proc-arm1022.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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/hwcap.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_area(void *addr, size_t size)
  201. *
  202. * Ensure no D cache aliasing occurs, either with itself or
  203. * the I cache
  204. *
  205. * - addr - kernel address
  206. * - size - region size
  207. */
  208. ENTRY(arm1022_flush_kern_dcache_area)
  209. mov ip, #0
  210. #ifndef CONFIG_CPU_DCACHE_DISABLE
  211. add r1, r0, r1
  212. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  213. add r0, r0, #CACHE_DLINESIZE
  214. cmp r0, r1
  215. blo 1b
  216. #endif
  217. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  218. mov pc, lr
  219. /*
  220. * dma_inv_range(start, end)
  221. *
  222. * Invalidate (discard) the specified virtual address range.
  223. * May not write back any entries. If 'start' or 'end'
  224. * are not cache line aligned, those lines must be written
  225. * back.
  226. *
  227. * - start - virtual start address
  228. * - end - virtual end address
  229. *
  230. * (same as v4wb)
  231. */
  232. ENTRY(arm1022_dma_inv_range)
  233. mov ip, #0
  234. #ifndef CONFIG_CPU_DCACHE_DISABLE
  235. tst r0, #CACHE_DLINESIZE - 1
  236. bic r0, r0, #CACHE_DLINESIZE - 1
  237. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  238. tst r1, #CACHE_DLINESIZE - 1
  239. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  240. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  241. add r0, r0, #CACHE_DLINESIZE
  242. cmp r0, r1
  243. blo 1b
  244. #endif
  245. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  246. mov pc, lr
  247. /*
  248. * dma_clean_range(start, end)
  249. *
  250. * Clean the specified virtual address range.
  251. *
  252. * - start - virtual start address
  253. * - end - virtual end address
  254. *
  255. * (same as v4wb)
  256. */
  257. ENTRY(arm1022_dma_clean_range)
  258. mov ip, #0
  259. #ifndef CONFIG_CPU_DCACHE_DISABLE
  260. bic r0, r0, #CACHE_DLINESIZE - 1
  261. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  262. add r0, r0, #CACHE_DLINESIZE
  263. cmp r0, r1
  264. blo 1b
  265. #endif
  266. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  267. mov pc, lr
  268. /*
  269. * dma_flush_range(start, end)
  270. *
  271. * Clean and invalidate the specified virtual address range.
  272. *
  273. * - start - virtual start address
  274. * - end - virtual end address
  275. */
  276. ENTRY(arm1022_dma_flush_range)
  277. mov ip, #0
  278. #ifndef CONFIG_CPU_DCACHE_DISABLE
  279. bic r0, r0, #CACHE_DLINESIZE - 1
  280. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  281. add r0, r0, #CACHE_DLINESIZE
  282. cmp r0, r1
  283. blo 1b
  284. #endif
  285. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  286. mov pc, lr
  287. ENTRY(arm1022_cache_fns)
  288. .long arm1022_flush_kern_cache_all
  289. .long arm1022_flush_user_cache_all
  290. .long arm1022_flush_user_cache_range
  291. .long arm1022_coherent_kern_range
  292. .long arm1022_coherent_user_range
  293. .long arm1022_flush_kern_dcache_area
  294. .long arm1022_dma_inv_range
  295. .long arm1022_dma_clean_range
  296. .long arm1022_dma_flush_range
  297. .align 5
  298. ENTRY(cpu_arm1022_dcache_clean_area)
  299. #ifndef CONFIG_CPU_DCACHE_DISABLE
  300. mov ip, #0
  301. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  302. add r0, r0, #CACHE_DLINESIZE
  303. subs r1, r1, #CACHE_DLINESIZE
  304. bhi 1b
  305. #endif
  306. mov pc, lr
  307. /* =============================== PageTable ============================== */
  308. /*
  309. * cpu_arm1022_switch_mm(pgd)
  310. *
  311. * Set the translation base pointer to be as described by pgd.
  312. *
  313. * pgd: new page tables
  314. */
  315. .align 5
  316. ENTRY(cpu_arm1022_switch_mm)
  317. #ifdef CONFIG_MMU
  318. #ifndef CONFIG_CPU_DCACHE_DISABLE
  319. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 16 segments
  320. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  321. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  322. subs r3, r3, #1 << 26
  323. bcs 2b @ entries 63 to 0
  324. subs r1, r1, #1 << 5
  325. bcs 1b @ segments 15 to 0
  326. #endif
  327. mov r1, #0
  328. #ifndef CONFIG_CPU_ICACHE_DISABLE
  329. mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
  330. #endif
  331. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  332. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  333. mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
  334. #endif
  335. mov pc, lr
  336. /*
  337. * cpu_arm1022_set_pte_ext(ptep, pte, ext)
  338. *
  339. * Set a PTE and flush it out
  340. */
  341. .align 5
  342. ENTRY(cpu_arm1022_set_pte_ext)
  343. #ifdef CONFIG_MMU
  344. armv3_set_pte_ext
  345. mov r0, r0
  346. #ifndef CONFIG_CPU_DCACHE_DISABLE
  347. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  348. #endif
  349. #endif /* CONFIG_MMU */
  350. mov pc, lr
  351. __INIT
  352. .type __arm1022_setup, #function
  353. __arm1022_setup:
  354. mov r0, #0
  355. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  356. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  357. #ifdef CONFIG_MMU
  358. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  359. #endif
  360. adr r5, arm1022_crval
  361. ldmia r5, {r5, r6}
  362. mrc p15, 0, r0, c1, c0 @ get control register v4
  363. bic r0, r0, r5
  364. orr r0, r0, r6
  365. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  366. orr r0, r0, #0x4000 @ .R..............
  367. #endif
  368. mov pc, lr
  369. .size __arm1022_setup, . - __arm1022_setup
  370. /*
  371. * R
  372. * .RVI ZFRS BLDP WCAM
  373. * .011 1001 ..11 0101
  374. *
  375. */
  376. .type arm1022_crval, #object
  377. arm1022_crval:
  378. crval clear=0x00007f3f, mmuset=0x00003935, ucset=0x00001930
  379. __INITDATA
  380. /*
  381. * Purpose : Function pointers used to access above functions - all calls
  382. * come through these
  383. */
  384. .type arm1022_processor_functions, #object
  385. arm1022_processor_functions:
  386. .word v4t_early_abort
  387. .word legacy_pabort
  388. .word cpu_arm1022_proc_init
  389. .word cpu_arm1022_proc_fin
  390. .word cpu_arm1022_reset
  391. .word cpu_arm1022_do_idle
  392. .word cpu_arm1022_dcache_clean_area
  393. .word cpu_arm1022_switch_mm
  394. .word cpu_arm1022_set_pte_ext
  395. .size arm1022_processor_functions, . - arm1022_processor_functions
  396. .section ".rodata"
  397. .type cpu_arch_name, #object
  398. cpu_arch_name:
  399. .asciz "armv5te"
  400. .size cpu_arch_name, . - cpu_arch_name
  401. .type cpu_elf_name, #object
  402. cpu_elf_name:
  403. .asciz "v5"
  404. .size cpu_elf_name, . - cpu_elf_name
  405. .type cpu_arm1022_name, #object
  406. cpu_arm1022_name:
  407. .asciz "ARM1022"
  408. .size cpu_arm1022_name, . - cpu_arm1022_name
  409. .align
  410. .section ".proc.info.init", #alloc, #execinstr
  411. .type __arm1022_proc_info,#object
  412. __arm1022_proc_info:
  413. .long 0x4105a220 @ ARM 1022E (v5TE)
  414. .long 0xff0ffff0
  415. .long PMD_TYPE_SECT | \
  416. PMD_BIT4 | \
  417. PMD_SECT_AP_WRITE | \
  418. PMD_SECT_AP_READ
  419. .long PMD_TYPE_SECT | \
  420. PMD_BIT4 | \
  421. PMD_SECT_AP_WRITE | \
  422. PMD_SECT_AP_READ
  423. b __arm1022_setup
  424. .long cpu_arch_name
  425. .long cpu_elf_name
  426. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB | HWCAP_EDSP
  427. .long cpu_arm1022_name
  428. .long arm1022_processor_functions
  429. .long v4wbi_tlb_fns
  430. .long v4wb_user_fns
  431. .long arm1022_cache_fns
  432. .size __arm1022_proc_info, . - __arm1022_proc_info