2
0

pvpanic.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 "sysemu/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/linux/pvpanic.h"
  23. static void handle_event(int event)
  24. {
  25. static bool logged;
  26. if (event & ~(PVPANIC_PANICKED | PVPANIC_CRASH_LOADED) && !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. }
  39. /* return supported events on read */
  40. static uint64_t pvpanic_read(void *opaque, hwaddr addr, unsigned size)
  41. {
  42. PVPanicState *pvp = opaque;
  43. return pvp->events;
  44. }
  45. static void pvpanic_write(void *opaque, hwaddr addr, uint64_t val,
  46. unsigned size)
  47. {
  48. handle_event(val);
  49. }
  50. static const MemoryRegionOps pvpanic_ops = {
  51. .read = pvpanic_read,
  52. .write = pvpanic_write,
  53. .impl = {
  54. .min_access_size = 1,
  55. .max_access_size = 1,
  56. },
  57. };
  58. void pvpanic_setup_io(PVPanicState *s, DeviceState *dev, unsigned size)
  59. {
  60. memory_region_init_io(&s->mr, OBJECT(dev), &pvpanic_ops, s, "pvpanic", size);
  61. }