proc-xsc3.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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 <mach/hardware.h>
  31. #include <asm/pgtable.h>
  32. #include <asm/pgtable-hwdef.h>
  33. #include <asm/page.h>
  34. #include <asm/ptrace.h>
  35. #include "proc-macros.S"
  36. /*
  37. * This is the maximum size of an area which will be flushed. If the
  38. * area is larger than this, then we flush the whole cache.
  39. */
  40. #define MAX_AREA_SIZE 32768
  41. /*
  42. * The cache line size of the L1 I, L1 D and unified L2 cache.
  43. */
  44. #define CACHELINESIZE 32
  45. /*
  46. * The size of the L1 D cache.
  47. */
  48. #define CACHESIZE 32768
  49. /*
  50. * This macro is used to wait for a CP15 write and is needed when we
  51. * have to ensure that the last operation to the coprocessor was
  52. * completed before continuing with operation.
  53. */
  54. .macro cpwait_ret, lr, rd
  55. mrc p15, 0, \rd, c2, c0, 0 @ arbitrary read of cp15
  56. sub pc, \lr, \rd, LSR #32 @ wait for completion and
  57. @ flush instruction pipeline
  58. .endm
  59. /*
  60. * This macro cleans and invalidates the entire L1 D cache.
  61. */
  62. .macro clean_d_cache rd, rs
  63. mov \rd, #0x1f00
  64. orr \rd, \rd, #0x00e0
  65. 1: mcr p15, 0, \rd, c7, c14, 2 @ clean/invalidate L1 D line
  66. adds \rd, \rd, #0x40000000
  67. bcc 1b
  68. subs \rd, \rd, #0x20
  69. bpl 1b
  70. .endm
  71. .text
  72. /*
  73. * cpu_xsc3_proc_init()
  74. *
  75. * Nothing too exciting at the moment
  76. */
  77. ENTRY(cpu_xsc3_proc_init)
  78. mov pc, lr
  79. /*
  80. * cpu_xsc3_proc_fin()
  81. */
  82. ENTRY(cpu_xsc3_proc_fin)
  83. str lr, [sp, #-4]!
  84. mov r0, #PSR_F_BIT|PSR_I_BIT|SVC_MODE
  85. msr cpsr_c, r0
  86. bl xsc3_flush_kern_cache_all @ clean caches
  87. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  88. bic r0, r0, #0x1800 @ ...IZ...........
  89. bic r0, r0, #0x0006 @ .............CA.
  90. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  91. ldr pc, [sp], #4
  92. /*
  93. * cpu_xsc3_reset(loc)
  94. *
  95. * Perform a soft reset of the system. Put the CPU into the
  96. * same state as it would be if it had been reset, and branch
  97. * to what would be the reset vector.
  98. *
  99. * loc: location to jump to for soft reset
  100. */
  101. .align 5
  102. ENTRY(cpu_xsc3_reset)
  103. mov r1, #PSR_F_BIT|PSR_I_BIT|SVC_MODE
  104. msr cpsr_c, r1 @ reset CPSR
  105. mrc p15, 0, r1, c1, c0, 0 @ ctrl register
  106. bic r1, r1, #0x3900 @ ..VIZ..S........
  107. bic r1, r1, #0x0086 @ ........B....CA.
  108. mcr p15, 0, r1, c1, c0, 0 @ ctrl register
  109. mcr p15, 0, ip, c7, c7, 0 @ invalidate L1 caches and BTB
  110. bic r1, r1, #0x0001 @ ...............M
  111. mcr p15, 0, r1, c1, c0, 0 @ ctrl register
  112. @ CAUTION: MMU turned off from this point. We count on the pipeline
  113. @ already containing those two last instructions to survive.
  114. mcr p15, 0, ip, c8, c7, 0 @ invalidate I and D TLBs
  115. mov pc, r0
  116. /*
  117. * cpu_xsc3_do_idle()
  118. *
  119. * Cause the processor to idle
  120. *
  121. * For now we do nothing but go to idle mode for every case
  122. *
  123. * XScale supports clock switching, but using idle mode support
  124. * allows external hardware to react to system state changes.
  125. */
  126. .align 5
  127. ENTRY(cpu_xsc3_do_idle)
  128. mov r0, #1
  129. mcr p14, 0, r0, c7, c0, 0 @ go to idle
  130. mov pc, lr
  131. /* ================================= CACHE ================================ */
  132. /*
  133. * flush_user_cache_all()
  134. *
  135. * Invalidate all cache entries in a particular address
  136. * space.
  137. */
  138. ENTRY(xsc3_flush_user_cache_all)
  139. /* FALLTHROUGH */
  140. /*
  141. * flush_kern_cache_all()
  142. *
  143. * Clean and invalidate the entire cache.
  144. */
  145. ENTRY(xsc3_flush_kern_cache_all)
  146. mov r2, #VM_EXEC
  147. mov ip, #0
  148. __flush_whole_cache:
  149. clean_d_cache r0, r1
  150. tst r2, #VM_EXEC
  151. mcrne p15, 0, ip, c7, c5, 0 @ invalidate L1 I cache and BTB
  152. mcrne p15, 0, ip, c7, c10, 4 @ data write barrier
  153. mcrne p15, 0, ip, c7, c5, 4 @ prefetch flush
  154. mov pc, lr
  155. /*
  156. * flush_user_cache_range(start, end, vm_flags)
  157. *
  158. * Invalidate a range of cache entries in the specified
  159. * address space.
  160. *
  161. * - start - start address (may not be aligned)
  162. * - end - end address (exclusive, may not be aligned)
  163. * - vma - vma_area_struct describing address space
  164. */
  165. .align 5
  166. ENTRY(xsc3_flush_user_cache_range)
  167. mov ip, #0
  168. sub r3, r1, r0 @ calculate total size
  169. cmp r3, #MAX_AREA_SIZE
  170. bhs __flush_whole_cache
  171. 1: tst r2, #VM_EXEC
  172. mcrne p15, 0, r0, c7, c5, 1 @ invalidate L1 I line
  173. mcr p15, 0, r0, c7, c14, 1 @ clean/invalidate L1 D line
  174. add r0, r0, #CACHELINESIZE
  175. cmp r0, r1
  176. blo 1b
  177. tst r2, #VM_EXEC
  178. mcrne p15, 0, ip, c7, c5, 6 @ invalidate BTB
  179. mcrne p15, 0, ip, c7, c10, 4 @ data write barrier
  180. mcrne p15, 0, ip, c7, c5, 4 @ prefetch flush
  181. mov pc, lr
  182. /*
  183. * coherent_kern_range(start, end)
  184. *
  185. * Ensure coherency between the I cache and the D cache in the
  186. * region described by start. If you have non-snooping
  187. * Harvard caches, you need to implement this function.
  188. *
  189. * - start - virtual start address
  190. * - end - virtual end address
  191. *
  192. * Note: single I-cache line invalidation isn't used here since
  193. * it also trashes the mini I-cache used by JTAG debuggers.
  194. */
  195. ENTRY(xsc3_coherent_kern_range)
  196. /* FALLTHROUGH */
  197. ENTRY(xsc3_coherent_user_range)
  198. bic r0, r0, #CACHELINESIZE - 1
  199. 1: mcr p15, 0, r0, c7, c10, 1 @ clean L1 D line
  200. add r0, r0, #CACHELINESIZE
  201. cmp r0, r1
  202. blo 1b
  203. mov r0, #0
  204. mcr p15, 0, r0, c7, c5, 0 @ invalidate L1 I cache and BTB
  205. mcr p15, 0, r0, c7, c10, 4 @ data write barrier
  206. mcr p15, 0, r0, c7, c5, 4 @ prefetch flush
  207. mov pc, lr
  208. /*
  209. * flush_kern_dcache_page(void *page)
  210. *
  211. * Ensure no D cache aliasing occurs, either with itself or
  212. * the I cache.
  213. *
  214. * - addr - page aligned address
  215. */
  216. ENTRY(xsc3_flush_kern_dcache_page)
  217. add r1, r0, #PAGE_SZ
  218. 1: mcr p15, 0, r0, c7, c14, 1 @ clean/invalidate L1 D line
  219. add r0, r0, #CACHELINESIZE
  220. cmp r0, r1
  221. blo 1b
  222. mov r0, #0
  223. mcr p15, 0, r0, c7, c5, 0 @ invalidate L1 I cache and BTB
  224. mcr p15, 0, r0, c7, c10, 4 @ data write barrier
  225. mcr p15, 0, r0, c7, c5, 4 @ prefetch flush
  226. mov pc, 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. ENTRY(xsc3_dma_inv_range)
  239. tst r0, #CACHELINESIZE - 1
  240. bic r0, r0, #CACHELINESIZE - 1
  241. mcrne p15, 0, r0, c7, c10, 1 @ clean L1 D line
  242. tst r1, #CACHELINESIZE - 1
  243. mcrne p15, 0, r1, c7, c10, 1 @ clean L1 D line
  244. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate L1 D line
  245. add r0, r0, #CACHELINESIZE
  246. cmp r0, r1
  247. blo 1b
  248. mcr p15, 0, r0, c7, c10, 4 @ data write barrier
  249. mov pc, lr
  250. /*
  251. * dma_clean_range(start, end)
  252. *
  253. * Clean the specified virtual address range.
  254. *
  255. * - start - virtual start address
  256. * - end - virtual end address
  257. */
  258. ENTRY(xsc3_dma_clean_range)
  259. bic r0, r0, #CACHELINESIZE - 1
  260. 1: mcr p15, 0, r0, c7, c10, 1 @ clean L1 D line
  261. add r0, r0, #CACHELINESIZE
  262. cmp r0, r1
  263. blo 1b
  264. mcr p15, 0, r0, c7, c10, 4 @ data write barrier
  265. mov pc, lr
  266. /*
  267. * dma_flush_range(start, end)
  268. *
  269. * Clean and invalidate the specified virtual address range.
  270. *
  271. * - start - virtual start address
  272. * - end - virtual end address
  273. */
  274. ENTRY(xsc3_dma_flush_range)
  275. bic r0, r0, #CACHELINESIZE - 1
  276. 1: mcr p15, 0, r0, c7, c14, 1 @ clean/invalidate L1 D line
  277. add r0, r0, #CACHELINESIZE
  278. cmp r0, r1
  279. blo 1b
  280. mcr p15, 0, r0, c7, c10, 4 @ data write barrier
  281. mov pc, lr
  282. ENTRY(xsc3_cache_fns)
  283. .long xsc3_flush_kern_cache_all
  284. .long xsc3_flush_user_cache_all
  285. .long xsc3_flush_user_cache_range
  286. .long xsc3_coherent_kern_range
  287. .long xsc3_coherent_user_range
  288. .long xsc3_flush_kern_dcache_page
  289. .long xsc3_dma_inv_range
  290. .long xsc3_dma_clean_range
  291. .long xsc3_dma_flush_range
  292. ENTRY(cpu_xsc3_dcache_clean_area)
  293. 1: mcr p15, 0, r0, c7, c10, 1 @ clean L1 D line
  294. add r0, r0, #CACHELINESIZE
  295. subs r1, r1, #CACHELINESIZE
  296. bhi 1b
  297. mov pc, lr
  298. /* =============================== PageTable ============================== */
  299. /*
  300. * cpu_xsc3_switch_mm(pgd)
  301. *
  302. * Set the translation base pointer to be as described by pgd.
  303. *
  304. * pgd: new page tables
  305. */
  306. .align 5
  307. ENTRY(cpu_xsc3_switch_mm)
  308. clean_d_cache r1, r2
  309. mcr p15, 0, ip, c7, c5, 0 @ invalidate L1 I cache and BTB
  310. mcr p15, 0, ip, c7, c10, 4 @ data write barrier
  311. mcr p15, 0, ip, c7, c5, 4 @ prefetch flush
  312. orr r0, r0, #0x18 @ cache the page table in L2
  313. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  314. mcr p15, 0, ip, c8, c7, 0 @ invalidate I and D TLBs
  315. cpwait_ret lr, ip
  316. /*
  317. * cpu_xsc3_set_pte_ext(ptep, pte, ext)
  318. *
  319. * Set a PTE and flush it out
  320. */
  321. cpu_xsc3_mt_table:
  322. .long 0x00 @ L_PTE_MT_UNCACHED
  323. .long PTE_EXT_TEX(1) @ L_PTE_MT_BUFFERABLE
  324. .long PTE_CACHEABLE @ L_PTE_MT_WRITETHROUGH
  325. .long PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_WRITEBACK
  326. .long PTE_EXT_TEX(1) | PTE_BUFFERABLE @ L_PTE_MT_DEV_SHARED
  327. .long 0x00 @ unused
  328. .long 0x00 @ L_PTE_MT_MINICACHE (not present)
  329. .long PTE_EXT_TEX(5) | PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_WRITEALLOC (not present?)
  330. .long 0x00 @ unused
  331. .long PTE_EXT_TEX(1) @ L_PTE_MT_DEV_WC
  332. .long 0x00 @ unused
  333. .long PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_DEV_CACHED
  334. .long PTE_EXT_TEX(2) @ L_PTE_MT_DEV_NONSHARED
  335. .long 0x00 @ unused
  336. .long 0x00 @ unused
  337. .long 0x00 @ unused
  338. .align 5
  339. ENTRY(cpu_xsc3_set_pte_ext)
  340. xscale_set_pte_ext_prologue
  341. tst r1, #L_PTE_SHARED @ shared?
  342. and r1, r1, #L_PTE_MT_MASK
  343. adr ip, cpu_xsc3_mt_table
  344. ldr ip, [ip, r1]
  345. orrne r2, r2, #PTE_EXT_COHERENT @ interlock: mask in coherent bit
  346. bic r2, r2, #0x0c @ clear old C,B bits
  347. orr r2, r2, ip
  348. xscale_set_pte_ext_epilogue
  349. mov pc, lr
  350. .ltorg
  351. .align
  352. __INIT
  353. .type __xsc3_setup, #function
  354. __xsc3_setup:
  355. mov r0, #PSR_F_BIT|PSR_I_BIT|SVC_MODE
  356. msr cpsr_c, r0
  357. mcr p15, 0, ip, c7, c7, 0 @ invalidate L1 caches and BTB
  358. mcr p15, 0, ip, c7, c10, 4 @ data write barrier
  359. mcr p15, 0, ip, c7, c5, 4 @ prefetch flush
  360. mcr p15, 0, ip, c8, c7, 0 @ invalidate I and D TLBs
  361. orr r4, r4, #0x18 @ cache the page table in L2
  362. mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
  363. mov r0, #0 @ don't allow CP access
  364. mcr p15, 0, r0, c15, c1, 0 @ write CP access register
  365. mrc p15, 0, r0, c1, c0, 1 @ get auxiliary control reg
  366. and r0, r0, #2 @ preserve bit P bit setting
  367. orr r0, r0, #(1 << 10) @ enable L2 for LLR cache
  368. mcr p15, 0, r0, c1, c0, 1 @ set auxiliary control reg
  369. adr r5, xsc3_crval
  370. ldmia r5, {r5, r6}
  371. mrc p15, 0, r0, c1, c0, 0 @ get control register
  372. bic r0, r0, r5 @ ..V. ..R. .... ..A.
  373. orr r0, r0, r6 @ ..VI Z..S .... .C.M (mmu)
  374. @ ...I Z..S .... .... (uc)
  375. mov pc, lr
  376. .size __xsc3_setup, . - __xsc3_setup
  377. .type xsc3_crval, #object
  378. xsc3_crval:
  379. crval clear=0x04002202, mmuset=0x00003905, ucset=0x00001900
  380. __INITDATA
  381. /*
  382. * Purpose : Function pointers used to access above functions - all calls
  383. * come through these
  384. */
  385. .type xsc3_processor_functions, #object
  386. ENTRY(xsc3_processor_functions)
  387. .word v5t_early_abort
  388. .word pabort_noifar
  389. .word cpu_xsc3_proc_init
  390. .word cpu_xsc3_proc_fin
  391. .word cpu_xsc3_reset
  392. .word cpu_xsc3_do_idle
  393. .word cpu_xsc3_dcache_clean_area
  394. .word cpu_xsc3_switch_mm
  395. .word cpu_xsc3_set_pte_ext
  396. .size xsc3_processor_functions, . - xsc3_processor_functions
  397. .section ".rodata"
  398. .type cpu_arch_name, #object
  399. cpu_arch_name:
  400. .asciz "armv5te"
  401. .size cpu_arch_name, . - cpu_arch_name
  402. .type cpu_elf_name, #object
  403. cpu_elf_name:
  404. .asciz "v5"
  405. .size cpu_elf_name, . - cpu_elf_name
  406. .type cpu_xsc3_name, #object
  407. cpu_xsc3_name:
  408. .asciz "XScale-V3 based processor"
  409. .size cpu_xsc3_name, . - cpu_xsc3_name
  410. .align
  411. .section ".proc.info.init", #alloc, #execinstr
  412. .type __xsc3_proc_info,#object
  413. __xsc3_proc_info:
  414. .long 0x69056000
  415. .long 0xffffe000
  416. .long PMD_TYPE_SECT | \
  417. PMD_SECT_BUFFERABLE | \
  418. PMD_SECT_CACHEABLE | \
  419. PMD_SECT_AP_WRITE | \
  420. PMD_SECT_AP_READ
  421. .long PMD_TYPE_SECT | \
  422. PMD_SECT_AP_WRITE | \
  423. PMD_SECT_AP_READ
  424. b __xsc3_setup
  425. .long cpu_arch_name
  426. .long cpu_elf_name
  427. .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
  428. .long cpu_xsc3_name
  429. .long xsc3_processor_functions
  430. .long v4wbi_tlb_fns
  431. .long xsc3_mc_user_fns
  432. .long xsc3_cache_fns
  433. .size __xsc3_proc_info, . - __xsc3_proc_info