وبلاگ بلیان

Linux device drivers : [covers Linux 2.4

معرفی کتاب «Linux device drivers : [covers Linux 2.4» نوشتهٔ Jonathan Corbet, Alessandro Rubini، منتشرشده توسط نشر O'Reilly Media در سال 2001. این کتاب در 87 صفحه، فرمت pdf، زبان انگلیسی ارائه شده است. «Linux device drivers : [covers Linux 2.4» در دستهٔ بدون دسته‌بندی قرار دارد.

Honestly, I really don't understand how anyone can give this book 5 stars. To start off on a positive tone, I'll say what I liked about it. 1) Lots of information. There is no denying this, it is very informitive. However, this is a double edged swords (will discuss later) 2) The basic drivers are described pretty well. The scull driver is a good way to ease into driver development, imo. Simple enough that it's not too overwhelming and ununderstandable, but not overly simple so that you actually get an idea of what's going on. 3) It's free. That's it for the positives. Now for a huge list of negatives. 1) Most of the information is irrelevent. I feel like the authors lost focus as the book went on, and forgot they were not writing a general "Linux Kernel" book but a specific book for drivers. Many a time do they spend pages upon pages going on about something, only to mention "but this is never used by read driver developers" at the end. You end up in a really unpleasant situation where you have to sift through a bunch of useless info to get to the useful stuff. Most of the time I ended up just searching google, and got better results. 2) Lack of more complex examples. Let's face it, no one needs to write an extremely simple char driver. However, that's as complex as the examples get. Beyond the scull driver, it's just code fragments. I sincerely hope you don't have to write a serial tty device. Which leads me to my next point. 3) Outdated. Many kernel API changes have been made to the point where the code is no longer compilable (especially on the tty front). Methods used in the book have been done away with in the newer kernel API's. Honestly, you're much better off just resorting to Google. If you want to write your own driver and you read through this book, you'll still have no idea where to start. The functions in the scull driver are well-described, but that's it. The authors use too much space writing about useless crap you really don't care about, and this comes at the expense of useful info that will actually help you write drivers. This book will probably come up on your google searches, and it might be worth it to skim the regular chapters. Honestly though, it's not going to tell you anything your other search results won't. This is most definitely not the "end all, be all" of writing linux drivers, it just happens to be the only one. Linux Linux Device Drivers Linux Device Drivers, 2nd Edition 1 Preface -1 Alessandro’s Introduction 2 Jon’s Introduction 3 Audience of This Book 4 Organization of the Material 5 Background Information 6 Sources of Further Information 6 Online Version and License 8 Conventions Used in This Book 8 We’d Like to Hear from You 9 Acknowledgments 9 CH1: An Introduction to Device Drivers 11 The Role of the Device Driver 12 Splitting the Kernel 14 Classes of Devices and Modules 16 Security Issues 19 Version Numbering 20 License Terms 22 Joining the Kernel Development Community 23 Overview of the Book 23 CH2: Building and Running Modules 25 Kernel Modules Versus Applications 26 User Space and Kernel Space 29 Concurrency in the Kernel 30 The Current Process 31 Compiling and Loading 32 Version Dependency 34 Platform Dependency 37 The Kernel Symbol Table 37 Initialization and Shutdown 39 Error Handling in init_module 40 The Usage Count 43 Unloading 44 Explicit Initialization and Cleanup Functions 44 Using Resources 45 I/O Ports and I/O Memory 46 Resource Allocation in Linux 2.4 50 Automatic and Manual Configuration 52 Doing It in User Space 55 Backward Compatibility 57 Changes in Resource Management 57 Compiling for Multiprocessor Systems 58 Exporting Symbols in Linux 2.0 58 Module Configuration Parameters 60 Quick Reference 60 CH3: Char Drivers 64 The Design of scull 64 Major and Minor Numbers 65 Dynamic Allocation of Major Numbers 67 Removing a Driver from the System 71 dev_t and kdev_t 71 File Operations 73 The file Structure 76 open and release 78 The open Method 78 The release Method 82 scull's Memory Usage 83 A Brief Introduction to Race Conditions 86 read and write 88 The read Method 90 The write Method 92 readv and writev 94 Playing with the New Devices 95 The Device Filesystem 95 Using devfs in Practice 98 Portability Issues and devfs 100 Backward Compatibility 101 Changes in the File Operations Structure 101 The Module Usage Count 103 Changes in Semaphore Support 104 Changes in Access to User Space 104 Quick Reference 105 CH4: Debugging Techniques 107 Debugging by Printing 107 printk 107 How Messages Get Logged 110 Turning the Messages On and Off 111 Debugging by Querying 113 Using the /proc Filesystem 113 The ioctl Method 118 Debugging by Watching 118 Debugging System Faults 120 Oops Messages 121 System Hangs 128 Debuggers and Related Tools 130 Using gdb 130 The kdb Kernel Debugger 132 The Integrated Kernel Debugger Patch 134 The kgdb Patch 135 Kernel Crash Dump Analyzers 135 The User-Mode Linux Port 136 The Linux Trace Toolkit 137 Dynamic Probes 137 CH5: Enhanced Char Driver Operations 138 ioctl 139 Choosing the ioctl Commands 140 The Return Value 143 The Predefined Commands 143 Using the ioctl Argument 144 Capabilities and Restricted Operations 147 The Implementation of the ioctl Commands 148 Device Control Without ioctl 150 Blocking I/O 151 Going to Sleep and Awakening 151 A Deeper Look at Wait Queues 154 Writing Reentrant Code 157 Blocking and Nonblocking Operations 158 A Sample Implementation: scullpipe 160 poll and select 164 Interaction with read and write 167 The Underlying Data Structure 168 Asynchronous Notification 169 The Driver's Point of View 171 Seeking a Device 173 The llseek Implementation 173 Access Control on a Device File 174 Single-Open Devices 175 Another Digression into Race Conditions 176 Restricting Access to a Single User at a Time 177 Blocking open as an Alternative to EBUSY 178 Cloning the Device on Open 179 Backward Compatibility 182 Wait Queues in Linux 2.2 and 2.0 182 Asynchronous Notification 183 The fsync Method 183 Access to User Space in Linux 2.0 183 Capabilities in 2.0 185 The Linux 2.0 select Method 185 Seeking in Linux 2.0 186 and SMP 186 Quick Reference 187 CH6: Flow of Time 191 Time Intervals in the Kernel 191 Processor-Specific Registers 192 Knowing the Current Time 194 Delaying Execution 196 Long Delays 196 Short Delays 198 Task Queues 199 The Nature of Task Queues 200 How Task Queues Are Run 201 Predefined Task Queues 202 Running Your Own Task Queues 208 Tasklets 208 Kernel Timers 210 Backward Compatibility 214 Quick Reference 215 CH7: Getting Hold of Memory 218 The Real Story of kmalloc 218 The Flags Argument 218 The Size Argument 221 Lookaside Caches 221 A scull Based on the Slab Caches: scullc 223 get_free_page and Friends 224 A scull Using Whole Pages: scullp 226 vmalloc and Friends 227 A scull Using Virtual Addresses: scullv 229 Boot-Time Allocation 231 Acquiring a Dedicated Buffer at Boot Time 231 The bigphysarea Patch 232 Reserving High RAM Addresses 233 Backward Compatibility 233 Quick Reference 234 CH8: Hardware Management 236 I/O Ports and I/O Memory 236 I/O Registers and Conventional Memory 237 Using I/O Ports 239 String Operations 241 Pausing I/O 242 Platform Dependencies 242 Using Digital I/O Ports 245 An Overview of the Parallel Port 245 A Sample Driver 247 Using I/O Memory 248 Directly Mapped Memory 250 Reusing short for I/O Memory 251 Software-Mapped I/O Memory 252 ISA Memory Below 1 MB 253 isa_readb and Friends 255 Probing for ISA Memory 255 Backward Compatibility 258 Quick Reference 259 CH9: Interrupt Handling 261 Overall Control of Interrupts 261 Preparing the Parallel Port 263 Installing an Interrupt Handler 263 The /proc Interface 266 Autodetecting the IRQ Number 268 Fast and Slow Handlers 272 Implementing a Handler 274 Using Arguments 277 Enabling and Disabling Interrupts 277 Tasklets and Bottom-Half Processing 279 Tasklets 280 The BH Mechanism 281 Writing a BH Bottom Half 283 Interrupt Sharing 284 Installing a Shared Handler 285 Running the Handler 286 The /proc Interface 287 Interrupt-Driven I/O 288 Race Conditions 288 Using Circular Buffers 289 Using Spinlocks 291 Using Lock Variables 294 Going to Sleep Without Races 296 Backward Compatibility 298 Differences in the 2.2 Kernel 298 Further Differences in the 2.0 Kernel 298 Quick Reference 299 CH10: Judicious Use of Data Types 303 Use of Standard C Types 303 Assigning an Explicit Size to Data Items 305 Interface-Specific Types 306 Other Portability Issues 307 Time Intervals 307 Page Size 307 Byte Order 308 Data Alignment 309 Linked Lists 310 Quick Reference 313 CH11: kmod and Advanced Modularization 315 Loading Modules on Demand 315 Requesting Modules in the Kernel 316 The User-Space Side 317 Module Loading and Security 319 Module Loading Example 319 Running User-Mode Helper Programs 321 Intermodule Communication 321 Version Control in Modules 324 Using Version Support in Modules 325 Exporting Versioned Symbols 327 Backward Compatibility 328 Quick Reference 329 CH12: Loading Block Drivers 331 Registering the Driver 332 The Header File blk.h 338 Handling Requests: A Simple Introduction 340 The Request Queue 340 Performing the Actual Data Transfer 342 Handling Requests: The Detailed View 344 The I/O Request Queue 345 Clustered Requests 350 Multiqueue Block Drivers 352 Doing Without the Request Queue 355 How Mounting and Unmounting Works 358 The ioctl Method 359 Removable Devices 362 check_media_change 363 Revalidation 363 Extra Care 364 Partitionable Devices 365 The Generic Hard Disk 366 Partition Detection 367 Partition Detection Using initrd 370 The Device Methods for spull 370 Interrupt-Driven Block Drivers 372 Backward Compatibility 374 Quick Reference 376 CH13: mmap and DMA 380 Memory Management in Linux 380 Address Types 381 High and Low Memory 382 The Memory Map and struct page 383 Page Tables 385 Virtual Memory Areas 388 The mmap Device Operation 392 Using remap_page_range 394 A Simple Implementation 395 Adding VMA Operations 396 Mapping Memory with nopage 397 Remapping Specific I/O Regions 399 Remapping RAM 400 Remapping Virtual Addresses 404 The kiobuf Interface 406 The kiobuf Structure 406 Mapping User-Space Buffers and Raw I/O 407 Direct Memory Access and Bus Mastering 411 Overview of a DMA Data Transfer 411 Allocating the DMA Buffer 412 Bus Addresses 414 DMA on the PCI Bus 414 DMA for ISA Devices 423 Backward Compatibility 428 Changes to Memory Management 428 Changes to DMA 430 Quick Reference 431 CH14: Network Drivers 435 How snull Is Designed 436 Assigning IP Numbers 437 The Physical Transport of Packets 439 Connecting to the Kernel 440 Module Loading 440 Initializing Each Device 442 Module Unloading 444 Modularized and Nonmodularized Drivers 444 The net_device Structure in Detail 445 The Visible Head 445 The Hidden Fields 446 Opening and Closing 453 Packet Transmission 455 Controlling Transmission Concurrency 456 Transmission Timeouts 457 Packet Reception 458 The Interrupt Handler 460 Changes in Link State 461 The Socket Buffers 462 The Important Fields 462 Functions Acting on Socket Buffers 464 MAC Address Resolution 465 Using ARP with Ethernet 465 Overriding ARP 466 Non-Ethernet Headers 467 Custom ioctl Commands 468 Statistical Information 469 Multicasting 470 Kernel Support for Multicasting 471 A Typical Implementation 472 Backward Compatibility 474 Differences in Linux 2.2 474 Further Differences in Linux 2.0 475 Probing and HAVE_DEVLIST 476 Quick Reference 477 CH15: Overview of Peripheral Buses 480 The PCI Interface 480 PCI Addressing 481 Boot Time 484 Configuration Registers and Initialization 485 Accessing the Configuration Space 490 Accessing the I/O and Memory Spaces 493 PCI Interrupts 498 Handling Hot-Pluggable Devices 499 Hardware Abstractions 503 A Look Back: ISA 504 Hardware Resources 504 ISA Programming 505 The Plug-and-Play Specification 506 PC/104 and PC/104+ 506 Other PC Buses 507 MCA 507 EISA 507 VLB 508 SBus 508 NuBus 509 External Buses 509 USB 510 Writing a USB Driver 510 Backward Compatibility 512 Quick Reference 513 CH16: Physical Layout of the Kernel Source 516 Booting the Kernel 517 Before Booting 519 The init Process 521 The kernel Directory 522 The fs Directory 523 The mm Directory 524 The net directory 526 ipc and lib 527 include and arch 527 Drivers 527 drivers/char 528 drivers/block 528 drivers/ide 529 drivers/md 529 drivers/cdrom 530 drivers/scsi 530 drivers/net 531 drivers/sound 531 drivers/video 532 drivers/input 533 drivers/media 533 Bus-Specific Directories 533 Platform-Specific Directories 534 Other Subdirectories 534 Bibliography 536 Linux Kernel Books 536 Unix Design and Internals 537 Index 538

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, is winning over enthusiastic adherents in many application areas, and is being viewed more and more as a good platform for embedded systems. Linux Device Drivers, already a classic in its second edition, reveals information that heretofore has been shared by word of mouth or in cryptic source code comments, on how to write drivers for a wide range of devices.

