proc-arm1020e.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. /*
  2. * linux/arch/arm/mm/proc-arm1020e.S: MMU functions for ARM1020
  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. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. *
  23. * These are the low level assembler for performing cache and TLB
  24. * functions on the arm1020e.
  25. */
  26. #include <linux/linkage.h>
  27. #include <linux/init.h>
  28. #include <asm/assembler.h>
  29. #include <asm/asm-offsets.h>
  30. #include <asm/hwcap.h>
  31. #include <asm/pgtable-hwdef.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/ptrace.h>
  34. #include "proc-macros.S"
  35. /*
  36. * This is the maximum size of an area which will be invalidated
  37. * using the single invalidate entry instructions. Anything larger
  38. * than this, and we go for the whole cache.
  39. *
  40. * This value should be chosen such that we choose the cheapest
  41. * alternative.
  42. */
  43. #define MAX_AREA_SIZE 32768
  44. /*
  45. * The size of one data cache line.
  46. */
  47. #define CACHE_DLINESIZE 32
  48. /*
  49. * The number of data cache segments.
  50. */
  51. #define CACHE_DSEGMENTS 16
  52. /*
  53. * The number of lines in a cache segment.
  54. */
  55. #define CACHE_DENTRIES 64
  56. /*
  57. * This is the size at which it becomes more efficient to
  58. * clean the whole cache, rather than using the individual
  59. * cache line maintenance instructions.
  60. */
  61. #define CACHE_DLIMIT 32768
  62. .text
  63. /*
  64. * cpu_arm1020e_proc_init()
  65. */
  66. ENTRY(cpu_arm1020e_proc_init)
  67. ret lr
  68. /*
  69. * cpu_arm1020e_proc_fin()
  70. */
  71. ENTRY(cpu_arm1020e_proc_fin)
  72. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  73. bic r0, r0, #0x1000 @ ...i............
  74. bic r0, r0, #0x000e @ ............wca.
  75. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  76. ret lr
  77. /*
  78. * cpu_arm1020e_reset(loc)
  79. *
  80. * Perform a soft reset of the system. Put the CPU into the
  81. * same state as it would be if it had been reset, and branch
  82. * to what would be the reset vector.
  83. *
  84. * loc: location to jump to for soft reset
  85. */
  86. .align 5
  87. .pushsection .idmap.text, "ax"
  88. ENTRY(cpu_arm1020e_reset)
  89. mov ip, #0
  90. mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
  91. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  92. #ifdef CONFIG_MMU
  93. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  94. #endif
  95. mrc p15, 0, ip, c1, c0, 0 @ ctrl register
  96. bic ip, ip, #0x000f @ ............wcam
  97. bic ip, ip, #0x1100 @ ...i...s........
  98. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  99. ret r0
  100. ENDPROC(cpu_arm1020e_reset)
  101. .popsection
  102. /*
  103. * cpu_arm1020e_do_idle()
  104. */
  105. .align 5
  106. ENTRY(cpu_arm1020e_do_idle)
  107. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  108. ret lr
  109. /* ================================= CACHE ================================ */
  110. .align 5
  111. /*
  112. * flush_icache_all()
  113. *
  114. * Unconditionally clean and invalidate the entire icache.
  115. */
  116. ENTRY(arm1020e_flush_icache_all)
  117. #ifndef CONFIG_CPU_ICACHE_DISABLE
  118. mov r0, #0
  119. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  120. #endif
  121. ret lr
  122. ENDPROC(arm1020e_flush_icache_all)
  123. /*
  124. * flush_user_cache_all()
  125. *
  126. * Invalidate all cache entries in a particular address
  127. * space.
  128. */
  129. ENTRY(arm1020e_flush_user_cache_all)
  130. /* FALLTHROUGH */
  131. /*
  132. * flush_kern_cache_all()
  133. *
  134. * Clean and invalidate the entire cache.
  135. */
  136. ENTRY(arm1020e_flush_kern_cache_all)
  137. mov r2, #VM_EXEC
  138. mov ip, #0
  139. __flush_whole_cache:
  140. #ifndef CONFIG_CPU_DCACHE_DISABLE
  141. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  142. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 16 segments
  143. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  144. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  145. subs r3, r3, #1 << 26
  146. bcs 2b @ entries 63 to 0
  147. subs r1, r1, #1 << 5
  148. bcs 1b @ segments 15 to 0
  149. #endif
  150. tst r2, #VM_EXEC
  151. #ifndef CONFIG_CPU_ICACHE_DISABLE
  152. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  153. #endif
  154. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  155. ret lr
  156. /*
  157. * flush_user_cache_range(start, end, flags)
  158. *
  159. * Invalidate a range of cache entries in the specified
  160. * address space.
  161. *
  162. * - start - start address (inclusive)
  163. * - end - end address (exclusive)
  164. * - flags - vm_flags for this space
  165. */
  166. ENTRY(arm1020e_flush_user_cache_range)
  167. mov ip, #0
  168. sub r3, r1, r0 @ calculate total size
  169. cmp r3, #CACHE_DLIMIT
  170. bhs __flush_whole_cache
  171. #ifndef CONFIG_CPU_DCACHE_DISABLE
  172. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  173. add r0, r0, #CACHE_DLINESIZE
  174. cmp r0, r1
  175. blo 1b
  176. #endif
  177. tst r2, #VM_EXEC
  178. #ifndef CONFIG_CPU_ICACHE_DISABLE
  179. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  180. #endif
  181. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  182. ret lr
  183. /*
  184. * coherent_kern_range(start, end)
  185. *
  186. * Ensure coherency between the Icache and the Dcache in the
  187. * region described by start. If you have non-snooping
  188. * Harvard caches, you need to implement this function.
  189. *
  190. * - start - virtual start address
  191. * - end - virtual end address
  192. */
  193. ENTRY(arm1020e_coherent_kern_range)
  194. /* FALLTHROUGH */
  195. /*
  196. * coherent_user_range(start, end)
  197. *
  198. * Ensure coherency between the Icache and the Dcache in the
  199. * region described by start. If you have non-snooping
  200. * Harvard caches, you need to implement this function.
  201. *
  202. * - start - virtual start address
  203. * - end - virtual end address
  204. */
  205. ENTRY(arm1020e_coherent_user_range)
  206. mov ip, #0
  207. bic r0, r0, #CACHE_DLINESIZE - 1
  208. 1:
  209. #ifndef CONFIG_CPU_DCACHE_DISABLE
  210. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  211. #endif
  212. #ifndef CONFIG_CPU_ICACHE_DISABLE
  213. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  214. #endif
  215. add r0, r0, #CACHE_DLINESIZE
  216. cmp r0, r1
  217. blo 1b
  218. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  219. mov r0, #0
  220. ret lr
  221. /*
  222. * flush_kern_dcache_area(void *addr, size_t size)
  223. *
  224. * Ensure no D cache aliasing occurs, either with itself or
  225. * the I cache
  226. *
  227. * - addr - kernel address
  228. * - size - region size
  229. */
  230. ENTRY(arm1020e_flush_kern_dcache_area)
  231. mov ip, #0
  232. #ifndef CONFIG_CPU_DCACHE_DISABLE
  233. add r1, r0, r1
  234. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  235. add r0, r0, #CACHE_DLINESIZE
  236. cmp r0, r1
  237. blo 1b
  238. #endif
  239. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  240. ret lr
  241. /*
  242. * dma_inv_range(start, end)
  243. *
  244. * Invalidate (discard) the specified virtual address range.
  245. * May not write back any entries. If 'start' or 'end'
  246. * are not cache line aligned, those lines must be written
  247. * back.
  248. *
  249. * - start - virtual start address
  250. * - end - virtual end address
  251. *
  252. * (same as v4wb)
  253. */
  254. arm1020e_dma_inv_range:
  255. mov ip, #0
  256. #ifndef CONFIG_CPU_DCACHE_DISABLE
  257. tst r0, #CACHE_DLINESIZE - 1
  258. bic r0, r0, #CACHE_DLINESIZE - 1
  259. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  260. tst r1, #CACHE_DLINESIZE - 1
  261. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  262. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  263. add r0, r0, #CACHE_DLINESIZE
  264. cmp r0, r1
  265. blo 1b
  266. #endif
  267. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  268. ret lr
  269. /*
  270. * dma_clean_range(start, end)
  271. *
  272. * Clean the specified virtual address range.
  273. *
  274. * - start - virtual start address
  275. * - end - virtual end address
  276. *
  277. * (same as v4wb)
  278. */
  279. arm1020e_dma_clean_range:
  280. mov ip, #0
  281. #ifndef CONFIG_CPU_DCACHE_DISABLE
  282. bic r0, r0, #CACHE_DLINESIZE - 1
  283. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  284. add r0, r0, #CACHE_DLINESIZE
  285. cmp r0, r1
  286. blo 1b
  287. #endif
  288. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  289. ret lr
  290. /*
  291. * dma_flush_range(start, end)
  292. *
  293. * Clean and invalidate the specified virtual address range.
  294. *
  295. * - start - virtual start address
  296. * - end - virtual end address
  297. */
  298. ENTRY(arm1020e_dma_flush_range)
  299. mov ip, #0
  300. #ifndef CONFIG_CPU_DCACHE_DISABLE
  301. bic r0, r0, #CACHE_DLINESIZE - 1
  302. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  303. add r0, r0, #CACHE_DLINESIZE
  304. cmp r0, r1
  305. blo 1b
  306. #endif
  307. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  308. ret lr
  309. /*
  310. * dma_map_area(start, size, dir)
  311. * - start - kernel virtual start address
  312. * - size - size of region
  313. * - dir - DMA direction
  314. */
  315. ENTRY(arm1020e_dma_map_area)
  316. add r1, r1, r0
  317. cmp r2, #DMA_TO_DEVICE
  318. beq arm1020e_dma_clean_range
  319. bcs arm1020e_dma_inv_range
  320. b arm1020e_dma_flush_range
  321. ENDPROC(arm1020e_dma_map_area)
  322. /*
  323. * dma_unmap_area(start, size, dir)
  324. * - start - kernel virtual start address
  325. * - size - size of region
  326. * - dir - DMA direction
  327. */
  328. ENTRY(arm1020e_dma_unmap_area)
  329. ret lr
  330. ENDPROC(arm1020e_dma_unmap_area)
  331. .globl arm1020e_flush_kern_cache_louis
  332. .equ arm1020e_flush_kern_cache_louis, arm1020e_flush_kern_cache_all
  333. @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
  334. define_cache_functions arm1020e
  335. .align 5
  336. ENTRY(cpu_arm1020e_dcache_clean_area)
  337. #ifndef CONFIG_CPU_DCACHE_DISABLE
  338. mov ip, #0
  339. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  340. add r0, r0, #CACHE_DLINESIZE
  341. subs r1, r1, #CACHE_DLINESIZE
  342. bhi 1b
  343. #endif
  344. ret lr
  345. /* =============================== PageTable ============================== */
  346. /*
  347. * cpu_arm1020e_switch_mm(pgd)
  348. *
  349. * Set the translation base pointer to be as described by pgd.
  350. *
  351. * pgd: new page tables
  352. */
  353. .align 5
  354. ENTRY(cpu_arm1020e_switch_mm)
  355. #ifdef CONFIG_MMU
  356. #ifndef CONFIG_CPU_DCACHE_DISABLE
  357. mcr p15, 0, r3, c7, c10, 4
  358. mov r1, #0xF @ 16 segments
  359. 1: mov r3, #0x3F @ 64 entries
  360. 2: mov ip, r3, LSL #26 @ shift up entry
  361. orr ip, ip, r1, LSL #5 @ shift in/up index
  362. mcr p15, 0, ip, c7, c14, 2 @ Clean & Inval DCache entry
  363. mov ip, #0
  364. subs r3, r3, #1
  365. cmp r3, #0
  366. bge 2b @ entries 3F to 0
  367. subs r1, r1, #1
  368. cmp r1, #0
  369. bge 1b @ segments 15 to 0
  370. #endif
  371. mov r1, #0
  372. #ifndef CONFIG_CPU_ICACHE_DISABLE
  373. mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
  374. #endif
  375. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  376. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  377. mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
  378. #endif
  379. ret lr
  380. /*
  381. * cpu_arm1020e_set_pte(ptep, pte)
  382. *
  383. * Set a PTE and flush it out
  384. */
  385. .align 5
  386. ENTRY(cpu_arm1020e_set_pte_ext)
  387. #ifdef CONFIG_MMU
  388. armv3_set_pte_ext
  389. mov r0, r0
  390. #ifndef CONFIG_CPU_DCACHE_DISABLE
  391. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  392. #endif
  393. #endif /* CONFIG_MMU */
  394. ret lr
  395. .type __arm1020e_setup, #function
  396. __arm1020e_setup:
  397. mov r0, #0
  398. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  399. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  400. #ifdef CONFIG_MMU
  401. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  402. #endif
  403. adr r5, arm1020e_crval
  404. ldmia r5, {r5, r6}
  405. mrc p15, 0, r0, c1, c0 @ get control register v4
  406. bic r0, r0, r5
  407. orr r0, r0, r6
  408. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  409. orr r0, r0, #0x4000 @ .R.. .... .... ....
  410. #endif
  411. ret lr
  412. .size __arm1020e_setup, . - __arm1020e_setup
  413. /*
  414. * R
  415. * .RVI ZFRS BLDP WCAM
  416. * .011 1001 ..11 0101
  417. */
  418. .type arm1020e_crval, #object
  419. arm1020e_crval:
  420. crval clear=0x00007f3f, mmuset=0x00003935, ucset=0x00001930
  421. __INITDATA
  422. @ define struct processor (see <asm/proc-fns.h> and proc-macros.S)
  423. define_processor_functions arm1020e, dabort=v4t_early_abort, pabort=legacy_pabort
  424. .section ".rodata"
  425. string cpu_arch_name, "armv5te"
  426. string cpu_elf_name, "v5"
  427. string cpu_arm1020e_name, "ARM1020E"
  428. .align
  429. .section ".proc.info.init", #alloc
  430. .type __arm1020e_proc_info,#object
  431. __arm1020e_proc_info:
  432. .long 0x4105a200 @ ARM 1020TE (Architecture v5TE)
  433. .long 0xff0ffff0
  434. .long PMD_TYPE_SECT | \
  435. PMD_BIT4 | \
  436. PMD_SECT_AP_WRITE | \
  437. PMD_SECT_AP_READ
  438. .long PMD_TYPE_SECT | \
  439. PMD_BIT4 | \
  440. PMD_SECT_AP_WRITE | \
  441. PMD_SECT_AP_READ
  442. initfn __arm1020e_setup, __arm1020e_proc_info
  443. .long cpu_arch_name
  444. .long cpu_elf_name
  445. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB | HWCAP_EDSP
  446. .long cpu_arm1020e_name
  447. .long arm1020e_processor_functions
  448. .long v4wbi_tlb_fns
  449. .long v4wb_user_fns
  450. .long arm1020e_cache_fns
  451. .size __arm1020e_proc_info, . - __arm1020e_proc_info