blob: ae2e799822bd1c69e55f9b8abfddef1f25648ae7 [file] [log] [blame]
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +10001/*
2 * TLB flush routines for radix kernels.
3 *
4 * Copyright 2015-2016, Aneesh Kumar K.V, IBM Corporation.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/mm.h>
13#include <linux/hugetlb.h>
14#include <linux/memblock.h>
Balbir Singh8cd6d3c2016-07-13 15:05:20 +053015#include <asm/ppc-opcode.h>
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100016
17#include <asm/tlb.h>
18#include <asm/tlbflush.h>
19
20static DEFINE_RAW_SPINLOCK(native_tlbie_lock);
21
Aneesh Kumar K.V36194812016-06-08 19:55:50 +053022#define RIC_FLUSH_TLB 0
23#define RIC_FLUSH_PWC 1
24#define RIC_FLUSH_ALL 2
25
26static inline void __tlbiel_pid(unsigned long pid, int set,
27 unsigned long ric)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100028{
Aneesh Kumar K.V36194812016-06-08 19:55:50 +053029 unsigned long rb,rs,prs,r;
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100030
31 rb = PPC_BIT(53); /* IS = 1 */
32 rb |= set << PPC_BITLSHIFT(51);
33 rs = ((unsigned long)pid) << PPC_BITLSHIFT(31);
34 prs = 1; /* process scoped */
35 r = 1; /* raidx format */
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100036
Balbir Singh8cd6d3c2016-07-13 15:05:20 +053037 asm volatile(PPC_TLBIEL(%0, %4, %3, %2, %1)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100038 : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(rs) : "memory");
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100039}
40
41/*
42 * We use 128 set in radix mode and 256 set in hpt mode.
43 */
Aneesh Kumar K.V36194812016-06-08 19:55:50 +053044static inline void _tlbiel_pid(unsigned long pid, unsigned long ric)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100045{
46 int set;
47
Aneesh Kumar K.Vf7327e02017-04-01 20:11:48 +053048 asm volatile("ptesync": : :"memory");
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100049 for (set = 0; set < POWER9_TLB_SETS_RADIX ; set++) {
Aneesh Kumar K.V36194812016-06-08 19:55:50 +053050 __tlbiel_pid(pid, set, ric);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100051 }
Aneesh Kumar K.Vf7327e02017-04-01 20:11:48 +053052 asm volatile("ptesync": : :"memory");
Benjamin Herrenschmidt90c1e3c2017-02-06 13:05:16 +110053 asm volatile(PPC_INVALIDATE_ERAT "; isync" : : :"memory");
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100054}
55
Aneesh Kumar K.Vcf4f08b2017-04-26 21:38:30 +100056static inline void tlbiel_pwc(unsigned long pid)
57{
58 asm volatile("ptesync": : :"memory");
59
60 /* For PWC flush, we don't look at set number */
61 __tlbiel_pid(pid, 0, RIC_FLUSH_PWC);
62
63 asm volatile("ptesync": : :"memory");
64 asm volatile(PPC_INVALIDATE_ERAT "; isync" : : :"memory");
65}
66
Aneesh Kumar K.V36194812016-06-08 19:55:50 +053067static inline void _tlbie_pid(unsigned long pid, unsigned long ric)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100068{
Aneesh Kumar K.V36194812016-06-08 19:55:50 +053069 unsigned long rb,rs,prs,r;
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100070
71 rb = PPC_BIT(53); /* IS = 1 */
72 rs = pid << PPC_BITLSHIFT(31);
73 prs = 1; /* process scoped */
74 r = 1; /* raidx format */
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100075
76 asm volatile("ptesync": : :"memory");
Balbir Singh8cd6d3c2016-07-13 15:05:20 +053077 asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100078 : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(rs) : "memory");
79 asm volatile("eieio; tlbsync; ptesync": : :"memory");
80}
81
82static inline void _tlbiel_va(unsigned long va, unsigned long pid,
Aneesh Kumar K.V36194812016-06-08 19:55:50 +053083 unsigned long ap, unsigned long ric)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100084{
Aneesh Kumar K.V36194812016-06-08 19:55:50 +053085 unsigned long rb,rs,prs,r;
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100086
87 rb = va & ~(PPC_BITMASK(52, 63));
88 rb |= ap << PPC_BITLSHIFT(58);
89 rs = pid << PPC_BITLSHIFT(31);
90 prs = 1; /* process scoped */
91 r = 1; /* raidx format */
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100092
93 asm volatile("ptesync": : :"memory");
Balbir Singh8cd6d3c2016-07-13 15:05:20 +053094 asm volatile(PPC_TLBIEL(%0, %4, %3, %2, %1)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100095 : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(rs) : "memory");
96 asm volatile("ptesync": : :"memory");
97}
98
99static inline void _tlbie_va(unsigned long va, unsigned long pid,
Aneesh Kumar K.V36194812016-06-08 19:55:50 +0530100 unsigned long ap, unsigned long ric)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000101{
Aneesh Kumar K.V36194812016-06-08 19:55:50 +0530102 unsigned long rb,rs,prs,r;
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000103
104 rb = va & ~(PPC_BITMASK(52, 63));
105 rb |= ap << PPC_BITLSHIFT(58);
106 rs = pid << PPC_BITLSHIFT(31);
107 prs = 1; /* process scoped */
108 r = 1; /* raidx format */
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000109
110 asm volatile("ptesync": : :"memory");
Balbir Singh8cd6d3c2016-07-13 15:05:20 +0530111 asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000112 : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(rs) : "memory");
113 asm volatile("eieio; tlbsync; ptesync": : :"memory");
114}
115
116/*
117 * Base TLB flushing operations:
118 *
119 * - flush_tlb_mm(mm) flushes the specified mm context TLB's
120 * - flush_tlb_page(vma, vmaddr) flushes one page
121 * - flush_tlb_range(vma, start, end) flushes a range of pages
122 * - flush_tlb_kernel_range(start, end) flushes kernel pages
123 *
124 * - local_* variants of page and mm only apply to the current
125 * processor
126 */
127void radix__local_flush_tlb_mm(struct mm_struct *mm)
128{
Aneesh Kumar K.V9690c152016-06-02 15:14:48 +0530129 unsigned long pid;
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000130
131 preempt_disable();
132 pid = mm->context.id;
133 if (pid != MMU_NO_CONTEXT)
Aneesh Kumar K.V36194812016-06-08 19:55:50 +0530134 _tlbiel_pid(pid, RIC_FLUSH_ALL);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000135 preempt_enable();
136}
137EXPORT_SYMBOL(radix__local_flush_tlb_mm);
138
Aneesh Kumar K.Va145abf2016-06-08 19:55:51 +0530139void radix__local_flush_tlb_pwc(struct mmu_gather *tlb, unsigned long addr)
140{
141 unsigned long pid;
142 struct mm_struct *mm = tlb->mm;
Aneesh Kumar K.Vf6b0df52017-04-01 20:11:47 +0530143 /*
144 * If we are doing a full mm flush, we will do a tlb flush
145 * with RIC_FLUSH_ALL later.
146 */
147 if (tlb->fullmm)
148 return;
Aneesh Kumar K.Va145abf2016-06-08 19:55:51 +0530149
150 preempt_disable();
151
152 pid = mm->context.id;
153 if (pid != MMU_NO_CONTEXT)
Aneesh Kumar K.Vcf4f08b2017-04-26 21:38:30 +1000154 tlbiel_pwc(pid);
Aneesh Kumar K.Va145abf2016-06-08 19:55:51 +0530155
156 preempt_enable();
157}
158EXPORT_SYMBOL(radix__local_flush_tlb_pwc);
159
Aneesh Kumar K.Vf22dfc92016-07-13 15:06:41 +0530160void radix__local_flush_tlb_page_psize(struct mm_struct *mm, unsigned long vmaddr,
Aneesh Kumar K.Vfbfa26d2016-07-13 15:06:42 +0530161 int psize)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000162{
Aneesh Kumar K.V9690c152016-06-02 15:14:48 +0530163 unsigned long pid;
Aneesh Kumar K.Vfbfa26d2016-07-13 15:06:42 +0530164 unsigned long ap = mmu_get_ap(psize);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000165
166 preempt_disable();
167 pid = mm ? mm->context.id : 0;
168 if (pid != MMU_NO_CONTEXT)
Aneesh Kumar K.V36194812016-06-08 19:55:50 +0530169 _tlbiel_va(vmaddr, pid, ap, RIC_FLUSH_TLB);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000170 preempt_enable();
171}
172
173void radix__local_flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
174{
Aneesh Kumar K.V48483762016-04-29 23:26:25 +1000175#ifdef CONFIG_HUGETLB_PAGE
176 /* need the return fix for nohash.c */
177 if (vma && is_vm_hugetlb_page(vma))
178 return __local_flush_hugetlb_page(vma, vmaddr);
179#endif
Aneesh Kumar K.Vf22dfc92016-07-13 15:06:41 +0530180 radix__local_flush_tlb_page_psize(vma ? vma->vm_mm : NULL, vmaddr,
Aneesh Kumar K.Vfbfa26d2016-07-13 15:06:42 +0530181 mmu_virtual_psize);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000182}
183EXPORT_SYMBOL(radix__local_flush_tlb_page);
184
185#ifdef CONFIG_SMP
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000186void radix__flush_tlb_mm(struct mm_struct *mm)
187{
Aneesh Kumar K.V9690c152016-06-02 15:14:48 +0530188 unsigned long pid;
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000189
190 preempt_disable();
191 pid = mm->context.id;
192 if (unlikely(pid == MMU_NO_CONTEXT))
193 goto no_context;
194
Aneesh Kumar K.Vbd77c442016-10-24 08:50:43 +0530195 if (!mm_is_thread_local(mm)) {
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000196 int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE);
197
198 if (lock_tlbie)
199 raw_spin_lock(&native_tlbie_lock);
Aneesh Kumar K.V36194812016-06-08 19:55:50 +0530200 _tlbie_pid(pid, RIC_FLUSH_ALL);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000201 if (lock_tlbie)
202 raw_spin_unlock(&native_tlbie_lock);
203 } else
Aneesh Kumar K.V36194812016-06-08 19:55:50 +0530204 _tlbiel_pid(pid, RIC_FLUSH_ALL);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000205no_context:
206 preempt_enable();
207}
208EXPORT_SYMBOL(radix__flush_tlb_mm);
209
Aneesh Kumar K.Va145abf2016-06-08 19:55:51 +0530210void radix__flush_tlb_pwc(struct mmu_gather *tlb, unsigned long addr)
211{
212 unsigned long pid;
213 struct mm_struct *mm = tlb->mm;
214
Aneesh Kumar K.Vf6b0df52017-04-01 20:11:47 +0530215 /*
216 * If we are doing a full mm flush, we will do a tlb flush
217 * with RIC_FLUSH_ALL later.
218 */
219 if (tlb->fullmm)
220 return;
Aneesh Kumar K.Va145abf2016-06-08 19:55:51 +0530221 preempt_disable();
222
223 pid = mm->context.id;
224 if (unlikely(pid == MMU_NO_CONTEXT))
225 goto no_context;
226
Aneesh Kumar K.Vbd77c442016-10-24 08:50:43 +0530227 if (!mm_is_thread_local(mm)) {
Aneesh Kumar K.Va145abf2016-06-08 19:55:51 +0530228 int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE);
229
230 if (lock_tlbie)
231 raw_spin_lock(&native_tlbie_lock);
232 _tlbie_pid(pid, RIC_FLUSH_PWC);
233 if (lock_tlbie)
234 raw_spin_unlock(&native_tlbie_lock);
235 } else
Aneesh Kumar K.Vcf4f08b2017-04-26 21:38:30 +1000236 tlbiel_pwc(pid);
Aneesh Kumar K.Va145abf2016-06-08 19:55:51 +0530237no_context:
238 preempt_enable();
239}
240EXPORT_SYMBOL(radix__flush_tlb_pwc);
241
Aneesh Kumar K.Vf22dfc92016-07-13 15:06:41 +0530242void radix__flush_tlb_page_psize(struct mm_struct *mm, unsigned long vmaddr,
Aneesh Kumar K.Vfbfa26d2016-07-13 15:06:42 +0530243 int psize)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000244{
Aneesh Kumar K.V9690c152016-06-02 15:14:48 +0530245 unsigned long pid;
Aneesh Kumar K.Vfbfa26d2016-07-13 15:06:42 +0530246 unsigned long ap = mmu_get_ap(psize);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000247
248 preempt_disable();
249 pid = mm ? mm->context.id : 0;
250 if (unlikely(pid == MMU_NO_CONTEXT))
251 goto bail;
Aneesh Kumar K.Vbd77c442016-10-24 08:50:43 +0530252 if (!mm_is_thread_local(mm)) {
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000253 int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE);
254
255 if (lock_tlbie)
256 raw_spin_lock(&native_tlbie_lock);
Aneesh Kumar K.V36194812016-06-08 19:55:50 +0530257 _tlbie_va(vmaddr, pid, ap, RIC_FLUSH_TLB);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000258 if (lock_tlbie)
259 raw_spin_unlock(&native_tlbie_lock);
260 } else
Aneesh Kumar K.V36194812016-06-08 19:55:50 +0530261 _tlbiel_va(vmaddr, pid, ap, RIC_FLUSH_TLB);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000262bail:
263 preempt_enable();
264}
265
266void radix__flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
267{
Aneesh Kumar K.V48483762016-04-29 23:26:25 +1000268#ifdef CONFIG_HUGETLB_PAGE
269 if (vma && is_vm_hugetlb_page(vma))
270 return flush_hugetlb_page(vma, vmaddr);
271#endif
Aneesh Kumar K.Vf22dfc92016-07-13 15:06:41 +0530272 radix__flush_tlb_page_psize(vma ? vma->vm_mm : NULL, vmaddr,
Aneesh Kumar K.Vfbfa26d2016-07-13 15:06:42 +0530273 mmu_virtual_psize);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000274}
275EXPORT_SYMBOL(radix__flush_tlb_page);
276
277#endif /* CONFIG_SMP */
278
279void radix__flush_tlb_kernel_range(unsigned long start, unsigned long end)
280{
281 int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE);
282
283 if (lock_tlbie)
284 raw_spin_lock(&native_tlbie_lock);
Aneesh Kumar K.V36194812016-06-08 19:55:50 +0530285 _tlbie_pid(0, RIC_FLUSH_ALL);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000286 if (lock_tlbie)
287 raw_spin_unlock(&native_tlbie_lock);
288}
289EXPORT_SYMBOL(radix__flush_tlb_kernel_range);
290
291/*
292 * Currently, for range flushing, we just do a full mm flush. Because
293 * we use this in code path where we don' track the page size.
294 */
295void radix__flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
296 unsigned long end)
297
298{
299 struct mm_struct *mm = vma->vm_mm;
300 radix__flush_tlb_mm(mm);
301}
302EXPORT_SYMBOL(radix__flush_tlb_range);
303
Aneesh Kumar K.V912cc872016-07-13 15:05:29 +0530304static int radix_get_mmu_psize(int page_size)
305{
306 int psize;
307
308 if (page_size == (1UL << mmu_psize_defs[mmu_virtual_psize].shift))
309 psize = mmu_virtual_psize;
310 else if (page_size == (1UL << mmu_psize_defs[MMU_PAGE_2M].shift))
311 psize = MMU_PAGE_2M;
312 else if (page_size == (1UL << mmu_psize_defs[MMU_PAGE_1G].shift))
313 psize = MMU_PAGE_1G;
314 else
315 return -1;
316 return psize;
317}
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000318
319void radix__tlb_flush(struct mmu_gather *tlb)
320{
Aneesh Kumar K.V8cb81402016-07-13 15:06:35 +0530321 int psize = 0;
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000322 struct mm_struct *mm = tlb->mm;
Aneesh Kumar K.V8cb81402016-07-13 15:06:35 +0530323 int page_size = tlb->page_size;
324
325 psize = radix_get_mmu_psize(page_size);
326 /*
327 * if page size is not something we understand, do a full mm flush
328 */
329 if (psize != -1 && !tlb->fullmm && !tlb->need_flush_all)
330 radix__flush_tlb_range_psize(mm, tlb->start, tlb->end, psize);
331 else
332 radix__flush_tlb_mm(mm);
333}
334
335#define TLB_FLUSH_ALL -1UL
336/*
337 * Number of pages above which we will do a bcast tlbie. Just a
338 * number at this point copied from x86
339 */
340static unsigned long tlb_single_page_flush_ceiling __read_mostly = 33;
341
342void radix__flush_tlb_range_psize(struct mm_struct *mm, unsigned long start,
343 unsigned long end, int psize)
344{
345 unsigned long pid;
346 unsigned long addr;
Aneesh Kumar K.Vbd77c442016-10-24 08:50:43 +0530347 int local = mm_is_thread_local(mm);
Aneesh Kumar K.V8cb81402016-07-13 15:06:35 +0530348 unsigned long ap = mmu_get_ap(psize);
349 int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE);
350 unsigned long page_size = 1UL << mmu_psize_defs[psize].shift;
351
352
353 preempt_disable();
354 pid = mm ? mm->context.id : 0;
355 if (unlikely(pid == MMU_NO_CONTEXT))
356 goto err_out;
357
358 if (end == TLB_FLUSH_ALL ||
359 (end - start) > tlb_single_page_flush_ceiling * page_size) {
360 if (local)
361 _tlbiel_pid(pid, RIC_FLUSH_TLB);
362 else
363 _tlbie_pid(pid, RIC_FLUSH_TLB);
364 goto err_out;
365 }
366 for (addr = start; addr < end; addr += page_size) {
367
368 if (local)
369 _tlbiel_va(addr, pid, ap, RIC_FLUSH_TLB);
370 else {
371 if (lock_tlbie)
372 raw_spin_lock(&native_tlbie_lock);
373 _tlbie_va(addr, pid, ap, RIC_FLUSH_TLB);
374 if (lock_tlbie)
375 raw_spin_unlock(&native_tlbie_lock);
376 }
377 }
378err_out:
379 preempt_enable();
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000380}
Aneesh Kumar K.V912cc872016-07-13 15:05:29 +0530381
382void radix__flush_tlb_lpid_va(unsigned long lpid, unsigned long gpa,
383 unsigned long page_size)
384{
385 unsigned long rb,rs,prs,r;
386 unsigned long ap;
387 unsigned long ric = RIC_FLUSH_TLB;
388
389 ap = mmu_get_ap(radix_get_mmu_psize(page_size));
390 rb = gpa & ~(PPC_BITMASK(52, 63));
391 rb |= ap << PPC_BITLSHIFT(58);
392 rs = lpid & ((1UL << 32) - 1);
393 prs = 0; /* process scoped */
394 r = 1; /* raidx format */
395
396 asm volatile("ptesync": : :"memory");
397 asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1)
398 : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(rs) : "memory");
399 asm volatile("eieio; tlbsync; ptesync": : :"memory");
400}
401EXPORT_SYMBOL(radix__flush_tlb_lpid_va);
402
403void radix__flush_tlb_lpid(unsigned long lpid)
404{
405 unsigned long rb,rs,prs,r;
406 unsigned long ric = RIC_FLUSH_ALL;
407
408 rb = 0x2 << PPC_BITLSHIFT(53); /* IS = 2 */
409 rs = lpid & ((1UL << 32) - 1);
410 prs = 0; /* partition scoped */
411 r = 1; /* raidx format */
412
413 asm volatile("ptesync": : :"memory");
414 asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1)
415 : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(rs) : "memory");
416 asm volatile("eieio; tlbsync; ptesync": : :"memory");
417}
418EXPORT_SYMBOL(radix__flush_tlb_lpid);
Aneesh Kumar K.Vd8e91e92016-07-13 15:06:40 +0530419
420void radix__flush_pmd_tlb_range(struct vm_area_struct *vma,
421 unsigned long start, unsigned long end)
422{
423 radix__flush_tlb_range_psize(vma->vm_mm, start, end, MMU_PAGE_2M);
424}
425EXPORT_SYMBOL(radix__flush_pmd_tlb_range);
Aneesh Kumar K.Vbe34d302016-08-23 16:27:48 +0530426
427void radix__flush_tlb_all(void)
428{
429 unsigned long rb,prs,r,rs;
430 unsigned long ric = RIC_FLUSH_ALL;
431
432 rb = 0x3 << PPC_BITLSHIFT(53); /* IS = 3 */
433 prs = 0; /* partition scoped */
434 r = 1; /* raidx format */
435 rs = 1 & ((1UL << 32) - 1); /* any LPID value to flush guest mappings */
436
437 asm volatile("ptesync": : :"memory");
438 /*
439 * now flush guest entries by passing PRS = 1 and LPID != 0
440 */
441 asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1)
442 : : "r"(rb), "i"(r), "i"(1), "i"(ric), "r"(rs) : "memory");
443 /*
444 * now flush host entires by passing PRS = 0 and LPID == 0
445 */
446 asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1)
447 : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(0) : "memory");
448 asm volatile("eieio; tlbsync; ptesync": : :"memory");
449}
Aneesh Kumar K.V6d3a0372016-11-28 11:47:01 +0530450
451void radix__flush_tlb_pte_p9_dd1(unsigned long old_pte, struct mm_struct *mm,
452 unsigned long address)
453{
454 /*
455 * We track page size in pte only for DD1, So we can
456 * call this only on DD1.
457 */
458 if (!cpu_has_feature(CPU_FTR_POWER9_DD1)) {
459 VM_WARN_ON(1);
460 return;
461 }
462
Aneesh Kumar K.Vddb014b2017-03-21 22:59:54 +0530463 if (old_pte & R_PAGE_LARGE)
Aneesh Kumar K.V6d3a0372016-11-28 11:47:01 +0530464 radix__flush_tlb_page_psize(mm, address, MMU_PAGE_2M);
465 else
466 radix__flush_tlb_page_psize(mm, address, mmu_virtual_psize);
467}