Linux设备模型基本机构体

来源:本站
导读:目前正在解读《Linux设备模型基本机构体》的相关信息,《Linux设备模型基本机构体》是由用户自行发布的知识型内容!下面请观看由(电工技术网 - www.9ddd.net)用户发布《Linux设备模型基本机构体》的详细说明。
简介:Linux设备模型bus_type、device和device_driver基本机构体汇总

经历了人生美好一刻、难过的时候,会懂得,会放弃,会怀念不断积累的平淡。那些曾经拥有的都过去了,忘记了,不再在意了,而棱角渐渐光滑,激情也慢慢消失,会同意有些事需要时间慢慢积累,也相信付出不一定会有收获,而这里,却还想欺骗自己一回,想说“一分耕耘一分收获”。

用了多年时间耗尽精力一遍遍地学那些看似应该学的东西,最后却仍觉得捉襟见肘,会伤心,会回首,忍受许多无奈。学习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);/*恢复时调用*/

struct dev_pm_ops *pm;/*设备电源管理*/

struct bus_type_private *p;/*私有数据。完全由驱动核心初始化并使用*/

};

struct bus_type_private{

struct kset subsys;/*与该总线相关的子系统*/

struct kset *drivers_kset;/*总线上驱动程序的kset*/

struct kset *devices_kset;/*挂在该总线的所有设备的kset*/

struct klist klist_devices;/*挂接在该总线的设备链表*/

struct klist klist_drivers;/*与该总线相关的驱动程序链表*/

struct blocking_notifier_head bus_notifier;

unsigned int drivers_autoprobe:1;

struct bus_type *bus;

};

struct kobj_attribute{

struct attribute attr;

ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,

char *buf);

ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,

const char *buf, size_t count);

};

struct device{

struct device*parent;//父设备,会在父设备目录下生成当前设备的目录

struct device_private*p;

struct kobject kobj;

const char*init_name; /* initial name of the device */

struct device_type*type;

struct semaphoresem;/* semaphore to synchronize calls to its driver. */

struct bus_type *bus;/* type of bus device is on */

struct device_driver *driver;/* which driver has allocated this device */

void*driver_data;/* data private to the driver */

void*platform_data; /* Platform specific data, device

core doesn't touch it */

struct dev_pm_infopower;

#ifdef CONFIG_NUMA

intnuma_node;/* NUMA node this device is close to */

#endif

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

u64coherent_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_headdma_pools;/* dma pools (if dma'ble) */

struct dma_coherent_mem *dma_mem; /* internal for coherent mem

override */

/* arch specific additions */

struct dev_archdataarchdata;

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

spinlock_tdevres_lock;

struct list_headdevres_head;

struct klist_nodeknode_class;

struct class*class;

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

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

};

struct device_private{

struct klist klist_children;

struct klist_node knode_parent;

struct klist_node knode_driver;/*作为添加到驱动的设备列表的节点*/

struct klist_node knode_bus;

struct device *device;

};

struct device_driver{

const char*name;/*驱动程序的名字(在sysfs中出现)*/

struct bus_type*bus;/*驱动程序所操作的总线类型*/

struct module*owner;

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

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);

struct attribute_group **groups;

struct dev_pm_ops *pm;

struct driver_private *p;

};

struct driver_private{

struct kobject kobj;/*内嵌的kobject对象*/

struct klist klist_devices;/*当前驱动程序能操作的设备链表*/

struct klist_node knode_bus;/*作为添加到总线的驱动列表的节点*/

struct module_kobject *mkobj;

struct device_driver *driver;

};

提醒:《Linux设备模型基本机构体》最后刷新时间 2024-03-14 01:05:38,本站为公益型个人网站,仅供个人学习和记录信息,不进行任何商业性质的盈利。如果内容、图片资源失效或内容涉及侵权,请反馈至,我们会及时处理。本站只保证内容的可读性,无法保证真实性,《Linux设备模型基本机构体》该内容的真实性请自行鉴别。