1 /* $Id: mmu_context.h,v 1.54 2002/02/09 19:49:31 davem Exp $ */
2 #ifndef __SPARC64_MMU_CONTEXT_H
3 #define __SPARC64_MMU_CONTEXT_H
5 /* Derived heavily from Linus's Alpha/AXP ASN code... */
10 * For the 8k pagesize kernel, use only 10 hw context bits to optimize some shifts in
11 * the fast tlbmiss handlers, instead of all 13 bits (specifically for vpte offset
12 * calculation). For other pagesizes, this optimization in the tlbhandlers can not be
13 * done; but still, all 13 bits can not be used because the tlb handlers use "andcc"
14 * instruction which sign extends 13 bit arguments.
17 #define CTX_VERSION_SHIFT 10
18 #define TAG_CONTEXT_BITS 0x3ff
20 #define CTX_VERSION_SHIFT 12
21 #define TAG_CONTEXT_BITS 0xfff
26 #include <linux/spinlock.h>
27 #include <asm/system.h>
28 #include <asm/spitfire.h>
30 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
34 extern spinlock_t ctx_alloc_lock;
35 extern unsigned long tlb_context_cache;
36 extern unsigned long mmu_context_bmap[];
38 #define CTX_VERSION_MASK ((~0UL) << CTX_VERSION_SHIFT)
39 #define CTX_FIRST_VERSION ((1UL << CTX_VERSION_SHIFT) + 1UL)
40 #define CTX_VALID(__ctx) \
41 (!(((__ctx) ^ tlb_context_cache) & CTX_VERSION_MASK))
42 #define CTX_HWBITS(__ctx) ((__ctx) & ~CTX_VERSION_MASK)
44 extern void get_new_mmu_context(struct mm_struct *mm);
46 /* Initialize a new mmu context. This is invoked when a new
47 * address space instance (unique or shared) is instantiated.
48 * This just needs to set mm->context to an invalid context.
50 #define init_new_context(__tsk, __mm) (((__mm)->context = 0UL), 0)
52 /* Destroy a dead context. This occurs when mmput drops the
53 * mm_users count to zero, the mmaps have been released, and
54 * all the page tables have been flushed. Our job is to destroy
55 * any remaining processor-specific state, and in the sparc64
56 * case this just means freeing up the mmu context ID held by
59 #define destroy_context(__mm) \
60 do { spin_lock(&ctx_alloc_lock); \
61 if (CTX_VALID((__mm)->context)) { \
62 unsigned long nr = CTX_HWBITS((__mm)->context); \
63 mmu_context_bmap[nr>>6] &= ~(1UL << (nr & 63)); \
65 spin_unlock(&ctx_alloc_lock); \
68 /* Reload the two core values used by TLB miss handler
69 * processing on sparc64. They are:
70 * 1) The physical address of mm->pgd, when full page
71 * table walks are necessary, this is where the
73 * 2) A "PGD cache". For 32-bit tasks only pgd[0] is
74 * ever used since that maps the entire low 4GB
75 * completely. To speed up TLB miss processing we
76 * make this value available to the handlers. This
77 * decreases the amount of memory traffic incurred.
79 #define reload_tlbmiss_state(__tsk, __mm) \
81 register unsigned long paddr asm("o5"); \
82 register unsigned long pgd_cache asm("o4"); \
83 paddr = __pa((__mm)->pgd); \
85 if ((__tsk)->thread_info->flags & _TIF_32BIT) \
86 pgd_cache = get_pgd_cache((__mm)->pgd); \
87 __asm__ __volatile__("wrpr %%g0, 0x494, %%pstate\n\t" \
90 "stxa %1, [%%g4] %2\n\t" \
92 "wrpr %%g0, 0x096, %%pstate" \
94 : "r" (paddr), "r" (pgd_cache),\
95 "i" (ASI_DMMU), "i" (TSB_REG)); \
98 /* Set MMU context in the actual hardware. */
99 #define load_secondary_context(__mm) \
100 __asm__ __volatile__("stxa %0, [%1] %2\n\t" \
103 : "r" (CTX_HWBITS((__mm)->context)), \
104 "r" (0x10), "i" (ASI_DMMU))
106 extern void __flush_tlb_mm(unsigned long, unsigned long);
108 /* Switch the current MM context. */
109 static inline void switch_mm(struct mm_struct *old_mm, struct mm_struct *mm, struct task_struct *tsk)
111 unsigned long ctx_valid;
113 spin_lock(&mm->page_table_lock);
114 if (CTX_VALID(mm->context))
119 if (!ctx_valid || (old_mm != mm)) {
121 get_new_mmu_context(mm);
123 load_secondary_context(mm);
124 reload_tlbmiss_state(tsk, mm);
128 int cpu = smp_processor_id();
130 /* Even if (mm == old_mm) we _must_ check
131 * the cpu_vm_mask. If we do not we could
132 * corrupt the TLB state because of how
133 * smp_flush_tlb_{page,range,mm} on sparc64
134 * and lazy tlb switches work. -DaveM
136 if (!ctx_valid || !cpu_isset(cpu, mm->cpu_vm_mask)) {
137 cpu_set(cpu, mm->cpu_vm_mask);
138 __flush_tlb_mm(CTX_HWBITS(mm->context), SECONDARY_CONTEXT);
141 spin_unlock(&mm->page_table_lock);
144 #define deactivate_mm(tsk,mm) do { } while (0)
146 /* Activate a new MM instance for the current task. */
147 static inline void activate_mm(struct mm_struct *active_mm, struct mm_struct *mm)
151 spin_lock(&mm->page_table_lock);
152 if (!CTX_VALID(mm->context))
153 get_new_mmu_context(mm);
154 cpu = smp_processor_id();
155 if (!cpu_isset(cpu, mm->cpu_vm_mask))
156 cpu_set(cpu, mm->cpu_vm_mask);
157 spin_unlock(&mm->page_table_lock);
159 load_secondary_context(mm);
160 __flush_tlb_mm(CTX_HWBITS(mm->context), SECONDARY_CONTEXT);
161 reload_tlbmiss_state(current, mm);
164 #endif /* !(__ASSEMBLY__) */
166 #endif /* !(__SPARC64_MMU_CONTEXT_H) */