10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
220Sstevel@tonic-gate /*
23*7542SRichard.Bean@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #include <sys/modctl.h>
280Sstevel@tonic-gate #include <sys/sunddi.h>
290Sstevel@tonic-gate
300Sstevel@tonic-gate /* internal global data */
310Sstevel@tonic-gate static struct modlmisc modlmisc = {
32*7542SRichard.Bean@Sun.COM &mod_miscops, "bootdev misc module"
330Sstevel@tonic-gate };
340Sstevel@tonic-gate
350Sstevel@tonic-gate static struct modlinkage modlinkage = {
360Sstevel@tonic-gate MODREV_1, (void *)&modlmisc, NULL
370Sstevel@tonic-gate };
380Sstevel@tonic-gate
390Sstevel@tonic-gate int
_init()400Sstevel@tonic-gate _init()
410Sstevel@tonic-gate {
420Sstevel@tonic-gate return (mod_install(&modlinkage));
430Sstevel@tonic-gate }
440Sstevel@tonic-gate
450Sstevel@tonic-gate int
_fini()460Sstevel@tonic-gate _fini()
470Sstevel@tonic-gate {
480Sstevel@tonic-gate return (mod_remove(&modlinkage));
490Sstevel@tonic-gate }
500Sstevel@tonic-gate
510Sstevel@tonic-gate int
_info(struct modinfo * modinfop)520Sstevel@tonic-gate _info(struct modinfo *modinfop)
530Sstevel@tonic-gate {
540Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
550Sstevel@tonic-gate }
560Sstevel@tonic-gate
570Sstevel@tonic-gate /*
580Sstevel@tonic-gate * convert a prom device path to an equivalent path in /devices
590Sstevel@tonic-gate * Does not deal with aliases. Does deal with pathnames which
600Sstevel@tonic-gate * are not fully qualified. This routine is generalized
610Sstevel@tonic-gate * to work across several flavors of OBP
620Sstevel@tonic-gate */
630Sstevel@tonic-gate int
i_promname_to_devname(char * prom_name,char * ret_buf)640Sstevel@tonic-gate i_promname_to_devname(char *prom_name, char *ret_buf)
650Sstevel@tonic-gate {
660Sstevel@tonic-gate if (prom_name == NULL || ret_buf == NULL ||
670Sstevel@tonic-gate (strlen(prom_name) >= MAXPATHLEN)) {
680Sstevel@tonic-gate return (EINVAL);
690Sstevel@tonic-gate }
700Sstevel@tonic-gate if (i_ddi_prompath_to_devfspath(prom_name, ret_buf) != DDI_SUCCESS)
710Sstevel@tonic-gate return (EINVAL);
720Sstevel@tonic-gate
730Sstevel@tonic-gate return (0);
740Sstevel@tonic-gate }
750Sstevel@tonic-gate
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate * If bootstring contains a device path, we need to convert to a format
780Sstevel@tonic-gate * the prom will understand. To do so, we convert the existing path to
790Sstevel@tonic-gate * a prom-compatible path and return the value of new_path. If the
800Sstevel@tonic-gate * caller specifies new_path as NULL, we allocate an appropriately
810Sstevel@tonic-gate * sized new_path on behalf of the caller. If the caller invokes this
820Sstevel@tonic-gate * function with new_path = NULL, they must do so from a context in
830Sstevel@tonic-gate * which it is safe to perform a sleeping memory allocation.
840Sstevel@tonic-gate *
850Sstevel@tonic-gate * NOTE: Intel does not have a real PROM, so the implementation
860Sstevel@tonic-gate * simply returns a copy of the string passed in.
870Sstevel@tonic-gate */
880Sstevel@tonic-gate char *
i_convert_boot_device_name(char * cur_path,char * new_path,size_t * len)890Sstevel@tonic-gate i_convert_boot_device_name(char *cur_path, char *new_path, size_t *len)
900Sstevel@tonic-gate {
910Sstevel@tonic-gate if (new_path != NULL) {
920Sstevel@tonic-gate (void) snprintf(new_path, *len, "%s", cur_path);
930Sstevel@tonic-gate return (new_path);
940Sstevel@tonic-gate } else {
950Sstevel@tonic-gate *len = strlen(cur_path) + 1;
960Sstevel@tonic-gate new_path = kmem_alloc(*len, KM_SLEEP);
970Sstevel@tonic-gate (void) snprintf(new_path, *len, "%s", cur_path);
980Sstevel@tonic-gate return (new_path);
990Sstevel@tonic-gate }
1000Sstevel@tonic-gate }
101