1 /* arch/sparc64/mm/tsb.c
3 * Copyright (C) 2006 David S. Miller <davem@davemloft.net>
6 #include <linux/kernel.h>
7 #include <asm/system.h>
9 #include <asm/tlbflush.h>
11 #include <asm/mmu_context.h>
12 #include <asm/pgtable.h>
14 /* We use an 8K TSB for the whole kernel, this allows to
15 * handle about 4MB of modules and vmalloc mappings without
16 * incurring many hash conflicts.
18 #define KERNEL_TSB_SIZE_BYTES 8192
19 #define KERNEL_TSB_NENTRIES \
20 (KERNEL_TSB_SIZE_BYTES / sizeof(struct tsb))
22 extern struct tsb swapper_tsb[KERNEL_TSB_NENTRIES];
24 static inline unsigned long tsb_hash(unsigned long vaddr, unsigned long nentries)
27 return vaddr & (nentries - 1);
30 static inline int tag_compare(struct tsb *entry, unsigned long vaddr, unsigned long context)
35 return (entry->tag == ((vaddr >> 22) | (context << 48)));
38 /* TSB flushes need only occur on the processor initiating the address
39 * space modification, not on each cpu the address space has run on.
40 * Only the TLB flush needs that treatment.
43 void flush_tsb_kernel_range(unsigned long start, unsigned long end)
47 for (v = start; v < end; v += PAGE_SIZE) {
48 unsigned long hash = tsb_hash(v, KERNEL_TSB_NENTRIES);
49 struct tsb *ent = &swapper_tsb[hash];
51 if (tag_compare(ent, v, 0)) {
53 membar_storeload_storestore();
58 void flush_tsb_user(struct mmu_gather *mp)
60 struct mm_struct *mm = mp->mm;
61 struct tsb *tsb = mm->context.tsb;
62 unsigned long ctx = ~0UL;
63 unsigned long nentries = mm->context.tsb_nentries;
66 if (CTX_VALID(mm->context))
67 ctx = CTX_HWBITS(mm->context);
69 for (i = 0; i < mp->tlb_nr; i++) {
70 unsigned long v = mp->vaddrs[i];
75 ent = &tsb[tsb_hash(v, nentries)];
76 if (tag_compare(ent, v, ctx)) {
78 membar_storeload_storestore();
83 static void setup_tsb_params(struct mm_struct *mm, unsigned long tsb_bytes)
85 unsigned long tsb_reg, base, tsb_paddr;
86 unsigned long page_sz, tte;
88 mm->context.tsb_nentries = tsb_bytes / sizeof(struct tsb);
91 tte = (_PAGE_VALID | _PAGE_L | _PAGE_CP |
92 _PAGE_CV | _PAGE_P | _PAGE_W);
93 tsb_paddr = __pa(mm->context.tsb);
95 /* Use the smallest page size that can map the whole TSB
101 #ifdef DCACHE_ALIASING_POSSIBLE
102 base += (tsb_paddr & 8192);
129 page_sz = 512 * 1024;
135 page_sz = 512 * 1024;
141 page_sz = 512 * 1024;
147 page_sz = 4 * 1024 * 1024;
152 tsb_reg |= (tsb_paddr & (page_sz - 1UL));
153 tte |= (tsb_paddr & ~(page_sz - 1UL));
155 mm->context.tsb_reg_val = tsb_reg;
156 mm->context.tsb_map_vaddr = base;
157 mm->context.tsb_map_pte = tte;
160 int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
162 unsigned long page = get_zeroed_page(GFP_KERNEL);
164 mm->context.sparc64_ctx_val = 0UL;
168 mm->context.tsb = (struct tsb *) page;
169 setup_tsb_params(mm, PAGE_SIZE);
174 void destroy_context(struct mm_struct *mm)
176 free_page((unsigned long) mm->context.tsb);
178 /* We can remove these later, but for now it's useful
179 * to catch any bogus post-destroy_context() references
182 mm->context.tsb = NULL;
183 mm->context.tsb_reg_val = 0UL;
185 spin_lock(&ctx_alloc_lock);
187 if (CTX_VALID(mm->context)) {
188 unsigned long nr = CTX_NRBITS(mm->context);
189 mmu_context_bmap[nr>>6] &= ~(1UL << (nr & 63));
192 spin_unlock(&ctx_alloc_lock);