Skip to contentSkip to conversation

Add ACPI and SMBIOS tables for IPMI

PATCH New [email protected] 1 participant 6 messages May 13, 2016

lore
Share & tools
lore
#2 lore raw

PATCH v3 2/6 pc: Postpone SMBIOS table installation to post machine init

In reply to [email protected]

From: Corey Minyard <[email protected]>

This is the same place that the ACPI SSDT table gets added, so that devices can add themselves to the SMBIOS table.

---
 hw/i386/pc.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
hw/i386/pc.c +6 -5
index 99437e0..5e78ef4 100644
@@ -764,8 +764,6 @@ static FWCfgState *bochs_bios_init(AddressSpace *as, PCMachineState *pcms)
                      acpi_tables, acpi_tables_len);
     fw_cfg_add_i32(fw_cfg, FW_CFG_IRQ0_OVERRIDE, kvm_allows_irq0_override());
 
-    pc_build_smbios(fw_cfg);
-
     fw_cfg_add_bytes(fw_cfg, FW_CFG_E820_TABLE,
                      &e820_reserve, sizeof(e820_reserve));
     fw_cfg_add_file(fw_cfg, "etc/e820", e820_table,
@@ -1161,6 +1159,7 @@ void pc_machine_done(Notifier *notifier, void *data)
 {
     PCMachineState *pcms = container_of(notifier,
                                         PCMachineState, machine_done);
+    FWCfgState *fw_cfg = pcms->fw_cfg;
     PCIBus *bus = pcms->bus;
 
     if (bus) {
@@ -1172,15 +1171,17 @@ void pc_machine_done(Notifier *notifier, void *data)
                 extra_hosts++;
             }
         }
-        if (extra_hosts && pcms->fw_cfg) {
+        if (extra_hosts && fw_cfg) {
             uint64_t *val = g_malloc(sizeof(*val));
             *val = cpu_to_le64(extra_hosts);
-            fw_cfg_add_file(pcms->fw_cfg,
-                    "etc/extra-pci-roots", val, sizeof(*val));
+            fw_cfg_add_file(fw_cfg, "etc/extra-pci-roots", val, sizeof(*val));
         }
     }
 
     acpi_setup();
+    if (fw_cfg) {
+        pc_build_smbios(fw_cfg);
+    }
 }
 
 void pc_guest_info_init(PCMachineState *pcms)
Signature · 1 line
2.7.4
#3 lore raw

PATCH v3 3/6 smbios: Move table build tools into an include file.

In reply to [email protected]

From: Corey Minyard <[email protected]>

This will let things in other files (like IPMI) build SMBIOS tables.

---
 hw/smbios/smbios.c       | 70 ++++---------------------------------------
 hw/smbios/smbios_build.h | 77 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+), 64 deletions(-)
 create mode 100644 hw/smbios/smbios_build.h
hw/smbios/smbios.c +6 -64
index cb8a111..5dc3e43 100644
@@ -24,6 +24,7 @@
 #include "hw/smbios/smbios.h"
 #include "hw/loader.h"
 #include "exec/cpu-common.h"
