hw/acpi: convert object props to class props
v4 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.]
[Note: this will have substantial conflicts with Marc-André's series "qom/qdev:
associate properties with QAPI schema types" at
https://patchew.org/QEMU/[email protected]/.]
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.
The following warnings below are generated by checkpatch but are incorrect since they form part of macro definitions:
1/16 Checking commit 58e8d5fb5971 (qom/object.c: introduce OBJECT_CLASS_PROPERTY_SCALAR_GETTER(type) macro)
ERROR: spaces required around that '*' (ctx:WxB)
#41: FILE: qom/object.c:2720:
+ type##_t value = *(type##_t *)object_class_prop_ptr(obj, \
^total: 1 errors, 0 warnings, 28 lines checked
Patch 1/16 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
2/15 Checking commit 2068ae0d4ded (qom/object.c: introduce OBJECT_CLASS_PROPERTY_SCALAR_SETTER(type) macro)
ERROR: spaces required around that '*' (ctx:WxV)
#28: FILE: qom/object.c:2730:
+ type##_t *field = (type##_t *)object_class_prop_ptr(obj, \
^ERROR: spaces required around that '*' (ctx:WxB)
#28: FILE: qom/object.c:2730:
+ type##_t *field = (type##_t *)object_class_prop_ptr(obj, \
(Patches still requiring review: 5, 6)
v4:
- Add R-B tags from Marc-André
- Fix comments mismatch within object_class_property_add_*_ptr() descriptions in object.h
- Add patch 5 implementing object_class_property_add_uint64_ptr() now required by patch 6
- Don't promote ICH9_LPC_SMI_NEGOTIATED_FEAT_PROP to a Property in patch 6 since it must be marked as read-only: use object_class_property_add_uint64_ptr() instead
v3:
- Re-implement the object_class_property_add_*_ptr() get/set functions using new OBJECT_CLASS_PROPERTY_SCALAR_GETTER() and OBJECT_CLASS_PROPERTY_SCALAR_SETTER() macros, similar as has already been done for object properties
- Drop most R-B tags since nearly all patches have changed since v2
- Split conversion of static variables to static class properties into separate commits to act as a reference for future conversions
- Drop patch 6 from v2 since that has already been merged separately by Phil
- Use UINT32_MAX to indicate ACPI_PCIHP_PROP_BSEL has not been set in patch 13 instead of -1. This is because the existing object_property_add_*_ptr() functions always use unsigned scalars: let's try and keep this the same for the object_class_property_add_*_ptr() functions if possible
- Add a new object_class_property_add_bool_ptr() function rather than using object_class_property_add_bool() in patch 10 since it avoids writing explicit helpers for each property, and there will likely be other cases in future
- Rebase onto master
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 (16):
qom/object.c: introduce OBJECT_CLASS_PROPERTY_SCALAR_GETTER(type)
macro
qom/object.c: introduce OBJECT_CLASS_PROPERTY_SCALAR_SETTER(type)
macro
qom/object.c: introduce DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS()
macro
qom/object.c: add object_class_property_add_uint8_ptr() qom/object.c: add object_class_property_add_uint64_ptr() 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
qom/object.c: add object_class_property_add_uint32_ptr() hw/acpi/ich9.c: convert ACPI_PM_PROP_GPE0_BLK_LEN to a static class
property
qom/object.c: add object_class_property_add_bool_ptr() hw/acpi/ich9.c: convert object props in ICH9_LPC_DEVICE to class props qom/object.c: add object_class_property_add_uint16_ptr() 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 static variables to static class properties hw/acpi/piix4.c: convert ACPI_PM_PROP_PM_IO_BASE to a class prop
include/hw/acpi/ich9.h | 2 +- include/hw/pci/pci_bus.h | 2 + include/qom/object.h | 90 +++++++++++++++++ hw/acpi/generic_event_device.c | 10 ++ hw/acpi/ich9.c | 126 +++++++++++------------- hw/acpi/pci-bridge.c | 9 +- hw/acpi/pcihp.c | 35 +++---- hw/acpi/piix4.c | 51 +++++++--- hw/arm/virt-acpi-build.c | 7 +- hw/i386/acpi-build.c | 7 +- hw/isa/lpc_ich9.c | 36 ++++--- hw/pci/pci.c | 7 ++ qom/object.c | 171 +++++++++++++++++++++++++++++++++ 13 files changed, 431 insertions(+), 122 deletions(-)
Signature · 1 line
2.43.0
PATCH v4 1/16 qom/object.c: introduce OBJECT_CLASS_PROPERTY_SCALAR_GETTER(type) macro
This macro will be used to generate the boilerplate property_class_get_type_ptr() QOM get function for the specified scalar type.
Note that since the macro is currently unused, the object_class_prop_ptr() helper function is temporarily marked as __attribute__((unused)) to allow compilation to succeed.
--- qom/object.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
qom/object.c +22 -0
@@ -2703,6 +2703,28 @@ DEFINE_OBJECT_PROPERTY_SCALAR_METHODS(uint64)#undef DEFINE_OBJECT_PROPERTY_SCALAR_METHODS +__attribute__((unused)) +static void *object_class_prop_ptr (Object *obj,ptrdiff_t offset) +{ +void *ptr = obj; + ptr += offset; + +return ptr; +} + +#define OBJECT_CLASS_PROPERTY_SCALAR_GETTER (type) \ + static void property_class_get_##type##_ptr(Object *obj, Visitor *v, \ + const char *name, \ + void *opaque, Error **errp) \ + { \ + type##_t value = *(type##_t *)object_class_prop_ptr(obj, \ + (ptrdiff_t)opaque); \ + visit_type_##type(v, name, &value, errp); \ + } + +#undef OBJECT_CLASS_PROPERTY_SCALAR_GETTER + +ObjectProperty * object_property_add_uint8_ptr(Object *obj, const char *name, const uint8_t *v,
Signature · 1 line
2.43.0
Re: [PATCH v4 01/16] qom/object.c: introduce OBJECT_CLASS_PROPERTY_SCALAR_GETTER(type) macro
Quoted 7 lines · Mark Cave-Ayland
This macro will be used to generate the boilerplate
property_class_get_type_ptr()QOM get function for the specified scalar type.Note that since the macro is currently unused, the
object_class_prop_ptr()helper function is temporarily marked as __attribute__((unused)) to allow compilation to succeed.
Quoted 5 lines
Signed-off-by Mark Cave-Ayland <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- qom/object.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
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 v4 2/16 qom/object.c: introduce OBJECT_CLASS_PROPERTY_SCALAR_SETTER(type) macro
In reply to Mark Cave-AylandThis macro will be used to generate the boilerplate property_class_set_type_ptr() QOM set function for the specified scalar type.
--- qom/object.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
qom/object.c +17 -0
@@ -2722,7 +2722,24 @@ static void *object_class_prop_ptr(Object *obj, ptrdiff_t offset) visit_type_##type(v, name, &value, errp); \ } +#define OBJECT_CLASS_PROPERTY_SCALAR_SETTER (type) \ + static void property_class_set_##type##_ptr(Object *obj, Visitor *v, \ + const char *name, \ + void *opaque, Error **errp) \ + { \ + type##_t *field = (type##_t *)object_class_prop_ptr(obj, \ + (ptrdiff_t)opaque); \ + type##_t value; \ + \ + if (!visit_type_##type(v, name, &value, errp)) { \ + return; \ + } \ + \ + *field = value; \ + } +#undef OBJECT_CLASS_PROPERTY_SCALAR_GETTER +#undef OBJECT_CLASS_PROPERTY_SCALAR_SETTER ObjectProperty *
Signature · 1 line
2.43.0
Re: [PATCH v4 02/16] qom/object.c: introduce OBJECT_CLASS_PROPERTY_SCALAR_SETTER(type) macro
Quoted 8 lines · Mark Cave-Ayland
This macro will be used to generate the boilerplate
property_class_set_type_ptr()QOM set function for the specified scalar type.Signed-off-by Mark Cave-Ayland <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- qom/object.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
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 v4 3/16 qom/object.c: introduce DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS() macro
In reply to Mark Cave-AylandThis macro defines both the QOM get and set functions for the given scaler type.
--- qom/object.c | 5 +++++ 1 file changed, 5 insertions(+)
qom/object.c +5 -0
@@ -2738,8 +2738,13 @@ static void *object_class_prop_ptr(Object *obj, ptrdiff_t offset) *field = value; \ } +#define DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS (type) \ + OBJECT_CLASS_PROPERTY_SCALAR_GETTER(type) \ + OBJECT_CLASS_PROPERTY_SCALAR_SETTER(type) +#undef OBJECT_CLASS_PROPERTY_SCALAR_GETTER#undef OBJECT_CLASS_PROPERTY_SCALAR_SETTER +#undef DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS ObjectProperty *
Signature · 1 line
2.43.0
Re: [PATCH v4 03/16] qom/object.c: introduce DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS() macro
Quoted 8 lines · Mark Cave-Ayland
This macro defines both the QOM get and set functions for the given scaler type.
Signed-off-by Mark Cave-Ayland <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- qom/object.c | 5 +++++ 1 file changed, 5 insertions(+)
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 v4 4/16 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().
This commit also removes the __attribute__((unused)) annotation from object_class_prop_ptr() which is no longer required now that the previous defined DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS() is now being used.
--- include/qom/object.h | 18 ++++++++++++++++++ qom/object.c | 23 ++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-)
include/qom/object.h +18 -0
@@ -2033,6 +2033,24 @@ ObjectProperty *object_property_add_uint8_ptr(Object *obj, const char *name,const uint8_t *v, ObjectPropertyFlags flags); +/** +* object_class_property_add_uint8_ptr: +* @klass: the object class to add a property to +* @name: the name of the property +* @offset: the offset from the object instance where the uint8 value is +* stored +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add an integer property in memory. This function will add a +* property of type 'uint8'. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty *object_class_property_add_uint8_ptr (ObjectClass *klass, +const char *name, +ptrdiff_t offset, +ObjectPropertyFlags flags); +/** * object_class_static_property_add_uint8_ptr: * @klass: the object class to add a static property to
qom/object.c +22 -1
@@ -2703,7 +2703,6 @@ DEFINE_OBJECT_PROPERTY_SCALAR_METHODS(uint64)#undef DEFINE_OBJECT_PROPERTY_SCALAR_METHODS -__attribute__((unused))static void *object_class_prop_ptr (Object *obj,ptrdiff_t offset) {void *ptr = obj;
@@ -2742,6 +2741,8 @@ static void *object_class_prop_ptr(Object *obj, ptrdiff_t offset) OBJECT_CLASS_PROPERTY_SCALAR_GETTER(type) \ OBJECT_CLASS_PROPERTY_SCALAR_SETTER(type) +DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(uint8) +#undef OBJECT_CLASS_PROPERTY_SCALAR_GETTER#undef OBJECT_CLASS_PROPERTY_SCALAR_SETTER#undef DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS
@@ -2767,6 +2768,26 @@ object_property_add_uint8_ptr(Object *obj, const char *name, getter, setter, NULL, (void *)v); } +ObjectProperty * +object_class_property_add_uint8_ptr (ObjectClass *klass,const char *name, +ptrdiff_t offset, +ObjectPropertyFlags flags) +{ +ObjectPropertyAccessor *getter =NULL ; +ObjectPropertyAccessor *setter =NULL ; + +if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { + getter = property_class_get_uint8_ptr; + } + +if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { + setter = property_class_set_uint8_ptr; + } + +return object_class_property_add (klass, name,"uint8" , + getter, setter,NULL , (void *)offset); +} +ObjectProperty * object_class_static_property_add_uint8_ptr(ObjectClass *klass, const char *name,
Signature · 1 line
2.43.0
Re: [PATCH v4 04/16] qom/object.c: add object_class_property_add_uint8_ptr()
Quoted 7 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().This commit also removes the __attribute__((unused)) annotation from
object_class_prop_ptr()which is no longer required now that the previous definedDEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS()is now being used.
Quoted 6 lines
Signed-off-by Mark Cave-Ayland <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- include/qom/object.h | 18 ++++++++++++++++++ qom/object.c | 23 ++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-)
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 v4 5/16 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_uint64_ptr().
--- include/qom/object.h | 18 ++++++++++++++++++ qom/object.c | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+)
include/qom/object.h +18 -0
@@ -2168,6 +2168,24 @@ ObjectProperty *object_property_add_uint64_ptr(Object *obj, const char *name,const uint64_t *v, ObjectPropertyFlags flags); +/** +* object_class_property_add_uint64_ptr: +* @klass: the object class to add a property to +* @name: the name of the property +* @offset: the offset from the object instance where the uint64 value is +* stored +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add an integer property in memory. This function will add a +* property of type 'uint64'. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty *object_class_property_add_uint64_ptr (ObjectClass *klass, +const char *name, +ptrdiff_t offset, +ObjectPropertyFlags flags); +/** * object_class_static_property_add_uint64_ptr: * @klass: the object class to add a static property to
qom/object.c +21 -0
@@ -2742,6 +2742,7 @@ static void *object_class_prop_ptr(Object *obj, ptrdiff_t offset) OBJECT_CLASS_PROPERTY_SCALAR_SETTER(type) DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(uint8) +DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(uint64)#undef OBJECT_CLASS_PROPERTY_SCALAR_GETTER#undef OBJECT_CLASS_PROPERTY_SCALAR_SETTER
@@ -2911,6 +2912,26 @@ object_property_add_uint64_ptr(Object *obj, const char *name, getter, setter, NULL, (void *)v); } +ObjectProperty * +object_class_property_add_uint64_ptr (ObjectClass *klass,const char *name, +ptrdiff_t offset, +ObjectPropertyFlags flags) +{ +ObjectPropertyAccessor *getter =NULL ; +ObjectPropertyAccessor *setter =NULL ; + +if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { + getter = property_class_get_uint64_ptr; + } + +if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { + setter = property_class_set_uint64_ptr; + } + +return object_class_property_add (klass, name,"uint64" , + getter, setter,NULL , (void *)offset); +} +ObjectProperty * object_class_static_property_add_uint64_ptr(ObjectClass *klass, const char *name,
Signature · 1 line
2.43.0
Re: [PATCH v4 05/16] qom/object.c: add object_class_property_add_uint64_ptr()
Quoted 8 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_uint64_ptr().Signed-off-by Mark Cave-Ayland <[email protected]>--- include/qom/object.h | 18 ++++++++++++++++++ qom/object.c | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+)
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 v4 6/16 hw/isa/lpc_ich9.c: convert ich9_lpc_initfn() object props to class props
In reply to Mark Cave-AylandACPI_PM_PROP_SCI_INT can be updated to use object_class_property_add_uint8_ptr() with OBJ_PROP_FLAG_READ, whilst ICH9_LPC_SMI_NEGOTIATED_FEAT_PROP can be updated to use object_class_property_add_uint64_ptr().
--- hw/isa/lpc_ich9.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-)
hw/isa/lpc_ich9.c +20 -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); }
@@ -888,6 +875,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 +902,23 @@ 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_uint8_ptr (klass,ACPI_PM_PROP_SCI_INT , + offsetof(ICH9LPCState , sci_gsi), +OBJ_PROP_FLAG_READ ); +object_class_property_add_uint64_ptr (klass, +ICH9_LPC_SMI_NEGOTIATED_FEAT_PROP , + offsetof(ICH9LPCState , + smi_negotiated_features), +OBJ_PROP_FLAG_READ ); +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 ); }static const TypeInfo ich9_lpc_info = {
Signature · 1 line
2.43.0
Re: [PATCH v4 06/16] hw/isa/lpc_ich9.c: convert ich9_lpc_initfn() object props to class props
Quoted 8 lines · Mark Cave-Ayland
ACPI_PM_PROP_SCI_INTcan be updated to useobject_class_property_add_uint8_ptr()withOBJ_PROP_FLAG_READ, whilstICH9_LPC_SMI_NEGOTIATED_FEAT_PROPcan be updated to useobject_class_property_add_uint64_ptr().Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/isa/lpc_ich9.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-)
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 v4 7/16 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 v4 07/16] hw/acpi/ich9.c: don't pass ICH9LPCPMRegs via opaque for ACPI_PM_PROP_GPE0_BLK prop
Quoted 9 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]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- hw/acpi/ich9.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
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 v4 8/16 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 | 18 ++++++++++++++++++ qom/object.c | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+)
include/qom/object.h +18 -0
@@ -2129,6 +2129,24 @@ ObjectProperty *object_property_add_uint32_ptr(Object *obj, const char *name,const uint32_t *v, ObjectPropertyFlags flags); +/** +* object_class_property_add_uint32_ptr: +* @klass: the object class to add a property to +* @name: the name of the property +* @offset: the offset from the object instance where the uint32 value is +* stored +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add an integer property in memory. This function will add a +* property of type 'uint32'. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty *object_class_property_add_uint32_ptr (ObjectClass *klass, +const char *name, +ptrdiff_t offset, +ObjectPropertyFlags flags); +/** * object_class_static_property_add_uint32_ptr: * @klass: the object class to add a static property to
qom/object.c +21 -0
@@ -2742,6 +2742,7 @@ static void *object_class_prop_ptr(Object *obj, ptrdiff_t offset) OBJECT_CLASS_PROPERTY_SCALAR_SETTER(type) DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(uint8) +DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(uint32) DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(uint64)#undef OBJECT_CLASS_PROPERTY_SCALAR_GETTER
@@ -2871,6 +2872,26 @@ object_property_add_uint32_ptr(Object *obj, const char *name, getter, setter, NULL, (void *)v); } +ObjectProperty * +object_class_property_add_uint32_ptr (ObjectClass *klass,const char *name, +ptrdiff_t offset, +ObjectPropertyFlags flags) +{ +ObjectPropertyAccessor *getter =NULL ; +ObjectPropertyAccessor *setter =NULL ; + +if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { + getter = property_class_get_uint32_ptr; + } + +if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { + setter = property_class_set_uint32_ptr; + } + +return object_class_property_add (klass, name,"uint32" , + getter, setter,NULL , (void *)offset); +} +ObjectProperty * object_class_static_property_add_uint32_ptr(ObjectClass *klass, const char *name,
Signature · 1 line
2.43.0
Re: [PATCH v4 08/16] qom/object.c: add object_class_property_add_uint32_ptr()
Quoted 9 lines · Mark Cave-Ayland
This adds a class property that references a
uint32_twithin the object instance and is intended to be a replacement forobject_property_add_uint32_ptr().Signed-off-by Mark Cave-Ayland <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- include/qom/object.h | 18 ++++++++++++++++++ qom/object.c | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+)
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 v4 9/16 hw/acpi/ich9.c: convert ACPI_PM_PROP_GPE0_BLK_LEN to a static class property
In reply to Mark Cave-AylandThe ACPI_PM_PROP_GPE0_BLK_LEN property is assigned to a static variable and so can be converted to a static class property. Introduce ich9_pm_add_class_properties() to hold the ACPI_PM_PROP_GPE0_BLK_LEN property and soon all other class props after they have been converted from object props.
--- include/hw/acpi/ich9.h | 1 + hw/acpi/ich9.c | 14 ++++++++++---- hw/isa/lpc_ich9.c | 2 ++ 3 files changed, 13 insertions(+), 4 deletions(-)
include/hw/acpi/ich9.h +1 -0
@@ -84,6 +84,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 +10 -4
@@ -402,8 +402,6 @@ void ich9_pm_reset_properties(ICH9LPCPMRegs *pm)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 ); object_property_add_link(obj, "bus", TYPE_PCI_BUS,
@@ -413,8 +411,6 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm)object_property_add (obj,ACPI_PM_PROP_GPE0_BLK ,"uint32" , ich9_pm_get_gpe0_blk,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 , &pm->disable_s3,OBJ_PROP_FLAG_READWRITE ); object_property_add_uint8_ptr(obj, ACPI_PM_PROP_S4_DISABLED,
@@ -432,6 +428,16 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm) ich9_pm_set_keep_pci_slot_hpc); } +void ich9_pm_add_class_properties (ObjectClass *oc) +{ +static const uint32_t gpe0_len =ICH9_PMIO_GPE0_LEN ; + +object_class_static_property_add_uint32_ptr (oc, +ACPI_PM_PROP_GPE0_BLK_LEN , + &gpe0_len, +OBJ_PROP_FLAG_READ ); +} +void ich9_pm_device_pre_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) {
hw/isa/lpc_ich9.c +2 -0
@@ -919,6 +919,8 @@ static void ich9_lpc_class_init(ObjectClass *klass, const void *data)ACPI_PM_PROP_ACPI_DISABLE_CMD , &acpi_disable_cmd, OBJ_PROP_FLAG_READ); + +ich9_pm_add_class_properties (klass); }static const TypeInfo ich9_lpc_info = {
Signature · 1 line
2.43.0
Re: [PATCH v4 09/16] hw/acpi/ich9.c: convert ACPI_PM_PROP_GPE0_BLK_LEN to a static class property
Quoted 5 lines · Mark Cave-Ayland
The
ACPI_PM_PROP_GPE0_BLK_LENproperty is assigned to a static variable and so can be converted to a static class property. Introduceich9_pm_add_class_properties()to hold theACPI_PM_PROP_GPE0_BLK_LENproperty and soon all other class props after they have been converted from object props.
Quoted 8 lines
Signed-off-by Mark Cave-Ayland <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- include/hw/acpi/ich9.h | 1 + hw/acpi/ich9.c | 14 ++++++++++---- hw/isa/lpc_ich9.c | 2 ++ 3 files changed, 13 insertions(+), 4 deletions(-)
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 v4 10/16 qom/object.c: add object_class_property_add_bool_ptr()
In reply to Mark Cave-AylandThis adds a class property that references a bool within the object instance and is intended to be used as a replacement for object_class_property_add_bool() where possible.
--- include/qom/object.h | 18 ++++++++++++++++++ qom/object.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+)
include/qom/object.h +18 -0
@@ -2017,6 +2017,24 @@ typedef enum {OBJ_PROP_FLAG_READWRITE = (OBJ_PROP_FLAG_READ |OBJ_PROP_FLAG_WRITE ), } ObjectPropertyFlags; +/** +* object_class_property_add_bool_ptr: +* @klass: the object class to add a property to +* @name: the name of the property +* @offset: the offset from the object instance where the bool value is +* stored +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add an boolean property in memory. This function will add a +* property of type 'bool'. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty *object_class_property_add_bool_ptr (ObjectClass *klass, +const char *name, +ptrdiff_t offset, +ObjectPropertyFlags flags); +/** * object_property_add_uint8_ptr: * @obj: the object to add a property to
qom/object.c +43 -0
49 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v4 10/16] qom/object.c: add object_class_property_add_bool_ptr()
Quoted 60 lines · Mark Cave-Ayland
This adds a class property that references a bool within the object instance and is intended to be used as a replacement for
object_class_property_add_bool()where possible.Signed-off-by Mark Cave-Ayland <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- include/qom/object.h | 18 ++++++++++++++++++ qom/object.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+)include/qom/object.h +18
-0@@ -2017,6 +2017,24 @@ typedef enum {OBJ_PROP_FLAG_READWRITE = (OBJ_PROP_FLAG_READ |OBJ_PROP_FLAG_WRITE ), } ObjectPropertyFlags; +/** +* object_class_property_add_bool_ptr: +* @klass: the object class to add a property to +* @name: the name of the property +* @offset: the offset from the object instance where the bool value is +* stored +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add an boolean property in memory. This function will add a +* property of type 'bool'. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty *object_class_property_add_bool_ptr (ObjectClass *klass, +const char *name, +ptrdiff_t offset, +ObjectPropertyFlags flags); +/** * object_property_add_uint8_ptr: * @obj: the object to add a property to qom/object.c +12
-0@@ -2750,6 +2750,49 @@ DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(uint64)#undef DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS +static void property_class_get_bool_ptr (Object *obj,Visitor *v, +const char *name, +void *opaque,Error **errp) +{ +bool value = *(bool *)object_class_prop_ptr (obj, (ptrdiff_t )opaque); + +visit_type_bool (v, name, &value, errp); +} + +static void property_class_set_bool_ptr (Object *obj,Visitor *v, +const char *name, +void *opaque,Error **errp)
qom/object.c DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(uint64) · line 2774
Quoted 10 lines
qom/object.c +10
-0+{ +bool *field = (bool *)object_class_prop_ptr (obj, (ptrdiff_t )opaque); +bool value; + +if (!visit_type_bool (v, name, &value, errp)) { +return ; + } + + *field = value; +}
Am I missing the reason why we can't use
DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(bool)
? If so, could that be mentioned in the commit message.
Quoted 27 lines
qom/object.c +21
-0+ +ObjectProperty * +object_class_property_add_bool_ptr (ObjectClass *klass,const char *name, +ptrdiff_t offset, +ObjectPropertyFlags flags) +{ +ObjectPropertyAccessor *getter =NULL ; +ObjectPropertyAccessor *setter =NULL ; + +if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { + getter = property_class_get_bool_ptr; + } + +if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { + setter = property_class_set_bool_ptr; + } + +return object_class_property_add (klass, name,"bool" , + getter, setter,NULL , (void *)offset); +} +ObjectProperty * object_property_add_uint8_ptr(Object *obj, const char *name, const uint8_t *v,Signature · 1 line
2.43.0
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 v4 10/16] qom/object.c: add object_class_property_add_bool_ptr()
Quoted 74 lines · Daniel P. Berrangé
Quoted 60 lines · Mark Cave-Ayland
This adds a class property that references a bool within the object instance and is intended to be used as a replacement for
object_class_property_add_bool()where possible.Signed-off-by Mark Cave-Ayland <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- include/qom/object.h | 18 ++++++++++++++++++ qom/object.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+)include/qom/object.h +18
-0@@ -2017,6 +2017,24 @@ typedef enum {OBJ_PROP_FLAG_READWRITE = (OBJ_PROP_FLAG_READ |OBJ_PROP_FLAG_WRITE ), } ObjectPropertyFlags; +/** +* object_class_property_add_bool_ptr: +* @klass: the object class to add a property to +* @name: the name of the property +* @offset: the offset from the object instance where the bool value is +* stored +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add an boolean property in memory. This function will add a +* property of type 'bool'. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty *object_class_property_add_bool_ptr (ObjectClass *klass, +const char *name, +ptrdiff_t offset, +ObjectPropertyFlags flags); +/** * object_property_add_uint8_ptr: * @obj: the object to add a property to qom/object.c +12
-0@@ -2750,6 +2750,49 @@ DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(uint64)#undef DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS +static void property_class_get_bool_ptr (Object *obj,Visitor *v, +const char *name, +void *opaque,Error **errp) +{ +bool value = *(bool *)object_class_prop_ptr (obj, (ptrdiff_t )opaque); + +visit_type_bool (v, name, &value, errp); +} + +static void property_class_set_bool_ptr (Object *obj,Visitor *v, +const char *name, +void *opaque,Error **errp)qom/object.c DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(uint64) · line 2774
Quoted 10 lines
qom/object.c +10
-0+{ +bool *field = (bool *)object_class_prop_ptr (obj, (ptrdiff_t )opaque); +bool value; + +if (!visit_type_bool (v, name, &value, errp)) { +return ; + } + + *field = value; +}Am I missing the reason why we can't use
Quoted 3 lines
DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(bool)? If so, could that be mentioned in the commit message.
It's because bool is actually a macro according to C99 which causes the expansion to fail.
I'll update the commit message accordingly for v5.
Quoted 18 lines
Quoted 18 lines
qom/object.c +18
-0+ +ObjectProperty * +object_class_property_add_bool_ptr (ObjectClass *klass,const char *name, +ptrdiff_t offset, +ObjectPropertyFlags flags) +{ +ObjectPropertyAccessor *getter =NULL ; +ObjectPropertyAccessor *setter =NULL ; + +if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { + getter = property_class_get_bool_ptr; + } + +if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { + setter = property_class_set_bool_ptr; + } + + return object_class_property_add(klass, name, "bool",
Quoted 8 lines
Quoted 8 lines
qom/object.c +3
-0+ getter, setter, NULL, (void *)offset); +} +ObjectProperty * object_property_add_uint8_ptr(Object *obj, const char *name, const uint8_t *v,Signature · 1 line
2.43.0
ATB,
Mark.
Re: [PATCH v4 10/16] qom/object.c: add object_class_property_add_bool_ptr()
Quoted 73 lines · Mark Cave-Ayland
Quoted 71 lines · Daniel P. Berrangé
Quoted 57 lines · Mark Cave-Ayland
This adds a class property that references a bool within the object instance and is intended to be used as a replacement for
object_class_property_add_bool()where possible.Signed-off-by Mark Cave-Ayland <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- include/qom/object.h | 18 ++++++++++++++++++ qom/object.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+)include/qom/object.h +18
-0@@ -2017,6 +2017,24 @@ typedef enum {OBJ_PROP_FLAG_READWRITE = (OBJ_PROP_FLAG_READ |OBJ_PROP_FLAG_WRITE ), } ObjectPropertyFlags; +/** +* object_class_property_add_bool_ptr: +* @klass: the object class to add a property to +* @name: the name of the property +* @offset: the offset from the object instance where the bool value is +* stored +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add an boolean property in memory. This function will add a +* property of type 'bool'. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty *object_class_property_add_bool_ptr (ObjectClass *klass, +const char *name, +ptrdiff_t offset, +ObjectPropertyFlags flags); +/** * object_property_add_uint8_ptr: * @obj: the object to add a property to qom/object.c +12
-0@@ -2750,6 +2750,49 @@ DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(uint64)#undef DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS +static void property_class_get_bool_ptr (Object *obj,Visitor *v, +const char *name, +void *opaque,Error **errp) +{ +bool value = *(bool *)object_class_prop_ptr (obj, (ptrdiff_t )opaque); + +visit_type_bool (v, name, &value, errp); +} + +static void property_class_set_bool_ptr (Object *obj,Visitor *v, +const char *name, +void *opaque,Error **errp)qom/object.c DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(uint64) · line 2772
Quoted 10 lines
qom/object.c +10
-0+{ +bool *field = (bool *)object_class_prop_ptr (obj, (ptrdiff_t )opaque); +bool value; + +if (!visit_type_bool (v, name, &value, errp)) { +return ; + } + + *field = value; +}Am I missing the reason why we can't use
Quoted 8 lines
Quoted 3 lines
DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(bool)? If so, could that be mentioned in the commit message.
It's because bool is actually a macro according to C99 which causes the expansion to fail.
I'll update the commit message accordingly for v5.
Ah yes, I see it gets messy as you end up expanding to visit_type__Bool which of course doesn't exist.
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 v4 11/16 hw/acpi/ich9.c: convert object props in ICH9_LPC_DEVICE to class props
In reply to Mark Cave-AylandACPI_PM_PROP_TCO_ENABLED, ACPI_PM_PROP_ACPI_PCIHP_BRIDGE and x-keep-pci-slot-hpc properties can be converted to use object_class_property_add_bool_ptr(). Remove the now unused ich9_pm_add_properties() function.
--- include/hw/acpi/ich9.h | 3 +- hw/acpi/ich9.c | 111 ++++++++++++++++------------------------- hw/isa/lpc_ich9.c | 3 +- 3 files changed, 44 insertions(+), 73 deletions(-)
include/hw/acpi/ich9.h +1 -2
@@ -83,8 +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_add_class_properties (ObjectClass *oc,ptrdiff_t pm_offset);void ich9_pm_device_pre_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp);
hw/acpi/ich9.c +42 -69
129 lines not on this page · raw message
hw/isa/lpc_ich9.c +1 -2
@@ -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)
@@ -920,7 +919,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, const void *data) &acpi_disable_cmd, OBJ_PROP_FLAG_READ); -ich9_pm_add_class_properties (klass); +ich9_pm_add_class_properties (klass, offsetof(ICH9LPCState , pm)); }static const TypeInfo ich9_lpc_info = {
Signature · 1 line
2.43.0
Re: [PATCH v4 11/16] hw/acpi/ich9.c: convert object props in ICH9_LPC_DEVICE to class props
Quoted 11 lines · Mark Cave-Ayland
ACPI_PM_PROP_TCO_ENABLED,ACPI_PM_PROP_ACPI_PCIHP_BRIDGEand x-keep-pci-slot-hpc properties can be converted to useobject_class_property_add_bool_ptr(). Remove the now unusedich9_pm_add_properties()function.Signed-off-by Mark Cave-Ayland <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- include/hw/acpi/ich9.h | 3 +- hw/acpi/ich9.c | 111 ++++++++++++++++------------------------- hw/isa/lpc_ich9.c | 3 +- 3 files changed, 44 insertions(+), 73 deletions(-)
but...
hw/acpi/ich9.c void ich9_pm_add_class_properties(ObjectClass *oc) · line 370
Quoted 4 lines
hw/acpi/ich9.c +0
-0@@ -436,6 +368,47 @@ void ich9_pm_add_class_properties(ObjectClass *oc)ACPI_PM_PROP_GPE0_BLK_LEN , &gpe0_len, OBJ_PROP_FLAG_READ);
...it'd read nicer with
#define REG_FIELD(n) \
(pm_offset + offsetof(ICH9LPCPMRegs, n))Quoted 5 lines
hw/acpi/ich9.c +5
-0+object_class_property_add_uint32_ptr (oc,ACPI_PM_PROP_PM_IO_BASE , + pm_offset + + offsetof(ICH9LPCPMRegs , + pm_io_base), +OBJ_PROP_FLAG_READ );
....
object_class_property_add_uint32_ptr(oc, ACPI_PM_PROP_PM_IO_BASE,
REG_FIELD(pm_io_base),
OBJ_PROP_FLAG_READ);...
Quoted 26 lines
hw/acpi/ich9.c +26
-0+object_class_property_add_link (oc,"bus" , +TYPE_PCI_BUS , + pm_offset + + offsetof(ICH9LPCPMRegs , + acpi_pci_hotplug.root), + object_property_allow_set_link, +OBJ_PROP_LINK_STRONG ); +object_class_property_add (oc,ACPI_PM_PROP_GPE0_BLK ,"uint32" , + ich9_pm_get_gpe0_blk, +NULL ,NULL ,NULL ); +object_class_property_add_uint8_ptr (oc,ACPI_PM_PROP_S3_DISABLED , + pm_offset + + offsetof(ICH9LPCPMRegs , disable_s3), +OBJ_PROP_FLAG_READWRITE ); +object_class_property_add_uint8_ptr (oc,ACPI_PM_PROP_S4_DISABLED , + pm_offset + + offsetof(ICH9LPCPMRegs , disable_s4), +OBJ_PROP_FLAG_READWRITE ); +object_class_property_add_uint8_ptr (oc,ACPI_PM_PROP_S4_VAL , + pm_offset + + offsetof(ICH9LPCPMRegs , s4_val), +OBJ_PROP_FLAG_READWRITE ); +object_class_property_add_bool_ptr (oc,ACPI_PM_PROP_TCO_ENABLED , + pm_offset + + offsetof(ICH9LPCPMRegs , enable_tco), +OBJ_PROP_FLAG_READWRITE );
hw/acpi/ich9.c void ich9_pm_add_class_properties(ObjectClass *oc) · line 411
Quoted 10 lines
hw/acpi/ich9.c +10
-0+object_class_property_add_bool_ptr (oc,ACPI_PM_PROP_ACPI_PCIHP_BRIDGE , + pm_offset + + offsetof(ICH9LPCPMRegs , + acpi_pci_hotplug.use_acpi_hotplug_bridge), +OBJ_PROP_FLAG_READWRITE ); +object_class_property_add_bool_ptr (oc,"x-keep-pci-slot-hpc" , + pm_offset + + offsetof(ICH9LPCPMRegs , + keep_pci_slot_hpc), +OBJ_PROP_FLAG_READWRITE );
...
#undef REG_FIELD
Quoted 27 lines
}
void ich9_pm_device_pre_plug_cb(HotplugHandler
*hotplug_dev, DeviceState *dev,hw/isa/lpc_ich9.c +1
-2@@ -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)@@ -920,7 +919,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, const void *data) &acpi_disable_cmd, OBJ_PROP_FLAG_READ); -ich9_pm_add_class_properties (klass); +ich9_pm_add_class_properties (klass, offsetof(ICH9LPCState , pm)); }static const TypeInfo ich9_lpc_info = {Signature · 1 line
2.43.0
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 v4 11/16] hw/acpi/ich9.c: convert object props in ICH9_LPC_DEVICE to class props
Quoted 18 lines · Daniel P. Berrangé
Quoted 11 lines · Mark Cave-Ayland
ACPI_PM_PROP_TCO_ENABLED,ACPI_PM_PROP_ACPI_PCIHP_BRIDGEand x-keep-pci-slot-hpc properties can be converted to useobject_class_property_add_bool_ptr(). Remove the now unusedich9_pm_add_properties()function.Signed-off-by Mark Cave-Ayland <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- include/hw/acpi/ich9.h | 3 +- hw/acpi/ich9.c | 111 ++++++++++++++++------------------------- hw/isa/lpc_ich9.c | 3 +- 3 files changed, 44 insertions(+), 73 deletions(-)Reviewed-by Daniel P. Berrangé <[email protected]>but...
Quoted 8 lines
hw/acpi/ich9.c void ich9_pm_add_class_properties(ObjectClass *oc) · line 370
Quoted 4 lines
hw/acpi/ich9.c +0
-0@@ -436,6 +368,47 @@ void ich9_pm_add_class_properties(ObjectClass *oc)ACPI_PM_PROP_GPE0_BLK_LEN , &gpe0_len, OBJ_PROP_FLAG_READ);...it'd read nicer with
#define REG_FIELD(n) \ (pm_offset + offsetof(ICH9LPCPMRegs, n))
I don't feel strongly about it either way, but I'll try implementing it using a PM_REG_FIELD() macro as suggested above (I'm worried that REG_FIELD() is a generic enough name that it may end up clashing with something internally).
Quoted 75 lines
Quoted 5 lines
hw/acpi/ich9.c +5
-0+object_class_property_add_uint32_ptr (oc,ACPI_PM_PROP_PM_IO_BASE , + pm_offset + + offsetof(ICH9LPCPMRegs , + pm_io_base), +OBJ_PROP_FLAG_READ );....
object_class_property_add_uint32_ptr(oc, ACPI_PM_PROP_PM_IO_BASE, REG_FIELD(pm_io_base), OBJ_PROP_FLAG_READ);...
Quoted 26 lines
hw/acpi/ich9.c +26
-0+object_class_property_add_link (oc,"bus" , +TYPE_PCI_BUS , + pm_offset + + offsetof(ICH9LPCPMRegs , + acpi_pci_hotplug.root), + object_property_allow_set_link, +OBJ_PROP_LINK_STRONG ); +object_class_property_add (oc,ACPI_PM_PROP_GPE0_BLK ,"uint32" , + ich9_pm_get_gpe0_blk, +NULL ,NULL ,NULL ); +object_class_property_add_uint8_ptr (oc,ACPI_PM_PROP_S3_DISABLED , + pm_offset + + offsetof(ICH9LPCPMRegs , disable_s3), +OBJ_PROP_FLAG_READWRITE ); +object_class_property_add_uint8_ptr (oc,ACPI_PM_PROP_S4_DISABLED , + pm_offset + + offsetof(ICH9LPCPMRegs , disable_s4), +OBJ_PROP_FLAG_READWRITE ); +object_class_property_add_uint8_ptr (oc,ACPI_PM_PROP_S4_VAL , + pm_offset + + offsetof(ICH9LPCPMRegs , s4_val), +OBJ_PROP_FLAG_READWRITE ); +object_class_property_add_bool_ptr (oc,ACPI_PM_PROP_TCO_ENABLED , + pm_offset + + offsetof(ICH9LPCPMRegs , enable_tco), +OBJ_PROP_FLAG_READWRITE );hw/acpi/ich9.c void ich9_pm_add_class_properties(ObjectClass *oc) · line 411
Quoted 10 lines
hw/acpi/ich9.c +10
-0+object_class_property_add_bool_ptr (oc,ACPI_PM_PROP_ACPI_PCIHP_BRIDGE , + pm_offset + + offsetof(ICH9LPCPMRegs , + acpi_pci_hotplug.use_acpi_hotplug_bridge), +OBJ_PROP_FLAG_READWRITE ); +object_class_property_add_bool_ptr (oc,"x-keep-pci-slot-hpc" , + pm_offset + + offsetof(ICH9LPCPMRegs , + keep_pci_slot_hpc), +OBJ_PROP_FLAG_READWRITE );...
#undef
REG_FIELDQuoted 19 lines
}void ich9_pm_device_pre_plug_cb(HotplugHandler
*hotplug_dev, DeviceState *dev,hw/isa/lpc_ich9.c +0
-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)@@ -920,7 +919,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, const void *data) &acpi_disable_cmd, OBJ_PROP_FLAG_READ);
Quoted 7 lines
Quoted 7 lines
hw/isa/lpc_ich9.c +1
-1-ich9_pm_add_class_properties (klass); +ich9_pm_add_class_properties (klass, offsetof(ICH9LPCState , pm)); }static const TypeInfo ich9_lpc_info = {Signature · 1 line
2.43.0
ATB,
Mark.
PATCH v4 12/16 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 | 18 ++++++++++++++++++ qom/object.c | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+)
include/qom/object.h +18 -0
@@ -2108,6 +2108,24 @@ ObjectProperty *object_property_add_uint16_ptr(Object *obj, const char *name,const uint16_t *v, ObjectPropertyFlags flags); +/** +* object_class_property_add_uint16_ptr: +* @klass: the object class to add a property to +* @name: the name of the property +* @offset: the offset from the object instance where the uint16 value is +* stored +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add an integer property in memory. This function will add a +* property of type 'uint16'. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty *object_class_property_add_uint16_ptr (ObjectClass *klass, +const char *name, +ptrdiff_t offset, +ObjectPropertyFlags flags); +/** * object_class_static_property_add_uint16_ptr: * @klass: the object class to add a static property to
qom/object.c +21 -0
@@ -2742,6 +2742,7 @@ static void *object_class_prop_ptr(Object *obj, ptrdiff_t offset) OBJECT_CLASS_PROPERTY_SCALAR_SETTER(type) DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(uint8) +DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(uint16) DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(uint32) DEFINE_OBJECT_CLASS_PROPERTY_SCALAR_METHODS(uint64)
@@ -2874,6 +2875,26 @@ object_property_add_uint16_ptr(Object *obj, const char *name, getter, setter, NULL, (void *)v); } +ObjectProperty * +object_class_property_add_uint16_ptr (ObjectClass *klass,const char *name, +ptrdiff_t offset, +ObjectPropertyFlags flags) +{ +ObjectPropertyAccessor *getter =NULL ; +ObjectPropertyAccessor *setter =NULL ; + +if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { + getter = property_class_get_uint16_ptr; + } + +if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { + setter = property_class_set_uint16_ptr; + } + +return object_class_property_add (klass, name,"uint16" , + getter, setter,NULL , (void *)offset); +} +ObjectProperty * object_class_static_property_add_uint16_ptr(ObjectClass *klass, const char *name,
Signature · 1 line
2.43.0
Re: [PATCH v4 12/16] qom/object.c: add object_class_property_add_uint16_ptr()
Quoted 9 lines · Mark Cave-Ayland
This adds a class property that references a
uint16_twithin the object instance and is intended to be a replacement forobject_property_add_uint16_ptr().Signed-off-by Mark Cave-Ayland <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- include/qom/object.h | 18 ++++++++++++++++++ qom/object.c | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+)
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 v4 13/16 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 | 10 ++++++++++ hw/acpi/pcihp.c | 5 ----- hw/acpi/piix4.c | 9 +++++++++ 4 files changed, 29 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 +10 -0
@@ -409,6 +409,16 @@ void ich9_pm_add_class_properties(ObjectClass *oc, ptrdiff_t pm_offset) offsetof(ICH9LPCPMRegs , keep_pci_slot_hpc), OBJ_PROP_FLAG_READWRITE); +object_class_property_add_uint16_ptr (oc,ACPI_PCIHP_IO_BASE_PROP , + pm_offset + + offsetof(ICH9LPCPMRegs , + acpi_pci_hotplug.io_base), +OBJ_PROP_FLAG_READ ); +object_class_property_add_uint16_ptr (oc,ACPI_PCIHP_IO_LEN_PROP , + pm_offset + + offsetof(ICH9LPCPMRegs , + 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
Re: [PATCH v4 13/16] hw/acpi/pcihp.c: convert ACPI_PCIHP_IO_BASE_PROP and ACPI_PCIHP_IO_BASE_PROP to class props
Quoted 5 lines · Mark Cave-Ayland
Since the objects referenced by
acpi_pcihp_init()do not inherit from a common class, addACPI_PCIHP_IO_BASE_PROPandACPI_PCIHP_IO_BASE_PROPclass properties to each referenced object and remove the object properties manually added inacpi_pcihp_init().
Quoted 8 lines
Signed-off-by Mark Cave-Ayland <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- hw/acpi/generic_event_device.c | 10 ++++++++++ hw/acpi/ich9.c | 10 ++++++++++ hw/acpi/pcihp.c | 5 ----- hw/acpi/piix4.c | 9 +++++++++ 4 files changed, 29 insertions(+), 5 deletions(-)
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 v4 14/16 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 uint32_t with a default value of UINT32_MAX 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 | 30 ++++++++++++++---------------- hw/arm/virt-acpi-build.c | 7 ++++++- hw/i386/acpi-build.c | 7 ++++++- hw/pci/pci.c | 7 +++++++ 6 files changed, 43 insertions(+), 19 deletions(-)
include/hw/pci/pci_bus.h +2 -0
@@ -56,6 +56,8 @@ struct PCIBus {int *irq_count;Notifier machine_done; + +uint32_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 ; +uint32_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_uint (OBJECT (sec_bus),ACPI_PCIHP_PROP_BSEL , + &local_err); + +if (local_err ==NULL && bsel !=UINT32_MAX ) {build_append_pcihp_slots (scope, sec_bus); } + +error_free (local_err); } }
hw/acpi/pcihp.c +14 -16
@@ -58,7 +58,7 @@ 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 , +uint32_t bsel =object_property_get_uint (OBJECT (bus),ACPI_PCIHP_PROP_BSEL , &local_err);if (local_err || bsel >=ACPI_PCIHP_MAX_HOTPLUG_BUS ) {
@@ -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_uint (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++; +uint32_t bsel_val =qnum_get_uint (qobject_to (QNum, bsel)); + +if (bsel_val !=UINT32_MAX ) { +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)); +uint32_t bsel_val =qnum_get_uint (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
@@ -1207,6 +1207,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 ; +uint32_t bsel;acpi_table_begin (&table, table_data); dsdt =init_aml_allocator ();
@@ -1269,9 +1271,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_uint (OBJECT (vms->bus),ACPI_PCIHP_PROP_BSEL , + &local_err); +if (local_err ==NULL && bsel !=UINT32_MAX ) {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
@@ -1198,15 +1198,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 ; +uint32_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_uint (OBJECT (pbus),ACPI_PCIHP_PROP_BSEL , + &local_err); +if (local_err ==NULL && bsel !=UINT32_MAX ) {build_append_pcihp_slots (ascope, pbus); } +error_free (local_err);aml_append (sb_scope, ascope); } }
hw/pci/pci.c +7 -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 =UINT32_MAX ; +vmstate_register_any (NULL , &vmstate_pcibus, bus); }
@@ -302,6 +305,10 @@ 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_uint32_ptr (klass,ACPI_PCIHP_PROP_BSEL , + offsetof(PCIBus , acpi_pcihp_bsel_val), +OBJ_PROP_FLAG_READWRITE ); }static const TypeInfo pci_bus_info = {
Signature · 1 line
2.43.0
Re: [PATCH v4 14/16] hw/acpi/pcihp.c: convert ACPI_PCIHP_PROP_BSEL from object prop to class prop
Quoted 48 lines · Mark Cave-Ayland
Move the
ACPI_PCIHP_PROP_BSELproperty to the PCIBus object and update all callers accordingly.Since the existing logic checks for the existence of the
ACPI_PCIHP_PROP_BSELproperty to enable the relevant ACPI changes, set the type of the underlying variable touint32_twith a default value ofUINT32_MAXindicating that the property has not been set.Signed-off-by Mark Cave-Ayland <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- include/hw/pci/pci_bus.h | 2 ++ hw/acpi/pci-bridge.c | 9 ++++++++- hw/acpi/pcihp.c | 30 ++++++++++++++---------------- hw/arm/virt-acpi-build.c | 7 ++++++- hw/i386/acpi-build.c | 7 ++++++- hw/pci/pci.c | 7 +++++++ 6 files changed, 43 insertions(+), 19 deletions(-)include/hw/pci/pci_bus.h +2
-0@@ -56,6 +56,8 @@ struct PCIBus {int *irq_count;Notifier machine_done; + +uint32_t acpi_pcihp_bsel_val; };static inline bool pci_bus_is_cxl (PCIBus *bus)hw/acpi/pci-bridge.c +2
-0@@ -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 ; +uint32_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,
hw/acpi/pci-bridge.c void build_pci_bridge_aml(AcpiDevAmlIf *adev, Aml *scope) · line 42
Quoted 10 lines
hw/acpi/pci-bridge.c +6
-1*/ -if (object_property_find (OBJECT (sec_bus),ACPI_PCIHP_PROP_BSEL )) { + bsel =object_property_get_uint (OBJECT (sec_bus),ACPI_PCIHP_PROP_BSEL , + &local_err); + +if (local_err ==NULL && bsel !=UINT32_MAX ) {build_append_pcihp_slots (scope, sec_bus); } + +error_free (local_err);
IIUC, in this new approach the property should always exist and so I'd expect object_property_get_uint to always succeed.
IOW, is something stopping us using &error_abort and merely checking
if (bsel != UINT32_MAX)
?
Quoted 159 lines
hw/acpi/pci-bridge.c +0
-0} }hw/acpi/pcihp.c +14
-16@@ -58,7 +58,7 @@ 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 , +uint32_t bsel =object_property_get_uint (OBJECT (bus),ACPI_PCIHP_PROP_BSEL , &local_err);if (local_err || bsel >=ACPI_PCIHP_MAX_HOTPLUG_BUS ) {@@ -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_uint (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++; +uint32_t bsel_val =qnum_get_uint (qobject_to (QNum, bsel)); + +if (bsel_val !=UINT32_MAX ) { +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)); +uint32_t bsel_val =qnum_get_uint (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@@ -1207,6 +1207,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 ; +uint32_t bsel;acpi_table_begin (&table, table_data); dsdt =init_aml_allocator ();@@ -1269,9 +1271,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_uint (OBJECT (vms->bus),ACPI_PCIHP_PROP_BSEL , + &local_err); +if (local_err ==NULL && bsel !=UINT32_MAX ) {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@@ -1198,15 +1198,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 ; +uint32_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_uint (OBJECT (pbus),ACPI_PCIHP_PROP_BSEL , + &local_err); +if (local_err ==NULL && bsel !=UINT32_MAX ) {build_append_pcihp_slots (ascope, pbus); } +error_free (local_err);aml_append (sb_scope, ascope); } }hw/pci/pci.c +7
-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 =UINT32_MAX ; +vmstate_register_any (NULL , &vmstate_pcibus, bus); }@@ -302,6 +305,10 @@ 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_uint32_ptr (klass,ACPI_PCIHP_PROP_BSEL , + offsetof(PCIBus , acpi_pcihp_bsel_val), +OBJ_PROP_FLAG_READWRITE ); }static const TypeInfo pci_bus_info = {Signature · 1 line
2.43.0
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 v4 14/16] hw/acpi/pcihp.c: convert ACPI_PCIHP_PROP_BSEL from object prop to class prop
Quoted 63 lines · Daniel P. Berrangé
Quoted 48 lines · Mark Cave-Ayland
Move the
ACPI_PCIHP_PROP_BSELproperty to the PCIBus object and update all callers accordingly.Since the existing logic checks for the existence of the
ACPI_PCIHP_PROP_BSELproperty to enable the relevant ACPI changes, set the type of the underlying variable touint32_twith a default value ofUINT32_MAXindicating that the property has not been set.Signed-off-by Mark Cave-Ayland <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- include/hw/pci/pci_bus.h | 2 ++ hw/acpi/pci-bridge.c | 9 ++++++++- hw/acpi/pcihp.c | 30 ++++++++++++++---------------- hw/arm/virt-acpi-build.c | 7 ++++++- hw/i386/acpi-build.c | 7 ++++++- hw/pci/pci.c | 7 +++++++ 6 files changed, 43 insertions(+), 19 deletions(-)include/hw/pci/pci_bus.h +2
-0@@ -56,6 +56,8 @@ struct PCIBus {int *irq_count;Notifier machine_done; + +uint32_t acpi_pcihp_bsel_val; };static inline bool pci_bus_is_cxl (PCIBus *bus)hw/acpi/pci-bridge.c +2
-0@@ -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 ; +uint32_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, hw/acpi/pci-bridge.c void build_pci_bridge_aml(AcpiDevAmlIf *adev, Aml *scope) · line 42
Quoted 10 lines
hw/acpi/pci-bridge.c +6
-1*/ -if (object_property_find (OBJECT (sec_bus),ACPI_PCIHP_PROP_BSEL )) { + bsel =object_property_get_uint (OBJECT (sec_bus),ACPI_PCIHP_PROP_BSEL , + &local_err); + +if (local_err ==NULL && bsel !=UINT32_MAX ) {build_append_pcihp_slots (scope, sec_bus); } + +error_free (local_err);IIUC, in this new approach the property should always exist and so I'd expect
object_property_get_uintto always succeed.
Quoted 5 lines
IOW, is something stopping us using
&error_abortand merely checkingif (bsel != UINT32_MAX)?
I think that would work, although in the back of my mind I have a memory that we should try avoiding error_abort where at all possible.
Markus, any thoughts/comments on error_abort usage?
Quoted 155 lines
Quoted 155 lines
hw/acpi/pci-bridge.c +0
-0} }hw/acpi/pcihp.c +14
-16@@ -58,7 +58,7 @@ 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 , +uint32_t bsel =object_property_get_uint (OBJECT (bus),ACPI_PCIHP_PROP_BSEL , &local_err);if (local_err || bsel >=ACPI_PCIHP_MAX_HOTPLUG_BUS ) {@@ -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_uint (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++; +uint32_t bsel_val =qnum_get_uint (qobject_to (QNum, bsel)); + +if (bsel_val !=UINT32_MAX ) { +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)); +uint32_t bsel_val =qnum_get_uint (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@@ -1207,6 +1207,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 ; +uint32_t bsel;acpi_table_begin (&table, table_data); dsdt =init_aml_allocator ();@@ -1269,9 +1271,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_uint (OBJECT (vms->bus),ACPI_PCIHP_PROP_BSEL , + &local_err); +if (local_err ==NULL && bsel !=UINT32_MAX ) {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@@ -1198,15 +1198,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 ; +uint32_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_uint (OBJECT (pbus),ACPI_PCIHP_PROP_BSEL , + &local_err); +if (local_err ==NULL && bsel !=UINT32_MAX ) {build_append_pcihp_slots (ascope, pbus); } +error_free (local_err);aml_append (sb_scope, ascope); } }hw/pci/pci.c +7
-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 =UINT32_MAX ; +vmstate_register_any (NULL , &vmstate_pcibus, bus); }@@ -302,6 +305,10 @@ 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_uint32_ptr (klass,ACPI_PCIHP_PROP_BSEL , + offsetof(PCIBus , acpi_pcihp_bsel_val), +OBJ_PROP_FLAG_READWRITE ); }
Quoted 3 lines
Quoted 3 lines
hw/pci/pci.c +0
-0static const TypeInfo pci_bus_info = {Signature · 1 line
2.43.0
ATB,
Mark.
Re: [PATCH v4 14/16] hw/acpi/pcihp.c: convert ACPI_PCIHP_PROP_BSEL from object prop to class prop
Quoted 66 lines · Mark Cave-Ayland
Quoted 55 lines · Daniel P. Berrangé
Quoted 54 lines · Mark Cave-Ayland
Move the
ACPI_PCIHP_PROP_BSELproperty to the PCIBus object and update all callers accordingly.Since the existing logic checks for the existence of the
ACPI_PCIHP_PROP_BSELproperty to enable the relevant ACPI changes, set the type of the underlying variable touint32_twith a default value ofUINT32_MAXindicating that the property has not been set.Signed-off-by Mark Cave-Ayland <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- include/hw/pci/pci_bus.h | 2 ++ hw/acpi/pci-bridge.c | 9 ++++++++- hw/acpi/pcihp.c | 30 ++++++++++++++---------------- hw/arm/virt-acpi-build.c | 7 ++++++- hw/i386/acpi-build.c | 7 ++++++- hw/pci/pci.c | 7 +++++++ 6 files changed, 43 insertions(+), 19 deletions(-)include/hw/pci/pci_bus.h +2
-0@@ -56,6 +56,8 @@ struct PCIBus {int *irq_count;Notifier machine_done; + +uint32_t acpi_pcihp_bsel_val; };static inline bool pci_bus_is_cxl (PCIBus *bus)hw/acpi/pci-bridge.c +6
-1@@ -23,6 +23,8 @@ void build_pci_bridge_aml(AcpiDevAmlIf *adev, Aml *scope)@@ -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 ; +uint32_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_uint (OBJECT (sec_bus),ACPI_PCIHP_PROP_BSEL , + &local_err); + +if (local_err ==NULL && bsel !=UINT32_MAX ) {build_append_pcihp_slots (scope, sec_bus);Quoted 8 lines
hw/acpi/pci-bridge.c void build_pci_bridge_aml(AcpiDevAmlIf *adev, Aml *scope) · line 42
Quoted 3 lines
hw/acpi/pci-bridge.c +2
-0} + +error_free (local_err);IIUC, in this new approach the property should always exist and so I'd expect
object_property_get_uintto always succeed.
IOW, is something stopping us using&error_abortand merely checking
if (bsel !=UINT32_MAX)
?
Quoted 3 lines
I think that would work, although in the back of my mind I have a memory that we should try avoiding
error_abortwhere at all possible.Markus, any thoughts/comments on
error_abortusage?
&error_abort is an assertion, just like assert().
Assertions are strictly for programming errors. When the program detects such an error, it is defective and needs fixing.
Commonly, the program is in an invalid state then, and continuing execution is unsafe. Aborting it is the only sane option.
Assertions conveniently combine the error check and the abort, and also scream "this is a a programming error" both to readers of the code and unfortunate users tripping them. Good!
I particularly dislike the pattern
if (programming error detected) {
error recovery that should never be reached
}where the code doesn't actually *tell* me it's a programming error. This matters! The error recovery needs to be treated with extreme suspicion then, because it's not testable and almost certainly unsafe.
The pattern can also make me go "huh, I wonder how this error can happen, let me figure that out", wasting my time.
Another gripe of mine: we often pass NULL where we should pass &error_abort.
Questions?
[...]
Re: [PATCH v4 14/16] hw/acpi/pcihp.c: convert ACPI_PCIHP_PROP_BSEL from object prop to class prop
Quoted 94 lines · Markus Armbruster
Quoted 66 lines · Mark Cave-Ayland
Quoted 61 lines · Daniel P. Berrangé
Quoted 47 lines · Mark Cave-Ayland
Move the
ACPI_PCIHP_PROP_BSELproperty to the PCIBus object and update all callers accordingly.Since the existing logic checks for the existence of the
ACPI_PCIHP_PROP_BSELproperty to enable the relevant ACPI changes, set the type of the underlying variable touint32_twith a default value ofUINT32_MAXindicating that the property has not been set.Signed-off-by Mark Cave-Ayland <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- include/hw/pci/pci_bus.h | 2 ++ hw/acpi/pci-bridge.c | 9 ++++++++- hw/acpi/pcihp.c | 30 ++++++++++++++---------------- hw/arm/virt-acpi-build.c | 7 ++++++- hw/i386/acpi-build.c | 7 ++++++- hw/pci/pci.c | 7 +++++++ 6 files changed, 43 insertions(+), 19 deletions(-)include/hw/pci/pci_bus.h +2
-0@@ -56,6 +56,8 @@ struct PCIBus {int *irq_count;Notifier machine_done; + +uint32_t acpi_pcihp_bsel_val; };static inline bool pci_bus_is_cxl (PCIBus *bus)hw/acpi/pci-bridge.c +2
-0@@ -23,6 +23,8 @@ void build_pci_bridge_aml(AcpiDevAmlIf *adev, Aml *scope)@@ -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 ; +uint32_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, hw/acpi/pci-bridge.c void build_pci_bridge_aml(AcpiDevAmlIf *adev, Aml *scope) · line 42
Quoted 10 lines
hw/acpi/pci-bridge.c +6
-1*/ -if (object_property_find (OBJECT (sec_bus),ACPI_PCIHP_PROP_BSEL )) { + bsel =object_property_get_uint (OBJECT (sec_bus),ACPI_PCIHP_PROP_BSEL , + &local_err); + +if (local_err ==NULL && bsel !=UINT32_MAX ) {build_append_pcihp_slots (scope, sec_bus); } + +error_free (local_err);IIUC, in this new approach the property should always exist and so I'd expect
object_property_get_uintto always succeed.
IOW, is something stopping us using&error_abortand merely checkingQuoted 2 lines
if (bsel != UINT32_MAX)?
Quoted 3 lines
I think that would work, although in the back of my mind I have a memory that we should try avoiding
error_abortwhere at all possible.Markus, any thoughts/comments on
error_abortusage?
&error_abortis an assertion, just likeassert().Assertions are strictly for programming errors. When the program detects such an error, it is defective and needs fixing.
Commonly, the program is in an invalid state then, and continuing execution is unsafe. Aborting it is the only sane option.
Assertions conveniently combine the error check and the abort, and also scream "this is a a programming error" both to readers of the code and unfortunate users tripping them. Good!
I particularly dislike the pattern
if (programming error detected) { error recovery that should never be reached }where the code doesn't actually *tell* me it's a programming error. This matters! The error recovery needs to be treated with extreme suspicion then, because it's not testable and almost certainly unsafe.
Quoted 7 lines
The pattern can also make me go "huh, I wonder how this error can happen, let me figure that out", wasting my time.
Another gripe of mine: we often pass NULL where we should pass
&error_abort.Questions?
Always :) Seriously though, for this particular case I think error_abort is reasonable since if you've managed to get a non-PCIBus from pci_bridge_get_sec_bus() then things are generally looking pretty bad.
Thanks for the pointers as it's something else to add to my set of notes as to how we should best model these things in QEMU. I wonder if there is a suitable place in the documentation we could add this?
ATB,
Mark.
Re: [PATCH v4 14/16] hw/acpi/pcihp.c: convert ACPI_PCIHP_PROP_BSEL from object prop to class prop
Mark Cave-Ayland <[email protected]> writes:
[...]
Quoted 1 line
Thanks for the pointers as it's something else to add to my set of notes as to how we should best model these things in QEMU. I wonder if there is a suitable place in the documentation we could add this?
docs/devel/style.rst has a section "Error handling and reporting".
There's quite a bit of documentation in qapi/error.h.
Feel free to propose improvements.
PATCH v4 15/16 hw/acpi/piix4.c: convert static variables to static class properties
In reply to Mark Cave-AylandThe majority of the properties in piix4_pm_add_properties() are assigned to static variables and so can be converted to static class properties. Introduce piix4_pm_add_class_properties() to hold the static properties and soon all other class props after they have been converted from object props.
--- hw/acpi/piix4.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-)
hw/acpi/piix4.c +28 -12
@@ -406,6 +406,12 @@ static void piix4_pm_machine_ready(Notifier *n, void *opaque) }static void piix4_pm_add_properties (PIIX4PMState *s) +{ +object_property_add_uint32_ptr (OBJECT (s),ACPI_PM_PROP_PM_IO_BASE , + &s->io_base,OBJ_PROP_FLAG_READ ); +} + +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 +419,26 @@ 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 ); }static void piix4_pm_realize (PCIDevice *dev,Error **errp)
@@ -616,6 +630,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
Re: [PATCH v4 15/16] hw/acpi/piix4.c: convert static variables to static class properties
Quoted 10 lines · Mark Cave-Ayland
The majority of the properties in
piix4_pm_add_properties()are assigned to static variables and so can be converted to static class properties. Introducepiix4_pm_add_class_properties()to hold the static properties and soon all other class props after they have been converted from object props.Signed-off-by Mark Cave-Ayland <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- hw/acpi/piix4.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-)
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 v4 16/16 hw/acpi/piix4.c: convert ACPI_PM_PROP_PM_IO_BASE to a class prop
In reply to Mark Cave-AylandACPI_PM_PROP_PM_IO_BASE can be converted to use object_class_property_add_uint32_ptr(). Remove the now unused piix4_pm_add_properties() function.
--- hw/acpi/piix4.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
hw/acpi/piix4.c +4 -8
@@ -405,12 +405,6 @@ 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) -{ -object_property_add_uint32_ptr (OBJECT (s),ACPI_PM_PROP_PM_IO_BASE , - &s->io_base,OBJ_PROP_FLAG_READ ); -} -static void piix4_pm_add_class_properties (ObjectClass *oc) {static const uint8_t acpi_enable_cmd =ACPI_ENABLE ;
@@ -439,6 +433,10 @@ static void piix4_pm_add_class_properties(ObjectClass *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)
@@ -494,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)
Signature · 1 line
2.43.0
Re: [PATCH v4 16/16] hw/acpi/piix4.c: convert ACPI_PM_PROP_PM_IO_BASE to a class prop
Quoted 8 lines · Mark Cave-Ayland
ACPI_PM_PROP_PM_IO_BASEcan be converted to useobject_class_property_add_uint32_ptr(). Remove the now unusedpiix4_pm_add_properties()function.Signed-off-by Mark Cave-Ayland <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>--- hw/acpi/piix4.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
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 :|