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
25 #include "qemu/osdep.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"
34 static uint32_t ipmi_current_uuid
= 1;
36 uint32_t ipmi_next_uuid(void)
38 return ipmi_current_uuid
++;
41 static int ipmi_do_hw_op(IPMIInterface
*s
, enum ipmi_op op
, int checkonly
)
44 case IPMI_RESET_CHASSIS
:
48 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET
);
51 case IPMI_POWEROFF_CHASSIS
:
55 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN
);
65 case IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP
:
69 qemu_system_powerdown_request();
72 case IPMI_POWERCYCLE_CHASSIS
:
73 case IPMI_PULSE_DIAG_IRQ
:
74 case IPMI_POWERON_CHASSIS
:
76 return IPMI_CC_COMMAND_NOT_SUPPORTED
;
80 static void ipmi_interface_class_init(ObjectClass
*class, void *data
)
82 IPMIInterfaceClass
*ik
= IPMI_INTERFACE_CLASS(class);
84 ik
->do_hw_op
= ipmi_do_hw_op
;
87 static 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
,
94 static void isa_ipmi_bmc_check(const Object
*obj
, const char *name
,
95 Object
*val
, Error
**errp
)
97 IPMIBmc
*bmc
= IPMI_BMC(val
);
100 error_setg(errp
, "BMC object is already in use");
103 void ipmi_bmc_find_and_link(Object
*obj
, Object
**bmc
)
105 object_property_add_link(obj
, "bmc", TYPE_IPMI_BMC
, bmc
,
107 OBJ_PROP_LINK_STRONG
,
111 static Property ipmi_bmc_properties
[] = {
112 DEFINE_PROP_UINT8("slave_addr", IPMIBmc
, slave_addr
, 0x20),
113 DEFINE_PROP_END_OF_LIST(),
116 static void bmc_class_init(ObjectClass
*oc
, void *data
)
118 DeviceClass
*dc
= DEVICE_CLASS(oc
);
120 dc
->props
= ipmi_bmc_properties
;
123 static TypeInfo ipmi_bmc_type_info
= {
124 .name
= TYPE_IPMI_BMC
,
125 .parent
= TYPE_DEVICE
,
126 .instance_size
= sizeof(IPMIBmc
),
128 .class_size
= sizeof(IPMIBmcClass
),
129 .class_init
= bmc_class_init
,
132 static void ipmi_register_types(void)
134 type_register_static(&ipmi_interface_type_info
);
135 type_register_static(&ipmi_bmc_type_info
);
138 type_init(ipmi_register_types
)