tlb.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* arch/sparc64/mm/tlb.c
  2. *
  3. * Copyright (C) 2004 David S. Miller <davem@redhat.com>
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/init.h>
  7. #include <linux/percpu.h>
  8. #include <linux/mm.h>
  9. #include <linux/swap.h>
  10. #include <asm/pgtable.h>
  11. #include <asm/pgalloc.h>
  12. #include <asm/tlbflush.h>
  13. #include <asm/cacheflush.h>
  14. #include <asm/mmu_context.h>
  15. #include <asm/tlb.h>
  16. /* Heavily inspired by the ppc64 code. */
  17. DEFINE_PER_CPU(struct mmu_gather, mmu_gathers) = { 0, };
  18. void flush_tlb_pending(void)
  19. {
  20. struct mmu_gather *mp = &__get_cpu_var(mmu_gathers);
  21. if (mp->tlb_nr) {
  22. flush_tsb_user(mp);
  23. if (CTX_VALID(mp->mm->context)) {
  24. #ifdef CONFIG_SMP
  25. smp_flush_tlb_pending(mp->mm, mp->tlb_nr,
  26. &mp->vaddrs[0]);
  27. #else
  28. __flush_tlb_pending(CTX_HWBITS(mp->mm->context),
  29. mp->tlb_nr, &mp->vaddrs[0]);
  30. #endif
  31. }
  32. mp->tlb_nr = 0;
  33. }
  34. }
  35. void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr, pte_t *ptep, pte_t orig)
  36. {
  37. struct mmu_gather *mp = &__get_cpu_var(mmu_gathers);
  38. unsigned long nr;
  39. vaddr &= PAGE_MASK;
  40. if (pte_exec(orig))
  41. vaddr |= 0x1UL;
  42. if (tlb_type != hypervisor &&
  43. pte_dirty(orig)) {
  44. unsigned long paddr, pfn = pte_pfn(orig);
  45. struct address_space *mapping;
  46. struct page *page;
  47. if (!pfn_valid(pfn))
  48. goto no_cache_flush;
  49. page = pfn_to_page(pfn);
  50. if (PageReserved(page))
  51. goto no_cache_flush;
  52. /* A real file page? */
  53. mapping = page_mapping(page);
  54. if (!mapping)
  55. goto no_cache_flush;
  56. paddr = (unsigned long) page_address(page);
  57. if ((paddr ^ vaddr) & (1 << 13))
  58. flush_dcache_page_all(mm, page);
  59. }
  60. no_cache_flush:
  61. if (mp->fullmm)
  62. return;
  63. nr = mp->tlb_nr;
  64. if (unlikely(nr != 0 && mm != mp->mm)) {
  65. flush_tlb_pending();
  66. nr = 0;
  67. }
  68. if (nr == 0)
  69. mp->mm = mm;
  70. mp->vaddrs[nr] = vaddr;
  71. mp->tlb_nr = ++nr;
  72. if (nr >= TLB_BATCH_NR)
  73. flush_tlb_pending();
  74. }