| 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 | |
| 14 | #include "qemu/osdep.h" |
| 15 | #include "qemu/module.h" |
| 16 | #include "system/runstate.h" |
| 17 | |
| 18 | #include "hw/nvram/fw_cfg.h" |
| 19 | #include "hw/core/qdev-properties.h" |
| 20 | #include "migration/vmstate.h" |
| 21 | #include "hw/misc/pvpanic.h" |
| 22 | #include "qom/object.h" |
| 23 | #include "hw/pci/pci_device.h" |
| 24 | #include "standard-headers/misc/pvpanic.h" |
| 25 | |
| 26 | OBJECT_DECLARE_SIMPLE_TYPE(PVPanicPCIState, PVPANIC_PCI_DEVICE) |
| 27 | |
| 28 | /* |
| 29 | * PVPanicPCIState for PCI device |
| 30 | */ |
| 31 | typedef struct PVPanicPCIState { |
| 32 | PCIDevice dev; |
| 33 | PVPanicState pvpanic; |
| 34 | } PVPanicPCIState; |
| 35 | |
| 36 | static const VMStateDescription vmstate_pvpanic_pci = { |
| 37 | .name = "pvpanic-pci", |
| 38 | .version_id = 1, |
| 39 | .minimum_version_id = 1, |
| 40 | .fields = (const VMStateField[]) { |
| 41 | VMSTATE_PCI_DEVICE(dev, PVPanicPCIState), |
| 42 | VMSTATE_END_OF_LIST() |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | static void pvpanic_pci_realizefn(PCIDevice *dev, Error **errp) |
| 47 | { |
| 48 | PVPanicPCIState *s = PVPANIC_PCI_DEVICE(dev); |
| 49 | PVPanicState *ps = &s->pvpanic; |
| 50 | |
| 51 | pvpanic_setup_io(ps, DEVICE(s), 2); |
| 52 | |
| 53 | pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &ps->mr); |
| 54 | } |
| 55 | |
| 56 | static const Property pvpanic_pci_properties[] = { |
| 57 | DEFINE_PROP_UINT8("events", PVPanicPCIState, pvpanic.events, |
| 58 | PVPANIC_EVENTS), |
| 59 | }; |
| 60 | |
| 61 | static void pvpanic_pci_class_init(ObjectClass *klass, const void *data) |
| 62 | { |
| 63 | DeviceClass *dc = DEVICE_CLASS(klass); |
| 64 | PCIDeviceClass *pc = PCI_DEVICE_CLASS(klass); |
| 65 | |
| 66 | device_class_set_props(dc, pvpanic_pci_properties); |
| 67 | |
| 68 | pc->realize = pvpanic_pci_realizefn; |
| 69 | pc->vendor_id = PCI_VENDOR_ID_REDHAT; |
| 70 | pc->device_id = PCI_DEVICE_ID_REDHAT_PVPANIC; |
| 71 | pc->revision = 1; |
| 72 | pc->class_id = PCI_CLASS_SYSTEM_OTHER; |
| 73 | dc->vmsd = &vmstate_pvpanic_pci; |
| 74 | |
| 75 | set_bit(DEVICE_CATEGORY_MISC, dc->categories); |
| 76 | } |
| 77 | |
| 78 | static const TypeInfo pvpanic_pci_info = { |
| 79 | .name = TYPE_PVPANIC_PCI_DEVICE, |
| 80 | .parent = TYPE_PCI_DEVICE, |
| 81 | .instance_size = sizeof(PVPanicPCIState), |
| 82 | .class_init = pvpanic_pci_class_init, |
| 83 | .interfaces = (const InterfaceInfo[]) { |
| 84 | { INTERFACE_CONVENTIONAL_PCI_DEVICE }, |
| 85 | { } |
| 86 | } |
| 87 | }; |
| 88 | |
| 89 | static void pvpanic_register_types(void) |
| 90 | { |
| 91 | type_register_static(&pvpanic_pci_info); |
| 92 | } |
| 93 | |
| 94 | type_init(pvpanic_register_types); |