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

[cdi-devel] [PATCH 2/4] Use the CDI_DRIVER macro



* cdi: Initialize driver structures statically instead of using init
  functions that set the values
+ cdi: Add a CDI_DRIVER definition to each driver

Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 ata/main.c     |   48 +++++++++++++++++++++++++++++-------------------
 e1000/main.c   |   26 ++++++++++++++++----------
 ext2/main.c    |   24 ++++++++++++++++--------
 floppy/main.c  |   30 ++++++++++++++++++------------
 iso9660/main.c |   23 ++++++++++++++++-------
 ne2k/main.c    |   31 +++++++++++++++++++------------
 pcnet/main.c   |   31 +++++++++++++++++++------------
 ramdisk/main.c |   24 ++++++++++++++++--------
 rtl8139/main.c |   28 +++++++++++++++++-----------
 serial/main.c  |   24 ++++++++++++++++--------
 sis900/main.c  |   38 ++++++++++++++++++++++----------------
 11 files changed, 204 insertions(+), 123 deletions(-)

diff --git a/ata/main.c b/ata/main.c
index d5200c2..e7fec85 100644
--- a/ata/main.c
+++ b/ata/main.c
@@ -37,10 +37,11 @@
 
 #include "device.h"
 
+#define DRIVER_STORAGE_NAME "ata"
+#define DRIVER_SCSI_NAME "atapi"
+
 static struct cdi_storage_driver driver_storage;
 static struct cdi_scsi_driver driver_scsi;
-static const char* driver_storage_name = "ata";
-static const char* driver_scsi_name = "atapi";
 static cdi_list_t controller_list = NULL;
 
 static void ata_driver_init(int argc, char* argv[]);
@@ -78,23 +79,7 @@ static void ata_driver_init(int argc, char* argv[])
     // Konstruktor der Vaterklasse
     cdi_storage_driver_init((struct cdi_storage_driver*) &driver_storage);
     cdi_scsi_driver_init((struct cdi_scsi_driver*) &driver_scsi);
-    
-    // Namen setzen
-    driver_storage.drv.name = driver_storage_name;
-    driver_scsi.drv.name = driver_scsi_name;
-
-    // Funktionspointer initialisieren
-    driver_storage.drv.destroy          = ata_driver_destroy;
-    driver_storage.drv.init_device      = ata_init_device;
-    driver_storage.drv.remove_device    = ata_remove_device;
-    driver_storage.read_blocks          = ata_read_blocks;
-    driver_storage.write_blocks         = ata_write_blocks;
-
-    driver_scsi.drv.destroy             = atapi_driver_destroy;
-    driver_scsi.drv.init_device         = atapi_init_device;
-    driver_scsi.drv.remove_device       = atapi_remove_device;
-    driver_scsi.request                 = atapi_request;
-    
+
     // Liste mit Controllern initialisieren
     controller_list = cdi_list_create();
 
@@ -180,3 +165,28 @@ static void atapi_driver_destroy(struct cdi_driver* driver)
 {
     cdi_scsi_driver_destroy((struct cdi_scsi_driver*) driver);
 }
+
+
+static struct cdi_storage_driver driver_storage = {
+    .drv = {
+        .name           = DRIVER_STORAGE_NAME,
+        .destroy        = ata_driver_destroy,
+        .init_device    = ata_init_device,
+        .remove_device  = ata_remove_device,
+    },
+    .read_blocks        = ata_read_blocks,
+    .write_blocks       = ata_write_blocks,
+};
+
+static struct cdi_scsi_driver driver_scsi = {
+    .drv = {
+        .name           = DRIVER_SCSI_NAME,
+        .destroy        = atapi_driver_destroy,
+        .init_device    = atapi_init_device,
+        .remove_device  = atapi_remove_device,
+    },
+    .request            = atapi_request,
+};
+
+CDI_DRIVER(DRIVER_STORAGE_NAME, driver_storage)
+CDI_DRIVER(DRIVER_SCSI_NAME, driver_scsi)
diff --git a/e1000/main.c b/e1000/main.c
index a96e055..3affced 100644
--- a/e1000/main.c
+++ b/e1000/main.c
@@ -37,13 +37,13 @@
 
 #include "device.h"
 
