pc: make ACPI pcihp more reusable
v3 cover pc: make ACPI pcihp more reusable
changes since v2:
- rename 'use_acpi_pci_hotplug' field to 'legacy_piix'
and corresponding properties
- drop excessive checks for legacy mode
- rework legacy vmstate handling to use AcpiPciHpPciStatus[0] structure
which reduced acpi/piix4.c by another 50 LOC
- move legacy initialization to pcihp.c
changes since v1:
- add BSEL property to root bus when in compatibility mode
as result dropped "hw:acpi:pcihp: assume root PCI bus if bus has no ACPI_PCIHP_PROP_BSEL property"
- rebasing on top of "pcihp: reduce number of device check events"
added patch 3/4.
Reuses new pcihp code for handling legacy PCI hotplug in acpi/piix4_pm, which significantly reduces code duplication between piix4_pm and pcihp reducing codebase by ~200 LOC.
It also allows cleaner rebase of generic hotplug refactoring, by not increasing code duplication since it will need to be done only for pcihp.
Git tree for testing based on mst's PCI tree:
https://github.com/imammedo/qemu/commits/pcihp_cleanup_v3
Igor Mammedov (5):
pcihp: replace enable|disable_device() with oneliners
pcihp: make PCI hotplug mmio handlers indifferent to PCI_HOTPLUG_ADDR
pcihp: make pci_read() mmio calback compatible with legacy ACPI
hotplug
pcihp: remove unused AcpiPciHpPciStatus.device_present field hw:piix4:acpi: reuse pcihp code for legacy PCI hotplug
hw/acpi/pcihp.c | 64 +++++++------- hw/acpi/piix4.c | 220 ++++------------------------------------------- include/hw/acpi/pcihp.h | 3 +- include/hw/i386/pc.h | 4 +- 4 files changed, 57 insertions(+), 234 deletions(-)
PATCH v3 1/5 pcihp: replace enable|disable_device() with oneliners
enable_device() and disable_device() functions aren't reused anywere, so replace them with respective oneliners at call sites.
--- hw/acpi/pcihp.c | 14 ++------------ 1 files changed, 2 insertions(+), 12 deletions(-)
hw/acpi/pcihp.c +2 -12
@@ -177,16 +177,6 @@ void acpi_pcihp_reset(AcpiPciHpState *s)acpi_pcihp_update (s); } -static void enable_device (AcpiPciHpState *s,unsigned bsel,int slot) -{ - s->acpi_pcihp_pci_status[bsel].up |= (1U << slot); -} - -static void disable_device (AcpiPciHpState *s,unsigned bsel,int slot) -{ - s->acpi_pcihp_pci_status[bsel].down |= (1U << slot); -} -int acpi_pcihp_device_hotplug (AcpiPciHpState *s,PCIDevice *dev,PCIHotplugState state) {
@@ -204,9 +194,9 @@ int acpi_pcihp_device_hotplug(AcpiPciHpState *s, PCIDevice *dev, }if (state ==PCI_HOTPLUG_ENABLED ) { -enable_device (s, bsel, slot); + s->acpi_pcihp_pci_status[bsel].up |= (1U << slot); }else { -disable_device (s, bsel, slot); + s->acpi_pcihp_pci_status[bsel].down |= (1U << slot); }return 0 ;
Signature · 1 line
1.7.1
PATCH v3 2/5 pcihp: make PCI hotplug mmio handlers indifferent to PCI_HOTPLUG_ADDR
In reply to Igor Mammedov... removes dependency of mmio handler on PCI_HOTPLUG_ADDR. It will be needed in case of Q35 where base could be different.
--- hw/acpi/pcihp.c | 24 ++++++++++++------------ 1 files changed, 12 insertions(+), 12 deletions(-)
hw/acpi/pcihp.c +12 -12
@@ -48,11 +48,11 @@#define PCI_HOTPLUG_ADDR 0xae00#define PCI_HOTPLUG_SIZE 0x0014 -#define PCI_UP_BASE 0xae00 -#define PCI_DOWN_BASE 0xae04 -#define PCI_EJ_BASE 0xae08 -#define PCI_RMV_BASE 0xae0c -#define PCI_SEL_BASE 0xae10 +#define PCI_UP_BASE 0x0000 +#define PCI_DOWN_BASE 0x0004 +#define PCI_EJ_BASE 0x0008 +#define PCI_RMV_BASE 0x000c +#define PCI_SEL_BASE 0x0010 typedef struct AcpiPciHpFind { int bsel;
@@ -213,24 +213,24 @@ static uint64_t pci_read(void *opaque, hwaddr addr, unsigned int size) }switch (addr) { -case PCI_UP_BASE -PCI_HOTPLUG_ADDR : +case PCI_UP_BASE : val = s->acpi_pcihp_pci_status[bsel].up; s->acpi_pcihp_pci_status[bsel].up =0 ;ACPI_PCIHP_DPRINTF ("pci_up_read %" PRIu32"\n" , val);break ; -case PCI_DOWN_BASE -PCI_HOTPLUG_ADDR : +case PCI_DOWN_BASE : val = s->acpi_pcihp_pci_status[bsel].down;ACPI_PCIHP_DPRINTF ("pci_down_read %" PRIu32"\n" , val);break ; -case PCI_EJ_BASE -PCI_HOTPLUG_ADDR : +case PCI_EJ_BASE :/* No feature defined yet */ ACPI_PCIHP_DPRINTF ("pci_features_read %" PRIu32"\n" , val);break ; -case PCI_RMV_BASE -PCI_HOTPLUG_ADDR : +case PCI_RMV_BASE : val = s->acpi_pcihp_pci_status[bsel].hotplug_enable;ACPI_PCIHP_DPRINTF ("pci_rmv_read %" PRIu32"\n" , val);break ; -case PCI_SEL_BASE -PCI_HOTPLUG_ADDR : +case PCI_SEL_BASE : val = s->hotplug_select;ACPI_PCIHP_DPRINTF ("pci_sel_read %" PRIu32"\n" , val);default :
@@ -245,7 +245,7 @@ static void pci_write(void *opaque, hwaddr addr, uint64_t data, {AcpiPciHpState *s = opaque;switch (addr) { -case PCI_EJ_BASE -PCI_HOTPLUG_ADDR : +case PCI_EJ_BASE :if (s->hotplug_select >=ACPI_PCIHP_MAX_HOTPLUG_BUS ) {break ; }
@@ -253,7 +253,7 @@ static void pci_write(void *opaque, hwaddr addr, uint64_t data,ACPI_PCIHP_DPRINTF ("pciej write %" HWADDR_PRIx" <== %" PRIu64"\n" , addr, data);break ; -case PCI_SEL_BASE -PCI_HOTPLUG_ADDR : +case PCI_SEL_BASE : s->hotplug_select = data;ACPI_PCIHP_DPRINTF ("pcisel write %" HWADDR_PRIx" <== %" PRIu64"\n" , addr, data);
Signature · 1 line
1.7.1
PATCH v3 3/5 pcihp: make pci_read() mmio calback compatible with legacy ACPI hotplug
In reply to Igor Mammedovdue to recent change introduced by:
"pcihp: reduce number of device check events"
'up' field is cleared right after it's read. This is incompatible with legacy BIOS ACPI code where PCNF ACPI method reads this field 32 times.
To make pci_read mmio callback compatible with legacy 'up' behavior, pcihp code will need to know in which mode it runs so move 'use_acpi_pci_hotplug' into AcpiPciHpState structure and alter register behavior accordingly.
PS:
And since field 'use_acpi_pci_hotplug' is touched anyway rename it to reflect its meaning more crearly to 'legacy_piix' and corresponding property to 'legacy-acpi-pci-hotplug'.
--- hw/acpi/pcihp.c | 4 +++- hw/acpi/piix4.c | 15 +++++++-------- include/hw/acpi/pcihp.h | 1 + include/hw/i386/pc.h | 4 ++-- 4 files changed, 13 insertions(+), 11 deletions(-)
hw/acpi/pcihp.c +3 -1
@@ -215,7 +215,9 @@ static uint64_t pci_read(void *opaque, hwaddr addr, unsigned int size)switch (addr) {case PCI_UP_BASE : val = s->acpi_pcihp_pci_status[bsel].up; - s->acpi_pcihp_pci_status[bsel].up =0 ; +if (!s->legacy_piix) { + s->acpi_pcihp_pci_status[bsel].up =0 ; + }ACPI_PCIHP_DPRINTF ("pci_up_read %" PRIu32"\n" , val);break ;case PCI_DOWN_BASE :
hw/acpi/piix4.c +7 -8
@@ -88,7 +88,6 @@ typedef struct PIIX4PMState {/* for new pci hotplug (with PCI2PCI bridge support) */ AcpiPciHpState acpi_pci_hotplug; -bool use_acpi_pci_hotplug;uint8_t disable_s3;uint8_t disable_s4;
@@ -263,13 +262,13 @@ static int acpi_load_old(QEMUFile *f, void *opaque, int version_id)static bool vmstate_test_use_acpi_pci_hotplug (void *opaque,int version_id) {PIIX4PMState *s = opaque; -return s->use_acpi_pci_hotplug; +return !s->acpi_pci_hotplug.legacy_piix; }static bool vmstate_test_no_use_acpi_pci_hotplug (void *opaque,int version_id) {PIIX4PMState *s = opaque; -return !s->use_acpi_pci_hotplug; +return s->acpi_pci_hotplug.legacy_piix; }/* qemu-kvm 1.2 uses version 3 but advertised as 2
@@ -377,7 +376,7 @@ static void piix4_reset(void *opaque) pci_conf[0x5B ] =0x02 ; }pm_io_space_update (s); -if (s->use_acpi_pci_hotplug) { +if (!s->acpi_pci_hotplug.legacy_piix) {acpi_pcihp_reset (&s->acpi_pci_hotplug); }else {piix4_update_hotplug (s);
@@ -426,7 +425,7 @@ static void piix4_pm_machine_ready(Notifier *n, void *opaque) pci_conf[0x67 ] = (memory_region_present (io_as,0x3f8 ) ?0x08 :0 ) | (memory_region_present (io_as,0x2f8 ) ?0x90 :0 ); -if (s->use_acpi_pci_hotplug) { +if (!s->acpi_pci_hotplug.legacy_piix) {pci_for_each_bus (d->bus, piix4_update_bus_hotplug, s); } }
@@ -550,8 +549,8 @@ static Property piix4_pm_properties[] = {DEFINE_PROP_UINT8 (ACPI_PM_PROP_S3_DISABLED , PIIX4PMState, disable_s3,0 ),DEFINE_PROP_UINT8 (ACPI_PM_PROP_S4_DISABLED , PIIX4PMState, disable_s4,0 ),DEFINE_PROP_UINT8 (ACPI_PM_PROP_S4_VAL , PIIX4PMState, s4_val,2 ), -DEFINE_PROP_BOOL ("acpi-pci-hotplug-with-bridge-support" , PIIX4PMState, - use_acpi_pci_hotplug, true), +DEFINE_PROP_BOOL ("legacy-acpi-pci-hotplug" , PIIX4PMState, + acpi_pci_hotplug.legacy_piix, false), DEFINE_PROP_END_OF_LIST(), };
@@ -694,7 +693,7 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent, "acpi-gpe0", GPE_LEN);memory_region_add_subregion (parent,GPE_BASE , &s->io_gpe); -if (s->use_acpi_pci_hotplug) { +if (!s->acpi_pci_hotplug.legacy_piix) {acpi_pcihp_init (&s->acpi_pci_hotplug, bus, parent); }else { memory_region_init_io(&s->io_pci, OBJECT(s), &piix4_pci_ops, s,
include/hw/acpi/pcihp.h +1 -0
@@ -46,6 +46,7 @@ typedef struct AcpiPciHpState {uint32_t hotplug_select;PCIBus *root;MemoryRegion io; +bool legacy_piix; } AcpiPciHpState; void acpi_pcihp_init(AcpiPciHpState *, PCIBus *root,
include/hw/i386/pc.h +2 -2
@@ -268,8 +268,8 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t); },\ {\ .driver = "PIIX4_PM",\ - .property = "acpi-pci-hotplug-with-bridge-support",\ - .value = "off",\ + .property = "legacy-acpi-pci-hotplug",\ + .value = "on",\ }#define PC_COMPAT_1_6 \
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH v3 3/5] pcihp: make pci_read() mmio calback compatible with legacy ACPI hotplug
Quoted 89 lines · Igor Mammedov
due to recent change introduced by:
"pcihp: reduce number of device check events"'up' field is cleared right after it's read. This is incompatible with legacy BIOS ACPI code where PCNF ACPI method reads this field 32 times.
To make
pci_readmmio callback compatible with legacy 'up' behavior, pcihp code will need to know in which mode it runs so move 'use_acpi_pci_hotplug' into AcpiPciHpState structure and alter register behavior accordingly.PS:
And since field 'use_acpi_pci_hotplug' is touched anyway rename it to reflect its meaning more crearly to 'legacy_piix' and corresponding property to 'legacy-acpi-pci-hotplug'.Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/pcihp.c | 4 +++- hw/acpi/piix4.c | 15 +++++++-------- include/hw/acpi/pcihp.h | 1 + include/hw/i386/pc.h | 4 ++-- 4 files changed, 13 insertions(+), 11 deletions(-)hw/acpi/pcihp.c +3
-1@@ -215,7 +215,9 @@ static uint64_t pci_read(void *opaque, hwaddr addr, unsigned int size)switch (addr) {case PCI_UP_BASE : val = s->acpi_pcihp_pci_status[bsel].up; - s->acpi_pcihp_pci_status[bsel].up =0 ; +if (!s->legacy_piix) { + s->acpi_pcihp_pci_status[bsel].up =0 ; + }ACPI_PCIHP_DPRINTF ("pci_up_read %" PRIu32"\n" , val);break ;case PCI_DOWN_BASE :hw/acpi/piix4.c +4
-5@@ -88,7 +88,6 @@ typedef struct PIIX4PMState {/* for new pci hotplug (with PCI2PCI bridge support) */ AcpiPciHpState acpi_pci_hotplug; -bool use_acpi_pci_hotplug;uint8_t disable_s3;uint8_t disable_s4;@@ -263,13 +262,13 @@ static int acpi_load_old(QEMUFile *f, void *opaque, int version_id)static bool vmstate_test_use_acpi_pci_hotplug (void *opaque,int version_id) {PIIX4PMState *s = opaque; -return s->use_acpi_pci_hotplug; +return !s->acpi_pci_hotplug.legacy_piix; }static bool vmstate_test_no_use_acpi_pci_hotplug (void *opaque,int version_id) {PIIX4PMState *s = opaque; -return !s->use_acpi_pci_hotplug; +return s->acpi_pci_hotplug.legacy_piix; }/* qemu-kvm 1.2 uses version 3 but advertised as 2 @@ -377,7 +376,7 @@ static void piix4_reset(void *opaque) pci_conf[0x5B ] =0x02 ; }pm_io_space_update (s); -if (s->use_acpi_pci_hotplug) { +if (!s->acpi_pci_hotplug.legacy_piix) {acpi_pcihp_reset (&s->acpi_pci_hotplug); }else {piix4_update_hotplug (s);@@ -426,7 +425,7 @@ static void piix4_pm_machine_ready(Notifier *n, void *opaque) pci_conf[0x67 ] = (memory_region_present (io_as,0x3f8 ) ?0x08 :0 ) | (memory_region_present (io_as,0x2f8 ) ?0x90 :0 ); -if (s->use_acpi_pci_hotplug) { +if (!s->acpi_pci_hotplug.legacy_piix) {pci_for_each_bus (d->bus, piix4_update_bus_hotplug, s); } }
hw/acpi/piix4.c static Property piix4_pm_properties[] = { · line 553
Quoted 7 lines
hw/acpi/piix4.c +2
-2@@ -550,8 +549,8 @@ static Property piix4_pm_properties[] = {DEFINE_PROP_UINT8 (ACPI_PM_PROP_S3_DISABLED , PIIX4PMState, disable_s3,0 ),DEFINE_PROP_UINT8 (ACPI_PM_PROP_S4_DISABLED , PIIX4PMState, disable_s4,0 ),DEFINE_PROP_UINT8 (ACPI_PM_PROP_S4_VAL , PIIX4PMState, s4_val,2 ), -DEFINE_PROP_BOOL ("acpi-pci-hotplug-with-bridge-support" , PIIX4PMState, - use_acpi_pci_hotplug, true), +DEFINE_PROP_BOOL ("legacy-acpi-pci-hotplug" , PIIX4PMState, + acpi_pci_hotplug.legacy_piix, false),
That's a worse less descriptive name for user property. I also think it's not nice that piix pokes at acpi_pci_hotplug structure internals
without an API, here and below.
Let's pass a bool flag to the init function, have
acpi maintain it internally.
Quoted 29 lines
hw/acpi/piix4.c +1
-1DEFINE_PROP_END_OF_LIST(), };@@ -694,7 +693,7 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent, "acpi-gpe0", GPE_LEN);memory_region_add_subregion (parent,GPE_BASE , &s->io_gpe); -if (s->use_acpi_pci_hotplug) { +if (!s->acpi_pci_hotplug.legacy_piix) {acpi_pcihp_init (&s->acpi_pci_hotplug, bus, parent); }else { memory_region_init_io(&s->io_pci, OBJECT(s), &piix4_pci_ops, s,include/hw/acpi/pcihp.h +1
-0@@ -46,6 +46,7 @@ typedef struct AcpiPciHpState {uint32_t hotplug_select;PCIBus *root;MemoryRegion io; +bool legacy_piix; } AcpiPciHpState; void acpi_pcihp_init(AcpiPciHpState *, PCIBus *root,include/hw/i386/pc.h +0
-0
include/hw/i386/pc.h int e820_add_entry(uint64_t, uint64_t, uint32_t); · line 272
Quoted 7 lines
include/hw/i386/pc.h +2
-2@@ -268,8 +268,8 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t); },\ {\ .driver = "PIIX4_PM",\ - .property = "acpi-pci-hotplug-with-bridge-support",\ - .value = "off",\ + .property = "legacy-acpi-pci-hotplug",\ + .value = "on",\
?
Quoted 5 lines
include/hw/i386/pc.h +0
-0}#define PC_COMPAT_1_6 \Signature · 1 line
1.7.1
PATCH v3 4/5 pcihp: remove unused AcpiPciHpPciStatus.device_present field
In reply to Igor MammedovRemove now unused 'device_present' field wich was obsoleted by patch "pcihp: reduce number of device check events"
--- include/hw/acpi/pcihp.h | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
include/hw/acpi/pcihp.h +0 -1
@@ -35,7 +35,6 @@ typedef struct AcpiPciHpPciStatus {uint32_t up;uint32_t down;uint32_t hotplug_enable; -uint32_t device_present; } AcpiPciHpPciStatus;#define ACPI_PCIHP_PROP_BSEL "acpi-pcihp-bsel"
Signature · 1 line
1.7.1
PATCH v3 5/5 hw:piix4:acpi: reuse pcihp code for legacy PCI hotplug
In reply to Igor Mammedovreduces acpi PCI hotplug code duplication by ~200LOC
---
v3:
- remove exessive checks for compat mode
- replace up/down fields of pci_status with corresponding fields form AcpiPciHpPciStatus in vmstate wich allow to remove extra 50 LOC of legacy code
- move legacy initialization logic to pcihp.c
v2:
- replace obsolete 'device_present' with 'up' field
- add/set ACPI_PCIHP_PROP_BSEL to 0 when running in compatibility mode with old machine types.
--- hw/acpi/pcihp.c | 22 ++++- hw/acpi/piix4.c | 209 +++------------------------------------------- include/hw/acpi/pcihp.h | 1 + 3 files changed, 32 insertions(+), 200 deletions(-)
hw/acpi/pcihp.c +17 -5
@@ -46,8 +46,9 @@# define ACPI_PCIHP_DPRINTF (format, ...) do { } while (0)#endif -#define PCI_HOTPLUG_ADDR 0xae00 -#define PCI_HOTPLUG_SIZE 0x0014 +#define ACPI_PCIHP_ADDR 0xae00 +#define ACPI_PCIHP_SIZE 0x0014 +#define ACPI_PCIHP_LEGACY_SIZE 0x000f#define PCI_UP_BASE 0x0000#define PCI_DOWN_BASE 0x0004#define PCI_EJ_BASE 0x0008
@@ -277,11 +278,22 @@ static const MemoryRegionOps acpi_pcihp_io_ops = {void acpi_pcihp_init (AcpiPciHpState *s,PCIBus *root_bus,MemoryRegion *address_space_io) { +uint16_t io_size =ACPI_PCIHP_SIZE ; + +if (s->legacy_piix) { +unsigned *bus_bsel =g_malloc (sizeof *bus_bsel); + + io_size =ACPI_PCIHP_LEGACY_SIZE ; + + *bus_bsel =ACPI_PCIHP_BSEL_DEFAULT ; +object_property_add_uint32_ptr (OBJECT (root_bus),ACPI_PCIHP_PROP_BSEL , + bus_bsel,NULL ); + } + s->root= root_bus;memory_region_init_io (&s->io,NULL , &acpi_pcihp_io_ops, s, -"acpi-pci-hotplug" , -PCI_HOTPLUG_SIZE ); -memory_region_add_subregion (address_space_io,PCI_HOTPLUG_ADDR , &s->io); +"acpi-pci-hotplug" , io_size); +memory_region_add_subregion (address_space_io,ACPI_PCIHP_ADDR , &s->io); }const VMStateDescription vmstate_acpi_pcihp_pci_status = {
hw/acpi/piix4.c +14 -195
285 lines not on this page · raw message
include/hw/acpi/pcihp.h +1 -0
@@ -39,6 +39,7 @@ typedef struct AcpiPciHpPciStatus {#define ACPI_PCIHP_PROP_BSEL "acpi-pcihp-bsel"#define ACPI_PCIHP_MAX_HOTPLUG_BUS 256 +#define ACPI_PCIHP_BSEL_DEFAULT 0x0 typedef struct AcpiPciHpState { AcpiPciHpPciStatus acpi_pcihp_pci_status[ACPI_PCIHP_MAX_HOTPLUG_BUS];
Signature · 1 line
1.7.1