proc-arm1020.S 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. /*
  2. * linux/arch/arm/mm/proc-arm1020.S: MMU functions for ARM1020
  3. *
  4. * Copyright (C) 2000 ARM Limited
  5. * Copyright (C) 2000 Deep Blue Solutions Ltd.
  6. * hacked for non-paged-MM by Hyok S. Choi, 2003.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. *
  23. * These are the low level assembler for performing cache and TLB
  24. * functions on the arm1020.
  25. *
  26. * CONFIG_CPU_ARM1020_CPU_IDLE -> nohlt
  27. */
  28. #include <linux/linkage.h>
  29. #include <linux/init.h>
  30. #include <asm/assembler.h>
  31. #include <asm/asm-offsets.h>
  32. #include <asm/hwcap.h>
  33. #include <asm/pgtable-hwdef.h>
  34. #include <asm/pgtable.h>
  35. #include <asm/ptrace.h>
  36. #include "proc-macros.S"
  37. /*
  38. * This is the maximum size of an area which will be invalidated
  39. * using the single invalidate entry instructions. Anything larger
  40. * than this, and we go for the whole cache.
  41. *
  42. * This value should be chosen such that we choose the cheapest
  43. * alternative.
  44. */
  45. #define MAX_AREA_SIZE 32768
  46. /*
  47. * The size of one data cache line.
  48. */
  49. #define CACHE_DLINESIZE 32
  50. /*
  51. * The number of data cache segments.
  52. */
  53. #define CACHE_DSEGMENTS 16
  54. /*
  55. * The number of lines in a cache segment.
  56. */
  57. #define CACHE_DENTRIES 64
  58. /*
  59. * This is the size at which it becomes more efficient to
  60. * clean the whole cache, rather than using the individual
  61. * cache line maintainence instructions.
  62. */
  63. #define CACHE_DLIMIT 32768
  64. .text
  65. /*
  66. * cpu_arm1020_proc_init()
  67. */
  68. ENTRY(cpu_arm1020_proc_init)
  69. mov pc, lr
  70. /*
  71. * cpu_arm1020_proc_fin()
  72. */
  73. ENTRY(cpu_arm1020_proc_fin)
  74. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  75. bic r0, r0, #0x1000 @ ...i............
  76. bic r0, r0, #0x000e @ ............wca.
  77. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  78. mov pc, lr
  79. /*
  80. * cpu_arm1020_reset(loc)
  81. *
  82. * Perform a soft reset of the system. Put the CPU into the
  83. * same state as it would be if it had been reset, and branch
  84. * to what would be the reset vector.
  85. *
  86. * loc: location to jump to for soft reset
  87. */
  88. .align 5
  89. ENTRY(cpu_arm1020_reset)
  90. mov ip, #0
  91. mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
  92. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  93. #ifdef CONFIG_MMU
  94. mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
  95. #endif
  96. mrc p15, 0, ip, c1, c0, 0 @ ctrl register
  97. bic ip, ip, #0x000f @ ............wcam
  98. bic ip, ip, #0x1100 @ ...i...s........
  99. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  100. mov pc, r0
  101. /*
  102. * cpu_arm1020_do_idle()
  103. */
  104. .align 5
  105. ENTRY(cpu_arm1020_do_idle)
  106. mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
  107. mov pc, lr
  108. /* ================================= CACHE ================================ */
  109. .align 5
  110. /*
  111. * flush_user_cache_all()
  112. *
  113. * Invalidate all cache entries in a particular address
  114. * space.
  115. */
  116. ENTRY(arm1020_flush_user_cache_all)
  117. /* FALLTHROUGH */
  118. /*
  119. * flush_kern_cache_all()
  120. *
  121. * Clean and invalidate the entire cache.
  122. */
  123. ENTRY(arm1020_flush_kern_cache_all)
  124. mov r2, #VM_EXEC
  125. mov ip, #0
  126. __flush_whole_cache:
  127. #ifndef CONFIG_CPU_DCACHE_DISABLE
  128. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  129. mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 16 segments
  130. 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
  131. 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
  132. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  133. subs r3, r3, #1 << 26
  134. bcs 2b @ entries 63 to 0
  135. subs r1, r1, #1 << 5
  136. bcs 1b @ segments 15 to 0
  137. #endif
  138. tst r2, #VM_EXEC
  139. #ifndef CONFIG_CPU_ICACHE_DISABLE
  140. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  141. #endif
  142. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  143. mov pc, lr
  144. /*
  145. * flush_user_cache_range(start, end, flags)
  146. *
  147. * Invalidate a range of cache entries in the specified
  148. * address space.
  149. *
  150. * - start - start address (inclusive)
  151. * - end - end address (exclusive)
  152. * - flags - vm_flags for this space
  153. */
  154. ENTRY(arm1020_flush_user_cache_range)
  155. mov ip, #0
  156. sub r3, r1, r0 @ calculate total size
  157. cmp r3, #CACHE_DLIMIT
  158. bhs __flush_whole_cache
  159. #ifndef CONFIG_CPU_DCACHE_DISABLE
  160. mcr p15, 0, ip, c7, c10, 4
  161. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  162. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  163. add r0, r0, #CACHE_DLINESIZE
  164. cmp r0, r1
  165. blo 1b
  166. #endif
  167. tst r2, #VM_EXEC
  168. #ifndef CONFIG_CPU_ICACHE_DISABLE
  169. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  170. #endif
  171. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  172. mov pc, lr
  173. /*
  174. * coherent_kern_range(start, end)
  175. *
  176. * Ensure coherency between the Icache and the Dcache in the
  177. * region described by start. If you have non-snooping
  178. * Harvard caches, you need to implement this function.
  179. *
  180. * - start - virtual start address
  181. * - end - virtual end address
  182. */
  183. ENTRY(arm1020_coherent_kern_range)
  184. /* FALLTRHOUGH */
  185. /*
  186. * coherent_user_range(start, end)
  187. *
  188. * Ensure coherency between the Icache and the Dcache in the
  189. * region described by start. If you have non-snooping
  190. * Harvard caches, you need to implement this function.
  191. *
  192. * - start - virtual start address
  193. * - end - virtual end address
  194. */
  195. ENTRY(arm1020_coherent_user_range)
  196. mov ip, #0
  197. bic r0, r0, #CACHE_DLINESIZE - 1
  198. mcr p15, 0, ip, c7, c10, 4
  199. 1:
  200. #ifndef CONFIG_CPU_DCACHE_DISABLE
  201. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  202. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  203. #endif
  204. #ifndef CONFIG_CPU_ICACHE_DISABLE
  205. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  206. #endif
  207. add r0, r0, #CACHE_DLINESIZE
  208. cmp r0, r1
  209. blo 1b
  210. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  211. mov pc, lr
  212. /*
  213. * flush_kern_dcache_area(void *addr, size_t size)
  214. *
  215. * Ensure no D cache aliasing occurs, either with itself or
  216. * the I cache
  217. *
  218. * - addr - kernel address
  219. * - size - region size
  220. */
  221. ENTRY(arm1020_flush_kern_dcache_area)
  222. mov ip, #0
  223. #ifndef CONFIG_CPU_DCACHE_DISABLE
  224. add r1, r0, r1
  225. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  226. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  227. add r0, r0, #CACHE_DLINESIZE
  228. cmp r0, r1
  229. blo 1b
  230. #endif
  231. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  232. mov pc, lr
  233. /*
  234. * dma_inv_range(start, end)
  235. *
  236. * Invalidate (discard) the specified virtual address range.
  237. * May not write back any entries. If 'start' or 'end'
  238. * are not cache line aligned, those lines must be written
  239. * back.
  240. *
  241. * - start - virtual start address
  242. * - end - virtual end address
  243. *
  244. * (same as v4wb)
  245. */
  246. arm1020_dma_inv_range:
  247. mov ip, #0
  248. #ifndef CONFIG_CPU_DCACHE_DISABLE
  249. tst r0, #CACHE_DLINESIZE - 1
  250. bic r0, r0, #CACHE_DLINESIZE - 1
  251. mcrne p15, 0, ip, c7, c10, 4
  252. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  253. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  254. tst r1, #CACHE_DLINESIZE - 1
  255. mcrne p15, 0, ip, c7, c10, 4
  256. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  257. mcrne p15, 0, ip, c7, c10, 4 @ drain WB
  258. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  259. add r0, r0, #CACHE_DLINESIZE
  260. cmp r0, r1
  261. blo 1b
  262. #endif
  263. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  264. mov pc, lr
  265. /*
  266. * dma_clean_range(start, end)
  267. *
  268. * Clean the specified virtual address range.
  269. *
  270. * - start - virtual start address
  271. * - end - virtual end address
  272. *
  273. * (same as v4wb)
  274. */
  275. arm1020_dma_clean_range:
  276. mov ip, #0
  277. #ifndef CONFIG_CPU_DCACHE_DISABLE
  278. bic r0, r0, #CACHE_DLINESIZE - 1
  279. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  280. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  281. add r0, r0, #CACHE_DLINESIZE
  282. cmp r0, r1
  283. blo 1b
  284. #endif
  285. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  286. mov pc, lr
  287. /*
  288. * dma_flush_range(start, end)
  289. *
  290. * Clean and invalidate the specified virtual address range.
  291. *
  292. * - start - virtual start address
  293. * - end - virtual end address
  294. */
  295. ENTRY(arm1020_dma_flush_range)
  296. mov ip, #0
  297. #ifndef CONFIG_CPU_DCACHE_DISABLE
  298. bic r0, r0, #CACHE_DLINESIZE - 1
  299. mcr p15, 0, ip, c7, c10, 4
  300. 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
  301. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  302. add r0, r0, #CACHE_DLINESIZE
  303. cmp r0, r1
  304. blo 1b
  305. #endif
  306. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  307. mov pc, lr
  308. /*
  309. * dma_map_area(start, size, dir)
  310. * - start - kernel virtual start address
  311. * - size - size of region
  312. * - dir - DMA direction
  313. */
  314. ENTRY(arm1020_dma_map_area)
  315. add r1, r1, r0
  316. cmp r2, #DMA_TO_DEVICE
  317. beq arm1020_dma_clean_range
  318. bcs arm1020_dma_inv_range
  319. b arm1020_dma_flush_range
  320. ENDPROC(arm1020_dma_map_area)
  321. /*
  322. * dma_unmap_area(start, size, dir)
  323. * - start - kernel virtual start address
  324. * - size - size of region
  325. * - dir - DMA direction
  326. */
  327. ENTRY(arm1020_dma_unmap_area)
  328. mov pc, lr
  329. ENDPROC(arm1020_dma_unmap_area)
  330. ENTRY(arm1020_cache_fns)
  331. .long arm1020_flush_kern_cache_all
  332. .long arm1020_flush_user_cache_all
  333. .long arm1020_flush_user_cache_range
  334. .long arm1020_coherent_kern_range
  335. .long arm1020_coherent_user_range
  336. .long arm1020_flush_kern_dcache_area
  337. .long arm1020_dma_map_area
  338. .long arm1020_dma_unmap_area
  339. .long arm1020_dma_flush_range
  340. .align 5
  341. ENTRY(cpu_arm1020_dcache_clean_area)
  342. #ifndef CONFIG_CPU_DCACHE_DISABLE
  343. mov ip, #0
  344. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  345. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  346. add r0, r0, #CACHE_DLINESIZE
  347. subs r1, r1, #CACHE_DLINESIZE
  348. bhi 1b
  349. #endif
  350. mov pc, lr
  351. /* =============================== PageTable ============================== */
  352. /*
  353. * cpu_arm1020_switch_mm(pgd)
  354. *
  355. * Set the translation base pointer to be as described by pgd.
  356. *
  357. * pgd: new page tables
  358. */
  359. .align 5
  360. ENTRY(cpu_arm1020_switch_mm)
  361. #ifdef CONFIG_MMU
  362. #ifndef CONFIG_CPU_DCACHE_DISABLE
  363. mcr p15, 0, r3, c7, c10, 4
  364. mov r1, #0xF @ 16 segments
  365. 1: mov r3, #0x3F @ 64 entries
  366. 2: mov ip, r3, LSL #26 @ shift up entry
  367. orr ip, ip, r1, LSL #5 @ shift in/up index
  368. mcr p15, 0, ip, c7, c14, 2 @ Clean & Inval DCache entry
  369. mov ip, #0
  370. mcr p15, 0, ip, c7, c10, 4
  371. subs r3, r3, #1
  372. cmp r3, #0
  373. bge 2b @ entries 3F to 0
  374. subs r1, r1, #1
  375. cmp r1, #0
  376. bge 1b @ segments 15 to 0
  377. #endif
  378. mov r1, #0
  379. #ifndef CONFIG_CPU_ICACHE_DISABLE
  380. mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
  381. #endif
  382. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  383. mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
  384. mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
  385. #endif /* CONFIG_MMU */
  386. mov pc, lr
  387. /*
  388. * cpu_arm1020_set_pte(ptep, pte)
  389. *
  390. * Set a PTE and flush it out
  391. */
  392. .align 5
  393. ENTRY(cpu_arm1020_set_pte_ext)
  394. #ifdef CONFIG_MMU
  395. armv3_set_pte_ext
  396. mov r0, r0
  397. #ifndef CONFIG_CPU_DCACHE_DISABLE
  398. mcr p15, 0, r0, c7, c10, 4
  399. mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  400. #endif
  401. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  402. #endif /* CONFIG_MMU */
  403. mov pc, lr
  404. __INIT
  405. .type __arm1020_setup, #function
  406. __arm1020_setup:
  407. mov r0, #0
  408. mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
  409. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
  410. #ifdef CONFIG_MMU
  411. mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
  412. #endif
  413. adr r5, arm1020_crval
  414. ldmia r5, {r5, r6}
  415. mrc p15, 0, r0, c1, c0 @ get control register v4
  416. bic r0, r0, r5
  417. orr r0, r0, r6
  418. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  419. orr r0, r0, #0x4000 @ .R.. .... .... ....
  420. #endif
  421. mov pc, lr
  422. .size __arm1020_setup, . - __arm1020_setup
  423. /*
  424. * R
  425. * .RVI ZFRS BLDP WCAM
  426. * .011 1001 ..11 0101
  427. */
  428. .type arm1020_crval, #object
  429. arm1020_crval:
  430. crval clear=0x0000593f, mmuset=0x00003935, ucset=0x00001930
  431. __INITDATA
  432. /*
  433. * Purpose : Function pointers used to access above functions - all calls
  434. * come through these
  435. */
  436. .type arm1020_processor_functions, #object
  437. arm1020_processor_functions:
  438. .word v4t_early_abort
  439. .word legacy_pabort
  440. .word cpu_arm1020_proc_init
  441. .word cpu_arm1020_proc_fin
  442. .word cpu_arm1020_reset
  443. .word cpu_arm1020_do_idle
  444. .word cpu_arm1020_dcache_clean_area
  445. .word cpu_arm1020_switch_mm
  446. .word cpu_arm1020_set_pte_ext
  447. .size arm1020_processor_functions, . - arm1020_processor_functions
  448. .section ".rodata"
  449. .type cpu_arch_name, #object
  450. cpu_arch_name:
  451. .asciz "armv5t"
  452. .size cpu_arch_name, . - cpu_arch_name
  453. .type cpu_elf_name, #object
  454. cpu_elf_name:
  455. .asciz "v5"
  456. .size cpu_elf_name, . - cpu_elf_name
  457. .type cpu_arm1020_name, #object
  458. cpu_arm1020_name:
  459. .ascii "ARM1020"
  460. #ifndef CONFIG_CPU_ICACHE_DISABLE
  461. .ascii "i"
  462. #endif
  463. #ifndef CONFIG_CPU_DCACHE_DISABLE
  464. .ascii "d"
  465. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  466. .ascii "(wt)"
  467. #else
  468. .ascii "(wb)"
  469. #endif
  470. #endif
  471. #ifndef CONFIG_CPU_BPREDICT_DISABLE
  472. .ascii "B"
  473. #endif
  474. #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
  475. .ascii "RR"
  476. #endif
  477. .ascii "\0"
  478. .size cpu_arm1020_name, . - cpu_arm1020_name
  479. .align
  480. .section ".proc.info.init", #alloc, #execinstr
  481. .type __arm1020_proc_info,#object
  482. __arm1020_proc_info:
  483. .long 0x4104a200 @ ARM 1020T (Architecture v5T)
  484. .long 0xff0ffff0
  485. .long PMD_TYPE_SECT | \
  486. PMD_SECT_AP_WRITE | \
  487. PMD_SECT_AP_READ
  488. .long PMD_TYPE_SECT | \
  489. PMD_SECT_AP_WRITE | \
  490. PMD_SECT_AP_READ
  491. b __arm1020_setup
  492. .long cpu_arch_name
  493. .long cpu_elf_name
  494. .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
  495. .long cpu_arm1020_name
  496. .long arm1020_processor_functions
  497. .long v4wbi_tlb_fns
  498. .long v4wb_user_fns
  499. .long arm1020_cache_fns
  500. .size __arm1020_proc_info, . - __arm1020_proc_info