+#include "smbios_build.h"
 
 /* legacy structures and constants for <= 2.0 machines */
 struct smbios_header {
@@ -53,10 +54,10 @@ static bool smbios_uuid_encoded = true;
 /* end: legacy structures & constants for <= 2.0 machines */
 
 
-static uint8_t *smbios_tables;
-static size_t smbios_tables_len;
-static unsigned smbios_table_max;
-static unsigned smbios_table_cnt;
+uint8_t *smbios_tables;
+size_t smbios_tables_len;
+unsigned smbios_table_max;
+unsigned smbios_table_cnt;
 static SmbiosEntryPointType smbios_ep_type = SMBIOS_ENTRY_POINT_21;
 
 static SmbiosEntryPoint ep;
@@ -429,7 +430,7 @@ uint8_t *smbios_get_table_legacy(size_t *length)
 /* end: legacy setup functions for <= 2.0 machines */
 
 
-static bool smbios_skip_table(uint8_t type, bool required_table)
+bool smbios_skip_table(uint8_t type, bool required_table)
 {
     if (test_bit(type, have_binfile_bitmap)) {
         return true; /* user provided their own binary blob(s) */
@@ -443,65 +444,6 @@ static bool smbios_skip_table(uint8_t type, bool required_table)
     return true;
 }
 
-#define SMBIOS_BUILD_TABLE_PRE(tbl_type, tbl_handle, tbl_required)        \
-    struct smbios_type_##tbl_type *t;                                     \
-    size_t t_off; /* table offset into smbios_tables */                   \
-    int str_index = 0;                                                    \
-    do {                                                                  \
-        /* should we skip building this table ? */                        \
-        if (smbios_skip_table(tbl_type, tbl_required)) {                  \
-            return;                                                       \
-        }                                                                 \
-                                                                          \
-        /* use offset of table t within smbios_tables */                  \
-        /* (pointer must be updated after each realloc) */                \
-        t_off = smbios_tables_len;                                        \
-        smbios_tables_len += sizeof(*t);                                  \
-        smbios_tables = g_realloc(smbios_tables, smbios_tables_len);      \
-        t = (struct smbios_type_##tbl_type *)(smbios_tables + t_off);     \
-                                                                          \
-        t->header.type = tbl_type;                                        \
-        t->header.length = sizeof(*t);                                    \
-        t->header.handle = cpu_to_le16(tbl_handle);                       \
-    } while (0)
-
-#define SMBIOS_TABLE_SET_STR(tbl_type, field, value)                      \
-    do {                                                                  \
-        int len = (value != NULL) ? strlen(value) + 1 : 0;                \
-        if (len > 1) {                                                    \
-            smbios_tables = g_realloc(smbios_tables,                      \
-                                      smbios_tables_len + len);           \
-            memcpy(smbios_tables + smbios_tables_len, value, len);        \
-            smbios_tables_len += len;                                     \
-            /* update pointer post-realloc */                             \
-            t = (struct smbios_type_##tbl_type *)(smbios_tables + t_off); \
-            t->field = ++str_index;                                       \
-        } else {                                                          \
-            t->field = 0;                                                 \
-        }                                                                 \
-    } while (0)
-
-#define SMBIOS_BUILD_TABLE_POST                                           \
-    do {                                                                  \
-        size_t term_cnt, t_size;                                          \
-                                                                          \
-        /* add '\0' terminator (add two if no strings defined) */         \
-        term_cnt = (str_index == 0) ? 2 : 1;                              \
-        smbios_tables = g_realloc(smbios_tables,                          \
-                                  smbios_tables_len + term_cnt);          \
-        memset(smbios_tables + smbios_tables_len, 0, term_cnt);           \
-        smbios_tables_len += term_cnt;                                    \
-                                                                          \
-        /* update smbios max. element size */                             \
-        t_size = smbios_tables_len - t_off;                               \
-        if (t_size > smbios_table_max) {                                  \
-            smbios_table_max = t_size;                                    \
-        }                                                                 \
-                                                                          \
-        /* update smbios element count */                                 \
-        smbios_table_cnt++;                                               \
-    } while (0)
-
 static void smbios_build_type_0_table(void)
 {
     SMBIOS_BUILD_TABLE_PRE(0, 0x000, false); /* optional, leave up to BIOS */
hw/smbios/smbios_build.h new file +77 -0

77 lines not on this page · raw message

Signature · 1 line
2.7.4
#5 lore raw

PATCH v3 5/6 acpi: Add IPMI table entries

In reply to [email protected]

From: Corey Minyard <[email protected]>

Use the new ACPI table construction tools to create an ACPI entry for IPMI. This adds a function called from build_dsdt to add an DSDT entry for IPMI if IPMI is compiled in and has registered firmware. It also adds a dummy function if IPMI is not compiled in.

This conforms to section "C3-2 Locating IPMI System Interfaces in ACPI Name Space" in the IPMI 2.0 specification.

---
 hw/acpi/Makefile.objs  |   2 +
 hw/acpi/ipmi.c         | 102 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/acpi/noipmi.c       |  14 +++++++
 hw/i386/acpi-build.c   |  10 +++--
 hw/i386/pc_piix.c      |   1 +
 hw/i386/pc_q35.c       |   1 +
 include/hw/acpi/ipmi.h |  22 +++++++++++
 include/hw/i386/pc.h   |   1 +
 8 files changed, 150 insertions(+), 3 deletions(-)
 create mode 100644 hw/acpi/ipmi.c
 create mode 100644 hw/acpi/noipmi.c
 create mode 100644 include/hw/acpi/ipmi.h
hw/acpi/Makefile.objs +2 -0
index faee86c..b8d5c84 100644
@@ -6,3 +6,5 @@ obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o
 common-obj-$(CONFIG_ACPI) += acpi_interface.o
 common-obj-$(CONFIG_ACPI) += bios-linker-loader.o
 common-obj-$(CONFIG_ACPI) += aml-build.o
+common-obj-$(call land,$(CONFIG_ACPI),$(CONFIG_IPMI)) += ipmi.o
+common-obj-$(call land,$(CONFIG_ACPI),$(call lnot,$(CONFIG_IPMI))) += noipmi.o
hw/acpi/ipmi.c new file +102 -0

102 lines not on this page · raw message

hw/acpi/noipmi.c new file +14 -0
new file mode 100644
index 0000000..dd7590d
@@ -0,0 +1,14 @@
+/*
+ * IPMI ACPI firmware handling
+ *
+ * Copyright (c) 2015 Corey Minyard, MontaVista Software, LLC
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "hw/acpi/ipmi.h"
+
+void acpi_add_ipmi(Aml *table, BusState *bus, const char *resource)
+{
+}
hw/i386/acpi-build.c +7 -3
index 6477003..375a94b 100644
@@ -59,6 +59,8 @@
 #include "qapi/qmp/qint.h"
 #include "qom/qom-qobject.h"
 
+#include "hw/acpi/ipmi.h"
+
 /* These are used to size the ACPI tables for -M pc-i440fx-1.7 and
  * -M pc-i440fx-2.0.  Even if the actual amount of AML generated grows
  * a little bit, there should be plenty of free space since the DSDT
@@ -1445,7 +1447,7 @@ static Aml *build_com_device_aml(uint8_t uid)
     return dev;
 }
 
-static void build_isa_devices_aml(Aml *table)
+static void build_isa_devices_aml(Aml *table, ISABus *isa_bus)
 {
     ISADevice *fdc = pc_find_fdc0();
 
@@ -1461,6 +1463,8 @@ static void build_isa_devices_aml(Aml *table)
     aml_append(scope, build_com_device_aml(1));
     aml_append(scope, build_com_device_aml(2));
 
+    acpi_add_ipmi(scope, BUS(isa_bus), "\\_SB.PCI0.ISA");
+
     aml_append(table, scope);
 }
 
@@ -2011,7 +2015,7 @@ build_dsdt(GArray *table_data, GArray *linker,
         build_hpet_aml(dsdt);
         build_piix4_pm(dsdt);
         build_piix4_isa_bridge(dsdt);
-        build_isa_devices_aml(dsdt);
+        build_isa_devices_aml(dsdt, pcms->isa_bus);
         build_piix4_pci_hotplug(dsdt);
         build_piix4_pci0_int(dsdt);
     } else {
@@ -2039,7 +2043,7 @@ build_dsdt(GArray *table_data, GArray *linker,
 
         build_hpet_aml(dsdt);
         build_q35_isa_bridge(dsdt);
-        build_isa_devices_aml(dsdt);
+        build_isa_devices_aml(dsdt, pcms->isa_bus);
         build_q35_pci0_int(dsdt);
     }
 
hw/i386/pc_piix.c +1 -0
index 7f50116..2e5ff45 100644
@@ -185,6 +185,7 @@ static void pc_init1(MachineState *machine,
                               &error_abort);
         no_hpet = 1;
     }
+    pcms->isa_bus = isa_bus;
     isa_bus_irqs(isa_bus, gsi);
 
     if (kvm_pic_in_kernel()) {
hw/i386/pc_q35.c +1 -0
index 04aae89..027655b 100644
@@ -190,6 +190,7 @@ static void pc_q35_init(MachineState *machine)
                  ICH9_LPC_NB_PIRQS);
     pci_bus_set_route_irq_fn(host_bus, ich9_route_intx_pin_to_irq);
     isa_bus = ich9_lpc->isa_bus;
+    pcms->isa_bus = isa_bus;
 
     /*end early*/
     isa_bus_irqs(isa_bus, gsi);
include/hw/acpi/ipmi.h new file +22 -0
new file mode 100644
index 0000000..67d6e2f
@@ -0,0 +1,22 @@
+/*
+ * QEMU IPMI ACPI handling
+ *
+ * Copyright (c) 2015 Corey Minyard <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#ifndef HW_ACPI_IPMI_H
+#define HW_ACPI_IPMI_H
+
+#include "qemu/osdep.h"
+#include "hw/acpi/aml-build.h"
+
+/*
+ * Add ACPI IPMI entries for all registered IPMI devices whose parent
+ * bus matches the given bus.  The resource is the ACPI resource that
+ * contains the IPMI device, this is required for the I2C CRS.
+ */
+void acpi_add_ipmi(Aml *table, BusState *bus, const char *resource);
+
+#endif /* HW_ACPI_IPMI_H */
include/hw/i386/pc.h +1 -0
index 96f0b66..aa8bc97 100644
@@ -51,6 +51,7 @@ struct PCMachineState {
     HotplugHandler *acpi_dev;
     ISADevice *rtc;
     PCIBus *bus;
+    ISABus *isa_bus;
     FWCfgState *fw_cfg;
 
     /* Configuration options: */
Signature · 1 line
2.7.4
#1 lore raw

PATCH v3 1/6 ipmi fwinfo: Remove ACPI parent, add the device

In reply to [email protected]

From: Corey Minyard <[email protected]>

Instead of storing the ACPI parent, store the device in the fwinfo structure for IPMI. This way a future change that scans the IPMI devices for firmware can select the devices on a particular bus.

This will let the ACPI scope be defined by the calling code so the IPMI code doesn't have to know the scope.

---
 hw/ipmi/isa_ipmi_bt.c  | 2 +-
 hw/ipmi/isa_ipmi_kcs.c | 2 +-
 include/hw/ipmi/ipmi.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
hw/ipmi/isa_ipmi_bt.c +1 -1
index aaea12e..9ee3979 100644
@@ -449,8 +449,8 @@ static void isa_ipmi_bt_realize(DeviceState *dev, Error **errp)
     iib->fwinfo.memspace = IPMI_MEMSPACE_IO;
     iib->fwinfo.irq_type = IPMI_LEVEL_IRQ;
     iib->fwinfo.interrupt_number = iib->isairq;
-    iib->fwinfo.acpi_parent = "\\_SB.PCI0.ISA";
     iib->fwinfo.i2c_slave_address = iib->bt.bmc->slave_addr;
+    iib->fwinfo.dev = dev;
     ipmi_add_fwinfo(&iib->fwinfo, errp);
 }
 
hw/ipmi/isa_ipmi_kcs.c +1 -1
index 2742ce0..09ba92d 100644
@@ -413,7 +413,7 @@ static void ipmi_isa_realize(DeviceState *dev, Error **errp)
     iik->fwinfo.memspace = IPMI_MEMSPACE_IO;
     iik->fwinfo.irq_type = IPMI_LEVEL_IRQ;
     iik->fwinfo.interrupt_number = iik->isairq;
-    iik->fwinfo.acpi_parent = "\\_SB.PCI0.ISA";
+    iik->fwinfo.dev = dev;
     ipmi_add_fwinfo(&iik->fwinfo, errp);
 }
 
include/hw/ipmi/ipmi.h +1 -1
index 74a2b5a..1874c55 100644
@@ -196,7 +196,7 @@ typedef struct IPMIFwInfo {
         IPMI_EDGE_IRQ
     } irq_type;
 
-    const char *acpi_parent;
+    DeviceState *dev;
 } IPMIFwInfo;
 
 void ipmi_add_fwinfo(IPMIFwInfo *info, Error **errp);
Signature · 1 line
2.7.4
#4 lore raw

PATCH v3 4/6 ipmi: Add SMBIOS table entry

In reply to [email protected]

From: Corey Minyard <[email protected]>

Add an IPMI table entry to the SMBIOS.

---
 hw/smbios/Makefile.objs  |  2 ++
 hw/smbios/ipmi.c         | 76 ++++++++++++++++++++++++++++++++++++++++++++++++
 hw/smbios/noipmi.c       | 14 +++++++++
 hw/smbios/smbios.c       |  2 ++
 include/hw/smbios/ipmi.h | 15 ++++++++++
 5 files changed, 109 insertions(+)
 create mode 100644 hw/smbios/ipmi.c
 create mode 100644 hw/smbios/noipmi.c
 create mode 100644 include/hw/smbios/ipmi.h
hw/smbios/Makefile.objs +2 -0
index f69a92f..5578f51 100644
@@ -1 +1,3 @@
 common-obj-$(CONFIG_SMBIOS) += smbios.o
+common-obj-$(call land,$(CONFIG_SMBIOS),$(CONFIG_IPMI)) += ipmi.o
+common-obj-$(call land,$(CONFIG_SMBIOS),$(call lnot,$(CONFIG_IPMI))) += noipmi.o
hw/smbios/ipmi.c new file +76 -0

76 lines not on this page · raw message

hw/smbios/noipmi.c new file +14 -0
new file mode 100644
index 0000000..ad669a4
@@ -0,0 +1,14 @@
+/*
+ * IPMI SMBIOS firmware handling
+ *
+ * Copyright (c) 2015 Corey Minyard, MontaVista Software, LLC
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "hw/smbios/ipmi.h"
+
+void smbios_build_type_38_table(void)
+{
+}
hw/smbios/smbios.c +2 -0
index 5dc3e43..74c7102 100644
@@ -25,6 +25,7 @@
 #include "hw/loader.h"
 #include "exec/cpu-common.h"
 #include "smbios_build.h"
+#include "hw/smbios/ipmi.h"
 
 /* legacy structures and constants for <= 2.0 machines */
 struct smbios_header {
@@ -848,6 +849,7 @@ void smbios_get_tables(const struct smbios_phys_mem_area *mem_array,
         }
 
         smbios_build_type_32_table();
+        smbios_build_type_38_table();
         smbios_build_type_127_table();
 
         smbios_validate_table();
include/hw/smbios/ipmi.h new file +15 -0
new file mode 100644
index 0000000..fd53c96
@@ -0,0 +1,15 @@
+/*
+ * IPMI SMBIOS firmware handling
+ *
+ * Copyright (c) 2015 Corey Minyard, MontaVista Software, LLC
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_SMBIOS_IPMI_H
+#define QEMU_SMBIOS_IPMI_H
+
+void smbios_build_type_38_table(void);
+
+#endif /* QEMU_SMBIOS_IPMI_H */
Signature · 1 line
2.7.4
#0 lore raw

v3 cover Add ACPI and SMBIOS tables for IPMI

This rework is based on Michael's comments on the SMBus series.

This patch series modifies the way the tables are added so that they are scanned from the ACPI code handling that particular bus instead of all being added at the end. This way the IPMI ACPI code doesn't have to know the ACPI scope of the device, that only has to be known by the caller.

-corey