1 /* ----------------------------------------------------------------------------
\r
2 * SAM Software Package License
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2012, Atmel Corporation
\r
6 * All rights reserved.
\r
8 * Redistribution and use in source and binary forms, with or without
\r
9 * modification, are permitted provided that the following conditions are met:
\r
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\r
14 * Atmel's name may not be used to endorse or promote products derived from
\r
15 * this software without specific prior written permission.
\r
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
\r
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES// LOSS OF USE, DATA,
\r
23 * OR PROFITS// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
27 * ----------------------------------------------------------------------------
\r
36 * \addtogroup cp15_cache Cache Operations
\r
40 * They are performed as MCR instructions and only operate on a level 1 cache associated with
\r
42 * The supported operations are:
\r
44 * <li> Any of these operations can be applied to
\r
46 * -# any unified cache.
\r
47 * <li> Invalidate by MVA
\r
48 * Performs an invalidate of a data or unified cache line based on the address it contains.
\r
49 * <li> Invalidate by set/way
\r
50 * Performs an invalidate of a data or unified cache line based on its location in the cache hierarchy.
\r
52 * Performs a clean of a data or unified cache line based on the address it contains.
\r
53 * <li> Clean by set/way
\r
54 * Performs a clean of a data or unified cache line based on its location in the cache hierarchy.
\r
55 * <li> Clean and Invalidate by MVA
\r
56 * Performs a clean and invalidate of a data or unified cache line based on the address it contains.
\r
57 * <li> Clean and Invalidate by set/way
\r
58 * Performs a clean and invalidate of a data or unified cache line based on its location in the cache hierarchy.
\r
63 * \ref cp15_arm_iar.s \n
\r
69 //// Forward declaration of sections.
\r
70 SECTION IRQ_STACK:DATA:NOROOT(2)
\r
71 SECTION CSTACK:DATA:NOROOT(3)
\r
73 /*----------------------------------------------------------------------------
\r
75 *----------------------------------------------------------------------------*/
\r
76 #define __ASSEMBLY__
\r
79 /*----------------------------------------------------------------------------
\r
80 * Functions to access CP15 coprocessor register
\r
81 *----------------------------------------------------------------------------*/
\r
83 PUBLIC CP15_ReadControl
\r
84 PUBLIC CP15_WriteControl
\r
85 PUBLIC CP15_WriteDomainAccessControl
\r
86 PUBLIC CP15_WriteTTB
\r
87 PUBLIC CP15_InvalidateIcacheInnerSharable
\r
88 PUBLIC CP15_InvalidateBTBinnerSharable
\r
89 PUBLIC CP15_InvalidateIcache
\r
90 PUBLIC CP15_InvalidateIcacheByMva
\r
91 PUBLIC CP15_FlushBTB
\r
92 PUBLIC CP15_FlushBTBbyMva
\r
93 PUBLIC CP15_InvalidateDcacheLineByMva
\r
94 PUBLIC CP15_InvalidateDcacheLineBySetWay
\r
95 PUBLIC CP15_CleanDCacheByMva
\r
96 PUBLIC CP15_CleanDCacheBySetWay
\r
97 PUBLIC CP15_CleanDCacheMva
\r
98 PUBLIC CP15_CleanInvalidateDcacheLineByMva
\r
99 PUBLIC CP15_CleanInvalidateDcacheLine
\r
100 PUBLIC CP15_coherent_dcache_for_dma
\r
101 PUBLIC CP15_invalidate_dcache_for_dma
\r
102 PUBLIC CP15_clean_dcache_for_dma
\r
103 PUBLIC CP15_flush_dcache_for_dma
\r
104 PUBLIC CP15_flush_kern_dcache_for_dma
\r
107 * \brief Register c0 accesses the ID Register, Cache Type Register, and TCM Status Registers.
\r
108 * Reading from this register returns the device ID, the cache type, or the TCM status
\r
109 * depending on the value of Opcode_2 used.
\r
111 SECTION .CP15_ReadID:DATA:NOROOT(2)
\r
115 mrc p15, 0, r0, c0, c0, 0
\r
119 * \brief Register c1 is the Control Register for the ARM926EJ-S processor.
\r
120 * This register specifies the configuration used to enable and disable the
\r
121 * caches and MMU. It is recommended that you access this register using a
\r
122 * read-modify-write sequence
\r
124 SECTION .CP15_ReadControl:CODE:NOROOT(2)
\r
125 PUBLIC CP15_ReadControl
\r
128 mrc p15, 0, r0, c1, c0, 0
\r
131 SECTION .CP15_WriteControl:CODE:NOROOT(2)
\r
132 PUBLIC CP15_WriteControl
\r
134 mcr p15, 0, r0, c1, c0, 0
\r
145 SECTION .CP15_WriteDomainAccessControl:CODE:NOROOT(2)
\r
146 PUBLIC CP15_WriteDomainAccessControl
\r
147 CP15_WriteDomainAccessControl:
\r
148 mcr p15, 0, r0, c3, c0, 0
\r
160 * \brief ARMv7A architecture supports two translation tables
\r
161 * Configure translation table base (TTB) control register cp15,c2
\r
162 * to a value of all zeros, indicates we are using TTB register 0.
\r
163 * write the address of our page table base to TTB register 0.
\r
165 SECTION .CP15_WriteTTB:CODE:NOROOT(2)
\r
166 PUBLIC CP15_WriteTTB
\r
168 mcr p15, 0, r0, c2, c0, 0
\r
180 * \brief Invalidate I cache predictor array inner Sharable
\r
182 SECTION .CP15_InvalidateIcacheInnerSharable:CODE:NOROOT(2)
\r
183 PUBLIC CP15_InvalidateIcacheInnerSharable
\r
184 CP15_InvalidateIcacheInnerSharable:
\r
186 mcr p15, 0, r0, c7, c1, 0
\r
190 * \brief Invalidate entire branch predictor array inner Sharable
\r
192 SECTION .CP15_InvalidateBTBinnerSharable:CODE:NOROOT(2)
\r
193 PUBLIC CP15_InvalidateBTBinnerSharable
\r
194 CP15_InvalidateBTBinnerSharable:
\r
196 mcr p15, 0, r0, c7, c1, 6
\r
200 * \brief Invalidate all instruction caches to PoU, also flushes branch target cache
\r
202 SECTION .CP15_InvalidateIcache:CODE:NOROOT(2)
\r
203 PUBLIC CP15_InvalidateIcache
\r
204 CP15_InvalidateIcache:
\r
206 mcr p15, 0, r0, c7, c5, 0
\r
210 * \brief Invalidate instruction caches by VA to PoU
\r
212 SECTION .CP15_InvalidateIcacheByMva:CODE:NOROOT(2)
\r
213 PUBLIC CP15_InvalidateIcacheByMva
\r
214 CP15_InvalidateIcacheByMva:
\r
216 mcr p15, 0, r0, c7, c5, 1
\r
220 * \brief Flush entire branch predictor array
\r
222 SECTION .CP15_FlushBTB:CODE:NOROOT(2)
\r
223 PUBLIC CP15_FlushBTB
\r
226 mcr p15, 0, r0, c7, c5, 6
\r
230 * \brief Flush branch predictor array entry by MVA
\r
232 SECTION .CP15_FlushBTBbyMva:CODE:NOROOT(2)
\r
233 PUBLIC CP15_FlushBTBbyMva
\r
234 CP15_FlushBTBbyMva:
\r
236 mcr p15, 0, r0, c7, c5, 7
\r
240 * \brief Invalidate data cache line by VA to Poc
\r
242 SECTION .CP15_InvalidateDcacheLineByMva:CODE:NOROOT(2)
\r
243 PUBLIC CP15_InvalidateDcacheLineByMva
\r
244 CP15_InvalidateDcacheLineByMva:
\r
246 mcr p15, 0, r0, c7, c6, 1
\r
250 * \brief Invalidate data cache line by set/way
\r
252 SECTION .CP15_InvalidateDcacheLineBySetWay:CODE:NOROOT(2)
\r
253 PUBLIC CP15_InvalidateDcacheLineBySetWay
\r
254 CP15_InvalidateDcacheLineBySetWay:
\r
256 mcr p15, 0, r0, c7, c6, 2
\r
260 * \brief Clean data cache line by MVA
\r
262 SECTION .CP15_CleanDCacheByMva:CODE:NOROOT(2)
\r
263 PUBLIC CP15_CleanDCacheByMva
\r
264 CP15_CleanDCacheByMva:
\r
266 mcr p15, 0, r0, c7, c10, 1
\r
270 * \brief Clean data cache line by Set/way
\r
272 SECTION .CP15_CleanDCacheBySetWay:CODE:NOROOT(2)
\r
273 PUBLIC CP15_CleanDCacheBySetWay
\r
274 CP15_CleanDCacheBySetWay:
\r
276 mcr p15, 0, r0, c7, c10, 2
\r
280 * \brief Clean unified cache line by MVA
\r
282 SECTION .CP15_CleanDCacheMva:CODE:NOROOT(2)
\r
283 PUBLIC CP15_CleanDCacheMva
\r
284 CP15_CleanDCacheMva:
\r
286 mcr p15, 0, r0, c7, c11, 1
\r
290 * \brief Clean and invalidate data cache line by VA to PoC
\r
292 SECTION .CP15_CleanInvalidateDcacheLineByMva:CODE:NOROOT(2)
\r
293 PUBLIC CP15_CleanInvalidateDcacheLineByMva
\r
294 CP15_CleanInvalidateDcacheLineByMva:
\r
296 mcr p15, 0, r0, c7, c14, 1
\r
300 * \brief Clean and Incalidate data cache line by Set/Way
\r
302 SECTION .CP15_CleanInvalidateDcacheLine:CODE:NOROOT(2)
\r
303 PUBLIC CP15_CleanInvalidateDcacheLine
\r
304 CP15_CleanInvalidateDcacheLine:
\r
306 mcr p15, 0, r0, c7, c14, 2
\r
310 * \brief Ensure that the I and D caches are coherent within specified
\r
311 * region. This is typically used when code has been written to
\r
312 * a memory region, and will be executed.
\r
313 * \param start virtual start address of region
\r
314 * \param end virtual end address of region
\r
316 SECTION .CP15_coherent_dcache_for_dma:CODE:NOROOT(2)
\r
317 PUBLIC CP15_coherent_dcache_for_dma
\r
318 CP15_coherent_dcache_for_dma:
\r
319 // dcache_line_size r2, r3
\r
321 mrc p15, 0, r3, c0, c0, 1 // read ctr
\r
323 and r3, r3, #0xf // cache line size encoding
\r
324 mov r2, #4 // bytes per word
\r
325 mov r2, r2, lsl r3 // actual cache line size
\r
330 mcr p15, 0, r12, c7, c11, 1 // clean D line to the point of unification
\r
336 // .macro icache_line_size, reg, tmp
\r
337 mrc p15, 0, r3, c0, c0, 1 // read ctr
\r
338 and r3, r3, #0xf // cache line size encoding
\r
339 mov r2, #4 // bytes per word
\r
340 mov r2, r2, lsl r3 // actual cache line size
\r
345 mcr p15, 0, r12, c7, c5, 1 // invalidate I line
\r
350 mcr p15, 0, r0, c7, c1, 6 //invalidate BTB Inner Shareable
\r
351 mcr p15, 0, r0, c7, c5, 6 // invalidate BTB
\r
358 * \brief Invalidate the data cache within the specified region; we will
\r
359 * be performing a DMA operation in this region and we want to
\r
360 * purge old data in the cache.
\r
361 * \param start virtual start address of region
\r
362 * \param end virtual end address of region
\r
364 SECTION .CP15_invalidate_dcache_for_dma:CODE:NOROOT(2)
\r
365 PUBLIC CP15_invalidate_dcache_for_dma
\r
366 CP15_invalidate_dcache_for_dma:
\r
368 // dcache_line_size r2, r3
\r
369 mrc p15, 0, r3, c0, c0, 1 // read ctr
\r
371 and r3, r3, #0xf // cache line size encoding
\r
372 mov r2, #4 // bytes per word
\r
373 mov r2, r2, lsl r3 // actual cache line size
\r
379 mcrne p15, 0, r0, c7, c14, 1 // clean & invalidate D / U line
\r
383 mcrne p15, 0, r1, c7, c14, 1 // clean & invalidate D / U line
\r
385 mcr p15, 0, r0, c7, c6, 1 // invalidate D / U line
\r
394 * \brief Clean the data cache within the specified region
\r
395 * \param start virtual start address of region
\r
396 * \param end virtual end address of region
\r
398 SECTION .CP15_clean_dcache_for_dma:CODE:NOROOT(2)
\r
399 PUBLIC CP15_clean_dcache_for_dma
\r
400 CP15_clean_dcache_for_dma:
\r
401 // dcache_line_size r2, r3
\r
402 mrc p15, 0, r3, c0, c0, 1 // read ctr
\r
404 and r3, r3, #0xf // cache line size encoding
\r
405 mov r2, #4 // bytes per word
\r
406 mov r2, r2, lsl r3 // actual cache line size
\r
411 mcr p15, 0, r0, c7, c10, 1 // clean D / U line
\r
420 * \brief Flush the data cache within the specified region
\r
421 * \param start virtual start address of region
\r
422 * \param end virtual end address of region
\r
424 SECTION .CP15_flush_dcache_for_dma:CODE:NOROOT(2)
\r
425 PUBLIC CP15_flush_dcache_for_dma
\r
426 CP15_flush_dcache_for_dma:
\r
427 // dcache_line_size r2, r3
\r
428 mrc p15, 0, r3, c0, c0, 1 // read ctr
\r
430 and r3, r3, #0xf // cache line size encoding
\r
431 mov r2, #4 // bytes per word
\r
432 mov r2, r2, lsl r3 // actual cache line size
\r
436 mcr p15, 0, r0, c7, c14, 1 // clean & invalidate D / U line
\r
445 * \brief CP15_flush_kern_dcache_for_dma
\r
446 * Ensure that the data held in the page kaddr is written back to the page in question.
\r
447 * \param start virtual start address of region
\r
448 * \param end virtual end address of region
\r
450 SECTION .CP15_flush_kern_dcache_for_dma:CODE:NOROOT(2)
\r
451 PUBLIC CP15_flush_kern_dcache_for_dma
\r
452 CP15_flush_kern_dcache_for_dma:
\r
453 // dcache_line_size r2, r3
\r
454 mrc p15, 0, r3, c0, c0, 1 // read ctr
\r
456 and r3, r3, #0xf // cache line size encoding
\r
457 mov r2, #4 // bytes per word
\r
458 mov r2, r2, lsl r3 // actual cache line size
\r
464 mcr p15, 0, r0, c7, c14, 1 // clean & invalidate D line / unified line
\r