Managing and Developing Dynamically Loadable Kernel Modules

Managing and Developing Dynamically Loadable Kernel Modules
Developing Dynamically Loadable Kernel Modules
Chapter 12534
The _unload() function must clean up any resources that were
allocated to the module, and it must remove all references to the module.
Typical cleanup tasks include releasing private memory acquired by the
module, removing device interrupts, disabling interrupts from the
device, and canceling any outstanding timeout requests made by the
module.
The module’s _unload() function should return 0 on success and an
errno value on failure. In the event of failure, the function must leave
the module in a sane state, since the module will remain loaded after the
return.
The system will never attempt to unload a module that it thinks is busy.
However, the system cannot determine under all cases when the module
is in use. Currently, a module is considered to be busy when another
module that depends on it is also loaded. In addition, WSIO class drivers
and STREAMS drivers track the open() and close() calls; these
types of modules are busy whenever there is at least one open on the
device using the driver. Under most other circumstances, the module
must determine for itself whether it is appropriate for it to be unloaded.
When a module is still in use, its _unload() function can return a
nonzero value to cancel the unload.
The argument passed to the _unload() function by the DLKM
infrastructure is the same type-specific value that was passed to the
module’s _load() function. The use of this argument is described in
“Initializing and Terminating DLKM Modules” on page 538.
master File Definition
Each DLKM module has its own master file. The format of the master
file includes the following section keywords:
$VERSION – indicates the version number for the file format. Version
is defined as an integer. A single line containing the version is
entered. For PA systems, the only supported version is 1.
For Itanium-based systems, version 2 is a supported file format for
Boot Time Loaded modules. If $VERSION is 2 in the master and
system files the phases keyword in the master file and the
$LOADPHASE keyword in the system file would need to be specified.
$LOADABLE – indicates that the module is dynamically loadable. If
this section keyword does not exist, the module can only be statically
configured into the kernel. Optionally, this section may contain either