Chapter 1. An Introduction to Device Drivers

One of the many advantages of free operating systems, as typified by Linux, is that their internals are open for all to view. 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. Linux has helped to democratize operating systems. 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 为代表的免费操作系统的众多优点之一是其内部结构对所有人开放。 操作系统曾经是一个黑暗而神秘的领域,其代码仅限于少数程序员,现在任何具备必要技能的人都可以轻松地检查、理解和修改。 Linux 有助于使操作系统民主化。 然而,Linux 内核仍然是一个庞大而复杂的代码体,潜在的内核黑客需要一个入口点,他们可以在不被复杂性压倒的情况下接近代码。 通常,设备驱动程序提供该入口

Device drivers take on a special role in the Linux kernel. They are distinct "black boxes" 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 act on real hardware is then the role of the 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. This modularity makes Linux drivers easy to write, to the point that there are now hundreds of them available. 设备驱动程序在 Linux 内核中扮演着特殊的角色。 它们是不同的“黑匣子”,使特定的硬件响应定义良好的内部编程接口; 它们完全隐藏了设备工作原理的细节。 用户活动是通过一组独立于特定驱动程序的标准化调用来执行的; 将这些调用映射到作用于真实硬件的特定于设备的操作是设备驱动程序的角色。 这种编程接口使得驱动程序可以与内核的其余部分分开构建,并在需要时在运行时“插入”。 这种模块化使得 Linux 驱动程序易于编写,以至于现在有数百个可用的驱动程序。

There are a number of reasons to be interested in the writing of 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. Individuals may need to know about drivers in order to gain access to a particular device that is of interest to them. Hardware vendors, by making a Linux driver available for their products, can add the large and growing Linux user base to their potential markets. And the open source 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设备驱动程序的写作有兴趣。 新硬件可用的速度(并且已过时!)单独保证驱动开发人员将忙于可预见的未来。 个人可能需要了解驱动程序,以便访问对他们感兴趣的特定设备。 硬件供应商是通过为其产品提供Linux驱动程序,可以将大型和不断增长的Linux用户群添加到其潜在市场。 Linux系统的开源性质意味着,如果驱动开发人员希望,驱动的源代码可以快速传播到数百万用户。

This book teaches you how to write your own drivers and how to hack around in related parts of the kernel. We have taken a device-independent approach; the programming techniques and interfaces are presented, whenever possible, without being tied to any specific device. Each driver is different; as a driver writer, you need to understand your specific device well. 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. 这本书教你如何编写自己的驱动程序以及如何破解内核的相关部分。 我们采取了独立于设备的方法; 尽可能提供编程技术和接口,而不与任何特定设备绑定。 每个驱动都不一样; 作为驱动程序编写者,您需要很好地了解您的特定设备。 但大多数原理和基本技术对所有驱动程序都是相同的。 这本书不能教你有关你的设备的知识,但它可以让你了解使你的设备工作所需的背景知识。

As you learn to write drivers, you find out a lot about the Linux kernel in general; this may help you understand how your machine works and why things aren't always as fast as you expect or don't do quite what you want. We introduce new ideas gradually, starting off with very simple drivers and building on them; every new concept is accompanied by sample code that doesn't need special hardware to be tested. 当你学习编写驱动程序时,你会发现很多关于 Linux 内核的知识。 这可以帮助您了解您的机器是如何工作的,以及为什么事情并不总是像您期望的那样快,或者没有完全按照您的意愿行事。 我们逐渐引入新的想法,从非常简单的驱动程序开始,并以此为基础; 每个新概念都附有示例代码,无需特殊硬件进行测试。

This chapter doesn't actually get into writing code. However, we introduce some background concepts about the Linux kernel that you'll be glad you know later, when we do launch into programming. 本章实际上并没有涉及编写代码。 然而,我们介绍了一些关于 Linux 内核的背景概念,当我们开始编程时,您会很高兴您知道这些概念。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mounter625

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值