Catalin Marinas | 58d0ba5 | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Based on arch/arm/include/asm/tlbflush.h |
| 3 | * |
| 4 | * Copyright (C) 1999-2003 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_TLBFLUSH_H |
| 20 | #define __ASM_TLBFLUSH_H |
| 21 | |
| 22 | #ifndef __ASSEMBLY__ |
| 23 | |
| 24 | #include <linux/sched.h> |
| 25 | #include <asm/cputype.h> |
| 26 | |
Catalin Marinas | 58d0ba5 | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 27 | /* |
| 28 | * TLB Management |
| 29 | * ============== |
| 30 | * |
| 31 | * The arch/arm64/mm/tlb.S files implement these methods. |
| 32 | * |
| 33 | * The TLB specific code is expected to perform whatever tests it needs |
| 34 | * to determine if it should invalidate the TLB for each call. Start |
| 35 | * addresses are inclusive and end addresses are exclusive; it is safe to |
| 36 | * round these addresses down. |
| 37 | * |
| 38 | * flush_tlb_all() |
| 39 | * |
| 40 | * Invalidate the entire TLB. |
| 41 | * |
| 42 | * flush_tlb_mm(mm) |
| 43 | * |
| 44 | * Invalidate all TLB entries in a particular address space. |
| 45 | * - mm - mm_struct describing address space |
| 46 | * |
| 47 | * flush_tlb_range(mm,start,end) |
| 48 | * |
| 49 | * Invalidate a range of TLB entries in the specified address |
| 50 | * space. |
| 51 | * - mm - mm_struct describing address space |
| 52 | * - start - start address (may not be aligned) |
| 53 | * - end - end address (exclusive, may not be aligned) |
| 54 | * |
| 55 | * flush_tlb_page(vaddr,vma) |
| 56 | * |
| 57 | * Invalidate the specified page in the specified address range. |
| 58 | * - vaddr - virtual address (may not be aligned) |
| 59 | * - vma - vma_struct describing address range |
| 60 | * |
| 61 | * flush_kern_tlb_page(kaddr) |
| 62 | * |
| 63 | * Invalidate the TLB entry for the specified page. The address |
| 64 | * will be in the kernels virtual memory space. Current uses |
| 65 | * only require the D-TLB to be invalidated. |
| 66 | * - kaddr - Kernel virtual memory address |
| 67 | */ |
| 68 | static inline void flush_tlb_all(void) |
| 69 | { |
Will Deacon | 98f7685 | 2014-05-02 16:24:10 +0100 | [diff] [blame] | 70 | dsb(ishst); |
Catalin Marinas | 58d0ba5 | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 71 | asm("tlbi vmalle1is"); |
Will Deacon | 98f7685 | 2014-05-02 16:24:10 +0100 | [diff] [blame] | 72 | dsb(ish); |
Catalin Marinas | 58d0ba5 | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 73 | isb(); |
| 74 | } |
| 75 | |
| 76 | static inline void flush_tlb_mm(struct mm_struct *mm) |
| 77 | { |
| 78 | unsigned long asid = (unsigned long)ASID(mm) << 48; |
| 79 | |
Will Deacon | 98f7685 | 2014-05-02 16:24:10 +0100 | [diff] [blame] | 80 | dsb(ishst); |
Catalin Marinas | 58d0ba5 | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 81 | asm("tlbi aside1is, %0" : : "r" (asid)); |
Will Deacon | 98f7685 | 2014-05-02 16:24:10 +0100 | [diff] [blame] | 82 | dsb(ish); |
Catalin Marinas | 58d0ba5 | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | static inline void flush_tlb_page(struct vm_area_struct *vma, |
| 86 | unsigned long uaddr) |
| 87 | { |
| 88 | unsigned long addr = uaddr >> 12 | |
| 89 | ((unsigned long)ASID(vma->vm_mm) << 48); |
| 90 | |
Will Deacon | 98f7685 | 2014-05-02 16:24:10 +0100 | [diff] [blame] | 91 | dsb(ishst); |
Catalin Marinas | 58d0ba5 | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 92 | asm("tlbi vae1is, %0" : : "r" (addr)); |
Will Deacon | 98f7685 | 2014-05-02 16:24:10 +0100 | [diff] [blame] | 93 | dsb(ish); |
Catalin Marinas | 58d0ba5 | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Mark Salter | 05ac653 | 2014-07-24 15:56:15 +0100 | [diff] [blame] | 96 | static inline void __flush_tlb_range(struct vm_area_struct *vma, |
| 97 | unsigned long start, unsigned long end) |
Steve Capper | fa48e6f | 2014-05-02 14:49:00 +0100 | [diff] [blame] | 98 | { |
| 99 | unsigned long asid = (unsigned long)ASID(vma->vm_mm) << 48; |
| 100 | unsigned long addr; |
| 101 | start = asid | (start >> 12); |
| 102 | end = asid | (end >> 12); |
| 103 | |
| 104 | dsb(ishst); |
| 105 | for (addr = start; addr < end; addr += 1 << (PAGE_SHIFT - 12)) |
| 106 | asm("tlbi vae1is, %0" : : "r"(addr)); |
| 107 | dsb(ish); |
| 108 | } |
| 109 | |
Mark Salter | 05ac653 | 2014-07-24 15:56:15 +0100 | [diff] [blame] | 110 | static inline void __flush_tlb_kernel_range(unsigned long start, unsigned long end) |
Steve Capper | fa48e6f | 2014-05-02 14:49:00 +0100 | [diff] [blame] | 111 | { |
| 112 | unsigned long addr; |
| 113 | start >>= 12; |
| 114 | end >>= 12; |
| 115 | |
| 116 | dsb(ishst); |
| 117 | for (addr = start; addr < end; addr += 1 << (PAGE_SHIFT - 12)) |
| 118 | asm("tlbi vaae1is, %0" : : "r"(addr)); |
| 119 | dsb(ish); |
Catalin Marinas | 7f0b1bf | 2014-06-09 11:55:03 +0100 | [diff] [blame] | 120 | isb(); |
Steve Capper | fa48e6f | 2014-05-02 14:49:00 +0100 | [diff] [blame] | 121 | } |
Catalin Marinas | 58d0ba5 | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 122 | |
| 123 | /* |
Mark Salter | 05ac653 | 2014-07-24 15:56:15 +0100 | [diff] [blame] | 124 | * This is meant to avoid soft lock-ups on large TLB flushing ranges and not |
| 125 | * necessarily a performance improvement. |
| 126 | */ |
| 127 | #define MAX_TLB_RANGE (1024UL << PAGE_SHIFT) |
| 128 | |
| 129 | static inline void flush_tlb_range(struct vm_area_struct *vma, |
| 130 | unsigned long start, unsigned long end) |
| 131 | { |
| 132 | if ((end - start) <= MAX_TLB_RANGE) |
| 133 | __flush_tlb_range(vma, start, end); |
| 134 | else |
| 135 | flush_tlb_mm(vma->vm_mm); |
| 136 | } |
| 137 | |
| 138 | static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end) |
| 139 | { |
| 140 | if ((end - start) <= MAX_TLB_RANGE) |
| 141 | __flush_tlb_kernel_range(start, end); |
| 142 | else |
| 143 | flush_tlb_all(); |
| 144 | } |
| 145 | |
| 146 | /* |
Catalin Marinas | 58d0ba5 | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 147 | * On AArch64, the cache coherency is handled via the set_pte_at() function. |
| 148 | */ |
| 149 | static inline void update_mmu_cache(struct vm_area_struct *vma, |
| 150 | unsigned long addr, pte_t *ptep) |
| 151 | { |
| 152 | /* |
Catalin Marinas | 7f0b1bf | 2014-06-09 11:55:03 +0100 | [diff] [blame] | 153 | * set_pte() does not have a DSB for user mappings, so make sure that |
| 154 | * the page table write is visible. |
Catalin Marinas | 58d0ba5 | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 155 | */ |
Will Deacon | 98f7685 | 2014-05-02 16:24:10 +0100 | [diff] [blame] | 156 | dsb(ishst); |
Catalin Marinas | 58d0ba5 | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Steve Capper | af07484 | 2013-04-19 16:23:57 +0100 | [diff] [blame] | 159 | #define update_mmu_cache_pmd(vma, address, pmd) do { } while (0) |
| 160 | |
Catalin Marinas | 58d0ba5 | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 161 | #endif |
| 162 | |
| 163 | #endif |