1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_BOOK3S_64_PGTABLE_4K_H
3 #define _ASM_POWERPC_BOOK3S_64_PGTABLE_4K_H
4 /*
5  * hash 4k can't share hugetlb and also doesn't support THP
6  */
7 #ifndef __ASSEMBLY__
8 #ifdef CONFIG_HUGETLB_PAGE
9 static inline int pmd_huge(pmd_t pmd)
10 {
11 	/*
12 	 * leaf pte for huge page
13 	 */
14 	if (radix_enabled())
15 		return !!(pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE));
16 	return 0;
17 }
18 
19 static inline int pud_huge(pud_t pud)
20 {
21 	/*
22 	 * leaf pte for huge page
23 	 */
24 	if (radix_enabled())
25 		return !!(pud_raw(pud) & cpu_to_be64(_PAGE_PTE));
26 	return 0;
27 }
28 
29 /*
30  * With radix , we have hugepage ptes in the pud and pmd entries. We don't
31  * need to setup hugepage directory for them. Our pte and page directory format
32  * enable us to have this enabled.
33  */
34 static inline int hugepd_ok(hugepd_t hpd)
35 {
36 	if (radix_enabled())
37 		return 0;
38 	return hash__hugepd_ok(hpd);
39 }
40 #define is_hugepd(hpd)		(hugepd_ok(hpd))
41 
42 /*
43  * 16M and 16G huge page directory tables are allocated from slab cache
44  *
45  */
46 #define H_16M_CACHE_INDEX (PAGE_SHIFT + H_PTE_INDEX_SIZE + H_PMD_INDEX_SIZE - 24)
47 #define H_16G_CACHE_INDEX                                                      \
48 	(PAGE_SHIFT + H_PTE_INDEX_SIZE + H_PMD_INDEX_SIZE + H_PUD_INDEX_SIZE - 34)
49 
50 static inline int get_hugepd_cache_index(int index)
51 {
52 	switch (index) {
53 	case H_16M_CACHE_INDEX:
54 		return HTLB_16M_INDEX;
55 	case H_16G_CACHE_INDEX:
56 		return HTLB_16G_INDEX;
57 	default:
58 		BUG();
59 	}
60 	/* should not reach */
61 }
62 
63 #endif /* CONFIG_HUGETLB_PAGE */
64 
65 #endif /* __ASSEMBLY__ */
66 
67 #endif /*_ASM_POWERPC_BOOK3S_64_PGTABLE_4K_H */
68