blob: 1fda38b09c91dcfbe14a659b659367c65d41d88e [file] [log] [blame]
Catalin Marinas8d2cd3a2011-11-22 17:30:28 +00001/*
2 * arch/arm/mm/proc-v7-2level.S
3 *
4 * Copyright (C) 2001 Deep Blue Solutions Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#define TTB_S (1 << 1)
12#define TTB_RGN_NC (0 << 3)
13#define TTB_RGN_OC_WBWA (1 << 3)
14#define TTB_RGN_OC_WT (2 << 3)
15#define TTB_RGN_OC_WB (3 << 3)
16#define TTB_NOS (1 << 5)
17#define TTB_IRGN_NC ((0 << 0) | (0 << 6))
18#define TTB_IRGN_WBWA ((0 << 0) | (1 << 6))
19#define TTB_IRGN_WT ((1 << 0) | (0 << 6))
20#define TTB_IRGN_WB ((1 << 0) | (1 << 6))
21
22/* PTWs cacheable, inner WB not shareable, outer WB not shareable */
23#define TTB_FLAGS_UP TTB_IRGN_WB|TTB_RGN_OC_WB
24#define PMD_FLAGS_UP PMD_SECT_WB
25
26/* PTWs cacheable, inner WBWA shareable, outer WBWA not shareable */
27#define TTB_FLAGS_SMP TTB_IRGN_WBWA|TTB_S|TTB_NOS|TTB_RGN_OC_WBWA
28#define PMD_FLAGS_SMP PMD_SECT_WBWA|PMD_SECT_S
29
30/*
31 * cpu_v7_switch_mm(pgd_phys, tsk)
32 *
33 * Set the translation table base pointer to be pgd_phys
34 *
35 * - pgd_phys - physical address of new TTB
36 *
37 * It is assumed that:
38 * - we are not using split page tables
39 */
40ENTRY(cpu_v7_switch_mm)
41#ifdef CONFIG_MMU
42 mov r2, #0
43 ldr r1, [r1, #MM_CONTEXT_ID] @ get mm->context.id
44 ALT_SMP(orr r0, r0, #TTB_FLAGS_SMP)
45 ALT_UP(orr r0, r0, #TTB_FLAGS_UP)
46#ifdef CONFIG_ARM_ERRATA_430973
47 mcr p15, 0, r2, c7, c5, 6 @ flush BTAC/BTB
48#endif
49#ifdef CONFIG_ARM_ERRATA_754322
50 dsb
51#endif
Steve Mucklef132c6c2012-06-06 18:30:57 -070052#ifdef CONFIG_PID_IN_CONTEXTIDR
53 mrc p15, 0, r2, c13, c0, 1 @ read current context ID
54 bic r2, r2, #0xff @ extract the PID
55 and r1, r1, #0xff
56 orr r1, r1, r2 @ insert the PID into r1
57#endif
Catalin Marinas8d2cd3a2011-11-22 17:30:28 +000058 mcr p15, 0, r2, c13, c0, 1 @ set reserved context ID
59 isb
601: mcr p15, 0, r0, c2, c0, 0 @ set TTB 0
61 isb
62#ifdef CONFIG_ARM_ERRATA_754322
63 dsb
64#endif
65 mcr p15, 0, r1, c13, c0, 1 @ set context ID
66 isb
67#endif
68 mov pc, lr
69ENDPROC(cpu_v7_switch_mm)
70
71/*
72 * cpu_v7_set_pte_ext(ptep, pte)
73 *
74 * Set a level 2 translation table entry.
75 *
76 * - ptep - pointer to level 2 translation table entry
77 * (hardware version is stored at +2048 bytes)
78 * - pte - PTE value to store
79 * - ext - value for extended PTE bits
80 */
81ENTRY(cpu_v7_set_pte_ext)
82#ifdef CONFIG_MMU
83 str r1, [r0] @ linux version
84
85 bic r3, r1, #0x000003f0
86 bic r3, r3, #PTE_TYPE_MASK
87 orr r3, r3, r2
88 orr r3, r3, #PTE_EXT_AP0 | 2
89
90 tst r1, #1 << 4
91 orrne r3, r3, #PTE_EXT_TEX(1)
92
93 eor r1, r1, #L_PTE_DIRTY
94 tst r1, #L_PTE_RDONLY | L_PTE_DIRTY
95 orrne r3, r3, #PTE_EXT_APX
96
97 tst r1, #L_PTE_USER
98 orrne r3, r3, #PTE_EXT_AP1
99#ifdef CONFIG_CPU_USE_DOMAINS
100 @ allow kernel read/write access to read-only user pages
101 tstne r3, #PTE_EXT_APX
102 bicne r3, r3, #PTE_EXT_APX | PTE_EXT_AP0
103#endif
104
105 tst r1, #L_PTE_XN
106 orrne r3, r3, #PTE_EXT_XN
107
108 tst r1, #L_PTE_YOUNG
109 tstne r1, #L_PTE_PRESENT
110 moveq r3, #0
111
112 ARM( str r3, [r0, #2048]! )
113 THUMB( add r0, r0, #2048 )
114 THUMB( str r3, [r0] )
115 mcr p15, 0, r0, c7, c10, 1 @ flush_pte
116#endif
117 mov pc, lr
118ENDPROC(cpu_v7_set_pte_ext)
119
120 /*
121 * Memory region attributes with SCTLR.TRE=1
122 *
123 * n = TEX[0],C,B
124 * TR = PRRR[2n+1:2n] - memory type
125 * IR = NMRR[2n+1:2n] - inner cacheable property
126 * OR = NMRR[2n+17:2n+16] - outer cacheable property
127 *
128 * n TR IR OR
129 * UNCACHED 000 00
130 * BUFFERABLE 001 10 00 00
131 * WRITETHROUGH 010 10 10 10
132 * WRITEBACK 011 10 11 11
133 * reserved 110
134 * WRITEALLOC 111 10 01 01
135 * DEV_SHARED 100 01
136 * DEV_NONSHARED 100 01
137 * DEV_WC 001 10
138 * DEV_CACHED 011 10
139 *
140 * Other attributes:
141 *
142 * DS0 = PRRR[16] = 0 - device shareable property
143 * DS1 = PRRR[17] = 1 - device shareable property
144 * NS0 = PRRR[18] = 0 - normal shareable property
145 * NS1 = PRRR[19] = 1 - normal shareable property
146 * NOS = PRRR[24+n] = 1 - not outer shareable
147 */
148.equ PRRR, 0xff0a81a8
Steve Mucklef132c6c2012-06-06 18:30:57 -0700149#ifdef CONFIG_ARCH_MSM_SCORPIONMP
150.equ NMRR, 0x40e080e0
151#else
Catalin Marinas8d2cd3a2011-11-22 17:30:28 +0000152.equ NMRR, 0x40e040e0
Steve Mucklef132c6c2012-06-06 18:30:57 -0700153#endif
Catalin Marinas8d2cd3a2011-11-22 17:30:28 +0000154
155 /*
156 * Macro for setting up the TTBRx and TTBCR registers.
157 * - \ttb0 and \ttb1 updated with the corresponding flags.
158 */
159 .macro v7_ttb_setup, zero, ttbr0, ttbr1, tmp
160 mcr p15, 0, \zero, c2, c0, 2 @ TTB control register
161 ALT_SMP(orr \ttbr0, \ttbr0, #TTB_FLAGS_SMP)
162 ALT_UP(orr \ttbr0, \ttbr0, #TTB_FLAGS_UP)
163 ALT_SMP(orr \ttbr1, \ttbr1, #TTB_FLAGS_SMP)
164 ALT_UP(orr \ttbr1, \ttbr1, #TTB_FLAGS_UP)
165 mcr p15, 0, \ttbr1, c2, c0, 1 @ load TTB1
166 .endm
167
168 __CPUINIT
169
170 /* AT
171 * TFR EV X F I D LR S
172 * .EEE ..EE PUI. .T.T 4RVI ZWRS BLDP WCAM
173 * rxxx rrxx xxx0 0101 xxxx xxxx x111 xxxx < forced
174 * 1 0 110 0011 1100 .111 1101 < we want
175 */
176 .align 2
177 .type v7_crval, #object
178v7_crval:
179 crval clear=0x0120c302, mmuset=0x10c03c7d, ucset=0x00c01c7c
180
181 .previous