···11+#include <linux/linkage.h>22+#include <asm/assembler.h>33+/*44+ * Function: v7_early_abort55+ *66+ * Params : r2 = address of aborted instruction77+ * : r3 = saved SPSR88+ *99+ * Returns : r0 = address of abort1010+ * : r1 = FSR, bit 11 = write1111+ * : r2-r8 = corrupted1212+ * : r9 = preserved1313+ * : sp = pointer to registers1414+ *1515+ * Purpose : obtain information about current aborted instruction.1616+ */1717+ .align 51818+ENTRY(v7_early_abort)1919+ /*2020+ * The effect of data aborts on on the exclusive access monitor are2121+ * UNPREDICTABLE. Do a CLREX to clear the state2222+ */2323+ clrex2424+2525+ mrc p15, 0, r1, c5, c0, 0 @ get FSR2626+ mrc p15, 0, r0, c6, c0, 0 @ get FAR2727+2828+ /*2929+ * V6 code adjusts the returned DFSR.3030+ * New designs should not need to patch up faults.3131+ */3232+ mov pc, lr
+253
arch/arm/mm/cache-v7.S
···11+/*22+ * linux/arch/arm/mm/cache-v7.S33+ *44+ * Copyright (C) 2001 Deep Blue Solutions Ltd.55+ * Copyright (C) 2005 ARM Ltd.66+ *77+ * This program is free software; you can redistribute it and/or modify88+ * it under the terms of the GNU General Public License version 2 as99+ * published by the Free Software Foundation.1010+ *1111+ * This is the "shell" of the ARMv7 processor support.1212+ */1313+#include <linux/linkage.h>1414+#include <linux/init.h>1515+#include <asm/assembler.h>1616+1717+#include "proc-macros.S"1818+1919+/*2020+ * v7_flush_dcache_all()2121+ *2222+ * Flush the whole D-cache.2323+ *2424+ * Corrupted registers: r0-r5, r7, r9-r112525+ *2626+ * - mm - mm_struct describing address space2727+ */2828+ENTRY(v7_flush_dcache_all)2929+ mrc p15, 1, r0, c0, c0, 1 @ read clidr3030+ ands r3, r0, #0x7000000 @ extract loc from clidr3131+ mov r3, r3, lsr #23 @ left align loc bit field3232+ beq finished @ if loc is 0, then no need to clean3333+ mov r10, #0 @ start clean at cache level 03434+loop1:3535+ add r2, r10, r10, lsr #1 @ work out 3x current cache level3636+ mov r1, r0, lsr r2 @ extract cache type bits from clidr3737+ and r1, r1, #7 @ mask of the bits for current cache only3838+ cmp r1, #2 @ see what cache we have at this level3939+ blt skip @ skip if no cache, or just i-cache4040+ mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr4141+ isb @ isb to sych the new cssr&csidr4242+ mrc p15, 1, r1, c0, c0, 0 @ read the new csidr4343+ and r2, r1, #7 @ extract the length of the cache lines4444+ add r2, r2, #4 @ add 4 (line length offset)4545+ ldr r4, =0x3ff4646+ ands r4, r4, r1, lsr #3 @ find maximum number on the way size4747+ clz r5, r4 @ find bit position of way size increment4848+ ldr r7, =0x7fff4949+ ands r7, r7, r1, lsr #13 @ extract max number of the index size5050+loop2:5151+ mov r9, r4 @ create working copy of max way size5252+loop3:5353+ orr r11, r10, r9, lsl r5 @ factor way and cache number into r115454+ orr r11, r11, r7, lsl r2 @ factor index number into r115555+ mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way5656+ subs r9, r9, #1 @ decrement the way5757+ bge loop35858+ subs r7, r7, #1 @ decrement the index5959+ bge loop26060+skip:6161+ add r10, r10, #2 @ increment cache number6262+ cmp r3, r106363+ bgt loop16464+finished:6565+ mov r10, #0 @ swith back to cache level 06666+ mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr6767+ isb6868+ mov pc, lr6969+7070+/*7171+ * v7_flush_cache_all()7272+ *7373+ * Flush the entire cache system.7474+ * The data cache flush is now achieved using atomic clean / invalidates7575+ * working outwards from L1 cache. This is done using Set/Way based cache7676+ * maintainance instructions.7777+ * The instruction cache can still be invalidated back to the point of7878+ * unification in a single instruction.7979+ *8080+ */8181+ENTRY(v7_flush_kern_cache_all)8282+ stmfd sp!, {r4-r5, r7, r9-r11, lr}8383+ bl v7_flush_dcache_all8484+ mov r0, #08585+ mcr p15, 0, r0, c7, c5, 0 @ I+BTB cache invalidate8686+ ldmfd sp!, {r4-r5, r7, r9-r11, lr}8787+ mov pc, lr8888+8989+/*9090+ * v7_flush_cache_all()9191+ *9292+ * Flush all TLB entries in a particular address space9393+ *9494+ * - mm - mm_struct describing address space9595+ */9696+ENTRY(v7_flush_user_cache_all)9797+ /*FALLTHROUGH*/9898+9999+/*100100+ * v7_flush_cache_range(start, end, flags)101101+ *102102+ * Flush a range of TLB entries in the specified address space.103103+ *104104+ * - start - start address (may not be aligned)105105+ * - end - end address (exclusive, may not be aligned)106106+ * - flags - vm_area_struct flags describing address space107107+ *108108+ * It is assumed that:109109+ * - we have a VIPT cache.110110+ */111111+ENTRY(v7_flush_user_cache_range)112112+ mov pc, lr113113+114114+/*115115+ * v7_coherent_kern_range(start,end)116116+ *117117+ * Ensure that the I and D caches are coherent within specified118118+ * region. This is typically used when code has been written to119119+ * a memory region, and will be executed.120120+ *121121+ * - start - virtual start address of region122122+ * - end - virtual end address of region123123+ *124124+ * It is assumed that:125125+ * - the Icache does not read data from the write buffer126126+ */127127+ENTRY(v7_coherent_kern_range)128128+ /* FALLTHROUGH */129129+130130+/*131131+ * v7_coherent_user_range(start,end)132132+ *133133+ * Ensure that the I and D caches are coherent within specified134134+ * region. This is typically used when code has been written to135135+ * a memory region, and will be executed.136136+ *137137+ * - start - virtual start address of region138138+ * - end - virtual end address of region139139+ *140140+ * It is assumed that:141141+ * - the Icache does not read data from the write buffer142142+ */143143+ENTRY(v7_coherent_user_range)144144+ dcache_line_size r2, r3145145+ sub r3, r2, #1146146+ bic r0, r0, r3147147+1: mcr p15, 0, r0, c7, c11, 1 @ clean D line to the point of unification148148+ dsb149149+ mcr p15, 0, r0, c7, c5, 1 @ invalidate I line150150+ add r0, r0, r2151151+ cmp r0, r1152152+ blo 1b153153+ mov r0, #0154154+ mcr p15, 0, r0, c7, c5, 6 @ invalidate BTB155155+ dsb156156+ isb157157+ mov pc, lr158158+159159+/*160160+ * v7_flush_kern_dcache_page(kaddr)161161+ *162162+ * Ensure that the data held in the page kaddr is written back163163+ * to the page in question.164164+ *165165+ * - kaddr - kernel address (guaranteed to be page aligned)166166+ */167167+ENTRY(v7_flush_kern_dcache_page)168168+ dcache_line_size r2, r3169169+ add r1, r0, #PAGE_SZ170170+1:171171+ mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line / unified line172172+ add r0, r0, r2173173+ cmp r0, r1174174+ blo 1b175175+ dsb176176+ mov pc, lr177177+178178+/*179179+ * v7_dma_inv_range(start,end)180180+ *181181+ * Invalidate the data cache within the specified region; we will182182+ * be performing a DMA operation in this region and we want to183183+ * purge old data in the cache.184184+ *185185+ * - start - virtual start address of region186186+ * - end - virtual end address of region187187+ */188188+ENTRY(v7_dma_inv_range)189189+ dcache_line_size r2, r3190190+ sub r3, r2, #1191191+ tst r0, r3192192+ bic r0, r0, r3193193+ mcrne p15, 0, r0, c7, c14, 1 @ clean & invalidate D / U line194194+195195+ tst r1, r3196196+ bic r1, r1, r3197197+ mcrne p15, 0, r1, c7, c14, 1 @ clean & invalidate D / U line198198+1:199199+ mcr p15, 0, r0, c7, c6, 1 @ invalidate D / U line200200+ add r0, r0, r2201201+ cmp r0, r1202202+ blo 1b203203+ dsb204204+ mov pc, lr205205+206206+/*207207+ * v7_dma_clean_range(start,end)208208+ * - start - virtual start address of region209209+ * - end - virtual end address of region210210+ */211211+ENTRY(v7_dma_clean_range)212212+ dcache_line_size r2, r3213213+ sub r3, r2, #1214214+ bic r0, r0, r3215215+1:216216+ mcr p15, 0, r0, c7, c10, 1 @ clean D / U line217217+ add r0, r0, r2218218+ cmp r0, r1219219+ blo 1b220220+ dsb221221+ mov pc, lr222222+223223+/*224224+ * v7_dma_flush_range(start,end)225225+ * - start - virtual start address of region226226+ * - end - virtual end address of region227227+ */228228+ENTRY(v7_dma_flush_range)229229+ dcache_line_size r2, r3230230+ sub r3, r2, #1231231+ bic r0, r0, r3232232+1:233233+ mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D / U line234234+ add r0, r0, r2235235+ cmp r0, r1236236+ blo 1b237237+ dsb238238+ mov pc, lr239239+240240+ __INITDATA241241+242242+ .type v7_cache_fns, #object243243+ENTRY(v7_cache_fns)244244+ .long v7_flush_kern_cache_all245245+ .long v7_flush_user_cache_all246246+ .long v7_flush_user_cache_range247247+ .long v7_coherent_kern_range248248+ .long v7_coherent_user_range249249+ .long v7_flush_kern_dcache_page250250+ .long v7_dma_inv_range251251+ .long v7_dma_clean_range252252+ .long v7_dma_flush_range253253+ .size v7_cache_fns, . - v7_cache_fns
+12
arch/arm/mm/proc-macros.S
···5959 .word \ucset6060#endif6161 .endm6262+6363+/*6464+ * cache_line_size - get the cache line size from the CSIDR register6565+ * (available on ARMv7+). It assumes that the CSSR register was configured6666+ * to access the L1 data cache CSIDR.6767+ */6868+ .macro dcache_line_size, reg, tmp6969+ mrc p15, 1, \tmp, c0, c0, 0 @ read CSIDR7070+ and \tmp, \tmp, #7 @ cache line size encoding7171+ mov \reg, #16 @ size offset7272+ mov \reg, \reg, lsl \tmp @ actual cache line size7373+ .endm
+262
arch/arm/mm/proc-v7.S
···11+/*22+ * linux/arch/arm/mm/proc-v7.S33+ *44+ * Copyright (C) 2001 Deep Blue Solutions Ltd.55+ *66+ * This program is free software; you can redistribute it and/or modify77+ * it under the terms of the GNU General Public License version 2 as88+ * published by the Free Software Foundation.99+ *1010+ * This is the "shell" of the ARMv7 processor support.1111+ */1212+#include <linux/linkage.h>1313+#include <asm/assembler.h>1414+#include <asm/asm-offsets.h>1515+#include <asm/elf.h>1616+#include <asm/pgtable-hwdef.h>1717+#include <asm/pgtable.h>1818+1919+#include "proc-macros.S"2020+2121+#define TTB_C (1 << 0)2222+#define TTB_S (1 << 1)2323+#define TTB_RGN_OC_WT (2 << 3)2424+#define TTB_RGN_OC_WB (3 << 3)2525+2626+ENTRY(cpu_v7_proc_init)2727+ mov pc, lr2828+2929+ENTRY(cpu_v7_proc_fin)3030+ mov pc, lr3131+3232+/*3333+ * cpu_v7_reset(loc)3434+ *3535+ * Perform a soft reset of the system. Put the CPU into the3636+ * same state as it would be if it had been reset, and branch3737+ * to what would be the reset vector.3838+ *3939+ * - loc - location to jump to for soft reset4040+ *4141+ * It is assumed that:4242+ */4343+ .align 54444+ENTRY(cpu_v7_reset)4545+ mov pc, r04646+4747+/*4848+ * cpu_v7_do_idle()4949+ *5050+ * Idle the processor (eg, wait for interrupt).5151+ *5252+ * IRQs are already disabled.5353+ */5454+ENTRY(cpu_v7_do_idle)5555+ .long 0xe320f003 @ ARM V7 WFI instruction5656+ mov pc, lr5757+5858+ENTRY(cpu_v7_dcache_clean_area)5959+#ifndef TLB_CAN_READ_FROM_L1_CACHE6060+ dcache_line_size r2, r36161+1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry6262+ add r0, r0, r26363+ subs r1, r1, r26464+ bhi 1b6565+ dsb6666+#endif6767+ mov pc, lr6868+6969+/*7070+ * cpu_v7_switch_mm(pgd_phys, tsk)7171+ *7272+ * Set the translation table base pointer to be pgd_phys7373+ *7474+ * - pgd_phys - physical address of new TTB7575+ *7676+ * It is assumed that:7777+ * - we are not using split page tables7878+ */7979+ENTRY(cpu_v7_switch_mm)8080+ mov r2, #08181+ ldr r1, [r1, #MM_CONTEXT_ID] @ get mm->context.id8282+ orr r0, r0, #TTB_RGN_OC_WB @ mark PTWs outer cacheable, WB8383+ mcr p15, 0, r2, c13, c0, 1 @ set reserved context ID8484+ isb8585+1: mcr p15, 0, r0, c2, c0, 0 @ set TTB 08686+ isb8787+ mcr p15, 0, r1, c13, c0, 1 @ set context ID8888+ isb8989+ mov pc, lr9090+9191+/*9292+ * cpu_v7_set_pte_ext(ptep, pte)9393+ *9494+ * Set a level 2 translation table entry.9595+ *9696+ * - ptep - pointer to level 2 translation table entry9797+ * (hardware version is stored at -1024 bytes)9898+ * - pte - PTE value to store9999+ * - ext - value for extended PTE bits100100+ *101101+ * Permissions:102102+ * YUWD APX AP1 AP0 SVC User103103+ * 0xxx 0 0 0 no acc no acc104104+ * 100x 1 0 1 r/o no acc105105+ * 10x0 1 0 1 r/o no acc106106+ * 1011 0 0 1 r/w no acc107107+ * 110x 0 1 0 r/w r/o108108+ * 11x0 0 1 0 r/w r/o109109+ * 1111 0 1 1 r/w r/w110110+ */111111+ENTRY(cpu_v7_set_pte_ext)112112+ str r1, [r0], #-2048 @ linux version113113+114114+ bic r3, r1, #0x000003f0115115+ bic r3, r3, #0x00000003116116+ orr r3, r3, r2117117+ orr r3, r3, #PTE_EXT_AP0 | 2118118+119119+ tst r1, #L_PTE_WRITE120120+ tstne r1, #L_PTE_DIRTY121121+ orreq r3, r3, #PTE_EXT_APX122122+123123+ tst r1, #L_PTE_USER124124+ orrne r3, r3, #PTE_EXT_AP1125125+ tstne r3, #PTE_EXT_APX126126+ bicne r3, r3, #PTE_EXT_APX | PTE_EXT_AP0127127+128128+ tst r1, #L_PTE_YOUNG129129+ biceq r3, r3, #PTE_EXT_APX | PTE_EXT_AP_MASK130130+131131+ tst r1, #L_PTE_EXEC132132+ orreq r3, r3, #PTE_EXT_XN133133+134134+ tst r1, #L_PTE_PRESENT135135+ moveq r3, #0136136+137137+ str r3, [r0]138138+ mcr p15, 0, r0, c7, c10, 1 @ flush_pte139139+ mov pc, lr140140+141141+cpu_v7_name:142142+ .ascii "ARMv7 Processor"143143+ .align144144+145145+ .section ".text.init", #alloc, #execinstr146146+147147+/*148148+ * __v7_setup149149+ *150150+ * Initialise TLB, Caches, and MMU state ready to switch the MMU151151+ * on. Return in r0 the new CP15 C1 control register setting.152152+ *153153+ * We automatically detect if we have a Harvard cache, and use the154154+ * Harvard cache control instructions insead of the unified cache155155+ * control instructions.156156+ *157157+ * This should be able to cover all ARMv7 cores.158158+ *159159+ * It is assumed that:160160+ * - cache type register is implemented161161+ */162162+__v7_setup:163163+ adr r12, __v7_setup_stack @ the local stack164164+ stmia r12, {r0-r5, r7, r9, r11, lr}165165+ bl v7_flush_dcache_all166166+ ldmia r12, {r0-r5, r7, r9, r11, lr}167167+ mov r10, #0168168+#ifdef HARVARD_CACHE169169+ mcr p15, 0, r10, c7, c5, 0 @ I+BTB cache invalidate170170+#endif171171+ dsb172172+ mcr p15, 0, r10, c8, c7, 0 @ invalidate I + D TLBs173173+ mcr p15, 0, r10, c2, c0, 2 @ TTB control register174174+ orr r4, r4, #TTB_RGN_OC_WB @ mark PTWs outer cacheable, WB175175+ mcr p15, 0, r4, c2, c0, 0 @ load TTB0176176+ mcr p15, 0, r4, c2, c0, 1 @ load TTB1177177+ mov r10, #0x1f @ domains 0, 1 = manager178178+ mcr p15, 0, r10, c3, c0, 0 @ load domain access register179179+#ifndef CONFIG_CPU_L2CACHE_DISABLE180180+ @ L2 cache configuration in the L2 aux control register181181+ mrc p15, 1, r10, c9, c0, 2182182+ bic r10, r10, #(1 << 16) @ L2 outer cache183183+ mcr p15, 1, r10, c9, c0, 2184184+ @ L2 cache is enabled in the aux control register185185+ mrc p15, 0, r10, c1, c0, 1186186+ orr r10, r10, #2187187+ mcr p15, 0, r10, c1, c0, 1188188+#endif189189+ mrc p15, 0, r0, c1, c0, 0 @ read control register190190+ ldr r10, cr1_clear @ get mask for bits to clear191191+ bic r0, r0, r10 @ clear bits them192192+ ldr r10, cr1_set @ get mask for bits to set193193+ orr r0, r0, r10 @ set them194194+ mov pc, lr @ return to head.S:__ret195195+196196+ /*197197+ * V X F I D LR198198+ * .... ...E PUI. .T.T 4RVI ZFRS BLDP WCAM199199+ * rrrr rrrx xxx0 0101 xxxx xxxx x111 xxxx < forced200200+ * 0 110 0011 1.00 .111 1101 < we want201201+ */202202+ .type cr1_clear, #object203203+ .type cr1_set, #object204204+cr1_clear:205205+ .word 0x0120c302206206+cr1_set:207207+ .word 0x00c0387d208208+209209+__v7_setup_stack:210210+ .space 4 * 11 @ 11 registers211211+212212+ .type v7_processor_functions, #object213213+ENTRY(v7_processor_functions)214214+ .word v7_early_abort215215+ .word cpu_v7_proc_init216216+ .word cpu_v7_proc_fin217217+ .word cpu_v7_reset218218+ .word cpu_v7_do_idle219219+ .word cpu_v7_dcache_clean_area220220+ .word cpu_v7_switch_mm221221+ .word cpu_v7_set_pte_ext222222+ .size v7_processor_functions, . - v7_processor_functions223223+224224+ .type cpu_arch_name, #object225225+cpu_arch_name:226226+ .asciz "armv7"227227+ .size cpu_arch_name, . - cpu_arch_name228228+229229+ .type cpu_elf_name, #object230230+cpu_elf_name:231231+ .asciz "v7"232232+ .size cpu_elf_name, . - cpu_elf_name233233+ .align234234+235235+ .section ".proc.info.init", #alloc, #execinstr236236+237237+ /*238238+ * Match any ARMv7 processor core.239239+ */240240+ .type __v7_proc_info, #object241241+__v7_proc_info:242242+ .long 0x000f0000 @ Required ID value243243+ .long 0x000f0000 @ Mask for ID244244+ .long PMD_TYPE_SECT | \245245+ PMD_SECT_BUFFERABLE | \246246+ PMD_SECT_CACHEABLE | \247247+ PMD_SECT_AP_WRITE | \248248+ PMD_SECT_AP_READ249249+ .long PMD_TYPE_SECT | \250250+ PMD_SECT_XN | \251251+ PMD_SECT_AP_WRITE | \252252+ PMD_SECT_AP_READ253253+ b __v7_setup254254+ .long cpu_arch_name255255+ .long cpu_elf_name256256+ .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP257257+ .long cpu_v7_name258258+ .long v7_processor_functions259259+ .long v6wbi_tlb_fns260260+ .long v6_user_fns261261+ .long v7_cache_fns262262+ .size __v7_proc_info, . - __v7_proc_info