tlb_hash32.c 4.4 KB

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