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