cache.S 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * Copyright (c) 2009 Wind River Systems, Inc.
  3. * Tom Rix <Tom.Rix@windriver.com>
  4. *
  5. * This file is based on and replaces the existing cache.c file
  6. * The copyrights for the cache.c file are:
  7. *
  8. * (C) Copyright 2008 Texas Insturments
  9. *
  10. * (C) Copyright 2002
  11. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  12. * Marius Groeger <mgroeger@sysgo.de>
  13. *
  14. * (C) Copyright 2002
  15. * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
  16. *
  17. * See file CREDITS for list of people who contributed to this
  18. * project.
  19. *
  20. * This program is free software; you can redistribute it and/or
  21. * modify it under the terms of the GNU General Public License as
  22. * published by the Free Software Foundation; either version 2 of
  23. * the License, or (at your option) any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with this program; if not, write to the Free Software
  32. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  33. * MA 02111-1307 USA
  34. */
  35. #include <asm/arch/omap3.h>
  36. /*
  37. * omap3 cache code
  38. */
  39. .align 5
  40. .global invalidate_dcache
  41. .global l2_cache_enable
  42. .global l2_cache_disable
  43. .global setup_auxcr
  44. /*
  45. * invalidate_dcache()
  46. *
  47. * Invalidate the whole D-cache.
  48. *
  49. * Corrupted registers: r0-r5, r7, r9-r11
  50. *
  51. * - mm - mm_struct describing address space
  52. */
  53. invalidate_dcache:
  54. stmfd r13!, {r0 - r5, r7, r9 - r12, r14}
  55. mov r7, r0 @ take a backup of device type
  56. cmp r0, #0x3 @ check if the device type is
  57. @ GP
  58. moveq r12, #0x1 @ set up to invalide L2
  59. smi: .word 0x01600070 @ Call SMI monitor (smieq)
  60. cmp r7, #0x3 @ compare again in case its
  61. @ lost
  62. beq finished_inval @ if GP device, inval done
  63. @ above
  64. mrc p15, 1, r0, c0, c0, 1 @ read clidr
  65. ands r3, r0, #0x7000000 @ extract loc from clidr
  66. mov r3, r3, lsr #23 @ left align loc bit field
  67. beq finished_inval @ if loc is 0, then no need to
  68. @ clean
  69. mov r10, #0 @ start clean at cache level 0
  70. inval_loop1:
  71. add r2, r10, r10, lsr #1 @ work out 3x current cache
  72. @ level
  73. mov r1, r0, lsr r2 @ extract cache type bits from
  74. @ clidr
  75. and r1, r1, #7 @ mask of the bits for current
  76. @ cache only
  77. cmp r1, #2 @ see what cache we have at
  78. @ this level
  79. blt skip_inval @ skip if no cache, or just
  80. @ i-cache
  81. mcr p15, 2, r10, c0, c0, 0 @ select current cache level
  82. @ in cssr
  83. mov r2, #0 @ operand for mcr SBZ
  84. mcr p15, 0, r2, c7, c5, 4 @ flush prefetch buffer to
  85. @ sych the new cssr&csidr,
  86. @ with armv7 this is 'isb',
  87. @ but we compile with armv5
  88. mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
  89. and r2, r1, #7 @ extract the length of the
  90. @ cache lines
  91. add r2, r2, #4 @ add 4 (line length offset)
  92. ldr r4, =0x3ff
  93. ands r4, r4, r1, lsr #3 @ find maximum number on the
  94. @ way size
  95. clz r5, r4 @ find bit position of way
  96. @ size increment
  97. ldr r7, =0x7fff
  98. ands r7, r7, r1, lsr #13 @ extract max number of the
  99. @ index size
  100. inval_loop2:
  101. mov r9, r4 @ create working copy of max
  102. @ way size
  103. inval_loop3:
  104. orr r11, r10, r9, lsl r5 @ factor way and cache number
  105. @ into r11
  106. orr r11, r11, r7, lsl r2 @ factor index number into r11
  107. mcr p15, 0, r11, c7, c6, 2 @ invalidate by set/way
  108. subs r9, r9, #1 @ decrement the way
  109. bge inval_loop3
  110. subs r7, r7, #1 @ decrement the index
  111. bge inval_loop2
  112. skip_inval:
  113. add r10, r10, #2 @ increment cache number
  114. cmp r3, r10
  115. bgt inval_loop1
  116. finished_inval:
  117. mov r10, #0 @ swith back to cache level 0
  118. mcr p15, 2, r10, c0, c0, 0 @ select current cache level
  119. @ in cssr
  120. mcr p15, 0, r10, c7, c5, 4 @ flush prefetch buffer,
  121. @ with armv7 this is 'isb',
  122. @ but we compile with armv5
  123. ldmfd r13!, {r0 - r5, r7, r9 - r12, pc}
  124. l2_cache_set:
  125. stmfd r13!, {r4 - r6, lr}
  126. mov r5, r0
  127. bl get_cpu_rev
  128. mov r4, r0
  129. bl get_cpu_family
  130. @ ES2 onwards we can disable/enable L2 ourselves
  131. cmp r0, #CPU_OMAP34XX
  132. cmpeq r4, #CPU_3XX_ES10
  133. mrc 15, 0, r0, cr1, cr0, 1
  134. bic r0, r0, #2
  135. orr r0, r0, r5, lsl #1
  136. mcreq 15, 0, r0, cr1, cr0, 1
  137. @ GP Device ROM code API usage here
  138. @ r12 = AUXCR Write function and r0 value
  139. mov ip, #3
  140. @ SMCNE instruction to call ROM Code API
  141. .word 0x11600070
  142. ldmfd r13!, {r4 - r6, pc}
  143. l2_cache_enable:
  144. mov r0, #1
  145. b l2_cache_set
  146. l2_cache_disable:
  147. mov r0, #0
  148. b l2_cache_set
  149. /******************************************************************************
  150. * Routine: setup_auxcr()
  151. * Description: Write to AuxCR desired value using SMI.
  152. * general use.
  153. *****************************************************************************/
  154. setup_auxcr:
  155. mrc p15, 0, r0, c0, c0, 0 @ read main ID register
  156. and r2, r0, #0x00f00000 @ variant
  157. and r3, r0, #0x0000000f @ revision
  158. orr r1, r3, r2, lsr #20-4 @ combine variant and revision
  159. mov r12, #0x3
  160. mrc p15, 0, r0, c1, c0, 1
  161. orr r0, r0, #0x10 @ Enable ASA
  162. @ Enable L1NEON on pre-r2p1 (erratum 621766 workaround)
  163. cmp r1, #0x21
  164. orrlt r0, r0, #1 << 5
  165. .word 0xE1600070 @ SMC
  166. mov r12, #0x2
  167. mrc p15, 1, r0, c9, c0, 2
  168. @ Set PLD_FWD bit in L2AUXCR on pre-r2p1 (erratum 725233 workaround)
  169. cmp r1, #0x21
  170. orrlt r0, r0, #1 << 27
  171. .word 0xE1600070 @ SMC
  172. bx lr
  173. .align 5
  174. .global v7_flush_dcache_all
  175. .global v7_flush_cache_all
  176. /*
  177. * v7_flush_dcache_all()
  178. *
  179. * Flush the whole D-cache.
  180. *
  181. * Corrupted registers: r0-r7, r9-r11 (r6 only in Thumb mode)
  182. *
  183. * - mm - mm_struct describing address space
  184. */
  185. v7_flush_dcache_all:
  186. # dmb @ ensure ordering with previous memory accesses
  187. mrc p15, 1, r0, c0, c0, 1 @ read clidr
  188. ands r3, r0, #0x7000000 @ extract loc from clidr
  189. mov r3, r3, lsr #23 @ left align loc bit field
  190. beq finished @ if loc is 0, then no need to clean
  191. mov r10, #0 @ start clean at cache level 0
  192. loop1:
  193. add r2, r10, r10, lsr #1 @ work out 3x current cache level
  194. mov r1, r0, lsr r2 @ extract cache type bits from clidr
  195. and r1, r1, #7 @ mask of the bits for current cache only
  196. cmp r1, #2 @ see what cache we have at this level
  197. blt skip @ skip if no cache, or just i-cache
  198. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  199. mcr p15, 0, r10, c7, c5, 4 @ flush prefetch buffer,
  200. @ with armv7 this is 'isb',
  201. @ but we compile with armv5
  202. mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
  203. and r2, r1, #7 @ extract the length of the cache lines
  204. add r2, r2, #4 @ add 4 (line length offset)
  205. ldr r4, =0x3ff
  206. ands r4, r4, r1, lsr #3 @ find maximum number on the way size
  207. clz r5, r4 @ find bit position of way size increment
  208. ldr r7, =0x7fff
  209. ands r7, r7, r1, lsr #13 @ extract max number of the index size
  210. loop2:
  211. mov r9, r4 @ create working copy of max way size
  212. loop3:
  213. orr r11, r10, r9, lsl r5 @ factor way and cache number into r11
  214. orr r11, r11, r7, lsl r2 @ factor index number into r11
  215. mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way
  216. subs r9, r9, #1 @ decrement the way
  217. bge loop3
  218. subs r7, r7, #1 @ decrement the index
  219. bge loop2
  220. skip:
  221. add r10, r10, #2 @ increment cache number
  222. cmp r3, r10
  223. bgt loop1
  224. finished:
  225. mov r10, #0 @ swith back to cache level 0
  226. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  227. # dsb
  228. mcr p15, 0, r10, c7, c5, 4 @ flush prefetch buffer,
  229. @ with armv7 this is 'isb',
  230. @ but we compile with armv5
  231. mov pc, lr
  232. /*
  233. * v7_flush_cache_all()
  234. *
  235. * Flush the entire cache system.
  236. * The data cache flush is now achieved using atomic clean / invalidates
  237. * working outwards from L1 cache. This is done using Set/Way based cache
  238. * maintainance instructions.
  239. * The instruction cache can still be invalidated back to the point of
  240. * unification in a single instruction.
  241. *
  242. */
  243. v7_flush_cache_all:
  244. stmfd sp!, {r0-r7, r9-r11, lr}
  245. bl v7_flush_dcache_all
  246. mov r0, #0
  247. mcr p15, 0, r0, c7, c5, 0 @ I+BTB cache invalidate
  248. ldmfd sp!, {r0-r7, r9-r11, lr}
  249. mov pc, lr