xref: /freebsd/sys/dev/ofw/ofwvar.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
191416fb2SNathan Whitehorn /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
491416fb2SNathan Whitehorn  * Copyright (c) 2005 Peter Grehan
591416fb2SNathan Whitehorn  * Copyright (c) 2008 Nathan Whitehorn
691416fb2SNathan Whitehorn  * All rights reserved.
791416fb2SNathan Whitehorn  *
891416fb2SNathan Whitehorn  * Redistribution and use in source and binary forms, with or without
991416fb2SNathan Whitehorn  * modification, are permitted provided that the following conditions
1091416fb2SNathan Whitehorn  * are met:
1191416fb2SNathan Whitehorn  * 1. Redistributions of source code must retain the above copyright
1291416fb2SNathan Whitehorn  *    notice, this list of conditions and the following disclaimer.
1391416fb2SNathan Whitehorn  * 2. Redistributions in binary form must reproduce the above copyright
1491416fb2SNathan Whitehorn  *    notice, this list of conditions and the following disclaimer in the
1591416fb2SNathan Whitehorn  *    documentation and/or other materials provided with the distribution.
1691416fb2SNathan Whitehorn  *
1791416fb2SNathan Whitehorn  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1891416fb2SNathan Whitehorn  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1991416fb2SNathan Whitehorn  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2091416fb2SNathan Whitehorn  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2191416fb2SNathan Whitehorn  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2291416fb2SNathan Whitehorn  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2391416fb2SNathan Whitehorn  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2491416fb2SNathan Whitehorn  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2591416fb2SNathan Whitehorn  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2691416fb2SNathan Whitehorn  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2791416fb2SNathan Whitehorn  * SUCH DAMAGE.
2891416fb2SNathan Whitehorn  */
2991416fb2SNathan Whitehorn 
30481d6b54SMarius Strobl #ifndef _DEV_OFW_OFWVAR_H_
31481d6b54SMarius Strobl #define	_DEV_OFW_OFWVAR_H_
3291416fb2SNathan Whitehorn 
3391416fb2SNathan Whitehorn /*
3491416fb2SNathan Whitehorn  * An Open Firmware client implementation is declared with a kernel object and
3591416fb2SNathan Whitehorn  * an associated method table, similar to a device driver.
3691416fb2SNathan Whitehorn  *
3791416fb2SNathan Whitehorn  * e.g.
3891416fb2SNathan Whitehorn  *
3991416fb2SNathan Whitehorn  * static ofw_method_t fdt_methods[] = {
4091416fb2SNathan Whitehorn  *	OFWMETHOD(ofw_init,		fdt_init),
4191416fb2SNathan Whitehorn  *	OFWMETHOD(ofw_finddevice,	fdt_finddevice),
4291416fb2SNathan Whitehorn  *  ...
4391416fb2SNathan Whitehorn  *	OFWMETHOD(ofw_nextprop,		fdt_nextprop),
4491416fb2SNathan Whitehorn  *	{ 0, 0 }
4591416fb2SNathan Whitehorn  * };
4691416fb2SNathan Whitehorn  *
4791416fb2SNathan Whitehorn  * static ofw_def_t ofw_fdt = {
4891416fb2SNathan Whitehorn  *	"ofw_fdt",
4991416fb2SNathan Whitehorn  *	fdt_methods,
5091416fb2SNathan Whitehorn  *	sizeof(fdt_softc),	// or 0 if no softc
5191416fb2SNathan Whitehorn  * };
5291416fb2SNathan Whitehorn  *
5391416fb2SNathan Whitehorn  * OFW_DEF(ofw_fdt);
5491416fb2SNathan Whitehorn  */
5591416fb2SNathan Whitehorn 
5691416fb2SNathan Whitehorn #include <sys/kobj.h>
5791416fb2SNathan Whitehorn 
5891416fb2SNathan Whitehorn struct ofw_kobj {
5991416fb2SNathan Whitehorn 	/*
6091416fb2SNathan Whitehorn 	 * An OFW instance is a kernel object.
6191416fb2SNathan Whitehorn 	 */
6291416fb2SNathan Whitehorn 	KOBJ_FIELDS;
6391416fb2SNathan Whitehorn 
6491416fb2SNathan Whitehorn 	/*
6591416fb2SNathan Whitehorn 	 * Utility elements that an instance may use
6691416fb2SNathan Whitehorn 	 */
6791416fb2SNathan Whitehorn 	struct mtx	ofw_mtx;	/* available for instance use */
6891416fb2SNathan Whitehorn 	void		*ofw_iptr;	/* instance data pointer */
6991416fb2SNathan Whitehorn 
7091416fb2SNathan Whitehorn 	/*
7191416fb2SNathan Whitehorn 	 * Opaque data that can be overlaid with an instance-private
7291416fb2SNathan Whitehorn 	 * structure.  OFW code can test that this is large enough at
7391416fb2SNathan Whitehorn 	 * compile time with a sizeof() test againt it's softc.  There
7491416fb2SNathan Whitehorn 	 * is also a run-time test when the MMU kernel object is
7591416fb2SNathan Whitehorn 	 * registered.
7691416fb2SNathan Whitehorn 	 */
7791416fb2SNathan Whitehorn #define	OFW_OPAQUESZ	64
7891416fb2SNathan Whitehorn 	u_int		ofw_opaque[OFW_OPAQUESZ];
7991416fb2SNathan Whitehorn };
8091416fb2SNathan Whitehorn 
8191416fb2SNathan Whitehorn typedef struct ofw_kobj		*ofw_t;
8291416fb2SNathan Whitehorn typedef struct kobj_class	ofw_def_t;
8391416fb2SNathan Whitehorn 
8491416fb2SNathan Whitehorn #define	ofw_method_t	kobj_method_t
8591416fb2SNathan Whitehorn #define	OFWMETHOD	KOBJMETHOD
8691416fb2SNathan Whitehorn 
8791416fb2SNathan Whitehorn #define	OFW_DEF(name)	DATA_SET(ofw_set, name)
8891416fb2SNathan Whitehorn 
89481d6b54SMarius Strobl #endif /* _DEV_OFW_OFWVAR_H_ */
90