xref: /freebsd/sys/dev/ofw/ofw_standard.c (revision fdafd315)
191416fb2SNathan Whitehorn /*	$NetBSD: Locore.c,v 1.7 2000/08/20 07:04:59 tsubai Exp $	*/
291416fb2SNathan Whitehorn 
391416fb2SNathan Whitehorn /*-
44d846d26SWarner Losh  * SPDX-License-Identifier: BSD-4-Clause AND BSD-2-Clause
5718cf2ccSPedro F. Giffuni  *
691416fb2SNathan Whitehorn  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
791416fb2SNathan Whitehorn  * Copyright (C) 1995, 1996 TooLs GmbH.
891416fb2SNathan Whitehorn  * All rights reserved.
991416fb2SNathan Whitehorn  *
1091416fb2SNathan Whitehorn  * Redistribution and use in source and binary forms, with or without
1191416fb2SNathan Whitehorn  * modification, are permitted provided that the following conditions
1291416fb2SNathan Whitehorn  * are met:
1391416fb2SNathan Whitehorn  * 1. Redistributions of source code must retain the above copyright
1491416fb2SNathan Whitehorn  *    notice, this list of conditions and the following disclaimer.
1591416fb2SNathan Whitehorn  * 2. Redistributions in binary form must reproduce the above copyright
1691416fb2SNathan Whitehorn  *    notice, this list of conditions and the following disclaimer in the
1791416fb2SNathan Whitehorn  *    documentation and/or other materials provided with the distribution.
1891416fb2SNathan Whitehorn  * 3. All advertising materials mentioning features or use of this software
1991416fb2SNathan Whitehorn  *    must display the following acknowledgement:
2091416fb2SNathan Whitehorn  *	This product includes software developed by TooLs GmbH.
2191416fb2SNathan Whitehorn  * 4. The name of TooLs GmbH may not be used to endorse or promote products
2291416fb2SNathan Whitehorn  *    derived from this software without specific prior written permission.
2391416fb2SNathan Whitehorn  *
2491416fb2SNathan Whitehorn  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
2591416fb2SNathan Whitehorn  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2691416fb2SNathan Whitehorn  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2791416fb2SNathan Whitehorn  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2891416fb2SNathan Whitehorn  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2991416fb2SNathan Whitehorn  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
3091416fb2SNathan Whitehorn  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
3191416fb2SNathan Whitehorn  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
3291416fb2SNathan Whitehorn  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
3391416fb2SNathan Whitehorn  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3491416fb2SNathan Whitehorn  */
3591416fb2SNathan Whitehorn /*-
3691416fb2SNathan Whitehorn  * Copyright (C) 2000 Benno Rice.
3791416fb2SNathan Whitehorn  * All rights reserved.
3891416fb2SNathan Whitehorn  *
3991416fb2SNathan Whitehorn  * Redistribution and use in source and binary forms, with or without
4091416fb2SNathan Whitehorn  * modification, are permitted provided that the following conditions
4191416fb2SNathan Whitehorn  * are met:
4291416fb2SNathan Whitehorn  * 1. Redistributions of source code must retain the above copyright
4391416fb2SNathan Whitehorn  *    notice, this list of conditions and the following disclaimer.
4491416fb2SNathan Whitehorn  * 2. Redistributions in binary form must reproduce the above copyright
4591416fb2SNathan Whitehorn  *    notice, this list of conditions and the following disclaimer in the
4691416fb2SNathan Whitehorn  *    documentation and/or other materials provided with the distribution.
4791416fb2SNathan Whitehorn  *
4891416fb2SNathan Whitehorn  * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
4991416fb2SNathan Whitehorn  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
5091416fb2SNathan Whitehorn  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
5191416fb2SNathan Whitehorn  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
5291416fb2SNathan Whitehorn  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
5391416fb2SNathan Whitehorn  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
5491416fb2SNathan Whitehorn  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
5591416fb2SNathan Whitehorn  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
5691416fb2SNathan Whitehorn  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
5791416fb2SNathan Whitehorn  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5891416fb2SNathan Whitehorn  */
5991416fb2SNathan Whitehorn 
6091416fb2SNathan Whitehorn #include <sys/param.h>
6191416fb2SNathan Whitehorn #include <sys/kernel.h>
6291416fb2SNathan Whitehorn #include <sys/malloc.h>
6391416fb2SNathan Whitehorn #include <sys/systm.h>
6491416fb2SNathan Whitehorn 
6591416fb2SNathan Whitehorn #include <machine/stdarg.h>
6691416fb2SNathan Whitehorn 
6791416fb2SNathan Whitehorn #include <dev/ofw/ofwvar.h>
68481d6b54SMarius Strobl #include <dev/ofw/openfirm.h>
69481d6b54SMarius Strobl 
7091416fb2SNathan Whitehorn #include "ofw_if.h"
7191416fb2SNathan Whitehorn 
728297758aSRafal Jaworowski static int ofw_std_init(ofw_t ofw, void *openfirm);
7391416fb2SNathan Whitehorn static int ofw_std_test(ofw_t ofw, const char *name);
7491416fb2SNathan Whitehorn static int ofw_std_interpret(ofw_t ofw, const char *cmd, int nreturns,
75cdb25d82SMarius Strobl     cell_t *returns);
7691416fb2SNathan Whitehorn static phandle_t ofw_std_peer(ofw_t ofw, phandle_t node);
7791416fb2SNathan Whitehorn static phandle_t ofw_std_child(ofw_t ofw, phandle_t node);
7891416fb2SNathan Whitehorn static phandle_t ofw_std_parent(ofw_t ofw, phandle_t node);
7991416fb2SNathan Whitehorn static phandle_t ofw_std_instance_to_package(ofw_t ofw, ihandle_t instance);
8091416fb2SNathan Whitehorn static ssize_t ofw_std_getproplen(ofw_t ofw, phandle_t package,
8191416fb2SNathan Whitehorn     const char *propname);
8291416fb2SNathan Whitehorn static ssize_t ofw_std_getprop(ofw_t ofw, phandle_t package,
8391416fb2SNathan Whitehorn     const char *propname, void *buf, size_t buflen);
8491416fb2SNathan Whitehorn static int ofw_std_nextprop(ofw_t ofw, phandle_t package, const char *previous,
8591416fb2SNathan Whitehorn     char *buf, size_t);
864fc23012SAndriy Gapon static int ofw_std_setprop(ofw_t ofw, phandle_t package, const char *propname,
874fc23012SAndriy Gapon     const void *buf, size_t len);
8891416fb2SNathan Whitehorn static ssize_t ofw_std_canon(ofw_t ofw, const char *device, char *buf,
8991416fb2SNathan Whitehorn     size_t len);
9091416fb2SNathan Whitehorn static phandle_t ofw_std_finddevice(ofw_t ofw, const char *device);
9191416fb2SNathan Whitehorn static ssize_t ofw_std_instance_to_path(ofw_t ofw, ihandle_t instance,
9291416fb2SNathan Whitehorn     char *buf, size_t len);
9391416fb2SNathan Whitehorn static ssize_t ofw_std_package_to_path(ofw_t ofw, phandle_t package, char *buf,
9491416fb2SNathan Whitehorn     size_t len);
9591416fb2SNathan Whitehorn static int ofw_std_call_method(ofw_t ofw, ihandle_t instance,
96cdb25d82SMarius Strobl     const char *method, int nargs, int nreturns, cell_t *args_and_returns);
9791416fb2SNathan Whitehorn static ihandle_t ofw_std_open(ofw_t ofw, const char *device);
9891416fb2SNathan Whitehorn static void ofw_std_close(ofw_t ofw, ihandle_t instance);
9991416fb2SNathan Whitehorn static ssize_t ofw_std_read(ofw_t ofw, ihandle_t instance, void *addr,
10091416fb2SNathan Whitehorn     size_t len);
10191416fb2SNathan Whitehorn static ssize_t ofw_std_write(ofw_t ofw, ihandle_t instance, const void *addr,
10291416fb2SNathan Whitehorn     size_t len);
103481d6b54SMarius Strobl static int ofw_std_seek(ofw_t ofw, ihandle_t instance, uint64_t pos);
10491416fb2SNathan Whitehorn static caddr_t ofw_std_claim(ofw_t ofw, void *virt, size_t size, u_int align);
10591416fb2SNathan Whitehorn static void ofw_std_release(ofw_t ofw, void *virt, size_t size);
10691416fb2SNathan Whitehorn static void ofw_std_enter(ofw_t ofw);
10791416fb2SNathan Whitehorn static void ofw_std_exit(ofw_t ofw);
10891416fb2SNathan Whitehorn 
10991416fb2SNathan Whitehorn static ofw_method_t ofw_std_methods[] = {
11091416fb2SNathan Whitehorn 	OFWMETHOD(ofw_init,			ofw_std_init),
11191416fb2SNathan Whitehorn 	OFWMETHOD(ofw_peer,			ofw_std_peer),
11291416fb2SNathan Whitehorn 	OFWMETHOD(ofw_child,			ofw_std_child),
11391416fb2SNathan Whitehorn 	OFWMETHOD(ofw_parent,			ofw_std_parent),
11491416fb2SNathan Whitehorn 	OFWMETHOD(ofw_instance_to_package,	ofw_std_instance_to_package),
11591416fb2SNathan Whitehorn 	OFWMETHOD(ofw_getproplen,		ofw_std_getproplen),
11691416fb2SNathan Whitehorn 	OFWMETHOD(ofw_getprop,			ofw_std_getprop),
11791416fb2SNathan Whitehorn 	OFWMETHOD(ofw_nextprop,			ofw_std_nextprop),
11891416fb2SNathan Whitehorn 	OFWMETHOD(ofw_setprop,			ofw_std_setprop),
11991416fb2SNathan Whitehorn 	OFWMETHOD(ofw_canon,			ofw_std_canon),
12091416fb2SNathan Whitehorn 	OFWMETHOD(ofw_finddevice,		ofw_std_finddevice),
12191416fb2SNathan Whitehorn 	OFWMETHOD(ofw_instance_to_path,		ofw_std_instance_to_path),
12291416fb2SNathan Whitehorn 	OFWMETHOD(ofw_package_to_path,		ofw_std_package_to_path),
12391416fb2SNathan Whitehorn 
12491416fb2SNathan Whitehorn 	OFWMETHOD(ofw_test,			ofw_std_test),
12591416fb2SNathan Whitehorn 	OFWMETHOD(ofw_call_method,		ofw_std_call_method),
12691416fb2SNathan Whitehorn 	OFWMETHOD(ofw_interpret,		ofw_std_interpret),
12791416fb2SNathan Whitehorn 	OFWMETHOD(ofw_open,			ofw_std_open),
12891416fb2SNathan Whitehorn 	OFWMETHOD(ofw_close,			ofw_std_close),
12991416fb2SNathan Whitehorn 	OFWMETHOD(ofw_read,			ofw_std_read),
13091416fb2SNathan Whitehorn 	OFWMETHOD(ofw_write,			ofw_std_write),
13191416fb2SNathan Whitehorn 	OFWMETHOD(ofw_seek,			ofw_std_seek),
13291416fb2SNathan Whitehorn 	OFWMETHOD(ofw_claim,			ofw_std_claim),
13391416fb2SNathan Whitehorn 	OFWMETHOD(ofw_release,			ofw_std_release),
13491416fb2SNathan Whitehorn 	OFWMETHOD(ofw_enter,			ofw_std_enter),
13591416fb2SNathan Whitehorn 	OFWMETHOD(ofw_exit,			ofw_std_exit),
13691416fb2SNathan Whitehorn 	{ 0, 0 }
13791416fb2SNathan Whitehorn };
13891416fb2SNathan Whitehorn 
13991416fb2SNathan Whitehorn static ofw_def_t ofw_std = {
14091416fb2SNathan Whitehorn 	OFW_STD_DIRECT,
14191416fb2SNathan Whitehorn 	ofw_std_methods,
14291416fb2SNathan Whitehorn 	0
14391416fb2SNathan Whitehorn };
14491416fb2SNathan Whitehorn OFW_DEF(ofw_std);
14591416fb2SNathan Whitehorn 
14691416fb2SNathan Whitehorn static int (*openfirmware)(void *);
14791416fb2SNathan Whitehorn 
148481d6b54SMarius Strobl /* Initializer */
14991416fb2SNathan Whitehorn 
1508297758aSRafal Jaworowski static int
ofw_std_init(ofw_t ofw,void * openfirm)15191416fb2SNathan Whitehorn ofw_std_init(ofw_t ofw, void *openfirm)
15291416fb2SNathan Whitehorn {
153481d6b54SMarius Strobl 
15491416fb2SNathan Whitehorn 	openfirmware = (int (*)(void *))openfirm;
1558297758aSRafal Jaworowski 	return (0);
15691416fb2SNathan Whitehorn }
15791416fb2SNathan Whitehorn 
15891416fb2SNathan Whitehorn /*
15991416fb2SNathan Whitehorn  * Generic functions
16091416fb2SNathan Whitehorn  */
16191416fb2SNathan Whitehorn 
16291416fb2SNathan Whitehorn /* Test to see if a service exists. */
16391416fb2SNathan Whitehorn static int
ofw_std_test(ofw_t ofw,const char * name)16491416fb2SNathan Whitehorn ofw_std_test(ofw_t ofw, const char *name)
16591416fb2SNathan Whitehorn {
166d4bccd63SNathan Whitehorn 	struct {
16791416fb2SNathan Whitehorn 		cell_t name;
16891416fb2SNathan Whitehorn 		cell_t nargs;
16991416fb2SNathan Whitehorn 		cell_t nreturns;
17091416fb2SNathan Whitehorn 		cell_t service;
17191416fb2SNathan Whitehorn 		cell_t missing;
17291416fb2SNathan Whitehorn 	} args = {
17391416fb2SNathan Whitehorn 		(cell_t)"test",
17491416fb2SNathan Whitehorn 		1,
17591416fb2SNathan Whitehorn 		1,
17691416fb2SNathan Whitehorn 	};
17791416fb2SNathan Whitehorn 
17891416fb2SNathan Whitehorn 	args.service = (cell_t)name;
17991416fb2SNathan Whitehorn 	if (openfirmware(&args) == -1)
18091416fb2SNathan Whitehorn 		return (-1);
18191416fb2SNathan Whitehorn 	return (args.missing);
18291416fb2SNathan Whitehorn }
18391416fb2SNathan Whitehorn 
18491416fb2SNathan Whitehorn static int
ofw_std_interpret(ofw_t ofw,const char * cmd,int nreturns,cell_t * returns)185cdb25d82SMarius Strobl ofw_std_interpret(ofw_t ofw, const char *cmd, int nreturns, cell_t *returns)
18691416fb2SNathan Whitehorn {
187d4bccd63SNathan Whitehorn 	struct {
18891416fb2SNathan Whitehorn 		cell_t name;
18991416fb2SNathan Whitehorn 		cell_t nargs;
19091416fb2SNathan Whitehorn 		cell_t nreturns;
19191416fb2SNathan Whitehorn 		cell_t slot[16];
19291416fb2SNathan Whitehorn 	} args = {
19391416fb2SNathan Whitehorn 		(cell_t)"interpret",
19491416fb2SNathan Whitehorn 		1,
19591416fb2SNathan Whitehorn 	};
19691416fb2SNathan Whitehorn 	cell_t status;
19791416fb2SNathan Whitehorn 	int i = 0, j = 0;
19891416fb2SNathan Whitehorn 
19991416fb2SNathan Whitehorn 	args.nreturns = ++nreturns;
20091416fb2SNathan Whitehorn 	args.slot[i++] = (cell_t)cmd;
201481d6b54SMarius Strobl 	if (openfirmware(&args) == -1)
20291416fb2SNathan Whitehorn 		return (-1);
20391416fb2SNathan Whitehorn 	status = args.slot[i++];
20491416fb2SNathan Whitehorn 	while (i < 1 + nreturns)
20549bbb93cSMarius Strobl 		returns[j++] = args.slot[i++];
20691416fb2SNathan Whitehorn 	return (status);
20791416fb2SNathan Whitehorn }
20891416fb2SNathan Whitehorn 
20991416fb2SNathan Whitehorn /*
21091416fb2SNathan Whitehorn  * Device tree functions
21191416fb2SNathan Whitehorn  */
21291416fb2SNathan Whitehorn 
21391416fb2SNathan Whitehorn /* Return the next sibling of this node or 0. */
21491416fb2SNathan Whitehorn static phandle_t
ofw_std_peer(ofw_t ofw,phandle_t node)21591416fb2SNathan Whitehorn ofw_std_peer(ofw_t ofw, phandle_t node)
21691416fb2SNathan Whitehorn {
217d4bccd63SNathan Whitehorn 	struct {
21891416fb2SNathan Whitehorn 		cell_t name;
21991416fb2SNathan Whitehorn 		cell_t nargs;
22091416fb2SNathan Whitehorn 		cell_t nreturns;
22191416fb2SNathan Whitehorn 		cell_t node;
22291416fb2SNathan Whitehorn 		cell_t next;
22391416fb2SNathan Whitehorn 	} args = {
22491416fb2SNathan Whitehorn 		(cell_t)"peer",
22591416fb2SNathan Whitehorn 		1,
22691416fb2SNathan Whitehorn 		1,
22791416fb2SNathan Whitehorn 	};
22891416fb2SNathan Whitehorn 
22991416fb2SNathan Whitehorn 	args.node = node;
23091416fb2SNathan Whitehorn 	if (openfirmware(&args) == -1)
23165184f89SNathan Whitehorn 		return (0);
23291416fb2SNathan Whitehorn 	return (args.next);
23391416fb2SNathan Whitehorn }
23491416fb2SNathan Whitehorn 
23591416fb2SNathan Whitehorn /* Return the first child of this node or 0. */
23691416fb2SNathan Whitehorn static phandle_t
ofw_std_child(ofw_t ofw,phandle_t node)23791416fb2SNathan Whitehorn ofw_std_child(ofw_t ofw, phandle_t node)
23891416fb2SNathan Whitehorn {
239d4bccd63SNathan Whitehorn 	struct {
24091416fb2SNathan Whitehorn 		cell_t name;
24191416fb2SNathan Whitehorn 		cell_t nargs;
24291416fb2SNathan Whitehorn 		cell_t nreturns;
24391416fb2SNathan Whitehorn 		cell_t node;
24491416fb2SNathan Whitehorn 		cell_t child;
24591416fb2SNathan Whitehorn 	} args = {
24691416fb2SNathan Whitehorn 		(cell_t)"child",
24791416fb2SNathan Whitehorn 		1,
24891416fb2SNathan Whitehorn 		1,
24991416fb2SNathan Whitehorn 	};
25091416fb2SNathan Whitehorn 
25191416fb2SNathan Whitehorn 	args.node = node;
25291416fb2SNathan Whitehorn 	if (openfirmware(&args) == -1)
25365184f89SNathan Whitehorn 		return (0);
25491416fb2SNathan Whitehorn 	return (args.child);
25591416fb2SNathan Whitehorn }
25691416fb2SNathan Whitehorn 
25791416fb2SNathan Whitehorn /* Return the parent of this node or 0. */
25891416fb2SNathan Whitehorn static phandle_t
ofw_std_parent(ofw_t ofw,phandle_t node)25991416fb2SNathan Whitehorn ofw_std_parent(ofw_t ofw, phandle_t node)
26091416fb2SNathan Whitehorn {
261d4bccd63SNathan Whitehorn 	struct {
26291416fb2SNathan Whitehorn 		cell_t name;
26391416fb2SNathan Whitehorn 		cell_t nargs;
26491416fb2SNathan Whitehorn 		cell_t nreturns;
26591416fb2SNathan Whitehorn 		cell_t node;
26691416fb2SNathan Whitehorn 		cell_t parent;
26791416fb2SNathan Whitehorn 	} args = {
26891416fb2SNathan Whitehorn 		(cell_t)"parent",
26991416fb2SNathan Whitehorn 		1,
27091416fb2SNathan Whitehorn 		1,
27191416fb2SNathan Whitehorn 	};
27291416fb2SNathan Whitehorn 
27391416fb2SNathan Whitehorn 	args.node = node;
27491416fb2SNathan Whitehorn 	if (openfirmware(&args) == -1)
27565184f89SNathan Whitehorn 		return (0);
27691416fb2SNathan Whitehorn 	return (args.parent);
27791416fb2SNathan Whitehorn }
27891416fb2SNathan Whitehorn 
27991416fb2SNathan Whitehorn /* Return the package handle that corresponds to an instance handle. */
28091416fb2SNathan Whitehorn static phandle_t
ofw_std_instance_to_package(ofw_t ofw,ihandle_t instance)28191416fb2SNathan Whitehorn ofw_std_instance_to_package(ofw_t ofw, ihandle_t instance)
28291416fb2SNathan Whitehorn {
283d4bccd63SNathan Whitehorn 	struct {
28491416fb2SNathan Whitehorn 		cell_t name;
28591416fb2SNathan Whitehorn 		cell_t nargs;
28691416fb2SNathan Whitehorn 		cell_t nreturns;
28791416fb2SNathan Whitehorn 		cell_t instance;
28891416fb2SNathan Whitehorn 		cell_t package;
28991416fb2SNathan Whitehorn 	} args = {
29091416fb2SNathan Whitehorn 		(cell_t)"instance-to-package",
29191416fb2SNathan Whitehorn 		1,
29291416fb2SNathan Whitehorn 		1,
29391416fb2SNathan Whitehorn 	};
29491416fb2SNathan Whitehorn 
29591416fb2SNathan Whitehorn 	args.instance = instance;
29691416fb2SNathan Whitehorn 	if (openfirmware(&args) == -1)
29791416fb2SNathan Whitehorn 		return (-1);
29891416fb2SNathan Whitehorn 	return (args.package);
29991416fb2SNathan Whitehorn }
30091416fb2SNathan Whitehorn 
30191416fb2SNathan Whitehorn /* Get the length of a property of a package. */
30291416fb2SNathan Whitehorn static ssize_t
ofw_std_getproplen(ofw_t ofw,phandle_t package,const char * propname)30391416fb2SNathan Whitehorn ofw_std_getproplen(ofw_t ofw, phandle_t package, const char *propname)
30491416fb2SNathan Whitehorn {
305d4bccd63SNathan Whitehorn 	struct {
30691416fb2SNathan Whitehorn 		cell_t name;
30791416fb2SNathan Whitehorn 		cell_t nargs;
30891416fb2SNathan Whitehorn 		cell_t nreturns;
30991416fb2SNathan Whitehorn 		cell_t package;
31091416fb2SNathan Whitehorn 		cell_t propname;
31191416fb2SNathan Whitehorn 		cell_t proplen;
31291416fb2SNathan Whitehorn 	} args = {
31391416fb2SNathan Whitehorn 		(cell_t)"getproplen",
31491416fb2SNathan Whitehorn 		2,
31591416fb2SNathan Whitehorn 		1,
31691416fb2SNathan Whitehorn 	};
31791416fb2SNathan Whitehorn 
31891416fb2SNathan Whitehorn 	args.package = package;
31991416fb2SNathan Whitehorn 	args.propname = (cell_t)propname;
32091416fb2SNathan Whitehorn 	if (openfirmware(&args) == -1)
32191416fb2SNathan Whitehorn 		return (-1);
32291416fb2SNathan Whitehorn 	return (args.proplen);
32391416fb2SNathan Whitehorn }
32491416fb2SNathan Whitehorn 
32591416fb2SNathan Whitehorn /* Get the value of a property of a package. */
32691416fb2SNathan Whitehorn static ssize_t
ofw_std_getprop(ofw_t ofw,phandle_t package,const char * propname,void * buf,size_t buflen)32791416fb2SNathan Whitehorn ofw_std_getprop(ofw_t ofw, phandle_t package, const char *propname, void *buf,
32891416fb2SNathan Whitehorn     size_t buflen)
32991416fb2SNathan Whitehorn {
330d4bccd63SNathan Whitehorn 	struct {
33191416fb2SNathan Whitehorn 		cell_t name;
33291416fb2SNathan Whitehorn 		cell_t nargs;
33391416fb2SNathan Whitehorn 		cell_t nreturns;
33491416fb2SNathan Whitehorn 		cell_t package;
33591416fb2SNathan Whitehorn 		cell_t propname;
33691416fb2SNathan Whitehorn 		cell_t buf;
33791416fb2SNathan Whitehorn 		cell_t buflen;
33891416fb2SNathan Whitehorn 		cell_t size;
33991416fb2SNathan Whitehorn 	} args = {
34091416fb2SNathan Whitehorn 		(cell_t)"getprop",
34191416fb2SNathan Whitehorn 		4,
34291416fb2SNathan Whitehorn 		1,
34391416fb2SNathan Whitehorn 	};
34491416fb2SNathan Whitehorn 
34591416fb2SNathan Whitehorn 	args.package = package;
34691416fb2SNathan Whitehorn 	args.propname = (cell_t)propname;
34791416fb2SNathan Whitehorn 	args.buf = (cell_t)buf;
34891416fb2SNathan Whitehorn 	args.buflen = buflen;
34991416fb2SNathan Whitehorn 	if (openfirmware(&args) == -1)
35091416fb2SNathan Whitehorn 		return (-1);
35191416fb2SNathan Whitehorn 	return (args.size);
35291416fb2SNathan Whitehorn }
35391416fb2SNathan Whitehorn 
35491416fb2SNathan Whitehorn /* Get the next property of a package. */
35591416fb2SNathan Whitehorn static int
ofw_std_nextprop(ofw_t ofw,phandle_t package,const char * previous,char * buf,size_t size)35691416fb2SNathan Whitehorn ofw_std_nextprop(ofw_t ofw, phandle_t package, const char *previous, char *buf,
35791416fb2SNathan Whitehorn     size_t size)
35891416fb2SNathan Whitehorn {
359d4bccd63SNathan Whitehorn 	struct {
36091416fb2SNathan Whitehorn 		cell_t name;
36191416fb2SNathan Whitehorn 		cell_t nargs;
36291416fb2SNathan Whitehorn 		cell_t nreturns;
36391416fb2SNathan Whitehorn 		cell_t package;
36491416fb2SNathan Whitehorn 		cell_t previous;
36591416fb2SNathan Whitehorn 		cell_t buf;
36691416fb2SNathan Whitehorn 		cell_t flag;
36791416fb2SNathan Whitehorn 	} args = {
36891416fb2SNathan Whitehorn 		(cell_t)"nextprop",
36991416fb2SNathan Whitehorn 		3,
37091416fb2SNathan Whitehorn 		1,
37191416fb2SNathan Whitehorn 	};
37291416fb2SNathan Whitehorn 
37391416fb2SNathan Whitehorn 	args.package = package;
37491416fb2SNathan Whitehorn 	args.previous = (cell_t)previous;
37591416fb2SNathan Whitehorn 	args.buf = (cell_t)buf;
37691416fb2SNathan Whitehorn 	if (openfirmware(&args) == -1)
37791416fb2SNathan Whitehorn 		return (-1);
37891416fb2SNathan Whitehorn 	return (args.flag);
37991416fb2SNathan Whitehorn }
38091416fb2SNathan Whitehorn 
38191416fb2SNathan Whitehorn /* Set the value of a property of a package. */
38291416fb2SNathan Whitehorn /* XXX Has a bug on FirePower */
38391416fb2SNathan Whitehorn static int
ofw_std_setprop(ofw_t ofw,phandle_t package,const char * propname,const void * buf,size_t len)3844fc23012SAndriy Gapon ofw_std_setprop(ofw_t ofw, phandle_t package, const char *propname,
3854fc23012SAndriy Gapon     const void *buf, size_t len)
38691416fb2SNathan Whitehorn {
387d4bccd63SNathan Whitehorn 	struct {
38891416fb2SNathan Whitehorn 		cell_t name;
38991416fb2SNathan Whitehorn 		cell_t nargs;
39091416fb2SNathan Whitehorn 		cell_t nreturns;
39191416fb2SNathan Whitehorn 		cell_t package;
39291416fb2SNathan Whitehorn 		cell_t propname;
39391416fb2SNathan Whitehorn 		cell_t buf;
39491416fb2SNathan Whitehorn 		cell_t len;
39591416fb2SNathan Whitehorn 		cell_t size;
39691416fb2SNathan Whitehorn 	} args = {
39791416fb2SNathan Whitehorn 		(cell_t)"setprop",
39891416fb2SNathan Whitehorn 		4,
39991416fb2SNathan Whitehorn 		1,
40091416fb2SNathan Whitehorn 	};
40191416fb2SNathan Whitehorn 
40291416fb2SNathan Whitehorn 	args.package = package;
40391416fb2SNathan Whitehorn 	args.propname = (cell_t)propname;
40491416fb2SNathan Whitehorn 	args.buf = (cell_t)buf;
40591416fb2SNathan Whitehorn 	args.len = len;
40691416fb2SNathan Whitehorn 	if (openfirmware(&args) == -1)
40791416fb2SNathan Whitehorn 		return (-1);
40891416fb2SNathan Whitehorn 	return (args.size);
40991416fb2SNathan Whitehorn }
41091416fb2SNathan Whitehorn 
41191416fb2SNathan Whitehorn /* Convert a device specifier to a fully qualified pathname. */
41291416fb2SNathan Whitehorn static ssize_t
ofw_std_canon(ofw_t ofw,const char * device,char * buf,size_t len)41391416fb2SNathan Whitehorn ofw_std_canon(ofw_t ofw, const char *device, char *buf, size_t len)
41491416fb2SNathan Whitehorn {
415d4bccd63SNathan Whitehorn 	struct {
41691416fb2SNathan Whitehorn 		cell_t name;
41791416fb2SNathan Whitehorn 		cell_t nargs;
41891416fb2SNathan Whitehorn 		cell_t nreturns;
41991416fb2SNathan Whitehorn 		cell_t device;
42091416fb2SNathan Whitehorn 		cell_t buf;
42191416fb2SNathan Whitehorn 		cell_t len;
42291416fb2SNathan Whitehorn 		cell_t size;
42391416fb2SNathan Whitehorn 	} args = {
42491416fb2SNathan Whitehorn 		(cell_t)"canon",
42591416fb2SNathan Whitehorn 		3,
42691416fb2SNathan Whitehorn 		1,
42791416fb2SNathan Whitehorn 	};
42891416fb2SNathan Whitehorn 
42991416fb2SNathan Whitehorn 	args.device = (cell_t)device;
43091416fb2SNathan Whitehorn 	args.buf = (cell_t)buf;
43191416fb2SNathan Whitehorn 	args.len = len;
43291416fb2SNathan Whitehorn 	if (openfirmware(&args) == -1)
43391416fb2SNathan Whitehorn 		return (-1);
43491416fb2SNathan Whitehorn 	return (args.size);
43591416fb2SNathan Whitehorn }
43691416fb2SNathan Whitehorn 
43791416fb2SNathan Whitehorn /* Return a package handle for the specified device. */
43891416fb2SNathan Whitehorn static phandle_t
ofw_std_finddevice(ofw_t ofw,const char * device)43991416fb2SNathan Whitehorn ofw_std_finddevice(ofw_t ofw, const char *device)
44091416fb2SNathan Whitehorn {
441d4bccd63SNathan Whitehorn 	struct {
44291416fb2SNathan Whitehorn 		cell_t name;
44391416fb2SNathan Whitehorn 		cell_t nargs;
44491416fb2SNathan Whitehorn 		cell_t nreturns;
44591416fb2SNathan Whitehorn 		cell_t device;
44691416fb2SNathan Whitehorn 		cell_t package;
44791416fb2SNathan Whitehorn 	} args = {
44891416fb2SNathan Whitehorn 		(cell_t)"finddevice",
44991416fb2SNathan Whitehorn 		1,
45091416fb2SNathan Whitehorn 		1,
45191416fb2SNathan Whitehorn 	};
45291416fb2SNathan Whitehorn 
45391416fb2SNathan Whitehorn 	args.device = (cell_t)device;
45491416fb2SNathan Whitehorn 	if (openfirmware(&args) == -1)
45591416fb2SNathan Whitehorn 		return (-1);
45691416fb2SNathan Whitehorn 	return (args.package);
45791416fb2SNathan Whitehorn }
45891416fb2SNathan Whitehorn 
45991416fb2SNathan Whitehorn /* Return the fully qualified pathname corresponding to an instance. */
46091416fb2SNathan Whitehorn static ssize_t
ofw_std_instance_to_path(ofw_t ofw,ihandle_t instance,char * buf,size_t len)46191416fb2SNathan Whitehorn ofw_std_instance_to_path(ofw_t ofw, ihandle_t instance, char *buf, size_t len)
46291416fb2SNathan Whitehorn {
463d4bccd63SNathan Whitehorn 	struct {
46491416fb2SNathan Whitehorn 		cell_t name;
46591416fb2SNathan Whitehorn 		cell_t nargs;
46691416fb2SNathan Whitehorn 		cell_t nreturns;
46791416fb2SNathan Whitehorn 		cell_t instance;
46891416fb2SNathan Whitehorn 		cell_t buf;
46991416fb2SNathan Whitehorn 		cell_t len;
47091416fb2SNathan Whitehorn 		cell_t size;
47191416fb2SNathan Whitehorn 	} args = {
47291416fb2SNathan Whitehorn 		(cell_t)"instance-to-path",
47391416fb2SNathan Whitehorn 		3,
47491416fb2SNathan Whitehorn 		1,
47591416fb2SNathan Whitehorn 	};
47691416fb2SNathan Whitehorn 
47791416fb2SNathan Whitehorn 	args.instance = instance;
47891416fb2SNathan Whitehorn 	args.buf = (cell_t)buf;
47991416fb2SNathan Whitehorn 	args.len = len;
48091416fb2SNathan Whitehorn 	if (openfirmware(&args) == -1)
48191416fb2SNathan Whitehorn 		return (-1);
48291416fb2SNathan Whitehorn 	return (args.size);
48391416fb2SNathan Whitehorn }
48491416fb2SNathan Whitehorn 
48591416fb2SNathan Whitehorn /* Return the fully qualified pathname corresponding to a package. */
48691416fb2SNathan Whitehorn static ssize_t
ofw_std_package_to_path(ofw_t ofw,phandle_t package,char * buf,size_t len)48791416fb2SNathan Whitehorn ofw_std_package_to_path(ofw_t ofw, phandle_t package, char *buf, size_t len)
48891416fb2SNathan Whitehorn {
489d4bccd63SNathan Whitehorn 	struct {
49091416fb2SNathan Whitehorn 		cell_t name;
49191416fb2SNathan Whitehorn 		cell_t nargs;
49291416fb2SNathan Whitehorn 		cell_t nreturns;
49391416fb2SNathan Whitehorn 		cell_t package;
49491416fb2SNathan Whitehorn 		cell_t buf;
49591416fb2SNathan Whitehorn 		cell_t len;
49691416fb2SNathan Whitehorn 		cell_t size;
49791416fb2SNathan Whitehorn 	} args = {
49891416fb2SNathan Whitehorn 		(cell_t)"package-to-path",
49991416fb2SNathan Whitehorn 		3,
50091416fb2SNathan Whitehorn 		1,
50191416fb2SNathan Whitehorn 	};
50291416fb2SNathan Whitehorn 
50391416fb2SNathan Whitehorn 	args.package = package;
50491416fb2SNathan Whitehorn 	args.buf = (cell_t)buf;
50591416fb2SNathan Whitehorn 	args.len = len;
50691416fb2SNathan Whitehorn 	if (openfirmware(&args) == -1)
50791416fb2SNathan Whitehorn 		return (-1);
50891416fb2SNathan Whitehorn 	return (args.size);
50991416fb2SNathan Whitehorn }
51091416fb2SNathan Whitehorn 
51191416fb2SNathan Whitehorn /*  Call the method in the scope of a given instance. */
51291416fb2SNathan Whitehorn static int
ofw_std_call_method(ofw_t ofw,ihandle_t instance,const char * method,int nargs,int nreturns,cell_t * args_and_returns)51391416fb2SNathan Whitehorn ofw_std_call_method(ofw_t ofw, ihandle_t instance, const char *method,
514054e5dcbSNathan Whitehorn     int nargs, int nreturns, cell_t *args_and_returns)
51591416fb2SNathan Whitehorn {
516d4bccd63SNathan Whitehorn 	struct {
51791416fb2SNathan Whitehorn 		cell_t name;
51891416fb2SNathan Whitehorn 		cell_t nargs;
51991416fb2SNathan Whitehorn 		cell_t nreturns;
52091416fb2SNathan Whitehorn 		cell_t method;
52191416fb2SNathan Whitehorn 		cell_t instance;
52291416fb2SNathan Whitehorn 		cell_t args_n_results[12];
52391416fb2SNathan Whitehorn 	} args = {
52491416fb2SNathan Whitehorn 		(cell_t)"call-method",
52591416fb2SNathan Whitehorn 		2,
52691416fb2SNathan Whitehorn 		1,
52791416fb2SNathan Whitehorn 	};
528cdb25d82SMarius Strobl 	cell_t *ap, *cp;
52991416fb2SNathan Whitehorn 	int n;
53091416fb2SNathan Whitehorn 
53191416fb2SNathan Whitehorn 	if (nargs > 6)
53291416fb2SNathan Whitehorn 		return (-1);
53391416fb2SNathan Whitehorn 	args.nargs = nargs + 2;
53491416fb2SNathan Whitehorn 	args.nreturns = nreturns + 1;
53591416fb2SNathan Whitehorn 	args.method = (cell_t)method;
53691416fb2SNathan Whitehorn 	args.instance = instance;
53791416fb2SNathan Whitehorn 
53891416fb2SNathan Whitehorn 	ap = args_and_returns;
53991416fb2SNathan Whitehorn 	for (cp = args.args_n_results + (n = nargs); --n >= 0;)
54091416fb2SNathan Whitehorn 		*--cp = *(ap++);
54191416fb2SNathan Whitehorn 	if (openfirmware(&args) == -1)
54291416fb2SNathan Whitehorn 		return (-1);
54391416fb2SNathan Whitehorn 	if (args.args_n_results[nargs])
54491416fb2SNathan Whitehorn 		return (args.args_n_results[nargs]);
54591416fb2SNathan Whitehorn 	for (cp = args.args_n_results + nargs + (n = args.nreturns); --n > 0;)
54691416fb2SNathan Whitehorn 		*(ap++) = *--cp;
54791416fb2SNathan Whitehorn 	return (0);
54891416fb2SNathan Whitehorn }
54991416fb2SNathan Whitehorn 
55091416fb2SNathan Whitehorn /*
55191416fb2SNathan Whitehorn  * Device I/O functions
55291416fb2SNathan Whitehorn  */
55391416fb2SNathan Whitehorn 
55491416fb2SNathan Whitehorn /* Open an instance for a device. */
55591416fb2SNathan Whitehorn static ihandle_t
ofw_std_open(ofw_t ofw,const char * device)55691416fb2SNathan Whitehorn ofw_std_open(ofw_t ofw, const char *device)
55791416fb2SNathan Whitehorn {
558d4bccd63SNathan Whitehorn 	struct {
55991416fb2SNathan Whitehorn 		cell_t name;
56091416fb2SNathan Whitehorn 		cell_t nargs;
56191416fb2SNathan Whitehorn 		cell_t nreturns;
56291416fb2SNathan Whitehorn 		cell_t device;
56391416fb2SNathan Whitehorn 		cell_t instance;
56491416fb2SNathan Whitehorn 	} args = {
56591416fb2SNathan Whitehorn 		(cell_t)"open",
56691416fb2SNathan Whitehorn 		1,
56791416fb2SNathan Whitehorn 		1,
56891416fb2SNathan Whitehorn 	};
56991416fb2SNathan Whitehorn 
57091416fb2SNathan Whitehorn 	args.device = (cell_t)device;
571481d6b54SMarius Strobl 	if (openfirmware(&args) == -1 || args.instance == 0)
57291416fb2SNathan Whitehorn 		return (-1);
57391416fb2SNathan Whitehorn 	return (args.instance);
57491416fb2SNathan Whitehorn }
57591416fb2SNathan Whitehorn 
57691416fb2SNathan Whitehorn /* Close an instance. */
57791416fb2SNathan Whitehorn static void
ofw_std_close(ofw_t ofw,ihandle_t instance)57891416fb2SNathan Whitehorn ofw_std_close(ofw_t ofw, ihandle_t instance)
57991416fb2SNathan Whitehorn {
580d4bccd63SNathan Whitehorn 	struct {
58191416fb2SNathan Whitehorn 		cell_t name;
58291416fb2SNathan Whitehorn 		cell_t nargs;
58391416fb2SNathan Whitehorn 		cell_t nreturns;
58491416fb2SNathan Whitehorn 		cell_t instance;
58591416fb2SNathan Whitehorn 	} args = {
58691416fb2SNathan Whitehorn 		(cell_t)"close",
58791416fb2SNathan Whitehorn 		1,
588bd7e69e4SMarius Strobl 		0,
58991416fb2SNathan Whitehorn 	};
59091416fb2SNathan Whitehorn 
59191416fb2SNathan Whitehorn 	args.instance = instance;
59291416fb2SNathan Whitehorn 	openfirmware(&args);
59391416fb2SNathan Whitehorn }
59491416fb2SNathan Whitehorn 
59591416fb2SNathan Whitehorn /* Read from an instance. */
59691416fb2SNathan Whitehorn static ssize_t
ofw_std_read(ofw_t ofw,ihandle_t instance,void * addr,size_t len)59791416fb2SNathan Whitehorn ofw_std_read(ofw_t ofw, ihandle_t instance, void *addr, size_t len)
59891416fb2SNathan Whitehorn {
599d4bccd63SNathan Whitehorn 	struct {
60091416fb2SNathan Whitehorn 		cell_t name;
60191416fb2SNathan Whitehorn 		cell_t nargs;
60291416fb2SNathan Whitehorn 		cell_t nreturns;
60391416fb2SNathan Whitehorn 		cell_t instance;
60491416fb2SNathan Whitehorn 		cell_t addr;
60591416fb2SNathan Whitehorn 		cell_t len;
60691416fb2SNathan Whitehorn 		cell_t actual;
60791416fb2SNathan Whitehorn 	} args = {
60891416fb2SNathan Whitehorn 		(cell_t)"read",
60991416fb2SNathan Whitehorn 		3,
61091416fb2SNathan Whitehorn 		1,
61191416fb2SNathan Whitehorn 	};
61291416fb2SNathan Whitehorn 
61391416fb2SNathan Whitehorn 	args.instance = instance;
61491416fb2SNathan Whitehorn 	args.addr = (cell_t)addr;
61591416fb2SNathan Whitehorn 	args.len = len;
61691416fb2SNathan Whitehorn 	if (openfirmware(&args) == -1)
61791416fb2SNathan Whitehorn 		return (-1);
61891416fb2SNathan Whitehorn 
61991416fb2SNathan Whitehorn 	return (args.actual);
62091416fb2SNathan Whitehorn }
62191416fb2SNathan Whitehorn 
62291416fb2SNathan Whitehorn /* Write to an instance. */
62391416fb2SNathan Whitehorn static ssize_t
ofw_std_write(ofw_t ofw,ihandle_t instance,const void * addr,size_t len)62491416fb2SNathan Whitehorn ofw_std_write(ofw_t ofw, ihandle_t instance, const void *addr, size_t len)
62591416fb2SNathan Whitehorn {
626d4bccd63SNathan Whitehorn 	struct {
62791416fb2SNathan Whitehorn 		cell_t name;
62891416fb2SNathan Whitehorn 		cell_t nargs;
62991416fb2SNathan Whitehorn 		cell_t nreturns;
63091416fb2SNathan Whitehorn 		cell_t instance;
63191416fb2SNathan Whitehorn 		cell_t addr;
63291416fb2SNathan Whitehorn 		cell_t len;
63391416fb2SNathan Whitehorn 		cell_t actual;
63491416fb2SNathan Whitehorn 	} args = {
63591416fb2SNathan Whitehorn 		(cell_t)"write",
63691416fb2SNathan Whitehorn 		3,
63791416fb2SNathan Whitehorn 		1,
63891416fb2SNathan Whitehorn 	};
63991416fb2SNathan Whitehorn 
64091416fb2SNathan Whitehorn 	args.instance = instance;
64191416fb2SNathan Whitehorn 	args.addr = (cell_t)addr;
64291416fb2SNathan Whitehorn 	args.len = len;
64391416fb2SNathan Whitehorn 	if (openfirmware(&args) == -1)
64491416fb2SNathan Whitehorn 		return (-1);
64591416fb2SNathan Whitehorn 	return (args.actual);
64691416fb2SNathan Whitehorn }
64791416fb2SNathan Whitehorn 
64891416fb2SNathan Whitehorn /* Seek to a position. */
64991416fb2SNathan Whitehorn static int
ofw_std_seek(ofw_t ofw,ihandle_t instance,uint64_t pos)650481d6b54SMarius Strobl ofw_std_seek(ofw_t ofw, ihandle_t instance, uint64_t pos)
65191416fb2SNathan Whitehorn {
652d4bccd63SNathan Whitehorn 	struct {
65391416fb2SNathan Whitehorn 		cell_t name;
65491416fb2SNathan Whitehorn 		cell_t nargs;
65591416fb2SNathan Whitehorn 		cell_t nreturns;
65691416fb2SNathan Whitehorn 		cell_t instance;
65791416fb2SNathan Whitehorn 		cell_t poshi;
65891416fb2SNathan Whitehorn 		cell_t poslo;
65991416fb2SNathan Whitehorn 		cell_t status;
66091416fb2SNathan Whitehorn 	} args = {
66191416fb2SNathan Whitehorn 		(cell_t)"seek",
66291416fb2SNathan Whitehorn 		3,
66391416fb2SNathan Whitehorn 		1,
66491416fb2SNathan Whitehorn 	};
66591416fb2SNathan Whitehorn 
66691416fb2SNathan Whitehorn 	args.instance = instance;
66791416fb2SNathan Whitehorn 	args.poshi = pos >> 32;
66891416fb2SNathan Whitehorn 	args.poslo = pos;
66991416fb2SNathan Whitehorn 	if (openfirmware(&args) == -1)
67091416fb2SNathan Whitehorn 		return (-1);
67191416fb2SNathan Whitehorn 	return (args.status);
67291416fb2SNathan Whitehorn }
67391416fb2SNathan Whitehorn 
67491416fb2SNathan Whitehorn /*
67591416fb2SNathan Whitehorn  * Memory functions
67691416fb2SNathan Whitehorn  */
67791416fb2SNathan Whitehorn 
67891416fb2SNathan Whitehorn /* Claim an area of memory. */
67991416fb2SNathan Whitehorn static caddr_t
ofw_std_claim(ofw_t ofw,void * virt,size_t size,u_int align)68091416fb2SNathan Whitehorn ofw_std_claim(ofw_t ofw, void *virt, size_t size, u_int align)
68191416fb2SNathan Whitehorn {
682d4bccd63SNathan Whitehorn 	struct {
68391416fb2SNathan Whitehorn 		cell_t name;
68491416fb2SNathan Whitehorn 		cell_t nargs;
68591416fb2SNathan Whitehorn 		cell_t nreturns;
68691416fb2SNathan Whitehorn 		cell_t virt;
68791416fb2SNathan Whitehorn 		cell_t size;
68891416fb2SNathan Whitehorn 		cell_t align;
68991416fb2SNathan Whitehorn 		cell_t baseaddr;
69091416fb2SNathan Whitehorn 	} args = {
69191416fb2SNathan Whitehorn 		(cell_t)"claim",
69291416fb2SNathan Whitehorn 		3,
69391416fb2SNathan Whitehorn 		1,
69491416fb2SNathan Whitehorn 	};
69591416fb2SNathan Whitehorn 
69691416fb2SNathan Whitehorn 	args.virt = (cell_t)virt;
69791416fb2SNathan Whitehorn 	args.size = size;
69891416fb2SNathan Whitehorn 	args.align = align;
69991416fb2SNathan Whitehorn 	if (openfirmware(&args) == -1)
70091416fb2SNathan Whitehorn 		return ((void *)-1);
70191416fb2SNathan Whitehorn 	return ((void *)args.baseaddr);
70291416fb2SNathan Whitehorn }
70391416fb2SNathan Whitehorn 
70491416fb2SNathan Whitehorn /* Release an area of memory. */
70591416fb2SNathan Whitehorn static void
ofw_std_release(ofw_t ofw,void * virt,size_t size)70691416fb2SNathan Whitehorn ofw_std_release(ofw_t ofw, void *virt, size_t size)
70791416fb2SNathan Whitehorn {
708d4bccd63SNathan Whitehorn 	struct {
70991416fb2SNathan Whitehorn 		cell_t name;
71091416fb2SNathan Whitehorn 		cell_t nargs;
71191416fb2SNathan Whitehorn 		cell_t nreturns;
71291416fb2SNathan Whitehorn 		cell_t virt;
71391416fb2SNathan Whitehorn 		cell_t size;
71491416fb2SNathan Whitehorn 	} args = {
71591416fb2SNathan Whitehorn 		(cell_t)"release",
71691416fb2SNathan Whitehorn 		2,
717bd7e69e4SMarius Strobl 		0,
71891416fb2SNathan Whitehorn 	};
71991416fb2SNathan Whitehorn 
72091416fb2SNathan Whitehorn 	args.virt = (cell_t)virt;
72191416fb2SNathan Whitehorn 	args.size = size;
72291416fb2SNathan Whitehorn 	openfirmware(&args);
72391416fb2SNathan Whitehorn }
72491416fb2SNathan Whitehorn 
72591416fb2SNathan Whitehorn /*
72691416fb2SNathan Whitehorn  * Control transfer functions
72791416fb2SNathan Whitehorn  */
72891416fb2SNathan Whitehorn 
72991416fb2SNathan Whitehorn /* Suspend and drop back to the Open Firmware interface. */
73091416fb2SNathan Whitehorn static void
ofw_std_enter(ofw_t ofw)73191416fb2SNathan Whitehorn ofw_std_enter(ofw_t ofw)
73291416fb2SNathan Whitehorn {
733d4bccd63SNathan Whitehorn 	struct {
73491416fb2SNathan Whitehorn 		cell_t name;
73591416fb2SNathan Whitehorn 		cell_t nargs;
73691416fb2SNathan Whitehorn 		cell_t nreturns;
73791416fb2SNathan Whitehorn 	} args = {
73891416fb2SNathan Whitehorn 		(cell_t)"enter",
739bd7e69e4SMarius Strobl 		0,
740bd7e69e4SMarius Strobl 		0,
74191416fb2SNathan Whitehorn 	};
74291416fb2SNathan Whitehorn 
74391416fb2SNathan Whitehorn 	openfirmware(&args);
74491416fb2SNathan Whitehorn 	/* We may come back. */
74591416fb2SNathan Whitehorn }
74691416fb2SNathan Whitehorn 
74791416fb2SNathan Whitehorn /* Shut down and drop back to the Open Firmware interface. */
74891416fb2SNathan Whitehorn static void
ofw_std_exit(ofw_t ofw)74991416fb2SNathan Whitehorn ofw_std_exit(ofw_t ofw)
75091416fb2SNathan Whitehorn {
751d4bccd63SNathan Whitehorn 	struct {
75291416fb2SNathan Whitehorn 		cell_t name;
75391416fb2SNathan Whitehorn 		cell_t nargs;
75491416fb2SNathan Whitehorn 		cell_t nreturns;
75591416fb2SNathan Whitehorn 	} args = {
75691416fb2SNathan Whitehorn 		(cell_t)"exit",
757bd7e69e4SMarius Strobl 		0,
758bd7e69e4SMarius Strobl 		0,
75991416fb2SNathan Whitehorn 	};
76091416fb2SNathan Whitehorn 
76191416fb2SNathan Whitehorn 	openfirmware(&args);
76291416fb2SNathan Whitehorn 	for (;;)			/* just in case */
76391416fb2SNathan Whitehorn 		;
76491416fb2SNathan Whitehorn }
765