Patchwork [19/26] Add pci_ne2000_{save/load} functions, then remove pci_dev NE2000State field

login
register
mail settings
Submitter Juan Quintela
Date Aug. 24, 2009, 4:42 p.m.
Message ID <3cb5dafa20850ea5da3f32a1ba7c18bd4127fc68.1251131364.git.quintela@redhat.com>
Download mbox | patch
Permalink /patch/31985/
State Superseded
Headers show

Comments

Juan Quintela - Aug. 24, 2009, 4:42 p.m.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/ne2000.c |   43 ++++++++++++++++++++++++++++---------------
 1 files changed, 28 insertions(+), 15 deletions(-)

Patch

diff --git a/hw/ne2000.c b/hw/ne2000.c
index 1c47c84..c983bc5 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -141,7 +141,6 @@  typedef struct NE2000State {
     uint8_t mult[8]; /* multicast mask array */
     qemu_irq irq;
     int isa_io_base;
-    PCIDevice *pci_dev;
     VLANClientState *vc;
     uint8_t macaddr[6];
     uint8_t mem[NE2000_MEM_SIZE];
@@ -653,14 +652,11 @@  static uint32_t ne2000_reset_ioport_read(void *opaque, uint32_t addr)
     return 0;
 }

-static void ne2000_save(QEMUFile* f,void* opaque)
+static void ne2000_save(QEMUFile* f, void* opaque)
 {
 	NE2000State* s = opaque;
         uint32_t tmp;

-        if (s->pci_dev)
-            pci_device_save(s->pci_dev, f);
-
         qemu_put_8s(f, &s->rxcr);

 	qemu_put_8s(f, &s->cmd);
@@ -684,21 +680,14 @@  static void ne2000_save(QEMUFile* f,void* opaque)
 	qemu_put_buffer(f, s->mem, NE2000_MEM_SIZE);
 }

-static int ne2000_load(QEMUFile* f,void* opaque,int version_id)
+static int ne2000_load(QEMUFile* f, void* opaque, int version_id)
 {
 	NE2000State* s = opaque;
-        int ret;
         uint32_t tmp;

         if (version_id > 3)
             return -EINVAL;

-        if (s->pci_dev && version_id >= 3) {
-            ret = pci_device_load(s->pci_dev, f);
-            if (ret < 0)
-                return ret;
-        }
-
         if (version_id >= 2) {
             qemu_get_8s(f, &s->rxcr);
         } else {
@@ -727,6 +716,31 @@  static int ne2000_load(QEMUFile* f,void* opaque,int version_id)
 	return 0;
 }

+static void pci_ne2000_save(QEMUFile* f, void* opaque)
+{
+	PCINE2000State* s = opaque;
+
+        pci_device_save(&s->dev, f);
+        ne2000_save(f, &s->ne2000);
+}
+
+static int pci_ne2000_load(QEMUFile* f, void* opaque, int version_id)
+{
+	PCINE2000State* s = opaque;
+        int ret;
+
+        if (version_id > 3)
+            return -EINVAL;
+
+        if (version_id >= 3) {
+            ret = pci_device_load(&s->dev, f);
+            if (ret < 0)
+                return ret;
+        }
+
+        return ne2000_load(f, &s->ne2000, version_id);
+}
+
 static void isa_ne2000_cleanup(VLANClientState *vc)
 {
     NE2000State *s = vc->opaque;
@@ -820,7 +834,6 @@  static void pci_ne2000_init(PCIDevice *pci_dev)
                            PCI_ADDRESS_SPACE_IO, ne2000_map);
     s = &d->ne2000;
     s->irq = d->dev.irq[0];
-    s->pci_dev = pci_dev;
     qdev_get_macaddr(&d->dev.qdev, s->macaddr);
     ne2000_reset(s);
     s->vc = qdev_get_vlan_client(&d->dev.qdev,
@@ -829,7 +842,7 @@  static void pci_ne2000_init(PCIDevice *pci_dev)

     qemu_format_nic_info_str(s->vc, s->macaddr);

-    register_savevm("ne2000", -1, 3, ne2000_save, ne2000_load, s);
+    register_savevm("ne2000", -1, 3, pci_ne2000_save, pci_ne2000_load, d);
 }

 static PCIDeviceInfo ne2000_info = {