Dynamic sysbus device allocation support
v2 cover Dynamic sysbus device allocation support
Platforms without ISA and/or PCI have had a seriously hard time in the dynamic device creation world of QEMU. Devices on these were modeled as SysBus devices which can only be instantiated in machine files, not through -device.
Why is that so?
For Sysbus devices we didn't know who should be responsible for mapping them when the machine file didn't do it. Turns out, the machine file is the perfect place to map them even when it doesn't create them :).
This patch set enables machine files to declare sysbus device creation via the -device command line option as possible. With this we can (in the machine file) map sysbus devices to whatever the machine thinks is fitting.
Some times users do want to specify manually where to map a device. This is very useful when you want to have stable offsets in memory and irq space. This patch set adds support for "user mapping hints" that the machine can use to map a device at a certain location.
As example this patch set only enables the eTSEC device on the e500plat machine type. This device was not possible to get added to the machine at all.
$ qemu-system-ppc -nographic -M ppce500 -device eTSEC,netdev=nd \
-netdev user,id=ndThe idea can easily be extended to any sysbus device on any machine type though.
This patch set is based on previous ideas and discussions, most notably:
https://lists.gnu.org/archive/html/qemu-devel/2013-07/msg03614.html
https://lists.gnu.org/archive/html/qemu-devel/2014-06/msg00849.html
v1 -> v2:
- new patch: qom: Move property helpers to own file
- reworked patch: qom: Expose property helpers for get/set of integers
- new patch: qom: Add generic object property g_free helper
- new patch: PPC: Fix default config ordering and add eTSEC for ppc64
- Rename DECLARE_INTEGER_VISITOR to DECLARE_PROP_SET_GET
- Make macro take name and type arguments, enabling generation of "bool" types later
- make irq and pio properties uint64
- ensure qom exposed pointers don't change due to realloc
- fix sysbus_pass_irq
- make properties write-once, not write-before-realize
- make props only available via qom, no state pointers left
- use bool in MachineClass rather than property
- access sysbus properties via qom
- move platform bus definitions to params
- move platform bus to 36bit address space
- make naming more consistent
- remove device_type from platform bus dt node
- remove id field in dt generation
- fix device name (base on reg for value after @)
- use qom properties to fetch mmio and irq props
- remove useless interrupt-parent
- make interrupts level triggered
Alexander Graf (9):
qom: Move property helpers to own file
qom: macroify integer property helpers
qom: Expose property helpers for get/set of integers
qom: Add generic object property g_free helper
sysbus: Add user map hints
sysbus: Make devices spawnable via -device
PPC: e500: Support dynamically spawned sysbus devices
e500: Add support for eTSEC in device tree
PPC: Fix default config ordering and add eTSEC for ppc64
backends/hostmem-file.c | 1 + backends/hostmem.c | 1 + backends/rng-egd.c | 1 + backends/rng-random.c | 1 + backends/rng.c | 1 + backends/tpm.c | 1 + default-configs/ppc-softmmu.mak | 4 +- default-configs/ppc64-softmmu.mak | 3 +- hw/acpi/ich9.c | 1 + hw/acpi/pcihp.c | 1 + hw/acpi/piix4.c | 1 + hw/core/machine.c | 44 ++++++ hw/core/qdev.c | 1 + hw/core/sysbus.c | 50 +++++-- hw/i386/acpi-build.c | 1 + hw/isa/lpc_ich9.c | 1 + hw/ppc/e500.c | 288 ++++++++++++++++++++++++++++++++++++++ hw/ppc/e500.h | 5 + hw/ppc/e500plat.c | 6 + hw/ppc/spapr.c | 1 + include/hw/boards.h | 8 +- include/hw/sysbus.h | 1 + include/qom/object.h | 85 ----------- include/qom/property.h | 244 ++++++++++++++++++++++++++++++++ memory.c | 1 + qom/Makefile.objs | 2 +- qom/object.c | 206 +-------------------------- qom/property.c | 179 +++++++++++++++++++++++ target-i386/cpu.c | 1 + ui/console.c | 1 + vl.c | 1 + 31 files changed, 842 insertions(+), 300 deletions(-) create mode 100644 include/qom/property.h create mode 100644 qom/property.c
Signature · 1 line
1.8.1.4
PATCH v2 1/9 qom: Move property helpers to own file
We have accumulated a number of friendly helpers that make registration of properties easier. However, their number is only increasing and they start to clutter the core object.c file.
So let's move them into a separate C file and thus ensure that we have room to grow :).
--- backends/hostmem-file.c | 1 + backends/hostmem.c | 1 + backends/rng-egd.c | 1 + backends/rng-random.c | 1 + backends/rng.c | 1 + backends/tpm.c | 1 + hw/acpi/ich9.c | 1 + hw/acpi/pcihp.c | 1 + hw/acpi/piix4.c | 1 + hw/core/machine.c | 1 + hw/core/qdev.c | 1 + hw/i386/acpi-build.c | 1 + hw/isa/lpc_ich9.c | 1 + hw/ppc/spapr.c | 1 + include/qom/object.h | 85 ------------------- include/qom/property.h | 104 ++++++++++++++++++++++++ memory.c | 1 + qom/Makefile.objs | 2 +- qom/object.c | 197 ++------------------------------------------ qom/property.c | 212 ++++++++++++++++++++++++++++++++++++++++++++++++ target-i386/cpu.c | 1 + ui/console.c | 1 + 22 files changed, 340 insertions(+), 277 deletions(-) create mode 100644 include/qom/property.h create mode 100644 qom/property.c
backends/hostmem-file.c +1 -0
@@ -13,6 +13,7 @@#include "sysemu/hostmem.h" #include "sysemu/sysemu.h" #include "qom/object_interfaces.h" +#include "qom/property.h" /* hostmem-file.c */ /**
backends/hostmem.c +1 -0
@@ -16,6 +16,7 @@#include "qapi/qmp/qerror.h" #include "qemu/config-file.h" #include "qom/object_interfaces.h" +#include "qom/property.h" #ifdef CONFIG_NUMA #include <numaif.h>
backends/rng-egd.c +1 -0
@@ -14,6 +14,7 @@#include "sysemu/char.h" #include "qapi/qmp/qerror.h" #include "hw/qdev.h" /* just for DEFINE_PROP_CHR */ +#include "qom/property.h" #define TYPE_RNG_EGD "rng-egd"#define RNG_EGD (obj) OBJECT_CHECK(RngEgd, (obj), TYPE_RNG_EGD)
backends/rng-random.c +1 -0
@@ -14,6 +14,7 @@#include "sysemu/rng.h" #include "qapi/qmp/qerror.h" #include "qemu/main-loop.h" +#include "qom/property.h" struct RndRandom {
backends/rng.c +1 -0
@@ -13,6 +13,7 @@#include "sysemu/rng.h" #include "qapi/qmp/qerror.h" #include "qom/object_interfaces.h" +#include "qom/property.h" void rng_backend_request_entropy(RngBackend *s, size_t size, EntropyReceiveFunc *receive_entropy,
backends/tpm.c +1 -0
@@ -17,6 +17,7 @@#include "sysemu/tpm.h" #include "qemu/thread.h" #include "sysemu/tpm_backend_int.h" +#include "qom/property.h" enum TpmType tpm_backend_get_type (TPMBackend *s) {
hw/acpi/ich9.c +1 -0
@@ -32,6 +32,7 @@#include "hw/acpi/acpi.h" #include "sysemu/kvm.h" #include "exec/address-spaces.h" +#include "qom/property.h" #include "hw/i386/ich9.h" #include "hw/mem/pc-dimm.h"
hw/acpi/pcihp.c +1 -0
@@ -36,6 +36,7 @@#include "exec/address-spaces.h" #include "hw/pci/pci_bus.h" #include "qom/qom-qobject.h" +#include "qom/property.h" #include "qapi/qmp/qint.h" //#define DEBUG
hw/acpi/piix4.c +1 -0
@@ -36,6 +36,7 @@#include "hw/mem/pc-dimm.h" #include "hw/acpi/memory_hotplug.h" #include "hw/acpi/acpi_dev_interface.h" +#include "qom/property.h" //#define DEBUG
hw/core/machine.c +1 -0
@@ -12,6 +12,7 @@#include "hw/boards.h" #include "qapi/visitor.h" +#include "qom/property.h" static char *machine_get_accel (Object *obj,Error **errp) {
hw/core/qdev.c +1 -0
@@ -35,6 +35,7 @@#include "hw/hotplug.h" #include "hw/boards.h" #include "qapi-event.h" +#include "qom/property.h" int qdev_hotplug =0 ;static bool qdev_hot_added = false;
hw/i386/acpi-build.c +1 -0
@@ -51,6 +51,7 @@#include "qapi/qmp/qint.h" #include "qom/qom-qobject.h" +#include "qom/property.h" typedef struct AcpiCpuInfo { DECLARE_BITMAP(found_cpus, ACPI_CPU_HOTPLUG_ID_LIMIT);
hw/isa/lpc_ich9.c +1 -0
@@ -45,6 +45,7 @@#include "hw/pci/pci_bus.h" #include "exec/address-spaces.h" #include "sysemu/sysemu.h" +#include "qom/property.h" static int ich9_lpc_sci_irq (ICH9LPCState *lpc);
hw/ppc/spapr.c +1 -0
@@ -35,6 +35,7 @@#include "kvm_ppc.h" #include "mmu-hash64.h" #include "qom/cpu.h" +#include "qom/property.h" #include "hw/boards.h" #include "hw/ppc/ppc.h"
include/qom/object.h +0 -85
91 lines not on this page · raw message
include/qom/property.h new file +104 -0
104 lines not on this page · raw message
memory.c +1 -0
@@ -19,6 +19,7 @@#include "qapi/visitor.h" #include "qemu/bitops.h" #include "qom/object.h" +#include "qom/property.h" #include "trace.h" #include <assert.h>
qom/Makefile.objs +1 -1
@@ -1,3 +1,3 @@ -common-obj-y = object.o container.o qom-qobject.o +common-obj-y = object.o container.o qom-qobject.o property.o common-obj-y += cpu.o common-obj-y += object_interfaces.o
qom/object.c +6 -191
215 lines not on this page · raw message
qom/property.c new file +212 -0
212 lines not on this page · raw message
target-i386/cpu.c +1 -0
@@ -43,6 +43,7 @@#include "sysemu/sysemu.h" #include "hw/qdev-properties.h" +#include "qom/property.h" #include "hw/cpu/icc_bus.h" #ifndef CONFIG_USER_ONLY #include "hw/xen/xen.h"
ui/console.c +1 -0
@@ -28,6 +28,7 @@#include "qmp-commands.h" #include "sysemu/char.h" #include "trace.h" +#include "qom/property.h" #define DEFAULT_BACKSCROLL 512#define CONSOLE_CURSOR_PERIOD 500
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH v2 1/9] qom: Move property helpers to own file
Quoted 45 lines · Alexander Graf
We have accumulated a number of friendly helpers that make registration of properties easier. However, their number is only increasing and they start to clutter the core
object.cfile.So let's move them into a separate C file and thus ensure that we have room to grow :).
Signed-off-by Alexander Graf <[email protected]>--- backends/hostmem-file.c | 1 + backends/hostmem.c | 1 + backends/rng-egd.c | 1 + backends/rng-random.c | 1 + backends/rng.c | 1 + backends/tpm.c | 1 + hw/acpi/ich9.c | 1 + hw/acpi/pcihp.c | 1 + hw/acpi/piix4.c | 1 + hw/core/machine.c | 1 + hw/core/qdev.c | 1 + hw/i386/acpi-build.c | 1 + hw/isa/lpc_ich9.c | 1 + hw/ppc/spapr.c | 1 + include/qom/object.h | 85 ------------------- include/qom/property.h | 104 ++++++++++++++++++++++++ memory.c | 1 + qom/Makefile.objs | 2 +- qom/object.c | 197 ++------------------------------------------ qom/property.c | 212 ++++++++++++++++++++++++++++++++++++++++++++++++ target-i386/cpu.c | 1 + ui/console.c | 1 + 22 files changed, 340 insertions(+), 277 deletions(-) create mode 100644 include/qom/property.h create mode 100644 qom/property.c- *
object_property_add_uint64_ptr:
- * @obj: the object to add a property to
- * @name: the name of the property
- * @v: pointer to value
- * @errp: if an error occurs, a pointer to an area to store the error
- *
- * Add an integer property in memory. This function will add a
- * property of type 'uint64'.
- */
include/qom/object.h void object_property_add_link(Object *obj, const char *name, · line 1173
Quoted 5 lines
include/qom/object.h +0
-4-void object_property_add_uint64_ptr (Object *obj,const char *name, -const uint64_t *v,Error **Errp); - -/** * object_property_add_alias:
Any reason to not migrate alias and link props as well?
Regards,
Peter
Re: [Qemu-devel] [PATCH v2 1/9] qom: Move property helpers to own file
Quoted 36 lines · Peter Crosthwaite
Quoted 35 lines · Alexander Graf
We have accumulated a number of friendly helpers that make registration of properties easier. However, their number is only increasing and they start to clutter the core
object.cfile.So let's move them into a separate C file and thus ensure that we have room to grow :).
Signed-off-by Alexander Graf <[email protected]>--- backends/hostmem-file.c | 1 + backends/hostmem.c | 1 + backends/rng-egd.c | 1 + backends/rng-random.c | 1 + backends/rng.c | 1 + backends/tpm.c | 1 + hw/acpi/ich9.c | 1 + hw/acpi/pcihp.c | 1 + hw/acpi/piix4.c | 1 + hw/core/machine.c | 1 + hw/core/qdev.c | 1 + hw/i386/acpi-build.c | 1 + hw/isa/lpc_ich9.c | 1 + hw/ppc/spapr.c | 1 + include/qom/object.h | 85 ------------------- include/qom/property.h | 104 ++++++++++++++++++++++++ memory.c | 1 + qom/Makefile.objs | 2 +- qom/object.c | 197 ++------------------------------------------ qom/property.c | 212 ++++++++++++++++++++++++++++++++++++++++++++++++ target-i386/cpu.c | 1 + ui/console.c | 1 + 22 files changed, 340 insertions(+), 277 deletions(-)create mode 100644
include/qom/property.h
create mode 100644qom/property.c
Quoted 15 lines
Quoted 9 lines
- *
object_property_add_uint64_ptr:
- * @obj: the object to add a property to
- * @name: the name of the property
- * @v: pointer to value
- * @errp: if an error occurs, a pointer to an area to store the error
- *
- * Add an integer property in memory. This function will add a
- * property of type 'uint64'.
- */include/qom/object.h void object_property_add_link(Object *obj, const char *name, · line 1173
Quoted 5 lines
include/qom/object.h +0
-4-void object_property_add_uint64_ptr (Object *obj,const char *name, -const uint64_t *v,Error **Errp); - -/** * object_property_add_alias: Any reason to not migrate alias and link props as well?
IIRC I tried, but there were more interdependencies inside the same file. So I went with the easy ones (that I cared about) first and left the rest as exercise for the reader :).
Alex
PATCH v2 2/9 qom: macroify integer property helpers
In reply to Alexander GrafWe have a bunch of nice helpers that allow us to easily register an integer field as QOM property. However, we have those duplicated for every integer size available.
This is very cumbersome (and prone to bugs) to work with and extend, so let's strip out the only difference there is (the size) and generate the actual functions via a macro.
---
v1 -> v2:
- Rename DECLARE_INTEGER_VISITOR to DECLARE_PROP_SET_GET
- Make macro take name and type arguments, enabling generation of "bool" types later
--- qom/property.c | 82 +++++++++++++++++----------------------------------------- 1 file changed, 24 insertions(+), 58 deletions(-)
qom/property.c +24 -58
@@ -151,62 +151,28 @@ void object_property_add_bool(Object *obj, const char *name, } } -static void property_get_uint8_ptr (Object *obj,Visitor *v, -void *opaque,const char *name, -Error **errp) -{ -uint8_t value = *(uint8_t *)opaque; -visit_type_uint8 (v, &value, name, errp); -} - -static void property_get_uint16_ptr (Object *obj,Visitor *v, -void *opaque,const char *name, -Error **errp) -{ -uint16_t value = *(uint16_t *)opaque; -visit_type_uint16 (v, &value, name, errp); -} - -static void property_get_uint32_ptr (Object *obj,Visitor *v, -void *opaque,const char *name, -Error **errp) -{ -uint32_t value = *(uint32_t *)opaque; -visit_type_uint32 (v, &value, name, errp); -} - -static void property_get_uint64_ptr (Object *obj,Visitor *v, -void *opaque,const char *name, -Error **errp) -{ -uint64_t value = *(uint64_t *)opaque; -visit_type_uint64 (v, &value, name, errp); -} +#define DECLARE_PROP_SET_GET (name, valtype) \ + \ +static void glue(glue(property_get_,name),_ptr)(Object *obj, Visitor *v, \ + void *opaque, \ + const char *name, \ + Error **errp) \ +{ \ + valtype value = *(valtype *)opaque; \ + glue(visit_type_,name)(v, &value, name, errp); \ +} \ + \ +void glue(glue(object_property_add_,name),_ptr)(Object *obj, const char *name, \ + const valtype *v, \ + Error **errp) \ +{ \ + ObjectPropertyAccessor *get = glue(glue(property_get_,name),_ptr); \ + object_property_add(obj, name, stringify(name), get, NULL, NULL, (void *)v,\ + errp); \ +} \ + +DECLARE_PROP_SET_GET(uint8, uint8_t) +DECLARE_PROP_SET_GET(uint16, uint16_t) +DECLARE_PROP_SET_GET(uint32, uint32_t) +DECLARE_PROP_SET_GET (uint64, uint64_t) -void object_property_add_uint8_ptr (Object *obj,const char *name, -const uint8_t *v,Error **errp) -{ -object_property_add (obj, name,"uint8" , property_get_uint8_ptr, -NULL ,NULL , (void *)v, errp); -} - -void object_property_add_uint16_ptr (Object *obj,const char *name, -const uint16_t *v,Error **errp) -{ -object_property_add (obj, name,"uint16" , property_get_uint16_ptr, -NULL ,NULL , (void *)v, errp); -} - -void object_property_add_uint32_ptr (Object *obj,const char *name, -const uint32_t *v,Error **errp) -{ -object_property_add (obj, name,"uint32" , property_get_uint32_ptr, -NULL ,NULL , (void *)v, errp); -} - -void object_property_add_uint64_ptr (Object *obj,const char *name, -const uint64_t *v,Error **errp) -{ -object_property_add (obj, name,"uint64" , property_get_uint64_ptr, -NULL ,NULL , (void *)v, errp); -}
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH v2 2/9] qom: macroify integer property helpers
Quoted 10 lines · Alexander Graf
We have a bunch of nice helpers that allow us to easily register an integer field as QOM property. However, we have those duplicated for every integer size available.
This is very cumbersome (and prone to bugs) to work with and extend, so let's strip out the only difference there is (the size) and generate the actual functions via a macro.
Signed-off-by Alexander Graf <[email protected]>
Quoted 106 lines
---
v1 -> v2:
- Rename
DECLARE_INTEGER_VISITORtoDECLARE_PROP_SET_GET
- Make macro take name and type arguments, enabling generation of "bool" types later--- qom/property.c | 82 +++++++++++++++++----------------------------------------- 1 file changed, 24 insertions(+), 58 deletions(-)qom/property.c +24
-59@@ -151,62 +151,28 @@ void object_property_add_bool(Object *obj, const char *name, } } -static void property_get_uint8_ptr (Object *obj,Visitor *v, -void *opaque,const char *name, -Error **errp) -{ -uint8_t value = *(uint8_t *)opaque; -visit_type_uint8 (v, &value, name, errp); -} - -static void property_get_uint16_ptr (Object *obj,Visitor *v, -void *opaque,const char *name, -Error **errp) -{ -uint16_t value = *(uint16_t *)opaque; -visit_type_uint16 (v, &value, name, errp); -} - -static void property_get_uint32_ptr (Object *obj,Visitor *v, -void *opaque,const char *name, -Error **errp) -{ -uint32_t value = *(uint32_t *)opaque; -visit_type_uint32 (v, &value, name, errp); -} - -static void property_get_uint64_ptr (Object *obj,Visitor *v, -void *opaque,const char *name, -Error **errp) -{ -uint64_t value = *(uint64_t *)opaque; -visit_type_uint64 (v, &value, name, errp); -} +#define DECLARE_PROP_SET_GET (name, valtype) \ + \ +static void glue(glue(property_get_,name),_ptr)(Object *obj, Visitor *v, \ + void *opaque, \ + const char *name, \ + Error **errp) \ +{ \ + valtype value = *(valtype *)opaque; \ + glue(visit_type_,name)(v, &value, name, errp); \ +} \ + \ +void glue(glue(object_property_add_,name),_ptr)(Object *obj, const char *name, \ + const valtype *v, \ + Error **errp) \ +{ \ + ObjectPropertyAccessor *get = glue(glue(property_get_,name),_ptr); \ + object_property_add(obj, name, stringify(name), get, NULL, NULL, (void *)v,\ + errp); \ +} \ + +DECLARE_PROP_SET_GET(uint8, uint8_t) +DECLARE_PROP_SET_GET(uint16, uint16_t) +DECLARE_PROP_SET_GET(uint32, uint32_t) +DECLARE_PROP_SET_GET (uint64, uint64_t) -void object_property_add_uint8_ptr (Object *obj,const char *name, -const uint8_t *v,Error **errp) -{ -object_property_add (obj, name,"uint8" , property_get_uint8_ptr, -NULL ,NULL , (void *)v, errp); -} - -void object_property_add_uint16_ptr (Object *obj,const char *name, -const uint16_t *v,Error **errp) -{ -object_property_add (obj, name,"uint16" , property_get_uint16_ptr, -NULL ,NULL , (void *)v, errp); -} - -void object_property_add_uint32_ptr (Object *obj,const char *name, -const uint32_t *v,Error **errp) -{ -object_property_add (obj, name,"uint32" , property_get_uint32_ptr, -NULL ,NULL , (void *)v, errp); -} - -void object_property_add_uint64_ptr (Object *obj,const char *name, -const uint64_t *v,Error **errp) -{ -object_property_add (obj, name,"uint64" , property_get_uint64_ptr, -NULL ,NULL , (void *)v, errp); -} --1.8.1.4
PATCH v2 3/9 qom: Expose property helpers for get/set of integers
In reply to Alexander GrafWe have helper functions to easily expose integers as QOM object properties. However, these are read only.
This patch makes the getter function world accessible and adds a generic setter for integer properties.
We can use these later with the generic object_property_add to not dupliate simple logic all over the place.
--- include/qom/property.h | 128 +++++++++++++++++++++++++++++++++++++++++++++++++ qom/property.c | 14 +++++- 2 files changed, 140 insertions(+), 2 deletions(-)
include/qom/property.h +128 -0
@@ -63,6 +63,38 @@ void object_property_add_uint8_ptr(Object *obj, const char *name, const uint8_t *v, Error **errp);/** +* object_property_get_uint8_ptr: +* @obj: the object to get the property from +* @v: visitor to the property +* @opaque: pointer to the integer value we write the result to +* @name: name of the property +* @errp: if an error occurs, a pointer to an area to store the error +* +* Visitor function to read an integer value of type 'uint8' into the visitor. +* Use this as the 'get' argument in object_property_add if your field is a +* uint8_t value. +*/ +void object_property_get_uint8_ptr (Object *obj,struct Visitor *v, +void *opaque,const char *name, +Error **errp); + +/** +* object_property_set_uint8_ptr: +* @obj: the object to set the property in +* @v: visitor to the property +* @opaque: pointer to the integer value +* @name: name of the property +* @errp: if an error occurs, a pointer to an area to store the error +* +* Visitor function to set an integer value of type 'uint8' to a given value. +* Use this as the 'set' argument in object_property_add if your field is a +* uint8_t value. +*/ +void object_property_set_uint8_ptr (Object *obj,struct Visitor *v, +void *opaque,const char *name, +Error **errp); + +/** * object_property_add_uint16_ptr: * @obj: the object to add a property to * @name: the name of the property
@@ -76,6 +108,38 @@ void object_property_add_uint16_ptr(Object *obj, const char *name, const uint16_t *v, Error **errp);/** +* object_property_get_uint16_ptr: +* @obj: the object to get the property from +* @v: visitor to the property +* @opaque: pointer to the integer value we write the result to +* @name: name of the property +* @errp: if an error occurs, a pointer to an area to store the error +* +* Visitor function to read an integer value of type 'uint16' into the visitor. +* Use this as the 'get' argument in object_property_add if your field is a +* uint16_t value. +*/ +void object_property_get_uint16_ptr (Object *obj,struct Visitor *v, +void *opaque,const char *name, +Error **errp); + +/** +* object_property_set_uint16_ptr: +* @obj: the object to set the property in +* @v: visitor to the property +* @opaque: pointer to the integer value +* @name: name of the property +* @errp: if an error occurs, a pointer to an area to store the error +* +* Visitor function to set an integer value of type 'uint16' to a given value. +* Use this as the 'set' argument in object_property_add if your field is a +* uint16_t value. +*/ +void object_property_set_uint16_ptr (Object *obj,struct Visitor *v, +void *opaque,const char *name, +Error **errp); + +/** * object_property_add_uint32_ptr: * @obj: the object to add a property to * @name: the name of the property
@@ -89,6 +153,38 @@ void object_property_add_uint32_ptr(Object *obj, const char *name, const uint32_t *v, Error **errp);/** +* object_property_get_uint32_ptr: +* @obj: the object to get the property from +* @v: visitor to the property +* @opaque: pointer to the integer value we write the result to +* @name: name of the property +* @errp: if an error occurs, a pointer to an area to store the error +* +* Visitor function to read an integer value of type 'uint32' into the visitor. +* Use this as the 'get' argument in object_property_add if your field is a +* uint32_t value. +*/ +void object_property_get_uint32_ptr (Object *obj,struct Visitor *v, +void *opaque,const char *name, +Error **errp); + +/** +* object_property_set_uint32_ptr: +* @obj: the object to set the property in +* @v: visitor to the property +* @opaque: pointer to the integer value +* @name: name of the property +* @errp: if an error occurs, a pointer to an area to store the error +* +* Visitor function to set an integer value of type 'uint32' to a given value. +* Use this as the 'set' argument in object_property_add if your field is a +* uint32_t value. +*/ +void object_property_set_uint32_ptr (Object *obj,struct Visitor *v, +void *opaque,const char *name, +Error **errp); + +/** * object_property_add_uint64_ptr: * @obj: the object to add a property to * @name: the name of the property
@@ -101,4 +197,36 @@ void object_property_add_uint32_ptr(Object *obj, const char *name,void object_property_add_uint64_ptr (Object *obj,const char *name,const uint64_t *v,Error **Errp); +/** +* object_property_get_uint64_ptr: +* @obj: the object to get the property from +* @v: visitor to the property +* @opaque: pointer to the integer value we write the result to +* @name: name of the property +* @errp: if an error occurs, a pointer to an area to store the error +* +* Visitor function to read an integer value of type 'uint64' into the visitor. +* Use this as the 'get' argument in object_property_add if your field is a +* uint64_t value. +*/ +void object_property_get_uint64_ptr (Object *obj,struct Visitor *v, +void *opaque,const char *name, +Error **errp); + +/** +* object_property_set_uint64_ptr: +* @obj: the object to set the property in +* @v: visitor to the property +* @opaque: pointer to the integer value +* @name: name of the property +* @errp: if an error occurs, a pointer to an area to store the error +* +* Visitor function to set an integer value of type 'uint64' to a given value. +* Use this as the 'set' argument in object_property_add if your field is a +* uint64_t value. +*/ +void object_property_set_uint64_ptr (Object *obj,struct Visitor *v, +void *opaque,const char *name, +Error **errp); +#endif /* !QEMU_PROPERTY_H */
qom/property.c +12 -2
@@ -153,7 +153,7 @@ void object_property_add_bool(Object *obj, const char *name,#define DECLARE_PROP_SET_GET (name, valtype) \ \ -static void glue(glue(property_get_,name),_ptr)(Object *obj, Visitor *v, \ +void glue(glue(object_property_get_,name),_ptr)(Object *obj, Visitor *v, \ void *opaque, \ const char *name, \ Error **errp) \
@@ -162,11 +162,21 @@ static void glue(glue(property_get_,name),_ptr)(Object *obj, Visitor *v, \glue (visit_type_,name)(v, &value, name, errp); \ } \ \ +void glue (glue (object_property_set_ ,name ),_ptr )(Object *obj,Visitor *v, \ +void *opaque, \ +const char *name, \ +Error **errp) \ +{ \ +valtype value; \ +glue (visit_type_,name)(v, &value, name, errp); \ + *(valtype *)opaque = value; \ +} \ + \void glue (glue (object_property_add_ ,name ),_ptr )(Object *obj,const char *name, \const valtype *v, \Error **errp) \ { \ -ObjectPropertyAccessor *get =glue (glue (property_get_,name),_ptr); \ +ObjectPropertyAccessor *get =glue (glue (object_property_get_,name),_ptr); \object_property_add (obj, name,stringify (name), get,NULL ,NULL , (void *)v,\ errp); \ } \
Signature · 1 line
1.8.1.4
PATCH v2 4/9 qom: Add generic object property g_free helper
In reply to Alexander GrafA good amount of properties are really just g_new / g_malloc allocated memory. There's no reason we need to have different release helpers for all of those.
This patch introduces a new g_free() based helper for property release and replaces existing duplicated code implementations in object.c as well as property.c with it.
--- include/qom/property.h | 12 ++++++++++++ qom/object.c | 9 +-------- qom/property.c | 17 ++++------------- 3 files changed, 17 insertions(+), 21 deletions(-)
include/qom/property.h +12 -0
@@ -229,4 +229,16 @@ void object_property_set_uint64_ptr(Object *obj, struct Visitor *v, void *opaque, const char *name, Error **errp); +/** +* object_property_release_g_free: +* @obj: the object that owns the property +* @name: name of the property +* @opaque: pointer to glib allocated memory +* +* Generic helper function to free a property using g_free(). Use this if you +* want to make sure that your property is properly g_free()'d when the property +* gets released. +*/ +void object_property_release_g_free (Object *obj,const char *name,void *opaque); +#endif /* !QEMU_PROPERTY_H */
qom/object.c +1 -8
@@ -1406,13 +1406,6 @@ static Object *property_resolve_alias(Object *obj, void *opaque,return object_resolve_path_component (prop->target_obj, prop->target_name); } -static void property_release_alias (Object *obj,const char *name,void *opaque) -{ -AliasProperty *prop = opaque; - -g_free (prop); -} -void object_property_add_alias (Object *obj,const char *name,Object *target_obj,const char *target_name,Error **errp)
@@ -1441,7 +1434,7 @@ void object_property_add_alias(Object *obj, const char *name, op =object_property_add (obj, name, prop_type, property_get_alias, property_set_alias, - property_release_alias, + object_property_release_g_free, prop, errp); op->resolve = property_resolve_alias;
qom/property.c +4 -13
@@ -61,11 +61,9 @@ static void property_set_str(Object *obj, Visitor *v, void *opaque,g_free (value); } -static void property_release_str (Object *obj,const char *name, -void *opaque) +void object_property_release_g_free (Object *obj,const char *name,void *opaque) { -StringProperty *prop = opaque; -g_free (prop); +g_free (opaque); } void object_property_add_str(Object *obj, const char *name,
@@ -82,7 +80,7 @@ void object_property_add_str(Object *obj, const char *name,object_property_add (obj, name,"string" , get ? property_get_str :NULL , set ? property_set_str :NULL , - property_release_str, + object_property_release_g_free, prop, &local_err);if (local_err) {error_propagate (errp, local_err);
@@ -122,13 +120,6 @@ static void property_set_bool(Object *obj, Visitor *v, void *opaque, prop->set (obj, value, errp); } -static void property_release_bool (Object *obj,const char *name, -void *opaque) -{ -BoolProperty *prop = opaque; -g_free (prop); -} - void object_property_add_bool(Object *obj, const char *name, bool (*get)(Object *, Error **), void (*set)(Object *, bool, Error **),
@@ -143,7 +134,7 @@ void object_property_add_bool(Object *obj, const char *name,object_property_add (obj, name,"bool" , get ? property_get_bool :NULL , set ? property_set_bool :NULL , - property_release_bool, + object_property_release_g_free, prop, &local_err);if (local_err) {error_propagate (errp, local_err);
Signature · 1 line
1.8.1.4
PATCH v2 5/9 sysbus: Add user map hints
In reply to Alexander GrafWe want to give the user the ability to tell our machine file where he wants to have devices mapped to. This patch adds code to create these hints dynamically and expose them as object properties that can only be modified before device realization.
---
v1 -> v2:
- make irq and pio properties uint64
- ensure qom exposed pointers don't change due to realloc
- fix sysbus_pass_irq
- make properties write-once, not write-before-realize
- make props only available via qom, no state pointers left
--- hw/core/sysbus.c | 43 ++++++++++++++++++++++++++++++++++++++++--- include/hw/sysbus.h | 1 + 2 files changed, 41 insertions(+), 3 deletions(-)
hw/core/sysbus.c +40 -3
@@ -20,6 +20,7 @@#include "hw/sysbus.h" #include "monitor/monitor.h" #include "exec/address-spaces.h" +#include "qom/property.h" static void sysbus_dev_print (Monitor *mon,DeviceState *dev,int indent);static char *sysbus_get_fw_dev_path (DeviceState *dev);
@@ -86,6 +87,34 @@ void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,sysbus_mmio_map_common (dev, n, addr, true, priority); } +static void sysbus_property_set_uint64_ptr (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +uint64_t *valp = opaque; + +if (*valp !=SYSBUS_DYNAMIC ) { +error_setg (errp,"Attempt to set property '%s' twice" , name); +return ; + } + +object_property_set_uint64_ptr (obj, v, opaque, name, errp); +} + +static void sysbus_init_int64_prop (SysBusDevice *dev,const char *propstr, +int n) +{ +char *name =g_strdup_printf (propstr, n); +Object *obj =OBJECT (dev); +uint64_t *user_val =g_new (uint64_t,1 ); + + *user_val =SYSBUS_DYNAMIC ; + +object_property_add (obj, name,"uint64" , object_property_get_uint64_ptr, + sysbus_property_set_uint64_ptr, + object_property_release_g_free, user_val,NULL ); +} +/* Request an IRQ source. The actual IRQ object may be populated later. */ void sysbus_init_irq (SysBusDevice *dev,qemu_irq *p) {
@@ -94,6 +123,8 @@ void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p)assert (dev->num_irq <QDEV_MAX_IRQ ); n = dev->num_irq++; dev->irqp[n] = p; + +sysbus_init_int64_prop (dev,"irq[%d]" , n); }/* Pass IRQs from a target device. */
@@ -101,9 +132,8 @@ void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target) {int i;assert (dev->num_irq ==0 ); - dev->num_irq = target->num_irq;for (i =0 ; i < dev->num_irq; i++) { - dev->irqp[i] = target->irqp[i]; +sysbus_init_irq (dev, target->irqp[i]); } }
@@ -115,6 +145,8 @@ void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory) n = dev->num_mmio++; dev->mmio[n].addr =-1 ; dev->mmio[n].memory = memory; + +sysbus_init_int64_prop (dev,"mmio[%d]" , n); }MemoryRegion *sysbus_mmio_get_region (SysBusDevice *dev,int n)
@@ -127,8 +159,13 @@ void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size)pio_addr_t i;for (i =0 ; i < size; i++) { +int n; +assert (dev->num_pio <QDEV_MAX_PIO ); - dev->pio[dev->num_pio++] = ioport++; + n = dev->num_pio++; + dev->pio[n] = ioport++; + +sysbus_init_int64_prop (dev,"pio[%d]" , n); } }
include/hw/sysbus.h +1 -0
@@ -9,6 +9,7 @@#define QDEV_MAX_MMIO 32#define QDEV_MAX_PIO 32#define QDEV_MAX_IRQ 512 +#define SYSBUS_DYNAMIC -1ULL#define TYPE_SYSTEM_BUS "System"#define SYSTEM_BUS (obj) OBJECT_CHECK(IDEBus, (obj), TYPE_IDE_BUS)
Signature · 1 line
1.8.1.4
PATCH v2 6/9 sysbus: Make devices spawnable via -device
In reply to Alexander GrafNow that we can properly map sysbus devices that haven't been connected to something forcefully by C code, we can allow the -device command line option to spawn them.
For machines that don't implement dynamic sysbus assignment in their board files we add a new bool "has_dynamic_sysbus" to the machine class. When that property is false (default), we bail out when we see dynamically spawned sysbus devices, like we did before.
---
v1 -> v2:
- use bool in MachineClass rather than property
--- hw/core/machine.c | 43 +++++++++++++++++++++++++++++++++++++++++++ hw/core/sysbus.c | 7 ------- include/hw/boards.h | 8 ++++++-- vl.c | 1 + 4 files changed, 50 insertions(+), 9 deletions(-)
hw/core/machine.c +43 -0
@@ -13,6 +13,9 @@#include "hw/boards.h" #include "qapi/visitor.h" #include "qom/property.h" +#include "hw/sysbus.h" +#include "sysemu/sysemu.h" +#include "qemu/error-report.h" static char *machine_get_accel (Object *obj,Error **errp) {
@@ -236,8 +239,44 @@ static void machine_set_firmware(Object *obj, const char *value, Error **errp) ms->firmware =g_strdup (value); } +static int search_for_sysbus_device (Object *obj,void *opaque) +{ +if (!object_dynamic_cast (obj,TYPE_SYS_BUS_DEVICE )) { +/* Container or different device, traverse it for children */ +return object_child_foreach (obj, search_for_sysbus_device, opaque); + } + +error_report ("Device '%s' can not be handled by this machine" , +qdev_fw_name (DEVICE (obj))); +exit (1 ); +} + +static void machine_init_notify (Notifier *notifier,void *data) +{ +Object *machine =qdev_get_machine (); +ObjectClass *oc =object_get_class (machine); +MachineClass *mc =MACHINE_CLASS (oc); +Object *container; + +if (mc->has_dynamic_sysbus) { +/* Our machine can handle dynamic sysbus devices, we're all good */ +return ; + } + +/* +* Loop through all dynamically created devices and check whether there +* are sysbus devices among them. If there are, error out. +*/ + container =container_get (machine,"/peripheral" ); +search_for_sysbus_device (container,NULL ); + container =container_get (machine,"/peripheral-anon" ); +search_for_sysbus_device (container,NULL ); +} +static void machine_initfn (Object *obj) { +MachineState *ms =MACHINE (obj); +object_property_add_str (obj,"accel" , machine_get_accel, machine_set_accel,NULL ); object_property_add_bool(obj, "kernel_irqchip",
@@ -275,6 +314,10 @@ static void machine_initfn(Object *obj)object_property_add_bool (obj,"usb" , machine_get_usb, machine_set_usb,NULL );object_property_add_str (obj,"firmware" , machine_get_firmware, machine_set_firmware,NULL ); + +/* Register notifier when init is done for sysbus sanity checks */ + ms->sysbus_notifier.notify = machine_init_notify; +qemu_add_machine_init_done_notifier (&ms->sysbus_notifier); }static void machine_finalize (Object *obj)
hw/core/sysbus.c +0 -7
@@ -294,13 +294,6 @@ static void sysbus_device_class_init(ObjectClass *klass, void *data)DeviceClass *k =DEVICE_CLASS (klass); k->init = sysbus_device_init; k->bus_type =TYPE_SYSTEM_BUS ; -/* -* device_add plugs devices into suitable bus. For "real" buses, -* that actually connects the device. For sysbus, the connections -* need to be made separately, and device_add can't do that. The -* device would be left unconnected, and could not possibly work. -*/ - k->cannot_instantiate_with_device_add_yet = true; }static const TypeInfo sysbus_device_type_info = {
include/hw/boards.h +6 -2
@@ -35,7 +35,8 @@ struct QEMUMachine { use_sclp:1, no_floppy:1, no_cdrom:1, - no_sdcard:1; + no_sdcard:1, + has_dynamic_sysbus:1;int is_default;const char *default_machine_opts;const char *default_boot_order;
@@ -93,7 +94,8 @@ struct MachineClass { use_sclp:1, no_floppy:1, no_cdrom:1, - no_sdcard:1; + no_sdcard:1, + has_dynamic_sysbus:1;int is_default;const char *default_machine_opts;const char *default_boot_order;
@@ -110,6 +112,8 @@ struct MachineClass {struct MachineState {/*< private >*/ Object parent_obj; +Notifier sysbus_notifier; +/*< public >*/ char *accel;
vl.c +1 -0
@@ -1569,6 +1569,7 @@ static void machine_class_init(ObjectClass *oc, void *data) mc->no_floppy = qm->no_floppy; mc->no_cdrom = qm->no_cdrom; mc->no_sdcard = qm->no_sdcard; + mc->has_dynamic_sysbus = qm->has_dynamic_sysbus; mc->is_default = qm->is_default; mc->default_machine_opts = qm->default_machine_opts; mc->default_boot_order = qm->default_boot_order;
Signature · 1 line
1.8.1.4
PATCH v2 7/9 PPC: e500: Support dynamically spawned sysbus devices
In reply to Alexander GrafFor e500 our approach to supporting dynamically spawned sysbus devices is to create a simple bus from the guest's point of view within which we map those devices dynamically.
We allocate memory regions always within the "platform" hole in address space and map IRQs to predetermined IRQ lines that are reserved for platform device usage.
This maps really nicely into device tree logic, so we can just tell the guest about our virtual simple bus in device tree as well.
---
v1 -> v2:
- access sysbus properties via qom
- move platform bus definitions to params
- move platform bus to 36bit address space
- make naming more consistent
- remove device_type from platform bus dt node
- remove id field in dt generation
--- hw/ppc/e500.c | 251 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/e500.h | 5 ++ hw/ppc/e500plat.c | 6 ++ 3 files changed, 262 insertions(+)
hw/ppc/e500.c +251 -0
@@ -36,6 +36,7 @@#include "exec/address-spaces.h" #include "qemu/host-utils.h" #include "hw/pci-host/ppce500.h" +#include "qemu/error-report.h" #define EPAPR_MAGIC (0x45504150)#define BINARY_DEVICE_TREE_FILE "mpc8544ds.dtb"
@@ -47,6 +48,8 @@#define RAM_SIZES_ALIGN (64UL << 20) +#define E500_PLATFORM_BUS_PAGE_SHIFT 12 +/* TODO: parameterize */ #define MPC8544_CCSRBAR_BASE 0xE0000000ULL#define MPC8544_CCSRBAR_SIZE 0x00100000ULL
@@ -122,6 +125,76 @@ static void dt_serial_create(void *fdt, unsigned long long offset, } } +typedef struct PlatformDevtreeData { +void *fdt; +const char *mpic; +int irq_start; +const char *node; +}PlatformDevtreeData ; + +static int sysbus_device_create_devtree (Object *obj,void *opaque) +{ +PlatformDevtreeData *data = opaque; +Object *dev; +SysBusDevice *sbdev; +bool matched = false; + + dev =object_dynamic_cast (obj,TYPE_SYS_BUS_DEVICE ); + sbdev = (SysBusDevice *)dev; + +if (!sbdev) { +/* Container, traverse it for children */ +return object_child_foreach (obj, sysbus_device_create_devtree, data); + } + +if (!matched) { +error_report ("Device %s is not supported by this machine yet." , +qdev_fw_name (DEVICE (dev))); +exit (1 ); + } + +return 0 ; +} + +static void platform_bus_create_devtree (PPCE500Params *params,void *fdt, +const char *mpic) +{ +gchar *node =g_strdup_printf ("/platform@%" PRIx64, params->platform_bus_base); +const char platcomp[] ="qemu,platform\0simple-bus" ; +PlatformDevtreeData data; +Object *container; +uint64_t addr = params->platform_bus_base; +uint64_t size = params->platform_bus_size; +int irq_start = params->platform_bus_first_irq; + +/* Create a /platform node that we can put all devices into */ + +qemu_fdt_add_subnode (fdt, node); +qemu_fdt_setprop (fdt, node,"compatible" , platcomp,sizeof (platcomp)); + +/* Our platform bus region is less than 32bit big, so 1 cell is enough for +address and size */ +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_phandle (fdt, node,"interrupt-parent" , mpic); + +/* Loop through all devices and create nodes for known ones */ + + data.fdt = fdt; + data.mpic = mpic; + data.irq_start = irq_start; + data.node = node; + + container =container_get (qdev_get_machine (),"/peripheral" ); +sysbus_device_create_devtree (container, &data); + container =container_get (qdev_get_machine (),"/peripheral-anon" ); +sysbus_device_create_devtree (container, &data); + +g_free (node); +} + static int ppce500_load_device_tree(MachineState *machine, PPCE500Params *params, hwaddr addr,
@@ -379,6 +452,10 @@ static int ppce500_load_device_tree(MachineState *machine,qemu_fdt_setprop_cell (fdt, pci,"#address-cells" ,3 );qemu_fdt_setprop_string (fdt,"/aliases" ,"pci0" , pci); +if (params->has_platform_bus) { +platform_bus_create_devtree (params, fdt, mpic); + } + params->fixup_devtree (params, fdt);if (toplevel_compat) {
@@ -618,6 +695,169 @@ static qemu_irq *ppce500_init_mpic(PPCE500Params *params, MemoryRegion *ccsr,return mpic; } +typedef struct PlatformBusNotifier { +Notifier notifier; +MemoryRegion *address_space_mem; +qemu_irq *mpic; +PPCE500Params params; +}PlatformBusNotifier ; + +typedef struct PlatformBusInitData { +unsigned long *used_irqs; +unsigned long *used_mem; +MemoryRegion *mem; +qemu_irq *irqs; +int device_count; +PPCE500Params *params; +}PlatformBusInitData ; + +static int platform_bus_map_irq (PPCE500Params *params,SysBusDevice *sbdev, +int n,unsigned long *used_irqs, +qemu_irq *platform_irqs) +{ +int max_irqs = params->platform_bus_num_irqs; +char *prop =g_strdup_printf ("irq[%d]" , n); +int irqn =object_property_get_int (OBJECT (sbdev), prop,NULL ); + +if (irqn ==SYSBUS_DYNAMIC ) { +/* Find the first available IRQ */ + irqn =find_first_zero_bit (used_irqs, max_irqs); + } + +if ((irqn >= max_irqs) ||test_and_set_bit (irqn, used_irqs)) { +hw_error ("e500: IRQ %d is already allocated or no free IRQ left" , irqn); + } + +sysbus_connect_irq (sbdev, n, platform_irqs[irqn]); +object_property_set_int (OBJECT (sbdev), irqn, prop,NULL ); + +g_free (prop); +return 0 ; +} + +static int platform_bus_map_mmio (PPCE500Params *params,SysBusDevice *sbdev, +int n,unsigned long *used_mem, +MemoryRegion *pmem) +{ +MemoryRegion *device_mem = sbdev->mmio[n].memory; +uint64_t size =memory_region_size (device_mem); +uint64_t page_size = (1 <<E500_PLATFORM_BUS_PAGE_SHIFT ); +uint64_t page_mask = page_size -1 ; +uint64_t size_pages = (size + page_mask) >>E500_PLATFORM_BUS_PAGE_SHIFT ; +uint64_t max_size = params->platform_bus_size; +uint64_t max_pages = max_size >>E500_PLATFORM_BUS_PAGE_SHIFT ; +char *prop =g_strdup_printf ("mmio[%d]" , n); +hwaddr addr =object_property_get_int (OBJECT (sbdev), prop,NULL ); +int page; +int i; + + page = addr >>E500_PLATFORM_BUS_PAGE_SHIFT ; +if (addr ==SYSBUS_DYNAMIC ) { +uint64_t size_pages_align; + +/* Align the region to at least its own size granularity */ +if (is_power_of_2 (size_pages)) { + size_pages_align = size_pages; + }else { + size_pages_align =pow2floor (size_pages) <<1 ; + } + +/* Find the first available region that fits */ + page =bitmap_find_next_zero_area (used_mem, max_pages,0 , size_pages, + size_pages_align); + + addr = (uint64_t )page <<E500_PLATFORM_BUS_PAGE_SHIFT ; + } + +if (page >= max_pages ||test_bit (page, used_mem) || + (find_next_bit (used_mem, max_pages, page) < size_pages)) { +hw_error ("e500: Memory [%" PRIx64":%" PRIx64" is already allocated or " +"no slot left" , addr, size); + } + +for (i = page; i < (page + size_pages); i++) { +set_bit (i, used_mem); + } + +memory_region_add_subregion (pmem, addr, device_mem); + sbdev->mmio[n].addr = addr; +object_property_set_int (OBJECT (sbdev), addr, prop,NULL ); + +g_free (prop); +return 0 ; +} + +static int sysbus_device_check (Object *obj,void *opaque) +{ +PlatformBusInitData *init = opaque; +Object *dev; +SysBusDevice *sbdev; +int i; + + dev =object_dynamic_cast (obj,TYPE_SYS_BUS_DEVICE ); + sbdev = (SysBusDevice *)dev; + +if (!sbdev) { +/* Container, traverse it for children */ +return object_child_foreach (obj, sysbus_device_check, opaque); + } + +/* Connect sysbus device to virtual platform bus */ +for (i =0 ; i < sbdev->num_irq; i++) { +if (!sbdev->irqp[i]) { +/* This IRQ is an incoming IRQ, we can't wire those here */ +continue ; + } +platform_bus_map_irq (init->params, sbdev, i, init->used_irqs, init->irqs); + } + +for (i =0 ; i < sbdev->num_mmio; i++) { +platform_bus_map_mmio (init->params, sbdev, i, init->used_mem, init->mem); + } + +return 0 ; +} + +static void platform_bus_init (PPCE500Params *params, +MemoryRegion *address_space_mem, +qemu_irq *mpic) +{ +uint64_t max_size = params->platform_bus_size; +uint64_t max_pages = max_size >>E500_PLATFORM_BUS_PAGE_SHIFT ; +DECLARE_BITMAP (used_irqs, params->platform_bus_num_irqs); +DECLARE_BITMAP (used_mem, max_pages); +MemoryRegion *platform_region =g_new (MemoryRegion,1 ); +Object *container; +PlatformBusInitData init = { + .used_irqs = used_irqs, + .used_mem = used_mem, + .mem = platform_region, + .irqs = &mpic[params->platform_bus_first_irq], + .params = params, + }; + +memory_region_init (platform_region,NULL ,"platform devices" , + params->platform_bus_size); + +bitmap_clear (used_irqs,0 , params->platform_bus_num_irqs); +bitmap_clear (used_mem,0 , max_pages); + +/* Loop through all sysbus devices that were spawened outside the machine */ + container =container_get (qdev_get_machine (),"/peripheral" ); +sysbus_device_check (container, &init); + container =container_get (qdev_get_machine (),"/peripheral-anon" ); +sysbus_device_check (container, &init); + +memory_region_add_subregion (address_space_mem, params->platform_bus_base, + platform_region); +} + +static void platform_bus_init_notify (Notifier *notifier,void *data) +{ +PlatformBusNotifier *pn = (PlatformBusNotifier *)notifier; +platform_bus_init (&pn->params, pn->address_space_mem, pn->mpic); +} +void ppce500_init (MachineState *machine,PPCE500Params *params) {MemoryRegion *address_space_mem =get_system_memory ();
@@ -770,6 +1010,17 @@ void ppce500_init(MachineState *machine, PPCE500Params *params) cur_base = (32 *1024 *1024 ); } +/* Platform Devices */ +if (params->has_platform_bus) { +PlatformBusNotifier *notifier =g_new (PlatformBusNotifier,1 ); + + notifier->notifier.notify = platform_bus_init_notify; + notifier->address_space_mem = address_space_mem; + notifier->mpic = mpic; + notifier->params = *params; +qemu_add_machine_init_done_notifier (¬ifier->notifier); + } +/* Load kernel. */ if (machine->kernel_filename) { kernel_base = cur_base;
hw/ppc/e500.h +5 -0
@@ -11,6 +11,11 @@ typedef struct PPCE500Params {void (*fixup_devtree)(struct PPCE500Params *params,void *fdt);int mpic_version; +bool has_platform_bus; +hwaddr platform_bus_base; +hwaddr platform_bus_size; +int platform_bus_first_irq; +int platform_bus_num_irqs; } PPCE500Params;void ppce500_init (MachineState *machine,PPCE500Params *params);
hw/ppc/e500plat.c +6 -0
@@ -35,6 +35,11 @@ static void e500plat_init(MachineState *machine) .pci_nr_slots = PCI_SLOT_MAX - 1, .fixup_devtree = e500plat_fixup_devtree, .mpic_version = OPENPIC_MODEL_FSL_MPIC_42, + .has_platform_bus = true, + .platform_bus_base = 0xf00000000ULL, + .platform_bus_size = (128ULL * 1024 * 1024), + .platform_bus_first_irq = 5, + .platform_bus_num_irqs = 10, };/* Older KVM versions don't support EPR which breaks guests when we announce
@@ -51,6 +56,7 @@ static QEMUMachine e500plat_machine = { .desc = "generic paravirt e500 platform", .init = e500plat_init, .max_cpus = 32, + .has_dynamic_sysbus = true, };static void e500plat_machine_init (void )
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH v2 7/9] PPC: e500: Support dynamically spawned sysbus devices
hw/ppc/e500.c static qemu_irq *ppce500_init_mpic(PPCE500Params *params, MemoryRegion *ccsr, · line 808
Quoted 8 lines · Alexander Graf
For e500 our approach to supporting dynamically spawned sysbus devices is to create a simple bus from the guest's point of view within which we map those devices dynamically.
hw/ppc/e500.c +4
-0+/* Connect sysbus device to virtual platform bus */ +for (i =0 ; i < sbdev->num_irq; i++) { +if (!sbdev->irqp[i]) { +/* This IRQ is an incoming IRQ, we can't wire those here */
I don't understand this comment -- sysbus IRQs are all outbound by definition. Lines going in to a device are GPIOs. (Ideally we should get rid of "sysbus IRQs" completely and just use named inbound GPIOs for everything.)
Also, sbdev->irqp[] is private to the sysbus implementation, so you shouldn't be fishing about in it in the platform code.
thanks
-- PMM
Re: [Qemu-devel] [PATCH v2 7/9] PPC: e500: Support dynamically spawned sysbus devices
Quoted 10 lines · Peter Maydell
hw/ppc/e500.c static qemu_irq *ppce500_init_mpic(PPCE500Params *params, MemoryRegion *ccsr, · line 808
Quoted 8 lines · Alexander Graf
For e500 our approach to supporting dynamically spawned sysbus devices is to create a simple bus from the guest's point of view within which we map those devices dynamically.
hw/ppc/e500.c +4
-0+/* Connect sysbus device to virtual platform bus */ +for (i =0 ; i < sbdev->num_irq; i++) { +if (!sbdev->irqp[i]) { +/* This IRQ is an incoming IRQ, we can't wire those here */
Quoted 5 lines
I don't understand this comment -- sysbus IRQs are all outbound by definition. Lines going in to a device are GPIOs. (Ideally we should get rid of "sysbus IRQs" completely and just use named inbound GPIOs for everything.)
I have some patches in this area. Will post shortly cc you and Alex.
Quoted 3 lines
Also, sbdev->irqp[] is private to the sysbus implementation, so you shouldn't be fishing about in it in the platform code.
And this is in the crosshairs of that work:
@@ -47,8 +49,6 @@ struct SysBusDevice {
/*< public >*/
int num_irq;- qemu_irq irqs[QDEV_MAX_IRQ];
- qemu_irq *irqp[QDEV_MAX_IRQ];
Regards,
Peter
Quoted 3 lines
thanks
-- PMM
PATCH v2 8/9 e500: Add support for eTSEC in device tree
In reply to Alexander GrafThis patch adds support to expose eTSEC devices in the dynamically created guest facing device tree. This allows us to expose eTSEC devices into guests without changes in the machine file.
Because we can now tell the guest about eTSEC devices this patch allows the user to specify eTSEC devices via -device at all.
---
v1 -> v2:
- fix device name (base on reg for value after @)
- use qom properties to fetch mmio and irq props
- remove useless interrupt-parent
- make interrupts level triggered
--- hw/ppc/e500.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
hw/ppc/e500.c +37 -0
@@ -37,6 +37,7 @@#include "qemu/host-utils.h" #include "hw/pci-host/ppce500.h" #include "qemu/error-report.h" +#include "hw/net/fsl_etsec/etsec.h" #define EPAPR_MAGIC (0x45504150)#define BINARY_DEVICE_TREE_FILE "mpc8544ds.dtb"
@@ -132,6 +133,37 @@ typedef struct PlatformDevtreeData {const char *node; } PlatformDevtreeData; +static int create_devtree_etsec (eTSEC *etsec,PlatformDevtreeData *data) +{ +Object *obj =OBJECT (etsec); +uint64_t mmio0 =object_property_get_int (obj,"mmio[0]" ,NULL ); +uint64_t irq0 =object_property_get_int (obj,"irq[0]" ,NULL ); +uint64_t irq1 =object_property_get_int (obj,"irq[1]" ,NULL ); +uint64_t irq2 =object_property_get_int (obj,"irq[2]" ,NULL ); +gchar *node =g_strdup_printf ("/platform/ethernet@%" PRIx64, mmio0); +gchar *group =g_strdup_printf ("%s/queue-group" , node); +void *fdt = data->fdt; + +qemu_fdt_add_subnode (fdt, node); +qemu_fdt_setprop_string (fdt, node,"device_type" ,"network" ); +qemu_fdt_setprop_string (fdt, node,"compatible" ,"fsl,etsec2" ); +qemu_fdt_setprop_string (fdt, node,"model" ,"eTSEC" ); +qemu_fdt_setprop (fdt, node,"local-mac-address" , etsec->conf.macaddr.a,6 ); +qemu_fdt_setprop_cells (fdt, node,"fixed-link" ,0 ,1 ,1000 ,0 ,0 ); + +qemu_fdt_add_subnode (fdt, group); +qemu_fdt_setprop_cells (fdt, group,"reg" , mmio0,0x1000 ); +qemu_fdt_setprop_cells (fdt, group,"interrupts" , + data->irq_start + irq0,0x2 , + data->irq_start + irq1,0x2 , + data->irq_start + irq2,0x2 ); + +g_free (node); +g_free (group); + +return 0 ; +} +static int sysbus_device_create_devtree (Object *obj,void *opaque) {PlatformDevtreeData *data = opaque;
@@ -147,6 +179,11 @@ static int sysbus_device_create_devtree(Object *obj, void *opaque)return object_child_foreach (obj, sysbus_device_create_devtree, data); } +if (object_dynamic_cast (obj,TYPE_ETSEC_COMMON )) { +create_devtree_etsec (ETSEC_COMMON (dev), data); + matched = true; + } +if (!matched) {error_report ("Device %s is not supported by this machine yet." ,qdev_fw_name (DEVICE (dev)));
Signature · 1 line
1.8.1.4
PATCH v2 9/9 PPC: Fix default config ordering and add eTSEC for ppc64
In reply to Alexander GrafWe messed up the ordering in our default configs for PPC. The top entries are generic entries, then come sections that indicate that features are only in because of a special feature (such as PReP).
Fix the ordering again and while at it add eTSEC support to the ppc64 target so that we can spawn eTSEC adapters with qemu-system-ppc64.
--- default-configs/ppc-softmmu.mak | 4 ++-- default-configs/ppc64-softmmu.mak | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-)
default-configs/ppc-softmmu.mak +2 -2
@@ -45,8 +45,8 @@ CONFIG_PREP=y CONFIG_MAC=y CONFIG_E500=y CONFIG_OPENPIC_KVM=$(and $(CONFIG_E500),$(CONFIG_KVM)) +CONFIG_ETSEC=y +CONFIG_LIBDECNUMBER=y # For PReP CONFIG_MC146818RTC=y -CONFIG_ETSEC=y CONFIG_ISA_TESTDEV=y -CONFIG_LIBDECNUMBER=y
default-configs/ppc64-softmmu.mak +2 -1
@@ -46,6 +46,8 @@ CONFIG_PREP=y CONFIG_MAC=y CONFIG_E500=y CONFIG_OPENPIC_KVM=$(and $(CONFIG_E500),$(CONFIG_KVM)) +CONFIG_ETSEC=y +CONFIG_LIBDECNUMBER=y # For pSeries CONFIG_XICS=$(CONFIG_PSERIES) CONFIG_XICS_KVM=$(and $(CONFIG_PSERIES),$(CONFIG_KVM))
@@ -58,4 +60,3 @@ CONFIG_I82374=y CONFIG_I8257=y CONFIG_MC146818RTC=y CONFIG_ISA_TESTDEV=y -CONFIG_LIBDECNUMBER=y
Signature · 1 line
1.8.1.4