linux下bus,device,driver三者关系
1.bus:
总线作为主机和外设的连接通道,有些总线是比较规范的,形成了很多协议。如PCI,USB,1394,IIC等。任何设备都可以选择合适的总线连接到主机。当然主机也可能就是CPU本身。内存也是通过BUS连接到主机的,可内存使用的总线不是外设总线,因此和内存使用相同类型的总线的设备,谈及BUS比较含糊。
一块网卡在嵌入式开发中,直接通过内存总线接入到CPU。我们在写网卡驱动时,要给该BUS定义就麻烦了。
2.driver:
驱动程序是在CPU运行时,提供操作的软件接口。所有的设备必须有与之配套驱动程序才能正常工作。一个驱动程序可以驱动多个类似或者完全不同的设备。
3.device:
设备就是连接在总线上的物理实体。设备是有功能之分的。具有相同功能的设备被归到一个类(CLASS中)。如音频设备(和声音相关的都算),输入设备(鼠标,键盘,游戏杆等)。。。。
从宏观考虑,任何设备必须要连接到主机才能发挥其作用。一个鼠标离开了电脑主机就不再是鼠标了。提到了连接就必然出现总线BUS。任何设备要正常运行必须有软件支持,所有的设备必须有DRIVER。设备的目的就是完成功能,根据功能的分类,该设备必然属于某个CLASS。
1.三者的定义在 include/linux/device.h里。
2.总线中的那两条链表是怎么形成:
这要求每次出现一个设备就要向总线汇报,或者说注册,每次出现一个驱动,也要向总线汇报,或者说注册。比如系统初始化的时候,会扫描连接了哪些设备,并为每一个设备建立起一个struct device的变量,每一次有一个驱动程序,就要准备一个struct device_driver结构的变量。把这些变量统统加入相应的链表,device 插入devices 链表,driver插入drivers链表。这样通过总线就能找到每一个设备,每一个驱动.然而,假如计算机里只有设备却没有对应的驱动,那么设备无法工作。反过来,倘若只有驱动却没有设备,驱动也起不了任何作用。
3.总线上的两条链表已经有了,链表里的device和driver又是如何联系
每一个要用的device在计算机启动之前就已经插好了,插放在它应该在的位置上,然后计算机启动,然后操作系统开始初始化,总线开始扫描设备,每找到一个设备,就为其申请一个struct device结构,并且挂入总线中的devices链表中来;
然后每一个驱动程序开始初始化,开始注册其struct device_driver结构,然后它去总线的devices链表中去寻找(遍历),去寻找每一个还没有绑定driver的设备,即struct device中的struct device_driver指针仍为空的设备,然后它会去观察这种设备的特征,看是否是他所支持的设备,如果是,那么调用一个叫做 device_bind_driver的函数。换句话说,把struct device中的struct
device_driver driver指向这个driver,而struct device_driver driver把struct device加入他的那张struct klist klist_devices链表中来。就这样,bus、device和driver,这三者之间或者说他们中的两两之间,就给联系上了
4.热插拔:
device可以在计算机启动以后在插入或者拔出计算机了。因此,很难再说是先有 device还是先有driver了。因为都有可能。device可以在任何时刻出现,而driver 也可以在任何时刻被加载,所以,出现的情况就是,每当一个struct device诞生,它就会去bus的drivers链表中寻找自己的另一半,反之,每当一个一个struct device_driver诞生,它就去bus的devices链表中寻找它的那些设备。如果找到了合适的,那么ok,和之前那种情况一下,调用
device_bind_driver绑定好.
分享到:
相关推荐
linux 中 设备模型 中bus device driver kobject kset 集合
bus device driver
linux设备模型之bus,device,driver
linux驱动 bus-device-driver模型
new chapters on the USB bus and the serial driver subsystem; the chapter on PCI has also been enhanced. While the organization of the rest of the book resembles that of the earlier editions, every ...
Linux Device Driver 3rd Edition This is, on the surface, a book about writing device drivers for the Linux system. That is a worthy goal, of course; the flow of new hardware products is not likely to ...
Android Linux Device Bus Drivers,come from internet
spi接口的 LINUX CAN driver
Universal Serial Bus Device Class Definition for Video Devices
USB subsystem and the device driver framework. Then the API and its data structures will be explained step by step. The last section of this document contains a reference of all API calls and their ...
mmc linux 驱动 bus总线 部分讲解
The Linux Device Model Memory Barriers Power Management Looking at the Sources Chapter 5. Character Drivers Char Driver Basics Device Example: System CMOS Sensing Data Availability Talking to ...
不可多得的linux下的pci e驱动编写文档
介绍linux设备驱动模型概念中的设备篇
linux3.16 bus device driver 驱动模型