1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_BOOK3S_32_TLBFLUSH_H
3 #define _ASM_POWERPC_BOOK3S_32_TLBFLUSH_H
4
5 #include <linux/build_bug.h>
6
7 #define MMU_NO_CONTEXT (0)
8 /*
9 * TLB flushing for "classic" hash-MMU 32-bit CPUs, 6xx, 7xx, 7xxx
10 */
11 void hash__flush_tlb_mm(struct mm_struct *mm);
12 void hash__flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr);
13 void hash__flush_range(struct mm_struct *mm, unsigned long start, unsigned long end);
14 void hash__flush_gather(struct mmu_gather *tlb);
15
16 #ifdef CONFIG_SMP
17 void _tlbie(unsigned long address);
18 #else
_tlbie(unsigned long address)19 static inline void _tlbie(unsigned long address)
20 {
21 asm volatile ("tlbie %0; sync" : : "r" (address) : "memory");
22 }
23 #endif
24 void _tlbia(void);
25
26 /*
27 * Called at the end of a mmu_gather operation to make sure the
28 * TLB flush is completely done.
29 */
tlb_flush(struct mmu_gather * tlb)30 static inline void tlb_flush(struct mmu_gather *tlb)
31 {
32 /* 603 needs to flush the whole TLB here since it doesn't use a hash table. */
33 if (mmu_has_feature(MMU_FTR_HPTE_TABLE))
34 hash__flush_gather(tlb);
35 else
36 _tlbia();
37 }
38
flush_range(struct mm_struct * mm,unsigned long start,unsigned long end)39 static inline void flush_range(struct mm_struct *mm, unsigned long start, unsigned long end)
40 {
41 start &= PAGE_MASK;
42 if (mmu_has_feature(MMU_FTR_HPTE_TABLE))
43 hash__flush_range(mm, start, end);
44 else if (end - start <= PAGE_SIZE)
45 _tlbie(start);
46 else
47 _tlbia();
48 }
49
flush_tlb_mm(struct mm_struct * mm)50 static inline void flush_tlb_mm(struct mm_struct *mm)
51 {
52 if (mmu_has_feature(MMU_FTR_HPTE_TABLE))
53 hash__flush_tlb_mm(mm);
54 else
55 _tlbia();
56 }
57
flush_tlb_page(struct vm_area_struct * vma,unsigned long vmaddr)58 static inline void flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
59 {
60 if (mmu_has_feature(MMU_FTR_HPTE_TABLE))
61 hash__flush_tlb_page(vma, vmaddr);
62 else
63 _tlbie(vmaddr);
64 }
65
66 static inline void
flush_tlb_range(struct vm_area_struct * vma,unsigned long start,unsigned long end)67 flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
68 {
69 flush_range(vma->vm_mm, start, end);
70 }
71
flush_tlb_kernel_range(unsigned long start,unsigned long end)72 static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end)
73 {
74 flush_range(&init_mm, start, end);
75 }
76
local_flush_tlb_page(struct vm_area_struct * vma,unsigned long vmaddr)77 static inline void local_flush_tlb_page(struct vm_area_struct *vma,
78 unsigned long vmaddr)
79 {
80 flush_tlb_page(vma, vmaddr);
81 }
82
local_flush_tlb_page_psize(struct mm_struct * mm,unsigned long vmaddr,int psize)83 static inline void local_flush_tlb_page_psize(struct mm_struct *mm,
84 unsigned long vmaddr, int psize)
85 {
86 flush_range(mm, vmaddr, vmaddr);
87 }
88
local_flush_tlb_mm(struct mm_struct * mm)89 static inline void local_flush_tlb_mm(struct mm_struct *mm)
90 {
91 flush_tlb_mm(mm);
92 }
93
94 #endif /* _ASM_POWERPC_BOOK3S_32_TLBFLUSH_H */
95