tlb_hash32.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 <linux/export.h>
  30. #include <asm/tlbflush.h>
  31. #include <asm/tlb.h>
  32. #include "mmu_decl.h"
  33. /*
  34. * Called when unmapping pages to flush entries from the TLB/hash table.
  35. */
  36. void flush_hash_entry(struct mm_struct *mm, pte_t *ptep, unsigned long addr)
  37. {
  38. unsigned long ptephys;
  39. if (Hash != 0) {
  40. ptephys = __pa(ptep) & PAGE_MASK;
  41. flush_hash_pages(mm->context.id, addr, ptephys, 1);
  42. }
  43. }
  44. EXPORT_SYMBOL(flush_hash_entry);
  45. /*
  46. * Called by ptep_set_access_flags, must flush on CPUs for which the
  47. * DSI handler can't just "fixup" the TLB on a write fault
  48. */
  49. void flush_tlb_page_nohash(struct vm_area_struct *vma, unsigned long addr)
  50. {
  51. if (Hash != 0)
  52. return;
  53. _tlbie(addr);
  54. }
  55. /*
  56. * Called at the end of a mmu_gather operation to make sure the
  57. * TLB flush is completely done.
  58. */
  59. void tlb_flush(struct mmu_gather *tlb)
  60. {
  61. if (Hash == 0) {
  62. /*
  63. * 603 needs to flush the whole TLB here since
  64. * it doesn't use a hash table.
  65. */
  66. _tlbia();
  67. }
  68. }
  69. /*
  70. * TLB flushing:
  71. *
  72. * - flush_tlb_mm(mm) flushes the specified mm context TLB's
  73. * - flush_tlb_page(vma, vmaddr) flushes one page
  74. * - flush_tlb_range(vma, start, end) flushes a range of pages
  75. * - flush_tlb_kernel_range(start, end) flushes kernel pages
  76. *
  77. * since the hardware hash table functions as an extension of the
  78. * tlb as far as the linux tables are concerned, flush it too.
  79. * -- Cort
  80. */
  81. static void flush_range(struct mm_struct *mm, unsigned long start,
  82. unsigned long end)
  83. {
  84. pmd_t *pmd;
  85. unsigned long pmd_end;
  86. int count;
  87. unsigned int ctx = mm->context.id;
  88. if (Hash == 0) {
  89. _tlbia();
  90. return;
  91. }
  92. start &= PAGE_MASK;
  93. if (start >= end)
  94. return;
  95. end = (end - 1) | ~PAGE_MASK;
  96. pmd = pmd_offset(pud_offset(pgd_offset(mm, start), start), start);
  97. for (;;) {
  98. pmd_end = ((start + PGDIR_SIZE) & PGDIR_MASK) - 1;
  99. if (pmd_end > end)
  100. pmd_end = end;
  101. if (!pmd_none(*pmd)) {
  102. count = ((pmd_end - start) >> PAGE_SHIFT) + 1;
  103. flush_hash_pages(ctx, start, pmd_val(*pmd), count);
  104. }
  105. if (pmd_end == end)
  106. break;
  107. start = pmd_end + 1;
  108. ++pmd;
  109. }
  110. }
  111. /*
  112. * Flush kernel TLB entries in the given range
  113. */
  114. void flush_tlb_kernel_range(unsigned long start, unsigned long end)
  115. {
  116. flush_range(&init_mm, start, end);
  117. }
  118. EXPORT_SYMBOL(flush_tlb_kernel_range);
  119. /*
  120. * Flush all the (user) entries for the address space described by mm.
  121. */
  122. void flush_tlb_mm(struct mm_struct *mm)
  123. {
  124. struct vm_area_struct *mp;
  125. if (Hash == 0) {
  126. _tlbia();
  127. return;
  128. }
  129. /*
  130. * It is safe to go down the mm's list of vmas when called
  131. * from dup_mmap, holding mmap_sem. It would also be safe from
  132. * unmap_region or exit_mmap, but not from vmtruncate on SMP -
  133. * but it seems dup_mmap is the only SMP case which gets here.
  134. */
  135. for (mp = mm->mmap; mp != NULL; mp = mp->vm_next)
  136. flush_range(mp->vm_mm, mp->vm_start, mp->vm_end);
  137. }
  138. EXPORT_SYMBOL(flush_tlb_mm);
  139. void flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
  140. {
  141. struct mm_struct *mm;
  142. pmd_t *pmd;
  143. if (Hash == 0) {
  144. _tlbie(vmaddr);
  145. return;
  146. }
  147. mm = (vmaddr < TASK_SIZE)? vma->vm_mm: &init_mm;
  148. pmd = pmd_offset(pud_offset(pgd_offset(mm, vmaddr), vmaddr), vmaddr);
  149. if (!pmd_none(*pmd))
  150. flush_hash_pages(mm->context.id, vmaddr, pmd_val(*pmd), 1);
  151. }
  152. EXPORT_SYMBOL(flush_tlb_page);
  153. /*
  154. * For each address in the range, find the pte for the address
  155. * and check _PAGE_HASHPTE bit; if it is set, find and destroy
  156. * the corresponding HPTE.
  157. */
  158. void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  159. unsigned long end)
  160. {
  161. flush_range(vma->vm_mm, start, end);
  162. }
  163. EXPORT_SYMBOL(flush_tlb_range);
  164. void __init early_init_mmu(void)
  165. {
  166. }