proc-arm922.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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 maintainence 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. stmfd sp!, {lr}
  68. mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
  69. msr cpsr_c, ip
  70. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  71. bl arm922_flush_kern_cache_all
  72. #else
  73. bl v4wt_flush_kern_cache_all
  74. #endif
  75. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  76. bic r0, r0, #0x1000 @ ...i............
  77. bic r0, r0, #0x000e @ ............wca.
  78. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  79. ldmfd sp!, {pc}
  80. /*
  81. * cpu_arm922_reset(loc)
  82. *
  83. * Perform a soft reset of the system. Put the CPU into the
  84. * same state as it would be if it had been reset, and branch
  85. * to what would be the reset vector.
  86. *
  87. * loc: location to jump to for soft reset
  88. */
  89. .align 5
  90. ENTRY(cpu_arm922_reset)
  91. mov ip, #0
  92. mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
  93. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  94. #ifdef CONFIG_MMU
  95. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  96. #endif
  97. mrc p15, 0, ip, c1, c0, 0 @ ctrl register
  98. bic ip, ip, #0x000f @ ............wcam
  99. bic ip, ip, #0x1100 @ ...i...s........
  100. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  101. mov pc, r0
  102. /*
  103. * cpu_arm922_do_idle()
  104. */
  105. .align 5
  106. ENTRY(cpu_arm922_do_idle)
  107. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  108. mov pc, lr
  109. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  110. /*
  111. * flush_user_cache_all()
  112. *
  113. * Clean and invalidate all cache entries in a particular
  114. * address space.
  115. */
  116. ENTRY(arm922_flush_user_cache_all)
  117. /* FALLTHROUGH */
  118. /*
  119. * flush_kern_cache_all()
  120. *
  121. * Clean and invalidate the entire cache.
  122. */
  123. ENTRY(arm922_flush_kern_cache_all)
  124. mov r2, #VM_EXEC
  125. mov ip, #0
  126. __flush_whole_cache:
  127. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 8 segments
  128. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  129. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  130. subs r3, r3, #1 << 26
  131. bcs 2b @ entries 63 to 0
  132. subs r1, r1, #1 << 5
  133. bcs 1b @ segments 7 to 0
  134. tst r2, #VM_EXEC
  135. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  136. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  137. mov pc, lr
  138. /*
  139. * flush_user_cache_range(start, end, flags)
  140. *
  141. * Clean and invalidate a range of cache entries in the
  142. * specified address range.
  143. *
  144. * - start - start address (inclusive)
  145. * - end - end address (exclusive)
  146. * - flags - vm_flags describing address space
  147. */
  148. ENTRY(arm922_flush_user_cache_range)
  149. mov ip, #0
  150. sub r3, r1, r0 @ calculate total size
  151. cmp r3, #CACHE_DLIMIT
  152. bhs __flush_whole_cache
  153. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  154. tst r2, #VM_EXEC
  155. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  156. add r0, r0, #CACHE_DLINESIZE
  157. cmp r0, r1
  158. blo 1b
  159. tst r2, #VM_EXEC
  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, end. 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(arm922_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, end. 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(arm922_coherent_user_range)
  185. bic r0, r0, #CACHE_DLINESIZE - 1
  186. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  187. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  188. add r0, r0, #CACHE_DLINESIZE
  189. cmp r0, r1
  190. blo 1b
  191. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  192. mov pc, lr
  193. /*
  194. * flush_kern_dcache_area(void *addr, size_t size)
  195. *
  196. * Ensure no D cache aliasing occurs, either with itself or
  197. * the I cache
  198. *
  199. * - addr - kernel address
  200. * - size - region size
  201. */
  202. ENTRY(arm922_flush_kern_dcache_area)
  203. add r1, r0, r1
  204. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  205. add r0, r0, #CACHE_DLINESIZE
  206. cmp r0, r1
  207. blo 1b
  208. mov r0, #0
  209. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  210. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  211. mov pc, lr
  212. /*
  213. * dma_inv_range(start, end)
  214. *
  215. * Invalidate (discard) the specified virtual address range.
  216. * May not write back any entries. If 'start' or 'end'
  217. * are not cache line aligned, those lines must be written
  218. * back.
  219. *
  220. * - start - virtual start address
  221. * - end - virtual end address
  222. *
  223. * (same as v4wb)
  224. */
  225. ENTRY(arm922_dma_inv_range)
  226. tst r0, #CACHE_DLINESIZE - 1
  227. bic r0, r0, #CACHE_DLINESIZE - 1
  228. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  229. tst r1, #CACHE_DLINESIZE - 1
  230. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  231. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  232. add r0, r0, #CACHE_DLINESIZE
  233. cmp r0, r1
  234. blo 1b
  235. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  236. mov pc, lr
  237. /*
  238. * dma_clean_range(start, end)
  239. *
  240. * Clean the specified virtual address range.
  241. *
  242. * - start - virtual start address
  243. * - end - virtual end address
  244. *
  245. * (same as v4wb)
  246. */
  247. ENTRY(arm922_dma_clean_range)
  248. bic r0, r0, #CACHE_DLINESIZE - 1
  249. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  250. add r0, r0, #CACHE_DLINESIZE
  251. cmp r0, r1
  252. blo 1b
  253. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  254. mov pc, lr
  255. /*
  256. * dma_flush_range(start, end)
  257. *
  258. * Clean and invalidate the specified virtual address range.
  259. *
  260. * - start - virtual start address
  261. * - end - virtual end address
  262. */
  263. ENTRY(arm922_dma_flush_range)
  264. bic r0, r0, #CACHE_DLINESIZE - 1
  265. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  266. add r0, r0, #CACHE_DLINESIZE
  267. cmp r0, r1
  268. blo 1b
  269. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  270. mov pc, lr
  271. ENTRY(arm922_cache_fns)
  272. .long arm922_flush_kern_cache_all
  273. .long arm922_flush_user_cache_all
  274. .long arm922_flush_user_cache_range
  275. .long arm922_coherent_kern_range
  276. .long arm922_coherent_user_range
  277. .long arm922_flush_kern_dcache_area
  278. .long arm922_dma_inv_range
  279. .long arm922_dma_clean_range
  280. .long arm922_dma_flush_range
  281. #endif
  282. ENTRY(cpu_arm922_dcache_clean_area)
  283. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  284. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  285. add r0, r0, #CACHE_DLINESIZE
  286. subs r1, r1, #CACHE_DLINESIZE
  287. bhi 1b
  288. #endif
  289. mov pc, lr
  290. /* =============================== PageTable ============================== */
  291. /*
  292. * cpu_arm922_switch_mm(pgd)
  293. *
  294. * Set the translation base pointer to be as described by pgd.
  295. *
  296. * pgd: new page tables
  297. */
  298. .align 5
  299. ENTRY(cpu_arm922_switch_mm)
  300. #ifdef CONFIG_MMU
  301. mov ip, #0
  302. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  303. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  304. #else
  305. @ && 'Clean & Invalidate whole DCache'
  306. @ && Re-written to use Index Ops.
  307. @ && Uses registers r1, r3 and ip
  308. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 4 segments
  309. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  310. 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
  311. subs r3, r3, #1 << 26
  312. bcs 2b @ entries 63 to 0
  313. subs r1, r1, #1 << 5
  314. bcs 1b @ segments 7 to 0
  315. #endif
  316. mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
  317. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  318. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  319. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  320. #endif
  321. mov pc, lr
  322. /*
  323. * cpu_arm922_set_pte_ext(ptep, pte, ext)
  324. *
  325. * Set a PTE and flush it out
  326. */
  327. .align 5
  328. ENTRY(cpu_arm922_set_pte_ext)
  329. #ifdef CONFIG_MMU
  330. armv3_set_pte_ext
  331. mov r0, r0
  332. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  333. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  334. #endif /* CONFIG_MMU */
  335. mov pc, lr
  336. __INIT
  337. .type __arm922_setup, #function
  338. __arm922_setup:
  339. mov r0, #0
  340. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  341. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  342. #ifdef CONFIG_MMU
  343. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  344. #endif
  345. adr r5, arm922_crval
  346. ldmia r5, {r5, r6}
  347. mrc p15, 0, r0, c1, c0 @ get control register v4
  348. bic r0, r0, r5
  349. orr r0, r0, r6
  350. mov pc, lr
  351. .size __arm922_setup, . - __arm922_setup
  352. /*
  353. * R
  354. * .RVI ZFRS BLDP WCAM
  355. * ..11 0001 ..11 0101
  356. *
  357. */
  358. .type arm922_crval, #object
  359. arm922_crval:
  360. crval clear=0x00003f3f, mmuset=0x00003135, ucset=0x00001130
  361. __INITDATA
  362. /*
  363. * Purpose : Function pointers used to access above functions - all calls
  364. * come through these
  365. */
  366. .type arm922_processor_functions, #object
  367. arm922_processor_functions:
  368. .word v4t_early_abort
  369. .word legacy_pabort
  370. .word cpu_arm922_proc_init
  371. .word cpu_arm922_proc_fin
  372. .word cpu_arm922_reset
  373. .word cpu_arm922_do_idle
  374. .word cpu_arm922_dcache_clean_area
  375. .word cpu_arm922_switch_mm
  376. .word cpu_arm922_set_pte_ext
  377. .size arm922_processor_functions, . - arm922_processor_functions
  378. .section ".rodata"
  379. .type cpu_arch_name, #object
  380. cpu_arch_name:
  381. .asciz "armv4t"
  382. .size cpu_arch_name, . - cpu_arch_name
  383. .type cpu_elf_name, #object
  384. cpu_elf_name:
  385. .asciz "v4"
  386. .size cpu_elf_name, . - cpu_elf_name
  387. .type cpu_arm922_name, #object
  388. cpu_arm922_name:
  389. .asciz "ARM922T"
  390. .size cpu_arm922_name, . - cpu_arm922_name
  391. .align
  392. .section ".proc.info.init", #alloc, #execinstr
  393. .type __arm922_proc_info,#object
  394. __arm922_proc_info:
  395. .long 0x41009220
  396. .long 0xff00fff0
  397. .long PMD_TYPE_SECT | \
  398. PMD_SECT_BUFFERABLE | \
  399. PMD_SECT_CACHEABLE | \
  400. PMD_BIT4 | \
  401. PMD_SECT_AP_WRITE | \
  402. PMD_SECT_AP_READ
  403. .long PMD_TYPE_SECT | \
  404. PMD_BIT4 | \
  405. PMD_SECT_AP_WRITE | \
  406. PMD_SECT_AP_READ
  407. b __arm922_setup
  408. .long cpu_arch_name
  409. .long cpu_elf_name
  410. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
  411. .long cpu_arm922_name
  412. .long arm922_processor_functions
  413. .long v4wbi_tlb_fns
  414. .long v4wb_user_fns
  415. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  416. .long arm922_cache_fns
  417. #else
  418. .long v4wt_cache_fns
  419. #endif
  420. .size __arm922_proc_info, . - __arm922_proc_info