18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_BOOK3S_64_HASH_64K_H
38c2ecf20Sopenharmony_ci#define _ASM_POWERPC_BOOK3S_64_HASH_64K_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#define H_PTE_INDEX_SIZE   8  // size: 8B <<  8 = 2KB, maps 2^8  x 64KB = 16MB
68c2ecf20Sopenharmony_ci#define H_PMD_INDEX_SIZE  10  // size: 8B << 10 = 8KB, maps 2^10 x 16MB = 16GB
78c2ecf20Sopenharmony_ci#define H_PUD_INDEX_SIZE  10  // size: 8B << 10 = 8KB, maps 2^10 x 16GB = 16TB
88c2ecf20Sopenharmony_ci#define H_PGD_INDEX_SIZE   8  // size: 8B <<  8 = 2KB, maps 2^8  x 16TB =  4PB
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/*
118c2ecf20Sopenharmony_ci * If we store section details in page->flags we can't increase the MAX_PHYSMEM_BITS
128c2ecf20Sopenharmony_ci * if we increase SECTIONS_WIDTH we will not store node details in page->flags and
138c2ecf20Sopenharmony_ci * page_to_nid does a page->section->node lookup
148c2ecf20Sopenharmony_ci * Hence only increase for VMEMMAP. Further depending on SPARSEMEM_EXTREME reduce
158c2ecf20Sopenharmony_ci * memory requirements with large number of sections.
168c2ecf20Sopenharmony_ci * 51 bits is the max physical real address on POWER9
178c2ecf20Sopenharmony_ci */
188c2ecf20Sopenharmony_ci#if defined(CONFIG_SPARSEMEM_VMEMMAP) && defined(CONFIG_SPARSEMEM_EXTREME)
198c2ecf20Sopenharmony_ci#define H_MAX_PHYSMEM_BITS	51
208c2ecf20Sopenharmony_ci#else
218c2ecf20Sopenharmony_ci#define H_MAX_PHYSMEM_BITS	46
228c2ecf20Sopenharmony_ci#endif
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/*
258c2ecf20Sopenharmony_ci * Each context is 512TB size. SLB miss for first context/default context
268c2ecf20Sopenharmony_ci * is handled in the hotpath.
278c2ecf20Sopenharmony_ci */
288c2ecf20Sopenharmony_ci#define MAX_EA_BITS_PER_CONTEXT		49
298c2ecf20Sopenharmony_ci#define REGION_SHIFT		MAX_EA_BITS_PER_CONTEXT
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/*
328c2ecf20Sopenharmony_ci * We use one context for each MAP area.
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci#define H_KERN_MAP_SIZE		(1UL << MAX_EA_BITS_PER_CONTEXT)
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/*
378c2ecf20Sopenharmony_ci * Define the address range of the kernel non-linear virtual area
388c2ecf20Sopenharmony_ci * 2PB
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_ci#define H_KERN_VIRT_START	ASM_CONST(0xc008000000000000)
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci/*
438c2ecf20Sopenharmony_ci * 64k aligned address free up few of the lower bits of RPN for us
448c2ecf20Sopenharmony_ci * We steal that here. For more deatils look at pte_pfn/pfn_pte()
458c2ecf20Sopenharmony_ci */
468c2ecf20Sopenharmony_ci#define H_PAGE_COMBO	_RPAGE_RPN0 /* this is a combo 4k page */
478c2ecf20Sopenharmony_ci#define H_PAGE_4K_PFN	_RPAGE_RPN1 /* PFN is for a single 4k page */
488c2ecf20Sopenharmony_ci#define H_PAGE_BUSY	_RPAGE_RSV1     /* software: PTE & hash are busy */
498c2ecf20Sopenharmony_ci#define H_PAGE_HASHPTE	_RPAGE_RPN43	/* PTE has associated HPTE */
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/* memory key bits. */
528c2ecf20Sopenharmony_ci#define H_PTE_PKEY_BIT4		_RPAGE_PKEY_BIT4
538c2ecf20Sopenharmony_ci#define H_PTE_PKEY_BIT3		_RPAGE_PKEY_BIT3
548c2ecf20Sopenharmony_ci#define H_PTE_PKEY_BIT2		_RPAGE_PKEY_BIT2
558c2ecf20Sopenharmony_ci#define H_PTE_PKEY_BIT1		_RPAGE_PKEY_BIT1
568c2ecf20Sopenharmony_ci#define H_PTE_PKEY_BIT0		_RPAGE_PKEY_BIT0
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/*
598c2ecf20Sopenharmony_ci * We need to differentiate between explicit huge page and THP huge
608c2ecf20Sopenharmony_ci * page, since THP huge page also need to track real subpage details
618c2ecf20Sopenharmony_ci */
628c2ecf20Sopenharmony_ci#define H_PAGE_THP_HUGE  H_PAGE_4K_PFN
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/* PTE flags to conserve for HPTE identification */
658c2ecf20Sopenharmony_ci#define _PAGE_HPTEFLAGS (H_PAGE_BUSY | H_PAGE_HASHPTE | H_PAGE_COMBO)
668c2ecf20Sopenharmony_ci/*
678c2ecf20Sopenharmony_ci * We use a 2K PTE page fragment and another 2K for storing
688c2ecf20Sopenharmony_ci * real_pte_t hash index
698c2ecf20Sopenharmony_ci * 8 bytes per each pte entry and another 8 bytes for storing
708c2ecf20Sopenharmony_ci * slot details.
718c2ecf20Sopenharmony_ci */
728c2ecf20Sopenharmony_ci#define H_PTE_FRAG_SIZE_SHIFT  (H_PTE_INDEX_SIZE + 3 + 1)
738c2ecf20Sopenharmony_ci#define H_PTE_FRAG_NR	(PAGE_SIZE >> H_PTE_FRAG_SIZE_SHIFT)
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci#if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLB_PAGE)
768c2ecf20Sopenharmony_ci#define H_PMD_FRAG_SIZE_SHIFT  (H_PMD_INDEX_SIZE + 3 + 1)
778c2ecf20Sopenharmony_ci#else
788c2ecf20Sopenharmony_ci#define H_PMD_FRAG_SIZE_SHIFT  (H_PMD_INDEX_SIZE + 3)
798c2ecf20Sopenharmony_ci#endif
808c2ecf20Sopenharmony_ci#define H_PMD_FRAG_NR	(PAGE_SIZE >> H_PMD_FRAG_SIZE_SHIFT)
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
838c2ecf20Sopenharmony_ci#include <asm/errno.h>
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci/*
868c2ecf20Sopenharmony_ci * With 64K pages on hash table, we have a special PTE format that
878c2ecf20Sopenharmony_ci * uses a second "half" of the page table to encode sub-page information
888c2ecf20Sopenharmony_ci * in order to deal with 64K made of 4K HW pages. Thus we override the
898c2ecf20Sopenharmony_ci * generic accessors and iterators here
908c2ecf20Sopenharmony_ci */
918c2ecf20Sopenharmony_ci#define __real_pte __real_pte
928c2ecf20Sopenharmony_cistatic inline real_pte_t __real_pte(pte_t pte, pte_t *ptep, int offset)
938c2ecf20Sopenharmony_ci{
948c2ecf20Sopenharmony_ci	real_pte_t rpte;
958c2ecf20Sopenharmony_ci	unsigned long *hidxp;
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	rpte.pte = pte;
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	/*
1008c2ecf20Sopenharmony_ci	 * Ensure that we do not read the hidx before we read the PTE. Because
1018c2ecf20Sopenharmony_ci	 * the writer side is expected to finish writing the hidx first followed
1028c2ecf20Sopenharmony_ci	 * by the PTE, by using smp_wmb(). pte_set_hash_slot() ensures that.
1038c2ecf20Sopenharmony_ci	 */
1048c2ecf20Sopenharmony_ci	smp_rmb();
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	hidxp = (unsigned long *)(ptep + offset);
1078c2ecf20Sopenharmony_ci	rpte.hidx = *hidxp;
1088c2ecf20Sopenharmony_ci	return rpte;
1098c2ecf20Sopenharmony_ci}
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci/*
1128c2ecf20Sopenharmony_ci * shift the hidx representation by one-modulo-0xf; i.e hidx 0 is respresented
1138c2ecf20Sopenharmony_ci * as 1, 1 as 2,... , and 0xf as 0.  This convention lets us represent a
1148c2ecf20Sopenharmony_ci * invalid hidx 0xf with a 0x0 bit value. PTEs are anyway zero'd when
1158c2ecf20Sopenharmony_ci * allocated. We dont have to zero them gain; thus save on the initialization.
1168c2ecf20Sopenharmony_ci */
1178c2ecf20Sopenharmony_ci#define HIDX_UNSHIFT_BY_ONE(x) ((x + 0xfUL) & 0xfUL) /* shift backward by one */
1188c2ecf20Sopenharmony_ci#define HIDX_SHIFT_BY_ONE(x) ((x + 0x1UL) & 0xfUL)   /* shift forward by one */
1198c2ecf20Sopenharmony_ci#define HIDX_BITS(x, index)  (x << (index << 2))
1208c2ecf20Sopenharmony_ci#define BITS_TO_HIDX(x, index)  ((x >> (index << 2)) & 0xfUL)
1218c2ecf20Sopenharmony_ci#define INVALID_RPTE_HIDX  0x0UL
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_cistatic inline unsigned long __rpte_to_hidx(real_pte_t rpte, unsigned long index)
1248c2ecf20Sopenharmony_ci{
1258c2ecf20Sopenharmony_ci	return HIDX_UNSHIFT_BY_ONE(BITS_TO_HIDX(rpte.hidx, index));
1268c2ecf20Sopenharmony_ci}
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci/*
1298c2ecf20Sopenharmony_ci * Commit the hidx and return PTE bits that needs to be modified. The caller is
1308c2ecf20Sopenharmony_ci * expected to modify the PTE bits accordingly and commit the PTE to memory.
1318c2ecf20Sopenharmony_ci */
1328c2ecf20Sopenharmony_cistatic inline unsigned long pte_set_hidx(pte_t *ptep, real_pte_t rpte,
1338c2ecf20Sopenharmony_ci					 unsigned int subpg_index,
1348c2ecf20Sopenharmony_ci					 unsigned long hidx, int offset)
1358c2ecf20Sopenharmony_ci{
1368c2ecf20Sopenharmony_ci	unsigned long *hidxp = (unsigned long *)(ptep + offset);
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	rpte.hidx &= ~HIDX_BITS(0xfUL, subpg_index);
1398c2ecf20Sopenharmony_ci	*hidxp = rpte.hidx  | HIDX_BITS(HIDX_SHIFT_BY_ONE(hidx), subpg_index);
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	/*
1428c2ecf20Sopenharmony_ci	 * Anyone reading PTE must ensure hidx bits are read after reading the
1438c2ecf20Sopenharmony_ci	 * PTE by using the read-side barrier smp_rmb(). __real_pte() can be
1448c2ecf20Sopenharmony_ci	 * used for that.
1458c2ecf20Sopenharmony_ci	 */
1468c2ecf20Sopenharmony_ci	smp_wmb();
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	/* No PTE bits to be modified, return 0x0UL */
1498c2ecf20Sopenharmony_ci	return 0x0UL;
1508c2ecf20Sopenharmony_ci}
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci#define __rpte_to_pte(r)	((r).pte)
1538c2ecf20Sopenharmony_ciextern bool __rpte_sub_valid(real_pte_t rpte, unsigned long index);
1548c2ecf20Sopenharmony_ci/*
1558c2ecf20Sopenharmony_ci * Trick: we set __end to va + 64k, which happens works for
1568c2ecf20Sopenharmony_ci * a 16M page as well as we want only one iteration
1578c2ecf20Sopenharmony_ci */
1588c2ecf20Sopenharmony_ci#define pte_iterate_hashed_subpages(rpte, psize, vpn, index, shift)	\
1598c2ecf20Sopenharmony_ci	do {								\
1608c2ecf20Sopenharmony_ci		unsigned long __end = vpn + (1UL << (PAGE_SHIFT - VPN_SHIFT));	\
1618c2ecf20Sopenharmony_ci		unsigned __split = (psize == MMU_PAGE_4K ||		\
1628c2ecf20Sopenharmony_ci				    psize == MMU_PAGE_64K_AP);		\
1638c2ecf20Sopenharmony_ci		shift = mmu_psize_defs[psize].shift;			\
1648c2ecf20Sopenharmony_ci		for (index = 0; vpn < __end; index++,			\
1658c2ecf20Sopenharmony_ci			     vpn += (1L << (shift - VPN_SHIFT))) {	\
1668c2ecf20Sopenharmony_ci		if (!__split || __rpte_sub_valid(rpte, index))
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci#define pte_iterate_hashed_end()  } } while(0)
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci#define pte_pagesize_index(mm, addr, pte)	\
1718c2ecf20Sopenharmony_ci	(((pte) & H_PAGE_COMBO)? MMU_PAGE_4K: MMU_PAGE_64K)
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ciextern int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
1748c2ecf20Sopenharmony_ci			   unsigned long pfn, unsigned long size, pgprot_t);
1758c2ecf20Sopenharmony_cistatic inline int hash__remap_4k_pfn(struct vm_area_struct *vma, unsigned long addr,
1768c2ecf20Sopenharmony_ci				 unsigned long pfn, pgprot_t prot)
1778c2ecf20Sopenharmony_ci{
1788c2ecf20Sopenharmony_ci	if (pfn > (PTE_RPN_MASK >> PAGE_SHIFT)) {
1798c2ecf20Sopenharmony_ci		WARN(1, "remap_4k_pfn called with wrong pfn value\n");
1808c2ecf20Sopenharmony_ci		return -EINVAL;
1818c2ecf20Sopenharmony_ci	}
1828c2ecf20Sopenharmony_ci	return remap_pfn_range(vma, addr, pfn, PAGE_SIZE,
1838c2ecf20Sopenharmony_ci			       __pgprot(pgprot_val(prot) | H_PAGE_4K_PFN));
1848c2ecf20Sopenharmony_ci}
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci#define H_PTE_TABLE_SIZE	PTE_FRAG_SIZE
1878c2ecf20Sopenharmony_ci#if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined (CONFIG_HUGETLB_PAGE)
1888c2ecf20Sopenharmony_ci#define H_PMD_TABLE_SIZE	((sizeof(pmd_t) << PMD_INDEX_SIZE) + \
1898c2ecf20Sopenharmony_ci				 (sizeof(unsigned long) << PMD_INDEX_SIZE))
1908c2ecf20Sopenharmony_ci#else
1918c2ecf20Sopenharmony_ci#define H_PMD_TABLE_SIZE	(sizeof(pmd_t) << PMD_INDEX_SIZE)
1928c2ecf20Sopenharmony_ci#endif
1938c2ecf20Sopenharmony_ci#ifdef CONFIG_HUGETLB_PAGE
1948c2ecf20Sopenharmony_ci#define H_PUD_TABLE_SIZE	((sizeof(pud_t) << PUD_INDEX_SIZE) +	\
1958c2ecf20Sopenharmony_ci				 (sizeof(unsigned long) << PUD_INDEX_SIZE))
1968c2ecf20Sopenharmony_ci#else
1978c2ecf20Sopenharmony_ci#define H_PUD_TABLE_SIZE	(sizeof(pud_t) << PUD_INDEX_SIZE)
1988c2ecf20Sopenharmony_ci#endif
1998c2ecf20Sopenharmony_ci#define H_PGD_TABLE_SIZE	(sizeof(pgd_t) << PGD_INDEX_SIZE)
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci#ifdef CONFIG_TRANSPARENT_HUGEPAGE
2028c2ecf20Sopenharmony_cistatic inline char *get_hpte_slot_array(pmd_t *pmdp)
2038c2ecf20Sopenharmony_ci{
2048c2ecf20Sopenharmony_ci	/*
2058c2ecf20Sopenharmony_ci	 * The hpte hindex is stored in the pgtable whose address is in the
2068c2ecf20Sopenharmony_ci	 * second half of the PMD
2078c2ecf20Sopenharmony_ci	 *
2088c2ecf20Sopenharmony_ci	 * Order this load with the test for pmd_trans_huge in the caller
2098c2ecf20Sopenharmony_ci	 */
2108c2ecf20Sopenharmony_ci	smp_rmb();
2118c2ecf20Sopenharmony_ci	return *(char **)(pmdp + PTRS_PER_PMD);
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci}
2158c2ecf20Sopenharmony_ci/*
2168c2ecf20Sopenharmony_ci * The linux hugepage PMD now include the pmd entries followed by the address
2178c2ecf20Sopenharmony_ci * to the stashed pgtable_t. The stashed pgtable_t contains the hpte bits.
2188c2ecf20Sopenharmony_ci * [ 000 | 1 bit secondary | 3 bit hidx | 1 bit valid]. We use one byte per
2198c2ecf20Sopenharmony_ci * each HPTE entry. With 16MB hugepage and 64K HPTE we need 256 entries and
2208c2ecf20Sopenharmony_ci * with 4K HPTE we need 4096 entries. Both will fit in a 4K pgtable_t.
2218c2ecf20Sopenharmony_ci *
2228c2ecf20Sopenharmony_ci * The top three bits are intentionally left as zero. This memory location
2238c2ecf20Sopenharmony_ci * are also used as normal page PTE pointers. So if we have any pointers
2248c2ecf20Sopenharmony_ci * left around while we collapse a hugepage, we need to make sure
2258c2ecf20Sopenharmony_ci * _PAGE_PRESENT bit of that is zero when we look at them
2268c2ecf20Sopenharmony_ci */
2278c2ecf20Sopenharmony_cistatic inline unsigned int hpte_valid(unsigned char *hpte_slot_array, int index)
2288c2ecf20Sopenharmony_ci{
2298c2ecf20Sopenharmony_ci	return hpte_slot_array[index] & 0x1;
2308c2ecf20Sopenharmony_ci}
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_cistatic inline unsigned int hpte_hash_index(unsigned char *hpte_slot_array,
2338c2ecf20Sopenharmony_ci					   int index)
2348c2ecf20Sopenharmony_ci{
2358c2ecf20Sopenharmony_ci	return hpte_slot_array[index] >> 1;
2368c2ecf20Sopenharmony_ci}
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_cistatic inline void mark_hpte_slot_valid(unsigned char *hpte_slot_array,
2398c2ecf20Sopenharmony_ci					unsigned int index, unsigned int hidx)
2408c2ecf20Sopenharmony_ci{
2418c2ecf20Sopenharmony_ci	hpte_slot_array[index] = (hidx << 1) | 0x1;
2428c2ecf20Sopenharmony_ci}
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci/*
2458c2ecf20Sopenharmony_ci *
2468c2ecf20Sopenharmony_ci * For core kernel code by design pmd_trans_huge is never run on any hugetlbfs
2478c2ecf20Sopenharmony_ci * page. The hugetlbfs page table walking and mangling paths are totally
2488c2ecf20Sopenharmony_ci * separated form the core VM paths and they're differentiated by
2498c2ecf20Sopenharmony_ci *  VM_HUGETLB being set on vm_flags well before any pmd_trans_huge could run.
2508c2ecf20Sopenharmony_ci *
2518c2ecf20Sopenharmony_ci * pmd_trans_huge() is defined as false at build time if
2528c2ecf20Sopenharmony_ci * CONFIG_TRANSPARENT_HUGEPAGE=n to optimize away code blocks at build
2538c2ecf20Sopenharmony_ci * time in such case.
2548c2ecf20Sopenharmony_ci *
2558c2ecf20Sopenharmony_ci * For ppc64 we need to differntiate from explicit hugepages from THP, because
2568c2ecf20Sopenharmony_ci * for THP we also track the subpage details at the pmd level. We don't do
2578c2ecf20Sopenharmony_ci * that for explicit huge pages.
2588c2ecf20Sopenharmony_ci *
2598c2ecf20Sopenharmony_ci */
2608c2ecf20Sopenharmony_cistatic inline int hash__pmd_trans_huge(pmd_t pmd)
2618c2ecf20Sopenharmony_ci{
2628c2ecf20Sopenharmony_ci	return !!((pmd_val(pmd) & (_PAGE_PTE | H_PAGE_THP_HUGE | _PAGE_DEVMAP)) ==
2638c2ecf20Sopenharmony_ci		  (_PAGE_PTE | H_PAGE_THP_HUGE));
2648c2ecf20Sopenharmony_ci}
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_cistatic inline int hash__pmd_same(pmd_t pmd_a, pmd_t pmd_b)
2678c2ecf20Sopenharmony_ci{
2688c2ecf20Sopenharmony_ci	return (((pmd_raw(pmd_a) ^ pmd_raw(pmd_b)) & ~cpu_to_be64(_PAGE_HPTEFLAGS)) == 0);
2698c2ecf20Sopenharmony_ci}
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_cistatic inline pmd_t hash__pmd_mkhuge(pmd_t pmd)
2728c2ecf20Sopenharmony_ci{
2738c2ecf20Sopenharmony_ci	return __pmd(pmd_val(pmd) | (_PAGE_PTE | H_PAGE_THP_HUGE));
2748c2ecf20Sopenharmony_ci}
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ciextern unsigned long hash__pmd_hugepage_update(struct mm_struct *mm,
2778c2ecf20Sopenharmony_ci					   unsigned long addr, pmd_t *pmdp,
2788c2ecf20Sopenharmony_ci					   unsigned long clr, unsigned long set);
2798c2ecf20Sopenharmony_ciextern pmd_t hash__pmdp_collapse_flush(struct vm_area_struct *vma,
2808c2ecf20Sopenharmony_ci				   unsigned long address, pmd_t *pmdp);
2818c2ecf20Sopenharmony_ciextern void hash__pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
2828c2ecf20Sopenharmony_ci					 pgtable_t pgtable);
2838c2ecf20Sopenharmony_ciextern pgtable_t hash__pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp);
2848c2ecf20Sopenharmony_ciextern pmd_t hash__pmdp_huge_get_and_clear(struct mm_struct *mm,
2858c2ecf20Sopenharmony_ci				       unsigned long addr, pmd_t *pmdp);
2868c2ecf20Sopenharmony_ciextern int hash__has_transparent_hugepage(void);
2878c2ecf20Sopenharmony_ci#endif /*  CONFIG_TRANSPARENT_HUGEPAGE */
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_cistatic inline pmd_t hash__pmd_mkdevmap(pmd_t pmd)
2908c2ecf20Sopenharmony_ci{
2918c2ecf20Sopenharmony_ci	return __pmd(pmd_val(pmd) | (_PAGE_PTE | H_PAGE_THP_HUGE | _PAGE_DEVMAP));
2928c2ecf20Sopenharmony_ci}
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci#endif	/* __ASSEMBLY__ */
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci#endif /* _ASM_POWERPC_BOOK3S_64_HASH_64K_H */
297