⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sources.htm

📁 What is this ``device driver stuff anyway? Here s a very short introduction to the concept.
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<html><head><title>Device Driver Example Source Listings</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="DevDrvSrcList"></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="sources_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="sources_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut27.html"><img src="sources_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<img src="sources_files/BLANK.GIF" border="0">
<a href="#SrcListfordevnone"><img src="sources_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/drivertut29.html"><img src="sources_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="sources_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="sources_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h1>B&nbsp;&nbsp;&nbsp;&nbsp;Device Driver Example Source Listings</h1>
<p>
This appendix contains the source listings for the following device
drivers:
</p><ul>
<p></p><li>
<tt>/dev/none</tt>
<p>
This source listing shows how to write the
<tt>/dev/none</tt>
device driver as though it controlled a real hardware device controller
that connects to a TURBOchannel bus.
For an example of how to implement a
<tt>probe</tt>
interface so that a driver can operate on multiple buses, see
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut11.html#SetUpProbeRtnHandleMultBuses">Section 7.1.4</a>.
If you would prefer to study the
<tt>/dev/none</tt>
driver with explanations that expand on the inline comments, see the
chapters in
Part 3.
</p><p></p></li><li>
<tt>/dev/edpseudo</tt>
<p>
This source listing shows a pseudodevice driver that the driver writers
at EasyDriver Incorporated implement to test static and dynamic configuration.
A pseudodevice driver does not control a hardware device controller and,
therefore, does not operate on a bus.
</p></li></ul><p>
<a name="SrcListfordevnone"></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="sources_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="sources_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#DevDrvSrcList"><img src="sources_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<img src="sources_files/BLANK.GIF" border="0">
<a href="#SrcListfordevexpseudo"><img src="sources_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/drivertut29.html"><img src="sources_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="sources_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="sources_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h2>
B.1&nbsp;&nbsp;&nbsp;&nbsp;Source Listing for the /dev/none Device Driver
</h2>
<p>
<a name="nx_id_891"></a>
<a name="nx_id_892"></a>
</p><p>
</p><pre>/***************************************************
 *                                                 *
 *           Copyright (c) 1995 by                 *
 *   Digital Equipment Corporation, Maynard, MA    *
 *            All rights reserved.                 *
 *                                                 *
 * The information in this software is subject to  *
 * change without notice and should not be         *
 * construed as a commitment by Digital Equipment  *
 * Corporation.                                    *
 *                                                 *
 * Digital assumes no responsibility for the use   *
 * or reliability of its software on equipment     *
 * which is not supplied by Digital.               *
 ***************************************************/
<p>

/***************************************************
 * nonereg.h   Header file for none.c 13-Apr-1996  *
 *                                                 *
 *                                                 *
 * Define ioctl macros for the /dev/none driver.   *
 ***************************************************/
</p><p>
</p><p>
</p><p>
</p><p>
#define DN_GETCOUNT   _IOR(0,1,int) 
#define DN_CLRCOUNT   _IO(0,2)      

</p><p>
/***************************************************
 *                                                 *
 * Device register offset definition for the NONE  *
 * device.                                         *
 *                                                 *
 ***************************************************/
</p><p>
#define NONE_CSR 0 /* 64-bit read/write CSR/LED register */
</p></pre>
<p>
</p><p>
</p><pre>/***************************************************
 * none.c  Driver for NONE device    13-April-1996 *
 *                                                 *
 * The /dev/none device driver is an example       *
 * driver that supports a fictitious NONE device.  *
 * The /dev/none device driver shows you how       *
 * to write a device driver that can be statically *
 * or dynamically configured into the kernel.      *
 * The /dev/none driver is implemented to operate  *
 * on the TURBOchannel bus.  However, comments     *
 * describe what you need to change to support the *
 * following buses: EISA, ISA, and PCI.  To help   *
 * you more easily locate sections in the driver   *
 * that need to deal with multiple bus issues, the *
 * following words appear in the comment line:     *
 *                                                 *
 *        !!* BUS-SPECIFIC CHANGE *!!              *
 *                                                 *
 * The comments following the above words provide  *
 * information on what changes you need to make    *
 * to a device driver to support more than one     *
 * bus.                                            *
 ***************************************************/
/***************************************************
 *            A WORD ABOUT PSEUDODEVICE DRIVERS    *
 ***************************************************
 *                                                 *
 * The /dev/none driver is written as though it    *
 * controls a real hardware device and operates    *
 * on the TURBOchannel bus.  Therefore, do not     *
 * treat the /dev/none driver as a pseudodevice    *
 * driver.                                         *
 *                                                 *
 * To learn how to write a pseudodevice driver,    *
 * see Section B.2 of Writing Device Drivers:      *
 * Tutorial.  This section contains a source       *
 * listing for an example pseudodevice driver.     *
 *                                                 *
 * Because the /dev/none driver does not control   *
 * a real hardware device and does not operate on  *
 * a real bus, do not attempt to open it unless    *
 * you make the appropriate modifications.         *
 *                                                 *
 ***************************************************/
