17aec1d6eScindi /*
27aec1d6eScindi  * CDDL HEADER START
37aec1d6eScindi  *
47aec1d6eScindi  * The contents of this file are subject to the terms of the
5724365f7Ssethg  * Common Development and Distribution License (the "License").
6724365f7Ssethg  * You may not use this file except in compliance with the License.
77aec1d6eScindi  *
87aec1d6eScindi  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97aec1d6eScindi  * or http://www.opensolaris.org/os/licensing.
107aec1d6eScindi  * See the License for the specific language governing permissions
117aec1d6eScindi  * and limitations under the License.
127aec1d6eScindi  *
137aec1d6eScindi  * When distributing Covered Code, include this CDDL HEADER in each
147aec1d6eScindi  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157aec1d6eScindi  * If applicable, add the following below this CDDL HEADER, with the
167aec1d6eScindi  * fields enclosed by brackets "[]" replaced with your own identifying
177aec1d6eScindi  * information: Portions Copyright [yyyy] [name of copyright owner]
187aec1d6eScindi  *
197aec1d6eScindi  * CDDL HEADER END
207aec1d6eScindi  */
2153f3aea0SRoger A. Faulkner 
227aec1d6eScindi /*
2353f3aea0SRoger A. Faulkner  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
247aec1d6eScindi  * Use is subject to license terms.
257aec1d6eScindi  */
26*1e95bfe1SRob Johnston /*
27*1e95bfe1SRob Johnston  * Copyright (c) 2019, Joyent, Inc. All rights reserved.
28*1e95bfe1SRob Johnston  */
297aec1d6eScindi 
307aec1d6eScindi #include <signal.h>
317aec1d6eScindi #include <dirent.h>
327aec1d6eScindi #include <limits.h>
337aec1d6eScindi #include <alloca.h>
347aec1d6eScindi #include <unistd.h>
357aec1d6eScindi #include <stdio.h>
367aec1d6eScindi #include <pthread.h>
3753f3aea0SRoger A. Faulkner #include <synch.h>
387aec1d6eScindi #include <errno.h>
397aec1d6eScindi #include <strings.h>
407aec1d6eScindi #include <assert.h>
417aec1d6eScindi #include <sys/nvpair.h>
427aec1d6eScindi 
437aec1d6eScindi #include <topo_string.h>
447aec1d6eScindi #include <topo_alloc.h>
457aec1d6eScindi #include <topo_module.h>
467aec1d6eScindi #include <topo_error.h>
477aec1d6eScindi #include <topo_subr.h>
487aec1d6eScindi 
497aec1d6eScindi extern nv_alloc_ops_t topo_nv_alloc_ops;
507aec1d6eScindi 
517aec1d6eScindi void
topo_mod_release(topo_mod_t * mod,tnode_t * node)527aec1d6eScindi topo_mod_release(topo_mod_t *mod, tnode_t *node)
537aec1d6eScindi {
547aec1d6eScindi 	topo_mod_enter(mod);
557aec1d6eScindi 
560eb822a1Scindi 	if (mod->tm_info->tmi_ops->tmo_release != NULL)
570eb822a1Scindi 		mod->tm_info->tmi_ops->tmo_release(mod, node);
587aec1d6eScindi 
597aec1d6eScindi 	topo_mod_exit(mod);
607aec1d6eScindi }
617aec1d6eScindi 
627aec1d6eScindi void
topo_mod_hold(topo_mod_t * mod)637aec1d6eScindi topo_mod_hold(topo_mod_t *mod)
647aec1d6eScindi {
657aec1d6eScindi 	(void) pthread_mutex_lock(&mod->tm_lock);
667aec1d6eScindi 	mod->tm_refs++;
677aec1d6eScindi 	assert(mod->tm_refs != 0);
687aec1d6eScindi 	(void) pthread_mutex_unlock(&mod->tm_lock);
697aec1d6eScindi }
707aec1d6eScindi 
717aec1d6eScindi void
topo_mod_rele(topo_mod_t * mod)727aec1d6eScindi topo_mod_rele(topo_mod_t *mod)
737aec1d6eScindi {
747aec1d6eScindi 	assert(mod->tm_refs != 0);
757aec1d6eScindi 
767aec1d6eScindi 	(void) pthread_mutex_lock(&mod->tm_lock);
777aec1d6eScindi 
787aec1d6eScindi 	/*
797aec1d6eScindi 	 * Lazy unload module
807aec1d6eScindi 	 */
817aec1d6eScindi 	if (--mod->tm_refs == 0)
827aec1d6eScindi 		topo_modhash_unload(mod);
837aec1d6eScindi 	else
847aec1d6eScindi 		(void) pthread_mutex_unlock(&mod->tm_lock);
857aec1d6eScindi }
867aec1d6eScindi 
877aec1d6eScindi void
topo_mod_enter(topo_mod_t * mod)887aec1d6eScindi topo_mod_enter(topo_mod_t *mod)
897aec1d6eScindi {
907aec1d6eScindi 	(void) pthread_mutex_lock(&mod->tm_lock);
917aec1d6eScindi 
927aec1d6eScindi 	while (mod->tm_busy != 0)
937aec1d6eScindi 		(void) pthread_cond_wait(&mod->tm_cv, &mod->tm_lock);
947aec1d6eScindi 
957aec1d6eScindi 	++mod->tm_busy;
967aec1d6eScindi 
977aec1d6eScindi 	(void) pthread_mutex_unlock(&mod->tm_lock);
987aec1d6eScindi }
997aec1d6eScindi 
1007aec1d6eScindi void
topo_mod_exit(topo_mod_t * mod)1017aec1d6eScindi topo_mod_exit(topo_mod_t *mod)
1027aec1d6eScindi {
1037aec1d6eScindi 	(void) pthread_mutex_lock(&mod->tm_lock);
1047aec1d6eScindi 	--mod->tm_busy;
1057aec1d6eScindi 
1067aec1d6eScindi 	assert(mod->tm_busy == 0);
1077aec1d6eScindi 
1087aec1d6eScindi 	(void) pthread_cond_broadcast(&mod->tm_cv);
1097aec1d6eScindi 	(void) pthread_mutex_unlock(&mod->tm_lock);
1107aec1d6eScindi }
1117aec1d6eScindi 
1127aec1d6eScindi static void
topo_modhash_lock(topo_modhash_t * mhp)1137aec1d6eScindi topo_modhash_lock(topo_modhash_t *mhp)
1147aec1d6eScindi {
1157aec1d6eScindi 	(void) pthread_mutex_lock(&mhp->mh_lock);
1167aec1d6eScindi }
1177aec1d6eScindi 
1187aec1d6eScindi static void
topo_modhash_unlock(topo_modhash_t * mhp)1197aec1d6eScindi topo_modhash_unlock(topo_modhash_t *mhp)
1207aec1d6eScindi {
1217aec1d6eScindi 	(void) pthread_mutex_unlock(&mhp->mh_lock);
1227aec1d6eScindi }
1237aec1d6eScindi 
1247aec1d6eScindi static void
topo_mod_stop(topo_mod_t * mod)1257aec1d6eScindi topo_mod_stop(topo_mod_t *mod)
1267aec1d6eScindi {
1277aec1d6eScindi 	if (mod->tm_flags & TOPO_MOD_INIT) {
128*1e95bfe1SRob Johnston 		(void) mod->tm_mops->mop_fini(mod);
1297aec1d6eScindi 		if (mod->tm_flags & TOPO_MOD_REG)
1307aec1d6eScindi 			topo_mod_unregister(mod);
1317aec1d6eScindi 	}
1327aec1d6eScindi 
1337aec1d6eScindi 	mod->tm_flags = TOPO_MOD_FINI;
1347aec1d6eScindi 
1350eb822a1Scindi 	topo_dprintf(mod->tm_hdl, TOPO_DBG_MODSVC,
1360eb822a1Scindi 	    "module %s stopped\n", mod->tm_name);
1377aec1d6eScindi }
1387aec1d6eScindi 
1397aec1d6eScindi static int
topo_mod_start(topo_mod_t * mod,topo_version_t version)1400eb822a1Scindi topo_mod_start(topo_mod_t *mod, topo_version_t version)
1417aec1d6eScindi {
1420eb822a1Scindi 	topo_dprintf(mod->tm_hdl, TOPO_DBG_MODSVC,
1430eb822a1Scindi 	    "starting module %s\n", mod->tm_name);
1447aec1d6eScindi 
1450eb822a1Scindi 	if (mod->tm_mops->mop_init(mod, version) != 0) {
1460eb822a1Scindi 		if (mod->tm_errno == 0)
1470eb822a1Scindi 			mod->tm_errno = ETOPO_MOD_INIT;
1480eb822a1Scindi 		topo_dprintf(mod->tm_hdl, TOPO_DBG_ERR,
1497aec1d6eScindi 		    "module %s failed to initialize: %s\n", mod->tm_name,
1507aec1d6eScindi 		    topo_strerror(mod->tm_errno));
1517aec1d6eScindi 		return (-1);
1527aec1d6eScindi 	}
1537aec1d6eScindi 
1547aec1d6eScindi 	mod->tm_flags |= TOPO_MOD_INIT;
1557aec1d6eScindi 
1567aec1d6eScindi 	if (!(mod->tm_flags & TOPO_MOD_REG)) {
1570eb822a1Scindi 		topo_dprintf(mod->tm_hdl, TOPO_DBG_ERR,
1587aec1d6eScindi 		    "module %s failed to register\n", mod->tm_name);
1597aec1d6eScindi 		mod->tm_errno = ETOPO_MOD_NOREG;
1607aec1d6eScindi 		topo_mod_stop(mod);
1617aec1d6eScindi 		return (-1);
1627aec1d6eScindi 	}
1637aec1d6eScindi 
1647aec1d6eScindi 	return (0);
1657aec1d6eScindi }
1667aec1d6eScindi 
1677aec1d6eScindi topo_mod_t *
topo_mod_lookup(topo_hdl_t * thp,const char * name,int bump)1680eb822a1Scindi topo_mod_lookup(topo_hdl_t *thp, const char *name, int bump)
1697aec1d6eScindi {
1707aec1d6eScindi 	topo_mod_t *mod;
1717aec1d6eScindi 	topo_modhash_t *mhp = thp->th_modhash;
1727aec1d6eScindi 
1737aec1d6eScindi 	topo_modhash_lock(mhp);
1747aec1d6eScindi 	mod = topo_modhash_lookup(mhp, name);
1750eb822a1Scindi 	if (mod != NULL && bump != 0)
1760eb822a1Scindi 		topo_mod_hold(mod);
1777aec1d6eScindi 	topo_modhash_unlock(mhp);
1787aec1d6eScindi 
1797aec1d6eScindi 	return (mod);
1807aec1d6eScindi }
1817aec1d6eScindi 
1827aec1d6eScindi static void
topo_mod_destroy(topo_mod_t * mod)1837aec1d6eScindi topo_mod_destroy(topo_mod_t *mod)
1847aec1d6eScindi {
185*1e95bfe1SRob Johnston 	topo_hdl_t *thp;
1867aec1d6eScindi 
1877aec1d6eScindi 	if (mod == NULL)
1887aec1d6eScindi 		return;
1897aec1d6eScindi 
190*1e95bfe1SRob Johnston 	thp = mod->tm_hdl;
191*1e95bfe1SRob Johnston 
1927aec1d6eScindi 	assert(mod->tm_refs == 0);
19353f3aea0SRoger A. Faulkner 	assert(!MUTEX_HELD(&mod->tm_lock));
1947aec1d6eScindi 
1957aec1d6eScindi 	if (mod->tm_name != NULL)
1967aec1d6eScindi 		topo_hdl_strfree(thp, mod->tm_name);
1977aec1d6eScindi 	if (mod->tm_path != NULL)
1987aec1d6eScindi 		topo_hdl_strfree(thp, mod->tm_path);
1997aec1d6eScindi 	if (mod->tm_rootdir != NULL)
2007aec1d6eScindi 		topo_hdl_strfree(thp, mod->tm_rootdir);
2017aec1d6eScindi 
2027aec1d6eScindi 	topo_hdl_free(thp, mod, sizeof (topo_mod_t));
2037aec1d6eScindi }
2047aec1d6eScindi 
2057aec1d6eScindi static topo_mod_t *
set_create_error(topo_hdl_t * thp,topo_mod_t * mod,const char * path,int err)2067aec1d6eScindi set_create_error(topo_hdl_t *thp, topo_mod_t *mod, const char *path, int err)
2077aec1d6eScindi {
20812cc75c8Scindi 	if (path != NULL)
20912cc75c8Scindi 		topo_dprintf(thp, TOPO_DBG_ERR, "unable to load module %s: "
21012cc75c8Scindi 		    "%s\n", path, topo_strerror(err));
21112cc75c8Scindi 	else
21212cc75c8Scindi 		topo_dprintf(thp, TOPO_DBG_ERR, "unable to load module: "
21312cc75c8Scindi 		    "%s\n", topo_strerror(err));
2147aec1d6eScindi 
2157aec1d6eScindi 	if (mod != NULL)
2167aec1d6eScindi 		topo_mod_destroy(mod);
2177aec1d6eScindi 
2187aec1d6eScindi 	(void) topo_hdl_seterrno(thp, err);
2197aec1d6eScindi 
2207aec1d6eScindi 	return (NULL);
2217aec1d6eScindi }
2227aec1d6eScindi 
2237aec1d6eScindi static topo_mod_t *
topo_mod_create(topo_hdl_t * thp,const char * name,const char * path,const topo_imodops_t * ops,topo_version_t version)2247aec1d6eScindi topo_mod_create(topo_hdl_t *thp, const char *name, const char *path,
2250eb822a1Scindi     const topo_imodops_t *ops, topo_version_t version)
2267aec1d6eScindi {
2277aec1d6eScindi 	topo_mod_t *mod;
2287aec1d6eScindi 
2297aec1d6eScindi 	if (topo_modhash_lookup(thp->th_modhash, name) != NULL)
2307aec1d6eScindi 		return (set_create_error(thp, NULL, path, ETOPO_MOD_LOADED));
2317aec1d6eScindi 
2327aec1d6eScindi 	if ((mod = topo_hdl_zalloc(thp, sizeof (topo_mod_t))) == NULL)
2337aec1d6eScindi 		return (set_create_error(thp, mod, path, ETOPO_NOMEM));
2347aec1d6eScindi 
235c40d7343Scindi 	mod->tm_hdl = thp;
236c40d7343Scindi 
2377aec1d6eScindi 	(void) pthread_mutex_init(&mod->tm_lock, NULL);
2387aec1d6eScindi 
2397aec1d6eScindi 	mod->tm_name = topo_hdl_strdup(thp, name);
2400eb822a1Scindi 	if (path != NULL)
2410eb822a1Scindi 		mod->tm_path = topo_hdl_strdup(thp, path);
2427aec1d6eScindi 	mod->tm_rootdir = topo_hdl_strdup(thp, thp->th_rootdir);
2430eb822a1Scindi 	if (mod->tm_name == NULL || mod->tm_rootdir == NULL)
2447aec1d6eScindi 		return (set_create_error(thp, mod, path, ETOPO_NOMEM));
2457aec1d6eScindi 
2460eb822a1Scindi 	mod->tm_mops = (topo_imodops_t *)ops;
2477aec1d6eScindi 	mod->tm_alloc = thp->th_alloc;
2487aec1d6eScindi 
2497aec1d6eScindi 	/*
2507aec1d6eScindi 	 * Module will be held upon a successful return from topo_mod_start()
2517aec1d6eScindi 	 */
2520eb822a1Scindi 	if ((topo_mod_start(mod, version)) < 0)
2537aec1d6eScindi 		return (set_create_error(thp, mod, path, mod->tm_errno));
2547aec1d6eScindi 
2550eb822a1Scindi 	topo_dprintf(thp, TOPO_DBG_MODSVC, "loaded module %s\n", mod->tm_name);
2567aec1d6eScindi 
2577aec1d6eScindi 	return (mod);
2587aec1d6eScindi }
2597aec1d6eScindi 
2607aec1d6eScindi topo_modhash_t *
topo_modhash_create(topo_hdl_t * thp)2617aec1d6eScindi topo_modhash_create(topo_hdl_t *thp)
2627aec1d6eScindi {
2637aec1d6eScindi 	topo_modhash_t *mhp;
2647aec1d6eScindi 
2657aec1d6eScindi 	if ((mhp = topo_hdl_zalloc(thp, sizeof (topo_modhash_t))) == NULL)
2667aec1d6eScindi 		return (NULL);
2677aec1d6eScindi 
2687aec1d6eScindi 	mhp->mh_hashlen = TOPO_HASH_BUCKETS;
2697aec1d6eScindi 	if ((mhp->mh_hash = topo_hdl_zalloc(thp,
2707aec1d6eScindi 	    sizeof (void *) * mhp->mh_hashlen)) == NULL) {
2717aec1d6eScindi 		topo_hdl_free(thp, mhp, sizeof (topo_modhash_t));
2727aec1d6eScindi 		return (NULL);
2737aec1d6eScindi 	}
2747aec1d6eScindi 	mhp->mh_nelems = 0;
2757aec1d6eScindi 	(void) pthread_mutex_init(&mhp->mh_lock, NULL);
2767aec1d6eScindi 
2777aec1d6eScindi 	thp->th_modhash = mhp;
2787aec1d6eScindi 
2797aec1d6eScindi 	return (mhp);
2807aec1d6eScindi }
2817aec1d6eScindi 
2827aec1d6eScindi void
topo_modhash_destroy(topo_hdl_t * thp)2837aec1d6eScindi topo_modhash_destroy(topo_hdl_t *thp)
2847aec1d6eScindi {
2857aec1d6eScindi 	topo_modhash_t *mhp = thp->th_modhash;
2867aec1d6eScindi 
2877aec1d6eScindi 	if (mhp == NULL)
2887aec1d6eScindi 		return;
2897aec1d6eScindi 
2907aec1d6eScindi 	assert(mhp->mh_nelems == 0);
2917aec1d6eScindi 
2927aec1d6eScindi 	topo_hdl_free(thp, mhp->mh_hash, sizeof (void *) * mhp->mh_hashlen);
2937aec1d6eScindi 	topo_hdl_free(thp, mhp, sizeof (topo_modhash_t));
2947aec1d6eScindi 	thp->th_modhash = NULL;
2957aec1d6eScindi }
2967aec1d6eScindi 
2977aec1d6eScindi topo_mod_t *
topo_modhash_lookup(topo_modhash_t * mhp,const char * name)2987aec1d6eScindi topo_modhash_lookup(topo_modhash_t *mhp, const char *name)
2997aec1d6eScindi {
3007aec1d6eScindi 	topo_mod_t *mod = NULL;
3017aec1d6eScindi 	uint_t h;
3027aec1d6eScindi 
3037aec1d6eScindi 	h = topo_strhash(name) % mhp->mh_hashlen;
3047aec1d6eScindi 
3057aec1d6eScindi 	for (mod = mhp->mh_hash[h]; mod != NULL; mod = mod->tm_next) {
3067aec1d6eScindi 		if (strcmp(name, mod->tm_name) == 0)
3077aec1d6eScindi 			break;
3087aec1d6eScindi 	}
3097aec1d6eScindi 
3107aec1d6eScindi 	return (mod);
3117aec1d6eScindi }
3127aec1d6eScindi 
3137aec1d6eScindi topo_mod_t *
topo_modhash_load(topo_hdl_t * thp,const char * name,const char * path,const topo_imodops_t * ops,topo_version_t version)3140eb822a1Scindi topo_modhash_load(topo_hdl_t *thp, const char *name, const char *path,
3150eb822a1Scindi     const topo_imodops_t *ops, topo_version_t version)
3167aec1d6eScindi {
3177aec1d6eScindi 	topo_modhash_t *mhp = thp->th_modhash;
3187aec1d6eScindi 	topo_mod_t *mod;
3197aec1d6eScindi 	uint_t h;
3207aec1d6eScindi 
3217aec1d6eScindi 	topo_modhash_lock(mhp);
3227aec1d6eScindi 
3230eb822a1Scindi 	if ((mod = topo_mod_create(thp, name, path, ops, version)) == NULL) {
324724365f7Ssethg 		topo_modhash_unlock(mhp);
3257aec1d6eScindi 		return (NULL); /* th_errno set */
3267aec1d6eScindi 	}
3277aec1d6eScindi 
3287aec1d6eScindi 	topo_mod_hold(mod);
3297aec1d6eScindi 
3307aec1d6eScindi 	h = topo_strhash(name) % mhp->mh_hashlen;
3317aec1d6eScindi 	mod->tm_next = mhp->mh_hash[h];
3327aec1d6eScindi 	mhp->mh_hash[h] = mod;
3337aec1d6eScindi 	mhp->mh_nelems++;
3347aec1d6eScindi 	topo_modhash_unlock(mhp);
3357aec1d6eScindi 
3367aec1d6eScindi 	return (mod);
3377aec1d6eScindi }
3387aec1d6eScindi 
3397aec1d6eScindi void
topo_modhash_unload(topo_mod_t * mod)3407aec1d6eScindi topo_modhash_unload(topo_mod_t *mod)
3417aec1d6eScindi {
3427aec1d6eScindi 	uint_t h;
3437aec1d6eScindi 	topo_mod_t **pp, *mp;
3447aec1d6eScindi 	topo_hdl_t *thp = mod->tm_hdl;
3457aec1d6eScindi 	topo_modhash_t *mhp;
3467aec1d6eScindi 
34753f3aea0SRoger A. Faulkner 	assert(MUTEX_HELD(&mod->tm_lock));
3487aec1d6eScindi 	assert(mod->tm_busy == 0);
3497aec1d6eScindi 
3507aec1d6eScindi 	mhp = thp->th_modhash;
3517aec1d6eScindi 	topo_modhash_lock(mhp);
3527aec1d6eScindi 
3537aec1d6eScindi 	assert(mhp != NULL);
3547aec1d6eScindi 
3557aec1d6eScindi 	h = topo_strhash(mod->tm_name) % mhp->mh_hashlen;
3567aec1d6eScindi 	pp = &mhp->mh_hash[h];
3577aec1d6eScindi 
3587aec1d6eScindi 	for (mp = *pp; mp != NULL; mp = mp->tm_next) {
3597aec1d6eScindi 		if (mp == mod)
3607aec1d6eScindi 			break;
3617aec1d6eScindi 		else
3627aec1d6eScindi 			pp = &mp->tm_next;
3637aec1d6eScindi 	}
3647aec1d6eScindi 
3657aec1d6eScindi 	if (mp != NULL) {
3667aec1d6eScindi 		*pp = mod->tm_next;
3677aec1d6eScindi 
3687aec1d6eScindi 		assert(mhp->mh_nelems != 0);
3697aec1d6eScindi 
3707aec1d6eScindi 		mhp->mh_nelems--;
3717aec1d6eScindi 
3727aec1d6eScindi 	}
3737aec1d6eScindi 	topo_modhash_unlock(mhp);
3747aec1d6eScindi 
3757aec1d6eScindi 	(void) pthread_mutex_unlock(&mod->tm_lock);
3767aec1d6eScindi 
3777aec1d6eScindi 	topo_mod_stop(mod);
3787aec1d6eScindi 	topo_mod_destroy(mod);
3797aec1d6eScindi 
3807aec1d6eScindi }
3817aec1d6eScindi 
3827aec1d6eScindi void
topo_modhash_unload_all(topo_hdl_t * thp)3837aec1d6eScindi topo_modhash_unload_all(topo_hdl_t *thp)
3847aec1d6eScindi {
3857aec1d6eScindi 	int i;
3867aec1d6eScindi 	topo_modhash_t *mhp = thp->th_modhash;
3877aec1d6eScindi 	topo_mod_t *mp, **pp;
3887aec1d6eScindi 
389c40d7343Scindi 	if (mhp == NULL)
390c40d7343Scindi 		return;
391c40d7343Scindi 
3927aec1d6eScindi 	topo_modhash_lock(mhp);
3937aec1d6eScindi 	for (i = 0; i < TOPO_HASH_BUCKETS; ++i) {
3947aec1d6eScindi 		pp = &mhp->mh_hash[i];
3957aec1d6eScindi 		mp = *pp;
3967aec1d6eScindi 		while (mp != NULL) {
3977aec1d6eScindi 			topo_mod_stop(mp);
3987aec1d6eScindi 
3990eb822a1Scindi 			/*
4000eb822a1Scindi 			 * At this point we are forcing all modules to
4010eb822a1Scindi 			 * stop, ignore any remaining module reference counts.
4020eb822a1Scindi 			 */
4030eb822a1Scindi 			mp->tm_refs = 0;
4047aec1d6eScindi 
4057aec1d6eScindi 			*pp = mp->tm_next;
4067aec1d6eScindi 			topo_mod_destroy(mp);
4077aec1d6eScindi 			mp = *pp;
4087aec1d6eScindi 
4097aec1d6eScindi 			--mhp->mh_nelems;
4107aec1d6eScindi 		}
4117aec1d6eScindi 	}
4127aec1d6eScindi 	topo_modhash_unlock(mhp);
4137aec1d6eScindi }
414