ACPI controller cleanup
cover ACPI controller cleanup
This series brings the PIIX4 PM device closer to reality and resolves some redundant code along the way.
Testing done:
- make check
- Starting a live CD under pc and q35 machines and check that the GPE accesses are traced
Bernhard Beschow (7):
hw/acpi/{ich9,piix4}: Reuse existing attributes for QOM properties hw/acpi/ich9: Remove unneeded assignments hw/acpi/{ich9,piix4}: Resolve redundant io_base address attributes hw/acpi/ich9: Use ICH9_PMIO_GPE0_STS just once hw/acpi/piix4: Fix offset of GPE0 registers
hw/acpi: Trace GPE access in all device models, not just PIIX4 hw/acpi/core: Trace enable and status registers of GPE separately
include/hw/acpi/ich9.h | 1 - include/hw/acpi/piix4.h | 3 +-- hw/acpi/core.c | 9 +++++++++ hw/acpi/ich9.c | 26 ++++++++++++-------------- hw/acpi/piix4.c | 31 ++++++++++++++++--------------- hw/acpi/trace-events | 10 ++++++---- 6 files changed, 44 insertions(+), 36 deletions(-)
Signature · 1 line
2.39.1
PATCH 1/7 hw/acpi/{ich9, piix4}: Reuse existing attributes for QOM properties
The QOM properties are accessed after the device models have been realized. This means that the constants are redundant. Remove them.
--- hw/acpi/ich9.c | 5 ++--- hw/acpi/piix4.c | 10 ++++------ 2 files changed, 6 insertions(+), 9 deletions(-)
hw/acpi/ich9.c +2 -3
@@ -433,7 +433,6 @@ static void ich9_pm_set_keep_pci_slot_hpc(Object *obj, bool value, Error **errp)void ich9_pm_add_properties (Object *obj,ICH9LPCPMRegs *pm) { -static const uint32_t gpe0_len =ICH9_PMIO_GPE0_LEN ; pm->acpi_memory_hotplug.is_enabled = true; pm->cpu_hotplug_legacy = true; pm->disable_s3 =0 ;
@@ -448,8 +447,8 @@ 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 , pm); -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_GPE0_BLK_LEN , + &pm->acpi_regs.gpe.len,OBJ_PROP_FLAG_READ );object_property_add_bool (obj,"memory-hotplug-support" , ich9_pm_get_memory_hotplug_support, ich9_pm_set_memory_hotplug_support);
hw/acpi/piix4.c +4 -6
@@ -421,18 +421,16 @@ static void piix4_pm_add_properties(PIIX4PMState *s) {static const uint8_t acpi_enable_cmd =ACPI_ENABLE ;static const uint8_t acpi_disable_cmd =ACPI_DISABLE ; -static const uint32_t gpe0_blk =GPE_BASE ; -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_uint64_ptr (OBJECT (s),ACPI_PM_PROP_GPE0_BLK , + &s->io_gpe.addr,OBJ_PROP_FLAG_READ ); +object_property_add_uint8_ptr (OBJECT (s),ACPI_PM_PROP_GPE0_BLK_LEN , + &s->ar.gpe.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,
Signature · 1 line
2.39.1
Re: [PATCH 1/7] hw/acpi/{ich9,piix4}: Reuse existing attributes for QOM properties
Quoted 2 lines · On Sun, 22 Jan 2023 18:07:18 +0100 Bernhard Beschow <[email protected]> wrote:
The QOM properties are accessed after the device models have been realized. This means that the constants are redundant. Remove them.
not sure it above means.
Perhaps:
subj: use existing fields type::foo instead of static memory.
all object_property_add_*_ptr() needs is a pointer to memory storing so RO defaults where provided as pointers to static constants. Instead of keeping static constants around, drop them and initialize use existing type::foo field, which were set set later on to this constant later at ...
(also see below: maybe squash ICH9_PMIO_GPE0_LEN cleanup here as well)
or something along this lines.
Quoted 12 lines
Signed-off-by Bernhard Beschow <[email protected]>--- hw/acpi/ich9.c | 5 ++--- hw/acpi/piix4.c | 10 ++++------ 2 files changed, 6 insertions(+), 9 deletions(-)hw/acpi/ich9.c +0
-0
hw/acpi/ich9.c static void ich9_pm_set_keep_pci_slot_hpc(Object *obj, bool value, Error **errp) · line 436
Quoted 4 lines
hw/acpi/ich9.c +0
-1@@ -433,7 +433,6 @@ static void ich9_pm_set_keep_pci_slot_hpc(Object *obj, bool value, Error **errp)void ich9_pm_add_properties (Object *obj,ICH9LPCPMRegs *pm) { -static const uint32_t gpe0_len =ICH9_PMIO_GPE0_LEN ;
you are loosing default value here, (true it's set somewhere later) suggest:
pm->acpi_regs.gpe.len = ICH9_PMIO_GPE0_LEN;
and in patch on top maybe cleanup other places that use ICH9_PMIO_GPE0_LEN with pm->acpi_regs.gpe.len
Quoted 19 lines
hw/acpi/ich9.c +2
-2pm->acpi_memory_hotplug.is_enabled = true; pm->cpu_hotplug_legacy = true; pm->disable_s3 =0 ;@@ -448,8 +447,8 @@ 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 , pm); -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_GPE0_BLK_LEN , + &pm->acpi_regs.gpe.len,OBJ_PROP_FLAG_READ );object_property_add_bool (obj,"memory-hotplug-support" , ich9_pm_get_memory_hotplug_support, ich9_pm_set_memory_hotplug_support);hw/acpi/piix4.c +0
-0
hw/acpi/piix4.c static void piix4_pm_add_properties(PIIX4PMState *s) · line 425
Quoted 5 lines
hw/acpi/piix4.c +0
-2@@ -421,18 +421,16 @@ static void piix4_pm_add_properties(PIIX4PMState *s) {static const uint8_t acpi_enable_cmd =ACPI_ENABLE ;static const uint8_t acpi_disable_cmd =ACPI_DISABLE ; -static const uint32_t gpe0_blk =GPE_BASE ; -static const uint32_t gpe0_blk_len =GPE_LEN ;
ditto
also maybe split on 2 patches 1 for ich9 another for piix4
Quoted 17 lines
hw/acpi/piix4.c +4
-4static 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_uint64_ptr (OBJECT (s),ACPI_PM_PROP_GPE0_BLK , + &s->io_gpe.addr,OBJ_PROP_FLAG_READ ); +object_property_add_uint8_ptr (OBJECT (s),ACPI_PM_PROP_GPE0_BLK_LEN , + &s->ar.gpe.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,
PATCH 2/7 hw/acpi/ich9: Remove unneeded assignments
In reply to Bernhard BeschowThe first thing ich9_pm_iospace_update() does is to set pm->pm_io_base to the pm_io_base parameter. The pm_io_base parameter's value is the old one of pm->pm_io_base.
--- hw/acpi/ich9.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
hw/acpi/ich9.c +1 -3
@@ -136,9 +136,7 @@ void ich9_pm_iospace_update(ICH9LPCPMRegs *pm, uint32_t pm_io_base)static int ich9_pm_post_load (void *opaque,int version_id) {ICH9LPCPMRegs *pm = opaque; -uint32_t pm_io_base = pm->pm_io_base; - pm->pm_io_base =0 ; -ich9_pm_iospace_update (pm, pm_io_base); +ich9_pm_iospace_update (pm, pm->pm_io_base);return 0 ; }
Signature · 1 line
2.39.1
Re: [PATCH 2/7] hw/acpi/ich9: Remove unneeded assignments
Quoted 2 lines · On Sun, 22 Jan 2023 18:07:19 +0100 Bernhard Beschow <[email protected]> wrote:
The first thing
ich9_pm_iospace_update()does is to setpm->pm_io_baseto thepm_io_baseparameter.
try to explain why 'pm->pm_io_base = 0' was there , what's changed and then why it's no longer needed.
Quoted 2 lines
The
pm_io_baseparameter's value is the old
one ofpm->pm_io_base.
I can't parse this sentence.
Quoted 21 lines
Signed-off-by Bernhard Beschow <[email protected]>--- hw/acpi/ich9.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)hw/acpi/ich9.c +1
-3@@ -136,9 +136,7 @@ void ich9_pm_iospace_update(ICH9LPCPMRegs *pm, uint32_t pm_io_base)static int ich9_pm_post_load (void *opaque,int version_id) {ICH9LPCPMRegs *pm = opaque; -uint32_t pm_io_base = pm->pm_io_base; - pm->pm_io_base =0 ; -ich9_pm_iospace_update (pm, pm_io_base); +ich9_pm_iospace_update (pm, pm->pm_io_base);return 0 ; }
Re: [PATCH 2/7] hw/acpi/ich9: Remove unneeded assignments
Am 24. Januar 2023 16:55:37 UTC schrieb Igor Mammedov <[email protected]>:
Quoted 7 lines
Quoted 2 lines · On Sun, 22 Jan 2023 18:07:19 +0100 Bernhard Beschow <[email protected]> wrote:
The first thing
ich9_pm_iospace_update()does is to setpm->pm_io_baseto thepm_io_baseparameter.try to explain why '
pm->pm_io_base= 0' was there , what's changed and then why it's no longer needed.
Meanwhile I think the whole function is a no-op and can be removed. Some archeology will explain how it came to be.
Quoted 30 lines
Quoted 3 lines
The
pm_io_baseparameter's value is the old
one ofpm->pm_io_base.I can't parse this sentence.
Fixes cacaab8bdd7460Quoted 21 lines
Signed-off-by Bernhard Beschow <[email protected]>--- hw/acpi/ich9.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)hw/acpi/ich9.c +1
-3@@ -136,9 +136,7 @@ void ich9_pm_iospace_update(ICH9LPCPMRegs *pm, uint32_t pm_io_base)static int ich9_pm_post_load (void *opaque,int version_id) {ICH9LPCPMRegs *pm = opaque; -uint32_t pm_io_base = pm->pm_io_base; - pm->pm_io_base =0 ; -ich9_pm_iospace_update (pm, pm_io_base); +ich9_pm_iospace_update (pm, pm->pm_io_base);return 0 ; }
PATCH 3/7 hw/acpi/{ich9, piix4}: Resolve redundant io_base address attributes
In reply to Bernhard BeschowA MemoryRegion has an addr attribute which gets set to the same values as the redundant io_addr attributes.
--- include/hw/acpi/ich9.h | 1 - include/hw/acpi/piix4.h | 2 -- hw/acpi/ich9.c | 17 ++++++++--------- hw/acpi/piix4.c | 11 ++++++----- 4 files changed, 14 insertions(+), 17 deletions(-)
include/hw/acpi/ich9.h +0 -1
@@ -49,7 +49,6 @@ typedef struct ICH9LPCPMRegs {qemu_irq irq;/* SCI */ -uint32_t pm_io_base;Notifier powerdown_notifier;bool cpu_hotplug_legacy;
include/hw/acpi/piix4.h +0 -2
@@ -39,8 +39,6 @@ struct PIIX4PMState {/*< public >*/ MemoryRegion io; -uint32_t io_base; -MemoryRegion io_gpe;ACPIREGS ar;
hw/acpi/ich9.c +8 -9
@@ -126,17 +126,16 @@ void ich9_pm_iospace_update(ICH9LPCPMRegs *pm, uint32_t pm_io_base)assert ((pm_io_base &ICH9_PMIO_MASK ) ==0 ); - pm->pm_io_base = pm_io_base;memory_region_transaction_begin (); -memory_region_set_enabled (&pm->io, pm->pm_io_base !=0 ); -memory_region_set_address (&pm->io, pm->pm_io_base); +memory_region_set_enabled (&pm->io, pm_io_base !=0 ); +memory_region_set_address (&pm->io, pm_io_base);memory_region_transaction_commit (); }static int ich9_pm_post_load (void *opaque,int version_id) {ICH9LPCPMRegs *pm = opaque; -ich9_pm_iospace_update (pm, pm->pm_io_base); +ich9_pm_iospace_update (pm, pm->io.addr);return 0 ; }
@@ -349,9 +348,9 @@ static void ich9_pm_get_gpe0_blk(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { ICH9LPCPMRegs *pm = opaque; -uint32_t value = pm->pm_io_base +ICH9_PMIO_GPE0_STS ; +uint64_t value = pm->io.addr +ICH9_PMIO_GPE0_STS ; -visit_type_uint32 (v, name, &value, errp); +visit_type_uint64 (v, name, &value, errp); }static bool ich9_pm_get_memory_hotplug_support (Object *obj,Error **errp)
@@ -440,9 +439,9 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm) pm->keep_pci_slot_hpc = true; pm->enable_tco = true; -object_property_add_uint32_ptr (obj,ACPI_PM_PROP_PM_IO_BASE , - &pm->pm_io_base,OBJ_PROP_FLAG_READ ); -object_property_add (obj,ACPI_PM_PROP_GPE0_BLK ,"uint32" , +object_property_add_uint64_ptr (obj,ACPI_PM_PROP_PM_IO_BASE , + &pm->io.addr,OBJ_PROP_FLAG_READ ); +object_property_add (obj,ACPI_PM_PROP_GPE0_BLK ,"uint64" , ich9_pm_get_gpe0_blk,NULL ,NULL , pm); object_property_add_uint8_ptr(obj, ACPI_PM_PROP_GPE0_BLK_LEN,
hw/acpi/piix4.c +6 -5
@@ -91,13 +91,14 @@ static void apm_ctrl_changed(uint32_t val, void *arg)static void pm_io_space_update (PIIX4PMState *s) {PCIDevice *d =PCI_DEVICE (s); +uint32_t io_base; - s->io_base =le32_to_cpu (*(uint32_t *)(d->config +0x40 )); - s->io_base &=0xffc0 ; + io_base =le32_to_cpu (*(uint32_t *)(d->config +0x40 )); + io_base &=0xffc0 ;memory_region_transaction_begin ();memory_region_set_enabled (&s->io, d->config[0x80 ] &1 ); -memory_region_set_address (&s->io, s->io_base); +memory_region_set_address (&s->io, io_base);memory_region_transaction_commit (); }
@@ -433,8 +434,8 @@ static void piix4_pm_add_properties(PIIX4PMState *s) &s->ar.gpe.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_property_add_uint64_ptr (OBJECT (s),ACPI_PM_PROP_PM_IO_BASE , + &s->io.addr,OBJ_PROP_FLAG_READ ); }static void piix4_pm_realize (PCIDevice *dev,Error **errp)
Signature · 1 line
2.39.1
Re: [PATCH 3/7] hw/acpi/{ich9,piix4}: Resolve redundant io_base address attributes
Hi Bernhard,
Quoted 20 lines · Bernhard Beschow
A MemoryRegion has an addr attribute which gets set to the same values as the redundant
io_addrattributes.Signed-off-by Bernhard Beschow <[email protected]>--- include/hw/acpi/ich9.h | 1 - include/hw/acpi/piix4.h | 2 -- hw/acpi/ich9.c | 17 ++++++++--------- hw/acpi/piix4.c | 11 ++++++----- 4 files changed, 14 insertions(+), 17 deletions(-)hw/acpi/piix4.c +1
-0@@ -91,13 +91,14 @@ static void apm_ctrl_changed(uint32_t val, void *arg)static void pm_io_space_update (PIIX4PMState *s) {PCIDevice *d =PCI_DEVICE (s); +uint32_t io_base;
hw/acpi/piix4.c static void apm_ctrl_changed(uint32_t val, void *arg) · line 101
Quoted 10 lines
hw/acpi/piix4.c +3
-3- s->io_base =le32_to_cpu (*(uint32_t *)(d->config +0x40 )); - s->io_base &=0xffc0 ; + io_base =le32_to_cpu (*(uint32_t *)(d->config +0x40 )); + io_base &=0xffc0 ;memory_region_transaction_begin ();memory_region_set_enabled (&s->io, d->config[0x80 ] &1 ); -memory_region_set_address (&s->io, s->io_base); +memory_region_set_address (&s->io, io_base);
OK for this part.
hw/acpi/piix4.c static void piix4_pm_add_properties(PIIX4PMState *s) · line 438
Quoted 11 lines
hw/acpi/piix4.c +2
-2memory_region_transaction_commit (); }@@ -433,8 +434,8 @@ static void piix4_pm_add_properties(PIIX4PMState *s) &s->ar.gpe.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_property_add_uint64_ptr (OBJECT (s),ACPI_PM_PROP_PM_IO_BASE , + &s->io.addr,OBJ_PROP_FLAG_READ );
+Eduardo/Mark
We shouldn't do that IMO, because we access an internal field from another QOM object.
We can however alias the MR property:
object_property_add_alias(OBJECT(s), ACPI_PM_PROP_PM_IO_BASE,
OBJECT(&s->io), "addr");Quoted 1 line
hw/acpi/piix4.c +0
-0}
Re: [PATCH 3/7] hw/acpi/{ich9,piix4}: Resolve redundant io_base address attributes
Am 23. Januar 2023 07:57:08 UTC schrieb "Philippe Mathieu-Daudé" <[email protected]>:
Quoted 47 lines
Hi Bernhard,
Quoted 18 lines · Bernhard Beschow
A MemoryRegion has an addr attribute which gets set to the same values as the redundant
io_addrattributes.Signed-off-by Bernhard Beschow <[email protected]>--- include/hw/acpi/ich9.h | 1 - include/hw/acpi/piix4.h | 2 -- hw/acpi/ich9.c | 17 ++++++++--------- hw/acpi/piix4.c | 11 ++++++----- 4 files changed, 14 insertions(+), 17 deletions(-)hw/acpi/piix4.c +0
-0@@ -91,13 +91,14 @@ static void apm_ctrl_changed(uint32_t val, void *arg)static void pm_io_space_update (PIIX4PMState *s) {hw/acpi/piix4.c static void apm_ctrl_changed(uint32_t val, void *arg) · line 100
Quoted 10 lines
hw/acpi/piix4.c +4
-2PCIDevice *d =PCI_DEVICE (s); +uint32_t io_base; - s->io_base =le32_to_cpu (*(uint32_t *)(d->config +0x40 )); - s->io_base &=0xffc0 ; + io_base =le32_to_cpu (*(uint32_t *)(d->config +0x40 )); + io_base &=0xffc0 ;memory_region_transaction_begin ();memory_region_set_enabled (&s->io, d->config[0x80 ] &1 ); -memory_region_set_address (&s->io, s->io_base); +memory_region_set_address (&s->io, io_base);OK for this part.
hw/acpi/piix4.c static void piix4_pm_add_properties(PIIX4PMState *s) · line 438
Quoted 10 lines
hw/acpi/piix4.c +2
-2memory_region_transaction_commit (); } @@ -433,8 +434,8 @@ static void piix4_pm_add_properties(PIIX4PMState *s) &s->ar.gpe.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_property_add_uint64_ptr (OBJECT (s),ACPI_PM_PROP_PM_IO_BASE , + &s->io.addr,OBJ_PROP_FLAG_READ );+Eduardo/Mark
Quoted 7 lines
We shouldn't do that IMO, because we access an internal field from another QOM object.
We can however alias the MR property:
object_property_add_alias(OBJECT(s),
ACPI_PM_PROP_PM_IO_BASE,OBJECT(&s->io), "addr");
Indeed! And the "addr" property is already read-only -- which seems like a good fit.
Quoted 2 lines
Quoted 2 lines
}
Re: [PATCH 3/7] hw/acpi/{ich9,piix4}: Resolve redundant io_base address attributes
s/resolve/remove|drop/
Quoted 6 lines · On Mon, 23 Jan 2023 15:49:29 +0000 Bernhard Beschow <[email protected]> wrote:
Am 23. Januar 2023 07:57:08 UTC schrieb "Philippe Mathieu-Daudé" <[email protected]>:
Quoted 5 lines
Hi Bernhard,
Quoted 2 lines · Bernhard Beschow
A MemoryRegion has an addr attribute which gets set to the same values as the redundant
io_addrattributes.
MemoryRegion::addr is an offset within subregion while fields you are removing are absolute values (offset within address space).
Assuming that the former is the same as the later seems wrong to me (even if they both match at the moment).
So I'd drop this patch.
Quoted 41 lines
Quoted 41 lines
Quoted 15 lines
Signed-off-by Bernhard Beschow <[email protected]>--- include/hw/acpi/ich9.h | 1 - include/hw/acpi/piix4.h | 2 -- hw/acpi/ich9.c | 17 ++++++++--------- hw/acpi/piix4.c | 11 ++++++----- 4 files changed, 14 insertions(+), 17 deletions(-)hw/acpi/piix4.c +0
-0@@ -91,13 +91,14 @@ static void apm_ctrl_changed(uint32_t val, void *arg)static void pm_io_space_update (PIIX4PMState *s) {hw/acpi/piix4.c static void apm_ctrl_changed(uint32_t val, void *arg) · line 100
Quoted 10 lines
hw/acpi/piix4.c +4
-2PCIDevice *d =PCI_DEVICE (s); +uint32_t io_base; - s->io_base =le32_to_cpu (*(uint32_t *)(d->config +0x40 )); - s->io_base &=0xffc0 ; + io_base =le32_to_cpu (*(uint32_t *)(d->config +0x40 )); + io_base &=0xffc0 ;memory_region_transaction_begin ();memory_region_set_enabled (&s->io, d->config[0x80 ] &1 ); -memory_region_set_address (&s->io, s->io_base); +memory_region_set_address (&s->io, io_base);OK for this part.
hw/acpi/piix4.c static void piix4_pm_add_properties(PIIX4PMState *s) · line 438
Quoted 10 lines
hw/acpi/piix4.c +2
-2memory_region_transaction_commit (); } @@ -433,8 +434,8 @@ static void piix4_pm_add_properties(PIIX4PMState *s) &s->ar.gpe.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_property_add_uint64_ptr (OBJECT (s),ACPI_PM_PROP_PM_IO_BASE , + &s->io.addr,OBJ_PROP_FLAG_READ );+Eduardo/Mark
Quoted 7 lines
Quoted 7 lines
We shouldn't do that IMO, because we access an internal field from another QOM object.
We can however alias the MR property:
object_property_add_alias(OBJECT(s),
ACPI_PM_PROP_PM_IO_BASE,OBJECT(&s->io), "addr");
also, do not access 'io.addr' directly elsewhere in the patch either.
Quoted 6 lines
Indeed! And the "addr" property is already read-only -- which seems like a good fit.
Quoted 2 lines
Quoted 2 lines
}
Re: [PATCH 3/7] hw/acpi/{ich9,piix4}: Resolve redundant io_base address attributes
Am 24. Januar 2023 16:05:40 UTC schrieb Igor Mammedov <[email protected]>:
Quoted 13 lines
s/resolve/remove|drop/
Quoted 6 lines · On Mon, 23 Jan 2023 15:49:29 +0000 Bernhard Beschow <[email protected]> wrote:
Am 23. Januar 2023 07:57:08 UTC schrieb "Philippe Mathieu-Daudé" <[email protected]>:
Quoted 5 lines
Hi Bernhard,
Quoted 2 lines · Bernhard Beschow
A MemoryRegion has an addr attribute which gets set to the same values as the redundant
io_addrattributes.
Quoted 6 lines
MemoryRegion::addris an offset within subregion while fields you are removing are absolute values (offset within address space).Assuming that the former is the same as the later seems wrong to me (even if they both match at the moment).
So I'd drop this patch.
The device models try hard to keep those in sync. I'd rather avoid having two sources of truth, so I think there is merit in keeping this patch and split it in two.
Note that in addition, the base addresses are also present in PCI config space which is yet another source of truth. The config space is preserved during migration, and I meanwhile noticed that the addresses are recovered from there. This makes the io_addr attributes seem even more redundant.
There is already a memory_region_to_absolute_addr() which would fit well here. It would need to be exported, and I wonder if it isn't for a reason? Any thoughts?
Quoted 60 lines
Quoted 43 lines
Quoted 43 lines
Quoted 17 lines
Signed-off-by Bernhard Beschow <[email protected]>--- include/hw/acpi/ich9.h | 1 - include/hw/acpi/piix4.h | 2 -- hw/acpi/ich9.c | 17 ++++++++--------- hw/acpi/piix4.c | 11 ++++++----- 4 files changed, 14 insertions(+), 17 deletions(-)hw/acpi/piix4.c +0
-0@@ -91,13 +91,14 @@ static void apm_ctrl_changed(uint32_t val, void *arg)static void pm_io_space_update (PIIX4PMState *s) {hw/acpi/piix4.c static void apm_ctrl_changed(uint32_t val, void *arg) · line 100
Quoted 10 lines
hw/acpi/piix4.c +4
-2PCIDevice *d =PCI_DEVICE (s); +uint32_t io_base; - s->io_base =le32_to_cpu (*(uint32_t *)(d->config +0x40 )); - s->io_base &=0xffc0 ; + io_base =le32_to_cpu (*(uint32_t *)(d->config +0x40 )); + io_base &=0xffc0 ;memory_region_transaction_begin ();memory_region_set_enabled (&s->io, d->config[0x80 ] &1 ); -memory_region_set_address (&s->io, s->io_base); +memory_region_set_address (&s->io, io_base);OK for this part.
hw/acpi/piix4.c static void piix4_pm_add_properties(PIIX4PMState *s) · line 438
Quoted 10 lines
hw/acpi/piix4.c +2
-2memory_region_transaction_commit (); } @@ -433,8 +434,8 @@ static void piix4_pm_add_properties(PIIX4PMState *s) &s->ar.gpe.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_property_add_uint64_ptr (OBJECT (s),ACPI_PM_PROP_PM_IO_BASE , + &s->io.addr,OBJ_PROP_FLAG_READ );+Eduardo/Mark
Quoted 7 lines
Quoted 7 lines
We shouldn't do that IMO, because we access an internal field from another QOM object.
We can however alias the MR property:
object_property_add_alias(OBJECT(s),
ACPI_PM_PROP_PM_IO_BASE,OBJECT(&s->io), "addr");also, do not access 'io.addr' directly elsewhere in the patch either.
Quoted 6 lines
Indeed! And the "addr" property is already read-only -- which seems like a good fit.
Quoted 2 lines
Quoted 2 lines
}
PATCH 4/7 hw/acpi/ich9: Use ICH9_PMIO_GPE0_STS just once
In reply to Bernhard BeschowCosmetic change emphasizing that always the actual address of the gpe0 block is returned.
--- hw/acpi/ich9.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/acpi/ich9.c +3 -1
@@ -348,7 +348,9 @@ static void ich9_pm_get_gpe0_blk(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { ICH9LPCPMRegs *pm = opaque; -uint64_t value = pm->io.addr +ICH9_PMIO_GPE0_STS ; +uint64_t value = pm->io.addr + pm->io_gpe.addr; + +assert (&pm->io == pm->io_gpe.container);visit_type_uint64 (v, name, &value, errp); }
Signature · 1 line
2.39.1
Re: [PATCH 4/7] hw/acpi/ich9: Use ICH9_PMIO_GPE0_STS just once
Quoted 1 line · On Sun, 22 Jan 2023 18:07:21 +0100 Bernhard Beschow <[email protected]> wrote:
Cosmetic change emphasizing
... how 3/7 makes it more confusing
Quoted 13 lines
that always the actual address of the gpe0
block is returned.Signed-off-by Bernhard Beschow <[email protected]>--- hw/acpi/ich9.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)hw/acpi/ich9.c +0
-0
hw/acpi/ich9.c static void ich9_pm_get_gpe0_blk(Object *obj, Visitor *v, const char *name, · line 351
Quoted 5 lines
hw/acpi/ich9.c +1
-1@@ -348,7 +348,9 @@ static void ich9_pm_get_gpe0_blk(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { ICH9LPCPMRegs *pm = opaque; -uint64_t value = pm->io.addr +ICH9_PMIO_GPE0_STS ; +uint64_t value = pm->io.addr + pm->io_gpe.addr;
do not poke inside of MemoryRegion, right API to use here if you really want to get it from memory region would be
memory_region_find && MemoryRegionSection::offset_within_address_space magic
I'd just drop 3/7 and this patch
Quoted 5 lines
hw/acpi/ich9.c +2
-0+ +assert (&pm->io == pm->io_gpe.container);visit_type_uint64 (v, name, &value, errp); }
PATCH 5/7 hw/acpi/piix4: Fix offset of GPE0 registers
In reply to Bernhard BeschowThe PIIX4 datasheet defines the GPSTS register to be at offset 0x0c of the power management I/O register block. This register block is represented in the device model by the io attribute. So make io_gpe a child memory region of io at offset 0x0c.
Note that SeaBIOS sets the base address of the register block to 0x600, resulting in the io_gpe block to start at 0x60c. GPE_BASE is defined as 0xafe0 which is 0xa9d4 bytes off. In order to preserve compatibilty, create an io_gpe_qemu memory region alias at GPE_BASE.
--- include/hw/acpi/piix4.h | 1 + hw/acpi/piix4.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
include/hw/acpi/piix4.h +1 -0
@@ -40,6 +40,7 @@ struct PIIX4PMState {MemoryRegion io;MemoryRegion io_gpe; +MemoryRegion io_gpe_qemu;ACPIREGS ar;APMState apm;
hw/acpi/piix4.c +7 -2
@@ -49,6 +49,7 @@#include "qom/object.h" #define GPE_BASE 0xafe0 +#define GPE_OFS 0xc#define GPE_LEN 4#define ACPI_PCIHP_ADDR_PIIX4 0xae00
@@ -429,7 +430,7 @@ static void piix4_pm_add_properties(PIIX4PMState *s)object_property_add_uint8_ptr (OBJECT (s),ACPI_PM_PROP_ACPI_DISABLE_CMD , &acpi_disable_cmd,OBJ_PROP_FLAG_READ );object_property_add_uint64_ptr (OBJECT (s),ACPI_PM_PROP_GPE0_BLK , - &s->io_gpe.addr,OBJ_PROP_FLAG_READ ); + &s->io_gpe_qemu.addr,OBJ_PROP_FLAG_READ );object_property_add_uint8_ptr (OBJECT (s),ACPI_PM_PROP_GPE0_BLK_LEN , &s->ar.gpe.len,OBJ_PROP_FLAG_READ ); object_property_add_uint16_ptr(OBJECT(s), ACPI_PM_PROP_SCI_INT,
@@ -558,7 +559,11 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent, {memory_region_init_io (&s->io_gpe,OBJECT (s), &piix4_gpe_ops, s,"acpi-gpe0" ,GPE_LEN ); -memory_region_add_subregion (parent,GPE_BASE , &s->io_gpe); +memory_region_add_subregion (&s->io,GPE_OFS , &s->io_gpe); + +memory_region_init_alias (&s->io_gpe_qemu,OBJECT (s),"acpi-gpe0-qemu" , + &s->io_gpe,0 ,memory_region_size (&s->io_gpe)); +memory_region_add_subregion (parent,GPE_BASE , &s->io_gpe_qemu);if (s->use_acpi_hotplug_bridge || s->use_acpi_root_pci_hotplug) { acpi_pcihp_init(OBJECT(s), &s->acpi_pci_hotplug, bus, parent,
Signature · 1 line
2.39.1
Re: [PATCH 5/7] hw/acpi/piix4: Fix offset of GPE0 registers
Quoted 4 lines · On Sun, 22 Jan 2023 18:07:22 +0100 Bernhard Beschow <[email protected]> wrote:
The PIIX4 datasheet defines the GPSTS register to be at offset
0x0cof the power management I/O register block. This register block is represented in the device model by the io attribute. So makeio_gpea child memory region of io at offset0x0c.
to what end?
Quoted 4 lines
Note that SeaBIOS sets the base address of the register block to
0x600, resulting in theio_gpeblock to start at0x60c.GPE_BASEis defined as0xafe0which is0xa9d4bytes off. In order to preserve compatibilty, create anio_gpe_qemumemory region alias atGPE_BASE.
qemu's io_gpe != piix4(GPSTS)
QEMU simply doesn't implement piix4(GPSTS), instead it has implemented custom GPE registers block at 0xafe0 for its hotplug purposes. Bits in both GPE blocks have different meaning,
so moving io_gpe to PMBASE+0x0c, would be a bug.
Interesting question is what guest gets now when it reads PMBASE+0x0c ?
If reads return -1 and guest uses these
registers it might get confused since all STS/EN bits are set and writes are ignored. We likely get away with it since these registers aren't used by non ACPI guests (non x86 ones) and x86 ones fetch GPE block from FADT table => not using piix4(GPSTS) at all.
So It's a bug to fix (at least make it read as 0s)
Quoted 52 lines
Signed-off-by Bernhard Beschow <[email protected]>--- include/hw/acpi/piix4.h | 1 + hw/acpi/piix4.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-)include/hw/acpi/piix4.h +1
-0@@ -40,6 +40,7 @@ struct PIIX4PMState {MemoryRegion io;MemoryRegion io_gpe; +MemoryRegion io_gpe_qemu;ACPIREGS ar;APMState apm;hw/acpi/piix4.c +7
-2@@ -49,6 +49,7 @@#include "qom/object.h" #define GPE_BASE 0xafe0 +#define GPE_OFS 0xc#define GPE_LEN 4#define ACPI_PCIHP_ADDR_PIIX4 0xae00@@ -429,7 +430,7 @@ static void piix4_pm_add_properties(PIIX4PMState *s)object_property_add_uint8_ptr (OBJECT (s),ACPI_PM_PROP_ACPI_DISABLE_CMD , &acpi_disable_cmd,OBJ_PROP_FLAG_READ );object_property_add_uint64_ptr (OBJECT (s),ACPI_PM_PROP_GPE0_BLK , - &s->io_gpe.addr,OBJ_PROP_FLAG_READ ); + &s->io_gpe_qemu.addr,OBJ_PROP_FLAG_READ );object_property_add_uint8_ptr (OBJECT (s),ACPI_PM_PROP_GPE0_BLK_LEN , &s->ar.gpe.len,OBJ_PROP_FLAG_READ ); object_property_add_uint16_ptr(OBJECT(s), ACPI_PM_PROP_SCI_INT,@@ -558,7 +559,11 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent, {memory_region_init_io (&s->io_gpe,OBJECT (s), &piix4_gpe_ops, s,"acpi-gpe0" ,GPE_LEN ); -memory_region_add_subregion (parent,GPE_BASE , &s->io_gpe); +memory_region_add_subregion (&s->io,GPE_OFS , &s->io_gpe); + +memory_region_init_alias (&s->io_gpe_qemu,OBJECT (s),"acpi-gpe0-qemu" , + &s->io_gpe,0 ,memory_region_size (&s->io_gpe)); +memory_region_add_subregion (parent,GPE_BASE , &s->io_gpe_qemu);if (s->use_acpi_hotplug_bridge || s->use_acpi_root_pci_hotplug) { acpi_pcihp_init(OBJECT(s), &s->acpi_pci_hotplug, bus, parent,
Re: [PATCH 5/7] hw/acpi/piix4: Fix offset of GPE0 registers
Am 25. Januar 2023 15:55:01 UTC schrieb Igor Mammedov <[email protected]>:
Quoted 24 lines
Quoted 4 lines · On Sun, 22 Jan 2023 18:07:22 +0100 Bernhard Beschow <[email protected]> wrote:
The PIIX4 datasheet defines the GPSTS register to be at offset
0x0cof the power management I/O register block. This register block is represented in the device model by the io attribute. So makeio_gpea child memory region of io at offset0x0c.to what end?
Quoted 4 lines
Note that SeaBIOS sets the base address of the register block to
0x600, resulting in theio_gpeblock to start at0x60c.GPE_BASEis defined as0xafe0which is0xa9d4bytes off. In order to preserve compatibilty, create anio_gpe_qemumemory region alias atGPE_BASE.qemu's
io_gpe!= piix4(GPSTS)
QEMU simply doesn't implement piix4(GPSTS), instead it has implemented custom GPE registers block at0xafe0for its hotplug purposes. Bits in both GPE blocks have different meaning,
so movingio_gpetoPMBASE+0x0c, would be a bug.Interesting question is what guest gets now when it reads
PMBASE+0x0c?
Quoted 7 lines
If reads return -1 and guest uses these
registers it might get confused since all STS/EN bits are set and writes are ignored. We likely get away with it since these registers aren't used by non ACPI guests (non x86 ones) and x86 ones fetch GPE block from FADT table => not using piix4(GPSTS) at all.
So It's a bug to fix (at least make it read as 0s)
I see. This wasn't obvious to me and I'll drop this patch.
How about renaming io_gpe to something communicating that this is purely a "Frankenstein" functionality, e.g. to io_gpe_qemu or io_gpe_hotplug? Any preferences?
Quoted 53 lines
Quoted 52 lines
Signed-off-by Bernhard Beschow <[email protected]>--- include/hw/acpi/piix4.h | 1 + hw/acpi/piix4.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-)include/hw/acpi/piix4.h +1
-0@@ -40,6 +40,7 @@ struct PIIX4PMState {MemoryRegion io;MemoryRegion io_gpe; +MemoryRegion io_gpe_qemu;ACPIREGS ar;APMState apm;hw/acpi/piix4.c +7
-2@@ -49,6 +49,7 @@#include "qom/object.h" #define GPE_BASE 0xafe0 +#define GPE_OFS 0xc#define GPE_LEN 4#define ACPI_PCIHP_ADDR_PIIX4 0xae00@@ -429,7 +430,7 @@ static void piix4_pm_add_properties(PIIX4PMState *s)object_property_add_uint8_ptr (OBJECT (s),ACPI_PM_PROP_ACPI_DISABLE_CMD , &acpi_disable_cmd,OBJ_PROP_FLAG_READ );object_property_add_uint64_ptr (OBJECT (s),ACPI_PM_PROP_GPE0_BLK , - &s->io_gpe.addr,OBJ_PROP_FLAG_READ ); + &s->io_gpe_qemu.addr,OBJ_PROP_FLAG_READ );object_property_add_uint8_ptr (OBJECT (s),ACPI_PM_PROP_GPE0_BLK_LEN , &s->ar.gpe.len,OBJ_PROP_FLAG_READ ); object_property_add_uint16_ptr(OBJECT(s), ACPI_PM_PROP_SCI_INT,@@ -558,7 +559,11 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent, {memory_region_init_io (&s->io_gpe,OBJECT (s), &piix4_gpe_ops, s,"acpi-gpe0" ,GPE_LEN ); -memory_region_add_subregion (parent,GPE_BASE , &s->io_gpe); +memory_region_add_subregion (&s->io,GPE_OFS , &s->io_gpe); + +memory_region_init_alias (&s->io_gpe_qemu,OBJECT (s),"acpi-gpe0-qemu" , + &s->io_gpe,0 ,memory_region_size (&s->io_gpe)); +memory_region_add_subregion (parent,GPE_BASE , &s->io_gpe_qemu);if (s->use_acpi_hotplug_bridge || s->use_acpi_root_pci_hotplug) { acpi_pcihp_init(OBJECT(s), &s->acpi_pci_hotplug, bus, parent,
Re: [PATCH 5/7] hw/acpi/piix4: Fix offset of GPE0 registers
Quoted 33 lines · On Sun, 29 Jan 2023 14:55:06 +0000 Bernhard Beschow <[email protected]> wrote:
Am 25. Januar 2023 15:55:01 UTC schrieb Igor Mammedov <[email protected]>:
Quoted 24 lines
Quoted 4 lines · On Sun, 22 Jan 2023 18:07:22 +0100 Bernhard Beschow <[email protected]> wrote:
The PIIX4 datasheet defines the GPSTS register to be at offset
0x0cof the power management I/O register block. This register block is represented in the device model by the io attribute. So makeio_gpea child memory region of io at offset0x0c.to what end?
Quoted 4 lines
Note that SeaBIOS sets the base address of the register block to
0x600, resulting in theio_gpeblock to start at0x60c.GPE_BASEis defined as0xafe0which is0xa9d4bytes off. In order to preserve compatibilty, create anio_gpe_qemumemory region alias atGPE_BASE.qemu's
io_gpe!= piix4(GPSTS)
QEMU simply doesn't implement piix4(GPSTS), instead it has implemented custom GPE registers block at0xafe0for its hotplug purposes. Bits in both GPE blocks have different meaning,
so movingio_gpetoPMBASE+0x0c, would be a bug.Interesting question is what guest gets now when it reads
PMBASE+0x0c?Quoted 7 lines
If reads return -1 and guest uses these
registers it might get confused since all STS/EN bits are set and writes are ignored. We likely get away with it since these registers aren't used by non ACPI guests (non x86 ones) and x86 ones fetch GPE block from FADT table => not using piix4(GPSTS) at all.
So It's a bug to fix (at least make it read as 0s)
Quoted 3 lines
I see. This wasn't obvious to me and I'll drop this patch.
How about renaming
io_gpeto something communicating that this is purely a "Frankenstein" functionality, e.g. toio_gpe_qemuorio_gpe_hotplug? Any preferences?
I don't think it's worth of effort, io_gpe is not worse that others.
Quoted 55 lines
Quoted 54 lines
Quoted 53 lines
Signed-off-by Bernhard Beschow <[email protected]>--- include/hw/acpi/piix4.h | 1 + hw/acpi/piix4.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-)include/hw/acpi/piix4.h +1
-0@@ -40,6 +40,7 @@ struct PIIX4PMState {MemoryRegion io;MemoryRegion io_gpe; +MemoryRegion io_gpe_qemu;ACPIREGS ar;APMState apm;hw/acpi/piix4.c +7
-2@@ -49,6 +49,7 @@#include "qom/object.h" #define GPE_BASE 0xafe0 +#define GPE_OFS 0xc#define GPE_LEN 4#define ACPI_PCIHP_ADDR_PIIX4 0xae00@@ -429,7 +430,7 @@ static void piix4_pm_add_properties(PIIX4PMState *s)object_property_add_uint8_ptr (OBJECT (s),ACPI_PM_PROP_ACPI_DISABLE_CMD , &acpi_disable_cmd,OBJ_PROP_FLAG_READ );object_property_add_uint64_ptr (OBJECT (s),ACPI_PM_PROP_GPE0_BLK , - &s->io_gpe.addr,OBJ_PROP_FLAG_READ ); + &s->io_gpe_qemu.addr,OBJ_PROP_FLAG_READ );object_property_add_uint8_ptr (OBJECT (s),ACPI_PM_PROP_GPE0_BLK_LEN , &s->ar.gpe.len,OBJ_PROP_FLAG_READ ); object_property_add_uint16_ptr(OBJECT(s), ACPI_PM_PROP_SCI_INT,@@ -558,7 +559,11 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent, {memory_region_init_io (&s->io_gpe,OBJECT (s), &piix4_gpe_ops, s,"acpi-gpe0" ,GPE_LEN ); -memory_region_add_subregion (parent,GPE_BASE , &s->io_gpe); +memory_region_add_subregion (&s->io,GPE_OFS , &s->io_gpe); + +memory_region_init_alias (&s->io_gpe_qemu,OBJECT (s),"acpi-gpe0-qemu" , + &s->io_gpe,0 ,memory_region_size (&s->io_gpe)); +memory_region_add_subregion (parent,GPE_BASE , &s->io_gpe_qemu);if (s->use_acpi_hotplug_bridge || s->use_acpi_root_pci_hotplug) { acpi_pcihp_init(OBJECT(s), &s->acpi_pci_hotplug, bus, parent,
PATCH 6/7 hw/acpi: Trace GPE access in all device models, not just PIIX4
In reply to Bernhard Beschow--- hw/acpi/core.c | 5 +++++ hw/acpi/piix4.c | 3 --- hw/acpi/trace-events | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-)
hw/acpi/core.c +5 -0
@@ -32,6 +32,7 @@#include "qemu/module.h" #include "qemu/option.h" #include "sysemu/runstate.h" +#include "trace.h" struct acpi_table_header {uint16_t _length;/* our length, not actual part of the hdr */
@@ -686,6 +687,8 @@ void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val) {uint8_t *cur; +trace_acpi_gpe_ioport_writeb (addr, val); + cur =acpi_gpe_ioport_get_ptr (ar, addr);if (addr < ar->gpe.len /2 ) {/* GPE_STS */
@@ -709,6 +712,8 @@ uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr) val = *cur; } +trace_acpi_gpe_ioport_readb (addr, val); +return val; }
hw/acpi/piix4.c +0 -3
@@ -45,7 +45,6 @@#include "hw/acpi/acpi_dev_interface.h" #include "migration/vmstate.h" #include "hw/core/cpu.h" -#include "trace.h" #include "qom/object.h" #define GPE_BASE 0xafe0
@@ -510,7 +509,6 @@ static uint64_t gpe_readb(void *opaque, hwaddr addr, unsigned width)PIIX4PMState *s = opaque;uint32_t val =acpi_gpe_ioport_readb (&s->ar, addr); -trace_piix4_gpe_readb (addr, width, val);return val; }
@@ -519,7 +517,6 @@ static void gpe_writeb(void *opaque, hwaddr addr, uint64_t val, {PIIX4PMState *s = opaque; -trace_piix4_gpe_writeb (addr, width, val);acpi_gpe_ioport_writeb (&s->ar, addr, val);acpi_update_sci (&s->ar, s->irq); }
hw/acpi/trace-events +4 -4
@@ -17,6 +17,10 @@ mhp_acpi_clear_remove_evt(uint32_t slot) "slot[0x%"PRIx32"] clear remove event" mhp_acpi_pc_dimm_deleted(uint32_t slot) "slot[0x%"PRIx32"] pc-dimm deleted" mhp_acpi_pc_dimm_delete_failed(uint32_t slot) "slot[0x%"PRIx32"] pc-dimm delete failed" +# core.c +acpi_gpe_ioport_readb(uint32_t addr, uint8_t val) "addr: 0x%" PRIx32 " ==> 0x%" PRIx8 +acpi_gpe_ioport_writeb(uint32_t addr, uint8_t val) "addr: 0x%" PRIx32 " <== 0x%" PRIx8 + # cpu.c cpuhp_acpi_invalid_idx_selected(uint32_t idx) "0x%"PRIx32 cpuhp_acpi_read_flags(uint32_t idx, uint8_t flags) "idx[0x%"PRIx32"] flags: 0x%"PRIx8
@@ -48,10 +52,6 @@ acpi_pci_sel_read(uint32_t val) "%" PRIu32 acpi_pci_ej_write(uint64_t addr, uint64_t data) "0x%" PRIx64 " <== %" PRIu64 acpi_pci_sel_write(uint64_t addr, uint64_t data) "0x%" PRIx64 " <== %" PRIu64 -# piix4.c -piix4_gpe_readb(uint64_t addr, unsigned width, uint64_t val) "addr: 0x%" PRIx64 " width: %d ==> 0x%" PRIx64 -piix4_gpe_writeb(uint64_t addr, unsigned width, uint64_t val) "addr: 0x%" PRIx64 " width: %d <== 0x%" PRIx64 - # tco.c tco_timer_reload(int ticks, int msec) "ticks=%d (%d ms)" tco_timer_expired(int timeouts_no, bool strap, bool no_reboot) "timeouts_no=%d no_reboot=%d/%d"
Signature · 1 line
2.39.1
Re: [PATCH 6/7] hw/acpi: Trace GPE access in all device models, not just PIIX4
Quoted 6 lines · Bernhard Beschow
Signed-off-by Bernhard Beschow <[email protected]>--- hw/acpi/core.c | 5 +++++ hw/acpi/piix4.c | 3 --- hw/acpi/trace-events | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-)
Re: [PATCH 6/7] hw/acpi: Trace GPE access in all device models, not just PIIX4
In reply to Bernhard BeschowQuoted 1 line · On Sun, 22 Jan 2023 18:07:23 +0100 Bernhard Beschow <[email protected]> wrote:
Signed-off-by Bernhard Beschow <[email protected]>
Quoted 90 lines
--- hw/acpi/core.c | 5 +++++ hw/acpi/piix4.c | 3 --- hw/acpi/trace-events | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-)hw/acpi/core.c +5
-0@@ -32,6 +32,7 @@#include "qemu/module.h" #include "qemu/option.h" #include "sysemu/runstate.h" +#include "trace.h" struct acpi_table_header {uint16_t _length;/* our length, not actual part of the hdr */ @@ -686,6 +687,8 @@ void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val) {uint8_t *cur; +trace_acpi_gpe_ioport_writeb (addr, val); + cur =acpi_gpe_ioport_get_ptr (ar, addr);if (addr < ar->gpe.len /2 ) {/* GPE_STS */ @@ -709,6 +712,8 @@ uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr) val = *cur; } +trace_acpi_gpe_ioport_readb (addr, val); +return val; }hw/acpi/piix4.c +0
-3@@ -45,7 +45,6 @@#include "hw/acpi/acpi_dev_interface.h" #include "migration/vmstate.h" #include "hw/core/cpu.h" -#include "trace.h" #include "qom/object.h" #define GPE_BASE 0xafe0@@ -510,7 +509,6 @@ static uint64_t gpe_readb(void *opaque, hwaddr addr, unsigned width)PIIX4PMState *s = opaque;uint32_t val =acpi_gpe_ioport_readb (&s->ar, addr); -trace_piix4_gpe_readb (addr, width, val);return val; }@@ -519,7 +517,6 @@ static void gpe_writeb(void *opaque, hwaddr addr, uint64_t val, {PIIX4PMState *s = opaque; -trace_piix4_gpe_writeb (addr, width, val);acpi_gpe_ioport_writeb (&s->ar, addr, val);acpi_update_sci (&s->ar, s->irq); }hw/acpi/trace-events +4
-4@@ -17,6 +17,10 @@ mhp_acpi_clear_remove_evt(uint32_t slot) "slot[0x%"PRIx32"] clear remove event" mhp_acpi_pc_dimm_deleted(uint32_t slot) "slot[0x%"PRIx32"] pc-dimm deleted" mhp_acpi_pc_dimm_delete_failed(uint32_t slot) "slot[0x%"PRIx32"] pc-dimm delete failed" +# core.c +acpi_gpe_ioport_readb(uint32_t addr, uint8_t val) "addr: 0x%" PRIx32 " ==> 0x%" PRIx8 +acpi_gpe_ioport_writeb(uint32_t addr, uint8_t val) "addr: 0x%" PRIx32 " <== 0x%" PRIx8 + # cpu.c cpuhp_acpi_invalid_idx_selected(uint32_t idx) "0x%"PRIx32 cpuhp_acpi_read_flags(uint32_t idx, uint8_t flags) "idx[0x%"PRIx32"] flags: 0x%"PRIx8@@ -48,10 +52,6 @@ acpi_pci_sel_read(uint32_t val) "%" PRIu32 acpi_pci_ej_write(uint64_t addr, uint64_t data) "0x%" PRIx64 " <== %" PRIu64 acpi_pci_sel_write(uint64_t addr, uint64_t data) "0x%" PRIx64 " <== %" PRIu64 -# piix4.c -piix4_gpe_readb(uint64_t addr, unsigned width, uint64_t val) "addr: 0x%" PRIx64 " width: %d ==> 0x%" PRIx64 -piix4_gpe_writeb(uint64_t addr, unsigned width, uint64_t val) "addr: 0x%" PRIx64 " width: %d <== 0x%" PRIx64 - # tco.c tco_timer_reload(int ticks, int msec) "ticks=%d (%d ms)" tco_timer_expired(int timeouts_no, bool strap, bool no_reboot) "timeouts_no=%d no_reboot=%d/%d"
PATCH 7/7 hw/acpi/core: Trace enable and status registers of GPE separately
In reply to Bernhard BeschowThe bit positions of both registers are related. Tracing the registers independently results in the same offsets across these registers which eases debugging.
--- hw/acpi/core.c | 10 +++++++--- hw/acpi/trace-events | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-)
hw/acpi/core.c +7 -3
@@ -687,13 +687,13 @@ void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val) {uint8_t *cur; -trace_acpi_gpe_ioport_writeb (addr, val); - cur =acpi_gpe_ioport_get_ptr (ar, addr);if (addr < ar->gpe.len /2 ) { +trace_acpi_gpe_sts_ioport_writeb (addr, val);/* GPE_STS */ *cur = (*cur) & ~val; }else if (addr < ar->gpe.len) { +trace_acpi_gpe_en_ioport_writeb (addr - (ar->gpe.len /2 ), val);/* GPE_EN */ *cur = val; }else {
@@ -712,7 +712,11 @@ uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr) val = *cur; } -trace_acpi_gpe_ioport_readb (addr, val); +if (addr < ar->gpe.len /2 ) { +trace_acpi_gpe_sts_ioport_readb (addr, val); + }else { +trace_acpi_gpe_en_ioport_readb (addr - (ar->gpe.len /2 ), val); + }return val; }
hw/acpi/trace-events +4 -2
@@ -18,8 +18,10 @@ mhp_acpi_pc_dimm_deleted(uint32_t slot) "slot[0x%"PRIx32"] pc-dimm deleted" mhp_acpi_pc_dimm_delete_failed(uint32_t slot) "slot[0x%"PRIx32"] pc-dimm delete failed" # core.c -acpi_gpe_ioport_readb(uint32_t addr, uint8_t val) "addr: 0x%" PRIx32 " ==> 0x%" PRIx8 -acpi_gpe_ioport_writeb(uint32_t addr, uint8_t val) "addr: 0x%" PRIx32 " <== 0x%" PRIx8 +acpi_gpe_sts_ioport_readb(uint32_t addr, uint8_t val) "addr: 0x%" PRIx32 " ==> 0x%" PRIx8 +acpi_gpe_en_ioport_readb(uint32_t addr, uint8_t val) "addr: 0x%" PRIx32 " ==> 0x%" PRIx8 +acpi_gpe_sts_ioport_writeb(uint32_t addr, uint8_t val) "addr: 0x%" PRIx32 " <== 0x%" PRIx8 +acpi_gpe_en_ioport_writeb(uint32_t addr, uint8_t val) "addr: 0x%" PRIx32 " <== 0x%" PRIx8 # cpu.c cpuhp_acpi_invalid_idx_selected(uint32_t idx) "0x%"PRIx32
Signature · 1 line
2.39.1
Re: [PATCH 7/7] hw/acpi/core: Trace enable and status registers of GPE separately
Quoted 5 lines · On Sun, 22 Jan 2023 18:07:24 +0100 Bernhard Beschow <[email protected]> wrote:
The bit positions of both registers are related. Tracing the registers independently results in the same offsets across these registers which eases debugging.
Signed-off-by Bernhard Beschow <[email protected]>
Quoted 55 lines
--- hw/acpi/core.c | 10 +++++++--- hw/acpi/trace-events | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-)hw/acpi/core.c +7
-3@@ -687,13 +687,13 @@ void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val) {uint8_t *cur; -trace_acpi_gpe_ioport_writeb (addr, val); - cur =acpi_gpe_ioport_get_ptr (ar, addr);if (addr < ar->gpe.len /2 ) { +trace_acpi_gpe_sts_ioport_writeb (addr, val);/* GPE_STS */ *cur = (*cur) & ~val; }else if (addr < ar->gpe.len) { +trace_acpi_gpe_en_ioport_writeb (addr - (ar->gpe.len /2 ), val);/* GPE_EN */ *cur = val; }else {@@ -712,7 +712,11 @@ uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr) val = *cur; } -trace_acpi_gpe_ioport_readb (addr, val); +if (addr < ar->gpe.len /2 ) { +trace_acpi_gpe_sts_ioport_readb (addr, val); + }else { +trace_acpi_gpe_en_ioport_readb (addr - (ar->gpe.len /2 ), val); + }return val; }hw/acpi/trace-events +4
-2@@ -18,8 +18,10 @@ mhp_acpi_pc_dimm_deleted(uint32_t slot) "slot[0x%"PRIx32"] pc-dimm deleted" mhp_acpi_pc_dimm_delete_failed(uint32_t slot) "slot[0x%"PRIx32"] pc-dimm delete failed" # core.c -acpi_gpe_ioport_readb(uint32_t addr, uint8_t val) "addr: 0x%" PRIx32 " ==> 0x%" PRIx8 -acpi_gpe_ioport_writeb(uint32_t addr, uint8_t val) "addr: 0x%" PRIx32 " <== 0x%" PRIx8 +acpi_gpe_sts_ioport_readb(uint32_t addr, uint8_t val) "addr: 0x%" PRIx32 " ==> 0x%" PRIx8 +acpi_gpe_en_ioport_readb(uint32_t addr, uint8_t val) "addr: 0x%" PRIx32 " ==> 0x%" PRIx8 +acpi_gpe_sts_ioport_writeb(uint32_t addr, uint8_t val) "addr: 0x%" PRIx32 " <== 0x%" PRIx8 +acpi_gpe_en_ioport_writeb(uint32_t addr, uint8_t val) "addr: 0x%" PRIx32 " <== 0x%" PRIx8 # cpu.c cpuhp_acpi_invalid_idx_selected(uint32_t idx) "0x%"PRIx32
Quoted 2 lines · On Sun, 22 Jan 2023 18:07:17 +0100 Bernhard Beschow <[email protected]> wrote:
This series brings the PIIX4 PM device closer to reality and resolves some redundant code along the way.
I'm done with this series review
Quoted 23 lines
Testing done:
-make check
- Starting a live CD under pc and q35 machines and check that the GPE accesses are tracedBernhard Beschow (7):
hw/acpi/{ich9,piix4}: Reuse existing attributes for QOM properties hw/acpi/ich9: Remove unneeded assignments hw/acpi/{ich9,piix4}: Resolve redundantio_baseaddress attributes hw/acpi/ich9: UseICH9_PMIO_GPE0_STSjust once hw/acpi/piix4: Fix offset of GPE0 registers
hw/acpi: Trace GPE access in all device models, not just PIIX4 hw/acpi/core: Trace enable and status registers of GPE separatelyinclude/hw/acpi/ich9.h | 1 - include/hw/acpi/piix4.h | 3 +-- hw/acpi/core.c | 9 +++++++++ hw/acpi/ich9.c | 26 ++++++++++++-------------- hw/acpi/piix4.c | 31 ++++++++++++++++--------------- hw/acpi/trace-events | 10 ++++++---- 6 files changed, 44 insertions(+), 36 deletions(-)