From nobody Sat Apr 20 06:03:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523551445883726.2014807963478; Thu, 12 Apr 2018 09:44:05 -0700 (PDT) Received: from localhost ([::1]:53533 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6fKP-0005zU-4C for importer@patchew.org; Thu, 12 Apr 2018 12:44:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58298) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6fI7-00046Q-9f for qemu-devel@nongnu.org; Thu, 12 Apr 2018 12:41:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6fI6-00018z-77 for qemu-devel@nongnu.org; Thu, 12 Apr 2018 12:41:43 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52856 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f6fI0-00013s-Si; Thu, 12 Apr 2018 12:41:36 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6E50F8DC38; Thu, 12 Apr 2018 16:41:31 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id B026810B00B2; Thu, 12 Apr 2018 16:41:30 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Thu, 12 Apr 2018 18:40:18 +0200 Message-Id: <1523551221-11612-2-git-send-email-imammedo@redhat.com> In-Reply-To: <1523551221-11612-1-git-send-email-imammedo@redhat.com> References: <1523551221-11612-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 12 Apr 2018 16:41:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 12 Apr 2018 16:41:31 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'imammedo@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH for-2.13 1/4] arm: reuse arm_boot_address_space() in armv7m_load_kernel() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, eric.auger@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" reduce code duplication by resusing arm_boot_address_space() Signed-off-by: Igor Mammedov --- include/hw/arm/arm.h | 2 ++ hw/arm/armv7m.c | 10 +--------- hw/arm/boot.c | 16 ++++++++-------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/include/hw/arm/arm.h b/include/hw/arm/arm.h index ce769bd..188d18b 100644 --- a/include/hw/arm/arm.h +++ b/include/hw/arm/arm.h @@ -143,6 +143,8 @@ struct arm_boot_info { */ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info); =20 +AddressSpace *arm_boot_address_space(ARMCPU *cpu, bool secure_boot); + /* Write a secure board setup routine with a dummy handler for SMCs */ void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu, const struct arm_boot_info *in= fo, diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c index f123cc7..d372d9c 100644 --- a/hw/arm/armv7m.c +++ b/hw/arm/armv7m.c @@ -289,8 +289,6 @@ void armv7m_load_kernel(ARMCPU *cpu, const char *kernel= _filename, int mem_size) uint64_t lowaddr; int big_endian; AddressSpace *as; - int asidx; - CPUState *cs =3D CPU(cpu); =20 #ifdef TARGET_WORDS_BIGENDIAN big_endian =3D 1; @@ -303,13 +301,7 @@ void armv7m_load_kernel(ARMCPU *cpu, const char *kerne= l_filename, int mem_size) exit(1); } =20 - if (arm_feature(&cpu->env, ARM_FEATURE_EL3)) { - asidx =3D ARMASIdx_S; - } else { - asidx =3D ARMASIdx_NS; - } - as =3D cpu_get_address_space(cs, asidx); - + as =3D arm_boot_address_space(cpu, true); if (kernel_filename) { image_size =3D load_elf_as(kernel_filename, NULL, NULL, &entry, &l= owaddr, NULL, big_endian, EM_ARM, 1, 0, as); diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 26184bc..2f464ca 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -36,8 +36,7 @@ #define ARM64_TEXT_OFFSET_OFFSET 8 #define ARM64_MAGIC_OFFSET 56 =20 -static AddressSpace *arm_boot_address_space(ARMCPU *cpu, - const struct arm_boot_info *in= fo) +AddressSpace *arm_boot_address_space(ARMCPU *cpu, bool secure_boot) { /* Return the address space to use for bootloader reads and writes. * We prefer the secure address space if the CPU has it and we're @@ -46,7 +45,7 @@ static AddressSpace *arm_boot_address_space(ARMCPU *cpu, int asidx; CPUState *cs =3D CPU(cpu); =20 - if (arm_feature(&cpu->env, ARM_FEATURE_EL3) && info->secure_boot) { + if (arm_feature(&cpu->env, ARM_FEATURE_EL3) && secure_boot) { asidx =3D ARMASIdx_S; } else { asidx =3D ARMASIdx_NS; @@ -193,7 +192,7 @@ static void default_write_secondary(ARMCPU *cpu, const struct arm_boot_info *info) { uint32_t fixupcontext[FIXUP_MAX]; - AddressSpace *as =3D arm_boot_address_space(cpu, info); + AddressSpace *as =3D arm_boot_address_space(cpu, info->secure_boot); =20 fixupcontext[FIXUP_GIC_CPU_IF] =3D info->gic_cpu_if_addr; fixupcontext[FIXUP_BOOTREG] =3D info->smp_bootreg_addr; @@ -211,7 +210,7 @@ void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu, const struct arm_boot_info *in= fo, hwaddr mvbar_addr) { - AddressSpace *as =3D arm_boot_address_space(cpu, info); + AddressSpace *as =3D arm_boot_address_space(cpu, info->secure_boot); int n; uint32_t mvbar_blob[] =3D { /* mvbar_addr: secure monitor vectors @@ -262,7 +261,7 @@ void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu, static void default_reset_secondary(ARMCPU *cpu, const struct arm_boot_info *info) { - AddressSpace *as =3D arm_boot_address_space(cpu, info); + AddressSpace *as =3D arm_boot_address_space(cpu, info->secure_boot); CPUState *cs =3D CPU(cpu); =20 address_space_stl_notdirty(as, info->smp_bootreg_addr, @@ -753,7 +752,8 @@ static void do_cpu_reset(void *opaque) } =20 if (cs =3D=3D first_cpu) { - AddressSpace *as =3D arm_boot_address_space(cpu, info); + AddressSpace *as =3D + arm_boot_address_space(cpu, info->secure_boot); =20 cpu_set_pc(cs, info->loader_start); =20 @@ -950,7 +950,7 @@ static void arm_load_kernel_notify(Notifier *notifier, = void *data) ARMCPU *cpu =3D n->cpu; struct arm_boot_info *info =3D container_of(n, struct arm_boot_info, load_kernel_notifier); - AddressSpace *as =3D arm_boot_address_space(cpu, info); + AddressSpace *as =3D arm_boot_address_space(cpu, info->secure_boot); =20 /* The board code is not supposed to set secure_board_setup unless * running its code in secure mode is actually possible, and KVM --=20 2.7.4 From nobody Sat Apr 20 06:03:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523551566114964.3489013691843; Thu, 12 Apr 2018 09:46:06 -0700 (PDT) Received: from localhost ([::1]:53640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6fMH-0008AR-1i for importer@patchew.org; Thu, 12 Apr 2018 12:46:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6fI9-0004BD-Co for qemu-devel@nongnu.org; Thu, 12 Apr 2018 12:41:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6fI7-00019j-8G for qemu-devel@nongnu.org; Thu, 12 Apr 2018 12:41:45 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53020 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f6fI0-00013r-Sf; Thu, 12 Apr 2018 12:41:37 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 05D1181A88A8; Thu, 12 Apr 2018 16:41:33 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2A1E10B00B2; Thu, 12 Apr 2018 16:41:31 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Thu, 12 Apr 2018 18:40:19 +0200 Message-Id: <1523551221-11612-3-git-send-email-imammedo@redhat.com> In-Reply-To: <1523551221-11612-1-git-send-email-imammedo@redhat.com> References: <1523551221-11612-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 12 Apr 2018 16:41:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 12 Apr 2018 16:41:33 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'imammedo@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH for-2.13 2/4] platform-bus-device: use device plug callback instead of machine_done notifier X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, agraf@suse.de, eric.auger@redhat.com, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" platform-bus were using machine_done notifier to get and map (assign irq/mmio resources) dynamically added sysbus devices after all '-device' options had been processed. That however creates non obvious dependencies on ordering of machine_done notifiers and requires carefull line juggling to keep it working. For example see comment above create_platform_bus() and 'straitforward' arm_load_kernel() had to converted to machine_done notifier and that lead to yet another machine_done notifier to keep it working arm_register_platform_bus_fdt_creator(). Instead of hiding resource assignment in platform-bus-device to magically initialize sysbus devices, use device plug callback and assign resources explicitly at board level at the moment each -device option is being processed. That adds a bunch of machine declaration boiler plate to e500plat board, similar to ARM/x86 but gets rid of hidden machine_done notifier and would allow to remove the dependent notifiers in ARM code simplifying it and making code flow easier to follow. Signed-off-by: Igor Mammedov --- CC: agraf@suse.de CC: david@gibson.dropbear.id.au CC: qemu-ppc@nongnu.org --- hw/ppc/e500.h | 3 +++ include/hw/arm/virt.h | 3 +++ include/hw/platform-bus.h | 4 ++-- hw/arm/sysbus-fdt.c | 3 --- hw/arm/virt.c | 36 ++++++++++++++++++++++++++++ hw/core/platform-bus.c | 29 ++++------------------- hw/ppc/e500.c | 37 +++++++++++++++++------------ hw/ppc/e500plat.c | 60 +++++++++++++++++++++++++++++++++++++++++++= ++-- 8 files changed, 129 insertions(+), 46 deletions(-) diff --git a/hw/ppc/e500.h b/hw/ppc/e500.h index 70ba1d8..d0f8ddd 100644 --- a/hw/ppc/e500.h +++ b/hw/ppc/e500.h @@ -2,6 +2,7 @@ #define PPCE500_H =20 #include "hw/boards.h" +#include "hw/sysbus.h" =20 typedef struct PPCE500Params { int pci_first_slot; @@ -26,6 +27,8 @@ typedef struct PPCE500Params { =20 void ppce500_init(MachineState *machine, PPCE500Params *params); =20 +void ppce500_plug_dynamic_sysbus_device(SysBusDevice *sbdev); + hwaddr booke206_page_size_to_tlb(uint64_t size); =20 #endif diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index ba0c1a4..5535760 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -86,11 +86,14 @@ typedef struct { bool no_pmu; bool claim_edge_triggered_timers; bool smbios_old_sys_ver; + HotplugHandler *(*get_hotplug_handler)(MachineState *machine, + DeviceState *dev); } VirtMachineClass; =20 typedef struct { MachineState parent; Notifier machine_done; + DeviceState *platform_bus_dev; FWCfgState *fw_cfg; bool secure; bool highmem; diff --git a/include/hw/platform-bus.h b/include/hw/platform-bus.h index a00775c..19e20c5 100644 --- a/include/hw/platform-bus.h +++ b/include/hw/platform-bus.h @@ -37,8 +37,6 @@ typedef struct PlatformBusDevice PlatformBusDevice; struct PlatformBusDevice { /*< private >*/ SysBusDevice parent_obj; - Notifier notifier; - bool done_gathering; =20 /*< public >*/ uint32_t mmio_size; @@ -54,4 +52,6 @@ int platform_bus_get_irqn(PlatformBusDevice *platform_bus= , SysBusDevice *sbdev, hwaddr platform_bus_get_mmio_addr(PlatformBusDevice *pbus, SysBusDevice *s= bdev, int n); =20 +void platform_bus_link_device(PlatformBusDevice *pbus, SysBusDevice *sbdev= ); + #endif /* HW_PLATFORM_BUS_H */ diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c index d68e3dc..80ff70e 100644 --- a/hw/arm/sysbus-fdt.c +++ b/hw/arm/sysbus-fdt.c @@ -506,9 +506,6 @@ static void add_all_platform_bus_fdt_nodes(ARMPlatformB= usFDTParams *fdt_params) dev =3D qdev_find_recursive(sysbus_get_default(), TYPE_PLATFORM_BUS_DE= VICE); pbus =3D PLATFORM_BUS_DEVICE(dev); =20 - /* We can only create dt nodes for dynamic devices when they're ready = */ - assert(pbus->done_gathering); - PlatformBusFDTData data =3D { .fdt =3D fdt, .irq_start =3D irq_start, diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 94dcb12..2e10d8b 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1087,6 +1087,7 @@ static void create_platform_bus(VirtMachineState *vms= , qemu_irq *pic) qdev_prop_set_uint32(dev, "mmio_size", platform_bus_params.platform_bus_size); qdev_init_nofail(dev); + vms->platform_bus_dev =3D dev; s =3D SYS_BUS_DEVICE(dev); =20 for (i =3D 0; i < platform_bus_params.platform_bus_num_irqs; i++) { @@ -1536,9 +1537,37 @@ static const CPUArchIdList *virt_possible_cpu_arch_i= ds(MachineState *ms) return ms->possible_cpus; } =20 +static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + VirtMachineState *vms =3D VIRT_MACHINE(hotplug_dev); + + if (object_dynamic_cast(OBJECT(dev), TYPE_SYS_BUS_DEVICE)) { + if (vms->platform_bus_dev) { + platform_bus_link_device(PLATFORM_BUS_DEVICE(vms->platform_bus= _dev), + SYS_BUS_DEVICE(dev)); + } + } +} + +static HotplugHandler *virt_machine_get_hotpug_handler(MachineState *machi= ne, + DeviceState *dev) +{ + VirtMachineClass *vmc =3D VIRT_MACHINE_GET_CLASS(machine); + + if (object_dynamic_cast(OBJECT(dev), TYPE_SYS_BUS_DEVICE)) { + return HOTPLUG_HANDLER(machine); + } + + return vmc->get_hotplug_handler ? + vmc->get_hotplug_handler(machine, dev) : NULL; +} + static void virt_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); + VirtMachineClass *vmc =3D VIRT_MACHINE_CLASS(oc); + HotplugHandlerClass *hc =3D HOTPLUG_HANDLER_CLASS(oc); =20 mc->init =3D machvirt_init; /* Start max_cpus at the maximum QEMU supports. We'll further restrict @@ -1557,6 +1586,9 @@ static void virt_machine_class_init(ObjectClass *oc, = void *data) mc->cpu_index_to_instance_props =3D virt_cpu_index_to_props; mc->default_cpu_type =3D ARM_CPU_TYPE_NAME("cortex-a15"); mc->get_default_cpu_node_id =3D virt_get_default_cpu_node_id; + vmc->get_hotplug_handler =3D mc->get_hotplug_handler; + mc->get_hotplug_handler =3D virt_machine_get_hotpug_handler; + hc->plug =3D virt_machine_device_plug_cb; } =20 static const TypeInfo virt_machine_info =3D { @@ -1566,6 +1598,10 @@ static const TypeInfo virt_machine_info =3D { .instance_size =3D sizeof(VirtMachineState), .class_size =3D sizeof(VirtMachineClass), .class_init =3D virt_machine_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_HOTPLUG_HANDLER }, + { } + }, }; =20 static void machvirt_machine_init(void) diff --git a/hw/core/platform-bus.c b/hw/core/platform-bus.c index 33d32fb..807cb5c 100644 --- a/hw/core/platform-bus.c +++ b/hw/core/platform-bus.c @@ -103,7 +103,6 @@ static void plaform_bus_refresh_irqs(PlatformBusDevice = *pbus) { bitmap_zero(pbus->used_irqs, pbus->num_irqs); foreach_dynamic_sysbus_device(platform_bus_count_irqs, pbus); - pbus->done_gathering =3D true; } =20 static void platform_bus_map_irq(PlatformBusDevice *pbus, SysBusDevice *sb= dev, @@ -163,12 +162,11 @@ static void platform_bus_map_mmio(PlatformBusDevice *= pbus, SysBusDevice *sbdev, } =20 /* - * For each sysbus device, look for unassigned IRQ lines as well as - * unassociated MMIO regions. Connect them to the platform bus if availabl= e. + * Look for unassigned IRQ lines as well as unassociated MMIO regions. + * Connect them to the platform bus if available. */ -static void link_sysbus_device(SysBusDevice *sbdev, void *opaque) +void platform_bus_link_device(PlatformBusDevice *pbus, SysBusDevice *sbdev) { - PlatformBusDevice *pbus =3D opaque; int i; =20 for (i =3D 0; sysbus_has_irq(sbdev, i); i++) { @@ -180,19 +178,6 @@ static void link_sysbus_device(SysBusDevice *sbdev, vo= id *opaque) } } =20 -static void platform_bus_init_notify(Notifier *notifier, void *data) -{ - PlatformBusDevice *pb =3D container_of(notifier, PlatformBusDevice, no= tifier); - - /* - * Generate a bitmap of used IRQ lines, as the user might have specifi= ed - * them on the command line. - */ - plaform_bus_refresh_irqs(pb); - - foreach_dynamic_sysbus_device(link_sysbus_device, pb); -} - static void platform_bus_realize(DeviceState *dev, Error **errp) { PlatformBusDevice *pbus; @@ -211,12 +196,8 @@ static void platform_bus_realize(DeviceState *dev, Err= or **errp) sysbus_init_irq(d, &pbus->irqs[i]); } =20 - /* - * Register notifier that allows us to gather dangling devices once the - * machine is completely assembled - */ - pbus->notifier.notify =3D platform_bus_init_notify; - qemu_add_machine_init_done_notifier(&pbus->notifier); + /* some devices might be initialized before so update used IRQs map */ + plaform_bus_refresh_irqs(pbus); } =20 static Property platform_bus_properties[] =3D { diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c index 9a85a41..e2829db 100644 --- a/hw/ppc/e500.c +++ b/hw/ppc/e500.c @@ -64,6 +64,8 @@ #define MPC8XXX_GPIO_OFFSET 0x000FF000ULL #define MPC8XXX_GPIO_IRQ 47 =20 +static SysBusDevice *pbus_dev; + struct boot_info { uint32_t dt_base; @@ -248,23 +250,28 @@ static void platform_bus_create_devtree(PPCE500Params= *params, void *fdt, dev =3D qdev_find_recursive(sysbus_get_default(), TYPE_PLATFORM_BUS_DE= VICE); pbus =3D PLATFORM_BUS_DEVICE(dev); =20 - /* We can only create dt nodes for dynamic devices when they're ready = */ - if (pbus->done_gathering) { - PlatformDevtreeData data =3D { - .fdt =3D fdt, - .mpic =3D mpic, - .irq_start =3D irq_start, - .node =3D node, - .pbus =3D pbus, - }; + /* Create dt nodes for dynamic devices */ + PlatformDevtreeData data =3D { + .fdt =3D fdt, + .mpic =3D mpic, + .irq_start =3D irq_start, + .node =3D node, + .pbus =3D pbus, + }; =20 - /* Loop through all dynamic sysbus devices and create nodes for th= em */ - foreach_dynamic_sysbus_device(sysbus_device_create_devtree, &data); - } + /* Loop through all dynamic sysbus devices and create nodes for them */ + foreach_dynamic_sysbus_device(sysbus_device_create_devtree, &data); =20 g_free(node); } =20 +void ppce500_plug_dynamic_sysbus_device(SysBusDevice *sbdev) +{ + if (pbus_dev) { + platform_bus_link_device(PLATFORM_BUS_DEVICE(pbus_dev), sbdev); + } +} + static int ppce500_load_device_tree(MachineState *machine, PPCE500Params *params, hwaddr addr, @@ -945,16 +952,16 @@ void ppce500_init(MachineState *machine, PPCE500Param= s *params) qdev_prop_set_uint32(dev, "num_irqs", params->platform_bus_num_irq= s); qdev_prop_set_uint32(dev, "mmio_size", params->platform_bus_size); qdev_init_nofail(dev); - s =3D SYS_BUS_DEVICE(dev); + pbus_dev =3D SYS_BUS_DEVICE(dev); =20 for (i =3D 0; i < params->platform_bus_num_irqs; i++) { int irqn =3D params->platform_bus_first_irq + i; - sysbus_connect_irq(s, i, qdev_get_gpio_in(mpicdev, irqn)); + sysbus_connect_irq(pbus_dev, i, qdev_get_gpio_in(mpicdev, irqn= )); } =20 memory_region_add_subregion(address_space_mem, params->platform_bus_base, - sysbus_mmio_get_region(s, 0)); + sysbus_mmio_get_region(pbus_dev, 0)); } =20 /* diff --git a/hw/ppc/e500plat.c b/hw/ppc/e500plat.c index 81d03e1..2f014cc 100644 --- a/hw/ppc/e500plat.c +++ b/hw/ppc/e500plat.c @@ -60,8 +60,49 @@ static void e500plat_init(MachineState *machine) ppce500_init(machine, ¶ms); } =20 -static void e500plat_machine_init(MachineClass *mc) +typedef struct { + MachineClass parent; + HotplugHandler *(*get_hotplug_handler)(MachineState *machine, + DeviceState *dev); +} E500PlatMachineClass; + +#define TYPE_E500PLAT_MACHINE MACHINE_TYPE_NAME("ppce500") +#define E500PLAT_MACHINE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(E500PlatMachineClass, obj, TYPE_E500PLAT_MACHINE) +#define E500PLAT_MACHINE_CLASS(klass) \ + OBJECT_CLASS_CHECK(E500PlatMachineClass, klass, TYPE_E500PLAT_MACHINE) + +static void e500plat_machine_device_plug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) { + if (object_dynamic_cast(OBJECT(dev), TYPE_SYS_BUS_DEVICE)) { + ppce500_plug_dynamic_sysbus_device(SYS_BUS_DEVICE(dev)); + } +} + +static +HotplugHandler *e500plat_machine_get_hotpug_handler(MachineState *machine, + DeviceState *dev) +{ + E500PlatMachineClass *emc =3D E500PLAT_MACHINE_GET_CLASS(machine); + if (object_dynamic_cast(OBJECT(dev), TYPE_SYS_BUS_DEVICE)) { + return HOTPLUG_HANDLER(machine); + } + + return emc->get_hotplug_handler ? + emc->get_hotplug_handler(machine, dev) : NULL; +} + +static void e500plat_machine_class_init(ObjectClass *oc, void *data) +{ + E500PlatMachineClass *emc =3D E500PLAT_MACHINE_CLASS(oc); + HotplugHandlerClass *hc =3D HOTPLUG_HANDLER_CLASS(oc); + MachineClass *mc =3D MACHINE_CLASS(oc); + + emc->get_hotplug_handler =3D mc->get_hotplug_handler; + mc->get_hotplug_handler =3D e500plat_machine_get_hotpug_handler; + hc->plug =3D e500plat_machine_device_plug_cb; + mc->desc =3D "generic paravirt e500 platform"; mc->init =3D e500plat_init; mc->max_cpus =3D 32; @@ -69,4 +110,19 @@ static void e500plat_machine_init(MachineClass *mc) mc->default_cpu_type =3D POWERPC_CPU_TYPE_NAME("e500v2_v30"); } =20 -DEFINE_MACHINE("ppce500", e500plat_machine_init) +static const TypeInfo e500plat_info =3D { + .name =3D TYPE_E500PLAT_MACHINE, + .parent =3D TYPE_MACHINE, + .class_size =3D sizeof(E500PlatMachineClass), + .class_init =3D e500plat_machine_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_HOTPLUG_HANDLER }, + { } + } +}; + +static void e500plat_register_types(void) +{ + type_register_static(&e500plat_info); +} +type_init(e500plat_register_types) --=20 2.7.4 From nobody Sat Apr 20 06:03:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523551433875124.45304133529919; Thu, 12 Apr 2018 09:43:53 -0700 (PDT) Received: from localhost ([::1]:53527 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6fK9-0005lB-E0 for importer@patchew.org; Thu, 12 Apr 2018 12:43:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58282) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6fI6-00045o-Le for qemu-devel@nongnu.org; Thu, 12 Apr 2018 12:41:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6fI5-00018k-VO for qemu-devel@nongnu.org; Thu, 12 Apr 2018 12:41:42 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40716 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f6fI0-00013p-Sc; Thu, 12 Apr 2018 12:41:36 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EDBBB4074453; Thu, 12 Apr 2018 16:41:33 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A9BE1208F8D; Thu, 12 Apr 2018 16:41:33 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Thu, 12 Apr 2018 18:40:20 +0200 Message-Id: <1523551221-11612-4-git-send-email-imammedo@redhat.com> In-Reply-To: <1523551221-11612-1-git-send-email-imammedo@redhat.com> References: <1523551221-11612-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 12 Apr 2018 16:41:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 12 Apr 2018 16:41:34 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'imammedo@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH for-2.13 3/4] arm: always start from first_cpu when registering loader cpu reset callback X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, eric.auger@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" if arm_load_kernel() were passed non first_cpu, QEMU would end up with partially set do_cpu_reset() callback leaving some CPUs without it. Make sure that do_cpu_reset() is registered for all CPUs by enumerating CPUs from first_cpu. Signed-off-by: Igor Mammedov Reviewed-by: Peter Maydell --- hw/arm/boot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 2f464ca..2591fee 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -1188,7 +1188,7 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_inf= o *info) * actually loading a kernel, the handler is also responsible for * arranging that we start it correctly. */ - for (cs =3D CPU(cpu); cs; cs =3D CPU_NEXT(cs)) { + for (cs =3D first_cpu; cs; cs =3D CPU_NEXT(cs)) { qemu_register_reset(do_cpu_reset, ARM_CPU(cs)); } } --=20 2.7.4 From nobody Sat Apr 20 06:03:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523551567034405.97994253424577; Thu, 12 Apr 2018 09:46:07 -0700 (PDT) Received: from localhost ([::1]:53645 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6fMM-0008Em-7Y for importer@patchew.org; Thu, 12 Apr 2018 12:46:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6fIA-0004Di-LM for qemu-devel@nongnu.org; Thu, 12 Apr 2018 12:41:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6fI8-0001AD-1d for qemu-devel@nongnu.org; Thu, 12 Apr 2018 12:41:46 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59216 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f6fI0-00013q-Se; Thu, 12 Apr 2018 12:41:37 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 07D06EB715; Thu, 12 Apr 2018 16:41:35 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DD0A1208F86; Thu, 12 Apr 2018 16:41:34 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Thu, 12 Apr 2018 18:40:21 +0200 Message-Id: <1523551221-11612-5-git-send-email-imammedo@redhat.com> In-Reply-To: <1523551221-11612-1-git-send-email-imammedo@redhat.com> References: <1523551221-11612-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 12 Apr 2018 16:41:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 12 Apr 2018 16:41:35 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'imammedo@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH for-2.13 4/4] arm/boot: split load_dtb() from arm_load_kernel() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, eric.auger@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" load_dtb() depends on arm_load_kernel() to figure out place in RAM where it should be loaded, but it's not required for arm_load_kernel() to work. Sometimes it's neccesary for devices added with -device/device_add to be enumerated in DTB as well, which's lead to [1] and surrounding commits to add 2 more machine_done notifiers with non obvious ordering to make dynamic sysbus devices initialization happen in the right order. However instead of moving whole arm_load_kernel() in to machine_done, it's sufficient to move only load_dtb() into virt_machine_done() notifier and remove ArmLoadKernelNotifier/ /PlatformBusFDTNotifierParams notifiers, which saves us ~90LOC and simplifies code flow quite a bit. Later would allow to consolidate DTB generation within one function for 'mach-virt' board and make it reentrant so it could generate updated DTB in device hotplug secenarios. While at it rename load_dtb() to arm_load_dtb() since it's public now. Add additional field skip_dtb_autoload to struct arm_boot_info to allow manual DTB load later in mach-virt and to avoid touching all other boards to explicitly call arm_load_dtb(). 1) (ac9d32e hw/arm/boot: arm_load_kernel implemented as a machine init don= e notifier) Signed-off-by: Igor Mammedov --- include/hw/arm/arm.h | 37 ++++++++++++++++++------- include/hw/arm/sysbus-fdt.h | 37 +++++-------------------- hw/arm/boot.c | 67 +++++++++++------------------------------= ---- hw/arm/sysbus-fdt.c | 64 ++++-------------------------------------= -- hw/arm/virt.c | 64 ++++++++++++++++++++---------------------= -- 5 files changed, 86 insertions(+), 183 deletions(-) diff --git a/include/hw/arm/arm.h b/include/hw/arm/arm.h index 188d18b..312e533 100644 --- a/include/hw/arm/arm.h +++ b/include/hw/arm/arm.h @@ -39,15 +39,6 @@ DeviceState *armv7m_init(MemoryRegion *system_memory, in= t mem_size, int num_irq, */ void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename, int mem_= size); =20 -/* - * struct used as a parameter of the arm_load_kernel machine init - * done notifier - */ -typedef struct { - Notifier notifier; /* actual notifier */ - ARMCPU *cpu; /* handle to the first cpu object */ -} ArmLoadKernelNotifier; - /* arm_boot.c */ struct arm_boot_info { uint64_t ram_size; @@ -56,6 +47,9 @@ struct arm_boot_info { const char *initrd_filename; const char *dtb_filename; hwaddr loader_start; + hwaddr dtb_start; + hwaddr dtb_limit; + bool skip_dtb_autoload; /* multicore boards that use the default secondary core boot functions * need to put the address of the secondary boot code, the boot reg, * and the GIC address in the next 3 values, respectively. boards that @@ -95,7 +89,6 @@ struct arm_boot_info { */ void (*modify_dtb)(const struct arm_boot_info *info, void *fdt); /* machine init done notifier executing arm_load_dtb */ - ArmLoadKernelNotifier load_kernel_notifier; /* Used internally by arm_boot.c */ int is_linux; hwaddr initrd_start; @@ -145,6 +138,30 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info= *info); =20 AddressSpace *arm_boot_address_space(ARMCPU *cpu, bool secure_boot); =20 +/** + * arm_load_dtb() - load a device tree binary image into memory + * @addr: the address to load the image at + * @binfo: struct describing the boot environment + * @addr_limit: upper limit of the available memory area at @addr + * @as: address space to load image to + * + * Load a device tree supplied by the machine or by the user with the + * '-dtb' command line option, and put it at offset @addr in target + * memory. + * + * If @addr_limit contains a meaningful value (i.e., it is strictly greater + * than @addr), the device tree is only loaded if its size does not exceed + * the limit. + * + * Returns: the size of the device tree image on success, + * 0 if the image size exceeds the limit, + * -1 on errors. + * + * Note: Must not be called unless have_dtb(binfo) is true. + */ +int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo, + hwaddr addr_limit, AddressSpace *as); + /* Write a secure board setup routine with a dummy handler for SMCs */ void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu, const struct arm_boot_info *in= fo, diff --git a/include/hw/arm/sysbus-fdt.h b/include/hw/arm/sysbus-fdt.h index e15bb81..340c382 100644 --- a/include/hw/arm/sysbus-fdt.h +++ b/include/hw/arm/sysbus-fdt.h @@ -24,37 +24,14 @@ #ifndef HW_ARM_SYSBUS_FDT_H #define HW_ARM_SYSBUS_FDT_H =20 -#include "hw/arm/arm.h" -#include "qemu-common.h" -#include "hw/sysbus.h" - -/* - * struct that contains dimensioning parameters of the platform bus - */ -typedef struct { - hwaddr platform_bus_base; /* start address of the bus */ - hwaddr platform_bus_size; /* size of the bus */ - int platform_bus_first_irq; /* first hwirq assigned to the bus */ - int platform_bus_num_irqs; /* number of hwirq assigned to the bus */ -} ARMPlatformBusSystemParams; - -/* - * struct that contains all relevant info to build the fdt nodes of - * platform bus and attached dynamic sysbus devices - * in the future might be augmented with additional info - * such as PHY, CLK handles ... - */ -typedef struct { - const ARMPlatformBusSystemParams *system_params; - struct arm_boot_info *binfo; - const char *intc; /* parent interrupt controller name */ -} ARMPlatformBusFDTParams; +#include "exec/hwaddr.h" =20 /** - * arm_register_platform_bus_fdt_creator - register a machine init done - * notifier that creates the device tree nodes of the platform bus and - * associated dynamic sysbus devices + * platform_bus_add_all_fdt_nodes - create all the platform bus nodes + * + * builds the parent platform bus node and all the nodes of dynamic + * sysbus devices attached to it. */ -void arm_register_platform_bus_fdt_creator(ARMPlatformBusFDTParams *fdt_pa= rams); - +void platform_bus_add_all_fdt_nodes(void *fdt, const char *intc, hwaddr ad= dr, + hwaddr bus_size, int irq_start); #endif diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 2591fee..0cd2fb3 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -485,29 +485,8 @@ static void fdt_add_psci_node(void *fdt) qemu_fdt_setprop_cell(fdt, "/psci", "migrate", migrate_fn); } =20 -/** - * load_dtb() - load a device tree binary image into memory - * @addr: the address to load the image at - * @binfo: struct describing the boot environment - * @addr_limit: upper limit of the available memory area at @addr - * @as: address space to load image to - * - * Load a device tree supplied by the machine or by the user with the - * '-dtb' command line option, and put it at offset @addr in target - * memory. - * - * If @addr_limit contains a meaningful value (i.e., it is strictly greater - * than @addr), the device tree is only loaded if its size does not exceed - * the limit. - * - * Returns: the size of the device tree image on success, - * 0 if the image size exceeds the limit, - * -1 on errors. - * - * Note: Must not be called unless have_dtb(binfo) is true. - */ -static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo, - hwaddr addr_limit, AddressSpace *as) +int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo, + hwaddr addr_limit, AddressSpace *as) { void *fdt =3D NULL; int size, rc; @@ -935,7 +914,7 @@ static uint64_t load_aarch64_image(const char *filename= , hwaddr mem_base, return size; } =20 -static void arm_load_kernel_notify(Notifier *notifier, void *data) +void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) { CPUState *cs; int kernel_size; @@ -945,11 +924,6 @@ static void arm_load_kernel_notify(Notifier *notifier,= void *data) int elf_machine; hwaddr entry; static const ARMInsnFixup *primary_loader; - ArmLoadKernelNotifier *n =3D DO_UPCAST(ArmLoadKernelNotifier, - notifier, notifier); - ARMCPU *cpu =3D n->cpu; - struct arm_boot_info *info =3D - container_of(n, struct arm_boot_info, load_kernel_notifier); AddressSpace *as =3D arm_boot_address_space(cpu, info->secure_boot); =20 /* The board code is not supposed to set secure_board_setup unless @@ -968,9 +942,7 @@ static void arm_load_kernel_notify(Notifier *notifier, = void *data) * the kernel is supposed to be loaded by the bootloader), cop= y the * DTB to the base of RAM for the bootloader to pick up. */ - if (load_dtb(info->loader_start, info, 0, as) < 0) { - exit(1); - } + info->dtb_start =3D info->loader_start; } =20 if (info->kernel_filename) { @@ -1050,15 +1022,14 @@ static void arm_load_kernel_notify(Notifier *notifi= er, void *data) */ if (elf_low_addr > info->loader_start || elf_high_addr < info->loader_start) { - /* Pass elf_low_addr as address limit to load_dtb if it may be + /* Set elf_low_addr as address limit for arm_load_dtb if it ma= y be * pointing into RAM, otherwise pass '0' (no limit) */ if (elf_low_addr < info->loader_start) { elf_low_addr =3D 0; } - if (load_dtb(info->loader_start, info, elf_low_addr, as) < 0) { - exit(1); - } + info->dtb_start =3D info->loader_start; + info->dtb_limit =3D elf_low_addr; } } entry =3D elf_entry; @@ -1116,7 +1087,6 @@ static void arm_load_kernel_notify(Notifier *notifier= , void *data) */ if (have_dtb(info)) { hwaddr align; - hwaddr dtb_start; =20 if (elf_machine =3D=3D EM_AARCH64) { /* @@ -1136,11 +1106,9 @@ static void arm_load_kernel_notify(Notifier *notifie= r, void *data) } =20 /* Place the DTB after the initrd in memory with alignment. */ - dtb_start =3D QEMU_ALIGN_UP(info->initrd_start + initrd_size, = align); - if (load_dtb(dtb_start, info, 0, as) < 0) { - exit(1); - } - fixupcontext[FIXUP_ARGPTR] =3D dtb_start; + info->dtb_start =3D QEMU_ALIGN_UP(info->initrd_start + initrd_= size, + align); + fixupcontext[FIXUP_ARGPTR] =3D info->dtb_start; } else { fixupcontext[FIXUP_ARGPTR] =3D info->loader_start + KERNEL_ARG= S_ADDR; if (info->ram_size >=3D (1ULL << 32)) { @@ -1173,15 +1141,6 @@ static void arm_load_kernel_notify(Notifier *notifie= r, void *data) for (cs =3D CPU(cpu); cs; cs =3D CPU_NEXT(cs)) { ARM_CPU(cs)->env.boot_info =3D info; } -} - -void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) -{ - CPUState *cs; - - info->load_kernel_notifier.cpu =3D cpu; - info->load_kernel_notifier.notifier.notify =3D arm_load_kernel_notify; - qemu_add_machine_init_done_notifier(&info->load_kernel_notifier.notifi= er); =20 /* CPU objects (unlike devices) are not automatically reset on system * reset, so we must always register a handler to do so. If we're @@ -1191,6 +1150,12 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_in= fo *info) for (cs =3D first_cpu; cs; cs =3D CPU_NEXT(cs)) { qemu_register_reset(do_cpu_reset, ARM_CPU(cs)); } + + if (!info->skip_dtb_autoload) { + if (arm_load_dtb(info->dtb_start, info, info->dtb_limit, as) < 0) { + exit(1); + } + } } =20 static const TypeInfo arm_linux_boot_if_info =3D { diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c index 80ff70e..a4dea93 100644 --- a/hw/arm/sysbus-fdt.c +++ b/hw/arm/sysbus-fdt.c @@ -49,15 +49,6 @@ typedef struct PlatformBusFDTData { PlatformBusDevice *pbus; } PlatformBusFDTData; =20 -/* - * struct used when calling the machine init done notifier - * that constructs the fdt nodes of platform bus devices - */ -typedef struct PlatformBusFDTNotifierParams { - Notifier notifier; - ARMPlatformBusFDTParams *fdt_params; -} PlatformBusFDTNotifierParams; - /* struct that associates a device type name and a node creation function = */ typedef struct NodeCreationPair { const char *typename; @@ -453,42 +444,17 @@ static void add_fdt_node(SysBusDevice *sbdev, void *o= paque) exit(1); } =20 -/** - * add_all_platform_bus_fdt_nodes - create all the platform bus nodes - * - * builds the parent platform bus node and all the nodes of dynamic - * sysbus devices attached to it. - */ -static void add_all_platform_bus_fdt_nodes(ARMPlatformBusFDTParams *fdt_pa= rams) +void platform_bus_add_all_fdt_nodes(void *fdt, const char *intc, hwaddr ad= dr, + hwaddr bus_size, int irq_start) { const char platcomp[] =3D "qemu,platform\0simple-bus"; - PlatformBusDevice *pbus; DeviceState *dev; + PlatformBusDevice *pbus; gchar *node; - uint64_t addr, size; - int irq_start, dtb_size; - struct arm_boot_info *info =3D fdt_params->binfo; - const ARMPlatformBusSystemParams *params =3D fdt_params->system_params; - const char *intc =3D fdt_params->intc; - void *fdt =3D info->get_dtb(info, &dtb_size); - - /* - * If the user provided a dtb, we assume the dynamic sysbus nodes - * already are integrated there. This corresponds to a use case where - * the dynamic sysbus nodes are complex and their generation is not yet - * supported. In that case the user can take charge of the guest dt - * while qemu takes charge of the qom stuff. - */ - if (info->dtb_filename) { - return; - } =20 assert(fdt); =20 - node =3D g_strdup_printf("/platform@%"PRIx64, params->platform_bus_bas= e); - addr =3D params->platform_bus_base; - size =3D params->platform_bus_size; - irq_start =3D params->platform_bus_first_irq; + node =3D g_strdup_printf("/platform@%"PRIx64, addr); =20 /* Create a /platform node that we can put all devices into */ qemu_fdt_add_subnode(fdt, node); @@ -499,10 +465,11 @@ static void add_all_platform_bus_fdt_nodes(ARMPlatfor= mBusFDTParams *fdt_params) */ qemu_fdt_setprop_cells(fdt, node, "#size-cells", 1); qemu_fdt_setprop_cells(fdt, node, "#address-cells", 1); - qemu_fdt_setprop_cells(fdt, node, "ranges", 0, addr >> 32, addr, size); + qemu_fdt_setprop_cells(fdt, node, "ranges", 0, addr >> 32, addr, bus_s= ize); =20 qemu_fdt_setprop_phandle(fdt, node, "interrupt-parent", intc); =20 + dev =3D qdev_find_recursive(sysbus_get_default(), TYPE_PLATFORM_BUS_DE= VICE); pbus =3D PLATFORM_BUS_DEVICE(dev); =20 @@ -518,22 +485,3 @@ static void add_all_platform_bus_fdt_nodes(ARMPlatform= BusFDTParams *fdt_params) =20 g_free(node); } - -static void platform_bus_fdt_notify(Notifier *notifier, void *data) -{ - PlatformBusFDTNotifierParams *p =3D DO_UPCAST(PlatformBusFDTNotifierPa= rams, - notifier, notifier); - - add_all_platform_bus_fdt_nodes(p->fdt_params); - g_free(p->fdt_params); - g_free(p); -} - -void arm_register_platform_bus_fdt_creator(ARMPlatformBusFDTParams *fdt_pa= rams) -{ - PlatformBusFDTNotifierParams *p =3D g_new(PlatformBusFDTNotifierParams= , 1); - - p->fdt_params =3D fdt_params; - p->notifier.notify =3D platform_bus_fdt_notify; - qemu_add_machine_init_done_notifier(&p->notifier); -} diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 2e10d8b..4139e56 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -93,8 +93,6 @@ =20 #define PLATFORM_BUS_NUM_IRQS 64 =20 -static ARMPlatformBusSystemParams platform_bus_params; - /* RAM limit in GB. Since VIRT_MEM starts at the 1GB mark, this means * RAM can go up to the 256GB mark, leaving 256GB of the physical * address space unallocated and free for future use between 256G and 512G. @@ -1063,40 +1061,23 @@ static void create_platform_bus(VirtMachineState *v= ms, qemu_irq *pic) DeviceState *dev; SysBusDevice *s; int i; - ARMPlatformBusFDTParams *fdt_params =3D g_new(ARMPlatformBusFDTParams,= 1); MemoryRegion *sysmem =3D get_system_memory(); =20 - platform_bus_params.platform_bus_base =3D vms->memmap[VIRT_PLATFORM_BU= S].base; - platform_bus_params.platform_bus_size =3D vms->memmap[VIRT_PLATFORM_BU= S].size; - platform_bus_params.platform_bus_first_irq =3D vms->irqmap[VIRT_PLATFO= RM_BUS]; - platform_bus_params.platform_bus_num_irqs =3D PLATFORM_BUS_NUM_IRQS; - - fdt_params->system_params =3D &platform_bus_params; - fdt_params->binfo =3D &vms->bootinfo; - fdt_params->intc =3D "/intc"; - /* - * register a machine init done notifier that creates the device tree - * nodes of the platform bus and its children dynamic sysbus devices - */ - arm_register_platform_bus_fdt_creator(fdt_params); - dev =3D qdev_create(NULL, TYPE_PLATFORM_BUS_DEVICE); dev->id =3D TYPE_PLATFORM_BUS_DEVICE; - qdev_prop_set_uint32(dev, "num_irqs", - platform_bus_params.platform_bus_num_irqs); - qdev_prop_set_uint32(dev, "mmio_size", - platform_bus_params.platform_bus_size); + qdev_prop_set_uint32(dev, "num_irqs", PLATFORM_BUS_NUM_IRQS); + qdev_prop_set_uint32(dev, "mmio_size", vms->memmap[VIRT_PLATFORM_BUS].= size); qdev_init_nofail(dev); vms->platform_bus_dev =3D dev; - s =3D SYS_BUS_DEVICE(dev); =20 - for (i =3D 0; i < platform_bus_params.platform_bus_num_irqs; i++) { - int irqn =3D platform_bus_params.platform_bus_first_irq + i; + s =3D SYS_BUS_DEVICE(dev); + for (i =3D 0; i < PLATFORM_BUS_NUM_IRQS; i++) { + int irqn =3D vms->irqmap[VIRT_PLATFORM_BUS] + i; sysbus_connect_irq(s, i, pic[irqn]); } =20 memory_region_add_subregion(sysmem, - platform_bus_params.platform_bus_base, + vms->memmap[VIRT_PLATFORM_BUS].base, sysbus_mmio_get_region(s, 0)); } =20 @@ -1167,6 +1148,26 @@ void virt_machine_done(Notifier *notifier, void *dat= a) { VirtMachineState *vms =3D container_of(notifier, VirtMachineState, machine_done); + ARMCPU *cpu =3D ARM_CPU(first_cpu); + struct arm_boot_info *info =3D &vms->bootinfo; + AddressSpace *as =3D arm_boot_address_space(cpu, info->secure_boot); + + /* + * If the user provided a dtb, we assume the dynamic sysbus nodes + * already are integrated there. This corresponds to a use case where + * the dynamic sysbus nodes are complex and their generation is not yet + * supported. In that case the user can take charge of the guest dt + * while qemu takes charge of the qom stuff. + */ + if (info->dtb_filename =3D=3D NULL) { + platform_bus_add_all_fdt_nodes(vms->fdt, "/intc", + vms->memmap[VIRT_PLATFORM_BUS].base, + vms->memmap[VIRT_PLATFORM_BUS].size, + vms->irqmap[VIRT_PLATFORM_BUS]); + } + if (arm_load_dtb(info->dtb_start, info, info->dtb_limit, as) < 0) { + exit(1); + } =20 virt_acpi_setup(vms); virt_build_smbios(vms); @@ -1394,8 +1395,7 @@ static void machvirt_init(MachineState *machine) vms->fw_cfg =3D create_fw_cfg(vms, &address_space_memory); rom_set_fw(vms->fw_cfg); =20 - vms->machine_done.notify =3D virt_machine_done; - qemu_add_machine_init_done_notifier(&vms->machine_done); + create_platform_bus(vms, pic); =20 vms->bootinfo.ram_size =3D machine->ram_size; vms->bootinfo.kernel_filename =3D machine->kernel_filename; @@ -1405,16 +1405,12 @@ static void machvirt_init(MachineState *machine) vms->bootinfo.board_id =3D -1; vms->bootinfo.loader_start =3D vms->memmap[VIRT_MEM].base; vms->bootinfo.get_dtb =3D machvirt_dtb; + vms->bootinfo.skip_dtb_autoload =3D true; vms->bootinfo.firmware_loaded =3D firmware_loaded; arm_load_kernel(ARM_CPU(first_cpu), &vms->bootinfo); =20 - /* - * arm_load_kernel machine init done notifier registration must - * happen before the platform_bus_create call. In this latter, - * another notifier is registered which adds platform bus nodes. - * Notifiers are executed in registration reverse order. - */ - create_platform_bus(vms, pic); + vms->machine_done.notify =3D virt_machine_done; + qemu_add_machine_init_done_notifier(&vms->machine_done); } =20 static bool virt_get_secure(Object *obj, Error **errp) --=20 2.7.4