Skip to contentSkip to conversation

Add an IPMI device to QEMU

PATCH Superseded [email protected] 7 participants 28 messages Nov 12, 2015 – Nov 26, 2015

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add an IPMI device to QEMU

This is a long delayed patch set, but I think I have things reworked to make Igor happy with the way ACPI and SMBIOS work. This is more consistent with the way most other things work, anyway. It did require adding stubs for systems without IPMI.

The first nine patches are unchanged.

The IPMI firmware configuration storage now holds the firmware information in a data structure and lets it be iterated.

SMBIOS and ACPI build the tables with their existing building functions and call out to the IPMI one (or the stub) when the time comes. This required pulling some code out of smbios.c into an include file and making some things global, as IPMI has to be configurable.

The BIOS table tests were also modified since the ACPI info is now in the existing SSDT.

I've also added a force-off function for external BMCs; an external BMC needs a way to do a hard power-off of the system if the soft power offs fail.

Thanks all!

-corey

#8 lore raw

PATCH v4 4/17 ipmi: Add an external connection simulation interface

From: Corey Minyard <[email protected]>

This adds an interface for IPMI that connects to a remote BMC over a chardev (generally a TCP socket). The OpenIPMI lanserv simulator describes this interface, see that for interface details.

---
 default-configs/i386-softmmu.mak   |   1 +
 default-configs/x86_64-softmmu.mak |   1 +
 hw/ipmi/Makefile.objs              |   1 +
 hw/ipmi/ipmi_bmc_extern.c          | 478 +++++++++++++++++++++++++++++++++++++
 4 files changed, 481 insertions(+)
 create mode 100644 hw/ipmi/ipmi_bmc_extern.c
default-configs/i386-softmmu.mak +1 -0
index 00a0346..077b3c4 100644
@@ -11,6 +11,7 @@ CONFIG_VIRTIO_VGA=y
 CONFIG_VMMOUSE=y
 CONFIG_IPMI=y
 CONFIG_IPMI_LOCAL=y
+CONFIG_IPMI_EXTERN=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
default-configs/x86_64-softmmu.mak +1 -0
index 39a619f..81b0cb0 100644
@@ -11,6 +11,7 @@ CONFIG_VIRTIO_VGA=y
 CONFIG_VMMOUSE=y
 CONFIG_IPMI=y
 CONFIG_IPMI_LOCAL=y
+CONFIG_IPMI_EXTERN=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
hw/ipmi/Makefile.objs +1 -0
index 875271c..ddb15ec 100644
@@ -1,2 +1,3 @@
 common-obj-$(CONFIG_IPMI) += ipmi.o
 common-obj-$(CONFIG_IPMI_LOCAL) += ipmi_bmc_sim.o
+common-obj-$(CONFIG_IPMI_LOCAL) += ipmi_bmc_extern.o
hw/ipmi/ipmi_bmc_extern.c new file +478 -0

478 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#14 lore raw

PATCH v4 10/17 ipmi: Add a firmware configuration repository

In reply to [email protected]

From: Corey Minyard <[email protected]>

Add a way for IPMI devices to register their firmware information with the IPMI subsystem so that various firmware entities can pull that information later for adding to firmware tables.

---
 hw/ipmi/ipmi.c         | 27 +++++++++++++++++++++++++++
 include/hw/ipmi/ipmi.h | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)
hw/ipmi/ipmi.c +27 -0
index 7d17469..52aba1e 100644
@@ -123,3 +123,30 @@ static void ipmi_register_types(void)
 }
 
 type_init(ipmi_register_types)
+
+static IPMIFwInfo *ipmi_fw_info;
+static unsigned int ipmi_fw_info_len;
+
+static uint32_t current_uuid = 1;
+
+void ipmi_add_fwinfo(IPMIFwInfo *info, Error **errp)
+{
+    info->uuid = current_uuid++;
+    ipmi_fw_info = g_realloc(ipmi_fw_info,
+                             sizeof(*ipmi_fw_info) * (ipmi_fw_info_len + 1));
+    ipmi_fw_info[ipmi_fw_info_len] = *info;
+}
+
+IPMIFwInfo *ipmi_first_fwinfo(void)
+{
+    return ipmi_fw_info;
+}
+
+IPMIFwInfo *ipmi_next_fwinfo(IPMIFwInfo *current)
+{
+    current++;
+    if (current >= &ipmi_fw_info[ipmi_fw_info_len]) {
+        return NULL;
+    }
+    return current;
+}
include/hw/ipmi/ipmi.h +35 -0
index e4f7738..74e84a0 100644
@@ -168,6 +168,41 @@ typedef struct IPMIBmcClass {
  */
 void ipmi_bmc_find_and_link(Object *obj, Object **bmc);
 
+/*
+ * Used for transferring information to interfaces that add 
+ * entries to firmware tables.
+ */
+typedef struct IPMIFwInfo {
+    const char *interface_name;
+    int interface_type;
+    uint8_t ipmi_spec_major_revision;
+    uint8_t ipmi_spec_minor_revision;
+    uint8_t i2c_slave_address;
+    uint32_t uuid;
+
+    uint64_t base_address;
+    uint64_t register_length;
+    uint8_t register_spacing;
+    enum {
+        IPMI_MEMSPACE_IO,
+        IPMI_MEMSPACE_MEM32,
+        IPMI_MEMSPACE_MEM64,
+        IPMI_MEMSPACE_SMBUS
+    } memspace;
+
+    int interrupt_number;
+    enum {
+        IPMI_LEVEL_IRQ,
+        IPMI_EDGE_IRQ
+    } irq_type;
+
+    const char *acpi_parent;
+} IPMIFwInfo;
+
+void ipmi_add_fwinfo(IPMIFwInfo *info, Error **errp);
+IPMIFwInfo *ipmi_first_fwinfo(void);
+IPMIFwInfo *ipmi_next_fwinfo(IPMIFwInfo *current);
+
 #ifdef IPMI_DEBUG
 #define ipmi_debug(fs, ...) \
     fprintf(stderr, "IPMI (%s): " fs, __func__, ##__VA_ARGS__)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v4 2/17 Add a base IPMI interface

In reply to [email protected]

From: Corey Minyard <[email protected]>

Add the basic IPMI types and infrastructure to QEMU. Low-level interfaces and simulation interfaces will register with this; it's kind of the go-between to tie them together.

---
 default-configs/i386-softmmu.mak   |   1 +
 default-configs/x86_64-softmmu.mak |   1 +
 hw/Makefile.objs                   |   1 +
 hw/ipmi/Makefile.objs              |   1 +
 hw/ipmi/ipmi.c                     | 125 ++++++++++++++++++++++++++
 include/hw/ipmi/ipmi.h             | 178 +++++++++++++++++++++++++++++++++++++
 qemu-doc.texi                      |   2 +
 7 files changed, 309 insertions(+)
 create mode 100644 hw/ipmi/Makefile.objs
 create mode 100644 hw/ipmi/ipmi.c
 create mode 100644 include/hw/ipmi/ipmi.h
default-configs/i386-softmmu.mak +1 -0
index 43c96d1..8fa751a 100644
@@ -9,6 +9,7 @@ CONFIG_VGA_CIRRUS=y
 CONFIG_VMWARE_VGA=y
 CONFIG_VIRTIO_VGA=y
 CONFIG_VMMOUSE=y
+CONFIG_IPMI=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
default-configs/x86_64-softmmu.mak +1 -0
index dfb8095..6767f4f 100644
@@ -9,6 +9,7 @@ CONFIG_VGA_CIRRUS=y
 CONFIG_VMWARE_VGA=y
 CONFIG_VIRTIO_VGA=y
 CONFIG_VMMOUSE=y
+CONFIG_IPMI=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
hw/Makefile.objs +1 -0
index 7e7c241..4a07ed4 100644
@@ -13,6 +13,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += ide/
 devices-dirs-$(CONFIG_SOFTMMU) += input/
 devices-dirs-$(CONFIG_SOFTMMU) += intc/
 devices-dirs-$(CONFIG_IPACK) += ipack/
+devices-dirs-$(CONFIG_IPMI) += ipmi/
 devices-dirs-$(CONFIG_SOFTMMU) += isa/
 devices-dirs-$(CONFIG_SOFTMMU) += misc/
 devices-dirs-$(CONFIG_SOFTMMU) += net/
hw/ipmi/Makefile.objs new file +1 -0
new file mode 100644
index 0000000..65bde11
@@ -0,0 +1 @@
+common-obj-$(CONFIG_IPMI) += ipmi.o
hw/ipmi/ipmi.c new file +125 -0

125 lines not on this page · raw message

include/hw/ipmi/ipmi.h new file +178 -0

178 lines not on this page · raw message

qemu-doc.texi +2 -0
index 460ab71..3c82d30 100644
@@ -195,6 +195,8 @@ PCI and ISA network adapters
 @item
 Serial ports
 @item
+IPMI BMC, either and internal or external one
+@item
 Creative SoundBlaster 16 sound card
 @item
 ENSONIQ AudioPCI ES1370 sound card
Signature · 1 line
1.8.3.1
#15 lore raw

PATCH v4 11/17 ipmi: Add firmware registration to the ISA interface

In reply to [email protected]

From: Corey Minyard <[email protected]>

---
 hw/ipmi/isa_ipmi_bt.c  | 15 +++++++++++++++
 hw/ipmi/isa_ipmi_kcs.c | 15 +++++++++++++++
 2 files changed, 30 insertions(+)
hw/ipmi/isa_ipmi_bt.c +15 -0
index 03eb9cc..21fa4a7 100644
@@ -407,6 +407,7 @@ typedef struct ISAIPMIBTDevice {
     ISADevice dev;
     int32 isairq;
     IPMIBT bt;
+    IPMIFwInfo fwinfo;
 } ISAIPMIBTDevice;
 
 static void isa_ipmi_bt_realize(DeviceState *dev, Error **errp)
@@ -435,6 +436,20 @@ static void isa_ipmi_bt_realize(DeviceState *dev, Error **errp)
     qdev_set_legacy_instance_id(dev, iib->bt.io_base, iib->bt.io_length);
 
     isa_register_ioport(isadev, &iib->bt.io, iib->bt.io_base);
+
+    iib->fwinfo.interface_name = "bt";
+    iib->fwinfo.interface_type = IPMI_SMBIOS_BT;
+    iib->fwinfo.ipmi_spec_major_revision = 2;
+    iib->fwinfo.ipmi_spec_minor_revision = 0;
+    iib->fwinfo.base_address = iib->bt.io_base;
+    iib->fwinfo.register_length = iib->bt.io_length;
+    iib->fwinfo.register_spacing = 1;
+    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;
+    ipmi_add_fwinfo(&iib->fwinfo, errp);
 }
 
 static const VMStateDescription vmstate_ISAIPMIBTDevice = {
hw/ipmi/isa_ipmi_kcs.c +15 -0
index b588711..c662aee 100644
@@ -370,6 +370,7 @@ typedef struct ISAIPMIKCSDevice {
     ISADevice dev;
     int32 isairq;
     IPMIKCS kcs;
+    IPMIFwInfo fwinfo;
 } ISAIPMIKCSDevice;
 
 static void ipmi_isa_realize(DeviceState *dev, Error **errp)
@@ -398,6 +399,20 @@ static void ipmi_isa_realize(DeviceState *dev, Error **errp)
     qdev_set_legacy_instance_id(dev, iik->kcs.io_base, iik->kcs.io_length);
 
     isa_register_ioport(isadev, &iik->kcs.io, iik->kcs.io_base);
+
+    iik->fwinfo.interface_name = "kcs";
+    iik->fwinfo.interface_type = IPMI_SMBIOS_KCS;
+    iik->fwinfo.ipmi_spec_major_revision = 2;
+    iik->fwinfo.ipmi_spec_minor_revision = 0;
+    iik->fwinfo.base_address = iik->kcs.io_base;
+    iik->fwinfo.i2c_slave_address = iik->kcs.bmc->slave_addr;
+    iik->fwinfo.register_length = iik->kcs.io_length;
+    iik->fwinfo.register_spacing = 1;
+    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";
+    ipmi_add_fwinfo(&iik->fwinfo, errp);
 }
 
 const VMStateDescription vmstate_ISAIPMIKCSDevice = {
Signature · 1 line
1.8.3.1
#12 lore raw

PATCH v4 8/17 ipmi: Add documentation

In reply to [email protected]

From: Corey Minyard <[email protected]>

Add some basic documentation for the IPMI device.

---
 qemu-options.hx | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
qemu-options.hx +52 -0
index 0eea4ee..985d2ab 100644
@@ -381,6 +381,58 @@ Add device @var{driver}.  @var{prop}=@var{value} sets driver
 properties.  Valid properties depend on the driver.  To get help on
 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}]
+
+Add an IPMI BMC.  This is a simulation of a hardware management
+interface processor that normally sits on a system.  It provides
+a watchdog and the ability to reset and power control the system.
+You need to connect this to an IPMI interface to make it useful
+
+The IPMI slave address to use for the BMC.  The default is 0x20.
+This address is the BMC's address on the I2C network of management
+controllers.  If you don't know what this means, it is safe to ignore
+it.
+
+@item -device ipmi-bmc-extern,id=@var{id},chardev=@var{id}[,slave_addr=@var{val}]
+
+Add a connection to an external IPMI BMC simulator.  Instead of
+locally emulating the BMC like the above item, instead connect
+to an external entity that provides the IPMI services.
+
+A connection is made to an external BMC simulator.  If you do this, it
+is strongly recommended that you use the "reconnect=" chardev option
+to reconnect to the simulator if the connection is lost.  Note that if
+this is not used carefully, it can be a security issue, as the
+interface has the ability to send resets, NMIs, and power off the VM.
+It's best if QEMU makes a connection to an external simulator running
+on a secure port on localhost, so neither the simulator nor QEMU is
+exposed to any outside network.
+
+See the "lanserv/README.vm" file in the OpenIPMI library for more
+details on the external interface.
+
+@item -device isa-ipmi-kcs,bmc=@var{id}[,ioport=@var{val}][,irq=@var{val}]
+
+Add a KCS IPMI interafce on the ISA bus.  This also adds a
+corresponding ACPI and SMBIOS entries, if appropriate.
+
+@table @option
+@item bmc=@var{id}
+The BMC to connect to, one of ipmi-bmc-sim or ipmi-bmc-extern above.
+@item ioport=@var{val}
+Define the I/O address of the interface.  The default is 0xca0 for KCS.
+@item irq=@var{val}
+Define the interrupt to use.  The default is 5.  To disable interrupts,
+set this to 0.
+@end table
+
+@item -device isa-ipmi-bt,bmc=@var{id}[,ioport=@var{val}][,irq=@var{val}]
+
+Like the KCS interface, but defines a BT interface.  The default port is
+0xe4 and the default interrupt is 5.
+
 ETEXI
 
 DEF("name", HAS_ARG, QEMU_OPTION_name,
Signature · 1 line
1.8.3.1
#13 lore raw

PATCH v4 9/17 ipmi: Add migration capability to the IPMI devices.

In reply to [email protected]

From: Corey Minyard <[email protected]>

---
 hw/ipmi/ipmi_bmc_extern.c | 34 ++++++++++++++++++++++++++++++++++
 hw/ipmi/ipmi_bmc_sim.c    | 30 ++++++++++++++++++++++++++++++
 hw/ipmi/isa_ipmi_bt.c     | 24 ++++++++++++++++++++++++
 hw/ipmi/isa_ipmi_kcs.c    | 26 ++++++++++++++++++++++++++
 4 files changed, 114 insertions(+)
hw/ipmi/ipmi_bmc_extern.c +34 -0
index d4669f0..05b9121 100644
@@ -439,11 +439,45 @@ static void ipmi_bmc_extern_realize(DeviceState *dev, Error **errp)
     qemu_chr_add_handlers(ibe->chr, can_receive, receive, chr_event, ibe);
 }
 
