qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: qemu-devel@nongnu.org
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Subject: [Qemu-devel] [patch 02/18] qemu: return PCIDevice on net device init and record devfn
Date: Wed, 04 Feb 2009 11:33:05 -0200	[thread overview]
Message-ID: <20090204133923.279946626@localhost.localdomain> (raw)
In-Reply-To: 20090204133303.113145633@localhost.localdomain

[-- Attachment #1: net-return-pcidev --]
[-- Type: text/plain, Size: 8766 bytes --]

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>

Index: trunk/hw/e1000.c
===================================================================
--- trunk.orig/hw/e1000.c
+++ trunk/hw/e1000.c
@@ -1034,7 +1034,7 @@ e1000_mmio_map(PCIDevice *pci_dev, int r
                                      excluded_regs[i] - 4);
 }
 
-void
+PCIDevice *
 pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn)
 {
     E1000State *d;
@@ -1092,4 +1092,6 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd,
     qemu_format_nic_info_str(d->vc, d->nd->macaddr);
 
     register_savevm(info_str, -1, 2, nic_save, nic_load, d);
+
+    return (PCIDevice *)d;
 }
Index: trunk/hw/eepro100.c
===================================================================
--- trunk.orig/hw/eepro100.c
+++ trunk/hw/eepro100.c
@@ -1735,7 +1735,7 @@ static void nic_save(QEMUFile * f, void 
     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)
 {
     PCIEEPRO100State *d;
@@ -1783,22 +1783,23 @@ static void nic_init(PCIBus * bus, NICIn
     qemu_register_reset(nic_reset, 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;
 }
 
-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 */
Index: trunk/hw/ne2000.c
===================================================================
--- trunk.orig/hw/ne2000.c
+++ trunk/hw/ne2000.c
@@ -779,7 +779,7 @@ static void ne2000_map(PCIDevice *pci_de
     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;
     NE2000State *s;
@@ -809,4 +809,6 @@ void pci_ne2000_init(PCIBus *bus, NICInf
     qemu_format_nic_info_str(s->vc, s->macaddr);
 
     register_savevm("ne2000", -1, 3, ne2000_save, ne2000_load, s);
+
+    return (PCIDevice *)d;
 }
Index: trunk/hw/pci.c
===================================================================
--- trunk.orig/hw/pci.c
+++ trunk/hw/pci.c
@@ -664,7 +664,7 @@ static const char * const pci_nic_models
     NULL
 };
 
-typedef void (*PCINICInitFn)(PCIBus *, NICInfo *, int);
+typedef PCIDevice *(*PCINICInitFn)(PCIBus *, NICInfo *, int);
 
 static PCINICInitFn pci_nic_init_fns[] = {
     pci_ne2000_init,
@@ -679,16 +679,23 @@ static PCINICInitFn pci_nic_init_fns[] =
 };
 
 /* 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)
 {
+    PCIDevice *pci_dev;
     int i;
 
     qemu_check_nic_model_list(nd, pci_nic_models, default_model);
 
     for (i = 0; pci_nic_models[i]; i++)
-        if (strcmp(nd->model, pci_nic_models[i]) == 0)
-            pci_nic_init_fns[i](bus, nd, devfn);
+        if (strcmp(nd->model, pci_nic_models[i]) == 0) {
+            pci_dev = pci_nic_init_fns[i](bus, nd, devfn);
+            if (pci_dev)
+                nd->private = pci_dev;
+            return pci_dev;
+        }
+
+    return NULL;
 }
 
 typedef struct {
Index: trunk/hw/pci.h
===================================================================
--- trunk.orig/hw/pci.h
+++ trunk/hw/pci.h
@@ -220,7 +220,7 @@ typedef int (*pci_map_irq_fn)(PCIDevice 
 PCIBus *pci_register_bus(pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
                          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);
 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);
@@ -269,23 +269,23 @@ void usb_ohci_init_pci(struct PCIBus *bu
 
 /* eepro100.c */
 
-void pci_i82551_init(PCIBus *bus, NICInfo *nd, int devfn);
-void pci_i82557b_init(PCIBus *bus, NICInfo *nd, int devfn);
-void pci_i82559er_init(PCIBus *bus, NICInfo *nd, int devfn);
+PCIDevice *pci_i82551_init(PCIBus *bus, NICInfo *nd, int devfn);
+PCIDevice *pci_i82557b_init(PCIBus *bus, NICInfo *nd, int devfn);
+PCIDevice *pci_i82559er_init(PCIBus *bus, NICInfo *nd, int devfn);
 
 /* ne2000.c */
 
-void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn);
+PCIDevice *pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn);
 
 /* rtl8139.c */
 
-void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn);
+PCIDevice *pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn);
 
 /* e1000.c */
-void pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn);
+PCIDevice *pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn);
 
 /* 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 */
 PCIBus *pci_prep_init(qemu_irq *pic);
