Updated to cover version 2.4.x of the Linux kernel, the second edition of Linux Device Drivers remains the best general-purpose, paper-bound guide for programmers wishing to make hardware devices work under the world's most popular open-source operating system. The authors take care to show how to write drivers that are portable--that is, that compile and run under all popular Linux platforms. That, along with the fact that they're careful to explain and illustrate concepts, makes this book very well suited to any programmer familiar with C but not with the hardware-software interface. It's worth noting that the emphasis in the title is on "device drivers" as much as "Linux." This book will make sense to you if you've never written a driver for any platform before. It helps if you have some Linux or Unix background, but even that is secondary as a prerequisite to C skill.
For a programming text--and one concerned with low-level instructions and data structures, at that--this book is remarkably rich in prose. You'll typically want to read this book straight through, more or less skipping the code samples, before sketching out your plan for the driver you need to write. Then, go back and pay closer attention to the sections on specific details you need to implement, like custom task queues. For coding-time details about specific system calls and programming techniques, count on the index to point you to the right passages. --David Wall
Topics covered: Techniques for writing hardware device drivers that run under Linux kernels 2.0.x through 2.2.x. Sections show how to manage memory, time, interrupts, ports, and other details of the hardware-software interface.
Book Description
Device drivers literally drive everything you're interested in--disks, monitors, keyboards, modems--everything outside the computer chip and memory. And writing device drivers is one of the few areas of programming for the Linux operating system that calls for unique, Linux-specific knowledge. For years now, programmers have relied on the classic Linux Device Drivers from O'Reilly to master this critical subject. Now in its third edition, this bestselling guide provides all the information you'll need to write drivers for a wide range of devices. Over the years the book has helped countless programmers learn:how to support computer peripherals under the Linux operating system how to develop and write software for new hardware under Linuxthe basics of Linux operation even if they are not expecting to write a driverThe new edition of Linux Device Drivers is better than ever. The book covers all the significant changes to Version 2.6 of the Linux kernel, which simplifies many activities, and contains subtle new features that can make a driver both more efficient and more flexible. Readers will find new chapters on important types of drivers not covered previously, such as consoles, USB drivers, and more. Best of all, you don't have to be a kernel hacker to understand and enjoy this book. All you need is an understanding of the C programming language and some background in Unix system calls. And for maximum ease-of-use, the book uses full-featured examples that you can compile and run without special hardware. Today Linux holds fast as the most rapidly growing segment of the computer market and continues to win over enthusiastic adherents in many application areas. With this increasing support, Linux is now absolutely mainstream, and viewed as a solid platform for embedded systems. If you're writing device drivers, you'll want this book. In fact, you'll wonder how drivers are ever written without it.
Book Info
Handbook for Linux users who want to support computer peripherals or develop new hardware and run it under Linux. Requires only some knowledge of C and some background in Unix system calls. Provides insights into address spaces, asynchronous events, and I/O. Softcover. DLC: Linux device drivers (Computer programs).
Linux Device Drivers, 3rd Edition FROM OUR EDITORS
The Barnes & Noble Review
There are a world of devices just waiting to have Linux devices written for them, and a world of users who will be forever grateful if you take on the quest. It's a quest that'll take you deep inside the bowels of the Linux kernel -- and offer powerful psychic rewards when you succeed. Take this guide on your journey: Linux Device Drivers, Second Edition.
Alessandro Rubini and Jonathan Corbet have done an excellent job of getting their arms around this very big subject. They first introduce modularization and what it means for modules to run in kernel space rather than user space. (Those who've built device drivers for Windows NT will recognize this distinction.)
You'll learn how to set up kernel modules properly, avoiding header files and eschewing namespace pollution (remember, even the smallest kernel module links to the entire kernel, and can wreak havoc if you're not careful). You'll also learn how modules use system resources such as memory, I/O ports, and IRQs.
By Chapter 3, you're writing a complete character device driver -- which is all that some simple hardware devices will need. To illuminate the techniques they present, Rubini and Corbet draw upon examples from scull, the Linux Simple Character Utility for Loading Localities (which, in essence, treats an area of memory as if it were a device). They introduce file operations and struct files, and introduce the problem of race conditions (a classic problem with device drivers which will get much deeper consideration later in the book).
Once you've learned how to provide for read and write operations, you'll learn how to perform a variety of hardware control tasks using ioctl, a device-specific entry point for the driver to handle commands. The authors warn you about some gotchas you might otherwise not notice -- gotchas related to numbering your commands, and working with pointers to user space.
Real-world drivers need to pay especially careful attention to timing. Linux Device Drivers contains a full chapter on the topic. It introduces the timer interrupt, shows how to retrieve the current time, how to delay execution of a piece of code for a specified amount of time (to give the hardware time to finish what it's doing); and how to schedule functions using task queues, tasklets, and kernel timers.
Early in the book, Rubini and Corbet introduce debugging -- a special challenge when it comes to device drivers, which don't lend themselves to easy execution or tracing by a debugger. (It doesn't help that Linus dislikes interactive debuggers almost as much as he likes penguins, and won't build one in.) Your options include debugging by printing (using printk); by querying; and by watching. If you still can't track a bug down, you can at least collect information about its behavior when it generates a system fault.
There's a short but extremely valuable chapter on portability. The Linux kernel is extremely portable, but you have to watch out for your data typing, and be suspicious of explicit constant values (if you've lived your life in the x86 universe, you may find time intervals, page sizes, and byte order to be especially problematic).
From start to finish, each chapter of Linux Device Drivers covers a single problem; for example, getting hold of memory, managing I/O, handling interrupts. Part II moves on to block drivers, network drivers, peripheral buses, and finally, a quick look at the layout of kernel source. (The book's written for the 2.4 kernel but also covers 2.2, and offers some workarounds for 2.0. Throughout, the authors call your attention to significant changes in the latest kernels, including changes to resource management, wait queues, and the block device layer, to name a few examples.)
Rubini and Corbet won't completely absolve you from grepping through kernel sources, but they've done a lot of that work for you. You'll still need to join the Linux-kernel mailing list, but hey: you'll understand what they're talking about! (Bill Camarda)
Bill Camarda is a consultant, writer, and web/multimedia content developer with nearly 20 years' experience in helping technology companies deploy and market advanced software, computing, and networking products and services. His 15 books include Special Edition Using Word 2000 and Upgrading & Fixing Networks For Dummies®, Second Edition.
ANNOTATION
"We're back to the times when men were men and wrote their own device drivers." -- Linus Torvalds. Of course, this is also a very good publication for the excellent, equally facile (and less macho) kernel and hardware programmers of the opposite gender. Comments aside, this is a very good (and to-date the only publication) for programmers and developers that covers device drivers in-depth. The author assumes that you understand the Linux kernel and C code.
FROM THE PUBLISHER
This book, a classic entering its third edition, is a must-read for anyone who wants to support computer peripherals under the Linux operating system, wants to run new hardware under Linux, or is simply interested in Linux kernel programming in general. Linux Device Drivers reveals information-heretofore shared only by word of mouth or in cryptic source code comments-on how to write drivers for a wide range of devices.
The authors of the book are leaders in the Linux community. Jonathan Corbet is an occasional kernel contributor and the executive editor of the highly regarded LWN.net news and information site. Alessandro Rubini is a contributor to Linux code and a central figure in the vibrant Italian Linux community. Greg Kroah-Hartman is the current kernel maintainer for the USB, PCI, and driver core subsystems documented in this book.
This new edition has been competely updated for Version 2.6.10 of the Linux kernel. This version of the kernel has rationalized and simplified several ways of doing common tasks, such as plug and play, interaction with user space through the sysfs filesystem, and management of multiple devices on standard buses.
You don't have to be a kernel hacker to understand and enjoy Linux Device Drivers; all you need is an understanding of C and some background in Unix system calls. You'll learn how to write drivers for character devices, block devices, and network interfaces, guided by full-featured examples you can compile and run without special hardware. The PCI, USB, and tty (terminal) subsystems each get their own chapter. For those who are curious about how an operating system does its job, this book provides insights into address spaces, asynchronous events, and I/O.
SYNOPSIS
This book is for anyone who wants to support computer peripherals under the Linux operating system or who wants to develop new hardware and run it under Linux. As the fastest-growing segment of the Unix market, Linux is winning over enthusiastic adherents in many application areas, and is being viewed more and more as a good platform for embedded systems. Linux Device Drivers shows how to write drivers for a wide range of devices, revealing information heretofore available only by word-of-mouth or in cryptic source code comments.
You don't have to be a kernel hacker to understand and enjoy this book; all you need is an understanding of C and some background in Unix system calls. Drivers for character devices, block devices, and network interfaces are all described in step-by-step form and are illustrated with full-featured examples that show driver design issues and can be executed without special hardware. Major changes in the second edition include support for symmetric multiprocessing (SMP), Universal Service Bus (USB), and some new platforms.
For those who are curious about how an operating system does its job, this book provides insights into address spaces, asynchronous events, and I/O.
Portability is a major concern in the text. The book is centered on kernel version 2.4, but includes information for kernels back to 2.0 where feasible. You'll also learn how to maximize portability among hardware platforms; examples were tested on IA32 (PC) and IA64, PowerPC, SPARC and SPARC64, Alpha, ARM, and MIPS.
Contents include:
Building a driver and loading modules
Complete character, block, and network drivers
Debugging a driver
Timing
Handling symmetric multiprocessing (SMP) systems
Memory management and DMA
Interrupts
Portability issues
Peripheral Component Interconnect (PCI)