proc-arm1020.S 13 KB

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