xref: /linux/arch/powerpc/include/asm/mman.h (revision 4a39ac5b7d62679c07a3e3d12b0f6982377d8a7d)
12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2b8b572e1SStephen Rothwell /*
3b8b572e1SStephen Rothwell  */
4c3617f72SDavid Howells #ifndef _ASM_POWERPC_MMAN_H
5c3617f72SDavid Howells #define _ASM_POWERPC_MMAN_H
6b8b572e1SStephen Rothwell 
7c3617f72SDavid Howells #include <uapi/asm/mman.h>
8b8b572e1SStephen Rothwell 
9*53cee505SChristophe Leroy #if defined(CONFIG_PPC64) && !defined(BUILD_VDSO)
10b8b572e1SStephen Rothwell 
11b8b572e1SStephen Rothwell #include <asm/cputable.h>
12b8b572e1SStephen Rothwell #include <linux/mm.h>
13013a91b3SRam Pai #include <linux/pkeys.h>
14b92a226eSKevin Hao #include <asm/cpu_has_feature.h>
1546d60bdbSChristophe Leroy #include <asm/firmware.h>
16b8b572e1SStephen Rothwell 
17e6bfb709SDave Hansen static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot,
18e6bfb709SDave Hansen 		unsigned long pkey)
19b8b572e1SStephen Rothwell {
2012564485SShawn Anastasio #ifdef CONFIG_PPC_MEM_KEYS
2112564485SShawn Anastasio 	return (((prot & PROT_SAO) ? VM_SAO : 0) | pkey_to_vmflag_bits(pkey));
2212564485SShawn Anastasio #else
2312564485SShawn Anastasio 	return ((prot & PROT_SAO) ? VM_SAO : 0);
2412564485SShawn Anastasio #endif
25b8b572e1SStephen Rothwell }
26e6bfb709SDave Hansen #define arch_calc_vm_prot_bits(prot, pkey) arch_calc_vm_prot_bits(prot, pkey)
27b8b572e1SStephen Rothwell 
2812564485SShawn Anastasio static inline bool arch_validate_prot(unsigned long prot, unsigned long addr)
2912564485SShawn Anastasio {
3012564485SShawn Anastasio 	if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM | PROT_SAO))
3112564485SShawn Anastasio 		return false;
329b725a90SShawn Anastasio 	if (prot & PROT_SAO) {
339b725a90SShawn Anastasio 		if (!cpu_has_feature(CPU_FTR_SAO))
3412564485SShawn Anastasio 			return false;
359b725a90SShawn Anastasio 		if (firmware_has_feature(FW_FEATURE_LPAR) &&
369b725a90SShawn Anastasio 		    !IS_ENABLED(CONFIG_PPC_PROT_SAO_LPAR))
379b725a90SShawn Anastasio 			return false;
389b725a90SShawn Anastasio 	}
3912564485SShawn Anastasio 	return true;
4012564485SShawn Anastasio }
4112564485SShawn Anastasio #define arch_validate_prot arch_validate_prot
42b8b572e1SStephen Rothwell 
43b8b572e1SStephen Rothwell #endif /* CONFIG_PPC64 */
44b8b572e1SStephen Rothwell #endif	/* _ASM_POWERPC_MMAN_H */
45