proc-arm940.S 9.4 KB

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