proc-arm1020.S 13 KB

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