18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _ALPHA_TLBFLUSH_H 38c2ecf20Sopenharmony_ci#define _ALPHA_TLBFLUSH_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/mm.h> 68c2ecf20Sopenharmony_ci#include <linux/sched.h> 78c2ecf20Sopenharmony_ci#include <asm/compiler.h> 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifndef __EXTERN_INLINE 108c2ecf20Sopenharmony_ci#define __EXTERN_INLINE extern inline 118c2ecf20Sopenharmony_ci#define __MMU_EXTERN_INLINE 128c2ecf20Sopenharmony_ci#endif 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ciextern void __load_new_mm_context(struct mm_struct *); 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* Use a few helper functions to hide the ugly broken ASN 188c2ecf20Sopenharmony_ci numbers on early Alphas (ev4 and ev45). */ 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci__EXTERN_INLINE void 218c2ecf20Sopenharmony_ciev4_flush_tlb_current(struct mm_struct *mm) 228c2ecf20Sopenharmony_ci{ 238c2ecf20Sopenharmony_ci __load_new_mm_context(mm); 248c2ecf20Sopenharmony_ci tbiap(); 258c2ecf20Sopenharmony_ci} 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci__EXTERN_INLINE void 288c2ecf20Sopenharmony_ciev5_flush_tlb_current(struct mm_struct *mm) 298c2ecf20Sopenharmony_ci{ 308c2ecf20Sopenharmony_ci __load_new_mm_context(mm); 318c2ecf20Sopenharmony_ci} 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci/* Flush just one page in the current TLB set. We need to be very 348c2ecf20Sopenharmony_ci careful about the icache here, there is no way to invalidate a 358c2ecf20Sopenharmony_ci specific icache page. */ 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci__EXTERN_INLINE void 388c2ecf20Sopenharmony_ciev4_flush_tlb_current_page(struct mm_struct * mm, 398c2ecf20Sopenharmony_ci struct vm_area_struct *vma, 408c2ecf20Sopenharmony_ci unsigned long addr) 418c2ecf20Sopenharmony_ci{ 428c2ecf20Sopenharmony_ci int tbi_flag = 2; 438c2ecf20Sopenharmony_ci if (vma->vm_flags & VM_EXEC) { 448c2ecf20Sopenharmony_ci __load_new_mm_context(mm); 458c2ecf20Sopenharmony_ci tbi_flag = 3; 468c2ecf20Sopenharmony_ci } 478c2ecf20Sopenharmony_ci tbi(tbi_flag, addr); 488c2ecf20Sopenharmony_ci} 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci__EXTERN_INLINE void 518c2ecf20Sopenharmony_ciev5_flush_tlb_current_page(struct mm_struct * mm, 528c2ecf20Sopenharmony_ci struct vm_area_struct *vma, 538c2ecf20Sopenharmony_ci unsigned long addr) 548c2ecf20Sopenharmony_ci{ 558c2ecf20Sopenharmony_ci if (vma->vm_flags & VM_EXEC) 568c2ecf20Sopenharmony_ci __load_new_mm_context(mm); 578c2ecf20Sopenharmony_ci else 588c2ecf20Sopenharmony_ci tbi(2, addr); 598c2ecf20Sopenharmony_ci} 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci#ifdef CONFIG_ALPHA_GENERIC 638c2ecf20Sopenharmony_ci# define flush_tlb_current alpha_mv.mv_flush_tlb_current 648c2ecf20Sopenharmony_ci# define flush_tlb_current_page alpha_mv.mv_flush_tlb_current_page 658c2ecf20Sopenharmony_ci#else 668c2ecf20Sopenharmony_ci# ifdef CONFIG_ALPHA_EV4 678c2ecf20Sopenharmony_ci# define flush_tlb_current ev4_flush_tlb_current 688c2ecf20Sopenharmony_ci# define flush_tlb_current_page ev4_flush_tlb_current_page 698c2ecf20Sopenharmony_ci# else 708c2ecf20Sopenharmony_ci# define flush_tlb_current ev5_flush_tlb_current 718c2ecf20Sopenharmony_ci# define flush_tlb_current_page ev5_flush_tlb_current_page 728c2ecf20Sopenharmony_ci# endif 738c2ecf20Sopenharmony_ci#endif 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci#ifdef __MMU_EXTERN_INLINE 768c2ecf20Sopenharmony_ci#undef __EXTERN_INLINE 778c2ecf20Sopenharmony_ci#undef __MMU_EXTERN_INLINE 788c2ecf20Sopenharmony_ci#endif 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci/* Flush current user mapping. */ 818c2ecf20Sopenharmony_cistatic inline void 828c2ecf20Sopenharmony_ciflush_tlb(void) 838c2ecf20Sopenharmony_ci{ 848c2ecf20Sopenharmony_ci flush_tlb_current(current->active_mm); 858c2ecf20Sopenharmony_ci} 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci/* Flush someone else's user mapping. */ 888c2ecf20Sopenharmony_cistatic inline void 898c2ecf20Sopenharmony_ciflush_tlb_other(struct mm_struct *mm) 908c2ecf20Sopenharmony_ci{ 918c2ecf20Sopenharmony_ci unsigned long *mmc = &mm->context[smp_processor_id()]; 928c2ecf20Sopenharmony_ci /* Check it's not zero first to avoid cacheline ping pong 938c2ecf20Sopenharmony_ci when possible. */ 948c2ecf20Sopenharmony_ci if (*mmc) *mmc = 0; 958c2ecf20Sopenharmony_ci} 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci#ifndef CONFIG_SMP 988c2ecf20Sopenharmony_ci/* Flush everything (kernel mapping may also have changed 998c2ecf20Sopenharmony_ci due to vmalloc/vfree). */ 1008c2ecf20Sopenharmony_cistatic inline void flush_tlb_all(void) 1018c2ecf20Sopenharmony_ci{ 1028c2ecf20Sopenharmony_ci tbia(); 1038c2ecf20Sopenharmony_ci} 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci/* Flush a specified user mapping. */ 1068c2ecf20Sopenharmony_cistatic inline void 1078c2ecf20Sopenharmony_ciflush_tlb_mm(struct mm_struct *mm) 1088c2ecf20Sopenharmony_ci{ 1098c2ecf20Sopenharmony_ci if (mm == current->active_mm) 1108c2ecf20Sopenharmony_ci flush_tlb_current(mm); 1118c2ecf20Sopenharmony_ci else 1128c2ecf20Sopenharmony_ci flush_tlb_other(mm); 1138c2ecf20Sopenharmony_ci} 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci/* Page-granular tlb flush. */ 1168c2ecf20Sopenharmony_cistatic inline void 1178c2ecf20Sopenharmony_ciflush_tlb_page(struct vm_area_struct *vma, unsigned long addr) 1188c2ecf20Sopenharmony_ci{ 1198c2ecf20Sopenharmony_ci struct mm_struct *mm = vma->vm_mm; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci if (mm == current->active_mm) 1228c2ecf20Sopenharmony_ci flush_tlb_current_page(mm, vma, addr); 1238c2ecf20Sopenharmony_ci else 1248c2ecf20Sopenharmony_ci flush_tlb_other(mm); 1258c2ecf20Sopenharmony_ci} 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci/* Flush a specified range of user mapping. On the Alpha we flush 1288c2ecf20Sopenharmony_ci the whole user tlb. */ 1298c2ecf20Sopenharmony_cistatic inline void 1308c2ecf20Sopenharmony_ciflush_tlb_range(struct vm_area_struct *vma, unsigned long start, 1318c2ecf20Sopenharmony_ci unsigned long end) 1328c2ecf20Sopenharmony_ci{ 1338c2ecf20Sopenharmony_ci flush_tlb_mm(vma->vm_mm); 1348c2ecf20Sopenharmony_ci} 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci#else /* CONFIG_SMP */ 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ciextern void flush_tlb_all(void); 1398c2ecf20Sopenharmony_ciextern void flush_tlb_mm(struct mm_struct *); 1408c2ecf20Sopenharmony_ciextern void flush_tlb_page(struct vm_area_struct *, unsigned long); 1418c2ecf20Sopenharmony_ciextern void flush_tlb_range(struct vm_area_struct *, unsigned long, 1428c2ecf20Sopenharmony_ci unsigned long); 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci#endif /* CONFIG_SMP */ 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_cistatic inline void flush_tlb_kernel_range(unsigned long start, 1478c2ecf20Sopenharmony_ci unsigned long end) 1488c2ecf20Sopenharmony_ci{ 1498c2ecf20Sopenharmony_ci flush_tlb_all(); 1508c2ecf20Sopenharmony_ci} 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci#endif /* _ALPHA_TLBFLUSH_H */ 153