1186347Snwhitehorn#-
2186347Snwhitehorn# Copyright (c) 2008 Nathan Whitehorn
3186347Snwhitehorn# All rights reserved.
4186347Snwhitehorn#
5186347Snwhitehorn# Redistribution and use in source and binary forms, with or without
6186347Snwhitehorn# modification, are permitted provided that the following conditions
7186347Snwhitehorn# are met:
8186347Snwhitehorn# 1. Redistributions of source code must retain the above copyright
9186347Snwhitehorn#    notice, this list of conditions and the following disclaimer.
10186347Snwhitehorn# 2. Redistributions in binary form must reproduce the above copyright
11186347Snwhitehorn#    notice, this list of conditions and the following disclaimer in the
12186347Snwhitehorn#    documentation and/or other materials provided with the distribution.
13186347Snwhitehorn#
14186347Snwhitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15186347Snwhitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16186347Snwhitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17186347Snwhitehorn# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18186347Snwhitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19186347Snwhitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20186347Snwhitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21186347Snwhitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22186347Snwhitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23186347Snwhitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24186347Snwhitehorn# SUCH DAMAGE.
25186347Snwhitehorn#
26186347Snwhitehorn# $FreeBSD$
27186347Snwhitehorn#
28186347Snwhitehorn
29186347Snwhitehorn#include <dev/ofw/openfirm.h>
30186347Snwhitehorn#include <dev/ofw/ofwvar.h>
31186347Snwhitehorn
32186347Snwhitehorn/**
33186347Snwhitehorn * @defgroup OFW ofw - KObj methods for Open Firmware RTAS implementations
34186347Snwhitehorn * @brief A set of methods to implement the Open Firmware client side interface.
35194138Smarius * @{
36186347Snwhitehorn */
37186347Snwhitehorn
38186347SnwhitehornINTERFACE ofw;
39186347Snwhitehorn
40186347Snwhitehorn/**
41186347Snwhitehorn * @brief Initialize OFW client interface
42186347Snwhitehorn *
43186347Snwhitehorn * @param _cookie	A handle to the client interface, generally the OF
44186347Snwhitehorn *			callback routine.
45186347Snwhitehorn */
46208614SrajMETHOD int init {
47186347Snwhitehorn	ofw_t		_ofw;
48186347Snwhitehorn	void		*_cookie;
49186347Snwhitehorn};
50186347Snwhitehorn
51186347Snwhitehorn/**
52194138Smarius * @brief Return next sibling of node.
53186347Snwhitehorn *
54186347Snwhitehorn * @param _node		Selected node
55186347Snwhitehorn */
56186347SnwhitehornMETHOD phandle_t peer {
57186347Snwhitehorn	ofw_t		_ofw;
58194138Smarius	phandle_t	_node;
59186347Snwhitehorn};
60186347Snwhitehorn
61186347Snwhitehorn/**
62194138Smarius * @brief Return parent of node.
63186347Snwhitehorn *
64186347Snwhitehorn * @param _node		Selected node
65186347Snwhitehorn */
66186347SnwhitehornMETHOD phandle_t parent {
67186347Snwhitehorn	ofw_t		_ofw;
68194138Smarius	phandle_t	_node;
69186347Snwhitehorn};
70186347Snwhitehorn
71186347Snwhitehorn/**
72194138Smarius * @brief Return first child of node.
73186347Snwhitehorn *
74186347Snwhitehorn * @param _node		Selected node
75186347Snwhitehorn */
76186347SnwhitehornMETHOD phandle_t child {
77186347Snwhitehorn	ofw_t		_ofw;
78194138Smarius	phandle_t	_node;
79186347Snwhitehorn};
80186347Snwhitehorn
81186347Snwhitehorn/**
82194138Smarius * @brief Return package corresponding to instance.
83186347Snwhitehorn *
84186347Snwhitehorn * @param _handle	Selected instance
85186347Snwhitehorn */
86186347SnwhitehornMETHOD phandle_t instance_to_package {
87186347Snwhitehorn	ofw_t		_ofw;
88194138Smarius	ihandle_t	_handle;
89186347Snwhitehorn};
90186347Snwhitehorn
91186347Snwhitehorn/**
92194138Smarius * @brief Return length of node property.
93186347Snwhitehorn *
94186347Snwhitehorn * @param _node		Selected node
95186347Snwhitehorn * @param _prop		Property name
96186347Snwhitehorn */
97186347SnwhitehornMETHOD ssize_t getproplen {
98186347Snwhitehorn	ofw_t		_ofw;
99194138Smarius	phandle_t	_node;
100194138Smarius	const char	*_prop;
101186347Snwhitehorn};
102186347Snwhitehorn
103186347Snwhitehorn/**
104194138Smarius * @brief Read node property.
105186347Snwhitehorn *
106186347Snwhitehorn * @param _node		Selected node
107186347Snwhitehorn * @param _prop		Property name
108186347Snwhitehorn * @param _buf		Pointer to buffer
109186347Snwhitehorn * @param _size		Size of buffer
110186347Snwhitehorn */
111186347SnwhitehornMETHOD ssize_t getprop {
112186347Snwhitehorn	ofw_t		_ofw;
113194138Smarius	phandle_t	_node;
114186347Snwhitehorn	const char	*_prop;
115186347Snwhitehorn	void		*_buf;
116186347Snwhitehorn	size_t		_size;
117186347Snwhitehorn};
118186347Snwhitehorn
119186347Snwhitehorn/**
120194138Smarius * @brief Get next property name.
121186347Snwhitehorn *
122186347Snwhitehorn * @param _node		Selected node
123186347Snwhitehorn * @param _prop		Current property name
124186347Snwhitehorn * @param _buf		Buffer for next property name
125186347Snwhitehorn * @param _size		Size of buffer
126186347Snwhitehorn */
127186347SnwhitehornMETHOD int nextprop {
128186347Snwhitehorn	ofw_t		_ofw;
129194138Smarius	phandle_t	_node;
130186347Snwhitehorn	const char	*_prop;
131194138Smarius	char		*_buf;
132186347Snwhitehorn	size_t		_size;
133186347Snwhitehorn};
134186347Snwhitehorn
135186347Snwhitehorn/**
136194138Smarius * @brief Set property.
137186347Snwhitehorn *
138186347Snwhitehorn * @param _node		Selected node
139186347Snwhitehorn * @param _prop		Property name
140186347Snwhitehorn * @param _buf		Value to set
141186347Snwhitehorn * @param _size		Size of buffer
142186347Snwhitehorn */
143186347SnwhitehornMETHOD int setprop {
144186347Snwhitehorn	ofw_t		_ofw;
145194138Smarius	phandle_t	_node;
146194138Smarius	const char	*_prop;
147186347Snwhitehorn	const void	*_buf;
148186347Snwhitehorn	size_t		_size;
149186347Snwhitehorn};
150186347Snwhitehorn
151186347Snwhitehorn/**
152194138Smarius * @brief Canonicalize path.
153186347Snwhitehorn *
154186347Snwhitehorn * @param _path		Path to canonicalize
155186347Snwhitehorn * @param _buf		Buffer for canonicalized path
156186347Snwhitehorn * @param _size		Size of buffer
157186347Snwhitehorn */
158186347SnwhitehornMETHOD ssize_t canon {
159186347Snwhitehorn	ofw_t		_ofw;
160186347Snwhitehorn	const char	*_path;
161186347Snwhitehorn	char		*_buf;
162186347Snwhitehorn	size_t		_size;
163186347Snwhitehorn};
164186347Snwhitehorn
165186347Snwhitehorn/**
166194138Smarius * @brief Return phandle for named device.
167186347Snwhitehorn *
168186347Snwhitehorn * @param _path		Device path
169186347Snwhitehorn */
170186347SnwhitehornMETHOD phandle_t finddevice {
171186347Snwhitehorn	ofw_t		_ofw;
172194138Smarius	const char	*_path;
173186347Snwhitehorn};
174186347Snwhitehorn
175186347Snwhitehorn/**
176194138Smarius * @brief Return path for node instance.
177186347Snwhitehorn *
178186347Snwhitehorn * @param _handle	Instance handle
179186347Snwhitehorn * @param _path		Buffer for path
180186347Snwhitehorn * @param _size		Size of buffer
181186347Snwhitehorn */
182186347SnwhitehornMETHOD ssize_t instance_to_path {
183186347Snwhitehorn	ofw_t		_ofw;
184186347Snwhitehorn	ihandle_t	_handle;
185194138Smarius	char		*_path;
186186347Snwhitehorn	size_t		_size;
187186347Snwhitehorn};
188186347Snwhitehorn
189186347Snwhitehorn/**
190194138Smarius * @brief Return path for node.
191186347Snwhitehorn *
192186347Snwhitehorn * @param _node		Package node
193186347Snwhitehorn * @param _path		Buffer for path
194186347Snwhitehorn * @param _size		Size of buffer
195186347Snwhitehorn */
196186347SnwhitehornMETHOD ssize_t package_to_path {
197186347Snwhitehorn	ofw_t		_ofw;
198186347Snwhitehorn	phandle_t	_node;
199194138Smarius	char		*_path;
200186347Snwhitehorn	size_t		_size;
201186347Snwhitehorn};
202186347Snwhitehorn
203186347Snwhitehorn# Methods for OF method calls (optional)
204186347Snwhitehorn
205186347Snwhitehorn/**
206186347Snwhitehorn * @brief Test to see if a service exists.
207186347Snwhitehorn *
208186347Snwhitehorn * @param _name		name of the service
209186347Snwhitehorn */
210186347SnwhitehornMETHOD int test {
211186347Snwhitehorn	ofw_t		_ofw;
212186347Snwhitehorn	const char	*_name;
213186347Snwhitehorn};
214186347Snwhitehorn
215186347Snwhitehorn/**
216194138Smarius * @brief Call method belonging to an instance handle.
217186347Snwhitehorn *
218186347Snwhitehorn * @param _instance	Instance handle
219186347Snwhitehorn * @param _method	Method name
220186347Snwhitehorn * @param _nargs	Number of arguments
221186347Snwhitehorn * @param _nreturns	Number of return values
222186347Snwhitehorn * @param _args_and_returns	Values for arguments, followed by returns
223186347Snwhitehorn */
224186347Snwhitehorn
225186347SnwhitehornMETHOD int call_method {
226186347Snwhitehorn	ofw_t		_ofw;
227186347Snwhitehorn	ihandle_t	_instance;
228186347Snwhitehorn	const char	*_method;
229186347Snwhitehorn	int		_nargs;
230194138Smarius	int		_nreturns;
231186347Snwhitehorn
232209801Snwhitehorn	cell_t		*_args_and_returns;
233186347Snwhitehorn};
234186347Snwhitehorn
235186347Snwhitehorn/**
236194138Smarius * @brief Interpret a forth command.
237186347Snwhitehorn *
238186347Snwhitehorn * @param _cmd		Command
239186347Snwhitehorn * @param _nreturns	Number of return values
240186347Snwhitehorn * @param _returns	Values for returns
241186347Snwhitehorn */
242186347Snwhitehorn
243186347SnwhitehornMETHOD int interpret {
244186347Snwhitehorn	ofw_t		_ofw;
245186347Snwhitehorn	const char	*_cmd;
246194138Smarius	int		_nreturns;
247212477Smarius	cell_t		*_returns;
248186347Snwhitehorn};
249186347Snwhitehorn
250186347Snwhitehorn# Device I/O Functions (optional)
251186347Snwhitehorn
252186347Snwhitehorn/**
253194138Smarius * @brief Open node, returning instance handle.
254186347Snwhitehorn *
255186347Snwhitehorn * @param _path		Path to node
256186347Snwhitehorn */
257186347SnwhitehornMETHOD ihandle_t open {
258186347Snwhitehorn	ofw_t		_ofw;
259186347Snwhitehorn	const char	*_path;
260186347Snwhitehorn}
261186347Snwhitehorn
262186347Snwhitehorn/**
263194138Smarius * @brief Close node instance.
264186347Snwhitehorn *
265186347Snwhitehorn * @param _instance	Instance to close
266186347Snwhitehorn */
267186347SnwhitehornMETHOD void close {
268186347Snwhitehorn	ofw_t		_ofw;
269186347Snwhitehorn	ihandle_t	_instance;
270186347Snwhitehorn}
271186347Snwhitehorn
272186347Snwhitehorn/**
273194138Smarius * @brief Read from device.
274186347Snwhitehorn *
275186347Snwhitehorn * @param _instance	Device instance
276186347Snwhitehorn * @param _buf		Buffer to read to
277186347Snwhitehorn * @param _size		Size of buffer
278186347Snwhitehorn */
279186347SnwhitehornMETHOD ssize_t read {
280186347Snwhitehorn	ofw_t		_ofw;
281186347Snwhitehorn	ihandle_t	_instance;
282186347Snwhitehorn	void		*_buf;
283186347Snwhitehorn	size_t		size;
284186347Snwhitehorn}
285186347Snwhitehorn
286186347Snwhitehorn/**
287194138Smarius * @brief Write to device.
288186347Snwhitehorn *
289186347Snwhitehorn * @param _instance	Device instance
290186347Snwhitehorn * @param _buf		Buffer to write from
291186347Snwhitehorn * @param _size		Size of buffer
292186347Snwhitehorn */
293186347SnwhitehornMETHOD ssize_t write {
294186347Snwhitehorn	ofw_t		_ofw;
295186347Snwhitehorn	ihandle_t	_instance;
296186347Snwhitehorn	const void	*_buf;
297186347Snwhitehorn	size_t		size;
298186347Snwhitehorn}
299186347Snwhitehorn
300186347Snwhitehorn/**
301194138Smarius * @brief Seek device.
302186347Snwhitehorn *
303186347Snwhitehorn * @param _instance	Device instance
304186347Snwhitehorn * @param _off		Offset to which to seek
305186347Snwhitehorn */
306186347SnwhitehornMETHOD int seek {
307186347Snwhitehorn	ofw_t		_ofw;
308186347Snwhitehorn	ihandle_t	_instance;
309186347Snwhitehorn	uint64_t	_off;
310186347Snwhitehorn}
311186347Snwhitehorn
312186347Snwhitehorn# Open Firmware memory management
313186347Snwhitehorn
314186347Snwhitehorn/**
315194138Smarius * @brief Claim virtual memory.
316186347Snwhitehorn *
317186347Snwhitehorn * @param _addr		Requested memory location (NULL for first available)
318186347Snwhitehorn * @param _size		Requested size in bytes
319186347Snwhitehorn * @param _align	Requested alignment
320186347Snwhitehorn */
321186347SnwhitehornMETHOD caddr_t claim {
322186347Snwhitehorn	ofw_t		_ofw;
323186347Snwhitehorn	void		*_addr;
324186347Snwhitehorn	size_t		_size;
325186347Snwhitehorn	u_int		_align;
326186347Snwhitehorn}
327186347Snwhitehorn
328186347Snwhitehorn/**
329194138Smarius * @brief Release virtual memory.
330186347Snwhitehorn *
331186347Snwhitehorn * @param _addr		Memory location
332186347Snwhitehorn * @param _size		Size in bytes
333186347Snwhitehorn */
334186347SnwhitehornMETHOD void release {
335186347Snwhitehorn	ofw_t		_ofw;
336186347Snwhitehorn	void		*_addr;
337186347Snwhitehorn	size_t		_size;
338186347Snwhitehorn};
339186347Snwhitehorn
340186347Snwhitehorn# Commands for returning control to the firmware
341186347Snwhitehorn
342186347Snwhitehorn/**
343194138Smarius * @brief Temporarily return control to firmware.
344186347Snwhitehorn */
345186347SnwhitehornMETHOD void enter {
346186347Snwhitehorn	ofw_t		_ofw;
347186347Snwhitehorn};
348186347Snwhitehorn
349186347Snwhitehorn/**
350194138Smarius * @brief Halt and return control to firmware.
351186347Snwhitehorn */
352186347SnwhitehornMETHOD void exit {
353186347Snwhitehorn	ofw_t		_ofw;
354186347Snwhitehorn};
355