machvirt dynamic sysbus device instantiation
v10 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_v9
Previous version on official_dynsysbus_v9
Best Regards
Eric
v9 -> v10:
- add assert and fix return value in add_fdt_node
v8 -> v9:
Take into account Peter's comments:
hw/arm/sysbus-fdt:
- s/Fdt/FDT in struct type names
- reorder fields in PlatformBusFdtNotifierParams and use DO_UPCAST
- use assert() when relevant (board model issue)
- g_free the ARMPlatformBusFDTParams and PlatformBusFDTNotifierParams pointers in platform_bus_fdt_notifyhw/arm/boot.c
- fix compilation with arm-linux-user
- reorder fields in ArmLoadKernelNotifierhw/arm/virt.c
- PLATFORM_BUS_NUM_IRQS set to 32 instead of 20
- platform bus irq now start at 64 instead of 48
- remove change of indentation in a15memmap
- correct misc style issues
add a separate patch file for re-indentation invirt a15memmap
v7 -> v8:
- rebase on 2.2.0 (boot.c and virt.c)
- in virt.c machvirt_init, create_platform_bus simply is added after the arm_load_kernel call instead of moving this latter. should ease the review.
- Add Alex & Shannon Reviewed-by
v6 -> v7:
Take into account Shannon's comments:
- hw/arm/sysbus-fdt.c: revert indentation in add_fdt_node_functions
- hw/arm/virt.c:
- add an additional comment in a15irqmap related to PLATFORM_BUS_NUM_IRQS
- correct platform bus size to 0x400000
- remove PLATFORM_BUS_FIRST_IRQ macro
v5 -> v6:
Take into account Peter's comments:
- dtb overload mechanism rewritten: arm_load_kernel code is moved into a machine init done notifier notify instead. arm_load_kernel only registers that notifier. As a consequence the dtb is loaded once.
- v5 1-4 patch files are removed and replaced by a single patch file moving arm_load_kernel in the notifier (2).
- as a consequence arm_load_kernel must be called before sysbus-fdt arm_register_platform_bus_fdt_creator.
- In virt, platform_bus_params not a const anymore since its fields are initialized from vbi->memmap and vbi->irqmap. Hence create_platform_bus proto can be simplified.
- In sysbus-fdt add_all_platform_bus_fdt_nodes now takes a handle to an ARMPlatformBusFdtParams. This is not a modify_dtb function anymore fdt pointer is checked in case the callback is called after the load_dtb (this latter deallocated fdt pointer). Check of fdt_filename moved in here. upgrade_dtb is removed. copyright aligned between .h and .c.
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 dynamically 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
v1 -> v2:
- device node generation no more in sysbus device but in dyn_sysbus_devtree
- VFIO region shrinked to 4MB and relocated in machvirt to avoid PCI shrink (dynamic vfio-mmio support might come latter)
- platform_bus_base removed from PlatformDevtreeData
Eric Auger (4):
hw/arm/sysbus-fdt: helpers for platform bus nodes addition hw/arm/boot: arm_load_kernel implemented as a machine init done
notifier
hw/arm/virt: add dynamic sysbus device support hw/arm/virt: change indentation in a15memmap
hw/arm/Makefile.objs | 1 + hw/arm/boot.c | 14 +++- hw/arm/sysbus-fdt.c | 174 ++++++++++++++++++++++++++++++++++++++++++++ hw/arm/virt.c | 77 +++++++++++++++++--- include/hw/arm/arm.h | 28 +++++++ include/hw/arm/sysbus-fdt.h | 60 +++++++++++++++ 6 files changed, 344 insertions(+), 10 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 v10 1/4 hw/arm/sysbus-fdt: helpers for platform bus nodes addition
This 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.
---
v9 -> v10:
- add assert and exit in add_fdt_node
v8 -> v9:
- s/Fdt/FDT in struct type names
- reorder fields in PlatformBusFdtNotifierParams and use DO_UPCAST instead of container_of
- use assert() when relevant (board model issue)
- g_free the ARMPlatformBusFDTParams and PlatformBusFDTNotifierParams pointers in platform_bus_fdt_notify
v7 -> v8:
add Reviewed-by from Alex and Shannon
v6 -> v7:
- revert indentation in add_fdt_node_functions
v5 -> v6:
- add_all_platform_bus_fdt_nodes is not a modify_dtb function anymore
- it now takes a handle to an ARMPlatformBusFdtParams.
- fdt pointer is checked in case this notifier is executed after the one that executes the load_dtb (this latter deallocates the fdt pointer)
- check of fdt_filename moved in here.
- upgrade_dtb is removed
- copyright aligned between .h and .c
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 | 174 ++++++++++++++++++++++++++++++++++++++++++++ include/hw/arm/sysbus-fdt.h | 60 +++++++++++++++ 3 files changed, 235 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 +174 -0
174 lines not on this page · raw message
include/hw/arm/sysbus-fdt.h new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH v10 2/4 hw/arm/boot: arm_load_kernel implemented as a machine init done notifier
In reply to Eric AugerDevice tree nodes for the platform bus and its children dynamic sysbus devices are added in a machine init done notifier. To load the dtb once, after those latter nodes are built and before ROM freeze, the actual arm_load_kernel existing code is moved into a notifier notify function, arm_load_kernel_notify. arm_load_kernel now only registers the corresponding notifier.
Machine files that do not support platform bus stay unchanged. Machine files willing to support dynamic sysbus devices must call arm_load_kernel before sysbus-fdt arm_register_platform_bus_fdt_creator to make sure dynamic sysbus device nodes are integrated in the dtb.
---
v8 -> v9:
- fix compilation with arm-linux-user
- reorder fields in ArmLoadKernelNotifier and use DO_UPCAST
v7 -> v8:
- Add Reviewed-by from Alex & Shannon
- rebase on 2.2.0
v6: creation of this patch file
--- hw/arm/boot.c | 14 +++++++++++++- include/hw/arm/arm.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-)
hw/arm/boot.c +13 -1
@@ -537,7 +537,7 @@ static void load_image_to_fw_cfg(FWCfgState *fw_cfg, uint16_t size_key,fw_cfg_add_bytes (fw_cfg, data_key, data, size); } -void arm_load_kernel (ARMCPU *cpu,struct arm_boot_info *info) +static void arm_load_kernel_notify (Notifier *notifier,void *data) {CPUState *cs;int kernel_size;
@@ -548,6 +548,11 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info)hwaddr entry, kernel_load_offset;int big_endian;static const ARMInsnFixup *primary_loader; +ArmLoadKernelNotifier *n =DO_UPCAST (ArmLoadKernelNotifier, + notifier, notifier); +ARMCPU *cpu = n->cpu; +struct arm_boot_info *info = + container_of(n, struct arm_boot_info, load_kernel_notifier);/* CPU objects (unlike devices) are not automatically reset on system * reset, so we must always register a handler to do so. If we're
@@ -755,3 +760,10 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info)ARM_CPU (cs)->env.boot_info = info; } } + +void arm_load_kernel (ARMCPU *cpu,struct arm_boot_info *info) +{ + info->load_kernel_notifier.cpu = cpu; + info->load_kernel_notifier.notifier.notify = arm_load_kernel_notify; +qemu_add_machine_init_done_notifier (&info->load_kernel_notifier.notifier); +}
include/hw/arm/arm.h +28 -0
@@ -13,12 +13,22 @@#include "exec/memory.h" #include "hw/irq.h" +#include "qemu/notify.h" /* armv7m.c */ qemu_irq *armv7m_init (MemoryRegion *system_memory,int flash_size,int sram_size,const char *kernel_filename,const char *cpu_model); +/* +* 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;
@@ -65,6 +75,8 @@ struct arm_boot_info {* the user it should implement this hook. */ 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;
@@ -76,6 +88,22 @@ struct arm_boot_info {*/ bool firmware_loaded; }; + +/** +* arm_load_kernel - Loads memory with everything needed to boot +* +* @cpu: handle to the first CPU object +* @info: handle to the boot info struct +* Registers a machine init done notifier that copies to memory +* everything needed to boot, depending on machine and user options: +* kernel image, boot loaders, initrd, dtb. Also registers the CPU +* reset handler. +* +* In case the machine file supports the platform bus device and its +* dynamically instantiable sysbus devices, this function must be called +* before sysbus-fdt arm_register_platform_bus_fdt_creator. Indeed the +* machine init done notifiers are called in registration reverse order. +*/ void arm_load_kernel (ARMCPU *cpu,struct arm_boot_info *info);/* Multiplication factor to convert from system clock ticks to qemu timer
Signature · 1 line
1.8.3.2
PATCH v10 3/4 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.
---
v8 -> v9:
- PLATFORM_BUS_NUM_IRQS set to 32 instead of 20
- platform bus irq now start at 64 instead of 48
- remove change of indentation in a15memmap
- correct misc style issues
v7 -> v8:
- rebase on 2.2.0
- in machvirt_init, create_platform_bus simply is added after the arm_load_kernel call instead of moving this latter. Related comment slighly reworded.
- Due to those changes I dropped Alex and Shannon's Reviewed-by
v6 -> v7:
Take into account Shannon comments:
- remove PLATFORM_BUS_FIRST_IRQ macro
- correct platform bus size to 0x400000
- add an additional comment in a15irqmap related to PLATFORM_BUS_NUM_IRQS
v5 -> v6:
- Take into account Peter's comments:
- platform_bus_params initialized from vbi->memmap and vbi->irqmap. As a consequence, const is removed. Also alignment in a15memmap is slightly changed.
- ARMPlatformBusSystemParams handle removed from create_platform_bus prototype
- arm_load_kernel has become a machine init done notifier registration. It must be called before platform_bus_create to guarantee the correct notifier execution sequence
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
Conflicts:
hw/arm/virt.c
--- hw/arm/virt.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+)
hw/arm/virt.c +59 -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,8 @@#define GIC_FDT_IRQ_PPI_CPU_START 8#define GIC_FDT_IRQ_PPI_CPU_WIDTH 8 +#define PLATFORM_BUS_NUM_IRQS 32 +enum {VIRT_FLASH ,VIRT_MEM ,
@@ -69,8 +73,11 @@ enum {VIRT_MMIO ,VIRT_RTC ,VIRT_FW_CFG , + VIRT_PLATFORM_BUS, }; +static ARMPlatformBusSystemParams platform_bus_params; + typedef struct MemMapEntry { hwaddr base; hwaddr size;
@@ -127,6 +134,7 @@ static const MemMapEntry a15memmap[] = { [VIRT_UART] = { 0x09000000, 0x00001000 }, [VIRT_RTC] = { 0x09010000, 0x00001000 }, [VIRT_FW_CFG] = { 0x09020000, 0x0000000a }, + [VIRT_PLATFORM_BUS] = { 0x09400000, 0x00400000 }, [VIRT_MMIO] = { 0x0a000000, 0x00000200 },/* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */ /* 0x10000000 .. 0x40000000 reserved for PCI */
@@ -137,6 +145,7 @@ static const int a15irqmap[] = { [VIRT_UART] = 1, [VIRT_RTC] = 2, [VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */ + [VIRT_PLATFORM_BUS] = 64, /* ... to 64 + PLATFORM_BUS_NUM_IRQS -1 */ };static VirtBoardInfo machines[] = {
@@ -556,6 +565,47 @@ static void create_fw_cfg(const VirtBoardInfo *vbi)g_free (nodename); } +static void create_platform_bus (VirtBoardInfo *vbi,qemu_irq *pic) +{ +DeviceState *dev; +SysBusDevice *s; +int i; +ARMPlatformBusFDTParams *fdt_params =g_new (ARMPlatformBusFDTParams,1 ); +MemoryRegion *sysmem =get_system_memory (); + + platform_bus_params.platform_bus_base = vbi->memmap[VIRT_PLATFORM_BUS ].base; + platform_bus_params.platform_bus_size = vbi->memmap[VIRT_PLATFORM_BUS ].size; + platform_bus_params.platform_bus_first_irq = vbi->irqmap[VIRT_PLATFORM_BUS ]; + platform_bus_params.platform_bus_num_irqs =PLATFORM_BUS_NUM_IRQS ; + + fdt_params->system_params = &platform_bus_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" , + platform_bus_params.platform_bus_num_irqs); +qdev_prop_set_uint32 (dev,"mmio_size" , + platform_bus_params.platform_bus_size); +qdev_init_nofail (dev); + s =SYS_BUS_DEVICE (dev); + +for (i =0 ; i < platform_bus_params.platform_bus_num_irqs; i++) { +int irqn = platform_bus_params.platform_bus_first_irq + i; +sysbus_connect_irq (s, i, pic[irqn]); + } + +memory_region_add_subregion (sysmem, + platform_bus_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;
@@ -658,6 +708,14 @@ static void machvirt_init(MachineState *machine) vbi->bootinfo.get_dtb = machvirt_dtb; vbi->bootinfo.firmware_loaded = bios_name ||drive_get (IF_PFLASH ,0 ,0 );arm_load_kernel (ARM_CPU (first_cpu), &vbi->bootinfo); + +/* +* 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 (vbi, pic); }static bool virt_get_secure (Object *obj,Error **errp)
@@ -696,6 +754,7 @@ static void virt_class_init(ObjectClass *oc, void *data) mc->desc ="ARM Virtual Machine" , mc->init = machvirt_init; mc->max_cpus =8 ; + mc->has_dynamic_sysbus = true; }static const TypeInfo machvirt_info = {
Signature · 1 line
1.8.3.2
PATCH v10 4/4 hw/arm/virt: change indentation in a15memmap
In reply to Eric AugerRe-indent in a15memmap after VIRT_PLATFORM_BUS introduction
--- hw/arm/virt.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
hw/arm/virt.c +9 -9
@@ -126,19 +126,19 @@ typedef struct {*/ static const MemMapEntry a15memmap[] = {/* Space up to 0x8000000 is reserved for a boot ROM */ - [VIRT_FLASH ] = {0 ,0x08000000 }, - [VIRT_CPUPERIPHS ] = {0x08000000 ,0x00020000 }, + [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 }, - [VIRT_UART ] = {0x09000000 ,0x00001000 }, - [VIRT_RTC ] = {0x09010000 ,0x00001000 }, - [VIRT_FW_CFG ] = {0x09020000 ,0x0000000a }, + [VIRT_GIC_DIST ] = {0x08000000 ,0x00010000 }, + [VIRT_GIC_CPU ] = {0x08010000 ,0x00010000 }, + [VIRT_UART ] = {0x09000000 ,0x00001000 }, + [VIRT_RTC ] = {0x09010000 ,0x00001000 }, + [VIRT_FW_CFG ] = {0x09020000 ,0x0000000a }, [VIRT_PLATFORM_BUS ] = {0x09400000 ,0x00400000 }, - [VIRT_MMIO ] = {0x0a000000 ,0x00000200 }, + [VIRT_MMIO ] = {0x0a000000 ,0x00000200 },/* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */ /* 0x10000000 .. 0x40000000 reserved for PCI */ - [VIRT_MEM ] = {0x40000000 ,30ULL *1024 *1024 *1024 }, + [VIRT_MEM ] = {0x40000000 ,30ULL *1024 *1024 *1024 }, };static const int a15irqmap[] = {
Signature · 1 line
1.8.3.2