hw/acpi: convert object props to class props
cover hw/acpi: convert object props to class props
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.
Mark Cave-Ayland (7):
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 + hw/acpi/generic_event_device.c | 30 ++++++ hw/acpi/ich9.c | 192 ++++++++++++++++++++++++++++----- hw/acpi/pci-bridge.c | 9 +- hw/acpi/pcihp.c | 37 +++---- hw/acpi/piix4.c | 72 ++++++++++--- hw/arm/virt-acpi-build.c | 7 +- hw/i386/acpi-build.c | 7 +- hw/isa/lpc_ich9.c | 68 +++++++++--- hw/pci/pci.c | 32 ++++++ 11 files changed, 376 insertions(+), 84 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/7 hw/acpi/ich9.c: move initial property values into ich9_reset_properties()
--- 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 1/7] 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(-)
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 2/7 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 | 64 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 13 deletions(-)
hw/isa/lpc_ich9.c +51 -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,20 @@ 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_property_add_uint8_ptr (klass,ACPI_PM_PROP_ACPI_ENABLE_CMD , + &acpi_enable_cmd,OBJ_PROP_FLAG_READ ); +object_class_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
Re: [PATCH 2/7] hw/isa/lpc_ich9.c: convert ich9_lpc_initfn() object props to class props
Quoted 4 lines · Mark Cave-Ayland
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/isa/lpc_ich9.c | 64 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 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 3/7 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 3/7] 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(-)
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 4/7 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 | 153 +++++++++++++++++++++++++++++++++-------- hw/isa/lpc_ich9.c | 3 +- 3 files changed, 129 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 +126 -27
174 lines not on this page · raw message
hw/isa/lpc_ich9.c +2 -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)
@@ -950,6 +949,8 @@ 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
Re: [PATCH 4/7] hw/acpi/ich9.c: convert object props in ICH9_LPC_DEVICE to class props
Quoted 6 lines · Mark Cave-Ayland
Signed-off-by Mark Cave-Ayland <[email protected]>--- include/hw/acpi/ich9.h | 2 +- hw/acpi/ich9.c | 153 +++++++++++++++++++++++++++++++++-------- hw/isa/lpc_ich9.c | 3 +- 3 files changed, 129 insertions(+), 29 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 5/7 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 | 30 ++++++++++++++++++++++++++++++ hw/acpi/ich9.c | 30 ++++++++++++++++++++++++++++++ hw/acpi/pcihp.c | 5 ----- hw/acpi/piix4.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 5 deletions(-)
hw/acpi/generic_event_device.c +30 -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"
@@ -357,6 +358,26 @@ static void acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev)qemu_irq_pulse (s->irq); } +static void acpi_ged_get_pcihp_io_base (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +AcpiGedState *s =ACPI_GED (obj); +uint16_t io_base = s->pcihp_state.io_base; + +visit_type_uint16 (v, name, &io_base, errp); +} + +static void acpi_ged_get_pcihp_io_len (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +AcpiGedState *s =ACPI_GED (obj); +uint16_t io_len = s->pcihp_state.io_len; + +visit_type_uint16 (v, name, &io_len, errp); +} +static const Property acpi_ged_properties[] = {DEFINE_PROP_UINT32 ("ged-event" , AcpiGedState, ged_event_bitmap,0 ), DEFINE_PROP_BOOL(ACPI_PM_PROP_ACPI_PCIHP_BRIDGE, AcpiGedState,
@@ -608,6 +629,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 (class,ACPI_PCIHP_IO_BASE_PROP ,"uint16" , + acpi_ged_get_pcihp_io_base, +NULL , +NULL ,NULL ); +object_class_property_add (class,ACPI_PCIHP_IO_LEN_PROP ,"uint16" , + acpi_ged_get_pcihp_io_len, +NULL , +NULL ,NULL ); }static const TypeInfo acpi_ged_info = {
hw/acpi/ich9.c +30 -0
@@ -477,6 +477,28 @@ static void ich9_pm_set_keep_pci_slot_hpc(Object *obj, bool value, Error **errp) s->pm.keep_pci_slot_hpc = value; } +static void ich9_pm_get_pcihp_io_base (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +ICH9LPCState *s =ICH9_LPC_DEVICE (obj); +ICH9LPCPMRegs *pm = &s->pm; +uint16_t io_base = pm->acpi_pci_hotplug.io_base; + +visit_type_uint16 (v, name, &io_base, errp); +} + +static void ich9_pm_get_pcihp_io_len (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +ICH9LPCState *s =ICH9_LPC_DEVICE (obj); +ICH9LPCPMRegs *pm = &s->pm; +uint16_t io_len = pm->acpi_pci_hotplug.io_len; + +visit_type_uint16 (v, name, &io_len, errp); +} +void ich9_pm_reset_properties (ICH9LPCPMRegs *pm) { pm->acpi_memory_hotplug.is_enabled = true;
@@ -529,6 +551,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 (oc,ACPI_PCIHP_IO_BASE_PROP ,"uint16" , + ich9_pm_get_pcihp_io_base, +NULL , +NULL ,NULL ); +object_class_property_add (oc,ACPI_PCIHP_IO_LEN_PROP ,"uint16" , + ich9_pm_get_pcihp_io_len, +NULL , +NULL ,NULL ); } 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 +30 -0
@@ -32,6 +32,7 @@#include "system/system.h" #include "system/xen.h" #include "qapi/error.h" +#include "qapi/visitor.h" #include "qemu/range.h" #include "hw/acpi/cpu.h" #include "hw/core/hotplug.h"
@@ -405,6 +406,26 @@ static void piix4_pm_machine_ready(Notifier *n, void *opaque) (memory_region_present (io_as,0x2f8 ) ?0x90 :0 ); } +static void piix4_pm_get_pcihp_io_base (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +PIIX4PMState *s =PIIX4_PM (obj); +uint16_t io_base = s->acpi_pci_hotplug.io_base; + +visit_type_uint16 (v, name, &io_base, errp); +} + +static void piix4_pm_get_pcihp_io_len (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +PIIX4PMState *s =PIIX4_PM (obj); +uint16_t io_len = s->acpi_pci_hotplug.io_len; + +visit_type_uint16 (v, name, &io_len, errp); +} +static void piix4_pm_add_properties (PIIX4PMState *s) {static const uint8_t acpi_enable_cmd =ACPI_ENABLE ;
@@ -607,6 +628,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 (klass,ACPI_PCIHP_IO_BASE_PROP ,"uint16" , + piix4_pm_get_pcihp_io_base, +NULL , +NULL ,NULL ); +object_class_property_add (klass,ACPI_PCIHP_IO_LEN_PROP ,"uint16" , + piix4_pm_get_pcihp_io_len, +NULL , +NULL ,NULL ); }static const TypeInfo piix4_pm_info = {
Signature · 1 line
2.43.0
Re: [PATCH 5/7] 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 7 lines
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/acpi/generic_event_device.c | 30 ++++++++++++++++++++++++++++++ hw/acpi/ich9.c | 30 ++++++++++++++++++++++++++++++ hw/acpi/pcihp.c | 5 ----- hw/acpi/piix4.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 90 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 6/7 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
@@ -1138,6 +1138,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 ();
@@ -1196,9 +1198,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
Re: [PATCH 6/7] hw/acpi/pcihp.c: convert ACPI_PCIHP_PROP_BSEL from object prop to class prop
Quoted 9 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 toint32_twith a default value of -1 indicating that the property has not been set.Signed-off-by Mark Cave-Ayland <[email protected]>
Quoted 8 lines
--- 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(-)
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 7/7 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
@@ -406,6 +406,16 @@ static void piix4_pm_machine_ready(Notifier *n, void *opaque) (memory_region_present (io_as,0x2f8 ) ?0x90 :0 ); } +static void piix4_pm_get_io_base (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +PIIX4PMState *s =PIIX4_PM (obj); +uint32_t io_base = s->io_base; + +visit_type_uint32 (v, name, &io_base, errp); +} +static void piix4_pm_get_pcihp_io_base (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp)
@@ -426,7 +436,7 @@ static void piix4_pm_get_pcihp_io_len(Object *obj, Visitor *v,visit_type_uint16 (v, name, &io_len, errp); } -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 ;
@@ -434,18 +444,20 @@ 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_property_add_uint8_ptr (oc,ACPI_PM_PROP_ACPI_ENABLE_CMD , + &acpi_enable_cmd,OBJ_PROP_FLAG_READ ); +object_class_property_add_uint8_ptr (oc,ACPI_PM_PROP_ACPI_DISABLE_CMD , + &acpi_disable_cmd,OBJ_PROP_FLAG_READ ); +object_class_property_add_uint32_ptr (oc,ACPI_PM_PROP_GPE0_BLK , + &gpe0_blk,OBJ_PROP_FLAG_READ ); +object_class_property_add_uint32_ptr (oc,ACPI_PM_PROP_GPE0_BLK_LEN , + &gpe0_blk_len,OBJ_PROP_FLAG_READ ); +object_class_property_add_uint16_ptr (oc,ACPI_PM_PROP_SCI_INT , + &sci_int,OBJ_PROP_FLAG_READ ); +object_class_property_add (oc,ACPI_PM_PROP_PM_IO_BASE ,"uint32" , + piix4_pm_get_io_base, +NULL , +NULL ,NULL ); }static void piix4_pm_realize (PCIDevice *dev,Error **errp)
@@ -501,8 +513,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)
@@ -637,6 +647,8 @@ static void piix4_pm_class_init(ObjectClass *klass, const void *data) piix4_pm_get_pcihp_io_len,NULL , NULL, NULL); + +piix4_pm_add_class_properties (klass); }static const TypeInfo piix4_pm_info = {
Signature · 1 line
2.43.0
Re: [PATCH 7/7] hw/acpi/piix4.c: convert object props in PIIX4_PM to class props
Quoted 4 lines · Mark Cave-Ayland
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/acpi/piix4.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 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 :|