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