proc-feroceon.S 13 KB

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