18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __ASM_SH_PGTABLE_3LEVEL_H
38c2ecf20Sopenharmony_ci#define __ASM_SH_PGTABLE_3LEVEL_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <asm-generic/pgtable-nopud.h>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci/*
88c2ecf20Sopenharmony_ci * Some cores need a 3-level page table layout, for example when using
98c2ecf20Sopenharmony_ci * 64-bit PTEs and 4K pages.
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci#define PAGETABLE_LEVELS	3
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define PTE_MAGNITUDE		3	/* 64-bit PTEs on SH-X2 TLB */
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/* PGD bits */
168c2ecf20Sopenharmony_ci#define PGDIR_SHIFT		30
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#define PTRS_PER_PGD		4
198c2ecf20Sopenharmony_ci#define USER_PTRS_PER_PGD	2
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/* PMD bits */
228c2ecf20Sopenharmony_ci#define PMD_SHIFT	(PAGE_SHIFT + (PAGE_SHIFT - PTE_MAGNITUDE))
238c2ecf20Sopenharmony_ci#define PMD_SIZE	(1UL << PMD_SHIFT)
248c2ecf20Sopenharmony_ci#define PMD_MASK	(~(PMD_SIZE-1))
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define PTRS_PER_PMD	((1 << PGDIR_SHIFT) / PMD_SIZE)
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define pmd_ERROR(e) \
298c2ecf20Sopenharmony_ci	printk("%s:%d: bad pmd %016llx.\n", __FILE__, __LINE__, pmd_val(e))
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_citypedef struct { unsigned long long pmd; } pmd_t;
328c2ecf20Sopenharmony_ci#define pmd_val(x)	((x).pmd)
338c2ecf20Sopenharmony_ci#define __pmd(x)	((pmd_t) { (x) } )
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistatic inline pmd_t *pud_pgtable(pud_t pud)
368c2ecf20Sopenharmony_ci{
378c2ecf20Sopenharmony_ci	return (pmd_t *)(unsigned long)pud_val(pud);
388c2ecf20Sopenharmony_ci}
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci/* only used by the stubbed out hugetlb gup code, should never be called */
418c2ecf20Sopenharmony_ci#define pud_page(pud)		NULL
428c2ecf20Sopenharmony_ci#define pud_none(x)	(!pud_val(x))
438c2ecf20Sopenharmony_ci#define pud_present(x)	(pud_val(x))
448c2ecf20Sopenharmony_ci#define pud_clear(xp)	do { set_pud(xp, __pud(0)); } while (0)
458c2ecf20Sopenharmony_ci#define	pud_bad(x)	(pud_val(x) & ~PAGE_MASK)
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci/*
488c2ecf20Sopenharmony_ci * (puds are folded into pgds so this doesn't get actually called,
498c2ecf20Sopenharmony_ci * but the define is needed for a generic inline function.)
508c2ecf20Sopenharmony_ci */
518c2ecf20Sopenharmony_ci#define set_pud(pudptr, pudval) do { *(pudptr) = (pudval); } while(0)
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#endif /* __ASM_SH_PGTABLE_3LEVEL_H */
54