proc-arm925.S 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. /*
  2. * linux/arch/arm/mm/arm925.S: MMU functions for ARM925
  3. *
  4. * Copyright (C) 1999,2000 ARM Limited
  5. * Copyright (C) 2000 Deep Blue Solutions Ltd.
  6. * Copyright (C) 2002 RidgeRun, Inc.
  7. * Copyright (C) 2002-2003 MontaVista Software, Inc.
  8. *
  9. * Update for Linux-2.6 and cache flush improvements
  10. * Copyright (C) 2004 Nokia Corporation by Tony Lindgren <tony@atomide.com>
  11. *
  12. * hacked for non-paged-MM by Hyok S. Choi, 2004.
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. *
  28. *
  29. * These are the low level assembler for performing cache and TLB
  30. * functions on the arm925.
  31. *
  32. * CONFIG_CPU_ARM925_CPU_IDLE -> nohlt
  33. *
  34. * Some additional notes based on deciphering the TI TRM on OMAP-5910:
  35. *
  36. * NOTE1: The TI925T Configuration Register bit "D-cache clean and flush
  37. * entry mode" must be 0 to flush the entries in both segments
  38. * at once. This is the default value. See TRM 2-20 and 2-24 for
  39. * more information.
  40. *
  41. * NOTE2: Default is the "D-cache clean and flush entry mode". It looks
  42. * like the "Transparent mode" must be on for partial cache flushes
  43. * to work in this mode. This mode only works with 16-bit external
  44. * memory. See TRM 2-24 for more information.
  45. *
  46. * NOTE3: Write-back cache flushing seems to be flakey with devices using
  47. * direct memory access, such as USB OHCI. The workaround is to use
  48. * write-through cache with CONFIG_CPU_DCACHE_WRITETHROUGH (this is
  49. * the default for OMAP-1510).
  50. */
  51. #include <linux/linkage.h>
  52. #include <linux/config.h>
  53. #include <linux/init.h>
  54. #include <asm/assembler.h>
  55. #include <asm/pgtable-hwdef.h>
  56. #include <asm/pgtable.h>
  57. #include <asm/procinfo.h>
  58. #include <asm/page.h>
  59. #include <asm/ptrace.h>
  60. #include "proc-macros.S"
  61. /*
  62. * The size of one data cache line.
  63. */
  64. #define CACHE_DLINESIZE 16
  65. /*
  66. * The number of data cache segments.
  67. */
  68. #define CACHE_DSEGMENTS 2
  69. /*
  70. * The number of lines in a cache segment.
  71. */
  72. #define CACHE_DENTRIES 256
  73. /*
  74. * This is the size at which it becomes more efficient to
  75. * clean the whole cache, rather than using the individual
  76. * cache line maintainence instructions.
  77. */
  78. #define CACHE_DLIMIT 8192
  79. .text
  80. /*
  81. * cpu_arm925_proc_init()
  82. */
  83. ENTRY(cpu_arm925_proc_init)
  84. mov pc, lr
  85. /*
  86. * cpu_arm925_proc_fin()
  87. */
  88. ENTRY(cpu_arm925_proc_fin)
  89. stmfd sp!, {lr}
  90. mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
  91. msr cpsr_c, ip
  92. bl arm925_flush_kern_cache_all
  93. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  94. bic r0, r0, #0x1000 @ ...i............
  95. bic r0, r0, #0x000e @ ............wca.
  96. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  97. ldmfd sp!, {pc}
  98. /*
  99. * cpu_arm925_reset(loc)
  100. *
  101. * Perform a soft reset of the system. Put the CPU into the
  102. * same state as it would be if it had been reset, and branch
  103. * to what would be the reset vector.
  104. *
  105. * loc: location to jump to for soft reset
  106. */
  107. .align 5
  108. ENTRY(cpu_arm925_reset)
  109. /* Send software reset to MPU and DSP */
  110. mov ip, #0xff000000
  111. orr ip, ip, #0x00fe0000
  112. orr ip, ip, #0x0000ce00
  113. mov r4, #1
  114. strh r4, [ip, #0x10]
  115. mov ip, #0
  116. mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
  117. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  118. #ifdef CONFIG_MMU
  119. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  120. #endif
  121. mrc p15, 0, ip, c1, c0, 0 @ ctrl register
  122. bic ip, ip, #0x000f @ ............wcam
  123. bic ip, ip, #0x1100 @ ...i...s........
  124. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  125. mov pc, r0
  126. /*
  127. * cpu_arm925_do_idle()
  128. *
  129. * Called with IRQs disabled
  130. */
  131. .align 10
  132. ENTRY(cpu_arm925_do_idle)
  133. mov r0, #0
  134. mrc p15, 0, r1, c1, c0, 0 @ Read control register
  135. mcr p15, 0, r0, c7, c10, 4 @ Drain write buffer
  136. bic r2, r1, #1 << 12
  137. mcr p15, 0, r2, c1, c0, 0 @ Disable I cache
  138. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  139. mcr p15, 0, r1, c1, c0, 0 @ Restore ICache enable
  140. mov pc, lr
  141. /*
  142. * flush_user_cache_all()
  143. *
  144. * Clean and invalidate all cache entries in a particular
  145. * address space.
  146. */
  147. ENTRY(arm925_flush_user_cache_all)
  148. /* FALLTHROUGH */
  149. /*
  150. * flush_kern_cache_all()
  151. *
  152. * Clean and invalidate the entire cache.
  153. */
  154. ENTRY(arm925_flush_kern_cache_all)
  155. mov r2, #VM_EXEC
  156. mov ip, #0
  157. __flush_whole_cache:
  158. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  159. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  160. #else
  161. /* Flush entries in both segments at once, see NOTE1 above */
  162. mov r3, #(CACHE_DENTRIES - 1) << 4 @ 256 entries in segment
  163. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  164. subs r3, r3, #1 << 4
  165. bcs 2b @ entries 255 to 0
  166. #endif
  167. tst r2, #VM_EXEC
  168. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  169. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  170. mov pc, lr
  171. /*
  172. * flush_user_cache_range(start, end, flags)
  173. *
  174. * Clean and invalidate a range of cache entries in the
  175. * specified address range.
  176. *
  177. * - start - start address (inclusive)
  178. * - end - end address (exclusive)
  179. * - flags - vm_flags describing address space
  180. */
  181. ENTRY(arm925_flush_user_cache_range)
  182. mov ip, #0
  183. sub r3, r1, r0 @ calculate total size
  184. cmp r3, #CACHE_DLIMIT
  185. bgt __flush_whole_cache
  186. 1: tst r2, #VM_EXEC
  187. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  188. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  189. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  190. add r0, r0, #CACHE_DLINESIZE
  191. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  192. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  193. add r0, r0, #CACHE_DLINESIZE
  194. #else
  195. mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  196. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  197. add r0, r0, #CACHE_DLINESIZE
  198. mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  199. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  200. add r0, r0, #CACHE_DLINESIZE
  201. #endif
  202. cmp r0, r1
  203. blo 1b
  204. tst r2, #VM_EXEC
  205. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  206. mov pc, lr
  207. /*
  208. * coherent_kern_range(start, end)
  209. *
  210. * Ensure coherency between the Icache and the Dcache in the
  211. * region described by start, end. If you have non-snooping
  212. * Harvard caches, you need to implement this function.
  213. *
  214. * - start - virtual start address
  215. * - end - virtual end address
  216. */
  217. ENTRY(arm925_coherent_kern_range)
  218. /* FALLTHROUGH */
  219. /*
  220. * coherent_user_range(start, end)
  221. *
  222. * Ensure coherency between the Icache and the Dcache in the
  223. * region described by start, end. If you have non-snooping
  224. * Harvard caches, you need to implement this function.
  225. *
  226. * - start - virtual start address
  227. * - end - virtual end address
  228. */
  229. ENTRY(arm925_coherent_user_range)
  230. bic r0, r0, #CACHE_DLINESIZE - 1
  231. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  232. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  233. add r0, r0, #CACHE_DLINESIZE
  234. cmp r0, r1
  235. blo 1b
  236. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  237. mov pc, lr
  238. /*
  239. * flush_kern_dcache_page(void *page)
  240. *
  241. * Ensure no D cache aliasing occurs, either with itself or
  242. * the I cache
  243. *
  244. * - addr - page aligned address
  245. */
  246. ENTRY(arm925_flush_kern_dcache_page)
  247. add r1, r0, #PAGE_SZ
  248. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  249. add r0, r0, #CACHE_DLINESIZE
  250. cmp r0, r1
  251. blo 1b
  252. mov r0, #0
  253. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  254. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  255. mov pc, lr
  256. /*
  257. * dma_inv_range(start, end)
  258. *
  259. * Invalidate (discard) the specified virtual address range.
  260. * May not write back any entries. If 'start' or 'end'
  261. * are not cache line aligned, those lines must be written
  262. * back.
  263. *
  264. * - start - virtual start address
  265. * - end - virtual end address
  266. *
  267. * (same as v4wb)
  268. */
  269. ENTRY(arm925_dma_inv_range)
  270. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  271. tst r0, #CACHE_DLINESIZE - 1
  272. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  273. tst r1, #CACHE_DLINESIZE - 1
  274. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  275. #endif
  276. bic r0, r0, #CACHE_DLINESIZE - 1
  277. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  278. add r0, r0, #CACHE_DLINESIZE
  279. cmp r0, r1
  280. blo 1b
  281. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  282. mov pc, lr
  283. /*
  284. * dma_clean_range(start, end)
  285. *
  286. * Clean the specified virtual address range.
  287. *
  288. * - start - virtual start address
  289. * - end - virtual end address
  290. *
  291. * (same as v4wb)
  292. */
  293. ENTRY(arm925_dma_clean_range)
  294. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  295. bic r0, r0, #CACHE_DLINESIZE - 1
  296. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  297. add r0, r0, #CACHE_DLINESIZE
  298. cmp r0, r1
  299. blo 1b
  300. #endif
  301. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  302. mov pc, lr
  303. /*
  304. * dma_flush_range(start, end)
  305. *
  306. * Clean and invalidate the specified virtual address range.
  307. *
  308. * - start - virtual start address
  309. * - end - virtual end address
  310. */
  311. ENTRY(arm925_dma_flush_range)
  312. bic r0, r0, #CACHE_DLINESIZE - 1
  313. 1:
  314. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  315. mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  316. #else
  317. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  318. #endif
  319. add r0, r0, #CACHE_DLINESIZE
  320. cmp r0, r1
  321. blo 1b
  322. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  323. mov pc, lr
  324. ENTRY(arm925_cache_fns)
  325. .long arm925_flush_kern_cache_all
  326. .long arm925_flush_user_cache_all
  327. .long arm925_flush_user_cache_range
  328. .long arm925_coherent_kern_range
  329. .long arm925_coherent_user_range
  330. .long arm925_flush_kern_dcache_page
  331. .long arm925_dma_inv_range
  332. .long arm925_dma_clean_range
  333. .long arm925_dma_flush_range
  334. ENTRY(cpu_arm925_dcache_clean_area)
  335. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  336. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  337. add r0, r0, #CACHE_DLINESIZE
  338. subs r1, r1, #CACHE_DLINESIZE
  339. bhi 1b
  340. #endif
  341. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  342. mov pc, lr
  343. /* =============================== PageTable ============================== */
  344. /*
  345. * cpu_arm925_switch_mm(pgd)
  346. *
  347. * Set the translation base pointer to be as described by pgd.
  348. *
  349. * pgd: new page tables
  350. */
  351. .align 5
  352. ENTRY(cpu_arm925_switch_mm)
  353. #ifdef CONFIG_MMU
  354. mov ip, #0
  355. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  356. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  357. #else
  358. /* Flush entries in bothe segments at once, see NOTE1 above */
  359. mov r3, #(CACHE_DENTRIES - 1) << 4 @ 256 entries in segment
  360. 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
  361. subs r3, r3, #1 << 4
  362. bcs 2b @ entries 255 to 0
  363. #endif
  364. mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
  365. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  366. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  367. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  368. #endif
  369. mov pc, lr
  370. /*
  371. * cpu_arm925_set_pte(ptep, pte)
  372. *
  373. * Set a PTE and flush it out
  374. */
  375. .align 5
  376. ENTRY(cpu_arm925_set_pte)
  377. #ifdef CONFIG_MMU
  378. str r1, [r0], #-2048 @ linux version
  379. eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
  380. bic r2, r1, #PTE_SMALL_AP_MASK
  381. bic r2, r2, #PTE_TYPE_MASK
  382. orr r2, r2, #PTE_TYPE_SMALL
  383. tst r1, #L_PTE_USER @ User?
  384. orrne r2, r2, #PTE_SMALL_AP_URO_SRW
  385. tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
  386. orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
  387. tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
  388. movne r2, #0
  389. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  390. eor r3, r2, #0x0a @ C & small page?
  391. tst r3, #0x0b
  392. biceq r2, r2, #4
  393. #endif
  394. str r2, [r0] @ hardware version
  395. mov r0, r0
  396. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  397. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  398. #endif
  399. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  400. #endif /* CONFIG_MMU */
  401. mov pc, lr
  402. __INIT
  403. .type __arm925_setup, #function
  404. __arm925_setup:
  405. mov r0, #0
  406. #if defined(CONFIG_CPU_ICACHE_STREAMING_DISABLE)
  407. orr r0,r0,#1 << 7
  408. #endif
  409. /* Transparent on, D-cache clean & flush mode. See NOTE2 above */
  410. orr r0,r0,#1 << 1 @ transparent mode on
  411. mcr p15, 0, r0, c15, c1, 0 @ write TI config register
  412. mov r0, #0
  413. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  414. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  415. #ifdef CONFIG_MMU
  416. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  417. #endif
  418. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  419. mov r0, #4 @ disable write-back on caches explicitly
  420. mcr p15, 7, r0, c15, c0, 0
  421. #endif
  422. mrc p15, 0, r0, c1, c0 @ get control register v4
  423. ldr r5, arm925_cr1_clear
  424. bic r0, r0, r5
  425. ldr r5, arm925_cr1_set
  426. orr r0, r0, r5
  427. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  428. orr r0, r0, #0x4000 @ .1.. .... .... ....
  429. #endif
  430. mov pc, lr
  431. .size __arm925_setup, . - __arm925_setup
  432. /*
  433. * R
  434. * .RVI ZFRS BLDP WCAM
  435. * .011 0001 ..11 1101
  436. *
  437. */
  438. .type arm925_cr1_clear, #object
  439. .type arm925_cr1_set, #object
  440. arm925_cr1_clear:
  441. .word 0x7f3f
  442. arm925_cr1_set:
  443. .word 0x313d
  444. __INITDATA
  445. /*
  446. * Purpose : Function pointers used to access above functions - all calls
  447. * come through these
  448. */
  449. .type arm925_processor_functions, #object
  450. arm925_processor_functions:
  451. .word v4t_early_abort
  452. .word cpu_arm925_proc_init
  453. .word cpu_arm925_proc_fin
  454. .word cpu_arm925_reset
  455. .word cpu_arm925_do_idle
  456. .word cpu_arm925_dcache_clean_area
  457. .word cpu_arm925_switch_mm
  458. .word cpu_arm925_set_pte
  459. .size arm925_processor_functions, . - arm925_processor_functions
  460. .section ".rodata"
  461. .type cpu_arch_name, #object
  462. cpu_arch_name:
  463. .asciz "armv4t"
  464. .size cpu_arch_name, . - cpu_arch_name
  465. .type cpu_elf_name, #object
  466. cpu_elf_name:
  467. .asciz "v4"
  468. .size cpu_elf_name, . - cpu_elf_name
  469. .type cpu_arm925_name, #object
  470. cpu_arm925_name:
  471. .ascii "ARM925T"
  472. #ifndef CONFIG_CPU_ICACHE_DISABLE
  473. .ascii "i"
  474. #endif
  475. #ifndef CONFIG_CPU_DCACHE_DISABLE
  476. .ascii "d"
  477. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  478. .ascii "(wt)"
  479. #else
  480. .ascii "(wb)"
  481. #endif
  482. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  483. .ascii "RR"
  484. #endif
  485. #endif
  486. .ascii "\0"
  487. .size cpu_arm925_name, . - cpu_arm925_name
  488. .align
  489. .section ".proc.info.init", #alloc, #execinstr
  490. .type __arm925_proc_info,#object
  491. __arm925_proc_info:
  492. .long 0x54029250
  493. .long 0xfffffff0
  494. .long PMD_TYPE_SECT | \
  495. PMD_BIT4 | \
  496. PMD_SECT_AP_WRITE | \
  497. PMD_SECT_AP_READ
  498. b __arm925_setup
  499. .long cpu_arch_name
  500. .long cpu_elf_name
  501. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
  502. .long cpu_arm925_name
  503. .long arm925_processor_functions
  504. .long v4wbi_tlb_fns
  505. .long v4wb_user_fns
  506. .long arm925_cache_fns
  507. .size __arm925_proc_info, . - __arm925_proc_info
  508. .type __arm915_proc_info,#object
  509. __arm915_proc_info:
  510. .long 0x54029150
  511. .long 0xfffffff0
  512. .long PMD_TYPE_SECT | \
  513. PMD_BIT4 | \
  514. PMD_SECT_AP_WRITE | \
  515. PMD_SECT_AP_READ
  516. b __arm925_setup
  517. .long cpu_arch_name
  518. .long cpu_elf_name
  519. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
  520. .long cpu_arm925_name
  521. .long arm925_processor_functions
  522. .long v4wbi_tlb_fns
  523. .long v4wb_user_fns
  524. .long arm925_cache_fns
  525. .size __arm925_proc_info, . - __arm925_proc_info