162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef _ASM_POWERPC_BOOK3S_32_TLBFLUSH_H
362306a36Sopenharmony_ci#define _ASM_POWERPC_BOOK3S_32_TLBFLUSH_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/build_bug.h>
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#define MMU_NO_CONTEXT      (0)
862306a36Sopenharmony_ci/*
962306a36Sopenharmony_ci * TLB flushing for "classic" hash-MMU 32-bit CPUs, 6xx, 7xx, 7xxx
1062306a36Sopenharmony_ci */
1162306a36Sopenharmony_civoid hash__flush_tlb_mm(struct mm_struct *mm);
1262306a36Sopenharmony_civoid hash__flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr);
1362306a36Sopenharmony_civoid hash__flush_range(struct mm_struct *mm, unsigned long start, unsigned long end);
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#ifdef CONFIG_SMP
1662306a36Sopenharmony_civoid _tlbie(unsigned long address);
1762306a36Sopenharmony_ci#else
1862306a36Sopenharmony_cistatic inline void _tlbie(unsigned long address)
1962306a36Sopenharmony_ci{
2062306a36Sopenharmony_ci	asm volatile ("tlbie %0; sync" : : "r" (address) : "memory");
2162306a36Sopenharmony_ci}
2262306a36Sopenharmony_ci#endif
2362306a36Sopenharmony_civoid _tlbia(void);
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci/*
2662306a36Sopenharmony_ci * Called at the end of a mmu_gather operation to make sure the
2762306a36Sopenharmony_ci * TLB flush is completely done.
2862306a36Sopenharmony_ci */
2962306a36Sopenharmony_cistatic inline void tlb_flush(struct mmu_gather *tlb)
3062306a36Sopenharmony_ci{
3162306a36Sopenharmony_ci	/* 603 needs to flush the whole TLB here since it doesn't use a hash table. */
3262306a36Sopenharmony_ci	if (!mmu_has_feature(MMU_FTR_HPTE_TABLE))
3362306a36Sopenharmony_ci		_tlbia();
3462306a36Sopenharmony_ci}
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_cistatic inline void flush_range(struct mm_struct *mm, unsigned long start, unsigned long end)
3762306a36Sopenharmony_ci{
3862306a36Sopenharmony_ci	start &= PAGE_MASK;
3962306a36Sopenharmony_ci	if (mmu_has_feature(MMU_FTR_HPTE_TABLE))
4062306a36Sopenharmony_ci		hash__flush_range(mm, start, end);
4162306a36Sopenharmony_ci	else if (end - start <= PAGE_SIZE)
4262306a36Sopenharmony_ci		_tlbie(start);
4362306a36Sopenharmony_ci	else
4462306a36Sopenharmony_ci		_tlbia();
4562306a36Sopenharmony_ci}
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_cistatic inline void flush_tlb_mm(struct mm_struct *mm)
4862306a36Sopenharmony_ci{
4962306a36Sopenharmony_ci	if (mmu_has_feature(MMU_FTR_HPTE_TABLE))
5062306a36Sopenharmony_ci		hash__flush_tlb_mm(mm);
5162306a36Sopenharmony_ci	else
5262306a36Sopenharmony_ci		_tlbia();
5362306a36Sopenharmony_ci}
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_cistatic inline void flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
5662306a36Sopenharmony_ci{
5762306a36Sopenharmony_ci	if (mmu_has_feature(MMU_FTR_HPTE_TABLE))
5862306a36Sopenharmony_ci		hash__flush_tlb_page(vma, vmaddr);
5962306a36Sopenharmony_ci	else
6062306a36Sopenharmony_ci		_tlbie(vmaddr);
6162306a36Sopenharmony_ci}
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_cistatic inline void
6462306a36Sopenharmony_ciflush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
6562306a36Sopenharmony_ci{
6662306a36Sopenharmony_ci	flush_range(vma->vm_mm, start, end);
6762306a36Sopenharmony_ci}
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_cistatic inline void flush_tlb_kernel_range(unsigned long start, unsigned long end)
7062306a36Sopenharmony_ci{
7162306a36Sopenharmony_ci	flush_range(&init_mm, start, end);
7262306a36Sopenharmony_ci}
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_cistatic inline void local_flush_tlb_page(struct vm_area_struct *vma,
7562306a36Sopenharmony_ci					unsigned long vmaddr)
7662306a36Sopenharmony_ci{
7762306a36Sopenharmony_ci	flush_tlb_page(vma, vmaddr);
7862306a36Sopenharmony_ci}
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_cistatic inline void local_flush_tlb_page_psize(struct mm_struct *mm,
8162306a36Sopenharmony_ci					      unsigned long vmaddr, int psize)
8262306a36Sopenharmony_ci{
8362306a36Sopenharmony_ci	BUILD_BUG();
8462306a36Sopenharmony_ci}
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_cistatic inline void local_flush_tlb_mm(struct mm_struct *mm)
8762306a36Sopenharmony_ci{
8862306a36Sopenharmony_ci	flush_tlb_mm(mm);
8962306a36Sopenharmony_ci}
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci#endif /* _ASM_POWERPC_BOOK3S_32_TLBFLUSH_H */
92