分类: LINUX
2014-10-30 23:17:51
hub的一生是伟大的,是曲折的。Roothub设备在xhci驱动注册的时候创建,在roothub创建之前hub驱动---hub_driver已经被注册。下面是hub_driver的注册流程,流程的最后,调用了hub_driver的成员函数hub_probe。
int usb_hub_init(void)
{
if (usb_register(&hub_driver) < 0) {
printk(KERN_ERR "%s: can't register hub driver\n",usbcore_name);
return -1;
}
khubd_task = kthread_run(hub_thread, NULL, "khubd");
if (!IS_ERR(khubd_task))
return 0;
/* Fall through if kernel_thread failed */
usb_deregister(&hub_driver);
printk(KERN_ERR "%s: can't start khubd\n", usbcore_name);
return -1;
}
usb_register_driver
driver_register(&new_driver->drvwrap.driver) 这里的new_driver就是hub_driver
bus_add_driver
driver_attach
bus_for_each_dev()
Bus_for_each_dev这里传入的参数是usb_bus_type、&new_driver->drvwrap.driver、__driver_attach。在这个函数中会遍历 usb_bus_type这条总线上的所有设备,一一取出来与&new_driver->drvwrap.driver进行匹配,这个匹配函数就是__driver_attach
__driver_attach(dev, drv)
driver_match_device(drv, dev)
usb_device_match
usb_match_id //依次选取hub_driver成员id_tables中的成员依次去match。
usb_match_one_id(interface, id) //匹配上了就返回usb_device_id
driver_probe_device(drv, dev)
really_probe()
usb_probe_interface(dev) //dev是与&hub_driver->drvwrap.drive匹配的device
intf = to_usb_interface(dev);
driver = to_usb_driver(dev->driver)
id = usb_match_id(intf, driver->id_table);
hub_probe(intf , id)
driver_bound(dev)
wake_up(&probe_waitqueue)