- Shopping Bag ( 0 items )
From Barnes & NobleThe 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.