proc-arm1022.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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. * hacked for non-paged-MM by Hyok S. Choi, 2003.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. *
  14. * These are the low level assembler for performing cache and TLB
  15. * functions on the ARM1022E.
  16. */
  17. #include <linux/linkage.h>
  18. #include <linux/init.h>
  19. #include <asm/assembler.h>
  20. #include <asm/asm-offsets.h>
  21. #include <asm/elf.h>
  22. #include <asm/pgtable-hwdef.h>
  23. #include <asm/pgtable.h>
  24. #include <asm/ptrace.h>
  25. #include "proc-macros.S"
  26. /*
  27. * This is the maximum size of an area which will be invalidated
  28. * using the single invalidate entry instructions. Anything larger
  29. * than this, and we go for the whole cache.
  30. *
  31. * This value should be chosen such that we choose the cheapest
  32. * alternative.
  33. */
  34. #define MAX_AREA_SIZE 32768
  35. /*
  36. * The size of one data cache line.
  37. */
  38. #define CACHE_DLINESIZE 32
  39. /*
  40. * The number of data cache segments.
  41. */
  42. #define CACHE_DSEGMENTS 16
  43. /*
  44. * The number of lines in a cache segment.
  45. */
  46. #define CACHE_DENTRIES 64
  47. /*
  48. * This is the size at which it becomes more efficient to
  49. * clean the whole cache, rather than using the individual
  50. * cache line maintainence instructions.
  51. */
  52. #define CACHE_DLIMIT 32768
  53. .text
  54. /*
  55. * cpu_arm1022_proc_init()
  56. */
  57. ENTRY(cpu_arm1022_proc_init)
  58. mov pc, lr
  59. /*
  60. * cpu_arm1022_proc_fin()
  61. */
  62. ENTRY(cpu_arm1022_proc_fin)
  63. stmfd sp!, {lr}
  64. mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
  65. msr cpsr_c, ip
  66. bl arm1022_flush_kern_cache_all
  67. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  68. bic r0, r0, #0x1000 @ ...i............
  69. bic r0, r0, #0x000e @ ............wca.
  70. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  71. ldmfd sp!, {pc}
  72. /*
  73. * cpu_arm1022_reset(loc)
  74. *
  75. * Perform a soft reset of the system. Put the CPU into the
  76. * same state as it would be if it had been reset, and branch
  77. * to what would be the reset vector.
  78. *
  79. * loc: location to jump to for soft reset
  80. */
  81. .align 5
  82. ENTRY(cpu_arm1022_reset)
  83. mov ip, #0
  84. mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
  85. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  86. #ifdef CONFIG_MMU
  87. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  88. #endif
  89. mrc p15, 0, ip, c1, c0, 0 @ ctrl register
  90. bic ip, ip, #0x000f @ ............wcam
  91. bic ip, ip, #0x1100 @ ...i...s........
  92. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  93. mov pc, r0
  94. /*
  95. * cpu_arm1022_do_idle()
  96. */
  97. .align 5
  98. ENTRY(cpu_arm1022_do_idle)
  99. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  100. mov pc, lr
  101. /* ================================= CACHE ================================ */
  102. .align 5
  103. /*
  104. * flush_user_cache_all()
  105. *
  106. * Invalidate all cache entries in a particular address
  107. * space.
  108. */
  109. ENTRY(arm1022_flush_user_cache_all)
  110. /* FALLTHROUGH */
  111. /*
  112. * flush_kern_cache_all()
  113. *
  114. * Clean and invalidate the entire cache.
  115. */
  116. ENTRY(arm1022_flush_kern_cache_all)
  117. mov r2, #VM_EXEC
  118. mov ip, #0
  119. __flush_whole_cache:
  120. #ifndef CONFIG_CPU_DCACHE_DISABLE
  121. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 16 segments
  122. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  123. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  124. subs r3, r3, #1 << 26
  125. bcs 2b @ entries 63 to 0
  126. subs r1, r1, #1 << 5
  127. bcs 1b @ segments 15 to 0
  128. #endif
  129. tst r2, #VM_EXEC
  130. #ifndef CONFIG_CPU_ICACHE_DISABLE
  131. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  132. #endif
  133. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  134. mov pc, lr
  135. /*
  136. * flush_user_cache_range(start, end, flags)
  137. *
  138. * Invalidate a range of cache entries in the specified
  139. * address space.
  140. *
  141. * - start - start address (inclusive)
  142. * - end - end address (exclusive)
  143. * - flags - vm_flags for this space
  144. */
  145. ENTRY(arm1022_flush_user_cache_range)
  146. mov ip, #0
  147. sub r3, r1, r0 @ calculate total size
  148. cmp r3, #CACHE_DLIMIT
  149. bhs __flush_whole_cache
  150. #ifndef CONFIG_CPU_DCACHE_DISABLE
  151. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  152. add r0, r0, #CACHE_DLINESIZE
  153. cmp r0, r1
  154. blo 1b
  155. #endif
  156. tst r2, #VM_EXEC
  157. #ifndef CONFIG_CPU_ICACHE_DISABLE
  158. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  159. #endif
  160. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  161. mov pc, lr
  162. /*
  163. * coherent_kern_range(start, end)
  164. *
  165. * Ensure coherency between the Icache and the Dcache in the
  166. * region described by start. If you have non-snooping
  167. * Harvard caches, you need to implement this function.
  168. *
  169. * - start - virtual start address
  170. * - end - virtual end address
  171. */
  172. ENTRY(arm1022_coherent_kern_range)
  173. /* FALLTHROUGH */
  174. /*
  175. * coherent_user_range(start, end)
  176. *
  177. * Ensure coherency between the Icache and the Dcache in the
  178. * region described by start. If you have non-snooping
  179. * Harvard caches, you need to implement this function.
  180. *
  181. * - start - virtual start address
  182. * - end - virtual end address
  183. */
  184. ENTRY(arm1022_coherent_user_range)
  185. mov ip, #0
  186. bic r0, r0, #CACHE_DLINESIZE - 1
  187. 1:
  188. #ifndef CONFIG_CPU_DCACHE_DISABLE
  189. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  190. #endif
  191. #ifndef CONFIG_CPU_ICACHE_DISABLE
  192. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  193. #endif
  194. add r0, r0, #CACHE_DLINESIZE
  195. cmp r0, r1
  196. blo 1b
  197. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  198. mov pc, lr
  199. /*
  200. * flush_kern_dcache_page(void *page)
  201. *
  202. * Ensure no D cache aliasing occurs, either with itself or
  203. * the I cache
  204. *
  205. * - page - page aligned address
  206. */
  207. ENTRY(arm1022_flush_kern_dcache_page)
  208. mov ip, #0
  209. #ifndef CONFIG_CPU_DCACHE_DISABLE
  210. add r1, r0, #PAGE_SZ
  211. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  212. add r0, r0, #CACHE_DLINESIZE
  213. cmp r0, r1
  214. blo 1b
  215. #endif
  216. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  217. mov pc, lr
  218. /*
  219. * dma_inv_range(start, end)
  220. *
  221. * Invalidate (discard) the specified virtual address range.
  222. * May not write back any entries. If 'start' or 'end'
  223. * are not cache line aligned, those lines must be written
  224. * back.
  225. *
  226. * - start - virtual start address
  227. * - end - virtual end address
  228. *
  229. * (same as v4wb)
  230. */
  231. ENTRY(arm1022_dma_inv_range)
  232. mov ip, #0
  233. #ifndef CONFIG_CPU_DCACHE_DISABLE
  234. tst r0, #CACHE_DLINESIZE - 1
  235. bic r0, r0, #CACHE_DLINESIZE - 1
  236. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  237. tst r1, #CACHE_DLINESIZE - 1
  238. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  239. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  240. add r0, r0, #CACHE_DLINESIZE
  241. cmp r0, r1
  242. blo 1b
  243. #endif
  244. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  245. mov pc, lr
  246. /*
  247. * dma_clean_range(start, end)
  248. *
  249. * Clean the specified virtual address range.
  250. *
  251. * - start - virtual start address
  252. * - end - virtual end address
  253. *
  254. * (same as v4wb)
  255. */
  256. ENTRY(arm1022_dma_clean_range)
  257. mov ip, #0
  258. #ifndef CONFIG_CPU_DCACHE_DISABLE
  259. bic r0, r0, #CACHE_DLINESIZE - 1
  260. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  261. add r0, r0, #CACHE_DLINESIZE
  262. cmp r0, r1
  263. blo 1b
  264. #endif
  265. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  266. mov pc, lr
  267. /*
  268. * dma_flush_range(start, end)
  269. *
  270. * Clean and invalidate the specified virtual address range.
  271. *
  272. * - start - virtual start address
  273. * - end - virtual end address
  274. */
  275. ENTRY(arm1022_dma_flush_range)
  276. mov ip, #0
  277. #ifndef CONFIG_CPU_DCACHE_DISABLE
  278. bic r0, r0, #CACHE_DLINESIZE - 1
  279. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  280. add r0, r0, #CACHE_DLINESIZE
  281. cmp r0, r1
  282. blo 1b
  283. #endif
  284. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  285. mov pc, lr
  286. ENTRY(arm1022_cache_fns)
  287. .long arm1022_flush_kern_cache_all
  288. .long arm1022_flush_user_cache_all
  289. .long arm1022_flush_user_cache_range
  290. .long arm1022_coherent_kern_range
  291. .long arm1022_coherent_user_range
  292. .long arm1022_flush_kern_dcache_page
  293. .long arm1022_dma_inv_range
  294. .long arm1022_dma_clean_range
  295. .long arm1022_dma_flush_range
  296. .align 5
  297. ENTRY(cpu_arm1022_dcache_clean_area)
  298. #ifndef CONFIG_CPU_DCACHE_DISABLE
  299. mov ip, #0
  300. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  301. add r0, r0, #CACHE_DLINESIZE
  302. subs r1, r1, #CACHE_DLINESIZE
  303. bhi 1b
  304. #endif
  305. mov pc, lr
  306. /* =============================== PageTable ============================== */
  307. /*
  308. * cpu_arm1022_switch_mm(pgd)
  309. *
  310. * Set the translation base pointer to be as described by pgd.
  311. *
  312. * pgd: new page tables
  313. */
  314. .align 5
  315. ENTRY(cpu_arm1022_switch_mm)
  316. #ifdef CONFIG_MMU
  317. #ifndef CONFIG_CPU_DCACHE_DISABLE
  318. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 16 segments
  319. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  320. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  321. subs r3, r3, #1 << 26
  322. bcs 2b @ entries 63 to 0
  323. subs r1, r1, #1 << 5
  324. bcs 1b @ segments 15 to 0
  325. #endif
  326. mov r1, #0
  327. #ifndef CONFIG_CPU_ICACHE_DISABLE
  328. mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
  329. #endif
  330. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  331. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  332. mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
  333. #endif
  334. mov pc, lr
  335. /*
  336. * cpu_arm1022_set_pte_ext(ptep, pte, ext)
  337. *
  338. * Set a PTE and flush it out
  339. */
  340. .align 5
  341. ENTRY(cpu_arm1022_set_pte_ext)
  342. #ifdef CONFIG_MMU
  343. str r1, [r0], #-2048 @ linux version
  344. eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
  345. bic r2, r1, #PTE_SMALL_AP_MASK
  346. bic r2, r2, #PTE_TYPE_MASK
  347. orr r2, r2, #PTE_TYPE_SMALL
  348. tst r1, #L_PTE_USER @ User?
  349. orrne r2, r2, #PTE_SMALL_AP_URO_SRW
  350. tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
  351. orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
  352. tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
  353. movne r2, #0
  354. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  355. eor r3, r1, #0x0a @ C & small page?
  356. tst r3, #0x0b
  357. biceq r2, r2, #4
  358. #endif
  359. str r2, [r0] @ hardware version
  360. mov r0, r0
  361. #ifndef CONFIG_CPU_DCACHE_DISABLE
  362. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  363. #endif
  364. #endif /* CONFIG_MMU */
  365. mov pc, lr
  366. __INIT
  367. .type __arm1022_setup, #function
  368. __arm1022_setup:
  369. mov r0, #0
  370. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  371. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  372. #ifdef CONFIG_MMU
  373. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  374. #endif
  375. adr r5, arm1022_crval
  376. ldmia r5, {r5, r6}
  377. mrc p15, 0, r0, c1, c0 @ get control register v4
  378. bic r0, r0, r5
  379. orr r0, r0, r6
  380. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  381. orr r0, r0, #0x4000 @ .R..............
  382. #endif
  383. mov pc, lr
  384. .size __arm1022_setup, . - __arm1022_setup
  385. /*
  386. * R
  387. * .RVI ZFRS BLDP WCAM
  388. * .011 1001 ..11 0101
  389. *
  390. */
  391. .type arm1022_crval, #object
  392. arm1022_crval:
  393. crval clear=0x00007f3f, mmuset=0x00003935, ucset=0x00001930
  394. __INITDATA
  395. /*
  396. * Purpose : Function pointers used to access above functions - all calls
  397. * come through these
  398. */
  399. .type arm1022_processor_functions, #object
  400. arm1022_processor_functions:
  401. .word v4t_early_abort
  402. .word cpu_arm1022_proc_init
  403. .word cpu_arm1022_proc_fin
  404. .word cpu_arm1022_reset
  405. .word cpu_arm1022_do_idle
  406. .word cpu_arm1022_dcache_clean_area
  407. .word cpu_arm1022_switch_mm
  408. .word cpu_arm1022_set_pte_ext
  409. .size arm1022_processor_functions, . - arm1022_processor_functions
  410. .section ".rodata"
  411. .type cpu_arch_name, #object
  412. cpu_arch_name:
  413. .asciz "armv5te"
  414. .size cpu_arch_name, . - cpu_arch_name
  415. .type cpu_elf_name, #object
  416. cpu_elf_name:
  417. .asciz "v5"
  418. .size cpu_elf_name, . - cpu_elf_name
  419. .type cpu_arm1022_name, #object
  420. cpu_arm1022_name:
  421. .asciz "ARM1022"
  422. .size cpu_arm1022_name, . - cpu_arm1022_name
  423. .align
  424. .section ".proc.info.init", #alloc, #execinstr
  425. .type __arm1022_proc_info,#object
  426. __arm1022_proc_info:
  427. .long 0x4105a220 @ ARM 1022E (v5TE)
  428. .long 0xff0ffff0
  429. .long PMD_TYPE_SECT | \
  430. PMD_BIT4 | \
  431. PMD_SECT_AP_WRITE | \
  432. PMD_SECT_AP_READ
  433. .long PMD_TYPE_SECT | \
  434. PMD_BIT4 | \
  435. PMD_SECT_AP_WRITE | \
  436. PMD_SECT_AP_READ
  437. b __arm1022_setup
  438. .long cpu_arch_name
  439. .long cpu_elf_name
  440. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB | HWCAP_EDSP
  441. .long cpu_arm1022_name
  442. .long arm1022_processor_functions
  443. .long v4wbi_tlb_fns
  444. .long v4wb_user_fns
  445. .long arm1022_cache_fns
  446. .size __arm1022_proc_info, . - __arm1022_proc_info