1 /* 2 * QEMU simulated pvpanic device. 3 * 4 * Copyright Fujitsu, Corp. 2013 5 * 6 * Authors: 7 * Wen Congyang <wency@cn.fujitsu.com> 8 * Hu Tao <hutao@cn.fujitsu.com> 9 * 10 * This work is licensed under the terms of the GNU GPL, version 2 or later. 11 * See the COPYING file in the top-level directory. 12 * 13 */ 14 15 #include "qemu/osdep.h" 16 #include "qemu/module.h" 17 #include "sysemu/runstate.h" 18 19 #include "hw/nvram/fw_cfg.h" 20 #include "hw/qdev-properties.h" 21 #include "hw/misc/pvpanic.h" 22 #include "qom/object.h" 23 #include "hw/isa/isa.h" 24 25 OBJECT_DECLARE_SIMPLE_TYPE(PVPanicISAState, PVPANIC_ISA_DEVICE) 26 27 /* 28 * PVPanicISAState for ISA device and 29 * use ioport. 30 */ 31 struct PVPanicISAState { 32 ISADevice parent_obj; 33 34 uint16_t ioport; 35 PVPanicState pvpanic; 36 }; 37 38 static void pvpanic_isa_initfn(Object *obj) 39 { 40 PVPanicISAState *s = PVPANIC_ISA_DEVICE(obj); 41 42 pvpanic_setup_io(&s->pvpanic, DEVICE(s), 1); 43 } 44 45 static void pvpanic_isa_realizefn(DeviceState *dev, Error **errp) 46 { 47 ISADevice *d = ISA_DEVICE(dev); 48 PVPanicISAState *s = PVPANIC_ISA_DEVICE(dev); 49 PVPanicState *ps = &s->pvpanic; 50 FWCfgState *fw_cfg = fw_cfg_find(); 51 uint16_t *pvpanic_port; 52 53 if (!fw_cfg) { 54 return; 55 } 56 57 pvpanic_port = g_malloc(sizeof(*pvpanic_port)); 58 *pvpanic_port = cpu_to_le16(s->ioport); 59 fw_cfg_add_file(fw_cfg, "etc/pvpanic-port", pvpanic_port, 60 sizeof(*pvpanic_port)); 61 62 isa_register_ioport(d, &ps->mr, s->ioport); 63 } 64 65 static Property pvpanic_isa_properties[] = { 66 DEFINE_PROP_UINT16(PVPANIC_IOPORT_PROP, PVPanicISAState, ioport, 0x505), 67 DEFINE_PROP_UINT8("events", PVPanicISAState, pvpanic.events, PVPANIC_PANICKED | PVPANIC_CRASHLOADED), 68 DEFINE_PROP_END_OF_LIST(), 69 }; 70 71 static void pvpanic_isa_class_init(ObjectClass *klass, void *data) 72 { 73 DeviceClass *dc = DEVICE_CLASS(klass); 74 75 dc->realize = pvpanic_isa_realizefn; 76 device_class_set_props(dc, pvpanic_isa_properties); 77 set_bit(DEVICE_CATEGORY_MISC, dc->categories); 78 } 79 80 static TypeInfo pvpanic_isa_info = { 81 .name = TYPE_PVPANIC_ISA_DEVICE, 82 .parent = TYPE_ISA_DEVICE, 83 .instance_size = sizeof(PVPanicISAState), 84 .instance_init = pvpanic_isa_initfn, 85 .class_init = pvpanic_isa_class_init, 86 }; 87 88 static void pvpanic_register_types(void) 89 { 90 type_register_static(&pvpanic_isa_info); 91 } 92 93 type_init(pvpanic_register_types) 94