All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@kaod.org>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org,
	"Cédric Le Goater" <clg@kaod.org>
Subject: [Qemu-devel] [PATCH 15/21] ppc/pnv: add initial IPMI sensors for the BMC simulator
Date: Wed,  5 Apr 2017 14:41:40 +0200	[thread overview]
Message-ID: <1491396106-26376-16-git-send-email-clg@kaod.org> (raw)
In-Reply-To: <1491396106-26376-1-git-send-email-clg@kaod.org>

Skiboot, the firmware for the PowerNV platform, expects the BMC to
provide some specific IPMI sensors. These sensors are exposed in the
device tree and their values are updated by the firmware at boot time.

Sensors of interest are :

	"FW Boot Progress"
	"Boot Count"

As such a device is defined on the command line, we can only detect
its presence at reset time.

Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
 hw/ppc/Makefile.objs |  2 +-
 hw/ppc/pnv.c         | 17 +++++++++++
 hw/ppc/pnv_bmc.c     | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/ppc/pnv.h |  7 +++++
 4 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100644 hw/ppc/pnv_bmc.c

diff --git a/hw/ppc/Makefile.objs b/hw/ppc/Makefile.objs
index ef67ea820158..7efc68674819 100644
--- a/hw/ppc/Makefile.objs
+++ b/hw/ppc/Makefile.objs
@@ -6,7 +6,7 @@ obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o
 obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o
 obj-$(CONFIG_PSERIES) += spapr_cpu_core.o spapr_ovec.o
 # IBM PowerNV
-obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o pnv_lpc.o pnv_psi.o pnv_occ.o
+obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o pnv_lpc.o pnv_psi.o pnv_occ.o pnv_bmc.o
 ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy)
 obj-y += spapr_pci_vfio.o
 endif
diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
index dfa1cf849b35..c7caecad0aa6 100644
--- a/hw/ppc/pnv.c
+++ b/hw/ppc/pnv.c
@@ -35,6 +35,7 @@
 #include "qapi/visitor.h"
 #include "monitor/monitor.h"
 #include "hw/intc/intc.h"
+#include "hw/ipmi/ipmi.h"
 
 #include "hw/ppc/xics.h"
 #include "hw/ppc/pnv_xscom.h"
@@ -458,16 +459,32 @@ static void *powernv_create_fdt(MachineState *machine)
     }
 
     powernv_populate_isa(pnv->isa_bus, fdt);
