Specifications
17
Writing a User-Level Device Driver
Understanding a User-Level Device Driver. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-1
What Is a User-Level Device Driver?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-1
What Are the Advantages and Disadvantages of a User-Level Driver?. . . . . . . 17-2
Which Types of Devices Are Candidates for a User-Level Driver?. . . . . . . . . . 17-3
What Affects the Complexity of a User-Level Device Driver? . . . . . . . . . . . . . 17-3
Programmed I/O versus Direct Memory Access Devices. . . . . . . . . . . . . . 17-3
Single-User Drivers versus Multiuser Drivers . . . . . . . . . . . . . . . . . . . . . . 17-4
Polling Support versus Interrupt Support . . . . . . . . . . . . . . . . . . . . . . . . . . 17-4
Understanding the Components of a User-Level Driver . . . . . . . . . . . . . . . . . . . . . . 17-4
Overview of Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-5
Shared Memory Regions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-6
User I/O Buffer Descriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-7
Overview of User-Level Device Driver Routines. . . . . . . . . . . . . . . . . . . . . . . . 17-9
Overview of Interrupt-Handling Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-11
Overview of Synchronization Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-12
Overview of Error Returns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-13
Overview of the Device Configuration Program . . . . . . . . . . . . . . . . . . . . . . . . 17-14
Understanding Operating System Support for a User-Level Driver . . . . . . . . . . . . . 17-15
The userdma(2) System Call . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-15
The udbufalloc(3X) Library Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-16
The udbuffree(3X) Library Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-17
The atexit(3C) Library Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-17
The uderror(3X) Library Routine. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-18
The spl Support Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-19
Process Synchronization Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-19
Busy-Wait Mutual Exclusion Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-20
Rescheduling Control Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-20
The Server System Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-21
The User-Level Interrupt Library Routines and Utility . . . . . . . . . . . . . . . . . . . 17-22
The vme_address(3C) Library Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-23
Developing the Driver’s I/O Service Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-23
The open Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-23
The Asynchronous I/O Support Routines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-25
The aread Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-26
The awrite Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-27
The acheck Routine. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-28
The await Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-29
Control Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-30
The close Routine. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-31
Developing the Driver’s Interrupt Service Routine . . . . . . . . . . . . . . . . . . . . . . . . . . 17-34
Connecting a User-Level Interrupt Process and Interrupt Vector. . . . . . . . . . . . 17-34
User-Level Interrupts and Memory Locking . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-36
Use of Local Memory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-36
Constraints on Interrupt-Handling Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-37
Developing the Device Configuration Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-38
Create Shared Memory Regions and Initialize the Device. . . . . . . . . . . . . . . . . 17-39
Reset the Device. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-40