+#define DRIVER_NAME "e1000"
+
 struct e1000_driver {
     struct cdi_net_driver net;
 };
 
 static struct e1000_driver driver;
-static const char* driver_name = "e1000";
-
 static void e1000_driver_init(void);
 static void e1000_driver_destroy(struct cdi_driver* driver);
 
@@ -71,14 +71,6 @@ static void e1000_driver_init()
     // Konstruktor der Vaterklasse
     cdi_net_driver_init((struct cdi_net_driver*) &driver);
 
-    // Namen setzen
-    driver.net.drv.name = driver_name;
-
-    // Funktionspointer initialisieren
-    driver.net.drv.destroy         = e1000_driver_destroy;
-    driver.net.drv.init_device     = e1000_init_device;
-    driver.net.drv.remove_device   = e1000_remove_device;
-
     // Passende PCI-Geraete suchen
     cdi_list_t pci_devices = cdi_list_create();
     cdi_pci_get_all_devices(pci_devices);
@@ -117,3 +109,17 @@ static void e1000_driver_destroy(struct cdi_driver* driver)
 
     // TODO Alle Karten deinitialisieren
 }
+
+
+static struct e1000_driver driver = {
+    .net =  {
+        .drv = {
+            .name           = DRIVER_NAME,
+            .destroy        = e1000_driver_destroy,
+            .init_device    = e1000_init_device,
+            .remove_device  = e1000_remove_device,
+        },
+    },
+};
+
+CDI_DRIVER(DRIVER_NAME, driver)
diff --git a/ext2/main.c b/ext2/main.c
index acbe6db..ae0c094 100644
--- a/ext2/main.c
+++ b/ext2/main.c
@@ -41,13 +41,13 @@
 
 #include "ext2_cdi.h"
 
+#define DRIVER_NAME "ext2"
+
 struct ext2_driver {
     struct cdi_fs_driver fs;
 };
 
 static struct ext2_driver ext2_driver;
-static const char* driver_name = "ext2";
-
 static int ext2_driver_init(struct ext2_driver* driver);
 static void ext2_driver_destroy(struct cdi_driver* driver);
 
@@ -77,12 +77,6 @@ static int ext2_driver_init(struct ext2_driver* driver)
     // Konstruktor der Vaterklasse
     cdi_fs_driver_init((struct cdi_fs_driver*) driver);
 
-    // Namen setzen
-    driver->fs.drv.name = driver_name;
-    driver->fs.fs_init = ext2_fs_init;
-    driver->fs.fs_destroy = ext2_fs_destroy;
-
-    driver->fs.drv.destroy = ext2_driver_destroy;
     return 0;
 }
 
@@ -93,3 +87,17 @@ static void ext2_driver_destroy(struct cdi_driver* driver)
 {
     cdi_fs_driver_destroy((struct cdi_fs_driver*) driver);
 }
+
+
+static struct ext2_driver ext2_driver = {
+    .fs = {
+        .drv = {
+            .name       = DRIVER_NAME,
+            .destroy    = ext2_driver_destroy,
+        },
+        .fs_init        = ext2_fs_init,
+        .fs_destroy     = ext2_fs_destroy,
+    },
+};
+
+CDI_DRIVER(DRIVER_NAME, ext2_driver)
diff --git a/floppy/main.c b/floppy/main.c
index 8ecd8cd..1f44ed6 100644
--- a/floppy/main.c
+++ b/floppy/main.c
@@ -35,6 +35,8 @@
 
 #include "device.h"
 
+#define DRIVER_NAME "floppy"
+
 struct floppy_driver {
     struct cdi_storage_driver storage;
 };
@@ -45,8 +47,6 @@ static struct floppy_controller floppy_controller = {
     .use_dma = 1
 };
 