+static int ipmi_bmc_extern_post_migrate(void *opaque, int version_id)
+{
+    IPMIBmcExtern *ibe = opaque;
+
+    /*
+     * We don't directly restore waiting_rsp, Instead, we return an
+     * error on the interface if a response was being waited for.
+     */
+    if (ibe->waiting_rsp) {
+        IPMIInterface *ii = ibe->parent.intf;
+        IPMIInterfaceClass *iic = IPMI_INTERFACE_GET_CLASS(ii);
+
+        ibe->waiting_rsp = false;
+        ibe->inbuf[1] = ibe->outbuf[1] | 0x04;
+        ibe->inbuf[2] = ibe->outbuf[2];
+        ibe->inbuf[3] = IPMI_CC_BMC_INIT_IN_PROGRESS;
+        iic->handle_rsp(ii, ibe->outbuf[0], ibe->inbuf + 1, 3);
+    }
+    return 0;
+}
+
+static const VMStateDescription vmstate_ipmi_bmc_extern = {
+    .name = TYPE_IPMI_BMC_EXTERN,
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .post_load = ipmi_bmc_extern_post_migrate,
+    .fields      = (VMStateField[]) {
+        VMSTATE_BOOL(send_reset, IPMIBmcExtern),
+        VMSTATE_BOOL(waiting_rsp, IPMIBmcExtern),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static void ipmi_bmc_extern_init(Object *obj)
 {
     IPMIBmcExtern *ibe = IPMI_BMC_EXTERN(obj);
 
     ibe->extern_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, extern_timeout, ibe);
+    vmstate_register(NULL, 0, &vmstate_ipmi_bmc_extern, ibe);
 }
 
 static Property ipmi_bmc_extern_properties[] = {
hw/ipmi/ipmi_bmc_sim.c +30 -0
index d246029..c81a19d 100644
@@ -1658,6 +1658,34 @@ static const uint8_t init_sdrs[] = {
     0xff, 0xff, 0x00, 0x00, 0x00
 };
 
+static const VMStateDescription vmstate_ipmi_sim = {
+    .name = TYPE_IPMI_BMC_SIMULATOR,
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields      = (VMStateField[]) {
+        VMSTATE_UINT8(bmc_global_enables, IPMIBmcSim),
+        VMSTATE_UINT8(msg_flags, IPMIBmcSim),
+        VMSTATE_BOOL(watchdog_initialized, IPMIBmcSim),
+        VMSTATE_UINT8(watchdog_use, IPMIBmcSim),
+        VMSTATE_UINT8(watchdog_action, IPMIBmcSim),
+        VMSTATE_UINT8(watchdog_pretimeout, IPMIBmcSim),
+        VMSTATE_BOOL(watchdog_expired, IPMIBmcSim),
+        VMSTATE_UINT16(watchdog_timeout, IPMIBmcSim),
+        VMSTATE_BOOL(watchdog_running, IPMIBmcSim),
+        VMSTATE_BOOL(watchdog_preaction_ran, IPMIBmcSim),
+        VMSTATE_INT64(watchdog_expiry, IPMIBmcSim),
+        VMSTATE_UINT8_ARRAY(evtbuf, IPMIBmcSim, 16),
+        VMSTATE_UINT8(sensors[IPMI_WATCHDOG_SENSOR].status, IPMIBmcSim),
+        VMSTATE_UINT8(sensors[IPMI_WATCHDOG_SENSOR].reading, IPMIBmcSim),
+        VMSTATE_UINT16(sensors[IPMI_WATCHDOG_SENSOR].states, IPMIBmcSim),
+        VMSTATE_UINT16(sensors[IPMI_WATCHDOG_SENSOR].assert_states, IPMIBmcSim),
+        VMSTATE_UINT16(sensors[IPMI_WATCHDOG_SENSOR].deassert_states,
+                       IPMIBmcSim),
+        VMSTATE_UINT16(sensors[IPMI_WATCHDOG_SENSOR].assert_enable, IPMIBmcSim),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static void ipmi_sim_init(Object *obj)
 {
     IPMIBmc *b = IPMI_BMC(obj);
@@ -1706,6 +1734,8 @@ static void ipmi_sim_init(Object *obj)
     register_cmds(ibs);
 
     ibs->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, ipmi_timeout, ibs);
+
+    vmstate_register(NULL, 0, &vmstate_ipmi_sim, ibs);
 }
 
 static void ipmi_sim_class_init(ObjectClass *oc, void *data)
hw/ipmi/isa_ipmi_bt.c +24 -0
index 70e2c0d..03eb9cc 100644
@@ -437,11 +437,35 @@ static void isa_ipmi_bt_realize(DeviceState *dev, Error **errp)
     isa_register_ioport(isadev, &iib->bt.io, iib->bt.io_base);
 }
 
+static const VMStateDescription vmstate_ISAIPMIBTDevice = {
+    .name = TYPE_IPMI_INTERFACE,
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields      = (VMStateField[]) {
+        VMSTATE_BOOL(bt.obf_irq_set, ISAIPMIBTDevice),
+        VMSTATE_BOOL(bt.atn_irq_set, ISAIPMIBTDevice),
+        VMSTATE_BOOL(bt.use_irq, ISAIPMIBTDevice),
+        VMSTATE_BOOL(bt.irqs_enabled, ISAIPMIBTDevice),
+        VMSTATE_UINT32(bt.outpos, ISAIPMIBTDevice),
+        VMSTATE_VBUFFER_UINT32(bt.outmsg, ISAIPMIBTDevice, 1, NULL, 0,
+                               bt.outlen),
+        VMSTATE_VBUFFER_UINT32(bt.inmsg, ISAIPMIBTDevice, 1, NULL, 0,
+                               bt.inlen),
+        VMSTATE_UINT8(bt.control_reg, ISAIPMIBTDevice),
+        VMSTATE_UINT8(bt.mask_reg, ISAIPMIBTDevice),
+        VMSTATE_UINT8(bt.waiting_rsp, ISAIPMIBTDevice),
+        VMSTATE_UINT8(bt.waiting_seq, ISAIPMIBTDevice),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static void isa_ipmi_bt_init(Object *obj)
 {
     ISAIPMIBTDevice *iib = ISA_IPMI_BT(obj);
 
     ipmi_bmc_find_and_link(obj, (Object **) &iib->bt.bmc);
+
+    vmstate_register(NULL, 0, &vmstate_ISAIPMIBTDevice, iib);
 }
 
 static void *isa_ipmi_bt_get_backend_data(IPMIInterface *ii)
hw/ipmi/isa_ipmi_kcs.c +26 -0
index 750a725..b588711 100644
@@ -400,11 +400,37 @@ static void ipmi_isa_realize(DeviceState *dev, Error **errp)
     isa_register_ioport(isadev, &iik->kcs.io, iik->kcs.io_base);
 }
 
+const VMStateDescription vmstate_ISAIPMIKCSDevice = {
+    .name = TYPE_IPMI_INTERFACE,
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields      = (VMStateField[]) {
+        VMSTATE_BOOL(kcs.obf_irq_set, ISAIPMIKCSDevice),
+        VMSTATE_BOOL(kcs.atn_irq_set, ISAIPMIKCSDevice),
+        VMSTATE_BOOL(kcs.use_irq, ISAIPMIKCSDevice),
+        VMSTATE_BOOL(kcs.irqs_enabled, ISAIPMIKCSDevice),
+        VMSTATE_UINT32(kcs.outpos, ISAIPMIKCSDevice),
+        VMSTATE_VBUFFER_UINT32(kcs.outmsg, ISAIPMIKCSDevice, 1, NULL, 0,
+                               kcs.outlen),
+        VMSTATE_VBUFFER_UINT32(kcs.inmsg, ISAIPMIKCSDevice, 1, NULL, 0,
+                               kcs.inlen),
+        VMSTATE_BOOL(kcs.write_end, ISAIPMIKCSDevice),
+        VMSTATE_UINT8(kcs.status_reg, ISAIPMIKCSDevice),
+        VMSTATE_UINT8(kcs.data_out_reg, ISAIPMIKCSDevice),
+        VMSTATE_INT16(kcs.data_in_reg, ISAIPMIKCSDevice),
+        VMSTATE_INT16(kcs.cmd_reg, ISAIPMIKCSDevice),
+        VMSTATE_UINT8(kcs.waiting_rsp, ISAIPMIKCSDevice),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static void isa_ipmi_kcs_init(Object *obj)
 {
     ISAIPMIKCSDevice *iik = ISA_IPMI_KCS(obj);
 
     ipmi_bmc_find_and_link(obj, (Object **) &iik->kcs.bmc);
+
+    vmstate_register(NULL, 0, &vmstate_ISAIPMIKCSDevice, iik);
 }
 
 static void *isa_ipmi_kcs_get_backend_data(IPMIInterface *ii)
Signature · 1 line
1.8.3.1
#16 lore raw

PATCH v4 12/17 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 b81a1d3..fe553f9 100644
@@ -22,6 +22,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 {
@@ -51,10 +52,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;
@@ -427,7 +428,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) */
@@ -441,65 +442,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
1.8.3.1
#17 lore raw

PATCH v4 13/17 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 0cb8afd..47faef7 100644
@@ -781,8 +781,6 @@ static FWCfgState *bochs_bios_init(AddressSpace *as)
                      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,
@@ -1174,6 +1172,7 @@ void pc_guest_info_machine_done(Notifier *notifier, void *data)
     PcGuestInfoState *guest_info_state = container_of(notifier,
                                                       PcGuestInfoState,
                                                       machine_done);
+    FWCfgState *fw_cfg = guest_info_state->info.fw_cfg;
     PCIBus *bus = find_i440fx();
 
     if (bus) {
@@ -1185,15 +1184,17 @@ void pc_guest_info_machine_done(Notifier *notifier, void *data)
                 extra_hosts++;
             }
         }
-        if (extra_hosts && guest_info_state->info.fw_cfg) {
+        if (extra_hosts && fw_cfg) {
             uint64_t *val = g_malloc(sizeof(*val));
             *val = cpu_to_le64(extra_hosts);
-            fw_cfg_add_file(guest_info_state->info.fw_cfg,
-                    "etc/extra-pci-roots", val, sizeof(*val));
+            fw_cfg_add_file(fw_cfg, "etc/extra-pci-roots", val, sizeof(*val));
         }
     }
 
     acpi_setup(&guest_info_state->info);
+    if (fw_cfg) {
+        pc_build_smbios(fw_cfg);
+    }
 }
 
 PcGuestInfo *pc_guest_info_init(PCMachineState *pcms)
Signature · 1 line
1.8.3.1
#10 lore raw

PATCH v4 6/17 ipmi: Add a BT low-level interface

In reply to [email protected]

From: Corey Minyard <[email protected]>

This provides the simulation of the BT hardware interface for IPMI.

---
 default-configs/i386-softmmu.mak   |   1 +
 default-configs/x86_64-softmmu.mak |   1 +
 hw/ipmi/Makefile.objs              |   1 +
 hw/ipmi/isa_ipmi_bt.c              | 489 +++++++++++++++++++++++++++++++++++++
 4 files changed, 492 insertions(+)
 create mode 100644 hw/ipmi/isa_ipmi_bt.c
default-configs/i386-softmmu.mak +1 -0
index 1c24aab..1730fbb 100644
@@ -13,6 +13,7 @@ CONFIG_IPMI=y
 CONFIG_IPMI_LOCAL=y
 CONFIG_IPMI_EXTERN=y
 CONFIG_ISA_IPMI_KCS=y
+CONFIG_ISA_IPMI_BT=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
default-configs/x86_64-softmmu.mak +1 -0
index 9d1f934..22a99a2 100644
@@ -13,6 +13,7 @@ CONFIG_IPMI=y
 CONFIG_IPMI_LOCAL=y
 CONFIG_IPMI_EXTERN=y
 CONFIG_ISA_IPMI_KCS=y
+CONFIG_ISA_IPMI_BT=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
hw/ipmi/Makefile.objs +1 -0
index 28618c5..a90318d 100644
@@ -2,3 +2,4 @@ common-obj-$(CONFIG_IPMI) += ipmi.o
 common-obj-$(CONFIG_IPMI_LOCAL) += ipmi_bmc_sim.o
 common-obj-$(CONFIG_IPMI_LOCAL) += ipmi_bmc_extern.o
 common-obj-$(CONFIG_ISA_IPMI_KCS) += isa_ipmi_kcs.o
+common-obj-$(CONFIG_ISA_IPMI_BT) += isa_ipmi_bt.o
hw/ipmi/isa_ipmi_bt.c new file +489 -0

489 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#18 lore raw

PATCH v4 14/17 ipmi: Add SMBIOS table entry

In reply to [email protected]

From: Corey Minyard <[email protected]>

Add an IPMI table entry to the SMBIOS.

---
 default-configs/i386-softmmu.mak   |  1 +
 default-configs/x86_64-softmmu.mak |  1 +
 hw/smbios/Makefile.objs            |  2 +
 hw/smbios/ipmi.c                   | 75 ++++++++++++++++++++++++++++++++++++++
 hw/smbios/noipmi.c                 | 14 +++++++
 hw/smbios/smbios.c                 |  2 +
 include/hw/smbios/ipmi.h           | 15 ++++++++
 7 files changed, 110 insertions(+)
 create mode 100644 hw/smbios/ipmi.c
 create mode 100644 hw/smbios/noipmi.c
 create mode 100644 include/hw/smbios/ipmi.h
default-configs/i386-softmmu.mak +1 -0
index 1730fbb..b73bf3a 100644
@@ -20,6 +20,7 @@ CONFIG_I8254=y
 CONFIG_PCSPK=y
 CONFIG_PCKBD=y
 CONFIG_FDC=y
+CONFIG_SMBIOS=y
 CONFIG_ACPI=y
 CONFIG_ACPI_X86=y
 CONFIG_ACPI_X86_ICH=y
default-configs/x86_64-softmmu.mak +1 -0
index 22a99a2..baf07cc 100644
@@ -20,6 +20,7 @@ CONFIG_I8254=y
 CONFIG_PCSPK=y
 CONFIG_PCKBD=y
 CONFIG_FDC=y
+CONFIG_SMBIOS=y
 CONFIG_ACPI=y
 CONFIG_ACPI_X86=y
 CONFIG_ACPI_X86_ICH=y
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 +75 -0

75 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 fe553f9..ebfb077 100644
@@ -23,6 +23,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 {
@@ -846,6 +847,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
1.8.3.1
#9 lore raw

PATCH v4 5/17 ipmi: Add an ISA KCS low-level interface

In reply to [email protected]

From: Corey Minyard <[email protected]>

This provides the simulation of the KCS hardware interface.

---
 default-configs/i386-softmmu.mak   |   1 +
 default-configs/x86_64-softmmu.mak |   1 +
 hw/ipmi/Makefile.objs              |   1 +
 hw/ipmi/isa_ipmi_kcs.c             | 452 +++++++++++++++++++++++++++++++++++++
 4 files changed, 455 insertions(+)
 create mode 100644 hw/ipmi/isa_ipmi_kcs.c
default-configs/i386-softmmu.mak +1 -0
index 077b3c4..1c24aab 100644
@@ -12,6 +12,7 @@ CONFIG_VMMOUSE=y
 CONFIG_IPMI=y
 CONFIG_IPMI_LOCAL=y
 CONFIG_IPMI_EXTERN=y
+CONFIG_ISA_IPMI_KCS=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
default-configs/x86_64-softmmu.mak +1 -0
index 81b0cb0..9d1f934 100644
@@ -12,6 +12,7 @@ CONFIG_VMMOUSE=y
 CONFIG_IPMI=y
 CONFIG_IPMI_LOCAL=y
 CONFIG_IPMI_EXTERN=y
+CONFIG_ISA_IPMI_KCS=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
hw/ipmi/Makefile.objs +1 -0
index ddb15ec..28618c5 100644
@@ -1,3 +1,4 @@
 common-obj-$(CONFIG_IPMI) += ipmi.o
 common-obj-$(CONFIG_IPMI_LOCAL) += ipmi_bmc_sim.o
 common-obj-$(CONFIG_IPMI_LOCAL) += ipmi_bmc_extern.o
+common-obj-$(CONFIG_ISA_IPMI_KCS) += isa_ipmi_kcs.o
hw/ipmi/isa_ipmi_kcs.c new file +452 -0

452 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#11 lore raw

PATCH v4 7/17 ipmi: Add tests

In reply to [email protected]

From: Corey Minyard <[email protected]>

Test the KCS interface with a local BMC and a BT interface with an external BMC.

---
 tests/Makefile        |   4 +
 tests/ipmi-bt-test.c  | 436 ++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/ipmi-kcs-test.c | 295 ++++++++++++++++++++++++++++++++++
 3 files changed, 735 insertions(+)
 create mode 100644 tests/ipmi-bt-test.c
 create mode 100644 tests/ipmi-kcs-test.c
tests/Makefile +4 -0
index 92969e8..039c440 100644
@@ -163,6 +163,8 @@ gcov-files-i386-y += hw/block/hd-geometry.c
 check-qtest-i386-y += tests/boot-order-test$(EXESUF)
 check-qtest-i386-y += tests/bios-tables-test$(EXESUF)
 check-qtest-i386-y += tests/rtc-test$(EXESUF)
+check-qtest-i386-y += tests/ipmi-kcs-test$(EXESUF)
+check-qtest-i386-y += 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/drive_del-test$(EXESUF)
@@ -481,6 +483,8 @@ tests/spapr-phb-test$(EXESUF): tests/spapr-phb-test.o $(libqos-obj-y)
 tests/fdc-test$(EXESUF): tests/fdc-test.o
 tests/ide-test$(EXESUF): tests/ide-test.o $(libqos-pc-obj-y)
 tests/ahci-test$(EXESUF): tests/ahci-test.o $(libqos-pc-obj-y)
+tests/ipmi-kcs-test$(EXESUF): tests/ipmi-kcs-test.o
+tests/ipmi-bt-test$(EXESUF): tests/ipmi-bt-test.o
 tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o
 tests/boot-order-test$(EXESUF): tests/boot-order-test.o $(libqos-obj-y)
 tests/bios-tables-test$(EXESUF): tests/bios-tables-test.o $(libqos-obj-y)
tests/ipmi-bt-test.c new file +436 -0

436 lines not on this page · raw message

tests/ipmi-kcs-test.c new file +295 -0

295 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#4 lore raw

PATCH v4 3/17 ipmi: Add a local BMC simulation

In reply to [email protected]

From: Corey Minyard <[email protected]>

This provides a minimal local BMC, basically enough to comply with the spec and provide a complete watchdog timer (including a sensor, SDR, and event).

---
 default-configs/i386-softmmu.mak   |    1 +
 default-configs/x86_64-softmmu.mak |    1 +
 hw/ipmi/Makefile.objs              |    1 +
 hw/ipmi/ipmi_bmc_sim.c             | 1731 ++++++++++++++++++++++++++++++++++++
 4 files changed, 1734 insertions(+)
 create mode 100644 hw/ipmi/ipmi_bmc_sim.c
default-configs/i386-softmmu.mak +1 -0
index 8fa751a..00a0346 100644
@@ -10,6 +10,7 @@ CONFIG_VMWARE_VGA=y
 CONFIG_VIRTIO_VGA=y
 CONFIG_VMMOUSE=y
 CONFIG_IPMI=y
+CONFIG_IPMI_LOCAL=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
default-configs/x86_64-softmmu.mak +1 -0
index 6767f4f..39a619f 100644
@@ -10,6 +10,7 @@ CONFIG_VMWARE_VGA=y
 CONFIG_VIRTIO_VGA=y
 CONFIG_VMMOUSE=y
 CONFIG_IPMI=y
+CONFIG_IPMI_LOCAL=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
hw/ipmi/Makefile.objs +1 -0
index 65bde11..875271c 100644
@@ -1 +1,2 @@
 common-obj-$(CONFIG_IPMI) += ipmi.o
+common-obj-$(CONFIG_IPMI_LOCAL) += ipmi_bmc_sim.o
hw/ipmi/ipmi_bmc_sim.c new file +1731 -0

1,731 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#19 lore raw

PATCH v4 15/17 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_ssdt to add an SSDT 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         | 116 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/acpi/noipmi.c       |  14 ++++++
 hw/i386/acpi-build.c   |   4 ++
 include/hw/acpi/ipmi.h |  16 +++++++
 5 files changed, 152 insertions(+)
 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 7d3230c..f35ecfc 100644
@@ -5,3 +5,5 @@ common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.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 +116 -0

116 lines not on this page · raw message

hw/acpi/noipmi.c new file +14 -0
new file mode 100644
index 0000000..4aae336
@@ -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 *ssdt)
+{
+}
hw/i386/acpi-build.c +4 -0
index 95e0c65..039368f 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
@@ -1345,6 +1347,8 @@ build_ssdt(GArray *table_data, GArray *linker,
         aml_append(ssdt, sb_scope);
     }
 
+    acpi_add_ipmi(ssdt);
+
     /* copy AML table into ACPI tables blob and patch header there */
     g_array_append_vals(table_data, ssdt->buf->data, ssdt->buf->len);
     build_header(linker, table_data,
include/hw/acpi/ipmi.h new file +16 -0
new file mode 100644
index 0000000..313ce37
@@ -0,0 +1,16 @@
+/*
+ * 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 "hw/acpi/aml-build.h"
+
+void acpi_add_ipmi(Aml *ssdt);
+
+#endif /* HW_ACPI_IPMI_H */
Signature · 1 line
1.8.3.1
#20 lore raw

PATCH v4 17/17 ipmi: Add a force off function

In reply to [email protected]

From: Corey Minyard <[email protected]>

Allow the IPMI interface to request a forced power off.

---
 hw/ipmi/ipmi_bmc_extern.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/ipmi/ipmi_bmc_extern.c +5 -0
index 05b9121..7ae6294 100644
@@ -52,6 +52,7 @@
 #define   VM_CAPABILITIES_IRQ      0x04
 #define   VM_CAPABILITIES_NMI      0x08
 #define   VM_CAPABILITIES_ATTN     0x10
+#define VM_CMD_FORCEOFF            0x09
 
 #define TYPE_IPMI_BMC_EXTERN "ipmi-bmc-extern"
 #define IPMI_BMC_EXTERN(obj) OBJECT_CHECK(IPMIBmcExtern, (obj), \
@@ -268,6 +269,10 @@ static void handle_hw_op(IPMIBmcExtern *ibe, unsigned char hw_op)
     case VM_CMD_SEND_NMI:
         k->do_hw_op(s, IPMI_SEND_NMI, 0);
         break;
+
+    case VM_CMD_FORCEOFF:
+        exit(0);
+        break;
     }
 }
 
Signature · 1 line
1.8.3.1
#21 lore raw

Re: [Qemu-devel] [PATCH v4 17/17] ipmi: Add a force off function

Quoted 22 lines · On Thu, Nov 12, 2015 at 01:02:33PM -0600, [email protected] wrote:

From: Corey Minyard <[email protected]>

Allow the IPMI interface to request a forced power off.

---
 hw/ipmi/ipmi_bmc_extern.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/ipmi/ipmi_bmc_extern.c +1 -0
index 05b9121..7ae6294 100644
@@ -52,6 +52,7 @@
 #define   VM_CAPABILITIES_IRQ      0x04
 #define   VM_CAPABILITIES_NMI      0x08
 #define   VM_CAPABILITIES_ATTN     0x10
+#define VM_CMD_FORCEOFF            0x09
 
 #define TYPE_IPMI_BMC_EXTERN "ipmi-bmc-extern"
 #define IPMI_BMC_EXTERN(obj) OBJECT_CHECK(IPMIBmcExtern, (obj), \

hw/ipmi/ipmi_bmc_extern.c static void handle_hw_op(IPMIBmcExtern *ibe, unsigned char hw_op) · line 275

Quoted 7 lines
hw/ipmi/ipmi_bmc_extern.c +4 -0
@@ -268,6 +269,10 @@ static void handle_hw_op(IPMIBmcExtern *ibe, unsigned char hw_op)
     case VM_CMD_SEND_NMI:
         k->do_hw_op(s, IPMI_SEND_NMI, 0);
         break;
+
+    case VM_CMD_FORCEOFF:
+        exit(0);
+        break;

You should really be calling qemu_system_shutdown_request() rather than exit() so that you run normal QEMU shutdown logic.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#22 lore raw

Re: [Qemu-devel] [PATCH v4 17/17] ipmi: Add a force off function

Quoted 20 lines · Daniel P. Berrange
Quoted 19 lines · On Thu, Nov 12, 2015 at 01:02:33PM -0600, [email protected] wrote:

From: Corey Minyard <[email protected]>

Allow the IPMI interface to request a forced power off.

---
 hw/ipmi/ipmi_bmc_extern.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/ipmi/ipmi_bmc_extern.c +1 -0
index 05b9121..7ae6294 100644
@@ -52,6 +52,7 @@
 #define   VM_CAPABILITIES_IRQ      0x04
 #define   VM_CAPABILITIES_NMI      0x08
 #define   VM_CAPABILITIES_ATTN     0x10
+#define VM_CMD_FORCEOFF            0x09
 
Quoted 12 lines

hw/ipmi/ipmi_bmc_extern.c static void handle_hw_op(IPMIBmcExtern *ibe, unsigned char hw_op) · line 275

Quoted 10 lines
hw/ipmi/ipmi_bmc_extern.c +4 -0
 #define TYPE_IPMI_BMC_EXTERN "ipmi-bmc-extern"
 #define IPMI_BMC_EXTERN(obj) OBJECT_CHECK(IPMIBmcExtern, (obj), \
@@ -268,6 +269,10 @@ static void handle_hw_op(IPMIBmcExtern *ibe, unsigned char hw_op)
     case VM_CMD_SEND_NMI:
         k->do_hw_op(s, IPMI_SEND_NMI, 0);
         break;
+
+    case VM_CMD_FORCEOFF:
+        exit(0);
+        break;

You should really be calling qemu_system_shutdown_request() rather than exit() so that you run normal QEMU shutdown logic.

qemu_system_shutdown_request() would generally have already been called using VM_CMD_POWEROFF. If I understand correctly, qemu_system_shutdown_request() does a graceful shutdown and may not complete if the OS has failed.

The CMD_FORCEOFF is a "power off and don't ask me any questions" operation. It's used as a last resort if VM_CMD_POWEROFF fails.

-corey

#23 lore raw

Re: [Qemu-devel] [PATCH v4 17/17] ipmi: Add a force off function

Quoted 34 lines · Corey Minyard
Quoted 20 lines · Daniel P. Berrange
Quoted 19 lines · On Thu, Nov 12, 2015 at 01:02:33PM -0600, [email protected] wrote:

From: Corey Minyard <[email protected]>

Allow the IPMI interface to request a forced power off.

---
 hw/ipmi/ipmi_bmc_extern.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/ipmi/ipmi_bmc_extern.c +1 -0
index 05b9121..7ae6294 100644
@@ -52,6 +52,7 @@
 #define   VM_CAPABILITIES_IRQ      0x04
 #define   VM_CAPABILITIES_NMI      0x08
 #define   VM_CAPABILITIES_ATTN     0x10
+#define VM_CMD_FORCEOFF            0x09
 
Quoted 12 lines

hw/ipmi/ipmi_bmc_extern.c static void handle_hw_op(IPMIBmcExtern *ibe, unsigned char hw_op) · line 275

Quoted 10 lines
hw/ipmi/ipmi_bmc_extern.c +4 -0
 #define TYPE_IPMI_BMC_EXTERN "ipmi-bmc-extern"
 #define IPMI_BMC_EXTERN(obj) OBJECT_CHECK(IPMIBmcExtern, (obj), \
@@ -268,6 +269,10 @@ static void handle_hw_op(IPMIBmcExtern *ibe, unsigned char hw_op)
     case VM_CMD_SEND_NMI:
         k->do_hw_op(s, IPMI_SEND_NMI, 0);
         break;
+
+    case VM_CMD_FORCEOFF:
+        exit(0);
+        break;

You should really be calling qemu_system_shutdown_request() rather than exit() so that you run normal QEMU shutdown logic.

Quoted 3 lines

qemu_system_shutdown_request() would generally have already been called using VM_CMD_POWEROFF. If I understand correctly, qemu_system_shutdown_request() does a graceful shutdown and may not complete if the OS has failed.

No, that's qemu_system_powerdown_request.

Paolo

Quoted 6 lines

The CMD_FORCEOFF is a "power off and don't ask me any questions" operation. It's used as a last resort if VM_CMD_POWEROFF fails.

-corey

#24 lore raw

Re: [Qemu-devel] [PATCH v4 17/17] ipmi: Add a force off function

Quoted 35 lines · Paolo Bonzini
Quoted 33 lines · Corey Minyard
Quoted 32 lines · Daniel P. Berrange
Quoted 22 lines · On Thu, Nov 12, 2015 at 01:02:33PM -0600, [email protected] wrote:

From: Corey Minyard <[email protected]>

Allow the IPMI interface to request a forced power off.

---
 hw/ipmi/ipmi_bmc_extern.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/ipmi/ipmi_bmc_extern.c +1 -0
index 05b9121..7ae6294 100644
@@ -52,6 +52,7 @@
 #define   VM_CAPABILITIES_IRQ      0x04
 #define   VM_CAPABILITIES_NMI      0x08
 #define   VM_CAPABILITIES_ATTN     0x10
+#define VM_CMD_FORCEOFF            0x09
 
 #define TYPE_IPMI_BMC_EXTERN "ipmi-bmc-extern"
 #define IPMI_BMC_EXTERN(obj) OBJECT_CHECK(IPMIBmcExtern, (obj), \

hw/ipmi/ipmi_bmc_extern.c static void handle_hw_op(IPMIBmcExtern *ibe, unsigned char hw_op) · line 275

Quoted 7 lines
hw/ipmi/ipmi_bmc_extern.c +4 -0
@@ -268,6 +269,10 @@ static void handle_hw_op(IPMIBmcExtern *ibe, unsigned char hw_op)
     case VM_CMD_SEND_NMI:
         k->do_hw_op(s, IPMI_SEND_NMI, 0);
         break;
+
+    case VM_CMD_FORCEOFF:
+        exit(0);
+        break;

You should really be calling qemu_system_shutdown_request() rather than exit() so that you run normal QEMU shutdown logic.

Quoted 6 lines
Quoted 3 lines

qemu_system_shutdown_request() would generally have already been called using VM_CMD_POWEROFF. If I understand correctly, qemu_system_shutdown_request() does a graceful shutdown and may not complete if the OS has failed.

No, that's qemu_system_powerdown_request.

Paolo

Ah, ok, got it.

Thanks Daniel and Paulo,

-corey

Quoted 7 lines
Quoted 7 lines

The CMD_FORCEOFF is a "power off and don't ask me any questions" operation. It's used as a last resort if VM_CMD_POWEROFF fails.

-corey

#25 lore raw

Re: [Qemu-devel] [PATCH v4 17/17] ipmi: Add a force off function

In reply to Paolo Bonzini
Quoted 37 lines · Paolo Bonzini
Quoted 34 lines · Corey Minyard
Quoted 32 lines · Daniel P. Berrange
Quoted 22 lines · On Thu, Nov 12, 2015 at 01:02:33PM -0600, [email protected] wrote:

From: Corey Minyard <[email protected]>

Allow the IPMI interface to request a forced power off.

---
 hw/ipmi/ipmi_bmc_extern.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/ipmi/ipmi_bmc_extern.c +1 -0
index 05b9121..7ae6294 100644
@@ -52,6 +52,7 @@
 #define   VM_CAPABILITIES_IRQ      0x04
 #define   VM_CAPABILITIES_NMI      0x08
 #define   VM_CAPABILITIES_ATTN     0x10
+#define VM_CMD_FORCEOFF            0x09
 
 #define TYPE_IPMI_BMC_EXTERN "ipmi-bmc-extern"
 #define IPMI_BMC_EXTERN(obj) OBJECT_CHECK(IPMIBmcExtern, (obj), \

hw/ipmi/ipmi_bmc_extern.c static void handle_hw_op(IPMIBmcExtern *ibe, unsigned char hw_op) · line 275

Quoted 7 lines
hw/ipmi/ipmi_bmc_extern.c +4 -0
@@ -268,6 +269,10 @@ static void handle_hw_op(IPMIBmcExtern *ibe, unsigned char hw_op)
     case VM_CMD_SEND_NMI:
         k->do_hw_op(s, IPMI_SEND_NMI, 0);
         break;
+
+    case VM_CMD_FORCEOFF:
+        exit(0);
+        break;

You should really be calling qemu_system_shutdown_request() rather than exit() so that you run normal QEMU shutdown logic.

Quoted 5 lines
Quoted 3 lines

qemu_system_shutdown_request() would generally have already been called using VM_CMD_POWEROFF. If I understand correctly, qemu_system_shutdown_request() does a graceful shutdown and may not complete if the OS has failed.

No, that's qemu_system_powerdown_request.

Yep, for reference the reason I suggest qemu_system_shutdown_request() is because that's the code path triggered when you send QEMU SIGTERM/SIGQUIT etc, and this IMPI request feels like it should be doing equivalent handling to that scenario.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#26 lore raw
In reply to [email protected]
Quoted 19 lines · On 11/12/2015 08:02 PM, [email protected] wrote:

This is a long delayed patch set, but I think I have things reworked to make Igor happy with the way ACPI and SMBIOS work. This is more consistent with the way most other things work, anyway. It did require adding stubs for systems without IPMI.

The first nine patches are unchanged.

The IPMI firmware configuration storage now holds the firmware information in a data structure and lets it be iterated.

SMBIOS and ACPI build the tables with their existing building functions and call out to the IPMI one (or the stub) when the time comes. This required pulling some code out of smbios.c into an include file and making some things global, as IPMI has to be configurable.

The BIOS table tests were also modified since the ACPI info is now in the existing SSDT.

Quoted 7 lines

I've also added a force-off function for external BMCs; an external BMC needs a way to do a hard power-off of the system if the soft power offs fail.

Thanks all!

-corey

Hi Corey,

Adding your patchset to Ben's work on the PowerNV platform gives us a promising OpenPower system simulator !

I did not have to do too much to make it work. A few SENSOR_EVENT commands are missing which Openpower systems use. I did the merge and quick addons here :

https://github.com/legoater/qemu/tree/powernv-ipmi

For a first try, that went extremely well. The system boots and the ipmi device is fully functionnal. I guess we would need to define a larger set of sdrs. They can be added to the bmc simulator device probably with time.

OpenPower systems also use some specific OEM event upon reboot and reset when initiated from the bmc. We need will to find a way to fill the event buffer with such data. Nothing complex.

I was wondering how much fix up we should be doing in the firmware (skiboot) when running a qemu guest. I guess we should try to generate as much we can of the device tree in qemu depending on the devices available ? or shall we force the qemu platform in skiboot to be strictly openpower oriented ?

Thanks,

C.

#27 lore raw
In reply to [email protected]
Quoted 4 lines · On Thu, 2015-11-12 at 13:02 -0600, [email protected] wrote:

This is a long delayed patch set, but I think I have things reworked to make Igor happy with the way ACPI and SMBIOS work.  This is more consistent with the way most other things work, anyway.  It did require adding stubs for systems without IPMI.

Thanks Corey !

This looks like it's going to be very useful for the new OpenPower model I have been working on.

Cheers,
Ben.

Quoted 23 lines

The first nine patches are unchanged.

The IPMI firmware configuration storage now holds the firmware information
in a data structure and lets it be iterated.

SMBIOS and ACPI build the tables with their existing building functions and call out to the IPMI one (or the stub) when the time comes.  This required pulling some code out of smbios.c into an include file and making some things global, as IPMI has to be configurable.

The BIOS table tests were also modified since the ACPI info is now in the existing SSDT.

I've also added a force-off function for external BMCs; an external BMC needs a way to do a hard power-off of the system if the soft power offs fail.

Thanks all!

-corey

#2 lore raw

Re: [Qemu-devel] [PATCH v4 02/17] Add a base IPMI interface

In reply to [email protected]

I haven't heard any more comments on this series, should I resubmit with the one shutdown change?

-corey

Quoted 419 lines · On Nov 12, 2015 1:02 PM, <[email protected]> wrote:

From: Corey Minyard <[email protected]>

Add the basic IPMI types and infrastructure to QEMU. Low-level interfaces and simulation interfaces will register with this; it's kind of the go-between to tie them together.

---
 default-configs/i386-softmmu.mak   |   1 +
 default-configs/x86_64-softmmu.mak |   1 +
 hw/Makefile.objs                   |   1 +
 hw/ipmi/Makefile.objs              |   1 +
 hw/ipmi/ipmi.c                     | 125 ++++++++++++++++++++++++++
 include/hw/ipmi/ipmi.h             | 178
+++++++++++++++++++++++++++++++++++++
 qemu-doc.texi                      |   2 +
 7 files changed, 309 insertions(+)
 create mode 100644 hw/ipmi/Makefile.objs
 create mode 100644 hw/ipmi/ipmi.c
 create mode 100644 include/hw/ipmi/ipmi.h
default-configs/i386-softmmu.mak +1 -0
index 43c96d1..8fa751a 100644
@@ -9,6 +9,7 @@ CONFIG_VGA_CIRRUS=y
 CONFIG_VMWARE_VGA=y
 CONFIG_VIRTIO_VGA=y
 CONFIG_VMMOUSE=y
+CONFIG_IPMI=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
default-configs/x86_64-softmmu.mak +1 -0
index dfb8095..6767f4f 100644
@@ -9,6 +9,7 @@ CONFIG_VGA_CIRRUS=y
 CONFIG_VMWARE_VGA=y
 CONFIG_VIRTIO_VGA=y
 CONFIG_VMMOUSE=y
+CONFIG_IPMI=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
hw/Makefile.objs +1 -0
index 7e7c241..4a07ed4 100644
@@ -13,6 +13,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += ide/
 devices-dirs-$(CONFIG_SOFTMMU) += input/
 devices-dirs-$(CONFIG_SOFTMMU) += intc/
 devices-dirs-$(CONFIG_IPACK) += ipack/
+devices-dirs-$(CONFIG_IPMI) += ipmi/
 devices-dirs-$(CONFIG_SOFTMMU) += isa/
 devices-dirs-$(CONFIG_SOFTMMU) += misc/
 devices-dirs-$(CONFIG_SOFTMMU) += net/
hw/ipmi/Makefile.objs new file +1 -0
new file mode 100644
index 0000000..65bde11
@@ -0,0 +1 @@
+common-obj-$(CONFIG_IPMI) += ipmi.o
hw/ipmi/ipmi.c new file +6 -0
new file mode 100644
index 0000000..7d17469
@@ -0,0 +1,125 @@
+/*
+ * QEMU IPMI emulation
+ *
+ * Copyright (c) 2015 Corey Minyard, MontaVista Software, LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining

a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */

hw/ipmi/ipmi.c new file +102 -0
+
+#include "hw/hw.h"
+#include "hw/ipmi/ipmi.h"
+#include "sysemu/sysemu.h"
+#include "qmp-commands.h"
+#include "qom/object_interfaces.h"
+#include "qapi/visitor.h"
+
+static int ipmi_do_hw_op(IPMIInterface *s, enum ipmi_op op, int checkonly)
+{
+    switch (op) {
+    case IPMI_RESET_CHASSIS:
+        if (checkonly) {
+            return 0;
+        }
+        qemu_system_reset_request();
+        return 0;
+
+    case IPMI_POWEROFF_CHASSIS:
+        if (checkonly) {
+            return 0;
+        }
+        qemu_system_powerdown_request();
+        return 0;
+
+    case IPMI_SEND_NMI:
+        if (checkonly) {
+            return 0;
+        }
+        qemu_mutex_lock_iothread();
+        qmp_inject_nmi(NULL);
+        qemu_mutex_unlock_iothread();
+        return 0;
+
+    case IPMI_POWERCYCLE_CHASSIS:
+    case IPMI_PULSE_DIAG_IRQ:
+    case IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP:
+    case IPMI_POWERON_CHASSIS:
+    default:
+        return IPMI_CC_COMMAND_NOT_SUPPORTED;
+    }
+}
+
+static void ipmi_interface_class_init(ObjectClass *class, void *data)
+{
+    IPMIInterfaceClass *ik = IPMI_INTERFACE_CLASS(class);
+
+    ik->do_hw_op = ipmi_do_hw_op;
+}
+
+static TypeInfo ipmi_interface_type_info = {
+    .name = TYPE_IPMI_INTERFACE,
+    .parent = TYPE_INTERFACE,
+    .class_size = sizeof(IPMIInterfaceClass),
+    .class_init = ipmi_interface_class_init,
+};
+
+static void isa_ipmi_bmc_check(Object *obj, const char *name,
+                               Object *val, Error **errp)
+{
+    IPMIBmc *bmc = IPMI_BMC(val);
+
+    if (bmc->intf)
+        error_setg(errp, "BMC object is already in use");
+}
+
+void ipmi_bmc_find_and_link(Object *obj, Object **bmc)
+{
+    object_property_add_link(obj, "bmc", TYPE_IPMI_BMC, bmc,
+                             isa_ipmi_bmc_check,
+                             OBJ_PROP_LINK_UNREF_ON_RELEASE,
+                             &error_abort);
+}
+
+static Property ipmi_bmc_properties[] = {
+    DEFINE_PROP_UINT8("slave_addr",  IPMIBmc, slave_addr, 0x20),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void bmc_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+
+    dc->props = ipmi_bmc_properties;
+}
+
+static TypeInfo ipmi_bmc_type_info = {
+    .name = TYPE_IPMI_BMC,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(IPMIBmc),
+    .abstract = true,
+    .class_size = sizeof(IPMIBmcClass),
+    .class_init = bmc_class_init,
+};
+
+static void ipmi_register_types(void)
+{
+    type_register_static(&ipmi_interface_type_info);
+    type_register_static(&ipmi_bmc_type_info);
+}
+
+type_init(ipmi_register_types)
include/hw/ipmi/ipmi.h new file +6 -0
new file mode 100644
index 0000000..e4f7738
@@ -0,0 +1,178 @@
+/*
+ * IPMI base class
+ *
+ * Copyright (c) 2015 Corey Minyard, MontaVista Software, LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining

a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */

include/hw/ipmi/ipmi.h new file +74 -0
+
+#ifndef HW_IPMI_H
+#define HW_IPMI_H
+
+#include "exec/memory.h"
+#include "qemu-common.h"
+#include "hw/qdev.h"
+
+#define MAX_IPMI_MSG_SIZE 300
+
+enum ipmi_op {
+    IPMI_RESET_CHASSIS,
+    IPMI_POWEROFF_CHASSIS,
+    IPMI_POWERON_CHASSIS,
+    IPMI_POWERCYCLE_CHASSIS,
+    IPMI_PULSE_DIAG_IRQ,
+    IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP,
+    IPMI_SEND_NMI
+};
+
+#define IPMI_CC_INVALID_CMD                              0xc1
+#define IPMI_CC_COMMAND_INVALID_FOR_LUN                  0xc2
+#define IPMI_CC_TIMEOUT                                  0xc3
+#define IPMI_CC_OUT_OF_SPACE                             0xc4
+#define IPMI_CC_INVALID_RESERVATION                      0xc5
+#define IPMI_CC_REQUEST_DATA_TRUNCATED                   0xc6
+#define IPMI_CC_REQUEST_DATA_LENGTH_INVALID              0xc7
+#define IPMI_CC_PARM_OUT_OF_RANGE                        0xc9
+#define IPMI_CC_CANNOT_RETURN_REQ_NUM_BYTES              0xca
+#define IPMI_CC_REQ_ENTRY_NOT_PRESENT                    0xcb
+#define IPMI_CC_INVALID_DATA_FIELD                       0xcc
+#define IPMI_CC_BMC_INIT_IN_PROGRESS                     0xd2
+#define IPMI_CC_COMMAND_NOT_SUPPORTED                    0xd5
+
+#define IPMI_NETFN_APP                0x06
+
+#define IPMI_DEBUG 1
+
+/* Specified in the SMBIOS spec. */
+#define IPMI_SMBIOS_KCS         0x01
+#define IPMI_SMBIOS_SMIC        0x02
+#define IPMI_SMBIOS_BT          0x03
+#define IPMI_SMBIOS_SSIF        0x04
+
+/* IPMI Interface types (KCS, SMIC, BT) are prefixed with this */
+#define TYPE_IPMI_INTERFACE_PREFIX "ipmi-interface-"
+
+/*
+ * An IPMI Interface, the interface for talking between the target
+ * and the BMC.
+ */
+#define TYPE_IPMI_INTERFACE "ipmi-interface"
+#define IPMI_INTERFACE(obj) \
+     INTERFACE_CHECK(IPMIInterface, (obj), TYPE_IPMI_INTERFACE)
+#define IPMI_INTERFACE_CLASS(class) \
+     OBJECT_CLASS_CHECK(IPMIInterfaceClass, (class), TYPE_IPMI_INTERFACE)
+#define IPMI_INTERFACE_GET_CLASS(class) \
+     OBJECT_GET_CLASS(IPMIInterfaceClass, (class), TYPE_IPMI_INTERFACE)
+
+typedef struct IPMIInterface {
+    Object parent;
+} IPMIInterface;
+
+typedef struct IPMIInterfaceClass {
+    InterfaceClass parent;
+
+    void (*init)(struct IPMIInterface *s, Error **errp);
+
+    /*
+     * Perform various operations on the hardware.  If checkonly is
+     * true, it will return if the operation can be performed, but it
+     * will not do the operation.
+     */
+    int (*do_hw_op)(struct IPMIInterface *s, enum ipmi_op op, int

checkonly);

include/hw/ipmi/ipmi.h new file +81 -0
+
+    /*
+     * Enable/disable irqs on the interface when the BMC requests this.
+     */
+    void (*set_irq_enable)(struct IPMIInterface *s, int val);
+
+    /*
+     * Handle an event that occurred on the interface, generally the.
+     * target writing to a register.
+     */
+    void (*handle_if_event)(struct IPMIInterface *s);
+
+    /*
+     * The interfaces use this to perform certain ops
+     */
+    void (*set_atn)(struct IPMIInterface *s, int val, int irq);
+
+    /*
+     * Got an IPMI warm/cold reset.
+     */
+    void (*reset)(struct IPMIInterface *s, bool is_cold);
+
+    /*
+     * Handle a response from the bmc.
+     */
+    void (*handle_rsp)(struct IPMIInterface *s, uint8_t msg_id,
+                       unsigned char *rsp, unsigned int rsp_len);
+
+    /*
+     * Set by the owner to hold the backend data for the interface.
+     */
+    void *(*get_backend_data)(struct IPMIInterface *s);
+} IPMIInterfaceClass;
+
+/*
+ * Define a BMC simulator (or perhaps a connection to a real BMC)
+ */
+#define TYPE_IPMI_BMC "ipmi-bmc"
+#define IPMI_BMC(obj) \
+     OBJECT_CHECK(IPMIBmc, (obj), TYPE_IPMI_BMC)
+#define IPMI_BMC_CLASS(obj_class) \
+     OBJECT_CLASS_CHECK(IPMIBmcClass, (obj_class), TYPE_IPMI_BMC)
+#define IPMI_BMC_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(IPMIBmcClass, (obj), TYPE_IPMI_BMC)
+
+typedef struct IPMIBmc {
+    DeviceState parent;
+
+    uint8_t slave_addr;
+
+    IPMIInterface *intf;
+} IPMIBmc;
+
+typedef struct IPMIBmcClass {
+    DeviceClass parent;
+
+    /* Called when the system resets to report to the bmc. */
+    void (*handle_reset)(struct IPMIBmc *s);
+
+    /*
+     * Handle a command to the bmc.
+     */
+    void (*handle_command)(struct IPMIBmc *s,
+                           uint8_t *cmd, unsigned int cmd_len,
+                           unsigned int max_cmd_len,
+                           uint8_t msg_id);
+} IPMIBmcClass;
+
+/*
+ * Add a link property to obj that points to a BMC.
+ */
+void ipmi_bmc_find_and_link(Object *obj, Object **bmc);
+
+#ifdef IPMI_DEBUG
+#define ipmi_debug(fs, ...) \
+    fprintf(stderr, "IPMI (%s): " fs, __func__, ##__VA_ARGS__)
+#else
+#define ipmi_debug(fs, ...)
+#endif
+
+#endif
qemu-doc.texi +2 -1
index 460ab71..3c82d30 100644
@@ -195,6 +195,8 @@ PCI and ISA network adapters
 @item
 Serial ports
 @item
+IPMI BMC, either and internal or external one
+@item
 Creative SoundBlaster 16 sound card
 @item
 ENSONIQ AudioPCI ES1370 sound card
--

1.8.3.1

#3 lore raw

Re: [Qemu-devel] [PATCH v4 02/17] Add a base IPMI interface

Please submit after 2.5 is out.
It's clearly a new feature so can't be merged now, after freeze.

Quoted 426 lines · Corey Minyard

I haven't heard any more comments on this series, should I resubmit with the one shutdown change?

-corey

On Nov 12, 2015 1:02 PM, <[email protected]> wrote:

    From: Corey Minyard <[email protected]>

    Add the basic IPMI types and infrastructure to QEMU.  Low-level
    interfaces and simulation interfaces will register with this; it's
    kind of the go-between to tie them together.

    Signed-off-by: Corey Minyard <[email protected]>
    ---
     default-configs/i386-softmmu.mak   |   1 +
     default-configs/x86_64-softmmu.mak |   1 +
     hw/Makefile.objs                   |   1 +
     hw/ipmi/Makefile.objs              |   1 +
     hw/ipmi/ipmi.c                     | 125 ++++++++++++++++++++++++++
     include/hw/ipmi/ipmi.h             | 178
    +++++++++++++++++++++++++++++++++++++
     qemu-doc.texi                      |   2 +
     7 files changed, 309 insertions(+)
     create mode 100644 hw/ipmi/Makefile.objs
     create mode 100644 hw/ipmi/ipmi.c
     create mode 100644 include/hw/ipmi/ipmi.h

    diff --git a/default-configs/i386-softmmu.mak b/default-configs/
    i386-softmmu.mak
    index 43c96d1..8fa751a 100644
    --- a/default-configs/i386-softmmu.mak
    +++ b/default-configs/i386-softmmu.mak
    @@ -9,6 +9,7 @@ CONFIG_VGA_CIRRUS=y
     CONFIG_VMWARE_VGA=y
     CONFIG_VIRTIO_VGA=y
     CONFIG_VMMOUSE=y
    +CONFIG_IPMI=y
     CONFIG_SERIAL=y
     CONFIG_PARALLEL=y
     CONFIG_I8254=y
    diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/
    x86_64-softmmu.mak
    index dfb8095..6767f4f 100644
    --- a/default-configs/x86_64-softmmu.mak
    +++ b/default-configs/x86_64-softmmu.mak
    @@ -9,6 +9,7 @@ CONFIG_VGA_CIRRUS=y
     CONFIG_VMWARE_VGA=y
     CONFIG_VIRTIO_VGA=y
     CONFIG_VMMOUSE=y
    +CONFIG_IPMI=y
     CONFIG_SERIAL=y
     CONFIG_PARALLEL=y
     CONFIG_I8254=y
    diff --git a/hw/Makefile.objs b/hw/Makefile.objs
    index 7e7c241..4a07ed4 100644
    --- a/hw/Makefile.objs
    +++ b/hw/Makefile.objs
    @@ -13,6 +13,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += ide/
     devices-dirs-$(CONFIG_SOFTMMU) += input/
     devices-dirs-$(CONFIG_SOFTMMU) += intc/
     devices-dirs-$(CONFIG_IPACK) += ipack/
    +devices-dirs-$(CONFIG_IPMI) += ipmi/
     devices-dirs-$(CONFIG_SOFTMMU) += isa/
     devices-dirs-$(CONFIG_SOFTMMU) += misc/
     devices-dirs-$(CONFIG_SOFTMMU) += net/
    diff --git a/hw/ipmi/Makefile.objs b/hw/ipmi/Makefile.objs
    new file mode 100644
    index 0000000..65bde11
    --- /dev/null
    +++ b/hw/ipmi/Makefile.objs
    @@ -0,0 +1 @@
    +common-obj-$(CONFIG_IPMI) += ipmi.o
    diff --git a/hw/ipmi/ipmi.c b/hw/ipmi/ipmi.c
    new file mode 100644
    index 0000000..7d17469
    --- /dev/null
    +++ b/hw/ipmi/ipmi.c
    @@ -0,0 +1,125 @@
    +/*
    + * QEMU IPMI emulation
    + *
    + * Copyright (c) 2015 Corey Minyard, MontaVista Software, LLC
    + *
    + * Permission is hereby granted, free of charge, to any person obtaining a
    copy
    + * of this software and associated documentation files (the "Software"),
    to deal
    + * in the Software without restriction, including without limitation the
    rights
    + * to use, copy, modify, merge, publish, distribute, sublicense, and/or
    sell
    + * copies of the Software, and to permit persons to whom the Software is
    + * furnished to do so, subject to the following conditions:
    + *
    + * The above copyright notice and this permission notice shall be included
    in
    + * all copies or substantial portions of the Software.
    + *
    + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    OR
    + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY,
    + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
    OTHER
    + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    FROM,
    + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
    IN
    + * THE SOFTWARE.
    + */
    +
    +#include "hw/hw.h"
    +#include "hw/ipmi/ipmi.h"
    +#include "sysemu/sysemu.h"
    +#include "qmp-commands.h"
    +#include "qom/object_interfaces.h"
    +#include "qapi/visitor.h"
    +
    +static int ipmi_do_hw_op(IPMIInterface *s, enum ipmi_op op, int checkonly)
    +{
    +    switch (op) {
    +    case IPMI_RESET_CHASSIS:
    +        if (checkonly) {
    +            return 0;
    +        }
    +        qemu_system_reset_request();
    +        return 0;
    +
    +    case IPMI_POWEROFF_CHASSIS:
    +        if (checkonly) {
    +            return 0;
    +        }
    +        qemu_system_powerdown_request();
    +        return 0;
    +
    +    case IPMI_SEND_NMI:
    +        if (checkonly) {
    +            return 0;
    +        }
    +        qemu_mutex_lock_iothread();
    +        qmp_inject_nmi(NULL);
    +        qemu_mutex_unlock_iothread();
    +        return 0;
    +
    +    case IPMI_POWERCYCLE_CHASSIS:
    +    case IPMI_PULSE_DIAG_IRQ:
    +    case IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP:
    +    case IPMI_POWERON_CHASSIS:
    +    default:
    +        return IPMI_CC_COMMAND_NOT_SUPPORTED;
    +    }
    +}
    +
    +static void ipmi_interface_class_init(ObjectClass *class, void *data)
    +{
    +    IPMIInterfaceClass *ik = IPMI_INTERFACE_CLASS(class);
    +
    +    ik->do_hw_op = ipmi_do_hw_op;
    +}
    +
    +static TypeInfo ipmi_interface_type_info = {
    +    .name = TYPE_IPMI_INTERFACE,
    +    .parent = TYPE_INTERFACE,
    +    .class_size = sizeof(IPMIInterfaceClass),
    +    .class_init = ipmi_interface_class_init,
    +};
    +
    +static void isa_ipmi_bmc_check(Object *obj, const char *name,
    +                               Object *val, Error **errp)
    +{
    +    IPMIBmc *bmc = IPMI_BMC(val);
    +
    +    if (bmc->intf)
    +        error_setg(errp, "BMC object is already in use");
    +}
    +
    +void ipmi_bmc_find_and_link(Object *obj, Object **bmc)
    +{
    +    object_property_add_link(obj, "bmc", TYPE_IPMI_BMC, bmc,
    +                             isa_ipmi_bmc_check,
    +                             OBJ_PROP_LINK_UNREF_ON_RELEASE,
    +                             &error_abort);
    +}
    +
    +static Property ipmi_bmc_properties[] = {
    +    DEFINE_PROP_UINT8("slave_addr",  IPMIBmc, slave_addr, 0x20),
    +    DEFINE_PROP_END_OF_LIST(),
    +};
    +
    +static void bmc_class_init(ObjectClass *oc, void *data)
    +{
    +    DeviceClass *dc = DEVICE_CLASS(oc);
    +
    +    dc->props = ipmi_bmc_properties;
    +}
    +
    +static TypeInfo ipmi_bmc_type_info = {
    +    .name = TYPE_IPMI_BMC,
    +    .parent = TYPE_DEVICE,
    +    .instance_size = sizeof(IPMIBmc),
    +    .abstract = true,
    +    .class_size = sizeof(IPMIBmcClass),
    +    .class_init = bmc_class_init,
    +};
    +
    +static void ipmi_register_types(void)
    +{
    +    type_register_static(&ipmi_interface_type_info);
    +    type_register_static(&ipmi_bmc_type_info);
    +}
    +
    +type_init(ipmi_register_types)
    diff --git a/include/hw/ipmi/ipmi.h b/include/hw/ipmi/ipmi.h
    new file mode 100644
    index 0000000..e4f7738
    --- /dev/null
    +++ b/include/hw/ipmi/ipmi.h
    @@ -0,0 +1,178 @@
    +/*
    + * IPMI base class
    + *
    + * Copyright (c) 2015 Corey Minyard, MontaVista Software, LLC
    + *
    + * Permission is hereby granted, free of charge, to any person obtaining a
    copy
    + * of this software and associated documentation files (the "Software"),
    to deal
    + * in the Software without restriction, including without limitation the
    rights
    + * to use, copy, modify, merge, publish, distribute, sublicense, and/or
    sell
    + * copies of the Software, and to permit persons to whom the Software is
    + * furnished to do so, subject to the following conditions:
    + *
    + * The above copyright notice and this permission notice shall be included
    in
    + * all copies or substantial portions of the Software.
    + *
    + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    OR
    + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY,
    + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
    OTHER
    + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    FROM,
    + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
    IN
    + * THE SOFTWARE.
    + */
    +
    +#ifndef HW_IPMI_H
    +#define HW_IPMI_H
    +
    +#include "exec/memory.h"
    +#include "qemu-common.h"
    +#include "hw/qdev.h"
    +
    +#define MAX_IPMI_MSG_SIZE 300
    +
    +enum ipmi_op {
    +    IPMI_RESET_CHASSIS,
    +    IPMI_POWEROFF_CHASSIS,
    +    IPMI_POWERON_CHASSIS,
    +    IPMI_POWERCYCLE_CHASSIS,
    +    IPMI_PULSE_DIAG_IRQ,
    +    IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP,
    +    IPMI_SEND_NMI
    +};
    +
    +#define IPMI_CC_INVALID_CMD                              0xc1
    +#define IPMI_CC_COMMAND_INVALID_FOR_LUN                  0xc2
    +#define IPMI_CC_TIMEOUT                                  0xc3
    +#define IPMI_CC_OUT_OF_SPACE                             0xc4
    +#define IPMI_CC_INVALID_RESERVATION                      0xc5
    +#define IPMI_CC_REQUEST_DATA_TRUNCATED                   0xc6
    +#define IPMI_CC_REQUEST_DATA_LENGTH_INVALID              0xc7
    +#define IPMI_CC_PARM_OUT_OF_RANGE                        0xc9
    +#define IPMI_CC_CANNOT_RETURN_REQ_NUM_BYTES              0xca
    +#define IPMI_CC_REQ_ENTRY_NOT_PRESENT                    0xcb
    +#define IPMI_CC_INVALID_DATA_FIELD                       0xcc
    +#define IPMI_CC_BMC_INIT_IN_PROGRESS                     0xd2
    +#define IPMI_CC_COMMAND_NOT_SUPPORTED                    0xd5
    +
    +#define IPMI_NETFN_APP                0x06
    +
    +#define IPMI_DEBUG 1
    +
    +/* Specified in the SMBIOS spec. */
    +#define IPMI_SMBIOS_KCS         0x01
    +#define IPMI_SMBIOS_SMIC        0x02
    +#define IPMI_SMBIOS_BT          0x03
    +#define IPMI_SMBIOS_SSIF        0x04
    +
    +/* IPMI Interface types (KCS, SMIC, BT) are prefixed with this */
    +#define TYPE_IPMI_INTERFACE_PREFIX "ipmi-interface-"
    +
    +/*
    + * An IPMI Interface, the interface for talking between the target
    + * and the BMC.
    + */
    +#define TYPE_IPMI_INTERFACE "ipmi-interface"
    +#define IPMI_INTERFACE(obj) \
    +     INTERFACE_CHECK(IPMIInterface, (obj), TYPE_IPMI_INTERFACE)
    +#define IPMI_INTERFACE_CLASS(class) \
    +     OBJECT_CLASS_CHECK(IPMIInterfaceClass, (class), TYPE_IPMI_INTERFACE)
    +#define IPMI_INTERFACE_GET_CLASS(class) \
    +     OBJECT_GET_CLASS(IPMIInterfaceClass, (class), TYPE_IPMI_INTERFACE)
    +
    +typedef struct IPMIInterface {
    +    Object parent;
    +} IPMIInterface;
    +
    +typedef struct IPMIInterfaceClass {
    +    InterfaceClass parent;
    +
    +    void (*init)(struct IPMIInterface *s, Error **errp);
    +
    +    /*
    +     * Perform various operations on the hardware.  If checkonly is
    +     * true, it will return if the operation can be performed, but it
    +     * will not do the operation.
    +     */
    +    int (*do_hw_op)(struct IPMIInterface *s, enum ipmi_op op, int
    checkonly);
    +
    +    /*
    +     * Enable/disable irqs on the interface when the BMC requests this.
    +     */
    +    void (*set_irq_enable)(struct IPMIInterface *s, int val);
    +
    +    /*
    +     * Handle an event that occurred on the interface, generally the.
    +     * target writing to a register.
    +     */
    +    void (*handle_if_event)(struct IPMIInterface *s);
    +
    +    /*
    +     * The interfaces use this to perform certain ops
    +     */
    +    void (*set_atn)(struct IPMIInterface *s, int val, int irq);
    +
    +    /*
    +     * Got an IPMI warm/cold reset.
    +     */
    +    void (*reset)(struct IPMIInterface *s, bool is_cold);
    +
    +    /*
    +     * Handle a response from the bmc.
    +     */
    +    void (*handle_rsp)(struct IPMIInterface *s, uint8_t msg_id,
    +                       unsigned char *rsp, unsigned int rsp_len);
    +
    +    /*
    +     * Set by the owner to hold the backend data for the interface.
    +     */
    +    void *(*get_backend_data)(struct IPMIInterface *s);
    +} IPMIInterfaceClass;
    +
    +/*
    + * Define a BMC simulator (or perhaps a connection to a real BMC)
    + */
    +#define TYPE_IPMI_BMC "ipmi-bmc"
    +#define IPMI_BMC(obj) \
    +     OBJECT_CHECK(IPMIBmc, (obj), TYPE_IPMI_BMC)
    +#define IPMI_BMC_CLASS(obj_class) \
    +     OBJECT_CLASS_CHECK(IPMIBmcClass, (obj_class), TYPE_IPMI_BMC)
    +#define IPMI_BMC_GET_CLASS(obj) \
    +     OBJECT_GET_CLASS(IPMIBmcClass, (obj), TYPE_IPMI_BMC)
    +
    +typedef struct IPMIBmc {
    +    DeviceState parent;
    +
    +    uint8_t slave_addr;
    +
    +    IPMIInterface *intf;
    +} IPMIBmc;
    +
    +typedef struct IPMIBmcClass {
    +    DeviceClass parent;
    +
    +    /* Called when the system resets to report to the bmc. */
    +    void (*handle_reset)(struct IPMIBmc *s);
    +
    +    /*
    +     * Handle a command to the bmc.
    +     */
    +    void (*handle_command)(struct IPMIBmc *s,
    +                           uint8_t *cmd, unsigned int cmd_len,
    +                           unsigned int max_cmd_len,
    +                           uint8_t msg_id);
    +} IPMIBmcClass;
    +
    +/*
    + * Add a link property to obj that points to a BMC.
    + */
    +void ipmi_bmc_find_and_link(Object *obj, Object **bmc);
    +
    +#ifdef IPMI_DEBUG
    +#define ipmi_debug(fs, ...) \
    +    fprintf(stderr, "IPMI (%s): " fs, __func__, ##__VA_ARGS__)
    +#else
    +#define ipmi_debug(fs, ...)
    +#endif
    +
    +#endif
    diff --git a/qemu-doc.texi b/qemu-doc.texi
    index 460ab71..3c82d30 100644
    --- a/qemu-doc.texi
    +++ b/qemu-doc.texi
    @@ -195,6 +195,8 @@ PCI and ISA network adapters
     @item
     Serial ports
     @item
    +IPMI BMC, either and internal or external one
    +@item
     Creative SoundBlaster 16 sound card
     @item
     ENSONIQ AudioPCI ES1370 sound card
    --
    1.8.3.1
#5 lore raw

Re: [Qemu-devel] [PATCH v4 03/17] ipmi: Add a local BMC simulation

In reply to [email protected]

A few comments below,

Quoted 88 lines · On 11/12/2015 08:02 PM, [email protected] wrote:

From: Corey Minyard <[email protected]>

This provides a minimal local BMC, basically enough to comply with the spec and provide a complete watchdog timer (including a sensor, SDR, and event).

---
 default-configs/i386-softmmu.mak   |    1 +
 default-configs/x86_64-softmmu.mak |    1 +
 hw/ipmi/Makefile.objs              |    1 +
 hw/ipmi/ipmi_bmc_sim.c             | 1731 ++++++++++++++++++++++++++++++++++++
 4 files changed, 1734 insertions(+)
 create mode 100644 hw/ipmi/ipmi_bmc_sim.c
default-configs/i386-softmmu.mak +1 -0
index 8fa751a..00a0346 100644
@@ -10,6 +10,7 @@ CONFIG_VMWARE_VGA=y
 CONFIG_VIRTIO_VGA=y
 CONFIG_VMMOUSE=y
 CONFIG_IPMI=y
+CONFIG_IPMI_LOCAL=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
default-configs/x86_64-softmmu.mak +1 -0
index 6767f4f..39a619f 100644
@@ -10,6 +10,7 @@ CONFIG_VMWARE_VGA=y
 CONFIG_VIRTIO_VGA=y
 CONFIG_VMMOUSE=y
 CONFIG_IPMI=y
+CONFIG_IPMI_LOCAL=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
hw/ipmi/Makefile.objs +1 -0
index 65bde11..875271c 100644
@@ -1 +1,2 @@
 common-obj-$(CONFIG_IPMI) += ipmi.o
+common-obj-$(CONFIG_IPMI_LOCAL) += ipmi_bmc_sim.o
hw/ipmi/ipmi_bmc_sim.c new file +36 -0
new file mode 100644
index 0000000..d246029
@@ -0,0 +1,1731 @@
+/*
+ * IPMI BMC emulation
+ *
+ * Copyright (c) 2015 Corey Minyard, MontaVista Software, LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include "qemu/timer.h"
+#include "hw/ipmi/ipmi.h"
+#include "qemu/error-report.h"
+
+#define IPMI_NETFN_CHASSIS            0x00
+#define IPMI_NETFN_CHASSIS_MAXCMD         0x03
+
+#define IPMI_CMD_GET_CHASSIS_CAPABILITIES 0x00
+#define IPMI_CMD_GET_CHASSIS_STATUS       0x01

hw/ipmi/ipmi_bmc_sim.c line 46

Quoted 10 lines
hw/ipmi/ipmi_bmc_sim.c new file +10 -0
+#define IPMI_CMD_CHASSIS_CONTROL          0x02
+
+#define IPMI_NETFN_SENSOR_EVENT       0x04
+#define IPMI_NETFN_SENSOR_EVENT_MAXCMD    0x2e
+
+#define IPMI_CMD_SET_SENSOR_EVT_ENABLE    0x28
+#define IPMI_CMD_GET_SENSOR_EVT_ENABLE    0x29
+#define IPMI_CMD_REARM_SENSOR_EVTS        0x2a
+#define IPMI_CMD_GET_SENSOR_EVT_STATUS    0x2b
+#define IPMI_CMD_GET_SENSOR_READING       0x2d

I have started adding a few commands and got scared by IPMI_CMD_SET_SENSOR_READING spec. By any chance, would you have one in stock ?

Quoted 95 lines
hw/ipmi/ipmi_bmc_sim.c new file +95 -0
+
+/* #define IPMI_NETFN_APP             0x06 In ipmi.h */
+#define IPMI_NETFN_APP_MAXCMD             0x36
+
+#define IPMI_CMD_GET_DEVICE_ID            0x01
+#define IPMI_CMD_COLD_RESET               0x02
+#define IPMI_CMD_WARM_RESET               0x03
+#define IPMI_CMD_RESET_WATCHDOG_TIMER     0x22
+#define IPMI_CMD_SET_WATCHDOG_TIMER       0x24
+#define IPMI_CMD_GET_WATCHDOG_TIMER       0x25
+#define IPMI_CMD_SET_BMC_GLOBAL_ENABLES   0x2e
+#define IPMI_CMD_GET_BMC_GLOBAL_ENABLES   0x2f
+#define IPMI_CMD_CLR_MSG_FLAGS            0x30
+#define IPMI_CMD_GET_MSG_FLAGS            0x31
+#define IPMI_CMD_GET_MSG                  0x33
+#define IPMI_CMD_SEND_MSG                 0x34
+#define IPMI_CMD_READ_EVT_MSG_BUF         0x35
+
+#define IPMI_NETFN_STORAGE            0x0a
+#define IPMI_NETFN_STORAGE_MAXCMD         0x4a
+
+#define IPMI_CMD_GET_SDR_REP_INFO         0x20
+#define IPMI_CMD_GET_SDR_REP_ALLOC_INFO   0x21
+#define IPMI_CMD_RESERVE_SDR_REP          0x22
+#define IPMI_CMD_GET_SDR                  0x23
+#define IPMI_CMD_ADD_SDR                  0x24
+#define IPMI_CMD_PARTIAL_ADD_SDR          0x25
+#define IPMI_CMD_DELETE_SDR               0x26
+#define IPMI_CMD_CLEAR_SDR_REP            0x27
+#define IPMI_CMD_GET_SDR_REP_TIME         0x28
+#define IPMI_CMD_SET_SDR_REP_TIME         0x29
+#define IPMI_CMD_ENTER_SDR_REP_UPD_MODE   0x2A
+#define IPMI_CMD_EXIT_SDR_REP_UPD_MODE    0x2B
+#define IPMI_CMD_RUN_INIT_AGENT           0x2C
+#define IPMI_CMD_GET_SEL_INFO             0x40
+#define IPMI_CMD_GET_SEL_ALLOC_INFO       0x41
+#define IPMI_CMD_RESERVE_SEL              0x42
+#define IPMI_CMD_GET_SEL_ENTRY            0x43
+#define IPMI_CMD_ADD_SEL_ENTRY            0x44
+#define IPMI_CMD_PARTIAL_ADD_SEL_ENTRY    0x45
+#define IPMI_CMD_DELETE_SEL_ENTRY         0x46
+#define IPMI_CMD_CLEAR_SEL                0x47
+#define IPMI_CMD_GET_SEL_TIME             0x48
+#define IPMI_CMD_SET_SEL_TIME             0x49
+
+
+/* Same as a timespec struct. */
+struct ipmi_time {
+    long tv_sec;
+    long tv_nsec;
+};
+
+#define MAX_SEL_SIZE 128
+
+typedef struct IPMISel {
+    uint8_t sel[MAX_SEL_SIZE][16];
+    unsigned int next_free;
+    long time_offset;
+    uint16_t reservation;
+    uint8_t last_addition[4];
+    uint8_t last_clear[4];
+    uint8_t overflow;
+} IPMISel;
+
+#define MAX_SDR_SIZE 16384
+
+typedef struct IPMISdr {
+    uint8_t sdr[MAX_SDR_SIZE];
+    unsigned int next_free;
+    uint16_t next_rec_id;
+    uint16_t reservation;
+    uint8_t last_addition[4];
+    uint8_t last_clear[4];
+    uint8_t overflow;
+} IPMISdr;
+
+typedef struct IPMISensor {
+    uint8_t status;
+    uint8_t reading;
+    uint16_t states_suppt;
+    uint16_t assert_suppt;
+    uint16_t deassert_suppt;
+    uint16_t states;
+    uint16_t assert_states;
+    uint16_t deassert_states;
+    uint16_t assert_enable;
+    uint16_t deassert_enable;
+    uint8_t  sensor_type;
+    uint8_t  evt_reading_type_code;
+} IPMISensor;
+#define IPMI_SENSOR_GET_PRESENT(s)       ((s)->status & 0x01)
+#define IPMI_SENSOR_SET_PRESENT(s, v)    ((s)->status = (s->status & ~0x01) | \
+                                             !!(v))
+#define IPMI_SENSOR_GET_SCAN_ON(s)       ((s)->status & 0x40)
+#define IPMI_SENSOR_SET_SCAN_ON(s, v)    ((s)->status = (s->status & ~0x40) | \

hw/ipmi/ipmi_bmc_sim.c line 151

Quoted 10 lines
hw/ipmi/ipmi_bmc_sim.c new file +10 -0
+                                             ((!!(v)) << 6))
+#define IPMI_SENSOR_GET_EVENTS_ON(s)     ((s)->status & 0x80)
+#define IPMI_SENSOR_SET_EVENTS_ON(s, v)  ((s)->status = (s->status & ~0x80) | \
+                                             ((!!(v)) << 7))
+#define IPMI_SENSOR_GET_RET_STATUS(s)    ((s)->status & 0xc0)
+#define IPMI_SENSOR_SET_RET_STATUS(s, v) ((s)->status = (s->status & ~0xc0) | \
+                                             (v & 0xc0))
+#define IPMI_SENSOR_IS_DISCRETE(s) ((s)->evt_reading_type_code != 1)
+
+#define MAX_SENSORS 20

