1152179Sgrehan/*-
2152179Sgrehan * Copyright (c) 2005 Peter Grehan
3152179Sgrehan * All rights reserved.
4152179Sgrehan *
5152179Sgrehan * Redistribution and use in source and binary forms, with or without
6152179Sgrehan * modification, are permitted provided that the following conditions
7152179Sgrehan * are met:
8152179Sgrehan * 1. Redistributions of source code must retain the above copyright
9152179Sgrehan *    notice, this list of conditions and the following disclaimer.
10152179Sgrehan * 2. Redistributions in binary form must reproduce the above copyright
11152179Sgrehan *    notice, this list of conditions and the following disclaimer in the
12152179Sgrehan *    documentation and/or other materials provided with the distribution.
13152179Sgrehan *
14152179Sgrehan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15152179Sgrehan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16152179Sgrehan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17152179Sgrehan * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18152179Sgrehan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19152179Sgrehan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20152179Sgrehan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21152179Sgrehan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22152179Sgrehan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23152179Sgrehan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24152179Sgrehan * SUCH DAMAGE.
25152179Sgrehan *
26152179Sgrehan * $FreeBSD: releng/10.3/sys/powerpc/include/mmuvar.h 212627 2010-09-15 00:17:52Z grehan $
27152179Sgrehan */
28152179Sgrehan
29152179Sgrehan#ifndef _MACHINE_MMUVAR_H_
30152179Sgrehan#define _MACHINE_MMUVAR_H_
31152179Sgrehan
32152179Sgrehan/*
33152179Sgrehan * A PowerPC MMU implementation is declared with a kernel object and
34212627Sgrehan * an associated method table. The MMU_DEF macro is used to declare
35212627Sgrehan * the class, and also links it to the global MMU class list.
36152179Sgrehan *
37152179Sgrehan * e.g.
38152179Sgrehan *
39152179Sgrehan * static mmu_method_t ppc8xx_methods[] = {
40152179Sgrehan *	MMUMETHOD(mmu_change_wiring,		ppc8xx_mmu_change_wiring),
41152179Sgrehan *	MMUMETHOD(mmu_clear_modify,		ppc8xx_mmu_clear_modify),
42152179Sgrehan *	MMUMETHOD(mmu_clear_reference,		ppc8xx_mmu_clear_reference),
43152179Sgrehan *  ...
44152179Sgrehan *	MMUMETHOD(mmu_dev_direct_mapped,	ppc8xx_mmu_dev_direct_mapped),
45152179Sgrehan *	{ 0, 0 }
46152179Sgrehan * };
47152179Sgrehan *
48212627Sgrehan * MMU_DEF(ppc8xx, MMU_TYPE_8xx, ppc8xx_methods, sizeof(ppc8xx_mmu_softc));
49152179Sgrehan *
50212627Sgrehan * A single level of inheritance is supported in a similar fashion to
51212627Sgrehan * kobj inheritance e.g.
52212627Sgrehan *
53212627Sgrehan * MMU_DEF_1(ppc860c, MMU_TYPE_860c, ppc860c_methods, 0, ppc8xx);
54152179Sgrehan */
55152179Sgrehan
56152179Sgrehan#include <sys/kobj.h>
57152179Sgrehan
58152179Sgrehanstruct mmu_kobj {
59152179Sgrehan	/*
60152179Sgrehan	 * An MMU instance is a kernel object
61152179Sgrehan	 */
62152179Sgrehan	KOBJ_FIELDS;
63152179Sgrehan
64152179Sgrehan	/*
65152179Sgrehan	 * Utility elements that an instance may use
66152179Sgrehan	 */
67152179Sgrehan	struct mtx	mmu_mtx;	/* available for instance use */
68152179Sgrehan	void		*mmu_iptr;	/* instance data pointer */
69152179Sgrehan
70152179Sgrehan	/*
71152179Sgrehan	 * Opaque data that can be overlaid with an instance-private
72152179Sgrehan	 * structure. MMU code can test that this is large enough at
73152179Sgrehan	 * compile time with a sizeof() test againt it's softc. There
74152179Sgrehan	 * is also a run-time test when the MMU kernel object is
75152179Sgrehan	 * registered.
76152179Sgrehan	 */
77152179Sgrehan#define MMU_OPAQUESZ	64
78152179Sgrehan	u_int		mmu_opaque[MMU_OPAQUESZ];
79152179Sgrehan};
80152179Sgrehan
81152179Sgrehantypedef struct mmu_kobj		*mmu_t;
82152179Sgrehantypedef struct kobj_class	mmu_def_t;
83152179Sgrehan#define mmu_method_t		kobj_method_t
84152179Sgrehan
85152179Sgrehan#define MMUMETHOD	KOBJMETHOD
86152179Sgrehan
87212627Sgrehan#define MMU_DEF(name, ident, methods, size)	\
88212627Sgrehan						\
89212627Sgrehanmmu_def_t name = {				\
90212627Sgrehan	ident, methods, size, NULL		\
91212627Sgrehan};						\
92212627SgrehanDATA_SET(mmu_set, name)
93152179Sgrehan
94212627Sgrehan#define MMU_DEF_INHERIT(name, ident, methods, size, base1)	\
95212627Sgrehan						\
96212627Sgrehanstatic kobj_class_t name ## _baseclasses[] =	\
97212627Sgrehan       	{ &base1, NULL };			\
98212627Sgrehanmmu_def_t name = {                              \
99212627Sgrehan	ident, methods, size, name ## _baseclasses	\
100212627Sgrehan};                                              \
101212627SgrehanDATA_SET(mmu_set, name)
102212627Sgrehan
103212627Sgrehan
104212627Sgrehan#if 0
105212627Sgrehanmmu_def_t name = {				\
106212627Sgrehan	ident, methods, size, name ## _baseclasses	\
107212627Sgrehan};
108212627SgrehanDATA_SET(mmu_set, name)
109212627Sgrehan#endif
110212627Sgrehan
111152179Sgrehan/*
112152179Sgrehan * Known MMU names
113152179Sgrehan */
114176771Sraj#define MMU_TYPE_BOOKE	"mmu_booke"	/* Book-E MMU specification */
115152179Sgrehan#define MMU_TYPE_OEA	"mmu_oea"	/* 32-bit OEA */
116152179Sgrehan#define MMU_TYPE_G5	"mmu_g5"	/* 64-bit bridge (ibm 970) */
117152179Sgrehan#define MMU_TYPE_8xx	"mmu_8xx"	/* 8xx quicc TLB */
118152179Sgrehan
119152179Sgrehan#endif /* _MACHINE_MMUVAR_H_ */
120