Skip to contentSkip to conversation

acpi hotplug of devices behind a bridge

PATCH Superseded Michael S. Tsirkin 1 participant 4 messages Jul 11, 2013

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover acpi hotplug of devices behind a bridge

This is on top of patchset generating ACPI tables in qemu. Changes from v1:
- fixed some bugs
- fixed migration and cross version compatibility
- rebased to latest bits

Michael S. Tsirkin (2):
pci: add pci_for_each_bus
qemu: piix: PCI bridge ACPI hotplug support

 docs/specs/acpi_pci_hotplug.txt  |   8 +
 hw/acpi/piix4.c                  | 217 +++++++++++++++-----
 hw/i386/Makefile.objs            |   2 +-
 hw/i386/acpi-build.c             | 425 +++++++++++++++++++++++++++++++++++----
 hw/i386/acpi-dsdt.dsl            |  36 +++-
 hw/i386/pc_piix.c                |   3 +
 hw/i386/ssdt-pcihp.dsl           |  51 -----
 hw/i386/ssdt-pcihp.hex.generated | 108 ----------
 hw/pci/pci.c                     |  17 ++
 include/hw/i386/pc.h             |   5 +-
 include/hw/pci/pci.h             |   3 +
 11 files changed, 607 insertions(+), 268 deletions(-)
 delete mode 100644 hw/i386/ssdt-pcihp.dsl
 delete mode 100644 hw/i386/ssdt-pcihp.hex.generated
Signature · 1 line
MST
#1 lore raw

PATCH v2 1/2 pci: add pci_for_each_bus

Useful for ACPI hotplug.

---
 hw/pci/pci.c         | 17 +++++++++++++++++
 include/hw/pci/pci.h |  3 +++
 2 files changed, 20 insertions(+)
hw/pci/pci.c +17 -0
index 8680063..a4f7f8d 100644
@@ -1679,6 +1679,23 @@ static PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num)
     return NULL;
 }
 
