pvpanic-pci.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * QEMU simulated PCI pvpanic device.
  3. *
  4. * Copyright (C) 2020 Oracle
  5. *
  6. * Authors:
  7. * Mihai Carabas <mihai.carabas@oracle.com>
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  10. * See the COPYING file in the top-level directory.
  11. *
  12. */
  13. #include "qemu/osdep.h"
  14. #include "qemu/module.h"
  15. #include "sysemu/runstate.h"
  16. #include "hw/nvram/fw_cfg.h"
  17. #include "hw/qdev-properties.h"
  18. #include "migration/vmstate.h"
  19. #include "hw/misc/pvpanic.h"
  20. #include "qom/object.h"
  21. #include "hw/pci/pci.h"
  22. #include "standard-headers/linux/pvpanic.h"
  23. OBJECT_DECLARE_SIMPLE_TYPE(PVPanicPCIState, PVPANIC_PCI_DEVICE)
  24. /*
  25. * PVPanicPCIState for PCI device
  26. */
  27. typedef struct PVPanicPCIState {
  28. PCIDevice dev;
  29. PVPanicState pvpanic;
  30. } PVPanicPCIState;
  31. static const VMStateDescription vmstate_pvpanic_pci = {
  32. .name = "pvpanic-pci",
  33. .version_id = 1,
  34. .minimum_version_id = 1,
  35. .fields = (VMStateField[]) {
  36. VMSTATE_PCI_DEVICE(dev, PVPanicPCIState),
  37. VMSTATE_END_OF_LIST()
  38. }
  39. };
  40. static void pvpanic_pci_realizefn(PCIDevice *dev, Error **errp)
  41. {
  42. PVPanicPCIState *s = PVPANIC_PCI_DEVICE(dev);
  43. PVPanicState *ps = &s->pvpanic;
  44. pvpanic_setup_io(&s->pvpanic, DEVICE(s), 2);
  45. pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &ps->mr);
  46. }
  47. static Property pvpanic_pci_properties[] = {
  48. DEFINE_PROP_UINT8("events", PVPanicPCIState, pvpanic.events,
  49. PVPANIC_PANICKED | PVPANIC_CRASH_LOADED),
  50. DEFINE_PROP_END_OF_LIST(),
  51. };
  52. static void pvpanic_pci_class_init(ObjectClass *klass, void *data)
  53. {
  54. DeviceClass *dc = DEVICE_CLASS(klass);
  55. PCIDeviceClass *pc = PCI_DEVICE_CLASS(klass);
  56. device_class_set_props(dc, pvpanic_pci_properties);
  57. pc->realize = pvpanic_pci_realizefn;
  58. pc->vendor_id = PCI_VENDOR_ID_REDHAT;
  59. pc->device_id = PCI_DEVICE_ID_REDHAT_PVPANIC;
  60. pc->revision = 1;
  61. pc->class_id = PCI_CLASS_SYSTEM_OTHER;
  62. dc->vmsd = &vmstate_pvpanic_pci;
  63. set_bit(DEVICE_CATEGORY_MISC, dc->categories);
  64. }
  65. static const TypeInfo pvpanic_pci_info = {
  66. .name = TYPE_PVPANIC_PCI_DEVICE,
  67. .parent = TYPE_PCI_DEVICE,
  68. .instance_size = sizeof(PVPanicPCIState),
  69. .class_init = pvpanic_pci_class_init,
  70. .interfaces = (InterfaceInfo[]) {
  71. { INTERFACE_CONVENTIONAL_PCI_DEVICE },
  72. { }
  73. }
  74. };
  75. static void pvpanic_register_types(void)
  76. {
  77. type_register_static(&pvpanic_pci_info);
  78. }
  79. type_init(pvpanic_register_types);