proc-arm1020.S 13 KB

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