非常好的linux驱动入门,介绍详尽
Linux USB驱动程序基础
来源: ChinaUnix博客日期:2008.04.10 23:55(共有条评论) 我要评论
(
Linux USB Driver Basics
Introduction
Drivers are software components that operating systems use to provide
hardware specific services to applications. This webpage attempts to document
the basics of USB drivers on Linux. The goal here is to provide you with a basic understanding of how USB device drivers on Linux work.
The File Abstraction
Linux, like other Unix derived operating systems, tries to make applications simpler by providing a common hardware abstraction, the File. Essentially, interactions with almost all hardware can be abstracted into the same interface
that the operating system provides for manipulating files. Hence, you can "Open"
a driver, "Read" a driver, "Write" to a driver and "Close" a driver. This
abstraction extends all the way into the application, who can use the same
system calls that it uses to open and manipulate files to talk to hardware.
The way this works is that the kernel creates nodes in the file system,
typically located in /dev that represent a particular interface to a driver. To
talk to a particular driver an application will open the /dev entry associated
with that driver. The file descriptor returned by that open is passed to all
future system calls (read, write, select), and is eventually passed to
close.
Besides drivers, Unix also uses this file paradigm for various different
kinds of IPC, and even for socket communications over a network.
It is quite surprising how many completely different kinds of hardware can be modeled with just 4 operations (open, close, read and write). That said, their
is another very important system call that unix applications developers commonly use, select(). The select() system call allows applications to poll and
determine whether data could be read from, or written to a file descriptor
without blocking.
Sometimes a piece of hardware provides some functionality that doesn't fit
well into this file centric paradigm. To allow for this, unix applications
typically make use of the ioctl() system call. This call takes a numeric value
that is essentially an identifier for a specific piece of functionality in the
driver.
The Job of the Device Driver
Simply stated, it is the job of the driver to provide functions that the
kernel can use to implement this file programming paradigm. Applications do not directly call functions in the driver, instead they call functions in libc that