xref: /linux/arch/xtensa/include/asm/initialize_mmu.h (revision e85e335f8ff615f74e29e09cc2599f095600114b)
1c622b29dSMax Filippov /*
2c622b29dSMax Filippov  * arch/xtensa/include/asm/initialize_mmu.h
3c622b29dSMax Filippov  *
4c622b29dSMax Filippov  * Initializes MMU:
5c622b29dSMax Filippov  *
6c622b29dSMax Filippov  *      For the new V3 MMU we remap the TLB from virtual == physical
7c622b29dSMax Filippov  *      to the standard Linux mapping used in earlier MMU's.
8c622b29dSMax Filippov  *
9c622b29dSMax Filippov  *      The the MMU we also support a new configuration register that
10c622b29dSMax Filippov  *      specifies how the S32C1I instruction operates with the cache
11c622b29dSMax Filippov  *      controller.
12c622b29dSMax Filippov  *
13c622b29dSMax Filippov  * This file is subject to the terms and conditions of the GNU General
14c622b29dSMax Filippov  * Public License.  See the file "COPYING" in the main directory of
15c622b29dSMax Filippov  * this archive for more details.
16c622b29dSMax Filippov  *
17c622b29dSMax Filippov  * Copyright (C) 2008 - 2012 Tensilica, Inc.
18c622b29dSMax Filippov  *
19c622b29dSMax Filippov  *   Marc Gauthier <marc@tensilica.com>
20c622b29dSMax Filippov  *   Pete Delaney <piet@tensilica.com>
21c622b29dSMax Filippov  */
22c622b29dSMax Filippov 
23c622b29dSMax Filippov #ifndef _XTENSA_INITIALIZE_MMU_H
24c622b29dSMax Filippov #define _XTENSA_INITIALIZE_MMU_H
25c622b29dSMax Filippov 
26*e85e335fSMax Filippov #include <asm/pgtable.h>
27*e85e335fSMax Filippov #include <asm/vectors.h>
28*e85e335fSMax Filippov 
29c622b29dSMax Filippov #ifdef __ASSEMBLY__
30c622b29dSMax Filippov 
31c622b29dSMax Filippov #define XTENSA_HWVERSION_RC_2009_0 230000
32c622b29dSMax Filippov 
33c622b29dSMax Filippov 	.macro	initialize_mmu
34c622b29dSMax Filippov 
35c622b29dSMax Filippov #if XCHAL_HAVE_S32C1I && (XCHAL_HW_MIN_VERSION >= XTENSA_HWVERSION_RC_2009_0)
36c622b29dSMax Filippov /*
37c622b29dSMax Filippov  * We Have Atomic Operation Control (ATOMCTL) Register; Initialize it.
38c622b29dSMax Filippov  * For details see Documentation/xtensa/atomctl.txt
39c622b29dSMax Filippov  */
40c622b29dSMax Filippov #if XCHAL_DCACHE_IS_COHERENT
41c622b29dSMax Filippov 	movi	a3, 0x25	/* For SMP/MX -- internal for writeback,
42c622b29dSMax Filippov 				 * RCW otherwise
43c622b29dSMax Filippov 				 */
44c622b29dSMax Filippov #else
45c622b29dSMax Filippov 	movi	a3, 0x29	/* non-MX -- Most cores use Std Memory
46c622b29dSMax Filippov 				 * Controlers which usually can't use RCW
47c622b29dSMax Filippov 				 */
48c622b29dSMax Filippov #endif
49c622b29dSMax Filippov 	wsr	a3, atomctl
50c622b29dSMax Filippov #endif  /* XCHAL_HAVE_S32C1I &&
51c622b29dSMax Filippov 	 * (XCHAL_HW_MIN_VERSION >= XTENSA_HWVERSION_RC_2009_0)
52c622b29dSMax Filippov 	 */
53c622b29dSMax Filippov 
54*e85e335fSMax Filippov #if defined(CONFIG_MMU) && XCHAL_HAVE_PTP_MMU && XCHAL_HAVE_SPANNING_WAY
55*e85e335fSMax Filippov /*
56*e85e335fSMax Filippov  * Have MMU v3
57*e85e335fSMax Filippov  */
58*e85e335fSMax Filippov 
59*e85e335fSMax Filippov #if !XCHAL_HAVE_VECBASE
60*e85e335fSMax Filippov # error "MMU v3 requires reloc vectors"
61*e85e335fSMax Filippov #endif
62*e85e335fSMax Filippov 
63*e85e335fSMax Filippov 	movi	a1, 0
64*e85e335fSMax Filippov 	_call0	1f
65*e85e335fSMax Filippov 	_j	2f
66*e85e335fSMax Filippov 
67*e85e335fSMax Filippov 	.align	4
68*e85e335fSMax Filippov 1:	movi	a2, 0x10000000
69*e85e335fSMax Filippov 	movi	a3, 0x18000000
70*e85e335fSMax Filippov 	add	a2, a2, a0
71*e85e335fSMax Filippov 9:	bgeu	a2, a3, 9b	/* PC is out of the expected range */
72*e85e335fSMax Filippov 
73*e85e335fSMax Filippov 	/* Step 1: invalidate mapping at 0x40000000..0x5FFFFFFF. */
74*e85e335fSMax Filippov 
75*e85e335fSMax Filippov 	movi	a2, 0x40000006
76*e85e335fSMax Filippov 	idtlb	a2
77*e85e335fSMax Filippov 	iitlb	a2
78*e85e335fSMax Filippov 	isync
79*e85e335fSMax Filippov 
80*e85e335fSMax Filippov 	/* Step 2: map 0x40000000..0x47FFFFFF to paddr containing this code
81*e85e335fSMax Filippov 	 * and jump to the new mapping.
82*e85e335fSMax Filippov 	 */
83*e85e335fSMax Filippov #define CA_BYPASS	(_PAGE_CA_BYPASS | _PAGE_HW_WRITE | _PAGE_HW_EXEC)
84*e85e335fSMax Filippov #define CA_WRITEBACK	(_PAGE_CA_WB     | _PAGE_HW_WRITE | _PAGE_HW_EXEC)
85*e85e335fSMax Filippov 
86*e85e335fSMax Filippov 	srli	a3, a0, 27
87*e85e335fSMax Filippov 	slli	a3, a3, 27
88*e85e335fSMax Filippov 	addi	a3, a3, CA_BYPASS
89*e85e335fSMax Filippov 	addi	a7, a2, -1
90*e85e335fSMax Filippov 	wdtlb	a3, a7
91*e85e335fSMax Filippov 	witlb	a3, a7
92*e85e335fSMax Filippov 	isync
93*e85e335fSMax Filippov 
94*e85e335fSMax Filippov 	slli	a4, a0, 5
95*e85e335fSMax Filippov 	srli	a4, a4, 5
96*e85e335fSMax Filippov 	addi	a5, a2, -6
97*e85e335fSMax Filippov 	add	a4, a4, a5
98*e85e335fSMax Filippov 	jx	a4
99*e85e335fSMax Filippov 
100*e85e335fSMax Filippov 	/* Step 3: unmap everything other than current area.
101*e85e335fSMax Filippov 	 *	   Start at 0x60000000, wrap around, and end with 0x20000000
102*e85e335fSMax Filippov 	 */
103*e85e335fSMax Filippov 2:	movi	a4, 0x20000000
104*e85e335fSMax Filippov 	add	a5, a2, a4
105*e85e335fSMax Filippov 3:	idtlb	a5
106*e85e335fSMax Filippov 	iitlb	a5
107*e85e335fSMax Filippov 	add	a5, a5, a4
108*e85e335fSMax Filippov 	bne	a5, a2, 3b
109*e85e335fSMax Filippov 
110*e85e335fSMax Filippov 	/* Step 4: Setup MMU with the old V2 mappings. */
111*e85e335fSMax Filippov 	movi	a6, 0x01000000
112*e85e335fSMax Filippov 	wsr	a6, ITLBCFG
113*e85e335fSMax Filippov 	wsr	a6, DTLBCFG
114*e85e335fSMax Filippov 	isync
115*e85e335fSMax Filippov 
116*e85e335fSMax Filippov 	movi	a5, 0xd0000005
117*e85e335fSMax Filippov 	movi	a4, CA_WRITEBACK
118*e85e335fSMax Filippov 	wdtlb	a4, a5
119*e85e335fSMax Filippov 	witlb	a4, a5
120*e85e335fSMax Filippov 
121*e85e335fSMax Filippov 	movi	a5, 0xd8000005
122*e85e335fSMax Filippov 	movi	a4, CA_BYPASS
123*e85e335fSMax Filippov 	wdtlb	a4, a5
124*e85e335fSMax Filippov 	witlb	a4, a5
125*e85e335fSMax Filippov 
126*e85e335fSMax Filippov 	movi	a5, 0xe0000006
127*e85e335fSMax Filippov 	movi	a4, 0xf0000000 + CA_WRITEBACK
128*e85e335fSMax Filippov 	wdtlb	a4, a5
129*e85e335fSMax Filippov 	witlb	a4, a5
130*e85e335fSMax Filippov 
131*e85e335fSMax Filippov 	movi	a5, 0xf0000006
132*e85e335fSMax Filippov 	movi	a4, 0xf0000000 + CA_BYPASS
133*e85e335fSMax Filippov 	wdtlb	a4, a5
134*e85e335fSMax Filippov 	witlb	a4, a5
135*e85e335fSMax Filippov 
136*e85e335fSMax Filippov 	isync
137*e85e335fSMax Filippov 
138*e85e335fSMax Filippov 	/* Jump to self, using MMU v2 mappings. */
139*e85e335fSMax Filippov 	movi	a4, 1f
140*e85e335fSMax Filippov 	jx	a4
141*e85e335fSMax Filippov 
142*e85e335fSMax Filippov 1:
143*e85e335fSMax Filippov 	movi    a2, VECBASE_RESET_VADDR
144*e85e335fSMax Filippov 	wsr	a2, vecbase
145*e85e335fSMax Filippov 
146*e85e335fSMax Filippov 	/* Step 5: remove temporary mapping. */
147*e85e335fSMax Filippov 	idtlb	a7
148*e85e335fSMax Filippov 	iitlb	a7
149*e85e335fSMax Filippov 	isync
150*e85e335fSMax Filippov 
151*e85e335fSMax Filippov 	movi	a0, 0
152*e85e335fSMax Filippov 	wsr	a0, ptevaddr
153*e85e335fSMax Filippov 	rsync
154*e85e335fSMax Filippov 
155*e85e335fSMax Filippov #endif /* defined(CONFIG_MMU) && XCHAL_HAVE_PTP_MMU &&
156*e85e335fSMax Filippov 	  XCHAL_HAVE_SPANNING_WAY */
157*e85e335fSMax Filippov 
158c622b29dSMax Filippov 	.endm
159c622b29dSMax Filippov 
160c622b29dSMax Filippov #endif /*__ASSEMBLY__*/
161c622b29dSMax Filippov 
162c622b29dSMax Filippov #endif /* _XTENSA_INITIALIZE_MMU_H */
163