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