Sparc32/64 CPU selection
[qemu] / hw / ne2000.c
index 674d83e..a045a20 100644 (file)
@@ -206,7 +206,7 @@ static int ne2000_buffer_full(NE2000State *s)
 
     index = s->curpag << 8;
     boundary = s->boundary << 8;
-    if (index < boundary)
+    if (index <= boundary)
         avail = boundary - index;
     else
         avail = (s->stop - s->start) - (index - boundary);
@@ -312,7 +312,7 @@ static void ne2000_receive(void *opaque, const uint8_t *buf, int size)
     }
     s->curpag = next >> 8;
 
-    /* now we can signal we have receive something */
+    /* now we can signal we have received something */
     s->isr |= ENISR_RX;
     ne2000_update_irq(s);
 }
@@ -648,6 +648,9 @@ static void ne2000_save(QEMUFile* f,void* opaque)
 {
        NE2000State* s=(NE2000State*)opaque;
 
+        if (s->pci_dev)
+            pci_device_save(s->pci_dev, f);
+
         qemu_put_8s(f, &s->rxcr);
 
        qemu_put_8s(f, &s->cmd);
@@ -673,13 +676,21 @@ static void ne2000_save(QEMUFile* f,void* opaque)
 static int ne2000_load(QEMUFile* f,void* opaque,int version_id)
 {
        NE2000State* s=(NE2000State*)opaque;
+        int ret;
+
+        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) {
+        if (version_id >= 2) {
             qemu_get_8s(f, &s->rxcr);
-        } else if (version_id == 1) {
-            s->rxcr = 0x0c;
         } else {
-            return -EINVAL;
+            s->rxcr = 0x0c;
         }
 
        qemu_get_8s(f, &s->cmd);
@@ -770,7 +781,7 @@ static void ne2000_map(PCIDevice *pci_dev, int region_num,
     register_ioport_read(addr + 0x1f, 1, 1, ne2000_reset_ioport_read, s);
 }
 
-void pci_ne2000_init(PCIBus *bus, NICInfo *nd)
+void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn)
 {
     PCINE2000State *d;
     NE2000State *s;
@@ -778,7 +789,7 @@ void pci_ne2000_init(PCIBus *bus, NICInfo *nd)
     
     d = (PCINE2000State *)pci_register_device(bus,
                                               "NE2000", sizeof(PCINE2000State),
-                                              -1, 
+                                              devfn, 
                                               NULL, NULL);
     pci_conf = d->dev.config;
     pci_conf[0x00] = 0xec; // Realtek 8029
@@ -810,7 +821,5 @@ void pci_ne2000_init(PCIBus *bus, NICInfo *nd)
              s->macaddr[5]);
              
     /* XXX: instance number ? */
-    register_savevm("ne2000", 0, 2, ne2000_save, ne2000_load, s);
-    register_savevm("ne2000_pci", 0, 1, generic_pci_save, generic_pci_load, 
-                    &d->dev);
+    register_savevm("ne2000", 0, 3, ne2000_save, ne2000_load, s);
 }