xref: /linux/arch/powerpc/include/asm/book3s/64/hash-4k.h (revision f1981b5b302f7f3b4c8b9b5e25ea8c48cebb1ae1)
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
4ab537dcaSAneesh Kumar K.V /*
5ab537dcaSAneesh Kumar K.V  * Entries per page directory level.  The PTE level must use a 64b record
6ab537dcaSAneesh Kumar K.V  * for each page table entry.  The PMD and PGD level use a 32b record for
7ab537dcaSAneesh Kumar K.V  * each entry by assuming that each entry is page aligned.
8ab537dcaSAneesh Kumar K.V  */
9dd1842a2SAneesh Kumar K.V #define H_PTE_INDEX_SIZE  9
10dd1842a2SAneesh Kumar K.V #define H_PMD_INDEX_SIZE  7
11dd1842a2SAneesh Kumar K.V #define H_PUD_INDEX_SIZE  9
1292d9dfdaSAneesh Kumar K.V #define H_PGD_INDEX_SIZE  9
13ab537dcaSAneesh Kumar K.V 
14f384796cSAneesh Kumar K.V /*
15f384796cSAneesh Kumar K.V  * Each context is 512TB. But on 4k we restrict our max TASK size to 64TB
16f384796cSAneesh Kumar K.V  * Hence also limit max EA bits to 64TB.
17f384796cSAneesh Kumar K.V  */
18f384796cSAneesh Kumar K.V #define MAX_EA_BITS_PER_CONTEXT		46
19f384796cSAneesh Kumar K.V 
20ab537dcaSAneesh Kumar K.V #ifndef __ASSEMBLY__
21dd1842a2SAneesh Kumar K.V #define H_PTE_TABLE_SIZE	(sizeof(pte_t) << H_PTE_INDEX_SIZE)
22dd1842a2SAneesh Kumar K.V #define H_PMD_TABLE_SIZE	(sizeof(pmd_t) << H_PMD_INDEX_SIZE)
23dd1842a2SAneesh Kumar K.V #define H_PUD_TABLE_SIZE	(sizeof(pud_t) << H_PUD_INDEX_SIZE)
24dd1842a2SAneesh Kumar K.V #define H_PGD_TABLE_SIZE	(sizeof(pgd_t) << H_PGD_INDEX_SIZE)
25ab537dcaSAneesh Kumar K.V 
26273b4936SRam Pai #define H_PAGE_F_GIX_SHIFT	53
27273b4936SRam Pai #define H_PAGE_F_SECOND	_RPAGE_RPN44	/* HPTE is in 2ndary HPTEG */
28273b4936SRam Pai #define H_PAGE_F_GIX	(_RPAGE_RPN43 | _RPAGE_RPN42 | _RPAGE_RPN41)
299d2edb18SRam Pai #define H_PAGE_BUSY	_RPAGE_RSV1     /* software: PTE & hash are busy */
30273b4936SRam Pai #define H_PAGE_HASHPTE	_RPAGE_RSV2     /* software: PTE & hash are busy */
319d2edb18SRam Pai 
3226b6a3d9SAneesh Kumar K.V /* PTE flags to conserve for HPTE identification */
33945537dfSAneesh Kumar K.V #define _PAGE_HPTEFLAGS (H_PAGE_BUSY | H_PAGE_HASHPTE | \
34945537dfSAneesh Kumar K.V 			 H_PAGE_F_SECOND | H_PAGE_F_GIX)
35945537dfSAneesh Kumar K.V /*
36945537dfSAneesh Kumar K.V  * Not supported by 4k linux page size
37945537dfSAneesh Kumar K.V  */
38945537dfSAneesh Kumar K.V #define H_PAGE_4K_PFN	0x0
39945537dfSAneesh Kumar K.V #define H_PAGE_THP_HUGE 0x0
40945537dfSAneesh Kumar K.V #define H_PAGE_COMBO	0x0
411c7ec8a4SAneesh Kumar K.V 
421c7ec8a4SAneesh Kumar K.V /* 8 bytes per each pte entry */
431c7ec8a4SAneesh Kumar K.V #define H_PTE_FRAG_SIZE_SHIFT  (H_PTE_INDEX_SIZE + 3)
441c7ec8a4SAneesh Kumar K.V #define H_PTE_FRAG_NR	(PAGE_SIZE >> H_PTE_FRAG_SIZE_SHIFT)
458a6c697bSAneesh Kumar K.V #define H_PMD_FRAG_SIZE_SHIFT  (H_PMD_INDEX_SIZE + 3)
468a6c697bSAneesh Kumar K.V #define H_PMD_FRAG_NR	(PAGE_SIZE >> H_PMD_FRAG_SIZE_SHIFT)
471a2f7789SAneesh Kumar K.V 
481a2f7789SAneesh Kumar K.V /* memory key bits, only 8 keys supported */
491a2f7789SAneesh Kumar K.V #define H_PTE_PKEY_BIT0	0
501a2f7789SAneesh Kumar K.V #define H_PTE_PKEY_BIT1	0
511a2f7789SAneesh Kumar K.V #define H_PTE_PKEY_BIT2	_RPAGE_RSV3
521a2f7789SAneesh Kumar K.V #define H_PTE_PKEY_BIT3	_RPAGE_RSV4
531a2f7789SAneesh Kumar K.V #define H_PTE_PKEY_BIT4	_RPAGE_RSV5
541a2f7789SAneesh Kumar K.V 
55ab537dcaSAneesh Kumar K.V /*
56368ced78SAneesh Kumar K.V  * On all 4K setups, remap_4k_pfn() equates to remap_pfn_range()
57ab537dcaSAneesh Kumar K.V  */
58ab537dcaSAneesh Kumar K.V #define remap_4k_pfn(vma, addr, pfn, prot)	\
59ab537dcaSAneesh Kumar K.V 	remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE, (prot))
60ab537dcaSAneesh Kumar K.V 
6126a344aeSAneesh Kumar K.V #ifdef CONFIG_HUGETLB_PAGE
62c0a6c719SAneesh Kumar K.V static inline int hash__hugepd_ok(hugepd_t hpd)
6326a344aeSAneesh Kumar K.V {
6420717e1fSAneesh Kumar K.V 	unsigned long hpdval = hpd_val(hpd);
6526a344aeSAneesh Kumar K.V 	/*
666a119eaeSAneesh Kumar K.V 	 * if it is not a pte and have hugepd shift mask
676a119eaeSAneesh Kumar K.V 	 * set, then it is a hugepd directory pointer
6826a344aeSAneesh Kumar K.V 	 */
69*f1981b5bSAneesh Kumar K.V 	if (!(hpdval & _PAGE_PTE) && (hpdval & _PAGE_PRESENT) &&
7020717e1fSAneesh Kumar K.V 	    ((hpdval & HUGEPD_SHIFT_MASK) != 0))
716a119eaeSAneesh Kumar K.V 		return true;
726a119eaeSAneesh Kumar K.V 	return false;
7326a344aeSAneesh Kumar K.V }
7426a344aeSAneesh Kumar K.V #endif
7526a344aeSAneesh Kumar K.V 
7659aa31fdSRam Pai /*
7759aa31fdSRam Pai  * 4K PTE format is different from 64K PTE format. Saving the hash_slot is just
7859aa31fdSRam Pai  * a matter of returning the PTE bits that need to be modified. On 64K PTE,
7959aa31fdSRam Pai  * things are a little more involved and hence needs many more parameters to
8059aa31fdSRam Pai  * accomplish the same. However we want to abstract this out from the caller by
8159aa31fdSRam Pai  * keeping the prototype consistent across the two formats.
8259aa31fdSRam Pai  */
8359aa31fdSRam Pai static inline unsigned long pte_set_hidx(pte_t *ptep, real_pte_t rpte,
84ff31e105SAneesh Kumar K.V 					 unsigned int subpg_index, unsigned long hidx,
85ff31e105SAneesh Kumar K.V 					 int offset)
8659aa31fdSRam Pai {
8759aa31fdSRam Pai 	return (hidx << H_PAGE_F_GIX_SHIFT) &
8859aa31fdSRam Pai 		(H_PAGE_F_SECOND | H_PAGE_F_GIX);
8959aa31fdSRam Pai }
9059aa31fdSRam Pai 
91ab624762SAneesh Kumar K.V #ifdef CONFIG_TRANSPARENT_HUGEPAGE
92ab624762SAneesh Kumar K.V 
93ab624762SAneesh Kumar K.V static inline char *get_hpte_slot_array(pmd_t *pmdp)
94ab624762SAneesh Kumar K.V {
95ab624762SAneesh Kumar K.V 	BUG();
96ab624762SAneesh Kumar K.V 	return NULL;
97ab624762SAneesh Kumar K.V }
98ab624762SAneesh Kumar K.V 
99ab624762SAneesh Kumar K.V static inline unsigned int hpte_valid(unsigned char *hpte_slot_array, int index)
100ab624762SAneesh Kumar K.V {
101ab624762SAneesh Kumar K.V 	BUG();
102ab624762SAneesh Kumar K.V 	return 0;
103ab624762SAneesh Kumar K.V }
104ab624762SAneesh Kumar K.V 
105ab624762SAneesh Kumar K.V static inline unsigned int hpte_hash_index(unsigned char *hpte_slot_array,
106ab624762SAneesh Kumar K.V 					   int index)
107ab624762SAneesh Kumar K.V {
108ab624762SAneesh Kumar K.V 	BUG();
109ab624762SAneesh Kumar K.V 	return 0;
110ab624762SAneesh Kumar K.V }
111ab624762SAneesh Kumar K.V 
112ab624762SAneesh Kumar K.V static inline void mark_hpte_slot_valid(unsigned char *hpte_slot_array,
113ab624762SAneesh Kumar K.V 					unsigned int index, unsigned int hidx)
114ab624762SAneesh Kumar K.V {
115ab624762SAneesh Kumar K.V 	BUG();
116ab624762SAneesh Kumar K.V }
117ab624762SAneesh Kumar K.V 
118ab624762SAneesh Kumar K.V static inline int hash__pmd_trans_huge(pmd_t pmd)
119ab624762SAneesh Kumar K.V {
120ab624762SAneesh Kumar K.V 	return 0;
121ab624762SAneesh Kumar K.V }
122ab624762SAneesh Kumar K.V 
123ab624762SAneesh Kumar K.V static inline int hash__pmd_same(pmd_t pmd_a, pmd_t pmd_b)
124ab624762SAneesh Kumar K.V {
125ab624762SAneesh Kumar K.V 	BUG();
126ab624762SAneesh Kumar K.V 	return 0;
127ab624762SAneesh Kumar K.V }
128ab624762SAneesh Kumar K.V 
129ab624762SAneesh Kumar K.V static inline pmd_t hash__pmd_mkhuge(pmd_t pmd)
130ab624762SAneesh Kumar K.V {
131ab624762SAneesh Kumar K.V 	BUG();
132ab624762SAneesh Kumar K.V 	return pmd;
133ab624762SAneesh Kumar K.V }
134ab624762SAneesh Kumar K.V 
135ab624762SAneesh Kumar K.V extern unsigned long hash__pmd_hugepage_update(struct mm_struct *mm,
136ab624762SAneesh Kumar K.V 					   unsigned long addr, pmd_t *pmdp,
137ab624762SAneesh Kumar K.V 					   unsigned long clr, unsigned long set);
138ab624762SAneesh Kumar K.V extern pmd_t hash__pmdp_collapse_flush(struct vm_area_struct *vma,
139ab624762SAneesh Kumar K.V 				   unsigned long address, pmd_t *pmdp);
140ab624762SAneesh Kumar K.V extern void hash__pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
141ab624762SAneesh Kumar K.V 					 pgtable_t pgtable);
142ab624762SAneesh Kumar K.V extern pgtable_t hash__pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp);
143ab624762SAneesh Kumar K.V extern pmd_t hash__pmdp_huge_get_and_clear(struct mm_struct *mm,
144ab624762SAneesh Kumar K.V 				       unsigned long addr, pmd_t *pmdp);
145ab624762SAneesh Kumar K.V extern int hash__has_transparent_hugepage(void);
146ab624762SAneesh Kumar K.V #endif
147ab624762SAneesh Kumar K.V 
148ab537dcaSAneesh Kumar K.V #endif /* !__ASSEMBLY__ */
149ab537dcaSAneesh Kumar K.V 
150ab537dcaSAneesh Kumar K.V #endif /* _ASM_POWERPC_BOOK3S_64_HASH_4K_H */
151