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 (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 flags;
  74. int size;
  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 flags;
  109. int size;
  110. #ifdef DEBUG_TLB
  111. printk("[tlbrange<%lu,0x%08lx,0x%08lx>]", start, end);
  112. #endif
  113. local_irq_save(flags);
  114. size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
  115. if (size <= current_cpu_data.tlbsize) {
  116. int pid = read_c0_entryhi();
  117. start &= PAGE_MASK;
  118. end += PAGE_SIZE - 1;
  119. end &= PAGE_MASK;
  120. while (start < end) {
  121. int idx;
  122. write_c0_entryhi(start);
  123. start += PAGE_SIZE; /* BARRIER */
  124. tlb_probe();
  125. idx = read_c0_index();
  126. write_c0_entrylo0(0);
  127. write_c0_entryhi(KSEG0);
  128. if (idx < 0) /* BARRIER */
  129. continue;
  130. tlb_write_indexed();
  131. }
  132. write_c0_entryhi(pid);
  133. } else {
  134. local_flush_tlb_all();
  135. }
  136. local_irq_restore(flags);
  137. }
  138. void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  139. {
  140. int cpu = smp_processor_id();
  141. if (!vma || cpu_context(cpu, vma->vm_mm) != 0) {
  142. unsigned long flags;
  143. int oldpid, newpid, idx;
  144. #ifdef DEBUG_TLB
  145. printk("[tlbpage<%lu,0x%08lx>]", cpu_context(cpu, vma->vm_mm), page);
  146. #endif
  147. newpid = cpu_context(cpu, vma->vm_mm) & ASID_MASK;
  148. page &= PAGE_MASK;
  149. local_irq_save(flags);
  150. oldpid = read_c0_entryhi() & ASID_MASK;
  151. write_c0_entryhi(page | newpid);
  152. BARRIER;
  153. tlb_probe();
  154. idx = read_c0_index();
  155. write_c0_entrylo0(0);
  156. write_c0_entryhi(KSEG0);
  157. if (idx < 0) /* BARRIER */
  158. goto finish;
  159. tlb_write_indexed();
  160. finish:
  161. write_c0_entryhi(oldpid);
  162. local_irq_restore(flags);
  163. }
  164. }
  165. void __update_tlb(struct vm_area_struct *vma, unsigned long address, pte_t pte)
  166. {
  167. unsigned long flags;
  168. int idx, pid;
  169. /*
  170. * Handle debugger faulting in for debugee.
  171. */
  172. if (current->active_mm != vma->vm_mm)
  173. return;
  174. pid = read_c0_entryhi() & ASID_MASK;
  175. #ifdef DEBUG_TLB
  176. if ((pid != (cpu_context(cpu, vma->vm_mm) & ASID_MASK)) || (cpu_context(cpu, vma->vm_mm) == 0)) {
  177. printk("update_mmu_cache: Wheee, bogus tlbpid mmpid=%lu tlbpid=%d\n",
  178. (cpu_context(cpu, vma->vm_mm)), pid);
  179. }
  180. #endif
  181. local_irq_save(flags);
  182. address &= PAGE_MASK;
  183. write_c0_entryhi(address | pid);
  184. BARRIER;
  185. tlb_probe();
  186. idx = read_c0_index();
  187. write_c0_entrylo0(pte_val(pte));
  188. write_c0_entryhi(address | pid);
  189. if (idx < 0) { /* BARRIER */
  190. tlb_write_random();
  191. } else {
  192. tlb_write_indexed();
  193. }
  194. write_c0_entryhi(pid);
  195. local_irq_restore(flags);
  196. }
  197. void __init add_wired_entry(unsigned long entrylo0, unsigned long entrylo1,
  198. unsigned long entryhi, unsigned long pagemask)
  199. {
  200. unsigned long flags;
  201. unsigned long old_ctx;
  202. static unsigned long wired = 0;
  203. if (r3k_have_wired_reg) { /* TX39XX */
  204. unsigned long old_pagemask;
  205. unsigned long w;
  206. #ifdef DEBUG_TLB
  207. printk("[tlbwired<entry lo0 %8x, hi %8x\n, pagemask %8x>]\n",
  208. entrylo0, entryhi, pagemask);
  209. #endif
  210. local_irq_save(flags);
  211. /* Save old context and create impossible VPN2 value */
  212. old_ctx = read_c0_entryhi() & ASID_MASK;
  213. old_pagemask = read_c0_pagemask();
  214. w = read_c0_wired();
  215. write_c0_wired(w + 1);
  216. write_c0_index(w << 8);
  217. write_c0_pagemask(pagemask);
  218. write_c0_entryhi(entryhi);
  219. write_c0_entrylo0(entrylo0);
  220. BARRIER;
  221. tlb_write_indexed();
  222. write_c0_entryhi(old_ctx);
  223. write_c0_pagemask(old_pagemask);
  224. local_flush_tlb_all();
  225. local_irq_restore(flags);
  226. } else if (wired < 8) {
  227. #ifdef DEBUG_TLB
  228. printk("[tlbwired<entry lo0 %8x, hi %8x\n>]\n",
  229. entrylo0, entryhi);
  230. #endif
  231. local_irq_save(flags);
  232. old_ctx = read_c0_entryhi() & ASID_MASK;
  233. write_c0_entrylo0(entrylo0);
  234. write_c0_entryhi(entryhi);
  235. write_c0_index(wired);
  236. wired++; /* BARRIER */
  237. tlb_write_indexed();
  238. write_c0_entryhi(old_ctx);
  239. local_flush_tlb_all();
  240. local_irq_restore(flags);
  241. }
  242. }
  243. void __cpuinit tlb_init(void)
  244. {
  245. local_flush_tlb_all();
  246. build_tlb_refill_handler();
  247. }