1ab537dcaSAneesh Kumar K.V #ifndef _ASM_POWERPC_BOOK3S_64_HASH_4K_H 2ab537dcaSAneesh Kumar K.V #define _ASM_POWERPC_BOOK3S_64_HASH_4K_H 3ab537dcaSAneesh Kumar K.V /* 4ab537dcaSAneesh Kumar K.V * Entries per page directory level. The PTE level must use a 64b record 5ab537dcaSAneesh Kumar K.V * for each page table entry. The PMD and PGD level use a 32b record for 6ab537dcaSAneesh Kumar K.V * each entry by assuming that each entry is page aligned. 7ab537dcaSAneesh Kumar K.V */ 8ab537dcaSAneesh Kumar K.V #define PTE_INDEX_SIZE 9 9ab537dcaSAneesh Kumar K.V #define PMD_INDEX_SIZE 7 10ab537dcaSAneesh Kumar K.V #define PUD_INDEX_SIZE 9 11ab537dcaSAneesh Kumar K.V #define PGD_INDEX_SIZE 9 12ab537dcaSAneesh Kumar K.V 13ab537dcaSAneesh Kumar K.V #ifndef __ASSEMBLY__ 14ab537dcaSAneesh Kumar K.V #define PTE_TABLE_SIZE (sizeof(pte_t) << PTE_INDEX_SIZE) 15ab537dcaSAneesh Kumar K.V #define PMD_TABLE_SIZE (sizeof(pmd_t) << PMD_INDEX_SIZE) 16ab537dcaSAneesh Kumar K.V #define PUD_TABLE_SIZE (sizeof(pud_t) << PUD_INDEX_SIZE) 17ab537dcaSAneesh Kumar K.V #define PGD_TABLE_SIZE (sizeof(pgd_t) << PGD_INDEX_SIZE) 18ab537dcaSAneesh Kumar K.V #endif /* __ASSEMBLY__ */ 19ab537dcaSAneesh Kumar K.V 20ab537dcaSAneesh Kumar K.V #define PTRS_PER_PTE (1 << PTE_INDEX_SIZE) 21ab537dcaSAneesh Kumar K.V #define PTRS_PER_PMD (1 << PMD_INDEX_SIZE) 22ab537dcaSAneesh Kumar K.V #define PTRS_PER_PUD (1 << PUD_INDEX_SIZE) 23ab537dcaSAneesh Kumar K.V #define PTRS_PER_PGD (1 << PGD_INDEX_SIZE) 24ab537dcaSAneesh Kumar K.V 25ab537dcaSAneesh Kumar K.V /* PMD_SHIFT determines what a second-level page table entry can map */ 26ab537dcaSAneesh Kumar K.V #define PMD_SHIFT (PAGE_SHIFT + PTE_INDEX_SIZE) 27ab537dcaSAneesh Kumar K.V #define PMD_SIZE (1UL << PMD_SHIFT) 28ab537dcaSAneesh Kumar K.V #define PMD_MASK (~(PMD_SIZE-1)) 29ab537dcaSAneesh Kumar K.V 30ab537dcaSAneesh Kumar K.V /* With 4k base page size, hugepage PTEs go at the PMD level */ 31ab537dcaSAneesh Kumar K.V #define MIN_HUGEPTE_SHIFT PMD_SHIFT 32ab537dcaSAneesh Kumar K.V 33ab537dcaSAneesh Kumar K.V /* PUD_SHIFT determines what a third-level page table entry can map */ 34ab537dcaSAneesh Kumar K.V #define PUD_SHIFT (PMD_SHIFT + PMD_INDEX_SIZE) 35ab537dcaSAneesh Kumar K.V #define PUD_SIZE (1UL << PUD_SHIFT) 36ab537dcaSAneesh Kumar K.V #define PUD_MASK (~(PUD_SIZE-1)) 37ab537dcaSAneesh Kumar K.V 38ab537dcaSAneesh Kumar K.V /* PGDIR_SHIFT determines what a fourth-level page table entry can map */ 39ab537dcaSAneesh Kumar K.V #define PGDIR_SHIFT (PUD_SHIFT + PUD_INDEX_SIZE) 40ab537dcaSAneesh Kumar K.V #define PGDIR_SIZE (1UL << PGDIR_SHIFT) 41ab537dcaSAneesh Kumar K.V #define PGDIR_MASK (~(PGDIR_SIZE-1)) 42ab537dcaSAneesh Kumar K.V 43ab537dcaSAneesh Kumar K.V /* Bits to mask out from a PMD to get to the PTE page */ 44ab537dcaSAneesh Kumar K.V #define PMD_MASKED_BITS 0 45ab537dcaSAneesh Kumar K.V /* Bits to mask out from a PUD to get to the PMD page */ 46ab537dcaSAneesh Kumar K.V #define PUD_MASKED_BITS 0 47ab537dcaSAneesh Kumar K.V /* Bits to mask out from a PGD to get to the PUD page */ 48ab537dcaSAneesh Kumar K.V #define PGD_MASKED_BITS 0 4926b6a3d9SAneesh Kumar K.V 5026b6a3d9SAneesh Kumar K.V /* PTE flags to conserve for HPTE identification */ 5126b6a3d9SAneesh Kumar K.V #define _PAGE_HPTEFLAGS (_PAGE_BUSY | _PAGE_HASHPTE | \ 52bf680d51SAneesh Kumar K.V _PAGE_F_SECOND | _PAGE_F_GIX) 5326b6a3d9SAneesh Kumar K.V 5426b6a3d9SAneesh Kumar K.V /* shift to put page number into pte */ 5526b6a3d9SAneesh Kumar K.V #define PTE_RPN_SHIFT (17) 5626b6a3d9SAneesh Kumar K.V 57b0412ea9SAneesh Kumar K.V #define _PAGE_4K_PFN 0 58ab537dcaSAneesh Kumar K.V #ifndef __ASSEMBLY__ 59ab537dcaSAneesh Kumar K.V /* 60ab537dcaSAneesh Kumar K.V * 4-level page tables related bits 61ab537dcaSAneesh Kumar K.V */ 62ab537dcaSAneesh Kumar K.V 63ab537dcaSAneesh Kumar K.V #define pgd_none(pgd) (!pgd_val(pgd)) 64ab537dcaSAneesh Kumar K.V #define pgd_bad(pgd) (pgd_val(pgd) == 0) 65ab537dcaSAneesh Kumar K.V #define pgd_present(pgd) (pgd_val(pgd) != 0) 66ab537dcaSAneesh Kumar K.V #define pgd_page_vaddr(pgd) (pgd_val(pgd) & ~PGD_MASKED_BITS) 67ab537dcaSAneesh Kumar K.V 68f281b5d5SAneesh Kumar K.V static inline void pgd_clear(pgd_t *pgdp) 69f281b5d5SAneesh Kumar K.V { 70f281b5d5SAneesh Kumar K.V *pgdp = __pgd(0); 71f281b5d5SAneesh Kumar K.V } 72f281b5d5SAneesh Kumar K.V 73ab537dcaSAneesh Kumar K.V static inline pte_t pgd_pte(pgd_t pgd) 74ab537dcaSAneesh Kumar K.V { 75ab537dcaSAneesh Kumar K.V return __pte(pgd_val(pgd)); 76ab537dcaSAneesh Kumar K.V } 77ab537dcaSAneesh Kumar K.V 78ab537dcaSAneesh Kumar K.V static inline pgd_t pte_pgd(pte_t pte) 79ab537dcaSAneesh Kumar K.V { 80ab537dcaSAneesh Kumar K.V return __pgd(pte_val(pte)); 81ab537dcaSAneesh Kumar K.V } 82ab537dcaSAneesh Kumar K.V extern struct page *pgd_page(pgd_t pgd); 83ab537dcaSAneesh Kumar K.V 84ab537dcaSAneesh Kumar K.V #define pud_offset(pgdp, addr) \ 85ab537dcaSAneesh Kumar K.V (((pud_t *) pgd_page_vaddr(*(pgdp))) + \ 86ab537dcaSAneesh Kumar K.V (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))) 87ab537dcaSAneesh Kumar K.V 88ab537dcaSAneesh Kumar K.V #define pud_ERROR(e) \ 89ab537dcaSAneesh Kumar K.V pr_err("%s:%d: bad pud %08lx.\n", __FILE__, __LINE__, pud_val(e)) 90ab537dcaSAneesh Kumar K.V 91ab537dcaSAneesh Kumar K.V /* 92ab537dcaSAneesh Kumar K.V * On all 4K setups, remap_4k_pfn() equates to remap_pfn_range() */ 93ab537dcaSAneesh Kumar K.V #define remap_4k_pfn(vma, addr, pfn, prot) \ 94ab537dcaSAneesh Kumar K.V remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE, (prot)) 95ab537dcaSAneesh Kumar K.V 9626a344aeSAneesh Kumar K.V #ifdef CONFIG_HUGETLB_PAGE 9726a344aeSAneesh Kumar K.V /* 9826a344aeSAneesh Kumar K.V * For 4k page size, we support explicit hugepage via hugepd 9926a344aeSAneesh Kumar K.V */ 10026a344aeSAneesh Kumar K.V static inline int pmd_huge(pmd_t pmd) 10126a344aeSAneesh Kumar K.V { 10226a344aeSAneesh Kumar K.V return 0; 10326a344aeSAneesh Kumar K.V } 10426a344aeSAneesh Kumar K.V 10526a344aeSAneesh Kumar K.V static inline int pud_huge(pud_t pud) 10626a344aeSAneesh Kumar K.V { 10726a344aeSAneesh Kumar K.V return 0; 10826a344aeSAneesh Kumar K.V } 10926a344aeSAneesh Kumar K.V 11026a344aeSAneesh Kumar K.V static inline int pgd_huge(pgd_t pgd) 11126a344aeSAneesh Kumar K.V { 11226a344aeSAneesh Kumar K.V return 0; 11326a344aeSAneesh Kumar K.V } 11426a344aeSAneesh Kumar K.V #define pgd_huge pgd_huge 11526a344aeSAneesh Kumar K.V 11626a344aeSAneesh Kumar K.V static inline int hugepd_ok(hugepd_t hpd) 11726a344aeSAneesh Kumar K.V { 11826a344aeSAneesh Kumar K.V /* 119*6a119eaeSAneesh Kumar K.V * if it is not a pte and have hugepd shift mask 120*6a119eaeSAneesh Kumar K.V * set, then it is a hugepd directory pointer 12126a344aeSAneesh Kumar K.V */ 122*6a119eaeSAneesh Kumar K.V if (!(hpd.pd & _PAGE_PTE) && 123*6a119eaeSAneesh Kumar K.V ((hpd.pd & HUGEPD_SHIFT_MASK) != 0)) 124*6a119eaeSAneesh Kumar K.V return true; 125*6a119eaeSAneesh Kumar K.V return false; 12626a344aeSAneesh Kumar K.V } 12726a344aeSAneesh Kumar K.V #define is_hugepd(hpd) (hugepd_ok(hpd)) 12826a344aeSAneesh Kumar K.V #endif 12926a344aeSAneesh Kumar K.V 130ab537dcaSAneesh Kumar K.V #endif /* !__ASSEMBLY__ */ 131ab537dcaSAneesh Kumar K.V 132ab537dcaSAneesh Kumar K.V #endif /* _ASM_POWERPC_BOOK3S_64_HASH_4K_H */ 133