1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright 2003 PathScale Inc
4 * Derived from include/asm-i386/pgtable.h
7 #ifndef __UM_PGTABLE_4LEVEL_H
8 #define __UM_PGTABLE_4LEVEL_H
10 #include <asm-generic/pgtable-nop4d.h>
12 /* PGDIR_SHIFT determines what a fourth-level page table entry can map */
14 #define PGDIR_SHIFT 39
15 #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
16 #define PGDIR_MASK (~(PGDIR_SIZE-1))
18 /* PUD_SHIFT determines the size of the area a third-level page table can
23 #define PUD_SIZE (1UL << PUD_SHIFT)
24 #define PUD_MASK (~(PUD_SIZE-1))
26 /* PMD_SHIFT determines the size of the area a second-level page table can
31 #define PMD_SIZE (1UL << PMD_SHIFT)
32 #define PMD_MASK (~(PMD_SIZE-1))
35 * entries per page directory level
38 #define PTRS_PER_PTE 512
39 #define PTRS_PER_PMD 512
40 #define PTRS_PER_PUD 512
41 #define PTRS_PER_PGD 512
43 #define USER_PTRS_PER_PGD ((TASK_SIZE + (PGDIR_SIZE - 1)) / PGDIR_SIZE)
45 #define pte_ERROR(e) \
46 printk("%s:%d: bad pte %p(%016lx).\n", __FILE__, __LINE__, &(e), \
48 #define pmd_ERROR(e) \
49 printk("%s:%d: bad pmd %p(%016lx).\n", __FILE__, __LINE__, &(e), \
51 #define pud_ERROR(e) \
52 printk("%s:%d: bad pud %p(%016lx).\n", __FILE__, __LINE__, &(e), \
54 #define pgd_ERROR(e) \
55 printk("%s:%d: bad pgd %p(%016lx).\n", __FILE__, __LINE__, &(e), \
58 #define pud_none(x) (!(pud_val(x) & ~_PAGE_NEEDSYNC))
59 #define pud_bad(x) ((pud_val(x) & (~PAGE_MASK & ~_PAGE_USER)) != _KERNPG_TABLE)
60 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
61 #define pud_populate(mm, pud, pmd) \
62 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
64 #define set_pud(pudptr, pudval) (*(pudptr) = (pudval))
66 #define p4d_none(x) (!(p4d_val(x) & ~_PAGE_NEEDSYNC))
67 #define p4d_bad(x) ((p4d_val(x) & (~PAGE_MASK & ~_PAGE_USER)) != _KERNPG_TABLE)
68 #define p4d_present(x) (p4d_val(x) & _PAGE_PRESENT)
69 #define p4d_populate(mm, p4d, pud) \
70 set_p4d(p4d, __p4d(_PAGE_TABLE + __pa(pud)))
72 #define set_p4d(p4dptr, p4dval) (*(p4dptr) = (p4dval))
75 static inline int pgd_needsync(pgd_t pgd)
77 return pgd_val(pgd) & _PAGE_NEEDSYNC;
80 static inline void pgd_mkuptodate(pgd_t pgd) { pgd_val(pgd) &= ~_PAGE_NEEDSYNC; }
82 #define set_pmd(pmdptr, pmdval) (*(pmdptr) = (pmdval))
84 static inline void pud_clear (pud_t *pud)
86 set_pud(pud, __pud(_PAGE_NEEDSYNC));
89 static inline void p4d_clear (p4d_t *p4d)
91 set_p4d(p4d, __p4d(_PAGE_NEEDSYNC));
94 #define pud_page(pud) phys_to_page(pud_val(pud) & PAGE_MASK)
95 #define pud_pgtable(pud) ((pmd_t *) __va(pud_val(pud) & PAGE_MASK))
97 #define p4d_page(p4d) phys_to_page(p4d_val(p4d) & PAGE_MASK)
98 #define p4d_pgtable(p4d) ((pud_t *) __va(p4d_val(p4d) & PAGE_MASK))
100 static inline unsigned long pte_pfn(pte_t pte)
102 return phys_to_pfn(pte_val(pte));
105 static inline pte_t pfn_pte(unsigned long page_nr, pgprot_t pgprot)
108 phys_t phys = pfn_to_phys(page_nr);
110 pte_set_val(pte, phys, pgprot);
114 static inline pmd_t pfn_pmd(unsigned long page_nr, pgprot_t pgprot)
116 return __pmd((page_nr << PAGE_SHIFT) | pgprot_val(pgprot));