1*4882a593Smuzhiyun #ifndef _ASM_POWERPC_PTE_WALK_H
2*4882a593Smuzhiyun #define _ASM_POWERPC_PTE_WALK_H
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun #include <linux/sched.h>
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun /* Don't use this directly */
7*4882a593Smuzhiyun extern pte_t *__find_linux_pte(pgd_t *pgdir, unsigned long ea,
8*4882a593Smuzhiyun bool *is_thp, unsigned *hshift);
9*4882a593Smuzhiyun
find_linux_pte(pgd_t * pgdir,unsigned long ea,bool * is_thp,unsigned * hshift)10*4882a593Smuzhiyun static inline pte_t *find_linux_pte(pgd_t *pgdir, unsigned long ea,
11*4882a593Smuzhiyun bool *is_thp, unsigned *hshift)
12*4882a593Smuzhiyun {
13*4882a593Smuzhiyun pte_t *pte;
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun VM_WARN(!arch_irqs_disabled(), "%s called with irq enabled\n", __func__);
16*4882a593Smuzhiyun pte = __find_linux_pte(pgdir, ea, is_thp, hshift);
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun #if defined(CONFIG_DEBUG_VM) && \
19*4882a593Smuzhiyun !(defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE))
20*4882a593Smuzhiyun /*
21*4882a593Smuzhiyun * We should not find huge page if these configs are not enabled.
22*4882a593Smuzhiyun */
23*4882a593Smuzhiyun if (hshift)
24*4882a593Smuzhiyun WARN_ON(*hshift);
25*4882a593Smuzhiyun #endif
26*4882a593Smuzhiyun return pte;
27*4882a593Smuzhiyun }
28*4882a593Smuzhiyun
find_init_mm_pte(unsigned long ea,unsigned * hshift)29*4882a593Smuzhiyun static inline pte_t *find_init_mm_pte(unsigned long ea, unsigned *hshift)
30*4882a593Smuzhiyun {
31*4882a593Smuzhiyun pgd_t *pgdir = init_mm.pgd;
32*4882a593Smuzhiyun return __find_linux_pte(pgdir, ea, NULL, hshift);
33*4882a593Smuzhiyun }
34*4882a593Smuzhiyun /*
35*4882a593Smuzhiyun * This is what we should always use. Any other lockless page table lookup needs
36*4882a593Smuzhiyun * careful audit against THP split.
37*4882a593Smuzhiyun */
find_current_mm_pte(pgd_t * pgdir,unsigned long ea,bool * is_thp,unsigned * hshift)38*4882a593Smuzhiyun static inline pte_t *find_current_mm_pte(pgd_t *pgdir, unsigned long ea,
39*4882a593Smuzhiyun bool *is_thp, unsigned *hshift)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun pte_t *pte;
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun VM_WARN(!arch_irqs_disabled(), "%s called with irq enabled\n", __func__);
44*4882a593Smuzhiyun VM_WARN(pgdir != current->mm->pgd,
45*4882a593Smuzhiyun "%s lock less page table lookup called on wrong mm\n", __func__);
46*4882a593Smuzhiyun pte = __find_linux_pte(pgdir, ea, is_thp, hshift);
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun #if defined(CONFIG_DEBUG_VM) && \
49*4882a593Smuzhiyun !(defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE))
50*4882a593Smuzhiyun /*
51*4882a593Smuzhiyun * We should not find huge page if these configs are not enabled.
52*4882a593Smuzhiyun */
53*4882a593Smuzhiyun if (hshift)
54*4882a593Smuzhiyun WARN_ON(*hshift);
55*4882a593Smuzhiyun #endif
56*4882a593Smuzhiyun return pte;
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun #endif /* _ASM_POWERPC_PTE_WALK_H */
60