powerpc+sparc/vio: Modernize driver registration

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>
This commit is contained in:
Benjamin Herrenschmidt 2012-03-26 19:06:30 +00:00
parent 1d9a473150
commit cb52d8970e
13 changed files with 44 additions and 48 deletions

View File

@ -69,6 +69,7 @@ struct vio_dev {
}; };
struct vio_driver { struct vio_driver {
const char *name;
const struct vio_device_id *id_table; const struct vio_device_id *id_table;
int (*probe)(struct vio_dev *dev, const struct vio_device_id *id); int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
int (*remove)(struct vio_dev *dev); int (*remove)(struct vio_dev *dev);
@ -76,10 +77,17 @@ struct vio_driver {
* be loaded in a CMO environment if it uses DMA. * be loaded in a CMO environment if it uses DMA.
*/ */
unsigned long (*get_desired_dma)(struct vio_dev *dev); unsigned long (*get_desired_dma)(struct vio_dev *dev);
const struct dev_pm_ops *pm;
struct device_driver driver; 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 void vio_unregister_driver(struct vio_driver *drv);
extern int vio_cmo_entitlement_update(size_t); extern int vio_cmo_entitlement_update(size_t);

View File

@ -1159,17 +1159,21 @@ static int vio_bus_remove(struct device *dev)
* vio_register_driver: - Register a new vio driver * vio_register_driver: - Register a new vio driver
* @drv: The vio_driver structure to be registered. * @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__, pr_debug("%s: driver %s registering\n", __func__, viodrv->name);
viodrv->driver.name);
/* fill in 'struct driver' fields */ /* fill in 'struct driver' fields */
viodrv->driver.name = viodrv->name;
viodrv->driver.pm = viodrv->pm;
viodrv->driver.bus = &vio_bus_type; viodrv->driver.bus = &vio_bus_type;
viodrv->driver.owner = owner;
viodrv->driver.mod_name = mod_name;
return driver_register(&viodrv->driver); return driver_register(&viodrv->driver);
} }
EXPORT_SYMBOL(vio_register_driver); EXPORT_SYMBOL(__vio_register_driver);
/** /**
* vio_unregister_driver - Remove registration of vio driver. * vio_unregister_driver - Remove registration of vio driver.

View File

@ -284,6 +284,7 @@ struct vio_dev {
}; };
struct vio_driver { struct vio_driver {
const char *name;
struct list_head node; struct list_head node;
const struct vio_device_id *id_table; const struct vio_device_id *id_table;
int (*probe)(struct vio_dev *dev, const struct vio_device_id *id); 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); \ vio->vdev->channel_id, ## a); \
} while (0) } 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); extern void vio_unregister_driver(struct vio_driver *drv);
static inline struct vio_driver *to_vio_driver(struct device_driver *drv) static inline struct vio_driver *to_vio_driver(struct device_driver *drv)

View File

@ -1244,10 +1244,7 @@ static struct vio_driver ds_driver = {
.id_table = ds_match, .id_table = ds_match,
.probe = ds_probe, .probe = ds_probe,
.remove = ds_remove, .remove = ds_remove,
.driver = { .name = "ds",
.name = "ds",
.owner = THIS_MODULE,
}
}; };
static int __init ds_init(void) static int __init ds_init(void)

View File

@ -119,13 +119,17 @@ static struct bus_type vio_bus_type = {
.remove = vio_device_remove, .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.bus = &vio_bus_type;
viodrv->driver.name = viodrv->name;
viodrv->driver.owner = owner;
viodrv->driver.mod_name = mod_name;
return driver_register(&viodrv->driver); return driver_register(&viodrv->driver);
} }
EXPORT_SYMBOL(vio_register_driver); EXPORT_SYMBOL(__vio_register_driver);
void vio_unregister_driver(struct vio_driver *viodrv) void vio_unregister_driver(struct vio_driver *viodrv)
{ {

View File

@ -839,10 +839,7 @@ static struct vio_driver vdc_port_driver = {
.id_table = vdc_port_match, .id_table = vdc_port_match,
.probe = vdc_port_probe, .probe = vdc_port_probe,
.remove = vdc_port_remove, .remove = vdc_port_remove,
.driver = { .name = "vdc_port",
.name = "vdc_port",
.owner = THIS_MODULE,
}
}; };
static int __init vdc_init(void) static int __init vdc_init(void)

View File

@ -1616,11 +1616,8 @@ static struct vio_driver ibmveth_driver = {
.probe = ibmveth_probe, .probe = ibmveth_probe,
.remove = ibmveth_remove, .remove = ibmveth_remove,
.get_desired_dma = ibmveth_get_desired_dma, .get_desired_dma = ibmveth_get_desired_dma,
.driver = { .name = ibmveth_driver_name,
.name = ibmveth_driver_name, .pm = &ibmveth_pm_ops,
.owner = THIS_MODULE,
.pm = &ibmveth_pm_ops,
}
}; };
static int __init ibmveth_module_init(void) static int __init ibmveth_module_init(void)

View File

@ -1259,10 +1259,7 @@ static struct vio_driver vnet_port_driver = {
.id_table = vnet_port_match, .id_table = vnet_port_match,
.probe = vnet_port_probe, .probe = vnet_port_probe,
.remove = vnet_port_remove, .remove = vnet_port_remove,
.driver = { .name = "vnet_port",
.name = "vnet_port",
.owner = THIS_MODULE,
}
}; };
static int __init vnet_init(void) static int __init vnet_init(void)

View File

@ -4890,11 +4890,8 @@ static struct vio_driver ibmvfc_driver = {
.probe = ibmvfc_probe, .probe = ibmvfc_probe,
.remove = ibmvfc_remove, .remove = ibmvfc_remove,
.get_desired_dma = ibmvfc_get_desired_dma, .get_desired_dma = ibmvfc_get_desired_dma,
.driver = { .name = IBMVFC_NAME,
.name = IBMVFC_NAME, .pm = &ibmvfc_pm_ops,
.owner = THIS_MODULE,
.pm = &ibmvfc_pm_ops,
}
}; };
static struct fc_function_template ibmvfc_transport_functions = { static struct fc_function_template ibmvfc_transport_functions = {

View File

@ -2061,11 +2061,8 @@ static struct vio_driver ibmvscsi_driver = {
.probe = ibmvscsi_probe, .probe = ibmvscsi_probe,
.remove = ibmvscsi_remove, .remove = ibmvscsi_remove,
.get_desired_dma = ibmvscsi_get_desired_dma, .get_desired_dma = ibmvscsi_get_desired_dma,
.driver = { .name = "ibmvscsi",
.name = "ibmvscsi", .pm = &ibmvscsi_pm_ops,
.owner = THIS_MODULE,
.pm = &ibmvscsi_pm_ops,
}
}; };
static struct srp_function_template ibmvscsi_transport_functions = { static struct srp_function_template ibmvscsi_transport_functions = {

View File

@ -918,10 +918,7 @@ static struct vio_driver ibmvstgt_driver = {
.id_table = ibmvstgt_device_table, .id_table = ibmvstgt_device_table,
.probe = ibmvstgt_probe, .probe = ibmvstgt_probe,
.remove = ibmvstgt_remove, .remove = ibmvstgt_remove,
.driver = { .name = "ibmvscsis",
.name = "ibmvscsis",
.owner = THIS_MODULE,
}
}; };
static int get_system_info(void) static int get_system_info(void)

View File

@ -310,11 +310,8 @@ static int __devexit hvc_vio_remove(struct vio_dev *vdev)
static struct vio_driver hvc_vio_driver = { static struct vio_driver hvc_vio_driver = {
.id_table = hvc_driver_table, .id_table = hvc_driver_table,
.probe = hvc_vio_probe, .probe = hvc_vio_probe,
.remove = __devexit_p(hvc_vio_remove), .remove = hvc_vio_remove,
.driver = { .name = hvc_driver_name,
.name = hvc_driver_name,
.owner = THIS_MODULE,
}
}; };
static int __init hvc_vio_init(void) static int __init hvc_vio_init(void)

View File

@ -879,10 +879,7 @@ static struct vio_driver hvcs_vio_driver = {
.id_table = hvcs_driver_table, .id_table = hvcs_driver_table,
.probe = hvcs_probe, .probe = hvcs_probe,
.remove = __devexit_p(hvcs_remove), .remove = __devexit_p(hvcs_remove),
.driver = { .name = hvcs_driver_name,
.name = hvcs_driver_name,
.owner = THIS_MODULE,
}
}; };
/* Only called from hvcs_get_pi please */ /* Only called from hvcs_get_pi please */