/arch/arm/mm/cache-v6.S

https://github.com/bananacakes/bravo_2.6.35_gb-mr · Assembly · 354 lines · 216 code · 19 blank · 119 comment · 11 complexity · b9702da817ba859139144889598a181c MD5 · raw file

  1. /*
  2. * linux/arch/arm/mm/cache-v6.S
  3. *
  4. * Copyright (C) 2001 Deep Blue Solutions Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This is the "shell" of the ARMv6 processor support.
  11. */
  12. #include <linux/linkage.h>
  13. #include <linux/init.h>
  14. #include <asm/assembler.h>
  15. #include <asm/unwind.h>
  16. #include "proc-macros.S"
  17. #define HARVARD_CACHE
  18. #define CACHE_LINE_SIZE 32
  19. #define D_CACHE_LINE_SIZE 32
  20. #define BTB_FLUSH_SIZE 8
  21. #ifdef CONFIG_ARM_ERRATA_411920
  22. /*
  23. * Invalidate the entire I cache (this code is a workaround for the ARM1136
  24. * erratum 411920 - Invalidate Instruction Cache operation can fail. This
  25. * erratum is present in 1136, 1156 and 1176. It does not affect the MPCore.
  26. *
  27. * Registers:
  28. * r0 - set to 0
  29. * r1 - corrupted
  30. */
  31. ENTRY(v6_icache_inval_all)
  32. mov r0, #0
  33. mrs r1, cpsr
  34. cpsid ifa @ disable interrupts
  35. mcr p15, 0, r0, c7, c5, 0 @ invalidate entire I-cache
  36. mcr p15, 0, r0, c7, c5, 0 @ invalidate entire I-cache
  37. mcr p15, 0, r0, c7, c5, 0 @ invalidate entire I-cache
  38. mcr p15, 0, r0, c7, c5, 0 @ invalidate entire I-cache
  39. msr cpsr_cx, r1 @ restore interrupts
  40. .rept 11 @ ARM Ltd recommends at least
  41. nop @ 11 NOPs
  42. .endr
  43. mov pc, lr
  44. #endif
  45. /*
  46. * v6_flush_cache_all()
  47. *
  48. * Flush the entire cache.
  49. *
  50. * It is assumed that:
  51. */
  52. ENTRY(v6_flush_kern_cache_all)
  53. mov r0, #0
  54. #ifdef HARVARD_CACHE
  55. mcr p15, 0, r0, c7, c14, 0 @ D cache clean+invalidate
  56. #ifndef CONFIG_ARM_ERRATA_411920
  57. mcr p15, 0, r0, c7, c5, 0 @ I+BTB cache invalidate
  58. #else
  59. b v6_icache_inval_all
  60. #endif
  61. #else
  62. mcr p15, 0, r0, c7, c15, 0 @ Cache clean+invalidate
  63. #endif
  64. mov pc, lr
  65. /*
  66. * v6_flush_cache_all()
  67. *
  68. * Flush all TLB entries in a particular address space
  69. *
  70. * - mm - mm_struct describing address space
  71. */
  72. ENTRY(v6_flush_user_cache_all)
  73. /*FALLTHROUGH*/
  74. /*
  75. * v6_flush_cache_range(start, end, flags)
  76. *
  77. * Flush a range of TLB entries in the specified address space.
  78. *
  79. * - start - start address (may not be aligned)
  80. * - end - end address (exclusive, may not be aligned)
  81. * - flags - vm_area_struct flags describing address space
  82. *
  83. * It is assumed that:
  84. * - we have a VIPT cache.
  85. */
  86. ENTRY(v6_flush_user_cache_range)
  87. mov pc, lr
  88. /*
  89. * v6_coherent_kern_range(start,end)
  90. *
  91. * Ensure that the I and D caches are coherent within specified
  92. * region. This is typically used when code has been written to
  93. * a memory region, and will be executed.
  94. *
  95. * - start - virtual start address of region
  96. * - end - virtual end address of region
  97. *
  98. * It is assumed that:
  99. * - the Icache does not read data from the write buffer
  100. */
  101. ENTRY(v6_coherent_kern_range)
  102. /* FALLTHROUGH */
  103. /*
  104. * v6_coherent_user_range(start,end)
  105. *
  106. * Ensure that the I and D caches are coherent within specified
  107. * region. This is typically used when code has been written to
  108. * a memory region, and will be executed.
  109. *
  110. * - start - virtual start address of region
  111. * - end - virtual end address of region
  112. *
  113. * It is assumed that:
  114. * - the Icache does not read data from the write buffer
  115. */
  116. ENTRY(v6_coherent_user_range)
  117. UNWIND(.fnstart )
  118. #ifdef HARVARD_CACHE
  119. bic r0, r0, #CACHE_LINE_SIZE - 1
  120. 1:
  121. USER( mcr p15, 0, r0, c7, c10, 1 ) @ clean D line
  122. add r0, r0, #CACHE_LINE_SIZE
  123. 2:
  124. cmp r0, r1
  125. blo 1b
  126. #endif
  127. mov r0, #0
  128. #ifdef HARVARD_CACHE
  129. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  130. #ifndef CONFIG_ARM_ERRATA_411920
  131. mcr p15, 0, r0, c7, c5, 0 @ I+BTB cache invalidate
  132. #else
  133. b v6_icache_inval_all
  134. #endif
  135. #else
  136. mcr p15, 0, r0, c7, c5, 6 @ invalidate BTB
  137. #endif
  138. mov pc, lr
  139. /*
  140. * Fault handling for the cache operation above. If the virtual address in r0
  141. * isn't mapped, just try the next page.
  142. */
  143. 9001:
  144. mov r0, r0, lsr #12
  145. mov r0, r0, lsl #12
  146. add r0, r0, #4096
  147. b 2b
  148. UNWIND(.fnend )
  149. ENDPROC(v6_coherent_user_range)
  150. ENDPROC(v6_coherent_kern_range)
  151. /*
  152. * v6_flush_kern_dcache_area(void *addr, size_t size)
  153. *
  154. * Ensure that the data held in the page kaddr is written back
  155. * to the page in question.
  156. *
  157. * - addr - kernel address
  158. * - size - region size
  159. */
  160. ENTRY(v6_flush_kern_dcache_area)
  161. add r1, r0, r1
  162. bic r0, r0, #D_CACHE_LINE_SIZE - 1
  163. 1:
  164. #ifdef HARVARD_CACHE
  165. mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line
  166. #else
  167. mcr p15, 0, r0, c7, c15, 1 @ clean & invalidate unified line
  168. #endif
  169. add r0, r0, #D_CACHE_LINE_SIZE
  170. cmp r0, r1
  171. blo 1b
  172. #ifdef HARVARD_CACHE
  173. mov r0, #0
  174. mcr p15, 0, r0, c7, c10, 4
  175. #endif
  176. mov pc, lr
  177. /*
  178. * v6_dma_inv_range(start,end)
  179. *
  180. * Invalidate the data cache within the specified region; we will
  181. * be performing a DMA operation in this region and we want to
  182. * purge old data in the cache.
  183. *
  184. * - start - virtual start address of region
  185. * - end - virtual end address of region
  186. */
  187. v6_dma_inv_range:
  188. #ifdef CONFIG_DMA_CACHE_RWFO
  189. ldrb r2, [r0] @ read for ownership
  190. strb r2, [r0] @ write for ownership
  191. #endif
  192. tst r0, #D_CACHE_LINE_SIZE - 1
  193. bic r0, r0, #D_CACHE_LINE_SIZE - 1
  194. #ifdef HARVARD_CACHE
  195. mcrne p15, 0, r0, c7, c10, 1 @ clean D line
  196. #else
  197. mcrne p15, 0, r0, c7, c11, 1 @ clean unified line
  198. #endif
  199. tst r1, #D_CACHE_LINE_SIZE - 1
  200. #ifdef CONFIG_DMA_CACHE_RWFO
  201. ldrneb r2, [r1, #-1] @ read for ownership
  202. strneb r2, [r1, #-1] @ write for ownership
  203. #endif
  204. bic r1, r1, #D_CACHE_LINE_SIZE - 1
  205. #ifdef HARVARD_CACHE
  206. mcrne p15, 0, r1, c7, c14, 1 @ clean & invalidate D line
  207. #else
  208. mcrne p15, 0, r1, c7, c15, 1 @ clean & invalidate unified line
  209. #endif
  210. 1:
  211. #ifdef HARVARD_CACHE
  212. mcr p15, 0, r0, c7, c6, 1 @ invalidate D line
  213. #else
  214. mcr p15, 0, r0, c7, c7, 1 @ invalidate unified line
  215. #endif
  216. add r0, r0, #D_CACHE_LINE_SIZE
  217. cmp r0, r1
  218. #ifdef CONFIG_DMA_CACHE_RWFO
  219. ldrlo r2, [r0] @ read for ownership
  220. strlo r2, [r0] @ write for ownership
  221. #endif
  222. blo 1b
  223. mov r0, #0
  224. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  225. mov pc, lr
  226. /*
  227. * v6_dma_clean_range(start,end)
  228. * - start - virtual start address of region
  229. * - end - virtual end address of region
  230. */
  231. v6_dma_clean_range:
  232. bic r0, r0, #D_CACHE_LINE_SIZE - 1
  233. 1:
  234. #ifdef CONFIG_DMA_CACHE_RWFO
  235. ldr r2, [r0] @ read for ownership
  236. #endif
  237. #ifdef HARVARD_CACHE
  238. mcr p15, 0, r0, c7, c10, 1 @ clean D line
  239. #else
  240. mcr p15, 0, r0, c7, c11, 1 @ clean unified line
  241. #endif
  242. add r0, r0, #D_CACHE_LINE_SIZE
  243. cmp r0, r1
  244. blo 1b
  245. mov r0, #0
  246. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  247. mov pc, lr
  248. /*
  249. * v6_dma_flush_range(start,end)
  250. * - start - virtual start address of region
  251. * - end - virtual end address of region
  252. */
  253. ENTRY(v6_dma_flush_range)
  254. #ifdef CONFIG_CACHE_FLUSH_RANGE_LIMIT
  255. sub r2, r1, r0
  256. cmp r2, #CONFIG_CACHE_FLUSH_RANGE_LIMIT
  257. bhi v6_dma_flush_dcache_all
  258. #endif
  259. bic r0, r0, #D_CACHE_LINE_SIZE - 1
  260. 1:
  261. #ifdef CONFIG_DMA_CACHE_RWFO
  262. ldr r2, [r0] @ read for ownership
  263. str r2, [r0] @ write for ownership
  264. #endif
  265. #ifdef HARVARD_CACHE
  266. mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line
  267. #else
  268. mcr p15, 0, r0, c7, c15, 1 @ clean & invalidate line
  269. #endif
  270. add r0, r0, #D_CACHE_LINE_SIZE
  271. cmp r0, r1
  272. #ifdef CONFIG_DMA_CACHE_RWFO
  273. ldrlob r2, [r0] @ read for ownership
  274. strlob r2, [r0] @ write for ownership
  275. #endif
  276. blo 1b
  277. mov r0, #0
  278. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  279. mov pc, lr
  280. #ifdef CONFIG_CACHE_FLUSH_RANGE_LIMIT
  281. v6_dma_flush_dcache_all:
  282. mov r0, #0
  283. #ifdef HARVARD_CACHE
  284. mcr p15, 0, r0, c7, c14, 0 @ D cache clean+invalidate
  285. #else
  286. mcr p15, 0, r0, c7, c15, 0 @ Cache clean+invalidate
  287. #endif
  288. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  289. mov pc, lr
  290. #endif
  291. /*
  292. * dma_map_area(start, size, dir)
  293. * - start - kernel virtual start address
  294. * - size - size of region
  295. * - dir - DMA direction
  296. */
  297. ENTRY(v6_dma_map_area)
  298. add r1, r1, r0
  299. teq r2, #DMA_FROM_DEVICE
  300. beq v6_dma_inv_range
  301. #ifndef CONFIG_DMA_CACHE_RWFO
  302. b v6_dma_clean_range
  303. #else
  304. teq r2, #DMA_TO_DEVICE
  305. beq v6_dma_clean_range
  306. b v6_dma_flush_range
  307. #endif
  308. ENDPROC(v6_dma_map_area)
  309. /*
  310. * dma_unmap_area(start, size, dir)
  311. * - start - kernel virtual start address
  312. * - size - size of region
  313. * - dir - DMA direction
  314. */
  315. ENTRY(v6_dma_unmap_area)
  316. #ifndef CONFIG_DMA_CACHE_RWFO
  317. add r1, r1, r0
  318. teq r2, #DMA_TO_DEVICE
  319. bne v6_dma_inv_range
  320. #endif
  321. mov pc, lr
  322. ENDPROC(v6_dma_unmap_area)
  323. __INITDATA
  324. .type v6_cache_fns, #object
  325. ENTRY(v6_cache_fns)
  326. .long v6_flush_kern_cache_all
  327. .long v6_flush_user_cache_all
  328. .long v6_flush_user_cache_range
  329. .long v6_coherent_kern_range
  330. .long v6_coherent_user_range
  331. .long v6_flush_kern_dcache_area
  332. .long v6_dma_map_area
  333. .long v6_dma_unmap_area
  334. .long v6_dma_flush_range
  335. .size v6_cache_fns, . - v6_cache_fns