-static const char* driver_name = "floppy";
-
 static int floppy_driver_init(struct floppy_driver* driver);
 static void floppy_driver_destroy(struct cdi_driver* driver);
 
@@ -79,16 +79,6 @@ static int floppy_driver_init(struct floppy_driver* driver)
     // Konstruktor der Vaterklasse
     cdi_storage_driver_init((struct cdi_storage_driver*) driver);
     
-    // Namen setzen
-    driver->storage.drv.name = driver_name;
-
-    // Funktionspointer initialisieren
-    driver->storage.drv.destroy         = floppy_driver_destroy;
-    driver->storage.drv.init_device     = floppy_init_device;
-    driver->storage.drv.remove_device   = floppy_remove_device;
-    driver->storage.read_blocks         = floppy_read_blocks; 
-    driver->storage.write_blocks        = floppy_write_blocks;
-    
     // Geraete erstellen (TODO: Was wenn eines oder beide nicht vorhanden
     // sind?)
     for (i = 0; i < 2; i++) {
@@ -131,3 +121,19 @@ static void floppy_driver_destroy(struct cdi_driver* driver)
 
     // TODO Alle Laufwerke deinitialisieren
 }
+
+
+static struct floppy_driver floppy_driver = {
+    .storage = {
+        .drv = {
+            .name           = DRIVER_NAME,
+            .destroy        = floppy_driver_destroy,
+            .init_device    = floppy_init_device,
+            .remove_device  = floppy_remove_device,
+        },
+        .read_blocks        = floppy_read_blocks,
+        .write_blocks       = floppy_write_blocks,
+    },
+};
+
+CDI_DRIVER(DRIVER_NAME, floppy_driver)
diff --git a/iso9660/main.c b/iso9660/main.c
index 3d21a96..01424d9 100644
--- a/iso9660/main.c
+++ b/iso9660/main.c
@@ -24,13 +24,13 @@
 #include "iso9660_cdi.h"
 #include "iso9660def.h"
 
+#define DRIVER_NAME "iso9660"
+
 struct iso9660_driver {
   struct cdi_fs_driver drv;
 };
 
 static struct iso9660_driver iso9660_driver;
-static const char* driver_name = "iso9660";
-
 static int iso9660_driver_init(struct iso9660_driver *driver);
 static void iso9660_driver_destroy(struct cdi_driver* driver);
 
@@ -57,11 +57,6 @@ static int iso9660_driver_init(struct iso9660_driver *driver) {
     // Konstruktor der Vaterklasse
     cdi_fs_driver_init((struct cdi_fs_driver*)driver);
 
-    // Namen setzen
-    driver->drv.drv.name = driver_name;
-    driver->drv.fs_init = iso9660_fs_init;
-    driver->drv.fs_destroy = iso9660_fs_destroy;
-    driver->drv.drv.destroy = iso9660_driver_destroy;
     return 0;
 }
 
@@ -91,3 +86,17 @@ int debug(const char *fmt,...) {
   return 0;
 #endif
 }
+
+
+static struct iso9660_driver iso9660_driver = {
+    .drv =  {
+        .drv = {
+            .name           = DRIVER_NAME,
+            .destroy        = iso9660_driver_destroy,
+        },
+        .fs_init            = iso9660_fs_init,
+        .fs_destroy         = iso9660_fs_destroy,
+    },
+};
+
+CDI_DRIVER(DRIVER_NAME, iso9660_driver)
diff --git a/ne2k/main.c b/ne2k/main.c
index 3a8a87e..170157a 100644
--- a/ne2k/main.c
+++ b/ne2k/main.c
@@ -35,12 +35,13 @@
 
 #include "ne2k.h"
 
-static struct {
-    struct cdi_net_driver net;
-} driver;
+#define DRIVER_NAME "ne2k"
 
-static const char* driver_name = "ne2k";
+struct ne2k_driver {
+    struct cdi_net_driver net;
+};
 
