xref: /titanic_50/usr/src/uts/intel/ia32/os/bootdev.c (revision 554ff184129088135ad2643c1c9832174a17be88)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/modctl.h>
30 #include <sys/sunddi.h>
31 
32 /* internal global data */
33 static struct modlmisc modlmisc = {
34 	&mod_miscops, "bootdev misc module %I%"
35 };
36 
37 static struct modlinkage modlinkage = {
38 	MODREV_1, (void *)&modlmisc, NULL
39 };
40 
41 int
42 _init()
43 {
44 	return (mod_install(&modlinkage));
45 }
46 
47 int
48 _fini()
49 {
50 	return (mod_remove(&modlinkage));
51 }
52 
53 int
54 _info(struct modinfo *modinfop)
55 {
56 	return (mod_info(&modlinkage, modinfop));
57 }
58 
59 /*
60  * convert a prom device path to an equivalent path in /devices
61  * Does not deal with aliases.  Does deal with pathnames which
62  * are not fully qualified.  This routine is generalized
63  * to work across several flavors of OBP
64  */
65 int
66 i_promname_to_devname(char *prom_name, char *ret_buf)
67 {
68 	if (prom_name == NULL || ret_buf == NULL ||
69 	    (strlen(prom_name) >= MAXPATHLEN)) {
70 		return (EINVAL);
71 	}
72 	if (i_ddi_prompath_to_devfspath(prom_name, ret_buf) != DDI_SUCCESS)
73 		return (EINVAL);
74 
75 	return (0);
76 }
77 
78 /*
79  * If bootstring contains a device path, we need to convert to a format
80  * the prom will understand.  To do so, we convert the existing path to
81  * a prom-compatible path and return the value of new_path.  If the
82  * caller specifies new_path as NULL, we allocate an appropriately
83  * sized new_path on behalf of the caller.  If the caller invokes this
84  * function with new_path = NULL, they must do so from a context in
85  * which it is safe to perform a sleeping memory allocation.
86  *
87  * NOTE: Intel does not have a real PROM, so the implementation
88  *       simply returns a copy of the string passed in.
89  */
90 char *
91 i_convert_boot_device_name(char *cur_path, char *new_path, size_t *len)
92 {
93 	if (new_path != NULL) {
94 		(void) snprintf(new_path, *len, "%s", cur_path);
95 		return (new_path);
96 	} else {
97 		*len = strlen(cur_path) + 1;
98 		new_path = kmem_alloc(*len, KM_SLEEP);
99 		(void) snprintf(new_path, *len, "%s", cur_path);
100 		return (new_path);
101 	}
102 }
103