proc-arm940.S 9.5 KB

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