[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cdi-devel] [PATCH 1/3] cdi.h: Introduce cdi_bus_data



+ Each device gets a structure that links it to its bus. For now this
  means moving the cdi_pci_device out of the specific device struct of
  each driver into the generic cdi_device.

Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 e1000/device.c            |   12 +++++++-----
 e1000/device.h            |    2 --
 e1000/main.c              |    2 +-
 include/cdi.h             |   11 +++++++++--
 include/cdi/pci.h         |    2 ++
 ne2k/include/ne2k.h       |    2 --
 ne2k/main.c               |    2 +-
 ne2k/ne2k.c               |    7 ++++---
 pcnet/include/pcnet.h     |    1 -
 pcnet/main.c              |    2 +-
 pcnet/pcnet.c             |   12 ++++++++----
 rtl8139/include/rtl8139.h |    1 -
 rtl8139/main.c            |    2 +-
 rtl8139/rtl8139.c         |    7 ++++---
 sis900/device.c           |   11 ++++++-----
 sis900/device.h           |    1 -
 sis900/main.c             |    2 +-
 17 files changed, 45 insertions(+), 34 deletions(-)

diff --git a/e1000/device.c b/e1000/device.c
index 4e5a62e..a92acf3 100644
--- a/e1000/device.c
+++ b/e1000/device.c
@@ -34,6 +34,7 @@
 
 #include "cdi.h"
 #include "cdi/misc.h"
+#include "cdi/pci.h"
 
 #include "device.h"
 #include "e1000_io.h"
