proc-arm926.S 12 KB

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