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 552cac543Sramat * Common Development and Distribution License (the "License"). 652cac543Sramat * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 227730e2acScg13442 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <sys/param.h> 297c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 307c478bd9Sstevel@tonic-gate #include <sys/modhash.h> 317c478bd9Sstevel@tonic-gate #include <sys/open.h> 327c478bd9Sstevel@tonic-gate #include <sys/conf.h> 337c478bd9Sstevel@tonic-gate #include <sys/errno.h> 347c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 357c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 367c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 377c478bd9Sstevel@tonic-gate #include <sys/stat.h> 387c478bd9Sstevel@tonic-gate #include <sys/mode.h> 397c478bd9Sstevel@tonic-gate #include <sys/pathname.h> 407c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 417c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 427c478bd9Sstevel@tonic-gate #include <sys/ddi_implfuncs.h> 437c478bd9Sstevel@tonic-gate #include <sys/esunddi.h> 447c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 457c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 467c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h> 477c478bd9Sstevel@tonic-gate #include <sys/hwconf.h> 487c478bd9Sstevel@tonic-gate #include <sys/file.h> 497c478bd9Sstevel@tonic-gate #include <sys/varargs.h> 507c478bd9Sstevel@tonic-gate #include <sys/thread.h> 517c478bd9Sstevel@tonic-gate #include <sys/cred.h> 527c478bd9Sstevel@tonic-gate #include <sys/autoconf.h> 537c478bd9Sstevel@tonic-gate #include <sys/kobj.h> 547c478bd9Sstevel@tonic-gate #include <sys/consdev.h> 557c478bd9Sstevel@tonic-gate #include <sys/systm.h> 567c478bd9Sstevel@tonic-gate #include <sys/debug.h> 577c478bd9Sstevel@tonic-gate #include <sys/atomic.h> 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate extern struct dev_ops nodev_ops; 607c478bd9Sstevel@tonic-gate extern struct dev_ops mod_nodev_ops; 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate struct mod_noload { 637c478bd9Sstevel@tonic-gate struct mod_noload *mn_next; 647c478bd9Sstevel@tonic-gate char *mn_name; 657c478bd9Sstevel@tonic-gate }; 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate /* 687c478bd9Sstevel@tonic-gate * Function prototypes 697c478bd9Sstevel@tonic-gate */ 707c478bd9Sstevel@tonic-gate static int init_stubs(struct modctl *, struct mod_modinfo *); 717c478bd9Sstevel@tonic-gate static int nm_hash(char *); 727c478bd9Sstevel@tonic-gate static void make_syscallname(char *, int); 737c478bd9Sstevel@tonic-gate static void hwc_hash_init(); 747c478bd9Sstevel@tonic-gate static void hwc_hash(struct hwc_spec *, major_t); 757c478bd9Sstevel@tonic-gate static void hwc_unhash(struct hwc_spec *); 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate struct dev_ops * 787c478bd9Sstevel@tonic-gate mod_hold_dev_by_major(major_t major) 797c478bd9Sstevel@tonic-gate { 807c478bd9Sstevel@tonic-gate struct dev_ops **devopspp, *ops; 817c478bd9Sstevel@tonic-gate int loaded; 827c478bd9Sstevel@tonic-gate char *drvname; 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate if (major >= devcnt) 857c478bd9Sstevel@tonic-gate return (NULL); 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate LOCK_DEV_OPS(&(devnamesp[major].dn_lock)); 887c478bd9Sstevel@tonic-gate devopspp = &devopsp[major]; 897c478bd9Sstevel@tonic-gate loaded = 1; 907c478bd9Sstevel@tonic-gate while (loaded && !CB_DRV_INSTALLED(*devopspp)) { 917c478bd9Sstevel@tonic-gate UNLOCK_DEV_OPS(&(devnamesp[major].dn_lock)); 927c478bd9Sstevel@tonic-gate drvname = mod_major_to_name(major); 937c478bd9Sstevel@tonic-gate if (drvname == NULL) 947c478bd9Sstevel@tonic-gate return (NULL); 957c478bd9Sstevel@tonic-gate loaded = (modload("drv", drvname) != -1); 967c478bd9Sstevel@tonic-gate LOCK_DEV_OPS(&(devnamesp[major].dn_lock)); 977c478bd9Sstevel@tonic-gate } 987c478bd9Sstevel@tonic-gate if (loaded) { 997c478bd9Sstevel@tonic-gate INCR_DEV_OPS_REF(*devopspp); 1007c478bd9Sstevel@tonic-gate ops = *devopspp; 1017c478bd9Sstevel@tonic-gate } else { 1027c478bd9Sstevel@tonic-gate ops = NULL; 1037c478bd9Sstevel@tonic-gate } 1047c478bd9Sstevel@tonic-gate UNLOCK_DEV_OPS(&(devnamesp[major].dn_lock)); 1057c478bd9Sstevel@tonic-gate return (ops); 1067c478bd9Sstevel@tonic-gate } 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate #ifdef DEBUG_RELE 1097c478bd9Sstevel@tonic-gate static int mod_rele_pause = DEBUG_RELE; 1107c478bd9Sstevel@tonic-gate #endif /* DEBUG_RELE */ 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate void 1137c478bd9Sstevel@tonic-gate mod_rele_dev_by_major(major_t major) 1147c478bd9Sstevel@tonic-gate { 1157c478bd9Sstevel@tonic-gate struct dev_ops *ops; 1167c478bd9Sstevel@tonic-gate struct devnames *dnp; 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate if (major >= devcnt) 1197c478bd9Sstevel@tonic-gate return; 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate dnp = &devnamesp[major]; 1227c478bd9Sstevel@tonic-gate LOCK_DEV_OPS(&dnp->dn_lock); 1237c478bd9Sstevel@tonic-gate ops = devopsp[major]; 1247c478bd9Sstevel@tonic-gate ASSERT(CB_DRV_INSTALLED(ops)); 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate #ifdef DEBUG_RELE 1277c478bd9Sstevel@tonic-gate if (!DEV_OPS_HELD(ops)) { 1287c478bd9Sstevel@tonic-gate char *s; 1297c478bd9Sstevel@tonic-gate static char *msg = "mod_rele_dev_by_major: unheld driver!"; 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate printf("mod_rele_dev_by_major: Major dev <%u>, name <%s>\n", 1327c478bd9Sstevel@tonic-gate (uint_t)major, 1337c478bd9Sstevel@tonic-gate (s = mod_major_to_name(major)) ? s : "unknown"); 1347c478bd9Sstevel@tonic-gate if (mod_rele_pause) 1357c478bd9Sstevel@tonic-gate debug_enter(msg); 1367c478bd9Sstevel@tonic-gate else 1377c478bd9Sstevel@tonic-gate printf("%s\n", msg); 1387c478bd9Sstevel@tonic-gate UNLOCK_DEV_OPS(&dnp->dn_lock); 1397c478bd9Sstevel@tonic-gate return; /* XXX: Note changed behavior */ 1407c478bd9Sstevel@tonic-gate } 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate #endif /* DEBUG_RELE */ 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate if (!DEV_OPS_HELD(ops)) { 1457c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, 1467c478bd9Sstevel@tonic-gate "mod_rele_dev_by_major: Unheld driver: major number <%u>", 1477c478bd9Sstevel@tonic-gate (uint_t)major); 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate DECR_DEV_OPS_REF(ops); 1507c478bd9Sstevel@tonic-gate UNLOCK_DEV_OPS(&dnp->dn_lock); 1517c478bd9Sstevel@tonic-gate } 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate struct dev_ops * 1547c478bd9Sstevel@tonic-gate mod_hold_dev_by_devi(dev_info_t *devi) 1557c478bd9Sstevel@tonic-gate { 1567c478bd9Sstevel@tonic-gate major_t major; 1577c478bd9Sstevel@tonic-gate char *name; 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate name = ddi_get_name(devi); 160*a204de77Scth if ((major = mod_name_to_major(name)) == DDI_MAJOR_T_NONE) 1617c478bd9Sstevel@tonic-gate return (NULL); 1627c478bd9Sstevel@tonic-gate return (mod_hold_dev_by_major(major)); 1637c478bd9Sstevel@tonic-gate } 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate void 1667c478bd9Sstevel@tonic-gate mod_rele_dev_by_devi(dev_info_t *devi) 1677c478bd9Sstevel@tonic-gate { 1687c478bd9Sstevel@tonic-gate major_t major; 1697c478bd9Sstevel@tonic-gate char *name; 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate name = ddi_get_name(devi); 172*a204de77Scth if ((major = mod_name_to_major(name)) == DDI_MAJOR_T_NONE) 1737c478bd9Sstevel@tonic-gate return; 1747c478bd9Sstevel@tonic-gate mod_rele_dev_by_major(major); 1757c478bd9Sstevel@tonic-gate } 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate int 1787c478bd9Sstevel@tonic-gate nomod_zero() 1797c478bd9Sstevel@tonic-gate { 1807c478bd9Sstevel@tonic-gate return (0); 1817c478bd9Sstevel@tonic-gate } 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate int 1847c478bd9Sstevel@tonic-gate nomod_minus_one() 1857c478bd9Sstevel@tonic-gate { 1867c478bd9Sstevel@tonic-gate return (-1); 1877c478bd9Sstevel@tonic-gate } 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate int 1907c478bd9Sstevel@tonic-gate nomod_einval() 1917c478bd9Sstevel@tonic-gate { 1927c478bd9Sstevel@tonic-gate return (EINVAL); 1937c478bd9Sstevel@tonic-gate } 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate void 1967c478bd9Sstevel@tonic-gate nomod_void() 1977c478bd9Sstevel@tonic-gate { 1987c478bd9Sstevel@tonic-gate /* nothing */ 1997c478bd9Sstevel@tonic-gate } 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate /* 2027c478bd9Sstevel@tonic-gate * Install all the stubs for a module. 2037c478bd9Sstevel@tonic-gate * Return zero if there were no errors or an errno value. 2047c478bd9Sstevel@tonic-gate */ 2057c478bd9Sstevel@tonic-gate int 2067c478bd9Sstevel@tonic-gate install_stubs_by_name(struct modctl *modp, char *name) 2077c478bd9Sstevel@tonic-gate { 2087c478bd9Sstevel@tonic-gate char *p; 2097c478bd9Sstevel@tonic-gate char *filenamep; 2107c478bd9Sstevel@tonic-gate char namebuf[MODMAXNAMELEN + 12]; 2117c478bd9Sstevel@tonic-gate struct mod_modinfo *mp; 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate p = name; 2147c478bd9Sstevel@tonic-gate filenamep = name; 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate while (*p) 2177c478bd9Sstevel@tonic-gate if (*p++ == '/') 2187c478bd9Sstevel@tonic-gate filenamep = p; 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate /* 2217c478bd9Sstevel@tonic-gate * Concatenate "name" with "_modname" then look up this symbol 2227c478bd9Sstevel@tonic-gate * in the kernel. If not found, we're done. 2237c478bd9Sstevel@tonic-gate * If found, then find the "mod" info structure and call init_stubs(). 2247c478bd9Sstevel@tonic-gate */ 2257c478bd9Sstevel@tonic-gate p = namebuf; 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate while (*filenamep && *filenamep != '.') 2287c478bd9Sstevel@tonic-gate *p++ = *filenamep++; 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate (void) strcpy(p, "_modinfo"); 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate if ((mp = (struct mod_modinfo *)modgetsymvalue(namebuf, 1)) != 0) 2337c478bd9Sstevel@tonic-gate return (init_stubs(modp, mp)); 2347c478bd9Sstevel@tonic-gate else 2357c478bd9Sstevel@tonic-gate return (0); 2367c478bd9Sstevel@tonic-gate } 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate static int 2397c478bd9Sstevel@tonic-gate init_stubs(struct modctl *modp, struct mod_modinfo *mp) 2407c478bd9Sstevel@tonic-gate { 2417c478bd9Sstevel@tonic-gate struct mod_stub_info *sp; 2427c478bd9Sstevel@tonic-gate int i; 2437c478bd9Sstevel@tonic-gate ulong_t offset; 2447c478bd9Sstevel@tonic-gate uintptr_t funcadr; 2457c478bd9Sstevel@tonic-gate char *funcname; 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate modp->mod_modinfo = mp; 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate /* 2507c478bd9Sstevel@tonic-gate * Fill in all stubs for this module. We can't be lazy, since 2517c478bd9Sstevel@tonic-gate * some calls could come in from interrupt level, and we 2527c478bd9Sstevel@tonic-gate * can't modlookup then (symbols may be paged out). 2537c478bd9Sstevel@tonic-gate */ 2547c478bd9Sstevel@tonic-gate sp = mp->modm_stubs; 2557c478bd9Sstevel@tonic-gate for (i = 0; sp->mods_func_adr; i++, sp++) { 2567c478bd9Sstevel@tonic-gate funcname = modgetsymname(sp->mods_stub_adr, &offset); 2577c478bd9Sstevel@tonic-gate if (funcname == NULL) { 258e099bf07Scth printf("init_stubs: couldn't find symbol " 259e099bf07Scth "in module %s\n", mp->modm_module_name); 2607c478bd9Sstevel@tonic-gate return (EFAULT); 2617c478bd9Sstevel@tonic-gate } 2627c478bd9Sstevel@tonic-gate funcadr = kobj_lookup(modp->mod_mp, funcname); 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate if (kobj_addrcheck(modp->mod_mp, (caddr_t)funcadr)) { 2657c478bd9Sstevel@tonic-gate printf("%s:%s() not defined properly\n", 2667c478bd9Sstevel@tonic-gate mp->modm_module_name, funcname); 2677c478bd9Sstevel@tonic-gate return (EFAULT); 2687c478bd9Sstevel@tonic-gate } 2697c478bd9Sstevel@tonic-gate sp->mods_func_adr = funcadr; 2707c478bd9Sstevel@tonic-gate } 2717c478bd9Sstevel@tonic-gate mp->mp = modp; 2727c478bd9Sstevel@tonic-gate return (0); 2737c478bd9Sstevel@tonic-gate } 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate /* 2767c478bd9Sstevel@tonic-gate * modp->mod_modinfo has to be checked in these functions before 2777c478bd9Sstevel@tonic-gate * mod_stub_info is accessed because it's not guranteed that all 2787c478bd9Sstevel@tonic-gate * modules define mod_stub_info structures. 2797c478bd9Sstevel@tonic-gate */ 2807c478bd9Sstevel@tonic-gate void 2817c478bd9Sstevel@tonic-gate install_stubs(struct modctl *modp) 2827c478bd9Sstevel@tonic-gate { 2837c478bd9Sstevel@tonic-gate struct mod_stub_info *stub; 2847c478bd9Sstevel@tonic-gate 2857c478bd9Sstevel@tonic-gate if (modp->mod_modinfo) { 2867c478bd9Sstevel@tonic-gate membar_producer(); 2877c478bd9Sstevel@tonic-gate for (stub = modp->mod_modinfo->modm_stubs; 2887c478bd9Sstevel@tonic-gate stub->mods_func_adr; stub++) { 2897c478bd9Sstevel@tonic-gate stub->mods_flag |= MODS_INSTALLED; 2907c478bd9Sstevel@tonic-gate } 2917c478bd9Sstevel@tonic-gate membar_producer(); 2927c478bd9Sstevel@tonic-gate } 2937c478bd9Sstevel@tonic-gate } 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate void 2967c478bd9Sstevel@tonic-gate uninstall_stubs(struct modctl *modp) 2977c478bd9Sstevel@tonic-gate { 2987c478bd9Sstevel@tonic-gate struct mod_stub_info *stub; 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate if (modp->mod_modinfo) { 3017c478bd9Sstevel@tonic-gate membar_producer(); 3027c478bd9Sstevel@tonic-gate for (stub = modp->mod_modinfo->modm_stubs; 3037c478bd9Sstevel@tonic-gate stub->mods_func_adr; stub++) { 3047c478bd9Sstevel@tonic-gate stub->mods_flag &= ~MODS_INSTALLED; 3057c478bd9Sstevel@tonic-gate } 3067c478bd9Sstevel@tonic-gate membar_producer(); 3077c478bd9Sstevel@tonic-gate } 3087c478bd9Sstevel@tonic-gate } 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate void 3117c478bd9Sstevel@tonic-gate reset_stubs(struct modctl *modp) 3127c478bd9Sstevel@tonic-gate { 3137c478bd9Sstevel@tonic-gate struct mod_stub_info *stub; 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate if (modp->mod_modinfo) { 3167c478bd9Sstevel@tonic-gate for (stub = modp->mod_modinfo->modm_stubs; 3177c478bd9Sstevel@tonic-gate stub->mods_func_adr; stub++) { 3187c478bd9Sstevel@tonic-gate if (stub->mods_flag & (MODS_WEAK | MODS_NOUNLOAD)) 3197c478bd9Sstevel@tonic-gate stub->mods_func_adr = 3207c478bd9Sstevel@tonic-gate (uintptr_t)stub->mods_errfcn; 3217c478bd9Sstevel@tonic-gate else 3227c478bd9Sstevel@tonic-gate stub->mods_func_adr = 3237c478bd9Sstevel@tonic-gate (uintptr_t)mod_hold_stub; 3247c478bd9Sstevel@tonic-gate } 3257c478bd9Sstevel@tonic-gate modp->mod_modinfo->mp = NULL; 3267c478bd9Sstevel@tonic-gate } 3277c478bd9Sstevel@tonic-gate } 3287c478bd9Sstevel@tonic-gate 3297c478bd9Sstevel@tonic-gate struct modctl * 3307c478bd9Sstevel@tonic-gate mod_getctl(struct modlinkage *modlp) 3317c478bd9Sstevel@tonic-gate { 3327c478bd9Sstevel@tonic-gate struct modctl *modp; 3337c478bd9Sstevel@tonic-gate 3347c478bd9Sstevel@tonic-gate mutex_enter(&mod_lock); 3357c478bd9Sstevel@tonic-gate modp = &modules; 3367c478bd9Sstevel@tonic-gate do { 3377c478bd9Sstevel@tonic-gate if (modp->mod_linkage == modlp) { 3387c478bd9Sstevel@tonic-gate mutex_exit(&mod_lock); 3397c478bd9Sstevel@tonic-gate return (modp); 3407c478bd9Sstevel@tonic-gate } 3417c478bd9Sstevel@tonic-gate } while ((modp = modp->mod_next) != &modules); 3427c478bd9Sstevel@tonic-gate mutex_exit(&mod_lock); 3437c478bd9Sstevel@tonic-gate return (NULL); 3447c478bd9Sstevel@tonic-gate } 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate 3477c478bd9Sstevel@tonic-gate /* 3487c478bd9Sstevel@tonic-gate * Attach driver.conf info to devnames for a driver 3497c478bd9Sstevel@tonic-gate */ 3507c478bd9Sstevel@tonic-gate struct par_list * 3517c478bd9Sstevel@tonic-gate impl_make_parlist(major_t major) 3527c478bd9Sstevel@tonic-gate { 3537c478bd9Sstevel@tonic-gate int err; 3547c478bd9Sstevel@tonic-gate struct par_list *pl = NULL, *tmp; 3557c478bd9Sstevel@tonic-gate ddi_prop_t *props = NULL; 3567c478bd9Sstevel@tonic-gate char *confname, *drvname; 3577c478bd9Sstevel@tonic-gate struct devnames *dnp; 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate dnp = &devnamesp[major]; 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate ASSERT(mutex_owned(&dnp->dn_lock)); 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate /* 3647c478bd9Sstevel@tonic-gate * If .conf file already parsed or driver removed, just return. 3657c478bd9Sstevel@tonic-gate * May return NULL. 3667c478bd9Sstevel@tonic-gate */ 3677c478bd9Sstevel@tonic-gate if (dnp->dn_flags & (DN_CONF_PARSED | DN_DRIVER_REMOVED)) 3687c478bd9Sstevel@tonic-gate return (dnp->dn_pl); 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate drvname = mod_major_to_name(major); 3717c478bd9Sstevel@tonic-gate if (drvname == NULL) 3727c478bd9Sstevel@tonic-gate return (NULL); 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate confname = kmem_alloc(MAXNAMELEN, KM_SLEEP); 3757c478bd9Sstevel@tonic-gate (void) snprintf(confname, MAXNAMELEN, "drv/%s.conf", drvname); 3767c478bd9Sstevel@tonic-gate err = hwc_parse(confname, &pl, &props); 3777c478bd9Sstevel@tonic-gate kmem_free(confname, MAXNAMELEN); 3787c478bd9Sstevel@tonic-gate if (err) /* file doesn't exist */ 3797c478bd9Sstevel@tonic-gate return (NULL); 3807c478bd9Sstevel@tonic-gate 3817c478bd9Sstevel@tonic-gate /* 3827c478bd9Sstevel@tonic-gate * If there are global properties, reference it from dnp. 3837c478bd9Sstevel@tonic-gate */ 3847c478bd9Sstevel@tonic-gate if (props) 3857c478bd9Sstevel@tonic-gate dnp->dn_global_prop_ptr = i_ddi_prop_list_create(props); 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate /* 3887c478bd9Sstevel@tonic-gate * Hash specs to be looked up by nexus drivers 3897c478bd9Sstevel@tonic-gate */ 3907c478bd9Sstevel@tonic-gate tmp = pl; 3917c478bd9Sstevel@tonic-gate while (tmp) { 3927c478bd9Sstevel@tonic-gate (void) hwc_hash(tmp->par_specs, major); 3937c478bd9Sstevel@tonic-gate tmp = tmp->par_next; 3947c478bd9Sstevel@tonic-gate } 3957c478bd9Sstevel@tonic-gate 3967c478bd9Sstevel@tonic-gate if (!i_ddi_io_initialized()) { 3977c478bd9Sstevel@tonic-gate if (i_ddi_prop_search(DDI_DEV_T_ANY, DDI_FORCEATTACH, 3987c478bd9Sstevel@tonic-gate DDI_PROP_TYPE_INT, &props)) 3997c478bd9Sstevel@tonic-gate dnp->dn_flags |= DN_FORCE_ATTACH; 400e099bf07Scth if (i_ddi_prop_search(DDI_DEV_T_ANY, DDI_OPEN_RETURNS_EINTR, 401e099bf07Scth DDI_PROP_TYPE_INT, &props)) 402e099bf07Scth dnp->dn_flags |= DN_OPEN_RETURNS_EINTR; 403602ca9eaScth if (i_ddi_prop_search(DDI_DEV_T_ANY, "scsi-size-clean", 404602ca9eaScth DDI_PROP_TYPE_INT, &props)) 405602ca9eaScth dnp->dn_flags |= DN_SCSI_SIZE_CLEAN; 4067c478bd9Sstevel@tonic-gate } 40752cac543Sramat 40852cac543Sramat if (i_ddi_prop_search(DDI_DEV_T_ANY, DDI_VHCI_CLASS, 40952cac543Sramat DDI_PROP_TYPE_STRING, &props)) 41052cac543Sramat dnp->dn_flags |= DN_PHCI_DRIVER; 41152cac543Sramat 4127c478bd9Sstevel@tonic-gate dnp->dn_flags |= DN_CONF_PARSED; 4137c478bd9Sstevel@tonic-gate dnp->dn_pl = pl; 4147c478bd9Sstevel@tonic-gate return (pl); 4157c478bd9Sstevel@tonic-gate } 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate /* 4187c478bd9Sstevel@tonic-gate * Destroy driver.conf info in devnames array for a driver 4197c478bd9Sstevel@tonic-gate */ 4207c478bd9Sstevel@tonic-gate int 4217c478bd9Sstevel@tonic-gate impl_free_parlist(major_t major) 4227c478bd9Sstevel@tonic-gate { 4237c478bd9Sstevel@tonic-gate struct par_list *pl; 4247c478bd9Sstevel@tonic-gate struct devnames *dnp = &devnamesp[major]; 4257c478bd9Sstevel@tonic-gate 4267c478bd9Sstevel@tonic-gate /* 4277c478bd9Sstevel@tonic-gate * Unref driver global property list. Don't destroy it 4287c478bd9Sstevel@tonic-gate * because some instances may still be referencing it. 4297c478bd9Sstevel@tonic-gate * The property list will be freed when the last ref 4307c478bd9Sstevel@tonic-gate * goes away. 4317c478bd9Sstevel@tonic-gate */ 4327c478bd9Sstevel@tonic-gate if (dnp->dn_global_prop_ptr) { 4337c478bd9Sstevel@tonic-gate i_ddi_prop_list_rele(dnp->dn_global_prop_ptr, dnp); 4347c478bd9Sstevel@tonic-gate dnp->dn_global_prop_ptr = NULL; 4357c478bd9Sstevel@tonic-gate } 4367c478bd9Sstevel@tonic-gate 4377c478bd9Sstevel@tonic-gate /* 4387c478bd9Sstevel@tonic-gate * remove specs from hash table 4397c478bd9Sstevel@tonic-gate */ 4407c478bd9Sstevel@tonic-gate for (pl = dnp->dn_pl; pl; pl = pl->par_next) 4417c478bd9Sstevel@tonic-gate hwc_unhash(pl->par_specs); 4427c478bd9Sstevel@tonic-gate 4437c478bd9Sstevel@tonic-gate impl_delete_par_list(dnp->dn_pl); 4447c478bd9Sstevel@tonic-gate dnp->dn_pl = NULL; 4457c478bd9Sstevel@tonic-gate dnp->dn_flags &= ~DN_CONF_PARSED; 4467c478bd9Sstevel@tonic-gate return (0); 4477c478bd9Sstevel@tonic-gate } 4487c478bd9Sstevel@tonic-gate 4497c478bd9Sstevel@tonic-gate struct bind *mb_hashtab[MOD_BIND_HASHSIZE]; 4507c478bd9Sstevel@tonic-gate struct bind *sb_hashtab[MOD_BIND_HASHSIZE]; 4517c478bd9Sstevel@tonic-gate 4527c478bd9Sstevel@tonic-gate static int 4537c478bd9Sstevel@tonic-gate nm_hash(char *name) 4547c478bd9Sstevel@tonic-gate { 4557c478bd9Sstevel@tonic-gate char c; 4567c478bd9Sstevel@tonic-gate int hash = 0; 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate for (c = *name++; c; c = *name++) 4597c478bd9Sstevel@tonic-gate hash ^= c; 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate return (hash & MOD_BIND_HASHMASK); 4627c478bd9Sstevel@tonic-gate } 4637c478bd9Sstevel@tonic-gate 4647c478bd9Sstevel@tonic-gate void 4657c478bd9Sstevel@tonic-gate clear_binding_hash(struct bind **bhash) 4667c478bd9Sstevel@tonic-gate { 4677c478bd9Sstevel@tonic-gate int i; 4687c478bd9Sstevel@tonic-gate struct bind *bp, *bp1; 4697c478bd9Sstevel@tonic-gate 4707c478bd9Sstevel@tonic-gate for (i = 0; i < MOD_BIND_HASHSIZE; i++) { 4717c478bd9Sstevel@tonic-gate bp = bhash[i]; 4727c478bd9Sstevel@tonic-gate while (bp != NULL) { 4737c478bd9Sstevel@tonic-gate kmem_free(bp->b_name, strlen(bp->b_name) + 1); 4747c478bd9Sstevel@tonic-gate if (bp->b_bind_name) { 4757c478bd9Sstevel@tonic-gate kmem_free(bp->b_bind_name, 4767c478bd9Sstevel@tonic-gate strlen(bp->b_bind_name) + 1); 4777c478bd9Sstevel@tonic-gate } 4787c478bd9Sstevel@tonic-gate bp1 = bp; 4797c478bd9Sstevel@tonic-gate bp = bp->b_next; 4807c478bd9Sstevel@tonic-gate kmem_free(bp1, sizeof (struct bind)); 4817c478bd9Sstevel@tonic-gate } 4827c478bd9Sstevel@tonic-gate bhash[i] = NULL; 4837c478bd9Sstevel@tonic-gate } 4847c478bd9Sstevel@tonic-gate } 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate static struct bind * 4877c478bd9Sstevel@tonic-gate find_mbind(char *name, struct bind **hashtab) 4887c478bd9Sstevel@tonic-gate { 4897c478bd9Sstevel@tonic-gate int hashndx; 4907c478bd9Sstevel@tonic-gate struct bind *mb; 4917c478bd9Sstevel@tonic-gate 4927c478bd9Sstevel@tonic-gate hashndx = nm_hash(name); 4937c478bd9Sstevel@tonic-gate for (mb = hashtab[hashndx]; mb; mb = mb->b_next) { 4947c478bd9Sstevel@tonic-gate if (strcmp(name, mb->b_name) == 0) 4957c478bd9Sstevel@tonic-gate break; 4967c478bd9Sstevel@tonic-gate } 4977c478bd9Sstevel@tonic-gate 4987c478bd9Sstevel@tonic-gate return (mb); 4997c478bd9Sstevel@tonic-gate } 5007c478bd9Sstevel@tonic-gate 5017c478bd9Sstevel@tonic-gate /* 5027c478bd9Sstevel@tonic-gate * Create an entry for the given (name, major, bind_name) tuple in the 5037c478bd9Sstevel@tonic-gate * hash table supplied. Reject the attempt to do so if 'name' is already 5047c478bd9Sstevel@tonic-gate * in the hash table. 5057c478bd9Sstevel@tonic-gate * 5067c478bd9Sstevel@tonic-gate * Does not provide synchronization, so use only during boot or with 5077c478bd9Sstevel@tonic-gate * externally provided locking. 5087c478bd9Sstevel@tonic-gate */ 5097c478bd9Sstevel@tonic-gate int 5107c478bd9Sstevel@tonic-gate make_mbind(char *name, int major, char *bind_name, struct bind **hashtab) 5117c478bd9Sstevel@tonic-gate { 5127c478bd9Sstevel@tonic-gate struct bind *bp; 5137c478bd9Sstevel@tonic-gate int hashndx; 5147c478bd9Sstevel@tonic-gate 5157c478bd9Sstevel@tonic-gate ASSERT(hashtab != NULL); 5167c478bd9Sstevel@tonic-gate 5177c478bd9Sstevel@tonic-gate /* 5187c478bd9Sstevel@tonic-gate * Fail if the key being added is already in the hash table 5197c478bd9Sstevel@tonic-gate */ 5207c478bd9Sstevel@tonic-gate if (find_mbind(name, hashtab) != NULL) 5217c478bd9Sstevel@tonic-gate return (-1); 5227c478bd9Sstevel@tonic-gate 5237c478bd9Sstevel@tonic-gate bp = kmem_zalloc(sizeof (struct bind), KM_SLEEP); 5247c478bd9Sstevel@tonic-gate bp->b_name = kmem_alloc(strlen(name) + 1, KM_SLEEP); 5257c478bd9Sstevel@tonic-gate (void) strcpy(bp->b_name, name); 5267c478bd9Sstevel@tonic-gate bp->b_num = major; 5277c478bd9Sstevel@tonic-gate if (bind_name != NULL) { 5287c478bd9Sstevel@tonic-gate bp->b_bind_name = kmem_alloc(strlen(bind_name) + 1, KM_SLEEP); 5297c478bd9Sstevel@tonic-gate (void) strcpy(bp->b_bind_name, bind_name); 5307c478bd9Sstevel@tonic-gate } 5317c478bd9Sstevel@tonic-gate hashndx = nm_hash(name); 5327c478bd9Sstevel@tonic-gate bp->b_next = hashtab[hashndx]; 5337c478bd9Sstevel@tonic-gate hashtab[hashndx] = bp; 5347c478bd9Sstevel@tonic-gate 5357c478bd9Sstevel@tonic-gate return (0); 5367c478bd9Sstevel@tonic-gate } 5377c478bd9Sstevel@tonic-gate 5387c478bd9Sstevel@tonic-gate /* 5397c478bd9Sstevel@tonic-gate * Delete a binding from a binding-hash. 5407c478bd9Sstevel@tonic-gate * 5417c478bd9Sstevel@tonic-gate * Does not provide synchronization, so use only during boot or with 5427c478bd9Sstevel@tonic-gate * externally provided locking. 5437c478bd9Sstevel@tonic-gate */ 5447c478bd9Sstevel@tonic-gate void 5457c478bd9Sstevel@tonic-gate delete_mbind(char *name, struct bind **hashtab) 5467c478bd9Sstevel@tonic-gate { 5477c478bd9Sstevel@tonic-gate int hashndx; 5487c478bd9Sstevel@tonic-gate struct bind *b, *bparent = NULL; 5497c478bd9Sstevel@tonic-gate struct bind *t = NULL; /* target to delete */ 5507c478bd9Sstevel@tonic-gate 5517c478bd9Sstevel@tonic-gate hashndx = nm_hash(name); 5527c478bd9Sstevel@tonic-gate 5537c478bd9Sstevel@tonic-gate if (hashtab[hashndx] == NULL) 5547c478bd9Sstevel@tonic-gate return; 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate b = hashtab[hashndx]; 5577c478bd9Sstevel@tonic-gate if (strcmp(name, b->b_name) == 0) { /* special case first elem. */ 5587c478bd9Sstevel@tonic-gate hashtab[hashndx] = b->b_next; 5597c478bd9Sstevel@tonic-gate t = b; 5607c478bd9Sstevel@tonic-gate } else { 5617c478bd9Sstevel@tonic-gate for (b = hashtab[hashndx]; b; b = b->b_next) { 5627c478bd9Sstevel@tonic-gate if (strcmp(name, b->b_name) == 0) { 5637c478bd9Sstevel@tonic-gate ASSERT(bparent); 5647c478bd9Sstevel@tonic-gate t = b; 5657c478bd9Sstevel@tonic-gate bparent->b_next = b->b_next; 5667c478bd9Sstevel@tonic-gate break; 5677c478bd9Sstevel@tonic-gate } 5687c478bd9Sstevel@tonic-gate bparent = b; 5697c478bd9Sstevel@tonic-gate } 5707c478bd9Sstevel@tonic-gate } 5717c478bd9Sstevel@tonic-gate 5727c478bd9Sstevel@tonic-gate if (t != NULL) { /* delete the target */ 5737c478bd9Sstevel@tonic-gate ASSERT(t->b_name); 5747c478bd9Sstevel@tonic-gate kmem_free(t->b_name, strlen(t->b_name) + 1); 5757c478bd9Sstevel@tonic-gate if (t->b_bind_name) 5767c478bd9Sstevel@tonic-gate kmem_free(t->b_bind_name, strlen(t->b_bind_name) + 1); 5777c478bd9Sstevel@tonic-gate kmem_free(t, sizeof (struct bind)); 5787c478bd9Sstevel@tonic-gate } 5797c478bd9Sstevel@tonic-gate } 5807c478bd9Sstevel@tonic-gate 5817c478bd9Sstevel@tonic-gate 5827c478bd9Sstevel@tonic-gate major_t 5837c478bd9Sstevel@tonic-gate mod_name_to_major(char *name) 5847c478bd9Sstevel@tonic-gate { 5857c478bd9Sstevel@tonic-gate struct bind *mbind; 5867c478bd9Sstevel@tonic-gate 5877c478bd9Sstevel@tonic-gate if ((mbind = find_mbind(name, mb_hashtab)) != NULL) 5887c478bd9Sstevel@tonic-gate return ((major_t)mbind->b_num); 5897c478bd9Sstevel@tonic-gate 590*a204de77Scth return (DDI_MAJOR_T_NONE); 5917c478bd9Sstevel@tonic-gate } 5927c478bd9Sstevel@tonic-gate 5937c478bd9Sstevel@tonic-gate char * 5947c478bd9Sstevel@tonic-gate mod_major_to_name(major_t major) 5957c478bd9Sstevel@tonic-gate { 5967c478bd9Sstevel@tonic-gate if (major >= devcnt) 5977c478bd9Sstevel@tonic-gate return (NULL); 5987c478bd9Sstevel@tonic-gate return ((&devnamesp[major])->dn_name); 5997c478bd9Sstevel@tonic-gate } 6007c478bd9Sstevel@tonic-gate 6017c478bd9Sstevel@tonic-gate /* 6027c478bd9Sstevel@tonic-gate * Set up the devnames array. Error check for duplicate entries. 6037c478bd9Sstevel@tonic-gate */ 6047c478bd9Sstevel@tonic-gate void 6057c478bd9Sstevel@tonic-gate init_devnamesp(int size) 6067c478bd9Sstevel@tonic-gate { 6077c478bd9Sstevel@tonic-gate int hshndx; 6087c478bd9Sstevel@tonic-gate struct bind *bp; 6097c478bd9Sstevel@tonic-gate static char dupwarn[] = 6107c478bd9Sstevel@tonic-gate "!Device entry \"%s %d\" conflicts with previous entry \"%s %d\" " 6117c478bd9Sstevel@tonic-gate "in /etc/name_to_major."; 6127c478bd9Sstevel@tonic-gate static char badmaj[] = "The major number %u is invalid."; 6137c478bd9Sstevel@tonic-gate 6147c478bd9Sstevel@tonic-gate ASSERT(size <= L_MAXMAJ32 && size > 0); 6157c478bd9Sstevel@tonic-gate 6167c478bd9Sstevel@tonic-gate /* 6177c478bd9Sstevel@tonic-gate * Allocate the devnames array. All mutexes and cv's will be 6187c478bd9Sstevel@tonic-gate * automagically initialized. 6197c478bd9Sstevel@tonic-gate */ 6207c478bd9Sstevel@tonic-gate devnamesp = kobj_zalloc(size * sizeof (struct devnames), KM_SLEEP); 6217c478bd9Sstevel@tonic-gate 6227c478bd9Sstevel@tonic-gate /* 6237c478bd9Sstevel@tonic-gate * Stick the contents of mb_hashtab into the devnames array. Warn if 6247c478bd9Sstevel@tonic-gate * two hash entries correspond to the same major number, or if a 6257c478bd9Sstevel@tonic-gate * major number is out of range. 6267c478bd9Sstevel@tonic-gate */ 6277c478bd9Sstevel@tonic-gate for (hshndx = 0; hshndx < MOD_BIND_HASHSIZE; hshndx++) { 6287c478bd9Sstevel@tonic-gate for (bp = mb_hashtab[hshndx]; bp; bp = bp->b_next) { 6297c478bd9Sstevel@tonic-gate if (make_devname(bp->b_name, (major_t)bp->b_num) != 0) { 6307c478bd9Sstevel@tonic-gate /* 6317c478bd9Sstevel@tonic-gate * If there is not an entry at b_num already, 6327c478bd9Sstevel@tonic-gate * then this must be a bad major number. 6337c478bd9Sstevel@tonic-gate */ 6347c478bd9Sstevel@tonic-gate char *nm = mod_major_to_name(bp->b_num); 6357c478bd9Sstevel@tonic-gate if (nm == NULL) { 6367c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, badmaj, 6377c478bd9Sstevel@tonic-gate (uint_t)bp->b_num); 6387c478bd9Sstevel@tonic-gate } else { 6397c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, dupwarn, bp->b_name, 6407c478bd9Sstevel@tonic-gate bp->b_num, nm, bp->b_num); 6417c478bd9Sstevel@tonic-gate } 6427c478bd9Sstevel@tonic-gate } 6437c478bd9Sstevel@tonic-gate } 6447c478bd9Sstevel@tonic-gate } 6457c478bd9Sstevel@tonic-gate 6467c478bd9Sstevel@tonic-gate /* Initialize hash table for hwc_spec's */ 6477c478bd9Sstevel@tonic-gate hwc_hash_init(); 6487c478bd9Sstevel@tonic-gate } 6497c478bd9Sstevel@tonic-gate 6507c478bd9Sstevel@tonic-gate int 6517c478bd9Sstevel@tonic-gate make_devname(char *name, major_t major) 6527c478bd9Sstevel@tonic-gate { 6537c478bd9Sstevel@tonic-gate struct devnames *dnp; 6547c478bd9Sstevel@tonic-gate char *copy; 6557c478bd9Sstevel@tonic-gate 6567c478bd9Sstevel@tonic-gate /* 6577c478bd9Sstevel@tonic-gate * Until on-disk support for major nums > 14 bits arrives, fail 6587c478bd9Sstevel@tonic-gate * any major numbers that are too big. 6597c478bd9Sstevel@tonic-gate */ 6607c478bd9Sstevel@tonic-gate if (major > L_MAXMAJ32) 6617c478bd9Sstevel@tonic-gate return (EINVAL); 6627c478bd9Sstevel@tonic-gate 6637c478bd9Sstevel@tonic-gate dnp = &devnamesp[major]; 6647c478bd9Sstevel@tonic-gate LOCK_DEV_OPS(&dnp->dn_lock); 6657c478bd9Sstevel@tonic-gate if (dnp->dn_name) { 6667c478bd9Sstevel@tonic-gate if (strcmp(dnp->dn_name, name) != 0) { 6677c478bd9Sstevel@tonic-gate /* Another driver already here */ 6687c478bd9Sstevel@tonic-gate UNLOCK_DEV_OPS(&dnp->dn_lock); 6697c478bd9Sstevel@tonic-gate return (EINVAL); 6707c478bd9Sstevel@tonic-gate } 6717c478bd9Sstevel@tonic-gate /* Adding back a removed driver */ 6727c478bd9Sstevel@tonic-gate dnp->dn_flags &= ~DN_DRIVER_REMOVED; 6737c478bd9Sstevel@tonic-gate UNLOCK_DEV_OPS(&dnp->dn_lock); 6747c478bd9Sstevel@tonic-gate return (0); 6757c478bd9Sstevel@tonic-gate } 6767c478bd9Sstevel@tonic-gate 6777c478bd9Sstevel@tonic-gate /* 6787c478bd9Sstevel@tonic-gate * Check if flag is taken by getudev() 6797c478bd9Sstevel@tonic-gate */ 6807c478bd9Sstevel@tonic-gate if (dnp->dn_flags & DN_TAKEN_GETUDEV) { 6817c478bd9Sstevel@tonic-gate UNLOCK_DEV_OPS(&dnp->dn_lock); 6827c478bd9Sstevel@tonic-gate return (EINVAL); 6837c478bd9Sstevel@tonic-gate } 6847c478bd9Sstevel@tonic-gate 6857c478bd9Sstevel@tonic-gate copy = kmem_alloc(strlen(name) + 1, KM_SLEEP); 6867c478bd9Sstevel@tonic-gate (void) strcpy(copy, name); 6877c478bd9Sstevel@tonic-gate 6887c478bd9Sstevel@tonic-gate /* Make sure string is copied before setting dn_name */ 6897c478bd9Sstevel@tonic-gate membar_producer(); 6907c478bd9Sstevel@tonic-gate dnp->dn_name = copy; 6917c478bd9Sstevel@tonic-gate dnp->dn_flags = 0; 6927c478bd9Sstevel@tonic-gate UNLOCK_DEV_OPS(&dnp->dn_lock); 6937c478bd9Sstevel@tonic-gate return (0); 6947c478bd9Sstevel@tonic-gate } 6957c478bd9Sstevel@tonic-gate 6967c478bd9Sstevel@tonic-gate /* 6977c478bd9Sstevel@tonic-gate * Set up the syscallnames array. 6987c478bd9Sstevel@tonic-gate */ 6997c478bd9Sstevel@tonic-gate void 7007c478bd9Sstevel@tonic-gate init_syscallnames(int size) 7017c478bd9Sstevel@tonic-gate { 7027c478bd9Sstevel@tonic-gate int hshndx; 7037c478bd9Sstevel@tonic-gate struct bind *bp; 7047c478bd9Sstevel@tonic-gate 7057c478bd9Sstevel@tonic-gate syscallnames = kobj_zalloc(size * sizeof (char *), KM_SLEEP); 7067c478bd9Sstevel@tonic-gate 7077c478bd9Sstevel@tonic-gate for (hshndx = 0; hshndx < MOD_BIND_HASHSIZE; hshndx++) { 7087c478bd9Sstevel@tonic-gate for (bp = sb_hashtab[hshndx]; bp; bp = bp->b_next) { 7097730e2acScg13442 if (bp->b_num < 0 || bp->b_num >= size) { 7107730e2acScg13442 cmn_err(CE_WARN, 7117730e2acScg13442 "!Couldn't add system call \"%s %d\". " 7127730e2acScg13442 "Value out of range (0..%d) in " 7137730e2acScg13442 "/etc/name_to_sysnum.", 7147730e2acScg13442 bp->b_name, bp->b_num, size - 1); 7157730e2acScg13442 continue; 7167730e2acScg13442 } 7177c478bd9Sstevel@tonic-gate make_syscallname(bp->b_name, bp->b_num); 7187c478bd9Sstevel@tonic-gate } 7197c478bd9Sstevel@tonic-gate } 7207c478bd9Sstevel@tonic-gate } 7217c478bd9Sstevel@tonic-gate 7227c478bd9Sstevel@tonic-gate static void 7237c478bd9Sstevel@tonic-gate make_syscallname(char *name, int sysno) 7247c478bd9Sstevel@tonic-gate { 7257c478bd9Sstevel@tonic-gate char **cp = &syscallnames[sysno]; 7267c478bd9Sstevel@tonic-gate 7277c478bd9Sstevel@tonic-gate if (*cp != NULL) { 7287c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "!Couldn't add system call \"%s %d\". " 7297c478bd9Sstevel@tonic-gate "It conflicts with \"%s %d\" in /etc/name_to_sysnum.", 7307c478bd9Sstevel@tonic-gate name, sysno, *cp, sysno); 7317c478bd9Sstevel@tonic-gate return; 7327c478bd9Sstevel@tonic-gate } 7337c478bd9Sstevel@tonic-gate *cp = kmem_alloc(strlen(name) + 1, KM_SLEEP); 7347c478bd9Sstevel@tonic-gate (void) strcpy(*cp, name); 7357c478bd9Sstevel@tonic-gate } 7367c478bd9Sstevel@tonic-gate 7377c478bd9Sstevel@tonic-gate /* 7387c478bd9Sstevel@tonic-gate * Given a system call name, get its number. 7397c478bd9Sstevel@tonic-gate */ 7407c478bd9Sstevel@tonic-gate int 7417c478bd9Sstevel@tonic-gate mod_getsysnum(char *name) 7427c478bd9Sstevel@tonic-gate { 7437c478bd9Sstevel@tonic-gate struct bind *mbind; 7447c478bd9Sstevel@tonic-gate 7457c478bd9Sstevel@tonic-gate if ((mbind = find_mbind(name, sb_hashtab)) != NULL) 7467c478bd9Sstevel@tonic-gate return (mbind->b_num); 7477c478bd9Sstevel@tonic-gate 7487c478bd9Sstevel@tonic-gate return (-1); 7497c478bd9Sstevel@tonic-gate } 7507c478bd9Sstevel@tonic-gate 7517c478bd9Sstevel@tonic-gate /* 7527c478bd9Sstevel@tonic-gate * Given a system call number, get the system call name. 7537c478bd9Sstevel@tonic-gate */ 7547c478bd9Sstevel@tonic-gate char * 7557c478bd9Sstevel@tonic-gate mod_getsysname(int sysnum) 7567c478bd9Sstevel@tonic-gate { 7577c478bd9Sstevel@tonic-gate return (syscallnames[sysnum]); 7587c478bd9Sstevel@tonic-gate } 7597c478bd9Sstevel@tonic-gate 7607c478bd9Sstevel@tonic-gate /* 7617c478bd9Sstevel@tonic-gate * Find the name of the module containing the specified pc. 7627c478bd9Sstevel@tonic-gate * Returns the name on success, "<unknown>" on failure. 7637c478bd9Sstevel@tonic-gate * No mod_lock locking is required because things are never deleted from 7647c478bd9Sstevel@tonic-gate * the &modules list. 7657c478bd9Sstevel@tonic-gate */ 7667c478bd9Sstevel@tonic-gate char * 7677c478bd9Sstevel@tonic-gate mod_containing_pc(caddr_t pc) 7687c478bd9Sstevel@tonic-gate { 7697c478bd9Sstevel@tonic-gate struct modctl *mcp = &modules; 7707c478bd9Sstevel@tonic-gate 7717c478bd9Sstevel@tonic-gate do { 7727c478bd9Sstevel@tonic-gate if (mcp->mod_mp != NULL && 7737c478bd9Sstevel@tonic-gate (size_t)pc - (size_t)mcp->mod_text < mcp->mod_text_size) 7747c478bd9Sstevel@tonic-gate return (mcp->mod_modname); 7757c478bd9Sstevel@tonic-gate } while ((mcp = mcp->mod_next) != &modules); 7767c478bd9Sstevel@tonic-gate return ("<unknown>"); 7777c478bd9Sstevel@tonic-gate } 7787c478bd9Sstevel@tonic-gate 7797c478bd9Sstevel@tonic-gate /* 7807c478bd9Sstevel@tonic-gate * Hash tables for hwc_spec 7817c478bd9Sstevel@tonic-gate * 7827c478bd9Sstevel@tonic-gate * The purpose of these hash tables are to allow the framework to discover 7837c478bd9Sstevel@tonic-gate * all possible .conf children for a given nexus. There are two hash tables. 7847c478bd9Sstevel@tonic-gate * One is hashed based on parent name, the on the class name. Each 7857c478bd9Sstevel@tonic-gate * driver.conf file translates to a list of hwc_spec's. Adding and 7867c478bd9Sstevel@tonic-gate * removing the entire list is an atomic operation, protected by 7877c478bd9Sstevel@tonic-gate * the hwc_hash_lock. 7887c478bd9Sstevel@tonic-gate * 7897c478bd9Sstevel@tonic-gate * What we get from all the hashing is the function hwc_get_child_spec(). 7907c478bd9Sstevel@tonic-gate */ 7917c478bd9Sstevel@tonic-gate #define HWC_SPEC_HASHSIZE (1 << 6) /* 64 */ 7927c478bd9Sstevel@tonic-gate 7937c478bd9Sstevel@tonic-gate static mod_hash_t *hwc_par_hash; /* hash by parent name */ 7947c478bd9Sstevel@tonic-gate static mod_hash_t *hwc_class_hash; /* hash by class name */ 7957c478bd9Sstevel@tonic-gate static kmutex_t hwc_hash_lock; /* lock protecting hwc hashes */ 7967c478bd9Sstevel@tonic-gate 7977c478bd9Sstevel@tonic-gate /* 7987c478bd9Sstevel@tonic-gate * Initialize hash tables for parent and class specs 7997c478bd9Sstevel@tonic-gate */ 8007c478bd9Sstevel@tonic-gate static void 8017c478bd9Sstevel@tonic-gate hwc_hash_init() 8027c478bd9Sstevel@tonic-gate { 8037c478bd9Sstevel@tonic-gate hwc_par_hash = mod_hash_create_strhash("hwc parent spec hash", 8047c478bd9Sstevel@tonic-gate HWC_SPEC_HASHSIZE, mod_hash_null_valdtor); 8057c478bd9Sstevel@tonic-gate hwc_class_hash = mod_hash_create_strhash("hwc class spec hash", 8067c478bd9Sstevel@tonic-gate HWC_SPEC_HASHSIZE, mod_hash_null_valdtor); 8077c478bd9Sstevel@tonic-gate } 8087c478bd9Sstevel@tonic-gate 8097c478bd9Sstevel@tonic-gate /* 8107c478bd9Sstevel@tonic-gate * Insert a spec into hash table. hwc_hash_lock must be held 8117c478bd9Sstevel@tonic-gate */ 8127c478bd9Sstevel@tonic-gate static void 8137c478bd9Sstevel@tonic-gate hwc_hash_insert(struct hwc_spec *spec, char *name, mod_hash_t *hash) 8147c478bd9Sstevel@tonic-gate { 8157c478bd9Sstevel@tonic-gate mod_hash_key_t key; 8167c478bd9Sstevel@tonic-gate struct hwc_spec *entry = NULL; 8177c478bd9Sstevel@tonic-gate 8187c478bd9Sstevel@tonic-gate ASSERT(name != NULL); 8197c478bd9Sstevel@tonic-gate 8207c478bd9Sstevel@tonic-gate if (mod_hash_find(hash, (mod_hash_key_t)name, 8217c478bd9Sstevel@tonic-gate (mod_hash_val_t)&entry) != 0) { 8227c478bd9Sstevel@tonic-gate /* Name doesn't exist, insert a new key */ 8237c478bd9Sstevel@tonic-gate key = kmem_alloc(strlen(name) + 1, KM_SLEEP); 8247c478bd9Sstevel@tonic-gate (void) strcpy((char *)key, name); 8257c478bd9Sstevel@tonic-gate if (mod_hash_insert(hash, key, (mod_hash_val_t)spec) != 0) { 8267c478bd9Sstevel@tonic-gate kmem_free(key, strlen(name) + 1); 8277c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "hwc hash state inconsistent"); 8287c478bd9Sstevel@tonic-gate } 8297c478bd9Sstevel@tonic-gate return; 8307c478bd9Sstevel@tonic-gate } 8317c478bd9Sstevel@tonic-gate 8327c478bd9Sstevel@tonic-gate /* 8337c478bd9Sstevel@tonic-gate * Name is already present, append spec to the list. 8347c478bd9Sstevel@tonic-gate * This is the case when driver.conf specifies multiple 8357c478bd9Sstevel@tonic-gate * nodes under a single parent or class. 8367c478bd9Sstevel@tonic-gate */ 8377c478bd9Sstevel@tonic-gate while (entry->hwc_hash_next) 8387c478bd9Sstevel@tonic-gate entry = entry->hwc_hash_next; 8397c478bd9Sstevel@tonic-gate entry->hwc_hash_next = spec; 8407c478bd9Sstevel@tonic-gate } 8417c478bd9Sstevel@tonic-gate 8427c478bd9Sstevel@tonic-gate /* 8437c478bd9Sstevel@tonic-gate * Remove a spec entry from spec hash table, the spec itself is 8447c478bd9Sstevel@tonic-gate * destroyed external to this function. 8457c478bd9Sstevel@tonic-gate */ 8467c478bd9Sstevel@tonic-gate static void 8477c478bd9Sstevel@tonic-gate hwc_hash_remove(struct hwc_spec *spec, char *name, mod_hash_t *hash) 8487c478bd9Sstevel@tonic-gate { 8497c478bd9Sstevel@tonic-gate char *key; 8507c478bd9Sstevel@tonic-gate struct hwc_spec *entry; 8517c478bd9Sstevel@tonic-gate 8527c478bd9Sstevel@tonic-gate ASSERT(name != NULL); 8537c478bd9Sstevel@tonic-gate 8547c478bd9Sstevel@tonic-gate if (mod_hash_find(hash, (mod_hash_key_t)name, 8557c478bd9Sstevel@tonic-gate (mod_hash_val_t)&entry) != 0) { 8567c478bd9Sstevel@tonic-gate return; /* name not found in hash */ 8577c478bd9Sstevel@tonic-gate } 8587c478bd9Sstevel@tonic-gate 8597c478bd9Sstevel@tonic-gate /* 8607c478bd9Sstevel@tonic-gate * If the head is the spec to be removed, either destroy the 8617c478bd9Sstevel@tonic-gate * entry or replace it with the remaining list. 8627c478bd9Sstevel@tonic-gate */ 8637c478bd9Sstevel@tonic-gate if (entry == spec) { 8647c478bd9Sstevel@tonic-gate if (spec->hwc_hash_next == NULL) { 8657c478bd9Sstevel@tonic-gate (void) mod_hash_destroy(hash, (mod_hash_key_t)name); 8667c478bd9Sstevel@tonic-gate return; 8677c478bd9Sstevel@tonic-gate } 8687c478bd9Sstevel@tonic-gate key = kmem_alloc(strlen(name) + 1, KM_SLEEP); 8697c478bd9Sstevel@tonic-gate (void) strcpy(key, name); 8707c478bd9Sstevel@tonic-gate (void) mod_hash_replace(hash, (mod_hash_key_t)key, 8717c478bd9Sstevel@tonic-gate (mod_hash_val_t)spec->hwc_hash_next); 8727c478bd9Sstevel@tonic-gate spec->hwc_hash_next = NULL; 8737c478bd9Sstevel@tonic-gate return; 8747c478bd9Sstevel@tonic-gate } 8757c478bd9Sstevel@tonic-gate 8767c478bd9Sstevel@tonic-gate /* 8777c478bd9Sstevel@tonic-gate * If the head is not the one, look for the spec in the 8787c478bd9Sstevel@tonic-gate * hwc_hash_next linkage. 8797c478bd9Sstevel@tonic-gate */ 8807c478bd9Sstevel@tonic-gate while (entry->hwc_hash_next && (entry->hwc_hash_next != spec)) 8817c478bd9Sstevel@tonic-gate entry = entry->hwc_hash_next; 8827c478bd9Sstevel@tonic-gate 8837c478bd9Sstevel@tonic-gate if (entry->hwc_hash_next) { 8847c478bd9Sstevel@tonic-gate entry->hwc_hash_next = spec->hwc_hash_next; 8857c478bd9Sstevel@tonic-gate spec->hwc_hash_next = NULL; 8867c478bd9Sstevel@tonic-gate } 8877c478bd9Sstevel@tonic-gate } 8887c478bd9Sstevel@tonic-gate 8897c478bd9Sstevel@tonic-gate /* 8907c478bd9Sstevel@tonic-gate * Hash a list of specs based on either parent name or class name 8917c478bd9Sstevel@tonic-gate */ 8927c478bd9Sstevel@tonic-gate static void 8937c478bd9Sstevel@tonic-gate hwc_hash(struct hwc_spec *spec_list, major_t major) 8947c478bd9Sstevel@tonic-gate { 8957c478bd9Sstevel@tonic-gate struct hwc_spec *spec = spec_list; 8967c478bd9Sstevel@tonic-gate 8977c478bd9Sstevel@tonic-gate mutex_enter(&hwc_hash_lock); 8987c478bd9Sstevel@tonic-gate while (spec) { 8997c478bd9Sstevel@tonic-gate /* Put driver major here so parent can find it */ 9007c478bd9Sstevel@tonic-gate spec->hwc_major = major; 9017c478bd9Sstevel@tonic-gate 9027c478bd9Sstevel@tonic-gate if (spec->hwc_parent_name != NULL) { 9037c478bd9Sstevel@tonic-gate hwc_hash_insert(spec, spec->hwc_parent_name, 9047c478bd9Sstevel@tonic-gate hwc_par_hash); 9057c478bd9Sstevel@tonic-gate } else if (spec->hwc_class_name != NULL) { 9067c478bd9Sstevel@tonic-gate hwc_hash_insert(spec, spec->hwc_class_name, 9077c478bd9Sstevel@tonic-gate hwc_class_hash); 9087c478bd9Sstevel@tonic-gate } else { 9097c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 9107c478bd9Sstevel@tonic-gate "hwc_hash: No class or parent specified"); 9117c478bd9Sstevel@tonic-gate } 9127c478bd9Sstevel@tonic-gate spec = spec->hwc_next; 9137c478bd9Sstevel@tonic-gate } 9147c478bd9Sstevel@tonic-gate mutex_exit(&hwc_hash_lock); 9157c478bd9Sstevel@tonic-gate } 9167c478bd9Sstevel@tonic-gate 9177c478bd9Sstevel@tonic-gate /* 9187c478bd9Sstevel@tonic-gate * Remove a list of specs from hash tables. Don't destroy the specs yet. 9197c478bd9Sstevel@tonic-gate */ 9207c478bd9Sstevel@tonic-gate static void 9217c478bd9Sstevel@tonic-gate hwc_unhash(struct hwc_spec *spec_list) 9227c478bd9Sstevel@tonic-gate { 9237c478bd9Sstevel@tonic-gate struct hwc_spec *spec = spec_list; 9247c478bd9Sstevel@tonic-gate 9257c478bd9Sstevel@tonic-gate mutex_enter(&hwc_hash_lock); 9267c478bd9Sstevel@tonic-gate while (spec) { 9277c478bd9Sstevel@tonic-gate if (spec->hwc_parent_name != NULL) { 9287c478bd9Sstevel@tonic-gate hwc_hash_remove(spec, spec->hwc_parent_name, 9297c478bd9Sstevel@tonic-gate hwc_par_hash); 9307c478bd9Sstevel@tonic-gate } else if (spec->hwc_class_name != NULL) { 9317c478bd9Sstevel@tonic-gate hwc_hash_remove(spec, spec->hwc_class_name, 9327c478bd9Sstevel@tonic-gate hwc_class_hash); 9337c478bd9Sstevel@tonic-gate } else { 9347c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 9357c478bd9Sstevel@tonic-gate "hwc_unhash: No class or parent specified"); 9367c478bd9Sstevel@tonic-gate } 9377c478bd9Sstevel@tonic-gate spec = spec->hwc_next; 9387c478bd9Sstevel@tonic-gate } 9397c478bd9Sstevel@tonic-gate mutex_exit(&hwc_hash_lock); 9407c478bd9Sstevel@tonic-gate } 9417c478bd9Sstevel@tonic-gate 9427c478bd9Sstevel@tonic-gate /* 9437c478bd9Sstevel@tonic-gate * Make a copy of specs in a hash entry and add to the end of listp. 9447c478bd9Sstevel@tonic-gate * Called by nexus to locate a list of child specs. 9457c478bd9Sstevel@tonic-gate * 9467c478bd9Sstevel@tonic-gate * entry is a list of hwc_spec chained together with hwc_hash_next. 9477c478bd9Sstevel@tonic-gate * listp points to list chained together with hwc_next. 9487c478bd9Sstevel@tonic-gate */ 9497c478bd9Sstevel@tonic-gate static void 9507c478bd9Sstevel@tonic-gate hwc_spec_add(struct hwc_spec **listp, struct hwc_spec *entry, 9517c478bd9Sstevel@tonic-gate major_t match_major) 9527c478bd9Sstevel@tonic-gate { 9537c478bd9Sstevel@tonic-gate /* Find the tail of the list */ 9547c478bd9Sstevel@tonic-gate while (*listp) 9557c478bd9Sstevel@tonic-gate listp = &(*listp)->hwc_next; 9567c478bd9Sstevel@tonic-gate 9577c478bd9Sstevel@tonic-gate while (entry) { 9587c478bd9Sstevel@tonic-gate struct hwc_spec *spec; 9597c478bd9Sstevel@tonic-gate 960*a204de77Scth if ((match_major != DDI_MAJOR_T_NONE) && 9617c478bd9Sstevel@tonic-gate (match_major != entry->hwc_major)) { 9627c478bd9Sstevel@tonic-gate entry = entry->hwc_hash_next; 9637c478bd9Sstevel@tonic-gate continue; 9647c478bd9Sstevel@tonic-gate } 9657c478bd9Sstevel@tonic-gate 9667c478bd9Sstevel@tonic-gate /* 9677c478bd9Sstevel@tonic-gate * Allocate spec and copy the content of entry. 9687c478bd9Sstevel@tonic-gate * No need to copy class/parent name since caller 9697c478bd9Sstevel@tonic-gate * already knows the parent dip. 9707c478bd9Sstevel@tonic-gate */ 9717c478bd9Sstevel@tonic-gate spec = kmem_zalloc(sizeof (*spec), KM_SLEEP); 9727c478bd9Sstevel@tonic-gate spec->hwc_devi_name = i_ddi_strdup( 9737c478bd9Sstevel@tonic-gate entry->hwc_devi_name, KM_SLEEP); 9747c478bd9Sstevel@tonic-gate spec->hwc_major = entry->hwc_major; 9757c478bd9Sstevel@tonic-gate spec->hwc_devi_sys_prop_ptr = i_ddi_prop_list_dup( 9767c478bd9Sstevel@tonic-gate entry->hwc_devi_sys_prop_ptr, KM_SLEEP); 9777c478bd9Sstevel@tonic-gate 9787c478bd9Sstevel@tonic-gate *listp = spec; 9797c478bd9Sstevel@tonic-gate listp = &spec->hwc_next; 9807c478bd9Sstevel@tonic-gate entry = entry->hwc_hash_next; 9817c478bd9Sstevel@tonic-gate } 9827c478bd9Sstevel@tonic-gate } 9837c478bd9Sstevel@tonic-gate 9847c478bd9Sstevel@tonic-gate /* 9857c478bd9Sstevel@tonic-gate * Given a dip, find the list of child .conf specs from most specific 9867c478bd9Sstevel@tonic-gate * (parent pathname) to least specific (class name). 9877c478bd9Sstevel@tonic-gate * 9887c478bd9Sstevel@tonic-gate * This function allows top-down loading to be implemented without 9897c478bd9Sstevel@tonic-gate * changing the format of driver.conf file. 9907c478bd9Sstevel@tonic-gate */ 9917c478bd9Sstevel@tonic-gate struct hwc_spec * 9927c478bd9Sstevel@tonic-gate hwc_get_child_spec(dev_info_t *dip, major_t match_major) 9937c478bd9Sstevel@tonic-gate { 9947c478bd9Sstevel@tonic-gate extern char *i_ddi_parname(dev_info_t *, char *); 9957c478bd9Sstevel@tonic-gate extern int i_ddi_get_exported_classes(dev_info_t *, char ***); 9967c478bd9Sstevel@tonic-gate extern void i_ddi_free_exported_classes(char **, int); 9977c478bd9Sstevel@tonic-gate 9987c478bd9Sstevel@tonic-gate int i, nclass; 9997c478bd9Sstevel@tonic-gate char **classes; 10007c478bd9Sstevel@tonic-gate struct hwc_spec *list = NULL; 10017c478bd9Sstevel@tonic-gate mod_hash_val_t val; 10027c478bd9Sstevel@tonic-gate char *parname, *parname_buf; 10037c478bd9Sstevel@tonic-gate char *deviname, *deviname_buf; 10047c478bd9Sstevel@tonic-gate char *pathname, *pathname_buf; 10057c478bd9Sstevel@tonic-gate char *bindname; 10067c478bd9Sstevel@tonic-gate char *drvname; 10077c478bd9Sstevel@tonic-gate 10087c478bd9Sstevel@tonic-gate pathname_buf = kmem_alloc(3 * MAXPATHLEN, KM_SLEEP); 10097c478bd9Sstevel@tonic-gate deviname_buf = pathname_buf + MAXPATHLEN; 10107c478bd9Sstevel@tonic-gate parname_buf = pathname_buf + (2 * MAXPATHLEN); 10117c478bd9Sstevel@tonic-gate 10127c478bd9Sstevel@tonic-gate mutex_enter(&hwc_hash_lock); 10137c478bd9Sstevel@tonic-gate 10147c478bd9Sstevel@tonic-gate /* 10157c478bd9Sstevel@tonic-gate * Lookup based on full path. 10167c478bd9Sstevel@tonic-gate * In the case of root node, ddi_pathname would return 10177c478bd9Sstevel@tonic-gate * null string so just skip calling it. 10187c478bd9Sstevel@tonic-gate * As the pathname always begins with /, no simpler 10197c478bd9Sstevel@tonic-gate * name can duplicate it. 10207c478bd9Sstevel@tonic-gate */ 10217c478bd9Sstevel@tonic-gate pathname = (dip == ddi_root_node()) ? "/" : 10227c478bd9Sstevel@tonic-gate ddi_pathname(dip, pathname_buf); 10237c478bd9Sstevel@tonic-gate ASSERT(pathname != NULL); 10247c478bd9Sstevel@tonic-gate ASSERT(*pathname == '/'); 10257c478bd9Sstevel@tonic-gate 10267c478bd9Sstevel@tonic-gate if (mod_hash_find(hwc_par_hash, (mod_hash_key_t)pathname, &val) == 0) { 10277c478bd9Sstevel@tonic-gate hwc_spec_add(&list, (struct hwc_spec *)val, match_major); 10287c478bd9Sstevel@tonic-gate } 10297c478bd9Sstevel@tonic-gate 10307c478bd9Sstevel@tonic-gate /* 10317c478bd9Sstevel@tonic-gate * Lookup nodename@address. 10327c478bd9Sstevel@tonic-gate * Note deviname cannot match pathname. 10337c478bd9Sstevel@tonic-gate */ 10347c478bd9Sstevel@tonic-gate deviname = ddi_deviname(dip, deviname_buf); 10357c478bd9Sstevel@tonic-gate if (*deviname != '\0') { 10367c478bd9Sstevel@tonic-gate /* 10377c478bd9Sstevel@tonic-gate * Skip leading / returned by ddi_deviname. 10387c478bd9Sstevel@tonic-gate */ 10397c478bd9Sstevel@tonic-gate ASSERT(*deviname == '/'); 10407c478bd9Sstevel@tonic-gate deviname++; 1041e099bf07Scth if ((*deviname != '\0') && (mod_hash_find(hwc_par_hash, 10427c478bd9Sstevel@tonic-gate (mod_hash_key_t)deviname, &val) == 0)) 10437c478bd9Sstevel@tonic-gate hwc_spec_add(&list, 10447c478bd9Sstevel@tonic-gate (struct hwc_spec *)val, match_major); 10457c478bd9Sstevel@tonic-gate } 10467c478bd9Sstevel@tonic-gate 10477c478bd9Sstevel@tonic-gate /* 10487c478bd9Sstevel@tonic-gate * Lookup bindingname@address. 10497c478bd9Sstevel@tonic-gate * Take care not to perform duplicate lookups. 10507c478bd9Sstevel@tonic-gate */ 10517c478bd9Sstevel@tonic-gate parname = i_ddi_parname(dip, parname_buf); 10527c478bd9Sstevel@tonic-gate if (*parname != '\0') { 10537c478bd9Sstevel@tonic-gate ASSERT(*parname != '/'); 10547c478bd9Sstevel@tonic-gate if ((strcmp(parname, deviname) != 0) && 10557c478bd9Sstevel@tonic-gate (mod_hash_find(hwc_par_hash, 10567c478bd9Sstevel@tonic-gate (mod_hash_key_t)parname, &val) == 0)) { 10577c478bd9Sstevel@tonic-gate hwc_spec_add(&list, 10587c478bd9Sstevel@tonic-gate (struct hwc_spec *)val, match_major); 10597c478bd9Sstevel@tonic-gate } 10607c478bd9Sstevel@tonic-gate } 10617c478bd9Sstevel@tonic-gate 10627c478bd9Sstevel@tonic-gate /* 10637c478bd9Sstevel@tonic-gate * Lookup driver binding name 10647c478bd9Sstevel@tonic-gate */ 10657c478bd9Sstevel@tonic-gate bindname = ddi_binding_name(dip); 10667c478bd9Sstevel@tonic-gate ASSERT(*bindname != '/'); 10677c478bd9Sstevel@tonic-gate if ((strcmp(bindname, parname) != 0) && 10687c478bd9Sstevel@tonic-gate (strcmp(bindname, deviname) != 0) && 10697c478bd9Sstevel@tonic-gate (mod_hash_find(hwc_par_hash, (mod_hash_key_t)bindname, &val) == 0)) 10707c478bd9Sstevel@tonic-gate hwc_spec_add(&list, (struct hwc_spec *)val, match_major); 10717c478bd9Sstevel@tonic-gate 10727c478bd9Sstevel@tonic-gate /* 10737c478bd9Sstevel@tonic-gate * Lookup driver name 10747c478bd9Sstevel@tonic-gate */ 10757c478bd9Sstevel@tonic-gate drvname = (char *)ddi_driver_name(dip); 10767c478bd9Sstevel@tonic-gate ASSERT(*drvname != '/'); 10777c478bd9Sstevel@tonic-gate if ((strcmp(drvname, bindname) != 0) && 10787c478bd9Sstevel@tonic-gate (strcmp(drvname, parname) != 0) && 10797c478bd9Sstevel@tonic-gate (strcmp(drvname, deviname) != 0) && 10807c478bd9Sstevel@tonic-gate (mod_hash_find(hwc_par_hash, (mod_hash_key_t)drvname, &val) == 0)) 10817c478bd9Sstevel@tonic-gate hwc_spec_add(&list, (struct hwc_spec *)val, match_major); 10827c478bd9Sstevel@tonic-gate 10837c478bd9Sstevel@tonic-gate kmem_free(pathname_buf, 3 * MAXPATHLEN); 10847c478bd9Sstevel@tonic-gate 10857c478bd9Sstevel@tonic-gate /* 10867c478bd9Sstevel@tonic-gate * Lookup classes exported by this node and lookup the 10877c478bd9Sstevel@tonic-gate * class hash table for all .conf specs 10887c478bd9Sstevel@tonic-gate */ 10897c478bd9Sstevel@tonic-gate nclass = i_ddi_get_exported_classes(dip, &classes); 10907c478bd9Sstevel@tonic-gate for (i = 0; i < nclass; i++) { 10917c478bd9Sstevel@tonic-gate if (mod_hash_find(hwc_class_hash, (mod_hash_key_t)classes[i], 10927c478bd9Sstevel@tonic-gate &val) == 0) 10937c478bd9Sstevel@tonic-gate hwc_spec_add(&list, (struct hwc_spec *)val, 10947c478bd9Sstevel@tonic-gate match_major); 10957c478bd9Sstevel@tonic-gate } 10967c478bd9Sstevel@tonic-gate i_ddi_free_exported_classes(classes, nclass); 10977c478bd9Sstevel@tonic-gate 10987c478bd9Sstevel@tonic-gate mutex_exit(&hwc_hash_lock); 10997c478bd9Sstevel@tonic-gate return (list); 11007c478bd9Sstevel@tonic-gate } 1101