proc-arm1026.S 11 KB

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