2 .\" Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH _FINI 9E "Jan 22, 2002"
8 _fini, _info, _init \- loadable module configuration entry points
12 #include <sys/modctl.h>
16 \fBint\fR \fB_fini\fR(void)
21 \fBint\fR \fB_info\fR(\fBstruct modinfo *\fR\fImodinfop\fR);
26 \fBint\fR \fB_init\fR(void)
32 Solaris DDI specific (Solaris DDI). These entry points are required. You must
42 A pointer to an opaque \fBmodinfo\fR structure.
48 \fB_init()\fR initializes a loadable module. It is called before any other
49 routine in a loadable module. \fB_init()\fR returns the value returned by
50 \fBmod_install\fR(9F). The module may optionally perform some other work before
51 the \fBmod_install\fR(9F) call is performed. If the module has done some setup
52 before the \fBmod_install\fR(9F) function is called, then it should be prepared
53 to undo that setup if \fBmod_install\fR(9F) returns an error.
56 \fB_info()\fR returns information about a loadable module. \fB_info()\fR
57 returns the value returned by \fBmod_info\fR(9F).
60 \fB_fini()\fR prepares a loadable module for unloading. It is called when the
61 system wants to unload a module. If the module determines that it can be
62 unloaded, then \fB_fini()\fR returns the value returned by
63 \fBmod_remove\fR(9F). Upon successful return from \fB_fini()\fR no other
64 routine in the module will be called before \fB_init()\fR is called.
68 \fB_init()\fR should return the appropriate error number if there is an error,
69 otherwise it should return the return value from \fBmod_install\fR(9F).
72 \fB_info()\fR should return the return value from \fBmod_info\fR(9F)
75 \fB_fini()\fR should return the return value from \fBmod_remove\fR(9F).
76 \fB_fini()\fR is permitted to return \fBEBUSY\fR prior to calling
77 \fBmod_remove\fR(9F) if the driver should not be unloaded. Driver global
78 resources, such as mutexes and calls to \fBddi_soft_state_fini\fR(9F), should
79 only be destroyed in \fB_fini()\fR after \fBmod_remove()\fR returns
83 \fBExample 1 \fRInitializing and Freeing a Mutex
86 The following example demonstrates how to initialize and free a
92 #include <sys/modctl.h>
94 #include <sys/sunddi.h>
95 static struct dev_ops drv_ops;
97 * Module linkage information for the kernel.
99 static struct modldrv modldrv = {
100 &mod_driverops, /* Type of module. This one is a driver */
102 &drv_ops /* driver ops */
105 static struct modlinkage modlinkage = {
113 * Global driver mutex
115 static kmutex_t xx_global_mutex;
124 * Initialize global mutex before mod_install'ing driver.
125 * If mod_install() fails, must clean up mutex initialization
127 mutex_init(&xx_global_mutex, NULL,
128 MUTEX_DRIVER, (void *)NULL);
130 if ((i = mod_install(&modlinkage)) != 0) {
131 mutex_destroy(&xx_global_mutex);
138 _info(struct modinfo *modinfop)
140 return (mod_info(&modlinkage, modinfop));
150 * If mod_remove() is successful, we destroy our global mutex
152 if ((i = mod_remove(&modlinkage)) == 0) {
153 mutex_destroy(&xx_global_mutex);
163 \fBadd_drv\fR(1M), \fBmod_info\fR(9F), \fBmod_install\fR(9F),
164 \fBmod_remove\fR(9F), \fBmutex\fR(9F), \fBmodldrv\fR(9S), \fBmodlinkage\fR(9S),
168 \fIWriting Device Drivers\fR
172 Do not change the structures referred to by the \fBmodlinkage\fR structure
173 after the call to \fBmod_install()\fR, as the system may copy or change them.
177 Even though the identifiers \fB_fini()\fR, \fB_info()\fR, and \fB_init()\fR
178 appear to be declared as globals, their scope is restricted by the kernel to
179 the module that they are defined in.
183 On some implementations \fB_info()\fR may be called before \fB_init()\fR.