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 (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/init.h>
  12. #include <linux/sched.h>
  13. #include <linux/smp.h>
  14. #include <linux/mm.h>
  15. #include <asm/cpu.h>
  16. #include <asm/bootinfo.h>
  17. #include <asm/mmu_context.h>
  18. #include <asm/pgtable.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 size, flags;
  94. size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
  95. size = (size + 1) >> 1;
  96. if (size > TFP_TLB_SIZE / 2) {
  97. local_flush_tlb_all();
  98. return;
  99. }
  100. local_irq_save(flags);
  101. write_c0_entrylo(0);
  102. start &= PAGE_MASK;
  103. end += (PAGE_SIZE - 1);
  104. end &= PAGE_MASK;
  105. while (start < end) {
  106. signed long idx;
  107. write_c0_vaddr(start);
  108. write_c0_entryhi(start);
  109. start += PAGE_SIZE;
  110. tlb_probe();
  111. idx = read_c0_tlbset();
  112. if (idx < 0)
  113. continue;
  114. write_c0_entryhi(CKSEG0 + (idx << (PAGE_SHIFT + 1)));
  115. tlb_write();
  116. }
  117. local_irq_restore(flags);
  118. }
  119. void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  120. {
  121. int cpu = smp_processor_id();
  122. unsigned long flags;
  123. int oldpid, newpid;
  124. signed long idx;
  125. if (!cpu_context(cpu, vma->vm_mm))
  126. return;
  127. newpid = cpu_asid(cpu, vma->vm_mm);
  128. page &= PAGE_MASK;
  129. local_irq_save(flags);
  130. oldpid = read_c0_entryhi();
  131. write_c0_vaddr(page);
  132. write_c0_entryhi(newpid);
  133. tlb_probe();
  134. idx = read_c0_tlbset();
  135. if (idx < 0)
  136. goto finish;
  137. write_c0_entrylo(0);
  138. write_c0_entryhi(CKSEG0 + (idx << (PAGE_SHIFT + 1)));
  139. tlb_write();
  140. finish:
  141. write_c0_entryhi(oldpid);
  142. local_irq_restore(flags);
  143. }
  144. /*
  145. * We will need multiple versions of update_mmu_cache(), one that just
  146. * updates the TLB with the new pte(s), and another which also checks
  147. * for the R4k "end of page" hardware bug and does the needy.
  148. */
  149. void __update_tlb(struct vm_area_struct * vma, unsigned long address, pte_t pte)
  150. {
  151. unsigned long flags;
  152. pgd_t *pgdp;
  153. pmd_t *pmdp;
  154. pte_t *ptep;
  155. int pid;
  156. /*
  157. * Handle debugger faulting in for debugee.
  158. */
  159. if (current->active_mm != vma->vm_mm)
  160. return;
  161. pid = read_c0_entryhi() & ASID_MASK;
  162. local_irq_save(flags);
  163. address &= PAGE_MASK;
  164. write_c0_vaddr(address);
  165. write_c0_entryhi(pid);
  166. pgdp = pgd_offset(vma->vm_mm, address);
  167. pmdp = pmd_offset(pgdp, address);
  168. ptep = pte_offset_map(pmdp, address);
  169. tlb_probe();
  170. write_c0_entrylo(pte_val(*ptep++) >> 6);
  171. tlb_write();
  172. write_c0_entryhi(pid);
  173. local_irq_restore(flags);
  174. }
  175. static void __cpuinit probe_tlb(unsigned long config)
  176. {
  177. struct cpuinfo_mips *c = &current_cpu_data;
  178. c->tlbsize = 3 * 128; /* 3 sets each 128 entries */
  179. }
  180. void __cpuinit tlb_init(void)
  181. {
  182. unsigned int config = read_c0_config();
  183. unsigned long status;
  184. probe_tlb(config);
  185. status = read_c0_status();
  186. status &= ~(ST0_UPS | ST0_KPS);
  187. #ifdef CONFIG_PAGE_SIZE_4KB
  188. status |= (TFP_PAGESIZE_4K << 32) | (TFP_PAGESIZE_4K << 36);
  189. #elif defined(CONFIG_PAGE_SIZE_8KB)
  190. status |= (TFP_PAGESIZE_8K << 32) | (TFP_PAGESIZE_8K << 36);
  191. #elif defined(CONFIG_PAGE_SIZE_16KB)
  192. status |= (TFP_PAGESIZE_16K << 32) | (TFP_PAGESIZE_16K << 36);
  193. #elif defined(CONFIG_PAGE_SIZE_64KB)
  194. status |= (TFP_PAGESIZE_64K << 32) | (TFP_PAGESIZE_64K << 36);
  195. #endif
  196. write_c0_status(status);
  197. write_c0_wired(0);
  198. local_flush_tlb_all();
  199. build_tlb_refill_handler();
  200. }