proc-arm920.S 11 KB

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