openfirm.c revision 1.6.46.1 1 1.6.46.1 yamt /* $NetBSD: openfirm.c,v 1.6.46.1 2009/05/04 08:10:43 yamt 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.3 lukem
67 1.3 lukem #include <sys/cdefs.h>
68 1.6.46.1 yamt __KERNEL_RCSID(0, "$NetBSD: openfirm.c,v 1.6.46.1 2009/05/04 08:10:43 yamt Exp $");
69 1.3 lukem
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.6.46.1 yamt OF_peer(int phandle)
92 1.1 thorpej {
93 1.1 thorpej static struct {
94 1.4 scw const char *name;
95 1.1 thorpej int nargs;
96 1.1 thorpej int nreturns;
97 1.1 thorpej int phandle;
98 1.1 thorpej int sibling;
99 1.1 thorpej } args = {
100 1.1 thorpej "peer",
101 1.1 thorpej 1,
102 1.1 thorpej 1,
103 1.1 thorpej };
104 1.1 thorpej
105 1.1 thorpej args.phandle = phandle;
106 1.1 thorpej if (openfirmware(&args) == -1)
107 1.1 thorpej return 0;
108 1.1 thorpej return args.sibling;
109 1.1 thorpej }
110 1.1 thorpej
111 1.1 thorpej int
112 1.6.46.1 yamt OF_child(int phandle)
113 1.1 thorpej {
114 1.1 thorpej static struct {
115 1.4 scw const char *name;
116 1.1 thorpej int nargs;
117 1.1 thorpej int nreturns;
118 1.1 thorpej int phandle;
119 1.1 thorpej int child;
120 1.1 thorpej } args = {
121 1.1 thorpej "child",
122 1.1 thorpej 1,
123 1.1 thorpej 1,
124 1.1 thorpej };
125 1.1 thorpej
126 1.1 thorpej args.phandle = phandle;
127 1.1 thorpej if (openfirmware(&args) == -1)
128 1.1 thorpej return 0;
129 1.1 thorpej return args.child;
130 1.1 thorpej }
131 1.1 thorpej
132 1.1 thorpej int
133 1.6.46.1 yamt OF_parent(int phandle)
134 1.1 thorpej {
135 1.1 thorpej static struct {
136 1.4 scw const char *name;
137 1.1 thorpej int nargs;
138 1.1 thorpej int nreturns;
139 1.1 thorpej int phandle;
140 1.1 thorpej int parent;
141 1.1 thorpej } args = {
142 1.1 thorpej "parent",
143 1.1 thorpej 1,
144 1.1 thorpej 1,
145 1.1 thorpej };
146 1.1 thorpej
147 1.1 thorpej args.phandle = phandle;
148 1.1 thorpej if (openfirmware(&args) == -1)
149 1.1 thorpej return 0;
150 1.1 thorpej return args.parent;
151 1.1 thorpej }
152 1.1 thorpej
153 1.1 thorpej int
154 1.6.46.1 yamt OF_instance_to_package(int ihandle)
155 1.1 thorpej {
156 1.1 thorpej static struct {
157 1.4 scw const char *name;
158 1.1 thorpej int nargs;
159 1.1 thorpej int nreturns;
160 1.1 thorpej int ihandle;
161 1.1 thorpej int phandle;
162 1.1 thorpej } args = {
163 1.1 thorpej "instance-to-package",
164 1.1 thorpej 1,
165 1.1 thorpej 1,
166 1.1 thorpej };
167 1.1 thorpej
168 1.1 thorpej args.ihandle = ihandle;
169 1.1 thorpej if (openfirmware(&args) == -1)
170 1.1 thorpej return -1;
171 1.1 thorpej return args.phandle;
172 1.1 thorpej }
173 1.1 thorpej
174 1.1 thorpej int
175 1.6.46.1 yamt OF_nextprop(int handle, const char *prop, void *nextprop)
176 1.1 thorpej {
177 1.1 thorpej static struct {
178 1.4 scw const char *name;
179 1.1 thorpej int nargs;
180 1.1 thorpej int nreturns;
181 1.1 thorpej int phandle;
182 1.4 scw const char *prop;
183 1.1 thorpej void *nextprop;
184 1.1 thorpej int flags;
185 1.1 thorpej } args = {
186 1.1 thorpej "nextprop",
187 1.1 thorpej 3,
188 1.1 thorpej 1,
189 1.1 thorpej };
190 1.1 thorpej
191 1.1 thorpej args.phandle = handle;
192 1.1 thorpej args.prop = prop;
193 1.1 thorpej args.nextprop = nextprop;
194 1.1 thorpej
195 1.1 thorpej if (openfirmware(&args) == -1)
196 1.1 thorpej return -1;
197 1.1 thorpej return args.flags;
198 1.1 thorpej }
199 1.1 thorpej
200 1.1 thorpej int
201 1.6.46.1 yamt OF_getprop(int handle, const char *prop, void *buf, int buflen)
202 1.1 thorpej {
203 1.1 thorpej static struct {
204 1.4 scw const char *name;
205 1.1 thorpej int nargs;
206 1.1 thorpej int nreturns;
207 1.1 thorpej int phandle;
208 1.4 scw const char *prop;
209 1.1 thorpej void *buf;
210 1.1 thorpej int buflen;
211 1.1 thorpej int size;
212 1.1 thorpej } args = {
213 1.1 thorpej "getprop",
214 1.1 thorpej 4,
215 1.1 thorpej 1,
216 1.1 thorpej };
217 1.1 thorpej
218 1.1 thorpej args.phandle = handle;
219 1.1 thorpej args.prop = prop;
220 1.1 thorpej args.buf = buf;
221 1.1 thorpej args.buflen = buflen;
222 1.1 thorpej
223 1.1 thorpej
224 1.1 thorpej if (openfirmware(&args) == -1)
225 1.1 thorpej return -1;
226 1.1 thorpej return args.size;
227 1.1 thorpej }
228 1.1 thorpej
229 1.1 thorpej int
230 1.6.46.1 yamt OF_setprop(int handle, const char *prop, const void *buf, int buflen)
231 1.6 macallan {
232 1.6 macallan static struct {
233 1.6 macallan const char *name;
234 1.6 macallan int nargs;
235 1.6 macallan int nreturns;
236 1.6 macallan int phandle;
237 1.6 macallan const char *prop;
238 1.6 macallan const void *buf;
239 1.6 macallan int buflen;
240 1.6 macallan int size;
241 1.6 macallan } args = {
242 1.6 macallan "setprop",
243 1.6 macallan 4,
244 1.6 macallan 1,
245 1.6 macallan };
246 1.6 macallan
247 1.6 macallan args.phandle = handle;
248 1.6 macallan args.prop = prop;
249 1.6 macallan args.buf = buf;
250 1.6 macallan args.buflen = buflen;
251 1.6 macallan
252 1.6 macallan
253 1.6 macallan if (openfirmware(&args) == -1)
254 1.6 macallan return -1;
255 1.6 macallan return args.size;
256 1.6 macallan }
257 1.6 macallan
258 1.6 macallan int
259 1.6.46.1 yamt OF_getproplen(int handle, const char *prop)
260 1.1 thorpej {
261 1.1 thorpej static struct {
262 1.4 scw const char *name;
263 1.1 thorpej int nargs;
264 1.1 thorpej int nreturns;
265 1.1 thorpej int phandle;
266 1.4 scw const char *prop;
267 1.1 thorpej int size;
268 1.1 thorpej } args = {
269 1.1 thorpej "getproplen",
270 1.1 thorpej 2,
271 1.1 thorpej 1,
272 1.1 thorpej };
273 1.1 thorpej
274 1.1 thorpej args.phandle = handle;
275 1.1 thorpej args.prop = prop;
276 1.1 thorpej if (openfirmware(&args) == -1)
277 1.1 thorpej return -1;
278 1.1 thorpej return args.size;
279 1.1 thorpej }
280 1.1 thorpej
281 1.1 thorpej int
282 1.6.46.1 yamt OF_finddevice(const char *name)
283 1.1 thorpej {
284 1.1 thorpej static struct {
285 1.4 scw const char *name;
286 1.1 thorpej int nargs;
287 1.1 thorpej int nreturns;
288 1.4 scw const char *device;
289 1.1 thorpej int phandle;
290 1.1 thorpej } args = {
291 1.1 thorpej "finddevice",
292 1.1 thorpej 1,
293 1.1 thorpej 1,
294 1.1 thorpej };
295 1.1 thorpej
296 1.1 thorpej args.device = name;
297 1.1 thorpej if (openfirmware(&args) == -1)
298 1.1 thorpej return -1;
299 1.1 thorpej return args.phandle;
300 1.1 thorpej }
301 1.1 thorpej
302 1.1 thorpej int
303 1.6.46.1 yamt OF_instance_to_path(int ihandle, char *buf, int buflen)
304 1.1 thorpej {
305 1.1 thorpej static struct {
306 1.4 scw const char *name;
307 1.1 thorpej int nargs;
308 1.1 thorpej int nreturns;
309 1.1 thorpej int ihandle;
310 1.1 thorpej char *buf;
311 1.1 thorpej int buflen;
312 1.1 thorpej int length;
313 1.1 thorpej } args = {
314 1.1 thorpej "instance-to-path",
315 1.1 thorpej 3,
316 1.1 thorpej 1,
317 1.1 thorpej };
318 1.1 thorpej
319 1.1 thorpej args.ihandle = ihandle;
320 1.1 thorpej args.buf = buf;
321 1.1 thorpej args.buflen = buflen;
322 1.1 thorpej if (openfirmware(&args) < 0)
323 1.1 thorpej return -1;
324 1.1 thorpej return args.length;
325 1.1 thorpej }
326 1.1 thorpej
327 1.1 thorpej int
328 1.6.46.1 yamt OF_package_to_path(int phandle, char *buf, int buflen)
329 1.1 thorpej {
330 1.1 thorpej static struct {
331 1.4 scw const char *name;
332 1.1 thorpej int nargs;
333 1.1 thorpej int nreturns;
334 1.1 thorpej int phandle;
335 1.1 thorpej char *buf;
336 1.1 thorpej int buflen;
337 1.1 thorpej int length;
338 1.1 thorpej } args = {
339 1.1 thorpej "package-to-path",
340 1.1 thorpej 3,
341 1.1 thorpej 1,
342 1.1 thorpej };
343 1.1 thorpej
344 1.1 thorpej args.phandle = phandle;
345 1.1 thorpej args.buf = buf;
346 1.1 thorpej args.buflen = buflen;
347 1.1 thorpej if (openfirmware(&args) < 0)
348 1.1 thorpej return -1;
349 1.1 thorpej return args.length;
350 1.1 thorpej }
351 1.1 thorpej
352 1.1 thorpej int
353 1.1 thorpej #ifdef __STDC__
354 1.4 scw OF_call_method(const char *method, int ihandle, int nargs, int nreturns, ...)
355 1.1 thorpej #else
356 1.1 thorpej OF_call_method(method, ihandle, nargs, nreturns, va_alist)
357 1.4 scw const char *method;
358 1.1 thorpej int ihandle;
359 1.1 thorpej int nargs;
360 1.1 thorpej int nreturns;
361 1.1 thorpej va_dcl
362 1.1 thorpej #endif
363 1.1 thorpej {
364 1.1 thorpej va_list ap;
365 1.1 thorpej static struct {
366 1.4 scw const char *name;
367 1.1 thorpej int nargs;
368 1.1 thorpej int nreturns;
369 1.4 scw const char *method;
370 1.1 thorpej int ihandle;
371 1.1 thorpej int args_n_results[12];
372 1.1 thorpej } args = {
373 1.1 thorpej "call-method",
374 1.1 thorpej 2,
375 1.1 thorpej 1,
376 1.1 thorpej };
377 1.1 thorpej int *ip, n;
378 1.1 thorpej
379 1.1 thorpej if (nargs > 6)
380 1.1 thorpej return -1;
381 1.1 thorpej args.nargs = nargs + 2;
382 1.1 thorpej args.nreturns = nreturns + 1;
383 1.1 thorpej args.method = method;
384 1.1 thorpej args.ihandle = ihandle;
385 1.1 thorpej va_start(ap, nreturns);
386 1.1 thorpej for (ip = args.args_n_results + (n = nargs); --n >= 0;)
387 1.1 thorpej *--ip = va_arg(ap, int);
388 1.1 thorpej if (openfirmware(&args) == -1) {
389 1.1 thorpej va_end(ap);
390 1.1 thorpej return -1;
391 1.1 thorpej }
392 1.1 thorpej /*
393 1.1 thorpej {
394 1.1 thorpej int i, res;
395 1.1 thorpej
396 1.1 thorpej printf("call_method(%s): ihandle = %x, nargs = %d, nreturns = %d -- ",
397 1.1 thorpej method, ihandle, nargs, nreturns);
398 1.1 thorpej res = openfirmware(&args);
399 1.1 thorpej printf("res = %x\n", res);
400 1.1 thorpej printf("\targs_n_results = ");
401 1.1 thorpej for (i = 0; i < nargs + nreturns + 1; i++)
402 1.1 thorpej printf("%x ", args.args_n_results[i]);
403 1.1 thorpej printf("\n");
404 1.1 thorpej if (res == -1) return -1;
405 1.1 thorpej }
406 1.1 thorpej */
407 1.1 thorpej if (args.args_n_results[nargs]) {
408 1.1 thorpej va_end(ap);
409 1.1 thorpej return args.args_n_results[nargs];
410 1.1 thorpej }
411 1.1 thorpej for (ip = args.args_n_results + nargs + (n = args.nreturns); --n > 0;)
412 1.1 thorpej *va_arg(ap, int *) = *--ip;
413 1.1 thorpej va_end(ap);
414 1.1 thorpej return 0;
415 1.1 thorpej }
416 1.1 thorpej
417 1.1 thorpej int
418 1.1 thorpej #ifdef __STDC__
419 1.4 scw OF_call_method_1(const char *method, int ihandle, int nargs, ...)
420 1.1 thorpej #else
421 1.1 thorpej OF_call_method_1(method, ihandle, nargs, va_alist)
422 1.4 scw const char *method;
423 1.1 thorpej int ihandle;
424 1.1 thorpej int nargs;
425 1.1 thorpej va_dcl
426 1.1 thorpej #endif
427 1.1 thorpej {
428 1.1 thorpej va_list ap;
429 1.1 thorpej static struct {
430 1.4 scw const char *name;
431 1.1 thorpej int nargs;
432 1.1 thorpej int nreturns;
433 1.4 scw const char *method;
434 1.1 thorpej int ihandle;
435 1.1 thorpej int args_n_results[8];
436 1.1 thorpej } args = {
437 1.1 thorpej "call-method",
438 1.1 thorpej 2,
439 1.1 thorpej 2,
440 1.1 thorpej };
441 1.1 thorpej int *ip, n;
442 1.1 thorpej
443 1.1 thorpej if (nargs > 6)
444 1.1 thorpej return -1;
445 1.1 thorpej args.nargs = nargs + 2;
446 1.1 thorpej args.method = method;
447 1.1 thorpej args.ihandle = ihandle;
448 1.1 thorpej va_start(ap, nargs);
449 1.1 thorpej for (ip = args.args_n_results + (n = nargs); --n >= 0;)
450 1.1 thorpej *--ip = va_arg(ap, int);
451 1.1 thorpej va_end(ap);
452 1.1 thorpej if (openfirmware(&args) == -1)
453 1.1 thorpej return -1;
454 1.1 thorpej /*
455 1.1 thorpej {
456 1.1 thorpej int i, res;
457 1.1 thorpej
458 1.1 thorpej printf("call_method_1(%s): ihandle = %x, nargs = %d -- ",
459 1.1 thorpej method, ihandle, nargs);
460 1.1 thorpej res = openfirmware(&args);
461 1.1 thorpej printf("res = %x\n", res);
462 1.1 thorpej printf("\targs_n_results = ");
463 1.1 thorpej for (i = 0; i < nargs + 2; i++)
464 1.1 thorpej printf("%x ", args.args_n_results[i]);
465 1.1 thorpej printf("\n");
466 1.1 thorpej if (res == -1) return -1;
467 1.1 thorpej }
468 1.1 thorpej */
469 1.1 thorpej if (args.args_n_results[nargs])
470 1.1 thorpej return -1;
471 1.1 thorpej return args.args_n_results[nargs + 1];
472 1.1 thorpej }
473 1.1 thorpej
474 1.1 thorpej int
475 1.6.46.1 yamt OF_open(const char *dname)
476 1.1 thorpej {
477 1.1 thorpej static struct {
478 1.4 scw const char *name;
479 1.1 thorpej int nargs;
480 1.1 thorpej int nreturns;
481 1.4 scw const char *dname;
482 1.1 thorpej int handle;
483 1.1 thorpej } args = {
484 1.1 thorpej "open",
485 1.1 thorpej 1,
486 1.1 thorpej 1,
487 1.1 thorpej };
488 1.1 thorpej
489 1.1 thorpej args.dname = dname;
490 1.1 thorpej if (openfirmware(&args) == -1)
491 1.1 thorpej return -1;
492 1.1 thorpej return args.handle;
493 1.1 thorpej }
494 1.1 thorpej
495 1.1 thorpej void
496 1.6.46.1 yamt OF_close(int handle)
497 1.1 thorpej {
498 1.1 thorpej static struct {
499 1.4 scw const char *name;
500 1.1 thorpej int nargs;
501 1.1 thorpej int nreturns;
502 1.1 thorpej int handle;
503 1.1 thorpej } args = {
504 1.1 thorpej "close",
505 1.1 thorpej 1,
506 1.1 thorpej 0,
507 1.1 thorpej };
508 1.1 thorpej
509 1.1 thorpej args.handle = handle;
510 1.1 thorpej openfirmware(&args);
511 1.1 thorpej }
512 1.1 thorpej
513 1.1 thorpej int
514 1.6.46.1 yamt OF_read(int handle, void *addr, int len)
515 1.1 thorpej {
516 1.1 thorpej static struct {
517 1.4 scw const char *name;
518 1.1 thorpej int nargs;
519 1.1 thorpej int nreturns;
520 1.1 thorpej int ihandle;
521 1.1 thorpej void *addr;
522 1.1 thorpej int len;
523 1.1 thorpej int actual;
524 1.1 thorpej } args = {
525 1.1 thorpej "read",
526 1.1 thorpej 3,
527 1.1 thorpej 1,
528 1.1 thorpej };
529 1.1 thorpej
530 1.1 thorpej args.ihandle = handle;
531 1.1 thorpej args.addr = addr;
532 1.1 thorpej args.len = len;
533 1.1 thorpej if (openfirmware(&args) == -1)
534 1.1 thorpej return -1;
535 1.1 thorpej return args.actual;
536 1.1 thorpej }
537 1.1 thorpej
538 1.1 thorpej int
539 1.6.46.1 yamt OF_write(int handle, const void *addr, int len)
540 1.1 thorpej {
541 1.1 thorpej static struct {
542 1.4 scw const char *name;
543 1.1 thorpej int nargs;
544 1.1 thorpej int nreturns;
545 1.1 thorpej int ihandle;
546 1.4 scw const void *addr;
547 1.1 thorpej int len;
548 1.1 thorpej int actual;
549 1.1 thorpej } args = {
550 1.1 thorpej "write",
551 1.1 thorpej 3,
552 1.1 thorpej 1,
553 1.1 thorpej };
554 1.1 thorpej
555 1.1 thorpej args.ihandle = handle;
556 1.1 thorpej args.addr = addr;
557 1.1 thorpej args.len = len;
558 1.1 thorpej if (openfirmware(&args) == -1)
559 1.1 thorpej return -1;
560 1.1 thorpej return args.actual;
561 1.1 thorpej }
562 1.1 thorpej
563 1.1 thorpej int
564 1.6.46.1 yamt OF_seek(int handle, u_quad_t pos)
565 1.1 thorpej {
566 1.1 thorpej static struct {
567 1.4 scw const char *name;
568 1.1 thorpej int nargs;
569 1.1 thorpej int nreturns;
570 1.1 thorpej int handle;
571 1.1 thorpej int poshi;
572 1.1 thorpej int poslo;
573 1.1 thorpej int status;
574 1.1 thorpej } args = {
575 1.1 thorpej "seek",
576 1.1 thorpej 3,
577 1.1 thorpej 1,
578 1.1 thorpej };
579 1.1 thorpej
580 1.1 thorpej args.handle = handle;
581 1.1 thorpej args.poshi = (int)(pos >> 32);
582 1.1 thorpej args.poslo = (int)pos;
583 1.1 thorpej if (openfirmware(&args) == -1)
584 1.1 thorpej return -1;
585 1.1 thorpej return args.status;
586 1.1 thorpej }
587 1.1 thorpej
588 1.1 thorpej void *
589 1.6.46.1 yamt OF_claim(void *virt, u_int size, u_int align)
590 1.1 thorpej {
591 1.1 thorpej static struct {
592 1.4 scw const char *name;
593 1.1 thorpej int nargs;
594 1.1 thorpej int nreturns;
595 1.1 thorpej void *virt;
596 1.1 thorpej u_int size;
597 1.1 thorpej u_int align;
598 1.1 thorpej void *baseaddr;
599 1.1 thorpej } args = {
600 1.1 thorpej "claim",
601 1.1 thorpej 3,
602 1.1 thorpej 1,
603 1.1 thorpej };
604 1.1 thorpej
605 1.1 thorpej args.virt = virt;
606 1.1 thorpej args.size = size;
607 1.1 thorpej args.align = align;
608 1.1 thorpej if (openfirmware(&args) == -1)
609 1.1 thorpej return (void *)-1;
610 1.1 thorpej return args.baseaddr;
611 1.1 thorpej }
612 1.1 thorpej
613 1.1 thorpej void
614 1.6.46.1 yamt OF_release(void *virt, u_int size)
615 1.1 thorpej {
616 1.1 thorpej static struct {
617 1.4 scw const char *name;
618 1.1 thorpej int nargs;
619 1.1 thorpej int nreturns;
620 1.1 thorpej void *virt;
621 1.1 thorpej u_int size;
622 1.1 thorpej } args = {
623 1.1 thorpej "release",
624 1.1 thorpej 2,
625 1.1 thorpej 0,
626 1.1 thorpej };
627 1.1 thorpej
628 1.1 thorpej args.virt = virt;
629 1.1 thorpej args.size = size;
630 1.1 thorpej openfirmware(&args);
631 1.1 thorpej }
632 1.1 thorpej
633 1.1 thorpej int
634 1.6.46.1 yamt OF_milliseconds(void)
635 1.1 thorpej {
636 1.1 thorpej static struct {
637 1.4 scw const char *name;
638 1.1 thorpej int nargs;
639 1.1 thorpej int nreturns;
640 1.1 thorpej int ms;
641 1.1 thorpej } args = {
642 1.1 thorpej "milliseconds",
643 1.1 thorpej 0,
644 1.1 thorpej 1,
645 1.1 thorpej };
646 1.1 thorpej
647 1.1 thorpej openfirmware(&args);
648 1.1 thorpej return args.ms;
649 1.1 thorpej }
650 1.1 thorpej
651 1.1 thorpej void
652 1.6.46.1 yamt OF_boot(const char *bootspec)
653 1.1 thorpej {
654 1.1 thorpej static struct {
655 1.4 scw const char *name;
656 1.1 thorpej int nargs;
657 1.1 thorpej int nreturns;
658 1.4 scw const char *bootspec;
659 1.1 thorpej } args = {
660 1.1 thorpej "boot",
661 1.1 thorpej 1,
662 1.1 thorpej 0,
663 1.1 thorpej };
664 1.1 thorpej
665 1.1 thorpej args.bootspec = bootspec;
666 1.1 thorpej openfirmware(&args);
667 1.1 thorpej while (1); /* just in case */
668 1.1 thorpej }
669 1.1 thorpej
670 1.1 thorpej void
671 1.6.46.1 yamt OF_enter(void)
672 1.1 thorpej {
673 1.1 thorpej static struct {
674 1.4 scw const char *name;
675 1.1 thorpej int nargs;
676 1.1 thorpej int nreturns;
677 1.1 thorpej } args = {
678 1.1 thorpej "enter",
679 1.1 thorpej 0,
680 1.1 thorpej 0,
681 1.1 thorpej };
682 1.1 thorpej
683 1.1 thorpej openfirmware(&args);
684 1.1 thorpej }
685 1.1 thorpej
686 1.1 thorpej void
687 1.6.46.1 yamt OF_exit(void)
688 1.1 thorpej {
689 1.1 thorpej static struct {
690 1.4 scw const char *name;
691 1.1 thorpej int nargs;
692 1.1 thorpej int nreturns;
693 1.1 thorpej } args = {
694 1.1 thorpej "exit",
695 1.1 thorpej 0,
696 1.1 thorpej 0,
697 1.1 thorpej };
698 1.1 thorpej
699 1.1 thorpej openfirmware(&args);
700 1.1 thorpej while (1); /* just in case */
701 1.1 thorpej }
702 1.1 thorpej
703 1.1 thorpej void
704 1.2 chs (*OF_set_callback(newfunc))(void *)
705 1.2 chs void (*newfunc)(void *);
706 1.1 thorpej {
707 1.1 thorpej static struct {
708 1.4 scw const char *name;
709 1.1 thorpej int nargs;
710 1.1 thorpej int nreturns;
711 1.2 chs void (*newfunc)(void *);
712 1.2 chs void (*oldfunc)(void *);
713 1.1 thorpej } args = {
714 1.1 thorpej "set-callback",
715 1.1 thorpej 1,
716 1.1 thorpej 1,
717 1.1 thorpej };
718 1.1 thorpej
719 1.1 thorpej args.newfunc = newfunc;
720 1.1 thorpej if (openfirmware(&args) == -1)
721 1.1 thorpej return 0;
722 1.1 thorpej return args.oldfunc;
723 1.1 thorpej }
724