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 2008 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#include <sys/modctl.h>
28#include <sys/sunddi.h>
29
30/* internal global data */
31static struct modlmisc modlmisc = {
32	&mod_miscops, "bootdev misc module"
33};
34
35static struct modlinkage modlinkage = {
36	MODREV_1, (void *)&modlmisc, NULL
37};
38
39int
40_init()
41{
42	return (mod_install(&modlinkage));
43}
44
45int
46_fini()
47{
48	return (mod_remove(&modlinkage));
49}
50
51int
52_info(struct modinfo *modinfop)
53{
54	return (mod_info(&modlinkage, modinfop));
55}
56
57/*
58 * convert a prom device path to an equivalent path in /devices
59 * Does not deal with aliases.  Does deal with pathnames which
60 * are not fully qualified.  This routine is generalized
61 * to work across several flavors of OBP
62 */
63int
64i_promname_to_devname(char *prom_name, char *ret_buf)
65{
66	if (prom_name == NULL || ret_buf == NULL ||
67	    (strlen(prom_name) >= MAXPATHLEN)) {
68		return (EINVAL);
69	}
70	if (i_ddi_prompath_to_devfspath(prom_name, ret_buf) != DDI_SUCCESS)
71		return (EINVAL);
72
73	return (0);
74}
75
76/*
77 * If bootstring contains a device path, we need to convert to a format
78 * the prom will understand.  To do so, we convert the existing path to
79 * a prom-compatible path and return the value of new_path.  If the
80 * caller specifies new_path as NULL, we allocate an appropriately
81 * sized new_path on behalf of the caller.  If the caller invokes this
82 * function with new_path = NULL, they must do so from a context in
83 * which it is safe to perform a sleeping memory allocation.
84 *
85 * NOTE: Intel does not have a real PROM, so the implementation
86 *       simply returns a copy of the string passed in.
87 */
88char *
89i_convert_boot_device_name(char *cur_path, char *new_path, size_t *len)
90{
91	if (new_path != NULL) {
92		(void) snprintf(new_path, *len, "%s", cur_path);
93		return (new_path);
94	} else {
95		*len = strlen(cur_path) + 1;
96		new_path = kmem_alloc(*len, KM_SLEEP);
97		(void) snprintf(new_path, *len, "%s", cur_path);
98		return (new_path);
99	}
100}
101