tlb_hash32.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * This file contains the routines for TLB flushing.
  3. * On machines where the MMU uses a hash table to store virtual to
  4. * physical translations, these routines flush entries from the
  5. * hash table also.
  6. * -- paulus
  7. *
  8. * Derived from arch/ppc/mm/init.c:
  9. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  10. *
  11. * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
  12. * and Cort Dougan (PReP) (cort@cs.nmt.edu)
  13. * Copyright (C) 1996 Paul Mackerras
  14. *
  15. * Derived from "arch/i386/mm/init.c"
  16. * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
  17. *
  18. * This program is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU General Public License
  20. * as published by the Free Software Foundation; either version
  21. * 2 of the License, or (at your option) any later version.
  22. *
  23. */
  24. #include <linux/kernel.h>
  25. #include <linux/mm.h>
  26. #include <linux/init.h>
  27. #include <linux/highmem.h>
  28. #include <linux/pagemap.h>
  29. #include <asm/tlbflush.h>
  30. #include <asm/tlb.h>
  31. #include "mmu_decl.h"
  32. /*
  33. * Called when unmapping pages to flush entries from the TLB/hash table.
  34. */
  35. void flush_hash_entry(struct mm_struct *mm, pte_t *ptep, unsigned long addr)
  36. {
  37. unsigned long ptephys;
  38. if (Hash != 0) {
  39. ptephys = __pa(ptep) & PAGE_MASK;
  40. flush_hash_pages(mm->context.id, addr, ptephys, 1);
  41. }
  42. }
  43. EXPORT_SYMBOL(flush_hash_entry);
  44. /*
  45. * Called by ptep_set_access_flags, must flush on CPUs for which the
  46. * DSI handler can't just "fixup" the TLB on a write fault
  47. */
  48. void flush_tlb_page_nohash(struct vm_area_struct *vma, unsigned long addr)
  49. {
  50. if (Hash != 0)
  51. return;
  52. _tlbie(addr);
  53. }
  54. /*
  55. * Called at the end of a mmu_gather operation to make sure the
  56. * TLB flush is completely done.
  57. */
  58. void tlb_flush(struct mmu_gather *tlb)
  59. {
  60. if (Hash == 0) {
  61. /*
  62. * 603 needs to flush the whole TLB here since
  63. * it doesn't use a hash table.
  64. */
  65. _tlbia();
  66. }
  67. }
  68. /*
  69. * TLB flushing:
  70. *
  71. * - flush_tlb_mm(mm) flushes the specified mm context TLB's
  72. * - flush_tlb_page(vma, vmaddr) flushes one page
  73. * - flush_tlb_range(vma, start, end) flushes a range of pages
  74. * - flush_tlb_kernel_range(start, end) flushes kernel pages
  75. *
  76. * since the hardware hash table functions as an extension of the
  77. * tlb as far as the linux tables are concerned, flush it too.
  78. * -- Cort
  79. */
  80. /*
  81. * 750 SMP is a Bad Idea because the 750 doesn't broadcast all
  82. * the cache operations on the bus. Hence we need to use an IPI
  83. * to get the other CPU(s) to invalidate their TLBs.
  84. */
  85. #ifdef CONFIG_SMP_750
  86. #define FINISH_FLUSH smp_send_tlb_invalidate(0)
  87. #else
  88. #define FINISH_FLUSH do { } while (0)
  89. #endif
  90. static void flush_range(struct mm_struct *mm, unsigned long start,
  91. unsigned long end)
  92. {
  93. pmd_t *pmd;
  94. unsigned long pmd_end;
  95. int count;
  96. unsigned int ctx = mm->context.id;
  97. if (Hash == 0) {
  98. _tlbia();
  99. return;
  100. }
  101. start &= PAGE_MASK;
  102. if (start >= end)
  103. return;
  104. end = (end - 1) | ~PAGE_MASK;
  105. pmd = pmd_offset(pud_offset(pgd_offset(mm, start), start), start);
  106. for (;;) {
  107. pmd_end = ((start + PGDIR_SIZE) & PGDIR_MASK) - 1;
  108. if (pmd_end > end)
  109. pmd_end = end;
  110. if (!pmd_none(*pmd)) {
  111. count = ((pmd_end - start) >> PAGE_SHIFT) + 1;
  112. flush_hash_pages(ctx, start, pmd_val(*pmd), count);
  113. }
  114. if (pmd_end == end)
  115. break;
  116. start = pmd_end + 1;
  117. ++pmd;
  118. }
  119. }
  120. /*
  121. * Flush kernel TLB entries in the given range
  122. */
  123. void flush_tlb_kernel_range(unsigned long start, unsigned long end)
  124. {
  125. flush_range(&init_mm, start, end);
  126. FINISH_FLUSH;
  127. }
  128. EXPORT_SYMBOL(flush_tlb_kernel_range);
  129. /*
  130. * Flush all the (user) entries for the address space described by mm.
  131. */
  132. void flush_tlb_mm(struct mm_struct *mm)
  133. {
  134. struct vm_area_struct *mp;
  135. if (Hash == 0) {
  136. _tlbia();
  137. return;
  138. }
  139. /*
  140. * It is safe to go down the mm's list of vmas when called
  141. * from dup_mmap, holding mmap_sem. It would also be safe from
  142. * unmap_region or exit_mmap, but not from vmtruncate on SMP -
  143. * but it seems dup_mmap is the only SMP case which gets here.
  144. */
  145. for (mp = mm->mmap; mp != NULL; mp = mp->vm_next)
  146. flush_range(mp->vm_mm, mp->vm_start, mp->vm_end);
  147. FINISH_FLUSH;
  148. }
  149. EXPORT_SYMBOL(flush_tlb_mm);
  150. void flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
  151. {
  152. struct mm_struct *mm;
  153. pmd_t *pmd;
  154. if (Hash == 0) {
  155. _tlbie(vmaddr);
  156. return;
  157. }
  158. mm = (vmaddr < TASK_SIZE)? vma->vm_mm: &init_mm;
  159. pmd = pmd_offset(pud_offset(pgd_offset(mm, vmaddr), vmaddr), vmaddr);
  160. if (!pmd_none(*pmd))
  161. flush_hash_pages(mm->context.id, vmaddr, pmd_val(*pmd), 1);
  162. FINISH_FLUSH;
  163. }
  164. EXPORT_SYMBOL(flush_tlb_page);
  165. /*
  166. * For each address in the range, find the pte for the address
  167. * and check _PAGE_HASHPTE bit; if it is set, find and destroy
  168. * the corresponding HPTE.
  169. */
  170. void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  171. unsigned long end)
  172. {
  173. flush_range(vma->vm_mm, start, end);
  174. FINISH_FLUSH;
  175. }
  176. EXPORT_SYMBOL(flush_tlb_range);