proc-xsc3.S 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. /*
  2. * linux/arch/arm/mm/proc-xsc3.S
  3. *
  4. * Original Author: Matthew Gilbert
  5. * Current Maintainer: Lennert Buytenhek <buytenh@wantstofly.org>
  6. *
  7. * Copyright 2004 (C) Intel Corp.
  8. * Copyright 2005 (C) MontaVista Software, Inc.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. * MMU functions for the Intel XScale3 Core (XSC3). The XSC3 core is
  15. * an extension to Intel's original XScale core that adds the following
  16. * features:
  17. *
  18. * - ARMv6 Supersections
  19. * - Low Locality Reference pages (replaces mini-cache)
  20. * - 36-bit addressing
  21. * - L2 cache
  22. * - Cache coherency if chipset supports it
  23. *
  24. * Based on original XScale code by Nicolas Pitre.
  25. */
  26. #include <linux/linkage.h>
  27. #include <linux/init.h>
  28. #include <asm/assembler.h>
  29. #include <asm/hwcap.h>
  30. #include <asm/pgtable.h>
  31. #include <asm/pgtable-hwdef.h>
  32. #include <asm/page.h>
  33. #include <asm/ptrace.h>
  34. #include "proc-macros.S"
  35. /*
  36. * This is the maximum size of an area which will be flushed. If the
  37. * area is larger than this, then we flush the whole cache.
  38. */
  39. #define MAX_AREA_SIZE 32768
  40. /*
  41. * The cache line size of the L1 I, L1 D and unified L2 cache.
  42. */
  43. #define CACHELINESIZE 32
  44. /*
  45. * The size of the L1 D cache.
  46. */
  47. #define CACHESIZE 32768
  48. /*
  49. * This macro is used to wait for a CP15 write and is needed when we
  50. * have to ensure that the last operation to the coprocessor was
  51. * completed before continuing with operation.
  52. */
  53. .macro cpwait_ret, lr, rd
  54. mrc p15, 0, \rd, c2, c0, 0 @ arbitrary read of cp15
  55. sub pc, \lr, \rd, LSR #32 @ wait for completion and
  56. @ flush instruction pipeline
  57. .endm
  58. /*
  59. * This macro cleans and invalidates the entire L1 D cache.
  60. */
  61. .macro clean_d_cache rd, rs
  62. mov \rd, #0x1f00
  63. orr \rd, \rd, #0x00e0
  64. 1: mcr p15, 0, \rd, c7, c14, 2 @ clean/invalidate L1 D line
  65. adds \rd, \rd, #0x40000000
  66. bcc 1b
  67. subs \rd, \rd, #0x20
  68. bpl 1b
  69. .endm
  70. .text
  71. /*
  72. * cpu_xsc3_proc_init()
  73. *
  74. * Nothing too exciting at the moment
  75. */
  76. ENTRY(cpu_xsc3_proc_init)
  77. ret lr
  78. /*
  79. * cpu_xsc3_proc_fin()
  80. */
  81. ENTRY(cpu_xsc3_proc_fin)
  82. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  83. bic r0, r0, #0x1800 @ ...IZ...........
  84. bic r0, r0, #0x0006 @ .............CA.
  85. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  86. ret lr
  87. /*
  88. * cpu_xsc3_reset(loc)
  89. *
  90. * Perform a soft reset of the system. Put the CPU into the
  91. * same state as it would be if it had been reset, and branch
  92. * to what would be the reset vector.
  93. *
  94. * loc: location to jump to for soft reset
  95. */
  96. .align 5
  97. .pushsection .idmap.text, "ax"
  98. ENTRY(cpu_xsc3_reset)
  99. mov r1, #PSR_F_BIT|PSR_I_BIT|SVC_MODE
  100. msr cpsr_c, r1 @ reset CPSR
  101. mrc p15, 0, r1, c1, c0, 0 @ ctrl register
  102. bic r1, r1, #0x3900 @ ..VIZ..S........
  103. bic r1, r1, #0x0086 @ ........B....CA.
  104. mcr p15, 0, r1, c1, c0, 0 @ ctrl register
  105. mcr p15, 0, ip, c7, c7, 0 @ invalidate L1 caches and BTB
  106. bic r1, r1, #0x0001 @ ...............M
  107. mcr p15, 0, r1, c1, c0, 0 @ ctrl register
  108. @ CAUTION: MMU turned off from this point. We count on the pipeline
  109. @ already containing those two last instructions to survive.
  110. mcr p15, 0, ip, c8, c7, 0 @ invalidate I and D TLBs
  111. ret r0
  112. ENDPROC(cpu_xsc3_reset)
  113. .popsection
  114. /*
  115. * cpu_xsc3_do_idle()
  116. *
  117. * Cause the processor to idle
  118. *
  119. * For now we do nothing but go to idle mode for every case
  120. *
  121. * XScale supports clock switching, but using idle mode support
  122. * allows external hardware to react to system state changes.
  123. */
  124. .align 5
  125. ENTRY(cpu_xsc3_do_idle)
  126. mov r0, #1
  127. mcr p14, 0, r0, c7, c0, 0 @ go to idle
  128. ret lr
  129. /* ================================= CACHE ================================ */
  130. /*
  131. * flush_icache_all()
  132. *
  133. * Unconditionally clean and invalidate the entire icache.
  134. */
  135. ENTRY(xsc3_flush_icache_all)
  136. mov r0, #0
  137. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  138. ret lr
  139. ENDPROC(xsc3_flush_icache_all)
  140. /*
  141. * flush_user_cache_all()
  142. *
  143. * Invalidate all cache entries in a particular address
  144. * space.
  145. */
  146. ENTRY(xsc3_flush_user_cache_all)
  147. /* FALLTHROUGH */
  148. /*
  149. * flush_kern_cache_all()
  150. *
  151. * Clean and invalidate the entire cache.
  152. */
  153. ENTRY(xsc3_flush_kern_cache_all)
  154. mov r2, #VM_EXEC
  155. mov ip, #0
  156. __flush_whole_cache:
  157. clean_d_cache r0, r1
  158. tst r2, #VM_EXEC
  159. mcrne p15, 0, ip, c7, c5, 0 @ invalidate L1 I cache and BTB
  160. mcrne p15, 0, ip, c7, c10, 4 @ data write barrier
  161. mcrne p15, 0, ip, c7, c5, 4 @ prefetch flush
  162. ret lr
  163. /*
  164. * flush_user_cache_range(start, end, vm_flags)
  165. *
  166. * Invalidate a range of cache entries in the specified
  167. * address space.
  168. *
  169. * - start - start address (may not be aligned)
  170. * - end - end address (exclusive, may not be aligned)
  171. * - vma - vma_area_struct describing address space
  172. */
  173. .align 5
  174. ENTRY(xsc3_flush_user_cache_range)
  175. mov ip, #0
  176. sub r3, r1, r0 @ calculate total size
  177. cmp r3, #MAX_AREA_SIZE
  178. bhs __flush_whole_cache
  179. 1: tst r2, #VM_EXEC
  180. mcrne p15, 0, r0, c7, c5, 1 @ invalidate L1 I line
  181. mcr p15, 0, r0, c7, c14, 1 @ clean/invalidate L1 D line
  182. add r0, r0, #CACHELINESIZE
  183. cmp r0, r1
  184. blo 1b
  185. tst r2, #VM_EXEC
  186. mcrne p15, 0, ip, c7, c5, 6 @ invalidate BTB
  187. mcrne p15, 0, ip, c7, c10, 4 @ data write barrier
  188. mcrne p15, 0, ip, c7, c5, 4 @ prefetch flush
  189. ret lr
  190. /*
  191. * coherent_kern_range(start, end)
  192. *
  193. * Ensure coherency between the I cache and the D cache in the
  194. * region described by start. If you have non-snooping
  195. * Harvard caches, you need to implement this function.
  196. *
  197. * - start - virtual start address
  198. * - end - virtual end address
  199. *
  200. * Note: single I-cache line invalidation isn't used here since
  201. * it also trashes the mini I-cache used by JTAG debuggers.
  202. */
  203. ENTRY(xsc3_coherent_kern_range)
  204. /* FALLTHROUGH */
  205. ENTRY(xsc3_coherent_user_range)
  206. bic r0, r0, #CACHELINESIZE - 1
  207. 1: mcr p15, 0, r0, c7, c10, 1 @ clean L1 D line
  208. add r0, r0, #CACHELINESIZE
  209. cmp r0, r1
  210. blo 1b
  211. mov r0, #0
  212. mcr p15, 0, r0, c7, c5, 0 @ invalidate L1 I cache and BTB
  213. mcr p15, 0, r0, c7, c10, 4 @ data write barrier
  214. mcr p15, 0, r0, c7, c5, 4 @ prefetch flush
  215. ret lr
  216. /*
  217. * flush_kern_dcache_area(void *addr, size_t size)
  218. *
  219. * Ensure no D cache aliasing occurs, either with itself or
  220. * the I cache.
  221. *
  222. * - addr - kernel address
  223. * - size - region size
  224. */
  225. ENTRY(xsc3_flush_kern_dcache_area)
  226. add r1, r0, r1
  227. 1: mcr p15, 0, r0, c7, c14, 1 @ clean/invalidate L1 D line
  228. add r0, r0, #CACHELINESIZE
  229. cmp r0, r1
  230. blo 1b
  231. mov r0, #0
  232. mcr p15, 0, r0, c7, c5, 0 @ invalidate L1 I cache and BTB
  233. mcr p15, 0, r0, c7, c10, 4 @ data write barrier
  234. mcr p15, 0, r0, c7, c5, 4 @ prefetch flush
  235. ret lr
  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. xsc3_dma_inv_range:
  248. tst r0, #CACHELINESIZE - 1
  249. bic r0, r0, #CACHELINESIZE - 1
  250. mcrne p15, 0, r0, c7, c10, 1 @ clean L1 D line
  251. tst r1, #CACHELINESIZE - 1
  252. mcrne p15, 0, r1, c7, c10, 1 @ clean L1 D line
  253. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate L1 D line
  254. add r0, r0, #CACHELINESIZE
  255. cmp r0, r1
  256. blo 1b
  257. mcr p15, 0, r0, c7, c10, 4 @ data write barrier
  258. ret lr
  259. /*
  260. * dma_clean_range(start, end)
  261. *
  262. * Clean the specified virtual address range.
  263. *
  264. * - start - virtual start address
  265. * - end - virtual end address
  266. */
  267. xsc3_dma_clean_range:
  268. bic r0, r0, #CACHELINESIZE - 1
  269. 1: mcr p15, 0, r0, c7, c10, 1 @ clean L1 D line
  270. add r0, r0, #CACHELINESIZE
  271. cmp r0, r1
  272. blo 1b
  273. mcr p15, 0, r0, c7, c10, 4 @ data write barrier
  274. ret lr
  275. /*
  276. * dma_flush_range(start, end)
  277. *
  278. * Clean and invalidate the specified virtual address range.
  279. *
  280. * - start - virtual start address
  281. * - end - virtual end address
  282. */
  283. ENTRY(xsc3_dma_flush_range)
  284. bic r0, r0, #CACHELINESIZE - 1
  285. 1: mcr p15, 0, r0, c7, c14, 1 @ clean/invalidate L1 D line
  286. add r0, r0, #CACHELINESIZE
  287. cmp r0, r1
  288. blo 1b
  289. mcr p15, 0, r0, c7, c10, 4 @ data write barrier
  290. ret lr
  291. /*
  292. * dma_map_area(start, size, dir)
  293. * - start - kernel virtual start address
  294. * - size - size of region
  295. * - dir - DMA direction
  296. */
  297. ENTRY(xsc3_dma_map_area)
  298. add r1, r1, r0
  299. cmp r2, #DMA_TO_DEVICE
  300. beq xsc3_dma_clean_range
  301. bcs xsc3_dma_inv_range
  302. b xsc3_dma_flush_range
  303. ENDPROC(xsc3_dma_map_area)
  304. /*
  305. * dma_unmap_area(start, size, dir)
  306. * - start - kernel virtual start address
  307. * - size - size of region
  308. * - dir - DMA direction
  309. */
  310. ENTRY(xsc3_dma_unmap_area)
  311. ret lr
  312. ENDPROC(xsc3_dma_unmap_area)
  313. .globl xsc3_flush_kern_cache_louis
  314. .equ xsc3_flush_kern_cache_louis, xsc3_flush_kern_cache_all
  315. @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
  316. define_cache_functions xsc3
  317. ENTRY(cpu_xsc3_dcache_clean_area)
  318. 1: mcr p15, 0, r0, c7, c10, 1 @ clean L1 D line
  319. add r0, r0, #CACHELINESIZE
  320. subs r1, r1, #CACHELINESIZE
  321. bhi 1b
  322. ret lr
  323. /* =============================== PageTable ============================== */
  324. /*
  325. * cpu_xsc3_switch_mm(pgd)
  326. *
  327. * Set the translation base pointer to be as described by pgd.
  328. *
  329. * pgd: new page tables
  330. */
  331. .align 5
  332. ENTRY(cpu_xsc3_switch_mm)
  333. clean_d_cache r1, r2
  334. mcr p15, 0, ip, c7, c5, 0 @ invalidate L1 I cache and BTB
  335. mcr p15, 0, ip, c7, c10, 4 @ data write barrier
  336. mcr p15, 0, ip, c7, c5, 4 @ prefetch flush
  337. orr r0, r0, #0x18 @ cache the page table in L2
  338. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  339. mcr p15, 0, ip, c8, c7, 0 @ invalidate I and D TLBs
  340. cpwait_ret lr, ip
  341. /*
  342. * cpu_xsc3_set_pte_ext(ptep, pte, ext)
  343. *
  344. * Set a PTE and flush it out
  345. */
  346. cpu_xsc3_mt_table:
  347. .long 0x00 @ L_PTE_MT_UNCACHED
  348. .long PTE_EXT_TEX(1) @ L_PTE_MT_BUFFERABLE
  349. .long PTE_EXT_TEX(5) | PTE_CACHEABLE @ L_PTE_MT_WRITETHROUGH
  350. .long PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_WRITEBACK
  351. .long PTE_EXT_TEX(1) | PTE_BUFFERABLE @ L_PTE_MT_DEV_SHARED
  352. .long 0x00 @ unused
  353. .long 0x00 @ L_PTE_MT_MINICACHE (not present)
  354. .long PTE_EXT_TEX(5) | PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_WRITEALLOC (not present?)
  355. .long 0x00 @ unused
  356. .long PTE_EXT_TEX(1) @ L_PTE_MT_DEV_WC
  357. .long 0x00 @ unused
  358. .long PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_DEV_CACHED
  359. .long PTE_EXT_TEX(2) @ L_PTE_MT_DEV_NONSHARED
  360. .long 0x00 @ unused
  361. .long 0x00 @ unused
  362. .long 0x00 @ unused
  363. .align 5
  364. ENTRY(cpu_xsc3_set_pte_ext)
  365. xscale_set_pte_ext_prologue
  366. tst r1, #L_PTE_SHARED @ shared?
  367. and r1, r1, #L_PTE_MT_MASK
  368. adr ip, cpu_xsc3_mt_table
  369. ldr ip, [ip, r1]
  370. orrne r2, r2, #PTE_EXT_COHERENT @ interlock: mask in coherent bit
  371. bic r2, r2, #0x0c @ clear old C,B bits
  372. orr r2, r2, ip
  373. xscale_set_pte_ext_epilogue
  374. ret lr
  375. .ltorg
  376. .align
  377. .globl cpu_xsc3_suspend_size
  378. .equ cpu_xsc3_suspend_size, 4 * 6
  379. #ifdef CONFIG_ARM_CPU_SUSPEND
  380. ENTRY(cpu_xsc3_do_suspend)
  381. stmfd sp!, {r4 - r9, lr}
  382. mrc p14, 0, r4, c6, c0, 0 @ clock configuration, for turbo mode
  383. mrc p15, 0, r5, c15, c1, 0 @ CP access reg
  384. mrc p15, 0, r6, c13, c0, 0 @ PID
  385. mrc p15, 0, r7, c3, c0, 0 @ domain ID
  386. mrc p15, 0, r8, c1, c0, 1 @ auxiliary control reg
  387. mrc p15, 0, r9, c1, c0, 0 @ control reg
  388. bic r4, r4, #2 @ clear frequency change bit
  389. stmia r0, {r4 - r9} @ store cp regs
  390. ldmia sp!, {r4 - r9, pc}
  391. ENDPROC(cpu_xsc3_do_suspend)
  392. ENTRY(cpu_xsc3_do_resume)
  393. ldmia r0, {r4 - r9} @ load cp regs
  394. mov ip, #0
  395. mcr p15, 0, ip, c7, c7, 0 @ invalidate I & D caches, BTB
  396. mcr p15, 0, ip, c7, c10, 4 @ drain write (&fill) buffer
  397. mcr p15, 0, ip, c7, c5, 4 @ flush prefetch buffer
  398. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  399. mcr p14, 0, r4, c6, c0, 0 @ clock configuration, turbo mode.
  400. mcr p15, 0, r5, c15, c1, 0 @ CP access reg
  401. mcr p15, 0, r6, c13, c0, 0 @ PID
  402. mcr p15, 0, r7, c3, c0, 0 @ domain ID
  403. orr r1, r1, #0x18 @ cache the page table in L2
  404. mcr p15, 0, r1, c2, c0, 0 @ translation table base addr
  405. mcr p15, 0, r8, c1, c0, 1 @ auxiliary control reg
  406. mov r0, r9 @ control register
  407. b cpu_resume_mmu
  408. ENDPROC(cpu_xsc3_do_resume)
  409. #endif
  410. .type __xsc3_setup, #function
  411. __xsc3_setup:
  412. mov r0, #PSR_F_BIT|PSR_I_BIT|SVC_MODE
  413. msr cpsr_c, r0
  414. mcr p15, 0, ip, c7, c7, 0 @ invalidate L1 caches and BTB
  415. mcr p15, 0, ip, c7, c10, 4 @ data write barrier
  416. mcr p15, 0, ip, c7, c5, 4 @ prefetch flush
  417. mcr p15, 0, ip, c8, c7, 0 @ invalidate I and D TLBs
  418. orr r4, r4, #0x18 @ cache the page table in L2
  419. mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
  420. mov r0, #1 << 6 @ cp6 access for early sched_clock
  421. mcr p15, 0, r0, c15, c1, 0 @ write CP access register
  422. mrc p15, 0, r0, c1, c0, 1 @ get auxiliary control reg
  423. and r0, r0, #2 @ preserve bit P bit setting
  424. orr r0, r0, #(1 << 10) @ enable L2 for LLR cache
  425. mcr p15, 0, r0, c1, c0, 1 @ set auxiliary control reg
  426. adr r5, xsc3_crval
  427. ldmia r5, {r5, r6}
  428. #ifdef CONFIG_CACHE_XSC3L2
  429. mrc p15, 1, r0, c0, c0, 1 @ get L2 present information
  430. ands r0, r0, #0xf8
  431. orrne r6, r6, #(1 << 26) @ enable L2 if present
  432. #endif
  433. mrc p15, 0, r0, c1, c0, 0 @ get control register
  434. bic r0, r0, r5 @ ..V. ..R. .... ..A.
  435. orr r0, r0, r6 @ ..VI Z..S .... .C.M (mmu)
  436. @ ...I Z..S .... .... (uc)
  437. ret lr
  438. .size __xsc3_setup, . - __xsc3_setup
  439. .type xsc3_crval, #object
  440. xsc3_crval:
  441. crval clear=0x04002202, mmuset=0x00003905, ucset=0x00001900
  442. __INITDATA
  443. @ define struct processor (see <asm/proc-fns.h> and proc-macros.S)
  444. define_processor_functions xsc3, dabort=v5t_early_abort, pabort=legacy_pabort, suspend=1
  445. .section ".rodata"
  446. string cpu_arch_name, "armv5te"
  447. string cpu_elf_name, "v5"
  448. string cpu_xsc3_name, "XScale-V3 based processor"
  449. .align
  450. .section ".proc.info.init", #alloc
  451. .macro xsc3_proc_info name:req, cpu_val:req, cpu_mask:req
  452. .type __\name\()_proc_info,#object
  453. __\name\()_proc_info:
  454. .long \cpu_val
  455. .long \cpu_mask
  456. .long PMD_TYPE_SECT | \
  457. PMD_SECT_BUFFERABLE | \
  458. PMD_SECT_CACHEABLE | \
  459. PMD_SECT_AP_WRITE | \
  460. PMD_SECT_AP_READ
  461. .long PMD_TYPE_SECT | \
  462. PMD_SECT_AP_WRITE | \
  463. PMD_SECT_AP_READ
  464. initfn __xsc3_setup, __\name\()_proc_info
  465. .long cpu_arch_name
  466. .long cpu_elf_name
  467. .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
  468. .long cpu_xsc3_name
  469. .long xsc3_processor_functions
  470. .long v4wbi_tlb_fns
  471. .long xsc3_mc_user_fns
  472. .long xsc3_cache_fns
  473. .size __\name\()_proc_info, . - __\name\()_proc_info
  474. .endm
  475. xsc3_proc_info xsc3, 0x69056000, 0xffffe000
  476. /* Note: PXA935 changed its implementor ID from Intel to Marvell */
  477. xsc3_proc_info xsc3_pxa935, 0x56056000, 0xffffe000