Skip to contentSkip to conversation

acpi: Make piix-specific and q35-specific code generic

PATCH In review Eduardo Habkost 4 participants 21 messages Dec 3, 2015 – Dec 7, 2015

lore
Share & tools
lore
#0 lore raw

cover acpi: Make piix-specific and q35-specific code generic

This series removes piix-specific and q35-specific code from acpi-build.c, making it generic and without direct dependencies to piix and q35 code.

This series needs to be applied after the following:
* [PATCH v3 0/6] pc: Initialization and compat function cleanup
* [PATCH V3 0/3] hw/pcie: Multi-root support for Q35
* [PATCH 00/16] pc: Eliminate struct PcGuestInfo

For reference, there's a git tree containing this series plus all the dependencies, at:
git://github.com/ehabkost/qemu-hacks.git work/acpi-decouple

Eduardo Habkost (13):
pc: Add PCMachineState::pci_host field
acpi: Remove unnecessary check for NULL pci_host
acpi: Eliminate acpi_get_i386_pci_host() function
acpi: Move DSDT info to PCMachineClass
acpi: Simplify s3/s4 property querying
acpi: Use &error_abort when getting PCI hotplug properties
acpi: Use QOM property to get CPU hotplug I/O base
acpi: Always try to init PCI hotplug I/O base
acpi: Use PCMachineState::acpi_dev to get ACPI dev
acpi: Change acpi_pci_hotplug_enabled() argument to PCMachineState
acpi: Don't use find_i440fx() when setting bsel properties intel_iommu.h: Missing sysbus.h include
acpi: Don't include q35 and piix headers

 hw/acpi/cpu_hotplug.c         |   3 +
 hw/acpi/ich9.c                |   2 +
 hw/acpi/piix4.c               |   2 +
 hw/i386/acpi-build.c          | 161 +++++++++++++-----------------------------
 hw/i386/pc_piix.c             |   4 ++
 hw/i386/pc_q35.c              |   6 ++
 hw/pci-host/piix.c            |   1 +
 include/hw/acpi/cpu_hotplug.h |   1 +
 include/hw/acpi/pc-hotplug.h  |   4 +-
 include/hw/i386/intel_iommu.h |   1 +
 include/hw/i386/pc.h          |   3 +
 11 files changed, 74 insertions(+), 114 deletions(-)
Signature · 1 line
2.1.0
#1 lore raw

PATCH 1/13 pc: Add PCMachineState::pci_host field

This will allow us to avoid direct references to piix and q35 in acpi-build.c.

---
 hw/i386/pc_q35.c     | 2 ++
 hw/pci-host/piix.c   | 1 +
 include/hw/i386/pc.h | 1 +
 3 files changed, 4 insertions(+)
hw/i386/pc_q35.c +2 -0
index 0907746..317d36a 100644
@@ -171,6 +171,8 @@ static void pc_q35_init(MachineState *machine)
     phb = PCI_HOST_BRIDGE(q35_host);
     host_bus = phb->bus;
     pcms->bus = phb->bus;
