struct bus_attribute *bus_attrs; // 总线属性 struct device_attribute *dev_attrs; // 设备属性 struct driver_attribute *drv_attrs; // 驱动程序属性 const struct attribute_group **bus_groups; // 总线属性组 const struct attribute_group **dev_groups; // 设备属性组 const struct attribute_group **drv_groups; // 驱动程序属性组
时间: 2024-04-26 11:27:03 浏览: 23
这几个字段分别用于定义总线、设备和驱动程序的属性和属性组:
- `bus_attrs`:指向总线属性的指针,可以使用 `sysfs` 文件系统来读取和修改这些属性。
- `dev_attrs`:指向设备属性的指针,同样可以使用 `sysfs` 文件系统来读取和修改这些属性。
- `drv_attrs`:指向驱动程序属性的指针,也可以使用 `sysfs` 文件系统来读取和修改这些属性。
- `bus_groups`:指向总线属性组的指针,一个属性组是一组相关的属性,可以一次性添加到 `sysfs` 上。这个指针指向一个指针数组,每个指针指向一个属性组。
- `dev_groups`:指向设备属性组的指针,同样是一个指针数组,每个指针指向一个属性组。
- `drv_groups`:指向驱动程序属性组的指针,也是一个指针数组,每个指针指向一个属性组。
通过这些属性和属性组,可以方便地向 `sysfs` 中添加和管理设备和驱动程序的属性。
相关问题
linux内核struct device_driver定义
在 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`:设备恢复函数,当设备从挂起状态恢复时会调用该函数。
此外,还有一些用于设备属性和电源管理的成员变量,以及一些用于匹配设备的成员变量。
struct device_driver结构体定义
在Linux内核中,struct device_driver结构体用于表示一个设备驱动程序。
它的定义如下:
```
struct device_driver {
const char *name;
struct bus_type *bus;
struct module *owner;
const char *mod_name; /* driver model name */
bool suppress_bind_attrs;
const struct of_device_id *of_match_table;
const struct acpi_device_id *acpi_match_table;
const struct platform_device_id *id_table;
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 attribute_group **groups;
const struct dev_pm_ops *pm;
const struct driver_private *p;
};
```
其中,各个成员的含义如下:
- `name`:设备驱动程序的名称。
- `bus`:设备所连接的总线类型。
- `owner`:指向驱动程序模块的指针。
- `mod_name`:驱动程序的模块名。
- `suppress_bind_attrs`:是否禁用绑定属性。
- `of_match_table`:Open Firmware匹配表。
- `acpi_match_table`:ACPI匹配表。
- `id_table`:设备标识表。
- `probe`:设备探测函数指针。
- `remove`:设备移除函数指针。
- `shutdown`:设备关机函数指针。
- `suspend`:设备挂起函数指针。
- `resume`:设备恢复函数指针。
- `groups`:设备属性组。
- `pm`:设备电源管理操作函数指针。
- `p`:驱动程序的私有数据。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)