xref: /OK3568_Linux_fs/kernel/arch/powerpc/include/asm/book3s/64/hash-pkey.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _ASM_POWERPC_BOOK3S_64_HASH_PKEY_H
3*4882a593Smuzhiyun #define _ASM_POWERPC_BOOK3S_64_HASH_PKEY_H
4*4882a593Smuzhiyun 
hash__vmflag_to_pte_pkey_bits(u64 vm_flags)5*4882a593Smuzhiyun static inline u64 hash__vmflag_to_pte_pkey_bits(u64 vm_flags)
6*4882a593Smuzhiyun {
7*4882a593Smuzhiyun 	return (((vm_flags & VM_PKEY_BIT0) ? H_PTE_PKEY_BIT0 : 0x0UL) |
8*4882a593Smuzhiyun 		((vm_flags & VM_PKEY_BIT1) ? H_PTE_PKEY_BIT1 : 0x0UL) |
9*4882a593Smuzhiyun 		((vm_flags & VM_PKEY_BIT2) ? H_PTE_PKEY_BIT2 : 0x0UL) |
10*4882a593Smuzhiyun 		((vm_flags & VM_PKEY_BIT3) ? H_PTE_PKEY_BIT3 : 0x0UL) |
11*4882a593Smuzhiyun 		((vm_flags & VM_PKEY_BIT4) ? H_PTE_PKEY_BIT4 : 0x0UL));
12*4882a593Smuzhiyun }
13*4882a593Smuzhiyun 
pte_to_hpte_pkey_bits(u64 pteflags)14*4882a593Smuzhiyun static inline u64 pte_to_hpte_pkey_bits(u64 pteflags)
15*4882a593Smuzhiyun {
16*4882a593Smuzhiyun 	return (((pteflags & H_PTE_PKEY_BIT4) ? HPTE_R_KEY_BIT4 : 0x0UL) |
17*4882a593Smuzhiyun 		((pteflags & H_PTE_PKEY_BIT3) ? HPTE_R_KEY_BIT3 : 0x0UL) |
18*4882a593Smuzhiyun 		((pteflags & H_PTE_PKEY_BIT2) ? HPTE_R_KEY_BIT2 : 0x0UL) |
19*4882a593Smuzhiyun 		((pteflags & H_PTE_PKEY_BIT1) ? HPTE_R_KEY_BIT1 : 0x0UL) |
20*4882a593Smuzhiyun 		((pteflags & H_PTE_PKEY_BIT0) ? HPTE_R_KEY_BIT0 : 0x0UL));
21*4882a593Smuzhiyun }
22*4882a593Smuzhiyun 
hash__pte_to_pkey_bits(u64 pteflags)23*4882a593Smuzhiyun static inline u16 hash__pte_to_pkey_bits(u64 pteflags)
24*4882a593Smuzhiyun {
25*4882a593Smuzhiyun 	return (((pteflags & H_PTE_PKEY_BIT4) ? 0x10 : 0x0UL) |
26*4882a593Smuzhiyun 		((pteflags & H_PTE_PKEY_BIT3) ? 0x8 : 0x0UL) |
27*4882a593Smuzhiyun 		((pteflags & H_PTE_PKEY_BIT2) ? 0x4 : 0x0UL) |
28*4882a593Smuzhiyun 		((pteflags & H_PTE_PKEY_BIT1) ? 0x2 : 0x0UL) |
29*4882a593Smuzhiyun 		((pteflags & H_PTE_PKEY_BIT0) ? 0x1 : 0x0UL));
30*4882a593Smuzhiyun }
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun #endif
33