Commit 1941d19c657a8084603e88d7860786baa40c0e80
1 parent
89b6b508
PCI save/restore changes
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2115 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
4 changed files
with
50 additions
and
20 deletions
hw/ne2000.c
... | ... | @@ -648,6 +648,9 @@ static void ne2000_save(QEMUFile* f,void* opaque) |
648 | 648 | { |
649 | 649 | NE2000State* s=(NE2000State*)opaque; |
650 | 650 | |
651 | + if (s->pci_dev) | |
652 | + pci_device_save(s->pci_dev, f); | |
653 | + | |
651 | 654 | qemu_put_8s(f, &s->rxcr); |
652 | 655 | |
653 | 656 | qemu_put_8s(f, &s->cmd); |
... | ... | @@ -673,13 +676,21 @@ static void ne2000_save(QEMUFile* f,void* opaque) |
673 | 676 | static int ne2000_load(QEMUFile* f,void* opaque,int version_id) |
674 | 677 | { |
675 | 678 | NE2000State* s=(NE2000State*)opaque; |
679 | + int ret; | |
680 | + | |
681 | + if (version_id > 3) | |
682 | + return -EINVAL; | |
683 | + | |
684 | + if (s->pci_dev && version_id >= 3) { | |
685 | + ret = pci_device_load(s->pci_dev, f); | |
686 | + if (ret < 0) | |
687 | + return ret; | |
688 | + } | |
676 | 689 | |
677 | - if (version_id == 2) { | |
690 | + if (version_id >= 2) { | |
678 | 691 | qemu_get_8s(f, &s->rxcr); |
679 | - } else if (version_id == 1) { | |
680 | - s->rxcr = 0x0c; | |
681 | 692 | } else { |
682 | - return -EINVAL; | |
693 | + s->rxcr = 0x0c; | |
683 | 694 | } |
684 | 695 | |
685 | 696 | qemu_get_8s(f, &s->cmd); |
... | ... | @@ -810,7 +821,5 @@ void pci_ne2000_init(PCIBus *bus, NICInfo *nd) |
810 | 821 | s->macaddr[5]); |
811 | 822 | |
812 | 823 | /* XXX: instance number ? */ |
813 | - register_savevm("ne2000", 0, 2, ne2000_save, ne2000_load, s); | |
814 | - register_savevm("ne2000_pci", 0, 1, generic_pci_save, generic_pci_load, | |
815 | - &d->dev); | |
824 | + register_savevm("ne2000", 0, 3, ne2000_save, ne2000_load, s); | |
816 | 825 | } | ... | ... |
hw/pci.c
... | ... | @@ -36,6 +36,8 @@ struct PCIBus { |
36 | 36 | PCIDevice *devices[256]; |
37 | 37 | }; |
38 | 38 | |
39 | +static void pci_update_mappings(PCIDevice *d); | |
40 | + | |
39 | 41 | target_phys_addr_t pci_mem_base; |
40 | 42 | static int pci_irq_index; |
41 | 43 | static PCIBus *first_bus; |
... | ... | @@ -56,21 +58,20 @@ int pci_bus_num(PCIBus *s) |
56 | 58 | return s->bus_num; |
57 | 59 | } |
58 | 60 | |
59 | -void generic_pci_save(QEMUFile* f, void *opaque) | |
61 | +void pci_device_save(PCIDevice *s, QEMUFile *f) | |
60 | 62 | { |
61 | - PCIDevice* s=(PCIDevice*)opaque; | |
62 | - | |
63 | + qemu_put_be32(f, 1); /* PCI device version */ | |
63 | 64 | qemu_put_buffer(f, s->config, 256); |
64 | 65 | } |
65 | 66 | |
66 | -int generic_pci_load(QEMUFile* f, void *opaque, int version_id) | |
67 | +int pci_device_load(PCIDevice *s, QEMUFile *f) | |
67 | 68 | { |
68 | - PCIDevice* s=(PCIDevice*)opaque; | |
69 | - | |
69 | + uint32_t version_id; | |
70 | + version_id = qemu_get_be32(f); | |
70 | 71 | if (version_id != 1) |
71 | 72 | return -EINVAL; |
72 | - | |
73 | 73 | qemu_get_buffer(f, s->config, 256); |
74 | + pci_update_mappings(s); | |
74 | 75 | return 0; |
75 | 76 | } |
76 | 77 | ... | ... |
hw/piix_pci.c
... | ... | @@ -181,6 +181,20 @@ static void piix3_reset(PCIDevice *d) |
181 | 181 | pci_conf[0xae] = 0x00; |
182 | 182 | } |
183 | 183 | |
184 | +static void piix_save(QEMUFile* f, void *opaque) | |
185 | +{ | |
186 | + PCIDevice *d = opaque; | |
187 | + pci_device_save(d, f); | |
188 | +} | |
189 | + | |
190 | +static int piix_load(QEMUFile* f, void *opaque, int version_id) | |
191 | +{ | |
192 | + PCIDevice *d = opaque; | |
193 | + if (version_id != 2) | |
194 | + return -EINVAL; | |
195 | + return pci_device_load(d, f); | |
196 | +} | |
197 | + | |
184 | 198 | int piix3_init(PCIBus *bus) |
185 | 199 | { |
186 | 200 | PCIDevice *d; |
... | ... | @@ -188,7 +202,7 @@ int piix3_init(PCIBus *bus) |
188 | 202 | |
189 | 203 | d = pci_register_device(bus, "PIIX3", sizeof(PCIDevice), |
190 | 204 | -1, NULL, NULL); |
191 | - register_savevm("PIIX3", 0, 1, generic_pci_save, generic_pci_load, d); | |
205 | + register_savevm("PIIX3", 0, 2, piix_save, piix_load, d); | |
192 | 206 | |
193 | 207 | piix3_dev = d; |
194 | 208 | pci_conf = d->config; | ... | ... |
hw/rtl8139.c
... | ... | @@ -3122,6 +3122,8 @@ static void rtl8139_save(QEMUFile* f,void* opaque) |
3122 | 3122 | RTL8139State* s=(RTL8139State*)opaque; |
3123 | 3123 | int i; |
3124 | 3124 | |
3125 | + pci_device_save(s->pci_dev, f); | |
3126 | + | |
3125 | 3127 | qemu_put_buffer(f, s->phys, 6); |
3126 | 3128 | qemu_put_buffer(f, s->mult, 8); |
3127 | 3129 | |
... | ... | @@ -3203,12 +3205,18 @@ static void rtl8139_save(QEMUFile* f,void* opaque) |
3203 | 3205 | static int rtl8139_load(QEMUFile* f,void* opaque,int version_id) |
3204 | 3206 | { |
3205 | 3207 | RTL8139State* s=(RTL8139State*)opaque; |
3206 | - int i; | |
3208 | + int i, ret; | |
3207 | 3209 | |
3208 | 3210 | /* just 2 versions for now */ |
3209 | - if (version_id > 2) | |
3211 | + if (version_id > 3) | |
3210 | 3212 | return -EINVAL; |
3211 | 3213 | |
3214 | + if (version_id >= 3) { | |
3215 | + ret = pci_device_load(s->pci_dev, f); | |
3216 | + if (ret < 0) | |
3217 | + return ret; | |
3218 | + } | |
3219 | + | |
3212 | 3220 | /* saved since version 1 */ |
3213 | 3221 | qemu_get_buffer(f, s->phys, 6); |
3214 | 3222 | qemu_get_buffer(f, s->mult, 8); |
... | ... | @@ -3457,9 +3465,7 @@ void pci_rtl8139_init(PCIBus *bus, NICInfo *nd) |
3457 | 3465 | s->cplus_txbuffer_offset = 0; |
3458 | 3466 | |
3459 | 3467 | /* XXX: instance number ? */ |
3460 | - register_savevm("rtl8139", 0, 2, rtl8139_save, rtl8139_load, s); | |
3461 | - register_savevm("rtl8139_pci", 0, 1, generic_pci_save, generic_pci_load, | |
3462 | - &d->dev); | |
3468 | + register_savevm("rtl8139", 0, 3, rtl8139_save, rtl8139_load, s); | |
3463 | 3469 | |
3464 | 3470 | #if RTL8139_ONBOARD_TIMER |
3465 | 3471 | s->timer = qemu_new_timer(vm_clock, rtl8139_timer, s); | ... | ... |