tlb_hash32.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. static void flush_range(struct mm_struct *mm, unsigned long start,
  83. unsigned long end)
  84. {
  85. pmd_t *pmd;
  86. unsigned long pmd_end;
  87. int count;
  88. unsigned int ctx = mm->context.id;
  89. if (Hash == 0) {
  90. _tlbia();
  91. return;
  92. }
  93. start &= PAGE_MASK;
  94. if (start >= end)
  95. return;
  96. end = (end - 1) | ~PAGE_MASK;
  97. pmd = pmd_offset(pud_offset(pgd_offset(mm, start), start), start);
  98. for (;;) {
  99. pmd_end = ((start + PGDIR_SIZE) & PGDIR_MASK) - 1;
  100. if (pmd_end > end)
  101. pmd_end = end;
  102. if (!pmd_none(*pmd)) {
  103. count = ((pmd_end - start) >> PAGE_SHIFT) + 1;
  104. flush_hash_pages(ctx, start, pmd_val(*pmd), count);
  105. }
  106. if (pmd_end == end)
  107. break;
  108. start = pmd_end + 1;
  109. ++pmd;
  110. }
  111. }
  112. /*
  113. * Flush kernel TLB entries in the given range
  114. */
  115. void flush_tlb_kernel_range(unsigned long start, unsigned long end)
  116. {
  117. flush_range(&init_mm, start, end);
  118. }
  119. EXPORT_SYMBOL(flush_tlb_kernel_range);
  120. /*
  121. * Flush all the (user) entries for the address space described by mm.
  122. */
  123. void flush_tlb_mm(struct mm_struct *mm)
  124. {
  125. struct vm_area_struct *mp;
  126. if (Hash == 0) {
  127. _tlbia();
  128. return;
  129. }
  130. /*
  131. * It is safe to go down the mm's list of vmas when called
  132. * from dup_mmap, holding mmap_sem. It would also be safe from
  133. * unmap_region or exit_mmap, but not from vmtruncate on SMP -
  134. * but it seems dup_mmap is the only SMP case which gets here.
  135. */
  136. for (mp = mm->mmap; mp != NULL; mp = mp->vm_next)
  137. flush_range(mp->vm_mm, mp->vm_start, mp->vm_end);
  138. }
  139. EXPORT_SYMBOL(flush_tlb_mm);
  140. void flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
  141. {
  142. struct mm_struct *mm;
  143. pmd_t *pmd;
  144. if (Hash == 0) {
  145. _tlbie(vmaddr);
  146. return;
  147. }
  148. mm = (vmaddr < TASK_SIZE)? vma->vm_mm: &init_mm;
  149. pmd = pmd_offset(pud_offset(pgd_offset(mm, vmaddr), vmaddr), vmaddr);
  150. if (!pmd_none(*pmd))
  151. flush_hash_pages(mm->context.id, vmaddr, pmd_val(*pmd), 1);
  152. }
  153. EXPORT_SYMBOL(flush_tlb_page);
  154. /*
  155. * For each address in the range, find the pte for the address
  156. * and check _PAGE_HASHPTE bit; if it is set, find and destroy
  157. * the corresponding HPTE.
  158. */
  159. void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  160. unsigned long end)
  161. {
  162. flush_range(vma->vm_mm, start, end);
  163. }
  164. EXPORT_SYMBOL(flush_tlb_range);