/arch/powerpc/include/asm/mman.h

http://github.com/mirrors/linux · C Header · 54 lines · 40 code · 7 blank · 7 comment · 3 complexity · 67b09ae2bf1078ad6f621e11772d5d89 MD5 · raw file

  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. */
  4. #ifndef _ASM_POWERPC_MMAN_H
  5. #define _ASM_POWERPC_MMAN_H
  6. #include <uapi/asm/mman.h>
  7. #ifdef CONFIG_PPC64
  8. #include <asm/cputable.h>
  9. #include <linux/mm.h>
  10. #include <linux/pkeys.h>
  11. #include <asm/cpu_has_feature.h>
  12. /*
  13. * This file is included by linux/mman.h, so we can't use cacl_vm_prot_bits()
  14. * here. How important is the optimization?
  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. static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
  27. {
  28. #ifdef CONFIG_PPC_MEM_KEYS
  29. return (vm_flags & VM_SAO) ?
  30. __pgprot(_PAGE_SAO | vmflag_to_pte_pkey_bits(vm_flags)) :
  31. __pgprot(0 | vmflag_to_pte_pkey_bits(vm_flags));
  32. #else
  33. return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
  34. #endif
  35. }
  36. #define arch_vm_get_page_prot(vm_flags) arch_vm_get_page_prot(vm_flags)
  37. static inline bool arch_validate_prot(unsigned long prot, unsigned long addr)
  38. {
  39. if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM | PROT_SAO))
  40. return false;
  41. if ((prot & PROT_SAO) && !cpu_has_feature(CPU_FTR_SAO))
  42. return false;
  43. return true;
  44. }
  45. #define arch_validate_prot arch_validate_prot
  46. #endif /* CONFIG_PPC64 */
  47. #endif /* _ASM_POWERPC_MMAN_H */