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/ipmi/ipmi.h"
27#include "hw/qdev-properties.h"
28#include "qom/object_interfaces.h"
29#include "sysemu/runstate.h"
30#include "qapi/error.h"
31#include "qemu/module.h"
32#include "hw/nmi.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
63 nmi_monitor_handle(0, NULL);
64 return 0;
65
66 case IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP:
67 if (checkonly) {
68 return 0;
69 }
70 qemu_system_powerdown_request();
71 return 0;
72
73 case IPMI_POWERCYCLE_CHASSIS:
74 case IPMI_PULSE_DIAG_IRQ:
75 case IPMI_POWERON_CHASSIS:
76 default:
77 return IPMI_CC_COMMAND_NOT_SUPPORTED;
78 }
79}
80
81static void ipmi_interface_class_init(ObjectClass *class, void *data)
82{
83 IPMIInterfaceClass *ik = IPMI_INTERFACE_CLASS(class);
84
85 ik->do_hw_op = ipmi_do_hw_op;
86}
87
88static TypeInfo ipmi_interface_type_info = {
89 .name = TYPE_IPMI_INTERFACE,
90 .parent = TYPE_INTERFACE,
91 .class_size = sizeof(IPMIInterfaceClass),
92 .class_init = ipmi_interface_class_init,
93};
94
95static void isa_ipmi_bmc_check(const Object *obj, const char *name,
96 Object *val, Error **errp)
97{
98 IPMIBmc *bmc = IPMI_BMC(val);
99
100 if (bmc->intf)
101 error_setg(errp, "BMC object is already in use");
102}
103
104void ipmi_bmc_find_and_link(Object *obj, Object **bmc)
105{
106 object_property_add_link(obj, "bmc", TYPE_IPMI_BMC, bmc,
107 isa_ipmi_bmc_check,
108 OBJ_PROP_LINK_STRONG,
109 &error_abort);
110}
111
112static Property ipmi_bmc_properties[] = {
113 DEFINE_PROP_UINT8("slave_addr", IPMIBmc, slave_addr, 0x20),
114 DEFINE_PROP_END_OF_LIST(),
115};
116
117static void bmc_class_init(ObjectClass *oc, void *data)
118{
119 DeviceClass *dc = DEVICE_CLASS(oc);
120
121 dc->props = ipmi_bmc_properties;
122}
123
124static TypeInfo ipmi_bmc_type_info = {
125 .name = TYPE_IPMI_BMC,
126 .parent = TYPE_DEVICE,
127 .instance_size = sizeof(IPMIBmc),
128 .abstract = true,
129 .class_size = sizeof(IPMIBmcClass),
130 .class_init = bmc_class_init,
131};
132
133static void ipmi_register_types(void)
134{
135 type_register_static(&ipmi_interface_type_info);
136 type_register_static(&ipmi_bmc_type_info);
137}
138
139type_init(ipmi_register_types)
140