Could we extend that a bit ? like 80 ? There are real systems with more than 180 sensors.

Quoted 164 lines
hw/ipmi/ipmi_bmc_sim.c new file +164 -0
+#define IPMI_WATCHDOG_SENSOR 0
+
+typedef struct IPMIBmcSim IPMIBmcSim;
+
+#define MAX_NETFNS 64
+typedef void (*IPMICmdHandler)(IPMIBmcSim *s,
+                               uint8_t *cmd, unsigned int cmd_len,
+                               uint8_t *rsp, unsigned int *rsp_len,
+                               unsigned int max_rsp_len);
+typedef struct IPMINetfn {
+    unsigned int cmd_nums;
+    const IPMICmdHandler *cmd_handlers;
+} IPMINetfn;
+
+typedef struct IPMIRcvBufEntry {
+    QTAILQ_ENTRY(IPMIRcvBufEntry) entry;
+    uint8_t len;
+    uint8_t buf[MAX_IPMI_MSG_SIZE];
+} IPMIRcvBufEntry;
+
+#define TYPE_IPMI_BMC_SIMULATOR "ipmi-bmc-sim"
+#define IPMI_BMC_SIMULATOR(obj) OBJECT_CHECK(IPMIBmcSim, (obj), \
+                                        TYPE_IPMI_BMC_SIMULATOR)
+struct IPMIBmcSim {
+    IPMIBmc parent;
+
+    QEMUTimer *timer;
+
+    uint8_t bmc_global_enables;
+    uint8_t msg_flags;
+
+    bool     watchdog_initialized;
+    uint8_t  watchdog_use;
+    uint8_t  watchdog_action;
+    uint8_t  watchdog_pretimeout; /* In seconds */
+    bool     watchdog_expired;
+    uint16_t watchdog_timeout; /* in 100's of milliseconds */
+
+    bool     watchdog_running;
+    bool     watchdog_preaction_ran;
+    int64_t  watchdog_expiry;
+
+    uint8_t device_id;
+    uint8_t ipmi_version;
+    uint8_t device_rev;
+    uint8_t fwrev1;
+    uint8_t fwrev2;
+    uint8_t mfg_id[3];
+    uint8_t product_id[2];
+
+    IPMISel sel;
+    IPMISdr sdr;
+    IPMISensor sensors[MAX_SENSORS];
+
+    /* Odd netfns are for responses, so we only need the even ones. */
+    const IPMINetfn *netfns[MAX_NETFNS / 2];
+
+    QemuMutex lock;
+    /* We allow one event in the buffer */
+    uint8_t evtbuf[16];
+
+    QTAILQ_HEAD(, IPMIRcvBufEntry) rcvbufs;
+};
+
+#define IPMI_BMC_MSG_FLAG_WATCHDOG_TIMEOUT_MASK        (1 << 3)
+#define IPMI_BMC_MSG_FLAG_EVT_BUF_FULL                 (1 << 1)
+#define IPMI_BMC_MSG_FLAG_RCV_MSG_QUEUE                (1 << 0)
+#define IPMI_BMC_MSG_FLAG_WATCHDOG_TIMEOUT_MASK_SET(s) \
+    (IPMI_BMC_MSG_FLAG_WATCHDOG_TIMEOUT_MASK & (s)->msg_flags)
+#define IPMI_BMC_MSG_FLAG_EVT_BUF_FULL_SET(s) \
+    (IPMI_BMC_MSG_FLAG_EVT_BUF_FULL & (s)->msg_flags)
+#define IPMI_BMC_MSG_FLAG_RCV_MSG_QUEUE_SET(s) \
+    (IPMI_BMC_MSG_FLAG_RCV_MSG_QUEUE & (s)->msg_flags)
+
+#define IPMI_BMC_RCV_MSG_QUEUE_INT_BIT    0
+#define IPMI_BMC_EVBUF_FULL_INT_BIT       1
+#define IPMI_BMC_EVENT_MSG_BUF_BIT        2
+#define IPMI_BMC_EVENT_LOG_BIT            3
+#define IPMI_BMC_MSG_INTS_ON(s) ((s)->bmc_global_enables & \
+                                 (1 << IPMI_BMC_RCV_MSG_QUEUE_INT_BIT))
+#define IPMI_BMC_EVBUF_FULL_INT_ENABLED(s) ((s)->bmc_global_enables & \
+                                        (1 << IPMI_BMC_EVBUF_FULL_INT_BIT))
+#define IPMI_BMC_EVENT_LOG_ENABLED(s) ((s)->bmc_global_enables & \
+                                       (1 << IPMI_BMC_EVENT_LOG_BIT))
+#define IPMI_BMC_EVENT_MSG_BUF_ENABLED(s) ((s)->bmc_global_enables & \
+                                           (1 << IPMI_BMC_EVENT_MSG_BUF_BIT))
+
+#define IPMI_BMC_WATCHDOG_USE_MASK 0xc7
+#define IPMI_BMC_WATCHDOG_ACTION_MASK 0x77
+#define IPMI_BMC_WATCHDOG_GET_USE(s) ((s)->watchdog_use & 0x7)
+#define IPMI_BMC_WATCHDOG_GET_DONT_LOG(s) (((s)->watchdog_use >> 7) & 0x1)
+#define IPMI_BMC_WATCHDOG_GET_DONT_STOP(s) (((s)->watchdog_use >> 6) & 0x1)
+#define IPMI_BMC_WATCHDOG_GET_PRE_ACTION(s) (((s)->watchdog_action >> 4) & 0x7)
+#define IPMI_BMC_WATCHDOG_PRE_NONE               0
+#define IPMI_BMC_WATCHDOG_PRE_SMI                1
+#define IPMI_BMC_WATCHDOG_PRE_NMI                2
+#define IPMI_BMC_WATCHDOG_PRE_MSG_INT            3
+#define IPMI_BMC_WATCHDOG_GET_ACTION(s) ((s)->watchdog_action & 0x7)
+#define IPMI_BMC_WATCHDOG_ACTION_NONE            0
+#define IPMI_BMC_WATCHDOG_ACTION_RESET           1
+#define IPMI_BMC_WATCHDOG_ACTION_POWER_DOWN      2
+#define IPMI_BMC_WATCHDOG_ACTION_POWER_CYCLE     3
+
+
+/* Add a byte to the response. */
+#define IPMI_ADD_RSP_DATA(b) \
+    do {                                                   \
+        if (*rsp_len >= max_rsp_len) {                     \
+            rsp[2] = IPMI_CC_REQUEST_DATA_TRUNCATED;       \
+            goto out;                                      \
+        }                                                  \
+        rsp[(*rsp_len)++] = (b);                           \
+    } while (0)
+
+/* Verify that the received command is a certain length. */
+#define IPMI_CHECK_CMD_LEN(l) \
+    if (cmd_len < l) {                                     \
+        rsp[2] = IPMI_CC_REQUEST_DATA_LENGTH_INVALID;      \
+        goto out; \
+    }
+
+/* Check that the reservation in the command is valid. */
+#define IPMI_CHECK_RESERVATION(off, r) \
+    do {                                                   \
+        if ((cmd[off] | (cmd[off + 1] << 8)) != r) {       \
+            rsp[2] = IPMI_CC_INVALID_RESERVATION;          \
+            goto out;                                      \
+        }                                                  \
+    } while (0)
+
+
+static void ipmi_sim_handle_timeout(IPMIBmcSim *ibs);
+
+static void ipmi_gettime(struct ipmi_time *time)
+{
+    int64_t stime;
+
+    stime = qemu_clock_get_ns(QEMU_CLOCK_HOST);
+    time->tv_sec = stime / 1000000000LL;
+    time->tv_nsec = stime % 1000000000LL;
+}
+
+static int64_t ipmi_getmonotime(void)
+{
+    return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
+}
+
+static void ipmi_timeout(void *opaque)
+{
+    IPMIBmcSim *ibs = opaque;
+
+    ipmi_sim_handle_timeout(ibs);
+}
+
+static void set_timestamp(IPMIBmcSim *ibs, uint8_t *ts)
+{
+    unsigned int val;
+    struct ipmi_time now;
+
+    ipmi_gettime(&now);
+    val = now.tv_sec + ibs->sel.time_offset;
+    ts[0] = val & 0xff;
+    ts[1] = (val >> 8) & 0xff;
+    ts[2] = (val >> 16) & 0xff;

hw/ipmi/ipmi_bmc_sim.c line 325

Quoted 10 lines
hw/ipmi/ipmi_bmc_sim.c new file +10 -0
+    ts[3] = (val >> 24) & 0xff;
+}
+
+static void sdr_inc_reservation(IPMISdr *sdr)
+{
+    sdr->reservation++;
+    if (sdr->reservation == 0) {
+        sdr->reservation = 1;
+    }
+}