+static struct ne2k_driver driver;
 static int ne2k_driver_init(int argc, char* argv[]);
 static void ne2k_driver_destroy(struct cdi_driver* driver);
 
@@ -65,14 +66,6 @@ static int ne2k_driver_init(int argc, char* argv[])
     // Konstruktor der Vaterklasse
     cdi_net_driver_init((struct cdi_net_driver*) &driver);
 
-    // Namen setzen
-    driver.net.drv.name = driver_name;
-
-    // Funktionspointer initialisieren
-    driver.net.drv.destroy         = ne2k_driver_destroy;
-    driver.net.drv.init_device     = ne2k_init_device;
-    driver.net.drv.remove_device   = ne2k_remove_device;
-
     // Passende PCI-Geraete suchen
     cdi_list_t pci_devices = cdi_list_create();
     cdi_pci_get_all_devices(pci_devices);
@@ -110,3 +103,17 @@ static void ne2k_driver_destroy(struct cdi_driver* driver)
 
     // TODO Alle Karten deinitialisieren
 }
+
+
+static struct ne2k_driver ne2k_driver = {
+    .net =  {
+        .drv = {
+            .name           = DRIVER_NAME,
+            .destroy        = ne2k_driver_destroy,
+            .init_device    = ne2k_init_device,
+            .remove_device  = ne2k_remove_device,
+        },
+    },
+};
+
+CDI_DRIVER(DRIVER_NAME, ne2k_driver)
diff --git a/pcnet/main.c b/pcnet/main.c
index c37454a..b6bf7e4 100644
--- a/pcnet/main.c
+++ b/pcnet/main.c
@@ -36,16 +36,17 @@
 
 #include "pcnet.h"
 
+#define DRIVER_NAME "pcnet"
+
 struct module_options {
     uint32_t ip;
 };
 
-static struct {
+struct pcnet_driver {
     struct cdi_net_driver net;
-} driver;
-
-static const char* driver_name = "pcnet";
+};
 
+static struct pcnet_driver driver;
 static int pcnet_driver_init(int argc, char* argv[]);
 static void pcnet_driver_destroy(struct cdi_driver* driver);
 
@@ -73,14 +74,6 @@ static int pcnet_driver_init(int argc, char* argv[])
     // Konstruktor der Vaterklasse
     cdi_net_driver_init((struct cdi_net_driver*) &driver);
 
-    // Namen setzen
-    driver.net.drv.name = driver_name;
-
-    // Funktionspointer initialisieren
-    driver.net.drv.destroy         = pcnet_driver_destroy;
-    driver.net.drv.init_device     = pcnet_init_device;
-    driver.net.drv.remove_device   = pcnet_remove_device;
-
     // Passende PCI-Geraete suchen
     cdi_list_t pci_devices = cdi_list_create();
     cdi_pci_get_all_devices(pci_devices);
@@ -115,3 +108,17 @@ static void pcnet_driver_destroy(struct cdi_driver* driver)
 
     // TODO Alle Karten deinitialisieren
 }
+
+
+static struct pcnet_driver driver = {
+    .net =  {
+        .drv = {
+            .name           = DRIVER_NAME,
+            .destroy        = pcnet_driver_destroy,
+            .init_device    = pcnet_init_device,
+            .remove_device  = pcnet_remove_device,
+        },
+    },
+};
+
+CDI_DRIVER(DRIVER_NAME, driver)
diff --git a/ramdisk/main.c b/ramdisk/main.c
index 73a7e0c..422cd80 100644
--- a/ramdisk/main.c
+++ b/ramdisk/main.c
@@ -35,13 +35,13 @@
 
 #include "ramdisk_cdi.h"
 
+#define DRIVER_NAME "ramdisk"
+
 struct ramdisk_driver {
     struct cdi_fs_driver fs;
 };
 
 static struct ramdisk_driver ramdisk_driver;
