WIP FPC-III support
[linux/fpc-iii.git] / arch / riscv / include / asm / pgtable-64.h
blobf3b0da64c6c8f2c1d6c87373b336a9737d3fcfe0
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (C) 2012 Regents of the University of California
4 */
6 #ifndef _ASM_RISCV_PGTABLE_64_H
7 #define _ASM_RISCV_PGTABLE_64_H
9 #include <linux/const.h>
11 #define PGDIR_SHIFT 30
12 /* Size of region mapped by a page global directory */
13 #define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT)
14 #define PGDIR_MASK (~(PGDIR_SIZE - 1))
16 #define PMD_SHIFT 21
17 /* Size of region mapped by a page middle directory */
18 #define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
19 #define PMD_MASK (~(PMD_SIZE - 1))
21 /* Page Middle Directory entry */
22 typedef struct {
23 unsigned long pmd;
24 } pmd_t;
26 #define pmd_val(x) ((x).pmd)
27 #define __pmd(x) ((pmd_t) { (x) })
29 #define PTRS_PER_PMD (PAGE_SIZE / sizeof(pmd_t))
31 static inline int pud_present(pud_t pud)
33 return (pud_val(pud) & _PAGE_PRESENT);
36 static inline int pud_none(pud_t pud)
38 return (pud_val(pud) == 0);
41 static inline int pud_bad(pud_t pud)
43 return !pud_present(pud);
46 #define pud_leaf pud_leaf
47 static inline int pud_leaf(pud_t pud)
49 return pud_present(pud) &&
50 (pud_val(pud) & (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC));
53 static inline void set_pud(pud_t *pudp, pud_t pud)
55 *pudp = pud;
58 static inline void pud_clear(pud_t *pudp)
60 set_pud(pudp, __pud(0));
63 static inline unsigned long pud_page_vaddr(pud_t pud)
65 return (unsigned long)pfn_to_virt(pud_val(pud) >> _PAGE_PFN_SHIFT);
68 static inline struct page *pud_page(pud_t pud)
70 return pfn_to_page(pud_val(pud) >> _PAGE_PFN_SHIFT);
73 static inline pmd_t pfn_pmd(unsigned long pfn, pgprot_t prot)
75 return __pmd((pfn << _PAGE_PFN_SHIFT) | pgprot_val(prot));
78 static inline unsigned long _pmd_pfn(pmd_t pmd)
80 return pmd_val(pmd) >> _PAGE_PFN_SHIFT;
83 #define pmd_ERROR(e) \
84 pr_err("%s:%d: bad pmd %016lx.\n", __FILE__, __LINE__, pmd_val(e))
86 #endif /* _ASM_RISCV_PGTABLE_64_H */