proc-arm1022.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. /*
  2. * linux/arch/arm/mm/proc-arm1022.S: MMU functions for ARM1022E
  3. *
  4. * Copyright (C) 2000 ARM Limited
  5. * Copyright (C) 2000 Deep Blue Solutions Ltd.
  6. * hacked for non-paged-MM by Hyok S. Choi, 2003.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. *
  14. * These are the low level assembler for performing cache and TLB
  15. * functions on the ARM1022E.
  16. */
  17. #include <linux/linkage.h>
  18. #include <linux/init.h>
  19. #include <asm/assembler.h>
  20. #include <asm/asm-offsets.h>
  21. #include <asm/hwcap.h>
  22. #include <asm/pgtable-hwdef.h>
  23. #include <asm/pgtable.h>
  24. #include <asm/ptrace.h>
  25. #include "proc-macros.S"
  26. /*
  27. * This is the maximum size of an area which will be invalidated
  28. * using the single invalidate entry instructions. Anything larger
  29. * than this, and we go for the whole cache.
  30. *
  31. * This value should be chosen such that we choose the cheapest
  32. * alternative.
  33. */
  34. #define MAX_AREA_SIZE 32768
  35. /*
  36. * The size of one data cache line.
  37. */
  38. #define CACHE_DLINESIZE 32
  39. /*
  40. * The number of data cache segments.
  41. */
  42. #define CACHE_DSEGMENTS 16
  43. /*
  44. * The number of lines in a cache segment.
  45. */
  46. #define CACHE_DENTRIES 64
  47. /*
  48. * This is the size at which it becomes more efficient to
  49. * clean the whole cache, rather than using the individual
  50. * cache line maintainence instructions.
  51. */
  52. #define CACHE_DLIMIT 32768
  53. .text
  54. /*
  55. * cpu_arm1022_proc_init()
  56. */
  57. ENTRY(cpu_arm1022_proc_init)
  58. mov pc, lr
  59. /*
  60. * cpu_arm1022_proc_fin()
  61. */
  62. ENTRY(cpu_arm1022_proc_fin)
  63. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  64. bic r0, r0, #0x1000 @ ...i............
  65. bic r0, r0, #0x000e @ ............wca.
  66. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  67. mov pc, lr
  68. /*
  69. * cpu_arm1022_reset(loc)
  70. *
  71. * Perform a soft reset of the system. Put the CPU into the
  72. * same state as it would be if it had been reset, and branch
  73. * to what would be the reset vector.
  74. *
  75. * loc: location to jump to for soft reset
  76. */
  77. .align 5
  78. ENTRY(cpu_arm1022_reset)
  79. mov ip, #0
  80. mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
  81. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  82. #ifdef CONFIG_MMU
  83. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  84. #endif
  85. mrc p15, 0, ip, c1, c0, 0 @ ctrl register
  86. bic ip, ip, #0x000f @ ............wcam
  87. bic ip, ip, #0x1100 @ ...i...s........
  88. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  89. mov pc, r0
  90. /*
  91. * cpu_arm1022_do_idle()
  92. */
  93. .align 5
  94. ENTRY(cpu_arm1022_do_idle)
  95. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  96. mov pc, lr
  97. /* ================================= CACHE ================================ */
  98. .align 5
  99. /*
  100. * flush_user_cache_all()
  101. *
  102. * Invalidate all cache entries in a particular address
  103. * space.
  104. */
  105. ENTRY(arm1022_flush_user_cache_all)
  106. /* FALLTHROUGH */
  107. /*
  108. * flush_kern_cache_all()
  109. *
  110. * Clean and invalidate the entire cache.
  111. */
  112. ENTRY(arm1022_flush_kern_cache_all)
  113. mov r2, #VM_EXEC
  114. mov ip, #0
  115. __flush_whole_cache:
  116. #ifndef CONFIG_CPU_DCACHE_DISABLE
  117. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 16 segments
  118. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  119. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  120. subs r3, r3, #1 << 26
  121. bcs 2b @ entries 63 to 0
  122. subs r1, r1, #1 << 5
  123. bcs 1b @ segments 15 to 0
  124. #endif
  125. tst r2, #VM_EXEC
  126. #ifndef CONFIG_CPU_ICACHE_DISABLE
  127. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  128. #endif
  129. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  130. mov pc, lr
  131. /*
  132. * flush_user_cache_range(start, end, flags)
  133. *
  134. * Invalidate a range of cache entries in the specified
  135. * address space.
  136. *
  137. * - start - start address (inclusive)
  138. * - end - end address (exclusive)
  139. * - flags - vm_flags for this space
  140. */
  141. ENTRY(arm1022_flush_user_cache_range)
  142. mov ip, #0
  143. sub r3, r1, r0 @ calculate total size
  144. cmp r3, #CACHE_DLIMIT
  145. bhs __flush_whole_cache
  146. #ifndef CONFIG_CPU_DCACHE_DISABLE
  147. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  148. add r0, r0, #CACHE_DLINESIZE
  149. cmp r0, r1
  150. blo 1b
  151. #endif
  152. tst r2, #VM_EXEC
  153. #ifndef CONFIG_CPU_ICACHE_DISABLE
  154. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  155. #endif
  156. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  157. mov pc, lr
  158. /*
  159. * coherent_kern_range(start, end)
  160. *
  161. * Ensure coherency between the Icache and the Dcache in the
  162. * region described by start. If you have non-snooping
  163. * Harvard caches, you need to implement this function.
  164. *
  165. * - start - virtual start address
  166. * - end - virtual end address
  167. */
  168. ENTRY(arm1022_coherent_kern_range)
  169. /* FALLTHROUGH */
  170. /*
  171. * coherent_user_range(start, end)
  172. *
  173. * Ensure coherency between the Icache and the Dcache in the
  174. * region described by start. If you have non-snooping
  175. * Harvard caches, you need to implement this function.
  176. *
  177. * - start - virtual start address
  178. * - end - virtual end address
  179. */
  180. ENTRY(arm1022_coherent_user_range)
  181. mov ip, #0
  182. bic r0, r0, #CACHE_DLINESIZE - 1
  183. 1:
  184. #ifndef CONFIG_CPU_DCACHE_DISABLE
  185. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  186. #endif
  187. #ifndef CONFIG_CPU_ICACHE_DISABLE
  188. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  189. #endif
  190. add r0, r0, #CACHE_DLINESIZE
  191. cmp r0, r1
  192. blo 1b
  193. mcr p15, 0, ip, 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(arm1022_flush_kern_dcache_area)
  205. mov ip, #0
  206. #ifndef CONFIG_CPU_DCACHE_DISABLE
  207. add r1, r0, r1
  208. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  209. add r0, r0, #CACHE_DLINESIZE
  210. cmp r0, r1
  211. blo 1b
  212. #endif
  213. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  214. mov pc, lr
  215. /*
  216. * dma_inv_range(start, end)
  217. *
  218. * Invalidate (discard) the specified virtual address range.
  219. * May not write back any entries. If 'start' or 'end'
  220. * are not cache line aligned, those lines must be written
  221. * back.
  222. *
  223. * - start - virtual start address
  224. * - end - virtual end address
  225. *
  226. * (same as v4wb)
  227. */
  228. arm1022_dma_inv_range:
  229. mov ip, #0
  230. #ifndef CONFIG_CPU_DCACHE_DISABLE
  231. tst r0, #CACHE_DLINESIZE - 1
  232. bic r0, r0, #CACHE_DLINESIZE - 1
  233. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  234. tst r1, #CACHE_DLINESIZE - 1
  235. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  236. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  237. add r0, r0, #CACHE_DLINESIZE
  238. cmp r0, r1
  239. blo 1b
  240. #endif
  241. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  242. mov pc, 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. arm1022_dma_clean_range:
  254. mov ip, #0
  255. #ifndef CONFIG_CPU_DCACHE_DISABLE
  256. bic r0, r0, #CACHE_DLINESIZE - 1
  257. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  258. add r0, r0, #CACHE_DLINESIZE
  259. cmp r0, r1
  260. blo 1b
  261. #endif
  262. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  263. mov pc, lr
  264. /*
  265. * dma_flush_range(start, end)
  266. *
  267. * Clean and invalidate the specified virtual address range.
  268. *
  269. * - start - virtual start address
  270. * - end - virtual end address
  271. */
  272. ENTRY(arm1022_dma_flush_range)
  273. mov ip, #0
  274. #ifndef CONFIG_CPU_DCACHE_DISABLE
  275. bic r0, r0, #CACHE_DLINESIZE - 1
  276. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  277. add r0, r0, #CACHE_DLINESIZE
  278. cmp r0, r1
  279. blo 1b
  280. #endif
  281. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  282. mov pc, lr
  283. /*
  284. * dma_map_area(start, size, dir)
  285. * - start - kernel virtual start address
  286. * - size - size of region
  287. * - dir - DMA direction
  288. */
  289. ENTRY(arm1022_dma_map_area)
  290. add r1, r1, r0
  291. cmp r2, #DMA_TO_DEVICE
  292. beq arm1022_dma_clean_range
  293. bcs arm1022_dma_inv_range
  294. b arm1022_dma_flush_range
  295. ENDPROC(arm1022_dma_map_area)
  296. /*
  297. * dma_unmap_area(start, size, dir)
  298. * - start - kernel virtual start address
  299. * - size - size of region
  300. * - dir - DMA direction
  301. */
  302. ENTRY(arm1022_dma_unmap_area)
  303. mov pc, lr
  304. ENDPROC(arm1022_dma_unmap_area)
  305. ENTRY(arm1022_cache_fns)
  306. .long arm1022_flush_kern_cache_all
  307. .long arm1022_flush_user_cache_all
  308. .long arm1022_flush_user_cache_range
  309. .long arm1022_coherent_kern_range
  310. .long arm1022_coherent_user_range
  311. .long arm1022_flush_kern_dcache_area
  312. .long arm1022_dma_map_area
  313. .long arm1022_dma_unmap_area
  314. .long arm1022_dma_flush_range
  315. .align 5
  316. ENTRY(cpu_arm1022_dcache_clean_area)
  317. #ifndef CONFIG_CPU_DCACHE_DISABLE
  318. mov ip, #0
  319. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  320. add r0, r0, #CACHE_DLINESIZE
  321. subs r1, r1, #CACHE_DLINESIZE
  322. bhi 1b
  323. #endif
  324. mov pc, lr
  325. /* =============================== PageTable ============================== */
  326. /*
  327. * cpu_arm1022_switch_mm(pgd)
  328. *
  329. * Set the translation base pointer to be as described by pgd.
  330. *
  331. * pgd: new page tables
  332. */
  333. .align 5
  334. ENTRY(cpu_arm1022_switch_mm)
  335. #ifdef CONFIG_MMU
  336. #ifndef CONFIG_CPU_DCACHE_DISABLE
  337. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 16 segments
  338. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  339. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  340. subs r3, r3, #1 << 26
  341. bcs 2b @ entries 63 to 0
  342. subs r1, r1, #1 << 5
  343. bcs 1b @ segments 15 to 0
  344. #endif
  345. mov r1, #0
  346. #ifndef CONFIG_CPU_ICACHE_DISABLE
  347. mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
  348. #endif
  349. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  350. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  351. mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
  352. #endif
  353. mov pc, lr
  354. /*
  355. * cpu_arm1022_set_pte_ext(ptep, pte, ext)
  356. *
  357. * Set a PTE and flush it out
  358. */
  359. .align 5
  360. ENTRY(cpu_arm1022_set_pte_ext)
  361. #ifdef CONFIG_MMU
  362. armv3_set_pte_ext
  363. mov r0, r0
  364. #ifndef CONFIG_CPU_DCACHE_DISABLE
  365. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  366. #endif
  367. #endif /* CONFIG_MMU */
  368. mov pc, lr
  369. __INIT
  370. .type __arm1022_setup, #function
  371. __arm1022_setup:
  372. mov r0, #0
  373. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  374. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  375. #ifdef CONFIG_MMU
  376. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  377. #endif
  378. adr r5, arm1022_crval
  379. ldmia r5, {r5, r6}
  380. mrc p15, 0, r0, c1, c0 @ get control register v4
  381. bic r0, r0, r5
  382. orr r0, r0, r6
  383. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  384. orr r0, r0, #0x4000 @ .R..............
  385. #endif
  386. mov pc, lr
  387. .size __arm1022_setup, . - __arm1022_setup
  388. /*
  389. * R
  390. * .RVI ZFRS BLDP WCAM
  391. * .011 1001 ..11 0101
  392. *
  393. */
  394. .type arm1022_crval, #object
  395. arm1022_crval:
  396. crval clear=0x00007f3f, mmuset=0x00003935, ucset=0x00001930
  397. __INITDATA
  398. /*
  399. * Purpose : Function pointers used to access above functions - all calls
  400. * come through these
  401. */
  402. .type arm1022_processor_functions, #object
  403. arm1022_processor_functions:
  404. .word v4t_early_abort
  405. .word legacy_pabort
  406. .word cpu_arm1022_proc_init
  407. .word cpu_arm1022_proc_fin
  408. .word cpu_arm1022_reset
  409. .word cpu_arm1022_do_idle
  410. .word cpu_arm1022_dcache_clean_area
  411. .word cpu_arm1022_switch_mm
  412. .word cpu_arm1022_set_pte_ext
  413. .size arm1022_processor_functions, . - arm1022_processor_functions
  414. .section ".rodata"
  415. .type cpu_arch_name, #object
  416. cpu_arch_name:
  417. .asciz "armv5te"
  418. .size cpu_arch_name, . - cpu_arch_name
  419. .type cpu_elf_name, #object
  420. cpu_elf_name:
  421. .asciz "v5"
  422. .size cpu_elf_name, . - cpu_elf_name
  423. .type cpu_arm1022_name, #object
  424. cpu_arm1022_name:
  425. .asciz "ARM1022"
  426. .size cpu_arm1022_name, . - cpu_arm1022_name
  427. .align
  428. .section ".proc.info.init", #alloc, #execinstr
  429. .type __arm1022_proc_info,#object
  430. __arm1022_proc_info:
  431. .long 0x4105a220 @ ARM 1022E (v5TE)
  432. .long 0xff0ffff0
  433. .long PMD_TYPE_SECT | \
  434. PMD_BIT4 | \
  435. PMD_SECT_AP_WRITE | \
  436. PMD_SECT_AP_READ
  437. .long PMD_TYPE_SECT | \
  438. PMD_BIT4 | \
  439. PMD_SECT_AP_WRITE | \
  440. PMD_SECT_AP_READ
  441. b __arm1022_setup
  442. .long cpu_arch_name
  443. .long cpu_elf_name
  444. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB | HWCAP_EDSP
  445. .long cpu_arm1022_name
  446. .long arm1022_processor_functions
  447. .long v4wbi_tlb_fns
  448. .long v4wb_user_fns
  449. .long arm1022_cache_fns
  450. .size __arm1022_proc_info, . - __arm1022_proc_info