Could we externalize the following routine ? for platforms needing to add a few initial sdrs.

hw/ipmi/ipmi_bmc_sim.c line 334

Quoted 8 lines
hw/ipmi/ipmi_bmc_sim.c new file +8 -0
+static int sdr_add_entry(IPMIBmcSim *ibs, const uint8_t *entry,
+                         unsigned int len, uint16_t *recid)
+{
+    if ((len < 5) || (len > 255)) {
+        return 1;
+    }
+
+    if (entry[ibs->sdr.next_free + 4] != len) {

I think you meant :

	if (entry[4] != len) {

no ?

Quoted 23 lines
hw/ipmi/ipmi_bmc_sim.c new file +23 -0
+        return 1;
+    }
+
+    if (ibs->sdr.next_free + len > MAX_SDR_SIZE) {
+        ibs->sdr.overflow = 1;
+        return 1;
+    }
+
+    memcpy(ibs->sdr.sdr + ibs->sdr.next_free, entry, len);
+    ibs->sdr.sdr[ibs->sdr.next_free] = ibs->sdr.next_rec_id & 0xff;
+    ibs->sdr.sdr[ibs->sdr.next_free+1] = (ibs->sdr.next_rec_id >> 8) & 0xff;
+    ibs->sdr.sdr[ibs->sdr.next_free+2] = 0x51; /* Conform to IPMI 1.5 spec */
+
+    if (recid) {
+        *recid = ibs->sdr.next_rec_id;
+    }
+    ibs->sdr.next_rec_id++;
+    set_timestamp(ibs, ibs->sdr.last_addition);
+    ibs->sdr.next_free += len;
+    sdr_inc_reservation(&ibs->sdr);
+    return 0;
+}
+

[ ... ]

hw/ipmi/ipmi_bmc_sim.c line 1652

Quoted 11 lines
hw/ipmi/ipmi_bmc_sim.c new file +11 -0
+static void register_cmds(IPMIBmcSim *s)
+{
+    ipmi_register_netfn(s, IPMI_NETFN_CHASSIS, &chassis_netfn);
+    ipmi_register_netfn(s, IPMI_NETFN_SENSOR_EVENT, &sensor_event_netfn);
+    ipmi_register_netfn(s, IPMI_NETFN_APP, &app_netfn);
+    ipmi_register_netfn(s, IPMI_NETFN_STORAGE, &storage_netfn);
+}
+
+static const uint8_t init_sdrs[] = {
+    /* Watchdog device */
+    0x00, 0x00, 0x51, 0x02,   40, 0x20, 0x00, 0x00,

Regarding the 'length' byte, the specs says :

Record Length: Number of bytes of data following the Record Length field.

So it should be 35 and not 40 ? This change will problably have some consequences in the routine above.

Quoted 38 lines
hw/ipmi/ipmi_bmc_sim.c new file +38 -0
+    0x23, 0x01, 0x63, 0x00, 0x23, 0x6f, 0x0f, 0x01,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8,
+    'W',  'a',  't',  'c',  'h',  'd',  'o',  'g',
+    /* End */
+    0xff, 0xff, 0x00, 0x00, 0x00
+};
+
+static void ipmi_sim_init(Object *obj)
+{
+    IPMIBmc *b = IPMI_BMC(obj);
+    unsigned int i;
+    unsigned int next_recid, recid;
+    IPMIBmcSim *ibs = IPMI_BMC_SIMULATOR(b);
+
+    qemu_mutex_init(&ibs->lock);
+    QTAILQ_INIT(&ibs->rcvbufs);
+
+    ibs->bmc_global_enables = (1 << IPMI_BMC_EVENT_LOG_BIT);
+    ibs->device_id = 0x20;
+    ibs->ipmi_version = 0x02; /* IPMI 2.0 */
+    for (i = 0; i < 4; i++) {
+        ibs->sel.last_addition[i] = 0xff;
+        ibs->sel.last_clear[i] = 0xff;
+        ibs->sdr.last_addition[i] = 0xff;
+        ibs->sdr.last_clear[i] = 0xff;
+    }
+
+    next_recid = 0;
+    for (i = 0;;) {
+        int len;
+        if ((i + 5) > sizeof(init_sdrs)) {
+            error_report("Problem with recid 0x%4.4x\n", i);
+            return;
+        }
+        len = init_sdrs[i + 4];
+        recid = init_sdrs[i] | (init_sdrs[i + 1] << 8);
+        if (recid == 0xffff) {

hw/ipmi/ipmi_bmc_sim.c line 1700

Quoted 10 lines
hw/ipmi/ipmi_bmc_sim.c new file +10 -0
+            break;
+        }
+        if ((i + len) > sizeof(init_sdrs)) {
+            error_report("Problem with recid 0x%4.4x\n", i);
+            return;
+        }
+        if (recid != next_recid) {
+            error_report("Problem with recid 0x%4.4x\n", i);
+            return;
+        }

May be remove the check on recid which is useless here ?

Quoted 32 lines
hw/ipmi/ipmi_bmc_sim.c new file +31 -0
+        sdr_add_entry(ibs, init_sdrs + i, len, NULL);
+        i += len;
+    }
+
+    ipmi_init_sensors_from_sdrs(ibs);
+    register_cmds(ibs);
+
+    ibs->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, ipmi_timeout, ibs);
+}
+
+static void ipmi_sim_class_init(ObjectClass *oc, void *data)
+{
+    IPMIBmcClass *bk = IPMI_BMC_CLASS(oc);
+
+    bk->handle_command = ipmi_sim_handle_command;
+}
+
+static const TypeInfo ipmi_sim_type = {
+    .name          = TYPE_IPMI_BMC_SIMULATOR,
+    .parent        = TYPE_IPMI_BMC,
+    .instance_size = sizeof(IPMIBmcSim),
+    .instance_init = ipmi_sim_init,
+    .class_init    = ipmi_sim_class_init,
+};
+
+static void ipmi_sim_register_types(void)
+{
+    type_register_static(&ipmi_sim_type);
+}
+
+type_init(ipmi_sim_register_types)
#6 lore raw

