proc-arm925.S 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * linux/arch/arm/mm/arm925.S: MMU functions for ARM925
  4. *
  5. * Copyright (C) 1999,2000 ARM Limited
  6. * Copyright (C) 2000 Deep Blue Solutions Ltd.
  7. * Copyright (C) 2002 RidgeRun, Inc.
  8. * Copyright (C) 2002-2003 MontaVista Software, Inc.
  9. *
  10. * Update for Linux-2.6 and cache flush improvements
  11. * Copyright (C) 2004 Nokia Corporation by Tony Lindgren <tony@atomide.com>
  12. *
  13. * hacked for non-paged-MM by Hyok S. Choi, 2004.
  14. *
  15. * These are the low level assembler for performing cache and TLB
  16. * functions on the arm925.
  17. *
  18. * CONFIG_CPU_ARM925_CPU_IDLE -> nohlt
  19. *
  20. * Some additional notes based on deciphering the TI TRM on OMAP-5910:
  21. *
  22. * NOTE1: The TI925T Configuration Register bit "D-cache clean and flush
  23. * entry mode" must be 0 to flush the entries in both segments
  24. * at once. This is the default value. See TRM 2-20 and 2-24 for
  25. * more information.
  26. *
  27. * NOTE2: Default is the "D-cache clean and flush entry mode". It looks
  28. * like the "Transparent mode" must be on for partial cache flushes
  29. * to work in this mode. This mode only works with 16-bit external
  30. * memory. See TRM 2-24 for more information.
  31. *
  32. * NOTE3: Write-back cache flushing seems to be flakey with devices using
  33. * direct memory access, such as USB OHCI. The workaround is to use
  34. * write-through cache with CONFIG_CPU_DCACHE_WRITETHROUGH (this is
  35. * the default for OMAP-1510).
  36. */
  37. #include <linux/linkage.h>
  38. #include <linux/init.h>
  39. #include <linux/cfi_types.h>
  40. #include <linux/pgtable.h>
  41. #include <asm/assembler.h>
  42. #include <asm/hwcap.h>
  43. #include <asm/pgtable-hwdef.h>
  44. #include <asm/page.h>
  45. #include <asm/ptrace.h>
  46. #include "proc-macros.S"
  47. /*
  48. * The size of one data cache line.
  49. */
  50. #define CACHE_DLINESIZE 16
  51. /*
  52. * The number of data cache segments.
  53. */
  54. #define CACHE_DSEGMENTS 2
  55. /*
  56. * The number of lines in a cache segment.
  57. */
  58. #define CACHE_DENTRIES 256
  59. /*
  60. * This is the size at which it becomes more efficient to
  61. * clean the whole cache, rather than using the individual
  62. * cache line maintenance instructions.
  63. */
  64. #define CACHE_DLIMIT 8192
  65. .text
  66. /*
  67. * cpu_arm925_proc_init()
  68. */
  69. SYM_TYPED_FUNC_START(cpu_arm925_proc_init)
  70. ret lr
  71. SYM_FUNC_END(cpu_arm925_proc_init)
  72. /*
  73. * cpu_arm925_proc_fin()
  74. */
  75. SYM_TYPED_FUNC_START(cpu_arm925_proc_fin)
  76. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  77. bic r0, r0, #0x1000 @ ...i............
  78. bic r0, r0, #0x000e @ ............wca.
  79. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  80. ret lr
  81. SYM_FUNC_END(cpu_arm925_proc_fin)
  82. /*
  83. * cpu_arm925_reset(loc)
  84. *
  85. * Perform a soft reset of the system. Put the CPU into the
  86. * same state as it would be if it had been reset, and branch
  87. * to what would be the reset vector.
  88. *
  89. * loc: location to jump to for soft reset
  90. */
  91. .align 5
  92. .pushsection .idmap.text, "ax"
  93. SYM_TYPED_FUNC_START(cpu_arm925_reset)
  94. /* Send software reset to MPU and DSP */
  95. mov ip, #0xff000000
  96. orr ip, ip, #0x00fe0000
  97. orr ip, ip, #0x0000ce00
  98. mov r4, #1
  99. strh r4, [ip, #0x10]
  100. SYM_FUNC_END(cpu_arm925_reset)
  101. .popsection
  102. mov ip, #0
  103. mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
  104. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  105. #ifdef CONFIG_MMU
  106. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  107. #endif
  108. mrc p15, 0, ip, c1, c0, 0 @ ctrl register
  109. bic ip, ip, #0x000f @ ............wcam
  110. bic ip, ip, #0x1100 @ ...i...s........
  111. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  112. ret r0
  113. /*
  114. * cpu_arm925_do_idle()
  115. *
  116. * Called with IRQs disabled
  117. */
  118. .align 10
  119. SYM_TYPED_FUNC_START(cpu_arm925_do_idle)
  120. mov r0, #0
  121. mrc p15, 0, r1, c1, c0, 0 @ Read control register
  122. mcr p15, 0, r0, c7, c10, 4 @ Drain write buffer
  123. bic r2, r1, #1 << 12
  124. mcr p15, 0, r2, c1, c0, 0 @ Disable I cache
  125. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  126. mcr p15, 0, r1, c1, c0, 0 @ Restore ICache enable
  127. ret lr
  128. SYM_FUNC_END(cpu_arm925_do_idle)
  129. /*
  130. * flush_icache_all()
  131. *
  132. * Unconditionally clean and invalidate the entire icache.
  133. */
  134. SYM_TYPED_FUNC_START(arm925_flush_icache_all)
  135. mov r0, #0
  136. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  137. ret lr
  138. SYM_FUNC_END(arm925_flush_icache_all)
  139. /*
  140. * flush_user_cache_all()
  141. *
  142. * Clean and invalidate all cache entries in a particular
  143. * address space.
  144. */
  145. SYM_FUNC_ALIAS(arm925_flush_user_cache_all, arm925_flush_kern_cache_all)
  146. /*
  147. * flush_kern_cache_all()
  148. *
  149. * Clean and invalidate the entire cache.
  150. */
  151. SYM_TYPED_FUNC_START(arm925_flush_kern_cache_all)
  152. mov r2, #VM_EXEC
  153. mov ip, #0
  154. __flush_whole_cache:
  155. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  156. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  157. #else
  158. /* Flush entries in both segments at once, see NOTE1 above */
  159. mov r3, #(CACHE_DENTRIES - 1) << 4 @ 256 entries in segment
  160. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  161. subs r3, r3, #1 << 4
  162. bcs 2b @ entries 255 to 0
  163. #endif
  164. tst r2, #VM_EXEC
  165. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  166. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  167. ret lr
  168. SYM_FUNC_END(arm925_flush_kern_cache_all)
  169. /*
  170. * flush_user_cache_range(start, end, flags)
  171. *
  172. * Clean and invalidate a range of cache entries in the
  173. * specified address range.
  174. *
  175. * - start - start address (inclusive)
  176. * - end - end address (exclusive)
  177. * - flags - vm_flags describing address space
  178. */
  179. SYM_TYPED_FUNC_START(arm925_flush_user_cache_range)
  180. mov ip, #0
  181. sub r3, r1, r0 @ calculate total size
  182. cmp r3, #CACHE_DLIMIT
  183. bgt __flush_whole_cache
  184. 1: tst r2, #VM_EXEC
  185. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  186. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  187. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  188. add r0, r0, #CACHE_DLINESIZE
  189. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  190. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  191. add r0, r0, #CACHE_DLINESIZE
  192. #else
  193. mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  194. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  195. add r0, r0, #CACHE_DLINESIZE
  196. mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  197. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  198. add r0, r0, #CACHE_DLINESIZE
  199. #endif
  200. cmp r0, r1
  201. blo 1b
  202. tst r2, #VM_EXEC
  203. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  204. ret lr
  205. SYM_FUNC_END(arm925_flush_user_cache_range)
  206. /*
  207. * coherent_kern_range(start, end)
  208. *
  209. * Ensure coherency between the Icache and the Dcache in the
  210. * region described by start, end. If you have non-snooping
  211. * Harvard caches, you need to implement this function.
  212. *
  213. * - start - virtual start address
  214. * - end - virtual end address
  215. */
  216. SYM_TYPED_FUNC_START(arm925_coherent_kern_range)
  217. #ifdef CONFIG_CFI_CLANG /* Fallthrough if !CFI */
  218. b arm925_coherent_user_range
  219. #endif
  220. SYM_FUNC_END(arm925_coherent_kern_range)
  221. /*
  222. * coherent_user_range(start, end)
  223. *
  224. * Ensure coherency between the Icache and the Dcache in the
  225. * region described by start, end. If you have non-snooping
  226. * Harvard caches, you need to implement this function.
  227. *
  228. * - start - virtual start address
  229. * - end - virtual end address
  230. */
  231. SYM_TYPED_FUNC_START(arm925_coherent_user_range)
  232. bic r0, r0, #CACHE_DLINESIZE - 1
  233. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  234. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  235. add r0, r0, #CACHE_DLINESIZE
  236. cmp r0, r1
  237. blo 1b
  238. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  239. mov r0, #0
  240. ret lr
  241. SYM_FUNC_END(arm925_coherent_user_range)
  242. /*
  243. * flush_kern_dcache_area(void *addr, size_t size)
  244. *
  245. * Ensure no D cache aliasing occurs, either with itself or
  246. * the I cache
  247. *
  248. * - addr - kernel address
  249. * - size - region size
  250. */
  251. SYM_TYPED_FUNC_START(arm925_flush_kern_dcache_area)
  252. add r1, r0, r1
  253. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  254. add r0, r0, #CACHE_DLINESIZE
  255. cmp r0, r1
  256. blo 1b
  257. mov r0, #0
  258. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  259. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  260. ret lr
  261. SYM_FUNC_END(arm925_flush_kern_dcache_area)
  262. /*
  263. * dma_inv_range(start, end)
  264. *
  265. * Invalidate (discard) the specified virtual address range.
  266. * May not write back any entries. If 'start' or 'end'
  267. * are not cache line aligned, those lines must be written
  268. * back.
  269. *
  270. * - start - virtual start address
  271. * - end - virtual end address
  272. *
  273. * (same as v4wb)
  274. */
  275. arm925_dma_inv_range:
  276. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  277. tst r0, #CACHE_DLINESIZE - 1
  278. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  279. tst r1, #CACHE_DLINESIZE - 1
  280. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  281. #endif
  282. bic r0, r0, #CACHE_DLINESIZE - 1
  283. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  284. add r0, r0, #CACHE_DLINESIZE
  285. cmp r0, r1
  286. blo 1b
  287. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  288. ret lr
  289. /*
  290. * dma_clean_range(start, end)
  291. *
  292. * Clean the specified virtual address range.
  293. *
  294. * - start - virtual start address
  295. * - end - virtual end address
  296. *
  297. * (same as v4wb)
  298. */
  299. arm925_dma_clean_range:
  300. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  301. bic r0, r0, #CACHE_DLINESIZE - 1
  302. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  303. add r0, r0, #CACHE_DLINESIZE
  304. cmp r0, r1
  305. blo 1b
  306. #endif
  307. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  308. ret lr
  309. /*
  310. * dma_flush_range(start, end)
  311. *
  312. * Clean and invalidate the specified virtual address range.
  313. *
  314. * - start - virtual start address
  315. * - end - virtual end address
  316. */
  317. SYM_TYPED_FUNC_START(arm925_dma_flush_range)
  318. bic r0, r0, #CACHE_DLINESIZE - 1
  319. 1:
  320. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  321. mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  322. #else
  323. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  324. #endif
  325. add r0, r0, #CACHE_DLINESIZE
  326. cmp r0, r1
  327. blo 1b
  328. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  329. ret lr
  330. SYM_FUNC_END(arm925_dma_flush_range)
  331. /*
  332. * dma_map_area(start, size, dir)
  333. * - start - kernel virtual start address
  334. * - size - size of region
  335. * - dir - DMA direction
  336. */
  337. SYM_TYPED_FUNC_START(arm925_dma_map_area)
  338. add r1, r1, r0
  339. cmp r2, #DMA_TO_DEVICE
  340. beq arm925_dma_clean_range
  341. bcs arm925_dma_inv_range
  342. b arm925_dma_flush_range
  343. SYM_FUNC_END(arm925_dma_map_area)
  344. /*
  345. * dma_unmap_area(start, size, dir)
  346. * - start - kernel virtual start address
  347. * - size - size of region
  348. * - dir - DMA direction
  349. */
  350. SYM_TYPED_FUNC_START(arm925_dma_unmap_area)
  351. ret lr
  352. SYM_FUNC_END(arm925_dma_unmap_area)
  353. SYM_TYPED_FUNC_START(cpu_arm925_dcache_clean_area)
  354. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  355. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  356. add r0, r0, #CACHE_DLINESIZE
  357. subs r1, r1, #CACHE_DLINESIZE
  358. bhi 1b
  359. #endif
  360. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  361. ret lr
  362. SYM_FUNC_END(cpu_arm925_dcache_clean_area)
  363. /* =============================== PageTable ============================== */
  364. /*
  365. * cpu_arm925_switch_mm(pgd)
  366. *
  367. * Set the translation base pointer to be as described by pgd.
  368. *
  369. * pgd: new page tables
  370. */
  371. .align 5
  372. SYM_TYPED_FUNC_START(cpu_arm925_switch_mm)
  373. #ifdef CONFIG_MMU
  374. mov ip, #0
  375. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  376. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  377. #else
  378. /* Flush entries in bothe segments at once, see NOTE1 above */
  379. mov r3, #(CACHE_DENTRIES - 1) << 4 @ 256 entries in segment
  380. 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
  381. subs r3, r3, #1 << 4
  382. bcs 2b @ entries 255 to 0
  383. #endif
  384. mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
  385. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  386. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  387. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  388. #endif
  389. ret lr
  390. SYM_FUNC_END(cpu_arm925_switch_mm)
  391. /*
  392. * cpu_arm925_set_pte_ext(ptep, pte, ext)
  393. *
  394. * Set a PTE and flush it out
  395. */
  396. .align 5
  397. SYM_TYPED_FUNC_START(cpu_arm925_set_pte_ext)
  398. #ifdef CONFIG_MMU
  399. armv3_set_pte_ext
  400. mov r0, r0
  401. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  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_arm925_set_pte_ext)
  408. .type __arm925_setup, #function
  409. __arm925_setup:
  410. mov r0, #0
  411. /* Transparent on, D-cache clean & flush mode. See NOTE2 above */
  412. orr r0,r0,#1 << 1 @ transparent mode on
  413. mcr p15, 0, r0, c15, c1, 0 @ write TI config register
  414. mov r0, #0
  415. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  416. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  417. #ifdef CONFIG_MMU
  418. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  419. #endif
  420. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  421. mov r0, #4 @ disable write-back on caches explicitly
  422. mcr p15, 7, r0, c15, c0, 0
  423. #endif
  424. adr r5, arm925_crval
  425. ldmia r5, {r5, r6}
  426. mrc p15, 0, r0, c1, c0 @ get control register v4
  427. bic r0, r0, r5
  428. orr r0, r0, r6
  429. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  430. orr r0, r0, #0x4000 @ .1.. .... .... ....
  431. #endif
  432. ret lr
  433. .size __arm925_setup, . - __arm925_setup
  434. /*
  435. * R
  436. * .RVI ZFRS BLDP WCAM
  437. * .011 0001 ..11 1101
  438. *
  439. */
  440. .type arm925_crval, #object
  441. arm925_crval:
  442. crval clear=0x00007f3f, mmuset=0x0000313d, ucset=0x00001130
  443. __INITDATA
  444. @ define struct processor (see <asm/proc-fns.h> and proc-macros.S)
  445. define_processor_functions arm925, dabort=v4t_early_abort, pabort=legacy_pabort
  446. .section ".rodata"
  447. string cpu_arch_name, "armv4t"
  448. string cpu_elf_name, "v4"
  449. string cpu_arm925_name, "ARM925T"
  450. .align
  451. .section ".proc.info.init", "a"
  452. .macro arm925_proc_info name:req, cpu_val:req, cpu_mask:req, cpu_name:req, cache
  453. .type __\name\()_proc_info,#object
  454. __\name\()_proc_info:
  455. .long \cpu_val
  456. .long \cpu_mask
  457. .long PMD_TYPE_SECT | \
  458. PMD_SECT_CACHEABLE | \
  459. PMD_BIT4 | \
  460. PMD_SECT_AP_WRITE | \
  461. PMD_SECT_AP_READ
  462. .long PMD_TYPE_SECT | \
  463. PMD_BIT4 | \
  464. PMD_SECT_AP_WRITE | \
  465. PMD_SECT_AP_READ
  466. initfn __arm925_setup, __\name\()_proc_info
  467. .long cpu_arch_name
  468. .long cpu_elf_name
  469. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
  470. .long cpu_arm925_name
  471. .long arm925_processor_functions
  472. .long v4wbi_tlb_fns
  473. .long v4wb_user_fns
  474. .long arm925_cache_fns
  475. .size __\name\()_proc_info, . - __\name\()_proc_info
  476. .endm
  477. arm925_proc_info arm925, 0x54029250, 0xfffffff0, cpu_arm925_name
  478. arm925_proc_info arm915, 0x54029150, 0xfffffff0, cpu_arm925_name