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

📄 supp device auto config.htm

📁 What is this ``device driver stuff anyway? Here s a very short introduction to the concept.
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<html><head><title>Implementing Device Driver Interfaces That Support Device Autoconfiguration</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="ImplProbeRtn"></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="supp%20device%20auto%20config_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="supp%20device%20auto%20config_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut10.html"><img src="supp%20device%20auto%20config_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<img src="supp%20device%20auto%20config_files/BLANK.GIF" border="0">
<a href="#ImplementTheProbeRtn"><img src="supp%20device%20auto%20config_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/drivertut12.html"><img src="supp%20device%20auto%20config_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="supp%20device%20auto%20config_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="supp%20device%20auto%20config_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h1>7&nbsp;&nbsp;&nbsp;&nbsp;Implementing Device Driver Interfaces That Support Device Autoconfiguration</h1>
<p>
When Digital UNIX boots up, the kernel determines what devices are
connected to the computer.
After finding a device, the kernel initializes it so that the device can
be used at a later time.
A device driver has a
<tt>probe</tt>,
<tt>attach</tt>,
and possibly a
<tt>slave</tt>
interface.
The
<tt>probe</tt>
interface determines if a particular device is present and the
<tt>attach</tt>
interface initializes the device.
The
<tt>slave</tt>
interface, if one is implemented, checks that a device is valid for a
specific controller.
</p><p>
The autoconfiguration support section of a device driver contains the
code that implements these interfaces for both character and
block device drivers.
For drivers that are dynamically configured into the kernel, the
autoconfiguration support section also
contains a controller
<tt>unattach</tt>
or a device
<tt>unattach</tt>
interface, which is
called when the driver is unloaded.
You define the entry point for each of these interfaces in the
<tt>driver</tt>
structure.
</p><p>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut8.html#driver_struct">Section 5.3</a>
describes the
<tt>driver</tt>
structure.
The following sections show you how to set up and implement each
of these interfaces.
If you prefer to study the
<tt>/dev/none</tt>
driver with inline comments, see the source code listing in
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut28.html#DevDrvSrcList">Appendix B</a>.
<a name="ImplementTheProbeRtn"></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="supp%20device%20auto%20config_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="supp%20device%20auto%20config_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#ImplProbeRtn"><img src="supp%20device%20auto%20config_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<img src="supp%20device%20auto%20config_files/BLANK.GIF" border="0">
<a href="#MultipleBusIssues"><img src="supp%20device%20auto%20config_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/drivertut12.html"><img src="supp%20device%20auto%20config_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="supp%20device%20auto%20config_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="supp%20device%20auto%20config_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h2>
7.1&nbsp;&nbsp;&nbsp;&nbsp;Implementing the probe Interface
</h2>
<p>
<a name="nx_id_353"></a>
A device driver's
<tt>probe</tt>
interface performs the tasks necessary to determine if the device exists
and is functional on a given system.
The bus configuration code calls the driver's
<tt>probe</tt>
interface. 
You specify the entry point for the driver's
<tt>probe</tt>
interface
in the
<tt>driver</tt>
structure.
</p><p>
To implement a
<tt>probe</tt>
interface you must understand the multiple bus issues associated with a
<tt>probe</tt>
interface and the I/O handle.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut11.html#MultipleBusIssues">Section 7.1.1</a>
and
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut11.html#TheIOHandle">Section 7.1.2</a>
discuss these topics.
</p><p>
The following list describes some typical tasks that a
<tt>probe</tt>
interface performs:
</p><ul>
<p></p><li>
Sets up the
<tt>probe</tt>
interface
<p></p></li><li>
Sets up the
<tt>probe</tt>
interface to handle multiple buses
<p></p></li><li>
Uses data structures to register interrupt handlers
<p></p></li><li>
Uses the
<tt>handler</tt>
interfaces to register interrupt handlers
<p></p></li><li>
Uses the
<tt>handler</tt>
interfaces to register shared interrupt handlers
<p></p></li><li>
Uses
<tt>BADADDR</tt>
to probe the address
<p></p></li><li>
Uses
<tt>read_io_port</tt>
and
<tt>write_io_port</tt>
to read and write data
<p></p></li><li>
Uses driver-specific macros to read and write data
</li></ul><p>
Your
<tt>probe</tt>
interface will probably perform most of these tasks and, possibly, some
additional ones.
The following sections describe each of these tasks.
<a name="MultipleBusIssues"></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="supp%20device%20auto%20config_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="supp%20device%20auto%20config_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#ImplProbeRtn"><img src="supp%20device%20auto%20config_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<a href="#ImplementTheProbeRtn"><img src="supp%20device%20auto%20config_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#TheIOHandle"><img src="supp%20device%20auto%20config_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/drivertut12.html"><img src="supp%20device%20auto%20config_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="supp%20device%20auto%20config_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="supp%20device%20auto%20config_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h3>
7.1.1&nbsp;&nbsp;&nbsp;&nbsp;Resolving Multiple Bus Issues Related to Implementing a probe Interface
</h3>
<p>
<a name="nx_id_354"></a>
<a name="nx_id_355"></a>
The first argument associated with a driver's
<tt>probe</tt>
interface is bus specific.
To write portable device drivers across multiple bus architectures, you
need to know the first argument associated with the
<tt>probe</tt>
interface for that bus.
See the bus-specific driver book for a description of the first argument
associated with the
<tt>probe</tt>
interface for that bus.
</p><p>
The second argument for a driver's
<tt>probe</tt>
interface is always a pointer to a
<tt>controller</tt>
structure.
You can use the
<tt>controller</tt>
structure pointer to determine the bus to which the device controller
is connected.
Typically, you reference the
<tt>bus_name</tt>
member of the
<tt>bus</tt>
structure through the
<tt>controller</tt>
structure's
<tt>bus_hd</tt>
member.
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut24.html#DeviceAutoconfig">Chapter 17</a>
discusses the members of the
<tt>bus</tt>
and
<tt>controller</tt>
structures.
<a name="TheIOHandle"></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="supp%20device%20auto%20config_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="supp%20device%20auto%20config_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#ImplProbeRtn"><img src="supp%20device%20auto%20config_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<a href="#MultipleBusIssues"><img src="supp%20device%20auto%20config_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#SetUpProbeRoutine"><img src="supp%20device%20auto%20config_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/drivertut12.html"><img src="supp%20device%20auto%20config_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="supp%20device%20auto%20config_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="supp%20device%20auto%20config_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h3>
7.1.2&nbsp;&nbsp;&nbsp;&nbsp;Using the I/O Handle
</h3>
<p>
<a name="nx_id_356"></a>
<a name="nx_id_357"></a>
<a name="nx_id_358"></a>
<a name="nx_id_359"></a>
As described in
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut5.html#TheIOHandleDataType">Section 2.3.1</a>,
the I/O handle is a data entity that is of type
<tt>io_handle_t</tt>.
Device drivers use the I/O handle to reference bus address space (either
I/O space or memory space).
</p><p>
The bus configuration code passes the I/O handle to the
device driver's
<tt>probe</tt>
interface during device autoconfiguration.
(The bus configuration code also passes this I/O handle to the device
driver's
<tt>slave</tt>
interface, if one is implemented, during device autoconfiguration.)
The number of I/O handles that the bus configuration code
passes to the device driver depends on the bus the device
operates on.
The I/O handle passed to the driver's
<tt>probe</tt>
interface describes how to access (address) that
device on a particular Alpha CPU.
</p><p>
The properties associated with an I/O handle depend on what
slot, bus, or child bus the device resides in.
</p><p>
An I/O handle has properties similar to memory-mapped registers
on other UNIX-based systems (for example, TURBOchannel base address regions
on ULTRIX MIPS).
See the bus-specific device driver books for information on
the I/O handle or handles a specific bus passes to a device
driver's
<tt>probe</tt>
interface.
</p><p>
You can perform standard C mathematical operations (addition and
subtraction only) on the I/O handle.
For example, you can add an offset to or subtract an offset from the
I/O handle.
The following list points out restrictions on the use of the I/O handle:
</p><ul>
<p></p><li>
You cannot add two I/O handles.
<p></p></li><li>
You cannot pass an I/O handle directly to the
<tt>PHYS_TO_KSEG</tt>
interface.
<p></p></li><li>
You cannot use the I/O handle as an address.
</li></ul><p>
</p><p>
You call the
<tt>iohandle_to_phys</tt>
interface to convert an I/O handle into a valid system
physical address that resides in sparse space, dense space,
or bus physical address space.
</p><p>
One purpose of the I/O handle is to hide CPU-specific architecture
idiosyncracies that describe how to access a device's control status registers
(CSRs) and how to perform I/O copy operations.
For example, rather than perform an I/O copy operation according to
a specific CPU architecture, you call an I/O copy interface that uses
the I/O handle.
The use of the I/O handle guarantees device driver portability across
those CPUs on which the I/O copy interface is implemented.
</p><p>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut11.html#RegISIswithhandlerRtns">Section 7.1.6</a>
shows you how the
<tt>/dev/none</tt>
driver deals with the I/O handle.
<a name="SetUpProbeRoutine"></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="supp%20device%20auto%20config_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="supp%20device%20auto%20config_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#ImplProbeRtn"><img src="supp%20device%20auto%20config_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<a href="#TheIOHandle"><img src="supp%20device%20auto%20config_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#SetUpProbeRtnHandleMultBuses"><img src="supp%20device%20auto%20config_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/drivertut12.html"><img src="supp%20device%20auto%20config_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="supp%20device%20auto%20config_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="supp%20device%20auto%20config_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h3>
7.1.3&nbsp;&nbsp;&nbsp;&nbsp;Setting Up the probe Interface
</h3>
<p>
<a name="nx_id_360"></a>
The way you set up a
<tt>probe</tt>
interface depends on the bus on which the driver operates.
The following code example shows you how to set up a
<tt>probe</tt>
interface for a
driver that operates on a TURBOchannel bus, using the
<tt>/dev/none</tt>
driver as an example:
</p><p>
</p><p>
</p><pre>noneprobe(bus_io_handle, ctlr)
io_handle_t bus_io_handle; <a name="co_id_50_rtn_1"></a><a href="#co_id_50_1"><strong>[1]</strong></a>
struct controller *ctlr; <a name="co_id_50_rtn_2"></a><a href="#co_id_50_2"><strong>[2]</strong></a>
<p>
{
</p></pre>
<p>
<br>
<tt>.</tt>
<br>
<tt>.</tt>
<br>
<tt>.</tt>
<br>
</p><p>
</p><ol>
<p></p><li>
<a name="co_id_50_1"></a>
Declares an argument that specifies an I/O handle that you can use to
reference a device register or memory located in bus address space
(either I/O space or memory space).
This I/O handle references the device's I/O address space for the bus
where the read operation originates (in calls to the
<tt>read_io_port</tt>
interface) and where the write operation occurs (in calls to the
<tt>write_io_port</tt>
interface).
The bus configuration code passes this I/O handle to the driver's
<tt>probe</tt>
interface during device autoconfiguration.
<a href="#co_id_50_rtn_1">[Return to example]</a>
<p></p></li><li>
<a name="co_id_50_2"></a>
Declares a pointer to a

⌨️ 快捷键说明

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