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/misc/pvpanic.h" 25 26 static void handle_event(int event) 27 { 28 static bool logged; 29 30 if (event & ~PVPANIC_EVENTS && !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 if (event & PVPANIC_SHUTDOWN) { 46 qemu_system_guest_pvshutdown(); 47 return; 48 } 49 } 50 51 /* return supported events on read */ 52 static uint64_t pvpanic_read(void *opaque, hwaddr addr, unsigned size) 53 { 54 PVPanicState *pvp = opaque; 55 return pvp->events; 56 } 57 58 static void pvpanic_write(void *opaque, hwaddr addr, uint64_t val, 59 unsigned size) 60 { 61 handle_event(val); 62 } 63 64 static const MemoryRegionOps pvpanic_ops = { 65 .read = pvpanic_read, 66 .write = pvpanic_write, 67 .impl = { 68 .min_access_size = 1, 69 .max_access_size = 1, 70 }, 71 }; 72 73 void pvpanic_setup_io(PVPanicState *s, DeviceState *dev, unsigned size) 74 { 75 memory_region_init_io(&s->mr, OBJECT(dev), &pvpanic_ops, s, "pvpanic", size); 76 } 77