proc-arm926.S 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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/init.h>
  30. #include <asm/assembler.h>
  31. #include <asm/hwcap.h>
  32. #include <asm/pgtable-hwdef.h>
  33. #include <asm/pgtable.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. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  61. bic r0, r0, #0x1000 @ ...i............
  62. bic r0, r0, #0x000e @ ............wca.
  63. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  64. mov pc, lr
  65. /*
  66. * cpu_arm926_reset(loc)
  67. *
  68. * Perform a soft reset of the system. Put the CPU into the
  69. * same state as it would be if it had been reset, and branch
  70. * to what would be the reset vector.
  71. *
  72. * loc: location to jump to for soft reset
  73. */
  74. .align 5
  75. .pushsection .idmap.text, "ax"
  76. ENTRY(cpu_arm926_reset)
  77. mov ip, #0
  78. mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
  79. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  80. #ifdef CONFIG_MMU
  81. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  82. #endif
  83. mrc p15, 0, ip, c1, c0, 0 @ ctrl register
  84. bic ip, ip, #0x000f @ ............wcam
  85. bic ip, ip, #0x1100 @ ...i...s........
  86. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  87. mov pc, r0
  88. ENDPROC(cpu_arm926_reset)
  89. .popsection
  90. /*
  91. * cpu_arm926_do_idle()
  92. *
  93. * Called with IRQs disabled
  94. */
  95. .align 10
  96. ENTRY(cpu_arm926_do_idle)
  97. mov r0, #0
  98. mrc p15, 0, r1, c1, c0, 0 @ Read control register
  99. mcr p15, 0, r0, c7, c10, 4 @ Drain write buffer
  100. bic r2, r1, #1 << 12
  101. mrs r3, cpsr @ Disable FIQs while Icache
  102. orr ip, r3, #PSR_F_BIT @ is disabled
  103. msr cpsr_c, ip
  104. mcr p15, 0, r2, c1, c0, 0 @ Disable I cache
  105. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  106. mcr p15, 0, r1, c1, c0, 0 @ Restore ICache enable
  107. msr cpsr_c, r3 @ Restore FIQ state
  108. mov pc, lr
  109. /*
  110. * flush_icache_all()
  111. *
  112. * Unconditionally clean and invalidate the entire icache.
  113. */
  114. ENTRY(arm926_flush_icache_all)
  115. mov r0, #0
  116. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  117. mov pc, lr
  118. ENDPROC(arm926_flush_icache_all)
  119. /*
  120. * flush_user_cache_all()
  121. *
  122. * Clean and invalidate all cache entries in a particular
  123. * address space.
  124. */
  125. ENTRY(arm926_flush_user_cache_all)
  126. /* FALLTHROUGH */
  127. /*
  128. * flush_kern_cache_all()
  129. *
  130. * Clean and invalidate the entire cache.
  131. */
  132. ENTRY(arm926_flush_kern_cache_all)
  133. mov r2, #VM_EXEC
  134. mov ip, #0
  135. __flush_whole_cache:
  136. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  137. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  138. #else
  139. 1: mrc p15, 0, r15, c7, c14, 3 @ test,clean,invalidate
  140. bne 1b
  141. #endif
  142. tst r2, #VM_EXEC
  143. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  144. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  145. mov pc, lr
  146. /*
  147. * flush_user_cache_range(start, end, flags)
  148. *
  149. * Clean and invalidate a range of cache entries in the
  150. * specified address range.
  151. *
  152. * - start - start address (inclusive)
  153. * - end - end address (exclusive)
  154. * - flags - vm_flags describing address space
  155. */
  156. ENTRY(arm926_flush_user_cache_range)
  157. mov ip, #0
  158. sub r3, r1, r0 @ calculate total size
  159. cmp r3, #CACHE_DLIMIT
  160. bgt __flush_whole_cache
  161. 1: tst r2, #VM_EXEC
  162. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  163. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  164. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  165. add r0, r0, #CACHE_DLINESIZE
  166. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  167. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  168. add r0, r0, #CACHE_DLINESIZE
  169. #else
  170. mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  171. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  172. add r0, r0, #CACHE_DLINESIZE
  173. mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  174. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  175. add r0, r0, #CACHE_DLINESIZE
  176. #endif
  177. cmp r0, r1
  178. blo 1b
  179. tst r2, #VM_EXEC
  180. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  181. mov pc, lr
  182. /*
  183. * coherent_kern_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_kern_range)
  193. /* FALLTHROUGH */
  194. /*
  195. * coherent_user_range(start, end)
  196. *
  197. * Ensure coherency between the Icache and the Dcache in the
  198. * region described by start, end. If you have non-snooping
  199. * Harvard caches, you need to implement this function.
  200. *
  201. * - start - virtual start address
  202. * - end - virtual end address
  203. */
  204. ENTRY(arm926_coherent_user_range)
  205. bic r0, r0, #CACHE_DLINESIZE - 1
  206. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  207. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  208. add r0, r0, #CACHE_DLINESIZE
  209. cmp r0, r1
  210. blo 1b
  211. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  212. mov pc, lr
  213. /*
  214. * flush_kern_dcache_area(void *addr, size_t size)
  215. *
  216. * Ensure no D cache aliasing occurs, either with itself or
  217. * the I cache
  218. *
  219. * - addr - kernel address
  220. * - size - region size
  221. */
  222. ENTRY(arm926_flush_kern_dcache_area)
  223. add r1, r0, r1
  224. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  225. add r0, r0, #CACHE_DLINESIZE
  226. cmp r0, r1
  227. blo 1b
  228. mov r0, #0
  229. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  230. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  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. * (same as v4wb)
  244. */
  245. arm926_dma_inv_range:
  246. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  247. tst r0, #CACHE_DLINESIZE - 1
  248. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  249. tst r1, #CACHE_DLINESIZE - 1
  250. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  251. #endif
  252. bic r0, r0, #CACHE_DLINESIZE - 1
  253. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  254. add r0, r0, #CACHE_DLINESIZE
  255. cmp r0, r1
  256. blo 1b
  257. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  258. mov pc, lr
  259. /*
  260. * dma_clean_range(start, end)
  261. *
  262. * Clean the specified virtual address range.
  263. *
  264. * - start - virtual start address
  265. * - end - virtual end address
  266. *
  267. * (same as v4wb)
  268. */
  269. arm926_dma_clean_range:
  270. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  271. bic r0, r0, #CACHE_DLINESIZE - 1
  272. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  273. add r0, r0, #CACHE_DLINESIZE
  274. cmp r0, r1
  275. blo 1b
  276. #endif
  277. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  278. mov pc, lr
  279. /*
  280. * dma_flush_range(start, end)
  281. *
  282. * Clean and invalidate the specified virtual address range.
  283. *
  284. * - start - virtual start address
  285. * - end - virtual end address
  286. */
  287. ENTRY(arm926_dma_flush_range)
  288. bic r0, r0, #CACHE_DLINESIZE - 1
  289. 1:
  290. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  291. mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  292. #else
  293. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  294. #endif
  295. add r0, r0, #CACHE_DLINESIZE
  296. cmp r0, r1
  297. blo 1b
  298. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  299. mov pc, lr
  300. /*
  301. * dma_map_area(start, size, dir)
  302. * - start - kernel virtual start address
  303. * - size - size of region
  304. * - dir - DMA direction
  305. */
  306. ENTRY(arm926_dma_map_area)
  307. add r1, r1, r0
  308. cmp r2, #DMA_TO_DEVICE
  309. beq arm926_dma_clean_range
  310. bcs arm926_dma_inv_range
  311. b arm926_dma_flush_range
  312. ENDPROC(arm926_dma_map_area)
  313. /*
  314. * dma_unmap_area(start, size, dir)
  315. * - start - kernel virtual start address
  316. * - size - size of region
  317. * - dir - DMA direction
  318. */
  319. ENTRY(arm926_dma_unmap_area)
  320. mov pc, lr
  321. ENDPROC(arm926_dma_unmap_area)
  322. .globl arm926_flush_kern_cache_louis
  323. .equ arm926_flush_kern_cache_louis, arm926_flush_kern_cache_all
  324. @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
  325. define_cache_functions arm926
  326. ENTRY(cpu_arm926_dcache_clean_area)
  327. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  328. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  329. add r0, r0, #CACHE_DLINESIZE
  330. subs r1, r1, #CACHE_DLINESIZE
  331. bhi 1b
  332. #endif
  333. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  334. mov pc, lr
  335. /* =============================== PageTable ============================== */
  336. /*
  337. * cpu_arm926_switch_mm(pgd)
  338. *
  339. * Set the translation base pointer to be as described by pgd.
  340. *
  341. * pgd: new page tables
  342. */
  343. .align 5
  344. ENTRY(cpu_arm926_switch_mm)
  345. #ifdef CONFIG_MMU
  346. mov ip, #0
  347. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  348. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  349. #else
  350. @ && 'Clean & Invalidate whole DCache'
  351. 1: mrc p15, 0, r15, c7, c14, 3 @ test,clean,invalidate
  352. bne 1b
  353. #endif
  354. mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
  355. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  356. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  357. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  358. #endif
  359. mov pc, lr
  360. /*
  361. * cpu_arm926_set_pte_ext(ptep, pte, ext)
  362. *
  363. * Set a PTE and flush it out
  364. */
  365. .align 5
  366. ENTRY(cpu_arm926_set_pte_ext)
  367. #ifdef CONFIG_MMU
  368. armv3_set_pte_ext
  369. mov r0, r0
  370. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  371. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  372. #endif
  373. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  374. #endif
  375. mov pc, lr
  376. /* Suspend/resume support: taken from arch/arm/plat-s3c24xx/sleep.S */
  377. .globl cpu_arm926_suspend_size
  378. .equ cpu_arm926_suspend_size, 4 * 3
  379. #ifdef CONFIG_ARM_CPU_SUSPEND
  380. ENTRY(cpu_arm926_do_suspend)
  381. stmfd sp!, {r4 - r6, lr}
  382. mrc p15, 0, r4, c13, c0, 0 @ PID
  383. mrc p15, 0, r5, c3, c0, 0 @ Domain ID
  384. mrc p15, 0, r6, c1, c0, 0 @ Control register
  385. stmia r0, {r4 - r6}
  386. ldmfd sp!, {r4 - r6, pc}
  387. ENDPROC(cpu_arm926_do_suspend)
  388. ENTRY(cpu_arm926_do_resume)
  389. mov ip, #0
  390. mcr p15, 0, ip, c8, c7, 0 @ invalidate I+D TLBs
  391. mcr p15, 0, ip, c7, c7, 0 @ invalidate I+D caches
  392. ldmia r0, {r4 - r6}
  393. mcr p15, 0, r4, c13, c0, 0 @ PID
  394. mcr p15, 0, r5, c3, c0, 0 @ Domain ID
  395. mcr p15, 0, r1, c2, c0, 0 @ TTB address
  396. mov r0, r6 @ control register
  397. b cpu_resume_mmu
  398. ENDPROC(cpu_arm926_do_resume)
  399. #endif
  400. __CPUINIT
  401. .type __arm926_setup, #function
  402. __arm926_setup:
  403. mov r0, #0
  404. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  405. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  406. #ifdef CONFIG_MMU
  407. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  408. #endif
  409. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  410. mov r0, #4 @ disable write-back on caches explicitly
  411. mcr p15, 7, r0, c15, c0, 0
  412. #endif
  413. adr r5, arm926_crval
  414. ldmia r5, {r5, r6}
  415. mrc p15, 0, r0, c1, c0 @ get control register v4
  416. bic r0, r0, r5
  417. orr r0, r0, r6
  418. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  419. orr r0, r0, #0x4000 @ .1.. .... .... ....
  420. #endif
  421. mov pc, lr
  422. .size __arm926_setup, . - __arm926_setup
  423. /*
  424. * R
  425. * .RVI ZFRS BLDP WCAM
  426. * .011 0001 ..11 0101
  427. *
  428. */
  429. .type arm926_crval, #object
  430. arm926_crval:
  431. crval clear=0x00007f3f, mmuset=0x00003135, ucset=0x00001134
  432. __INITDATA
  433. @ define struct processor (see <asm/proc-fns.h> and proc-macros.S)
  434. define_processor_functions arm926, dabort=v5tj_early_abort, pabort=legacy_pabort, suspend=1
  435. .section ".rodata"
  436. string cpu_arch_name, "armv5tej"
  437. string cpu_elf_name, "v5"
  438. string cpu_arm926_name, "ARM926EJ-S"
  439. .align
  440. .section ".proc.info.init", #alloc, #execinstr
  441. .type __arm926_proc_info,#object
  442. __arm926_proc_info:
  443. .long 0x41069260 @ ARM926EJ-S (v5TEJ)
  444. .long 0xff0ffff0
  445. .long PMD_TYPE_SECT | \
  446. PMD_SECT_BUFFERABLE | \
  447. PMD_SECT_CACHEABLE | \
  448. PMD_BIT4 | \
  449. PMD_SECT_AP_WRITE | \
  450. PMD_SECT_AP_READ
  451. .long PMD_TYPE_SECT | \
  452. PMD_BIT4 | \
  453. PMD_SECT_AP_WRITE | \
  454. PMD_SECT_AP_READ
  455. b __arm926_setup
  456. .long cpu_arch_name
  457. .long cpu_elf_name
  458. .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP|HWCAP_JAVA
  459. .long cpu_arm926_name
  460. .long arm926_processor_functions
  461. .long v4wbi_tlb_fns
  462. .long v4wb_user_fns
  463. .long arm926_cache_fns
  464. .size __arm926_proc_info, . - __arm926_proc_info