[prev in list] [next in list] [prev in thread] [next in thread] 

List:       qemu-arm
Subject:    Re: [Qemu-arm] [PATCH v4] hw/arm: Add arm SBSA reference machine
From:       Radoslaw Biernacki <radoslaw.biernacki () linaro ! org>
Date:       2019-01-31 13:21:07
Message-ID: CAEK-wKnWAOtfTKffvj1xuoj0iXTmnn4sQ20ooV9a+0+OsrWmuA () mail ! gmail ! com
[Download RAW message or body]

Hongbo,

Take a look at last patch in: ssh://
git@git.linaro.org/people/radoslaw.biernacki/qemu.git
branch wip_rad_new_memmap

On Wed, 30 Jan 2019 at 09:37, Ard Biesheuvel <ard.biesheuvel@linaro.org>
wrote:

> On Wed, 30 Jan 2019 at 09:34, Hongbo Zhang <hongbo.zhang@linaro.org>
> wrote:
> >
> > On Tue, 29 Jan 2019 at 19:29, Ard Biesheuvel <ard.biesheuvel@linaro.org>
> wrote:
> > >
> > > Responding to an old thread ...
> > >
> > > On Thu, 15 Nov 2018 at 17:05, Peter Maydell <peter.maydell@linaro.org>
> wrote:
> > > >
> > > > On 19 October 2018 at 09:55, Hongbo Zhang <hongbo.zhang@linaro.org>
> wrote:
> > > > > 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.
> > > > >  - CPU type cortex-a57.
> > > > >  - EL2 and EL3 are enabled by default.
> > > > >  - GIC version 3 only.
> > > > >  - Re-designed memory map.
> > > > >  - AHCI controller attached to system bus.
> > > > >  - EHCI controller attached to system bus.
> > > > >  - CDROM and hard disc on AHCI bus.
> > > > >  - USB mouse and key board.
> > > > >  - E1000E ethernet card on PCIE bus.
> > > > >  - VGA display adaptor on PCIE bus.
> > > > >  - No virtio deivces.
> > > > >  - No paravirtualized fw_cfg device.
> > > > >  - No ACPI table supplied.
> > > > >  - Only minimal device tree nodes.
> > > > >
> > > > > Arm Trusted Firmware and UEFI porting to this are done accordingly.
> > > > >
> > > > > Signed-off-by: Hongbo Zhang <hongbo.zhang@linaro.org>
> > > >
> > > > Hi; I've had a quick run through this patch. My comments
> > > > below are mostly about there still being a lot of code
> > > > here which has been copied from virt.c but which you do
> > > > not need.
> > > >
> > > > If after you've done that this patch is still more than
> > > > about 500 lines long, I would recommend that you split it
> > > > up into coherent pieces, to make it easier to review.
> > > >
> > > > > ---
> > > > >  hw/arm/Makefile.objs  |   2 +-
> > > > >  hw/arm/sbsa-ref.c     | 937
> ++++++++++++++++++++++++++++++++++++++++++++++++++
> > > > >  include/hw/arm/virt.h |   2 +
> > > > >  3 files changed, 940 insertions(+), 1 deletion(-)
> > > > >  create mode 100644 hw/arm/sbsa-ref.c
> > > > >
> > > > > diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
> > > > > index d51fcec..a8895eb 100644
> > > > > --- a/hw/arm/Makefile.objs
> > > > > +++ b/hw/arm/Makefile.objs
> > > > > @@ -1,4 +1,4 @@
> > > > > -obj-y += boot.o virt.o sysbus-fdt.o
> > > > > +obj-y += boot.o virt.o sbsa-ref.o sysbus-fdt.o
> > > > >  obj-$(CONFIG_ACPI) += virt-acpi-build.o
> > > > >  obj-$(CONFIG_DIGIC) += digic_boards.o
> > > > >  obj-$(CONFIG_EXYNOS4) += exynos4_boards.o
> > > > > diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
> > > > > new file mode 100644
> > > > > index 0000000..28ebb3a
> > > > > --- /dev/null
> > > > > +++ b/hw/arm/sbsa-ref.c
> > > > > @@ -0,0 +1,937 @@
> > > > > +/*
> > > > > + * ARM SBSA Reference Platform emulation
> > > > > + *
> > > > > + * Copyright (c) 2018 Linaro Limited
> > > > > + * Written by Hongbo Zhang <hongbo.zhang@linaro.org>
> > > > > + *
> > > > > + * Based on hw/arm/virt.c
> > > > > + *
> > > > > + * 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 for
> > > > > + * more details.
> > > > > + *
> > > > > + * You should have received a copy of the GNU General Public
> License along with
> > > > > + * this program.  If not, see <http://www.gnu.org/licenses/>.
> > > > > + */
> > > > > +
> > > > > +#include "qemu/osdep.h"
> > > > > +#include "qapi/error.h"
> > > > > +#include "hw/arm/virt.h"
> > > > > +#include "hw/devices.h"
> > > > > +#include "net/net.h"
> > > > > +#include "sysemu/device_tree.h"
> > > > > +#include "sysemu/numa.h"
> > > > > +#include "hw/loader.h"
> > > > > +#include "qemu/error-report.h"
> > > > > +#include "hw/pci-host/gpex.h"
> > > > > +#include "hw/arm/sysbus-fdt.h"
> > > > > +#include "hw/arm/fdt.h"
> > > > > +#include "hw/intc/arm_gic.h"
> > > > > +#include "hw/intc/arm_gicv3_common.h"
> > > > > +#include "kvm_arm.h"
> > > > > +#include "hw/ide/internal.h"
> > > > > +#include "hw/ide/ahci_internal.h"
> > > > > +#include "hw/usb.h"
> > > > > +#include "qemu/units.h"
> > > > > +
> > > > > +#define NUM_IRQS 256
> > > > > +
> > > > > +#define SATA_NUM_PORTS 6
> > > > > +
> > > > > +#define RAMLIMIT_GB 255
> > > > > +#define RAMLIMIT_BYTES (RAMLIMIT_GB * GiB)
> > > >
> > > > You probably don't want to stick yourself with the same
> > > > ram limits that the virt board has, especially since you
> > > > don't need to care about AArch32. Strongly consider
> > > > putting the RAM somwhere that lets you get up to a
> > > > maximum value that matches what we might expect in
> > > > server-class hardware.
> > > >
> > > > > +
> > > > > +static const MemMapEntry sbsa_ref_memmap[] = {
> > > > > +    /* Space up to 0x8000000 is reserved for a boot ROM */
> > > > > +    [VIRT_FLASH] =              {          0, 0x08000000 },
> > > > > +    [VIRT_CPUPERIPHS] =         { 0x08000000, 0x00020000 },
> > > > > +    /* GIC distributor and CPU interfaces sit inside the CPU
> peripheral space */
> > > > > +    [VIRT_GIC_DIST] =           { 0x08000000, 0x00010000 },
> > > > > +    [VIRT_GIC_CPU] =            { 0x08010000, 0x00010000 },
> > > > > +    /* The space in between here is reserved for GICv3
> CPU/vCPU/HYP */
> > > > > +    /* This redistributor space allows up to 2*64kB*123 CPUs */
> > > >
> > > > You don't need to do the split-redistributor layout that
> > > > "virt" does because you have no backwards compatibility
> > > > concerns. So make the space for redistributors big enough
> > > > to fit more CPUs in (at least 512, or more if you expect
> > > > this board to be used in future for development of a
> > > > software stack that handles more).
> > > >
> > > > > +    [VIRT_GIC_REDIST] =         { 0x080A0000, 0x00F60000 },
> > > > > +    [VIRT_UART] =               { 0x09000000, 0x00001000 },
> > > > > +    [VIRT_RTC] =                { 0x09010000, 0x00001000 },
> > > > > +    [VIRT_GPIO] =               { 0x09030000, 0x00001000 },
> > > > > +    [VIRT_SECURE_UART] =        { 0x09040000, 0x00001000 },
> > > > > +    [VIRT_AHCI] =               { 0x09050000, 0x00010000 },
> > > > > +    [VIRT_EHCI] =               { 0x09060000, 0x00010000 },
> > > > > +    [VIRT_SECURE_MEM] =         { 0x0e000000, 0x01000000 },
> > > > > +    [VIRT_PCIE_MMIO] =          { 0x10000000, 0x7fff0000 },
> > > > > +    [VIRT_PCIE_PIO] =           { 0x8fff0000, 0x00010000 },
> > > > > +    [VIRT_PCIE_ECAM] =          { 0x90000000, 0x10000000 },
> > > > > +    /* Second PCIe window, 508GB wide at the 4GB boundary */
> > > > > +    [VIRT_PCIE_MMIO_HIGH] =     { 0x100000000ULL, 0x7F00000000ULL
> },
> > > >
> > > > Again, you don't need the layout that "virt" has to
> > > > satisfy 32-bit guests and backwards compatibility. You
> > > > can just have a single large MMIO window.
> > > >
> > >
> > > Apologies for not spotting this at the time this was posted.
> > >
> > > The MMIO32 window is not there for the benefit of 32-bit only CPUs. It
> > > is there for the benefit of PCIe devices with 32-bit memory BARs
> > > which, given that our PCI MMIO is 1:1 mapped between the CPU and PCI
> > > address spaces, require a 32-bit addressable CPU mapping. (PCIe
> > > permits so-called 'legacy' endpoints to have 32-bit MMIO BARs)
> > >
> > > So please, reinstate the MMIO32 window, but keep the other one as well.
> > >
> > So we still use the old VIRT_PCIE_MMIO starting from fixed address
> > 0x10000000, or anywhere within 4G is OK?
> >
>
> Anywhere in the 32-bit addressable area is fine, but please align the
> window to its own size.
>
> > > Thanks,
> > > Ard.
> > >
> > > >
> > > > > +    [VIRT_MEM] =                { 0x8000000000ULL, RAMLIMIT_BYTES
> },
> > > > > +};
> > > > > +
> > > > > +static const int sbsa_ref_irqmap[] = {
> > > > > +    [VIRT_UART] = 1,
> > > > > +    [VIRT_RTC] = 2,
> > > > > +    [VIRT_PCIE] = 3, /* ... to 6 */
> > > > > +    [VIRT_GPIO] = 7,
> > > > > +    [VIRT_SECURE_UART] = 8,
> > > > > +    [VIRT_AHCI] = 9,
> > > > > +    [VIRT_EHCI] = 10,
> > > > > +};
> > > > > +
> > > > > +static void create_fdt(VirtMachineState *vms)
> > > > > +{
> > > > > +    void *fdt = create_device_tree(&vms->fdt_size);
> > > > > +
> > > > > +    if (!fdt) {
> > > > > +        error_report("create_device_tree() failed");
> > > > > +        exit(1);
> > > > > +    }
> > > > > +
> > > > > +    vms->fdt = fdt;
> > > > > +
> > > > > +    /* Header */
> > > > > +    qemu_fdt_setprop_string(fdt, "/", "compatible",
> "linux,dummy-virt");
> > > > > +    qemu_fdt_setprop_cell(fdt, "/", "#address-cells", 0x2);
> > > > > +    qemu_fdt_setprop_cell(fdt, "/", "#size-cells", 0x2);
> > > > > +
> > > > > +    /* /chosen must exist for load_dtb to fill in necessary
> properties later */
> > > > > +    qemu_fdt_add_subnode(fdt, "/chosen");
> > > > > +
> > > > > +    if (have_numa_distance) {
> > > > > +        int size = nb_numa_nodes * nb_numa_nodes * 3 *
> sizeof(uint32_t);
> > > > > +        uint32_t *matrix = g_malloc0(size);
> > > > > +        int idx, i, j;
> > > > > +
> > > > > +        for (i = 0; i < nb_numa_nodes; i++) {
> > > > > +            for (j = 0; j < nb_numa_nodes; j++) {
> > > > > +                idx = (i * nb_numa_nodes + j) * 3;
> > > > > +                matrix[idx + 0] = cpu_to_be32(i);
> > > > > +                matrix[idx + 1] = cpu_to_be32(j);
> > > > > +                matrix[idx + 2] =
> cpu_to_be32(numa_info[i].distance[j]);
> > > > > +            }
> > > > > +        }
> > > > > +
> > > > > +        qemu_fdt_add_subnode(fdt, "/distance-map");
> > > > > +        qemu_fdt_setprop_string(fdt, "/distance-map",
> "compatible",
> > > > > +                                "numa-distance-map-v1");
> > > > > +        qemu_fdt_setprop(fdt, "/distance-map", "distance-matrix",
> > > > > +                         matrix, size);
> > > > > +        g_free(matrix);
> > > > > +    }
> > > > > +}
> > > > > +
> > > > > +static void fdt_add_cpu_nodes(const VirtMachineState *vms)
> > > > > +{
> > > > > +    int cpu;
> > > > > +    const MachineState *ms = MACHINE(vms);
> > > > > +
> > > > > +    qemu_fdt_add_subnode(vms->fdt, "/cpus");
> > > > > +    /* #address-cells should be 2 for Arm v8 64-bit systems */
> > > > > +    qemu_fdt_setprop_cell(vms->fdt, "/cpus", "#address-cells", 2);
> > > > > +    qemu_fdt_setprop_cell(vms->fdt, "/cpus", "#size-cells", 0x0);
> > > > > +
> > > > > +    for (cpu = vms->smp_cpus - 1; cpu >= 0; cpu--) {
> > > > > +        char *nodename = g_strdup_printf("/cpus/cpu@%d", cpu);
> > > > > +        ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(cpu));
> > > > > +        CPUState *cs = CPU(armcpu);
> > > > > +
> > > > > +        qemu_fdt_add_subnode(vms->fdt, nodename);
> > > > > +        qemu_fdt_setprop_string(vms->fdt, nodename,
> "device_type", "cpu");
> > > > > +        qemu_fdt_setprop_string(vms->fdt, nodename, "compatible",
> > > > > +                                    armcpu->dtb_compatible);
> > > > > +
> > > > > +        if (vms->psci_conduit != QEMU_PSCI_CONDUIT_DISABLED
> > > > > +            && vms->smp_cpus > 1) {
> > > > > +            qemu_fdt_setprop_string(vms->fdt, nodename,
> > > > > +                                        "enable-method", "psci");
> > > > > +        }
> > > > > +
> > > > > +        qemu_fdt_setprop_u64(vms->fdt, nodename, "reg",
> armcpu->mp_affinity);
> > > > > +
> > > > > +        if
> (ms->possible_cpus->cpus[cs->cpu_index].props.has_node_id) {
> > > > > +            qemu_fdt_setprop_cell(vms->fdt, nodename,
> "numa-node-id",
> > > > > +
> ms->possible_cpus->cpus[cs->cpu_index].props.node_id);
> > > > > +        }
> > > > > +
> > > > > +        g_free(nodename);
> > > > > +    }
> > > > > +}
> > > > > +
> > > > > +static void fdt_add_gic_node(VirtMachineState *vms)
> > > > > +{
> > > > > +    char *nodename;
> > > > > +    int nb_redist_regions = virt_gicv3_redist_region_count(vms);
> > > > > +
> > > > > +    vms->gic_phandle = qemu_fdt_alloc_phandle(vms->fdt);
> > > > > +    qemu_fdt_setprop_cell(vms->fdt, "/", "interrupt-parent",
> vms->gic_phandle);
> > > > > +
> > > > > +    nodename = g_strdup_printf("/intc@%" PRIx64,
> > > > > +                               vms->memmap[VIRT_GIC_DIST].base);
> > > > > +    qemu_fdt_add_subnode(vms->fdt, nodename);
> > > > > +    qemu_fdt_setprop_cell(vms->fdt, nodename, "#interrupt-cells",
> 3);
> > > > > +    qemu_fdt_setprop(vms->fdt, nodename, "interrupt-controller",
> NULL, 0);
> > > > > +    qemu_fdt_setprop_cell(vms->fdt, nodename, "#address-cells",
> 0x2);
> > > > > +    qemu_fdt_setprop_cell(vms->fdt, nodename, "#size-cells", 0x2);
> > > > > +    qemu_fdt_setprop(vms->fdt, nodename, "ranges", NULL, 0);
> > > > > +
> > > > > +    /* Only GICv3 created */
> > > > > +    qemu_fdt_setprop_string(vms->fdt, nodename, "compatible",
> > > > > +                            "arm,gic-v3");
> > > > > +
> > > > > +    qemu_fdt_setprop_cell(vms->fdt, nodename,
> > > > > +                          "#redistributor-regions",
> nb_redist_regions);
> > > > > +
> > > > > +    if (nb_redist_regions == 1) {
> > > > > +        qemu_fdt_setprop_sized_cells(vms->fdt, nodename, "reg",
> > > > > +                                     2,
> vms->memmap[VIRT_GIC_DIST].base,
> > > > > +                                     2,
> vms->memmap[VIRT_GIC_DIST].size,
> > > > > +                                     2,
> vms->memmap[VIRT_GIC_REDIST].base,
> > > > > +                                     2,
> vms->memmap[VIRT_GIC_REDIST].size);
> > > > > +    } else {
> > > > > +        qemu_fdt_setprop_sized_cells(vms->fdt, nodename, "reg",
> > > > > +                                     2,
> vms->memmap[VIRT_GIC_DIST].base,
> > > > > +                                     2,
> vms->memmap[VIRT_GIC_DIST].size,
> > > > > +                                     2,
> vms->memmap[VIRT_GIC_REDIST].base,
> > > > > +                                     2,
> vms->memmap[VIRT_GIC_REDIST].size,
> > > > > +                                     2,
> vms->memmap[VIRT_GIC_REDIST2].base,
> > > > > +                                     2,
> vms->memmap[VIRT_GIC_REDIST2].size);
> > > > > +    }
> > > > > +
> > > > > +    if (vms->virt) {
> > > > > +        qemu_fdt_setprop_cells(vms->fdt, nodename, "interrupts",
> > > > > +                               GIC_FDT_IRQ_TYPE_PPI,
> ARCH_GICV3_MAINT_IRQ,
> > > > > +                               GIC_FDT_IRQ_FLAGS_LEVEL_HI);
> > > > > +    }
> > > > > +
> > > > > +    qemu_fdt_setprop_cell(vms->fdt, nodename, "phandle",
> vms->gic_phandle);
> > > > > +    g_free(nodename);
> > > > > +}
> > > >
> > > > This is still generating a lot of device tree nodes.
> > > > I thought we had agreed that we were going to just have
> > > > a minimal device tree that says "here is the RAM" and nothing
> > > > else ?
> > > >
> > > > > +
> > > > > +static void create_gic(VirtMachineState *vms, qemu_irq *pic)
> > > > > +{
> > > > > +    /* We create a standalone GIC */
> > > > > +    DeviceState *gicdev;
> > > > > +    SysBusDevice *gicbusdev;
> > > > > +    const char *gictype;
> > > > > +    int i;
> > > > > +    uint32_t nb_redist_regions = 0;
> > > > > +    uint32_t redist0_capacity, redist0_count;
> > > > > +
> > > > > +    /* Only GICv3 created */
> > > > > +    gictype = gicv3_class_name();
> > > > > +
> > > > > +    gicdev = 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);
> > > > > +    if (!kvm_irqchip_in_kernel()) {
> > > > > +        qdev_prop_set_bit(gicdev, "has-security-extensions",
> vms->secure);
> > > > > +    }
> > > > > +
> > > > > +    redist0_capacity =
> > > > > +                vms->memmap[VIRT_GIC_REDIST].size /
> GICV3_REDIST_SIZE;
> > > > > +    redist0_count = MIN(smp_cpus, redist0_capacity);
> > > > > +
> > > > > +    nb_redist_regions = virt_gicv3_redist_region_count(vms);
> > > > > +
> > > > > +    qdev_prop_set_uint32(gicdev, "len-redist-region-count",
> > > > > +                         nb_redist_regions);
> > > > > +    qdev_prop_set_uint32(gicdev, "redist-region-count[0]",
> redist0_count);
> > > > > +
> > > > > +    if (nb_redist_regions == 2) {
> > > > > +        uint32_t redist1_capacity =
> > > > > +                    vms->memmap[VIRT_GIC_REDIST2].size /
> GICV3_REDIST_SIZE;
> > > > > +
> > > > > +        qdev_prop_set_uint32(gicdev, "redist-region-count[1]",
> > > > > +            MIN(smp_cpus - redist0_count, redist1_capacity));
> > > > > +    }
> > > > > +
> > > > > +    qdev_init_nofail(gicdev);
> > > > > +    gicbusdev = SYS_BUS_DEVICE(gicdev);
> > > > > +    sysbus_mmio_map(gicbusdev, 0,
> vms->memmap[VIRT_GIC_DIST].base);
> > > > > +    sysbus_mmio_map(gicbusdev, 1,
> vms->memmap[VIRT_GIC_REDIST].base);
> > > > > +    if (nb_redist_regions == 2) {
> > > > > +        sysbus_mmio_map(gicbusdev, 2,
> vms->memmap[VIRT_GIC_REDIST2].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 inputs.
> > > > > +     */
> > > > > +    for (i = 0; i < smp_cpus; i++) {
> > > > > +        DeviceState *cpudev = DEVICE(qemu_get_cpu(i));
> > > > > +        int ppibase = 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 we use for the virt board.
> > > > > +         */
> > > > > +        const int timer_irq[] = {
> > > > > +            [GTIMER_PHYS] = ARCH_TIMER_NS_EL1_IRQ,
> > > > > +            [GTIMER_VIRT] = ARCH_TIMER_VIRT_IRQ,
> > > > > +            [GTIMER_HYP]  = ARCH_TIMER_NS_EL2_IRQ,
> > > > > +            [GTIMER_SEC]  = ARCH_TIMER_S_EL1_IRQ,
> > > > > +        };
> > > > > +
> > > > > +        for (irq = 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_GICV3_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 = 0; i < NUM_IRQS; i++) {
> > > > > +        pic[i] = qdev_get_gpio_in(gicdev, i);
> > > > > +    }
> > > > > +
> > > > > +    fdt_add_gic_node(vms);
> > > > > +}
> > > > > +
> > > > > +static void create_uart(const VirtMachineState *vms, qemu_irq
> *pic, int uart,
> > > > > +                        MemoryRegion *mem, Chardev *chr)
> > > > > +{
> > > > > +    hwaddr base = vms->memmap[uart].base;
> > > > > +    int irq = vms->irqmap[uart];
> > > > > +    DeviceState *dev = qdev_create(NULL, "pl011");
> > > > > +    SysBusDevice *s = 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 VirtMachineState *vms, qemu_irq *pic)
> > > > > +{
> > > > > +    hwaddr base = vms->memmap[VIRT_RTC].base;
> > > > > +    int irq = vms->irqmap[VIRT_RTC];
> > > > > +
> > > > > +    sysbus_create_simple("pl031", base, pic[irq]);
> > > > > +}
> > > > > +
> > > > > +static void create_ahci(const VirtMachineState *vms, qemu_irq
> *pic)
> > > > > +{
> > > > > +    hwaddr base = vms->memmap[VIRT_AHCI].base;
> > > > > +    int irq = vms->irqmap[VIRT_AHCI];
> > > > > +    DeviceState *dev;
> > > > > +    DriveInfo *hd[SATA_NUM_PORTS];
> > > > > +    SysbusAHCIState *sysahci;
> > > > > +    AHCIState *ahci;
> > > > > +    int i;
> > > > > +
> > > > > +    dev = qdev_create(NULL, "sysbus-ahci");
> > > > > +    qdev_prop_set_uint32(dev, "num-ports", SATA_NUM_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 = SYSBUS_AHCI(dev);
> > > > > +    ahci = &sysahci->ahci;
> > > > > +    ide_drive_get(hd, ARRAY_SIZE(hd));
> > > > > +    for (i = 0; i < ahci->ports; i++) {
> > > > > +        if (hd[i] == NULL) {
> > > > > +            continue;
> > > > > +        }
> > > > > +        ide_create_drive(&ahci->dev[i].port, 0, hd[i]);
> > > > > +    }
> > > > > +}
> > > > > +
> > > > > +static void create_ehci(const VirtMachineState *vms, qemu_irq
> *pic)
> > > > > +{
> > > > > +    hwaddr base = vms->memmap[VIRT_EHCI].base;
> > > > > +    int irq = vms->irqmap[VIRT_EHCI];
> > > > > +    USBBus *usb_bus;
> > > > > +
> > > > > +    sysbus_create_simple("exynos4210-ehci-usb", base, pic[irq]);
> > > >
> > > > What is this using the exynos4210 USB device for? That
> > > > is definitely not correct for a generic board.
> > > >
> > > > > +
> > > > > +    usb_bus = usb_bus_find(-1);
> > > > > +    usb_create_simple(usb_bus, "usb-kbd");
> > > > > +    usb_create_simple(usb_bus, "usb-mouse");
> > > >
> > > > Don't create USB devices by default -- let the user do it on
> > > > the command line.
> > > >
> > > > > +}
> > > > > +
> > > > > +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 = {
> > > > > +    .notify = sbsa_ref_powerdown_req
> > > > > +};
> > > > > +
> > > > > +static void create_gpio(const VirtMachineState *vms, qemu_irq
> *pic)
> > > > > +{
> > > > > +    DeviceState *pl061_dev;
> > > > > +    hwaddr base = vms->memmap[VIRT_GPIO].base;
> > > > > +    int irq = vms->irqmap[VIRT_GPIO];
> > > > > +
> > > > > +    pl061_dev = sysbus_create_simple("pl061", base, pic[irq]);
> > > > > +
> > > > > +    gpio_key_dev = 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_one_flash(const char *name, hwaddr flashbase,
> > > > > +                             hwaddr flashsize, const char *file,
> > > > > +                             MemoryRegion *sysmem)
> > > > > +{
> > > > > +    /* Create and map a single flash device. We use the same
> > > > > +     * parameters as the flash devices on the Versatile Express
> board.
> > > > > +     */
> > > > > +    DriveInfo *dinfo = drive_get_next(IF_PFLASH);
> > > > > +    DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
> > > > > +    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
> > > > > +    const uint64_t sectorlength = 256 * 1024;
> > > > > +
> > > > > +    if (dinfo) {
> > > > > +        qdev_prop_set_drive(dev, "drive",
> blk_by_legacy_dinfo(dinfo),
> > > > > +                            &error_abort);
> > > > > +    }
> > > > > +
> > > > > +    qdev_prop_set_uint32(dev, "num-blocks", flashsize /
> sectorlength);
> > > > > +    qdev_prop_set_uint64(dev, "sector-length", sectorlength);
> > > > > +    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);
> > > > > +    qdev_init_nofail(dev);
> > > > > +
> > > > > +    memory_region_add_subregion(sysmem, flashbase,
> > > > > +
> sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0));
> > > > > +
> > > > > +    if (file) {
> > > > > +        char *fn;
> > > > > +        int image_size;
> > > > > +
> > > > > +        if (drive_get(IF_PFLASH, 0, 0)) {
> > > > > +            error_report("The contents of the first flash device
> may be "
> > > > > +                         "specified with -bios or with -drive
> if=pflash... "
> > > > > +                         "but you cannot use both options at
> once");
> > > > > +            exit(1);
> > > > > +        }
> > > > > +        fn = qemu_find_file(QEMU_FILE_TYPE_BIOS, file);
> > > > > +        if (!fn) {
> > > > > +            error_report("Could not find ROM image '%s'", file);
> > > > > +            exit(1);
> > > > > +        }
> > > > > +        image_size = load_image_mr(fn,
> sysbus_mmio_get_region(sbd, 0));
> > > > > +        g_free(fn);
> > > > > +        if (image_size < 0) {
> > > > > +            error_report("Could not load ROM image '%s'", file);
> > > > > +            exit(1);
> > > > > +        }
> > > > > +    }
> > > > > +}
> > > > > +
> > > > > +static void create_flash(const VirtMachineState *vms,
> > > > > +                         MemoryRegion *sysmem,
> > > > > +                         MemoryRegion *secure_sysmem)
> > > > > +{
> > > > > +    /* Create two flash devices to fill the VIRT_FLASH space in
> the memmap.
> > > > > +     * Any file passed via -bios goes in the first of these.
> > > > > +     * sysmem is the system memory space. secure_sysmem is the
> secure view
> > > > > +     * of the system, and the first flash device should be made
> visible only
> > > > > +     * there. The second flash device is visible to both secure
> and nonsecure.
> > > > > +     * If sysmem == secure_sysmem this means there is no separate
> Secure
> > > > > +     * address space and both flash devices are generally visible.
> > > > > +     */
> > > > > +    hwaddr flashsize = vms->memmap[VIRT_FLASH].size / 2;
> > > > > +    hwaddr flashbase = vms->memmap[VIRT_FLASH].base;
> > > > > +
> > > > > +    create_one_flash("sbsa-ref.flash0", flashbase, flashsize,
> > > > > +                     bios_name, secure_sysmem);
> > > > > +    create_one_flash("sbsa-ref.flash1", flashbase + flashsize,
> flashsize,
> > > > > +                     NULL, sysmem);
> > > > > +}
> > > > > +
> > > > > +static void create_smmu(const VirtMachineState *vms, qemu_irq
> *pic,
> > > > > +                        PCIBus *bus)
> > > > > +{
> > > > > +    int irq =  vms->irqmap[VIRT_SMMU];
> > > > > +    int i;
> > > > > +    hwaddr base = vms->memmap[VIRT_SMMU].base;
> > > > > +    DeviceState *dev;
> > > > > +
> > > > > +    if (vms->iommu != VIRT_IOMMU_SMMUV3) {
> > > > > +        return;
> > > > > +    }
> > > > > +
> > > > > +    dev = 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 = 0; i < NUM_SMMU_IRQS; i++) {
> > > > > +        sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, pic[irq + i]);
> > > > > +    }
> > > > > +}
> > > > > +
> > > > > +static void create_pcie(VirtMachineState *vms, qemu_irq *pic)
> > > > > +{
> > > > > +    hwaddr base_mmio = vms->memmap[VIRT_PCIE_MMIO].base;
> > > > > +    hwaddr size_mmio = vms->memmap[VIRT_PCIE_MMIO].size;
> > > > > +    hwaddr base_mmio_high = vms->memmap[VIRT_PCIE_MMIO_HIGH].base;
> > > > > +    hwaddr size_mmio_high = vms->memmap[VIRT_PCIE_MMIO_HIGH].size;
> > > > > +    hwaddr base_pio = vms->memmap[VIRT_PCIE_PIO].base;
> > > > > +    hwaddr base_ecam, size_ecam;
> > > > > +    int irq = vms->irqmap[VIRT_PCIE];
> > > > > +    MemoryRegion *mmio_alias;
> > > > > +    MemoryRegion *mmio_reg;
> > > > > +    MemoryRegion *ecam_alias;
> > > > > +    MemoryRegion *ecam_reg;
> > > > > +    DeviceState *dev;
> > > > > +    int i, ecam_id;
> > > > > +    PCIHostState *pci;
> > > > > +
> > > > > +    dev = qdev_create(NULL, TYPE_GPEX_HOST);
> > > > > +    qdev_init_nofail(dev);
> > > > > +
> > > > > +    ecam_id = VIRT_ECAM_ID(vms->highmem_ecam);
> > > > > +    base_ecam = vms->memmap[ecam_id].base;
> > > > > +    size_ecam = vms->memmap[ecam_id].size;
> > > > > +    /* Map only the first size_ecam bytes of ECAM space */
> > > > > +    ecam_alias = g_new0(MemoryRegion, 1);
> > > > > +    ecam_reg = 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 window into system address space so as to
> expose
> > > > > +     * the section of PCI MMIO space which starts at the same
> base address
> > > > > +     * (ie 1:1 mapping for that part of PCI MMIO space visible
> through
> > > > > +     * the window).
> > > > > +     */
> > > > > +    mmio_alias = g_new0(MemoryRegion, 1);
> > > > > +    mmio_reg = 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);
> > > > > +
> > > > > +    if (vms->highmem) {
> > > > > +        /* Map high MMIO space */
> > > > > +        MemoryRegion *high_mmio_alias = g_new0(MemoryRegion, 1);
> > > > > +
> > > > > +        memory_region_init_alias(high_mmio_alias, OBJECT(dev),
> "pcie-mmio-high",
> > > > > +                                 mmio_reg, base_mmio_high,
> size_mmio_high);
> > > > > +        memory_region_add_subregion(get_system_memory(),
> base_mmio_high,
> > > > > +                                    high_mmio_alias);
> > > > > +    }
> > > > > +
> > > > > +    /* Map IO port space */
> > > > > +    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, base_pio);
> > > > > +
> > > > > +    for (i = 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 = PCI_HOST_BRIDGE(dev);
> > > > > +    if (pci->bus) {
> > > > > +        for (i = 0; i < nb_nics; i++) {
> > > > > +            NICInfo *nd = &nd_table[i];
> > > > > +
> > > > > +            if (!nd->model) {
> > > > > +                nd->model = g_strdup("e1000e");
> > > > > +            }
> > > > > +
> > > > > +            pci_nic_init_nofail(nd, pci->bus, nd->model, NULL);
> > > > > +        }
> > > > > +    }
> > > > > +
> > > > > +    pci_create_simple(pci->bus, -1, "VGA");
> > > > > +
> > > > > +    if (vms->iommu) {
> > > > > +        create_smmu(vms, pic, pci->bus);
> > > > > +    }
> > > > > +}
> > > > > +
> > > > > +static void create_secure_ram(VirtMachineState *vms,
> > > > > +                              MemoryRegion *secure_sysmem)
> > > > > +{
> > > > > +    MemoryRegion *secram = g_new(MemoryRegion, 1);
> > > > > +    hwaddr base = vms->memmap[VIRT_SECURE_MEM].base;
> > > > > +    hwaddr size = vms->memmap[VIRT_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 *sbsa_ref_dtb(const struct arm_boot_info *binfo, int
> *fdt_size)
> > > > > +{
> > > > > +    const VirtMachineState *board = container_of(binfo,
> VirtMachineState,
> > > > > +                                                 bootinfo);
> > > > > +
> > > > > +    *fdt_size = board->fdt_size;
> > > > > +    return board->fdt;
> > > > > +}
> > > > > +
> > > > > +static
> > > > > +void sbsa_ref_machine_done(Notifier *notifier, void *data)
> > > > > +{
> > > > > +    VirtMachineState *vms = container_of(notifier,
> VirtMachineState,
> > > > > +                                         machine_done);
> > > > > +    ARMCPU *cpu = ARM_CPU(first_cpu);
> > > > > +    struct arm_boot_info *info = &vms->bootinfo;
> > > > > +    AddressSpace *as = arm_boot_address_space(cpu, info);
> > > > > +
> > > > > +    if (arm_load_dtb(info->dtb_start, info, info->dtb_limit, as)
> < 0) {
> > > > > +        exit(1);
> > > > > +    }
> > > > > +}
> > > >
> > > > The virt board needs a machine-done notifier because it has
> > > > to add extra things to the DTB here. You don't, so you don't
> > > > need one. Don't set bootinfo.skip_dtb_autoload to true, and
> > > > then the boot.c code will do the arm_load_dtb() call for you.
> > > >
> > > > > +
> > > > > +static void sbsa_ref_init(MachineState *machine)
> > > > > +{
> > > > > +    VirtMachineState *vms = VIRT_MACHINE(machine);
> > > > > +    VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(machine);
> > > > > +    MachineClass *mc = MACHINE_GET_CLASS(machine);
> > > > > +    const CPUArchIdList *possible_cpus;
> > > > > +    qemu_irq pic[NUM_IRQS];
> > > > > +    MemoryRegion *sysmem = get_system_memory();
> > > > > +    MemoryRegion *secure_sysmem = NULL;
> > > > > +    int n, sbsa_max_cpus;
> > > > > +    MemoryRegion *ram = g_new(MemoryRegion, 1);
> > > > > +    bool firmware_loaded = bios_name || drive_get(IF_PFLASH, 0,
> 0);
> > > > > +    bool aarch64 = true;
> > > > > +
> > > > > +    if (strcmp(machine->cpu_type,
> ARM_CPU_TYPE_NAME("cortex-a57"))) {
> > > > > +        error_report("sbsa-ref: CPU type %s not supported",
> machine->cpu_type);
> > > > > +        exit(1);
> > > > > +    }
> > > > > +
> > > > > +    if (kvm_enabled()) {
> > > > > +        error_report("sbsa-ref: KVM is not supported at 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 loaded, "
> > > > > +                     "please load hard disk instead");
> > > > > +        exit(1);
> > > > > +    }
> > > >
> > > > If ther is no fw_cfg device, why does your memory map datastructure
> > > > have an entry for it earlier ?
> > > > > +    [VIRT_FW_CFG] =             { 0x09020000, 0x00000018 },
> > > >
> > > > > +
> > > > > +    /* If we have an EL3 boot ROM then the assumption is that it
> will
> > > > > +     * implement PSCI itself, so disable QEMU's internal
> implementation
> > > > > +     * so it doesn't get in the way. Instead of starting secondary
> > > > > +     * CPUs in PSCI powerdown state we will start them all
> running and
> > > > > +     * let the boot ROM sort them out.
> > > > > +     * The usual case is that we do use QEMU's PSCI
> implementation;
> > > > > +     * if the guest has EL2 then we will use SMC as the conduit,
> > > > > +     * and otherwise we will use HVC (for backwards compatibility
> and
> > > > > +     * because if we're using KVM then we must use HVC).
> > > > > +     */
> > > > > +    if (vms->secure && firmware_loaded) {
> > > > > +        vms->psci_conduit = QEMU_PSCI_CONDUIT_DISABLED;
> > > > > +    } else if (vms->virt) {
> > > > > +        vms->psci_conduit = QEMU_PSCI_CONDUIT_SMC;
> > > > > +    } else {
> > > > > +        vms->psci_conduit = QEMU_PSCI_CONDUIT_HVC;
> > > > > +    }
> > > >
> > > > Do you actually intend this to work in all these cases? I
> > > > thought the intention was "always start the boot rom in EL3"
> > > > for this board, like the real hardware would. In that case, most
> > > > of these if clauses are dead code.
> > > >
> > > > > +
> > > > > +    /* Only GICv3 is uesd in this machine */
> > > > > +    sbsa_max_cpus = vms->memmap[VIRT_GIC_REDIST].size /
> GICV3_REDIST_SIZE;
> > > > > +    sbsa_max_cpus += vms->memmap[VIRT_GIC_REDIST2].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);
> > > > > +    }
> > > > > +
> > > > > +    vms->smp_cpus = smp_cpus;
> > > > > +
> > > > > +    if (machine->ram_size > vms->memmap[VIRT_MEM].size) {
> > > > > +        error_report("sbsa-ref: cannot model more than %dGB RAM",
> RAMLIMIT_GB);
> > > > > +        exit(1);
> > > > > +    }
> > > > > +
> > > > > +    if (vms->secure) {
> > > > > +        /* 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 = 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);
> > > > > +    }
> > > >
> > > > Again, unless you intentionally want to support both "has EL3"
> > > > and "does not have EL3" configs for this board, you don't need
> > > > to do this conditionally.
> > > >
> > > > > +
> > > > > +    create_fdt(vms);
> > > > > +
> > > > > +    possible_cpus = mc->possible_cpu_arch_ids(machine);
> > > > > +    for (n = 0; n < possible_cpus->len; n++) {
> > > > > +        Object *cpuobj;
> > > > > +        CPUState *cs;
> > > > > +
> > > > > +        if (n >= smp_cpus) {
> > > > > +            break;
> > > > > +        }
> > > > > +
> > > > > +        cpuobj = object_new(possible_cpus->cpus[n].type);
> > > > > +        object_property_set_int(cpuobj,
> possible_cpus->cpus[n].arch_id,
> > > > > +                                "mp-affinity", NULL);
> > > > > +
> > > > > +        cs = CPU(cpuobj);
> > > > > +        cs->cpu_index = n;
> > > > > +
> > > > > +        numa_cpu_pre_plug(&possible_cpus->cpus[cs->cpu_index],
> DEVICE(cpuobj),
> > > > > +                          &error_fatal);
> > > > > +
> > > > > +        aarch64 &= object_property_get_bool(cpuobj, "aarch64",
> NULL);
> > > > > +
> > > > > +        if (!vms->secure) {
> > > > > +            object_property_set_bool(cpuobj, false, "has_el3",
> NULL);
> > > > > +        }
> > > > > +
> > > > > +        if (!vms->virt && object_property_find(cpuobj, "has_el2",
> NULL)) {
> > > > > +            object_property_set_bool(cpuobj, false, "has_el2",
> NULL);
> > > > > +        }
> > > > > +
> > > > > +        if (vms->psci_conduit != QEMU_PSCI_CONDUIT_DISABLED) {
> > > > > +            object_property_set_int(cpuobj, vms->psci_conduit,
> > > > > +                                    "psci-conduit", NULL);
> > > > > +
> > > > > +            /* Secondary CPUs start in PSCI powered-down state */
> > > > > +            if (n > 0) {
> > > > > +                object_property_set_bool(cpuobj, true,
> > > > > +                                         "start-powered-off",
> NULL);
> > > > > +            }
> > > > > +        }
> > > > > +
> > > > > +        if (vmc->no_pmu && object_property_find(cpuobj, "pmu",
> NULL)) {
> > > > > +            object_property_set_bool(cpuobj, false, "pmu", NULL);
> > > > > +        }
> > > > > +
> > > > > +        if (object_property_find(cpuobj, "reset-cbar", NULL)) {
> > > > > +            object_property_set_int(cpuobj,
> vms->memmap[VIRT_CPUPERIPHS].base,
> > > > > +                                    "reset-cbar", &error_abort);
> > > > > +        }
> > > > > +
> > > > > +        object_property_set_link(cpuobj, OBJECT(sysmem), "memory",
> > > > > +                                 &error_abort);
> > > > > +        if (vms->secure) {
> > > > > +            object_property_set_link(cpuobj,
> OBJECT(secure_sysmem),
> > > > > +                                     "secure-memory",
> &error_abort);
> > > > > +        }
> > > > > +
> > > > > +        object_property_set_bool(cpuobj, true, "realized",
> &error_fatal);
> > > > > +        object_unref(cpuobj);
> > > > > +    }
> > > > > +    fdt_add_cpu_nodes(vms);
> > > > > +
> > > > > +    memory_region_allocate_system_memory(ram, NULL,
> "sbsa-ref.ram",
> > > > > +                                         machine->ram_size);
> > > > > +    memory_region_add_subregion(sysmem,
> vms->memmap[VIRT_MEM].base, ram);
> > > > > +
> > > > > +    create_flash(vms, sysmem, secure_sysmem ? secure_sysmem :
> sysmem);
> > > > > +
> > > > > +    create_gic(vms, pic);
> > > > > +
> > > > > +    create_uart(vms, pic, VIRT_UART, sysmem, serial_hd(0));
> > > > > +
> > > > > +    if (vms->secure) {
> > > > > +        create_secure_ram(vms, secure_sysmem);
> > > > > +        create_uart(vms, pic, VIRT_SECURE_UART, secure_sysmem,
> serial_hd(1));
> > > > > +    }
> > > > > +
> > > > > +    vms->highmem_ecam &= vms->highmem && (!firmware_loaded ||
> aarch64);
> > > > > +
> > > > > +    create_rtc(vms, pic);
> > > > > +
> > > > > +    create_pcie(vms, pic);
> > > > > +
> > > > > +    create_gpio(vms, pic);
> > > > > +
> > > > > +    create_ahci(vms, pic);
> > > > > +
> > > > > +    create_ehci(vms, pic);
> > > > > +
> > > > > +    vms->bootinfo.ram_size = machine->ram_size;
> > > > > +    vms->bootinfo.kernel_filename = machine->kernel_filename;
> > > > > +    vms->bootinfo.kernel_cmdline = machine->kernel_cmdline;
> > > > > +    vms->bootinfo.initrd_filename = machine->initrd_filename;
> > > > > +    vms->bootinfo.nb_cpus = smp_cpus;
> > > > > +    vms->bootinfo.board_id = -1;
> > > > > +    vms->bootinfo.loader_start = vms->memmap[VIRT_MEM].base;
> > > > > +    vms->bootinfo.get_dtb = sbsa_ref_dtb;
> > > > > +    vms->bootinfo.skip_dtb_autoload = true;
> > > > > +    vms->bootinfo.firmware_loaded = firmware_loaded;
> > > > > +    arm_load_kernel(ARM_CPU(first_cpu), &vms->bootinfo);
> > > > > +
> > > > > +    vms->machine_done.notify = sbsa_ref_machine_done;
> > > > > +    qemu_add_machine_init_done_notifier(&vms->machine_done);
> > > > > +}
> > > > > +
> > > > > +static bool sbsa_ref_get_secure(Object *obj, Error **errp)
> > > > > +{
> > > > > +    VirtMachineState *vms = VIRT_MACHINE(obj);
> > > > > +
> > > > > +    return vms->secure;
> > > > > +}
> > > > > +
> > > > > +static void sbsa_ref_set_secure(Object *obj, bool value, Error
> **errp)
> > > > > +{
> > > > > +    VirtMachineState *vms = VIRT_MACHINE(obj);
> > > > > +
> > > > > +    vms->secure = value;
> > > > > +}
> > > > > +
> > > > > +static bool sbsa_ref_get_virt(Object *obj, Error **errp)
> > > > > +{
> > > > > +    VirtMachineState *vms = VIRT_MACHINE(obj);
> > > > > +
> > > > > +    return vms->virt;
> > > > > +}
> > > > > +
> > > > > +static void sbsa_ref_set_virt(Object *obj, bool value, Error
> **errp)
> > > > > +{
> > > > > +    VirtMachineState *vms = VIRT_MACHINE(obj);
> > > > > +
> > > > > +    vms->virt = value;
> > > > > +}
> > > > > +
> > > > > +static CpuInstanceProperties
> > > > > +sbsa_ref_cpu_index_to_props(MachineState *ms, unsigned cpu_index)
> > > > > +{
> > > > > +    MachineClass *mc = MACHINE_GET_CLASS(ms);
> > > > > +    const CPUArchIdList *possible_cpus =
> 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 uint64_t sbsa_ref_cpu_mp_affinity(VirtMachineState *vms,
> int idx)
> > > > > +{
> > > > > +    uint8_t clustersz = ARM_DEFAULT_CPUS_PER_CLUSTER;
> > > > > +    VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(vms);
> > > > > +
> > > > > +    if (!vmc->disallow_affinity_adjustment) {
> > > > > +        /* Only GICv3 is used in this machine */
> > > > > +        clustersz = GICV3_TARGETLIST_BITS;
> > > > > +    }
> > > > > +    return arm_cpu_mp_affinity(idx, clustersz);
> > > > > +}
> > > > > +
> > > > > +static const CPUArchIdList
> *sbsa_ref_possible_cpu_arch_ids(MachineState *ms)
> > > > > +{
> > > > > +    int n;
> > > > > +    VirtMachineState *vms = VIRT_MACHINE(ms);
> > > > > +
> > > > > +    if (ms->possible_cpus) {
> > > > > +        assert(ms->possible_cpus->len == max_cpus);
> > > > > +        return ms->possible_cpus;
> > > > > +    }
> > > > > +
> > > > > +    ms->possible_cpus = g_malloc0(sizeof(CPUArchIdList) +
> > > > > +                                  sizeof(CPUArchId) * max_cpus);
> > > > > +    ms->possible_cpus->len = max_cpus;
> > > > > +    for (n = 0; n < ms->possible_cpus->len; n++) {
> > > > > +        ms->possible_cpus->cpus[n].type = ms->cpu_type;
> > > > > +        ms->possible_cpus->cpus[n].arch_id =
> > > > > +            sbsa_ref_cpu_mp_affinity(vms, n);
> > > > > +        ms->possible_cpus->cpus[n].props.has_thread_id = true;
> > > > > +        ms->possible_cpus->cpus[n].props.thread_id = n;
> > > > > +    }
> > > > > +    return ms->possible_cpus;
> > > > > +}
> > > > > +
> > > > > +static void sbsa_ref_instance_init(Object *obj)
> > > > > +{
> > > > > +    VirtMachineState *vms = VIRT_MACHINE(obj);
> > > > > +
> > > > > +    vms->secure = true;
> > > > > +    object_property_add_bool(obj, "secure", sbsa_ref_get_secure,
> > > > > +                             sbsa_ref_set_secure, NULL);
> > > > > +    object_property_set_description(obj, "secure",
> > > > > +                                    "Set on/off to enable/disable
> the ARM "
> > > > > +                                    "Security Extensions
> (TrustZone)",
> > > > > +                                    NULL);
> > > > > +
> > > > > +    vms->virt = true;
> > > > > +    object_property_add_bool(obj, "virtualization",
> sbsa_ref_get_virt,
> > > > > +                             sbsa_ref_set_virt, NULL);
> > > > > +    object_property_set_description(obj, "virtualization",
> > > > > +                                    "Set on/off to enable/disable
> emulating a "
> > > > > +                                    "guest CPU which implements
> the ARM "
> > > > > +                                    "Virtualization Extensions",
> > > > > +                                    NULL);
> > > >
> > > > Drop the properties unless you need to actually support
> > > > all the different variations.
> > > >
> > > > > +
> > > > > +    vms->highmem = true;
> > > > > +    vms->iommu = VIRT_IOMMU_NONE;
> > > > > +    vms->gic_version = 3;
> > > > > +    vms->memmap = sbsa_ref_memmap;
> > > > > +    vms->irqmap = sbsa_ref_irqmap;
> > > > > +}
> > > > > +
> > > > > +static void sbsa_ref_class_init(ObjectClass *oc, void *data)
> > > > > +{
> > > > > +    MachineClass *mc = MACHINE_CLASS(oc);
> > > > > +
> > > > > +    mc->init = sbsa_ref_init;
> > > > > +    mc->max_cpus = 246;
> > > > > +    mc->block_default_type = IF_IDE;
> > > > > +    mc->no_cdrom = 1;
> > > > > +    mc->pci_allow_0_address = true;
> > > > > +    mc->minimum_page_bits = 12;
> > > > > +    mc->possible_cpu_arch_ids = sbsa_ref_possible_cpu_arch_ids;
> > > > > +    mc->cpu_index_to_instance_props = sbsa_ref_cpu_index_to_props;
> > > > > +    mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a57");
> > > > > +    mc->get_default_cpu_node_id =
> sbsa_ref_get_default_cpu_node_id;
> > > > > +    mc->default_ram_size = 1 * GiB;
> > > > > +    mc->default_cpus = 4;
> > > > > +    mc->desc = "QEMU 'SBSA Reference' ARM Virtual Machine";
> > > > > +}
> > > > > +
> > > > > +static const TypeInfo sbsa_ref_info = {
> > > > > +    .name          = MACHINE_TYPE_NAME("sbsa-ref"),
> > > > > +    .parent        = TYPE_VIRT_MACHINE,
> > > > > +    .instance_init = sbsa_ref_instance_init,
> > > > > +    .class_init    = sbsa_ref_class_init,
> > > > > +};
> > > > > +
> > > > > +static void sbsa_ref_machine_init(void)
> > > > > +{
> > > > > +    type_register_static(&sbsa_ref_info);
> > > > > +}
> > > > > +
> > > > > +type_init(sbsa_ref_machine_init);
> > > > > diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
> > > > > index 9a870cc..f6c48be 100644
> > > > > --- a/include/hw/arm/virt.h
> > > > > +++ b/include/hw/arm/virt.h
> > > > > @@ -78,6 +78,8 @@ enum {
> > > > >      VIRT_GPIO,
> > > > >      VIRT_SECURE_UART,
> > > > >      VIRT_SECURE_MEM,
> > > > > +    VIRT_AHCI,
> > > > > +    VIRT_EHCI,
> > > > >  };
> > > > >
> > > > >  typedef enum VirtIOMMUType {
> > > > > --
> > > >
> > > > thanks
> > > > -- PMM
>

[Attachment #3 (text/html)]

<div dir="ltr"><div dir="ltr"><div dir="ltr">Hongbo,  <div><br></div><div>Take a look \
at last patch in:  ssh://<a \
href="http://git@git.linaro.org/people/radoslaw.biernacki/qemu.git">git@git.linaro.org/people/radoslaw.biernacki/qemu.git</a></div><div>branch \
wip_rad_new_memmap</div></div></div></div><br><div class="gmail_quote"><div dir="ltr" \
class="gmail_attr">On Wed, 30 Jan 2019 at 09:37, Ard Biesheuvel &lt;<a \
href="mailto:ard.biesheuvel@linaro.org">ard.biesheuvel@linaro.org</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wed, 30 Jan 2019 at \
09:34, Hongbo Zhang &lt;<a href="mailto:hongbo.zhang@linaro.org" \
target="_blank">hongbo.zhang@linaro.org</a>&gt; wrote:<br> &gt;<br>
&gt; On Tue, 29 Jan 2019 at 19:29, Ard Biesheuvel &lt;<a \
href="mailto:ard.biesheuvel@linaro.org" \
target="_blank">ard.biesheuvel@linaro.org</a>&gt; wrote:<br> &gt; &gt;<br>
&gt; &gt; Responding to an old thread ...<br>
&gt; &gt;<br>
&gt; &gt; On Thu, 15 Nov 2018 at 17:05, Peter Maydell &lt;<a \
href="mailto:peter.maydell@linaro.org" \
target="_blank">peter.maydell@linaro.org</a>&gt; wrote:<br> &gt; &gt; &gt;<br>
&gt; &gt; &gt; On 19 October 2018 at 09:55, Hongbo Zhang &lt;<a \
href="mailto:hongbo.zhang@linaro.org" target="_blank">hongbo.zhang@linaro.org</a>&gt; \
wrote:<br> &gt; &gt; &gt; &gt; For the Aarch64, there is one machine &#39;virt&#39;, \
it is primarily meant to<br> &gt; &gt; &gt; &gt; run on KVM and execute \
virtualization workloads, but we need an<br> &gt; &gt; &gt; &gt; environment as \
faithful as possible to physical hardware, for supporting<br> &gt; &gt; &gt; &gt; \
firmware and OS development for pysical Aarch64 machines.<br> &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; This patch introduces new machine type &#39;sbsa-ref&#39; with \
main features:<br> &gt; &gt; &gt; &gt;   - Based on &#39;virt&#39; machine type.<br>
&gt; &gt; &gt; &gt;   - CPU type cortex-a57.<br>
&gt; &gt; &gt; &gt;   - EL2 and EL3 are enabled by default.<br>
&gt; &gt; &gt; &gt;   - GIC version 3 only.<br>
&gt; &gt; &gt; &gt;   - Re-designed memory map.<br>
&gt; &gt; &gt; &gt;   - AHCI controller attached to system bus.<br>
&gt; &gt; &gt; &gt;   - EHCI controller attached to system bus.<br>
&gt; &gt; &gt; &gt;   - CDROM and hard disc on AHCI bus.<br>
&gt; &gt; &gt; &gt;   - USB mouse and key board.<br>
&gt; &gt; &gt; &gt;   - E1000E ethernet card on PCIE bus.<br>
&gt; &gt; &gt; &gt;   - VGA display adaptor on PCIE bus.<br>
&gt; &gt; &gt; &gt;   - No virtio deivces.<br>
&gt; &gt; &gt; &gt;   - No paravirtualized fw_cfg device.<br>
&gt; &gt; &gt; &gt;   - No ACPI table supplied.<br>
&gt; &gt; &gt; &gt;   - Only minimal device tree nodes.<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; Arm Trusted Firmware and UEFI porting to this are done \
accordingly.<br> &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; Signed-off-by: Hongbo Zhang &lt;<a \
href="mailto:hongbo.zhang@linaro.org" \
target="_blank">hongbo.zhang@linaro.org</a>&gt;<br> &gt; &gt; &gt;<br>
&gt; &gt; &gt; Hi; I&#39;ve had a quick run through this patch. My comments<br>
&gt; &gt; &gt; below are mostly about there still being a lot of code<br>
&gt; &gt; &gt; here which has been copied from virt.c but which you do<br>
&gt; &gt; &gt; not need.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; If after you&#39;ve done that this patch is still more than<br>
&gt; &gt; &gt; about 500 lines long, I would recommend that you split it<br>
&gt; &gt; &gt; up into coherent pieces, to make it easier to review.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; ---<br>
&gt; &gt; &gt; &gt;   hw/arm/Makefile.objs   |     2 +-<br>
&gt; &gt; &gt; &gt;   hw/arm/sbsa-ref.c        | 937 \
++++++++++++++++++++++++++++++++++++++++++++++++++<br> &gt; &gt; &gt; &gt;   \
include/hw/arm/virt.h |     2 +<br> &gt; &gt; &gt; &gt;   3 files changed, 940 \
insertions(+), 1 deletion(-)<br> &gt; &gt; &gt; &gt;   create mode 100644 \
hw/arm/sbsa-ref.c<br> &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs<br>
&gt; &gt; &gt; &gt; index d51fcec..a8895eb 100644<br>
&gt; &gt; &gt; &gt; --- a/hw/arm/Makefile.objs<br>
&gt; &gt; &gt; &gt; +++ b/hw/arm/Makefile.objs<br>
&gt; &gt; &gt; &gt; @@ -1,4 +1,4 @@<br>
&gt; &gt; &gt; &gt; -obj-y += boot.o virt.o sysbus-fdt.o<br>
&gt; &gt; &gt; &gt; +obj-y += boot.o virt.o sbsa-ref.o sysbus-fdt.o<br>
&gt; &gt; &gt; &gt;   obj-$(CONFIG_ACPI) += virt-acpi-build.o<br>
&gt; &gt; &gt; &gt;   obj-$(CONFIG_DIGIC) += digic_boards.o<br>
&gt; &gt; &gt; &gt;   obj-$(CONFIG_EXYNOS4) += exynos4_boards.o<br>
&gt; &gt; &gt; &gt; diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c<br>
&gt; &gt; &gt; &gt; new file mode 100644<br>
&gt; &gt; &gt; &gt; index 0000000..28ebb3a<br>
&gt; &gt; &gt; &gt; --- /dev/null<br>
&gt; &gt; &gt; &gt; +++ b/hw/arm/sbsa-ref.c<br>
&gt; &gt; &gt; &gt; @@ -0,0 +1,937 @@<br>
&gt; &gt; &gt; &gt; +/*<br>
&gt; &gt; &gt; &gt; + * ARM SBSA Reference Platform emulation<br>
&gt; &gt; &gt; &gt; + *<br>
&gt; &gt; &gt; &gt; + * Copyright (c) 2018 Linaro Limited<br>
&gt; &gt; &gt; &gt; + * Written by Hongbo Zhang &lt;<a \
href="mailto:hongbo.zhang@linaro.org" \
target="_blank">hongbo.zhang@linaro.org</a>&gt;<br> &gt; &gt; &gt; &gt; + *<br>
&gt; &gt; &gt; &gt; + * Based on hw/arm/virt.c<br>
&gt; &gt; &gt; &gt; + *<br>
&gt; &gt; &gt; &gt; + * This program is free software; you can redistribute it and/or \
modify it<br> &gt; &gt; &gt; &gt; + * under the terms and conditions of the GNU \
General Public License,<br> &gt; &gt; &gt; &gt; + * version 2 or later, as published \
by the Free Software Foundation.<br> &gt; &gt; &gt; &gt; + *<br>
&gt; &gt; &gt; &gt; + * This program is distributed in the hope it will be useful, \
but WITHOUT<br> &gt; &gt; &gt; &gt; + * ANY WARRANTY; without even the implied \
warranty of MERCHANTABILITY or<br> &gt; &gt; &gt; &gt; + * FITNESS FOR A PARTICULAR \
PURPOSE.   See the GNU General Public License for<br> &gt; &gt; &gt; &gt; + * more \
details.<br> &gt; &gt; &gt; &gt; + *<br>
&gt; &gt; &gt; &gt; + * You should have received a copy of the GNU General Public \
License along with<br> &gt; &gt; &gt; &gt; + * this program.   If not, see &lt;<a \
href="http://www.gnu.org/licenses/" rel="noreferrer" \
target="_blank">http://www.gnu.org/licenses/</a>&gt;.<br> &gt; &gt; &gt; &gt; + \
*/<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +#include &quot;qemu/osdep.h&quot;<br>
&gt; &gt; &gt; &gt; +#include &quot;qapi/error.h&quot;<br>
&gt; &gt; &gt; &gt; +#include &quot;hw/arm/virt.h&quot;<br>
&gt; &gt; &gt; &gt; +#include &quot;hw/devices.h&quot;<br>
&gt; &gt; &gt; &gt; +#include &quot;net/net.h&quot;<br>
&gt; &gt; &gt; &gt; +#include &quot;sysemu/device_tree.h&quot;<br>
&gt; &gt; &gt; &gt; +#include &quot;sysemu/numa.h&quot;<br>
&gt; &gt; &gt; &gt; +#include &quot;hw/loader.h&quot;<br>
&gt; &gt; &gt; &gt; +#include &quot;qemu/error-report.h&quot;<br>
&gt; &gt; &gt; &gt; +#include &quot;hw/pci-host/gpex.h&quot;<br>
&gt; &gt; &gt; &gt; +#include &quot;hw/arm/sysbus-fdt.h&quot;<br>
&gt; &gt; &gt; &gt; +#include &quot;hw/arm/fdt.h&quot;<br>
&gt; &gt; &gt; &gt; +#include &quot;hw/intc/arm_gic.h&quot;<br>
&gt; &gt; &gt; &gt; +#include &quot;hw/intc/arm_gicv3_common.h&quot;<br>
&gt; &gt; &gt; &gt; +#include &quot;kvm_arm.h&quot;<br>
&gt; &gt; &gt; &gt; +#include &quot;hw/ide/internal.h&quot;<br>
&gt; &gt; &gt; &gt; +#include &quot;hw/ide/ahci_internal.h&quot;<br>
&gt; &gt; &gt; &gt; +#include &quot;hw/usb.h&quot;<br>
&gt; &gt; &gt; &gt; +#include &quot;qemu/units.h&quot;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +#define NUM_IRQS 256<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +#define SATA_NUM_PORTS 6<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +#define RAMLIMIT_GB 255<br>
&gt; &gt; &gt; &gt; +#define RAMLIMIT_BYTES (RAMLIMIT_GB * GiB)<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; You probably don&#39;t want to stick yourself with the same<br>
&gt; &gt; &gt; ram limits that the virt board has, especially since you<br>
&gt; &gt; &gt; don&#39;t need to care about AArch32. Strongly consider<br>
&gt; &gt; &gt; putting the RAM somwhere that lets you get up to a<br>
&gt; &gt; &gt; maximum value that matches what we might expect in<br>
&gt; &gt; &gt; server-class hardware.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static const MemMapEntry sbsa_ref_memmap[] = {<br>
&gt; &gt; &gt; &gt; +      /* Space up to 0x8000000 is reserved for a boot ROM */<br>
&gt; &gt; &gt; &gt; +      [VIRT_FLASH] =                     {               0, \
0x08000000 },<br> &gt; &gt; &gt; &gt; +      [VIRT_CPUPERIPHS] =              { \
0x08000000, 0x00020000 },<br> &gt; &gt; &gt; &gt; +      /* GIC distributor and CPU \
interfaces sit inside the CPU peripheral space */<br> &gt; &gt; &gt; &gt; +      \
[VIRT_GIC_DIST] =                 { 0x08000000, 0x00010000 },<br> &gt; &gt; &gt; &gt; \
+      [VIRT_GIC_CPU] =                  { 0x08010000, 0x00010000 },<br> &gt; &gt; \
&gt; &gt; +      /* The space in between here is reserved for GICv3 CPU/vCPU/HYP \
*/<br> &gt; &gt; &gt; &gt; +      /* This redistributor space allows up to 2*64kB*123 \
CPUs */<br> &gt; &gt; &gt;<br>
&gt; &gt; &gt; You don&#39;t need to do the split-redistributor layout that<br>
&gt; &gt; &gt; &quot;virt&quot; does because you have no backwards compatibility<br>
&gt; &gt; &gt; concerns. So make the space for redistributors big enough<br>
&gt; &gt; &gt; to fit more CPUs in (at least 512, or more if you expect<br>
&gt; &gt; &gt; this board to be used in future for development of a<br>
&gt; &gt; &gt; software stack that handles more).<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; +      [VIRT_GIC_REDIST] =              { 0x080A0000, 0x00F60000 \
},<br> &gt; &gt; &gt; &gt; +      [VIRT_UART] =                       { 0x09000000, \
0x00001000 },<br> &gt; &gt; &gt; &gt; +      [VIRT_RTC] =                        { \
0x09010000, 0x00001000 },<br> &gt; &gt; &gt; &gt; +      [VIRT_GPIO] =                \
{ 0x09030000, 0x00001000 },<br> &gt; &gt; &gt; &gt; +      [VIRT_SECURE_UART] =       \
{ 0x09040000, 0x00001000 },<br> &gt; &gt; &gt; &gt; +      [VIRT_AHCI] =              \
{ 0x09050000, 0x00010000 },<br> &gt; &gt; &gt; &gt; +      [VIRT_EHCI] =              \
{ 0x09060000, 0x00010000 },<br> &gt; &gt; &gt; &gt; +      [VIRT_SECURE_MEM] =        \
{ 0x0e000000, 0x01000000 },<br> &gt; &gt; &gt; &gt; +      [VIRT_PCIE_MMIO] =         \
{ 0x10000000, 0x7fff0000 },<br> &gt; &gt; &gt; &gt; +      [VIRT_PCIE_PIO] =          \
{ 0x8fff0000, 0x00010000 },<br> &gt; &gt; &gt; &gt; +      [VIRT_PCIE_ECAM] =         \
{ 0x90000000, 0x10000000 },<br> &gt; &gt; &gt; &gt; +      /* Second PCIe window, \
508GB wide at the 4GB boundary */<br> &gt; &gt; &gt; &gt; +      \
[VIRT_PCIE_MMIO_HIGH] =        { 0x100000000ULL, 0x7F00000000ULL },<br> &gt; &gt; \
&gt;<br> &gt; &gt; &gt; Again, you don&#39;t need the layout that &quot;virt&quot; \
has to<br> &gt; &gt; &gt; satisfy 32-bit guests and backwards compatibility. You<br>
&gt; &gt; &gt; can just have a single large MMIO window.<br>
&gt; &gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; Apologies for not spotting this at the time this was posted.<br>
&gt; &gt;<br>
&gt; &gt; The MMIO32 window is not there for the benefit of 32-bit only CPUs. It<br>
&gt; &gt; is there for the benefit of PCIe devices with 32-bit memory BARs<br>
&gt; &gt; which, given that our PCI MMIO is 1:1 mapped between the CPU and PCI<br>
&gt; &gt; address spaces, require a 32-bit addressable CPU mapping. (PCIe<br>
&gt; &gt; permits so-called &#39;legacy&#39; endpoints to have 32-bit MMIO BARs)<br>
&gt; &gt;<br>
&gt; &gt; So please, reinstate the MMIO32 window, but keep the other one as well.<br>
&gt; &gt;<br>
&gt; So we still use the old VIRT_PCIE_MMIO starting from fixed address<br>
&gt; 0x10000000, or anywhere within 4G is OK?<br>
&gt;<br>
<br>
Anywhere in the 32-bit addressable area is fine, but please align the<br>
window to its own size.<br>
<br>
&gt; &gt; Thanks,<br>
&gt; &gt; Ard.<br>
&gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; +      [VIRT_MEM] =                        { 0x8000000000ULL, \
RAMLIMIT_BYTES },<br> &gt; &gt; &gt; &gt; +};<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static const int sbsa_ref_irqmap[] = {<br>
&gt; &gt; &gt; &gt; +      [VIRT_UART] = 1,<br>
&gt; &gt; &gt; &gt; +      [VIRT_RTC] = 2,<br>
&gt; &gt; &gt; &gt; +      [VIRT_PCIE] = 3, /* ... to 6 */<br>
&gt; &gt; &gt; &gt; +      [VIRT_GPIO] = 7,<br>
&gt; &gt; &gt; &gt; +      [VIRT_SECURE_UART] = 8,<br>
&gt; &gt; &gt; &gt; +      [VIRT_AHCI] = 9,<br>
&gt; &gt; &gt; &gt; +      [VIRT_EHCI] = 10,<br>
&gt; &gt; &gt; &gt; +};<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void create_fdt(VirtMachineState *vms)<br>
&gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      void *fdt = create_device_tree(&amp;vms-&gt;fdt_size);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      if (!fdt) {<br>
&gt; &gt; &gt; &gt; +            error_report(&quot;create_device_tree() \
failed&quot;);<br> &gt; &gt; &gt; &gt; +            exit(1);<br>
&gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      vms-&gt;fdt = fdt;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      /* Header */<br>
&gt; &gt; &gt; &gt; +      qemu_fdt_setprop_string(fdt, &quot;/&quot;, \
&quot;compatible&quot;, &quot;linux,dummy-virt&quot;);<br> &gt; &gt; &gt; &gt; +      \
qemu_fdt_setprop_cell(fdt, &quot;/&quot;, &quot;#address-cells&quot;, 0x2);<br> &gt; \
&gt; &gt; &gt; +      qemu_fdt_setprop_cell(fdt, &quot;/&quot;, \
&quot;#size-cells&quot;, 0x2);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      /* /chosen must exist for load_dtb to fill in necessary \
properties later */<br> &gt; &gt; &gt; &gt; +      qemu_fdt_add_subnode(fdt, \
&quot;/chosen&quot;);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      if (have_numa_distance) {<br>
&gt; &gt; &gt; &gt; +            int size = nb_numa_nodes * nb_numa_nodes * 3 * \
sizeof(uint32_t);<br> &gt; &gt; &gt; &gt; +            uint32_t *matrix = \
g_malloc0(size);<br> &gt; &gt; &gt; &gt; +            int idx, i, j;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            for (i = 0; i &lt; nb_numa_nodes; i++) {<br>
&gt; &gt; &gt; &gt; +                  for (j = 0; j &lt; nb_numa_nodes; j++) {<br>
&gt; &gt; &gt; &gt; +                        idx = (i * nb_numa_nodes + j) * 3;<br>
&gt; &gt; &gt; &gt; +                        matrix[idx + 0] = cpu_to_be32(i);<br>
&gt; &gt; &gt; &gt; +                        matrix[idx + 1] = cpu_to_be32(j);<br>
&gt; &gt; &gt; &gt; +                        matrix[idx + 2] = \
cpu_to_be32(numa_info[i].distance[j]);<br> &gt; &gt; &gt; &gt; +                  \
}<br> &gt; &gt; &gt; &gt; +            }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            qemu_fdt_add_subnode(fdt, \
&quot;/distance-map&quot;);<br> &gt; &gt; &gt; &gt; +            \
qemu_fdt_setprop_string(fdt, &quot;/distance-map&quot;, &quot;compatible&quot;,<br> \
&gt; &gt; &gt; &gt; +                                                \
&quot;numa-distance-map-v1&quot;);<br> &gt; &gt; &gt; &gt; +            \
qemu_fdt_setprop(fdt, &quot;/distance-map&quot;, &quot;distance-matrix&quot;,<br> \
&gt; &gt; &gt; &gt; +                                      matrix, size);<br> &gt; \
&gt; &gt; &gt; +            g_free(matrix);<br> &gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void fdt_add_cpu_nodes(const VirtMachineState *vms)<br>
&gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      int cpu;<br>
&gt; &gt; &gt; &gt; +      const MachineState *ms = MACHINE(vms);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      qemu_fdt_add_subnode(vms-&gt;fdt, &quot;/cpus&quot;);<br>
&gt; &gt; &gt; &gt; +      /* #address-cells should be 2 for Arm v8 64-bit systems \
*/<br> &gt; &gt; &gt; &gt; +      qemu_fdt_setprop_cell(vms-&gt;fdt, \
&quot;/cpus&quot;, &quot;#address-cells&quot;, 2);<br> &gt; &gt; &gt; &gt; +      \
qemu_fdt_setprop_cell(vms-&gt;fdt, &quot;/cpus&quot;, &quot;#size-cells&quot;, \
0x0);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      for (cpu = vms-&gt;smp_cpus - 1; cpu &gt;= 0; cpu--) {<br>
&gt; &gt; &gt; &gt; +            char *nodename = \
g_strdup_printf(&quot;/cpus/cpu@%d&quot;, cpu);<br> &gt; &gt; &gt; &gt; +            \
ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(cpu));<br> &gt; &gt; &gt; &gt; +            \
CPUState *cs = CPU(armcpu);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            qemu_fdt_add_subnode(vms-&gt;fdt, nodename);<br>
&gt; &gt; &gt; &gt; +            qemu_fdt_setprop_string(vms-&gt;fdt, nodename, \
&quot;device_type&quot;, &quot;cpu&quot;);<br> &gt; &gt; &gt; &gt; +            \
qemu_fdt_setprop_string(vms-&gt;fdt, nodename, &quot;compatible&quot;,<br> &gt; &gt; \
&gt; &gt; +                                                      \
armcpu-&gt;dtb_compatible);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            if (vms-&gt;psci_conduit != \
QEMU_PSCI_CONDUIT_DISABLED<br> &gt; &gt; &gt; &gt; +                  &amp;&amp; \
vms-&gt;smp_cpus &gt; 1) {<br> &gt; &gt; &gt; &gt; +                  \
qemu_fdt_setprop_string(vms-&gt;fdt, nodename,<br> &gt; &gt; &gt; &gt; +              \
&quot;enable-method&quot;, &quot;psci&quot;);<br> &gt; &gt; &gt; &gt; +            \
}<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            qemu_fdt_setprop_u64(vms-&gt;fdt, nodename, \
&quot;reg&quot;, armcpu-&gt;mp_affinity);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            if \
(ms-&gt;possible_cpus-&gt;cpus[cs-&gt;cpu_index].props.has_node_id) {<br> &gt; &gt; \
&gt; &gt; +                  qemu_fdt_setprop_cell(vms-&gt;fdt, nodename, \
&quot;numa-node-id&quot;,<br> &gt; &gt; &gt; &gt; +                        \
ms-&gt;possible_cpus-&gt;cpus[cs-&gt;cpu_index].props.node_id);<br> &gt; &gt; &gt; \
&gt; +            }<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            g_free(nodename);<br>
&gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void fdt_add_gic_node(VirtMachineState *vms)<br>
&gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      char *nodename;<br>
&gt; &gt; &gt; &gt; +      int nb_redist_regions = \
virt_gicv3_redist_region_count(vms);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      vms-&gt;gic_phandle = \
qemu_fdt_alloc_phandle(vms-&gt;fdt);<br> &gt; &gt; &gt; &gt; +      \
qemu_fdt_setprop_cell(vms-&gt;fdt, &quot;/&quot;, &quot;interrupt-parent&quot;, \
vms-&gt;gic_phandle);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      nodename = g_strdup_printf(&quot;/intc@%&quot; PRIx64,<br>
&gt; &gt; &gt; &gt; +                                               \
vms-&gt;memmap[VIRT_GIC_DIST].base);<br> &gt; &gt; &gt; &gt; +      \
qemu_fdt_add_subnode(vms-&gt;fdt, nodename);<br> &gt; &gt; &gt; &gt; +      \
qemu_fdt_setprop_cell(vms-&gt;fdt, nodename, &quot;#interrupt-cells&quot;, 3);<br> \
&gt; &gt; &gt; &gt; +      qemu_fdt_setprop(vms-&gt;fdt, nodename, \
&quot;interrupt-controller&quot;, NULL, 0);<br> &gt; &gt; &gt; &gt; +      \
qemu_fdt_setprop_cell(vms-&gt;fdt, nodename, &quot;#address-cells&quot;, 0x2);<br> \
&gt; &gt; &gt; &gt; +      qemu_fdt_setprop_cell(vms-&gt;fdt, nodename, \
&quot;#size-cells&quot;, 0x2);<br> &gt; &gt; &gt; &gt; +      \
qemu_fdt_setprop(vms-&gt;fdt, nodename, &quot;ranges&quot;, NULL, 0);<br> &gt; &gt; \
&gt; &gt; +<br> &gt; &gt; &gt; &gt; +      /* Only GICv3 created */<br>
&gt; &gt; &gt; &gt; +      qemu_fdt_setprop_string(vms-&gt;fdt, nodename, \
&quot;compatible&quot;,<br> &gt; &gt; &gt; &gt; +                                     \
&quot;arm,gic-v3&quot;);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      qemu_fdt_setprop_cell(vms-&gt;fdt, nodename,<br>
&gt; &gt; &gt; &gt; +                                       \
&quot;#redistributor-regions&quot;, nb_redist_regions);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      if (nb_redist_regions == 1) {<br>
&gt; &gt; &gt; &gt; +            qemu_fdt_setprop_sized_cells(vms-&gt;fdt, nodename, \
&quot;reg&quot;,<br> &gt; &gt; &gt; &gt; +                                            \
2, vms-&gt;memmap[VIRT_GIC_DIST].base,<br> &gt; &gt; &gt; &gt; +                      \
2, vms-&gt;memmap[VIRT_GIC_DIST].size,<br> &gt; &gt; &gt; &gt; +                      \
2, vms-&gt;memmap[VIRT_GIC_REDIST].base,<br> &gt; &gt; &gt; &gt; +                    \
2, vms-&gt;memmap[VIRT_GIC_REDIST].size);<br> &gt; &gt; &gt; &gt; +      } else {<br>
&gt; &gt; &gt; &gt; +            qemu_fdt_setprop_sized_cells(vms-&gt;fdt, nodename, \
&quot;reg&quot;,<br> &gt; &gt; &gt; &gt; +                                            \
2, vms-&gt;memmap[VIRT_GIC_DIST].base,<br> &gt; &gt; &gt; &gt; +                      \
2, vms-&gt;memmap[VIRT_GIC_DIST].size,<br> &gt; &gt; &gt; &gt; +                      \
2, vms-&gt;memmap[VIRT_GIC_REDIST].base,<br> &gt; &gt; &gt; &gt; +                    \
2, vms-&gt;memmap[VIRT_GIC_REDIST].size,<br> &gt; &gt; &gt; &gt; +                    \
2, vms-&gt;memmap[VIRT_GIC_REDIST2].base,<br> &gt; &gt; &gt; &gt; +                   \
2, vms-&gt;memmap[VIRT_GIC_REDIST2].size);<br> &gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      if (vms-&gt;virt) {<br>
&gt; &gt; &gt; &gt; +            qemu_fdt_setprop_cells(vms-&gt;fdt, nodename, \
&quot;interrupts&quot;,<br> &gt; &gt; &gt; &gt; +                                     \
GIC_FDT_IRQ_TYPE_PPI, ARCH_GICV3_MAINT_IRQ,<br> &gt; &gt; &gt; &gt; +                 \
GIC_FDT_IRQ_FLAGS_LEVEL_HI);<br> &gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      qemu_fdt_setprop_cell(vms-&gt;fdt, nodename, \
&quot;phandle&quot;, vms-&gt;gic_phandle);<br> &gt; &gt; &gt; &gt; +      \
g_free(nodename);<br> &gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; This is still generating a lot of device tree nodes.<br>
&gt; &gt; &gt; I thought we had agreed that we were going to just have<br>
&gt; &gt; &gt; a minimal device tree that says &quot;here is the RAM&quot; and \
nothing<br> &gt; &gt; &gt; else ?<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void create_gic(VirtMachineState *vms, qemu_irq *pic)<br>
&gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      /* We create a standalone GIC */<br>
&gt; &gt; &gt; &gt; +      DeviceState *gicdev;<br>
&gt; &gt; &gt; &gt; +      SysBusDevice *gicbusdev;<br>
&gt; &gt; &gt; &gt; +      const char *gictype;<br>
&gt; &gt; &gt; &gt; +      int i;<br>
&gt; &gt; &gt; &gt; +      uint32_t nb_redist_regions = 0;<br>
&gt; &gt; &gt; &gt; +      uint32_t redist0_capacity, redist0_count;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      /* Only GICv3 created */<br>
&gt; &gt; &gt; &gt; +      gictype = gicv3_class_name();<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      gicdev = qdev_create(NULL, gictype);<br>
&gt; &gt; &gt; &gt; +      qdev_prop_set_uint32(gicdev, &quot;revision&quot;, 3);<br>
&gt; &gt; &gt; &gt; +      qdev_prop_set_uint32(gicdev, &quot;num-cpu&quot;, \
smp_cpus);<br> &gt; &gt; &gt; &gt; +      /* Note that the num-irq property counts \
both internal and external<br> &gt; &gt; &gt; &gt; +        * interrupts; there are \
always 32 of the former (mandated by GIC spec).<br> &gt; &gt; &gt; &gt; +        \
*/<br> &gt; &gt; &gt; &gt; +      qdev_prop_set_uint32(gicdev, &quot;num-irq&quot;, \
NUM_IRQS + 32);<br> &gt; &gt; &gt; &gt; +      if (!kvm_irqchip_in_kernel()) {<br>
&gt; &gt; &gt; &gt; +            qdev_prop_set_bit(gicdev, \
&quot;has-security-extensions&quot;, vms-&gt;secure);<br> &gt; &gt; &gt; &gt; +      \
}<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      redist0_capacity =<br>
&gt; &gt; &gt; &gt; +                        vms-&gt;memmap[VIRT_GIC_REDIST].size / \
GICV3_REDIST_SIZE;<br> &gt; &gt; &gt; &gt; +      redist0_count = MIN(smp_cpus, \
redist0_capacity);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      nb_redist_regions = \
virt_gicv3_redist_region_count(vms);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      qdev_prop_set_uint32(gicdev, \
&quot;len-redist-region-count&quot;,<br> &gt; &gt; &gt; &gt; +                        \
nb_redist_regions);<br> &gt; &gt; &gt; &gt; +      qdev_prop_set_uint32(gicdev, \
&quot;redist-region-count[0]&quot;, redist0_count);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      if (nb_redist_regions == 2) {<br>
&gt; &gt; &gt; &gt; +            uint32_t redist1_capacity =<br>
&gt; &gt; &gt; &gt; +                              \
vms-&gt;memmap[VIRT_GIC_REDIST2].size / GICV3_REDIST_SIZE;<br> &gt; &gt; &gt; &gt; \
+<br> &gt; &gt; &gt; &gt; +            qdev_prop_set_uint32(gicdev, \
&quot;redist-region-count[1]&quot;,<br> &gt; &gt; &gt; &gt; +                  \
MIN(smp_cpus - redist0_count, redist1_capacity));<br> &gt; &gt; &gt; &gt; +      \
}<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      qdev_init_nofail(gicdev);<br>
&gt; &gt; &gt; &gt; +      gicbusdev = SYS_BUS_DEVICE(gicdev);<br>
&gt; &gt; &gt; &gt; +      sysbus_mmio_map(gicbusdev, 0, \
vms-&gt;memmap[VIRT_GIC_DIST].base);<br> &gt; &gt; &gt; &gt; +      \
sysbus_mmio_map(gicbusdev, 1, vms-&gt;memmap[VIRT_GIC_REDIST].base);<br> &gt; &gt; \
&gt; &gt; +      if (nb_redist_regions == 2) {<br> &gt; &gt; &gt; &gt; +            \
sysbus_mmio_map(gicbusdev, 2, vms-&gt;memmap[VIRT_GIC_REDIST2].base);<br> &gt; &gt; \
&gt; &gt; +      }<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      /* Wire the outputs from each CPU&#39;s generic timer and \
the GICv3<br> &gt; &gt; &gt; &gt; +        * maintenance interrupt signal to the \
appropriate GIC PPI inputs,<br> &gt; &gt; &gt; &gt; +        * and the GIC&#39;s \
IRQ/FIQ/VIRQ/VFIQ interrupt outputs to the CPU&#39;s inputs.<br> &gt; &gt; &gt; &gt; \
+        */<br> &gt; &gt; &gt; &gt; +      for (i = 0; i &lt; smp_cpus; i++) {<br>
&gt; &gt; &gt; &gt; +            DeviceState *cpudev = DEVICE(qemu_get_cpu(i));<br>
&gt; &gt; &gt; &gt; +            int ppibase = NUM_IRQS + i * GIC_INTERNAL + \
GIC_NR_SGIS;<br> &gt; &gt; &gt; &gt; +            int irq;<br>
&gt; &gt; &gt; &gt; +            /* Mapping from the output timer irq lines from the \
CPU to the<br> &gt; &gt; &gt; &gt; +              * GIC PPI inputs we use for the \
virt board.<br> &gt; &gt; &gt; &gt; +              */<br>
&gt; &gt; &gt; &gt; +            const int timer_irq[] = {<br>
&gt; &gt; &gt; &gt; +                  [GTIMER_PHYS] = ARCH_TIMER_NS_EL1_IRQ,<br>
&gt; &gt; &gt; &gt; +                  [GTIMER_VIRT] = ARCH_TIMER_VIRT_IRQ,<br>
&gt; &gt; &gt; &gt; +                  [GTIMER_HYP]   = ARCH_TIMER_NS_EL2_IRQ,<br>
&gt; &gt; &gt; &gt; +                  [GTIMER_SEC]   = ARCH_TIMER_S_EL1_IRQ,<br>
&gt; &gt; &gt; &gt; +            };<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            for (irq = 0; irq &lt; ARRAY_SIZE(timer_irq); irq++) \
{<br> &gt; &gt; &gt; &gt; +                  qdev_connect_gpio_out(cpudev, irq,<br>
&gt; &gt; &gt; &gt; +                                                   \
qdev_get_gpio_in(gicdev,<br> &gt; &gt; &gt; &gt; +                                    \
ppibase + timer_irq[irq]));<br> &gt; &gt; &gt; &gt; +            }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            qdev_connect_gpio_out_named(cpudev, \
&quot;gicv3-maintenance-interrupt&quot;, 0,<br> &gt; &gt; &gt; &gt; +                 \
qdev_get_gpio_in(gicdev, ppibase<br> &gt; &gt; &gt; &gt; +                            \
+ ARCH_GICV3_MAINT_IRQ));<br> &gt; &gt; &gt; &gt; +            \
qdev_connect_gpio_out_named(cpudev, &quot;pmu-interrupt&quot;, 0,<br> &gt; &gt; &gt; \
&gt; +                                                      qdev_get_gpio_in(gicdev, \
ppibase<br> &gt; &gt; &gt; &gt; +                                                     \
+ VIRTUAL_PMU_IRQ));<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            sysbus_connect_irq(gicbusdev, i, \
qdev_get_gpio_in(cpudev, ARM_CPU_IRQ));<br> &gt; &gt; &gt; &gt; +            \
sysbus_connect_irq(gicbusdev, i + smp_cpus,<br> &gt; &gt; &gt; &gt; +                 \
qdev_get_gpio_in(cpudev, ARM_CPU_FIQ));<br> &gt; &gt; &gt; &gt; +            \
sysbus_connect_irq(gicbusdev, i + 2 * smp_cpus,<br> &gt; &gt; &gt; &gt; +             \
qdev_get_gpio_in(cpudev, ARM_CPU_VIRQ));<br> &gt; &gt; &gt; &gt; +            \
sysbus_connect_irq(gicbusdev, i + 3 * smp_cpus,<br> &gt; &gt; &gt; &gt; +             \
qdev_get_gpio_in(cpudev, ARM_CPU_VFIQ));<br> &gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      for (i = 0; i &lt; NUM_IRQS; i++) {<br>
&gt; &gt; &gt; &gt; +            pic[i] = qdev_get_gpio_in(gicdev, i);<br>
&gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      fdt_add_gic_node(vms);<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void create_uart(const VirtMachineState *vms, qemu_irq \
*pic, int uart,<br> &gt; &gt; &gt; &gt; +                                    \
MemoryRegion *mem, Chardev *chr)<br> &gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      hwaddr base = vms-&gt;memmap[uart].base;<br>
&gt; &gt; &gt; &gt; +      int irq = vms-&gt;irqmap[uart];<br>
&gt; &gt; &gt; &gt; +      DeviceState *dev = qdev_create(NULL, \
&quot;pl011&quot;);<br> &gt; &gt; &gt; &gt; +      SysBusDevice *s = \
SYS_BUS_DEVICE(dev);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      qdev_prop_set_chr(dev, &quot;chardev&quot;, chr);<br>
&gt; &gt; &gt; &gt; +      qdev_init_nofail(dev);<br>
&gt; &gt; &gt; &gt; +      memory_region_add_subregion(mem, base,<br>
&gt; &gt; &gt; &gt; +                                                \
sysbus_mmio_get_region(s, 0));<br> &gt; &gt; &gt; &gt; +      sysbus_connect_irq(s, \
0, pic[irq]);<br> &gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void create_rtc(const VirtMachineState *vms, qemu_irq \
*pic)<br> &gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      hwaddr base = vms-&gt;memmap[VIRT_RTC].base;<br>
&gt; &gt; &gt; &gt; +      int irq = vms-&gt;irqmap[VIRT_RTC];<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      sysbus_create_simple(&quot;pl031&quot;, base, \
pic[irq]);<br> &gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void create_ahci(const VirtMachineState *vms, qemu_irq \
*pic)<br> &gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      hwaddr base = vms-&gt;memmap[VIRT_AHCI].base;<br>
&gt; &gt; &gt; &gt; +      int irq = vms-&gt;irqmap[VIRT_AHCI];<br>
&gt; &gt; &gt; &gt; +      DeviceState *dev;<br>
&gt; &gt; &gt; &gt; +      DriveInfo *hd[SATA_NUM_PORTS];<br>
&gt; &gt; &gt; &gt; +      SysbusAHCIState *sysahci;<br>
&gt; &gt; &gt; &gt; +      AHCIState *ahci;<br>
&gt; &gt; &gt; &gt; +      int i;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      dev = qdev_create(NULL, &quot;sysbus-ahci&quot;);<br>
&gt; &gt; &gt; &gt; +      qdev_prop_set_uint32(dev, &quot;num-ports&quot;, \
SATA_NUM_PORTS);<br> &gt; &gt; &gt; &gt; +      qdev_init_nofail(dev);<br>
&gt; &gt; &gt; &gt; +      sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);<br>
&gt; &gt; &gt; &gt; +      sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, pic[irq]);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      sysahci = SYSBUS_AHCI(dev);<br>
&gt; &gt; &gt; &gt; +      ahci = &amp;sysahci-&gt;ahci;<br>
&gt; &gt; &gt; &gt; +      ide_drive_get(hd, ARRAY_SIZE(hd));<br>
&gt; &gt; &gt; &gt; +      for (i = 0; i &lt; ahci-&gt;ports; i++) {<br>
&gt; &gt; &gt; &gt; +            if (hd[i] == NULL) {<br>
&gt; &gt; &gt; &gt; +                  continue;<br>
&gt; &gt; &gt; &gt; +            }<br>
&gt; &gt; &gt; &gt; +            ide_create_drive(&amp;ahci-&gt;dev[i].port, 0, \
hd[i]);<br> &gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void create_ehci(const VirtMachineState *vms, qemu_irq \
*pic)<br> &gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      hwaddr base = vms-&gt;memmap[VIRT_EHCI].base;<br>
&gt; &gt; &gt; &gt; +      int irq = vms-&gt;irqmap[VIRT_EHCI];<br>
&gt; &gt; &gt; &gt; +      USBBus *usb_bus;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      sysbus_create_simple(&quot;exynos4210-ehci-usb&quot;, \
base, pic[irq]);<br> &gt; &gt; &gt;<br>
&gt; &gt; &gt; What is this using the exynos4210 USB device for? That<br>
&gt; &gt; &gt; is definitely not correct for a generic board.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      usb_bus = usb_bus_find(-1);<br>
&gt; &gt; &gt; &gt; +      usb_create_simple(usb_bus, &quot;usb-kbd&quot;);<br>
&gt; &gt; &gt; &gt; +      usb_create_simple(usb_bus, &quot;usb-mouse&quot;);<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Don&#39;t create USB devices by default -- let the user do it on<br>
&gt; &gt; &gt; the command line.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static DeviceState *gpio_key_dev;<br>
&gt; &gt; &gt; &gt; +static void sbsa_ref_powerdown_req(Notifier *n, void \
*opaque)<br> &gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      /* use gpio Pin 3 for power button event */<br>
&gt; &gt; &gt; &gt; +      qemu_set_irq(qdev_get_gpio_in(gpio_key_dev, 0), 1);<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static Notifier sbsa_ref_powerdown_notifier = {<br>
&gt; &gt; &gt; &gt; +      .notify = sbsa_ref_powerdown_req<br>
&gt; &gt; &gt; &gt; +};<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void create_gpio(const VirtMachineState *vms, qemu_irq \
*pic)<br> &gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      DeviceState *pl061_dev;<br>
&gt; &gt; &gt; &gt; +      hwaddr base = vms-&gt;memmap[VIRT_GPIO].base;<br>
&gt; &gt; &gt; &gt; +      int irq = vms-&gt;irqmap[VIRT_GPIO];<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      pl061_dev = sysbus_create_simple(&quot;pl061&quot;, base, \
pic[irq]);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      gpio_key_dev = sysbus_create_simple(&quot;gpio-key&quot;, \
-1,<br> &gt; &gt; &gt; &gt; +                                                         \
qdev_get_gpio_in(pl061_dev, 3));<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      /* connect powerdown request */<br>
&gt; &gt; &gt; &gt; +      \
qemu_register_powerdown_notifier(&amp;sbsa_ref_powerdown_notifier);<br> &gt; &gt; \
&gt; &gt; +}<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void create_one_flash(const char *name, hwaddr \
flashbase,<br> &gt; &gt; &gt; &gt; +                                            \
hwaddr flashsize, const char *file,<br> &gt; &gt; &gt; &gt; +                         \
MemoryRegion *sysmem)<br> &gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      /* Create and map a single flash device. We use the \
same<br> &gt; &gt; &gt; &gt; +        * parameters as the flash devices on the \
Versatile Express board.<br> &gt; &gt; &gt; &gt; +        */<br>
&gt; &gt; &gt; &gt; +      DriveInfo *dinfo = drive_get_next(IF_PFLASH);<br>
&gt; &gt; &gt; &gt; +      DeviceState *dev = qdev_create(NULL, \
&quot;cfi.pflash01&quot;);<br> &gt; &gt; &gt; &gt; +      SysBusDevice *sbd = \
SYS_BUS_DEVICE(dev);<br> &gt; &gt; &gt; &gt; +      const uint64_t sectorlength = 256 \
* 1024;<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      if (dinfo) {<br>
&gt; &gt; &gt; &gt; +            qdev_prop_set_drive(dev, &quot;drive&quot;, \
blk_by_legacy_dinfo(dinfo),<br> &gt; &gt; &gt; &gt; +                                 \
&amp;error_abort);<br> &gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      qdev_prop_set_uint32(dev, &quot;num-blocks&quot;, \
flashsize / sectorlength);<br> &gt; &gt; &gt; &gt; +      qdev_prop_set_uint64(dev, \
&quot;sector-length&quot;, sectorlength);<br> &gt; &gt; &gt; &gt; +      \
qdev_prop_set_uint8(dev, &quot;width&quot;, 4);<br> &gt; &gt; &gt; &gt; +      \
qdev_prop_set_uint8(dev, &quot;device-width&quot;, 2);<br> &gt; &gt; &gt; &gt; +      \
qdev_prop_set_bit(dev, &quot;big-endian&quot;, false);<br> &gt; &gt; &gt; &gt; +      \
qdev_prop_set_uint16(dev, &quot;id0&quot;, 0x89);<br> &gt; &gt; &gt; &gt; +      \
qdev_prop_set_uint16(dev, &quot;id1&quot;, 0x18);<br> &gt; &gt; &gt; &gt; +      \
qdev_prop_set_uint16(dev, &quot;id2&quot;, 0x00);<br> &gt; &gt; &gt; &gt; +      \
qdev_prop_set_uint16(dev, &quot;id3&quot;, 0x00);<br> &gt; &gt; &gt; &gt; +      \
qdev_prop_set_string(dev, &quot;name&quot;, name);<br> &gt; &gt; &gt; &gt; +      \
qdev_init_nofail(dev);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      memory_region_add_subregion(sysmem, flashbase,<br>
&gt; &gt; &gt; &gt; +                                                \
sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0));<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      if (file) {<br>
&gt; &gt; &gt; &gt; +            char *fn;<br>
&gt; &gt; &gt; &gt; +            int image_size;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            if (drive_get(IF_PFLASH, 0, 0)) {<br>
&gt; &gt; &gt; &gt; +                  error_report(&quot;The contents of the first \
flash device may be &quot;<br> &gt; &gt; &gt; &gt; +                                  \
&quot;specified with -bios or with -drive if=pflash... &quot;<br> &gt; &gt; &gt; &gt; \
+                                      &quot;but you cannot use both options at \
once&quot;);<br> &gt; &gt; &gt; &gt; +                  exit(1);<br>
&gt; &gt; &gt; &gt; +            }<br>
&gt; &gt; &gt; &gt; +            fn = qemu_find_file(QEMU_FILE_TYPE_BIOS, file);<br>
&gt; &gt; &gt; &gt; +            if (!fn) {<br>
&gt; &gt; &gt; &gt; +                  error_report(&quot;Could not find ROM image \
&#39;%s&#39;&quot;, file);<br> &gt; &gt; &gt; &gt; +                  exit(1);<br>
&gt; &gt; &gt; &gt; +            }<br>
&gt; &gt; &gt; &gt; +            image_size = load_image_mr(fn, \
sysbus_mmio_get_region(sbd, 0));<br> &gt; &gt; &gt; &gt; +            g_free(fn);<br>
&gt; &gt; &gt; &gt; +            if (image_size &lt; 0) {<br>
&gt; &gt; &gt; &gt; +                  error_report(&quot;Could not load ROM image \
&#39;%s&#39;&quot;, file);<br> &gt; &gt; &gt; &gt; +                  exit(1);<br>
&gt; &gt; &gt; &gt; +            }<br>
&gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void create_flash(const VirtMachineState *vms,<br>
&gt; &gt; &gt; &gt; +                                      MemoryRegion *sysmem,<br>
&gt; &gt; &gt; &gt; +                                      MemoryRegion \
*secure_sysmem)<br> &gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      /* Create two flash devices to fill the VIRT_FLASH space \
in the memmap.<br> &gt; &gt; &gt; &gt; +        * Any file passed via -bios goes in \
the first of these.<br> &gt; &gt; &gt; &gt; +        * sysmem is the system memory \
space. secure_sysmem is the secure view<br> &gt; &gt; &gt; &gt; +        * of the \
system, and the first flash device should be made visible only<br> &gt; &gt; &gt; \
&gt; +        * there. The second flash device is visible to both secure and \
nonsecure.<br> &gt; &gt; &gt; &gt; +        * If sysmem == secure_sysmem this means \
there is no separate Secure<br> &gt; &gt; &gt; &gt; +        * address space and both \
flash devices are generally visible.<br> &gt; &gt; &gt; &gt; +        */<br>
&gt; &gt; &gt; &gt; +      hwaddr flashsize = vms-&gt;memmap[VIRT_FLASH].size / \
2;<br> &gt; &gt; &gt; &gt; +      hwaddr flashbase = \
vms-&gt;memmap[VIRT_FLASH].base;<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      create_one_flash(&quot;sbsa-ref.flash0&quot;, flashbase, \
flashsize,<br> &gt; &gt; &gt; &gt; +                                bios_name, \
secure_sysmem);<br> &gt; &gt; &gt; &gt; +      \
create_one_flash(&quot;sbsa-ref.flash1&quot;, flashbase + flashsize, flashsize,<br> \
&gt; &gt; &gt; &gt; +                                NULL, sysmem);<br> &gt; &gt; \
&gt; &gt; +}<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void create_smmu(const VirtMachineState *vms, qemu_irq \
*pic,<br> &gt; &gt; &gt; &gt; +                                    PCIBus *bus)<br>
&gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      int irq =   vms-&gt;irqmap[VIRT_SMMU];<br>
&gt; &gt; &gt; &gt; +      int i;<br>
&gt; &gt; &gt; &gt; +      hwaddr base = vms-&gt;memmap[VIRT_SMMU].base;<br>
&gt; &gt; &gt; &gt; +      DeviceState *dev;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      if (vms-&gt;iommu != VIRT_IOMMU_SMMUV3) {<br>
&gt; &gt; &gt; &gt; +            return;<br>
&gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      dev = qdev_create(NULL, &quot;arm-smmuv3&quot;);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      object_property_set_link(OBJECT(dev), OBJECT(bus), \
&quot;primary-bus&quot;,<br> &gt; &gt; &gt; &gt; +                                    \
&amp;error_abort);<br> &gt; &gt; &gt; &gt; +      qdev_init_nofail(dev);<br>
&gt; &gt; &gt; &gt; +      sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);<br>
&gt; &gt; &gt; &gt; +      for (i = 0; i &lt; NUM_SMMU_IRQS; i++) {<br>
&gt; &gt; &gt; &gt; +            sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, pic[irq + \
i]);<br> &gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void create_pcie(VirtMachineState *vms, qemu_irq \
*pic)<br> &gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      hwaddr base_mmio = \
vms-&gt;memmap[VIRT_PCIE_MMIO].base;<br> &gt; &gt; &gt; &gt; +      hwaddr size_mmio \
= vms-&gt;memmap[VIRT_PCIE_MMIO].size;<br> &gt; &gt; &gt; &gt; +      hwaddr \
base_mmio_high = vms-&gt;memmap[VIRT_PCIE_MMIO_HIGH].base;<br> &gt; &gt; &gt; &gt; +  \
hwaddr size_mmio_high = vms-&gt;memmap[VIRT_PCIE_MMIO_HIGH].size;<br> &gt; &gt; &gt; \
&gt; +      hwaddr base_pio = vms-&gt;memmap[VIRT_PCIE_PIO].base;<br> &gt; &gt; &gt; \
&gt; +      hwaddr base_ecam, size_ecam;<br> &gt; &gt; &gt; &gt; +      int irq = \
vms-&gt;irqmap[VIRT_PCIE];<br> &gt; &gt; &gt; &gt; +      MemoryRegion \
*mmio_alias;<br> &gt; &gt; &gt; &gt; +      MemoryRegion *mmio_reg;<br>
&gt; &gt; &gt; &gt; +      MemoryRegion *ecam_alias;<br>
&gt; &gt; &gt; &gt; +      MemoryRegion *ecam_reg;<br>
&gt; &gt; &gt; &gt; +      DeviceState *dev;<br>
&gt; &gt; &gt; &gt; +      int i, ecam_id;<br>
&gt; &gt; &gt; &gt; +      PCIHostState *pci;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      dev = qdev_create(NULL, TYPE_GPEX_HOST);<br>
&gt; &gt; &gt; &gt; +      qdev_init_nofail(dev);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      ecam_id = VIRT_ECAM_ID(vms-&gt;highmem_ecam);<br>
&gt; &gt; &gt; &gt; +      base_ecam = vms-&gt;memmap[ecam_id].base;<br>
&gt; &gt; &gt; &gt; +      size_ecam = vms-&gt;memmap[ecam_id].size;<br>
&gt; &gt; &gt; &gt; +      /* Map only the first size_ecam bytes of ECAM space */<br>
&gt; &gt; &gt; &gt; +      ecam_alias = g_new0(MemoryRegion, 1);<br>
&gt; &gt; &gt; &gt; +      ecam_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), \
0);<br> &gt; &gt; &gt; &gt; +      memory_region_init_alias(ecam_alias, OBJECT(dev), \
&quot;pcie-ecam&quot;,<br> &gt; &gt; &gt; &gt; +                                      \
ecam_reg, 0, size_ecam);<br> &gt; &gt; &gt; &gt; +      \
memory_region_add_subregion(get_system_memory(), base_ecam, ecam_alias);<br> &gt; \
&gt; &gt; &gt; +<br> &gt; &gt; &gt; &gt; +      /* Map the MMIO window into system \
address space so as to expose<br> &gt; &gt; &gt; &gt; +        * the section of PCI \
MMIO space which starts at the same base address<br> &gt; &gt; &gt; &gt; +        * \
(ie 1:1 mapping for that part of PCI MMIO space visible through<br> &gt; &gt; &gt; \
&gt; +        * the window).<br> &gt; &gt; &gt; &gt; +        */<br>
&gt; &gt; &gt; &gt; +      mmio_alias = g_new0(MemoryRegion, 1);<br>
&gt; &gt; &gt; &gt; +      mmio_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), \
1);<br> &gt; &gt; &gt; &gt; +      memory_region_init_alias(mmio_alias, OBJECT(dev), \
&quot;pcie-mmio&quot;,<br> &gt; &gt; &gt; &gt; +                                      \
mmio_reg, base_mmio, size_mmio);<br> &gt; &gt; &gt; &gt; +      \
memory_region_add_subregion(get_system_memory(), base_mmio, mmio_alias);<br> &gt; \
&gt; &gt; &gt; +<br> &gt; &gt; &gt; &gt; +      if (vms-&gt;highmem) {<br>
&gt; &gt; &gt; &gt; +            /* Map high MMIO space */<br>
&gt; &gt; &gt; &gt; +            MemoryRegion *high_mmio_alias = g_new0(MemoryRegion, \
1);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            memory_region_init_alias(high_mmio_alias, \
OBJECT(dev), &quot;pcie-mmio-high&quot;,<br> &gt; &gt; &gt; &gt; +                    \
mmio_reg, base_mmio_high, size_mmio_high);<br> &gt; &gt; &gt; &gt; +            \
memory_region_add_subregion(get_system_memory(), base_mmio_high,<br> &gt; &gt; &gt; \
&gt; +                                                      high_mmio_alias);<br> \
&gt; &gt; &gt; &gt; +      }<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      /* Map IO port space */<br>
&gt; &gt; &gt; &gt; +      sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, base_pio);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      for (i = 0; i &lt; GPEX_NUM_IRQS; i++) {<br>
&gt; &gt; &gt; &gt; +            sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, pic[irq + \
i]);<br> &gt; &gt; &gt; &gt; +            gpex_set_irq_num(GPEX_HOST(dev), i, irq + \
i);<br> &gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      pci = PCI_HOST_BRIDGE(dev);<br>
&gt; &gt; &gt; &gt; +      if (pci-&gt;bus) {<br>
&gt; &gt; &gt; &gt; +            for (i = 0; i &lt; nb_nics; i++) {<br>
&gt; &gt; &gt; &gt; +                  NICInfo *nd = &amp;nd_table[i];<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +                  if (!nd-&gt;model) {<br>
&gt; &gt; &gt; &gt; +                        nd-&gt;model = \
g_strdup(&quot;e1000e&quot;);<br> &gt; &gt; &gt; &gt; +                  }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +                  pci_nic_init_nofail(nd, pci-&gt;bus, \
nd-&gt;model, NULL);<br> &gt; &gt; &gt; &gt; +            }<br>
&gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      pci_create_simple(pci-&gt;bus, -1, &quot;VGA&quot;);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      if (vms-&gt;iommu) {<br>
&gt; &gt; &gt; &gt; +            create_smmu(vms, pic, pci-&gt;bus);<br>
&gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void create_secure_ram(VirtMachineState *vms,<br>
&gt; &gt; &gt; &gt; +                                             MemoryRegion \
*secure_sysmem)<br> &gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      MemoryRegion *secram = g_new(MemoryRegion, 1);<br>
&gt; &gt; &gt; &gt; +      hwaddr base = vms-&gt;memmap[VIRT_SECURE_MEM].base;<br>
&gt; &gt; &gt; &gt; +      hwaddr size = vms-&gt;memmap[VIRT_SECURE_MEM].size;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      memory_region_init_ram(secram, NULL, \
&quot;sbsa-ref.secure-ram&quot;, size,<br> &gt; &gt; &gt; &gt; +                      \
&amp;error_fatal);<br> &gt; &gt; &gt; &gt; +      \
memory_region_add_subregion(secure_sysmem, base, secram);<br> &gt; &gt; &gt; &gt; \
+}<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void *sbsa_ref_dtb(const struct arm_boot_info *binfo, int \
*fdt_size)<br> &gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      const VirtMachineState *board = container_of(binfo, \
VirtMachineState,<br> &gt; &gt; &gt; &gt; +                                           \
bootinfo);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      *fdt_size = board-&gt;fdt_size;<br>
&gt; &gt; &gt; &gt; +      return board-&gt;fdt;<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static<br>
&gt; &gt; &gt; &gt; +void sbsa_ref_machine_done(Notifier *notifier, void *data)<br>
&gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      VirtMachineState *vms = container_of(notifier, \
VirtMachineState,<br> &gt; &gt; &gt; &gt; +                                           \
machine_done);<br> &gt; &gt; &gt; &gt; +      ARMCPU *cpu = ARM_CPU(first_cpu);<br>
&gt; &gt; &gt; &gt; +      struct arm_boot_info *info = &amp;vms-&gt;bootinfo;<br>
&gt; &gt; &gt; &gt; +      AddressSpace *as = arm_boot_address_space(cpu, info);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      if (arm_load_dtb(info-&gt;dtb_start, info, \
info-&gt;dtb_limit, as) &lt; 0) {<br> &gt; &gt; &gt; &gt; +            exit(1);<br>
&gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; The virt board needs a machine-done notifier because it has<br>
&gt; &gt; &gt; to add extra things to the DTB here. You don&#39;t, so you \
don&#39;t<br> &gt; &gt; &gt; need one. Don&#39;t set bootinfo.skip_dtb_autoload to \
true, and<br> &gt; &gt; &gt; then the boot.c code will do the arm_load_dtb() call for \
you.<br> &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void sbsa_ref_init(MachineState *machine)<br>
&gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      VirtMachineState *vms = VIRT_MACHINE(machine);<br>
&gt; &gt; &gt; &gt; +      VirtMachineClass *vmc = \
VIRT_MACHINE_GET_CLASS(machine);<br> &gt; &gt; &gt; &gt; +      MachineClass *mc = \
MACHINE_GET_CLASS(machine);<br> &gt; &gt; &gt; &gt; +      const CPUArchIdList \
*possible_cpus;<br> &gt; &gt; &gt; &gt; +      qemu_irq pic[NUM_IRQS];<br>
&gt; &gt; &gt; &gt; +      MemoryRegion *sysmem = get_system_memory();<br>
&gt; &gt; &gt; &gt; +      MemoryRegion *secure_sysmem = NULL;<br>
&gt; &gt; &gt; &gt; +      int n, sbsa_max_cpus;<br>
&gt; &gt; &gt; &gt; +      MemoryRegion *ram = g_new(MemoryRegion, 1);<br>
&gt; &gt; &gt; &gt; +      bool firmware_loaded = bios_name || drive_get(IF_PFLASH, \
0, 0);<br> &gt; &gt; &gt; &gt; +      bool aarch64 = true;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      if (strcmp(machine-&gt;cpu_type, \
ARM_CPU_TYPE_NAME(&quot;cortex-a57&quot;))) {<br> &gt; &gt; &gt; &gt; +            \
error_report(&quot;sbsa-ref: CPU type %s not supported&quot;, \
machine-&gt;cpu_type);<br> &gt; &gt; &gt; &gt; +            exit(1);<br>
&gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      if (kvm_enabled()) {<br>
&gt; &gt; &gt; &gt; +            error_report(&quot;sbsa-ref: KVM is not supported at \
this machine&quot;);<br> &gt; &gt; &gt; &gt; +            exit(1);<br>
&gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      if (machine-&gt;kernel_filename &amp;&amp; \
firmware_loaded) {<br> &gt; &gt; &gt; &gt; +            error_report(&quot;sbsa-ref: \
No fw_cfg device on this machine, &quot;<br> &gt; &gt; &gt; &gt; +                    \
&quot;so -kernel option is not supported when firmware loaded, &quot;<br> &gt; &gt; \
&gt; &gt; +                                &quot;please load hard disk \
instead&quot;);<br> &gt; &gt; &gt; &gt; +            exit(1);<br>
&gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; If ther is no fw_cfg device, why does your memory map \
datastructure<br> &gt; &gt; &gt; have an entry for it earlier ?<br>
&gt; &gt; &gt; &gt; +      [VIRT_FW_CFG] =                    { 0x09020000, \
0x00000018 },<br> &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      /* If we have an EL3 boot ROM then the assumption is that \
it will<br> &gt; &gt; &gt; &gt; +        * implement PSCI itself, so disable \
QEMU&#39;s internal implementation<br> &gt; &gt; &gt; &gt; +        * so it \
doesn&#39;t get in the way. Instead of starting secondary<br> &gt; &gt; &gt; &gt; +   \
* CPUs in PSCI powerdown state we will start them all running and<br> &gt; &gt; &gt; \
&gt; +        * let the boot ROM sort them out.<br> &gt; &gt; &gt; &gt; +        * \
The usual case is that we do use QEMU&#39;s PSCI implementation;<br> &gt; &gt; &gt; \
&gt; +        * if the guest has EL2 then we will use SMC as the conduit,<br> &gt; \
&gt; &gt; &gt; +        * and otherwise we will use HVC (for backwards compatibility \
and<br> &gt; &gt; &gt; &gt; +        * because if we&#39;re using KVM then we must \
use HVC).<br> &gt; &gt; &gt; &gt; +        */<br>
&gt; &gt; &gt; &gt; +      if (vms-&gt;secure &amp;&amp; firmware_loaded) {<br>
&gt; &gt; &gt; &gt; +            vms-&gt;psci_conduit = \
QEMU_PSCI_CONDUIT_DISABLED;<br> &gt; &gt; &gt; &gt; +      } else if (vms-&gt;virt) \
{<br> &gt; &gt; &gt; &gt; +            vms-&gt;psci_conduit = \
QEMU_PSCI_CONDUIT_SMC;<br> &gt; &gt; &gt; &gt; +      } else {<br>
&gt; &gt; &gt; &gt; +            vms-&gt;psci_conduit = QEMU_PSCI_CONDUIT_HVC;<br>
&gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Do you actually intend this to work in all these cases? I<br>
&gt; &gt; &gt; thought the intention was &quot;always start the boot rom in \
EL3&quot;<br> &gt; &gt; &gt; for this board, like the real hardware would. In that \
case, most<br> &gt; &gt; &gt; of these if clauses are dead code.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      /* Only GICv3 is uesd in this machine */<br>
&gt; &gt; &gt; &gt; +      sbsa_max_cpus = vms-&gt;memmap[VIRT_GIC_REDIST].size / \
GICV3_REDIST_SIZE;<br> &gt; &gt; &gt; &gt; +      sbsa_max_cpus += \
vms-&gt;memmap[VIRT_GIC_REDIST2].size / GICV3_REDIST_SIZE;<br> &gt; &gt; &gt; &gt; \
+<br> &gt; &gt; &gt; &gt; +      if (max_cpus &gt; sbsa_max_cpus) {<br>
&gt; &gt; &gt; &gt; +            error_report(&quot;Number of SMP CPUs requested (%d) \
exceeds max CPUs &quot;<br> &gt; &gt; &gt; &gt; +                                \
&quot;supported by machine &#39;sbsa-ref&#39; (%d)&quot;,<br> &gt; &gt; &gt; &gt; +   \
max_cpus, sbsa_max_cpus);<br> &gt; &gt; &gt; &gt; +            exit(1);<br>
&gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      vms-&gt;smp_cpus = smp_cpus;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      if (machine-&gt;ram_size &gt; \
vms-&gt;memmap[VIRT_MEM].size) {<br> &gt; &gt; &gt; &gt; +            \
error_report(&quot;sbsa-ref: cannot model more than %dGB RAM&quot;, RAMLIMIT_GB);<br> \
&gt; &gt; &gt; &gt; +            exit(1);<br> &gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      if (vms-&gt;secure) {<br>
&gt; &gt; &gt; &gt; +            /* The Secure view of the world is the same as the \
NonSecure,<br> &gt; &gt; &gt; &gt; +              * but with a few extra devices. \
Create it as a container region<br> &gt; &gt; &gt; &gt; +              * containing \
the system memory at low priority; any secure-only<br> &gt; &gt; &gt; &gt; +          \
* devices go in at higher priority and take precedence.<br> &gt; &gt; &gt; &gt; +     \
*/<br> &gt; &gt; &gt; &gt; +            secure_sysmem = g_new(MemoryRegion, 1);<br>
&gt; &gt; &gt; &gt; +            memory_region_init(secure_sysmem, OBJECT(machine), \
&quot;secure-memory&quot;,<br> &gt; &gt; &gt; &gt; +                                  \
UINT64_MAX);<br> &gt; &gt; &gt; &gt; +            \
memory_region_add_subregion_overlap(secure_sysmem, 0, sysmem, -1);<br> &gt; &gt; &gt; \
&gt; +      }<br> &gt; &gt; &gt;<br>
&gt; &gt; &gt; Again, unless you intentionally want to support both &quot;has \
EL3&quot;<br> &gt; &gt; &gt; and &quot;does not have EL3&quot; configs for this \
board, you don&#39;t need<br> &gt; &gt; &gt; to do this conditionally.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      create_fdt(vms);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      possible_cpus = mc-&gt;possible_cpu_arch_ids(machine);<br>
&gt; &gt; &gt; &gt; +      for (n = 0; n &lt; possible_cpus-&gt;len; n++) {<br>
&gt; &gt; &gt; &gt; +            Object *cpuobj;<br>
&gt; &gt; &gt; &gt; +            CPUState *cs;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            if (n &gt;= smp_cpus) {<br>
&gt; &gt; &gt; &gt; +                  break;<br>
&gt; &gt; &gt; &gt; +            }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            cpuobj = \
object_new(possible_cpus-&gt;cpus[n].type);<br> &gt; &gt; &gt; &gt; +            \
object_property_set_int(cpuobj, possible_cpus-&gt;cpus[n].arch_id,<br> &gt; &gt; &gt; \
&gt; +                                                &quot;mp-affinity&quot;, \
NULL);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            cs = CPU(cpuobj);<br>
&gt; &gt; &gt; &gt; +            cs-&gt;cpu_index = n;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            \
numa_cpu_pre_plug(&amp;possible_cpus-&gt;cpus[cs-&gt;cpu_index], DEVICE(cpuobj),<br> \
&gt; &gt; &gt; &gt; +                                       &amp;error_fatal);<br> \
&gt; &gt; &gt; &gt; +<br> &gt; &gt; &gt; &gt; +            aarch64 &amp;= \
object_property_get_bool(cpuobj, &quot;aarch64&quot;, NULL);<br> &gt; &gt; &gt; &gt; \
+<br> &gt; &gt; &gt; &gt; +            if (!vms-&gt;secure) {<br>
&gt; &gt; &gt; &gt; +                  object_property_set_bool(cpuobj, false, \
&quot;has_el3&quot;, NULL);<br> &gt; &gt; &gt; &gt; +            }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            if (!vms-&gt;virt &amp;&amp; \
object_property_find(cpuobj, &quot;has_el2&quot;, NULL)) {<br> &gt; &gt; &gt; &gt; +  \
object_property_set_bool(cpuobj, false, &quot;has_el2&quot;, NULL);<br> &gt; &gt; \
&gt; &gt; +            }<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            if (vms-&gt;psci_conduit != \
QEMU_PSCI_CONDUIT_DISABLED) {<br> &gt; &gt; &gt; &gt; +                  \
object_property_set_int(cpuobj, vms-&gt;psci_conduit,<br> &gt; &gt; &gt; &gt; +       \
&quot;psci-conduit&quot;, NULL);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +                  /* Secondary CPUs start in PSCI powered-down \
state */<br> &gt; &gt; &gt; &gt; +                  if (n &gt; 0) {<br>
&gt; &gt; &gt; &gt; +                        object_property_set_bool(cpuobj, \
true,<br> &gt; &gt; &gt; &gt; +                                                       \
&quot;start-powered-off&quot;, NULL);<br> &gt; &gt; &gt; &gt; +                  \
}<br> &gt; &gt; &gt; &gt; +            }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            if (vmc-&gt;no_pmu &amp;&amp; \
object_property_find(cpuobj, &quot;pmu&quot;, NULL)) {<br> &gt; &gt; &gt; &gt; +      \
object_property_set_bool(cpuobj, false, &quot;pmu&quot;, NULL);<br> &gt; &gt; &gt; \
&gt; +            }<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            if (object_property_find(cpuobj, \
&quot;reset-cbar&quot;, NULL)) {<br> &gt; &gt; &gt; &gt; +                  \
object_property_set_int(cpuobj, vms-&gt;memmap[VIRT_CPUPERIPHS].base,<br> &gt; &gt; \
&gt; &gt; +                                                      \
&quot;reset-cbar&quot;, &amp;error_abort);<br> &gt; &gt; &gt; &gt; +            }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            object_property_set_link(cpuobj, OBJECT(sysmem), \
&quot;memory&quot;,<br> &gt; &gt; &gt; &gt; +                                         \
&amp;error_abort);<br> &gt; &gt; &gt; &gt; +            if (vms-&gt;secure) {<br>
&gt; &gt; &gt; &gt; +                  object_property_set_link(cpuobj, \
OBJECT(secure_sysmem),<br> &gt; &gt; &gt; &gt; +                                      \
&quot;secure-memory&quot;, &amp;error_abort);<br> &gt; &gt; &gt; &gt; +            \
}<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +            object_property_set_bool(cpuobj, true, \
&quot;realized&quot;, &amp;error_fatal);<br> &gt; &gt; &gt; &gt; +            \
object_unref(cpuobj);<br> &gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +      fdt_add_cpu_nodes(vms);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      memory_region_allocate_system_memory(ram, NULL, \
&quot;sbsa-ref.ram&quot;,<br> &gt; &gt; &gt; &gt; +                                   \
machine-&gt;ram_size);<br> &gt; &gt; &gt; &gt; +      \
memory_region_add_subregion(sysmem, vms-&gt;memmap[VIRT_MEM].base, ram);<br> &gt; \
&gt; &gt; &gt; +<br> &gt; &gt; &gt; &gt; +      create_flash(vms, sysmem, \
secure_sysmem ? secure_sysmem : sysmem);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      create_gic(vms, pic);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      create_uart(vms, pic, VIRT_UART, sysmem, \
serial_hd(0));<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      if (vms-&gt;secure) {<br>
&gt; &gt; &gt; &gt; +            create_secure_ram(vms, secure_sysmem);<br>
&gt; &gt; &gt; &gt; +            create_uart(vms, pic, VIRT_SECURE_UART, \
secure_sysmem, serial_hd(1));<br> &gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      vms-&gt;highmem_ecam &amp;= vms-&gt;highmem &amp;&amp; \
(!firmware_loaded || aarch64);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      create_rtc(vms, pic);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      create_pcie(vms, pic);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      create_gpio(vms, pic);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      create_ahci(vms, pic);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      create_ehci(vms, pic);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      vms-&gt;bootinfo.ram_size = machine-&gt;ram_size;<br>
&gt; &gt; &gt; &gt; +      vms-&gt;bootinfo.kernel_filename = \
machine-&gt;kernel_filename;<br> &gt; &gt; &gt; &gt; +      \
vms-&gt;bootinfo.kernel_cmdline = machine-&gt;kernel_cmdline;<br> &gt; &gt; &gt; &gt; \
+      vms-&gt;bootinfo.initrd_filename = machine-&gt;initrd_filename;<br> &gt; &gt; \
&gt; &gt; +      vms-&gt;bootinfo.nb_cpus = smp_cpus;<br> &gt; &gt; &gt; &gt; +      \
vms-&gt;bootinfo.board_id = -1;<br> &gt; &gt; &gt; &gt; +      \
vms-&gt;bootinfo.loader_start = vms-&gt;memmap[VIRT_MEM].base;<br> &gt; &gt; &gt; \
&gt; +      vms-&gt;bootinfo.get_dtb = sbsa_ref_dtb;<br> &gt; &gt; &gt; &gt; +      \
vms-&gt;bootinfo.skip_dtb_autoload = true;<br> &gt; &gt; &gt; &gt; +      \
vms-&gt;bootinfo.firmware_loaded = firmware_loaded;<br> &gt; &gt; &gt; &gt; +      \
arm_load_kernel(ARM_CPU(first_cpu), &amp;vms-&gt;bootinfo);<br> &gt; &gt; &gt; &gt; \
+<br> &gt; &gt; &gt; &gt; +      vms-&gt;machine_done.notify = \
sbsa_ref_machine_done;<br> &gt; &gt; &gt; &gt; +      \
qemu_add_machine_init_done_notifier(&amp;vms-&gt;machine_done);<br> &gt; &gt; &gt; \
&gt; +}<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static bool sbsa_ref_get_secure(Object *obj, Error **errp)<br>
&gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      VirtMachineState *vms = VIRT_MACHINE(obj);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      return vms-&gt;secure;<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void sbsa_ref_set_secure(Object *obj, bool value, Error \
**errp)<br> &gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      VirtMachineState *vms = VIRT_MACHINE(obj);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      vms-&gt;secure = value;<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static bool sbsa_ref_get_virt(Object *obj, Error **errp)<br>
&gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      VirtMachineState *vms = VIRT_MACHINE(obj);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      return vms-&gt;virt;<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void sbsa_ref_set_virt(Object *obj, bool value, Error \
**errp)<br> &gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      VirtMachineState *vms = VIRT_MACHINE(obj);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      vms-&gt;virt = value;<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static CpuInstanceProperties<br>
&gt; &gt; &gt; &gt; +sbsa_ref_cpu_index_to_props(MachineState *ms, unsigned \
cpu_index)<br> &gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      MachineClass *mc = MACHINE_GET_CLASS(ms);<br>
&gt; &gt; &gt; &gt; +      const CPUArchIdList *possible_cpus = \
mc-&gt;possible_cpu_arch_ids(ms);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      assert(cpu_index &lt; possible_cpus-&gt;len);<br>
&gt; &gt; &gt; &gt; +      return possible_cpus-&gt;cpus[cpu_index].props;<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static int64_t<br>
&gt; &gt; &gt; &gt; +sbsa_ref_get_default_cpu_node_id(const MachineState *ms, int \
idx)<br> &gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      return idx % nb_numa_nodes;<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static uint64_t sbsa_ref_cpu_mp_affinity(VirtMachineState *vms, \
int idx)<br> &gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      uint8_t clustersz = ARM_DEFAULT_CPUS_PER_CLUSTER;<br>
&gt; &gt; &gt; &gt; +      VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(vms);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      if (!vmc-&gt;disallow_affinity_adjustment) {<br>
&gt; &gt; &gt; &gt; +            /* Only GICv3 is used in this machine */<br>
&gt; &gt; &gt; &gt; +            clustersz = GICV3_TARGETLIST_BITS;<br>
&gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +      return arm_cpu_mp_affinity(idx, clustersz);<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static const CPUArchIdList \
*sbsa_ref_possible_cpu_arch_ids(MachineState *ms)<br> &gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      int n;<br>
&gt; &gt; &gt; &gt; +      VirtMachineState *vms = VIRT_MACHINE(ms);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      if (ms-&gt;possible_cpus) {<br>
&gt; &gt; &gt; &gt; +            assert(ms-&gt;possible_cpus-&gt;len == \
max_cpus);<br> &gt; &gt; &gt; &gt; +            return ms-&gt;possible_cpus;<br>
&gt; &gt; &gt; &gt; +      }<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      ms-&gt;possible_cpus = g_malloc0(sizeof(CPUArchIdList) \
+<br> &gt; &gt; &gt; &gt; +                                                   \
sizeof(CPUArchId) * max_cpus);<br> &gt; &gt; &gt; &gt; +      \
ms-&gt;possible_cpus-&gt;len = max_cpus;<br> &gt; &gt; &gt; &gt; +      for (n = 0; n \
&lt; ms-&gt;possible_cpus-&gt;len; n++) {<br> &gt; &gt; &gt; &gt; +            \
ms-&gt;possible_cpus-&gt;cpus[n].type = ms-&gt;cpu_type;<br> &gt; &gt; &gt; &gt; +    \
ms-&gt;possible_cpus-&gt;cpus[n].arch_id =<br> &gt; &gt; &gt; &gt; +                  \
sbsa_ref_cpu_mp_affinity(vms, n);<br> &gt; &gt; &gt; &gt; +            \
ms-&gt;possible_cpus-&gt;cpus[n].props.has_thread_id = true;<br> &gt; &gt; &gt; &gt; \
+            ms-&gt;possible_cpus-&gt;cpus[n].props.thread_id = n;<br> &gt; &gt; &gt; \
&gt; +      }<br> &gt; &gt; &gt; &gt; +      return ms-&gt;possible_cpus;<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void sbsa_ref_instance_init(Object *obj)<br>
&gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      VirtMachineState *vms = VIRT_MACHINE(obj);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      vms-&gt;secure = true;<br>
&gt; &gt; &gt; &gt; +      object_property_add_bool(obj, &quot;secure&quot;, \
sbsa_ref_get_secure,<br> &gt; &gt; &gt; &gt; +                                        \
sbsa_ref_set_secure, NULL);<br> &gt; &gt; &gt; &gt; +      \
object_property_set_description(obj, &quot;secure&quot;,<br> &gt; &gt; &gt; &gt; +    \
&quot;Set on/off to enable/disable the ARM &quot;<br> &gt; &gt; &gt; &gt; +           \
&quot;Security Extensions (TrustZone)&quot;,<br> &gt; &gt; &gt; &gt; +                \
NULL);<br> &gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      vms-&gt;virt = true;<br>
&gt; &gt; &gt; &gt; +      object_property_add_bool(obj, &quot;virtualization&quot;, \
sbsa_ref_get_virt,<br> &gt; &gt; &gt; &gt; +                                          \
sbsa_ref_set_virt, NULL);<br> &gt; &gt; &gt; &gt; +      \
object_property_set_description(obj, &quot;virtualization&quot;,<br> &gt; &gt; &gt; \
&gt; +                                                      &quot;Set on/off to \
enable/disable emulating a &quot;<br> &gt; &gt; &gt; &gt; +                           \
&quot;guest CPU which implements the ARM &quot;<br> &gt; &gt; &gt; &gt; +             \
&quot;Virtualization Extensions&quot;,<br> &gt; &gt; &gt; &gt; +                      \
NULL);<br> &gt; &gt; &gt;<br>
&gt; &gt; &gt; Drop the properties unless you need to actually support<br>
&gt; &gt; &gt; all the different variations.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      vms-&gt;highmem = true;<br>
&gt; &gt; &gt; &gt; +      vms-&gt;iommu = VIRT_IOMMU_NONE;<br>
&gt; &gt; &gt; &gt; +      vms-&gt;gic_version = 3;<br>
&gt; &gt; &gt; &gt; +      vms-&gt;memmap = sbsa_ref_memmap;<br>
&gt; &gt; &gt; &gt; +      vms-&gt;irqmap = sbsa_ref_irqmap;<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void sbsa_ref_class_init(ObjectClass *oc, void *data)<br>
&gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      MachineClass *mc = MACHINE_CLASS(oc);<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +      mc-&gt;init = sbsa_ref_init;<br>
&gt; &gt; &gt; &gt; +      mc-&gt;max_cpus = 246;<br>
&gt; &gt; &gt; &gt; +      mc-&gt;block_default_type = IF_IDE;<br>
&gt; &gt; &gt; &gt; +      mc-&gt;no_cdrom = 1;<br>
&gt; &gt; &gt; &gt; +      mc-&gt;pci_allow_0_address = true;<br>
&gt; &gt; &gt; &gt; +      mc-&gt;minimum_page_bits = 12;<br>
&gt; &gt; &gt; &gt; +      mc-&gt;possible_cpu_arch_ids = \
sbsa_ref_possible_cpu_arch_ids;<br> &gt; &gt; &gt; &gt; +      \
mc-&gt;cpu_index_to_instance_props = sbsa_ref_cpu_index_to_props;<br> &gt; &gt; &gt; \
&gt; +      mc-&gt;default_cpu_type = ARM_CPU_TYPE_NAME(&quot;cortex-a57&quot;);<br> \
&gt; &gt; &gt; &gt; +      mc-&gt;get_default_cpu_node_id = \
sbsa_ref_get_default_cpu_node_id;<br> &gt; &gt; &gt; &gt; +      \
mc-&gt;default_ram_size = 1 * GiB;<br> &gt; &gt; &gt; &gt; +      mc-&gt;default_cpus \
= 4;<br> &gt; &gt; &gt; &gt; +      mc-&gt;desc = &quot;QEMU &#39;SBSA Reference&#39; \
ARM Virtual Machine&quot;;<br> &gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static const TypeInfo sbsa_ref_info = {<br>
&gt; &gt; &gt; &gt; +      .name               = \
MACHINE_TYPE_NAME(&quot;sbsa-ref&quot;),<br> &gt; &gt; &gt; &gt; +      .parent       \
= TYPE_VIRT_MACHINE,<br> &gt; &gt; &gt; &gt; +      .instance_init = \
sbsa_ref_instance_init,<br> &gt; &gt; &gt; &gt; +      .class_init      = \
sbsa_ref_class_init,<br> &gt; &gt; &gt; &gt; +};<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +static void sbsa_ref_machine_init(void)<br>
&gt; &gt; &gt; &gt; +{<br>
&gt; &gt; &gt; &gt; +      type_register_static(&amp;sbsa_ref_info);<br>
&gt; &gt; &gt; &gt; +}<br>
&gt; &gt; &gt; &gt; +<br>
&gt; &gt; &gt; &gt; +type_init(sbsa_ref_machine_init);<br>
&gt; &gt; &gt; &gt; diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h<br>
&gt; &gt; &gt; &gt; index 9a870cc..f6c48be 100644<br>
&gt; &gt; &gt; &gt; --- a/include/hw/arm/virt.h<br>
&gt; &gt; &gt; &gt; +++ b/include/hw/arm/virt.h<br>
&gt; &gt; &gt; &gt; @@ -78,6 +78,8 @@ enum {<br>
&gt; &gt; &gt; &gt;         VIRT_GPIO,<br>
&gt; &gt; &gt; &gt;         VIRT_SECURE_UART,<br>
&gt; &gt; &gt; &gt;         VIRT_SECURE_MEM,<br>
&gt; &gt; &gt; &gt; +      VIRT_AHCI,<br>
&gt; &gt; &gt; &gt; +      VIRT_EHCI,<br>
&gt; &gt; &gt; &gt;   };<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;   typedef enum VirtIOMMUType {<br>
&gt; &gt; &gt; &gt; --<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; thanks<br>
&gt; &gt; &gt; -- PMM<br>
</blockquote></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic