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" 31*e688df6bSMarkus Armbruster #include "qapi/error.h" 3223076bb3SCorey Minyard #include "qapi/visitor.h" 3323076bb3SCorey Minyard 3415139b8eSCorey Minyard static uint32_t ipmi_current_uuid = 1; 3515139b8eSCorey Minyard 3615139b8eSCorey Minyard uint32_t ipmi_next_uuid(void) 3715139b8eSCorey Minyard { 3815139b8eSCorey Minyard return ipmi_current_uuid++; 3915139b8eSCorey Minyard } 4015139b8eSCorey Minyard 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 } 6223076bb3SCorey Minyard qmp_inject_nmi(NULL); 6323076bb3SCorey Minyard return 0; 6423076bb3SCorey Minyard 659c22c1c3SCorey Minyard case IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP: 669c22c1c3SCorey Minyard if (checkonly) { 679c22c1c3SCorey Minyard return 0; 689c22c1c3SCorey Minyard } 699c22c1c3SCorey Minyard qemu_system_powerdown_request(); 709c22c1c3SCorey Minyard return 0; 719c22c1c3SCorey Minyard 7223076bb3SCorey Minyard case IPMI_POWERCYCLE_CHASSIS: 7323076bb3SCorey Minyard case IPMI_PULSE_DIAG_IRQ: 7423076bb3SCorey Minyard case IPMI_POWERON_CHASSIS: 7523076bb3SCorey Minyard default: 7623076bb3SCorey Minyard return IPMI_CC_COMMAND_NOT_SUPPORTED; 7723076bb3SCorey Minyard } 7823076bb3SCorey Minyard } 7923076bb3SCorey Minyard 8023076bb3SCorey Minyard static void ipmi_interface_class_init(ObjectClass *class, void *data) 8123076bb3SCorey Minyard { 8223076bb3SCorey Minyard IPMIInterfaceClass *ik = IPMI_INTERFACE_CLASS(class); 8323076bb3SCorey Minyard 8423076bb3SCorey Minyard ik->do_hw_op = ipmi_do_hw_op; 8523076bb3SCorey Minyard } 8623076bb3SCorey Minyard 8723076bb3SCorey Minyard static TypeInfo ipmi_interface_type_info = { 8823076bb3SCorey Minyard .name = TYPE_IPMI_INTERFACE, 8923076bb3SCorey Minyard .parent = TYPE_INTERFACE, 9023076bb3SCorey Minyard .class_size = sizeof(IPMIInterfaceClass), 9123076bb3SCorey Minyard .class_init = ipmi_interface_class_init, 9223076bb3SCorey Minyard }; 9323076bb3SCorey Minyard 948f5d58efSIgor Mammedov static void isa_ipmi_bmc_check(const Object *obj, const char *name, 9523076bb3SCorey Minyard Object *val, Error **errp) 9623076bb3SCorey Minyard { 9723076bb3SCorey Minyard IPMIBmc *bmc = IPMI_BMC(val); 9823076bb3SCorey Minyard 9923076bb3SCorey Minyard if (bmc->intf) 10023076bb3SCorey Minyard error_setg(errp, "BMC object is already in use"); 10123076bb3SCorey Minyard } 10223076bb3SCorey Minyard 10323076bb3SCorey Minyard void ipmi_bmc_find_and_link(Object *obj, Object **bmc) 10423076bb3SCorey Minyard { 10523076bb3SCorey Minyard object_property_add_link(obj, "bmc", TYPE_IPMI_BMC, bmc, 10623076bb3SCorey Minyard isa_ipmi_bmc_check, 10723076bb3SCorey Minyard OBJ_PROP_LINK_UNREF_ON_RELEASE, 10823076bb3SCorey Minyard &error_abort); 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 11623076bb3SCorey Minyard static void bmc_class_init(ObjectClass *oc, void *data) 11723076bb3SCorey Minyard { 11823076bb3SCorey Minyard DeviceClass *dc = DEVICE_CLASS(oc); 11923076bb3SCorey Minyard 12023076bb3SCorey Minyard dc->props = ipmi_bmc_properties; 12123076bb3SCorey Minyard } 12223076bb3SCorey Minyard 12323076bb3SCorey Minyard static 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 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