proc-mohawk.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * linux/arch/arm/mm/proc-mohawk.S: MMU functions for Marvell PJ1 core
  4. *
  5. * PJ1 (codename Mohawk) is a hybrid of the xscale3 and Marvell's own core.
  6. *
  7. * Heavily based on proc-arm926.S and proc-xsc3.S
  8. */
  9. #include <linux/linkage.h>
  10. #include <linux/init.h>
  11. #include <linux/cfi_types.h>
  12. #include <linux/pgtable.h>
  13. #include <asm/assembler.h>
  14. #include <asm/hwcap.h>
  15. #include <asm/pgtable-hwdef.h>
  16. #include <asm/page.h>
  17. #include <asm/ptrace.h>
  18. #include "proc-macros.S"
  19. /*
  20. * This is the maximum size of an area which will be flushed. If the
  21. * area is larger than this, then we flush the whole cache.
  22. */
  23. #define CACHE_DLIMIT 32768
  24. /*
  25. * The cache line size of the L1 D cache.
  26. */
  27. #define CACHE_DLINESIZE 32
  28. /*
  29. * cpu_mohawk_proc_init()
  30. */
  31. SYM_TYPED_FUNC_START(cpu_mohawk_proc_init)
  32. ret lr
  33. SYM_FUNC_END(cpu_mohawk_proc_init)
  34. /*
  35. * cpu_mohawk_proc_fin()
  36. */
  37. SYM_TYPED_FUNC_START(cpu_mohawk_proc_fin)
  38. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  39. bic r0, r0, #0x1800 @ ...iz...........
  40. bic r0, r0, #0x0006 @ .............ca.
  41. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  42. ret lr
  43. SYM_FUNC_END(cpu_mohawk_proc_fin)
  44. /*
  45. * cpu_mohawk_reset(loc)
  46. *
  47. * Perform a soft reset of the system. Put the CPU into the
  48. * same state as it would be if it had been reset, and branch
  49. * to what would be the reset vector.
  50. *
  51. * loc: location to jump to for soft reset
  52. *
  53. * (same as arm926)
  54. */
  55. .align 5
  56. .pushsection .idmap.text, "ax"
  57. SYM_TYPED_FUNC_START(cpu_mohawk_reset)
  58. mov ip, #0
  59. mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
  60. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  61. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  62. mrc p15, 0, ip, c1, c0, 0 @ ctrl register
  63. bic ip, ip, #0x0007 @ .............cam
  64. bic ip, ip, #0x1100 @ ...i...s........
  65. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  66. ret r0
  67. SYM_FUNC_END(cpu_mohawk_reset)
  68. .popsection
  69. /*
  70. * cpu_mohawk_do_idle()
  71. *
  72. * Called with IRQs disabled
  73. */
  74. .align 5
  75. SYM_TYPED_FUNC_START(cpu_mohawk_do_idle)
  76. mov r0, #0
  77. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  78. mcr p15, 0, r0, c7, c0, 4 @ wait for interrupt
  79. ret lr
  80. SYM_FUNC_END(cpu_mohawk_do_idle)
  81. /*
  82. * flush_icache_all()
  83. *
  84. * Unconditionally clean and invalidate the entire icache.
  85. */
  86. SYM_TYPED_FUNC_START(mohawk_flush_icache_all)
  87. mov r0, #0
  88. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  89. ret lr
  90. SYM_FUNC_END(mohawk_flush_icache_all)
  91. /*
  92. * flush_user_cache_all()
  93. *
  94. * Clean and invalidate all cache entries in a particular
  95. * address space.
  96. */
  97. SYM_FUNC_ALIAS(mohawk_flush_user_cache_all, mohawk_flush_kern_cache_all)
  98. /*
  99. * flush_kern_cache_all()
  100. *
  101. * Clean and invalidate the entire cache.
  102. */
  103. SYM_TYPED_FUNC_START(mohawk_flush_kern_cache_all)
  104. mov r2, #VM_EXEC
  105. mov ip, #0
  106. __flush_whole_cache:
  107. mcr p15, 0, ip, c7, c14, 0 @ clean & invalidate all D cache
  108. tst r2, #VM_EXEC
  109. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  110. mcrne p15, 0, ip, c7, c10, 0 @ drain write buffer
  111. ret lr
  112. SYM_FUNC_END(mohawk_flush_kern_cache_all)
  113. /*
  114. * flush_user_cache_range(start, end, flags)
  115. *
  116. * Clean and invalidate a range of cache entries in the
  117. * specified address range.
  118. *
  119. * - start - start address (inclusive)
  120. * - end - end address (exclusive)
  121. * - flags - vm_flags describing address space
  122. *
  123. * (same as arm926)
  124. */
  125. SYM_TYPED_FUNC_START(mohawk_flush_user_cache_range)
  126. mov ip, #0
  127. sub r3, r1, r0 @ calculate total size
  128. cmp r3, #CACHE_DLIMIT
  129. bgt __flush_whole_cache
  130. 1: tst r2, #VM_EXEC
  131. mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  132. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  133. add r0, r0, #CACHE_DLINESIZE
  134. mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  135. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  136. add r0, r0, #CACHE_DLINESIZE
  137. cmp r0, r1
  138. blo 1b
  139. tst r2, #VM_EXEC
  140. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  141. ret lr
  142. SYM_FUNC_END(mohawk_flush_user_cache_range)
  143. /*
  144. * coherent_kern_range(start, end)
  145. *
  146. * Ensure coherency between the Icache and the Dcache in the
  147. * region described by start, end. If you have non-snooping
  148. * Harvard caches, you need to implement this function.
  149. *
  150. * - start - virtual start address
  151. * - end - virtual end address
  152. */
  153. SYM_TYPED_FUNC_START(mohawk_coherent_kern_range)
  154. #ifdef CONFIG_CFI_CLANG /* Fallthrough if !CFI */
  155. b mohawk_coherent_user_range
  156. #endif
  157. SYM_FUNC_END(mohawk_coherent_kern_range)
  158. /*
  159. * coherent_user_range(start, end)
  160. *
  161. * Ensure coherency between the Icache and the Dcache in the
  162. * region described by start, end. If you have non-snooping
  163. * Harvard caches, you need to implement this function.
  164. *
  165. * - start - virtual start address
  166. * - end - virtual end address
  167. *
  168. * (same as arm926)
  169. */
  170. SYM_TYPED_FUNC_START(mohawk_coherent_user_range)
  171. bic r0, r0, #CACHE_DLINESIZE - 1
  172. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  173. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  174. add r0, r0, #CACHE_DLINESIZE
  175. cmp r0, r1
  176. blo 1b
  177. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  178. mov r0, #0
  179. ret lr
  180. SYM_FUNC_END(mohawk_coherent_user_range)
  181. /*
  182. * flush_kern_dcache_area(void *addr, size_t size)
  183. *
  184. * Ensure no D cache aliasing occurs, either with itself or
  185. * the I cache
  186. *
  187. * - addr - kernel address
  188. * - size - region size
  189. */
  190. SYM_TYPED_FUNC_START(mohawk_flush_kern_dcache_area)
  191. add r1, r0, r1
  192. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  193. add r0, r0, #CACHE_DLINESIZE
  194. cmp r0, r1
  195. blo 1b
  196. mov r0, #0
  197. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  198. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  199. ret lr
  200. SYM_FUNC_END(mohawk_flush_kern_dcache_area)
  201. /*
  202. * dma_inv_range(start, end)
  203. *
  204. * Invalidate (discard) the specified virtual address range.
  205. * May not write back any entries. If 'start' or 'end'
  206. * are not cache line aligned, those lines must be written
  207. * back.
  208. *
  209. * - start - virtual start address
  210. * - end - virtual end address
  211. *
  212. * (same as v4wb)
  213. */
  214. mohawk_dma_inv_range:
  215. tst r0, #CACHE_DLINESIZE - 1
  216. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  217. tst r1, #CACHE_DLINESIZE - 1
  218. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  219. bic r0, r0, #CACHE_DLINESIZE - 1
  220. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  221. add r0, r0, #CACHE_DLINESIZE
  222. cmp r0, r1
  223. blo 1b
  224. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  225. ret lr
  226. /*
  227. * dma_clean_range(start, end)
  228. *
  229. * Clean the specified virtual address range.
  230. *
  231. * - start - virtual start address
  232. * - end - virtual end address
  233. *
  234. * (same as v4wb)
  235. */
  236. mohawk_dma_clean_range:
  237. bic r0, r0, #CACHE_DLINESIZE - 1
  238. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  239. add r0, r0, #CACHE_DLINESIZE
  240. cmp r0, r1
  241. blo 1b
  242. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  243. ret lr
  244. /*
  245. * dma_flush_range(start, end)
  246. *
  247. * Clean and invalidate the specified virtual address range.
  248. *
  249. * - start - virtual start address
  250. * - end - virtual end address
  251. */
  252. SYM_TYPED_FUNC_START(mohawk_dma_flush_range)
  253. bic r0, r0, #CACHE_DLINESIZE - 1
  254. 1:
  255. mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  256. add r0, r0, #CACHE_DLINESIZE
  257. cmp r0, r1
  258. blo 1b
  259. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  260. ret lr
  261. SYM_FUNC_END(mohawk_dma_flush_range)
  262. /*
  263. * dma_map_area(start, size, dir)
  264. * - start - kernel virtual start address
  265. * - size - size of region
  266. * - dir - DMA direction
  267. */
  268. SYM_TYPED_FUNC_START(mohawk_dma_map_area)
  269. add r1, r1, r0
  270. cmp r2, #DMA_TO_DEVICE
  271. beq mohawk_dma_clean_range
  272. bcs mohawk_dma_inv_range
  273. b mohawk_dma_flush_range
  274. SYM_FUNC_END(mohawk_dma_map_area)
  275. /*
  276. * dma_unmap_area(start, size, dir)
  277. * - start - kernel virtual start address
  278. * - size - size of region
  279. * - dir - DMA direction
  280. */
  281. SYM_TYPED_FUNC_START(mohawk_dma_unmap_area)
  282. ret lr
  283. SYM_FUNC_END(mohawk_dma_unmap_area)
  284. SYM_TYPED_FUNC_START(cpu_mohawk_dcache_clean_area)
  285. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  286. add r0, r0, #CACHE_DLINESIZE
  287. subs r1, r1, #CACHE_DLINESIZE
  288. bhi 1b
  289. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  290. ret lr
  291. SYM_FUNC_END(cpu_mohawk_dcache_clean_area)
  292. /*
  293. * cpu_mohawk_switch_mm(pgd)
  294. *
  295. * Set the translation base pointer to be as described by pgd.
  296. *
  297. * pgd: new page tables
  298. */
  299. .align 5
  300. SYM_TYPED_FUNC_START(cpu_mohawk_switch_mm)
  301. mov ip, #0
  302. mcr p15, 0, ip, c7, c14, 0 @ clean & invalidate all D cache
  303. mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
  304. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  305. orr r0, r0, #0x18 @ cache the page table in L2
  306. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  307. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  308. ret lr
  309. SYM_FUNC_END(cpu_mohawk_switch_mm)
  310. /*
  311. * cpu_mohawk_set_pte_ext(ptep, pte, ext)
  312. *
  313. * Set a PTE and flush it out
  314. */
  315. .align 5
  316. SYM_TYPED_FUNC_START(cpu_mohawk_set_pte_ext)
  317. #ifdef CONFIG_MMU
  318. armv3_set_pte_ext
  319. mov r0, r0
  320. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  321. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  322. ret lr
  323. #endif
  324. SYM_FUNC_END(cpu_mohawk_set_pte_ext)
  325. .globl cpu_mohawk_suspend_size
  326. .equ cpu_mohawk_suspend_size, 4 * 6
  327. #ifdef CONFIG_ARM_CPU_SUSPEND
  328. SYM_TYPED_FUNC_START(cpu_mohawk_do_suspend)
  329. stmfd sp!, {r4 - r9, lr}
  330. mrc p14, 0, r4, c6, c0, 0 @ clock configuration, for turbo mode
  331. mrc p15, 0, r5, c15, c1, 0 @ CP access reg
  332. mrc p15, 0, r6, c13, c0, 0 @ PID
  333. mrc p15, 0, r7, c3, c0, 0 @ domain ID
  334. mrc p15, 0, r8, c1, c0, 1 @ auxiliary control reg
  335. mrc p15, 0, r9, c1, c0, 0 @ control reg
  336. bic r4, r4, #2 @ clear frequency change bit
  337. stmia r0, {r4 - r9} @ store cp regs
  338. ldmia sp!, {r4 - r9, pc}
  339. SYM_FUNC_END(cpu_mohawk_do_suspend)
  340. SYM_TYPED_FUNC_START(cpu_mohawk_do_resume)
  341. ldmia r0, {r4 - r9} @ load cp regs
  342. mov ip, #0
  343. mcr p15, 0, ip, c7, c7, 0 @ invalidate I & D caches, BTB
  344. mcr p15, 0, ip, c7, c10, 4 @ drain write (&fill) buffer
  345. mcr p15, 0, ip, c7, c5, 4 @ flush prefetch buffer
  346. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  347. mcr p14, 0, r4, c6, c0, 0 @ clock configuration, turbo mode.
  348. mcr p15, 0, r5, c15, c1, 0 @ CP access reg
  349. mcr p15, 0, r6, c13, c0, 0 @ PID
  350. mcr p15, 0, r7, c3, c0, 0 @ domain ID
  351. orr r1, r1, #0x18 @ cache the page table in L2
  352. mcr p15, 0, r1, c2, c0, 0 @ translation table base addr
  353. mcr p15, 0, r8, c1, c0, 1 @ auxiliary control reg
  354. mov r0, r9 @ control register
  355. b cpu_resume_mmu
  356. SYM_FUNC_END(cpu_mohawk_do_resume)
  357. #endif
  358. .type __mohawk_setup, #function
  359. __mohawk_setup:
  360. mov r0, #0
  361. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches
  362. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  363. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs
  364. orr r4, r4, #0x18 @ cache the page table in L2
  365. mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
  366. mov r0, #0 @ don't allow CP access
  367. mcr p15, 0, r0, c15, c1, 0 @ write CP access register
  368. adr r5, mohawk_crval
  369. ldmia r5, {r5, r6}
  370. mrc p15, 0, r0, c1, c0 @ get control register
  371. bic r0, r0, r5
  372. orr r0, r0, r6
  373. ret lr
  374. .size __mohawk_setup, . - __mohawk_setup
  375. /*
  376. * R
  377. * .RVI ZFRS BLDP WCAM
  378. * .011 1001 ..00 0101
  379. *
  380. */
  381. .type mohawk_crval, #object
  382. mohawk_crval:
  383. crval clear=0x00007f3f, mmuset=0x00003905, ucset=0x00001134
  384. __INITDATA
  385. @ define struct processor (see <asm/proc-fns.h> and proc-macros.S)
  386. define_processor_functions mohawk, dabort=v5t_early_abort, pabort=legacy_pabort
  387. .section ".rodata"
  388. string cpu_arch_name, "armv5te"
  389. string cpu_elf_name, "v5"
  390. string cpu_mohawk_name, "Marvell 88SV331x"
  391. .align
  392. .section ".proc.info.init", "a"
  393. .type __88sv331x_proc_info,#object
  394. __88sv331x_proc_info:
  395. .long 0x56158000 @ Marvell 88SV331x (MOHAWK)
  396. .long 0xfffff000
  397. .long PMD_TYPE_SECT | \
  398. PMD_SECT_BUFFERABLE | \
  399. PMD_SECT_CACHEABLE | \
  400. PMD_BIT4 | \
  401. PMD_SECT_AP_WRITE | \
  402. PMD_SECT_AP_READ
  403. .long PMD_TYPE_SECT | \
  404. PMD_BIT4 | \
  405. PMD_SECT_AP_WRITE | \
  406. PMD_SECT_AP_READ
  407. initfn __mohawk_setup, __88sv331x_proc_info
  408. .long cpu_arch_name
  409. .long cpu_elf_name
  410. .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
  411. .long cpu_mohawk_name
  412. .long mohawk_processor_functions
  413. .long v4wbi_tlb_fns
  414. .long v4wb_user_fns
  415. .long mohawk_cache_fns
  416. .size __88sv331x_proc_info, . - __88sv331x_proc_info