14 模型,又见模型 小结

来源:互联网 发布:天盾数据恢复软件 编辑:程序博客网 时间:2024/06/05 02:51

1. bus_type,device,device_driver的关系?

1)bus_type有两个kset成员,
struct kset drivers;
struct kset devices;
分别表示它连接在这个总线上的设备列表和注册在这个总线上的驱动列表。

2)device有两个成员:
struct bus_type * bus; /* type of bus device is on */
struct device_driver *driver; /* which driver has allocated this device */
分别表示它连接的总线和驱动。

3)device_driver有两个成员:
struct bus_type * bus;
struct klist klist_devices;
分别表示它连接的总线和支持的设备的列表。

操作系统初始化时,总线扫描设备,每找到一个设备,就为其申请一个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三者就联系上了。

2. 什么是kobject,kset和klist?kset和klist的区别?

参见p34.

klist在include\linux\klist.h定义。

援引注释:
"Some generic list helpers, extending struct list_head a bit.
"
它是一个内核里面的通用链表的实现。

而kset在include\linux\kobject.h定义。

援引注释:
"a set of kobjects of a specific type, belonging to a specific subsystem."
它被设计为一个针对kobjects的链表。

这就是两者的区别。
原创粉丝点击