1
2#ifndef _ASM_POWERPC_BOOK3S_32_PGTABLE_H
3#define _ASM_POWERPC_BOOK3S_32_PGTABLE_H
4
5#define __ARCH_USE_5LEVEL_HACK
6#include <asm-generic/pgtable-nopmd.h>
7
8#include <asm/book3s/32/hash.h>
9
10
11
12#define _PAGE_KERNEL_RO 0
13#define _PAGE_KERNEL_ROX (_PAGE_EXEC)
14#define _PAGE_KERNEL_RW (_PAGE_DIRTY | _PAGE_RW)
15#define _PAGE_KERNEL_RWX (_PAGE_DIRTY | _PAGE_RW | _PAGE_EXEC)
16
17#define _PAGE_HPTEFLAGS _PAGE_HASHPTE
18
19#ifndef __ASSEMBLY__
20
21static inline bool pte_user(pte_t pte)
22{
23 return pte_val(pte) & _PAGE_USER;
24}
25#endif
26
27
28
29
30
31
32#define PTE_RPN_SHIFT (PAGE_SHIFT)
33
34
35
36
37
38#ifdef CONFIG_PTE_64BIT
39#define PTE_RPN_MASK (~((1ULL << PTE_RPN_SHIFT) - 1))
40#else
41#define PTE_RPN_MASK (~((1UL << PTE_RPN_SHIFT) - 1))
42#endif
43
44
45
46
47
48#define _PAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HASHPTE | _PAGE_DIRTY | \
49 _PAGE_ACCESSED | _PAGE_SPECIAL)
50
51
52
53
54
55
56
57#define _PAGE_BASE_NC (_PAGE_PRESENT | _PAGE_ACCESSED)
58#define _PAGE_BASE (_PAGE_BASE_NC | _PAGE_COHERENT)
59
60
61
62
63
64
65
66
67#define PAGE_NONE __pgprot(_PAGE_BASE)
68#define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW)
69#define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | _PAGE_EXEC)
70#define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER)
71#define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
72#define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER)
73#define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
74
75
76#define PAGE_KERNEL __pgprot(_PAGE_BASE | _PAGE_KERNEL_RW)
77#define PAGE_KERNEL_NC __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | _PAGE_NO_CACHE)
78#define PAGE_KERNEL_NCG __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \
79 _PAGE_NO_CACHE | _PAGE_GUARDED)
80#define PAGE_KERNEL_X __pgprot(_PAGE_BASE | _PAGE_KERNEL_RWX)
81#define PAGE_KERNEL_RO __pgprot(_PAGE_BASE | _PAGE_KERNEL_RO)
82#define PAGE_KERNEL_ROX __pgprot(_PAGE_BASE | _PAGE_KERNEL_ROX)
83
84
85
86
87
88
89#if defined(CONFIG_KGDB) || defined(CONFIG_XMON) || defined(CONFIG_BDI_SWITCH) ||\
90 defined(CONFIG_KPROBES) || defined(CONFIG_DYNAMIC_FTRACE)
91#define PAGE_KERNEL_TEXT PAGE_KERNEL_X
92#else
93#define PAGE_KERNEL_TEXT PAGE_KERNEL_ROX
94#endif
95
96
97#define PAGE_KERNEL_EXEC PAGE_KERNEL_X
98
99
100#define PAGE_AGP (PAGE_KERNEL_NC)
101#define HAVE_PAGE_AGP
102
103#define PTE_INDEX_SIZE PTE_SHIFT
104#define PMD_INDEX_SIZE 0
105#define PUD_INDEX_SIZE 0
106#define PGD_INDEX_SIZE (32 - PGDIR_SHIFT)
107
108#define PMD_CACHE_INDEX PMD_INDEX_SIZE
109#define PUD_CACHE_INDEX PUD_INDEX_SIZE
110
111#ifndef __ASSEMBLY__
112#define PTE_TABLE_SIZE (sizeof(pte_t) << PTE_INDEX_SIZE)
113#define PMD_TABLE_SIZE 0
114#define PUD_TABLE_SIZE 0
115#define PGD_TABLE_SIZE (sizeof(pgd_t) << PGD_INDEX_SIZE)
116#endif
117
118#define PTRS_PER_PTE (1 << PTE_INDEX_SIZE)
119#define PTRS_PER_PGD (1 << PGD_INDEX_SIZE)
120
121
122
123
124
125
126
127
128
129
130
131
132#define PGDIR_SHIFT (PAGE_SHIFT + PTE_INDEX_SIZE)
133#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
134#define PGDIR_MASK (~(PGDIR_SIZE-1))
135
136#define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE)
137
138
139
140
141
142#ifdef CONFIG_HIGHMEM
143#define KVIRT_TOP PKMAP_BASE
144#else
145#define KVIRT_TOP (0xfe000000UL)
146#endif
147
148
149
150
151
152
153#ifdef CONFIG_NOT_COHERENT_CACHE
154#define IOREMAP_TOP ((KVIRT_TOP - CONFIG_CONSISTENT_SIZE) & PAGE_MASK)
155#else
156#define IOREMAP_TOP KVIRT_TOP
157#endif
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176#define VMALLOC_OFFSET (0x1000000)
177
178
179
180
181
182
183#if defined(CONFIG_STRICT_KERNEL_RWX) && defined(CONFIG_MODULES)
184#define VMALLOC_START ((_ALIGN((long)high_memory, 256L << 20) + VMALLOC_OFFSET) & \
185 ~(VMALLOC_OFFSET - 1))
186#else
187#define VMALLOC_START ((((long)high_memory + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1)))
188#endif
189#define VMALLOC_END ioremap_bot
190
191#ifndef __ASSEMBLY__
192#include <linux/sched.h>
193#include <linux/threads.h>
194
195extern unsigned long ioremap_bot;
196
197
198#define PGD_MASKED_BITS 0
199
200#define pte_ERROR(e) \
201 pr_err("%s:%d: bad pte %llx.\n", __FILE__, __LINE__, \
202 (unsigned long long)pte_val(e))
203#define pgd_ERROR(e) \
204 pr_err("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
205
206
207
208
209
210#define pte_clear(mm, addr, ptep) \
211 do { pte_update(ptep, ~_PAGE_HASHPTE, 0); } while (0)
212
213#define pmd_none(pmd) (!pmd_val(pmd))
214#define pmd_bad(pmd) (pmd_val(pmd) & _PMD_BAD)
215#define pmd_present(pmd) (pmd_val(pmd) & _PMD_PRESENT_MASK)
216static inline void pmd_clear(pmd_t *pmdp)
217{
218 *pmdp = __pmd(0);
219}
220
221
222
223
224
225
226extern int flush_hash_pages(unsigned context, unsigned long va,
227 unsigned long pmdval, int count);
228
229
230extern void add_hash_page(unsigned context, unsigned long va,
231 unsigned long pmdval);
232
233
234extern void flush_hash_entry(struct mm_struct *mm, pte_t *ptep,
235 unsigned long address);
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252#ifndef CONFIG_PTE_64BIT
253static inline unsigned long pte_update(pte_t *p,
254 unsigned long clr,
255 unsigned long set)
256{
257 unsigned long old, tmp;
258
259 __asm__ __volatile__("\
2601: lwarx %0,0,%3\n\
261 andc %1,%0,%4\n\
262 or %1,%1,%5\n"
263" stwcx. %1,0,%3\n\
264 bne- 1b"
265 : "=&r" (old), "=&r" (tmp), "=m" (*p)
266 : "r" (p), "r" (clr), "r" (set), "m" (*p)
267 : "cc" );
268
269 return old;
270}
271#else
272static inline unsigned long long pte_update(pte_t *p,
273 unsigned long clr,
274 unsigned long set)
275{
276 unsigned long long old;
277 unsigned long tmp;
278
279 __asm__ __volatile__("\
2801: lwarx %L0,0,%4\n\
281 lwzx %0,0,%3\n\
282 andc %1,%L0,%5\n\
283 or %1,%1,%6\n"
284" stwcx. %1,0,%4\n\
285 bne- 1b"
286 : "=&r" (old), "=&r" (tmp), "=m" (*p)
287 : "r" (p), "r" ((unsigned long)(p) + 4), "r" (clr), "r" (set), "m" (*p)
288 : "cc" );
289
290 return old;
291}
292#endif
293
294
295
296
297
298#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
299static inline int __ptep_test_and_clear_young(unsigned int context, unsigned long addr, pte_t *ptep)
300{
301 unsigned long old;
302 old = pte_update(ptep, _PAGE_ACCESSED, 0);
303 if (old & _PAGE_HASHPTE) {
304 unsigned long ptephys = __pa(ptep) & PAGE_MASK;
305 flush_hash_pages(context, addr, ptephys, 1);
306 }
307 return (old & _PAGE_ACCESSED) != 0;
308}
309#define ptep_test_and_clear_young(__vma, __addr, __ptep) \
310 __ptep_test_and_clear_young((__vma)->vm_mm->context.id, __addr, __ptep)
311
312#define __HAVE_ARCH_PTEP_GET_AND_CLEAR
313static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
314 pte_t *ptep)
315{
316 return __pte(pte_update(ptep, ~_PAGE_HASHPTE, 0));
317}
318
319#define __HAVE_ARCH_PTEP_SET_WRPROTECT
320static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,
321 pte_t *ptep)
322{
323 pte_update(ptep, _PAGE_RW, 0);
324}
325
326static inline void __ptep_set_access_flags(struct vm_area_struct *vma,
327 pte_t *ptep, pte_t entry,
328 unsigned long address,
329 int psize)
330{
331 unsigned long set = pte_val(entry) &
332 (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC);
333
334 pte_update(ptep, 0, set);
335
336 flush_tlb_page(vma, address);
337}
338
339#define __HAVE_ARCH_PTE_SAME
340#define pte_same(A,B) (((pte_val(A) ^ pte_val(B)) & ~_PAGE_HASHPTE) == 0)
341
342#define pmd_page_vaddr(pmd) \
343 ((unsigned long)__va(pmd_val(pmd) & ~(PTE_TABLE_SIZE - 1)))
344#define pmd_page(pmd) \
345 pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT)
346
347
348#define pgd_offset_k(address) pgd_offset(&init_mm, address)
349
350
351#define pgd_index(address) ((address) >> PGDIR_SHIFT)
352#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
353
354
355#define pte_index(address) \
356 (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
357#define pte_offset_kernel(dir, addr) \
358 ((pte_t *) pmd_page_vaddr(*(dir)) + pte_index(addr))
359#define pte_offset_map(dir, addr) \
360 ((pte_t *)(kmap_atomic(pmd_page(*(dir))) + \
361 (pmd_page_vaddr(*(dir)) & ~PAGE_MASK)) + pte_index(addr))
362#define pte_unmap(pte) kunmap_atomic(pte)
363
364
365
366
367
368
369
370#define __swp_type(entry) ((entry).val & 0x1f)
371#define __swp_offset(entry) ((entry).val >> 5)
372#define __swp_entry(type, offset) ((swp_entry_t) { (type) | ((offset) << 5) })
373#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> 3 })
374#define __swp_entry_to_pte(x) ((pte_t) { (x).val << 3 })
375
376int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot);
377
378
379static inline int pte_write(pte_t pte) { return !!(pte_val(pte) & _PAGE_RW);}
380static inline int pte_read(pte_t pte) { return 1; }
381static inline int pte_dirty(pte_t pte) { return !!(pte_val(pte) & _PAGE_DIRTY); }
382static inline int pte_young(pte_t pte) { return !!(pte_val(pte) & _PAGE_ACCESSED); }
383static inline int pte_special(pte_t pte) { return !!(pte_val(pte) & _PAGE_SPECIAL); }
384static inline int pte_none(pte_t pte) { return (pte_val(pte) & ~_PTE_NONE_MASK) == 0; }
385static inline bool pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_EXEC; }
386
387static inline int pte_present(pte_t pte)
388{
389 return pte_val(pte) & _PAGE_PRESENT;
390}
391
392static inline bool pte_hw_valid(pte_t pte)
393{
394 return pte_val(pte) & _PAGE_PRESENT;
395}
396
397static inline bool pte_hashpte(pte_t pte)
398{
399 return !!(pte_val(pte) & _PAGE_HASHPTE);
400}
401
402static inline bool pte_ci(pte_t pte)
403{
404 return !!(pte_val(pte) & _PAGE_NO_CACHE);
405}
406
407
408
409
410
411#define pte_access_permitted pte_access_permitted
412static inline bool pte_access_permitted(pte_t pte, bool write)
413{
414
415
416
417
418 if (!pte_present(pte) || !pte_user(pte) || !pte_read(pte))
419 return false;
420
421 if (write && !pte_write(pte))
422 return false;
423
424 return true;
425}
426
427
428
429
430
431
432
433static inline pte_t pfn_pte(unsigned long pfn, pgprot_t pgprot)
434{
435 return __pte(((pte_basic_t)(pfn) << PTE_RPN_SHIFT) |
436 pgprot_val(pgprot));
437}
438
439static inline unsigned long pte_pfn(pte_t pte)
440{
441 return pte_val(pte) >> PTE_RPN_SHIFT;
442}
443
444
445static inline pte_t pte_wrprotect(pte_t pte)
446{
447 return __pte(pte_val(pte) & ~_PAGE_RW);
448}
449
450static inline pte_t pte_exprotect(pte_t pte)
451{
452 return __pte(pte_val(pte) & ~_PAGE_EXEC);
453}
454
455static inline pte_t pte_mkclean(pte_t pte)
456{
457 return __pte(pte_val(pte) & ~_PAGE_DIRTY);
458}
459
460static inline pte_t pte_mkold(pte_t pte)
461{
462 return __pte(pte_val(pte) & ~_PAGE_ACCESSED);
463}
464
465static inline pte_t pte_mkexec(pte_t pte)
466{
467 return __pte(pte_val(pte) | _PAGE_EXEC);
468}
469
470static inline pte_t pte_mkpte(pte_t pte)
471{
472 return pte;
473}
474
475static inline pte_t pte_mkwrite(pte_t pte)
476{
477 return __pte(pte_val(pte) | _PAGE_RW);
478}
479
480static inline pte_t pte_mkdirty(pte_t pte)
481{
482 return __pte(pte_val(pte) | _PAGE_DIRTY);
483}
484
485static inline pte_t pte_mkyoung(pte_t pte)
486{
487 return __pte(pte_val(pte) | _PAGE_ACCESSED);
488}
489
490static inline pte_t pte_mkspecial(pte_t pte)
491{
492 return __pte(pte_val(pte) | _PAGE_SPECIAL);
493}
494
495static inline pte_t pte_mkhuge(pte_t pte)
496{
497 return pte;
498}
499
500static inline pte_t pte_mkprivileged(pte_t pte)
501{
502 return __pte(pte_val(pte) & ~_PAGE_USER);
503}
504
505static inline pte_t pte_mkuser(pte_t pte)
506{
507 return __pte(pte_val(pte) | _PAGE_USER);
508}
509
510static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
511{
512 return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
513}
514
515
516
517
518
519
520
521
522static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,
523 pte_t *ptep, pte_t pte, int percpu)
524{
525#if defined(CONFIG_SMP) && !defined(CONFIG_PTE_64BIT)
526
527
528
529
530
531
532 if (percpu)
533 *ptep = __pte((pte_val(*ptep) & _PAGE_HASHPTE)
534 | (pte_val(pte) & ~_PAGE_HASHPTE));
535 else
536 pte_update(ptep, ~_PAGE_HASHPTE, pte_val(pte));
537
538#elif defined(CONFIG_PTE_64BIT)
539
540
541
542
543
544
545
546
547 if (percpu) {
548 *ptep = __pte((pte_val(*ptep) & _PAGE_HASHPTE)
549 | (pte_val(pte) & ~_PAGE_HASHPTE));
550 return;
551 }
552 if (pte_val(*ptep) & _PAGE_HASHPTE)
553 flush_hash_entry(mm, ptep, addr);
554 __asm__ __volatile__("\
555 stw%U0%X0 %2,%0\n\
556 eieio\n\
557 stw%U0%X0 %L2,%1"
558 : "=m" (*ptep), "=m" (*((unsigned char *)ptep+4))
559 : "r" (pte) : "memory");
560
561#else
562
563
564
565
566
567 *ptep = __pte((pte_val(*ptep) & _PAGE_HASHPTE)
568 | (pte_val(pte) & ~_PAGE_HASHPTE));
569#endif
570}
571
572
573
574
575
576#define _PAGE_CACHE_CTL (_PAGE_COHERENT | _PAGE_GUARDED | _PAGE_NO_CACHE | \
577 _PAGE_WRITETHRU)
578
579#define pgprot_noncached pgprot_noncached
580static inline pgprot_t pgprot_noncached(pgprot_t prot)
581{
582 return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) |
583 _PAGE_NO_CACHE | _PAGE_GUARDED);
584}
585
586#define pgprot_noncached_wc pgprot_noncached_wc
587static inline pgprot_t pgprot_noncached_wc(pgprot_t prot)
588{
589 return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) |
590 _PAGE_NO_CACHE);
591}
592
593#define pgprot_cached pgprot_cached
594static inline pgprot_t pgprot_cached(pgprot_t prot)
595{
596 return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) |
597 _PAGE_COHERENT);
598}
599
600#define pgprot_cached_wthru pgprot_cached_wthru
601static inline pgprot_t pgprot_cached_wthru(pgprot_t prot)
602{
603 return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) |
604 _PAGE_COHERENT | _PAGE_WRITETHRU);
605}
606
607#define pgprot_cached_noncoherent pgprot_cached_noncoherent
608static inline pgprot_t pgprot_cached_noncoherent(pgprot_t prot)
609{
610 return __pgprot(pgprot_val(prot) & ~_PAGE_CACHE_CTL);
611}
612
613#define pgprot_writecombine pgprot_writecombine
614static inline pgprot_t pgprot_writecombine(pgprot_t prot)
615{
616 return pgprot_noncached_wc(prot);
617}
618
619#endif
620
621#endif
622