1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#ifndef HW_IPMI_H
26#define HW_IPMI_H
27
28#include "exec/memory.h"
29#include "hw/qdev-core.h"
30
31#define MAX_IPMI_MSG_SIZE 300
32
33enum ipmi_op {
34 IPMI_RESET_CHASSIS,
35 IPMI_POWEROFF_CHASSIS,
36 IPMI_POWERON_CHASSIS,
37 IPMI_POWERCYCLE_CHASSIS,
38 IPMI_PULSE_DIAG_IRQ,
39 IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP,
40 IPMI_SEND_NMI
41};
42
43#define IPMI_CC_INVALID_CMD 0xc1
44#define IPMI_CC_COMMAND_INVALID_FOR_LUN 0xc2
45#define IPMI_CC_TIMEOUT 0xc3
46#define IPMI_CC_OUT_OF_SPACE 0xc4
47#define IPMI_CC_INVALID_RESERVATION 0xc5
48#define IPMI_CC_REQUEST_DATA_TRUNCATED 0xc6
49#define IPMI_CC_REQUEST_DATA_LENGTH_INVALID 0xc7
50#define IPMI_CC_PARM_OUT_OF_RANGE 0xc9
51#define IPMI_CC_CANNOT_RETURN_REQ_NUM_BYTES 0xca
52#define IPMI_CC_REQ_ENTRY_NOT_PRESENT 0xcb
53#define IPMI_CC_INVALID_DATA_FIELD 0xcc
54#define IPMI_CC_BMC_INIT_IN_PROGRESS 0xd2
55#define IPMI_CC_COMMAND_NOT_SUPPORTED 0xd5
56
57#define IPMI_NETFN_APP 0x06
58
59#define IPMI_DEBUG 1
60
61
62#define IPMI_SMBIOS_KCS 0x01
63#define IPMI_SMBIOS_SMIC 0x02
64#define IPMI_SMBIOS_BT 0x03
65#define IPMI_SMBIOS_SSIF 0x04
66
67
68
69
70
71typedef struct IPMIFwInfo {
72 const char *interface_name;
73 int interface_type;
74 uint8_t ipmi_spec_major_revision;
75 uint8_t ipmi_spec_minor_revision;
76 uint8_t i2c_slave_address;
77 uint32_t uuid;
78
79 uint64_t base_address;
80 uint64_t register_length;
81 uint8_t register_spacing;
82 enum {
83 IPMI_MEMSPACE_IO,
84 IPMI_MEMSPACE_MEM32,
85 IPMI_MEMSPACE_MEM64,
86 IPMI_MEMSPACE_SMBUS
87 } memspace;
88
89 int interrupt_number;
90 enum {
91 IPMI_LEVEL_IRQ,
92 IPMI_EDGE_IRQ
93 } irq_type;
94} IPMIFwInfo;
95
96
97
98
99uint32_t ipmi_next_uuid(void);
100
101
102#define TYPE_IPMI_INTERFACE_PREFIX "ipmi-interface-"
103
104
105
106
107
108#define TYPE_IPMI_INTERFACE "ipmi-interface"
109#define IPMI_INTERFACE(obj) \
110 INTERFACE_CHECK(IPMIInterface, (obj), TYPE_IPMI_INTERFACE)
111#define IPMI_INTERFACE_CLASS(class) \
112 OBJECT_CLASS_CHECK(IPMIInterfaceClass, (class), TYPE_IPMI_INTERFACE)
113#define IPMI_INTERFACE_GET_CLASS(class) \
114 OBJECT_GET_CLASS(IPMIInterfaceClass, (class), TYPE_IPMI_INTERFACE)
115
116typedef struct IPMIInterface IPMIInterface;
117
118typedef struct IPMIInterfaceClass {
119 InterfaceClass parent;
120
121
122
123
124
125
126 void (*init)(struct IPMIInterface *s, unsigned int min_size, Error **errp);
127
128
129
130
131
132
133 int (*do_hw_op)(struct IPMIInterface *s, enum ipmi_op op, int checkonly);
134
135
136
137
138 void (*set_irq_enable)(struct IPMIInterface *s, int val);
139
140
141
142
143
144 void (*handle_if_event)(struct IPMIInterface *s);
145
146
147
148
149 void (*set_atn)(struct IPMIInterface *s, int val, int irq);
150
151
152
153
154 void (*reset)(struct IPMIInterface *s, bool is_cold);
155
156
157
158
159 void (*handle_rsp)(struct IPMIInterface *s, uint8_t msg_id,
160 unsigned char *rsp, unsigned int rsp_len);
161
162
163
164
165 void *(*get_backend_data)(struct IPMIInterface *s);
166
167
168
169
170 void (*get_fwinfo)(struct IPMIInterface *s, IPMIFwInfo *info);
171} IPMIInterfaceClass;
172
173
174
175
176#define TYPE_IPMI_BMC "ipmi-bmc"
177#define IPMI_BMC(obj) \
178 OBJECT_CHECK(IPMIBmc, (obj), TYPE_IPMI_BMC)
179#define IPMI_BMC_CLASS(obj_class) \
180 OBJECT_CLASS_CHECK(IPMIBmcClass, (obj_class), TYPE_IPMI_BMC)
181#define IPMI_BMC_GET_CLASS(obj) \
182 OBJECT_GET_CLASS(IPMIBmcClass, (obj), TYPE_IPMI_BMC)
183
184typedef struct IPMIBmc {
185 DeviceState parent;
186
187 uint8_t slave_addr;
188
189 IPMIInterface *intf;
190} IPMIBmc;
191
192typedef struct IPMIBmcClass {
193 DeviceClass parent;
194
195
196 void (*handle_reset)(struct IPMIBmc *s);
197
198
199
200
201 void (*handle_command)(struct IPMIBmc *s,
202 uint8_t *cmd, unsigned int cmd_len,
203 unsigned int max_cmd_len,
204 uint8_t msg_id);
205} IPMIBmcClass;
206
207
208
209
210void ipmi_bmc_find_and_link(Object *obj, Object **bmc);
211
212#ifdef IPMI_DEBUG
213#define ipmi_debug(fs, ...) \
214 fprintf(stderr, "IPMI (%s): " fs, __func__, ##__VA_ARGS__)
215#else
216#define ipmi_debug(fs, ...)
217#endif
218
219struct ipmi_sdr_header {
220 uint8_t rec_id[2];
221 uint8_t sdr_version;
222 uint8_t rec_type;
223 uint8_t rec_length;
224};
225#define IPMI_SDR_HEADER_SIZE sizeof(struct ipmi_sdr_header)
226
227#define ipmi_sdr_recid(sdr) ((sdr)->rec_id[0] | ((sdr)->rec_id[1] << 8))
228#define ipmi_sdr_length(sdr) ((sdr)->rec_length + IPMI_SDR_HEADER_SIZE)
229
230
231
232
233#define IPMI_SDR_COMPACT_TYPE 2
234
235struct ipmi_sdr_compact {
236 struct ipmi_sdr_header header;
237
238 uint8_t sensor_owner_id;
239 uint8_t sensor_owner_lun;
240 uint8_t sensor_owner_number;
241 uint8_t entity_id;
242 uint8_t entity_instance;
243 uint8_t sensor_init;
244 uint8_t sensor_caps;
245 uint8_t sensor_type;
246 uint8_t reading_type;
247 uint8_t assert_mask[2];
248 uint8_t deassert_mask[2];
249 uint8_t discrete_mask[2];
250 uint8_t sensor_unit1;
251 uint8_t sensor_unit2;
252 uint8_t sensor_unit3;
253 uint8_t sensor_direction[2];
254 uint8_t positive_threshold;
255 uint8_t negative_threshold;
256 uint8_t reserved[3];
257 uint8_t oem;
258 uint8_t id_str_len;
259 uint8_t id_string[16];
260};
261
262typedef uint8_t ipmi_sdr_compact_buffer[sizeof(struct ipmi_sdr_compact)];
263
264int ipmi_bmc_sdr_find(IPMIBmc *b, uint16_t recid,
265 const struct ipmi_sdr_compact **sdr, uint16_t *nextrec);
266void ipmi_bmc_gen_event(IPMIBmc *b, uint8_t *evt, bool log);
267
268#endif
269