tlb-r3k.c 6.4 KB

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