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 "qapi/qmp/qobject.h"
16 #include "qapi/qmp/qjson.h"
17 #include "monitor/monitor.h"
18 #include "sysemu/sysemu.h"
21 #include "hw/nvram/fw_cfg.h"
22 #include "hw/i386/pc.h"
24 /* The bit of supported pv event */
25 #define PVPANIC_F_PANICKED 0
27 /* The pv event value */
28 #define PVPANIC_PANICKED (1 << PVPANIC_F_PANICKED)
30 #define TYPE_ISA_PVPANIC_DEVICE "pvpanic"
31 #define ISA_PVPANIC_DEVICE(obj) \
32 OBJECT_CHECK(PVPanicState, (obj), TYPE_ISA_PVPANIC_DEVICE)
34 static void panicked_mon_event(const char *action
)
38 data
= qobject_from_jsonf("{ 'action': %s }", action
);
39 monitor_protocol_event(QEVENT_GUEST_PANICKED
, data
);
43 static void handle_event(int event
)
47 if (event
& ~PVPANIC_PANICKED
&& !logged
) {
48 qemu_log_mask(LOG_GUEST_ERROR
, "pvpanic: unknown event %#x.\n", event
);
52 if (event
& PVPANIC_PANICKED
) {
53 panicked_mon_event("pause");
54 vm_stop(RUN_STATE_GUEST_PANICKED
);
59 #include "hw/isa/isa.h"
61 typedef struct PVPanicState
{
68 /* return supported events on read */
69 static uint64_t pvpanic_ioport_read(void *opaque
, hwaddr addr
, unsigned size
)
71 return PVPANIC_PANICKED
;
74 static void pvpanic_ioport_write(void *opaque
, hwaddr addr
, uint64_t val
,
80 static const MemoryRegionOps pvpanic_ops
= {
81 .read
= pvpanic_ioport_read
,
82 .write
= pvpanic_ioport_write
,
89 static int pvpanic_isa_initfn(ISADevice
*dev
)
91 PVPanicState
*s
= ISA_PVPANIC_DEVICE(dev
);
92 static bool port_configured
;
95 memory_region_init_io(&s
->io
, &pvpanic_ops
, s
, "pvpanic", 1);
96 isa_register_ioport(dev
, &s
->io
, s
->ioport
);
98 if (!port_configured
) {
99 fw_cfg
= object_resolve_path("/machine/fw_cfg", NULL
);
101 fw_cfg_add_file(fw_cfg
, "etc/pvpanic-port",
102 g_memdup(&s
->ioport
, sizeof(s
->ioport
)),
104 port_configured
= true;
111 int pvpanic_init(ISABus
*bus
)
113 isa_create_simple(bus
, TYPE_ISA_PVPANIC_DEVICE
);
117 static Property pvpanic_isa_properties
[] = {
118 DEFINE_PROP_UINT16("ioport", PVPanicState
, ioport
, 0x505),
119 DEFINE_PROP_END_OF_LIST(),
122 static void pvpanic_isa_class_init(ObjectClass
*klass
, void *data
)
124 DeviceClass
*dc
= DEVICE_CLASS(klass
);
125 ISADeviceClass
*ic
= ISA_DEVICE_CLASS(klass
);
127 ic
->init
= pvpanic_isa_initfn
;
129 dc
->props
= pvpanic_isa_properties
;
132 static TypeInfo pvpanic_isa_info
= {
133 .name
= TYPE_ISA_PVPANIC_DEVICE
,
134 .parent
= TYPE_ISA_DEVICE
,
135 .instance_size
= sizeof(PVPanicState
),
136 .class_init
= pvpanic_isa_class_init
,
139 static void pvpanic_register_types(void)
141 type_register_static(&pvpanic_isa_info
);
144 type_init(pvpanic_register_types
)