tlb-r8k.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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) 1996 David S. Miller (davem@davemloft.net)
  7. * Copyright (C) 1997, 1998, 1999, 2000 Ralf Baechle ralf@gnu.org
  8. * Carsten Langgaard, carstenl@mips.com
  9. * Copyright (C) 2002 MIPS Technologies, Inc. All rights reserved.
  10. */
  11. #include <linux/sched.h>
  12. #include <linux/smp.h>
  13. #include <linux/mm.h>
  14. #include <asm/cpu.h>
  15. #include <asm/bootinfo.h>
  16. #include <asm/mmu_context.h>
  17. #include <asm/pgtable.h>
  18. extern void build_tlb_refill_handler(void);
  19. #define TFP_TLB_SIZE 384
  20. #define TFP_TLB_SET_SHIFT 7
  21. /* CP0 hazard avoidance. */
  22. #define BARRIER __asm__ __volatile__(".set noreorder\n\t" \
  23. "nop; nop; nop; nop; nop; nop;\n\t" \
  24. ".set reorder\n\t")
  25. void local_flush_tlb_all(void)
  26. {
  27. unsigned long flags;
  28. unsigned long old_ctx;
  29. int entry;
  30. local_irq_save(flags);
  31. /* Save old context and create impossible VPN2 value */
  32. old_ctx = read_c0_entryhi();
  33. write_c0_entrylo(0);
  34. for (entry = 0; entry < TFP_TLB_SIZE; entry++) {
  35. write_c0_tlbset(entry >> TFP_TLB_SET_SHIFT);
  36. write_c0_vaddr(entry << PAGE_SHIFT);
  37. write_c0_entryhi(CKSEG0 + (entry << (PAGE_SHIFT + 1)));
  38. mtc0_tlbw_hazard();
  39. tlb_write();
  40. }
  41. tlbw_use_hazard();
  42. write_c0_entryhi(old_ctx);
  43. local_irq_restore(flags);
  44. }
  45. void local_flush_tlb_mm(struct mm_struct *mm)
  46. {
  47. int cpu = smp_processor_id();
  48. if (cpu_context(cpu, mm) != 0)
  49. drop_mmu_context(mm, cpu);
  50. }
  51. void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  52. unsigned long end)
  53. {
  54. struct mm_struct *mm = vma->vm_mm;
  55. int cpu = smp_processor_id();
  56. unsigned long flags;
  57. int oldpid, newpid, size;
  58. if (!cpu_context(cpu, mm))
  59. return;
  60. size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
  61. size = (size + 1) >> 1;
  62. local_irq_save(flags);
  63. if (size > TFP_TLB_SIZE / 2) {
  64. drop_mmu_context(mm, cpu);
  65. goto out_restore;
  66. }
  67. oldpid = read_c0_entryhi();
  68. newpid = cpu_asid(cpu, mm);
  69. write_c0_entrylo(0);
  70. start &= PAGE_MASK;
  71. end += (PAGE_SIZE - 1);
  72. end &= PAGE_MASK;
  73. while (start < end) {
  74. signed long idx;
  75. write_c0_vaddr(start);
  76. write_c0_entryhi(start);
  77. start += PAGE_SIZE;
  78. tlb_probe();
  79. idx = read_c0_tlbset();
  80. if (idx < 0)
  81. continue;
  82. write_c0_entryhi(CKSEG0 + (idx << (PAGE_SHIFT + 1)));
  83. tlb_write();
  84. }
  85. write_c0_entryhi(oldpid);
  86. out_restore:
  87. local_irq_restore(flags);
  88. }
  89. /* Usable for KV1 addresses only! */
  90. void local_flush_tlb_kernel_range(unsigned long start, unsigned long end)
  91. {
  92. unsigned long size, flags;
  93. size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
  94. size = (size + 1) >> 1;
  95. if (size > TFP_TLB_SIZE / 2) {
  96. local_flush_tlb_all();
  97. return;
  98. }
  99. local_irq_save(flags);
  100. write_c0_entrylo(0);
  101. start &= PAGE_MASK;
  102. end += (PAGE_SIZE - 1);
  103. end &= PAGE_MASK;
  104. while (start < end) {
  105. signed long idx;
  106. write_c0_vaddr(start);
  107. write_c0_entryhi(start);
  108. start += PAGE_SIZE;
  109. tlb_probe();
  110. idx = read_c0_tlbset();
  111. if (idx < 0)
  112. continue;
  113. write_c0_entryhi(CKSEG0 + (idx << (PAGE_SHIFT + 1)));
  114. tlb_write();
  115. }
  116. local_irq_restore(flags);
  117. }
  118. void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  119. {
  120. int cpu = smp_processor_id();
  121. unsigned long flags;
  122. int oldpid, newpid;
  123. signed long idx;
  124. if (!cpu_context(cpu, vma->vm_mm))
  125. return;
  126. newpid = cpu_asid(cpu, vma->vm_mm);
  127. page &= PAGE_MASK;
  128. local_irq_save(flags);
  129. oldpid = read_c0_entryhi();
  130. write_c0_vaddr(page);
  131. write_c0_entryhi(newpid);
  132. tlb_probe();
  133. idx = read_c0_tlbset();
  134. if (idx < 0)
  135. goto finish;
  136. write_c0_entrylo(0);
  137. write_c0_entryhi(CKSEG0 + (idx << (PAGE_SHIFT + 1)));
  138. tlb_write();
  139. finish:
  140. write_c0_entryhi(oldpid);
  141. local_irq_restore(flags);
  142. }
  143. /*
  144. * We will need multiple versions of update_mmu_cache(), one that just
  145. * updates the TLB with the new pte(s), and another which also checks
  146. * for the R4k "end of page" hardware bug and does the needy.
  147. */
  148. void __update_tlb(struct vm_area_struct * vma, unsigned long address, pte_t pte)
  149. {
  150. unsigned long flags;
  151. pgd_t *pgdp;
  152. pmd_t *pmdp;
  153. pte_t *ptep;
  154. int pid;
  155. /*
  156. * Handle debugger faulting in for debugee.
  157. */
  158. if (current->active_mm != vma->vm_mm)
  159. return;
  160. pid = read_c0_entryhi() & ASID_MASK;
  161. local_irq_save(flags);
  162. address &= PAGE_MASK;
  163. write_c0_vaddr(address);
  164. write_c0_entryhi(pid);
  165. pgdp = pgd_offset(vma->vm_mm, address);
  166. pmdp = pmd_offset(pgdp, address);
  167. ptep = pte_offset_map(pmdp, address);
  168. tlb_probe();
  169. write_c0_entrylo(pte_val(*ptep++) >> 6);
  170. tlb_write();
  171. write_c0_entryhi(pid);
  172. local_irq_restore(flags);
  173. }
  174. static void probe_tlb(unsigned long config)
  175. {
  176. struct cpuinfo_mips *c = &current_cpu_data;
  177. c->tlbsize = 3 * 128; /* 3 sets each 128 entries */
  178. }
  179. void tlb_init(void)
  180. {
  181. unsigned int config = read_c0_config();
  182. unsigned long status;
  183. probe_tlb(config);
  184. status = read_c0_status();
  185. status &= ~(ST0_UPS | ST0_KPS);
  186. #ifdef CONFIG_PAGE_SIZE_4KB
  187. status |= (TFP_PAGESIZE_4K << 32) | (TFP_PAGESIZE_4K << 36);
  188. #elif defined(CONFIG_PAGE_SIZE_8KB)
  189. status |= (TFP_PAGESIZE_8K << 32) | (TFP_PAGESIZE_8K << 36);
  190. #elif defined(CONFIG_PAGE_SIZE_16KB)
  191. status |= (TFP_PAGESIZE_16K << 32) | (TFP_PAGESIZE_16K << 36);
  192. #elif defined(CONFIG_PAGE_SIZE_64KB)
  193. status |= (TFP_PAGESIZE_64K << 32) | (TFP_PAGESIZE_64K << 36);
  194. #endif
  195. write_c0_status(status);
  196. write_c0_wired(0);
  197. local_flush_tlb_all();
  198. build_tlb_refill_handler();
  199. }