Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / mn10300 / include / asm / mmu_context.h
blobd2034f5e6eda790fab4e6380c3bd8f8b6a398e78
1 /* MN10300 MMU context management
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Modified by David Howells (dhowells@redhat.com)
5 * - Derived from include/asm-m32r/mmu_context.h
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public Licence
9 * as published by the Free Software Foundation; either version
10 * 2 of the Licence, or (at your option) any later version.
13 * This implements an algorithm to provide TLB PID mappings to provide
14 * selective access to the TLB for processes, thus reducing the number of TLB
15 * flushes required.
17 * Note, however, that the M32R algorithm is technically broken as it does not
18 * handle version wrap-around, and could, theoretically, have a problem with a
19 * very long lived program that sleeps long enough for the version number to
20 * wrap all the way around so that its TLB mappings appear valid once again.
22 #ifndef _ASM_MMU_CONTEXT_H
23 #define _ASM_MMU_CONTEXT_H
25 #include <linux/atomic.h>
26 #include <linux/mm_types.h>
28 #include <asm/pgalloc.h>
29 #include <asm/tlbflush.h>
30 #include <asm-generic/mm_hooks.h>
32 #define MMU_CONTEXT_TLBPID_NR 256
33 #define MMU_CONTEXT_TLBPID_MASK 0x000000ffUL
34 #define MMU_CONTEXT_VERSION_MASK 0xffffff00UL
35 #define MMU_CONTEXT_FIRST_VERSION 0x00000100UL
36 #define MMU_NO_CONTEXT 0x00000000UL
37 #define MMU_CONTEXT_TLBPID_LOCK_NR 0
39 #define enter_lazy_tlb(mm, tsk) do {} while (0)
41 static inline void cpu_ran_vm(int cpu, struct mm_struct *mm)
43 #ifdef CONFIG_SMP
44 cpumask_set_cpu(cpu, mm_cpumask(mm));
45 #endif
48 static inline bool cpu_maybe_ran_vm(int cpu, struct mm_struct *mm)
50 #ifdef CONFIG_SMP
51 return cpumask_test_and_set_cpu(cpu, mm_cpumask(mm));
52 #else
53 return true;
54 #endif
57 #ifdef CONFIG_MN10300_TLB_USE_PIDR
58 extern unsigned long mmu_context_cache[NR_CPUS];
59 #define mm_context(mm) (mm->context.tlbpid[smp_processor_id()])
61 /**
62 * allocate_mmu_context - Allocate storage for the arch-specific MMU data
63 * @mm: The userspace VM context being set up
65 static inline unsigned long allocate_mmu_context(struct mm_struct *mm)
67 unsigned long *pmc = &mmu_context_cache[smp_processor_id()];
68 unsigned long mc = ++(*pmc);
70 if (!(mc & MMU_CONTEXT_TLBPID_MASK)) {
71 /* we exhausted the TLB PIDs of this version on this CPU, so we
72 * flush this CPU's TLB in its entirety and start new cycle */
73 local_flush_tlb_all();
75 /* fix the TLB version if needed (we avoid version #0 so as to
76 * distinguish MMU_NO_CONTEXT) */
77 if (!mc)
78 *pmc = mc = MMU_CONTEXT_FIRST_VERSION;
80 mm_context(mm) = mc;
81 return mc;
85 * get an MMU context if one is needed
87 static inline unsigned long get_mmu_context(struct mm_struct *mm)
89 unsigned long mc = MMU_NO_CONTEXT, cache;
91 if (mm) {
92 cache = mmu_context_cache[smp_processor_id()];
93 mc = mm_context(mm);
95 /* if we have an old version of the context, replace it */
96 if ((mc ^ cache) & MMU_CONTEXT_VERSION_MASK)
97 mc = allocate_mmu_context(mm);
99 return mc;
103 * initialise the context related info for a new mm_struct instance
105 static inline int init_new_context(struct task_struct *tsk,
106 struct mm_struct *mm)
108 int num_cpus = NR_CPUS, i;
110 for (i = 0; i < num_cpus; i++)
111 mm->context.tlbpid[i] = MMU_NO_CONTEXT;
112 return 0;
116 * after we have set current->mm to a new value, this activates the context for
117 * the new mm so we see the new mappings.
119 static inline void activate_context(struct mm_struct *mm)
121 PIDR = get_mmu_context(mm) & MMU_CONTEXT_TLBPID_MASK;
123 #else /* CONFIG_MN10300_TLB_USE_PIDR */
125 #define init_new_context(tsk, mm) (0)
126 #define activate_context(mm) local_flush_tlb()
128 #endif /* CONFIG_MN10300_TLB_USE_PIDR */
131 * destroy_context - Destroy mm context information
132 * @mm: The MM being destroyed.
134 * Destroy context related info for an mm_struct that is about to be put to
135 * rest
137 #define destroy_context(mm) do {} while (0)
140 * switch_mm - Change between userspace virtual memory contexts
141 * @prev: The outgoing MM context.
142 * @next: The incoming MM context.
143 * @tsk: The incoming task.
145 static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
146 struct task_struct *tsk)
148 int cpu = smp_processor_id();
150 if (prev != next) {
151 #ifdef CONFIG_SMP
152 per_cpu(cpu_tlbstate, cpu).active_mm = next;
153 #endif
154 cpu_ran_vm(cpu, next);
155 PTBR = (unsigned long) next->pgd;
156 activate_context(next);
160 #define deactivate_mm(tsk, mm) do {} while (0)
161 #define activate_mm(prev, next) switch_mm((prev), (next), NULL)
163 #endif /* _ASM_MMU_CONTEXT_H */