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/hw.h" 2723076bb3SCorey Minyard #include "hw/ipmi/ipmi.h" 2823076bb3SCorey Minyard #include "sysemu/sysemu.h" 2923076bb3SCorey Minyard #include "qmp-commands.h" 3023076bb3SCorey Minyard #include "qom/object_interfaces.h" 3123076bb3SCorey Minyard #include "qapi/visitor.h" 3223076bb3SCorey Minyard 3315139b8eSCorey Minyard static uint32_t ipmi_current_uuid = 1; 3415139b8eSCorey Minyard 3515139b8eSCorey Minyard uint32_t ipmi_next_uuid(void) 3615139b8eSCorey Minyard { 3715139b8eSCorey Minyard return ipmi_current_uuid++; 3815139b8eSCorey Minyard } 3915139b8eSCorey Minyard 4023076bb3SCorey Minyard static int ipmi_do_hw_op(IPMIInterface *s, enum ipmi_op op, int checkonly) 4123076bb3SCorey Minyard { 4223076bb3SCorey Minyard switch (op) { 4323076bb3SCorey Minyard case IPMI_RESET_CHASSIS: 4423076bb3SCorey Minyard if (checkonly) { 4523076bb3SCorey Minyard return 0; 4623076bb3SCorey Minyard } 4723076bb3SCorey Minyard qemu_system_reset_request(); 4823076bb3SCorey Minyard return 0; 4923076bb3SCorey Minyard 5023076bb3SCorey Minyard case IPMI_POWEROFF_CHASSIS: 5123076bb3SCorey Minyard if (checkonly) { 5223076bb3SCorey Minyard return 0; 5323076bb3SCorey Minyard } 542b7812d3SCédric Le Goater qemu_system_shutdown_request(); 5523076bb3SCorey Minyard return 0; 5623076bb3SCorey Minyard 5723076bb3SCorey Minyard case IPMI_SEND_NMI: 5823076bb3SCorey Minyard if (checkonly) { 5923076bb3SCorey Minyard return 0; 6023076bb3SCorey Minyard } 6123076bb3SCorey Minyard qmp_inject_nmi(NULL); 6223076bb3SCorey Minyard return 0; 6323076bb3SCorey Minyard 64*9c22c1c3SCorey Minyard case IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP: 65*9c22c1c3SCorey Minyard if (checkonly) { 66*9c22c1c3SCorey Minyard return 0; 67*9c22c1c3SCorey Minyard } 68*9c22c1c3SCorey Minyard qemu_system_powerdown_request(); 69*9c22c1c3SCorey Minyard return 0; 70*9c22c1c3SCorey Minyard 7123076bb3SCorey Minyard case IPMI_POWERCYCLE_CHASSIS: 7223076bb3SCorey Minyard case IPMI_PULSE_DIAG_IRQ: 7323076bb3SCorey Minyard case IPMI_POWERON_CHASSIS: 7423076bb3SCorey Minyard default: 7523076bb3SCorey Minyard return IPMI_CC_COMMAND_NOT_SUPPORTED; 7623076bb3SCorey Minyard } 7723076bb3SCorey Minyard } 7823076bb3SCorey Minyard 7923076bb3SCorey Minyard static void ipmi_interface_class_init(ObjectClass *class, void *data) 8023076bb3SCorey Minyard { 8123076bb3SCorey Minyard IPMIInterfaceClass *ik = IPMI_INTERFACE_CLASS(class); 8223076bb3SCorey Minyard 8323076bb3SCorey Minyard ik->do_hw_op = ipmi_do_hw_op; 8423076bb3SCorey Minyard } 8523076bb3SCorey Minyard 8623076bb3SCorey Minyard static TypeInfo ipmi_interface_type_info = { 8723076bb3SCorey Minyard .name = TYPE_IPMI_INTERFACE, 8823076bb3SCorey Minyard .parent = TYPE_INTERFACE, 8923076bb3SCorey Minyard .class_size = sizeof(IPMIInterfaceClass), 9023076bb3SCorey Minyard .class_init = ipmi_interface_class_init, 9123076bb3SCorey Minyard }; 9223076bb3SCorey Minyard 9323076bb3SCorey Minyard static void isa_ipmi_bmc_check(Object *obj, const char *name, 9423076bb3SCorey Minyard Object *val, Error **errp) 9523076bb3SCorey Minyard { 9623076bb3SCorey Minyard IPMIBmc *bmc = IPMI_BMC(val); 9723076bb3SCorey Minyard 9823076bb3SCorey Minyard if (bmc->intf) 9923076bb3SCorey Minyard error_setg(errp, "BMC object is already in use"); 10023076bb3SCorey Minyard } 10123076bb3SCorey Minyard 10223076bb3SCorey Minyard void ipmi_bmc_find_and_link(Object *obj, Object **bmc) 10323076bb3SCorey Minyard { 10423076bb3SCorey Minyard object_property_add_link(obj, "bmc", TYPE_IPMI_BMC, bmc, 10523076bb3SCorey Minyard isa_ipmi_bmc_check, 10623076bb3SCorey Minyard OBJ_PROP_LINK_UNREF_ON_RELEASE, 10723076bb3SCorey Minyard &error_abort); 10823076bb3SCorey Minyard } 10923076bb3SCorey Minyard 11023076bb3SCorey Minyard static Property ipmi_bmc_properties[] = { 11123076bb3SCorey Minyard DEFINE_PROP_UINT8("slave_addr", IPMIBmc, slave_addr, 0x20), 11223076bb3SCorey Minyard DEFINE_PROP_END_OF_LIST(), 11323076bb3SCorey Minyard }; 11423076bb3SCorey Minyard 11523076bb3SCorey Minyard static void bmc_class_init(ObjectClass *oc, void *data) 11623076bb3SCorey Minyard { 11723076bb3SCorey Minyard DeviceClass *dc = DEVICE_CLASS(oc); 11823076bb3SCorey Minyard 11923076bb3SCorey Minyard dc->props = ipmi_bmc_properties; 12023076bb3SCorey Minyard } 12123076bb3SCorey Minyard 12223076bb3SCorey Minyard static TypeInfo ipmi_bmc_type_info = { 12323076bb3SCorey Minyard .name = TYPE_IPMI_BMC, 12423076bb3SCorey Minyard .parent = TYPE_DEVICE, 12523076bb3SCorey Minyard .instance_size = sizeof(IPMIBmc), 12623076bb3SCorey Minyard .abstract = true, 12723076bb3SCorey Minyard .class_size = sizeof(IPMIBmcClass), 12823076bb3SCorey Minyard .class_init = bmc_class_init, 12923076bb3SCorey Minyard }; 13023076bb3SCorey Minyard 13123076bb3SCorey Minyard static void ipmi_register_types(void) 13223076bb3SCorey Minyard { 13323076bb3SCorey Minyard type_register_static(&ipmi_interface_type_info); 13423076bb3SCorey Minyard type_register_static(&ipmi_bmc_type_info); 13523076bb3SCorey Minyard } 13623076bb3SCorey Minyard 13723076bb3SCorey Minyard type_init(ipmi_register_types) 138