xref: /OK3568_Linux_fs/kernel/arch/powerpc/include/asm/nohash/pte-book3e.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _ASM_POWERPC_NOHASH_PTE_BOOK3E_H
3*4882a593Smuzhiyun #define _ASM_POWERPC_NOHASH_PTE_BOOK3E_H
4*4882a593Smuzhiyun #ifdef __KERNEL__
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun /* PTE bit definitions for processors compliant to the Book3E
7*4882a593Smuzhiyun  * architecture 2.06 or later. The position of the PTE bits
8*4882a593Smuzhiyun  * matches the HW definition of the optional Embedded Page Table
9*4882a593Smuzhiyun  * category.
10*4882a593Smuzhiyun  */
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun /* Architected bits */
13*4882a593Smuzhiyun #define _PAGE_PRESENT	0x000001 /* software: pte contains a translation */
14*4882a593Smuzhiyun #define _PAGE_SW1	0x000002
15*4882a593Smuzhiyun #define _PAGE_BIT_SWAP_TYPE	2
16*4882a593Smuzhiyun #define _PAGE_BAP_SR	0x000004
17*4882a593Smuzhiyun #define _PAGE_BAP_UR	0x000008
18*4882a593Smuzhiyun #define _PAGE_BAP_SW	0x000010
19*4882a593Smuzhiyun #define _PAGE_BAP_UW	0x000020
20*4882a593Smuzhiyun #define _PAGE_BAP_SX	0x000040
21*4882a593Smuzhiyun #define _PAGE_BAP_UX	0x000080
22*4882a593Smuzhiyun #define _PAGE_PSIZE_MSK	0x000f00
23*4882a593Smuzhiyun #define _PAGE_PSIZE_4K	0x000200
24*4882a593Smuzhiyun #define _PAGE_PSIZE_8K	0x000300
25*4882a593Smuzhiyun #define _PAGE_PSIZE_16K	0x000400
26*4882a593Smuzhiyun #define _PAGE_PSIZE_32K	0x000500
27*4882a593Smuzhiyun #define _PAGE_PSIZE_64K	0x000600
28*4882a593Smuzhiyun #define _PAGE_PSIZE_128K	0x000700
29*4882a593Smuzhiyun #define _PAGE_PSIZE_256K	0x000800
30*4882a593Smuzhiyun #define _PAGE_PSIZE_512K	0x000900
31*4882a593Smuzhiyun #define _PAGE_PSIZE_1M	0x000a00
32*4882a593Smuzhiyun #define _PAGE_PSIZE_2M	0x000b00
33*4882a593Smuzhiyun #define _PAGE_PSIZE_4M	0x000c00
34*4882a593Smuzhiyun #define _PAGE_PSIZE_8M	0x000d00
35*4882a593Smuzhiyun #define _PAGE_PSIZE_16M	0x000e00
36*4882a593Smuzhiyun #define _PAGE_PSIZE_32M	0x000f00
37*4882a593Smuzhiyun #define _PAGE_DIRTY	0x001000 /* C: page changed */
38*4882a593Smuzhiyun #define _PAGE_SW0	0x002000
39*4882a593Smuzhiyun #define _PAGE_U3	0x004000
40*4882a593Smuzhiyun #define _PAGE_U2	0x008000
41*4882a593Smuzhiyun #define _PAGE_U1	0x010000
42*4882a593Smuzhiyun #define _PAGE_U0	0x020000
43*4882a593Smuzhiyun #define _PAGE_ACCESSED	0x040000
44*4882a593Smuzhiyun #define _PAGE_ENDIAN	0x080000
45*4882a593Smuzhiyun #define _PAGE_GUARDED	0x100000
46*4882a593Smuzhiyun #define _PAGE_COHERENT	0x200000 /* M: enforce memory coherence */
47*4882a593Smuzhiyun #define _PAGE_NO_CACHE	0x400000 /* I: cache inhibit */
48*4882a593Smuzhiyun #define _PAGE_WRITETHRU	0x800000 /* W: cache write-through */
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun /* "Higher level" linux bit combinations */
51*4882a593Smuzhiyun #define _PAGE_EXEC		_PAGE_BAP_UX /* .. and was cache cleaned */
52*4882a593Smuzhiyun #define _PAGE_RW		(_PAGE_BAP_SW | _PAGE_BAP_UW) /* User write permission */
53*4882a593Smuzhiyun #define _PAGE_KERNEL_RW		(_PAGE_BAP_SW | _PAGE_BAP_SR | _PAGE_DIRTY)
54*4882a593Smuzhiyun #define _PAGE_KERNEL_RO		(_PAGE_BAP_SR)
55*4882a593Smuzhiyun #define _PAGE_KERNEL_RWX	(_PAGE_BAP_SW | _PAGE_BAP_SR | _PAGE_DIRTY | _PAGE_BAP_SX)
56*4882a593Smuzhiyun #define _PAGE_KERNEL_ROX	(_PAGE_BAP_SR | _PAGE_BAP_SX)
57*4882a593Smuzhiyun #define _PAGE_USER		(_PAGE_BAP_UR | _PAGE_BAP_SR) /* Can be read */
58*4882a593Smuzhiyun #define _PAGE_PRIVILEGED	(_PAGE_BAP_SR)
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun #define _PAGE_SPECIAL	_PAGE_SW0
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun /* Base page size */
63*4882a593Smuzhiyun #define _PAGE_PSIZE	_PAGE_PSIZE_4K
64*4882a593Smuzhiyun #define	PTE_RPN_SHIFT	(24)
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun #define PTE_WIMGE_SHIFT (19)
67*4882a593Smuzhiyun #define PTE_BAP_SHIFT	(2)
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun /* On 32-bit, we never clear the top part of the PTE */
70*4882a593Smuzhiyun #ifdef CONFIG_PPC32
71*4882a593Smuzhiyun #define _PTE_NONE_MASK	0xffffffff00000000ULL
72*4882a593Smuzhiyun #define _PMD_PRESENT	0
73*4882a593Smuzhiyun #define _PMD_PRESENT_MASK (PAGE_MASK)
74*4882a593Smuzhiyun #define _PMD_BAD	(~PAGE_MASK)
75*4882a593Smuzhiyun #define _PMD_USER	0
76*4882a593Smuzhiyun #else
77*4882a593Smuzhiyun #define _PTE_NONE_MASK	0
78*4882a593Smuzhiyun #endif
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun /*
81*4882a593Smuzhiyun  * We define 2 sets of base prot bits, one for basic pages (ie,
82*4882a593Smuzhiyun  * cacheable kernel and user pages) and one for non cacheable
83*4882a593Smuzhiyun  * pages. We always set _PAGE_COHERENT when SMP is enabled or
84*4882a593Smuzhiyun  * the processor might need it for DMA coherency.
85*4882a593Smuzhiyun  */
86*4882a593Smuzhiyun #define _PAGE_BASE_NC	(_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_PSIZE)
87*4882a593Smuzhiyun #if defined(CONFIG_SMP)
88*4882a593Smuzhiyun #define _PAGE_BASE	(_PAGE_BASE_NC | _PAGE_COHERENT)
89*4882a593Smuzhiyun #else
90*4882a593Smuzhiyun #define _PAGE_BASE	(_PAGE_BASE_NC)
91*4882a593Smuzhiyun #endif
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun /* Permission masks used to generate the __P and __S table */
94*4882a593Smuzhiyun #define PAGE_NONE	__pgprot(_PAGE_BASE)
95*4882a593Smuzhiyun #define PAGE_SHARED	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW)
96*4882a593Smuzhiyun #define PAGE_SHARED_X	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | _PAGE_EXEC)
97*4882a593Smuzhiyun #define PAGE_COPY	__pgprot(_PAGE_BASE | _PAGE_USER)
98*4882a593Smuzhiyun #define PAGE_COPY_X	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
99*4882a593Smuzhiyun #define PAGE_READONLY	__pgprot(_PAGE_BASE | _PAGE_USER)
100*4882a593Smuzhiyun #define PAGE_READONLY_X	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun #ifndef __ASSEMBLY__
pte_mkprivileged(pte_t pte)103*4882a593Smuzhiyun static inline pte_t pte_mkprivileged(pte_t pte)
104*4882a593Smuzhiyun {
105*4882a593Smuzhiyun 	return __pte((pte_val(pte) & ~_PAGE_USER) | _PAGE_PRIVILEGED);
106*4882a593Smuzhiyun }
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun #define pte_mkprivileged pte_mkprivileged
109*4882a593Smuzhiyun 
pte_mkuser(pte_t pte)110*4882a593Smuzhiyun static inline pte_t pte_mkuser(pte_t pte)
111*4882a593Smuzhiyun {
112*4882a593Smuzhiyun 	return __pte((pte_val(pte) & ~_PAGE_PRIVILEGED) | _PAGE_USER);
113*4882a593Smuzhiyun }
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun #define pte_mkuser pte_mkuser
116*4882a593Smuzhiyun #endif /* __ASSEMBLY__ */
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun #endif /* __KERNEL__ */
119*4882a593Smuzhiyun #endif /*  _ASM_POWERPC_NOHASH_PTE_BOOK3E_H */
120