proc-arm926.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. /*
  2. * linux/arch/arm/mm/proc-arm926.S: MMU functions for ARM926EJ-S
  3. *
  4. * Copyright (C) 1999-2001 ARM Limited
  5. * Copyright (C) 2000 Deep Blue Solutions Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. *
  22. * These are the low level assembler for performing cache and TLB
  23. * functions on the arm926.
  24. *
  25. * CONFIG_CPU_ARM926_CPU_IDLE -> nohlt
  26. */
  27. #include <linux/linkage.h>
  28. #include <linux/config.h>
  29. #include <linux/init.h>
  30. #include <asm/assembler.h>
  31. #include <asm/pgtable.h>
  32. #include <asm/procinfo.h>
  33. #include <asm/hardware.h>
  34. #include <asm/page.h>
  35. #include <asm/ptrace.h>
  36. #include "proc-macros.S"
  37. /*
  38. * This is the maximum size of an area which will be invalidated
  39. * using the single invalidate entry instructions. Anything larger
  40. * than this, and we go for the whole cache.
  41. *
  42. * This value should be chosen such that we choose the cheapest
  43. * alternative.
  44. */
  45. #define CACHE_DLIMIT 16384
  46. /*
  47. * the cache line size of the I and D cache
  48. */
  49. #define CACHE_DLINESIZE 32
  50. .text
  51. /*
  52. * cpu_arm926_proc_init()
  53. */
  54. ENTRY(cpu_arm926_proc_init)
  55. mov pc, lr
  56. /*
  57. * cpu_arm926_proc_fin()
  58. */
  59. ENTRY(cpu_arm926_proc_fin)
  60. stmfd sp!, {lr}
  61. mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
  62. msr cpsr_c, ip
  63. bl arm926_flush_kern_cache_all
  64. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  65. bic r0, r0, #0x1000 @ ...i............
  66. bic r0, r0, #0x000e @ ............wca.
  67. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  68. ldmfd sp!, {pc}
  69. /*
  70. * cpu_arm926_reset(loc)
  71. *
  72. * Perform a soft reset of the system. Put the CPU into the
  73. * same state as it would be if it had been reset, and branch
  74. * to what would be the reset vector.
  75. *
  76. * loc: location to jump to for soft reset
  77. */
  78. .align 5
  79. ENTRY(cpu_arm926_reset)
  80. mov ip, #0
  81. mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
  82. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  83. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  84. mrc p15, 0, ip, c1, c0, 0 @ ctrl register
  85. bic ip, ip, #0x000f @ ............wcam
  86. bic ip, ip, #0x1100 @ ...i...s........
  87. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  88. mov pc, r0
  89. /*
  90. * cpu_arm926_do_idle()
  91. *
  92. * Called with IRQs disabled
  93. */
  94. .align 10
  95. ENTRY(cpu_arm926_do_idle)
  96. mov r0, #0
  97. mrc p15, 0, r1, c1, c0, 0 @ Read control register
  98. mcr p15, 0, r0, c7, c10, 4 @ Drain write buffer
  99. bic r2, r1, #1 << 12
  100. mcr p15, 0, r2, c1, c0, 0 @ Disable I cache
  101. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  102. mcr p15, 0, r1, c1, c0, 0 @ Restore ICache enable
  103. mov pc, lr
  104. /*
  105. * flush_user_cache_all()
  106. *
  107. * Clean and invalidate all cache entries in a particular
  108. * address space.
  109. */
  110. ENTRY(arm926_flush_user_cache_all)
  111. /* FALLTHROUGH */
  112. /*
  113. * flush_kern_cache_all()
  114. *
  115. * Clean and invalidate the entire cache.
  116. */
  117. ENTRY(arm926_flush_kern_cache_all)
  118. mov r2, #VM_EXEC
  119. mov ip, #0
  120. __flush_whole_cache:
  121. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  122. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  123. #else
  124. 1: mrc p15, 0, r15, c7, c14, 3 @ test,clean,invalidate
  125. bne 1b
  126. #endif
  127. tst r2, #VM_EXEC
  128. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  129. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  130. mov pc, lr
  131. /*
  132. * flush_user_cache_range(start, end, flags)
  133. *
  134. * Clean and invalidate a range of cache entries in the
  135. * specified address range.
  136. *
  137. * - start - start address (inclusive)
  138. * - end - end address (exclusive)
  139. * - flags - vm_flags describing address space
  140. */
  141. ENTRY(arm926_flush_user_cache_range)
  142. mov ip, #0
  143. sub r3, r1, r0 @ calculate total size
  144. cmp r3, #CACHE_DLIMIT
  145. bgt __flush_whole_cache
  146. 1: tst r2, #VM_EXEC
  147. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  148. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  149. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  150. add r0, r0, #CACHE_DLINESIZE
  151. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  152. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  153. add r0, r0, #CACHE_DLINESIZE
  154. #else
  155. mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  156. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  157. add r0, r0, #CACHE_DLINESIZE
  158. mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  159. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  160. add r0, r0, #CACHE_DLINESIZE
  161. #endif
  162. cmp r0, r1
  163. blo 1b
  164. tst r2, #VM_EXEC
  165. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  166. mov pc, lr
  167. /*
  168. * coherent_kern_range(start, end)
  169. *
  170. * Ensure coherency between the Icache and the Dcache in the
  171. * region described by start, end. If you have non-snooping
  172. * Harvard caches, you need to implement this function.
  173. *
  174. * - start - virtual start address
  175. * - end - virtual end address
  176. */
  177. ENTRY(arm926_coherent_kern_range)
  178. /* FALLTHROUGH */
  179. /*
  180. * coherent_user_range(start, end)
  181. *
  182. * Ensure coherency between the Icache and the Dcache in the
  183. * region described by start, end. If you have non-snooping
  184. * Harvard caches, you need to implement this function.
  185. *
  186. * - start - virtual start address
  187. * - end - virtual end address
  188. */
  189. ENTRY(arm926_coherent_user_range)
  190. bic r0, r0, #CACHE_DLINESIZE - 1
  191. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  192. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  193. add r0, r0, #CACHE_DLINESIZE
  194. cmp r0, r1
  195. blo 1b
  196. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  197. mov pc, lr
  198. /*
  199. * flush_kern_dcache_page(void *page)
  200. *
  201. * Ensure no D cache aliasing occurs, either with itself or
  202. * the I cache
  203. *
  204. * - addr - page aligned address
  205. */
  206. ENTRY(arm926_flush_kern_dcache_page)
  207. add r1, r0, #PAGE_SZ
  208. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  209. add r0, r0, #CACHE_DLINESIZE
  210. cmp r0, r1
  211. blo 1b
  212. mov r0, #0
  213. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  214. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  215. mov pc, lr
  216. /*
  217. * dma_inv_range(start, end)
  218. *
  219. * Invalidate (discard) the specified virtual address range.
  220. * May not write back any entries. If 'start' or 'end'
  221. * are not cache line aligned, those lines must be written
  222. * back.
  223. *
  224. * - start - virtual start address
  225. * - end - virtual end address
  226. *
  227. * (same as v4wb)
  228. */
  229. ENTRY(arm926_dma_inv_range)
  230. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  231. tst r0, #CACHE_DLINESIZE - 1
  232. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  233. tst r1, #CACHE_DLINESIZE - 1
  234. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  235. #endif
  236. bic r0, r0, #CACHE_DLINESIZE - 1
  237. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  238. add r0, r0, #CACHE_DLINESIZE
  239. cmp r0, r1
  240. blo 1b
  241. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  242. mov pc, lr
  243. /*
  244. * dma_clean_range(start, end)
  245. *
  246. * Clean the specified virtual address range.
  247. *
  248. * - start - virtual start address
  249. * - end - virtual end address
  250. *
  251. * (same as v4wb)
  252. */
  253. ENTRY(arm926_dma_clean_range)
  254. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  255. bic r0, r0, #CACHE_DLINESIZE - 1
  256. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  257. add r0, r0, #CACHE_DLINESIZE
  258. cmp r0, r1
  259. blo 1b
  260. #endif
  261. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  262. mov pc, lr
  263. /*
  264. * dma_flush_range(start, end)
  265. *
  266. * Clean and invalidate the specified virtual address range.
  267. *
  268. * - start - virtual start address
  269. * - end - virtual end address
  270. */
  271. ENTRY(arm926_dma_flush_range)
  272. bic r0, r0, #CACHE_DLINESIZE - 1
  273. 1:
  274. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  275. mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  276. #else
  277. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  278. #endif
  279. add r0, r0, #CACHE_DLINESIZE
  280. cmp r0, r1
  281. blo 1b
  282. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  283. mov pc, lr
  284. ENTRY(arm926_cache_fns)
  285. .long arm926_flush_kern_cache_all
  286. .long arm926_flush_user_cache_all
  287. .long arm926_flush_user_cache_range
  288. .long arm926_coherent_kern_range
  289. .long arm926_coherent_user_range
  290. .long arm926_flush_kern_dcache_page
  291. .long arm926_dma_inv_range
  292. .long arm926_dma_clean_range
  293. .long arm926_dma_flush_range
  294. ENTRY(cpu_arm926_dcache_clean_area)
  295. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  296. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  297. add r0, r0, #CACHE_DLINESIZE
  298. subs r1, r1, #CACHE_DLINESIZE
  299. bhi 1b
  300. #endif
  301. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  302. mov pc, lr
  303. /* =============================== PageTable ============================== */
  304. /*
  305. * cpu_arm926_switch_mm(pgd)
  306. *
  307. * Set the translation base pointer to be as described by pgd.
  308. *
  309. * pgd: new page tables
  310. */
  311. .align 5
  312. ENTRY(cpu_arm926_switch_mm)
  313. mov ip, #0
  314. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  315. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  316. #else
  317. @ && 'Clean & Invalidate whole DCache'
  318. 1: mrc p15, 0, r15, c7, c14, 3 @ test,clean,invalidate
  319. bne 1b
  320. #endif
  321. mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
  322. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  323. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  324. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  325. mov pc, lr
  326. /*
  327. * cpu_arm926_set_pte(ptep, pte)
  328. *
  329. * Set a PTE and flush it out
  330. */
  331. .align 5
  332. ENTRY(cpu_arm926_set_pte)
  333. str r1, [r0], #-2048 @ linux version
  334. eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
  335. bic r2, r1, #PTE_SMALL_AP_MASK
  336. bic r2, r2, #PTE_TYPE_MASK
  337. orr r2, r2, #PTE_TYPE_SMALL
  338. tst r1, #L_PTE_USER @ User?
  339. orrne r2, r2, #PTE_SMALL_AP_URO_SRW
  340. tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
  341. orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
  342. tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
  343. movne r2, #0
  344. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  345. eor r3, r2, #0x0a @ C & small page?
  346. tst r3, #0x0b
  347. biceq r2, r2, #4
  348. #endif
  349. str r2, [r0] @ hardware version
  350. mov r0, r0
  351. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  352. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  353. #endif
  354. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  355. mov pc, lr
  356. __INIT
  357. .type __arm926_setup, #function
  358. __arm926_setup:
  359. mov r0, #0
  360. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  361. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  362. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  363. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  364. mov r0, #4 @ disable write-back on caches explicitly
  365. mcr p15, 7, r0, c15, c0, 0
  366. #endif
  367. mrc p15, 0, r0, c1, c0 @ get control register v4
  368. ldr r5, arm926_cr1_clear
  369. bic r0, r0, r5
  370. ldr r5, arm926_cr1_set
  371. orr r0, r0, r5
  372. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  373. orr r0, r0, #0x4000 @ .1.. .... .... ....
  374. #endif
  375. mov pc, lr
  376. .size __arm926_setup, . - __arm926_setup
  377. /*
  378. * R
  379. * .RVI ZFRS BLDP WCAM
  380. * .011 0001 ..11 0101
  381. *
  382. */
  383. .type arm926_cr1_clear, #object
  384. .type arm926_cr1_set, #object
  385. arm926_cr1_clear:
  386. .word 0x7f3f
  387. arm926_cr1_set:
  388. .word 0x3135
  389. __INITDATA
  390. /*
  391. * Purpose : Function pointers used to access above functions - all calls
  392. * come through these
  393. */
  394. .type arm926_processor_functions, #object
  395. arm926_processor_functions:
  396. .word v5tj_early_abort
  397. .word cpu_arm926_proc_init
  398. .word cpu_arm926_proc_fin
  399. .word cpu_arm926_reset
  400. .word cpu_arm926_do_idle
  401. .word cpu_arm926_dcache_clean_area
  402. .word cpu_arm926_switch_mm
  403. .word cpu_arm926_set_pte
  404. .size arm926_processor_functions, . - arm926_processor_functions
  405. .section ".rodata"
  406. .type cpu_arch_name, #object
  407. cpu_arch_name:
  408. .asciz "armv5tej"
  409. .size cpu_arch_name, . - cpu_arch_name
  410. .type cpu_elf_name, #object
  411. cpu_elf_name:
  412. .asciz "v5"
  413. .size cpu_elf_name, . - cpu_elf_name
  414. .type cpu_arm926_name, #object
  415. cpu_arm926_name:
  416. .ascii "ARM926EJ-S"
  417. #ifndef CONFIG_CPU_ICACHE_DISABLE
  418. .ascii "i"
  419. #endif
  420. #ifndef CONFIG_CPU_DCACHE_DISABLE
  421. .ascii "d"
  422. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  423. .ascii "(wt)"
  424. #else
  425. .ascii "(wb)"
  426. #endif
  427. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  428. .ascii "RR"
  429. #endif
  430. #endif
  431. .ascii "\0"
  432. .size cpu_arm926_name, . - cpu_arm926_name
  433. .align
  434. .section ".proc.info", #alloc, #execinstr
  435. .type __arm926_proc_info,#object
  436. __arm926_proc_info:
  437. .long 0x41069260 @ ARM926EJ-S (v5TEJ)
  438. .long 0xff0ffff0
  439. .long PMD_TYPE_SECT | \
  440. PMD_SECT_BUFFERABLE | \
  441. PMD_SECT_CACHEABLE | \
  442. PMD_BIT4 | \
  443. PMD_SECT_AP_WRITE | \
  444. PMD_SECT_AP_READ
  445. b __arm926_setup
  446. .long cpu_arch_name
  447. .long cpu_elf_name
  448. .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP|HWCAP_JAVA
  449. .long cpu_arm926_name
  450. .long arm926_processor_functions
  451. .long v4wbi_tlb_fns
  452. .long v4wb_user_fns
  453. .long arm926_cache_fns
  454. .size __arm926_proc_info, . - __arm926_proc_info