1d84d862obrien/*	$NetBSD: openfirm.h,v 1.1 1998/05/15 10:16:00 tsubai Exp $	*/
2d84d862obrien
34b31995imp/*-
4de3a5fcpfg * SPDX-License-Identifier: (BSD-4-Clause AND BSD-2-Clause-FreeBSD)
51537078pfg *
6d84d862obrien * Copyright (C) 1995, 1996 Wolfgang Solfrank.
7d84d862obrien * Copyright (C) 1995, 1996 TooLs GmbH.
8d84d862obrien * All rights reserved.
9d84d862obrien *
10d84d862obrien * Redistribution and use in source and binary forms, with or without
11d84d862obrien * modification, are permitted provided that the following conditions
12d84d862obrien * are met:
13d84d862obrien * 1. Redistributions of source code must retain the above copyright
14d84d862obrien *    notice, this list of conditions and the following disclaimer.
15d84d862obrien * 2. Redistributions in binary form must reproduce the above copyright
16d84d862obrien *    notice, this list of conditions and the following disclaimer in the
17d84d862obrien *    documentation and/or other materials provided with the distribution.
18d84d862obrien * 3. All advertising materials mentioning features or use of this software
19d84d862obrien *    must display the following acknowledgement:
20d84d862obrien *	This product includes software developed by TooLs GmbH.
21d84d862obrien * 4. The name of TooLs GmbH may not be used to endorse or promote products
22d84d862obrien *    derived from this software without specific prior written permission.
23d84d862obrien *
24d84d862obrien * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
25d84d862obrien * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26d84d862obrien * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27d84d862obrien * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28d84d862obrien * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29d84d862obrien * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30d84d862obrien * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31d84d862obrien * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32d84d862obrien * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33d84d862obrien * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34d84d862obrien */
35d84d862obrien/*
36d84d862obrien * Copyright (C) 2000 Benno Rice.
37d84d862obrien * All rights reserved.
38d84d862obrien *
39d84d862obrien * Redistribution and use in source and binary forms, with or without
40d84d862obrien * modification, are permitted provided that the following conditions
41d84d862obrien * are met:
42d84d862obrien * 1. Redistributions of source code must retain the above copyright
43d84d862obrien *    notice, this list of conditions and the following disclaimer.
44d84d862obrien * 2. Redistributions in binary form must reproduce the above copyright
45d84d862obrien *    notice, this list of conditions and the following disclaimer in the
46d84d862obrien *    documentation and/or other materials provided with the distribution.
47d84d862obrien *
48d84d862obrien * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
49d84d862obrien * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
50d84d862obrien * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
51d84d862obrien * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52d84d862obrien * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
53d84d862obrien * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
54d84d862obrien * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
55d84d862obrien * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
56d84d862obrien * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
57d84d862obrien * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58d84d862obrien *
59d84d862obrien * $FreeBSD$
60d84d862obrien */
61d84d862obrien
623961775marius#ifndef _DEV_OPENFIRM_H_
633961775marius#define _DEV_OPENFIRM_H_
64c92b4bbbenno
653fcef6dnwhitehorn#include <sys/types.h>
6680bb89bian#include <machine/_bus.h>
673fcef6dnwhitehorn
68d84d862obrien/*
6924ad8a9marius * Prototypes for Open Firmware Interface Routines
70d84d862obrien */
71d84d862obrien
723961775mariustypedef uint32_t	ihandle_t;
733fcef6dnwhitehorntypedef uint32_t	phandle_t;
743fcef6dnwhitehorntypedef uint32_t	pcell_t;
75c68dcf7tmm
76c68dcf7tmm#ifdef _KERNEL
77f90b466tmm#include <sys/malloc.h>
78f90b466tmm
793fcef6dnwhitehorn#include <machine/ofw_machdep.h>
803fcef6dnwhitehorn
81f90b466tmmMALLOC_DECLARE(M_OFWPROP);
82d84d862obrien
83d84d862obrien/*
843961775marius * Open Firmware interface initialization.  OF_install installs the named
853fcef6dnwhitehorn * interface as the Open Firmware access mechanism, OF_init initializes it.
86ad445e7nwhitehorn */
87ad445e7nwhitehorn
883fcef6dnwhitehornboolean_t	OF_install(char *name, int prio);
89ef99eb1rajint		OF_init(void *cookie);
9010abd05benno
9110abd05benno/*
923fcef6dnwhitehorn * Known Open Firmware interface names
93d84d862obrien */
943fcef6dnwhitehorn
953fcef6dnwhitehorn#define	OFW_STD_DIRECT	"ofw_std"	/* Standard OF interface */
963fcef6dnwhitehorn#define	OFW_STD_REAL	"ofw_real"	/* Real-mode OF interface */
978f78316nwhitehorn#define	OFW_STD_32BIT	"ofw_32bit"	/* 32-bit OF interface */
983fcef6dnwhitehorn#define	OFW_FDT		"ofw_fdt"	/* Flattened Device Tree */
99d84d862obrien
100d84d862obrien/* Generic functions */
1013961775mariusint		OF_test(const char *name);
1023961775mariusvoid		OF_printf(const char *fmt, ...);
103d84d862obrien
104d84d862obrien/* Device tree functions */
1053fcef6dnwhitehornphandle_t	OF_peer(phandle_t node);
1063fcef6dnwhitehornphandle_t	OF_child(phandle_t node);
1073fcef6dnwhitehornphandle_t	OF_parent(phandle_t node);
1083fcef6dnwhitehornssize_t		OF_getproplen(phandle_t node, const char *propname);
1093fcef6dnwhitehornssize_t		OF_getprop(phandle_t node, const char *propname, void *buf,
1103fcef6dnwhitehorn		    size_t len);
111f79afefnwhitehornssize_t		OF_getencprop(phandle_t node, const char *prop, pcell_t *buf,
112f79afefnwhitehorn		    size_t len); /* Same as getprop, but maintains endianness */
1135320d21hrsint		OF_hasprop(phandle_t node, const char *propname);
1143961775mariusssize_t		OF_searchprop(phandle_t node, const char *propname, void *buf,
1154ca1211nwhitehorn		    size_t len);
11615e1002nwhitehornssize_t		OF_searchencprop(phandle_t node, const char *propname,
117eb86958gonzo		    pcell_t *buf, size_t len);
1183fcef6dnwhitehornssize_t		OF_getprop_alloc(phandle_t node, const char *propname,
1191252c93gonzo		    void **buf);
1201252c93gonzossize_t		OF_getprop_alloc_multi(phandle_t node, const char *propname,
1213fcef6dnwhitehorn		    int elsz, void **buf);
12215e1002nwhitehornssize_t		OF_getencprop_alloc(phandle_t node, const char *propname,
1233308d36gonzo		    void **buf);
1243308d36gonzossize_t		OF_getencprop_alloc_multi(phandle_t node, const char *propname,
12515e1002nwhitehorn		    int elsz, void **buf);
12623a2d5fgonzovoid		OF_prop_free(void *buf);
1273fcef6dnwhitehornint		OF_nextprop(phandle_t node, const char *propname, char *buf,
1283fcef6dnwhitehorn		    size_t len);
1293fcef6dnwhitehornint		OF_setprop(phandle_t node, const char *name, const void *buf,
1303fcef6dnwhitehorn		    size_t len);
1313fcef6dnwhitehornssize_t		OF_canon(const char *path, char *buf, size_t len);
1323fcef6dnwhitehornphandle_t	OF_finddevice(const char *path);
1333fcef6dnwhitehornssize_t		OF_package_to_path(phandle_t node, char *buf, size_t len);
134d84d862obrien
1353b7e4aanwhitehorn/*
1363b7e4aanwhitehorn * Some OF implementations (IBM, FDT) have a concept of effective phandles
1373b7e4aanwhitehorn * used for device-tree cross-references. Given one of these, returns the
1383b7e4aanwhitehorn * real phandle. If one can't be found (or running on OF implementations
139c8e7d83ian * without this property), returns its input.
1403b7e4aanwhitehorn */
141b149a9eianphandle_t	OF_node_from_xref(phandle_t xref);
142b149a9eianphandle_t	OF_xref_from_node(phandle_t node);
1433b7e4aanwhitehorn
144c1f3eb1ian/*
145c1f3eb1ian * When properties contain references to other nodes using xref handles it is
146c1f3eb1ian * often necessary to use interfaces provided by the driver for the referenced
147c1f3eb1ian * instance.  These routines allow a driver that provides such an interface to
148c1f3eb1ian * register its association with an xref handle, and for other drivers to obtain
149c1f3eb1ian * the device_t associated with an xref handle.
150c1f3eb1ian */
151c1f3eb1iandevice_t	OF_device_from_xref(phandle_t xref);
15229ba19bianphandle_t	OF_xref_from_device(device_t dev);
153c1f3eb1ianint		OF_device_register_xref(phandle_t xref, device_t dev);
154c1f3eb1ian
155d84d862obrien/* Device I/O functions */
1563fcef6dnwhitehornihandle_t	OF_open(const char *path);
1573fcef6dnwhitehornvoid		OF_close(ihandle_t instance);
1583fcef6dnwhitehornssize_t		OF_read(ihandle_t instance, void *buf, size_t len);
1593fcef6dnwhitehornssize_t		OF_write(ihandle_t instance, const void *buf, size_t len);
1603fcef6dnwhitehornint		OF_seek(ihandle_t instance, uint64_t where);
1613fcef6dnwhitehorn
1623fcef6dnwhitehornphandle_t	OF_instance_to_package(ihandle_t instance);
1633fcef6dnwhitehornssize_t		OF_instance_to_path(ihandle_t instance, char *buf, size_t len);
1643fcef6dnwhitehornint		OF_call_method(const char *method, ihandle_t instance,
1653fcef6dnwhitehorn		    int nargs, int nreturns, ...);
166d84d862obrien
167d84d862obrien/* Memory functions */
1683961775mariusvoid		*OF_claim(void *virtrequest, size_t size, u_int align);
1693fcef6dnwhitehornvoid		OF_release(void *virt, size_t size);
170d84d862obrien
171d84d862obrien/* Control transfer functions */
172d84d862obrienvoid		OF_enter(void);
1737d73a33bennovoid		OF_exit(void) __attribute__((noreturn));
174d84d862obrien
175d84d862obrien/* User interface functions */
1763fcef6dnwhitehornint		OF_interpret(const char *cmd, int nreturns, ...);
177c92b4bbbenno
178f2c27d0ian/*
179f2c27d0ian * Decode the Nth register property of the given device node and create a bus
180f2c27d0ian * space tag and handle for accessing it.  This is for use in setting up things
18148b9486imp * like early console output before newbus is available.
182f2c27d0ian */
183f2c27d0ianint		OF_decode_addr(phandle_t dev, int regno, bus_space_tag_t *ptag,
18405274f8andrew		    bus_space_handle_t *phandle, bus_size_t *sz);
185f2c27d0ian
186c68dcf7tmm#endif /* _KERNEL */
1873961775marius#endif /* _DEV_OPENFIRM_H_ */
188