2 * QEMU simulated pvpanic device.
4 * Copyright Fujitsu, Corp. 2013
7 * Wen Congyang <wency@cn.fujitsu.com>
8 * Hu Tao <hutao@cn.fujitsu.com>
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.
15 #include "qemu/osdep.h"
17 #include "qemu/module.h"
18 #include "sysemu/runstate.h"
20 #include "hw/nvram/fw_cfg.h"
21 #include "hw/qdev-properties.h"
22 #include "hw/misc/pvpanic.h"
23 #include "qom/object.h"
24 #include "hw/isa/isa.h"
26 OBJECT_DECLARE_SIMPLE_TYPE(PVPanicISAState
, PVPANIC_ISA_DEVICE
)
29 * PVPanicISAState for ISA device and
32 struct PVPanicISAState
{
39 static void pvpanic_isa_initfn(Object
*obj
)
41 PVPanicISAState
*s
= PVPANIC_ISA_DEVICE(obj
);
43 pvpanic_setup_io(&s
->pvpanic
, DEVICE(s
), 1);
46 static void pvpanic_isa_realizefn(DeviceState
*dev
, Error
**errp
)
48 ISADevice
*d
= ISA_DEVICE(dev
);
49 PVPanicISAState
*s
= PVPANIC_ISA_DEVICE(dev
);
50 PVPanicState
*ps
= &s
->pvpanic
;
51 FWCfgState
*fw_cfg
= fw_cfg_find();
52 uint16_t *pvpanic_port
;
58 pvpanic_port
= g_malloc(sizeof(*pvpanic_port
));
59 *pvpanic_port
= cpu_to_le16(s
->ioport
);
60 fw_cfg_add_file(fw_cfg
, "etc/pvpanic-port", pvpanic_port
,
61 sizeof(*pvpanic_port
));
63 isa_register_ioport(d
, &ps
->mr
, s
->ioport
);
66 static Property pvpanic_isa_properties
[] = {
67 DEFINE_PROP_UINT16(PVPANIC_IOPORT_PROP
, PVPanicISAState
, ioport
, 0x505),
68 DEFINE_PROP_UINT8("events", PVPanicISAState
, pvpanic
.events
, PVPANIC_PANICKED
| PVPANIC_CRASHLOADED
),
69 DEFINE_PROP_END_OF_LIST(),
72 static void pvpanic_isa_class_init(ObjectClass
*klass
, void *data
)
74 DeviceClass
*dc
= DEVICE_CLASS(klass
);
76 dc
->realize
= pvpanic_isa_realizefn
;
77 device_class_set_props(dc
, pvpanic_isa_properties
);
78 set_bit(DEVICE_CATEGORY_MISC
, dc
->categories
);
81 static TypeInfo pvpanic_isa_info
= {
82 .name
= TYPE_PVPANIC_ISA_DEVICE
,
83 .parent
= TYPE_ISA_DEVICE
,
84 .instance_size
= sizeof(PVPanicISAState
),
85 .instance_init
= pvpanic_isa_initfn
,
86 .class_init
= pvpanic_isa_class_init
,
89 static void pvpanic_register_types(void)
91 type_register_static(&pvpanic_isa_info
);
94 type_init(pvpanic_register_types
)