2012-03-05 18:49:28 +07:00
|
|
|
/*
|
|
|
|
* Based on arch/arm/include/asm/tlbflush.h
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999-2003 Russell King
|
|
|
|
* Copyright (C) 2012 ARM Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#ifndef __ASM_TLBFLUSH_H
|
|
|
|
#define __ASM_TLBFLUSH_H
|
|
|
|
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <asm/cputype.h>
|
2017-08-10 20:13:33 +07:00
|
|
|
#include <asm/mmu.h>
|
2012-03-05 18:49:28 +07:00
|
|
|
|
2016-09-13 17:16:06 +07:00
|
|
|
/*
|
|
|
|
* Raw TLBI operations.
|
|
|
|
*
|
|
|
|
* Where necessary, use the __tlbi() macro to avoid asm()
|
|
|
|
* boilerplate. Drivers and most kernel code should use the TLB
|
|
|
|
* management routines in preference to the macro below.
|
|
|
|
*
|
|
|
|
* The macro can be used as __tlbi(op) or __tlbi(op, arg), depending
|
|
|
|
* on whether a particular TLBI operation takes an argument or
|
|
|
|
* not. The macros handles invoking the asm with or without the
|
|
|
|
* register argument as appropriate.
|
|
|
|
*/
|
2017-02-01 00:50:19 +07:00
|
|
|
#define __TLBI_0(op, arg) asm ("tlbi " #op "\n" \
|
|
|
|
ALTERNATIVE("nop\n nop", \
|
|
|
|
"dsb ish\n tlbi " #op, \
|
|
|
|
ARM64_WORKAROUND_REPEAT_TLBI, \
|
|
|
|
CONFIG_QCOM_FALKOR_ERRATUM_1009) \
|
|
|
|
: : )
|
|
|
|
|
|
|
|
#define __TLBI_1(op, arg) asm ("tlbi " #op ", %0\n" \
|
|
|
|
ALTERNATIVE("nop\n nop", \
|
|
|
|
"dsb ish\n tlbi " #op ", %0", \
|
|
|
|
ARM64_WORKAROUND_REPEAT_TLBI, \
|
|
|
|
CONFIG_QCOM_FALKOR_ERRATUM_1009) \
|
|
|
|
: : "r" (arg))
|
|
|
|
|
|
|
|
#define __TLBI_N(op, arg, n, ...) __TLBI_##n(op, arg)
|
2016-09-13 17:16:06 +07:00
|
|
|
|
|
|
|
#define __tlbi(op, ...) __TLBI_N(op, ##__VA_ARGS__, 1, 0)
|
|
|
|
|
2017-08-10 20:13:33 +07:00
|
|
|
#define __tlbi_user(op, arg) do { \
|
|
|
|
if (arm64_kernel_unmapped_at_el0()) \
|
|
|
|
__tlbi(op, (arg) | USER_ASID_FLAG); \
|
|
|
|
} while (0)
|
|
|
|
|
2018-03-28 08:55:32 +07:00
|
|
|
/* This macro creates a properly formatted VA operand for the TLBI */
|
|
|
|
#define __TLBI_VADDR(addr, asid) \
|
|
|
|
({ \
|
|
|
|
unsigned long __ta = (addr) >> 12; \
|
|
|
|
__ta &= GENMASK_ULL(43, 0); \
|
|
|
|
__ta |= (unsigned long)(asid) << 48; \
|
|
|
|
__ta; \
|
|
|
|
})
|
|
|
|
|
2012-03-05 18:49:28 +07:00
|
|
|
/*
|
|
|
|
* TLB Management
|
|
|
|
* ==============
|
|
|
|
*
|
|
|
|
* The TLB specific code is expected to perform whatever tests it needs
|
|
|
|
* to determine if it should invalidate the TLB for each call. Start
|
|
|
|
* addresses are inclusive and end addresses are exclusive; it is safe to
|
|
|
|
* round these addresses down.
|
|
|
|
*
|
|
|
|
* flush_tlb_all()
|
|
|
|
*
|
|
|
|
* Invalidate the entire TLB.
|
|
|
|
*
|
|
|
|
* flush_tlb_mm(mm)
|
|
|
|
*
|
|
|
|
* Invalidate all TLB entries in a particular address space.
|
|
|
|
* - mm - mm_struct describing address space
|
|
|
|
*
|
|
|
|
* flush_tlb_range(mm,start,end)
|
|
|
|
*
|
|
|
|
* Invalidate a range of TLB entries in the specified address
|
|
|
|
* space.
|
|
|
|
* - mm - mm_struct describing address space
|
|
|
|
* - start - start address (may not be aligned)
|
|
|
|
* - end - end address (exclusive, may not be aligned)
|
|
|
|
*
|
|
|
|
* flush_tlb_page(vaddr,vma)
|
|
|
|
*
|
|
|
|
* Invalidate the specified page in the specified address range.
|
|
|
|
* - vaddr - virtual address (may not be aligned)
|
|
|
|
* - vma - vma_struct describing address range
|
|
|
|
*
|
|
|
|
* flush_kern_tlb_page(kaddr)
|
|
|
|
*
|
|
|
|
* Invalidate the TLB entry for the specified page. The address
|
|
|
|
* will be in the kernels virtual memory space. Current uses
|
|
|
|
* only require the D-TLB to be invalidated.
|
|
|
|
* - kaddr - Kernel virtual memory address
|
|
|
|
*/
|
2015-10-07 00:46:23 +07:00
|
|
|
static inline void local_flush_tlb_all(void)
|
|
|
|
{
|
|
|
|
dsb(nshst);
|
2016-09-13 17:16:06 +07:00
|
|
|
__tlbi(vmalle1);
|
2015-10-07 00:46:23 +07:00
|
|
|
dsb(nsh);
|
|
|
|
isb();
|
|
|
|
}
|
|
|
|
|
2012-03-05 18:49:28 +07:00
|
|
|
static inline void flush_tlb_all(void)
|
|
|
|
{
|
2014-05-02 22:24:10 +07:00
|
|
|
dsb(ishst);
|
2016-09-13 17:16:06 +07:00
|
|
|
__tlbi(vmalle1is);
|
2014-05-02 22:24:10 +07:00
|
|
|
dsb(ish);
|
2012-03-05 18:49:28 +07:00
|
|
|
isb();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void flush_tlb_mm(struct mm_struct *mm)
|
|
|
|
{
|
2018-03-28 08:55:32 +07:00
|
|
|
unsigned long asid = __TLBI_VADDR(0, ASID(mm));
|
2012-03-05 18:49:28 +07:00
|
|
|
|
2014-05-02 22:24:10 +07:00
|
|
|
dsb(ishst);
|
2016-09-13 17:16:06 +07:00
|
|
|
__tlbi(aside1is, asid);
|
2017-08-10 20:13:33 +07:00
|
|
|
__tlbi_user(aside1is, asid);
|
2014-05-02 22:24:10 +07:00
|
|
|
dsb(ish);
|
2012-03-05 18:49:28 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void flush_tlb_page(struct vm_area_struct *vma,
|
|
|
|
unsigned long uaddr)
|
|
|
|
{
|
2018-03-28 08:55:32 +07:00
|
|
|
unsigned long addr = __TLBI_VADDR(uaddr, ASID(vma->vm_mm));
|
2012-03-05 18:49:28 +07:00
|
|
|
|
2014-05-02 22:24:10 +07:00
|
|
|
dsb(ishst);
|
2016-09-13 17:16:06 +07:00
|
|
|
__tlbi(vale1is, addr);
|
2017-08-10 20:13:33 +07:00
|
|
|
__tlbi_user(vale1is, addr);
|
2014-05-02 22:24:10 +07:00
|
|
|
dsb(ish);
|
2012-03-05 18:49:28 +07:00
|
|
|
}
|
|
|
|
|
2015-07-24 15:59:55 +07:00
|
|
|
/*
|
|
|
|
* This is meant to avoid soft lock-ups on large TLB flushing ranges and not
|
|
|
|
* necessarily a performance improvement.
|
|
|
|
*/
|
|
|
|
#define MAX_TLB_RANGE (1024UL << PAGE_SHIFT)
|
|
|
|
|
2015-03-18 18:28:06 +07:00
|
|
|
static inline void __flush_tlb_range(struct vm_area_struct *vma,
|
|
|
|
unsigned long start, unsigned long end,
|
|
|
|
bool last_level)
|
2014-05-02 20:49:00 +07:00
|
|
|
{
|
2018-03-28 08:55:32 +07:00
|
|
|
unsigned long asid = ASID(vma->vm_mm);
|
2014-05-02 20:49:00 +07:00
|
|
|
unsigned long addr;
|
2015-07-24 15:59:55 +07:00
|
|
|
|
|
|
|
if ((end - start) > MAX_TLB_RANGE) {
|
|
|
|
flush_tlb_mm(vma->vm_mm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-28 08:55:32 +07:00
|
|
|
start = __TLBI_VADDR(start, asid);
|
|
|
|
end = __TLBI_VADDR(end, asid);
|
2014-05-02 20:49:00 +07:00
|
|
|
|
|
|
|
dsb(ishst);
|
2015-03-18 18:28:06 +07:00
|
|
|
for (addr = start; addr < end; addr += 1 << (PAGE_SHIFT - 12)) {
|
2017-08-10 20:13:33 +07:00
|
|
|
if (last_level) {
|
2016-09-13 17:16:06 +07:00
|
|
|
__tlbi(vale1is, addr);
|
2017-08-10 20:13:33 +07:00
|
|
|
__tlbi_user(vale1is, addr);
|
|
|
|
} else {
|
2016-09-13 17:16:06 +07:00
|
|
|
__tlbi(vae1is, addr);
|
2017-08-10 20:13:33 +07:00
|
|
|
__tlbi_user(vae1is, addr);
|
|
|
|
}
|
2015-03-18 18:28:06 +07:00
|
|
|
}
|
2014-05-02 20:49:00 +07:00
|
|
|
dsb(ish);
|
|
|
|
}
|
|
|
|
|
2015-03-18 18:28:06 +07:00
|
|
|
static inline void flush_tlb_range(struct vm_area_struct *vma,
|
|
|
|
unsigned long start, unsigned long end)
|
|
|
|
{
|
|
|
|
__flush_tlb_range(vma, start, end, false);
|
|
|
|
}
|
|
|
|
|
2015-07-24 15:59:55 +07:00
|
|
|
static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end)
|
2014-05-02 20:49:00 +07:00
|
|
|
{
|
|
|
|
unsigned long addr;
|
2015-07-24 15:59:55 +07:00
|
|
|
|
|
|
|
if ((end - start) > MAX_TLB_RANGE) {
|
|
|
|
flush_tlb_all();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-28 08:55:32 +07:00
|
|
|
start = __TLBI_VADDR(start, 0);
|
|
|
|
end = __TLBI_VADDR(end, 0);
|
2014-05-02 20:49:00 +07:00
|
|
|
|
|
|
|
dsb(ishst);
|
|
|
|
for (addr = start; addr < end; addr += 1 << (PAGE_SHIFT - 12))
|
2016-09-13 17:16:06 +07:00
|
|
|
__tlbi(vaae1is, addr);
|
2014-05-02 20:49:00 +07:00
|
|
|
dsb(ish);
|
2014-06-09 17:55:03 +07:00
|
|
|
isb();
|
2014-05-02 20:49:00 +07:00
|
|
|
}
|
2012-03-05 18:49:28 +07:00
|
|
|
|
2015-03-11 19:20:39 +07:00
|
|
|
/*
|
|
|
|
* Used to invalidate the TLB (walk caches) corresponding to intermediate page
|
|
|
|
* table levels (pgd/pud/pmd).
|
|
|
|
*/
|
|
|
|
static inline void __flush_tlb_pgtable(struct mm_struct *mm,
|
|
|
|
unsigned long uaddr)
|
|
|
|
{
|
2018-03-28 08:55:32 +07:00
|
|
|
unsigned long addr = __TLBI_VADDR(uaddr, ASID(mm));
|
2015-03-11 19:20:39 +07:00
|
|
|
|
2016-09-13 17:16:06 +07:00
|
|
|
__tlbi(vae1is, addr);
|
2017-08-10 20:13:33 +07:00
|
|
|
__tlbi_user(vae1is, addr);
|
2015-03-11 19:20:39 +07:00
|
|
|
dsb(ish);
|
|
|
|
}
|
2013-04-19 22:23:57 +07:00
|
|
|
|
2012-03-05 18:49:28 +07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|