pvpanic.c 1.7 KB

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