powerpc/mm: Don't use pte_val as lvalue
[cascardo/linux.git] / arch / powerpc / include / asm / book3s / pgtable.h
1 #ifndef _ASM_POWERPC_BOOK3S_PGTABLE_H
2 #define _ASM_POWERPC_BOOK3S_PGTABLE_H
3
4 #ifdef CONFIG_PPC64
5 #include <asm/book3s/64/pgtable.h>
6 #else
7 #include <asm/book3s/32/pgtable.h>
8 #endif
9
10 #define FIRST_USER_ADDRESS      0UL
11 #ifndef __ASSEMBLY__
12
13 /* Generic accessors to PTE bits */
14 static inline int pte_write(pte_t pte)          { return !!(pte_val(pte) & _PAGE_RW);}
15 static inline int pte_dirty(pte_t pte)          { return !!(pte_val(pte) & _PAGE_DIRTY); }
16 static inline int pte_young(pte_t pte)          { return !!(pte_val(pte) & _PAGE_ACCESSED); }
17 static inline int pte_special(pte_t pte)        { return !!(pte_val(pte) & _PAGE_SPECIAL); }
18 static inline int pte_none(pte_t pte)           { return (pte_val(pte) & ~_PTE_NONE_MASK) == 0; }
19 static inline pgprot_t pte_pgprot(pte_t pte)    { return __pgprot(pte_val(pte) & PAGE_PROT_BITS); }
20
21 #ifdef CONFIG_NUMA_BALANCING
22 /*
23  * These work without NUMA balancing but the kernel does not care. See the
24  * comment in include/asm-generic/pgtable.h . On powerpc, this will only
25  * work for user pages and always return true for kernel pages.
26  */
27 static inline int pte_protnone(pte_t pte)
28 {
29         return (pte_val(pte) &
30                 (_PAGE_PRESENT | _PAGE_USER)) == _PAGE_PRESENT;
31 }
32
33 static inline int pmd_protnone(pmd_t pmd)
34 {
35         return pte_protnone(pmd_pte(pmd));
36 }
37 #endif /* CONFIG_NUMA_BALANCING */
38
39 static inline int pte_present(pte_t pte)
40 {
41         return pte_val(pte) & _PAGE_PRESENT;
42 }
43
44 /* Conversion functions: convert a page and protection to a page entry,
45  * and a page entry and page directory to the page they refer to.
46  *
47  * Even if PTEs can be unsigned long long, a PFN is always an unsigned
48  * long for now.
49  */
50 static inline pte_t pfn_pte(unsigned long pfn, pgprot_t pgprot)
51 {
52         return __pte(((pte_basic_t)(pfn) << PTE_RPN_SHIFT) |
53                      pgprot_val(pgprot));
54 }
55
56 static inline unsigned long pte_pfn(pte_t pte)
57 {
58         return pte_val(pte) >> PTE_RPN_SHIFT;
59 }
60
61 /* Generic modifiers for PTE bits */
62 static inline pte_t pte_wrprotect(pte_t pte)
63 {
64         return __pte(pte_val(pte) & ~_PAGE_RW);
65 }
66
67 static inline pte_t pte_mkclean(pte_t pte)
68 {
69         return __pte(pte_val(pte) & ~_PAGE_DIRTY);
70 }
71
72 static inline pte_t pte_mkold(pte_t pte)
73 {
74         return __pte(pte_val(pte) & ~_PAGE_ACCESSED);
75 }
76
77 static inline pte_t pte_mkwrite(pte_t pte)
78 {
79         return __pte(pte_val(pte) | _PAGE_RW);
80 }
81
82 static inline pte_t pte_mkdirty(pte_t pte)
83 {
84         return __pte(pte_val(pte) | _PAGE_DIRTY);
85 }
86
87 static inline pte_t pte_mkyoung(pte_t pte)
88 {
89         return __pte(pte_val(pte) | _PAGE_ACCESSED);
90 }
91
92 static inline pte_t pte_mkspecial(pte_t pte)
93 {
94         return __pte(pte_val(pte) | _PAGE_SPECIAL);
95 }
96
97 static inline pte_t pte_mkhuge(pte_t pte)
98 {
99         return pte;
100 }
101
102 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
103 {
104         return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
105 }
106
107
108 /* Insert a PTE, top-level function is out of line. It uses an inline
109  * low level function in the respective pgtable-* files
110  */
111 extern void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
112                        pte_t pte);
113
114 /* This low level function performs the actual PTE insertion
115  * Setting the PTE depends on the MMU type and other factors. It's
116  * an horrible mess that I'm not going to try to clean up now but
117  * I'm keeping it in one place rather than spread around
118  */
119 static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,
120                                 pte_t *ptep, pte_t pte, int percpu)
121 {
122 #if defined(CONFIG_PPC_STD_MMU_32) && defined(CONFIG_SMP) && !defined(CONFIG_PTE_64BIT)
123         /* First case is 32-bit Hash MMU in SMP mode with 32-bit PTEs. We use the
124          * helper pte_update() which does an atomic update. We need to do that
125          * because a concurrent invalidation can clear _PAGE_HASHPTE. If it's a
126          * per-CPU PTE such as a kmap_atomic, we do a simple update preserving
127          * the hash bits instead (ie, same as the non-SMP case)
128          */
129         if (percpu)
130                 *ptep = __pte((pte_val(*ptep) & _PAGE_HASHPTE)
131                               | (pte_val(pte) & ~_PAGE_HASHPTE));
132         else
133                 pte_update(ptep, ~_PAGE_HASHPTE, pte_val(pte));
134
135 #elif defined(CONFIG_PPC32) && defined(CONFIG_PTE_64BIT)
136         /* Second case is 32-bit with 64-bit PTE.  In this case, we
137          * can just store as long as we do the two halves in the right order
138          * with a barrier in between. This is possible because we take care,
139          * in the hash code, to pre-invalidate if the PTE was already hashed,
140          * which synchronizes us with any concurrent invalidation.
141          * In the percpu case, we also fallback to the simple update preserving
142          * the hash bits
143          */
144         if (percpu) {
145                 *ptep = __pte((pte_val(*ptep) & _PAGE_HASHPTE)
146                               | (pte_val(pte) & ~_PAGE_HASHPTE));
147                 return;
148         }
149         if (pte_val(*ptep) & _PAGE_HASHPTE)
150                 flush_hash_entry(mm, ptep, addr);
151         __asm__ __volatile__("\
152                 stw%U0%X0 %2,%0\n\
153                 eieio\n\
154                 stw%U0%X0 %L2,%1"
155         : "=m" (*ptep), "=m" (*((unsigned char *)ptep+4))
156         : "r" (pte) : "memory");
157
158 #elif defined(CONFIG_PPC_STD_MMU_32)
159         /* Third case is 32-bit hash table in UP mode, we need to preserve
160          * the _PAGE_HASHPTE bit since we may not have invalidated the previous
161          * translation in the hash yet (done in a subsequent flush_tlb_xxx())
162          * and see we need to keep track that this PTE needs invalidating
163          */
164         *ptep = __pte((pte_val(*ptep) & _PAGE_HASHPTE)
165                       | (pte_val(pte) & ~_PAGE_HASHPTE));
166
167 #else
168         /* Anything else just stores the PTE normally. That covers all 64-bit
169          * cases, and 32-bit non-hash with 32-bit PTEs.
170          */
171         *ptep = pte;
172 #endif
173 }
174
175
176 #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
177 extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
178                                  pte_t *ptep, pte_t entry, int dirty);
179
180 /*
181  * Macro to mark a page protection value as "uncacheable".
182  */
183
184 #define _PAGE_CACHE_CTL (_PAGE_COHERENT | _PAGE_GUARDED | _PAGE_NO_CACHE | \
185                          _PAGE_WRITETHRU)
186
187 #define pgprot_noncached pgprot_noncached
188 static inline pgprot_t pgprot_noncached(pgprot_t prot)
189 {
190         return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) |
191                         _PAGE_NO_CACHE | _PAGE_GUARDED);
192 }
193
194 #define pgprot_noncached_wc pgprot_noncached_wc
195 static inline pgprot_t pgprot_noncached_wc(pgprot_t prot)
196 {
197         return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) |
198                         _PAGE_NO_CACHE);
199 }
200
201 #define pgprot_cached pgprot_cached
202 static inline pgprot_t pgprot_cached(pgprot_t prot)
203 {
204         return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) |
205                         _PAGE_COHERENT);
206 }
207
208 #define pgprot_cached_wthru pgprot_cached_wthru
209 static inline pgprot_t pgprot_cached_wthru(pgprot_t prot)
210 {
211         return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) |
212                         _PAGE_COHERENT | _PAGE_WRITETHRU);
213 }
214
215 #define pgprot_cached_noncoherent pgprot_cached_noncoherent
216 static inline pgprot_t pgprot_cached_noncoherent(pgprot_t prot)
217 {
218         return __pgprot(pgprot_val(prot) & ~_PAGE_CACHE_CTL);
219 }
220
221 #define pgprot_writecombine pgprot_writecombine
222 static inline pgprot_t pgprot_writecombine(pgprot_t prot)
223 {
224         return pgprot_noncached_wc(prot);
225 }
226
227 struct file;
228 extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
229                                      unsigned long size, pgprot_t vma_prot);
230 #define __HAVE_PHYS_MEM_ACCESS_PROT
231
232 #endif /* __ASSEMBLY__ */
233 #endif