tlb-andes.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1997, 1998, 1999 Ralf Baechle (ralf@gnu.org)
  7. * Copyright (C) 1999 Silicon Graphics, Inc.
  8. * Copyright (C) 2000 Kanoj Sarcar (kanoj@sgi.com)
  9. */
  10. #include <linux/init.h>
  11. #include <linux/kernel.h>
  12. #include <linux/sched.h>
  13. #include <linux/mm.h>
  14. #include <asm/page.h>
  15. #include <asm/pgtable.h>
  16. #include <asm/system.h>
  17. #include <asm/mmu_context.h>
  18. extern void build_tlb_refill_handler(void);
  19. #define NTLB_ENTRIES 64
  20. #define NTLB_ENTRIES_HALF 32
  21. void local_flush_tlb_all(void)
  22. {
  23. unsigned long flags;
  24. unsigned long old_ctx;
  25. unsigned long entry;
  26. local_irq_save(flags);
  27. /* Save old context and create impossible VPN2 value */
  28. old_ctx = read_c0_entryhi() & ASID_MASK;
  29. write_c0_entryhi(CKSEG0);
  30. write_c0_entrylo0(0);
  31. write_c0_entrylo1(0);
  32. entry = read_c0_wired();
  33. /* Blast 'em all away. */
  34. while (entry < NTLB_ENTRIES) {
  35. write_c0_index(entry);
  36. tlb_write_indexed();
  37. entry++;
  38. }
  39. write_c0_entryhi(old_ctx);
  40. local_irq_restore(flags);
  41. }
  42. void local_flush_tlb_mm(struct mm_struct *mm)
  43. {
  44. int cpu = smp_processor_id();
  45. if (cpu_context(cpu, mm) != 0) {
  46. drop_mmu_context(mm,cpu);
  47. }
  48. }
  49. void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  50. unsigned long end)
  51. {
  52. struct mm_struct *mm = vma->vm_mm;
  53. int cpu = smp_processor_id();
  54. if (cpu_context(cpu, mm) != 0) {
  55. unsigned long flags;
  56. int size;
  57. local_irq_save(flags);
  58. size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
  59. size = (size + 1) >> 1;
  60. if (size <= NTLB_ENTRIES_HALF) {
  61. int oldpid = (read_c0_entryhi() & ASID_MASK);
  62. int newpid = (cpu_context(smp_processor_id(), mm)
  63. & ASID_MASK);
  64. start &= (PAGE_MASK << 1);
  65. end += ((PAGE_SIZE << 1) - 1);
  66. end &= (PAGE_MASK << 1);
  67. while(start < end) {
  68. int idx;
  69. write_c0_entryhi(start | newpid);
  70. start += (PAGE_SIZE << 1);
  71. tlb_probe();
  72. idx = read_c0_index();
  73. write_c0_entrylo0(0);
  74. write_c0_entrylo1(0);
  75. write_c0_entryhi(CKSEG0);
  76. if(idx < 0)
  77. continue;
  78. tlb_write_indexed();
  79. }
  80. write_c0_entryhi(oldpid);
  81. } else {
  82. drop_mmu_context(mm, cpu);
  83. }
  84. local_irq_restore(flags);
  85. }
  86. }
  87. void local_flush_tlb_kernel_range(unsigned long start, unsigned long end)
  88. {
  89. unsigned long flags;
  90. int size;
  91. size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
  92. size = (size + 1) >> 1;
  93. local_irq_save(flags);
  94. if (size <= NTLB_ENTRIES_HALF) {
  95. int pid = read_c0_entryhi();
  96. start &= (PAGE_MASK << 1);
  97. end += ((PAGE_SIZE << 1) - 1);
  98. end &= (PAGE_MASK << 1);
  99. while (start < end) {
  100. int idx;
  101. write_c0_entryhi(start);
  102. start += (PAGE_SIZE << 1);
  103. tlb_probe();
  104. idx = read_c0_index();
  105. write_c0_entrylo0(0);
  106. write_c0_entrylo1(0);
  107. write_c0_entryhi(CKSEG0 + (idx << (PAGE_SHIFT+1)));
  108. if (idx < 0)
  109. continue;
  110. tlb_write_indexed();
  111. }
  112. write_c0_entryhi(pid);
  113. } else {
  114. local_flush_tlb_all();
  115. }
  116. local_irq_restore(flags);
  117. }
  118. void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  119. {
  120. if (cpu_context(smp_processor_id(), vma->vm_mm) != 0) {
  121. unsigned long flags;
  122. int oldpid, newpid, idx;
  123. newpid = (cpu_context(smp_processor_id(), vma->vm_mm) &
  124. ASID_MASK);
  125. page &= (PAGE_MASK << 1);
  126. local_irq_save(flags);
  127. oldpid = (read_c0_entryhi() & ASID_MASK);
  128. write_c0_entryhi(page | newpid);
  129. tlb_probe();
  130. idx = read_c0_index();
  131. write_c0_entrylo0(0);
  132. write_c0_entrylo1(0);
  133. write_c0_entryhi(CKSEG0);
  134. if (idx < 0)
  135. goto finish;
  136. tlb_write_indexed();
  137. finish:
  138. write_c0_entryhi(oldpid);
  139. local_irq_restore(flags);
  140. }
  141. }
  142. /*
  143. * This one is only used for pages with the global bit set so we don't care
  144. * much about the ASID.
  145. */
  146. void local_flush_tlb_one(unsigned long page)
  147. {
  148. unsigned long flags;
  149. int oldpid, idx;
  150. local_irq_save(flags);
  151. page &= (PAGE_MASK << 1);
  152. oldpid = read_c0_entryhi() & 0xff;
  153. write_c0_entryhi(page);
  154. tlb_probe();
  155. idx = read_c0_index();
  156. write_c0_entrylo0(0);
  157. write_c0_entrylo1(0);
  158. if (idx >= 0) {
  159. /* Make sure all entries differ. */
  160. write_c0_entryhi(CKSEG0+(idx<<(PAGE_SHIFT+1)));
  161. tlb_write_indexed();
  162. }
  163. write_c0_entryhi(oldpid);
  164. local_irq_restore(flags);
  165. }
  166. /* XXX Simplify this. On the R10000 writing a TLB entry for an virtual
  167. address that already exists will overwrite the old entry and not result
  168. in TLB malfunction or TLB shutdown. */
  169. void __update_tlb(struct vm_area_struct * vma, unsigned long address, pte_t pte)
  170. {
  171. unsigned long flags;
  172. pgd_t *pgdp;
  173. pmd_t *pmdp;
  174. pte_t *ptep;
  175. int idx, pid;
  176. /*
  177. * Handle debugger faulting in for debugee.
  178. */
  179. if (current->active_mm != vma->vm_mm)
  180. return;
  181. pid = read_c0_entryhi() & ASID_MASK;
  182. if ((pid != (cpu_context(smp_processor_id(), vma->vm_mm) & ASID_MASK))
  183. || (cpu_context(smp_processor_id(), vma->vm_mm) == 0)) {
  184. printk(KERN_WARNING
  185. "%s: Wheee, bogus tlbpid mmpid=%d tlbpid=%d\n",
  186. __FUNCTION__, (int) (cpu_context(smp_processor_id(),
  187. vma->vm_mm) & ASID_MASK), pid);
  188. }
  189. local_irq_save(flags);
  190. address &= (PAGE_MASK << 1);
  191. write_c0_entryhi(address | (pid));
  192. pgdp = pgd_offset(vma->vm_mm, address);
  193. tlb_probe();
  194. pmdp = pmd_offset(pgdp, address);
  195. idx = read_c0_index();
  196. ptep = pte_offset_map(pmdp, address);
  197. write_c0_entrylo0(pte_val(*ptep++) >> 6);
  198. write_c0_entrylo1(pte_val(*ptep) >> 6);
  199. write_c0_entryhi(address | pid);
  200. if (idx < 0) {
  201. tlb_write_random();
  202. } else {
  203. tlb_write_indexed();
  204. }
  205. write_c0_entryhi(pid);
  206. local_irq_restore(flags);
  207. }
  208. void __init tlb_init(void)
  209. {
  210. /*
  211. * You should never change this register:
  212. * - On R4600 1.7 the tlbp never hits for pages smaller than
  213. * the value in the c0_pagemask register.
  214. * - The entire mm handling assumes the c0_pagemask register to
  215. * be set for 4kb pages.
  216. */
  217. write_c0_pagemask(PM_4K);
  218. write_c0_wired(0);
  219. write_c0_framemask(0);
  220. /* From this point on the ARC firmware is dead. */
  221. local_flush_tlb_all();
  222. /* Did I tell you that ARC SUCKS? */
  223. build_tlb_refill_handler();
  224. }