+    pcms->pci_host = phb;
+
     /* create ISA bus */
     lpc = pci_create_simple_multifunction(host_bus, PCI_DEVFN(ICH9_LPC_DEV,
                                           ICH9_LPC_FUNC), true,
hw/pci-host/piix.c +1 -0
index 715208b..7711e27 100644
@@ -335,6 +335,7 @@ PCIBus *i440fx_init(const char *host_type, const char *pci_type,
                     address_space_io, 0, TYPE_PCI_BUS);
     s->bus = b;
     object_property_add_child(qdev_get_machine(), "i440fx", OBJECT(dev), NULL);
+    PC_MACHINE(qdev_get_machine())->pci_host = s;
     qdev_init_nofail(dev);
 
     d = pci_create_simple(b, 0, pci_type);
include/hw/i386/pc.h +1 -0
index 6ff4721..8b184c1 100644
@@ -38,6 +38,7 @@ struct PCMachineState {
     OnOffAuto vmport;
     OnOffAuto smm;
     ram_addr_t below_4g_mem_size, above_4g_mem_size;
+    PCIHostState *pci_host;
     PCIBus *bus;
     Notifier machine_done;
     FWCfgState *fw_cfg;
Signature · 1 line
2.1.0
#4 lore raw

PATCH 2/13 acpi: Remove unnecessary check for NULL pci_host

In reply to Eduardo Habkost

If acpi_get_i386_pci_host() returned NULL, acpi_get_pci_info() would crash before build_ssdt() gets called. Remove unnecessary check for NULL pci_host.

---
 hw/i386/acpi-build.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
hw/i386/acpi-build.c +1 -7
index 3c7af74..20a7066 100644
@@ -1338,13 +1338,7 @@ build_ssdt(GArray *table_data, GArray *linker,
         aml_append(sb_scope, method);
 
         {
-            Object *pci_host;
-            PCIBus *bus = NULL;
-
-            pci_host = acpi_get_i386_pci_host();
-            if (pci_host) {
-                bus = PCI_HOST_BRIDGE(pci_host)->bus;
-            }
+            PCIBus *bus = PCI_HOST_BRIDGE(acpi_get_i386_pci_host())->bus;
 
             if (bus) {
                 Aml *scope = aml_scope("PCI0");
Signature · 1 line
2.1.0
#5 lore raw

PATCH 3/13 acpi: Eliminate acpi_get_i386_pci_host() function

In reply to Eduardo Habkost

We can simply use PCMachineState::pci_host directly.

---
 hw/i386/acpi-build.c | 38 +++++++-------------------------------
 1 file changed, 7 insertions(+), 31 deletions(-)
hw/i386/acpi-build.c +7 -31
index 20a7066..a595575 100644
@@ -241,32 +241,9 @@ static void acpi_get_misc_info(AcpiMiscInfo *info)
     info->applesmc_io_base = applesmc_port();
 }
 
-/*
- * Because of the PXB hosts we cannot simply query TYPE_PCI_HOST_BRIDGE.
- * On i386 arch we only have two pci hosts, so we can look only for them.
- */
-static Object *acpi_get_i386_pci_host(void)
+static void acpi_get_pci_info(PcPciInfo *info, PCMachineState *pcms)
 {
-    PCIHostState *host;
-
-    host = OBJECT_CHECK(PCIHostState,
-                        object_resolve_path("/machine/i440fx", NULL),
-                        TYPE_PCI_HOST_BRIDGE);
-    if (!host) {
-        host = OBJECT_CHECK(PCIHostState,
-                            object_resolve_path("/machine/q35", NULL),
-                            TYPE_PCI_HOST_BRIDGE);
-    }
-
-    return OBJECT(host);
-}
-
-static void acpi_get_pci_info(PcPciInfo *info)
-{
-    Object *pci_host;
-
-
-    pci_host = acpi_get_i386_pci_host();
+    Object *pci_host = OBJECT(pcms->pci_host);
     g_assert(pci_host);
 
     info->w32.begin = object_property_get_int(pci_host,
@@ -1338,7 +1315,7 @@ build_ssdt(GArray *table_data, GArray *linker,
         aml_append(sb_scope, method);
 
         {
-            PCIBus *bus = PCI_HOST_BRIDGE(acpi_get_i386_pci_host())->bus;
+            PCIBus *bus = pcms->pci_host->bus;
 
             if (bus) {
                 Aml *scope = aml_scope("PCI0");
@@ -1643,12 +1620,11 @@ struct AcpiBuildState {
     MemoryRegion *linker_mr;
 } AcpiBuildState;
 
-static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)
+static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg, PCMachineState *pcms)
 {
-    Object *pci_host;
+    Object *pci_host = OBJECT(pcms->pci_host);
     QObject *o;
 
-    pci_host = acpi_get_i386_pci_host();
     g_assert(pci_host);
 
     o = object_property_get_qobject(pci_host, PCIE_HOST_MCFG_BASE, NULL);
@@ -1694,7 +1670,7 @@ void acpi_build(PCMachineState *pcms, AcpiBuildTables *tables)
     acpi_get_pm_info(&pm);
     acpi_get_dsdt(&misc);
     acpi_get_misc_info(&misc);
-    acpi_get_pci_info(&pci);
+    acpi_get_pci_info(&pci, pcms);
 
     table_offsets = g_array_new(false, true /* clear */,
                                         sizeof(uint32_t));
@@ -1751,7 +1727,7 @@ void acpi_build(PCMachineState *pcms, AcpiBuildTables *tables)
         acpi_add_table(table_offsets, tables_blob);
         build_srat(tables_blob, tables->linker, pcms);
     }
-    if (acpi_get_mcfg(&mcfg)) {
+    if (acpi_get_mcfg(&mcfg, pcms)) {
         acpi_add_table(table_offsets, tables_blob);
         build_mcfg_q35(tables_blob, tables->linker, &mcfg);
     }
Signature · 1 line
2.1.0
#6 lore raw

PATCH 4/13 acpi: Move DSDT info to PCMachineClass

In reply to Eduardo Habkost

Remove direct dependency on q35-acpi-dsdt.hex and acpi-dsdt.hex from acpi-build.c.

---
 hw/i386/acpi-build.c | 35 +++++++----------------------------
 hw/i386/pc_piix.c    |  4 ++++
 hw/i386/pc_q35.c     |  4 ++++
 include/hw/i386/pc.h |  2 ++
 4 files changed, 17 insertions(+), 28 deletions(-)
hw/i386/acpi-build.c +7 -28
index a595575..4677e97 100644
@@ -51,9 +51,6 @@
 #include "hw/pci-host/q35.h"
 #include "hw/i386/intel_iommu.h"
 
-#include "hw/i386/q35-acpi-dsdt.hex"
-#include "hw/i386/acpi-dsdt.hex"
-
 #include "hw/acpi/aml-build.h"
 
 #include "qapi/qmp/qint.h"
@@ -108,8 +105,6 @@ typedef struct AcpiPmInfo {
 typedef struct AcpiMiscInfo {
     bool has_hpet;
     TPMVersion tpm_version;
-    const unsigned char *dsdt_code;
-    unsigned dsdt_size;
     uint16_t pvpanic_port;
     uint16_t applesmc_io_base;
 } AcpiMiscInfo;
@@ -121,22 +116,6 @@ typedef struct AcpiBuildPciBusHotplugState {
     bool pcihp_bridge_en;
 } AcpiBuildPciBusHotplugState;
 
-static void acpi_get_dsdt(AcpiMiscInfo *info)
-{
-    Object *piix = piix4_pm_find();
-    Object *lpc = ich9_lpc_find();
-    assert(!!piix != !!lpc);
-
-    if (piix) {
-        info->dsdt_code = AcpiDsdtAmlCode;
-        info->dsdt_size = sizeof AcpiDsdtAmlCode;
-    }
-    if (lpc) {
-        info->dsdt_code = Q35AcpiDsdtAmlCode;
-        info->dsdt_size = sizeof Q35AcpiDsdtAmlCode;
-    }
-}
-
 static
 int acpi_add_cpu_info(Object *o, void *opaque)
 {
@@ -1570,18 +1549,19 @@ build_dmar_q35(GArray *table_data, GArray *linker)
 }
 
 static void
-build_dsdt(GArray *table_data, GArray *linker, AcpiMiscInfo *misc)
+build_dsdt(GArray *table_data, GArray *linker, PCMachineState *pcms)
 {
+    PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
     AcpiTableHeader *dsdt;
 
-    assert(misc->dsdt_code && misc->dsdt_size);
+    assert(pcmc->dsdt_code && pcmc->dsdt_size);
 
-    dsdt = acpi_data_push(table_data, misc->dsdt_size);
-    memcpy(dsdt, misc->dsdt_code, misc->dsdt_size);
+    dsdt = acpi_data_push(table_data, pcmc->dsdt_size);
+    memcpy(dsdt, pcmc->dsdt_code, pcmc->dsdt_size);
 
     memset(dsdt, 0, sizeof *dsdt);
     build_header(linker, table_data, dsdt, "DSDT",
-                 misc->dsdt_size, 1);
+                 pcmc->dsdt_size, 1);
 }
 
 static GArray *
@@ -1668,7 +1648,6 @@ void acpi_build(PCMachineState *pcms, AcpiBuildTables *tables)
 
     acpi_get_cpu_info(&cpu);
     acpi_get_pm_info(&pm);
-    acpi_get_dsdt(&misc);
     acpi_get_misc_info(&misc);
     acpi_get_pci_info(&pci, pcms);
 
@@ -1690,7 +1669,7 @@ void acpi_build(PCMachineState *pcms, AcpiBuildTables *tables)
 
     /* DSDT is pointed to by FADT */
     dsdt = tables_blob->len;
-    build_dsdt(tables_blob, tables->linker, &misc);
+    build_dsdt(tables_blob, tables->linker, pcms);
 
     /* Count the size of the DSDT and SSDT, we will need it for legacy
      * sizing of ACPI tables.
hw/i386/pc_piix.c +4 -0
index f0c2dc8..f4e03b5 100644
@@ -53,6 +53,7 @@
 #include "hw/xen/xen_pt.h"
 #endif
 #include "migration/migration.h"
+#include "hw/i386/acpi-dsdt.hex"
 
 #define MAX_IDE_BUS 2
 
@@ -402,11 +403,14 @@ static void pc_xen_hvm_init(MachineState *machine)
 
 static void pc_i440fx_machine_options(MachineClass *m)
 {
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     m->family = "pc_piix";
     m->desc = "Standard PC (i440FX + PIIX, 1996)";
     m->hot_add_cpu = pc_hot_add_cpu;
     m->default_machine_opts = "firmware=bios-256k.bin";
     m->default_display = "std";
+    pcmc->dsdt_code = AcpiDsdtAmlCode;
+    pcmc->dsdt_size = sizeof AcpiDsdtAmlCode;
 }
 
 static void pc_i440fx_2_5_machine_options(MachineClass *m)
hw/i386/pc_q35.c +4 -0
index 317d36a..37d4e8c 100644
@@ -45,6 +45,7 @@
 #include "hw/usb.h"
 #include "qemu/error-report.h"
 #include "migration/migration.h"
+#include "hw/i386/q35-acpi-dsdt.hex"
 
 /* ICH9 AHCI has 6 ports */
 #define MAX_SATA_PORTS     6
@@ -328,6 +329,7 @@ static void pc_compat_1_4(MachineState *machine)
 
 static void pc_q35_machine_options(MachineClass *m)
 {
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     m->family = "pc_q35";
     m->desc = "Standard PC (Q35 + ICH9, 2009)";
     m->hot_add_cpu = pc_hot_add_cpu;
@@ -336,6 +338,8 @@ static void pc_q35_machine_options(MachineClass *m)
     m->default_display = "std";
     m->no_floppy = 1;
     m->no_tco = 0;
+    pcmc->dsdt_code = Q35AcpiDsdtAmlCode;
+    pcmc->dsdt_size = sizeof Q35AcpiDsdtAmlCode;
 }
 
 static void pc_q35_2_5_machine_options(MachineClass *m)
include/hw/i386/pc.h +2 -0
index 8b184c1..e09fb98 100644
@@ -89,6 +89,8 @@ struct PCMachineClass {
      */
     unsigned acpi_data_size;
     bool enforce_aligned_dimm;
+    const unsigned char *dsdt_code;
+    unsigned dsdt_size;
 };
 
 #define TYPE_PC_MACHINE "generic-pc-machine"
Signature · 1 line
2.1.0
#7 lore raw

PATCH 5/13 acpi: Simplify s3/s4 property querying

In reply to Eduardo Habkost

object_property_get_bool() already returns false when the property is not present, there's no need to call object_property_get_qobject() manually.

---
 hw/i386/acpi-build.c | 32 +++++++++-----------------------
 1 file changed, 9 insertions(+), 23 deletions(-)
hw/i386/acpi-build.c +9 -23
index 4677e97..9a45a59 100644
@@ -146,7 +146,6 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
     Object *piix = piix4_pm_find();
     Object *lpc = ich9_lpc_find();
     Object *obj = NULL;
-    QObject *o;
 
     pm->cpu_hp_io_base = 0;
     pm->pcihp_io_base = 0;
@@ -169,28 +168,15 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
     pm->mem_hp_io_base = ACPI_MEMORY_HOTPLUG_BASE;
     pm->mem_hp_io_len = ACPI_MEMORY_HOTPLUG_IO_LEN;
 
-    /* Fill in optional s3/s4 related properties */
-    o = object_property_get_qobject(obj, ACPI_PM_PROP_S3_DISABLED, NULL);
-    if (o) {
-        pm->s3_disabled = qint_get_int(qobject_to_qint(o));
-    } else {
-        pm->s3_disabled = false;
-    }
-    qobject_decref(o);
-    o = object_property_get_qobject(obj, ACPI_PM_PROP_S4_DISABLED, NULL);
-    if (o) {
-        pm->s4_disabled = qint_get_int(qobject_to_qint(o));
-    } else {
-        pm->s4_disabled = false;
-    }
-    qobject_decref(o);
-    o = object_property_get_qobject(obj, ACPI_PM_PROP_S4_VAL, NULL);
-    if (o) {
-        pm->s4_val = qint_get_int(qobject_to_qint(o));
-    } else {
-        pm->s4_val = false;
-    }
-    qobject_decref(o);
+    /* Fill in optional s3/s4 related properties
+     * (default to false if property is not present)
+     */
+    pm->s3_disabled =
+        object_property_get_bool(obj, ACPI_PM_PROP_S3_DISABLED, NULL);
+    pm->s4_disabled =
+        object_property_get_bool(obj, ACPI_PM_PROP_S4_DISABLED, NULL);
+    pm->s4_val =
+        object_property_get_bool(obj, ACPI_PM_PROP_S4_VAL, NULL);
 
     /* Fill in mandatory properties */
     pm->sci_int = object_property_get_int(obj, ACPI_PM_PROP_SCI_INT, NULL);
Signature · 1 line
2.1.0
#8 lore raw

PATCH 6/13 acpi: Use &error_abort when getting PCI hotplug properties

In reply to Eduardo Habkost

The properties must be present, so use &error_abort to ensure we don't ignore errors.

---
 hw/i386/acpi-build.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/i386/acpi-build.c +4 -2
index 9a45a59..4f42e28 100644
@@ -154,9 +154,11 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
         obj = piix;
         pm->cpu_hp_io_base = PIIX4_CPU_HOTPLUG_IO_BASE;
         pm->pcihp_io_base =
-            object_property_get_int(obj, ACPI_PCIHP_IO_BASE_PROP, NULL);
+            object_property_get_int(obj, ACPI_PCIHP_IO_BASE_PROP,
+                                    &error_abort);
         pm->pcihp_io_len =
-            object_property_get_int(obj, ACPI_PCIHP_IO_LEN_PROP, NULL);
+            object_property_get_int(obj, ACPI_PCIHP_IO_LEN_PROP,
+                                    &error_abort);
     }
     if (lpc) {
         obj = lpc;
Signature · 1 line
2.1.0
#9 lore raw

PATCH 7/13 acpi: Use QOM property to get CPU hotplug I/O base

In reply to Eduardo Habkost

Instead of hardcoding the ich9 and piix I/O bases, use a QOM property, the same way we already do for PCI hotplug I/O base.

---
 hw/acpi/cpu_hotplug.c         | 3 +++
 hw/acpi/ich9.c                | 2 ++
 hw/acpi/piix4.c               | 2 ++
 hw/i386/acpi-build.c          | 5 ++---
 include/hw/acpi/cpu_hotplug.h | 1 +
 include/hw/acpi/pc-hotplug.h  | 4 ++--
 6 files changed, 12 insertions(+), 5 deletions(-)
hw/acpi/cpu_hotplug.c +3 -0
index f5b9972..6d4d7c1 100644
@@ -73,4 +73,7 @@ void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
     memory_region_init_io(&gpe_cpu->io, owner, &AcpiCpuHotplug_ops,
                           gpe_cpu, "acpi-cpu-hotplug", ACPI_GPE_PROC_LEN);
     memory_region_add_subregion(parent, base, &gpe_cpu->io);
+    gpe_cpu->base = base;
+    object_property_add_uint16_ptr(owner, ACPI_CPUHP_IO_BASE_PROP,
+                                   &gpe_cpu->base, &error_abort);
 }
hw/acpi/ich9.c +2 -0
index 1c7fcfa..aa30c3e 100644
@@ -46,6 +46,8 @@ do { printf("%s "fmt, __func__, ## __VA_ARGS__); } while (0)
 #define ICH9_DEBUG(fmt, ...)    do { } while (0)
 #endif
 
+#define ICH9_CPU_HOTPLUG_IO_BASE 0x0CD8
+
 static void ich9_pm_update_sci_fn(ACPIREGS *regs)
 {
     ICH9LPCPMRegs *pm = container_of(regs, ICH9LPCPMRegs, acpi_regs);
hw/acpi/piix4.c +2 -0
index 2cd2fee..e4393fd 100644
@@ -46,6 +46,8 @@
 # define PIIX4_DPRINTF(format, ...)     do { } while (0)
 #endif
 
+#define PIIX4_CPU_HOTPLUG_IO_BASE 0xaf00
+
 #define GPE_BASE 0xafe0
 #define GPE_LEN 4
 
hw/i386/acpi-build.c +2 -3
index 4f42e28..6774ced 100644
@@ -147,12 +147,10 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
     Object *lpc = ich9_lpc_find();
     Object *obj = NULL;
 
-    pm->cpu_hp_io_base = 0;
     pm->pcihp_io_base = 0;
     pm->pcihp_io_len = 0;
     if (piix) {
         obj = piix;
-        pm->cpu_hp_io_base = PIIX4_CPU_HOTPLUG_IO_BASE;
         pm->pcihp_io_base =
             object_property_get_int(obj, ACPI_PCIHP_IO_BASE_PROP,
                                     &error_abort);
@@ -162,10 +160,11 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
     }
     if (lpc) {
         obj = lpc;
-        pm->cpu_hp_io_base = ICH9_CPU_HOTPLUG_IO_BASE;
     }
     assert(obj);
 
+    pm->cpu_hp_io_base =
+        object_property_get_int(obj, ACPI_CPUHP_IO_BASE_PROP, &error_abort);
     pm->cpu_hp_io_len = ACPI_GPE_PROC_LEN;
     pm->mem_hp_io_base = ACPI_MEMORY_HOTPLUG_BASE;
     pm->mem_hp_io_len = ACPI_MEMORY_HOTPLUG_IO_LEN;
include/hw/acpi/cpu_hotplug.h +1 -0
index f6d358d..0e1dd99 100644
@@ -16,6 +16,7 @@
 #include "hw/acpi/pc-hotplug.h"
 
 typedef struct AcpiCpuHotplug {
+    uint16_t base;
     MemoryRegion io;
     uint8_t sts[ACPI_GPE_PROC_LEN];
 } AcpiCpuHotplug;
include/hw/acpi/pc-hotplug.h +2 -2
index 77b1569..f4b006c 100644
@@ -25,8 +25,8 @@
 /* 256 CPU IDs, 8 bits per entry: */
 #define ACPI_GPE_PROC_LEN 32
 
-#define ICH9_CPU_HOTPLUG_IO_BASE 0x0CD8
-#define PIIX4_CPU_HOTPLUG_IO_BASE 0xaf00
+#define ACPI_CPUHP_IO_BASE_PROP "acpi-cpuhp-io-base"
+
 #define CPU_HOTPLUG_RESOURCE_DEVICE PRES
 
 #define ACPI_MEMORY_HOTPLUG_IO_LEN 24
Signature · 1 line
2.1.0
#10 lore raw

PATCH 8/13 acpi: Always try to init PCI hotplug I/O base

In reply to Eduardo Habkost

Instead of making pcihp_io_base/pcihp_io_len initialization specific to piix4, just check if ACPI_PCIHP_IO_BASE_PROP property is present.

No behavior is changed, as only piix4 initializes the ACPI_PCIHP_IO_BASE_PROP property today.

---
 hw/i386/acpi-build.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
hw/i386/acpi-build.c +12 -4
index 6774ced..617cd53 100644
@@ -141,6 +141,11 @@ static void acpi_get_cpu_info(AcpiCpuInfo *cpu)
     object_child_foreach(root, acpi_add_cpu_info, cpu);
 }
 
+static bool acpi_pci_hotplug_enabled(Object *acpi_dev)
+{
+    return object_property_find(acpi_dev, ACPI_PCIHP_IO_BASE_PROP, NULL);
+}
+
 static void acpi_get_pm_info(AcpiPmInfo *pm)
 {
     Object *piix = piix4_pm_find();
@@ -151,6 +156,13 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
     pm->pcihp_io_len = 0;
     if (piix) {
         obj = piix;
+    }
+    if (lpc) {
+        obj = lpc;
+    }
+    assert(obj);
+
+    if (acpi_pci_hotplug_enabled(obj)) {
         pm->pcihp_io_base =
             object_property_get_int(obj, ACPI_PCIHP_IO_BASE_PROP,
                                     &error_abort);
@@ -158,10 +170,6 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
             object_property_get_int(obj, ACPI_PCIHP_IO_LEN_PROP,
                                     &error_abort);
     }
-    if (lpc) {
-        obj = lpc;
-    }
-    assert(obj);
 
     pm->cpu_hp_io_base =
         object_property_get_int(obj, ACPI_CPUHP_IO_BASE_PROP, &error_abort);
Signature · 1 line
2.1.0
#12 lore raw

PATCH 10/13 acpi: Change acpi_pci_hotplug_enabled() argument to PCMachineState

In reply to Eduardo Habkost

Now that we just use PCMachineState::acpi_dev, we can change the argument to acpi_pci_hotplug_enabled().

---
 hw/i386/acpi-build.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/i386/acpi-build.c +4 -3
index 440d4e2..585100f 100644
@@ -141,9 +141,10 @@ static void acpi_get_cpu_info(AcpiCpuInfo *cpu)
     object_child_foreach(root, acpi_add_cpu_info, cpu);
 }
 
-static bool acpi_pci_hotplug_enabled(Object *acpi_dev)
+static bool acpi_pci_hotplug_enabled(PCMachineState *pcms)
 {
-    return object_property_find(acpi_dev, ACPI_PCIHP_IO_BASE_PROP, NULL);
+    return object_property_find(OBJECT(pcms->acpi_dev),
+                                ACPI_PCIHP_IO_BASE_PROP, NULL);
 }
 
 static void acpi_get_pm_info(AcpiPmInfo *pm, PCMachineState *pcms)
@@ -154,7 +155,7 @@ static void acpi_get_pm_info(AcpiPmInfo *pm, PCMachineState *pcms)
     pm->pcihp_io_base = 0;
     pm->pcihp_io_len = 0;
 
-    if (acpi_pci_hotplug_enabled(obj)) {
+    if (acpi_pci_hotplug_enabled(pcms)) {
         pm->pcihp_io_base =
             object_property_get_int(obj, ACPI_PCIHP_IO_BASE_PROP,
                                     &error_abort);
Signature · 1 line
2.1.0
#11 lore raw

PATCH 9/13 acpi: Use PCMachineState::acpi_dev to get ACPI dev

In reply to Eduardo Habkost

Instead of calling piix4_pm_find() and ich9_lpc_find(), simply use PCMachineState::acpi_dev to get the object containing the ACPI-related properties.

---
 hw/i386/acpi-build.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
hw/i386/acpi-build.c +4 -12
index 617cd53..440d4e2 100644
@@ -146,21 +146,13 @@ static bool acpi_pci_hotplug_enabled(Object *acpi_dev)
     return object_property_find(acpi_dev, ACPI_PCIHP_IO_BASE_PROP, NULL);
 }
 
-static void acpi_get_pm_info(AcpiPmInfo *pm)
+static void acpi_get_pm_info(AcpiPmInfo *pm, PCMachineState *pcms)
 {
-    Object *piix = piix4_pm_find();
-    Object *lpc = ich9_lpc_find();
-    Object *obj = NULL;
+    Object *obj = OBJECT(pcms->acpi_dev);
 
+    assert(obj);
     pm->pcihp_io_base = 0;
     pm->pcihp_io_len = 0;
-    if (piix) {
-        obj = piix;
-    }
-    if (lpc) {
-        obj = lpc;
-    }
-    assert(obj);
 
     if (acpi_pci_hotplug_enabled(obj)) {
         pm->pcihp_io_base =
@@ -1642,7 +1634,7 @@ void acpi_build(PCMachineState *pcms, AcpiBuildTables *tables)
     GArray *tables_blob = tables->table_data;
 
     acpi_get_cpu_info(&cpu);
-    acpi_get_pm_info(&pm);
+    acpi_get_pm_info(&pm, pcms);
     acpi_get_misc_info(&misc);
     acpi_get_pci_info(&pci, pcms);
 
Signature · 1 line
2.1.0
#14 lore raw

PATCH 12/13 intel_iommu.h: Missing sysbus.h include

In reply to Eduardo Habkost

intel_iommu.h uses SysBusDevice. This never caused any problems before because all files including intel_iommu.h were already including sysbus.h.

---
 include/hw/i386/intel_iommu.h | 1 +
 1 file changed, 1 insertion(+)
include/hw/i386/intel_iommu.h +1 -0
index 5dbadb7..e175000 100644
@@ -21,6 +21,7 @@
 
 #ifndef INTEL_IOMMU_H
 #define INTEL_IOMMU_H
+#include "hw/sysbus.h"
 #include "hw/qdev.h"
 #include "sysemu/dma.h"
 
Signature · 1 line
2.1.0
#13 lore raw

PATCH 11/13 acpi: Don't use find_i440fx() when setting bsel properties

In reply to Eduardo Habkost

Instead of checking for i440fx, the code can simply check if the machine has ACPI PCI hotplug enabled.

---
 hw/i386/acpi-build.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/i386/acpi-build.c +4 -4
index 585100f..048967e 100644
@@ -397,12 +397,12 @@ static void *acpi_set_bsel(PCIBus *bus, void *opaque)
     return bsel_alloc;
 }
 
-static void acpi_set_pci_info(void)
+static void acpi_set_pci_info(PCMachineState *pcms)
 {
-    PCIBus *bus = find_i440fx(); /* TODO: Q35 support */
+    PCIBus *bus = pcms->bus;
     unsigned bsel_alloc = 0;
 
-    if (bus) {
+    if (acpi_pci_hotplug_enabled(pcms) && bus) {
         /* Scan all PCI buses. Set property to enable acpi based hotplug. */
         pci_for_each_bus_depth_first(bus, acpi_set_bsel, NULL, &bsel_alloc);
     }
@@ -1855,7 +1855,7 @@ void acpi_setup(PCMachineState *pcms)
 
     build_state->pcms = pcms;
 
-    acpi_set_pci_info();
+    acpi_set_pci_info(pcms);
 
     acpi_build_tables_init(&tables);
     acpi_build(build_state->pcms, &tables);
Signature · 1 line
2.1.0
#15 lore raw

PATCH 13/13 acpi: Don't include q35 and piix headers

In reply to Eduardo Habkost

The ACPI code doesn't need to include q35 and piix headers anymore, as the code is generic have no piix-specific or q35-specific parts.

---
 hw/i386/acpi-build.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/i386/acpi-build.c +4 -4
index 048967e..d27ea67 100644
@@ -28,6 +28,9 @@
 #include "qemu/osdep.h"
 #include "qemu/error-report.h"
 #include "hw/pci/pci.h"
+#include "hw/pci/pci_bridge.h"
+#include "hw/pci/pci_host.h"
+#include "hw/pci/pcie_host.h"
 #include "qom/cpu.h"
 #include "hw/i386/pc.h"
 #include "target-i386/cpu.h"
@@ -43,12 +46,9 @@
 #include "hw/acpi/tpm.h"
 #include "sysemu/tpm_backend.h"
 
-/* Supported chipsets: */
-#include "hw/acpi/piix4.h"
+#include "hw/acpi/pc-hotplug.h"
 #include "hw/acpi/pcihp.h"
-#include "hw/i386/ich9.h"
 #include "hw/pci/pci_bus.h"
-#include "hw/pci-host/q35.h"
 #include "hw/i386/intel_iommu.h"
 
 #include "hw/acpi/aml-build.h"
Signature · 1 line
2.1.0
#16 lore raw
In reply to Eduardo Habkost
Quoted 3 lines · On Wed, 2 Dec 2015 20:22:45 -0200 Eduardo Habkost <[email protected]> wrote:

This series removes piix-specific and q35-specific code from acpi-build.c, making it generic and without direct dependencies to piix and q35 code.

we are conflicting reshuffling acpi-build.c at the same time could be cleanup done on top of my refactoring drop_ASL_support_v1 branch:

https://github.com/imammedo/qemu/commits/drop_ASL_support_v1

Quoted 37 lines

This series needs to be applied after the following:
* [PATCH v3 0/6] pc: Initialization and compat function cleanup
* [PATCH V3 0/3] hw/pcie: Multi-root support for Q35
* [PATCH 00/16] pc: Eliminate struct PcGuestInfo

For reference, there's a git tree containing this series plus all the dependencies, at:
git://github.com/ehabkost/qemu-hacks.git work/acpi-decouple

Eduardo Habkost (13):
pc: Add PCMachineState::pci_host field
acpi: Remove unnecessary check for NULL pci_host
acpi: Eliminate acpi_get_i386_pci_host() function
acpi: Move DSDT info to PCMachineClass
acpi: Simplify s3/s4 property querying
acpi: Use &error_abort when getting PCI hotplug properties
acpi: Use QOM property to get CPU hotplug I/O base
acpi: Always try to init PCI hotplug I/O base
acpi: Use PCMachineState::acpi_dev to get ACPI dev
acpi: Change acpi_pci_hotplug_enabled() argument to PCMachineState
acpi: Don't use find_i440fx() when setting bsel properties intel_iommu.h: Missing sysbus.h include
acpi: Don't include q35 and piix headers

 hw/acpi/cpu_hotplug.c         |   3 +
 hw/acpi/ich9.c                |   2 +
 hw/acpi/piix4.c               |   2 +
 hw/i386/acpi-build.c          | 161 +++++++++++++-----------------------------
 hw/i386/pc_piix.c             |   4 ++
 hw/i386/pc_q35.c              |   6 ++
 hw/pci-host/piix.c            |   1 +
 include/hw/acpi/cpu_hotplug.h |   1 +
 include/hw/acpi/pc-hotplug.h  |   4 +-
 include/hw/i386/intel_iommu.h |   1 +
 include/hw/i386/pc.h          |   3 +
 11 files changed, 74 insertions(+), 114 deletions(-)
#2 lore raw

Re: [Qemu-devel] [PATCH 01/13] pc: Add PCMachineState::pci_host field

In reply to Eduardo Habkost
Quoted 40 lines · Eduardo Habkost

This will allow us to avoid direct references to piix and q35 in acpi-build.c.

---
  hw/i386/pc_q35.c     | 2 ++
  hw/pci-host/piix.c   | 1 +
  include/hw/i386/pc.h | 1 +
  3 files changed, 4 insertions(+)
hw/i386/pc_q35.c +2 -0
index 0907746..317d36a 100644
@@ -171,6 +171,8 @@ static void pc_q35_init(MachineState *machine)
      phb = PCI_HOST_BRIDGE(q35_host);
      host_bus = phb->bus;
      pcms->bus = phb->bus;
+    pcms->pci_host = phb;
+
      /* create ISA bus */
      lpc = pci_create_simple_multifunction(host_bus, PCI_DEVFN(ICH9_LPC_DEV,
                                            ICH9_LPC_FUNC), true,
hw/pci-host/piix.c +1 -0
index 715208b..7711e27 100644
@@ -335,6 +335,7 @@ PCIBus *i440fx_init(const char *host_type, const char *pci_type,
                      address_space_io, 0, TYPE_PCI_BUS);
      s->bus = b;
      object_property_add_child(qdev_get_machine(), "i440fx", OBJECT(dev), NULL);
+    PC_MACHINE(qdev_get_machine())->pci_host = s;
      qdev_init_nofail(dev);
 
      d = pci_create_simple(b, 0, pci_type);
include/hw/i386/pc.h +0 -0
index 6ff4721..8b184c1 100644

include/hw/i386/pc.h struct PCMachineState { · line 41

Quoted 4 lines
include/hw/i386/pc.h +1 -0
@@ -38,6 +38,7 @@ struct PCMachineState {
      OnOffAuto vmport;
      OnOffAuto smm;
      ram_addr_t below_4g_mem_size, above_4g_mem_size;
+    PCIHostState *pci_host;

Having both pci_host and bus as class fields is not needed. If you have the host, maybe you can get rid of the bus.

Thanks,
Marcel

Quoted 4 lines
include/hw/i386/pc.h +0 -0
      PCIBus *bus;
      Notifier machine_done;
      FWCfgState *fw_cfg;
#3 lore raw

Re: [Qemu-devel] [PATCH 01/13] pc: Add PCMachineState::pci_host field

Quoted 5 lines · Marcel Apfelbaum
Quoted 4 lines · Eduardo Habkost

This will allow us to avoid direct references to piix and q35 in acpi-build.c.

[...]

Quoted 4 lines
Quoted 4 lines
include/hw/i386/pc.h +0 -0
index 6ff4721..8b184c1 100644
Quoted 8 lines

include/hw/i386/pc.h struct PCMachineState { · line 41

Quoted 5 lines
include/hw/i386/pc.h +1 -0
@@ -38,6 +38,7 @@ struct PCMachineState {
     OnOffAuto vmport;
     OnOffAuto smm;
     ram_addr_t below_4g_mem_size, above_4g_mem_size;
+    PCIHostState *pci_host;

Having both pci_host and bus as class fields is not needed. If you have the host, maybe you can get rid of the bus.

Yes, I will send that as folllow-up.

Signature · 1 line
Eduardo
#17 lore raw
In reply to Igor Mammedov
Quoted 11 lines · Igor Mammedov
Quoted 3 lines · On Wed, 2 Dec 2015 20:22:45 -0200 Eduardo Habkost <[email protected]> wrote:

This series removes piix-specific and q35-specific code from acpi-build.c, making it generic and without direct dependencies to piix and q35 code.

we are conflicting reshuffling acpi-build.c at the same time could be cleanup done on top of my refactoring drop_ASL_support_v1 branch:

https://github.com/imammedo/qemu/commits/drop_ASL_support_v1

Do you plan to submit it soon?

It looks like my series and yours go in opposite directions. I am trying to remove piix4-specific code from acpi-build, and you are addding a is_piix4 field to AcpiMiscInfo. Your series makes much more difficult to remove piix4-specific code from acpi-build.c, but this sounds like a reasonable price for moving the dsdt.dsl logic to C. Maybe I should change my goal from "removing piix4-specific code" to just simplifying the code.

I will redo this series on top of yours, taking that into account.

There are a few conflicts with the other series, but they are very easy to solve:

Quoted 2 lines
Quoted 2 lines

This series needs to be applied after the following:
* [PATCH v3 0/6] pc: Initialization and compat function cleanup

No conflicts.

Quoted 1 line
Quoted 1 line

* [PATCH V3 0/3] hw/pcie: Multi-root support for Q35

Trivial conflict at crs_range_merge().

Quoted 1 line
Quoted 1 line

* [PATCH 00/16] pc: Eliminate struct PcGuestInfo

Simple conflict at build_ssdt().

Signature · 1 line
Eduardo
#18 lore raw
Quoted 7 lines · On Thu, 3 Dec 2015 15:16:21 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 6 lines · Igor Mammedov
Quoted 3 lines · On Wed, 2 Dec 2015 20:22:45 -0200 Eduardo Habkost <[email protected]> wrote:

This series removes piix-specific and q35-specific code from acpi-build.c, making it generic and without direct dependencies to piix and q35 code.

Quoted 7 lines
Quoted 5 lines

we are conflicting reshuffling acpi-build.c at the same time could be cleanup done on top of my refactoring drop_ASL_support_v1 branch:

https://github.com/imammedo/qemu/commits/drop_ASL_support_v1

Do you plan to submit it soon?

I plan to submit it as soon as 2.5 is released since Michael is busy with 2.5 and possibly the only reviewer.
But if it help I can submit it earlier and add you in CC.

Quoted 8 lines

It looks like my series and yours go in opposite directions. I am trying to remove piix4-specific code from acpi-build, and you are addding a is_piix4 field to AcpiMiscInfo. Your series makes much more difficult to remove piix4-specific code from acpi-build.c, but this sounds like a reasonable price for moving the dsdt.dsl logic to C. Maybe I should change my goal from "removing piix4-specific code" to just simplifying the code.

It should be ok to remove explicit detection of piix4/q35 from acpi-build.c, what I wouldn't wish though is to pull ACPI deps into boards codebase. What we have in acpi-build.c is mostly firmware generation code and it would be better to keep it there.

After merging refactoring, I plan to simplify it by moving out generic memory/cpu hotplug parts into hw/acpi/,
but the rest of DSDT will probably stay there and we can merge SSDT into DSDT which also should help to simplify it.

But for now it's dumb refactoring which is byte compatible with DSDTs we have in ASL to avoid regressions in such huge series.

Quoted 3 lines

I will redo this series on top of yours, taking that into account.

Thanks!

Quoted 17 lines

There are a few conflicts with the other series, but they are very easy to solve:

Quoted 2 lines
Quoted 2 lines

This series needs to be applied after the following:
* [PATCH v3 0/6] pc: Initialization and compat function cleanup

No conflicts.

Quoted 1 line
Quoted 1 line

* [PATCH V3 0/3] hw/pcie: Multi-root support for Q35

Trivial conflict at crs_range_merge().

Quoted 1 line
Quoted 1 line

* [PATCH 00/16] pc: Eliminate struct PcGuestInfo

Simple conflict at build_ssdt().

#19 lore raw
Quoted 14 lines · Igor Mammedov
Quoted 11 lines · On Thu, 3 Dec 2015 15:16:21 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 10 lines · Igor Mammedov
Quoted 3 lines · On Wed, 2 Dec 2015 20:22:45 -0200 Eduardo Habkost <[email protected]> wrote:

This series removes piix-specific and q35-specific code from acpi-build.c, making it generic and without direct dependencies to piix and q35 code.

we are conflicting reshuffling acpi-build.c at the same time could be cleanup done on top of my refactoring drop_ASL_support_v1 branch:

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

https://github.com/imammedo/qemu/commits/drop_ASL_support_v1

Do you plan to submit it soon?

I plan to submit it as soon as 2.5 is released since Michael is busy with 2.5 and possibly the only reviewer.
But if it help I can submit it earlier and add you in CC.

I have been submitting for-2.6 patches, already. It helps get the patches reviewed earlier so they have a chance to get applied as soon as 2.5 is released.

Quoted 9 lines
Quoted 9 lines

It looks like my series and yours go in opposite directions. I am trying to remove piix4-specific code from acpi-build, and you are addding a is_piix4 field to AcpiMiscInfo. Your series makes much more difficult to remove piix4-specific code from acpi-build.c, but this sounds like a reasonable price for moving the dsdt.dsl logic to C. Maybe I should change my goal from "removing piix4-specific code" to just simplifying the code.

Quoted 4 lines

It should be ok to remove explicit detection of piix4/q35 from acpi-build.c, what I wouldn't wish though is to pull ACPI deps into boards codebase. What we have in acpi-build.c is mostly firmware generation code and it would be better to keep it there.

Agreed. And your refactoring makes the piix4/q35 differences much more visible.

After making the piix4/q35 differences visible, I wonder if we could make the reason for each "if (piix4)" line clearer. For example, I assume some of the "if (piix4)" lines could become "if (acpi_pci_hotplug_enabled())", but I don't know which ones.

Quoted 8 lines

After merging refactoring, I plan to simplify it by moving out generic memory/cpu hotplug parts into hw/acpi/,
but the rest of DSDT will probably stay there and we can merge SSDT into DSDT which also should help to simplify it.

But for now it's dumb refactoring which is byte compatible with DSDTs we have in ASL to avoid regressions in such huge series.

I will let you make the cleanups you are planning, first. After that is settled, I will check which of the patches in this series still make sense. My original plan was to only suggest 1 or 2 simple cleanups after a discussion with Marcel. :)

Signature · 1 line
Eduardo
#20 lore raw
Quoted 3 lines · Eduardo Habkost
Quoted 2 lines · Igor Mammedov

On Thu, 3 Dec 2015 15:16:21 -0200
Eduardo Habkost <[email protected]> wrote:

[..]

Quoted 3 lines

I will let you make the cleanups you are planning, first. After that is settled, I will check which of the patches in this series still make sense.

I was planning to try and review the series, however after reading this, the smart thing to do now is wait ... :)

Thanks,
Marcel

My original plan was to only suggest 1 or 2

Quoted 2 lines

simple cleanups after a discussion with Marcel. :)