-static const char* driver_name = "ramdisk";
-
 static int ramdisk_driver_init(struct ramdisk_driver* driver);
 static void ramdisk_driver_destroy(struct cdi_driver* driver);
 
@@ -71,12 +71,6 @@ static int ramdisk_driver_init(struct ramdisk_driver* driver)
     // Konstruktor der Vaterklasse
     cdi_fs_driver_init((struct cdi_fs_driver*) driver);
 
-    // Namen setzen
-    driver->fs.drv.name = driver_name;
-    driver->fs.fs_init = ramdisk_fs_init;
-    driver->fs.fs_destroy = ramdisk_fs_destroy;
-
-    driver->fs.drv.destroy = ramdisk_driver_destroy;
     return 0;
 }
 
@@ -87,3 +81,17 @@ static void ramdisk_driver_destroy(struct cdi_driver* driver)
 {
     cdi_fs_driver_destroy((struct cdi_fs_driver*) driver);
 }
+
+
+static struct ramdisk_driver ramdisk_driver = {
+    .fs =  {
+        .drv = {
+            .name           = DRIVER_NAME,
+            .destroy        = ramdisk_driver_destroy,
+        },
+        .fs_init            = ramdisk_fs_init,
+        .fs_destroy         = ramdisk_fs_destroy,
+    },
+};
+
+CDI_DRIVER(DRIVER_NAME, ramdisk_driver)
diff --git a/rtl8139/main.c b/rtl8139/main.c
index 07c1adf..b9d7728 100644
--- a/rtl8139/main.c
+++ b/rtl8139/main.c
@@ -35,16 +35,16 @@
 
 #include "rtl8139.h"
 
+#define DRIVER_NAME "rtl8139"
+
 struct module_options {
     uint32_t ip;
 };
 
-static struct {
+static struct rtl8139_driver {
     struct cdi_net_driver net;
 } driver;
 
-static const char* driver_name = "rtl8139";
-
 static int rtl8139_driver_init(int argc, char* argv[]);
 static void rtl8139_driver_destroy(struct cdi_driver* driver);
 
@@ -72,14 +72,6 @@ static int rtl8139_driver_init(int argc, char* argv[])
     // Konstruktor der Vaterklasse
     cdi_net_driver_init((struct cdi_net_driver*) &driver);
 
-    // Namen setzen
-    driver.net.drv.name = driver_name;
-
-    // Funktionspointer initialisieren
-    driver.net.drv.destroy         = rtl8139_driver_destroy;
-    driver.net.drv.init_device     = rtl8139_init_device;
-    driver.net.drv.remove_device   = rtl8139_remove_device;
-
     // Passende PCI-Geraete suchen
     cdi_list_t pci_devices = cdi_list_create();
     cdi_pci_get_all_devices(pci_devices);
@@ -117,3 +109,17 @@ static void rtl8139_driver_destroy(struct cdi_driver* driver)
 
     // TODO Alle Karten deinitialisieren
 }
+
+
+static struct rtl8139_driver driver = {
+    .net =  {
+        .drv = {
+            .name           = DRIVER_NAME,
+            .destroy        = rtl8139_driver_destroy,
+            .init_device    = rtl8139_init_device,
+            .remove_device  = rtl8139_remove_device,
+        },
+    },
+};
+
+CDI_DRIVER(DRIVER_NAME, driver)
diff --git a/serial/main.c b/serial/main.c
index 2ebc62a..3fd71ba 100644
--- a/serial/main.c
+++ b/serial/main.c
@@ -35,13 +35,13 @@
 
 #include "serial_cdi.h"
 
+#define DRIVER_NAME "serial"
+
 struct serial_driver {
     struct cdi_fs_driver fs;
 };
 
 static struct serial_driver serial_driver;
-static const char* driver_name = "serial";
-
 static int serial_driver_init(struct serial_driver* driver);
 static void serial_driver_destroy(struct cdi_driver* driver);
 
@@ -71,12 +71,6 @@ static int serial_driver_init(struct serial_driver* driver)
     // Konstruktor der Vaterklasse
     cdi_fs_driver_init((struct cdi_fs_driver*) driver);
 
