Linux设备管理模型-01:基础数据结构

1. 设备管理模型

设备模型是内核提供的一个编写驱动的架构。
设备管理是设备-总线-驱动结构。
linux中的设备是由树状模型组织的,从sysfs中可以查看树状结构。

他本身实现了:

  • 电源管理
  • 热插拔(hotplug)事件管理

2. 基本数据结构

  • kobject, kset, uevent
  • device, device_driver, bus, class

2.1 kobject

许多内核对象都是由kobject作为基类派生的。相同类型的kobject通过其内嵌的list_head链成一个链表,然后使用另外一个结构体kset(kobject的子类)来指向和管理这个列表。

struct kobject {
   
	const char		*name;
	struct list_head	entry;
	struct kobject		*parent;
	struct kset		*kset; 		/* 给相关的kobject分组,是kobj的集合 */
	struct kobj_type	*ktype; /* 抽象出了一些kobj和sysfs的通用接口,描述kobj的行为 */
	struct kernfs_node	*sd; 	/* sysfs 的文件节点 */
	struct kref		kref; 		/* kobject的引用计数 */
#ifdef CONFIG_DEBUG_KOBJECT_RELEASE
	struct delayed_work	release;
#endif
	unsigned int state_initialized:1;
	unsigned int state_in_sysfs:1;
	unsigned int state_add_uevent_sent:1;
	unsigned int state_remove_uevent_sent:1;
	unsigned int uevent_suppress:1;
};

一个新的kobject要加入到设备管理模型中,需要使用函数:

/* 创建新的kobj */
struct kobject * __must_check kobject_create_and_add(const char *name,
						struct kobject *parent); 
/* parent : 在sysfs中的父目录,如果为NULL则表示在"/sys/"目录下 */

/* 添加已存在的的kobj */						
int kobject_init_and_add(struct kobject *kobj,
			 struct kobj_type *ktype, 
			 struct kobject *parent, 
			 const char *fmt, ...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值