]>
Commit | Line | Data |
---|---|---|
23076bb3 CM |
1 | /* |
2 | * QEMU IPMI emulation | |
3 | * | |
4 | * Copyright (c) 2015 Corey Minyard, MontaVista Software, LLC | |
5 | * | |
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: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
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 | |
22 | * THE SOFTWARE. | |
23 | */ | |
24 | ||
0430891c | 25 | #include "qemu/osdep.h" |
23076bb3 CM |
26 | #include "hw/hw.h" |
27 | #include "hw/ipmi/ipmi.h" | |
28 | #include "sysemu/sysemu.h" | |
29 | #include "qmp-commands.h" | |
30 | #include "qom/object_interfaces.h" | |
31 | #include "qapi/visitor.h" | |
32 | ||
33 | static int ipmi_do_hw_op(IPMIInterface *s, enum ipmi_op op, int checkonly) | |
34 | { | |
35 | switch (op) { | |
36 | case IPMI_RESET_CHASSIS: | |
37 | if (checkonly) { | |
38 | return 0; | |
39 | } | |
40 | qemu_system_reset_request(); | |
41 | return 0; | |
42 | ||
43 | case IPMI_POWEROFF_CHASSIS: | |
44 | if (checkonly) { | |
45 | return 0; | |
46 | } | |
47 | qemu_system_powerdown_request(); | |
48 | return 0; | |
49 | ||
50 | case IPMI_SEND_NMI: | |
51 | if (checkonly) { | |
52 | return 0; | |
53 | } | |
23076bb3 | 54 | qmp_inject_nmi(NULL); |
23076bb3 CM |
55 | return 0; |
56 | ||
57 | case IPMI_POWERCYCLE_CHASSIS: | |
58 | case IPMI_PULSE_DIAG_IRQ: | |
59 | case IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP: | |
60 | case IPMI_POWERON_CHASSIS: | |
61 | default: | |
62 | return IPMI_CC_COMMAND_NOT_SUPPORTED; | |
63 | } | |
64 | } | |
65 | ||
66 | static void ipmi_interface_class_init(ObjectClass *class, void *data) | |
67 | { | |
68 | IPMIInterfaceClass *ik = IPMI_INTERFACE_CLASS(class); | |
69 | ||
70 | ik->do_hw_op = ipmi_do_hw_op; | |
71 | } | |
72 | ||
73 | static TypeInfo ipmi_interface_type_info = { | |
74 | .name = TYPE_IPMI_INTERFACE, | |
75 | .parent = TYPE_INTERFACE, | |
76 | .class_size = sizeof(IPMIInterfaceClass), | |
77 | .class_init = ipmi_interface_class_init, | |
78 | }; | |
79 | ||
80 | static void isa_ipmi_bmc_check(Object *obj, const char *name, | |
81 | Object *val, Error **errp) | |
82 | { | |
83 | IPMIBmc *bmc = IPMI_BMC(val); | |
84 | ||
85 | if (bmc->intf) | |
86 | error_setg(errp, "BMC object is already in use"); | |
87 | } | |
88 | ||
89 | void ipmi_bmc_find_and_link(Object *obj, Object **bmc) | |
90 | { | |
91 | object_property_add_link(obj, "bmc", TYPE_IPMI_BMC, bmc, | |
92 | isa_ipmi_bmc_check, | |
93 | OBJ_PROP_LINK_UNREF_ON_RELEASE, | |
94 | &error_abort); | |
95 | } | |
96 | ||
97 | static Property ipmi_bmc_properties[] = { | |
98 | DEFINE_PROP_UINT8("slave_addr", IPMIBmc, slave_addr, 0x20), | |
99 | DEFINE_PROP_END_OF_LIST(), | |
100 | }; | |
101 | ||
102 | static void bmc_class_init(ObjectClass *oc, void *data) | |
103 | { | |
104 | DeviceClass *dc = DEVICE_CLASS(oc); | |
105 | ||
106 | dc->props = ipmi_bmc_properties; | |
107 | } | |
108 | ||
109 | static TypeInfo ipmi_bmc_type_info = { | |
110 | .name = TYPE_IPMI_BMC, | |
111 | .parent = TYPE_DEVICE, | |
112 | .instance_size = sizeof(IPMIBmc), | |
113 | .abstract = true, | |
114 | .class_size = sizeof(IPMIBmcClass), | |
115 | .class_init = bmc_class_init, | |
116 | }; | |
117 | ||
118 | static void ipmi_register_types(void) | |
119 | { | |
120 | type_register_static(&ipmi_interface_type_info); | |
121 | type_register_static(&ipmi_bmc_type_info); | |
122 | } | |
123 | ||
124 | type_init(ipmi_register_types) | |
90b61805 CM |
125 | |
126 | static IPMIFwInfo *ipmi_fw_info; | |
127 | static unsigned int ipmi_fw_info_len; | |
128 | ||
129 | static uint32_t current_uuid = 1; | |
130 | ||
131 | void ipmi_add_fwinfo(IPMIFwInfo *info, Error **errp) | |
132 | { | |
133 | info->uuid = current_uuid++; | |
134 | ipmi_fw_info = g_realloc(ipmi_fw_info, | |
135 | sizeof(*ipmi_fw_info) * (ipmi_fw_info_len + 1)); | |
136 | ipmi_fw_info[ipmi_fw_info_len] = *info; | |
137 | } | |
138 | ||
139 | IPMIFwInfo *ipmi_first_fwinfo(void) | |
140 | { | |
141 | return ipmi_fw_info; | |
142 | } | |
143 | ||
144 | IPMIFwInfo *ipmi_next_fwinfo(IPMIFwInfo *current) | |
145 | { | |
146 | current++; | |
147 | if (current >= &ipmi_fw_info[ipmi_fw_info_len]) { | |
148 | return NULL; | |
149 | } | |
150 | return current; | |
151 | } |