xref: /titanic_52/usr/src/uts/common/os/modconf.c (revision 7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fe)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*7aec1d6eScindi  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/systm.h>
317c478bd9Sstevel@tonic-gate #include <sys/param.h>
327c478bd9Sstevel@tonic-gate #include <sys/user.h>
337c478bd9Sstevel@tonic-gate #include <sys/vm.h>
347c478bd9Sstevel@tonic-gate #include <sys/conf.h>
357c478bd9Sstevel@tonic-gate #include <sys/class.h>
367c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
377c478bd9Sstevel@tonic-gate #include <sys/mount.h>
387c478bd9Sstevel@tonic-gate #include <sys/systm.h>
397c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
407c478bd9Sstevel@tonic-gate #include <sys/exec.h>
417c478bd9Sstevel@tonic-gate #include <sys/exechdr.h>
427c478bd9Sstevel@tonic-gate #include <sys/devops.h>
437c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
447c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
457c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
467c478bd9Sstevel@tonic-gate #include <sys/hwconf.h>
477c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
487c478bd9Sstevel@tonic-gate #include <sys/autoconf.h>
497c478bd9Sstevel@tonic-gate #include <sys/disp.h>
507c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
517c478bd9Sstevel@tonic-gate #include <sys/instance.h>
527c478bd9Sstevel@tonic-gate #include <sys/modhash.h>
537c478bd9Sstevel@tonic-gate #include <sys/dacf.h>
547c478bd9Sstevel@tonic-gate #include <sys/debug.h>
557c478bd9Sstevel@tonic-gate #include <ipp/ipp.h>
567c478bd9Sstevel@tonic-gate #include <sys/strsubr.h>
577c478bd9Sstevel@tonic-gate #include <sys/kcpc.h>
587c478bd9Sstevel@tonic-gate #include <sys/cpc_pcbe.h>
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate extern int moddebug;
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate extern struct cb_ops no_cb_ops;
637c478bd9Sstevel@tonic-gate extern struct dev_ops nodev_ops;
647c478bd9Sstevel@tonic-gate extern struct dev_ops mod_nodev_ops;
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate extern struct modctl *mod_getctl(struct modlinkage *);
677c478bd9Sstevel@tonic-gate extern int errsys(), nodev(), nulldev();
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate extern int findmodbyname(char *);
707c478bd9Sstevel@tonic-gate extern int mod_getsysnum(char *);
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate extern struct execsw execsw[];
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate  * Define dev_ops for unused devopsp entry.
767c478bd9Sstevel@tonic-gate  */
777c478bd9Sstevel@tonic-gate struct dev_ops mod_nodev_ops = {
787c478bd9Sstevel@tonic-gate 	DEVO_REV,		/* devo_rev	*/
797c478bd9Sstevel@tonic-gate 	0,			/* refcnt	*/
807c478bd9Sstevel@tonic-gate 	ddi_no_info,		/* info */
817c478bd9Sstevel@tonic-gate 	nulldev,		/* identify	*/
827c478bd9Sstevel@tonic-gate 	nulldev,		/* probe	*/
837c478bd9Sstevel@tonic-gate 	ddifail,		/* attach	*/
847c478bd9Sstevel@tonic-gate 	nodev,			/* detach	*/
857c478bd9Sstevel@tonic-gate 	nulldev,		/* reset	*/
867c478bd9Sstevel@tonic-gate 	&no_cb_ops,		/* character/block driver operations */
877c478bd9Sstevel@tonic-gate 	(struct bus_ops *)0	/* bus operations for nexus drivers */
887c478bd9Sstevel@tonic-gate };
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate /*
917c478bd9Sstevel@tonic-gate  * Define mod_ops for each supported module type
927c478bd9Sstevel@tonic-gate  */
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /*
957c478bd9Sstevel@tonic-gate  * Null operations; used for uninitialized and "misc" modules.
967c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate static int mod_null(struct modldrv *, struct modlinkage *);
987c478bd9Sstevel@tonic-gate static int mod_infonull(void *, struct modlinkage *, int *);
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate struct mod_ops mod_miscops = {
1017c478bd9Sstevel@tonic-gate 	mod_null, mod_null, mod_infonull
1027c478bd9Sstevel@tonic-gate };
1037c478bd9Sstevel@tonic-gate 
104*7aec1d6eScindi /* CPU Modules */
105*7aec1d6eScindi struct mod_ops mod_cpuops = {
106*7aec1d6eScindi 	mod_null, mod_null, mod_infonull
107*7aec1d6eScindi };
108*7aec1d6eScindi 
1097c478bd9Sstevel@tonic-gate /*
1107c478bd9Sstevel@tonic-gate  * Cryptographic Modules
1117c478bd9Sstevel@tonic-gate  */
1127c478bd9Sstevel@tonic-gate struct mod_ops mod_cryptoops = {
1137c478bd9Sstevel@tonic-gate 	mod_null, mod_null, mod_infonull
1147c478bd9Sstevel@tonic-gate };
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /*
1177c478bd9Sstevel@tonic-gate  * IP Policy Modules
1187c478bd9Sstevel@tonic-gate  */
1197c478bd9Sstevel@tonic-gate static int mod_installipp(struct modlipp *, struct modlinkage *);
1207c478bd9Sstevel@tonic-gate static int mod_removeipp(struct modlipp *, struct modlinkage *);
1217c478bd9Sstevel@tonic-gate static int mod_infoipp(struct modlipp *, struct modlinkage *, int *);
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate struct mod_ops mod_ippops = {
1247c478bd9Sstevel@tonic-gate 	mod_installipp, mod_removeipp, mod_infoipp
1257c478bd9Sstevel@tonic-gate };
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate /*
1287c478bd9Sstevel@tonic-gate  * Device drivers
1297c478bd9Sstevel@tonic-gate  */
1307c478bd9Sstevel@tonic-gate static int mod_infodrv(struct modldrv *, struct modlinkage *, int *);
1317c478bd9Sstevel@tonic-gate static int mod_installdrv(struct modldrv *, struct modlinkage *);
1327c478bd9Sstevel@tonic-gate static int mod_removedrv(struct modldrv *, struct modlinkage *);
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate struct mod_ops mod_driverops = {
1357c478bd9Sstevel@tonic-gate 	mod_installdrv, mod_removedrv, mod_infodrv
1367c478bd9Sstevel@tonic-gate };
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate /*
1397c478bd9Sstevel@tonic-gate  * System calls (new interface)
1407c478bd9Sstevel@tonic-gate  */
1417c478bd9Sstevel@tonic-gate static int mod_infosys(struct modlsys *, struct modlinkage *, int *);
1427c478bd9Sstevel@tonic-gate static int mod_installsys(struct modlsys *, struct modlinkage *);
1437c478bd9Sstevel@tonic-gate static int mod_removesys(struct modlsys *, struct modlinkage *);
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate struct mod_ops mod_syscallops = {
1467c478bd9Sstevel@tonic-gate 	mod_installsys, mod_removesys, mod_infosys
1477c478bd9Sstevel@tonic-gate };
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate  * 32-bit system calls in 64-bit kernel
1527c478bd9Sstevel@tonic-gate  */
1537c478bd9Sstevel@tonic-gate static int mod_infosys32(struct modlsys *, struct modlinkage *, int *);
1547c478bd9Sstevel@tonic-gate static int mod_installsys32(struct modlsys *, struct modlinkage *);
1557c478bd9Sstevel@tonic-gate static int mod_removesys32(struct modlsys *, struct modlinkage *);
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate struct mod_ops mod_syscallops32 = {
1587c478bd9Sstevel@tonic-gate 	mod_installsys32, mod_removesys32, mod_infosys32
1597c478bd9Sstevel@tonic-gate };
1607c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32_IMPL */
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate /*
1637c478bd9Sstevel@tonic-gate  * Filesystems
1647c478bd9Sstevel@tonic-gate  */
1657c478bd9Sstevel@tonic-gate static int mod_infofs(struct modlfs *, struct modlinkage *, int *);
1667c478bd9Sstevel@tonic-gate static int mod_installfs(struct modlfs *, struct modlinkage *);
1677c478bd9Sstevel@tonic-gate static int mod_removefs(struct modlfs *, struct modlinkage *);
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate struct mod_ops mod_fsops = {
1707c478bd9Sstevel@tonic-gate 	mod_installfs, mod_removefs, mod_infofs
1717c478bd9Sstevel@tonic-gate };
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate /*
1747c478bd9Sstevel@tonic-gate  * Streams modules.
1757c478bd9Sstevel@tonic-gate  */
1767c478bd9Sstevel@tonic-gate static int mod_infostrmod(struct modlstrmod *, struct modlinkage *, int *);
1777c478bd9Sstevel@tonic-gate static int mod_installstrmod(struct modlstrmod *, struct modlinkage *);
1787c478bd9Sstevel@tonic-gate static int mod_removestrmod(struct modlstrmod *, struct modlinkage *);
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate struct mod_ops mod_strmodops = {
1817c478bd9Sstevel@tonic-gate 	mod_installstrmod, mod_removestrmod, mod_infostrmod
1827c478bd9Sstevel@tonic-gate };
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate /*
1857c478bd9Sstevel@tonic-gate  * Scheduling classes.
1867c478bd9Sstevel@tonic-gate  */
1877c478bd9Sstevel@tonic-gate static int mod_infosched(struct modlsched *, struct modlinkage *, int *);
1887c478bd9Sstevel@tonic-gate static int mod_installsched(struct modlsched *, struct modlinkage *);
1897c478bd9Sstevel@tonic-gate static int mod_removesched(struct modlsched *, struct modlinkage *);
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate struct mod_ops mod_schedops = {
1927c478bd9Sstevel@tonic-gate 	mod_installsched, mod_removesched, mod_infosched
1937c478bd9Sstevel@tonic-gate };
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate /*
1967c478bd9Sstevel@tonic-gate  * Exec file type (like ELF, ...).
1977c478bd9Sstevel@tonic-gate  */
1987c478bd9Sstevel@tonic-gate static int mod_infoexec(struct modlexec *, struct modlinkage *, int *);
1997c478bd9Sstevel@tonic-gate static int mod_installexec(struct modlexec *, struct modlinkage *);
2007c478bd9Sstevel@tonic-gate static int mod_removeexec(struct modlexec *, struct modlinkage *);
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate struct mod_ops mod_execops = {
2037c478bd9Sstevel@tonic-gate 	mod_installexec, mod_removeexec, mod_infoexec
2047c478bd9Sstevel@tonic-gate };
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate /*
2077c478bd9Sstevel@tonic-gate  * Dacf (Dynamic Autoconfiguration) modules.
2087c478bd9Sstevel@tonic-gate  */
2097c478bd9Sstevel@tonic-gate static int mod_infodacf(struct modldacf *, struct modlinkage *, int *);
2107c478bd9Sstevel@tonic-gate static int mod_installdacf(struct modldacf *, struct modlinkage *);
2117c478bd9Sstevel@tonic-gate static int mod_removedacf(struct modldacf *, struct modlinkage *);
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate struct mod_ops mod_dacfops = {
2147c478bd9Sstevel@tonic-gate 	mod_installdacf, mod_removedacf, mod_infodacf
2157c478bd9Sstevel@tonic-gate };
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate /*
2187c478bd9Sstevel@tonic-gate  * PCBE (Performance Counter BackEnd) modules.
2197c478bd9Sstevel@tonic-gate  */
2207c478bd9Sstevel@tonic-gate static int mod_installpcbe(struct modlpcbe *, struct modlinkage *);
2217c478bd9Sstevel@tonic-gate static int mod_removepcbe(struct modlpcbe *, struct modlinkage *);
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate struct mod_ops mod_pcbeops = {
2247c478bd9Sstevel@tonic-gate 	mod_installpcbe, mod_removepcbe, mod_infonull
2257c478bd9Sstevel@tonic-gate };
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate static struct sysent *mod_getsysent(struct modlinkage *, struct sysent *);
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate static char uninstall_err[] = "Cannot uninstall %s; not installed";
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate /*
2327c478bd9Sstevel@tonic-gate  * Debugging support
2337c478bd9Sstevel@tonic-gate  */
2347c478bd9Sstevel@tonic-gate #define	DRV_DBG		MODDEBUG_LOADMSG2
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate /*PRINTFLIKE2*/
2377c478bd9Sstevel@tonic-gate static void mod_dprintf(int flag, const char *format, ...) __KPRINTFLIKE(2);
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate static void
2407c478bd9Sstevel@tonic-gate mod_dprintf(int flag, const char *format, ...)
2417c478bd9Sstevel@tonic-gate {
2427c478bd9Sstevel@tonic-gate 	va_list alist;
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 	if ((moddebug & flag) != 0) {
2457c478bd9Sstevel@tonic-gate 		va_start(alist, format);
2467c478bd9Sstevel@tonic-gate 		(void) vprintf(format, alist);
2477c478bd9Sstevel@tonic-gate 		va_end(alist);
2487c478bd9Sstevel@tonic-gate 	}
2497c478bd9Sstevel@tonic-gate }
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate /*
2527c478bd9Sstevel@tonic-gate  * Install a module.
2537c478bd9Sstevel@tonic-gate  * (This routine is in the Solaris SPARC DDI/DKI)
2547c478bd9Sstevel@tonic-gate  */
2557c478bd9Sstevel@tonic-gate int
2567c478bd9Sstevel@tonic-gate mod_install(struct modlinkage *modlp)
2577c478bd9Sstevel@tonic-gate {
2587c478bd9Sstevel@tonic-gate 	int retval = -1;	/* No linkage structures */
2597c478bd9Sstevel@tonic-gate 	struct modlmisc **linkpp;
2607c478bd9Sstevel@tonic-gate 	struct modlmisc **linkpp1;
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate 	if (modlp->ml_rev != MODREV_1) {
2637c478bd9Sstevel@tonic-gate 		printf("mod_install:  modlinkage structure is not MODREV_1\n");
2647c478bd9Sstevel@tonic-gate 		return (EINVAL);
2657c478bd9Sstevel@tonic-gate 	}
2667c478bd9Sstevel@tonic-gate 	linkpp = (struct modlmisc **)&modlp->ml_linkage[0];
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 	while (*linkpp != NULL) {
2697c478bd9Sstevel@tonic-gate 		if ((retval = MODL_INSTALL(*linkpp, modlp)) != 0) {
2707c478bd9Sstevel@tonic-gate 			linkpp1 = (struct modlmisc **)&modlp->ml_linkage[0];
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 			while (linkpp1 != linkpp) {
2737c478bd9Sstevel@tonic-gate 				MODL_REMOVE(*linkpp1, modlp); /* clean up */
2747c478bd9Sstevel@tonic-gate 				linkpp1++;
2757c478bd9Sstevel@tonic-gate 			}
2767c478bd9Sstevel@tonic-gate 			break;
2777c478bd9Sstevel@tonic-gate 		}
2787c478bd9Sstevel@tonic-gate 		linkpp++;
2797c478bd9Sstevel@tonic-gate 	}
2807c478bd9Sstevel@tonic-gate 	return (retval);
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate static char *reins_err =
2847c478bd9Sstevel@tonic-gate 	"Could not reinstall %s\nReboot to correct the problem";
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate /*
2877c478bd9Sstevel@tonic-gate  * Remove a module.  This is called by the module wrapper routine.
2887c478bd9Sstevel@tonic-gate  * (This routine is in the Solaris SPARC DDI/DKI)
2897c478bd9Sstevel@tonic-gate  */
2907c478bd9Sstevel@tonic-gate int
2917c478bd9Sstevel@tonic-gate mod_remove(struct modlinkage *modlp)
2927c478bd9Sstevel@tonic-gate {
2937c478bd9Sstevel@tonic-gate 	int retval = 0;
2947c478bd9Sstevel@tonic-gate 	struct modlmisc **linkpp, *last_linkp;
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate 	linkpp = (struct modlmisc **)&modlp->ml_linkage[0];
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate 	while (*linkpp != NULL) {
2997c478bd9Sstevel@tonic-gate 		if ((retval = MODL_REMOVE(*linkpp, modlp)) != 0) {
3007c478bd9Sstevel@tonic-gate 			last_linkp = *linkpp;
3017c478bd9Sstevel@tonic-gate 			linkpp = (struct modlmisc **)&modlp->ml_linkage[0];
3027c478bd9Sstevel@tonic-gate 			while (*linkpp != last_linkp) {
3037c478bd9Sstevel@tonic-gate 				if (MODL_INSTALL(*linkpp, modlp) != 0) {
3047c478bd9Sstevel@tonic-gate 					cmn_err(CE_WARN, reins_err,
3057c478bd9Sstevel@tonic-gate 						(*linkpp)->misc_linkinfo);
3067c478bd9Sstevel@tonic-gate 					break;
3077c478bd9Sstevel@tonic-gate 				}
3087c478bd9Sstevel@tonic-gate 				linkpp++;
3097c478bd9Sstevel@tonic-gate 			}
3107c478bd9Sstevel@tonic-gate 			break;
3117c478bd9Sstevel@tonic-gate 		}
3127c478bd9Sstevel@tonic-gate 		linkpp++;
3137c478bd9Sstevel@tonic-gate 	}
3147c478bd9Sstevel@tonic-gate 	return (retval);
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate /*
3187c478bd9Sstevel@tonic-gate  * Get module status.
3197c478bd9Sstevel@tonic-gate  * (This routine is in the Solaris SPARC DDI/DKI)
3207c478bd9Sstevel@tonic-gate  */
3217c478bd9Sstevel@tonic-gate int
3227c478bd9Sstevel@tonic-gate mod_info(struct modlinkage *modlp, struct modinfo *modinfop)
3237c478bd9Sstevel@tonic-gate {
3247c478bd9Sstevel@tonic-gate 	int i;
3257c478bd9Sstevel@tonic-gate 	int retval = 0;
3267c478bd9Sstevel@tonic-gate 	struct modspecific_info *msip;
3277c478bd9Sstevel@tonic-gate 	struct modlmisc **linkpp;
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate 	modinfop->mi_rev = modlp->ml_rev;
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 	linkpp = (struct modlmisc **)modlp->ml_linkage;
3327c478bd9Sstevel@tonic-gate 	msip = &modinfop->mi_msinfo[0];
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate 	for (i = 0; i < MODMAXLINK; i++) {
3357c478bd9Sstevel@tonic-gate 		if (*linkpp == NULL) {
3367c478bd9Sstevel@tonic-gate 			msip->msi_linkinfo[0] = '\0';
3377c478bd9Sstevel@tonic-gate 		} else {
3387c478bd9Sstevel@tonic-gate 			(void) strncpy(msip->msi_linkinfo,
3397c478bd9Sstevel@tonic-gate 			    (*linkpp)->misc_linkinfo, MODMAXLINKINFOLEN);
3407c478bd9Sstevel@tonic-gate 			retval = MODL_INFO(*linkpp, modlp, &msip->msi_p0);
3417c478bd9Sstevel@tonic-gate 			if (retval != 0)
3427c478bd9Sstevel@tonic-gate 				break;
3437c478bd9Sstevel@tonic-gate 			linkpp++;
3447c478bd9Sstevel@tonic-gate 		}
3457c478bd9Sstevel@tonic-gate 		msip++;
3467c478bd9Sstevel@tonic-gate 	}
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate 	if (modinfop->mi_info == MI_INFO_LINKAGE) {
3497c478bd9Sstevel@tonic-gate 		/*
3507c478bd9Sstevel@tonic-gate 		 * Slight kludge used to extract the address of the
3517c478bd9Sstevel@tonic-gate 		 * modlinkage structure from the module (just after
3527c478bd9Sstevel@tonic-gate 		 * loading a module for the very first time)
3537c478bd9Sstevel@tonic-gate 		 */
3547c478bd9Sstevel@tonic-gate 		modinfop->mi_base = (void *)modlp;
3557c478bd9Sstevel@tonic-gate 	}
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 	if (retval == 0)
3587c478bd9Sstevel@tonic-gate 		return (1);
3597c478bd9Sstevel@tonic-gate 	return (0);
3607c478bd9Sstevel@tonic-gate }
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate /*
3637c478bd9Sstevel@tonic-gate  * Get module name.
3647c478bd9Sstevel@tonic-gate  */
3657c478bd9Sstevel@tonic-gate char *
3667c478bd9Sstevel@tonic-gate mod_modname(struct modlinkage *modlp)
3677c478bd9Sstevel@tonic-gate {
3687c478bd9Sstevel@tonic-gate 	struct modctl	*mcp;
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate 	if ((mcp = mod_getctl(modlp)) == NULL)
3717c478bd9Sstevel@tonic-gate 		return (NULL);
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 	return (mcp->mod_modname);
3747c478bd9Sstevel@tonic-gate }
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate /*
3777c478bd9Sstevel@tonic-gate  * Null operation; return 0.
3787c478bd9Sstevel@tonic-gate  */
3797c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3807c478bd9Sstevel@tonic-gate static int
3817c478bd9Sstevel@tonic-gate mod_null(struct modldrv *modl, struct modlinkage *modlp)
3827c478bd9Sstevel@tonic-gate {
3837c478bd9Sstevel@tonic-gate 	return (0);
3847c478bd9Sstevel@tonic-gate }
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate /*
3877c478bd9Sstevel@tonic-gate  * Status for User modules.
3887c478bd9Sstevel@tonic-gate  */
3897c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3907c478bd9Sstevel@tonic-gate static int
3917c478bd9Sstevel@tonic-gate mod_infonull(void *modl, struct modlinkage *modlp, int *p0)
3927c478bd9Sstevel@tonic-gate {
3937c478bd9Sstevel@tonic-gate 	*p0 = -1;		/* for modinfo display */
3947c478bd9Sstevel@tonic-gate 	return (0);
3957c478bd9Sstevel@tonic-gate }
3967c478bd9Sstevel@tonic-gate 
3977c478bd9Sstevel@tonic-gate /*
3987c478bd9Sstevel@tonic-gate  * Driver status info
3997c478bd9Sstevel@tonic-gate  */
4007c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4017c478bd9Sstevel@tonic-gate static int
4027c478bd9Sstevel@tonic-gate mod_infodrv(struct modldrv *modl, struct modlinkage *modlp, int *p0)
4037c478bd9Sstevel@tonic-gate {
4047c478bd9Sstevel@tonic-gate 	struct modctl *mcp;
4057c478bd9Sstevel@tonic-gate 	char *mod_name;
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate 	if ((mcp = mod_getctl(modlp)) == NULL) {
4087c478bd9Sstevel@tonic-gate 		*p0 = -1;
4097c478bd9Sstevel@tonic-gate 		return (0);	/* driver is not yet installed */
4107c478bd9Sstevel@tonic-gate 	}
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate 	mod_name = mcp->mod_modname;
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate 	*p0 = ddi_name_to_major(mod_name);
4157c478bd9Sstevel@tonic-gate 	return (0);
4167c478bd9Sstevel@tonic-gate }
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate /*
4197c478bd9Sstevel@tonic-gate  * Manage dacf (device autoconfiguration) modules
4207c478bd9Sstevel@tonic-gate  */
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4237c478bd9Sstevel@tonic-gate static int
4247c478bd9Sstevel@tonic-gate mod_infodacf(struct modldacf *modl, struct modlinkage *modlp, int *p0)
4257c478bd9Sstevel@tonic-gate {
4267c478bd9Sstevel@tonic-gate 	if (mod_getctl(modlp) == NULL) {
4277c478bd9Sstevel@tonic-gate 		*p0 = -1;
4287c478bd9Sstevel@tonic-gate 		return (0);	/* module is not yet installed */
4297c478bd9Sstevel@tonic-gate 	}
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate 	*p0 = 0;
4327c478bd9Sstevel@tonic-gate 	return (0);
4337c478bd9Sstevel@tonic-gate }
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate static int
4367c478bd9Sstevel@tonic-gate mod_installdacf(struct modldacf *modl, struct modlinkage *modlp)
4377c478bd9Sstevel@tonic-gate {
4387c478bd9Sstevel@tonic-gate 	struct modctl	*mcp;
4397c478bd9Sstevel@tonic-gate 
4407c478bd9Sstevel@tonic-gate 	if ((mcp = mod_getctl(modlp)) == NULL)
4417c478bd9Sstevel@tonic-gate 		return (EINVAL);
4427c478bd9Sstevel@tonic-gate 	return (dacf_module_register(mcp->mod_modname, modl->dacf_dacfsw));
4437c478bd9Sstevel@tonic-gate }
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4467c478bd9Sstevel@tonic-gate static int
4477c478bd9Sstevel@tonic-gate mod_removedacf(struct modldacf *modl, struct modlinkage *modlp)
4487c478bd9Sstevel@tonic-gate {
4497c478bd9Sstevel@tonic-gate 	struct modctl	*mcp;
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate 	if ((mcp = mod_getctl(modlp)) == NULL)
4527c478bd9Sstevel@tonic-gate 		return (EINVAL);
4537c478bd9Sstevel@tonic-gate 	return (dacf_module_unregister(mcp->mod_modname));
4547c478bd9Sstevel@tonic-gate }
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate /*
4577c478bd9Sstevel@tonic-gate  * Manage PCBE (Performance Counter BackEnd) modules.
4587c478bd9Sstevel@tonic-gate  */
4597c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4607c478bd9Sstevel@tonic-gate static int
4617c478bd9Sstevel@tonic-gate mod_installpcbe(struct modlpcbe *modl, struct modlinkage *modlp)
4627c478bd9Sstevel@tonic-gate {
4637c478bd9Sstevel@tonic-gate 	if (modl->pcbe_ops->pcbe_ver != PCBE_VER_1) {
4647c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "pcbe '%s' version mismatch",
4657c478bd9Sstevel@tonic-gate 		    modl->pcbe_linkinfo);
4667c478bd9Sstevel@tonic-gate 		return (EINVAL);
4677c478bd9Sstevel@tonic-gate 	}
4687c478bd9Sstevel@tonic-gate 
4697c478bd9Sstevel@tonic-gate 	kcpc_register_pcbe(modl->pcbe_ops);
4707c478bd9Sstevel@tonic-gate 	return (0);
4717c478bd9Sstevel@tonic-gate }
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate /*
4747c478bd9Sstevel@tonic-gate  * PCBEs may not be unloaded. It would make CPC locking too complex, and since
4757c478bd9Sstevel@tonic-gate  * PCBEs are loaded once and used for life, there is no harm done in leaving
4767c478bd9Sstevel@tonic-gate  * them in the system.
4777c478bd9Sstevel@tonic-gate  */
4787c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4797c478bd9Sstevel@tonic-gate static int
4807c478bd9Sstevel@tonic-gate mod_removepcbe(struct modlpcbe *modl, struct modlinkage *modlp)
4817c478bd9Sstevel@tonic-gate {
4827c478bd9Sstevel@tonic-gate 	return (EBUSY);
4837c478bd9Sstevel@tonic-gate }
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate 
4867c478bd9Sstevel@tonic-gate /*
4877c478bd9Sstevel@tonic-gate  * Install a new driver
4887c478bd9Sstevel@tonic-gate  */
4897c478bd9Sstevel@tonic-gate static int
4907c478bd9Sstevel@tonic-gate mod_installdrv(struct modldrv *modl, struct modlinkage *modlp)
4917c478bd9Sstevel@tonic-gate {
4927c478bd9Sstevel@tonic-gate 	struct modctl *mcp;
4937c478bd9Sstevel@tonic-gate 	struct dev_ops *ops;
4947c478bd9Sstevel@tonic-gate 	char *modname;
4957c478bd9Sstevel@tonic-gate 	major_t major;
4967c478bd9Sstevel@tonic-gate 	struct dev_ops *dp;
4977c478bd9Sstevel@tonic-gate 	struct devnames *dnp;
4987c478bd9Sstevel@tonic-gate 	struct streamtab *str;
4997c478bd9Sstevel@tonic-gate 	cdevsw_impl_t *cdp;
5007c478bd9Sstevel@tonic-gate 	uint_t sqtype;
5017c478bd9Sstevel@tonic-gate 	uint_t qflag;
5027c478bd9Sstevel@tonic-gate 	uint_t flag;
5037c478bd9Sstevel@tonic-gate 	int err = 0;
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate 	/* sanity check module */
5067c478bd9Sstevel@tonic-gate 	if ((mcp = mod_getctl(modlp)) == NULL) {
5077c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "mod_install: bad module linkage data");
5087c478bd9Sstevel@tonic-gate 		err = ENXIO;
5097c478bd9Sstevel@tonic-gate 		goto done;
5107c478bd9Sstevel@tonic-gate 	}
5117c478bd9Sstevel@tonic-gate 	modname = mcp->mod_modname;
5127c478bd9Sstevel@tonic-gate 
5137c478bd9Sstevel@tonic-gate 	/* Sanity check modname */
5147c478bd9Sstevel@tonic-gate 	if ((major = ddi_name_to_major(modname)) == (major_t)-1) {
5157c478bd9Sstevel@tonic-gate #ifdef DEBUG
5167c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
5177c478bd9Sstevel@tonic-gate 		    "mod_installdrv: no major number for %s", modname);
5187c478bd9Sstevel@tonic-gate #endif
5197c478bd9Sstevel@tonic-gate 		err = ENXIO;
5207c478bd9Sstevel@tonic-gate 		goto done;
5217c478bd9Sstevel@tonic-gate 	}
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate 	/* Verify MP safety flag */
5247c478bd9Sstevel@tonic-gate 	ops = modl->drv_dev_ops;
5257c478bd9Sstevel@tonic-gate 	if (ops->devo_bus_ops == NULL && ops->devo_cb_ops != NULL &&
5267c478bd9Sstevel@tonic-gate 	    !(ops->devo_cb_ops->cb_flag & D_MP)) {
5277c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
5287c478bd9Sstevel@tonic-gate 		    "mod_installdrv: MT-unsafe driver '%s' rejected", modname);
5297c478bd9Sstevel@tonic-gate 		err = ENXIO;
5307c478bd9Sstevel@tonic-gate 		goto done;
5317c478bd9Sstevel@tonic-gate 	}
5327c478bd9Sstevel@tonic-gate 
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate 	/* Is bus_map_fault signature correct (version 8 and higher)? */
5357c478bd9Sstevel@tonic-gate 	if (ops->devo_bus_ops != NULL &&
5367c478bd9Sstevel@tonic-gate 	    ops->devo_bus_ops->bus_map_fault != NULL &&
5377c478bd9Sstevel@tonic-gate 	    ops->devo_bus_ops->bus_map_fault != i_ddi_map_fault &&
5387c478bd9Sstevel@tonic-gate 	    ops->devo_bus_ops->busops_rev < BUSO_REV_8) {
5397c478bd9Sstevel@tonic-gate 
5407c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
5417c478bd9Sstevel@tonic-gate 		    "mod_installdrv: busops' revision of '%s' is too low"
5427c478bd9Sstevel@tonic-gate 		    " (must be at least 8)", modname);
5437c478bd9Sstevel@tonic-gate 		err = ENXIO;
5447c478bd9Sstevel@tonic-gate 		goto done;
5457c478bd9Sstevel@tonic-gate 	}
5467c478bd9Sstevel@tonic-gate 
5477c478bd9Sstevel@tonic-gate 
5487c478bd9Sstevel@tonic-gate 	/* Make sure the driver is uninstalled */
5497c478bd9Sstevel@tonic-gate 	dnp = &devnamesp[major];
5507c478bd9Sstevel@tonic-gate 	LOCK_DEV_OPS(&dnp->dn_lock);
5517c478bd9Sstevel@tonic-gate 	dp = devopsp[major];
5527c478bd9Sstevel@tonic-gate 
5537c478bd9Sstevel@tonic-gate 	if (dnp->dn_flags & DN_DRIVER_REMOVED) {
5547c478bd9Sstevel@tonic-gate #ifdef DEBUG
5557c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE,
5567c478bd9Sstevel@tonic-gate 		    "mod_installdrv: driver has been removed %s", modname);
5577c478bd9Sstevel@tonic-gate #endif
5587c478bd9Sstevel@tonic-gate 		err = ENXIO;
5597c478bd9Sstevel@tonic-gate 		goto unlock;
5607c478bd9Sstevel@tonic-gate 	}
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate 	if (dp != &nodev_ops && dp != &mod_nodev_ops) {
5637c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
5647c478bd9Sstevel@tonic-gate 		    "mod_installdrv: driver already installed %s", modname);
5657c478bd9Sstevel@tonic-gate 		err = EALREADY;
5667c478bd9Sstevel@tonic-gate 		goto unlock;
5677c478bd9Sstevel@tonic-gate 	}
5687c478bd9Sstevel@tonic-gate 
5697c478bd9Sstevel@tonic-gate 	devopsp[major] = ops; /* setup devopsp */
5707c478bd9Sstevel@tonic-gate 
5717c478bd9Sstevel@tonic-gate 	if ((str = STREAMSTAB(major)) != NULL) {	/* streams driver */
5727c478bd9Sstevel@tonic-gate 		flag = CBFLAG(major);
5737c478bd9Sstevel@tonic-gate 		if ((err = devflg_to_qflag(str, flag, &qflag, &sqtype)) != 0)
5747c478bd9Sstevel@tonic-gate 			goto unlock;
5757c478bd9Sstevel@tonic-gate 		cdp = &devimpl[major];
5767c478bd9Sstevel@tonic-gate 		ASSERT(cdp->d_str == NULL);
5777c478bd9Sstevel@tonic-gate 		cdp->d_str = str;
5787c478bd9Sstevel@tonic-gate 		cdp->d_qflag = qflag | QISDRV;
5797c478bd9Sstevel@tonic-gate 		cdp->d_sqtype = sqtype;
5807c478bd9Sstevel@tonic-gate 	}
5817c478bd9Sstevel@tonic-gate 
5827c478bd9Sstevel@tonic-gate 	if (ops->devo_bus_ops == NULL)
5837c478bd9Sstevel@tonic-gate 		dnp->dn_flags |= DN_LEAF_DRIVER;
5847c478bd9Sstevel@tonic-gate 
5857c478bd9Sstevel@tonic-gate unlock:
5867c478bd9Sstevel@tonic-gate 	UNLOCK_DEV_OPS(&dnp->dn_lock);
5877c478bd9Sstevel@tonic-gate done:
5887c478bd9Sstevel@tonic-gate 	return (err);
5897c478bd9Sstevel@tonic-gate }
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate static int
5927c478bd9Sstevel@tonic-gate mod_removedrv(struct modldrv *modl, struct modlinkage *modlp)
5937c478bd9Sstevel@tonic-gate {
5947c478bd9Sstevel@tonic-gate 	struct modctl *mcp;
5957c478bd9Sstevel@tonic-gate 	struct dev_ops *ops;
5967c478bd9Sstevel@tonic-gate 	struct devnames *dnp;
5977c478bd9Sstevel@tonic-gate 	struct dev_ops *dp;
5987c478bd9Sstevel@tonic-gate 	major_t major;
5997c478bd9Sstevel@tonic-gate 	char *modname;
6007c478bd9Sstevel@tonic-gate 	extern kthread_id_t mod_aul_thread;
6017c478bd9Sstevel@tonic-gate 	struct streamtab *str;
6027c478bd9Sstevel@tonic-gate 	cdevsw_impl_t *cdp;
6037c478bd9Sstevel@tonic-gate 	int err = 0;
6047c478bd9Sstevel@tonic-gate 
6057c478bd9Sstevel@tonic-gate 	/* Don't auto unload modules on if moddebug flag is set */
6067c478bd9Sstevel@tonic-gate 	if ((moddebug & MODDEBUG_NOAUL_DRV) && (mod_aul_thread == curthread)) {
6077c478bd9Sstevel@tonic-gate 		err = EBUSY;
6087c478bd9Sstevel@tonic-gate 		goto done;
6097c478bd9Sstevel@tonic-gate 	}
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate 	/* Verify modname has a driver major */
6127c478bd9Sstevel@tonic-gate 	mcp = mod_getctl(modlp);
6137c478bd9Sstevel@tonic-gate 	ASSERT(mcp != NULL);
6147c478bd9Sstevel@tonic-gate 	modname = mcp->mod_modname;
6157c478bd9Sstevel@tonic-gate 
6167c478bd9Sstevel@tonic-gate 	if ((major = ddi_name_to_major(modname)) == -1) {
6177c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, uninstall_err, modname);
6187c478bd9Sstevel@tonic-gate 		err = EINVAL;
6197c478bd9Sstevel@tonic-gate 		goto done;
6207c478bd9Sstevel@tonic-gate 	}
6217c478bd9Sstevel@tonic-gate 
6227c478bd9Sstevel@tonic-gate 	ops = modl->drv_dev_ops;
6237c478bd9Sstevel@tonic-gate 	dnp = &(devnamesp[major]);
6247c478bd9Sstevel@tonic-gate 	LOCK_DEV_OPS(&(dnp->dn_lock));
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate 	dp = devopsp[major];
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate 	if (dp != ops)  {
6297c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "mod_removedrv: mismatched driver for %s",
6307c478bd9Sstevel@tonic-gate 		    modname);
6317c478bd9Sstevel@tonic-gate 		err = EBUSY;
6327c478bd9Sstevel@tonic-gate 		goto unlock;
6337c478bd9Sstevel@tonic-gate 	}
6347c478bd9Sstevel@tonic-gate 
6357c478bd9Sstevel@tonic-gate 	/*
6367c478bd9Sstevel@tonic-gate 	 * A driver is not unloadable if its dev_ops are held
6377c478bd9Sstevel@tonic-gate 	 */
6387c478bd9Sstevel@tonic-gate 	if (!DRV_UNLOADABLE(dp)) {
6397c478bd9Sstevel@tonic-gate 		mod_dprintf(DRV_DBG, "Cannot unload device driver <%s>,"
6407c478bd9Sstevel@tonic-gate 		    " refcnt %d\n", modname, dp->devo_refcnt);
6417c478bd9Sstevel@tonic-gate 		err = EBUSY;
6427c478bd9Sstevel@tonic-gate 		goto unlock;
6437c478bd9Sstevel@tonic-gate 	}
6447c478bd9Sstevel@tonic-gate 
6457c478bd9Sstevel@tonic-gate 	/*
6467c478bd9Sstevel@tonic-gate 	 * OK to unload.
6477c478bd9Sstevel@tonic-gate 	 */
6487c478bd9Sstevel@tonic-gate 	if ((str = STREAMSTAB(major)) != NULL) {	/* streams driver */
6497c478bd9Sstevel@tonic-gate 		cdp = &devimpl[major];
6507c478bd9Sstevel@tonic-gate 		ASSERT(cdp->d_str == str);
6517c478bd9Sstevel@tonic-gate 		cdp->d_str = NULL;
6527c478bd9Sstevel@tonic-gate 
6537c478bd9Sstevel@tonic-gate 		/* check for reference to per-dev syncq */
6547c478bd9Sstevel@tonic-gate 		if (cdp->d_dmp != NULL) {
6557c478bd9Sstevel@tonic-gate 			rele_dm(cdp->d_dmp);
6567c478bd9Sstevel@tonic-gate 			cdp->d_dmp = NULL;
6577c478bd9Sstevel@tonic-gate 		}
6587c478bd9Sstevel@tonic-gate 	}
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate 	devopsp[major] = &mod_nodev_ops;
6617c478bd9Sstevel@tonic-gate 	dnp->dn_flags &= ~(DN_DRIVER_HELD|DN_NO_AUTODETACH);
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate unlock:
6647c478bd9Sstevel@tonic-gate 	UNLOCK_DEV_OPS(&(dnp->dn_lock));
6657c478bd9Sstevel@tonic-gate done:
6667c478bd9Sstevel@tonic-gate 	return (err);
6677c478bd9Sstevel@tonic-gate }
6687c478bd9Sstevel@tonic-gate 
6697c478bd9Sstevel@tonic-gate /*
6707c478bd9Sstevel@tonic-gate  * System call subroutines
6717c478bd9Sstevel@tonic-gate  */
6727c478bd9Sstevel@tonic-gate 
6737c478bd9Sstevel@tonic-gate /*
6747c478bd9Sstevel@tonic-gate  * Compute system call number for given sysent and sysent table
6757c478bd9Sstevel@tonic-gate  */
6767c478bd9Sstevel@tonic-gate static int
6777c478bd9Sstevel@tonic-gate mod_infosysnum(struct modlinkage *modlp, struct sysent table[])
6787c478bd9Sstevel@tonic-gate {
6797c478bd9Sstevel@tonic-gate 	struct sysent *sysp;
6807c478bd9Sstevel@tonic-gate 
6817c478bd9Sstevel@tonic-gate 	if ((sysp = mod_getsysent(modlp, table)) == NULL)
6827c478bd9Sstevel@tonic-gate 		return (-1);
6837c478bd9Sstevel@tonic-gate 	return ((int)(sysp - table));
6847c478bd9Sstevel@tonic-gate }
6857c478bd9Sstevel@tonic-gate 
6867c478bd9Sstevel@tonic-gate /*
6877c478bd9Sstevel@tonic-gate  * Put a loadable system call entry into a sysent table.
6887c478bd9Sstevel@tonic-gate  */
6897c478bd9Sstevel@tonic-gate static int
6907c478bd9Sstevel@tonic-gate mod_installsys_sysent(
6917c478bd9Sstevel@tonic-gate 	struct modlsys		*modl,
6927c478bd9Sstevel@tonic-gate 	struct modlinkage	*modlp,
6937c478bd9Sstevel@tonic-gate 	struct sysent		table[])
6947c478bd9Sstevel@tonic-gate {
6957c478bd9Sstevel@tonic-gate 	struct sysent *sysp;
6967c478bd9Sstevel@tonic-gate 	struct sysent *mp;
6977c478bd9Sstevel@tonic-gate 
6987c478bd9Sstevel@tonic-gate #ifdef DEBUG
6997c478bd9Sstevel@tonic-gate 	/*
7007c478bd9Sstevel@tonic-gate 	 * Before we even play with the sysent table, sanity check the
7017c478bd9Sstevel@tonic-gate 	 * incoming flags to make sure the entry is valid
7027c478bd9Sstevel@tonic-gate 	 */
7037c478bd9Sstevel@tonic-gate 	switch (modl->sys_sysent->sy_flags & SE_RVAL_MASK) {
7047c478bd9Sstevel@tonic-gate 	case SE_32RVAL1:
7057c478bd9Sstevel@tonic-gate 		/* only r_val1 returned */
7067c478bd9Sstevel@tonic-gate 	case SE_32RVAL1 | SE_32RVAL2:
7077c478bd9Sstevel@tonic-gate 		/* r_val1 and r_val2 returned */
7087c478bd9Sstevel@tonic-gate 	case SE_64RVAL:
7097c478bd9Sstevel@tonic-gate 		/* 64-bit rval returned */
7107c478bd9Sstevel@tonic-gate 		break;
7117c478bd9Sstevel@tonic-gate 	default:
7127c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "loadable syscall: %p: bad rval flags %x",
7137c478bd9Sstevel@tonic-gate 		    (void *)modl, modl->sys_sysent->sy_flags);
7147c478bd9Sstevel@tonic-gate 		return (ENOSYS);
7157c478bd9Sstevel@tonic-gate 	}
7167c478bd9Sstevel@tonic-gate #endif
7177c478bd9Sstevel@tonic-gate 	if ((sysp = mod_getsysent(modlp, table)) == NULL)
7187c478bd9Sstevel@tonic-gate 		return (ENOSPC);
7197c478bd9Sstevel@tonic-gate 
7207c478bd9Sstevel@tonic-gate 	/*
7217c478bd9Sstevel@tonic-gate 	 * We should only block here until the reader in syscall gives
7227c478bd9Sstevel@tonic-gate 	 * up the lock.  Multiple writers are prevented in the mod layer.
7237c478bd9Sstevel@tonic-gate 	 */
7247c478bd9Sstevel@tonic-gate 	rw_enter(sysp->sy_lock, RW_WRITER);
7257c478bd9Sstevel@tonic-gate 	mp = modl->sys_sysent;
7267c478bd9Sstevel@tonic-gate 	sysp->sy_narg = mp->sy_narg;
7277c478bd9Sstevel@tonic-gate 	sysp->sy_call = mp->sy_call;
7287c478bd9Sstevel@tonic-gate 
7297c478bd9Sstevel@tonic-gate 	/*
7307c478bd9Sstevel@tonic-gate 	 * clear the old call method flag, and get the new one from the module.
7317c478bd9Sstevel@tonic-gate 	 */
7327c478bd9Sstevel@tonic-gate 	sysp->sy_flags &= ~SE_ARGC;
7337c478bd9Sstevel@tonic-gate 	sysp->sy_flags |= SE_LOADED |
7347c478bd9Sstevel@tonic-gate 	    (mp->sy_flags & (SE_ARGC | SE_NOUNLOAD | SE_RVAL_MASK));
7357c478bd9Sstevel@tonic-gate 
7367c478bd9Sstevel@tonic-gate 	/*
7377c478bd9Sstevel@tonic-gate 	 * If the syscall doesn't need or want unloading, it can avoid
7387c478bd9Sstevel@tonic-gate 	 * the locking overhead on each entry.  Convert the sysent to a
7397c478bd9Sstevel@tonic-gate 	 * normal non-loadable entry in that case.
7407c478bd9Sstevel@tonic-gate 	 */
7417c478bd9Sstevel@tonic-gate 	if (mp->sy_flags & SE_NOUNLOAD) {
7427c478bd9Sstevel@tonic-gate 		if (mp->sy_flags & SE_ARGC) {
7437c478bd9Sstevel@tonic-gate 			sysp->sy_callc = (int64_t (*)())mp->sy_call;
7447c478bd9Sstevel@tonic-gate 		} else {
7457c478bd9Sstevel@tonic-gate 			sysp->sy_callc = syscall_ap;
7467c478bd9Sstevel@tonic-gate 		}
7477c478bd9Sstevel@tonic-gate 		sysp->sy_flags &= ~SE_LOADABLE;
7487c478bd9Sstevel@tonic-gate 	}
7497c478bd9Sstevel@tonic-gate 	rw_exit(sysp->sy_lock);
7507c478bd9Sstevel@tonic-gate 	return (0);
7517c478bd9Sstevel@tonic-gate }
7527c478bd9Sstevel@tonic-gate 
7537c478bd9Sstevel@tonic-gate /*
7547c478bd9Sstevel@tonic-gate  * Remove a loadable system call entry from a sysent table.
7557c478bd9Sstevel@tonic-gate  */
7567c478bd9Sstevel@tonic-gate static int
7577c478bd9Sstevel@tonic-gate mod_removesys_sysent(
7587c478bd9Sstevel@tonic-gate 	struct modlsys		*modl,
7597c478bd9Sstevel@tonic-gate 	struct modlinkage	*modlp,
7607c478bd9Sstevel@tonic-gate 	struct sysent		table[])
7617c478bd9Sstevel@tonic-gate {
7627c478bd9Sstevel@tonic-gate 	struct sysent	*sysp;
7637c478bd9Sstevel@tonic-gate 
7647c478bd9Sstevel@tonic-gate 	if ((sysp = mod_getsysent(modlp, table)) == NULL ||
7657c478bd9Sstevel@tonic-gate 	    (sysp->sy_flags & (SE_LOADABLE | SE_NOUNLOAD)) == 0 ||
7667c478bd9Sstevel@tonic-gate 	    sysp->sy_call != modl->sys_sysent->sy_call) {
7677c478bd9Sstevel@tonic-gate 
7687c478bd9Sstevel@tonic-gate 		struct modctl *mcp = mod_getctl(modlp);
7697c478bd9Sstevel@tonic-gate 		char *modname = mcp->mod_modname;
7707c478bd9Sstevel@tonic-gate 
7717c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, uninstall_err, modname);
7727c478bd9Sstevel@tonic-gate 		return (EINVAL);
7737c478bd9Sstevel@tonic-gate 	}
7747c478bd9Sstevel@tonic-gate 
7757c478bd9Sstevel@tonic-gate 	/* If we can't get the write lock, we can't unlink from the system */
7767c478bd9Sstevel@tonic-gate 
7777c478bd9Sstevel@tonic-gate 	if (!(moddebug & MODDEBUG_NOAUL_SYS) &&
7787c478bd9Sstevel@tonic-gate 	    rw_tryenter(sysp->sy_lock, RW_WRITER)) {
7797c478bd9Sstevel@tonic-gate 		/*
7807c478bd9Sstevel@tonic-gate 		 * Check the flags to be sure the syscall is still
7817c478bd9Sstevel@tonic-gate 		 * (un)loadable.
7827c478bd9Sstevel@tonic-gate 		 * If SE_NOUNLOAD is set, SE_LOADABLE will not be.
7837c478bd9Sstevel@tonic-gate 		 */
7847c478bd9Sstevel@tonic-gate 		if ((sysp->sy_flags & (SE_LOADED | SE_LOADABLE)) ==
7857c478bd9Sstevel@tonic-gate 		    (SE_LOADED | SE_LOADABLE)) {
7867c478bd9Sstevel@tonic-gate 			sysp->sy_flags &= ~SE_LOADED;
7877c478bd9Sstevel@tonic-gate 			sysp->sy_callc = loadable_syscall;
7887c478bd9Sstevel@tonic-gate 			sysp->sy_call = (int (*)())nosys;
7897c478bd9Sstevel@tonic-gate 			rw_exit(sysp->sy_lock);
7907c478bd9Sstevel@tonic-gate 			return (0);
7917c478bd9Sstevel@tonic-gate 		}
7927c478bd9Sstevel@tonic-gate 		rw_exit(sysp->sy_lock);
7937c478bd9Sstevel@tonic-gate 	}
7947c478bd9Sstevel@tonic-gate 	return (EBUSY);
7957c478bd9Sstevel@tonic-gate }
7967c478bd9Sstevel@tonic-gate 
7977c478bd9Sstevel@tonic-gate /*
7987c478bd9Sstevel@tonic-gate  * System call status info
7997c478bd9Sstevel@tonic-gate  */
8007c478bd9Sstevel@tonic-gate /*ARGSUSED*/
8017c478bd9Sstevel@tonic-gate static int
8027c478bd9Sstevel@tonic-gate mod_infosys(struct modlsys *modl, struct modlinkage *modlp, int *p0)
8037c478bd9Sstevel@tonic-gate {
8047c478bd9Sstevel@tonic-gate 	*p0 = mod_infosysnum(modlp, sysent);
8057c478bd9Sstevel@tonic-gate 	return (0);
8067c478bd9Sstevel@tonic-gate }
8077c478bd9Sstevel@tonic-gate 
8087c478bd9Sstevel@tonic-gate /*
8097c478bd9Sstevel@tonic-gate  * Link a system call into the system by setting the proper sysent entry.
8107c478bd9Sstevel@tonic-gate  * Called from the module's _init routine.
8117c478bd9Sstevel@tonic-gate  */
8127c478bd9Sstevel@tonic-gate static int
8137c478bd9Sstevel@tonic-gate mod_installsys(struct modlsys *modl, struct modlinkage *modlp)
8147c478bd9Sstevel@tonic-gate {
8157c478bd9Sstevel@tonic-gate 	return (mod_installsys_sysent(modl, modlp, sysent));
8167c478bd9Sstevel@tonic-gate }
8177c478bd9Sstevel@tonic-gate 
8187c478bd9Sstevel@tonic-gate /*
8197c478bd9Sstevel@tonic-gate  * Unlink a system call from the system.
8207c478bd9Sstevel@tonic-gate  * Called from a modules _fini routine.
8217c478bd9Sstevel@tonic-gate  */
8227c478bd9Sstevel@tonic-gate static int
8237c478bd9Sstevel@tonic-gate mod_removesys(struct modlsys *modl, struct modlinkage *modlp)
8247c478bd9Sstevel@tonic-gate {
8257c478bd9Sstevel@tonic-gate 	return (mod_removesys_sysent(modl, modlp, sysent));
8267c478bd9Sstevel@tonic-gate }
8277c478bd9Sstevel@tonic-gate 
8287c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
8297c478bd9Sstevel@tonic-gate 
8307c478bd9Sstevel@tonic-gate /*
8317c478bd9Sstevel@tonic-gate  * 32-bit system call status info
8327c478bd9Sstevel@tonic-gate  */
8337c478bd9Sstevel@tonic-gate /*ARGSUSED*/
8347c478bd9Sstevel@tonic-gate static int
8357c478bd9Sstevel@tonic-gate mod_infosys32(struct modlsys *modl, struct modlinkage *modlp, int *p0)
8367c478bd9Sstevel@tonic-gate {
8377c478bd9Sstevel@tonic-gate 	*p0 = mod_infosysnum(modlp, sysent32);
8387c478bd9Sstevel@tonic-gate 	return (0);
8397c478bd9Sstevel@tonic-gate }
8407c478bd9Sstevel@tonic-gate 
8417c478bd9Sstevel@tonic-gate /*
8427c478bd9Sstevel@tonic-gate  * Link the 32-bit syscall into the system by setting the proper sysent entry.
8437c478bd9Sstevel@tonic-gate  * Also called from the module's _init routine.
8447c478bd9Sstevel@tonic-gate  */
8457c478bd9Sstevel@tonic-gate static int
8467c478bd9Sstevel@tonic-gate mod_installsys32(struct modlsys *modl, struct modlinkage *modlp)
8477c478bd9Sstevel@tonic-gate {
8487c478bd9Sstevel@tonic-gate 	return (mod_installsys_sysent(modl, modlp, sysent32));
8497c478bd9Sstevel@tonic-gate }
8507c478bd9Sstevel@tonic-gate 
8517c478bd9Sstevel@tonic-gate /*
8527c478bd9Sstevel@tonic-gate  * Unlink the 32-bit flavor of a system call from the system.
8537c478bd9Sstevel@tonic-gate  * Also called from a module's _fini routine.
8547c478bd9Sstevel@tonic-gate  */
8557c478bd9Sstevel@tonic-gate static int
8567c478bd9Sstevel@tonic-gate mod_removesys32(struct modlsys *modl, struct modlinkage *modlp)
8577c478bd9Sstevel@tonic-gate {
8587c478bd9Sstevel@tonic-gate 	return (mod_removesys_sysent(modl, modlp, sysent32));
8597c478bd9Sstevel@tonic-gate }
8607c478bd9Sstevel@tonic-gate 
8617c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32_IMPL */
8627c478bd9Sstevel@tonic-gate 
8637c478bd9Sstevel@tonic-gate /*
8647c478bd9Sstevel@tonic-gate  * Filesystem status info
8657c478bd9Sstevel@tonic-gate  */
8667c478bd9Sstevel@tonic-gate /*ARGSUSED*/
8677c478bd9Sstevel@tonic-gate static int
8687c478bd9Sstevel@tonic-gate mod_infofs(struct modlfs *modl, struct modlinkage *modlp, int *p0)
8697c478bd9Sstevel@tonic-gate {
8707c478bd9Sstevel@tonic-gate 	struct vfssw *vswp;
8717c478bd9Sstevel@tonic-gate 
8727c478bd9Sstevel@tonic-gate 	RLOCK_VFSSW();
8737c478bd9Sstevel@tonic-gate 	if ((vswp = vfs_getvfsswbyname(modl->fs_vfsdef->name)) == NULL)
8747c478bd9Sstevel@tonic-gate 		*p0 = -1;
8757c478bd9Sstevel@tonic-gate 	else {
8767c478bd9Sstevel@tonic-gate 		*p0 = vswp - vfssw;
8777c478bd9Sstevel@tonic-gate 		vfs_unrefvfssw(vswp);
8787c478bd9Sstevel@tonic-gate 	}
8797c478bd9Sstevel@tonic-gate 	RUNLOCK_VFSSW();
8807c478bd9Sstevel@tonic-gate 	return (0);
8817c478bd9Sstevel@tonic-gate }
8827c478bd9Sstevel@tonic-gate 
8837c478bd9Sstevel@tonic-gate /*
8847c478bd9Sstevel@tonic-gate  * Install a filesystem.
8857c478bd9Sstevel@tonic-gate  */
8867c478bd9Sstevel@tonic-gate /*ARGSUSED1*/
8877c478bd9Sstevel@tonic-gate static int
8887c478bd9Sstevel@tonic-gate mod_installfs(struct modlfs *modl, struct modlinkage *modlp)
8897c478bd9Sstevel@tonic-gate {
8907c478bd9Sstevel@tonic-gate 	struct vfssw *vswp;
8917c478bd9Sstevel@tonic-gate 	struct modctl *mcp;
8927c478bd9Sstevel@tonic-gate 	char *fsname;
8937c478bd9Sstevel@tonic-gate 	int allocated;
8947c478bd9Sstevel@tonic-gate 	int err;
8957c478bd9Sstevel@tonic-gate 
8967c478bd9Sstevel@tonic-gate 	if (modl->fs_vfsdef->def_version == VFSDEF_VERSION) {
8977c478bd9Sstevel@tonic-gate 		/* Version matched */
8987c478bd9Sstevel@tonic-gate 		fsname = modl->fs_vfsdef->name;
8997c478bd9Sstevel@tonic-gate 	} else {
9007c478bd9Sstevel@tonic-gate 		if ((modl->fs_vfsdef->def_version > 0) &&
9017c478bd9Sstevel@tonic-gate 		    (modl->fs_vfsdef->def_version < VFSDEF_VERSION)) {
9027c478bd9Sstevel@tonic-gate 			/* Older VFSDEF_VERSION */
9037c478bd9Sstevel@tonic-gate 			fsname = modl->fs_vfsdef->name;
9047c478bd9Sstevel@tonic-gate 		} else if ((mcp = mod_getctl(modlp)) != NULL) {
9057c478bd9Sstevel@tonic-gate 			/* Pre-VFSDEF_VERSION */
9067c478bd9Sstevel@tonic-gate 			fsname = mcp->mod_modname;
9077c478bd9Sstevel@tonic-gate 		} else {
9087c478bd9Sstevel@tonic-gate 			/* If all else fails... */
9097c478bd9Sstevel@tonic-gate 			fsname = "<unknown file system type>";
9107c478bd9Sstevel@tonic-gate 		}
9117c478bd9Sstevel@tonic-gate 
9127c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "file system '%s' version mismatch", fsname);
9137c478bd9Sstevel@tonic-gate 		return (ENXIO);
9147c478bd9Sstevel@tonic-gate 	}
9157c478bd9Sstevel@tonic-gate 
9167c478bd9Sstevel@tonic-gate 	allocated = 0;
9177c478bd9Sstevel@tonic-gate 
9187c478bd9Sstevel@tonic-gate 	WLOCK_VFSSW();
9197c478bd9Sstevel@tonic-gate 	if ((vswp = vfs_getvfsswbyname(fsname)) == NULL) {
9207c478bd9Sstevel@tonic-gate 		if ((vswp = allocate_vfssw(fsname)) == NULL) {
9217c478bd9Sstevel@tonic-gate 			WUNLOCK_VFSSW();
9227c478bd9Sstevel@tonic-gate 			/*
9237c478bd9Sstevel@tonic-gate 			 * See 1095689.  If this message appears, then
9247c478bd9Sstevel@tonic-gate 			 * we either need to make the vfssw table bigger
9257c478bd9Sstevel@tonic-gate 			 * statically, or make it grow dynamically.
9267c478bd9Sstevel@tonic-gate 			 */
9277c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN, "no room for '%s' in vfssw!", fsname);
9287c478bd9Sstevel@tonic-gate 			return (ENXIO);
9297c478bd9Sstevel@tonic-gate 		}
9307c478bd9Sstevel@tonic-gate 		allocated = 1;
9317c478bd9Sstevel@tonic-gate 	}
9327c478bd9Sstevel@tonic-gate 	ASSERT(vswp != NULL);
9337c478bd9Sstevel@tonic-gate 
9347c478bd9Sstevel@tonic-gate 	vswp->vsw_flag = modl->fs_vfsdef->flags;
9357c478bd9Sstevel@tonic-gate 	if (modl->fs_vfsdef->flags & VSW_HASPROTO) {
9367c478bd9Sstevel@tonic-gate 		vfs_mergeopttbl(&vfs_mntopts, modl->fs_vfsdef->optproto,
9377c478bd9Sstevel@tonic-gate 		    &vswp->vsw_optproto);
9387c478bd9Sstevel@tonic-gate 	} else {
9397c478bd9Sstevel@tonic-gate 		vfs_copyopttbl(&vfs_mntopts, &vswp->vsw_optproto);
9407c478bd9Sstevel@tonic-gate 	}
9417c478bd9Sstevel@tonic-gate 
9427c478bd9Sstevel@tonic-gate 	if (modl->fs_vfsdef->flags & VSW_CANRWRO) {
9437c478bd9Sstevel@tonic-gate 		/*
9447c478bd9Sstevel@tonic-gate 		 * This obviously implies VSW_CANREMOUNT.
9457c478bd9Sstevel@tonic-gate 		 */
9467c478bd9Sstevel@tonic-gate 		vswp->vsw_flag |= VSW_CANREMOUNT;
9477c478bd9Sstevel@tonic-gate 	}
9487c478bd9Sstevel@tonic-gate 	if (modl->fs_vfsdef->init == NULL)
9497c478bd9Sstevel@tonic-gate 		err = EFAULT;
9507c478bd9Sstevel@tonic-gate 	else
9517c478bd9Sstevel@tonic-gate 		err = (*(modl->fs_vfsdef->init))(vswp - vfssw, fsname);
9527c478bd9Sstevel@tonic-gate 
9537c478bd9Sstevel@tonic-gate 	if (err != 0) {
9547c478bd9Sstevel@tonic-gate 		if (allocated) {
9557c478bd9Sstevel@tonic-gate 			kmem_free(vswp->vsw_name, strlen(vswp->vsw_name)+1);
9567c478bd9Sstevel@tonic-gate 			vswp->vsw_name = "";
9577c478bd9Sstevel@tonic-gate 		}
9587c478bd9Sstevel@tonic-gate 		vswp->vsw_flag = 0;
9597c478bd9Sstevel@tonic-gate 		vswp->vsw_init = NULL;
9607c478bd9Sstevel@tonic-gate 	}
9617c478bd9Sstevel@tonic-gate 
9627c478bd9Sstevel@tonic-gate 	vfs_unrefvfssw(vswp);
9637c478bd9Sstevel@tonic-gate 	WUNLOCK_VFSSW();
9647c478bd9Sstevel@tonic-gate 
9657c478bd9Sstevel@tonic-gate 	return (err);
9667c478bd9Sstevel@tonic-gate }
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate /*
9697c478bd9Sstevel@tonic-gate  * Remove a filesystem
9707c478bd9Sstevel@tonic-gate  */
9717c478bd9Sstevel@tonic-gate static int
9727c478bd9Sstevel@tonic-gate mod_removefs(struct modlfs *modl, struct modlinkage *modlp)
9737c478bd9Sstevel@tonic-gate {
9747c478bd9Sstevel@tonic-gate 	struct vfssw *vswp;
9757c478bd9Sstevel@tonic-gate 	struct modctl *mcp;
9767c478bd9Sstevel@tonic-gate 	char *modname;
9777c478bd9Sstevel@tonic-gate 
9787c478bd9Sstevel@tonic-gate 	if (moddebug & MODDEBUG_NOAUL_FS)
9797c478bd9Sstevel@tonic-gate 		return (EBUSY);
9807c478bd9Sstevel@tonic-gate 
9817c478bd9Sstevel@tonic-gate 	WLOCK_VFSSW();
9827c478bd9Sstevel@tonic-gate 	if ((vswp = vfs_getvfsswbyname(modl->fs_vfsdef->name)) == NULL) {
9837c478bd9Sstevel@tonic-gate 		mcp = mod_getctl(modlp);
9847c478bd9Sstevel@tonic-gate 		ASSERT(mcp != NULL);
9857c478bd9Sstevel@tonic-gate 		modname = mcp->mod_modname;
9867c478bd9Sstevel@tonic-gate 		WUNLOCK_VFSSW();
9877c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, uninstall_err, modname);
9887c478bd9Sstevel@tonic-gate 		return (EINVAL);
9897c478bd9Sstevel@tonic-gate 	}
9907c478bd9Sstevel@tonic-gate 	if (vswp->vsw_count != 1) {
9917c478bd9Sstevel@tonic-gate 		vfs_unrefvfssw(vswp);
9927c478bd9Sstevel@tonic-gate 		WUNLOCK_VFSSW();
9937c478bd9Sstevel@tonic-gate 		return (EBUSY);
9947c478bd9Sstevel@tonic-gate 	}
9957c478bd9Sstevel@tonic-gate 
9967c478bd9Sstevel@tonic-gate 	/* XXX - Shouldn't the refcount be sufficient? */
9977c478bd9Sstevel@tonic-gate 
9987c478bd9Sstevel@tonic-gate 	if (vfs_opsinuse(&vswp->vsw_vfsops)) {
999d397866eSsp92102 		vfs_unrefvfssw(vswp);
10007c478bd9Sstevel@tonic-gate 		WUNLOCK_VFSSW();
10017c478bd9Sstevel@tonic-gate 		return (EBUSY);
10027c478bd9Sstevel@tonic-gate 	}
10037c478bd9Sstevel@tonic-gate 
10047c478bd9Sstevel@tonic-gate 	vfs_freeopttbl(&vswp->vsw_optproto);
10057c478bd9Sstevel@tonic-gate 	vswp->vsw_optproto.mo_count = 0;
10067c478bd9Sstevel@tonic-gate 
10077c478bd9Sstevel@tonic-gate 	vswp->vsw_flag = 0;
10087c478bd9Sstevel@tonic-gate 	vswp->vsw_init = NULL;
10097c478bd9Sstevel@tonic-gate 	vfs_unrefvfssw(vswp);
10107c478bd9Sstevel@tonic-gate 	WUNLOCK_VFSSW();
10117c478bd9Sstevel@tonic-gate 	return (0);
10127c478bd9Sstevel@tonic-gate }
10137c478bd9Sstevel@tonic-gate 
10147c478bd9Sstevel@tonic-gate /*
10157c478bd9Sstevel@tonic-gate  * Get status of a streams module.
10167c478bd9Sstevel@tonic-gate  */
10177c478bd9Sstevel@tonic-gate /*ARGSUSED*/
10187c478bd9Sstevel@tonic-gate static int
10197c478bd9Sstevel@tonic-gate mod_infostrmod(struct modlstrmod *modl, struct modlinkage *modlp, int *p0)
10207c478bd9Sstevel@tonic-gate {
10217c478bd9Sstevel@tonic-gate 	*p0 = -1;	/* no useful info */
10227c478bd9Sstevel@tonic-gate 	return (0);
10237c478bd9Sstevel@tonic-gate }
10247c478bd9Sstevel@tonic-gate 
10257c478bd9Sstevel@tonic-gate 
10267c478bd9Sstevel@tonic-gate /*
10277c478bd9Sstevel@tonic-gate  * Install a streams module.
10287c478bd9Sstevel@tonic-gate  */
10297c478bd9Sstevel@tonic-gate /*ARGSUSED*/
10307c478bd9Sstevel@tonic-gate static int
10317c478bd9Sstevel@tonic-gate mod_installstrmod(struct modlstrmod *modl, struct modlinkage *modlp)
10327c478bd9Sstevel@tonic-gate {
10337c478bd9Sstevel@tonic-gate 	struct fmodsw *fp = modl->strmod_fmodsw;
10347c478bd9Sstevel@tonic-gate 
10357c478bd9Sstevel@tonic-gate 	if (!(fp->f_flag & D_MP)) {
10367c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "mod_install: MT-unsafe strmod '%s' rejected",
10377c478bd9Sstevel@tonic-gate 		    fp->f_name);
10387c478bd9Sstevel@tonic-gate 		return (ENXIO);
10397c478bd9Sstevel@tonic-gate 	}
10407c478bd9Sstevel@tonic-gate 
10417c478bd9Sstevel@tonic-gate 	return (fmodsw_register(fp->f_name, fp->f_str, fp->f_flag));
10427c478bd9Sstevel@tonic-gate }
10437c478bd9Sstevel@tonic-gate 
10447c478bd9Sstevel@tonic-gate /*
10457c478bd9Sstevel@tonic-gate  * Remove a streams module.
10467c478bd9Sstevel@tonic-gate  */
10477c478bd9Sstevel@tonic-gate /*ARGSUSED*/
10487c478bd9Sstevel@tonic-gate static int
10497c478bd9Sstevel@tonic-gate mod_removestrmod(struct modlstrmod *modl, struct modlinkage *modlp)
10507c478bd9Sstevel@tonic-gate {
10517c478bd9Sstevel@tonic-gate 	if (moddebug & MODDEBUG_NOAUL_STR)
10527c478bd9Sstevel@tonic-gate 		return (EBUSY);
10537c478bd9Sstevel@tonic-gate 
10547c478bd9Sstevel@tonic-gate 	return (fmodsw_unregister(modl->strmod_fmodsw->f_name));
10557c478bd9Sstevel@tonic-gate }
10567c478bd9Sstevel@tonic-gate 
10577c478bd9Sstevel@tonic-gate /*
10587c478bd9Sstevel@tonic-gate  * Get status of a scheduling class module.
10597c478bd9Sstevel@tonic-gate  */
10607c478bd9Sstevel@tonic-gate /*ARGSUSED1*/
10617c478bd9Sstevel@tonic-gate static int
10627c478bd9Sstevel@tonic-gate mod_infosched(struct modlsched *modl, struct modlinkage *modlp, int *p0)
10637c478bd9Sstevel@tonic-gate {
10647c478bd9Sstevel@tonic-gate 	int	status;
10657c478bd9Sstevel@tonic-gate 	auto id_t	cid;
10667c478bd9Sstevel@tonic-gate 
10677c478bd9Sstevel@tonic-gate 	status = getcidbyname(modl->sched_class->cl_name, &cid);
10687c478bd9Sstevel@tonic-gate 
10697c478bd9Sstevel@tonic-gate 	if (status != 0)
10707c478bd9Sstevel@tonic-gate 		*p0 = -1;
10717c478bd9Sstevel@tonic-gate 	else
10727c478bd9Sstevel@tonic-gate 		*p0 = cid;
10737c478bd9Sstevel@tonic-gate 
10747c478bd9Sstevel@tonic-gate 	return (0);
10757c478bd9Sstevel@tonic-gate }
10767c478bd9Sstevel@tonic-gate 
10777c478bd9Sstevel@tonic-gate /*
10787c478bd9Sstevel@tonic-gate  * Install a scheduling class module.
10797c478bd9Sstevel@tonic-gate  */
10807c478bd9Sstevel@tonic-gate /*ARGSUSED1*/
10817c478bd9Sstevel@tonic-gate static int
10827c478bd9Sstevel@tonic-gate mod_installsched(struct modlsched *modl, struct modlinkage *modlp)
10837c478bd9Sstevel@tonic-gate {
10847c478bd9Sstevel@tonic-gate 	sclass_t *clp;
10857c478bd9Sstevel@tonic-gate 	int status;
10867c478bd9Sstevel@tonic-gate 	id_t cid;
10877c478bd9Sstevel@tonic-gate 
10887c478bd9Sstevel@tonic-gate 	/*
10897c478bd9Sstevel@tonic-gate 	 * See if module is already installed.
10907c478bd9Sstevel@tonic-gate 	 */
10917c478bd9Sstevel@tonic-gate 	mutex_enter(&class_lock);
10927c478bd9Sstevel@tonic-gate 	status = alloc_cid(modl->sched_class->cl_name, &cid);
10937c478bd9Sstevel@tonic-gate 	mutex_exit(&class_lock);
10947c478bd9Sstevel@tonic-gate 	ASSERT(status == 0);
10957c478bd9Sstevel@tonic-gate 	clp = &sclass[cid];
10967c478bd9Sstevel@tonic-gate 	rw_enter(clp->cl_lock, RW_WRITER);
10977c478bd9Sstevel@tonic-gate 	if (SCHED_INSTALLED(clp)) {
10987c478bd9Sstevel@tonic-gate 		printf("scheduling class %s is already installed\n",
10997c478bd9Sstevel@tonic-gate 			modl->sched_class->cl_name);
11007c478bd9Sstevel@tonic-gate 		rw_exit(clp->cl_lock);
11017c478bd9Sstevel@tonic-gate 		return (EBUSY);		/* it's already there */
11027c478bd9Sstevel@tonic-gate 	}
11037c478bd9Sstevel@tonic-gate 
11047c478bd9Sstevel@tonic-gate 	clp->cl_init = modl->sched_class->cl_init;
11057c478bd9Sstevel@tonic-gate 	clp->cl_funcs = modl->sched_class->cl_funcs;
11067c478bd9Sstevel@tonic-gate 	modl->sched_class = clp;
11077c478bd9Sstevel@tonic-gate 	disp_add(clp);
11087c478bd9Sstevel@tonic-gate 	loaded_classes++;		/* for priocntl system call */
11097c478bd9Sstevel@tonic-gate 	rw_exit(clp->cl_lock);
11107c478bd9Sstevel@tonic-gate 	return (0);
11117c478bd9Sstevel@tonic-gate }
11127c478bd9Sstevel@tonic-gate 
11137c478bd9Sstevel@tonic-gate /*
11147c478bd9Sstevel@tonic-gate  * Remove a scheduling class module.
11157c478bd9Sstevel@tonic-gate  *
11167c478bd9Sstevel@tonic-gate  * we only null out the init func and the class functions because
11177c478bd9Sstevel@tonic-gate  * once a class has been loaded it has that slot in the class
11187c478bd9Sstevel@tonic-gate  * array until the next reboot. We don't decrement loaded_classes
11197c478bd9Sstevel@tonic-gate  * because this keeps count of the number of classes that have
11207c478bd9Sstevel@tonic-gate  * been loaded for this session. It will have to be this way until
11217c478bd9Sstevel@tonic-gate  * we implement the class array as a linked list and do true
11227c478bd9Sstevel@tonic-gate  * dynamic allocation.
11237c478bd9Sstevel@tonic-gate  */
11247c478bd9Sstevel@tonic-gate static int
11257c478bd9Sstevel@tonic-gate mod_removesched(struct modlsched *modl, struct modlinkage *modlp)
11267c478bd9Sstevel@tonic-gate {
11277c478bd9Sstevel@tonic-gate 	int status;
11287c478bd9Sstevel@tonic-gate 	sclass_t *clp;
11297c478bd9Sstevel@tonic-gate 	struct modctl *mcp;
11307c478bd9Sstevel@tonic-gate 	char *modname;
11317c478bd9Sstevel@tonic-gate 	id_t cid;
11327c478bd9Sstevel@tonic-gate 
11337c478bd9Sstevel@tonic-gate 	status = getcidbyname(modl->sched_class->cl_name, &cid);
11347c478bd9Sstevel@tonic-gate 	if (status != 0) {
11357c478bd9Sstevel@tonic-gate 		mcp = mod_getctl(modlp);
11367c478bd9Sstevel@tonic-gate 		ASSERT(mcp != NULL);
11377c478bd9Sstevel@tonic-gate 		modname = mcp->mod_modname;
11387c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, uninstall_err, modname);
11397c478bd9Sstevel@tonic-gate 		return (EINVAL);
11407c478bd9Sstevel@tonic-gate 	}
11417c478bd9Sstevel@tonic-gate 	clp = &sclass[cid];
11427c478bd9Sstevel@tonic-gate 	if (moddebug & MODDEBUG_NOAUL_SCHED ||
11437c478bd9Sstevel@tonic-gate 	    !rw_tryenter(clp->cl_lock, RW_WRITER))
11447c478bd9Sstevel@tonic-gate 		return (EBUSY);
11457c478bd9Sstevel@tonic-gate 
11467c478bd9Sstevel@tonic-gate 	clp->cl_init = NULL;
11477c478bd9Sstevel@tonic-gate 	clp->cl_funcs = NULL;
11487c478bd9Sstevel@tonic-gate 	rw_exit(clp->cl_lock);
11497c478bd9Sstevel@tonic-gate 	return (0);
11507c478bd9Sstevel@tonic-gate }
11517c478bd9Sstevel@tonic-gate 
11527c478bd9Sstevel@tonic-gate /*
11537c478bd9Sstevel@tonic-gate  * Get status of an exec module.
11547c478bd9Sstevel@tonic-gate  */
11557c478bd9Sstevel@tonic-gate /*ARGSUSED1*/
11567c478bd9Sstevel@tonic-gate static int
11577c478bd9Sstevel@tonic-gate mod_infoexec(struct modlexec *modl, struct modlinkage *modlp, int *p0)
11587c478bd9Sstevel@tonic-gate {
11597c478bd9Sstevel@tonic-gate 	struct execsw *eswp;
11607c478bd9Sstevel@tonic-gate 
11617c478bd9Sstevel@tonic-gate 	if ((eswp = findexecsw(modl->exec_execsw->exec_magic)) == NULL)
11627c478bd9Sstevel@tonic-gate 		*p0 = -1;
11637c478bd9Sstevel@tonic-gate 	else
11647c478bd9Sstevel@tonic-gate 		*p0 = eswp - execsw;
11657c478bd9Sstevel@tonic-gate 
11667c478bd9Sstevel@tonic-gate 	return (0);
11677c478bd9Sstevel@tonic-gate }
11687c478bd9Sstevel@tonic-gate 
11697c478bd9Sstevel@tonic-gate /*
11707c478bd9Sstevel@tonic-gate  * Install an exec module.
11717c478bd9Sstevel@tonic-gate  */
11727c478bd9Sstevel@tonic-gate static int
11737c478bd9Sstevel@tonic-gate mod_installexec(struct modlexec *modl, struct modlinkage *modlp)
11747c478bd9Sstevel@tonic-gate {
11757c478bd9Sstevel@tonic-gate 	struct execsw *eswp;
11767c478bd9Sstevel@tonic-gate 	struct modctl *mcp;
11777c478bd9Sstevel@tonic-gate 	char *modname;
11787c478bd9Sstevel@tonic-gate 	char *magic;
11797c478bd9Sstevel@tonic-gate 	size_t magic_size;
11807c478bd9Sstevel@tonic-gate 
11817c478bd9Sstevel@tonic-gate 	/*
11827c478bd9Sstevel@tonic-gate 	 * See if execsw entry is already allocated.  Can't use findexectype()
11837c478bd9Sstevel@tonic-gate 	 * because we may get a recursive call to here.
11847c478bd9Sstevel@tonic-gate 	 */
11857c478bd9Sstevel@tonic-gate 
11867c478bd9Sstevel@tonic-gate 	if ((eswp = findexecsw(modl->exec_execsw->exec_magic)) == NULL) {
11877c478bd9Sstevel@tonic-gate 		mcp = mod_getctl(modlp);
11887c478bd9Sstevel@tonic-gate 		ASSERT(mcp != NULL);
11897c478bd9Sstevel@tonic-gate 		modname = mcp->mod_modname;
11907c478bd9Sstevel@tonic-gate 		magic = modl->exec_execsw->exec_magic;
11917c478bd9Sstevel@tonic-gate 		magic_size = modl->exec_execsw->exec_maglen;
11927c478bd9Sstevel@tonic-gate 		if ((eswp = allocate_execsw(modname, magic, magic_size)) ==
11937c478bd9Sstevel@tonic-gate 		    NULL) {
11947c478bd9Sstevel@tonic-gate 			printf("no unused entries in 'execsw'\n");
11957c478bd9Sstevel@tonic-gate 			return (ENOSPC);
11967c478bd9Sstevel@tonic-gate 		}
11977c478bd9Sstevel@tonic-gate 	}
11987c478bd9Sstevel@tonic-gate 	if (eswp->exec_func != NULL) {
11997c478bd9Sstevel@tonic-gate 		printf("exec type %x is already installed\n",
12007c478bd9Sstevel@tonic-gate 			*eswp->exec_magic);
12017c478bd9Sstevel@tonic-gate 			return (EBUSY);		 /* it's already there! */
12027c478bd9Sstevel@tonic-gate 	}
12037c478bd9Sstevel@tonic-gate 
12047c478bd9Sstevel@tonic-gate 	rw_enter(eswp->exec_lock, RW_WRITER);
12057c478bd9Sstevel@tonic-gate 	eswp->exec_func = modl->exec_execsw->exec_func;
12067c478bd9Sstevel@tonic-gate 	eswp->exec_core = modl->exec_execsw->exec_core;
12077c478bd9Sstevel@tonic-gate 	rw_exit(eswp->exec_lock);
12087c478bd9Sstevel@tonic-gate 
12097c478bd9Sstevel@tonic-gate 	return (0);
12107c478bd9Sstevel@tonic-gate }
12117c478bd9Sstevel@tonic-gate 
12127c478bd9Sstevel@tonic-gate /*
12137c478bd9Sstevel@tonic-gate  * Remove an exec module.
12147c478bd9Sstevel@tonic-gate  */
12157c478bd9Sstevel@tonic-gate static int
12167c478bd9Sstevel@tonic-gate mod_removeexec(struct modlexec *modl, struct modlinkage *modlp)
12177c478bd9Sstevel@tonic-gate {
12187c478bd9Sstevel@tonic-gate 	struct execsw *eswp;
12197c478bd9Sstevel@tonic-gate 	struct modctl *mcp;
12207c478bd9Sstevel@tonic-gate 	char *modname;
12217c478bd9Sstevel@tonic-gate 
12227c478bd9Sstevel@tonic-gate 	eswp = findexecsw(modl->exec_execsw->exec_magic);
12237c478bd9Sstevel@tonic-gate 	if (eswp == NULL) {
12247c478bd9Sstevel@tonic-gate 		mcp = mod_getctl(modlp);
12257c478bd9Sstevel@tonic-gate 		ASSERT(mcp != NULL);
12267c478bd9Sstevel@tonic-gate 		modname = mcp->mod_modname;
12277c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, uninstall_err, modname);
12287c478bd9Sstevel@tonic-gate 		return (EINVAL);
12297c478bd9Sstevel@tonic-gate 	}
12307c478bd9Sstevel@tonic-gate 	if (moddebug & MODDEBUG_NOAUL_EXEC ||
12317c478bd9Sstevel@tonic-gate 	    !rw_tryenter(eswp->exec_lock, RW_WRITER))
12327c478bd9Sstevel@tonic-gate 		return (EBUSY);
12337c478bd9Sstevel@tonic-gate 	eswp->exec_func = NULL;
12347c478bd9Sstevel@tonic-gate 	eswp->exec_core = NULL;
12357c478bd9Sstevel@tonic-gate 	rw_exit(eswp->exec_lock);
12367c478bd9Sstevel@tonic-gate 	return (0);
12377c478bd9Sstevel@tonic-gate }
12387c478bd9Sstevel@tonic-gate 
12397c478bd9Sstevel@tonic-gate /*
12407c478bd9Sstevel@tonic-gate  * Find a free sysent entry or check if the specified one is free.
12417c478bd9Sstevel@tonic-gate  */
12427c478bd9Sstevel@tonic-gate static struct sysent *
12437c478bd9Sstevel@tonic-gate mod_getsysent(struct modlinkage *modlp, struct sysent *se)
12447c478bd9Sstevel@tonic-gate {
12457c478bd9Sstevel@tonic-gate 	int sysnum;
12467c478bd9Sstevel@tonic-gate 	struct modctl *mcp;
12477c478bd9Sstevel@tonic-gate 	char *mod_name;
12487c478bd9Sstevel@tonic-gate 
12497c478bd9Sstevel@tonic-gate 	if ((mcp = mod_getctl(modlp)) == NULL) {
12507c478bd9Sstevel@tonic-gate 		/*
12517c478bd9Sstevel@tonic-gate 		 * This happens when we're looking up the module
12527c478bd9Sstevel@tonic-gate 		 * pointer as part of a stub installation.  So
12537c478bd9Sstevel@tonic-gate 		 * there's no need to whine at this point.
12547c478bd9Sstevel@tonic-gate 		 */
12557c478bd9Sstevel@tonic-gate 		return (NULL);
12567c478bd9Sstevel@tonic-gate 	}
12577c478bd9Sstevel@tonic-gate 
12587c478bd9Sstevel@tonic-gate 	mod_name = mcp->mod_modname;
12597c478bd9Sstevel@tonic-gate 
12607c478bd9Sstevel@tonic-gate 	if ((sysnum = mod_getsysnum(mod_name)) == -1) {
12617c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "system call missing from bind file");
12627c478bd9Sstevel@tonic-gate 		return (NULL);
12637c478bd9Sstevel@tonic-gate 	}
12647c478bd9Sstevel@tonic-gate 
12657c478bd9Sstevel@tonic-gate 	if (sysnum > 0 && sysnum < NSYSCALL &&
12667c478bd9Sstevel@tonic-gate 	    (se[sysnum].sy_flags & (SE_LOADABLE | SE_NOUNLOAD)))
12677c478bd9Sstevel@tonic-gate 		return (se + sysnum);
12687c478bd9Sstevel@tonic-gate 
12697c478bd9Sstevel@tonic-gate 	cmn_err(CE_WARN, "system call entry %d is already in use", sysnum);
12707c478bd9Sstevel@tonic-gate 	return (NULL);
12717c478bd9Sstevel@tonic-gate }
12727c478bd9Sstevel@tonic-gate 
12737c478bd9Sstevel@tonic-gate /*
12747c478bd9Sstevel@tonic-gate  * IP Policy Modules.
12757c478bd9Sstevel@tonic-gate  */
12767c478bd9Sstevel@tonic-gate /*ARGSUSED*/
12777c478bd9Sstevel@tonic-gate static int
12787c478bd9Sstevel@tonic-gate mod_infoipp(struct modlipp *modl, struct modlinkage *modlp, int *p0)
12797c478bd9Sstevel@tonic-gate {
12807c478bd9Sstevel@tonic-gate 	struct modctl *mcp = mod_getctl(modlp);
12817c478bd9Sstevel@tonic-gate 	ipp_mod_id_t mid;
12827c478bd9Sstevel@tonic-gate 
12837c478bd9Sstevel@tonic-gate 	if (mcp == NULL) {
12847c478bd9Sstevel@tonic-gate 		*p0 = -1;
12857c478bd9Sstevel@tonic-gate 		return (0);	/* module is not yet installed */
12867c478bd9Sstevel@tonic-gate 	}
12877c478bd9Sstevel@tonic-gate 
12887c478bd9Sstevel@tonic-gate 	mid = ipp_mod_lookup(mcp->mod_modname);
12897c478bd9Sstevel@tonic-gate 
12907c478bd9Sstevel@tonic-gate 	*p0 = mid;
12917c478bd9Sstevel@tonic-gate 	return (0);
12927c478bd9Sstevel@tonic-gate }
12937c478bd9Sstevel@tonic-gate 
12947c478bd9Sstevel@tonic-gate static int
12957c478bd9Sstevel@tonic-gate mod_installipp(struct modlipp *modl, struct modlinkage *modlp)
12967c478bd9Sstevel@tonic-gate {
12977c478bd9Sstevel@tonic-gate 	struct modctl *mcp = mod_getctl(modlp);
12987c478bd9Sstevel@tonic-gate 
12997c478bd9Sstevel@tonic-gate 	ASSERT(mcp != NULL);
13007c478bd9Sstevel@tonic-gate 	return (ipp_mod_register(mcp->mod_modname, modl->ipp_ops));
13017c478bd9Sstevel@tonic-gate }
13027c478bd9Sstevel@tonic-gate 
13037c478bd9Sstevel@tonic-gate /*ARGSUSED*/
13047c478bd9Sstevel@tonic-gate static int
13057c478bd9Sstevel@tonic-gate mod_removeipp(struct modlipp *modl, struct modlinkage *modlp)
13067c478bd9Sstevel@tonic-gate {
13077c478bd9Sstevel@tonic-gate 	struct modctl *mcp = mod_getctl(modlp);
13087c478bd9Sstevel@tonic-gate 	extern kthread_id_t mod_aul_thread;
13097c478bd9Sstevel@tonic-gate 	ipp_mod_id_t mid;
13107c478bd9Sstevel@tonic-gate 
13117c478bd9Sstevel@tonic-gate 	ASSERT(mcp != NULL);
13127c478bd9Sstevel@tonic-gate 
13137c478bd9Sstevel@tonic-gate 	if ((moddebug & MODDEBUG_NOAUL_IPP) && (mod_aul_thread == curthread))
13147c478bd9Sstevel@tonic-gate 		return (EBUSY);
13157c478bd9Sstevel@tonic-gate 
13167c478bd9Sstevel@tonic-gate 	mid = ipp_mod_lookup(mcp->mod_modname);
13177c478bd9Sstevel@tonic-gate 	ASSERT(mid != IPP_MOD_INVAL);
13187c478bd9Sstevel@tonic-gate 
13197c478bd9Sstevel@tonic-gate 	return (ipp_mod_unregister(mid));
13207c478bd9Sstevel@tonic-gate }
1321