proc-arm925.S 14 KB

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