tlb_hash32.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. /* Push out batch of freed page tables */
  68. pte_free_finish();
  69. }
  70. /*
  71. * TLB flushing:
  72. *
  73. * - flush_tlb_mm(mm) flushes the specified mm context TLB's
  74. * - flush_tlb_page(vma, vmaddr) flushes one page
  75. * - flush_tlb_range(vma, start, end) flushes a range of pages
  76. * - flush_tlb_kernel_range(start, end) flushes kernel pages
  77. *
  78. * since the hardware hash table functions as an extension of the
  79. * tlb as far as the linux tables are concerned, flush it too.
  80. * -- Cort
  81. */
  82. /*
  83. * 750 SMP is a Bad Idea because the 750 doesn't broadcast all
  84. * the cache operations on the bus. Hence we need to use an IPI
  85. * to get the other CPU(s) to invalidate their TLBs.
  86. */
  87. #ifdef CONFIG_SMP_750
  88. #define FINISH_FLUSH smp_send_tlb_invalidate(0)
  89. #else
  90. #define FINISH_FLUSH do { } while (0)
  91. #endif
  92. static void flush_range(struct mm_struct *mm, unsigned long start,
  93. unsigned long end)
  94. {
  95. pmd_t *pmd;
  96. unsigned long pmd_end;
  97. int count;
  98. unsigned int ctx = mm->context.id;
  99. if (Hash == 0) {
  100. _tlbia();
  101. return;
  102. }
  103. start &= PAGE_MASK;
  104. if (start >= end)
  105. return;
  106. end = (end - 1) | ~PAGE_MASK;
  107. pmd = pmd_offset(pud_offset(pgd_offset(mm, start), start), start);
  108. for (;;) {
  109. pmd_end = ((start + PGDIR_SIZE) & PGDIR_MASK) - 1;
  110. if (pmd_end > end)
  111. pmd_end = end;
  112. if (!pmd_none(*pmd)) {
  113. count = ((pmd_end - start) >> PAGE_SHIFT) + 1;
  114. flush_hash_pages(ctx, start, pmd_val(*pmd), count);
  115. }
  116. if (pmd_end == end)
  117. break;
  118. start = pmd_end + 1;
  119. ++pmd;
  120. }
  121. }
  122. /*
  123. * Flush kernel TLB entries in the given range
  124. */
  125. void flush_tlb_kernel_range(unsigned long start, unsigned long end)
  126. {
  127. flush_range(&init_mm, start, end);
  128. FINISH_FLUSH;
  129. }
  130. EXPORT_SYMBOL(flush_tlb_kernel_range);
  131. /*
  132. * Flush all the (user) entries for the address space described by mm.
  133. */
  134. void flush_tlb_mm(struct mm_struct *mm)
  135. {
  136. struct vm_area_struct *mp;
  137. if (Hash == 0) {
  138. _tlbia();
  139. return;
  140. }
  141. /*
  142. * It is safe to go down the mm's list of vmas when called
  143. * from dup_mmap, holding mmap_sem. It would also be safe from
  144. * unmap_region or exit_mmap, but not from vmtruncate on SMP -
  145. * but it seems dup_mmap is the only SMP case which gets here.
  146. */
  147. for (mp = mm->mmap; mp != NULL; mp = mp->vm_next)
  148. flush_range(mp->vm_mm, mp->vm_start, mp->vm_end);
  149. FINISH_FLUSH;
  150. }
  151. EXPORT_SYMBOL(flush_tlb_mm);
  152. void flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
  153. {
  154. struct mm_struct *mm;
  155. pmd_t *pmd;
  156. if (Hash == 0) {
  157. _tlbie(vmaddr);
  158. return;
  159. }
  160. mm = (vmaddr < TASK_SIZE)? vma->vm_mm: &init_mm;
  161. pmd = pmd_offset(pud_offset(pgd_offset(mm, vmaddr), vmaddr), vmaddr);
  162. if (!pmd_none(*pmd))
  163. flush_hash_pages(mm->context.id, vmaddr, pmd_val(*pmd), 1);
  164. FINISH_FLUSH;
  165. }
  166. EXPORT_SYMBOL(flush_tlb_page);
  167. /*
  168. * For each address in the range, find the pte for the address
  169. * and check _PAGE_HASHPTE bit; if it is set, find and destroy
  170. * the corresponding HPTE.
  171. */
  172. void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  173. unsigned long end)
  174. {
  175. flush_range(vma->vm_mm, start, end);
  176. FINISH_FLUSH;
  177. }
  178. EXPORT_SYMBOL(flush_tlb_range);