2
0

pvpanic-pci.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 "system/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_device.h"
  22. #include "standard-headers/misc/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 = (const 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(ps, DEVICE(s), 2);
  45. pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &ps->mr);
  46. }
  47. static const Property pvpanic_pci_properties[] = {
  48. DEFINE_PROP_UINT8("events", PVPanicPCIState, pvpanic.events,
  49. PVPANIC_EVENTS),
  50. };
  51. static void pvpanic_pci_class_init(ObjectClass *klass, void *data)
  52. {
  53. DeviceClass *dc = DEVICE_CLASS(klass);
  54. PCIDeviceClass *pc = PCI_DEVICE_CLASS(klass);
  55. device_class_set_props(dc, pvpanic_pci_properties);
  56. pc->realize = pvpanic_pci_realizefn;
  57. pc->vendor_id = PCI_VENDOR_ID_REDHAT;
  58. pc->device_id = PCI_DEVICE_ID_REDHAT_PVPANIC;
  59. pc->revision = 1;
  60. pc->class_id = PCI_CLASS_SYSTEM_OTHER;
  61. dc->vmsd = &vmstate_pvpanic_pci;
  62. set_bit(DEVICE_CATEGORY_MISC, dc->categories);
  63. }
  64. static const TypeInfo pvpanic_pci_info = {
  65. .name = TYPE_PVPANIC_PCI_DEVICE,
  66. .parent = TYPE_PCI_DEVICE,
  67. .instance_size = sizeof(PVPanicPCIState),
  68. .class_init = pvpanic_pci_class_init,
  69. .interfaces = (InterfaceInfo[]) {
  70. { INTERFACE_CONVENTIONAL_PCI_DEVICE },
  71. { }
  72. }
  73. };
  74. static void pvpanic_register_types(void)
  75. {
  76. type_register_static(&pvpanic_pci_info);
  77. }
  78. type_init(pvpanic_register_types);