18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_NOHASH_64_PGTABLE_4K_H 38c2ecf20Sopenharmony_ci#define _ASM_POWERPC_NOHASH_64_PGTABLE_4K_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <asm-generic/pgtable-nop4d.h> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci/* 88c2ecf20Sopenharmony_ci * Entries per page directory level. The PTE level must use a 64b record 98c2ecf20Sopenharmony_ci * for each page table entry. The PMD and PGD level use a 32b record for 108c2ecf20Sopenharmony_ci * each entry by assuming that each entry is page aligned. 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci#define PTE_INDEX_SIZE 9 138c2ecf20Sopenharmony_ci#define PMD_INDEX_SIZE 7 148c2ecf20Sopenharmony_ci#define PUD_INDEX_SIZE 9 158c2ecf20Sopenharmony_ci#define PGD_INDEX_SIZE 9 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 188c2ecf20Sopenharmony_ci#define PTE_TABLE_SIZE (sizeof(pte_t) << PTE_INDEX_SIZE) 198c2ecf20Sopenharmony_ci#define PMD_TABLE_SIZE (sizeof(pmd_t) << PMD_INDEX_SIZE) 208c2ecf20Sopenharmony_ci#define PUD_TABLE_SIZE (sizeof(pud_t) << PUD_INDEX_SIZE) 218c2ecf20Sopenharmony_ci#define PGD_TABLE_SIZE (sizeof(pgd_t) << PGD_INDEX_SIZE) 228c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */ 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#define PTRS_PER_PTE (1 << PTE_INDEX_SIZE) 258c2ecf20Sopenharmony_ci#define PTRS_PER_PMD (1 << PMD_INDEX_SIZE) 268c2ecf20Sopenharmony_ci#define PTRS_PER_PUD (1 << PUD_INDEX_SIZE) 278c2ecf20Sopenharmony_ci#define PTRS_PER_PGD (1 << PGD_INDEX_SIZE) 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci/* PMD_SHIFT determines what a second-level page table entry can map */ 308c2ecf20Sopenharmony_ci#define PMD_SHIFT (PAGE_SHIFT + PTE_INDEX_SIZE) 318c2ecf20Sopenharmony_ci#define PMD_SIZE (1UL << PMD_SHIFT) 328c2ecf20Sopenharmony_ci#define PMD_MASK (~(PMD_SIZE-1)) 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci/* PUD_SHIFT determines what a third-level page table entry can map */ 358c2ecf20Sopenharmony_ci#define PUD_SHIFT (PMD_SHIFT + PMD_INDEX_SIZE) 368c2ecf20Sopenharmony_ci#define PUD_SIZE (1UL << PUD_SHIFT) 378c2ecf20Sopenharmony_ci#define PUD_MASK (~(PUD_SIZE-1)) 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/* PGDIR_SHIFT determines what a fourth-level page table entry can map */ 408c2ecf20Sopenharmony_ci#define PGDIR_SHIFT (PUD_SHIFT + PUD_INDEX_SIZE) 418c2ecf20Sopenharmony_ci#define PGDIR_SIZE (1UL << PGDIR_SHIFT) 428c2ecf20Sopenharmony_ci#define PGDIR_MASK (~(PGDIR_SIZE-1)) 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci/* Bits to mask out from a PMD to get to the PTE page */ 458c2ecf20Sopenharmony_ci#define PMD_MASKED_BITS 0 468c2ecf20Sopenharmony_ci/* Bits to mask out from a PUD to get to the PMD page */ 478c2ecf20Sopenharmony_ci#define PUD_MASKED_BITS 0 488c2ecf20Sopenharmony_ci/* Bits to mask out from a P4D to get to the PUD page */ 498c2ecf20Sopenharmony_ci#define P4D_MASKED_BITS 0 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci/* 538c2ecf20Sopenharmony_ci * 4-level page tables related bits 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci#define p4d_none(p4d) (!p4d_val(p4d)) 578c2ecf20Sopenharmony_ci#define p4d_bad(p4d) (p4d_val(p4d) == 0) 588c2ecf20Sopenharmony_ci#define p4d_present(p4d) (p4d_val(p4d) != 0) 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_cistatic inline pud_t *p4d_pgtable(p4d_t p4d) 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci return (pud_t *) (p4d_val(p4d) & ~P4D_MASKED_BITS); 658c2ecf20Sopenharmony_ci} 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_cistatic inline void p4d_clear(p4d_t *p4dp) 688c2ecf20Sopenharmony_ci{ 698c2ecf20Sopenharmony_ci *p4dp = __p4d(0); 708c2ecf20Sopenharmony_ci} 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_cistatic inline pte_t p4d_pte(p4d_t p4d) 738c2ecf20Sopenharmony_ci{ 748c2ecf20Sopenharmony_ci return __pte(p4d_val(p4d)); 758c2ecf20Sopenharmony_ci} 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistatic inline p4d_t pte_p4d(pte_t pte) 788c2ecf20Sopenharmony_ci{ 798c2ecf20Sopenharmony_ci return __p4d(pte_val(pte)); 808c2ecf20Sopenharmony_ci} 818c2ecf20Sopenharmony_ciextern struct page *p4d_page(p4d_t p4d); 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#endif /* !__ASSEMBLY__ */ 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#define pud_ERROR(e) \ 868c2ecf20Sopenharmony_ci pr_err("%s:%d: bad pud %08lx.\n", __FILE__, __LINE__, pud_val(e)) 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci/* 898c2ecf20Sopenharmony_ci * On all 4K setups, remap_4k_pfn() equates to remap_pfn_range() */ 908c2ecf20Sopenharmony_ci#define remap_4k_pfn(vma, addr, pfn, prot) \ 918c2ecf20Sopenharmony_ci remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE, (prot)) 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci#endif /* _ _ASM_POWERPC_NOHASH_64_PGTABLE_4K_H */ 94