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

📄 char n block.htm

📁 What is this ``device driver stuff anyway? Here s a very short introduction to the concept.
💻 HTM
📖 第 1 页 / 共 4 页
字号:
Declares a pointer to a
<tt>none_softc</tt>
structure and calls it
<tt>sc</tt>.
The driver initializes
<tt>sc</tt>
to the address of the
<tt>none_softc</tt>
structure associated with this
<tt>NONE</tt>
device.
The minor device number,
<tt><var>unit</var></tt>,
is used as an index into the array of
<tt>none_softc</tt>
structures to determine which
<tt>none_softc</tt>
structure is associated with this
<tt>NONE</tt>
device.
<a href="#co_id_84_rtn_7">[Return to example]</a>
<p></p></li><li>
<a name="co_id_84_8"></a>
Sets the
<tt><var>res</var></tt>
variable to point to the kernel memory allocated by the
<tt>ioctl</tt>
system call.
The
<tt>ioctl</tt>
system call copies the data to and from user address space.
<p>
Because the data types are different, this line performs a type-casting
operation that converts the
<tt><var>data</var></tt>
argument (which is of type
<tt>caddr_t</tt>)
to be of type pointer to an
<tt>int</tt>.
<a href="#co_id_84_rtn_8">[Return to example]</a>
</p><p></p></li><li>
<a name="co_id_84_9"></a>
If the
<tt>ioctl</tt>
command is equal to the
<tt>DN_GETCOUNT</tt>
macro, sets
<tt><var>res</var></tt>
to the number of bytes in the write request.
This count was previously set by the
<tt>nonewrite</tt>
interface in the
<tt>sc_count</tt>
member of the
<tt>sc</tt>
pointer.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut8.html#DevDrvRegHeadFile">Section 5.1.2</a>
discusses the
<tt>DN_GETCOUNT</tt>
macro.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut12.html#CopyDataWriteRoutine">Section 8.2.2</a>
discusses the
<tt>nonewrite</tt>
interface.
<a href="#co_id_84_rtn_9">[Return to example]</a>
<p></p></li><li>
<a name="co_id_84_10"></a>
If the
<tt>ioctl</tt>
command is equal to the
<tt>DN_CLRCOUNT</tt>
macro, sets the count of characters written to the device to the
value zero (0).
This line has the effect of clearing the
<tt>sc_count</tt>
member of the
<tt>softc</tt>
structure associated with this
<tt>NONE</tt>
device.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut8.html#DevDrvRegHeadFile">Section 5.1.2</a>
discusses the
<tt>DN_CLRCOUNT</tt>
macro.
<a href="#co_id_84_rtn_10">[Return to example]</a>
<p></p></li><li>
<a name="co_id_84_11"></a>
Returns
<tt>ESUCCESS</tt>
to indicate successful completion of the
<tt>ioctl</tt>
operation.
<a href="#co_id_84_rtn_11">[Return to example]</a>
</li></ol><p>
<a name="ImplementTheInterruptRoutine"></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="char%20n%20block_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="char%20n%20block_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#ImplBlkandCharDrvRtns"><img src="char%20n%20block_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<a href="#ImplementTheioctlRoutine"><img src="char%20n%20block_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<img src="char%20n%20block_files/BLANK.GIF" border="0">
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut15.html"><img src="char%20n%20block_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="char%20n%20block_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="char%20n%20block_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h2>
10.4&nbsp;&nbsp;&nbsp;&nbsp;Implementing the Interrupt Handler
</h2>
<p>
<a name="nx_id_526"></a>
The interrupt section applies to both character and block device drivers
and it contains a device interrupt handler, which this book refers to as
the driver's interrupt handler.
The interrupt handler
is called as a result of a hardware interrupt.
</p><p>
Digital requires that all drivers call the
<tt>handler</tt>
interfaces to dynamically register interrupt handlers. 
Typically, a device driver registers interrupt handlers in the driver's
<tt>probe</tt>
interface.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut11.html#RegISIswithhandlerRtns">Section 7.1.6</a>
discusses how to register a driver's interrupt handler (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/drivertut11.html#RegSharedISIswithhandlerRtns">Section 7.1.7</a>
discusses how to register a driver's shared interrupt handler (using the
<tt>/dev/xx</tt>
driver as an example).
</p><p>
When the kernel interrupt interface that does the initial handling of
interrupts receives an interrupt, it:
</p><ul>
<p></p><li>
Saves the state of the CPU (for example, the registers)
<p></p></li><li>
Sets up the argument list for the call to the driver (that is, the unit
number)
<p></p></li><li>
Transfers control to the appropriate driver, based on the interrupt
vector index provided by the bus
</li></ul><p>
Upon return from the driver's interrupt handler, the kernel
restores the state of the CPU to allow previously running processes to
run.
<a name="nx_id_527"></a>
</p><p>
The
<tt>/dev/none</tt>
driver's
interrupt
handler (called
<tt>noneintr</tt>)
is a stub because there is no physical device to generate an interrupt.
However, most devices can generate interrupts.
For example, a terminal might generate an interrupt when a character is
keyed into it.
There is an interrupt entry point for those drivers that are written for
devices that generate interrupts.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut5.html#SpecActionsonInterrupts">Section 2.1.3.4</a>
discusses a number of important issues relating to interrupts.
Some devices generate more than one type of interrupt.
Thus, drivers controlling these devices can contain more than one
interrupt section.
For the
<tt>/dev/none</tt>
driver, these issues are not relevant because there are no interrupts,
but they will be important for most drivers.
</p><p>
To give you an idea of some tasks an interrupt handler can perform, the
following example shows the code associated with the
<tt>/dev/xx</tt>
driver's interrupt handler (called
<tt>xxintr</tt>).
The
<tt>xxintr</tt>
interrupt handler is an example of a shared interrupt.
</p><p>
</p><p>
</p><pre>int xx_intr(parameter)
   int parameter; <a name="co_id_85_rtn_1"></a><a href="#co_id_85_1"><strong>[1]</strong></a>
{
<br>.<br>.<br>.<br>
   register struct xx_softc *sc = xx_softc[unit]; <a name="co_id_85_rtn_2"></a><a href="#co_id_85_2"><strong>[2]</strong></a>
   int intr_status; <a name="co_id_85_rtn_3"></a><a href="#co_id_85_3"><strong>[3]</strong></a>
<br>
<br>.<br>.<br>.<br>
   intr_status = xx_readio(PNV_INTR_CTRL, sc); <a name="co_id_85_rtn_4"></a><a href="#co_id_85_4"><strong>[4]</strong></a>

   if (!(intr_status &amp; PNV_INTR_OCCURRED))
        return(INTR_NOT_SERVICED); <a name="co_id_85_rtn_5"></a><a href="#co_id_85_5"><strong>[5]</strong></a>

   if ((intr_status &amp; PNV_DMA_INTR) { <a name="co_id_85_rtn_6"></a><a href="#co_id_85_6"><strong>[6]</strong></a>
        xx_writeio(PNV_INTR_CTRL,
                        (intr_status &amp; ~(PNV_CRD_INTR|PNV_ABRT_INTR)), sc);
<br>
<br>.<br>.<br>.<br>
   }
   return(INTR_SERVICED); <a name="co_id_85_rtn_7"></a><a href="#co_id_85_7"><strong>[7]</strong></a>
} /* End of xx_intr */
</pre>
<p>
</p><p>
</p><ol>
<p></p><li>
<a name="co_id_85_1"></a>
Specifies
any parameter that the driver needs to control operation of the
interrupt handler.
The value that gets passed to the
<tt><var>parameter</var></tt>
argument is the value you stored in the
<tt>param</tt>
member of the
<tt>handler_intr_info</tt>
data structure.
<p>
In this example, the device driver's interrupt handler does not make
use of this argument.
<a href="#co_id_85_rtn_1">[Return to example]</a>
</p><p></p></li><li>
<a name="co_id_85_2"></a>
Specifies a pointer to a
<tt>softc</tt>
data structure and initializes it to the
<tt>softc</tt>
structure associated with this
<tt>XX</tt>
device.
<a href="#co_id_85_rtn_2">[Return to example]</a>
<p></p></li><li>
<a name="co_id_85_3"></a>
Declares a variable called
<tt><var>intr_status</var></tt>
that stores the bit associated with the interrupt controller register
after the interrupt occurred.
<a href="#co_id_85_rtn_3">[Return to example]</a>
<p></p></li><li>
<a name="co_id_85_4"></a>
Calls the device driver's
<tt>xx_readio</tt>
interface, which reads the interrupt control register
<tt>PNV_INTR_CTRL</tt>
to determine if an interrupt occurred.
(Assume that the
<tt>/dev/xx</tt>
driver implements the
<tt>xx_readio</tt>
interface to read the control register.)
<a href="#co_id_85_rtn_4">[Return to example]</a>
<p></p></li><li>
<a name="co_id_85_5"></a>
If there is no interrupt status bit set in the interrupt control
register, returns the constant
<tt>INTR_NOT_SERVICED</tt>
to the kernel's interrupt dispatch code.
This constant indicates that the driver's interrupt handler
did not service the shared
interrupt.
<a href="#co_id_85_rtn_5">[Return to example]</a>
<p></p></li><li>
<a name="co_id_85_6"></a>
If the interrupt control register is set to the
<tt>PNV_DMA_INTR</tt>
bit, then an interrupt occurred.
Calls the device driver's
<tt>xx_writeio</tt>
interface to write the bit status to the interrupt control register.
(Assume that the
<tt>/dev/xx</tt>
driver implements the
<tt>xx_writeio</tt>
interface to write the bit status.)
<a href="#co_id_85_rtn_6">[Return to example]</a>
<p></p></li><li>
<a name="co_id_85_7"></a>
Returns
<tt>INTR_SERVICED</tt>
to the kernel's interrupt dispatch code to indicate that the driver's
interrupt handler serviced the shared interrupt.
<a href="#co_id_85_rtn_7">[Return to example]</a>
</li></ol><p>
<!--Metrics Tag -->
 <!-- Updated April 22, 2003 --> 
<!-- SiteCatalyst code version: G.0. w/dev site filtering
Copyright 1997-2003 Omniture, Inc. More info available at
http://www.omniture.com --><script language="JavaScript"><!--
/* Specify the Report Suite ID(s) to track here */
var s_account="HPHQGlobal,hphqWWesg,hphqbcs,hphqtru64"
/* Dynamic Report Suite ID Selection Config */
var s_dynamicAccountSelection = true
var s_dynamicAccountList = "hphqwwtrash=dec.com,cpqcorp.net,hpqcorp.net"
/* You may give each page an identifying user friendly name in place of urls. */
var s_pageName="Tru64-" + document.title;
if ( location.pathname.indexOf('/docs' ) != -1 )         { s_pageName = "Tru64-docs-" + document.title; }

/* Regionally assigned variables. */
var s_server=""
var s_channel=""
var s_pageType=""
var s_prop1="Tru64 UNIX"
if ( location.pathname.indexOf('/docs' ) != -1 )         { s_prop1 = "Tru64 documentation"; }
var s_prop2 = "";

   if ( location.search.indexOf('?jumpid=' ) != -1 )
        {
        s_prop2=location.search.substring((location.search.indexOf('?jumpid=' )+8),(location.search.length));
        }
			else
		{ 
		if (location.search.toUpperCase().indexOf('?' ) != -1 )        {
		s_prop2=location.search.toUpperCase().substring((location.search.toUpperCase().indexOf('?' )+1),(location.search.length));
		}
		}
var s_prop6=""
var s_prop7="w1"
var s_prop8="en-us"
var s_prop9="enterprise"
var s_prop10="w1|en-us|enterprise"
var s_prop13="HPHQGlobal,hphqWWesg,hphqbcs,hphqtru64"


/************************ ADDITIONAL FEATURES ************************
     Plugins
*/
/************************** CONFIG SECTION **************************/
/* You may add or alter any code config here.                       */
var s_charSet=""
// Netscape 4.X on Unix uses EUC-JP instead of SHIFT-JIS
if ((navigator.appName.indexOf('Netscape')>=0)&&
    (parseInt(navigator.appVersion)<=4)&&
    (navigator.userAgent.toLowerCase().indexOf('win')<0)&&
    (navigator.userAgent.toLowerCase().indexOf('mac')<0)) {
	s_charSet="EUC-JP"
}
/* E-commerce Config */
var s_eVarCFG=""

/* Link Tracking Config */
var s_trackDownloadLinks=true
var s_trackExternalLinks=true
var s_trackInlineStats=true
var s_linkDownloadFileTypes="exe,zip,wav,mp3,mov,mpg,avi,doc,pdf,xls,cgi,dot,pot,ppt,wmv,cgi,asx,tar,rpm,gz,crypt,sh"
var s_linkInternalFilters="hp,compaq,javascript:"
var s_linkLeaveQueryString=true


/********* INSERT THE DOMAIN AND PATH TO YOUR CODE BELOW ************/
//--></script><script language="JavaScript" src="char%20n%20block_files/s_code.js"></script><img src="char%20n%20block_files/s57468949005429.gif" name="s_i_hphqglobal" border="0" height="1" width="1">
<!-- End SiteCatalyst code version: G.0. -->

<!--End Tag -->
</p></body></html>

⌨️ 快捷键说明

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