proc-arm922.S 12 KB

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