167204Sobrien/*	$NetBSD: openfirm.h,v 1.1 1998/05/15 10:16:00 tsubai Exp $	*/
267204Sobrien
3139749Simp/*-
467204Sobrien * Copyright (C) 1995, 1996 Wolfgang Solfrank.
567204Sobrien * Copyright (C) 1995, 1996 TooLs GmbH.
667204Sobrien * All rights reserved.
767204Sobrien *
867204Sobrien * Redistribution and use in source and binary forms, with or without
967204Sobrien * modification, are permitted provided that the following conditions
1067204Sobrien * are met:
1167204Sobrien * 1. Redistributions of source code must retain the above copyright
1267204Sobrien *    notice, this list of conditions and the following disclaimer.
1367204Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1467204Sobrien *    notice, this list of conditions and the following disclaimer in the
1567204Sobrien *    documentation and/or other materials provided with the distribution.
1667204Sobrien * 3. All advertising materials mentioning features or use of this software
1767204Sobrien *    must display the following acknowledgement:
1867204Sobrien *	This product includes software developed by TooLs GmbH.
1967204Sobrien * 4. The name of TooLs GmbH may not be used to endorse or promote products
2067204Sobrien *    derived from this software without specific prior written permission.
2167204Sobrien *
2267204Sobrien * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
2367204Sobrien * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2467204Sobrien * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2567204Sobrien * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2667204Sobrien * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2767204Sobrien * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
2867204Sobrien * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2967204Sobrien * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
3067204Sobrien * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
3167204Sobrien * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3267204Sobrien */
3367204Sobrien/*
3467204Sobrien * Copyright (C) 2000 Benno Rice.
3567204Sobrien * All rights reserved.
3667204Sobrien *
3767204Sobrien * Redistribution and use in source and binary forms, with or without
3867204Sobrien * modification, are permitted provided that the following conditions
3967204Sobrien * are met:
4067204Sobrien * 1. Redistributions of source code must retain the above copyright
4167204Sobrien *    notice, this list of conditions and the following disclaimer.
4267204Sobrien * 2. Redistributions in binary form must reproduce the above copyright
4367204Sobrien *    notice, this list of conditions and the following disclaimer in the
4467204Sobrien *    documentation and/or other materials provided with the distribution.
4567204Sobrien *
4667204Sobrien * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
4767204Sobrien * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
4867204Sobrien * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
4967204Sobrien * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
5067204Sobrien * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
5167204Sobrien * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
5267204Sobrien * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
5367204Sobrien * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
5467204Sobrien * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
5567204Sobrien * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5667204Sobrien *
5767204Sobrien * $FreeBSD$
5867204Sobrien */
5967204Sobrien
60194138Smarius#ifndef _DEV_OPENFIRM_H_
61194138Smarius#define _DEV_OPENFIRM_H_
6278877Sbenno
63186347Snwhitehorn#include <sys/types.h>
64186347Snwhitehorn
6567204Sobrien/*
66133862Smarius * Prototypes for Open Firmware Interface Routines
6767204Sobrien */
6867204Sobrien
69194138Smariustypedef uint32_t	ihandle_t;
70186347Snwhitehorntypedef uint32_t	phandle_t;
71186347Snwhitehorntypedef uint32_t	pcell_t;
72105397Stmm
73105397Stmm#ifdef _KERNEL
7486557Stmm#include <sys/malloc.h>
7567204Sobrien
76186347Snwhitehorn#include <machine/ofw_machdep.h>
77186347Snwhitehorn
7886557StmmMALLOC_DECLARE(M_OFWPROP);
7986557Stmm
8067204Sobrien/*
81194138Smarius * Open Firmware interface initialization.  OF_install installs the named
82186347Snwhitehorn * interface as the Open Firmware access mechanism, OF_init initializes it.
83186133Snwhitehorn */
84186133Snwhitehorn
85186347Snwhitehornboolean_t	OF_install(char *name, int prio);
86208614Srajint		OF_init(void *cookie);
8778346Sbenno
8878346Sbenno/*
89186347Snwhitehorn * Known Open Firmware interface names
9067204Sobrien */
9167204Sobrien
92186347Snwhitehorn#define	OFW_STD_DIRECT	"ofw_std"	/* Standard OF interface */
93186347Snwhitehorn#define	OFW_STD_REAL	"ofw_real"	/* Real-mode OF interface */
94209817Snwhitehorn#define	OFW_STD_32BIT	"ofw_32bit"	/* 32-bit OF interface */
95186347Snwhitehorn#define	OFW_FDT		"ofw_fdt"	/* Flattened Device Tree */
96186347Snwhitehorn
9767204Sobrien/* Generic functions */
98194138Smariusint		OF_test(const char *name);
99194138Smariusvoid		OF_printf(const char *fmt, ...);
10067204Sobrien
10167204Sobrien/* Device tree functions */
102186347Snwhitehornphandle_t	OF_peer(phandle_t node);
103186347Snwhitehornphandle_t	OF_child(phandle_t node);
104186347Snwhitehornphandle_t	OF_parent(phandle_t node);
105186347Snwhitehornssize_t		OF_getproplen(phandle_t node, const char *propname);
106186347Snwhitehornssize_t		OF_getprop(phandle_t node, const char *propname, void *buf,
107186347Snwhitehorn		    size_t len);
108239366Shrsint		OF_hasprop(phandle_t node, const char *propname);
109194138Smariusssize_t		OF_searchprop(phandle_t node, const char *propname, void *buf,
110186728Snwhitehorn		    size_t len);
111186347Snwhitehornssize_t		OF_getprop_alloc(phandle_t node, const char *propname,
112186347Snwhitehorn		    int elsz, void **buf);
113186347Snwhitehornint		OF_nextprop(phandle_t node, const char *propname, char *buf,
114186347Snwhitehorn		    size_t len);
115186347Snwhitehornint		OF_setprop(phandle_t node, const char *name, const void *buf,
116186347Snwhitehorn		    size_t len);
117186347Snwhitehornssize_t		OF_canon(const char *path, char *buf, size_t len);
118186347Snwhitehornphandle_t	OF_finddevice(const char *path);
119186347Snwhitehornssize_t		OF_package_to_path(phandle_t node, char *buf, size_t len);
12067204Sobrien
121255596Snwhitehorn/*
122255596Snwhitehorn * Some OF implementations (IBM, FDT) have a concept of effective phandles
123255596Snwhitehorn * used for device-tree cross-references. Given one of these, returns the
124255596Snwhitehorn * real phandle. If one can't be found (or running on OF implementations
125255596Snwhitehorn * without this property), returns its input.
126255596Snwhitehorn */
127255596Snwhitehornphandle_t	OF_xref_phandle(phandle_t xref);
128255596Snwhitehorn
12967204Sobrien/* Device I/O functions */
130186347Snwhitehornihandle_t	OF_open(const char *path);
131186347Snwhitehornvoid		OF_close(ihandle_t instance);
132186347Snwhitehornssize_t		OF_read(ihandle_t instance, void *buf, size_t len);
133186347Snwhitehornssize_t		OF_write(ihandle_t instance, const void *buf, size_t len);
134186347Snwhitehornint		OF_seek(ihandle_t instance, uint64_t where);
13567204Sobrien
136186347Snwhitehornphandle_t	OF_instance_to_package(ihandle_t instance);
137186347Snwhitehornssize_t		OF_instance_to_path(ihandle_t instance, char *buf, size_t len);
138186347Snwhitehornint		OF_call_method(const char *method, ihandle_t instance,
139186347Snwhitehorn		    int nargs, int nreturns, ...);
140186347Snwhitehorn
14167204Sobrien/* Memory functions */
142194138Smariusvoid		*OF_claim(void *virtrequest, size_t size, u_int align);
143186347Snwhitehornvoid		OF_release(void *virt, size_t size);
14467204Sobrien
14567204Sobrien/* Control transfer functions */
14667204Sobrienvoid		OF_enter(void);
14768548Sbennovoid		OF_exit(void) __attribute__((noreturn));
14867204Sobrien
149115973Sjake/* User interface functions */
150186347Snwhitehornint		OF_interpret(const char *cmd, int nreturns, ...);
15167204Sobrien
152105397Stmm#endif /* _KERNEL */
153194138Smarius#endif /* _DEV_OPENFIRM_H_ */
154