Linux设备驱动模型的private_data 简单理解


Linux内核模型,主要是通过kobject kset来组织各部分目录的关系。 我的理解:任何的kobject都是一个对象元素,kset就是元素的集合,并且kset本身也有kobject的属性,并且描述kset的kobject同样隶属于另外一个kset集合。 内核模型的bus class driver devices数据结构,内部都镶嵌了自己的private data,用来用作外部访问的接口.

BUS PRIVATE

 
  
/**
 * struct bus_type_private - structure to hold the private to the driver core portions of the bus_type structure.
 *
 * @subsys - the struct kset that defines this bus.  This is the main kobject
 * @drivers_kset - the list of drivers associated with this bus
 * @devices_kset - the list of devices associated with this bus
 * @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.
 *
 * This structure is the one that is the actual kobject allowing struct
 * bus_type to be statically allocated safely.  Nothing outside of the driver
 * core should ever touch these fields.
 */
struct bus_type_private {
	struct kset subsys;	//指向本身的这个bus的kset集合 
	struct kset *drivers_kset;//子目录的drivers的kset
	struct kset *devices_kset;//子目录的devices的kset
	struct klist klist_devices;//链表,链表元素knode,每个knode所属一个设备struct device
	struct klist klist_drivers;//同上,也是个链表。knode所属一个驱动实体 struct device_driver
	struct blocking_notifier_head bus_notifier;//一个通知链表,给关心这个bus变化的对象进行操作
	unsigned int drivers_autoprobe:1;//代表是否允许 驱动自动探测设备 设备自动探测驱动
	struct bus_type *bus;//指向bus实体本身
};


//总结:

bus 是什么玩意????

答:bus就是管理着一组设备,设备之间代码表示都是结构体内嵌了个kobject,各个设备的object相互链接。然后这些object都一个parent,就是这个bus实体中内嵌的driver_kset or device_kset。

bus上有2个链表,链表元素是knode,一个链表是驱动链表,一个设备链表。然后,每个bus目录下,有2个目录 分别为driver和device,这2个目录其实就是对应这个private里的两个drivers_kset and devices_kset。新增设备或者驱动,加载链表上的同时,会把本身的kobject的parent指向driver或者device。

//

DEVICE PRIVATE

struct driver_private {
	struct kobject kobj;//driver 实体的kobject对象变量
	struct klist klist_devices;//管理的设备列表,列表里的设备都是匹配本驱动的
	struct klist_node knode_bus;//一个knode节点,会连接到所属的bus的驱动列表上//
	struct module_kobject *mkobj;//驱动归属模块  不太懂
	struct device_driver *driver;//驱动实体本身
};
#define to_driver(obj) container_of(obj, struct driver_private, kobj)
//驱动的private,在sys目录里只存在于bus下的driver目录下的各个驱动的子目录下。

驱动的存在性,即被链接到bus总线的驱动链表上。本身又维护着匹配的设备链表。本身作为kobject隶属于driver目录


/**
 * struct class_private - structure to hold the private to the driver core portions of the class structure.
 *
 * @class_subsys - the struct kset that defines this class.  This is the main kobject
 * @class_devices - list of devices associated with this class
 * @class_interfaces - list of class_interfaces associated with this class
 * @class_dirs - "glue" directory for virtual devices associated with this class
 * @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
 * class to be statically allocated safely.  Nothing outside of the driver
 * core should ever touch these fields.
 */
struct class_private {
	struct kset class_subsys;//class本身的kset
	struct klist class_devices;//class涉及的knode元素单元的list列表
	struct list_head class_interfaces;//
	struct kset class_dirs;
	struct mutex class_mutex;
	struct class *class;
};
#define to_class(obj)	\
	container_of(obj, struct class_private, class_subsys.kobj)
















你可能感兴趣的:(LINUX)