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. Linux is the fastest-growing segment of the UNIX market and is winning over enthusiastic adherents in many application areas. This book reveals information that heretofore has been passed by word-of-mouth or in cryptic source code comments, showing how to write a driver for a wide range of devices.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, which can be executed without special hardware.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 version 2.0, but also covers 1.2.13 and experimental versions up to 2.1.43. You are also told how to maximize portability among hardware platforms.Contents include:
- Building a driver and loading modules
- Complete character, block, and network drivers
- Debugging a driver
- Timing
- Memory management and DMA
- Interrupts
- Portability issues
- Peripheral Component Interconnect (PCI)
- A tour of kernel internals
Preface; Audience of This Book; Organization of the Material; Background Information; Sources for Further Information; Relevant Books; Conventions Used in This Book; We’d Like to Hear from You; Acknowledgments; Chapter 1: An Introduction to the Linux Kernel; 1.1 The Role of the Driver Writer; 1.2 Splitting the Kernel; 1.3 Classes of Devices and Modules; 1.4 Security Issues; 1.5 Version Numbering; 1.6 License Terms; 1.7 Overview of the Book; Chapter 2: Building and Running Modules; 2.1 Modules Versus Applications; 2.2 Compiling and Loading; 2.3 The Kernel Symbol Table; 2.4 Initialization and Shutdown; 2.5 Using Resources; 2.6 Automatic and Manual Configuration; 2.7 Doing It in User Space; 2.8 Quick Reference; Chapter 3: Char Drivers; 3.1 The Design of scull; 3.2 Major and Minor Numbers; 3.3 File Operations; 3.4 The file Structure; 3.5 Open and Release; 3.6 Scull’s Memory Usage; 3.7 Read and Write; 3.8 Playing with the New Devices; 3.9 Quick Reference; Chapter 4: Debugging Techniques; 4.1 Debugging by Printing; 4.2 Debugging by Querying; 4.3 Debugging by Watching; 4.4 Debugging System Faults; 4.5 Using a Debugger; Chapter 5: Enhanced Char Driver Operations; 5.1 ioctl; 5.2 Blocking I/O; 5.3 Select; 5.4 Asynchronous Notification; 5.5 Seeking a Device; 5.6 Access Control on a Device File; 5.7 Quick Reference; Chapter 6: Flow of Time; 6.1 Time Intervals in the Kernel; 6.2 Knowing the Current Time; 6.3 Delaying Execution; 6.4 Task Queues; 6.5 Kernel Timers; 6.6 Quick Reference; Chapter 7: Getting Hold of Memory; 7.1 The Real Story of kmalloc; 7.2 get_free_page and Friends; 7.3 vmalloc and Friends; 7.4 Playing Dirty; 7.5 Quick Reference; Chapter 8: Hardware Management; 8.1 Using I/O Ports; 8.2 Using the Parallel Port; 8.3 Accessing Memory on Device Boards; 8.4 Accessing the Text-Mode Video Buffer; 8.5 Quick Reference; Chapter 9: Interrupt Handling; 9.1 Preparing the Parallel Port; 9.2 Installing an Interrupt Handler; 9.3 Implementing a Handler; 9.4 Bottom Halves; 9.5 Interrupt Sharing; 9.6 Interrupt-Driven I/O; 9.7 Race Conditions; 9.8 Version Dependencies of IRQ Handling; 9.9 Quick Reference; Chapter 10: Judicious Use of Data Types; 10.1 Use of Standard C Types; 10.2 Assigning an Explicit Size to Data Items; 10.3 Interface-Specific Types; 10.4 Other Portability Issues; 10.5 Quick Reference; Chapter 11: Kerneld and Advanced Modularization; 11.1 Loading Modules on Demand; 11.2 Version Control in Modules; 11.3 Persistent Storage Across Unload/Load; 11.4 Quick Reference; Chapter 12: Loading Block Drivers; 12.1 Registering the Driver; 12.2 The Header File blk.h; 12.3 Handling Requests; 12.4 How Mounting Works; 12.5 The ioctl Method; 12.6 Removable Devices; 12.7 Partitionable Devices; 12.8 Interrupt-Driven Block Drivers; 12.9 Quick Reference; Chapter 13: Mmap and DMA; 13.1 Memory Management in Linux; 13.2 The mmap Device Operation; 13.3 Direct Memory Access; 13.4 Quick Reference; Chapter 14: Network Drivers; 14.1 How snull Is Designed; 14.2 Connecting to the Kernel; 14.3 The device Structure in Detail; 14.4 Opening and Closing; 14.5 Packet Transmission; 14.6 Packet Reception; 14.7 Interrupt-Driven Operation; 14.8 The Socket Buffers; 14.9 Address Resolution; 14.10 Load-Time Configuration; 14.11 Run-Time Configuration; 14.12 Custom ioctl Commands; 14.13 Statistical Information; 14.14 Multicasting; 14.15 Quick Reference; Chapter 15: Overview of Peripheral Buses; 15.1 The PCI Interface; 15.2 A Look Back: ISA; 15.3 Other PC Buses; 15.4 Sbus; 15.5 Quick Reference; Chapter 16: Physical Layout of the Kernel Source; 16.1 Booting the Kernel; 16.2 Before Booting; 16.3 The Init Process; 16.4 The kernel Directory; 16.5 The mm Directory; 16.6 The fs Directory; 16.7 Networking; 16.8 IPC and lib Functions; 16.9 Drivers; 16.10 Architecture Dependencies; Chapter 17: Recent Developments; 17.1 Modularization; 17.2 File Operations; 17.3 Accessing User Space; 17.4 Task Queues; 17.5 Interrupt Management; 17.6 Bit Operations; 17.7 Conversion Functions; 17.8 vremap; 17.9 Virtual Memory; 17.10 Handling Kernel-Space Faults; 17.11 Other Changes; Colophon;