Ldr3TOC FM

You might also like

You are on page 1of 6

,ldr3TOC.fm.

4587 Page v Thursday, January 20, 2005 9:30 AM

Table of Contents

Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi 1. An Introduction to Device Drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1


The Role of the Device Driver Splitting the Kernel Classes of Devices and Modules Security Issues Version Numbering License Terms Joining the Kernel Development Community Overview of the Book 2 4 5 8 10 11 12 12

2. Building and Running Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15


Setting Up Your Test System The Hello World Module Kernel Modules Versus Applications Compiling and Loading The Kernel Symbol Table Preliminaries Initialization and Shutdown Module Parameters Doing It in User Space Quick Reference 15 16 18 22 28 30 31 35 37 39

3. Char Drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
The Design of scull Major and Minor Numbers Some Important Data Structures 42 43 49

,ldr3TOC.fm.4587 Page vi Thursday, January 20, 2005 9:30 AM

Char Device Registration open and release sculls Memory Usage read and write Playing with the New Devices Quick Reference

55 58 60 63 70 70

4. Debugging Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Debugging Support in the Kernel Debugging by Printing Debugging by Querying Debugging by Watching Debugging System Faults Debuggers and Related Tools 73 75 82 91 93 99

5. Concurrency and Race Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106


Pitfalls in scull Concurrency and Its Management Semaphores and Mutexes Completions Spinlocks Locking Traps Alternatives to Locking Quick Reference 107 107 109 114 116 121 123 130

6. Advanced Char Driver Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135


ioctl Blocking I/O poll and select Asynchronous Notification Seeking a Device Access Control on a Device File Quick Reference 135 147 163 169 171 173 179

7. Time, Delays, and Deferred Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183


Measuring Time Lapses Knowing the Current Time Delaying Execution Kernel Timers Tasklets
vi | Table of Contents

183 188 190 196 202

,ldr3TOC.fm.4587 Page vii Thursday, January 20, 2005 9:30 AM

Workqueues Quick Reference

205 208

8. Allocating Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213


The Real Story of kmalloc Lookaside Caches get_free_page and Friends vmalloc and Friends Per-CPU Variables Obtaining Large Buffers Quick Reference 213 217 221 224 228 230 231

9. Communicating with Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235


I/O Ports and I/O Memory Using I/O Ports An I/O Port Example Using I/O Memory Quick Reference 235 239 245 248 255

10. Interrupt Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258


Preparing the Parallel Port Installing an Interrupt Handler Implementing a Handler Top and Bottom Halves Interrupt Sharing Interrupt-Driven I/O Quick Reference 259 259 269 275 278 281 286

11. Data Types in the Kernel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288


Use of Standard C Types Assigning an Explicit Size to Data Items Interface-Specific Types Other Portability Issues Linked Lists Quick Reference 288 290 291 292 295 299

12. PCI Drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302


The PCI Interface A Look Back: ISA PC/104 and PC/104+ 302 319 322

Table of Contents

vii

,ldr3TOC.fm.4587 Page viii Thursday, January 20, 2005 9:30 AM

Other PC Buses SBus NuBus External Buses Quick Reference

322 323 324 325 325

13. USB Drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327


USB Device Basics USB and Sysfs USB Urbs Writing a USB Driver USB Transfers Without Urbs Quick Reference 328 333 335 346 356 360

14. The Linux Device Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362


Kobjects, Ksets, and Subsystems Low-Level Sysfs Operations Hotplug Event Generation Buses, Devices, and Drivers Classes Putting It All Together Hotplug Dealing with Firmware Quick Reference 364 371 375 377 387 391 397 405 407

15. Memory Mapping and DMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412


Memory Management in Linux The mmap Device Operation Performing Direct I/O Direct Memory Access Quick Reference 412 422 435 440 459

16. Block Drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464


Registration The Block Device Operations Request Processing Some Other Details Quick Reference 465 471 474 491 494

viii |

Table of Contents

,ldr3TOC.fm.4587 Page ix Thursday, January 20, 2005 9:30 AM

17. Network Drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497


How snull Is Designed Connecting to the Kernel The net_device Structure in Detail Opening and Closing Packet Transmission Packet Reception The Interrupt Handler Receive Interrupt Mitigation Changes in Link State The Socket Buffers MAC Address Resolution Custom ioctl Commands Statistical Information Multicast A Few Other Details Quick Reference 498 502 506 515 516 521 523 525 528 528 532 535 536 537 540 542

18. TTY Drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546


A Small TTY Driver tty_driver Function Pointers TTY Line Settings ioctls proc and sysfs Handling of TTY Devices The tty_driver Structure in Detail The tty_operations Structure in Detail The tty_struct Structure in Detail Quick Reference 548 553 560 564 566 567 569 571 573

Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579

Table of Contents

ix

,ldr3TOC.fm.4587 Page x Thursday, January 20, 2005 9:30 AM

You might also like