proc-arm1022.S 12 KB

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