2 #ifndef __PPC_MMU_CONTEXT_H
3 #define __PPC_MMU_CONTEXT_H
5 #include <linux/config.h>
6 #include <asm/atomic.h>
7 #include <asm/bitops.h>
11 * On 32-bit PowerPC 6xx/7xx/7xxx CPUs, we use a set of 16 VSIDs
12 * (virtual segment identifiers) for each context. Although the
13 * hardware supports 24-bit VSIDs, and thus >1 million contexts,
14 * we only use 32,768 of them. That is ample, since there can be
15 * at most around 30,000 tasks in the system anyway, and it means
16 * that we can use a bitmap to indicate which contexts are in use.
17 * Using a bitmap means that we entirely avoid all of the problems
18 * that we used to have when the context number overflowed,
19 * particularly on SMP systems.
24 * This function defines the mapping from contexts to VSIDs (virtual
25 * segment IDs). We use a skew on both the context and the high 4 bits
26 * of the 32-bit virtual address (the "effective segment ID") in order
27 * to spread out the entries in the MMU hash table. Note, if this
28 * function is changed then arch/ppc/mm/hashtable.S will have to be
29 * changed to correspond.
31 #define CTX_TO_VSID(ctx, va) (((ctx) * (897 * 16) + ((va) >> 28) * 0x111) \
35 The MPC8xx has only 16 contexts. We rotate through them on each
36 task switch. A better way would be to keep track of tasks that
37 own contexts, and implement an LRU usage. That way very active
38 tasks don't always have to pay the TLB reload overhead. The
39 kernel pages are mapped shared, so the kernel can run on behalf
40 of any task that makes a kernel entry. Shared does not mean they
41 are not protected, just that the ASID comparison is not performed.
44 The IBM4xx has 256 contexts, so we can just rotate through these
45 as a way of "switching" contexts. If the TID of the TLB is zero,
46 the PID/TID comparison is disabled, so we can use a TID of zero
47 to represent all kernel pages as shared among all contexts.
51 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk, unsigned cpu)
57 #define LAST_CONTEXT 15
58 #define FIRST_CONTEXT 0
61 #define NO_CONTEXT 256
62 #define LAST_CONTEXT 255
63 #define FIRST_CONTEXT 1
67 /* PPC 6xx, 7xx CPUs */
68 #define NO_CONTEXT ((mm_context_t) -1)
69 #define LAST_CONTEXT 32767
70 #define FIRST_CONTEXT 1
74 * Set the current MMU context.
75 * On 32-bit PowerPCs (other than the 8xx embedded chips), this is done by
76 * loading up the segment registers for the user part of the address space.
78 * Since the PGD is immediately available, it is much faster to simply
79 * pass this along as a second parameter, which is required for 8xx and
80 * can be used for debugging on all processors (if you happen to have
83 extern void set_context(mm_context_t context, pgd_t *pgd);
86 * Bitmap of contexts in use.
87 * The size of this bitmap is LAST_CONTEXT + 1 bits.
89 extern unsigned long context_map[];
92 * This caches the next context number that we expect to be free.
93 * Its use is an optimization only, we can't rely on this context
94 * number to be free, but it usually will be.
96 extern mm_context_t next_mmu_context;
99 * If we don't have sufficient contexts to give one to every task
100 * that could be in the system, we need to be able to steal contexts.
101 * These variables support that.
103 #if LAST_CONTEXT < 30000
104 #define FEW_CONTEXTS 1
105 extern atomic_t nr_free_contexts;
106 extern struct mm_struct *context_mm[LAST_CONTEXT+1];
107 extern void steal_context(void);
111 * Get a new mmu context for the address space described by `mm'.
113 static inline void get_mmu_context(struct mm_struct *mm)
117 if (mm->context != NO_CONTEXT)
120 while (atomic_dec_if_positive(&nr_free_contexts) < 0)
123 ctx = next_mmu_context;
124 while (test_and_set_bit(ctx, context_map)) {
125 ctx = find_next_zero_bit(context_map, LAST_CONTEXT+1, ctx);
126 if (ctx > LAST_CONTEXT)
129 next_mmu_context = (ctx + 1) & LAST_CONTEXT;
132 context_mm[ctx] = mm;
137 * Set up the context for a new address space.
139 #define init_new_context(tsk,mm) (((mm)->context = NO_CONTEXT), 0)
142 * We're finished using the context for an address space.
144 static inline void destroy_context(struct mm_struct *mm)
146 if (mm->context != NO_CONTEXT) {
147 clear_bit(mm->context, context_map);
148 mm->context = NO_CONTEXT;
150 atomic_inc(&nr_free_contexts);
155 static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
156 struct task_struct *tsk, int cpu)
158 tsk->thread.pgdir = next->pgd;
159 get_mmu_context(next);
160 set_context(next->context, next->pgd);
164 * After we have set current->mm to a new value, this activates
165 * the context for the new mm so we see the new mappings.
167 static inline void activate_mm(struct mm_struct *active_mm, struct mm_struct *mm)
169 current->thread.pgdir = mm->pgd;
171 set_context(mm->context, mm->pgd);
174 extern void mmu_context_init(void);
176 #endif /* __PPC_MMU_CONTEXT_H */
177 #endif /* __KERNEL__ */