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