Commit 72da42085924f65c78e6ec478373f51a9e49e48d
1 parent
3ae80618
qemu: return PCIDevice on net device init and record devfn (Marcelo Tosatti)
Change the PCI network drivers init functions to return the PCIDev, to inform which slot has been hot-plugged. Also record PCIDevice structure on NICInfo to locate for release on hot-removal. Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6593 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
10 changed files
with
44 additions
and
28 deletions
hw/e1000.c
... | ... | @@ -1034,7 +1034,7 @@ e1000_mmio_map(PCIDevice *pci_dev, int region_num, |
1034 | 1034 | excluded_regs[i] - 4); |
1035 | 1035 | } |
1036 | 1036 | |
1037 | -void | |
1037 | +PCIDevice * | |
1038 | 1038 | pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn) |
1039 | 1039 | { |
1040 | 1040 | E1000State *d; |
... | ... | @@ -1092,4 +1092,6 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn) |
1092 | 1092 | qemu_format_nic_info_str(d->vc, d->nd->macaddr); |
1093 | 1093 | |
1094 | 1094 | register_savevm(info_str, -1, 2, nic_save, nic_load, d); |
1095 | + | |
1096 | + return (PCIDevice *)d; | |
1095 | 1097 | } | ... | ... |
hw/eepro100.c
... | ... | @@ -1735,7 +1735,7 @@ static void nic_save(QEMUFile * f, void *opaque) |
1735 | 1735 | qemu_put_buffer(f, s->configuration, sizeof(s->configuration)); |
1736 | 1736 | } |
1737 | 1737 | |
1738 | -static void nic_init(PCIBus * bus, NICInfo * nd, | |
1738 | +static PCIDevice *nic_init(PCIBus * bus, NICInfo * nd, | |
1739 | 1739 | const char *name, uint32_t device) |
1740 | 1740 | { |
1741 | 1741 | PCIEEPRO100State *d; |
... | ... | @@ -1783,22 +1783,23 @@ static void nic_init(PCIBus * bus, NICInfo * nd, |
1783 | 1783 | qemu_register_reset(nic_reset, s); |
1784 | 1784 | |
1785 | 1785 | register_savevm(name, -1, 3, nic_save, nic_load, s); |
1786 | + return (PCIDevice *)d; | |
1786 | 1787 | } |
1787 | 1788 | |
1788 | -void pci_i82551_init(PCIBus * bus, NICInfo * nd, int devfn) | |
1789 | +PCIDevice *pci_i82551_init(PCIBus * bus, NICInfo * nd, int devfn) | |
1789 | 1790 | { |
1790 | - nic_init(bus, nd, "i82551", i82551); | |
1791 | + return nic_init(bus, nd, "i82551", i82551); | |
1791 | 1792 | //~ uint8_t *pci_conf = d->dev.config; |
1792 | 1793 | } |
1793 | 1794 | |
1794 | -void pci_i82557b_init(PCIBus * bus, NICInfo * nd, int devfn) | |
1795 | +PCIDevice *pci_i82557b_init(PCIBus * bus, NICInfo * nd, int devfn) | |
1795 | 1796 | { |
1796 | - nic_init(bus, nd, "i82557b", i82557B); | |
1797 | + return nic_init(bus, nd, "i82557b", i82557B); | |
1797 | 1798 | } |
1798 | 1799 | |
1799 | -void pci_i82559er_init(PCIBus * bus, NICInfo * nd, int devfn) | |
1800 | +PCIDevice *pci_i82559er_init(PCIBus * bus, NICInfo * nd, int devfn) | |
1800 | 1801 | { |
1801 | - nic_init(bus, nd, "i82559er", i82559ER); | |
1802 | + return nic_init(bus, nd, "i82559er", i82559ER); | |
1802 | 1803 | } |
1803 | 1804 | |
1804 | 1805 | /* eof */ | ... | ... |
hw/ne2000.c
... | ... | @@ -777,7 +777,7 @@ static void ne2000_map(PCIDevice *pci_dev, int region_num, |
777 | 777 | register_ioport_read(addr + 0x1f, 1, 1, ne2000_reset_ioport_read, s); |
778 | 778 | } |
779 | 779 | |
780 | -void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn) | |
780 | +PCIDevice *pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn) | |
781 | 781 | { |
782 | 782 | PCINE2000State *d; |
783 | 783 | NE2000State *s; |
... | ... | @@ -807,4 +807,6 @@ void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn) |
807 | 807 | qemu_format_nic_info_str(s->vc, s->macaddr); |
808 | 808 | |
809 | 809 | register_savevm("ne2000", -1, 3, ne2000_save, ne2000_load, s); |
810 | + | |
811 | + return (PCIDevice *)d; | |
810 | 812 | } | ... | ... |
hw/pci.c
... | ... | @@ -662,7 +662,7 @@ static const char * const pci_nic_models[] = { |
662 | 662 | NULL |
663 | 663 | }; |
664 | 664 | |
665 | -typedef void (*PCINICInitFn)(PCIBus *, NICInfo *, int); | |
665 | +typedef PCIDevice *(*PCINICInitFn)(PCIBus *, NICInfo *, int); | |
666 | 666 | |
667 | 667 | static PCINICInitFn pci_nic_init_fns[] = { |
668 | 668 | pci_ne2000_init, |
... | ... | @@ -677,16 +677,23 @@ static PCINICInitFn pci_nic_init_fns[] = { |
677 | 677 | }; |
678 | 678 | |
679 | 679 | /* Initialize a PCI NIC. */ |
680 | -void pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn, | |
680 | +PCIDevice *pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn, | |
681 | 681 | const char *default_model) |
682 | 682 | { |
683 | + PCIDevice *pci_dev; | |
683 | 684 | int i; |
684 | 685 | |
685 | 686 | qemu_check_nic_model_list(nd, pci_nic_models, default_model); |
686 | 687 | |
687 | 688 | for (i = 0; pci_nic_models[i]; i++) |
688 | - if (strcmp(nd->model, pci_nic_models[i]) == 0) | |
689 | - pci_nic_init_fns[i](bus, nd, devfn); | |
689 | + if (strcmp(nd->model, pci_nic_models[i]) == 0) { | |
690 | + pci_dev = pci_nic_init_fns[i](bus, nd, devfn); | |
691 | + if (pci_dev) | |
692 | + nd->private = pci_dev; | |
693 | + return pci_dev; | |
694 | + } | |
695 | + | |
696 | + return NULL; | |
690 | 697 | } |
691 | 698 | |
692 | 699 | typedef struct { | ... | ... |
hw/pci.h
... | ... | @@ -220,7 +220,7 @@ typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num); |
220 | 220 | PCIBus *pci_register_bus(pci_set_irq_fn set_irq, pci_map_irq_fn map_irq, |
221 | 221 | qemu_irq *pic, int devfn_min, int nirq); |
222 | 222 | |
223 | -void pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn, | |
223 | +PCIDevice *pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn, | |
224 | 224 | const char *default_model); |
225 | 225 | void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len); |
226 | 226 | uint32_t pci_data_read(void *opaque, uint32_t addr, int len); |
... | ... | @@ -269,23 +269,23 @@ void usb_ohci_init_pci(struct PCIBus *bus, int num_ports, int devfn); |
269 | 269 | |
270 | 270 | /* eepro100.c */ |
271 | 271 | |
272 | -void pci_i82551_init(PCIBus *bus, NICInfo *nd, int devfn); | |
273 | -void pci_i82557b_init(PCIBus *bus, NICInfo *nd, int devfn); | |
274 | -void pci_i82559er_init(PCIBus *bus, NICInfo *nd, int devfn); | |
272 | +PCIDevice *pci_i82551_init(PCIBus *bus, NICInfo *nd, int devfn); | |
273 | +PCIDevice *pci_i82557b_init(PCIBus *bus, NICInfo *nd, int devfn); | |
274 | +PCIDevice *pci_i82559er_init(PCIBus *bus, NICInfo *nd, int devfn); | |
275 | 275 | |
276 | 276 | /* ne2000.c */ |
277 | 277 | |
278 | -void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn); | |
278 | +PCIDevice *pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn); | |
279 | 279 | |
280 | 280 | /* rtl8139.c */ |
281 | 281 | |
282 | -void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn); | |
282 | +PCIDevice *pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn); | |
283 | 283 | |
284 | 284 | /* e1000.c */ |
285 | -void pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn); | |
285 | +PCIDevice *pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn); | |
286 | 286 | |
287 | 287 | /* pcnet.c */ |
288 | -void pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn); | |
288 | +PCIDevice *pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn); | |
289 | 289 | |
290 | 290 | /* prep_pci.c */ |
291 | 291 | PCIBus *pci_prep_init(qemu_irq *pic); | ... | ... |
hw/pcnet.c
... | ... | @@ -1985,7 +1985,7 @@ static void pci_physical_memory_read(void *dma_opaque, target_phys_addr_t addr, |
1985 | 1985 | cpu_physical_memory_read(addr, buf, len); |
1986 | 1986 | } |
1987 | 1987 | |
1988 | -void pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn) | |
1988 | +PCIDevice *pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn) | |
1989 | 1989 | { |
1990 | 1990 | PCNetState *d; |
1991 | 1991 | uint8_t *pci_conf; |
... | ... | @@ -2032,6 +2032,7 @@ void pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn) |
2032 | 2032 | d->pci_dev = &d->dev; |
2033 | 2033 | |
2034 | 2034 | pcnet_common_init(d, nd); |
2035 | + return (PCIDevice *)d; | |
2035 | 2036 | } |
2036 | 2037 | |
2037 | 2038 | /* SPARC32 interface */ | ... | ... |
hw/rtl8139.c
... | ... | @@ -3414,7 +3414,7 @@ static void rtl8139_timer(void *opaque) |
3414 | 3414 | } |
3415 | 3415 | #endif /* RTL8139_ONBOARD_TIMER */ |
3416 | 3416 | |
3417 | -void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn) | |
3417 | +PCIDevice *pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn) | |
3418 | 3418 | { |
3419 | 3419 | PCIRTL8139State *d; |
3420 | 3420 | RTL8139State *s; |
... | ... | @@ -3466,4 +3466,5 @@ void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn) |
3466 | 3466 | qemu_mod_timer(s->timer, |
3467 | 3467 | rtl8139_get_next_tctr_time(s,qemu_get_clock(vm_clock))); |
3468 | 3468 | #endif /* RTL8139_ONBOARD_TIMER */ |
3469 | + return (PCIDevice *)d; | |
3469 | 3470 | } | ... | ... |
hw/virtio-net.c
... | ... | @@ -560,7 +560,7 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) |
560 | 560 | return 0; |
561 | 561 | } |
562 | 562 | |
563 | -void virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn) | |
563 | +PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn) | |
564 | 564 | { |
565 | 565 | VirtIONet *n; |
566 | 566 | static int virtio_net_id; |
... | ... | @@ -574,7 +574,7 @@ void virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn) |
574 | 574 | sizeof(struct virtio_net_config), |
575 | 575 | sizeof(VirtIONet)); |
576 | 576 | if (!n) |
577 | - return; | |
577 | + return NULL; | |
578 | 578 | |
579 | 579 | n->vdev.get_config = virtio_net_get_config; |
580 | 580 | n->vdev.set_config = virtio_net_set_config; |
... | ... | @@ -599,12 +599,13 @@ void virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn) |
599 | 599 | |
600 | 600 | n->mac_table.macs = qemu_mallocz(MAC_TABLE_ENTRIES * ETH_ALEN); |
601 | 601 | if (!n->mac_table.macs) |
602 | - return; | |
602 | + return NULL; | |
603 | 603 | |
604 | 604 | n->vlans = qemu_mallocz(MAX_VLAN >> 3); |
605 | 605 | if (!n->vlans) |
606 | - return; | |
606 | + return NULL; | |
607 | 607 | |
608 | 608 | register_savevm("virtio-net", virtio_net_id++, VIRTIO_NET_VM_VERSION, |
609 | 609 | virtio_net_save, virtio_net_load, n); |
610 | + return (PCIDevice *)n; | |
610 | 611 | } | ... | ... |
hw/virtio-net.h
... | ... | @@ -85,7 +85,7 @@ struct virtio_net_hdr_mrg_rxbuf |
85 | 85 | uint16_t num_buffers; /* Number of merged rx buffers */ |
86 | 86 | }; |
87 | 87 | |
88 | -void virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn); | |
88 | +PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn); | |
89 | 89 | |
90 | 90 | /* |
91 | 91 | * Control virtqueue data structures | ... | ... |