4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
30 * loadable module support.
33 #include <sys/zfs_context.h>
43 * The following structure defines the operations used by modctl
44 * to load and unload modules. Each supported loadable module type
45 * requires a set of mod_ops.
48 int (*modm_install)(struct modlmisc *, struct modlinkage *);
49 int (*modm_remove)(struct modlmisc *, struct modlinkage *);
50 int (*modm_info)(void *, struct modlinkage *, int *);
54 * The defined set of mod_ops structures for each loadable module type
57 extern struct mod_ops mod_brandops;
58 #if defined(__i386) || defined(__amd64)
59 extern struct mod_ops mod_cpuops;
61 extern struct mod_ops mod_cryptoops;
62 extern struct mod_ops mod_driverops;
63 extern struct mod_ops mod_execops;
64 extern struct mod_ops mod_fsops;
65 extern struct mod_ops mod_miscops;
66 extern struct mod_ops mod_schedops;
67 extern struct mod_ops mod_strmodops;
68 extern struct mod_ops mod_syscallops;
69 extern struct mod_ops mod_sockmodops;
70 #ifdef _SYSCALL32_IMPL
71 extern struct mod_ops mod_syscallops32;
73 extern struct mod_ops mod_dacfops;
74 extern struct mod_ops mod_ippops;
75 extern struct mod_ops mod_pcbeops;
76 extern struct mod_ops mod_devfsops;
77 extern struct mod_ops mod_kiconvops;
80 * Definitions for the module specific linkage structures.
81 * The first two fields are the same in all of the structures.
82 * The linkinfo is for informational purposes only and is returned by
83 * modctl with the MODINFO cmd.
86 /* For cryptographic providers */
88 struct mod_ops *crypto_modops;
89 char *crypto_linkinfo;
94 struct mod_ops *misc_modops;
99 * Revision number of loadable modules support. This is the value
100 * that must be used in the modlinkage structure.
105 * The modlinkage structure is the structure that the module writer
106 * provides to the routines to install, remove, and stat a module.
107 * The ml_linkage element is an array of pointers to linkage structures.
108 * For most modules there is only one linkage structure. We allocate
109 * enough space for 3 linkage structures which happens to be the most
110 * we have in any sun supplied module. For those modules with more
111 * than 3 linkage structures (which is very unlikely), a modlinkage
112 * structure must be kmem_alloc'd in the module wrapper to be big enough
113 * for all of the linkage structures.
116 int ml_rev; /* rev of loadable modules system */
118 void *ml_linkage[7]; /* more space in 64-bit OS */
120 void *ml_linkage[4]; /* NULL terminated list of */
121 /* linkage structures */
126 * commands. These are the commands supported by the modctl system call.
131 #define MODRESERVED 3
132 #define MODSETMINIROOT 4
133 #define MODADDMAJBIND 5
135 #define MODREADSYSBIND 7
136 #define MODGETMAJBIND 8
138 #define MODSIZEOF_DEVID 10
139 #define MODGETDEVID 11
140 #define MODSIZEOF_MINORNAME 12
141 #define MODGETMINORNAME 13
142 #define MODGETPATHLEN 14
144 #define MODGETFBNAME 16
145 #define MODREREADDACF 17
146 #define MODLOADDRVCONF 18
147 #define MODUNLOADDRVCONF 19
148 #define MODREMMAJBIND 20
149 #define MODDEVT2INSTANCE 21
150 #define MODGETDEVFSPATH_LEN 22
151 #define MODGETDEVFSPATH 23
152 #define MODDEVID2PATHS 24
153 #define MODSETDEVPOLICY 26
154 #define MODGETDEVPOLICY 27
155 #define MODALLOCPRIV 28
156 #define MODGETDEVPOLICYBYNAME 29
157 #define MODLOADMINORPERM 31
158 #define MODADDMINORPERM 32
159 #define MODREMMINORPERM 33
160 #define MODREMDRVCLEANUP 34
161 #define MODDEVEXISTS 35
162 #define MODDEVREADDIR 36
163 #define MODDEVNAME 37
164 #define MODGETDEVFSPATH_MI_LEN 38
165 #define MODGETDEVFSPATH_MI 39
167 #define MODUNRETIRE 41
168 #define MODISRETIRED 42
169 #define MODDEVEMPTYDIR 43
170 #define MODREMDRVALIAS 44
173 * sub cmds for MODEVENTS
175 #define MODEVENTS_FLUSH 0
176 #define MODEVENTS_FLUSH_DUMP 1
177 #define MODEVENTS_SET_DOOR_UPCALL_FILENAME 2
178 #define MODEVENTS_GETDATA 3
179 #define MODEVENTS_FREEDATA 4
180 #define MODEVENTS_POST_EVENT 5
181 #define MODEVENTS_REGISTER_EVENT 6
184 * devname subcmds for MODDEVNAME
186 #define MODDEVNAME_LOOKUPDOOR 0
187 #define MODDEVNAME_DEVFSADMNODE 1
188 #define MODDEVNAME_NSMAPS 2
189 #define MODDEVNAME_PROFILE 3
190 #define MODDEVNAME_RECONFIG 4
191 #define MODDEVNAME_SYSAVAIL 5
195 * Data structure passed to modconfig command in kernel to build devfs tree
199 struct aliases *a_next;
204 #define MAXMODCONFNAME 256
207 char drvname[MAXMODCONFNAME];
208 char drvclass[MAXMODCONFNAME];
215 #if defined(_SYSCALL32)
224 char drvname[MAXMODCONFNAME];
225 char drvclass[MAXMODCONFNAME];
232 #endif /* _SYSCALL32 */
234 /* flags for modconfig */
235 #define MOD_UNBIND_OVERRIDE 0x01 /* fail unbind if in use */
238 * Max module path length
240 #define MOD_MAXPATH 256
243 * Default search path for modules ADDITIONAL to the directory
244 * where the kernel components we booted from are.
246 * Most often, this will be "/platform/{platform}/kernel /kernel /usr/kernel",
247 * but we don't wire it down here.
249 #define MOD_DEFPATH "/kernel /usr/kernel"
252 * Default file name extension for autoloading modules.
254 #define MOD_DEFEXT ""
257 * Parameters for modinfo
259 #define MODMAXNAMELEN 32 /* max module name length */
260 #define MODMAXLINKINFOLEN 32 /* max link info length */
263 * Module specific information.
265 struct modspecific_info {
266 char msi_linkinfo[MODMAXLINKINFOLEN]; /* name in linkage struct */
267 int msi_p0; /* module specific information */
271 * Structure returned by modctl with MODINFO command.
273 #define MODMAXLINK 10 /* max linkages modinfo can handle */
276 int mi_info; /* Flags for info wanted */
277 int mi_state; /* Flags for module state */
278 int mi_id; /* id of this loaded module */
279 int mi_nextid; /* id of next module or -1 */
280 caddr_t mi_base; /* virtual addr of text */
281 size_t mi_size; /* size of module in bytes */
282 int mi_rev; /* loadable modules rev */
283 int mi_loadcnt; /* # of times loaded */
284 char mi_name[MODMAXNAMELEN]; /* name of module */
285 struct modspecific_info mi_msinfo[MODMAXLINK];
286 /* mod specific info */
290 #if defined(_SYSCALL32)
292 #define MODMAXNAMELEN32 32 /* max module name length */
293 #define MODMAXLINKINFOLEN32 32 /* max link info length */
294 #define MODMAXLINK32 10 /* max linkages modinfo can handle */
296 struct modspecific_info32 {
297 char msi_linkinfo[MODMAXLINKINFOLEN32]; /* name in linkage struct */
298 int32_t msi_p0; /* module specific information */
302 int32_t mi_info; /* Flags for info wanted */
303 int32_t mi_state; /* Flags for module state */
304 int32_t mi_id; /* id of this loaded module */
305 int32_t mi_nextid; /* id of next module or -1 */
306 caddr32_t mi_base; /* virtual addr of text */
307 uint32_t mi_size; /* size of module in bytes */
308 int32_t mi_rev; /* loadable modules rev */
309 int32_t mi_loadcnt; /* # of times loaded */
310 char mi_name[MODMAXNAMELEN32]; /* name of module */
311 struct modspecific_info32 mi_msinfo[MODMAXLINK32];
312 /* mod specific info */
315 #endif /* _SYSCALL32 */
317 /* Values for mi_info flags */
318 #define MI_INFO_ONE 1
319 #define MI_INFO_ALL 2
320 #define MI_INFO_CNT 4
321 #define MI_INFO_LINKAGE 8 /* used internally to extract modlinkage */
323 * MI_INFO_NOBASE indicates caller does not need mi_base. Failure to use this
324 * flag may lead 32-bit apps to receive an EOVERFLOW error from modctl(MODINFO)
325 * when used with a 64-bit kernel.
327 #define MI_INFO_NOBASE 16
329 /* Values for mi_state */
331 #define MI_INSTALLED 2
334 * Macros to vector to the appropriate module specific routine.
336 #define MODL_INSTALL(MODL, MODLP) \
337 (*(MODL)->misc_modops->modm_install)(MODL, MODLP)
338 #define MODL_REMOVE(MODL, MODLP) \
339 (*(MODL)->misc_modops->modm_remove)(MODL, MODLP)
340 #define MODL_INFO(MODL, MODLP, P0) \
341 (*(MODL)->misc_modops->modm_info)(MODL, MODLP, P0)
344 * Definitions for stubs
346 struct mod_stub_info {
347 uintptr_t mods_func_adr;
348 struct mod_modinfo *mods_modinfo;
349 uintptr_t mods_stub_adr;
350 int (*mods_errfcn)(void);
351 int mods_flag; /* flags defined below */
355 * Definitions for mods_flag.
357 #define MODS_WEAK 0x01 /* weak stub (not loaded if called) */
358 #define MODS_NOUNLOAD 0x02 /* module not unloadable (no _fini()) */
359 #define MODS_INSTALLED 0x10 /* module installed */
362 char *modm_module_name;
364 struct mod_stub_info modm_stubs[1];
368 struct modctl_list *modl_next;
369 struct modctl *modl_modp;
373 * Structure to manage a loadable module.
374 * Note: the module (mod_mp) structure's "text" and "text_size" information
375 * are replicated in the modctl structure so that mod_containing_pc()
376 * doesn't have to grab any locks (modctls are persistent; modules are not.)
378 typedef struct modctl {
379 struct modctl *mod_next; /* &modules based list */
380 struct modctl *mod_prev;
383 kthread_t *mod_inprogress_thread;
384 struct mod_modinfo *mod_modinfo;
385 struct modlinkage *mod_linkage;
389 char mod_busy; /* inprogress_thread has locked */
390 char mod_want; /* someone waiting for unlock */
391 char mod_prim; /* primary module */
393 int mod_ref; /* ref count - from dependent or stub */
395 char mod_loaded; /* module in memory */
396 char mod_installed; /* post _init pre _fini */
398 char mod_delay_unload; /* deferred unload */
400 struct modctl_list *mod_requisites; /* mods this one depends on. */
401 void *____unused; /* NOTE: reuse (same size) is OK, */
402 /* deletion causes mdb.vs.core issues */
403 int mod_loadcnt; /* number of times mod was loaded */
404 int mod_nenabled; /* # of enabled DTrace probes in mod */
406 size_t mod_text_size;
408 int mod_gencount; /* # times loaded/unloaded */
409 struct modctl *mod_requisite_loading; /* mod circular dependency */
416 #define MOD_NOAUTOUNLOAD 0x1 /* Auto mod-unloader skips this mod */
417 #define MOD_NONOTIFY 0x2 /* No krtld notifications on (un)load */
418 #define MOD_NOUNLOAD 0x4 /* Assume EBUSY for all _fini's */
420 #define MOD_BIND_HASHSIZE 64
421 #define MOD_BIND_HASHMASK (MOD_BIND_HASHSIZE-1)
426 * global function and data declarations
428 extern kmutex_t mod_lock;
430 extern char *systemfile;
431 extern char **syscallnames;
435 * this is the head of a doubly linked list. Only the next and prev
438 extern modctl_t modules;
441 * Only the following are part of the DDI/DKI
443 extern int mod_install(struct modlinkage *);
444 extern int mod_remove(struct modlinkage *);
445 extern int mod_info(struct modlinkage *, struct modinfo *);
448 * bit definitions for moddebug.
450 #define MODDEBUG_LOADMSG 0x80000000 /* print "[un]loading..." msg */
451 #define MODDEBUG_ERRMSG 0x40000000 /* print detailed error msgs */
452 #define MODDEBUG_LOADMSG2 0x20000000 /* print 2nd level msgs */
453 #define MODDEBUG_RETIRE 0x10000000 /* print retire msgs */
454 #define MODDEBUG_BINDING 0x00040000 /* driver/alias binding */
455 #define MODDEBUG_FINI_EBUSY 0x00020000 /* pretend fini returns EBUSY */
456 #define MODDEBUG_NOAUL_IPP 0x00010000 /* no Autounloading ipp mods */
457 #define MODDEBUG_NOAUL_DACF 0x00008000 /* no Autounloading dacf mods */
458 #define MODDEBUG_KEEPTEXT 0x00004000 /* keep text after unloading */
459 #define MODDEBUG_NOAUL_DRV 0x00001000 /* no Autounloading Drivers */
460 #define MODDEBUG_NOAUL_EXEC 0x00000800 /* no Autounloading Execs */
461 #define MODDEBUG_NOAUL_FS 0x00000400 /* no Autounloading File sys */
462 #define MODDEBUG_NOAUL_MISC 0x00000200 /* no Autounloading misc */
463 #define MODDEBUG_NOAUL_SCHED 0x00000100 /* no Autounloading scheds */
464 #define MODDEBUG_NOAUL_STR 0x00000080 /* no Autounloading streams */
465 #define MODDEBUG_NOAUL_SYS 0x00000040 /* no Autounloading syscalls */
466 #define MODDEBUG_NOCTF 0x00000020 /* do not load CTF debug data */
467 #define MODDEBUG_NOAUTOUNLOAD 0x00000010 /* no autounloading at all */
468 #define MODDEBUG_DDI_MOD 0x00000008 /* ddi_mod{open,sym,close} */
469 #define MODDEBUG_MP_MATCH 0x00000004 /* dev_minorperm */
470 #define MODDEBUG_MINORPERM 0x00000002 /* minor perm modctls */
471 #define MODDEBUG_USERDEBUG 0x00000001 /* bpt after init_module() */
477 #endif /* _SYS_MODCTL_H */