xref: /linux/arch/powerpc/include/asm/book3s/64/hash-4k.h (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
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 /*
26b32d5d7eSAneesh Kumar K.V  * Limits the linear mapping range
27b32d5d7eSAneesh Kumar K.V  */
28b32d5d7eSAneesh Kumar K.V #define H_MAX_PHYSMEM_BITS	46
29b32d5d7eSAneesh Kumar K.V 
30b32d5d7eSAneesh 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 
7759aa31fdSRam Pai /*
78*8ae4f16fSMichael Ellerman  * With 4K page size the real_pte machinery is all nops.
79*8ae4f16fSMichael Ellerman  */
80*8ae4f16fSMichael Ellerman #define __real_pte(e, p, o)		((real_pte_t){(e)})
81*8ae4f16fSMichael Ellerman #define __rpte_to_pte(r)	((r).pte)
82*8ae4f16fSMichael Ellerman #define __rpte_to_hidx(r,index)	(pte_val(__rpte_to_pte(r)) >> H_PAGE_F_GIX_SHIFT)
83*8ae4f16fSMichael Ellerman 
84*8ae4f16fSMichael Ellerman #define pte_iterate_hashed_subpages(rpte, psize, va, index, shift)       \
85*8ae4f16fSMichael Ellerman 	do {							         \
86*8ae4f16fSMichael Ellerman 		index = 0;					         \
87*8ae4f16fSMichael Ellerman 		shift = mmu_psize_defs[psize].shift;		         \
88*8ae4f16fSMichael Ellerman 
89*8ae4f16fSMichael Ellerman #define pte_iterate_hashed_end() } while(0)
90*8ae4f16fSMichael Ellerman 
91*8ae4f16fSMichael Ellerman /*
92*8ae4f16fSMichael Ellerman  * We expect this to be called only for user addresses or kernel virtual
93*8ae4f16fSMichael Ellerman  * addresses other than the linear mapping.
94*8ae4f16fSMichael Ellerman  */
95*8ae4f16fSMichael Ellerman #define pte_pagesize_index(mm, addr, pte)	MMU_PAGE_4K
96*8ae4f16fSMichael Ellerman 
97*8ae4f16fSMichael Ellerman /*
9859aa31fdSRam Pai  * 4K PTE format is different from 64K PTE format. Saving the hash_slot is just
9959aa31fdSRam Pai  * a matter of returning the PTE bits that need to be modified. On 64K PTE,
10059aa31fdSRam Pai  * things are a little more involved and hence needs many more parameters to
10159aa31fdSRam Pai  * accomplish the same. However we want to abstract this out from the caller by
10259aa31fdSRam Pai  * keeping the prototype consistent across the two formats.
10359aa31fdSRam Pai  */
pte_set_hidx(pte_t * ptep,real_pte_t rpte,unsigned int subpg_index,unsigned long hidx,int offset)10459aa31fdSRam Pai static inline unsigned long pte_set_hidx(pte_t *ptep, real_pte_t rpte,
105ff31e105SAneesh Kumar K.V 					 unsigned int subpg_index, unsigned long hidx,
106ff31e105SAneesh Kumar K.V 					 int offset)
10759aa31fdSRam Pai {
10859aa31fdSRam Pai 	return (hidx << H_PAGE_F_GIX_SHIFT) &
10959aa31fdSRam Pai 		(H_PAGE_F_SECOND | H_PAGE_F_GIX);
11059aa31fdSRam Pai }
11159aa31fdSRam Pai 
112ab624762SAneesh Kumar K.V #ifdef CONFIG_TRANSPARENT_HUGEPAGE
113ab624762SAneesh Kumar K.V 
get_hpte_slot_array(pmd_t * pmdp)114ab624762SAneesh Kumar K.V static inline char *get_hpte_slot_array(pmd_t *pmdp)
115ab624762SAneesh Kumar K.V {
116ab624762SAneesh Kumar K.V 	BUG();
117ab624762SAneesh Kumar K.V 	return NULL;
118ab624762SAneesh Kumar K.V }
119ab624762SAneesh Kumar K.V 
hpte_valid(unsigned char * hpte_slot_array,int index)120ab624762SAneesh Kumar K.V static inline unsigned int hpte_valid(unsigned char *hpte_slot_array, int index)
121ab624762SAneesh Kumar K.V {
122ab624762SAneesh Kumar K.V 	BUG();
123ab624762SAneesh Kumar K.V 	return 0;
124ab624762SAneesh Kumar K.V }
125ab624762SAneesh Kumar K.V 
hpte_hash_index(unsigned char * hpte_slot_array,int index)126ab624762SAneesh Kumar K.V static inline unsigned int hpte_hash_index(unsigned char *hpte_slot_array,
127ab624762SAneesh Kumar K.V 					   int index)
128ab624762SAneesh Kumar K.V {
129ab624762SAneesh Kumar K.V 	BUG();
130ab624762SAneesh Kumar K.V 	return 0;
131ab624762SAneesh Kumar K.V }
132ab624762SAneesh Kumar K.V 
mark_hpte_slot_valid(unsigned char * hpte_slot_array,unsigned int index,unsigned int hidx)133ab624762SAneesh Kumar K.V static inline void mark_hpte_slot_valid(unsigned char *hpte_slot_array,
134ab624762SAneesh Kumar K.V 					unsigned int index, unsigned int hidx)
135ab624762SAneesh Kumar K.V {
136ab624762SAneesh Kumar K.V 	BUG();
137ab624762SAneesh Kumar K.V }
138ab624762SAneesh Kumar K.V 
hash__pmd_trans_huge(pmd_t pmd)139ab624762SAneesh Kumar K.V static inline int hash__pmd_trans_huge(pmd_t pmd)
140ab624762SAneesh Kumar K.V {
141ab624762SAneesh Kumar K.V 	return 0;
142ab624762SAneesh Kumar K.V }
143ab624762SAneesh Kumar K.V 
hash__pmd_mkhuge(pmd_t pmd)144ab624762SAneesh Kumar K.V static inline pmd_t hash__pmd_mkhuge(pmd_t pmd)
145ab624762SAneesh Kumar K.V {
146ab624762SAneesh Kumar K.V 	BUG();
147ab624762SAneesh Kumar K.V 	return pmd;
148ab624762SAneesh Kumar K.V }
149ab624762SAneesh Kumar K.V 
150ab624762SAneesh Kumar K.V extern unsigned long hash__pmd_hugepage_update(struct mm_struct *mm,
151ab624762SAneesh Kumar K.V 					   unsigned long addr, pmd_t *pmdp,
152ab624762SAneesh Kumar K.V 					   unsigned long clr, unsigned long set);
153ab624762SAneesh Kumar K.V extern pmd_t hash__pmdp_collapse_flush(struct vm_area_struct *vma,
154ab624762SAneesh Kumar K.V 				   unsigned long address, pmd_t *pmdp);
155ab624762SAneesh Kumar K.V extern void hash__pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
156ab624762SAneesh Kumar K.V 					 pgtable_t pgtable);
157ab624762SAneesh Kumar K.V extern pgtable_t hash__pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp);
158ab624762SAneesh Kumar K.V extern pmd_t hash__pmdp_huge_get_and_clear(struct mm_struct *mm,
159ab624762SAneesh Kumar K.V 				       unsigned long addr, pmd_t *pmdp);
160ab624762SAneesh Kumar K.V extern int hash__has_transparent_hugepage(void);
161ab624762SAneesh Kumar K.V #endif
162ab624762SAneesh Kumar K.V 
hash__pmd_mkdevmap(pmd_t pmd)16336b78402SAneesh Kumar K.V static inline pmd_t hash__pmd_mkdevmap(pmd_t pmd)
16436b78402SAneesh Kumar K.V {
16536b78402SAneesh Kumar K.V 	BUG();
16636b78402SAneesh Kumar K.V 	return pmd;
16736b78402SAneesh Kumar K.V }
16836b78402SAneesh Kumar K.V 
169ab537dcaSAneesh Kumar K.V #endif /* !__ASSEMBLY__ */
170ab537dcaSAneesh Kumar K.V 
171ab537dcaSAneesh Kumar K.V #endif /* _ASM_POWERPC_BOOK3S_64_HASH_4K_H */
172