linux内核学习(20)设备模型第二层之一

linux内核学习(20)设备模型第二层之一  

2010-12-30 11:31:39|  分类: Linux_内核 |  标签: |举报 |字号 订阅

设备模型第二层也是非常重要的一层,为各种设备打好了基础,由于我之前在分析的过程中发现,如果每个细节都一起抠,可能很难将设备模型的概貌理解清楚,因此,我将采用从整体到局部的方法分析设备模型第二层,还是因为里面的东西太过于复杂。那么我们将哪些给踢掉呢,当然为了将设备模型的重点给捋出来,我可是费了不少功夫。

我们将设备模型中关于sysfs、class 、attribute、电源管理等给踢掉,剩下的基本就简单多了,等我们将重点分析完后,在回过头来分析这每个部分,那将非常简单了。好了立刻开始吧!

设备模型第二层:


一、重要的数据结构:


1device对象:

struct device {

struct device *parent; //父设备


struct device_private *p; //设备私有数据


struct kobject kobj; //嵌入内核对象

const char *init_name; //设备初始名字

struct device_type *type; //设备类型


struct mutex mutex; //用于同步的互斥量


struct bus_type *bus; //总线类型

struct device_driver *driver; //设备对应的驱动

void *platform_data; /* Platform specific data, device

core doesn't touch it */

struct dev_pm_info power; //电源信息


#ifdef CONFIG_NUMA

int numa_node; /* NUMA node this device is close to */

#endif

u64 *dma_mask; /* dma mask (if dma'able device) */

u64 coherent_dma_mask;/* Like dma_mask, but for

alloc_coherent mappings as

not all hardware supports

64 bit addresses for consistent

allocations such descriptors. */


struct device_dma_parameters *dma_parms;


struct list_head dma_pools; /* dma pools (if dma'ble) */


struct dma_coherent_mem *dma_mem; /* internal for coherent mem

override */

/* arch specific additions */

struct dev_archdata archdata;

#ifdef CONFIG_OF

struct device_node *of_node;

#endif


dev_t devt; /* dev_t, creates the sysfs "dev" */

//设备号


spinlock_t devres_lock;

struct list_head devres_head; //子设备链表节点


struct klist_node knode_class;

struct class *class;

const struct attribute_group **groups; /* optional groups */


void (*release)(struct device *dev);

};


1-1device_private结构体:

struct device_private {

struct klist klist_children;

struct klist_node knode_parent;

struct klist_node knode_driver;

struct klist_node knode_bus;

void *driver_data;

struct device *device;

};

2bus_type对象:

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 bus_type_private *p; //总线私有数据

};

2-1bus_type_private结构体:

struct bus_type_private {

struct kset subsys;

struct kset *drivers_kset;

struct kset *devices_kset;

struct klist klist_devices;

struct klist klist_drivers;

struct blocking_notifier_head bus_notifier;

unsigned int drivers_autoprobe:1;

struct bus_type *bus;

};

3device_driver对象:

struct device_driver {

const char *name; //驱动名字

struct bus_type *bus; //总线


struct module *owner; //所属模块

const char *mod_name; /* used for built-in modules */

//模块名称

bool suppress_bind_attrs; /* disables bind/unbind via sysfs */


#if defined(CONFIG_OF)

const struct of_device_id *of_match_table; //匹配设备的表

#endif


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 attribute_group **groups; //sysfs


const struct dev_pm_ops *pm; //电源管理的操作集合

struct driver_private *p; //驱动私有数据

};

3-1of_device_id结构体:

struct of_device_id

{

char name[32];

char type[32];

char compatible[128];

#ifdef __KERNEL__

void *data;

#else

kernel_ulong_t data;

#endif

};

3-2driver_private结构体:

struct driver_private {

struct kobject kobj;

struct klist klist_devices;

struct klist_node knode_bus;

struct module_kobject *mkobj;

struct device_driver *driver;

};



二、重要的常量数据:

1static struct kobj_type device_ktype = {

.release = device_release,

.sysfs_ops = &dev_sysfs_ops,

.namespace = device_namespace,

};

2static struct kobj_type bus_ktype = {

.sysfs_ops = &bus_sysfs_ops,

};

3static struct kobj_type driver_ktype = {

.sysfs_ops = &driver_sysfs_ops,

.release = driver_release,

};


三、重要的函数:


int device_register(struct device *dev);

int bus_register(struct bus_type *bus);

int driver_register(struct device_driver *drv);



这些只是把第二层的重要的东西给罗列了出来,其实通过device、device_driver、bus_type结构体,我们可以将它们的关系弄的比较清楚,当然了,很多资料中已经将它们描述的无比细致了。剩下的事情就是关于这个3个非常重要的函数了,都是注册。我们将马上会分析到。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值