📄 supp static n dynamic config.htm
字号:
<html><head><title>Implementing a Configure Interface to Support Static and Dynamic Configuration</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="ImplConfigureRtn"></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%20static%20n%20dynamic%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%20static%20n%20dynamic%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/drivertut9.html"><img src="supp%20static%20n%20dynamic%20config_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<img src="supp%20static%20n%20dynamic%20config_files/BLANK.GIF" border="0">
<a href="#cfg_subsys_attr_tStruct"><img src="supp%20static%20n%20dynamic%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/drivertut11.html"><img src="supp%20static%20n%20dynamic%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%20static%20n%20dynamic%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%20static%20n%20dynamic%20config_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h1>6 Implementing a Configure Interface to Support Static and Dynamic Configuration</h1>
<p>
A device driver's
<tt>configure</tt>
interface cooperates with the
<tt>cfgmgr</tt>
framework to handle user-level requests
to dynamically configure, unconfigure, query,
and reconfigure a device driver.
In addition, the driver's
<tt>configure</tt>
interface cooperates with the
<tt>cfgmgr</tt>
framework to handle static configuration requests.
The driver's
<tt>configure</tt>
interface also cooperates with the
<tt>cfgmgr</tt>
framework to perform one-time initialization tasks such as allocating
memory, initializing data structures and variables, adding the
driver's I/O services interfaces, and reserving a major number in the
<tt>dsent</tt>
(device switch) table.
You should implement a driver's
<tt>configure</tt>
interface to handle static and dynamic
configuration.
<a name="nx_id_297"></a>
</p><p>
The code associated with this interface resides in the configure section
of the device driver.
To implement a
<tt>configure</tt>
interface, you must perform the following tasks:
</p><ul>
<p></p><li>
Use the
<tt>cfg_subsys_attr_t</tt>
data structure
<p></p></li><li>
Use the
<tt>cfg_attr_t</tt>
data structure
<p></p></li><li>
Set up configure-related declarations and the
<tt>cfg_subsys_attr_t</tt>
data structure
<p></p></li><li>
Define bus-specific name constants
<p></p></li><li>
Understand multiple bus issues related to the
<tt>configure</tt>
interface
<p></p></li><li>
Set up the
<tt>configure</tt>
interface
<p></p></li><li>
Implement the
<tt>CFG_OP_CONFIGURE</tt>
(configure) operation
<p></p></li><li>
Implement the
<tt>CFG_OP_UNCONFIGURE</tt>
(unconfigure) operation
<p></p></li><li>
Implement the
<tt>CFG_OP_RECONFIGURE</tt>
(reconfigure) operation
<p></p></li><li>
Implement the
<tt>CFG_OP_QUERY</tt>
(query) operation
<p></p></li><li>
Implement the default operation
</li></ul><p>
The following sections describe each of these tasks.
<a name="cfg_subsys_attr_tStruct"></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%20static%20n%20dynamic%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%20static%20n%20dynamic%20config_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#ImplConfigureRtn"><img src="supp%20static%20n%20dynamic%20config_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<img src="supp%20static%20n%20dynamic%20config_files/BLANK.GIF" border="0">
<a href="#cfg_attrStruct"><img src="supp%20static%20n%20dynamic%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/drivertut11.html"><img src="supp%20static%20n%20dynamic%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%20static%20n%20dynamic%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%20static%20n%20dynamic%20config_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h2>
6.1 Using the cfg_subsys_attr_t Structure
</h2>
<p>
<a name="nx_id_298"></a>
The
<tt>cfg_subsys_attr_t</tt>
data structure contains information that device drivers use to
describe a variety of attributes.
Device driver writers declare and initialize an array of
<tt>cfg_subsys_attr_t</tt>
structures in their device drivers.
The
<tt>cfg_subsys_attr_t</tt>
structure is a simplified version of the
<tt>cfg_attr_t</tt>
structure and is designed to save space in the kernel.
Driver writers need to be intimately familiar with the
members of the
<tt>cfg_subsys_attr_t</tt>
structure.
The following code shows the C definition:
</p><p>
</p><p>
</p><pre>typedef struct {
char name[CFG_ATTR_NAME_SZ];
uchar type;
uchar operation;
caddr_t addr;
ulong min_val;
ulong max_val;
ulong val_size;
} cfg_subsys_attr_t;
</pre>
<p>
<a name="nx_id_299"></a>
The
<tt>name</tt>
member specifies
the ASCII name of the attribute.
The name must be between two and
<tt>CFG_ATTR_NAME_SZ</tt>
characters in length, including the terminating null character.
Do not begin the ASCII name of the attribute with the
<tt>Method_</tt>
or
<tt>Device_</tt>
characters.
The
<tt>cfgmgr</tt>
framework reserves certain names that begin with the
<tt>Method_</tt>
and
<tt>Device_</tt>
characters.
</p><p>
The
<tt>type</tt>
member specifies
the data type associated with the
<tt>name</tt>
attribute.
You must set the
<tt>type</tt>
member to one of the following constants:
<table border="4" cellpadding="4">
<tbody><tr>
<td align="left" valign="top">
<strong>
Value
</strong>
</td>
<td align="left" valign="top">
<strong>
Meaning
</strong>
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>CFG_ATTR_STRTYPE</tt>
</td>
<td align="left" valign="top">
Data type is a null-terminated array of characters.
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>CFG_ATTR_INTTYPE</tt>
</td>
<td align="left" valign="top">
Data type is a 32-bit signed integer.
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>CFG_ATTR_UINTTYPE</tt>
</td>
<td align="left" valign="top">
Data type is a 32-bit unsigned integer.
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>CFG_ATTR_LONGTYPE</tt>
</td>
<td align="left" valign="top">
Data type is a 64-bit signed integer.
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>CFG_ATTR_ULONGTYPE</tt>
</td>
<td align="left" valign="top">
Data type is a 64-bit unsigned integer.
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>CFG_ATTR_BINTYPE</tt>
</td>
<td align="left" valign="top">
Data type is an array of bytes.
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>CFG_ATTR_UCHARTYPE</tt>
</td>
<td align="left" valign="top">
Data type is an 8-bit unsigned character.
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>CFG_ATTR_USHORTTYPE</tt>
</td>
<td align="left" valign="top">
Data type is a 16-bit unsigned short integer.
</td>
</tr>
</tbody></table></p><p>
</p><p>
The
<tt>operation</tt>
member specifies
the operations that the
<tt>cfgmgr</tt>
framework can perform on the attribute.
</p><p>
You can set this member to one of the following constants:
<tt>CFG_OP_CONFIGURE</tt>,
<tt>CFG_OP_QUERY</tt>,
and
<tt>CFG_OP_RECONFIGURE</tt>.
</p><p>
The following table describes the meaning of these constants.
<br>
<table border="4" cellpadding="4">
<tbody><tr>
<td align="left" valign="top">
<strong>
Value
</strong>
</td>
<td align="left" valign="top">
<strong>
Meaning
</strong>
</td>
</tr>
<tr>
<td align="left" valign="top">
<tt>CFG_OP_CONFIGURE</tt>
</td>
<td align="left" valign="top">
The
<tt>cfgmgr</tt>
framework configures the attribute.
This means the
<tt>cfgmgr</tt>
framework obtains a data value for the attribute from the
<tt>/etc/sysconfigtab</tt>
database.
<p>
The configure operation occurs when the
<tt>cfgmgr</tt>
framework calls the driver's
<tt>configure</tt>
interface at its
<tt>CFG_OP_CONFIGURE</tt>
entry point.
(That is, the
<tt><var>optype</var></tt>
argument of the driver's
<tt>configure</tt>
interface evaluates to the
<tt>CFG_OP_CONFIGURE</tt>
constant.)
</p></td>
</tr>
<tr>
<td align="left" valign="top">
<tt>CFG_OP_QUERY</tt>
</td>
<td align="left" valign="top">
The
<tt>cfgmgr</tt>
framework queries (reads) the attribute.
This means the driver cooperates with the
<tt>cfgmgr</tt>
framework to provide the value associated with the attribute as a result
of user-initiated query requests.
These requests are typically the result of the
<tt>sysconfig -q</tt>
command.
<p>
The query operation occurs when the
<tt>cfgmgr</tt>
framework calls the driver's
<tt>configure</tt>
interface at its
<tt>CFG_OP_QUERY</tt>
entry point.
(That is, the
<tt><var>optype</var></tt>
argument of the driver's
<tt>configure</tt>
interface evaluates to the
<tt>CFG_OP_QUERY</tt>
constant.)
</p></td>
</tr>
<tr>
<td align="left" valign="top">
<tt>CFG_OP_RECONFIGURE</tt>
</td>
<td align="left" valign="top">
The
<tt>cfgmgr</tt>
framework reconfigures the attribute.
This means the
<tt>cfgmgr</tt>
framework reconfigures the data value for the attribute.
This functionality allows a user to modify the attribute.
A reconfigure request is typically the result of the
<tt>sysconfig -r</tt>
command.
<br>
<p>
The reconfigure operation occurs when the
<tt>cfgmgr</tt>
framework calls the driver's
<tt>configure</tt>
interface at its
<tt>CFG_OP_RECONFIGURE</tt>
entry point.
(That is, the
<tt><var>optype</var></tt>
argument of the driver's
<tt>configure</tt>
interface evaluates to the
<tt>CFG_OP_RECONFIGURE</tt>
constant.)
</p></td>
</tr>
</tbody></table></p><p>
</p><p>
The
<tt>addr</tt>
member specifies
the address of the data value associated with the attribute.
The
<tt>cfgmgr</tt>
framework obtains the data value for this attribute from the
<tt>/etc/sysconfigtab</tt>
database and stores it at this address.
The
<tt>cfgmgr</tt>
framework performs this storage operation if the following occurs:
</p><ul>
<p></p><li>
The attribute appears in the
<tt>cfg_subsys_attr_t</tt>
table (declared and initialized in the driver)
with an operation code of
<tt>CFG_OP_CONFIGURE</tt>.
<p></p></li><li>
The driver writer passes the
<tt>CFG_OP_CONFIGURE</tt>
constant to the
<tt><var>optype</var></tt>
argument of the driver's
<tt>configure</tt>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -