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("模块支持的设备")
上一篇:poj2688


下一篇:python3 练手实例1 计算三角形周长和面积