arm64: mm: remove unused cpu_set_idmap_tcr_t0sz function
[deliverable/linux.git] / arch / arm64 / include / asm / mmu_context.h
1 /*
2 * Based on arch/arm/include/asm/mmu_context.h
3 *
4 * Copyright (C) 1996 Russell King.
5 * Copyright (C) 2012 ARM Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #ifndef __ASM_MMU_CONTEXT_H
20 #define __ASM_MMU_CONTEXT_H
21
22 #include <linux/compiler.h>
23 #include <linux/sched.h>
24
25 #include <asm/cacheflush.h>
26 #include <asm/proc-fns.h>
27 #include <asm-generic/mm_hooks.h>
28 #include <asm/cputype.h>
29 #include <asm/pgtable.h>
30
31 #define MAX_ASID_BITS 16
32
33 extern unsigned int cpu_last_asid;
34
35 void __init_new_context(struct task_struct *tsk, struct mm_struct *mm);
36 void __new_context(struct mm_struct *mm);
37
38 #ifdef CONFIG_PID_IN_CONTEXTIDR
39 static inline void contextidr_thread_switch(struct task_struct *next)
40 {
41 asm(
42 " msr contextidr_el1, %0\n"
43 " isb"
44 :
45 : "r" (task_pid_nr(next)));
46 }
47 #else
48 static inline void contextidr_thread_switch(struct task_struct *next)
49 {
50 }
51 #endif
52
53 /*
54 * Set TTBR0 to empty_zero_page. No translations will be possible via TTBR0.
55 */
56 static inline void cpu_set_reserved_ttbr0(void)
57 {
58 unsigned long ttbr = page_to_phys(empty_zero_page);
59
60 asm(
61 " msr ttbr0_el1, %0 // set TTBR0\n"
62 " isb"
63 :
64 : "r" (ttbr));
65 }
66
67 /*
68 * TCR.T0SZ value to use when the ID map is active. Usually equals
69 * TCR_T0SZ(VA_BITS), unless system RAM is positioned very high in
70 * physical memory, in which case it will be smaller.
71 */
72 extern u64 idmap_t0sz;
73
74 static inline bool __cpu_uses_extended_idmap(void)
75 {
76 return (!IS_ENABLED(CONFIG_ARM64_VA_BITS_48) &&
77 unlikely(idmap_t0sz != TCR_T0SZ(VA_BITS)));
78 }
79
80 /*
81 * Set TCR.T0SZ to its default value (based on VA_BITS)
82 */
83 static inline void cpu_set_default_tcr_t0sz(void)
84 {
85 unsigned long tcr;
86
87 if (!__cpu_uses_extended_idmap())
88 return;
89
90 asm volatile (
91 " mrs %0, tcr_el1 ;"
92 " bfi %0, %1, %2, %3 ;"
93 " msr tcr_el1, %0 ;"
94 " isb"
95 : "=&r" (tcr)
96 : "r"(TCR_T0SZ(VA_BITS)), "I"(TCR_T0SZ_OFFSET), "I"(TCR_TxSZ_WIDTH));
97 }
98
99 static inline void switch_new_context(struct mm_struct *mm)
100 {
101 unsigned long flags;
102
103 __new_context(mm);
104
105 local_irq_save(flags);
106 cpu_switch_mm(mm->pgd, mm);
107 local_irq_restore(flags);
108 }
109
110 static inline void check_and_switch_context(struct mm_struct *mm,
111 struct task_struct *tsk)
112 {
113 /*
114 * Required during context switch to avoid speculative page table
115 * walking with the wrong TTBR.
116 */
117 cpu_set_reserved_ttbr0();
118
119 if (!((mm->context.id ^ cpu_last_asid) >> MAX_ASID_BITS))
120 /*
121 * The ASID is from the current generation, just switch to the
122 * new pgd. This condition is only true for calls from
123 * context_switch() and interrupts are already disabled.
124 */
125 cpu_switch_mm(mm->pgd, mm);
126 else if (irqs_disabled())
127 /*
128 * Defer the new ASID allocation until after the context
129 * switch critical region since __new_context() cannot be
130 * called with interrupts disabled.
131 */
132 set_ti_thread_flag(task_thread_info(tsk), TIF_SWITCH_MM);
133 else
134 /*
135 * That is a direct call to switch_mm() or activate_mm() with
136 * interrupts enabled and a new context.
137 */
138 switch_new_context(mm);
139 }
140
141 #define init_new_context(tsk,mm) (__init_new_context(tsk,mm),0)
142 #define destroy_context(mm) do { } while(0)
143
144 #define finish_arch_post_lock_switch \
145 finish_arch_post_lock_switch
146 static inline void finish_arch_post_lock_switch(void)
147 {
148 if (test_and_clear_thread_flag(TIF_SWITCH_MM)) {
149 struct mm_struct *mm = current->mm;
150 unsigned long flags;
151
152 __new_context(mm);
153
154 local_irq_save(flags);
155 cpu_switch_mm(mm->pgd, mm);
156 local_irq_restore(flags);
157 }
158 }
159
160 /*
161 * This is called when "tsk" is about to enter lazy TLB mode.
162 *
163 * mm: describes the currently active mm context
164 * tsk: task which is entering lazy tlb
165 * cpu: cpu number which is entering lazy tlb
166 *
167 * tsk->mm will be NULL
168 */
169 static inline void
170 enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
171 {
172 }
173
174 /*
175 * This is the actual mm switch as far as the scheduler
176 * is concerned. No registers are touched. We avoid
177 * calling the CPU specific function when the mm hasn't
178 * actually changed.
179 */
180 static inline void
181 switch_mm(struct mm_struct *prev, struct mm_struct *next,
182 struct task_struct *tsk)
183 {
184 unsigned int cpu = smp_processor_id();
185
186 /*
187 * init_mm.pgd does not contain any user mappings and it is always
188 * active for kernel addresses in TTBR1. Just set the reserved TTBR0.
189 */
190 if (next == &init_mm) {
191 cpu_set_reserved_ttbr0();
192 return;
193 }
194
195 if (!cpumask_test_and_set_cpu(cpu, mm_cpumask(next)) || prev != next)
196 check_and_switch_context(next, tsk);
197 }
198
199 #define deactivate_mm(tsk,mm) do { } while (0)
200 #define activate_mm(prev,next) switch_mm(prev, next, NULL)
201
202 #endif
This page took 0.036144 seconds and 5 git commands to generate.