📄 structure of device driver.htm
字号:
#include <machine/cpu.h>
#include <sys/conf.h>
#include <sys/sysconfig.h>
</pre>
<p>
</p><p>
The example shows that
device drivers should not use explicit pathnames.
Using angle brackets (< and >) means you will not have to make changes to
your device driver if the file path changes.
</p><p>
The following sections contain brief descriptions of the previously
listed common driver header files.
<a name="nx_id_188"></a>
<a name="nx_id_189"></a>
<a name="typeshHeadFile"></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="#ComDrvHeadFiles"><img src="structure%20of%20device%20driver_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#errnohHeadFile"><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.1 The types.h Header File
</h3>
<p>
The header file
<tt>/usr/sys/include/sys/types.h</tt>
defines system data types used to declare members in the data structures
referenced by device drivers.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut8.html#datatypes_usedbydrvs">Table 5-1</a>
lists the system data types defined in this file that device drivers
use most frequently.
<a name="nx_id_190"></a>
<a name="datatypes_usedbydrvs"></a>
</p><h3>
Table 5-1: Frequently-Used System Data Types Defined in the types.h File
</h3>
<a name="nx_id_191"></a>
<a name="nx_id_192"></a>
<a name="nx_id_193"></a>
<a name="nx_id_194"></a>
<a name="nx_id_195"></a>
<a name="nx_id_196"></a>
<a name="nx_id_197"></a>
<a name="nx_id_198"></a>
<table border="4" cellpadding="4">
<tbody><tr>
<td align="left" valign="top">
<strong>
Data Type
</strong>
</td>
<td align="left" valign="top">
<strong>
Meaning
</strong>
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>daddr_t</tt>
</td>
<td align="left" valign="top">
Block device address
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>caddr_t</tt>
</td>
<td align="left" valign="top">
Main memory virtual address
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>ino_t</tt>
</td>
<td align="left" valign="top">
Inode index
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>dev_t</tt>
</td>
<td align="left" valign="top">
Device major and minor numbers
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>off_t</tt>
</td>
<td align="left" valign="top">
File offset
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>paddr_t</tt>
</td>
<td align="left" valign="top">
Main memory physical address
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>time_t</tt>
</td>
<td align="left" valign="top">
System time
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>u_short</tt>
</td>
<td align="left" valign="top">
<tt>unsigned short</tt>
</td>
</tr>
</tbody></table><p>
</p><p>
The
<tt>/usr/sys/include/sys/types.h</tt>
header file includes the file
<tt>/mach/machine/vm_types.h</tt>.
This file defines the data type
<tt>vm_offset_t</tt>,
which driver writers should use when addresses are treated as arithmetic
quantities (that is, as ints and longs).
The
<tt>vm_offset_t</tt>
data type is defined as
<tt>unsigned long</tt>
on Alpha systems.
<a name="errnohHeadFile"></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="#typeshHeadFile"><img src="structure%20of%20device%20driver_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#devdrvhHeadFile"><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.2 The errno.h Header File
</h3>
<p>
<a name="nx_id_199"></a>
<a name="nx_id_200"></a>
The header file
<tt>/usr/sys/include/sys/errno.h</tt>
defines the error codes returned to a user process by a device driver.
Examples of these error codes include
<tt>EINVAL</tt>
(invalid argument),
<tt>ENODEV</tt>
(no such device),
and
<tt>EIO</tt>
(I/O error).
<a name="nx_id_201"></a>
<a name="nx_id_202"></a>
<a name="nx_id_203"></a>
<a name="devdrvhHeadFile"></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="#errnohHeadFile"><img src="structure%20of%20device%20driver_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#uiohHeadFile"><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.3 The devdriver.h Header File
</h3>
<p>
<a name="nx_id_204"></a>
The header file
<tt>/usr/sys/include/io/common/devdriver.h</tt>
defines structures, constants, data types, and external interfaces that
device drivers and the autoconfiguration software use.
Two opaque data types that you can use to make your device drivers more
portable are
<tt>io_handle_t</tt>
and
<tt>dma_handle_t</tt>.
</p><p>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut11.html#TheIOHandle">Section 7.1.2</a>
and
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut25.html#DataStructsUsedwithDMAInter">Section 18.6.1</a>
discuss the I/O and DMA handles.
<a name="nx_id_205"></a>
<a name="nx_id_206"></a>
<a name="nx_id_207"></a>
<a name="uiohHeadFile"></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="#devdrvhHeadFile"><img src="structure%20of%20device%20driver_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#cpuhHeadFile"><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.4 The uio.h Header File
</h3>
<p>
<a name="nx_id_208"></a>
<a name="nx_id_209"></a>
The header file
<tt>/usr/sys/include/sys/uio.h</tt>
contains the definition of the
<tt>uio</tt>
structure.
The kernel sets up and uses the
<tt>uio</tt>
structures to read and write data.
Character device drivers include this file because they may reference the
<tt>uio</tt>
structure.
</p><p>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut12.html#theuio_struct">Section 8.1.2</a>
discusses the
<tt>uio</tt>
structure.
<a name="cpuhHeadFile"></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="#uiohHeadFile"><img src="structure%20of%20device%20driver_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#confhHeadFile"><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.5 The cpu.h Header File
</h3>
<p>
<a name="nx_id_210"></a>
<a name="nx_id_211"></a>
The
<tt>cpu.h</tt>
file defines a variety of structures and constants related to the CPU.
You include the
<tt>cpu.h</tt>
file in block and character device drivers when calling any of the
<tt>spl</tt>
interfaces.
The reason for this is that the
<tt>spl</tt>
interfaces map to an assembler interface.
<a name="confhHeadFile"></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="#cpuhHeadFile"><img src="structure%20of%20device%20driver_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#sysconfighHeadFile"><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.6 The conf.h Header File
</h3>
<p>
<a name="nx_id_212"></a>
The header file
<tt>/usr/sys/include/sys/conf.h</tt>
defines the
<tt>dsent</tt>
structure (for block and character devices).
You should include the
<tt>conf.h</tt>
file in block and character device drivers because
these drivers declare an instance of and set the associated members of the
<tt>dsent</tt>
structure.
For statically and dynamically configured device drivers,
the driver writer declares and initalizes an instance of a
<tt>dsent</tt>
structure and then passes the address of this initialized structure to the
<tt>devsw_add</tt>
interface.
This interface adds the I/O services interfaces (and other information)
for block and character drivers to the device switch table
and reserves an associated major number.
</p><p>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut8.html#dev_swit_tbls">Section 5.4</a>
describes the device switch table.
<a name="nx_id_213"></a>
<a name="nx_id_214"></a>
<a name="nx_id_215"></a>
<a name="sysconfighHeadFile"></a>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -