15648Ssetje /*
25648Ssetje * CDDL HEADER START
35648Ssetje *
45648Ssetje * The contents of this file are subject to the terms of the
55648Ssetje * Common Development and Distribution License (the "License").
65648Ssetje * You may not use this file except in compliance with the License.
75648Ssetje *
85648Ssetje * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95648Ssetje * or http://www.opensolaris.org/os/licensing.
105648Ssetje * See the License for the specific language governing permissions
115648Ssetje * and limitations under the License.
125648Ssetje *
135648Ssetje * When distributing Covered Code, include this CDDL HEADER in each
145648Ssetje * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155648Ssetje * If applicable, add the following below this CDDL HEADER, with the
165648Ssetje * fields enclosed by brackets "[]" replaced with your own identifying
175648Ssetje * information: Portions Copyright [yyyy] [name of copyright owner]
185648Ssetje *
195648Ssetje * CDDL HEADER END
205648Ssetje */
215648Ssetje
225648Ssetje /*
23*6423Sgw25295 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
245648Ssetje * Use is subject to license terms.
255648Ssetje */
265648Ssetje
275648Ssetje #pragma ident "%Z%%M% %I% %E% SMI"
285648Ssetje
295648Ssetje #include <sys/promif.h>
305648Ssetje #include <sys/promimpl.h>
315648Ssetje
325648Ssetje int
prom_fopen(ihandle_t fsih,char * path)335648Ssetje prom_fopen(ihandle_t fsih, char *path)
345648Ssetje {
355648Ssetje cell_t ci[10];
365648Ssetje size_t len;
375648Ssetje
385648Ssetje #ifdef PROM_32BIT_ADDRS
395648Ssetje char *opath = NULL;
405648Ssetje
415648Ssetje if ((uintptr_t)path > (uint32_t)-1) {
425648Ssetje opath = path;
435648Ssetje len = prom_strlen(opath) + 1; /* include terminating NUL */
445648Ssetje path = promplat_alloc(len);
455648Ssetje if (path == NULL)
465648Ssetje return (0);
475648Ssetje (void) prom_strcpy(path, opath);
485648Ssetje }
495648Ssetje #endif
505648Ssetje len = prom_strlen(path);
515648Ssetje
525648Ssetje promif_preprom();
535648Ssetje ci[0] = p1275_ptr2cell("call-method"); /* Service name */
545648Ssetje ci[1] = (cell_t)4; /* #argument cells */
555648Ssetje ci[2] = (cell_t)3; /* #result cells */
565648Ssetje ci[3] = p1275_ptr2cell("open-file"); /* Arg1: Method name */
575648Ssetje ci[4] = p1275_ihandle2cell(fsih); /* Arg2: fs ihandle */
585648Ssetje ci[5] = p1275_uint2cell(len); /* Arg3: Len */
595648Ssetje ci[6] = p1275_ptr2cell(path); /* Arg4: Pathname */
605648Ssetje
615648Ssetje (void) p1275_cif_handler(&ci);
625648Ssetje
635648Ssetje promif_postprom();
645648Ssetje
655648Ssetje #ifdef PROM_32BIT_ADDRS
665648Ssetje if (opath != NULL)
675648Ssetje promplat_free(path, len + 1);
685648Ssetje #endif
695648Ssetje
705648Ssetje if (ci[7] != 0) /* Catch result */
715648Ssetje return (-1);
725648Ssetje
735648Ssetje if (ci[8] == 0) /* Res1: failed */
745648Ssetje return (-1);
755648Ssetje
765648Ssetje return (p1275_cell2int(ci[9])); /* Res2: fd */
775648Ssetje }
785648Ssetje
79*6423Sgw25295 int
prom_volopen(ihandle_t fsih,char * path)80*6423Sgw25295 prom_volopen(ihandle_t fsih, char *path)
81*6423Sgw25295 {
82*6423Sgw25295 cell_t ci[10];
83*6423Sgw25295 size_t len;
84*6423Sgw25295
85*6423Sgw25295 #ifdef PROM_32BIT_ADDRS
86*6423Sgw25295 char *opath = NULL;
87*6423Sgw25295
88*6423Sgw25295 if ((uintptr_t)path > (uint32_t)-1) {
89*6423Sgw25295 opath = path;
90*6423Sgw25295 len = prom_strlen(opath) + 1; /* include terminating NUL */
91*6423Sgw25295 path = promplat_alloc(len);
92*6423Sgw25295 if (path == NULL)
93*6423Sgw25295 return (0);
94*6423Sgw25295 (void) prom_strcpy(path, opath);
95*6423Sgw25295 }
96*6423Sgw25295 #endif
97*6423Sgw25295 len = prom_strlen(path);
98*6423Sgw25295
99*6423Sgw25295 promif_preprom();
100*6423Sgw25295 ci[0] = p1275_ptr2cell("call-method"); /* Service name */
101*6423Sgw25295 ci[1] = (cell_t)4; /* #argument cells */
102*6423Sgw25295 ci[2] = (cell_t)3; /* #result cells */
103*6423Sgw25295 ci[3] = p1275_ptr2cell("open-volume"); /* Arg1: Method name */
104*6423Sgw25295 ci[4] = p1275_ihandle2cell(fsih); /* Arg2: fs ihandle */
105*6423Sgw25295 ci[5] = p1275_uint2cell(len); /* Arg3: Len */
106*6423Sgw25295 ci[6] = p1275_ptr2cell(path); /* Arg4: Pathname */
107*6423Sgw25295
108*6423Sgw25295 (void) p1275_cif_handler(&ci);
109*6423Sgw25295
110*6423Sgw25295 promif_postprom();
111*6423Sgw25295
112*6423Sgw25295 #ifdef PROM_32BIT_ADDRS
113*6423Sgw25295 if (opath != NULL)
114*6423Sgw25295 promplat_free(path, len + 1);
115*6423Sgw25295 #endif
116*6423Sgw25295
117*6423Sgw25295 if (ci[7] != 0) /* Catch result */
118*6423Sgw25295 return (-1);
119*6423Sgw25295
120*6423Sgw25295 if (ci[8] == 0) /* Res1: failed */
121*6423Sgw25295 return (-1);
122*6423Sgw25295
123*6423Sgw25295 return (p1275_cell2int(ci[9])); /* Res2: fd */
124*6423Sgw25295 }
1255648Ssetje
1265648Ssetje int
prom_fseek(ihandle_t fsih,int fd,unsigned long long offset)1275648Ssetje prom_fseek(ihandle_t fsih, int fd, unsigned long long offset)
1285648Ssetje {
1295648Ssetje cell_t ci[10];
1305648Ssetje
1315648Ssetje ci[0] = p1275_ptr2cell("call-method"); /* Service name */
1325648Ssetje ci[1] = (cell_t)4; /* #argument cells */
1335648Ssetje ci[2] = (cell_t)3; /* #result cells */
1345648Ssetje ci[3] = p1275_ptr2cell("seek-file"); /* Arg1: Method name */
1355648Ssetje ci[4] = p1275_ihandle2cell(fsih); /* Arg2: fs ihandle */
1365648Ssetje ci[5] = p1275_int2cell(fd); /* Arg3: file desc */
1375648Ssetje ci[6] = p1275_ull2cell_low(offset); /* Arg4: Offset */
1385648Ssetje
1395648Ssetje promif_preprom();
1405648Ssetje (void) p1275_cif_handler(&ci);
1415648Ssetje promif_postprom();
1425648Ssetje
1435648Ssetje if (ci[7] != 0) /* Catch result */
1445648Ssetje return (-1);
1455648Ssetje
1465648Ssetje if (ci[8] == 0) /* Res1: failed */
1475648Ssetje return (-1);
1485648Ssetje
1495648Ssetje return (p1275_cell2int(ci[9])); /* Res2: off */
1505648Ssetje }
1515648Ssetje
1525648Ssetje
1535648Ssetje int
prom_fread(ihandle_t fsih,int fd,caddr_t buf,size_t len)1545648Ssetje prom_fread(ihandle_t fsih, int fd, caddr_t buf, size_t len)
1555648Ssetje {
1565648Ssetje cell_t ci[10];
1575648Ssetje #ifdef PROM_32BIT_ADDRS
1585648Ssetje caddr_t obuf = NULL;
1595648Ssetje
1605648Ssetje if ((uintptr_t)buf > (uint32_t)-1) {
1615648Ssetje obuf = buf;
1625648Ssetje buf = promplat_alloc(len);
1635648Ssetje if (buf == NULL)
1645648Ssetje return (-1);
1655648Ssetje }
1665648Ssetje #endif
1675648Ssetje
1685648Ssetje promif_preprom();
1695648Ssetje
1705648Ssetje ci[0] = p1275_ptr2cell("call-method"); /* Service name */
1715648Ssetje ci[1] = (cell_t)5; /* #argument cells */
1725648Ssetje ci[2] = (cell_t)2; /* #result cells */
1735648Ssetje ci[3] = p1275_ptr2cell("read-file"); /* Arg1: Method name */
1745648Ssetje ci[4] = p1275_ihandle2cell(fsih); /* Arg2: fs ihandle */
1755648Ssetje ci[5] = p1275_int2cell(fd); /* Arg3: file desc */
1765648Ssetje ci[6] = p1275_uint2cell(len); /* Arg4: buffer length */
1775648Ssetje ci[7] = p1275_ptr2cell(buf); /* Arg5: buffer address */
1785648Ssetje
1795648Ssetje (void) p1275_cif_handler(&ci);
1805648Ssetje
1815648Ssetje promif_postprom();
1825648Ssetje
1835648Ssetje #ifdef PROM_32BIT_ADDRS
1845648Ssetje if (obuf != NULL) {
1855648Ssetje promplat_bcopy(buf, obuf, len);
1865648Ssetje promplat_free(buf, len);
1875648Ssetje }
1885648Ssetje #endif
1895648Ssetje
1905648Ssetje if (ci[8] != 0) /* Catch result */
1915648Ssetje return (-1);
1925648Ssetje
1935648Ssetje return (p1275_cell2int(ci[9])); /* Res2: actual length */
1945648Ssetje }
1955648Ssetje
1965648Ssetje int
prom_fsize(ihandle_t fsih,int fd,size_t * size)1975648Ssetje prom_fsize(ihandle_t fsih, int fd, size_t *size)
1985648Ssetje {
1995648Ssetje cell_t ci[8];
2005648Ssetje
2015648Ssetje promif_preprom();
2025648Ssetje
2035648Ssetje ci[0] = p1275_ptr2cell("call-method"); /* Service name */
2045648Ssetje ci[1] = (cell_t)3; /* #argument cells */
2055648Ssetje ci[2] = (cell_t)2; /* #result cells */
2065648Ssetje ci[3] = p1275_ptr2cell("size-file"); /* Arg1: Method name */
2075648Ssetje ci[4] = p1275_ihandle2cell(fsih); /* Arg2: fs ihandle */
2085648Ssetje ci[5] = p1275_int2cell(fd); /* Arg3: file desc */
2095648Ssetje
2105648Ssetje (void) p1275_cif_handler(&ci);
2115648Ssetje
2125648Ssetje promif_postprom();
2135648Ssetje
2145648Ssetje if (ci[6] != 0) /* Catch result */
2155648Ssetje return (-1);
2165648Ssetje
2175648Ssetje *size = p1275_cell2uint(ci[7]); /* Res2: size */
2185648Ssetje return (0);
2195648Ssetje }
2205648Ssetje
2215648Ssetje
2225648Ssetje int
prom_compinfo(ihandle_t fsih,int fd,int * iscmp,size_t * fsize,size_t * bsize)2235648Ssetje prom_compinfo(ihandle_t fsih, int fd, int *iscmp, size_t *fsize, size_t *bsize)
2245648Ssetje {
2255648Ssetje cell_t ci[10];
2265648Ssetje
2275648Ssetje promif_preprom();
2285648Ssetje
2295648Ssetje ci[0] = p1275_ptr2cell("call-method"); /* Service name */
2305648Ssetje ci[1] = (cell_t)3; /* #argument cells */
2315648Ssetje ci[2] = (cell_t)4; /* #result cells */
2325648Ssetje ci[3] = p1275_ptr2cell("cinfo-file"); /* Arg1: Method name */
2335648Ssetje ci[4] = p1275_ihandle2cell(fsih); /* Arg2: fs ihandle */
2345648Ssetje ci[5] = p1275_int2cell(fd); /* Arg3: file desc */
2355648Ssetje
2365648Ssetje (void) p1275_cif_handler(&ci);
2375648Ssetje
2385648Ssetje promif_postprom();
2395648Ssetje
2405648Ssetje if (ci[6] != 0) /* Catch result */
2415648Ssetje return (-1);
2425648Ssetje
2435648Ssetje *iscmp = p1275_cell2int(ci[7]); /* Res2: iscmp */
2445648Ssetje *fsize = p1275_cell2uint(ci[8]); /* Res3: fsize */
2455648Ssetje *bsize = p1275_cell2uint(ci[9]); /* Res4: bsize */
2465648Ssetje return (0);
2475648Ssetje }
2485648Ssetje
2495648Ssetje void
prom_fclose(ihandle_t fsih,int fd)2505648Ssetje prom_fclose(ihandle_t fsih, int fd)
2515648Ssetje {
2525648Ssetje cell_t ci[7];
2535648Ssetje
2545648Ssetje ci[0] = p1275_ptr2cell("call-method"); /* Service name */
2555648Ssetje ci[1] = (cell_t)3; /* #argument cells */
2565648Ssetje ci[2] = (cell_t)1; /* #result cells */
2575648Ssetje ci[3] = p1275_ptr2cell("close-file"); /* Arg1: Method name */
2585648Ssetje ci[4] = p1275_ihandle2cell(fsih); /* Arg2: fs ihandle */
2595648Ssetje ci[5] = p1275_int2cell(fd); /* Arg3: file desc */
2605648Ssetje
2615648Ssetje promif_preprom();
2625648Ssetje (void) p1275_cif_handler(&ci);
2635648Ssetje promif_postprom();
2645648Ssetje
2655648Ssetje }
266