1、设备总线
struct
bus_attribute//设备总线的属性结构体,主要是展示和存储总线
BUS_ATTR(_name, _mode, _show, _store)、
bus_create_file//通过设备总线创建文件
bus_remove_file(struct bus_type *, struct
bus_attribute *);//通过设备总线释放文件
struct bus_type //设备总线的类型extern
int __must_check bus_register(struct
bus_type *bus);//总线注册
extern void bus_unregister(struct
bus_type *bus);//总线注销
extern int __must_check bus_rescan_devices(struct bus_type
*bus);//重新扫描总线上的设备
bus_for_each_dev
//为每个设备重申总线
struct device *bus_find_device(struct
bus_type *bus, struct device *start,//查找总线上的设备
struct device *bus_find_device_by_name(struct bus_type
*bus,?/通过别名查找总线上的设备
int bus_for_each_drv(struct bus_type
*bus, struct device_driver *start,//为每个驱动重申总线
void bus_sort_breadthfirst
extern int bus_register_notifier
extern int bus_unregister_notifier
extern struct kset *bus_get_kset
extern struct klist *bus_get_device_klist
2、设备驱动
struct device_driver
//设备的驱动结构体extern int __must_check driver_register(struct device_driver
*drv);//设备驱动注册
extern void driver_unregister(struct
device_driver *drv);//设备驱动注销
extern struct device_driver *get_driver(struct device_driver *drv);//获取驱动
extern void put_driver(struct
device_driver *drv);//关闭驱动
extern struct device_driver *driver_find(const char *name,struct bus_type
*bus);//查找驱动
extern int driver_probe_done(void);//
已探测了设备驱动
extern void wait_for_device_probe(void);//等待探测设备驱动
struct driver_attribute //设备属性结构体
extern int __must_check driver_create_file(struct device_driver
*driver,const struct driver_attribute *attr);
extern void driver_remove_file(struct
device_driver *driver,const struct driver_attribute *attr);
extern int __must_check driver_add_kobj(struct device_driver
*drv, struct kobject
*kobj, const char
*fmt, ...);
extern int __must_check driver_for_each_device(struct device_driver
*drv,struct device *start,void *data,
int (*fn)(struct
device *dev,void *));
struct device *driver_find_device(struct device_driver
*drv, struct device *start, void *data,int
(*match)
(struct device *dev, void *data));
3、设备类别
struct class
//设备类别结构体struct class_dev_iter
//设备类别通路结构体extern int __must_check __class_register(struct class *class,struct
lock_class_key *key);
extern void class_unregister(struct
class *class);
struct class_compat *class_compat_register(const char
*name);//兼容性类别的注册
void class_compat_unregister(struct
class_compat *cls);//兼容性类别的注销
int class_compat_create_link
创建兼容性类别的链接
void class_compat_remove_link
extern void class_dev_iter_init
extern struct device *class_dev_iter_next
extern void class_dev_iter_exit
extern int class_for_each_device
extern struct device *class_find_device
extern int
__must_check class_create_file extern void
class_remove_file
struct class_attribute
struct class_attribute_string {
extern ssize_t show_class_attr_string(struct class *class, struct
class_attribute *attr,//展示类别属性的字符串
struct
class_interface
extern int __must_check class_interface_register(struct class_interface
*);//类别接口的注册
extern void class_interface_unregister(struct class_interface
*);
extern struct class * __must_check
__class_create
4、设备
struct device_type
//设备的类别,A classor bus can contain devices of different types
struct device_attribute // 设备属性结构体extern int
__must_check device_create_file(struct
device *device,const struct device_attribute *entry);
extern void device_remove_file(struct
device *dev,const struct device_attribute *attr);
extern int __must_check device_create_bin_file(struct device *dev,const
struct bin_attribute *attr);
extern void device_remove_bin_file(struct device
*dev, const struct bin_attribute *attr);
extern int device_schedule_callback_owner
设备资源的操作
extern void *__devres_alloc(dr_release_t release, size_t size,
gfp_t gfp, const char *name);
extern void devres_free(void
*res);//释放设备资源数据
extern void devres_add(struct device
*dev, void *res);
extern void *devres_find(struct device
*dev, dr_release_t release,dr_match_t match, void
*match_data);
extern void *devres_get(struct device
*dev, void *new_res,dr_match_t match, void *match_data);
extern void *devres_remove(struct
device *dev, dr_release_t release,dr_match_t match,
void
*match_data);
extern int devres_destroy(struct
device *dev, dr_release_t release,dr_match_t match, void
*match_data);
设备资源组
extern void * __must_check devres_open_group(struct device *dev, void
*id, gfp_t gfp);
extern void devres_close_group(struct
device *dev, void *id);
extern void devres_remove_group(struct
device *dev, void *id);
extern int devres_release_group(struct
device *dev, void *id);
extern void *devm_kzalloc(struct
device *dev, size_t size, gfp_t gfp);
extern void devm_kfree(struct device
*dev, void *p);
struct device
static inline const char *dev_name(const struct device *dev)//设备的名字
extern int dev_set_name(struct device
*dev, const char *name, ...)//设置设备的名字
static inline void set_dev_node(struct
device *dev, int node)// 设置设备节点
static inline int dev_to_node(struct
device *dev)
static inline void set_dev_node(struct
device *dev, int node)
static inline unsigned int dev_get_uevent_suppress(const struct device
*dev)
static inline void dev_set_uevent_suppress(struct device *dev, int
val)
static inline int device_is_registered(struct device *dev)
static inline void device_enable_async_suspend(struct device
*dev)
static inline void device_disable_async_suspend(struct device
*dev)
static inline bool device_async_suspend_enabled(struct device
*dev)
static inline void device_lock(struct
device *dev)
static inline int device_trylock(struct device *dev)
static inline void device_unlock(struct device *dev)
void driver_init(void);//设备初始化
extern int __must_check device_register(struct device *dev);
extern void device_unregister(struct
device *dev);
extern void device_initialize(struct
device *dev);
extern int __must_check device_add(struct device *dev);
extern void device_del(struct device
*dev);
extern int device_for_each_child(struct device *dev, void
*data,int (*fn)(struct device *dev, void *data));
extern struct device *device_find_child(struct device *dev, void
*data,int (*match)(struct device *dev,
void *data));
extern int device_rename(struct device
*dev, const char *new_name);
extern int device_move(struct device
*dev, struct device *new_parent,enum dpm_order dpm_order);
extern const char *device_get_devnode(struct device
*dev, mode_t *mode, const char **tmp);
extern void *dev_get_drvdata(const
struct device *dev);
extern void dev_set_drvdata(struct
device *dev, void *data);
static inline struct device *root_device_register(const char *name)
extern void root_device_unregister(struct device *root);
设备的绑定
extern int __must_check device_bind_driver(struct device
*dev);//将设备和驱动绑定
extern void device_release_driver(struct device *dev);
extern int __must_check device_attach(struct device *dev);
extern int __must_check driver_attach(struct device_driver *drv);
extern int __must_check device_reprobe(struct device *dev);
static inline int devtmpfs_delete_node(struct device *dev) { return
0; }//删除设别临时文件的节点
static inline int devtmpfs_mount(const
char *mountpoint) { return 0; }//设备临时文件的挂载
extern void device_shutdown(void);
extern void sysdev_shutdown(void);
extern const char *dev_driver_string(const struct device
*dev);//设备驱动的字符串
5、设备调试打印
extern int dev_printk(const char *level, const struct device
*dev,
const char *fmt, ...)
__attribute__ ((format (printf, 3, 4)));
extern int dev_emerg(const struct
device *dev, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
extern int dev_alert(const struct
device *dev, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
extern int dev_crit(const struct
device *dev, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
extern int dev_err(const struct device
*dev, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
extern int dev_warn(const struct
device *dev, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
extern int dev_notice(const struct
device *dev, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
extern int _dev_info(const struct
device *dev, const char *fmt, ...)
__attribute__ ((format (printf, 2,
3)));