Linux上PCI-E驅(qū)動(dòng)設(shè)計(jì)_第1頁(yè)
Linux上PCI-E驅(qū)動(dòng)設(shè)計(jì)_第2頁(yè)
Linux上PCI-E驅(qū)動(dòng)設(shè)計(jì)_第3頁(yè)
Linux上PCI-E驅(qū)動(dòng)設(shè)計(jì)_第4頁(yè)
Linux上PCI-E驅(qū)動(dòng)設(shè)計(jì)_第5頁(yè)
免費(fèi)預(yù)覽已結(jié)束,剩余1頁(yè)可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、    linux上pcie驅(qū)動(dòng)設(shè)計(jì)    摘 要:當(dāng)前基于linux內(nèi)核的操作系統(tǒng)應(yīng)用越來越廣泛,開發(fā)基于linux的設(shè)備驅(qū)動(dòng)程序,具有很強(qiáng)的實(shí)用性和可移植性。本文簡(jiǎn)單介紹linux系統(tǒng)上pci-e設(shè)備驅(qū)動(dòng)的框架以及重要的數(shù)據(jù)結(jié)構(gòu)。關(guān)鍵詞:linux;pci-e;pci;驅(qū)動(dòng)abstract:at present,the operating system based on linux kernel is used more and more widely. it is very practical and portable to develop the

2、 device driver based on linux. this article briefly introduces the framework and the important data structure of pci-e device driver on linux system .key word: linux;pci-e;pci;driverpci-express 簡(jiǎn)稱pci-e,是一種完全不同于pci、具有高速串行點(diǎn)對(duì)點(diǎn)雙通道高帶寬傳輸模式的全新總線規(guī)范,所連接的設(shè)備分配獨(dú)享通道帶寬,不共享總線帶寬,支持端對(duì)端的可靠性傳輸。pci-e在軟件層面上兼容的pci技術(shù)和設(shè)備,支

3、持pci設(shè)備和內(nèi)存模組的初始化,也就是說驅(qū)動(dòng)程序、操作系統(tǒng)完全兼容。1 pci設(shè)備與驅(qū)動(dòng)關(guān)系pci設(shè)備通常由一組參數(shù)唯一地標(biāo)識(shí),它們被vendorid,deviceid和class nodes所標(biāo)識(shí),即設(shè)備廠商,型號(hào)等,這些參數(shù)保存在 pci_device_id結(jié)構(gòu)中。每個(gè)pci設(shè)備都會(huì)被分配一個(gè)pci_dev變量。所有的pci驅(qū)動(dòng)程序都必須定義一個(gè)pci_driver結(jié)構(gòu)變量,在該變量中包含了這個(gè)pci驅(qū)動(dòng)程序所提供的不同功能的函數(shù),同時(shí),在這個(gè)結(jié)構(gòu)中也包含了一個(gè)device_driver結(jié)構(gòu),這個(gè)結(jié)構(gòu)定義了pci子系統(tǒng)與pci設(shè)備之間的接口。在注冊(cè)pci驅(qū)動(dòng)程序時(shí),這個(gè)結(jié)構(gòu)將被初始化,同時(shí)

4、這個(gè) pci_driver變量會(huì)被鏈接到pci_bus_type中的驅(qū)動(dòng)鏈上去。在pci_driver中有一個(gè)成員struct pci_device_id *id_table,它列出了這個(gè)設(shè)備驅(qū)動(dòng)程序所能夠處理的所有pci設(shè)備的id值。2 基本框架在用模塊方式實(shí)現(xiàn)pci設(shè)備驅(qū)動(dòng)程序時(shí),通常至少要實(shí)現(xiàn)以下幾個(gè)部分:初始化設(shè)備模塊、設(shè)備打開模塊、數(shù)據(jù)讀寫和控制模塊、中斷處理模塊、設(shè)備釋放模塊、設(shè)備卸載模塊。下面給出一個(gè)典型的pci設(shè)備驅(qū)動(dòng)程序的基本框架,從中不難體會(huì)到這幾個(gè)關(guān)鍵模塊是如何組織起來的。staticstruct pci_device_id example_pci_tbl _initda

