1_fini(9E)                     Driver Entry Points                    _fini(9E)
2
3
4

NAME

6       _fini, _info, _init - loadable module configuration entry points
7

SYNOPSIS

9       #include <sys/modctl.h>
10
11
12
13       int _fini(void)
14
15
16       int _info(struct modinfo *modinfop);
17
18
19       int _init(void)
20
21

INTERFACE LEVEL

23       Solaris  DDI  specific  (Solaris DDI). These entry points are required.
24       You must write them.
25

PARAMETERS

27   _info()
28       modinfop     A pointer to an opaque modinfo structure.
29
30

DESCRIPTION

32       _init() initializes a loadable module. It is called  before  any  other
33       routine  in  a  loadable  module. _init() returns the value returned by
34       mod_install(9F). The module may  optionally  perform  some  other  work
35       before  the  mod_install(9F)  call is performed. If the module has done
36       some setup before the  mod_install(9F)  function  is  called,  then  it
37       should  be  prepared  to  undo that setup if mod_install(9F) returns an
38       error.
39
40
41       _info() returns information about a loadable  module.  _info()  returns
42       the value returned by mod_info(9F).
43
44
45       _fini() prepares a loadable module for unloading. It is called when the
46       system wants to unload a module. If the module determines that  it  can
47       be unloaded, then _fini() returns the value returned by mod_remove(9F).
48       Upon successful return from _fini() no other routine in the module will
49       be called before _init() is called.
50

RETURN VALUES

52       _init()  should  return  the  appropriate  error  number if there is an
53       error,   otherwise   it   should   return   the   return   value   from
54       mod_install(9F).
55
56
57       _info() should return the return value from mod_info(9F)
58
59
60       _fini()  should return the return value from mod_remove(9F). _fini() is
61       permitted to return EBUSY prior to calling mod_remove(9F) if the driver
62       should  not  be  unloaded. Driver global resources, such as mutexes and
63       calls to ddi_soft_state_fini(9F), should only be destroyed  in  _fini()
64       after mod_remove() returns successfully.
65

EXAMPLES

67       Example 1 Initializing and Freeing a Mutex
68
69
70       The  following  example  demonstrates  how  to  initialize  and  free a
71       mutex(9F).
72
73
74         #include <sys/modctl.h>
75         #include <sys/ddi.h>
76         #include <sys/sunddi.h>
77         static struct dev_ops  drv_ops;
78         /*
79          * Module linkage information for the kernel.
80          */
81         static struct modldrv modldrv = {
82              &mod_driverops,     /* Type of module.  This one is a driver */
83             "Sample Driver",
84             &drv_ops       /* driver ops */
85         };
86
87         static struct modlinkage modlinkage = {
88                 MODREV_1,
89                 &modldrv,
90                 NULL
91         };
92
93
94         /*
95          * Global driver mutex
96          */
97         static kmutex_t   xx_global_mutex;
98
99
100         int
101         _init(void)
102         {
103                 int     i;
104
105                 /*
106                   * Initialize global mutex before mod_install'ing driver.
107                   * If mod_install() fails, must clean up mutex initialization
108                   */
109                 mutex_init(&xx_global_mutex, NULL,
110                         MUTEX_DRIVER, (void *)NULL);
111
112                 if ((i = mod_install(&modlinkage)) != 0) {
113                         mutex_destroy(&xx_global_mutex);
114                 }
115
116                 return (i);
117         }
118
119         int
120         _info(struct modinfo *modinfop)
121         {
122                 return (mod_info(&modlinkage, modinfop));
123         }
124
125
126         int
127         _fini(void)
128         {
129                 int       i;
130
131                 /*
132                   * If mod_remove() is successful, we destroy our global mutex
133                   */
134                 if ((i = mod_remove(&modlinkage)) == 0) {
135                          mutex_destroy(&xx_global_mutex);
136                 }
137                 return (i);
138         }
139
140

SEE ALSO

142       add_drv(1M), mod_info(9F), mod_install(9F), mod_remove(9F),  mutex(9F),
143       modldrv(9S), modlinkage(9S), modlstrmod(9S)
144
145
146       Writing Device Drivers
147

WARNINGS

149       Do  not  change  the structures referred to by the modlinkage structure
150       after the call to mod_install(), as the system may copy or change them.
151

NOTES

153       Even though the identifiers _fini(), _info(), and _init() appear to  be
154       declared  as  globals,  their  scope is restricted by the kernel to the
155       module that they are defined in.
156

BUGS

158       On some implementations _info() may be called before _init().
159
160
161
162SunOS 5.11                        22 Jan 2002                        _fini(9E)
Impressum