1aeaef83dSCédric Le Goater /* 2aeaef83dSCédric Le Goater * QEMU PowerNV, BMC related functions 3aeaef83dSCédric Le Goater * 4aeaef83dSCédric Le Goater * Copyright (c) 2016-2017, IBM Corporation. 5aeaef83dSCédric Le Goater * 6aeaef83dSCédric Le Goater * This program is free software; you can redistribute it and/or modify 7aeaef83dSCédric Le Goater * it under the terms of the GNU General Public License, version 2, as 8aeaef83dSCédric Le Goater * published by the Free Software Foundation. 9aeaef83dSCédric Le Goater * 10aeaef83dSCédric Le Goater * This program is distributed in the hope that it will be useful, 11aeaef83dSCédric Le Goater * but WITHOUT ANY WARRANTY; without even the implied warranty of 12aeaef83dSCédric Le Goater * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13aeaef83dSCédric Le Goater * GNU General Public License for more details. 14aeaef83dSCédric Le Goater * 15aeaef83dSCédric Le Goater * You should have received a copy of the GNU General Public License 16aeaef83dSCédric Le Goater * along with this program; if not, see <http://www.gnu.org/licenses/>. 17aeaef83dSCédric Le Goater */ 18aeaef83dSCédric Le Goater 19aeaef83dSCédric Le Goater #include "qemu/osdep.h" 20aeaef83dSCédric Le Goater #include "target/ppc/cpu.h" 21aeaef83dSCédric Le Goater #include "qemu/log.h" 22aeaef83dSCédric Le Goater #include "hw/ipmi/ipmi.h" 23aeaef83dSCédric Le Goater #include "hw/ppc/fdt.h" 24aeaef83dSCédric Le Goater 25aeaef83dSCédric Le Goater #include "hw/ppc/pnv.h" 26aeaef83dSCédric Le Goater 27aeaef83dSCédric Le Goater #include <libfdt.h> 28aeaef83dSCédric Le Goater 29aeaef83dSCédric Le Goater /* TODO: include definition in ipmi.h */ 30aeaef83dSCédric Le Goater #define IPMI_SDR_FULL_TYPE 1 31aeaef83dSCédric Le Goater 32bce0b691SCédric Le Goater /* 33bce0b691SCédric Le Goater * OEM SEL Event data packet sent by BMC in response of a Read Event 34bce0b691SCédric Le Goater * Message Buffer command 35bce0b691SCédric Le Goater */ 36bce0b691SCédric Le Goater typedef struct OemSel { 37bce0b691SCédric Le Goater /* SEL header */ 38bce0b691SCédric Le Goater uint8_t id[2]; 39bce0b691SCédric Le Goater uint8_t type; 40bce0b691SCédric Le Goater uint8_t timestamp[4]; 41bce0b691SCédric Le Goater uint8_t manuf_id[3]; 42bce0b691SCédric Le Goater 43bce0b691SCédric Le Goater /* OEM SEL data (6 bytes) follows */ 44bce0b691SCédric Le Goater uint8_t netfun; 45bce0b691SCédric Le Goater uint8_t cmd; 46bce0b691SCédric Le Goater uint8_t data[4]; 47bce0b691SCédric Le Goater } OemSel; 48bce0b691SCédric Le Goater 49bce0b691SCédric Le Goater #define SOFT_OFF 0x00 50bce0b691SCédric Le Goater #define SOFT_REBOOT 0x01 51bce0b691SCédric Le Goater 52bce0b691SCédric Le Goater static void pnv_gen_oem_sel(IPMIBmc *bmc, uint8_t reboot) 53bce0b691SCédric Le Goater { 54bce0b691SCédric Le Goater /* IPMI SEL Event are 16 bytes long */ 55bce0b691SCédric Le Goater OemSel sel = { 56bce0b691SCédric Le Goater .id = { 0x55 , 0x55 }, 57bce0b691SCédric Le Goater .type = 0xC0, /* OEM */ 58bce0b691SCédric Le Goater .manuf_id = { 0x0, 0x0, 0x0 }, 59bce0b691SCédric Le Goater .timestamp = { 0x0, 0x0, 0x0, 0x0 }, 60bce0b691SCédric Le Goater .netfun = 0x3A, /* IBM */ 61bce0b691SCédric Le Goater .cmd = 0x04, /* AMI OEM SEL Power Notification */ 62bce0b691SCédric Le Goater .data = { reboot, 0xFF, 0xFF, 0xFF }, 63bce0b691SCédric Le Goater }; 64bce0b691SCédric Le Goater 65bce0b691SCédric Le Goater ipmi_bmc_gen_event(bmc, (uint8_t *) &sel, 0 /* do not log the event */); 66bce0b691SCédric Le Goater } 67bce0b691SCédric Le Goater 68bce0b691SCédric Le Goater void pnv_bmc_powerdown(IPMIBmc *bmc) 69bce0b691SCédric Le Goater { 70bce0b691SCédric Le Goater pnv_gen_oem_sel(bmc, SOFT_OFF); 71bce0b691SCédric Le Goater } 72bce0b691SCédric Le Goater 73b168a138SCédric Le Goater void pnv_dt_bmc_sensors(IPMIBmc *bmc, void *fdt) 74aeaef83dSCédric Le Goater { 75aeaef83dSCédric Le Goater int offset; 76aeaef83dSCédric Le Goater int i; 77aeaef83dSCédric Le Goater const struct ipmi_sdr_compact *sdr; 78aeaef83dSCédric Le Goater uint16_t nextrec; 79aeaef83dSCédric Le Goater 80*f42b6f53SCédric Le Goater offset = fdt_add_subnode(fdt, 0, "bmc"); 81aeaef83dSCédric Le Goater _FDT(offset); 82aeaef83dSCédric Le Goater 83aeaef83dSCédric Le Goater _FDT((fdt_setprop_string(fdt, offset, "name", "bmc"))); 84aeaef83dSCédric Le Goater offset = fdt_add_subnode(fdt, offset, "sensors"); 85aeaef83dSCédric Le Goater _FDT(offset); 86aeaef83dSCédric Le Goater 87aeaef83dSCédric Le Goater _FDT((fdt_setprop_cell(fdt, offset, "#address-cells", 0x1))); 88aeaef83dSCédric Le Goater _FDT((fdt_setprop_cell(fdt, offset, "#size-cells", 0x0))); 89aeaef83dSCédric Le Goater 90aeaef83dSCédric Le Goater for (i = 0; !ipmi_bmc_sdr_find(bmc, i, &sdr, &nextrec); i++) { 91aeaef83dSCédric Le Goater int off; 92aeaef83dSCédric Le Goater char *name; 93aeaef83dSCédric Le Goater 94aeaef83dSCédric Le Goater if (sdr->header.rec_type != IPMI_SDR_COMPACT_TYPE && 95aeaef83dSCédric Le Goater sdr->header.rec_type != IPMI_SDR_FULL_TYPE) { 96aeaef83dSCédric Le Goater continue; 97aeaef83dSCédric Le Goater } 98aeaef83dSCédric Le Goater 99aeaef83dSCédric Le Goater name = g_strdup_printf("sensor@%x", sdr->sensor_owner_number); 100aeaef83dSCédric Le Goater off = fdt_add_subnode(fdt, offset, name); 101aeaef83dSCédric Le Goater _FDT(off); 102aeaef83dSCédric Le Goater g_free(name); 103aeaef83dSCédric Le Goater 104aeaef83dSCédric Le Goater _FDT((fdt_setprop_cell(fdt, off, "reg", sdr->sensor_owner_number))); 105aeaef83dSCédric Le Goater _FDT((fdt_setprop_string(fdt, off, "name", "sensor"))); 106aeaef83dSCédric Le Goater _FDT((fdt_setprop_string(fdt, off, "compatible", "ibm,ipmi-sensor"))); 107aeaef83dSCédric Le Goater _FDT((fdt_setprop_cell(fdt, off, "ipmi-sensor-reading-type", 108aeaef83dSCédric Le Goater sdr->reading_type))); 109aeaef83dSCédric Le Goater _FDT((fdt_setprop_cell(fdt, off, "ipmi-entity-id", 110aeaef83dSCédric Le Goater sdr->entity_id))); 111aeaef83dSCédric Le Goater _FDT((fdt_setprop_cell(fdt, off, "ipmi-entity-instance", 112aeaef83dSCédric Le Goater sdr->entity_instance))); 113aeaef83dSCédric Le Goater _FDT((fdt_setprop_cell(fdt, off, "ipmi-sensor-type", 114aeaef83dSCédric Le Goater sdr->sensor_type))); 115aeaef83dSCédric Le Goater } 116aeaef83dSCédric Le Goater } 117