Linux 设备驱动 (第三版)第 14 章 Linux 设备模型14.9. 快速参考

14.9. 快速参考

包含 sysfs 声明的包含文件.

int sysfs_create_file(struct kobject *kobj, struct attribute *attr);
int sysfs_remove_file(struct kobject *kobj, struct attribute *attr);
int sysfs_create_bin_file(struct kobject *kobj, struct bin_attribute *attr);
int sysfs_remove_bin_file(struct kobject *kobj, struct bin_attribute *attr);
int sysfs_create_link(struct kobject *kobj, struct kobject *target, char *name);
void sysfs_remove_link(struct kobject *kobj, char *name);

创建和去除和一个 kobject 关联的属性文件的函数.

14.9.3. 总线, 设备, 和驱动

int bus_register(struct bus_type *bus);
void bus_unregister(struct bus_type *bus);

在设备模型中进行注册和注销总线的函数.

int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, int (*fn)(struct device *, void *));
int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, void *data, int (*fn)(struct device_driver *, void *));

列举每个设备和驱动的函数, 特别地, 绑定到给定总线的设备.


BUS_ATTR(name, mode, show, store);
int bus_create_file(struct bus_type *bus, struct bus_attribute *attr);
void bus_remove_file(struct bus_type *bus, struct bus_attribute *attr);

BUS_ATTR 宏可能用来声明一个 bus_attribute 结构, 它可能接着被添加和去除, 使用上面 2 个函数.

int device_register(struct device *dev);
void device_unregister(struct device *dev);

处理设备注册的函数.

DEVICE_ATTR(name, mode, show, store);
int device_create_file(struct device *device, struct device_attribute *entry);
void device_remove_file(struct device *dev, struct device_attribute *attr);

处理设备属性的宏和函数.

int driver_register(struct device_driver *drv);
void driver_unregister(struct device_driver *drv);

注册和注销一个设备驱动的函数.

DRIVER_ATTR(name, mode, show, store);
int driver_create_file(struct device_driver *drv, struct driver_attribute *attr);
void driver_remove_file(struct device_driver *drv, struct driver_attribute *attr);

关联驱动属性的宏和函数.

14.9.4. 类

struct class_simple *class_simple_create(struct module *owner, char *name);
void class_simple_destroy(struct class_simple *cs);
struct class_device *class_simple_device_add(struct class_simple *cs, dev_t devnum, struct device *device, const char *fmt, ...);
void class_simple_device_remove(dev_t dev);
int class_simple_set_hotplug(struct class_simple *cs, int (*hotplug)(struct class_device *dev, char **envp, int num_envp, char *buffer, int buffer_size));

实现 class_simple 接口的函数; 它们管理包含一个 dev 属性和很少其他属性的简单的类入口

int class_register(struct class *cls);
void class_unregister(struct class *cls);

注册和注销类.

CLASS_ATTR(name, mode, show, store);
int class_create_file(struct class *cls, const struct class_attribute *attr);
void class_remove_file(struct class *cls, const struct class_attribute *attr);

处理类属性的常用宏和函数.

int class_device_register(struct class_device *cd);
void class_device_unregister(struct class_device *cd);
int class_device_rename(struct class_device *cd, char *new_name);
CLASS_DEVICE_ATTR(name, mode, show, store);
int class_device_create_file(struct class_device *cls, const struct class_device_attribute *attr);

属性类设备接口的函数和宏.

int class_interface_register(struct class_interface *intf);
void class_interface_unregister(struct class_interface *intf);

添加一个接口到一个类(或去除它)的函数.

14.9.5. 固件

#include 
int request_firmware(const struct firmware **fw, char *name, struct device *device);
int request_firmware_nowait(struct module *module, char *name, struct device *device, void *context, void (*cont)(const struct firmware *fw, void *context));
void release_firmware(struct firmware *fw);

属性内核固件加载接口的函数.