_load(D2) _load(D2)
NAME
_load - initialize a loadable kernel module
SYNOPSIS
#include <sys/moddefs.h>
#include <sys/ddi.h>
int prefix_load(void);
DESCRIPTION
The module _load routine performs any module-specific setup
and initialization needed to dynamically load a kernel module
into a running system.
Return Values
The _load routine should return 0 for success, or the
appropriate error number.
USAGE
This entry point is optional.
Types of modules that can be dynamically loaded include:
device drivers (block, character, STREAMS and pseudo)
Host Bus Adapter drivers
Direct Coupled Device controller drivers
STREAMS modules
file systems
miscellaneous modules, such as modules containing code
for support routines shared among multiple loadable
modules which are not needed in the statically
configured kernel
A loadable module's _load routine is defined in module-
specific initialization code called wrapper code. The _load
routine can perform activities such as:
allocate memory for private data
initialize driver data structures
Copyright 1994 Novell, Inc. Page 1
_load(D2) _load(D2)
install and enable device interrupts by calling the
mod_drvattach(D3) routine
initialize devices
sys/moddefs.h provides a set a macros that can be used to
generate wrappers for loadable modules. The macros are of the
form:
type(prefix, load, unload, halt, desc);
where
type is the type of wrapper macro. Valid types are:
MOD_DRV_WRAPPER Generates wrappers for device
drivers.
MOD_HDRV_WRAPPER Generates wrappers for Host Bus
Adapter drivers.
MOD_STR_WRAPPER Generates wrappers for STREAMS
modules.
MOD_FS_WRAPPER Generates wrappers for file
systems.
MOD_MISC_WRAPPER Generates wrappers for
miscellaneous modules.
prefix Specifies the module's prefix [see prefix(D1)].
load Specifies the name of the module's _load routine.
unload Specifies the name of the module's _unload routine
[see _unload(D2)].
halt This optional keyword specifies the name of the
module's halt routine, if any [see halt(D2)].
desc Supplies a character string that identifies the
module.
Synchronization Constraints
The _load routine can sleep.
Copyright 1994 Novell, Inc. Page 2
_load(D2) _load(D2)
Warnings
Loadable file system modules should not attempt to manipulate
entries in the vfssw[] table with their _load routines. The
vfssw[] table is updated automatically at the time the file
system is loaded into the system.
Examples
The example shows sample wrapper code for the m320 mouse
driver.
#include <sys/moddefs.h>
#include <sys/ddi.h>
static int mse3_load(), mse3_unload();
void mse3start();
MOD_DRV_WRAPPER(mse3, mse3_load, mse3_unload, "320 Mouse Driver");
static int mse3_load(void)
{
mod_drvattach(&mse3_attach_info);
mse3start();
return(0);
}
static int mse3_unload(void)
{
mod_drvdetach(&mse3_attach_info);
return(0);
}
REFERENCES
halt(D2), init(D2), start(D2), _unload(D2), mod_drvattach(D3)
NOTICES
Portability
All processors
Applicability
ddi: 4, 5, 5mp, 6, 6mp, 7, 7mp
Copyright 1994 Novell, Inc. Page 3