Writing Device Drivers
この本のみを検索

............................Contents


1. The SunOS Kernel and Device Tree
1
..What is the Kernel? 1
..Multithreading 2
..Virtual Memory 2
....Virtual Addresses 3
....Address Spaces 3
..Special Files 3
..Dynamic Loading of Kernel Modules 3
..Overview of the Solaris 2.x DDI/DKI 4
..The Device Tree 5
....Example Device Tree 7
....Displaying the Device Tree 9
....Binding a Driver to a Device Node 11

2. Hardware Overview
15
..SPARC Processor Issues 15
....Data Alignment 15
....Structure Member Alignment 16
....Byte Ordering 16
....Register Windows 16
....Floating Point Operations 17
.... Multiply and Divide Instructions 17
....SPARC Architecture Manual 17
..x86 Processor Issues 17
....Data Alignment 17
....Structure Member Alignment 18
....Byte Ordering 18
....Floating Point Operations 18
....x86 Architecture Manuals 18
..PowerPC Processor Issues 18
....Data Alignment 18
....Structure Member Alignment 19
....Byte Ordering 19
....Floating Point Operations 19
....PowerPC Architecture Manual 20
..Store Buffers 20
..System Memory Model 20
....Total Store Ordering (TSO) 21
....Partial Store Ordering (PSO) 21
..Bus Architectures 21
....Device Identification 22
....Interrupts 22
..Bus Specifics 23
....PCI Local Bus 23
....PCI Address Domain 25
....SBus 28
....VMEbus 31
....ISA Bus 34
....EISA Bus 35
....MCA Bus 36
..Device Issues 36
....Timing-Critical Sections 36
....Delays 37
....Internal Sequencing Logic 37
....Interrupt Issues 37
....Byte Ordering 38
....Device Component Representations 39
..The PROM on SPARC Machines 40
....Open Boot PROM 2.x 40
..Reading and Writing 46

3. Overview of SunOS Device Drivers
49
..What is a Device Driver? 49
..Types of Device Drivers 50
....Block Device Drivers 50
....Standard Character Device Drivers 50
....STREAMS Drivers 52
..Bus Address Spaces 52
....Overview 52
....Address Mapping Setup 53
....Data Access Functions 55
....Example Device Registers 57
....Device Register Structure 58
..Driver Interfaces 61
....Entry Points 61
..Callback functions 63
..Interrupt Handling 64
..Driver Context 65
..Printing Messages 66
..Dynamic Memory Allocation 66
..Software State Management 67
....State Structure 67
....State Management Routines 68
..Properties 69
..Driver Layout 73
....Header Files 73
....xx.c Files 73
....driver .conf Files 74
..Driver Structure Overview 74
..The C Language and Compiler Modes 75
....Compiler Modes 75
....Function Prototypes 75
....New Keywords 76

4. Multithreading
79
..Threads 79
....User Threads 79
....Kernel Threads 80
..Multiprocessing Changes Since SunOS 4.x 81
..Locking Primitives 82
....Storage Classes of Driver Data 82
....State Structure 83
....Mutual-Exclusion Locks 83
....Readers/Writer Locks 85
....Semaphores 85
..Thread Synchronization 85
....Condition Variables 85
....cv_timedwait( ) 89
....cv_wait_sig( ) 90
....cv_timedwait_sig( ) 90
..Choosing a Locking Scheme 91

5. Autoconfiguration
93
..Overview 93
..State Structure 93
..Driver Loading and Configuration 94
..Data Structures 95
....modlinkage() 95
....modldrv() 95
....dev_ops() 96
....cb_ops 96
..Loadable Driver Interface 98
..Device Configuration 100
....identify( ) 100
....probe( ) 101
....attach( ) 105
....detach( ) 110
....getinfo( ) 112