Re: [Qemu-devel] [PATCH v4 03/17] ipmi: Add a local BMC simulation

Quoted 1 line · Cédric Le Goater

A few comments below,

Thanks a bunch for the review. As you probably have guessed, this was not really intended as a fully functional BMC, though it has most of the trappings
of what you would need to implement one. I assume you are working on the power systems, and it makes sense to extend this for that application.

Quoted 94 lines · On 11/12/2015 08:02 PM, [email protected] wrote:
Quoted 93 lines

From: Corey Minyard <[email protected]>

This provides a minimal local BMC, basically enough to comply with the spec and provide a complete watchdog timer (including a sensor, SDR, and event).

---
 default-configs/i386-softmmu.mak   |    1 +
 default-configs/x86_64-softmmu.mak |    1 +
 hw/ipmi/Makefile.objs              |    1 +
 hw/ipmi/ipmi_bmc_sim.c             | 1731 ++++++++++++++++++++++++++++++++++++
 4 files changed, 1734 insertions(+)
 create mode 100644 hw/ipmi/ipmi_bmc_sim.c
default-configs/i386-softmmu.mak +1 -0
index 8fa751a..00a0346 100644
@@ -10,6 +10,7 @@ CONFIG_VMWARE_VGA=y
 CONFIG_VIRTIO_VGA=y
 CONFIG_VMMOUSE=y
 CONFIG_IPMI=y