Index: trunk/hw/pcnet.c
===================================================================
--- trunk.orig/hw/pcnet.c
+++ trunk/hw/pcnet.c
@@ -1985,7 +1985,7 @@ static void pci_physical_memory_read(voi
     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;
     uint8_t *pci_conf;
@@ -2032,6 +2032,7 @@ void pci_pcnet_init(PCIBus *bus, NICInfo
     d->pci_dev = &d->dev;
 
     pcnet_common_init(d, nd);
+    return (PCIDevice *)d;
 }
 
 /* SPARC32 interface */
Index: trunk/hw/rtl8139.c
===================================================================
--- trunk.orig/hw/rtl8139.c
+++ trunk/hw/rtl8139.c
@@ -3414,7 +3414,7 @@ static void rtl8139_timer(void *opaque)
 }
 #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;
     RTL8139State *s;
@@ -3466,4 +3466,5 @@ void pci_rtl8139_init(PCIBus *bus, NICIn
     qemu_mod_timer(s->timer,
         rtl8139_get_next_tctr_time(s,qemu_get_clock(vm_clock)));
 #endif /* RTL8139_ONBOARD_TIMER */
+    return (PCIDevice *)d;
 }
Index: trunk/hw/virtio-net.c
===================================================================
--- trunk.orig/hw/virtio-net.c
+++ trunk/hw/virtio-net.c
@@ -315,7 +315,7 @@ static int virtio_net_load(QEMUFile *f, 
     return 0;
 }
 
-void virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)
+PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)
 {
     VirtIONet *n;
     static int virtio_net_id;
@@ -329,7 +329,7 @@ void virtio_net_init(PCIBus *bus, NICInf
                                      sizeof(struct virtio_net_config),
                                      sizeof(VirtIONet));
     if (!n)
-        return;
+        return NULL;
 
     n->vdev.get_config = virtio_net_update_config;
     n->vdev.get_features = virtio_net_get_features;
@@ -350,4 +350,5 @@ void virtio_net_init(PCIBus *bus, NICInf
 
     register_savevm("virtio-net", virtio_net_id++, 2,
                     virtio_net_save, virtio_net_load, n);
+    return (PCIDevice *)n;
 }
Index: trunk/hw/virtio-net.h
===================================================================
--- trunk.orig/hw/virtio-net.h
+++ trunk/hw/virtio-net.h
@@ -80,6 +80,6 @@ struct virtio_net_hdr_mrg_rxbuf
     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);
 
 #endif
Index: trunk/net.h
===================================================================
--- trunk.orig/net.h
+++ trunk/net.h
@@ -64,6 +64,7 @@ struct NICInfo {
     const char *model;
     const char *name;
     VLANState *vlan;
+    void *private;
 };
 
 extern int nb_nics;

-- 

  parent reply	other threads:[~2009-02-04 13:45 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-04 13:33 [Qemu-devel] [patch 00/18] acpi pci hotplug support Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 01/18] qemu: add pci helper functions Marcelo Tosatti
2009-02-04 14:56   ` Paul Brook
2009-02-04 19:15     ` Anthony Liguori
2009-02-06 17:35       ` Marcelo Tosatti
2009-02-04 13:33 ` Marcelo Tosatti [this message]
2009-02-04 13:33 ` [Qemu-devel] [patch 03/18] qemu: dynamic drive/drive_opt index allocation Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 04/18] qemu: dynamic nic info " Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 05/18] qemu: drive removal support Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 06/18] qemu: record devfn on block driver instance Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 07/18] qemu: move drives_opt for external use Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 08/18] qemu: net/drive add/remove tweaks Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 09/18] qemu: add net_client_uninit / qemu_find_vlan_client Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 10/18] qemu: add cpu_unregister_io_memory and make io mem table index dynamic Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 11/18] qemu: add qemu_free_irqs Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 12/18] qemu: add pci_unregister_device Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 13/18] qemu: warn if PCI region is not power of two Marcelo Tosatti
2009-02-04 14:38   ` Paul Brook
2009-02-06 17:34     ` Marcelo Tosatti
2009-02-08  6:08       ` malc
2009-02-08 17:20         ` Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 14/18] qemu: LSI SCSI and e1000 unregister callbacks Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 15/18] qemu: zero ioport_opaque on isa_unassign_ioport Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 16/18] qemu: initialize hot add system / acpi gpe Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 17/18] qemu: pci hotplug GPE support Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 18/18] qemu: PCI device, disk and host network hot-add / hot-remove Marcelo Tosatti
2009-02-04 14:38   ` Daniel P. Berrange
2009-02-04 15:21     ` Anthony Liguori
2009-02-04 15:37       ` Daniel P. Berrange
2009-02-04 15:59       ` Avi Kivity
2009-02-04 16:46         ` Anthony Liguori
2009-02-04 14:59   ` Paul Brook
2009-02-04 16:17   ` Markus Armbruster
2009-02-04 17:47   ` Blue Swirl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090204133923.279946626@localhost.localdomain \
    --to=mtosatti@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).