Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / hw / misc / pvpanic.c
blob1540e9091a451a845d34c256ddbe9be547fb6873
1 /*
2 * QEMU simulated pvpanic device.
4 * Copyright Fujitsu, Corp. 2013
6 * Authors:
7 * Wen Congyang <wency@cn.fujitsu.com>
8 * Hu Tao <hutao@cn.fujitsu.com>
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.
15 #include "qemu/osdep.h"
16 #include "qemu/log.h"
17 #include "qemu/module.h"
18 #include "sysemu/runstate.h"
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"
26 static void handle_event(int event)
28 static bool logged;
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;
35 if (event & PVPANIC_PANICKED) {
36 qemu_system_guest_panicked(NULL);
37 return;
40 if (event & PVPANIC_CRASH_LOADED) {
41 qemu_system_guest_crashloaded(NULL);
42 return;
46 /* return supported events on read */
47 static uint64_t pvpanic_read(void *opaque, hwaddr addr, unsigned size)
49 PVPanicState *pvp = opaque;
50 return pvp->events;
53 static void pvpanic_write(void *opaque, hwaddr addr, uint64_t val,
54 unsigned size)
56 handle_event(val);
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,
68 void pvpanic_setup_io(PVPanicState *s, DeviceState *dev, unsigned size)
70 memory_region_init_io(&s->mr, OBJECT(dev), &pvpanic_ops, s, "pvpanic", size);