tlb-r8k.c 5.4 KB

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