xref: /freebsd/sys/dev/ofw/ofwvar.h (revision 580744621f33383027108364dcadad718df46ffe)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2005 Peter Grehan
5  * Copyright (c) 2008 Nathan Whitehorn
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  */
31 
32 #ifndef _DEV_OFW_OFWVAR_H_
33 #define	_DEV_OFW_OFWVAR_H_
34 
35 /*
36  * An Open Firmware client implementation is declared with a kernel object and
37  * an associated method table, similar to a device driver.
38  *
39  * e.g.
40  *
41  * static ofw_method_t fdt_methods[] = {
42  *	OFWMETHOD(ofw_init,		fdt_init),
43  *	OFWMETHOD(ofw_finddevice,	fdt_finddevice),
44  *  ...
45  *	OFWMETHOD(ofw_nextprop,		fdt_nextprop),
46  *	{ 0, 0 }
47  * };
48  *
49  * static ofw_def_t ofw_fdt = {
50  *	"ofw_fdt",
51  *	fdt_methods,
52  *	sizeof(fdt_softc),	// or 0 if no softc
53  * };
54  *
55  * OFW_DEF(ofw_fdt);
56  */
57 
58 #include <sys/kobj.h>
59 
60 struct ofw_kobj {
61 	/*
62 	 * An OFW instance is a kernel object.
63 	 */
64 	KOBJ_FIELDS;
65 
66 	/*
67 	 * Utility elements that an instance may use
68 	 */
69 	struct mtx	ofw_mtx;	/* available for instance use */
70 	void		*ofw_iptr;	/* instance data pointer */
71 
72 	/*
73 	 * Opaque data that can be overlaid with an instance-private
74 	 * structure.  OFW code can test that this is large enough at
75 	 * compile time with a sizeof() test againt it's softc.  There
76 	 * is also a run-time test when the MMU kernel object is
77 	 * registered.
78 	 */
79 #define	OFW_OPAQUESZ	64
80 	u_int		ofw_opaque[OFW_OPAQUESZ];
81 };
82 
83 typedef struct ofw_kobj		*ofw_t;
84 typedef struct kobj_class	ofw_def_t;
85 
86 #define	ofw_method_t	kobj_method_t
87 #define	OFWMETHOD	KOBJMETHOD
88 
89 #define	OFW_DEF(name)	DATA_SET(ofw_set, name)
90 
91 #endif /* _DEV_OFW_OFWVAR_H_ */
92