xref: /openbmc/linux/arch/powerpc/include/asm/book3s/64/hash-4k.h (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
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 
170034d395SAneesh Kumar K.V /*
187746406bSAneesh Kumar K.V  * Our page table limit us to 64TB. For 64TB physical memory, we only need 64GB
197746406bSAneesh Kumar K.V  * of vmemmap space. To better support sparse memory layout, we use 61TB
207746406bSAneesh Kumar K.V  * linear map range, 1TB of vmalloc, 1TB of I/O and 1TB of vmememmap.
210034d395SAneesh Kumar K.V  */
227746406bSAneesh Kumar K.V #define REGION_SHIFT		(40)
231c946c1bSAneesh Kumar K.V #define H_KERN_MAP_SIZE		(ASM_CONST(1) << REGION_SHIFT)
240034d395SAneesh Kumar K.V 
250034d395SAneesh Kumar K.V /*
26*b32d5d7eSAneesh Kumar K.V  * Limits the linear mapping range
27*b32d5d7eSAneesh Kumar K.V  */
28*b32d5d7eSAneesh Kumar K.V #define H_MAX_PHYSMEM_BITS	46
29*b32d5d7eSAneesh Kumar K.V 
30*b32d5d7eSAneesh Kumar K.V /*
317746406bSAneesh Kumar K.V  * Define the address range of the kernel non-linear virtual area (61TB)
320034d395SAneesh Kumar K.V  */
337746406bSAneesh Kumar K.V #define H_KERN_VIRT_START	ASM_CONST(0xc0003d0000000000)
340034d395SAneesh Kumar K.V 
35ab537dcaSAneesh Kumar K.V #ifndef __ASSEMBLY__
36dd1842a2SAneesh Kumar K.V #define H_PTE_TABLE_SIZE	(sizeof(pte_t) << H_PTE_INDEX_SIZE)
37dd1842a2SAneesh Kumar K.V #define H_PMD_TABLE_SIZE	(sizeof(pmd_t) << H_PMD_INDEX_SIZE)
38dd1842a2SAneesh Kumar K.V #define H_PUD_TABLE_SIZE	(sizeof(pud_t) << H_PUD_INDEX_SIZE)
39dd1842a2SAneesh Kumar K.V #define H_PGD_TABLE_SIZE	(sizeof(pgd_t) << H_PGD_INDEX_SIZE)
40ab537dcaSAneesh Kumar K.V 
41ee8b3933SAneesh Kumar K.V #define H_PAGE_F_GIX_SHIFT	_PAGE_PA_MAX
42ee8b3933SAneesh Kumar K.V #define H_PAGE_F_SECOND		_RPAGE_PKEY_BIT0 /* HPTE is in 2ndary HPTEG */
43273b4936SRam Pai #define H_PAGE_F_GIX		(_RPAGE_RPN43 | _RPAGE_RPN42 | _RPAGE_RPN41)
44ee8b3933SAneesh Kumar K.V #define H_PAGE_BUSY		_RPAGE_RSV1
45ee8b3933SAneesh Kumar K.V #define H_PAGE_HASHPTE		_RPAGE_PKEY_BIT4
469d2edb18SRam Pai 
4726b6a3d9SAneesh Kumar K.V /* PTE flags to conserve for HPTE identification */
48945537dfSAneesh Kumar K.V #define _PAGE_HPTEFLAGS (H_PAGE_BUSY | H_PAGE_HASHPTE | \
49945537dfSAneesh Kumar K.V 			 H_PAGE_F_SECOND | H_PAGE_F_GIX)
50945537dfSAneesh Kumar K.V /*
51945537dfSAneesh Kumar K.V  * Not supported by 4k linux page size
52945537dfSAneesh Kumar K.V  */
53945537dfSAneesh Kumar K.V #define H_PAGE_4K_PFN	0x0
54945537dfSAneesh Kumar K.V #define H_PAGE_THP_HUGE 0x0
55945537dfSAneesh Kumar K.V #define H_PAGE_COMBO	0x0
561c7ec8a4SAneesh Kumar K.V 
571c7ec8a4SAneesh Kumar K.V /* 8 bytes per each pte entry */
581c7ec8a4SAneesh Kumar K.V #define H_PTE_FRAG_SIZE_SHIFT  (H_PTE_INDEX_SIZE + 3)
591c7ec8a4SAneesh Kumar K.V #define H_PTE_FRAG_NR	(PAGE_SIZE >> H_PTE_FRAG_SIZE_SHIFT)
608a6c697bSAneesh Kumar K.V #define H_PMD_FRAG_SIZE_SHIFT  (H_PMD_INDEX_SIZE + 3)
618a6c697bSAneesh Kumar K.V #define H_PMD_FRAG_NR	(PAGE_SIZE >> H_PMD_FRAG_SIZE_SHIFT)
621a2f7789SAneesh Kumar K.V 
631a2f7789SAneesh Kumar K.V /* memory key bits, only 8 keys supported */
6433699023SAneesh Kumar K.V #define H_PTE_PKEY_BIT4	0
6533699023SAneesh Kumar K.V #define H_PTE_PKEY_BIT3	0
66ee8b3933SAneesh Kumar K.V #define H_PTE_PKEY_BIT2	_RPAGE_PKEY_BIT3
67ee8b3933SAneesh Kumar K.V #define H_PTE_PKEY_BIT1	_RPAGE_PKEY_BIT2
68ee8b3933SAneesh Kumar K.V #define H_PTE_PKEY_BIT0	_RPAGE_PKEY_BIT1
6933699023SAneesh Kumar K.V 
701a2f7789SAneesh Kumar K.V 
71ab537dcaSAneesh Kumar K.V /*
72368ced78SAneesh Kumar K.V  * On all 4K setups, remap_4k_pfn() equates to remap_pfn_range()
73ab537dcaSAneesh Kumar K.V  */
74ab537dcaSAneesh Kumar K.V #define remap_4k_pfn(vma, addr, pfn, prot)	\
75ab537dcaSAneesh Kumar K.V 	remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE, (prot))
76ab537dcaSAneesh Kumar K.V 
7726a344aeSAneesh Kumar K.V #ifdef CONFIG_HUGETLB_PAGE
hash__hugepd_ok(hugepd_t hpd)78c0a6c719SAneesh Kumar K.V static inline int hash__hugepd_ok(hugepd_t hpd)
7926a344aeSAneesh Kumar K.V {
8020717e1fSAneesh Kumar K.V 	unsigned long hpdval = hpd_val(hpd);
8126a344aeSAneesh Kumar K.V 	/*
826a119eaeSAneesh Kumar K.V 	 * if it is not a pte and have hugepd shift mask
836a119eaeSAneesh Kumar K.V 	 * set, then it is a hugepd directory pointer
8426a344aeSAneesh Kumar K.V 	 */
85f1981b5bSAneesh Kumar K.V 	if (!(hpdval & _PAGE_PTE) && (hpdval & _PAGE_PRESENT) &&
8620717e1fSAneesh Kumar K.V 	    ((hpdval & HUGEPD_SHIFT_MASK) != 0))
876a119eaeSAneesh Kumar K.V 		return true;
886a119eaeSAneesh Kumar K.V 	return false;
8926a344aeSAneesh Kumar K.V }
9026a344aeSAneesh Kumar K.V #endif
9126a344aeSAneesh Kumar K.V 
9259aa31fdSRam Pai /*
9359aa31fdSRam Pai  * 4K PTE format is different from 64K PTE format. Saving the hash_slot is just
9459aa31fdSRam Pai  * a matter of returning the PTE bits that need to be modified. On 64K PTE,
9559aa31fdSRam Pai  * things are a little more involved and hence needs many more parameters to
9659aa31fdSRam Pai  * accomplish the same. However we want to abstract this out from the caller by
9759aa31fdSRam Pai  * keeping the prototype consistent across the two formats.
9859aa31fdSRam Pai  */
pte_set_hidx(pte_t * ptep,real_pte_t rpte,unsigned int subpg_index,unsigned long hidx,int offset)9959aa31fdSRam Pai static inline unsigned long pte_set_hidx(pte_t *ptep, real_pte_t rpte,
100ff31e105SAneesh Kumar K.V 					 unsigned int subpg_index, unsigned long hidx,
101ff31e105SAneesh Kumar K.V 					 int offset)
10259aa31fdSRam Pai {
10359aa31fdSRam Pai 	return (hidx << H_PAGE_F_GIX_SHIFT) &
10459aa31fdSRam Pai 		(H_PAGE_F_SECOND | H_PAGE_F_GIX);
10559aa31fdSRam Pai }
10659aa31fdSRam Pai 
107ab624762SAneesh Kumar K.V #ifdef CONFIG_TRANSPARENT_HUGEPAGE
108ab624762SAneesh Kumar K.V 
get_hpte_slot_array(pmd_t * pmdp)109ab624762SAneesh Kumar K.V static inline char *get_hpte_slot_array(pmd_t *pmdp)
110ab624762SAneesh Kumar K.V {
111ab624762SAneesh Kumar K.V 	BUG();
112ab624762SAneesh Kumar K.V 	return NULL;
113ab624762SAneesh Kumar K.V }
114ab624762SAneesh Kumar K.V 
hpte_valid(unsigned char * hpte_slot_array,int index)115ab624762SAneesh Kumar K.V static inline unsigned int hpte_valid(unsigned char *hpte_slot_array, int index)
116ab624762SAneesh Kumar K.V {
117ab624762SAneesh Kumar K.V 	BUG();
118ab624762SAneesh Kumar K.V 	return 0;
119ab624762SAneesh Kumar K.V }
120ab624762SAneesh Kumar K.V 
hpte_hash_index(unsigned char * hpte_slot_array,int index)121ab624762SAneesh Kumar K.V static inline unsigned int hpte_hash_index(unsigned char *hpte_slot_array,
122ab624762SAneesh Kumar K.V 					   int index)
123ab624762SAneesh Kumar K.V {
124ab624762SAneesh Kumar K.V 	BUG();
125ab624762SAneesh Kumar K.V 	return 0;
126ab624762SAneesh Kumar K.V }
127ab624762SAneesh Kumar K.V 
mark_hpte_slot_valid(unsigned char * hpte_slot_array,unsigned int index,unsigned int hidx)128ab624762SAneesh Kumar K.V static inline void mark_hpte_slot_valid(unsigned char *hpte_slot_array,
129ab624762SAneesh Kumar K.V 					unsigned int index, unsigned int hidx)
130ab624762SAneesh Kumar K.V {
131ab624762SAneesh Kumar K.V 	BUG();
132ab624762SAneesh Kumar K.V }
133ab624762SAneesh Kumar K.V 
hash__pmd_trans_huge(pmd_t pmd)134ab624762SAneesh Kumar K.V static inline int hash__pmd_trans_huge(pmd_t pmd)
135ab624762SAneesh Kumar K.V {
136ab624762SAneesh Kumar K.V 	return 0;
137ab624762SAneesh Kumar K.V }
138ab624762SAneesh Kumar K.V 
hash__pmd_mkhuge(pmd_t pmd)139ab624762SAneesh Kumar K.V static inline pmd_t hash__pmd_mkhuge(pmd_t pmd)
140ab624762SAneesh Kumar K.V {
141ab624762SAneesh Kumar K.V 	BUG();
142ab624762SAneesh Kumar K.V 	return pmd;
143ab624762SAneesh Kumar K.V }
144ab624762SAneesh Kumar K.V 
145ab624762SAneesh Kumar K.V extern unsigned long hash__pmd_hugepage_update(struct mm_struct *mm,
146ab624762SAneesh Kumar K.V 					   unsigned long addr, pmd_t *pmdp,
147ab624762SAneesh Kumar K.V 					   unsigned long clr, unsigned long set);
148ab624762SAneesh Kumar K.V extern pmd_t hash__pmdp_collapse_flush(struct vm_area_struct *vma,
149ab624762SAneesh Kumar K.V 				   unsigned long address, pmd_t *pmdp);
150ab624762SAneesh Kumar K.V extern void hash__pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
151ab624762SAneesh Kumar K.V 					 pgtable_t pgtable);
152ab624762SAneesh Kumar K.V extern pgtable_t hash__pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp);
153ab624762SAneesh Kumar K.V extern pmd_t hash__pmdp_huge_get_and_clear(struct mm_struct *mm,
154ab624762SAneesh Kumar K.V 				       unsigned long addr, pmd_t *pmdp);
155ab624762SAneesh Kumar K.V extern int hash__has_transparent_hugepage(void);
156ab624762SAneesh Kumar K.V #endif
157ab624762SAneesh Kumar K.V 
hash__pmd_mkdevmap(pmd_t pmd)15836b78402SAneesh Kumar K.V static inline pmd_t hash__pmd_mkdevmap(pmd_t pmd)
15936b78402SAneesh Kumar K.V {
16036b78402SAneesh Kumar K.V 	BUG();
16136b78402SAneesh Kumar K.V 	return pmd;
16236b78402SAneesh Kumar K.V }
16336b78402SAneesh Kumar K.V 
164ab537dcaSAneesh Kumar K.V #endif /* !__ASSEMBLY__ */
165ab537dcaSAneesh Kumar K.V 
166ab537dcaSAneesh Kumar K.V #endif /* _ASM_POWERPC_BOOK3S_64_HASH_4K_H */
167