5、ta =pci_vendor_id_example,pci_device_id_example,pci_any_id,pci_any_id,0,0, example,0,;struct example_pci /* 對(duì)特定pci設(shè)備進(jìn)行描述的數(shù)據(jù)結(jié)構(gòu) */unsigned int magic;struct example_pci *next;/* 使用鏈表保存所有同類的pci設(shè)備 */* . */staticvoid example_interrupt(int irq,void*dev_id,struct pt_regs *regs)/* 中斷處理模塊 */* . */staticstruct

6、 file_operations example_fops = /* 設(shè)備文件操作接口 */owner: this_module,/* demo_fops所屬的設(shè)備模塊 */read: example_read,/* 讀設(shè)備操作*/write: example_write,/* 寫設(shè)備操作*/ioctl: example_ioctl,/* 控制設(shè)備操作*/open: example_open,/* 打開設(shè)備操作*/elease: example_release /* 釋放設(shè)備操作*/* . */;staticstruct pci_driver example_pci_driver =/ * 設(shè)

7、備模塊信息 */name: example_module_name,/* 設(shè)備模塊名稱 */id_table: example_pci_tbl,/* 能夠驅(qū)動(dòng)的設(shè)備列表 */probe: example_probe,/* 查找并初始化設(shè)備 */remove: example_remove /* 卸載設(shè)備模塊 */* . */;staticint _init example_init_module (void)/* . */staticvoid _exit example_cleanup_module (void)pci_unregister_driver(&demo_pci_drive

8、r);module_init( example_init_module);/* 加載驅(qū)動(dòng)程序模塊入口 */module_exit( example_cleanup_module);/* 卸載驅(qū)動(dòng)程序模塊入口 */3 主要數(shù)據(jù)結(jié)構(gòu)上面這段代碼給出了一個(gè)典型的pci設(shè)備驅(qū)動(dòng)程序的框架,是一種相對(duì)固定的模式。主要用了幾個(gè)重要的數(shù)據(jù)結(jié)構(gòu)。struct pci_device_id _u32 vendor, device;/* vendor and device id or pci_any_id*/_u32 subvendor, subdevice;/* subsystem id's o

9、r pci_any_id */_u32 class, class_mask;/* (class,subclass,prog-if) triplet */kernel_ulong_t driver_data;/* data private to the driver */;vendorid:標(biāo)識(shí)硬件制造商,是一個(gè)16位的寄存器。deviceid:設(shè)備id,由制造商選擇,也是一個(gè)16位的寄存器。class:每個(gè)外部設(shè)備屬于某個(gè)類(class),也是一個(gè)16位的寄存器。struct pci_driver struct list_head node;char*name;conststruct pci_

10、device_id *id_table;/* must be non-null for probe to be called */int(*probe)(struct pci_dev *dev,conststruct pci_device_id *id);/* new device inserted */void(*remove)(struct pci_dev *dev);/* device removed */* . */;struct pci_driver它的作用并不僅僅是識(shí)別設(shè)備的id_table結(jié)構(gòu),還包括了檢測(cè)設(shè)備的函數(shù)probe()和卸載設(shè)備的函數(shù)remove(),struct p

11、ci_dev struct list_head bus_list;/* node in per-bus list */struct pci_bus *bus;/* bus this device is on */struct pci_bus *subordinate;/* bus this device bridges to */void*sysdata;/* hook for sys-specific extension */struct proc_dir_entry *procent;/* device entry in /proc/bus/pci */struct pci_slot *slot;/* physical slot this device is in */unsignedint devfn;/* encoded device & function index */unsignedshort vendor;unsignedshort device;/* . */;它詳細(xì)描述了一個(gè)pci設(shè)備幾乎所有的硬件信息,包括廠商id、設(shè)備id、各種資源等。4 結(jié)束語(yǔ)linux pci設(shè)備驅(qū)動(dòng)實(shí)際包括linux pci設(shè)備驅(qū)動(dòng)和具體設(shè)備本身驅(qū)動(dòng)

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論