Linux設備驅動模型探究--2(bus)



二. 總線bus、設備device、驅動driver
 
----總線、設備、驅動是建立在kobject和kset基礎之上的,也是設備驅動程序員與之打交道最多的部分。

----總線是Linux設備驅動模型中最核心的框架,設備與驅動都圍繞着總線工作,總線可以是實際物理總線(比如PCI總線,I2C總線)的抽象,
----也可以是出去驅動模型構架需要產生的虛擬"平臺"總線,因爲符合Linux驅動模型的設備與驅動必須掛在一根總線上。


----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 (*resume)(struct device *dev);

 const struct dev_pm_ops *pm;   /*總線上一組跟電源管理相關的操作*/

 struct subsys_private *p;    /*用來管理設備和驅動的操作*/
---};

---/**
 * struct subsys_private - structure to hold the private to the driver core portions of the bus_type/class structure.
 *
 * @subsys - the struct kset that defines this subsystem
 * @devices_kset - the list of devices associated /*設備集合*/
 *
 * @drivers_kset - the list of drivers associated /*驅動集合*/
 * @klist_devices - the klist to iterate over the @devices_kset
 * @klist_drivers - the klist to iterate over the @drivers_kset
 * @bus_notifier - the bus notifier list for anything that cares about things
 *                 on this bus.
 * @bus - pointer back to the struct bus_type that this structure is associated
 *        with.
 *
 * @class_interfaces - list of class_interfaces associated
 * @glue_dirs - "glue" directory to put in-between the parent device to
 *              avoid namespace conflicts
 * @class_mutex - mutex to protect the children, devices, and interfaces lists.
 * @class - pointer back to the struct class that this structure is associated
 *          with.
 *
 * This structure is the one that is the actual kobject allowing struct
 * bus_type/class to be statically allocated safely.  Nothing outside of the
 * driver core should ever touch these fields.
 */
 
---struct subsys_private {
 struct kset subsys;   /*用來表示bus所在的子系統,在內核中所有通過bus_register註冊進系統的bus所在的kset都指向bus_kset*/
 struct kset *devices_kset; 

 struct kset *drivers_kset;
 struct klist klist_devices;
 struct klist klist_drivers;
 struct blocking_notifier_head bus_notifier;
 unsigned int drivers_autoprobe:1;
 struct bus_type *bus;  /*指向與subsys_private相關的bus_type*/

 struct list_head class_interfaces;
 struct kset glue_dirs;
 struct mutex class_mutex;
 struct class *class;
---};


---/*struct kset subsys; 用來表示bus所在的子系統,
---在內核中所有通過bus_register註冊進系統的bus所在的kset都指向bus_kset(總線屬性--以及方法),
---bus_kset是所有bus內核對象的容器
---bus_kset = kset_create_and_add("bus", &bus_uevent_ops, NULL); --->bus_init()
---*/


/*
--bus_register - register a bus and enstable a directory blow the /sys/bus/.
--struct kset *kset_create_and_add(const char *name,
     const struct kset_uevent_ops *uevent_ops,
     struct kobject *parent_kobj)
*/

--int bus_register(struct bus_type *bus)
--{ 
 
----retval = kobject_set_name(&priv->subsys.kobj, "%s", bus->name);

----priv->subsys.kobj.kset = bus_kset;

----priv->subsys.kobj.ktype = &bus_ktype;

----priv->devices_kset = kset_create_and_add("devices", NULL,  /*在priv_subys.kobj目錄下建立devices目錄*/
       &priv->subsys.kobj);
----priv->drivers_kset = kset_create_and_add("drivers", NULL,  
       &priv->subsys.kobj);
--}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章