proc-arm1022.S 11 KB

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