Preface

As an electronic engineer and a do-it-yourself kind of person, I have always enjoyed using the computer to control external hardware. Ever since the days of my father’s Apple-2e, I have been looking for another platform where I could connect my custom circuitry and write my own driver software. Unfortunately, the PC of the eighties wasn’t powerful enough, at either the software or the hardware level--the internal design of the PC was much worse than that of the Apple-2e, and the available documentation for a long time was unsatisfying. But then Linux appeared, and I decided to give it a try by buying an expensive 386 motherboard and no commercial software at all.

At the time, I was using Unix systems at the university, and was greatly excited by the smart operating system, particularly when supplemented by the even smarter utilities that the GNU project donates to the user base. Running Linux on my own PC motherboard has always been an interesting experience, and I could even write my own device drivers and play with the soldering iron once again. I continue to tell people ``when I grow up, I wanna be a hacker,'' and Linux is the perfect platform for such dreams. That said, I don’t know if I will ever grow up.

As Linux matures, more and more people get interested in writing drivers for custom circuitry and for commercial devices. As Linus Torvalds noted, ``We’re back to the times when men were men and wrote their own device drivers.''

Not being able to write innovative code, I began writing technical articles for Linux Journal as a contribution to the Linux community; later, Andy Oram at O’Reilly expressed an interest in having me write a whole book about device drivers, and I accepted this task. Although real hackers can find all the necessary information in the official kernel sources, a written text can be helpful in developing programming skills. The text you are approaching is the result of hours of patient grepping through the kernel sources, and I hope the final result is worth the effort it took. I hope this book will be useful as a starting point for people who want to become kernel hackers but don’t know where to start.

Audience of This Book

On the technical side, this text should offer a hands-on approach to understanding the kernel internals and some of the design choices made by the Linux developers. Although the main and official target of the book is teaching how to write device drivers, the enclosed material should give an intriguing overview of kernel implementation as well.

This book should be an interesting source of information both for people who want to play with their computer and for technical programmers who need to deal with the inner levels of a Linux box. Note that ``a Linux box'' is a wider concept than ``a PC running Linux'' as many platforms are supported by our operating system, and kernel programming is by no means bound to a specific platform.

The Linux enthusiast should find in this book enough food for her mind to start playing with the code base, and then be able to join the group of developers who are continuously working on new capabilities and performance enhancements. Linux is still a work-in-progress, and there’s always a place for new programmers to jump into the game.

If, on the other hand, you are just trying to write a device driver for your own device and don’t want to muck with the kernel internals, the text should be modularized enough to fit your needs as well. If you don’t want to go deep into the details, you can just skip the most technical sections and stick to the standard API used by device drivers to seamlessly integrate with the rest of the kernel.

The main target of this book is writing kernel modules for version 2.0 of the Linux kernel. A module is object code that can be loaded at run time to add new functionality to a running kernel. The discussion also covers version 1.2 of the kernel, and the last chapter describes the changes that the driver interface underwent from version 2.0 to version 2.1.43 (the latest-and-greatest at the time the book went to technical review).

Get Linux Device Drivers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.