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
78 /*----------------------------------------------------------------------------
\r
79 * Functions to access CP15 coprocessor register
\r
80 *----------------------------------------------------------------------------*/
\r
82 PUBLIC CP15_ReadControl
\r
83 PUBLIC CP15_WriteControl
\r
84 PUBLIC CP15_WriteDomainAccessControl
\r
85 PUBLIC CP15_WriteTTB
\r
86 PUBLIC CP15_InvalidateIcacheInnerSharable
\r
87 PUBLIC CP15_InvalidateBTBinnerSharable
\r
88 PUBLIC CP15_InvalidateIcache
\r
89 PUBLIC CP15_InvalidateIcacheByMva
\r
90 PUBLIC CP15_FlushBTB
\r
91 PUBLIC CP15_FlushBTBbyMva
\r
92 PUBLIC CP15_InvalidateDcacheLineByMva
\r
93 PUBLIC CP15_InvalidateDcacheLineBySetWay
\r
94 PUBLIC CP15_CleanDCacheByMva
\r
95 PUBLIC CP15_CleanDCacheBySetWay
\r
96 PUBLIC CP15_CleanDCacheMva
\r
97 PUBLIC CP15_CleanInvalidateDcacheLineByMva
\r
98 PUBLIC CP15_CleanInvalidateDcacheLine
\r
99 PUBLIC CP15_coherent_dcache_for_dma
\r
100 PUBLIC CP15_invalidate_dcache_for_dma
\r
101 PUBLIC CP15_clean_dcache_for_dma
\r
102 PUBLIC CP15_flush_dcache_for_dma
\r
103 PUBLIC CP15_flush_kern_dcache_for_dma
\r
106 * \brief Register c0 accesses the ID Register, Cache Type Register, and TCM Status Registers.
\r
107 * Reading from this register returns the device ID, the cache type, or the TCM status
\r
108 * depending on the value of Opcode_2 used.
\r
110 SECTION .CP15_ReadID:DATA:NOROOT(2)
\r
114 mrc p15, 0, r0, c0, c0, 0
\r
118 * \brief Register c1 is the Control Register for the ARM926EJ-S processor.
\r
119 * This register specifies the configuration used to enable and disable the
\r
120 * caches and MMU. It is recommended that you access this register using a
\r
121 * read-modify-write sequence
\r
123 SECTION .CP15_ReadControl:CODE:NOROOT(2)
\r
124 PUBLIC CP15_ReadControl
\r
127 mrc p15, 0, r0, c1, c0, 0
\r
130 SECTION .CP15_WriteControl:CODE:NOROOT(2)
\r
131 PUBLIC CP15_WriteControl
\r
133 mcr p15, 0, r0, c1, c0, 0
\r
144 SECTION .CP15_WriteDomainAccessControl:CODE:NOROOT(2)
\r
145 PUBLIC CP15_WriteDomainAccessControl
\r
146 CP15_WriteDomainAccessControl:
\r
147 mcr p15, 0, r0, c3, c0, 0
\r
159 * \brief ARMv7A architecture supports two translation tables
\r
160 * Configure translation table base (TTB) control register cp15,c2
\r
161 * to a value of all zeros, indicates we are using TTB register 0.
\r
162 * write the address of our page table base to TTB register 0.
\r
164 SECTION .CP15_WriteTTB:CODE:NOROOT(2)
\r
165 PUBLIC CP15_WriteTTB
\r
167 mcr p15, 0, r0, c2, c0, 0
\r
179 * \brief Invalidate I cache predictor array inner Sharable
\r
181 SECTION .CP15_InvalidateIcacheInnerSharable:CODE:NOROOT(2)
\r
182 PUBLIC CP15_InvalidateIcacheInnerSharable
\r
183 CP15_InvalidateIcacheInnerSharable:
\r
185 mcr p15, 0, r0, c7, c1, 0
\r
189 * \brief Invalidate entire branch predictor array inner Sharable
\r
191 SECTION .CP15_InvalidateBTBinnerSharable:CODE:NOROOT(2)
\r
192 PUBLIC CP15_InvalidateBTBinnerSharable
\r
193 CP15_InvalidateBTBinnerSharable:
\r
195 mcr p15, 0, r0, c7, c1, 6
\r
199 * \brief Invalidate all instruction caches to PoU, also flushes branch target cache
\r
201 SECTION .CP15_InvalidateIcache:CODE:NOROOT(2)
\r
202 PUBLIC CP15_InvalidateIcache
\r
203 CP15_InvalidateIcache:
\r
205 mcr p15, 0, r0, c7, c5, 0
\r
209 * \brief Invalidate instruction caches by VA to PoU
\r
211 SECTION .CP15_InvalidateIcacheByMva:CODE:NOROOT(2)
\r
212 PUBLIC CP15_InvalidateIcacheByMva
\r
213 CP15_InvalidateIcacheByMva:
\r
215 mcr p15, 0, r0, c7, c5, 1
\r
219 * \brief Flush entire branch predictor array
\r
221 SECTION .CP15_FlushBTB:CODE:NOROOT(2)
\r
222 PUBLIC CP15_FlushBTB
\r
225 mcr p15, 0, r0, c7, c5, 6
\r
229 * \brief Flush branch predictor array entry by MVA
\r
231 SECTION .CP15_FlushBTBbyMva:CODE:NOROOT(2)
\r
232 PUBLIC CP15_FlushBTBbyMva
\r
233 CP15_FlushBTBbyMva:
\r
235 mcr p15, 0, r0, c7, c5, 7
\r
239 * \brief Invalidate data cache line by VA to Poc
\r
241 SECTION .CP15_InvalidateDcacheLineByMva:CODE:NOROOT(2)
\r
242 PUBLIC CP15_InvalidateDcacheLineByMva
\r
243 CP15_InvalidateDcacheLineByMva:
\r
245 mcr p15, 0, r0, c7, c6, 1
\r
249 * \brief Invalidate data cache line by set/way
\r
251 SECTION .CP15_InvalidateDcacheLineBySetWay:CODE:NOROOT(2)
\r
252 PUBLIC CP15_InvalidateDcacheLineBySetWay
\r
253 CP15_InvalidateDcacheLineBySetWay:
\r
255 mcr p15, 0, r0, c7, c6, 2
\r
259 * \brief Clean data cache line by MVA
\r
261 SECTION .CP15_CleanDCacheByMva:CODE:NOROOT(2)
\r
262 PUBLIC CP15_CleanDCacheByMva
\r
263 CP15_CleanDCacheByMva:
\r
265 mcr p15, 0, r0, c7, c10, 1
\r
269 * \brief Clean data cache line by Set/way
\r
271 SECTION .CP15_CleanDCacheBySetWay:CODE:NOROOT(2)
\r
272 PUBLIC CP15_CleanDCacheBySetWay
\r
273 CP15_CleanDCacheBySetWay:
\r
275 mcr p15, 0, r0, c7, c10, 2
\r
279 * \brief Clean unified cache line by MVA
\r
281 SECTION .CP15_CleanDCacheMva:CODE:NOROOT(2)
\r
282 PUBLIC CP15_CleanDCacheMva
\r
283 CP15_CleanDCacheMva:
\r
285 mcr p15, 0, r0, c7, c11, 1
\r
289 * \brief Clean and invalidate data cache line by VA to PoC
\r
291 SECTION .CP15_CleanInvalidateDcacheLineByMva:CODE:NOROOT(2)
\r
292 PUBLIC CP15_CleanInvalidateDcacheLineByMva
\r
293 CP15_CleanInvalidateDcacheLineByMva:
\r
295 mcr p15, 0, r0, c7, c14, 1
\r
299 * \brief Clean and Incalidate data cache line by Set/Way
\r
301 SECTION .CP15_CleanInvalidateDcacheLine:CODE:NOROOT(2)
\r
302 PUBLIC CP15_CleanInvalidateDcacheLine
\r
303 CP15_CleanInvalidateDcacheLine:
\r
305 mcr p15, 0, r0, c7, c14, 2
\r
309 * \brief Ensure that the I and D caches are coherent within specified
\r
310 * region. This is typically used when code has been written to
\r
311 * a memory region, and will be executed.
\r
312 * \param start virtual start address of region
\r
313 * \param end virtual end address of region
\r
315 SECTION .CP15_coherent_dcache_for_dma:CODE:NOROOT(2)
\r
316 PUBLIC CP15_coherent_dcache_for_dma
\r
317 CP15_coherent_dcache_for_dma:
\r
318 // dcache_line_size r2, r3
\r
320 mrc p15, 0, r3, c0, c0, 1 // read ctr
\r
322 and r3, r3, #0xf // cache line size encoding
\r
323 mov r2, #4 // bytes per word
\r
324 mov r2, r2, lsl r3 // actual cache line size
\r
329 mcr p15, 0, r12, c7, c11, 1 // clean D line to the point of unification
\r
335 // .macro icache_line_size, reg, tmp
\r
336 mrc p15, 0, r3, c0, c0, 1 // read ctr
\r
337 and r3, r3, #0xf // cache line size encoding
\r
338 mov r2, #4 // bytes per word
\r
339 mov r2, r2, lsl r3 // actual cache line size
\r
344 mcr p15, 0, r12, c7, c5, 1 // invalidate I line
\r
349 mcr p15, 0, r0, c7, c1, 6 //invalidate BTB Inner Shareable
\r
350 mcr p15, 0, r0, c7, c5, 6 // invalidate BTB
\r
357 * \brief Invalidate the data cache within the specified region; we will
\r
358 * be performing a DMA operation in this region and we want to
\r
359 * purge old data in the cache.
\r
360 * \param start virtual start address of region
\r
361 * \param end virtual end address of region
\r
363 SECTION .CP15_invalidate_dcache_for_dma:CODE:NOROOT(2)
\r
364 PUBLIC CP15_invalidate_dcache_for_dma
\r
365 CP15_invalidate_dcache_for_dma:
\r
367 // dcache_line_size r2, r3
\r
368 mrc p15, 0, r3, c0, c0, 1 // read ctr
\r
370 and r3, r3, #0xf // cache line size encoding
\r
371 mov r2, #4 // bytes per word
\r
372 mov r2, r2, lsl r3 // actual cache line size
\r
378 mcrne p15, 0, r0, c7, c14, 1 // clean & invalidate D / U line
\r
382 mcrne p15, 0, r1, c7, c14, 1 // clean & invalidate D / U line
\r
384 mcr p15, 0, r0, c7, c6, 1 // invalidate D / U line
\r
393 * \brief Clean the data cache within the specified region
\r
394 * \param start virtual start address of region
\r
395 * \param end virtual end address of region
\r
397 SECTION .CP15_clean_dcache_for_dma:CODE:NOROOT(2)
\r
398 PUBLIC CP15_clean_dcache_for_dma
\r
399 CP15_clean_dcache_for_dma:
\r
400 // dcache_line_size r2, r3
\r
401 mrc p15, 0, r3, c0, c0, 1 // read ctr
\r
403 and r3, r3, #0xf // cache line size encoding
\r
404 mov r2, #4 // bytes per word
\r
405 mov r2, r2, lsl r3 // actual cache line size
\r
410 mcr p15, 0, r0, c7, c10, 1 // clean D / U line
\r
419 * \brief Flush the data cache within the specified region
\r
420 * \param start virtual start address of region
\r
421 * \param end virtual end address of region
\r
423 SECTION .CP15_flush_dcache_for_dma:CODE:NOROOT(2)
\r
424 PUBLIC CP15_flush_dcache_for_dma
\r
425 CP15_flush_dcache_for_dma:
\r
426 // dcache_line_size r2, r3
\r
427 mrc p15, 0, r3, c0, c0, 1 // read ctr
\r
429 and r3, r3, #0xf // cache line size encoding
\r
430 mov r2, #4 // bytes per word
\r
431 mov r2, r2, lsl r3 // actual cache line size
\r
435 mcr p15, 0, r0, c7, c14, 1 // clean & invalidate D / U line
\r
444 * \brief CP15_flush_kern_dcache_for_dma
\r
445 * Ensure that the data held in the page kaddr is written back to the page in question.
\r
446 * \param start virtual start address of region
\r
447 * \param end virtual end address of region
\r
449 SECTION .CP15_flush_kern_dcache_for_dma:CODE:NOROOT(2)
\r
450 PUBLIC CP15_flush_kern_dcache_for_dma
\r
451 CP15_flush_kern_dcache_for_dma:
\r
452 // dcache_line_size r2, r3
\r
453 mrc p15, 0, r3, c0, c0, 1 // read ctr
\r
455 and r3, r3, #0xf // cache line size encoding
\r
456 mov r2, #4 // bytes per word
\r
457 mov r2, r2, lsl r3 // actual cache line size
\r
463 mcr p15, 0, r0, c7, c14, 1 // clean & invalidate D line / unified line
\r