proc-xsc3.S 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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 an
  15. * 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 orignal XScale code by Nicolas Pitre
  25. */
  26. #include <linux/linkage.h>
  27. #include <linux/init.h>
  28. #include <asm/assembler.h>
  29. #include <asm/elf.h>
  30. #include <asm/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 I and D cache.
  43. */
  44. #define CACHELINESIZE 32
  45. /*
  46. * The size of the data cache.
  47. */
  48. #define CACHESIZE 32768
  49. /*
  50. * Run with L2 enabled.
  51. */
  52. #define L2_CACHE_ENABLE 1
  53. /*
  54. * This macro is used to wait for a CP15 write and is needed
  55. * when we have to ensure that the last operation to the co-pro
  56. * was completed before continuing with operation.
  57. */
  58. .macro cpwait_ret, lr, rd
  59. mrc p15, 0, \rd, c2, c0, 0 @ arbitrary read of cp15
  60. sub pc, \lr, \rd, LSR #32 @ wait for completion and
  61. @ flush instruction pipeline
  62. .endm
  63. /*
  64. * This macro cleans & invalidates the entire xsc3 dcache by set & way.
  65. */
  66. .macro clean_d_cache rd, rs
  67. mov \rd, #0x1f00
  68. orr \rd, \rd, #0x00e0
  69. 1: mcr p15, 0, \rd, c7, c14, 2 @ clean/inv set/way
  70. adds \rd, \rd, #0x40000000
  71. bcc 1b
  72. subs \rd, \rd, #0x20
  73. bpl 1b
  74. .endm
  75. .text
  76. /*
  77. * cpu_xsc3_proc_init()
  78. *
  79. * Nothing too exciting at the moment
  80. */
  81. ENTRY(cpu_xsc3_proc_init)
  82. mov pc, lr
  83. /*
  84. * cpu_xsc3_proc_fin()
  85. */
  86. ENTRY(cpu_xsc3_proc_fin)
  87. str lr, [sp, #-4]!
  88. mov r0, #PSR_F_BIT|PSR_I_BIT|SVC_MODE
  89. msr cpsr_c, r0
  90. bl xsc3_flush_kern_cache_all @ clean caches
  91. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  92. bic r0, r0, #0x1800 @ ...IZ...........
  93. bic r0, r0, #0x0006 @ .............CA.
  94. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  95. ldr pc, [sp], #4
  96. /*
  97. * cpu_xsc3_reset(loc)
  98. *
  99. * Perform a soft reset of the system. Put the CPU into the
  100. * same state as it would be if it had been reset, and branch
  101. * to what would be the reset vector.
  102. *
  103. * loc: location to jump to for soft reset
  104. */
  105. .align 5
  106. ENTRY(cpu_xsc3_reset)
  107. mov r1, #PSR_F_BIT|PSR_I_BIT|SVC_MODE
  108. msr cpsr_c, r1 @ reset CPSR
  109. mrc p15, 0, r1, c1, c0, 0 @ ctrl register
  110. bic r1, r1, #0x0086 @ ........B....CA.
  111. bic r1, r1, #0x3900 @ ..VIZ..S........
  112. mcr p15, 0, r1, c1, c0, 0 @ ctrl register
  113. mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches & BTB
  114. bic r1, r1, #0x0001 @ ...............M
  115. mcr p15, 0, r1, c1, c0, 0 @ ctrl register
  116. @ CAUTION: MMU turned off from this point. We count on the pipeline
  117. @ already containing those two last instructions to survive.
  118. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  119. mov pc, r0
  120. /*
  121. * cpu_xsc3_do_idle()
  122. *
  123. * Cause the processor to idle
  124. *
  125. * For now we do nothing but go to idle mode for every case
  126. *
  127. * XScale supports clock switching, but using idle mode support
  128. * allows external hardware to react to system state changes.
  129. MMG: Come back to this one.
  130. */
  131. .align 5
  132. ENTRY(cpu_xsc3_do_idle)
  133. mov r0, #1
  134. mcr p14, 0, r0, c7, c0, 0 @ Go to IDLE
  135. mov pc, lr
  136. /* ================================= CACHE ================================ */
  137. /*
  138. * flush_user_cache_all()
  139. *
  140. * Invalidate all cache entries in a particular address
  141. * space.
  142. */
  143. ENTRY(xsc3_flush_user_cache_all)
  144. /* FALLTHROUGH */
  145. /*
  146. * flush_kern_cache_all()
  147. *
  148. * Clean and invalidate the entire cache.
  149. */
  150. ENTRY(xsc3_flush_kern_cache_all)
  151. mov r2, #VM_EXEC
  152. mov ip, #0
  153. __flush_whole_cache:
  154. clean_d_cache r0, r1
  155. tst r2, #VM_EXEC
  156. mcrne p15, 0, ip, c7, c5, 0 @ Invalidate I cache & BTB
  157. mcrne p15, 0, ip, c7, c10, 4 @ Drain Write Buffer
  158. mcrne p15, 0, ip, c7, c5, 4 @ Prefetch Flush
  159. mov pc, lr
  160. /*
  161. * flush_user_cache_range(start, end, vm_flags)
  162. *
  163. * Invalidate a range of cache entries in the specified
  164. * address space.
  165. *
  166. * - start - start address (may not be aligned)
  167. * - end - end address (exclusive, may not be aligned)
  168. * - vma - vma_area_struct describing address space
  169. */
  170. .align 5
  171. ENTRY(xsc3_flush_user_cache_range)
  172. mov ip, #0
  173. sub r3, r1, r0 @ calculate total size
  174. cmp r3, #MAX_AREA_SIZE
  175. bhs __flush_whole_cache
  176. 1: tst r2, #VM_EXEC
  177. mcrne p15, 0, r0, c7, c5, 1 @ Invalidate I cache line
  178. mcr p15, 0, r0, c7, c14, 1 @ Clean/invalidate D cache line
  179. add r0, r0, #CACHELINESIZE
  180. cmp r0, r1
  181. blo 1b
  182. tst r2, #VM_EXEC
  183. mcrne p15, 0, ip, c7, c5, 6 @ Invalidate BTB
  184. mcrne p15, 0, ip, c7, c10, 4 @ Drain Write Buffer
  185. mcrne p15, 0, ip, c7, c5, 4 @ Prefetch Flush
  186. mov pc, lr
  187. /*
  188. * coherent_kern_range(start, end)
  189. *
  190. * Ensure coherency between the Icache and the Dcache in the
  191. * region described by start. If you have non-snooping
  192. * Harvard caches, you need to implement this function.
  193. *
  194. * - start - virtual start address
  195. * - end - virtual end address
  196. *
  197. * Note: single I-cache line invalidation isn't used here since
  198. * it also trashes the mini I-cache used by JTAG debuggers.
  199. */
  200. ENTRY(xsc3_coherent_kern_range)
  201. /* FALLTHROUGH */
  202. ENTRY(xsc3_coherent_user_range)
  203. bic r0, r0, #CACHELINESIZE - 1
  204. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  205. add r0, r0, #CACHELINESIZE
  206. cmp r0, r1
  207. blo 1b
  208. mov r0, #0
  209. mcr p15, 0, r0, c7, c5, 0 @ Invalidate I cache & BTB
  210. mcr p15, 0, r0, c7, c10, 4 @ Drain Write Buffer
  211. mcr p15, 0, r0, c7, c5, 4 @ Prefetch Flush
  212. mov pc, lr
  213. /*
  214. * flush_kern_dcache_page(void *page)
  215. *
  216. * Ensure no D cache aliasing occurs, either with itself or
  217. * the I cache
  218. *
  219. * - addr - page aligned address
  220. */
  221. ENTRY(xsc3_flush_kern_dcache_page)
  222. add r1, r0, #PAGE_SZ
  223. 1: mcr p15, 0, r0, c7, c14, 1 @ Clean/Invalidate D Cache line
  224. add r0, r0, #CACHELINESIZE
  225. cmp r0, r1
  226. blo 1b
  227. mov r0, #0
  228. mcr p15, 0, r0, c7, c5, 0 @ Invalidate I cache & BTB
  229. mcr p15, 0, r0, c7, c10, 4 @ Drain Write Buffer
  230. mcr p15, 0, r0, c7, c5, 4 @ Prefetch Flush
  231. mov pc, lr
  232. /*
  233. * dma_inv_range(start, end)
  234. *
  235. * Invalidate (discard) the specified virtual address range.
  236. * May not write back any entries. If 'start' or 'end'
  237. * are not cache line aligned, those lines must be written
  238. * back.
  239. *
  240. * - start - virtual start address
  241. * - end - virtual end address
  242. */
  243. ENTRY(xsc3_dma_inv_range)
  244. tst r0, #CACHELINESIZE - 1
  245. bic r0, r0, #CACHELINESIZE - 1
  246. mcrne p15, 0, r0, c7, c10, 1 @ clean L1 D entry
  247. mcrne p15, 1, r0, c7, c11, 1 @ clean L2 D entry
  248. tst r1, #CACHELINESIZE - 1
  249. mcrne p15, 0, r1, c7, c10, 1 @ clean L1 D entry
  250. mcrne p15, 1, r1, c7, c11, 1 @ clean L2 D entry
  251. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate L1 D entry
  252. mcr p15, 1, r0, c7, c7, 1 @ Invalidate L2 D cache line
  253. add r0, r0, #CACHELINESIZE
  254. cmp r0, r1
  255. blo 1b
  256. mcr p15, 0, r0, c7, c10, 4 @ Drain Write Buffer
  257. mov pc, lr
  258. /*
  259. * dma_clean_range(start, end)
  260. *
  261. * Clean the specified virtual address range.
  262. *
  263. * - start - virtual start address
  264. * - end - virtual end address
  265. */
  266. ENTRY(xsc3_dma_clean_range)
  267. bic r0, r0, #CACHELINESIZE - 1
  268. 1: mcr p15, 0, r0, c7, c10, 1 @ clean L1 D entry
  269. mcr p15, 1, r0, c7, c11, 1 @ clean L2 D entry
  270. add r0, r0, #CACHELINESIZE
  271. cmp r0, r1
  272. blo 1b
  273. mcr p15, 0, r0, c7, c10, 4 @ Drain Write Buffer
  274. mov pc, 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 cache line
  286. mcr p15, 1, r0, c7, c11, 1 @ Clean L2 D cache line
  287. mcr p15, 1, r0, c7, c7, 1 @ Invalidate L2 D cache line
  288. add r0, r0, #CACHELINESIZE
  289. cmp r0, r1
  290. blo 1b
  291. mcr p15, 0, r0, c7, c10, 4 @ Drain Write Buffer
  292. mov pc, lr
  293. ENTRY(xsc3_cache_fns)
  294. .long xsc3_flush_kern_cache_all
  295. .long xsc3_flush_user_cache_all
  296. .long xsc3_flush_user_cache_range
  297. .long xsc3_coherent_kern_range
  298. .long xsc3_coherent_user_range
  299. .long xsc3_flush_kern_dcache_page
  300. .long xsc3_dma_inv_range
  301. .long xsc3_dma_clean_range
  302. .long xsc3_dma_flush_range
  303. ENTRY(cpu_xsc3_dcache_clean_area)
  304. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  305. add r0, r0, #CACHELINESIZE
  306. subs r1, r1, #CACHELINESIZE
  307. bhi 1b
  308. mov pc, lr
  309. /* =============================== PageTable ============================== */
  310. /*
  311. * cpu_xsc3_switch_mm(pgd)
  312. *
  313. * Set the translation base pointer to be as described by pgd.
  314. *
  315. * pgd: new page tables
  316. */
  317. .align 5
  318. ENTRY(cpu_xsc3_switch_mm)
  319. clean_d_cache r1, r2
  320. mcr p15, 0, ip, c7, c5, 0 @ Invalidate I cache & BTB
  321. mcr p15, 0, ip, c7, c10, 4 @ Drain Write Buffer
  322. mcr p15, 0, ip, c7, c5, 4 @ Prefetch Flush
  323. #ifdef L2_CACHE_ENABLE
  324. orr r0, r0, #0x18 @ cache the page table in L2
  325. #endif
  326. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  327. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  328. cpwait_ret lr, ip
  329. /*
  330. * cpu_xsc3_set_pte_ext(ptep, pte, ext)
  331. *
  332. * Set a PTE and flush it out
  333. *
  334. */
  335. .align 5
  336. ENTRY(cpu_xsc3_set_pte_ext)
  337. str r1, [r0], #-2048 @ linux version
  338. bic r2, r1, #0xff0 @ Keep C, B bits
  339. orr r2, r2, #PTE_TYPE_EXT @ extended page
  340. tst r1, #L_PTE_SHARED @ Shared?
  341. orrne r2, r2, #0x200
  342. eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
  343. tst r3, #L_PTE_USER @ User?
  344. orrne r2, r2, #PTE_EXT_AP_URO_SRW @ yes -> user r/o, system r/w
  345. tst r3, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
  346. orreq r2, r2, #PTE_EXT_AP_UNO_SRW @ yes -> user n/a, system r/w
  347. @ combined with user -> user r/w
  348. #if L2_CACHE_ENABLE
  349. @ If its cacheable it needs to be in L2 also.
  350. eor ip, r1, #L_PTE_CACHEABLE
  351. tst ip, #L_PTE_CACHEABLE
  352. orreq r2, r2, #PTE_EXT_TEX(0x5)
  353. #endif
  354. tst r3, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
  355. movne r2, #0 @ no -> fault
  356. str r2, [r0] @ hardware version
  357. mov ip, #0
  358. mcr p15, 0, r0, c7, c10, 1 @ Clean D cache line mcr
  359. mcr p15, 0, ip, c7, c10, 4 @ Drain Write Buffer
  360. mov pc, lr
  361. .ltorg
  362. .align
  363. __INIT
  364. .type __xsc3_setup, #function
  365. __xsc3_setup:
  366. mov r0, #PSR_F_BIT|PSR_I_BIT|SVC_MODE
  367. msr cpsr_c, r0
  368. mcr p15, 0, ip, c7, c7, 0 @ invalidate I, D caches & BTB
  369. mcr p15, 0, ip, c7, c10, 4 @ Drain Write Buffer
  370. mcr p15, 0, ip, c7, c5, 4 @ Prefetch Flush
  371. mcr p15, 0, ip, c8, c7, 0 @ invalidate I, D TLBs
  372. #if L2_CACHE_ENABLE
  373. orr r4, r4, #0x18 @ cache the page table in L2
  374. #endif
  375. mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
  376. mov r0, #1 @ Allow access to CP0 and CP13
  377. orr r0, r0, #1 << 13 @ Its undefined whether this
  378. mcr p15, 0, r0, c15, c1, 0 @ affects USR or SVC modes
  379. mrc p15, 0, r0, c1, c0, 1 @ get auxiliary control reg
  380. and r0, r0, #2 @ preserve bit P bit setting
  381. #if L2_CACHE_ENABLE
  382. orr r0, r0, #(1 << 10) @ enable L2 for LLR cache
  383. #endif
  384. mcr p15, 0, r0, c1, c0, 1 @ set auxiliary control reg
  385. adr r5, xsc3_crval
  386. ldmia r5, {r5, r6}
  387. mrc p15, 0, r0, c1, c0, 0 @ get control register
  388. bic r0, r0, r5 @ .... .... .... ..A.
  389. orr r0, r0, r6 @ .... .... .... .C.M
  390. orr r0, r0, #0x00000800 @ ..VI Z..S .... ....
  391. #if L2_CACHE_ENABLE
  392. orr r0, r0, #0x04000000 @ L2 enable
  393. #endif
  394. mov pc, lr
  395. .size __xsc3_setup, . - __xsc3_setup
  396. .type xsc3_crval, #object
  397. xsc3_crval:
  398. crval clear=0x04003b02, mmuset=0x00003105, ucset=0x00001100
  399. __INITDATA
  400. /*
  401. * Purpose : Function pointers used to access above functions - all calls
  402. * come through these
  403. */
  404. .type xsc3_processor_functions, #object
  405. ENTRY(xsc3_processor_functions)
  406. .word v5t_early_abort
  407. .word cpu_xsc3_proc_init
  408. .word cpu_xsc3_proc_fin
  409. .word cpu_xsc3_reset
  410. .word cpu_xsc3_do_idle
  411. .word cpu_xsc3_dcache_clean_area
  412. .word cpu_xsc3_switch_mm
  413. .word cpu_xsc3_set_pte_ext
  414. .size xsc3_processor_functions, . - xsc3_processor_functions
  415. .section ".rodata"
  416. .type cpu_arch_name, #object
  417. cpu_arch_name:
  418. .asciz "armv5te"
  419. .size cpu_arch_name, . - cpu_arch_name
  420. .type cpu_elf_name, #object
  421. cpu_elf_name:
  422. .asciz "v5"
  423. .size cpu_elf_name, . - cpu_elf_name
  424. .type cpu_xsc3_name, #object
  425. cpu_xsc3_name:
  426. .asciz "XScale-Core3"
  427. .size cpu_xsc3_name, . - cpu_xsc3_name
  428. .align
  429. .section ".proc.info.init", #alloc, #execinstr
  430. .type __xsc3_proc_info,#object
  431. __xsc3_proc_info:
  432. .long 0x69056000
  433. .long 0xffffe000
  434. .long PMD_TYPE_SECT | \
  435. PMD_SECT_BUFFERABLE | \
  436. PMD_SECT_CACHEABLE | \
  437. PMD_SECT_AP_WRITE | \
  438. PMD_SECT_AP_READ
  439. .long PMD_TYPE_SECT | \
  440. PMD_SECT_AP_WRITE | \
  441. PMD_SECT_AP_READ
  442. b __xsc3_setup
  443. .long cpu_arch_name
  444. .long cpu_elf_name
  445. .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
  446. .long cpu_xsc3_name
  447. .long xsc3_processor_functions
  448. .long v4wbi_tlb_fns
  449. .long xsc3_mc_user_fns
  450. .long xsc3_cache_fns
  451. .size __xsc3_proc_info, . - __xsc3_proc_info