tlb-r8k.c 5.3 KB

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