proc-arm925.S 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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/init.h>
  53. #include <asm/assembler.h>
  54. #include <asm/hwcap.h>
  55. #include <asm/pgtable-hwdef.h>
  56. #include <asm/pgtable.h>
  57. #include <asm/page.h>
  58. #include <asm/ptrace.h>
  59. #include "proc-macros.S"
  60. /*
  61. * The size of one data cache line.
  62. */
  63. #define CACHE_DLINESIZE 16
  64. /*
  65. * The number of data cache segments.
  66. */
  67. #define CACHE_DSEGMENTS 2
  68. /*
  69. * The number of lines in a cache segment.
  70. */
  71. #define CACHE_DENTRIES 256
  72. /*
  73. * This is the size at which it becomes more efficient to
  74. * clean the whole cache, rather than using the individual
  75. * cache line maintenance instructions.
  76. */
  77. #define CACHE_DLIMIT 8192
  78. .text
  79. /*
  80. * cpu_arm925_proc_init()
  81. */
  82. ENTRY(cpu_arm925_proc_init)
  83. mov pc, lr
  84. /*
  85. * cpu_arm925_proc_fin()
  86. */
  87. ENTRY(cpu_arm925_proc_fin)
  88. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  89. bic r0, r0, #0x1000 @ ...i............
  90. bic r0, r0, #0x000e @ ............wca.
  91. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  92. mov pc, lr
  93. /*
  94. * cpu_arm925_reset(loc)
  95. *
  96. * Perform a soft reset of the system. Put the CPU into the
  97. * same state as it would be if it had been reset, and branch
  98. * to what would be the reset vector.
  99. *
  100. * loc: location to jump to for soft reset
  101. */
  102. .align 5
  103. .pushsection .idmap.text, "ax"
  104. ENTRY(cpu_arm925_reset)
  105. /* Send software reset to MPU and DSP */
  106. mov ip, #0xff000000
  107. orr ip, ip, #0x00fe0000
  108. orr ip, ip, #0x0000ce00
  109. mov r4, #1
  110. strh r4, [ip, #0x10]
  111. ENDPROC(cpu_arm925_reset)
  112. .popsection
  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. #ifdef CONFIG_MMU
  117. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  118. #endif
  119. mrc p15, 0, ip, c1, c0, 0 @ ctrl register
  120. bic ip, ip, #0x000f @ ............wcam
  121. bic ip, ip, #0x1100 @ ...i...s........
  122. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  123. mov pc, r0
  124. /*
  125. * cpu_arm925_do_idle()
  126. *
  127. * Called with IRQs disabled
  128. */
  129. .align 10
  130. ENTRY(cpu_arm925_do_idle)
  131. mov r0, #0
  132. mrc p15, 0, r1, c1, c0, 0 @ Read control register
  133. mcr p15, 0, r0, c7, c10, 4 @ Drain write buffer
  134. bic r2, r1, #1 << 12
  135. mcr p15, 0, r2, c1, c0, 0 @ Disable I cache
  136. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  137. mcr p15, 0, r1, c1, c0, 0 @ Restore ICache enable
  138. mov pc, lr
  139. /*
  140. * flush_icache_all()
  141. *
  142. * Unconditionally clean and invalidate the entire icache.
  143. */
  144. ENTRY(arm925_flush_icache_all)
  145. mov r0, #0
  146. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  147. mov pc, lr
  148. ENDPROC(arm925_flush_icache_all)
  149. /*
  150. * flush_user_cache_all()
  151. *
  152. * Clean and invalidate all cache entries in a particular
  153. * address space.
  154. */
  155. ENTRY(arm925_flush_user_cache_all)
  156. /* FALLTHROUGH */
  157. /*
  158. * flush_kern_cache_all()
  159. *
  160. * Clean and invalidate the entire cache.
  161. */
  162. ENTRY(arm925_flush_kern_cache_all)
  163. mov r2, #VM_EXEC
  164. mov ip, #0
  165. __flush_whole_cache:
  166. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  167. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  168. #else
  169. /* Flush entries in both segments at once, see NOTE1 above */
  170. mov r3, #(CACHE_DENTRIES - 1) << 4 @ 256 entries in segment
  171. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  172. subs r3, r3, #1 << 4
  173. bcs 2b @ entries 255 to 0
  174. #endif
  175. tst r2, #VM_EXEC
  176. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  177. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  178. mov pc, lr
  179. /*
  180. * flush_user_cache_range(start, end, flags)
  181. *
  182. * Clean and invalidate a range of cache entries in the
  183. * specified address range.
  184. *
  185. * - start - start address (inclusive)
  186. * - end - end address (exclusive)
  187. * - flags - vm_flags describing address space
  188. */
  189. ENTRY(arm925_flush_user_cache_range)
  190. mov ip, #0
  191. sub r3, r1, r0 @ calculate total size
  192. cmp r3, #CACHE_DLIMIT
  193. bgt __flush_whole_cache
  194. 1: tst r2, #VM_EXEC
  195. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  196. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  197. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  198. add r0, r0, #CACHE_DLINESIZE
  199. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  200. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  201. add r0, r0, #CACHE_DLINESIZE
  202. #else
  203. mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  204. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  205. add r0, r0, #CACHE_DLINESIZE
  206. mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  207. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  208. add r0, r0, #CACHE_DLINESIZE
  209. #endif
  210. cmp r0, r1
  211. blo 1b
  212. tst r2, #VM_EXEC
  213. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  214. mov pc, lr
  215. /*
  216. * coherent_kern_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_kern_range)
  226. /* FALLTHROUGH */
  227. /*
  228. * coherent_user_range(start, end)
  229. *
  230. * Ensure coherency between the Icache and the Dcache in the
  231. * region described by start, end. If you have non-snooping
  232. * Harvard caches, you need to implement this function.
  233. *
  234. * - start - virtual start address
  235. * - end - virtual end address
  236. */
  237. ENTRY(arm925_coherent_user_range)
  238. bic r0, r0, #CACHE_DLINESIZE - 1
  239. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  240. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  241. add r0, r0, #CACHE_DLINESIZE
  242. cmp r0, r1
  243. blo 1b
  244. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  245. mov r0, #0
  246. mov pc, lr
  247. /*
  248. * flush_kern_dcache_area(void *addr, size_t size)
  249. *
  250. * Ensure no D cache aliasing occurs, either with itself or
  251. * the I cache
  252. *
  253. * - addr - kernel address
  254. * - size - region size
  255. */
  256. ENTRY(arm925_flush_kern_dcache_area)
  257. add r1, r0, r1
  258. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  259. add r0, r0, #CACHE_DLINESIZE
  260. cmp r0, r1
  261. blo 1b
  262. mov r0, #0
  263. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  264. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  265. mov pc, lr
  266. /*
  267. * dma_inv_range(start, end)
  268. *
  269. * Invalidate (discard) the specified virtual address range.
  270. * May not write back any entries. If 'start' or 'end'
  271. * are not cache line aligned, those lines must be written
  272. * back.
  273. *
  274. * - start - virtual start address
  275. * - end - virtual end address
  276. *
  277. * (same as v4wb)
  278. */
  279. arm925_dma_inv_range:
  280. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  281. tst r0, #CACHE_DLINESIZE - 1
  282. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  283. tst r1, #CACHE_DLINESIZE - 1
  284. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  285. #endif
  286. bic r0, r0, #CACHE_DLINESIZE - 1
  287. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  288. add r0, r0, #CACHE_DLINESIZE
  289. cmp r0, r1
  290. blo 1b
  291. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  292. mov pc, lr
  293. /*
  294. * dma_clean_range(start, end)
  295. *
  296. * Clean the specified virtual address range.
  297. *
  298. * - start - virtual start address
  299. * - end - virtual end address
  300. *
  301. * (same as v4wb)
  302. */
  303. arm925_dma_clean_range:
  304. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  305. bic r0, r0, #CACHE_DLINESIZE - 1
  306. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  307. add r0, r0, #CACHE_DLINESIZE
  308. cmp r0, r1
  309. blo 1b
  310. #endif
  311. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  312. mov pc, lr
  313. /*
  314. * dma_flush_range(start, end)
  315. *
  316. * Clean and invalidate the specified virtual address range.
  317. *
  318. * - start - virtual start address
  319. * - end - virtual end address
  320. */
  321. ENTRY(arm925_dma_flush_range)
  322. bic r0, r0, #CACHE_DLINESIZE - 1
  323. 1:
  324. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  325. mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  326. #else
  327. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  328. #endif
  329. add r0, r0, #CACHE_DLINESIZE
  330. cmp r0, r1
  331. blo 1b
  332. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  333. mov pc, lr
  334. /*
  335. * dma_map_area(start, size, dir)
  336. * - start - kernel virtual start address
  337. * - size - size of region
  338. * - dir - DMA direction
  339. */
  340. ENTRY(arm925_dma_map_area)
  341. add r1, r1, r0
  342. cmp r2, #DMA_TO_DEVICE
  343. beq arm925_dma_clean_range
  344. bcs arm925_dma_inv_range
  345. b arm925_dma_flush_range
  346. ENDPROC(arm925_dma_map_area)
  347. /*
  348. * dma_unmap_area(start, size, dir)
  349. * - start - kernel virtual start address
  350. * - size - size of region
  351. * - dir - DMA direction
  352. */
  353. ENTRY(arm925_dma_unmap_area)
  354. mov pc, lr
  355. ENDPROC(arm925_dma_unmap_area)
  356. @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
  357. define_cache_functions arm925
  358. ENTRY(cpu_arm925_dcache_clean_area)
  359. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  360. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  361. add r0, r0, #CACHE_DLINESIZE
  362. subs r1, r1, #CACHE_DLINESIZE
  363. bhi 1b
  364. #endif
  365. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  366. mov pc, lr
  367. /* =============================== PageTable ============================== */
  368. /*
  369. * cpu_arm925_switch_mm(pgd)
  370. *
  371. * Set the translation base pointer to be as described by pgd.
  372. *
  373. * pgd: new page tables
  374. */
  375. .align 5
  376. ENTRY(cpu_arm925_switch_mm)
  377. #ifdef CONFIG_MMU
  378. mov ip, #0
  379. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  380. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  381. #else
  382. /* Flush entries in bothe segments at once, see NOTE1 above */
  383. mov r3, #(CACHE_DENTRIES - 1) << 4 @ 256 entries in segment
  384. 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
  385. subs r3, r3, #1 << 4
  386. bcs 2b @ entries 255 to 0
  387. #endif
  388. mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
  389. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  390. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  391. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  392. #endif
  393. mov pc, lr
  394. /*
  395. * cpu_arm925_set_pte_ext(ptep, pte, ext)
  396. *
  397. * Set a PTE and flush it out
  398. */
  399. .align 5
  400. ENTRY(cpu_arm925_set_pte_ext)
  401. #ifdef CONFIG_MMU
  402. armv3_set_pte_ext
  403. mov r0, r0
  404. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  405. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  406. #endif
  407. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  408. #endif /* CONFIG_MMU */
  409. mov pc, lr
  410. __CPUINIT
  411. .type __arm925_setup, #function
  412. __arm925_setup:
  413. mov r0, #0
  414. #if defined(CONFIG_CPU_ICACHE_STREAMING_DISABLE)
  415. orr r0,r0,#1 << 7
  416. #endif
  417. /* Transparent on, D-cache clean & flush mode. See NOTE2 above */
  418. orr r0,r0,#1 << 1 @ transparent mode on
  419. mcr p15, 0, r0, c15, c1, 0 @ write TI config register
  420. mov r0, #0
  421. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  422. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  423. #ifdef CONFIG_MMU
  424. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  425. #endif
  426. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  427. mov r0, #4 @ disable write-back on caches explicitly
  428. mcr p15, 7, r0, c15, c0, 0
  429. #endif
  430. adr r5, arm925_crval
  431. ldmia r5, {r5, r6}
  432. mrc p15, 0, r0, c1, c0 @ get control register v4
  433. bic r0, r0, r5
  434. orr r0, r0, r6
  435. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  436. orr r0, r0, #0x4000 @ .1.. .... .... ....
  437. #endif
  438. mov pc, lr
  439. .size __arm925_setup, . - __arm925_setup
  440. /*
  441. * R
  442. * .RVI ZFRS BLDP WCAM
  443. * .011 0001 ..11 1101
  444. *
  445. */
  446. .type arm925_crval, #object
  447. arm925_crval:
  448. crval clear=0x00007f3f, mmuset=0x0000313d, ucset=0x00001130
  449. __INITDATA
  450. @ define struct processor (see <asm/proc-fns.h> and proc-macros.S)
  451. define_processor_functions arm925, dabort=v4t_early_abort, pabort=legacy_pabort
  452. .section ".rodata"
  453. string cpu_arch_name, "armv4t"
  454. string cpu_elf_name, "v4"
  455. string cpu_arm925_name, "ARM925T"
  456. .align
  457. .section ".proc.info.init", #alloc, #execinstr
  458. .macro arm925_proc_info name:req, cpu_val:req, cpu_mask:req, cpu_name:req, cache
  459. .type __\name\()_proc_info,#object
  460. __\name\()_proc_info:
  461. .long \cpu_val
  462. .long \cpu_mask
  463. .long PMD_TYPE_SECT | \
  464. PMD_BIT4 | \
  465. PMD_SECT_AP_WRITE | \
  466. PMD_SECT_AP_READ
  467. .long PMD_TYPE_SECT | \
  468. PMD_BIT4 | \
  469. PMD_SECT_AP_WRITE | \
  470. PMD_SECT_AP_READ
  471. b __arm925_setup
  472. .long cpu_arch_name
  473. .long cpu_elf_name
  474. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
  475. .long cpu_arm925_name
  476. .long arm925_processor_functions
  477. .long v4wbi_tlb_fns
  478. .long v4wb_user_fns
  479. .long arm925_cache_fns
  480. .size __\name\()_proc_info, . - __\name\()_proc_info
  481. .endm
  482. arm925_proc_info arm925, 0x54029250, 0xfffffff0, cpu_arm925_name
  483. arm925_proc_info arm915, 0x54029150, 0xfffffff0, cpu_arm925_name