]>
Commit | Line | Data |
---|---|---|
eec3d2ad HT |
1 | /* |
2 | * QEMU simulated pvpanic device. | |
3 | * | |
4 | * Copyright Fujitsu, Corp. 2013 | |
5 | * | |
6 | * Authors: | |
7 | * Wen Congyang <[email protected]> | |
8 | * Hu Tao <[email protected]> | |
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 | 16 | #include "qemu/log.h" |
0b8fa32f | 17 | #include "qemu/module.h" |
54d31236 | 18 | #include "sysemu/runstate.h" |
eec3d2ad | 19 | |
10a584b2 | 20 | #include "hw/nvram/fw_cfg.h" |
a27bd6c7 | 21 | #include "hw/qdev-properties.h" |
0d5d8a3a | 22 | #include "hw/misc/pvpanic.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 | ||
eec3d2ad | 30 | #define ISA_PVPANIC_DEVICE(obj) \ |
0d5d8a3a | 31 | OBJECT_CHECK(PVPanicState, (obj), TYPE_PVPANIC) |
eec3d2ad | 32 | |
eec3d2ad HT |
33 | static void handle_event(int event) |
34 | { | |
35 | static bool logged; | |
36 | ||
37 | if (event & ~PVPANIC_PANICKED && !logged) { | |
38 | qemu_log_mask(LOG_GUEST_ERROR, "pvpanic: unknown event %#x.\n", event); | |
39 | logged = true; | |
40 | } | |
41 | ||
42 | if (event & PVPANIC_PANICKED) { | |
c86f106b | 43 | qemu_system_guest_panicked(NULL); |
eec3d2ad HT |
44 | return; |
45 | } | |
46 | } | |
47 | ||
48 | #include "hw/isa/isa.h" | |
49 | ||
50 | typedef struct PVPanicState { | |
51 | ISADevice parent_obj; | |
52 | ||
53 | MemoryRegion io; | |
54 | uint16_t ioport; | |
55 | } PVPanicState; | |
56 | ||
57 | /* return supported events on read */ | |
58 | static uint64_t pvpanic_ioport_read(void *opaque, hwaddr addr, unsigned size) | |
59 | { | |
60 | return PVPANIC_PANICKED; | |
61 | } | |
62 | ||
63 | static void pvpanic_ioport_write(void *opaque, hwaddr addr, uint64_t val, | |
64 | unsigned size) | |
65 | { | |
66 | handle_event(val); | |
67 | } | |
68 | ||
69 | static const MemoryRegionOps pvpanic_ops = { | |
70 | .read = pvpanic_ioport_read, | |
71 | .write = pvpanic_ioport_write, | |
72 | .impl = { | |
73 | .min_access_size = 1, | |
74 | .max_access_size = 1, | |
75 | }, | |
76 | }; | |
77 | ||
db895a1e | 78 | static void pvpanic_isa_initfn(Object *obj) |
eec3d2ad | 79 | { |
db895a1e AF |
80 | PVPanicState *s = ISA_PVPANIC_DEVICE(obj); |
81 | ||
3c161542 | 82 | memory_region_init_io(&s->io, OBJECT(s), &pvpanic_ops, s, "pvpanic", 1); |
db895a1e AF |
83 | } |
84 | ||
85 | static void pvpanic_isa_realizefn(DeviceState *dev, Error **errp) | |
86 | { | |
87 | ISADevice *d = ISA_DEVICE(dev); | |
eec3d2ad | 88 | PVPanicState *s = ISA_PVPANIC_DEVICE(dev); |
a5d3f640 MA |
89 | FWCfgState *fw_cfg = fw_cfg_find(); |
90 | uint16_t *pvpanic_port; | |
eec3d2ad | 91 | |
a5d3f640 MA |
92 | if (!fw_cfg) { |
93 | return; | |
94 | } | |
eec3d2ad | 95 | |
a5d3f640 | 96 | pvpanic_port = g_malloc(sizeof(*pvpanic_port)); |
fea7d596 | 97 | *pvpanic_port = cpu_to_le16(s->ioport); |
fea7d596 MT |
98 | fw_cfg_add_file(fw_cfg, "etc/pvpanic-port", pvpanic_port, |
99 | sizeof(*pvpanic_port)); | |
a5d3f640 MA |
100 | |
101 | isa_register_ioport(d, &s->io, s->ioport); | |
eec3d2ad HT |
102 | } |
103 | ||
104 | static Property pvpanic_isa_properties[] = { | |
309cd62d | 105 | DEFINE_PROP_UINT16(PVPANIC_IOPORT_PROP, PVPanicState, ioport, 0x505), |
eec3d2ad HT |
106 | DEFINE_PROP_END_OF_LIST(), |
107 | }; | |
108 | ||
109 | static void pvpanic_isa_class_init(ObjectClass *klass, void *data) | |
110 | { | |
111 | DeviceClass *dc = DEVICE_CLASS(klass); | |
eec3d2ad | 112 | |
db895a1e | 113 | dc->realize = pvpanic_isa_realizefn; |
eec3d2ad | 114 | dc->props = pvpanic_isa_properties; |
a5d3f640 | 115 | set_bit(DEVICE_CATEGORY_MISC, dc->categories); |
eec3d2ad HT |
116 | } |
117 | ||
118 | static TypeInfo pvpanic_isa_info = { | |
0d5d8a3a | 119 | .name = TYPE_PVPANIC, |
eec3d2ad HT |
120 | .parent = TYPE_ISA_DEVICE, |
121 | .instance_size = sizeof(PVPanicState), | |
db895a1e | 122 | .instance_init = pvpanic_isa_initfn, |
eec3d2ad HT |
123 | .class_init = pvpanic_isa_class_init, |
124 | }; | |
125 | ||
126 | static void pvpanic_register_types(void) | |
127 | { | |
128 | type_register_static(&pvpanic_isa_info); | |
129 | } | |
130 | ||
131 | type_init(pvpanic_register_types) |