proc-arm1020e.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * linux/arch/arm/mm/proc-arm1020e.S: MMU functions for ARM1020
  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 arm1020e.
  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_arm1020e_proc_init()
  52. */
  53. SYM_TYPED_FUNC_START(cpu_arm1020e_proc_init)
  54. ret lr
  55. SYM_FUNC_END(cpu_arm1020e_proc_init)
  56. /*
  57. * cpu_arm1020e_proc_fin()
  58. */
  59. SYM_TYPED_FUNC_START(cpu_arm1020e_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_arm1020e_proc_fin)
  66. /*
  67. * cpu_arm1020e_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_arm1020e_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_arm1020e_reset)
  90. .popsection
  91. /*
  92. * cpu_arm1020e_do_idle()
  93. */
  94. .align 5
  95. SYM_TYPED_FUNC_START(cpu_arm1020e_do_idle)
  96. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  97. ret lr
  98. SYM_FUNC_END(cpu_arm1020e_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(arm1020e_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(arm1020e_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(arm1020e_flush_user_cache_all, arm1020e_flush_kern_cache_all)
  120. /*
  121. * flush_kern_cache_all()
  122. *
  123. * Clean and invalidate the entire cache.
  124. */
  125. SYM_TYPED_FUNC_START(arm1020e_flush_kern_cache_all)
  126. mov r2, #VM_EXEC
  127. mov ip, #0
  128. __flush_whole_cache:
  129. #ifndef CONFIG_CPU_DCACHE_DISABLE
  130. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  131. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 16 segments
  132. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  133. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  134. subs r3, r3, #1 << 26
  135. bcs 2b @ entries 63 to 0
  136. subs r1, r1, #1 << 5
  137. bcs 1b @ segments 15 to 0
  138. #endif
  139. tst r2, #VM_EXEC
  140. #ifndef CONFIG_CPU_ICACHE_DISABLE
  141. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  142. #endif
  143. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  144. ret lr
  145. SYM_FUNC_END(arm1020e_flush_kern_cache_all)
  146. /*
  147. * flush_user_cache_range(start, end, flags)
  148. *
  149. * Invalidate a range of cache entries in the specified
  150. * address space.
  151. *
  152. * - start - start address (inclusive)
  153. * - end - end address (exclusive)
  154. * - flags - vm_flags for this space
  155. */
  156. SYM_TYPED_FUNC_START(arm1020e_flush_user_cache_range)
  157. mov ip, #0
  158. sub r3, r1, r0 @ calculate total size
  159. cmp r3, #CACHE_DLIMIT
  160. bhs __flush_whole_cache
  161. #ifndef CONFIG_CPU_DCACHE_DISABLE
  162. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  163. add r0, r0, #CACHE_DLINESIZE
  164. cmp r0, r1
  165. blo 1b
  166. #endif
  167. tst r2, #VM_EXEC
  168. #ifndef CONFIG_CPU_ICACHE_DISABLE
  169. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  170. #endif
  171. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  172. ret lr
  173. SYM_FUNC_END(arm1020e_flush_user_cache_range)
  174. /*
  175. * coherent_kern_range(start, end)
  176. *
  177. * Ensure coherency between the Icache and the Dcache in the
  178. * region described by start. If you have non-snooping
  179. * Harvard caches, you need to implement this function.
  180. *
  181. * - start - virtual start address
  182. * - end - virtual end address
  183. */
  184. SYM_TYPED_FUNC_START(arm1020e_coherent_kern_range)
  185. #ifdef CONFIG_CFI_CLANG /* Fallthrough if !CFI */
  186. b arm1020e_coherent_user_range
  187. #endif
  188. SYM_FUNC_END(arm1020e_coherent_kern_range)
  189. /*
  190. * coherent_user_range(start, end)
  191. *
  192. * Ensure coherency between the Icache and the Dcache in the
  193. * region described by start. If you have non-snooping
  194. * Harvard caches, you need to implement this function.
  195. *
  196. * - start - virtual start address
  197. * - end - virtual end address
  198. */
  199. SYM_TYPED_FUNC_START(arm1020e_coherent_user_range)
  200. mov ip, #0
  201. bic r0, r0, #CACHE_DLINESIZE - 1
  202. 1:
  203. #ifndef CONFIG_CPU_DCACHE_DISABLE
  204. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  205. #endif
  206. #ifndef CONFIG_CPU_ICACHE_DISABLE
  207. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  208. #endif
  209. add r0, r0, #CACHE_DLINESIZE
  210. cmp r0, r1
  211. blo 1b
  212. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  213. mov r0, #0
  214. ret lr
  215. SYM_FUNC_END(arm1020e_coherent_user_range)
  216. /*
  217. * flush_kern_dcache_area(void *addr, size_t size)
  218. *
  219. * Ensure no D cache aliasing occurs, either with itself or
  220. * the I cache
  221. *
  222. * - addr - kernel address
  223. * - size - region size
  224. */
  225. SYM_TYPED_FUNC_START(arm1020e_flush_kern_dcache_area)
  226. mov ip, #0
  227. #ifndef CONFIG_CPU_DCACHE_DISABLE
  228. add r1, r0, r1
  229. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  230. add r0, r0, #CACHE_DLINESIZE
  231. cmp r0, r1
  232. blo 1b
  233. #endif
  234. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  235. ret lr
  236. SYM_FUNC_END(arm1020e_flush_kern_dcache_area)
  237. /*
  238. * dma_inv_range(start, end)
  239. *
  240. * Invalidate (discard) the specified virtual address range.
  241. * May not write back any entries. If 'start' or 'end'
  242. * are not cache line aligned, those lines must be written
  243. * back.
  244. *
  245. * - start - virtual start address
  246. * - end - virtual end address
  247. *
  248. * (same as v4wb)
  249. */
  250. arm1020e_dma_inv_range:
  251. mov ip, #0
  252. #ifndef CONFIG_CPU_DCACHE_DISABLE
  253. tst r0, #CACHE_DLINESIZE - 1
  254. bic r0, r0, #CACHE_DLINESIZE - 1
  255. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  256. tst r1, #CACHE_DLINESIZE - 1
  257. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  258. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  259. add r0, r0, #CACHE_DLINESIZE
  260. cmp r0, r1
  261. blo 1b
  262. #endif
  263. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  264. ret lr
  265. /*
  266. * dma_clean_range(start, end)
  267. *
  268. * Clean the specified virtual address range.
  269. *
  270. * - start - virtual start address
  271. * - end - virtual end address
  272. *
  273. * (same as v4wb)
  274. */
  275. arm1020e_dma_clean_range:
  276. mov ip, #0
  277. #ifndef CONFIG_CPU_DCACHE_DISABLE
  278. bic r0, r0, #CACHE_DLINESIZE - 1
  279. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  280. add r0, r0, #CACHE_DLINESIZE
  281. cmp r0, r1
  282. blo 1b
  283. #endif
  284. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  285. ret lr
  286. /*
  287. * dma_flush_range(start, end)
  288. *
  289. * Clean and invalidate the specified virtual address range.
  290. *
  291. * - start - virtual start address
  292. * - end - virtual end address
  293. */
  294. SYM_TYPED_FUNC_START(arm1020e_dma_flush_range)
  295. mov ip, #0
  296. #ifndef CONFIG_CPU_DCACHE_DISABLE
  297. bic r0, r0, #CACHE_DLINESIZE - 1
  298. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  299. add r0, r0, #CACHE_DLINESIZE
  300. cmp r0, r1
  301. blo 1b
  302. #endif
  303. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  304. ret lr
  305. SYM_FUNC_END(arm1020e_dma_flush_range)
  306. /*
  307. * dma_map_area(start, size, dir)
  308. * - start - kernel virtual start address
  309. * - size - size of region
  310. * - dir - DMA direction
  311. */
  312. SYM_TYPED_FUNC_START(arm1020e_dma_map_area)
  313. add r1, r1, r0
  314. cmp r2, #DMA_TO_DEVICE
  315. beq arm1020e_dma_clean_range
  316. bcs arm1020e_dma_inv_range
  317. b arm1020e_dma_flush_range
  318. SYM_FUNC_END(arm1020e_dma_map_area)
  319. /*
  320. * dma_unmap_area(start, size, dir)
  321. * - start - kernel virtual start address
  322. * - size - size of region
  323. * - dir - DMA direction
  324. */
  325. SYM_TYPED_FUNC_START(arm1020e_dma_unmap_area)
  326. ret lr
  327. SYM_FUNC_END(arm1020e_dma_unmap_area)
  328. .align 5
  329. SYM_TYPED_FUNC_START(cpu_arm1020e_dcache_clean_area)
  330. #ifndef CONFIG_CPU_DCACHE_DISABLE
  331. mov ip, #0
  332. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  333. add r0, r0, #CACHE_DLINESIZE
  334. subs r1, r1, #CACHE_DLINESIZE
  335. bhi 1b
  336. #endif
  337. ret lr
  338. SYM_FUNC_END(cpu_arm1020e_dcache_clean_area)
  339. /* =============================== PageTable ============================== */
  340. /*
  341. * cpu_arm1020e_switch_mm(pgd)
  342. *
  343. * Set the translation base pointer to be as described by pgd.
  344. *
  345. * pgd: new page tables
  346. */
  347. .align 5
  348. SYM_TYPED_FUNC_START(cpu_arm1020e_switch_mm)
  349. #ifdef CONFIG_MMU
  350. #ifndef CONFIG_CPU_DCACHE_DISABLE
  351. mcr p15, 0, r3, c7, c10, 4
  352. mov r1, #0xF @ 16 segments
  353. 1: mov r3, #0x3F @ 64 entries
  354. 2: mov ip, r3, LSL #26 @ shift up entry
  355. orr ip, ip, r1, LSL #5 @ shift in/up index
  356. mcr p15, 0, ip, c7, c14, 2 @ Clean & Inval DCache entry
  357. mov ip, #0
  358. subs r3, r3, #1
  359. cmp r3, #0
  360. bge 2b @ entries 3F to 0
  361. subs r1, r1, #1
  362. cmp r1, #0
  363. bge 1b @ segments 15 to 0
  364. #endif
  365. mov r1, #0
  366. #ifndef CONFIG_CPU_ICACHE_DISABLE
  367. mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
  368. #endif
  369. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  370. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  371. mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
  372. #endif
  373. ret lr
  374. SYM_FUNC_END(cpu_arm1020e_switch_mm)
  375. /*
  376. * cpu_arm1020e_set_pte(ptep, pte)
  377. *
  378. * Set a PTE and flush it out
  379. */
  380. .align 5
  381. SYM_TYPED_FUNC_START(cpu_arm1020e_set_pte_ext)
  382. #ifdef CONFIG_MMU
  383. armv3_set_pte_ext
  384. mov r0, r0
  385. #ifndef CONFIG_CPU_DCACHE_DISABLE
  386. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  387. #endif
  388. #endif /* CONFIG_MMU */
  389. ret lr
  390. SYM_FUNC_END(cpu_arm1020e_set_pte_ext)
  391. .type __arm1020e_setup, #function
  392. __arm1020e_setup:
  393. mov r0, #0
  394. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  395. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  396. #ifdef CONFIG_MMU
  397. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  398. #endif
  399. adr r5, arm1020e_crval
  400. ldmia r5, {r5, r6}
  401. mrc p15, 0, r0, c1, c0 @ get control register v4
  402. bic r0, r0, r5
  403. orr r0, r0, r6
  404. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  405. orr r0, r0, #0x4000 @ .R.. .... .... ....
  406. #endif
  407. ret lr
  408. .size __arm1020e_setup, . - __arm1020e_setup
  409. /*
  410. * R
  411. * .RVI ZFRS BLDP WCAM
  412. * .011 1001 ..11 0101
  413. */
  414. .type arm1020e_crval, #object
  415. arm1020e_crval:
  416. crval clear=0x00007f3f, mmuset=0x00003935, ucset=0x00001930
  417. __INITDATA
  418. @ define struct processor (see <asm/proc-fns.h> and proc-macros.S)
  419. define_processor_functions arm1020e, dabort=v4t_early_abort, pabort=legacy_pabort
  420. .section ".rodata"
  421. string cpu_arch_name, "armv5te"
  422. string cpu_elf_name, "v5"
  423. string cpu_arm1020e_name, "ARM1020E"
  424. .align
  425. .section ".proc.info.init", "a"
  426. .type __arm1020e_proc_info,#object
  427. __arm1020e_proc_info:
  428. .long 0x4105a200 @ ARM 1020TE (Architecture v5TE)
  429. .long 0xff0ffff0
  430. .long PMD_TYPE_SECT | \
  431. PMD_BIT4 | \
  432. PMD_SECT_AP_WRITE | \
  433. PMD_SECT_AP_READ
  434. .long PMD_TYPE_SECT | \
  435. PMD_BIT4 | \
  436. PMD_SECT_AP_WRITE | \
  437. PMD_SECT_AP_READ
  438. initfn __arm1020e_setup, __arm1020e_proc_info
  439. .long cpu_arch_name
  440. .long cpu_elf_name
  441. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB | HWCAP_EDSP
  442. .long cpu_arm1020e_name
  443. .long arm1020e_processor_functions
  444. .long v4wbi_tlb_fns
  445. .long v4wb_user_fns
  446. .long arm1020e_cache_fns
  447. .size __arm1020e_proc_info, . - __arm1020e_proc_info