proc-arm1020e.S 11 KB

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