proc-feroceon.S 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. /*
  2. * linux/arch/arm/mm/proc-feroceon.S: MMU functions for Feroceon
  3. *
  4. * Heavily based on proc-arm926.S
  5. * Maintainer: Assaf Hoffman <hoffman@marvell.com>
  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. #include <linux/linkage.h>
  22. #include <linux/init.h>
  23. #include <asm/assembler.h>
  24. #include <asm/elf.h>
  25. #include <asm/pgtable-hwdef.h>
  26. #include <asm/pgtable.h>
  27. #include <asm/page.h>
  28. #include <asm/ptrace.h>
  29. #include "proc-macros.S"
  30. /*
  31. * This is the maximum size of an area which will be invalidated
  32. * using the single invalidate entry instructions. Anything larger
  33. * than this, and we go for the whole cache.
  34. *
  35. * This value should be chosen such that we choose the cheapest
  36. * alternative.
  37. */
  38. #define CACHE_DLIMIT 16384
  39. /*
  40. * the cache line size of the I and D cache
  41. */
  42. #define CACHE_DLINESIZE 32
  43. .text
  44. /*
  45. * cpu_feroceon_proc_init()
  46. */
  47. ENTRY(cpu_feroceon_proc_init)
  48. mov pc, lr
  49. /*
  50. * cpu_feroceon_proc_fin()
  51. */
  52. ENTRY(cpu_feroceon_proc_fin)
  53. stmfd sp!, {lr}
  54. mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
  55. msr cpsr_c, ip
  56. bl feroceon_flush_kern_cache_all
  57. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  58. bic r0, r0, #0x1000 @ ...i............
  59. bic r0, r0, #0x000e @ ............wca.
  60. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  61. ldmfd sp!, {pc}
  62. /*
  63. * cpu_feroceon_reset(loc)
  64. *
  65. * Perform a soft reset of the system. Put the CPU into the
  66. * same state as it would be if it had been reset, and branch
  67. * to what would be the reset vector.
  68. *
  69. * loc: location to jump to for soft reset
  70. */
  71. .align 5
  72. ENTRY(cpu_feroceon_reset)
  73. mov ip, #0
  74. mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
  75. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  76. #ifdef CONFIG_MMU
  77. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  78. #endif
  79. mrc p15, 0, ip, c1, c0, 0 @ ctrl register
  80. bic ip, ip, #0x000f @ ............wcam
  81. bic ip, ip, #0x1100 @ ...i...s........
  82. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  83. mov pc, r0
  84. /*
  85. * cpu_feroceon_do_idle()
  86. *
  87. * Called with IRQs disabled
  88. */
  89. .align 10
  90. ENTRY(cpu_feroceon_do_idle)
  91. mov r0, #0
  92. mcr p15, 0, r0, c7, c10, 4 @ Drain write buffer
  93. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  94. mov pc, lr
  95. /*
  96. * flush_user_cache_all()
  97. *
  98. * Clean and invalidate all cache entries in a particular
  99. * address space.
  100. */
  101. ENTRY(feroceon_flush_user_cache_all)
  102. /* FALLTHROUGH */
  103. /*
  104. * flush_kern_cache_all()
  105. *
  106. * Clean and invalidate the entire cache.
  107. */
  108. ENTRY(feroceon_flush_kern_cache_all)
  109. mov r2, #VM_EXEC
  110. mov ip, #0
  111. __flush_whole_cache:
  112. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  113. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  114. #else
  115. 1: mrc p15, 0, r15, c7, c14, 3 @ test,clean,invalidate
  116. bne 1b
  117. #endif
  118. tst r2, #VM_EXEC
  119. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  120. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  121. mov pc, lr
  122. /*
  123. * flush_user_cache_range(start, end, flags)
  124. *
  125. * Clean and invalidate a range of cache entries in the
  126. * specified address range.
  127. *
  128. * - start - start address (inclusive)
  129. * - end - end address (exclusive)
  130. * - flags - vm_flags describing address space
  131. */
  132. ENTRY(feroceon_flush_user_cache_range)
  133. mov ip, #0
  134. sub r3, r1, r0 @ calculate total size
  135. cmp r3, #CACHE_DLIMIT
  136. bgt __flush_whole_cache
  137. 1: tst r2, #VM_EXEC
  138. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  139. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  140. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  141. add r0, r0, #CACHE_DLINESIZE
  142. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  143. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  144. add r0, r0, #CACHE_DLINESIZE
  145. #else
  146. mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  147. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  148. add r0, r0, #CACHE_DLINESIZE
  149. mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  150. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
  151. add r0, r0, #CACHE_DLINESIZE
  152. #endif
  153. cmp r0, r1
  154. blo 1b
  155. tst r2, #VM_EXEC
  156. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  157. mov pc, lr
  158. /*
  159. * coherent_kern_range(start, end)
  160. *
  161. * Ensure coherency between the Icache and the Dcache in the
  162. * region described by start, end. If you have non-snooping
  163. * Harvard caches, you need to implement this function.
  164. *
  165. * - start - virtual start address
  166. * - end - virtual end address
  167. */
  168. ENTRY(feroceon_coherent_kern_range)
  169. /* FALLTHROUGH */
  170. /*
  171. * coherent_user_range(start, end)
  172. *
  173. * Ensure coherency between the Icache and the Dcache in the
  174. * region described by start, end. If you have non-snooping
  175. * Harvard caches, you need to implement this function.
  176. *
  177. * - start - virtual start address
  178. * - end - virtual end address
  179. */
  180. ENTRY(feroceon_coherent_user_range)
  181. bic r0, r0, #CACHE_DLINESIZE - 1
  182. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  183. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  184. add r0, r0, #CACHE_DLINESIZE
  185. cmp r0, r1
  186. blo 1b
  187. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  188. mov pc, lr
  189. /*
  190. * flush_kern_dcache_page(void *page)
  191. *
  192. * Ensure no D cache aliasing occurs, either with itself or
  193. * the I cache
  194. *
  195. * - addr - page aligned address
  196. */
  197. ENTRY(feroceon_flush_kern_dcache_page)
  198. add r1, r0, #PAGE_SZ
  199. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  200. add r0, r0, #CACHE_DLINESIZE
  201. cmp r0, r1
  202. blo 1b
  203. mov r0, #0
  204. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  205. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  206. mov pc, lr
  207. /*
  208. * dma_inv_range(start, end)
  209. *
  210. * Invalidate (discard) the specified virtual address range.
  211. * May not write back any entries. If 'start' or 'end'
  212. * are not cache line aligned, those lines must be written
  213. * back.
  214. *
  215. * - start - virtual start address
  216. * - end - virtual end address
  217. *
  218. * (same as v4wb)
  219. */
  220. ENTRY(feroceon_dma_inv_range)
  221. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  222. tst r0, #CACHE_DLINESIZE - 1
  223. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  224. tst r1, #CACHE_DLINESIZE - 1
  225. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  226. #endif
  227. bic r0, r0, #CACHE_DLINESIZE - 1
  228. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D 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. * dma_clean_range(start, end)
  236. *
  237. * Clean the specified virtual address range.
  238. *
  239. * - start - virtual start address
  240. * - end - virtual end address
  241. *
  242. * (same as v4wb)
  243. */
  244. ENTRY(feroceon_dma_clean_range)
  245. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  246. bic r0, r0, #CACHE_DLINESIZE - 1
  247. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  248. add r0, r0, #CACHE_DLINESIZE
  249. cmp r0, r1
  250. blo 1b
  251. #endif
  252. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  253. mov pc, lr
  254. /*
  255. * dma_flush_range(start, end)
  256. *
  257. * Clean and invalidate the specified virtual address range.
  258. *
  259. * - start - virtual start address
  260. * - end - virtual end address
  261. */
  262. ENTRY(feroceon_dma_flush_range)
  263. bic r0, r0, #CACHE_DLINESIZE - 1
  264. 1:
  265. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  266. mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  267. #else
  268. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  269. #endif
  270. add r0, r0, #CACHE_DLINESIZE
  271. cmp r0, r1
  272. blo 1b
  273. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  274. mov pc, lr
  275. ENTRY(feroceon_cache_fns)
  276. .long feroceon_flush_kern_cache_all
  277. .long feroceon_flush_user_cache_all
  278. .long feroceon_flush_user_cache_range
  279. .long feroceon_coherent_kern_range
  280. .long feroceon_coherent_user_range
  281. .long feroceon_flush_kern_dcache_page
  282. .long feroceon_dma_inv_range
  283. .long feroceon_dma_clean_range
  284. .long feroceon_dma_flush_range
  285. ENTRY(cpu_feroceon_dcache_clean_area)
  286. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  287. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  288. add r0, r0, #CACHE_DLINESIZE
  289. subs r1, r1, #CACHE_DLINESIZE
  290. bhi 1b
  291. #endif
  292. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  293. mov pc, lr
  294. /* =============================== PageTable ============================== */
  295. /*
  296. * cpu_feroceon_switch_mm(pgd)
  297. *
  298. * Set the translation base pointer to be as described by pgd.
  299. *
  300. * pgd: new page tables
  301. */
  302. .align 5
  303. ENTRY(cpu_feroceon_switch_mm)
  304. #ifdef CONFIG_MMU
  305. mov ip, #0
  306. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  307. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  308. #else
  309. @ && 'Clean & Invalidate whole DCache'
  310. 1: mrc p15, 0, r15, c7, c14, 3 @ test,clean,invalidate
  311. bne 1b
  312. #endif
  313. mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
  314. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  315. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  316. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  317. #endif
  318. mov pc, lr
  319. /*
  320. * cpu_feroceon_set_pte_ext(ptep, pte, ext)
  321. *
  322. * Set a PTE and flush it out
  323. */
  324. .align 5
  325. ENTRY(cpu_feroceon_set_pte_ext)
  326. #ifdef CONFIG_MMU
  327. str r1, [r0], #-2048 @ linux version
  328. eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
  329. bic r2, r1, #PTE_SMALL_AP_MASK
  330. bic r2, r2, #PTE_TYPE_MASK
  331. orr r2, r2, #PTE_TYPE_SMALL
  332. tst r1, #L_PTE_USER @ User?
  333. orrne r2, r2, #PTE_SMALL_AP_URO_SRW
  334. tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
  335. orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
  336. tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
  337. movne r2, #0
  338. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  339. eor r3, r2, #0x0a @ C & small page?
  340. tst r3, #0x0b
  341. biceq r2, r2, #4
  342. #endif
  343. str r2, [r0] @ hardware version
  344. mov r0, r0
  345. #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
  346. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  347. #endif
  348. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  349. #endif
  350. mov pc, lr
  351. __INIT
  352. .type __feroceon_setup, #function
  353. __feroceon_setup:
  354. mov r0, #0
  355. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  356. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  357. #ifdef CONFIG_MMU
  358. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  359. #endif
  360. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  361. mov r0, #4 @ disable write-back on caches explicitly
  362. mcr p15, 7, r0, c15, c0, 0
  363. #endif
  364. adr r5, feroceon_crval
  365. ldmia r5, {r5, r6}
  366. mrc p15, 0, r0, c1, c0 @ get control register v4
  367. bic r0, r0, r5
  368. orr r0, r0, r6
  369. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  370. orr r0, r0, #0x4000 @ .1.. .... .... ....
  371. #endif
  372. mov pc, lr
  373. .size __feroceon_setup, . - __feroceon_setup
  374. /*
  375. * R
  376. * .RVI ZFRS BLDP WCAM
  377. * .011 0001 ..11 0101
  378. *
  379. */
  380. .type feroceon_crval, #object
  381. feroceon_crval:
  382. crval clear=0x00007f3f, mmuset=0x00003135, ucset=0x00001134
  383. __INITDATA
  384. /*
  385. * Purpose : Function pointers used to access above functions - all calls
  386. * come through these
  387. */
  388. .type feroceon_processor_functions, #object
  389. feroceon_processor_functions:
  390. .word v5t_early_abort
  391. .word cpu_feroceon_proc_init
  392. .word cpu_feroceon_proc_fin
  393. .word cpu_feroceon_reset
  394. .word cpu_feroceon_do_idle
  395. .word cpu_feroceon_dcache_clean_area
  396. .word cpu_feroceon_switch_mm
  397. .word cpu_feroceon_set_pte_ext
  398. .word pabort_noifar
  399. .size feroceon_processor_functions, . - feroceon_processor_functions
  400. .section ".rodata"
  401. .type cpu_arch_name, #object
  402. cpu_arch_name:
  403. .asciz "armv5te"
  404. .size cpu_arch_name, . - cpu_arch_name
  405. .type cpu_elf_name, #object
  406. cpu_elf_name:
  407. .asciz "v5"
  408. .size cpu_elf_name, . - cpu_elf_name
  409. .type cpu_feroceon_name, #object
  410. cpu_feroceon_name:
  411. .asciz "Feroceon"
  412. .size cpu_feroceon_name, . - cpu_feroceon_name
  413. .align
  414. .section ".proc.info.init", #alloc, #execinstr
  415. #ifdef CONFIG_CPU_FEROCEON_OLD_ID
  416. .type __feroceon_old_id_proc_info,#object
  417. __feroceon_old_id_proc_info:
  418. .long 0x41069260
  419. .long 0xfffffff0
  420. .long PMD_TYPE_SECT | \
  421. PMD_SECT_BUFFERABLE | \
  422. PMD_SECT_CACHEABLE | \
  423. PMD_BIT4 | \
  424. PMD_SECT_AP_WRITE | \
  425. PMD_SECT_AP_READ
  426. .long PMD_TYPE_SECT | \
  427. PMD_BIT4 | \
  428. PMD_SECT_AP_WRITE | \
  429. PMD_SECT_AP_READ
  430. b __feroceon_setup
  431. .long cpu_arch_name
  432. .long cpu_elf_name
  433. .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
  434. .long cpu_feroceon_name
  435. .long feroceon_processor_functions
  436. .long v4wbi_tlb_fns
  437. .long v4wb_user_fns
  438. .long feroceon_cache_fns
  439. .size __feroceon_old_id_proc_info, . - __feroceon_old_id_proc_info
  440. #endif
  441. .type __feroceon_proc_info,#object
  442. __feroceon_proc_info:
  443. .long 0x56055310
  444. .long 0xfffffff0
  445. .long PMD_TYPE_SECT | \
  446. PMD_SECT_BUFFERABLE | \
  447. PMD_SECT_CACHEABLE | \
  448. PMD_BIT4 | \
  449. PMD_SECT_AP_WRITE | \
  450. PMD_SECT_AP_READ
  451. .long PMD_TYPE_SECT | \
  452. PMD_BIT4 | \
  453. PMD_SECT_AP_WRITE | \
  454. PMD_SECT_AP_READ
  455. b __feroceon_setup
  456. .long cpu_arch_name
  457. .long cpu_elf_name
  458. .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
  459. .long cpu_feroceon_name
  460. .long feroceon_processor_functions
  461. .long v4wbi_tlb_fns
  462. .long v4wb_user_fns
  463. .long feroceon_cache_fns
  464. .size __feroceon_proc_info, . - __feroceon_proc_info