Version 2.4 of the Linux kernel includes significant changes to device drivers, simplifying many activities, but providing subtle new features that can make a driver both more efficient and more flexible. The second edition of this book thoroughly covers these changes, as well as new processors and buses.

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. You'll learn how to write drivers for character devices, block devices, and network interfaces, guided by full-featured examples that you can compile and run without special hardware. Major changes in the second edition include discussions of symmetric multiprocessing (SMP) and locking, new CPUs, and recently supported buses. 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.4, but includes information for kernels back to 2.0 where feasible. Linux Device Driver also shows how to maximize portability among hardware platforms; examples were tested on IA32 (PC) and IA64, PowerPC, SPARC and SPARC64, Alpha, ARM, and MIPS.

Contents include:

  • Building a driver and loading modules
  • Complete character, block, and network drivers
  • Debugging a driver
  • Timing
  • Handling symmetric multiprocessing (SMP) systems
  • Memory management and DMA
  • Interrupts
  • Portability issues
  • Peripheral Component Interconnect (PCI)


"We're back to the times when men were men and wrote their own device drivers." -- Linus Torvalds. Of course, this is also a very good publication for the excellent, equally facile (and less macho) kernel and hardware programmers of the opposite gender. Comments aside, this is a very good (and to-date the only publication) for programmers and developers that covers device drivers in-depth. The author assumes that you understand the Linux kernel and C code.

Nwely updated to include new calls and techniques introduced in Versions 2.2 and 2.4 of the Linux kernel, a definitive resource for those who want to support computer peripherals under the Linux operating system explains how to write a driver for a broad spectrum of devices, including character devices, network interfaces, and block devices. Original. (Intermediate)
دانلود کتاب Linux device drivers : [covers Linux 2.4