資源描述:
《linux內(nèi)核部件分析-設備驅動模型之device》由會員上傳分享,免費在線閱讀,更多相關內(nèi)容在工程資料-天天文庫。
1、linux的設備驅動模型,是建立在sysfs和kobject之上的,由總線、沒備、驅動、類所組成的關系結構。從本節(jié)開始,我們將對linux這一設備驅動模型進行深入分析。頭文件是include/linux/device.h,實現(xiàn)在drivers/base目錄中。本節(jié)要分析的,是其中的設備,主要在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的結構變量。首先是指向父節(jié)點的指針parent,kobj是內(nèi)嵌在device中的kobject,用于把它聯(lián)系到sysfs中。bus是對設備所在總線的指針,driver是對沒備所用驅動的指針。還有DMA需要的數(shù)據(jù),表示沒備號的devt,表示沒備資源的devres_head和保護它的devresjock。指向類的指針class,knode_class是被選入class鏈表時所用的klist節(jié)點。group是設備的屬性集合。release應該是沒備釋放時調(diào)用的閑數(shù)。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