proc-arm1026.S 11 KB

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