Linux驅(qū)動(dòng)程序的數(shù)據(jù)封裝



1struct?of_device_id?{
2????char????name[32];
3????char????type[32];
4????char????compatible[128];
5????const?void?*data;
6};


1const?void?*of_device_get_match_data(
2????const?struct?device?*dev)
3{
4????const?struct?of_device_id?*match;
5
6????match?=?of_match_device(xxx);
7????if?(!match)
8????????return?NULL;
9
10????return?match->data;
11}
12EXPORT_SYMBOL(of_device_get_match_data);
代碼中增加下面的內(nèi)容,來追蹤of_device_get_match_data執(zhí)行流程。

#在probe函數(shù)中增加獲取數(shù)據(jù)的代碼


#of_device_get_match_data()代碼流程



也可以通過modinfo來查看ko文件符號(hào)信息


刪除MODULE_DEVICE_TABLE,modules.alias里是沒有設(shè)備表信息的。

對(duì)于of_device_id而言,name、type、compatible添加的方法:

1struct?usb_device_id?{
2????/*?which?fields?to?match?against??*/
3????__u16???????match_flags;
4
5????/*?Used?for?product?specific?matches;?range?is?inclusive?*/
6????__u16???????idVendor;
7????__u16???????idProduct;
8????__u16???????bcdDevice_lo;
9????__u16???????bcdDevice_hi;
10
11????/*?Used?for?device?class?matches?*/
12????__u8????????bDeviceClass;
13????__u8????????bDeviceSubClass;
14????__u8????????bDeviceProtocol;
15
16????/*?Used?for?interface?class?matches?*/
17????__u8????????bInterfaceClass;
18????__u8????????bInterfaceSubClass;
19????__u8????????bInterfaceProtocol;
20
21????/*?Used?for?vendor-specific?interface?matches?*/
22????__u8????????bInterfaceNumber;
23
24????/*?not?matched?against?*/
25????kernel_ulong_t??driver_info
26????????__attribute__((aligned(sizeof(kernel_ulong_t))));
27};
1struct?pci_device_id?{
2????__u32?vendor,?device;???????/*?Vendor?and?device?ID?or?PCI_ANY_ID*/
3????__u32?subvendor,?subdevice;?/*?Subsystem?ID's?or?PCI_ANY_ID?*/
4????__u32?class,?class_mask;????/*?(class,subclass,prog-if)?triplet?*/
5????kernel_ulong_t?driver_data;?/*?Data?private?to?the?driver?*/
6};





mod_devicetable.h的commit log:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/log/include/linux/mod_devicetable.h
評(píng)論
圖片
表情
