proc-arm925.S 14 KB

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