1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include <sys/systm.h> 30*0Sstevel@tonic-gate #include <sys/pathname.h> 31*0Sstevel@tonic-gate #include <sys/modctl.h> 32*0Sstevel@tonic-gate #include <sys/sunndi.h> 33*0Sstevel@tonic-gate #include <sys/sunmdi.h> 34*0Sstevel@tonic-gate #include <sys/mdi_impldefs.h> 35*0Sstevel@tonic-gate #include <sys/promif.h> 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate struct parinfo { 38*0Sstevel@tonic-gate dev_info_t *dip; 39*0Sstevel@tonic-gate mdi_pathinfo_t *pip; 40*0Sstevel@tonic-gate dev_info_t *pdip; 41*0Sstevel@tonic-gate }; 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate /* 44*0Sstevel@tonic-gate * internal functions 45*0Sstevel@tonic-gate */ 46*0Sstevel@tonic-gate static int resolve_devfs_name(char *, char *); 47*0Sstevel@tonic-gate static dev_info_t *find_alternate_node(dev_info_t *, major_t); 48*0Sstevel@tonic-gate static dev_info_t *get_path_parent(dev_info_t *, struct parinfo *); 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate /* internal global data */ 51*0Sstevel@tonic-gate static struct modlmisc modlmisc = { 52*0Sstevel@tonic-gate &mod_miscops, "bootdev misc module 1.21" 53*0Sstevel@tonic-gate }; 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate static struct modlinkage modlinkage = { 56*0Sstevel@tonic-gate MODREV_1, (void *)&modlmisc, NULL 57*0Sstevel@tonic-gate }; 58*0Sstevel@tonic-gate 59*0Sstevel@tonic-gate int 60*0Sstevel@tonic-gate _init() 61*0Sstevel@tonic-gate { 62*0Sstevel@tonic-gate return (mod_install(&modlinkage)); 63*0Sstevel@tonic-gate } 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate int 66*0Sstevel@tonic-gate _fini() 67*0Sstevel@tonic-gate { 68*0Sstevel@tonic-gate return (mod_remove(&modlinkage)); 69*0Sstevel@tonic-gate } 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gate int 72*0Sstevel@tonic-gate _info(struct modinfo *modinfop) 73*0Sstevel@tonic-gate { 74*0Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 75*0Sstevel@tonic-gate } 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate /* 78*0Sstevel@tonic-gate * convert a prom device path to an equivalent path in /devices 79*0Sstevel@tonic-gate * Does not deal with aliases. Does deal with pathnames which 80*0Sstevel@tonic-gate * are not fully qualified. This routine is generalized 81*0Sstevel@tonic-gate * to work across several flavors of OBP 82*0Sstevel@tonic-gate */ 83*0Sstevel@tonic-gate int 84*0Sstevel@tonic-gate i_promname_to_devname(char *prom_name, char *ret_buf) 85*0Sstevel@tonic-gate { 86*0Sstevel@tonic-gate if (prom_name == NULL || ret_buf == NULL || 87*0Sstevel@tonic-gate (strlen(prom_name) >= MAXPATHLEN)) { 88*0Sstevel@tonic-gate return (EINVAL); 89*0Sstevel@tonic-gate } 90*0Sstevel@tonic-gate if (i_ddi_prompath_to_devfspath(prom_name, ret_buf) != DDI_SUCCESS) 91*0Sstevel@tonic-gate return (EINVAL); 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gate return (0); 94*0Sstevel@tonic-gate } 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate /* 97*0Sstevel@tonic-gate * translate a devfs pathname to one that will be acceptable 98*0Sstevel@tonic-gate * by the prom. In most cases, there is no translation needed. 99*0Sstevel@tonic-gate * For systems supporting generically named devices, the prom 100*0Sstevel@tonic-gate * may support nodes such as 'disk' that do not have any unit 101*0Sstevel@tonic-gate * address information (i.e. target,lun info). If this is the 102*0Sstevel@tonic-gate * case, the ddi framework will reject the node as invalid and 103*0Sstevel@tonic-gate * populate the devinfo tree with nodes froms the .conf file 104*0Sstevel@tonic-gate * (e.g. sd). In this case, the names that show up in /devices 105*0Sstevel@tonic-gate * are sd - since the prom only knows about 'disk' nodes, this 106*0Sstevel@tonic-gate * routine detects this situation and does the conversion 107*0Sstevel@tonic-gate * There are also cases such as pluto where the disk node in the 108*0Sstevel@tonic-gate * prom is named "SUNW,ssd" but in /devices the name is "ssd". 109*0Sstevel@tonic-gate * 110*0Sstevel@tonic-gate * If MPxIO is enabled, the translation involves following 111*0Sstevel@tonic-gate * pathinfo nodes to the "best" parent. See get_obp_parent(). 112*0Sstevel@tonic-gate * 113*0Sstevel@tonic-gate * return a 0 on success with the new device string in ret_buf. 114*0Sstevel@tonic-gate * Otherwise return the appropriate error code as we may be called 115*0Sstevel@tonic-gate * from the openprom driver. 116*0Sstevel@tonic-gate */ 117*0Sstevel@tonic-gate int 118*0Sstevel@tonic-gate i_devname_to_promname(char *dev_name, char *ret_buf, size_t len) 119*0Sstevel@tonic-gate { 120*0Sstevel@tonic-gate dev_info_t *dip, *pdip, *cdip, *idip; 121*0Sstevel@tonic-gate char *dev_path, *prom_path; 122*0Sstevel@tonic-gate char *unit_address, *minorname, *nodename; 123*0Sstevel@tonic-gate major_t major; 124*0Sstevel@tonic-gate int depth, old_depth; 125*0Sstevel@tonic-gate struct parinfo *parinfo; 126*0Sstevel@tonic-gate struct parinfo *info; 127*0Sstevel@tonic-gate char *rptr, *optr, *offline; 128*0Sstevel@tonic-gate size_t olen, rlen; 129*0Sstevel@tonic-gate 130*0Sstevel@tonic-gate /* do some sanity checks */ 131*0Sstevel@tonic-gate if ((dev_name == NULL) || (ret_buf == NULL) || 132*0Sstevel@tonic-gate (strlen(dev_name) > MAXPATHLEN)) { 133*0Sstevel@tonic-gate return (EINVAL); 134*0Sstevel@tonic-gate } 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate /* 137*0Sstevel@tonic-gate * Convert to a /devices name. Fail the translation if 138*0Sstevel@tonic-gate * the name doesn't exist. 139*0Sstevel@tonic-gate */ 140*0Sstevel@tonic-gate dev_path = kmem_zalloc(MAXPATHLEN, KM_SLEEP); 141*0Sstevel@tonic-gate if (resolve_devfs_name(dev_name, dev_path) != 0 || 142*0Sstevel@tonic-gate strncmp(dev_path, "/devices/", 9) != 0) { 143*0Sstevel@tonic-gate kmem_free(dev_path, MAXPATHLEN); 144*0Sstevel@tonic-gate return (EINVAL); 145*0Sstevel@tonic-gate } 146*0Sstevel@tonic-gate dev_name = dev_path + sizeof ("/devices") - 1; 147*0Sstevel@tonic-gate 148*0Sstevel@tonic-gate bzero(ret_buf, len); 149*0Sstevel@tonic-gate 150*0Sstevel@tonic-gate if (prom_finddevice(dev_name) != OBP_BADNODE) { 151*0Sstevel@tonic-gate /* we are done */ 152*0Sstevel@tonic-gate (void) snprintf(ret_buf, len, "%s", dev_name); 153*0Sstevel@tonic-gate kmem_free(dev_path, MAXPATHLEN); 154*0Sstevel@tonic-gate return (0); 155*0Sstevel@tonic-gate } 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gate /* 158*0Sstevel@tonic-gate * if we get here, then some portion of the device path is 159*0Sstevel@tonic-gate * not understood by the prom. We need to look for alternate 160*0Sstevel@tonic-gate * names (e.g. replace ssd by disk) and mpxio enabled devices. 161*0Sstevel@tonic-gate */ 162*0Sstevel@tonic-gate dip = e_ddi_hold_devi_by_path(dev_name, 0); 163*0Sstevel@tonic-gate if (dip == NULL) { 164*0Sstevel@tonic-gate cmn_err(CE_NOTE, "cannot find dip for %s", dev_name); 165*0Sstevel@tonic-gate kmem_free(dev_path, MAXPATHLEN); 166*0Sstevel@tonic-gate return (EINVAL); 167*0Sstevel@tonic-gate } 168*0Sstevel@tonic-gate 169*0Sstevel@tonic-gate /* find the closest ancestor which is a prom node */ 170*0Sstevel@tonic-gate pdip = dip; 171*0Sstevel@tonic-gate parinfo = kmem_alloc(OBP_STACKDEPTH * sizeof (*parinfo), KM_SLEEP); 172*0Sstevel@tonic-gate for (depth = 0; ndi_dev_is_prom_node(pdip) == 0; depth++) { 173*0Sstevel@tonic-gate if (depth == OBP_STACKDEPTH) { 174*0Sstevel@tonic-gate kmem_free(dev_path, MAXPATHLEN); 175*0Sstevel@tonic-gate kmem_free(parinfo, OBP_STACKDEPTH * sizeof (*parinfo)); 176*0Sstevel@tonic-gate return (EINVAL); /* must not have been an obp node */ 177*0Sstevel@tonic-gate } 178*0Sstevel@tonic-gate 179*0Sstevel@tonic-gate pdip = get_path_parent(pdip, &parinfo[depth]); 180*0Sstevel@tonic-gate } 181*0Sstevel@tonic-gate ASSERT(pdip); /* at least root is prom node */ 182*0Sstevel@tonic-gate ASSERT(depth > 0); 183*0Sstevel@tonic-gate 184*0Sstevel@tonic-gate prom_path = kmem_alloc(MAXPATHLEN, KM_SLEEP); 185*0Sstevel@tonic-gate 186*0Sstevel@tonic-gate offline = kmem_zalloc(len, KM_SLEEP); /* offline paths */ 187*0Sstevel@tonic-gate olen = len; 188*0Sstevel@tonic-gate rlen = len; 189*0Sstevel@tonic-gate 190*0Sstevel@tonic-gate rptr = ret_buf; 191*0Sstevel@tonic-gate optr = offline; 192*0Sstevel@tonic-gate 193*0Sstevel@tonic-gate old_depth = depth; 194*0Sstevel@tonic-gate do { 195*0Sstevel@tonic-gate bzero(prom_path, MAXPATHLEN); 196*0Sstevel@tonic-gate if (pdip) 197*0Sstevel@tonic-gate (void) ddi_pathname(pdip, prom_path); 198*0Sstevel@tonic-gate 199*0Sstevel@tonic-gate ndi_hold_devi(pdip); 200*0Sstevel@tonic-gate for (depth = old_depth; depth > 0; depth--) { 201*0Sstevel@tonic-gate info = &parinfo[depth - 1]; 202*0Sstevel@tonic-gate idip = info->dip; 203*0Sstevel@tonic-gate 204*0Sstevel@tonic-gate nodename = ddi_node_name(idip); 205*0Sstevel@tonic-gate if (info->pip) { 206*0Sstevel@tonic-gate unit_address = MDI_PI(info->pip)->pi_addr; 207*0Sstevel@tonic-gate } else { 208*0Sstevel@tonic-gate unit_address = ddi_get_name_addr(idip); 209*0Sstevel@tonic-gate } 210*0Sstevel@tonic-gate 211*0Sstevel@tonic-gate if (pdip) { 212*0Sstevel@tonic-gate major = ddi_driver_major(idip); 213*0Sstevel@tonic-gate cdip = find_alternate_node(pdip, major); 214*0Sstevel@tonic-gate ndi_rele_devi(pdip); 215*0Sstevel@tonic-gate if (cdip) { 216*0Sstevel@tonic-gate nodename = ddi_node_name(cdip); 217*0Sstevel@tonic-gate } 218*0Sstevel@tonic-gate } 219*0Sstevel@tonic-gate 220*0Sstevel@tonic-gate /* 221*0Sstevel@tonic-gate * node name + unitaddr to the prom_path 222*0Sstevel@tonic-gate */ 223*0Sstevel@tonic-gate (void) strcat(prom_path, "/"); 224*0Sstevel@tonic-gate (void) strcat(prom_path, nodename); 225*0Sstevel@tonic-gate if (unit_address && (*unit_address)) { 226*0Sstevel@tonic-gate (void) strcat(prom_path, "@"); 227*0Sstevel@tonic-gate (void) strcat(prom_path, unit_address); 228*0Sstevel@tonic-gate } 229*0Sstevel@tonic-gate pdip = cdip; 230*0Sstevel@tonic-gate } 231*0Sstevel@tonic-gate 232*0Sstevel@tonic-gate if (pdip) { 233*0Sstevel@tonic-gate ndi_rele_devi(pdip); /* hold from find_alternate_node */ 234*0Sstevel@tonic-gate } 235*0Sstevel@tonic-gate 236*0Sstevel@tonic-gate minorname = strrchr(dev_name, ':'); 237*0Sstevel@tonic-gate if (minorname && (minorname[1] != '\0')) { 238*0Sstevel@tonic-gate (void) strcat(prom_path, minorname); 239*0Sstevel@tonic-gate } 240*0Sstevel@tonic-gate 241*0Sstevel@tonic-gate if (!info || !info->pip || MDI_PI_IS_ONLINE(info->pip)) { 242*0Sstevel@tonic-gate (void) snprintf(rptr, rlen, "%s", prom_path); 243*0Sstevel@tonic-gate rlen -= strlen(rptr) + 1; 244*0Sstevel@tonic-gate rptr += strlen(rptr) + 1; 245*0Sstevel@tonic-gate if (rlen <= 0) /* drop paths we can't store */ 246*0Sstevel@tonic-gate break; 247*0Sstevel@tonic-gate } else { /* path is offline */ 248*0Sstevel@tonic-gate (void) snprintf(optr, olen, "%s", prom_path); 249*0Sstevel@tonic-gate olen -= strlen(optr) + 1; 250*0Sstevel@tonic-gate if (olen > 0) /* drop paths we can't store */ 251*0Sstevel@tonic-gate optr += strlen(optr) + 1; 252*0Sstevel@tonic-gate 253*0Sstevel@tonic-gate } 254*0Sstevel@tonic-gate 255*0Sstevel@tonic-gate /* 256*0Sstevel@tonic-gate * The following code assumes that the phci client is at leaf 257*0Sstevel@tonic-gate * level and that all phci nodes are prom nodes. 258*0Sstevel@tonic-gate */ 259*0Sstevel@tonic-gate info = &parinfo[0]; 260*0Sstevel@tonic-gate if (info && info->dip && info->pip) { 261*0Sstevel@tonic-gate info->pip = 262*0Sstevel@tonic-gate (mdi_pathinfo_t *)MDI_PI(info->pip)->pi_client_link; 263*0Sstevel@tonic-gate if (info->pip) { 264*0Sstevel@tonic-gate pdip = mdi_pi_get_phci(info->pip); 265*0Sstevel@tonic-gate pdip = ddi_get_parent(pdip); 266*0Sstevel@tonic-gate } else { 267*0Sstevel@tonic-gate break; 268*0Sstevel@tonic-gate } 269*0Sstevel@tonic-gate } else { 270*0Sstevel@tonic-gate break; 271*0Sstevel@tonic-gate } 272*0Sstevel@tonic-gate 273*0Sstevel@tonic-gate } while (info && info->pip && pdip); 274*0Sstevel@tonic-gate 275*0Sstevel@tonic-gate ndi_rele_devi(dip); /* release hold from e_ddi_hold_devi_by_path() */ 276*0Sstevel@tonic-gate 277*0Sstevel@tonic-gate /* release holds from get_path_parent() */ 278*0Sstevel@tonic-gate for (depth = old_depth; depth > 0; depth--) { 279*0Sstevel@tonic-gate info = &parinfo[depth - 1]; 280*0Sstevel@tonic-gate 281*0Sstevel@tonic-gate /* replace with mdi_rele_path() when mpxio goes into genunix */ 282*0Sstevel@tonic-gate if (info && info->pip) { 283*0Sstevel@tonic-gate MDI_PI_LOCK(info->pip); 284*0Sstevel@tonic-gate MDI_PI_RELE(info->pip); 285*0Sstevel@tonic-gate if (MDI_PI(info->pip)->pi_ref_cnt == 0) 286*0Sstevel@tonic-gate cv_broadcast(&MDI_PI(info->pip)->pi_ref_cv); 287*0Sstevel@tonic-gate MDI_PI_UNLOCK(info->pip); 288*0Sstevel@tonic-gate } 289*0Sstevel@tonic-gate if (info && info->pdip) 290*0Sstevel@tonic-gate ndi_rele_devi(info->pdip); 291*0Sstevel@tonic-gate } 292*0Sstevel@tonic-gate 293*0Sstevel@tonic-gate /* now add as much of offline to ret_buf as possible */ 294*0Sstevel@tonic-gate bcopy(offline, rptr, rlen); 295*0Sstevel@tonic-gate 296*0Sstevel@tonic-gate ret_buf[len - 1] = '\0'; 297*0Sstevel@tonic-gate ret_buf[len - 2] = '\0'; 298*0Sstevel@tonic-gate 299*0Sstevel@tonic-gate kmem_free(offline, len); 300*0Sstevel@tonic-gate kmem_free(dev_path, MAXPATHLEN); 301*0Sstevel@tonic-gate kmem_free(prom_path, MAXPATHLEN); 302*0Sstevel@tonic-gate kmem_free(parinfo, OBP_STACKDEPTH * sizeof (*parinfo)); 303*0Sstevel@tonic-gate return (0); 304*0Sstevel@tonic-gate } 305*0Sstevel@tonic-gate 306*0Sstevel@tonic-gate /* 307*0Sstevel@tonic-gate * check for a possible substitute node. This routine searches the 308*0Sstevel@tonic-gate * children of parent_dip, looking for a node that: 309*0Sstevel@tonic-gate * 1. is a prom node 310*0Sstevel@tonic-gate * 2. binds to the same major number 311*0Sstevel@tonic-gate * 3. there is no need to verify that the unit-address information 312*0Sstevel@tonic-gate * match since it is likely that the substitute node 313*0Sstevel@tonic-gate * will have none (e.g. disk) - this would be the reason the 314*0Sstevel@tonic-gate * framework rejected it in the first place. 315*0Sstevel@tonic-gate * 316*0Sstevel@tonic-gate * assumes parent_dip is held 317*0Sstevel@tonic-gate */ 318*0Sstevel@tonic-gate static dev_info_t * 319*0Sstevel@tonic-gate find_alternate_node(dev_info_t *parent_dip, major_t major) 320*0Sstevel@tonic-gate { 321*0Sstevel@tonic-gate int circ; 322*0Sstevel@tonic-gate dev_info_t *child_dip; 323*0Sstevel@tonic-gate 324*0Sstevel@tonic-gate /* lock down parent to keep children from being removed */ 325*0Sstevel@tonic-gate ndi_devi_enter(parent_dip, &circ); 326*0Sstevel@tonic-gate for (child_dip = ddi_get_child(parent_dip); child_dip != NULL; 327*0Sstevel@tonic-gate child_dip = ddi_get_next_sibling(child_dip)) { 328*0Sstevel@tonic-gate 329*0Sstevel@tonic-gate /* look for obp node with matching major */ 330*0Sstevel@tonic-gate if ((ndi_dev_is_prom_node(child_dip) != 0) && 331*0Sstevel@tonic-gate (ddi_driver_major(child_dip) == major)) { 332*0Sstevel@tonic-gate ndi_hold_devi(child_dip); 333*0Sstevel@tonic-gate break; 334*0Sstevel@tonic-gate } 335*0Sstevel@tonic-gate } 336*0Sstevel@tonic-gate ndi_devi_exit(parent_dip, circ); 337*0Sstevel@tonic-gate return (child_dip); 338*0Sstevel@tonic-gate } 339*0Sstevel@tonic-gate 340*0Sstevel@tonic-gate /* 341*0Sstevel@tonic-gate * given an absolute pathname, convert it, if possible, to a devfs 342*0Sstevel@tonic-gate * name. Examples: 343*0Sstevel@tonic-gate * /dev/rsd3a to /pci@1f,4000/glm@3/sd@0,0:a 344*0Sstevel@tonic-gate * /dev/dsk/c0t0d0s0 to /pci@1f,4000/glm@3/sd@0,0:a 345*0Sstevel@tonic-gate * /devices/pci@1f,4000/glm@3/sd@0,0:a to /pci@1f,4000/glm@3/sd@0,0:a 346*0Sstevel@tonic-gate * /pci@1f,4000/glm@3/sd@0,0:a unchanged 347*0Sstevel@tonic-gate * 348*0Sstevel@tonic-gate * This routine deals with symbolic links, physical pathname with and 349*0Sstevel@tonic-gate * without /devices stripped. Returns 0 on success or -1 on failure. 350*0Sstevel@tonic-gate */ 351*0Sstevel@tonic-gate static int 352*0Sstevel@tonic-gate resolve_devfs_name(char *name, char *buffer) 353*0Sstevel@tonic-gate { 354*0Sstevel@tonic-gate int error; 355*0Sstevel@tonic-gate char *fullname = NULL; 356*0Sstevel@tonic-gate struct pathname pn, rpn; 357*0Sstevel@tonic-gate 358*0Sstevel@tonic-gate /* if not a /dev or /device name, prepend /devices */ 359*0Sstevel@tonic-gate if (strncmp(name, "/dev/", 5) != 0 && 360*0Sstevel@tonic-gate strncmp(name, "/devices/", 9) != 0) { 361*0Sstevel@tonic-gate fullname = kmem_alloc(MAXPATHLEN, KM_SLEEP); 362*0Sstevel@tonic-gate (void) snprintf(fullname, MAXPATHLEN, "/devices%s", name); 363*0Sstevel@tonic-gate name = fullname; 364*0Sstevel@tonic-gate } 365*0Sstevel@tonic-gate 366*0Sstevel@tonic-gate if (pn_get(name, UIO_SYSSPACE, &pn) != 0) { 367*0Sstevel@tonic-gate if (fullname) 368*0Sstevel@tonic-gate kmem_free(fullname, MAXPATHLEN); 369*0Sstevel@tonic-gate return (-1); 370*0Sstevel@tonic-gate } 371*0Sstevel@tonic-gate 372*0Sstevel@tonic-gate pn_alloc(&rpn); 373*0Sstevel@tonic-gate error = lookuppn(&pn, &rpn, FOLLOW, NULL, NULL); 374*0Sstevel@tonic-gate if (error == 0) 375*0Sstevel@tonic-gate bcopy(rpn.pn_path, buffer, rpn.pn_pathlen); 376*0Sstevel@tonic-gate 377*0Sstevel@tonic-gate pn_free(&pn); 378*0Sstevel@tonic-gate pn_free(&rpn); 379*0Sstevel@tonic-gate if (fullname) 380*0Sstevel@tonic-gate kmem_free(fullname, MAXPATHLEN); 381*0Sstevel@tonic-gate 382*0Sstevel@tonic-gate return (error); 383*0Sstevel@tonic-gate } 384*0Sstevel@tonic-gate 385*0Sstevel@tonic-gate /* 386*0Sstevel@tonic-gate * If bootstring contains a device path, we need to convert to a format 387*0Sstevel@tonic-gate * the prom will understand. To do so, we convert the existing path to 388*0Sstevel@tonic-gate * a prom-compatible path and return the value of new_path. If the 389*0Sstevel@tonic-gate * caller specifies new_path as NULL, we allocate an appropriately 390*0Sstevel@tonic-gate * sized new_path on behalf of the caller. If the caller invokes this 391*0Sstevel@tonic-gate * function with new_path = NULL, they must do so from a context in 392*0Sstevel@tonic-gate * which it is safe to perform a sleeping memory allocation. 393*0Sstevel@tonic-gate */ 394*0Sstevel@tonic-gate char * 395*0Sstevel@tonic-gate i_convert_boot_device_name(char *cur_path, char *new_path, size_t *len) 396*0Sstevel@tonic-gate { 397*0Sstevel@tonic-gate char *ptr; 398*0Sstevel@tonic-gate int rval; 399*0Sstevel@tonic-gate 400*0Sstevel@tonic-gate ASSERT(cur_path != NULL && len != NULL); 401*0Sstevel@tonic-gate ASSERT(new_path == NULL || *len >= MAXPATHLEN); 402*0Sstevel@tonic-gate 403*0Sstevel@tonic-gate if (new_path == NULL) { 404*0Sstevel@tonic-gate *len = MAXPATHLEN + MAXNAMELEN; 405*0Sstevel@tonic-gate new_path = kmem_alloc(*len, KM_SLEEP); 406*0Sstevel@tonic-gate } 407*0Sstevel@tonic-gate 408*0Sstevel@tonic-gate if ((ptr = strchr(cur_path, ' ')) != NULL) 409*0Sstevel@tonic-gate *ptr = '\0'; 410*0Sstevel@tonic-gate 411*0Sstevel@tonic-gate rval = i_devname_to_promname(cur_path, new_path, *len); 412*0Sstevel@tonic-gate 413*0Sstevel@tonic-gate if (ptr != NULL) 414*0Sstevel@tonic-gate *ptr = ' '; 415*0Sstevel@tonic-gate 416*0Sstevel@tonic-gate if (rval == 0) { 417*0Sstevel@tonic-gate if (ptr != NULL) { 418*0Sstevel@tonic-gate (void) snprintf(new_path + strlen(new_path), 419*0Sstevel@tonic-gate *len - strlen(new_path), "%s", ptr); 420*0Sstevel@tonic-gate } 421*0Sstevel@tonic-gate } else { /* the conversion failed */ 422*0Sstevel@tonic-gate (void) snprintf(new_path, *len, "%s", cur_path); 423*0Sstevel@tonic-gate } 424*0Sstevel@tonic-gate 425*0Sstevel@tonic-gate return (new_path); 426*0Sstevel@tonic-gate } 427*0Sstevel@tonic-gate 428*0Sstevel@tonic-gate /* 429*0Sstevel@tonic-gate * Get the parent dip. If dip is mpxio client, get the first online 430*0Sstevel@tonic-gate * path and return the phci dip with both pathinfo and dip held 431*0Sstevel@tonic-gate * otherwise just return with the dip held. 432*0Sstevel@tonic-gate */ 433*0Sstevel@tonic-gate static dev_info_t * 434*0Sstevel@tonic-gate get_path_parent(dev_info_t *dip, struct parinfo *info) 435*0Sstevel@tonic-gate { 436*0Sstevel@tonic-gate dev_info_t *pdip; 437*0Sstevel@tonic-gate mdi_pathinfo_t *pip; 438*0Sstevel@tonic-gate int circ; 439*0Sstevel@tonic-gate 440*0Sstevel@tonic-gate if (!MDI_CLIENT(dip)) { 441*0Sstevel@tonic-gate pdip = ddi_get_parent(dip); 442*0Sstevel@tonic-gate pip = NULL; 443*0Sstevel@tonic-gate goto finish; 444*0Sstevel@tonic-gate } 445*0Sstevel@tonic-gate 446*0Sstevel@tonic-gate /* find and hold the pathinfo */ 447*0Sstevel@tonic-gate 448*0Sstevel@tonic-gate ndi_devi_enter(dip, &circ); 449*0Sstevel@tonic-gate pip = mdi_get_next_phci_path(dip, NULL); 450*0Sstevel@tonic-gate 451*0Sstevel@tonic-gate if (pip == NULL) { 452*0Sstevel@tonic-gate ndi_devi_exit(dip, circ); 453*0Sstevel@tonic-gate return (NULL); 454*0Sstevel@tonic-gate } 455*0Sstevel@tonic-gate 456*0Sstevel@tonic-gate /* replace with mdi_hold_path() when mpxio goes into genunix */ 457*0Sstevel@tonic-gate MDI_PI_LOCK(pip); 458*0Sstevel@tonic-gate MDI_PI_HOLD(pip); 459*0Sstevel@tonic-gate MDI_PI_UNLOCK(pip); 460*0Sstevel@tonic-gate 461*0Sstevel@tonic-gate ndi_devi_exit(dip, circ); 462*0Sstevel@tonic-gate pdip = mdi_pi_get_phci(pip); 463*0Sstevel@tonic-gate 464*0Sstevel@tonic-gate finish: 465*0Sstevel@tonic-gate ndi_hold_devi(pdip); 466*0Sstevel@tonic-gate 467*0Sstevel@tonic-gate info->dip = dip; 468*0Sstevel@tonic-gate info->pip = pip; 469*0Sstevel@tonic-gate info->pdip = pdip; 470*0Sstevel@tonic-gate return (pdip); 471*0Sstevel@tonic-gate } 472