+CONFIG_IPMI_LOCAL=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
default-configs/x86_64-softmmu.mak +1 -0
index 6767f4f..39a619f 100644
@@ -10,6 +10,7 @@ CONFIG_VMWARE_VGA=y
 CONFIG_VIRTIO_VGA=y
 CONFIG_VMMOUSE=y
 CONFIG_IPMI=y
+CONFIG_IPMI_LOCAL=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
hw/ipmi/Makefile.objs +1 -0
index 65bde11..875271c 100644
@@ -1 +1,2 @@
 common-obj-$(CONFIG_IPMI) += ipmi.o
+common-obj-$(CONFIG_IPMI_LOCAL) += ipmi_bmc_sim.o
hw/ipmi/ipmi_bmc_sim.c new file +41 -0
new file mode 100644
index 0000000..d246029
@@ -0,0 +1,1731 @@
+/*
+ * IPMI BMC emulation
+ *
+ * Copyright (c) 2015 Corey Minyard, MontaVista Software, LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include "qemu/timer.h"
+#include "hw/ipmi/ipmi.h"
+#include "qemu/error-report.h"
+
+#define IPMI_NETFN_CHASSIS            0x00
+#define IPMI_NETFN_CHASSIS_MAXCMD         0x03
+
+#define IPMI_CMD_GET_CHASSIS_CAPABILITIES 0x00
+#define IPMI_CMD_GET_CHASSIS_STATUS       0x01
+#define IPMI_CMD_CHASSIS_CONTROL          0x02
+
+#define IPMI_NETFN_SENSOR_EVENT       0x04
+#define IPMI_NETFN_SENSOR_EVENT_MAXCMD    0x2e
+
Quoted 8 lines

hw/ipmi/ipmi_bmc_sim.c line 46

Quoted 5 lines
hw/ipmi/ipmi_bmc_sim.c new file +5 -0
+#define IPMI_CMD_SET_SENSOR_EVT_ENABLE    0x28
+#define IPMI_CMD_GET_SENSOR_EVT_ENABLE    0x29
+#define IPMI_CMD_REARM_SENSOR_EVTS        0x2a
+#define IPMI_CMD_GET_SENSOR_EVT_STATUS    0x2b
+#define IPMI_CMD_GET_SENSOR_READING       0x2d

I have started adding a few commands and got scared by IPMI_CMD_SET_SENSOR_READING spec. By any chance, would you have one in stock ?

I'm not sure what you mean. That was added recently and is optional. If your target system doesn't implement it, you don't really need to implement it, either.

The IPMI spec is short on rationale, but I'm guessing that particular command has two purposes:

* Sensors whose value is provided by software running on the system.
* Testing for situations that you cannot reasonably reproduce on a real system.

Is there a reason you would need this particular command? If so, it will take a little work but won't be too hard.

Quoted 99 lines
Quoted 99 lines
hw/ipmi/ipmi_bmc_sim.c new file +99 -0
+
+/* #define IPMI_NETFN_APP             0x06 In ipmi.h */
+#define IPMI_NETFN_APP_MAXCMD             0x36
+
+#define IPMI_CMD_GET_DEVICE_ID            0x01
+#define IPMI_CMD_COLD_RESET               0x02
+#define IPMI_CMD_WARM_RESET               0x03
+#define IPMI_CMD_RESET_WATCHDOG_TIMER     0x22
+#define IPMI_CMD_SET_WATCHDOG_TIMER       0x24
+#define IPMI_CMD_GET_WATCHDOG_TIMER       0x25
+#define IPMI_CMD_SET_BMC_GLOBAL_ENABLES   0x2e
+#define IPMI_CMD_GET_BMC_GLOBAL_ENABLES   0x2f
+#define IPMI_CMD_CLR_MSG_FLAGS            0x30
+#define IPMI_CMD_GET_MSG_FLAGS            0x31
+#define IPMI_CMD_GET_MSG                  0x33
+#define IPMI_CMD_SEND_MSG                 0x34
+#define IPMI_CMD_READ_EVT_MSG_BUF         0x35
+
+#define IPMI_NETFN_STORAGE            0x0a
+#define IPMI_NETFN_STORAGE_MAXCMD         0x4a
+
+#define IPMI_CMD_GET_SDR_REP_INFO         0x20
+#define IPMI_CMD_GET_SDR_REP_ALLOC_INFO   0x21
+#define IPMI_CMD_RESERVE_SDR_REP          0x22
+#define IPMI_CMD_GET_SDR                  0x23
+#define IPMI_CMD_ADD_SDR                  0x24
+#define IPMI_CMD_PARTIAL_ADD_SDR          0x25
+#define IPMI_CMD_DELETE_SDR               0x26
+#define IPMI_CMD_CLEAR_SDR_REP            0x27
+#define IPMI_CMD_GET_SDR_REP_TIME         0x28
+#define IPMI_CMD_SET_SDR_REP_TIME         0x29
+#define IPMI_CMD_ENTER_SDR_REP_UPD_MODE   0x2A
+#define IPMI_CMD_EXIT_SDR_REP_UPD_MODE    0x2B
+#define IPMI_CMD_RUN_INIT_AGENT           0x2C
+#define IPMI_CMD_GET_SEL_INFO             0x40
+#define IPMI_CMD_GET_SEL_ALLOC_INFO       0x41
+#define IPMI_CMD_RESERVE_SEL              0x42
+#define IPMI_CMD_GET_SEL_ENTRY            0x43
+#define IPMI_CMD_ADD_SEL_ENTRY            0x44
+#define IPMI_CMD_PARTIAL_ADD_SEL_ENTRY    0x45
+#define IPMI_CMD_DELETE_SEL_ENTRY         0x46
+#define IPMI_CMD_CLEAR_SEL                0x47
+#define IPMI_CMD_GET_SEL_TIME             0x48
+#define IPMI_CMD_SET_SEL_TIME             0x49
+
+
+/* Same as a timespec struct. */
+struct ipmi_time {
+    long tv_sec;
+    long tv_nsec;
+};
+
+#define MAX_SEL_SIZE 128
+
+typedef struct IPMISel {
+    uint8_t sel[MAX_SEL_SIZE][16];
+    unsigned int next_free;
+    long time_offset;
+    uint16_t reservation;
+    uint8_t last_addition[4];
+    uint8_t last_clear[4];
+    uint8_t overflow;
+} IPMISel;
+
+#define MAX_SDR_SIZE 16384
+
+typedef struct IPMISdr {
+    uint8_t sdr[MAX_SDR_SIZE];
+    unsigned int next_free;
+    uint16_t next_rec_id;
+    uint16_t reservation;
+    uint8_t last_addition[4];
+    uint8_t last_clear[4];
+    uint8_t overflow;
+} IPMISdr;
+
+typedef struct IPMISensor {
+    uint8_t status;
+    uint8_t reading;
+    uint16_t states_suppt;
+    uint16_t assert_suppt;
+    uint16_t deassert_suppt;
+    uint16_t states;
+    uint16_t assert_states;
+    uint16_t deassert_states;
+    uint16_t assert_enable;
+    uint16_t deassert_enable;
+    uint8_t  sensor_type;
+    uint8_t  evt_reading_type_code;
+} IPMISensor;
+#define IPMI_SENSOR_GET_PRESENT(s)       ((s)->status & 0x01)
+#define IPMI_SENSOR_SET_PRESENT(s, v)    ((s)->status = (s->status & ~0x01) | \
+                                             !!(v))
+#define IPMI_SENSOR_GET_SCAN_ON(s)       ((s)->status & 0x40)
+#define IPMI_SENSOR_SET_SCAN_ON(s, v)    ((s)->status = (s->status & ~0x40) | \
+                                             ((!!(v)) << 6))
+#define IPMI_SENSOR_GET_EVENTS_ON(s)     ((s)->status & 0x80)
+#define IPMI_SENSOR_SET_EVENTS_ON(s, v)  ((s)->status = (s->status & ~0x80) | \
+                                             ((!!(v)) << 7))
Quoted 8 lines

