1186347Snwhitehorn/*-
2186347Snwhitehorn * Copyright (c) 2005 Peter Grehan
3186347Snwhitehorn * Copyright (c) 2008 Nathan Whitehorn
4186347Snwhitehorn * All rights reserved.
5186347Snwhitehorn *
6186347Snwhitehorn * Redistribution and use in source and binary forms, with or without
7186347Snwhitehorn * modification, are permitted provided that the following conditions
8186347Snwhitehorn * are met:
9186347Snwhitehorn * 1. Redistributions of source code must retain the above copyright
10186347Snwhitehorn *    notice, this list of conditions and the following disclaimer.
11186347Snwhitehorn * 2. Redistributions in binary form must reproduce the above copyright
12186347Snwhitehorn *    notice, this list of conditions and the following disclaimer in the
13186347Snwhitehorn *    documentation and/or other materials provided with the distribution.
14186347Snwhitehorn *
15186347Snwhitehorn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16186347Snwhitehorn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17186347Snwhitehorn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18186347Snwhitehorn * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19186347Snwhitehorn * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20186347Snwhitehorn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21186347Snwhitehorn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22186347Snwhitehorn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23186347Snwhitehorn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24186347Snwhitehorn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25186347Snwhitehorn * SUCH DAMAGE.
26186347Snwhitehorn *
27186347Snwhitehorn * $FreeBSD$
28186347Snwhitehorn */
29186347Snwhitehorn
30194138Smarius#ifndef _DEV_OFW_OFWVAR_H_
31194138Smarius#define	_DEV_OFW_OFWVAR_H_
32186347Snwhitehorn
33186347Snwhitehorn/*
34186347Snwhitehorn * An Open Firmware client implementation is declared with a kernel object and
35186347Snwhitehorn * an associated method table, similar to a device driver.
36186347Snwhitehorn *
37186347Snwhitehorn * e.g.
38186347Snwhitehorn *
39186347Snwhitehorn * static ofw_method_t fdt_methods[] = {
40186347Snwhitehorn *	OFWMETHOD(ofw_init,		fdt_init),
41186347Snwhitehorn *	OFWMETHOD(ofw_finddevice,	fdt_finddevice),
42186347Snwhitehorn *  ...
43186347Snwhitehorn *	OFWMETHOD(ofw_nextprop,		fdt_nextprop),
44186347Snwhitehorn *	{ 0, 0 }
45186347Snwhitehorn * };
46186347Snwhitehorn *
47186347Snwhitehorn * static ofw_def_t ofw_fdt = {
48194138Smarius *	"ofw_fdt",
49186347Snwhitehorn *	fdt_methods,
50186347Snwhitehorn *	sizeof(fdt_softc),	// or 0 if no softc
51186347Snwhitehorn * };
52186347Snwhitehorn *
53186347Snwhitehorn * OFW_DEF(ofw_fdt);
54186347Snwhitehorn */
55186347Snwhitehorn
56186347Snwhitehorn#include <sys/kobj.h>
57186347Snwhitehorn
58186347Snwhitehornstruct ofw_kobj {
59186347Snwhitehorn	/*
60186347Snwhitehorn	 * An OFW instance is a kernel object.
61186347Snwhitehorn	 */
62186347Snwhitehorn	KOBJ_FIELDS;
63186347Snwhitehorn
64186347Snwhitehorn	/*
65186347Snwhitehorn	 * Utility elements that an instance may use
66186347Snwhitehorn	 */
67186347Snwhitehorn	struct mtx	ofw_mtx;	/* available for instance use */
68186347Snwhitehorn	void		*ofw_iptr;	/* instance data pointer */
69186347Snwhitehorn
70186347Snwhitehorn	/*
71186347Snwhitehorn	 * Opaque data that can be overlaid with an instance-private
72194138Smarius	 * structure.  OFW code can test that this is large enough at
73194138Smarius	 * compile time with a sizeof() test againt it's softc.  There
74186347Snwhitehorn	 * is also a run-time test when the MMU kernel object is
75186347Snwhitehorn	 * registered.
76186347Snwhitehorn	 */
77194138Smarius#define	OFW_OPAQUESZ	64
78186347Snwhitehorn	u_int		ofw_opaque[OFW_OPAQUESZ];
79186347Snwhitehorn};
80186347Snwhitehorn
81186347Snwhitehorntypedef struct ofw_kobj		*ofw_t;
82186347Snwhitehorntypedef struct kobj_class	ofw_def_t;
83186347Snwhitehorn
84194138Smarius#define	ofw_method_t	kobj_method_t
85194138Smarius#define	OFWMETHOD	KOBJMETHOD
86186347Snwhitehorn
87194138Smarius#define	OFW_DEF(name)	DATA_SET(ofw_set, name)
88186347Snwhitehorn
89194138Smarius#endif /* _DEV_OFW_OFWVAR_H_ */
90