简体   繁体   中英

How does linux recognize what input driver it needs to load?

I've been studying input GNU/Linux drivers, for example usb mouse driver , I think I get how they interact with , but I don't understand how kernel recognizes a type of device to load this driver for it. I've looked through Linux Device Drivers diagonally, but haven't found anything about this matter.

Any advice about what should I read to understand this process?

Background: kernel sends what is called uevents using kobject_uevent_env function. This uevents are read by udev daemon from netlink socket (earlier versions used hotplug). Before start, udev preloads rules from /etc/udev/rules.d/ , this rules contain information about what need to be done as reaction to appropriate uevent from kernel (fe insmod a module).

Now about what you have asked. Typically what is shipped with uevent message is a MODALIAS, it could look like this:

MODALIAS = usb:v046DpC03Ed2000dc00dsc00dp00ic03isc01ip02

The USB device stores vendor id and device id, they are used, also, when MODALIAS is constructed. The kernel device drivers, which could be loaded dynamically (.ko files) also store the device identificators, this driver could work with. The driver could announce that it works with appropriate device/vendor id using MODULE_DEVICE_TABLE macro. So that is how the relationship between device and dynamic module is established.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM