xref: /OK3568_Linux_fs/kernel/arch/powerpc/include/asm/pgtable.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _ASM_POWERPC_PGTABLE_H
3*4882a593Smuzhiyun #define _ASM_POWERPC_PGTABLE_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun #ifndef __ASSEMBLY__
6*4882a593Smuzhiyun #include <linux/mmdebug.h>
7*4882a593Smuzhiyun #include <linux/mmzone.h>
8*4882a593Smuzhiyun #include <asm/processor.h>		/* For TASK_SIZE */
9*4882a593Smuzhiyun #include <asm/mmu.h>
10*4882a593Smuzhiyun #include <asm/page.h>
11*4882a593Smuzhiyun #include <asm/tlbflush.h>
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun struct mm_struct;
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #endif /* !__ASSEMBLY__ */
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #ifdef CONFIG_PPC_BOOK3S
18*4882a593Smuzhiyun #include <asm/book3s/pgtable.h>
19*4882a593Smuzhiyun #else
20*4882a593Smuzhiyun #include <asm/nohash/pgtable.h>
21*4882a593Smuzhiyun #endif /* !CONFIG_PPC_BOOK3S */
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun /* Note due to the way vm flags are laid out, the bits are XWR */
24*4882a593Smuzhiyun #define __P000	PAGE_NONE
25*4882a593Smuzhiyun #define __P001	PAGE_READONLY
26*4882a593Smuzhiyun #define __P010	PAGE_COPY
27*4882a593Smuzhiyun #define __P011	PAGE_COPY
28*4882a593Smuzhiyun #define __P100	PAGE_READONLY_X
29*4882a593Smuzhiyun #define __P101	PAGE_READONLY_X
30*4882a593Smuzhiyun #define __P110	PAGE_COPY_X
31*4882a593Smuzhiyun #define __P111	PAGE_COPY_X
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun #define __S000	PAGE_NONE
34*4882a593Smuzhiyun #define __S001	PAGE_READONLY
35*4882a593Smuzhiyun #define __S010	PAGE_SHARED
36*4882a593Smuzhiyun #define __S011	PAGE_SHARED
37*4882a593Smuzhiyun #define __S100	PAGE_READONLY_X
38*4882a593Smuzhiyun #define __S101	PAGE_READONLY_X
39*4882a593Smuzhiyun #define __S110	PAGE_SHARED_X
40*4882a593Smuzhiyun #define __S111	PAGE_SHARED_X
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun #ifndef __ASSEMBLY__
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun #include <asm/tlbflush.h>
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun /* Keep these as a macros to avoid include dependency mess */
47*4882a593Smuzhiyun #define pte_page(x)		pfn_to_page(pte_pfn(x))
48*4882a593Smuzhiyun #define mk_pte(page, pgprot)	pfn_pte(page_to_pfn(page), (pgprot))
49*4882a593Smuzhiyun /*
50*4882a593Smuzhiyun  * Select all bits except the pfn
51*4882a593Smuzhiyun  */
pte_pgprot(pte_t pte)52*4882a593Smuzhiyun static inline pgprot_t pte_pgprot(pte_t pte)
53*4882a593Smuzhiyun {
54*4882a593Smuzhiyun 	unsigned long pte_flags;
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun 	pte_flags = pte_val(pte) & ~PTE_RPN_MASK;
57*4882a593Smuzhiyun 	return __pgprot(pte_flags);
58*4882a593Smuzhiyun }
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun #ifndef pmd_page_vaddr
pmd_page_vaddr(pmd_t pmd)61*4882a593Smuzhiyun static inline unsigned long pmd_page_vaddr(pmd_t pmd)
62*4882a593Smuzhiyun {
63*4882a593Smuzhiyun 	return ((unsigned long)__va(pmd_val(pmd) & ~PMD_MASKED_BITS));
64*4882a593Smuzhiyun }
65*4882a593Smuzhiyun #define pmd_page_vaddr pmd_page_vaddr
66*4882a593Smuzhiyun #endif
67*4882a593Smuzhiyun /*
68*4882a593Smuzhiyun  * ZERO_PAGE is a global shared page that is always zero: used
69*4882a593Smuzhiyun  * for zero-mapped memory areas etc..
70*4882a593Smuzhiyun  */
71*4882a593Smuzhiyun extern unsigned long empty_zero_page[];
72*4882a593Smuzhiyun #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun extern pgd_t swapper_pg_dir[];
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun extern void paging_init(void);
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun extern unsigned long ioremap_bot;
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun /*
81*4882a593Smuzhiyun  * kern_addr_valid is intended to indicate whether an address is a valid
82*4882a593Smuzhiyun  * kernel address.  Most 32-bit archs define it as always true (like this)
83*4882a593Smuzhiyun  * but most 64-bit archs actually perform a test.  What should we do here?
84*4882a593Smuzhiyun  */
85*4882a593Smuzhiyun #define kern_addr_valid(addr)	(1)
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun #ifndef CONFIG_TRANSPARENT_HUGEPAGE
88*4882a593Smuzhiyun #define pmd_large(pmd)		0
89*4882a593Smuzhiyun #endif
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun /* can we use this in kvm */
92*4882a593Smuzhiyun unsigned long vmalloc_to_phys(void *vmalloc_addr);
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun void pgtable_cache_add(unsigned int shift);
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun pte_t *early_pte_alloc_kernel(pmd_t *pmdp, unsigned long va);
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun #if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_PPC32)
99*4882a593Smuzhiyun void mark_initmem_nx(void);
100*4882a593Smuzhiyun #else
mark_initmem_nx(void)101*4882a593Smuzhiyun static inline void mark_initmem_nx(void) { }
102*4882a593Smuzhiyun #endif
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun /*
105*4882a593Smuzhiyun  * When used, PTE_FRAG_NR is defined in subarch pgtable.h
106*4882a593Smuzhiyun  * so we are sure it is included when arriving here.
107*4882a593Smuzhiyun  */
108*4882a593Smuzhiyun #ifdef PTE_FRAG_NR
pte_frag_get(mm_context_t * ctx)109*4882a593Smuzhiyun static inline void *pte_frag_get(mm_context_t *ctx)
110*4882a593Smuzhiyun {
111*4882a593Smuzhiyun 	return ctx->pte_frag;
112*4882a593Smuzhiyun }
113*4882a593Smuzhiyun 
pte_frag_set(mm_context_t * ctx,void * p)114*4882a593Smuzhiyun static inline void pte_frag_set(mm_context_t *ctx, void *p)
115*4882a593Smuzhiyun {
116*4882a593Smuzhiyun 	ctx->pte_frag = p;
117*4882a593Smuzhiyun }
118*4882a593Smuzhiyun #else
119*4882a593Smuzhiyun #define PTE_FRAG_NR		1
120*4882a593Smuzhiyun #define PTE_FRAG_SIZE_SHIFT	PAGE_SHIFT
121*4882a593Smuzhiyun #define PTE_FRAG_SIZE		(1UL << PTE_FRAG_SIZE_SHIFT)
122*4882a593Smuzhiyun 
pte_frag_get(mm_context_t * ctx)123*4882a593Smuzhiyun static inline void *pte_frag_get(mm_context_t *ctx)
124*4882a593Smuzhiyun {
125*4882a593Smuzhiyun 	return NULL;
126*4882a593Smuzhiyun }
127*4882a593Smuzhiyun 
pte_frag_set(mm_context_t * ctx,void * p)128*4882a593Smuzhiyun static inline void pte_frag_set(mm_context_t *ctx, void *p)
129*4882a593Smuzhiyun {
130*4882a593Smuzhiyun }
131*4882a593Smuzhiyun #endif
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun #ifndef pmd_is_leaf
134*4882a593Smuzhiyun #define pmd_is_leaf pmd_is_leaf
pmd_is_leaf(pmd_t pmd)135*4882a593Smuzhiyun static inline bool pmd_is_leaf(pmd_t pmd)
136*4882a593Smuzhiyun {
137*4882a593Smuzhiyun 	return false;
138*4882a593Smuzhiyun }
139*4882a593Smuzhiyun #endif
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun #ifndef pud_is_leaf
142*4882a593Smuzhiyun #define pud_is_leaf pud_is_leaf
pud_is_leaf(pud_t pud)143*4882a593Smuzhiyun static inline bool pud_is_leaf(pud_t pud)
144*4882a593Smuzhiyun {
145*4882a593Smuzhiyun 	return false;
146*4882a593Smuzhiyun }
147*4882a593Smuzhiyun #endif
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun #ifndef p4d_is_leaf
150*4882a593Smuzhiyun #define p4d_is_leaf p4d_is_leaf
p4d_is_leaf(p4d_t p4d)151*4882a593Smuzhiyun static inline bool p4d_is_leaf(p4d_t p4d)
152*4882a593Smuzhiyun {
153*4882a593Smuzhiyun 	return false;
154*4882a593Smuzhiyun }
155*4882a593Smuzhiyun #endif
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun #ifdef CONFIG_PPC64
158*4882a593Smuzhiyun #define is_ioremap_addr is_ioremap_addr
is_ioremap_addr(const void * x)159*4882a593Smuzhiyun static inline bool is_ioremap_addr(const void *x)
160*4882a593Smuzhiyun {
161*4882a593Smuzhiyun 	unsigned long addr = (unsigned long)x;
162*4882a593Smuzhiyun 
163*4882a593Smuzhiyun 	return addr >= IOREMAP_BASE && addr < IOREMAP_END;
164*4882a593Smuzhiyun }
165*4882a593Smuzhiyun #endif /* CONFIG_PPC64 */
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun #endif /* __ASSEMBLY__ */
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun #endif /* _ASM_POWERPC_PGTABLE_H */
170