openfirm.c revision 1.1.2.3 1 1.1.2.3 nathanw /* $NetBSD: openfirm.c,v 1.1.2.3 2002/10/18 02:35:39 nathanw Exp $ */
2 1.1.2.2 nathanw
3 1.1.2.2 nathanw /*
4 1.1.2.2 nathanw * Copyright 1997
5 1.1.2.2 nathanw * Digital Equipment Corporation. All rights reserved.
6 1.1.2.2 nathanw *
7 1.1.2.2 nathanw * This software is furnished under license and may be used and
8 1.1.2.2 nathanw * copied only in accordance with the following terms and conditions.
9 1.1.2.2 nathanw * Subject to these conditions, you may download, copy, install,
10 1.1.2.2 nathanw * use, modify and distribute this software in source and/or binary
11 1.1.2.2 nathanw * form. No title or ownership is transferred hereby.
12 1.1.2.2 nathanw *
13 1.1.2.2 nathanw * 1) Any source code used, modified or distributed must reproduce
14 1.1.2.2 nathanw * and retain this copyright notice and list of conditions as
15 1.1.2.2 nathanw * they appear in the source file.
16 1.1.2.2 nathanw *
17 1.1.2.2 nathanw * 2) No right is granted to use any trade name, trademark, or logo of
18 1.1.2.2 nathanw * Digital Equipment Corporation. Neither the "Digital Equipment
19 1.1.2.2 nathanw * Corporation" name nor any trademark or logo of Digital Equipment
20 1.1.2.2 nathanw * Corporation may be used to endorse or promote products derived
21 1.1.2.2 nathanw * from this software without the prior written permission of
22 1.1.2.2 nathanw * Digital Equipment Corporation.
23 1.1.2.2 nathanw *
24 1.1.2.2 nathanw * 3) This software is provided "AS-IS" and any express or implied
25 1.1.2.2 nathanw * warranties, including but not limited to, any implied warranties
26 1.1.2.2 nathanw * of merchantability, fitness for a particular purpose, or
27 1.1.2.2 nathanw * non-infringement are disclaimed. In no event shall DIGITAL be
28 1.1.2.2 nathanw * liable for any damages whatsoever, and in particular, DIGITAL
29 1.1.2.2 nathanw * shall not be liable for special, indirect, consequential, or
30 1.1.2.2 nathanw * incidental damages or damages for lost profits, loss of
31 1.1.2.2 nathanw * revenue or loss of use, whether such damages arise in contract,
32 1.1.2.2 nathanw * negligence, tort, under statute, in equity, at law or otherwise,
33 1.1.2.2 nathanw * even if advised of the possibility of such damage.
34 1.1.2.2 nathanw */
35 1.1.2.2 nathanw
36 1.1.2.2 nathanw /*
37 1.1.2.2 nathanw * Copyright (C) 1995, 1996 Wolfgang Solfrank.
38 1.1.2.2 nathanw * Copyright (C) 1995, 1996 TooLs GmbH.
39 1.1.2.2 nathanw * All rights reserved.
40 1.1.2.2 nathanw *
41 1.1.2.2 nathanw * Redistribution and use in source and binary forms, with or without
42 1.1.2.2 nathanw * modification, are permitted provided that the following conditions
43 1.1.2.2 nathanw * are met:
44 1.1.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
45 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer.
46 1.1.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
47 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
48 1.1.2.2 nathanw * documentation and/or other materials provided with the distribution.
49 1.1.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
50 1.1.2.2 nathanw * must display the following acknowledgement:
51 1.1.2.2 nathanw * This product includes software developed by TooLs GmbH.
52 1.1.2.2 nathanw * 4. The name of TooLs GmbH may not be used to endorse or promote products
53 1.1.2.2 nathanw * derived from this software without specific prior written permission.
54 1.1.2.2 nathanw *
55 1.1.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
56 1.1.2.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
57 1.1.2.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
58 1.1.2.2 nathanw * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59 1.1.2.2 nathanw * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
60 1.1.2.2 nathanw * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
61 1.1.2.2 nathanw * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
62 1.1.2.2 nathanw * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
63 1.1.2.2 nathanw * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
64 1.1.2.2 nathanw * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65 1.1.2.2 nathanw */
66 1.1.2.2 nathanw #include <sys/param.h>
67 1.1.2.2 nathanw
68 1.1.2.2 nathanw #include <machine/stdarg.h>
69 1.1.2.2 nathanw
70 1.1.2.2 nathanw #include <dev/ofw/openfirm.h>
71 1.1.2.2 nathanw
72 1.1.2.2 nathanw
73 1.1.2.2 nathanw /*
74 1.1.2.2 nathanw * Wrapper routines for OFW client services.
75 1.1.2.2 nathanw *
76 1.1.2.2 nathanw * This code was adapted from the PowerPC version done by
77 1.1.2.2 nathanw * Wolfgang Solfrank. The main difference is that we don't
78 1.1.2.2 nathanw * do the silly "ofw_stack" dance to convert the OS's real-
79 1.1.2.2 nathanw * mode view of OFW to virtual-mode. We don't need to do
80 1.1.2.2 nathanw * that because our NetBSD port assumes virtual-mode OFW.
81 1.1.2.2 nathanw *
82 1.1.2.2 nathanw * We should work with Wolfgang to turn this into a MI file. -JJK
83 1.1.2.2 nathanw */
84 1.1.2.2 nathanw
85 1.1.2.2 nathanw
86 1.1.2.2 nathanw int
87 1.1.2.2 nathanw OF_peer(phandle)
88 1.1.2.2 nathanw int phandle;
89 1.1.2.2 nathanw {
90 1.1.2.2 nathanw static struct {
91 1.1.2.2 nathanw char *name;
92 1.1.2.2 nathanw int nargs;
93 1.1.2.2 nathanw int nreturns;
94 1.1.2.2 nathanw int phandle;
95 1.1.2.2 nathanw int sibling;
96 1.1.2.2 nathanw } args = {
97 1.1.2.2 nathanw "peer",
98 1.1.2.2 nathanw 1,
99 1.1.2.2 nathanw 1,
100 1.1.2.2 nathanw };
101 1.1.2.2 nathanw
102 1.1.2.2 nathanw args.phandle = phandle;
103 1.1.2.2 nathanw if (openfirmware(&args) == -1)
104 1.1.2.2 nathanw return 0;
105 1.1.2.2 nathanw return args.sibling;
106 1.1.2.2 nathanw }
107 1.1.2.2 nathanw
108 1.1.2.2 nathanw int
109 1.1.2.2 nathanw OF_child(phandle)
110 1.1.2.2 nathanw int phandle;
111 1.1.2.2 nathanw {
112 1.1.2.2 nathanw static struct {
113 1.1.2.2 nathanw char *name;
114 1.1.2.2 nathanw int nargs;
115 1.1.2.2 nathanw int nreturns;
116 1.1.2.2 nathanw int phandle;
117 1.1.2.2 nathanw int child;
118 1.1.2.2 nathanw } args = {
119 1.1.2.2 nathanw "child",
120 1.1.2.2 nathanw 1,
121 1.1.2.2 nathanw 1,
122 1.1.2.2 nathanw };
123 1.1.2.2 nathanw
124 1.1.2.2 nathanw args.phandle = phandle;
125 1.1.2.2 nathanw if (openfirmware(&args) == -1)
126 1.1.2.2 nathanw return 0;
127 1.1.2.2 nathanw return args.child;
128 1.1.2.2 nathanw }
129 1.1.2.2 nathanw
130 1.1.2.2 nathanw int
131 1.1.2.2 nathanw OF_parent(phandle)
132 1.1.2.2 nathanw int phandle;
133 1.1.2.2 nathanw {
134 1.1.2.2 nathanw static struct {
135 1.1.2.2 nathanw char *name;
136 1.1.2.2 nathanw int nargs;
137 1.1.2.2 nathanw int nreturns;
138 1.1.2.2 nathanw int phandle;
139 1.1.2.2 nathanw int parent;
140 1.1.2.2 nathanw } args = {
141 1.1.2.2 nathanw "parent",
142 1.1.2.2 nathanw 1,
143 1.1.2.2 nathanw 1,
144 1.1.2.2 nathanw };
145 1.1.2.2 nathanw
146 1.1.2.2 nathanw args.phandle = phandle;
147 1.1.2.2 nathanw if (openfirmware(&args) == -1)
148 1.1.2.2 nathanw return 0;
149 1.1.2.2 nathanw return args.parent;
150 1.1.2.2 nathanw }
151 1.1.2.2 nathanw
152 1.1.2.2 nathanw int
153 1.1.2.2 nathanw OF_instance_to_package(ihandle)
154 1.1.2.2 nathanw int ihandle;
155 1.1.2.2 nathanw {
156 1.1.2.2 nathanw static struct {
157 1.1.2.2 nathanw char *name;
158 1.1.2.2 nathanw int nargs;
159 1.1.2.2 nathanw int nreturns;
160 1.1.2.2 nathanw int ihandle;
161 1.1.2.2 nathanw int phandle;
162 1.1.2.2 nathanw } args = {
163 1.1.2.2 nathanw "instance-to-package",
164 1.1.2.2 nathanw 1,
165 1.1.2.2 nathanw 1,
166 1.1.2.2 nathanw };
167 1.1.2.2 nathanw
168 1.1.2.2 nathanw args.ihandle = ihandle;
169 1.1.2.2 nathanw if (openfirmware(&args) == -1)
170 1.1.2.2 nathanw return -1;
171 1.1.2.2 nathanw return args.phandle;
172 1.1.2.2 nathanw }
173 1.1.2.2 nathanw
174 1.1.2.2 nathanw int
175 1.1.2.2 nathanw OF_nextprop(handle, prop, nextprop)
176 1.1.2.2 nathanw int handle;
177 1.1.2.2 nathanw char *prop;
178 1.1.2.2 nathanw void *nextprop;
179 1.1.2.2 nathanw {
180 1.1.2.2 nathanw static struct {
181 1.1.2.2 nathanw char *name;
182 1.1.2.2 nathanw int nargs;
183 1.1.2.2 nathanw int nreturns;
184 1.1.2.2 nathanw int phandle;
185 1.1.2.2 nathanw char *prop;
186 1.1.2.2 nathanw void *nextprop;
187 1.1.2.2 nathanw int flags;
188 1.1.2.2 nathanw } args = {
189 1.1.2.2 nathanw "nextprop",
190 1.1.2.2 nathanw 3,
191 1.1.2.2 nathanw 1,
192 1.1.2.2 nathanw };
193 1.1.2.2 nathanw
194 1.1.2.2 nathanw args.phandle = handle;
195 1.1.2.2 nathanw args.prop = prop;
196 1.1.2.2 nathanw args.nextprop = nextprop;
197 1.1.2.2 nathanw
198 1.1.2.2 nathanw if (openfirmware(&args) == -1)
199 1.1.2.2 nathanw return -1;
200 1.1.2.2 nathanw return args.flags;
201 1.1.2.2 nathanw }
202 1.1.2.2 nathanw
203 1.1.2.2 nathanw int
204 1.1.2.2 nathanw OF_getprop(handle, prop, buf, buflen)
205 1.1.2.2 nathanw int handle;
206 1.1.2.2 nathanw char *prop;
207 1.1.2.2 nathanw void *buf;
208 1.1.2.2 nathanw int buflen;
209 1.1.2.2 nathanw {
210 1.1.2.2 nathanw static struct {
211 1.1.2.2 nathanw char *name;
212 1.1.2.2 nathanw int nargs;
213 1.1.2.2 nathanw int nreturns;
214 1.1.2.2 nathanw int phandle;
215 1.1.2.2 nathanw char *prop;
216 1.1.2.2 nathanw void *buf;
217 1.1.2.2 nathanw int buflen;
218 1.1.2.2 nathanw int size;
219 1.1.2.2 nathanw } args = {
220 1.1.2.2 nathanw "getprop",
221 1.1.2.2 nathanw 4,
222 1.1.2.2 nathanw 1,
223 1.1.2.2 nathanw };
224 1.1.2.2 nathanw
225 1.1.2.2 nathanw args.phandle = handle;
226 1.1.2.2 nathanw args.prop = prop;
227 1.1.2.2 nathanw args.buf = buf;
228 1.1.2.2 nathanw args.buflen = buflen;
229 1.1.2.2 nathanw
230 1.1.2.2 nathanw
231 1.1.2.2 nathanw if (openfirmware(&args) == -1)
232 1.1.2.2 nathanw return -1;
233 1.1.2.2 nathanw return args.size;
234 1.1.2.2 nathanw }
235 1.1.2.2 nathanw
236 1.1.2.2 nathanw int
237 1.1.2.2 nathanw OF_getproplen(handle, prop)
238 1.1.2.2 nathanw int handle;
239 1.1.2.2 nathanw char *prop;
240 1.1.2.2 nathanw {
241 1.1.2.2 nathanw static struct {
242 1.1.2.2 nathanw char *name;
243 1.1.2.2 nathanw int nargs;
244 1.1.2.2 nathanw int nreturns;
245 1.1.2.2 nathanw int phandle;
246 1.1.2.2 nathanw char *prop;
247 1.1.2.2 nathanw int size;
248 1.1.2.2 nathanw } args = {
249 1.1.2.2 nathanw "getproplen",
250 1.1.2.2 nathanw 2,
251 1.1.2.2 nathanw 1,
252 1.1.2.2 nathanw };
253 1.1.2.2 nathanw
254 1.1.2.2 nathanw args.phandle = handle;
255 1.1.2.2 nathanw args.prop = prop;
256 1.1.2.2 nathanw if (openfirmware(&args) == -1)
257 1.1.2.2 nathanw return -1;
258 1.1.2.2 nathanw return args.size;
259 1.1.2.2 nathanw }
260 1.1.2.2 nathanw
261 1.1.2.2 nathanw int
262 1.1.2.2 nathanw OF_finddevice(name)
263 1.1.2.2 nathanw char *name;
264 1.1.2.2 nathanw {
265 1.1.2.2 nathanw static struct {
266 1.1.2.2 nathanw char *name;
267 1.1.2.2 nathanw int nargs;
268 1.1.2.2 nathanw int nreturns;
269 1.1.2.2 nathanw char *device;
270 1.1.2.2 nathanw int phandle;
271 1.1.2.2 nathanw } args = {
272 1.1.2.2 nathanw "finddevice",
273 1.1.2.2 nathanw 1,
274 1.1.2.2 nathanw 1,
275 1.1.2.2 nathanw };
276 1.1.2.2 nathanw
277 1.1.2.2 nathanw args.device = name;
278 1.1.2.2 nathanw if (openfirmware(&args) == -1)
279 1.1.2.2 nathanw return -1;
280 1.1.2.2 nathanw return args.phandle;
281 1.1.2.2 nathanw }
282 1.1.2.2 nathanw
283 1.1.2.2 nathanw int
284 1.1.2.2 nathanw OF_instance_to_path(ihandle, buf, buflen)
285 1.1.2.2 nathanw int ihandle;
286 1.1.2.2 nathanw char *buf;
287 1.1.2.2 nathanw int buflen;
288 1.1.2.2 nathanw {
289 1.1.2.2 nathanw static struct {
290 1.1.2.2 nathanw char *name;
291 1.1.2.2 nathanw int nargs;
292 1.1.2.2 nathanw int nreturns;
293 1.1.2.2 nathanw int ihandle;
294 1.1.2.2 nathanw char *buf;
295 1.1.2.2 nathanw int buflen;
296 1.1.2.2 nathanw int length;
297 1.1.2.2 nathanw } args = {
298 1.1.2.2 nathanw "instance-to-path",
299 1.1.2.2 nathanw 3,
300 1.1.2.2 nathanw 1,
301 1.1.2.2 nathanw };
302 1.1.2.2 nathanw
303 1.1.2.2 nathanw args.ihandle = ihandle;
304 1.1.2.2 nathanw args.buf = buf;
305 1.1.2.2 nathanw args.buflen = buflen;
306 1.1.2.2 nathanw if (openfirmware(&args) < 0)
307 1.1.2.2 nathanw return -1;
308 1.1.2.2 nathanw return args.length;
309 1.1.2.2 nathanw }
310 1.1.2.2 nathanw
311 1.1.2.2 nathanw int
312 1.1.2.2 nathanw OF_package_to_path(phandle, buf, buflen)
313 1.1.2.2 nathanw int phandle;
314 1.1.2.2 nathanw char *buf;
315 1.1.2.2 nathanw int buflen;
316 1.1.2.2 nathanw {
317 1.1.2.2 nathanw static struct {
318 1.1.2.2 nathanw char *name;
319 1.1.2.2 nathanw int nargs;
320 1.1.2.2 nathanw int nreturns;
321 1.1.2.2 nathanw int phandle;
322 1.1.2.2 nathanw char *buf;
323 1.1.2.2 nathanw int buflen;
324 1.1.2.2 nathanw int length;
325 1.1.2.2 nathanw } args = {
326 1.1.2.2 nathanw "package-to-path",
327 1.1.2.2 nathanw 3,
328 1.1.2.2 nathanw 1,
329 1.1.2.2 nathanw };
330 1.1.2.2 nathanw
331 1.1.2.2 nathanw args.phandle = phandle;
332 1.1.2.2 nathanw args.buf = buf;
333 1.1.2.2 nathanw args.buflen = buflen;
334 1.1.2.2 nathanw if (openfirmware(&args) < 0)
335 1.1.2.2 nathanw return -1;
336 1.1.2.2 nathanw return args.length;
337 1.1.2.2 nathanw }
338 1.1.2.2 nathanw
339 1.1.2.2 nathanw int
340 1.1.2.2 nathanw #ifdef __STDC__
341 1.1.2.2 nathanw OF_call_method(char *method, int ihandle, int nargs, int nreturns, ...)
342 1.1.2.2 nathanw #else
343 1.1.2.2 nathanw OF_call_method(method, ihandle, nargs, nreturns, va_alist)
344 1.1.2.2 nathanw char *method;
345 1.1.2.2 nathanw int ihandle;
346 1.1.2.2 nathanw int nargs;
347 1.1.2.2 nathanw int nreturns;
348 1.1.2.2 nathanw va_dcl
349 1.1.2.2 nathanw #endif
350 1.1.2.2 nathanw {
351 1.1.2.2 nathanw va_list ap;
352 1.1.2.2 nathanw static struct {
353 1.1.2.2 nathanw char *name;
354 1.1.2.2 nathanw int nargs;
355 1.1.2.2 nathanw int nreturns;
356 1.1.2.2 nathanw char *method;
357 1.1.2.2 nathanw int ihandle;
358 1.1.2.2 nathanw int args_n_results[12];
359 1.1.2.2 nathanw } args = {
360 1.1.2.2 nathanw "call-method",
361 1.1.2.2 nathanw 2,
362 1.1.2.2 nathanw 1,
363 1.1.2.2 nathanw };
364 1.1.2.2 nathanw int *ip, n;
365 1.1.2.2 nathanw
366 1.1.2.2 nathanw if (nargs > 6)
367 1.1.2.2 nathanw return -1;
368 1.1.2.2 nathanw args.nargs = nargs + 2;
369 1.1.2.2 nathanw args.nreturns = nreturns + 1;
370 1.1.2.2 nathanw args.method = method;
371 1.1.2.2 nathanw args.ihandle = ihandle;
372 1.1.2.2 nathanw va_start(ap, nreturns);
373 1.1.2.2 nathanw for (ip = args.args_n_results + (n = nargs); --n >= 0;)
374 1.1.2.2 nathanw *--ip = va_arg(ap, int);
375 1.1.2.2 nathanw if (openfirmware(&args) == -1) {
376 1.1.2.2 nathanw va_end(ap);
377 1.1.2.2 nathanw return -1;
378 1.1.2.2 nathanw }
379 1.1.2.2 nathanw /*
380 1.1.2.2 nathanw {
381 1.1.2.2 nathanw int i, res;
382 1.1.2.2 nathanw
383 1.1.2.2 nathanw printf("call_method(%s): ihandle = %x, nargs = %d, nreturns = %d -- ",
384 1.1.2.2 nathanw method, ihandle, nargs, nreturns);
385 1.1.2.2 nathanw res = openfirmware(&args);
386 1.1.2.2 nathanw printf("res = %x\n", res);
387 1.1.2.2 nathanw printf("\targs_n_results = ");
388 1.1.2.2 nathanw for (i = 0; i < nargs + nreturns + 1; i++)
389 1.1.2.2 nathanw printf("%x ", args.args_n_results[i]);
390 1.1.2.2 nathanw printf("\n");
391 1.1.2.2 nathanw if (res == -1) return -1;
392 1.1.2.2 nathanw }
393 1.1.2.2 nathanw */
394 1.1.2.2 nathanw if (args.args_n_results[nargs]) {
395 1.1.2.2 nathanw va_end(ap);
396 1.1.2.2 nathanw return args.args_n_results[nargs];
397 1.1.2.2 nathanw }
398 1.1.2.2 nathanw for (ip = args.args_n_results + nargs + (n = args.nreturns); --n > 0;)
399 1.1.2.2 nathanw *va_arg(ap, int *) = *--ip;
400 1.1.2.2 nathanw va_end(ap);
401 1.1.2.2 nathanw return 0;
402 1.1.2.2 nathanw }
403 1.1.2.2 nathanw
404 1.1.2.2 nathanw int
405 1.1.2.2 nathanw #ifdef __STDC__
406 1.1.2.2 nathanw OF_call_method_1(char *method, int ihandle, int nargs, ...)
407 1.1.2.2 nathanw #else
408 1.1.2.2 nathanw OF_call_method_1(method, ihandle, nargs, va_alist)
409 1.1.2.2 nathanw char *method;
410 1.1.2.2 nathanw int ihandle;
411 1.1.2.2 nathanw int nargs;
412 1.1.2.2 nathanw va_dcl
413 1.1.2.2 nathanw #endif
414 1.1.2.2 nathanw {
415 1.1.2.2 nathanw va_list ap;
416 1.1.2.2 nathanw static struct {
417 1.1.2.2 nathanw char *name;
418 1.1.2.2 nathanw int nargs;
419 1.1.2.2 nathanw int nreturns;
420 1.1.2.2 nathanw char *method;
421 1.1.2.2 nathanw int ihandle;
422 1.1.2.2 nathanw int args_n_results[8];
423 1.1.2.2 nathanw } args = {
424 1.1.2.2 nathanw "call-method",
425 1.1.2.2 nathanw 2,
426 1.1.2.2 nathanw 2,
427 1.1.2.2 nathanw };
428 1.1.2.2 nathanw int *ip, n;
429 1.1.2.2 nathanw
430 1.1.2.2 nathanw if (nargs > 6)
431 1.1.2.2 nathanw return -1;
432 1.1.2.2 nathanw args.nargs = nargs + 2;
433 1.1.2.2 nathanw args.method = method;
434 1.1.2.2 nathanw args.ihandle = ihandle;
435 1.1.2.2 nathanw va_start(ap, nargs);
436 1.1.2.2 nathanw for (ip = args.args_n_results + (n = nargs); --n >= 0;)
437 1.1.2.2 nathanw *--ip = va_arg(ap, int);
438 1.1.2.2 nathanw va_end(ap);
439 1.1.2.2 nathanw if (openfirmware(&args) == -1)
440 1.1.2.2 nathanw return -1;
441 1.1.2.2 nathanw /*
442 1.1.2.2 nathanw {
443 1.1.2.2 nathanw int i, res;
444 1.1.2.2 nathanw
445 1.1.2.2 nathanw printf("call_method_1(%s): ihandle = %x, nargs = %d -- ",
446 1.1.2.2 nathanw method, ihandle, nargs);
447 1.1.2.2 nathanw res = openfirmware(&args);
448 1.1.2.2 nathanw printf("res = %x\n", res);
449 1.1.2.2 nathanw printf("\targs_n_results = ");
450 1.1.2.2 nathanw for (i = 0; i < nargs + 2; i++)
451 1.1.2.2 nathanw printf("%x ", args.args_n_results[i]);
452 1.1.2.2 nathanw printf("\n");
453 1.1.2.2 nathanw if (res == -1) return -1;
454 1.1.2.2 nathanw }
455 1.1.2.2 nathanw */
456 1.1.2.2 nathanw if (args.args_n_results[nargs])
457 1.1.2.2 nathanw return -1;
458 1.1.2.2 nathanw return args.args_n_results[nargs + 1];
459 1.1.2.2 nathanw }
460 1.1.2.2 nathanw
461 1.1.2.2 nathanw int
462 1.1.2.2 nathanw OF_open(dname)
463 1.1.2.2 nathanw char *dname;
464 1.1.2.2 nathanw {
465 1.1.2.2 nathanw static struct {
466 1.1.2.2 nathanw char *name;
467 1.1.2.2 nathanw int nargs;
468 1.1.2.2 nathanw int nreturns;
469 1.1.2.2 nathanw char *dname;
470 1.1.2.2 nathanw int handle;
471 1.1.2.2 nathanw } args = {
472 1.1.2.2 nathanw "open",
473 1.1.2.2 nathanw 1,
474 1.1.2.2 nathanw 1,
475 1.1.2.2 nathanw };
476 1.1.2.2 nathanw
477 1.1.2.2 nathanw args.dname = dname;
478 1.1.2.2 nathanw if (openfirmware(&args) == -1)
479 1.1.2.2 nathanw return -1;
480 1.1.2.2 nathanw return args.handle;
481 1.1.2.2 nathanw }
482 1.1.2.2 nathanw
483 1.1.2.2 nathanw void
484 1.1.2.2 nathanw OF_close(handle)
485 1.1.2.2 nathanw int handle;
486 1.1.2.2 nathanw {
487 1.1.2.2 nathanw static struct {
488 1.1.2.2 nathanw char *name;
489 1.1.2.2 nathanw int nargs;
490 1.1.2.2 nathanw int nreturns;
491 1.1.2.2 nathanw int handle;
492 1.1.2.2 nathanw } args = {
493 1.1.2.2 nathanw "close",
494 1.1.2.2 nathanw 1,
495 1.1.2.2 nathanw 0,
496 1.1.2.2 nathanw };
497 1.1.2.2 nathanw
498 1.1.2.2 nathanw args.handle = handle;
499 1.1.2.2 nathanw openfirmware(&args);
500 1.1.2.2 nathanw }
501 1.1.2.2 nathanw
502 1.1.2.2 nathanw int
503 1.1.2.2 nathanw OF_read(handle, addr, len)
504 1.1.2.2 nathanw int handle;
505 1.1.2.2 nathanw void *addr;
506 1.1.2.2 nathanw int len;
507 1.1.2.2 nathanw {
508 1.1.2.2 nathanw static struct {
509 1.1.2.2 nathanw char *name;
510 1.1.2.2 nathanw int nargs;
511 1.1.2.2 nathanw int nreturns;
512 1.1.2.2 nathanw int ihandle;
513 1.1.2.2 nathanw void *addr;
514 1.1.2.2 nathanw int len;
515 1.1.2.2 nathanw int actual;
516 1.1.2.2 nathanw } args = {
517 1.1.2.2 nathanw "read",
518 1.1.2.2 nathanw 3,
519 1.1.2.2 nathanw 1,
520 1.1.2.2 nathanw };
521 1.1.2.2 nathanw
522 1.1.2.2 nathanw args.ihandle = handle;
523 1.1.2.2 nathanw args.addr = addr;
524 1.1.2.2 nathanw args.len = len;
525 1.1.2.2 nathanw if (openfirmware(&args) == -1)
526 1.1.2.2 nathanw return -1;
527 1.1.2.2 nathanw return args.actual;
528 1.1.2.2 nathanw }
529 1.1.2.2 nathanw
530 1.1.2.2 nathanw int
531 1.1.2.2 nathanw OF_write(handle, addr, len)
532 1.1.2.2 nathanw int handle;
533 1.1.2.2 nathanw void *addr;
534 1.1.2.2 nathanw int len;
535 1.1.2.2 nathanw {
536 1.1.2.2 nathanw static struct {
537 1.1.2.2 nathanw char *name;
538 1.1.2.2 nathanw int nargs;
539 1.1.2.2 nathanw int nreturns;
540 1.1.2.2 nathanw int ihandle;
541 1.1.2.2 nathanw void *addr;
542 1.1.2.2 nathanw int len;
543 1.1.2.2 nathanw int actual;
544 1.1.2.2 nathanw } args = {
545 1.1.2.2 nathanw "write",
546 1.1.2.2 nathanw 3,
547 1.1.2.2 nathanw 1,
548 1.1.2.2 nathanw };
549 1.1.2.2 nathanw
550 1.1.2.2 nathanw args.ihandle = handle;
551 1.1.2.2 nathanw args.addr = addr;
552 1.1.2.2 nathanw args.len = len;
553 1.1.2.2 nathanw if (openfirmware(&args) == -1)
554 1.1.2.2 nathanw return -1;
555 1.1.2.2 nathanw return args.actual;
556 1.1.2.2 nathanw }
557 1.1.2.2 nathanw
558 1.1.2.2 nathanw int
559 1.1.2.2 nathanw OF_seek(handle, pos)
560 1.1.2.2 nathanw int handle;
561 1.1.2.2 nathanw u_quad_t pos;
562 1.1.2.2 nathanw {
563 1.1.2.2 nathanw static struct {
564 1.1.2.2 nathanw char *name;
565 1.1.2.2 nathanw int nargs;
566 1.1.2.2 nathanw int nreturns;
567 1.1.2.2 nathanw int handle;
568 1.1.2.2 nathanw int poshi;
569 1.1.2.2 nathanw int poslo;
570 1.1.2.2 nathanw int status;
571 1.1.2.2 nathanw } args = {
572 1.1.2.2 nathanw "seek",
573 1.1.2.2 nathanw 3,
574 1.1.2.2 nathanw 1,
575 1.1.2.2 nathanw };
576 1.1.2.2 nathanw
577 1.1.2.2 nathanw args.handle = handle;
578 1.1.2.2 nathanw args.poshi = (int)(pos >> 32);
579 1.1.2.2 nathanw args.poslo = (int)pos;
580 1.1.2.2 nathanw if (openfirmware(&args) == -1)
581 1.1.2.2 nathanw return -1;
582 1.1.2.2 nathanw return args.status;
583 1.1.2.2 nathanw }
584 1.1.2.2 nathanw
585 1.1.2.2 nathanw void *
586 1.1.2.2 nathanw OF_claim(virt, size, align)
587 1.1.2.2 nathanw void *virt;
588 1.1.2.2 nathanw u_int size;
589 1.1.2.2 nathanw u_int align;
590 1.1.2.2 nathanw {
591 1.1.2.2 nathanw static struct {
592 1.1.2.2 nathanw char *name;
593 1.1.2.2 nathanw int nargs;
594 1.1.2.2 nathanw int nreturns;
595 1.1.2.2 nathanw void *virt;
596 1.1.2.2 nathanw u_int size;
597 1.1.2.2 nathanw u_int align;
598 1.1.2.2 nathanw void *baseaddr;
599 1.1.2.2 nathanw } args = {
600 1.1.2.2 nathanw "claim",
601 1.1.2.2 nathanw 3,
602 1.1.2.2 nathanw 1,
603 1.1.2.2 nathanw };
604 1.1.2.2 nathanw
605 1.1.2.2 nathanw args.virt = virt;
606 1.1.2.2 nathanw args.size = size;
607 1.1.2.2 nathanw args.align = align;
608 1.1.2.2 nathanw if (openfirmware(&args) == -1)
609 1.1.2.2 nathanw return (void *)-1;
610 1.1.2.2 nathanw return args.baseaddr;
611 1.1.2.2 nathanw }
612 1.1.2.2 nathanw
613 1.1.2.2 nathanw void
614 1.1.2.2 nathanw OF_release(virt, size)
615 1.1.2.2 nathanw void *virt;
616 1.1.2.2 nathanw u_int size;
617 1.1.2.2 nathanw {
618 1.1.2.2 nathanw static struct {
619 1.1.2.2 nathanw char *name;
620 1.1.2.2 nathanw int nargs;
621 1.1.2.2 nathanw int nreturns;
622 1.1.2.2 nathanw void *virt;
623 1.1.2.2 nathanw u_int size;
624 1.1.2.2 nathanw } args = {
625 1.1.2.2 nathanw "release",
626 1.1.2.2 nathanw 2,
627 1.1.2.2 nathanw 0,
628 1.1.2.2 nathanw };
629 1.1.2.2 nathanw
630 1.1.2.2 nathanw args.virt = virt;
631 1.1.2.2 nathanw args.size = size;
632 1.1.2.2 nathanw openfirmware(&args);
633 1.1.2.2 nathanw }
634 1.1.2.2 nathanw
635 1.1.2.2 nathanw int
636 1.1.2.2 nathanw OF_milliseconds()
637 1.1.2.2 nathanw {
638 1.1.2.2 nathanw static struct {
639 1.1.2.2 nathanw char *name;
640 1.1.2.2 nathanw int nargs;
641 1.1.2.2 nathanw int nreturns;
642 1.1.2.2 nathanw int ms;
643 1.1.2.2 nathanw } args = {
644 1.1.2.2 nathanw "milliseconds",
645 1.1.2.2 nathanw 0,
646 1.1.2.2 nathanw 1,
647 1.1.2.2 nathanw };
648 1.1.2.2 nathanw
649 1.1.2.2 nathanw openfirmware(&args);
650 1.1.2.2 nathanw return args.ms;
651 1.1.2.2 nathanw }
652 1.1.2.2 nathanw
653 1.1.2.2 nathanw void
654 1.1.2.2 nathanw OF_boot(bootspec)
655 1.1.2.2 nathanw char *bootspec;
656 1.1.2.2 nathanw {
657 1.1.2.2 nathanw static struct {
658 1.1.2.2 nathanw char *name;
659 1.1.2.2 nathanw int nargs;
660 1.1.2.2 nathanw int nreturns;
661 1.1.2.2 nathanw char *bootspec;
662 1.1.2.2 nathanw } args = {
663 1.1.2.2 nathanw "boot",
664 1.1.2.2 nathanw 1,
665 1.1.2.2 nathanw 0,
666 1.1.2.2 nathanw };
667 1.1.2.2 nathanw
668 1.1.2.2 nathanw args.bootspec = bootspec;
669 1.1.2.2 nathanw openfirmware(&args);
670 1.1.2.2 nathanw while (1); /* just in case */
671 1.1.2.2 nathanw }
672 1.1.2.2 nathanw
673 1.1.2.2 nathanw void
674 1.1.2.2 nathanw OF_enter()
675 1.1.2.2 nathanw {
676 1.1.2.2 nathanw static struct {
677 1.1.2.2 nathanw char *name;
678 1.1.2.2 nathanw int nargs;
679 1.1.2.2 nathanw int nreturns;
680 1.1.2.2 nathanw } args = {
681 1.1.2.2 nathanw "enter",
682 1.1.2.2 nathanw 0,
683 1.1.2.2 nathanw 0,
684 1.1.2.2 nathanw };
685 1.1.2.2 nathanw
686 1.1.2.2 nathanw openfirmware(&args);
687 1.1.2.2 nathanw }
688 1.1.2.2 nathanw
689 1.1.2.2 nathanw void
690 1.1.2.2 nathanw OF_exit()
691 1.1.2.2 nathanw {
692 1.1.2.2 nathanw static struct {
693 1.1.2.2 nathanw char *name;
694 1.1.2.2 nathanw int nargs;
695 1.1.2.2 nathanw int nreturns;
696 1.1.2.2 nathanw } args = {
697 1.1.2.2 nathanw "exit",
698 1.1.2.2 nathanw 0,
699 1.1.2.2 nathanw 0,
700 1.1.2.2 nathanw };
701 1.1.2.2 nathanw
702 1.1.2.2 nathanw openfirmware(&args);
703 1.1.2.2 nathanw while (1); /* just in case */
704 1.1.2.2 nathanw }
705 1.1.2.2 nathanw
706 1.1.2.2 nathanw void
707 1.1.2.3 nathanw (*OF_set_callback(newfunc))(void *)
708 1.1.2.3 nathanw void (*newfunc)(void *);
709 1.1.2.2 nathanw {
710 1.1.2.2 nathanw static struct {
711 1.1.2.2 nathanw char *name;
712 1.1.2.2 nathanw int nargs;
713 1.1.2.2 nathanw int nreturns;
714 1.1.2.3 nathanw void (*newfunc)(void *);
715 1.1.2.3 nathanw void (*oldfunc)(void *);
716 1.1.2.2 nathanw } args = {
717 1.1.2.2 nathanw "set-callback",
718 1.1.2.2 nathanw 1,
719 1.1.2.2 nathanw 1,
720 1.1.2.2 nathanw };
721 1.1.2.2 nathanw
722 1.1.2.2 nathanw args.newfunc = newfunc;
723 1.1.2.2 nathanw if (openfirmware(&args) == -1)
724 1.1.2.2 nathanw return 0;
725 1.1.2.2 nathanw return args.oldfunc;
726 1.1.2.2 nathanw }
727