cache.S 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. /*
  44. * invalidate_dcache()
  45. *
  46. * Invalidate the whole D-cache.
  47. *
  48. * Corrupted registers: r0-r5, r7, r9-r11
  49. *
  50. * - mm - mm_struct describing address space
  51. */
  52. invalidate_dcache:
  53. stmfd r13!, {r0 - r5, r7, r9 - r12, r14}
  54. mov r7, r0 @ take a backup of device type
  55. cmp r0, #0x3 @ check if the device type is
  56. @ GP
  57. moveq r12, #0x1 @ set up to invalide L2
  58. smi: .word 0x01600070 @ Call SMI monitor (smieq)
  59. cmp r7, #0x3 @ compare again in case its
  60. @ lost
  61. beq finished_inval @ if GP device, inval done
  62. @ above
  63. mrc p15, 1, r0, c0, c0, 1 @ read clidr
  64. ands r3, r0, #0x7000000 @ extract loc from clidr
  65. mov r3, r3, lsr #23 @ left align loc bit field
  66. beq finished_inval @ if loc is 0, then no need to
  67. @ clean
  68. mov r10, #0 @ start clean at cache level 0
  69. inval_loop1:
  70. add r2, r10, r10, lsr #1 @ work out 3x current cache
  71. @ level
  72. mov r1, r0, lsr r2 @ extract cache type bits from
  73. @ clidr
  74. and r1, r1, #7 @ mask of the bits for current
  75. @ cache only
  76. cmp r1, #2 @ see what cache we have at
  77. @ this level
  78. blt skip_inval @ skip if no cache, or just
  79. @ i-cache
  80. mcr p15, 2, r10, c0, c0, 0 @ select current cache level
  81. @ in cssr
  82. mov r2, #0 @ operand for mcr SBZ
  83. mcr p15, 0, r2, c7, c5, 4 @ flush prefetch buffer to
  84. @ sych the new cssr&csidr,
  85. @ with armv7 this is 'isb',
  86. @ but we compile with armv5
  87. mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
  88. and r2, r1, #7 @ extract the length of the
  89. @ cache lines
  90. add r2, r2, #4 @ add 4 (line length offset)
  91. ldr r4, =0x3ff
  92. ands r4, r4, r1, lsr #3 @ find maximum number on the
  93. @ way size
  94. clz r5, r4 @ find bit position of way
  95. @ size increment
  96. ldr r7, =0x7fff
  97. ands r7, r7, r1, lsr #13 @ extract max number of the
  98. @ index size
  99. inval_loop2:
  100. mov r9, r4 @ create working copy of max
  101. @ way size
  102. inval_loop3:
  103. orr r11, r10, r9, lsl r5 @ factor way and cache number
  104. @ into r11
  105. orr r11, r11, r7, lsl r2 @ factor index number into r11
  106. mcr p15, 0, r11, c7, c6, 2 @ invalidate by set/way
  107. subs r9, r9, #1 @ decrement the way
  108. bge inval_loop3
  109. subs r7, r7, #1 @ decrement the index
  110. bge inval_loop2
  111. skip_inval:
  112. add r10, r10, #2 @ increment cache number
  113. cmp r3, r10
  114. bgt inval_loop1
  115. finished_inval:
  116. mov r10, #0 @ swith back to cache level 0
  117. mcr p15, 2, r10, c0, c0, 0 @ select current cache level
  118. @ in cssr
  119. mcr p15, 0, r10, c7, c5, 4 @ flush prefetch buffer,
  120. @ with armv7 this is 'isb',
  121. @ but we compile with armv5
  122. ldmfd r13!, {r0 - r5, r7, r9 - r12, pc}
  123. l2_cache_enable:
  124. push {r0, r1, r2, lr}
  125. @ ES2 onwards we can disable/enable L2 ourselves
  126. bl get_cpu_rev
  127. cmp r0, #CPU_3XX_ES20
  128. blt l2_cache_disable_EARLIER_THAN_ES2
  129. mrc 15, 0, r3, cr1, cr0, 1
  130. orr r3, r3, #2
  131. mcr 15, 0, r3, cr1, cr0, 1
  132. b l2_cache_enable_END
  133. l2_cache_enable_EARLIER_THAN_ES2:
  134. @ Save r0, r12 and restore them after usage
  135. mov r3, ip
  136. str r3, [sp, #4]
  137. mov r3, r0
  138. @
  139. @ GP Device ROM code API usage here
  140. @ r12 = AUXCR Write function and r0 value
  141. @
  142. mov ip, #3
  143. mrc 15, 0, r0, cr1, cr0, 1
  144. orr r0, r0, #2
  145. @ SMI instruction to call ROM Code API
  146. .word 0xe1600070
  147. mov r0, r3
  148. mov ip, r3
  149. str r3, [sp, #4]
  150. l2_cache_enable_END:
  151. pop {r1, r2, r3, pc}
  152. l2_cache_disable:
  153. push {r0, r1, r2, lr}
  154. @ ES2 onwards we can disable/enable L2 ourselves
  155. bl get_cpu_rev
  156. cmp r0, #CPU_3XX_ES20
  157. blt l2_cache_disable_EARLIER_THAN_ES2
  158. mrc 15, 0, r3, cr1, cr0, 1
  159. bic r3, r3, #2
  160. mcr 15, 0, r3, cr1, cr0, 1
  161. b l2_cache_disable_END
  162. l2_cache_disable_EARLIER_THAN_ES2:
  163. @ Save r0, r12 and restore them after usage
  164. mov r3, ip
  165. str r3, [sp, #4]
  166. mov r3, r0
  167. @
  168. @ GP Device ROM code API usage here
  169. @ r12 = AUXCR Write function and r0 value
  170. @
  171. mov ip, #3
  172. mrc 15, 0, r0, cr1, cr0, 1
  173. bic r0, r0, #2
  174. @ SMI instruction to call ROM Code API
  175. .word 0xe1600070
  176. mov r0, r3
  177. mov ip, r3
  178. str r3, [sp, #4]
  179. l2_cache_disable_END:
  180. pop {r1, r2, r3, pc}