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