1
2#ifndef _ASM_POWERPC_NOHASH_PGTABLE_H
3#define _ASM_POWERPC_NOHASH_PGTABLE_H
4
5#if defined(CONFIG_PPC64)
6#include <asm/nohash/64/pgtable.h>
7#else
8#include <asm/nohash/32/pgtable.h>
9#endif
10
11#ifndef __ASSEMBLY__
12
13
14static inline int pte_write(pte_t pte)
15{
16 return (pte_val(pte) & (_PAGE_RW | _PAGE_RO)) != _PAGE_RO;
17}
18static inline int pte_read(pte_t pte) { return 1; }
19static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; }
20static inline int pte_special(pte_t pte) { return pte_val(pte) & _PAGE_SPECIAL; }
21static inline int pte_none(pte_t pte) { return (pte_val(pte) & ~_PTE_NONE_MASK) == 0; }
22static inline pgprot_t pte_pgprot(pte_t pte) { return __pgprot(pte_val(pte) & PAGE_PROT_BITS); }
23
24#ifdef CONFIG_NUMA_BALANCING
25
26
27
28
29
30static inline int pte_protnone(pte_t pte)
31{
32 return (pte_val(pte) &
33 (_PAGE_PRESENT | _PAGE_USER)) == _PAGE_PRESENT;
34}
35
36static inline int pmd_protnone(pmd_t pmd)
37{
38 return pte_protnone(pmd_pte(pmd));
39}
40#endif
41
42static inline int pte_present(pte_t pte)
43{
44 return pte_val(pte) & _PAGE_PRESENT;
45}
46
47
48
49
50
51#define pte_access_permitted pte_access_permitted
52static inline bool pte_access_permitted(pte_t pte, bool write)
53{
54 unsigned long pteval = pte_val(pte);
55
56
57
58
59 unsigned long need_pte_bits = _PAGE_PRESENT | _PAGE_USER;
60
61 if (write)
62 need_pte_bits |= _PAGE_WRITE;
63
64 if ((pteval & need_pte_bits) != need_pte_bits)
65 return false;
66
67 return true;
68}
69
70
71
72
73
74
75
76static inline pte_t pfn_pte(unsigned long pfn, pgprot_t pgprot) {
77 return __pte(((pte_basic_t)(pfn) << PTE_RPN_SHIFT) |
78 pgprot_val(pgprot)); }
79static inline unsigned long pte_pfn(pte_t pte) {
80 return pte_val(pte) >> PTE_RPN_SHIFT; }
81
82
83static inline pte_t pte_wrprotect(pte_t pte)
84{
85 pte_basic_t ptev;
86
87 ptev = pte_val(pte) & ~(_PAGE_RW | _PAGE_HWWRITE);
88 ptev |= _PAGE_RO;
89 return __pte(ptev);
90}
91
92static inline pte_t pte_mkclean(pte_t pte)
93{
94 return __pte(pte_val(pte) & ~(_PAGE_DIRTY | _PAGE_HWWRITE));
95}
96
97static inline pte_t pte_mkold(pte_t pte)
98{
99 return __pte(pte_val(pte) & ~_PAGE_ACCESSED);
100}
101
102static inline pte_t pte_mkwrite(pte_t pte)
103{
104 pte_basic_t ptev;
105
106 ptev = pte_val(pte) & ~_PAGE_RO;
107 ptev |= _PAGE_RW;
108 return __pte(ptev);
109}
110
111static inline pte_t pte_mkdirty(pte_t pte)
112{
113 return __pte(pte_val(pte) | _PAGE_DIRTY);
114}
115
116static inline pte_t pte_mkyoung(pte_t pte)
117{
118 return __pte(pte_val(pte) | _PAGE_ACCESSED);
119}
120
121static inline pte_t pte_mkspecial(pte_t pte)
122{
123 return __pte(pte_val(pte) | _PAGE_SPECIAL);
124}
125
126static inline pte_t pte_mkhuge(pte_t pte)
127{
128 return __pte(pte_val(pte) | _PAGE_HUGE);
129}
130
131static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
132{
133 return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
134}
135
136
137
138
139extern void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
140 pte_t pte);
141
142
143
144
145
146
147static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,
148 pte_t *ptep, pte_t pte, int percpu)
149{
150
151
152
153
154
155 if (IS_ENABLED(CONFIG_PPC32) && IS_ENABLED(CONFIG_PTE_64BIT) && !percpu) {
156 __asm__ __volatile__("\
157 stw%U0%X0 %2,%0\n\
158 eieio\n\
159 stw%U0%X0 %L2,%1"
160 : "=m" (*ptep), "=m" (*((unsigned char *)ptep+4))
161 : "r" (pte) : "memory");
162 return;
163 }
164
165
166
167 *ptep = pte;
168
169
170
171
172
173
174
175 if (IS_ENABLED(CONFIG_PPC_BOOK3E_64) && is_kernel_addr(addr))
176 mb();
177}
178
179
180#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
181extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
182 pte_t *ptep, pte_t entry, int dirty);
183
184
185
186
187
188#define _PAGE_CACHE_CTL (_PAGE_COHERENT | _PAGE_GUARDED | _PAGE_NO_CACHE | \
189 _PAGE_WRITETHRU)
190
191#define pgprot_noncached(prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \
192 _PAGE_NO_CACHE | _PAGE_GUARDED))
193
194#define pgprot_noncached_wc(prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \
195 _PAGE_NO_CACHE))
196
197#define pgprot_cached(prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \
198 _PAGE_COHERENT))
199
200#if _PAGE_WRITETHRU != 0
201#define pgprot_cached_wthru(prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \
202 _PAGE_COHERENT | _PAGE_WRITETHRU))
203#else
204#define pgprot_cached_wthru(prot) pgprot_noncached(prot)
205#endif
206
207#define pgprot_cached_noncoherent(prot) \
208 (__pgprot(pgprot_val(prot) & ~_PAGE_CACHE_CTL))
209
210#define pgprot_writecombine pgprot_noncached_wc
211
212struct file;
213extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
214 unsigned long size, pgprot_t vma_prot);
215#define __HAVE_PHYS_MEM_ACCESS_PROT
216
217#ifdef CONFIG_HUGETLB_PAGE
218static inline int hugepd_ok(hugepd_t hpd)
219{
220#ifdef CONFIG_PPC_8xx
221 return ((hpd_val(hpd) & 0x4) != 0);
222#else
223
224 return (hpd_val(hpd) && (hpd_val(hpd) & PD_HUGE) == 0);
225#endif
226}
227
228static inline int pmd_huge(pmd_t pmd)
229{
230 return 0;
231}
232
233static inline int pud_huge(pud_t pud)
234{
235 return 0;
236}
237
238static inline int pgd_huge(pgd_t pgd)
239{
240 return 0;
241}
242#define pgd_huge pgd_huge
243
244#define is_hugepd(hpd) (hugepd_ok(hpd))
245#endif
246
247
248
249
250
251
252
253#if defined(CONFIG_PPC_FSL_BOOK3E) && defined(CONFIG_HUGETLB_PAGE)
254void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep);
255#else
256static inline
257void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) {}
258#endif
259
260#endif
261#endif
262