blob: a079cf42505ed08906d42b0371372d6842d8a8b7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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>
11
12#include <asm/pgtable.h>
13#include <asm/pgalloc.h>
14#include <asm/tlbflush.h>
15#include <asm/cacheflush.h>
16#include <asm/mmu_context.h>
17#include <asm/tlb.h>
18
19/* Heavily inspired by the ppc64 code. */
20
Hugh Dickinsfc2acab2005-10-29 18:16:03 -070021DEFINE_PER_CPU(struct mmu_gather, mmu_gathers) = { 0, };
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23void flush_tlb_pending(void)
24{
25 struct mmu_gather *mp = &__get_cpu_var(mmu_gathers);
26
27 if (mp->tlb_nr) {
David S. Miller74bf4312006-01-31 18:29:18 -080028 flush_tsb_user(mp);
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 if (CTX_VALID(mp->mm->context)) {
31#ifdef CONFIG_SMP
32 smp_flush_tlb_pending(mp->mm, mp->tlb_nr,
33 &mp->vaddrs[0]);
34#else
35 __flush_tlb_pending(CTX_HWBITS(mp->mm->context),
36 mp->tlb_nr, &mp->vaddrs[0]);
37#endif
38 }
39 mp->tlb_nr = 0;
40 }
41}
42
43void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr, pte_t *ptep, pte_t orig)
44{
45 struct mmu_gather *mp = &__get_cpu_var(mmu_gathers);
46 unsigned long nr;
47
48 vaddr &= PAGE_MASK;
49 if (pte_exec(orig))
50 vaddr |= 0x1UL;
51
David S. Miller7a591cf2006-02-26 19:44:50 -080052 if (tlb_type != hypervisor &&
53 pte_dirty(orig)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 unsigned long paddr, pfn = pte_pfn(orig);
55 struct address_space *mapping;
56 struct page *page;
57
58 if (!pfn_valid(pfn))
59 goto no_cache_flush;
60
61 page = pfn_to_page(pfn);
62 if (PageReserved(page))
63 goto no_cache_flush;
64
65 /* A real file page? */
66 mapping = page_mapping(page);
67 if (!mapping)
68 goto no_cache_flush;
69
70 paddr = (unsigned long) page_address(page);
71 if ((paddr ^ vaddr) & (1 << 13))
72 flush_dcache_page_all(mm, page);
73 }
74
75no_cache_flush:
76
Hugh Dickins4d6ddfa2005-10-29 18:16:02 -070077 if (mp->fullmm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 return;
79
80 nr = mp->tlb_nr;
81
82 if (unlikely(nr != 0 && mm != mp->mm)) {
83 flush_tlb_pending();
84 nr = 0;
85 }
86
87 if (nr == 0)
88 mp->mm = mm;
89
90 mp->vaddrs[nr] = vaddr;
91 mp->tlb_nr = ++nr;
92 if (nr >= TLB_BATCH_NR)
93 flush_tlb_pending();
94}