Skip to contentSkip to conversation

Make qdev static property API usable by any QOM type

PATCH Superseded Eduardo Habkost 3 participants 58 messages Nov 12, 2020 – Dec 11, 2020

Subsystems (10)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover Make qdev static property API usable by any QOM type

Based-on: [email protected]
Git branch: https://gitlab.com/ehabkost/qemu/-/commits/work/qdev-make-generic

This series refactor the qdev property code so the static property system from qdev becomes a common QOM API that can be used by any QOM type.

As an example, at the end of the series we use the new API at:
* check-qom-proplist unit test, to replace the hand-written getter and setter for the "sv" property
* target/i386/sev.c, to replace the instance properties registered using object_property_add_uint32_ptr()

I still want to make object_class_add_field_properties() the recommended interface for registering QOM properties, but this will be done in another series.

Changes v2 -> v3
----------------

* Patches were reordered

* New qom/qom.h header file
(See "qom: Add new qom.h header")

* Fixed memory leak in the array property refactor from v2 (See "qdev: Get rid of ArrayElementProperty struct")

* Made object_property_add_field() copy the Property struct passed as argument, to make the array property memory leak easier to fix
(See "qdev: Make object_property_add_field() copy the Property struct")

* Both object_class_add_field_properties() and object_class_property_add_field() functions are available, but only object_class_property_add_field() are made public by this series. object_class_add_field_properties() is used to implement device_class_set_props().
(See "qom: object_class_property_add_field() function" & "qdev: Separate generic and device-specific property registration")

* Now object_class_property_add_field() will get a copy of the Property struct, to avoid tricks involving static variables in the FIELD_PROP macro.
(See "qom: object_class_property_add_field() function")

* check-qom-proplist won't use object_property_add_field(), as it is an internal API and I don't want to make it a bad example to be followed.
(See "tests: Use field property at check-qom-proplist test case")

* Property.qdev_prop_name is now Property.name_template, because it might be used outside qdev in case we make object_class_add_field_properties() public.
(See "qdev: Rename Property.name to Property.name_template")

* New unit test for array property
(See "tests: Add unit test for qdev array properties")

* Include sev patch for using class properties instead of object_property_add_uint32_ptr()
(See "sev: Use class properties")

* FIELD_PROP macro is now inside field-property.h
(See "qom: FIELD_PROP macro")

* DEFINE_PROP_* macros are now defined using PROP_*, not the other way around
(See "qom: PROP_* macros")

Changes v1 -> v2
----------------

* Rename functions and source files to call the new feature "field property" instead of "static property"

* Change the API signature from an array-based interface similar to device_class_set_props() to a object_property_add()-like interface.

This means instead of doing this:

    object_class_property_add_static_props(oc, my_array_of_props);

properties are registered like this:

    object_class_property_add_field(oc, "property-name"
                                    PROP_XXX(MyState, my_field),
                                    prop_allow_set_always);

where PROP_XXX is a PROP_* macro like PROP_STRING, PROP_BOOL, etc.

* Make Property.name optional. Rename it to qdev_prop_name, and restrict its usage to qdev property tracking code.

* Make allow_set callback mandatory, to avoid ambiguity

* Big cleanup of array property code. We don't need a custom release function for array elements anymore, because we don't need to save the property name in the Property struct anymore.

* Moved UUID property to qdev-properties-system, because it still has dependencies on qdev code

Eduardo Habkost (53):
cs4231: Get rid of empty property array
cpu: Move cpu_common_props to hw/core/cpu.c
qdev: Move property code to qdev-properties.[ch]
qdev: Check dev->realized at set_size()
sparc: Check dev->realized at sparc_set_nwindows()
qdev: Don't use dev->id on set_size32() error message
qdev: Make PropertyInfo.print method get Object* argument
qdev: Make bit_prop_set() get Object* argument
qdev: Make qdev_get_prop_ptr() get Object* arg
qdev: Make qdev_find_global_prop() get Object* argument
qdev: Make check_prop_still_unset() get Object* argument
qdev: Make error_set_from_qdev_prop_error() get Object* argument
qdev: Make qdev_propinfo_get_uint16() static
qdev: Move UUID property to qdev-properties-system.c
qdev: Move softmmu properties to qdev-properties-system.h
qdev: Reuse DEFINE_PROP in all DEFINE_PROP_* macros
sparc: Use DEFINE_PROP for nwindows property
qdev: Get just property name at error_set_from_qdev_prop_error()
qdev: Avoid using prop->name unnecessarily
qdev: Add name parameter to qdev_class_add_property()
qdev: Add name argument to PropertyInfo.create method
qdev: Wrap getters and setters in separate helpers
qdev: Move dev->realized check to qdev_property_set()
qdev: Make PropertyInfo.create return ObjectProperty*
qdev: Make qdev_class_add_property() more flexible
qdev: Separate generic and device-specific property registration
qdev: Rename qdev_propinfo_* to field_prop_*
qdev: Move qdev_prop_tpm declaration to tpm_prop.h
qdev: Rename qdev_prop_* to prop_info_*
qdev: Rename qdev_get_prop_ptr() to object_field_prop_ptr()
qdev: Avoid unnecessary DeviceState* variable at set_prop_arraylen()
tests: Add unit test for qdev array properties
qom: Add allow_set callback to ObjectProperty
qdev: Make qdev_prop_allow_set() a ObjectProperty.allow_set callback
qdev: Rename Property.name to Property.name_template
qdev: Don't set .name_template for array elements
qdev: Remove ArrayElementProperty.propname field
qdev: Remove ArrayElementProperty.release field
qdev: Get rid of ArrayElementProperty struct
qdev: Rename array_element_release() to
static_prop_release_dynamic_prop()
qdev: Make object_property_add_field() copy the Property struct
qdev: Reuse object_property_add_field() when adding array elements
qdev: Move static_prop_release_dynamic_prop() closer to its usage
qom: Add new qom.h header
qdev: Move core field property code to QOM
qdev: Move base property types to qom/property-types.c
qom: Include static property API reference in documentation
qom: object_class_property_add_field() function
qom: FIELD_PROP macro
qom: Delete DEFINE_PROP_*SIGNED_NODEFAULT macro
qom: PROP_* macros
tests: Use field property at check-qom-proplist test case
sev: Use class properties

 docs/devel/qom.rst                    |  17 +-
 audio/audio.h                         |   1 +
 hw/core/qdev-prop-internal.h          |  30 -
 hw/tpm/tpm_prop.h                     |   2 +
 include/hw/block/block.h              |   1 +
 include/hw/core/cpu.h                 |   1 -
 include/hw/qdev-core.h                |  37 --
 include/hw/qdev-properties-system.h   |  77 +++
 include/hw/qdev-properties.h          | 244 +-------
 include/net/net.h                     |   1 +
 include/qom/field-property-internal.h |  80 +++
 include/qom/field-property.h          | 128 ++++
 include/qom/object.h                  |  38 ++
 include/qom/property-types.h          | 176 ++++++
 include/qom/qom.h                     |  12 +
 backends/tpm/tpm_util.c               |  16 +-
 cpu.c                                 |  15 -
 hw/acpi/vmgenid.c                     |   1 +
 hw/arm/pxa2xx.c                       |   1 +
 hw/arm/strongarm.c                    |   1 +
 hw/audio/cs4231.c                     |   5 -
 hw/block/fdc.c                        |   1 +
 hw/block/m25p80.c                     |   1 +
 hw/block/nand.c                       |   1 +
 hw/block/onenand.c                    |   1 +
 hw/block/pflash_cfi01.c               |   1 +
 hw/block/pflash_cfi02.c               |   1 +
 hw/block/vhost-user-blk.c             |   1 +
 hw/block/xen-block.c                  |  11 +-
 hw/char/avr_usart.c                   |   1 +
 hw/char/bcm2835_aux.c                 |   1 +
 hw/char/cadence_uart.c                |   1 +
 hw/char/cmsdk-apb-uart.c              |   1 +
 hw/char/debugcon.c                    |   1 +
 hw/char/digic-uart.c                  |   1 +
 hw/char/escc.c                        |   1 +
 hw/char/etraxfs_ser.c                 |   1 +
 hw/char/exynos4210_uart.c             |   1 +
 hw/char/grlib_apbuart.c               |   1 +
 hw/char/ibex_uart.c                   |   1 +
 hw/char/imx_serial.c                  |   1 +
 hw/char/ipoctal232.c                  |   1 +
 hw/char/lm32_juart.c                  |   1 +
 hw/char/lm32_uart.c                   |   1 +
 hw/char/mcf_uart.c                    |   1 +
 hw/char/milkymist-uart.c              |   1 +
 hw/char/nrf51_uart.c                  |   1 +
 hw/char/parallel.c                    |   1 +
 hw/char/pl011.c                       |   1 +
 hw/char/renesas_sci.c                 |   1 +
 hw/char/sclpconsole-lm.c              |   1 +
 hw/char/sclpconsole.c                 |   1 +
 hw/char/serial-pci-multi.c            |   1 +
 hw/char/serial.c                      |   1 +
 hw/char/spapr_vty.c                   |   1 +
 hw/char/stm32f2xx_usart.c             |   1 +
 hw/char/terminal3270.c                |   1 +
 hw/char/virtio-console.c              |   1 +
 hw/char/xilinx_uartlite.c             |   1 +
 hw/core/cpu.c                         |  15 +
 hw/core/qdev-properties-system.c      | 258 ++++-----
 hw/core/qdev-properties.c             | 806 +++-----------------------
 hw/core/qdev.c                        | 120 ----
 hw/hyperv/vmbus.c                     |   1 +
 hw/i386/kvm/i8254.c                   |   1 +
 hw/ide/qdev.c                         |   1 +
 hw/intc/arm_gicv3_common.c            |   2 +-
 hw/intc/rx_icu.c                      |   4 +-
 hw/ipmi/ipmi_bmc_extern.c             |   1 +
 hw/ipmi/ipmi_bmc_sim.c                |   1 +
 hw/misc/allwinner-sid.c               |   1 +
 hw/misc/arm_sysctl.c                  |   4 +-
 hw/misc/ivshmem.c                     |   1 +
 hw/misc/mac_via.c                     |   1 +
 hw/misc/sifive_u_otp.c                |   1 +
 hw/net/e1000e.c                       |   6 +-
 hw/net/rocker/rocker.c                |   1 +
 hw/nvram/eeprom_at24c.c               |   1 +
 hw/nvram/spapr_nvram.c                |   1 +
 hw/pci-bridge/gen_pcie_root_port.c    |   1 +
 hw/pci/pci.c                          |   1 +
 hw/ppc/pnv_pnor.c                     |   1 +
 hw/rdma/vmw/pvrdma_main.c             |   1 +
 hw/rtc/mc146818rtc.c                  |   1 +
 hw/s390x/css.c                        |  13 +-
 hw/s390x/s390-pci-bus.c               |  10 +-
 hw/scsi/scsi-disk.c                   |   1 +
 hw/scsi/scsi-generic.c                |   1 +
 hw/scsi/vhost-user-scsi.c             |   1 +
 hw/sd/sd.c                            |   1 +
 hw/usb/ccid-card-passthru.c           |   1 +
 hw/usb/dev-serial.c                   |   1 +
 hw/usb/redirect.c                     |   1 +
 hw/vfio/pci-quirks.c                  |  11 +-
 hw/vfio/pci.c                         |   7 +-
 hw/virtio/vhost-user-fs.c             |   1 +
 hw/virtio/vhost-user-vsock.c          |   1 +
 hw/virtio/virtio-iommu-pci.c          |   1 +
 hw/xen/xen_pt.c                       |   1 +
 migration/migration.c                 |   1 +
 qom/field-property.c                  | 151 +++++
 qom/object.c                          |  16 +
 qom/property-types.c                  | 546 +++++++++++++++++
 softmmu/qdev-monitor.c                |   9 +-
 target/arm/cpu.c                      |   6 +-
 target/i386/sev.c                     |  25 +-
 target/sparc/cpu.c                    |   5 +-
 tests/check-qom-proplist.c            |  39 +-
 tests/test-qdev-global-props.c        |  61 ++
 qom/meson.build                       |   2 +
 110 files changed, 1659 insertions(+), 1418 deletions(-)
 delete mode 100644 hw/core/qdev-prop-internal.h
 create mode 100644 include/hw/qdev-properties-system.h
 create mode 100644 include/qom/field-property-internal.h
 create mode 100644 include/qom/field-property.h
 create mode 100644 include/qom/property-types.h
 create mode 100644 include/qom/qom.h
 create mode 100644 qom/field-property.c
 create mode 100644 qom/property-types.c
Signature · 1 line
2.28.0
#1 lore raw

PATCH v3 1/53 cs4231: Get rid of empty property array

An empty props array is unnecessary, we can just not call device_class_set_props().

---
Cc: Gerd Hoffmann <[email protected]>
Cc: [email protected]

---
 hw/audio/cs4231.c | 5 -----
 1 file changed, 5 deletions(-)
hw/audio/cs4231.c +0 -5
index 8e9554ce9b..209c05a0a0 100644
@@ -160,17 +160,12 @@ static void cs4231_init(Object *obj)
     sysbus_init_irq(dev, &s->irq);
 }
 
-static Property cs4231_properties[] = {
-    {.name = NULL},
-};
-
 static void cs4231_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->reset = cs_reset;
     dc->vmsd = &vmstate_cs4231;
-    device_class_set_props(dc, cs4231_properties);
 }
 
 static const TypeInfo cs4231_info = {
Signature · 1 line
2.28.0
#2 lore raw

PATCH v3 2/53 cpu: Move cpu_common_props to hw/core/cpu.c

In reply to Eduardo Habkost

There's no reason to keep the property list separate from the CPU class code. Move the variable to hw/core/cpu.c and make it static.

---
Cc: Eduardo Habkost <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: [email protected]

---
 include/hw/core/cpu.h |  1 -
 cpu.c                 | 15 ---------------
 hw/core/cpu.c         | 15 +++++++++++++++
 3 files changed, 15 insertions(+), 16 deletions(-)
include/hw/core/cpu.h +0 -1
index 3d92c967ff..8e7552910d 100644
@@ -1111,7 +1111,6 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx);
 
 void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
     GCC_FMT_ATTR(2, 3);
-extern Property cpu_common_props[];
 void cpu_exec_initfn(CPUState *cpu);
 void cpu_exec_realizefn(CPUState *cpu, Error **errp);
 void cpu_exec_unrealizefn(CPUState *cpu);
cpu.c +0 -15
index 0be5dcb6f3..0c485cdf2d 100644
@@ -144,21 +144,6 @@ void cpu_exec_unrealizefn(CPUState *cpu)
 #endif
 }
 
