欢迎来到天天文库
浏览记录
ID:22583377
大小:740.24 KB
页数:53页
时间:2018-10-30
《linux内核部件分析-设备驱动模型之device》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、linux的设备驱动模型,是建立在sysfs和kobject之上的,由总线、没备、驱动、类所组成的关系结构。从本节开始,我们将对linux这一设备驱动模型进行深入分析。头文件是include/linux/device.h,实现在drivers/base目录中。本节要分析的,是其中的设备,主要在core.c中。[cpp]viewplaincopyprint?2345678910111213141516171819202122232425262728293031structdevice{structdevice♦parentstruct
2、device一privatestructkobjectkobj;constchar*init_name;/*initialnameofthedevice*/structdevice一type*type;structsemaphoresem;/*semaphoretosynchronizecallsto*itsdriver.*/structbus_type*bus;/*typeofbusdeviceison*/structdevice—driver*driver;/*whichdriverhasallocatedthisvoiddev
3、ice*/*platform_data;/*Platformspecificdata,devicecoredoesn’ttouchit*/structdev_pm_infopower;#ifdefCONFIGNUMAint#endifu64u64numa_node;/*NUMAnodethisdeviceiscloseto*/*dma_mask;/*dmamask(ifdma’abledevice)*/coherent_dma_mask;/*Likedmajnask,butforalloc一coherentmappingsasnot
4、allhardwaresupports64bitaddressesforconsistentallocationssuchdescriptors.*/structdevice一dma—parameters*dma一parms;33.structlist_headdma—pools;/*dmapools(ifdma'ble)*/34.34.structdmacoherentmem*dmamem:/*internalforcoherentmem35.override*/36./*archspecificadditions*/37.str
5、uctdev_archdataarchdata;39.38.dev_tdevt;/*dev_t,createsthesysfs"dev1'*/41.39.spinlockjtdevres_lock;43.structlistJheaddevres_head;44.45.structklist—nodeknode—class;46.structclass*class:47.conststructattribute_group**groups;/*optionalgroups*/48.48.void(*release)(structde
6、vice*dev);49.};先来分析卜‘structdevice的结构变量。首先是指向父节点的指针parent,kobj是内嵌在device中的kobject,用于把它联系到sysfs中。bus是对设备所在总线的指针,driver是对没备所用驱动的指针。还有DMA需要的数据,表示没备号的devt,表示没备资源的devres_head和保护它的devresjock。指向类的指针class,knode_class是被选入class链表时所用的klist节点。group是设备的属性集合。release应该是没备释放时调用的闲数。2345
7、67[cpp]viewplaincopyprint?structdevice—private{structklistklist_children;structklist—nodeknode—parentjstructklistnodeknodedriver:structklistnodeknodebus:void*driver—data;structdevice*device;9.#defineto_device_private_parent(obj)10.container一of(ob]structdevice一private
8、,knode—parent)11>#defineto_device_private_driver(obj)12.container_of(obj,structdevice一private,knode—driver)12.#defin
此文档下载收益归作者所有