From nobody Tue May 14 06:36:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1561257841; cv=none; d=zoho.com; s=zohoarc; b=CYT6jxnkdSYCY3iC001almuMHZMloefgJkqgICzKL8+aN7UgGz/TM152fRkgHoZ7HacJqqys/4JfzhLqkmDJREcQxO3+pQzohf2RYEpqSzwRA5op9w+QeZcBHX8aUqqKhhZMpHq8ZwgVvZIblilRUWeRCjUuinrDYh+j5i88kvM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561257841; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=6Rrv66pKtyutG8BNJAqwpnkTe55r3tpMS5om+gBp7as=; b=EROO5zTa/mK+18/VbJ7659JGjFhyDXmwpas0NJ0OEVL6OiYbCm2o+3Rb6rC5F4UPLkLhhcr4+LCsoxEwWnzTtC0kiT7sKaxO3SFZ8iwzIPcSkML0kIJPi33vOHTC4wmJkBbatFBfQNZdtrTPsS4SJD3WKI13QZubbdIgU1jfps0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1561257841272525.2780755286466; Sat, 22 Jun 2019 19:44:01 -0700 (PDT) Received: from localhost ([::1]:43040 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hesTz-0001Cp-8P for importer@patchew.org; Sat, 22 Jun 2019 22:43:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42880) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hesSr-0000Fn-5o for qemu-devel@nongnu.org; Sat, 22 Jun 2019 22:42:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hesSp-00035c-3P for qemu-devel@nongnu.org; Sat, 22 Jun 2019 22:42:45 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]:46701) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hesSo-00033g-S4 for qemu-devel@nongnu.org; Sat, 22 Jun 2019 22:42:43 -0400 Received: by mail-pg1-x52f.google.com with SMTP id v9so5198865pgr.13 for ; Sat, 22 Jun 2019 19:42:42 -0700 (PDT) Received: from localhost.localdomain ([222.131.159.173]) by smtp.gmail.com with ESMTPSA id o13sm7007146pje.28.2019.06.22.19.42.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 22 Jun 2019 19:42:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6Rrv66pKtyutG8BNJAqwpnkTe55r3tpMS5om+gBp7as=; b=nLuNFfVIKes4M4XJkXhn9bi/Z/3b0bZ41uBzRD2kgalvvil6z6ny+tORTpYRWzUx09 3PKsHjDbUxcnSxVocZH1QFE+5kM9Ev30Rn/M/5fenJcjfER2fLKBKNoPfu+rwhf51v5R jahjl/nRUNKjfU1a+rbS4Amj7DcB//Uu6uiqu6sLO8CS5LggSGTZuaHfGsczMm5eydug 9IZVULX+8w6sobuFPeUS3EynbU/FyBny7FbOQK2ttyY3fFcvHk+1L3YFgY/4E3iLa/cI qlqw/rL/Wuie2CpTmF/0zSVNgPlbTHXOEHDYfpXP9bmys6vdTEKhV2vjWYHYOU7VV5U1 GSEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6Rrv66pKtyutG8BNJAqwpnkTe55r3tpMS5om+gBp7as=; b=qjjw+RkMaXnOLYkzQMFtoSKk7uFGm3fsOXNppwnUWL15jDQRUxGb58mQKu9kj1o/qJ Ae+wbJZEogPF/JrLDunmV6I5jLhuGxfDL8obXph/NpKdCSCH0YaJATpjg8p74RhM229P q6Ttlm8cVvZm8duiky+qgOu/Ax4KEuSRfBEk/NL//ir+yjqS3RJ13WoR5KYbuEwey3jj 0P97Gt/jKth6MxaPVv8kFwxSdyU73BP+iqfVogVhESQVq2ToB1A+dr8ZPW/0T2J31z9j c/4l2aIWnqgETXetsInyHFmCWNjU8NV6wJHZVg+w2KC7R/vYT+ISkAIvMzTHBdl+p5BT nbqw== X-Gm-Message-State: APjAAAW6ZPxn9h/XoguSbd6nALbGUi152n6VAkV+YUCY94KoU3JsztgV Uf/qHno2+pVjavnjoX+foyoYIA== X-Google-Smtp-Source: APXvYqx9AoMAfNB/YHfVoU7/JdEslufqphaS1UrDj0cIPYyCuhBdNzxdkBqEEKFjFsYD7wUPPCUWfw== X-Received: by 2002:a63:6981:: with SMTP id e123mr25622441pgc.136.1561257761632; Sat, 22 Jun 2019 19:42:41 -0700 (PDT) From: Hongbo Zhang To: peter.maydell@linaro.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org Date: Sun, 23 Jun 2019 10:40:54 +0800 Message-Id: <1561257655-25907-2-git-send-email-hongbo.zhang@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1561257655-25907-1-git-send-email-hongbo.zhang@linaro.org> References: <1561257655-25907-1-git-send-email-hongbo.zhang@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::52f Subject: [Qemu-devel] [PATCH v8 1/2] hw/arm: Add arm SBSA reference machine, skeleton part X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hongbo Zhang , radoslaw.biernacki@linaro.org, leif.lindholm@linaro.org, ard.biesheuvel@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" For the Aarch64, there is one machine 'virt', it is primarily meant to run on KVM and execute virtualization workloads, but we need an environment as faithful as possible to physical hardware, for supporting firmware and OS development for pysical Aarch64 machines. This patch introduces new machine type 'sbsa-ref' with main features: - Based on 'virt' machine type. - A new memory map. - CPU type cortex-a57. - EL2 and EL3 are enabled. - GIC version 3. - System bus AHCI controller. - System bus EHCI controller. - CDROM and hard disc on AHCI bus. - E1000E ethernet card on PCIE bus. - VGA display adaptor on PCIE bus. - No virtio deivces. - No fw_cfg device. - No ACPI table supplied. - Only minimal device tree nodes. Arm Trusted Firmware and UEFI porting to this are done accordingly, and it should supply ACPI tables to load OS, the minimal device tree nodes supplied from this platform are only to pass the dynamic info reflecting command line input to firmware, not for loading OS. To make the review easier, this task is split into two patches, the fundamental sceleton part and the peripheral devices part, this patch is the first part. Signed-off-by: Hongbo Zhang --- default-configs/arm-softmmu.mak | 1 + hw/arm/Kconfig | 14 ++ hw/arm/Makefile.objs | 1 + hw/arm/sbsa-ref.c | 295 ++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 311 insertions(+) create mode 100644 hw/arm/sbsa-ref.c diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.= mak index 1f2e0e7..f9fdb73 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -19,6 +19,7 @@ CONFIG_SX1=3Dy CONFIG_NSERIES=3Dy CONFIG_STELLARIS=3Dy CONFIG_REALVIEW=3Dy +CONFIG_SBSA_REF=3Dy CONFIG_VERSATILE=3Dy CONFIG_VEXPRESS=3Dy CONFIG_ZYNQ=3Dy diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 9aced9d..d8f40ad 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -184,6 +184,20 @@ config REALVIEW select DS1338 # I2C RTC+NVRAM select USB_OHCI =20 +config SBSA_REF + bool + imply PCI_DEVICES + select A15MPCORE + select ARM_SMMUV3 + select GPIO_KEY + select PCI_EXPRESS + select PCI_EXPRESS_GENERIC_BRIDGE + select PFLASH_CFI01 + select PL011 # UART + select PL031 # RTC + select PL061 # GPIO + select PLATFORM_BUS + config SABRELITE bool select FSL_IMX6 diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs index 994e67d..43ce8d5 100644 --- a/hw/arm/Makefile.objs +++ b/hw/arm/Makefile.objs @@ -19,6 +19,7 @@ obj-$(CONFIG_SPITZ) +=3D spitz.o obj-$(CONFIG_TOSA) +=3D tosa.o obj-$(CONFIG_Z2) +=3D z2.o obj-$(CONFIG_REALVIEW) +=3D realview.o +obj-$(CONFIG_SBSA_REF) +=3D sbsa-ref.o obj-$(CONFIG_STELLARIS) +=3D stellaris.o obj-$(CONFIG_COLLIE) +=3D collie.o obj-$(CONFIG_VERSATILE) +=3D versatilepb.o diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c new file mode 100644 index 0000000..e68751e --- /dev/null +++ b/hw/arm/sbsa-ref.c @@ -0,0 +1,295 @@ +/* + * ARM SBSA Reference Platform emulation + * + * Copyright (c) 2018 Linaro Limited + * Written by Hongbo Zhang + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program. If not, see . + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "qemu/units.h" +#include "sysemu/numa.h" +#include "sysemu/sysemu.h" +#include "exec/address-spaces.h" +#include "exec/hwaddr.h" +#include "kvm_arm.h" +#include "hw/arm/boot.h" +#include "hw/boards.h" +#include "hw/intc/arm_gicv3_common.h" + +#define RAMLIMIT_GB 8192 +#define RAMLIMIT_BYTES (RAMLIMIT_GB * GiB) + +enum { + SBSA_FLASH, + SBSA_MEM, + SBSA_CPUPERIPHS, + SBSA_GIC_DIST, + SBSA_GIC_REDIST, + SBSA_SMMU, + SBSA_UART, + SBSA_RTC, + SBSA_PCIE, + SBSA_PCIE_MMIO, + SBSA_PCIE_MMIO_HIGH, + SBSA_PCIE_PIO, + SBSA_PCIE_ECAM, + SBSA_GPIO, + SBSA_SECURE_UART, + SBSA_SECURE_UART_MM, + SBSA_SECURE_MEM, + SBSA_AHCI, + SBSA_EHCI, +}; + +typedef struct MemMapEntry { + hwaddr base; + hwaddr size; +} MemMapEntry; + +typedef struct { + MachineState parent; + struct arm_boot_info bootinfo; + int smp_cpus; + void *fdt; + int fdt_size; + int psci_conduit; +} SBSAMachineState; + +#define TYPE_SBSA_MACHINE MACHINE_TYPE_NAME("sbsa-ref") +#define SBSA_MACHINE(obj) \ + OBJECT_CHECK(SBSAMachineState, (obj), TYPE_SBSA_MACHINE) + +static const MemMapEntry sbsa_ref_memmap[] =3D { + /* 512M boot ROM */ + [SBSA_FLASH] =3D { 0, 0x20000000 }, + /* 512M secure memory */ + [SBSA_SECURE_MEM] =3D { 0x20000000, 0x20000000 }, + /* Space reserved for CPU peripheral devices */ + [SBSA_CPUPERIPHS] =3D { 0x40000000, 0x00040000 }, + [SBSA_GIC_DIST] =3D { 0x40060000, 0x00010000 }, + [SBSA_GIC_REDIST] =3D { 0x40080000, 0x04000000 }, + [SBSA_UART] =3D { 0x60000000, 0x00001000 }, + [SBSA_RTC] =3D { 0x60010000, 0x00001000 }, + [SBSA_GPIO] =3D { 0x60020000, 0x00001000 }, + [SBSA_SECURE_UART] =3D { 0x60030000, 0x00001000 }, + [SBSA_SECURE_UART_MM] =3D { 0x60040000, 0x00001000 }, + [SBSA_SMMU] =3D { 0x60050000, 0x00020000 }, + /* Space here reserved for more SMMUs */ + [SBSA_AHCI] =3D { 0x60100000, 0x00010000 }, + [SBSA_EHCI] =3D { 0x60110000, 0x00010000 }, + /* Space here reserved for other devices */ + [SBSA_PCIE_PIO] =3D { 0x7fff0000, 0x00010000 }, + /* 32-bit address PCIE MMIO space */ + [SBSA_PCIE_MMIO] =3D { 0x80000000, 0x70000000 }, + /* 256M PCIE ECAM space */ + [SBSA_PCIE_ECAM] =3D { 0xf0000000, 0x10000000 }, + /* ~1TB PCIE MMIO space (4GB to 1024GB boundary) */ + [SBSA_PCIE_MMIO_HIGH] =3D { 0x100000000ULL, 0xFF00000000ULL }, + [SBSA_MEM] =3D { 0x10000000000ULL, RAMLIMIT_BYTES }, +}; + +static const int sbsa_ref_irqmap[] =3D { + [SBSA_UART] =3D 1, + [SBSA_RTC] =3D 2, + [SBSA_PCIE] =3D 3, /* ... to 6 */ + [SBSA_GPIO] =3D 7, + [SBSA_SECURE_UART] =3D 8, + [SBSA_SECURE_UART_MM] =3D 9, + [SBSA_AHCI] =3D 10, + [SBSA_EHCI] =3D 11, +}; + +static void sbsa_ref_init(MachineState *machine) +{ + SBSAMachineState *sms =3D SBSA_MACHINE(machine); + MachineClass *mc =3D MACHINE_GET_CLASS(machine); + MemoryRegion *sysmem =3D get_system_memory(); + MemoryRegion *secure_sysmem =3D NULL; + MemoryRegion *ram =3D g_new(MemoryRegion, 1); + bool firmware_loaded =3D bios_name || drive_get(IF_PFLASH, 0, 0); + const CPUArchIdList *possible_cpus; + int n, sbsa_max_cpus; + + if (strcmp(machine->cpu_type, ARM_CPU_TYPE_NAME("cortex-a57"))) { + error_report("sbsa-ref: CPU type other than the built-in " + "cortex-a57 not supported"); + exit(1); + } + + if (kvm_enabled()) { + error_report("sbsa-ref: KVM is not supported for this machine"); + exit(1); + } + + if (machine->kernel_filename && firmware_loaded) { + error_report("sbsa-ref: No fw_cfg device on this machine, " + "so -kernel option is not supported when firmware loa= ded, " + "please load OS from hard disk instead"); + exit(1); + } + + /* + * This machine has EL3 enabled, external firmware should supply PSCI + * implementation, so the QEMU's internal PSCI is disabled. + */ + sms->psci_conduit =3D QEMU_PSCI_CONDUIT_DISABLED; + + sbsa_max_cpus =3D sbsa_ref_memmap[SBSA_GIC_REDIST].size / GICV3_REDIST= _SIZE; + + if (max_cpus > sbsa_max_cpus) { + error_report("Number of SMP CPUs requested (%d) exceeds max CPUs " + "supported by machine 'sbsa-ref' (%d)", + max_cpus, sbsa_max_cpus); + exit(1); + } + + sms->smp_cpus =3D smp_cpus; + + if (machine->ram_size > sbsa_ref_memmap[SBSA_MEM].size) { + error_report("sbsa-ref: cannot model more than %dGB RAM", RAMLIMIT= _GB); + exit(1); + } + + secure_sysmem =3D g_new(MemoryRegion, 1); + memory_region_init(secure_sysmem, OBJECT(machine), "secure-memory", + UINT64_MAX); + memory_region_add_subregion_overlap(secure_sysmem, 0, sysmem, -1); + + possible_cpus =3D mc->possible_cpu_arch_ids(machine); + for (n =3D 0; n < possible_cpus->len; n++) { + Object *cpuobj; + CPUState *cs; + + if (n >=3D smp_cpus) { + break; + } + + cpuobj =3D object_new(possible_cpus->cpus[n].type); + object_property_set_int(cpuobj, possible_cpus->cpus[n].arch_id, + "mp-affinity", NULL); + + cs =3D CPU(cpuobj); + cs->cpu_index =3D n; + + numa_cpu_pre_plug(&possible_cpus->cpus[cs->cpu_index], DEVICE(cpuo= bj), + &error_fatal); + + if (object_property_find(cpuobj, "reset-cbar", NULL)) { + object_property_set_int(cpuobj, + sbsa_ref_memmap[SBSA_CPUPERIPHS].base, + "reset-cbar", &error_abort); + } + + object_property_set_link(cpuobj, OBJECT(sysmem), "memory", + &error_abort); + + object_property_set_link(cpuobj, OBJECT(secure_sysmem), + "secure-memory", &error_abort); + + object_property_set_bool(cpuobj, true, "realized", &error_fatal); + object_unref(cpuobj); + } + + memory_region_allocate_system_memory(ram, NULL, "sbsa-ref.ram", + machine->ram_size); + memory_region_add_subregion(sysmem, sbsa_ref_memmap[SBSA_MEM].base, ra= m); + + sms->bootinfo.ram_size =3D machine->ram_size; + sms->bootinfo.kernel_filename =3D machine->kernel_filename; + sms->bootinfo.nb_cpus =3D smp_cpus; + sms->bootinfo.board_id =3D -1; + sms->bootinfo.loader_start =3D sbsa_ref_memmap[SBSA_MEM].base; + sms->bootinfo.firmware_loaded =3D firmware_loaded; + arm_load_kernel(ARM_CPU(first_cpu), &sms->bootinfo); +} + +static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx) +{ + uint8_t clustersz =3D ARM_DEFAULT_CPUS_PER_CLUSTER; + return arm_cpu_mp_affinity(idx, clustersz); +} + +static const CPUArchIdList *sbsa_ref_possible_cpu_arch_ids(MachineState *m= s) +{ + SBSAMachineState *sms =3D SBSA_MACHINE(ms); + int n; + + if (ms->possible_cpus) { + assert(ms->possible_cpus->len =3D=3D max_cpus); + return ms->possible_cpus; + } + + ms->possible_cpus =3D g_malloc0(sizeof(CPUArchIdList) + + sizeof(CPUArchId) * max_cpus); + ms->possible_cpus->len =3D max_cpus; + for (n =3D 0; n < ms->possible_cpus->len; n++) { + ms->possible_cpus->cpus[n].type =3D ms->cpu_type; + ms->possible_cpus->cpus[n].arch_id =3D + sbsa_ref_cpu_mp_affinity(sms, n); + ms->possible_cpus->cpus[n].props.has_thread_id =3D true; + ms->possible_cpus->cpus[n].props.thread_id =3D n; + } + return ms->possible_cpus; +} + +static CpuInstanceProperties +sbsa_ref_cpu_index_to_props(MachineState *ms, unsigned cpu_index) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + const CPUArchIdList *possible_cpus =3D mc->possible_cpu_arch_ids(ms); + + assert(cpu_index < possible_cpus->len); + return possible_cpus->cpus[cpu_index].props; +} + +static int64_t +sbsa_ref_get_default_cpu_node_id(const MachineState *ms, int idx) +{ + return idx % nb_numa_nodes; +} + +static void sbsa_ref_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + + mc->init =3D sbsa_ref_init; + mc->desc =3D "QEMU 'SBSA Reference' ARM Virtual Machine"; + mc->default_cpu_type =3D ARM_CPU_TYPE_NAME("cortex-a57"); + mc->max_cpus =3D 512; + mc->pci_allow_0_address =3D true; + mc->minimum_page_bits =3D 12; + mc->block_default_type =3D IF_IDE; + mc->no_cdrom =3D 1; + mc->default_ram_size =3D 1 * GiB; + mc->default_cpus =3D 4; + mc->possible_cpu_arch_ids =3D sbsa_ref_possible_cpu_arch_ids; + mc->cpu_index_to_instance_props =3D sbsa_ref_cpu_index_to_props; + mc->get_default_cpu_node_id =3D sbsa_ref_get_default_cpu_node_id; +} + +static const TypeInfo sbsa_ref_info =3D { + .name =3D TYPE_SBSA_MACHINE, + .parent =3D TYPE_MACHINE, + .class_init =3D sbsa_ref_class_init, +}; + +static void sbsa_ref_machine_init(void) +{ + type_register_static(&sbsa_ref_info); +} + +type_init(sbsa_ref_machine_init); --=20 2.7.4 From nobody Tue May 14 06:36:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1561257955; cv=none; d=zoho.com; s=zohoarc; b=eq5QeQnybXoLlxJBcfW/Oc7e3qcOeYFxx6OxyczRyXsdXGrKrT2iQ76arhANqnPwA1ZpfQEy4aEZI6DhXAaZVICh08pxwKJaAY6fgt19muJGPoTV1QaimsRXFNVFK5KLyzq5ApFz65HYrFHL+CELmQp7LwRevK2JB+ZB0fApXNQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561257955; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=0175rzzmXB3wcWtqy4A/d2/Pbdgtm6CItBQos36x938=; b=IMg7rdHLeR557Vp2azZVD0MPYpfemSePrTlf7+squpbb3KaYnZA/0Cqm594NMfy97fenuaBfPFDodOX30utLTU1jn2lLc/Jmyf1A+IHcNTrZyDY9dHBgKuAv0b+yQMC93U/rc12xcJ9bRofqJXY5z1BV3ZlQFo3avEaUKfFD1ts= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1561257955906714.9541231821304; Sat, 22 Jun 2019 19:45:55 -0700 (PDT) Received: from localhost ([::1]:43064 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hesVu-0002pX-Ti for importer@patchew.org; Sat, 22 Jun 2019 22:45:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42931) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hesSv-0000Kv-2T for qemu-devel@nongnu.org; Sat, 22 Jun 2019 22:42:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hesSs-0003Dc-Ep for qemu-devel@nongnu.org; Sat, 22 Jun 2019 22:42:48 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:35850) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hesSs-0003BV-46 for qemu-devel@nongnu.org; Sat, 22 Jun 2019 22:42:46 -0400 Received: by mail-pf1-x441.google.com with SMTP id r7so5548214pfl.3 for ; Sat, 22 Jun 2019 19:42:46 -0700 (PDT) Received: from localhost.localdomain ([222.131.159.173]) by smtp.gmail.com with ESMTPSA id o13sm7007146pje.28.2019.06.22.19.42.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 22 Jun 2019 19:42:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0175rzzmXB3wcWtqy4A/d2/Pbdgtm6CItBQos36x938=; b=tx9kTKVwYAjPXfNSqLQ6rfmCCR5BW/Rtw9K9MZC8dsZ2rFzYjj7jEXUhfdkdKwJuVj nAOsEZdsVi1rOpRTMcALiAjlrm2q1mJ3klPAKqQw6GI2q/uRZ4d2WlnVzLuDXzoVYZ7n fZo2OPaydXxWhCEiJh5IQdGEMEBP3HQjzzikWnw4v3h4Tj4VN1OUKD0NiMNJfCWENmZv 5reHsrln9bXklQN7jekduqpkELgUMNbv+m5smcekRhnN7jdtBqR9Hr9TckWbzb7opp/B XXTdsMMNOT1TRvdNkcDjHpv0KTNyVFR1xwGAjTiTXgf6xAOR9BxXX71+fq1mPI7PVWrU vCTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0175rzzmXB3wcWtqy4A/d2/Pbdgtm6CItBQos36x938=; b=JUM6f7ImdSvoq7XQsaovxtDI9hv4ZNDTDt9bFWtDeRoHfRxM7HpMBZdMyk7DwsyEvA SAPv7zXt0XZv6xDfpWzQAvpgLJM5M2B0MpyuLUQhshTlkFwFvnc+uTXBfg0nTsy46h2k Ui+7p7+wcVA9DY78VwfoLxZGWz6WtTn8fSbfz4IcBG0RF6kjkApWxSqZYQjyeP7hyqgx jrZCu1iSulZhiLphmKQ8ylvfbhUsNi4QewdWbrN7vZXE/7JKQOpKjQuUMwvmmWwZusI/ dtZnjqmSMi7xZcbCcah5N4VXtSU8HjxIGoGeG6n0pFlBSJSGa22CBVqq5DG+KMV6br3m YKEQ== X-Gm-Message-State: APjAAAXv2L0pKScp8nvShF+ruGGVTQwl0JnapOdCsUGH0AoGYTSKzFSw nFCsPap6LVu82cR2t8G2lfQG/Q== X-Google-Smtp-Source: APXvYqw3173tR8OJnH7al5jA8PaFzDc0m06p2OMqdGNlglcG7DnUvX7OdKToaLZx/yGxPWET+JAo5A== X-Received: by 2002:a17:90a:35e6:: with SMTP id r93mr16413441pjb.20.1561257764914; Sat, 22 Jun 2019 19:42:44 -0700 (PDT) From: Hongbo Zhang To: peter.maydell@linaro.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org Date: Sun, 23 Jun 2019 10:40:55 +0800 Message-Id: <1561257655-25907-3-git-send-email-hongbo.zhang@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1561257655-25907-1-git-send-email-hongbo.zhang@linaro.org> References: <1561257655-25907-1-git-send-email-hongbo.zhang@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::441 Subject: [Qemu-devel] [PATCH v8 2/2] hw/arm: Add arm SBSA reference machine, devices part X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hongbo Zhang , radoslaw.biernacki@linaro.org, leif.lindholm@linaro.org, ard.biesheuvel@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Following the previous patch, this patch adds peripheral devices to the newly introduced SBSA-ref machine. Signed-off-by: Hongbo Zhang --- hw/arm/sbsa-ref.c | 523 ++++++++++++++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 517 insertions(+), 6 deletions(-) diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c index e68751e..3b2b9cb 100644 --- a/hw/arm/sbsa-ref.c +++ b/hw/arm/sbsa-ref.c @@ -18,21 +18,41 @@ */ =20 #include "qemu/osdep.h" +#include "qemu-common.h" #include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/units.h" +#include "sysemu/device_tree.h" #include "sysemu/numa.h" #include "sysemu/sysemu.h" #include "exec/address-spaces.h" #include "exec/hwaddr.h" #include "kvm_arm.h" #include "hw/arm/boot.h" +#include "hw/block/flash.h" #include "hw/boards.h" +#include "hw/ide/internal.h" +#include "hw/ide/ahci_internal.h" #include "hw/intc/arm_gicv3_common.h" +#include "hw/loader.h" +#include "hw/pci-host/gpex.h" +#include "hw/usb.h" +#include "net/net.h" =20 #define RAMLIMIT_GB 8192 #define RAMLIMIT_BYTES (RAMLIMIT_GB * GiB) =20 +#define NUM_IRQS 256 +#define NUM_SMMU_IRQS 4 +#define NUM_SATA_PORTS 6 + +#define VIRTUAL_PMU_IRQ 7 +#define ARCH_GIC_MAINT_IRQ 9 +#define ARCH_TIMER_VIRT_IRQ 11 +#define ARCH_TIMER_S_EL1_IRQ 13 +#define ARCH_TIMER_NS_EL1_IRQ 14 +#define ARCH_TIMER_NS_EL2_IRQ 10 + enum { SBSA_FLASH, SBSA_MEM, @@ -67,6 +87,7 @@ typedef struct { void *fdt; int fdt_size; int psci_conduit; + PFlashCFI01 *flash[2]; } SBSAMachineState; =20 #define TYPE_SBSA_MACHINE MACHINE_TYPE_NAME("sbsa-ref") @@ -113,6 +134,455 @@ static const int sbsa_ref_irqmap[] =3D { [SBSA_EHCI] =3D 11, }; =20 +/* + * Firmware on this machine only uses ACPI table to load OS, these limited + * device tree nodes are just to let firmware know the info which varies f= rom + * command line parameters, so it is not necessary to be fully compatible + * with the kernel CPU and NUMA binding rules. + */ +static void create_fdt(SBSAMachineState *sms) +{ + void *fdt =3D create_device_tree(&sms->fdt_size); + const MachineState *ms =3D MACHINE(sms); + int cpu; + + if (!fdt) { + error_report("create_device_tree() failed"); + exit(1); + } + + sms->fdt =3D fdt; + + qemu_fdt_setprop_string(fdt, "/", "compatible", "linux,sbsa-ref"); + qemu_fdt_setprop_cell(fdt, "/", "#address-cells", 0x2); + qemu_fdt_setprop_cell(fdt, "/", "#size-cells", 0x2); + + if (have_numa_distance) { + int size =3D nb_numa_nodes * nb_numa_nodes * 3 * sizeof(uint32_t); + uint32_t *matrix =3D g_malloc0(size); + int idx, i, j; + + for (i =3D 0; i < nb_numa_nodes; i++) { + for (j =3D 0; j < nb_numa_nodes; j++) { + idx =3D (i * nb_numa_nodes + j) * 3; + matrix[idx + 0] =3D cpu_to_be32(i); + matrix[idx + 1] =3D cpu_to_be32(j); + matrix[idx + 2] =3D cpu_to_be32(numa_info[i].distance[j]); + } + } + + qemu_fdt_add_subnode(fdt, "/distance-map"); + qemu_fdt_setprop(fdt, "/distance-map", "distance-matrix", + matrix, size); + g_free(matrix); + } + + qemu_fdt_add_subnode(sms->fdt, "/cpus"); + + for (cpu =3D sms->smp_cpus - 1; cpu >=3D 0; cpu--) { + char *nodename =3D g_strdup_printf("/cpus/cpu@%d", cpu); + ARMCPU *armcpu =3D ARM_CPU(qemu_get_cpu(cpu)); + CPUState *cs =3D CPU(armcpu); + + qemu_fdt_add_subnode(sms->fdt, nodename); + + if (ms->possible_cpus->cpus[cs->cpu_index].props.has_node_id) { + qemu_fdt_setprop_cell(sms->fdt, nodename, "numa-node-id", + ms->possible_cpus->cpus[cs->cpu_index].props.node_id); + } + + g_free(nodename); + } +} + +#define SBSA_FLASH_SECTOR_SIZE (256 * KiB) + +static PFlashCFI01 *sbsa_flash_create1(SBSAMachineState *sms, + const char *name, + const char *alias_prop_name) +{ + /* + * Create a single flash device. We use the same parameters as + * the flash devices on the Versatile Express board. + */ + DeviceState *dev =3D qdev_create(NULL, TYPE_PFLASH_CFI01); + + qdev_prop_set_uint64(dev, "sector-length", SBSA_FLASH_SECTOR_SIZE); + qdev_prop_set_uint8(dev, "width", 4); + qdev_prop_set_uint8(dev, "device-width", 2); + qdev_prop_set_bit(dev, "big-endian", false); + qdev_prop_set_uint16(dev, "id0", 0x89); + qdev_prop_set_uint16(dev, "id1", 0x18); + qdev_prop_set_uint16(dev, "id2", 0x00); + qdev_prop_set_uint16(dev, "id3", 0x00); + qdev_prop_set_string(dev, "name", name); + object_property_add_child(OBJECT(sms), name, OBJECT(dev), + &error_abort); + object_property_add_alias(OBJECT(sms), alias_prop_name, + OBJECT(dev), "drive", &error_abort); + return PFLASH_CFI01(dev); +} + +static void sbsa_flash_create(SBSAMachineState *sms) +{ + sms->flash[0] =3D sbsa_flash_create1(sms, "sbsa.flash0", "pflash0"); + sms->flash[1] =3D sbsa_flash_create1(sms, "sbsa.flash1", "pflash1"); +} + +static void sbsa_flash_map1(PFlashCFI01 *flash, + hwaddr base, hwaddr size, + MemoryRegion *sysmem) +{ + DeviceState *dev =3D DEVICE(flash); + + assert(size % SBSA_FLASH_SECTOR_SIZE =3D=3D 0); + assert(size / SBSA_FLASH_SECTOR_SIZE <=3D UINT32_MAX); + qdev_prop_set_uint32(dev, "num-blocks", size / SBSA_FLASH_SECTOR_SIZE); + qdev_init_nofail(dev); + + memory_region_add_subregion(sysmem, base, + sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), + 0)); +} + +static void sbsa_flash_map(SBSAMachineState *sms, + MemoryRegion *sysmem, + MemoryRegion *secure_sysmem) +{ + /* + * Map two flash devices to fill the SBSA_FLASH space in the memmap. + * sysmem is the system memory space. secure_sysmem is the secure view + * of the system, and the first flash device should be made visible on= ly + * there. The second flash device is visible to both secure and nonsec= ure. + * If sysmem =3D=3D secure_sysmem this means there is no separate Secu= re + * address space and both flash devices are generally visible. + */ + hwaddr flashsize =3D sbsa_ref_memmap[SBSA_FLASH].size / 2; + hwaddr flashbase =3D sbsa_ref_memmap[SBSA_FLASH].base; + + sbsa_flash_map1(sms->flash[0], flashbase, flashsize, + secure_sysmem); + sbsa_flash_map1(sms->flash[1], flashbase + flashsize, flashsize, + sysmem); +} + +static bool sbsa_firmware_init(SBSAMachineState *sms, + MemoryRegion *sysmem, + MemoryRegion *secure_sysmem) +{ + int i; + BlockBackend *pflash_blk0; + + /* Map legacy -drive if=3Dpflash to machine properties */ + for (i =3D 0; i < ARRAY_SIZE(sms->flash); i++) { + pflash_cfi01_legacy_drive(sms->flash[i], + drive_get(IF_PFLASH, 0, i)); + } + + sbsa_flash_map(sms, sysmem, secure_sysmem); + + pflash_blk0 =3D pflash_cfi01_get_blk(sms->flash[0]); + + if (bios_name) { + char *fname; + MemoryRegion *mr; + int image_size; + + if (pflash_blk0) { + error_report("The contents of the first flash device may be " + "specified with -bios or with -drive if=3Dpflash.= .. " + "but you cannot use both options at once"); + exit(1); + } + + /* Fall back to -bios */ + + fname =3D qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); + if (!fname) { + error_report("Could not find ROM image '%s'", bios_name); + exit(1); + } + mr =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(sms->flash[0]), 0); + image_size =3D load_image_mr(fname, mr); + g_free(fname); + if (image_size < 0) { + error_report("Could not load ROM image '%s'", bios_name); + exit(1); + } + } + + return pflash_blk0 || bios_name; +} + +static void create_secure_ram(SBSAMachineState *sms, + MemoryRegion *secure_sysmem) +{ + MemoryRegion *secram =3D g_new(MemoryRegion, 1); + hwaddr base =3D sbsa_ref_memmap[SBSA_SECURE_MEM].base; + hwaddr size =3D sbsa_ref_memmap[SBSA_SECURE_MEM].size; + + memory_region_init_ram(secram, NULL, "sbsa-ref.secure-ram", size, + &error_fatal); + memory_region_add_subregion(secure_sysmem, base, secram); +} + +static void create_gic(SBSAMachineState *sms, qemu_irq *pic) +{ + DeviceState *gicdev; + SysBusDevice *gicbusdev; + const char *gictype; + uint32_t redist0_capacity, redist0_count; + int i; + + gictype =3D gicv3_class_name(); + + gicdev =3D qdev_create(NULL, gictype); + qdev_prop_set_uint32(gicdev, "revision", 3); + qdev_prop_set_uint32(gicdev, "num-cpu", smp_cpus); + /* + * Note that the num-irq property counts both internal and external + * interrupts; there are always 32 of the former (mandated by GIC spec= ). + */ + qdev_prop_set_uint32(gicdev, "num-irq", NUM_IRQS + 32); + qdev_prop_set_bit(gicdev, "has-security-extensions", true); + + redist0_capacity =3D + sbsa_ref_memmap[SBSA_GIC_REDIST].size / GICV3_REDIST_SIZE; + redist0_count =3D MIN(smp_cpus, redist0_capacity); + + qdev_prop_set_uint32(gicdev, "len-redist-region-count", 1); + qdev_prop_set_uint32(gicdev, "redist-region-count[0]", redist0_count); + + qdev_init_nofail(gicdev); + gicbusdev =3D SYS_BUS_DEVICE(gicdev); + sysbus_mmio_map(gicbusdev, 0, sbsa_ref_memmap[SBSA_GIC_DIST].base); + sysbus_mmio_map(gicbusdev, 1, sbsa_ref_memmap[SBSA_GIC_REDIST].base); + + /* + * Wire the outputs from each CPU's generic timer and the GICv3 + * maintenance interrupt signal to the appropriate GIC PPI inputs, + * and the GIC's IRQ/FIQ/VIRQ/VFIQ interrupt outputs to the CPU's inpu= ts. + */ + for (i =3D 0; i < smp_cpus; i++) { + DeviceState *cpudev =3D DEVICE(qemu_get_cpu(i)); + int ppibase =3D NUM_IRQS + i * GIC_INTERNAL + GIC_NR_SGIS; + int irq; + /* + * Mapping from the output timer irq lines from the CPU to the + * GIC PPI inputs used for this board. + */ + const int timer_irq[] =3D { + [GTIMER_PHYS] =3D ARCH_TIMER_NS_EL1_IRQ, + [GTIMER_VIRT] =3D ARCH_TIMER_VIRT_IRQ, + [GTIMER_HYP] =3D ARCH_TIMER_NS_EL2_IRQ, + [GTIMER_SEC] =3D ARCH_TIMER_S_EL1_IRQ, + }; + + for (irq =3D 0; irq < ARRAY_SIZE(timer_irq); irq++) { + qdev_connect_gpio_out(cpudev, irq, + qdev_get_gpio_in(gicdev, + ppibase + timer_irq[irq= ])); + } + + qdev_connect_gpio_out_named(cpudev, "gicv3-maintenance-interrupt",= 0, + qdev_get_gpio_in(gicdev, ppibase + + ARCH_GIC_MAINT_IRQ)= ); + qdev_connect_gpio_out_named(cpudev, "pmu-interrupt", 0, + qdev_get_gpio_in(gicdev, ppibase + + VIRTUAL_PMU_IRQ)); + + sysbus_connect_irq(gicbusdev, i, qdev_get_gpio_in(cpudev, ARM_CPU_= IRQ)); + sysbus_connect_irq(gicbusdev, i + smp_cpus, + qdev_get_gpio_in(cpudev, ARM_CPU_FIQ)); + sysbus_connect_irq(gicbusdev, i + 2 * smp_cpus, + qdev_get_gpio_in(cpudev, ARM_CPU_VIRQ)); + sysbus_connect_irq(gicbusdev, i + 3 * smp_cpus, + qdev_get_gpio_in(cpudev, ARM_CPU_VFIQ)); + } + + for (i =3D 0; i < NUM_IRQS; i++) { + pic[i] =3D qdev_get_gpio_in(gicdev, i); + } +} + +static void create_uart(const SBSAMachineState *sms, qemu_irq *pic, int ua= rt, + MemoryRegion *mem, Chardev *chr) +{ + hwaddr base =3D sbsa_ref_memmap[uart].base; + int irq =3D sbsa_ref_irqmap[uart]; + DeviceState *dev =3D qdev_create(NULL, "pl011"); + SysBusDevice *s =3D SYS_BUS_DEVICE(dev); + + qdev_prop_set_chr(dev, "chardev", chr); + qdev_init_nofail(dev); + memory_region_add_subregion(mem, base, + sysbus_mmio_get_region(s, 0)); + sysbus_connect_irq(s, 0, pic[irq]); +} + +static void create_rtc(const SBSAMachineState *sms, qemu_irq *pic) +{ + hwaddr base =3D sbsa_ref_memmap[SBSA_RTC].base; + int irq =3D sbsa_ref_irqmap[SBSA_RTC]; + + sysbus_create_simple("pl031", base, pic[irq]); +} + +static DeviceState *gpio_key_dev; +static void sbsa_ref_powerdown_req(Notifier *n, void *opaque) +{ + /* use gpio Pin 3 for power button event */ + qemu_set_irq(qdev_get_gpio_in(gpio_key_dev, 0), 1); +} + +static Notifier sbsa_ref_powerdown_notifier =3D { + .notify =3D sbsa_ref_powerdown_req +}; + +static void create_gpio(const SBSAMachineState *sms, qemu_irq *pic) +{ + DeviceState *pl061_dev; + hwaddr base =3D sbsa_ref_memmap[SBSA_GPIO].base; + int irq =3D sbsa_ref_irqmap[SBSA_GPIO]; + + pl061_dev =3D sysbus_create_simple("pl061", base, pic[irq]); + + gpio_key_dev =3D sysbus_create_simple("gpio-key", -1, + qdev_get_gpio_in(pl061_dev, 3)); + + /* connect powerdown request */ + qemu_register_powerdown_notifier(&sbsa_ref_powerdown_notifier); +} + +static void create_ahci(const SBSAMachineState *sms, qemu_irq *pic) +{ + hwaddr base =3D sbsa_ref_memmap[SBSA_AHCI].base; + int irq =3D sbsa_ref_irqmap[SBSA_AHCI]; + DeviceState *dev; + DriveInfo *hd[NUM_SATA_PORTS]; + SysbusAHCIState *sysahci; + AHCIState *ahci; + int i; + + dev =3D qdev_create(NULL, "sysbus-ahci"); + qdev_prop_set_uint32(dev, "num-ports", NUM_SATA_PORTS); + qdev_init_nofail(dev); + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base); + sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, pic[irq]); + + sysahci =3D SYSBUS_AHCI(dev); + ahci =3D &sysahci->ahci; + ide_drive_get(hd, ARRAY_SIZE(hd)); + for (i =3D 0; i < ahci->ports; i++) { + if (hd[i] =3D=3D NULL) { + continue; + } + ide_create_drive(&ahci->dev[i].port, 0, hd[i]); + } +} + +static void create_ehci(const SBSAMachineState *sms, qemu_irq *pic) +{ + hwaddr base =3D sbsa_ref_memmap[SBSA_EHCI].base; + int irq =3D sbsa_ref_irqmap[SBSA_EHCI]; + + sysbus_create_simple("platform-ehci-usb", base, pic[irq]); +} + +static void create_smmu(const SBSAMachineState *sms, qemu_irq *pic, + PCIBus *bus) +{ + hwaddr base =3D sbsa_ref_memmap[SBSA_SMMU].base; + int irq =3D sbsa_ref_irqmap[SBSA_SMMU]; + DeviceState *dev; + int i; + + dev =3D qdev_create(NULL, "arm-smmuv3"); + + object_property_set_link(OBJECT(dev), OBJECT(bus), "primary-bus", + &error_abort); + qdev_init_nofail(dev); + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base); + for (i =3D 0; i < NUM_SMMU_IRQS; i++) { + sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, pic[irq + i]); + } +} + +static void create_pcie(SBSAMachineState *sms, qemu_irq *pic) +{ + hwaddr base_ecam =3D sbsa_ref_memmap[SBSA_PCIE_ECAM].base; + hwaddr size_ecam =3D sbsa_ref_memmap[SBSA_PCIE_ECAM].size; + hwaddr base_mmio =3D sbsa_ref_memmap[SBSA_PCIE_MMIO].base; + hwaddr size_mmio =3D sbsa_ref_memmap[SBSA_PCIE_MMIO].size; + hwaddr base_mmio_high =3D sbsa_ref_memmap[SBSA_PCIE_MMIO_HIGH].base; + hwaddr size_mmio_high =3D sbsa_ref_memmap[SBSA_PCIE_MMIO_HIGH].size; + hwaddr base_pio =3D sbsa_ref_memmap[SBSA_PCIE_PIO].base; + int irq =3D sbsa_ref_irqmap[SBSA_PCIE]; + MemoryRegion *mmio_alias, *mmio_alias_high, *mmio_reg; + MemoryRegion *ecam_alias, *ecam_reg; + DeviceState *dev; + PCIHostState *pci; + int i; + + dev =3D qdev_create(NULL, TYPE_GPEX_HOST); + qdev_init_nofail(dev); + + /* Map ECAM space */ + ecam_alias =3D g_new0(MemoryRegion, 1); + ecam_reg =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0); + memory_region_init_alias(ecam_alias, OBJECT(dev), "pcie-ecam", + ecam_reg, 0, size_ecam); + memory_region_add_subregion(get_system_memory(), base_ecam, ecam_alias= ); + + /* Map the MMIO space */ + mmio_alias =3D g_new0(MemoryRegion, 1); + mmio_reg =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 1); + memory_region_init_alias(mmio_alias, OBJECT(dev), "pcie-mmio", + mmio_reg, base_mmio, size_mmio); + memory_region_add_subregion(get_system_memory(), base_mmio, mmio_alias= ); + + /* Map the MMIO_HIGH space */ + mmio_alias_high =3D g_new0(MemoryRegion, 1); + memory_region_init_alias(mmio_alias_high, OBJECT(dev), "pcie-mmio-high= ", + mmio_reg, base_mmio_high, size_mmio_high); + memory_region_add_subregion(get_system_memory(), base_mmio_high, + mmio_alias_high); + + /* Map IO port space */ + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, base_pio); + + for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, pic[irq + i]); + gpex_set_irq_num(GPEX_HOST(dev), i, irq + i); + } + + pci =3D PCI_HOST_BRIDGE(dev); + if (pci->bus) { + for (i =3D 0; i < nb_nics; i++) { + NICInfo *nd =3D &nd_table[i]; + + if (!nd->model) { + nd->model =3D g_strdup("e1000e"); + } + + pci_nic_init_nofail(nd, pci->bus, nd->model, NULL); + } + } + + pci_create_simple(pci->bus, -1, "VGA"); + + create_smmu(sms, pic, pci->bus); +} + +static void *sbsa_ref_dtb(const struct arm_boot_info *binfo, int *fdt_size) +{ + const SBSAMachineState *board =3D container_of(binfo, SBSAMachineState, + bootinfo); + + *fdt_size =3D board->fdt_size; + return board->fdt; +} + static void sbsa_ref_init(MachineState *machine) { SBSAMachineState *sms =3D SBSA_MACHINE(machine); @@ -120,9 +590,10 @@ static void sbsa_ref_init(MachineState *machine) MemoryRegion *sysmem =3D get_system_memory(); MemoryRegion *secure_sysmem =3D NULL; MemoryRegion *ram =3D g_new(MemoryRegion, 1); - bool firmware_loaded =3D bios_name || drive_get(IF_PFLASH, 0, 0); + bool firmware_loaded; const CPUArchIdList *possible_cpus; int n, sbsa_max_cpus; + qemu_irq pic[NUM_IRQS]; =20 if (strcmp(machine->cpu_type, ARM_CPU_TYPE_NAME("cortex-a57"))) { error_report("sbsa-ref: CPU type other than the built-in " @@ -135,6 +606,20 @@ static void sbsa_ref_init(MachineState *machine) exit(1); } =20 + /* + * The Secure view of the world is the same as the NonSecure, + * but with a few extra devices. Create it as a container region + * containing the system memory at low priority; any secure-only + * devices go in at higher priority and take precedence. + */ + secure_sysmem =3D g_new(MemoryRegion, 1); + memory_region_init(secure_sysmem, OBJECT(machine), "secure-memory", + UINT64_MAX); + memory_region_add_subregion_overlap(secure_sysmem, 0, sysmem, -1); + + firmware_loaded =3D sbsa_firmware_init(sms, sysmem, + secure_sysmem ?: sysmem); + if (machine->kernel_filename && firmware_loaded) { error_report("sbsa-ref: No fw_cfg device on this machine, " "so -kernel option is not supported when firmware loa= ded, " @@ -164,11 +649,6 @@ static void sbsa_ref_init(MachineState *machine) exit(1); } =20 - secure_sysmem =3D g_new(MemoryRegion, 1); - memory_region_init(secure_sysmem, OBJECT(machine), "secure-memory", - UINT64_MAX); - memory_region_add_subregion_overlap(secure_sysmem, 0, sysmem, -1); - possible_cpus =3D mc->possible_cpu_arch_ids(machine); for (n =3D 0; n < possible_cpus->len; n++) { Object *cpuobj; @@ -208,11 +688,33 @@ static void sbsa_ref_init(MachineState *machine) machine->ram_size); memory_region_add_subregion(sysmem, sbsa_ref_memmap[SBSA_MEM].base, ra= m); =20 + create_fdt(sms); + + create_secure_ram(sms, secure_sysmem); + + create_gic(sms, pic); + + create_uart(sms, pic, SBSA_UART, sysmem, serial_hd(0)); + create_uart(sms, pic, SBSA_SECURE_UART, secure_sysmem, serial_hd(1)); + /* Second secure UART for RAS and MM from EL0 */ + create_uart(sms, pic, SBSA_SECURE_UART_MM, secure_sysmem, serial_hd(2)= ); + + create_rtc(sms, pic); + + create_gpio(sms, pic); + + create_ahci(sms, pic); + + create_ehci(sms, pic); + + create_pcie(sms, pic); + sms->bootinfo.ram_size =3D machine->ram_size; sms->bootinfo.kernel_filename =3D machine->kernel_filename; sms->bootinfo.nb_cpus =3D smp_cpus; sms->bootinfo.board_id =3D -1; sms->bootinfo.loader_start =3D sbsa_ref_memmap[SBSA_MEM].base; + sms->bootinfo.get_dtb =3D sbsa_ref_dtb; sms->bootinfo.firmware_loaded =3D firmware_loaded; arm_load_kernel(ARM_CPU(first_cpu), &sms->bootinfo); } @@ -262,6 +764,13 @@ sbsa_ref_get_default_cpu_node_id(const MachineState *m= s, int idx) return idx % nb_numa_nodes; } =20 +static void sbsa_ref_instance_init(Object *obj) +{ + SBSAMachineState *sms =3D SBSA_MACHINE(obj); + + sbsa_flash_create(sms); +} + static void sbsa_ref_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); @@ -284,6 +793,8 @@ static void sbsa_ref_class_init(ObjectClass *oc, void *= data) static const TypeInfo sbsa_ref_info =3D { .name =3D TYPE_SBSA_MACHINE, .parent =3D TYPE_MACHINE, + .instance_size =3D sizeof(SBSAMachineState), + .instance_init =3D sbsa_ref_instance_init, .class_init =3D sbsa_ref_class_init, }; =20 --=20 2.7.4