1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 */ 4 #ifndef _ASM_POWERPC_MMAN_H 5 #define _ASM_POWERPC_MMAN_H 6 7 #include <uapi/asm/mman.h> 8 9 #ifdef CONFIG_PPC64 10 11 #include <asm/cputable.h> 12 #include <linux/mm.h> 13 #include <linux/pkeys.h> 14 #include <asm/cpu_has_feature.h> 15 16 static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot, 17 unsigned long pkey) 18 { 19 #ifdef CONFIG_PPC_MEM_KEYS 20 return (((prot & PROT_SAO) ? VM_SAO : 0) | pkey_to_vmflag_bits(pkey)); 21 #else 22 return ((prot & PROT_SAO) ? VM_SAO : 0); 23 #endif 24 } 25 #define arch_calc_vm_prot_bits(prot, pkey) arch_calc_vm_prot_bits(prot, pkey) 26 27 static inline bool arch_validate_prot(unsigned long prot, unsigned long addr) 28 { 29 if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM | PROT_SAO)) 30 return false; 31 if (prot & PROT_SAO) { 32 if (!cpu_has_feature(CPU_FTR_SAO)) 33 return false; 34 if (firmware_has_feature(FW_FEATURE_LPAR) && 35 !IS_ENABLED(CONFIG_PPC_PROT_SAO_LPAR)) 36 return false; 37 } 38 return true; 39 } 40 #define arch_validate_prot arch_validate_prot 41 42 #endif /* CONFIG_PPC64 */ 43 #endif /* _ASM_POWERPC_MMAN_H */ 44