+
+    if (pnv->bmc) {
+        pnv_bmc_populate_sensors(pnv->bmc, fdt);
+    }
+
     return fdt;
 }
 
 static void ppc_powernv_reset(void)
 {
     MachineState *machine = MACHINE(qdev_get_machine());
+    PnvMachineState *pnv = POWERNV_MACHINE(machine);
     void *fdt;
 
     qemu_devices_reset();
 
+    /* OpenPOWER systems have a BMC, which can be defined on the
+     * command line with:
+     *
+     *   -device ipmi-bmc-sim,id=bmc0
+     *
+     * This is the internal simulator but it could also be an external
+     * BMC.
+     */
+    pnv->bmc = object_resolve_path_type("", TYPE_IPMI_BMC, NULL);
+
     fdt = powernv_create_fdt(machine);
 
     /* Pack resulting tree */
diff --git a/hw/ppc/pnv_bmc.c b/hw/ppc/pnv_bmc.c
new file mode 100644
index 000000000000..2998530dc4c0
--- /dev/null
+++ b/hw/ppc/pnv_bmc.c
@@ -0,0 +1,81 @@
+/*
+ * QEMU PowerNV, BMC related functions
+ *
+ * Copyright (c) 2016-2017, IBM Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/hw.h"
+#include "sysemu/sysemu.h"
+#include "target/ppc/cpu.h"
+#include "qapi/error.h"
+#include "qemu/log.h"
+#include "hw/ipmi/ipmi.h"
+#include "hw/ppc/fdt.h"
+
+#include "hw/ppc/pnv.h"
+
+#include <libfdt.h>
+
+/* TODO: include definition in ipmi.h */
+#define IPMI_SDR_FULL_TYPE 1
+
+void pnv_bmc_populate_sensors(Object *bmc, void *fdt)
+{
+    int offset;
+    int i;
+    const struct ipmi_sdr_compact *sdr;
+    uint16_t nextrec;
+
+    offset = fdt_add_subnode(fdt, 0, "/bmc");
+    _FDT(offset);
+
+    _FDT((fdt_setprop_string(fdt, offset, "name", "bmc")));
+    _FDT((fdt_setprop_cell(fdt, offset, "#address-cells", 0x1)));
+    _FDT((fdt_setprop_cell(fdt, offset, "#size-cells", 0x0)));
+
+    offset = fdt_add_subnode(fdt, offset, "sensors");
+    _FDT(offset);
+
+    _FDT((fdt_setprop_cell(fdt, offset, "#address-cells", 0x1)));
+    _FDT((fdt_setprop_cell(fdt, offset, "#size-cells", 0x0)));
+
+    for (i = 0; !ipmi_bmc_sdr_find(IPMI_BMC(bmc), i, &sdr, &nextrec); i++) {
+        int off;
+        char *name;
+
+        if (sdr->header.rec_type != IPMI_SDR_COMPACT_TYPE ||
+            sdr->header.rec_type != IPMI_SDR_FULL_TYPE) {
+            continue;
+        }
+
+        name = g_strdup_printf("sensor@%x", sdr->sensor_owner_number);
+        off = fdt_add_subnode(fdt, offset, name);
+        _FDT(off);
+        g_free(name);
+
+        _FDT((fdt_setprop_cell(fdt, off, "reg", sdr->sensor_owner_number)));
+        _FDT((fdt_setprop_string(fdt, off, "name", "sensor")));
+        _FDT((fdt_setprop_string(fdt, off, "compatible", "ibm,ipmi-sensor")));
+        _FDT((fdt_setprop_cell(fdt, off, "ipmi-sensor-reading-type",
+                               sdr->reading_type)));
+        _FDT((fdt_setprop_cell(fdt, off, "ipmi-entity-id",
+                               sdr->entity_id)));
+        _FDT((fdt_setprop_cell(fdt, off, "ipmi-entity-instance",
+                               sdr->entity_instance)));
+        _FDT((fdt_setprop_cell(fdt, off, "ipmi-sensor-type",
+                               sdr->sensor_type)));
+    }
+}
diff --git a/include/hw/ppc/pnv.h b/include/hw/ppc/pnv.h
index b45a0d91c813..050763f6cf54 100644
--- a/include/hw/ppc/pnv.h
+++ b/include/hw/ppc/pnv.h
@@ -130,12 +130,19 @@ typedef struct PnvMachineState {
 
     ISABus       *isa_bus;
     uint32_t     cpld_irqstate;
+
+    Object       *bmc;
 } PnvMachineState;
 
 #define PNV_FDT_ADDR          0x01000000
 #define PNV_TIMEBASE_FREQ     512000000ULL
 
 /*
+ * BMC helpers
+ */
+void pnv_bmc_populate_sensors(Object *objbmc, void *fdt);
+
+/*
  * POWER8 MMIO base addresses
  */
 #define PNV_XSCOM_SIZE        0x800000000ull
-- 
2.7.4

  parent reply	other threads:[~2017-04-05 12:43 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-05 12:41 [Qemu-devel] [PATCH 00/21] pnv: PSI, OCC, IPMI and PCI models Cédric Le Goater
2017-04-05 12:41 ` [Qemu-devel] [PATCH 01/21] ppc/pnv: Add cut down PSI bridge model and hookup external interrupt Cédric Le Goater
2017-04-05 12:41 ` [Qemu-devel] [PATCH 02/21] ppc/pnv: Add OCC model stub with interrupt support Cédric Le Goater
2017-04-05 12:41 ` [Qemu-devel] [PATCH 03/21] ppc/pnv: Add support for POWER8+ LPC Controller Cédric Le Goater
2017-04-06  2:02   ` David Gibson
2017-04-06 12:27     ` Cédric Le Goater
2017-04-06 12:44     ` Cédric Le Goater
2017-04-06 21:54       ` Benjamin Herrenschmidt
2017-04-07  6:12         ` Cédric Le Goater
2017-04-05 12:41 ` [Qemu-devel] [PATCH 04/21] ppc/pnv: enable only one LPC bus Cédric Le Goater
2017-04-06  4:23   ` David Gibson
2017-04-06  9:06     ` Cédric Le Goater
2017-04-06  9:16       ` Benjamin Herrenschmidt
2017-04-06 11:50         ` Cédric Le Goater
2017-04-06 12:01           ` Benjamin Herrenschmidt
2017-04-06 12:35             ` Cédric Le Goater
2017-04-06 21:53               ` Benjamin Herrenschmidt
2017-04-07  6:14                 ` Cédric Le Goater
2017-04-08  2:14                   ` David Gibson
2017-04-05 12:41 ` [Qemu-devel] [PATCH 05/21] ppc: add IPMI support Cédric Le Goater
2017-04-05 12:41 ` [Qemu-devel] [PATCH 06/21] ipmi: use a file to load SDRs Cédric Le Goater
2017-04-05 12:41 ` [Qemu-devel] [PATCH 07/21] ipmi: provide support for FRUs Cédric Le Goater
2017-04-05 12:41 ` [Qemu-devel] [PATCH 08/21] ipmi: introduce an ipmi_bmc_sdr_find() API Cédric Le Goater
2017-04-06  5:36   ` David Gibson
2017-04-06  7:36     ` Cédric Le Goater
2017-04-06  7:38       ` Cédric Le Goater
2017-04-05 12:41 ` [Qemu-devel] [PATCH 09/21] ipmi: introduce an ipmi_bmc_gen_event() API Cédric Le Goater
2017-04-05 12:41 ` [Qemu-devel] [PATCH 10/21] ipmi: add SET_SENSOR_READING command Cédric Le Goater
2017-04-05 14:41   ` Corey Minyard
2017-04-06  7:29     ` Cédric Le Goater
2017-04-05 12:41 ` [Qemu-devel] [PATCH 11/21] ppc/pnv: scan ISA bus to populate device tree Cédric Le Goater
2017-04-10  5:17   ` David Gibson
2017-04-10  9:08     ` Cédric Le Goater
2017-04-10 13:16   ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2017-04-10 13:21     ` Cédric Le Goater
2017-04-05 12:41 ` [Qemu-devel] [PATCH 12/21] ppc/pnv: populate device tree for RTC devices Cédric Le Goater
2017-04-10  5:18   ` David Gibson
2017-04-05 12:41 ` [Qemu-devel] [PATCH 13/21] ppc/pnv: populate device tree for serial devices Cédric Le Goater
2017-04-10  5:19   ` David Gibson
2017-04-05 12:41 ` [Qemu-devel] [PATCH 14/21] ppc/pnv: populate device tree for IPMI BT devices Cédric Le Goater
2017-04-10  5:23   ` David Gibson
2017-04-05 12:41 ` Cédric Le Goater [this message]
2017-04-10  5:31   ` [Qemu-devel] [PATCH 15/21] ppc/pnv: add initial IPMI sensors for the BMC simulator David Gibson
2017-04-10  9:25     ` Cédric Le Goater
2017-04-05 12:41 ` [Qemu-devel] [PATCH 16/21] ppc/pnv: generate an OEM SEL event on shutdown Cédric Le Goater
2017-04-10  5:32   ` David Gibson
2017-04-05 12:41 ` [Qemu-devel] [PATCH 17/21] qdev: Add a hook for a bus to device if it can add devices Cédric Le Goater
2017-04-10  5:36   ` David Gibson
2017-04-05 12:41 ` [Qemu-devel] [PATCH 18/21] pci: Use the new pci_can_add_device() to enforce devfn_min/max Cédric Le Goater
2017-04-10  5:41   ` David Gibson
2017-04-10 19:48   ` Michael S. Tsirkin
2017-04-05 12:41 ` [Qemu-devel] [PATCH 19/21] pci: Don't call pci_irq_handler() for a negative intx Cédric Le Goater
2017-04-10  5:59   ` David Gibson
2017-04-11 15:41     ` Cédric Le Goater
2017-04-05 12:41 ` [Qemu-devel] [PATCH 20/21] ppc/pnv: Add model for Power8 PHB3 PCIe Host bridge Cédric Le Goater
2017-04-10  8:14   ` David Gibson
2017-04-11  3:05     ` Benjamin Herrenschmidt
2017-04-11  6:06       ` David Gibson
2017-04-11 16:03       ` Cédric Le Goater
2017-04-11 16:35     ` Cédric Le Goater
2017-04-05 12:41 ` [Qemu-devel] [PATCH 21/21] ppc/pnv: Create a default PCI layout Cédric Le Goater
2017-04-10  8:16   ` David Gibson
2017-04-11 11:10   ` [Qemu-devel] [Qemu-ppc] " Andrea Bolognani
2017-04-11 16:50     ` Cédric Le Goater
2017-04-12  8:02       ` Andrea Bolognani
2017-04-12  9:01         ` Cédric Le Goater

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1491396106-26376-16-git-send-email-clg@kaod.org \
    --to=clg@kaod.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.