proc-arm920.S 11 KB

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