总线设备
设备模型元素
总线
驱动
设备
总线是处理器和设备之间的通道,在设备模型中, 所有的设备都通过总线相连, 甚至是内部的虚拟“platform”总线。 在 Linux 设备模型中, 总线由 bus_type 结构表示, 定义在 <linux/device.h>
struct bus_type { const char *name; /*总线名称*/ struct bus_attribute *bus_attrs; /*总线属性*/ struct device_attribute *dev_attrs; /*设备属性*/ struct driver_attribute *drv_attrs; /*驱动属性*/ int (*match)(struct device *dev, struct device_driver *drv); int (*uevent)(struct device *dev, struct kobj_uevent_env *env); 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 (*suspend_late)(struct device *dev, pm_message_t state); int (*resume_early)(struct device *dev); int (*resume)(struct device *dev); struct dev_pm_ops *pm; struct bus_type_private *p; }
总线注册/删除
1)总线的注册使用:bus_register(struct bus_type * bus)
若成功,新的总线将被添加进系统,并可在sysfs 的 /sys/bus 下看到。
2)总线的删除使用:void bus_unregister(struct bus_type *bus)
总线方法
1)int (*match)(struct device * dev, struct device_driver * drv)
当一个新设备或者驱动被添加到这个总线时,该方法被调用。用于判断指定的驱动程序是否能处理指定的设备。若可以,则返回非零值。
2)int (*uevent)(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size)
在为用户空间产生热插拔事件之前,这个方法允许总线添加环境变量。
总线属性由结构bus_attribute 描述,
struct bus_attribute { struct attribute attr; ssize_t (*show)(struct bus_type *, char * buf); ssize_t (*store)(struct bus_type *, const char * buf, size_t count); }
int bus_create_file(struct bus_type *bus, struct bus_attribute *attr)
创建属性
void bus_remove_file(struct bus_type *bus, struct bus_attribute *attr)
删除属性

浙公网安备 33010602011771号