powerpc+sparc/vio: Modernize driver registration
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>
Mon, 26 Mar 2012 19:06:30 +0000 (19:06 +0000)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Wed, 28 Mar 2012 00:33:24 +0000 (11:33 +1100)
This makes vio_register_driver() get the module owner & name at compile
time like PCI drivers do, and adds a name pointer directly in struct
vio_driver to avoid having to explicitly initialize the embedded
struct device.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: David S. Miller <davem@davemloft.net>
13 files changed:
arch/powerpc/include/asm/vio.h
arch/powerpc/kernel/vio.c
arch/sparc/include/asm/vio.h
arch/sparc/kernel/ds.c
arch/sparc/kernel/vio.c
drivers/block/sunvdc.c
drivers/net/ethernet/ibm/ibmveth.c
drivers/net/ethernet/sun/sunvnet.c
drivers/scsi/ibmvscsi/ibmvfc.c
drivers/scsi/ibmvscsi/ibmvscsi.c
drivers/scsi/ibmvscsi/ibmvstgt.c
drivers/tty/hvc/hvc_vio.c
drivers/tty/hvc/hvcs.c

index 0a290a19594645b41ac386a21576459705756b7a..6bfd5ffe1d4fd287141523e10d1589d89472b636 100644 (file)
@@ -69,6 +69,7 @@ struct vio_dev {
 };
 
 struct vio_driver {
+       const char *name;
        const struct vio_device_id *id_table;
        int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
        int (*remove)(struct vio_dev *dev);
@@ -76,10 +77,17 @@ struct vio_driver {
         * be loaded in a CMO environment if it uses DMA.
         */
        unsigned long (*get_desired_dma)(struct vio_dev *dev);
+       const struct dev_pm_ops *pm;
        struct device_driver driver;
 };
 
-extern int vio_register_driver(struct vio_driver *drv);
+extern int __vio_register_driver(struct vio_driver *drv, struct module *owner,
+                                const char *mod_name);
+/*
+ * vio_register_driver must be a macro so that KBUILD_MODNAME can be expanded
+ */
+#define vio_register_driver(driver)            \
+       __vio_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
 extern void vio_unregister_driver(struct vio_driver *drv);
 
 extern int vio_cmo_entitlement_update(size_t);
index bca3fc427b45fffae821440d8021ac9beb4de7bd..b2f7c8480bf6e853704ba20cb4787db7cb519a91 100644 (file)
@@ -1159,17 +1159,21 @@ static int vio_bus_remove(struct device *dev)
  * vio_register_driver: - Register a new vio driver
  * @drv:       The vio_driver structure to be registered.
  */
-int vio_register_driver(struct vio_driver *viodrv)
+int __vio_register_driver(struct vio_driver *viodrv, struct module *owner,
+                         const char *mod_name)
 {
-       printk(KERN_DEBUG "%s: driver %s registering\n", __func__,
-               viodrv->driver.name);
+       pr_debug("%s: driver %s registering\n", __func__, viodrv->name);
 
        /* fill in 'struct driver' fields */
+       viodrv->driver.name = viodrv->name;
+       viodrv->driver.pm = viodrv->pm;
        viodrv->driver.bus = &vio_bus_type;
+       viodrv->driver.owner = owner;
+       viodrv->driver.mod_name = mod_name;
 
        return driver_register(&viodrv->driver);
 }
-EXPORT_SYMBOL(vio_register_driver);
+EXPORT_SYMBOL(__vio_register_driver);
 
 /**
  * vio_unregister_driver - Remove registration of vio driver.
index 9d83d3bcb494b44e3620f4942934e832035450a5..432afa83886137a89bcd6fa66911922addfa50d3 100644 (file)
@@ -284,6 +284,7 @@ struct vio_dev {
 };
 
 struct vio_driver {
+       const char                      *name;
        struct list_head                node;
        const struct vio_device_id      *id_table;
        int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
@@ -371,7 +372,13 @@ do {       if (vio->debug & VIO_DEBUG_##TYPE) \
                       vio->vdev->channel_id, ## a); \
 } while (0)
 
-extern int vio_register_driver(struct vio_driver *drv);
+extern int __vio_register_driver(struct vio_driver *drv, struct module *owner,
+                                const char *mod_name);
+/*
+ * vio_register_driver must be a macro so that KBUILD_MODNAME can be expanded
+ */
+#define vio_register_driver(driver)            \
+       __vio_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
 extern void vio_unregister_driver(struct vio_driver *drv);
 
 static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
index 381edcd5bc2946471e2c47e4f73a607272d25c09..fea13c7b1aeeddcf206217c935a1b044ae96e215 100644 (file)
@@ -1244,10 +1244,7 @@ static struct vio_driver ds_driver = {
        .id_table       = ds_match,
        .probe          = ds_probe,
        .remove         = ds_remove,
-       .driver         = {
-               .name   = "ds",
-               .owner  = THIS_MODULE,
-       }
+       .name           = "ds",
 };
 
 static int __init ds_init(void)
index f67e28ef598cae92e660d93afb42a4241dc66dc4..5cffdc55f075a7c9229e40e6abfd97c44d211ed2 100644 (file)
@@ -119,13 +119,17 @@ static struct bus_type vio_bus_type = {
        .remove         = vio_device_remove,
 };
 
-int vio_register_driver(struct vio_driver *viodrv)
+int __vio_register_driver(struct vio_driver *viodrv, struct module *owner,
+                       const char *mod_name)
 {
        viodrv->driver.bus = &vio_bus_type;
+       viodrv->driver.name = viodrv->name;
+       viodrv->driver.owner = owner;
+       viodrv->driver.mod_name = mod_name;
 
        return driver_register(&viodrv->driver);
 }
-EXPORT_SYMBOL(vio_register_driver);
+EXPORT_SYMBOL(__vio_register_driver);
 
 void vio_unregister_driver(struct vio_driver *viodrv)
 {
index 48e8fee9f2d4f8aa6bacf4243694a430b53fdae9..9dcf76a10bb64584b2d43bfbcc4d06a735711f43 100644 (file)
@@ -839,10 +839,7 @@ static struct vio_driver vdc_port_driver = {
        .id_table       = vdc_port_match,
        .probe          = vdc_port_probe,
        .remove         = vdc_port_remove,
-       .driver         = {
-               .name   = "vdc_port",
-               .owner  = THIS_MODULE,
-       }
+       .name           = "vdc_port",
 };
 
 static int __init vdc_init(void)
index e877371680a9b1417f53b7b4c73f770b4e6c3d43..9010cea68bc3094a4b9b18b06cae1aa7d9796cd7 100644 (file)
@@ -1616,11 +1616,8 @@ static struct vio_driver ibmveth_driver = {
        .probe          = ibmveth_probe,
        .remove         = ibmveth_remove,
        .get_desired_dma = ibmveth_get_desired_dma,
-       .driver         = {
-               .name   = ibmveth_driver_name,
-               .owner  = THIS_MODULE,
-               .pm = &ibmveth_pm_ops,
-       }
+       .name           = ibmveth_driver_name,
+       .pm             = &ibmveth_pm_ops,
 };
 
 static int __init ibmveth_module_init(void)
index 92a037a8228a3f0c004347442517fe9c2d0c4588..38e3ae9155b7080fc6d0baf5c7b84eadb9f4723d 100644 (file)
@@ -1259,10 +1259,7 @@ static struct vio_driver vnet_port_driver = {
        .id_table       = vnet_port_match,
        .probe          = vnet_port_probe,
        .remove         = vnet_port_remove,
-       .driver         = {
-               .name   = "vnet_port",
-               .owner  = THIS_MODULE,
-       }
+       .name           = "vnet_port",
 };
 
 static int __init vnet_init(void)
index bdfa223a7dbb9e047c278b6414c5135e49a47001..134a0ae85bb7d8d996252879b8dfb5b413f4ac0f 100644 (file)
@@ -4890,11 +4890,8 @@ static struct vio_driver ibmvfc_driver = {
        .probe = ibmvfc_probe,
        .remove = ibmvfc_remove,
        .get_desired_dma = ibmvfc_get_desired_dma,
-       .driver = {
-               .name = IBMVFC_NAME,
-               .owner = THIS_MODULE,
-               .pm = &ibmvfc_pm_ops,
-       }
+       .name = IBMVFC_NAME,
+       .pm = &ibmvfc_pm_ops,
 };
 
 static struct fc_function_template ibmvfc_transport_functions = {
index e984951baeb6834b27d82b26f5afa6dbcc0bf471..3a6c4742951ea4f1e661c4973a48fdd16abb501d 100644 (file)
@@ -2061,11 +2061,8 @@ static struct vio_driver ibmvscsi_driver = {
        .probe = ibmvscsi_probe,
        .remove = ibmvscsi_remove,
        .get_desired_dma = ibmvscsi_get_desired_dma,
-       .driver = {
-               .name = "ibmvscsi",
-               .owner = THIS_MODULE,
-               .pm = &ibmvscsi_pm_ops,
-       }
+       .name = "ibmvscsi",
+       .pm = &ibmvscsi_pm_ops,
 };
 
 static struct srp_function_template ibmvscsi_transport_functions = {
index 2256babe047463fa04621efcf432b0affe80ff71..aa7ed81e92371140738bbe4f8d32559662e9b3d7 100644 (file)
@@ -918,10 +918,7 @@ static struct vio_driver ibmvstgt_driver = {
        .id_table = ibmvstgt_device_table,
        .probe = ibmvstgt_probe,
        .remove = ibmvstgt_remove,
-       .driver = {
-               .name = "ibmvscsis",
-               .owner = THIS_MODULE,
-       }
+       .name = "ibmvscsis",
 };
 
 static int get_system_info(void)
index 3a0d53d6368f2f177afc3fc7528ec27cdbd56027..ee307799271a4d3cd362cb131a58490d0d00f18b 100644 (file)
@@ -310,11 +310,8 @@ static int __devexit hvc_vio_remove(struct vio_dev *vdev)
 static struct vio_driver hvc_vio_driver = {
        .id_table       = hvc_driver_table,
        .probe          = hvc_vio_probe,
-       .remove         = __devexit_p(hvc_vio_remove),
-       .driver         = {
-               .name   = hvc_driver_name,
-               .owner  = THIS_MODULE,
-       }
+       .remove         = hvc_vio_remove,
+       .name           = hvc_driver_name,
 };
 
 static int __init hvc_vio_init(void)
index d23759183b4782485f03db20de7fa57279a41ca7..3436436fe2d7bc7317e8b43cae2dadfd4cad5f72 100644 (file)
@@ -879,10 +879,7 @@ static struct vio_driver hvcs_vio_driver = {
        .id_table       = hvcs_driver_table,
        .probe          = hvcs_probe,
        .remove         = __devexit_p(hvcs_remove),
-       .driver         = {
-               .name   = hvcs_driver_name,
-               .owner  = THIS_MODULE,
-       }
+       .name           = hvcs_driver_name,
 };
 
 /* Only called from hvcs_get_pi please */