0
votes

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?

1

1 Answers

2
votes

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 (f.e. 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.