proc-arm1022.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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 maintenance instructions.
  51. */
  52. #define CACHE_DLIMIT 32768
  53. .text
  54. /*
  55. * cpu_arm1022_proc_init()
  56. */
  57. ENTRY(cpu_arm1022_proc_init)
  58. ret lr
  59. /*
  60. * cpu_arm1022_proc_fin()
  61. */
  62. ENTRY(cpu_arm1022_proc_fin)
  63. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  64. bic r0, r0, #0x1000 @ ...i............
  65. bic r0, r0, #0x000e @ ............wca.
  66. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  67. ret lr
  68. /*
  69. * cpu_arm1022_reset(loc)
  70. *
  71. * Perform a soft reset of the system. Put the CPU into the
  72. * same state as it would be if it had been reset, and branch
  73. * to what would be the reset vector.
  74. *
  75. * loc: location to jump to for soft reset
  76. */
  77. .align 5
  78. .pushsection .idmap.text, "ax"
  79. ENTRY(cpu_arm1022_reset)
  80. mov ip, #0
  81. mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
  82. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  83. #ifdef CONFIG_MMU
  84. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  85. #endif
  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. ret r0
  91. ENDPROC(cpu_arm1022_reset)
  92. .popsection
  93. /*
  94. * cpu_arm1022_do_idle()
  95. */
  96. .align 5
  97. ENTRY(cpu_arm1022_do_idle)
  98. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  99. ret lr
  100. /* ================================= CACHE ================================ */
  101. .align 5
  102. /*
  103. * flush_icache_all()
  104. *
  105. * Unconditionally clean and invalidate the entire icache.
  106. */
  107. ENTRY(arm1022_flush_icache_all)
  108. #ifndef CONFIG_CPU_ICACHE_DISABLE
  109. mov r0, #0
  110. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  111. #endif
  112. ret lr
  113. ENDPROC(arm1022_flush_icache_all)
  114. /*
  115. * flush_user_cache_all()
  116. *
  117. * Invalidate all cache entries in a particular address
  118. * space.
  119. */
  120. ENTRY(arm1022_flush_user_cache_all)
  121. /* FALLTHROUGH */
  122. /*
  123. * flush_kern_cache_all()
  124. *
  125. * Clean and invalidate the entire cache.
  126. */
  127. ENTRY(arm1022_flush_kern_cache_all)
  128. mov r2, #VM_EXEC
  129. mov ip, #0
  130. __flush_whole_cache:
  131. #ifndef CONFIG_CPU_DCACHE_DISABLE
  132. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 16 segments
  133. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  134. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  135. subs r3, r3, #1 << 26
  136. bcs 2b @ entries 63 to 0
  137. subs r1, r1, #1 << 5
  138. bcs 1b @ segments 15 to 0
  139. #endif
  140. tst r2, #VM_EXEC
  141. #ifndef CONFIG_CPU_ICACHE_DISABLE
  142. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  143. #endif
  144. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  145. ret lr
  146. /*
  147. * flush_user_cache_range(start, end, flags)
  148. *
  149. * Invalidate a range of cache entries in the specified
  150. * address space.
  151. *
  152. * - start - start address (inclusive)
  153. * - end - end address (exclusive)
  154. * - flags - vm_flags for this space
  155. */
  156. ENTRY(arm1022_flush_user_cache_range)
  157. mov ip, #0
  158. sub r3, r1, r0 @ calculate total size
  159. cmp r3, #CACHE_DLIMIT
  160. bhs __flush_whole_cache
  161. #ifndef CONFIG_CPU_DCACHE_DISABLE
  162. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  163. add r0, r0, #CACHE_DLINESIZE
  164. cmp r0, r1
  165. blo 1b
  166. #endif
  167. tst r2, #VM_EXEC
  168. #ifndef CONFIG_CPU_ICACHE_DISABLE
  169. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  170. #endif
  171. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  172. ret lr
  173. /*
  174. * coherent_kern_range(start, end)
  175. *
  176. * Ensure coherency between the Icache and the Dcache in the
  177. * region described by start. If you have non-snooping
  178. * Harvard caches, you need to implement this function.
  179. *
  180. * - start - virtual start address
  181. * - end - virtual end address
  182. */
  183. ENTRY(arm1022_coherent_kern_range)
  184. /* FALLTHROUGH */
  185. /*
  186. * coherent_user_range(start, end)
  187. *
  188. * Ensure coherency between the Icache and the Dcache in the
  189. * region described by start. If you have non-snooping
  190. * Harvard caches, you need to implement this function.
  191. *
  192. * - start - virtual start address
  193. * - end - virtual end address
  194. */
  195. ENTRY(arm1022_coherent_user_range)
  196. mov ip, #0
  197. bic r0, r0, #CACHE_DLINESIZE - 1
  198. 1:
  199. #ifndef CONFIG_CPU_DCACHE_DISABLE
  200. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  201. #endif
  202. #ifndef CONFIG_CPU_ICACHE_DISABLE
  203. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  204. #endif
  205. add r0, r0, #CACHE_DLINESIZE
  206. cmp r0, r1
  207. blo 1b
  208. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  209. mov r0, #0
  210. ret lr
  211. /*
  212. * flush_kern_dcache_area(void *addr, size_t size)
  213. *
  214. * Ensure no D cache aliasing occurs, either with itself or
  215. * the I cache
  216. *
  217. * - addr - kernel address
  218. * - size - region size
  219. */
  220. ENTRY(arm1022_flush_kern_dcache_area)
  221. mov ip, #0
  222. #ifndef CONFIG_CPU_DCACHE_DISABLE
  223. add r1, r0, r1
  224. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  225. add r0, r0, #CACHE_DLINESIZE
  226. cmp r0, r1
  227. blo 1b
  228. #endif
  229. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  230. ret lr
  231. /*
  232. * dma_inv_range(start, end)
  233. *
  234. * Invalidate (discard) the specified virtual address range.
  235. * May not write back any entries. If 'start' or 'end'
  236. * are not cache line aligned, those lines must be written
  237. * back.
  238. *
  239. * - start - virtual start address
  240. * - end - virtual end address
  241. *
  242. * (same as v4wb)
  243. */
  244. arm1022_dma_inv_range:
  245. mov ip, #0
  246. #ifndef CONFIG_CPU_DCACHE_DISABLE
  247. tst r0, #CACHE_DLINESIZE - 1
  248. bic r0, r0, #CACHE_DLINESIZE - 1
  249. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  250. tst r1, #CACHE_DLINESIZE - 1
  251. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  252. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate 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. ret lr
  259. /*
  260. * dma_clean_range(start, end)
  261. *
  262. * Clean the specified virtual address range.
  263. *
  264. * - start - virtual start address
  265. * - end - virtual end address
  266. *
  267. * (same as v4wb)
  268. */
  269. arm1022_dma_clean_range:
  270. mov ip, #0
  271. #ifndef CONFIG_CPU_DCACHE_DISABLE
  272. bic r0, r0, #CACHE_DLINESIZE - 1
  273. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  274. add r0, r0, #CACHE_DLINESIZE
  275. cmp r0, r1
  276. blo 1b
  277. #endif
  278. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  279. ret lr
  280. /*
  281. * dma_flush_range(start, end)
  282. *
  283. * Clean and invalidate the specified virtual address range.
  284. *
  285. * - start - virtual start address
  286. * - end - virtual end address
  287. */
  288. ENTRY(arm1022_dma_flush_range)
  289. mov ip, #0
  290. #ifndef CONFIG_CPU_DCACHE_DISABLE
  291. bic r0, r0, #CACHE_DLINESIZE - 1
  292. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  293. add r0, r0, #CACHE_DLINESIZE
  294. cmp r0, r1
  295. blo 1b
  296. #endif
  297. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  298. ret lr
  299. /*
  300. * dma_map_area(start, size, dir)
  301. * - start - kernel virtual start address
  302. * - size - size of region
  303. * - dir - DMA direction
  304. */
  305. ENTRY(arm1022_dma_map_area)
  306. add r1, r1, r0
  307. cmp r2, #DMA_TO_DEVICE
  308. beq arm1022_dma_clean_range
  309. bcs arm1022_dma_inv_range
  310. b arm1022_dma_flush_range
  311. ENDPROC(arm1022_dma_map_area)
  312. /*
  313. * dma_unmap_area(start, size, dir)
  314. * - start - kernel virtual start address
  315. * - size - size of region
  316. * - dir - DMA direction
  317. */
  318. ENTRY(arm1022_dma_unmap_area)
  319. ret lr
  320. ENDPROC(arm1022_dma_unmap_area)
  321. .globl arm1022_flush_kern_cache_louis
  322. .equ arm1022_flush_kern_cache_louis, arm1022_flush_kern_cache_all
  323. @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
  324. define_cache_functions arm1022
  325. .align 5
  326. ENTRY(cpu_arm1022_dcache_clean_area)
  327. #ifndef CONFIG_CPU_DCACHE_DISABLE
  328. mov ip, #0
  329. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  330. add r0, r0, #CACHE_DLINESIZE
  331. subs r1, r1, #CACHE_DLINESIZE
  332. bhi 1b
  333. #endif
  334. ret lr
  335. /* =============================== PageTable ============================== */
  336. /*
  337. * cpu_arm1022_switch_mm(pgd)
  338. *
  339. * Set the translation base pointer to be as described by pgd.
  340. *
  341. * pgd: new page tables
  342. */
  343. .align 5
  344. ENTRY(cpu_arm1022_switch_mm)
  345. #ifdef CONFIG_MMU
  346. #ifndef CONFIG_CPU_DCACHE_DISABLE
  347. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 16 segments
  348. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  349. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  350. subs r3, r3, #1 << 26
  351. bcs 2b @ entries 63 to 0
  352. subs r1, r1, #1 << 5
  353. bcs 1b @ segments 15 to 0
  354. #endif
  355. mov r1, #0
  356. #ifndef CONFIG_CPU_ICACHE_DISABLE
  357. mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
  358. #endif
  359. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  360. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  361. mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
  362. #endif
  363. ret lr
  364. /*
  365. * cpu_arm1022_set_pte_ext(ptep, pte, ext)
  366. *
  367. * Set a PTE and flush it out
  368. */
  369. .align 5
  370. ENTRY(cpu_arm1022_set_pte_ext)
  371. #ifdef CONFIG_MMU
  372. armv3_set_pte_ext
  373. mov r0, r0
  374. #ifndef CONFIG_CPU_DCACHE_DISABLE
  375. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  376. #endif
  377. #endif /* CONFIG_MMU */
  378. ret lr
  379. .type __arm1022_setup, #function
  380. __arm1022_setup:
  381. mov r0, #0
  382. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  383. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  384. #ifdef CONFIG_MMU
  385. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  386. #endif
  387. adr r5, arm1022_crval
  388. ldmia r5, {r5, r6}
  389. mrc p15, 0, r0, c1, c0 @ get control register v4
  390. bic r0, r0, r5
  391. orr r0, r0, r6
  392. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  393. orr r0, r0, #0x4000 @ .R..............
  394. #endif
  395. ret lr
  396. .size __arm1022_setup, . - __arm1022_setup
  397. /*
  398. * R
  399. * .RVI ZFRS BLDP WCAM
  400. * .011 1001 ..11 0101
  401. *
  402. */
  403. .type arm1022_crval, #object
  404. arm1022_crval:
  405. crval clear=0x00007f3f, mmuset=0x00003935, ucset=0x00001930
  406. __INITDATA
  407. @ define struct processor (see <asm/proc-fns.h> and proc-macros.S)
  408. define_processor_functions arm1022, dabort=v4t_early_abort, pabort=legacy_pabort
  409. .section ".rodata"
  410. string cpu_arch_name, "armv5te"
  411. string cpu_elf_name, "v5"
  412. string cpu_arm1022_name, "ARM1022"
  413. .align
  414. .section ".proc.info.init", #alloc
  415. .type __arm1022_proc_info,#object
  416. __arm1022_proc_info:
  417. .long 0x4105a220 @ ARM 1022E (v5TE)
  418. .long 0xff0ffff0
  419. .long PMD_TYPE_SECT | \
  420. PMD_BIT4 | \
  421. PMD_SECT_AP_WRITE | \
  422. PMD_SECT_AP_READ
  423. .long PMD_TYPE_SECT | \
  424. PMD_BIT4 | \
  425. PMD_SECT_AP_WRITE | \
  426. PMD_SECT_AP_READ
  427. initfn __arm1022_setup, __arm1022_proc_info
  428. .long cpu_arch_name
  429. .long cpu_elf_name
  430. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB | HWCAP_EDSP
  431. .long cpu_arm1022_name
  432. .long arm1022_processor_functions
  433. .long v4wbi_tlb_fns
  434. .long v4wb_user_fns
  435. .long arm1022_cache_fns
  436. .size __arm1022_proc_info, . - __arm1022_proc_info