« LPIC-3 即將登場 | Home | Linux 2.6.20 將正式加入 KVM 驅動程式 » Linux 驅動程式的 I/O, #1: 基本概念jollen 發表於 December 12, 2006 12:02 PM 由本篇日記開始,我們將進行「Linux Device Driver 入門:I/O 處理」的議題討論。這裡所提的 I/O 處理定義是:user process 與 physical device 的 I/O 存取。 在讀「Linux Device Driver 入門:I/O 處理」專欄前,您必須熟悉 Linux 驅動程式的架構,因此「Linux Device Driver 入門:架構層」的專欄是 Jollen's Linux Device Driver 系列專欄的先備知識;此外,接下來的專欄使用的語法也必須對架構層有基本認識後才能看得懂。 Linux 驅動程式 I/O 機制 Linux device driver 處理 I/O 的「基本款」是:
另外「典藏款」則是 mmap,未來在「Linux Device Driver 進階」專欄裡再來討論這個主題。 fops->ioctl ioctl 代表 input/output control 的意思,故名思義,ioctl system call 是用來控制 I/O 讀寫用的,並且是支援 user application 存取裝置的重要 system call。因此,在Linux驅動程式設計上,我們會實作ioctl system call以提供user application讀寫(input/output)裝置的功能。 依此觀念,回到架構篇所舉的 debug card 範例。當 user application 需要將數字顯示到 debug card 時,範例 debug card 0.1.0 便需要實作 ioctl system call,然後在 fops->ioctl 裡呼叫 outb() 將 user application 所指定的數字輸出至 I/O port 80H。 User application 使用 GNU LIBC 的 ioctl() 函數呼叫device driver所提供的命令來「控制」裝置,因此驅動程式必須實作 fops->ioctl 以提供「命令」給使用者。 fops->read & fops->write read/write 是 Linux 驅動程式最重要的 2 個 driver function,也是驅動程式最核心的觀念所在。對驅動程式而言,read/write 的目的是在實作並支援 user application 的 read() 與 write() 函數;user application 是否能正常由硬體讀寫資料,完全掌握在驅動程式的 read/write ethod。 User application 呼叫 read()/write() 函數後,就會執行 fops->read 與 fops->write。read/write method 負責讀取使用者資料與進行裝置的I/O 存取。依照觸發資料傳輸的方式來區分,我們可以將 I/O 裝置分成以下 2 種(from hardware view):
根據I/O處理原理的不同(from software view),可以將 read/write method 的實作策略分成多種排列組合來討論。為了簡化討論內容,未來的日記將鎖定「Interrupt 式的 I/O」來做探討。 --jollen 引用通告如果您想引用這篇文章到您的Blog, |
Top | 授權條款 | Jollen's Forum: Blog 評論、討論與搜尋
Copyright(c) 2006 www.jollen.org
評論 (2)
请问:fops->read & fops->write可以做数据的读写工作,但是fops->ioctl也可以做数据的读写工作(利用copy_to_user和copy_form_user)。请问他们在应用上有哪些区别啊?
由 tanbiao | December 11, 2007 5:05 PM
發表於 December 11, 2007 17:05
漏了一個字母
user application 是否能正常由硬體讀寫資料,完全掌握在驅動程式的 read/write ethod
=>
user application 是否能正常由硬體讀寫資料,完全掌握在驅動程式的 read/write method
由 Fisher | December 25, 2007 5:32 PM
發表於 December 25, 2007 17:32