简体   繁体   English

linux如何识别需要加载的输入驱动程序?

[英]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. 我一直在研究输入的GNU / Linux驱动程序,例如usb鼠标驱动程序 ,我想我知道它们如何交互,但是我不了解内核如何识别一种设备类型并为此加载驱动程序。 I've looked through Linux Device Drivers diagonally, but haven't found anything about this matter. 我对角地看过Linux设备驱动程序 ,但没有发现任何有关此问题的信息。

Any advice about what should I read to understand this process? 关于应该阅读什么以了解此过程的任何建议?

Background: kernel sends what is called uevents using kobject_uevent_env function. 背景:内核使用kobject_uevent_env函数发送称为uevents的事件。 This uevents are read by udev daemon from netlink socket (earlier versions used hotplug). udev守护程序从netlink套接字(早期版本使用热插拔)读取此uevents。 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). 在开始之前,udev从/etc/udev/rules.d/预加载规则,该规则包含有关对内核中的适当uevent进行响应需要执行哪些操作的信息(例如insmod模块)。

Now about what you have asked. 现在,关于您的要求。 Typically what is shipped with uevent message is a MODALIAS, it could look like this: 通常,uevent消息附带的是MODALIAS,看起来可能像这样:

MODALIAS = usb:v046DpC03Ed2000dc00dsc00dp00ic03isc01ip02

The USB device stores vendor id and device id, they are used, also, when MODALIAS is constructed. USB设备存储供应商ID和设备ID,在构造MODALIAS时也会使用它们。 The kernel device drivers, which could be loaded dynamically (.ko files) also store the device identificators, this driver could work with. 可以动态加载的内核设备驱动程序(.ko文件)也存储该驱动程序可以使用的设备标识符。 The driver could announce that it works with appropriate device/vendor id using MODULE_DEVICE_TABLE macro. 驱动程序可以使用MODULE_DEVICE_TABLE宏宣布它可以与适当的设备/供应商ID一起使用。 So that is how the relationship between device and dynamic module is established. 这样便可以建立设备与动态模块之间的关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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