2 * QEMU PowerNV, BMC related functions
4 * Copyright (c) 2016-2017, IBM Corporation.
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.
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.
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/>.
19 #include "qemu/osdep.h"
20 #include "target/ppc/cpu.h"
22 #include "hw/ipmi/ipmi.h"
23 #include "hw/ppc/fdt.h"
25 #include "hw/ppc/pnv.h"
29 /* TODO: include definition in ipmi.h */
30 #define IPMI_SDR_FULL_TYPE 1
33 * OEM SEL Event data packet sent by BMC in response of a Read Event
34 * Message Buffer command
36 typedef struct OemSel
{
43 /* OEM SEL data (6 bytes) follows */
50 #define SOFT_REBOOT 0x01
52 static void pnv_gen_oem_sel(IPMIBmc
*bmc
, uint8_t reboot
)
54 /* IPMI SEL Event are 16 bytes long */
56 .id
= { 0x55 , 0x55 },
57 .type
= 0xC0, /* OEM */
58 .manuf_id
= { 0x0, 0x0, 0x0 },
59 .timestamp
= { 0x0, 0x0, 0x0, 0x0 },
60 .netfun
= 0x3A, /* IBM */
61 .cmd
= 0x04, /* AMI OEM SEL Power Notification */
62 .data
= { reboot
, 0xFF, 0xFF, 0xFF },
65 ipmi_bmc_gen_event(bmc
, (uint8_t *) &sel
, 0 /* do not log the event */);
68 void pnv_bmc_powerdown(IPMIBmc
*bmc
)
70 pnv_gen_oem_sel(bmc
, SOFT_OFF
);
73 void pnv_dt_bmc_sensors(IPMIBmc
*bmc
, void *fdt
)
77 const struct ipmi_sdr_compact
*sdr
;
80 offset
= fdt_add_subnode(fdt
, 0, "bmc");
83 _FDT((fdt_setprop_string(fdt
, offset
, "name", "bmc")));
84 offset
= fdt_add_subnode(fdt
, offset
, "sensors");
87 _FDT((fdt_setprop_cell(fdt
, offset
, "#address-cells", 0x1)));
88 _FDT((fdt_setprop_cell(fdt
, offset
, "#size-cells", 0x0)));
90 for (i
= 0; !ipmi_bmc_sdr_find(bmc
, i
, &sdr
, &nextrec
); i
++) {
94 if (sdr
->header
.rec_type
!= IPMI_SDR_COMPACT_TYPE
&&
95 sdr
->header
.rec_type
!= IPMI_SDR_FULL_TYPE
) {
99 name
= g_strdup_printf("sensor@%x", sdr
->sensor_owner_number
);
100 off
= fdt_add_subnode(fdt
, offset
, name
);
104 _FDT((fdt_setprop_cell(fdt
, off
, "reg", sdr
->sensor_owner_number
)));
105 _FDT((fdt_setprop_string(fdt
, off
, "name", "sensor")));
106 _FDT((fdt_setprop_string(fdt
, off
, "compatible", "ibm,ipmi-sensor")));
107 _FDT((fdt_setprop_cell(fdt
, off
, "ipmi-sensor-reading-type",
108 sdr
->reading_type
)));
109 _FDT((fdt_setprop_cell(fdt
, off
, "ipmi-entity-id",
111 _FDT((fdt_setprop_cell(fdt
, off
, "ipmi-entity-instance",
112 sdr
->entity_instance
)));
113 _FDT((fdt_setprop_cell(fdt
, off
, "ipmi-sensor-type",
119 * HIOMAP protocol handler
121 #define HIOMAP_C_RESET 1
122 #define HIOMAP_C_GET_INFO 2
123 #define HIOMAP_C_GET_FLASH_INFO 3
124 #define HIOMAP_C_CREATE_READ_WINDOW 4
125 #define HIOMAP_C_CLOSE_WINDOW 5
126 #define HIOMAP_C_CREATE_WRITE_WINDOW 6
127 #define HIOMAP_C_MARK_DIRTY 7
128 #define HIOMAP_C_FLUSH 8
129 #define HIOMAP_C_ACK 9
130 #define HIOMAP_C_ERASE 10
131 #define HIOMAP_C_DEVICE_NAME 11
132 #define HIOMAP_C_LOCK 12
134 #define BLOCK_SHIFT 12 /* 4K */
136 static uint16_t bytes_to_blocks(uint32_t bytes
)
138 return bytes
>> BLOCK_SHIFT
;
141 static void hiomap_cmd(IPMIBmcSim
*ibs
, uint8_t *cmd
, unsigned int cmd_len
,
144 PnvMachineState
*pnv
= PNV_MACHINE(qdev_get_machine());
145 PnvPnor
*pnor
= pnv
->pnor
;
146 uint32_t pnor_size
= pnor
->size
;
147 uint32_t pnor_addr
= PNOR_SPI_OFFSET
;
148 bool readonly
= false;
150 rsp_buffer_push(rsp
, cmd
[2]);
151 rsp_buffer_push(rsp
, cmd
[3]);
154 case HIOMAP_C_MARK_DIRTY
:
160 case HIOMAP_C_GET_INFO
:
161 rsp_buffer_push(rsp
, 2); /* Version 2 */
162 rsp_buffer_push(rsp
, BLOCK_SHIFT
); /* block size */
163 rsp_buffer_push(rsp
, 0); /* Timeout */
164 rsp_buffer_push(rsp
, 0); /* Timeout */
167 case HIOMAP_C_GET_FLASH_INFO
:
168 rsp_buffer_push(rsp
, bytes_to_blocks(pnor_size
) & 0xFF);
169 rsp_buffer_push(rsp
, bytes_to_blocks(pnor_size
) >> 8);
170 rsp_buffer_push(rsp
, 0x01); /* erase size */
171 rsp_buffer_push(rsp
, 0x00); /* erase size */
174 case HIOMAP_C_CREATE_READ_WINDOW
:
178 case HIOMAP_C_CREATE_WRITE_WINDOW
:
179 memory_region_set_readonly(&pnor
->mmio
, readonly
);
180 memory_region_set_enabled(&pnor
->mmio
, true);
182 rsp_buffer_push(rsp
, bytes_to_blocks(pnor_addr
) & 0xFF);
183 rsp_buffer_push(rsp
, bytes_to_blocks(pnor_addr
) >> 8);
184 rsp_buffer_push(rsp
, bytes_to_blocks(pnor_size
) & 0xFF);
185 rsp_buffer_push(rsp
, bytes_to_blocks(pnor_size
) >> 8);
186 rsp_buffer_push(rsp
, 0x00); /* offset */
187 rsp_buffer_push(rsp
, 0x00); /* offset */
190 case HIOMAP_C_CLOSE_WINDOW
:
191 memory_region_set_enabled(&pnor
->mmio
, false);
194 case HIOMAP_C_DEVICE_NAME
:
198 qemu_log_mask(LOG_GUEST_ERROR
, "HIOMAP: unknow command %02X\n", cmd
[2]);
205 static const IPMICmdHandler hiomap_cmds
[] = {
206 [HIOMAP
] = { hiomap_cmd
, 3 },
209 static const IPMINetfn hiomap_netfn
= {
210 .cmd_nums
= ARRAY_SIZE(hiomap_cmds
),
211 .cmd_handlers
= hiomap_cmds
214 int pnv_bmc_hiomap(IPMIBmc
*bmc
)
216 return ipmi_sim_register_netfn(IPMI_BMC_SIMULATOR(bmc
),
217 IPMI_NETFN_OEM
, &hiomap_netfn
);