Linux驱动程序的数据封装
嵌入式Linux
共 3802字,需浏览 8分钟
·
2021-11-15 16:58
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);
代码中增加下面的内容,来追踪of_device_get_match_data执行流程。
#在probe函数中增加获取数据的代码
#of_device_get_match_data()代码流程
也可以通过modinfo来查看ko文件符号信息
删除MODULE_DEVICE_TABLE,modules.alias里是没有设备表信息的。
对于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
评论