tlb_hash32.c 4.2 KB

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