Skip to contentSkip to conversation

ipmi: Bug fixes, add new interfaces

PATCH In review [email protected] 4 participants 30 messages Sep 19, 2019 – Jul 29, 2022

lore
Share & tools
lore
#0 lore raw

cover ipmi: Bug fixes, add new interfaces

I haven't gotten a lot of commentary on this, but I assume that means that everything is ok. It's been posted a few times and the last time I received no issues, just a couple of reviews. I would like more review. But I'm not quite sure what to do about that, I've been hanging on to these changes far too long.

The following changes since commit a77d20bafcd4cb7684168a9b4c6dc2a321aaeb50:

Merge remote-tracking branch 'remotes/kraxel/tags/ui-20190919-pull-request' into staging (2019-09-19 17:16:07 +0100)

are available in the Git repository at:

https://github.com/cminyard/qemu.git tags/ipmi-for-release-2019-09-19

for you to fetch changes up to d9b74295c6528fd68cebdea116b283e46543b2a2:

pc: Add an SMB0 ACPI device to q35 (2019-09-19 14:41:58 -0500)

----------------------------------------------------------------
ipmi: Some bug fixes and new interfaces

Some bug fixes for the watchdog and hopeful the BT tests.

Change the IPMI UUID handling to give the user the ability to set it or not have it.

Add a PCI interface.

Add an SMBus interfaces.

-corey

----------------------------------------------------------------
Corey Minyard (15):
ipmi: Fix watchdog NMI handling
ipmi: Fix the get watchdog command
ipmi: Generate an interrupt on watchdog pretimeout expiry tests:ipmi: Fix IPMI BT tests
qdev: Add a no default uuid property
ipmi: Add a UUID device property
ipmi: Split out KCS-specific code from ISA KCS code
ipmi: Split out BT-specific code from ISA BT code
ipmi: Allow a size value to be passed for I/O space smbios:ipmi: Ignore IPMI devices with no fwinfo function
ipmi: Add PCI IPMI interfaces
ipmi: Add an SMBus IPMI interface
acpi: Add i2c serial bus CRS handling
ipmi: Fix SSIF ACPI handling to use the right CRS
pc: Add an SMB0 ACPI device to q35

 default-configs/i386-softmmu.mak |   3 +
 hw/acpi/aml-build.c              |  40 ++++
 hw/acpi/ipmi-stub.c              |   2 +-
 hw/acpi/ipmi.c                   |  13 +-
 hw/i386/Kconfig                  |   3 +
 hw/i386/acpi-build.c             |  17 +-
 hw/i386/pc_piix.c                |  12 +-
 hw/i386/pc_q35.c                 |   9 +-
 hw/ipmi/Kconfig                  |  15 ++
 hw/ipmi/Makefile.objs            |   5 +-
 hw/ipmi/ipmi.c                   |   6 +-
 hw/ipmi/ipmi_bmc_sim.c           |  30 ++-
 hw/ipmi/ipmi_bt.c                | 437 ++++++++++++++++++++++++++++++++++++++
 hw/ipmi/ipmi_kcs.c               | 423 +++++++++++++++++++++++++++++++++++++
 hw/ipmi/isa_ipmi_bt.c            | 443 ++-------------------------------------
 hw/ipmi/isa_ipmi_kcs.c           | 419 ++----------------------------------
 hw/ipmi/pci_ipmi_bt.c            | 146 +++++++++++++
 hw/ipmi/pci_ipmi_kcs.c           | 146 +++++++++++++
 hw/ipmi/smbus_ipmi.c             | 384 +++++++++++++++++++++++++++++++++
 hw/smbios/smbios_type_38.c       |   3 +
 include/hw/acpi/aml-build.h      |  18 ++
 include/hw/acpi/ipmi.h           |   2 +-
 include/hw/i386/pc.h             |   2 +
 include/hw/ipmi/ipmi.h           |   7 +-
 include/hw/ipmi/ipmi_bt.h        |  73 +++++++
 include/hw/ipmi/ipmi_kcs.h       |  76 +++++++
 include/hw/pci/pci.h             |   1 +
 include/hw/qdev-properties.h     |   7 +
 qemu-options.hx                  |  10 +-
 tests/Makefile.include           |   3 +-
 tests/data/acpi/q35/DSDT         | Bin 7841 -> 7879 bytes
 tests/data/acpi/q35/DSDT.bridge  | Bin 7858 -> 7896 bytes
 tests/data/acpi/q35/DSDT.cphp    | Bin 8304 -> 8342 bytes
 tests/data/acpi/q35/DSDT.dimmpxm | Bin 9494 -> 9532 bytes
 tests/data/acpi/q35/DSDT.ipmibt  | Bin 7916 -> 7954 bytes
 tests/data/acpi/q35/DSDT.memhp   | Bin 9200 -> 9238 bytes
 tests/data/acpi/q35/DSDT.mmio64  | Bin 8971 -> 9009 bytes
 tests/data/acpi/q35/DSDT.numamem | Bin 7847 -> 7885 bytes
 tests/ipmi-bt-test.c             |   6 +-
 39 files changed, 1902 insertions(+), 859 deletions(-)
 create mode 100644 hw/ipmi/ipmi_bt.c
 create mode 100644 hw/ipmi/ipmi_kcs.c
 create mode 100644 hw/ipmi/pci_ipmi_bt.c
 create mode 100644 hw/ipmi/pci_ipmi_kcs.c
 create mode 100644 hw/ipmi/smbus_ipmi.c
 create mode 100644 include/hw/ipmi/ipmi_bt.h
 create mode 100644 include/hw/ipmi/ipmi_kcs.h
#1 lore raw

PATCH 1/15 ipmi: Fix watchdog NMI handling

From: Corey Minyard <[email protected]>