6. Interrupt Handlers
115
..Overview 115
....Interrupt Specification 116
....Interrupt Number 117
....Interrupt Block Cookies 117
....Bus-Interrupt Levels 117
....High-Level Interrupts 117
..Types of Interrupts 118
....Vectored Interrupts 118
....Polled Interrupts 119
....Software Interrupts 119
..Registering Interrupts 120
..Responsibilities of an Interrupt Handler 121
..State Structure 124
..Handling High-Level Interrupts 124
....Example 125

7. DMA
129
..The DMA Model 129
..Types of Device DMA 130
..DMA and DVMA 131
..Handles, Windows and Cookies 132
..DMA Operations 132
....DMA attributes 134
....Object Locking 139
....Allocating a DMA Handle 140
....Allocating DMA Resources 141
....Burst Sizes 145
....Programming the DMA Engine 145
....Freeing the DMA Resources 147
....Freeing the DMA handle 148
..Cancelling DMA Callbacks 148
..Synchronizing Memory Objects 150
....Cache 150
....ddi_dma_sync( ) 152
..DMA Windows 153
..Allocating Private DMA Buffers 156
....ddi_dma_devalign( ) 158

8. Drivers for Character Devices
161
..Driver Structure Overview 161
....Character Driver Device Access 161
..Entry Points 163
..Autoconfiguration 164
..Controlling Device Access 165
..I/O Request Handling 167
....User Addresses 167
....Vectored I/O 168
....Synchronous vs. Asynchronous I/O 169
....Data Transfer Methods 170
..Mapping Device Memory 177
..Multiplexing I/O on File Descriptors 180
..Miscellaneous I/O Control 183

9. Drivers for Block Devices
187
..Driver Structure Overview 187
....Block Driver Device Access 187
..File I/O 189
..State Structure 189
..Entry Points 189
..Autoconfiguration 190
..Controlling Device Access 192
..Data Transfers 195
.....strategy( ) 195
.....The buf Structure 195
..Synchronous Data Transfers 197
..Asynchronous Data Transfers 201
..Miscellaneous Entry Points 206
.....dump( ) 206
.....print( ) 207

10. Device Context Management
209
..What Is A Device Context? 209
..Context Management Model 209
.....Multiprocessor Considerations 211
..Context Management Operation 212
.....State Structure 212
.....Declarations and Data Structures 213
.....Associating Devices with User Mappings 213
.....Managing Mapping Accesses 216
.....Device Context Management Entry Points 217

11. SCSI Target Drivers
223
..Overview 223
..Reference Documents 224
..Sun Common SCSI Architecture Overview 225
.....General Flow of Control 226
..SCSA Functions 228
..SCSA Compatibility Functions 229
..SCSI Target Drivers 229
.....Hardware Configuration File 229
.....Declarations and Data Structures 230
.....Autoconfiguration 233
.....Resource Allocation 239
..Building and Transporting a Command 241
.....Building a Command 242
.....Capabilities 243
.....Transporting a Command 243
.....Command Completion 244
.....Reuse of packets 245
.....Auto-Request Sense Mode 246

12. SCSI Host Bus Adapter Drivers
249
..Overview 249
.....SCSA Interface 250
.....HBA Transport Layer 251
..SCSA HBA Interfaces 252
.....SCSA HBA Entry Point Summary 252
.....SCSA HBA Data Structures 252
.....Per-Target Instance Data 258
.....Transport Structure Cloning (optional) 260
.....SCSA HBA Functions 262
..HBA Driver Dependency and Configuration Issues 262
.....Configuration Properties 263
.....Declarations and Structures 264
.....Module Initialization Entry Points 266
.....Autoconfiguration Entry Points 269
..SCSA HBA Entry Points 274
.....Target Driver Instance Initialization 275
.....Resource Allocation 277
.....Command Transport 288
.....Capability Management 295
.....Abort and Reset Management 301
..Driver Installation 304
.....Hardware Configuration File 304
.....Installing the Driver 304
.....x86 Target Driver Configuration Properties 305

