Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mm/proc-v7.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 | * This is the "shell" of the ARMv7 processor support. |
| 11 | */ |
| 12 | #include <linux/linkage.h> |
| 13 | #include <asm/assembler.h> |
| 14 | #include <asm/asm-offsets.h> |
Russell King | 5ec9407 | 2008-09-07 19:15:31 +0100 | [diff] [blame] | 15 | #include <asm/hwcap.h> |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 16 | #include <asm/pgtable-hwdef.h> |
| 17 | #include <asm/pgtable.h> |
| 18 | |
| 19 | #include "proc-macros.S" |
| 20 | |
| 21 | #define TTB_C (1 << 0) |
| 22 | #define TTB_S (1 << 1) |
Jon Callan | 73b63ef | 2008-11-06 13:23:09 +0000 | [diff] [blame] | 23 | #define TTB_RGN_NC (0 << 3) |
| 24 | #define TTB_RGN_OC_WBWA (1 << 3) |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 25 | #define TTB_RGN_OC_WT (2 << 3) |
| 26 | #define TTB_RGN_OC_WB (3 << 3) |
| 27 | |
Jon Callan | 73b63ef | 2008-11-06 13:23:09 +0000 | [diff] [blame] | 28 | #ifndef CONFIG_SMP |
| 29 | #define TTB_FLAGS TTB_C|TTB_RGN_OC_WB @ mark PTWs cacheable, outer WB |
| 30 | #else |
| 31 | #define TTB_FLAGS TTB_C|TTB_S|TTB_RGN_OC_WBWA @ mark PTWs cacheable and shared, outer WBWA |
| 32 | #endif |
| 33 | |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 34 | ENTRY(cpu_v7_proc_init) |
| 35 | mov pc, lr |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 36 | ENDPROC(cpu_v7_proc_init) |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 37 | |
| 38 | ENTRY(cpu_v7_proc_fin) |
| 39 | mov pc, lr |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 40 | ENDPROC(cpu_v7_proc_fin) |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * cpu_v7_reset(loc) |
| 44 | * |
| 45 | * Perform a soft reset of the system. Put the CPU into the |
| 46 | * same state as it would be if it had been reset, and branch |
| 47 | * to what would be the reset vector. |
| 48 | * |
| 49 | * - loc - location to jump to for soft reset |
| 50 | * |
| 51 | * It is assumed that: |
| 52 | */ |
| 53 | .align 5 |
| 54 | ENTRY(cpu_v7_reset) |
| 55 | mov pc, r0 |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 56 | ENDPROC(cpu_v7_reset) |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 57 | |
| 58 | /* |
| 59 | * cpu_v7_do_idle() |
| 60 | * |
| 61 | * Idle the processor (eg, wait for interrupt). |
| 62 | * |
| 63 | * IRQs are already disabled. |
| 64 | */ |
| 65 | ENTRY(cpu_v7_do_idle) |
Catalin Marinas | 8553cb6 | 2008-11-10 14:14:11 +0000 | [diff] [blame] | 66 | dsb @ WFI may enter a low-power mode |
Catalin Marinas | 000b502 | 2008-10-03 11:09:10 +0100 | [diff] [blame] | 67 | wfi |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 68 | mov pc, lr |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 69 | ENDPROC(cpu_v7_do_idle) |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 70 | |
| 71 | ENTRY(cpu_v7_dcache_clean_area) |
| 72 | #ifndef TLB_CAN_READ_FROM_L1_CACHE |
| 73 | dcache_line_size r2, r3 |
| 74 | 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry |
| 75 | add r0, r0, r2 |
| 76 | subs r1, r1, r2 |
| 77 | bhi 1b |
| 78 | dsb |
| 79 | #endif |
| 80 | mov pc, lr |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 81 | ENDPROC(cpu_v7_dcache_clean_area) |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 82 | |
| 83 | /* |
| 84 | * cpu_v7_switch_mm(pgd_phys, tsk) |
| 85 | * |
| 86 | * Set the translation table base pointer to be pgd_phys |
| 87 | * |
| 88 | * - pgd_phys - physical address of new TTB |
| 89 | * |
| 90 | * It is assumed that: |
| 91 | * - we are not using split page tables |
| 92 | */ |
| 93 | ENTRY(cpu_v7_switch_mm) |
Catalin Marinas | 2eb8c82 | 2007-07-20 11:43:02 +0100 | [diff] [blame] | 94 | #ifdef CONFIG_MMU |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 95 | mov r2, #0 |
| 96 | ldr r1, [r1, #MM_CONTEXT_ID] @ get mm->context.id |
Jon Callan | 73b63ef | 2008-11-06 13:23:09 +0000 | [diff] [blame] | 97 | orr r0, r0, #TTB_FLAGS |
Catalin Marinas | 7ce236f | 2009-04-30 17:06:09 +0100 | [diff] [blame^] | 98 | #ifdef CONFIG_ARM_ERRATA_430973 |
| 99 | mcr p15, 0, r2, c7, c5, 6 @ flush BTAC/BTB |
| 100 | #endif |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 101 | mcr p15, 0, r2, c13, c0, 1 @ set reserved context ID |
| 102 | isb |
| 103 | 1: mcr p15, 0, r0, c2, c0, 0 @ set TTB 0 |
| 104 | isb |
| 105 | mcr p15, 0, r1, c13, c0, 1 @ set context ID |
| 106 | isb |
Catalin Marinas | 2eb8c82 | 2007-07-20 11:43:02 +0100 | [diff] [blame] | 107 | #endif |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 108 | mov pc, lr |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 109 | ENDPROC(cpu_v7_switch_mm) |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 110 | |
| 111 | /* |
| 112 | * cpu_v7_set_pte_ext(ptep, pte) |
| 113 | * |
| 114 | * Set a level 2 translation table entry. |
| 115 | * |
| 116 | * - ptep - pointer to level 2 translation table entry |
| 117 | * (hardware version is stored at -1024 bytes) |
| 118 | * - pte - PTE value to store |
| 119 | * - ext - value for extended PTE bits |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 120 | */ |
| 121 | ENTRY(cpu_v7_set_pte_ext) |
Catalin Marinas | 2eb8c82 | 2007-07-20 11:43:02 +0100 | [diff] [blame] | 122 | #ifdef CONFIG_MMU |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 123 | str r1, [r0], #-2048 @ linux version |
| 124 | |
| 125 | bic r3, r1, #0x000003f0 |
Russell King | 3f69c0c | 2008-09-15 17:23:10 +0100 | [diff] [blame] | 126 | bic r3, r3, #PTE_TYPE_MASK |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 127 | orr r3, r3, r2 |
| 128 | orr r3, r3, #PTE_EXT_AP0 | 2 |
| 129 | |
Russell King | b1cce6b | 2008-11-04 10:52:28 +0000 | [diff] [blame] | 130 | tst r1, #1 << 4 |
Russell King | 3f69c0c | 2008-09-15 17:23:10 +0100 | [diff] [blame] | 131 | orrne r3, r3, #PTE_EXT_TEX(1) |
| 132 | |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 133 | tst r1, #L_PTE_WRITE |
| 134 | tstne r1, #L_PTE_DIRTY |
| 135 | orreq r3, r3, #PTE_EXT_APX |
| 136 | |
| 137 | tst r1, #L_PTE_USER |
| 138 | orrne r3, r3, #PTE_EXT_AP1 |
| 139 | tstne r3, #PTE_EXT_APX |
| 140 | bicne r3, r3, #PTE_EXT_APX | PTE_EXT_AP0 |
| 141 | |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 142 | tst r1, #L_PTE_EXEC |
| 143 | orreq r3, r3, #PTE_EXT_XN |
| 144 | |
Russell King | 3f69c0c | 2008-09-15 17:23:10 +0100 | [diff] [blame] | 145 | tst r1, #L_PTE_YOUNG |
| 146 | tstne r1, #L_PTE_PRESENT |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 147 | moveq r3, #0 |
| 148 | |
| 149 | str r3, [r0] |
| 150 | mcr p15, 0, r0, c7, c10, 1 @ flush_pte |
Catalin Marinas | 2eb8c82 | 2007-07-20 11:43:02 +0100 | [diff] [blame] | 151 | #endif |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 152 | mov pc, lr |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 153 | ENDPROC(cpu_v7_set_pte_ext) |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 154 | |
| 155 | cpu_v7_name: |
| 156 | .ascii "ARMv7 Processor" |
| 157 | .align |
| 158 | |
| 159 | .section ".text.init", #alloc, #execinstr |
| 160 | |
| 161 | /* |
| 162 | * __v7_setup |
| 163 | * |
| 164 | * Initialise TLB, Caches, and MMU state ready to switch the MMU |
| 165 | * on. Return in r0 the new CP15 C1 control register setting. |
| 166 | * |
| 167 | * We automatically detect if we have a Harvard cache, and use the |
| 168 | * Harvard cache control instructions insead of the unified cache |
| 169 | * control instructions. |
| 170 | * |
| 171 | * This should be able to cover all ARMv7 cores. |
| 172 | * |
| 173 | * It is assumed that: |
| 174 | * - cache type register is implemented |
| 175 | */ |
| 176 | __v7_setup: |
Jon Callan | 73b63ef | 2008-11-06 13:23:09 +0000 | [diff] [blame] | 177 | #ifdef CONFIG_SMP |
| 178 | mrc p15, 0, r0, c1, c0, 1 @ Enable SMP/nAMP mode |
| 179 | orr r0, r0, #(0x1 << 6) |
| 180 | mcr p15, 0, r0, c1, c0, 1 |
| 181 | #endif |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 182 | adr r12, __v7_setup_stack @ the local stack |
| 183 | stmia r12, {r0-r5, r7, r9, r11, lr} |
| 184 | bl v7_flush_dcache_all |
| 185 | ldmia r12, {r0-r5, r7, r9, r11, lr} |
Catalin Marinas | 7ce236f | 2009-04-30 17:06:09 +0100 | [diff] [blame^] | 186 | #ifdef CONFIG_ARM_ERRATA_430973 |
| 187 | mrc p15, 0, r10, c1, c0, 1 @ read aux control register |
| 188 | orr r10, r10, #(1 << 6) @ set IBE to 1 |
| 189 | mcr p15, 0, r10, c1, c0, 1 @ write aux control register |
| 190 | #endif |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 191 | mov r10, #0 |
| 192 | #ifdef HARVARD_CACHE |
| 193 | mcr p15, 0, r10, c7, c5, 0 @ I+BTB cache invalidate |
| 194 | #endif |
| 195 | dsb |
Catalin Marinas | 2eb8c82 | 2007-07-20 11:43:02 +0100 | [diff] [blame] | 196 | #ifdef CONFIG_MMU |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 197 | mcr p15, 0, r10, c8, c7, 0 @ invalidate I + D TLBs |
| 198 | mcr p15, 0, r10, c2, c0, 2 @ TTB control register |
Jon Callan | 73b63ef | 2008-11-06 13:23:09 +0000 | [diff] [blame] | 199 | orr r4, r4, #TTB_FLAGS |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 200 | mcr p15, 0, r4, c2, c0, 1 @ load TTB1 |
| 201 | mov r10, #0x1f @ domains 0, 1 = manager |
| 202 | mcr p15, 0, r10, c3, c0, 0 @ load domain access register |
Catalin Marinas | 2eb8c82 | 2007-07-20 11:43:02 +0100 | [diff] [blame] | 203 | #endif |
Catalin Marinas | f80a3bb | 2008-10-22 13:04:30 +0100 | [diff] [blame] | 204 | ldr r5, =0xff0aa1a8 |
| 205 | ldr r6, =0x40e040e0 |
Russell King | 3f69c0c | 2008-09-15 17:23:10 +0100 | [diff] [blame] | 206 | mcr p15, 0, r5, c10, c2, 0 @ write PRRR |
| 207 | mcr p15, 0, r6, c10, c2, 1 @ write NMRR |
Catalin Marinas | 2eb8c82 | 2007-07-20 11:43:02 +0100 | [diff] [blame] | 208 | adr r5, v7_crval |
| 209 | ldmia r5, {r5, r6} |
| 210 | mrc p15, 0, r0, c1, c0, 0 @ read control register |
| 211 | bic r0, r0, r5 @ clear bits them |
| 212 | orr r0, r0, r6 @ set them |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 213 | mov pc, lr @ return to head.S:__ret |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 214 | ENDPROC(__v7_setup) |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 215 | |
Russell King | b1cce6b | 2008-11-04 10:52:28 +0000 | [diff] [blame] | 216 | /* AT |
| 217 | * TFR EV X F I D LR |
| 218 | * .EEE ..EE PUI. .T.T 4RVI ZFRS BLDP WCAM |
| 219 | * rxxx rrxx xxx0 0101 xxxx xxxx x111 xxxx < forced |
| 220 | * 1 0 110 0011 1.00 .111 1101 < we want |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 221 | */ |
Catalin Marinas | 2eb8c82 | 2007-07-20 11:43:02 +0100 | [diff] [blame] | 222 | .type v7_crval, #object |
| 223 | v7_crval: |
Russell King | 3f69c0c | 2008-09-15 17:23:10 +0100 | [diff] [blame] | 224 | crval clear=0x0120c302, mmuset=0x10c0387d, ucset=0x00c0187c |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 225 | |
| 226 | __v7_setup_stack: |
| 227 | .space 4 * 11 @ 11 registers |
| 228 | |
| 229 | .type v7_processor_functions, #object |
| 230 | ENTRY(v7_processor_functions) |
| 231 | .word v7_early_abort |
Catalin Marinas | 4a1fd55 | 2008-04-21 18:42:04 +0100 | [diff] [blame] | 232 | .word pabort_ifar |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 233 | .word cpu_v7_proc_init |
| 234 | .word cpu_v7_proc_fin |
| 235 | .word cpu_v7_reset |
| 236 | .word cpu_v7_do_idle |
| 237 | .word cpu_v7_dcache_clean_area |
| 238 | .word cpu_v7_switch_mm |
| 239 | .word cpu_v7_set_pte_ext |
| 240 | .size v7_processor_functions, . - v7_processor_functions |
| 241 | |
| 242 | .type cpu_arch_name, #object |
| 243 | cpu_arch_name: |
| 244 | .asciz "armv7" |
| 245 | .size cpu_arch_name, . - cpu_arch_name |
| 246 | |
| 247 | .type cpu_elf_name, #object |
| 248 | cpu_elf_name: |
| 249 | .asciz "v7" |
| 250 | .size cpu_elf_name, . - cpu_elf_name |
| 251 | .align |
| 252 | |
| 253 | .section ".proc.info.init", #alloc, #execinstr |
| 254 | |
| 255 | /* |
| 256 | * Match any ARMv7 processor core. |
| 257 | */ |
| 258 | .type __v7_proc_info, #object |
| 259 | __v7_proc_info: |
| 260 | .long 0x000f0000 @ Required ID value |
| 261 | .long 0x000f0000 @ Mask for ID |
| 262 | .long PMD_TYPE_SECT | \ |
| 263 | PMD_SECT_BUFFERABLE | \ |
| 264 | PMD_SECT_CACHEABLE | \ |
| 265 | PMD_SECT_AP_WRITE | \ |
| 266 | PMD_SECT_AP_READ |
| 267 | .long PMD_TYPE_SECT | \ |
| 268 | PMD_SECT_XN | \ |
| 269 | PMD_SECT_AP_WRITE | \ |
| 270 | PMD_SECT_AP_READ |
| 271 | b __v7_setup |
| 272 | .long cpu_arch_name |
| 273 | .long cpu_elf_name |
| 274 | .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP |
| 275 | .long cpu_v7_name |
| 276 | .long v7_processor_functions |
Catalin Marinas | 2ccdd1e | 2007-05-18 11:25:31 +0100 | [diff] [blame] | 277 | .long v7wbi_tlb_fns |
Catalin Marinas | bbe8888 | 2007-05-08 22:27:46 +0100 | [diff] [blame] | 278 | .long v6_user_fns |
| 279 | .long v7_cache_fns |
| 280 | .size __v7_proc_info, . - __v7_proc_info |