博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MODULE_DEVICE_TABLE
阅读量:4180 次
发布时间:2019-05-26

本文共 1856 字,大约阅读时间需要 6 分钟。

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 ofstruct pci_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("模块支持的设备")

转载地址:http://tphai.baihongyu.com/

你可能感兴趣的文章
JAVA常用基础类
查看>>
简述Java异常处理
查看>>
简述Java集合框架
查看>>
jQuery+ajax实现省市区(县)下拉框三级联动
查看>>
Spring中的AOP 面向切面编程
查看>>
简述Spring中的JDBC框架
查看>>
MyBatis 动态SQL
查看>>
Spring MVC体系结构和处理请求控制器
查看>>
浏览器内核的整理稿
查看>>
暴力搜索内存空间获得API的线性地址
查看>>
CTF编码
查看>>
万能密码原理和总结
查看>>
缓冲区溢出学习
查看>>
Excel高级使用技巧
查看>>
速算,以后留着教孩子
查看>>
让你变成ps高手
查看>>
在可执行jar中动态载入第三方jar(转贴)
查看>>
考虑体积重量的01背包问题—基于遗传算法
查看>>
K-means 聚类算法
查看>>
带约束的K-means聚类算法
查看>>