proc-arm922.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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. mov pc, 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. mov pc, 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. ENTRY(cpu_arm922_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_arm922_do_idle()
  96. */
  97. .align 5
  98. ENTRY(cpu_arm922_do_idle)
  99. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  100. mov pc, lr
  101. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  102. /*
  103. * flush_icache_all()
  104. *
  105. * Unconditionally clean and invalidate the entire icache.
  106. */
  107. ENTRY(arm922_flush_icache_all)
  108. mov r0, #0
  109. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  110. mov pc, lr
  111. ENDPROC(arm922_flush_icache_all)
  112. /*
  113. * flush_user_cache_all()
  114. *
  115. * Clean and invalidate all cache entries in a particular
  116. * address space.
  117. */
  118. ENTRY(arm922_flush_user_cache_all)
  119. /* FALLTHROUGH */
  120. /*
  121. * flush_kern_cache_all()
  122. *
  123. * Clean and invalidate the entire cache.
  124. */
  125. ENTRY(arm922_flush_kern_cache_all)
  126. mov r2, #VM_EXEC
  127. mov ip, #0
  128. __flush_whole_cache:
  129. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 8 segments
  130. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  131. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  132. subs r3, r3, #1 << 26
  133. bcs 2b @ entries 63 to 0
  134. subs r1, r1, #1 << 5
  135. bcs 1b @ segments 7 to 0
  136. tst r2, #VM_EXEC
  137. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  138. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  139. mov pc, lr
  140. /*
  141. * flush_user_cache_range(start, end, flags)
  142. *
  143. * Clean and invalidate a range of cache entries in the
  144. * specified address range.
  145. *
  146. * - start - start address (inclusive)
  147. * - end - end address (exclusive)
  148. * - flags - vm_flags describing address space
  149. */
  150. ENTRY(arm922_flush_user_cache_range)
  151. mov ip, #0
  152. sub r3, r1, r0 @ calculate total size
  153. cmp r3, #CACHE_DLIMIT
  154. bhs __flush_whole_cache
  155. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  156. tst r2, #VM_EXEC
  157. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  158. add r0, r0, #CACHE_DLINESIZE
  159. cmp r0, r1
  160. blo 1b
  161. tst r2, #VM_EXEC
  162. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  163. mov pc, lr
  164. /*
  165. * coherent_kern_range(start, end)
  166. *
  167. * Ensure coherency between the Icache and the Dcache in the
  168. * region described by start, end. If you have non-snooping
  169. * Harvard caches, you need to implement this function.
  170. *
  171. * - start - virtual start address
  172. * - end - virtual end address
  173. */
  174. ENTRY(arm922_coherent_kern_range)
  175. /* FALLTHROUGH */
  176. /*
  177. * coherent_user_range(start, end)
  178. *
  179. * Ensure coherency between the Icache and the Dcache in the
  180. * region described by start, end. If you have non-snooping
  181. * Harvard caches, you need to implement this function.
  182. *
  183. * - start - virtual start address
  184. * - end - virtual end address
  185. */
  186. ENTRY(arm922_coherent_user_range)
  187. bic r0, r0, #CACHE_DLINESIZE - 1
  188. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  189. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  190. add r0, r0, #CACHE_DLINESIZE
  191. cmp r0, r1
  192. blo 1b
  193. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  194. mov pc, lr
  195. /*
  196. * flush_kern_dcache_area(void *addr, size_t size)
  197. *
  198. * Ensure no D cache aliasing occurs, either with itself or
  199. * the I cache
  200. *
  201. * - addr - kernel address
  202. * - size - region size
  203. */
  204. ENTRY(arm922_flush_kern_dcache_area)
  205. add r1, r0, r1
  206. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  207. add r0, r0, #CACHE_DLINESIZE
  208. cmp r0, r1
  209. blo 1b
  210. mov r0, #0
  211. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  212. mcr p15, 0, r0, 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. arm922_dma_inv_range:
  228. tst r0, #CACHE_DLINESIZE - 1
  229. bic r0, r0, #CACHE_DLINESIZE - 1
  230. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  231. tst r1, #CACHE_DLINESIZE - 1
  232. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  233. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  234. add r0, r0, #CACHE_DLINESIZE
  235. cmp r0, r1
  236. blo 1b
  237. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  238. mov pc, lr
  239. /*
  240. * dma_clean_range(start, end)
  241. *
  242. * Clean the specified virtual address range.
  243. *
  244. * - start - virtual start address
  245. * - end - virtual end address
  246. *
  247. * (same as v4wb)
  248. */
  249. arm922_dma_clean_range:
  250. bic r0, r0, #CACHE_DLINESIZE - 1
  251. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  252. add r0, r0, #CACHE_DLINESIZE
  253. cmp r0, r1
  254. blo 1b
  255. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  256. mov pc, lr
  257. /*
  258. * dma_flush_range(start, end)
  259. *
  260. * Clean and invalidate the specified virtual address range.
  261. *
  262. * - start - virtual start address
  263. * - end - virtual end address
  264. */
  265. ENTRY(arm922_dma_flush_range)
  266. bic r0, r0, #CACHE_DLINESIZE - 1
  267. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  268. add r0, r0, #CACHE_DLINESIZE
  269. cmp r0, r1
  270. blo 1b
  271. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  272. mov pc, lr
  273. /*
  274. * dma_map_area(start, size, dir)
  275. * - start - kernel virtual start address
  276. * - size - size of region
  277. * - dir - DMA direction
  278. */
  279. ENTRY(arm922_dma_map_area)
  280. add r1, r1, r0
  281. cmp r2, #DMA_TO_DEVICE
  282. beq arm922_dma_clean_range
  283. bcs arm922_dma_inv_range
  284. b arm922_dma_flush_range
  285. ENDPROC(arm922_dma_map_area)
  286. /*
  287. * dma_unmap_area(start, size, dir)
  288. * - start - kernel virtual start address
  289. * - size - size of region
  290. * - dir - DMA direction
  291. */
  292. ENTRY(arm922_dma_unmap_area)
  293. mov pc, lr
  294. ENDPROC(arm922_dma_unmap_area)
  295. @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
  296. define_cache_functions arm922
  297. #endif
  298. ENTRY(cpu_arm922_dcache_clean_area)
  299. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  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_arm922_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_arm922_switch_mm)
  316. #ifdef CONFIG_MMU
  317. mov ip, #0
  318. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  319. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  320. #else
  321. @ && 'Clean & Invalidate whole DCache'
  322. @ && Re-written to use Index Ops.
  323. @ && Uses registers r1, r3 and ip
  324. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 4 segments
  325. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  326. 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
  327. subs r3, r3, #1 << 26
  328. bcs 2b @ entries 63 to 0
  329. subs r1, r1, #1 << 5
  330. bcs 1b @ segments 7 to 0
  331. #endif
  332. mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
  333. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  334. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  335. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  336. #endif
  337. mov pc, lr
  338. /*
  339. * cpu_arm922_set_pte_ext(ptep, pte, ext)
  340. *
  341. * Set a PTE and flush it out
  342. */
  343. .align 5
  344. ENTRY(cpu_arm922_set_pte_ext)
  345. #ifdef CONFIG_MMU
  346. armv3_set_pte_ext
  347. mov r0, r0
  348. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  349. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  350. #endif /* CONFIG_MMU */
  351. mov pc, lr
  352. __CPUINIT
  353. .type __arm922_setup, #function
  354. __arm922_setup:
  355. mov r0, #0
  356. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  357. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  358. #ifdef CONFIG_MMU
  359. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  360. #endif
  361. adr r5, arm922_crval
  362. ldmia r5, {r5, r6}
  363. mrc p15, 0, r0, c1, c0 @ get control register v4
  364. bic r0, r0, r5
  365. orr r0, r0, r6
  366. mov pc, lr
  367. .size __arm922_setup, . - __arm922_setup
  368. /*
  369. * R
  370. * .RVI ZFRS BLDP WCAM
  371. * ..11 0001 ..11 0101
  372. *
  373. */
  374. .type arm922_crval, #object
  375. arm922_crval:
  376. crval clear=0x00003f3f, mmuset=0x00003135, ucset=0x00001130
  377. __INITDATA
  378. @ define struct processor (see <asm/proc-fns.h> and proc-macros.S)
  379. define_processor_functions arm922, dabort=v4t_early_abort, pabort=legacy_pabort
  380. .section ".rodata"
  381. string cpu_arch_name, "armv4t"
  382. string cpu_elf_name, "v4"
  383. string cpu_arm922_name, "ARM922T"
  384. .align
  385. .section ".proc.info.init", #alloc, #execinstr
  386. .type __arm922_proc_info,#object
  387. __arm922_proc_info:
  388. .long 0x41009220
  389. .long 0xff00fff0
  390. .long PMD_TYPE_SECT | \
  391. PMD_SECT_BUFFERABLE | \
  392. PMD_SECT_CACHEABLE | \
  393. PMD_BIT4 | \
  394. PMD_SECT_AP_WRITE | \
  395. PMD_SECT_AP_READ
  396. .long PMD_TYPE_SECT | \
  397. PMD_BIT4 | \
  398. PMD_SECT_AP_WRITE | \
  399. PMD_SECT_AP_READ
  400. b __arm922_setup
  401. .long cpu_arch_name
  402. .long cpu_elf_name
  403. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
  404. .long cpu_arm922_name
  405. .long arm922_processor_functions
  406. .long v4wbi_tlb_fns
  407. .long v4wb_user_fns
  408. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  409. .long arm922_cache_fns
  410. #else
  411. .long v4wt_cache_fns
  412. #endif
  413. .size __arm922_proc_info, . - __arm922_proc_info