The wrong logic was used for detection (so it wouldn't work at all) and the wrong interface was used to inject the NMI if the detection logic was correct.

---
 hw/ipmi/ipmi.c         | 6 +++---
 hw/ipmi/ipmi_bmc_sim.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
hw/ipmi/ipmi.c +3 -3
index 136c86b7a7..cbe158f815 100644
@@ -28,9 +28,8 @@
 #include "qom/object_interfaces.h"
 #include "sysemu/runstate.h"
 #include "qapi/error.h"
-#include "qapi/qapi-commands-misc.h"
-#include "qapi/visitor.h"
 #include "qemu/module.h"
+#include "hw/nmi.h"
 
 static uint32_t ipmi_current_uuid = 1;
 
@@ -60,7 +59,8 @@ static int ipmi_do_hw_op(IPMIInterface *s, enum ipmi_op op, int checkonly)
         if (checkonly) {
             return 0;
         }
-        qmp_inject_nmi(NULL);
+        /* We don't care what CPU we use. */
+        nmi_monitor_handle(0, NULL);
         return 0;
 
     case IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP:
hw/ipmi/ipmi_bmc_sim.c +1 -1
index 246a6d390c..8f63bb7181 100644
@@ -1194,7 +1194,7 @@ static void set_watchdog_timer(IPMIBmcSim *ibs,
         break;
 
     case IPMI_BMC_WATCHDOG_PRE_NMI:
-        if (!k->do_hw_op(s, IPMI_SEND_NMI, 1)) {
+        if (k->do_hw_op(s, IPMI_SEND_NMI, 1)) {
             /* NMI not supported. */
             rsp_buffer_set_error(rsp, IPMI_CC_INVALID_DATA_FIELD);
             return;
Signature · 1 line
2.17.1
Reviewed-by on v1 1/15
#2 lore raw

Re: [PATCH 01/15] ipmi: Fix watchdog NMI handling

Quoted 7 lines · On 19/09/2019 23:39, [email protected] wrote:

From: Corey Minyard <[email protected]>

The wrong logic was used for detection (so it wouldn't work at all) and the wrong interface was used to inject the NMI if the detection logic was correct.

C.

Quoted 44 lines
---
 hw/ipmi/ipmi.c         | 6 +++---
 hw/ipmi/ipmi_bmc_sim.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
hw/ipmi/ipmi.c +3 -3
index 136c86b7a7..cbe158f815 100644
@@ -28,9 +28,8 @@
 #include "qom/object_interfaces.h"
 #include "sysemu/runstate.h"
 #include "qapi/error.h"
-#include "qapi/qapi-commands-misc.h"
-#include "qapi/visitor.h"
 #include "qemu/module.h"
+#include "hw/nmi.h"
 
 static uint32_t ipmi_current_uuid = 1;
 
@@ -60,7 +59,8 @@ static int ipmi_do_hw_op(IPMIInterface *s, enum ipmi_op op, int checkonly)
         if (checkonly) {
             return 0;
         }
-        qmp_inject_nmi(NULL);
+        /* We don't care what CPU we use. */
+        nmi_monitor_handle(0, NULL);
         return 0;
 
     case IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP:
hw/ipmi/ipmi_bmc_sim.c +1 -1
index 246a6d390c..8f63bb7181 100644
@@ -1194,7 +1194,7 @@ static void set_watchdog_timer(IPMIBmcSim *ibs,
         break;
 
     case IPMI_BMC_WATCHDOG_PRE_NMI:
-        if (!k->do_hw_op(s, IPMI_SEND_NMI, 1)) {
+        if (k->do_hw_op(s, IPMI_SEND_NMI, 1)) {
             /* NMI not supported. */
             rsp_buffer_set_error(rsp, IPMI_CC_INVALID_DATA_FIELD);
             return;
#3 lore raw

PATCH 2/15 ipmi: Fix the get watchdog command

In reply to [email protected]

From: Corey Minyard <[email protected]>

It wasn't returning the set timeout like it should have been.

---
 hw/ipmi/ipmi_bmc_sim.c | 2 ++
 1 file changed, 2 insertions(+)
hw/ipmi/ipmi_bmc_sim.c +2 -0
index 8f63bb7181..afb99e33d7 100644
@@ -1228,6 +1228,8 @@ static void get_watchdog_timer(IPMIBmcSim *ibs,
     rsp_buffer_push(rsp, ibs->watchdog_action);
     rsp_buffer_push(rsp, ibs->watchdog_pretimeout);
     rsp_buffer_push(rsp, ibs->watchdog_expired);
+    rsp_buffer_push(rsp, ibs->watchdog_timeout & 0xff);
+    rsp_buffer_push(rsp, (ibs->watchdog_timeout >> 8) & 0xff);
     if (ibs->watchdog_running) {
         long timeout;
         timeout = ((ibs->watchdog_expiry - ipmi_getmonotime() + 50000000)
Signature · 1 line
2.17.1
Reviewed-by on v1 2/15
#4 lore raw

Re: [PATCH 02/15] ipmi: Fix the get watchdog command

Quoted 3 lines · On 19/09/2019 23:39, [email protected] wrote:

From: Corey Minyard <[email protected]>

It wasn't returning the set timeout like it should have been.

Looking at

27.7 Get Watchdog Timer Command

This looks correct.

Thanks,

C.

Quoted 20 lines
---
 hw/ipmi/ipmi_bmc_sim.c | 2 ++
 1 file changed, 2 insertions(+)
hw/ipmi/ipmi_bmc_sim.c +2 -0
index 8f63bb7181..afb99e33d7 100644
@@ -1228,6 +1228,8 @@ static void get_watchdog_timer(IPMIBmcSim *ibs,
     rsp_buffer_push(rsp, ibs->watchdog_action);
     rsp_buffer_push(rsp, ibs->watchdog_pretimeout);
     rsp_buffer_push(rsp, ibs->watchdog_expired);
+    rsp_buffer_push(rsp, ibs->watchdog_timeout & 0xff);
+    rsp_buffer_push(rsp, (ibs->watchdog_timeout >> 8) & 0xff);
     if (ibs->watchdog_running) {
         long timeout;
         timeout = ((ibs->watchdog_expiry - ipmi_getmonotime() + 50000000)
#5 lore raw

PATCH 3/15 ipmi: Generate an interrupt on watchdog pretimeout expiry

In reply to [email protected]

From: Corey Minyard <[email protected]>

Add the watchdog pretimeout to the bits that cause an interrupt on attn. Otherwise the user won't know.

---
 hw/ipmi/ipmi_bmc_sim.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/ipmi/ipmi_bmc_sim.c +3 -1
index afb99e33d7..6e6cd1b47d 100644
@@ -477,7 +477,9 @@ static int attn_set(IPMIBmcSim *ibs)
 
 static int attn_irq_enabled(IPMIBmcSim *ibs)
 {
-    return (IPMI_BMC_MSG_INTS_ON(ibs) && IPMI_BMC_MSG_FLAG_RCV_MSG_QUEUE_SET(ibs))
+    return (IPMI_BMC_MSG_INTS_ON(ibs) &&
+            (IPMI_BMC_MSG_FLAG_RCV_MSG_QUEUE_SET(ibs) ||
+             IPMI_BMC_MSG_FLAG_WATCHDOG_TIMEOUT_MASK_SET(ibs)))
         || (IPMI_BMC_EVBUF_FULL_INT_ENABLED(ibs) &&
             IPMI_BMC_MSG_FLAG_EVT_BUF_FULL_SET(ibs));
 }
Signature · 1 line
2.17.1
Reviewed-by on v1 3/15
#6 lore raw

Re: [PATCH 03/15] ipmi: Generate an interrupt on watchdog pretimeout expiry

Quoted 6 lines · On 19/09/2019 23:39, [email protected] wrote:

From: Corey Minyard <[email protected]>

Add the watchdog pretimeout to the bits that cause an interrupt on attn. Otherwise the user won't know.

C.

Quoted 20 lines
---
 hw/ipmi/ipmi_bmc_sim.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/ipmi/ipmi_bmc_sim.c +3 -1
index afb99e33d7..6e6cd1b47d 100644
@@ -477,7 +477,9 @@ static int attn_set(IPMIBmcSim *ibs)
 
 static int attn_irq_enabled(IPMIBmcSim *ibs)
 {
-    return (IPMI_BMC_MSG_INTS_ON(ibs) && IPMI_BMC_MSG_FLAG_RCV_MSG_QUEUE_SET(ibs))
+    return (IPMI_BMC_MSG_INTS_ON(ibs) &&
+            (IPMI_BMC_MSG_FLAG_RCV_MSG_QUEUE_SET(ibs) ||
+             IPMI_BMC_MSG_FLAG_WATCHDOG_TIMEOUT_MASK_SET(ibs)))
         || (IPMI_BMC_EVBUF_FULL_INT_ENABLED(ibs) &&
             IPMI_BMC_MSG_FLAG_EVT_BUF_FULL_SET(ibs));
 }
#7 lore raw

PATCH 4/15 tests:ipmi: Fix IPMI BT tests

In reply to [email protected]

From: Corey Minyard <[email protected]>

The IPMI BT tests had a race condition, if it receive an IPMI command to enable interrupt, it would write the message to enable interrupts after it wrote the command response. So the test code could receive the command response and issue the next command before the device handled the interrupt enable command, and thus no interrupt.

So send the message to enable interrupt before the command response.

Also add some sleeps to give qemu time to handle responses, there was no delay before, and it could result in an invalid timeout.

And re-enable the tests, as hopefully they are fixed now.

Note that I was unable to reproduce this even with the instructions Peter gave me, but hopefully this fixes the issue.

---
 tests/Makefile.include | 3 +--
 tests/ipmi-bt-test.c   | 6 ++++--
 2 files changed, 5 insertions(+), 4 deletions(-)
tests/Makefile.include +1 -2
index 793632ca72..479664f899 100644
@@ -170,8 +170,7 @@ check-qtest-i386-$(CONFIG_SGA) += tests/boot-serial-test$(EXESUF)
 check-qtest-i386-$(CONFIG_SLIRP) += tests/pxe-test$(EXESUF)
 check-qtest-i386-y += tests/rtc-test$(EXESUF)
 check-qtest-i386-$(CONFIG_ISA_IPMI_KCS) += tests/ipmi-kcs-test$(EXESUF)
-# Disabled temporarily as it fails intermittently especially under NetBSD VM
-# check-qtest-i386-$(CONFIG_ISA_IPMI_BT) += tests/ipmi-bt-test$(EXESUF)
+check-qtest-i386-$(CONFIG_ISA_IPMI_BT) += tests/ipmi-bt-test$(EXESUF)
 check-qtest-i386-y += tests/i440fx-test$(EXESUF)
 check-qtest-i386-y += tests/fw_cfg-test$(EXESUF)
 check-qtest-i386-y += tests/device-plug-test$(EXESUF)
tests/ipmi-bt-test.c +4 -2
index fc4c83b5db..a42207d416 100644
@@ -30,7 +30,7 @@
 #include <netinet/tcp.h>
 
 
-#include "libqtest.h"
+#include "libqtest-single.h"
 #include "qemu-common.h"
 
 #define IPMI_IRQ        5
@@ -99,6 +99,7 @@ static void bt_wait_b_busy(void)
     unsigned int count = 1000;
     while (IPMI_BT_CTLREG_GET_B_BUSY() != 0) {
         g_assert(--count != 0);
+        usleep(100);
     }
 }
 
@@ -107,6 +108,7 @@ static void bt_wait_b2h_atn(void)
     unsigned int count = 1000;
     while (IPMI_BT_CTLREG_GET_B2H_ATN() == 0) {
         g_assert(--count != 0);
+        usleep(100);
     }
 }
 
@@ -240,13 +242,13 @@ static void emu_msg_handler(void)
         write_emu_msg(msg, msg_len);
     } else if ((msg[1] == set_bmc_globals_cmd[0]) &&
                (msg[2] == set_bmc_globals_cmd[1])) {
+        write_emu_msg(enable_irq_cmd, sizeof(enable_irq_cmd));
         memcpy(msg + 1, set_bmc_globals_rsp, sizeof(set_bmc_globals_rsp));
         msg_len = sizeof(set_bmc_globals_rsp) + 1;
         msg[msg_len] = -ipmb_checksum(msg, msg_len, 0);
         msg_len++;
         msg[msg_len++] = 0xa0;
         write_emu_msg(msg, msg_len);
-        write_emu_msg(enable_irq_cmd, sizeof(enable_irq_cmd));
     } else {
         g_assert(0);
     }
Signature · 1 line
2.17.1
#8 lore raw

PATCH 5/15 qdev: Add a no default uuid property

In reply to [email protected]

From: Corey Minyard <[email protected]>

This is for IPMI, which will behave differently if the UUID is not set.

Cc Fam Zheng <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
Cc Marc-André Lureau <[email protected]>
---
 include/hw/qdev-properties.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/hw/qdev-properties.h +7 -0
index 2e98dd60db..c6a8cb5516 100644
@@ -238,6 +238,13 @@ extern const PropertyInfo qdev_prop_pcie_link_width;
 #define DEFINE_PROP_AUDIODEV(_n, _s, _f) \
     DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, QEMUSoundCard)
 
+#define DEFINE_PROP_UUID_NODEFAULT(_name, _state, _field) {        \
+        .name      = (_name),                                      \
+        .info      = &qdev_prop_uuid,                              \
+        .offset    = offsetof(_state, _field)                      \
+            + type_check(QemuUUID, typeof_field(_state, _field)),  \
+        }
+
 #define DEFINE_PROP_END_OF_LIST()               \
     {}
 
Signature · 1 line
2.17.1
Reviewed-by on v1 5/15
#9 lore raw

Re: [PATCH 05/15] qdev: Add a no default uuid property

Quoted 9 lines · On 19/09/2019 23:39, [email protected] wrote:

From: Corey Minyard <[email protected]>

This is for IPMI, which will behave differently if the UUID is not set.

Cc Fam Zheng <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
Cc Marc-André Lureau <[email protected]>

C.

Quoted 23 lines
---
 include/hw/qdev-properties.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/hw/qdev-properties.h +7 -0
index 2e98dd60db..c6a8cb5516 100644
@@ -238,6 +238,13 @@ extern const PropertyInfo qdev_prop_pcie_link_width;
 #define DEFINE_PROP_AUDIODEV(_n, _s, _f) \
     DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, QEMUSoundCard)
 
+#define DEFINE_PROP_UUID_NODEFAULT(_name, _state, _field) {        \
+        .name      = (_name),                                      \
+        .info      = &qdev_prop_uuid,                              \
+        .offset    = offsetof(_state, _field)                      \
+            + type_check(QemuUUID, typeof_field(_state, _field)),  \
+        }
+
 #define DEFINE_PROP_END_OF_LIST()               \
     {}
 
#10 lore raw

PATCH 6/15 ipmi: Add a UUID device property

In reply to [email protected]

From: Corey Minyard <[email protected]>

Using the UUID that qemu generates probably isn't the best thing to do, allow it to be passed in via properties, and use QemuUUID for the type.

If the UUID is not set, return an unsupported command error. This way we are not providing an all-zero (or randomly generated) GUID to the IPMI user. This lets the host fall back to the other method of using the get device id command to determind the BMC being accessed.

Cc Cédric Le Goater <[email protected]>
Cc David Gibson <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
Cc Paolo Bonzini <[email protected]>
---
 hw/ipmi/ipmi_bmc_sim.c | 22 ++++++++++++++--------
 qemu-options.hx        | 10 +++++++---
 2 files changed, 21 insertions(+), 11 deletions(-)
hw/ipmi/ipmi_bmc_sim.c +14 -8
index 6e6cd1b47d..71e56f3b13 100644
@@ -223,7 +223,7 @@ struct IPMIBmcSim {
     uint8_t restart_cause;
 
     uint8_t acpi_power_state[2];
-    uint8_t uuid[16];
+    QemuUUID uuid;
 
     IPMISel sel;
     IPMISdr sdr;
@@ -941,8 +941,19 @@ static void get_device_guid(IPMIBmcSim *ibs,
 {
     unsigned int i;
 
+    /* An uninitialized uuid is all zeros, use that to know if it is set. */
     for (i = 0; i < 16; i++) {
-        rsp_buffer_push(rsp, ibs->uuid[i]);
+        if (ibs->uuid.data[i]) {
+            goto uuid_set;
+        }
+    }
+    /* No uuid is set, return an error. */
+    rsp_buffer_set_error(rsp, IPMI_CC_INVALID_CMD);
+    return;
+
+ uuid_set:
+    for (i = 0; i < 16; i++) {
+        rsp_buffer_push(rsp, ibs->uuid.data[i]);
     }
 }
 
@@ -1986,12 +1997,6 @@ static void ipmi_sim_realize(DeviceState *dev, Error **errp)
     ibs->acpi_power_state[0] = 0;
     ibs->acpi_power_state[1] = 0;
 
-    if (qemu_uuid_set) {
-        memcpy(&ibs->uuid, &qemu_uuid, 16);
-    } else {
-        memset(&ibs->uuid, 0, 16);
-    }
-
     ipmi_init_sensors_from_sdrs(ibs);
     register_cmds(ibs);
 
@@ -2011,6 +2016,7 @@ static Property ipmi_sim_properties[] = {
     DEFINE_PROP_UINT8("fwrev2", IPMIBmcSim, fwrev2, 0),
     DEFINE_PROP_UINT32("mfg_id", IPMIBmcSim, mfg_id, 0),
     DEFINE_PROP_UINT16("product_id", IPMIBmcSim, product_id, 0),
+    DEFINE_PROP_UUID_NODEFAULT("guid", IPMIBmcSim, uuid),
     DEFINE_PROP_END_OF_LIST(),
 };
 
qemu-options.hx +7 -3
index bbfd936d29..ed9292f65e 100644
@@ -701,7 +701,7 @@ possible drivers and properties, use @code{-device help} and
 @code{-device @var{driver},help}.
 
 Some drivers are:
-@item -device ipmi-bmc-sim,id=@var{id}[,slave_addr=@var{val}][,sdrfile=@var{file}][,furareasize=@var{val}][,furdatafile=@var{file}]
+@item -device ipmi-bmc-sim,id=@var{id}[,slave_addr=@var{val}][,sdrfile=@var{file}][,furareasize=@var{val}][,furdatafile=@var{file}][,guid=@var{uuid}]
 
 Add an IPMI BMC.  This is a simulation of a hardware management
 interface processor that normally sits on a system.  It provides
@@ -714,8 +714,8 @@ controllers.  If you don't know what this means, it is safe to ignore
 it.
 
 @table @option
-@item bmc=@var{id}
-The BMC to connect to, one of ipmi-bmc-sim or ipmi-bmc-extern above.
+@item id=@var{id}
+The BMC id for interfaces to use this device.
 @item slave_addr=@var{val}
 Define slave address to use for the BMC.  The default is 0x20.
 @item sdrfile=@var{file}
@@ -724,6 +724,10 @@ file containing raw Sensor Data Records (SDR) data. The default is none.
 size of a Field Replaceable Unit (FRU) area.  The default is 1024.
 @item frudatafile=@var{file}
 file containing raw Field Replaceable Unit (FRU) inventory data. The default is none.
+@item guid=@var{uuid}
+value for the GUID for the BMC, in standard UUID format.  If this is set,
+get "Get GUID" command to the BMC will return it.  Otherwise "Get GUID"
+will return an error.
 @end table
 
 @item -device ipmi-bmc-extern,id=@var{id},chardev=@var{id}[,slave_addr=@var{val}]
Signature · 1 line
2.17.1
Reviewed-by on v1 6/15
#11 lore raw

Re: [PATCH 06/15] ipmi: Add a UUID device property

Quoted 11 lines · On 19/09/2019 23:39, [email protected] wrote:

From: Corey Minyard <[email protected]>

Using the UUID that qemu generates probably isn't the best thing to do, allow it to be passed in via properties, and use QemuUUID for the type.

If the UUID is not set, return an unsupported command error. This way we are not providing an all-zero (or randomly generated) GUID to the IPMI user. This lets the host fall back to the other method of using the get device id command to determind the BMC being accessed.

C.

Quoted 101 lines
Cc Cédric Le Goater <[email protected]>
Cc David Gibson <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
Cc Paolo Bonzini <[email protected]>
---
 hw/ipmi/ipmi_bmc_sim.c | 22 ++++++++++++++--------
 qemu-options.hx        | 10 +++++++---
 2 files changed, 21 insertions(+), 11 deletions(-)
hw/ipmi/ipmi_bmc_sim.c +14 -8
index 6e6cd1b47d..71e56f3b13 100644
@@ -223,7 +223,7 @@ struct IPMIBmcSim {
     uint8_t restart_cause;
 
     uint8_t acpi_power_state[2];
-    uint8_t uuid[16];
+    QemuUUID uuid;
 
     IPMISel sel;
     IPMISdr sdr;
@@ -941,8 +941,19 @@ static void get_device_guid(IPMIBmcSim *ibs,
 {
     unsigned int i;
 
+    /* An uninitialized uuid is all zeros, use that to know if it is set. */
     for (i = 0; i < 16; i++) {
-        rsp_buffer_push(rsp, ibs->uuid[i]);
+        if (ibs->uuid.data[i]) {
+            goto uuid_set;
+        }
+    }
+    /* No uuid is set, return an error. */
+    rsp_buffer_set_error(rsp, IPMI_CC_INVALID_CMD);
+    return;
+
+ uuid_set:
+    for (i = 0; i < 16; i++) {
+        rsp_buffer_push(rsp, ibs->uuid.data[i]);
     }
 }
 
@@ -1986,12 +1997,6 @@ static void ipmi_sim_realize(DeviceState *dev, Error **errp)
     ibs->acpi_power_state[0] = 0;
     ibs->acpi_power_state[1] = 0;
 
-    if (qemu_uuid_set) {
-        memcpy(&ibs->uuid, &qemu_uuid, 16);
-    } else {
-        memset(&ibs->uuid, 0, 16);
-    }
-
     ipmi_init_sensors_from_sdrs(ibs);
     register_cmds(ibs);
 
@@ -2011,6 +2016,7 @@ static Property ipmi_sim_properties[] = {
     DEFINE_PROP_UINT8("fwrev2", IPMIBmcSim, fwrev2, 0),
     DEFINE_PROP_UINT32("mfg_id", IPMIBmcSim, mfg_id, 0),
     DEFINE_PROP_UINT16("product_id", IPMIBmcSim, product_id, 0),
+    DEFINE_PROP_UUID_NODEFAULT("guid", IPMIBmcSim, uuid),
     DEFINE_PROP_END_OF_LIST(),
 };
 
qemu-options.hx +7 -3
index bbfd936d29..ed9292f65e 100644
@@ -701,7 +701,7 @@ possible drivers and properties, use @code{-device help} and
 @code{-device @var{driver},help}.
 
 Some drivers are:
-@item -device ipmi-bmc-sim,id=@var{id}[,slave_addr=@var{val}][,sdrfile=@var{file}][,furareasize=@var{val}][,furdatafile=@var{file}]
+@item -device ipmi-bmc-sim,id=@var{id}[,slave_addr=@var{val}][,sdrfile=@var{file}][,furareasize=@var{val}][,furdatafile=@var{file}][,guid=@var{uuid}]
 
 Add an IPMI BMC.  This is a simulation of a hardware management
 interface processor that normally sits on a system.  It provides
@@ -714,8 +714,8 @@ controllers.  If you don't know what this means, it is safe to ignore
 it.
 
 @table @option
-@item bmc=@var{id}
-The BMC to connect to, one of ipmi-bmc-sim or ipmi-bmc-extern above.
+@item id=@var{id}
+The BMC id for interfaces to use this device.
 @item slave_addr=@var{val}
 Define slave address to use for the BMC.  The default is 0x20.
 @item sdrfile=@var{file}
@@ -724,6 +724,10 @@ file containing raw Sensor Data Records (SDR) data. The default is none.
 size of a Field Replaceable Unit (FRU) area.  The default is 1024.
 @item frudatafile=@var{file}
 file containing raw Field Replaceable Unit (FRU) inventory data. The default is none.
+@item guid=@var{uuid}
+value for the GUID for the BMC, in standard UUID format.  If this is set,
+get "Get GUID" command to the BMC will return it.  Otherwise "Get GUID"
+will return an error.
 @end table
 
 @item -device ipmi-bmc-extern,id=@var{id},chardev=@var{id}[,slave_addr=@var{val}]
#12 lore raw

PATCH 7/15 ipmi: Split out KCS-specific code from ISA KCS code

In reply to [email protected]

From: Corey Minyard <[email protected]>

Get ready for PCI and other KCS interfaces.

No functional changes, just split the code into the generic KCS code and the ISA-specific code.

---
 hw/ipmi/Makefile.objs      |   2 +-
 hw/ipmi/ipmi_kcs.c         | 408 ++++++++++++++++++++++++++++++++++++
 hw/ipmi/isa_ipmi_kcs.c     | 417 ++-----------------------------------
 include/hw/ipmi/ipmi_kcs.h |  75 +++++++
 4 files changed, 505 insertions(+), 397 deletions(-)
 create mode 100644 hw/ipmi/ipmi_kcs.c
 create mode 100644 include/hw/ipmi/ipmi_kcs.h
hw/ipmi/Makefile.objs +1 -1
index 1b422bbee0..6835d2f64a 100644
@@ -1,4 +1,4 @@
-common-obj-$(CONFIG_IPMI) += ipmi.o
+common-obj-$(CONFIG_IPMI) += ipmi.o ipmi_kcs.o
 common-obj-$(CONFIG_IPMI_LOCAL) += ipmi_bmc_sim.o
 common-obj-$(CONFIG_IPMI_EXTERN) += ipmi_bmc_extern.o
 common-obj-$(CONFIG_ISA_IPMI_KCS) += isa_ipmi_kcs.o
hw/ipmi/ipmi_kcs.c new file +408 -0

408 lines not on this page · raw message

hw/ipmi/isa_ipmi_kcs.c +21 -396

482 lines not on this page · raw message

include/hw/ipmi/ipmi_kcs.h new file +75 -0

75 lines not on this page · raw message

Signature · 1 line
2.17.1
#13 lore raw

PATCH 8/15 ipmi: Split out BT-specific code from ISA BT code

In reply to [email protected]

From: Corey Minyard <[email protected]>

Get ready for PCI and other BT interfaces.

No functional changes, just split the code into generic BT code and ISA-specific BT code.

---
 hw/ipmi/Makefile.objs     |   2 +-
 hw/ipmi/ipmi_bt.c         | 426 ++++++++++++++++++++++++++++++++++++
 hw/ipmi/isa_ipmi_bt.c     | 441 ++------------------------------------
 include/hw/ipmi/ipmi_bt.h |  72 +++++++
 4 files changed, 520 insertions(+), 421 deletions(-)
 create mode 100644 hw/ipmi/ipmi_bt.c
 create mode 100644 include/hw/ipmi/ipmi_bt.h
hw/ipmi/Makefile.objs +1 -1
index 6835d2f64a..4ffa45a66c 100644
@@ -1,4 +1,4 @@
-common-obj-$(CONFIG_IPMI) += ipmi.o ipmi_kcs.o
+common-obj-$(CONFIG_IPMI) += ipmi.o ipmi_kcs.o ipmi_bt.o
 common-obj-$(CONFIG_IPMI_LOCAL) += ipmi_bmc_sim.o
 common-obj-$(CONFIG_IPMI_EXTERN) += ipmi_bmc_extern.o
 common-obj-$(CONFIG_ISA_IPMI_KCS) += isa_ipmi_kcs.o
hw/ipmi/ipmi_bt.c new file +426 -0

426 lines not on this page · raw message

hw/ipmi/isa_ipmi_bt.c +21 -420

496 lines not on this page · raw message

include/hw/ipmi/ipmi_bt.h new file +72 -0

72 lines not on this page · raw message

Signature · 1 line
2.17.1
#14 lore raw

PATCH 9/15 ipmi: Allow a size value to be passed for I/O space

In reply to [email protected]

From: Corey Minyard <[email protected]>

PCI device I/O must be >= 8 bytes in length or they don't work. Allow the size to be passed in, the default size of 2 or 3 won't work.

---
 hw/ipmi/ipmi_bt.c          | 19 +++++++++++++++----
 hw/ipmi/ipmi_kcs.c         | 23 +++++++++++++++++++----
 hw/ipmi/isa_ipmi_bt.c      |  2 +-
 hw/ipmi/isa_ipmi_kcs.c     |  2 +-
 include/hw/ipmi/ipmi.h     |  7 ++++++-
 include/hw/ipmi/ipmi_bt.h  |  1 +
 include/hw/ipmi/ipmi_kcs.h |  1 +
 7 files changed, 44 insertions(+), 11 deletions(-)
hw/ipmi/ipmi_bt.c +15 -4
index e6765ca4f8..22f94fb98d 100644
@@ -189,7 +189,7 @@ static uint64_t ipmi_bt_ioport_read(void *opaque, hwaddr addr, unsigned size)
     IPMIBT *ib = iic->get_backend_data(ii);
     uint32_t ret = 0xff;
 
-    switch (addr & 3) {
+    switch (addr & ib->size_mask) {
     case 0:
         ret = ib->control_reg;
         break;
@@ -208,6 +208,9 @@ static uint64_t ipmi_bt_ioport_read(void *opaque, hwaddr addr, unsigned size)
     case 2:
         ret = ib->mask_reg;
         break;
+    default:
+        ret = 0xff;
+        break;
     }
     return ret;
 }
@@ -230,7 +233,7 @@ static void ipmi_bt_ioport_write(void *opaque, hwaddr addr, uint64_t val,
     IPMIInterfaceClass *iic = IPMI_INTERFACE_GET_CLASS(ii);
     IPMIBT *ib = iic->get_backend_data(ii);
 
-    switch (addr & 3) {
+    switch (addr & ib->size_mask) {
     case 0:
         if (IPMI_BT_GET_CLR_WR(val)) {
             ib->inlen = 0;
@@ -285,6 +288,9 @@ static void ipmi_bt_ioport_write(void *opaque, hwaddr addr, uint64_t val,
             ipmi_bt_lower_irq(ib);
         }
         break;
+    default:
+        /* Ignore. */
+        break;
     }
 }
 
@@ -346,14 +352,19 @@ static void ipmi_bt_set_irq_enable(IPMIInterface *ii, int val)
     ib->irqs_enabled = val;
 }
 
-static void ipmi_bt_init(IPMIInterface *ii, Error **errp)
+static void ipmi_bt_init(IPMIInterface *ii, unsigned int min_size, Error **errp)
 {
     IPMIInterfaceClass *iic = IPMI_INTERFACE_GET_CLASS(ii);
     IPMIBT *ib = iic->get_backend_data(ii);
 
+    if (min_size == 0) {
+        min_size = 4;
+    }
+    ib->size_mask = min_size - 1;
     ib->io_length = 3;
 
-    memory_region_init_io(&ib->io, NULL, &ipmi_bt_io_ops, ii, "ipmi-bt", 3);
+    memory_region_init_io(&ib->io, NULL, &ipmi_bt_io_ops, ii, "ipmi-bt",
+                          min_size);
 }
 
 int ipmi_bt_vmstate_post_load(void *opaque, int version)
hw/ipmi/ipmi_kcs.c +19 -4
index dab1af8bc8..a77612946a 100644
@@ -232,7 +232,7 @@ static uint64_t ipmi_kcs_ioport_read(void *opaque, hwaddr addr, unsigned size)
     IPMIKCS *ik = iic->get_backend_data(ii);
     uint32_t ret;
 
-    switch (addr & 1) {
+    switch (addr & ik->size_mask) {
     case 0:
         ret = ik->data_out_reg;
         IPMI_KCS_SET_OBF(ik->status_reg, 0);
@@ -243,6 +243,7 @@ static uint64_t ipmi_kcs_ioport_read(void *opaque, hwaddr addr, unsigned size)
             }
         }
         break;
+
     case 1:
         ret = ik->status_reg;
         if (ik->atn_irq_set) {
@@ -252,6 +253,9 @@ static uint64_t ipmi_kcs_ioport_read(void *opaque, hwaddr addr, unsigned size)
             }
         }
         break;
+
+    default:
+        ret = 0xff;
     }
     return ret;
 }
@@ -267,7 +271,7 @@ static void ipmi_kcs_ioport_write(void *opaque, hwaddr addr, uint64_t val,
         return;
     }
 
-    switch (addr & 1) {
+    switch (addr & ik->size_mask) {
     case 0:
         ik->data_in_reg = val;
         break;
@@ -275,6 +279,10 @@ static void ipmi_kcs_ioport_write(void *opaque, hwaddr addr, uint64_t val,
     case 1:
         ik->cmd_reg = val;
         break;
+
+    default:
+        /* Ignore. */
+        break;
     }
     IPMI_KCS_SET_IBF(ik->status_reg, 1);
     ipmi_kcs_signal(ik, ii);
@@ -321,13 +329,20 @@ static void ipmi_kcs_set_irq_enable(IPMIInterface *ii, int val)
     ik->irqs_enabled = val;
 }
 
-static void ipmi_kcs_init(IPMIInterface *ii, Error **errp)
+/* min_size must be a power of 2. */
+static void ipmi_kcs_init(IPMIInterface *ii, unsigned int min_size,
+                          Error **errp)
 {
     IPMIInterfaceClass *iic = IPMI_INTERFACE_GET_CLASS(ii);
     IPMIKCS *ik = iic->get_backend_data(ii);
 
+    if (min_size == 0) {
+        min_size = 2;
+    }
+    ik->size_mask = min_size - 1;
     ik->io_length = 2;
-    memory_region_init_io(&ik->io, NULL, &ipmi_kcs_io_ops, ii, "ipmi-kcs", 2);
+    memory_region_init_io(&ik->io, NULL, &ipmi_kcs_io_ops, ii, "ipmi-kcs",
+                          min_size);
 }
 
 int ipmi_kcs_vmstate_post_load(void *opaque, int version)
hw/ipmi/isa_ipmi_bt.c +1 -1
index c102778712..9a87ffd3f0 100644
@@ -85,7 +85,7 @@ static void isa_ipmi_bt_realize(DeviceState *dev, Error **errp)
     iib->bt.bmc->intf = ii;
     iib->bt.opaque = iib;
 
-    iic->init(ii, errp);
+    iic->init(ii, 0, errp);
     if (*errp)
         return;
 
hw/ipmi/isa_ipmi_kcs.c +1 -1
index 8e32774f85..ca3ea36a3f 100644
@@ -84,7 +84,7 @@ static void ipmi_isa_realize(DeviceState *dev, Error **errp)
     iik->kcs.bmc->intf = ii;
     iik->kcs.opaque = iik;
 
-    iic->init(ii, errp);
+    iic->init(ii, 0, errp);
     if (*errp)
         return;
 
include/hw/ipmi/ipmi.h +6 -1
index 70871da0a7..6f2413b39b 100644
@@ -118,7 +118,12 @@ typedef struct IPMIInterface IPMIInterface;
 typedef struct IPMIInterfaceClass {
     InterfaceClass parent;
 
-    void (*init)(struct IPMIInterface *s, Error **errp);
+    /*
+     * min_size is the requested I/O size and must be a power of 2.
+     * This is so PCI (or other busses) can request a bigger range.
+     * Use 0 for the default.
+     */
+    void (*init)(struct IPMIInterface *s, unsigned int min_size, Error **errp);
 
     /*
      * Perform various operations on the hardware.  If checkonly is
include/hw/ipmi/ipmi_bt.h +1 -0
index 9667aaa88a..8a4316ea7c 100644
@@ -56,6 +56,7 @@ typedef struct IPMIBT {
     uint32_t io_base;
     unsigned long io_length;
     MemoryRegion io;
+    unsigned long size_mask;
 
     void (*raise_irq)(struct IPMIBT *ib);
     void (*lower_irq)(struct IPMIBT *ib);
include/hw/ipmi/ipmi_kcs.h +1 -0
index 91d76d08f4..6e6ef4c539 100644
@@ -59,6 +59,7 @@ typedef struct IPMIKCS {
     uint32_t io_base;
     unsigned long io_length;
     MemoryRegion io;
+    unsigned long size_mask;
 
     void (*raise_irq)(struct IPMIKCS *ik);
     void (*lower_irq)(struct IPMIKCS *ik);
Signature · 1 line
2.17.1
#15 lore raw

PATCH 10/15 smbios:ipmi: Ignore IPMI devices with no fwinfo function

In reply to [email protected]

From: Corey Minyard <[email protected]>

Not all devices have fwinfo (like the coming PCI one), so ignore them if the their fwinfo function is NULL.

Cc Michael S. Tsirkin <[email protected]>
Cc Igor Mammedov <[email protected]>
---
 hw/smbios/smbios_type_38.c | 3 +++
 1 file changed, 3 insertions(+)
hw/smbios/smbios_type_38.c +3 -0
index 0c08f282de..168b886647 100644
@@ -94,6 +94,9 @@ static void smbios_add_ipmi_devices(BusState *bus)
             ii = IPMI_INTERFACE(obj);
             iic = IPMI_INTERFACE_GET_CLASS(obj);
             memset(&info, 0, sizeof(info));
+            if (!iic->get_fwinfo) {
+                continue;
+            }
             iic->get_fwinfo(ii, &info);
             smbios_build_one_type_38(&info);
             continue;
Signature · 1 line
2.17.1
#16 lore raw

PATCH 11/15 ipmi: Add PCI IPMI interfaces

In reply to [email protected]

From: Corey Minyard <[email protected]>

Pretty straightforward, just hook the current KCS and BT code into the PCI system with the proper configuration.

Cc Michael S. Tsirkin <[email protected]>
Cc M: Marcel Apfelbaum <[email protected]>
---
 default-configs/i386-softmmu.mak |   2 +
 hw/i386/Kconfig                  |   2 +
 hw/ipmi/Kconfig                  |  10 +++
 hw/ipmi/Makefile.objs            |   2 +
 hw/ipmi/pci_ipmi_bt.c            | 146 +++++++++++++++++++++++++++++++
 hw/ipmi/pci_ipmi_kcs.c           | 146 +++++++++++++++++++++++++++++++
 include/hw/pci/pci.h             |   1 +
 7 files changed, 309 insertions(+)
 create mode 100644 hw/ipmi/pci_ipmi_bt.c
 create mode 100644 hw/ipmi/pci_ipmi_kcs.c
default-configs/i386-softmmu.mak +2 -0
index ba3fb3ff50..2294c0be5a 100644
@@ -10,6 +10,8 @@
 #CONFIG_ISA_DEBUG=n
 #CONFIG_ISA_IPMI_BT=n
 #CONFIG_ISA_IPMI_KCS=n
+#CONFIG_PCI_IPMI_KCS=n
+#CONFIG_PCI_IPMI_BT=n
 #CONFIG_PCI_DEVICES=n
 #CONFIG_PVPANIC=n
 #CONFIG_QXL=n
hw/i386/Kconfig +2 -0
index c7a9d6315c..d10f4e3e8b 100644
@@ -8,6 +8,8 @@ config PC
     imply HYPERV
     imply ISA_IPMI_KCS
     imply ISA_IPMI_BT
+    imply PCI_IPMI_KCS
+    imply PCI_IPMI_BT
     imply ISA_DEBUG
     imply PARALLEL
     imply PCI_DEVICES
hw/ipmi/Kconfig +10 -0
index b944fae100..12db4e81ad 100644
@@ -20,3 +20,13 @@ config ISA_IPMI_BT
     bool
     depends on ISA_BUS
     select IPMI
+
+config PCI_IPMI_KCS
+    bool
+    depends on PCI
+    select IPMI
+
+config PCI_IPMI_BT
+    bool
+    depends on PCI
+    select IPMI
hw/ipmi/Makefile.objs +2 -0
index 4ffa45a66c..2d7f080a86 100644
@@ -2,4 +2,6 @@ common-obj-$(CONFIG_IPMI) += ipmi.o ipmi_kcs.o ipmi_bt.o
 common-obj-$(CONFIG_IPMI_LOCAL) += ipmi_bmc_sim.o
 common-obj-$(CONFIG_IPMI_EXTERN) += ipmi_bmc_extern.o
 common-obj-$(CONFIG_ISA_IPMI_KCS) += isa_ipmi_kcs.o
+common-obj-$(CONFIG_PCI_IPMI_KCS) += pci_ipmi_kcs.o
 common-obj-$(CONFIG_ISA_IPMI_BT) += isa_ipmi_bt.o
+common-obj-$(CONFIG_PCI_IPMI_BT) += pci_ipmi_bt.o
hw/ipmi/pci_ipmi_bt.c new file +146 -0

146 lines not on this page · raw message

hw/ipmi/pci_ipmi_kcs.c new file +146 -0

146 lines not on this page · raw message

include/hw/pci/pci.h +1 -0
index 1b840e61a2..f3f0ffd5fb 100644
@@ -55,6 +55,7 @@ extern bool pci_available;
 /* QEMU/Bochs VGA (0x1234) */
 #define PCI_VENDOR_ID_QEMU               0x1234
 #define PCI_DEVICE_ID_QEMU_VGA           0x1111
+#define PCI_DEVICE_ID_QEMU_IPMI          0x1112
 
 /* VMWare (0x15ad) */
 #define PCI_VENDOR_ID_VMWARE             0x15ad
Signature · 1 line
2.17.1
#17 lore raw

PATCH 12/15 ipmi: Add an SMBus IPMI interface

In reply to [email protected]

From: Corey Minyard <[email protected]>

---
 default-configs/i386-softmmu.mak |   1 +
 hw/i386/Kconfig                  |   1 +
 hw/ipmi/Kconfig                  |   5 +
 hw/ipmi/Makefile.objs            |   1 +
 hw/ipmi/smbus_ipmi.c             | 384 +++++++++++++++++++++++++++++++
 5 files changed, 392 insertions(+)
 create mode 100644 hw/ipmi/smbus_ipmi.c
default-configs/i386-softmmu.mak +1 -0
index 2294c0be5a..4229900f57 100644
@@ -12,6 +12,7 @@
 #CONFIG_ISA_IPMI_KCS=n
 #CONFIG_PCI_IPMI_KCS=n
 #CONFIG_PCI_IPMI_BT=n
+#CONFIG_IPMI_SSIF=n
 #CONFIG_PCI_DEVICES=n
 #CONFIG_PVPANIC=n
 #CONFIG_QXL=n
hw/i386/Kconfig +1 -0
index d10f4e3e8b..c5c9d4900e 100644
@@ -10,6 +10,7 @@ config PC
     imply ISA_IPMI_BT
     imply PCI_IPMI_KCS
     imply PCI_IPMI_BT
+    imply IPMI_SSIF
     imply ISA_DEBUG
     imply PARALLEL
     imply PCI_DEVICES
hw/ipmi/Kconfig +5 -0
index 12db4e81ad..9befd4f422 100644
@@ -30,3 +30,8 @@ config PCI_IPMI_BT
     bool
     depends on PCI
     select IPMI
+
+config IPMI_SSIF
+    bool
+    depends on I2C
+    select IPMI
hw/ipmi/Makefile.objs +1 -0
index 2d7f080a86..3cca10bc50 100644
@@ -5,3 +5,4 @@ common-obj-$(CONFIG_ISA_IPMI_KCS) += isa_ipmi_kcs.o
 common-obj-$(CONFIG_PCI_IPMI_KCS) += pci_ipmi_kcs.o
 common-obj-$(CONFIG_ISA_IPMI_BT) += isa_ipmi_bt.o
 common-obj-$(CONFIG_PCI_IPMI_BT) += pci_ipmi_bt.o
+common-obj-$(CONFIG_IPMI_SSIF) += smbus_ipmi.o
hw/ipmi/smbus_ipmi.c new file +384 -0

384 lines not on this page · raw message

Signature · 1 line
2.17.1
#18 lore raw

Re: [PATCH 12/15] ipmi: Add an SMBus IPMI interface

Quoted 5 lines · On Thu, 19 Sept 2019 at 22:39, <[email protected]> wrote:

From: Corey Minyard <[email protected]>

---

Very old patch, but Coverity has decided it doesn't like something in this function that's still basically the same in the current codebase (CID 1487146):

Quoted 34 lines
hw/ipmi/smbus_ipmi.c new file +34 -0
+static int ipmi_write_data(SMBusDevice *dev, uint8_t *buf, uint8_t len)
+{
+    SMBusIPMIDevice *sid = SMBUS_IPMI(dev);
+    bool send = false;
+    uint8_t cmd;
+    int ret = 0;
+
+    /* length is guaranteed to be >= 1. */
+    cmd = *buf++;
+    len--;
+
+    /* Handle read request, which don't have any data in the write part. */
+    switch (cmd) {
+    case SSIF_IPMI_RESPONSE:
+        sid->currblk = 0;
+        ret = ipmi_load_readbuf(sid);
+        break;
+
+    case SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE:
+        sid->currblk++;
+        ret = ipmi_load_readbuf(sid);
+        break;
+
+    case SSIF_IPMI_MULTI_PART_RETRY:
+        if (len >= 1) {
+            sid->currblk = buf[0];
+            ret = ipmi_load_readbuf(sid);
+        } else {
+            ret = -1;
+        }
+        break;
+
+    default:
+        break;

hw/ipmi/smbus_ipmi.c line 248

Quoted 10 lines
hw/ipmi/smbus_ipmi.c new file +10 -0
+    }
+
+    /* This should be a message write, make the length is there and correct. */
+    if (len >= 1) {
+        if (*buf != len - 1 || *buf > MAX_SSIF_IPMI_MSG_CHUNK) {
+            return -1; /* Bogus message */
+        }
+        buf++;
+        len--;
+    }

After all of this preamble, len can be zero...

Quoted 14 lines
hw/ipmi/smbus_ipmi.c new file +14 -0
+
+    switch (cmd) {
+    case SSIF_IPMI_REQUEST:
+        send = true;
+        /* FALLTHRU */
+    case SSIF_IPMI_MULTI_PART_REQUEST_START:
+        if (len < 2) {
+            return -1; /* Bogus. */
+        }
+        memcpy(sid->inmsg, buf, len);
+        sid->inlen = len;
+        break;
+
+    case SSIF_IPMI_MULTI_PART_REQUEST_END:

hw/ipmi/smbus_ipmi.c line 272

Quoted 10 lines
hw/ipmi/smbus_ipmi.c new file +10 -0
+        send = true;
+        /* FALLTHRU */
+    case SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE:
+        if (!sid->inlen) {
+            return -1; /* Bogus. */
+        }
+        if (sid->inlen + len > MAX_SSIF_IPMI_MSG_SIZE) {
+            sid->inlen = 0; /* Discard the message. */
+            return -1; /* Bogus. */
+        }

...this error checking on the values of the 'middle' request means that after one 'middle' request we can end up with sid->inlen == MAX_SSIF_IPMI_MSG_SIZE (ie we filled the entire sid->inmsg[] array).

But then if we get another 'middle' request with len == 0, that will pass this error checking because (sid->inlen + len == MSG_SIZE) and fall through into...

hw/ipmi/smbus_ipmi.c line 282

Quoted 10 lines
hw/ipmi/smbus_ipmi.c new file +10 -0
+        if (len < 32) {
+            /*
+             * Special hack, a multi-part middle that is less than 32 bytes
+             * marks the end of a message.  The specification is fairly
+             * confusing, so some systems to this, even sending a zero
+             * length end message to mark the end.
+             */
+            send = true;
+        }
+        memcpy(sid->inmsg + sid->inlen, buf, len);

...calling memcpy() with argument 1 being a pointer that points one past the end of the array. Even though len will be 0 and we won't memcpy() anything, this is (depending on how you choose to intepret things the C standard doesn't come right out and state explicitly) undefined behaviour, because memcpy() wants to be passed valid pointers, even if you ask it to do no work with a zero len.

This isn't going to be a visible bug in practical terms, but it would make Coverity happy if we either (a) rejected a request with an empty length or else (b) skipped the memcpy(). I don't know enough about IPMI to know which is better.

hw/ipmi/smbus_ipmi.c line 292

Quoted 10 lines
hw/ipmi/smbus_ipmi.c new file +10 -0
+        sid->inlen += len;
+        break;
+    }
+
+    if (send && sid->inlen) {
+        smbus_ipmi_send_msg(sid);
+    }
+
+    return ret;
+}

thanks
-- PMM

#19 lore raw

Re: [PATCH 12/15] ipmi: Add an SMBus IPMI interface

Quoted 11 lines · Peter Maydell
Quoted 5 lines · On Thu, 19 Sept 2019 at 22:39, <[email protected]> wrote:

From: Corey Minyard <[email protected]>

---

Very old patch, but Coverity has decided it doesn't like something in this function that's still basically the same in the current codebase (CID 1487146):

Ping ?

Quoted 99 lines
Quoted 34 lines
hw/ipmi/smbus_ipmi.c new file +34 -0
+static int ipmi_write_data(SMBusDevice *dev, uint8_t *buf, uint8_t len)
+{
+    SMBusIPMIDevice *sid = SMBUS_IPMI(dev);
+    bool send = false;
+    uint8_t cmd;
+    int ret = 0;
+
+    /* length is guaranteed to be >= 1. */
+    cmd = *buf++;
+    len--;
+
+    /* Handle read request, which don't have any data in the write part. */
+    switch (cmd) {
+    case SSIF_IPMI_RESPONSE:
+        sid->currblk = 0;
+        ret = ipmi_load_readbuf(sid);
+        break;
+
+    case SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE:
+        sid->currblk++;
+        ret = ipmi_load_readbuf(sid);
+        break;
+
+    case SSIF_IPMI_MULTI_PART_RETRY:
+        if (len >= 1) {
+            sid->currblk = buf[0];
+            ret = ipmi_load_readbuf(sid);
+        } else {
+            ret = -1;
+        }
+        break;
+
+    default:
+        break;

hw/ipmi/smbus_ipmi.c line 248

Quoted 10 lines
hw/ipmi/smbus_ipmi.c new file +10 -0
+    }
+
+    /* This should be a message write, make the length is there and correct. */
+    if (len >= 1) {
+        if (*buf != len - 1 || *buf > MAX_SSIF_IPMI_MSG_CHUNK) {
+            return -1; /* Bogus message */
+        }
+        buf++;
+        len--;
+    }

After all of this preamble, len can be zero...

Quoted 14 lines
hw/ipmi/smbus_ipmi.c new file +14 -0
+
+    switch (cmd) {
+    case SSIF_IPMI_REQUEST:
+        send = true;
+        /* FALLTHRU */
+    case SSIF_IPMI_MULTI_PART_REQUEST_START:
+        if (len < 2) {
+            return -1; /* Bogus. */
+        }
+        memcpy(sid->inmsg, buf, len);
+        sid->inlen = len;
+        break;
+
+    case SSIF_IPMI_MULTI_PART_REQUEST_END:

hw/ipmi/smbus_ipmi.c line 272

Quoted 10 lines
hw/ipmi/smbus_ipmi.c new file +10 -0
+        send = true;
+        /* FALLTHRU */
+    case SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE:
+        if (!sid->inlen) {
+            return -1; /* Bogus. */
+        }
+        if (sid->inlen + len > MAX_SSIF_IPMI_MSG_SIZE) {
+            sid->inlen = 0; /* Discard the message. */
+            return -1; /* Bogus. */
+        }

...this error checking on the values of the 'middle' request means that after one 'middle' request we can end up with sid->inlen == MAX_SSIF_IPMI_MSG_SIZE (ie we filled the entire sid->inmsg[] array).

But then if we get another 'middle' request with len == 0, that will pass this error checking because (sid->inlen + len == MSG_SIZE) and fall through into...

hw/ipmi/smbus_ipmi.c line 282

Quoted 10 lines
hw/ipmi/smbus_ipmi.c new file +10 -0
+        if (len < 32) {
+            /*
+             * Special hack, a multi-part middle that is less than 32 bytes
+             * marks the end of a message.  The specification is fairly
+             * confusing, so some systems to this, even sending a zero
+             * length end message to mark the end.
+             */
+            send = true;
+        }
+        memcpy(sid->inmsg + sid->inlen, buf, len);

...calling memcpy() with argument 1 being a pointer that points one past the end of the array. Even though len will be 0 and we won't memcpy() anything, this is (depending on how you choose to intepret things the C standard doesn't come right out and state explicitly) undefined behaviour, because memcpy() wants to be passed valid pointers, even if you ask it to do no work with a zero len.

Quoted 4 lines

This isn't going to be a visible bug in practical terms, but it would make Coverity happy if we either (a) rejected a request with an empty length or else (b) skipped the memcpy(). I don't know enough about IPMI to know which is better.

thanks
-- PMM

#20 lore raw

Re: [PATCH 12/15] ipmi: Add an SMBus IPMI interface

In reply to Peter Maydell
Quoted 7 lines · Peter Maydell
Quoted 5 lines · On Thu, 19 Sept 2019 at 22:39, <[email protected]> wrote:

From: Corey Minyard <[email protected]>

---

Thank you for the ping. Comments inline...

Quoted 103 lines

Very old patch, but Coverity has decided it doesn't like something in this function that's still basically the same in the current codebase (CID 1487146):

Quoted 34 lines
hw/ipmi/smbus_ipmi.c new file +34 -0
+static int ipmi_write_data(SMBusDevice *dev, uint8_t *buf, uint8_t len)
+{
+    SMBusIPMIDevice *sid = SMBUS_IPMI(dev);
+    bool send = false;
+    uint8_t cmd;
+    int ret = 0;
+
+    /* length is guaranteed to be >= 1. */
+    cmd = *buf++;
+    len--;
+
+    /* Handle read request, which don't have any data in the write part. */
+    switch (cmd) {
+    case SSIF_IPMI_RESPONSE:
+        sid->currblk = 0;
+        ret = ipmi_load_readbuf(sid);
+        break;
+
+    case SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE:
+        sid->currblk++;
+        ret = ipmi_load_readbuf(sid);
+        break;
+
+    case SSIF_IPMI_MULTI_PART_RETRY:
+        if (len >= 1) {
+            sid->currblk = buf[0];
+            ret = ipmi_load_readbuf(sid);
+        } else {
+            ret = -1;
+        }
+        break;
+
+    default:
+        break;

hw/ipmi/smbus_ipmi.c line 248

Quoted 10 lines
hw/ipmi/smbus_ipmi.c new file +10 -0
+    }
+
+    /* This should be a message write, make the length is there and correct. */
+    if (len >= 1) {
+        if (*buf != len - 1 || *buf > MAX_SSIF_IPMI_MSG_CHUNK) {
+            return -1; /* Bogus message */
+        }
+        buf++;
+        len--;
+    }

After all of this preamble, len can be zero...

Quoted 14 lines
hw/ipmi/smbus_ipmi.c new file +14 -0
+
+    switch (cmd) {
+    case SSIF_IPMI_REQUEST:
+        send = true;
+        /* FALLTHRU */
+    case SSIF_IPMI_MULTI_PART_REQUEST_START:
+        if (len < 2) {
+            return -1; /* Bogus. */
+        }
+        memcpy(sid->inmsg, buf, len);
+        sid->inlen = len;
+        break;
+
+    case SSIF_IPMI_MULTI_PART_REQUEST_END:

hw/ipmi/smbus_ipmi.c line 272

Quoted 10 lines
hw/ipmi/smbus_ipmi.c new file +10 -0
+        send = true;
+        /* FALLTHRU */
+    case SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE:
+        if (!sid->inlen) {
+            return -1; /* Bogus. */
+        }
+        if (sid->inlen + len > MAX_SSIF_IPMI_MSG_SIZE) {
+            sid->inlen = 0; /* Discard the message. */
+            return -1; /* Bogus. */
+        }

...this error checking on the values of the 'middle' request means that after one 'middle' request we can end up with sid->inlen == MAX_SSIF_IPMI_MSG_SIZE (ie we filled the entire sid->inmsg[] array).

But then if we get another 'middle' request with len == 0, that will pass this error checking because (sid->inlen + len == MSG_SIZE) and fall through into...

hw/ipmi/smbus_ipmi.c line 282

Quoted 10 lines
hw/ipmi/smbus_ipmi.c new file +10 -0
+        if (len < 32) {
+            /*
+             * Special hack, a multi-part middle that is less than 32 bytes
+             * marks the end of a message.  The specification is fairly
+             * confusing, so some systems to this, even sending a zero
+             * length end message to mark the end.
+             */
+            send = true;
+        }
+        memcpy(sid->inmsg + sid->inlen, buf, len);

...calling memcpy() with argument 1 being a pointer that points one past the end of the array. Even though len will be 0 and we won't memcpy() anything, this is (depending on how you choose to intepret things the C standard doesn't come right out and state explicitly) undefined behaviour, because memcpy() wants to be passed valid pointers, even if you ask it to do no work with a zero len.

Quoted 4 lines

This isn't going to be a visible bug in practical terms, but it would make Coverity happy if we either (a) rejected a request with an empty length or else (b) skipped the memcpy(). I don't know enough about IPMI to know which is better.

Hmm. In some cases you have to accept a zero-length packet (as described in the comments), but if you said:

  if (len > 0)
      memcpy(sid->inmsg + sid->inlen, buf, len);

would that make Coverity happy? I was under the impression that if you passed zero into len, you could pass anything into the data on a memcpy. But apparently not; I can make this change.

-corey

Quoted 15 lines

hw/ipmi/smbus_ipmi.c line 292

Quoted 11 lines
hw/ipmi/smbus_ipmi.c new file +10 -0
+        sid->inlen += len;
+        break;
+    }
+
+    if (send && sid->inlen) {
+        smbus_ipmi_send_msg(sid);
+    }
+
+    return ret;
+}

thanks
-- PMM

#21 lore raw

Re: [PATCH 12/15] ipmi: Add an SMBus IPMI interface

Quoted 27 lines · Corey Minyard
Quoted 7 lines · Peter Maydell
Quoted 5 lines · On Thu, 19 Sept 2019 at 22:39, <[email protected]> wrote:

From: Corey Minyard <[email protected]>

---

Thank you for the ping. Comments inline...

Quoted 11 lines

...calling memcpy() with argument 1 being a pointer that points one past the end of the array. Even though len will be 0 and we won't memcpy() anything, this is (depending on how you choose to intepret things the C standard doesn't come right out and state explicitly) undefined behaviour, because memcpy() wants to be passed valid pointers, even if you ask it to do no work with a zero len.

This isn't going to be a visible bug in practical terms, but it would make Coverity happy if we either (a) rejected a request with an empty length or else (b) skipped the memcpy(). I don't know enough about IPMI to know which is better.

Hmm. In some cases you have to accept a zero-length packet (as described in the comments), but if you said:

Quoted 6 lines
  if (len > 0)
      memcpy(sid->inmsg + sid->inlen, buf, len);

would that make Coverity happy? I was under the impression that if you passed zero into len, you could pass anything into the data on a memcpy. But apparently not; I can make this change.

Yes, putting an if() around the memcpy() will be enough to avoid the undefined behaviour. (NB that you want braces {} on it ;-))

thanks
-- PMM

#22 lore raw

PATCH 13/15 acpi: Add i2c serial bus CRS handling

In reply to [email protected]

From: Corey Minyard <[email protected]>

This will be required for getting IPMI SSIF (SMBus interface) into the ACPI tables.

Cc Michael S. Tsirkin <[email protected]>
Cc Igor Mammedov <[email protected]>
---
 hw/acpi/aml-build.c         | 40 +++++++++++++++++++++++++++++++++++++
 include/hw/acpi/aml-build.h | 18 +++++++++++++++++
 2 files changed, 58 insertions(+)
hw/acpi/aml-build.c +40 -0
index 78aee1a2f9..2c3702b882 100644
@@ -1874,3 +1874,43 @@ build_hdr:
     build_header(linker, tbl, (void *)(tbl->data + fadt_start),
                  "FACP", tbl->len - fadt_start, f->rev, oem_id, oem_table_id);
 }
+
+/* ACPI 5.0: 6.4.3.8.2 Serial Bus Connection Descriptors */
+static Aml *aml_serial_bus_device(uint8_t serial_bus_type, uint8_t flags,
+                                  uint16_t type_flags,
+                                  uint8_t revid, uint16_t data_length,
+                                  uint16_t resource_source_len)
+{
+    Aml *var = aml_alloc();
+    uint16_t length = data_length + resource_source_len + 9;
+
+    build_append_byte(var->buf, 0x8e); /* Serial Bus Connection Descriptor */
+    build_append_int_noprefix(var->buf, length, sizeof(length));
+    build_append_byte(var->buf, 1);    /* Revision ID */
+    build_append_byte(var->buf, 0);    /* Resource Source Index */
+    build_append_byte(var->buf, serial_bus_type); /* Serial Bus Type */
+    build_append_byte(var->buf, flags); /* General Flags */
+    build_append_int_noprefix(var->buf, type_flags, /* Type Specific Flags */
+                              sizeof(type_flags));
+    build_append_byte(var->buf, revid); /* Type Specification Revision ID */
+    build_append_int_noprefix(var->buf, data_length, sizeof(data_length));
+
+    return var;
+}
+
+/* ACPI 5.0: 6.4.3.8.2.1 I2C Serial Bus Connection Resource Descriptor */
+Aml *aml_i2c_serial_bus_device(uint16_t address, const char *resource_source)
+{
+    uint16_t resource_source_len = strlen(resource_source) + 1;
+    Aml *var = aml_serial_bus_device(AML_SERIAL_BUS_TYPE_I2C, 0, 0, 1,
+                                     6, resource_source_len);
+
+    /* Connection Speed.  Just set to 100K for now, it doesn't really matter. */
+    build_append_int_noprefix(var->buf, 100000, 4);
+    build_append_int_noprefix(var->buf, address, sizeof(address));
+
+    /* This is a string, not a name, so just copy it directly in. */
+    g_array_append_vals(var->buf, resource_source, resource_source_len);
+
+    return var;
+}
include/hw/acpi/aml-build.h +18 -0
index 991cf05134..de4a406568 100644
@@ -223,6 +223,23 @@ struct AcpiBuildTables {
     BIOSLinker *linker;
 } AcpiBuildTables;
 
+/*
+ * ACPI 5.0: 6.4.3.8.2 Serial Bus Connection Descriptors
+ * Serial Bus Type
+ */
+#define AML_SERIAL_BUS_TYPE_I2C  1
+#define AML_SERIAL_BUS_TYPE_SPI  2
+#define AML_SERIAL_BUS_TYPE_UART 3
+
+/*
+ * ACPI 5.0: 6.4.3.8.2 Serial Bus Connection Descriptors
+ * General Flags
+ */
+/* Slave Mode */
+#define AML_SERIAL_BUS_FLAG_MASTER_DEVICE       (1 << 0)
+/* Consumer/Producer */
+#define AML_SERIAL_BUS_FLAG_CONSUME_ONLY        (1 << 1)
+
 /**
  * init_aml_allocator:
  *
@@ -347,6 +364,7 @@ Aml *aml_qword_memory(AmlDecode dec, AmlMinFixed min_fixed,
 Aml *aml_dma(AmlDmaType typ, AmlDmaBusMaster bm, AmlTransferSize sz,
              uint8_t channel);
 Aml *aml_sleep(uint64_t msec);
+Aml *aml_i2c_serial_bus_device(uint16_t address, const char *resource_source);
 
 /* Block AML object primitives */
 Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
Signature · 1 line
2.17.1
#23 lore raw

PATCH 14/15 ipmi: Fix SSIF ACPI handling to use the right CRS

In reply to [email protected]

From: Corey Minyard <[email protected]>

Pass in the CRS so that it can be set to the SMBus for IPMI later.

Cc Michael S. Tsirkin <[email protected]>
Cc Igor Mammedov <[email protected]>
---
 hw/acpi/ipmi-stub.c    |  2 +-
 hw/acpi/ipmi.c         | 13 +++++++------
 hw/i386/acpi-build.c   |  2 +-
 include/hw/acpi/ipmi.h |  2 +-
 4 files changed, 10 insertions(+), 9 deletions(-)
hw/acpi/ipmi-stub.c +1 -1
index f525f71c2d..8634fb325c 100644
@@ -10,6 +10,6 @@
 #include "qemu/osdep.h"
 #include "hw/acpi/ipmi.h"
 
-void build_acpi_ipmi_devices(Aml *table, BusState *bus)
+void build_acpi_ipmi_devices(Aml *table, BusState *bus, const char *resource)
 {
 }
hw/acpi/ipmi.c +7 -6
index 651e2e94ea..96e48eba15 100644
@@ -13,7 +13,7 @@
 #include "hw/acpi/acpi.h"
 #include "hw/acpi/ipmi.h"
 
-static Aml *aml_ipmi_crs(IPMIFwInfo *info)
+static Aml *aml_ipmi_crs(IPMIFwInfo *info, const char *resource)
 {
     Aml *crs = aml_resource_template();
 
@@ -48,7 +48,8 @@ static Aml *aml_ipmi_crs(IPMIFwInfo *info)
                             info->register_spacing, info->register_length));
         break;
     case IPMI_MEMSPACE_SMBUS:
-        aml_append(crs, aml_return(aml_int(info->base_address)));
+        aml_append(crs, aml_i2c_serial_bus_device(info->base_address,
+                                                  resource));
         break;
     default:
         abort();
@@ -61,7 +62,7 @@ static Aml *aml_ipmi_crs(IPMIFwInfo *info)
     return crs;
 }
 
-static Aml *aml_ipmi_device(IPMIFwInfo *info)
+static Aml *aml_ipmi_device(IPMIFwInfo *info, const char *resource)
 {
     Aml *dev;
     uint16_t version = ((info->ipmi_spec_major_revision << 8)
@@ -74,14 +75,14 @@ static Aml *aml_ipmi_device(IPMIFwInfo *info)
     aml_append(dev, aml_name_decl("_STR", aml_string("ipmi_%s",
                                                      info->interface_name)));
     aml_append(dev, aml_name_decl("_UID", aml_int(info->uuid)));
-    aml_append(dev, aml_name_decl("_CRS", aml_ipmi_crs(info)));
+    aml_append(dev, aml_name_decl("_CRS", aml_ipmi_crs(info, resource)));
     aml_append(dev, aml_name_decl("_IFT", aml_int(info->interface_type)));
     aml_append(dev, aml_name_decl("_SRV", aml_int(version)));
 
     return dev;
 }
 
-void build_acpi_ipmi_devices(Aml *scope, BusState *bus)
+void build_acpi_ipmi_devices(Aml *scope, BusState *bus, const char *resource)
 {
 
     BusChild *kid;
@@ -101,6 +102,6 @@ void build_acpi_ipmi_devices(Aml *scope, BusState *bus)
         iic = IPMI_INTERFACE_GET_CLASS(obj);
         memset(&info, 0, sizeof(info));
         iic->get_fwinfo(ii, &info);
-        aml_append(scope, aml_ipmi_device(&info));
+        aml_append(scope, aml_ipmi_device(&info, resource));
     }
 }
hw/i386/acpi-build.c +1 -1
index e54e571a75..8acf12df9a 100644
@@ -1290,7 +1290,7 @@ static void build_isa_devices_aml(Aml *table)
     } else if (!obj) {
         error_report("No ISA bus, unable to define IPMI ACPI data");
     } else {
-        build_acpi_ipmi_devices(scope, BUS(obj));
+        build_acpi_ipmi_devices(scope, BUS(obj), "\\_SB.PCI0.ISA");
     }
 
     aml_append(table, scope);
include/hw/acpi/ipmi.h +1 -1
index c38483565c..c14ad682ac 100644
@@ -16,6 +16,6 @@
  * bus matches the given bus.  The resource is the ACPI resource that
  * contains the IPMI device, this is required for the I2C CRS.
  */
-void build_acpi_ipmi_devices(Aml *table, BusState *bus);
+void build_acpi_ipmi_devices(Aml *table, BusState *bus, const char *resource);
 
 #endif /* HW_ACPI_IPMI_H */
Signature · 1 line
2.17.1
#24 lore raw

PATCH 15/15 pc: Add an SMB0 ACPI device to q35

In reply to [email protected]

From: Corey Minyard <[email protected]>

This is so I2C devices can be found in the ACPI namespace. Currently that's only IPMI, but devices can be easily added now.

Adding the devices required some PCI information, and the bus itself to be added to the PCMachineState structure.

Note that this only works on Q35, the ACPI for PIIX4 is not capable of handling an SMBus device.

Cc Michael S. Tsirkin <[email protected]>
Cc Igor Mammedov <[email protected]>
---
 hw/i386/acpi-build.c             |  15 +++++++++++++++
 hw/i386/pc_piix.c                |  12 ++++++------
 hw/i386/pc_q35.c                 |   9 +++++----
 include/hw/i386/pc.h             |   2 ++
 tests/data/acpi/q35/DSDT         | Bin 7841 -> 7879 bytes
 tests/data/acpi/q35/DSDT.bridge  | Bin 7858 -> 7896 bytes
 tests/data/acpi/q35/DSDT.cphp    | Bin 8304 -> 8342 bytes
 tests/data/acpi/q35/DSDT.dimmpxm | Bin 9494 -> 9532 bytes
 tests/data/acpi/q35/DSDT.ipmibt  | Bin 7916 -> 7954 bytes
 tests/data/acpi/q35/DSDT.memhp   | Bin 9200 -> 9238 bytes
 tests/data/acpi/q35/DSDT.mmio64  | Bin 8971 -> 9009 bytes
 tests/data/acpi/q35/DSDT.numamem | Bin 7847 -> 7885 bytes
 12 files changed, 28 insertions(+), 10 deletions(-)
hw/i386/acpi-build.c +15 -0
index 8acf12df9a..4e0f9f425a 100644
@@ -1809,6 +1809,18 @@ static Aml *build_q35_osc_method(void)
     return method;
 }
 
+static void build_smb0(Aml *table, I2CBus *smbus, int devnr, int func)
+{
+    Aml *scope = aml_scope("_SB.PCI0");
+    Aml *dev = aml_device("SMB0");
+
+    aml_append(dev, aml_name_decl("_HID", aml_eisaid("APP0005")));
+    aml_append(dev, aml_name_decl("_ADR", aml_int(devnr << 16 | func)));
+    build_acpi_ipmi_devices(dev, BUS(smbus), "\\_SB.PCI0.SMB0");
+    aml_append(scope, dev);
+    aml_append(table, scope);
+}
+
 static void
 build_dsdt(GArray *table_data, BIOSLinker *linker,
            AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -1862,6 +1874,9 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
         build_q35_isa_bridge(dsdt);
         build_isa_devices_aml(dsdt);
         build_q35_pci0_int(dsdt);
+        if (pcms->smbus && !pcmc->do_not_add_smb_acpi) {
+            build_smb0(dsdt, pcms->smbus, ICH9_SMB_DEV, ICH9_SMB_FUNC);
+        }
     }
 
     if (pcmc->legacy_cpu_hotplug) {
hw/i386/pc_piix.c +6 -6
index 2362675149..6824b72124 100644
@@ -283,15 +283,14 @@ else {
 
     if (pcmc->pci_enabled && acpi_enabled) {
         DeviceState *piix4_pm;
-        I2CBus *smbus;
 
         smi_irq = qemu_allocate_irq(pc_acpi_smi_interrupt, first_cpu, 0);
         /* TODO: Populate SPD eeprom data.  */
-        smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
-                              pcms->gsi[9], smi_irq,
-                              pc_machine_is_smm_enabled(pcms),
-                              &piix4_pm);
-        smbus_eeprom_init(smbus, 8, NULL, 0);
+        pcms->smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
+                                    pcms->gsi[9], smi_irq,
+                                    pc_machine_is_smm_enabled(pcms),
+                                    &piix4_pm);
+        smbus_eeprom_init(pcms->smbus, 8, NULL, 0);
 
         object_property_add_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_PROP,
                                  TYPE_HOTPLUG_HANDLER,
@@ -476,6 +475,7 @@ static void pc_i440fx_3_1_machine_options(MachineClass *m)
 
     pc_i440fx_4_0_machine_options(m);
     m->is_default = 0;
+    pcmc->do_not_add_smb_acpi = true;
     m->smbus_no_migration_support = true;
     m->alias = NULL;
     pcmc->pvh_enabled = false;
hw/i386/pc_q35.c +5 -4
index d4e8a1cb9f..8fad20f314 100644
@@ -316,10 +316,10 @@ static void pc_q35_init(MachineState *machine)
 
     if (pcms->smbus_enabled) {
         /* TODO: Populate SPD eeprom data.  */
-        smbus_eeprom_init(ich9_smb_init(host_bus,
-                                        PCI_DEVFN(ICH9_SMB_DEV, ICH9_SMB_FUNC),
-                                        0xb100),
-                          8, NULL, 0);
+        pcms->smbus = ich9_smb_init(host_bus,
+                                    PCI_DEVFN(ICH9_SMB_DEV, ICH9_SMB_FUNC),
+                                    0xb100);
+        smbus_eeprom_init(pcms->smbus, 8, NULL, 0);
     }
 
     pc_cmos_init(pcms, idebus[0], idebus[1], rtc_state);
@@ -421,6 +421,7 @@ static void pc_q35_3_1_machine_options(MachineClass *m)
 
     pc_q35_4_0_machine_options(m);
     m->default_kernel_irqchip_split = false;
+    pcmc->do_not_add_smb_acpi = true;
     m->smbus_no_migration_support = true;
     m->alias = NULL;
     pcmc->pvh_enabled = false;
include/hw/i386/pc.h +2 -0
index 062feeb69e..6df4f4b6fb 100644
@@ -38,6 +38,7 @@ struct PCMachineState {
     HotplugHandler *acpi_dev;
     ISADevice *rtc;
     PCIBus *bus;
+    I2CBus *smbus;
     FWCfgState *fw_cfg;
     qemu_irq *gsi;
     PFlashCFI01 *flash[2];
@@ -117,6 +118,7 @@ typedef struct PCMachineClass {
     bool rsdp_in_ram;
     int legacy_acpi_table_size;
     unsigned acpi_data_size;
+    bool do_not_add_smb_acpi;
 
     /* SMBIOS compat: */
     bool smbios_defaults;
tests/data/acpi/q35/DSDT binary +0 -0
index f9f36d1645c9b57aea38350d67dfaa143845697d..77ea60ffed421c566138fe6341421f579129a582 100644
GIT binary patch
tests/data/acpi/q35/DSDT.bridge binary +0 -0
index 29176832ca9842c6654273ae1246321aa38b2821..fbc2d40000428b402586ea9302b5ccf36ef8de1e 100644
GIT binary patch
tests/data/acpi/q35/DSDT.cphp binary +0 -0
index 19bdb5d21050f24aaacbafb1f84d6e1d541876c6..6a896cb2142feadbcabc6276b59c138a7e93f540 100644
GIT binary patch
tests/data/acpi/q35/DSDT.dimmpxm binary +0 -0
index 727fe489b4c8cdd39476ff61e7d7664c816f5291..23fdf5e60a5069f60d6c680ac9c68c4a8a81318e 100644
GIT binary patch
tests/data/acpi/q35/DSDT.ipmibt binary +0 -0
index 9634930e6125de4375d87a56a353f636985599d4..c3fca0a71efa7b55c958a49f305389426fbe7922 100644
GIT binary patch
tests/data/acpi/q35/DSDT.memhp binary +0 -0
index dad5dc8db2f13bdb0de001da42c13b18286c3061..2abd0e36cd1344cbca3fa4ab59c5db2ea326d125 100644
GIT binary patch
tests/data/acpi/q35/DSDT.mmio64 binary +0 -0
index 20f627ed08a0cae4e144f3e4dd7dd5f1d8d0318c..b32034a11c1f8a0a156df3765df44b14a88dbb4d 100644
GIT binary patch
tests/data/acpi/q35/DSDT.numamem binary +0 -0
index 7b96a972804e95e191d9d3bf9a965e90f6f7e555..d8b2b47f8b47067d375021a30086ca97d8aca43f 100644
GIT binary patch
Signature · 1 line
2.17.1
#25 lore raw
In reply to [email protected]
Quoted 5 lines · On 19/09/19 23:39, [email protected] wrote:

I haven't gotten a lot of commentary on this, but I assume that means that everything is ok. It's been posted a few times and the last time I received no issues, just a couple of reviews. I would like more review. But I'm not quite sure what to do about that, I've been hanging on to these changes far too long.

It's just that not many people here are IPMI-savvy. I took a quick look at patches 5 and 15, and they look fine.

Paolo

Quoted 94 lines

The following changes since commit a77d20bafcd4cb7684168a9b4c6dc2a321aaeb50:

Merge remote-tracking branch 'remotes/kraxel/tags/ui-20190919-pull-request' into staging (2019-09-19 17:16:07 +0100)

are available in the Git repository at:

https://github.com/cminyard/qemu.git tags/ipmi-for-release-2019-09-19

for you to fetch changes up to d9b74295c6528fd68cebdea116b283e46543b2a2:

pc: Add an SMB0 ACPI device to q35 (2019-09-19 14:41:58 -0500)

----------------------------------------------------------------
ipmi: Some bug fixes and new interfaces

Some bug fixes for the watchdog and hopeful the BT tests.

Change the IPMI UUID handling to give the user the ability to set it or not have it.

Add a PCI interface.

Add an SMBus interfaces.

-corey

----------------------------------------------------------------
Corey Minyard (15):
ipmi: Fix watchdog NMI handling
ipmi: Fix the get watchdog command
ipmi: Generate an interrupt on watchdog pretimeout expiry tests:ipmi: Fix IPMI BT tests
qdev: Add a no default uuid property
ipmi: Add a UUID device property
ipmi: Split out KCS-specific code from ISA KCS code
ipmi: Split out BT-specific code from ISA BT code
ipmi: Allow a size value to be passed for I/O space smbios:ipmi: Ignore IPMI devices with no fwinfo function
ipmi: Add PCI IPMI interfaces
ipmi: Add an SMBus IPMI interface
acpi: Add i2c serial bus CRS handling
ipmi: Fix SSIF ACPI handling to use the right CRS
pc: Add an SMB0 ACPI device to q35

 default-configs/i386-softmmu.mak |   3 +
 hw/acpi/aml-build.c              |  40 ++++
 hw/acpi/ipmi-stub.c              |   2 +-
 hw/acpi/ipmi.c                   |  13 +-
 hw/i386/Kconfig                  |   3 +
 hw/i386/acpi-build.c             |  17 +-
 hw/i386/pc_piix.c                |  12 +-
 hw/i386/pc_q35.c                 |   9 +-
 hw/ipmi/Kconfig                  |  15 ++
 hw/ipmi/Makefile.objs            |   5 +-
 hw/ipmi/ipmi.c                   |   6 +-
 hw/ipmi/ipmi_bmc_sim.c           |  30 ++-
 hw/ipmi/ipmi_bt.c                | 437 ++++++++++++++++++++++++++++++++++++++
 hw/ipmi/ipmi_kcs.c               | 423 +++++++++++++++++++++++++++++++++++++
 hw/ipmi/isa_ipmi_bt.c            | 443 ++-------------------------------------
 hw/ipmi/isa_ipmi_kcs.c           | 419 ++----------------------------------
 hw/ipmi/pci_ipmi_bt.c            | 146 +++++++++++++
 hw/ipmi/pci_ipmi_kcs.c           | 146 +++++++++++++
 hw/ipmi/smbus_ipmi.c             | 384 +++++++++++++++++++++++++++++++++
 hw/smbios/smbios_type_38.c       |   3 +
 include/hw/acpi/aml-build.h      |  18 ++
 include/hw/acpi/ipmi.h           |   2 +-
 include/hw/i386/pc.h             |   2 +
 include/hw/ipmi/ipmi.h           |   7 +-
 include/hw/ipmi/ipmi_bt.h        |  73 +++++++
 include/hw/ipmi/ipmi_kcs.h       |  76 +++++++
 include/hw/pci/pci.h             |   1 +
 include/hw/qdev-properties.h     |   7 +
 qemu-options.hx                  |  10 +-
 tests/Makefile.include           |   3 +-
 tests/data/acpi/q35/DSDT         | Bin 7841 -> 7879 bytes
 tests/data/acpi/q35/DSDT.bridge  | Bin 7858 -> 7896 bytes
 tests/data/acpi/q35/DSDT.cphp    | Bin 8304 -> 8342 bytes
 tests/data/acpi/q35/DSDT.dimmpxm | Bin 9494 -> 9532 bytes
 tests/data/acpi/q35/DSDT.ipmibt  | Bin 7916 -> 7954 bytes
 tests/data/acpi/q35/DSDT.memhp   | Bin 9200 -> 9238 bytes
 tests/data/acpi/q35/DSDT.mmio64  | Bin 8971 -> 9009 bytes
 tests/data/acpi/q35/DSDT.numamem | Bin 7847 -> 7885 bytes
 tests/ipmi-bt-test.c             |   6 +-
 39 files changed, 1902 insertions(+), 859 deletions(-)
 create mode 100644 hw/ipmi/ipmi_bt.c
 create mode 100644 hw/ipmi/ipmi_kcs.c
 create mode 100644 hw/ipmi/pci_ipmi_bt.c
 create mode 100644 hw/ipmi/pci_ipmi_kcs.c
 create mode 100644 hw/ipmi/smbus_ipmi.c
 create mode 100644 include/hw/ipmi/ipmi_bt.h
 create mode 100644 include/hw/ipmi/ipmi_kcs.h
#26 lore raw
Quoted 9 lines · Paolo Bonzini
Quoted 5 lines · On 19/09/19 23:39, [email protected] wrote:

I haven't gotten a lot of commentary on this, but I assume that means that everything is ok. It's been posted a few times and the last time I received no issues, just a couple of reviews. I would like more review. But I'm not quite sure what to do about that, I've been hanging on to these changes far too long.

It's just that not many people here are IPMI-savvy. I took a quick look at patches 5 and 15, and they look fine.

Thanks a bunch for looking at those. Patch 15 was my biggest worry.

-corey

Quoted 98 lines

Paolo

Quoted 94 lines

The following changes since commit a77d20bafcd4cb7684168a9b4c6dc2a321aaeb50:

Merge remote-tracking branch 'remotes/kraxel/tags/ui-20190919-pull-request' into staging (2019-09-19 17:16:07 +0100)

are available in the Git repository at:

https://github.com/cminyard/qemu.git tags/ipmi-for-release-2019-09-19

for you to fetch changes up to d9b74295c6528fd68cebdea116b283e46543b2a2:

pc: Add an SMB0 ACPI device to q35 (2019-09-19 14:41:58 -0500)

----------------------------------------------------------------
ipmi: Some bug fixes and new interfaces

Some bug fixes for the watchdog and hopeful the BT tests.

Change the IPMI UUID handling to give the user the ability to set it or not have it.

Add a PCI interface.

Add an SMBus interfaces.

-corey

----------------------------------------------------------------
Corey Minyard (15):
ipmi: Fix watchdog NMI handling
ipmi: Fix the get watchdog command
ipmi: Generate an interrupt on watchdog pretimeout expiry tests:ipmi: Fix IPMI BT tests
qdev: Add a no default uuid property
ipmi: Add a UUID device property
ipmi: Split out KCS-specific code from ISA KCS code
ipmi: Split out BT-specific code from ISA BT code
ipmi: Allow a size value to be passed for I/O space smbios:ipmi: Ignore IPMI devices with no fwinfo function
ipmi: Add PCI IPMI interfaces
ipmi: Add an SMBus IPMI interface
acpi: Add i2c serial bus CRS handling
ipmi: Fix SSIF ACPI handling to use the right CRS
pc: Add an SMB0 ACPI device to q35

 default-configs/i386-softmmu.mak |   3 +
 hw/acpi/aml-build.c              |  40 ++++
 hw/acpi/ipmi-stub.c              |   2 +-
 hw/acpi/ipmi.c                   |  13 +-
 hw/i386/Kconfig                  |   3 +
 hw/i386/acpi-build.c             |  17 +-
 hw/i386/pc_piix.c                |  12 +-
 hw/i386/pc_q35.c                 |   9 +-
 hw/ipmi/Kconfig                  |  15 ++
 hw/ipmi/Makefile.objs            |   5 +-
 hw/ipmi/ipmi.c                   |   6 +-
 hw/ipmi/ipmi_bmc_sim.c           |  30 ++-
 hw/ipmi/ipmi_bt.c                | 437 ++++++++++++++++++++++++++++++++++++++
 hw/ipmi/ipmi_kcs.c               | 423 +++++++++++++++++++++++++++++++++++++
 hw/ipmi/isa_ipmi_bt.c            | 443 ++-------------------------------------
 hw/ipmi/isa_ipmi_kcs.c           | 419 ++----------------------------------
 hw/ipmi/pci_ipmi_bt.c            | 146 +++++++++++++
 hw/ipmi/pci_ipmi_kcs.c           | 146 +++++++++++++
 hw/ipmi/smbus_ipmi.c             | 384 +++++++++++++++++++++++++++++++++
 hw/smbios/smbios_type_38.c       |   3 +
 include/hw/acpi/aml-build.h      |  18 ++
 include/hw/acpi/ipmi.h           |   2 +-
 include/hw/i386/pc.h             |   2 +
 include/hw/ipmi/ipmi.h           |   7 +-
 include/hw/ipmi/ipmi_bt.h        |  73 +++++++
 include/hw/ipmi/ipmi_kcs.h       |  76 +++++++
 include/hw/pci/pci.h             |   1 +
 include/hw/qdev-properties.h     |   7 +
 qemu-options.hx                  |  10 +-
 tests/Makefile.include           |   3 +-
 tests/data/acpi/q35/DSDT         | Bin 7841 -> 7879 bytes
 tests/data/acpi/q35/DSDT.bridge  | Bin 7858 -> 7896 bytes
 tests/data/acpi/q35/DSDT.cphp    | Bin 8304 -> 8342 bytes
 tests/data/acpi/q35/DSDT.dimmpxm | Bin 9494 -> 9532 bytes
 tests/data/acpi/q35/DSDT.ipmibt  | Bin 7916 -> 7954 bytes
 tests/data/acpi/q35/DSDT.memhp   | Bin 9200 -> 9238 bytes
 tests/data/acpi/q35/DSDT.mmio64  | Bin 8971 -> 9009 bytes
 tests/data/acpi/q35/DSDT.numamem | Bin 7847 -> 7885 bytes
 tests/ipmi-bt-test.c             |   6 +-
 39 files changed, 1902 insertions(+), 859 deletions(-)
 create mode 100644 hw/ipmi/ipmi_bt.c
 create mode 100644 hw/ipmi/ipmi_kcs.c
 create mode 100644 hw/ipmi/pci_ipmi_bt.c
 create mode 100644 hw/ipmi/pci_ipmi_kcs.c
 create mode 100644 hw/ipmi/smbus_ipmi.c
 create mode 100644 include/hw/ipmi/ipmi_bt.h
 create mode 100644 include/hw/ipmi/ipmi_kcs.h
#27 lore raw
In reply to [email protected]
Quoted 22 lines · On Thu, 19 Sep 2019 at 22:39, <[email protected]> wrote:

I haven't gotten a lot of commentary on this, but I assume that means that everything is ok. It's been posted a few times and the last time I received no issues, just a couple of reviews. I would like more review. But I'm not quite sure what to do about that, I've been hanging on to these changes far too long.

The following changes since commit a77d20bafcd4cb7684168a9b4c6dc2a321aaeb50:

Merge remote-tracking branch 'remotes/kraxel/tags/ui-20190919-pull-request' into staging (2019-09-19 17:16:07 +0100)

are available in the Git repository at:

https://github.com/cminyard/qemu.git tags/ipmi-for-release-2019-09-19

for you to fetch changes up to d9b74295c6528fd68cebdea116b283e46543b2a2:

pc: Add an SMB0 ACPI device to q35 (2019-09-19 14:41:58 -0500)

----------------------------------------------------------------
ipmi: Some bug fixes and new interfaces

Quoted 8 lines

Some bug fixes for the watchdog and hopeful the BT tests.

Change the IPMI UUID handling to give the user the ability to set it or not have it.

Add a PCI interface.

Add an SMBus interfaces.

Hi -- is this intended to be a pull request to be applied to master? It's in the form of a pullreq but the subject header says "PATCH" and you seem to be asking for more review, so I'm not sure...

thanks
-- PMM

#28 lore raw
Quoted 28 lines · Peter Maydell
Quoted 27 lines · On Thu, 19 Sep 2019 at 22:39, <[email protected]> wrote:

I haven't gotten a lot of commentary on this, but I assume that means that everything is ok. It's been posted a few times and the last time I received no issues, just a couple of reviews. I would like more review. But I'm not quite sure what to do about that, I've been hanging on to these changes far too long.

The following changes since commit a77d20bafcd4cb7684168a9b4c6dc2a321aaeb50:

Merge remote-tracking branch 'remotes/kraxel/tags/ui-20190919-pull-request' into staging (2019-09-19 17:16:07 +0100)

are available in the Git repository at:

https://github.com/cminyard/qemu.git tags/ipmi-for-release-2019-09-19

for you to fetch changes up to d9b74295c6528fd68cebdea116b283e46543b2a2:

pc: Add an SMB0 ACPI device to q35 (2019-09-19 14:41:58 -0500)

----------------------------------------------------------------
ipmi: Some bug fixes and new interfaces

Some bug fixes for the watchdog and hopeful the BT tests.

Change the IPMI UUID handling to give the user the ability to set it or not have it.

Quoted 8 lines
Quoted 3 lines

Add a PCI interface.

Add an SMBus interfaces.

Hi -- is this intended to be a pull request to be applied to master? It's in the form of a pullreq but the subject header says "PATCH" and you seem to be asking for more review, so I'm not sure...

Dang, it was meant to be a pull request for master. I would like more review, and I didn't think I would get any, but it turns out I have gotten it for the most important parts, so pulling it should be good, I think.

I can add the reviews and request a pull properly, if you like.

Thanks,

-corey

Quoted 3 lines

thanks
-- PMM

#29 lore raw
Quoted 7 lines · Corey Minyard
Quoted 4 lines · Peter Maydell

Hi -- is this intended to be a pull request to be applied to master? It's in the form of a pullreq but the subject header says "PATCH" and you seem to be asking for more review, so I'm not sure...

Quoted 6 lines

Dang, it was meant to be a pull request for master. I would like more review, and I didn't think I would get any, but it turns out I have gotten it for the most important parts, so pulling it should be good, I think.

I can add the reviews and request a pull properly, if you like.

If you got some extra reviewed-by tags it would be nice to respin with them added, I guess. You can just resend the cover letter, no need to send all the patches again.

thanks
-- PMM