proc-arm922.S 11 KB

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