cp15_asm_iar.s 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. /* ----------------------------------------------------------------------------
  2. * SAM Software Package License
  3. * ----------------------------------------------------------------------------
  4. * Copyright (c) 2012, Atmel Corporation
  5. *
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. *
  11. * - Redistributions of source code must retain the above copyright notice,
  12. * this list of conditions and the disclaimer below.
  13. *
  14. * Atmel's name may not be used to endorse or promote products derived from
  15. * this software without specific prior written permission.
  16. *
  17. * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
  18. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  20. * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  22. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES// LOSS OF USE, DATA,
  23. * OR PROFITS// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  24. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  25. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  26. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. * ----------------------------------------------------------------------------
  28. */
  29. /** \file */
  30. /**
  31. * \addtogroup cp15_cache Cache Operations
  32. *
  33. * \section Usage
  34. *
  35. * They are performed as MCR instructions and only operate on a level 1 cache associated with
  36. * ATM v7 processor.
  37. * The supported operations are:
  38. * <ul>
  39. * <li> Any of these operations can be applied to
  40. * -# any data cache
  41. * -# any unified cache.
  42. * <li> Invalidate by MVA
  43. * Performs an invalidate of a data or unified cache line based on the address it contains.
  44. * <li> Invalidate by set/way
  45. * Performs an invalidate of a data or unified cache line based on its location in the cache hierarchy.
  46. * <li> Clean by MVA
  47. * Performs a clean of a data or unified cache line based on the address it contains.
  48. * <li> Clean by set/way
  49. * Performs a clean of a data or unified cache line based on its location in the cache hierarchy.
  50. * <li> Clean and Invalidate by MVA
  51. * Performs a clean and invalidate of a data or unified cache line based on the address it contains.
  52. * <li> Clean and Invalidate by set/way
  53. * Performs a clean and invalidate of a data or unified cache line based on its location in the cache hierarchy.
  54. * </ul>
  55. *
  56. * Related files:\n
  57. * \ref cp15.h\n
  58. * \ref cp15_arm_iar.s \n
  59. */
  60. MODULE ?cp15
  61. //// Forward declaration of sections.
  62. SECTION IRQ_STACK:DATA:NOROOT(2)
  63. SECTION CSTACK:DATA:NOROOT(3)
  64. /*----------------------------------------------------------------------------
  65. * Headers
  66. *----------------------------------------------------------------------------*/
  67. #define __ASSEMBLY__
  68. /*----------------------------------------------------------------------------
  69. * Functions to access CP15 coprocessor register
  70. *----------------------------------------------------------------------------*/
  71. PUBLIC CP15_ReadID
  72. PUBLIC CP15_ExclusiveCache
  73. PUBLIC CP15_NonExclusiveCache
  74. PUBLIC CP15_ISB
  75. PUBLIC CP15_DSB
  76. PUBLIC CP15_DMB
  77. PUBLIC CP15_SelectICache
  78. PUBLIC CP15_SelectDCache
  79. PUBLIC CP15_ReadControl
  80. PUBLIC CP15_WriteControl
  81. PUBLIC CP15_WriteDomainAccessControl
  82. PUBLIC CP15_WriteTTB
  83. PUBLIC CP15_InvalidateIcacheInnerSharable
  84. PUBLIC CP15_InvalidateBTBinnerSharable
  85. PUBLIC CP15_InvalidateIcache
  86. PUBLIC CP15_InvalidateIcacheByMva
  87. PUBLIC CP15_InvalidateBTB
  88. PUBLIC CP15_InvalidateBTBbyMva
  89. PUBLIC CP15_InvalidateDcacheBySetWay
  90. PUBLIC CP15_CleanDCacheBySetWay
  91. PUBLIC CP15_CleanInvalidateDCacheBySetWay
  92. PUBLIC CP15_InvalidateDcacheByMva
  93. PUBLIC CP15_CleanDCacheByMva
  94. PUBLIC CP15_CleanDCacheUMva
  95. PUBLIC CP15_CleanInvalidateDcacheByMva
  96. PUBLIC CP15_InvalidateTranslationTable
  97. PUBLIC CP15_coherent_dcache_for_dma
  98. PUBLIC CP15_invalidate_dcache_for_dma
  99. PUBLIC CP15_clean_dcache_for_dma
  100. PUBLIC CP15_flush_dcache_for_dma
  101. PUBLIC CP15_flush_kern_dcache_for_dma
  102. /**
  103. * \brief Register c0 accesses the ID Register, Cache Type Register, and TCM Status Registers.
  104. * Reading from this register returns the device ID, the cache type, or the TCM status
  105. * depending on the value of Opcode_2 used.
  106. */
  107. SECTION .CP15_ReadID:DATA:NOROOT(2)
  108. PUBLIC CP15_ReadID
  109. CP15_ReadID:
  110. mov r0, #0
  111. mrc p15, 0, r0, c0, c0, 0
  112. bx lr
  113. /**
  114. * \brief Register c7 accesses the ACTLR Register, to indicate cpu that L2 is in exclusive mode
  115. */
  116. SECTION .CP15_ISB:DATA:NOROOT(2)
  117. PUBLIC CP15_ISB
  118. CP15_ISB:
  119. mov r0, #0
  120. mcr p15, 0, r0, c7, c5, 4
  121. nop
  122. bx lr
  123. /**
  124. * \brief Register c7 accesses the ACTLR Register, to indicate cpu that L2 is in exclusive mode
  125. */
  126. SECTION .CP15_DSB:DATA:NOROOT(2)
  127. PUBLIC CP15_DSB
  128. CP15_DSB:
  129. mov r0, #0
  130. mcr p15, 0, r0, c7, c10, 4
  131. nop
  132. bx lr
  133. /**
  134. * \brief Register c7 accesses the ACTLR Register, to indicate cpu that L2 is in exclusive mode
  135. */
  136. SECTION .CP15_DMB:DATA:NOROOT(2)
  137. PUBLIC CP15_DMB
  138. CP15_DMB:
  139. mov r0, #0
  140. mcr p15, 0, r0, c7, c10, 5
  141. nop
  142. bx lr
  143. /**
  144. * \brief Register c1 accesses the ACTLR Register, to indicate cpu that L2 is in exclusive mode
  145. */
  146. SECTION .CP15_ExclusiveCache:DATA:NOROOT(2)
  147. PUBLIC CP15_ExclusiveCache
  148. CP15_ExclusiveCache:
  149. mov r0, #0
  150. mrc p15, 0, r0, c1, c0, 1 ; Read ACTLR
  151. orr r0, r0, #0x00000080
  152. mcr p15, 0, r0, c1, c0, 1 ; Write ACTLR
  153. nop
  154. bx lr
  155. /**
  156. * \brief Register c1 accesses the ACTLR Register, to indicate cpu that L2 is in exclusive mode
  157. */
  158. SECTION .CP15_NonExclusiveCache:DATA:NOROOT(2)
  159. PUBLIC CP15_NonExclusiveCache
  160. CP15_NonExclusiveCache:
  161. mov r0, #0
  162. mrc p15, 0, r0, c1, c0, 1 ; Read ACTLR
  163. bic r0, r0, #0x00000080
  164. mcr p15, 0, r0, c1, c0, 1 ; Write ACTLR
  165. nop
  166. bx lr
  167. /**
  168. * \brief Register c1 accesses the CSSELR Register, to select ICache
  169. */
  170. SECTION .CP15_SelectICache:DATA:NOROOT(2)
  171. PUBLIC CP15_SelectICache
  172. CP15_SelectICache:
  173. mrc p15, 2, r0, c0, c0, 0 ; Read CSSELR
  174. orr r0, r0, #0x1 ; Change 0th bit to ICache
  175. mcr p15, 2, r0, c0, c0, 0 ; Write CSSELR
  176. nop
  177. bx lr
  178. /**
  179. * \brief Register c1 accesses the CSSELR Register, to select DCache
  180. */
  181. SECTION .CP15_SelectDCache:DATA:NOROOT(2)
  182. PUBLIC CP15_SelectDCache
  183. CP15_SelectDCache:
  184. mrc p15, 2, r0, c0, c0, 0 ; Read CSSELR
  185. and r0, r0, #0xFFFFFFFE ; Change 0th bit to ICache
  186. mcr p15, 2, r0, c0, c0, 0 ; Write CSSELR
  187. nop
  188. bx lr
  189. /**
  190. * \brief Register c1 is the Control Register for the ARM926EJ-S processor.
  191. * This register specifies the configuration used to enable and disable the
  192. * caches and MMU. It is recommended that you access this register using a
  193. * read-modify-write sequence
  194. */
  195. SECTION .CP15_ReadControl:CODE:NOROOT(2)
  196. PUBLIC CP15_ReadControl
  197. CP15_ReadControl:
  198. mov r0, #0
  199. mrc p15, 0, r0, c1, c0, 0
  200. bx lr
  201. SECTION .CP15_WriteControl:CODE:NOROOT(2)
  202. PUBLIC CP15_WriteControl
  203. CP15_WriteControl:
  204. mcr p15, 0, r0, c1, c0, 0
  205. dsb
  206. isb
  207. bx lr
  208. SECTION .CP15_WriteDomainAccessControl:CODE:NOROOT(2)
  209. PUBLIC CP15_WriteDomainAccessControl
  210. CP15_WriteDomainAccessControl:
  211. mcr p15, 0, r0, c3, c0, 0
  212. dsb
  213. isb
  214. bx lr
  215. /**
  216. * \brief ARMv7A architecture supports two translation tables
  217. * Configure translation table base (TTB) control register cp15,c2
  218. * to a value of all zeros, indicates we are using TTB register 0.
  219. * write the address of our page table base to TTB register 0.
  220. */
  221. SECTION .CP15_WriteTTB:CODE:NOROOT(2)
  222. PUBLIC CP15_WriteTTB
  223. CP15_WriteTTB:
  224. mcr p15, 0, r0, c2, c0, 0
  225. dsb
  226. isb
  227. bx lr
  228. /**
  229. * \brief Invalidate I cache predictor array inner Sharable
  230. */
  231. SECTION .CP15_InvalidateIcacheInnerSharable:CODE:NOROOT(2)
  232. PUBLIC CP15_InvalidateIcacheInnerSharable
  233. CP15_InvalidateIcacheInnerSharable:
  234. mov r0, #0
  235. mcr p15, 0, r0, c7, c1, 0
  236. bx lr
  237. /**
  238. * \brief Invalidate entire branch predictor array inner Sharable
  239. */
  240. SECTION .CP15_InvalidateBTBinnerSharable:CODE:NOROOT(2)
  241. PUBLIC CP15_InvalidateBTBinnerSharable
  242. CP15_InvalidateBTBinnerSharable:
  243. mov r0, #0
  244. mcr p15, 0, r0, c7, c1, 6
  245. bx lr
  246. /**
  247. * \brief Invalidate all instruction caches to PoU, also flushes branch target cache
  248. */
  249. SECTION .CP15_InvalidateIcache:CODE:NOROOT(2)
  250. PUBLIC CP15_InvalidateIcache
  251. CP15_InvalidateIcache:
  252. mov r0, #0
  253. mcr p15, 0, r0, c7, c5, 0
  254. isb
  255. bx lr
  256. /**
  257. * \brief Invalidate instruction caches by VA to PoU
  258. */
  259. SECTION .CP15_InvalidateIcacheByMva:CODE:NOROOT(2)
  260. PUBLIC CP15_InvalidateIcacheByMva
  261. CP15_InvalidateIcacheByMva:
  262. mov r0, #0
  263. mcr p15, 0, r0, c7, c5, 1
  264. bx lr
  265. /**
  266. * \brief Invalidate entire branch predictor array
  267. */
  268. SECTION .CP15_InvalidateBTB:CODE:NOROOT(2)
  269. PUBLIC CP15_InvalidateBTB
  270. CP15_InvalidateBTB:
  271. mov r0, #0
  272. mcr p15, 0, r0, c7, c5, 6
  273. dsb
  274. isb
  275. bx lr
  276. /**
  277. * \brief Invalidate branch predictor array entry by MVA
  278. */
  279. SECTION .CP15_InvalidateBTBbyMva:CODE:NOROOT(2)
  280. PUBLIC CP15_InvalidateBTBbyMva
  281. CP15_InvalidateBTBbyMva:
  282. mcr p15, 0, r0, c7, c5, 7
  283. bx lr
  284. /***********************************************************
  285. *
  286. * ===Data Cache related maintenance functions===
  287. *
  288. **************************************************************/
  289. // ===Data Cache maintenance by SetWay ===
  290. /**
  291. * \brief Invalidate entire data cache by set/way
  292. */
  293. SECTION .CP15_InvalidateDcacheBySetWay:CODE:NOROOT(2)
  294. PUBLIC CP15_InvalidateDcacheBySetWay
  295. CP15_InvalidateDcacheBySetWay:
  296. MRC p15, 1, r0, c0, c0, 1 ; Read CLIDR
  297. ANDS r3, r0, #0x07000000 ; Extract coherency level
  298. MOV r3, r3, LSR #23 ; Total cache levels << 1
  299. BEQ inv_finish ; If 0, no need to clean
  300. MOV r10, #0 ; R10 holds current cache level << 1
  301. inv_cache_level_loop
  302. ADD r2, r10, r10, LSR #1 ; R2 holds cache "Set" position
  303. MOV r1, r0, LSR r2 ; Bottom 3 bits are the Cache-type for this level
  304. AND r1, r1, #7 ; Isolate those lower 3 bits
  305. CMP r1, #2
  306. BLT inv_skip ; No cache or only instruction cache at this level
  307. MCR p15, 2, r10, c0, c0, 0 ; Write the Cache Size selection register
  308. ISB ; ISB to sync the change to the CacheSizeID reg
  309. MRC p15, 1, r1, c0, c0, 0 ; Reads current Cache Size ID register
  310. AND r2, r1, #7 ; Extract the line length field
  311. ADD r2, r2, #4 ; Add 4 for the line length offset (log2 16 bytes)
  312. LDR r4, =0x3FF
  313. ANDS r4, r4, r1, LSR #3 ; R4 is the max number on the way size (right aligned)
  314. CLZ r5, r4 ; R5 is the bit position of the way size increment
  315. LDR r7, =0x7FFF
  316. ANDS r7, r7, r1, LSR #13 ; R7 is the max number of the index size (right aligned)
  317. inv_set_loop
  318. MOV r9, r4 ; R9 working copy of the max way size (right aligned)
  319. inv_way_loop
  320. ORR r11, r10, r9, LSL r5 ; Factor in the Way number and cache number into R11
  321. ORR r11, r11, r7, LSL r2 ; Factor in the Set number
  322. MCR p15, 0, r11, c7, c6, 2 ; Invalidate by Set/Way
  323. SUBS r9, r9, #1 ; Decrement the Way number
  324. BGE inv_way_loop
  325. SUBS r7, r7, #1 ; Decrement the Set number
  326. BGE inv_set_loop
  327. inv_skip
  328. ADD r10, r10, #2 ; increment the cache number
  329. CMP r3, r10
  330. BGT inv_cache_level_loop
  331. inv_finish
  332. NOP
  333. BX lr
  334. /**
  335. * \brief Clean entire data cache by set/way
  336. */
  337. SECTION .CP15_CleanDCacheBySetWay:CODE:NOROOT(2)
  338. PUBLIC CP15_CleanDCacheBySetWay
  339. CP15_CleanDCacheBySetWay:
  340. MRC p15, 1, r0, c0, c0, 1 ; Read CLIDR
  341. ANDS r3, r0, #0x07000000 ; Extract coherency level
  342. MOV r3, r3, LSR #23 ; Total cache levels << 1
  343. BEQ clean_finish ; If 0, no need to clean
  344. MOV r10, #0 ; R10 holds current cache level << 1
  345. clean_cache_level_loop
  346. ADD r2, r10, r10, LSR #1 ; R2 holds cache "Set" position
  347. MOV r1, r0, LSR r2 ; Bottom 3 bits are the Cache-type for this level
  348. AND r1, r1, #7 ; Isolate those lower 3 bits
  349. CMP r1, #2
  350. BLT clean_skip ; No cache or only instruction cache at this level
  351. MCR p15, 2, r10, c0, c0, 0 ; Write the Cache Size selection register
  352. ISB ; ISB to sync the change to the CacheSizeID reg
  353. MRC p15, 1, r1, c0, c0, 0 ; Reads current Cache Size ID register
  354. AND r2, r1, #7 ; Extract the line length field
  355. ADD r2, r2, #4 ; Add 4 for the line length offset (log2 16 bytes)
  356. LDR r4, =0x3FF
  357. ANDS r4, r4, r1, LSR #3 ; R4 is the max number on the way size (right aligned)
  358. CLZ r5, r4 ; R5 is the bit position of the way size increment
  359. LDR r7, =0x7FFF
  360. ANDS r7, r7, r1, LSR #13 ; R7 is the max number of the index size (right aligned)
  361. clean_set_loop
  362. MOV r9, r4 ; R9 working copy of the max way size (right aligned)
  363. clean_way_loop
  364. ORR r11, r10, r9, LSL r5 ; Factor in the Way number and cache number into R11
  365. ORR r11, r11, r7, LSL r2 ; Factor in the Set number
  366. MCR p15, 0, r11, c7, c10, 2 ; Clean by Set/Way
  367. SUBS r9, r9, #1 ; Decrement the Way number
  368. BGE clean_way_loop
  369. SUBS r7, r7, #1 ; Decrement the Set number
  370. BGE clean_set_loop
  371. clean_skip
  372. ADD r10, r10, #2 ; increment the cache number
  373. CMP r3, r10
  374. BGT clean_cache_level_loop
  375. clean_finish
  376. NOP
  377. BX lr
  378. /**
  379. * \brief Clean and Invalidate entire data cache by set/way
  380. */
  381. SECTION .CP15_CleanInvalidateDCacheBySetWay:CODE:NOROOT(2)
  382. PUBLIC CP15_CleanInvalidateDCacheBySetWay
  383. CP15_CleanInvalidateDCacheBySetWay:
  384. MRC p15, 1, r0, c0, c0, 1 ; Read CLIDR
  385. ANDS r3, r0, #0x07000000 ; Extract coherency level
  386. MOV r3, r3, LSR #23 ; Total cache levels << 1
  387. BEQ clinv_finish ; If 0, no need to clean
  388. MOV r10, #0 ; R10 holds current cache level << 1
  389. clinv_cache_level_loop
  390. ADD r2, r10, r10, LSR #1 ; R2 holds cache "Set" position
  391. MOV r1, r0, LSR r2 ; Bottom 3 bits are the Cache-type for this level
  392. AND r1, r1, #7 ; Isolate those lower 3 bits
  393. CMP r1, #2
  394. BLT clean_skip ; No cache or only instruction cache at this level
  395. MCR p15, 2, r10, c0, c0, 0 ; Write the Cache Size selection register
  396. ISB ; ISB to sync the change to the CacheSizeID reg
  397. MRC p15, 1, r1, c0, c0, 0 ; Reads current Cache Size ID register
  398. AND r2, r1, #7 ; Extract the line length field
  399. ADD r2, r2, #4 ; Add 4 for the line length offset (log2 16 bytes)
  400. LDR r4, =0x3FF
  401. ANDS r4, r4, r1, LSR #3 ; R4 is the max number on the way size (right aligned)
  402. CLZ r5, r4 ; R5 is the bit position of the way size increment
  403. LDR r7, =0x7FFF
  404. ANDS r7, r7, r1, LSR #13 ; R7 is the max number of the index size (right aligned)
  405. clinv_set_loop
  406. MOV r9, r4 ; R9 working copy of the max way size (right aligned)
  407. clinv_way_loop
  408. ORR r11, r10, r9, LSL r5 ; Factor in the Way number and cache number into R11
  409. ORR r11, r11, r7, LSL r2 ; Factor in the Set number
  410. MCR p15, 0, r11, c7, c14, 2 ; Clean and Invalidate by Set/Way
  411. SUBS r9, r9, #1 ; Decrement the Way number
  412. BGE clean_way_loop
  413. SUBS r7, r7, #1 ; Decrement the Set number
  414. BGE clean_set_loop
  415. clinv_skip
  416. ADD r10, r10, #2 ; increment the cache number
  417. CMP r3, r10
  418. BGT clean_cache_level_loop
  419. clinv_finish
  420. NOP
  421. BX lr
  422. // ===Data Cache maintenance by VA ===
  423. /**
  424. * \brief Invalidate data cache by VA to Poc
  425. */
  426. SECTION .CP15_InvalidateDcacheByMva:CODE:NOROOT(2)
  427. PUBLIC CP15_InvalidateDcacheByMva
  428. CP15_InvalidateDcacheByMva:
  429. mov r2, #0x20 ;Eight words per line, Cortex-A5 L1 Line Size 32 Bytes
  430. mov r3, r0
  431. inv_loop
  432. mcr p15, 0, r0, c7, c6, 1
  433. add r3, r3, r2
  434. cmp r3, r1
  435. bls inv_loop
  436. bx lr
  437. /**
  438. * \brief Clean data cache by MVA
  439. */
  440. SECTION .CP15_CleanDCacheByMva:CODE:NOROOT(2)
  441. PUBLIC CP15_CleanDCacheByMva
  442. CP15_CleanDCacheByMva:
  443. mov r2, #0x20 ;Eight words per line, Cortex-A5 L1 Line Size 32 Bytes
  444. mov r3, r0
  445. clean_loop
  446. mcr p15, 0, r0, c7, c10, 1
  447. add r3, r3, r2
  448. cmp r3, r1
  449. bls clean_loop
  450. bx lr
  451. /**
  452. * \brief Clean unified cache by MVA
  453. */
  454. SECTION .CP15_CleanDCacheUMva:CODE:NOROOT(2)
  455. PUBLIC CP15_CleanDCacheUMva
  456. CP15_CleanDCacheUMva:
  457. mov r0, #0
  458. mcr p15, 0, r0, c7, c11, 1
  459. bx lr
  460. /**
  461. * \brief Clean and invalidate data cache by VA to PoC
  462. */
  463. SECTION .CP15_CleanInvalidateDcacheByMva:CODE:NOROOT(2)
  464. PUBLIC CP15_CleanInvalidateDcacheByMva
  465. CP15_CleanInvalidateDcacheByMva:
  466. mov r2, #0x20 ;Eight words per line, Cortex-A5 L1 Line Size 32 Bytes
  467. mov r3, r0
  468. clinv_loop
  469. mcr p15, 0, r0, c7, c14, 1
  470. add r3, r3, r2
  471. cmp r3, r1
  472. bls clinv_loop
  473. bx lr
  474. /**
  475. * \brief Invalidate translation table
  476. */
  477. SECTION .CP15_InvalidateTranslationTable:CODE:NOROOT(2)
  478. PUBLIC CP15_InvalidateTranslationTable
  479. CP15_InvalidateTranslationTable:
  480. mov r0, #0
  481. mcr p15, 0, r0, c8, c3, 0
  482. dsb
  483. isb
  484. mcr p15, 0, r0, c8, c7, 0
  485. dsb
  486. isb
  487. bx lr
  488. /**
  489. * \brief flush translation table
  490. */
  491. SECTION .CP15_FlushTranslationTable:CODE:NOROOT(2)
  492. PUBLIC CP15_FlushTranslationTable
  493. CP15_FlushTranslationTable:
  494. mov r0, #0
  495. mcr p15, 0, r0, c8, c3, 0
  496. dsb
  497. isb
  498. bx lr
  499. /**
  500. * \brief Ensure that the I and D caches are coherent within specified
  501. * region. This is typically used when code has been written to
  502. * a memory region, and will be executed.
  503. * \param start virtual start address of region
  504. * \param end virtual end address of region
  505. */
  506. SECTION .CP15_coherent_dcache_for_dma:CODE:NOROOT(2)
  507. PUBLIC CP15_coherent_dcache_for_dma
  508. CP15_coherent_dcache_for_dma:
  509. // dcache_line_size r2, r3
  510. mrc p15, 0, r3, c0, c0, 1 // read ctr
  511. lsr r3, r3, #16
  512. and r3, r3, #0xf // cache line size encoding
  513. mov r2, #4 // bytes per word
  514. mov r2, r2, lsl r3 // actual cache line size
  515. sub r3, r2, #1
  516. bic r12, r0, r3
  517. loop1:
  518. mcr p15, 0, r12, c7, c11, 1 // clean D line to the point of unification
  519. add r12, r12, r2
  520. cmp r12, r1
  521. blo loop1
  522. dsb
  523. // .macro icache_line_size, reg, tmp
  524. mrc p15, 0, r3, c0, c0, 1 // read ctr
  525. and r3, r3, #0xf // cache line size encoding
  526. mov r2, #4 // bytes per word
  527. mov r2, r2, lsl r3 // actual cache line size
  528. sub r3, r2, #1
  529. bic r12, r0, r3
  530. loop2:
  531. mcr p15, 0, r12, c7, c5, 1 // invalidate I line
  532. add r12, r12, r2
  533. cmp r12, r1
  534. blo loop2
  535. mov r0, #0
  536. mcr p15, 0, r0, c7, c1, 6 //invalidate BTB Inner Shareable
  537. mcr p15, 0, r0, c7, c5, 6 // invalidate BTB
  538. dsb
  539. isb
  540. bx lr
  541. /**
  542. * \brief Invalidate the data cache within the specified region; we will
  543. * be performing a DMA operation in this region and we want to
  544. * purge old data in the cache.
  545. * \param start virtual start address of region
  546. * \param end virtual end address of region
  547. */
  548. SECTION .CP15_invalidate_dcache_for_dma:CODE:NOROOT(2)
  549. PUBLIC CP15_invalidate_dcache_for_dma
  550. CP15_invalidate_dcache_for_dma:
  551. // dcache_line_size r2, r3
  552. mrc p15, 0, r3, c0, c0, 1 // read ctr
  553. lsr r3, r3, #16
  554. and r3, r3, #0xf // cache line size encoding
  555. mov r2, #4 // bytes per word
  556. mov r2, r2, lsl r3 // actual cache line size
  557. sub r3, r2, #1
  558. tst r0, r3
  559. bic r0, r0, r3
  560. mcrne p15, 0, r0, c7, c14, 1 // clean & invalidate D / U line
  561. tst r1, r3
  562. bic r1, r1, r3
  563. mcrne p15, 0, r1, c7, c14, 1 // clean & invalidate D / U line
  564. loop3:
  565. mcr p15, 0, r0, c7, c6, 1 // invalidate D / U line
  566. add r0, r0, r2
  567. cmp r0, r1
  568. blo loop3
  569. dsb
  570. bx lr
  571. /**
  572. * \brief Clean the data cache within the specified region
  573. * \param start virtual start address of region
  574. * \param end virtual end address of region
  575. */
  576. SECTION .CP15_clean_dcache_for_dma:CODE:NOROOT(2)
  577. PUBLIC CP15_clean_dcache_for_dma
  578. CP15_clean_dcache_for_dma:
  579. // dcache_line_size r2, r3
  580. mrc p15, 0, r3, c0, c0, 1 // read ctr
  581. lsr r3, r3, #16
  582. and r3, r3, #0xf // cache line size encoding
  583. mov r2, #4 // bytes per word
  584. mov r2, r2, lsl r3 // actual cache line size
  585. sub r3, r2, #1
  586. bic r0, r0, r3
  587. loop4:
  588. mcr p15, 0, r0, c7, c10, 1 // clean D / U line
  589. add r0, r0, r2
  590. cmp r0, r1
  591. blo loop4
  592. dsb
  593. bx lr
  594. /**
  595. * \brief Flush the data cache within the specified region
  596. * \param start virtual start address of region
  597. * \param end virtual end address of region
  598. */
  599. SECTION .CP15_flush_dcache_for_dma:CODE:NOROOT(2)
  600. PUBLIC CP15_flush_dcache_for_dma
  601. CP15_flush_dcache_for_dma:
  602. // dcache_line_size r2, r3
  603. mrc p15, 0, r3, c0, c0, 1 // read ctr
  604. lsr r3, r3, #16
  605. and r3, r3, #0xf // cache line size encoding
  606. mov r2, #4 // bytes per word
  607. mov r2, r2, lsl r3 // actual cache line size
  608. sub r3, r2, #1
  609. bic r0, r0, r3
  610. loop5:
  611. mcr p15, 0, r0, c7, c14, 1 // clean & invalidate D / U line
  612. add r0, r0, r2
  613. cmp r0, r1
  614. blo loop5
  615. dsb
  616. bx lr
  617. /**
  618. * \brief CP15_flush_kern_dcache_for_dma
  619. * Ensure that the data held in the page kaddr is written back to the page in question.
  620. * \param start virtual start address of region
  621. * \param end virtual end address of region
  622. */
  623. SECTION .CP15_flush_kern_dcache_for_dma:CODE:NOROOT(2)
  624. PUBLIC CP15_flush_kern_dcache_for_dma
  625. CP15_flush_kern_dcache_for_dma:
  626. // dcache_line_size r2, r3
  627. mrc p15, 0, r3, c0, c0, 1 // read ctr
  628. lsr r3, r3, #16
  629. and r3, r3, #0xf // cache line size encoding
  630. mov r2, #4 // bytes per word
  631. mov r2, r2, lsl r3 // actual cache line size
  632. add r1, r0, r1
  633. sub r3, r2, #1
  634. bic r0, r0, r3
  635. mcr p15, 0, r0, c7, c14, 1 // clean & invalidate D line / unified line
  636. add r0, r0, r2
  637. cmp r0, r1
  638. blo 1b
  639. dsb
  640. bx lr
  641. END