123076bb3SCorey Minyard /*
223076bb3SCorey Minyard * QEMU IPMI emulation
323076bb3SCorey Minyard *
423076bb3SCorey Minyard * Copyright (c) 2015 Corey Minyard, MontaVista Software, LLC
523076bb3SCorey Minyard *
623076bb3SCorey Minyard * Permission is hereby granted, free of charge, to any person obtaining a copy
723076bb3SCorey Minyard * of this software and associated documentation files (the "Software"), to deal
823076bb3SCorey Minyard * in the Software without restriction, including without limitation the rights
923076bb3SCorey Minyard * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1023076bb3SCorey Minyard * copies of the Software, and to permit persons to whom the Software is
1123076bb3SCorey Minyard * furnished to do so, subject to the following conditions:
1223076bb3SCorey Minyard *
1323076bb3SCorey Minyard * The above copyright notice and this permission notice shall be included in
1423076bb3SCorey Minyard * all copies or substantial portions of the Software.
1523076bb3SCorey Minyard *
1623076bb3SCorey Minyard * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1723076bb3SCorey Minyard * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1823076bb3SCorey Minyard * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1923076bb3SCorey Minyard * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2023076bb3SCorey Minyard * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2123076bb3SCorey Minyard * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2223076bb3SCorey Minyard * THE SOFTWARE.
2323076bb3SCorey Minyard */
2423076bb3SCorey Minyard
250430891cSPeter Maydell #include "qemu/osdep.h"
2623076bb3SCorey Minyard #include "hw/ipmi/ipmi.h"
27a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
2823076bb3SCorey Minyard #include "qom/object_interfaces.h"
2954d31236SMarkus Armbruster #include "sysemu/runstate.h"
30e688df6bSMarkus Armbruster #include "qapi/error.h"
310b8fa32fSMarkus Armbruster #include "qemu/module.h"
326af94767SCorey Minyard #include "hw/nmi.h"
3323076bb3SCorey Minyard
3415139b8eSCorey Minyard static uint32_t ipmi_current_uuid = 1;
3515139b8eSCorey Minyard
ipmi_next_uuid(void)3615139b8eSCorey Minyard uint32_t ipmi_next_uuid(void)
3715139b8eSCorey Minyard {
3815139b8eSCorey Minyard return ipmi_current_uuid++;
3915139b8eSCorey Minyard }
4015139b8eSCorey Minyard
ipmi_do_hw_op(IPMIInterface * s,enum ipmi_op op,int checkonly)4123076bb3SCorey Minyard static int ipmi_do_hw_op(IPMIInterface *s, enum ipmi_op op, int checkonly)
4223076bb3SCorey Minyard {
4323076bb3SCorey Minyard switch (op) {
4423076bb3SCorey Minyard case IPMI_RESET_CHASSIS:
4523076bb3SCorey Minyard if (checkonly) {
4623076bb3SCorey Minyard return 0;
4723076bb3SCorey Minyard }
48cf83f140SEric Blake qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
4923076bb3SCorey Minyard return 0;
5023076bb3SCorey Minyard
5123076bb3SCorey Minyard case IPMI_POWEROFF_CHASSIS:
5223076bb3SCorey Minyard if (checkonly) {
5323076bb3SCorey Minyard return 0;
5423076bb3SCorey Minyard }
55cf83f140SEric Blake qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
5623076bb3SCorey Minyard return 0;
5723076bb3SCorey Minyard
5823076bb3SCorey Minyard case IPMI_SEND_NMI:
5923076bb3SCorey Minyard if (checkonly) {
6023076bb3SCorey Minyard return 0;
6123076bb3SCorey Minyard }
626af94767SCorey Minyard /* We don't care what CPU we use. */
636af94767SCorey Minyard nmi_monitor_handle(0, NULL);
6423076bb3SCorey Minyard return 0;
6523076bb3SCorey Minyard
669c22c1c3SCorey Minyard case IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP:
679c22c1c3SCorey Minyard if (checkonly) {
689c22c1c3SCorey Minyard return 0;
699c22c1c3SCorey Minyard }
709c22c1c3SCorey Minyard qemu_system_powerdown_request();
719c22c1c3SCorey Minyard return 0;
729c22c1c3SCorey Minyard
7323076bb3SCorey Minyard case IPMI_POWERCYCLE_CHASSIS:
7423076bb3SCorey Minyard case IPMI_PULSE_DIAG_IRQ:
7523076bb3SCorey Minyard case IPMI_POWERON_CHASSIS:
7623076bb3SCorey Minyard default:
7723076bb3SCorey Minyard return IPMI_CC_COMMAND_NOT_SUPPORTED;
7823076bb3SCorey Minyard }
7923076bb3SCorey Minyard }
8023076bb3SCorey Minyard
ipmi_interface_class_init(ObjectClass * class,void * data)8123076bb3SCorey Minyard static void ipmi_interface_class_init(ObjectClass *class, void *data)
8223076bb3SCorey Minyard {
8323076bb3SCorey Minyard IPMIInterfaceClass *ik = IPMI_INTERFACE_CLASS(class);
8423076bb3SCorey Minyard
8523076bb3SCorey Minyard ik->do_hw_op = ipmi_do_hw_op;
8623076bb3SCorey Minyard }
8723076bb3SCorey Minyard
88*5e78c98bSBernhard Beschow static const TypeInfo ipmi_interface_type_info = {
8923076bb3SCorey Minyard .name = TYPE_IPMI_INTERFACE,
9023076bb3SCorey Minyard .parent = TYPE_INTERFACE,
9123076bb3SCorey Minyard .class_size = sizeof(IPMIInterfaceClass),
9223076bb3SCorey Minyard .class_init = ipmi_interface_class_init,
9323076bb3SCorey Minyard };
9423076bb3SCorey Minyard
isa_ipmi_bmc_check(const Object * obj,const char * name,Object * val,Error ** errp)958f5d58efSIgor Mammedov static void isa_ipmi_bmc_check(const Object *obj, const char *name,
9623076bb3SCorey Minyard Object *val, Error **errp)
9723076bb3SCorey Minyard {
9823076bb3SCorey Minyard IPMIBmc *bmc = IPMI_BMC(val);
9923076bb3SCorey Minyard
10023076bb3SCorey Minyard if (bmc->intf)
10123076bb3SCorey Minyard error_setg(errp, "BMC object is already in use");
10223076bb3SCorey Minyard }
10323076bb3SCorey Minyard
ipmi_bmc_find_and_link(Object * obj,Object ** bmc)10423076bb3SCorey Minyard void ipmi_bmc_find_and_link(Object *obj, Object **bmc)
10523076bb3SCorey Minyard {
10623076bb3SCorey Minyard object_property_add_link(obj, "bmc", TYPE_IPMI_BMC, bmc,
10723076bb3SCorey Minyard isa_ipmi_bmc_check,
108d2623129SMarkus Armbruster OBJ_PROP_LINK_STRONG);
10923076bb3SCorey Minyard }
11023076bb3SCorey Minyard
11123076bb3SCorey Minyard static Property ipmi_bmc_properties[] = {
11223076bb3SCorey Minyard DEFINE_PROP_UINT8("slave_addr", IPMIBmc, slave_addr, 0x20),
11323076bb3SCorey Minyard DEFINE_PROP_END_OF_LIST(),
11423076bb3SCorey Minyard };
11523076bb3SCorey Minyard
bmc_class_init(ObjectClass * oc,void * data)11623076bb3SCorey Minyard static void bmc_class_init(ObjectClass *oc, void *data)
11723076bb3SCorey Minyard {
11823076bb3SCorey Minyard DeviceClass *dc = DEVICE_CLASS(oc);
11923076bb3SCorey Minyard
1204f67d30bSMarc-André Lureau device_class_set_props(dc, ipmi_bmc_properties);
12123076bb3SCorey Minyard }
12223076bb3SCorey Minyard
123*5e78c98bSBernhard Beschow static const TypeInfo ipmi_bmc_type_info = {
12423076bb3SCorey Minyard .name = TYPE_IPMI_BMC,
12523076bb3SCorey Minyard .parent = TYPE_DEVICE,
12623076bb3SCorey Minyard .instance_size = sizeof(IPMIBmc),
12723076bb3SCorey Minyard .abstract = true,
12823076bb3SCorey Minyard .class_size = sizeof(IPMIBmcClass),
12923076bb3SCorey Minyard .class_init = bmc_class_init,
13023076bb3SCorey Minyard };
13123076bb3SCorey Minyard
ipmi_register_types(void)13223076bb3SCorey Minyard static void ipmi_register_types(void)
13323076bb3SCorey Minyard {
13423076bb3SCorey Minyard type_register_static(&ipmi_interface_type_info);
13523076bb3SCorey Minyard type_register_static(&ipmi_bmc_type_info);
13623076bb3SCorey Minyard }
13723076bb3SCorey Minyard
13823076bb3SCorey Minyard type_init(ipmi_register_types)
139