MODULE_DEVICE_TABLE【转】

简介:

转自:http://blog.csdn.net/tangkegagalikaiwu/article/details/8444249

This pci_device_id structure needs to be exported to user space to allow the hotplug and module loading systems know what module works with what hardware devices. The macroMODULE_DEVICE_TABLE accomplishes this. An example is:

MODULE_DEVICE_TABLE(pci, i810_ids);

 

This statement creates a local variable called _ _mod_pci_device_table that points to the list ofstructpci_device_id. Later in the kernel build process, the depmod program searches all modules for the symbol _ _mod_pci_device_table. If that symbol is found, it pulls the data out of the module and adds it to the file/lib/modules/KERNEL_VERSION/modules.pcimap. After depmod completes, all PCI devices that are supported by modules in the kernel are listed, along with their module names, in that file. When the kernel tells the hotplug system that a new PCI device has been found, the hotplug system uses the modules.pcimap file to find the proper driver to load.

 

 

 

/* Define these values to match your devices */ 

#define USB_SKEL_VENDOR_ID  0xfff0 
#define USB_SKEL_PRODUCT_ID 0xfff0 
/* table of devices that work with this driver */ 
static struct usb_device_id skel_table [] = { 
     { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) }, 
     { }                    /* Terminating entry */ 
}; 
MODULE_DEVICE_TABLE (usb, skel_table); 

    MODULE_DEVICE_TABLE的第一个参数是设备的类型,如果是USB设备,那自然是usb(如果是PCI设备,那将是pci,这两个子系统用同一个宏来注册所支持的设备。这涉及PCI设备的驱动了,在此先不深究)。后面一个参数是设备表,这个设备表的最后一个元素是空的,用于标识结束。代码定义了USB_SKEL_VENDOR_ID是0xfff0,USB_SKEL_PRODUCT_ID是0xfff0,也就是说,当有一个设备接到集线器时,usb子系统就会检查这个设备的vendor ID和product ID,如果它们的值是0xfff0时,那么子系统就会调用这个skeleton模块作为设备的驱动。

 

如果有几个驱动文件同时调用了MODULE_DEVICE_TABLE(pci,***),那么hotplug调用哪个哪个驱动?是不是就是调用该宏的本模块,本module,本驱动。应该是的,看上面红色字部分  along with their module names

类似的有:

 

    1. MODULE_LICENSE("许可证");  
    2. MODULE_AUTHOR("模块作者");  
    3. MODULE_DESCRIPTION("模块用途描述");  
    4. MODULE_VERSION("代码修订号");  
    5. MODULE_ALIAS("模块的别名");  
    6. MODULE_DEVICE_TABLE("模块支持的设备")










本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/sky-heaven/p/5063527.html,如需转载请自行联系原作者


相关文章
|
4月前
ts中interface和type的区别
ts中interface和type的区别
176 21
|
5月前
|
Python
module 'numpy' has no attribute 'int'.
module 'numpy' has no attribute 'int'.
180 0
Warning: To load an ES module, set “type“: “module“ in the package.json or use the .mjs extension.
Warning: To load an ES module, set “type“: “module“ in the package.json or use the .mjs extension.
|
8月前
|
JavaScript
TS中 type和interface的区别
TS中 type和interface的区别
1130 0
|
8月前
|
JavaScript 前端开发 索引
TS - interface和type的区别
TS - interface和type的区别
100 0
|
Linux
函数__module_address()
函数__module_address()
138 0
|
PyTorch Linux 算法框架/工具
AttributeError: cannot assign module before Module.__init__() call
AttributeError: cannot assign module before Module.__init__() call
|
算法框架/工具 Windows
|
机器学习/深度学习 计算机视觉
成功解决This module was deprecated in version 0.18 in favor of the model_selection module into which all
成功解决This module was deprecated in version 0.18 in favor of the model_selection module into which all
|
物联网 测试技术 索引
[20180609]Wrong Results with IOT, Added Column and Secondary Index2.txt
[20180609]Wrong Results with IOT, Added Column and Secondary Index2.txt --//链接:http://db-oriented.
1151 0