13. Loading and Unloading Drivers
307
..Preparing for Installation 307
.....Module Naming 307
.....Compile and Link the Driver 308
.....Write a Hardware Configuration File 308
..Installing and Removing Drivers 309
.....Copy the Driver to a Module Directory 309
.....Run add_drv(1M) 309
..Removing the Driver 310
..Loading Drivers 310
..Getting the Driver Module's ID 310
..Unloading Drivers 311

14. Debugging
313
..Machine Configuration 313
.....Setting Up a tip(1) Connection 313
.....Preparing for the Worst 315
..Coding Hints 319
.....Process Layout 319
.....System Support 320
.....Conditional Compilation and Variables 321
.....volatile and _depends_on 323
..Debugging Tools 323
...../etc/system 323
.....moddebug 324
.....modload and modunload 325
.....Saving System Core Dumps 325
.....adb and kadb 327
.....Example: adb on a Core Dump 340
.....Example: kadb on a Deadlocked Thread 343
..Testing 346
.....Configuration Testing 346
.....Functionality Testing 347
.....Error Handling 347
.....Stress, Performance, and Interoperability Testing 348
.....DDI/DKI Compliance Testing 348
.....Installation and Packaging Testing 349
.....Testing Specific Types of Drivers 349

A. Converting a 4.x Device Driver to SunOS 5.5
353
..Before Starting the Conversion 353
.....Review Existing Functionality 353
.....Read the Manual 353
.....ANSI C 354
..Development Environment 354
.....DDI/DKI 354
.....Things to Avoid 354
.....System V Release 4 355
.....Development Tools 355
.....Debugging Tools 356
.....ANSI C 356
.....Header Files 357
..Overview of Changes 357
.....Autoconfiguration 357
...../devices 358
...../dev 359
.....Multithreading 359
.....Locking 360
.....Interrupts 364
.....DMA 365
..Conversion Notes 366
.....SunOS 4.1.x to SunOS 5.5 Differences 371

B. Interface Transition List
379
.....Data Access Methods 379
.....DMA Data Access 379
.....SCSI HBA DMA Management 379
.....Device Memory Mapping 379
.....Open Boot PROM Device Properties 380
..Data Access Methods 380
.....Device Access Attributes Structure 380
.....CPU Device Access 380
.....Device Access Functions 380
.....Common Device Access Functions 382
.....Other Device Access Functions 383
..DMA Device Access 383
.....DMA Attributes Structure 383
.....DMA Memory Access 383
.....DMA Device Binding 384
..SCSI HBA DMA Management 385
..Device Memory Mapping 385
.....Device Context Management 385
..Open Boot PROM Device Properties 386
.....Property Access Functions 386

C. Summary of Solaris 2.5 DDI/DKI Services
387
..buf(9S) Handling 388
..Copying Data 391
..Device Access 392
..Device Configuration 393
..Device Information 394
..DMA Handling 395
..Flow of Control 405
..Interrupt Handling 406
..Kernel Statistics 408
..Memory Allocation 410
..Common Device Access Functions 414
..Polling 417
..Printing System Messages 417
..Process Signaling 418
..Properties 419
..Register and Memory Mapping 423
..PCI Configuration 427
..I/O Port Access 427
..SCSI and SCSA 431
..Soft State Management 439
..String Manipulation 440
..System Information 441
..Thread Synchronization 441
..Timing 446
...uio(9S) Handling 447
...Utility Functions 448

D. Sample Driver Source Code Listings
453

E. Driver Code Layout Structure
455
...Header Files 455
...xx.c Files 456
...driver .conf Files 460
F. Advanced Topics 461
...Multithreading 461
......Lock Granularity 461
......Avoiding Unnecessary Locks 462
......Locking Order 462
......Scope of a Lock 463
......Potential Panics 464
...Sun Disk Device Drivers 465
......Disk I/O Controls 465
......Disk Performance 466
...SCSA 467
......Global Data Definitions 467
......Tagged Queueing 468
......Untagged Queueing 469

Index
471