+void pci_for_each_bus(PCIBus *bus, 
+                      void (*fn)(PCIBus *bus, void *opaque),
+                      void *opaque)
+{
+    PCIBus *sec;
+
+    if (!bus) {
+        return;
+    }
+
+    fn(bus, opaque);
+
+    QLIST_FOREACH(sec, &bus->child, sibling) {
+        pci_for_each_bus(sec, fn, opaque);
+    }
+}
+
 PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn)
 {
     bus = pci_find_bus_nr(bus, bus_num);
include/hw/pci/pci.h +3 -0
index 209dda4..a82c1c7 100644
@@ -391,6 +391,9 @@ int pci_bus_num(PCIBus *s);
 void pci_for_each_device(PCIBus *bus, int bus_num,
                          void (*fn)(PCIBus *bus, PCIDevice *d, void *opaque),
                          void *opaque);
+void pci_for_each_bus(PCIBus *bus, 
+                      void (*fn)(PCIBus *bus, void *opaque),
+                      void *opaque);
 PCIBus *pci_find_primary_bus(void);
 PCIBus *pci_device_root_bus(const PCIDevice *d);
 const char *pci_root_bus_path(PCIDevice *dev);
Signature · 1 line
MST
#2 lore raw

PATCH v2 2/2 qemu: piix: PCI bridge ACPI hotplug support

In reply to Michael S. Tsirkin

This adds support for device hotplug behind
pci bridges. Bridge devices themselves need
to be pre-configured on qemu command line.

Design:
- each bus gets assigned a number 0-255
- generated ACPI code writes this number
to a new BSEL register, then uses existing
UP/DOWN registers to probe slot status;
to eject, write number to BSEL register,
then slot into existing EJ

This is to address the ACPI spec requirement to avoid config cycle access to any bus except PCI roots.

Note: ACPI doesn't support adding or removing bridges by hotplug. We detect and prevent removal of bridges by hotplug, unless they were added by hotplug previously
(and so, are not described by ACPI).

Portability:
- Non x86 (or any Linux) platforms don't need any of this code. They can keep happily using SHPC the way
they always did.

Things to note:
- this is on top of acpi patchset posted previously. with a small patch adding a core function to walk all pci buses, on top.
Can also be found in my git tree
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git acpi-bridges

- Extensive use of glib completely removes pointer math in new code: we use g_array_append_vals exclusively.
Code in acpi-build.c will be switched to use the same approach, for security.

- As was the case previously,
systems that lack working iasl are detected at configure time, pre-generated hex files in source tree are used in this case. This addresses the concern with iasl/big-endian systems.

- Cross version migration: when running with -M 1.5 and older, new hotplug functionality is unavailable. All ACPI table generation is disabled.
We present FW_CFG interface compatible with 1.5.

Cc Jordan Justen <[email protected]>
Cc Anthony Liguori <[email protected]>
Cc Laszlo Ersek <[email protected]>
Cc Gerd Hoffmann <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Kevin O'Connor <[email protected]>
Cc Peter Maydell <[email protected]>
---
 docs/specs/acpi_pci_hotplug.txt  |   8 +
 hw/acpi/piix4.c                  | 217 +++++++++++++++-----
 hw/i386/Makefile.objs            |   2 +-
 hw/i386/acpi-build.c             | 425 +++++++++++++++++++++++++++++++++++----
 hw/i386/acpi-dsdt.dsl            |  36 +++-
 hw/i386/pc_piix.c                |   3 +
 hw/i386/ssdt-pcihp.dsl           |  51 -----
 hw/i386/ssdt-pcihp.hex.generated | 108 ----------
 include/hw/i386/pc.h             |   5 +-
 9 files changed, 587 insertions(+), 268 deletions(-)
 delete mode 100644 hw/i386/ssdt-pcihp.dsl
 delete mode 100644 hw/i386/ssdt-pcihp.hex.generated
docs/specs/acpi_pci_hotplug.txt +8 -0
index a839434..951b99a 100644
@@ -43,3 +43,11 @@ PCI removability status (IO port 0xae0c-0xae0f, 4-byte access):
 
 Used by ACPI BIOS _RMV method to indicate removability status to OS. One
 bit per slot.  Read-only
+
+PCI bus selector (IO port 0xae10-0xae13, 4-byte access):
+-----------------------------------------------
+
+Used by ACPI BIOS methods to select the current PCI bus.
+When written, makes all the other PCI registers (0xae00 - 0xae0f)
+to refer to the appropriate bus.
+0 selects PCI root bus (default).
hw/acpi/piix4.c +164 -53

420 lines not on this page · raw message

hw/i386/Makefile.objs +1 -1
index 2ab2572..c2e74e9 100644
@@ -6,7 +6,7 @@ obj-$(CONFIG_XEN) += xen_domainbuild.o xen_machine_pv.o
 obj-y += kvmvapic.o
 obj-y += acpi-build.o
 obj-y += bios-linker-loader.o
-hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex hw/i386/ssdt-proc.hex hw/i386/ssdt-pcihp.hex hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex
+hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex hw/i386/ssdt-proc.hex hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex
 hw/i386/pc_piix.o: hw/i386/pc_piix.c hw/i386/acpi-dsdt.hex
 hw/i386/pc_q35.o: hw/i386/pc_q35.c hw/i386/q35-acpi-dsdt.hex
 
hw/i386/acpi-build.c +381 -44

474 lines not on this page · raw message

hw/i386/acpi-dsdt.dsl +26 -10
index 90efce0..dc05668 100644
@@ -133,11 +133,18 @@ DefinitionBlock (
             B0EJ, 32,
         }
 
+        OperationRegion(SEL, SystemIO, 0xae10, 0x04)
+        Field(SEL, DWordAcc, NoLock, WriteAsZeros) {
+            BSEL, 32,
+        }
+
         /* Methods called by bulk generated PCI devices below */
+        Name(BNUM, 0x00)
 
         /* Methods called by hotplug devices */
-        Method(PCEJ, 1, NotSerialized) {
+        Method(PCEJ, 2, NotSerialized) {
             // _EJ0 method - eject callback
+            Store(Arg1, BSEL)
             Store(ShiftLeft(1, Arg0), B0EJ)
             Return (0x0)
         }
@@ -147,16 +154,25 @@ DefinitionBlock (
 
         /* PCI hotplug notify method */
         Method(PCNF, 0) {
-            // Local0 = iterator
+            // Local0 = bridge selector
             Store(Zero, Local0)
-            While (LLess(Local0, 31)) {
-                Increment(Local0)
-                If (And(PCIU, ShiftLeft(1, Local0))) {
-                    PCNT(Local0, 1)
-                }
-                If (And(PCID, ShiftLeft(1, Local0))) {
-                    PCNT(Local0, 3)
-                }
+            While (LLess(Local0, 255)) {
+                    Store(Local0, BSEL)
+                    // Local1 = slot iterator
+                    Store(Zero, Local1)
+
+                    Store(PCIU, Local2)
+                    Store(PCID, Local3)
+                    While (LLess(Local1, 31)) {
+                        Increment(Local1)
+                        If (And(Local2, ShiftLeft(1, Local1))) {
+                            PCNT(Add(Local1, Multiply(Local0, 32)), 1)
+                        }
+                        If (And(Local3, ShiftLeft(1, Local1))) {
+                            PCNT(Add(Local1, Multiply(Local0, 32)), 3)
+                        }
+                    }
+                    Increment(Local0)
             }
         }
     }
hw/i386/pc_piix.c +3 -0
index 77e4260..9183acc 100644
@@ -61,6 +61,7 @@ static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
 static bool has_pvpanic = true;
 static bool has_pci_info = true;
 static bool has_acpi_build = true;
+static bool has_acpi_bridge_hotplug = true;
 
 /* PC hardware initialisation */
 static void pc_init1(MemoryRegion *system_memory,
@@ -131,6 +132,7 @@ static void pc_init1(MemoryRegion *system_memory,
 
     guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
 
+    guest_info->has_acpi_bridge_hotplug = has_acpi_bridge_hotplug;
     guest_info->has_acpi_build = has_acpi_build;
     guest_info->dsdt_code = AcpiDsdtAmlCode;
     guest_info->dsdt_size = sizeof AcpiDsdtAmlCode;
@@ -277,6 +279,7 @@ static void pc_init_pci_1_5(QEMUMachineInitArgs *args)
 {
     has_pci_info = false;
     has_acpi_build = false;
+    has_acpi_bridge_hotplug = false;
     pc_init_pci(args);
 }
 
hw/i386/ssdt-pcihp.dsl deleted +0 -51

51 lines not on this page · raw message

hw/i386/ssdt-pcihp.hex.generated deleted +0 -108

108 lines not on this page · raw message

include/hw/i386/pc.h +4 -1
index 2ac97d3..051f423 100644
@@ -38,7 +38,9 @@ struct PcGuestInfo {
     bool s3_disabled;
     bool s4_disabled;
     uint8_t s4_val;
-    DECLARE_BITMAP(slot_hotplug_enable, PCI_SLOT_MAX);
+#define GUEST_INFO_MAX_HOTPLUG_BUS 256
+    PCIBus *hotplug_buses[GUEST_INFO_MAX_HOTPLUG_BUS];
+    DECLARE_BITMAP(hotplug_enable[GUEST_INFO_MAX_HOTPLUG_BUS], PCI_SLOT_MAX);
     uint16_t sci_int;
     uint8_t acpi_enable_cmd;
     uint8_t acpi_disable_cmd;
@@ -52,6 +54,7 @@ struct PcGuestInfo {
     uint16_t pvpanic_port;
     FWCfgState *fw_cfg;
     bool has_acpi_build;
+    bool has_acpi_bridge_hotplug;
 };
 
 /* parallel.c */
Signature · 1 line
MST
#3 lore raw
In reply to Michael S. Tsirkin
Quoted 5 lines · Michael S. Tsirkin

This is on top of patchset generating ACPI tables in qemu. Changes from v1:
- fixed some bugs
- fixed migration and cross version compatibility
- rebased to latest bits

Naturally, as I address review comments for the base patchset this will be rebased too.

Quoted 22 lines

Michael S. Tsirkin (2):
pci: add pci_for_each_bus
qemu: piix: PCI bridge ACPI hotplug support

 docs/specs/acpi_pci_hotplug.txt  |   8 +
 hw/acpi/piix4.c                  | 217 +++++++++++++++-----
 hw/i386/Makefile.objs            |   2 +-
 hw/i386/acpi-build.c             | 425 +++++++++++++++++++++++++++++++++++----
 hw/i386/acpi-dsdt.dsl            |  36 +++-
 hw/i386/pc_piix.c                |   3 +
 hw/i386/ssdt-pcihp.dsl           |  51 -----
 hw/i386/ssdt-pcihp.hex.generated | 108 ----------
 hw/pci/pci.c                     |  17 ++
 include/hw/i386/pc.h             |   5 +-
 include/hw/pci/pci.h             |   3 +
 11 files changed, 607 insertions(+), 268 deletions(-)
 delete mode 100644 hw/i386/ssdt-pcihp.dsl
 delete mode 100644 hw/i386/ssdt-pcihp.hex.generated
Signature · 1 line
MST