@@ -148,14 +149,15 @@ static uint64_t get_mac_address(struct e1000_device* device)
 void e1000_init_device(struct cdi_device* device)
 {
     struct e1000_device* netcard = (struct e1000_device*) device;
+    struct cdi_pci_device* pci = (struct cdi_pci_device*) device->bus_data;
     netcard->net.send_packet = e1000_send_packet;
 
     // PCI-bezogenes Zeug initialisieren
-    netcard->revision = netcard->pci->rev_id;
-    cdi_register_irq(netcard->pci->irq, e1000_handle_interrupt, device);
-    cdi_pci_alloc_ioports(netcard->pci);
+    netcard->revision = pci->rev_id;
+    cdi_register_irq(pci->irq, e1000_handle_interrupt, device);
+    cdi_pci_alloc_ioports(pci);
 
-    cdi_list_t reslist = netcard->pci->resources;
+    cdi_list_t reslist = pci->resources;
     struct cdi_pci_resource* res;
     int i;
     for (i = 0; (res = cdi_list_get(reslist, i)); i++) {
@@ -167,7 +169,7 @@ void e1000_init_device(struct cdi_device* device)
 
     // Karte initialisieren
     printf("e1000: IRQ %d, MMIO an %p  Revision:%d\n",
-        netcard->pci->irq, netcard->mem_base, netcard->revision);
+        pci->irq, netcard->mem_base, netcard->revision);
 
     printf("e1000: Fuehre Reset der Karte durch\n");
     reset_nic(netcard);
diff --git a/e1000/device.h b/e1000/device.h
index 34f9dc1..40f03a7 100644
--- a/e1000/device.h
+++ b/e1000/device.h
@@ -33,7 +33,6 @@
 
 #include "cdi.h"
 #include "cdi/net.h"
-#include "cdi/pci.h"
 
 /* Register */
 
@@ -143,7 +142,6 @@ struct e1000_rx_descriptor {
 
 struct e1000_device {
     struct cdi_net_device       net;
-    struct cdi_pci_device*      pci;
 
     void*                       phys;
 
diff --git a/e1000/main.c b/e1000/main.c
index 26ce832..c98e191 100644
--- a/e1000/main.c
+++ b/e1000/main.c
@@ -65,7 +65,7 @@ static int e1000_driver_init(void)
             memset(device, 0, sizeof(*device));
 
             device->phys = phys_device;
-            device->pci = dev;
+            device->net.dev.bus_data = (struct cdi_bus_data*) dev;
             cdi_list_push(driver.drv.devices, device);
         } else {
             cdi_pci_device_destroy(dev);
diff --git a/include/cdi.h b/include/cdi.h
index b09bcff..a0e1826 100644
--- a/include/cdi.h
+++ b/include/cdi.h
@@ -33,9 +33,16 @@ typedef enum {
 } cdi_device_type_t;
 
 struct cdi_driver;
+struct cdi_device;
+
+struct cdi_bus_data {
+    cdi_device_type_t   bus_type;
+};
+
 struct cdi_device {
-    const char*         name;
-    struct cdi_driver*  driver;
+    const char*             name;
+    struct cdi_driver*      driver;
+    struct cdi_bus_data*    bus_data;
 
     // tyndur-spezifisch
     void*               backdev;
diff --git a/include/cdi/pci.h b/include/cdi/pci.h
index 31c1878..1192332 100644
--- a/include/cdi/pci.h
+++ b/include/cdi/pci.h
@@ -18,6 +18,8 @@
 #include "cdi/lists.h"
 
 struct cdi_pci_device {
+    struct cdi_bus_data bus_data;
+
     uint16_t    bus;
     uint16_t    dev;
     uint16_t    function;
diff --git a/ne2k/include/ne2k.h b/ne2k/include/ne2k.h
index 6e4125b..2a86897 100644
--- a/ne2k/include/ne2k.h
+++ b/ne2k/include/ne2k.h
@@ -33,7 +33,6 @@
 
 #include "cdi.h"
 #include "cdi/net.h"
-#include "cdi/pci.h"
 
 #define NE_CMD      0
 #define NE_PSTART   1
@@ -84,7 +83,6 @@ typedef struct {
 
 struct ne2k_device {
     struct cdi_net_device       net;
-    struct cdi_pci_device*      pci;
 
     void*                       phys;
     uint16_t                    port_base;
diff --git a/ne2k/main.c b/ne2k/main.c
index 229bccb..6f2448b 100644
--- a/ne2k/main.c
+++ b/ne2k/main.c
@@ -60,7 +60,7 @@ static int ne2k_driver_init(void)
             memset(device, 0, sizeof(*device));
 
             device->phys = phys_device;
-            device->pci = dev;
+            device->net.dev.bus_data = (struct cdi_bus_data*) dev;
             cdi_list_push(ne2k_driver.drv.devices, device);
         } else {
             cdi_pci_device_destroy(dev);
diff --git a/ne2k/ne2k.c b/ne2k/ne2k.c
index a77465b..d7f1e06 100644
--- a/ne2k/ne2k.c
+++ b/ne2k/ne2k.c
@@ -80,14 +80,15 @@ static inline uint32_t read_register_dword(struct ne2k_device* netcard, uint8_t
 void ne2k_init_device(struct cdi_device* device)
 {
     struct ne2k_device* netcard = (struct ne2k_device*) device;
+    struct cdi_pci_device* pci = (struct cdi_pci_device*) device->bus_data;
     netcard->net.send_packet = ne2k_send_packet;
 
     // PCI-bezogenes Zeug initialisieren
     DEBUG_MSG("Interrupthandler und Ports registrieren");
-    cdi_register_irq(netcard->pci->irq, ne2k_handle_interrupt, device);
-    cdi_pci_alloc_ioports(netcard->pci);
+    cdi_register_irq(pci->irq, ne2k_handle_interrupt, device);
+    cdi_pci_alloc_ioports(pci);
 
-    cdi_list_t reslist = netcard->pci->resources;
+    cdi_list_t reslist = pci->resources;
     struct cdi_pci_resource* res;
     int i;
     for (i = 0; (res = cdi_list_get(reslist, i)); i++) {
diff --git a/pcnet/include/pcnet.h b/pcnet/include/pcnet.h
index 8c8198e..0b55122 100644
--- a/pcnet/include/pcnet.h
+++ b/pcnet/include/pcnet.h
@@ -108,7 +108,6 @@ struct transmit_descriptor{
 
 struct pcnet_device {
     struct cdi_net_device       net;
-    struct cdi_pci_device*      pci;
 
     uint16_t                    port_base;
     struct receive_descriptor   *receive_descriptor;
diff --git a/pcnet/main.c b/pcnet/main.c
index 342ac39..613c162 100644
--- a/pcnet/main.c
+++ b/pcnet/main.c
@@ -61,7 +61,7 @@ static int pcnet_driver_init(void)
 
             memset(device, 0, sizeof(struct pcnet_device));
 
-            device->pci = dev;
+            device->net.dev.bus_data = (struct cdi_bus_data*) dev;
             cdi_list_push(pcnet_driver.drv.devices, device);
         } else {
             cdi_pci_device_destroy(dev);
diff --git a/pcnet/pcnet.c b/pcnet/pcnet.c
index dc671e7..2e29389 100644
--- a/pcnet/pcnet.c
+++ b/pcnet/pcnet.c
@@ -55,15 +55,16 @@ static void pcnet_write_bcr(struct pcnet_device *netcard, size_t bcr, uint16_t v
 void pcnet_init_device(struct cdi_device* device)
 {
     struct pcnet_device* netcard = (struct pcnet_device*) device;
+    struct cdi_pci_device* pci = (struct cdi_pci_device*) device->bus_data;
     netcard->net.send_packet = pcnet_send_packet;
 
     // PCI-bezogenes Zeug initialisieren
     DEBUG_MSG("Interrupthandler und Ports registrieren");
-    cdi_register_irq(netcard->pci->irq, pcnet_handle_interrupt, device);
-    cdi_pci_alloc_ioports(netcard->pci);
+    cdi_register_irq(pci->irq, pcnet_handle_interrupt, device);
+    cdi_pci_alloc_ioports(pci);
 
     // I/O Port raussuchen
-    cdi_list_t reslist = netcard->pci->resources;
+    cdi_list_t reslist = pci->resources;
     struct cdi_pci_resource* res;
     int i;
     for (i = 0; (res = cdi_list_get(reslist, i)); i++) {
@@ -226,6 +227,9 @@ void pcnet_stop(struct pcnet_device *netcard)
 }
 void pcnet_dev_init(struct pcnet_device *netcard, int promiscuous)
 {
+    struct cdi_pci_device* pci =
+        (struct cdi_pci_device*) netcard->net.dev.bus_data;
+
     // Allocate the receive & transmit descriptor buffer
     void *virt_desc_region;
     void *phys_desc_region;
@@ -307,7 +311,7 @@ void pcnet_dev_init(struct pcnet_device *netcard, int promiscuous)
     pcnet_write_csr(netcard, CSR_STATUS, STATUS_INIT | STATUS_INTERRUPT_ENABLE);
     
     // Wait until initialization completed, NOTE: see pcnet_handle_interrupt()
-    int irq = cdi_wait_irq(netcard->pci->irq, 1000);
+    int irq = cdi_wait_irq(pci->irq, 1000);
     if(irq < 0 || netcard->init_wait_for_irq == 1)
         printf("pcnet: waiting for IRQ failed: %d\n", irq);
     
diff --git a/rtl8139/include/rtl8139.h b/rtl8139/include/rtl8139.h
index 859696f..2c9e419 100644
--- a/rtl8139/include/rtl8139.h
+++ b/rtl8139/include/rtl8139.h
@@ -82,7 +82,6 @@ typedef struct {
 
 struct rtl8139_device {
     struct cdi_net_device       net;
-    struct cdi_pci_device*      pci;
 
     void*                       phys;
     uint16_t                    port_base;
diff --git a/rtl8139/main.c b/rtl8139/main.c
index 131c67b..5411238 100644
--- a/rtl8139/main.c
+++ b/rtl8139/main.c
@@ -63,7 +63,7 @@ static int rtl8139_driver_init(void)
             memset(device, 0, sizeof(*device));
 
             device->phys = phys_device;
-            device->pci = dev;
+            device->net.dev.bus_data = (struct cdi_bus_data*) dev;
             cdi_list_push(rtl8139_driver.drv.devices, device);
         } else {
             cdi_pci_device_destroy(dev);
diff --git a/rtl8139/rtl8139.c b/rtl8139/rtl8139.c
index 7b43154..c89e08f 100644
--- a/rtl8139/rtl8139.c
+++ b/rtl8139/rtl8139.c
@@ -78,14 +78,15 @@ static inline uint32_t read_register_dword(struct rtl8139_device* netcard, uint8
 void rtl8139_init_device(struct cdi_device* device)
 {
     struct rtl8139_device* netcard = (struct rtl8139_device*) device;
+    struct cdi_pci_device* pci = (struct cdi_pci_device*) device->bus_data;
     netcard->net.send_packet = rtl8139_send_packet;
 
     // PCI-bezogenes Zeug initialisieren
     DEBUG_MSG("Interrupthandler und Ports registrieren");
-    cdi_register_irq(netcard->pci->irq, rtl8139_handle_interrupt, device);
-    cdi_pci_alloc_ioports(netcard->pci);
+    cdi_register_irq(pci->irq, rtl8139_handle_interrupt, device);
+    cdi_pci_alloc_ioports(pci);
 
-    cdi_list_t reslist = netcard->pci->resources;
+    cdi_list_t reslist = pci->resources;
     struct cdi_pci_resource* res;
     int i;
     for (i = 0; (res = cdi_list_get(reslist, i)); i++) {
diff --git a/sis900/device.c b/sis900/device.c
index 0c95055..d6e68d6 100644
--- a/sis900/device.c
+++ b/sis900/device.c
@@ -184,14 +184,15 @@ static uint64_t get_mac_address(struct sis900_device* device)
 void sis900_init_device(struct cdi_device* device)
 {
     struct sis900_device* netcard = (struct sis900_device*) device;
+    struct cdi_pci_device* pci = (struct cdi_pci_device*) device->bus_data;
     netcard->net.send_packet = sis900_send_packet;
 
     // PCI-bezogenes Zeug initialisieren
-    netcard->revision = netcard->pci->rev_id;
-    cdi_register_irq(netcard->pci->irq, sis900_handle_interrupt, device);
-    cdi_pci_alloc_ioports(netcard->pci);
+    netcard->revision = pci->rev_id;
+    cdi_register_irq(pci->irq, sis900_handle_interrupt, device);
+    cdi_pci_alloc_ioports(pci);
     
-    cdi_list_t reslist = netcard->pci->resources;
+    cdi_list_t reslist = pci->resources;
     struct cdi_pci_resource* res;
     int i;
     for (i = 0; (res = cdi_list_get(reslist, i)); i++) {
@@ -203,7 +204,7 @@ void sis900_init_device(struct cdi_device* device)
     // Karte initialisieren
 #ifdef DEBUG
     printf("sis900: IRQ %d, Ports an %x  Revision:%d\n",
-        netcard->pci->irq, netcard->port_base, netcard->revision);
+        pci->irq, netcard->port_base, netcard->revision);
 
     printf("sis900: Fuehre Reset der Karte durch\n");
 #endif
diff --git a/sis900/device.h b/sis900/device.h
index f96b148..cbb44bf 100644
--- a/sis900/device.h
+++ b/sis900/device.h
@@ -128,7 +128,6 @@ struct sis900_tx_descriptor {
 
 struct sis900_device {
     struct cdi_net_device       net;
-    struct cdi_pci_device*      pci;
 
     void*                       phys;
 
diff --git a/sis900/main.c b/sis900/main.c
index b03511c..f813993 100644
--- a/sis900/main.c
+++ b/sis900/main.c
@@ -65,7 +65,7 @@ static int sis900_driver_init(void)
             memset(device, 0, sizeof(*device));
 
             device->phys = phys_device;
-            device->pci = dev;
+            device->net.dev.bus_data = (struct cdi_bus_data*) dev;
             cdi_list_push(sis900_driver.drv.devices, device);
         } else {
             cdi_pci_device_destroy(dev);
-- 
1.6.0.2