Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* arch/sparc64/mm/tlb.c |
| 2 | * |
| 3 | * Copyright (C) 2004 David S. Miller <davem@redhat.com> |
| 4 | */ |
| 5 | |
| 6 | #include <linux/kernel.h> |
| 7 | #include <linux/init.h> |
| 8 | #include <linux/percpu.h> |
| 9 | #include <linux/mm.h> |
| 10 | #include <linux/swap.h> |
David S. Miller | c9f2946 | 2006-04-30 22:54:27 -0700 | [diff] [blame] | 11 | #include <linux/preempt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
| 13 | #include <asm/pgtable.h> |
| 14 | #include <asm/pgalloc.h> |
| 15 | #include <asm/tlbflush.h> |
| 16 | #include <asm/cacheflush.h> |
| 17 | #include <asm/mmu_context.h> |
| 18 | #include <asm/tlb.h> |
| 19 | |
| 20 | /* Heavily inspired by the ppc64 code. */ |
| 21 | |
Hugh Dickins | fc2acab | 2005-10-29 18:16:03 -0700 | [diff] [blame] | 22 | DEFINE_PER_CPU(struct mmu_gather, mmu_gathers) = { 0, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | void flush_tlb_pending(void) |
| 25 | { |
| 26 | struct mmu_gather *mp = &__get_cpu_var(mmu_gathers); |
| 27 | |
David S. Miller | c9f2946 | 2006-04-30 22:54:27 -0700 | [diff] [blame] | 28 | preempt_disable(); |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | if (mp->tlb_nr) { |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 31 | flush_tsb_user(mp); |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | if (CTX_VALID(mp->mm->context)) { |
| 34 | #ifdef CONFIG_SMP |
| 35 | smp_flush_tlb_pending(mp->mm, mp->tlb_nr, |
| 36 | &mp->vaddrs[0]); |
| 37 | #else |
| 38 | __flush_tlb_pending(CTX_HWBITS(mp->mm->context), |
| 39 | mp->tlb_nr, &mp->vaddrs[0]); |
| 40 | #endif |
| 41 | } |
| 42 | mp->tlb_nr = 0; |
| 43 | } |
David S. Miller | c9f2946 | 2006-04-30 22:54:27 -0700 | [diff] [blame] | 44 | |
| 45 | preempt_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr, pte_t *ptep, pte_t orig) |
| 49 | { |
| 50 | struct mmu_gather *mp = &__get_cpu_var(mmu_gathers); |
| 51 | unsigned long nr; |
| 52 | |
| 53 | vaddr &= PAGE_MASK; |
| 54 | if (pte_exec(orig)) |
| 55 | vaddr |= 0x1UL; |
| 56 | |
David S. Miller | 7a591cf | 2006-02-26 19:44:50 -0800 | [diff] [blame] | 57 | if (tlb_type != hypervisor && |
| 58 | pte_dirty(orig)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | unsigned long paddr, pfn = pte_pfn(orig); |
| 60 | struct address_space *mapping; |
| 61 | struct page *page; |
| 62 | |
| 63 | if (!pfn_valid(pfn)) |
| 64 | goto no_cache_flush; |
| 65 | |
| 66 | page = pfn_to_page(pfn); |
| 67 | if (PageReserved(page)) |
| 68 | goto no_cache_flush; |
| 69 | |
| 70 | /* A real file page? */ |
| 71 | mapping = page_mapping(page); |
| 72 | if (!mapping) |
| 73 | goto no_cache_flush; |
| 74 | |
| 75 | paddr = (unsigned long) page_address(page); |
| 76 | if ((paddr ^ vaddr) & (1 << 13)) |
| 77 | flush_dcache_page_all(mm, page); |
| 78 | } |
| 79 | |
| 80 | no_cache_flush: |
| 81 | |
Hugh Dickins | 4d6ddfa | 2005-10-29 18:16:02 -0700 | [diff] [blame] | 82 | if (mp->fullmm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | return; |
| 84 | |
| 85 | nr = mp->tlb_nr; |
| 86 | |
| 87 | if (unlikely(nr != 0 && mm != mp->mm)) { |
| 88 | flush_tlb_pending(); |
| 89 | nr = 0; |
| 90 | } |
| 91 | |
| 92 | if (nr == 0) |
| 93 | mp->mm = mm; |
| 94 | |
| 95 | mp->vaddrs[nr] = vaddr; |
| 96 | mp->tlb_nr = ++nr; |
| 97 | if (nr >= TLB_BATCH_NR) |
| 98 | flush_tlb_pending(); |
| 99 | } |