machvirt dynamic sysbus device instantiation
v5 cover machvirt dynamic sysbus device instantiation
This patch series enables machvirt to dynamically instantiate sysbus devices from command line (using -device option).
All those sysbus devices are plugged onto a platform bus. This latter device is instantiated in machvirt and takes care of the binding of children sysbus devices on a machine init done notifier. The device tree node generation for children dynamic sysbus device also happens on a subsequent notifier that must be executed after the above one. machvirt registers that notifier before the platform bus creation to make sure notifiers are executed in the right order: dt generation after actual QOM binding.
Very few sysbus devices are supposed to be instantiated that way. VFIO devices belong to them.
Node creation really is architecture specific. On ARM the dynamic sysbus device node creation is implemented in a new C module, hw/arm/sysbus-fdt.c and not in the machine file.
Machvirt transformations and sysbus-fdt are largely inspired from Alex work.
The patch series can be found at:
http://git.linaro.org/people/eric.auger/qemu.git (branch vfio_integ_v8)
Best Regards
Eric
v4 -> v5:
- in virt.c: platform_bus_params becomes static const
- sysbus-fdt: change indentation in add_fdt_node_functions array init
- s/load_dtb/arm_load_dtb in one boot.c comment
v3 -> v4:
- dyn_sysbus_binding removed since binding stuff now are implemented by the platform bus device
- due to a change in ARM load_dtb implementation using rom_add_blob_fixed, the dt no more is generated in a reset notifier but is generated on a machine init done notifier
- the augmented device tree is not generated from scratch anymore but is added using a modify_dtb function. This required some small change in boot.c
- the case where the user provides a dtb file now is handled
- some cleanup in virt additions
- implement a list of dyanmically instantiable devices in sysbus-fdt
v2 -> v3:
- patch now applies on top of Alex full patchset
- dyn_sysbus_devtree: add arm_prefix to emphasize the fact those functions are arm specific; arm_sysbus_device_create_devtree becomes static
- load_dtb renamed into arm_load_dtb
- add copyright in hw/arm/dyn_sysbus_devtree.c
Eric Auger (6):
hw/arm/boot: load_dtb becomes non static arm_load_dtb hw/arm/boot: dtb start and limit moved in arm_boot_info hw/arm/boot: do not free VirtBoardInfo fdt in arm_load_dtb hw/arm: add a new modify_dtb_opaque field in arm_boot_info hw/arm/sysbus-fdt: helpers for platform bus nodes addition hw/arm/virt: add dynamic sysbus device support
hw/arm/Makefile.objs | 1 + hw/arm/boot.c | 52 +++++++------ hw/arm/sysbus-fdt.c | 180 ++++++++++++++++++++++++++++++++++++++++++++ hw/arm/virt.c | 57 ++++++++++++++ include/hw/arm/arm.h | 7 ++ include/hw/arm/sysbus-fdt.h | 50 ++++++++++++ 6 files changed, 325 insertions(+), 22 deletions(-) create mode 100644 hw/arm/sysbus-fdt.c create mode 100644 include/hw/arm/sysbus-fdt.h
Signature · 1 line
1.8.3.2
PATCH v5 1/6 hw/arm/boot: load_dtb becomes non static arm_load_dtb
load_dtb is renamed into arm_load_dtb and becomes non static. it will be used by machvirt for dynamic instantiation of platform devices
---
v4 -> v5:
s/load_dtb/arm_load_dtb in one comment
v2 -> v3:load_dtb renamed into arm_load_dtb
Conflicts:
hw/arm/boot.c
--- hw/arm/boot.c | 16 ++++++++-------- include/hw/arm/arm.h | 2 ++ 2 files changed, 10 insertions(+), 8 deletions(-)
hw/arm/boot.c +8 -8
@@ -313,7 +313,7 @@ static void set_kernel_args_old(const struct arm_boot_info *info) }/** -* load_dtb() - load a device tree binary image into memory +* 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
@@ -330,8 +330,8 @@ static void set_kernel_args_old(const struct arm_boot_info *info)* 0 if the image size exceeds the limit, * -1 on errors. */ -static int load_dtb (hwaddr addr,const struct arm_boot_info *binfo, -hwaddr addr_limit) +int arm_load_dtb (hwaddr addr,const struct arm_boot_info *binfo, +hwaddr addr_limit) {void *fdt =NULL ;int size, rc;
@@ -504,7 +504,7 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info)/* If we have a device tree blob, but no kernel to supply it to, * copy it to the base of RAM for a bootloader to pick up. */ -if (load_dtb (info->loader_start, info,0 ) <0 ) { +if (arm_load_dtb (info->loader_start, info,0 ) <0 ) {exit (1 ); } }
@@ -566,13 +566,13 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info)*/ 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 -* pointing into RAM, otherwise pass '0' (no limit) +/* Pass elf_low_addr as address limit to arm_load_dtb if it may +* be pointing into RAM, otherwise pass '0' (no limit) */ if (elf_low_addr < info->loader_start) { elf_low_addr =0 ; } -if (load_dtb (info->loader_start, info, elf_low_addr) <0 ) { +if (arm_load_dtb (info->loader_start, info, elf_low_addr) <0 ) {exit (1 ); } }
@@ -637,7 +637,7 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info)*/ hwaddr dtb_start =QEMU_ALIGN_UP (info->initrd_start + initrd_size,4096 ); -if (load_dtb (dtb_start, info,0 ) <0 ) { +if (arm_load_dtb (dtb_start, info,0 ) <0 ) {exit (1 ); } fixupcontext[FIXUP_ARGPTR ] = dtb_start;
include/hw/arm/arm.h +2 -0
@@ -68,6 +68,8 @@ struct arm_boot_info {hwaddr entry; };void arm_load_kernel (ARMCPU *cpu,struct arm_boot_info *info); +int arm_load_dtb (hwaddr addr,const struct arm_boot_info *binfo, +hwaddr addr_limit);/* Multiplication factor to convert from system clock ticks to qemu timer ticks. */
Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [PATCH v5 1/6] hw/arm/boot: load_dtb becomes non static arm_load_dtb
Quoted 3 lines · Eric Auger
load_dtbis renamed intoarm_load_dtband becomes non static. it will be used by machvirt for dynamic instantiation of platform devices
'virt' shouldn't be a special case -- we should always handle setting up the DTB in guest memory in the same way, whether there happens to be a vfio platform device available or not.
thanks
-- PMM
Re: [Qemu-devel] [PATCH v5 1/6] hw/arm/boot: load_dtb becomes non static arm_load_dtb
Quoted 9 lines · Peter Maydell
Quoted 3 lines · Eric Auger
load_dtbis renamed intoarm_load_dtband becomes non static. it will be used by machvirt for dynamic instantiation of platform devices'virt' shouldn't be a special case -- we should always handle setting up the DTB in guest memory in the same way, whether there happens to be a vfio platform device available or not.
...this probably means that a bunch of the work currently done in arm_load_kernel() should be deferred to a 'machine init complete' hook (perhaps all of it?).
-- PMM
Re: [Qemu-devel] [PATCH v5 1/6] hw/arm/boot: load_dtb becomes non static arm_load_dtb
Quoted 6 lines · Peter Maydell
Quoted 5 lines · Peter Maydell
Quoted 3 lines · Eric Auger
load_dtbis renamed intoarm_load_dtband becomes non static. it will be used by machvirt for dynamic instantiation of platform devices
Quoted 8 lines
Quoted 4 lines
'virt' shouldn't be a special case -- we should always handle setting up the DTB in guest memory in the same way, whether there happens to be a vfio platform device available or not.
...this probably means that a bunch of the work currently done in
arm_load_kernel()should be deferred to a 'machine init complete' hook (perhaps all of it?).
Hi Peter,
OK
I moved the arm_load_kernel code into a machine init done notify and arm_load_kernel now only registers the notifier.
For machine files willing to support platform bus, the arm_load_kernel must happen before the registration of the notifier that adds platform bus nodes and after CPU init (notifiers are executed in registration reverse order).
Best Regards
Eric
Quoted 3 lines
-- PMM
PATCH v5 2/6 hw/arm/boot: dtb start and limit moved in arm_boot_info
In reply to Eric AugerTwo fields are added in arm_boot_info (dtb_start and dtb_limit). The prototype of arm_load_kernel is changed to only use arm_boot_info.
The rationale behind introducing that change is when dealing with dynamic sysbus devices, we need to upgrade the device tree with dynamic device nodes after the dtb is already loaded. Storing those parameters in arm_boot_info allows to avoid computing again dtb_start and dtb_load, as done in arm_load_kernel.
--- hw/arm/boot.c | 38 +++++++++++++++++++++----------------- include/hw/arm/arm.h | 5 +++-- 2 files changed, 24 insertions(+), 19 deletions(-)
hw/arm/boot.c +21 -17
@@ -314,24 +314,21 @@ static void set_kernel_args_old(const struct arm_boot_info *info)/** * 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 * * 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. +* '-dtb' command line option, and put it at offset binfo->dtb_start 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. +* If binfo->dtb_limit contains a meaningful value (i.e., it is strictly +* greater binfo->dtb_start, the device tree is only loaded if its size does +* not exceed this upper limit. * * Returns: the size of the device tree image on success, * 0 if the image size exceeds the limit, * -1 on errors. */ -int arm_load_dtb (hwaddr addr,const struct arm_boot_info *binfo, -hwaddr addr_limit) +int arm_load_dtb (const struct arm_boot_info *binfo) {void *fdt =NULL ;int size, rc;
@@ -360,7 +357,8 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo, } } -if (addr_limit > addr && size > (addr_limit - addr)) { +if (binfo->dtb_limit > binfo->dtb_start && + size > (binfo->dtb_limit - binfo->dtb_start)) {/* Installing the device tree blob at addr would exceed addr_limit. * Whether this constitutes failure is up to the caller to decide, * so just return 0 as size, i.e., no error.
@@ -427,7 +425,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,/* Put the DTB into the memory map as a ROM image: this will ensure * the DTB is copied again upon reset, even if addr points into RAM. */ -rom_add_blob_fixed ("dtb" , fdt, size, addr); +rom_add_blob_fixed ("dtb" , fdt, size, binfo->dtb_start);g_free (fdt);
@@ -504,7 +502,10 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info)/* If we have a device tree blob, but no kernel to supply it to, * copy it to the base of RAM for a bootloader to pick up. */ -if (arm_load_dtb (info->loader_start, info,0 ) <0 ) { + info->dtb_start = info->loader_start; + info->dtb_limit =0 ; + +if (arm_load_dtb (info) <0 ) {exit (1 ); } }
@@ -572,7 +573,9 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info)if (elf_low_addr < info->loader_start) { elf_low_addr =0 ; } -if (arm_load_dtb (info->loader_start, info, elf_low_addr) <0 ) { + info->dtb_start = info->loader_start; + info->dtb_limit = elf_low_addr; +if (arm_load_dtb (info) <0 ) {exit (1 ); } }
@@ -635,12 +638,13 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info)* kernels will trash anything in the 4K page the initrd * ends in, so make sure the DTB isn't caught up in that. */ -hwaddr dtb_start =QEMU_ALIGN_UP (info->initrd_start + initrd_size, -4096 ); -if (arm_load_dtb (dtb_start, info,0 ) <0 ) { + info->dtb_start =QEMU_ALIGN_UP (info->initrd_start + initrd_size, +4096 ); + info->dtb_limit =0 ; +if (arm_load_dtb (info) <0 ) {exit (1 ); } - fixupcontext[FIXUP_ARGPTR ] = dtb_start; + fixupcontext[FIXUP_ARGPTR ] = info->dtb_start; }else { fixupcontext[FIXUP_ARGPTR ] = info->loader_start +KERNEL_ARGS_ADDR ;if (info->ram_size >= (1ULL <<32 )) {
include/hw/arm/arm.h +3 -2
@@ -65,11 +65,12 @@ struct arm_boot_info {int is_linux;hwaddr initrd_start;hwaddr initrd_size; +hwaddr dtb_start;/* start address of the dtb */ +hwaddr dtb_limit;/* upper RAM limit the dtb cannot overshoot */ hwaddr entry; };void arm_load_kernel (ARMCPU *cpu,struct arm_boot_info *info); -int arm_load_dtb (hwaddr addr,const struct arm_boot_info *binfo, -hwaddr addr_limit); +int arm_load_dtb (const struct arm_boot_info *binfo);/* Multiplication factor to convert from system clock ticks to qemu timer ticks. */
Signature · 1 line
1.8.3.2
PATCH v5 3/6 hw/arm/boot: do not free VirtBoardInfo fdt in arm_load_dtb
In reply to Eric AugerCurrently arm_load_dtb frees the fdt handle whatever it is allocated from load_device_tree or allocated externally.
When adding dynamic sysbus nodes after the first dtb load, we would like to reuse the fdt used during the first load instead of re-creating the whole device tree. If the fdt is destroyed, this is not possible.
--- hw/arm/boot.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
hw/arm/boot.c +6 -2
@@ -427,12 +427,16 @@ int arm_load_dtb(const struct arm_boot_info *binfo)*/ rom_add_blob_fixed ("dtb" , fdt, size, binfo->dtb_start); -g_free (fdt); +if (binfo->dtb_filename) { +g_free (fdt); + }return size; fail: -g_free (fdt); +if (binfo->dtb_filename) { +g_free (fdt); + }return -1 ; }
Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [PATCH v5 3/6] hw/arm/boot: do not free VirtBoardInfo fdt in arm_load_dtb
Quoted 17 lines · Eric Auger
Currently
arm_load_dtbfrees the fdt handle whatever it is allocated fromload_device_treeor allocated externally.When adding dynamic sysbus nodes after the first dtb load, we would like to reuse the fdt used during the first load instead of re-creating the whole device tree. If the fdt is destroyed, this is not possible.
Signed-off-by Eric Auger <[email protected]>--- hw/arm/boot.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)hw/arm/boot.c +0
-0
hw/arm/boot.c int arm_load_dtb(const struct arm_boot_info *binfo) · line 432
Quoted 7 lines
hw/arm/boot.c +3
-1@@ -427,12 +427,16 @@ int arm_load_dtb(const struct arm_boot_info *binfo)*/ rom_add_blob_fixed ("dtb" , fdt, size, binfo->dtb_start); -g_free (fdt); +if (binfo->dtb_filename) { +g_free (fdt); + }
This doesn't look right to me -- as you can see in this hunk, we've already added the fdt as a ROM blob, so it's complete and won't change hereafter. So there's nothing further useful to do with the malloc'd memory and we should always free it regardless.
thanks
-- PMM
PATCH v5 4/6 hw/arm: add a new modify_dtb_opaque field in arm_boot_info
In reply to Eric AugerThis field can be used by any modify_dtb() function to pass additional arguments requested to build the modified dtb. This is needed for creating the platform bus dynamic sysbus nodes.
--- include/hw/arm/arm.h | 4 ++++ 1 file changed, 4 insertions(+)
include/hw/arm/arm.h +4 -0
@@ -68,6 +68,10 @@ struct arm_boot_info {hwaddr dtb_start;/* start address of the dtb */ hwaddr dtb_limit;/* upper RAM limit the dtb cannot overshoot */ hwaddr entry; +/* in case modify_dtb requires additional parameters to create the +* the new nodes, use following opaque +*/ +void *modify_dtb_opaque; };void arm_load_kernel (ARMCPU *cpu,struct arm_boot_info *info);int arm_load_dtb (const struct arm_boot_info *binfo);
Signature · 1 line
1.8.3.2
PATCH v5 5/6 hw/arm/sysbus-fdt: helpers for platform bus nodes addition
In reply to Eric AugerThis new C module will be used by ARM machine files to generate platform bus node and their dynamic sysbus device tree nodes.
Dynamic sysbus device node addition is done in a machine init done notifier. arm_register_platform_bus_fdt_creator does the registration of this latter and is supposed to be called by ARM machine files that support platform bus and their dynamic sysbus. Addition of dynamic sysbus nodes is done only if the user did not provide any dtb.
---
v4 -> v5:
- change indentation in add_fdt_node_functions. Also becomes a static const.
- ARMPlatformBusFdtParams.system_params becomes a pointer to a const ARMPlatformBusSystemParams
- removes platform-bus.h second inclusion
v3 -> v4:
- dyn_sysbus_devtree.c renamed into sysbus-fdt.c
- use new PlatformBusDevice object
- the dtb upgrade is done through modify_dtb. Before the fdt was recreated from scratch. When the user provided a dtb this latter was overwritten which was not correct.
- an array contains the association between device type names and their node creation function
- I must aknowledge I did not find any cleaner way to implement a FDT_BUILDER interface, as suggested by Paolo. The class method would need to be initialized somewhere and since it cannot happen in the device itself - according to Alex & Peter comments -, I don't see when I shall associate the device type and its interface implementation.
v2 -> v3:
- add arm_ prefix
- arm_sysbus_device_create_devtree becomes static
v1 -> v2:
- Code moved in an arch specific file to accomodate architecture dependent specificities.
- remove platform_bus_base from PlatformDevtreeData
v1: code originally written by Alex Graf in e500.c and reused for ARM [Eric Auger]
--- hw/arm/Makefile.objs | 1 + hw/arm/sysbus-fdt.c | 180 ++++++++++++++++++++++++++++++++++++++++++++ include/hw/arm/sysbus-fdt.h | 50 ++++++++++++ 3 files changed, 231 insertions(+) create mode 100644 hw/arm/sysbus-fdt.c create mode 100644 include/hw/arm/sysbus-fdt.h
hw/arm/Makefile.objs +1 -0
@@ -3,6 +3,7 @@ obj-$(CONFIG_DIGIC) += digic_boards.o obj-y += integratorcp.o kzm.o mainstone.o musicpal.o nseries.o obj-y += omap_sx1.o palm.o realview.o spitz.o stellaris.o obj-y += tosa.o versatilepb.o vexpress.o virt.o xilinx_zynq.o z2.o +obj-y += sysbus-fdt.o obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o obj-$(CONFIG_DIGIC) += digic.o
hw/arm/sysbus-fdt.c new file +180 -0
180 lines not on this page · raw message
include/hw/arm/sysbus-fdt.h new file +50 -0
50 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [PATCH v5 5/6] hw/arm/sysbus-fdt: helpers for platform bus nodes addition
Quoted 5 lines · Eric Auger
hw/arm/sysbus-fdt.c new file +2
-0@@ -0,0 +1,180 @@ +/* +* ARM Platform Bus device tree generation helpers
hw/arm/sysbus-fdt.c line 12
Quoted 10 lines
hw/arm/sysbus-fdt.c new file +10
-0+* +* Copyright (c) 2014 Linaro Limited +* +* Authors: +* Alex Graf <[email protected]> +* Eric Auger <[email protected]> +* +* 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.
but
Quoted 8 lines
include/hw/arm/sysbus-fdt.h new file +2
-0@@ -0,0 +1,50 @@ +/* +* Dynamic sysbus device tree node generation API
include/hw/arm/sysbus-fdt.h line 12
Quoted 10 lines
include/hw/arm/sysbus-fdt.h new file +10
-0+* +* Copyright Linaro Limited, 2014 +* +* Authors: +* Alex Graf <[email protected]> +* Eric Auger <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +*/
...shouldn't the .c file and the .h file be under the same license?
-- PMM
Re: [Qemu-devel] [PATCH v5 5/6] hw/arm/sysbus-fdt: helpers for platform bus nodes addition
Quoted 31 lines · Peter Maydell
Quoted 5 lines · Eric Auger
hw/arm/sysbus-fdt.c new file +2
-0@@ -0,0 +1,180 @@ +/* +* ARM Platform Bus device tree generation helpers hw/arm/sysbus-fdt.c line 12
Quoted 10 lines
hw/arm/sysbus-fdt.c new file +10
-0+* +* Copyright (c) 2014 Linaro Limited +* +* Authors: +* Alex Graf <[email protected]> +* Eric Auger <[email protected]> +* +* 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. but
Quoted 12 lines
include/hw/arm/sysbus-fdt.h new file +6
-0@@ -0,0 +1,50 @@ +/* +* Dynamic sysbus device tree node generation API +* +* Copyright Linaro Limited, 2014 +* +* Authors:
Quoted 8 lines
include/hw/arm/sysbus-fdt.h line 12
Quoted 6 lines
include/hw/arm/sysbus-fdt.h new file +6
-0+* Alex Graf <[email protected]> +* Eric Auger <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +*/ ...shouldn't the .c file and the .h file be under the same license?
OK copyrights are now aligned
Thanks
Eric
Quoted 3 lines
-- PMM
PATCH v5 6/6 hw/arm/virt: add dynamic sysbus device support
In reply to Eric AugerAllows sysbus devices to be instantiated from command line by using -device option. Machvirt creates a platform bus at init. The dynamic sysbus devices are attached to this platform bus device.
The platform bus device registers a machine init done notifier whose role will be to bind the dynamic sysbus devices. Indeed dynamic sysbus devices are created after machine init.
machvirt also registers a notifier that will build the device tree nodes for the platform bus and its children dynamic sysbus devices.
---
v4 -> v5:
- platform_bus_params becomes static const
- reword comment in create_platform_bus
- reword the commit message
v3 -> v4:
- use platform bus object, instantiated in create_platform_bus
- device tree generation for platform bus and children dynamic sysbus devices is no more handled at reset but in a machine_init_done_notifier (due to the change in implementaion of ARM load dtb using rom_add_blob_fixed).
- device tree enhancement now takes into account the case of user provided dtb. Before the user dtb was overwritten which was wrong. However in case the dtb is provided by the user, dynamic sysbus nodes are not added there.
- renaming of MACHVIRT_PLATFORM defines
- MACHVIRT_PLATFORM_PAGE_SHIFT and SIZE_PAGES not needed anymore, hence removed.
- DynSysbusParams struct renamed into ARMPlatformBusSystemParams and above params removed.
- separation of dt creation and QEMU binding is not mandated anymore since the device tree is not created from scratch anymore. Instead the modify_dtb function is used.
- create_platform_bus registers another machine init done notifier to start VFIO IRQ handling. This latter executes after the dynamic sysbus device binding.
v2 -> v3:
- renaming of arm_platform_bus_create_devtree and arm_load_dtb
- add copyright in hw/arm/dyn_sysbus_devtree.c
v1 -> v2:
- remove useless vfio-platform.h include file
- s/MACHVIRT_PLATFORM_HOLE/MACHVIRT_PLATFORM_SIZE
- use dyn_sysbus_binding and dyn_sysbus_devtree
- dynamic sysbus platform buse size shrinked to 4MB and moved between RTC and MMIO
v1:
Inspired from what Alex Graf did in ppc e500
https://lists.gnu.org/archive/html/qemu-ppc/2014-07/msg00012.html
Conflicts:
hw/arm/sysbus-fdt.c
--- hw/arm/virt.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
hw/arm/virt.c +57 -0
@@ -42,6 +42,8 @@#include "exec/address-spaces.h" #include "qemu/bitops.h" #include "qemu/error-report.h" +#include "hw/arm/sysbus-fdt.h" +#include "hw/platform-bus.h" #define NUM_VIRTIO_TRANSPORTS 32
@@ -59,6 +61,11 @@#define GIC_FDT_IRQ_PPI_CPU_START 8#define GIC_FDT_IRQ_PPI_CPU_WIDTH 8 +#define PLATFORM_BUS_BASE 0x9400000 +#define PLATFORM_BUS_SIZE (4ULL * 1024 * 1024) +#define PLATFORM_BUS_FIRST_IRQ 48 +#define PLATFORM_BUS_NUM_IRQS 20 +enum {VIRT_FLASH ,VIRT_MEM ,
@@ -68,6 +75,7 @@ enum {VIRT_UART ,VIRT_MMIO ,VIRT_RTC , + VIRT_PLATFORM_BUS, }; typedef struct MemMapEntry {
@@ -107,6 +115,7 @@ static const MemMapEntry a15memmap[] = { [VIRT_GIC_CPU] = { 0x08010000, 0x00010000 }, [VIRT_UART] = { 0x09000000, 0x00001000 }, [VIRT_RTC] = { 0x09010000, 0x00001000 }, + [VIRT_PLATFORM_BUS] = {PLATFORM_BUS_BASE , PLATFORM_BUS_SIZE}, [VIRT_MMIO] = { 0x0a000000, 0x00000200 },/* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */ /* 0x10000000 .. 0x40000000 reserved for PCI */
@@ -117,6 +126,14 @@ static const int a15irqmap[] = { [VIRT_UART] = 1, [VIRT_RTC] = 2, [VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */ + [VIRT_PLATFORM_BUS] = PLATFORM_BUS_FIRST_IRQ, +}; + +static const ARMPlatformBusSystemParams platform_bus_params = { + .platform_bus_base =PLATFORM_BUS_BASE , + .platform_bus_size =PLATFORM_BUS_SIZE , + .platform_bus_first_irq =PLATFORM_BUS_FIRST_IRQ , + .platform_bus_num_irqs =PLATFORM_BUS_NUM_IRQS , };static VirtBoardInfo machines[] = {
@@ -519,6 +536,43 @@ static void create_flash(const VirtBoardInfo *vbi)g_free (nodename); } +static void create_platform_bus (VirtBoardInfo *vbi,qemu_irq *pic, +const ARMPlatformBusSystemParams *system_params) +{ +DeviceState *dev; +SysBusDevice *s; +int i; +ARMPlatformBusFdtParams *fdt_params =g_new (ARMPlatformBusFdtParams,1 ); +MemoryRegion *sysmem =get_system_memory (); + + fdt_params->system_params = system_params; + fdt_params->binfo = &vbi->bootinfo; + fdt_params->intc ="/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 =qdev_create (NULL ,TYPE_PLATFORM_BUS_DEVICE ); + dev->id =TYPE_PLATFORM_BUS_DEVICE ; +qdev_prop_set_uint32 (dev,"num_irqs" , + system_params->platform_bus_num_irqs); +qdev_prop_set_uint32 (dev,"mmio_size" , + system_params->platform_bus_size); +qdev_init_nofail (dev); + s =SYS_BUS_DEVICE (dev); + +for (i =0 ; i < system_params->platform_bus_num_irqs; i++) { +int irqn = system_params->platform_bus_first_irq + i; +sysbus_connect_irq (s, i, pic[irqn]); + } + +memory_region_add_subregion (sysmem, + system_params->platform_bus_base, +sysbus_mmio_get_region (s,0 )); +} +static void *machvirt_dtb (const struct arm_boot_info *binfo,int *fdt_size) {const VirtBoardInfo *board = (const VirtBoardInfo *)binfo;
@@ -604,6 +658,8 @@ static void machvirt_init(MachineState *machine)*/ create_virtio_devices (vbi, pic); +create_platform_bus (vbi, pic, &platform_bus_params); + vbi->bootinfo.ram_size = machine->ram_size; vbi->bootinfo.kernel_filename = machine->kernel_filename; vbi->bootinfo.kernel_cmdline = machine->kernel_cmdline;
@@ -620,6 +676,7 @@ static QEMUMachine machvirt_a15_machine = { .desc = "ARM Virtual Machine", .init = machvirt_init, .max_cpus = 8, + .has_dynamic_sysbus = true, };static void machvirt_machine_init (void )
Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [PATCH v5 6/6] hw/arm/virt: add dynamic sysbus device support
Quoted 99 lines · Eric Auger
Allows sysbus devices to be instantiated from command line by using -device option. Machvirt creates a platform bus at init. The dynamic sysbus devices are attached to this platform bus device.
The platform bus device registers a machine init done notifier whose role will be to bind the dynamic sysbus devices. Indeed dynamic sysbus devices are created after machine init.
machvirt also registers a notifier that will build the device tree nodes for the platform bus and its children dynamic sysbus devices.
Signed-off-by Alexander Graf <[email protected]>Signed-off-by Eric Auger <[email protected]>---
v4 -> v5:
-platform_bus_paramsbecomes static const
- reword comment increate_platform_bus
- reword the commit messagev3 -> v4:
- use platform bus object, instantiated increate_platform_bus
- device tree generation for platform bus and children dynamic sysbus devices is no more handled at reset but in amachine_init_done_notifier(due to the change in implementaion of ARM load dtb usingrom_add_blob_fixed).
- device tree enhancement now takes into account the case of user provided dtb. Before the user dtb was overwritten which was wrong. However in case the dtb is provided by the user, dynamic sysbus nodes are not added there.
- renaming ofMACHVIRT_PLATFORMdefines
-MACHVIRT_PLATFORM_PAGE_SHIFTandSIZE_PAGESnot needed anymore, hence removed.
- DynSysbusParams struct renamed into ARMPlatformBusSystemParams and above params removed.
- separation of dt creation and QEMU binding is not mandated anymore since the device tree is not created from scratch anymore. Instead themodify_dtbfunction is used.
-create_platform_busregisters another machine init done notifier to start VFIO IRQ handling. This latter executes after the dynamic sysbus device binding.v2 -> v3:
- renaming ofarm_platform_bus_create_devtreeandarm_load_dtb
- add copyright inhw/arm/dyn_sysbus_devtree.cv1 -> v2:
- remove uselessvfio-platform.hinclude file
- s/MACHVIRT_PLATFORM_HOLE/MACHVIRT_PLATFORM_SIZE
- usedyn_sysbus_bindinganddyn_sysbus_devtree
- dynamic sysbus platform buse size shrinked to 4MB and moved between RTC and MMIOv1:
Inspired from what Alex Graf did in ppc e500
https://lists.gnu.org/archive/html/qemu-ppc/2014-07/msg00012.htmlConflicts:
hw/arm/sysbus-fdt.c--- hw/arm/virt.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)hw/arm/virt.c +8
-0@@ -42,6 +42,8 @@#include "exec/address-spaces.h" #include "qemu/bitops.h" #include "qemu/error-report.h" +#include "hw/arm/sysbus-fdt.h" +#include "hw/platform-bus.h" #define NUM_VIRTIO_TRANSPORTS 32@@ -59,6 +61,11 @@#define GIC_FDT_IRQ_PPI_CPU_START 8#define GIC_FDT_IRQ_PPI_CPU_WIDTH 8 +#define PLATFORM_BUS_BASE 0x9400000 +#define PLATFORM_BUS_SIZE (4ULL * 1024 * 1024) +#define PLATFORM_BUS_FIRST_IRQ 48 +#define PLATFORM_BUS_NUM_IRQS 20 +enum {VIRT_FLASH ,VIRT_MEM ,@@ -68,6 +75,7 @@ enum {VIRT_UART ,VIRT_MMIO ,VIRT_RTC , + VIRT_PLATFORM_BUS, }; typedef struct MemMapEntry {
hw/arm/virt.c static const MemMapEntry a15memmap[] = { · line 118
Quoted 4 lines
hw/arm/virt.c +1
-0@@ -107,6 +115,7 @@ static const MemMapEntry a15memmap[] = { [VIRT_GIC_CPU] = { 0x08010000, 0x00010000 }, [VIRT_UART] = { 0x09000000, 0x00001000 }, [VIRT_RTC] = { 0x09010000, 0x00001000 }, + [VIRT_PLATFORM_BUS] = {PLATFORM_BUS_BASE , PLATFORM_BUS_SIZE},
This makes it pretty hard to read this -- you should use the raw 0x numbers here. Anywhere else that wants to know the base address etc should fish it out of the memory map at runtime, as we do with the other devices.
hw/arm/virt.c static const int a15irqmap[] = { · line 129
Quoted 8 lines
hw/arm/virt.c +1
-0[VIRT_MMIO] = { 0x0a000000, 0x00000200 },/* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */ /* 0x10000000 .. 0x40000000 reserved for PCI */ @@ -117,6 +126,14 @@ static const int a15irqmap[] = { [VIRT_UART] = 1, [VIRT_RTC] = 2, [VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */ + [VIRT_PLATFORM_BUS] = PLATFORM_BUS_FIRST_IRQ,
Similarly with interrupt numbers.
-- PMM
Re: [Qemu-devel] [PATCH v5 6/6] hw/arm/virt: add dynamic sysbus device support
Quoted 98 lines · Peter Maydell
Quoted 97 lines · Eric Auger
Allows sysbus devices to be instantiated from command line by using -device option. Machvirt creates a platform bus at init. The dynamic sysbus devices are attached to this platform bus device.
The platform bus device registers a machine init done notifier whose role will be to bind the dynamic sysbus devices. Indeed dynamic sysbus devices are created after machine init.
machvirt also registers a notifier that will build the device tree nodes for the platform bus and its children dynamic sysbus devices.
Signed-off-by Alexander Graf <[email protected]>Signed-off-by Eric Auger <[email protected]>---
v4 -> v5:
-platform_bus_paramsbecomes static const
- reword comment increate_platform_bus
- reword the commit messagev3 -> v4:
- use platform bus object, instantiated increate_platform_bus
- device tree generation for platform bus and children dynamic sysbus devices is no more handled at reset but in amachine_init_done_notifier(due to the change in implementaion of ARM load dtb usingrom_add_blob_fixed).
- device tree enhancement now takes into account the case of user provided dtb. Before the user dtb was overwritten which was wrong. However in case the dtb is provided by the user, dynamic sysbus nodes are not added there.
- renaming ofMACHVIRT_PLATFORMdefines
-MACHVIRT_PLATFORM_PAGE_SHIFTandSIZE_PAGESnot needed anymore, hence removed.
- DynSysbusParams struct renamed into ARMPlatformBusSystemParams and above params removed.
- separation of dt creation and QEMU binding is not mandated anymore since the device tree is not created from scratch anymore. Instead themodify_dtbfunction is used.
-create_platform_busregisters another machine init done notifier to start VFIO IRQ handling. This latter executes after the dynamic sysbus device binding.v2 -> v3:
- renaming ofarm_platform_bus_create_devtreeandarm_load_dtb
- add copyright inhw/arm/dyn_sysbus_devtree.cv1 -> v2:
- remove uselessvfio-platform.hinclude file
- s/MACHVIRT_PLATFORM_HOLE/MACHVIRT_PLATFORM_SIZE
- usedyn_sysbus_bindinganddyn_sysbus_devtree
- dynamic sysbus platform buse size shrinked to 4MB and moved between RTC and MMIOv1:
Inspired from what Alex Graf did in ppc e500
https://lists.gnu.org/archive/html/qemu-ppc/2014-07/msg00012.htmlConflicts:
hw/arm/sysbus-fdt.c--- hw/arm/virt.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)hw/arm/virt.c +8
-0@@ -42,6 +42,8 @@#include "exec/address-spaces.h" #include "qemu/bitops.h" #include "qemu/error-report.h" +#include "hw/arm/sysbus-fdt.h" +#include "hw/platform-bus.h" #define NUM_VIRTIO_TRANSPORTS 32@@ -59,6 +61,11 @@#define GIC_FDT_IRQ_PPI_CPU_START 8#define GIC_FDT_IRQ_PPI_CPU_WIDTH 8 +#define PLATFORM_BUS_BASE 0x9400000 +#define PLATFORM_BUS_SIZE (4ULL * 1024 * 1024) +#define PLATFORM_BUS_FIRST_IRQ 48 +#define PLATFORM_BUS_NUM_IRQS 20 +enum {VIRT_FLASH ,VIRT_MEM ,@@ -68,6 +75,7 @@ enum {VIRT_UART ,VIRT_MMIO ,VIRT_RTC , + VIRT_PLATFORM_BUS, };
Quoted 11 lines
hw/arm/virt.c static const MemMapEntry a15memmap[] = { · line 118
Quoted 6 lines
hw/arm/virt.c +1
-0typedef struct MemMapEntry {@@ -107,6 +115,7 @@ static const MemMapEntry a15memmap[] = { [VIRT_GIC_CPU] = { 0x08010000, 0x00010000 }, [VIRT_UART] = { 0x09000000, 0x00001000 }, [VIRT_RTC] = { 0x09010000, 0x00001000 }, + [VIRT_PLATFORM_BUS] = {PLATFORM_BUS_BASE , PLATFORM_BUS_SIZE},This makes it pretty hard to read this -- you should use the raw 0x numbers here. Anywhere else that wants to know the base address etc should fish it out of the memory map at runtime, as we do with the other devices.
Hi Peter
ok. As a side effect platform_bus_params will not be a const anymore, previously recommended by Alex.
Quoted 11 lines
hw/arm/virt.c static const int a15irqmap[] = { · line 129
Quoted 9 lines
hw/arm/virt.c +1
-0[VIRT_MMIO] = { 0x0a000000, 0x00000200 },/* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */ /* 0x10000000 .. 0x40000000 reserved for PCI */ @@ -117,6 +126,14 @@ static const int a15irqmap[] = { [VIRT_UART] = 1, [VIRT_RTC] = 2, [VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */ + [VIRT_PLATFORM_BUS] = PLATFORM_BUS_FIRST_IRQ,Similarly with interrupt numbers.
ok
Thanks
Eric
Quoted 3 lines
-- PMM