proc-arm1020.S 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. *
  22. * These are the low level assembler for performing cache and TLB
  23. * functions on the arm1020.
  24. *
  25. * CONFIG_CPU_ARM1020_CPU_IDLE -> nohlt
  26. */
  27. #include <linux/linkage.h>
  28. #include <linux/config.h>
  29. #include <linux/init.h>
  30. #include <asm/assembler.h>
  31. #include <asm/asm-offsets.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/procinfo.h>
  34. #include <asm/ptrace.h>
  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 maintainence instructions.
  60. */
  61. #define CACHE_DLIMIT 32768
  62. .text
  63. /*
  64. * cpu_arm1020_proc_init()
  65. */
  66. ENTRY(cpu_arm1020_proc_init)
  67. mov pc, lr
  68. /*
  69. * cpu_arm1020_proc_fin()
  70. */
  71. ENTRY(cpu_arm1020_proc_fin)
  72. stmfd sp!, {lr}
  73. mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
  74. msr cpsr_c, ip
  75. bl arm1020_flush_kern_cache_all
  76. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  77. bic r0, r0, #0x1000 @ ...i............
  78. bic r0, r0, #0x000e @ ............wca.
  79. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  80. ldmfd sp!, {pc}
  81. /*
  82. * cpu_arm1020_reset(loc)
  83. *
  84. * Perform a soft reset of the system. Put the CPU into the
  85. * same state as it would be if it had been reset, and branch
  86. * to what would be the reset vector.
  87. *
  88. * loc: location to jump to for soft reset
  89. */
  90. .align 5
  91. ENTRY(cpu_arm1020_reset)
  92. mov ip, #0
  93. mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
  94. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  95. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  96. mrc p15, 0, ip, c1, c0, 0 @ ctrl register
  97. bic ip, ip, #0x000f @ ............wcam
  98. bic ip, ip, #0x1100 @ ...i...s........
  99. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  100. mov pc, r0
  101. /*
  102. * cpu_arm1020_do_idle()
  103. */
  104. .align 5
  105. ENTRY(cpu_arm1020_do_idle)
  106. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  107. mov pc, lr
  108. /* ================================= CACHE ================================ */
  109. .align 5
  110. /*
  111. * flush_user_cache_all()
  112. *
  113. * Invalidate all cache entries in a particular address
  114. * space.
  115. */
  116. ENTRY(arm1020_flush_user_cache_all)
  117. /* FALLTHROUGH */
  118. /*
  119. * flush_kern_cache_all()
  120. *
  121. * Clean and invalidate the entire cache.
  122. */
  123. ENTRY(arm1020_flush_kern_cache_all)
  124. mov r2, #VM_EXEC
  125. mov ip, #0
  126. __flush_whole_cache:
  127. #ifndef CONFIG_CPU_DCACHE_DISABLE
  128. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  129. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 16 segments
  130. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  131. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  132. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  133. subs r3, r3, #1 << 26
  134. bcs 2b @ entries 63 to 0
  135. subs r1, r1, #1 << 5
  136. bcs 1b @ segments 15 to 0
  137. #endif
  138. tst r2, #VM_EXEC
  139. #ifndef CONFIG_CPU_ICACHE_DISABLE
  140. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  141. #endif
  142. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  143. mov pc, lr
  144. /*
  145. * flush_user_cache_range(start, end, flags)
  146. *
  147. * Invalidate a range of cache entries in the specified
  148. * address space.
  149. *
  150. * - start - start address (inclusive)
  151. * - end - end address (exclusive)
  152. * - flags - vm_flags for this space
  153. */
  154. ENTRY(arm1020_flush_user_cache_range)
  155. mov ip, #0
  156. sub r3, r1, r0 @ calculate total size
  157. cmp r3, #CACHE_DLIMIT
  158. bhs __flush_whole_cache
  159. #ifndef CONFIG_CPU_DCACHE_DISABLE
  160. mcr p15, 0, ip, c7, c10, 4
  161. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  162. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  163. add r0, r0, #CACHE_DLINESIZE
  164. cmp r0, r1
  165. blo 1b
  166. #endif
  167. tst r2, #VM_EXEC
  168. #ifndef CONFIG_CPU_ICACHE_DISABLE
  169. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  170. #endif
  171. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  172. mov pc, lr
  173. /*
  174. * coherent_kern_range(start, end)
  175. *
  176. * Ensure coherency between the Icache and the Dcache in the
  177. * region described by start. If you have non-snooping
  178. * Harvard caches, you need to implement this function.
  179. *
  180. * - start - virtual start address
  181. * - end - virtual end address
  182. */
  183. ENTRY(arm1020_coherent_kern_range)
  184. /* FALLTRHOUGH */
  185. /*
  186. * coherent_user_range(start, end)
  187. *
  188. * Ensure coherency between the Icache and the Dcache in the
  189. * region described by start. If you have non-snooping
  190. * Harvard caches, you need to implement this function.
  191. *
  192. * - start - virtual start address
  193. * - end - virtual end address
  194. */
  195. ENTRY(arm1020_coherent_user_range)
  196. mov ip, #0
  197. bic r0, r0, #CACHE_DLINESIZE - 1
  198. mcr p15, 0, ip, c7, c10, 4
  199. 1:
  200. #ifndef CONFIG_CPU_DCACHE_DISABLE
  201. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  202. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  203. #endif
  204. #ifndef CONFIG_CPU_ICACHE_DISABLE
  205. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  206. #endif
  207. add r0, r0, #CACHE_DLINESIZE
  208. cmp r0, r1
  209. blo 1b
  210. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  211. mov pc, lr
  212. /*
  213. * flush_kern_dcache_page(void *page)
  214. *
  215. * Ensure no D cache aliasing occurs, either with itself or
  216. * the I cache
  217. *
  218. * - page - page aligned address
  219. */
  220. ENTRY(arm1020_flush_kern_dcache_page)
  221. mov ip, #0
  222. #ifndef CONFIG_CPU_DCACHE_DISABLE
  223. add r1, r0, #PAGE_SZ
  224. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  225. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  226. add r0, r0, #CACHE_DLINESIZE
  227. cmp r0, r1
  228. blo 1b
  229. #endif
  230. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  231. mov pc, lr
  232. /*
  233. * dma_inv_range(start, end)
  234. *
  235. * Invalidate (discard) the specified virtual address range.
  236. * May not write back any entries. If 'start' or 'end'
  237. * are not cache line aligned, those lines must be written
  238. * back.
  239. *
  240. * - start - virtual start address
  241. * - end - virtual end address
  242. *
  243. * (same as v4wb)
  244. */
  245. ENTRY(arm1020_dma_inv_range)
  246. mov ip, #0
  247. #ifndef CONFIG_CPU_DCACHE_DISABLE
  248. tst r0, #CACHE_DLINESIZE - 1
  249. bic r0, r0, #CACHE_DLINESIZE - 1
  250. mcrne p15, 0, ip, c7, c10, 4
  251. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  252. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  253. tst r1, #CACHE_DLINESIZE - 1
  254. mcrne p15, 0, ip, c7, c10, 4
  255. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  256. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  257. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate 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_clean_range(start, end)
  266. *
  267. * Clean the specified virtual address range.
  268. *
  269. * - start - virtual start address
  270. * - end - virtual end address
  271. *
  272. * (same as v4wb)
  273. */
  274. ENTRY(arm1020_dma_clean_range)
  275. mov ip, #0
  276. #ifndef CONFIG_CPU_DCACHE_DISABLE
  277. bic r0, r0, #CACHE_DLINESIZE - 1
  278. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  279. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  280. add r0, r0, #CACHE_DLINESIZE
  281. cmp r0, r1
  282. blo 1b
  283. #endif
  284. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  285. mov pc, lr
  286. /*
  287. * dma_flush_range(start, end)
  288. *
  289. * Clean and invalidate the specified virtual address range.
  290. *
  291. * - start - virtual start address
  292. * - end - virtual end address
  293. */
  294. ENTRY(arm1020_dma_flush_range)
  295. mov ip, #0
  296. #ifndef CONFIG_CPU_DCACHE_DISABLE
  297. bic r0, r0, #CACHE_DLINESIZE - 1
  298. mcr p15, 0, ip, c7, c10, 4
  299. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  300. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  301. add r0, r0, #CACHE_DLINESIZE
  302. cmp r0, r1
  303. blo 1b
  304. #endif
  305. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  306. mov pc, lr
  307. ENTRY(arm1020_cache_fns)
  308. .long arm1020_flush_kern_cache_all
  309. .long arm1020_flush_user_cache_all
  310. .long arm1020_flush_user_cache_range
  311. .long arm1020_coherent_kern_range
  312. .long arm1020_coherent_user_range
  313. .long arm1020_flush_kern_dcache_page
  314. .long arm1020_dma_inv_range
  315. .long arm1020_dma_clean_range
  316. .long arm1020_dma_flush_range
  317. .align 5
  318. ENTRY(cpu_arm1020_dcache_clean_area)
  319. #ifndef CONFIG_CPU_DCACHE_DISABLE
  320. mov ip, #0
  321. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  322. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  323. add r0, r0, #CACHE_DLINESIZE
  324. subs r1, r1, #CACHE_DLINESIZE
  325. bhi 1b
  326. #endif
  327. mov pc, lr
  328. /* =============================== PageTable ============================== */
  329. /*
  330. * cpu_arm1020_switch_mm(pgd)
  331. *
  332. * Set the translation base pointer to be as described by pgd.
  333. *
  334. * pgd: new page tables
  335. */
  336. .align 5
  337. ENTRY(cpu_arm1020_switch_mm)
  338. #ifndef CONFIG_CPU_DCACHE_DISABLE
  339. mcr p15, 0, r3, c7, c10, 4
  340. mov r1, #0xF @ 16 segments
  341. 1: mov r3, #0x3F @ 64 entries
  342. 2: mov ip, r3, LSL #26 @ shift up entry
  343. orr ip, ip, r1, LSL #5 @ shift in/up index
  344. mcr p15, 0, ip, c7, c14, 2 @ Clean & Inval DCache entry
  345. mov ip, #0
  346. mcr p15, 0, ip, c7, c10, 4
  347. subs r3, r3, #1
  348. cmp r3, #0
  349. bge 2b @ entries 3F to 0
  350. subs r1, r1, #1
  351. cmp r1, #0
  352. bge 1b @ segments 15 to 0
  353. #endif
  354. mov r1, #0
  355. #ifndef CONFIG_CPU_ICACHE_DISABLE
  356. mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
  357. #endif
  358. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  359. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  360. mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
  361. mov pc, lr
  362. /*
  363. * cpu_arm1020_set_pte(ptep, pte)
  364. *
  365. * Set a PTE and flush it out
  366. */
  367. .align 5
  368. ENTRY(cpu_arm1020_set_pte)
  369. str r1, [r0], #-2048 @ linux version
  370. eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
  371. bic r2, r1, #PTE_SMALL_AP_MASK
  372. bic r2, r2, #PTE_TYPE_MASK
  373. orr r2, r2, #PTE_TYPE_SMALL
  374. tst r1, #L_PTE_USER @ User?
  375. orrne r2, r2, #PTE_SMALL_AP_URO_SRW
  376. tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
  377. orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
  378. tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
  379. movne r2, #0
  380. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  381. eor r3, r1, #0x0a @ C & small page?
  382. tst r3, #0x0b
  383. biceq r2, r2, #4
  384. #endif
  385. str r2, [r0] @ hardware version
  386. mov r0, r0
  387. #ifndef CONFIG_CPU_DCACHE_DISABLE
  388. mcr p15, 0, r0, c7, c10, 4
  389. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  390. #endif
  391. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  392. mov pc, lr
  393. __INIT
  394. .type __arm1020_setup, #function
  395. __arm1020_setup:
  396. mov r0, #0
  397. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  398. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  399. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  400. mrc p15, 0, r0, c1, c0 @ get control register v4
  401. ldr r5, arm1020_cr1_clear
  402. bic r0, r0, r5
  403. ldr r5, arm1020_cr1_set
  404. orr r0, r0, r5
  405. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  406. orr r0, r0, #0x4000 @ .R.. .... .... ....
  407. #endif
  408. mov pc, lr
  409. .size __arm1020_setup, . - __arm1020_setup
  410. /*
  411. * R
  412. * .RVI ZFRS BLDP WCAM
  413. * .011 1001 ..11 0101
  414. */
  415. .type arm1020_cr1_clear, #object
  416. .type arm1020_cr1_set, #object
  417. arm1020_cr1_clear:
  418. .word 0x593f
  419. arm1020_cr1_set:
  420. .word 0x3935
  421. __INITDATA
  422. /*
  423. * Purpose : Function pointers used to access above functions - all calls
  424. * come through these
  425. */
  426. .type arm1020_processor_functions, #object
  427. arm1020_processor_functions:
  428. .word v4t_early_abort
  429. .word cpu_arm1020_proc_init
  430. .word cpu_arm1020_proc_fin
  431. .word cpu_arm1020_reset
  432. .word cpu_arm1020_do_idle
  433. .word cpu_arm1020_dcache_clean_area
  434. .word cpu_arm1020_switch_mm
  435. .word cpu_arm1020_set_pte
  436. .size arm1020_processor_functions, . - arm1020_processor_functions
  437. .section ".rodata"
  438. .type cpu_arch_name, #object
  439. cpu_arch_name:
  440. .asciz "armv5t"
  441. .size cpu_arch_name, . - cpu_arch_name
  442. .type cpu_elf_name, #object
  443. cpu_elf_name:
  444. .asciz "v5"
  445. .size cpu_elf_name, . - cpu_elf_name
  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. b __arm1020_setup
  478. .long cpu_arch_name
  479. .long cpu_elf_name
  480. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
  481. .long cpu_arm1020_name
  482. .long arm1020_processor_functions
  483. .long v4wbi_tlb_fns
  484. .long v4wb_user_fns
  485. .long arm1020_cache_fns
  486. .size __arm1020_proc_info, . - __arm1020_proc_info