proc-arm922.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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. 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. ENTRY(arm922_cache_fns)
  296. .long arm922_flush_icache_all
  297. .long arm922_flush_kern_cache_all
  298. .long arm922_flush_user_cache_all
  299. .long arm922_flush_user_cache_range
  300. .long arm922_coherent_kern_range
  301. .long arm922_coherent_user_range
  302. .long arm922_flush_kern_dcache_area
  303. .long arm922_dma_map_area
  304. .long arm922_dma_unmap_area
  305. .long arm922_dma_flush_range
  306. #endif
  307. ENTRY(cpu_arm922_dcache_clean_area)
  308. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  309. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  310. add r0, r0, #CACHE_DLINESIZE
  311. subs r1, r1, #CACHE_DLINESIZE
  312. bhi 1b
  313. #endif
  314. mov pc, lr
  315. /* =============================== PageTable ============================== */
  316. /*
  317. * cpu_arm922_switch_mm(pgd)
  318. *
  319. * Set the translation base pointer to be as described by pgd.
  320. *
  321. * pgd: new page tables
  322. */
  323. .align 5
  324. ENTRY(cpu_arm922_switch_mm)
  325. #ifdef CONFIG_MMU
  326. mov ip, #0
  327. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  328. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  329. #else
  330. @ && 'Clean & Invalidate whole DCache'
  331. @ && Re-written to use Index Ops.
  332. @ && Uses registers r1, r3 and ip
  333. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 4 segments
  334. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  335. 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
  336. subs r3, r3, #1 << 26
  337. bcs 2b @ entries 63 to 0
  338. subs r1, r1, #1 << 5
  339. bcs 1b @ segments 7 to 0
  340. #endif
  341. mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
  342. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  343. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  344. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  345. #endif
  346. mov pc, lr
  347. /*
  348. * cpu_arm922_set_pte_ext(ptep, pte, ext)
  349. *
  350. * Set a PTE and flush it out
  351. */
  352. .align 5
  353. ENTRY(cpu_arm922_set_pte_ext)
  354. #ifdef CONFIG_MMU
  355. armv3_set_pte_ext
  356. mov r0, r0
  357. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  358. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  359. #endif /* CONFIG_MMU */
  360. mov pc, lr
  361. __CPUINIT
  362. .type __arm922_setup, #function
  363. __arm922_setup:
  364. mov r0, #0
  365. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  366. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  367. #ifdef CONFIG_MMU
  368. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  369. #endif
  370. adr r5, arm922_crval
  371. ldmia r5, {r5, r6}
  372. mrc p15, 0, r0, c1, c0 @ get control register v4
  373. bic r0, r0, r5
  374. orr r0, r0, r6
  375. mov pc, lr
  376. .size __arm922_setup, . - __arm922_setup
  377. /*
  378. * R
  379. * .RVI ZFRS BLDP WCAM
  380. * ..11 0001 ..11 0101
  381. *
  382. */
  383. .type arm922_crval, #object
  384. arm922_crval:
  385. crval clear=0x00003f3f, mmuset=0x00003135, ucset=0x00001130
  386. __INITDATA
  387. /*
  388. * Purpose : Function pointers used to access above functions - all calls
  389. * come through these
  390. */
  391. .type arm922_processor_functions, #object
  392. arm922_processor_functions:
  393. .word v4t_early_abort
  394. .word legacy_pabort
  395. .word cpu_arm922_proc_init
  396. .word cpu_arm922_proc_fin
  397. .word cpu_arm922_reset
  398. .word cpu_arm922_do_idle
  399. .word cpu_arm922_dcache_clean_area
  400. .word cpu_arm922_switch_mm
  401. .word cpu_arm922_set_pte_ext
  402. .word 0
  403. .word 0
  404. .word 0
  405. .size arm922_processor_functions, . - arm922_processor_functions
  406. .section ".rodata"
  407. .type cpu_arch_name, #object
  408. cpu_arch_name:
  409. .asciz "armv4t"
  410. .size cpu_arch_name, . - cpu_arch_name
  411. .type cpu_elf_name, #object
  412. cpu_elf_name:
  413. .asciz "v4"
  414. .size cpu_elf_name, . - cpu_elf_name
  415. .type cpu_arm922_name, #object
  416. cpu_arm922_name:
  417. .asciz "ARM922T"
  418. .size cpu_arm922_name, . - cpu_arm922_name
  419. .align
  420. .section ".proc.info.init", #alloc, #execinstr
  421. .type __arm922_proc_info,#object
  422. __arm922_proc_info:
  423. .long 0x41009220
  424. .long 0xff00fff0
  425. .long PMD_TYPE_SECT | \
  426. PMD_SECT_BUFFERABLE | \
  427. PMD_SECT_CACHEABLE | \
  428. PMD_BIT4 | \
  429. PMD_SECT_AP_WRITE | \
  430. PMD_SECT_AP_READ
  431. .long PMD_TYPE_SECT | \
  432. PMD_BIT4 | \
  433. PMD_SECT_AP_WRITE | \
  434. PMD_SECT_AP_READ
  435. b __arm922_setup
  436. .long cpu_arch_name
  437. .long cpu_elf_name
  438. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
  439. .long cpu_arm922_name
  440. .long arm922_processor_functions
  441. .long v4wbi_tlb_fns
  442. .long v4wb_user_fns
  443. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  444. .long arm922_cache_fns
  445. #else
  446. .long v4wt_cache_fns
  447. #endif
  448. .size __arm922_proc_info, . - __arm922_proc_info