]> git.proxmox.com Git - mirror_qemu.git/blob - hw/misc/pvpanic.c
Merge tag 'block-pull-request' of https://gitlab.com/stefanha/qemu into staging
[mirror_qemu.git] / hw / misc / pvpanic.c
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 "qemu/osdep.h"
16 #include "qemu/log.h"
17 #include "qemu/module.h"
18 #include "sysemu/runstate.h"
19
20 #include "hw/nvram/fw_cfg.h"
21 #include "hw/qdev-properties.h"
22 #include "hw/misc/pvpanic.h"
23 #include "qom/object.h"
24 #include "standard-headers/linux/pvpanic.h"
25
26 static void handle_event(int event)
27 {
28 static bool logged;
29
30 if (event & ~(PVPANIC_PANICKED | PVPANIC_CRASH_LOADED) && !logged) {
31 qemu_log_mask(LOG_GUEST_ERROR, "pvpanic: unknown event %#x.\n", event);
32 logged = true;
33 }
34
35 if (event & PVPANIC_PANICKED) {
36 qemu_system_guest_panicked(NULL);
37 return;
38 }
39
40 if (event & PVPANIC_CRASH_LOADED) {
41 qemu_system_guest_crashloaded(NULL);
42 return;
43 }
44 }
45
46 /* return supported events on read */
47 static uint64_t pvpanic_read(void *opaque, hwaddr addr, unsigned size)
48 {
49 PVPanicState *pvp = opaque;
50 return pvp->events;
51 }
52
53 static void pvpanic_write(void *opaque, hwaddr addr, uint64_t val,
54 unsigned size)
55 {
56 handle_event(val);
57 }
58
59 static const MemoryRegionOps pvpanic_ops = {
60 .read = pvpanic_read,
61 .write = pvpanic_write,
62 .impl = {
63 .min_access_size = 1,
64 .max_access_size = 1,
65 },
66 };
67
68 void pvpanic_setup_io(PVPanicState *s, DeviceState *dev, unsigned size)
69 {
70 memory_region_init_io(&s->mr, OBJECT(dev), &pvpanic_ops, s, "pvpanic", size);
71 }