diff mbox series

[39/40] pcihp: generate populated non-hotpluggble slot descriptions on non-hotplug path

Message ID 20230112140312.3096331-40-imammedo@redhat.com
State New
Headers show
Series x86: fixing and cleaning up ACPI PCI code part 3 | expand

Commit Message

Igor Mammedov Jan. 12, 2023, 2:03 p.m. UTC
Generating slots descriptions populated by non-hotpluggable devices
is akward at best and complicates hotplug path (build_append_pcihp_slots)
needlessly, and builds only dynamic _DSM for such slots which is overlkill.
Clean it up and let non-hotplug path (build_append_pci_bus_devices)
to handle that task.

Such clean up effectively drops dynamic _DSM methods on non-hotpluggable
slots (even though bus itself is hotpluggable), but in practice it
affects only built-in devices (ide controllers/various bridges) that don't
use acpi-index anyways so effectively it doesn't matter (NICs are hotpluggble).

Follow up series will add static _DSM for non-hotpluggble devices/buses
that will not depend on ACPI PCI hotplug at all, and potentially would
allows us to reuse non-hotplug path elsewhere (PBX/microvm/arm-virt),
including new support for acpi-index for non-hotpluggable devices.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/acpi-build.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 50504578b9..c085bf7812 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -414,6 +414,7 @@  static bool is_devfn_ignored_hotplug(const int devfn, const PCIBus *bus)
     PCIDevice *pdev = bus->devices[devfn];
     if (pdev) {
         return is_devfn_ignored_generic(devfn, bus) ||
+               !DEVICE_GET_CLASS(pdev)->hotpluggable ||
                /* Cold plugged bridges aren't themselves hot-pluggable */
                (IS_PCI_BRIDGE(pdev) && !DEVICE(pdev)->hotplugged);
     } else { /* non populated slots */
@@ -440,17 +441,14 @@  static void build_append_pcihp_slots(Aml *parent_scope, PCIBus *bus,
     notify_method = aml_method("DVNT", 2, AML_NOTSERIALIZED);
 
     for (devfn = 0; devfn < ARRAY_SIZE(bus->devices); devfn++) {
-        PCIDevice *pdev = bus->devices[devfn];
         int slot = PCI_SLOT(devfn);
         int adr = slot << 16 | PCI_FUNC(devfn);
-        bool hotpluggbale_slot = true;
 
         if (is_devfn_ignored_hotplug(devfn, bus)) {
             continue;
         }
 
-        if (pdev) {
-            hotpluggbale_slot = DEVICE_GET_CLASS(pdev)->hotpluggable;
+        if (bus->devices[devfn]) {
             dev = aml_scope("S%.02X", devfn);
         } else {
             dev = aml_device("S%.02X", devfn);
@@ -464,17 +462,15 @@  static void build_append_pcihp_slots(Aml *parent_scope, PCIBus *bus,
         aml_append(dev, aml_name_decl("ASUN", aml_int(slot)));
         aml_append(dev, aml_pci_device_dsm());
 
-        if (hotpluggbale_slot) {
-            aml_append(dev, aml_name_decl("_SUN", aml_int(slot)));
-            /* add _EJ0 to make slot hotpluggable  */
-            method = aml_method("_EJ0", 1, AML_NOTSERIALIZED);
-            aml_append(method,
-                aml_call2("PCEJ", aml_name("BSEL"), aml_name("_SUN"))
-            );
-            aml_append(dev, method);
+        aml_append(dev, aml_name_decl("_SUN", aml_int(slot)));
+        /* add _EJ0 to make slot hotpluggable  */
+        method = aml_method("_EJ0", 1, AML_NOTSERIALIZED);
+        aml_append(method,
+            aml_call2("PCEJ", aml_name("BSEL"), aml_name("_SUN"))
+        );
+        aml_append(dev, method);
 
-            build_append_pcihp_notify_entry(notify_method, slot);
-        }
+        build_append_pcihp_notify_entry(notify_method, slot);
 
         /* device descriptor has been composed, add it into parent context */
         aml_append(parent_scope, dev);
@@ -493,8 +489,9 @@  void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus)
     for (devfn = 0; devfn < ARRAY_SIZE(bus->devices); devfn++) {
         /* ACPI spec: 1.0b: Table 6-2 _ADR Object Bus Types, PCI type */
         int adr = PCI_SLOT(devfn) << 16 | PCI_FUNC(devfn);
+        PCIDevice *pdev = bus->devices[devfn];
 
-        if (!bus->devices[devfn] || is_devfn_ignored_generic(devfn, bus)) {
+        if (!pdev || is_devfn_ignored_generic(devfn, bus)) {
             continue;
         }