tlbflush.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #ifndef _M68K_TLBFLUSH_H
  2. #define _M68K_TLBFLUSH_H
  3. #ifndef CONFIG_SUN3
  4. #include <asm/current.h>
  5. static inline void flush_tlb_kernel_page(void *addr)
  6. {
  7. if (CPU_IS_040_OR_060) {
  8. mm_segment_t old_fs = get_fs();
  9. set_fs(KERNEL_DS);
  10. __asm__ __volatile__(".chip 68040\n\t"
  11. "pflush (%0)\n\t"
  12. ".chip 68k"
  13. : : "a" (addr));
  14. set_fs(old_fs);
  15. } else if (CPU_IS_020_OR_030)
  16. __asm__ __volatile__("pflush #4,#4,(%0)" : : "a" (addr));
  17. }
  18. /*
  19. * flush all user-space atc entries.
  20. */
  21. static inline void __flush_tlb(void)
  22. {
  23. if (CPU_IS_040_OR_060)
  24. __asm__ __volatile__(".chip 68040\n\t"
  25. "pflushan\n\t"
  26. ".chip 68k");
  27. else if (CPU_IS_020_OR_030)
  28. __asm__ __volatile__("pflush #0,#4");
  29. }
  30. static inline void __flush_tlb040_one(unsigned long addr)
  31. {
  32. __asm__ __volatile__(".chip 68040\n\t"
  33. "pflush (%0)\n\t"
  34. ".chip 68k"
  35. : : "a" (addr));
  36. }
  37. static inline void __flush_tlb_one(unsigned long addr)
  38. {
  39. if (CPU_IS_040_OR_060)
  40. __flush_tlb040_one(addr);
  41. else if (CPU_IS_020_OR_030)
  42. __asm__ __volatile__("pflush #0,#4,(%0)" : : "a" (addr));
  43. }
  44. #define flush_tlb() __flush_tlb()
  45. /*
  46. * flush all atc entries (both kernel and user-space entries).
  47. */
  48. static inline void flush_tlb_all(void)
  49. {
  50. if (CPU_IS_040_OR_060)
  51. __asm__ __volatile__(".chip 68040\n\t"
  52. "pflusha\n\t"
  53. ".chip 68k");
  54. else if (CPU_IS_020_OR_030)
  55. __asm__ __volatile__("pflusha");
  56. }
  57. static inline void flush_tlb_mm(struct mm_struct *mm)
  58. {
  59. if (mm == current->active_mm)
  60. __flush_tlb();
  61. }
  62. static inline void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
  63. {
  64. if (vma->vm_mm == current->active_mm) {
  65. mm_segment_t old_fs = get_fs();
  66. set_fs(USER_DS);
  67. __flush_tlb_one(addr);
  68. set_fs(old_fs);
  69. }
  70. }
  71. static inline void flush_tlb_range(struct vm_area_struct *vma,
  72. unsigned long start, unsigned long end)
  73. {
  74. if (vma->vm_mm == current->active_mm)
  75. __flush_tlb();
  76. }
  77. static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end)
  78. {
  79. flush_tlb_all();
  80. }
  81. #else
  82. /* Reserved PMEGs. */
  83. extern char sun3_reserved_pmeg[SUN3_PMEGS_NUM];
  84. extern unsigned long pmeg_vaddr[SUN3_PMEGS_NUM];
  85. extern unsigned char pmeg_alloc[SUN3_PMEGS_NUM];
  86. extern unsigned char pmeg_ctx[SUN3_PMEGS_NUM];
  87. /* Flush all userspace mappings one by one... (why no flush command,
  88. sun?) */
  89. static inline void flush_tlb_all(void)
  90. {
  91. unsigned long addr;
  92. unsigned char ctx, oldctx;
  93. oldctx = sun3_get_context();
  94. for(addr = 0x00000000; addr < TASK_SIZE; addr += SUN3_PMEG_SIZE) {
  95. for(ctx = 0; ctx < 8; ctx++) {
  96. sun3_put_context(ctx);
  97. sun3_put_segmap(addr, SUN3_INVALID_PMEG);
  98. }
  99. }
  100. sun3_put_context(oldctx);
  101. /* erase all of the userspace pmeg maps, we've clobbered them
  102. all anyway */
  103. for(addr = 0; addr < SUN3_INVALID_PMEG; addr++) {
  104. if(pmeg_alloc[addr] == 1) {
  105. pmeg_alloc[addr] = 0;
  106. pmeg_ctx[addr] = 0;
  107. pmeg_vaddr[addr] = 0;
  108. }
  109. }
  110. }
  111. /* Clear user TLB entries within the context named in mm */
  112. static inline void flush_tlb_mm (struct mm_struct *mm)
  113. {
  114. unsigned char oldctx;
  115. unsigned char seg;
  116. unsigned long i;
  117. oldctx = sun3_get_context();
  118. sun3_put_context(mm->context);
  119. for(i = 0; i < TASK_SIZE; i += SUN3_PMEG_SIZE) {
  120. seg = sun3_get_segmap(i);
  121. if(seg == SUN3_INVALID_PMEG)
  122. continue;
  123. sun3_put_segmap(i, SUN3_INVALID_PMEG);
  124. pmeg_alloc[seg] = 0;
  125. pmeg_ctx[seg] = 0;
  126. pmeg_vaddr[seg] = 0;
  127. }
  128. sun3_put_context(oldctx);
  129. }
  130. /* Flush a single TLB page. In this case, we're limited to flushing a
  131. single PMEG */
  132. static inline void flush_tlb_page (struct vm_area_struct *vma,
  133. unsigned long addr)
  134. {
  135. unsigned char oldctx;
  136. unsigned char i;
  137. oldctx = sun3_get_context();
  138. sun3_put_context(vma->vm_mm->context);
  139. addr &= ~SUN3_PMEG_MASK;
  140. if((i = sun3_get_segmap(addr)) != SUN3_INVALID_PMEG)
  141. {
  142. pmeg_alloc[i] = 0;
  143. pmeg_ctx[i] = 0;
  144. pmeg_vaddr[i] = 0;
  145. sun3_put_segmap (addr, SUN3_INVALID_PMEG);
  146. }
  147. sun3_put_context(oldctx);
  148. }
  149. /* Flush a range of pages from TLB. */
  150. static inline void flush_tlb_range (struct vm_area_struct *vma,
  151. unsigned long start, unsigned long end)
  152. {
  153. struct mm_struct *mm = vma->vm_mm;
  154. unsigned char seg, oldctx;
  155. start &= ~SUN3_PMEG_MASK;
  156. oldctx = sun3_get_context();
  157. sun3_put_context(mm->context);
  158. while(start < end)
  159. {
  160. if((seg = sun3_get_segmap(start)) == SUN3_INVALID_PMEG)
  161. goto next;
  162. if(pmeg_ctx[seg] == mm->context) {
  163. pmeg_alloc[seg] = 0;
  164. pmeg_ctx[seg] = 0;
  165. pmeg_vaddr[seg] = 0;
  166. }
  167. sun3_put_segmap(start, SUN3_INVALID_PMEG);
  168. next:
  169. start += SUN3_PMEG_SIZE;
  170. }
  171. }
  172. static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end)
  173. {
  174. flush_tlb_all();
  175. }
  176. /* Flush kernel page from TLB. */
  177. static inline void flush_tlb_kernel_page (unsigned long addr)
  178. {
  179. sun3_put_segmap (addr & ~(SUN3_PMEG_SIZE - 1), SUN3_INVALID_PMEG);
  180. }
  181. #endif
  182. #endif /* _M68K_TLBFLUSH_H */