proc-arm940.S 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /*
  2. * linux/arch/arm/mm/arm940.S: utility functions for ARM940T
  3. *
  4. * Copyright (C) 2004-2006 Hyok S. Choi (hyok.choi@samsung.com)
  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. */
  11. #include <linux/linkage.h>
  12. #include <linux/init.h>
  13. #include <asm/assembler.h>
  14. #include <asm/hwcap.h>
  15. #include <asm/pgtable-hwdef.h>
  16. #include <asm/pgtable.h>
  17. #include <asm/ptrace.h>
  18. #include "proc-macros.S"
  19. /* ARM940T has a 4KB DCache comprising 256 lines of 4 words */
  20. #define CACHE_DLINESIZE 16
  21. #define CACHE_DSEGMENTS 4
  22. #define CACHE_DENTRIES 64
  23. .text
  24. /*
  25. * cpu_arm940_proc_init()
  26. * cpu_arm940_switch_mm()
  27. *
  28. * These are not required.
  29. */
  30. ENTRY(cpu_arm940_proc_init)
  31. ENTRY(cpu_arm940_switch_mm)
  32. mov pc, lr
  33. /*
  34. * cpu_arm940_proc_fin()
  35. */
  36. ENTRY(cpu_arm940_proc_fin)
  37. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  38. bic r0, r0, #0x00001000 @ i-cache
  39. bic r0, r0, #0x00000004 @ d-cache
  40. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  41. mov pc, lr
  42. /*
  43. * cpu_arm940_reset(loc)
  44. * Params : r0 = address to jump to
  45. * Notes : This sets up everything for a reset
  46. */
  47. ENTRY(cpu_arm940_reset)
  48. mov ip, #0
  49. mcr p15, 0, ip, c7, c5, 0 @ flush I cache
  50. mcr p15, 0, ip, c7, c6, 0 @ flush D cache
  51. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  52. mrc p15, 0, ip, c1, c0, 0 @ ctrl register
  53. bic ip, ip, #0x00000005 @ .............c.p
  54. bic ip, ip, #0x00001000 @ i-cache
  55. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  56. mov pc, r0
  57. /*
  58. * cpu_arm940_do_idle()
  59. */
  60. .align 5
  61. ENTRY(cpu_arm940_do_idle)
  62. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  63. mov pc, lr
  64. /*
  65. * flush_user_cache_all()
  66. */
  67. ENTRY(arm940_flush_user_cache_all)
  68. /* FALLTHROUGH */
  69. /*
  70. * flush_kern_cache_all()
  71. *
  72. * Clean and invalidate the entire cache.
  73. */
  74. ENTRY(arm940_flush_kern_cache_all)
  75. mov r2, #VM_EXEC
  76. /* FALLTHROUGH */
  77. /*
  78. * flush_user_cache_range(start, end, flags)
  79. *
  80. * There is no efficient way to flush a range of cache entries
  81. * in the specified address range. Thus, flushes all.
  82. *
  83. * - start - start address (inclusive)
  84. * - end - end address (exclusive)
  85. * - flags - vm_flags describing address space
  86. */
  87. ENTRY(arm940_flush_user_cache_range)
  88. mov ip, #0
  89. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  90. mcr p15, 0, ip, c7, c6, 0 @ flush D cache
  91. #else
  92. mov r1, #(CACHE_DSEGMENTS - 1) << 4 @ 4 segments
  93. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  94. 2: mcr p15, 0, r3, c7, c14, 2 @ clean/flush D index
  95. subs r3, r3, #1 << 26
  96. bcs 2b @ entries 63 to 0
  97. subs r1, r1, #1 << 4
  98. bcs 1b @ segments 3 to 0
  99. #endif
  100. tst r2, #VM_EXEC
  101. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  102. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  103. mov pc, lr
  104. /*
  105. * coherent_kern_range(start, end)
  106. *
  107. * Ensure coherency between the Icache and the Dcache in the
  108. * region described by start, end. If you have non-snooping
  109. * Harvard caches, you need to implement this function.
  110. *
  111. * - start - virtual start address
  112. * - end - virtual end address
  113. */
  114. ENTRY(arm940_coherent_kern_range)
  115. /* FALLTHROUGH */
  116. /*
  117. * coherent_user_range(start, end)
  118. *
  119. * Ensure coherency between the Icache and the Dcache in the
  120. * region described by start, end. If you have non-snooping
  121. * Harvard caches, you need to implement this function.
  122. *
  123. * - start - virtual start address
  124. * - end - virtual end address
  125. */
  126. ENTRY(arm940_coherent_user_range)
  127. /* FALLTHROUGH */
  128. /*
  129. * flush_kern_dcache_area(void *addr, size_t size)
  130. *
  131. * Ensure no D cache aliasing occurs, either with itself or
  132. * the I cache
  133. *
  134. * - addr - kernel address
  135. * - size - region size
  136. */
  137. ENTRY(arm940_flush_kern_dcache_area)
  138. mov ip, #0
  139. mov r1, #(CACHE_DSEGMENTS - 1) << 4 @ 4 segments
  140. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  141. 2: mcr p15, 0, r3, c7, c14, 2 @ clean/flush D index
  142. subs r3, r3, #1 << 26
  143. bcs 2b @ entries 63 to 0
  144. subs r1, r1, #1 << 4
  145. bcs 1b @ segments 7 to 0
  146. mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
  147. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  148. mov pc, lr
  149. /*
  150. * dma_inv_range(start, end)
  151. *
  152. * There is no efficient way to invalidate a specifid virtual
  153. * address range. Thus, invalidates all.
  154. *
  155. * - start - virtual start address
  156. * - end - virtual end address
  157. */
  158. arm940_dma_inv_range:
  159. mov ip, #0
  160. mov r1, #(CACHE_DSEGMENTS - 1) << 4 @ 4 segments
  161. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  162. 2: mcr p15, 0, r3, c7, c6, 2 @ flush D entry
  163. subs r3, r3, #1 << 26
  164. bcs 2b @ entries 63 to 0
  165. subs r1, r1, #1 << 4
  166. bcs 1b @ segments 7 to 0
  167. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  168. mov pc, lr
  169. /*
  170. * dma_clean_range(start, end)
  171. *
  172. * There is no efficient way to clean a specifid virtual
  173. * address range. Thus, cleans all.
  174. *
  175. * - start - virtual start address
  176. * - end - virtual end address
  177. */
  178. arm940_dma_clean_range:
  179. ENTRY(cpu_arm940_dcache_clean_area)
  180. mov ip, #0
  181. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  182. mov r1, #(CACHE_DSEGMENTS - 1) << 4 @ 4 segments
  183. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  184. 2: mcr p15, 0, r3, c7, c10, 2 @ clean D entry
  185. subs r3, r3, #1 << 26
  186. bcs 2b @ entries 63 to 0
  187. subs r1, r1, #1 << 4
  188. bcs 1b @ segments 7 to 0
  189. #endif
  190. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  191. mov pc, lr
  192. /*
  193. * dma_flush_range(start, end)
  194. *
  195. * There is no efficient way to clean and invalidate a specifid
  196. * virtual address range.
  197. *
  198. * - start - virtual start address
  199. * - end - virtual end address
  200. */
  201. ENTRY(arm940_dma_flush_range)
  202. mov ip, #0
  203. mov r1, #(CACHE_DSEGMENTS - 1) << 4 @ 4 segments
  204. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  205. 2:
  206. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  207. mcr p15, 0, r3, c7, c14, 2 @ clean/flush D entry
  208. #else
  209. mcr p15, 0, r3, c7, c6, 2 @ invalidate D entry
  210. #endif
  211. subs r3, r3, #1 << 26
  212. bcs 2b @ entries 63 to 0
  213. subs r1, r1, #1 << 4
  214. bcs 1b @ segments 7 to 0
  215. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  216. mov pc, lr
  217. /*
  218. * dma_map_area(start, size, dir)
  219. * - start - kernel virtual start address
  220. * - size - size of region
  221. * - dir - DMA direction
  222. */
  223. ENTRY(arm940_dma_map_area)
  224. add r1, r1, r0
  225. cmp r2, #DMA_TO_DEVICE
  226. beq arm940_dma_clean_range
  227. bcs arm940_dma_inv_range
  228. b arm940_dma_flush_range
  229. ENDPROC(arm940_dma_map_area)
  230. /*
  231. * dma_unmap_area(start, size, dir)
  232. * - start - kernel virtual start address
  233. * - size - size of region
  234. * - dir - DMA direction
  235. */
  236. ENTRY(arm940_dma_unmap_area)
  237. mov pc, lr
  238. ENDPROC(arm940_dma_unmap_area)
  239. ENTRY(arm940_cache_fns)
  240. .long arm940_flush_kern_cache_all
  241. .long arm940_flush_user_cache_all
  242. .long arm940_flush_user_cache_range
  243. .long arm940_coherent_kern_range
  244. .long arm940_coherent_user_range
  245. .long arm940_flush_kern_dcache_area
  246. .long arm940_dma_map_area
  247. .long arm940_dma_unmap_area
  248. .long arm940_dma_flush_range
  249. __INIT
  250. .type __arm940_setup, #function
  251. __arm940_setup:
  252. mov r0, #0
  253. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  254. mcr p15, 0, r0, c7, c6, 0 @ invalidate D cache
  255. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  256. mcr p15, 0, r0, c6, c3, 0 @ disable data area 3~7
  257. mcr p15, 0, r0, c6, c4, 0
  258. mcr p15, 0, r0, c6, c5, 0
  259. mcr p15, 0, r0, c6, c6, 0
  260. mcr p15, 0, r0, c6, c7, 0
  261. mcr p15, 0, r0, c6, c3, 1 @ disable instruction area 3~7
  262. mcr p15, 0, r0, c6, c4, 1
  263. mcr p15, 0, r0, c6, c5, 1
  264. mcr p15, 0, r0, c6, c6, 1
  265. mcr p15, 0, r0, c6, c7, 1
  266. mov r0, #0x0000003F @ base = 0, size = 4GB
  267. mcr p15, 0, r0, c6, c0, 0 @ set area 0, default
  268. mcr p15, 0, r0, c6, c0, 1
  269. ldr r0, =(CONFIG_DRAM_BASE & 0xFFFFF000) @ base[31:12] of RAM
  270. ldr r1, =(CONFIG_DRAM_SIZE >> 12) @ size of RAM (must be >= 4KB)
  271. mov r2, #10 @ 11 is the minimum (4KB)
  272. 1: add r2, r2, #1 @ area size *= 2
  273. mov r1, r1, lsr #1
  274. bne 1b @ count not zero r-shift
  275. orr r0, r0, r2, lsl #1 @ the area register value
  276. orr r0, r0, #1 @ set enable bit
  277. mcr p15, 0, r0, c6, c1, 0 @ set area 1, RAM
  278. mcr p15, 0, r0, c6, c1, 1
  279. ldr r0, =(CONFIG_FLASH_MEM_BASE & 0xFFFFF000) @ base[31:12] of FLASH
  280. ldr r1, =(CONFIG_FLASH_SIZE >> 12) @ size of FLASH (must be >= 4KB)
  281. mov r2, #10 @ 11 is the minimum (4KB)
  282. 1: add r2, r2, #1 @ area size *= 2
  283. mov r1, r1, lsr #1
  284. bne 1b @ count not zero r-shift
  285. orr r0, r0, r2, lsl #1 @ the area register value
  286. orr r0, r0, #1 @ set enable bit
  287. mcr p15, 0, r0, c6, c2, 0 @ set area 2, ROM/FLASH
  288. mcr p15, 0, r0, c6, c2, 1
  289. mov r0, #0x06
  290. mcr p15, 0, r0, c2, c0, 0 @ Region 1&2 cacheable
  291. mcr p15, 0, r0, c2, c0, 1
  292. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  293. mov r0, #0x00 @ disable whole write buffer
  294. #else
  295. mov r0, #0x02 @ Region 1 write bufferred
  296. #endif
  297. mcr p15, 0, r0, c3, c0, 0
  298. mov r0, #0x10000
  299. sub r0, r0, #1 @ r0 = 0xffff
  300. mcr p15, 0, r0, c5, c0, 0 @ all read/write access
  301. mcr p15, 0, r0, c5, c0, 1
  302. mrc p15, 0, r0, c1, c0 @ get control register
  303. orr r0, r0, #0x00001000 @ I-cache
  304. orr r0, r0, #0x00000005 @ MPU/D-cache
  305. mov pc, lr
  306. .size __arm940_setup, . - __arm940_setup
  307. __INITDATA
  308. /*
  309. * Purpose : Function pointers used to access above functions - all calls
  310. * come through these
  311. */
  312. .type arm940_processor_functions, #object
  313. ENTRY(arm940_processor_functions)
  314. .word nommu_early_abort
  315. .word legacy_pabort
  316. .word cpu_arm940_proc_init
  317. .word cpu_arm940_proc_fin
  318. .word cpu_arm940_reset
  319. .word cpu_arm940_do_idle
  320. .word cpu_arm940_dcache_clean_area
  321. .word cpu_arm940_switch_mm
  322. .word 0 @ cpu_*_set_pte
  323. .size arm940_processor_functions, . - arm940_processor_functions
  324. .section ".rodata"
  325. .type cpu_arch_name, #object
  326. cpu_arch_name:
  327. .asciz "armv4t"
  328. .size cpu_arch_name, . - cpu_arch_name
  329. .type cpu_elf_name, #object
  330. cpu_elf_name:
  331. .asciz "v4"
  332. .size cpu_elf_name, . - cpu_elf_name
  333. .type cpu_arm940_name, #object
  334. cpu_arm940_name:
  335. .ascii "ARM940T"
  336. .size cpu_arm940_name, . - cpu_arm940_name
  337. .align
  338. .section ".proc.info.init", #alloc, #execinstr
  339. .type __arm940_proc_info,#object
  340. __arm940_proc_info:
  341. .long 0x41009400
  342. .long 0xff00fff0
  343. .long 0
  344. b __arm940_setup
  345. .long cpu_arch_name
  346. .long cpu_elf_name
  347. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
  348. .long cpu_arm940_name
  349. .long arm940_processor_functions
  350. .long 0
  351. .long 0
  352. .long arm940_cache_fns
  353. .size __arm940_proc_info, . - __arm940_proc_info