proc-xsc3.S 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. /*
  2. * linux/arch/arm/mm/proc-xsc3.S
  3. *
  4. * Original Author: Matthew Gilbert
  5. * Current Maintainer: Deepak Saxena <dsaxena@plexity.net>
  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/procinfo.h>
  30. #include <asm/hardware.h>
  31. #include <asm/pgtable.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 I and D cache.
  42. */
  43. #define CACHELINESIZE 32
  44. /*
  45. * The size of the data cache.
  46. */
  47. #define CACHESIZE 32768
  48. /*
  49. * Run with L2 enabled.
  50. */
  51. #define L2_CACHE_ENABLE 1
  52. /*
  53. * Enable the Branch Target Buffer (can cause crashes, see erratum #42.)
  54. */
  55. #define BTB_ENABLE 0
  56. /*
  57. * This macro is used to wait for a CP15 write and is needed
  58. * when we have to ensure that the last operation to the co-pro
  59. * was completed before continuing with operation.
  60. */
  61. .macro cpwait_ret, lr, rd
  62. mrc p15, 0, \rd, c2, c0, 0 @ arbitrary read of cp15
  63. sub pc, \lr, \rd, LSR #32 @ wait for completion and
  64. @ flush instruction pipeline
  65. .endm
  66. /*
  67. * This macro cleans & invalidates the entire xsc3 dcache by set & way.
  68. */
  69. .macro clean_d_cache rd, rs
  70. mov \rd, #0x1f00
  71. orr \rd, \rd, #0x00e0
  72. 1: mcr p15, 0, \rd, c7, c14, 2 @ clean/inv set/way
  73. adds \rd, \rd, #0x40000000
  74. bcc 1b
  75. subs \rd, \rd, #0x20
  76. bpl 1b
  77. .endm
  78. .text
  79. /*
  80. * cpu_xsc3_proc_init()
  81. *
  82. * Nothing too exciting at the moment
  83. */
  84. ENTRY(cpu_xsc3_proc_init)
  85. mov pc, lr
  86. /*
  87. * cpu_xsc3_proc_fin()
  88. */
  89. ENTRY(cpu_xsc3_proc_fin)
  90. str lr, [sp, #-4]!
  91. mov r0, #PSR_F_BIT|PSR_I_BIT|SVC_MODE
  92. msr cpsr_c, r0
  93. bl xsc3_flush_kern_cache_all @ clean caches
  94. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  95. bic r0, r0, #0x1800 @ ...IZ...........
  96. bic r0, r0, #0x0006 @ .............CA.
  97. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  98. ldr pc, [sp], #4
  99. /*
  100. * cpu_xsc3_reset(loc)
  101. *
  102. * Perform a soft reset of the system. Put the CPU into the
  103. * same state as it would be if it had been reset, and branch
  104. * to what would be the reset vector.
  105. *
  106. * loc: location to jump to for soft reset
  107. */
  108. .align 5
  109. ENTRY(cpu_xsc3_reset)
  110. mov r1, #PSR_F_BIT|PSR_I_BIT|SVC_MODE
  111. msr cpsr_c, r1 @ reset CPSR
  112. mrc p15, 0, r1, c1, c0, 0 @ ctrl register
  113. bic r1, r1, #0x0086 @ ........B....CA.
  114. bic r1, r1, #0x3900 @ ..VIZ..S........
  115. mcr p15, 0, r1, c1, c0, 0 @ ctrl register
  116. mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches & BTB
  117. bic r1, r1, #0x0001 @ ...............M
  118. mcr p15, 0, r1, c1, c0, 0 @ ctrl register
  119. @ CAUTION: MMU turned off from this point. We count on the pipeline
  120. @ already containing those two last instructions to survive.
  121. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  122. mov pc, r0
  123. /*
  124. * cpu_xsc3_do_idle()
  125. *
  126. * Cause the processor to idle
  127. *
  128. * For now we do nothing but go to idle mode for every case
  129. *
  130. * XScale supports clock switching, but using idle mode support
  131. * allows external hardware to react to system state changes.
  132. MMG: Come back to this one.
  133. */
  134. .align 5
  135. ENTRY(cpu_xsc3_do_idle)
  136. mov r0, #1
  137. mcr p14, 0, r0, c7, c0, 0 @ Go to IDLE
  138. mov pc, lr
  139. /* ================================= CACHE ================================ */
  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 I cache & BTB
  160. mcrne p15, 0, ip, c7, c10, 4 @ Drain Write Buffer
  161. mcrne p15, 0, ip, c7, c5, 4 @ Prefetch Flush
  162. mov pc, 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 I cache line
  181. mcr p15, 0, r0, c7, c14, 1 @ Clean/invalidate D cache 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 @ Drain Write Buffer
  188. mcrne p15, 0, ip, c7, c5, 4 @ Prefetch Flush
  189. mov pc, lr
  190. /*
  191. * coherent_kern_range(start, end)
  192. *
  193. * Ensure coherency between the Icache and the Dcache 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 D entry
  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 I cache & BTB
  213. mcr p15, 0, r0, c7, c10, 4 @ Drain Write Buffer
  214. mcr p15, 0, r0, c7, c5, 4 @ Prefetch Flush
  215. mov pc, lr
  216. /*
  217. * flush_kern_dcache_page(void *page)
  218. *
  219. * Ensure no D cache aliasing occurs, either with itself or
  220. * the I cache
  221. *
  222. * - addr - page aligned address
  223. */
  224. ENTRY(xsc3_flush_kern_dcache_page)
  225. add r1, r0, #PAGE_SZ
  226. 1: mcr p15, 0, r0, c7, c14, 1 @ Clean/Invalidate D Cache line
  227. add r0, r0, #CACHELINESIZE
  228. cmp r0, r1
  229. blo 1b
  230. mov r0, #0
  231. mcr p15, 0, r0, c7, c5, 0 @ Invalidate I cache & BTB
  232. mcr p15, 0, r0, c7, c10, 4 @ Drain Write Buffer
  233. mcr p15, 0, r0, c7, c5, 4 @ Prefetch Flush
  234. mov pc, lr
  235. /*
  236. * dma_inv_range(start, end)
  237. *
  238. * Invalidate (discard) the specified virtual address range.
  239. * May not write back any entries. If 'start' or 'end'
  240. * are not cache line aligned, those lines must be written
  241. * back.
  242. *
  243. * - start - virtual start address
  244. * - end - virtual end address
  245. */
  246. ENTRY(xsc3_dma_inv_range)
  247. tst r0, #CACHELINESIZE - 1
  248. bic r0, r0, #CACHELINESIZE - 1
  249. mcrne p15, 0, r0, c7, c10, 1 @ clean L1 D entry
  250. mcrne p15, 1, r0, c7, c11, 1 @ clean L2 D entry
  251. tst r1, #CACHELINESIZE - 1
  252. mcrne p15, 0, r1, c7, c10, 1 @ clean L1 D entry
  253. mcrne p15, 1, r1, c7, c11, 1 @ clean L2 D entry
  254. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate L1 D entry
  255. mcr p15, 1, r0, c7, c7, 1 @ Invalidate L2 D cache line
  256. add r0, r0, #CACHELINESIZE
  257. cmp r0, r1
  258. blo 1b
  259. mcr p15, 0, r0, c7, c10, 4 @ Drain Write Buffer
  260. mov pc, lr
  261. /*
  262. * dma_clean_range(start, end)
  263. *
  264. * Clean the specified virtual address range.
  265. *
  266. * - start - virtual start address
  267. * - end - virtual end address
  268. */
  269. ENTRY(xsc3_dma_clean_range)
  270. bic r0, r0, #CACHELINESIZE - 1
  271. 1: mcr p15, 0, r0, c7, c10, 1 @ clean L1 D entry
  272. mcr p15, 1, r0, c7, c11, 1 @ clean L2 D entry
  273. add r0, r0, #CACHELINESIZE
  274. cmp r0, r1
  275. blo 1b
  276. mcr p15, 0, r0, c7, c10, 4 @ Drain Write Buffer
  277. mov pc, lr
  278. /*
  279. * dma_flush_range(start, end)
  280. *
  281. * Clean and invalidate the specified virtual address range.
  282. *
  283. * - start - virtual start address
  284. * - end - virtual end address
  285. */
  286. ENTRY(xsc3_dma_flush_range)
  287. bic r0, r0, #CACHELINESIZE - 1
  288. 1: mcr p15, 0, r0, c7, c14, 1 @ Clean/invalidate L1 D cache line
  289. mcr p15, 1, r0, c7, c11, 1 @ Clean L2 D cache line
  290. mcr p15, 1, r0, c7, c7, 1 @ Invalidate L2 D cache line
  291. add r0, r0, #CACHELINESIZE
  292. cmp r0, r1
  293. blo 1b
  294. mcr p15, 0, r0, c7, c10, 4 @ Drain Write Buffer
  295. mov pc, lr
  296. ENTRY(xsc3_cache_fns)
  297. .long xsc3_flush_kern_cache_all
  298. .long xsc3_flush_user_cache_all
  299. .long xsc3_flush_user_cache_range
  300. .long xsc3_coherent_kern_range
  301. .long xsc3_coherent_user_range
  302. .long xsc3_flush_kern_dcache_page
  303. .long xsc3_dma_inv_range
  304. .long xsc3_dma_clean_range
  305. .long xsc3_dma_flush_range
  306. ENTRY(cpu_xsc3_dcache_clean_area)
  307. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  308. add r0, r0, #CACHELINESIZE
  309. subs r1, r1, #CACHELINESIZE
  310. bhi 1b
  311. mov pc, lr
  312. /* =============================== PageTable ============================== */
  313. /*
  314. * cpu_xsc3_switch_mm(pgd)
  315. *
  316. * Set the translation base pointer to be as described by pgd.
  317. *
  318. * pgd: new page tables
  319. */
  320. .align 5
  321. ENTRY(cpu_xsc3_switch_mm)
  322. clean_d_cache r1, r2
  323. mcr p15, 0, ip, c7, c5, 0 @ Invalidate I cache & BTB
  324. mcr p15, 0, ip, c7, c10, 4 @ Drain Write Buffer
  325. mcr p15, 0, ip, c7, c5, 4 @ Prefetch Flush
  326. #ifdef L2_CACHE_ENABLE
  327. orr r0, r0, #0x18 @ cache the page table in L2
  328. #endif
  329. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  330. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  331. cpwait_ret lr, ip
  332. /*
  333. * cpu_xsc3_set_pte(ptep, pte)
  334. *
  335. * Set a PTE and flush it out
  336. *
  337. */
  338. .align 5
  339. ENTRY(cpu_xsc3_set_pte)
  340. str r1, [r0], #-2048 @ linux version
  341. bic r2, r1, #0xff0
  342. orr r2, r2, #PTE_TYPE_EXT @ extended page
  343. eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
  344. tst r3, #L_PTE_USER @ User?
  345. orrne r2, r2, #PTE_EXT_AP_URO_SRW @ yes -> user r/o, system r/w
  346. tst r3, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
  347. orreq r2, r2, #PTE_EXT_AP_UNO_SRW @ yes -> user n/a, system r/w
  348. @ combined with user -> user r/w
  349. #if L2_CACHE_ENABLE
  350. @ If its cacheable it needs to be in L2 also.
  351. eor ip, r1, #L_PTE_CACHEABLE
  352. tst ip, #L_PTE_CACHEABLE
  353. orreq r2, r2, #PTE_EXT_TEX(0x5)
  354. #endif
  355. tst r3, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
  356. movne r2, #0 @ no -> fault
  357. str r2, [r0] @ hardware version
  358. mov ip, #0
  359. mcr p15, 0, r0, c7, c10, 1 @ Clean D cache line mcr
  360. mcr p15, 0, ip, c7, c10, 4 @ Drain Write Buffer
  361. mov pc, lr
  362. .ltorg
  363. .align
  364. __INIT
  365. .type __xsc3_setup, #function
  366. __xsc3_setup:
  367. mov r0, #PSR_F_BIT|PSR_I_BIT|SVC_MODE
  368. msr cpsr_c, r0
  369. mcr p15, 0, ip, c7, c7, 0 @ invalidate I, D caches & BTB
  370. mcr p15, 0, ip, c7, c10, 4 @ Drain Write Buffer
  371. mcr p15, 0, ip, c7, c5, 4 @ Prefetch Flush
  372. mcr p15, 0, ip, c8, c7, 0 @ invalidate I, D TLBs
  373. #if L2_CACHE_ENABLE
  374. orr r4, r4, #0x18 @ cache the page table in L2
  375. #endif
  376. mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
  377. mov r0, #1 @ Allow access to CP0 and CP13
  378. orr r0, r0, #1 << 13 @ Its undefined whether this
  379. mcr p15, 0, r0, c15, c1, 0 @ affects USR or SVC modes
  380. mrc p15, 0, r0, c1, c0, 1 @ get auxiliary control reg
  381. and r0, r0, #2 @ preserve bit P bit setting
  382. #if L2_CACHE_ENABLE
  383. orr r0, r0, #(1 << 10) @ enable L2 for LLR cache
  384. #endif
  385. mcr p15, 0, r0, c1, c0, 1 @ set auxiliary control reg
  386. mrc p15, 0, r0, c1, c0, 0 @ get control register
  387. bic r0, r0, #0x0200 @ .... ..R. .... ....
  388. bic r0, r0, #0x0002 @ .... .... .... ..A.
  389. orr r0, r0, #0x0005 @ .... .... .... .C.M
  390. #if BTB_ENABLE
  391. orr r0, r0, #0x3900 @ ..VI Z..S .... ....
  392. #else
  393. orr r0, r0, #0x3100 @ ..VI ...S .... ....
  394. #endif
  395. #if L2_CACHE_ENABLE
  396. orr r0, r0, #0x4000000 @ L2 enable
  397. #endif
  398. mov pc, lr
  399. .size __xsc3_setup, . - __xsc3_setup
  400. __INITDATA
  401. /*
  402. * Purpose : Function pointers used to access above functions - all calls
  403. * come through these
  404. */
  405. .type xsc3_processor_functions, #object
  406. ENTRY(xsc3_processor_functions)
  407. .word v5t_early_abort
  408. .word cpu_xsc3_proc_init
  409. .word cpu_xsc3_proc_fin
  410. .word cpu_xsc3_reset
  411. .word cpu_xsc3_do_idle
  412. .word cpu_xsc3_dcache_clean_area
  413. .word cpu_xsc3_switch_mm
  414. .word cpu_xsc3_set_pte
  415. .size xsc3_processor_functions, . - xsc3_processor_functions
  416. .section ".rodata"
  417. .type cpu_arch_name, #object
  418. cpu_arch_name:
  419. .asciz "armv5te"
  420. .size cpu_arch_name, . - cpu_arch_name
  421. .type cpu_elf_name, #object
  422. cpu_elf_name:
  423. .asciz "v5"
  424. .size cpu_elf_name, . - cpu_elf_name
  425. .type cpu_xsc3_name, #object
  426. cpu_xsc3_name:
  427. .asciz "XScale-Core3"
  428. .size cpu_xsc3_name, . - cpu_xsc3_name
  429. .align
  430. .section ".proc.info.init", #alloc, #execinstr
  431. .type __xsc3_proc_info,#object
  432. __xsc3_proc_info:
  433. .long 0x69056000
  434. .long 0xffffe000
  435. .long 0x00000c0e
  436. b __xsc3_setup
  437. .long cpu_arch_name
  438. .long cpu_elf_name
  439. .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
  440. .long cpu_xsc3_name
  441. .long xsc3_processor_functions
  442. .long v4wbi_tlb_fns
  443. .long xsc3_mc_user_fns
  444. .long xsc3_cache_fns
  445. .size __xsc3_proc_info, . - __xsc3_proc_info