1 /* $NetBSD: openfirm.c,v 1.7 2009/03/14 15:36:02 dsl Exp $ */
5 * Digital Equipment Corporation. All rights reserved.
7 * This software is furnished under license and may be used and
8 * copied only in accordance with the following terms and conditions.
9 * Subject to these conditions, you may download, copy, install,
10 * use, modify and distribute this software in source and/or binary
11 * form. No title or ownership is transferred hereby.
13 * 1) Any source code used, modified or distributed must reproduce
14 * and retain this copyright notice and list of conditions as
15 * they appear in the source file.
17 * 2) No right is granted to use any trade name, trademark, or logo of
18 * Digital Equipment Corporation. Neither the "Digital Equipment
19 * Corporation" name nor any trademark or logo of Digital Equipment
20 * Corporation may be used to endorse or promote products derived
21 * from this software without the prior written permission of
22 * Digital Equipment Corporation.
24 * 3) This software is provided "AS-IS" and any express or implied
25 * warranties, including but not limited to, any implied warranties
26 * of merchantability, fitness for a particular purpose, or
27 * non-infringement are disclaimed. In no event shall DIGITAL be
28 * liable for any damages whatsoever, and in particular, DIGITAL
29 * shall not be liable for special, indirect, consequential, or
30 * incidental damages or damages for lost profits, loss of
31 * revenue or loss of use, whether such damages arise in contract,
32 * negligence, tort, under statute, in equity, at law or otherwise,
33 * even if advised of the possibility of such damage.
37 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
38 * Copyright (C) 1995, 1996 TooLs GmbH.
39 * All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. All advertising materials mentioning features or use of this software
50 * must display the following acknowledgement:
51 * This product includes software developed by TooLs GmbH.
52 * 4. The name of TooLs GmbH may not be used to endorse or promote products
53 * derived from this software without specific prior written permission.
55 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
56 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
57 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
58 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
60 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
61 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
62 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
63 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
64 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 #include <sys/cdefs.h>
68 __KERNEL_RCSID(0, "$NetBSD: openfirm.c,v 1.7 2009/03/14 15:36:02 dsl Exp $");
70 #include <sys/param.h>
72 #include <machine/stdarg.h>
74 #include <dev/ofw/openfirm.h>
78 * Wrapper routines for OFW client services.
80 * This code was adapted from the PowerPC version done by
81 * Wolfgang Solfrank. The main difference is that we don't
82 * do the silly "ofw_stack" dance to convert the OS's real-
83 * mode view of OFW to virtual-mode. We don't need to do
84 * that because our NetBSD port assumes virtual-mode OFW.
86 * We should work with Wolfgang to turn this into a MI file. -JJK
105 args
.phandle
= phandle
;
106 if (openfirmware(&args
) == -1)
112 OF_child(int phandle
)
126 args
.phandle
= phandle
;
127 if (openfirmware(&args
) == -1)
133 OF_parent(int phandle
)
147 args
.phandle
= phandle
;
148 if (openfirmware(&args
) == -1)
154 OF_instance_to_package(int ihandle
)
163 "instance-to-package",
168 args
.ihandle
= ihandle
;
169 if (openfirmware(&args
) == -1)
175 OF_nextprop(int handle
, const char *prop
, void *nextprop
)
191 args
.phandle
= handle
;
193 args
.nextprop
= nextprop
;
195 if (openfirmware(&args
) == -1)
201 OF_getprop(int handle
, const char *prop
, void *buf
, int buflen
)
218 args
.phandle
= handle
;
221 args
.buflen
= buflen
;
224 if (openfirmware(&args
) == -1)
230 OF_setprop(int handle
, const char *prop
, const void *buf
, int buflen
)
247 args
.phandle
= handle
;
250 args
.buflen
= buflen
;
253 if (openfirmware(&args
) == -1)
259 OF_getproplen(int handle
, const char *prop
)
274 args
.phandle
= handle
;
276 if (openfirmware(&args
) == -1)
282 OF_finddevice(const char *name
)
297 if (openfirmware(&args
) == -1)
303 OF_instance_to_path(int ihandle
, char *buf
, int buflen
)
319 args
.ihandle
= ihandle
;
321 args
.buflen
= buflen
;
322 if (openfirmware(&args
) < 0)
328 OF_package_to_path(int phandle
, char *buf
, int buflen
)
344 args
.phandle
= phandle
;
346 args
.buflen
= buflen
;
347 if (openfirmware(&args
) < 0)
354 OF_call_method(const char *method
, int ihandle
, int nargs
, int nreturns
, ...)
356 OF_call_method(method
, ihandle
, nargs
, nreturns
, va_alist
)
371 int args_n_results
[12];
381 args
.nargs
= nargs
+ 2;
382 args
.nreturns
= nreturns
+ 1;
383 args
.method
= method
;
384 args
.ihandle
= ihandle
;
385 va_start(ap
, nreturns
);
386 for (ip
= args
.args_n_results
+ (n
= nargs
); --n
>= 0;)
387 *--ip
= va_arg(ap
, int);
388 if (openfirmware(&args
) == -1) {
396 printf("call_method(%s): ihandle = %x, nargs = %d, nreturns = %d -- ",
397 method, ihandle, nargs, nreturns);
398 res = openfirmware(&args);
399 printf("res = %x\n", res);
400 printf("\targs_n_results = ");
401 for (i = 0; i < nargs + nreturns + 1; i++)
402 printf("%x ", args.args_n_results[i]);
404 if (res == -1) return -1;
407 if (args
.args_n_results
[nargs
]) {
409 return args
.args_n_results
[nargs
];
411 for (ip
= args
.args_n_results
+ nargs
+ (n
= args
.nreturns
); --n
> 0;)
412 *va_arg(ap
, int *) = *--ip
;
419 OF_call_method_1(const char *method
, int ihandle
, int nargs
, ...)
421 OF_call_method_1(method
, ihandle
, nargs
, va_alist
)
435 int args_n_results
[8];
445 args
.nargs
= nargs
+ 2;
446 args
.method
= method
;
447 args
.ihandle
= ihandle
;
449 for (ip
= args
.args_n_results
+ (n
= nargs
); --n
>= 0;)
450 *--ip
= va_arg(ap
, int);
452 if (openfirmware(&args
) == -1)
458 printf("call_method_1(%s): ihandle = %x, nargs = %d -- ",
459 method, ihandle, nargs);
460 res = openfirmware(&args);
461 printf("res = %x\n", res);
462 printf("\targs_n_results = ");
463 for (i = 0; i < nargs + 2; i++)
464 printf("%x ", args.args_n_results[i]);
466 if (res == -1) return -1;
469 if (args
.args_n_results
[nargs
])
471 return args
.args_n_results
[nargs
+ 1];
475 OF_open(const char *dname
)
490 if (openfirmware(&args
) == -1)
509 args
.handle
= handle
;
514 OF_read(int handle
, void *addr
, int len
)
530 args
.ihandle
= handle
;
533 if (openfirmware(&args
) == -1)
539 OF_write(int handle
, const void *addr
, int len
)
555 args
.ihandle
= handle
;
558 if (openfirmware(&args
) == -1)
564 OF_seek(int handle
, u_quad_t pos
)
580 args
.handle
= handle
;
581 args
.poshi
= (int)(pos
>> 32);
582 args
.poslo
= (int)pos
;
583 if (openfirmware(&args
) == -1)
589 OF_claim(void *virt
, u_int size
, u_int align
)
608 if (openfirmware(&args
) == -1)
610 return args
.baseaddr
;
614 OF_release(void *virt
, u_int size
)
634 OF_milliseconds(void)
652 OF_boot(const char *bootspec
)
658 const char *bootspec
;
665 args
.bootspec
= bootspec
;
667 while (1); /* just in case */
700 while (1); /* just in case */
704 (*OF_set_callback(newfunc
))(void *)
705 void (*newfunc
)(void *);
711 void (*newfunc
)(void *);
712 void (*oldfunc
)(void *);
719 args
.newfunc
= newfunc
;
720 if (openfirmware(&args
) == -1)