TA的每日心情 | 开心 2024-11-20 21:23 |
---|
签到天数: 597 天 连续签到: 1 天 [LV.9]以坛为家II
|
这个是几个重要的数据结构,看看里面有啥东西:
- /* summary-2 */
- module:
- kobject
- (ops)
- class:
- module
- kobject
- (ops)
- device:
- class
- bus_type
- kobject
- device_driver:
- bus_type
- module
- (ops:probe,remove,shutdown,suspend,resume)
复制代码 这是宏定义,解析出来没啥东西,对照链接文件看,知道在哪里,后面看内核,知道怎么找到这些东西的:
- /* MODULE */
- (include/linux/device.h):
- MODULE_LICENSE
- MODULE_AUTHOR
- MODULE_DESCRIPTION
- MODULE_ALIAS
- MODULE_SOFTDEP
- MODULE_FIRMWARE
- MODULE_DEVICE_TABLE
- MODULE_VERSION
-
- /* MODULE_LICENSE */
- (include/linux/device.h):
- #define MODULE_LICENSE(_license) MODULE_INFO(license, _license)
- static char license[128];
- MODULE_LICENSE("GPL v2")=
- MODULE_INFO(license, _license)
-
- #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
- MODULE_LICENSE("GPL v2")=
- MODULE_INFO(license, _license)
- MODULE_LICENSE("GPL v2")=
- __MODULE_INFO(tag, tag, info)
-
- (include/linux/moduleparam.h)
- #define __MODULE_INFO(tag, name, info) \
- static const char __UNIQUE_ID(name)[] \
- __used __attribute__((section(".modinfo"), unused, aligned(1))) \
- = __stringify(tag) "=" info
- MODULE_LICENSE("GPL v2")=
- MODULE_INFO(license, _license)
- MODULE_LICENSE("GPL v2")=
- __MODULE_INFO(tag, tag, info)
- MODULE_LICENSE("GPL v2")=
- static const char __UNIQUE_ID(name)[] __used __attribute__((section(".modinfo"), unused, aligned(1)))
- = __stringify(tag) "=" info
-
- (include/linux/stringify.h)
- #define __stringify_1(x...) #x
- #define __stringify(x...) __stringify_1(x)
- MODULE_LICENSE("GPL v2")=
- license = "GPL v2"
-
- /* MODULE_AUTHOR */
- (include/linux/device.h):
- #define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
- MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>")=
- MODULE_INFO(author, _author)
- author = "Benjamin Tissoires <benjamin.tissoires@gmail.com>"
- /* MODULE_DESCRIPTION */
- (include/linux/device.h):
- #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
- MODULE_DESCRIPTION("Goodix touchscreen driver")=
- MODULE_INFO(description, _description)
- description = "Goodix touchscreen driver"
- /* MODULE_ALIAS */
- (include/linux/device.h):
- #define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias)
- MODULE_ALIAS("abc")=
- MODULE_INFO(alias, _alias)
- alias = "abc"
- /* MODULE_SOFTDEP */
- (include/linux/device.h):
- #define MODULE_SOFTDEP(_softdep) MODULE_INFO(softdep, _softdep)
- MODULE_SOFTDEP("abc")=
- MODULE_INFO(softdep, _softdep)
- softdep = "abc"
-
- /* MODULE_FIRMWARE */
- (include/linux/device.h):
- #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
- MODULE_FIRMWARE("abc")=
- MODULE_INFO(firmware, _firmware)
- firmware = "abc"
-
- /* MODULE_DEVICE_TABLE */
- (include/linux/device.h):
- #define MODULE_DEVICE_TABLE(type, name) \
- extern const typeof(name) __mod_##type##__##name##_device_table \
- __attribute__ ((unused, alias(__stringify(name))))
- MODULE_DEVICE_TABLE(of, goodix_of_match)=
- extern const typeof(name) __mod_##type##__##name##_device_table \
- __attribute__ ((unused, alias(__stringify(name))))
- MODULE_DEVICE_TABLE(of, goodix_of_match)=
- extern const typeof(goodix_of_match) __mod_of__goodix_of_match_device_table \
- __attribute__ ((unused, alias(__stringify(goodix_of_match))))
-
- /* MODULE_VERSION */
- (include/linux/device.h):
- #if defined(MODULE) || !defined(CONFIG_SYSFS)
- #define MODULE_VERSION(_version) MODULE_INFO(version, _version)
- #else
- #define MODULE_VERSION(_version) \
- static struct module_version_attribute ___modver_attr = { \
- .mattr = { \
- .attr = { \
- .name = "version", \
- .mode = S_IRUGO, \
- }, \
- .show = __modver_version_show, \
- }, \
- .module_name = KBUILD_MODNAME, \
- .version = _version, \
- }; \
- static const struct module_version_attribute \
- __used __attribute__ ((__section__ ("__modver"))) \
- * __moduleparam_const __modver_attr = &___modver_attr
- #endif
- MODULE_VERSION("abc") =
- version = "abc"
-
- /* MODULE_VERSION2 */
- MODULE_VERSION("abc") =
- static struct module_version_attribute ___modver_attr = {
- .mattr = {
- .attr = {
- .name = "version",
- .mode = S_IRUGO,
- },
- .show = __modver_version_show,
- },
- .module_name = KBUILD_MODNAME,
- .version = _version,
- };
- static const struct module_version_attribute __used __attribute__ ((__section__ ("__modver")))
- * __moduleparam_const __modver_attr = &___modver_attr
-
- (include/linux/moduleparam.h)
- #define __moduleparam_const const
- MODULE_VERSION("abc") =
- static struct module_version_attribute ___modver_attr = {
- .mattr = {
- .attr = {
- .name = "version",
- .mode = S_IRUGO,
- },
- .show = __modver_version_show,
- },
- .module_name = KBUILD_MODNAME,
- .version = "abc",
- };
- static const struct module_version_attribute __used __attribute__ ((__section__ ("__modver")))
- * const __modver_attr = &___modver_attr
-
-
复制代码 这个是 goodix iic 设备驱动:看看结构,很简单:
- /* goodix 驱动模型分析 */
- (drivers/input/touchscreen/goodix.c:)
- module_i2c_driver(goodix_ts_driver);
- static struct i2c_driver goodix_ts_driver = {
- .probe = goodix_ts_probe,
- .id_table = goodix_ts_id,
- .driver = {
- .name = "Goodix-TS",
- .owner = THIS_MODULE,
- .acpi_match_table = ACPI_PTR(goodix_acpi_match),
- .of_match_table = of_match_ptr(goodix_of_match),
- },
- };
- goodix_ts_probe: 实现
- goodix_ts_id: 实现
- goodix_acpi_match: 实现
- goodix_of_match: 实现
- /* module_i2c_driver */
- (include/linux/i2c.h):
- #define module_i2c_driver(__i2c_driver) \
- module_driver(__i2c_driver, i2c_add_driver, \
- i2c_del_driver)
-
- module_i2c_driver(__i2c_driver)=
- module_driver(__i2c_driver, i2c_add_driver,i2c_del_driver)
- (include/linux/device.h):
- #define module_driver(__driver, __register, __unregister, ...) \
- static int __init __driver##_init(void) \
- { \
- return __register(&(__driver) , ##__VA_ARGS__); \
- } \
- module_init(__driver##_init); \
- static void __exit __driver##_exit(void) \
- { \
- __unregister(&(__driver) , ##__VA_ARGS__); \
- } \
- module_exit(__driver##_exit);
- module_i2c_driver(__i2c_driver)=
- module_driver(__i2c_driver, i2c_add_driver,i2c_del_driver)
- module_i2c_driver(__i2c_driver)=
- static int __init __driver##_init(void)
- {
- return __register(&(__driver) , ##__VA_ARGS__);
- }
- module_init(__driver##_init);
- static void __exit __driver##_exit(void)
- {
- __unregister(&(__driver) , ##__VA_ARGS__);
- }
- module_exit(__driver##_exit);
- /* struct i2c_driver */
- (include/linux/i2c.h:)
- struct i2c_driver {
- unsigned int class;
- /* Notifies the driver that a new bus has appeared. You should avoid
- * using this, it will be removed in a near future.
- */
- int (*attach_adapter)(struct i2c_adapter *) __deprecated;
- /* Standard driver model interfaces */
- int (*probe)(struct i2c_client *, const struct i2c_device_id *);
- int (*remove)(struct i2c_client *);
- /* driver model interfaces that don't relate to enumeration */
- void (*shutdown)(struct i2c_client *);
- /* Alert callback, for example for the SMBus alert protocol.
- * The format and meaning of the data value depends on the protocol.
- * For the SMBus alert protocol, there is a single bit of data passed
- * as the alert response's low bit ("event flag").
- */
- void (*alert)(struct i2c_client *, unsigned int data);
- /* a ioctl like command that can be used to perform specific functions
- * with the device.
- */
- int (*command)(struct i2c_client *client, unsigned int cmd, void *arg);
- struct device_driver driver;
- const struct i2c_device_id *id_table;
- /* Device detection callback for automatic device creation */
- int (*detect)(struct i2c_client *, struct i2c_board_info *);
- const unsigned short *address_list;
- struct list_head clients;
- };
- /* struct i2c_device_id */
- (include/linux/mod_devicetable.h)
- struct i2c_device_id {
- char name[I2C_NAME_SIZE];
- kernel_ulong_t driver_data; /* Data private to the driver */
- };
复制代码
|
评分
-
查看全部评分
|