hw/ipmi/ipmi_bmc_sim.c line 151

Quoted 6 lines
hw/ipmi/ipmi_bmc_sim.c new file +6 -0
+#define IPMI_SENSOR_GET_RET_STATUS(s)    ((s)->status & 0xc0)
+#define IPMI_SENSOR_SET_RET_STATUS(s, v) ((s)->status = (s->status & ~0xc0) | \
+                                             (v & 0xc0))
+#define IPMI_SENSOR_IS_DISCRETE(s) ((s)->evt_reading_type_code != 1)
+
+#define MAX_SENSORS 20

Could we extend that a bit ? like 80 ? There are real systems with more than 180 sensors.

Actually, there are systems with more than that :). This was a quick hack, and I'm generally against arbitrary limitations. But this can be fixed.

Quoted 168 lines
Quoted 168 lines
hw/ipmi/ipmi_bmc_sim.c new file +168 -0
+#define IPMI_WATCHDOG_SENSOR 0
+
+typedef struct IPMIBmcSim IPMIBmcSim;
+
+#define MAX_NETFNS 64
+typedef void (*IPMICmdHandler)(IPMIBmcSim *s,
+                               uint8_t *cmd, unsigned int cmd_len,
+                               uint8_t *rsp, unsigned int *rsp_len,
+                               unsigned int max_rsp_len);
+typedef struct IPMINetfn {
+    unsigned int cmd_nums;
+    const IPMICmdHandler *cmd_handlers;
+} IPMINetfn;
+
+typedef struct IPMIRcvBufEntry {
+    QTAILQ_ENTRY(IPMIRcvBufEntry) entry;
+    uint8_t len;
+    uint8_t buf[MAX_IPMI_MSG_SIZE];
+} IPMIRcvBufEntry;
+
+#define TYPE_IPMI_BMC_SIMULATOR "ipmi-bmc-sim"
+#define IPMI_BMC_SIMULATOR(obj) OBJECT_CHECK(IPMIBmcSim, (obj), \
+                                        TYPE_IPMI_BMC_SIMULATOR)
+struct IPMIBmcSim {
+    IPMIBmc parent;
+
+    QEMUTimer *timer;
+
+    uint8_t bmc_global_enables;
+    uint8_t msg_flags;
+
+    bool     watchdog_initialized;
+    uint8_t  watchdog_use;
+    uint8_t  watchdog_action;
+    uint8_t  watchdog_pretimeout; /* In seconds */
+    bool     watchdog_expired;
+    uint16_t watchdog_timeout; /* in 100's of milliseconds */
+
+    bool     watchdog_running;
+    bool     watchdog_preaction_ran;
+    int64_t  watchdog_expiry;
+
+    uint8_t device_id;
+    uint8_t ipmi_version;
+    uint8_t device_rev;
+    uint8_t fwrev1;
+    uint8_t fwrev2;
+    uint8_t mfg_id[3];
+    uint8_t product_id[2];
+
+    IPMISel sel;
+    IPMISdr sdr;
+    IPMISensor sensors[MAX_SENSORS];
+
+    /* Odd netfns are for responses, so we only need the even ones. */
+    const IPMINetfn *netfns[MAX_NETFNS / 2];
+
+    QemuMutex lock;
+    /* We allow one event in the buffer */
+    uint8_t evtbuf[16];
+
+    QTAILQ_HEAD(, IPMIRcvBufEntry) rcvbufs;
+};
+
+#define IPMI_BMC_MSG_FLAG_WATCHDOG_TIMEOUT_MASK        (1 << 3)
+#define IPMI_BMC_MSG_FLAG_EVT_BUF_FULL                 (1 << 1)
+#define IPMI_BMC_MSG_FLAG_RCV_MSG_QUEUE                (1 << 0)
+#define IPMI_BMC_MSG_FLAG_WATCHDOG_TIMEOUT_MASK_SET(s) \
+    (IPMI_BMC_MSG_FLAG_WATCHDOG_TIMEOUT_MASK & (s)->msg_flags)
+#define IPMI_BMC_MSG_FLAG_EVT_BUF_FULL_SET(s) \
+    (IPMI_BMC_MSG_FLAG_EVT_BUF_FULL & (s)->msg_flags)
+#define IPMI_BMC_MSG_FLAG_RCV_MSG_QUEUE_SET(s) \
+    (IPMI_BMC_MSG_FLAG_RCV_MSG_QUEUE & (s)->msg_flags)
+
+#define IPMI_BMC_RCV_MSG_QUEUE_INT_BIT    0
+#define IPMI_BMC_EVBUF_FULL_INT_BIT       1
+#define IPMI_BMC_EVENT_MSG_BUF_BIT        2
+#define IPMI_BMC_EVENT_LOG_BIT            3
+#define IPMI_BMC_MSG_INTS_ON(s) ((s)->bmc_global_enables & \
+                                 (1 << IPMI_BMC_RCV_MSG_QUEUE_INT_BIT))
+#define IPMI_BMC_EVBUF_FULL_INT_ENABLED(s) ((s)->bmc_global_enables & \
+                                        (1 << IPMI_BMC_EVBUF_FULL_INT_BIT))
+#define IPMI_BMC_EVENT_LOG_ENABLED(s) ((s)->bmc_global_enables & \
+                                       (1 << IPMI_BMC_EVENT_LOG_BIT))
+#define IPMI_BMC_EVENT_MSG_BUF_ENABLED(s) ((s)->bmc_global_enables & \
+                                           (1 << IPMI_BMC_EVENT_MSG_BUF_BIT))
+
+#define IPMI_BMC_WATCHDOG_USE_MASK 0xc7
+#define IPMI_BMC_WATCHDOG_ACTION_MASK 0x77
+#define IPMI_BMC_WATCHDOG_GET_USE(s) ((s)->watchdog_use & 0x7)
+#define IPMI_BMC_WATCHDOG_GET_DONT_LOG(s) (((s)->watchdog_use >> 7) & 0x1)
+#define IPMI_BMC_WATCHDOG_GET_DONT_STOP(s) (((s)->watchdog_use >> 6) & 0x1)
+#define IPMI_BMC_WATCHDOG_GET_PRE_ACTION(s) (((s)->watchdog_action >> 4) & 0x7)
+#define IPMI_BMC_WATCHDOG_PRE_NONE               0
+#define IPMI_BMC_WATCHDOG_PRE_SMI                1
+#define IPMI_BMC_WATCHDOG_PRE_NMI                2
+#define IPMI_BMC_WATCHDOG_PRE_MSG_INT            3
+#define IPMI_BMC_WATCHDOG_GET_ACTION(s) ((s)->watchdog_action & 0x7)
+#define IPMI_BMC_WATCHDOG_ACTION_NONE            0
+#define IPMI_BMC_WATCHDOG_ACTION_RESET           1
+#define IPMI_BMC_WATCHDOG_ACTION_POWER_DOWN      2
+#define IPMI_BMC_WATCHDOG_ACTION_POWER_CYCLE     3
+
+
+/* Add a byte to the response. */
+#define IPMI_ADD_RSP_DATA(b) \
+    do {                                                   \
+        if (*rsp_len >= max_rsp_len) {                     \
+            rsp[2] = IPMI_CC_REQUEST_DATA_TRUNCATED;       \
+            goto out;                                      \
+        }                                                  \
+        rsp[(*rsp_len)++] = (b);                           \
+    } while (0)
+
+/* Verify that the received command is a certain length. */
+#define IPMI_CHECK_CMD_LEN(l) \
+    if (cmd_len < l) {                                     \
+        rsp[2] = IPMI_CC_REQUEST_DATA_LENGTH_INVALID;      \
+        goto out; \
+    }
+
+/* Check that the reservation in the command is valid. */
+#define IPMI_CHECK_RESERVATION(off, r) \
+    do {                                                   \
+        if ((cmd[off] | (cmd[off + 1] << 8)) != r) {       \
+            rsp[2] = IPMI_CC_INVALID_RESERVATION;          \
+            goto out;                                      \
+        }                                                  \
+    } while (0)
+
+
+static void ipmi_sim_handle_timeout(IPMIBmcSim *ibs);
+
+static void ipmi_gettime(struct ipmi_time *time)
+{
+    int64_t stime;
+
+    stime = qemu_clock_get_ns(QEMU_CLOCK_HOST);
+    time->tv_sec = stime / 1000000000LL;
+    time->tv_nsec = stime % 1000000000LL;
+}
+
+static int64_t ipmi_getmonotime(void)
+{
+    return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
+}
+
+static void ipmi_timeout(void *opaque)
+{
+    IPMIBmcSim *ibs = opaque;
+
+    ipmi_sim_handle_timeout(ibs);
+}
+
+static void set_timestamp(IPMIBmcSim *ibs, uint8_t *ts)
+{
+    unsigned int val;
+    struct ipmi_time now;
+
+    ipmi_gettime(&now);
+    val = now.tv_sec + ibs->sel.time_offset;
+    ts[0] = val & 0xff;
+    ts[1] = (val >> 8) & 0xff;
+    ts[2] = (val >> 16) & 0xff;
+    ts[3] = (val >> 24) & 0xff;
+}
+
+static void sdr_inc_reservation(IPMISdr *sdr)
Quoted 9 lines

