xref: /titanic_50/usr/src/uts/sun4v/sys/mmu.h (revision 9d0d62ad2e60e8f742a2e723d06e88352ee6a1f3)
17c478bd9Sstevel@tonic-gate /*
27636cb21Slm66018  * CDDL HEADER START
37636cb21Slm66018  *
47636cb21Slm66018  * The contents of this file are subject to the terms of the
57636cb21Slm66018  * Common Development and Distribution License (the "License").
67636cb21Slm66018  * You may not use this file except in compliance with the License.
77636cb21Slm66018  *
87636cb21Slm66018  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97636cb21Slm66018  * or http://www.opensolaris.org/os/licensing.
107636cb21Slm66018  * See the License for the specific language governing permissions
117636cb21Slm66018  * and limitations under the License.
127636cb21Slm66018  *
137636cb21Slm66018  * When distributing Covered Code, include this CDDL HEADER in each
147636cb21Slm66018  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157636cb21Slm66018  * If applicable, add the following below this CDDL HEADER, with the
167636cb21Slm66018  * fields enclosed by brackets "[]" replaced with your own identifying
177636cb21Slm66018  * information: Portions Copyright [yyyy] [name of copyright owner]
187636cb21Slm66018  *
197636cb21Slm66018  * CDDL HEADER END
207636cb21Slm66018  */
217636cb21Slm66018 
227636cb21Slm66018 /*
23*125be069SJason Beloro  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_SYS_MMU_H
287c478bd9Sstevel@tonic-gate #define	_SYS_MMU_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #ifndef _ASM
357c478bd9Sstevel@tonic-gate #include <sys/types.h>
367c478bd9Sstevel@tonic-gate #endif
377c478bd9Sstevel@tonic-gate #include <sys/hypervisor_api.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * Definitions for the SOFT MMU
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #define	FAST_IMMU_MISS_TT	0x64
447c478bd9Sstevel@tonic-gate #define	FAST_DMMU_MISS_TT	0x68
457c478bd9Sstevel@tonic-gate #define	FAST_PROT_TT		0x6c
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * Constants defining alternate spaces
497c478bd9Sstevel@tonic-gate  * and register layouts within them,
507c478bd9Sstevel@tonic-gate  * and a few other interesting assembly constants.
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate  * vaddr offsets of various registers
557c478bd9Sstevel@tonic-gate  */
567c478bd9Sstevel@tonic-gate #define	MMU_PCONTEXT		0x08 /* primary context number */
577c478bd9Sstevel@tonic-gate #define	MMU_SCONTEXT		0x10 /* secondary context number */
587c478bd9Sstevel@tonic-gate 
5905d3dc4bSpaulsan #define	MMU_PCONTEXT0		MMU_PCONTEXT	/* primary context# 0 */
6005d3dc4bSpaulsan #define	MMU_PCONTEXT1		0x108		/* primary context# 1 */
6105d3dc4bSpaulsan #define	MMU_SCONTEXT0		MMU_SCONTEXT	/* secondary context# 0 */
6205d3dc4bSpaulsan #define	MMU_SCONTEXT1		0x110		/* secondary context# 1 */
6305d3dc4bSpaulsan 
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate  * Pseudo Synchronous Fault Status Register Layout
667c478bd9Sstevel@tonic-gate  *
677c478bd9Sstevel@tonic-gate  * IMMU and DMMU maintain their own pseudo SFSR Register
687c478bd9Sstevel@tonic-gate  *
697c478bd9Sstevel@tonic-gate  * +------------------------------------------------+
707c478bd9Sstevel@tonic-gate  * |       Reserved       |   Context   |     FT    |
717c478bd9Sstevel@tonic-gate  * +----------------------|-------------------------+
727c478bd9Sstevel@tonic-gate  *  63                  32 31         16 15         0
737c478bd9Sstevel@tonic-gate  *
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate #define	SFSR_FT		0x0000FFFF	/* fault type mask */
767c478bd9Sstevel@tonic-gate #define	SFSR_CTX	0xFFFF0000	/* fault context mask */
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate /*
797c478bd9Sstevel@tonic-gate  * Definition of FT (Fault Type) bit field of sfsr.
807c478bd9Sstevel@tonic-gate  */
817c478bd9Sstevel@tonic-gate #define	FT_NONE		0x00
827c478bd9Sstevel@tonic-gate #define	FT_PRIV		MMFSA_F_PRIV	/* privilege violation */
837c478bd9Sstevel@tonic-gate #define	FT_SPEC_LD	MMFSA_F_SOPG	/* speculative ld to e page */
847c478bd9Sstevel@tonic-gate #define	FT_ATOMIC_NC	MMFSA_F_NCATM	/* atomic to nc page */
857c478bd9Sstevel@tonic-gate #define	FT_ILL_ALT	MMFSA_F_INVASI	/* illegal lda/sta */
867c478bd9Sstevel@tonic-gate #define	FT_NFO		MMFSA_F_NFO	/* normal access to nfo page */
877c478bd9Sstevel@tonic-gate #define	FT_RANGE	MMFSA_F_INVVA	/* dmmu or immu address out of range */
887c478bd9Sstevel@tonic-gate #define	FT_NEW_FMISS	MMFSA_F_FMISS	/* fast miss */
897c478bd9Sstevel@tonic-gate #define	FT_NEW_FPROT	MMFSA_F_FPROT	/* fast protection */
907c478bd9Sstevel@tonic-gate #define	FT_NEW_MISS	MMFSA_F_MISS	/* mmu miss */
917c478bd9Sstevel@tonic-gate #define	FT_NEW_INVRA	MMFSA_F_INVRA	/* invalid RA */
927c478bd9Sstevel@tonic-gate #define	FT_NEW_PROT	MMFSA_F_PROT	/* protection violation */
937c478bd9Sstevel@tonic-gate #define	FT_NEW_PRVACT	MMFSA_F_PRVACT	/* privileged action */
947c478bd9Sstevel@tonic-gate #define	FT_NEW_WPT	MMFSA_F_WPT	/* watchpoint hit */
957c478bd9Sstevel@tonic-gate #define	FT_NEW_UNALIGN	MMFSA_F_UNALIGN	/* unaligned access */
967c478bd9Sstevel@tonic-gate #define	FT_NEW_INVPGSZ	MMFSA_F_INVPGSZ	/* invalid page size */
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate #define	SFSR_FT_SHIFT	0	/* amt. to shift right to get flt type */
997c478bd9Sstevel@tonic-gate #define	SFSR_CTX_SHIFT	16	/* to shift right to get context */
1007c478bd9Sstevel@tonic-gate #define	X_FAULT_TYPE(x)	(((x) & SFSR_FT) >> SFSR_FT_SHIFT)
1017c478bd9Sstevel@tonic-gate #define	X_FAULT_CTX(x)	(((x) & SFSR_CTX) >> SFSR_CTX_SHIFT)
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate /*
1047c478bd9Sstevel@tonic-gate  * MMU TAG TARGET register Layout
1057c478bd9Sstevel@tonic-gate  *
10660972f37Sjb145095  * +---------------+------+-------------------------+
10760972f37Sjb145095  * |    context    |  --  | virtual address [63:22] |
10860972f37Sjb145095  * +---------------+------+-------------------------+
10960972f37Sjb145095  *  63           48 47  42 41                      0
11060972f37Sjb145095  *
11160972f37Sjb145095  * Some sun4v processors only use a 13-bit context ID, so bits 61-63 will be
11260972f37Sjb145095  * zero in that case.  This layout allows us to use the same code for any sun4v
11360972f37Sjb145095  * processors, whether they support 13 bit or 16 bit context IDs (or something
11460972f37Sjb145095  * in between).
1157c478bd9Sstevel@tonic-gate  */
1167c478bd9Sstevel@tonic-gate #define	TTARGET_CTX_SHIFT	48
1177c478bd9Sstevel@tonic-gate #define	TTARGET_VA_SHIFT	22
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate /*
12060972f37Sjb145095  * Pseudo MMU TAG ACCESS register Layout
1217c478bd9Sstevel@tonic-gate  *
1227c478bd9Sstevel@tonic-gate  * +-------------------------+------------------+
12360972f37Sjb145095  * | virtual address [63:13] |     0     | type |
1247c478bd9Sstevel@tonic-gate  * +-------------------------+------------------+
12560972f37Sjb145095  *  63			  13	12      2 1    0
12660972f37Sjb145095  *
12760972f37Sjb145095  * 16-bit context IDs don't fit into the 13 bit field as they did on sun4u,
12860972f37Sjb145095  * so we use a context type, 0 = kernel context, 1 = invalid context,
12960972f37Sjb145095  * 2 = user context.
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate #define	TAGACC_CTX_MASK		0x1FFF
1327c478bd9Sstevel@tonic-gate #define	TAGACC_SHIFT		13
1337c478bd9Sstevel@tonic-gate #define	TAGACC_VADDR_MASK	(~TAGACC_CTX_MASK)
1347c478bd9Sstevel@tonic-gate #define	TAGACC_CTX_LSHIFT	(64 - TAGACC_SHIFT)
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * The kernel always runs in KCONTEXT, and no user mappings
1387c478bd9Sstevel@tonic-gate  * are ever valid in it (so any user access pagefaults).
1397c478bd9Sstevel@tonic-gate  */
1407c478bd9Sstevel@tonic-gate #define	KCONTEXT	0
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate /*
1437c478bd9Sstevel@tonic-gate  * FLUSH_ADDR is used in the flush instruction to guarantee stores to mmu
1447c478bd9Sstevel@tonic-gate  * registers complete.  It is selected so it won't miss in the tlb.
1457c478bd9Sstevel@tonic-gate  */
1467c478bd9Sstevel@tonic-gate #define	FLUSH_ADDR	(KERNELBASE + 2 * MMU_PAGESIZE4M)
1477c478bd9Sstevel@tonic-gate 
1481ae08745Sheppo #define	MAX_NCTXS_BITS			16	/* sun4v max. contexts bits */
1491ae08745Sheppo #define	MIN_NCTXS_BITS			2
1501ae08745Sheppo #define	MAX_NCTXS	(1ull << MAX_NCTXS_BITS)
1511ae08745Sheppo 
15205d3dc4bSpaulsan /*
1537dacfc44Spaulsan  * MIN_NSHCONTEXTS and MIN_NTSBS are the minimum number of shared contexts
1547dacfc44Spaulsan  * and tsbs necessary for shared context support.
15505d3dc4bSpaulsan  */
15605d3dc4bSpaulsan #define	MIN_NSHCONTEXTS			1
15705d3dc4bSpaulsan #define	MIN_NTSBS			4
15805d3dc4bSpaulsan 
1597c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1607c478bd9Sstevel@tonic-gate }
1617c478bd9Sstevel@tonic-gate #endif
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate #endif /* _SYS_MMU_H */
164