proc-arm922.S 12 KB

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