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#include "qemu/osdep.h"
26#include "hw/hw.h"
27#include "hw/ipmi/ipmi.h"
28#include "sysemu/sysemu.h"
29#include "qom/object_interfaces.h"
30#include "qapi/error.h"
31#include "qapi/qapi-commands-misc.h"
32#include "qapi/visitor.h"
33
34static uint32_t ipmi_current_uuid = 1;
35
36uint32_t ipmi_next_uuid(void)
37{
38 return ipmi_current_uuid++;
39}
40
41static int ipmi_do_hw_op(IPMIInterface *s, enum ipmi_op op, int checkonly)
42{
43 switch (op) {
44 case IPMI_RESET_CHASSIS:
45 if (checkonly) {
46 return 0;
47 }
48 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
49 return 0;
50
51 case IPMI_POWEROFF_CHASSIS:
52 if (checkonly) {
53 return 0;
54 }
55 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
56 return 0;
57
58 case IPMI_SEND_NMI:
59 if (checkonly) {
60 return 0;
61 }
62 qmp_inject_nmi(NULL);
63 return 0;
64
65 case IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP:
66 if (checkonly) {
67 return 0;
68 }
69 qemu_system_powerdown_request();
70 return 0;
71
72 case IPMI_POWERCYCLE_CHASSIS:
73 case IPMI_PULSE_DIAG_IRQ:
74 case IPMI_POWERON_CHASSIS:
75 default:
76 return IPMI_CC_COMMAND_NOT_SUPPORTED;
77 }
78}
79
80static void ipmi_interface_class_init(ObjectClass *class, void *data)
81{
82 IPMIInterfaceClass *ik = IPMI_INTERFACE_CLASS(class);
83
84 ik->do_hw_op = ipmi_do_hw_op;
85}
86
87static TypeInfo ipmi_interface_type_info = {
88 .name = TYPE_IPMI_INTERFACE,
89 .parent = TYPE_INTERFACE,
90 .class_size = sizeof(IPMIInterfaceClass),
91 .class_init = ipmi_interface_class_init,
92};
93
94static void isa_ipmi_bmc_check(const Object *obj, const char *name,
95 Object *val, Error **errp)
96{
97 IPMIBmc *bmc = IPMI_BMC(val);
98
99 if (bmc->intf)
100 error_setg(errp, "BMC object is already in use");
101}
102
103void ipmi_bmc_find_and_link(Object *obj, Object **bmc)
104{
105 object_property_add_link(obj, "bmc", TYPE_IPMI_BMC, bmc,
106 isa_ipmi_bmc_check,
107 OBJ_PROP_LINK_UNREF_ON_RELEASE,
108 &error_abort);
109}
110
111static Property ipmi_bmc_properties[] = {
112 DEFINE_PROP_UINT8("slave_addr", IPMIBmc, slave_addr, 0x20),
113 DEFINE_PROP_END_OF_LIST(),
114};
115
116static void bmc_class_init(ObjectClass *oc, void *data)
117{
118 DeviceClass *dc = DEVICE_CLASS(oc);
119
120 dc->props = ipmi_bmc_properties;
121}
122
123static TypeInfo ipmi_bmc_type_info = {
124 .name = TYPE_IPMI_BMC,
125 .parent = TYPE_DEVICE,
126 .instance_size = sizeof(IPMIBmc),
127 .abstract = true,
128 .class_size = sizeof(IPMIBmcClass),
129 .class_init = bmc_class_init,
130};
131
132static void ipmi_register_types(void)
133{
134 type_register_static(&ipmi_interface_type_info);
135 type_register_static(&ipmi_bmc_type_info);
136}
137
138type_init(ipmi_register_types)
139