2 * Copyright (C) 2012 Regents of the University of California
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #ifndef _ASM_RISCV_PGTABLE_64_H
15 #define _ASM_RISCV_PGTABLE_64_H
17 #include <linux/const.h>
19 #define PGDIR_SHIFT 30
20 /* Size of region mapped by a page global directory */
21 #define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT)
22 #define PGDIR_MASK (~(PGDIR_SIZE - 1))
25 /* Size of region mapped by a page middle directory */
26 #define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
27 #define PMD_MASK (~(PMD_SIZE - 1))
29 /* Page Middle Directory entry */
34 #define pmd_val(x) ((x).pmd)
35 #define __pmd(x) ((pmd_t) { (x) })
37 #define PTRS_PER_PMD (PAGE_SIZE / sizeof(pmd_t))
39 static inline int pud_present(pud_t pud
)
41 return (pud_val(pud
) & _PAGE_PRESENT
);
44 static inline int pud_none(pud_t pud
)
46 return (pud_val(pud
) == 0);
49 static inline int pud_bad(pud_t pud
)
51 return !pud_present(pud
);
54 static inline void set_pud(pud_t
*pudp
, pud_t pud
)
59 static inline void pud_clear(pud_t
*pudp
)
61 set_pud(pudp
, __pud(0));
64 static inline unsigned long pud_page_vaddr(pud_t pud
)
66 return (unsigned long)pfn_to_virt(pud_val(pud
) >> _PAGE_PFN_SHIFT
);
69 #define pmd_index(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
71 static inline pmd_t
*pmd_offset(pud_t
*pud
, unsigned long addr
)
73 return (pmd_t
*)pud_page_vaddr(*pud
) + pmd_index(addr
);
76 static inline pmd_t
pfn_pmd(unsigned long pfn
, pgprot_t prot
)
78 return __pmd((pfn
<< _PAGE_PFN_SHIFT
) | pgprot_val(prot
));
81 #define pmd_ERROR(e) \
82 pr_err("%s:%d: bad pmd %016lx.\n", __FILE__, __LINE__, pmd_val(e))
84 #endif /* _ASM_RISCV_PGTABLE_64_H */