4 * Copyright (c) 2015 Corey Minyard, MontaVista Software, LLC
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 #include "exec/memory.h"
29 #include "qemu-common.h"
32 #define MAX_IPMI_MSG_SIZE 300
36 IPMI_POWEROFF_CHASSIS
,
38 IPMI_POWERCYCLE_CHASSIS
,
40 IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP
,
44 #define IPMI_CC_INVALID_CMD 0xc1
45 #define IPMI_CC_COMMAND_INVALID_FOR_LUN 0xc2
46 #define IPMI_CC_TIMEOUT 0xc3
47 #define IPMI_CC_OUT_OF_SPACE 0xc4
48 #define IPMI_CC_INVALID_RESERVATION 0xc5
49 #define IPMI_CC_REQUEST_DATA_TRUNCATED 0xc6
50 #define IPMI_CC_REQUEST_DATA_LENGTH_INVALID 0xc7
51 #define IPMI_CC_PARM_OUT_OF_RANGE 0xc9
52 #define IPMI_CC_CANNOT_RETURN_REQ_NUM_BYTES 0xca
53 #define IPMI_CC_REQ_ENTRY_NOT_PRESENT 0xcb
54 #define IPMI_CC_INVALID_DATA_FIELD 0xcc
55 #define IPMI_CC_BMC_INIT_IN_PROGRESS 0xd2
56 #define IPMI_CC_COMMAND_NOT_SUPPORTED 0xd5
58 #define IPMI_NETFN_APP 0x06
62 /* Specified in the SMBIOS spec. */
63 #define IPMI_SMBIOS_KCS 0x01
64 #define IPMI_SMBIOS_SMIC 0x02
65 #define IPMI_SMBIOS_BT 0x03
66 #define IPMI_SMBIOS_SSIF 0x04
68 /* IPMI Interface types (KCS, SMIC, BT) are prefixed with this */
69 #define TYPE_IPMI_INTERFACE_PREFIX "ipmi-interface-"
72 * An IPMI Interface, the interface for talking between the target
75 #define TYPE_IPMI_INTERFACE "ipmi-interface"
76 #define IPMI_INTERFACE(obj) \
77 INTERFACE_CHECK(IPMIInterface, (obj), TYPE_IPMI_INTERFACE)
78 #define IPMI_INTERFACE_CLASS(class) \
79 OBJECT_CLASS_CHECK(IPMIInterfaceClass, (class), TYPE_IPMI_INTERFACE)
80 #define IPMI_INTERFACE_GET_CLASS(class) \
81 OBJECT_GET_CLASS(IPMIInterfaceClass, (class), TYPE_IPMI_INTERFACE)
83 typedef struct IPMIInterface
{
87 typedef struct IPMIInterfaceClass
{
88 InterfaceClass parent
;
90 void (*init
)(struct IPMIInterface
*s
, Error
**errp
);
93 * Perform various operations on the hardware. If checkonly is
94 * true, it will return if the operation can be performed, but it
95 * will not do the operation.
97 int (*do_hw_op
)(struct IPMIInterface
*s
, enum ipmi_op op
, int checkonly
);
100 * Enable/disable irqs on the interface when the BMC requests this.
102 void (*set_irq_enable
)(struct IPMIInterface
*s
, int val
);
105 * Handle an event that occurred on the interface, generally the.
106 * target writing to a register.
108 void (*handle_if_event
)(struct IPMIInterface
*s
);
111 * The interfaces use this to perform certain ops
113 void (*set_atn
)(struct IPMIInterface
*s
, int val
, int irq
);
116 * Got an IPMI warm/cold reset.
118 void (*reset
)(struct IPMIInterface
*s
, bool is_cold
);
121 * Handle a response from the bmc.
123 void (*handle_rsp
)(struct IPMIInterface
*s
, uint8_t msg_id
,
124 unsigned char *rsp
, unsigned int rsp_len
);
127 * Set by the owner to hold the backend data for the interface.
129 void *(*get_backend_data
)(struct IPMIInterface
*s
);
130 } IPMIInterfaceClass
;
133 * Define a BMC simulator (or perhaps a connection to a real BMC)
135 #define TYPE_IPMI_BMC "ipmi-bmc"
136 #define IPMI_BMC(obj) \
137 OBJECT_CHECK(IPMIBmc, (obj), TYPE_IPMI_BMC)
138 #define IPMI_BMC_CLASS(obj_class) \
139 OBJECT_CLASS_CHECK(IPMIBmcClass, (obj_class), TYPE_IPMI_BMC)
140 #define IPMI_BMC_GET_CLASS(obj) \
141 OBJECT_GET_CLASS(IPMIBmcClass, (obj), TYPE_IPMI_BMC)
143 typedef struct IPMIBmc
{
151 typedef struct IPMIBmcClass
{
154 /* Called when the system resets to report to the bmc. */
155 void (*handle_reset
)(struct IPMIBmc
*s
);
158 * Handle a command to the bmc.
160 void (*handle_command
)(struct IPMIBmc
*s
,
161 uint8_t *cmd
, unsigned int cmd_len
,
162 unsigned int max_cmd_len
,
167 * Add a link property to obj that points to a BMC.
169 void ipmi_bmc_find_and_link(Object
*obj
, Object
**bmc
);
172 * Used for transferring information to interfaces that add
173 * entries to firmware tables.
175 typedef struct IPMIFwInfo
{
176 const char *interface_name
;
178 uint8_t ipmi_spec_major_revision
;
179 uint8_t ipmi_spec_minor_revision
;
180 uint8_t i2c_slave_address
;
183 uint64_t base_address
;
184 uint64_t register_length
;
185 uint8_t register_spacing
;
193 int interrupt_number
;
199 const char *acpi_parent
;
202 void ipmi_add_fwinfo(IPMIFwInfo
*info
, Error
**errp
);
203 IPMIFwInfo
*ipmi_first_fwinfo(void);
204 IPMIFwInfo
*ipmi_next_fwinfo(IPMIFwInfo
*current
);
207 #define ipmi_debug(fs, ...) \
208 fprintf(stderr, "IPMI (%s): " fs, __func__, ##__VA_ARGS__)
210 #define ipmi_debug(fs, ...)