diff mbox

[RFC,for-1.6,qom-next,3/3] pci: Move AER log into VMStateSubsection

Message ID 1374975670-8820-4-git-send-email-afaerber@suse.de
State New
Headers show

Commit Message

Andreas Färber July 28, 2013, 1:41 a.m. UTC
XHCI does not call pcie_aer_init(), so use allocation of the AER log as
indicator for whether vmstate_pcie_aer_log is needed.

Go safe and zero the log pointer to support unrealizing and re-realizing
a PCIDevice without AER.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/pci/pci.c      | 24 ++++++++++++++++++++++--
 hw/pci/pcie_aer.c |  1 +
 2 files changed, 23 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index b69421a..4f373f9 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -477,6 +477,25 @@  const VMStateDescription vmstate_pci_device = {
     }
 };
 
+static bool pcie_aer_log_needed(void *opaque)
+{
+    PCIDevice *s = opaque;
+
+    return s->exp.aer_log.log != NULL;
+}
+
+static const VMStateDescription vmstate_pcie_device_aer_log = {
+    .name = "PCIEDevice/AER_Log",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_STRUCT(exp.aer_log, PCIDevice, 0,
+                       vmstate_pcie_aer_log, PCIEAERLog),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static bool pcie_msix_needed(void *opaque)
 {
     PCIDevice *s = opaque;
@@ -497,12 +516,13 @@  const VMStateDescription vmstate_pcie_device = {
         VMSTATE_BUFFER_UNSAFE_INFO(irq_state, PCIDevice, 2,
 				   vmstate_info_pci_irq_state,
 				   PCI_NUM_PINS * sizeof(int32_t)),
-        VMSTATE_STRUCT(exp.aer_log, PCIDevice, 0,
-                       vmstate_pcie_aer_log, PCIEAERLog),
         VMSTATE_END_OF_LIST()
     },
     .subsections = (VMStateSubsection[]) {
         {
+            .vmsd = &vmstate_pcie_device_aer_log,
+            .needed = pcie_aer_log_needed,
+        }, {
             .vmsd = &vmstate_msix,
             .needed = pcie_msix_needed,
         }, {
diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c
index ca762ab..2767ebc 100644
--- a/hw/pci/pcie_aer.c
+++ b/hw/pci/pcie_aer.c
@@ -166,6 +166,7 @@  int pcie_aer_init(PCIDevice *dev, uint16_t offset)
 void pcie_aer_exit(PCIDevice *dev)
 {
     g_free(dev->exp.aer_log.log);
+    dev->exp.aer_log.log = NULL;
 }
 
 static void pcie_aer_update_uncor_status(PCIDevice *dev)