proc-arm922.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /*
  2. * linux/arch/arm/mm/proc-arm922.S: MMU functions for ARM922
  3. *
  4. * Copyright (C) 1999,2000 ARM Limited
  5. * Copyright (C) 2000 Deep Blue Solutions Ltd.
  6. * Copyright (C) 2001 Altera Corporation
  7. * hacked for non-paged-MM by Hyok S. Choi, 2003.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. *
  24. * These are the low level assembler for performing cache and TLB
  25. * functions on the arm922.
  26. *
  27. * CONFIG_CPU_ARM922_CPU_IDLE -> nohlt
  28. */
  29. #include <linux/linkage.h>
  30. #include <linux/init.h>
  31. #include <asm/assembler.h>
  32. #include <asm/hwcap.h>
  33. #include <asm/pgtable-hwdef.h>
  34. #include <asm/pgtable.h>
  35. #include <asm/page.h>
  36. #include <asm/ptrace.h>
  37. #include "proc-macros.S"
  38. /*
  39. * The size of one data cache line.
  40. */
  41. #define CACHE_DLINESIZE 32
  42. /*
  43. * The number of data cache segments.
  44. */
  45. #define CACHE_DSEGMENTS 4
  46. /*
  47. * The number of lines in a cache segment.
  48. */
  49. #define CACHE_DENTRIES 64
  50. /*
  51. * This is the size at which it becomes more efficient to
  52. * clean the whole cache, rather than using the individual
  53. * cache line maintenance instructions. (I think this should
  54. * be 32768).
  55. */
  56. #define CACHE_DLIMIT 8192
  57. .text
  58. /*
  59. * cpu_arm922_proc_init()
  60. */
  61. ENTRY(cpu_arm922_proc_init)
  62. ret lr
  63. /*
  64. * cpu_arm922_proc_fin()
  65. */
  66. ENTRY(cpu_arm922_proc_fin)
  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. ret lr
  72. /*
  73. * cpu_arm922_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. .pushsection .idmap.text, "ax"
  83. ENTRY(cpu_arm922_reset)
  84. mov ip, #0
  85. mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
  86. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  87. #ifdef CONFIG_MMU
  88. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  89. #endif
  90. mrc p15, 0, ip, c1, c0, 0 @ ctrl register
  91. bic ip, ip, #0x000f @ ............wcam
  92. bic ip, ip, #0x1100 @ ...i...s........
  93. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  94. ret r0
  95. ENDPROC(cpu_arm922_reset)
  96. .popsection
  97. /*
  98. * cpu_arm922_do_idle()
  99. */
  100. .align 5
  101. ENTRY(cpu_arm922_do_idle)
  102. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  103. ret lr
  104. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  105. /*
  106. * flush_icache_all()
  107. *
  108. * Unconditionally clean and invalidate the entire icache.
  109. */
  110. ENTRY(arm922_flush_icache_all)
  111. mov r0, #0
  112. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  113. ret lr
  114. ENDPROC(arm922_flush_icache_all)
  115. /*
  116. * flush_user_cache_all()
  117. *
  118. * Clean and invalidate all cache entries in a particular
  119. * address space.
  120. */
  121. ENTRY(arm922_flush_user_cache_all)
  122. /* FALLTHROUGH */
  123. /*
  124. * flush_kern_cache_all()
  125. *
  126. * Clean and invalidate the entire cache.
  127. */
  128. ENTRY(arm922_flush_kern_cache_all)
  129. mov r2, #VM_EXEC
  130. mov ip, #0
  131. __flush_whole_cache:
  132. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 8 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 7 to 0
  139. tst r2, #VM_EXEC
  140. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  141. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  142. ret lr
  143. /*
  144. * flush_user_cache_range(start, end, flags)
  145. *
  146. * Clean and invalidate a range of cache entries in the
  147. * specified address range.
  148. *
  149. * - start - start address (inclusive)
  150. * - end - end address (exclusive)
  151. * - flags - vm_flags describing address space
  152. */
  153. ENTRY(arm922_flush_user_cache_range)
  154. mov ip, #0
  155. sub r3, r1, r0 @ calculate total size
  156. cmp r3, #CACHE_DLIMIT
  157. bhs __flush_whole_cache
  158. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  159. tst r2, #VM_EXEC
  160. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  161. add r0, r0, #CACHE_DLINESIZE
  162. cmp r0, r1
  163. blo 1b
  164. tst r2, #VM_EXEC
  165. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  166. ret lr
  167. /*
  168. * coherent_kern_range(start, end)
  169. *
  170. * Ensure coherency between the Icache and the Dcache in the
  171. * region described by start, end. If you have non-snooping
  172. * Harvard caches, you need to implement this function.
  173. *
  174. * - start - virtual start address
  175. * - end - virtual end address
  176. */
  177. ENTRY(arm922_coherent_kern_range)
  178. /* FALLTHROUGH */
  179. /*
  180. * coherent_user_range(start, end)
  181. *
  182. * Ensure coherency between the Icache and the Dcache in the
  183. * region described by start, end. If you have non-snooping
  184. * Harvard caches, you need to implement this function.
  185. *
  186. * - start - virtual start address
  187. * - end - virtual end address
  188. */
  189. ENTRY(arm922_coherent_user_range)
  190. bic r0, r0, #CACHE_DLINESIZE - 1
  191. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  192. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  193. add r0, r0, #CACHE_DLINESIZE
  194. cmp r0, r1
  195. blo 1b
  196. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  197. mov r0, #0
  198. ret 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(arm922_flush_kern_dcache_area)
  209. add r1, r0, r1
  210. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  211. add r0, r0, #CACHE_DLINESIZE
  212. cmp r0, r1
  213. blo 1b
  214. mov r0, #0
  215. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  216. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  217. ret 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. arm922_dma_inv_range:
  232. tst r0, #CACHE_DLINESIZE - 1
  233. bic r0, r0, #CACHE_DLINESIZE - 1
  234. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  235. tst r1, #CACHE_DLINESIZE - 1
  236. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  237. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  238. add r0, r0, #CACHE_DLINESIZE
  239. cmp r0, r1
  240. blo 1b
  241. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  242. ret 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. arm922_dma_clean_range:
  254. bic r0, r0, #CACHE_DLINESIZE - 1
  255. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  256. add r0, r0, #CACHE_DLINESIZE
  257. cmp r0, r1
  258. blo 1b
  259. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  260. ret lr
  261. /*
  262. * dma_flush_range(start, end)
  263. *
  264. * Clean and invalidate the specified virtual address range.
  265. *
  266. * - start - virtual start address
  267. * - end - virtual end address
  268. */
  269. ENTRY(arm922_dma_flush_range)
  270. bic r0, r0, #CACHE_DLINESIZE - 1
  271. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  272. add r0, r0, #CACHE_DLINESIZE
  273. cmp r0, r1
  274. blo 1b
  275. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  276. ret lr
  277. /*
  278. * dma_map_area(start, size, dir)
  279. * - start - kernel virtual start address
  280. * - size - size of region
  281. * - dir - DMA direction
  282. */
  283. ENTRY(arm922_dma_map_area)
  284. add r1, r1, r0
  285. cmp r2, #DMA_TO_DEVICE
  286. beq arm922_dma_clean_range
  287. bcs arm922_dma_inv_range
  288. b arm922_dma_flush_range
  289. ENDPROC(arm922_dma_map_area)
  290. /*
  291. * dma_unmap_area(start, size, dir)
  292. * - start - kernel virtual start address
  293. * - size - size of region
  294. * - dir - DMA direction
  295. */
  296. ENTRY(arm922_dma_unmap_area)
  297. ret lr
  298. ENDPROC(arm922_dma_unmap_area)
  299. .globl arm922_flush_kern_cache_louis
  300. .equ arm922_flush_kern_cache_louis, arm922_flush_kern_cache_all
  301. @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
  302. define_cache_functions arm922
  303. #endif
  304. ENTRY(cpu_arm922_dcache_clean_area)
  305. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  306. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  307. add r0, r0, #CACHE_DLINESIZE
  308. subs r1, r1, #CACHE_DLINESIZE
  309. bhi 1b
  310. #endif
  311. ret lr
  312. /* =============================== PageTable ============================== */
  313. /*
  314. * cpu_arm922_switch_mm(pgd)
  315. *
  316. * Set the translation base pointer to be as described by pgd.
  317. *
  318. * pgd: new page tables
  319. */
  320. .align 5
  321. ENTRY(cpu_arm922_switch_mm)
  322. #ifdef CONFIG_MMU
  323. mov ip, #0
  324. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  325. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  326. #else
  327. @ && 'Clean & Invalidate whole DCache'
  328. @ && Re-written to use Index Ops.
  329. @ && Uses registers r1, r3 and ip
  330. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 4 segments
  331. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  332. 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
  333. subs r3, r3, #1 << 26
  334. bcs 2b @ entries 63 to 0
  335. subs r1, r1, #1 << 5
  336. bcs 1b @ segments 7 to 0
  337. #endif
  338. mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
  339. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  340. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  341. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  342. #endif
  343. ret lr
  344. /*
  345. * cpu_arm922_set_pte_ext(ptep, pte, ext)
  346. *
  347. * Set a PTE and flush it out
  348. */
  349. .align 5
  350. ENTRY(cpu_arm922_set_pte_ext)
  351. #ifdef CONFIG_MMU
  352. armv3_set_pte_ext
  353. mov r0, r0
  354. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  355. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  356. #endif /* CONFIG_MMU */
  357. ret lr
  358. .type __arm922_setup, #function
  359. __arm922_setup:
  360. mov r0, #0
  361. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  362. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  363. #ifdef CONFIG_MMU
  364. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  365. #endif
  366. adr r5, arm922_crval
  367. ldmia r5, {r5, r6}
  368. mrc p15, 0, r0, c1, c0 @ get control register v4
  369. bic r0, r0, r5
  370. orr r0, r0, r6
  371. ret lr
  372. .size __arm922_setup, . - __arm922_setup
  373. /*
  374. * R
  375. * .RVI ZFRS BLDP WCAM
  376. * ..11 0001 ..11 0101
  377. *
  378. */
  379. .type arm922_crval, #object
  380. arm922_crval:
  381. crval clear=0x00003f3f, mmuset=0x00003135, ucset=0x00001130
  382. __INITDATA
  383. @ define struct processor (see <asm/proc-fns.h> and proc-macros.S)
  384. define_processor_functions arm922, dabort=v4t_early_abort, pabort=legacy_pabort
  385. .section ".rodata"
  386. string cpu_arch_name, "armv4t"
  387. string cpu_elf_name, "v4"
  388. string cpu_arm922_name, "ARM922T"
  389. .align
  390. .section ".proc.info.init", #alloc
  391. .type __arm922_proc_info,#object
  392. __arm922_proc_info:
  393. .long 0x41009220
  394. .long 0xff00fff0
  395. .long PMD_TYPE_SECT | \
  396. PMD_SECT_BUFFERABLE | \
  397. PMD_SECT_CACHEABLE | \
  398. PMD_BIT4 | \
  399. PMD_SECT_AP_WRITE | \
  400. PMD_SECT_AP_READ
  401. .long PMD_TYPE_SECT | \
  402. PMD_BIT4 | \
  403. PMD_SECT_AP_WRITE | \
  404. PMD_SECT_AP_READ
  405. initfn __arm922_setup, __arm922_proc_info
  406. .long cpu_arch_name
  407. .long cpu_elf_name
  408. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
  409. .long cpu_arm922_name
  410. .long arm922_processor_functions
  411. .long v4wbi_tlb_fns
  412. .long v4wb_user_fns
  413. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  414. .long arm922_cache_fns
  415. #else
  416. .long v4wt_cache_fns
  417. #endif
  418. .size __arm922_proc_info, . - __arm922_proc_info