static void chr_event(void *opaque, int event) { IPMIBmcExtern *ibe = opaque; IPMIInterface *s = ibe->parent.intf; IPMIInterfaceClass *k = IPMI_INTERFACE_GET_CLASS(s); unsigned char v; switch (event) { case CHR_EVENT_OPENED: ibe->connected = true; ibe->outpos = 0; ibe->outlen = 0; addchar(ibe, VM_CMD_VERSION); addchar(ibe, VM_PROTOCOL_VERSION); ibe->outbuf[ibe->outlen] = VM_CMD_CHAR; ibe->outlen++; addchar(ibe, VM_CMD_CAPABILITIES); v = VM_CAPABILITIES_IRQ | VM_CAPABILITIES_ATTN; if (k->do_hw_op(ibe->parent.intf, IPMI_POWEROFF_CHASSIS, 1) == 0) { v |= VM_CAPABILITIES_POWER; } if (k->do_hw_op(ibe->parent.intf, IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP, 1) == 0) { v |= VM_CAPABILITIES_GRACEFUL_SHUTDOWN; } if (k->do_hw_op(ibe->parent.intf, IPMI_RESET_CHASSIS, 1) == 0) { v |= VM_CAPABILITIES_RESET; } if (k->do_hw_op(ibe->parent.intf, IPMI_SEND_NMI, 1) == 0) { v |= VM_CAPABILITIES_NMI; } addchar(ibe, v); ibe->outbuf[ibe->outlen] = VM_CMD_CHAR; ibe->outlen++; ibe->sending_cmd = false; continue_send(ibe); break; case CHR_EVENT_CLOSED: if (!ibe->connected) { return; } ibe->connected = false; if (ibe->waiting_rsp) { ibe->waiting_rsp = false; ibe->inbuf[1] = ibe->outbuf[1] | 0x04; ibe->inbuf[2] = ibe->outbuf[2]; ibe->inbuf[3] = IPMI_CC_BMC_INIT_IN_PROGRESS; k->handle_rsp(s, ibe->outbuf[0], ibe->inbuf + 1, 3); } break; } }
static void handle_hw_op(IPMIBmcExtern *ibe, unsigned char hw_op) { IPMIInterface *s = ibe->parent.intf; IPMIInterfaceClass *k = IPMI_INTERFACE_GET_CLASS(s); switch (hw_op) { case VM_CMD_VERSION: /* We only support one version at this time. */ break; case VM_CMD_NOATTN: k->set_atn(s, 0, 0); break; case VM_CMD_ATTN: k->set_atn(s, 1, 0); break; case VM_CMD_ATTN_IRQ: k->set_atn(s, 1, 1); break; case VM_CMD_POWEROFF: k->do_hw_op(s, IPMI_POWEROFF_CHASSIS, 0); break; case VM_CMD_RESET: k->do_hw_op(s, IPMI_RESET_CHASSIS, 0); break; case VM_CMD_ENABLE_IRQ: k->set_irq_enable(s, 1); break; case VM_CMD_DISABLE_IRQ: k->set_irq_enable(s, 0); break; case VM_CMD_SEND_NMI: k->do_hw_op(s, IPMI_SEND_NMI, 0); break; case VM_CMD_FORCEOFF: qemu_system_shutdown_request(); break; } }