]>
Commit | Line | Data |
---|---|---|
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 | 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" |
db1015e9 | 23 | #include "qom/object.h" |
10a584b2 | 24 | |
7dc58dee | 25 | /* The bit of supported pv event, TODO: include uapi header and remove this */ |
eec3d2ad | 26 | #define PVPANIC_F_PANICKED 0 |
7dc58dee | 27 | #define PVPANIC_F_CRASHLOADED 1 |
eec3d2ad HT |
28 | |
29 | /* The pv event value */ | |
30 | #define PVPANIC_PANICKED (1 << PVPANIC_F_PANICKED) | |
7dc58dee | 31 | #define PVPANIC_CRASHLOADED (1 << PVPANIC_F_CRASHLOADED) |
eec3d2ad | 32 | |
db1015e9 | 33 | typedef struct PVPanicState PVPanicState; |
8110fa1d EH |
34 | DECLARE_INSTANCE_CHECKER(PVPanicState, ISA_PVPANIC_DEVICE, |
35 | TYPE_PVPANIC) | |
eec3d2ad | 36 | |
eec3d2ad HT |
37 | static void handle_event(int event) |
38 | { | |
39 | static bool logged; | |
40 | ||
7dc58dee | 41 | if (event & ~(PVPANIC_PANICKED | PVPANIC_CRASHLOADED) && !logged) { |
eec3d2ad HT |
42 | qemu_log_mask(LOG_GUEST_ERROR, "pvpanic: unknown event %#x.\n", event); |
43 | logged = true; | |
44 | } | |
45 | ||
46 | if (event & PVPANIC_PANICKED) { | |
c86f106b | 47 | qemu_system_guest_panicked(NULL); |
eec3d2ad HT |
48 | return; |
49 | } | |
7dc58dee ZP |
50 | |
51 | if (event & PVPANIC_CRASHLOADED) { | |
52 | qemu_system_guest_crashloaded(NULL); | |
53 | return; | |
54 | } | |
eec3d2ad HT |
55 | } |
56 | ||
57 | #include "hw/isa/isa.h" | |
58 | ||
db1015e9 | 59 | struct PVPanicState { |
eec3d2ad HT |
60 | ISADevice parent_obj; |
61 | ||
62 | MemoryRegion io; | |
63 | uint16_t ioport; | |
db1015e9 | 64 | }; |
eec3d2ad HT |
65 | |
66 | /* return supported events on read */ | |
67 | static uint64_t pvpanic_ioport_read(void *opaque, hwaddr addr, unsigned size) | |
68 | { | |
69 | return PVPANIC_PANICKED; | |
70 | } | |
71 | ||
72 | static void pvpanic_ioport_write(void *opaque, hwaddr addr, uint64_t val, | |
73 | unsigned size) | |
74 | { | |
75 | handle_event(val); | |
76 | } | |
77 | ||
78 | static const MemoryRegionOps pvpanic_ops = { | |
79 | .read = pvpanic_ioport_read, | |
80 | .write = pvpanic_ioport_write, | |
81 | .impl = { | |
82 | .min_access_size = 1, | |
83 | .max_access_size = 1, | |
84 | }, | |
85 | }; | |
86 | ||
db895a1e | 87 | static void pvpanic_isa_initfn(Object *obj) |
eec3d2ad | 88 | { |
db895a1e AF |
89 | PVPanicState *s = ISA_PVPANIC_DEVICE(obj); |
90 | ||
3c161542 | 91 | memory_region_init_io(&s->io, OBJECT(s), &pvpanic_ops, s, "pvpanic", 1); |
db895a1e AF |
92 | } |
93 | ||
94 | static void pvpanic_isa_realizefn(DeviceState *dev, Error **errp) | |
95 | { | |
96 | ISADevice *d = ISA_DEVICE(dev); | |
eec3d2ad | 97 | PVPanicState *s = ISA_PVPANIC_DEVICE(dev); |
a5d3f640 MA |
98 | FWCfgState *fw_cfg = fw_cfg_find(); |
99 | uint16_t *pvpanic_port; | |
eec3d2ad | 100 | |
a5d3f640 MA |
101 | if (!fw_cfg) { |
102 | return; | |
103 | } | |
eec3d2ad | 104 | |
a5d3f640 | 105 | pvpanic_port = g_malloc(sizeof(*pvpanic_port)); |
fea7d596 | 106 | *pvpanic_port = cpu_to_le16(s->ioport); |
fea7d596 MT |
107 | fw_cfg_add_file(fw_cfg, "etc/pvpanic-port", pvpanic_port, |
108 | sizeof(*pvpanic_port)); | |
a5d3f640 MA |
109 | |
110 | isa_register_ioport(d, &s->io, s->ioport); | |
eec3d2ad HT |
111 | } |
112 | ||
113 | static Property pvpanic_isa_properties[] = { | |
309cd62d | 114 | DEFINE_PROP_UINT16(PVPANIC_IOPORT_PROP, PVPanicState, ioport, 0x505), |
eec3d2ad HT |
115 | DEFINE_PROP_END_OF_LIST(), |
116 | }; | |
117 | ||
118 | static void pvpanic_isa_class_init(ObjectClass *klass, void *data) | |
119 | { | |
120 | DeviceClass *dc = DEVICE_CLASS(klass); | |
eec3d2ad | 121 | |
db895a1e | 122 | dc->realize = pvpanic_isa_realizefn; |
4f67d30b | 123 | device_class_set_props(dc, pvpanic_isa_properties); |
a5d3f640 | 124 | set_bit(DEVICE_CATEGORY_MISC, dc->categories); |
eec3d2ad HT |
125 | } |
126 | ||
127 | static TypeInfo pvpanic_isa_info = { | |
0d5d8a3a | 128 | .name = TYPE_PVPANIC, |
eec3d2ad HT |
129 | .parent = TYPE_ISA_DEVICE, |
130 | .instance_size = sizeof(PVPanicState), | |
db895a1e | 131 | .instance_init = pvpanic_isa_initfn, |
eec3d2ad HT |
132 | .class_init = pvpanic_isa_class_init, |
133 | }; | |
134 | ||
135 | static void pvpanic_register_types(void) | |
136 | { | |
137 | type_register_static(&pvpanic_isa_info); | |
138 | } | |
139 | ||
140 | type_init(pvpanic_register_types) |