xref: /illumos-gate/usr/src/uts/sun4v/sys/mmu.h (revision 60a3f738d56f92ae8b80e4b62a2331c6e1f2311f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_MMU_H
28 #define	_SYS_MMU_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #ifndef _ASM
37 #include <sys/types.h>
38 #endif
39 #include <sys/hypervisor_api.h>
40 
41 /*
42  * Definitions for the SOFT MMU
43  */
44 
45 #define	FAST_IMMU_MISS_TT	0x64
46 #define	FAST_DMMU_MISS_TT	0x68
47 #define	FAST_PROT_TT		0x6c
48 
49 /*
50  * Constants defining alternate spaces
51  * and register layouts within them,
52  * and a few other interesting assembly constants.
53  */
54 
55 /*
56  * vaddr offsets of various registers
57  */
58 #define	MMU_PCONTEXT		0x08 /* primary context number */
59 #define	MMU_SCONTEXT		0x10 /* secondary context number */
60 
61 /*
62  * Pseudo Synchronous Fault Status Register Layout
63  *
64  * IMMU and DMMU maintain their own pseudo SFSR Register
65  *
66  * +------------------------------------------------+
67  * |       Reserved       |   Context   |     FT    |
68  * +----------------------|-------------------------+
69  *  63                  32 31         16 15         0
70  *
71  */
72 #define	SFSR_FT		0x0000FFFF	/* fault type mask */
73 #define	SFSR_CTX	0xFFFF0000	/* fault context mask */
74 
75 /*
76  * Definition of FT (Fault Type) bit field of sfsr.
77  */
78 #define	FT_NONE		0x00
79 #define	FT_PRIV		MMFSA_F_PRIV	/* privilege violation */
80 #define	FT_SPEC_LD	MMFSA_F_SOPG	/* speculative ld to e page */
81 #define	FT_ATOMIC_NC	MMFSA_F_NCATM	/* atomic to nc page */
82 #define	FT_ILL_ALT	MMFSA_F_INVASI	/* illegal lda/sta */
83 #define	FT_NFO		MMFSA_F_NFO	/* normal access to nfo page */
84 #define	FT_RANGE	MMFSA_F_INVVA	/* dmmu or immu address out of range */
85 #define	FT_NEW_FMISS	MMFSA_F_FMISS	/* fast miss */
86 #define	FT_NEW_FPROT	MMFSA_F_FPROT	/* fast protection */
87 #define	FT_NEW_MISS	MMFSA_F_MISS	/* mmu miss */
88 #define	FT_NEW_INVRA	MMFSA_F_INVRA	/* invalid RA */
89 #define	FT_NEW_PROT	MMFSA_F_PROT	/* protection violation */
90 #define	FT_NEW_PRVACT	MMFSA_F_PRVACT	/* privileged action */
91 #define	FT_NEW_WPT	MMFSA_F_WPT	/* watchpoint hit */
92 #define	FT_NEW_UNALIGN	MMFSA_F_UNALIGN	/* unaligned access */
93 #define	FT_NEW_INVPGSZ	MMFSA_F_INVPGSZ	/* invalid page size */
94 
95 #define	SFSR_FT_SHIFT	0	/* amt. to shift right to get flt type */
96 #define	SFSR_CTX_SHIFT	16	/* to shift right to get context */
97 #define	X_FAULT_TYPE(x)	(((x) & SFSR_FT) >> SFSR_FT_SHIFT)
98 #define	X_FAULT_CTX(x)	(((x) & SFSR_CTX) >> SFSR_CTX_SHIFT)
99 
100 /*
101  * MMU TAG TARGET register Layout
102  *
103  * +-----+---------+------+-------------------------+
104  * | 000 | context |  --  | virtual address [63:22] |
105  * +-----+---------+------+-------------------------+
106  *  63 61 60	 48 47	42 41			   0
107  */
108 #define	TTARGET_CTX_SHIFT	48
109 #define	TTARGET_VA_SHIFT	22
110 
111 /*
112  * MMU TAG ACCESS register Layout
113  *
114  * +-------------------------+------------------+
115  * | virtual address [63:13] |  context [12:0]  |
116  * +-------------------------+------------------+
117  *  63			  13	12		0
118  */
119 #define	TAGACC_CTX_MASK		0x1FFF
120 #define	TAGACC_SHIFT		13
121 #define	TAGACC_VADDR_MASK	(~TAGACC_CTX_MASK)
122 #define	TAGACC_CTX_LSHIFT	(64 - TAGACC_SHIFT)
123 
124 /*
125  * MMU PRIMARY/SECONDARY CONTEXT register
126  */
127 #define	CTXREG_CTX_MASK		0x1FFF
128 
129 /*
130  * The kernel always runs in KCONTEXT, and no user mappings
131  * are ever valid in it (so any user access pagefaults).
132  */
133 #define	KCONTEXT	0
134 
135 /*
136  * FLUSH_ADDR is used in the flush instruction to guarantee stores to mmu
137  * registers complete.  It is selected so it won't miss in the tlb.
138  */
139 #define	FLUSH_ADDR	(KERNELBASE + 2 * MMU_PAGESIZE4M)
140 
141 #define	MAX_NCTXS_BITS			16	/* sun4v max. contexts bits */
142 #define	MIN_NCTXS_BITS			2
143 #define	MAX_NCTXS	(1ull << MAX_NCTXS_BITS)
144 
145 #ifdef	__cplusplus
146 }
147 #endif
148 
149 #endif /* _SYS_MMU_H */
150