Writing Device Drivers.pdf

(1363 KB) Pobierz
No Job Name
Writing Device Drivers
Sun Microsystems, Inc.
4150 Network Circle
Santa Clara, CA 95054
U.S.A.
Part No: 806–5222–10
May 2002
189417863.001.png
Copyright 2002 Sun Microsystems, Inc.
4150 Network Circle, Santa Clara, CA 95054 U.S.A. All rights reserved.
This product or document is protected by copyright and distributed under licenses restricting its use, copying, distribution, and decompilation. No
part of this product or document may be reproduced in any form by any means without prior written authorization of Sun and its licensors, if any.
Third-party software, including font technology, is copyrighted and licensed from Sun suppliers.
Parts of the product may be derived from Berkeley BSD systems, licensed from the University of California. UNIX is a registered trademark in the U.S.
and other countries, exclusively licensed through X/Open Company, Ltd.
Sun, Sun Microsystems, the Sun logo, docs.sun.com, AnswerBook, AnswerBook2, Sun Cluster, Sun Workshop Compilers C, Power Management,
Ultra, and Solaris are trademarks, registered trademarks, or service marks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC
trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the U.S. and other countries. Products
bearing SPARC trademarks are based upon an architecture developed by Sun Microsystems, Inc.
The OPEN LOOK and Sun™ Graphical User Interface was developed by Sun Microsystems, Inc. for its users and licensees. Sun acknowledges the
pioneering efforts of Xerox in researching and developing the concept of visual or graphical user interfaces for the computer industry. Sun holds a
non-exclusive license from Xerox to the Xerox Graphical User Interface, which license also covers Sun’s licensees who implement OPEN LOOK GUIs
and otherwise comply with Sun’s written license agreements.
Federal Acquisitions: Commercial Software–Government Users Subject to Standard License Terms and Conditions.
DOCUMENTATION IS PROVIDED “AS IS” AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE
DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID.
Copyright 2002 Sun Microsystems, Inc. 4150 Network Circle, Santa Clara, CA 95054 U.S.A. Tous droits réservés
Ce produit ou document est protégé par un copyright et distribué avec des licences qui en restreignent l’utilisation, la copie, la distribution, et la
décompilation. Aucune partie de ce produit ou document ne peut être reproduite sous aucune forme, par quelque moyen que ce soit, sans
l’autorisation préalable et écrite de Sun et de ses bailleurs de licence, s’il y en a. Le logiciel détenu par des tiers, et qui comprend la technologie relative
aux polices de caractères, est protégé par un copyright et licencié par des fournisseurs de Sun.
Des parties de ce produit pourront être dérivées du système Berkeley BSD licenciés par l’Université de Californie. UNIX est une marque déposée aux
Etats-Unis et dans d’autres pays et licenciée exclusivement par X/Open Company, Ltd.
Sun, Sun Microsystems, le logo Sun, docs.sun.com, AnswerBook, AnswerBook2, Sun Cluster, Sun Workshop Compilers C, Power Management, Ultra,
et Solaris sont des marques de fabrique ou des marques déposées, ou marques de service, de Sun Microsystems, Inc. aux Etats-Unis et dans d’autres
pays. Toutes les marques SPARC sont utilisées sous licence et sont des marques de fabrique ou des marques déposées de SPARC International, Inc.
aux Etats-Unis et dans d’autres pays. Les produits portant les marques SPARC sont basés sur une architecture développée par Sun Microsystems, Inc.
L’interface d’utilisation graphique OPEN LOOK et Sun™ a été développée par Sun Microsystems, Inc. pour ses utilisateurs et licenciés. Sun reconnaît
les efforts de pionniers de Xerox pour la recherche et le développement du concept des interfaces d’utilisation visuelle ou graphique pour l’industrie
de l’informatique. Sun détient une licence non exclusive de Xerox sur l’interface d’utilisation graphique Xerox, cette licence couvrant également les
licenciés de Sun qui mettent en place l’interface d’utilisation graphique OPEN LOOK et qui en outre se conforment aux licences écrites de Sun.
CETTE PUBLICATION EST FOURNIE “EN L’ETAT” ET AUCUNE GARANTIE, EXPRESSE OU IMPLICITE, N’EST ACCORDEE, Y COMPRIS DES
GARANTIES CONCERNANT LA VALEUR MARCHANDE, L’APTITUDE DE LA PUBLICATION A REPONDRE A UNE UTILISATION
PARTICULIERE, OU LE FAIT QU’ELLE NE SOIT PAS CONTREFAISANTE DE PRODUIT DE TIERS. CE DENI DE GARANTIE NE
S’APPLIQUERAIT PAS, DANS LA MESURE OU IL SERAIT TENU JURIDIQUEMENT NUL ET NON AVENU.
020125@3062
189417863.002.png
Contents
Preface 17
1 Solaris Kernel and Device Tree
23
What Is the Kernel? 23
Multithreaded Execution Environment
25
Virtual Memory 25
Devices as Special Files
25
DDI/DKI Interfaces 26
Overview of the Device Tree
27
Device Tree Components
27
Displaying the Device Tree
28
Binding a Driver to a Device
30
2 Overview of Solaris Device Drivers
35
What Is a Device Driver? 35
Types of Device Drivers 36
Block Device Drivers 36
Character Device Drivers
36
STREAMS Drivers 37
Driver Module Entry Points 37
Loadable Module Entry Points 38
Autoconfiguration Entry Points 38
Character and Block Driver Entry Points
39
Power Management Entry Point
39
Device Driver Design Considerations
39
3
DDI/DKI Facilities
39
Driver Context 42
Returning Errors 42
Dynamic Memory Allocation
43
Hotplugging
43
Driver Layout
44
3 Multithreading 45
Locking Primitives 45
Storage Classes of Driver Data
45
Mutual-Exclusion Locks
46
Readers/Writer Locks
47
Semaphores 48
Thread Synchronization 48
Condition Variables in Thread Synchronization
48
cv_wait() and cv_timedwait() Functions
50
cv_wait_sig() Function 51
cv_timedwait_sig() Function
52
Choosing a Locking Scheme
52
Potential Locking Pitfalls
53
4 Properties and Events
55
Device Properties 55
Device Property Names 56
Creating and Updating Properties
56
Looking up Properties
56
prop_op() Entry Point
58
Events 59
How Drivers Track Events: ddi_log_sysevent() 60
Event Name-Value Pairs
62
5 Driver Autoconfiguration 65
Driver Loading and Unloading 65
Data Structures Required for Drivers
66
modlinkage Structure
66
modldrv Structure
67
dev_ops Structure
67
4 Writing Device Drivers • May 2002
cb_ops Structure 68
Loadable Driver Interfaces
69
_init() Example 70
_fini() Example 71
_info() Example 71
Device Configuration Concepts 72
Device Instances and Instance Numbers
72
Minor Nodes and Minor Numbers
73
The probe() Entry Point
73
The attach() Entry Point
76
The detach() Entry Point
82
The getinfo() Entry Point
83
Using Device IDs 85
Registering Device IDs
85
Unregistering Device IDs
86
6 Device Access — Programmed I/O
87
Device Memory 87
Managing Differences in Device and Host Endianness
88
Managing Data Ordering Requirements
88
ddi_device_acc_attr Structure
88
Mapping Device Memory
89
Mapping Setup Example
90
Device Access Functions 91
Alternate Device Access Interfaces
92
7 Interrupt Handlers 95
Interrupt Handler Overview
95
Interrupt Specification
95
Interrupt Number 96
Interrupt Block Cookies
96
Device Interrupts 96
High-Level Interrupts
97
Normal Interrupts 97
Software Interrupts 97
Registering Interrupts 98
Interrupt Handler Responsibilities
99
Contents 5
Zgłoś jeśli naruszono regulamin