ppc/pnv: add initial IPMI sensors for the BMC simulator
[qemu.git] / hw / ppc / pnv_bmc.c
1 /*
2 * QEMU PowerNV, BMC related functions
3 *
4 * Copyright (c) 2016-2017, IBM Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 2, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "qemu/osdep.h"
20 #include "hw/hw.h"
21 #include "sysemu/sysemu.h"
22 #include "target/ppc/cpu.h"
23 #include "qapi/error.h"
24 #include "qemu/log.h"
25 #include "hw/ipmi/ipmi.h"
26 #include "hw/ppc/fdt.h"
27
28 #include "hw/ppc/pnv.h"
29
30 #include <libfdt.h>
31
32 /* TODO: include definition in ipmi.h */
33 #define IPMI_SDR_FULL_TYPE 1
34
35 void pnv_bmc_populate_sensors(IPMIBmc *bmc, void *fdt)
36 {
37 int offset;
38 int i;
39 const struct ipmi_sdr_compact *sdr;
40 uint16_t nextrec;
41
42 offset = fdt_add_subnode(fdt, 0, "/bmc");
43 _FDT(offset);
44
45 _FDT((fdt_setprop_string(fdt, offset, "name", "bmc")));
46 _FDT((fdt_setprop_cell(fdt, offset, "#address-cells", 0x1)));
47 _FDT((fdt_setprop_cell(fdt, offset, "#size-cells", 0x0)));
48
49 offset = fdt_add_subnode(fdt, offset, "sensors");
50 _FDT(offset);
51
52 _FDT((fdt_setprop_cell(fdt, offset, "#address-cells", 0x1)));
53 _FDT((fdt_setprop_cell(fdt, offset, "#size-cells", 0x0)));
54
55 for (i = 0; !ipmi_bmc_sdr_find(bmc, i, &sdr, &nextrec); i++) {
56 int off;
57 char *name;
58
59 if (sdr->header.rec_type != IPMI_SDR_COMPACT_TYPE &&
60 sdr->header.rec_type != IPMI_SDR_FULL_TYPE) {
61 continue;
62 }
63
64 name = g_strdup_printf("sensor@%x", sdr->sensor_owner_number);
65 off = fdt_add_subnode(fdt, offset, name);
66 _FDT(off);
67 g_free(name);
68
69 _FDT((fdt_setprop_cell(fdt, off, "reg", sdr->sensor_owner_number)));
70 _FDT((fdt_setprop_string(fdt, off, "name", "sensor")));
71 _FDT((fdt_setprop_string(fdt, off, "compatible", "ibm,ipmi-sensor")));
72 _FDT((fdt_setprop_cell(fdt, off, "ipmi-sensor-reading-type",
73 sdr->reading_type)));
74 _FDT((fdt_setprop_cell(fdt, off, "ipmi-entity-id",
75 sdr->entity_id)));
76 _FDT((fdt_setprop_cell(fdt, off, "ipmi-entity-instance",
77 sdr->entity_instance)));
78 _FDT((fdt_setprop_cell(fdt, off, "ipmi-sensor-type",
79 sdr->sensor_type)));
80 }
81 }