proc-arm946.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. /*
  2. * linux/arch/arm/mm/arm946.S: utility functions for ARM946E-S
  3. *
  4. * Copyright (C) 2004-2006 Hyok S. Choi (hyok.choi@samsung.com)
  5. *
  6. * (Many of cache codes are from proc-arm926.S)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. */
  13. #include <linux/linkage.h>
  14. #include <linux/init.h>
  15. #include <asm/assembler.h>
  16. #include <asm/hwcap.h>
  17. #include <asm/pgtable-hwdef.h>
  18. #include <asm/pgtable.h>
  19. #include <asm/ptrace.h>
  20. #include "proc-macros.S"
  21. /*
  22. * ARM946E-S is synthesizable to have 0KB to 1MB sized D-Cache,
  23. * comprising 256 lines of 32 bytes (8 words).
  24. */
  25. #define CACHE_DSIZE (CONFIG_CPU_DCACHE_SIZE) /* typically 8KB. */
  26. #define CACHE_DLINESIZE 32 /* fixed */
  27. #define CACHE_DSEGMENTS 4 /* fixed */
  28. #define CACHE_DENTRIES (CACHE_DSIZE / CACHE_DSEGMENTS / CACHE_DLINESIZE)
  29. #define CACHE_DLIMIT (CACHE_DSIZE * 4) /* benchmark needed */
  30. .text
  31. /*
  32. * cpu_arm946_proc_init()
  33. * cpu_arm946_switch_mm()
  34. *
  35. * These are not required.
  36. */
  37. ENTRY(cpu_arm946_proc_init)
  38. ENTRY(cpu_arm946_switch_mm)
  39. ret lr
  40. /*
  41. * cpu_arm946_proc_fin()
  42. */
  43. ENTRY(cpu_arm946_proc_fin)
  44. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  45. bic r0, r0, #0x00001000 @ i-cache
  46. bic r0, r0, #0x00000004 @ d-cache
  47. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  48. ret lr
  49. /*
  50. * cpu_arm946_reset(loc)
  51. * Params : r0 = address to jump to
  52. * Notes : This sets up everything for a reset
  53. */
  54. .pushsection .idmap.text, "ax"
  55. ENTRY(cpu_arm946_reset)
  56. mov ip, #0
  57. mcr p15, 0, ip, c7, c5, 0 @ flush I cache
  58. mcr p15, 0, ip, c7, c6, 0 @ flush D cache
  59. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  60. mrc p15, 0, ip, c1, c0, 0 @ ctrl register
  61. bic ip, ip, #0x00000005 @ .............c.p
  62. bic ip, ip, #0x00001000 @ i-cache
  63. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  64. ret r0
  65. ENDPROC(cpu_arm946_reset)
  66. .popsection
  67. /*
  68. * cpu_arm946_do_idle()
  69. */
  70. .align 5
  71. ENTRY(cpu_arm946_do_idle)
  72. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  73. ret lr
  74. /*
  75. * flush_icache_all()
  76. *
  77. * Unconditionally clean and invalidate the entire icache.
  78. */
  79. ENTRY(arm946_flush_icache_all)
  80. mov r0, #0
  81. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  82. ret lr
  83. ENDPROC(arm946_flush_icache_all)
  84. /*
  85. * flush_user_cache_all()
  86. */
  87. ENTRY(arm946_flush_user_cache_all)
  88. /* FALLTHROUGH */
  89. /*
  90. * flush_kern_cache_all()
  91. *
  92. * Clean and invalidate the entire cache.
  93. */
  94. ENTRY(arm946_flush_kern_cache_all)
  95. mov r2, #VM_EXEC
  96. mov ip, #0
  97. __flush_whole_cache:
  98. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  99. mcr p15, 0, ip, c7, c6, 0 @ flush D cache
  100. #else
  101. mov r1, #(CACHE_DSEGMENTS - 1) << 29 @ 4 segments
  102. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 4 @ n entries
  103. 2: mcr p15, 0, r3, c7, c14, 2 @ clean/flush D index
  104. subs r3, r3, #1 << 4
  105. bcs 2b @ entries n to 0
  106. subs r1, r1, #1 << 29
  107. bcs 1b @ segments 3 to 0
  108. #endif
  109. tst r2, #VM_EXEC
  110. mcrne p15, 0, ip, c7, c5, 0 @ flush I cache
  111. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  112. ret lr
  113. /*
  114. * flush_user_cache_range(start, end, flags)
  115. *
  116. * Clean and invalidate a range of cache entries in the
  117. * specified address range.
  118. *
  119. * - start - start address (inclusive)
  120. * - end - end address (exclusive)
  121. * - flags - vm_flags describing address space
  122. * (same as arm926)
  123. */
  124. ENTRY(arm946_flush_user_cache_range)
  125. mov ip, #0
  126. sub r3, r1, r0 @ calculate total size
  127. cmp r3, #CACHE_DLIMIT
  128. bhs __flush_whole_cache
  129. 1: tst r2, #VM_EXEC
  130. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  131. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  132. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  133. add r0, r0, #CACHE_DLINESIZE
  134. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  135. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  136. add r0, r0, #CACHE_DLINESIZE
  137. #else
  138. mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  139. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  140. add r0, r0, #CACHE_DLINESIZE
  141. mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  142. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  143. add r0, r0, #CACHE_DLINESIZE
  144. #endif
  145. cmp r0, r1
  146. blo 1b
  147. tst r2, #VM_EXEC
  148. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  149. ret lr
  150. /*
  151. * coherent_kern_range(start, end)
  152. *
  153. * Ensure coherency between the Icache and the Dcache in the
  154. * region described by start, end. If you have non-snooping
  155. * Harvard caches, you need to implement this function.
  156. *
  157. * - start - virtual start address
  158. * - end - virtual end address
  159. */
  160. ENTRY(arm946_coherent_kern_range)
  161. /* FALLTHROUGH */
  162. /*
  163. * coherent_user_range(start, end)
  164. *
  165. * Ensure coherency between the Icache and the Dcache in the
  166. * region described by start, end. If you have non-snooping
  167. * Harvard caches, you need to implement this function.
  168. *
  169. * - start - virtual start address
  170. * - end - virtual end address
  171. * (same as arm926)
  172. */
  173. ENTRY(arm946_coherent_user_range)
  174. bic r0, r0, #CACHE_DLINESIZE - 1
  175. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  176. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  177. add r0, r0, #CACHE_DLINESIZE
  178. cmp r0, r1
  179. blo 1b
  180. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  181. mov r0, #0
  182. ret lr
  183. /*
  184. * flush_kern_dcache_area(void *addr, size_t size)
  185. *
  186. * Ensure no D cache aliasing occurs, either with itself or
  187. * the I cache
  188. *
  189. * - addr - kernel address
  190. * - size - region size
  191. * (same as arm926)
  192. */
  193. ENTRY(arm946_flush_kern_dcache_area)
  194. add r1, r0, r1
  195. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  196. add r0, r0, #CACHE_DLINESIZE
  197. cmp r0, r1
  198. blo 1b
  199. mov r0, #0
  200. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  201. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  202. ret lr
  203. /*
  204. * dma_inv_range(start, end)
  205. *
  206. * Invalidate (discard) the specified virtual address range.
  207. * May not write back any entries. If 'start' or 'end'
  208. * are not cache line aligned, those lines must be written
  209. * back.
  210. *
  211. * - start - virtual start address
  212. * - end - virtual end address
  213. * (same as arm926)
  214. */
  215. arm946_dma_inv_range:
  216. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  217. tst r0, #CACHE_DLINESIZE - 1
  218. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  219. tst r1, #CACHE_DLINESIZE - 1
  220. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  221. #endif
  222. bic r0, r0, #CACHE_DLINESIZE - 1
  223. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  224. add r0, r0, #CACHE_DLINESIZE
  225. cmp r0, r1
  226. blo 1b
  227. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  228. ret lr
  229. /*
  230. * dma_clean_range(start, end)
  231. *
  232. * Clean the specified virtual address range.
  233. *
  234. * - start - virtual start address
  235. * - end - virtual end address
  236. *
  237. * (same as arm926)
  238. */
  239. arm946_dma_clean_range:
  240. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  241. bic r0, r0, #CACHE_DLINESIZE - 1
  242. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  243. add r0, r0, #CACHE_DLINESIZE
  244. cmp r0, r1
  245. blo 1b
  246. #endif
  247. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  248. ret lr
  249. /*
  250. * dma_flush_range(start, end)
  251. *
  252. * Clean and invalidate the specified virtual address range.
  253. *
  254. * - start - virtual start address
  255. * - end - virtual end address
  256. *
  257. * (same as arm926)
  258. */
  259. ENTRY(arm946_dma_flush_range)
  260. bic r0, r0, #CACHE_DLINESIZE - 1
  261. 1:
  262. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  263. mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  264. #else
  265. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  266. #endif
  267. add r0, r0, #CACHE_DLINESIZE
  268. cmp r0, r1
  269. blo 1b
  270. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  271. ret lr
  272. /*
  273. * dma_map_area(start, size, dir)
  274. * - start - kernel virtual start address
  275. * - size - size of region
  276. * - dir - DMA direction
  277. */
  278. ENTRY(arm946_dma_map_area)
  279. add r1, r1, r0
  280. cmp r2, #DMA_TO_DEVICE
  281. beq arm946_dma_clean_range
  282. bcs arm946_dma_inv_range
  283. b arm946_dma_flush_range
  284. ENDPROC(arm946_dma_map_area)
  285. /*
  286. * dma_unmap_area(start, size, dir)
  287. * - start - kernel virtual start address
  288. * - size - size of region
  289. * - dir - DMA direction
  290. */
  291. ENTRY(arm946_dma_unmap_area)
  292. ret lr
  293. ENDPROC(arm946_dma_unmap_area)
  294. .globl arm946_flush_kern_cache_louis
  295. .equ arm946_flush_kern_cache_louis, arm946_flush_kern_cache_all
  296. @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
  297. define_cache_functions arm946
  298. ENTRY(cpu_arm946_dcache_clean_area)
  299. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  300. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  301. add r0, r0, #CACHE_DLINESIZE
  302. subs r1, r1, #CACHE_DLINESIZE
  303. bhi 1b
  304. #endif
  305. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  306. ret lr
  307. .type __arm946_setup, #function
  308. __arm946_setup:
  309. mov r0, #0
  310. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  311. mcr p15, 0, r0, c7, c6, 0 @ invalidate D cache
  312. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  313. mcr p15, 0, r0, c6, c3, 0 @ disable memory region 3~7
  314. mcr p15, 0, r0, c6, c4, 0
  315. mcr p15, 0, r0, c6, c5, 0
  316. mcr p15, 0, r0, c6, c6, 0
  317. mcr p15, 0, r0, c6, c7, 0
  318. mov r0, #0x0000003F @ base = 0, size = 4GB
  319. mcr p15, 0, r0, c6, c0, 0 @ set region 0, default
  320. ldr r0, =(CONFIG_DRAM_BASE & 0xFFFFF000) @ base[31:12] of RAM
  321. ldr r7, =CONFIG_DRAM_SIZE @ size of RAM (must be >= 4KB)
  322. pr_val r3, r0, r7, #1
  323. mcr p15, 0, r3, c6, c1, 0
  324. ldr r0, =(CONFIG_FLASH_MEM_BASE & 0xFFFFF000) @ base[31:12] of FLASH
  325. ldr r7, =CONFIG_FLASH_SIZE @ size of FLASH (must be >= 4KB)
  326. pr_val r3, r0, r7, #1
  327. mcr p15, 0, r3, c6, c2, 0
  328. mov r0, #0x06
  329. mcr p15, 0, r0, c2, c0, 0 @ region 1,2 d-cacheable
  330. mcr p15, 0, r0, c2, c0, 1 @ region 1,2 i-cacheable
  331. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  332. mov r0, #0x00 @ disable whole write buffer
  333. #else
  334. mov r0, #0x02 @ region 1 write bufferred
  335. #endif
  336. mcr p15, 0, r0, c3, c0, 0
  337. /*
  338. * Access Permission Settings for future permission control by PU.
  339. *
  340. * priv. user
  341. * region 0 (whole) rw -- : b0001
  342. * region 1 (RAM) rw rw : b0011
  343. * region 2 (FLASH) rw r- : b0010
  344. * region 3~7 (none) -- -- : b0000
  345. */
  346. mov r0, #0x00000031
  347. orr r0, r0, #0x00000200
  348. mcr p15, 0, r0, c5, c0, 2 @ set data access permission
  349. mcr p15, 0, r0, c5, c0, 3 @ set inst. access permission
  350. mrc p15, 0, r0, c1, c0 @ get control register
  351. orr r0, r0, #0x00001000 @ I-cache
  352. orr r0, r0, #0x00000005 @ MPU/D-cache
  353. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  354. orr r0, r0, #0x00004000 @ .1.. .... .... ....
  355. #endif
  356. ret lr
  357. .size __arm946_setup, . - __arm946_setup
  358. __INITDATA
  359. @ define struct processor (see <asm/proc-fns.h> and proc-macros.S)
  360. define_processor_functions arm946, dabort=nommu_early_abort, pabort=legacy_pabort, nommu=1
  361. .section ".rodata"
  362. string cpu_arch_name, "armv5te"
  363. string cpu_elf_name, "v5t"
  364. string cpu_arm946_name, "ARM946E-S"
  365. .align
  366. .section ".proc.info.init", #alloc
  367. .type __arm946_proc_info,#object
  368. __arm946_proc_info:
  369. .long 0x41009460
  370. .long 0xff00fff0
  371. .long 0
  372. .long 0
  373. initfn __arm946_setup, __arm946_proc_info
  374. .long cpu_arch_name
  375. .long cpu_elf_name
  376. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
  377. .long cpu_arm946_name
  378. .long arm946_processor_functions
  379. .long 0
  380. .long 0
  381. .long arm946_cache_fns
  382. .size __arm946_proc_info, . - __arm946_proc_info