?? structure of device driver.htm
字號:
<html><head><title>Analyzing the Structure of a Device Driver</title>
<meta name="ROBOTS" content="NOFOLLOW">
<meta name="DESCRIPTION" content="Writing Device Drivers Tutorial: DIGITAL UNIX Version 4.0B documentation set">
<meta name="AUTHOR" content="Copyright (c) Digital Equipment Corporation 1996. All Rights Reserved."></head>
<body>
<a name="StructDrv"></a>
<p></p><hr><p align="center">
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/Digital_UNIX_Bookshelf.html"><img src="structure%20of%20device%20driver_files/BOOKSHELF.GIF" alt="[Return to Library]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/TOC.html"><img src="structure%20of%20device%20driver_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut7.html"><img src="structure%20of%20device%20driver_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<img src="structure%20of%20device%20driver_files/BLANK.GIF" border="0">
<a href="#inclfile_sect"><img src="structure%20of%20device%20driver_files/NEXT.GIF" alt="[Next Section]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut9.html"><img src="structure%20of%20device%20driver_files/FF.GIF" alt="[Next Chapter]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/INDEX.html"><img src="structure%20of%20device%20driver_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="structure%20of%20device%20driver_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h1>5 Analyzing the Structure of a Device Driver</h1>
<p>
The sections that make up a Digital UNIX device driver differ depending
on whether the driver is a block, character, or network driver.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut8.html#sect_charblkdrv">Figure 5-1</a>
shows the sections that a character
device driver can contain and
the possible sections for a block device
driver.
Device drivers are not required to use all of the sections and
more complex drivers can have additional sections.
<a name="nx_id_181"></a>
<a name="nx_id_182"></a>
</p><p>
Both types of drivers contain:
</p><ul>
<p></p><li>
An include files section
<p></p></li><li>
A declarations section
<p></p></li><li>
A configure section
<p>
The
configure
section contains the code that implements the
<tt>configure</tt>
interface.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut10.html#ImplConfigureRtn">Chapter 6</a>
explains how to implement a
<tt>configure</tt>
interface.
</p><p></p></li><li>
An autoconfiguration support section
<p>
The autoconfiguration support section contains the code that implements
the
<tt>probe</tt>,
<tt>attach</tt>,
<tt>unattach</tt>,
and
<tt>slave</tt>
interfaces.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut11.html#ImplementTheProbeRtn">Section 7.1</a>,
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut11.html#ImplemenTheattachRoutine">Section 7.2</a>,
and
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut11.html#ImplemenTheunattachRoutine">Section 7.3</a>
explain how to implement the
<tt>probe</tt>,
<tt>attach</tt>,
and
<tt>unattach</tt>
interfaces, respectively.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut11.html#ImplemenTheslaveRoutine">Section 7.4</a>
explains how to set up the
<tt>slave</tt>
interface.
</p><p></p></li><li>
An open and close device section
<p>
The open and close device section contains the code that implements
the
<tt>open</tt>
and
<tt>close</tt>
interfaces.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut14.html#ImplementTheOpenRoutine">Section 10.1</a>
and
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut14.html#ImplementTheCloseRoutine">Section 10.2</a>
explain how to implement the
<tt>open</tt>
and
<tt>close</tt>
interfaces, respectively.
</p><p></p></li><li>
An
<tt>ioctl</tt>
section
<p>
The
<tt>ioctl</tt>
section contains the code that implements the
<tt>ioctl</tt>
interface.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut14.html#ImplementTheioctlRoutine">Section 10.3</a>
explains how to implement an
<tt>ioctl</tt>
interface.
</p><p></p></li><li>
An interrupt section
<p>
The interrupt
section contains the code that implements the
device driver's interrupt handler.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut11.html#RegSharedISIswithhandlerRtns">Section 7.1.7</a>
shows how to implement an
<tt>interrupt</tt>
handler for a driver that uses shared interrupts.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut14.html#ImplementTheInterruptRoutine">Section 10.4</a>
explains how to set up an interrupt handler.
</p></li></ul><p>
</p><p>
The block device driver can also contain:
</p><ul>
<p></p><li>
A strategy section
<p>
The strategy
section contains the code that implements the device driver's
<tt>strategy</tt>
interface.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut13.html#ImplementTheStrategyRoutine">Section 9.3</a>
explains how to set up a
<tt>strategy</tt>
interface.
</p><p></p></li><li>
A
<tt>psize</tt>
section
<p>
The
<tt>psize</tt>
section contains the code that implements the device driver's
<tt>psize</tt>
interface.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut13.html#ImplementThepsizeRoutine">Section 9.2</a>
explains how to set up a
<tt>psize</tt>
interface.
</p><p></p></li><li>
A dump section
<p>
The dump
section contains the code that implements the device driver's
<tt>dump</tt>
interface.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut13.html#ImplementTheDumpRoutine">Section 9.1</a>
explains how to set up a
<tt>dump</tt>
interface.
</p></li></ul><p>
</p><p>
The character device driver contains the following sections not
contained in a block device driver:
</p><ul>
<p></p><li>
A read and write device section
<p>
The read and write device section contains the code that implements
the
<tt>read</tt>
and
<tt>write</tt>
interfaces.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut12.html#ImplementTheReadRoutine">Section 8.1</a>
and
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut12.html#ImplementTheWriteRoutine">Section 8.2</a>
explain how to implement the
<tt>read</tt>
and
<tt>write</tt>
interfaces, respectively.
</p><p></p></li><li>
A reset section
<p>
The reset section contains the code that implements
the device driver's
<tt>reset</tt>
interface.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut12.html#ImplementTheResetRoutine">Section 8.3</a>
explains how to set up a
<tt>reset</tt>
interface.
</p><p></p></li><li>
A stop section
<p>
The stop section contains the code that implements
the device driver's
<tt>stop</tt>
interface.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut12.html#ImplementTheStopRoutine">Section 8.5</a>
explains how to set up a
<tt>stop</tt>
interface.
</p><p></p></li><li>
A select section
<p>
The select section contains the code that implements
the device driver's
<tt>select</tt>
interface.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut12.html#ImplementTheSelectRoutine">Section 8.4</a>
explains how to implement a
<tt>select</tt>
interface.
</p><p></p></li><li>
A memory map section (only for CPUs that include map registers)
<p>
The memory map section contains the code that implements
the device driver's
<tt>mmap</tt>
interface.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut12.html#ImplementThemmapRoutine">Section 8.6</a>
explains how to set up an
<tt>mmap</tt>
interface.
</p></li></ul><p>
</p><p>
<a name="sect_charblkdrv"></a>
</p><h3>Figure 5-1: Sections of a Character Device Driver and a Block Device Driver</h3>
<p><img src="structure%20of%20device%20driver_files/zk-0204U.gif"></p><p>
<a name="nx_id_183"></a>
<a name="nx_id_184"></a>
</p><p>
The include files section and the declarations section are described in
the following sections.
There are two data structures that you must initialize in the
declarations section:
<tt>driver</tt>
and
<tt>dsent</tt>
(for block and character drivers).
The following sections also describe the members of these structures.
<a name="inclfile_sect"></a>
</p><p></p><hr><p align="center">
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/Digital_UNIX_Bookshelf.html"><img src="structure%20of%20device%20driver_files/BOOKSHELF.GIF" alt="[Return to Library]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/TOC.html"><img src="structure%20of%20device%20driver_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#StructDrv"><img src="structure%20of%20device%20driver_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<img src="structure%20of%20device%20driver_files/BLANK.GIF" border="0">
<a href="#ComDrvHeadFiles"><img src="structure%20of%20device%20driver_files/NEXT.GIF" alt="[Next Section]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut9.html"><img src="structure%20of%20device%20driver_files/FF.GIF" alt="[Next Chapter]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/INDEX.html"><img src="structure%20of%20device%20driver_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="structure%20of%20device%20driver_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h2>
5.1 Include Files Section
</h2>
<p>
<a name="nx_id_185"></a>
<a name="nx_id_186"></a>
Data structures and constant values are defined in header files that you
include in the include files section of the driver source code.
The number and types of header files you specify in the include files
section vary, depending on such things as what structures, constants, and
kernel interfaces
your device driver references.
You need to be familiar with:
</p><ul>
<p></p><li>
The common driver header files
<p></p></li><li>
The device register header file
<p></p></li><li>
Bus-specific header files
</li></ul><p>
The following sections describe these categories of header
files.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut8.html#DevDrvRegHeadFile">Section 5.1.2</a>
shows a device register header file, using the
<tt>/dev/none</tt>
driver as an example.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut8.html#ExInclFilesSectdevnone">Section 5.1.4</a>
shows an include files section, using the
<tt>/dev/none</tt>
driver as an example.
<cite>Writing Device Drivers: Reference</cite>
provides
reference page descriptions of the header files that
Digital UNIX device drivers use most frequently.
<a name="ComDrvHeadFiles"></a>
</p><p></p><hr><p align="center">
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/Digital_UNIX_Bookshelf.html"><img src="structure%20of%20device%20driver_files/BOOKSHELF.GIF" alt="[Return to Library]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/TOC.html"><img src="structure%20of%20device%20driver_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#StructDrv"><img src="structure%20of%20device%20driver_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<a href="#inclfile_sect"><img src="structure%20of%20device%20driver_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#typeshHeadFile"><img src="structure%20of%20device%20driver_files/NEXT.GIF" alt="[Next Section]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut9.html"><img src="structure%20of%20device%20driver_files/FF.GIF" alt="[Next Chapter]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/INDEX.html"><img src="structure%20of%20device%20driver_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="structure%20of%20device%20driver_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h3>
5.1.1 Common Driver Header Files
</h3>
<p>
<a name="nx_id_187"></a>
The following example lists the header files that device
drivers use most frequently:
</p><p>
</p><p>
</p><pre>#include <sys/types.h>
#include <sys/errno.h>
#include <io/common/devdriver.h>
#include <sys/uio.h>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -