• 沒有找到結果。

The Different Between two Platforms Driver

2 The Comparison of Device Driver Model

2.6 The Different Between two Platforms Driver

Table 4: The Example with Linux Hardware ID

Windows Driver存取資料的方式有兩種,分別為Buffer I/O與Direct I/O;Buffer I/O 為預設值,用在資料量小、傳輸速度較慢的Device,如滑鼠及鍵盤;而Direct I/O則用在 資料量大、需要快速傳輸的Device,像PIO或DMA的傳輸方式,常見的Device有SCSI Disk 及VGA Card。在Linux也依存取方式將Driver分成兩種,一為處理少量資料的Character Device Driver,另一種則是以Block的單位來存取資料的Block Device Driver,如Table 5[22]。

Windows Linux Characteristic Device

Buffer I/O Character Device Driver

Slow/small size,but it’s default and easy to use/nonpage pool

Mouse、Keyboard

Direct I/O Block Device Driver

Fast/large size,but hard to use. (PIO or DMA)

SCSI Disk、VGA Card

Table 5: Windows and Linux's Access Type

2.6 The Different Between two Platforms Driver

兩個平台其Device Driver各有其特有做法及部分的差異,如Table 6,本節就其差異 做討論。

Windows Only Linux Only

IRP GPL/non GPL

Filter driver likely function to optimistic compiler WMI Use set bit & test bit

Unicode IRQL Function can be pagable/non-pagable

Similar Issue

Symbolic link to access by application Symbolic link to link with sysfs

Major/Minor function Major/Minor device

Pass Parameter Using INF File Pass Parameter Using insmod Command Put a lot information in INF file Put in driver code

Table 6: The Different between Windows and Linux Driver

z Windows Only,也就是Windows存在但Linux不存在的部分:

- Windows把某些資訊集合起來,放在一個特定的IRP(I/O request packet)Structure 裏,因此各個Entry Function都使用IRP變數來傳遞,Linux沒有這樣統一的封包格式,因 此每個Entry Function所傳入的變數都不一樣。

- 因Windows Driver不像Linux為開放原始碼,因此無法看到Source Code,一般使 用者無法自行修改/重新編譯Driver,所以微軟創造了Upper及Lower Filter Driver,能有彈 性的掛在Function Driver上下層去觀察及修改Packet的資料,而Linux就可以直接改Driver Code,因此少有這層動作。

- Windows有Windows Management Instrumentation(WMI)的設定的機制,可向系 統管理員報告管理訊息及允許用戶設定控制設備的操作,Linux則沒有。

- Windows所有字串都要轉成Unicode的資料型別才能與使用者應用程式溝通,

Linux則沒有這樣的資料型別要轉換。

- Windows Driver的各個函數均有指定其IRQ層級(Interrupt Request Level),限制 各個函數要在某個層級才能執行,以整增加整個Driver的執行速度,Linux則沒有。

- Windows有限制某些Function一定要使用不可分頁的分頁區(Nonpagable Page),強制該行程在整個Driver執行期間不可被置換空間(Swap Out)到記憶體外,在 Linux之下沒有規定,如下所示,函數IsoUsb_DispatchCreate被指定要放在可分頁區:

#pragma alloc_text(PAGE, IsoUsb_DispatchCreate)

z Linux Only,也就是Linux存在但Windows不存在的部分:

- Linux有unlikely函數來加強編譯時最佳化的處理,Windows則沒有。

- 因Linux為Open Souce的平台,因此其Linux Module有區分GPL及non GPL,如 果您將Driver設為non-GPL則會因此無法使用GPL only的Symbols。

- Linux有set bit及test_bit的位元操作(Bit Operations),Windows則沒有。

z Similar Issue,也就是兩個平台相近的部分:

- Windows及Linux都有提到Symbolic Link,但兩邊意義不同。Windows的 Symbolic Link可以開啟一個讓Application存取的介面,而Linux則是用來建立sysfs內 Device與Driver的關聯。

- Windows及Linux都有提到major及minor number但兩邊意義不同。Window的 major及minor是指Driver Entry Function;Linux則是12 bits的major加上20 bits的minor組成 一個32 bits的Unique ID,這部分類似Windows的16 bytes GUID,用來辨識一個唯一 (Unique)的Device。

- Linux在插入模組(insmod)時,可帶入參數,在Windows則是在INF檔帶入參數。

- Windows 有許多 Driver 資訊被放在 INF 檔,而 Linux 則是放在程式內,如 Class、

Hardware ID、Input Parameter、Device Description、Device Display Name,因此這部分也 需撰寫轉換到 Linux 對應的程式。

相關文件