]> git.proxmox.com Git - mirror_qemu.git/blame - hw/misc/pvpanic.c
Merge remote-tracking branch 'remotes/kraxel/tags/input-20190111-pull-request' into...
[mirror_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
0d1c9782 15#include "qemu/osdep.h"
eec3d2ad
HT
16#include "sysemu/sysemu.h"
17#include "qemu/log.h"
18
10a584b2 19#include "hw/nvram/fw_cfg.h"
0d5d8a3a 20#include "hw/misc/pvpanic.h"
10a584b2 21
eec3d2ad
HT
22/* The bit of supported pv event */
23#define PVPANIC_F_PANICKED 0
24
25/* The pv event value */
26#define PVPANIC_PANICKED (1 << PVPANIC_F_PANICKED)
27
eec3d2ad 28#define ISA_PVPANIC_DEVICE(obj) \
0d5d8a3a 29 OBJECT_CHECK(PVPanicState, (obj), TYPE_PVPANIC)
eec3d2ad 30
eec3d2ad
HT
31static void handle_event(int event)
32{
33 static bool logged;
34
35 if (event & ~PVPANIC_PANICKED && !logged) {
36 qemu_log_mask(LOG_GUEST_ERROR, "pvpanic: unknown event %#x.\n", event);
37 logged = true;
38 }
39
40 if (event & PVPANIC_PANICKED) {
c86f106b 41 qemu_system_guest_panicked(NULL);
eec3d2ad
HT
42 return;
43 }
44}
45
46#include "hw/isa/isa.h"
47
48typedef struct PVPanicState {
49 ISADevice parent_obj;
50
51 MemoryRegion io;
52 uint16_t ioport;
53} PVPanicState;
54
55/* return supported events on read */
56static uint64_t pvpanic_ioport_read(void *opaque, hwaddr addr, unsigned size)
57{
58 return PVPANIC_PANICKED;
59}
60
61static void pvpanic_ioport_write(void *opaque, hwaddr addr, uint64_t val,
62 unsigned size)
63{
64 handle_event(val);
65}
66
67static const MemoryRegionOps pvpanic_ops = {
68 .read = pvpanic_ioport_read,
69 .write = pvpanic_ioport_write,
70 .impl = {
71 .min_access_size = 1,
72 .max_access_size = 1,
73 },
74};
75
db895a1e 76static void pvpanic_isa_initfn(Object *obj)
eec3d2ad 77{
db895a1e
AF
78 PVPanicState *s = ISA_PVPANIC_DEVICE(obj);
79
3c161542 80 memory_region_init_io(&s->io, OBJECT(s), &pvpanic_ops, s, "pvpanic", 1);
db895a1e
AF
81}
82
83static void pvpanic_isa_realizefn(DeviceState *dev, Error **errp)
84{
85 ISADevice *d = ISA_DEVICE(dev);
eec3d2ad 86 PVPanicState *s = ISA_PVPANIC_DEVICE(dev);
a5d3f640
MA
87 FWCfgState *fw_cfg = fw_cfg_find();
88 uint16_t *pvpanic_port;
eec3d2ad 89
a5d3f640
MA
90 if (!fw_cfg) {
91 return;
92 }
eec3d2ad 93
a5d3f640 94 pvpanic_port = g_malloc(sizeof(*pvpanic_port));
fea7d596 95 *pvpanic_port = cpu_to_le16(s->ioport);
fea7d596
MT
96 fw_cfg_add_file(fw_cfg, "etc/pvpanic-port", pvpanic_port,
97 sizeof(*pvpanic_port));
a5d3f640
MA
98
99 isa_register_ioport(d, &s->io, s->ioport);
eec3d2ad
HT
100}
101
102static Property pvpanic_isa_properties[] = {
309cd62d 103 DEFINE_PROP_UINT16(PVPANIC_IOPORT_PROP, PVPanicState, ioport, 0x505),
eec3d2ad
HT
104 DEFINE_PROP_END_OF_LIST(),
105};
106
107static void pvpanic_isa_class_init(ObjectClass *klass, void *data)
108{
109 DeviceClass *dc = DEVICE_CLASS(klass);
eec3d2ad 110
db895a1e 111 dc->realize = pvpanic_isa_realizefn;
eec3d2ad 112 dc->props = pvpanic_isa_properties;
a5d3f640 113 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
eec3d2ad
HT
114}
115
116static TypeInfo pvpanic_isa_info = {
0d5d8a3a 117 .name = TYPE_PVPANIC,
eec3d2ad
HT
118 .parent = TYPE_ISA_DEVICE,
119 .instance_size = sizeof(PVPanicState),
db895a1e 120 .instance_init = pvpanic_isa_initfn,
eec3d2ad
HT
121 .class_init = pvpanic_isa_class_init,
122};
123
124static void pvpanic_register_types(void)
125{
126 type_register_static(&pvpanic_isa_info);
127}
128
129type_init(pvpanic_register_types)