tlb-r3k.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * r2300.c: R2000 and R3000 specific mmu/cache code.
  3. *
  4. * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
  5. *
  6. * with a lot of changes to make this thing work for R3000s
  7. * Tx39XX R4k style caches added. HK
  8. * Copyright (C) 1998, 1999, 2000 Harald Koerfgen
  9. * Copyright (C) 1998 Gleb Raiko & Vladimir Roganov
  10. * Copyright (C) 2002 Ralf Baechle
  11. * Copyright (C) 2002 Maciej W. Rozycki
  12. */
  13. #include <linux/init.h>
  14. #include <linux/kernel.h>
  15. #include <linux/sched.h>
  16. #include <linux/mm.h>
  17. #include <asm/page.h>
  18. #include <asm/pgtable.h>
  19. #include <asm/mmu_context.h>
  20. #include <asm/system.h>
  21. #include <asm/isadep.h>
  22. #include <asm/io.h>
  23. #include <asm/bootinfo.h>
  24. #include <asm/cpu.h>
  25. #undef DEBUG_TLB
  26. extern void build_tlb_refill_handler(void);
  27. /* CP0 hazard avoidance. */
  28. #define BARRIER \
  29. __asm__ __volatile__( \
  30. ".set push\n\t" \
  31. ".set noreorder\n\t" \
  32. "nop\n\t" \
  33. ".set pop\n\t")
  34. int r3k_have_wired_reg; /* should be in cpu_data? */
  35. /* TLB operations. */
  36. void local_flush_tlb_all(void)
  37. {
  38. unsigned long flags;
  39. unsigned long old_ctx;
  40. int entry;
  41. #ifdef DEBUG_TLB
  42. printk("[tlball]");
  43. #endif
  44. local_irq_save(flags);
  45. old_ctx = read_c0_entryhi() & ASID_MASK;
  46. write_c0_entrylo0(0);
  47. entry = r3k_have_wired_reg ? read_c0_wired() : 8;
  48. for (; entry < current_cpu_data.tlbsize; entry++) {
  49. write_c0_index(entry << 8);
  50. write_c0_entryhi((entry | 0x80000) << 12);
  51. BARRIER;
  52. tlb_write_indexed();
  53. }
  54. write_c0_entryhi(old_ctx);
  55. local_irq_restore(flags);
  56. }
  57. void local_flush_tlb_mm(struct mm_struct *mm)
  58. {
  59. int cpu = smp_processor_id();
  60. if (cpu_context(cpu, mm) != 0) {
  61. #ifdef DEBUG_TLB
  62. printk("[tlbmm<%lu>]", (unsigned long)cpu_context(cpu, mm));
  63. #endif
  64. drop_mmu_context(mm, cpu);
  65. }
  66. }
  67. void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  68. unsigned long end)
  69. {
  70. struct mm_struct *mm = vma->vm_mm;
  71. int cpu = smp_processor_id();
  72. if (cpu_context(cpu, mm) != 0) {
  73. unsigned long size, flags;
  74. #ifdef DEBUG_TLB
  75. printk("[tlbrange<%lu,0x%08lx,0x%08lx>]",
  76. cpu_context(cpu, mm) & ASID_MASK, start, end);
  77. #endif
  78. local_irq_save(flags);
  79. size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
  80. if (size <= current_cpu_data.tlbsize) {
  81. int oldpid = read_c0_entryhi() & ASID_MASK;
  82. int newpid = cpu_context(cpu, mm) & ASID_MASK;
  83. start &= PAGE_MASK;
  84. end += PAGE_SIZE - 1;
  85. end &= PAGE_MASK;
  86. while (start < end) {
  87. int idx;
  88. write_c0_entryhi(start | newpid);
  89. start += PAGE_SIZE; /* BARRIER */
  90. tlb_probe();
  91. idx = read_c0_index();
  92. write_c0_entrylo0(0);
  93. write_c0_entryhi(KSEG0);
  94. if (idx < 0) /* BARRIER */
  95. continue;
  96. tlb_write_indexed();
  97. }
  98. write_c0_entryhi(oldpid);
  99. } else {
  100. drop_mmu_context(mm, cpu);
  101. }
  102. local_irq_restore(flags);
  103. }
  104. }
  105. void local_flush_tlb_kernel_range(unsigned long start, unsigned long end)
  106. {
  107. unsigned long size, flags;
  108. #ifdef DEBUG_TLB
  109. printk("[tlbrange<%lu,0x%08lx,0x%08lx>]", start, end);
  110. #endif
  111. local_irq_save(flags);
  112. size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
  113. if (size <= current_cpu_data.tlbsize) {
  114. int pid = read_c0_entryhi();
  115. start &= PAGE_MASK;
  116. end += PAGE_SIZE - 1;
  117. end &= PAGE_MASK;
  118. while (start < end) {
  119. int idx;
  120. write_c0_entryhi(start);
  121. start += PAGE_SIZE; /* BARRIER */
  122. tlb_probe();
  123. idx = read_c0_index();
  124. write_c0_entrylo0(0);
  125. write_c0_entryhi(KSEG0);
  126. if (idx < 0) /* BARRIER */
  127. continue;
  128. tlb_write_indexed();
  129. }
  130. write_c0_entryhi(pid);
  131. } else {
  132. local_flush_tlb_all();
  133. }
  134. local_irq_restore(flags);
  135. }
  136. void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  137. {
  138. int cpu = smp_processor_id();
  139. if (!vma || cpu_context(cpu, vma->vm_mm) != 0) {
  140. unsigned long flags;
  141. int oldpid, newpid, idx;
  142. #ifdef DEBUG_TLB
  143. printk("[tlbpage<%lu,0x%08lx>]", cpu_context(cpu, vma->vm_mm), page);
  144. #endif
  145. newpid = cpu_context(cpu, vma->vm_mm) & ASID_MASK;
  146. page &= PAGE_MASK;
  147. local_irq_save(flags);
  148. oldpid = read_c0_entryhi() & ASID_MASK;
  149. write_c0_entryhi(page | newpid);
  150. BARRIER;
  151. tlb_probe();
  152. idx = read_c0_index();
  153. write_c0_entrylo0(0);
  154. write_c0_entryhi(KSEG0);
  155. if (idx < 0) /* BARRIER */
  156. goto finish;
  157. tlb_write_indexed();
  158. finish:
  159. write_c0_entryhi(oldpid);
  160. local_irq_restore(flags);
  161. }
  162. }
  163. void __update_tlb(struct vm_area_struct *vma, unsigned long address, pte_t pte)
  164. {
  165. unsigned long flags;
  166. int idx, pid;
  167. /*
  168. * Handle debugger faulting in for debugee.
  169. */
  170. if (current->active_mm != vma->vm_mm)
  171. return;
  172. pid = read_c0_entryhi() & ASID_MASK;
  173. #ifdef DEBUG_TLB
  174. if ((pid != (cpu_context(cpu, vma->vm_mm) & ASID_MASK)) || (cpu_context(cpu, vma->vm_mm) == 0)) {
  175. printk("update_mmu_cache: Wheee, bogus tlbpid mmpid=%lu tlbpid=%d\n",
  176. (cpu_context(cpu, vma->vm_mm)), pid);
  177. }
  178. #endif
  179. local_irq_save(flags);
  180. address &= PAGE_MASK;
  181. write_c0_entryhi(address | pid);
  182. BARRIER;
  183. tlb_probe();
  184. idx = read_c0_index();
  185. write_c0_entrylo0(pte_val(pte));
  186. write_c0_entryhi(address | pid);
  187. if (idx < 0) { /* BARRIER */
  188. tlb_write_random();
  189. } else {
  190. tlb_write_indexed();
  191. }
  192. write_c0_entryhi(pid);
  193. local_irq_restore(flags);
  194. }
  195. void __init add_wired_entry(unsigned long entrylo0, unsigned long entrylo1,
  196. unsigned long entryhi, unsigned long pagemask)
  197. {
  198. unsigned long flags;
  199. unsigned long old_ctx;
  200. static unsigned long wired = 0;
  201. if (r3k_have_wired_reg) { /* TX39XX */
  202. unsigned long old_pagemask;
  203. unsigned long w;
  204. #ifdef DEBUG_TLB
  205. printk("[tlbwired<entry lo0 %8x, hi %8x\n, pagemask %8x>]\n",
  206. entrylo0, entryhi, pagemask);
  207. #endif
  208. local_irq_save(flags);
  209. /* Save old context and create impossible VPN2 value */
  210. old_ctx = read_c0_entryhi() & ASID_MASK;
  211. old_pagemask = read_c0_pagemask();
  212. w = read_c0_wired();
  213. write_c0_wired(w + 1);
  214. write_c0_index(w << 8);
  215. write_c0_pagemask(pagemask);
  216. write_c0_entryhi(entryhi);
  217. write_c0_entrylo0(entrylo0);
  218. BARRIER;
  219. tlb_write_indexed();
  220. write_c0_entryhi(old_ctx);
  221. write_c0_pagemask(old_pagemask);
  222. local_flush_tlb_all();
  223. local_irq_restore(flags);
  224. } else if (wired < 8) {
  225. #ifdef DEBUG_TLB
  226. printk("[tlbwired<entry lo0 %8x, hi %8x\n>]\n",
  227. entrylo0, entryhi);
  228. #endif
  229. local_irq_save(flags);
  230. old_ctx = read_c0_entryhi() & ASID_MASK;
  231. write_c0_entrylo0(entrylo0);
  232. write_c0_entryhi(entryhi);
  233. write_c0_index(wired);
  234. wired++; /* BARRIER */
  235. tlb_write_indexed();
  236. write_c0_entryhi(old_ctx);
  237. local_flush_tlb_all();
  238. local_irq_restore(flags);
  239. }
  240. }
  241. void __cpuinit tlb_init(void)
  242. {
  243. local_flush_tlb_all();
  244. build_tlb_refill_handler();
  245. }