14.9. 快速參考

2018-02-24 15:50 更新

14.9.?快速參考

許多函數(shù)在本章中已經(jīng)被介紹過; 這是它們?nèi)康囊粋€(gè)快速總結(jié).

14.9.1.?Kobjects結(jié)構(gòu)

#include <linux/kobject.h>

包含文件, 包含 kobject 的定義, 相關(guān)結(jié)構(gòu), 和函數(shù).

void kobject_init(struct kobject *kobj);
int kobject_set_name(struct kobject *kobj, const char *format, ...);

用作 kobject 初始化的函數(shù)

struct kobject *kobject_get(struct kobject *kobj);
void kobject_put(struct kobject *kobj);

為 kobjects 管理引用計(jì)數(shù)的函數(shù).

struct kobj_type;
struct kobj_type *get_ktype(struct kobject *kobj);

表示一個(gè)kobjct 被嵌入的結(jié)構(gòu)類型. 使用 get_ktype 來獲得關(guān)聯(lián)到一個(gè)給定 kobject 的 kobj_type.

int kobject_add(struct kobject *kobj);
extern int kobject_register(struct kobject *kobj);
void kobject_del(struct kobject *kobj);
void kobject_unregister(struct kobject *kobj);

kobject_add 添加一個(gè) kobject 到系統(tǒng), 處理 kset 成員關(guān)系, sysfs 表示, 以及熱插拔事件產(chǎn)生. kobject_register 是一個(gè)方便函數(shù), 它結(jié)合 kobject_init 和 kobject_add. 使用 kobject_del 來去除一個(gè) kobject 或者 kobject_unregister, 它結(jié)合了 kobject_del 和 kobject_put.

void kset_init(struct kset *kset);
int kset_add(struct kset *kset);
int kset_register(struct kset *kset);
void kset_unregister(struct kset *kset);

為 ksets 初始化和注冊的函數(shù).

decl_subsys(name, type, hotplug_ops);

易于聲明子系統(tǒng)的一個(gè)宏.

void subsystem_init(struct subsystem *subsys);
int subsystem_register(struct subsystem *subsys);
void subsystem_unregister(struct subsystem *subsys);
struct subsystem *subsys_get(struct subsystem *subsys);
void subsys_put(struct subsystem *subsys);

對子系統(tǒng)的操作.

14.9.2.?sysfs 操作

include <linux/sysfs.h>

包含 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);

創(chuàng)建和去除和一個(gè) kobject 關(guān)聯(lián)的屬性文件的函數(shù).

14.9.3.?總線, 設(shè)備, 和驅(qū)動(dòng)

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

在設(shè)備模型中進(jìn)行注冊和注銷總線的函數(shù).

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 *));

列舉每個(gè)設(shè)備和驅(qū)動(dòng)的函數(shù), 特別地, 綁定到給定總線的設(shè)備.


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 宏可能用來聲明一個(gè) bus_attribute 結(jié)構(gòu), 它可能接著被添加和去除, 使用上面 2 個(gè)函數(shù).

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

處理設(shè)備注冊的函數(shù).

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);

處理設(shè)備屬性的宏和函數(shù).

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

注冊和注銷一個(gè)設(shè)備驅(qū)動(dòng)的函數(shù).

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);

關(guān)聯(lián)驅(qū)動(dòng)屬性的宏和函數(shù).

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));

實(shí)現(xiàn) class_simple 接口的函數(shù); 它們管理包含一個(gè) 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);

處理類屬性的常用宏和函數(shù).

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);

屬性類設(shè)備接口的函數(shù)和宏.

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

添加一個(gè)接口到一個(gè)類(或去除它)的函數(shù).

14.9.5.?固件

#include <linux/firmware.h>
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);

屬性內(nèi)核固件加載接口的函數(shù).

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號