]> git.proxmox.com Git - qemu.git/blame - hw/misc/pvpanic.c
Merge git://github.com/hw-claudio/qemu-aarch64-queue into tcg-next
[qemu.git] / hw / misc / pvpanic.c
CommitLineData
eec3d2ad
HT
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 "qapi/qmp/qobject.h"
16#include "qapi/qmp/qjson.h"
17#include "monitor/monitor.h"
18#include "sysemu/sysemu.h"
19#include "qemu/log.h"
20
10a584b2 21#include "hw/nvram/fw_cfg.h"
3ab135f3 22#include "hw/i386/pc.h"
10a584b2 23
eec3d2ad
HT
24/* The bit of supported pv event */
25#define PVPANIC_F_PANICKED 0
26
27/* The pv event value */
28#define PVPANIC_PANICKED (1 << PVPANIC_F_PANICKED)
29
30#define TYPE_ISA_PVPANIC_DEVICE "pvpanic"
31#define ISA_PVPANIC_DEVICE(obj) \
32 OBJECT_CHECK(PVPanicState, (obj), TYPE_ISA_PVPANIC_DEVICE)
33
34static void panicked_mon_event(const char *action)
35{
36 QObject *data;
37
38 data = qobject_from_jsonf("{ 'action': %s }", action);
39 monitor_protocol_event(QEVENT_GUEST_PANICKED, data);
40 qobject_decref(data);
41}
42
43static void handle_event(int event)
44{
45 static bool logged;
46
47 if (event & ~PVPANIC_PANICKED && !logged) {
48 qemu_log_mask(LOG_GUEST_ERROR, "pvpanic: unknown event %#x.\n", event);
49 logged = true;
50 }
51
52 if (event & PVPANIC_PANICKED) {
53 panicked_mon_event("pause");
54 vm_stop(RUN_STATE_GUEST_PANICKED);
55 return;
56 }
57}
58
59#include "hw/isa/isa.h"
60
61typedef struct PVPanicState {
62 ISADevice parent_obj;
63
64 MemoryRegion io;
65 uint16_t ioport;
66} PVPanicState;
67
68/* return supported events on read */
69static uint64_t pvpanic_ioport_read(void *opaque, hwaddr addr, unsigned size)
70{
71 return PVPANIC_PANICKED;
72}
73
74static void pvpanic_ioport_write(void *opaque, hwaddr addr, uint64_t val,
75 unsigned size)
76{
77 handle_event(val);
78}
79
80static const MemoryRegionOps pvpanic_ops = {
81 .read = pvpanic_ioport_read,
82 .write = pvpanic_ioport_write,
83 .impl = {
84 .min_access_size = 1,
85 .max_access_size = 1,
86 },
87};
88
db895a1e 89static void pvpanic_isa_initfn(Object *obj)
eec3d2ad 90{
db895a1e
AF
91 PVPanicState *s = ISA_PVPANIC_DEVICE(obj);
92
3c161542 93 memory_region_init_io(&s->io, OBJECT(s), &pvpanic_ops, s, "pvpanic", 1);
db895a1e
AF
94}
95
96static void pvpanic_isa_realizefn(DeviceState *dev, Error **errp)
97{
98 ISADevice *d = ISA_DEVICE(dev);
eec3d2ad
HT
99 PVPanicState *s = ISA_PVPANIC_DEVICE(dev);
100
db895a1e 101 isa_register_ioport(d, &s->io, s->ioport);
bc3e6a0d 102}
eec3d2ad 103
bc3e6a0d
MT
104static void pvpanic_fw_cfg(ISADevice *dev, FWCfgState *fw_cfg)
105{
106 PVPanicState *s = ISA_PVPANIC_DEVICE(dev);
fea7d596
MT
107 uint16_t *pvpanic_port = g_malloc(sizeof(*pvpanic_port));
108 *pvpanic_port = cpu_to_le16(s->ioport);
bc3e6a0d 109
fea7d596
MT
110 fw_cfg_add_file(fw_cfg, "etc/pvpanic-port", pvpanic_port,
111 sizeof(*pvpanic_port));
eec3d2ad
HT
112}
113
bc3e6a0d 114void pvpanic_init(ISABus *bus)
3ab135f3 115{
bc3e6a0d
MT
116 ISADevice *dev;
117 FWCfgState *fw_cfg = fw_cfg_find();
118 if (!fw_cfg) {
119 return;
120 }
121 dev = isa_create_simple (bus, TYPE_ISA_PVPANIC_DEVICE);
122 pvpanic_fw_cfg(dev, fw_cfg);
3ab135f3
HT
123}
124
eec3d2ad
HT
125static Property pvpanic_isa_properties[] = {
126 DEFINE_PROP_UINT16("ioport", PVPanicState, ioport, 0x505),
127 DEFINE_PROP_END_OF_LIST(),
128};
129
130static void pvpanic_isa_class_init(ObjectClass *klass, void *data)
131{
132 DeviceClass *dc = DEVICE_CLASS(klass);
eec3d2ad 133
db895a1e 134 dc->realize = pvpanic_isa_realizefn;
eec3d2ad
HT
135 dc->no_user = 1;
136 dc->props = pvpanic_isa_properties;
137}
138
139static TypeInfo pvpanic_isa_info = {
140 .name = TYPE_ISA_PVPANIC_DEVICE,
141 .parent = TYPE_ISA_DEVICE,
142 .instance_size = sizeof(PVPanicState),
db895a1e 143 .instance_init = pvpanic_isa_initfn,
eec3d2ad
HT
144 .class_init = pvpanic_isa_class_init,
145};
146
147static void pvpanic_register_types(void)
148{
149 type_register_static(&pvpanic_isa_info);
150}
151
152type_init(pvpanic_register_types)