Merge with Linux 2.4.0-test6-pre9.
[linux-2.6/linux-mips.git] / include / asm-mips64 / mmu_context.h
blob0fe300bda61e5623f6a7bb830e1d79f7e28efbf1
1 /* $Id: mmu_context.h,v 1.4 2000/02/23 00:41:38 ralf Exp $
3 * Switch a MMU context.
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
9 * Copyright (C) 1996, 1997, 1998, 1999 by Ralf Baechle
10 * Copyright (C) 1999 Silicon Graphics, Inc.
12 #ifndef _ASM_MMU_CONTEXT_H
13 #define _ASM_MMU_CONTEXT_H
15 #include <linux/config.h>
16 #include <linux/slab.h>
17 #include <asm/pgalloc.h>
18 #include <asm/processor.h>
21 * For the fast tlb miss handlers, we currently keep a per cpu array
22 * of pointers to the current pgd for each processor. Also, the proc.
23 * id is stuffed into the context register. This should be changed to
24 * use the processor id via current->processor, where current is stored
25 * in watchhi/lo. The context register should be used to contiguously
26 * map the page tables.
28 #define TLBMISS_HANDLER_SETUP_PGD(pgd) \
29 pgd_current[smp_processor_id()] = (unsigned long)(pgd)
30 #define TLBMISS_HANDLER_SETUP() \
31 set_context((unsigned long) smp_processor_id() << (23 + 3)); \
32 TLBMISS_HANDLER_SETUP_PGD(swapper_pg_dir)
33 extern unsigned long pgd_current[];
35 #ifndef CONFIG_SMP
36 #define CPU_CONTEXT(cpu, mm) (mm)->context
37 #else
38 #define CPU_CONTEXT(cpu, mm) (*((unsigned long *)((mm)->context) + cpu))
39 #endif
40 #define ASID_CACHE(cpu) cpu_data[cpu].asid_cache
42 #define ASID_INC 0x1
43 #define ASID_MASK 0xff
45 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk, unsigned cpu)
50 * All unused by hardware upper bits will be considered
51 * as a software asid extension.
53 #define ASID_VERSION_MASK ((unsigned long)~(ASID_MASK|(ASID_MASK-1)))
54 #define ASID_FIRST_VERSION ((unsigned long)(~ASID_VERSION_MASK) + 1)
56 extern inline void
57 get_new_cpu_mmu_context(struct mm_struct *mm, unsigned long cpu)
59 unsigned long asid = ASID_CACHE(cpu);
61 if (! ((asid += ASID_INC) & ASID_MASK) ) {
62 _flush_tlb_all(); /* start new asid cycle */
63 if (!asid) /* fix version if needed */
64 asid = ASID_FIRST_VERSION;
66 CPU_CONTEXT(cpu, mm) = ASID_CACHE(cpu) = asid;
70 * Initialize the context related info for a new mm_struct
71 * instance.
73 extern inline void
74 init_new_context(struct task_struct *tsk, struct mm_struct *mm)
76 #ifndef CONFIG_SMP
77 mm->context = 0;
78 #else
79 mm->context = (unsigned long)kmalloc(smp_num_cpus *
80 sizeof(unsigned long), GFP_KERNEL);
82 * Init the "context" values so that a tlbpid allocation
83 * happens on the first switch.
85 if (mm->context)
86 memset((void *)mm->context, 0, smp_num_cpus *
87 sizeof(unsigned long));
88 else
89 printk("Warning: init_new_context failed\n");
90 #endif
93 extern inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
94 struct task_struct *tsk, unsigned cpu)
96 /* Check if our ASID is of an older version and thus invalid */
97 if ((CPU_CONTEXT(cpu, next) ^ ASID_CACHE(cpu)) & ASID_VERSION_MASK)
98 get_new_cpu_mmu_context(next, cpu);
100 set_entryhi(CPU_CONTEXT(cpu, next) & 0xff);
101 TLBMISS_HANDLER_SETUP_PGD(next->pgd);
105 * Destroy context related info for an mm_struct that is about
106 * to be put to rest.
108 extern inline void destroy_context(struct mm_struct *mm)
110 #ifdef CONFIG_SMP
111 if (mm->context)
112 kfree((void *)mm->context);
113 #endif
117 * After we have set current->mm to a new value, this activates
118 * the context for the new mm so we see the new mappings.
120 extern inline void
121 activate_mm(struct mm_struct *prev, struct mm_struct *next)
123 /* Unconditionally get a new ASID. */
124 get_new_cpu_mmu_context(next, smp_processor_id());
126 set_entryhi(CPU_CONTEXT(smp_processor_id(), next) & 0xff);
127 TLBMISS_HANDLER_SETUP_PGD(next->pgd);
130 #endif /* _ASM_MMU_CONTEXT_H */