-Property cpu_common_props[] = {
-#ifndef CONFIG_USER_ONLY
-    /* Create a memory property for softmmu CPU object,
-     * so users can wire up its memory. (This can't go in hw/core/cpu.c
-     * because that file is compiled only once for both user-mode
-     * and system builds.) The default if no link is set up is to use
-     * the system address space.
-     */
-    DEFINE_PROP_LINK("memory", CPUState, memory, TYPE_MEMORY_REGION,
-                     MemoryRegion *),
-#endif
-    DEFINE_PROP_BOOL("start-powered-off", CPUState, start_powered_off, false),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
 void cpu_exec_initfn(CPUState *cpu)
 {
     cpu->as = NULL;
hw/core/cpu.c +15 -0
index 576fa1d7ba..5c89c858aa 100644
@@ -393,6 +393,21 @@ static vaddr cpu_adjust_watchpoint_address(CPUState *cpu, vaddr addr, int len)
     return addr;
 }
 
+static Property cpu_common_props[] = {
+#ifndef CONFIG_USER_ONLY
+    /* Create a memory property for softmmu CPU object,
+     * so users can wire up its memory. (This can't go in hw/core/cpu.c
+     * because that file is compiled only once for both user-mode
+     * and system builds.) The default if no link is set up is to use
+     * the system address space.
+     */
+    DEFINE_PROP_LINK("memory", CPUState, memory, TYPE_MEMORY_REGION,
+                     MemoryRegion *),
+#endif
+    DEFINE_PROP_BOOL("start-powered-off", CPUState, start_powered_off, false),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void cpu_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
Signature · 1 line
2.28.0
#3 lore raw

PATCH v3 3/53 qdev: Move property code to qdev-properties.[ch]

In reply to Eduardo Habkost

Move everything related to Property and PropertyInfo to qdev-properties.[ch] to make it easier to refactor that code.

---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 include/hw/qdev-core.h       |  37 -----------
 include/hw/qdev-properties.h |  38 +++++++++++
 hw/core/qdev-properties.c    | 120 +++++++++++++++++++++++++++++++++++
 hw/core/qdev.c               | 120 -----------------------------------
 softmmu/qdev-monitor.c       |   1 +
 5 files changed, 159 insertions(+), 157 deletions(-)
include/hw/qdev-core.h +0 -37
index 5e737195b5..d75cf47145 100644
@@ -274,43 +274,6 @@ struct BusState {
     ResettableState reset;
 };
 
-/**
- * Property:
- * @set_default: true if the default value should be set from @defval,
- *    in which case @info->set_default_value must not be NULL
- *    (if false then no default value is set by the property system
- *     and the field retains whatever value it was given by instance_init).
- * @defval: default value for the property. This is used only if @set_default
- *     is true.
- */
-struct Property {
-    const char   *name;
-    const PropertyInfo *info;
-    ptrdiff_t    offset;
-    uint8_t      bitnr;
-    bool         set_default;
-    union {
-        int64_t i;
-        uint64_t u;
-    } defval;
-    int          arrayoffset;
-    const PropertyInfo *arrayinfo;
-    int          arrayfieldsize;
-    const char   *link_type;
-};
-
-struct PropertyInfo {
-    const char *name;
-    const char *description;
-    const QEnumLookup *enum_table;
-    int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
-    void (*set_default_value)(ObjectProperty *op, const Property *prop);
-    void (*create)(ObjectClass *oc, Property *prop);
-    ObjectPropertyAccessor *get;
-    ObjectPropertyAccessor *set;
-    ObjectPropertyRelease *release;
-};
-
 /**
  * GlobalProperty:
  * @used: Set to true if property was used when initializing a device.
include/hw/qdev-properties.h +38 -0
index 4437450065..db7ce51dd5 100644
@@ -3,6 +3,44 @@
 
 #include "hw/qdev-core.h"
 
+/**
+ * Property:
+ * @set_default: true if the default value should be set from @defval,
+ *    in which case @info->set_default_value must not be NULL
+ *    (if false then no default value is set by the property system
+ *     and the field retains whatever value it was given by instance_init).
+ * @defval: default value for the property. This is used only if @set_default
+ *     is true.
+ */
+struct Property {
+    const char   *name;
+    const PropertyInfo *info;
+    ptrdiff_t    offset;
+    uint8_t      bitnr;
+    bool         set_default;
+    union {
+        int64_t i;
+        uint64_t u;
+    } defval;
+    int          arrayoffset;
+    const PropertyInfo *arrayinfo;
+    int          arrayfieldsize;
+    const char   *link_type;
+};
+
+struct PropertyInfo {
+    const char *name;
+    const char *description;
+    const QEnumLookup *enum_table;
+    int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
+    void (*set_default_value)(ObjectProperty *op, const Property *prop);
+    void (*create)(ObjectClass *oc, Property *prop);
+    ObjectPropertyAccessor *get;
+    ObjectPropertyAccessor *set;
+    ObjectPropertyRelease *release;
+};
+
+
 /*** qdev-properties.c ***/
 
 extern const PropertyInfo qdev_prop_bit;
hw/core/qdev-properties.c +120 -0

123 lines not on this page · raw message

hw/core/qdev.c +0 -120

132 lines not on this page · raw message

softmmu/qdev-monitor.c +1 -0
index bcfb90a08f..79164e4a3f 100644
@@ -38,6 +38,7 @@
 #include "migration/misc.h"
 #include "migration/migration.h"
 #include "qemu/cutils.h"
+#include "hw/qdev-properties.h"
 #include "hw/clock.h"
 
 /*
Signature · 1 line
2.28.0
#4 lore raw

PATCH v3 4/53 qdev: Check dev->realized at set_size()

In reply to Eduardo Habkost

This setter is one of the very few property setters that don't check dev->realized, and there's no reason to make size properties different from the rest. Add the missing check.

Fixes e8cd45c78f53 ("qdev: Add SIZE type to qdev properties")

---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-properties.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/core/qdev-properties.c +5 -0
index 12a053e732..67ae19df05 100644
@@ -905,6 +905,11 @@ static void set_size(Object *obj, Visitor *v, const char *name, void *opaque,
     Property *prop = opaque;
     uint64_t *ptr = qdev_get_prop_ptr(dev, prop);
 
+    if (dev->realized) {
+        qdev_prop_set_after_realize(dev, name, errp);
+        return;
+    }
+
     visit_type_size(v, name, ptr, errp);
 }
 
Signature · 1 line
2.28.0
#5 lore raw

PATCH v3 5/53 sparc: Check dev->realized at sparc_set_nwindows()

In reply to Eduardo Habkost

sparc_set_nwindows() is one of the very few property setters that don't check dev->realized, and there's no reason for it to be special. Check dev->realized like the other setters.

---
Cc: Mark Cave-Ayland <[email protected]>
Cc: Artyom Tarasenko <[email protected]>
Cc: [email protected]

---
 target/sparc/cpu.c | 6 ++++++
 1 file changed, 6 insertions(+)
target/sparc/cpu.c +6 -0
index cf21efd85f..8ecb20e55f 100644
@@ -798,11 +798,17 @@ static void sparc_get_nwindows(Object *obj, Visitor *v, const char *name,
 static void sparc_set_nwindows(Object *obj, Visitor *v, const char *name,
                                void *opaque, Error **errp)
 {
+    DeviceState *dev = DEVICE(obj);
     const int64_t min = MIN_NWINDOWS;
     const int64_t max = MAX_NWINDOWS;
     SPARCCPU *cpu = SPARC_CPU(obj);
     int64_t value;
 
+    if (dev->realized) {
+        qdev_prop_set_after_realize(dev, name, errp);
+        return;
+    }
+
     if (!visit_type_int(v, name, &value, errp)) {
         return;
     }
Signature · 1 line
2.28.0
#6 lore raw

PATCH v3 6/53 qdev: Don't use dev->id on set_size32() error message

In reply to Eduardo Habkost

All other qdev property error messages use "<type>.<property>" instead of "<id>.<property>". Change set_size32() for consistency, and to make the code not specific to TYPE_DEVICE.

---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-properties.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/core/qdev-properties.c +1 -1
index 67ae19df05..daf844c2d3 100644
@@ -542,7 +542,7 @@ static void set_size32(Object *obj, Visitor *v, const char *name, void *opaque,
         error_setg(errp,
                    "Property %s.%s doesn't take value %" PRIu64
                    " (maximum: %u)",
-                   dev->id ? : "", name, value, UINT32_MAX);
+                   object_get_typename(obj), name, value, UINT32_MAX);
         return;
     }
 
Signature · 1 line
2.28.0
#7 lore raw

PATCH v3 7/53 qdev: Make PropertyInfo.print method get Object* argument

In reply to Eduardo Habkost

Make the code more generic and not specific to TYPE_DEVICE.

---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 include/hw/qdev-properties.h     | 2 +-
 hw/core/qdev-properties-system.c | 3 ++-
 hw/core/qdev-properties.c        | 3 +--
 3 files changed, 4 insertions(+), 4 deletions(-)
include/hw/qdev-properties.h +1 -1
index db7ce51dd5..0ea822e6a7 100644
@@ -32,7 +32,7 @@ struct PropertyInfo {
     const char *name;
     const char *description;
     const QEnumLookup *enum_table;
-    int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
+    int (*print)(Object *obj, Property *prop, char *dest, size_t len);
     void (*set_default_value)(ObjectProperty *op, const Property *prop);
     void (*create)(ObjectClass *oc, Property *prop);
     ObjectPropertyAccessor *get;
hw/core/qdev-properties-system.c +2 -1
index b81a4e8d14..d0fb063a49 100644
@@ -801,9 +801,10 @@ invalid:
     g_free(str);
 }
 
-static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest,
+static int print_pci_devfn(Object *obj, Property *prop, char *dest,
                            size_t len)
 {
+    DeviceState *dev = DEVICE(obj);
     int32_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (*ptr == -1) {
hw/core/qdev-properties.c +1 -2
index daf844c2d3..b6cf53e929 100644
@@ -988,13 +988,12 @@ static void qdev_get_legacy_property(Object *obj, Visitor *v,
                                      const char *name, void *opaque,
                                      Error **errp)
 {
-    DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
 
     char buffer[1024];
     char *ptr = buffer;
 
-    prop->info->print(dev, prop, buffer, sizeof(buffer));
+    prop->info->print(obj, prop, buffer, sizeof(buffer));
     visit_type_str(v, name, &ptr, errp);
 }
 
Signature · 1 line
2.28.0
#8 lore raw

PATCH v3 8/53 qdev: Make bit_prop_set() get Object* argument

In reply to Eduardo Habkost

Make the code more generic and not specific to TYPE_DEVICE.

---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-properties.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
hw/core/qdev-properties.c +6 -4
index b6cf53e929..3a4638f4de 100644
@@ -92,8 +92,9 @@ static uint32_t qdev_get_prop_mask(Property *prop)
     return 0x1 << prop->bitnr;
 }
 
-static void bit_prop_set(DeviceState *dev, Property *props, bool val)
+static void bit_prop_set(Object *obj, Property *props, bool val)
 {
+    DeviceState *dev = DEVICE(obj);
     uint32_t *p = qdev_get_prop_ptr(dev, props);
     uint32_t mask = qdev_get_prop_mask(props);
     if (val) {
@@ -129,7 +130,7 @@ static void prop_set_bit(Object *obj, Visitor *v, const char *name,
     if (!visit_type_bool(v, name, &value, errp)) {
         return;
     }
-    bit_prop_set(dev, prop, value);
+    bit_prop_set(obj, prop, value);
 }
 
 static void set_default_value_bool(ObjectProperty *op, const Property *prop)
@@ -153,8 +154,9 @@ static uint64_t qdev_get_prop_mask64(Property *prop)
     return 0x1ull << prop->bitnr;
 }
 
-static void bit64_prop_set(DeviceState *dev, Property *props, bool val)
+static void bit64_prop_set(Object *obj, Property *props, bool val)
 {
+    DeviceState *dev = DEVICE(obj);
     uint64_t *p = qdev_get_prop_ptr(dev, props);
     uint64_t mask = qdev_get_prop_mask64(props);
     if (val) {
@@ -190,7 +192,7 @@ static void prop_set_bit64(Object *obj, Visitor *v, const char *name,
     if (!visit_type_bool(v, name, &value, errp)) {
         return;
     }
-    bit64_prop_set(dev, prop, value);
+    bit64_prop_set(obj, prop, value);
 }
 
 const PropertyInfo qdev_prop_bit64 = {
Signature · 1 line
2.28.0
#9 lore raw

PATCH v3 9/53 qdev: Make qdev_get_prop_ptr() get Object* arg

In reply to Eduardo Habkost

Make the code more generic and not specific to TYPE_DEVICE.

---
Changes v1 -> v2:
- Fix build error with CONFIG_XEN
I took the liberty of keeping the Reviewed-by line from Marc-André as the build fix is a trivial one line change
---
Cc: Stefan Berger <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: Paul Durrant <[email protected]>
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Cornelia Huck <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Halil Pasic <[email protected]>
Cc: Christian Borntraeger <[email protected]>
Cc: Matthew Rosato <[email protected]>
Cc: Alex Williamson <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
 include/hw/qdev-properties.h     |  2 +-
 backends/tpm/tpm_util.c          |  8 ++--
 hw/block/xen-block.c             |  5 +-
 hw/core/qdev-properties-system.c | 57 +++++++++-------------
 hw/core/qdev-properties.c        | 82 +++++++++++++-------------------
 hw/s390x/css.c                   |  5 +-
 hw/s390x/s390-pci-bus.c          |  4 +-
 hw/vfio/pci-quirks.c             |  5 +-
 8 files changed, 68 insertions(+), 100 deletions(-)
include/hw/qdev-properties.h +1 -1
index 0ea822e6a7..0b92cfc761 100644
@@ -302,7 +302,7 @@ void qdev_prop_set_macaddr(DeviceState *dev, const char *name,
                            const uint8_t *value);
 void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
 
-void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
+void *qdev_get_prop_ptr(Object *obj, Property *prop);
 
 void qdev_prop_register_global(GlobalProperty *prop);
 const GlobalProperty *qdev_find_global_prop(DeviceState *dev,
backends/tpm/tpm_util.c +3 -5
index b58d298c1a..e91c21dd4a 100644
@@ -35,8 +35,7 @@
 static void get_tpm(Object *obj, Visitor *v, const char *name, void *opaque,
                     Error **errp)
 {
-    DeviceState *dev = DEVICE(obj);
-    TPMBackend **be = qdev_get_prop_ptr(dev, opaque);
+    TPMBackend **be = qdev_get_prop_ptr(obj, opaque);
     char *p;
 
     p = g_strdup(*be ? (*be)->id : "");
@@ -49,7 +48,7 @@ static void set_tpm(Object *obj, Visitor *v, const char *name, void *opaque,
 {
     DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
-    TPMBackend *s, **be = qdev_get_prop_ptr(dev, prop);
+    TPMBackend *s, **be = qdev_get_prop_ptr(obj, prop);
     char *str;
 
     if (dev->realized) {
@@ -73,9 +72,8 @@ static void set_tpm(Object *obj, Visitor *v, const char *name, void *opaque,
 
 static void release_tpm(Object *obj, const char *name, void *opaque)
 {
-    DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
-    TPMBackend **be = qdev_get_prop_ptr(dev, prop);
+    TPMBackend **be = qdev_get_prop_ptr(obj, prop);
 
     if (*be) {
         tpm_backend_reset(*be);
hw/block/xen-block.c +2 -3
index 8a7a3f5452..905e4acd97 100644
@@ -335,9 +335,8 @@ static char *disk_to_vbd_name(unsigned int disk)
 static void xen_block_get_vdev(Object *obj, Visitor *v, const char *name,
                                void *opaque, Error **errp)
 {
-    DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
-    XenBlockVdev *vdev = qdev_get_prop_ptr(dev, prop);
+    XenBlockVdev *vdev = qdev_get_prop_ptr(obj, prop);
     char *str;
 
     switch (vdev->type) {
@@ -398,7 +397,7 @@ static void xen_block_set_vdev(Object *obj, Visitor *v, const char *name,
 {
     DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
-    XenBlockVdev *vdev = qdev_get_prop_ptr(dev, prop);
+    XenBlockVdev *vdev = qdev_get_prop_ptr(obj, prop);
     char *str, *p;
     const char *end;
 
hw/core/qdev-properties-system.c +23 -34

204 lines not on this page · raw message

hw/core/qdev-properties.c +33 -49

288 lines not on this page · raw message

hw/s390x/css.c +2 -3
index 9961cfe7bf..2b8f33fec2 100644
@@ -2343,9 +2343,8 @@ void css_reset(void)
 static void get_css_devid(Object *obj, Visitor *v, const char *name,
                           void *opaque, Error **errp)
 {
-    DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
-    CssDevId *dev_id = qdev_get_prop_ptr(dev, prop);
+    CssDevId *dev_id = qdev_get_prop_ptr(obj, prop);
     char buffer[] = "xx.x.xxxx";
     char *p = buffer;
     int r;
@@ -2375,7 +2374,7 @@ static void set_css_devid(Object *obj, Visitor *v, const char *name,
 {
     DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
-    CssDevId *dev_id = qdev_get_prop_ptr(dev, prop);
+    CssDevId *dev_id = qdev_get_prop_ptr(obj, prop);
     char *str;
     int num, n1, n2;
     unsigned int cssid, ssid, devid;
hw/s390x/s390-pci-bus.c +2 -2
index 48a3be802f..ab27b6e848 100644
@@ -1323,7 +1323,7 @@ static void s390_pci_get_fid(Object *obj, Visitor *v, const char *name,
                          void *opaque, Error **errp)
 {
     Property *prop = opaque;
-    uint32_t *ptr = qdev_get_prop_ptr(DEVICE(obj), prop);
+    uint32_t *ptr = qdev_get_prop_ptr(obj, prop);
 
     visit_type_uint32(v, name, ptr, errp);
 }
@@ -1334,7 +1334,7 @@ static void s390_pci_set_fid(Object *obj, Visitor *v, const char *name,
     DeviceState *dev = DEVICE(obj);
     S390PCIBusDevice *zpci = S390_PCI_DEVICE(obj);
     Property *prop = opaque;
-    uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
+    uint32_t *ptr = qdev_get_prop_ptr(obj, prop);
 
     if (dev->realized) {
         qdev_prop_set_after_realize(dev, name, errp);
hw/vfio/pci-quirks.c +2 -3
index 57150913b7..53569925a2 100644
@@ -1488,9 +1488,8 @@ static void get_nv_gpudirect_clique_id(Object *obj, Visitor *v,
                                        const char *name, void *opaque,
                                        Error **errp)
 {
-    DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
-    uint8_t *ptr = qdev_get_prop_ptr(dev, prop);
+    uint8_t *ptr = qdev_get_prop_ptr(obj, prop);
 
     visit_type_uint8(v, name, ptr, errp);
 }
@@ -1501,7 +1500,7 @@ static void set_nv_gpudirect_clique_id(Object *obj, Visitor *v,
 {
     DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
-    uint8_t value, *ptr = qdev_get_prop_ptr(dev, prop);
+    uint8_t value, *ptr = qdev_get_prop_ptr(obj, prop);
 
     if (dev->realized) {
         qdev_prop_set_after_realize(dev, name, errp);
Signature · 1 line
2.28.0
Reviewed-by on v3 9/53
#10 lore raw

Re: [PATCH v3 09/53] qdev: Make qdev_get_prop_ptr() get Object* arg

Quoted 31 lines · On Thu, 12 Nov 2020 16:43:06 -0500 Eduardo Habkost <[email protected]> wrote:

Make the code more generic and not specific to TYPE_DEVICE.

---
Changes v1 -> v2:
- Fix build error with CONFIG_XEN
I took the liberty of keeping the Reviewed-by line from Marc-André as the build fix is a trivial one line change
---
Cc: Stefan Berger <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: Paul Durrant <[email protected]>
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Cornelia Huck <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Halil Pasic <[email protected]>
Cc: Christian Borntraeger <[email protected]>
Cc: Matthew Rosato <[email protected]>
Cc: Alex Williamson <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

Quoted 10 lines
---
 include/hw/qdev-properties.h     |  2 +-
 backends/tpm/tpm_util.c          |  8 ++--
 hw/block/xen-block.c             |  5 +-
 hw/core/qdev-properties-system.c | 57 +++++++++-------------
 hw/core/qdev-properties.c        | 82 +++++++++++++-------------------
 hw/s390x/css.c                   |  5 +-
 hw/s390x/s390-pci-bus.c          |  4 +-
 hw/vfio/pci-quirks.c             |  5 +-
 8 files changed, 68 insertions(+), 100 deletions(-)
#11 lore raw

PATCH v3 10/53 qdev: Make qdev_find_global_prop() get Object* argument

In reply to Eduardo Habkost

Make the code more generic and not specific to TYPE_DEVICE.

---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 include/hw/qdev-properties.h     | 2 +-
 hw/core/qdev-properties-system.c | 2 +-
 hw/core/qdev-properties.c        | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
include/hw/qdev-properties.h +1 -1
index 0b92cfc761..7620095fed 100644
@@ -305,7 +305,7 @@ void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
 void *qdev_get_prop_ptr(Object *obj, Property *prop);
 
 void qdev_prop_register_global(GlobalProperty *prop);
-const GlobalProperty *qdev_find_global_prop(DeviceState *dev,
+const GlobalProperty *qdev_find_global_prop(Object *obj,
                                             const char *name);
 int qdev_prop_check_globals(void);
 void qdev_prop_set_globals(DeviceState *dev);
hw/core/qdev-properties-system.c +1 -1
index c8c73c371b..af1339e562 100644
@@ -36,7 +36,7 @@ static bool check_prop_still_unset(DeviceState *dev, const char *name,
                                    const void *old_val, const char *new_val,
                                    Error **errp)
 {
-    const GlobalProperty *prop = qdev_find_global_prop(dev, name);
+    const GlobalProperty *prop = qdev_find_global_prop(OBJECT(dev), name);
 
     if (!old_val) {
         return true;
hw/core/qdev-properties.c +2 -2
index 0a54a922c8..41482d83d1 100644
@@ -818,7 +818,7 @@ void qdev_prop_register_global(GlobalProperty *prop)
     g_ptr_array_add(global_props(), prop);
 }
 
-const GlobalProperty *qdev_find_global_prop(DeviceState *dev,
+const GlobalProperty *qdev_find_global_prop(Object *obj,
                                             const char *name)
 {
     GPtrArray *props = global_props();
@@ -827,7 +827,7 @@ const GlobalProperty *qdev_find_global_prop(DeviceState *dev,
 
     for (i = 0; i < props->len; i++) {
         p = g_ptr_array_index(props, i);
-        if (object_dynamic_cast(OBJECT(dev), p->driver)
+        if (object_dynamic_cast(obj, p->driver)
             && !strcmp(p->property, name)) {
             return p;
         }
Signature · 1 line
2.28.0
#12 lore raw

PATCH v3 11/53 qdev: Make check_prop_still_unset() get Object* argument

In reply to Eduardo Habkost

Make the code more generic and not specific to TYPE_DEVICE.

---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-properties-system.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
hw/core/qdev-properties-system.c +5 -5
index af1339e562..85dd38db0f 100644
@@ -32,11 +32,11 @@
 #include "hw/pci/pci.h"
 #include "util/block-helpers.h"
 
-static bool check_prop_still_unset(DeviceState *dev, const char *name,
+static bool check_prop_still_unset(Object *obj, const char *name,
                                    const void *old_val, const char *new_val,
                                    Error **errp)
 {
-    const GlobalProperty *prop = qdev_find_global_prop(OBJECT(dev), name);
+    const GlobalProperty *prop = qdev_find_global_prop(obj, name);
 
     if (!old_val) {
         return true;
@@ -105,7 +105,7 @@ static void set_drive_helper(Object *obj, Visitor *v, const char *name,
      * TODO Should this really be an error?  If no, the old value
      * needs to be released before we store the new one.
      */
-    if (!check_prop_still_unset(dev, name, *ptr, str, errp)) {
+    if (!check_prop_still_unset(obj, name, *ptr, str, errp)) {
         return;
     }
 
@@ -247,7 +247,7 @@ static void set_chr(Object *obj, Visitor *v, const char *name, void *opaque,
      * TODO Should this really be an error?  If no, the old value
      * needs to be released before we store the new one.
      */
-    if (!check_prop_still_unset(dev, name, be->chr, str, errp)) {
+    if (!check_prop_still_unset(obj, name, be->chr, str, errp)) {
         return;
     }
 
@@ -429,7 +429,7 @@ static void set_netdev(Object *obj, Visitor *v, const char *name,
          * TODO Should this really be an error?  If no, the old value
          * needs to be released before we store the new one.
          */
-        if (!check_prop_still_unset(dev, name, ncs[i], str, errp)) {
+        if (!check_prop_still_unset(obj, name, ncs[i], str, errp)) {
             goto out;
         }
 
Signature · 1 line
2.28.0
#13 lore raw

PATCH v3 12/53 qdev: Make error_set_from_qdev_prop_error() get Object* argument

In reply to Eduardo Habkost

Make the code more generic and not specific to TYPE_DEVICE.

---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Cornelia Huck <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Halil Pasic <[email protected]>
Cc: Christian Borntraeger <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 include/hw/qdev-properties.h     |  2 +-
 hw/core/qdev-properties-system.c | 10 +++++-----
 hw/core/qdev-properties.c        | 10 +++++-----
 hw/s390x/css.c                   |  2 +-
 4 files changed, 12 insertions(+), 12 deletions(-)
include/hw/qdev-properties.h +1 -1
index 7620095fed..530286e869 100644
@@ -309,7 +309,7 @@ const GlobalProperty *qdev_find_global_prop(Object *obj,
                                             const char *name);
 int qdev_prop_check_globals(void);
 void qdev_prop_set_globals(DeviceState *dev);
-void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
+void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,
                                     Property *prop, const char *value);
 
 /**
hw/core/qdev-properties-system.c +5 -5
index 85dd38db0f..fca1b694ca 100644
@@ -352,7 +352,7 @@ static void set_mac(Object *obj, Visitor *v, const char *name, void *opaque,
     return;
 
 inval:
-    error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+    error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
     g_free(str);
 }
 
@@ -440,7 +440,7 @@ static void set_netdev(Object *obj, Visitor *v, const char *name,
     peers_ptr->queues = queues;
 
 out:
-    error_set_from_qdev_prop_error(errp, err, dev, prop, str);
+    error_set_from_qdev_prop_error(errp, err, obj, prop, str);
     g_free(str);
 }
 
@@ -492,7 +492,7 @@ static void set_audiodev(Object *obj, Visitor *v, const char* name,
     card->state = state;
 
 out:
-    error_set_from_qdev_prop_error(errp, err, dev, prop, str);
+    error_set_from_qdev_prop_error(errp, err, obj, prop, str);
     g_free(str);
 }
 
@@ -790,7 +790,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, const char *name,
     return;
 
 invalid:
-    error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+    error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
     g_free(str);
 }
 
@@ -913,7 +913,7 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
     return;
 
 inval:
-    error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+    error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
     g_free(str);
 }
 
hw/core/qdev-properties.c +5 -5
index 41482d83d1..5e010afdb8 100644
@@ -581,7 +581,7 @@ static void set_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
     if (!strcmp(str, UUID_VALUE_AUTO)) {
         qemu_uuid_generate(uuid);
     } else if (qemu_uuid_parse(str, uuid) < 0) {
-        error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+        error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
     }
     g_free(str);
 }
@@ -735,22 +735,22 @@ static Property *qdev_prop_find(DeviceState *dev, const char *name)
     return NULL;
 }
 
-void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
+void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,
                                     Property *prop, const char *value)
 {
     switch (ret) {
     case -EEXIST:
         error_setg(errp, "Property '%s.%s' can't take value '%s', it's in use",
-                  object_get_typename(OBJECT(dev)), prop->name, value);
+                  object_get_typename(obj), prop->name, value);
         break;
     default:
     case -EINVAL:
         error_setg(errp, QERR_PROPERTY_VALUE_BAD,
-                   object_get_typename(OBJECT(dev)), prop->name, value);
+                   object_get_typename(obj), prop->name, value);
         break;
     case -ENOENT:
         error_setg(errp, "Property '%s.%s' can't find value '%s'",
-                  object_get_typename(OBJECT(dev)), prop->name, value);
+                  object_get_typename(obj), prop->name, value);
         break;
     case 0:
         break;
hw/s390x/css.c +1 -1
index 2b8f33fec2..38fd46b9a9 100644
@@ -2390,7 +2390,7 @@ static void set_css_devid(Object *obj, Visitor *v, const char *name,
 
     num = sscanf(str, "%2x.%1x%n.%4x%n", &cssid, &ssid, &n1, &devid, &n2);
     if (num != 3 || (n2 - n1) != 5 || strlen(str) != n2) {
-        error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+        error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
         goto out;
     }
     if ((cssid > MAX_CSSID) || (ssid > MAX_SSID)) {
Signature · 1 line
2.28.0
Reviewed-by on v3 12/53
#14 lore raw

Re: [PATCH v3 12/53] qdev: Make error_set_from_qdev_prop_error() get Object* argument

Quoted 16 lines · On Thu, 12 Nov 2020 16:43:09 -0500 Eduardo Habkost <[email protected]> wrote:

Make the code more generic and not specific to TYPE_DEVICE.

---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Cornelia Huck <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Halil Pasic <[email protected]>
Cc: Christian Borntraeger <[email protected]>
Cc: [email protected]
Cc: [email protected]

Quoted 6 lines
---
 include/hw/qdev-properties.h     |  2 +-
 hw/core/qdev-properties-system.c | 10 +++++-----
 hw/core/qdev-properties.c        | 10 +++++-----
 hw/s390x/css.c                   |  2 +-
 4 files changed, 12 insertions(+), 12 deletions(-)
#15 lore raw

PATCH v3 13/53 qdev: Make qdev_propinfo_get_uint16() static

In reply to Eduardo Habkost

There are no users of the function outside qdev-properties.c. Make function static and rename it to get_uint16().

---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-prop-internal.h | 2 --
 hw/core/qdev-properties.c    | 6 +++---
 2 files changed, 3 insertions(+), 5 deletions(-)
hw/core/qdev-prop-internal.h +0 -2
index 9cf5cc1d51..d7b77844fe 100644
@@ -20,8 +20,6 @@ void qdev_propinfo_set_default_value_int(ObjectProperty *op,
 void qdev_propinfo_set_default_value_uint(ObjectProperty *op,
                                           const Property *prop);
 
-void qdev_propinfo_get_uint16(Object *obj, Visitor *v, const char *name,
-                              void *opaque, Error **errp);
 void qdev_propinfo_get_int32(Object *obj, Visitor *v, const char *name,
                              void *opaque, Error **errp);
 void qdev_propinfo_get_size32(Object *obj, Visitor *v, const char *name,
hw/core/qdev-properties.c +3 -3
index 5e010afdb8..765e916c23 100644
@@ -278,8 +278,8 @@ const PropertyInfo qdev_prop_uint8 = {
 
 /* --- 16bit integer --- */
 
-void qdev_propinfo_get_uint16(Object *obj, Visitor *v, const char *name,
-                              void *opaque, Error **errp)
+static void get_uint16(Object *obj, Visitor *v, const char *name,
+                       void *opaque, Error **errp)
 {
     Property *prop = opaque;
     uint16_t *ptr = qdev_get_prop_ptr(obj, prop);
@@ -304,7 +304,7 @@ static void set_uint16(Object *obj, Visitor *v, const char *name,
 
 const PropertyInfo qdev_prop_uint16 = {
     .name  = "uint16",
-    .get   = qdev_propinfo_get_uint16,
+    .get   = get_uint16,
     .set   = set_uint16,
     .set_default_value = qdev_propinfo_set_default_value_uint,
 };
Signature · 1 line
2.28.0
#16 lore raw

PATCH v3 14/53 qdev: Move UUID property to qdev-properties-system.c

In reply to Eduardo Habkost

Only softmmu code uses DEFINE_PROP_UUID, and it currently depends on error_set_from_qdev_prop_error(). Move it to qdev-properties-system.c to get out of our way when refactoring the qdev property system.

We can eventually move it back to the core property system later, after removing usage of error_set_from_qdev_prop_error().

---
This is a new patch added in series v2
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-properties-system.c | 57 ++++++++++++++++++++++++++++++++
 hw/core/qdev-properties.c        | 57 --------------------------------
 2 files changed, 57 insertions(+), 57 deletions(-)
hw/core/qdev-properties-system.c +57 -0
index fca1b694ca..35515886a9 100644
@@ -21,6 +21,7 @@
 #include "qemu/ctype.h"
 #include "qemu/cutils.h"
 #include "qemu/units.h"
+#include "qemu/uuid.h"
 #include "qemu/error-report.h"
 #include "qdev-prop-internal.h"
 
@@ -1105,3 +1106,59 @@ const PropertyInfo qdev_prop_pcie_link_width = {
     .set = set_prop_pcielinkwidth,
     .set_default_value = qdev_propinfo_set_default_value_enum,
 };
+
+/* --- UUID --- */
+
+static void get_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
+                     Error **errp)
+{
+    Property *prop = opaque;
+    QemuUUID *uuid = qdev_get_prop_ptr(obj, prop);
+    char buffer[UUID_FMT_LEN + 1];
+    char *p = buffer;
+
+    qemu_uuid_unparse(uuid, buffer);
+
+    visit_type_str(v, name, &p, errp);
+}
+
+#define UUID_VALUE_AUTO        "auto"
+
+static void set_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
+                    Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    QemuUUID *uuid = qdev_get_prop_ptr(obj, prop);
+    char *str;
+
+    if (dev->realized) {
+        qdev_prop_set_after_realize(dev, name, errp);
+        return;
+    }
+
+    if (!visit_type_str(v, name, &str, errp)) {
+        return;
+    }
+
+    if (!strcmp(str, UUID_VALUE_AUTO)) {
+        qemu_uuid_generate(uuid);
+    } else if (qemu_uuid_parse(str, uuid) < 0) {
+        error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
+    }
+    g_free(str);
+}
+
+static void set_default_uuid_auto(ObjectProperty *op, const Property *prop)
+{
+    object_property_set_default_str(op, UUID_VALUE_AUTO);
+}
+
+const PropertyInfo qdev_prop_uuid = {
+    .name  = "str",
+    .description = "UUID (aka GUID) or \"" UUID_VALUE_AUTO
+        "\" for random value (default)",
+    .get   = get_uuid,
+    .set   = set_uuid,
+    .set_default_value = set_default_uuid_auto,
+};
hw/core/qdev-properties.c +0 -57

69 lines not on this page · raw message

Signature · 1 line
2.28.0
#17 lore raw

PATCH v3 15/53 qdev: Move softmmu properties to qdev-properties-system.h

In reply to Eduardo Habkost

Move the property types and property macros implemented in qdev-properties-system.c to a new qdev-properties-system.h header.

---
Changes v1 -> v2:
* Move UUID property type too, as it was moved to
qdev-properties-system.c in the previous patch

---
 audio/audio.h                       |  1 +
 include/hw/block/block.h            |  1 +
 include/hw/qdev-properties-system.h | 84 +++++++++++++++++++++++++++++
 include/hw/qdev-properties.h        | 75 --------------------------
 include/net/net.h                   |  1 +
 hw/acpi/vmgenid.c                   |  1 +
 hw/arm/pxa2xx.c                     |  1 +
 hw/arm/strongarm.c                  |  1 +
 hw/block/fdc.c                      |  1 +
 hw/block/m25p80.c                   |  1 +
 hw/block/nand.c                     |  1 +
 hw/block/onenand.c                  |  1 +
 hw/block/pflash_cfi01.c             |  1 +
 hw/block/pflash_cfi02.c             |  1 +
 hw/block/vhost-user-blk.c           |  1 +
 hw/char/avr_usart.c                 |  1 +
 hw/char/bcm2835_aux.c               |  1 +
 hw/char/cadence_uart.c              |  1 +
 hw/char/cmsdk-apb-uart.c            |  1 +
 hw/char/debugcon.c                  |  1 +
 hw/char/digic-uart.c                |  1 +
 hw/char/escc.c                      |  1 +
 hw/char/etraxfs_ser.c               |  1 +
 hw/char/exynos4210_uart.c           |  1 +
 hw/char/grlib_apbuart.c             |  1 +
 hw/char/ibex_uart.c                 |  1 +
 hw/char/imx_serial.c                |  1 +
 hw/char/ipoctal232.c                |  1 +
 hw/char/lm32_juart.c                |  1 +
 hw/char/lm32_uart.c                 |  1 +
 hw/char/mcf_uart.c                  |  1 +
 hw/char/milkymist-uart.c            |  1 +
 hw/char/nrf51_uart.c                |  1 +
 hw/char/parallel.c                  |  1 +
 hw/char/pl011.c                     |  1 +
 hw/char/renesas_sci.c               |  1 +
 hw/char/sclpconsole-lm.c            |  1 +
 hw/char/sclpconsole.c               |  1 +
 hw/char/serial-pci-multi.c          |  1 +
 hw/char/serial.c                    |  1 +
 hw/char/spapr_vty.c                 |  1 +
 hw/char/stm32f2xx_usart.c           |  1 +
 hw/char/terminal3270.c              |  1 +
 hw/char/virtio-console.c            |  1 +
 hw/char/xilinx_uartlite.c           |  1 +
 hw/core/qdev-properties-system.c    |  1 +
 hw/hyperv/vmbus.c                   |  1 +
 hw/i386/kvm/i8254.c                 |  1 +
 hw/ide/qdev.c                       |  1 +
 hw/ipmi/ipmi_bmc_extern.c           |  1 +
 hw/ipmi/ipmi_bmc_sim.c              |  1 +
 hw/misc/allwinner-sid.c             |  1 +
 hw/misc/ivshmem.c                   |  1 +
 hw/misc/mac_via.c                   |  1 +
 hw/misc/sifive_u_otp.c              |  1 +
 hw/net/rocker/rocker.c              |  1 +
 hw/nvram/eeprom_at24c.c             |  1 +
 hw/nvram/spapr_nvram.c              |  1 +
 hw/pci-bridge/gen_pcie_root_port.c  |  1 +
 hw/pci/pci.c                        |  1 +
 hw/ppc/pnv_pnor.c                   |  1 +
 hw/rdma/vmw/pvrdma_main.c           |  1 +
 hw/rtc/mc146818rtc.c                |  1 +
 hw/scsi/scsi-disk.c                 |  1 +
 hw/scsi/scsi-generic.c              |  1 +
 hw/scsi/vhost-user-scsi.c           |  1 +
 hw/sd/sd.c                          |  1 +
 hw/usb/ccid-card-passthru.c         |  1 +
 hw/usb/dev-serial.c                 |  1 +
 hw/usb/redirect.c                   |  1 +
 hw/vfio/pci.c                       |  1 +
 hw/virtio/vhost-user-fs.c           |  1 +
 hw/virtio/vhost-user-vsock.c        |  1 +
 hw/virtio/virtio-iommu-pci.c        |  1 +
 hw/xen/xen_pt.c                     |  1 +
 migration/migration.c               |  1 +
 76 files changed, 158 insertions(+), 75 deletions(-)
 create mode 100644 include/hw/qdev-properties-system.h
audio/audio.h +1 -0
index b883ebfb1f..21fe3226ae 100644
@@ -28,6 +28,7 @@
 #include "qemu/queue.h"
 #include "qapi/qapi-types-audio.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 
 typedef void (*audio_callback_fn) (void *opaque, int avail);
 
include/hw/block/block.h +1 -0
index 1e8b6253dd..c172cbe65f 100644
@@ -13,6 +13,7 @@
 
 #include "exec/hwaddr.h"
 #include "qapi/qapi-types-block-core.h"
+#include "hw/qdev-properties-system.h"
 
 /* Configuration */
 
include/hw/qdev-properties-system.h new file +84 -0

84 lines not on this page · raw message

include/hw/qdev-properties.h +0 -75

98 lines not on this page · raw message

include/net/net.h +1 -0
index 897b2d7595..da48bc8254 100644
@@ -4,6 +4,7 @@
 #include "qemu/queue.h"
 #include "qapi/qapi-types-net.h"
 #include "net/queue.h"
+#include "hw/qdev-properties-system.h"
 
 #define MAC_FMT "%02X:%02X:%02X:%02X:%02X:%02X"
 #define MAC_ARG(x) ((uint8_t *)(x))[0], ((uint8_t *)(x))[1], \
hw/acpi/vmgenid.c +1 -0
index 2c8152d508..6c92fdae49 100644
@@ -19,6 +19,7 @@
 #include "hw/acpi/vmgenid.h"
 #include "hw/nvram/fw_cfg.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "migration/vmstate.h"
 #include "sysemu/reset.h"
 
hw/arm/pxa2xx.c +1 -0
index 591776ba88..9c8030a271 100644
@@ -21,6 +21,7 @@
 #include "hw/i2c/i2c.h"
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/ssi/ssi.h"
 #include "hw/sd/sd.h"
 #include "chardev/char-fe.h"
hw/arm/strongarm.c +1 -0
index ca7c385f31..c7ca54bcea 100644
@@ -33,6 +33,7 @@
 #include "hw/boards.h"
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/sysbus.h"
 #include "migration/vmstate.h"
 #include "strongarm.h"
hw/block/fdc.c +1 -0
index 4c2c35e223..3636874432 100644
@@ -36,6 +36,7 @@
 #include "hw/irq.h"
 #include "hw/isa/isa.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/sysbus.h"
 #include "migration/vmstate.h"
 #include "hw/block/block.h"
hw/block/m25p80.c +1 -0
index 483925f57a..0ef7f00cb6 100644
@@ -25,6 +25,7 @@
 #include "qemu/units.h"
 #include "sysemu/block-backend.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/ssi/ssi.h"
 #include "migration/vmstate.h"
 #include "qemu/bitops.h"
hw/block/nand.c +1 -0
index bcceb64ebb..5558f5d2fa 100644
@@ -21,6 +21,7 @@
 #include "qemu/osdep.h"
 #include "hw/hw.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/block/flash.h"
 #include "sysemu/block-backend.h"
 #include "migration/vmstate.h"
hw/block/onenand.c +1 -0
index 5ff7be86bb..579a73d7f7 100644
@@ -24,6 +24,7 @@
 #include "hw/block/flash.h"
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "sysemu/block-backend.h"
 #include "exec/memory.h"
 #include "hw/sysbus.h"
hw/block/pflash_cfi01.c +1 -0
index f0fcd63f84..90baa72f82 100644
@@ -40,6 +40,7 @@
 #include "hw/block/block.h"
 #include "hw/block/flash.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "sysemu/block-backend.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
hw/block/pflash_cfi02.c +1 -0
index eb02fccfa5..e2d8a004fe 100644
@@ -36,6 +36,7 @@
 #include "hw/block/block.h"
 #include "hw/block/flash.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "qemu/bitmap.h"
hw/block/vhost-user-blk.c +1 -0
index 2dd3d93ca0..da4fbf9084 100644
@@ -22,6 +22,7 @@
 #include "qemu/cutils.h"
 #include "hw/qdev-core.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/virtio/vhost.h"
 #include "hw/virtio/vhost-user-blk.h"
 #include "hw/virtio/virtio.h"
hw/char/avr_usart.c +1 -0
index fbe2a112b7..5bcf9db0b7 100644
@@ -24,6 +24,7 @@
 #include "qemu/log.h"
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 
 static int avr_usart_can_receive(void *opaque)
 {
hw/char/bcm2835_aux.c +1 -0
index dade2ab5fd..96410b1ff8 100644
@@ -24,6 +24,7 @@
 #include "hw/char/bcm2835_aux.h"
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "migration/vmstate.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
hw/char/cadence_uart.c +1 -0
index e196906c92..c603e14012 100644
@@ -32,6 +32,7 @@
 #include "hw/char/cadence_uart.h"
 #include "hw/irq.h"
 #include "hw/qdev-clock.h"
+#include "hw/qdev-properties-system.h"
 #include "trace.h"
 
 #ifdef CADENCE_UART_ERR_DEBUG
hw/char/cmsdk-apb-uart.c +1 -0
index 626b68f2ec..ba2cbbee3d 100644
@@ -27,6 +27,7 @@
 #include "chardev/char-serial.h"
 #include "hw/char/cmsdk-apb-uart.h"
 #include "hw/irq.h"
+#include "hw/qdev-properties-system.h"
 
 REG32(DATA, 0)
 REG32(STATE, 4)
hw/char/debugcon.c +1 -0
index 2a063ad72c..fdb04fee09 100644
@@ -30,6 +30,7 @@
 #include "chardev/char-fe.h"
 #include "hw/isa/isa.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "qom/object.h"
 
 #define TYPE_ISA_DEBUGCON_DEVICE "isa-debugcon"
hw/char/digic-uart.c +1 -0
index e130cb4692..00e5df5517 100644
@@ -35,6 +35,7 @@
 
 #include "hw/char/digic-uart.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 
 enum {
     ST_RX_RDY = (1 << 0),
hw/char/escc.c +1 -0
index 7d16ee8688..52e7978287 100644
@@ -25,6 +25,7 @@
 #include "qemu/osdep.h"
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/sysbus.h"
 #include "migration/vmstate.h"
 #include "qemu/module.h"
hw/char/etraxfs_ser.c +1 -0
index d9fba2ae6c..6bee3ee18e 100644
@@ -25,6 +25,7 @@
 #include "qemu/osdep.h"
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/sysbus.h"
 #include "chardev/char-fe.h"
 #include "qemu/log.h"
hw/char/exynos4210_uart.c +1 -0
index 96afe3580f..6361df2ad3 100644
@@ -32,6 +32,7 @@
 #include "hw/arm/exynos4210.h"
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 
 #include "trace.h"
 #include "qom/object.h"
hw/char/grlib_apbuart.c +1 -0
index 3f80f6824e..82ff40a530 100644
@@ -25,6 +25,7 @@
 #include "qemu/osdep.h"
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/sparc/grlib.h"
 #include "hw/sysbus.h"
 #include "qemu/module.h"
hw/char/ibex_uart.c +1 -0
index cc49a35013..89f1182c9b 100644
@@ -30,6 +30,7 @@
 #include "hw/irq.h"
 #include "hw/qdev-clock.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "migration/vmstate.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
hw/char/imx_serial.c +1 -0
index 731b8fc64c..ee1375e26d 100644
@@ -22,6 +22,7 @@
 #include "hw/char/imx_serial.h"
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "migration/vmstate.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
hw/char/ipoctal232.c +1 -0
index ad000a39b9..3311e0872c 100644
@@ -12,6 +12,7 @@
 #include "hw/ipack/ipack.h"
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "migration/vmstate.h"
 #include "qemu/bitops.h"
 #include "qemu/module.h"
hw/char/lm32_juart.c +1 -0
index b97aacba91..c5ead05e08 100644
@@ -26,6 +26,7 @@
 
 #include "hw/char/lm32_juart.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "qom/object.h"
 
 enum {
hw/char/lm32_uart.c +1 -0
index 0e8b4e46a3..5cb87de548 100644
@@ -25,6 +25,7 @@
 #include "qemu/osdep.h"
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/sysbus.h"
 #include "migration/vmstate.h"
 #include "trace.h"
hw/char/mcf_uart.c +1 -0
index e6814faffb..6fa4ac502c 100644
@@ -13,6 +13,7 @@
 #include "qapi/error.h"
 #include "hw/m68k/mcf.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "chardev/char-fe.h"
 #include "qom/object.h"
 
hw/char/milkymist-uart.c +1 -0
index 1e83dbcafa..09e2f6bd76 100644
@@ -24,6 +24,7 @@
 #include "qemu/osdep.h"
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/sysbus.h"
 #include "migration/vmstate.h"
 #include "trace.h"
hw/char/nrf51_uart.c +1 -0
index d1fef77acd..045ca5fa40 100644
@@ -18,6 +18,7 @@
 #include "hw/char/nrf51_uart.h"
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "migration/vmstate.h"
 #include "trace.h"
 
hw/char/parallel.c +1 -0
index 8b418abf71..b45e67bfbb 100644
@@ -32,6 +32,7 @@
 #include "hw/irq.h"
 #include "hw/isa/isa.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "migration/vmstate.h"
 #include "hw/char/parallel.h"
 #include "sysemu/reset.h"
hw/char/pl011.c +1 -0
index ede16c781c..ea4a4e5235 100644
@@ -23,6 +23,7 @@
 #include "hw/irq.h"
 #include "hw/sysbus.h"
 #include "hw/qdev-clock.h"
+#include "hw/qdev-properties-system.h"
 #include "migration/vmstate.h"
 #include "chardev/char-fe.h"
 #include "qemu/log.h"
hw/char/renesas_sci.c +1 -0
index 5d7c6e6523..1c63467290 100644
@@ -26,6 +26,7 @@
 #include "hw/irq.h"
 #include "hw/registerfields.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/char/renesas_sci.h"
 #include "migration/vmstate.h"
 
hw/char/sclpconsole-lm.c +1 -0
index 81f6d0ed4f..b9e9b2d453 100644
@@ -23,6 +23,7 @@
 #include "migration/vmstate.h"
 #include "hw/s390x/event-facility.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/s390x/ebcdic.h"
 #include "qom/object.h"
 
hw/char/sclpconsole.c +1 -0
index aa72ab40b9..c36b572222 100644
@@ -20,6 +20,7 @@
 #include "hw/s390x/sclp.h"
 #include "migration/vmstate.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/s390x/event-facility.h"
 #include "chardev/char-fe.h"
 #include "qom/object.h"
hw/char/serial-pci-multi.c +1 -0
index 2cf3e44177..3a9f96c2d1 100644
@@ -33,6 +33,7 @@
 #include "hw/irq.h"
 #include "hw/pci/pci.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "migration/vmstate.h"
 
 #define PCI_SERIAL_MAX_PORTS 4
hw/char/serial.c +1 -0
index 97f71879ff..d99daa7695 100644
@@ -35,6 +35,7 @@
 #include "qemu/error-report.h"
 #include "trace.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 
 #define UART_LCR_DLAB	0x80	/* Divisor latch access bit */
 
hw/char/spapr_vty.c +1 -0
index e726d4d915..79eaa2fa52 100644
@@ -8,6 +8,7 @@
 #include "hw/ppc/spapr.h"
 #include "hw/ppc/spapr_vio.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "qom/object.h"
 
 #define VTERM_BUFSIZE   16
hw/char/stm32f2xx_usart.c +1 -0
index 0d661be6d3..8df0832424 100644
@@ -26,6 +26,7 @@
 #include "hw/char/stm32f2xx_usart.h"
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
 
hw/char/terminal3270.c +1 -0
index d77981bb6d..a9a46c8ed3 100644
@@ -16,6 +16,7 @@
 #include "qemu/module.h"
 #include "chardev/char-fe.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/s390x/3270-ccw.h"
 #include "qom/object.h"
 
hw/char/virtio-console.c +1 -0
index bc752cf90f..6b132caa29 100644
@@ -16,6 +16,7 @@
 #include "qemu/module.h"
 #include "trace.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/virtio/virtio-serial.h"
 #include "qapi/error.h"
 #include "qapi/qapi-events-char.h"
hw/char/xilinx_uartlite.c +1 -0
index 2e773ec4c4..99b9a6f851 100644
@@ -26,6 +26,7 @@
 #include "qemu/log.h"
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/sysbus.h"
 #include "qemu/module.h"
 #include "chardev/char-fe.h"
hw/core/qdev-properties-system.c +1 -0
index 35515886a9..a05150bfd0 100644
@@ -12,6 +12,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "qapi/error.h"
 #include "qapi/visitor.h"
 #include "qapi/qapi-types-block.h"
hw/hyperv/vmbus.c +1 -0
index 896e981f85..984caf898d 100644
@@ -13,6 +13,7 @@
 #include "qapi/error.h"
 #include "migration/vmstate.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/hyperv/hyperv.h"
 #include "hw/hyperv/vmbus.h"
 #include "hw/hyperv/vmbus-bridge.h"
hw/i386/kvm/i8254.c +1 -0
index 40d84734e7..c73254e886 100644
@@ -32,6 +32,7 @@
 #include "sysemu/runstate.h"
 #include "hw/timer/i8254.h"
 #include "hw/timer/i8254_internal.h"
+#include "hw/qdev-properties-system.h"
 #include "sysemu/kvm.h"
 #include "qom/object.h"
 
hw/ide/qdev.c +1 -0
index 27ff1f7f66..73499a6235 100644
@@ -26,6 +26,7 @@
 #include "qemu/module.h"
 #include "hw/ide/internal.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "hw/block/block.h"
hw/ipmi/ipmi_bmc_extern.c +1 -0
index c3f3306e66..e141a5cd45 100644
@@ -35,6 +35,7 @@
 #include "chardev/char-fe.h"
 #include "hw/ipmi/ipmi.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "migration/vmstate.h"
 #include "qom/object.h"
 
hw/ipmi/ipmi_bmc_sim.c +1 -0
index f78e92d3d5..55fb81fa5a 100644
@@ -30,6 +30,7 @@
 #include "qemu/module.h"
 #include "hw/loader.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "migration/vmstate.h"
 
 #define IPMI_NETFN_CHASSIS            0x00
hw/misc/allwinner-sid.c +1 -0
index 196380c33a..6d61f55b1d 100644
@@ -26,6 +26,7 @@
 #include "qemu/guest-random.h"
 #include "qapi/error.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/misc/allwinner-sid.h"
 #include "trace.h"
 
hw/misc/ivshmem.c +1 -0
index e321e5cb69..0505b52c98 100644
@@ -23,6 +23,7 @@
 #include "qemu/cutils.h"
 #include "hw/pci/pci.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/pci/msi.h"
 #include "hw/pci/msix.h"
 #include "sysemu/kvm.h"
hw/misc/mac_via.c +1 -0
index 6db62dab7d..488d086a17 100644
@@ -28,6 +28,7 @@
 #include "qapi/error.h"
 #include "qemu/cutils.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "sysemu/block-backend.h"
 #include "trace.h"
 #include "qemu/log.h"
hw/misc/sifive_u_otp.c +1 -0
index 60066375ab..4401787a5c 100644
@@ -21,6 +21,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/sysbus.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
hw/net/rocker/rocker.c +1 -0
index 1af1e6fa2f..0fb8db1dee 100644
@@ -18,6 +18,7 @@
 #include "qemu/osdep.h"
 #include "hw/pci/pci.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "migration/vmstate.h"
 #include "hw/pci/msix.h"
 #include "net/net.h"
hw/nvram/eeprom_at24c.c +1 -0
index 3e93dbbffb..af6f5dbb99 100644
@@ -13,6 +13,7 @@
 #include "qemu/module.h"
 #include "hw/i2c/i2c.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "sysemu/block-backend.h"
 #include "qom/object.h"
 
hw/nvram/spapr_nvram.c +1 -0
index fc53a42572..9e51bc82ae 100644
@@ -39,6 +39,7 @@
 #include "hw/ppc/spapr.h"
 #include "hw/ppc/spapr_vio.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "qom/object.h"
 
 struct SpaprNvram {
hw/pci-bridge/gen_pcie_root_port.c +1 -0
index 8931afc049..ec9907917e 100644
@@ -16,6 +16,7 @@
 #include "hw/pci/msix.h"
 #include "hw/pci/pcie_port.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "migration/vmstate.h"
 #include "qom/object.h"
 
hw/pci/pci.c +1 -0
index 0131d9d02c..ad2fa1eea2 100644
@@ -30,6 +30,7 @@
 #include "hw/pci/pci_bus.h"
 #include "hw/pci/pci_host.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "migration/qemu-file-types.h"
 #include "migration/vmstate.h"
 #include "monitor/monitor.h"
hw/ppc/pnv_pnor.c +1 -0
index c365ee58b8..ef8dff03e0 100644
@@ -17,6 +17,7 @@
 #include "hw/loader.h"
 #include "hw/ppc/pnv_pnor.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 
 static uint64_t pnv_pnor_read(void *opaque, hwaddr addr, unsigned size)
 {
hw/rdma/vmw/pvrdma_main.c +1 -0
index 77b1235a3f..8593570332 100644
@@ -21,6 +21,7 @@
 #include "hw/pci/msi.h"
 #include "hw/pci/msix.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "cpu.h"
 #include "trace.h"
 #include "monitor/monitor.h"
hw/rtc/mc146818rtc.c +1 -0
index 7a38540cb9..5d0fcacd0c 100644
@@ -30,6 +30,7 @@
 #include "hw/acpi/aml-build.h"
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "qemu/timer.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/replay.h"
hw/scsi/scsi-disk.c +1 -0
index e859534eaf..f9a591cd17 100644
@@ -34,6 +34,7 @@
 #include "sysemu/blockdev.h"
 #include "hw/block/block.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "sysemu/dma.h"
 #include "sysemu/sysemu.h"
 #include "qemu/cutils.h"
hw/scsi/scsi-generic.c +1 -0
index 2cb23ca891..9740f7e36a 100644
@@ -19,6 +19,7 @@
 #include "hw/scsi/scsi.h"
 #include "migration/qemu-file-types.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/scsi/emulation.h"
 #include "sysemu/block-backend.h"
 #include "trace.h"
hw/scsi/vhost-user-scsi.c +1 -0
index 7c0631656c..4666019442 100644
@@ -21,6 +21,7 @@
 #include "hw/fw-path-provider.h"
 #include "hw/qdev-core.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/virtio/vhost.h"
 #include "hw/virtio/vhost-backend.h"
 #include "hw/virtio/vhost-user-scsi.h"
hw/sd/sd.c +1 -0
index 3091382614..fa07398c8c 100644
@@ -42,6 +42,7 @@
 #include "qapi/error.h"
 #include "qemu/bitmap.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "qemu/error-report.h"
 #include "qemu/timer.h"
 #include "qemu/log.h"
hw/usb/ccid-card-passthru.c +1 -0
index e8e9d37e88..c27c602697 100644
@@ -14,6 +14,7 @@
 #include <libcacard.h>
 #include "chardev/char-fe.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "migration/vmstate.h"
 #include "qemu/error-report.h"
 #include "qemu/module.h"
hw/usb/dev-serial.c +1 -0
index 19e1933f04..b58c4eb908 100644
@@ -14,6 +14,7 @@
 #include "qemu/error-report.h"
 #include "qemu/module.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/usb.h"
 #include "migration/vmstate.h"
 #include "desc.h"
hw/usb/redirect.c +1 -0
index 3238de6bb8..0b7e0e15f4 100644
@@ -42,6 +42,7 @@
 #include <usbredirfilter.h>
 
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/usb.h"
 #include "migration/qemu-file-types.h"
 #include "migration/vmstate.h"
hw/vfio/pci.c +1 -0
index 58c0ce8971..edfaed8c9a 100644
@@ -27,6 +27,7 @@
 #include "hw/pci/msix.h"
 #include "hw/pci/pci_bridge.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "migration/vmstate.h"
 #include "qemu/error-report.h"
 #include "qemu/main-loop.h"
hw/virtio/vhost-user-fs.c +1 -0
index 1bc5d03a00..ed036ad9c1 100644
@@ -16,6 +16,7 @@
 #include "standard-headers/linux/virtio_fs.h"
 #include "qapi/error.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-access.h"
 #include "qemu/error-report.h"
hw/virtio/vhost-user-vsock.c +1 -0
index 3534a39d62..a6f08c26b9 100644
@@ -13,6 +13,7 @@
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/virtio/vhost-user-vsock.h"
 
 static const int user_feature_bits[] = {
hw/virtio/virtio-iommu-pci.c +1 -0
index 378f63b210..770c286be7 100644
@@ -14,6 +14,7 @@
 #include "virtio-pci.h"
 #include "hw/virtio/virtio-iommu.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "qapi/error.h"
 #include "hw/boards.h"
 #include "qom/object.h"
hw/xen/xen_pt.c +1 -0
index 6d359ee486..3cbd08b10e 100644
@@ -58,6 +58,7 @@
 
 #include "hw/pci/pci.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "hw/xen/xen.h"
 #include "hw/i386/pc.h"
 #include "hw/xen/xen-legacy-backend.h"
migration/migration.c +1 -0
index 3263aa55a9..68c8c715fa 100644
@@ -52,6 +52,7 @@
 #include "migration/colo.h"
 #include "hw/boards.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "monitor/monitor.h"
 #include "net/announce.h"
 #include "qemu/queue.h"
Signature · 1 line
2.28.0
#18 lore raw

PATCH v3 16/53 qdev: Reuse DEFINE_PROP in all DEFINE_PROP_* macros

In reply to Eduardo Habkost

Instead of duplicating the code that sets name, info, offset, and does type checking, make DEFINE_PROP accept a variable number of arguments and reuse it in all DEFINE_PROP_* macros.

---
Changes v1 -> v2:
* Redone after UUID property was moved
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 include/hw/qdev-properties-system.h |  19 ++---
 include/hw/qdev-properties.h        | 114 ++++++++++------------------
 2 files changed, 46 insertions(+), 87 deletions(-)
include/hw/qdev-properties-system.h +6 -13
index 29529dc999..0ac327ae60 100644
@@ -63,22 +63,15 @@ extern const PropertyInfo qdev_prop_pcie_link_width;
     DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pcie_link_width, \
                         PCIExpLinkWidth)
 
-#define DEFINE_PROP_UUID(_name, _state, _field) {                  \
-        .name      = (_name),                                      \
-        .info      = &qdev_prop_uuid,                              \
-        .offset    = offsetof(_state, _field)                      \
-            + type_check(QemuUUID, typeof_field(_state, _field)),  \
-        .set_default = true,                                       \
-        }
+#define DEFINE_PROP_UUID(_name, _state, _field) \
+    DEFINE_PROP(_name, _state, _field, qdev_prop_uuid, QemuUUID, \
+                .set_default = true)
+
 #define DEFINE_PROP_AUDIODEV(_n, _s, _f) \
     DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, QEMUSoundCard)
 
-#define DEFINE_PROP_UUID_NODEFAULT(_name, _state, _field) {        \
-        .name      = (_name),                                      \
-        .info      = &qdev_prop_uuid,                              \
-        .offset    = offsetof(_state, _field)                      \
-            + type_check(QemuUUID, typeof_field(_state, _field)),  \
-        }
+#define DEFINE_PROP_UUID_NODEFAULT(_name, _state, _field) \
+    DEFINE_PROP(_name, _state, _field, qdev_prop_uuid, QemuUUID)
 
 
 #endif
include/hw/qdev-properties.h +40 -74

139 lines not on this page · raw message

Signature · 1 line
2.28.0
#19 lore raw

PATCH v3 17/53 sparc: Use DEFINE_PROP for nwindows property

In reply to Eduardo Habkost

Use the DEFINE_PROP macro (which will set extra fields in the struct) instead of initializing a Property struct manually.

---
This is a new patch added in v2 of the series
---
Cc: Mark Cave-Ayland <[email protected]>
Cc: Artyom Tarasenko <[email protected]>
Cc: [email protected]

---
 target/sparc/cpu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/sparc/cpu.c +2 -1
index 8ecb20e55f..f5cff4103b 100644
@@ -848,7 +848,8 @@ static Property sparc_cpu_properties[] = {
                          qdev_prop_uint64, target_ulong),
     DEFINE_PROP_UINT32("fpu-version", SPARCCPU, env.def.fpu_version, 0),
     DEFINE_PROP_UINT32("mmu-version", SPARCCPU, env.def.mmu_version, 0),
-    { .name  = "nwindows", .info  = &qdev_prop_nwindows },
+    DEFINE_PROP("nwindows",     SPARCCPU, env.def.nwindows,
+                qdev_prop_nwindows, uint32_t),
     DEFINE_PROP_END_OF_LIST()
 };
 
Signature · 1 line
2.28.0
#20 lore raw

PATCH v3 18/53 qdev: Get just property name at error_set_from_qdev_prop_error()

In reply to Eduardo Habkost

Replace Property *prop parameter with char *name, to reduce dependency of getter and setter functions on the Property struct (which will be changed in following patches).

---
This is a new patch added in series v2
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Cornelia Huck <[email protected]>
Cc: Halil Pasic <[email protected]>
Cc: Christian Borntraeger <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 include/hw/qdev-properties.h     |  2 +-
 hw/core/qdev-properties-system.c | 12 ++++++------
 hw/core/qdev-properties.c        |  8 ++++----
 hw/s390x/css.c                   |  2 +-
 4 files changed, 12 insertions(+), 12 deletions(-)
include/hw/qdev-properties.h +1 -1
index 1b58e4f922..476737b9da 100644
@@ -201,7 +201,7 @@ const GlobalProperty *qdev_find_global_prop(Object *obj,
 int qdev_prop_check_globals(void);
 void qdev_prop_set_globals(DeviceState *dev);
 void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,
-                                    Property *prop, const char *value);
+                                    const char *name, const char *value);
 
 /**
  * qdev_property_add_static:
hw/core/qdev-properties-system.c +6 -6
index a05150bfd0..808e7136a0 100644
@@ -354,7 +354,7 @@ static void set_mac(Object *obj, Visitor *v, const char *name, void *opaque,
     return;
 
 inval:
-    error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
+    error_set_from_qdev_prop_error(errp, EINVAL, obj, name, str);
     g_free(str);
 }
 
@@ -442,7 +442,7 @@ static void set_netdev(Object *obj, Visitor *v, const char *name,
     peers_ptr->queues = queues;
 
 out:
-    error_set_from_qdev_prop_error(errp, err, obj, prop, str);
+    error_set_from_qdev_prop_error(errp, err, obj, name, str);
     g_free(str);
 }
 
@@ -494,7 +494,7 @@ static void set_audiodev(Object *obj, Visitor *v, const char* name,
     card->state = state;
 
 out:
-    error_set_from_qdev_prop_error(errp, err, obj, prop, str);
+    error_set_from_qdev_prop_error(errp, err, obj, name, str);
     g_free(str);
 }
 
@@ -792,7 +792,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, const char *name,
     return;
 
 invalid:
-    error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
+    error_set_from_qdev_prop_error(errp, EINVAL, obj, name, str);
     g_free(str);
 }
 
@@ -915,7 +915,7 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
     return;
 
 inval:
-    error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
+    error_set_from_qdev_prop_error(errp, EINVAL, obj, name, str);
     g_free(str);
 }
 
@@ -1145,7 +1145,7 @@ static void set_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
     if (!strcmp(str, UUID_VALUE_AUTO)) {
         qemu_uuid_generate(uuid);
     } else if (qemu_uuid_parse(str, uuid) < 0) {
-        error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
+        error_set_from_qdev_prop_error(errp, EINVAL, obj, name, str);
     }
     g_free(str);
 }
hw/core/qdev-properties.c +4 -4
index a2eaa43831..7495798a66 100644
@@ -679,21 +679,21 @@ static Property *qdev_prop_find(DeviceState *dev, const char *name)
 }
 
 void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,
-                                    Property *prop, const char *value)
+                                    const char *name, const char *value)
 {
     switch (ret) {
     case -EEXIST:
         error_setg(errp, "Property '%s.%s' can't take value '%s', it's in use",
-                  object_get_typename(obj), prop->name, value);
+                  object_get_typename(obj), name, value);
         break;
     default:
     case -EINVAL:
         error_setg(errp, QERR_PROPERTY_VALUE_BAD,
-                   object_get_typename(obj), prop->name, value);
+                   object_get_typename(obj), name, value);
         break;
     case -ENOENT:
         error_setg(errp, "Property '%s.%s' can't find value '%s'",
-                  object_get_typename(obj), prop->name, value);
+                  object_get_typename(obj), name, value);
         break;
     case 0:
         break;
hw/s390x/css.c +1 -1
index 38fd46b9a9..7a44320d12 100644
@@ -2390,7 +2390,7 @@ static void set_css_devid(Object *obj, Visitor *v, const char *name,
 
     num = sscanf(str, "%2x.%1x%n.%4x%n", &cssid, &ssid, &n1, &devid, &n2);
     if (num != 3 || (n2 - n1) != 5 || strlen(str) != n2) {
-        error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
+        error_set_from_qdev_prop_error(errp, EINVAL, obj, name, str);
         goto out;
     }
     if ((cssid > MAX_CSSID) || (ssid > MAX_SSID)) {
Signature · 1 line
2.28.0
#21 lore raw

PATCH v3 19/53 qdev: Avoid using prop->name unnecessarily

In reply to Eduardo Habkost

We already get the property name as argument to the property getter and setters, we don't need to use prop->name. This will make it easier to remove the Property.name field in the future.

---
This is a new patch added in series v2
---
Cc: Stefan Berger <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 backends/tpm/tpm_util.c          |  2 +-
 hw/core/qdev-properties-system.c | 14 +++++++-------
 hw/core/qdev-properties.c        |  4 ++--
 3 files changed, 10 insertions(+), 10 deletions(-)
backends/tpm/tpm_util.c +1 -1
index e91c21dd4a..dba2f6b04a 100644
@@ -63,7 +63,7 @@ static void set_tpm(Object *obj, Visitor *v, const char *name, void *opaque,
     s = qemu_find_tpm_be(str);
     if (s == NULL) {
         error_setg(errp, "Property '%s.%s' can't find value '%s'",
-                   object_get_typename(obj), prop->name, str);
+                   object_get_typename(obj), name, str);
     } else if (tpm_backend_init(s, TPM_IF(obj), errp) == 0) {
         *be = s; /* weak reference, avoid cyclic ref */
     }
hw/core/qdev-properties-system.c +7 -7
index 808e7136a0..202abd0e4b 100644
@@ -141,7 +141,7 @@ static void set_drive_helper(Object *obj, Visitor *v, const char *name,
     }
     if (!blk) {
         error_setg(errp, "Property '%s.%s' can't find value '%s'",
-                   object_get_typename(OBJECT(dev)), prop->name, str);
+                   object_get_typename(OBJECT(dev)), name, str);
         goto fail;
     }
     if (blk_attach_dev(blk, dev) < 0) {
@@ -262,10 +262,10 @@ static void set_chr(Object *obj, Visitor *v, const char *name, void *opaque,
     s = qemu_chr_find(str);
     if (s == NULL) {
         error_setg(errp, "Property '%s.%s' can't find value '%s'",
-                   object_get_typename(obj), prop->name, str);
+                   object_get_typename(obj), name, str);
     } else if (!qemu_chr_fe_init(be, s, errp)) {
         error_prepend(errp, "Property '%s.%s' can't take value '%s': ",
-                      object_get_typename(obj), prop->name, str);
+                      object_get_typename(obj), name, str);
     }
     g_free(str);
 }
@@ -965,7 +965,7 @@ static void get_prop_pcielinkspeed(Object *obj, Visitor *v, const char *name,
         abort();
     }
 
-    visit_type_enum(v, prop->name, &speed, prop->info->enum_table, errp);
+    visit_type_enum(v, name, &speed, prop->info->enum_table, errp);
 }
 
 static void set_prop_pcielinkspeed(Object *obj, Visitor *v, const char *name,
@@ -981,7 +981,7 @@ static void set_prop_pcielinkspeed(Object *obj, Visitor *v, const char *name,
         return;
     }
 
-    if (!visit_type_enum(v, prop->name, &speed, prop->info->enum_table,
+    if (!visit_type_enum(v, name, &speed, prop->info->enum_table,
                          errp)) {
         return;
     }
@@ -1050,7 +1050,7 @@ static void get_prop_pcielinkwidth(Object *obj, Visitor *v, const char *name,
         abort();
     }
 
-    visit_type_enum(v, prop->name, &width, prop->info->enum_table, errp);
+    visit_type_enum(v, name, &width, prop->info->enum_table, errp);
 }
 
 static void set_prop_pcielinkwidth(Object *obj, Visitor *v, const char *name,
@@ -1066,7 +1066,7 @@ static void set_prop_pcielinkwidth(Object *obj, Visitor *v, const char *name,
         return;
     }
 
-    if (!visit_type_enum(v, prop->name, &width, prop->info->enum_table,
+    if (!visit_type_enum(v, name, &width, prop->info->enum_table,
                          errp)) {
         return;
     }
hw/core/qdev-properties.c +2 -2
index 7495798a66..50734a1cd4 100644
@@ -50,7 +50,7 @@ void qdev_propinfo_get_enum(Object *obj, Visitor *v, const char *name,
     Property *prop = opaque;
     int *ptr = qdev_get_prop_ptr(obj, prop);
 
-    visit_type_enum(v, prop->name, ptr, prop->info->enum_table, errp);
+    visit_type_enum(v, name, ptr, prop->info->enum_table, errp);
 }
 
 void qdev_propinfo_set_enum(Object *obj, Visitor *v, const char *name,
@@ -65,7 +65,7 @@ void qdev_propinfo_set_enum(Object *obj, Visitor *v, const char *name,
         return;
     }
 
-    visit_type_enum(v, prop->name, ptr, prop->info->enum_table, errp);
+    visit_type_enum(v, name, ptr, prop->info->enum_table, errp);
 }
 
 void qdev_propinfo_set_default_value_enum(ObjectProperty *op,
Signature · 1 line
2.28.0
#22 lore raw

PATCH v3 20/53 qdev: Add name parameter to qdev_class_add_property()

In reply to Eduardo Habkost

This will make it easier to remove Property.name in the future.

---
This is a new patch added in series v2
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-properties.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
hw/core/qdev-properties.c +5 -4
index 50734a1cd4..457c7fe4ba 100644
@@ -887,7 +887,8 @@ void qdev_property_add_static(DeviceState *dev, Property *prop)
     }
 }
 
-static void qdev_class_add_property(DeviceClass *klass, Property *prop)
+static void qdev_class_add_property(DeviceClass *klass, const char *name,
+                                    Property *prop)
 {
     ObjectClass *oc = OBJECT_CLASS(klass);
 
@@ -897,7 +898,7 @@ static void qdev_class_add_property(DeviceClass *klass, Property *prop)
         ObjectProperty *op;
 
         op = object_class_property_add(oc,
-                                       prop->name, prop->info->name,
+                                       name, prop->info->name,
                                        prop->info->get, prop->info->set,
                                        prop->info->release,
                                        prop);
@@ -905,7 +906,7 @@ static void qdev_class_add_property(DeviceClass *klass, Property *prop)
             prop->info->set_default_value(op, prop);
         }
     }
-    object_class_property_set_description(oc, prop->name,
+    object_class_property_set_description(oc, name,
                                           prop->info->description);
 }
 
@@ -962,7 +963,7 @@ void device_class_set_props(DeviceClass *dc, Property *props)
     dc->props_ = props;
     for (prop = props; prop && prop->name; prop++) {
         qdev_class_add_legacy_property(dc, prop);
-        qdev_class_add_property(dc, prop);
+        qdev_class_add_property(dc, prop->name, prop);
     }
 }
 
Signature · 1 line
2.28.0
#23 lore raw

PATCH v3 21/53 qdev: Add name argument to PropertyInfo.create method

In reply to Eduardo Habkost

This will make it easier to remove the Property.name field in the future.

---
This is a new patch added in series v2
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 include/hw/qdev-properties.h | 2 +-
 hw/core/qdev-properties.c    | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)
include/hw/qdev-properties.h +1 -1
index 476737b9da..ab9c538ba4 100644
@@ -34,7 +34,7 @@ struct PropertyInfo {
     const QEnumLookup *enum_table;
     int (*print)(Object *obj, Property *prop, char *dest, size_t len);
     void (*set_default_value)(ObjectProperty *op, const Property *prop);
-    void (*create)(ObjectClass *oc, Property *prop);
+    void (*create)(ObjectClass *oc, const char *name, Property *prop);
     ObjectPropertyAccessor *get;
     ObjectPropertyAccessor *set;
     ObjectPropertyRelease *release;
hw/core/qdev-properties.c +4 -3
index 457c7fe4ba..c68a20695d 100644
@@ -851,9 +851,10 @@ const PropertyInfo qdev_prop_size = {
 
 /* --- object link property --- */
 
-static void create_link_property(ObjectClass *oc, Property *prop)
+static void create_link_property(ObjectClass *oc, const char *name,
+                                 Property *prop)
 {
-    object_class_property_add_link(oc, prop->name, prop->link_type,
+    object_class_property_add_link(oc, name, prop->link_type,
                                    prop->offset,
                                    qdev_prop_allow_set_link_before_realize,
                                    OBJ_PROP_LINK_STRONG);
@@ -893,7 +894,7 @@ static void qdev_class_add_property(DeviceClass *klass, const char *name,
     ObjectClass *oc = OBJECT_CLASS(klass);
 
     if (prop->info->create) {
-        prop->info->create(oc, prop);
+        prop->info->create(oc, name, prop);
     } else {
         ObjectProperty *op;
 
Signature · 1 line
2.28.0
#24 lore raw

PATCH v3 22/53 qdev: Wrap getters and setters in separate helpers

In reply to Eduardo Habkost

We'll add extra code to the qdev property getters and setters, so add wrapper functions where additional actions can be performed.

The new functions have a "field_prop_" prefix instead of "qdev_" because the code will eventually be moved outside qdev-properties.c, to common QOM code.

---
Changes v1 -> v2:
* Redone after changes in previous patches in the series
* Renamed functions from static_prop_* to field_prop_*
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-properties.c | 44 +++++++++++++++++++++++++++++++++++----
 1 file changed, 40 insertions(+), 4 deletions(-)
hw/core/qdev-properties.c +40 -4
index c68a20695d..b924f13d58 100644
@@ -44,6 +44,40 @@ void *qdev_get_prop_ptr(Object *obj, Property *prop)
     return ptr;
 }
 
+static void field_prop_get(Object *obj, Visitor *v, const char *name,
+                           void *opaque, Error **errp)
+{
+    Property *prop = opaque;
+    return prop->info->get(obj, v, name, opaque, errp);
+}
+
+/**
+ * field_prop_getter: Return getter function to be used for property
+ *
+ * Return value can be NULL if @info has no getter function.
+ */
+static ObjectPropertyAccessor *field_prop_getter(const PropertyInfo *info)
+{
+    return info->get ? field_prop_get : NULL;
+}
+
+static void field_prop_set(Object *obj, Visitor *v, const char *name,
+                           void *opaque, Error **errp)
+{
+    Property *prop = opaque;
+    return prop->info->set(obj, v, name, opaque, errp);
+}
+
+/**
+ * field_prop_setter: Return setter function to be used for property
+ *
+ * Return value can be NULL if @info has not setter function.
+ */
+static ObjectPropertyAccessor *field_prop_setter(const PropertyInfo *info)
+{
+    return info->set ? field_prop_set : NULL;
+}
+
 void qdev_propinfo_get_enum(Object *obj, Visitor *v, const char *name,
                             void *opaque, Error **errp)
 {
@@ -630,8 +664,8 @@ static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
         assert(qdev_get_prop_ptr(obj, &arrayprop->prop) == eltptr);
         object_property_add(obj, propname,
                             arrayprop->prop.info->name,
-                            arrayprop->prop.info->get,
-                            arrayprop->prop.info->set,
+                            field_prop_getter(arrayprop->prop.info),
+                            field_prop_setter(arrayprop->prop.info),
                             array_element_release,
                             arrayprop);
     }
@@ -873,7 +907,8 @@ void qdev_property_add_static(DeviceState *dev, Property *prop)
     assert(!prop->info->create);
 
     op = object_property_add(obj, prop->name, prop->info->name,
-                             prop->info->get, prop->info->set,
+                             field_prop_getter(prop->info),
+                             field_prop_setter(prop->info),
                              prop->info->release,
                              prop);
 
@@ -900,7 +935,8 @@ static void qdev_class_add_property(DeviceClass *klass, const char *name,
 
         op = object_class_property_add(oc,
                                        name, prop->info->name,
-                                       prop->info->get, prop->info->set,
+                                       field_prop_getter(prop->info),
+                                       field_prop_setter(prop->info),
                                        prop->info->release,
                                        prop);
         if (prop->set_default) {
Signature · 1 line
2.28.0
#25 lore raw

PATCH v3 23/53 qdev: Move dev->realized check to qdev_property_set()

In reply to Eduardo Habkost

Every single qdev property setter function manually checks dev->realized. We can just check dev->realized inside qdev_property_set() instead.

The check is being added as a separate function (qdev_prop_allow_set()) because it will become a callback later.

---
Changes v1 -> v2:
* Removed unused variable at xen_block_set_vdev()
* Redone patch after changes in the previous patches in the series
---
Cc: Stefan Berger <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: Paul Durrant <[email protected]>
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Cornelia Huck <[email protected]>
Cc: Halil Pasic <[email protected]>
Cc: Christian Borntraeger <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Matthew Rosato <[email protected]>
Cc: Alex Williamson <[email protected]>
Cc: Mark Cave-Ayland <[email protected]>
Cc: Artyom Tarasenko <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
 backends/tpm/tpm_util.c          |   6 --
 hw/block/xen-block.c             |   6 --
 hw/core/qdev-properties-system.c |  70 ----------------------
 hw/core/qdev-properties.c        | 100 ++++++-------------------------
 hw/s390x/css.c                   |   6 --
 hw/s390x/s390-pci-bus.c          |   6 --
 hw/vfio/pci-quirks.c             |   6 --
 target/sparc/cpu.c               |   6 --
 8 files changed, 18 insertions(+), 188 deletions(-)
backends/tpm/tpm_util.c +0 -6
index dba2f6b04a..0b07cf55ea 100644
@@ -46,16 +46,10 @@ static void get_tpm(Object *obj, Visitor *v, const char *name, void *opaque,
 static void set_tpm(Object *obj, Visitor *v, const char *name, void *opaque,
                     Error **errp)
 {
-    DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
     TPMBackend *s, **be = qdev_get_prop_ptr(obj, prop);
     char *str;
 
-    if (dev->realized) {
-        qdev_prop_set_after_realize(dev, name, errp);
-        return;
-    }
-
     if (!visit_type_str(v, name, &str, errp)) {
         return;
     }
hw/block/xen-block.c +0 -6
index 905e4acd97..bd1aef63a7 100644
@@ -395,17 +395,11 @@ static int vbd_name_to_disk(const char *name, const char **endp,
 static void xen_block_set_vdev(Object *obj, Visitor *v, const char *name,
                                void *opaque, Error **errp)
 {
-    DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
     XenBlockVdev *vdev = qdev_get_prop_ptr(obj, prop);
     char *str, *p;
     const char *end;
 
-    if (dev->realized) {
-        qdev_prop_set_after_realize(dev, name, errp);
-        return;
-    }
-
     if (!visit_type_str(v, name, &str, errp)) {
         return;
     }
hw/core/qdev-properties-system.c +0 -70

194 lines not on this page · raw message

hw/core/qdev-properties.c +18 -82

237 lines not on this page · raw message

hw/s390x/css.c +0 -6
index 7a44320d12..496e2c5801 100644
@@ -2372,18 +2372,12 @@ static void get_css_devid(Object *obj, Visitor *v, const char *name,
 static void set_css_devid(Object *obj, Visitor *v, const char *name,
                           void *opaque, Error **errp)
 {
-    DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
     CssDevId *dev_id = qdev_get_prop_ptr(obj, prop);
     char *str;
     int num, n1, n2;
     unsigned int cssid, ssid, devid;
 
-    if (dev->realized) {
-        qdev_prop_set_after_realize(dev, name, errp);
-        return;
-    }
-
     if (!visit_type_str(v, name, &str, errp)) {
         return;
     }
hw/s390x/s390-pci-bus.c +0 -6
index ab27b6e848..54fac3851d 100644
@@ -1331,16 +1331,10 @@ static void s390_pci_get_fid(Object *obj, Visitor *v, const char *name,
 static void s390_pci_set_fid(Object *obj, Visitor *v, const char *name,
                          void *opaque, Error **errp)
 {
-    DeviceState *dev = DEVICE(obj);
     S390PCIBusDevice *zpci = S390_PCI_DEVICE(obj);
     Property *prop = opaque;
     uint32_t *ptr = qdev_get_prop_ptr(obj, prop);
 
-    if (dev->realized) {
-        qdev_prop_set_after_realize(dev, name, errp);
-        return;
-    }
-
     if (!visit_type_uint32(v, name, ptr, errp)) {
         return;
     }
hw/vfio/pci-quirks.c +0 -6
index 53569925a2..802979635c 100644
@@ -1498,15 +1498,9 @@ static void set_nv_gpudirect_clique_id(Object *obj, Visitor *v,
                                        const char *name, void *opaque,
                                        Error **errp)
 {
-    DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
     uint8_t value, *ptr = qdev_get_prop_ptr(obj, prop);
 
-    if (dev->realized) {
-        qdev_prop_set_after_realize(dev, name, errp);
-        return;
-    }
-
     if (!visit_type_uint8(v, name, &value, errp)) {
         return;
     }
target/sparc/cpu.c +0 -6
index f5cff4103b..3375fffb38 100644
@@ -798,17 +798,11 @@ static void sparc_get_nwindows(Object *obj, Visitor *v, const char *name,
 static void sparc_set_nwindows(Object *obj, Visitor *v, const char *name,
                                void *opaque, Error **errp)
 {
-    DeviceState *dev = DEVICE(obj);
     const int64_t min = MIN_NWINDOWS;
     const int64_t max = MAX_NWINDOWS;
     SPARCCPU *cpu = SPARC_CPU(obj);
     int64_t value;
 
-    if (dev->realized) {
-        qdev_prop_set_after_realize(dev, name, errp);
-        return;
-    }
-
     if (!visit_type_int(v, name, &value, errp)) {
         return;
     }
Signature · 1 line
2.28.0
#26 lore raw

PATCH v3 24/53 qdev: Make PropertyInfo.create return ObjectProperty*

In reply to Eduardo Habkost

Returning ObjectProperty* will be useful for new property registration code that will add additional callbacks to ObjectProperty after registering it.

---
Changes v1 -> v2:
* Redone patch on top of additional changes in series v2
* Commit message reword
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 include/hw/qdev-properties.h |  3 ++-
 hw/core/qdev-properties.c    | 12 ++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)
include/hw/qdev-properties.h +2 -1
index ab9c538ba4..aae882317a 100644
@@ -34,7 +34,8 @@ struct PropertyInfo {
     const QEnumLookup *enum_table;
     int (*print)(Object *obj, Property *prop, char *dest, size_t len);
     void (*set_default_value)(ObjectProperty *op, const Property *prop);
-    void (*create)(ObjectClass *oc, const char *name, Property *prop);
+    ObjectProperty *(*create)(ObjectClass *oc, const char *name,
+                              Property *prop);
     ObjectPropertyAccessor *get;
     ObjectPropertyAccessor *set;
     ObjectPropertyRelease *release;
hw/core/qdev-properties.c +6 -6
index 92f48ecbf2..3bb05e7d0d 100644
@@ -821,13 +821,13 @@ const PropertyInfo qdev_prop_size = {
 
 /* --- object link property --- */
 
-static void create_link_property(ObjectClass *oc, const char *name,
-                                 Property *prop)
+static ObjectProperty *create_link_property(ObjectClass *oc, const char *name,
+                                            Property *prop)
 {
-    object_class_property_add_link(oc, name, prop->link_type,
-                                   prop->offset,
-                                   qdev_prop_allow_set_link_before_realize,
-                                   OBJ_PROP_LINK_STRONG);
+    return object_class_property_add_link(oc, name, prop->link_type,
+                                          prop->offset,
+                                          qdev_prop_allow_set_link_before_realize,
+                                          OBJ_PROP_LINK_STRONG);
 }
 
 const PropertyInfo qdev_prop_link = {
Signature · 1 line
2.28.0
#27 lore raw

PATCH v3 25/53 qdev: Make qdev_class_add_property() more flexible

In reply to Eduardo Habkost

Support Property.set_default and PropertyInfo.description even if PropertyInfo.create is set.

---
Changes v1 -> v2:
* Patch redone after changes in the previous patches in the series
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-properties.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
hw/core/qdev-properties.c +9 -8
index 3bb05e7d0d..fcda0c8f4b 100644
@@ -863,24 +863,25 @@ static void qdev_class_add_property(DeviceClass *klass, const char *name,
                                     Property *prop)
 {
     ObjectClass *oc = OBJECT_CLASS(klass);
+    ObjectProperty *op;
 
     if (prop->info->create) {
-        prop->info->create(oc, name, prop);
+        op = prop->info->create(oc, name, prop);
     } else {
-        ObjectProperty *op;
-
         op = object_class_property_add(oc,
                                        name, prop->info->name,
                                        field_prop_getter(prop->info),
                                        field_prop_setter(prop->info),
                                        prop->info->release,
                                        prop);
-        if (prop->set_default) {
-            prop->info->set_default_value(op, prop);
-        }
     }
-    object_class_property_set_description(oc, name,
-                                          prop->info->description);
+    if (prop->set_default) {
+        prop->info->set_default_value(op, prop);
+    }
+    if (prop->info->description) {
+        object_class_property_set_description(oc, name,
+                                              prop->info->description);
+    }
 }
 
 /**
Signature · 1 line
2.28.0
#28 lore raw

PATCH v3 26/53 qdev: Separate generic and device-specific property registration

In reply to Eduardo Habkost

qdev_class_add_property() and qdev_property_add_static() will have code that's specific for device types.

object_class_property_add_field_static() and object_property_add_field() will be generic and part of the QOM field property API. Note that the new functions have a name parameter because the plan is to eventually get rid of the Property.name field.

The declarations for the new functions are being added to qdev-properties-internal.h, but they will be moved to a QOM header later.

---
Changes v2 -> v3:
* Re-added array-based array registration function, named as object_class_add_field_properties()
* Renamed object_class_property_add_field() to object_class_property_add_field_static(), to indicate that the function expect the Property argument to have static life time.
* Keep all new functions as internal API by now, until we decide what's going to be the preferred API for registering class field properties.

Changes v1 -> v2:
* Patch redone after changes in previous patches in the series
* Rename new functions to object*_property_add_field()
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-prop-internal.h | 42 ++++++++++++++++++++++++++++++++++++
 hw/core/qdev-properties.c    | 37 ++++++++++++++++++++++++-------
 2 files changed, 71 insertions(+), 8 deletions(-)
hw/core/qdev-prop-internal.h +42 -0
index d7b77844fe..6f17ddf271 100644
@@ -25,4 +25,46 @@ void qdev_propinfo_get_int32(Object *obj, Visitor *v, const char *name,
 void qdev_propinfo_get_size32(Object *obj, Visitor *v, const char *name,
                               void *opaque, Error **errp);
 
+/**
+ * object_property_add_field: Add a field property to an object instance
+ * @obj: object instance
+ * @name: property name
+ * @prop: property definition
+ *
+ * This function should not be used in new code.  Please add class properties
+ * instead, using object_class_add_field().
+ */
+ObjectProperty *
+object_property_add_field(Object *obj, const char *name,
+                          Property *prop);
+
+/**
+ * object_class_property_add_field_static: Add a field property to object class
+ * @oc: object class
+ * @name: property name
+ * @prop: property definition
+ *
+ * Add a field property to an object class.  A field property is
+ * a property that will change a field at a specific offset of the
+ * object instance struct.
+ *
+ * *@prop must have static life time.
+ */
+ObjectProperty *
+object_class_property_add_field_static(ObjectClass *oc, const char *name,
+                                       Property *prop);
+
+/**
+ * object_class_add_field_properties: Add field properties from array to a class
+ * @oc: object class
+ * @props: array of property definitions
+ *
+ * Register an array of field properties to a class, using
+ * object_class_property_add_field_static() for each array element.
+ *
+ * The array at @props must end with DEFINE_PROP_END_OF_LIST(), and
+ * must have static life time.
+ */
+void object_class_add_field_properties(ObjectClass *oc, Property *props);
+
 #endif
hw/core/qdev-properties.c +29 -8
index fcda0c8f4b..8436b60ec4 100644
@@ -835,20 +835,21 @@ const PropertyInfo qdev_prop_link = {
     .create = create_link_property,
 };
 
-void qdev_property_add_static(DeviceState *dev, Property *prop)
+ObjectProperty *
+object_property_add_field(Object *obj, const char *name,
+                          Property *prop)
 {
-    Object *obj = OBJECT(dev);
     ObjectProperty *op;
 
     assert(!prop->info->create);
 
-    op = object_property_add(obj, prop->name, prop->info->name,
+    op = object_property_add(obj, name, prop->info->name,
                              field_prop_getter(prop->info),
                              field_prop_setter(prop->info),
                              prop->info->release,
                              prop);
 
-    object_property_set_description(obj, prop->name,
+    object_property_set_description(obj, name,
                                     prop->info->description);
 
     if (prop->set_default) {
@@ -857,12 +858,14 @@ void qdev_property_add_static(DeviceState *dev, Property *prop)
             op->init(obj, op);
         }
     }
+
+    return op;
 }
 
-static void qdev_class_add_property(DeviceClass *klass, const char *name,
-                                    Property *prop)
+ObjectProperty *
+object_class_property_add_field_static(ObjectClass *oc, const char *name,
+                                       Property *prop)
 {
-    ObjectClass *oc = OBJECT_CLASS(klass);
     ObjectProperty *op;
 
     if (prop->info->create) {
@@ -882,6 +885,22 @@ static void qdev_class_add_property(DeviceClass *klass, const char *name,
         object_class_property_set_description(oc, name,
                                               prop->info->description);
     }
+    return op;
+}
+
+void object_class_add_field_properties(ObjectClass *oc, Property *props)
+{
+    Property *prop;
+
+    for (prop = props; prop && prop->name; prop++) {
+        object_class_property_add_field_static(oc, prop->name, prop);
+    }
+}
+
+
+void qdev_property_add_static(DeviceState *dev, Property *prop)
+{
+    object_property_add_field(OBJECT(dev), prop->name, prop);
 }
 
 /**
@@ -932,13 +951,15 @@ static void qdev_class_add_legacy_property(DeviceClass *dc, Property *prop)
 
 void device_class_set_props(DeviceClass *dc, Property *props)
 {
+    ObjectClass *oc = OBJECT_CLASS(dc);
     Property *prop;
 
     dc->props_ = props;
     for (prop = props; prop && prop->name; prop++) {
         qdev_class_add_legacy_property(dc, prop);
-        qdev_class_add_property(dc, prop->name, prop);
     }
+
+    object_class_add_field_properties(oc, props);
 }
 
 void qdev_alias_all_properties(DeviceState *target, Object *source)
Signature · 1 line
2.28.0
#29 lore raw

PATCH v3 27/53 qdev: Rename qdev_propinfo_* to field_prop_*

In reply to Eduardo Habkost

These functions will be moved to be part of QOM, so rename them.

---
Changes v2:
* Rename to field_prop_* instead of object_propinfo_*
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-prop-internal.h     | 28 +++++++--------
 hw/core/qdev-properties-system.c | 48 ++++++++++++-------------
 hw/core/qdev-properties.c        | 62 ++++++++++++++++----------------
 3 files changed, 69 insertions(+), 69 deletions(-)
hw/core/qdev-prop-internal.h +14 -14
index 6f17ddf271..740a5e530b 100644
@@ -8,22 +8,22 @@
 #ifndef HW_CORE_QDEV_PROP_INTERNAL_H
 #define HW_CORE_QDEV_PROP_INTERNAL_H
 
-void qdev_propinfo_get_enum(Object *obj, Visitor *v, const char *name,
-                            void *opaque, Error **errp);
-void qdev_propinfo_set_enum(Object *obj, Visitor *v, const char *name,
-                            void *opaque, Error **errp);
+void field_prop_get_enum(Object *obj, Visitor *v, const char *name,
+                         void *opaque, Error **errp);
+void field_prop_set_enum(Object *obj, Visitor *v, const char *name,
+                         void *opaque, Error **errp);
 
-void qdev_propinfo_set_default_value_enum(ObjectProperty *op,
-                                          const Property *prop);
-void qdev_propinfo_set_default_value_int(ObjectProperty *op,
-                                         const Property *prop);
-void qdev_propinfo_set_default_value_uint(ObjectProperty *op,
-                                          const Property *prop);
+void field_prop_set_default_value_enum(ObjectProperty *op,
+                                       const Property *prop);
+void field_prop_set_default_value_int(ObjectProperty *op,
+                                      const Property *prop);
+void field_prop_set_default_value_uint(ObjectProperty *op,
+                                       const Property *prop);
 
-void qdev_propinfo_get_int32(Object *obj, Visitor *v, const char *name,
-                             void *opaque, Error **errp);
-void qdev_propinfo_get_size32(Object *obj, Visitor *v, const char *name,
-                              void *opaque, Error **errp);
+void field_prop_get_int32(Object *obj, Visitor *v, const char *name,
+                          void *opaque, Error **errp);
+void field_prop_get_size32(Object *obj, Visitor *v, const char *name,
+                           void *opaque, Error **errp);
 
 /**
  * object_property_add_field: Add a field property to an object instance
hw/core/qdev-properties-system.c +24 -24

110 lines not on this page · raw message

hw/core/qdev-properties.c +31 -31

166 lines not on this page · raw message

Signature · 1 line
2.28.0
#30 lore raw

PATCH v3 28/53 qdev: Move qdev_prop_tpm declaration to tpm_prop.h

In reply to Eduardo Habkost

Move the variable declaration close to the macro that uses it.

---
Cc: Stefan Berger <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/tpm/tpm_prop.h            | 2 ++
 include/hw/qdev-properties.h | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)
hw/tpm/tpm_prop.h +2 -0
index 85e1ae5718..871af584b7 100644
@@ -25,6 +25,8 @@
 #include "sysemu/tpm_backend.h"
 #include "hw/qdev-properties.h"
 
+extern const PropertyInfo qdev_prop_tpm;
+
 #define DEFINE_PROP_TPMBE(_n, _s, _f)                     \
     DEFINE_PROP(_n, _s, _f, qdev_prop_tpm, TPMBackend *)
 
include/hw/qdev-properties.h +0 -1
index aae882317a..68e544708b 100644
@@ -56,7 +56,6 @@ extern const PropertyInfo qdev_prop_uint64;
 extern const PropertyInfo qdev_prop_int64;
 extern const PropertyInfo qdev_prop_size;
 extern const PropertyInfo qdev_prop_string;
-extern const PropertyInfo qdev_prop_tpm;
 extern const PropertyInfo qdev_prop_on_off_auto;
 extern const PropertyInfo qdev_prop_size32;
 extern const PropertyInfo qdev_prop_arraylen;
Signature · 1 line
2.28.0
#31 lore raw

PATCH v3 29/53 qdev: Rename qdev_prop_* to prop_info_*

In reply to Eduardo Habkost

The basic property types in qdev-properties.c are not going to be qdev-specific anymore. Rename the variables to prop_info_*.

---
Changes v1 -> v2:
* Redone patch after moving UUID property to qdev-properties-system.c
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Peter Maydell <[email protected]>
Cc: Yoshinori Sato <[email protected]>
Cc: Dmitry Fleytman <[email protected]>
Cc: Jason Wang <[email protected]>
Cc: Mark Cave-Ayland <[email protected]>
Cc: Artyom Tarasenko <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 include/hw/qdev-properties.h | 62 ++++++++++++++++++------------------
 hw/core/qdev-properties.c    | 36 ++++++++++-----------
 hw/intc/arm_gicv3_common.c   |  2 +-
 hw/intc/rx_icu.c             |  4 +--
 hw/misc/arm_sysctl.c         |  4 +--
 hw/net/e1000e.c              |  6 ++--
 target/arm/cpu.c             |  2 +-
 target/sparc/cpu.c           |  2 +-
 8 files changed, 59 insertions(+), 59 deletions(-)
include/hw/qdev-properties.h +31 -31
index 68e544708b..90222822f1 100644
@@ -44,22 +44,22 @@ struct PropertyInfo {
 
 /*** qdev-properties.c ***/
 
-extern const PropertyInfo qdev_prop_bit;
-extern const PropertyInfo qdev_prop_bit64;
-extern const PropertyInfo qdev_prop_bool;
-extern const PropertyInfo qdev_prop_enum;
-extern const PropertyInfo qdev_prop_uint8;
-extern const PropertyInfo qdev_prop_uint16;
-extern const PropertyInfo qdev_prop_uint32;
-extern const PropertyInfo qdev_prop_int32;
-extern const PropertyInfo qdev_prop_uint64;
-extern const PropertyInfo qdev_prop_int64;
-extern const PropertyInfo qdev_prop_size;
-extern const PropertyInfo qdev_prop_string;
-extern const PropertyInfo qdev_prop_on_off_auto;
-extern const PropertyInfo qdev_prop_size32;
-extern const PropertyInfo qdev_prop_arraylen;
-extern const PropertyInfo qdev_prop_link;
+extern const PropertyInfo prop_info_bit;
+extern const PropertyInfo prop_info_bit64;
+extern const PropertyInfo prop_info_bool;
+extern const PropertyInfo prop_info_enum;
+extern const PropertyInfo prop_info_uint8;
+extern const PropertyInfo prop_info_uint16;
+extern const PropertyInfo prop_info_uint32;
+extern const PropertyInfo prop_info_int32;
+extern const PropertyInfo prop_info_uint64;
+extern const PropertyInfo prop_info_int64;
+extern const PropertyInfo prop_info_size;
+extern const PropertyInfo prop_info_string;
+extern const PropertyInfo prop_info_on_off_auto;
+extern const PropertyInfo prop_info_size32;
+extern const PropertyInfo prop_info_arraylen;
+extern const PropertyInfo prop_info_link;
 
 #define DEFINE_PROP(_name, _state, _field, _prop, _type, ...) {  \
         .name      = (_name),                                    \
@@ -78,7 +78,7 @@ extern const PropertyInfo qdev_prop_link;
     DEFINE_PROP(_name, _state, _field, _prop, _type)
 
 #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval)   \
-    DEFINE_PROP(_name, _state, _field, qdev_prop_bit, uint32_t, \
+    DEFINE_PROP(_name, _state, _field, prop_info_bit, uint32_t, \
                 .bitnr       = (_bit),                          \
                 .set_default = true,                            \
                 .defval.u    = (bool)_defval)
@@ -92,13 +92,13 @@ extern const PropertyInfo qdev_prop_link;
     DEFINE_PROP(_name, _state, _field, _prop, _type)
 
 #define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval)   \
-    DEFINE_PROP(_name, _state, _field, qdev_prop_bit64, uint64_t, \
+    DEFINE_PROP(_name, _state, _field, prop_info_bit64, uint64_t, \
                 .bitnr    = (_bit),                               \
                 .set_default = true,                              \
                 .defval.u  = (bool)_defval)
 
 #define DEFINE_PROP_BOOL(_name, _state, _field, _defval)     \
-    DEFINE_PROP(_name, _state, _field, qdev_prop_bool, bool, \
+    DEFINE_PROP(_name, _state, _field, prop_info_bool, bool, \
                 .set_default = true,                         \
                 .defval.u    = (bool)_defval)
 
@@ -131,7 +131,7 @@ extern const PropertyInfo qdev_prop_link;
 #define DEFINE_PROP_ARRAY(_name, _state, _field,               \
                           _arrayfield, _arrayprop, _arraytype) \
     DEFINE_PROP((PROP_ARRAY_LEN_PREFIX _name),                 \
-                _state, _field, qdev_prop_arraylen, uint32_t,  \
+                _state, _field, prop_info_arraylen, uint32_t,  \
                 .set_default = true,                           \
                 .defval.u = 0,                                 \
                 .arrayinfo = &(_arrayprop),                    \
@@ -139,29 +139,29 @@ extern const PropertyInfo qdev_prop_link;
                 .arrayoffset = offsetof(_state, _arrayfield))
 
 #define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type)     \
-    DEFINE_PROP(_name, _state, _field, qdev_prop_link, _ptr_type,     \
+    DEFINE_PROP(_name, _state, _field, prop_info_link, _ptr_type,     \
                 .link_type  = _type)
 
 #define DEFINE_PROP_UINT8(_n, _s, _f, _d)                       \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
+    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint8, uint8_t)
 #define DEFINE_PROP_UINT16(_n, _s, _f, _d)                      \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
+    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint16, uint16_t)
 #define DEFINE_PROP_UINT32(_n, _s, _f, _d)                      \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
+    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint32, uint32_t)
 #define DEFINE_PROP_INT32(_n, _s, _f, _d)                      \
-    DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int32, int32_t)
+    DEFINE_PROP_SIGNED(_n, _s, _f, _d, prop_info_int32, int32_t)
 #define DEFINE_PROP_UINT64(_n, _s, _f, _d)                      \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
+    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint64, uint64_t)
 #define DEFINE_PROP_INT64(_n, _s, _f, _d)                      \
-    DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int64, int64_t)
+    DEFINE_PROP_SIGNED(_n, _s, _f, _d, prop_info_int64, int64_t)
 #define DEFINE_PROP_SIZE(_n, _s, _f, _d)                       \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size, uint64_t)
+    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_size, uint64_t)
 #define DEFINE_PROP_STRING(_n, _s, _f)             \
-    DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
+    DEFINE_PROP(_n, _s, _f, prop_info_string, char*)
 #define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \
-    DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto)
+    DEFINE_PROP_SIGNED(_n, _s, _f, _d, prop_info_on_off_auto, OnOffAuto)
 #define DEFINE_PROP_SIZE32(_n, _s, _f, _d)                       \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size32, uint32_t)
+    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_size32, uint32_t)
 
 #define DEFINE_PROP_END_OF_LIST()               \
     {}
hw/core/qdev-properties.c +18 -18
index d2f565f552..c1dd4ae71b 100644
@@ -121,7 +121,7 @@ void field_prop_set_default_value_enum(ObjectProperty *op,
         qapi_enum_lookup(prop->info->enum_table, prop->defval.i));
 }
 
-const PropertyInfo qdev_prop_enum = {
+const PropertyInfo prop_info_enum = {
     .name  = "enum",
     .get   = field_prop_get_enum,
     .set   = field_prop_set_enum,
@@ -132,7 +132,7 @@ const PropertyInfo qdev_prop_enum = {
 
 static uint32_t qdev_get_prop_mask(Property *prop)
 {
-    assert(prop->info == &qdev_prop_bit);
+    assert(prop->info == &prop_info_bit);
     return 0x1 << prop->bitnr;
 }
 
@@ -174,7 +174,7 @@ static void set_default_value_bool(ObjectProperty *op, const Property *prop)
     object_property_set_default_bool(op, prop->defval.u);
 }
 
-const PropertyInfo qdev_prop_bit = {
+const PropertyInfo prop_info_bit = {
     .name  = "bool",
     .description = "on/off",
     .get   = prop_get_bit,
@@ -186,7 +186,7 @@ const PropertyInfo qdev_prop_bit = {
 
 static uint64_t qdev_get_prop_mask64(Property *prop)
 {
-    assert(prop->info == &qdev_prop_bit64);
+    assert(prop->info == &prop_info_bit64);
     return 0x1ull << prop->bitnr;
 }
 
@@ -223,7 +223,7 @@ static void prop_set_bit64(Object *obj, Visitor *v, const char *name,
     bit64_prop_set(obj, prop, value);
 }
 
-const PropertyInfo qdev_prop_bit64 = {
+const PropertyInfo prop_info_bit64 = {
     .name  = "bool",
     .description = "on/off",
     .get   = prop_get_bit64,
@@ -251,7 +251,7 @@ static void set_bool(Object *obj, Visitor *v, const char *name, void *opaque,
     visit_type_bool(v, name, ptr, errp);
 }
 
-const PropertyInfo qdev_prop_bool = {
+const PropertyInfo prop_info_bool = {
     .name  = "bool",
     .get   = get_bool,
     .set   = set_bool,
@@ -290,7 +290,7 @@ void field_prop_set_default_value_uint(ObjectProperty *op,
     object_property_set_default_uint(op, prop->defval.u);
 }
 
-const PropertyInfo qdev_prop_uint8 = {
+const PropertyInfo prop_info_uint8 = {
     .name  = "uint8",
     .get   = get_uint8,
     .set   = set_uint8,
@@ -317,7 +317,7 @@ static void set_uint16(Object *obj, Visitor *v, const char *name,
     visit_type_uint16(v, name, ptr, errp);
 }
 
-const PropertyInfo qdev_prop_uint16 = {
+const PropertyInfo prop_info_uint16 = {
     .name  = "uint16",
     .get   = get_uint16,
     .set   = set_uint16,
@@ -362,14 +362,14 @@ static void set_int32(Object *obj, Visitor *v, const char *name, void *opaque,
     visit_type_int32(v, name, ptr, errp);
 }
 
-const PropertyInfo qdev_prop_uint32 = {
+const PropertyInfo prop_info_uint32 = {
     .name  = "uint32",
     .get   = get_uint32,
     .set   = set_uint32,
     .set_default_value = field_prop_set_default_value_uint,
 };
 
-const PropertyInfo qdev_prop_int32 = {
+const PropertyInfo prop_info_int32 = {
     .name  = "int32",
     .get   = field_prop_get_int32,
     .set   = set_int32,
@@ -414,14 +414,14 @@ static void set_int64(Object *obj, Visitor *v, const char *name,
     visit_type_int64(v, name, ptr, errp);
 }
 
-const PropertyInfo qdev_prop_uint64 = {
+const PropertyInfo prop_info_uint64 = {
     .name  = "uint64",
     .get   = get_uint64,
     .set   = set_uint64,
     .set_default_value = field_prop_set_default_value_uint,
 };
 
-const PropertyInfo qdev_prop_int64 = {
+const PropertyInfo prop_info_int64 = {
     .name  = "int64",
     .get   = get_int64,
     .set   = set_int64,
@@ -464,7 +464,7 @@ static void set_string(Object *obj, Visitor *v, const char *name,
     *ptr = str;
 }
 
-const PropertyInfo qdev_prop_string = {
+const PropertyInfo prop_info_string = {
     .name  = "str",
     .release = release_string,
     .get   = get_string,
@@ -473,7 +473,7 @@ const PropertyInfo qdev_prop_string = {
 
 /* --- on/off/auto --- */
 
-const PropertyInfo qdev_prop_on_off_auto = {
+const PropertyInfo prop_info_on_off_auto = {
     .name = "OnOffAuto",
     .description = "on/off/auto",
     .enum_table = &OnOffAuto_lookup,
@@ -516,7 +516,7 @@ static void set_size32(Object *obj, Visitor *v, const char *name, void *opaque,
     *ptr = value;
 }
 
-const PropertyInfo qdev_prop_size32 = {
+const PropertyInfo prop_info_size32 = {
     .name  = "size",
     .get = field_prop_get_size32,
     .set = set_size32,
@@ -613,7 +613,7 @@ static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
     }
 }
 
-const PropertyInfo qdev_prop_arraylen = {
+const PropertyInfo prop_info_arraylen = {
     .name = "uint32",
     .get = get_uint32,
     .set = set_prop_arraylen,
@@ -812,7 +812,7 @@ static void set_size(Object *obj, Visitor *v, const char *name, void *opaque,
     visit_type_size(v, name, ptr, errp);
 }
 
-const PropertyInfo qdev_prop_size = {
+const PropertyInfo prop_info_size = {
     .name  = "size",
     .get = get_size,
     .set = set_size,
@@ -830,7 +830,7 @@ static ObjectProperty *create_link_property(ObjectClass *oc, const char *name,
                                           OBJ_PROP_LINK_STRONG);
 }
 
-const PropertyInfo qdev_prop_link = {
+const PropertyInfo prop_info_link = {
     .name = "link",
     .create = create_link_property,
 };
hw/intc/arm_gicv3_common.c +1 -1
index 58ef65f589..6d06b4d4c5 100644
@@ -496,7 +496,7 @@ static Property arm_gicv3_common_properties[] = {
     DEFINE_PROP_UINT32("revision", GICv3State, revision, 3),
     DEFINE_PROP_BOOL("has-security-extensions", GICv3State, security_extn, 0),
     DEFINE_PROP_ARRAY("redist-region-count", GICv3State, nb_redist_regions,
-                      redist_region_count, qdev_prop_uint32, uint32_t),
+                      redist_region_count, prop_info_uint32, uint32_t),
     DEFINE_PROP_END_OF_LIST(),
 };
 
hw/intc/rx_icu.c +2 -2
index 94e17a9dea..823160d9a8 100644
@@ -365,9 +365,9 @@ static const VMStateDescription vmstate_rxicu = {
 
 static Property rxicu_properties[] = {
     DEFINE_PROP_ARRAY("ipr-map", RXICUState, nr_irqs, map,
-                      qdev_prop_uint8, uint8_t),
+                      prop_info_uint8, uint8_t),
     DEFINE_PROP_ARRAY("trigger-level", RXICUState, nr_sense, init_sense,
-                      qdev_prop_uint8, uint8_t),
+                      prop_info_uint8, uint8_t),
     DEFINE_PROP_END_OF_LIST(),
 };
 
hw/misc/arm_sysctl.c +2 -2
index 42d4693854..634f3d916f 100644
@@ -628,10 +628,10 @@ static Property arm_sysctl_properties[] = {
     DEFINE_PROP_UINT32("proc_id", arm_sysctl_state, proc_id, 0),
     /* Daughterboard power supply voltages (as reported via SYS_CFG) */
     DEFINE_PROP_ARRAY("db-voltage", arm_sysctl_state, db_num_vsensors,
-                      db_voltage, qdev_prop_uint32, uint32_t),
+                      db_voltage, prop_info_uint32, uint32_t),
     /* Daughterboard clock reset values (as reported via SYS_CFG) */
     DEFINE_PROP_ARRAY("db-clock", arm_sysctl_state, db_num_clocks,
-                      db_clock_reset, qdev_prop_uint32, uint32_t),
+                      db_clock_reset, prop_info_uint32, uint32_t),
     DEFINE_PROP_END_OF_LIST(),
 };
 
hw/net/e1000e.c +3 -3
index b6f1ae3c8f..7928939ae2 100644
@@ -686,15 +686,15 @@ static void e1000e_class_init(ObjectClass *class, void *data)
     dc->reset = e1000e_qdev_reset;
     dc->vmsd = &e1000e_vmstate;
 
-    e1000e_prop_disable_vnet = qdev_prop_uint8;
+    e1000e_prop_disable_vnet = prop_info_uint8;
     e1000e_prop_disable_vnet.description = "Do not use virtio headers, "
                                            "perform SW offloads emulation "
                                            "instead";
 
-    e1000e_prop_subsys_ven = qdev_prop_uint16;
+    e1000e_prop_subsys_ven = prop_info_uint16;
     e1000e_prop_subsys_ven.description = "PCI device Subsystem Vendor ID";
 
-    e1000e_prop_subsys = qdev_prop_uint16;
+    e1000e_prop_subsys = prop_info_uint16;
     e1000e_prop_subsys.description = "PCI device Subsystem ID";
 
     device_class_set_props(dc, e1000e_properties);
target/arm/cpu.c +1 -1
index 07492e9f9a..cef92879b0 100644
@@ -1108,7 +1108,7 @@ static Property arm_cpu_has_mpu_property =
 static Property arm_cpu_pmsav7_dregion_property =
             DEFINE_PROP_UNSIGNED_NODEFAULT("pmsav7-dregion", ARMCPU,
                                            pmsav7_dregion,
-                                           qdev_prop_uint32, uint32_t);
+                                           prop_info_uint32, uint32_t);
 
 static bool arm_get_pmu(Object *obj, Error **errp)
 {
target/sparc/cpu.c +1 -1
index 3375fffb38..ec59a13eb8 100644
@@ -839,7 +839,7 @@ static Property sparc_cpu_properties[] = {
     DEFINE_PROP_BIT("cmt",      SPARCCPU, env.def.features, 12, false),
     DEFINE_PROP_BIT("gl",       SPARCCPU, env.def.features, 13, false),
     DEFINE_PROP_UNSIGNED("iu-version", SPARCCPU, env.def.iu_version, 0,
-                         qdev_prop_uint64, target_ulong),
+                         prop_info_uint64, target_ulong),
     DEFINE_PROP_UINT32("fpu-version", SPARCCPU, env.def.fpu_version, 0),
     DEFINE_PROP_UINT32("mmu-version", SPARCCPU, env.def.mmu_version, 0),
     DEFINE_PROP("nwindows",     SPARCCPU, env.def.nwindows,
Signature · 1 line
2.28.0
#32 lore raw

PATCH v3 30/53 qdev: Rename qdev_get_prop_ptr() to object_field_prop_ptr()

In reply to Eduardo Habkost

The function will be moved to common QOM code, as it is not specific to TYPE_DEVICE anymore.

---
Changes v1 -> v2:
* Rename to object_field_prop_ptr() instead of object_static_prop_ptr()
---
Cc: Stefan Berger <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: Paul Durrant <[email protected]>
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Cornelia Huck <[email protected]>
Cc: Halil Pasic <[email protected]>
Cc: Christian Borntraeger <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Matthew Rosato <[email protected]>
Cc: Alex Williamson <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
 include/hw/qdev-properties.h     |  2 +-
 backends/tpm/tpm_util.c          |  6 ++--
 hw/block/xen-block.c             |  4 +--
 hw/core/qdev-properties-system.c | 50 +++++++++++++-------------
 hw/core/qdev-properties.c        | 60 ++++++++++++++++----------------
 hw/s390x/css.c                   |  4 +--
 hw/s390x/s390-pci-bus.c          |  4 +--
 hw/vfio/pci-quirks.c             |  4 +--
 8 files changed, 67 insertions(+), 67 deletions(-)
include/hw/qdev-properties.h +1 -1
index 90222822f1..97bb9494ae 100644
@@ -193,7 +193,7 @@ void qdev_prop_set_macaddr(DeviceState *dev, const char *name,
                            const uint8_t *value);
 void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
 
-void *qdev_get_prop_ptr(Object *obj, Property *prop);
+void *object_field_prop_ptr(Object *obj, Property *prop);
 
 void qdev_prop_register_global(GlobalProperty *prop);
 const GlobalProperty *qdev_find_global_prop(Object *obj,
backends/tpm/tpm_util.c +3 -3
index 0b07cf55ea..bb1ab34a75 100644
@@ -35,7 +35,7 @@
 static void get_tpm(Object *obj, Visitor *v, const char *name, void *opaque,
                     Error **errp)
 {
-    TPMBackend **be = qdev_get_prop_ptr(obj, opaque);
+    TPMBackend **be = object_field_prop_ptr(obj, opaque);
     char *p;
 
     p = g_strdup(*be ? (*be)->id : "");
@@ -47,7 +47,7 @@ static void set_tpm(Object *obj, Visitor *v, const char *name, void *opaque,
                     Error **errp)
 {
     Property *prop = opaque;
-    TPMBackend *s, **be = qdev_get_prop_ptr(obj, prop);
+    TPMBackend *s, **be = object_field_prop_ptr(obj, prop);
     char *str;
 
     if (!visit_type_str(v, name, &str, errp)) {
@@ -67,7 +67,7 @@ static void set_tpm(Object *obj, Visitor *v, const char *name, void *opaque,
 static void release_tpm(Object *obj, const char *name, void *opaque)
 {
     Property *prop = opaque;
-    TPMBackend **be = qdev_get_prop_ptr(obj, prop);
+    TPMBackend **be = object_field_prop_ptr(obj, prop);
 
     if (*be) {
         tpm_backend_reset(*be);
hw/block/xen-block.c +2 -2
index bd1aef63a7..718d886e5c 100644
@@ -336,7 +336,7 @@ static void xen_block_get_vdev(Object *obj, Visitor *v, const char *name,
                                void *opaque, Error **errp)
 {
     Property *prop = opaque;
-    XenBlockVdev *vdev = qdev_get_prop_ptr(obj, prop);
+    XenBlockVdev *vdev = object_field_prop_ptr(obj, prop);
     char *str;
 
     switch (vdev->type) {
@@ -396,7 +396,7 @@ static void xen_block_set_vdev(Object *obj, Visitor *v, const char *name,
                                void *opaque, Error **errp)
 {
     Property *prop = opaque;
-    XenBlockVdev *vdev = qdev_get_prop_ptr(obj, prop);
+    XenBlockVdev *vdev = object_field_prop_ptr(obj, prop);
     char *str, *p;
     const char *end;
 
hw/core/qdev-properties-system.c +25 -25

200 lines not on this page · raw message

hw/core/qdev-properties.c +30 -30

240 lines not on this page · raw message

hw/s390x/css.c +2 -2
index 496e2c5801..fe47751df4 100644
@@ -2344,7 +2344,7 @@ static void get_css_devid(Object *obj, Visitor *v, const char *name,
                           void *opaque, Error **errp)
 {
     Property *prop = opaque;
-    CssDevId *dev_id = qdev_get_prop_ptr(obj, prop);
+    CssDevId *dev_id = object_field_prop_ptr(obj, prop);
     char buffer[] = "xx.x.xxxx";
     char *p = buffer;
     int r;
@@ -2373,7 +2373,7 @@ static void set_css_devid(Object *obj, Visitor *v, const char *name,
                           void *opaque, Error **errp)
 {
     Property *prop = opaque;
-    CssDevId *dev_id = qdev_get_prop_ptr(obj, prop);
+    CssDevId *dev_id = object_field_prop_ptr(obj, prop);
     char *str;
     int num, n1, n2;
     unsigned int cssid, ssid, devid;
hw/s390x/s390-pci-bus.c +2 -2
index 54fac3851d..99b18d56ba 100644
@@ -1323,7 +1323,7 @@ static void s390_pci_get_fid(Object *obj, Visitor *v, const char *name,
                          void *opaque, Error **errp)
 {
     Property *prop = opaque;
-    uint32_t *ptr = qdev_get_prop_ptr(obj, prop);
+    uint32_t *ptr = object_field_prop_ptr(obj, prop);
 
     visit_type_uint32(v, name, ptr, errp);
 }
@@ -1333,7 +1333,7 @@ static void s390_pci_set_fid(Object *obj, Visitor *v, const char *name,
 {
     S390PCIBusDevice *zpci = S390_PCI_DEVICE(obj);
     Property *prop = opaque;
-    uint32_t *ptr = qdev_get_prop_ptr(obj, prop);
+    uint32_t *ptr = object_field_prop_ptr(obj, prop);
 
     if (!visit_type_uint32(v, name, ptr, errp)) {
         return;
hw/vfio/pci-quirks.c +2 -2
index 802979635c..fc8d63c850 100644
@@ -1489,7 +1489,7 @@ static void get_nv_gpudirect_clique_id(Object *obj, Visitor *v,
                                        Error **errp)
 {
     Property *prop = opaque;
-    uint8_t *ptr = qdev_get_prop_ptr(obj, prop);
+    uint8_t *ptr = object_field_prop_ptr(obj, prop);
 
     visit_type_uint8(v, name, ptr, errp);
 }
@@ -1499,7 +1499,7 @@ static void set_nv_gpudirect_clique_id(Object *obj, Visitor *v,
                                        Error **errp)
 {
     Property *prop = opaque;
-    uint8_t value, *ptr = qdev_get_prop_ptr(obj, prop);
+    uint8_t value, *ptr = object_field_prop_ptr(obj, prop);
 
     if (!visit_type_uint8(v, name, &value, errp)) {
         return;
Signature · 1 line
2.28.0
#33 lore raw

PATCH v3 31/53 qdev: Avoid unnecessary DeviceState* variable at set_prop_arraylen()

In reply to Eduardo Habkost

We're just doing pointer math with the device pointer, we can simply use obj instead.

---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-properties.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
hw/core/qdev-properties.c +2 -3
index 3d648b088d..9d25b49fc1 100644
@@ -559,10 +559,9 @@ static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
      * array-length field in the device struct, we have to create the
      * array itself and dynamically add the corresponding properties.
      */
-    DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
     uint32_t *alenptr = object_field_prop_ptr(obj, prop);
-    void **arrayptr = (void *)dev + prop->arrayoffset;
+    void **arrayptr = (void *)obj + prop->arrayoffset;
     void *eltptr;
     const char *arrayname;
     int i;
@@ -602,7 +601,7 @@ static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
          * they get the right answer despite the array element not actually
          * being inside the device struct.
          */
-        arrayprop->prop.offset = eltptr - (void *)dev;
+        arrayprop->prop.offset = eltptr - (void *)obj;
         assert(object_field_prop_ptr(obj, &arrayprop->prop) == eltptr);
         object_property_add(obj, propname,
                             arrayprop->prop.info->name,
Signature · 1 line
2.28.0
#34 lore raw

PATCH v3 32/53 tests: Add unit test for qdev array properties

In reply to Eduardo Habkost

Add a test case to ensure array properties are behaving as expected.

---
This is a new patch added in v3 of this series.
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 tests/test-qdev-global-props.c | 61 ++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)
tests/test-qdev-global-props.c +61 -0
index c8862cac5f..9426ce2a72 100644
@@ -44,11 +44,16 @@ struct MyType {
 
     uint32_t prop1;
     uint32_t prop2;
+
+    char **myarray;
+    uint32_t myarray_len;
 };
 
 static Property static_props[] = {
     DEFINE_PROP_UINT32("prop1", MyType, prop1, PROP_DEFAULT),
     DEFINE_PROP_UINT32("prop2", MyType, prop2, PROP_DEFAULT),
+    DEFINE_PROP_ARRAY("myarray", MyType, myarray_len, myarray,
+                      prop_info_string, char *),
     DEFINE_PROP_END_OF_LIST()
 };
 
@@ -60,11 +65,19 @@ static void static_prop_class_init(ObjectClass *oc, void *data)
     device_class_set_props(dc, static_props);
 }
 
+static void static_props_finalize(Object *obj)
+{
+    MyType *mt = STATIC_TYPE(obj);
+
+    g_free(mt->myarray);
+}
+
 static const TypeInfo static_prop_type = {
     .name = TYPE_STATIC_PROPS,
     .parent = TYPE_DEVICE,
     .instance_size = sizeof(MyType),
     .class_init = static_prop_class_init,
+    .instance_finalize = static_props_finalize,
 };
 
 static const TypeInfo subclass_type = {
@@ -91,6 +104,52 @@ static void test_static_prop(void)
     g_test_trap_assert_stdout("");
 }
 
+static void test_static_prop_array(void)
+{
+    Error *err = NULL;
+    ObjectClass *oc = object_class_by_name(TYPE_STATIC_PROPS);
+    Object *obj = object_new(TYPE_STATIC_PROPS);
+    char *s = NULL;
+
+    g_assert_nonnull(object_class_property_find(oc, "len-myarray"));
+    g_assert_null(object_class_property_find(oc, "myarray[0]"));
+
+    g_assert_nonnull(object_property_find(obj, "len-myarray"));
+    g_assert_null(object_property_find(obj, "myarray[0]"));
+
+    g_assert_cmpint(object_property_get_int(obj, "len-myarray", &error_abort), ==, 0);
+    object_property_set_int(obj, "len-myarray", 3, &error_abort);
+    g_assert_cmpint(object_property_get_int(obj, "len-myarray", &error_abort), ==, 3);
+
+    g_assert_nonnull(object_property_find(obj, "myarray[0]"));
+    g_assert_nonnull(object_property_find(obj, "myarray[1]"));
+    g_assert_nonnull(object_property_find(obj, "myarray[2]"));
+    g_assert_null(object_property_find(obj, "myarray[3]"));
+
+    /* Setting length a second time must fail */
+    object_property_set_int(obj, "len-myarray", 42, &err);
+    error_free_or_abort(&err);
+
+    g_assert_nonnull(object_property_find(obj, "myarray[2]"));
+    g_assert_null(object_property_find(obj, "myarray[3]"));
+
+    s = object_property_get_str(obj, "myarray[2]", &error_abort);
+    g_assert_cmpstr(s, ==, "");
+    g_free(s);
+
+    object_property_set_str(obj, "myarray[1]", "value", &error_abort);
+
+    s = object_property_get_str(obj, "myarray[1]", &error_abort);
+    g_assert_cmpstr(s, ==, "value");
+    g_free(s);
+
+    s = object_property_get_str(obj, "myarray[2]", &error_abort);
+    g_assert_cmpstr(s, ==, "");
+    g_free(s);
+
+    object_unref(obj);
+}
+
 static void register_global_properties(GlobalProperty *props)
 {
     int i;
@@ -299,6 +358,8 @@ int main(int argc, char **argv)
                     test_static_prop_subprocess);
     g_test_add_func("/qdev/properties/static/default",
                     test_static_prop);
+    g_test_add_func("/qdev/properties/static/array",
+                    test_static_prop_array);
 
     g_test_add_func("/qdev/properties/static/global/subprocess",
                     test_static_globalprop_subprocess);
Signature · 1 line
2.28.0
#35 lore raw

PATCH v3 33/53 qom: Add allow_set callback to ObjectProperty

In reply to Eduardo Habkost

Add a ObjectProperty.allow_set callback, that can be set by QOM property registration functions.

Note that this doesn't replace the check callback at object*_property_add_link() (yet), because currently the link property check callback needs to get the property value as argument (despite this not being necessary in most cases).

---
Changes v1 -> v2:
* Redone patch on top of changes in previous patches in the series
* Provide prop_allow_set_always() and prop_allow_set_never() helpers
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 include/qom/object.h | 38 ++++++++++++++++++++++++++++++++++++++
 qom/object.c         | 16 ++++++++++++++++
 2 files changed, 54 insertions(+)
include/qom/object.h +38 -0
index d378f13a11..2ab124b8f0 100644
@@ -86,6 +86,43 @@ typedef void (ObjectPropertyRelease)(Object *obj,
  */
 typedef void (ObjectPropertyInit)(Object *obj, ObjectProperty *prop);
 
+/**
+ * typedef ObjectPropertyAllowSet:
+ * @obj: the object that owns the property
+ * @prop: the property being set
+ * @errp: pointer to error information
+ *
+ * Called when a property is being set.
+ *
+ * If return value is false, it will prevent the property from
+ * being changed.  Error information should be filled in @errp
+ * if return vlaue is false.
+ */
+typedef bool (ObjectPropertyAllowSet)(Object *obj, ObjectProperty *prop,
+                                      Error **errp);
+
+/**
+ * prop_allow_set_always:
+ * @obj: the object that owns the property
+ * @prop: the property being set
+ * @errp: pointer to error information
+ *
+ * ObjectPropertyAllowSet implementation that always allow the
+ * property to be set.
+ */
+bool prop_allow_set_always(Object *obj, ObjectProperty *prop, Error **errp);
+
+/**
+ * prop_allow_set_never:
+ * @obj: the object that owns the property
+ * @prop: the property being set
+ * @errp: pointer to error information
+ *
+ * ObjectPropertyAllowSet implementation that never allows the
+ * property to be set.
+ */
+bool prop_allow_set_never(Object *obj, ObjectProperty *prop, Error **errp);
+
 struct ObjectProperty
 {
     char *name;
@@ -96,6 +133,7 @@ struct ObjectProperty
     ObjectPropertyResolve *resolve;
     ObjectPropertyRelease *release;
     ObjectPropertyInit *init;
+    ObjectPropertyAllowSet *allow_set;
     void *opaque;
     QObject *defval;
 };
qom/object.c +16 -0
index 1065355233..7c11bcd3b1 100644
@@ -1381,6 +1381,18 @@ bool object_property_get(Object *obj, const char *name, Visitor *v,
     return !err;
 }
 
+bool prop_allow_set_always(Object *obj, ObjectProperty *prop, Error **errp)
+{
+    return true;
+}
+
+bool prop_allow_set_never(Object *obj, ObjectProperty *prop, Error **errp)
+{
+    error_setg(errp, "Property '%s.%s' can't be set",
+               object_get_typename(obj), prop->name);
+    return false;
+}
+
 bool object_property_set(Object *obj, const char *name, Visitor *v,
                          Error **errp)
 {
@@ -1395,6 +1407,10 @@ bool object_property_set(Object *obj, const char *name, Visitor *v,
         error_setg(errp, QERR_PERMISSION_DENIED);
         return false;
     }
+    if (prop->allow_set && !prop->allow_set(obj, prop, errp)) {
+        return false;
+    }
+
     prop->set(obj, v, name, prop->opaque, &err);
     error_propagate(errp, err);
     return !err;
Signature · 1 line
2.28.0
#36 lore raw

PATCH v3 34/53 qdev: Make qdev_prop_allow_set() a ObjectProperty.allow_set callback

In reply to Eduardo Habkost

Add a new allow_set parameter to object*_property_add_field(), and pass qdev_prop_allow_set as argument in the qdev registration code.

This removes the last remaining line of code inside the core field property code that's specific to TYPE_DEVICE, and will allow us to make field properties a core QOM feature.

The array property also needs to set PropertyInfo.allow_set manually, but this will be cleaned up later (that code will be changed to use object_class_property_add_field() too).

---
Changes v2 -> v3:
* Moved earlier in the series, before array property cleanup (I did this to allow us to move the code to QOM earlier)
* Redone after object_class_add_field_properties() was reintroduced

Changes v1 -> v2:
* Redone patch on top of changes in previous patches in the series
* Forbid allow_set==NULL to avoid confusion with link property semantics (where NULL makes the property read only)
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-prop-internal.h | 16 ++++++++---
 hw/core/qdev-properties.c    | 51 ++++++++++++++++++++++--------------
 2 files changed, 45 insertions(+), 22 deletions(-)
hw/core/qdev-prop-internal.h +13 -3
index 740a5e530b..47bab46810 100644
@@ -30,34 +30,43 @@ void field_prop_get_size32(Object *obj, Visitor *v, const char *name,
  * @obj: object instance
  * @name: property name
  * @prop: property definition
+ * @allow_set: check function called when property is set
  *
  * This function should not be used in new code.  Please add class properties
  * instead, using object_class_add_field().
  */
 ObjectProperty *
 object_property_add_field(Object *obj, const char *name,
-                          Property *prop);
+                          Property *prop,
+                          ObjectPropertyAllowSet allow_set);
 
 /**
  * object_class_property_add_field_static: Add a field property to object class
  * @oc: object class
  * @name: property name
  * @prop: property definition
+ * @allow_set: check function called when property is set
  *
  * Add a field property to an object class.  A field property is
  * a property that will change a field at a specific offset of the
  * object instance struct.
  *
  * *@prop must have static life time.
+ *
+ * @allow_set should not be NULL.  If the property can always be
+ * set, `prop_allow_set_always` can be used.  If the property can
+ * never be set, `prop_allow_set_never` can be used.
  */
 ObjectProperty *
 object_class_property_add_field_static(ObjectClass *oc, const char *name,
-                                       Property *prop);
+                                       Property *prop,
+                                       ObjectPropertyAllowSet allow_set);
 
 /**
  * object_class_add_field_properties: Add field properties from array to a class
  * @oc: object class
  * @props: array of property definitions
+ * @allow_set: check function called when property is set
  *
  * Register an array of field properties to a class, using
  * object_class_property_add_field_static() for each array element.
@@ -65,6 +74,7 @@ object_class_property_add_field_static(ObjectClass *oc, const char *name,
  * The array at @props must end with DEFINE_PROP_END_OF_LIST(), and
  * must have static life time.
  */
-void object_class_add_field_properties(ObjectClass *oc, Property *props);
+void object_class_add_field_properties(ObjectClass *oc, Property *props,
+                                       ObjectPropertyAllowSet allow_set);
 
 #endif
hw/core/qdev-properties.c +32 -19

142 lines not on this page · raw message

Signature · 1 line
2.28.0
#37 lore raw

PATCH v3 35/53 qdev: Rename Property.name to Property.name_template

In reply to Eduardo Habkost

The Property.name field won't always be set, but it is very easy to miss this detail when we see code using prop->name.

Rename the field to "name_template", to indicate it is just a template used when creating new properties in some cases, but is not always set.

---
Changes v2 -> v3:
* Change name from .qdev_prop_name to .name_template. The property won't be qdev-specific, but it won't be always set.

This is a patch added in v2 of the series
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 include/hw/qdev-properties.h | 11 +++++++++--
 hw/core/qdev-properties.c    | 23 ++++++++++++-----------
 softmmu/qdev-monitor.c       |  8 ++++----
 3 files changed, 25 insertions(+), 17 deletions(-)
include/hw/qdev-properties.h +9 -2
index 97bb9494ae..1208e12b9b 100644
@@ -13,7 +13,14 @@
  *     is true.
  */
 struct Property {
-    const char   *name;
+    /**
+     * @name_template: Property name template
+     *
+     * This is a string containing the template to be used when
+     * creating the property.  It can be NULL, and code shouldn't
+     * assume it will contain the actual property name.
+     */
+    const char   *name_template;
     const PropertyInfo *info;
     ptrdiff_t    offset;
     uint8_t      bitnr;
@@ -62,7 +69,7 @@ extern const PropertyInfo prop_info_arraylen;
 extern const PropertyInfo prop_info_link;
 
 #define DEFINE_PROP(_name, _state, _field, _prop, _type, ...) {  \
-        .name      = (_name),                                    \
+        .name_template = (_name),                           \
         .info      = &(_prop),                                   \
         .offset    = offsetof(_state, _field)                    \
             + type_check(_type, typeof_field(_state, _field)),   \
hw/core/qdev-properties.c +12 -11
index 638daf1ebf..03cfad1e74 100644
@@ -593,7 +593,7 @@ static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
         arrayprop->release = prop->arrayinfo->release;
         arrayprop->propname = propname;
         arrayprop->prop.info = prop->arrayinfo;
-        arrayprop->prop.name = propname;
+        arrayprop->prop.name_template = propname;
         /* This ugly piece of pointer arithmetic sets up the offset so
          * that when the underlying get/set hooks call qdev_get_prop_ptr
          * they get the right answer despite the array element not actually
@@ -625,8 +625,8 @@ static Property *qdev_prop_walk(Property *props, const char *name)
     if (!props) {
         return NULL;
     }
-    while (props->name) {
-        if (strcmp(props->name, name) == 0) {
+    while (props->name_template) {
+        if (strcmp(props->name_template, name) == 0) {
             return props;
         }
         props++;
@@ -903,15 +903,16 @@ void object_class_add_field_properties(ObjectClass *oc, Property *props,
 {
     Property *prop;
 
-    for (prop = props; prop && prop->name; prop++) {
-        object_class_property_add_field_static(oc, prop->name, prop, allow_set);
+    for (prop = props; prop && prop->name_template; prop++) {
+        object_class_property_add_field_static(oc, prop->name_template, prop,
+                                               allow_set);
     }
 }
 
 
 void qdev_property_add_static(DeviceState *dev, Property *prop)
 {
-    object_property_add_field(OBJECT(dev), prop->name, prop,
+    object_property_add_field(OBJECT(dev), prop->name_template, prop,
                               qdev_prop_allow_set);
 }
 
@@ -955,7 +956,7 @@ static void qdev_class_add_legacy_property(DeviceClass *dc, Property *prop)
         return;
     }
 
-    name = g_strdup_printf("legacy-%s", prop->name);
+    name = g_strdup_printf("legacy-%s", prop->name_template);
     object_class_property_add(OBJECT_CLASS(dc), name, "str",
         prop->info->print ? qdev_get_legacy_property : prop->info->get,
         NULL, NULL, prop);
@@ -967,7 +968,7 @@ void device_class_set_props(DeviceClass *dc, Property *props)
     Property *prop;
 
     dc->props_ = props;
-    for (prop = props; prop && prop->name; prop++) {
+    for (prop = props; prop && prop->name_template; prop++) {
         qdev_class_add_legacy_property(dc, prop);
     }
 
@@ -983,9 +984,9 @@ void qdev_alias_all_properties(DeviceState *target, Object *source)
     do {
         DeviceClass *dc = DEVICE_CLASS(class);
 
-        for (prop = dc->props_; prop && prop->name; prop++) {
-            object_property_add_alias(source, prop->name,
-                                      OBJECT(target), prop->name);
+        for (prop = dc->props_; prop && prop->name_template; prop++) {
+            object_property_add_alias(source, prop->name_template,
+                                      OBJECT(target), prop->name_template);
         }
         class = object_class_get_parent(class);
     } while (class != object_class_by_name(TYPE_DEVICE));
softmmu/qdev-monitor.c +4 -4
index 79164e4a3f..0d196a169a 100644
@@ -697,14 +697,14 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props,
 {
     if (!props)
         return;
-    for (; props->name; props++) {
+    for (; props->name_template; props++) {
         char *value;
-        char *legacy_name = g_strdup_printf("legacy-%s", props->name);
+        char *legacy_name = g_strdup_printf("legacy-%s", props->name_template);
 
         if (object_property_get_type(OBJECT(dev), legacy_name, NULL)) {
             value = object_property_get_str(OBJECT(dev), legacy_name, NULL);
         } else {
-            value = object_property_print(OBJECT(dev), props->name, true,
+            value = object_property_print(OBJECT(dev), props->name_template, true,
                                           NULL);
         }
         g_free(legacy_name);
@@ -712,7 +712,7 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props,
         if (!value) {
             continue;
         }
-        qdev_printf("%s = %s\n", props->name,
+        qdev_printf("%s = %s\n", props->name_template,
                     *value ? value : "<null>");
         g_free(value);
     }
Signature · 1 line
2.28.0
#38 lore raw

PATCH v3 36/53 qdev: Don't set .name_template for array elements

In reply to Eduardo Habkost

All property code should be able to handle .name_template==NULL without problems, so we don't need to set it for array elements.

This simple change will allow us to simplify the array property registration code a lot in the next commits.

---
This is a patch added in v2 of the series
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-properties.c | 1 -
 1 file changed, 1 deletion(-)
hw/core/qdev-properties.c +0 -1
index 03cfad1e74..ad08c80e67 100644
@@ -593,7 +593,6 @@ static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
         arrayprop->release = prop->arrayinfo->release;
         arrayprop->propname = propname;
         arrayprop->prop.info = prop->arrayinfo;
-        arrayprop->prop.name_template = propname;
         /* This ugly piece of pointer arithmetic sets up the offset so
          * that when the underlying get/set hooks call qdev_get_prop_ptr
          * they get the right answer despite the array element not actually
Signature · 1 line
2.28.0
#39 lore raw

PATCH v3 37/53 qdev: Remove ArrayElementProperty.propname field

In reply to Eduardo Habkost

Now that we don't save the property name in Property.name anymore, we don't need the to keep the property name string alive after the property was registered.

We can remove the ArrayElementProperty.propname field, and free the string immediately after registering the property.

---
This is a new patch added in v2 of the series
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-properties.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
hw/core/qdev-properties.c +1 -4
index ad08c80e67..2ab1c9688a 100644
@@ -529,7 +529,6 @@ const PropertyInfo prop_info_size32 = {
  */
 typedef struct {
     struct Property prop;
-    char *propname;
     ObjectPropertyRelease *release;
 } ArrayElementProperty;
 
@@ -543,7 +542,6 @@ static void array_element_release(Object *obj, const char *name, void *opaque)
     if (p->release) {
         p->release(obj, name, opaque);
     }
-    g_free(p->propname);
     g_free(p);
 }
 
@@ -587,11 +585,10 @@ static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
      */
     *arrayptr = eltptr = g_malloc0(*alenptr * prop->arrayfieldsize);
     for (i = 0; i < *alenptr; i++, eltptr += prop->arrayfieldsize) {
-        char *propname = g_strdup_printf("%s[%d]", arrayname, i);
+        g_autofree char *propname = g_strdup_printf("%s[%d]", arrayname, i);
         ArrayElementProperty *arrayprop = g_new0(ArrayElementProperty, 1);
         ObjectProperty *elmop;
         arrayprop->release = prop->arrayinfo->release;
-        arrayprop->propname = propname;
         arrayprop->prop.info = prop->arrayinfo;
         /* This ugly piece of pointer arithmetic sets up the offset so
          * that when the underlying get/set hooks call qdev_get_prop_ptr
Signature · 1 line
2.28.0
#40 lore raw

PATCH v3 38/53 qdev: Remove ArrayElementProperty.release field

In reply to Eduardo Habkost

We don't need the extra field because we can find the release function for the property directly at ArrayElementProperty.info.release.

---
This is a new patch added in v3 of this series.
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-properties.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
hw/core/qdev-properties.c +2 -4
index 2ab1c9688a..9f60f3b44d 100644
@@ -529,7 +529,6 @@ const PropertyInfo prop_info_size32 = {
  */
 typedef struct {
     struct Property prop;
-    ObjectPropertyRelease *release;
 } ArrayElementProperty;
 
 /* object property release callback for array element properties:
@@ -539,8 +538,8 @@ typedef struct {
 static void array_element_release(Object *obj, const char *name, void *opaque)
 {
     ArrayElementProperty *p = opaque;
-    if (p->release) {
-        p->release(obj, name, opaque);
+    if (p->prop.info->release) {
+        p->prop.info->release(obj, name, opaque);
     }
     g_free(p);
 }
@@ -588,7 +587,6 @@ static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
         g_autofree char *propname = g_strdup_printf("%s[%d]", arrayname, i);
         ArrayElementProperty *arrayprop = g_new0(ArrayElementProperty, 1);
         ObjectProperty *elmop;
-        arrayprop->release = prop->arrayinfo->release;
         arrayprop->prop.info = prop->arrayinfo;
         /* This ugly piece of pointer arithmetic sets up the offset so
          * that when the underlying get/set hooks call qdev_get_prop_ptr
Signature · 1 line
2.28.0
#41 lore raw

PATCH v3 39/53 qdev: Get rid of ArrayElementProperty struct

In reply to Eduardo Habkost

Now that we don't store any additional data about the property in AraryElementStruct, we don't need it anymore. We can just allocate a Property struct directly.

---
Change v1 -> v2:
* Get rid of the struct, but not of the release function (we still need it, or we will leak the Property struct we allocate)
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-properties.c | 32 +++++++++++---------------------
 1 file changed, 11 insertions(+), 21 deletions(-)
hw/core/qdev-properties.c +11 -21
index 9f60f3b44d..0ffef5ab4f 100644
@@ -521,27 +521,17 @@ const PropertyInfo prop_info_size32 = {
 
 /* --- support for array properties --- */
 
-/* Used as an opaque for the object properties we add for each
- * array element. Note that the struct Property must be first
- * in the struct so that a pointer to this works as the opaque
- * for the underlying element's property hooks as well as for
- * our own release callback.
- */
-typedef struct {
-    struct Property prop;
-} ArrayElementProperty;
-
 /* object property release callback for array element properties:
  * we call the underlying element's property release hook, and
  * then free the memory we allocated when we added the property.
  */
 static void array_element_release(Object *obj, const char *name, void *opaque)
 {
-    ArrayElementProperty *p = opaque;
-    if (p->prop.info->release) {
-        p->prop.info->release(obj, name, opaque);
+    Property *prop = opaque;
+    if (prop->info->release) {
+        prop->info->release(obj, name, opaque);
     }
-    g_free(p);
+    g_free(prop);
 }
 
 static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
@@ -585,20 +575,20 @@ static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
     *arrayptr = eltptr = g_malloc0(*alenptr * prop->arrayfieldsize);
     for (i = 0; i < *alenptr; i++, eltptr += prop->arrayfieldsize) {
         g_autofree char *propname = g_strdup_printf("%s[%d]", arrayname, i);
-        ArrayElementProperty *arrayprop = g_new0(ArrayElementProperty, 1);
+        Property *arrayprop = g_new0(Property, 1);
         ObjectProperty *elmop;
-        arrayprop->prop.info = prop->arrayinfo;
+        arrayprop->info = prop->arrayinfo;
         /* This ugly piece of pointer arithmetic sets up the offset so
          * that when the underlying get/set hooks call qdev_get_prop_ptr
          * they get the right answer despite the array element not actually
          * being inside the device struct.
          */
-        arrayprop->prop.offset = eltptr - (void *)obj;
-        assert(object_field_prop_ptr(obj, &arrayprop->prop) == eltptr);
+        arrayprop->offset = eltptr - (void *)obj;
+        assert(object_field_prop_ptr(obj, arrayprop) == eltptr);
         elmop = object_property_add(obj, propname,
-                                    arrayprop->prop.info->name,
-                                    field_prop_getter(arrayprop->prop.info),
-                                    field_prop_setter(arrayprop->prop.info),
+                                    arrayprop->info->name,
+                                    field_prop_getter(arrayprop->info),
+                                    field_prop_setter(arrayprop->info),
                                     array_element_release,
                                     arrayprop);
         elmop->allow_set = op->allow_set;
Signature · 1 line
2.28.0
#42 lore raw

PATCH v3 40/53 qdev: Rename array_element_release() to static_prop_release_dynamic_prop()

In reply to Eduardo Habkost

The function is now generic and can be used by any property that had the Property struct allocated dynamically.

---
This is a new patch added in v3 of the series.
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-properties.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/core/qdev-properties.c +4 -3
index 0ffef5ab4f..d5773ffd8a 100644
@@ -521,11 +521,12 @@ const PropertyInfo prop_info_size32 = {
 
 /* --- support for array properties --- */
 
-/* object property release callback for array element properties:
+/* object property release callback for dynamically-created properties:
  * we call the underlying element's property release hook, and
  * then free the memory we allocated when we added the property.
  */
-static void array_element_release(Object *obj, const char *name, void *opaque)
+static void static_prop_release_dynamic_prop(Object *obj, const char *name,
+                                             void *opaque)
 {
     Property *prop = opaque;
     if (prop->info->release) {
@@ -589,7 +590,7 @@ static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
                                     arrayprop->info->name,
                                     field_prop_getter(arrayprop->info),
                                     field_prop_setter(arrayprop->info),
-                                    array_element_release,
+                                    static_prop_release_dynamic_prop,
                                     arrayprop);
         elmop->allow_set = op->allow_set;
     }
Signature · 1 line
2.28.0
#43 lore raw

PATCH v3 41/53 qdev: Make object_property_add_field() copy the Property struct

In reply to Eduardo Habkost

This will make the function more convenient to use, and allow us to reuse it for array element properties.

I'm not adding a version of this function that doesn't copy the struct, because this function isn't supposed to be used widely.

---
This is a new patch added in v3 of the series.
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-properties.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
hw/core/qdev-properties.c +10 -8
index d5773ffd8a..451bb54cf6 100644
@@ -828,21 +828,23 @@ object_property_add_field(Object *obj, const char *name,
                           ObjectPropertyAllowSet allow_set)
 {
     ObjectProperty *op;
+    Property *newprop = g_new0(Property, 1);
 
     assert(allow_set);
     assert(!prop->info->create);
 
-    op = object_property_add(obj, name, prop->info->name,
-                             field_prop_getter(prop->info),
-                             field_prop_setter(prop->info),
-                             prop->info->release,
-                             prop);
+    *newprop = *prop;
+    op = object_property_add(obj, name, newprop->info->name,
+                             field_prop_getter(newprop->info),
+                             field_prop_setter(newprop->info),
+                             static_prop_release_dynamic_prop,
+                             newprop);
 
     object_property_set_description(obj, name,
-                                    prop->info->description);
+                                    newprop->info->description);
 
-    if (prop->set_default) {
-        prop->info->set_default_value(op, prop);
+    if (newprop->set_default) {
+        newprop->info->set_default_value(op, newprop);
         if (op->init) {
             op->init(obj, op);
         }
Signature · 1 line
2.28.0
#44 lore raw

PATCH v3 42/53 qdev: Reuse object_property_add_field() when adding array elements

In reply to Eduardo Habkost

Now that we call object_property_add() with exactly the same arguments as object_property_add_field() does, we can just reuse the function. We can now use a stack variable for the new Property struct, because object_property_add_field() will copy the struct.

---
Changes v2 -> v3:
* Fix memory leak from v2, after making object_property_add_field() copy the Property struct

Changes v1 -> v2:
* Now we don't need to hack ObjectProperty.release anymore, patch became trivial
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-properties.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
hw/core/qdev-properties.c +6 -12
index 451bb54cf6..83fd45add0 100644
@@ -576,23 +576,17 @@ static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
     *arrayptr = eltptr = g_malloc0(*alenptr * prop->arrayfieldsize);
     for (i = 0; i < *alenptr; i++, eltptr += prop->arrayfieldsize) {
         g_autofree char *propname = g_strdup_printf("%s[%d]", arrayname, i);
-        Property *arrayprop = g_new0(Property, 1);
-        ObjectProperty *elmop;
-        arrayprop->info = prop->arrayinfo;
+        Property arrayprop = { };
+        arrayprop.info = prop->arrayinfo;
         /* This ugly piece of pointer arithmetic sets up the offset so
          * that when the underlying get/set hooks call qdev_get_prop_ptr
          * they get the right answer despite the array element not actually
          * being inside the device struct.
          */
-        arrayprop->offset = eltptr - (void *)obj;
-        assert(object_field_prop_ptr(obj, arrayprop) == eltptr);
-        elmop = object_property_add(obj, propname,
-                                    arrayprop->info->name,
-                                    field_prop_getter(arrayprop->info),
-                                    field_prop_setter(arrayprop->info),
-                                    static_prop_release_dynamic_prop,
-                                    arrayprop);
-        elmop->allow_set = op->allow_set;
+        arrayprop.offset = eltptr - (void *)obj;
+        assert(object_field_prop_ptr(obj, &arrayprop) == eltptr);
+        object_property_add_field(obj, propname, &arrayprop,
+                                  op->allow_set);
     }
 }
 
Signature · 1 line
2.28.0
#45 lore raw

PATCH v3 43/53 qdev: Move static_prop_release_dynamic_prop() closer to its usage

In reply to Eduardo Habkost

Move the function closer to where it's used, to make refactor and review simpler. While doing it, reformat the comment at the top to follow coding style.

---
This is a new patch added in v3 of the series.
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 hw/core/qdev-properties.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
hw/core/qdev-properties.c +15 -14
index 83fd45add0..7aa5d2ff45 100644
@@ -521,20 +521,6 @@ const PropertyInfo prop_info_size32 = {
 
 /* --- support for array properties --- */
 
-/* object property release callback for dynamically-created properties:
- * we call the underlying element's property release hook, and
- * then free the memory we allocated when we added the property.
- */
-static void static_prop_release_dynamic_prop(Object *obj, const char *name,
-                                             void *opaque)
-{
-    Property *prop = opaque;
-    if (prop->info->release) {
-        prop->info->release(obj, name, opaque);
-    }
-    g_free(prop);
-}
-
 static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
                               void *opaque, Error **errp)
 {
@@ -816,6 +802,21 @@ const PropertyInfo prop_info_link = {
     .create = create_link_property,
 };
 
+/*
+ * Property release callback for dynamically-created properties:
+ * We call the underlying element's property release hook, and
+ * then free the memory we allocated when we added the property.
+ */
+static void static_prop_release_dynamic_prop(Object *obj, const char *name,
+                                             void *opaque)
+{
+    Property *prop = opaque;
+    if (prop->info->release) {
+        prop->info->release(obj, name, opaque);
+    }
+    g_free(prop);
+}
+
 ObjectProperty *
 object_property_add_field(Object *obj, const char *name,
                           Property *prop,
Signature · 1 line
2.28.0
#46 lore raw

PATCH v3 44/53 qom: Add new qom.h header

In reply to Eduardo Habkost

Multiple QOM features will be provided by different headers. Add a qom/qom.h header to make it easier to include all of them at once.

---
This is a new patch added in v3 of the series.
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 include/qom/qom.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
 create mode 100644 include/qom/qom.h
include/qom/qom.h new file +10 -0
new file mode 100644
index 0000000000..3286605083
@@ -0,0 +1,10 @@
+/*
+ * QEMU Object Model convenience header
+ *
+ * This header is not supposed to be included by other headers
+ * but by .c files that use QOM.
+ */
+
+#include "qom/object.h"
+#include "qom/object_interfaces.h"
+#include "qom/qom-qobject.h"
Signature · 1 line
2.28.0
#47 lore raw

PATCH v3 45/53 qdev: Move core field property code to QOM

In reply to Eduardo Habkost

Move the core of the static property code to qom/field-property.c.

The actual property type implementations are still in qdev-properties.c, they will be moved later.

---
Changes v2 -> v3:
* Redone patch after changes in previous patches of this series
* Reordered patch, tried to place it a bit earlier in the series

Changes v1 -> v2:
* Rename static-property.* to field-property.*
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 include/hw/qdev-properties.h                  |  49 +------
 .../qom/field-property-internal.h             |   6 +-
 include/qom/field-property.h                  |  57 ++++++++
 include/qom/qom.h                             |   1 +
 hw/core/qdev-properties-system.c              |   2 +-
 hw/core/qdev-properties.c                     | 134 +----------------
 qom/field-property.c                          | 137 ++++++++++++++++++
 qom/meson.build                               |   1 +
 8 files changed, 202 insertions(+), 185 deletions(-)
 rename hw/core/qdev-prop-internal.h => include/qom/field-property-internal.h (95%)
 create mode 100644 include/qom/field-property.h
 create mode 100644 qom/field-property.c
include/hw/qdev-properties.h +1 -48
index 1208e12b9b..6585a8e693 100644
@@ -2,52 +2,7 @@
 #define QEMU_QDEV_PROPERTIES_H
 
 #include "hw/qdev-core.h"
-
-/**
- * Property:
- * @set_default: true if the default value should be set from @defval,
- *    in which case @info->set_default_value must not be NULL
- *    (if false then no default value is set by the property system
- *     and the field retains whatever value it was given by instance_init).
- * @defval: default value for the property. This is used only if @set_default
- *     is true.
- */
-struct Property {
-    /**
-     * @name_template: Property name template
-     *
-     * This is a string containing the template to be used when
-     * creating the property.  It can be NULL, and code shouldn't
-     * assume it will contain the actual property name.
-     */
-    const char   *name_template;
-    const PropertyInfo *info;
-    ptrdiff_t    offset;
-    uint8_t      bitnr;
-    bool         set_default;
-    union {
-        int64_t i;
-        uint64_t u;
-    } defval;
-    int          arrayoffset;
-    const PropertyInfo *arrayinfo;
-    int          arrayfieldsize;
-    const char   *link_type;
-};
-
-struct PropertyInfo {
-    const char *name;
-    const char *description;
-    const QEnumLookup *enum_table;
-    int (*print)(Object *obj, Property *prop, char *dest, size_t len);
-    void (*set_default_value)(ObjectProperty *op, const Property *prop);
-    ObjectProperty *(*create)(ObjectClass *oc, const char *name,
-                              Property *prop);
-    ObjectPropertyAccessor *get;
-    ObjectPropertyAccessor *set;
-    ObjectPropertyRelease *release;
-};
-
+#include "qom/field-property.h"
 
 /*** qdev-properties.c ***/
 
@@ -200,8 +155,6 @@ void qdev_prop_set_macaddr(DeviceState *dev, const char *name,
                            const uint8_t *value);
 void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
 
-void *object_field_prop_ptr(Object *obj, Property *prop);
-
 void qdev_prop_register_global(GlobalProperty *prop);
 const GlobalProperty *qdev_find_global_prop(Object *obj,
                                             const char *name);
include/qom/field-property-internal.h renamed from hw/core/qdev-prop-internal.h +3 -3
similarity index 95%
rename from hw/core/qdev-prop-internal.h
rename to include/qom/field-property-internal.h
index 47bab46810..a7b7e2b69d 100644
@@ -1,12 +1,12 @@
 /*
- * qdev property parsing
+ * QOM field property internal API (for implementing custom types)
  *
  * This work is licensed under the terms of the GNU GPL, version 2 or later.
  * See the COPYING file in the top-level directory.
  */
 
-#ifndef HW_CORE_QDEV_PROP_INTERNAL_H
-#define HW_CORE_QDEV_PROP_INTERNAL_H
+#ifndef QOM_STATIC_PROPERTY_INTERNAL_H
+#define QOM_STATIC_PROPERTY_INTERNAL_H
 
 void field_prop_get_enum(Object *obj, Visitor *v, const char *name,
                          void *opaque, Error **errp);
include/qom/field-property.h new file +57 -0

57 lines not on this page · raw message

include/qom/qom.h +1 -0
index 3286605083..9dbc88801d 100644
@@ -8,3 +8,4 @@
 #include "qom/object.h"
 #include "qom/object_interfaces.h"
 #include "qom/qom-qobject.h"
+#include "qom/field-property.h"
hw/core/qdev-properties-system.c +1 -1
index 8781b856d3..8da68f076c 100644
@@ -24,7 +24,7 @@
 #include "qemu/units.h"
 #include "qemu/uuid.h"
 #include "qemu/error-report.h"
-#include "qdev-prop-internal.h"
+#include "qom/field-property-internal.h"
 
 #include "audio/audio.h"
 #include "chardev/char-fe.h"
hw/core/qdev-properties.c +1 -133

152 lines not on this page · raw message

qom/field-property.c new file +137 -0

137 lines not on this page · raw message

qom/meson.build +1 -0
index 062a3789d8..e83794454d 100644
@@ -4,6 +4,7 @@ qom_ss.add(files(
   'object.c',
   'object_interfaces.c',
   'qom-qobject.c',
+  'field-property.c',
 ))
 
 qmp_ss.add(files('qom-qmp-cmds.c'))
Signature · 1 line
2.28.0
#48 lore raw

PATCH v3 46/53 qdev: Move base property types to qom/property-types.c

In reply to Eduardo Habkost

Move all property types from qdev-properties.c to qom/property-types.c. Declarations are moved from hw/qdev-properties.h to qom/property-types.h.

---
Changes v2 -> v3:
* Redone after changes in previous patches in this series
* Reordered patch, tried to put it a bit earlier in the series

Changes v1 -> v2:
* Rebased after changes in previous patches in the series
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 include/hw/qdev-properties.h | 125 +-------
 include/qom/property-types.h | 131 +++++++++
 include/qom/qom.h            |   1 +
 hw/core/qdev-properties.c    | 538 ----------------------------------
 qom/property-types.c         | 546 +++++++++++++++++++++++++++++++++++
 qom/meson.build              |   1 +
 6 files changed, 680 insertions(+), 662 deletions(-)
 create mode 100644 include/qom/property-types.h
 create mode 100644 qom/property-types.c
include/hw/qdev-properties.h +1 -124
index 6585a8e693..939b6dbf4e 100644
@@ -3,130 +3,7 @@
 
 #include "hw/qdev-core.h"
 #include "qom/field-property.h"
-
-/*** qdev-properties.c ***/
-
-extern const PropertyInfo prop_info_bit;
-extern const PropertyInfo prop_info_bit64;
-extern const PropertyInfo prop_info_bool;
-extern const PropertyInfo prop_info_enum;
-extern const PropertyInfo prop_info_uint8;
-extern const PropertyInfo prop_info_uint16;
-extern const PropertyInfo prop_info_uint32;
-extern const PropertyInfo prop_info_int32;
-extern const PropertyInfo prop_info_uint64;
-extern const PropertyInfo prop_info_int64;
-extern const PropertyInfo prop_info_size;
-extern const PropertyInfo prop_info_string;
-extern const PropertyInfo prop_info_on_off_auto;
-extern const PropertyInfo prop_info_size32;
-extern const PropertyInfo prop_info_arraylen;
-extern const PropertyInfo prop_info_link;
-
-#define DEFINE_PROP(_name, _state, _field, _prop, _type, ...) {  \
-        .name_template = (_name),                           \
-        .info      = &(_prop),                                   \
-        .offset    = offsetof(_state, _field)                    \
-            + type_check(_type, typeof_field(_state, _field)),   \
-        __VA_ARGS__                                              \
-        }
-
-#define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) \
-    DEFINE_PROP(_name, _state, _field, _prop, _type,                     \
-                .set_default = true,                                     \
-                .defval.i    = (_type)_defval)
-
-#define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \
-    DEFINE_PROP(_name, _state, _field, _prop, _type)
-
-#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval)   \
-    DEFINE_PROP(_name, _state, _field, prop_info_bit, uint32_t, \
-                .bitnr       = (_bit),                          \
-                .set_default = true,                            \
-                .defval.u    = (bool)_defval)
-
-#define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) \
-    DEFINE_PROP(_name, _state, _field, _prop, _type,                       \
-                .set_default = true,                                       \
-                .defval.u  = (_type)_defval)
-
-#define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \
-    DEFINE_PROP(_name, _state, _field, _prop, _type)
-
-#define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval)   \
-    DEFINE_PROP(_name, _state, _field, prop_info_bit64, uint64_t, \
-                .bitnr    = (_bit),                               \
-                .set_default = true,                              \
-                .defval.u  = (bool)_defval)
-
-#define DEFINE_PROP_BOOL(_name, _state, _field, _defval)     \
-    DEFINE_PROP(_name, _state, _field, prop_info_bool, bool, \
-                .set_default = true,                         \
-                .defval.u    = (bool)_defval)
-
-#define PROP_ARRAY_LEN_PREFIX "len-"
-
-/**
- * DEFINE_PROP_ARRAY:
- * @_name: name of the array
- * @_state: name of the device state structure type
- * @_field: uint32_t field in @_state to hold the array length
- * @_arrayfield: field in @_state (of type '@_arraytype *') which
- *               will point to the array
- * @_arrayprop: PropertyInfo defining what property the array elements have
- * @_arraytype: C type of the array elements
- *
- * Define device properties for a variable-length array _name.  A
- * static property "len-arrayname" is defined. When the device creator
- * sets this property to the desired length of array, further dynamic
- * properties "arrayname[0]", "arrayname[1]", ...  are defined so the
- * device creator can set the array element values. Setting the
- * "len-arrayname" property more than once is an error.
- *
- * When the array length is set, the @_field member of the device
- * struct is set to the array length, and @_arrayfield is set to point
- * to (zero-initialised) memory allocated for the array.  For a zero
- * length array, @_field will be set to 0 and @_arrayfield to NULL.
- * It is the responsibility of the device deinit code to free the
- * @_arrayfield memory.
- */
-#define DEFINE_PROP_ARRAY(_name, _state, _field,               \
-                          _arrayfield, _arrayprop, _arraytype) \
-    DEFINE_PROP((PROP_ARRAY_LEN_PREFIX _name),                 \
-                _state, _field, prop_info_arraylen, uint32_t,  \
-                .set_default = true,                           \
-                .defval.u = 0,                                 \
-                .arrayinfo = &(_arrayprop),                    \
-                .arrayfieldsize = sizeof(_arraytype),          \
-                .arrayoffset = offsetof(_state, _arrayfield))
-
-#define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type)     \
-    DEFINE_PROP(_name, _state, _field, prop_info_link, _ptr_type,     \
-                .link_type  = _type)
-
-#define DEFINE_PROP_UINT8(_n, _s, _f, _d)                       \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint8, uint8_t)
-#define DEFINE_PROP_UINT16(_n, _s, _f, _d)                      \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint16, uint16_t)
-#define DEFINE_PROP_UINT32(_n, _s, _f, _d)                      \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint32, uint32_t)
-#define DEFINE_PROP_INT32(_n, _s, _f, _d)                      \
-    DEFINE_PROP_SIGNED(_n, _s, _f, _d, prop_info_int32, int32_t)
-#define DEFINE_PROP_UINT64(_n, _s, _f, _d)                      \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint64, uint64_t)
-#define DEFINE_PROP_INT64(_n, _s, _f, _d)                      \
-    DEFINE_PROP_SIGNED(_n, _s, _f, _d, prop_info_int64, int64_t)
-#define DEFINE_PROP_SIZE(_n, _s, _f, _d)                       \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_size, uint64_t)
-#define DEFINE_PROP_STRING(_n, _s, _f)             \
-    DEFINE_PROP(_n, _s, _f, prop_info_string, char*)
-#define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \
-    DEFINE_PROP_SIGNED(_n, _s, _f, _d, prop_info_on_off_auto, OnOffAuto)
-#define DEFINE_PROP_SIZE32(_n, _s, _f, _d)                       \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_size32, uint32_t)
-
-#define DEFINE_PROP_END_OF_LIST()               \
-    {}
+#include "qom/property-types.h"
 
 /*
  * Set properties between creation and realization.
include/qom/property-types.h new file +131 -0

131 lines not on this page · raw message

include/qom/qom.h +1 -0
index 9dbc88801d..ef37a317c3 100644
@@ -9,3 +9,4 @@
 #include "qom/object_interfaces.h"
 #include "qom/qom-qobject.h"
 #include "qom/field-property.h"
+#include "qom/property-types.h"
hw/core/qdev-properties.c +0 -538

550 lines not on this page · raw message

qom/property-types.c new file +546 -0

546 lines not on this page · raw message

qom/meson.build +1 -0
index e83794454d..7fdfd6fe7b 100644
@@ -5,6 +5,7 @@ qom_ss.add(files(
   'object_interfaces.c',
   'qom-qobject.c',
   'field-property.c',
+  'property-types.c',
 ))
 
 qmp_ss.add(files('qom-qmp-cmds.c'))
Signature · 1 line
2.28.0
#49 lore raw

PATCH v3 47/53 qom: Include static property API reference in documentation

In reply to Eduardo Habkost

Include the static-properties.h API reference in
docs/devel/qom.rst.

---
Changes v2 -> v3:
* Redone patch after changes in previous patches in the series
* Split into separate patches. This one only adds the file to qom.rst and Property/PropertyInfo doc comments. Another patch will add the documentation for DEFINE_PROP_* and PROP_*.

Changes v1 -> v2:
* Redone patch after changes in previous patches in the series
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 docs/devel/qom.rst           | 17 +++++++++++++-
 include/qom/field-property.h | 45 ++++++++++++++++++++++++++++++------
 include/qom/property-types.h |  2 +-
 3 files changed, 55 insertions(+), 9 deletions(-)
docs/devel/qom.rst +16 -1
index 42d0dc4f4d..9e43aa46f2 100644
@@ -376,6 +376,21 @@ the OBJECT_DEFINE_ABSTRACT_TYPE() macro can be used instead:
 
 
 API Reference
--------------
+=============
+
+Core QOM API Reference
+----------------------
 
 .. kernel-doc:: include/qom/object.h
+
+
+Field Property API Reference
+----------------------------
+
+.. kernel-doc:: include/qom/field-property.h
+
+
+Property Types Reference
+------------------------
+
+.. kernel-doc:: include/qom/property-types.h
include/qom/field-property.h +38 -7

80 lines not on this page · raw message

include/qom/property-types.h +1 -1
index 0aff0d9474..46c82da4e3 100644
@@ -71,7 +71,7 @@ extern const PropertyInfo prop_info_link;
  * @_name: name of the array
  * @_state: name of the device state structure type
  * @_field: uint32_t field in @_state to hold the array length
- * @_arrayfield: field in @_state (of type '@_arraytype *') which
+ * @_arrayfield: field in @_state (of type ``_arraytype *``) which
  *               will point to the array
  * @_arrayprop: PropertyInfo defining what property the array elements have
  * @_arraytype: C type of the array elements
Signature · 1 line
2.28.0
#50 lore raw

PATCH v3 48/53 qom: object_class_property_add_field() function

In reply to Eduardo Habkost

It is similar to object_class_property_add_field_static(), but gets a copy of a Property struct so we don't need static variables.

---
This is a new patch added in v3 of this series, but v2 had a object_class_property_add_field() function too.

This version of object_class_property_add_field() is slightly different from the one in v2, as it gets a copy of the Property struct (so it won't require static variables anymore).
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 include/qom/field-property.h | 23 +++++++++++++++++++++++
 qom/field-property.c         | 14 ++++++++++++++
 2 files changed, 37 insertions(+)
include/qom/field-property.h +23 -0
index 419e5eef75..a904f98609 100644
@@ -83,6 +83,29 @@ struct PropertyInfo {
     ObjectPropertyRelease *release;
 };
 
+/**
+ * object_class_property_add_field: Add a field property to object class
+ * @oc: object class
+ * @name: property name
+ * @prop: property definition
+ * @allow_set: check function called when property is set
+ *
+ * Add a field property to an object class.  A field property is
+ * a property that will change a field at a specific offset of the
+ * object instance struct.
+ *
+ * Note that data pointed by @prop (like strings or pointers to
+ * other structs) are not copied and must have static life time.
+ *
+ * @allow_set should not be NULL.  If the property can always be
+ * set, `prop_allow_set_always` can be used.  If the property can
+ * never be set, `prop_allow_set_never` can be used.
+ */
+ObjectProperty *
+object_class_property_add_field(ObjectClass *oc, const char *name,
+                                Property prop,
+                                ObjectPropertyAllowSet allow_set);
+
 void *object_field_prop_ptr(Object *obj, Property *prop);
 
 #endif
qom/field-property.c +14 -0
index 1fd11f2ad3..cb729626ce 100644
@@ -125,6 +125,20 @@ object_class_property_add_field_static(ObjectClass *oc, const char *name,
     return op;
 }
 
+ObjectProperty *
+object_class_property_add_field(ObjectClass *oc, const char *name,
+                                Property prop,
+                                ObjectPropertyAllowSet allow_set)
+{
+    /*
+     * QOM classes and class properties are never deallocated, so we don't
+     * have a corresponding release function that will free newprop.
+     */
+    Property *newprop = g_new0(Property, 1);
+    *newprop = prop;
+    return object_class_property_add_field_static(oc, name, newprop, allow_set);
+}
+
 void object_class_add_field_properties(ObjectClass *oc, Property *props,
                                        ObjectPropertyAllowSet allow_set)
 {
Signature · 1 line
2.28.0
#51 lore raw

PATCH v3 49/53 qom: FIELD_PROP macro

In reply to Eduardo Habkost

The FIELD_PROP macro can be used to define a Property struct when initializing static variables, or as a function parameter (e.g. as a paramter to object_class_property_add_field()).

The qdev-specific DEFINE_PROP macro can be defined using the new macro. The only difference is that DEFINE_PROP gets the property name as the first argument.

---
This is a new patch added in v3 of this series.
---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 include/qom/field-property.h | 17 +++++++++++++++++
 include/qom/property-types.h | 26 +++++++++++++++++++-------
 2 files changed, 36 insertions(+), 7 deletions(-)
include/qom/field-property.h +17 -0
index a904f98609..0cb1fe2217 100644
@@ -108,4 +108,21 @@ object_class_property_add_field(ObjectClass *oc, const char *name,
 
 void *object_field_prop_ptr(Object *obj, Property *prop);
 
+/**
+ * FIELD_PROP: Expands to a compound literal for a #Property struct
+ *
+ * @_state: name of the object state structure type
+ * @_field: name of field in @_state
+ * @_prop: name of #PropertyInfo variable with type information
+ * @_type: expected type of field @_field in struct @_state
+ * @...: additional initializers for #Property struct fields
+ */
+#define FIELD_PROP(_state, _field, _prop, _type, ...) \
+    (Property) {                                                 \
+        .info      = &(_prop),                                   \
+        .offset    = offsetof(_state, _field)                    \
+            + type_check(_type, typeof_field(_state, _field)),   \
+        __VA_ARGS__                                              \
+    }
+
 #endif
include/qom/property-types.h +19 -7
index 46c82da4e3..62551c77e0 100644
@@ -23,13 +23,25 @@ extern const PropertyInfo prop_info_size32;
 extern const PropertyInfo prop_info_arraylen;
 extern const PropertyInfo prop_info_link;
 
-#define DEFINE_PROP(_name, _state, _field, _prop, _type, ...) {  \
-        .name_template = (_name),                           \
-        .info      = &(_prop),                                   \
-        .offset    = offsetof(_state, _field)                    \
-            + type_check(_type, typeof_field(_state, _field)),   \
-        __VA_ARGS__                                              \
-        }
+/**
+ * DEFINE_PROP: Define a #Property struct, including a property name
+ *
+ * @_name: name of the property
+ * @_state: name of the object state structure type
+ * @_field: name of field in @_state
+ * @_prop: name of #PropertyInfo variable with type information
+ * @_type: expected type of field @_field in struct @_state
+ * @...: additional initializers for #Property struct fields
+ *
+ * `DEFINE_PROP` or other ``DEFINE_PROP_*`` macros are normally
+ * used when initialiing static const #Property arrays, to be
+ * used with object_class_add_field_properties() or
+ * device_class_set_props().
+ */
+#define DEFINE_PROP(_name, _state, _field, _prop, _type, ...) \
+    FIELD_PROP(_state, _field, _prop, _type,                  \
+               .name_template = (_name),                      \
+               __VA_ARGS__)
 
 #define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) \
     DEFINE_PROP(_name, _state, _field, _prop, _type,                     \
Signature · 1 line
2.28.0
#52 lore raw

PATCH v3 50/53 qom: Delete DEFINE_PROP_*SIGNED_NODEFAULT macro

In reply to Eduardo Habkost

Those macros are exactly the same as DEFINE_PROP, we can use DEFINE_PROP directly.

---
This is a new patch added in v3 of this series.
---
Cc: Alex Williamson <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Peter Maydell <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 include/qom/property-types.h | 6 ------
 hw/vfio/pci.c                | 6 +++---
 target/arm/cpu.c             | 6 +++---
 3 files changed, 6 insertions(+), 12 deletions(-)
include/qom/property-types.h +0 -6
index 62551c77e0..91b166badf 100644
@@ -48,9 +48,6 @@ extern const PropertyInfo prop_info_link;
                 .set_default = true,                                     \
                 .defval.i    = (_type)_defval)
 
-#define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \
-    DEFINE_PROP(_name, _state, _field, _prop, _type)
-
 #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval)   \
     DEFINE_PROP(_name, _state, _field, prop_info_bit, uint32_t, \
                 .bitnr       = (_bit),                          \
@@ -62,9 +59,6 @@ extern const PropertyInfo prop_info_link;
                 .set_default = true,                                       \
                 .defval.u  = (_type)_defval)
 
-#define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \
-    DEFINE_PROP(_name, _state, _field, _prop, _type)
-
 #define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval)   \
     DEFINE_PROP(_name, _state, _field, prop_info_bit64, uint64_t, \
                 .bitnr    = (_bit),                               \
hw/vfio/pci.c +3 -3
index edfaed8c9a..f15abacbdf 100644
@@ -3214,9 +3214,9 @@ static Property vfio_pci_dev_properties[] = {
     DEFINE_PROP_UINT32("x-pci-sub-device-id", VFIOPCIDevice,
                        sub_device_id, PCI_ANY_ID),
     DEFINE_PROP_UINT32("x-igd-gms", VFIOPCIDevice, igd_gms, 0),
-    DEFINE_PROP_UNSIGNED_NODEFAULT("x-nv-gpudirect-clique", VFIOPCIDevice,
-                                   nv_gpudirect_clique,
-                                   qdev_prop_nv_gpudirect_clique, uint8_t),
+    DEFINE_PROP("x-nv-gpudirect-clique", VFIOPCIDevice,
+                nv_gpudirect_clique,
+                qdev_prop_nv_gpudirect_clique, uint8_t),
     DEFINE_PROP_OFF_AUTO_PCIBAR("x-msix-relocation", VFIOPCIDevice, msix_relo,
                                 OFF_AUTOPCIBAR_OFF),
     /*
target/arm/cpu.c +3 -3
index cef92879b0..7cf2078622 100644
@@ -1106,9 +1106,9 @@ static Property arm_cpu_has_mpu_property =
  * to override that with an incorrect constant value.
  */
 static Property arm_cpu_pmsav7_dregion_property =
-            DEFINE_PROP_UNSIGNED_NODEFAULT("pmsav7-dregion", ARMCPU,
-                                           pmsav7_dregion,
-                                           prop_info_uint32, uint32_t);
+            DEFINE_PROP("pmsav7-dregion", ARMCPU,
+                        pmsav7_dregion,
+                        prop_info_uint32, uint32_t);
 
 static bool arm_get_pmu(Object *obj, Error **errp)
 {
Signature · 1 line
2.28.0
#53 lore raw

PATCH v3 51/53 qom: PROP_* macros

In reply to Eduardo Habkost

The new helper macros are similar to the old DEFINE_PROP_* macros, but don't take a name argument. They can be used directly as argument to object_class_property_add_field().

The DEFINE_PROP_* macros were redefined to just be wrappers to PROP_*.

---
Changes v2 -> v3:
* Now the DEFINE_PROP_* macros are defined using PROP_*, not the other way around
* Remove unused macros (PROP_UNSIGNED*, PROP_SIGNED*, PROP_UUID)
* Removed PROP_ARRAY because it isn't as trivial as the others
* Now PROP_* won't return a pointer to a static variable anymore, but just a compound literal for a Property struct.

This is a new patch added in v2 of the series

---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 include/qom/property-types.h | 141 ++++++++++++++++++++++-------------
 1 file changed, 90 insertions(+), 51 deletions(-)
include/qom/property-types.h +90 -51
index 91b166badf..3132ddafd9 100644
@@ -23,6 +23,64 @@ extern const PropertyInfo prop_info_size32;
 extern const PropertyInfo prop_info_arraylen;
 extern const PropertyInfo prop_info_link;
 
+#define PROP_SIGNED(_state, _field, _defval, _prop, _type, ...) \
+    FIELD_PROP(_state, _field, _prop, _type,                    \
+               .set_default = true,                             \
+               .defval.i    = (_type)_defval,                   \
+               __VA_ARGS__)
+
+#define PROP_UNSIGNED(_state, _field, _defval, _prop, _type, ...) \
+    FIELD_PROP(_state, _field, _prop, _type,                    \
+               .set_default = true,                             \
+               .defval.u  = (_type)_defval,                     \
+               __VA_ARGS__)
+
+#define PROP_BIT(_state, _field, _bit, _defval, ...) \
+    FIELD_PROP(_state, _field, prop_info_bit, uint32_t,         \
+               .bitnr       = (_bit),                           \
+               .set_default = true,                             \
+               .defval.u    = (bool)_defval,                    \
+               __VA_ARGS__)
+
+#define PROP_BIT64(_state, _field, _bit, _defval, ...) \
+    FIELD_PROP(_state, _field, prop_info_bit64, uint64_t,       \
+               .bitnr    = (_bit),                              \
+               .set_default = true,                             \
+               .defval.u  = (bool)_defval,                      \
+               __VA_ARGS__)
+
+#define PROP_BOOL(_state, _field, _defval, ...) \
+    FIELD_PROP(_state, _field, prop_info_bool, bool,            \
+               .set_default = true,                             \
+               .defval.u    = (bool)_defval,                    \
+               __VA_ARGS__)
+
+#define PROP_LINK(_state, _field, _type, _ptr_type, ...) \
+    FIELD_PROP(_state, _field, prop_info_link, _ptr_type,       \
+               .link_type  = _type,                             \
+               __VA_ARGS__)
+
+#define PROP_UINT8(_s, _f, _d, ...) \
+    PROP_UNSIGNED(_s, _f, _d, prop_info_uint8, uint8_t, __VA_ARGS__)
+#define PROP_UINT16(_s, _f, _d, ...) \
+    PROP_UNSIGNED(_s, _f, _d, prop_info_uint16, uint16_t, __VA_ARGS__)
+#define PROP_UINT32(_s, _f, _d, ...) \
+    PROP_UNSIGNED(_s, _f, _d, prop_info_uint32, uint32_t, __VA_ARGS__)
+#define PROP_INT32(_s, _f, _d, ...) \
+    PROP_SIGNED(_s, _f, _d, prop_info_int32, int32_t, __VA_ARGS__)
+#define PROP_UINT64(_s, _f, _d, ...) \
+    PROP_UNSIGNED(_s, _f, _d, prop_info_uint64, uint64_t, __VA_ARGS__)
+#define PROP_INT64(_s, _f, _d, ...) \
+    PROP_SIGNED(_s, _f, _d, prop_info_int64, int64_t, __VA_ARGS__)
+#define PROP_SIZE(_s, _f, _d, ...) \
+    PROP_UNSIGNED(_s, _f, _d, prop_info_size, uint64_t, __VA_ARGS__)
+#define PROP_STRING(_s, _f, ...) \
+    FIELD_PROP(_s, _f, prop_info_string, char*, __VA_ARGS__)
+#define PROP_ON_OFF_AUTO(_s, _f, _d, ...) \
+    PROP_SIGNED(_s, _f, _d, prop_info_on_off_auto, OnOffAuto, __VA_ARGS__)
+#define PROP_SIZE32(_s, _f, _d, ...) \
+    PROP_UNSIGNED(_s, _f, _d, prop_info_size32, uint32_t, __VA_ARGS__)
+
 /**
  * DEFINE_PROP: Define a #Property struct, including a property name
  *
@@ -43,33 +101,6 @@ extern const PropertyInfo prop_info_link;
                .name_template = (_name),                      \
                __VA_ARGS__)
 
-#define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) \
-    DEFINE_PROP(_name, _state, _field, _prop, _type,                     \
-                .set_default = true,                                     \
-                .defval.i    = (_type)_defval)
-
-#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval)   \
-    DEFINE_PROP(_name, _state, _field, prop_info_bit, uint32_t, \
-                .bitnr       = (_bit),                          \
-                .set_default = true,                            \
-                .defval.u    = (bool)_defval)
-
-#define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) \
-    DEFINE_PROP(_name, _state, _field, _prop, _type,                       \
-                .set_default = true,                                       \
-                .defval.u  = (_type)_defval)
-
-#define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval)   \
-    DEFINE_PROP(_name, _state, _field, prop_info_bit64, uint64_t, \
-                .bitnr    = (_bit),                               \
-                .set_default = true,                              \
-                .defval.u  = (bool)_defval)
-
-#define DEFINE_PROP_BOOL(_name, _state, _field, _defval)     \
-    DEFINE_PROP(_name, _state, _field, prop_info_bool, bool, \
-                .set_default = true,                         \
-                .defval.u    = (bool)_defval)
-
 #define PROP_ARRAY_LEN_PREFIX "len-"
 
 /**
@@ -106,30 +137,38 @@ extern const PropertyInfo prop_info_link;
                 .arrayfieldsize = sizeof(_arraytype),          \
                 .arrayoffset = offsetof(_state, _arrayfield))
 
-#define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type)     \
-    DEFINE_PROP(_name, _state, _field, prop_info_link, _ptr_type,     \
-                .link_type  = _type)
-
-#define DEFINE_PROP_UINT8(_n, _s, _f, _d)                       \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint8, uint8_t)
-#define DEFINE_PROP_UINT16(_n, _s, _f, _d)                      \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint16, uint16_t)
-#define DEFINE_PROP_UINT32(_n, _s, _f, _d)                      \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint32, uint32_t)
-#define DEFINE_PROP_INT32(_n, _s, _f, _d)                      \
-    DEFINE_PROP_SIGNED(_n, _s, _f, _d, prop_info_int32, int32_t)
-#define DEFINE_PROP_UINT64(_n, _s, _f, _d)                      \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint64, uint64_t)
-#define DEFINE_PROP_INT64(_n, _s, _f, _d)                      \
-    DEFINE_PROP_SIGNED(_n, _s, _f, _d, prop_info_int64, int64_t)
-#define DEFINE_PROP_SIZE(_n, _s, _f, _d)                       \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_size, uint64_t)
-#define DEFINE_PROP_STRING(_n, _s, _f)             \
-    DEFINE_PROP(_n, _s, _f, prop_info_string, char*)
-#define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \
-    DEFINE_PROP_SIGNED(_n, _s, _f, _d, prop_info_on_off_auto, OnOffAuto)
-#define DEFINE_PROP_SIZE32(_n, _s, _f, _d)                       \
-    DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_size32, uint32_t)
+#define DEFINE_PROP_SIGNED(_n, ...) \
+    PROP_SIGNED(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_BIT(_n, ...) \
+    PROP_BIT(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_UNSIGNED(_n, ...) \
+    PROP_UNSIGNED(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_BIT64(_n, ...) \
+    PROP_BIT64(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_BOOL(_n, ...) \
+    PROP_BOOL(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_LINK(_n, ...) \
+    PROP_LINK(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_UINT8(_n, ...) \
+    PROP_UINT8(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_UINT16(_n, ...) \
+    PROP_UINT16(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_UINT32(_n, ...) \
+    PROP_UINT32(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_INT32(_n, ...) \
+    PROP_INT32(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_UINT64(_n, ...) \
+    PROP_UINT64(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_INT64(_n, ...) \
+    PROP_INT64(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_SIZE(_n, ...) \
+    PROP_SIZE(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_STRING(_n, ...) \
+    PROP_STRING(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_ON_OFF_AUTO(_n, ...) \
+    PROP_ON_OFF_AUTO(__VA_ARGS__, .name_template = (_n))
+#define DEFINE_PROP_SIZE32(_n, ...) \
+    PROP_SIZE32(__VA_ARGS__, .name_template = (_n))
 
 #define DEFINE_PROP_END_OF_LIST()               \
     {}
Signature · 1 line
2.28.0
#54 lore raw

PATCH v3 52/53 tests: Use field property at check-qom-proplist test case

In reply to Eduardo Habkost

Use the field property system for the "sv" property used at check-qom-proplist.

---
Changes v2 -> v3:
* Don't register a instance field property, as
object_property_add_field() is an internal API

Changes v1 -> v2:
* Use PROP_* and object_class_property_add_field() interface

---
Cc: Paolo Bonzini <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 tests/check-qom-proplist.c | 39 ++++----------------------------------
 1 file changed, 4 insertions(+), 35 deletions(-)
tests/check-qom-proplist.c +4 -35
index 1b76581980..2ded6203fb 100644
@@ -25,7 +25,7 @@
 #include "qemu/module.h"
 #include "qemu/option.h"
 #include "qemu/config-file.h"
-#include "qom/object_interfaces.h"
+#include "qom/qom.h"
 
 
 #define TYPE_DUMMY "qemu-dummy"
@@ -103,26 +103,6 @@ static int dummy_get_av(Object *obj,
     return dobj->av;
 }
 
-
-static void dummy_set_sv(Object *obj,
-                         const char *value,
-                         Error **errp)
-{
-    DummyObject *dobj = DUMMY_OBJECT(obj);
-
-    g_free(dobj->sv);
-    dobj->sv = g_strdup(value);
-}
-
-static char *dummy_get_sv(Object *obj,
-                          Error **errp)
-{
-    DummyObject *dobj = DUMMY_OBJECT(obj);
-
-    return g_strdup(dobj->sv);
-}
-
-
 static void dummy_init(Object *obj)
 {
     object_property_add_bool(obj, "bv",
@@ -130,12 +110,11 @@ static void dummy_init(Object *obj)
                              dummy_set_bv);
 }
 
-
 static void dummy_class_init(ObjectClass *cls, void *data)
 {
-    object_class_property_add_str(cls, "sv",
-                                  dummy_get_sv,
-                                  dummy_set_sv);
+    object_class_property_add_field(cls, "sv",
+                                    PROP_STRING(DummyObject, sv),
+                                    prop_allow_set_always);
     object_class_property_add_enum(cls, "av",
                                    "DummyAnimal",
                                    &dummy_animal_map,
@@ -143,21 +122,11 @@ static void dummy_class_init(ObjectClass *cls, void *data)
                                    dummy_set_av);
 }
 
-
-static void dummy_finalize(Object *obj)
-{
-    DummyObject *dobj = DUMMY_OBJECT(obj);
-
-    g_free(dobj->sv);
-}
-
-
 static const TypeInfo dummy_info = {
     .name          = TYPE_DUMMY,
     .parent        = TYPE_OBJECT,
     .instance_size = sizeof(DummyObject),
     .instance_init = dummy_init,
-    .instance_finalize = dummy_finalize,
     .class_size = sizeof(DummyObjectClass),
     .class_init = dummy_class_init,
     .interfaces = (InterfaceInfo[]) {
Signature · 1 line
2.28.0
#55 lore raw

PATCH v3 53/53 sev: Use class properties

In reply to Eduardo Habkost

Instance properties make introspection hard and are not shown by "-object ...,help". Convert them to class properties.

---
This is a new patch added in v3 of this series.

There was another version of this patch inside series:
Subject: [PATCH 00/12] qom: Make all -object types use only class properties
Message-Id: <[email protected]>
https://lore.kernel.org/qemu-devel/[email protected]

Changes from v1 of the patch:
* Use new object_class_property_add_field() API
to replace object_property_add_uint32_ptr().
(v1 used object_class_property_add_uint32_ptr(), which won't exist anymore)
---
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: [email protected]

---
 target/i386/sev.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
target/i386/sev.c +14 -11
index 93c4d60b82..264ea5a7fb 100644
@@ -28,7 +28,7 @@
 #include "sysemu/runstate.h"
 #include "trace.h"
 #include "migration/blocker.h"
-#include "qom/object.h"
+#include "qom/qom.h"
 
 #define TYPE_SEV_GUEST "sev-guest"
 OBJECT_DECLARE_SIMPLE_TYPE(SevGuestState, SEV_GUEST)
@@ -298,6 +298,19 @@ sev_guest_class_init(ObjectClass *oc, void *data)
                                   sev_guest_set_session_file);
     object_class_property_set_description(oc, "session-file",
             "guest owners session parameters (encoded with base64)");
+
+    object_class_property_add_field(oc, "policy",
+            PROP_UINT32(SevGuestState, policy, DEFAULT_GUEST_POLICY),
+            prop_allow_set_always);
+    object_class_property_add_field(oc, "handle",
+            PROP_UINT32(SevGuestState, handle, 0),
+            prop_allow_set_always);
+    object_class_property_add_field(oc, "cbitpos",
+            PROP_UINT32(SevGuestState, cbitpos, 0),
+            prop_allow_set_always);
+    object_class_property_add_field(oc, "reduced-phys-bits",
+            PROP_UINT32(SevGuestState, reduced_phys_bits, 0),
+            prop_allow_set_always);
 }
 
 static void
@@ -306,16 +319,6 @@ sev_guest_instance_init(Object *obj)
     SevGuestState *sev = SEV_GUEST(obj);
 
     sev->sev_device = g_strdup(DEFAULT_SEV_DEVICE);
-    sev->policy = DEFAULT_GUEST_POLICY;
-    object_property_add_uint32_ptr(obj, "policy", &sev->policy,
-                                   OBJ_PROP_FLAG_READWRITE);
-    object_property_add_uint32_ptr(obj, "handle", &sev->handle,
-                                   OBJ_PROP_FLAG_READWRITE);
-    object_property_add_uint32_ptr(obj, "cbitpos", &sev->cbitpos,
-                                   OBJ_PROP_FLAG_READWRITE);
-    object_property_add_uint32_ptr(obj, "reduced-phys-bits",
-                                   &sev->reduced_phys_bits,
-                                   OBJ_PROP_FLAG_READWRITE);
 }
 
 /* sev guest info */
Signature · 1 line
2.28.0
#56 lore raw
In reply to Eduardo Habkost

Paolo, do you have any objections to adding the field property API in this series to QOM, considering the recent discussions about long term plans for QOM properties?

Note that I still want to perform most of the changes in this series, even if the code is kept inside hw/core. Moving the code to qom is just one extra step, but not essential.

Quoted 284 lines · Eduardo Habkost

Based-on: [email protected]
Git branch: https://gitlab.com/ehabkost/qemu/-/commits/work/qdev-make-generic

This series refactor the qdev property code so the static property system from qdev becomes a common QOM API that can be used by any QOM type.

As an example, at the end of the series we use the new API at:
* check-qom-proplist unit test, to replace the hand-written getter and setter for the "sv" property
* target/i386/sev.c, to replace the instance properties registered using object_property_add_uint32_ptr()

I still want to make object_class_add_field_properties() the recommended interface for registering QOM properties, but this will be done in another series.

Changes v2 -> v3
----------------

* Patches were reordered

* New qom/qom.h header file
(See "qom: Add new qom.h header")

* Fixed memory leak in the array property refactor from v2 (See "qdev: Get rid of ArrayElementProperty struct")

* Made object_property_add_field() copy the Property struct passed as argument, to make the array property memory leak easier to fix
(See "qdev: Make object_property_add_field() copy the Property struct")

* Both object_class_add_field_properties() and object_class_property_add_field() functions are available, but only object_class_property_add_field() are made public by this series. object_class_add_field_properties() is used to implement device_class_set_props().
(See "qom: object_class_property_add_field() function" & "qdev: Separate generic and device-specific property registration")

* Now object_class_property_add_field() will get a copy of the Property struct, to avoid tricks involving static variables in the FIELD_PROP macro.
(See "qom: object_class_property_add_field() function")

* check-qom-proplist won't use object_property_add_field(), as it is an internal API and I don't want to make it a bad example to be followed.
(See "tests: Use field property at check-qom-proplist test case")

* Property.qdev_prop_name is now Property.name_template, because it might be used outside qdev in case we make object_class_add_field_properties() public.
(See "qdev: Rename Property.name to Property.name_template")

* New unit test for array property
(See "tests: Add unit test for qdev array properties")

* Include sev patch for using class properties instead of object_property_add_uint32_ptr()
(See "sev: Use class properties")

* FIELD_PROP macro is now inside field-property.h
(See "qom: FIELD_PROP macro")

* DEFINE_PROP_* macros are now defined using PROP_*, not the other way around
(See "qom: PROP_* macros")

Changes v1 -> v2
----------------

* Rename functions and source files to call the new feature "field property" instead of "static property"

* Change the API signature from an array-based interface similar to device_class_set_props() to a object_property_add()-like interface.

This means instead of doing this:

    object_class_property_add_static_props(oc, my_array_of_props);

properties are registered like this:

    object_class_property_add_field(oc, "property-name"
                                    PROP_XXX(MyState, my_field),
                                    prop_allow_set_always);

where PROP_XXX is a PROP_* macro like PROP_STRING, PROP_BOOL, etc.

* Make Property.name optional. Rename it to qdev_prop_name, and restrict its usage to qdev property tracking code.

* Make allow_set callback mandatory, to avoid ambiguity

* Big cleanup of array property code. We don't need a custom release function for array elements anymore, because we don't need to save the property name in the Property struct anymore.

* Moved UUID property to qdev-properties-system, because it still has dependencies on qdev code

Eduardo Habkost (53):
cs4231: Get rid of empty property array
cpu: Move cpu_common_props to hw/core/cpu.c
qdev: Move property code to qdev-properties.[ch]
qdev: Check dev->realized at set_size()
sparc: Check dev->realized at sparc_set_nwindows()
qdev: Don't use dev->id on set_size32() error message
qdev: Make PropertyInfo.print method get Object* argument
qdev: Make bit_prop_set() get Object* argument
qdev: Make qdev_get_prop_ptr() get Object* arg
qdev: Make qdev_find_global_prop() get Object* argument
qdev: Make check_prop_still_unset() get Object* argument
qdev: Make error_set_from_qdev_prop_error() get Object* argument
qdev: Make qdev_propinfo_get_uint16() static
qdev: Move UUID property to qdev-properties-system.c
qdev: Move softmmu properties to qdev-properties-system.h
qdev: Reuse DEFINE_PROP in all DEFINE_PROP_* macros
sparc: Use DEFINE_PROP for nwindows property
qdev: Get just property name at error_set_from_qdev_prop_error()
qdev: Avoid using prop->name unnecessarily
qdev: Add name parameter to qdev_class_add_property()
qdev: Add name argument to PropertyInfo.create method
qdev: Wrap getters and setters in separate helpers
qdev: Move dev->realized check to qdev_property_set()
qdev: Make PropertyInfo.create return ObjectProperty*
qdev: Make qdev_class_add_property() more flexible
qdev: Separate generic and device-specific property registration
qdev: Rename qdev_propinfo_* to field_prop_*
qdev: Move qdev_prop_tpm declaration to tpm_prop.h
qdev: Rename qdev_prop_* to prop_info_*
qdev: Rename qdev_get_prop_ptr() to object_field_prop_ptr()
qdev: Avoid unnecessary DeviceState* variable at set_prop_arraylen()
tests: Add unit test for qdev array properties
qom: Add allow_set callback to ObjectProperty
qdev: Make qdev_prop_allow_set() a ObjectProperty.allow_set callback
qdev: Rename Property.name to Property.name_template
qdev: Don't set .name_template for array elements
qdev: Remove ArrayElementProperty.propname field
qdev: Remove ArrayElementProperty.release field
qdev: Get rid of ArrayElementProperty struct
qdev: Rename array_element_release() to
static_prop_release_dynamic_prop()
qdev: Make object_property_add_field() copy the Property struct
qdev: Reuse object_property_add_field() when adding array elements
qdev: Move static_prop_release_dynamic_prop() closer to its usage
qom: Add new qom.h header
qdev: Move core field property code to QOM
qdev: Move base property types to qom/property-types.c
qom: Include static property API reference in documentation
qom: object_class_property_add_field() function
qom: FIELD_PROP macro
qom: Delete DEFINE_PROP_*SIGNED_NODEFAULT macro
qom: PROP_* macros
tests: Use field property at check-qom-proplist test case
sev: Use class properties

 docs/devel/qom.rst                    |  17 +-
 audio/audio.h                         |   1 +
 hw/core/qdev-prop-internal.h          |  30 -
 hw/tpm/tpm_prop.h                     |   2 +
 include/hw/block/block.h              |   1 +
 include/hw/core/cpu.h                 |   1 -
 include/hw/qdev-core.h                |  37 --
 include/hw/qdev-properties-system.h   |  77 +++
 include/hw/qdev-properties.h          | 244 +-------
 include/net/net.h                     |   1 +
 include/qom/field-property-internal.h |  80 +++
 include/qom/field-property.h          | 128 ++++
 include/qom/object.h                  |  38 ++
 include/qom/property-types.h          | 176 ++++++
 include/qom/qom.h                     |  12 +
 backends/tpm/tpm_util.c               |  16 +-
 cpu.c                                 |  15 -
 hw/acpi/vmgenid.c                     |   1 +
 hw/arm/pxa2xx.c                       |   1 +
 hw/arm/strongarm.c                    |   1 +
 hw/audio/cs4231.c                     |   5 -
 hw/block/fdc.c                        |   1 +
 hw/block/m25p80.c                     |   1 +
 hw/block/nand.c                       |   1 +
 hw/block/onenand.c                    |   1 +
 hw/block/pflash_cfi01.c               |   1 +
 hw/block/pflash_cfi02.c               |   1 +
 hw/block/vhost-user-blk.c             |   1 +
 hw/block/xen-block.c                  |  11 +-
 hw/char/avr_usart.c                   |   1 +
 hw/char/bcm2835_aux.c                 |   1 +
 hw/char/cadence_uart.c                |   1 +
 hw/char/cmsdk-apb-uart.c              |   1 +
 hw/char/debugcon.c                    |   1 +
 hw/char/digic-uart.c                  |   1 +
 hw/char/escc.c                        |   1 +
 hw/char/etraxfs_ser.c                 |   1 +
 hw/char/exynos4210_uart.c             |   1 +
 hw/char/grlib_apbuart.c               |   1 +
 hw/char/ibex_uart.c                   |   1 +
 hw/char/imx_serial.c                  |   1 +
 hw/char/ipoctal232.c                  |   1 +
 hw/char/lm32_juart.c                  |   1 +
 hw/char/lm32_uart.c                   |   1 +
 hw/char/mcf_uart.c                    |   1 +
 hw/char/milkymist-uart.c              |   1 +
 hw/char/nrf51_uart.c                  |   1 +
 hw/char/parallel.c                    |   1 +
 hw/char/pl011.c                       |   1 +
 hw/char/renesas_sci.c                 |   1 +
 hw/char/sclpconsole-lm.c              |   1 +
 hw/char/sclpconsole.c                 |   1 +
 hw/char/serial-pci-multi.c            |   1 +
 hw/char/serial.c                      |   1 +
 hw/char/spapr_vty.c                   |   1 +
 hw/char/stm32f2xx_usart.c             |   1 +
 hw/char/terminal3270.c                |   1 +
 hw/char/virtio-console.c              |   1 +
 hw/char/xilinx_uartlite.c             |   1 +
 hw/core/cpu.c                         |  15 +
 hw/core/qdev-properties-system.c      | 258 ++++-----
 hw/core/qdev-properties.c             | 806 +++-----------------------
 hw/core/qdev.c                        | 120 ----
 hw/hyperv/vmbus.c                     |   1 +
 hw/i386/kvm/i8254.c                   |   1 +
 hw/ide/qdev.c                         |   1 +
 hw/intc/arm_gicv3_common.c            |   2 +-
 hw/intc/rx_icu.c                      |   4 +-
 hw/ipmi/ipmi_bmc_extern.c             |   1 +
 hw/ipmi/ipmi_bmc_sim.c                |   1 +
 hw/misc/allwinner-sid.c               |   1 +
 hw/misc/arm_sysctl.c                  |   4 +-
 hw/misc/ivshmem.c                     |   1 +
 hw/misc/mac_via.c                     |   1 +
 hw/misc/sifive_u_otp.c                |   1 +
 hw/net/e1000e.c                       |   6 +-
 hw/net/rocker/rocker.c                |   1 +
 hw/nvram/eeprom_at24c.c               |   1 +
 hw/nvram/spapr_nvram.c                |   1 +
 hw/pci-bridge/gen_pcie_root_port.c    |   1 +
 hw/pci/pci.c                          |   1 +
 hw/ppc/pnv_pnor.c                     |   1 +
 hw/rdma/vmw/pvrdma_main.c             |   1 +
 hw/rtc/mc146818rtc.c                  |   1 +
 hw/s390x/css.c                        |  13 +-
 hw/s390x/s390-pci-bus.c               |  10 +-
 hw/scsi/scsi-disk.c                   |   1 +
 hw/scsi/scsi-generic.c                |   1 +
 hw/scsi/vhost-user-scsi.c             |   1 +
 hw/sd/sd.c                            |   1 +
 hw/usb/ccid-card-passthru.c           |   1 +
 hw/usb/dev-serial.c                   |   1 +
 hw/usb/redirect.c                     |   1 +
 hw/vfio/pci-quirks.c                  |  11 +-
 hw/vfio/pci.c                         |   7 +-
 hw/virtio/vhost-user-fs.c             |   1 +
 hw/virtio/vhost-user-vsock.c          |   1 +
 hw/virtio/virtio-iommu-pci.c          |   1 +
 hw/xen/xen_pt.c                       |   1 +
 migration/migration.c                 |   1 +
 qom/field-property.c                  | 151 +++++
 qom/object.c                          |  16 +
 qom/property-types.c                  | 546 +++++++++++++++++
 softmmu/qdev-monitor.c                |   9 +-
 target/arm/cpu.c                      |   6 +-
 target/i386/sev.c                     |  25 +-
 target/sparc/cpu.c                    |   5 +-
 tests/check-qom-proplist.c            |  39 +-
 tests/test-qdev-global-props.c        |  61 ++
 qom/meson.build                       |   2 +
 110 files changed, 1659 insertions(+), 1418 deletions(-)
 delete mode 100644 hw/core/qdev-prop-internal.h
 create mode 100644 include/hw/qdev-properties-system.h
 create mode 100644 include/qom/field-property-internal.h
 create mode 100644 include/qom/field-property.h
 create mode 100644 include/qom/property-types.h
 create mode 100644 include/qom/qom.h
 create mode 100644 qom/field-property.c
 create mode 100644 qom/property-types.c
Signature · 1 line
2.28.0
Signature · 1 line
Eduardo
#57 lore raw
Quoted 7 lines · Eduardo Habkost

Paolo, do you have any objections to adding the field property API in this series to QOM, considering the recent discussions about long term plans for QOM properties?

Note that I still want to perform most of the changes in this series, even if the code is kept inside hw/core. Moving the code to qom is just one extra step, but not essential.

Absolutely not, go ahead.

Paolo