162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci */ 462306a36Sopenharmony_ci#ifndef _ASM_POWERPC_MMAN_H 562306a36Sopenharmony_ci#define _ASM_POWERPC_MMAN_H 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#include <uapi/asm/mman.h> 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#ifdef CONFIG_PPC64 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include <asm/cputable.h> 1262306a36Sopenharmony_ci#include <linux/mm.h> 1362306a36Sopenharmony_ci#include <linux/pkeys.h> 1462306a36Sopenharmony_ci#include <asm/cpu_has_feature.h> 1562306a36Sopenharmony_ci#include <asm/firmware.h> 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_cistatic inline unsigned long arch_calc_vm_prot_bits(unsigned long prot, 1862306a36Sopenharmony_ci unsigned long pkey) 1962306a36Sopenharmony_ci{ 2062306a36Sopenharmony_ci#ifdef CONFIG_PPC_MEM_KEYS 2162306a36Sopenharmony_ci return (((prot & PROT_SAO) ? VM_SAO : 0) | pkey_to_vmflag_bits(pkey)); 2262306a36Sopenharmony_ci#else 2362306a36Sopenharmony_ci return ((prot & PROT_SAO) ? VM_SAO : 0); 2462306a36Sopenharmony_ci#endif 2562306a36Sopenharmony_ci} 2662306a36Sopenharmony_ci#define arch_calc_vm_prot_bits(prot, pkey) arch_calc_vm_prot_bits(prot, pkey) 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_cistatic inline bool arch_validate_prot(unsigned long prot, unsigned long addr) 2962306a36Sopenharmony_ci{ 3062306a36Sopenharmony_ci if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM | PROT_SAO)) 3162306a36Sopenharmony_ci return false; 3262306a36Sopenharmony_ci if (prot & PROT_SAO) { 3362306a36Sopenharmony_ci if (!cpu_has_feature(CPU_FTR_SAO)) 3462306a36Sopenharmony_ci return false; 3562306a36Sopenharmony_ci if (firmware_has_feature(FW_FEATURE_LPAR) && 3662306a36Sopenharmony_ci !IS_ENABLED(CONFIG_PPC_PROT_SAO_LPAR)) 3762306a36Sopenharmony_ci return false; 3862306a36Sopenharmony_ci } 3962306a36Sopenharmony_ci return true; 4062306a36Sopenharmony_ci} 4162306a36Sopenharmony_ci#define arch_validate_prot arch_validate_prot 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci#endif /* CONFIG_PPC64 */ 4462306a36Sopenharmony_ci#endif /* _ASM_POWERPC_MMAN_H */ 45