-    // Namen setzen
-    driver->fs.drv.name = driver_name;
-    driver->fs.fs_init = serial_fs_init;
-    driver->fs.fs_destroy = serial_fs_destroy;
-
-    driver->fs.drv.destroy = serial_driver_destroy;
     return 0;
 }
 
@@ -87,3 +81,17 @@ static void serial_driver_destroy(struct cdi_driver* driver)
 {
     cdi_fs_driver_destroy((struct cdi_fs_driver*) driver);
 }
+
+
+static struct serial_driver serial_driver = {
+    .fs = {
+        .drv = {
+            .name       = DRIVER_NAME,
+            .destroy    = serial_driver_destroy,
+        },
+        .fs_init        = serial_fs_init,
+        .fs_destroy     = serial_fs_destroy,
+    },
+};
+
+CDI_DRIVER(DRIVER_NAME, serial_driver)
diff --git a/sis900/main.c b/sis900/main.c
index 550dd0a..0ae47ca 100644
--- a/sis900/main.c
+++ b/sis900/main.c
@@ -37,13 +37,13 @@
 
 #include "device.h"
 
+#define DRIVER_NAME "sis900"
+
 struct sis900_driver {
     struct cdi_net_driver net;
 };
 
-static struct sis900_driver driver;
-static const char* driver_name = "sis900";
-
+static struct sis900_driver sis900_driver;
 static void sis900_driver_init(int argc, char* argv[]);
 static void sis900_driver_destroy(struct cdi_driver* driver);
 
@@ -56,7 +56,7 @@ int init_sis900(int argc, char* argv[])
     cdi_init();
 
     sis900_driver_init(argc, argv);
-    cdi_driver_register((struct cdi_driver*) &driver);
+    cdi_driver_register((struct cdi_driver*) &sis900_driver);
 
     cdi_run_drivers();
 
@@ -69,15 +69,7 @@ int init_sis900(int argc, char* argv[])
 static void sis900_driver_init(int argc, char* argv[])
 {
     // Konstruktor der Vaterklasse
-    cdi_net_driver_init((struct cdi_net_driver*) &driver);
-    
-    // Namen setzen
-    driver.net.drv.name = driver_name;
-
-    // Funktionspointer initialisieren
-    driver.net.drv.destroy         = sis900_driver_destroy;
-    driver.net.drv.init_device     = sis900_init_device;
-    driver.net.drv.remove_device   = sis900_remove_device;
+    cdi_net_driver_init((struct cdi_net_driver*) &sis900_driver);
 
     // Passende PCI-Geraete suchen
     cdi_list_t pci_devices = cdi_list_create();
@@ -96,14 +88,14 @@ static void sis900_driver_init(int argc, char* argv[])
 
             device->phys = phys_device;
             device->pci = dev;
-            cdi_list_push(driver.net.drv.devices, device);
+            cdi_list_push(sis900_driver.net.drv.devices, device);
         } else {
             cdi_pci_device_destroy(dev);
         }
     }
 
-    printf("sis900: %d Karten gefunden.\n", 
-        cdi_list_size(driver.net.drv.devices));
+    printf("sis900: %d Karten gefunden.\n",
+        cdi_list_size(sis900_driver.net.drv.devices));
 
     cdi_list_destroy(pci_devices);
 }
@@ -117,3 +109,17 @@ static void sis900_driver_destroy(struct cdi_driver* driver)
 
     // TODO Alle Karten deinitialisieren
 }
+
+
+static struct sis900_driver sis900_driver = {
+    .net =  {
+        .drv = {
+            .name           = DRIVER_NAME,
+            .destroy        = sis900_driver_destroy,
+            .init_device    = sis900_init_device,
+            .remove_device  = sis900_remove_device,
+        },
+    },
+};
+
+CDI_DRIVER(DRIVER_NAME, sis900_driver)
-- 
1.6.0.2