proc-arm1020.S 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. /*
  2. * linux/arch/arm/mm/proc-arm1020.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 arm1020.
  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_arm1020_proc_init()
  65. */
  66. ENTRY(cpu_arm1020_proc_init)
  67. ret lr
  68. /*
  69. * cpu_arm1020_proc_fin()
  70. */
  71. ENTRY(cpu_arm1020_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_arm1020_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_arm1020_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_arm1020_reset)
  101. .popsection
  102. /*
  103. * cpu_arm1020_do_idle()
  104. */
  105. .align 5
  106. ENTRY(cpu_arm1020_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(arm1020_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(arm1020_flush_icache_all)
  123. /*
  124. * flush_user_cache_all()
  125. *
  126. * Invalidate all cache entries in a particular address
  127. * space.
  128. */
  129. ENTRY(arm1020_flush_user_cache_all)
  130. /* FALLTHROUGH */
  131. /*
  132. * flush_kern_cache_all()
  133. *
  134. * Clean and invalidate the entire cache.
  135. */
  136. ENTRY(arm1020_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. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  146. subs r3, r3, #1 << 26
  147. bcs 2b @ entries 63 to 0
  148. subs r1, r1, #1 << 5
  149. bcs 1b @ segments 15 to 0
  150. #endif
  151. tst r2, #VM_EXEC
  152. #ifndef CONFIG_CPU_ICACHE_DISABLE
  153. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  154. #endif
  155. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  156. ret lr
  157. /*
  158. * flush_user_cache_range(start, end, flags)
  159. *
  160. * Invalidate a range of cache entries in the specified
  161. * address space.
  162. *
  163. * - start - start address (inclusive)
  164. * - end - end address (exclusive)
  165. * - flags - vm_flags for this space
  166. */
  167. ENTRY(arm1020_flush_user_cache_range)
  168. mov ip, #0
  169. sub r3, r1, r0 @ calculate total size
  170. cmp r3, #CACHE_DLIMIT
  171. bhs __flush_whole_cache
  172. #ifndef CONFIG_CPU_DCACHE_DISABLE
  173. mcr p15, 0, ip, c7, c10, 4
  174. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  175. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  176. add r0, r0, #CACHE_DLINESIZE
  177. cmp r0, r1
  178. blo 1b
  179. #endif
  180. tst r2, #VM_EXEC
  181. #ifndef CONFIG_CPU_ICACHE_DISABLE
  182. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  183. #endif
  184. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  185. ret lr
  186. /*
  187. * coherent_kern_range(start, end)
  188. *
  189. * Ensure coherency between the Icache and the Dcache in the
  190. * region described by start. If you have non-snooping
  191. * Harvard caches, you need to implement this function.
  192. *
  193. * - start - virtual start address
  194. * - end - virtual end address
  195. */
  196. ENTRY(arm1020_coherent_kern_range)
  197. /* FALLTRHOUGH */
  198. /*
  199. * coherent_user_range(start, end)
  200. *
  201. * Ensure coherency between the Icache and the Dcache in the
  202. * region described by start. If you have non-snooping
  203. * Harvard caches, you need to implement this function.
  204. *
  205. * - start - virtual start address
  206. * - end - virtual end address
  207. */
  208. ENTRY(arm1020_coherent_user_range)
  209. mov ip, #0
  210. bic r0, r0, #CACHE_DLINESIZE - 1
  211. mcr p15, 0, ip, c7, c10, 4
  212. 1:
  213. #ifndef CONFIG_CPU_DCACHE_DISABLE
  214. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  215. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  216. #endif
  217. #ifndef CONFIG_CPU_ICACHE_DISABLE
  218. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  219. #endif
  220. add r0, r0, #CACHE_DLINESIZE
  221. cmp r0, r1
  222. blo 1b
  223. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  224. mov r0, #0
  225. ret lr
  226. /*
  227. * flush_kern_dcache_area(void *addr, size_t size)
  228. *
  229. * Ensure no D cache aliasing occurs, either with itself or
  230. * the I cache
  231. *
  232. * - addr - kernel address
  233. * - size - region size
  234. */
  235. ENTRY(arm1020_flush_kern_dcache_area)
  236. mov ip, #0
  237. #ifndef CONFIG_CPU_DCACHE_DISABLE
  238. add r1, r0, r1
  239. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  240. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  241. add r0, r0, #CACHE_DLINESIZE
  242. cmp r0, r1
  243. blo 1b
  244. #endif
  245. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  246. ret lr
  247. /*
  248. * dma_inv_range(start, end)
  249. *
  250. * Invalidate (discard) the specified virtual address range.
  251. * May not write back any entries. If 'start' or 'end'
  252. * are not cache line aligned, those lines must be written
  253. * back.
  254. *
  255. * - start - virtual start address
  256. * - end - virtual end address
  257. *
  258. * (same as v4wb)
  259. */
  260. arm1020_dma_inv_range:
  261. mov ip, #0
  262. #ifndef CONFIG_CPU_DCACHE_DISABLE
  263. tst r0, #CACHE_DLINESIZE - 1
  264. bic r0, r0, #CACHE_DLINESIZE - 1
  265. mcrne p15, 0, ip, c7, c10, 4
  266. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  267. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  268. tst r1, #CACHE_DLINESIZE - 1
  269. mcrne p15, 0, ip, c7, c10, 4
  270. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  271. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  272. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  273. add r0, r0, #CACHE_DLINESIZE
  274. cmp r0, r1
  275. blo 1b
  276. #endif
  277. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  278. ret lr
  279. /*
  280. * dma_clean_range(start, end)
  281. *
  282. * Clean the specified virtual address range.
  283. *
  284. * - start - virtual start address
  285. * - end - virtual end address
  286. *
  287. * (same as v4wb)
  288. */
  289. arm1020_dma_clean_range:
  290. mov ip, #0
  291. #ifndef CONFIG_CPU_DCACHE_DISABLE
  292. bic r0, r0, #CACHE_DLINESIZE - 1
  293. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  294. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  295. add r0, r0, #CACHE_DLINESIZE
  296. cmp r0, r1
  297. blo 1b
  298. #endif
  299. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  300. ret lr
  301. /*
  302. * dma_flush_range(start, end)
  303. *
  304. * Clean and invalidate the specified virtual address range.
  305. *
  306. * - start - virtual start address
  307. * - end - virtual end address
  308. */
  309. ENTRY(arm1020_dma_flush_range)
  310. mov ip, #0
  311. #ifndef CONFIG_CPU_DCACHE_DISABLE
  312. bic r0, r0, #CACHE_DLINESIZE - 1
  313. mcr p15, 0, ip, c7, c10, 4
  314. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  315. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  316. add r0, r0, #CACHE_DLINESIZE
  317. cmp r0, r1
  318. blo 1b
  319. #endif
  320. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  321. ret lr
  322. /*
  323. * dma_map_area(start, size, dir)
  324. * - start - kernel virtual start address
  325. * - size - size of region
  326. * - dir - DMA direction
  327. */
  328. ENTRY(arm1020_dma_map_area)
  329. add r1, r1, r0
  330. cmp r2, #DMA_TO_DEVICE
  331. beq arm1020_dma_clean_range
  332. bcs arm1020_dma_inv_range
  333. b arm1020_dma_flush_range
  334. ENDPROC(arm1020_dma_map_area)
  335. /*
  336. * dma_unmap_area(start, size, dir)
  337. * - start - kernel virtual start address
  338. * - size - size of region
  339. * - dir - DMA direction
  340. */
  341. ENTRY(arm1020_dma_unmap_area)
  342. ret lr
  343. ENDPROC(arm1020_dma_unmap_area)
  344. .globl arm1020_flush_kern_cache_louis
  345. .equ arm1020_flush_kern_cache_louis, arm1020_flush_kern_cache_all
  346. @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
  347. define_cache_functions arm1020
  348. .align 5
  349. ENTRY(cpu_arm1020_dcache_clean_area)
  350. #ifndef CONFIG_CPU_DCACHE_DISABLE
  351. mov ip, #0
  352. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  353. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  354. add r0, r0, #CACHE_DLINESIZE
  355. subs r1, r1, #CACHE_DLINESIZE
  356. bhi 1b
  357. #endif
  358. ret lr
  359. /* =============================== PageTable ============================== */
  360. /*
  361. * cpu_arm1020_switch_mm(pgd)
  362. *
  363. * Set the translation base pointer to be as described by pgd.
  364. *
  365. * pgd: new page tables
  366. */
  367. .align 5
  368. ENTRY(cpu_arm1020_switch_mm)
  369. #ifdef CONFIG_MMU
  370. #ifndef CONFIG_CPU_DCACHE_DISABLE
  371. mcr p15, 0, r3, c7, c10, 4
  372. mov r1, #0xF @ 16 segments
  373. 1: mov r3, #0x3F @ 64 entries
  374. 2: mov ip, r3, LSL #26 @ shift up entry
  375. orr ip, ip, r1, LSL #5 @ shift in/up index
  376. mcr p15, 0, ip, c7, c14, 2 @ Clean & Inval DCache entry
  377. mov ip, #0
  378. mcr p15, 0, ip, c7, c10, 4
  379. subs r3, r3, #1
  380. cmp r3, #0
  381. bge 2b @ entries 3F to 0
  382. subs r1, r1, #1
  383. cmp r1, #0
  384. bge 1b @ segments 15 to 0
  385. #endif
  386. mov r1, #0
  387. #ifndef CONFIG_CPU_ICACHE_DISABLE
  388. mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
  389. #endif
  390. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  391. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  392. mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
  393. #endif /* CONFIG_MMU */
  394. ret lr
  395. /*
  396. * cpu_arm1020_set_pte(ptep, pte)
  397. *
  398. * Set a PTE and flush it out
  399. */
  400. .align 5
  401. ENTRY(cpu_arm1020_set_pte_ext)
  402. #ifdef CONFIG_MMU
  403. armv3_set_pte_ext
  404. mov r0, r0
  405. #ifndef CONFIG_CPU_DCACHE_DISABLE
  406. mcr p15, 0, r0, c7, c10, 4
  407. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  408. #endif
  409. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  410. #endif /* CONFIG_MMU */
  411. ret lr
  412. .type __arm1020_setup, #function
  413. __arm1020_setup:
  414. mov r0, #0
  415. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  416. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  417. #ifdef CONFIG_MMU
  418. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  419. #endif
  420. adr r5, arm1020_crval
  421. ldmia r5, {r5, r6}
  422. mrc p15, 0, r0, c1, c0 @ get control register v4
  423. bic r0, r0, r5
  424. orr r0, r0, r6
  425. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  426. orr r0, r0, #0x4000 @ .R.. .... .... ....
  427. #endif
  428. ret lr
  429. .size __arm1020_setup, . - __arm1020_setup
  430. /*
  431. * R
  432. * .RVI ZFRS BLDP WCAM
  433. * .011 1001 ..11 0101
  434. */
  435. .type arm1020_crval, #object
  436. arm1020_crval:
  437. crval clear=0x0000593f, mmuset=0x00003935, ucset=0x00001930
  438. __INITDATA
  439. @ define struct processor (see <asm/proc-fns.h> and proc-macros.S)
  440. define_processor_functions arm1020, dabort=v4t_early_abort, pabort=legacy_pabort
  441. .section ".rodata"
  442. string cpu_arch_name, "armv5t"
  443. string cpu_elf_name, "v5"
  444. .type cpu_arm1020_name, #object
  445. cpu_arm1020_name:
  446. .ascii "ARM1020"
  447. #ifndef CONFIG_CPU_ICACHE_DISABLE
  448. .ascii "i"
  449. #endif
  450. #ifndef CONFIG_CPU_DCACHE_DISABLE
  451. .ascii "d"
  452. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  453. .ascii "(wt)"
  454. #else
  455. .ascii "(wb)"
  456. #endif
  457. #endif
  458. #ifndef CONFIG_CPU_BPREDICT_DISABLE
  459. .ascii "B"
  460. #endif
  461. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  462. .ascii "RR"
  463. #endif
  464. .ascii "\0"
  465. .size cpu_arm1020_name, . - cpu_arm1020_name
  466. .align
  467. .section ".proc.info.init", #alloc
  468. .type __arm1020_proc_info,#object
  469. __arm1020_proc_info:
  470. .long 0x4104a200 @ ARM 1020T (Architecture v5T)
  471. .long 0xff0ffff0
  472. .long PMD_TYPE_SECT | \
  473. PMD_SECT_AP_WRITE | \
  474. PMD_SECT_AP_READ
  475. .long PMD_TYPE_SECT | \
  476. PMD_SECT_AP_WRITE | \
  477. PMD_SECT_AP_READ
  478. initfn __arm1020_setup, __arm1020_proc_info
  479. .long cpu_arch_name
  480. .long cpu_elf_name
  481. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
  482. .long cpu_arm1020_name
  483. .long arm1020_processor_functions
  484. .long v4wbi_tlb_fns
  485. .long v4wb_user_fns
  486. .long arm1020_cache_fns
  487. .size __arm1020_proc_info, . - __arm1020_proc_info