Linux Kernel设备驱动模型之 struct device_type

设备模型之设备类型:
/*
 * The type of device, "struct device" is embedded in. A class
 * or bus can contain devices of different types
 * like "partitions" and "disks", "mouse" and "event".
 * This identifies the device type and carries type-specific
 * information, equivalent to the kobj_type of a kobject.
 * If "name" is specified, the uevent will contain it in
 * the DEVTYPE variable.
 */
struct device_type {
 const char *name;
 const struct attribute_group **groups;
 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
 char *(*devnode)(struct device *dev, umode_t *mode,
    kuid_t *uid, kgid_t *gid);
 void (*release)(struct device *dev);

 const struct dev_pm_ops *pm; };

 
 
 
Linux 内核中,struct device_driver 结构体用于表示设备驱动程序。它定义在 include/linux/device.h 头文件中,其定义如下: ```c struct device_driver { const char *name; /* 驱动程序的名称 */ struct bus_type *bus; /* 设备所在的总线类型 */ struct module *owner; /* 指向驱动程序的模块 */ const char *mod_name; /* 驱动程序的模块名称 */ bool suppress_bind_attrs; /* 是否抑制属性绑定 */ const struct of_device_id *of_match_table; /* of_match_table 数组 */ const struct acpi_device_id *acpi_match_table; /* ACPI 设备 ID 数组 */ const struct dmi_system_id *dmi_match_table; /* DMI 系统 ID 数组 */ const struct attribute_group **groups; /* 属性组数组 */ int (*probe) (struct device *dev); /* 探测设备 */ int (*remove) (struct device *dev); /* 移除设备 */ void (*shutdown) (struct device *dev); /* 关闭设备 */ int (*suspend) (struct device *dev, pm_message_t state); /* 挂起设备 */ int (*resume) (struct device *dev); /* 恢复设备 */ const struct dev_pm_ops *pm; /* 设备的电源管理操作 */ struct driver_private *p; /* 驱动程序的私有数据 */ }; ``` 其中,常用的成员变量如下: - `name`:驱动程序的名称。 - `bus`:指向设备所在的总线类型的指针。 - `probe`:设备探测函数,当设备被发现时会调用该函数。 - `remove`:设备移除函数,当设备被移除时会调用该函数。 - `suspend`:设备挂起函数,当设备被挂起时会调用该函数。 - `resume`:设备恢复函数,当设备从挂起状态恢复时会调用该函数。 此外,还有一些用于设备属性和电源管理的成员变量,以及一些用于匹配设备的成员变量。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值