1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2e44d6c40SPaul Mundt #ifndef __ASM_SH_PGTABLE_3LEVEL_H 3e44d6c40SPaul Mundt #define __ASM_SH_PGTABLE_3LEVEL_H 4e44d6c40SPaul Mundt 5e44d6c40SPaul Mundt #include <asm-generic/pgtable-nopud.h> 6e44d6c40SPaul Mundt 7e44d6c40SPaul Mundt /* 8e44d6c40SPaul Mundt * Some cores need a 3-level page table layout, for example when using 9e44d6c40SPaul Mundt * 64-bit PTEs and 4K pages. 10e44d6c40SPaul Mundt */ 11e44d6c40SPaul Mundt #define PAGETABLE_LEVELS 3 12e44d6c40SPaul Mundt 13e44d6c40SPaul Mundt #define PTE_MAGNITUDE 3 /* 64-bit PTEs on SH-X2 TLB */ 14e44d6c40SPaul Mundt 15e44d6c40SPaul Mundt /* PGD bits */ 16e44d6c40SPaul Mundt #define PGDIR_SHIFT 30 17e44d6c40SPaul Mundt 18e44d6c40SPaul Mundt #define PTRS_PER_PGD 4 19e44d6c40SPaul Mundt #define USER_PTRS_PER_PGD 2 20e44d6c40SPaul Mundt 21e44d6c40SPaul Mundt /* PMD bits */ 22e44d6c40SPaul Mundt #define PMD_SHIFT (PAGE_SHIFT + (PAGE_SHIFT - PTE_MAGNITUDE)) 23e44d6c40SPaul Mundt #define PMD_SIZE (1UL << PMD_SHIFT) 24e44d6c40SPaul Mundt #define PMD_MASK (~(PMD_SIZE-1)) 25e44d6c40SPaul Mundt 26e44d6c40SPaul Mundt #define PTRS_PER_PMD ((1 << PGDIR_SHIFT) / PMD_SIZE) 27e44d6c40SPaul Mundt 28e44d6c40SPaul Mundt #define pmd_ERROR(e) \ 29e44d6c40SPaul Mundt printk("%s:%d: bad pmd %016llx.\n", __FILE__, __LINE__, pmd_val(e)) 30e44d6c40SPaul Mundt 31*526970beSPeter Zijlstra typedef union { 320862ff05SPeter Zijlstra struct { 330862ff05SPeter Zijlstra unsigned long pmd_low; 340862ff05SPeter Zijlstra unsigned long pmd_high; 350862ff05SPeter Zijlstra }; 360862ff05SPeter Zijlstra unsigned long long pmd; 370862ff05SPeter Zijlstra } pmd_t; 38e44d6c40SPaul Mundt #define pmd_val(x) ((x).pmd) 390862ff05SPeter Zijlstra #define __pmd(x) ((pmd_t) { .pmd = (x) } ) 40e44d6c40SPaul Mundt pud_pgtable(pud_t pud)419cf6fa24SAneesh Kumar K.Vstatic inline pmd_t *pud_pgtable(pud_t pud) 42e44d6c40SPaul Mundt { 43e8e9f1e6SGeert Uytterhoeven return (pmd_t *)(unsigned long)pud_val(pud); 44e44d6c40SPaul Mundt } 45e44d6c40SPaul Mundt 462f85e7f9SChristoph Hellwig /* only used by the stubbed out hugetlb gup code, should never be called */ 472f85e7f9SChristoph Hellwig #define pud_page(pud) NULL 48e44d6c40SPaul Mundt #define pud_none(x) (!pud_val(x)) 49e44d6c40SPaul Mundt #define pud_present(x) (pud_val(x)) 50e44d6c40SPaul Mundt #define pud_clear(xp) do { set_pud(xp, __pud(0)); } while (0) 51e44d6c40SPaul Mundt #define pud_bad(x) (pud_val(x) & ~PAGE_MASK) 52e44d6c40SPaul Mundt 53e44d6c40SPaul Mundt /* 54e44d6c40SPaul Mundt * (puds are folded into pgds so this doesn't get actually called, 55e44d6c40SPaul Mundt * but the define is needed for a generic inline function.) 56e44d6c40SPaul Mundt */ 57e44d6c40SPaul Mundt #define set_pud(pudptr, pudval) do { *(pudptr) = (pudval); } while(0) 58e44d6c40SPaul Mundt 59e44d6c40SPaul Mundt #endif /* __ASM_SH_PGTABLE_3LEVEL_H */ 60