<p>
</p><p>
</p><p>
/***************************************************
 *            FEATURES OF THE /dev/none DRIVER     *
 ***************************************************
 *                                                 *
 * The following list highlights some features of  *
 * the /dev/none driver:                           *
 *                                                 *
 * o Single binary module                          *
 *                                                 *
 *   The /dev/none driver is written to produce a  *
 *   single driver image.  This single driver      *
 *   image has a file extension of .mod.  You      *
 *   compile a device driver to produce a single   *
 *   binary module that can be statically or       *
 *   dynamically configured into a Digital UNIX    *
 *   kernel at any point in time.                  *
 *                                                 *
 * o Static configuration                          *
 *                                                 *
 * The /dev/none driver's single binary module     *
 * (the none.mod file) can be:                     *
 *                                                 *
 *    - Statically configured into a Digital UNIX  *
 *      kernel (/vmunix)                           *
 *                                                 *
 *    - Statically configured into a  boot-link    *
 *      kernel (a /sysconfigtab text file)         *
 *                                                 *
 *      Typically, only device driver writers      *
 *      testing foreign devices and systems        *
 *      engineers (Digital internal) testing new   *
 *      hardware platforms in the boot path before *
 *      creating kits use the boot-link kernel     *
 *      technology.                                *
 *                                                 *
 * o Dynamic configuration                         *
 *                                                 *
 * The /dev/none driver's single binary module     *
 * (the none.mod file) can be dynamically          *
 * configured into a Digital UNIX kernel (/vmunix) *
 * when a user makes a request (by using the       *
 * sysconfig utility) at single user or multiuser  *
 * time.                                           * 
 ***************************************************/
/***************************************************
 *            INTERFACES that /dev/none IMPLEMENTS *
 ***************************************************
 *                                                 *
 * o register_configuration                        *
 * o callback_register_configuration               *
 * o register_major_number                         *
 * o callback_register_major_number                *
 * o none_configure                                *
 * o noneprobe                                     *
 * o nonecattach                                   *
 * o none_ctlr_unattach                            *
 * o noneopen                                      *
 * o noneclose                                     *
 * o noneread                                      *
 * o nonewrite                                     *
 * o noneintr                                      *
 * o noneioctl                                     *
/***************************************************
 * Tim Burke, Karl Ebner, Mark Parenti, and        *
 * Al Wojtas                                       *
 *                                                 *
 * Digital Device Driver Project                   * 
 *                                                 *
 ***************************************************/
/***************************************************
 *            Include Files Section                *
 ***************************************************/
</p><p>
</p><p>
</p><p>
</p><p>
/***************************************************
 * Common driver header files                      *
 ***************************************************/
</p><p>
#include &lt;sys/param.h&gt; 
#include &lt;sys/systm.h&gt; 
#include &lt;sys/ioctl.h&gt; 
#include &lt;sys/tty.h&gt; 
#include &lt;sys/user.h&gt; 
#include &lt;sys/proc.h&gt; 
#include &lt;sys/map.h&gt; 
#include &lt;sys/buf.h&gt; 
#include &lt;sys/vm.h&gt; 
#include &lt;sys/file.h&gt; 
#include &lt;sys/uio.h&gt; 
#include &lt;sys/types.h&gt;
#include &lt;sys/errno.h&gt;
#include &lt;sys/conf.h&gt;
#include &lt;sys/kernel.h&gt; 
#include &lt;sys/devio.h&gt; 
#include &lt;hal/cpuconf.h&gt; 
#include &lt;sys/exec.h&gt; 
#include &lt;io/common/devdriver.h&gt; 
#include &lt;sys/sysconfig.h&gt;
#include &lt;kern/kalloc.h&gt;

/***************************************************
 *        !!* BUS-SPECIFIC CHANGE *!!              *
 ***************************************************
 * If you are writing a device driver to           *
 * operate on more than one bus, you must include  *
 * the correct bus-specific header file.  The      *
 * following list shows the correct header files   *
 * for the EISA, ISA, PCI, and TURBOchannel buses: *
 *                                                 *
 *      #include &lt;io/dec/eisa/eisa.h&gt;              *
 *      #include &lt;io/dec/eisa/isa.h&gt;               *
 *      #include &lt;io/dec/pci/pci.h&gt;                *
 *      #include &lt;io/dec/tc/tc.h&gt;                  *
 *                                                 *
 * Because the fictitious NONE device controller   *
 * is connected to a TURBOchannel bus, the tc.h    *
 * file is included in the /dev/none driver for    *
 * illustrative purposes.  If your driver operates *
 * on all of these buses, you would include all of *
 * these bus-specific header files.                *
 ***************************************************/
#include &lt;io/dec/tc/tc.h&gt; 

#include &lt;machine/cpu.h&gt; 
#include &lt;io/ESA100/nonereg.h&gt; /* Device register header file */ 
</p><p>
</p><p>
</p><p>
</p><p>
/***************************************************
 * The /dev/none driver's register_major_number    *
 * interface uses the following #defines when      *
 * obtaining a major number.                       *
 ***************************************************/
</p><p>
</p><p>
</p><p>
</p><p>
#define NO_DEV -1 
#define MAJOR_INSTANCE 1
</p><p>
</p><p>
</p><p>
</p><p>
/***************************************************
 *      Data structure sizing approach             *
 ***************************************************
 *                                                 *
 * The following #define will be used to allocate  *
 * data structures needed by the /dev/none driver. *
 * There can be at most 8 instances of the NONE    *
 * device controller on the system.  This means    *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -