proc-arm1022.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. /*
  2. * linux/arch/arm/mm/proc-arm1022.S: MMU functions for ARM1022E
  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 ARM1022E.
  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_arm1022_proc_init()
  55. */
  56. ENTRY(cpu_arm1022_proc_init)
  57. mov pc, lr
  58. /*
  59. * cpu_arm1022_proc_fin()
  60. */
  61. ENTRY(cpu_arm1022_proc_fin)
  62. stmfd sp!, {lr}
  63. mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
  64. msr cpsr_c, ip
  65. bl arm1022_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_arm1022_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_arm1022_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_arm1022_do_idle()
  93. */
  94. .align 5
  95. ENTRY(cpu_arm1022_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(arm1022_flush_user_cache_all)
  107. /* FALLTHROUGH */
  108. /*
  109. * flush_kern_cache_all()
  110. *
  111. * Clean and invalidate the entire cache.
  112. */
  113. ENTRY(arm1022_flush_kern_cache_all)
  114. mov r2, #VM_EXEC
  115. mov ip, #0
  116. __flush_whole_cache:
  117. #ifndef CONFIG_CPU_DCACHE_DISABLE
  118. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 16 segments
  119. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  120. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  121. subs r3, r3, #1 << 26
  122. bcs 2b @ entries 63 to 0
  123. subs r1, r1, #1 << 5
  124. bcs 1b @ segments 15 to 0
  125. #endif
  126. tst r2, #VM_EXEC
  127. #ifndef CONFIG_CPU_ICACHE_DISABLE
  128. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  129. #endif
  130. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  131. mov pc, lr
  132. /*
  133. * flush_user_cache_range(start, end, flags)
  134. *
  135. * Invalidate a range of cache entries in the specified
  136. * address space.
  137. *
  138. * - start - start address (inclusive)
  139. * - end - end address (exclusive)
  140. * - flags - vm_flags for this space
  141. */
  142. ENTRY(arm1022_flush_user_cache_range)
  143. mov ip, #0
  144. sub r3, r1, r0 @ calculate total size
  145. cmp r3, #CACHE_DLIMIT
  146. bhs __flush_whole_cache
  147. #ifndef CONFIG_CPU_DCACHE_DISABLE
  148. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  149. add r0, r0, #CACHE_DLINESIZE
  150. cmp r0, r1
  151. blo 1b
  152. #endif
  153. tst r2, #VM_EXEC
  154. #ifndef CONFIG_CPU_ICACHE_DISABLE
  155. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  156. #endif
  157. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  158. mov pc, lr
  159. /*
  160. * coherent_kern_range(start, end)
  161. *
  162. * Ensure coherency between the Icache and the Dcache in the
  163. * region described by start. If you have non-snooping
  164. * Harvard caches, you need to implement this function.
  165. *
  166. * - start - virtual start address
  167. * - end - virtual end address
  168. */
  169. ENTRY(arm1022_coherent_kern_range)
  170. /* FALLTHROUGH */
  171. /*
  172. * coherent_user_range(start, end)
  173. *
  174. * Ensure coherency between the Icache and the Dcache in the
  175. * region described by start. If you have non-snooping
  176. * Harvard caches, you need to implement this function.
  177. *
  178. * - start - virtual start address
  179. * - end - virtual end address
  180. */
  181. ENTRY(arm1022_coherent_user_range)
  182. mov ip, #0
  183. bic r0, r0, #CACHE_DLINESIZE - 1
  184. 1:
  185. #ifndef CONFIG_CPU_DCACHE_DISABLE
  186. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  187. #endif
  188. #ifndef CONFIG_CPU_ICACHE_DISABLE
  189. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  190. #endif
  191. add r0, r0, #CACHE_DLINESIZE
  192. cmp r0, r1
  193. blo 1b
  194. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  195. mov pc, lr
  196. /*
  197. * flush_kern_dcache_page(void *page)
  198. *
  199. * Ensure no D cache aliasing occurs, either with itself or
  200. * the I cache
  201. *
  202. * - page - page aligned address
  203. */
  204. ENTRY(arm1022_flush_kern_dcache_page)
  205. mov ip, #0
  206. #ifndef CONFIG_CPU_DCACHE_DISABLE
  207. add r1, r0, #PAGE_SZ
  208. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  209. add r0, r0, #CACHE_DLINESIZE
  210. cmp r0, r1
  211. blo 1b
  212. #endif
  213. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  214. mov pc, lr
  215. /*
  216. * dma_inv_range(start, end)
  217. *
  218. * Invalidate (discard) the specified virtual address range.
  219. * May not write back any entries. If 'start' or 'end'
  220. * are not cache line aligned, those lines must be written
  221. * back.
  222. *
  223. * - start - virtual start address
  224. * - end - virtual end address
  225. *
  226. * (same as v4wb)
  227. */
  228. ENTRY(arm1022_dma_inv_range)
  229. mov ip, #0
  230. #ifndef CONFIG_CPU_DCACHE_DISABLE
  231. tst r0, #CACHE_DLINESIZE - 1
  232. bic r0, r0, #CACHE_DLINESIZE - 1
  233. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  234. tst r1, #CACHE_DLINESIZE - 1
  235. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  236. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  237. add r0, r0, #CACHE_DLINESIZE
  238. cmp r0, r1
  239. blo 1b
  240. #endif
  241. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  242. mov pc, lr
  243. /*
  244. * dma_clean_range(start, end)
  245. *
  246. * Clean the specified virtual address range.
  247. *
  248. * - start - virtual start address
  249. * - end - virtual end address
  250. *
  251. * (same as v4wb)
  252. */
  253. ENTRY(arm1022_dma_clean_range)
  254. mov ip, #0
  255. #ifndef CONFIG_CPU_DCACHE_DISABLE
  256. bic r0, r0, #CACHE_DLINESIZE - 1
  257. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  258. add r0, r0, #CACHE_DLINESIZE
  259. cmp r0, r1
  260. blo 1b
  261. #endif
  262. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  263. mov pc, lr
  264. /*
  265. * dma_flush_range(start, end)
  266. *
  267. * Clean and invalidate the specified virtual address range.
  268. *
  269. * - start - virtual start address
  270. * - end - virtual end address
  271. */
  272. ENTRY(arm1022_dma_flush_range)
  273. mov ip, #0
  274. #ifndef CONFIG_CPU_DCACHE_DISABLE
  275. bic r0, r0, #CACHE_DLINESIZE - 1
  276. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  277. add r0, r0, #CACHE_DLINESIZE
  278. cmp r0, r1
  279. blo 1b
  280. #endif
  281. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  282. mov pc, lr
  283. ENTRY(arm1022_cache_fns)
  284. .long arm1022_flush_kern_cache_all
  285. .long arm1022_flush_user_cache_all
  286. .long arm1022_flush_user_cache_range
  287. .long arm1022_coherent_kern_range
  288. .long arm1022_coherent_user_range
  289. .long arm1022_flush_kern_dcache_page
  290. .long arm1022_dma_inv_range
  291. .long arm1022_dma_clean_range
  292. .long arm1022_dma_flush_range
  293. .align 5
  294. ENTRY(cpu_arm1022_dcache_clean_area)
  295. #ifndef CONFIG_CPU_DCACHE_DISABLE
  296. mov ip, #0
  297. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  298. add r0, r0, #CACHE_DLINESIZE
  299. subs r1, r1, #CACHE_DLINESIZE
  300. bhi 1b
  301. #endif
  302. mov pc, lr
  303. /* =============================== PageTable ============================== */
  304. /*
  305. * cpu_arm1022_switch_mm(pgd)
  306. *
  307. * Set the translation base pointer to be as described by pgd.
  308. *
  309. * pgd: new page tables
  310. */
  311. .align 5
  312. ENTRY(cpu_arm1022_switch_mm)
  313. #ifndef CONFIG_CPU_DCACHE_DISABLE
  314. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 16 segments
  315. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  316. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  317. subs r3, r3, #1 << 26
  318. bcs 2b @ entries 63 to 0
  319. subs r1, r1, #1 << 5
  320. bcs 1b @ segments 15 to 0
  321. #endif
  322. mov r1, #0
  323. #ifndef CONFIG_CPU_ICACHE_DISABLE
  324. mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
  325. #endif
  326. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  327. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  328. mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
  329. mov pc, lr
  330. /*
  331. * cpu_arm1022_set_pte(ptep, pte)
  332. *
  333. * Set a PTE and flush it out
  334. */
  335. .align 5
  336. ENTRY(cpu_arm1022_set_pte)
  337. str r1, [r0], #-2048 @ linux version
  338. eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
  339. bic r2, r1, #PTE_SMALL_AP_MASK
  340. bic r2, r2, #PTE_TYPE_MASK
  341. orr r2, r2, #PTE_TYPE_SMALL
  342. tst r1, #L_PTE_USER @ User?
  343. orrne r2, r2, #PTE_SMALL_AP_URO_SRW
  344. tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
  345. orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
  346. tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
  347. movne r2, #0
  348. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  349. eor r3, r1, #0x0a @ C & small page?
  350. tst r3, #0x0b
  351. biceq r2, r2, #4
  352. #endif
  353. str r2, [r0] @ hardware version
  354. mov r0, r0
  355. #ifndef CONFIG_CPU_DCACHE_DISABLE
  356. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  357. #endif
  358. mov pc, lr
  359. __INIT
  360. .type __arm1022_setup, #function
  361. __arm1022_setup:
  362. mov r0, #0
  363. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  364. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  365. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  366. mrc p15, 0, r0, c1, c0 @ get control register v4
  367. ldr r5, arm1022_cr1_clear
  368. bic r0, r0, r5
  369. ldr r5, arm1022_cr1_set
  370. orr r0, r0, r5
  371. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  372. orr r0, r0, #0x4000 @ .R..............
  373. #endif
  374. mov pc, lr
  375. .size __arm1022_setup, . - __arm1022_setup
  376. /*
  377. * R
  378. * .RVI ZFRS BLDP WCAM
  379. * .011 1001 ..11 0101
  380. *
  381. */
  382. .type arm1022_cr1_clear, #object
  383. .type arm1022_cr1_set, #object
  384. arm1022_cr1_clear:
  385. .word 0x7f3f
  386. arm1022_cr1_set:
  387. .word 0x3935
  388. __INITDATA
  389. /*
  390. * Purpose : Function pointers used to access above functions - all calls
  391. * come through these
  392. */
  393. .type arm1022_processor_functions, #object
  394. arm1022_processor_functions:
  395. .word v4t_early_abort
  396. .word cpu_arm1022_proc_init
  397. .word cpu_arm1022_proc_fin
  398. .word cpu_arm1022_reset
  399. .word cpu_arm1022_do_idle
  400. .word cpu_arm1022_dcache_clean_area
  401. .word cpu_arm1022_switch_mm
  402. .word cpu_arm1022_set_pte
  403. .size arm1022_processor_functions, . - arm1022_processor_functions
  404. .section ".rodata"
  405. .type cpu_arch_name, #object
  406. cpu_arch_name:
  407. .asciz "armv5te"
  408. .size cpu_arch_name, . - cpu_arch_name
  409. .type cpu_elf_name, #object
  410. cpu_elf_name:
  411. .asciz "v5"
  412. .size cpu_elf_name, . - cpu_elf_name
  413. .type cpu_arm1022_name, #object
  414. cpu_arm1022_name:
  415. .ascii "arm1022"
  416. #ifndef CONFIG_CPU_ICACHE_DISABLE
  417. .ascii "i"
  418. #endif
  419. #ifndef CONFIG_CPU_DCACHE_DISABLE
  420. .ascii "d"
  421. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  422. .ascii "(wt)"
  423. #else
  424. .ascii "(wb)"
  425. #endif
  426. #endif
  427. #ifndef CONFIG_CPU_BPREDICT_DISABLE
  428. .ascii "B"
  429. #endif
  430. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  431. .ascii "RR"
  432. #endif
  433. .ascii "\0"
  434. .size cpu_arm1022_name, . - cpu_arm1022_name
  435. .align
  436. .section ".proc.info.init", #alloc, #execinstr
  437. .type __arm1022_proc_info,#object
  438. __arm1022_proc_info:
  439. .long 0x4105a220 @ ARM 1022E (v5TE)
  440. .long 0xff0ffff0
  441. .long PMD_TYPE_SECT | \
  442. PMD_BIT4 | \
  443. PMD_SECT_AP_WRITE | \
  444. PMD_SECT_AP_READ
  445. b __arm1022_setup
  446. .long cpu_arch_name
  447. .long cpu_elf_name
  448. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB | HWCAP_EDSP
  449. .long cpu_arm1022_name
  450. .long arm1022_processor_functions
  451. .long v4wbi_tlb_fns
  452. .long v4wb_user_fns
  453. .long arm1022_cache_fns
  454. .size __arm1022_proc_info, . - __arm1022_proc_info