import less(1)
[unleashed/tickless.git] / usr / src / psm / promif / ieee1275 / sun4 / prom_fio.c
blob0e814d2bcc71c3fdfe3b61b1c826527a8ba19fbc
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2008 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 int
33 prom_fopen(ihandle_t fsih, char *path)
35 cell_t ci[10];
36 size_t len;
38 #ifdef PROM_32BIT_ADDRS
39 char *opath = NULL;
41 if ((uintptr_t)path > (uint32_t)-1) {
42 opath = path;
43 len = prom_strlen(opath) + 1; /* include terminating NUL */
44 path = promplat_alloc(len);
45 if (path == NULL)
46 return (0);
47 (void) prom_strcpy(path, opath);
49 #endif
50 len = prom_strlen(path);
52 promif_preprom();
53 ci[0] = p1275_ptr2cell("call-method"); /* Service name */
54 ci[1] = (cell_t)4; /* #argument cells */
55 ci[2] = (cell_t)3; /* #result cells */
56 ci[3] = p1275_ptr2cell("open-file"); /* Arg1: Method name */
57 ci[4] = p1275_ihandle2cell(fsih); /* Arg2: fs ihandle */
58 ci[5] = p1275_uint2cell(len); /* Arg3: Len */
59 ci[6] = p1275_ptr2cell(path); /* Arg4: Pathname */
61 (void) p1275_cif_handler(&ci);
63 promif_postprom();
65 #ifdef PROM_32BIT_ADDRS
66 if (opath != NULL)
67 promplat_free(path, len + 1);
68 #endif
70 if (ci[7] != 0) /* Catch result */
71 return (-1);
73 if (ci[8] == 0) /* Res1: failed */
74 return (-1);
76 return (p1275_cell2int(ci[9])); /* Res2: fd */
79 int
80 prom_volopen(ihandle_t fsih, char *path)
82 cell_t ci[10];
83 size_t len;
85 #ifdef PROM_32BIT_ADDRS
86 char *opath = NULL;
88 if ((uintptr_t)path > (uint32_t)-1) {
89 opath = path;
90 len = prom_strlen(opath) + 1; /* include terminating NUL */
91 path = promplat_alloc(len);
92 if (path == NULL)
93 return (0);
94 (void) prom_strcpy(path, opath);
96 #endif
97 len = prom_strlen(path);
99 promif_preprom();
100 ci[0] = p1275_ptr2cell("call-method"); /* Service name */
101 ci[1] = (cell_t)4; /* #argument cells */
102 ci[2] = (cell_t)3; /* #result cells */
103 ci[3] = p1275_ptr2cell("open-volume"); /* Arg1: Method name */
104 ci[4] = p1275_ihandle2cell(fsih); /* Arg2: fs ihandle */
105 ci[5] = p1275_uint2cell(len); /* Arg3: Len */
106 ci[6] = p1275_ptr2cell(path); /* Arg4: Pathname */
108 (void) p1275_cif_handler(&ci);
110 promif_postprom();
112 #ifdef PROM_32BIT_ADDRS
113 if (opath != NULL)
114 promplat_free(path, len + 1);
115 #endif
117 if (ci[7] != 0) /* Catch result */
118 return (-1);
120 if (ci[8] == 0) /* Res1: failed */
121 return (-1);
123 return (p1275_cell2int(ci[9])); /* Res2: fd */
127 prom_fseek(ihandle_t fsih, int fd, unsigned long long offset)
129 cell_t ci[10];
131 ci[0] = p1275_ptr2cell("call-method"); /* Service name */
132 ci[1] = (cell_t)4; /* #argument cells */
133 ci[2] = (cell_t)3; /* #result cells */
134 ci[3] = p1275_ptr2cell("seek-file"); /* Arg1: Method name */
135 ci[4] = p1275_ihandle2cell(fsih); /* Arg2: fs ihandle */
136 ci[5] = p1275_int2cell(fd); /* Arg3: file desc */
137 ci[6] = p1275_ull2cell_low(offset); /* Arg4: Offset */
139 promif_preprom();
140 (void) p1275_cif_handler(&ci);
141 promif_postprom();
143 if (ci[7] != 0) /* Catch result */
144 return (-1);
146 if (ci[8] == 0) /* Res1: failed */
147 return (-1);
149 return (p1275_cell2int(ci[9])); /* Res2: off */
154 prom_fread(ihandle_t fsih, int fd, caddr_t buf, size_t len)
156 cell_t ci[10];
157 #ifdef PROM_32BIT_ADDRS
158 caddr_t obuf = NULL;
160 if ((uintptr_t)buf > (uint32_t)-1) {
161 obuf = buf;
162 buf = promplat_alloc(len);
163 if (buf == NULL)
164 return (-1);
166 #endif
168 promif_preprom();
170 ci[0] = p1275_ptr2cell("call-method"); /* Service name */
171 ci[1] = (cell_t)5; /* #argument cells */
172 ci[2] = (cell_t)2; /* #result cells */
173 ci[3] = p1275_ptr2cell("read-file"); /* Arg1: Method name */
174 ci[4] = p1275_ihandle2cell(fsih); /* Arg2: fs ihandle */
175 ci[5] = p1275_int2cell(fd); /* Arg3: file desc */
176 ci[6] = p1275_uint2cell(len); /* Arg4: buffer length */
177 ci[7] = p1275_ptr2cell(buf); /* Arg5: buffer address */
179 (void) p1275_cif_handler(&ci);
181 promif_postprom();
183 #ifdef PROM_32BIT_ADDRS
184 if (obuf != NULL) {
185 promplat_bcopy(buf, obuf, len);
186 promplat_free(buf, len);
188 #endif
190 if (ci[8] != 0) /* Catch result */
191 return (-1);
193 return (p1275_cell2int(ci[9])); /* Res2: actual length */
197 prom_fsize(ihandle_t fsih, int fd, size_t *size)
199 cell_t ci[8];
201 promif_preprom();
203 ci[0] = p1275_ptr2cell("call-method"); /* Service name */
204 ci[1] = (cell_t)3; /* #argument cells */
205 ci[2] = (cell_t)2; /* #result cells */
206 ci[3] = p1275_ptr2cell("size-file"); /* Arg1: Method name */
207 ci[4] = p1275_ihandle2cell(fsih); /* Arg2: fs ihandle */
208 ci[5] = p1275_int2cell(fd); /* Arg3: file desc */
210 (void) p1275_cif_handler(&ci);
212 promif_postprom();
214 if (ci[6] != 0) /* Catch result */
215 return (-1);
217 *size = p1275_cell2uint(ci[7]); /* Res2: size */
218 return (0);
223 prom_compinfo(ihandle_t fsih, int fd, int *iscmp, size_t *fsize, size_t *bsize)
225 cell_t ci[10];
227 promif_preprom();
229 ci[0] = p1275_ptr2cell("call-method"); /* Service name */
230 ci[1] = (cell_t)3; /* #argument cells */
231 ci[2] = (cell_t)4; /* #result cells */
232 ci[3] = p1275_ptr2cell("cinfo-file"); /* Arg1: Method name */
233 ci[4] = p1275_ihandle2cell(fsih); /* Arg2: fs ihandle */
234 ci[5] = p1275_int2cell(fd); /* Arg3: file desc */
236 (void) p1275_cif_handler(&ci);
238 promif_postprom();
240 if (ci[6] != 0) /* Catch result */
241 return (-1);
243 *iscmp = p1275_cell2int(ci[7]); /* Res2: iscmp */
244 *fsize = p1275_cell2uint(ci[8]); /* Res3: fsize */
245 *bsize = p1275_cell2uint(ci[9]); /* Res4: bsize */
246 return (0);
249 void
250 prom_fclose(ihandle_t fsih, int fd)
252 cell_t ci[7];
254 ci[0] = p1275_ptr2cell("call-method"); /* Service name */
255 ci[1] = (cell_t)3; /* #argument cells */
256 ci[2] = (cell_t)1; /* #result cells */
257 ci[3] = p1275_ptr2cell("close-file"); /* Arg1: Method name */
258 ci[4] = p1275_ihandle2cell(fsih); /* Arg2: fs ihandle */
259 ci[5] = p1275_int2cell(fd); /* Arg3: file desc */
261 promif_preprom();
262 (void) p1275_cif_handler(&ci);
263 promif_postprom();