1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _ASM_POWERPC_NOHASH_32_PTE_8xx_H
3*4882a593Smuzhiyun #define _ASM_POWERPC_NOHASH_32_PTE_8xx_H
4*4882a593Smuzhiyun #ifdef __KERNEL__
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun /*
7*4882a593Smuzhiyun * The PowerPC MPC8xx uses a TLB with hardware assisted, software tablewalk.
8*4882a593Smuzhiyun * We also use the two level tables, but we can put the real bits in them
9*4882a593Smuzhiyun * needed for the TLB and tablewalk. These definitions require Mx_CTR.PPM = 0,
10*4882a593Smuzhiyun * Mx_CTR.PPCS = 0, and MD_CTR.TWAM = 1. The level 2 descriptor has
11*4882a593Smuzhiyun * additional page protection (when Mx_CTR.PPCS = 1) that allows TLB hit
12*4882a593Smuzhiyun * based upon user/super access. The TLB does not have accessed nor write
13*4882a593Smuzhiyun * protect. We assume that if the TLB get loaded with an entry it is
14*4882a593Smuzhiyun * accessed, and overload the changed bit for write protect. We use
15*4882a593Smuzhiyun * two bits in the software pte that are supposed to be set to zero in
16*4882a593Smuzhiyun * the TLB entry (24 and 25) for these indicators. Although the level 1
17*4882a593Smuzhiyun * descriptor contains the guarded and writethrough/copyback bits, we can
18*4882a593Smuzhiyun * set these at the page level since they get copied from the Mx_TWC
19*4882a593Smuzhiyun * register when the TLB entry is loaded. We will use bit 27 for guard, since
20*4882a593Smuzhiyun * that is where it exists in the MD_TWC, and bit 26 for writethrough.
21*4882a593Smuzhiyun * These will get masked from the level 2 descriptor at TLB load time, and
22*4882a593Smuzhiyun * copied to the MD_TWC before it gets loaded.
23*4882a593Smuzhiyun * Large page sizes added. We currently support two sizes, 4K and 8M.
24*4882a593Smuzhiyun * This also allows a TLB hander optimization because we can directly
25*4882a593Smuzhiyun * load the PMD into MD_TWC. The 8M pages are only used for kernel
26*4882a593Smuzhiyun * mapping of well known areas. The PMD (PGD) entries contain control
27*4882a593Smuzhiyun * flags in addition to the address, so care must be taken that the
28*4882a593Smuzhiyun * software no longer assumes these are only pointers.
29*4882a593Smuzhiyun */
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun /* Definitions for 8xx embedded chips. */
32*4882a593Smuzhiyun #define _PAGE_PRESENT 0x0001 /* V: Page is valid */
33*4882a593Smuzhiyun #define _PAGE_NO_CACHE 0x0002 /* CI: cache inhibit */
34*4882a593Smuzhiyun #define _PAGE_SH 0x0004 /* SH: No ASID (context) compare */
35*4882a593Smuzhiyun #define _PAGE_SPS 0x0008 /* SPS: Small Page Size (1 if 16k, 512k or 8M)*/
36*4882a593Smuzhiyun #define _PAGE_DIRTY 0x0100 /* C: page changed */
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun /* These 4 software bits must be masked out when the L2 entry is loaded
39*4882a593Smuzhiyun * into the TLB.
40*4882a593Smuzhiyun */
41*4882a593Smuzhiyun #define _PAGE_GUARDED 0x0010 /* Copied to L1 G entry in DTLB */
42*4882a593Smuzhiyun #define _PAGE_ACCESSED 0x0020 /* Copied to L1 APG 1 entry in I/DTLB */
43*4882a593Smuzhiyun #define _PAGE_EXEC 0x0040 /* Copied to PP (bit 21) in ITLB */
44*4882a593Smuzhiyun #define _PAGE_SPECIAL 0x0080 /* SW entry */
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun #define _PAGE_NA 0x0200 /* Supervisor NA, User no access */
47*4882a593Smuzhiyun #define _PAGE_RO 0x0600 /* Supervisor RO, User no access */
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun #define _PAGE_HUGE 0x0800 /* Copied to L1 PS bit 29 */
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun /* cache related flags non existing on 8xx */
52*4882a593Smuzhiyun #define _PAGE_COHERENT 0
53*4882a593Smuzhiyun #define _PAGE_WRITETHRU 0
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun #define _PAGE_KERNEL_RO (_PAGE_SH | _PAGE_RO)
56*4882a593Smuzhiyun #define _PAGE_KERNEL_ROX (_PAGE_SH | _PAGE_RO | _PAGE_EXEC)
57*4882a593Smuzhiyun #define _PAGE_KERNEL_RW (_PAGE_SH | _PAGE_DIRTY)
58*4882a593Smuzhiyun #define _PAGE_KERNEL_RWX (_PAGE_SH | _PAGE_DIRTY | _PAGE_EXEC)
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun #define _PMD_PRESENT 0x0001
61*4882a593Smuzhiyun #define _PMD_PRESENT_MASK _PMD_PRESENT
62*4882a593Smuzhiyun #define _PMD_BAD 0x0f90
63*4882a593Smuzhiyun #define _PMD_PAGE_MASK 0x000c
64*4882a593Smuzhiyun #define _PMD_PAGE_8M 0x000c
65*4882a593Smuzhiyun #define _PMD_PAGE_512K 0x0004
66*4882a593Smuzhiyun #define _PMD_ACCESSED 0x0020 /* APG 1 */
67*4882a593Smuzhiyun #define _PMD_USER 0x0040 /* APG 2 */
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun #define _PTE_NONE_MASK 0
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun #ifdef CONFIG_PPC_16K_PAGES
72*4882a593Smuzhiyun #define _PAGE_PSIZE _PAGE_SPS
73*4882a593Smuzhiyun #else
74*4882a593Smuzhiyun #define _PAGE_PSIZE 0
75*4882a593Smuzhiyun #endif
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun #define _PAGE_BASE_NC (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_PSIZE)
78*4882a593Smuzhiyun #define _PAGE_BASE (_PAGE_BASE_NC)
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun /* Permission masks used to generate the __P and __S table */
81*4882a593Smuzhiyun #define PAGE_NONE __pgprot(_PAGE_BASE | _PAGE_NA)
82*4882a593Smuzhiyun #define PAGE_SHARED __pgprot(_PAGE_BASE)
83*4882a593Smuzhiyun #define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_EXEC)
84*4882a593Smuzhiyun #define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_RO)
85*4882a593Smuzhiyun #define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_RO | _PAGE_EXEC)
86*4882a593Smuzhiyun #define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_RO)
87*4882a593Smuzhiyun #define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_RO | _PAGE_EXEC)
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun #ifndef __ASSEMBLY__
pte_wrprotect(pte_t pte)90*4882a593Smuzhiyun static inline pte_t pte_wrprotect(pte_t pte)
91*4882a593Smuzhiyun {
92*4882a593Smuzhiyun return __pte(pte_val(pte) | _PAGE_RO);
93*4882a593Smuzhiyun }
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun #define pte_wrprotect pte_wrprotect
96*4882a593Smuzhiyun
pte_write(pte_t pte)97*4882a593Smuzhiyun static inline int pte_write(pte_t pte)
98*4882a593Smuzhiyun {
99*4882a593Smuzhiyun return !(pte_val(pte) & _PAGE_RO);
100*4882a593Smuzhiyun }
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun #define pte_write pte_write
103*4882a593Smuzhiyun
pte_mkwrite(pte_t pte)104*4882a593Smuzhiyun static inline pte_t pte_mkwrite(pte_t pte)
105*4882a593Smuzhiyun {
106*4882a593Smuzhiyun return __pte(pte_val(pte) & ~_PAGE_RO);
107*4882a593Smuzhiyun }
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun #define pte_mkwrite pte_mkwrite
110*4882a593Smuzhiyun
pte_user(pte_t pte)111*4882a593Smuzhiyun static inline bool pte_user(pte_t pte)
112*4882a593Smuzhiyun {
113*4882a593Smuzhiyun return !(pte_val(pte) & _PAGE_SH);
114*4882a593Smuzhiyun }
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun #define pte_user pte_user
117*4882a593Smuzhiyun
pte_mkprivileged(pte_t pte)118*4882a593Smuzhiyun static inline pte_t pte_mkprivileged(pte_t pte)
119*4882a593Smuzhiyun {
120*4882a593Smuzhiyun return __pte(pte_val(pte) | _PAGE_SH);
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun #define pte_mkprivileged pte_mkprivileged
124*4882a593Smuzhiyun
pte_mkuser(pte_t pte)125*4882a593Smuzhiyun static inline pte_t pte_mkuser(pte_t pte)
126*4882a593Smuzhiyun {
127*4882a593Smuzhiyun return __pte(pte_val(pte) & ~_PAGE_SH);
128*4882a593Smuzhiyun }
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun #define pte_mkuser pte_mkuser
131*4882a593Smuzhiyun
pte_mkhuge(pte_t pte)132*4882a593Smuzhiyun static inline pte_t pte_mkhuge(pte_t pte)
133*4882a593Smuzhiyun {
134*4882a593Smuzhiyun return __pte(pte_val(pte) | _PAGE_SPS | _PAGE_HUGE);
135*4882a593Smuzhiyun }
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun #define pte_mkhuge pte_mkhuge
138*4882a593Smuzhiyun #endif
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun #endif /* __KERNEL__ */
141*4882a593Smuzhiyun #endif /* _ASM_POWERPC_NOHASH_32_PTE_8xx_H */
142