順便練一下英文。
CHAPTER 1An Introduction toDevice Drivers
第一章 Device driver 的介紹
One of the many advantages of free operating systems, as typified by Linux, is that their internals are open for all to view.
免費的OS,像Linux, 的眾多優點之一就是code 都是開放的.
The operating system, once a dark and mysterious area whose code was restricted to a small number of programmers, can now be readily examined, understood, and modified by anybody with the requisite skills.
OS, 一個黑暗又神祕的領域,這個領域總是被掌握在少數幾位工程師身上,如今可以容易的被任何有能力的人,檢視、了解及修改.
Linux has helped to democratize operating systems.
Linux 已經成為大眾化的OS.
The Linux kernel remains a large and complex body of code, however, and would-be kernel hackers need an entry point where they can approach the code without being overwhelmed by complexity. Often, device drivers provide that gateway.
Linux kernel 總是很複雜的,對於那些想要成為kernel 專家的人,需要一個起點來了解kernel是比較容易的,而通常這個點就是device drivers.
Device drivers take on a special role in the Linux kernel.
在Linux kernel 裡 Device drivers 扮演了一個特別的角色.
They are distinct “blackboxes” that make a particular piece of hardware respond to a well-defined internal programming interface; they hide completely the details of how the device works.
它們跟所謂的"黑盒子"不同,它們讓一個特定的硬體對應到定義的好的內部程式介面; 它們能夠完全的穩藏硬體的動作。
User activities are performed by means of a set of standardized calls that are independent of the specific driver; mapping those calls to device-specific operations that acton real hardware is then the role of the device driver.
上層的使用者可以在一系列標準的function calls 上運作,而每一個function call 則是對印到獨立的且特定的硬體; 這也就是device driver所做的事。
This programming interface is such that drivers can be built separately from the rest of the kernel and “plugged in”at runtime when needed.
這個programming interface 可以分別build. 當需要時只要 "plugged in"就可. 即使是在rumtmie的時候。
This modularity makes Linux drivers easy to write, to the point that there are now hundreds of them available.
在這樣的模組化情況下,linux drivers 就很容易的去寫它。到目前為止已有幾百個drivers 可用了.
There are a number of reasons to be interested in the writing of Linux device drivers.
有很多理由讓你對設計Linux device drivers 有興趣 。
The rate at which new hardware becomes available (and obsolete!) alone guarantees that driver writers will be busy for the foreseeable future.
硬體不斷的出新換舊,更顯示出可預期的未來,driver 工程師們會一直很忙。
Individuals may need to know about drivers in order to gain access to a particular device that is of interest to them.
他們需要了解drivers ,才能對他們有興趣的device,進行存取
Hardware vendors, by making a Linux driver available for their products, can add the large and growing Linux user base to their potential markets.
讓想要支援Linux的硬體製造商,可以將那些使用Linux 的人,加入他們的潛在市場。
And the opensource nature of the Linux system means that if the driver writer wishes, the source to a driver can be quickly disseminated to millions of users.
而Linux 系統的opensource意謂著driver source 可以快速的散播給幾百萬人,如果driver設計師希望的話。
This book teaches you how to write your own drivers and how to hack around in related parts of the kernel.
這本書教你如何寫你的driver,以及如何處理跟它有關的kernel 部份。
We have taken a device-independent approach; the programming techniques and interfaces are presented, whenever possible, without being tied to any specific device.
我們已經採用裝置獨立的方式;程式技巧和介面都不需要跟任何特定的device 綁在一起。
Each driver is different; as a driver writer, you need to understand your specific device well.
每個driver 都不同; 身為driver 設計者必需要了解你的device.
But most of the principles and basic techniques are the same for all drivers. This book cannot teach you about your device,but it gives you a handle on the background you need to make your device work.
不過對所以的drivers來說,大部份的原則和基本技巧是一樣的。這本書沒辦法告訴你,關於你的device的東西,但可以告訴你如何讓你的device動起來,所需的背景知識
The Role of the Device Driver
Device driver 的角色
As a programmer, you are able to make your own choices about your driver, and
choose an acceptable trade-off between the programming time required and the flexibility of the result.
身為程式設計師,你能夠選擇你的driver, 也能夠在程式需完成的時間及靈活性之中做一個折衷的選擇。
Though it may appear strange to say that a driver is “flexible,” we
like this word because it emphasizes that the role of a device driver is providing
mechanism, not policy.
雖然說driver 是靈活的很奇怪,但是我們喜歡這個字眼,因為這强調了device driver 是一個可以"提供"的機制而不是個方法。
The distinction between mechanism and policy is one of the best ideas behind the
Unix design.
機制和方針之間的不同正是Unix 設計的背後最好的idea.
Most programming problems can indeed be split into two parts: “what
capabilities are to be provided” (the mechanism) and “how those capabilities can be
used” (the policy).
大部份設計的問題,可以正好分成兩個部份:"什麼樣的能力可以被提供"(機制)和"哪些能力如何被使用"(方針)
If the two issues are addressed by different parts of the program,or even by different programs altogether, the software package is much easier to develop and to adapt to particular needs.
如果這兩個問題被提出來在同一個程式不同的部份,或甚至完全不同的程式,那程式就很容易去研發也容易去適應特定的需求。
For example, Unix management of the graphic display is split between the X server,
which knows the hardware and offers a unified interface to user programs, and the
window and session managers, which implement a particular policy without knowing
anything about the hardware.
舉例來說,Unix 的圖形顯示管理就分X server(知道硬體也提供一個統一的介面給用的程式)和window, 還有session managers(實現了一個特定的方法在不知道硬體的情形下)。
People can use the same window manager on different hardware, and different users can run different configurations on the same workstation.
人們可以用一樣的window manager 在不同的硬體上跑,或者是不同的user 可以跑不同的組態在同一個workstation。
Even completely different desktop environments, such as KDE and GNOME, can coexist on the same system.
或甚至完全不同的桌面環境,像是KDE和GNOME,可以共存在同一個系統。
Another example is the layered structure of TCP/IP networking: the operating system offers the socket abstraction, which implements no policy regarding the data to be transferred, while different servers are in charge of the services (and their associated policies).
另一個例子是TCP/IP 網路的分層架構: 當不同的server再提供服務時(提供和何傳送資料的方法),作業系統就有提供socket抽像層(不提供任何方法跟被傳送的資料有關)
Moreover, a server like ftpd provides the file transfer mechanism, while users can use whatever client they prefer; both command-line and graphic clients exist, and anyone can write a new user interface to transfer files.
還有,像FTP 這樣的server 有提供檔案傳輸的機制,但是無論使用者用什麼介面都可用這個機制;command-line 和繪圖介面都可同時存在,並且任何人都可以寫個新的介面來傳送檔案
Where drivers are concerned, the same separation of mechanism and policy applies.
那drivers 要關切的,就是the same separation of mechanism and policy applies
The floppy driver is policy free—its role is only to show the diskette as a continuous array of data blocks. Higher levels of the system provide policies, such as who may access the floppy drive, whether the drive is accessed directly or via a filesystem, and whether users may mount filesystems on the drive.
軟碟 driver 不提供任何方法-它的角色就是只有顯示一個連續資料的陣列。而上層的系統則提供方法來讓任何人直接存取軟碟或通過檔案系統。
Since different environments usually need to use hardware in different ways, it’s important to be as policy free as possible.
一但在不同的環境下,用不同的方式,經常使用硬體,driver盡可能的不限制使用方法,就顯的很重要。
When writing drivers, a programmer should pay particular attention to this fundamental concept: write kernel code to access the hardware, but don’t force particular policies on the user, since different users have different needs.
當要設計drivers時,設計者們應該要特別注意這個重要的觀念: 寫一個在kernel的程式,來存取硬體,而不是要求使用者用特定的方法來用你的硬體,因為不同的使用者有不同的需要。
The driver should deal with making the hardware available, leaving all the issues about how to use the hardware to the applications.
driver 應該要讓硬體可以被使用,而不要管應用程式要如何使用硬體
A driver, then, is flexible if it offers access to the hardware capabilities without adding constraints.
然後driver也要夠靈活,如果它提供個能力來無限制的使用硬體
Sometimes, however, some policy decisions must be made. For example, a digital I/O driver may only offer byte-wide access to the hardware in order to avoid the extra code needed to handle individual bits.
然而,有時候有些方法是要被確定的。例如,一個數位I/O driver可能只提供byte-wide 的存取,來存取硬體來避免要額外的程式來處理獨立的bits
You can also look at your driver from a different perspective: it is a software layer
that lies between the applications and the actual device.
你也可以用不同的觀點來看你的driver: 它是一個軟體躺在應用程式跟實體device 的中間。
This privileged role of the driver allows the driver programmer to choose exactly how the device should appear: different drivers can offer different capabilities, even for the same device.
對於一個扮演有特權的角色的driver來說,允許driver 設計者可以決定device 要如何見人: 甚至於同一個device,可以有不同的drivers來提供不同的能力。
The actual driver design should be a balance between many different considerations. For instance, a single device may be used concurrently by different programs, and the
driver programmer has complete freedom to determine how to handle concurrency.
實際的driver設計應該要在許多不同的顧慮中取得平衡。舉例來說,一個單一的device可能同時被不同的程式使用,而driver 的設計者有完全的自由來決定如何處理這樣的同時發生的情況。
You could implement memory mapping on the device independently of its hardware
capabilities, or you could provide a user library to help application programmers
implement new policies on top of the available primitives, and so forth.
你可以寫個記憶體對映到一個完全跟硬體無關的device,或者你也可以提供一個user library 來幫助應用程式的設計者在可用的原素上寫些新的方法來使用,等等。
One major consideration is the trade-off between the desire to present the user with as many options as possible and the time you have to write the driver, as well as the need to keep things simple so that errors don’t creep in.
一個主要的考量就是,不但要在盡可能的給user選擇的權利和完成driver所需的時間中取得妥協,還要讓它簡單,以致於錯誤數量不會一直的上升。
Policy-free drivers have a number of typical characteristics. These include support for both synchronous and asynchronous operation, the ability to be opened multiple
times, the ability to exploit the full capabilities of the hardware, and the lack of software layers to “simplify things” or provide policy-related operations.
不含使用方法的driver 有很多特性。像是同步和非同步的運作,可以被開啟很多次,可以被盡情的使用,或是沒有軟體層讓它很簡單,或提供有特定方法的運作。
Drivers of this sort not only work better for their end users, but also turn out to be easier to write and maintain as well. Being policy-free is actually a common target for software designers.
這種特性的drivers 不只對end usres來說很好用,也容易來撰寫及維護。像這樣的不限制使用方法的driver 其實是軟體設計者的共同目標。
Many device drivers, indeed, are released together with user programs to help with
configuration and access to the target device.
透過使用者的程式幫助設定並存取目標的device,確實許多device drivers 是互相關連在一起的.
Those programs can range from simple utilities to complete graphical applications.
這些程式可以將簡單的工具延申到一個完整的圖形應用程式。
Examples include the tunelp program, which adjusts how the parallel port printer driver operates, and the graphical cardctl utility that is part of the PCMCIA driver package. Often a client library is provided as well, which provides capabilities that do not need to be implemented as part of the driver itself.
tunelp 程式就是個例子,它是用來調節並列port(印表機的運作),及繪圖 cardctl 系統工具(PCMCIA driver 包的一部份)。像client library 也是經常被提供,這樣的library 就提供了一些不需要在driver 裡寫的一些功能
The scope of this book is the kernel, so we try not to deal with policy issues or with application programs or support libraries. Sometimes we talk about different policies and how to support them, but we won’t go into much detail about programs
using the device or the policies they enforce. You should understand, however, that
user programs are an integral part of a software package and that even policy-free
packages are distributed with configuration files that apply a default behavior to the underlying mechanisms.
這本書是範疇在kernel,所以我們試著不要處理applicantion如何用的問題或是支援資料庫。有時我們會討論到不同的方法和如何支援他們,但我們不會太仔細的討論程式如何使用device,或是他們實施什麼樣的方法。然而,你需要了解,使用者程式是整個軟體組件的一部份,就算是(不含使用方法)的組件也是有設定檔,來設定預設的行為來實現基本的的機制。
No comments:
Post a Comment