proc-arm922.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * linux/arch/arm/mm/proc-arm922.S: MMU functions for ARM922
  4. *
  5. * Copyright (C) 1999,2000 ARM Limited
  6. * Copyright (C) 2000 Deep Blue Solutions Ltd.
  7. * Copyright (C) 2001 Altera Corporation
  8. * hacked for non-paged-MM by Hyok S. Choi, 2003.
  9. *
  10. * These are the low level assembler for performing cache and TLB
  11. * functions on the arm922.
  12. *
  13. * CONFIG_CPU_ARM922_CPU_IDLE -> nohlt
  14. */
  15. #include <linux/linkage.h>
  16. #include <linux/init.h>
  17. #include <linux/cfi_types.h>
  18. #include <linux/pgtable.h>
  19. #include <asm/assembler.h>
  20. #include <asm/hwcap.h>
  21. #include <asm/pgtable-hwdef.h>
  22. #include <asm/page.h>
  23. #include <asm/ptrace.h>
  24. #include "proc-macros.S"
  25. /*
  26. * The size of one data cache line.
  27. */
  28. #define CACHE_DLINESIZE 32
  29. /*
  30. * The number of data cache segments.
  31. */
  32. #define CACHE_DSEGMENTS 4
  33. /*
  34. * The number of lines in a cache segment.
  35. */
  36. #define CACHE_DENTRIES 64
  37. /*
  38. * This is the size at which it becomes more efficient to
  39. * clean the whole cache, rather than using the individual
  40. * cache line maintenance instructions. (I think this should
  41. * be 32768).
  42. */
  43. #define CACHE_DLIMIT 8192
  44. .text
  45. /*
  46. * cpu_arm922_proc_init()
  47. */
  48. SYM_TYPED_FUNC_START(cpu_arm922_proc_init)
  49. ret lr
  50. SYM_FUNC_END(cpu_arm922_proc_init)
  51. /*
  52. * cpu_arm922_proc_fin()
  53. */
  54. SYM_TYPED_FUNC_START(cpu_arm922_proc_fin)
  55. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  56. bic r0, r0, #0x1000 @ ...i............
  57. bic r0, r0, #0x000e @ ............wca.
  58. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  59. ret lr
  60. SYM_FUNC_END(cpu_arm922_proc_fin)
  61. /*
  62. * cpu_arm922_reset(loc)
  63. *
  64. * Perform a soft reset of the system. Put the CPU into the
  65. * same state as it would be if it had been reset, and branch
  66. * to what would be the reset vector.
  67. *
  68. * loc: location to jump to for soft reset
  69. */
  70. .align 5
  71. .pushsection .idmap.text, "ax"
  72. SYM_TYPED_FUNC_START(cpu_arm922_reset)
  73. mov ip, #0
  74. mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
  75. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  76. #ifdef CONFIG_MMU
  77. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  78. #endif
  79. mrc p15, 0, ip, c1, c0, 0 @ ctrl register
  80. bic ip, ip, #0x000f @ ............wcam
  81. bic ip, ip, #0x1100 @ ...i...s........
  82. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  83. ret r0
  84. SYM_FUNC_END(cpu_arm922_reset)
  85. .popsection
  86. /*
  87. * cpu_arm922_do_idle()
  88. */
  89. .align 5
  90. SYM_TYPED_FUNC_START(cpu_arm922_do_idle)
  91. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  92. ret lr
  93. SYM_FUNC_END(cpu_arm922_do_idle)
  94. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  95. /*
  96. * flush_icache_all()
  97. *
  98. * Unconditionally clean and invalidate the entire icache.
  99. */
  100. SYM_TYPED_FUNC_START(arm922_flush_icache_all)
  101. mov r0, #0
  102. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  103. ret lr
  104. SYM_FUNC_END(arm922_flush_icache_all)
  105. /*
  106. * flush_user_cache_all()
  107. *
  108. * Clean and invalidate all cache entries in a particular
  109. * address space.
  110. */
  111. SYM_FUNC_ALIAS(arm922_flush_user_cache_all, arm922_flush_kern_cache_all)
  112. /*
  113. * flush_kern_cache_all()
  114. *
  115. * Clean and invalidate the entire cache.
  116. */
  117. SYM_TYPED_FUNC_START(arm922_flush_kern_cache_all)
  118. mov r2, #VM_EXEC
  119. mov ip, #0
  120. __flush_whole_cache:
  121. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 8 segments
  122. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  123. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  124. subs r3, r3, #1 << 26
  125. bcs 2b @ entries 63 to 0
  126. subs r1, r1, #1 << 5
  127. bcs 1b @ segments 7 to 0
  128. tst r2, #VM_EXEC
  129. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  130. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  131. ret lr
  132. SYM_FUNC_END(arm922_flush_kern_cache_all)
  133. /*
  134. * flush_user_cache_range(start, end, flags)
  135. *
  136. * Clean and invalidate a range of cache entries in the
  137. * specified address range.
  138. *
  139. * - start - start address (inclusive)
  140. * - end - end address (exclusive)
  141. * - flags - vm_flags describing address space
  142. */
  143. SYM_TYPED_FUNC_START(arm922_flush_user_cache_range)
  144. mov ip, #0
  145. sub r3, r1, r0 @ calculate total size
  146. cmp r3, #CACHE_DLIMIT
  147. bhs __flush_whole_cache
  148. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  149. tst r2, #VM_EXEC
  150. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  151. add r0, r0, #CACHE_DLINESIZE
  152. cmp r0, r1
  153. blo 1b
  154. tst r2, #VM_EXEC
  155. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  156. ret lr
  157. SYM_FUNC_END(arm922_flush_user_cache_range)
  158. /*
  159. * coherent_kern_range(start, end)
  160. *
  161. * Ensure coherency between the Icache and the Dcache in the
  162. * region described by start, end. If you have non-snooping
  163. * Harvard caches, you need to implement this function.
  164. *
  165. * - start - virtual start address
  166. * - end - virtual end address
  167. */
  168. SYM_TYPED_FUNC_START(arm922_coherent_kern_range)
  169. #ifdef CONFIG_CFI_CLANG /* Fallthrough if !CFI */
  170. b arm922_coherent_user_range
  171. #endif
  172. SYM_FUNC_END(arm922_coherent_kern_range)
  173. /*
  174. * coherent_user_range(start, end)
  175. *
  176. * Ensure coherency between the Icache and the Dcache in the
  177. * region described by start, end. If you have non-snooping
  178. * Harvard caches, you need to implement this function.
  179. *
  180. * - start - virtual start address
  181. * - end - virtual end address
  182. */
  183. SYM_TYPED_FUNC_START(arm922_coherent_user_range)
  184. bic r0, r0, #CACHE_DLINESIZE - 1
  185. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  186. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  187. add r0, r0, #CACHE_DLINESIZE
  188. cmp r0, r1
  189. blo 1b
  190. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  191. mov r0, #0
  192. ret lr
  193. SYM_FUNC_END(arm922_coherent_user_range)
  194. /*
  195. * flush_kern_dcache_area(void *addr, size_t size)
  196. *
  197. * Ensure no D cache aliasing occurs, either with itself or
  198. * the I cache
  199. *
  200. * - addr - kernel address
  201. * - size - region size
  202. */
  203. SYM_TYPED_FUNC_START(arm922_flush_kern_dcache_area)
  204. add r1, r0, r1
  205. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  206. add r0, r0, #CACHE_DLINESIZE
  207. cmp r0, r1
  208. blo 1b
  209. mov r0, #0
  210. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  211. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  212. ret lr
  213. SYM_FUNC_END(arm922_flush_kern_dcache_area)
  214. /*
  215. * dma_inv_range(start, end)
  216. *
  217. * Invalidate (discard) the specified virtual address range.
  218. * May not write back any entries. If 'start' or 'end'
  219. * are not cache line aligned, those lines must be written
  220. * back.
  221. *
  222. * - start - virtual start address
  223. * - end - virtual end address
  224. *
  225. * (same as v4wb)
  226. */
  227. arm922_dma_inv_range:
  228. tst r0, #CACHE_DLINESIZE - 1
  229. bic r0, r0, #CACHE_DLINESIZE - 1
  230. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  231. tst r1, #CACHE_DLINESIZE - 1
  232. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  233. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  234. add r0, r0, #CACHE_DLINESIZE
  235. cmp r0, r1
  236. blo 1b
  237. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  238. ret lr
  239. /*
  240. * dma_clean_range(start, end)
  241. *
  242. * Clean the specified virtual address range.
  243. *
  244. * - start - virtual start address
  245. * - end - virtual end address
  246. *
  247. * (same as v4wb)
  248. */
  249. arm922_dma_clean_range:
  250. bic r0, r0, #CACHE_DLINESIZE - 1
  251. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  252. add r0, r0, #CACHE_DLINESIZE
  253. cmp r0, r1
  254. blo 1b
  255. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  256. ret lr
  257. /*
  258. * dma_flush_range(start, end)
  259. *
  260. * Clean and invalidate the specified virtual address range.
  261. *
  262. * - start - virtual start address
  263. * - end - virtual end address
  264. */
  265. SYM_TYPED_FUNC_START(arm922_dma_flush_range)
  266. bic r0, r0, #CACHE_DLINESIZE - 1
  267. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  268. add r0, r0, #CACHE_DLINESIZE
  269. cmp r0, r1
  270. blo 1b
  271. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  272. ret lr
  273. SYM_FUNC_END(arm922_dma_flush_range)
  274. /*
  275. * dma_map_area(start, size, dir)
  276. * - start - kernel virtual start address
  277. * - size - size of region
  278. * - dir - DMA direction
  279. */
  280. SYM_TYPED_FUNC_START(arm922_dma_map_area)
  281. add r1, r1, r0
  282. cmp r2, #DMA_TO_DEVICE
  283. beq arm922_dma_clean_range
  284. bcs arm922_dma_inv_range
  285. b arm922_dma_flush_range
  286. SYM_FUNC_END(arm922_dma_map_area)
  287. /*
  288. * dma_unmap_area(start, size, dir)
  289. * - start - kernel virtual start address
  290. * - size - size of region
  291. * - dir - DMA direction
  292. */
  293. SYM_TYPED_FUNC_START(arm922_dma_unmap_area)
  294. ret lr
  295. SYM_FUNC_END(arm922_dma_unmap_area)
  296. #endif /* !CONFIG_CPU_DCACHE_WRITETHROUGH */
  297. SYM_TYPED_FUNC_START(cpu_arm922_dcache_clean_area)
  298. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  299. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  300. add r0, r0, #CACHE_DLINESIZE
  301. subs r1, r1, #CACHE_DLINESIZE
  302. bhi 1b
  303. #endif
  304. ret lr
  305. SYM_FUNC_END(cpu_arm922_dcache_clean_area)
  306. /* =============================== PageTable ============================== */
  307. /*
  308. * cpu_arm922_switch_mm(pgd)
  309. *
  310. * Set the translation base pointer to be as described by pgd.
  311. *
  312. * pgd: new page tables
  313. */
  314. .align 5
  315. SYM_TYPED_FUNC_START(cpu_arm922_switch_mm)
  316. #ifdef CONFIG_MMU
  317. mov ip, #0
  318. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  319. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  320. #else
  321. @ && 'Clean & Invalidate whole DCache'
  322. @ && Re-written to use Index Ops.
  323. @ && Uses registers r1, r3 and ip
  324. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 4 segments
  325. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  326. 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
  327. subs r3, r3, #1 << 26
  328. bcs 2b @ entries 63 to 0
  329. subs r1, r1, #1 << 5
  330. bcs 1b @ segments 7 to 0
  331. #endif
  332. mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
  333. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  334. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  335. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  336. #endif
  337. ret lr
  338. SYM_FUNC_END(cpu_arm922_switch_mm)
  339. /*
  340. * cpu_arm922_set_pte_ext(ptep, pte, ext)
  341. *
  342. * Set a PTE and flush it out
  343. */
  344. .align 5
  345. SYM_TYPED_FUNC_START(cpu_arm922_set_pte_ext)
  346. #ifdef CONFIG_MMU
  347. armv3_set_pte_ext
  348. mov r0, r0
  349. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  350. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  351. #endif /* CONFIG_MMU */
  352. ret lr
  353. SYM_FUNC_END(cpu_arm922_set_pte_ext)
  354. .type __arm922_setup, #function
  355. __arm922_setup:
  356. mov r0, #0
  357. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  358. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  359. #ifdef CONFIG_MMU
  360. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  361. #endif
  362. adr r5, arm922_crval
  363. ldmia r5, {r5, r6}
  364. mrc p15, 0, r0, c1, c0 @ get control register v4
  365. bic r0, r0, r5
  366. orr r0, r0, r6
  367. ret lr
  368. .size __arm922_setup, . - __arm922_setup
  369. /*
  370. * R
  371. * .RVI ZFRS BLDP WCAM
  372. * ..11 0001 ..11 0101
  373. *
  374. */
  375. .type arm922_crval, #object
  376. arm922_crval:
  377. crval clear=0x00003f3f, mmuset=0x00003135, ucset=0x00001130
  378. __INITDATA
  379. @ define struct processor (see <asm/proc-fns.h> and proc-macros.S)
  380. define_processor_functions arm922, dabort=v4t_early_abort, pabort=legacy_pabort
  381. .section ".rodata"
  382. string cpu_arch_name, "armv4t"
  383. string cpu_elf_name, "v4"
  384. string cpu_arm922_name, "ARM922T"
  385. .align
  386. .section ".proc.info.init", "a"
  387. .type __arm922_proc_info,#object
  388. __arm922_proc_info:
  389. .long 0x41009220
  390. .long 0xff00fff0
  391. .long PMD_TYPE_SECT | \
  392. PMD_SECT_BUFFERABLE | \
  393. PMD_SECT_CACHEABLE | \
  394. PMD_BIT4 | \
  395. PMD_SECT_AP_WRITE | \
  396. PMD_SECT_AP_READ
  397. .long PMD_TYPE_SECT | \
  398. PMD_BIT4 | \
  399. PMD_SECT_AP_WRITE | \
  400. PMD_SECT_AP_READ
  401. initfn __arm922_setup, __arm922_proc_info
  402. .long cpu_arch_name
  403. .long cpu_elf_name
  404. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
  405. .long cpu_arm922_name
  406. .long arm922_processor_functions
  407. .long v4wbi_tlb_fns
  408. .long v4wb_user_fns
  409. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  410. .long arm922_cache_fns
  411. #else
  412. .long v4wt_cache_fns
  413. #endif
  414. .size __arm922_proc_info, . - __arm922_proc_info