1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2ab537dcaSAneesh Kumar K.V #ifndef _ASM_POWERPC_BOOK3S_64_HASH_4K_H 3ab537dcaSAneesh Kumar K.V #define _ASM_POWERPC_BOOK3S_64_HASH_4K_H 4423e2f94SMichael Ellerman 5eea86aa4SMichael Ellerman #define H_PTE_INDEX_SIZE 9 // size: 8B << 9 = 4KB, maps: 2^9 x 4KB = 2MB 6eea86aa4SMichael Ellerman #define H_PMD_INDEX_SIZE 7 // size: 8B << 7 = 1KB, maps: 2^7 x 2MB = 256MB 7eea86aa4SMichael Ellerman #define H_PUD_INDEX_SIZE 9 // size: 8B << 9 = 4KB, maps: 2^9 x 256MB = 128GB 8eea86aa4SMichael Ellerman #define H_PGD_INDEX_SIZE 9 // size: 8B << 9 = 4KB, maps: 2^9 x 128GB = 64TB 9ab537dcaSAneesh Kumar K.V 10f384796cSAneesh Kumar K.V /* 11f384796cSAneesh Kumar K.V * Each context is 512TB. But on 4k we restrict our max TASK size to 64TB 12f384796cSAneesh Kumar K.V * Hence also limit max EA bits to 64TB. 13f384796cSAneesh Kumar K.V */ 14f384796cSAneesh Kumar K.V #define MAX_EA_BITS_PER_CONTEXT 46 15f384796cSAneesh Kumar K.V 161c946c1bSAneesh Kumar K.V #define REGION_SHIFT (MAX_EA_BITS_PER_CONTEXT - 2) 171c946c1bSAneesh Kumar K.V 180034d395SAneesh Kumar K.V /* 190034d395SAneesh Kumar K.V * Our page table limit us to 64TB. Hence for the kernel mapping, 200034d395SAneesh Kumar K.V * each MAP area is limited to 16 TB. 210034d395SAneesh Kumar K.V * The four map areas are: linear mapping, vmap, IO and vmemmap 220034d395SAneesh Kumar K.V */ 231c946c1bSAneesh Kumar K.V #define H_KERN_MAP_SIZE (ASM_CONST(1) << REGION_SHIFT) 240034d395SAneesh Kumar K.V 250034d395SAneesh Kumar K.V /* 260034d395SAneesh Kumar K.V * Define the address range of the kernel non-linear virtual area 270034d395SAneesh Kumar K.V * 16TB 280034d395SAneesh Kumar K.V */ 290034d395SAneesh Kumar K.V #define H_KERN_VIRT_START ASM_CONST(0xc000100000000000) 300034d395SAneesh Kumar K.V 31ab537dcaSAneesh Kumar K.V #ifndef __ASSEMBLY__ 32dd1842a2SAneesh Kumar K.V #define H_PTE_TABLE_SIZE (sizeof(pte_t) << H_PTE_INDEX_SIZE) 33dd1842a2SAneesh Kumar K.V #define H_PMD_TABLE_SIZE (sizeof(pmd_t) << H_PMD_INDEX_SIZE) 34dd1842a2SAneesh Kumar K.V #define H_PUD_TABLE_SIZE (sizeof(pud_t) << H_PUD_INDEX_SIZE) 35dd1842a2SAneesh Kumar K.V #define H_PGD_TABLE_SIZE (sizeof(pgd_t) << H_PGD_INDEX_SIZE) 36ab537dcaSAneesh Kumar K.V 37273b4936SRam Pai #define H_PAGE_F_GIX_SHIFT 53 38273b4936SRam Pai #define H_PAGE_F_SECOND _RPAGE_RPN44 /* HPTE is in 2ndary HPTEG */ 39273b4936SRam Pai #define H_PAGE_F_GIX (_RPAGE_RPN43 | _RPAGE_RPN42 | _RPAGE_RPN41) 409d2edb18SRam Pai #define H_PAGE_BUSY _RPAGE_RSV1 /* software: PTE & hash are busy */ 41273b4936SRam Pai #define H_PAGE_HASHPTE _RPAGE_RSV2 /* software: PTE & hash are busy */ 429d2edb18SRam Pai 4326b6a3d9SAneesh Kumar K.V /* PTE flags to conserve for HPTE identification */ 44945537dfSAneesh Kumar K.V #define _PAGE_HPTEFLAGS (H_PAGE_BUSY | H_PAGE_HASHPTE | \ 45945537dfSAneesh Kumar K.V H_PAGE_F_SECOND | H_PAGE_F_GIX) 46945537dfSAneesh Kumar K.V /* 47945537dfSAneesh Kumar K.V * Not supported by 4k linux page size 48945537dfSAneesh Kumar K.V */ 49945537dfSAneesh Kumar K.V #define H_PAGE_4K_PFN 0x0 50945537dfSAneesh Kumar K.V #define H_PAGE_THP_HUGE 0x0 51945537dfSAneesh Kumar K.V #define H_PAGE_COMBO 0x0 521c7ec8a4SAneesh Kumar K.V 531c7ec8a4SAneesh Kumar K.V /* 8 bytes per each pte entry */ 541c7ec8a4SAneesh Kumar K.V #define H_PTE_FRAG_SIZE_SHIFT (H_PTE_INDEX_SIZE + 3) 551c7ec8a4SAneesh Kumar K.V #define H_PTE_FRAG_NR (PAGE_SIZE >> H_PTE_FRAG_SIZE_SHIFT) 568a6c697bSAneesh Kumar K.V #define H_PMD_FRAG_SIZE_SHIFT (H_PMD_INDEX_SIZE + 3) 578a6c697bSAneesh Kumar K.V #define H_PMD_FRAG_NR (PAGE_SIZE >> H_PMD_FRAG_SIZE_SHIFT) 581a2f7789SAneesh Kumar K.V 591a2f7789SAneesh Kumar K.V /* memory key bits, only 8 keys supported */ 601a2f7789SAneesh Kumar K.V #define H_PTE_PKEY_BIT0 0 611a2f7789SAneesh Kumar K.V #define H_PTE_PKEY_BIT1 0 621a2f7789SAneesh Kumar K.V #define H_PTE_PKEY_BIT2 _RPAGE_RSV3 631a2f7789SAneesh Kumar K.V #define H_PTE_PKEY_BIT3 _RPAGE_RSV4 641a2f7789SAneesh Kumar K.V #define H_PTE_PKEY_BIT4 _RPAGE_RSV5 651a2f7789SAneesh Kumar K.V 66ab537dcaSAneesh Kumar K.V /* 67368ced78SAneesh Kumar K.V * On all 4K setups, remap_4k_pfn() equates to remap_pfn_range() 68ab537dcaSAneesh Kumar K.V */ 69ab537dcaSAneesh Kumar K.V #define remap_4k_pfn(vma, addr, pfn, prot) \ 70ab537dcaSAneesh Kumar K.V remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE, (prot)) 71ab537dcaSAneesh Kumar K.V 7226a344aeSAneesh Kumar K.V #ifdef CONFIG_HUGETLB_PAGE 73c0a6c719SAneesh Kumar K.V static inline int hash__hugepd_ok(hugepd_t hpd) 7426a344aeSAneesh Kumar K.V { 7520717e1fSAneesh Kumar K.V unsigned long hpdval = hpd_val(hpd); 7626a344aeSAneesh Kumar K.V /* 776a119eaeSAneesh Kumar K.V * if it is not a pte and have hugepd shift mask 786a119eaeSAneesh Kumar K.V * set, then it is a hugepd directory pointer 7926a344aeSAneesh Kumar K.V */ 80f1981b5bSAneesh Kumar K.V if (!(hpdval & _PAGE_PTE) && (hpdval & _PAGE_PRESENT) && 8120717e1fSAneesh Kumar K.V ((hpdval & HUGEPD_SHIFT_MASK) != 0)) 826a119eaeSAneesh Kumar K.V return true; 836a119eaeSAneesh Kumar K.V return false; 8426a344aeSAneesh Kumar K.V } 8526a344aeSAneesh Kumar K.V #endif 8626a344aeSAneesh Kumar K.V 8759aa31fdSRam Pai /* 8859aa31fdSRam Pai * 4K PTE format is different from 64K PTE format. Saving the hash_slot is just 8959aa31fdSRam Pai * a matter of returning the PTE bits that need to be modified. On 64K PTE, 9059aa31fdSRam Pai * things are a little more involved and hence needs many more parameters to 9159aa31fdSRam Pai * accomplish the same. However we want to abstract this out from the caller by 9259aa31fdSRam Pai * keeping the prototype consistent across the two formats. 9359aa31fdSRam Pai */ 9459aa31fdSRam Pai static inline unsigned long pte_set_hidx(pte_t *ptep, real_pte_t rpte, 95ff31e105SAneesh Kumar K.V unsigned int subpg_index, unsigned long hidx, 96ff31e105SAneesh Kumar K.V int offset) 9759aa31fdSRam Pai { 9859aa31fdSRam Pai return (hidx << H_PAGE_F_GIX_SHIFT) & 9959aa31fdSRam Pai (H_PAGE_F_SECOND | H_PAGE_F_GIX); 10059aa31fdSRam Pai } 10159aa31fdSRam Pai 102ab624762SAneesh Kumar K.V #ifdef CONFIG_TRANSPARENT_HUGEPAGE 103ab624762SAneesh Kumar K.V 104ab624762SAneesh Kumar K.V static inline char *get_hpte_slot_array(pmd_t *pmdp) 105ab624762SAneesh Kumar K.V { 106ab624762SAneesh Kumar K.V BUG(); 107ab624762SAneesh Kumar K.V return NULL; 108ab624762SAneesh Kumar K.V } 109ab624762SAneesh Kumar K.V 110ab624762SAneesh Kumar K.V static inline unsigned int hpte_valid(unsigned char *hpte_slot_array, int index) 111ab624762SAneesh Kumar K.V { 112ab624762SAneesh Kumar K.V BUG(); 113ab624762SAneesh Kumar K.V return 0; 114ab624762SAneesh Kumar K.V } 115ab624762SAneesh Kumar K.V 116ab624762SAneesh Kumar K.V static inline unsigned int hpte_hash_index(unsigned char *hpte_slot_array, 117ab624762SAneesh Kumar K.V int index) 118ab624762SAneesh Kumar K.V { 119ab624762SAneesh Kumar K.V BUG(); 120ab624762SAneesh Kumar K.V return 0; 121ab624762SAneesh Kumar K.V } 122ab624762SAneesh Kumar K.V 123ab624762SAneesh Kumar K.V static inline void mark_hpte_slot_valid(unsigned char *hpte_slot_array, 124ab624762SAneesh Kumar K.V unsigned int index, unsigned int hidx) 125ab624762SAneesh Kumar K.V { 126ab624762SAneesh Kumar K.V BUG(); 127ab624762SAneesh Kumar K.V } 128ab624762SAneesh Kumar K.V 129ab624762SAneesh Kumar K.V static inline int hash__pmd_trans_huge(pmd_t pmd) 130ab624762SAneesh Kumar K.V { 131ab624762SAneesh Kumar K.V return 0; 132ab624762SAneesh Kumar K.V } 133ab624762SAneesh Kumar K.V 134ab624762SAneesh Kumar K.V static inline int hash__pmd_same(pmd_t pmd_a, pmd_t pmd_b) 135ab624762SAneesh Kumar K.V { 136ab624762SAneesh Kumar K.V BUG(); 137ab624762SAneesh Kumar K.V return 0; 138ab624762SAneesh Kumar K.V } 139ab624762SAneesh Kumar K.V 140ab624762SAneesh Kumar K.V static inline pmd_t hash__pmd_mkhuge(pmd_t pmd) 141ab624762SAneesh Kumar K.V { 142ab624762SAneesh Kumar K.V BUG(); 143ab624762SAneesh Kumar K.V return pmd; 144ab624762SAneesh Kumar K.V } 145ab624762SAneesh Kumar K.V 146ab624762SAneesh Kumar K.V extern unsigned long hash__pmd_hugepage_update(struct mm_struct *mm, 147ab624762SAneesh Kumar K.V unsigned long addr, pmd_t *pmdp, 148ab624762SAneesh Kumar K.V unsigned long clr, unsigned long set); 149ab624762SAneesh Kumar K.V extern pmd_t hash__pmdp_collapse_flush(struct vm_area_struct *vma, 150ab624762SAneesh Kumar K.V unsigned long address, pmd_t *pmdp); 151ab624762SAneesh Kumar K.V extern void hash__pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp, 152ab624762SAneesh Kumar K.V pgtable_t pgtable); 153ab624762SAneesh Kumar K.V extern pgtable_t hash__pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp); 154ab624762SAneesh Kumar K.V extern pmd_t hash__pmdp_huge_get_and_clear(struct mm_struct *mm, 155ab624762SAneesh Kumar K.V unsigned long addr, pmd_t *pmdp); 156ab624762SAneesh Kumar K.V extern int hash__has_transparent_hugepage(void); 157ab624762SAneesh Kumar K.V #endif 158ab624762SAneesh Kumar K.V 159*36b78402SAneesh Kumar K.V static inline pmd_t hash__pmd_mkdevmap(pmd_t pmd) 160*36b78402SAneesh Kumar K.V { 161*36b78402SAneesh Kumar K.V BUG(); 162*36b78402SAneesh Kumar K.V return pmd; 163*36b78402SAneesh Kumar K.V } 164*36b78402SAneesh Kumar K.V 165ab537dcaSAneesh Kumar K.V #endif /* !__ASSEMBLY__ */ 166ab537dcaSAneesh Kumar K.V 167ab537dcaSAneesh Kumar K.V #endif /* _ASM_POWERPC_BOOK3S_64_HASH_4K_H */ 168