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