Managing Systems and Workgroups: A Guide for HP-UX System Administrators

Configuring a System
Reconfiguring the Kernel (Prior to HP-UX 11i Version 2)
Chapter 3 295
A module may be unloaded only by a user level request specifying the
module to be unloaded. The unload is accomplished through the
kmadmin command. This request may fail for a number of reasons,
the most common being that the module is busy at the time. An
example of this would be attempting to unload a device while there
are outstanding opens on the device.
A loadable module’s _unload() function is called by the DLKM
mechanism whenever the module is about to be removed from active
memory. The function may be given any name (typically
module_name
_unload); a pointer to the _unload() function is obtained
from the module's wrapper.
The module’s _unload() function cleans 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 returns 0 on success and an errno
value on failure. In the event of failure, the function leaves 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 determines for itself whether it is
appropriate for it to be unloaded. When a module is still in use, its
_unload() function returns a non-zero value to cancel the unload.
The argument passed to the _unload() function is the same
type-specific value that was passed to the module’s _load() function.
The use of this argument is described in “STREAMS Drivers” on
page 298.
DLKM Driver Configuration Concepts Since kernel modules
written in the DLKM format can be configured as either dynamically
loadable or statically configured, DLKM-compatible device drivers must
accommodate either configuration.