在進入 Driver 的實作之前,我們必需先要有個立足點,
了解我們要知道什麼事,以及將要做什麼事。
==================================
A.> Background?
1. 當然,要寫 driver,大家應該要先會 c,
(可是我超弱…總之,這部份不是整理與分享的重點)
2. 既然是要寫 linux 的 driver,
至少要能了解一些 Linux 的指令與運作的觀念才好,
(這我也超弱…所以,有分享的部份知道就好 ==")。
==================================
B.> Driver 是 什麼?
Driver 位於 Kernel space,用來溝通
User space 的 porgram 與 底層的 Hardware。
再具體一點來說,Linux 將裝置視為"File",
而在 User space 的程式,可能會透過
open、read、write、close 之類的 System call,
或者透過 C lib 的 fopen、fprintf 等 function,
來對一個裝置(即一個檔案)做開啟、讀寫的動作,
而寫 Driver,就是要實作這些 open、read、write、
close、ioctl、lseek…等 System call。
(不過中間還是有透過 Kernel 做掉一些事情)
==================================
c.> 寫 Driver 要了解什麼事情?
1. Driver 在 Kernel space,沒有 c lib 可用,因此,
我們要了解有哪些可用的 Kernel API,能做到什麼事,
更甚者,最好能了解一些 Kernel 的原理。
2. 除了那些 system call 的實作,還需要了解
Concurrency and Race Conditions、
Time, Delays, and Deferred Work、
allocating memory 、
I/O port, I/O memory、
Interrupt handling…
以及各種週邊裝置相關的知識。
==================================
好,序篇就先到這裡,
既然 Driver 是位於 Kernel space,
也是透過 Kernel API 來實作 System call,
因此,Driver 也與 Kernel 有著莫大的關係。
Kernel 的範圍實在是太廣了,
許多細節有相關的部份再聊,也僅止於我知道的部份。
下一篇,我們將非常粗略的了解相關的一點點背景,
以及如何編譯 Kernel。