hw/ipmi/ipmi_bmc_sim.c line 325

Quoted 6 lines
hw/ipmi/ipmi_bmc_sim.c new file +6 -0
+{
+    sdr->reservation++;
+    if (sdr->reservation == 0) {
+        sdr->reservation = 1;
+    }
+}

Could we externalize the following routine ? for platforms needing to add a few initial sdrs.

Yes. You'll probably need a few others, too.

Quoted 10 lines

hw/ipmi/ipmi_bmc_sim.c line 334

Quoted 8 lines
hw/ipmi/ipmi_bmc_sim.c new file +8 -0
+static int sdr_add_entry(IPMIBmcSim *ibs, const uint8_t *entry,
+                         unsigned int len, uint16_t *recid)
+{
+    if ((len < 5) || (len > 255)) {
+        return 1;
+    }
+
+    if (entry[ibs->sdr.next_free + 4] != len) {

I think you meant :

Quoted 2 lines
	if (entry[4] != len) {

no ?

You are correct, this will be fixed in my next release.

Quoted 39 lines
Quoted 24 lines
hw/ipmi/ipmi_bmc_sim.c new file +23 -0
+        return 1;
+    }
+
+    if (ibs->sdr.next_free + len > MAX_SDR_SIZE) {
+        ibs->sdr.overflow = 1;
+        return 1;
+    }
+
+    memcpy(ibs->sdr.sdr + ibs->sdr.next_free, entry, len);
+    ibs->sdr.sdr[ibs->sdr.next_free] = ibs->sdr.next_rec_id & 0xff;
+    ibs->sdr.sdr[ibs->sdr.next_free+1] = (ibs->sdr.next_rec_id >> 8) & 0xff;
+    ibs->sdr.sdr[ibs->sdr.next_free+2] = 0x51; /* Conform to IPMI 1.5 spec */
+
+    if (recid) {
+        *recid = ibs->sdr.next_rec_id;
+    }
+    ibs->sdr.next_rec_id++;
+    set_timestamp(ibs, ibs->sdr.last_addition);
+    ibs->sdr.next_free += len;
+    sdr_inc_reservation(&ibs->sdr);
+    return 0;
+}
+

[ ... ]

hw/ipmi/ipmi_bmc_sim.c line 1652

Quoted 11 lines
hw/ipmi/ipmi_bmc_sim.c new file +11 -0
+static void register_cmds(IPMIBmcSim *s)
+{
+    ipmi_register_netfn(s, IPMI_NETFN_CHASSIS, &chassis_netfn);
+    ipmi_register_netfn(s, IPMI_NETFN_SENSOR_EVENT, &sensor_event_netfn);
+    ipmi_register_netfn(s, IPMI_NETFN_APP, &app_netfn);
+    ipmi_register_netfn(s, IPMI_NETFN_STORAGE, &storage_netfn);
+}
+
+static const uint8_t init_sdrs[] = {
+    /* Watchdog device */
+    0x00, 0x00, 0x51, 0x02,   40, 0x20, 0x00, 0x00,

Regarding the 'length' byte, the specs says :

Quoted 4 lines

Record Length: Number of bytes of data following the Record Length field.

So it should be 35 and not 40 ? This change will problably have some consequences in the routine above.

Yes, I've fixed these both.

Quoted 42 lines
Quoted 42 lines
hw/ipmi/ipmi_bmc_sim.c new file +41 -0
+    0x23, 0x01, 0x63, 0x00, 0x23, 0x6f, 0x0f, 0x01,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8,
+    'W',  'a',  't',  'c',  'h',  'd',  'o',  'g',
+    /* End */
+    0xff, 0xff, 0x00, 0x00, 0x00
+};
+
+static void ipmi_sim_init(Object *obj)
+{
+    IPMIBmc *b = IPMI_BMC(obj);
+    unsigned int i;
+    unsigned int next_recid, recid;
+    IPMIBmcSim *ibs = IPMI_BMC_SIMULATOR(b);
+
+    qemu_mutex_init(&ibs->lock);
+    QTAILQ_INIT(&ibs->rcvbufs);
+
+    ibs->bmc_global_enables = (1 << IPMI_BMC_EVENT_LOG_BIT);
+    ibs->device_id = 0x20;
+    ibs->ipmi_version = 0x02; /* IPMI 2.0 */
+    for (i = 0; i < 4; i++) {
+        ibs->sel.last_addition[i] = 0xff;
+        ibs->sel.last_clear[i] = 0xff;
+        ibs->sdr.last_addition[i] = 0xff;
+        ibs->sdr.last_clear[i] = 0xff;
+    }
+
+    next_recid = 0;
+    for (i = 0;;) {
+        int len;
+        if ((i + 5) > sizeof(init_sdrs)) {
+            error_report("Problem with recid 0x%4.4x\n", i);
+            return;
+        }
+        len = init_sdrs[i + 4];
+        recid = init_sdrs[i] | (init_sdrs[i + 1] << 8);
+        if (recid == 0xffff) {
+            break;
+        }
+        if ((i + len) > sizeof(init_sdrs)) {
Quoted 8 lines

hw/ipmi/ipmi_bmc_sim.c line 1700

Quoted 7 lines
hw/ipmi/ipmi_bmc_sim.c new file +7 -0
+            error_report("Problem with recid 0x%4.4x\n", i);
+            return;
+        }
+        if (recid != next_recid) {
+            error_report("Problem with recid 0x%4.4x\n", i);
+            return;
+        }

May be remove the check on recid which is useless here ?

Yes, that was left over from something else that was removed.

Thanks,

-corey

Quoted 32 lines
Quoted 32 lines
hw/ipmi/ipmi_bmc_sim.c new file +31 -0
+        sdr_add_entry(ibs, init_sdrs + i, len, NULL);
+        i += len;
+    }
+
+    ipmi_init_sensors_from_sdrs(ibs);
+    register_cmds(ibs);
+
+    ibs->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, ipmi_timeout, ibs);
+}
+
+static void ipmi_sim_class_init(ObjectClass *oc, void *data)
+{
+    IPMIBmcClass *bk = IPMI_BMC_CLASS(oc);
+
+    bk->handle_command = ipmi_sim_handle_command;
+}
+
+static const TypeInfo ipmi_sim_type = {
+    .name          = TYPE_IPMI_BMC_SIMULATOR,
+    .parent        = TYPE_IPMI_BMC,
+    .instance_size = sizeof(IPMIBmcSim),
+    .instance_init = ipmi_sim_init,
+    .class_init    = ipmi_sim_class_init,
+};
+
+static void ipmi_sim_register_types(void)
+{
+    type_register_static(&ipmi_sim_type);
+}
+
+type_init(ipmi_sim_register_types)
#7 lore raw

Re: [Qemu-devel] [PATCH v4 03/17] ipmi: Add a local BMC simulation

Quoted 9 lines · Corey Minyard
Quoted 1 line · Cédric Le Goater

A few comments below,

Thanks a bunch for the review. As you probably have guessed, this was not really intended as a fully functional BMC, though it has most of the trappings of what you would need to implement one.

I assume you are working on the power systems, and it makes sense to extend this for that application.

Yes. I am trying to add the few extra commands the opal firmware and the kernel are using when running on an open power platform.

It is currently booting fine but there are a few errors and still a few gaps to fill to make it look like a BMC was in charge. FRU would be nice also but we will see how it goes.

Quoted 107 lines
Quoted 94 lines · On 11/12/2015 08:02 PM, [email protected] wrote:
Quoted 93 lines

From: Corey Minyard <[email protected]>

This provides a minimal local BMC, basically enough to comply with the spec and provide a complete watchdog timer (including a sensor, SDR, and event).

---
 default-configs/i386-softmmu.mak   |    1 +
 default-configs/x86_64-softmmu.mak |    1 +
 hw/ipmi/Makefile.objs              |    1 +
 hw/ipmi/ipmi_bmc_sim.c             | 1731 ++++++++++++++++++++++++++++++++++++
 4 files changed, 1734 insertions(+)
 create mode 100644 hw/ipmi/ipmi_bmc_sim.c
default-configs/i386-softmmu.mak +1 -0
index 8fa751a..00a0346 100644
@@ -10,6 +10,7 @@ CONFIG_VMWARE_VGA=y
 CONFIG_VIRTIO_VGA=y
 CONFIG_VMMOUSE=y
 CONFIG_IPMI=y
+CONFIG_IPMI_LOCAL=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
default-configs/x86_64-softmmu.mak +1 -0
index 6767f4f..39a619f 100644
@@ -10,6 +10,7 @@ CONFIG_VMWARE_VGA=y
 CONFIG_VIRTIO_VGA=y
 CONFIG_VMMOUSE=y
 CONFIG_IPMI=y
+CONFIG_IPMI_LOCAL=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_I8254=y
hw/ipmi/Makefile.objs +1 -0
index 65bde11..875271c 100644
@@ -1 +1,2 @@
 common-obj-$(CONFIG_IPMI) += ipmi.o
+common-obj-$(CONFIG_IPMI_LOCAL) += ipmi_bmc_sim.o
hw/ipmi/ipmi_bmc_sim.c new file +41 -0
new file mode 100644
index 0000000..d246029
@@ -0,0 +1,1731 @@
+/*
+ * IPMI BMC emulation
+ *
+ * Copyright (c) 2015 Corey Minyard, MontaVista Software, LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include "qemu/timer.h"
+#include "hw/ipmi/ipmi.h"
+#include "qemu/error-report.h"
+
+#define IPMI_NETFN_CHASSIS            0x00
+#define IPMI_NETFN_CHASSIS_MAXCMD         0x03
+
+#define IPMI_CMD_GET_CHASSIS_CAPABILITIES 0x00
+#define IPMI_CMD_GET_CHASSIS_STATUS       0x01
+#define IPMI_CMD_CHASSIS_CONTROL          0x02
+
+#define IPMI_NETFN_SENSOR_EVENT       0x04
+#define IPMI_NETFN_SENSOR_EVENT_MAXCMD    0x2e
+
Quoted 8 lines

hw/ipmi/ipmi_bmc_sim.c line 46

Quoted 5 lines
hw/ipmi/ipmi_bmc_sim.c new file +5 -0
+#define IPMI_CMD_SET_SENSOR_EVT_ENABLE    0x28
+#define IPMI_CMD_GET_SENSOR_EVT_ENABLE    0x29
+#define IPMI_CMD_REARM_SENSOR_EVTS        0x2a
+#define IPMI_CMD_GET_SENSOR_EVT_STATUS    0x2b
+#define IPMI_CMD_GET_SENSOR_READING       0x2d

I have started adding a few commands and got scared by IPMI_CMD_SET_SENSOR_READING spec. By any chance, would you have one in stock ?

I'm not sure what you mean. That was added recently and is optional. If your target system doesn't implement it, you don't really need to implement it, either.

Quoted 8 lines

The IPMI spec is short on rationale, but I'm guessing that particular command has two purposes:

* Sensors whose value is provided by software running on the system.
* Testing for situations that you cannot reasonably reproduce on a real system.

Is there a reason you would need this particular command?

Yes. The Open Power systems use this command to set the "System Progress Sensor (0F)" and another one "Boot Count (C3) " which is an OEM one.

Looking at the code, I think the message we send as an issue with the spec, or the receiver has non specified expectations :

https://github.com/open-power/skiboot/blob/master/hw/ipmi/ipmi-sensor.c

	request.sensor_number = fw_sensor_num;
	request.operation = 0xa0; /* Set event data bytes, assertion bits */
	request.assertion_mask[0] = 0x04; /* Firmware progress offset */
	request.event_data[1] = state;

Should not that be :

	request.sensor_number = fw_sensor_num;
	request.operation = 0xa0; /* Set event data bytes, assertion bits */
	request.assertion_mask[0] = 0x04; /* Firmware progress offset (2) */
	request.event_data[1] = 0xc2; /* event extension in byte2, event offset 2 */
	request.event_data[2] = state;

?

Quoted 1 line

If so, it will take a little work but won't be too hard.

Well, the event data operations should be interesting ! Should we generate an event for each command SET_SENSOR_READING we receive ?

Thanks,

C.