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