proc-arm922.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. /*
  2. * linux/arch/arm/mm/proc-arm922.S: MMU functions for ARM922
  3. *
  4. * Copyright (C) 1999,2000 ARM Limited
  5. * Copyright (C) 2000 Deep Blue Solutions Ltd.
  6. * Copyright (C) 2001 Altera Corporation
  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 arm922.
  25. *
  26. * CONFIG_CPU_ARM922_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.h>
  33. #include <asm/procinfo.h>
  34. #include <asm/page.h>
  35. #include <asm/ptrace.h>
  36. #include "proc-macros.S"
  37. /*
  38. * The size of one data cache line.
  39. */
  40. #define CACHE_DLINESIZE 32
  41. /*
  42. * The number of data cache segments.
  43. */
  44. #define CACHE_DSEGMENTS 4
  45. /*
  46. * The number of lines in a cache segment.
  47. */
  48. #define CACHE_DENTRIES 64
  49. /*
  50. * This is the size at which it becomes more efficient to
  51. * clean the whole cache, rather than using the individual
  52. * cache line maintainence instructions. (I think this should
  53. * be 32768).
  54. */
  55. #define CACHE_DLIMIT 8192
  56. .text
  57. /*
  58. * cpu_arm922_proc_init()
  59. */
  60. ENTRY(cpu_arm922_proc_init)
  61. mov pc, lr
  62. /*
  63. * cpu_arm922_proc_fin()
  64. */
  65. ENTRY(cpu_arm922_proc_fin)
  66. stmfd sp!, {lr}
  67. mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
  68. msr cpsr_c, ip
  69. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  70. bl arm922_flush_kern_cache_all
  71. #else
  72. bl v4wt_flush_kern_cache_all
  73. #endif
  74. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  75. bic r0, r0, #0x1000 @ ...i............
  76. bic r0, r0, #0x000e @ ............wca.
  77. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  78. ldmfd sp!, {pc}
  79. /*
  80. * cpu_arm922_reset(loc)
  81. *
  82. * Perform a soft reset of the system. Put the CPU into the
  83. * same state as it would be if it had been reset, and branch
  84. * to what would be the reset vector.
  85. *
  86. * loc: location to jump to for soft reset
  87. */
  88. .align 5
  89. ENTRY(cpu_arm922_reset)
  90. mov ip, #0
  91. mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
  92. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  93. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  94. mrc p15, 0, ip, c1, c0, 0 @ ctrl register
  95. bic ip, ip, #0x000f @ ............wcam
  96. bic ip, ip, #0x1100 @ ...i...s........
  97. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  98. mov pc, r0
  99. /*
  100. * cpu_arm922_do_idle()
  101. */
  102. .align 5
  103. ENTRY(cpu_arm922_do_idle)
  104. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  105. mov pc, lr
  106. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  107. /*
  108. * flush_user_cache_all()
  109. *
  110. * Clean and invalidate all cache entries in a particular
  111. * address space.
  112. */
  113. ENTRY(arm922_flush_user_cache_all)
  114. /* FALLTHROUGH */
  115. /*
  116. * flush_kern_cache_all()
  117. *
  118. * Clean and invalidate the entire cache.
  119. */
  120. ENTRY(arm922_flush_kern_cache_all)
  121. mov r2, #VM_EXEC
  122. mov ip, #0
  123. __flush_whole_cache:
  124. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 8 segments
  125. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  126. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  127. subs r3, r3, #1 << 26
  128. bcs 2b @ entries 63 to 0
  129. subs r1, r1, #1 << 5
  130. bcs 1b @ segments 7 to 0
  131. tst r2, #VM_EXEC
  132. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  133. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  134. mov pc, lr
  135. /*
  136. * flush_user_cache_range(start, end, flags)
  137. *
  138. * Clean and invalidate a range of cache entries in the
  139. * specified address range.
  140. *
  141. * - start - start address (inclusive)
  142. * - end - end address (exclusive)
  143. * - flags - vm_flags describing address space
  144. */
  145. ENTRY(arm922_flush_user_cache_range)
  146. mov ip, #0
  147. sub r3, r1, r0 @ calculate total size
  148. cmp r3, #CACHE_DLIMIT
  149. bhs __flush_whole_cache
  150. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  151. tst r2, #VM_EXEC
  152. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  153. add r0, r0, #CACHE_DLINESIZE
  154. cmp r0, r1
  155. blo 1b
  156. tst r2, #VM_EXEC
  157. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  158. mov pc, lr
  159. /*
  160. * coherent_kern_range(start, end)
  161. *
  162. * Ensure coherency between the Icache and the Dcache in the
  163. * region described by start, end. If you have non-snooping
  164. * Harvard caches, you need to implement this function.
  165. *
  166. * - start - virtual start address
  167. * - end - virtual end address
  168. */
  169. ENTRY(arm922_coherent_kern_range)
  170. /* FALLTHROUGH */
  171. /*
  172. * coherent_user_range(start, end)
  173. *
  174. * Ensure coherency between the Icache and the Dcache in the
  175. * region described by start, end. If you have non-snooping
  176. * Harvard caches, you need to implement this function.
  177. *
  178. * - start - virtual start address
  179. * - end - virtual end address
  180. */
  181. ENTRY(arm922_coherent_user_range)
  182. bic r0, r0, #CACHE_DLINESIZE - 1
  183. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  184. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  185. add r0, r0, #CACHE_DLINESIZE
  186. cmp r0, r1
  187. blo 1b
  188. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  189. mov pc, lr
  190. /*
  191. * flush_kern_dcache_page(void *page)
  192. *
  193. * Ensure no D cache aliasing occurs, either with itself or
  194. * the I cache
  195. *
  196. * - addr - page aligned address
  197. */
  198. ENTRY(arm922_flush_kern_dcache_page)
  199. add r1, r0, #PAGE_SZ
  200. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  201. add r0, r0, #CACHE_DLINESIZE
  202. cmp r0, r1
  203. blo 1b
  204. mov r0, #0
  205. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  206. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  207. mov pc, lr
  208. /*
  209. * dma_inv_range(start, end)
  210. *
  211. * Invalidate (discard) the specified virtual address range.
  212. * May not write back any entries. If 'start' or 'end'
  213. * are not cache line aligned, those lines must be written
  214. * back.
  215. *
  216. * - start - virtual start address
  217. * - end - virtual end address
  218. *
  219. * (same as v4wb)
  220. */
  221. ENTRY(arm922_dma_inv_range)
  222. tst r0, #CACHE_DLINESIZE - 1
  223. bic r0, r0, #CACHE_DLINESIZE - 1
  224. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  225. tst r1, #CACHE_DLINESIZE - 1
  226. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  227. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  228. add r0, r0, #CACHE_DLINESIZE
  229. cmp r0, r1
  230. blo 1b
  231. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  232. mov pc, lr
  233. /*
  234. * dma_clean_range(start, end)
  235. *
  236. * Clean the specified virtual address range.
  237. *
  238. * - start - virtual start address
  239. * - end - virtual end address
  240. *
  241. * (same as v4wb)
  242. */
  243. ENTRY(arm922_dma_clean_range)
  244. bic r0, r0, #CACHE_DLINESIZE - 1
  245. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  246. add r0, r0, #CACHE_DLINESIZE
  247. cmp r0, r1
  248. blo 1b
  249. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  250. mov pc, lr
  251. /*
  252. * dma_flush_range(start, end)
  253. *
  254. * Clean and invalidate the specified virtual address range.
  255. *
  256. * - start - virtual start address
  257. * - end - virtual end address
  258. */
  259. ENTRY(arm922_dma_flush_range)
  260. bic r0, r0, #CACHE_DLINESIZE - 1
  261. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  262. add r0, r0, #CACHE_DLINESIZE
  263. cmp r0, r1
  264. blo 1b
  265. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  266. mov pc, lr
  267. ENTRY(arm922_cache_fns)
  268. .long arm922_flush_kern_cache_all
  269. .long arm922_flush_user_cache_all
  270. .long arm922_flush_user_cache_range
  271. .long arm922_coherent_kern_range
  272. .long arm922_coherent_user_range
  273. .long arm922_flush_kern_dcache_page
  274. .long arm922_dma_inv_range
  275. .long arm922_dma_clean_range
  276. .long arm922_dma_flush_range
  277. #endif
  278. ENTRY(cpu_arm922_dcache_clean_area)
  279. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  280. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  281. add r0, r0, #CACHE_DLINESIZE
  282. subs r1, r1, #CACHE_DLINESIZE
  283. bhi 1b
  284. #endif
  285. mov pc, lr
  286. /* =============================== PageTable ============================== */
  287. /*
  288. * cpu_arm922_switch_mm(pgd)
  289. *
  290. * Set the translation base pointer to be as described by pgd.
  291. *
  292. * pgd: new page tables
  293. */
  294. .align 5
  295. ENTRY(cpu_arm922_switch_mm)
  296. mov ip, #0
  297. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  298. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  299. #else
  300. @ && 'Clean & Invalidate whole DCache'
  301. @ && Re-written to use Index Ops.
  302. @ && Uses registers r1, r3 and ip
  303. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 4 segments
  304. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  305. 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
  306. subs r3, r3, #1 << 26
  307. bcs 2b @ entries 63 to 0
  308. subs r1, r1, #1 << 5
  309. bcs 1b @ segments 7 to 0
  310. #endif
  311. mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
  312. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  313. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  314. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  315. mov pc, lr
  316. /*
  317. * cpu_arm922_set_pte(ptep, pte)
  318. *
  319. * Set a PTE and flush it out
  320. */
  321. .align 5
  322. ENTRY(cpu_arm922_set_pte)
  323. str r1, [r0], #-2048 @ linux version
  324. eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
  325. bic r2, r1, #PTE_SMALL_AP_MASK
  326. bic r2, r2, #PTE_TYPE_MASK
  327. orr r2, r2, #PTE_TYPE_SMALL
  328. tst r1, #L_PTE_USER @ User?
  329. orrne r2, r2, #PTE_SMALL_AP_URO_SRW
  330. tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
  331. orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
  332. tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
  333. movne r2, #0
  334. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  335. eor r3, r2, #0x0a @ C & small page?
  336. tst r3, #0x0b
  337. biceq r2, r2, #4
  338. #endif
  339. str r2, [r0] @ hardware version
  340. mov r0, r0
  341. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  342. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  343. mov pc, lr
  344. __INIT
  345. .type __arm922_setup, #function
  346. __arm922_setup:
  347. mov r0, #0
  348. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  349. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  350. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  351. mrc p15, 0, r0, c1, c0 @ get control register v4
  352. ldr r5, arm922_cr1_clear
  353. bic r0, r0, r5
  354. ldr r5, arm922_cr1_set
  355. orr r0, r0, r5
  356. mov pc, lr
  357. .size __arm922_setup, . - __arm922_setup
  358. /*
  359. * R
  360. * .RVI ZFRS BLDP WCAM
  361. * ..11 0001 ..11 0101
  362. *
  363. */
  364. .type arm922_cr1_clear, #object
  365. .type arm922_cr1_set, #object
  366. arm922_cr1_clear:
  367. .word 0x3f3f
  368. arm922_cr1_set:
  369. .word 0x3135
  370. __INITDATA
  371. /*
  372. * Purpose : Function pointers used to access above functions - all calls
  373. * come through these
  374. */
  375. .type arm922_processor_functions, #object
  376. arm922_processor_functions:
  377. .word v4t_early_abort
  378. .word cpu_arm922_proc_init
  379. .word cpu_arm922_proc_fin
  380. .word cpu_arm922_reset
  381. .word cpu_arm922_do_idle
  382. .word cpu_arm922_dcache_clean_area
  383. .word cpu_arm922_switch_mm
  384. .word cpu_arm922_set_pte
  385. .size arm922_processor_functions, . - arm922_processor_functions
  386. .section ".rodata"
  387. .type cpu_arch_name, #object
  388. cpu_arch_name:
  389. .asciz "armv4t"
  390. .size cpu_arch_name, . - cpu_arch_name
  391. .type cpu_elf_name, #object
  392. cpu_elf_name:
  393. .asciz "v4"
  394. .size cpu_elf_name, . - cpu_elf_name
  395. .type cpu_arm922_name, #object
  396. cpu_arm922_name:
  397. .ascii "ARM922T"
  398. #ifndef CONFIG_CPU_ICACHE_DISABLE
  399. .ascii "i"
  400. #endif
  401. #ifndef CONFIG_CPU_DCACHE_DISABLE
  402. .ascii "d"
  403. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  404. .ascii "(wt)"
  405. #else
  406. .ascii "(wb)"
  407. #endif
  408. #endif
  409. .ascii "\0"
  410. .size cpu_arm922_name, . - cpu_arm922_name
  411. .align
  412. .section ".proc.info.init", #alloc, #execinstr
  413. .type __arm922_proc_info,#object
  414. __arm922_proc_info:
  415. .long 0x41009220
  416. .long 0xff00fff0
  417. .long PMD_TYPE_SECT | \
  418. PMD_SECT_BUFFERABLE | \
  419. PMD_SECT_CACHEABLE | \
  420. PMD_BIT4 | \
  421. PMD_SECT_AP_WRITE | \
  422. PMD_SECT_AP_READ
  423. b __arm922_setup
  424. .long cpu_arch_name
  425. .long cpu_elf_name
  426. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
  427. .long cpu_arm922_name
  428. .long arm922_processor_functions
  429. .long v4wbi_tlb_fns
  430. .long v4wb_user_fns
  431. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  432. .long arm922_cache_fns
  433. #else
  434. .long v4wt_cache_fns
  435. #endif
  436. .size __arm922_proc_info, . - __arm922_proc_info