proc-arm1026.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. /*
  2. * linux/arch/arm/mm/proc-arm1026.S: MMU functions for ARM1026EJ-S
  3. *
  4. * Copyright (C) 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. *
  13. * These are the low level assembler for performing cache and TLB
  14. * functions on the ARM1026EJ-S.
  15. */
  16. #include <linux/linkage.h>
  17. #include <linux/config.h>
  18. #include <linux/init.h>
  19. #include <asm/assembler.h>
  20. #include <asm/constants.h>
  21. #include <asm/pgtable.h>
  22. #include <asm/procinfo.h>
  23. #include <asm/ptrace.h>
  24. /*
  25. * This is the maximum size of an area which will be invalidated
  26. * using the single invalidate entry instructions. Anything larger
  27. * than this, and we go for the whole cache.
  28. *
  29. * This value should be chosen such that we choose the cheapest
  30. * alternative.
  31. */
  32. #define MAX_AREA_SIZE 32768
  33. /*
  34. * The size of one data cache line.
  35. */
  36. #define CACHE_DLINESIZE 32
  37. /*
  38. * The number of data cache segments.
  39. */
  40. #define CACHE_DSEGMENTS 16
  41. /*
  42. * The number of lines in a cache segment.
  43. */
  44. #define CACHE_DENTRIES 64
  45. /*
  46. * This is the size at which it becomes more efficient to
  47. * clean the whole cache, rather than using the individual
  48. * cache line maintainence instructions.
  49. */
  50. #define CACHE_DLIMIT 32768
  51. .text
  52. /*
  53. * cpu_arm1026_proc_init()
  54. */
  55. ENTRY(cpu_arm1026_proc_init)
  56. mov pc, lr
  57. /*
  58. * cpu_arm1026_proc_fin()
  59. */
  60. ENTRY(cpu_arm1026_proc_fin)
  61. stmfd sp!, {lr}
  62. mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
  63. msr cpsr_c, ip
  64. bl arm1026_flush_kern_cache_all
  65. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  66. bic r0, r0, #0x1000 @ ...i............
  67. bic r0, r0, #0x000e @ ............wca.
  68. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  69. ldmfd sp!, {pc}
  70. /*
  71. * cpu_arm1026_reset(loc)
  72. *
  73. * Perform a soft reset of the system. Put the CPU into the
  74. * same state as it would be if it had been reset, and branch
  75. * to what would be the reset vector.
  76. *
  77. * loc: location to jump to for soft reset
  78. */
  79. .align 5
  80. ENTRY(cpu_arm1026_reset)
  81. mov ip, #0
  82. mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
  83. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  84. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  85. mrc p15, 0, ip, c1, c0, 0 @ ctrl register
  86. bic ip, ip, #0x000f @ ............wcam
  87. bic ip, ip, #0x1100 @ ...i...s........
  88. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  89. mov pc, r0
  90. /*
  91. * cpu_arm1026_do_idle()
  92. */
  93. .align 5
  94. ENTRY(cpu_arm1026_do_idle)
  95. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  96. mov pc, lr
  97. /* ================================= CACHE ================================ */
  98. .align 5
  99. /*
  100. * flush_user_cache_all()
  101. *
  102. * Invalidate all cache entries in a particular address
  103. * space.
  104. */
  105. ENTRY(arm1026_flush_user_cache_all)
  106. /* FALLTHROUGH */
  107. /*
  108. * flush_kern_cache_all()
  109. *
  110. * Clean and invalidate the entire cache.
  111. */
  112. ENTRY(arm1026_flush_kern_cache_all)
  113. mov r2, #VM_EXEC
  114. mov ip, #0
  115. __flush_whole_cache:
  116. #ifndef CONFIG_CPU_DCACHE_DISABLE
  117. 1: mrc p15, 0, r15, c7, c14, 3 @ test, clean, invalidate
  118. bne 1b
  119. #endif
  120. tst r2, #VM_EXEC
  121. #ifndef CONFIG_CPU_ICACHE_DISABLE
  122. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  123. #endif
  124. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  125. mov pc, lr
  126. /*
  127. * flush_user_cache_range(start, end, flags)
  128. *
  129. * Invalidate a range of cache entries in the specified
  130. * address space.
  131. *
  132. * - start - start address (inclusive)
  133. * - end - end address (exclusive)
  134. * - flags - vm_flags for this space
  135. */
  136. ENTRY(arm1026_flush_user_cache_range)
  137. mov ip, #0
  138. sub r3, r1, r0 @ calculate total size
  139. cmp r3, #CACHE_DLIMIT
  140. bhs __flush_whole_cache
  141. #ifndef CONFIG_CPU_DCACHE_DISABLE
  142. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  143. add r0, r0, #CACHE_DLINESIZE
  144. cmp r0, r1
  145. blo 1b
  146. #endif
  147. tst r2, #VM_EXEC
  148. #ifndef CONFIG_CPU_ICACHE_DISABLE
  149. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  150. #endif
  151. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  152. mov pc, lr
  153. /*
  154. * coherent_kern_range(start, end)
  155. *
  156. * Ensure coherency between the Icache and the Dcache in the
  157. * region described by start. If you have non-snooping
  158. * Harvard caches, you need to implement this function.
  159. *
  160. * - start - virtual start address
  161. * - end - virtual end address
  162. */
  163. ENTRY(arm1026_coherent_kern_range)
  164. /* FALLTHROUGH */
  165. /*
  166. * coherent_user_range(start, end)
  167. *
  168. * Ensure coherency between the Icache and the Dcache in the
  169. * region described by start. If you have non-snooping
  170. * Harvard caches, you need to implement this function.
  171. *
  172. * - start - virtual start address
  173. * - end - virtual end address
  174. */
  175. ENTRY(arm1026_coherent_user_range)
  176. mov ip, #0
  177. bic r0, r0, #CACHE_DLINESIZE - 1
  178. 1:
  179. #ifndef CONFIG_CPU_DCACHE_DISABLE
  180. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  181. #endif
  182. #ifndef CONFIG_CPU_ICACHE_DISABLE
  183. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  184. #endif
  185. add r0, r0, #CACHE_DLINESIZE
  186. cmp r0, r1
  187. blo 1b
  188. mcr p15, 0, ip, 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. * - page - page aligned address
  197. */
  198. ENTRY(arm1026_flush_kern_dcache_page)
  199. mov ip, #0
  200. #ifndef CONFIG_CPU_DCACHE_DISABLE
  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. #endif
  207. mcr p15, 0, ip, 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(arm1026_dma_inv_range)
  223. mov ip, #0
  224. #ifndef CONFIG_CPU_DCACHE_DISABLE
  225. tst r0, #CACHE_DLINESIZE - 1
  226. bic r0, r0, #CACHE_DLINESIZE - 1
  227. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  228. tst r1, #CACHE_DLINESIZE - 1
  229. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  230. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  231. add r0, r0, #CACHE_DLINESIZE
  232. cmp r0, r1
  233. blo 1b
  234. #endif
  235. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  236. mov pc, lr
  237. /*
  238. * dma_clean_range(start, end)
  239. *
  240. * Clean the specified virtual address range.
  241. *
  242. * - start - virtual start address
  243. * - end - virtual end address
  244. *
  245. * (same as v4wb)
  246. */
  247. ENTRY(arm1026_dma_clean_range)
  248. mov ip, #0
  249. #ifndef CONFIG_CPU_DCACHE_DISABLE
  250. bic r0, r0, #CACHE_DLINESIZE - 1
  251. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  252. add r0, r0, #CACHE_DLINESIZE
  253. cmp r0, r1
  254. blo 1b
  255. #endif
  256. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  257. mov pc, lr
  258. /*
  259. * dma_flush_range(start, end)
  260. *
  261. * Clean and invalidate the specified virtual address range.
  262. *
  263. * - start - virtual start address
  264. * - end - virtual end address
  265. */
  266. ENTRY(arm1026_dma_flush_range)
  267. mov ip, #0
  268. #ifndef CONFIG_CPU_DCACHE_DISABLE
  269. bic r0, r0, #CACHE_DLINESIZE - 1
  270. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  271. add r0, r0, #CACHE_DLINESIZE
  272. cmp r0, r1
  273. blo 1b
  274. #endif
  275. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  276. mov pc, lr
  277. ENTRY(arm1026_cache_fns)
  278. .long arm1026_flush_kern_cache_all
  279. .long arm1026_flush_user_cache_all
  280. .long arm1026_flush_user_cache_range
  281. .long arm1026_coherent_kern_range
  282. .long arm1026_coherent_user_range
  283. .long arm1026_flush_kern_dcache_page
  284. .long arm1026_dma_inv_range
  285. .long arm1026_dma_clean_range
  286. .long arm1026_dma_flush_range
  287. .align 5
  288. ENTRY(cpu_arm1026_dcache_clean_area)
  289. #ifndef CONFIG_CPU_DCACHE_DISABLE
  290. mov ip, #0
  291. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  292. add r0, r0, #CACHE_DLINESIZE
  293. subs r1, r1, #CACHE_DLINESIZE
  294. bhi 1b
  295. #endif
  296. mov pc, lr
  297. /* =============================== PageTable ============================== */
  298. /*
  299. * cpu_arm1026_switch_mm(pgd)
  300. *
  301. * Set the translation base pointer to be as described by pgd.
  302. *
  303. * pgd: new page tables
  304. */
  305. .align 5
  306. ENTRY(cpu_arm1026_switch_mm)
  307. mov r1, #0
  308. #ifndef CONFIG_CPU_DCACHE_DISABLE
  309. 1: mrc p15, 0, r15, c7, c14, 3 @ test, clean, invalidate
  310. bne 1b
  311. #endif
  312. #ifndef CONFIG_CPU_ICACHE_DISABLE
  313. mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
  314. #endif
  315. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  316. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  317. mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
  318. mov pc, lr
  319. /*
  320. * cpu_arm1026_set_pte(ptep, pte)
  321. *
  322. * Set a PTE and flush it out
  323. */
  324. .align 5
  325. ENTRY(cpu_arm1026_set_pte)
  326. str r1, [r0], #-2048 @ linux version
  327. eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
  328. bic r2, r1, #PTE_SMALL_AP_MASK
  329. bic r2, r2, #PTE_TYPE_MASK
  330. orr r2, r2, #PTE_TYPE_SMALL
  331. tst r1, #L_PTE_USER @ User?
  332. orrne r2, r2, #PTE_SMALL_AP_URO_SRW
  333. tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
  334. orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
  335. tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
  336. movne r2, #0
  337. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  338. eor r3, r1, #0x0a @ C & small page?
  339. tst r3, #0x0b
  340. biceq r2, r2, #4
  341. #endif
  342. str r2, [r0] @ hardware version
  343. mov r0, r0
  344. #ifndef CONFIG_CPU_DCACHE_DISABLE
  345. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  346. #endif
  347. mov pc, lr
  348. __INIT
  349. .type __arm1026_setup, #function
  350. __arm1026_setup:
  351. mov r0, #0
  352. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  353. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  354. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  355. mcr p15, 0, r4, c2, c0 @ load page table pointer
  356. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  357. mov r0, #4 @ explicitly disable writeback
  358. mcr p15, 7, r0, c15, c0, 0
  359. #endif
  360. mrc p15, 0, r0, c1, c0 @ get control register v4
  361. ldr r5, arm1026_cr1_clear
  362. bic r0, r0, r5
  363. ldr r5, arm1026_cr1_set
  364. orr r0, r0, r5
  365. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  366. orr r0, r0, #0x4000 @ .R.. .... .... ....
  367. #endif
  368. mov pc, lr
  369. .size __arm1026_setup, . - __arm1026_setup
  370. /*
  371. * R
  372. * .RVI ZFRS BLDP WCAM
  373. * .011 1001 ..11 0101
  374. *
  375. */
  376. .type arm1026_cr1_clear, #object
  377. .type arm1026_cr1_set, #object
  378. arm1026_cr1_clear:
  379. .word 0x7f3f
  380. arm1026_cr1_set:
  381. .word 0x3935
  382. __INITDATA
  383. /*
  384. * Purpose : Function pointers used to access above functions - all calls
  385. * come through these
  386. */
  387. .type arm1026_processor_functions, #object
  388. arm1026_processor_functions:
  389. .word v5t_early_abort
  390. .word cpu_arm1026_proc_init
  391. .word cpu_arm1026_proc_fin
  392. .word cpu_arm1026_reset
  393. .word cpu_arm1026_do_idle
  394. .word cpu_arm1026_dcache_clean_area
  395. .word cpu_arm1026_switch_mm
  396. .word cpu_arm1026_set_pte
  397. .size arm1026_processor_functions, . - arm1026_processor_functions
  398. .section .rodata
  399. .type cpu_arch_name, #object
  400. cpu_arch_name:
  401. .asciz "armv5tej"
  402. .size cpu_arch_name, . - cpu_arch_name
  403. .type cpu_elf_name, #object
  404. cpu_elf_name:
  405. .asciz "v5"
  406. .size cpu_elf_name, . - cpu_elf_name
  407. .align
  408. .type cpu_arm1026_name, #object
  409. cpu_arm1026_name:
  410. .ascii "ARM1026EJ-S"
  411. #ifndef CONFIG_CPU_ICACHE_DISABLE
  412. .ascii "i"
  413. #endif
  414. #ifndef CONFIG_CPU_DCACHE_DISABLE
  415. .ascii "d"
  416. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  417. .ascii "(wt)"
  418. #else
  419. .ascii "(wb)"
  420. #endif
  421. #endif
  422. #ifndef CONFIG_CPU_BPREDICT_DISABLE
  423. .ascii "B"
  424. #endif
  425. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  426. .ascii "RR"
  427. #endif
  428. .ascii "\0"
  429. .size cpu_arm1026_name, . - cpu_arm1026_name
  430. .align
  431. .section ".proc.info", #alloc, #execinstr
  432. .type __arm1026_proc_info,#object
  433. __arm1026_proc_info:
  434. .long 0x4106a260 @ ARM 1026EJ-S (v5TEJ)
  435. .long 0xff0ffff0
  436. .long PMD_TYPE_SECT | \
  437. PMD_BIT4 | \
  438. PMD_SECT_AP_WRITE | \
  439. PMD_SECT_AP_READ
  440. b __arm1026_setup
  441. .long cpu_arch_name
  442. .long cpu_elf_name
  443. .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP|HWCAP_JAVA
  444. .long cpu_arm1026_name
  445. .long arm1026_processor_functions
  446. .long v4wbi_tlb_fns
  447. .long v4wb_user_fns
  448. .long arm1026_cache_fns
  449. .size __arm1026_proc_info, . - __arm1026_proc_info