1 #ifndef __PPC64_MMU_CONTEXT_H
2 #define __PPC64_MMU_CONTEXT_H
4 #include <linux/spinlock.h>
5 #include <linux/kernel.h>
8 #include <asm/ppcdebug.h>
10 #include <asm/cputable.h>
13 * Copyright (C) 2001 PPC 64 Team, IBM Corp
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version.
22 #define FIRST_USER_CONTEXT 0x10 /* First 16 reserved for kernel */
23 #define LAST_USER_CONTEXT 0x8000 /* Same as PID_MAX for now... */
24 #define NUM_USER_CONTEXT (LAST_USER_CONTEXT-FIRST_USER_CONTEXT)
26 /* Choose whether we want to implement our context
27 * number allocator as a LIFO or FIFO queue.
30 #define MMU_CONTEXT_LIFO
32 #define MMU_CONTEXT_FIFO
35 struct mmu_context_queue_t {
40 mm_context_t elements[LAST_USER_CONTEXT];
43 extern struct mmu_context_queue_t mmu_context_queue;
46 enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk, unsigned cpu)
50 extern void flush_stab(void);
53 * The context number queue has underflowed.
54 * Meaning: we tried to push a context number that was freed
55 * back onto the context queue and the queue was already full.
58 mmu_context_underflow(void)
60 printk(KERN_DEBUG "mmu_context_underflow\n");
61 panic("mmu_context_underflow");
66 * Set up the context for a new address space.
69 init_new_context(struct task_struct *tsk, struct mm_struct *mm)
74 spin_lock_irqsave(&mmu_context_queue.lock, flags);
76 if ( (size = mmu_context_queue.size) <= 0 ) {
77 spin_unlock_irqrestore(&mmu_context_queue.lock, flags);
81 head = mmu_context_queue.head;
82 mm->context = mmu_context_queue.elements[head];
84 head = (head < LAST_USER_CONTEXT-1) ? head+1 : 0;
85 mmu_context_queue.head = head;
86 mmu_context_queue.size = size-1;
88 spin_unlock_irqrestore(&mmu_context_queue.lock, flags);
94 * We're finished using the context for an address space.
97 destroy_context(struct mm_struct *mm)
99 long index, size = mmu_context_queue.size;
102 spin_lock_irqsave(&mmu_context_queue.lock, flags);
104 if ( (size = mmu_context_queue.size) >= NUM_USER_CONTEXT ) {
105 spin_unlock_irqrestore(&mmu_context_queue.lock, flags);
106 mmu_context_underflow();
109 #ifdef MMU_CONTEXT_LIFO
110 index = mmu_context_queue.head;
111 index = (index > 0) ? index-1 : LAST_USER_CONTEXT-1;
112 mmu_context_queue.head = index;
114 index = mmu_context_queue.tail;
115 index = (index < LAST_USER_CONTEXT-1) ? index+1 : 0;
116 mmu_context_queue.tail = index;
119 mmu_context_queue.size = size+1;
120 mmu_context_queue.elements[index] = mm->context;
122 spin_unlock_irqrestore(&mmu_context_queue.lock, flags);
125 extern void flush_stab(void);
128 * switch_mm is the entry point called from the architecture independent
129 * code in kernel/sched.c
132 switch_mm(struct mm_struct *prev, struct mm_struct *next,
133 struct task_struct *tsk, int cpu)
135 #ifdef CONFIG_ALTIVEC
136 __asm__ __volatile__(
140 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
147 * After we have set current->mm to a new value, this activates
148 * the context for the new mm so we see the new mappings.
150 #define activate_mm(active_mm, mm) \
151 switch_mm(active_mm, mm, current, smp_processor_id());
153 #define VSID_RANDOMIZER 42470972311
154 #define VSID_MASK 0xfffffffff
157 /* This is only valid for kernel (including vmalloc, imalloc and bolted) EA's
159 static inline unsigned long
160 get_kernel_vsid( unsigned long ea )
162 unsigned long ordinal, vsid;
164 ordinal = (((ea >> 28) & 0x1fffff) * LAST_USER_CONTEXT) | (ea >> 60);
165 vsid = (ordinal * VSID_RANDOMIZER) & VSID_MASK;
167 ifppcdebug(PPCDBG_HTABSTRESS) {
168 /* For debug, this path creates a very poor vsid distribuition.
169 * A user program can access virtual addresses in the form
170 * 0x0yyyyxxxx000 where yyyy = xxxx to cause multiple mappings
171 * to hash to the same page table group.
173 ordinal = ((ea >> 28) & 0x1fff) | (ea >> 44);
174 vsid = ordinal & VSID_MASK;
180 /* This is only valid for user EA's (user EA's do not exceed 2^41 (EADDR_SIZE))
182 static inline unsigned long
183 get_vsid( unsigned long context, unsigned long ea )
185 unsigned long ordinal, vsid;
187 ordinal = (((ea >> 28) & 0x1fffff) * LAST_USER_CONTEXT) | context;
188 vsid = (ordinal * VSID_RANDOMIZER) & VSID_MASK;
190 ifppcdebug(PPCDBG_HTABSTRESS) {
191 /* See comment above. */
192 ordinal = ((ea >> 28) & 0x1fff) | (context << 16);
193 vsid = ordinal & VSID_MASK;
199 #endif /* __PPC64_MMU_CONTEXT_H */