现在的位置: 首页 > 综合 > 正文

driver_register

2013年03月28日 ⁄ 综合 ⁄ 共 955字 ⁄ 字号 评论关闭

driver_register 注册设备驱动程序

下面代码是2.6.21内核的driver_register().

/* The one interesting aspect is that we setup @drv->unloaded
-
* as a completion that gets complete when the driver reference
-
* count reaches 0.
-
*/

driver_register() -- 注册设备驱动程序,搜寻驱动drv对应的设备,并与之关联
int driver_register(struct device_driver * drv)
{
    if ((drv->bus->probe && drv->probe) ||
        (drv->bus->remove && drv->remove) ||
        (drv->bus->shutdown && drv->shutdown)) {
        printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods/n", drv->name);
    }
    klist_init(&drv->klist_devices, NULL, NULL);
    init_completion(&drv->unloaded);
    return bus_add_driver(drv);
}

注册设备驱动程序
---------------------------------------------------
    在设备文件上发出的每个系统调用都由内核转化为相应设备驱动程序的对应函数的调用。为了完成这个操作,设备驱动程序必须注册自己。换句话说,注册一个设备驱动程序以为着把它对应的设备文件连接起来。如果设备文件对应的驱动程序以前没有注册,则对该设备文件的访问返回错误码 -ENODEV
    如果设备驱动程序被静态地编译进内核,则它的注册在内核初始化阶段进行。相反,如果驱动程序作为一个内核模块来编译,则它的注册在模块装入时进行。   
    一旦设备驱动程序被注册了,它就和设备文件的主设备号连接在一起,而不是和设备文件的路径连接在一起。这样,对设备文件的任何访问都会激活相应的设备驱动程序,而不用管所这用的路径名

抱歉!评论已关闭.