Kernel Extensions and Device Support Programming Concepts
Total Page:16
File Type:pdf, Size:1020Kb
Bull Kernel Extensions and Device Support Programming Concepts AIX ORDER REFERENCE 86 A2 36JX 02 Bull Kernel Extensions and Device Support Programming Concepts AIX Software November 1999 BULL ELECTRONICS ANGERS CEDOC 34 Rue du Nid de Pie – BP 428 49004 ANGERS CEDEX 01 FRANCE ORDER REFERENCE 86 A2 36JX 02 The following copyright notice protects this book under the Copyright laws of the United States of America and other countries which prohibit such actions as, but not limited to, copying, distributing, modifying, and making derivative works. Copyright Bull S.A. 1992, 1999 Printed in France Suggestions and criticisms concerning the form, content, and presentation of this book are invited. A form is provided at the end of this book for this purpose. To order additional copies of this book or other Bull Technical Publications, you are invited to use the Ordering Form also provided at the end of this book. Trademarks and Acknowledgements We acknowledge the right of proprietors of trademarks mentioned in this book. AIXR is a registered trademark of International Business Machines Corporation, and is being used under licence. UNIX is a registered trademark in the United States of America and other countries licensed exclusively through the Open Group. Year 2000 The product documented in this manual is Year 2000 Ready. The information in this document is subject to change without notice. Groupe Bull will not be liable for errors contained herein, or for incidental or consequential damages in connection with the use of this material. Contents Trademarks and Acknowledgements . iii 64-bit Kernel Extension Development. 23 About This Book . xv Chapter 2. System Calls . 25 Who Should Use This Book . xv Differences Between a System Call and a User How to Use This Book . xv Function . 25 Overview of Contents . xv Understanding System Call Execution . 25 Highlighting . xvi User Protection Domain . 26 ISO 9000 . xvi Kernel Protection Domain . 26 AIX 32-Bit Support for the X/Open UNIX95 Actions of the System Call Handler . 26 Specification . xvi Accessing Kernel Data While in a System Call. 27 AIX 32-Bit and 64-Bit Support for the UNIX98 Preempting a System Call . 28 Specification . xvii Handling Signals While in a System Call . 28 Related Publications . xvii Handling Exceptions While in a System Call . 29 Ordering Publications . xvii Understanding Nesting and Kernel-Mode Use of System Calls . 30 Chapter 1. Kernel Environment . 1 Page Faulting within System Calls. 30 Returning Error Information from System Calls 31 Understanding Kernel Extension Binding . 2 System Calls Available to Kernel Extensions . 31 Base Kernel Services - the /unix Name Space . 2 System Calls Available to All Kernel Extensions 31 Using System Calls with Kernel Extensions . 3 System Calls Available to Kernel Processes Only 32 Using Private Routines . 4 Using Libraries . 5 Understanding Execution Environments . 7 Chapter 3. Virtual File Systems . 33 Process Environment . 8 Logical File System Overview . 33 Interrupt Environment . 8 Component Structure of the Logical File System 34 Understanding Kernel Threads . 9 Virtual File System Overview . 35 Kernel Threads, Kernel Only Threads, and User Understanding Virtual Nodes (V-nodes) . 35 Threads . 9 Understanding Generic I-nodes (G-nodes) . 35 Kernel Data Structures. 10 Understanding the Virtual File System Interface 36 Thread Creation, Execution, and Termination . 10 Understanding Data Structures and Header Files for Thread Scheduling . 10 Virtual File Systems . 37 Thread Signal Handling . 10 Configuring a Virtual File System . 38 Using Kernel Processes . 11 Introduction to Kernel Processes . 11 Chapter 4. Kernel Services . 39 Accessing Data from a Kernel Process . 12 Categories of Kernel Services . 39 Cross-Memory Services . 13 I/O Kernel Services . 39 Kernel Process Creation, Execution, and Block I/O Kernel Services . 39 Termination . 13 Buffer Cache Kernel Services . 40 Kernel Process Preemption . 14 Character I/O Kernel Services . 40 Kernel Process Signal and Exception Handling . 14 Interrupt Management Services. 40 Kernel Process Use of System Calls . 15 Memory Buffer (mbuf) Kernel Services . 41 Accessing User-Mode Data While in Kernel Mode 15 DMA Management Kernel Services . 42 Data Transfer Services . 15 Block I/O Buffer Cache Kernel Services: Overview 42 Using Cross-Memory Kernel Services. 16 Managing the Buffer Cache . 43 Understanding Locking . 16 Using the Buffer Cache write Services . 43 Lockl Locks . 16 Understanding Interrupts. 44 Simple Locks . 17 Interrupt Priorities . 44 Complex Locks . 17 Understanding DMA Transfers . 44 Types of Critical Sections . 17 Hiding DMA Data . 45 Priority Promotion . 17 Accessing Data While the DMA Operation Is in Locking Strategy in Kernel Mode . 17 Progress . 45 Understanding Exception Handling . 18 Kernel Extension and Device Driver Management Exception Processing . 18 Kernel Services . 46 Kernel-Mode Exception Handling . 18 Kernel Extension Loading and Binding Services 46 Implementing Kernel Exception Handlers . 20 Other Functions for the Kernel Extension and User-Mode Exception Handling . 23 Device Driver Management Services . 46 © Copyright IBM Corp. 1997, 1999 v List of Kernel Extension and Device Driver Virtual File System (VFS) Kernel Services . 69 Management Kernel Services . 47 Locking Kernel Services . 48 Chapter 5. Asynchronous I/O Lock Allocation and Other Services . 48 Subsystem . 71 Simple Locks . 48 Asynchronous I/O Overview . 71 Complex Locks . 49 How do I know if I need to use AIO? . 72 Lockl Locks . 50 How many AIO Servers am I currently using?. 72 Atomic Lock Operations . 50 How many AIO servers do I need? . 73 Atomic Operations . 51 Prerequisites . 73 File Descriptor Management Services . 51 Functions of Asynchronous I/O . 73 Logical File System Kernel Services . 51 Large File-Enabled Asynchronous I/O (AIX Other Considerations . 52 Version 4.2.1 or later) . 73 List of Logical File System Kernel Services . 52 Nonblocking I/O . 74 Memory Kernel Services . 53 Notification of I/O Completion. 74 Memory Management Kernel Services . 53 Cancellation of I/O Requests . 75 Memory Pinning Kernel Services . 53 Asynchronous I/O Subroutines. 75 User Memory Access Kernel Services . 54 Order and Priority of Asynchronous I/O Calls . 76 Virtual Memory Management Kernel Services . 54 Subroutines Affected by Asynchronous I/O . 76 Cross-Memory Kernel Services . 55 Changing Attributes for Asynchronous I/O. 76 Understanding Virtual Memory Manager Interfaces 56 64-bit Enhancements . 77 Virtual Memory Objects . 56 Addressing Data. 57 Moving Data to or from a Virtual Memory Object 57 Chapter 6. Device Configuration Data Flushing . 57 Subsystem . 79 Discarding Data . 57 Scope of Device Configuration Support . 79 Protecting Data . 58 Device Configuration Subsystem Overview . 79 Executable Data . 58 General Structure of the Device Configuration Installing Pager Backends. 58 Subsystem . 80 Referenced Routines . 58 High-Level Perspective . 83 Services that Support 64-bit Processes . 59 Device Method Level . 84 Message Queue Kernel Services . 60 Low-Level Perspective. 84 Network Kernel Services . 61 Device Configuration Database Overview . 84 Address Family Domain and Network Interface Basic Device Configuration Procedures Overview. 85 Device Driver Kernel Services . 61 Device Configuration Manager Overview . 85 Routing and Interface Address Kernel Services 62 Devices Graph . 86 Loopback Kernel Services. 62 Configuration Rules . 86 Protocol Kernel Services . 62 Invoking the Configuration Manager . 87 Communications Device Handler Interface Kernel Device Classes, Subclasses, and Types Overview . 87 Services . 63 Writing a Device Method . 88 Process and Exception Management Kernel Services 63 Invoking Methods . 88 Creating Kernel Processes . 63 Example Methods . 88 Creating Kernel Threads . 63 Understanding Device Methods Interfaces . 89 Kernel Structures Encapsulation . 64 Configuration Manager . 89 Registering Exception Handlers. 64 Run-Time Configuration Commands . 90 Signal Management. 64 Understanding Device States . 90 Events Management . 64 Adding an Unsupported Device to the System . 92 List of Process, Thread, and Exception Modifying the Predefined Database . 92 Management Kernel Services . 65 Adding Device Methods . 92 RAS Kernel Services . 66 Adding a Device Driver . 93 List of RAS Kernel Services . 66 Using installp Procedures. 93 Security Kernel Services . 67 Understanding Device Dependencies and Child Timer and Time-of-Day Kernel Services . 67 Devices. 93 Time-Of-Day Kernel Services . 67 Accessing Device Attributes . 94 Fine Granularity Timer Kernel Services . 67 Modifying an Attribute Value . 95 Timer Kernel Services for Compatibility . 68 Device Dependent Structure (DDS) Overview . 95 Watchdog Timer Kernel Services . 68 How the Change Method Updates the DDS . 96 Using Fine Granularity Timer Services and Guidelines for DDS Structure . 96 Structures . 68 Example of DDS. 97 Timer Services Data Structures . 68 List of Device Configuration Commands . 97 Coding the Timer Function . 69 List of Device Configuration Subroutines . 98 Using Multiprocessor-Safe Timer Services . 69 vi Kernel Extensions and Device Support Programming Concepts Chapter 7. Communications I/O Reliability, Availability, and Serviceability for Subsystem . 99 FDDI Device Driver . 129 User-Mode Interface to a Communications PDH . 99 High-Performance (8fc8) Token-Ring Device Driver 131 Kernel-Mode Interface to a Communications PDH 99 Configuration Parameters for Token-Ring Device CDLI Device Drivers . 100 Driver