18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_NOHASH_PTE_BOOK3E_H 38c2ecf20Sopenharmony_ci#define _ASM_POWERPC_NOHASH_PTE_BOOK3E_H 48c2ecf20Sopenharmony_ci#ifdef __KERNEL__ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci/* PTE bit definitions for processors compliant to the Book3E 78c2ecf20Sopenharmony_ci * architecture 2.06 or later. The position of the PTE bits 88c2ecf20Sopenharmony_ci * matches the HW definition of the optional Embedded Page Table 98c2ecf20Sopenharmony_ci * category. 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci/* Architected bits */ 138c2ecf20Sopenharmony_ci#define _PAGE_PRESENT 0x000001 /* software: pte contains a translation */ 148c2ecf20Sopenharmony_ci#define _PAGE_SW1 0x000002 158c2ecf20Sopenharmony_ci#define _PAGE_BIT_SWAP_TYPE 2 168c2ecf20Sopenharmony_ci#define _PAGE_BAP_SR 0x000004 178c2ecf20Sopenharmony_ci#define _PAGE_BAP_UR 0x000008 188c2ecf20Sopenharmony_ci#define _PAGE_BAP_SW 0x000010 198c2ecf20Sopenharmony_ci#define _PAGE_BAP_UW 0x000020 208c2ecf20Sopenharmony_ci#define _PAGE_BAP_SX 0x000040 218c2ecf20Sopenharmony_ci#define _PAGE_BAP_UX 0x000080 228c2ecf20Sopenharmony_ci#define _PAGE_PSIZE_MSK 0x000f00 238c2ecf20Sopenharmony_ci#define _PAGE_PSIZE_4K 0x000200 248c2ecf20Sopenharmony_ci#define _PAGE_PSIZE_8K 0x000300 258c2ecf20Sopenharmony_ci#define _PAGE_PSIZE_16K 0x000400 268c2ecf20Sopenharmony_ci#define _PAGE_PSIZE_32K 0x000500 278c2ecf20Sopenharmony_ci#define _PAGE_PSIZE_64K 0x000600 288c2ecf20Sopenharmony_ci#define _PAGE_PSIZE_128K 0x000700 298c2ecf20Sopenharmony_ci#define _PAGE_PSIZE_256K 0x000800 308c2ecf20Sopenharmony_ci#define _PAGE_PSIZE_512K 0x000900 318c2ecf20Sopenharmony_ci#define _PAGE_PSIZE_1M 0x000a00 328c2ecf20Sopenharmony_ci#define _PAGE_PSIZE_2M 0x000b00 338c2ecf20Sopenharmony_ci#define _PAGE_PSIZE_4M 0x000c00 348c2ecf20Sopenharmony_ci#define _PAGE_PSIZE_8M 0x000d00 358c2ecf20Sopenharmony_ci#define _PAGE_PSIZE_16M 0x000e00 368c2ecf20Sopenharmony_ci#define _PAGE_PSIZE_32M 0x000f00 378c2ecf20Sopenharmony_ci#define _PAGE_DIRTY 0x001000 /* C: page changed */ 388c2ecf20Sopenharmony_ci#define _PAGE_SW0 0x002000 398c2ecf20Sopenharmony_ci#define _PAGE_U3 0x004000 408c2ecf20Sopenharmony_ci#define _PAGE_U2 0x008000 418c2ecf20Sopenharmony_ci#define _PAGE_U1 0x010000 428c2ecf20Sopenharmony_ci#define _PAGE_U0 0x020000 438c2ecf20Sopenharmony_ci#define _PAGE_ACCESSED 0x040000 448c2ecf20Sopenharmony_ci#define _PAGE_ENDIAN 0x080000 458c2ecf20Sopenharmony_ci#define _PAGE_GUARDED 0x100000 468c2ecf20Sopenharmony_ci#define _PAGE_COHERENT 0x200000 /* M: enforce memory coherence */ 478c2ecf20Sopenharmony_ci#define _PAGE_NO_CACHE 0x400000 /* I: cache inhibit */ 488c2ecf20Sopenharmony_ci#define _PAGE_WRITETHRU 0x800000 /* W: cache write-through */ 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/* "Higher level" linux bit combinations */ 518c2ecf20Sopenharmony_ci#define _PAGE_EXEC _PAGE_BAP_UX /* .. and was cache cleaned */ 528c2ecf20Sopenharmony_ci#define _PAGE_RW (_PAGE_BAP_SW | _PAGE_BAP_UW) /* User write permission */ 538c2ecf20Sopenharmony_ci#define _PAGE_KERNEL_RW (_PAGE_BAP_SW | _PAGE_BAP_SR | _PAGE_DIRTY) 548c2ecf20Sopenharmony_ci#define _PAGE_KERNEL_RO (_PAGE_BAP_SR) 558c2ecf20Sopenharmony_ci#define _PAGE_KERNEL_RWX (_PAGE_BAP_SW | _PAGE_BAP_SR | _PAGE_DIRTY | _PAGE_BAP_SX) 568c2ecf20Sopenharmony_ci#define _PAGE_KERNEL_ROX (_PAGE_BAP_SR | _PAGE_BAP_SX) 578c2ecf20Sopenharmony_ci#define _PAGE_USER (_PAGE_BAP_UR | _PAGE_BAP_SR) /* Can be read */ 588c2ecf20Sopenharmony_ci#define _PAGE_PRIVILEGED (_PAGE_BAP_SR) 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci#define _PAGE_SPECIAL _PAGE_SW0 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci/* Base page size */ 638c2ecf20Sopenharmony_ci#define _PAGE_PSIZE _PAGE_PSIZE_4K 648c2ecf20Sopenharmony_ci#define PTE_RPN_SHIFT (24) 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci#define PTE_WIMGE_SHIFT (19) 678c2ecf20Sopenharmony_ci#define PTE_BAP_SHIFT (2) 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci/* On 32-bit, we never clear the top part of the PTE */ 708c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC32 718c2ecf20Sopenharmony_ci#define _PTE_NONE_MASK 0xffffffff00000000ULL 728c2ecf20Sopenharmony_ci#define _PMD_PRESENT 0 738c2ecf20Sopenharmony_ci#define _PMD_PRESENT_MASK (PAGE_MASK) 748c2ecf20Sopenharmony_ci#define _PMD_BAD (~PAGE_MASK) 758c2ecf20Sopenharmony_ci#define _PMD_USER 0 768c2ecf20Sopenharmony_ci#else 778c2ecf20Sopenharmony_ci#define _PTE_NONE_MASK 0 788c2ecf20Sopenharmony_ci#endif 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci/* 818c2ecf20Sopenharmony_ci * We define 2 sets of base prot bits, one for basic pages (ie, 828c2ecf20Sopenharmony_ci * cacheable kernel and user pages) and one for non cacheable 838c2ecf20Sopenharmony_ci * pages. We always set _PAGE_COHERENT when SMP is enabled or 848c2ecf20Sopenharmony_ci * the processor might need it for DMA coherency. 858c2ecf20Sopenharmony_ci */ 868c2ecf20Sopenharmony_ci#define _PAGE_BASE_NC (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_PSIZE) 878c2ecf20Sopenharmony_ci#if defined(CONFIG_SMP) 888c2ecf20Sopenharmony_ci#define _PAGE_BASE (_PAGE_BASE_NC | _PAGE_COHERENT) 898c2ecf20Sopenharmony_ci#else 908c2ecf20Sopenharmony_ci#define _PAGE_BASE (_PAGE_BASE_NC) 918c2ecf20Sopenharmony_ci#endif 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci/* Permission masks used to generate the __P and __S table */ 948c2ecf20Sopenharmony_ci#define PAGE_NONE __pgprot(_PAGE_BASE) 958c2ecf20Sopenharmony_ci#define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW) 968c2ecf20Sopenharmony_ci#define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | _PAGE_EXEC) 978c2ecf20Sopenharmony_ci#define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER) 988c2ecf20Sopenharmony_ci#define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC) 998c2ecf20Sopenharmony_ci#define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER) 1008c2ecf20Sopenharmony_ci#define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC) 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 1038c2ecf20Sopenharmony_cistatic inline pte_t pte_mkprivileged(pte_t pte) 1048c2ecf20Sopenharmony_ci{ 1058c2ecf20Sopenharmony_ci return __pte((pte_val(pte) & ~_PAGE_USER) | _PAGE_PRIVILEGED); 1068c2ecf20Sopenharmony_ci} 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci#define pte_mkprivileged pte_mkprivileged 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_cistatic inline pte_t pte_mkuser(pte_t pte) 1118c2ecf20Sopenharmony_ci{ 1128c2ecf20Sopenharmony_ci return __pte((pte_val(pte) & ~_PAGE_PRIVILEGED) | _PAGE_USER); 1138c2ecf20Sopenharmony_ci} 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci#define pte_mkuser pte_mkuser 1168c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */ 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */ 1198c2ecf20Sopenharmony_ci#endif /* _ASM_POWERPC_NOHASH_PTE_BOOK3E_H */ 120