mirror of https://github.com/xemu-project/xemu.git
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
This commit is contained in:
parent
3ae8061898
commit
72da420859
|
@ -1034,7 +1034,7 @@ e1000_mmio_map(PCIDevice *pci_dev, int region_num,
|
||||||
excluded_regs[i] - 4);
|
excluded_regs[i] - 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
PCIDevice *
|
||||||
pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn)
|
pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn)
|
||||||
{
|
{
|
||||||
E1000State *d;
|
E1000State *d;
|
||||||
|
@ -1092,4 +1092,6 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn)
|
||||||
qemu_format_nic_info_str(d->vc, d->nd->macaddr);
|
qemu_format_nic_info_str(d->vc, d->nd->macaddr);
|
||||||
|
|
||||||
register_savevm(info_str, -1, 2, nic_save, nic_load, d);
|
register_savevm(info_str, -1, 2, nic_save, nic_load, d);
|
||||||
|
|
||||||
|
return (PCIDevice *)d;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1735,7 +1735,7 @@ static void nic_save(QEMUFile * f, void *opaque)
|
||||||
qemu_put_buffer(f, s->configuration, sizeof(s->configuration));
|
qemu_put_buffer(f, s->configuration, sizeof(s->configuration));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void nic_init(PCIBus * bus, NICInfo * nd,
|
static PCIDevice *nic_init(PCIBus * bus, NICInfo * nd,
|
||||||
const char *name, uint32_t device)
|
const char *name, uint32_t device)
|
||||||
{
|
{
|
||||||
PCIEEPRO100State *d;
|
PCIEEPRO100State *d;
|
||||||
|
@ -1783,22 +1783,23 @@ static void nic_init(PCIBus * bus, NICInfo * nd,
|
||||||
qemu_register_reset(nic_reset, s);
|
qemu_register_reset(nic_reset, s);
|
||||||
|
|
||||||
register_savevm(name, -1, 3, nic_save, nic_load, s);
|
register_savevm(name, -1, 3, nic_save, nic_load, s);
|
||||||
|
return (PCIDevice *)d;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pci_i82551_init(PCIBus * bus, NICInfo * nd, int devfn)
|
PCIDevice *pci_i82551_init(PCIBus * bus, NICInfo * nd, int devfn)
|
||||||
{
|
{
|
||||||
nic_init(bus, nd, "i82551", i82551);
|
return nic_init(bus, nd, "i82551", i82551);
|
||||||
//~ uint8_t *pci_conf = d->dev.config;
|
//~ uint8_t *pci_conf = d->dev.config;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pci_i82557b_init(PCIBus * bus, NICInfo * nd, int devfn)
|
PCIDevice *pci_i82557b_init(PCIBus * bus, NICInfo * nd, int devfn)
|
||||||
{
|
{
|
||||||
nic_init(bus, nd, "i82557b", i82557B);
|
return nic_init(bus, nd, "i82557b", i82557B);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pci_i82559er_init(PCIBus * bus, NICInfo * nd, int devfn)
|
PCIDevice *pci_i82559er_init(PCIBus * bus, NICInfo * nd, int devfn)
|
||||||
{
|
{
|
||||||
nic_init(bus, nd, "i82559er", i82559ER);
|
return nic_init(bus, nd, "i82559er", i82559ER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eof */
|
/* eof */
|
||||||
|
|
|
@ -777,7 +777,7 @@ static void ne2000_map(PCIDevice *pci_dev, int region_num,
|
||||||
register_ioport_read(addr + 0x1f, 1, 1, ne2000_reset_ioport_read, s);
|
register_ioport_read(addr + 0x1f, 1, 1, ne2000_reset_ioport_read, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn)
|
PCIDevice *pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn)
|
||||||
{
|
{
|
||||||
PCINE2000State *d;
|
PCINE2000State *d;
|
||||||
NE2000State *s;
|
NE2000State *s;
|
||||||
|
@ -807,4 +807,6 @@ void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn)
|
||||||
qemu_format_nic_info_str(s->vc, s->macaddr);
|
qemu_format_nic_info_str(s->vc, s->macaddr);
|
||||||
|
|
||||||
register_savevm("ne2000", -1, 3, ne2000_save, ne2000_load, s);
|
register_savevm("ne2000", -1, 3, ne2000_save, ne2000_load, s);
|
||||||
|
|
||||||
|
return (PCIDevice *)d;
|
||||||
}
|
}
|
||||||
|
|
15
hw/pci.c
15
hw/pci.c
|
@ -662,7 +662,7 @@ static const char * const pci_nic_models[] = {
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*PCINICInitFn)(PCIBus *, NICInfo *, int);
|
typedef PCIDevice *(*PCINICInitFn)(PCIBus *, NICInfo *, int);
|
||||||
|
|
||||||
static PCINICInitFn pci_nic_init_fns[] = {
|
static PCINICInitFn pci_nic_init_fns[] = {
|
||||||
pci_ne2000_init,
|
pci_ne2000_init,
|
||||||
|
@ -677,16 +677,23 @@ static PCINICInitFn pci_nic_init_fns[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Initialize a PCI NIC. */
|
/* Initialize a PCI NIC. */
|
||||||
void pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn,
|
PCIDevice *pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn,
|
||||||
const char *default_model)
|
const char *default_model)
|
||||||
{
|
{
|
||||||
|
PCIDevice *pci_dev;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
qemu_check_nic_model_list(nd, pci_nic_models, default_model);
|
qemu_check_nic_model_list(nd, pci_nic_models, default_model);
|
||||||
|
|
||||||
for (i = 0; pci_nic_models[i]; i++)
|
for (i = 0; pci_nic_models[i]; i++)
|
||||||
if (strcmp(nd->model, pci_nic_models[i]) == 0)
|
if (strcmp(nd->model, pci_nic_models[i]) == 0) {
|
||||||
pci_nic_init_fns[i](bus, nd, devfn);
|
pci_dev = pci_nic_init_fns[i](bus, nd, devfn);
|
||||||
|
if (pci_dev)
|
||||||
|
nd->private = pci_dev;
|
||||||
|
return pci_dev;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
16
hw/pci.h
16
hw/pci.h
|
@ -220,7 +220,7 @@ typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num);
|
||||||
PCIBus *pci_register_bus(pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
|
PCIBus *pci_register_bus(pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
|
||||||
qemu_irq *pic, int devfn_min, int nirq);
|
qemu_irq *pic, int devfn_min, int nirq);
|
||||||
|
|
||||||
void pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn,
|
PCIDevice *pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn,
|
||||||
const char *default_model);
|
const char *default_model);
|
||||||
void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len);
|
void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len);
|
||||||
uint32_t pci_data_read(void *opaque, uint32_t addr, int len);
|
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);
|
||||||
|
|
||||||
/* eepro100.c */
|
/* eepro100.c */
|
||||||
|
|
||||||
void pci_i82551_init(PCIBus *bus, NICInfo *nd, int devfn);
|
PCIDevice *pci_i82551_init(PCIBus *bus, NICInfo *nd, int devfn);
|
||||||
void pci_i82557b_init(PCIBus *bus, NICInfo *nd, int devfn);
|
PCIDevice *pci_i82557b_init(PCIBus *bus, NICInfo *nd, int devfn);
|
||||||
void pci_i82559er_init(PCIBus *bus, NICInfo *nd, int devfn);
|
PCIDevice *pci_i82559er_init(PCIBus *bus, NICInfo *nd, int devfn);
|
||||||
|
|
||||||
/* ne2000.c */
|
/* ne2000.c */
|
||||||
|
|
||||||
void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn);
|
PCIDevice *pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn);
|
||||||
|
|
||||||
/* rtl8139.c */
|
/* rtl8139.c */
|
||||||
|
|
||||||
void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn);
|
PCIDevice *pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn);
|
||||||
|
|
||||||
/* e1000.c */
|
/* e1000.c */
|
||||||
void pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn);
|
PCIDevice *pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn);
|
||||||
|
|
||||||
/* pcnet.c */
|
/* pcnet.c */
|
||||||
void pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn);
|
PCIDevice *pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn);
|
||||||
|
|
||||||
/* prep_pci.c */
|
/* prep_pci.c */
|
||||||
PCIBus *pci_prep_init(qemu_irq *pic);
|
PCIBus *pci_prep_init(qemu_irq *pic);
|
||||||
|
|
|
@ -1985,7 +1985,7 @@ static void pci_physical_memory_read(void *dma_opaque, target_phys_addr_t addr,
|
||||||
cpu_physical_memory_read(addr, buf, len);
|
cpu_physical_memory_read(addr, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn)
|
PCIDevice *pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn)
|
||||||
{
|
{
|
||||||
PCNetState *d;
|
PCNetState *d;
|
||||||
uint8_t *pci_conf;
|
uint8_t *pci_conf;
|
||||||
|
@ -2032,6 +2032,7 @@ void pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn)
|
||||||
d->pci_dev = &d->dev;
|
d->pci_dev = &d->dev;
|
||||||
|
|
||||||
pcnet_common_init(d, nd);
|
pcnet_common_init(d, nd);
|
||||||
|
return (PCIDevice *)d;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* SPARC32 interface */
|
/* SPARC32 interface */
|
||||||
|
|
|
@ -3414,7 +3414,7 @@ static void rtl8139_timer(void *opaque)
|
||||||
}
|
}
|
||||||
#endif /* RTL8139_ONBOARD_TIMER */
|
#endif /* RTL8139_ONBOARD_TIMER */
|
||||||
|
|
||||||
void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn)
|
PCIDevice *pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn)
|
||||||
{
|
{
|
||||||
PCIRTL8139State *d;
|
PCIRTL8139State *d;
|
||||||
RTL8139State *s;
|
RTL8139State *s;
|
||||||
|
@ -3466,4 +3466,5 @@ void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn)
|
||||||
qemu_mod_timer(s->timer,
|
qemu_mod_timer(s->timer,
|
||||||
rtl8139_get_next_tctr_time(s,qemu_get_clock(vm_clock)));
|
rtl8139_get_next_tctr_time(s,qemu_get_clock(vm_clock)));
|
||||||
#endif /* RTL8139_ONBOARD_TIMER */
|
#endif /* RTL8139_ONBOARD_TIMER */
|
||||||
|
return (PCIDevice *)d;
|
||||||
}
|
}
|
||||||
|
|
|
@ -560,7 +560,7 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)
|
PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)
|
||||||
{
|
{
|
||||||
VirtIONet *n;
|
VirtIONet *n;
|
||||||
static int virtio_net_id;
|
static int virtio_net_id;
|
||||||
|
@ -574,7 +574,7 @@ void virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)
|
||||||
sizeof(struct virtio_net_config),
|
sizeof(struct virtio_net_config),
|
||||||
sizeof(VirtIONet));
|
sizeof(VirtIONet));
|
||||||
if (!n)
|
if (!n)
|
||||||
return;
|
return NULL;
|
||||||
|
|
||||||
n->vdev.get_config = virtio_net_get_config;
|
n->vdev.get_config = virtio_net_get_config;
|
||||||
n->vdev.set_config = virtio_net_set_config;
|
n->vdev.set_config = virtio_net_set_config;
|
||||||
|
@ -599,12 +599,13 @@ void virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)
|
||||||
|
|
||||||
n->mac_table.macs = qemu_mallocz(MAC_TABLE_ENTRIES * ETH_ALEN);
|
n->mac_table.macs = qemu_mallocz(MAC_TABLE_ENTRIES * ETH_ALEN);
|
||||||
if (!n->mac_table.macs)
|
if (!n->mac_table.macs)
|
||||||
return;
|
return NULL;
|
||||||
|
|
||||||
n->vlans = qemu_mallocz(MAX_VLAN >> 3);
|
n->vlans = qemu_mallocz(MAX_VLAN >> 3);
|
||||||
if (!n->vlans)
|
if (!n->vlans)
|
||||||
return;
|
return NULL;
|
||||||
|
|
||||||
register_savevm("virtio-net", virtio_net_id++, VIRTIO_NET_VM_VERSION,
|
register_savevm("virtio-net", virtio_net_id++, VIRTIO_NET_VM_VERSION,
|
||||||
virtio_net_save, virtio_net_load, n);
|
virtio_net_save, virtio_net_load, n);
|
||||||
|
return (PCIDevice *)n;
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ struct virtio_net_hdr_mrg_rxbuf
|
||||||
uint16_t num_buffers; /* Number of merged rx buffers */
|
uint16_t num_buffers; /* Number of merged rx buffers */
|
||||||
};
|
};
|
||||||
|
|
||||||
void virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn);
|
PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Control virtqueue data structures
|
* Control virtqueue data structures
|
||||||
|
|
Loading…
Reference in New Issue