ebook img

Linux Device Drivers, 3rd Edition PDF

968 Pages·2005·5.16 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Linux Device Drivers, 3rd Edition

Linux Device Drivers, 3rd Edition Table of Contents SPECIAL OFFER: Upgrade this ebook with O’Reilly A Note Regarding Supplemental Files Preface Jon's Introduction Alessandro's Introduction Greg's Introduction Audience for This Book Organization of the Material Background Information Online Version and License Conventions Used in This Book Using Code Examples We'd Like to Hear from You Safari Enabled Acknowledgments Jon Alessandro Greg 1. An Introduction to Device Drivers 1.1. The Role of the Device Driver 1.2. Splitting the Kernel 1.2.1. Loadable Modules 1.3. Classes of Devices and Modules 1.4. Security Issues 1.5. Version Numbering 1.6. License Terms 1.7. Joining the Kernel Development Community 1.8. Overview of the Book 2. Building and Running Modules 2.1. Setting Up Your Test System 2.2. The Hello World Module 2.3. Kernel Modules Versus Applications 2.3.1. User Space and Kernel Space 2.3.2. Concurrency in the Kernel 2.3.3. The Current Process 2.3.4. A Few Other Details 2.4. Compiling and Loading 2.4.1. Compiling Modules 2.4.2. Loading and Unloading Modules 2.4.3. Version Dependency 2.4.4. Platform Dependency 2.5. The Kernel Symbol Table 2.6. Preliminaries 2.7. Initialization and Shutdown 2.7.1. The Cleanup Function 2.7.2. Error Handling During Initialization 2.7.3. Module-Loading Races 2.8. Module Parameters 2.9. Doing It in User Space 2.10. Quick Reference 3. Char Drivers 3.1. The Design of scull 3.2. Major and Minor Numbers 3.2.1. The Internal Representation of Device Numbers 3.2.2. Allocating and Freeing Device Numbers 3.2.3. Dynamic Allocation of Major Numbers 3.3. Some Important Data Structures 3.3.1. File Operations 3.3.2. The file Structure 3.3.3. The inode Structure 3.4. Char Device Registration 3.4.1. Device Registration in scull 3.4.2. The Older Way 3.5. open and release 3.5.1. The open Method 3.5.2. The release Method 3.6. scull's Memory Usage 3.7. read and write 3.7.1. The read Method 3.7.2. The write Method 3.7.3. readv and writev 3.8. Playing with the New Devices 3.9. Quick Reference 4. Debugging Techniques 4.1. Debugging Support in the Kernel 4.2. Debugging by Printing 4.2.1. printk 4.2.2. Redirecting Console Messages 4.2.3. How Messages Get Logged 4.2.4. Turning the Messages On and Off 4.2.5. Rate Limiting 4.2.6. Printing Device Numbers 4.3. Debugging by Querying 4.3.1. Using the /proc Filesystem 4.3.2. The ioctl Method 4.4. Debugging by Watching 4.5. Debugging System Faults 4.5.1. Oops Messages 4.5.2. System Hangs 4.6. Debuggers and Related Tools 4.6.1. Using gdb 4.6.2. The kdb Kernel Debugger 4.6.3. The kgdb Patches 4.6.4. The User-Mode Linux Port 4.6.5. The Linux Trace Toolkit 4.6.6. Dynamic Probes 5. Concurrency and Race Conditions 5.1. Pitfalls in scull 5.2. Concurrency and Its Management 5.3. Semaphores and Mutexes 5.3.1. The Linux Semaphore Implementation 5.3.2. Using Semaphores in scull 5.3.3. Reader/Writer Semaphores 5.4. Completions 5.5. Spinlocks 5.5.1. Introduction to the Spinlock API 5.5.2. Spinlocks and Atomic Context 5.5.3. The Spinlock Functions 5.5.4. Reader/Writer Spinlocks 5.6. Locking Traps 5.6.1. Ambiguous Rules 5.6.2. Lock Ordering Rules 5.6.3. Fine-Versus Coarse-Grained Locking 5.7. Alternatives to Locking 5.7.1. Lock-Free Algorithms 5.7.2. Atomic Variables 5.7.3. Bit Operations 5.7.4. seqlocks 5.7.5. Read-Copy-Update 5.8. Quick Reference 6. Advanced Char Driver Operations 6.1. ioctl 6.1.1. Choosing the ioctl Commands 6.1.2. The Return Value 6.1.3. The Predefined Commands 6.1.4. Using the ioctl Argument 6.1.5. Capabilities and Restricted Operations 6.1.6. The Implementation of the ioctl Commands 6.1.7. Device Control Without ioctl 6.2. Blocking I/O 6.2.1. Introduction to Sleeping 6.2.2. Simple Sleeping 6.2.3. Blocking and Nonblocking Operations 6.2.4. A Blocking I/O Example 6.2.5. Advanced Sleeping 6.2.6. Testing the Scullpipe Driver 6.3. poll and select 6.3.1. Interaction with read and write 6.3.2. The Underlying Data Structure 6.4. Asynchronous Notification 6.4.1. The Driver's Point of View 6.5. Seeking a Device 6.5.1. The llseek Implementation 6.6. Access Control on a Device File 6.6.1. Single-Open Devices 6.6.2. Restricting Access to a Single User at a Time 6.6.3. Blocking open as an Alternative to EBUSY 6.6.4. Cloning the Device on open 6.7. Quick Reference 7. Time, Delays, and Deferred Work 7.1. Measuring Time Lapses 7.1.1. Using the jiffies Counter 7.1.2. Processor-Specific Registers 7.2. Knowing the Current Time 7.3. Delaying Execution 7.3.1. Long Delays 7.3.2. Short Delays 7.4. Kernel Timers 7.4.1. The Timer API 7.4.2. The Implementation of Kernel Timers 7.5. Tasklets 7.6. Workqueues 7.6.1. The Shared Queue 7.7. Quick Reference 7.7.1. Timekeeping 7.7.2. Delays 7.7.3. Kernel Timers 7.7.4. Tasklets 7.7.5. Workqueues 8. Allocating Memory 8.1. The Real Story of kmalloc 8.1.1. The Flags Argument 8.1.2. The Size Argument 8.2. Lookaside Caches 8.2.1. A scull Based on the Slab Caches: scullc 8.2.2. Memory Pools 8.3. get_free_page and Friends 8.3.1. A scull Using Whole Pages: scullp 8.3.2. The alloc_pages Interface 8.4. vmalloc and Friends 8.4.1. A scull Using Virtual Addresses: scullv 8.5. Per-CPU Variables 8.6. Obtaining Large Buffers 8.6.1. Acquiring a Dedicated Buffer at Boot Time 8.7. Quick Reference 9. Communicating with Hardware 9.1. I/O Ports and I/O Memory 9.1.1. I/O Registers and Conventional Memory 9.2. Using I/O Ports 9.2.1. I/O Port Allocation 9.2.2. Manipulating I/O ports 9.2.3. I/O Port Access from User Space 9.2.4. String Operations 9.2.5. Pausing I/O 9.2.6. Platform Dependencies 9.3. An I/O Port Example 9.3.1. An Overview of the Parallel Port 9.3.2. A Sample Driver 9.4. Using I/O Memory 9.4.1. I/O Memory Allocation and Mapping 9.4.2. Accessing I/O Memory 9.4.3. Ports as I/O Memory 9.4.4. Reusing short for I/O Memory 9.4.5. ISA Memory Below 1 MB 9.4.6. isa_readb and Friends 9.5. Quick Reference 10. Interrupt Handling 10.1. Preparing the Parallel Port 10.2. Installing an Interrupt Handler 10.2.1. The /proc Interface 10.2.2. Autodetecting the IRQ Number 10.2.3. Fast and Slow Handlers 10.3. Implementing a Handler 10.3.1. Handler Arguments and Return Value 10.3.2. Enabling and Disabling Interrupts 10.4. Top and Bottom Halves 10.4.1. Tasklets 10.4.2. Workqueues 10.5. Interrupt Sharing 10.5.1. Installing a Shared Handler 10.5.2. Running the Handler 10.5.3. The /proc Interface and Shared Interrupts 10.6. Interrupt-Driven I/O 10.6.1. A Write-Buffering Example 10.7. Quick Reference 11. Data Types in the Kernel 11.1. Use of Standard C Types 11.2. Assigning an Explicit Size to Data Items 11.3. Interface-Specific Types 11.4. Other Portability Issues 11.4.1. Time Intervals 11.4.2. Page Size 11.4.3. Byte Order 11.4.4. Data Alignment 11.4.5. Pointers and Error Values 11.5. Linked Lists 11.6. Quick Reference 12. PCI Drivers 12.1. The PCI Interface 12.1.1. PCI Addressing 12.1.2. Boot Time 12.1.3. Configuration Registers and Initialization 12.1.4. MODULE_DEVICE_TABLE 12.1.5. Registering a PCI Driver 12.1.6. Old-Style PCI Probing 12.1.7. Enabling the PCI Device 12.1.8. Accessing the Configuration Space 12.1.9. Accessing the I/O and Memory Spaces 12.1.10. PCI Interrupts 12.1.11. Hardware Abstractions 12.2. A Look Back: ISA 12.2.1. Hardware Resources 12.2.2. ISA Programming 12.2.3. The Plug-and-Play Specification 12.3. PC/104 and PC/104+ 12.4. Other PC Buses 12.4.1. MCA 12.4.2. EISA 12.4.3. VLB 12.5. SBus 12.6. NuBus 12.7. External Buses 12.8. Quick Reference 13. USB Drivers 13.1. USB Device Basics 13.1.1. Endpoints 13.1.2. Interfaces 13.1.3. Configurations 13.2. USB and Sysfs 13.3. USB Urbs 13.3.1. struct urb 13.3.2. Creating and Destroying Urbs 13.3.3. Submitting Urbs 13.3.4. Completing Urbs: The Completion Callback Handler 13.3.5. Canceling Urbs 13.4. Writing a USB Driver 13.4.1. What Devices Does the Driver Support? 13.4.2. Registering a USB Driver 13.4.3. probe and disconnect in Detail 13.4.4. Submitting and Controlling a Urb 13.5. USB Transfers Without Urbs 13.5.1. usb_bulk_msg 13.5.2. usb_control_msg 13.5.3. Other USB Data Functions 13.6. Quick Reference 14. The Linux Device Model 14.1. Kobjects, Ksets, and Subsystems 14.1.1. Kobject Basics 14.1.2. Kobject Hierarchies, Ksets, and Subsystems 14.2. Low-Level Sysfs Operations 14.2.1. Default Attributes 14.2.2. Nondefault Attributes 14.2.3. Binary Attributes 14.2.4. Symbolic Links 14.3. Hotplug Event Generation 14.3.1. Hotplug Operations 14.4. Buses, Devices, and Drivers 14.4.1. Buses 14.4.2. Devices 14.4.3. Device Drivers 14.5. Classes 14.5.1. The class_simple Interface 14.5.2. The Full Class Interface 14.6. Putting It All Together 14.6.1. Add a Device 14.6.2. Remove a Device 14.6.3. Add a Driver 14.6.4. Remove a Driver 14.7. Hotplug 14.7.1. Dynamic Devices 14.7.2. The sbinhotplug Utility 14.7.3. Using sbinhotplug 14.8. Dealing with Firmware 14.8.1. The Kernel Firmware Interface 14.8.2. How It Works 14.9. Quick Reference 14.9.1. Kobjects 14.9.2. Sysfs Operations 14.9.3. Buses, Devices, and Drivers 14.9.4. Classes 14.9.5. Firmware 15. Memory Mapping and DMA 15.1. Memory Management in Linux 15.1.1. Address Types 15.1.2. Physical Addresses and Pages 15.1.3. High and Low Memory 15.1.4. The Memory Map and Struct Page 15.1.5. Page Tables 15.1.6. Virtual Memory Areas 15.1.7. The Process Memory Map 15.2. The mmap Device Operation 15.2.1. Using remap_pfn_range 15.2.2. A Simple Implementation 15.2.3. Adding VMA Operations 15.2.4. Mapping Memory with nopage 15.2.5. Remapping Specific I/O Regions 15.2.6. Remapping RAM 15.2.7. Remapping Kernel Virtual Addresses 15.3. Performing Direct I/O 15.3.1. Asynchronous I/O 15.4. Direct Memory Access 15.4.1. Overview of a DMA Data Transfer 15.4.2. Allocating the DMA Buffer 15.4.3. Bus Addresses 15.4.4. The Generic DMA Layer 15.4.5. DMA for ISA Devices

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.