linux设备驱动-总线设备和驱动解析

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

2、设备
linux系统中每个设备都用一个device结构的 表示,如下:
设备注册和注销
设备注册的步骤: 1)定义结构体device。 2)调用注册函数: int device_register(struct device *dev) 设备注销函数: void device_unregister(struct device *dev)
3、设备驱动
设备驱动的结构体如下:
驱动的注册和注销
驱动的注册步骤: 1)定义驱动的结构体device_driver。 2)调用注册函数: int driver_register(struct device_driver *drv) 驱动注销函数: void driver_unregister(struct device_driver *drv)
4、总结
属性结构体:xx_attribute。 注册函数:xx_register。 注销函数:xx_unregister。 创建属性文件函数:xx_create_file。 删除属性文件函数:xx_remove_file。
其中xx可以是总线(bus)、设备(device)或者驱 动函数(driver)。
设备属性的添加和删除
设置设备属性有两个步骤: 1)创建并初始化device_attribute结构 2)将device_attibute添加到指定的设备上,使 用以下调用: int device_create_file(struct device *dev, struct device_attribute *attr) 设备属性的删除: void device_remove_file(struct device *dev, struct device_attribute *attr)
总线、设备和驱动
罗苏笙 2012.12.4
1. sysfs文件系统
sysfs文件系统是处于内存中的虚拟文件系统, 其把连接在系统上的设备和总线组织成为一个分 级的目录及文件,它们可以由用户空间存取,向 用户空间导出内核数据结构以及它们的属性。 其顶层的目录主要有: block、bus、class、devices、firmware、fs、 kernel、module、power
2、总线
总线是处理器和设备之间的通道,在设备模型 中,所有的设备都通过总线相连,以总线来管理 设备和驱动函数。总线用bus_type结构表示。
总线的注册和删除:
总线的注册有两个步骤: 1)定义一个bus_type结构体 2)调用函数bus_register注册总线。函数原型 如下:int bus_register(struct bus_type *bus)
驱动属性的添加和删除
设置设备属性有两个步骤: 1)创建并初始化device_attribute结构 2)将device_attibute添加到指定的驱动函数上,使 用以下调用: int driver_create_file(struct device_driver *drv, struct driver_attribute *attr) 如果不需要该属性时,使用以下函数删除: void driver_remove_file(struct device_driver *drv, struct driver_attribute *attr)
5、总线、设备和驱动的关系
Fra Baidu bibliotek 5、关键函数
1)配对函数(match): int (*match)(struct device *dev, struct device_driver *drv);位于总线结构体bus_type中 2)探测函数(probe):int (*probe) (struct device *dev); 3)卸载函数(remove) :int (*remove) (struct device *dev);
总线删除时调用: void bus_unregister(struct bus_type *bus)
总线属性
设置总线的属性后,会在对应的总线目录下增 加了一个新的文件,通过对该文件的读写访问, 触发相应的函数操作,从而实现/sys/的文件接口 与内核设备模型的数据交互。
总线属性的添加和删除
设置总线属性有两个步骤: 1)创建并初始化bus_attribute结构,使用宏 BUS_ATTR(_name, _mode, _show, _store) 2)将bus_attibute添加到指定的总线上,使用以下 调用: int bus_create_file(struct bus_type *bus, struct bus_attribute *attr) 总线属性删除: void bus_remove_file(struct bus_type *bus, struct bus_attribute *attr)
match、probe和remove关系图
THANKS 谢谢
相关文档
最新文档