xref: /illumos-gate/usr/src/psm/promif/ieee1275/common/prom_2path.c (revision 89b2a9fbeabf42fa54594df0e5927bcc50a07cc9)
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 1991-1994,1998,2002 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/promif.h>
30 #include <sys/promimpl.h>
31 
32 static int token2path(char *svc, uint_t token, char *buf, uint_t len);
33 
34 int
35 prom_ihandle_to_path(ihandle_t instance, char *buf, uint_t len)
36 {
37 	return (token2path("instance-to-path", (uint_t)instance, buf, len));
38 }
39 
40 int
41 prom_phandle_to_path(phandle_t package, char *buf, uint_t len)
42 {
43 	return (token2path("package-to-path", (uint_t)package, buf, len));
44 }
45 
46 static int
47 token2path(char *service, uint_t token, char *buf, uint_t len)
48 {
49 	cell_t ci[7];
50 	int rv;
51 #ifdef PROM_32BIT_ADDRS
52 	char *obuf = NULL;
53 
54 	if ((uintptr_t)buf > (uint32_t)-1) {
55 		obuf = buf;
56 		buf = promplat_alloc(len);
57 		if (buf == NULL) {
58 			return (-1);
59 		}
60 	}
61 #endif
62 
63 	promif_preprom();
64 
65 	ci[0] = p1275_ptr2cell(service);	/* Service name */
66 	ci[1] = 3;				/* #argument cells */
67 	ci[2] = 1;				/* #return cells */
68 	ci[3] = p1275_uint2cell(token);		/* Arg1: ihandle/phandle */
69 	ci[4] = p1275_ptr2cell(buf);		/* Arg2: Result buffer */
70 	ci[5] = p1275_uint2cell(len);		/* Arg3: Buffer len */
71 	rv = p1275_cif_handler(&ci);
72 
73 	promif_postprom();
74 
75 #ifdef PROM_32BIT_ADDRS
76 	if (obuf != NULL) {
77 		promplat_bcopy(buf, obuf, len);
78 		promplat_free(buf, len);
79 	}
80 #endif
81 
82 	if (rv != 0)
83 		return (-1);
84 	return (p1275_cell2int(ci[6]));		/* Res1: Actual length */
85 }
86