blob: 18151e9ad694625179fae9161024600e9bc53a7b [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>
Balbir Singh04284912017-04-11 15:23:25 +100019#include <asm/trace.h>
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100020
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100021
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");
Balbir Singh04284912017-04-11 15:23:25 +100039 trace_tlbie(0, 1, rb, rs, ric, prs, r);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100040}
41
42/*
43 * We use 128 set in radix mode and 256 set in hpt mode.
44 */
Aneesh Kumar K.V36194812016-06-08 19:55:50 +053045static inline void _tlbiel_pid(unsigned long pid, unsigned long ric)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100046{
47 int set;
48
Aneesh Kumar K.Vf7327e02017-04-01 20:11:48 +053049 asm volatile("ptesync": : :"memory");
Aneesh Kumar K.Va5998fc2017-04-26 21:38:17 +100050
51 /*
52 * Flush the first set of the TLB, and if we're doing a RIC_FLUSH_ALL,
53 * also flush the entire Page Walk Cache.
54 */
55 __tlbiel_pid(pid, 0, ric);
56
Benjamin Herrenschmidt5ce5fe12017-07-19 14:49:04 +100057 /* For PWC, only one flush is needed */
58 if (ric == RIC_FLUSH_PWC) {
59 asm volatile("ptesync": : :"memory");
60 return;
61 }
Aneesh Kumar K.Va5998fc2017-04-26 21:38:17 +100062
Benjamin Herrenschmidt5ce5fe12017-07-19 14:49:04 +100063 /* For the remaining sets, just flush the TLB */
Aneesh Kumar K.Va5998fc2017-04-26 21:38:17 +100064 for (set = 1; set < POWER9_TLB_SETS_RADIX ; set++)
Benjamin Herrenschmidt5ce5fe12017-07-19 14:49:04 +100065 __tlbiel_pid(pid, set, RIC_FLUSH_TLB);
Aneesh Kumar K.Va5998fc2017-04-26 21:38:17 +100066
Aneesh Kumar K.Vf7327e02017-04-01 20:11:48 +053067 asm volatile("ptesync": : :"memory");
Benjamin Herrenschmidt90c1e3c2017-02-06 13:05:16 +110068 asm volatile(PPC_INVALIDATE_ERAT "; isync" : : :"memory");
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100069}
70
Aneesh Kumar K.V36194812016-06-08 19:55:50 +053071static inline void _tlbie_pid(unsigned long pid, unsigned long ric)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100072{
Aneesh Kumar K.V36194812016-06-08 19:55:50 +053073 unsigned long rb,rs,prs,r;
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100074
75 rb = PPC_BIT(53); /* IS = 1 */
76 rs = pid << PPC_BITLSHIFT(31);
77 prs = 1; /* process scoped */
78 r = 1; /* raidx format */
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100079
80 asm volatile("ptesync": : :"memory");
Balbir Singh8cd6d3c2016-07-13 15:05:20 +053081 asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100082 : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(rs) : "memory");
83 asm volatile("eieio; tlbsync; ptesync": : :"memory");
Balbir Singh04284912017-04-11 15:23:25 +100084 trace_tlbie(0, 0, rb, rs, ric, prs, r);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100085}
86
87static inline void _tlbiel_va(unsigned long va, unsigned long pid,
Aneesh Kumar K.V36194812016-06-08 19:55:50 +053088 unsigned long ap, unsigned long ric)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100089{
Aneesh Kumar K.V36194812016-06-08 19:55:50 +053090 unsigned long rb,rs,prs,r;
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100091
92 rb = va & ~(PPC_BITMASK(52, 63));
93 rb |= ap << PPC_BITLSHIFT(58);
94 rs = pid << PPC_BITLSHIFT(31);
95 prs = 1; /* process scoped */
96 r = 1; /* raidx format */
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +100097
98 asm volatile("ptesync": : :"memory");
Balbir Singh8cd6d3c2016-07-13 15:05:20 +053099 asm volatile(PPC_TLBIEL(%0, %4, %3, %2, %1)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000100 : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(rs) : "memory");
101 asm volatile("ptesync": : :"memory");
Balbir Singh04284912017-04-11 15:23:25 +1000102 trace_tlbie(0, 1, rb, rs, ric, prs, r);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000103}
104
105static inline void _tlbie_va(unsigned long va, unsigned long pid,
Aneesh Kumar K.V36194812016-06-08 19:55:50 +0530106 unsigned long ap, unsigned long ric)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000107{
Aneesh Kumar K.V36194812016-06-08 19:55:50 +0530108 unsigned long rb,rs,prs,r;
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000109
110 rb = va & ~(PPC_BITMASK(52, 63));
111 rb |= ap << PPC_BITLSHIFT(58);
112 rs = pid << PPC_BITLSHIFT(31);
113 prs = 1; /* process scoped */
114 r = 1; /* raidx format */
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000115
116 asm volatile("ptesync": : :"memory");
Balbir Singh8cd6d3c2016-07-13 15:05:20 +0530117 asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000118 : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(rs) : "memory");
119 asm volatile("eieio; tlbsync; ptesync": : :"memory");
Balbir Singh04284912017-04-11 15:23:25 +1000120 trace_tlbie(0, 0, rb, rs, ric, prs, r);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000121}
122
123/*
124 * Base TLB flushing operations:
125 *
126 * - flush_tlb_mm(mm) flushes the specified mm context TLB's
127 * - flush_tlb_page(vma, vmaddr) flushes one page
128 * - flush_tlb_range(vma, start, end) flushes a range of pages
129 * - flush_tlb_kernel_range(start, end) flushes kernel pages
130 *
131 * - local_* variants of page and mm only apply to the current
132 * processor
133 */
134void radix__local_flush_tlb_mm(struct mm_struct *mm)
135{
Aneesh Kumar K.V9690c152016-06-02 15:14:48 +0530136 unsigned long pid;
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000137
138 preempt_disable();
139 pid = mm->context.id;
140 if (pid != MMU_NO_CONTEXT)
Benjamin Herrenschmidta46cc7a2017-07-19 14:49:05 +1000141 _tlbiel_pid(pid, RIC_FLUSH_TLB);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000142 preempt_enable();
143}
144EXPORT_SYMBOL(radix__local_flush_tlb_mm);
145
Benjamin Herrenschmidta46cc7a2017-07-19 14:49:05 +1000146#ifndef CONFIG_SMP
147static void radix__local_flush_all_mm(struct mm_struct *mm)
Aneesh Kumar K.Va145abf2016-06-08 19:55:51 +0530148{
149 unsigned long pid;
Aneesh Kumar K.Va145abf2016-06-08 19:55:51 +0530150
151 preempt_disable();
Aneesh Kumar K.Va145abf2016-06-08 19:55:51 +0530152 pid = mm->context.id;
153 if (pid != MMU_NO_CONTEXT)
Benjamin Herrenschmidta46cc7a2017-07-19 14:49:05 +1000154 _tlbiel_pid(pid, RIC_FLUSH_ALL);
Aneesh Kumar K.Va145abf2016-06-08 19:55:51 +0530155 preempt_enable();
156}
Benjamin Herrenschmidta46cc7a2017-07-19 14:49:05 +1000157#endif /* CONFIG_SMP */
Aneesh Kumar K.Va145abf2016-06-08 19:55:51 +0530158
Aneesh Kumar K.Vf22dfc92016-07-13 15:06:41 +0530159void radix__local_flush_tlb_page_psize(struct mm_struct *mm, unsigned long vmaddr,
Aneesh Kumar K.Vfbfa26d2016-07-13 15:06:42 +0530160 int psize)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000161{
Aneesh Kumar K.V9690c152016-06-02 15:14:48 +0530162 unsigned long pid;
Aneesh Kumar K.Vfbfa26d2016-07-13 15:06:42 +0530163 unsigned long ap = mmu_get_ap(psize);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000164
165 preempt_disable();
166 pid = mm ? mm->context.id : 0;
167 if (pid != MMU_NO_CONTEXT)
Aneesh Kumar K.V36194812016-06-08 19:55:50 +0530168 _tlbiel_va(vmaddr, pid, ap, RIC_FLUSH_TLB);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000169 preempt_enable();
170}
171
172void radix__local_flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
173{
Aneesh Kumar K.V48483762016-04-29 23:26:25 +1000174#ifdef CONFIG_HUGETLB_PAGE
175 /* need the return fix for nohash.c */
176 if (vma && is_vm_hugetlb_page(vma))
177 return __local_flush_hugetlb_page(vma, vmaddr);
178#endif
Aneesh Kumar K.Vf22dfc92016-07-13 15:06:41 +0530179 radix__local_flush_tlb_page_psize(vma ? vma->vm_mm : NULL, vmaddr,
Aneesh Kumar K.Vfbfa26d2016-07-13 15:06:42 +0530180 mmu_virtual_psize);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000181}
182EXPORT_SYMBOL(radix__local_flush_tlb_page);
183
184#ifdef CONFIG_SMP
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000185void radix__flush_tlb_mm(struct mm_struct *mm)
186{
Aneesh Kumar K.V9690c152016-06-02 15:14:48 +0530187 unsigned long pid;
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000188
189 preempt_disable();
190 pid = mm->context.id;
191 if (unlikely(pid == MMU_NO_CONTEXT))
192 goto no_context;
193
Michael Ellerman3c9ac2b2017-05-02 21:00:14 +1000194 if (!mm_is_thread_local(mm))
Benjamin Herrenschmidta46cc7a2017-07-19 14:49:05 +1000195 _tlbie_pid(pid, RIC_FLUSH_TLB);
196 else
197 _tlbiel_pid(pid, RIC_FLUSH_TLB);
198no_context:
199 preempt_enable();
200}
201EXPORT_SYMBOL(radix__flush_tlb_mm);
202
203static void radix__flush_all_mm(struct mm_struct *mm)
204{
205 unsigned long pid;
206
207 preempt_disable();
208 pid = mm->context.id;
209 if (unlikely(pid == MMU_NO_CONTEXT))
210 goto no_context;
211
212 if (!mm_is_thread_local(mm))
Aneesh Kumar K.V36194812016-06-08 19:55:50 +0530213 _tlbie_pid(pid, RIC_FLUSH_ALL);
Michael Ellerman3c9ac2b2017-05-02 21:00:14 +1000214 else
Aneesh Kumar K.V36194812016-06-08 19:55:50 +0530215 _tlbiel_pid(pid, RIC_FLUSH_ALL);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000216no_context:
217 preempt_enable();
218}
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000219
Aneesh Kumar K.Va145abf2016-06-08 19:55:51 +0530220void radix__flush_tlb_pwc(struct mmu_gather *tlb, unsigned long addr)
221{
Benjamin Herrenschmidta46cc7a2017-07-19 14:49:05 +1000222 tlb->need_flush_all = 1;
Aneesh Kumar K.Va145abf2016-06-08 19:55:51 +0530223}
224EXPORT_SYMBOL(radix__flush_tlb_pwc);
225
Aneesh Kumar K.Vf22dfc92016-07-13 15:06:41 +0530226void radix__flush_tlb_page_psize(struct mm_struct *mm, unsigned long vmaddr,
Aneesh Kumar K.Vfbfa26d2016-07-13 15:06:42 +0530227 int psize)
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000228{
Aneesh Kumar K.V9690c152016-06-02 15:14:48 +0530229 unsigned long pid;
Aneesh Kumar K.Vfbfa26d2016-07-13 15:06:42 +0530230 unsigned long ap = mmu_get_ap(psize);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000231
232 preempt_disable();
233 pid = mm ? mm->context.id : 0;
234 if (unlikely(pid == MMU_NO_CONTEXT))
235 goto bail;
Michael Ellerman3c9ac2b2017-05-02 21:00:14 +1000236 if (!mm_is_thread_local(mm))
Aneesh Kumar K.V36194812016-06-08 19:55:50 +0530237 _tlbie_va(vmaddr, pid, ap, RIC_FLUSH_TLB);
Michael Ellerman3c9ac2b2017-05-02 21:00:14 +1000238 else
Aneesh Kumar K.V36194812016-06-08 19:55:50 +0530239 _tlbiel_va(vmaddr, pid, ap, RIC_FLUSH_TLB);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000240bail:
241 preempt_enable();
242}
243
244void radix__flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
245{
Aneesh Kumar K.V48483762016-04-29 23:26:25 +1000246#ifdef CONFIG_HUGETLB_PAGE
247 if (vma && is_vm_hugetlb_page(vma))
248 return flush_hugetlb_page(vma, vmaddr);
249#endif
Aneesh Kumar K.Vf22dfc92016-07-13 15:06:41 +0530250 radix__flush_tlb_page_psize(vma ? vma->vm_mm : NULL, vmaddr,
Aneesh Kumar K.Vfbfa26d2016-07-13 15:06:42 +0530251 mmu_virtual_psize);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000252}
253EXPORT_SYMBOL(radix__flush_tlb_page);
254
Benjamin Herrenschmidta46cc7a2017-07-19 14:49:05 +1000255#else /* CONFIG_SMP */
256#define radix__flush_all_mm radix__local_flush_all_mm
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000257#endif /* CONFIG_SMP */
258
259void radix__flush_tlb_kernel_range(unsigned long start, unsigned long end)
260{
Aneesh Kumar K.V36194812016-06-08 19:55:50 +0530261 _tlbie_pid(0, RIC_FLUSH_ALL);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000262}
263EXPORT_SYMBOL(radix__flush_tlb_kernel_range);
264
265/*
266 * Currently, for range flushing, we just do a full mm flush. Because
267 * we use this in code path where we don' track the page size.
268 */
269void radix__flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
270 unsigned long end)
271
272{
273 struct mm_struct *mm = vma->vm_mm;
Benjamin Herrenschmidta46cc7a2017-07-19 14:49:05 +1000274
Benjamin Herrenschmidt424de9c2017-07-19 14:49:06 +1000275 radix__flush_tlb_mm(mm);
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000276}
277EXPORT_SYMBOL(radix__flush_tlb_range);
278
Aneesh Kumar K.V912cc872016-07-13 15:05:29 +0530279static int radix_get_mmu_psize(int page_size)
280{
281 int psize;
282
283 if (page_size == (1UL << mmu_psize_defs[mmu_virtual_psize].shift))
284 psize = mmu_virtual_psize;
285 else if (page_size == (1UL << mmu_psize_defs[MMU_PAGE_2M].shift))
286 psize = MMU_PAGE_2M;
287 else if (page_size == (1UL << mmu_psize_defs[MMU_PAGE_1G].shift))
288 psize = MMU_PAGE_1G;
289 else
290 return -1;
291 return psize;
292}
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000293
294void radix__tlb_flush(struct mmu_gather *tlb)
295{
Aneesh Kumar K.V8cb81402016-07-13 15:06:35 +0530296 int psize = 0;
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000297 struct mm_struct *mm = tlb->mm;
Aneesh Kumar K.V8cb81402016-07-13 15:06:35 +0530298 int page_size = tlb->page_size;
299
300 psize = radix_get_mmu_psize(page_size);
301 /*
302 * if page size is not something we understand, do a full mm flush
303 */
304 if (psize != -1 && !tlb->fullmm && !tlb->need_flush_all)
305 radix__flush_tlb_range_psize(mm, tlb->start, tlb->end, psize);
Benjamin Herrenschmidta46cc7a2017-07-19 14:49:05 +1000306 else if (tlb->need_flush_all) {
307 tlb->need_flush_all = 0;
308 radix__flush_all_mm(mm);
309 } else
Aneesh Kumar K.V8cb81402016-07-13 15:06:35 +0530310 radix__flush_tlb_mm(mm);
311}
312
313#define TLB_FLUSH_ALL -1UL
314/*
315 * Number of pages above which we will do a bcast tlbie. Just a
316 * number at this point copied from x86
317 */
318static unsigned long tlb_single_page_flush_ceiling __read_mostly = 33;
319
320void radix__flush_tlb_range_psize(struct mm_struct *mm, unsigned long start,
321 unsigned long end, int psize)
322{
323 unsigned long pid;
324 unsigned long addr;
Aneesh Kumar K.Vbd77c442016-10-24 08:50:43 +0530325 int local = mm_is_thread_local(mm);
Aneesh Kumar K.V8cb81402016-07-13 15:06:35 +0530326 unsigned long ap = mmu_get_ap(psize);
Aneesh Kumar K.V8cb81402016-07-13 15:06:35 +0530327 unsigned long page_size = 1UL << mmu_psize_defs[psize].shift;
328
329
330 preempt_disable();
331 pid = mm ? mm->context.id : 0;
332 if (unlikely(pid == MMU_NO_CONTEXT))
333 goto err_out;
334
335 if (end == TLB_FLUSH_ALL ||
336 (end - start) > tlb_single_page_flush_ceiling * page_size) {
337 if (local)
338 _tlbiel_pid(pid, RIC_FLUSH_TLB);
339 else
340 _tlbie_pid(pid, RIC_FLUSH_TLB);
341 goto err_out;
342 }
343 for (addr = start; addr < end; addr += page_size) {
344
345 if (local)
346 _tlbiel_va(addr, pid, ap, RIC_FLUSH_TLB);
Michael Ellerman3c9ac2b2017-05-02 21:00:14 +1000347 else
Aneesh Kumar K.V8cb81402016-07-13 15:06:35 +0530348 _tlbie_va(addr, pid, ap, RIC_FLUSH_TLB);
Aneesh Kumar K.V8cb81402016-07-13 15:06:35 +0530349 }
350err_out:
351 preempt_enable();
Aneesh Kumar K.V1a472c92016-04-29 23:26:05 +1000352}
Aneesh Kumar K.V912cc872016-07-13 15:05:29 +0530353
Benjamin Herrenschmidt424de9c2017-07-19 14:49:06 +1000354#ifdef CONFIG_TRANSPARENT_HUGEPAGE
355void radix__flush_tlb_collapsed_pmd(struct mm_struct *mm, unsigned long addr)
356{
357 int local = mm_is_thread_local(mm);
358 unsigned long ap = mmu_get_ap(mmu_virtual_psize);
359 unsigned long pid, end;
360
361
362 pid = mm ? mm->context.id : 0;
363 if (unlikely(pid == MMU_NO_CONTEXT))
364 goto no_context;
365
366 /* 4k page size, just blow the world */
367 if (PAGE_SIZE == 0x1000) {
368 radix__flush_all_mm(mm);
369 return;
370 }
371
372 /* Otherwise first do the PWC */
373 if (local)
374 _tlbiel_pid(pid, RIC_FLUSH_PWC);
375 else
376 _tlbie_pid(pid, RIC_FLUSH_PWC);
377
378 /* Then iterate the pages */
379 end = addr + HPAGE_PMD_SIZE;
380 for (; addr < end; addr += PAGE_SIZE) {
381 if (local)
382 _tlbiel_va(addr, pid, ap, RIC_FLUSH_TLB);
383 else
384 _tlbie_va(addr, pid, ap, RIC_FLUSH_TLB);
385 }
386no_context:
387 preempt_enable();
388}
389#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
390
Aneesh Kumar K.V912cc872016-07-13 15:05:29 +0530391void radix__flush_tlb_lpid_va(unsigned long lpid, unsigned long gpa,
392 unsigned long page_size)
393{
394 unsigned long rb,rs,prs,r;
395 unsigned long ap;
396 unsigned long ric = RIC_FLUSH_TLB;
397
398 ap = mmu_get_ap(radix_get_mmu_psize(page_size));
399 rb = gpa & ~(PPC_BITMASK(52, 63));
400 rb |= ap << PPC_BITLSHIFT(58);
401 rs = lpid & ((1UL << 32) - 1);
402 prs = 0; /* process scoped */
403 r = 1; /* raidx format */
404
405 asm volatile("ptesync": : :"memory");
406 asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1)
407 : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(rs) : "memory");
408 asm volatile("eieio; tlbsync; ptesync": : :"memory");
Balbir Singh04284912017-04-11 15:23:25 +1000409 trace_tlbie(lpid, 0, rb, rs, ric, prs, r);
Aneesh Kumar K.V912cc872016-07-13 15:05:29 +0530410}
411EXPORT_SYMBOL(radix__flush_tlb_lpid_va);
412
413void radix__flush_tlb_lpid(unsigned long lpid)
414{
415 unsigned long rb,rs,prs,r;
416 unsigned long ric = RIC_FLUSH_ALL;
417
418 rb = 0x2 << PPC_BITLSHIFT(53); /* IS = 2 */
419 rs = lpid & ((1UL << 32) - 1);
420 prs = 0; /* partition scoped */
421 r = 1; /* raidx format */
422
423 asm volatile("ptesync": : :"memory");
424 asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1)
425 : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(rs) : "memory");
426 asm volatile("eieio; tlbsync; ptesync": : :"memory");
Balbir Singh04284912017-04-11 15:23:25 +1000427 trace_tlbie(lpid, 0, rb, rs, ric, prs, r);
Aneesh Kumar K.V912cc872016-07-13 15:05:29 +0530428}
429EXPORT_SYMBOL(radix__flush_tlb_lpid);
Aneesh Kumar K.Vd8e91e92016-07-13 15:06:40 +0530430
431void radix__flush_pmd_tlb_range(struct vm_area_struct *vma,
432 unsigned long start, unsigned long end)
433{
434 radix__flush_tlb_range_psize(vma->vm_mm, start, end, MMU_PAGE_2M);
435}
436EXPORT_SYMBOL(radix__flush_pmd_tlb_range);
Aneesh Kumar K.Vbe34d302016-08-23 16:27:48 +0530437
438void radix__flush_tlb_all(void)
439{
440 unsigned long rb,prs,r,rs;
441 unsigned long ric = RIC_FLUSH_ALL;
442
443 rb = 0x3 << PPC_BITLSHIFT(53); /* IS = 3 */
444 prs = 0; /* partition scoped */
445 r = 1; /* raidx format */
446 rs = 1 & ((1UL << 32) - 1); /* any LPID value to flush guest mappings */
447
448 asm volatile("ptesync": : :"memory");
449 /*
450 * now flush guest entries by passing PRS = 1 and LPID != 0
451 */
452 asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1)
453 : : "r"(rb), "i"(r), "i"(1), "i"(ric), "r"(rs) : "memory");
Balbir Singh04284912017-04-11 15:23:25 +1000454 trace_tlbie(0, 0, rb, rs, ric, prs, r);
Aneesh Kumar K.Vbe34d302016-08-23 16:27:48 +0530455 /*
456 * now flush host entires by passing PRS = 0 and LPID == 0
457 */
458 asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1)
459 : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(0) : "memory");
460 asm volatile("eieio; tlbsync; ptesync": : :"memory");
Balbir Singh04284912017-04-11 15:23:25 +1000461 trace_tlbie(0, 0, rb, 0, ric, prs, r);
Aneesh Kumar K.Vbe34d302016-08-23 16:27:48 +0530462}
Aneesh Kumar K.V6d3a0372016-11-28 11:47:01 +0530463
464void radix__flush_tlb_pte_p9_dd1(unsigned long old_pte, struct mm_struct *mm,
465 unsigned long address)
466{
467 /*
468 * We track page size in pte only for DD1, So we can
469 * call this only on DD1.
470 */
471 if (!cpu_has_feature(CPU_FTR_POWER9_DD1)) {
472 VM_WARN_ON(1);
473 return;
474 }
475
Aneesh Kumar K.Vddb014b2017-03-21 22:59:54 +0530476 if (old_pte & R_PAGE_LARGE)
Aneesh Kumar K.V6d3a0372016-11-28 11:47:01 +0530477 radix__flush_tlb_page_psize(mm, address, MMU_PAGE_2M);
478 else
479 radix__flush_tlb_page_psize(mm, address, mmu_virtual_psize);
480}