hw/acpi: convert object props to class props
v2 cover hw/acpi: convert object props to class props
[Background: based upon Peter's feedback at
https://lists.gnu.org/archive/html/qemu-devel/2026-06/msg07717.html I realised that what we really need are object_class_property_add_*_ptr() equivalents to the existing object_property_add_*_ptr() functions to make it easier to convert existing properties.
There are actually existing functions with these names that are already in use but after observation these are really static properties, so these are renamed to aid porting object props to class props, as well as making the difference clearer.]
Since the use of object props is effectively deprecated, here is an attempt to convert all use of object props in hw/acpi to class props. The eventual aim is to continue working through the codebase, removing all remaining uses of object props.
The series is lightly tested: it passes "make check", GitLab CI and some simple local tests. I'm mostly interested for feedback on the conversion strategy, and to get a feel for the best way to merge this series since once the basic conversion patterns are in place, the same patterns can be applied elsewhere and it would be good to minimise the merge window for such changes.
v2:
- Add object_class_property_add_*_ptr() functions matching the existing object_property_add_*_ptr() functions for class functions
- Rework patch to use new functions instead of manually adding get/set functions as part of the conversion
- Ignore existing R-Bs since this approach is quite different to v1
- Rebase onto master
Mark Cave-Ayland (12):
qom/object.c: rename object_class_property_uint*_ptr() to
object_class_static_property_uint*_ptr()
qom/object.c: add object_class_property_add_uint8_ptr() qom/object.c: add object_class_property_add_uint16_ptr() qom/object.c: add object_class_property_add_uint32_ptr() qom/object.c: add object_class_property_add_uint64_ptr() hw/acpi/ich9.c: move initial property values into
ich9_reset_properties()
hw/isa/lpc_ich9.c: convert ich9_lpc_initfn() object props to class
props
hw/acpi/ich9.c: don't pass ICH9LPCPMRegs via opaque for
ACPI_PM_PROP_GPE0_BLK prop
hw/acpi/ich9.c: convert object props in ICH9_LPC_DEVICE to class props hw/acpi/pcihp.c: convert ACPI_PCIHP_IO_BASE_PROP and
ACPI_PCIHP_IO_BASE_PROP to class props
hw/acpi/pcihp.c: convert ACPI_PCIHP_PROP_BSEL from object prop to
class prop
hw/acpi/piix4.c: convert object props in PIIX4_PM to class props
include/hw/acpi/ich9.h | 4 +- include/hw/pci/pci_bus.h | 2 + include/qom/object.h | 20 ++++ hw/acpi/generic_event_device.c | 10 ++ hw/acpi/ich9.c | 79 ++++++++----- hw/acpi/pci-bridge.c | 9 +- hw/acpi/pcihp.c | 37 +++---- hw/acpi/piix4.c | 51 ++++++--- hw/arm/virt-acpi-build.c | 7 +- hw/i386/acpi-build.c | 7 +- hw/isa/lpc_ich9.c | 71 +++++++++--- hw/pci/pci.c | 32 ++++++ hw/riscv/spike.c | 5 +- qom/object.c | 196 ++++++++++++++++++++++++++++++++- 14 files changed, 440 insertions(+), 90 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/12 qom/object.c: rename object_class_property_uint*_ptr() to object_class_static_property_uint*_ptr()
This more accurately reflects that these properties are held within the class and not the object.
--- include/qom/object.h | 8 ++++---- hw/riscv/spike.c | 5 +++-- qom/object.c | 28 ++++++++++++++++------------ 3 files changed, 23 insertions(+), 18 deletions(-)
include/qom/object.h +4 -4
@@ -1956,7 +1956,7 @@ ObjectProperty *object_property_add_uint8_ptr(Object *obj, const char *name,const uint8_t *v, ObjectPropertyFlags flags); -ObjectProperty *object_class_property_add_uint8_ptr (ObjectClass *klass, +ObjectProperty *object_class_static_property_add_uint8_ptr (ObjectClass *klass,const char *name,const uint8_t *v,ObjectPropertyFlags flags);
@@ -1977,7 +1977,7 @@ ObjectProperty *object_property_add_uint16_ptr(Object *obj, const char *name,const uint16_t *v, ObjectPropertyFlags flags); -ObjectProperty *object_class_property_add_uint16_ptr (ObjectClass *klass, +ObjectProperty *object_class_static_property_add_uint16_ptr (ObjectClass *klass,const char *name,const uint16_t *v,ObjectPropertyFlags flags);
@@ -1998,7 +1998,7 @@ ObjectProperty *object_property_add_uint32_ptr(Object *obj, const char *name,const uint32_t *v, ObjectPropertyFlags flags); -ObjectProperty *object_class_property_add_uint32_ptr (ObjectClass *klass, +ObjectProperty *object_class_static_property_add_uint32_ptr (ObjectClass *klass,const char *name,const uint32_t *v,ObjectPropertyFlags flags);
@@ -2019,7 +2019,7 @@ ObjectProperty *object_property_add_uint64_ptr(Object *obj, const char *name,const uint64_t *v, ObjectPropertyFlags flags); -ObjectProperty *object_class_property_add_uint64_ptr (ObjectClass *klass, +ObjectProperty *object_class_static_property_add_uint64_ptr (ObjectClass *klass,const char *name,const uint64_t *v,ObjectPropertyFlags flags);
hw/riscv/spike.c +3 -2
@@ -278,8 +278,9 @@ static void spike_machine_class_init(ObjectClass *oc, const void *data)object_class_property_add_str (oc,"signature" ,NULL , spike_set_signature);object_class_property_set_description (oc,"signature" ,"File to write ACT test signature" ); -object_class_property_add_uint8_ptr (oc,"signature-granularity" , - &line_size,OBJ_PROP_FLAG_WRITE ); +object_class_static_property_add_uint8_ptr (oc,"signature-granularity" , + &line_size, +OBJ_PROP_FLAG_WRITE );object_class_property_set_description (oc,"signature-granularity" ,"Size of each line in ACT signature " "file" );
qom/object.c +16 -12
@@ -2762,9 +2762,10 @@ object_property_add_uint8_ptr(Object *obj, const char *name, }ObjectProperty * -object_class_property_add_uint8_ptr (ObjectClass *klass,const char *name, -const uint8_t *v, -ObjectPropertyFlags flags) +object_class_static_property_add_uint8_ptr (ObjectClass *klass, +const char *name, +const uint8_t *v, +ObjectPropertyFlags flags) {ObjectPropertyAccessor *getter =NULL ;ObjectPropertyAccessor *setter =NULL ;
@@ -2802,9 +2803,10 @@ object_property_add_uint16_ptr(Object *obj, const char *name, }ObjectProperty * -object_class_property_add_uint16_ptr (ObjectClass *klass,const char *name, -const uint16_t *v, -ObjectPropertyFlags flags) +object_class_static_property_add_uint16_ptr (ObjectClass *klass, +const char *name, +const uint16_t *v, +ObjectPropertyFlags flags) {ObjectPropertyAccessor *getter =NULL ;ObjectPropertyAccessor *setter =NULL ;
@@ -2842,9 +2844,10 @@ object_property_add_uint32_ptr(Object *obj, const char *name, }ObjectProperty * -object_class_property_add_uint32_ptr (ObjectClass *klass,const char *name, -const uint32_t *v, -ObjectPropertyFlags flags) +object_class_static_property_add_uint32_ptr (ObjectClass *klass, +const char *name, +const uint32_t *v, +ObjectPropertyFlags flags) {ObjectPropertyAccessor *getter =NULL ;ObjectPropertyAccessor *setter =NULL ;
@@ -2882,9 +2885,10 @@ object_property_add_uint64_ptr(Object *obj, const char *name, }ObjectProperty * -object_class_property_add_uint64_ptr (ObjectClass *klass,const char *name, -const uint64_t *v, -ObjectPropertyFlags flags) +object_class_static_property_add_uint64_ptr (ObjectClass *klass, +const char *name, +const uint64_t *v, +ObjectPropertyFlags flags) {ObjectPropertyAccessor *getter =NULL ;ObjectPropertyAccessor *setter =NULL ;
Signature · 1 line
2.43.0
Re: [PATCH v2 01/12] qom/object.c: rename object_class_property_uint*_ptr() to object_class_static_property_uint*_ptr()
Quoted 55 lines · Mark Cave-Ayland
This more accurately reflects that these properties are held within the class and not the object.
Signed-off-by Mark Cave-Ayland <[email protected]>--- include/qom/object.h | 8 ++++---- hw/riscv/spike.c | 5 +++-- qom/object.c | 28 ++++++++++++++++------------ 3 files changed, 23 insertions(+), 18 deletions(-)include/qom/object.h +4
-4@@ -1956,7 +1956,7 @@ ObjectProperty *object_property_add_uint8_ptr(Object *obj, const char *name,const uint8_t *v, ObjectPropertyFlags flags); -ObjectProperty *object_class_property_add_uint8_ptr (ObjectClass *klass, +ObjectProperty *object_class_static_property_add_uint8_ptr (ObjectClass *klass,const char *name,const uint8_t *v,ObjectPropertyFlags flags);@@ -1977,7 +1977,7 @@ ObjectProperty *object_property_add_uint16_ptr(Object *obj, const char *name,const uint16_t *v, ObjectPropertyFlags flags); -ObjectProperty *object_class_property_add_uint16_ptr (ObjectClass *klass, +ObjectProperty *object_class_static_property_add_uint16_ptr (ObjectClass *klass,const char *name,const uint16_t *v,ObjectPropertyFlags flags);@@ -1998,7 +1998,7 @@ ObjectProperty *object_property_add_uint32_ptr(Object *obj, const char *name,const uint32_t *v, ObjectPropertyFlags flags); -ObjectProperty *object_class_property_add_uint32_ptr (ObjectClass *klass, +ObjectProperty *object_class_static_property_add_uint32_ptr (ObjectClass *klass,const char *name,const uint32_t *v,ObjectPropertyFlags flags);@@ -2019,7 +2019,7 @@ ObjectProperty *object_property_add_uint64_ptr(Object *obj, const char *name,const uint64_t *v, ObjectPropertyFlags flags); -ObjectProperty *object_class_property_add_uint64_ptr (ObjectClass *klass, +ObjectProperty *object_class_static_property_add_uint64_ptr (ObjectClass *klass,const char *name,const uint64_t *v,ObjectPropertyFlags flags);hw/riscv/spike.c +0
-0
hw/riscv/spike.c static void spike_machine_class_init(ObjectClass *oc, const void *data) · line 283
Quoted 8 lines
hw/riscv/spike.c +3
-2@@ -278,8 +278,9 @@ static void spike_machine_class_init(ObjectClass *oc, const void *data)object_class_property_add_str (oc,"signature" ,NULL , spike_set_signature);object_class_property_set_description (oc,"signature" ,"File to write ACT test signature" ); -object_class_property_add_uint8_ptr (oc,"signature-granularity" , - &line_size,OBJ_PROP_FLAG_WRITE ); +object_class_static_property_add_uint8_ptr (oc,"signature-granularity" , + &line_size, +OBJ_PROP_FLAG_WRITE );
When we have just one use of these "static property" API in the code base, I wonder if we genuinely need these APIs ?
I wonder why "line_size" isn't merely a field in the machine class ? External code ought to be able to fetch the current machine and read a line_size struct field, surely ?
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
Re: [PATCH v2 01/12] qom/object.c: rename object_class_property_uint*_ptr() to object_class_static_property_uint*_ptr()
Quoted 59 lines · Daniel P. Berrangé
Quoted 58 lines · Mark Cave-Ayland
This more accurately reflects that these properties are held within the class and not the object.
Signed-off-by Mark Cave-Ayland <[email protected]>--- include/qom/object.h | 8 ++++---- hw/riscv/spike.c | 5 +++-- qom/object.c | 28 ++++++++++++++++------------ 3 files changed, 23 insertions(+), 18 deletions(-)include/qom/object.h +4
-4@@ -1956,7 +1956,7 @@ ObjectProperty *object_property_add_uint8_ptr(Object *obj, const char *name,const uint8_t *v, ObjectPropertyFlags flags); -ObjectProperty *object_class_property_add_uint8_ptr (ObjectClass *klass, +ObjectProperty *object_class_static_property_add_uint8_ptr (ObjectClass *klass,const char *name,const uint8_t *v,ObjectPropertyFlags flags);@@ -1977,7 +1977,7 @@ ObjectProperty *object_property_add_uint16_ptr(Object *obj, const char *name,const uint16_t *v, ObjectPropertyFlags flags); -ObjectProperty *object_class_property_add_uint16_ptr (ObjectClass *klass, +ObjectProperty *object_class_static_property_add_uint16_ptr (ObjectClass *klass,const char *name,const uint16_t *v,ObjectPropertyFlags flags);@@ -1998,7 +1998,7 @@ ObjectProperty *object_property_add_uint32_ptr(Object *obj, const char *name,const uint32_t *v, ObjectPropertyFlags flags); -ObjectProperty *object_class_property_add_uint32_ptr (ObjectClass *klass, +ObjectProperty *object_class_static_property_add_uint32_ptr (ObjectClass *klass,const char *name,const uint32_t *v,ObjectPropertyFlags flags);@@ -2019,7 +2019,7 @@ ObjectProperty *object_property_add_uint64_ptr(Object *obj, const char *name,const uint64_t *v, ObjectPropertyFlags flags); -ObjectProperty *object_class_property_add_uint64_ptr (ObjectClass *klass, +ObjectProperty *object_class_static_property_add_uint64_ptr (ObjectClass *klass,const char *name,const uint64_t *v,ObjectPropertyFlags flags);hw/riscv/spike.c +0
-0@@ -278,8 +278,9 @@ static void spike_machine_class_init(ObjectClass *oc, const void *data)object_class_property_add_str (oc,"signature" ,NULL , spike_set_signature);object_class_property_set_description (oc,"signature" ,"File to write ACT test signature" );
Quoted 8 lines
hw/riscv/spike.c static void spike_machine_class_init(ObjectClass *oc, const void *data) · line 283
Quoted 5 lines
hw/riscv/spike.c +3
-2-object_class_property_add_uint8_ptr (oc,"signature-granularity" , - &line_size,OBJ_PROP_FLAG_WRITE ); +object_class_static_property_add_uint8_ptr (oc,"signature-granularity" , + &line_size, +OBJ_PROP_FLAG_WRITE );When we have just one use of these "static property" API in the code base, I wonder if we genuinely need these APIs ?
There are actually more uses in hw/acpi later on in the series: see patches 7, 9 and 12.
Quoted 3 lines
I wonder why "
line_size" isn't merely a field in the machine class ? External code ought to be able to fetch the current machine and read aline_sizestruct field, surely ?
It certainly looks odd from here: one of things I wanted to discuss on the call was how to approach the conversion.
My current thinking is that the aim should be simply to convert everything as-is, and avoid attempting any refactorings or converting to a device class prop via device_class_set_props() if possible. Otherwise anyone attempting conversions will get stuck in the details of the individual devices, which I would argue is more the remit of maintainers.
ATB,
Mark.
Re: [PATCH v2 01/12] qom/object.c: rename object_class_property_uint*_ptr() to object_class_static_property_uint*_ptr()
Quoted 66 lines · Mark Cave-Ayland
Quoted 55 lines · Daniel P. Berrangé
Quoted 54 lines · Mark Cave-Ayland
This more accurately reflects that these properties are held within the class and not the object.
Signed-off-by Mark Cave-Ayland <[email protected]>--- include/qom/object.h | 8 ++++---- hw/riscv/spike.c | 5 +++-- qom/object.c | 28 ++++++++++++++++------------ 3 files changed, 23 insertions(+), 18 deletions(-)include/qom/object.h +4
-4@@ -1956,7 +1956,7 @@ ObjectProperty *object_property_add_uint8_ptr(Object *obj, const char *name,const uint8_t *v, ObjectPropertyFlags flags); -ObjectProperty *object_class_property_add_uint8_ptr (ObjectClass *klass, +ObjectProperty *object_class_static_property_add_uint8_ptr (ObjectClass *klass,const char *name,const uint8_t *v,ObjectPropertyFlags flags);@@ -1977,7 +1977,7 @@ ObjectProperty *object_property_add_uint16_ptr(Object *obj, const char *name,const uint16_t *v, ObjectPropertyFlags flags); -ObjectProperty *object_class_property_add_uint16_ptr (ObjectClass *klass, +ObjectProperty *object_class_static_property_add_uint16_ptr (ObjectClass *klass,const char *name,const uint16_t *v,ObjectPropertyFlags flags);@@ -1998,7 +1998,7 @@ ObjectProperty *object_property_add_uint32_ptr(Object *obj, const char *name,const uint32_t *v, ObjectPropertyFlags flags); -ObjectProperty *object_class_property_add_uint32_ptr (ObjectClass *klass, +ObjectProperty *object_class_static_property_add_uint32_ptr (ObjectClass *klass,const char *name,const uint32_t *v,ObjectPropertyFlags flags);@@ -2019,7 +2019,7 @@ ObjectProperty *object_property_add_uint64_ptr(Object *obj, const char *name,const uint64_t *v, ObjectPropertyFlags flags); -ObjectProperty *object_class_property_add_uint64_ptr (ObjectClass *klass, +ObjectProperty *object_class_static_property_add_uint64_ptr (ObjectClass *klass,const char *name,const uint64_t *v,ObjectPropertyFlags flags);hw/riscv/spike.c +0
-0@@ -278,8 +278,9 @@ static void spike_machine_class_init(ObjectClass *oc, const void *data)object_class_property_add_str (oc,"signature" ,NULL , spike_set_signature);object_class_property_set_description (oc,"signature" ,"File to write ACT test signature" );Quoted 8 lines
hw/riscv/spike.c static void spike_machine_class_init(ObjectClass *oc, const void *data) · line 283
Quoted 5 lines
hw/riscv/spike.c +3
-2-object_class_property_add_uint8_ptr (oc,"signature-granularity" , - &line_size,OBJ_PROP_FLAG_WRITE ); +object_class_static_property_add_uint8_ptr (oc,"signature-granularity" , + &line_size, +OBJ_PROP_FLAG_WRITE );When we have just one use of these "static property" API in the code base, I wonder if we genuinely need these APIs ?
Quoted 2 lines
There are actually more uses in hw/acpi later on in the series: see patches 7, 9 and 12.
Ok, I missed that, only looking an existnig code.
Quoted 4 lines
Quoted 3 lines
I wonder why "
line_size" isn't merely a field in the machine class ? External code ought to be able to fetch the current machine and read aline_sizestruct field, surely ?
Quoted 8 lines
It certainly looks odd from here: one of things I wanted to discuss on the call was how to approach the conversion.
My current thinking is that the aim should be simply to convert everything as-is, and avoid attempting any refactorings or converting to a device class prop via
device_class_set_props()if possible. Otherwise anyone attempting conversions will get stuck in the details of the individual devices, which I would argue is more the remit of maintainers.
Yeah, ok, that is probably a wise approach to minimizing complexity.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
Re: [PATCH v2 01/12] qom/object.c: rename object_class_property_uint*_ptr() to object_class_static_property_uint*_ptr()
In reply to Mark Cave-AylandQuoted 8 lines · Mark Cave-Ayland
Quoted 4 lines · Daniel P. Berrangé
On Fri, Jul 03, 2026 at 02:53:03PM +0100, Mark Cave-Ayland wrote:
I wonder why "line_size" isn't merely a field in the machine class ? External code ought to be able to fetch the current machine and read aline_sizestruct field, surely ?
Quoted 6 lines
It certainly looks odd from here: one of things I wanted to discuss on the call was how to approach the conversion.
My current thinking is that the aim should be simply to convert everything as-is, and avoid attempting any refactorings or converting to a device class prop via
device_class_set_props()if possible.
Oh yeah, I was going to ask how device_class_set_props() fits in here. That is a much nicer API for the cases where it fits. I would like any QOM-level API for setting up class properties to be as easy and convenient to use as that is for the basic "there is a property and it just sets a field in the object structure" common case. (Obviously the more oddball stuff will need finer control.)
-- PMM
Re: [PATCH v2 01/12] qom/object.c: rename object_class_property_uint*_ptr() to object_class_static_property_uint*_ptr()
Quoted 17 lines · Peter Maydell
Quoted 8 lines · Mark Cave-Ayland
Quoted 4 lines · Daniel P. Berrangé
On Fri, Jul 03, 2026 at 02:53:03PM +0100, Mark Cave-Ayland wrote:
I wonder why "line_size" isn't merely a field in the machine class ? External code ought to be able to fetch the current machine and read aline_sizestruct field, surely ?Quoted 6 lines
It certainly looks odd from here: one of things I wanted to discuss on the call was how to approach the conversion.
My current thinking is that the aim should be simply to convert everything as-is, and avoid attempting any refactorings or converting to a device class prop via
device_class_set_props()if possible.
Quoted 6 lines
Oh yeah, I was going to ask how
device_class_set_props()fits in here. That is a much nicer API for the cases where it fits. I would like any QOM-level API for setting up class properties to be as easy and convenient to use as that is for the basic "there is a property and it just sets a field in the object structure" common case. (Obviously the more oddball stuff will need finer control.)
Having a look at these series, I think we can come up with some basic rules as to whether an object property could be promoted to a static Property:
- The QOM object in question must inherit from TYPE_DEVICE
- The getter and setter must only set/retrieve the value with no additional logic/constraints included
- The object property in question must not be a QOM array element i.e. a name of the form "foo[N]"
- The object property must be declared with OBJ_PROP_FLAG_READWRITE
- The object property must be defined directly in an QOM init() function, or a static function called from it
Does that seem reasonable?
ATB,
Mark.
PATCH v2 2/12 qom/object.c: add object_class_property_add_uint8_ptr()
In reply to Mark Cave-AylandThis adds a class property that references a uint8_t within the object instance and is intended to be a replacement for object_property_add_uint8_ptr().
--- include/qom/object.h | 5 +++++ qom/object.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+)
include/qom/object.h +5 -0
@@ -1956,6 +1956,11 @@ ObjectProperty *object_property_add_uint8_ptr(Object *obj, const char *name,const uint8_t *v, ObjectPropertyFlags flags); +ObjectProperty *object_class_property_add_uint8_ptr (ObjectClass *klass, +const char *name, +ptrdiff_t v, +ObjectPropertyFlags flags); + ObjectProperty *object_class_static_property_add_uint8_ptr(ObjectClass *klass, const char *name, const uint8_t *v,
qom/object.c +52 -0
64 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v2 02/12] qom/object.c: add object_class_property_add_uint8_ptr()
Quoted 30 lines · Mark Cave-Ayland
This adds a class property that references a
uint8_twithin the object instance and is intended to be a replacement forobject_property_add_uint8_ptr().Signed-off-by Mark Cave-Ayland <[email protected]>--- include/qom/object.h | 5 +++++ qom/object.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+)include/qom/object.h +5
-0@@ -1956,6 +1956,11 @@ ObjectProperty *object_property_add_uint8_ptr(Object *obj, const char *name,const uint8_t *v, ObjectPropertyFlags flags); +ObjectProperty *object_class_property_add_uint8_ptr (ObjectClass *klass, +const char *name, +ptrdiff_t v, +ObjectPropertyFlags flags); + ObjectProperty *object_class_static_property_add_uint8_ptr(ObjectClass *klass, const char *name, const uint8_t *v,qom/object.c +0
-0
qom/object.c static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, · line 2750
Quoted 10 lines
qom/object.c +7
-0@@ -2741,6 +2741,38 @@ static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, *field = value; } +static void *object_class_prop_ptr (Object *obj,ptrdiff_t offset) +{ +void *ptr = obj; + ptr += offset; + +return ptr; +}
Perhaps just
#define FIELD(obj, offset) ((void *)obj+(ptrdiff_t)offset)
qom/object.c static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, · line 2757
Quoted 7 lines
qom/object.c +7
-0+ +static void property_class_get_uint8_ptr (Object *obj,Visitor *v, +const char *name, +void *opaque,Error **errp) +{ +uint8_t value = *(uint8_t *)object_class_prop_ptr (obj, + (ptrdiff_t )opaque);
Do we need this intermediate instead of now
qom/object.c static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, · line 2758
Quoted 1 line
qom/object.c +1
-0+visit_type_uint8 (v, name, &value, errp);
visit_type_uint8(v, name, FIELD(obj, opaque), errp);
Quoted 5 lines
qom/object.c +5
-0+} + +static void property_class_set_uint8_ptr (Object *obj,Visitor *v, +const char *name, +void *opaque,Error **errp)
qom/object.c static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, · line 2773
Quoted 10 lines
qom/object.c +10
-0+{ +uint8_t *field = (uint8_t *)object_class_prop_ptr (obj, + (ptrdiff_t )opaque); +uint8_t value; + +if (!visit_type_uint8 (v, name, &value, errp)) { +return ; + } + + *field = value;
Instead of all this is it sufficient to do:
visit_type_uint8(v, name, FIELD(obj, opaque), errp);
Also, since we'll be using this pattern for int8, int16, int32, and many more, perhaps we could define a macro that can expand to the getter/setter impl for any scalar type. so we can do
DEFINE_SCALAR_PROP_CALLBACKS(uint8); DEFINE_SCALAR_PROP_CALLBACKS(uint16); DEFINE_SCALAR_PROP_CALLBACKS(uint32); DEFINE_SCALAR_PROP_CALLBACKS(uint64); DEFINE_SCALAR_PROP_CALLBACKS(bool); ..etc..
qom/object.c static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, · line 2778
Quoted 5 lines
qom/object.c +2
-0+} +ObjectProperty * object_property_add_uint8_ptr(Object *obj, const char *name, const uint8_t *v,
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
Re: [PATCH v2 02/12] qom/object.c: add object_class_property_add_uint8_ptr()
Quoted 44 lines · Daniel P. Berrangé
Quoted 30 lines · Mark Cave-Ayland
This adds a class property that references a
uint8_twithin the object instance and is intended to be a replacement forobject_property_add_uint8_ptr().Signed-off-by Mark Cave-Ayland <[email protected]>--- include/qom/object.h | 5 +++++ qom/object.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+)include/qom/object.h +5
-0@@ -1956,6 +1956,11 @@ ObjectProperty *object_property_add_uint8_ptr(Object *obj, const char *name,const uint8_t *v, ObjectPropertyFlags flags); +ObjectProperty *object_class_property_add_uint8_ptr (ObjectClass *klass, +const char *name, +ptrdiff_t v, +ObjectPropertyFlags flags); + ObjectProperty *object_class_static_property_add_uint8_ptr(ObjectClass *klass, const char *name, const uint8_t *v,qom/object.c +0
-0qom/object.c static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, · line 2750
Quoted 10 lines
qom/object.c +7
-0@@ -2741,6 +2741,38 @@ static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, *field = value; } +static void *object_class_prop_ptr (Object *obj,ptrdiff_t offset) +{ +void *ptr = obj; + ptr += offset; + +return ptr; +}Perhaps just
Quoted 1 line
#define FIELD(obj, offset) ((void *)obj+(ptrdiff_t)offset)
That could work.
Quoted 10 lines
qom/object.c static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, · line 2757
Quoted 7 lines
qom/object.c +7
-0+ +static void property_class_get_uint8_ptr (Object *obj,Visitor *v, +const char *name, +void *opaque,Error **errp) +{ +uint8_t value = *(uint8_t *)object_class_prop_ptr (obj, + (ptrdiff_t )opaque);Do we need this intermediate instead of now
Quoted 3 lines
qom/object.c static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, · line 2758
Quoted 1 line
qom/object.c +1
-0+visit_type_uint8 (v, name, &value, errp);visit_type_uint8(v, name, FIELD(obj, opaque), errp);
Yes, I think that would be possible. I shall give it a test and report back.
Quoted 25 lines
Quoted 5 lines
qom/object.c +5
-0+} + +static void property_class_set_uint8_ptr (Object *obj,Visitor *v, +const char *name, +void *opaque,Error **errp)qom/object.c static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, · line 2773
Quoted 10 lines
qom/object.c +10
-0+{ +uint8_t *field = (uint8_t *)object_class_prop_ptr (obj, + (ptrdiff_t )opaque); +uint8_t value; + +if (!visit_type_uint8 (v, name, &value, errp)) { +return ; + } + + *field = value;Instead of all this is it sufficient to do:
visit_type_uint8(v, name, FIELD(obj, opaque), errp);Also, since we'll be using this pattern for int8, int16, int32, and many more, perhaps we could define a macro that can expand to the getter/setter impl for any scalar type. so we can do
Quoted 6 lines
DEFINE_SCALAR_PROP_CALLBACKS(uint8); DEFINE_SCALAR_PROP_CALLBACKS(uint16); DEFINE_SCALAR_PROP_CALLBACKS(uint32); DEFINE_SCALAR_PROP_CALLBACKS(uint64); DEFINE_SCALAR_PROP_CALLBACKS(bool); ..etc..
That is something else that is possible: I've purposely avoided doing this since it's not a pattern already in use within object.c. Do you think this is worth doing as a separate exercise first?
Quoted 5 lines
qom/object.c static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, · line 2778
Quoted 5 lines
qom/object.c +2
-0+} +ObjectProperty * object_property_add_uint8_ptr(Object *obj, const char *name, const uint8_t *v,
ATB,
Mark.
Re: [PATCH v2 02/12] qom/object.c: add object_class_property_add_uint8_ptr()
Quoted 96 lines · Mark Cave-Ayland
Quoted 42 lines · Daniel P. Berrangé
Quoted 29 lines · Mark Cave-Ayland
This adds a class property that references a
uint8_twithin the object instance and is intended to be a replacement forobject_property_add_uint8_ptr().Signed-off-by Mark Cave-Ayland <[email protected]>--- include/qom/object.h | 5 +++++ qom/object.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+)include/qom/object.h +5
-0@@ -1956,6 +1956,11 @@ ObjectProperty *object_property_add_uint8_ptr(Object *obj, const char *name,const uint8_t *v, ObjectPropertyFlags flags); +ObjectProperty *object_class_property_add_uint8_ptr (ObjectClass *klass, +const char *name, +ptrdiff_t v, +ObjectPropertyFlags flags); + ObjectProperty *object_class_static_property_add_uint8_ptr(ObjectClass *klass, const char *name, const uint8_t *v,qom/object.c +0
-0qom/object.c static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, · line 2749
Quoted 9 lines
qom/object.c +7
-0@@ -2741,6 +2741,38 @@ static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, *field = value; } +static void *object_class_prop_ptr (Object *obj,ptrdiff_t offset) +{ +void *ptr = obj; + ptr += offset; + +return ptr; +}Perhaps just
Quoted 1 line
#define FIELD(obj, offset) ((void *)obj+(ptrdiff_t)offset)That could work.
Quoted 10 lines
qom/object.c static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, · line 2757
Quoted 7 lines
qom/object.c +7
-0+ +static void property_class_get_uint8_ptr (Object *obj,Visitor *v, +const char *name, +void *opaque,Error **errp) +{ +uint8_t value = *(uint8_t *)object_class_prop_ptr (obj, + (ptrdiff_t )opaque);Do we need this intermediate instead of now
Quoted 3 lines
qom/object.c static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, · line 2758
Quoted 1 line
qom/object.c +1
-0+visit_type_uint8 (v, name, &value, errp);visit_type_uint8(v, name, FIELD(obj, opaque), errp);Yes, I think that would be possible. I shall give it a test and report back.
Quoted 25 lines
Quoted 5 lines
qom/object.c +5
-0+} + +static void property_class_set_uint8_ptr (Object *obj,Visitor *v, +const char *name, +void *opaque,Error **errp)qom/object.c static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, · line 2773
Quoted 10 lines
qom/object.c +10
-0+{ +uint8_t *field = (uint8_t *)object_class_prop_ptr (obj, + (ptrdiff_t )opaque); +uint8_t value; + +if (!visit_type_uint8 (v, name, &value, errp)) { +return ; + } + + *field = value;Instead of all this is it sufficient to do:
visit_type_uint8(v, name, FIELD(obj, opaque), errp);Also, since we'll be using this pattern for int8, int16, int32, and many more, perhaps we could define a macro that can expand to the getter/setter impl for any scalar type. so we can do
Quoted 6 lines
DEFINE_SCALAR_PROP_CALLBACKS(uint8); DEFINE_SCALAR_PROP_CALLBACKS(uint16); DEFINE_SCALAR_PROP_CALLBACKS(uint32); DEFINE_SCALAR_PROP_CALLBACKS(uint64); DEFINE_SCALAR_PROP_CALLBACKS(bool); ..etc..
Quoted 3 lines
That is something else that is possible: I've purposely avoided doing this since it's not a pattern already in use within
object.c. Do you think this is worth doing as a separate exercise first?
Yeah, if we can convert existing scalar setters/getters that would be nice. Otherwise we're piling up a huge amount of repetitive code for dealing with every property type :-(
Quoted 10 lines
Quoted 6 lines
qom/object.c static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, · line 2778
Quoted 6 lines
qom/object.c +2
-0+} +ObjectProperty * object_property_add_uint8_ptr(Object *obj, const char *name, const uint8_t *v,ATB,
Quoted 2 lines
Mark.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
PATCH v2 3/12 qom/object.c: add object_class_property_add_uint16_ptr()
In reply to Mark Cave-AylandThis adds a class property that references a uint16_t within the object instance and is intended to be a replacement for object_property_add_uint16_ptr().
--- include/qom/object.h | 5 +++++ qom/object.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+)
include/qom/object.h +5 -0
@@ -1982,6 +1982,11 @@ ObjectProperty *object_property_add_uint16_ptr(Object *obj, const char *name,const uint16_t *v, ObjectPropertyFlags flags); +ObjectProperty *object_class_property_add_uint16_ptr (ObjectClass *klass, +const char *name, +ptrdiff_t v, +ObjectPropertyFlags flags); + ObjectProperty *object_class_static_property_add_uint16_ptr(ObjectClass *klass, const char *name, const uint16_t *v,
qom/object.c +44 -0
56 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 4/12 qom/object.c: add object_class_property_add_uint32_ptr()
In reply to Mark Cave-AylandThis adds a class property that references a uint32_t within the object instance and is intended to be a replacement for object_property_add_uint32_ptr().
--- include/qom/object.h | 5 +++++ qom/object.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+)
include/qom/object.h +5 -0
@@ -2008,6 +2008,11 @@ ObjectProperty *object_property_add_uint32_ptr(Object *obj, const char *name,const uint32_t *v, ObjectPropertyFlags flags); +ObjectProperty *object_class_property_add_uint32_ptr (ObjectClass *klass, +const char *name, +ptrdiff_t v, +ObjectPropertyFlags flags); + ObjectProperty *object_class_static_property_add_uint32_ptr(ObjectClass *klass, const char *name, const uint32_t *v,
qom/object.c +44 -0
56 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 5/12 qom/object.c: add object_class_property_add_uint64_ptr()
In reply to Mark Cave-AylandThis adds a class property that references a uint8_t within the object instance and is intended to be a replacement for object_property_add_uint8_ptr().
--- include/qom/object.h | 5 +++++ qom/object.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+)
include/qom/object.h +5 -0
@@ -2034,6 +2034,11 @@ ObjectProperty *object_property_add_uint64_ptr(Object *obj, const char *name,const uint64_t *v, ObjectPropertyFlags flags); +ObjectProperty *object_class_property_add_uint64_ptr (ObjectClass *klass, +const char *name, +ptrdiff_t v, +ObjectPropertyFlags flags); + ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass, const char *name, const uint64_t *v,
qom/object.c +44 -0
56 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 6/12 hw/acpi/ich9.c: move initial property values into ich9_reset_properties()
In reply to Mark Cave-Ayland--- include/hw/acpi/ich9.h | 2 ++ hw/acpi/ich9.c | 8 ++++++-- hw/isa/lpc_ich9.c | 1 + 3 files changed, 9 insertions(+), 2 deletions(-)
include/hw/acpi/ich9.h +2 -0
@@ -81,6 +81,8 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm, qemu_irq sci_irq);void ich9_pm_iospace_update (ICH9LPCPMRegs *pm,uint32_t pm_io_base);extern const VMStateDescription vmstate_ich9_pm; +void ich9_pm_reset_properties (ICH9LPCPMRegs *pm); +void ich9_pm_add_properties (Object *obj,ICH9LPCPMRegs *pm); void ich9_pm_device_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
hw/acpi/ich9.c +6 -2
@@ -388,9 +388,8 @@ static void ich9_pm_set_keep_pci_slot_hpc(Object *obj, bool value, Error **errp) s->pm.keep_pci_slot_hpc = value; } -void ich9_pm_add_properties (Object *obj,ICH9LPCPMRegs *pm) +void ich9_pm_reset_properties (ICH9LPCPMRegs *pm) { -static const uint32_t gpe0_len =ICH9_PMIO_GPE0_LEN ; pm->acpi_memory_hotplug.is_enabled = true; pm->disable_s3 =0 ; pm->disable_s4 =0 ;
@@ -398,6 +397,11 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm) pm->acpi_pci_hotplug.use_acpi_hotplug_bridge = true; pm->keep_pci_slot_hpc = true; pm->enable_tco = true; +} + +void ich9_pm_add_properties (Object *obj,ICH9LPCPMRegs *pm) +{ +static const uint32_t gpe0_len =ICH9_PMIO_GPE0_LEN ;object_property_add_uint32_ptr (obj,ACPI_PM_PROP_PM_IO_BASE , &pm->pm_io_base,OBJ_PROP_FLAG_READ );
hw/isa/lpc_ich9.c +1 -0
@@ -701,6 +701,7 @@ static void ich9_lpc_initfn(Object *obj) &lpc->smi_negotiated_features, OBJ_PROP_FLAG_READ); +ich9_pm_reset_properties (&lpc->pm);ich9_pm_add_properties (obj, &lpc->pm); }
Signature · 1 line
2.43.0
Re: [PATCH v2 06/12] hw/acpi/ich9.c: move initial property values into ich9_reset_properties()
Quoted 6 lines · Mark Cave-Ayland
Signed-off-by Mark Cave-Ayland <[email protected]>--- include/hw/acpi/ich9.h | 2 ++ hw/acpi/ich9.c | 8 ++++++-- hw/isa/lpc_ich9.c | 1 + 3 files changed, 9 insertions(+), 2 deletions(-)
PATCH v2 7/12 hw/isa/lpc_ich9.c: convert ich9_lpc_initfn() object props to class props
In reply to Mark Cave-Ayland--- hw/isa/lpc_ich9.c | 68 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 13 deletions(-)
hw/isa/lpc_ich9.c +55 -13
@@ -683,24 +683,11 @@ static void ich9_lpc_initfn(Object *obj) {ICH9LPCState *lpc =ICH9_LPC_DEVICE (obj); -static const uint8_t acpi_enable_cmd =ICH9_APM_ACPI_ENABLE ; -static const uint8_t acpi_disable_cmd =ICH9_APM_ACPI_DISABLE ; -object_initialize_child (obj,"rtc" , &lpc->rtc,TYPE_MC146818_RTC );qdev_init_gpio_out_named (DEVICE (lpc), lpc->gsi,ICH9_GPIO_GSI ,IOAPIC_NUM_PINS ); -object_property_add_uint8_ptr (obj,ACPI_PM_PROP_SCI_INT , - &lpc->sci_gsi,OBJ_PROP_FLAG_READ ); -object_property_add_uint8_ptr (OBJECT (lpc),ACPI_PM_PROP_ACPI_ENABLE_CMD , - &acpi_enable_cmd,OBJ_PROP_FLAG_READ ); -object_property_add_uint8_ptr (OBJECT (lpc),ACPI_PM_PROP_ACPI_DISABLE_CMD , - &acpi_disable_cmd,OBJ_PROP_FLAG_READ ); -object_property_add_uint64_ptr (obj,ICH9_LPC_SMI_NEGOTIATED_FEAT_PROP , - &lpc->smi_negotiated_features, -OBJ_PROP_FLAG_READ ); -ich9_pm_reset_properties (&lpc->pm);ich9_pm_add_properties (obj, &lpc->pm); }
@@ -880,6 +867,40 @@ static void build_ich9_isa_aml(AcpiDevAmlIf *adev, Aml *scope)qbus_build_aml (bus, scope); } +static void ich9_lpc_get_sci_int (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +ICH9LPCState *lpc =ICH9_LPC_DEVICE (obj); +uint8_t sci_gsi = lpc->sci_gsi; + +visit_type_uint8 (v, name, &sci_gsi, errp); +} + +static void ich9_lpc_get_smi_negotiated_feat (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +ICH9LPCState *lpc =ICH9_LPC_DEVICE (obj); +uint64_t smi_negotiated_features = lpc->smi_negotiated_features; + +visit_type_uint64 (v, name, &smi_negotiated_features, errp); +} + +static void ich9_lpc_set_smi_negotiated_feat (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +ICH9LPCState *lpc =ICH9_LPC_DEVICE (obj); +uint64_t smi_negotiated_features = lpc->smi_negotiated_features; + +if (!visit_type_uint64 (v, name, &smi_negotiated_features, errp)) { +return ; + } + + lpc->smi_negotiated_features = smi_negotiated_features; +} +static void ich9_lpc_class_init (ObjectClass *klass,const void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -888,6 +909,9 @@ static void ich9_lpc_class_init(ObjectClass *klass, const void *data)AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_CLASS (klass);AcpiDevAmlIfClass *amldevc =ACPI_DEV_AML_IF_CLASS (klass); +static const uint8_t acpi_enable_cmd =ICH9_APM_ACPI_ENABLE ; +static const uint8_t acpi_disable_cmd =ICH9_APM_ACPI_DISABLE ; +set_bit (DEVICE_CATEGORY_BRIDGE , dc->categories);device_class_set_legacy_reset (dc, ich9_lpc_reset); k->realize = ich9_lpc_realize;
@@ -912,6 +936,24 @@ static void ich9_lpc_class_init(ObjectClass *klass, const void *data) adevc->ospm_status = ich9_pm_ospm_status; adevc->send_event = ich9_send_gpe; amldevc->build_dev_aml = build_ich9_isa_aml; + +object_class_property_add (klass,ACPI_PM_PROP_SCI_INT ,"uint8" , + ich9_lpc_get_sci_int, +NULL , +NULL ,NULL ); +object_class_static_property_add_uint8_ptr (klass, +ACPI_PM_PROP_ACPI_ENABLE_CMD , + &acpi_enable_cmd, +OBJ_PROP_FLAG_READ ); +object_class_static_property_add_uint8_ptr (klass, +ACPI_PM_PROP_ACPI_DISABLE_CMD , + &acpi_disable_cmd, +OBJ_PROP_FLAG_READ ); +object_class_property_add (klass,ICH9_LPC_SMI_NEGOTIATED_FEAT_PROP , +"uint64" , + ich9_lpc_get_smi_negotiated_feat, + ich9_lpc_set_smi_negotiated_feat, +NULL ,NULL ); }static const TypeInfo ich9_lpc_info = {
Signature · 1 line
2.43.0
PATCH v2 8/12 hw/acpi/ich9.c: don't pass ICH9LPCPMRegs via opaque for ACPI_PM_PROP_GPE0_BLK prop
In reply to Mark Cave-AylandIn order to convert to a class property, the ICH9LPCPMRegs instance must be resolved by the getter/setter instead of being passed directly as an opaque.
--- hw/acpi/ich9.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/acpi/ich9.c +3 -2
@@ -342,7 +342,8 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm, qemu_irq sci_irq)static void ich9_pm_get_gpe0_blk (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) { -ICH9LPCPMRegs *pm = opaque; +ICH9LPCState *s =ICH9_LPC_DEVICE (obj); +ICH9LPCPMRegs *pm = &s->pm;uint32_t value = pm->pm_io_base +ICH9_PMIO_GPE0_STS ;visit_type_uint32 (v, name, &value, errp);
@@ -411,7 +412,7 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm) OBJ_PROP_LINK_STRONG);object_property_add (obj,ACPI_PM_PROP_GPE0_BLK ,"uint32" , ich9_pm_get_gpe0_blk, -NULL ,NULL , pm); +NULL ,NULL ,NULL );object_property_add_uint32_ptr (obj,ACPI_PM_PROP_GPE0_BLK_LEN , &gpe0_len,OBJ_PROP_FLAG_READ ); object_property_add_uint8_ptr(obj, ACPI_PM_PROP_S3_DISABLED,
Signature · 1 line
2.43.0
Re: [PATCH v2 08/12] hw/acpi/ich9.c: don't pass ICH9LPCPMRegs via opaque for ACPI_PM_PROP_GPE0_BLK prop
Quoted 7 lines · Mark Cave-Ayland
In order to convert to a class property, the ICH9LPCPMRegs instance must be resolved by the getter/setter instead of being passed directly as an opaque.
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/acpi/ich9.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
PATCH v2 9/12 hw/acpi/ich9.c: convert object props in ICH9_LPC_DEVICE to class props
In reply to Mark Cave-Ayland--- include/hw/acpi/ich9.h | 2 +- hw/acpi/ich9.c | 62 ++++++++++++++++++++++++------------------ hw/isa/lpc_ich9.c | 2 +- 3 files changed, 37 insertions(+), 29 deletions(-)
include/hw/acpi/ich9.h +1 -1
@@ -83,7 +83,7 @@ extern const VMStateDescription vmstate_ich9_pm;void ich9_pm_reset_properties (ICH9LPCPMRegs *pm); -void ich9_pm_add_properties (Object *obj,ICH9LPCPMRegs *pm); +void ich9_pm_add_class_properties (ObjectClass *oc);void ich9_pm_device_pre_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp);
hw/acpi/ich9.c +35 -27
71 lines not on this page · raw message
hw/isa/lpc_ich9.c +1 -1
@@ -689,7 +689,6 @@ static void ich9_lpc_initfn(Object *obj) IOAPIC_NUM_PINS);ich9_pm_reset_properties (&lpc->pm); -ich9_pm_add_properties (obj, &lpc->pm); }static void ich9_lpc_realize (PCIDevice *d,Error **errp)
@@ -954,6 +953,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, const void *data) ich9_lpc_get_smi_negotiated_feat, ich9_lpc_set_smi_negotiated_feat, NULL, NULL); +ich9_pm_add_class_properties (klass); }static const TypeInfo ich9_lpc_info = {
Signature · 1 line
2.43.0
PATCH v2 10/12 hw/acpi/pcihp.c: convert ACPI_PCIHP_IO_BASE_PROP and ACPI_PCIHP_IO_BASE_PROP to class props
In reply to Mark Cave-AylandSince the objects referenced by acpi_pcihp_init() do not inherit from a common class, add ACPI_PCIHP_IO_BASE_PROP and ACPI_PCIHP_IO_BASE_PROP class properties to each referenced object and remove the object properties manually added in acpi_pcihp_init().
--- hw/acpi/generic_event_device.c | 10 ++++++++++ hw/acpi/ich9.c | 8 ++++++++ hw/acpi/pcihp.c | 5 ----- hw/acpi/piix4.c | 9 +++++++++ 4 files changed, 27 insertions(+), 5 deletions(-)
hw/acpi/generic_event_device.c +10 -0
@@ -11,6 +11,7 @@#include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/visitor.h" #include "hw/acpi/acpi.h" #include "hw/acpi/pcihp.h" #include "hw/acpi/cpu.h"
@@ -608,6 +609,15 @@ static void acpi_ged_class_init(ObjectClass *class, const void *data) adevc->ospm_status = acpi_ged_ospm_status; adevc->send_event = acpi_ged_send_event; + +object_class_property_add_uint16_ptr (class,ACPI_PCIHP_IO_BASE_PROP , + offsetof(AcpiGedState , + pcihp_state.io_base), +OBJ_PROP_FLAG_READ ); +object_class_property_add_uint16_ptr (class,ACPI_PCIHP_IO_LEN_PROP , + offsetof(AcpiGedState , + pcihp_state.io_len), +OBJ_PROP_FLAG_READ ); }static const TypeInfo acpi_ged_info = {
hw/acpi/ich9.c +8 -0
@@ -438,6 +438,14 @@ void ich9_pm_add_class_properties(ObjectClass *oc)object_class_property_add_bool (oc,"x-keep-pci-slot-hpc" , ich9_pm_get_keep_pci_slot_hpc, ich9_pm_set_keep_pci_slot_hpc); +object_class_property_add_uint16_ptr (oc,ACPI_PCIHP_IO_BASE_PROP , + offsetof(ICH9LPCState , + pm.acpi_pci_hotplug.io_base), + OBJ_PROP_FLAG_READ); +object_class_property_add_uint16_ptr (oc,ACPI_PCIHP_IO_LEN_PROP , + offsetof(ICH9LPCState , + pm.acpi_pci_hotplug.io_len), + OBJ_PROP_FLAG_READ); } void ich9_pm_device_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
hw/acpi/pcihp.c +0 -5
@@ -502,11 +502,6 @@ void acpi_pcihp_init(Object *owner, AcpiPciHpState *s,memory_region_init_io (&s->io, owner, &acpi_pcihp_io_ops, s,"acpi-pci-hotplug" , s->io_len);memory_region_add_subregion (io, s->io_base, &s->io); - -object_property_add_uint16_ptr (owner,ACPI_PCIHP_IO_BASE_PROP , &s->io_base, -OBJ_PROP_FLAG_READ ); -object_property_add_uint16_ptr (owner,ACPI_PCIHP_IO_LEN_PROP , &s->io_len, -OBJ_PROP_FLAG_READ ); }void build_append_pci_dsm_func0_common (Aml *ctx,Aml *retvar)
hw/acpi/piix4.c +9 -0
@@ -607,6 +607,15 @@ static void piix4_pm_class_init(ObjectClass *klass, const void *data) hc->is_hotpluggable_bus = piix4_is_hotpluggable_bus; adevc->ospm_status = piix4_ospm_status; adevc->send_event = piix4_send_gpe; + +object_class_property_add_uint16_ptr (klass,ACPI_PCIHP_IO_BASE_PROP , + offsetof(PIIX4PMState , + acpi_pci_hotplug.io_base), +OBJ_PROP_FLAG_READ ); +object_class_property_add_uint16_ptr (klass,ACPI_PCIHP_IO_LEN_PROP , + offsetof(PIIX4PMState , + acpi_pci_hotplug.io_len), +OBJ_PROP_FLAG_READ ); }static const TypeInfo piix4_pm_info = {
Signature · 1 line
2.43.0
PATCH v2 11/12 hw/acpi/pcihp.c: convert ACPI_PCIHP_PROP_BSEL from object prop to class prop
In reply to Mark Cave-AylandMove the ACPI_PCIHP_PROP_BSEL property to the PCIBus object and update all callers accordingly.
Since the existing logic checks for the existence of the ACPI_PCIHP_PROP_BSEL property to enable the relevant ACPI changes, set the type of the underlying variable to int32_t with a default value of -1 indicating that the property has not been set.
--- include/hw/pci/pci_bus.h | 2 ++ hw/acpi/pci-bridge.c | 9 ++++++++- hw/acpi/pcihp.c | 32 +++++++++++++++----------------- hw/arm/virt-acpi-build.c | 7 ++++++- hw/i386/acpi-build.c | 7 ++++++- hw/pci/pci.c | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 20 deletions(-)
include/hw/pci/pci_bus.h +2 -0
@@ -56,6 +56,8 @@ struct PCIBus {int *irq_count;Notifier machine_done; + +int32_t acpi_pcihp_bsel_val; };static inline bool pci_bus_is_cxl (PCIBus *bus)
hw/acpi/pci-bridge.c +8 -1
@@ -23,6 +23,8 @@ void build_pci_bridge_aml(AcpiDevAmlIf *adev, Aml *scope)if (!DEVICE (br)->hotplugged) {PCIBus *sec_bus =pci_bridge_get_sec_bus (br); +Error *local_err =NULL ; +int32_t bsel;build_append_pci_bus_devices (scope, sec_bus);
@@ -30,9 +32,14 @@ void build_pci_bridge_aml(AcpiDevAmlIf *adev, Aml *scope)* generate hotplug slots descriptors if * bridge has ACPI PCI hotplug attached, */ -if (object_property_find (OBJECT (sec_bus),ACPI_PCIHP_PROP_BSEL )) { + bsel =object_property_get_int (OBJECT (sec_bus),ACPI_PCIHP_PROP_BSEL , + &local_err); + +if (local_err ==NULL && bsel >=0 ) {build_append_pcihp_slots (scope, sec_bus); } + +error_free (local_err); } }
hw/acpi/pcihp.c +15 -17
@@ -58,8 +58,8 @@ typedef struct AcpiPciHpFind {static int acpi_pcihp_get_bsel (PCIBus *bus) {Error *local_err =NULL ; -uint64_t bsel =object_property_get_uint (OBJECT (bus),ACPI_PCIHP_PROP_BSEL , - &local_err); +int32_t bsel =object_property_get_int (OBJECT (bus),ACPI_PCIHP_PROP_BSEL , + &local_err);if (local_err || bsel >=ACPI_PCIHP_MAX_HOTPLUG_BUS ) {error_free (local_err);
@@ -78,18 +78,14 @@ typedef struct {static void *acpi_set_bsel (PCIBus *bus,void *opaque) {BSELInfo *info = opaque; -unsigned *bus_bsel;DeviceState *br = bus->qbus.parent;bool is_bridge =IS_PCI_BRIDGE (br);/* hotplugged bridges can't be described in ACPI ignore them */ if (qbus_is_hotpluggable (BUS (bus))) {if (!is_bridge || (!br->hotplugged && info->has_bridge_hotplug)) { - bus_bsel =g_malloc (sizeof *bus_bsel); - - *bus_bsel = info->bsel_alloc++; -object_property_add_uint32_ptr (OBJECT (bus),ACPI_PCIHP_PROP_BSEL , - bus_bsel,OBJ_PROP_FLAG_READ ); +object_property_set_int (OBJECT (bus),ACPI_PCIHP_PROP_BSEL , + info->bsel_alloc++,NULL ); } }
@@ -730,14 +726,16 @@ bool build_append_notification_callback(Aml *parent_scope, const PCIBus *bus)/* If bus supports hotplug select it and notify about local events */ bsel =object_property_get_qobject (OBJECT (bus),ACPI_PCIHP_PROP_BSEL ,NULL );if (bsel) { -uint64_t bsel_val =qnum_get_uint (qobject_to (QNum, bsel)); - -aml_append (method,aml_store (aml_int (bsel_val),aml_name ("BNUM" ))); -aml_append (method,aml_call2 ("DVNT" ,aml_name ("PCIU" ), -aml_int (1 )));/* Device Check */ -aml_append (method,aml_call2 ("DVNT" ,aml_name ("PCID" ), -aml_int (3 )));/* Eject Request */ - nr_notifiers++; +int32_t bsel_val =qnum_get_int (qobject_to (QNum, bsel)); + +if (bsel_val >=0 ) { +aml_append (method,aml_store (aml_int (bsel_val),aml_name ("BNUM" ))); +aml_append (method,aml_call2 ("DVNT" ,aml_name ("PCIU" ), +aml_int (1 )));/* Device Check */ +aml_append (method,aml_call2 ("DVNT" ,aml_name ("PCID" ), +aml_int (3 )));/* Eject Request */ + nr_notifiers++; + } }/* Notify about child bus events in any case */
@@ -848,7 +846,7 @@ void build_append_pcihp_slots(Aml *parent_scope, PCIBus *bus)Aml *dev, *notify_method =NULL , *method;QObject *bsel =object_property_get_qobject (OBJECT (bus),ACPI_PCIHP_PROP_BSEL ,NULL ); -uint64_t bsel_val =qnum_get_uint (qobject_to (QNum, bsel)); +int32_t bsel_val =qnum_get_int (qobject_to (QNum, bsel));qobject_unref (bsel);aml_append (parent_scope,aml_name_decl ("BSEL" ,aml_int (bsel_val)));
hw/arm/virt-acpi-build.c +6 -1
@@ -1181,6 +1181,8 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)AcpiTable table = { .sig ="DSDT" , .rev =2 , .oem_id = vms->oem_id, .oem_table_id = vms->oem_table_id };Aml *pci0_scope; +Error *local_err =NULL ; +int32_t bsel;acpi_table_begin (&table, table_data); dsdt =init_aml_allocator ();
@@ -1243,9 +1245,12 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)aml_append (pci0_scope,build_pci_bridge_edsm ());build_append_pci_bus_devices (pci0_scope, vms->bus); -if (object_property_find (OBJECT (vms->bus),ACPI_PCIHP_PROP_BSEL )) { + bsel =object_property_get_int (OBJECT (vms->bus),ACPI_PCIHP_PROP_BSEL , + &local_err); +if (local_err ==NULL && bsel >=0 ) {build_append_pcihp_slots (pci0_scope, vms->bus); } +error_free (local_err);if (vms->acpi_dev) {bool acpi_pcihp;
hw/i386/acpi-build.c +6 -1
@@ -1197,15 +1197,20 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, sb_scope =aml_scope ("\\_SB" ); {Object *pci_host =acpi_get_i386_pci_host (); +Error *local_err =NULL ; +int32_t bsel;if (pci_host) {PCIBus *pbus =PCI_HOST_BRIDGE (pci_host)->bus;Aml *ascope =aml_scope ("PCI0" );/* Scan all PCI buses. Generate tables to support hotplug. */ build_append_pci_bus_devices (ascope, pbus); -if (object_property_find (OBJECT (pbus),ACPI_PCIHP_PROP_BSEL )) { + bsel =object_property_get_int (OBJECT (pbus),ACPI_PCIHP_PROP_BSEL , + &local_err); +if (local_err ==NULL && bsel >=0 ) {build_append_pcihp_slots (ascope, pbus); } +error_free (local_err);aml_append (sb_scope, ascope); } }
hw/pci/pci.c +32 -0
@@ -25,6 +25,7 @@#include "qemu/osdep.h" #include "qemu/datadir.h" #include "qemu/units.h" +#include "hw/acpi/pcihp.h" #include "hw/core/irq.h" #include "hw/pci/pci.h" #include "hw/pci/pci_bridge.h"
@@ -187,6 +188,8 @@ static void pci_bus_realize(BusState *qbus, Error **errp) bus->machine_done.notify = pcibus_machine_done;qemu_add_machine_init_done_notifier (&bus->machine_done); + bus->acpi_pcihp_bsel_val =-1 ; +vmstate_register_any (NULL , &vmstate_pcibus, bus); }
@@ -283,6 +286,30 @@ static GByteArray *pci_bus_fw_cfg_gen_data(Object *obj, Error **errp)return byte_array; } +static void pci_bus_get_acpi_pcihp_bsel_val (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +PCIBus *bus =PCI_BUS (obj); +int32_t bsel_val = bus->acpi_pcihp_bsel_val; + +visit_type_int32 (v, name, &bsel_val, errp); +} + +static void pci_bus_set_acpi_pcihp_bsel_val (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +PCIBus *bus =PCI_BUS (obj); +int32_t bsel_val = bus->acpi_pcihp_bsel_val; + +if (!visit_type_int32 (v, name, &bsel_val, errp)) { +return ; + } + + bus->acpi_pcihp_bsel_val = bsel_val; +} +static void pci_bus_class_init (ObjectClass *klass,const void *data) {BusClass *k =BUS_CLASS (klass);
@@ -302,6 +329,11 @@ static void pci_bus_class_init(ObjectClass *klass, const void *data) pbc->numa_node = pcibus_numa_node; fwgc->get_data = pci_bus_fw_cfg_gen_data; + +object_class_property_add (klass,ACPI_PCIHP_PROP_BSEL ,"int32" , + pci_bus_get_acpi_pcihp_bsel_val, + pci_bus_set_acpi_pcihp_bsel_val, +NULL ,NULL ); }static const TypeInfo pci_bus_info = {
Signature · 1 line
2.43.0
PATCH v2 12/12 hw/acpi/piix4.c: convert object props in PIIX4_PM to class props
In reply to Mark Cave-Ayland--- hw/acpi/piix4.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-)
hw/acpi/piix4.c +27 -15
@@ -405,7 +405,7 @@ static void piix4_pm_machine_ready(Notifier *n, void *opaque) (memory_region_present (io_as,0x2f8 ) ?0x90 :0 ); } -static void piix4_pm_add_properties (PIIX4PMState *s) +static void piix4_pm_add_class_properties (ObjectClass *oc) {static const uint8_t acpi_enable_cmd =ACPI_ENABLE ;static const uint8_t acpi_disable_cmd =ACPI_DISABLE ;
@@ -413,18 +413,30 @@ static void piix4_pm_add_properties(PIIX4PMState *s)static const uint32_t gpe0_blk_len =GPE_LEN ;static const uint16_t sci_int =9 ; -object_property_add_uint8_ptr (OBJECT (s),ACPI_PM_PROP_ACPI_ENABLE_CMD , - &acpi_enable_cmd,OBJ_PROP_FLAG_READ ); -object_property_add_uint8_ptr (OBJECT (s),ACPI_PM_PROP_ACPI_DISABLE_CMD , - &acpi_disable_cmd,OBJ_PROP_FLAG_READ ); -object_property_add_uint32_ptr (OBJECT (s),ACPI_PM_PROP_GPE0_BLK , - &gpe0_blk,OBJ_PROP_FLAG_READ ); -object_property_add_uint32_ptr (OBJECT (s),ACPI_PM_PROP_GPE0_BLK_LEN , - &gpe0_blk_len,OBJ_PROP_FLAG_READ ); -object_property_add_uint16_ptr (OBJECT (s),ACPI_PM_PROP_SCI_INT , - &sci_int,OBJ_PROP_FLAG_READ ); -object_property_add_uint32_ptr (OBJECT (s),ACPI_PM_PROP_PM_IO_BASE , - &s->io_base,OBJ_PROP_FLAG_READ ); +object_class_static_property_add_uint8_ptr (oc, +ACPI_PM_PROP_ACPI_ENABLE_CMD , + &acpi_enable_cmd, +OBJ_PROP_FLAG_READ ); +object_class_static_property_add_uint8_ptr (oc, +ACPI_PM_PROP_ACPI_DISABLE_CMD , + &acpi_disable_cmd, +OBJ_PROP_FLAG_READ ); +object_class_static_property_add_uint32_ptr (oc, +ACPI_PM_PROP_GPE0_BLK , + &gpe0_blk, +OBJ_PROP_FLAG_READ ); +object_class_static_property_add_uint32_ptr (oc, +ACPI_PM_PROP_GPE0_BLK_LEN , + &gpe0_blk_len, +OBJ_PROP_FLAG_READ ); +object_class_static_property_add_uint16_ptr (oc, +ACPI_PM_PROP_SCI_INT , + &sci_int, +OBJ_PROP_FLAG_READ ); +object_class_property_add_uint32_ptr (oc, +ACPI_PM_PROP_PM_IO_BASE , + offsetof(PIIX4PMState , io_base), +OBJ_PROP_FLAG_READ ); }static void piix4_pm_realize (PCIDevice *dev,Error **errp)
@@ -480,8 +492,6 @@ static void piix4_pm_realize(PCIDevice *dev, Error **errp)piix4_acpi_system_hot_add_init (pci_address_space_io (dev),pci_get_bus (dev), s); - -piix4_pm_add_properties (s); }static void piix4_pm_init (Object *obj)
@@ -616,6 +626,8 @@ static void piix4_pm_class_init(ObjectClass *klass, const void *data) offsetof(PIIX4PMState , acpi_pci_hotplug.io_len), OBJ_PROP_FLAG_READ); + +piix4_pm_add_class_properties (klass); }static const TypeInfo piix4_pm_info = {
Signature · 1 line
2.43.0