import less(1)
[unleashed/tickless.git] / usr / src / psm / promif / ieee1275 / common / prom_2path.c
blob50bdada053d77308aa1e7de2dc2ef6ac9c4aaa9a
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 1991-1994,1998,2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/promif.h>
30 #include <sys/promimpl.h>
32 static int token2path(char *svc, uint_t token, char *buf, uint_t len);
34 int
35 prom_ihandle_to_path(ihandle_t instance, char *buf, uint_t len)
37 return (token2path("instance-to-path", (uint_t)instance, buf, len));
40 int
41 prom_phandle_to_path(phandle_t package, char *buf, uint_t len)
43 return (token2path("package-to-path", (uint_t)package, buf, len));
46 static int
47 token2path(char *service, uint_t token, char *buf, uint_t len)
49 cell_t ci[7];
50 int rv;
51 #ifdef PROM_32BIT_ADDRS
52 char *obuf = NULL;
54 if ((uintptr_t)buf > (uint32_t)-1) {
55 obuf = buf;
56 buf = promplat_alloc(len);
57 if (buf == NULL) {
58 return (-1);
61 #endif
63 promif_preprom();
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);
73 promif_postprom();
75 #ifdef PROM_32BIT_ADDRS
76 if (obuf != NULL) {
77 promplat_bcopy(buf, obuf, len);
78 promplat_free(buf, len);
80 #endif
82 if (rv != 0)
83 return (-1);
84 return (p1275_cell2int(ci[6])); /* Res1: Actual length */