1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
23dfcb315SAneesh Kumar K.V #ifndef _ASM_POWERPC_BOOK3S_64_PGTABLE_H_
33dfcb315SAneesh Kumar K.V #define _ASM_POWERPC_BOOK3S_64_PGTABLE_H_
42e873519SAneesh Kumar K.V
52fb47060SMike Rapoport #include <asm-generic/pgtable-nop4d.h>
69849a569SKirill A. Shutemov
7c137a275SAneesh Kumar K.V #ifndef __ASSEMBLY__
8c137a275SAneesh Kumar K.V #include <linux/mmdebug.h>
9ebd31197SOliver O'Halloran #include <linux/bug.h>
109ccba66dSChristophe Leroy #include <linux/sizes.h>
11c137a275SAneesh Kumar K.V #endif
129849a569SKirill A. Shutemov
133dfcb315SAneesh Kumar K.V /*
142e873519SAneesh Kumar K.V * Common bits between hash and Radix page table
153dfcb315SAneesh Kumar K.V */
162e873519SAneesh Kumar K.V
172e873519SAneesh Kumar K.V #define _PAGE_EXEC 0x00001 /* execute permission */
182e873519SAneesh Kumar K.V #define _PAGE_WRITE 0x00002 /* write access allowed */
192e873519SAneesh Kumar K.V #define _PAGE_READ 0x00004 /* read access allowed */
202e873519SAneesh Kumar K.V #define _PAGE_RW (_PAGE_READ | _PAGE_WRITE)
212e873519SAneesh Kumar K.V #define _PAGE_RWX (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC)
222e873519SAneesh Kumar K.V #define _PAGE_PRIVILEGED 0x00008 /* kernel access only */
2312564485SShawn Anastasio #define _PAGE_SAO 0x00010 /* Strong access order */
242e873519SAneesh Kumar K.V #define _PAGE_NON_IDEMPOTENT 0x00020 /* non idempotent memory */
252e873519SAneesh Kumar K.V #define _PAGE_TOLERANT 0x00030 /* tolerant memory, cache inhibited */
262e873519SAneesh Kumar K.V #define _PAGE_DIRTY 0x00080 /* C: page changed */
272e873519SAneesh Kumar K.V #define _PAGE_ACCESSED 0x00100 /* R: page referenced */
282e873519SAneesh Kumar K.V /*
292e873519SAneesh Kumar K.V * Software bits
302e873519SAneesh Kumar K.V */
3169dfbaebSAneesh Kumar K.V #define _RPAGE_SW0 0x2000000000000000UL
3269dfbaebSAneesh Kumar K.V #define _RPAGE_SW1 0x00800
3369dfbaebSAneesh Kumar K.V #define _RPAGE_SW2 0x00400
3469dfbaebSAneesh Kumar K.V #define _RPAGE_SW3 0x00200
35ee8b3933SAneesh Kumar K.V #define _RPAGE_RSV1 0x00040UL
36ee8b3933SAneesh Kumar K.V
37ee8b3933SAneesh Kumar K.V #define _RPAGE_PKEY_BIT4 0x1000000000000000UL
38ee8b3933SAneesh Kumar K.V #define _RPAGE_PKEY_BIT3 0x0800000000000000UL
39ee8b3933SAneesh Kumar K.V #define _RPAGE_PKEY_BIT2 0x0400000000000000UL
40ee8b3933SAneesh Kumar K.V #define _RPAGE_PKEY_BIT1 0x0200000000000000UL
41ee8b3933SAneesh Kumar K.V #define _RPAGE_PKEY_BIT0 0x0100000000000000UL
426aa59f51SAneesh Kumar K.V
436aa59f51SAneesh Kumar K.V #define _PAGE_PTE 0x4000000000000000UL /* distinguishes PTEs from pointers */
446aa59f51SAneesh Kumar K.V #define _PAGE_PRESENT 0x8000000000000000UL /* pte contains a translation */
45bd0dbb73SAneesh Kumar K.V /*
46bd0dbb73SAneesh Kumar K.V * We need to mark a pmd pte invalid while splitting. We can do that by clearing
47bd0dbb73SAneesh Kumar K.V * the _PAGE_PRESENT bit. But then that will be taken as a swap pte. In order to
48bd0dbb73SAneesh Kumar K.V * differentiate between two use a SW field when invalidating.
49bd0dbb73SAneesh Kumar K.V *
50bd0dbb73SAneesh Kumar K.V * We do that temporary invalidate for regular pte entry in ptep_set_access_flags
51bd0dbb73SAneesh Kumar K.V *
52bd0dbb73SAneesh Kumar K.V * This is used only when _PAGE_PRESENT is cleared.
53bd0dbb73SAneesh Kumar K.V */
54bd0dbb73SAneesh Kumar K.V #define _PAGE_INVALID _RPAGE_SW0
556aa59f51SAneesh Kumar K.V
566aa59f51SAneesh Kumar K.V /*
576aa59f51SAneesh Kumar K.V * Top and bottom bits of RPN which can be used by hash
586aa59f51SAneesh Kumar K.V * translation mode, because we expect them to be zero
596aa59f51SAneesh Kumar K.V * otherwise.
606aa59f51SAneesh Kumar K.V */
6132789d38SAneesh Kumar K.V #define _RPAGE_RPN0 0x01000
6232789d38SAneesh Kumar K.V #define _RPAGE_RPN1 0x02000
636aa59f51SAneesh Kumar K.V #define _RPAGE_RPN43 0x0080000000000000UL
646aa59f51SAneesh Kumar K.V #define _RPAGE_RPN42 0x0040000000000000UL
656aa59f51SAneesh Kumar K.V #define _RPAGE_RPN41 0x0020000000000000UL
66049d567aSAneesh Kumar K.V
672f18d533SAneesh Kumar K.V /* Max physical address bit as per radix table */
68ee8b3933SAneesh Kumar K.V #define _RPAGE_PA_MAX 56
692f18d533SAneesh Kumar K.V
702f18d533SAneesh Kumar K.V /*
712f18d533SAneesh Kumar K.V * Max physical address bit we will use for now.
722f18d533SAneesh Kumar K.V *
732f18d533SAneesh Kumar K.V * This is mostly a hardware limitation and for now Power9 has
742f18d533SAneesh Kumar K.V * a 51 bit limit.
752f18d533SAneesh Kumar K.V *
762f18d533SAneesh Kumar K.V * This is different from the number of physical bit required to address
772f18d533SAneesh Kumar K.V * the last byte of memory. That is defined by MAX_PHYSMEM_BITS.
782f18d533SAneesh Kumar K.V * MAX_PHYSMEM_BITS is a linux limitation imposed by the maximum
792f18d533SAneesh Kumar K.V * number of sections we can support (SECTIONS_SHIFT).
802f18d533SAneesh Kumar K.V *
812f18d533SAneesh Kumar K.V * This is different from Radix page table limitation above and
822f18d533SAneesh Kumar K.V * should always be less than that. The limit is done such that
832f18d533SAneesh Kumar K.V * we can overload the bits between _RPAGE_PA_MAX and _PAGE_PA_MAX
842f18d533SAneesh Kumar K.V * for hash linux page table specific bits.
852f18d533SAneesh Kumar K.V *
862f18d533SAneesh Kumar K.V * In order to be compatible with future hardware generations we keep
872f18d533SAneesh Kumar K.V * some offsets and limit this for now to 53
882f18d533SAneesh Kumar K.V */
892f18d533SAneesh Kumar K.V #define _PAGE_PA_MAX 53
902f18d533SAneesh Kumar K.V
9169dfbaebSAneesh Kumar K.V #define _PAGE_SOFT_DIRTY _RPAGE_SW3 /* software: software dirty tracking */
9269dfbaebSAneesh Kumar K.V #define _PAGE_SPECIAL _RPAGE_SW2 /* software: special page */
93ebd31197SOliver O'Halloran #define _PAGE_DEVMAP _RPAGE_SW1 /* software: ZONE_DEVICE page */
94ebd31197SOliver O'Halloran
952e873519SAneesh Kumar K.V /*
962e873519SAneesh Kumar K.V * Drivers request for cache inhibited pte mapping using _PAGE_NO_CACHE
972e873519SAneesh Kumar K.V * Instead of fixing all of them, add an alternate define which
982e873519SAneesh Kumar K.V * maps CI pte mapping.
992e873519SAneesh Kumar K.V */
1002e873519SAneesh Kumar K.V #define _PAGE_NO_CACHE _PAGE_TOLERANT
1012e873519SAneesh Kumar K.V /*
1022f18d533SAneesh Kumar K.V * We support _RPAGE_PA_MAX bit real address in pte. On the linux side
1032f18d533SAneesh Kumar K.V * we are limited by _PAGE_PA_MAX. Clear everything above _PAGE_PA_MAX
1042f18d533SAneesh Kumar K.V * and every thing below PAGE_SHIFT;
1052e873519SAneesh Kumar K.V */
1062f18d533SAneesh Kumar K.V #define PTE_RPN_MASK (((1UL << _PAGE_PA_MAX) - 1) & (PAGE_MASK))
1079fee28baSMatthew Wilcox (Oracle) #define PTE_RPN_SHIFT PAGE_SHIFT
1082e873519SAneesh Kumar K.V /*
1092e873519SAneesh Kumar K.V * set of bits not changed in pmd_modify. Even though we have hash specific bits
1102e873519SAneesh Kumar K.V * in here, on radix we expect them to be zero.
1112e873519SAneesh Kumar K.V */
1122e873519SAneesh Kumar K.V #define _HPAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | _PAGE_DIRTY | \
1132e873519SAneesh Kumar K.V _PAGE_ACCESSED | H_PAGE_THP_HUGE | _PAGE_PTE | \
1144628a645SJan Kara _PAGE_SOFT_DIRTY | _PAGE_DEVMAP)
1152e873519SAneesh Kumar K.V /*
1162e873519SAneesh Kumar K.V * user access blocked by key
1172e873519SAneesh Kumar K.V */
1182e873519SAneesh Kumar K.V #define _PAGE_KERNEL_RW (_PAGE_PRIVILEGED | _PAGE_RW | _PAGE_DIRTY)
1192e873519SAneesh Kumar K.V #define _PAGE_KERNEL_RO (_PAGE_PRIVILEGED | _PAGE_READ)
12056bec2f9SMichael Ellerman #define _PAGE_KERNEL_ROX (_PAGE_PRIVILEGED | _PAGE_READ | _PAGE_EXEC)
1216cc07821SChristophe Leroy #define _PAGE_KERNEL_RWX (_PAGE_PRIVILEGED | _PAGE_DIRTY | _PAGE_RW | _PAGE_EXEC)
1222e873519SAneesh Kumar K.V /*
1232e873519SAneesh Kumar K.V * _PAGE_CHG_MASK masks of bits that are to be preserved across
1242e873519SAneesh Kumar K.V * pgprot changes
1252e873519SAneesh Kumar K.V */
1262e873519SAneesh Kumar K.V #define _PAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | _PAGE_DIRTY | \
1272e873519SAneesh Kumar K.V _PAGE_ACCESSED | _PAGE_SPECIAL | _PAGE_PTE | \
1284628a645SJan Kara _PAGE_SOFT_DIRTY | _PAGE_DEVMAP)
129eb95d016SRam Pai
1302e873519SAneesh Kumar K.V /*
1312e873519SAneesh Kumar K.V * We define 2 sets of base prot bits, one for basic pages (ie,
1322e873519SAneesh Kumar K.V * cacheable kernel and user pages) and one for non cacheable
1332e873519SAneesh Kumar K.V * pages. We always set _PAGE_COHERENT when SMP is enabled or
1342e873519SAneesh Kumar K.V * the processor might need it for DMA coherency.
1352e873519SAneesh Kumar K.V */
136093d7ca2SChristophe Leroy #define _PAGE_BASE_NC (_PAGE_PRESENT | _PAGE_ACCESSED)
1372e873519SAneesh Kumar K.V #define _PAGE_BASE (_PAGE_BASE_NC)
1382e873519SAneesh Kumar K.V
1392e873519SAneesh Kumar K.V /* Permission masks used to generate the __P and __S table,
1402e873519SAneesh Kumar K.V *
1412e873519SAneesh Kumar K.V * Note:__pgprot is defined in arch/powerpc/include/asm/page.h
1422e873519SAneesh Kumar K.V *
1432e873519SAneesh Kumar K.V * Write permissions imply read permissions for now (we could make write-only
1442e873519SAneesh Kumar K.V * pages on BookE but we don't bother for now). Execute permission control is
1452e873519SAneesh Kumar K.V * possible on platforms that define _PAGE_EXEC
1462e873519SAneesh Kumar K.V */
1472e873519SAneesh Kumar K.V #define PAGE_NONE __pgprot(_PAGE_BASE | _PAGE_PRIVILEGED)
1482e873519SAneesh Kumar K.V #define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_RW)
1492e873519SAneesh Kumar K.V #define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_RW | _PAGE_EXEC)
1502e873519SAneesh Kumar K.V #define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_READ)
1512e873519SAneesh Kumar K.V #define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_READ | _PAGE_EXEC)
1522e873519SAneesh Kumar K.V #define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_READ)
1532e873519SAneesh Kumar K.V #define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_READ | _PAGE_EXEC)
154395cac77SRussell Currey /* Radix only, Hash uses PAGE_READONLY_X + execute-only pkey instead */
155395cac77SRussell Currey #define PAGE_EXECONLY __pgprot(_PAGE_BASE | _PAGE_EXEC)
1562e873519SAneesh Kumar K.V
1572e873519SAneesh Kumar K.V /* Permission masks used for kernel mappings */
1582e873519SAneesh Kumar K.V #define PAGE_KERNEL __pgprot(_PAGE_BASE | _PAGE_KERNEL_RW)
1596cc07821SChristophe Leroy #define PAGE_KERNEL_NC __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | _PAGE_TOLERANT)
1606cc07821SChristophe Leroy #define PAGE_KERNEL_NCG __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | _PAGE_NON_IDEMPOTENT)
1612e873519SAneesh Kumar K.V #define PAGE_KERNEL_X __pgprot(_PAGE_BASE | _PAGE_KERNEL_RWX)
1622e873519SAneesh Kumar K.V #define PAGE_KERNEL_RO __pgprot(_PAGE_BASE | _PAGE_KERNEL_RO)
1632e873519SAneesh Kumar K.V #define PAGE_KERNEL_ROX __pgprot(_PAGE_BASE | _PAGE_KERNEL_ROX)
1642e873519SAneesh Kumar K.V
165dd1842a2SAneesh Kumar K.V #ifndef __ASSEMBLY__
166dd1842a2SAneesh Kumar K.V /*
167dd1842a2SAneesh Kumar K.V * page table defines
168dd1842a2SAneesh Kumar K.V */
169dd1842a2SAneesh Kumar K.V extern unsigned long __pte_index_size;
170dd1842a2SAneesh Kumar K.V extern unsigned long __pmd_index_size;
171dd1842a2SAneesh Kumar K.V extern unsigned long __pud_index_size;
172dd1842a2SAneesh Kumar K.V extern unsigned long __pgd_index_size;
173fae22116SAneesh Kumar K.V extern unsigned long __pud_cache_index;
174dd1842a2SAneesh Kumar K.V #define PTE_INDEX_SIZE __pte_index_size
175dd1842a2SAneesh Kumar K.V #define PMD_INDEX_SIZE __pmd_index_size
176dd1842a2SAneesh Kumar K.V #define PUD_INDEX_SIZE __pud_index_size
177dd1842a2SAneesh Kumar K.V #define PGD_INDEX_SIZE __pgd_index_size
178738f9645SAneesh Kumar K.V /* pmd table use page table fragments */
179738f9645SAneesh Kumar K.V #define PMD_CACHE_INDEX 0
180fae22116SAneesh Kumar K.V #define PUD_CACHE_INDEX __pud_cache_index
181dd1842a2SAneesh Kumar K.V /*
182dd1842a2SAneesh Kumar K.V * Because of use of pte fragments and THP, size of page table
183dd1842a2SAneesh Kumar K.V * are not always derived out of index size above.
184dd1842a2SAneesh Kumar K.V */
185dd1842a2SAneesh Kumar K.V extern unsigned long __pte_table_size;
186dd1842a2SAneesh Kumar K.V extern unsigned long __pmd_table_size;
187dd1842a2SAneesh Kumar K.V extern unsigned long __pud_table_size;
188dd1842a2SAneesh Kumar K.V extern unsigned long __pgd_table_size;
189dd1842a2SAneesh Kumar K.V #define PTE_TABLE_SIZE __pte_table_size
190dd1842a2SAneesh Kumar K.V #define PMD_TABLE_SIZE __pmd_table_size
191dd1842a2SAneesh Kumar K.V #define PUD_TABLE_SIZE __pud_table_size
192dd1842a2SAneesh Kumar K.V #define PGD_TABLE_SIZE __pgd_table_size
193a2f41eb9SAneesh Kumar K.V
194a2f41eb9SAneesh Kumar K.V extern unsigned long __pmd_val_bits;
195a2f41eb9SAneesh Kumar K.V extern unsigned long __pud_val_bits;
196a2f41eb9SAneesh Kumar K.V extern unsigned long __pgd_val_bits;
197a2f41eb9SAneesh Kumar K.V #define PMD_VAL_BITS __pmd_val_bits
198a2f41eb9SAneesh Kumar K.V #define PUD_VAL_BITS __pud_val_bits
199a2f41eb9SAneesh Kumar K.V #define PGD_VAL_BITS __pgd_val_bits
2005ed7ecd0SAneesh Kumar K.V
2015ed7ecd0SAneesh Kumar K.V extern unsigned long __pte_frag_nr;
2025ed7ecd0SAneesh Kumar K.V #define PTE_FRAG_NR __pte_frag_nr
2035ed7ecd0SAneesh Kumar K.V extern unsigned long __pte_frag_size_shift;
2045ed7ecd0SAneesh Kumar K.V #define PTE_FRAG_SIZE_SHIFT __pte_frag_size_shift
2055ed7ecd0SAneesh Kumar K.V #define PTE_FRAG_SIZE (1UL << PTE_FRAG_SIZE_SHIFT)
206dd1842a2SAneesh Kumar K.V
2078a6c697bSAneesh Kumar K.V extern unsigned long __pmd_frag_nr;
2088a6c697bSAneesh Kumar K.V #define PMD_FRAG_NR __pmd_frag_nr
2098a6c697bSAneesh Kumar K.V extern unsigned long __pmd_frag_size_shift;
2108a6c697bSAneesh Kumar K.V #define PMD_FRAG_SIZE_SHIFT __pmd_frag_size_shift
2118a6c697bSAneesh Kumar K.V #define PMD_FRAG_SIZE (1UL << PMD_FRAG_SIZE_SHIFT)
2128a6c697bSAneesh Kumar K.V
213dd1842a2SAneesh Kumar K.V #define PTRS_PER_PTE (1 << PTE_INDEX_SIZE)
214dd1842a2SAneesh Kumar K.V #define PTRS_PER_PMD (1 << PMD_INDEX_SIZE)
215dd1842a2SAneesh Kumar K.V #define PTRS_PER_PUD (1 << PUD_INDEX_SIZE)
216dd1842a2SAneesh Kumar K.V #define PTRS_PER_PGD (1 << PGD_INDEX_SIZE)
217dd1842a2SAneesh Kumar K.V
21841b7a347SDaniel Axtens #define MAX_PTRS_PER_PTE ((H_PTRS_PER_PTE > R_PTRS_PER_PTE) ? H_PTRS_PER_PTE : R_PTRS_PER_PTE)
21941b7a347SDaniel Axtens #define MAX_PTRS_PER_PMD ((H_PTRS_PER_PMD > R_PTRS_PER_PMD) ? H_PTRS_PER_PMD : R_PTRS_PER_PMD)
22041b7a347SDaniel Axtens #define MAX_PTRS_PER_PUD ((H_PTRS_PER_PUD > R_PTRS_PER_PUD) ? H_PTRS_PER_PUD : R_PTRS_PER_PUD)
221e72421a0SChristophe Leroy #define MAX_PTRS_PER_PGD (1 << (H_PGD_INDEX_SIZE > RADIX_PGD_INDEX_SIZE ? \
222e72421a0SChristophe Leroy H_PGD_INDEX_SIZE : RADIX_PGD_INDEX_SIZE))
223e72421a0SChristophe Leroy
224dd1842a2SAneesh Kumar K.V /* PMD_SHIFT determines what a second-level page table entry can map */
225dd1842a2SAneesh Kumar K.V #define PMD_SHIFT (PAGE_SHIFT + PTE_INDEX_SIZE)
226dd1842a2SAneesh Kumar K.V #define PMD_SIZE (1UL << PMD_SHIFT)
227dd1842a2SAneesh Kumar K.V #define PMD_MASK (~(PMD_SIZE-1))
228dd1842a2SAneesh Kumar K.V
229dd1842a2SAneesh Kumar K.V /* PUD_SHIFT determines what a third-level page table entry can map */
230dd1842a2SAneesh Kumar K.V #define PUD_SHIFT (PMD_SHIFT + PMD_INDEX_SIZE)
231dd1842a2SAneesh Kumar K.V #define PUD_SIZE (1UL << PUD_SHIFT)
232dd1842a2SAneesh Kumar K.V #define PUD_MASK (~(PUD_SIZE-1))
233dd1842a2SAneesh Kumar K.V
234dd1842a2SAneesh Kumar K.V /* PGDIR_SHIFT determines what a fourth-level page table entry can map */
235dd1842a2SAneesh Kumar K.V #define PGDIR_SHIFT (PUD_SHIFT + PUD_INDEX_SIZE)
236dd1842a2SAneesh Kumar K.V #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
237dd1842a2SAneesh Kumar K.V #define PGDIR_MASK (~(PGDIR_SIZE-1))
238dd1842a2SAneesh Kumar K.V
239dd1842a2SAneesh Kumar K.V /* Bits to mask out from a PMD to get to the PTE page */
240dd1842a2SAneesh Kumar K.V #define PMD_MASKED_BITS 0xc0000000000000ffUL
241dd1842a2SAneesh Kumar K.V /* Bits to mask out from a PUD to get to the PMD page */
242dd1842a2SAneesh Kumar K.V #define PUD_MASKED_BITS 0xc0000000000000ffUL
243dd1842a2SAneesh Kumar K.V /* Bits to mask out from a PGD to get to the PUD page */
2442fb47060SMike Rapoport #define P4D_MASKED_BITS 0xc0000000000000ffUL
245d6a9996eSAneesh Kumar K.V
2460c4d2680SAneesh Kumar K.V /*
2470c4d2680SAneesh Kumar K.V * Used as an indicator for rcu callback functions
2480c4d2680SAneesh Kumar K.V */
2490c4d2680SAneesh Kumar K.V enum pgtable_index {
2500c4d2680SAneesh Kumar K.V PTE_INDEX = 0,
2510c4d2680SAneesh Kumar K.V PMD_INDEX,
2520c4d2680SAneesh Kumar K.V PUD_INDEX,
2530c4d2680SAneesh Kumar K.V PGD_INDEX,
254fadd03c6SAneesh Kumar K.V /*
255fadd03c6SAneesh Kumar K.V * Below are used with 4k page size and hugetlb
256fadd03c6SAneesh Kumar K.V */
257fadd03c6SAneesh Kumar K.V HTLB_16M_INDEX,
258fadd03c6SAneesh Kumar K.V HTLB_16G_INDEX,
2590c4d2680SAneesh Kumar K.V };
2600c4d2680SAneesh Kumar K.V
261d6a9996eSAneesh Kumar K.V extern unsigned long __vmalloc_start;
262d6a9996eSAneesh Kumar K.V extern unsigned long __vmalloc_end;
263d6a9996eSAneesh Kumar K.V #define VMALLOC_START __vmalloc_start
264d6a9996eSAneesh Kumar K.V #define VMALLOC_END __vmalloc_end
265d6a9996eSAneesh Kumar K.V
ioremap_max_order(void)266d909f910SNicholas Piggin static inline unsigned int ioremap_max_order(void)
267d909f910SNicholas Piggin {
268d909f910SNicholas Piggin if (radix_enabled())
269d909f910SNicholas Piggin return PUD_SHIFT;
270d909f910SNicholas Piggin return 7 + PAGE_SHIFT; /* default from linux/vmalloc.h */
271d909f910SNicholas Piggin }
272d909f910SNicholas Piggin #define IOREMAP_MAX_ORDER ioremap_max_order()
273d909f910SNicholas Piggin
274d6a9996eSAneesh Kumar K.V extern unsigned long __kernel_virt_start;
27563ee9b2fSMichael Ellerman extern unsigned long __kernel_io_start;
276a35a3c6fSAneesh Kumar K.V extern unsigned long __kernel_io_end;
277d6a9996eSAneesh Kumar K.V #define KERN_VIRT_START __kernel_virt_start
27863ee9b2fSMichael Ellerman #define KERN_IO_START __kernel_io_start
279a35a3c6fSAneesh Kumar K.V #define KERN_IO_END __kernel_io_end
280a35a3c6fSAneesh Kumar K.V
281d6a9996eSAneesh Kumar K.V extern struct page *vmemmap;
282bfa37087SDarren Stevens extern unsigned long pci_io_base;
283dd1842a2SAneesh Kumar K.V #endif /* __ASSEMBLY__ */
2843dfcb315SAneesh Kumar K.V
285ab537dcaSAneesh Kumar K.V #include <asm/book3s/64/hash.h>
286b0b5e9b1SAneesh Kumar K.V #include <asm/book3s/64/radix.h>
2873dfcb315SAneesh Kumar K.V
288b32d5d7eSAneesh Kumar K.V #if H_MAX_PHYSMEM_BITS > R_MAX_PHYSMEM_BITS
289b32d5d7eSAneesh Kumar K.V #define MAX_PHYSMEM_BITS H_MAX_PHYSMEM_BITS
290b32d5d7eSAneesh Kumar K.V #else
291b32d5d7eSAneesh Kumar K.V #define MAX_PHYSMEM_BITS R_MAX_PHYSMEM_BITS
292b32d5d7eSAneesh Kumar K.V #endif
293b32d5d7eSAneesh Kumar K.V
294b32d5d7eSAneesh Kumar K.V
295a9252aaeSAneesh Kumar K.V #ifdef CONFIG_PPC_64K_PAGES
296a9252aaeSAneesh Kumar K.V #include <asm/book3s/64/pgtable-64k.h>
297a9252aaeSAneesh Kumar K.V #else
298a9252aaeSAneesh Kumar K.V #include <asm/book3s/64/pgtable-4k.h>
299a9252aaeSAneesh Kumar K.V #endif
300a9252aaeSAneesh Kumar K.V
3013dfcb315SAneesh Kumar K.V #include <asm/barrier.h>
3023dfcb315SAneesh Kumar K.V /*
303a35a3c6fSAneesh Kumar K.V * IO space itself carved into the PIO region (ISA and PHB IO space) and
3043dfcb315SAneesh Kumar K.V * the ioremap space
3053dfcb315SAneesh Kumar K.V *
3063dfcb315SAneesh Kumar K.V * ISA_IO_BASE = KERN_IO_START, 64K reserved area
3073dfcb315SAneesh Kumar K.V * PHB_IO_BASE = ISA_IO_BASE + 64K to ISA_IO_BASE + 2G, PHB IO spaces
3083dfcb315SAneesh Kumar K.V * IOREMAP_BASE = ISA_IO_BASE + 2G to VMALLOC_START + PGTABLE_RANGE
3093dfcb315SAneesh Kumar K.V */
3103dfcb315SAneesh Kumar K.V #define FULL_IO_SIZE 0x80000000ul
3113dfcb315SAneesh Kumar K.V #define ISA_IO_BASE (KERN_IO_START)
3123dfcb315SAneesh Kumar K.V #define ISA_IO_END (KERN_IO_START + 0x10000ul)
3133dfcb315SAneesh Kumar K.V #define PHB_IO_BASE (ISA_IO_END)
3143dfcb315SAneesh Kumar K.V #define PHB_IO_END (KERN_IO_START + FULL_IO_SIZE)
3153dfcb315SAneesh Kumar K.V #define IOREMAP_BASE (PHB_IO_END)
3164a45b746SChristophe Leroy #define IOREMAP_START (ioremap_bot)
3179ccba66dSChristophe Leroy #define IOREMAP_END (KERN_IO_END - FIXADDR_SIZE)
3189ccba66dSChristophe Leroy #define FIXADDR_SIZE SZ_32M
3193dfcb315SAneesh Kumar K.V
3203dfcb315SAneesh Kumar K.V #ifndef __ASSEMBLY__
3213dfcb315SAneesh Kumar K.V
pte_update(struct mm_struct * mm,unsigned long addr,pte_t * ptep,unsigned long clr,unsigned long set,int huge)322ac94ac79SAneesh Kumar K.V static inline unsigned long pte_update(struct mm_struct *mm, unsigned long addr,
323ac94ac79SAneesh Kumar K.V pte_t *ptep, unsigned long clr,
324ac94ac79SAneesh Kumar K.V unsigned long set, int huge)
325ac94ac79SAneesh Kumar K.V {
326ac94ac79SAneesh Kumar K.V if (radix_enabled())
327ac94ac79SAneesh Kumar K.V return radix__pte_update(mm, addr, ptep, clr, set, huge);
328ac94ac79SAneesh Kumar K.V return hash__pte_update(mm, addr, ptep, clr, set, huge);
329ac94ac79SAneesh Kumar K.V }
33013f829a5SAneesh Kumar K.V /*
33113f829a5SAneesh Kumar K.V * For hash even if we have _PAGE_ACCESSED = 0, we do a pte_update.
33213f829a5SAneesh Kumar K.V * We currently remove entries from the hashtable regardless of whether
33313f829a5SAneesh Kumar K.V * the entry was young or dirty.
33413f829a5SAneesh Kumar K.V *
33513f829a5SAneesh Kumar K.V * We should be more intelligent about this but for the moment we override
33613f829a5SAneesh Kumar K.V * these functions and force a tlb flush unconditionally
33713f829a5SAneesh Kumar K.V * For radix: H_PAGE_HASHPTE should be zero. Hence we can use the same
33813f829a5SAneesh Kumar K.V * function for both hash and radix.
33913f829a5SAneesh Kumar K.V */
__ptep_test_and_clear_young(struct mm_struct * mm,unsigned long addr,pte_t * ptep)34013f829a5SAneesh Kumar K.V static inline int __ptep_test_and_clear_young(struct mm_struct *mm,
34113f829a5SAneesh Kumar K.V unsigned long addr, pte_t *ptep)
34213f829a5SAneesh Kumar K.V {
34313f829a5SAneesh Kumar K.V unsigned long old;
34413f829a5SAneesh Kumar K.V
34566c570f5SAneesh Kumar K.V if ((pte_raw(*ptep) & cpu_to_be64(_PAGE_ACCESSED | H_PAGE_HASHPTE)) == 0)
34613f829a5SAneesh Kumar K.V return 0;
34713f829a5SAneesh Kumar K.V old = pte_update(mm, addr, ptep, _PAGE_ACCESSED, 0, 0);
34813f829a5SAneesh Kumar K.V return (old & _PAGE_ACCESSED) != 0;
34913f829a5SAneesh Kumar K.V }
35013f829a5SAneesh Kumar K.V
35113f829a5SAneesh Kumar K.V #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
35213f829a5SAneesh Kumar K.V #define ptep_test_and_clear_young(__vma, __addr, __ptep) \
35313f829a5SAneesh Kumar K.V ({ \
3543cb1aa7aSNicholas Piggin __ptep_test_and_clear_young((__vma)->vm_mm, __addr, __ptep); \
35513f829a5SAneesh Kumar K.V })
35613f829a5SAneesh Kumar K.V
3573cb1aa7aSNicholas Piggin /*
3583cb1aa7aSNicholas Piggin * On Book3S CPUs, clearing the accessed bit without a TLB flush
3593cb1aa7aSNicholas Piggin * doesn't cause data corruption. [ It could cause incorrect
3603cb1aa7aSNicholas Piggin * page aging and the (mistaken) reclaim of hot pages, but the
3613cb1aa7aSNicholas Piggin * chance of that should be relatively low. ]
3623cb1aa7aSNicholas Piggin *
3633cb1aa7aSNicholas Piggin * So as a performance optimization don't flush the TLB when
3643cb1aa7aSNicholas Piggin * clearing the accessed bit, it will eventually be flushed by
3653cb1aa7aSNicholas Piggin * a context switch or a VM operation anyway. [ In the rare
3663cb1aa7aSNicholas Piggin * event of it not getting flushed for a long time the delay
3673cb1aa7aSNicholas Piggin * shouldn't really matter because there's no real memory
3683cb1aa7aSNicholas Piggin * pressure for swapout to react to. ]
369b11931e9SNicholas Piggin *
370b11931e9SNicholas Piggin * Note: this optimisation also exists in pte_needs_flush() and
371b11931e9SNicholas Piggin * huge_pmd_needs_flush().
3723cb1aa7aSNicholas Piggin */
3733cb1aa7aSNicholas Piggin #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
3743cb1aa7aSNicholas Piggin #define ptep_clear_flush_young ptep_test_and_clear_young
3753cb1aa7aSNicholas Piggin
3763cb1aa7aSNicholas Piggin #define __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
3773cb1aa7aSNicholas Piggin #define pmdp_clear_flush_young pmdp_test_and_clear_young
3783cb1aa7aSNicholas Piggin
pte_write(pte_t pte)379d19469e8SAneesh Kumar K.V static inline int pte_write(pte_t pte)
380d19469e8SAneesh Kumar K.V {
381d6379159SDavid Hildenbrand return !!(pte_raw(pte) & cpu_to_be64(_PAGE_WRITE));
382d19469e8SAneesh Kumar K.V }
383d19469e8SAneesh Kumar K.V
pte_read(pte_t pte)384ca8afd40SChristophe Leroy static inline int pte_read(pte_t pte)
385ca8afd40SChristophe Leroy {
386ca8afd40SChristophe Leroy return !!(pte_raw(pte) & cpu_to_be64(_PAGE_READ));
387ca8afd40SChristophe Leroy }
388ca8afd40SChristophe Leroy
38913f829a5SAneesh Kumar K.V #define __HAVE_ARCH_PTEP_SET_WRPROTECT
ptep_set_wrprotect(struct mm_struct * mm,unsigned long addr,pte_t * ptep)39013f829a5SAneesh Kumar K.V static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,
39113f829a5SAneesh Kumar K.V pte_t *ptep)
39213f829a5SAneesh Kumar K.V {
393d6379159SDavid Hildenbrand if (pte_write(*ptep))
39413f829a5SAneesh Kumar K.V pte_update(mm, addr, ptep, _PAGE_WRITE, 0, 0);
39513f829a5SAneesh Kumar K.V }
39613f829a5SAneesh Kumar K.V
3978e581d43SAlexandre Ghiti #define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT
huge_ptep_set_wrprotect(struct mm_struct * mm,unsigned long addr,pte_t * ptep)39813f829a5SAneesh Kumar K.V static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
39913f829a5SAneesh Kumar K.V unsigned long addr, pte_t *ptep)
40013f829a5SAneesh Kumar K.V {
401d6379159SDavid Hildenbrand if (pte_write(*ptep))
40213f829a5SAneesh Kumar K.V pte_update(mm, addr, ptep, _PAGE_WRITE, 0, 1);
40313f829a5SAneesh Kumar K.V }
40413f829a5SAneesh Kumar K.V
40513f829a5SAneesh Kumar K.V #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
ptep_get_and_clear(struct mm_struct * mm,unsigned long addr,pte_t * ptep)40613f829a5SAneesh Kumar K.V static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
40713f829a5SAneesh Kumar K.V unsigned long addr, pte_t *ptep)
40813f829a5SAneesh Kumar K.V {
40913f829a5SAneesh Kumar K.V unsigned long old = pte_update(mm, addr, ptep, ~0UL, 0, 0);
41013f829a5SAneesh Kumar K.V return __pte(old);
41113f829a5SAneesh Kumar K.V }
41213f829a5SAneesh Kumar K.V
413f4894b80SAneesh Kumar K.V #define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL
ptep_get_and_clear_full(struct mm_struct * mm,unsigned long addr,pte_t * ptep,int full)414f4894b80SAneesh Kumar K.V static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
415f4894b80SAneesh Kumar K.V unsigned long addr,
416f4894b80SAneesh Kumar K.V pte_t *ptep, int full)
417f4894b80SAneesh Kumar K.V {
418f4894b80SAneesh Kumar K.V if (full && radix_enabled()) {
419f4894b80SAneesh Kumar K.V /*
4202bf1071aSNicholas Piggin * We know that this is a full mm pte clear and
4212bf1071aSNicholas Piggin * hence can be sure there is no parallel set_pte.
422f4894b80SAneesh Kumar K.V */
423f4894b80SAneesh Kumar K.V return radix__ptep_get_and_clear_full(mm, addr, ptep, full);
424f4894b80SAneesh Kumar K.V }
425f4894b80SAneesh Kumar K.V return ptep_get_and_clear(mm, addr, ptep);
426f4894b80SAneesh Kumar K.V }
427f4894b80SAneesh Kumar K.V
428f4894b80SAneesh Kumar K.V
pte_clear(struct mm_struct * mm,unsigned long addr,pte_t * ptep)42913f829a5SAneesh Kumar K.V static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
43013f829a5SAneesh Kumar K.V pte_t * ptep)
43113f829a5SAneesh Kumar K.V {
43213f829a5SAneesh Kumar K.V pte_update(mm, addr, ptep, ~0UL, 0, 0);
43313f829a5SAneesh Kumar K.V }
43466c570f5SAneesh Kumar K.V
pte_dirty(pte_t pte)43566c570f5SAneesh Kumar K.V static inline int pte_dirty(pte_t pte)
43666c570f5SAneesh Kumar K.V {
43766c570f5SAneesh Kumar K.V return !!(pte_raw(pte) & cpu_to_be64(_PAGE_DIRTY));
43866c570f5SAneesh Kumar K.V }
43966c570f5SAneesh Kumar K.V
pte_young(pte_t pte)44066c570f5SAneesh Kumar K.V static inline int pte_young(pte_t pte)
44166c570f5SAneesh Kumar K.V {
44266c570f5SAneesh Kumar K.V return !!(pte_raw(pte) & cpu_to_be64(_PAGE_ACCESSED));
44366c570f5SAneesh Kumar K.V }
44466c570f5SAneesh Kumar K.V
pte_special(pte_t pte)44566c570f5SAneesh Kumar K.V static inline int pte_special(pte_t pte)
44666c570f5SAneesh Kumar K.V {
44766c570f5SAneesh Kumar K.V return !!(pte_raw(pte) & cpu_to_be64(_PAGE_SPECIAL));
44866c570f5SAneesh Kumar K.V }
44966c570f5SAneesh Kumar K.V
pte_exec(pte_t pte)450daba7902SChristophe Leroy static inline bool pte_exec(pte_t pte)
451daba7902SChristophe Leroy {
452daba7902SChristophe Leroy return !!(pte_raw(pte) & cpu_to_be64(_PAGE_EXEC));
453daba7902SChristophe Leroy }
454daba7902SChristophe Leroy
45513f829a5SAneesh Kumar K.V
45613f829a5SAneesh Kumar K.V #ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
pte_soft_dirty(pte_t pte)45713f829a5SAneesh Kumar K.V static inline bool pte_soft_dirty(pte_t pte)
45813f829a5SAneesh Kumar K.V {
45966c570f5SAneesh Kumar K.V return !!(pte_raw(pte) & cpu_to_be64(_PAGE_SOFT_DIRTY));
46013f829a5SAneesh Kumar K.V }
46166c570f5SAneesh Kumar K.V
pte_mksoft_dirty(pte_t pte)46213f829a5SAneesh Kumar K.V static inline pte_t pte_mksoft_dirty(pte_t pte)
46313f829a5SAneesh Kumar K.V {
4641b2443a5SChristophe Leroy return __pte_raw(pte_raw(pte) | cpu_to_be64(_PAGE_SOFT_DIRTY));
46513f829a5SAneesh Kumar K.V }
46613f829a5SAneesh Kumar K.V
pte_clear_soft_dirty(pte_t pte)46713f829a5SAneesh Kumar K.V static inline pte_t pte_clear_soft_dirty(pte_t pte)
46813f829a5SAneesh Kumar K.V {
4691b2443a5SChristophe Leroy return __pte_raw(pte_raw(pte) & cpu_to_be64(~_PAGE_SOFT_DIRTY));
47013f829a5SAneesh Kumar K.V }
47113f829a5SAneesh Kumar K.V #endif /* CONFIG_HAVE_ARCH_SOFT_DIRTY */
47213f829a5SAneesh Kumar K.V
47313f829a5SAneesh Kumar K.V #ifdef CONFIG_NUMA_BALANCING
pte_protnone(pte_t pte)47413f829a5SAneesh Kumar K.V static inline int pte_protnone(pte_t pte)
47513f829a5SAneesh Kumar K.V {
476c137a275SAneesh Kumar K.V return (pte_raw(pte) & cpu_to_be64(_PAGE_PRESENT | _PAGE_PTE | _PAGE_RWX)) ==
477c137a275SAneesh Kumar K.V cpu_to_be64(_PAGE_PRESENT | _PAGE_PTE);
478c137a275SAneesh Kumar K.V }
47913f829a5SAneesh Kumar K.V #endif /* CONFIG_NUMA_BALANCING */
48013f829a5SAneesh Kumar K.V
pte_hw_valid(pte_t pte)481ec4abf1eSAneesh Kumar K.V static inline bool pte_hw_valid(pte_t pte)
482ec4abf1eSAneesh Kumar K.V {
483ec4abf1eSAneesh Kumar K.V return (pte_raw(pte) & cpu_to_be64(_PAGE_PRESENT | _PAGE_PTE)) ==
484ec4abf1eSAneesh Kumar K.V cpu_to_be64(_PAGE_PRESENT | _PAGE_PTE);
485ec4abf1eSAneesh Kumar K.V }
486ec4abf1eSAneesh Kumar K.V
pte_present(pte_t pte)48713f829a5SAneesh Kumar K.V static inline int pte_present(pte_t pte)
48813f829a5SAneesh Kumar K.V {
489bd0dbb73SAneesh Kumar K.V /*
490bd0dbb73SAneesh Kumar K.V * A pte is considerent present if _PAGE_PRESENT is set.
491bd0dbb73SAneesh Kumar K.V * We also need to consider the pte present which is marked
492bd0dbb73SAneesh Kumar K.V * invalid during ptep_set_access_flags. Hence we look for _PAGE_INVALID
493bd0dbb73SAneesh Kumar K.V * if we find _PAGE_PRESENT cleared.
494bd0dbb73SAneesh Kumar K.V */
495f72a85e3SAneesh Kumar K.V
496ec4abf1eSAneesh Kumar K.V if (pte_hw_valid(pte))
497ec4abf1eSAneesh Kumar K.V return true;
498ec4abf1eSAneesh Kumar K.V return (pte_raw(pte) & cpu_to_be64(_PAGE_INVALID | _PAGE_PTE)) ==
499ec4abf1eSAneesh Kumar K.V cpu_to_be64(_PAGE_INVALID | _PAGE_PTE);
500daba7902SChristophe Leroy }
501daba7902SChristophe Leroy
502bca7aacfSRam Pai #ifdef CONFIG_PPC_MEM_KEYS
503f2407ef3SRam Pai extern bool arch_pte_access_permitted(u64 pte, bool write, bool execute);
504bca7aacfSRam Pai #else
arch_pte_access_permitted(u64 pte,bool write,bool execute)505bca7aacfSRam Pai static inline bool arch_pte_access_permitted(u64 pte, bool write, bool execute)
506bca7aacfSRam Pai {
507bca7aacfSRam Pai return true;
508bca7aacfSRam Pai }
509bca7aacfSRam Pai #endif /* CONFIG_PPC_MEM_KEYS */
510f2407ef3SRam Pai
pte_user(pte_t pte)5111b2443a5SChristophe Leroy static inline bool pte_user(pte_t pte)
5121b2443a5SChristophe Leroy {
5131b2443a5SChristophe Leroy return !(pte_raw(pte) & cpu_to_be64(_PAGE_PRIVILEGED));
5141b2443a5SChristophe Leroy }
5151b2443a5SChristophe Leroy
516f72a85e3SAneesh Kumar K.V #define pte_access_permitted pte_access_permitted
pte_access_permitted(pte_t pte,bool write)517f72a85e3SAneesh Kumar K.V static inline bool pte_access_permitted(pte_t pte, bool write)
518f72a85e3SAneesh Kumar K.V {
519f72a85e3SAneesh Kumar K.V /*
520f72a85e3SAneesh Kumar K.V * _PAGE_READ is needed for any access and will be
521f72a85e3SAneesh Kumar K.V * cleared for PROT_NONE
522f72a85e3SAneesh Kumar K.V */
5231b2443a5SChristophe Leroy if (!pte_present(pte) || !pte_user(pte) || !pte_read(pte))
524f72a85e3SAneesh Kumar K.V return false;
525f72a85e3SAneesh Kumar K.V
5261b2443a5SChristophe Leroy if (write && !pte_write(pte))
527f72a85e3SAneesh Kumar K.V return false;
528bca7aacfSRam Pai
529bca7aacfSRam Pai return arch_pte_access_permitted(pte_val(pte), write, 0);
530f72a85e3SAneesh Kumar K.V }
531f72a85e3SAneesh Kumar K.V
53213f829a5SAneesh Kumar K.V /*
53313f829a5SAneesh Kumar K.V * Conversion functions: convert a page and protection to a page entry,
53413f829a5SAneesh Kumar K.V * and a page entry and page directory to the page they refer to.
53513f829a5SAneesh Kumar K.V *
53613f829a5SAneesh Kumar K.V * Even if PTEs can be unsigned long long, a PFN is always an unsigned
53713f829a5SAneesh Kumar K.V * long for now.
53813f829a5SAneesh Kumar K.V */
pfn_pte(unsigned long pfn,pgprot_t pgprot)53913f829a5SAneesh Kumar K.V static inline pte_t pfn_pte(unsigned long pfn, pgprot_t pgprot)
54013f829a5SAneesh Kumar K.V {
5416bb25170SNicholas Piggin VM_BUG_ON(pfn >> (64 - PAGE_SHIFT));
5426bb25170SNicholas Piggin VM_BUG_ON((pfn << PAGE_SHIFT) & ~PTE_RPN_MASK);
5436bb25170SNicholas Piggin
544379c926dSAneesh Kumar K.V return __pte(((pte_basic_t)pfn << PAGE_SHIFT) | pgprot_val(pgprot) | _PAGE_PTE);
54513f829a5SAneesh Kumar K.V }
54613f829a5SAneesh Kumar K.V
54713f829a5SAneesh Kumar K.V /* Generic modifiers for PTE bits */
pte_wrprotect(pte_t pte)54813f829a5SAneesh Kumar K.V static inline pte_t pte_wrprotect(pte_t pte)
54913f829a5SAneesh Kumar K.V {
5501b2443a5SChristophe Leroy return __pte_raw(pte_raw(pte) & cpu_to_be64(~_PAGE_WRITE));
55113f829a5SAneesh Kumar K.V }
55213f829a5SAneesh Kumar K.V
pte_exprotect(pte_t pte)553daba7902SChristophe Leroy static inline pte_t pte_exprotect(pte_t pte)
554daba7902SChristophe Leroy {
5551b2443a5SChristophe Leroy return __pte_raw(pte_raw(pte) & cpu_to_be64(~_PAGE_EXEC));
55613f829a5SAneesh Kumar K.V }
55713f829a5SAneesh Kumar K.V
pte_mkclean(pte_t pte)55813f829a5SAneesh Kumar K.V static inline pte_t pte_mkclean(pte_t pte)
55913f829a5SAneesh Kumar K.V {
5601b2443a5SChristophe Leroy return __pte_raw(pte_raw(pte) & cpu_to_be64(~_PAGE_DIRTY));
56113f829a5SAneesh Kumar K.V }
56213f829a5SAneesh Kumar K.V
pte_mkold(pte_t pte)56313f829a5SAneesh Kumar K.V static inline pte_t pte_mkold(pte_t pte)
56413f829a5SAneesh Kumar K.V {
5651b2443a5SChristophe Leroy return __pte_raw(pte_raw(pte) & cpu_to_be64(~_PAGE_ACCESSED));
56613f829a5SAneesh Kumar K.V }
56713f829a5SAneesh Kumar K.V
pte_mkexec(pte_t pte)568daba7902SChristophe Leroy static inline pte_t pte_mkexec(pte_t pte)
569daba7902SChristophe Leroy {
5701b2443a5SChristophe Leroy return __pte_raw(pte_raw(pte) | cpu_to_be64(_PAGE_EXEC));
571daba7902SChristophe Leroy }
572daba7902SChristophe Leroy
pte_mkwrite_novma(pte_t pte)5732f0584f3SRick Edgecombe static inline pte_t pte_mkwrite_novma(pte_t pte)
57413f829a5SAneesh Kumar K.V {
57513f829a5SAneesh Kumar K.V /*
57613f829a5SAneesh Kumar K.V * write implies read, hence set both
57713f829a5SAneesh Kumar K.V */
5781b2443a5SChristophe Leroy return __pte_raw(pte_raw(pte) | cpu_to_be64(_PAGE_RW));
57913f829a5SAneesh Kumar K.V }
58013f829a5SAneesh Kumar K.V
pte_mkdirty(pte_t pte)58113f829a5SAneesh Kumar K.V static inline pte_t pte_mkdirty(pte_t pte)
58213f829a5SAneesh Kumar K.V {
5831b2443a5SChristophe Leroy return __pte_raw(pte_raw(pte) | cpu_to_be64(_PAGE_DIRTY | _PAGE_SOFT_DIRTY));
58413f829a5SAneesh Kumar K.V }
58513f829a5SAneesh Kumar K.V
pte_mkyoung(pte_t pte)58613f829a5SAneesh Kumar K.V static inline pte_t pte_mkyoung(pte_t pte)
58713f829a5SAneesh Kumar K.V {
5881b2443a5SChristophe Leroy return __pte_raw(pte_raw(pte) | cpu_to_be64(_PAGE_ACCESSED));
58913f829a5SAneesh Kumar K.V }
59013f829a5SAneesh Kumar K.V
pte_mkspecial(pte_t pte)59113f829a5SAneesh Kumar K.V static inline pte_t pte_mkspecial(pte_t pte)
59213f829a5SAneesh Kumar K.V {
5931b2443a5SChristophe Leroy return __pte_raw(pte_raw(pte) | cpu_to_be64(_PAGE_SPECIAL));
59413f829a5SAneesh Kumar K.V }
59513f829a5SAneesh Kumar K.V
pte_mkhuge(pte_t pte)59613f829a5SAneesh Kumar K.V static inline pte_t pte_mkhuge(pte_t pte)
59713f829a5SAneesh Kumar K.V {
59813f829a5SAneesh Kumar K.V return pte;
59913f829a5SAneesh Kumar K.V }
60013f829a5SAneesh Kumar K.V
pte_mkdevmap(pte_t pte)601ebd31197SOliver O'Halloran static inline pte_t pte_mkdevmap(pte_t pte)
602ebd31197SOliver O'Halloran {
6031b2443a5SChristophe Leroy return __pte_raw(pte_raw(pte) | cpu_to_be64(_PAGE_SPECIAL | _PAGE_DEVMAP));
604ebd31197SOliver O'Halloran }
605ebd31197SOliver O'Halloran
pte_mkprivileged(pte_t pte)606daba7902SChristophe Leroy static inline pte_t pte_mkprivileged(pte_t pte)
607daba7902SChristophe Leroy {
6081b2443a5SChristophe Leroy return __pte_raw(pte_raw(pte) | cpu_to_be64(_PAGE_PRIVILEGED));
609daba7902SChristophe Leroy }
610daba7902SChristophe Leroy
pte_mkuser(pte_t pte)611daba7902SChristophe Leroy static inline pte_t pte_mkuser(pte_t pte)
612daba7902SChristophe Leroy {
6131b2443a5SChristophe Leroy return __pte_raw(pte_raw(pte) & cpu_to_be64(~_PAGE_PRIVILEGED));
614ebd31197SOliver O'Halloran }
615ebd31197SOliver O'Halloran
616c9c98bc5SOliver O'Halloran /*
617c9c98bc5SOliver O'Halloran * This is potentially called with a pmd as the argument, in which case it's not
618c9c98bc5SOliver O'Halloran * safe to check _PAGE_DEVMAP unless we also confirm that _PAGE_PTE is set.
619c9c98bc5SOliver O'Halloran * That's because the bit we use for _PAGE_DEVMAP is not reserved for software
620c9c98bc5SOliver O'Halloran * use in page directory entries (ie. non-ptes).
621c9c98bc5SOliver O'Halloran */
pte_devmap(pte_t pte)622ebd31197SOliver O'Halloran static inline int pte_devmap(pte_t pte)
623ebd31197SOliver O'Halloran {
624c9c98bc5SOliver O'Halloran u64 mask = cpu_to_be64(_PAGE_DEVMAP | _PAGE_PTE);
625c9c98bc5SOliver O'Halloran
626c9c98bc5SOliver O'Halloran return (pte_raw(pte) & mask) == mask;
627ebd31197SOliver O'Halloran }
628ebd31197SOliver O'Halloran
pte_modify(pte_t pte,pgprot_t newprot)62913f829a5SAneesh Kumar K.V static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
63013f829a5SAneesh Kumar K.V {
63113f829a5SAneesh Kumar K.V /* FIXME!! check whether this need to be a conditional */
6321b2443a5SChristophe Leroy return __pte_raw((pte_raw(pte) & cpu_to_be64(_PAGE_CHG_MASK)) |
6331b2443a5SChristophe Leroy cpu_to_be64(pgprot_val(newprot)));
63434fbadd8SAneesh Kumar K.V }
63534fbadd8SAneesh Kumar K.V
63634fbadd8SAneesh Kumar K.V /* Encode and de-code a swap entry */
63734fbadd8SAneesh Kumar K.V #define MAX_SWAPFILES_CHECK() do { \
63834fbadd8SAneesh Kumar K.V BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > SWP_TYPE_BITS); \
63934fbadd8SAneesh Kumar K.V /* \
64034fbadd8SAneesh Kumar K.V * Don't have overlapping bits with _PAGE_HPTEFLAGS \
64134fbadd8SAneesh Kumar K.V * We filter HPTEFLAGS on set_pte. \
64234fbadd8SAneesh Kumar K.V */ \
64303ac1b71SDavid Hildenbrand BUILD_BUG_ON(_PAGE_HPTEFLAGS & SWP_TYPE_MASK); \
64434fbadd8SAneesh Kumar K.V BUILD_BUG_ON(_PAGE_HPTEFLAGS & _PAGE_SWP_SOFT_DIRTY); \
645bff9beaaSDavid Hildenbrand BUILD_BUG_ON(_PAGE_HPTEFLAGS & _PAGE_SWP_EXCLUSIVE); \
64634fbadd8SAneesh Kumar K.V } while (0)
6473159f943SMatthew Wilcox
64834fbadd8SAneesh Kumar K.V #define SWP_TYPE_BITS 5
64903ac1b71SDavid Hildenbrand #define SWP_TYPE_MASK ((1UL << SWP_TYPE_BITS) - 1)
65003ac1b71SDavid Hildenbrand #define __swp_type(x) ((x).val & SWP_TYPE_MASK)
65134fbadd8SAneesh Kumar K.V #define __swp_offset(x) (((x).val & PTE_RPN_MASK) >> PAGE_SHIFT)
65234fbadd8SAneesh Kumar K.V #define __swp_entry(type, offset) ((swp_entry_t) { \
65303ac1b71SDavid Hildenbrand (type) | (((offset) << PAGE_SHIFT) & PTE_RPN_MASK)})
65434fbadd8SAneesh Kumar K.V /*
65534fbadd8SAneesh Kumar K.V * swp_entry_t must be independent of pte bits. We build a swp_entry_t from
65634fbadd8SAneesh Kumar K.V * swap type and offset we get from swap and convert that to pte to find a
65734fbadd8SAneesh Kumar K.V * matching pte in linux page table.
65834fbadd8SAneesh Kumar K.V * Clear bits not found in swap entries here.
65934fbadd8SAneesh Kumar K.V */
66034fbadd8SAneesh Kumar K.V #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val((pte)) & ~_PAGE_PTE })
66134fbadd8SAneesh Kumar K.V #define __swp_entry_to_pte(x) __pte((x).val | _PAGE_PTE)
662a0820ff3SAneesh Kumar K.V #define __pmd_to_swp_entry(pmd) (__pte_to_swp_entry(pmd_pte(pmd)))
663a0820ff3SAneesh Kumar K.V #define __swp_entry_to_pmd(x) (pte_pmd(__swp_entry_to_pte(x)))
66434fbadd8SAneesh Kumar K.V
66534fbadd8SAneesh Kumar K.V #ifdef CONFIG_MEM_SOFT_DIRTY
666bff9beaaSDavid Hildenbrand #define _PAGE_SWP_SOFT_DIRTY _PAGE_SOFT_DIRTY
66734fbadd8SAneesh Kumar K.V #else
66834fbadd8SAneesh Kumar K.V #define _PAGE_SWP_SOFT_DIRTY 0UL
66934fbadd8SAneesh Kumar K.V #endif /* CONFIG_MEM_SOFT_DIRTY */
67034fbadd8SAneesh Kumar K.V
671bff9beaaSDavid Hildenbrand #define _PAGE_SWP_EXCLUSIVE _PAGE_NON_IDEMPOTENT
672bff9beaaSDavid Hildenbrand
67334fbadd8SAneesh Kumar K.V #ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
pte_swp_mksoft_dirty(pte_t pte)67434fbadd8SAneesh Kumar K.V static inline pte_t pte_swp_mksoft_dirty(pte_t pte)
67534fbadd8SAneesh Kumar K.V {
6761b2443a5SChristophe Leroy return __pte_raw(pte_raw(pte) | cpu_to_be64(_PAGE_SWP_SOFT_DIRTY));
67734fbadd8SAneesh Kumar K.V }
67866c570f5SAneesh Kumar K.V
pte_swp_soft_dirty(pte_t pte)67934fbadd8SAneesh Kumar K.V static inline bool pte_swp_soft_dirty(pte_t pte)
68034fbadd8SAneesh Kumar K.V {
68166c570f5SAneesh Kumar K.V return !!(pte_raw(pte) & cpu_to_be64(_PAGE_SWP_SOFT_DIRTY));
68234fbadd8SAneesh Kumar K.V }
68366c570f5SAneesh Kumar K.V
pte_swp_clear_soft_dirty(pte_t pte)68434fbadd8SAneesh Kumar K.V static inline pte_t pte_swp_clear_soft_dirty(pte_t pte)
68534fbadd8SAneesh Kumar K.V {
6861b2443a5SChristophe Leroy return __pte_raw(pte_raw(pte) & cpu_to_be64(~_PAGE_SWP_SOFT_DIRTY));
68734fbadd8SAneesh Kumar K.V }
68834fbadd8SAneesh Kumar K.V #endif /* CONFIG_HAVE_ARCH_SOFT_DIRTY */
68934fbadd8SAneesh Kumar K.V
pte_swp_mkexclusive(pte_t pte)690bff9beaaSDavid Hildenbrand static inline pte_t pte_swp_mkexclusive(pte_t pte)
691bff9beaaSDavid Hildenbrand {
692bff9beaaSDavid Hildenbrand return __pte_raw(pte_raw(pte) | cpu_to_be64(_PAGE_SWP_EXCLUSIVE));
693bff9beaaSDavid Hildenbrand }
694bff9beaaSDavid Hildenbrand
pte_swp_exclusive(pte_t pte)695bff9beaaSDavid Hildenbrand static inline int pte_swp_exclusive(pte_t pte)
696bff9beaaSDavid Hildenbrand {
697bff9beaaSDavid Hildenbrand return !!(pte_raw(pte) & cpu_to_be64(_PAGE_SWP_EXCLUSIVE));
698bff9beaaSDavid Hildenbrand }
699bff9beaaSDavid Hildenbrand
pte_swp_clear_exclusive(pte_t pte)700bff9beaaSDavid Hildenbrand static inline pte_t pte_swp_clear_exclusive(pte_t pte)
701bff9beaaSDavid Hildenbrand {
702bff9beaaSDavid Hildenbrand return __pte_raw(pte_raw(pte) & cpu_to_be64(~_PAGE_SWP_EXCLUSIVE));
703bff9beaaSDavid Hildenbrand }
704bff9beaaSDavid Hildenbrand
check_pte_access(unsigned long access,unsigned long ptev)70534fbadd8SAneesh Kumar K.V static inline bool check_pte_access(unsigned long access, unsigned long ptev)
70634fbadd8SAneesh Kumar K.V {
70734fbadd8SAneesh Kumar K.V /*
70834fbadd8SAneesh Kumar K.V * This check for _PAGE_RWX and _PAGE_PRESENT bits
70934fbadd8SAneesh Kumar K.V */
71034fbadd8SAneesh Kumar K.V if (access & ~ptev)
71134fbadd8SAneesh Kumar K.V return false;
71234fbadd8SAneesh Kumar K.V /*
71334fbadd8SAneesh Kumar K.V * This check for access to privilege space
71434fbadd8SAneesh Kumar K.V */
71534fbadd8SAneesh Kumar K.V if ((access & _PAGE_PRIVILEGED) != (ptev & _PAGE_PRIVILEGED))
71634fbadd8SAneesh Kumar K.V return false;
71734fbadd8SAneesh Kumar K.V
71834fbadd8SAneesh Kumar K.V return true;
71934fbadd8SAneesh Kumar K.V }
720ac94ac79SAneesh Kumar K.V /*
721ac94ac79SAneesh Kumar K.V * Generic functions with hash/radix callbacks
722ac94ac79SAneesh Kumar K.V */
723ac94ac79SAneesh Kumar K.V
__ptep_set_access_flags(struct vm_area_struct * vma,pte_t * ptep,pte_t entry,unsigned long address,int psize)724e4c1112cSAneesh Kumar K.V static inline void __ptep_set_access_flags(struct vm_area_struct *vma,
725b3603e17SAneesh Kumar K.V pte_t *ptep, pte_t entry,
726e4c1112cSAneesh Kumar K.V unsigned long address,
727e4c1112cSAneesh Kumar K.V int psize)
728ac94ac79SAneesh Kumar K.V {
729ac94ac79SAneesh Kumar K.V if (radix_enabled())
730e4c1112cSAneesh Kumar K.V return radix__ptep_set_access_flags(vma, ptep, entry,
731e4c1112cSAneesh Kumar K.V address, psize);
732ac94ac79SAneesh Kumar K.V return hash__ptep_set_access_flags(ptep, entry);
733ac94ac79SAneesh Kumar K.V }
734ac94ac79SAneesh Kumar K.V
735ac94ac79SAneesh Kumar K.V #define __HAVE_ARCH_PTE_SAME
pte_same(pte_t pte_a,pte_t pte_b)736ac94ac79SAneesh Kumar K.V static inline int pte_same(pte_t pte_a, pte_t pte_b)
737ac94ac79SAneesh Kumar K.V {
738ac94ac79SAneesh Kumar K.V if (radix_enabled())
739ac94ac79SAneesh Kumar K.V return radix__pte_same(pte_a, pte_b);
740ac94ac79SAneesh Kumar K.V return hash__pte_same(pte_a, pte_b);
741ac94ac79SAneesh Kumar K.V }
742ac94ac79SAneesh Kumar K.V
pte_none(pte_t pte)743ac94ac79SAneesh Kumar K.V static inline int pte_none(pte_t pte)
744ac94ac79SAneesh Kumar K.V {
745ac94ac79SAneesh Kumar K.V if (radix_enabled())
746ac94ac79SAneesh Kumar K.V return radix__pte_none(pte);
747ac94ac79SAneesh Kumar K.V return hash__pte_none(pte);
748ac94ac79SAneesh Kumar K.V }
749ac94ac79SAneesh Kumar K.V
__set_pte_at(struct mm_struct * mm,unsigned long addr,pte_t * ptep,pte_t pte,int percpu)750ac94ac79SAneesh Kumar K.V static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,
751ac94ac79SAneesh Kumar K.V pte_t *ptep, pte_t pte, int percpu)
752ac94ac79SAneesh Kumar K.V {
753379c926dSAneesh Kumar K.V
754379c926dSAneesh Kumar K.V VM_WARN_ON(!(pte_raw(pte) & cpu_to_be64(_PAGE_PTE)));
755379c926dSAneesh Kumar K.V /*
756379c926dSAneesh Kumar K.V * Keep the _PAGE_PTE added till we are sure we handle _PAGE_PTE
757379c926dSAneesh Kumar K.V * in all the callers.
758379c926dSAneesh Kumar K.V */
759379c926dSAneesh Kumar K.V pte = __pte_raw(pte_raw(pte) | cpu_to_be64(_PAGE_PTE));
760379c926dSAneesh Kumar K.V
761ac94ac79SAneesh Kumar K.V if (radix_enabled())
762ac94ac79SAneesh Kumar K.V return radix__set_pte_at(mm, addr, ptep, pte, percpu);
763ac94ac79SAneesh Kumar K.V return hash__set_pte_at(mm, addr, ptep, pte, percpu);
764ac94ac79SAneesh Kumar K.V }
76534fbadd8SAneesh Kumar K.V
76612564485SShawn Anastasio #define _PAGE_CACHE_CTL (_PAGE_SAO | _PAGE_NON_IDEMPOTENT | _PAGE_TOLERANT)
76712564485SShawn Anastasio
76813f829a5SAneesh Kumar K.V #define pgprot_noncached pgprot_noncached
pgprot_noncached(pgprot_t prot)76913f829a5SAneesh Kumar K.V static inline pgprot_t pgprot_noncached(pgprot_t prot)
77013f829a5SAneesh Kumar K.V {
77113f829a5SAneesh Kumar K.V return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) |
77213f829a5SAneesh Kumar K.V _PAGE_NON_IDEMPOTENT);
77313f829a5SAneesh Kumar K.V }
77413f829a5SAneesh Kumar K.V
77513f829a5SAneesh Kumar K.V #define pgprot_noncached_wc pgprot_noncached_wc
pgprot_noncached_wc(pgprot_t prot)77613f829a5SAneesh Kumar K.V static inline pgprot_t pgprot_noncached_wc(pgprot_t prot)
77713f829a5SAneesh Kumar K.V {
77813f829a5SAneesh Kumar K.V return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) |
77913f829a5SAneesh Kumar K.V _PAGE_TOLERANT);
78013f829a5SAneesh Kumar K.V }
78113f829a5SAneesh Kumar K.V
78213f829a5SAneesh Kumar K.V #define pgprot_cached pgprot_cached
pgprot_cached(pgprot_t prot)78313f829a5SAneesh Kumar K.V static inline pgprot_t pgprot_cached(pgprot_t prot)
78413f829a5SAneesh Kumar K.V {
78513f829a5SAneesh Kumar K.V return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL));
78613f829a5SAneesh Kumar K.V }
78713f829a5SAneesh Kumar K.V
78813f829a5SAneesh Kumar K.V #define pgprot_writecombine pgprot_writecombine
pgprot_writecombine(pgprot_t prot)78913f829a5SAneesh Kumar K.V static inline pgprot_t pgprot_writecombine(pgprot_t prot)
79013f829a5SAneesh Kumar K.V {
79113f829a5SAneesh Kumar K.V return pgprot_noncached_wc(prot);
79213f829a5SAneesh Kumar K.V }
79313f829a5SAneesh Kumar K.V /*
79413f829a5SAneesh Kumar K.V * check a pte mapping have cache inhibited property
79513f829a5SAneesh Kumar K.V */
pte_ci(pte_t pte)79613f829a5SAneesh Kumar K.V static inline bool pte_ci(pte_t pte)
79713f829a5SAneesh Kumar K.V {
7981b2443a5SChristophe Leroy __be64 pte_v = pte_raw(pte);
79913f829a5SAneesh Kumar K.V
8001b2443a5SChristophe Leroy if (((pte_v & cpu_to_be64(_PAGE_CACHE_CTL)) == cpu_to_be64(_PAGE_TOLERANT)) ||
8011b2443a5SChristophe Leroy ((pte_v & cpu_to_be64(_PAGE_CACHE_CTL)) == cpu_to_be64(_PAGE_NON_IDEMPOTENT)))
80213f829a5SAneesh Kumar K.V return true;
80313f829a5SAneesh Kumar K.V return false;
80413f829a5SAneesh Kumar K.V }
80513f829a5SAneesh Kumar K.V
pmd_clear(pmd_t * pmdp)806f281b5d5SAneesh Kumar K.V static inline void pmd_clear(pmd_t *pmdp)
807f281b5d5SAneesh Kumar K.V {
808392b4669SAneesh Kumar K.V if (IS_ENABLED(CONFIG_DEBUG_VM) && !radix_enabled()) {
809392b4669SAneesh Kumar K.V /*
810392b4669SAneesh Kumar K.V * Don't use this if we can possibly have a hash page table
811392b4669SAneesh Kumar K.V * entry mapping this.
812392b4669SAneesh Kumar K.V */
813392b4669SAneesh Kumar K.V WARN_ON((pmd_val(*pmdp) & (H_PAGE_HASHPTE | _PAGE_PTE)) == (H_PAGE_HASHPTE | _PAGE_PTE));
814392b4669SAneesh Kumar K.V }
815f281b5d5SAneesh Kumar K.V *pmdp = __pmd(0);
816f281b5d5SAneesh Kumar K.V }
817f281b5d5SAneesh Kumar K.V
pmd_none(pmd_t pmd)81866c570f5SAneesh Kumar K.V static inline int pmd_none(pmd_t pmd)
81966c570f5SAneesh Kumar K.V {
82066c570f5SAneesh Kumar K.V return !pmd_raw(pmd);
82166c570f5SAneesh Kumar K.V }
82266c570f5SAneesh Kumar K.V
pmd_present(pmd_t pmd)82366c570f5SAneesh Kumar K.V static inline int pmd_present(pmd_t pmd)
82466c570f5SAneesh Kumar K.V {
825da7ad366SAneesh Kumar K.V /*
826da7ad366SAneesh Kumar K.V * A pmd is considerent present if _PAGE_PRESENT is set.
827da7ad366SAneesh Kumar K.V * We also need to consider the pmd present which is marked
828da7ad366SAneesh Kumar K.V * invalid during a split. Hence we look for _PAGE_INVALID
829da7ad366SAneesh Kumar K.V * if we find _PAGE_PRESENT cleared.
830da7ad366SAneesh Kumar K.V */
831da7ad366SAneesh Kumar K.V if (pmd_raw(pmd) & cpu_to_be64(_PAGE_PRESENT | _PAGE_INVALID))
832da7ad366SAneesh Kumar K.V return true;
83366c570f5SAneesh Kumar K.V
834da7ad366SAneesh Kumar K.V return false;
83566c570f5SAneesh Kumar K.V }
8363dfcb315SAneesh Kumar K.V
pmd_is_serializing(pmd_t pmd)83733258a1dSNicholas Piggin static inline int pmd_is_serializing(pmd_t pmd)
83833258a1dSNicholas Piggin {
83933258a1dSNicholas Piggin /*
84033258a1dSNicholas Piggin * If the pmd is undergoing a split, the _PAGE_PRESENT bit is clear
84133258a1dSNicholas Piggin * and _PAGE_INVALID is set (see pmd_present, pmdp_invalidate).
84233258a1dSNicholas Piggin *
84333258a1dSNicholas Piggin * This condition may also occur when flushing a pmd while flushing
84433258a1dSNicholas Piggin * it (see ptep_modify_prot_start), so callers must ensure this
84533258a1dSNicholas Piggin * case is fine as well.
84633258a1dSNicholas Piggin */
84733258a1dSNicholas Piggin if ((pmd_raw(pmd) & cpu_to_be64(_PAGE_PRESENT | _PAGE_INVALID)) ==
84833258a1dSNicholas Piggin cpu_to_be64(_PAGE_INVALID))
84933258a1dSNicholas Piggin return true;
85033258a1dSNicholas Piggin
85133258a1dSNicholas Piggin return false;
85233258a1dSNicholas Piggin }
85333258a1dSNicholas Piggin
pmd_bad(pmd_t pmd)854ac94ac79SAneesh Kumar K.V static inline int pmd_bad(pmd_t pmd)
855ac94ac79SAneesh Kumar K.V {
856ac94ac79SAneesh Kumar K.V if (radix_enabled())
857ac94ac79SAneesh Kumar K.V return radix__pmd_bad(pmd);
858ac94ac79SAneesh Kumar K.V return hash__pmd_bad(pmd);
859ac94ac79SAneesh Kumar K.V }
860ac94ac79SAneesh Kumar K.V
pud_clear(pud_t * pudp)861f281b5d5SAneesh Kumar K.V static inline void pud_clear(pud_t *pudp)
862f281b5d5SAneesh Kumar K.V {
863392b4669SAneesh Kumar K.V if (IS_ENABLED(CONFIG_DEBUG_VM) && !radix_enabled()) {
864392b4669SAneesh Kumar K.V /*
865392b4669SAneesh Kumar K.V * Don't use this if we can possibly have a hash page table
866392b4669SAneesh Kumar K.V * entry mapping this.
867392b4669SAneesh Kumar K.V */
868392b4669SAneesh Kumar K.V WARN_ON((pud_val(*pudp) & (H_PAGE_HASHPTE | _PAGE_PTE)) == (H_PAGE_HASHPTE | _PAGE_PTE));
869392b4669SAneesh Kumar K.V }
870f281b5d5SAneesh Kumar K.V *pudp = __pud(0);
871f281b5d5SAneesh Kumar K.V }
872f281b5d5SAneesh Kumar K.V
pud_none(pud_t pud)87366c570f5SAneesh Kumar K.V static inline int pud_none(pud_t pud)
87466c570f5SAneesh Kumar K.V {
87566c570f5SAneesh Kumar K.V return !pud_raw(pud);
87666c570f5SAneesh Kumar K.V }
87766c570f5SAneesh Kumar K.V
pud_present(pud_t pud)87866c570f5SAneesh Kumar K.V static inline int pud_present(pud_t pud)
87966c570f5SAneesh Kumar K.V {
880a5800762SMichael Ellerman return !!(pud_raw(pud) & cpu_to_be64(_PAGE_PRESENT));
88166c570f5SAneesh Kumar K.V }
8823dfcb315SAneesh Kumar K.V
8833dfcb315SAneesh Kumar K.V extern struct page *pud_page(pud_t pud);
884371352caSAneesh Kumar K.V extern struct page *pmd_page(pmd_t pmd);
pud_pte(pud_t pud)8853dfcb315SAneesh Kumar K.V static inline pte_t pud_pte(pud_t pud)
8863dfcb315SAneesh Kumar K.V {
88766c570f5SAneesh Kumar K.V return __pte_raw(pud_raw(pud));
8883dfcb315SAneesh Kumar K.V }
8893dfcb315SAneesh Kumar K.V
pte_pud(pte_t pte)8903dfcb315SAneesh Kumar K.V static inline pud_t pte_pud(pte_t pte)
8913dfcb315SAneesh Kumar K.V {
89266c570f5SAneesh Kumar K.V return __pud_raw(pte_raw(pte));
8933dfcb315SAneesh Kumar K.V }
89427af67f3SAneesh Kumar K.V
pudp_ptep(pud_t * pud)89527af67f3SAneesh Kumar K.V static inline pte_t *pudp_ptep(pud_t *pud)
89627af67f3SAneesh Kumar K.V {
89727af67f3SAneesh Kumar K.V return (pte_t *)pud;
89827af67f3SAneesh Kumar K.V }
89927af67f3SAneesh Kumar K.V
90027af67f3SAneesh Kumar K.V #define pud_pfn(pud) pte_pfn(pud_pte(pud))
90127af67f3SAneesh Kumar K.V #define pud_dirty(pud) pte_dirty(pud_pte(pud))
90227af67f3SAneesh Kumar K.V #define pud_young(pud) pte_young(pud_pte(pud))
90327af67f3SAneesh Kumar K.V #define pud_mkold(pud) pte_pud(pte_mkold(pud_pte(pud)))
90427af67f3SAneesh Kumar K.V #define pud_wrprotect(pud) pte_pud(pte_wrprotect(pud_pte(pud)))
90527af67f3SAneesh Kumar K.V #define pud_mkdirty(pud) pte_pud(pte_mkdirty(pud_pte(pud)))
90627af67f3SAneesh Kumar K.V #define pud_mkclean(pud) pte_pud(pte_mkclean(pud_pte(pud)))
90727af67f3SAneesh Kumar K.V #define pud_mkyoung(pud) pte_pud(pte_mkyoung(pud_pte(pud)))
908*f441ff73SIngo Molnar #define pud_mkwrite(pud) pte_pud(pte_mkwrite_novma(pud_pte(pud)))
9093dfcb315SAneesh Kumar K.V #define pud_write(pud) pte_write(pud_pte(pud))
910ac94ac79SAneesh Kumar K.V
91127af67f3SAneesh Kumar K.V #ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
91227af67f3SAneesh Kumar K.V #define pud_soft_dirty(pmd) pte_soft_dirty(pud_pte(pud))
91327af67f3SAneesh Kumar K.V #define pud_mksoft_dirty(pmd) pte_pud(pte_mksoft_dirty(pud_pte(pud)))
91427af67f3SAneesh Kumar K.V #define pud_clear_soft_dirty(pmd) pte_pud(pte_clear_soft_dirty(pud_pte(pud)))
91527af67f3SAneesh Kumar K.V #endif /* CONFIG_HAVE_ARCH_SOFT_DIRTY */
91627af67f3SAneesh Kumar K.V
pud_bad(pud_t pud)917ac94ac79SAneesh Kumar K.V static inline int pud_bad(pud_t pud)
918ac94ac79SAneesh Kumar K.V {
919ac94ac79SAneesh Kumar K.V if (radix_enabled())
920ac94ac79SAneesh Kumar K.V return radix__pud_bad(pud);
921ac94ac79SAneesh Kumar K.V return hash__pud_bad(pud);
922ac94ac79SAneesh Kumar K.V }
923ac94ac79SAneesh Kumar K.V
924f72a85e3SAneesh Kumar K.V #define pud_access_permitted pud_access_permitted
pud_access_permitted(pud_t pud,bool write)925f72a85e3SAneesh Kumar K.V static inline bool pud_access_permitted(pud_t pud, bool write)
926f72a85e3SAneesh Kumar K.V {
927f72a85e3SAneesh Kumar K.V return pte_access_permitted(pud_pte(pud), write);
928f72a85e3SAneesh Kumar K.V }
929ac94ac79SAneesh Kumar K.V
9302fb47060SMike Rapoport #define __p4d_raw(x) ((p4d_t) { __pgd_raw(x) })
p4d_raw(p4d_t x)9312fb47060SMike Rapoport static inline __be64 p4d_raw(p4d_t x)
932368ced78SAneesh Kumar K.V {
9332fb47060SMike Rapoport return pgd_raw(x.pgd);
934368ced78SAneesh Kumar K.V }
935368ced78SAneesh Kumar K.V
9362fb47060SMike Rapoport #define p4d_write(p4d) pte_write(p4d_pte(p4d))
9372fb47060SMike Rapoport
p4d_clear(p4d_t * p4dp)9382fb47060SMike Rapoport static inline void p4d_clear(p4d_t *p4dp)
93966c570f5SAneesh Kumar K.V {
9402fb47060SMike Rapoport *p4dp = __p4d(0);
94166c570f5SAneesh Kumar K.V }
94266c570f5SAneesh Kumar K.V
p4d_none(p4d_t p4d)9432fb47060SMike Rapoport static inline int p4d_none(p4d_t p4d)
94466c570f5SAneesh Kumar K.V {
9452fb47060SMike Rapoport return !p4d_raw(p4d);
94666c570f5SAneesh Kumar K.V }
947368ced78SAneesh Kumar K.V
p4d_present(p4d_t p4d)9482fb47060SMike Rapoport static inline int p4d_present(p4d_t p4d)
949368ced78SAneesh Kumar K.V {
9502fb47060SMike Rapoport return !!(p4d_raw(p4d) & cpu_to_be64(_PAGE_PRESENT));
951368ced78SAneesh Kumar K.V }
952368ced78SAneesh Kumar K.V
p4d_pte(p4d_t p4d)9532fb47060SMike Rapoport static inline pte_t p4d_pte(p4d_t p4d)
954368ced78SAneesh Kumar K.V {
9552fb47060SMike Rapoport return __pte_raw(p4d_raw(p4d));
956368ced78SAneesh Kumar K.V }
957368ced78SAneesh Kumar K.V
pte_p4d(pte_t pte)9582fb47060SMike Rapoport static inline p4d_t pte_p4d(pte_t pte)
9592fb47060SMike Rapoport {
9602fb47060SMike Rapoport return __p4d_raw(pte_raw(pte));
9612fb47060SMike Rapoport }
9622fb47060SMike Rapoport
p4d_bad(p4d_t p4d)9632fb47060SMike Rapoport static inline int p4d_bad(p4d_t p4d)
964ac94ac79SAneesh Kumar K.V {
965ac94ac79SAneesh Kumar K.V if (radix_enabled())
9662fb47060SMike Rapoport return radix__p4d_bad(p4d);
9672fb47060SMike Rapoport return hash__p4d_bad(p4d);
968ac94ac79SAneesh Kumar K.V }
969ac94ac79SAneesh Kumar K.V
9702fb47060SMike Rapoport #define p4d_access_permitted p4d_access_permitted
p4d_access_permitted(p4d_t p4d,bool write)9712fb47060SMike Rapoport static inline bool p4d_access_permitted(p4d_t p4d, bool write)
972f72a85e3SAneesh Kumar K.V {
9732fb47060SMike Rapoport return pte_access_permitted(p4d_pte(p4d), write);
974f72a85e3SAneesh Kumar K.V }
975f72a85e3SAneesh Kumar K.V
9762fb47060SMike Rapoport extern struct page *p4d_page(p4d_t p4d);
977368ced78SAneesh Kumar K.V
978aba480e1SAneesh Kumar K.V /* Pointers in the page table tree are physical addresses */
979aba480e1SAneesh Kumar K.V #define __pgtable_ptr_val(ptr) __pa(ptr)
980aba480e1SAneesh Kumar K.V
p4d_pgtable(p4d_t p4d)981dc4875f0SAneesh Kumar K.V static inline pud_t *p4d_pgtable(p4d_t p4d)
982dc4875f0SAneesh Kumar K.V {
983dc4875f0SAneesh Kumar K.V return (pud_t *)__va(p4d_val(p4d) & ~P4D_MASKED_BITS);
984dc4875f0SAneesh Kumar K.V }
985aba480e1SAneesh Kumar K.V
pud_pgtable(pud_t pud)9869cf6fa24SAneesh Kumar K.V static inline pmd_t *pud_pgtable(pud_t pud)
9879cf6fa24SAneesh Kumar K.V {
9889cf6fa24SAneesh Kumar K.V return (pmd_t *)__va(pud_val(pud) & ~PUD_MASKED_BITS);
9899cf6fa24SAneesh Kumar K.V }
9909cf6fa24SAneesh Kumar K.V
9913dfcb315SAneesh Kumar K.V #define pte_ERROR(e) \
9923dfcb315SAneesh Kumar K.V pr_err("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e))
9933dfcb315SAneesh Kumar K.V #define pmd_ERROR(e) \
9943dfcb315SAneesh Kumar K.V pr_err("%s:%d: bad pmd %08lx.\n", __FILE__, __LINE__, pmd_val(e))
995368ced78SAneesh Kumar K.V #define pud_ERROR(e) \
996368ced78SAneesh Kumar K.V pr_err("%s:%d: bad pud %08lx.\n", __FILE__, __LINE__, pud_val(e))
9973dfcb315SAneesh Kumar K.V #define pgd_ERROR(e) \
9983dfcb315SAneesh Kumar K.V pr_err("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
9993dfcb315SAneesh Kumar K.V
map_kernel_page(unsigned long ea,unsigned long pa,pgprot_t prot)1000c766ee72SChristophe Leroy static inline int map_kernel_page(unsigned long ea, unsigned long pa, pgprot_t prot)
100131a14faeSAneesh Kumar K.V {
1002d9225ad9SAneesh Kumar K.V if (radix_enabled()) {
1003d9225ad9SAneesh Kumar K.V #if defined(CONFIG_PPC_RADIX_MMU) && defined(DEBUG_VM)
1004d9225ad9SAneesh Kumar K.V unsigned long page_size = 1 << mmu_psize_defs[mmu_io_psize].shift;
1005d9225ad9SAneesh Kumar K.V WARN((page_size != PAGE_SIZE), "I/O page size != PAGE_SIZE");
1006d9225ad9SAneesh Kumar K.V #endif
1007c766ee72SChristophe Leroy return radix__map_kernel_page(ea, pa, prot, PAGE_SIZE);
1008d9225ad9SAneesh Kumar K.V }
1009c766ee72SChristophe Leroy return hash__map_kernel_page(ea, pa, prot);
101031a14faeSAneesh Kumar K.V }
101131a14faeSAneesh Kumar K.V
1012aec98260SChristophe Leroy void unmap_kernel_page(unsigned long va);
1013aec98260SChristophe Leroy
vmemmap_create_mapping(unsigned long start,unsigned long page_size,unsigned long phys)101431a14faeSAneesh Kumar K.V static inline int __meminit vmemmap_create_mapping(unsigned long start,
101531a14faeSAneesh Kumar K.V unsigned long page_size,
101631a14faeSAneesh Kumar K.V unsigned long phys)
101731a14faeSAneesh Kumar K.V {
1018d9225ad9SAneesh Kumar K.V if (radix_enabled())
1019d9225ad9SAneesh Kumar K.V return radix__vmemmap_create_mapping(start, page_size, phys);
102031a14faeSAneesh Kumar K.V return hash__vmemmap_create_mapping(start, page_size, phys);
102131a14faeSAneesh Kumar K.V }
102231a14faeSAneesh Kumar K.V
102331a14faeSAneesh Kumar K.V #ifdef CONFIG_MEMORY_HOTPLUG
vmemmap_remove_mapping(unsigned long start,unsigned long page_size)102431a14faeSAneesh Kumar K.V static inline void vmemmap_remove_mapping(unsigned long start,
102531a14faeSAneesh Kumar K.V unsigned long page_size)
102631a14faeSAneesh Kumar K.V {
1027d9225ad9SAneesh Kumar K.V if (radix_enabled())
1028d9225ad9SAneesh Kumar K.V return radix__vmemmap_remove_mapping(start, page_size);
102931a14faeSAneesh Kumar K.V return hash__vmemmap_remove_mapping(start, page_size);
103031a14faeSAneesh Kumar K.V }
103131a14faeSAneesh Kumar K.V #endif
10323dfcb315SAneesh Kumar K.V
1033a5edf981SNicholas Miehlbradt #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KFENCE)
__kernel_map_pages(struct page * page,int numpages,int enable)10344f703e7fSJoel Stanley static inline void __kernel_map_pages(struct page *page, int numpages, int enable)
10354f703e7fSJoel Stanley {
10364f703e7fSJoel Stanley if (radix_enabled())
10374f703e7fSJoel Stanley radix__kernel_map_pages(page, numpages, enable);
10384f703e7fSJoel Stanley else
10394f703e7fSJoel Stanley hash__kernel_map_pages(page, numpages, enable);
10404f703e7fSJoel Stanley }
10414f703e7fSJoel Stanley #endif
10424f703e7fSJoel Stanley
pmd_pte(pmd_t pmd)10433dfcb315SAneesh Kumar K.V static inline pte_t pmd_pte(pmd_t pmd)
10443dfcb315SAneesh Kumar K.V {
104566c570f5SAneesh Kumar K.V return __pte_raw(pmd_raw(pmd));
10463dfcb315SAneesh Kumar K.V }
10473dfcb315SAneesh Kumar K.V
pte_pmd(pte_t pte)10483dfcb315SAneesh Kumar K.V static inline pmd_t pte_pmd(pte_t pte)
10493dfcb315SAneesh Kumar K.V {
105066c570f5SAneesh Kumar K.V return __pmd_raw(pte_raw(pte));
10513dfcb315SAneesh Kumar K.V }
10523dfcb315SAneesh Kumar K.V
pmdp_ptep(pmd_t * pmd)10533dfcb315SAneesh Kumar K.V static inline pte_t *pmdp_ptep(pmd_t *pmd)
10543dfcb315SAneesh Kumar K.V {
10553dfcb315SAneesh Kumar K.V return (pte_t *)pmd;
10563dfcb315SAneesh Kumar K.V }
10573dfcb315SAneesh Kumar K.V #define pmd_pfn(pmd) pte_pfn(pmd_pte(pmd))
10583dfcb315SAneesh Kumar K.V #define pmd_dirty(pmd) pte_dirty(pmd_pte(pmd))
10593dfcb315SAneesh Kumar K.V #define pmd_young(pmd) pte_young(pmd_pte(pmd))
10603dfcb315SAneesh Kumar K.V #define pmd_mkold(pmd) pte_pmd(pte_mkold(pmd_pte(pmd)))
10613dfcb315SAneesh Kumar K.V #define pmd_wrprotect(pmd) pte_pmd(pte_wrprotect(pmd_pte(pmd)))
10623dfcb315SAneesh Kumar K.V #define pmd_mkdirty(pmd) pte_pmd(pte_mkdirty(pmd_pte(pmd)))
1063d5d6a443SMinchan Kim #define pmd_mkclean(pmd) pte_pmd(pte_mkclean(pmd_pte(pmd)))
10643dfcb315SAneesh Kumar K.V #define pmd_mkyoung(pmd) pte_pmd(pte_mkyoung(pmd_pte(pmd)))
10652f0584f3SRick Edgecombe #define pmd_mkwrite_novma(pmd) pte_pmd(pte_mkwrite_novma(pmd_pte(pmd)))
10667207f436SLaurent Dufour
10677207f436SLaurent Dufour #ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
10687207f436SLaurent Dufour #define pmd_soft_dirty(pmd) pte_soft_dirty(pmd_pte(pmd))
10697207f436SLaurent Dufour #define pmd_mksoft_dirty(pmd) pte_pmd(pte_mksoft_dirty(pmd_pte(pmd)))
10707207f436SLaurent Dufour #define pmd_clear_soft_dirty(pmd) pte_pmd(pte_clear_soft_dirty(pmd_pte(pmd)))
1071a0820ff3SAneesh Kumar K.V
1072a0820ff3SAneesh Kumar K.V #ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION
1073a0820ff3SAneesh Kumar K.V #define pmd_swp_mksoft_dirty(pmd) pte_pmd(pte_swp_mksoft_dirty(pmd_pte(pmd)))
1074a0820ff3SAneesh Kumar K.V #define pmd_swp_soft_dirty(pmd) pte_swp_soft_dirty(pmd_pte(pmd))
1075a0820ff3SAneesh Kumar K.V #define pmd_swp_clear_soft_dirty(pmd) pte_pmd(pte_swp_clear_soft_dirty(pmd_pte(pmd)))
1076a0820ff3SAneesh Kumar K.V #endif
10777207f436SLaurent Dufour #endif /* CONFIG_HAVE_ARCH_SOFT_DIRTY */
10787207f436SLaurent Dufour
10791ca72129SAneesh Kumar K.V #ifdef CONFIG_NUMA_BALANCING
pmd_protnone(pmd_t pmd)10801ca72129SAneesh Kumar K.V static inline int pmd_protnone(pmd_t pmd)
10811ca72129SAneesh Kumar K.V {
10821ca72129SAneesh Kumar K.V return pte_protnone(pmd_pte(pmd));
10831ca72129SAneesh Kumar K.V }
10841ca72129SAneesh Kumar K.V #endif /* CONFIG_NUMA_BALANCING */
10853dfcb315SAneesh Kumar K.V
10863dfcb315SAneesh Kumar K.V #define pmd_write(pmd) pte_write(pmd_pte(pmd))
10873dfcb315SAneesh Kumar K.V
1088f72a85e3SAneesh Kumar K.V #define pmd_access_permitted pmd_access_permitted
pmd_access_permitted(pmd_t pmd,bool write)1089f72a85e3SAneesh Kumar K.V static inline bool pmd_access_permitted(pmd_t pmd, bool write)
1090f72a85e3SAneesh Kumar K.V {
109133258a1dSNicholas Piggin /*
109233258a1dSNicholas Piggin * pmdp_invalidate sets this combination (which is not caught by
109333258a1dSNicholas Piggin * !pte_present() check in pte_access_permitted), to prevent
109433258a1dSNicholas Piggin * lock-free lookups, as part of the serialize_against_pte_lookup()
109533258a1dSNicholas Piggin * synchronisation.
109633258a1dSNicholas Piggin *
109733258a1dSNicholas Piggin * This also catches the case where the PTE's hardware PRESENT bit is
109833258a1dSNicholas Piggin * cleared while TLB is flushed, which is suboptimal but should not
109933258a1dSNicholas Piggin * be frequent.
110033258a1dSNicholas Piggin */
110133258a1dSNicholas Piggin if (pmd_is_serializing(pmd))
110233258a1dSNicholas Piggin return false;
110333258a1dSNicholas Piggin
1104f72a85e3SAneesh Kumar K.V return pte_access_permitted(pmd_pte(pmd), write);
1105f72a85e3SAneesh Kumar K.V }
1106f72a85e3SAneesh Kumar K.V
11076a1ea362SAneesh Kumar K.V #ifdef CONFIG_TRANSPARENT_HUGEPAGE
11086a1ea362SAneesh Kumar K.V extern pmd_t pfn_pmd(unsigned long pfn, pgprot_t pgprot);
110927af67f3SAneesh Kumar K.V extern pud_t pfn_pud(unsigned long pfn, pgprot_t pgprot);
11106a1ea362SAneesh Kumar K.V extern pmd_t mk_pmd(struct page *page, pgprot_t pgprot);
11116a1ea362SAneesh Kumar K.V extern pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot);
11126a1ea362SAneesh Kumar K.V extern void set_pmd_at(struct mm_struct *mm, unsigned long addr,
11136a1ea362SAneesh Kumar K.V pmd_t *pmdp, pmd_t pmd);
111427af67f3SAneesh Kumar K.V extern void set_pud_at(struct mm_struct *mm, unsigned long addr,
111527af67f3SAneesh Kumar K.V pud_t *pudp, pud_t pud);
111627af67f3SAneesh Kumar K.V
update_mmu_cache_pmd(struct vm_area_struct * vma,unsigned long addr,pmd_t * pmd)111718594f9bSNicholas Piggin static inline void update_mmu_cache_pmd(struct vm_area_struct *vma,
111818594f9bSNicholas Piggin unsigned long addr, pmd_t *pmd)
111918594f9bSNicholas Piggin {
112018594f9bSNicholas Piggin }
112118594f9bSNicholas Piggin
update_mmu_cache_pud(struct vm_area_struct * vma,unsigned long addr,pud_t * pud)112227af67f3SAneesh Kumar K.V static inline void update_mmu_cache_pud(struct vm_area_struct *vma,
112327af67f3SAneesh Kumar K.V unsigned long addr, pud_t *pud)
112427af67f3SAneesh Kumar K.V {
112527af67f3SAneesh Kumar K.V }
112627af67f3SAneesh Kumar K.V
11273df33f12SAneesh Kumar K.V extern int hash__has_transparent_hugepage(void);
has_transparent_hugepage(void)11283df33f12SAneesh Kumar K.V static inline int has_transparent_hugepage(void)
11293dfcb315SAneesh Kumar K.V {
1130bde3eb62SAneesh Kumar K.V if (radix_enabled())
1131bde3eb62SAneesh Kumar K.V return radix__has_transparent_hugepage();
11323df33f12SAneesh Kumar K.V return hash__has_transparent_hugepage();
11333df33f12SAneesh Kumar K.V }
1134c04a5880SLinus Torvalds #define has_transparent_hugepage has_transparent_hugepage
11353df33f12SAneesh Kumar K.V
has_transparent_pud_hugepage(void)113627af67f3SAneesh Kumar K.V static inline int has_transparent_pud_hugepage(void)
113727af67f3SAneesh Kumar K.V {
113827af67f3SAneesh Kumar K.V if (radix_enabled())
113927af67f3SAneesh Kumar K.V return radix__has_transparent_pud_hugepage();
114027af67f3SAneesh Kumar K.V return 0;
114127af67f3SAneesh Kumar K.V }
114227af67f3SAneesh Kumar K.V #define has_transparent_pud_hugepage has_transparent_pud_hugepage
114327af67f3SAneesh Kumar K.V
11443df33f12SAneesh Kumar K.V static inline unsigned long
pmd_hugepage_update(struct mm_struct * mm,unsigned long addr,pmd_t * pmdp,unsigned long clr,unsigned long set)11453df33f12SAneesh Kumar K.V pmd_hugepage_update(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp,
11463df33f12SAneesh Kumar K.V unsigned long clr, unsigned long set)
11473df33f12SAneesh Kumar K.V {
1148bde3eb62SAneesh Kumar K.V if (radix_enabled())
1149bde3eb62SAneesh Kumar K.V return radix__pmd_hugepage_update(mm, addr, pmdp, clr, set);
11503df33f12SAneesh Kumar K.V return hash__pmd_hugepage_update(mm, addr, pmdp, clr, set);
11513df33f12SAneesh Kumar K.V }
11523df33f12SAneesh Kumar K.V
115327af67f3SAneesh Kumar K.V static inline unsigned long
pud_hugepage_update(struct mm_struct * mm,unsigned long addr,pud_t * pudp,unsigned long clr,unsigned long set)115427af67f3SAneesh Kumar K.V pud_hugepage_update(struct mm_struct *mm, unsigned long addr, pud_t *pudp,
115527af67f3SAneesh Kumar K.V unsigned long clr, unsigned long set)
115627af67f3SAneesh Kumar K.V {
115727af67f3SAneesh Kumar K.V if (radix_enabled())
115827af67f3SAneesh Kumar K.V return radix__pud_hugepage_update(mm, addr, pudp, clr, set);
115927af67f3SAneesh Kumar K.V BUG();
116027af67f3SAneesh Kumar K.V return pud_val(*pudp);
116127af67f3SAneesh Kumar K.V }
116227af67f3SAneesh Kumar K.V
11638890e033SAneesh Kumar K.V /*
11648890e033SAneesh Kumar K.V * returns true for pmd migration entries, THP, devmap, hugetlb
11658890e033SAneesh Kumar K.V * But compile time dependent on THP config
11668890e033SAneesh Kumar K.V */
pmd_large(pmd_t pmd)11673df33f12SAneesh Kumar K.V static inline int pmd_large(pmd_t pmd)
11683df33f12SAneesh Kumar K.V {
116966c570f5SAneesh Kumar K.V return !!(pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE));
11703df33f12SAneesh Kumar K.V }
11713df33f12SAneesh Kumar K.V
pud_large(pud_t pud)117227af67f3SAneesh Kumar K.V static inline int pud_large(pud_t pud)
117327af67f3SAneesh Kumar K.V {
117427af67f3SAneesh Kumar K.V return !!(pud_raw(pud) & cpu_to_be64(_PAGE_PTE));
117527af67f3SAneesh Kumar K.V }
117627af67f3SAneesh Kumar K.V
11773df33f12SAneesh Kumar K.V /*
11783df33f12SAneesh Kumar K.V * For radix we should always find H_PAGE_HASHPTE zero. Hence
11793df33f12SAneesh Kumar K.V * the below will work for radix too
11803df33f12SAneesh Kumar K.V */
__pmdp_test_and_clear_young(struct mm_struct * mm,unsigned long addr,pmd_t * pmdp)11813df33f12SAneesh Kumar K.V static inline int __pmdp_test_and_clear_young(struct mm_struct *mm,
11823df33f12SAneesh Kumar K.V unsigned long addr, pmd_t *pmdp)
11833df33f12SAneesh Kumar K.V {
11843df33f12SAneesh Kumar K.V unsigned long old;
11853df33f12SAneesh Kumar K.V
118666c570f5SAneesh Kumar K.V if ((pmd_raw(*pmdp) & cpu_to_be64(_PAGE_ACCESSED | H_PAGE_HASHPTE)) == 0)
11873df33f12SAneesh Kumar K.V return 0;
11883df33f12SAneesh Kumar K.V old = pmd_hugepage_update(mm, addr, pmdp, _PAGE_ACCESSED, 0);
11893df33f12SAneesh Kumar K.V return ((old & _PAGE_ACCESSED) != 0);
11903df33f12SAneesh Kumar K.V }
11913df33f12SAneesh Kumar K.V
__pudp_test_and_clear_young(struct mm_struct * mm,unsigned long addr,pud_t * pudp)119227af67f3SAneesh Kumar K.V static inline int __pudp_test_and_clear_young(struct mm_struct *mm,
119327af67f3SAneesh Kumar K.V unsigned long addr, pud_t *pudp)
119427af67f3SAneesh Kumar K.V {
119527af67f3SAneesh Kumar K.V unsigned long old;
119627af67f3SAneesh Kumar K.V
119727af67f3SAneesh Kumar K.V if ((pud_raw(*pudp) & cpu_to_be64(_PAGE_ACCESSED | H_PAGE_HASHPTE)) == 0)
119827af67f3SAneesh Kumar K.V return 0;
119927af67f3SAneesh Kumar K.V old = pud_hugepage_update(mm, addr, pudp, _PAGE_ACCESSED, 0);
120027af67f3SAneesh Kumar K.V return ((old & _PAGE_ACCESSED) != 0);
120127af67f3SAneesh Kumar K.V }
120227af67f3SAneesh Kumar K.V
12033df33f12SAneesh Kumar K.V #define __HAVE_ARCH_PMDP_SET_WRPROTECT
pmdp_set_wrprotect(struct mm_struct * mm,unsigned long addr,pmd_t * pmdp)12043df33f12SAneesh Kumar K.V static inline void pmdp_set_wrprotect(struct mm_struct *mm, unsigned long addr,
12053df33f12SAneesh Kumar K.V pmd_t *pmdp)
12063df33f12SAneesh Kumar K.V {
1207d6379159SDavid Hildenbrand if (pmd_write(*pmdp))
12083df33f12SAneesh Kumar K.V pmd_hugepage_update(mm, addr, pmdp, _PAGE_WRITE, 0);
12093dfcb315SAneesh Kumar K.V }
12103dfcb315SAneesh Kumar K.V
121127af67f3SAneesh Kumar K.V #define __HAVE_ARCH_PUDP_SET_WRPROTECT
pudp_set_wrprotect(struct mm_struct * mm,unsigned long addr,pud_t * pudp)121227af67f3SAneesh Kumar K.V static inline void pudp_set_wrprotect(struct mm_struct *mm, unsigned long addr,
121327af67f3SAneesh Kumar K.V pud_t *pudp)
121427af67f3SAneesh Kumar K.V {
121527af67f3SAneesh Kumar K.V if (pud_write(*pudp))
121627af67f3SAneesh Kumar K.V pud_hugepage_update(mm, addr, pudp, _PAGE_WRITE, 0);
121727af67f3SAneesh Kumar K.V }
121827af67f3SAneesh Kumar K.V
12198890e033SAneesh Kumar K.V /*
12208890e033SAneesh Kumar K.V * Only returns true for a THP. False for pmd migration entry.
12218890e033SAneesh Kumar K.V * We also need to return true when we come across a pte that
12228890e033SAneesh Kumar K.V * in between a thp split. While splitting THP, we mark the pmd
12238890e033SAneesh Kumar K.V * invalid (pmdp_invalidate()) before we set it with pte page
12248890e033SAneesh Kumar K.V * address. A pmd_trans_huge() check against a pmd entry during that time
12258890e033SAneesh Kumar K.V * should return true.
12268890e033SAneesh Kumar K.V * We should not call this on a hugetlb entry. We should check for HugeTLB
12278890e033SAneesh Kumar K.V * entry using vma->vm_flags
1228ee65728eSMike Rapoport * The page table walk rule is explained in Documentation/mm/transhuge.rst
12298890e033SAneesh Kumar K.V */
pmd_trans_huge(pmd_t pmd)1230ab624762SAneesh Kumar K.V static inline int pmd_trans_huge(pmd_t pmd)
1231ab624762SAneesh Kumar K.V {
12328890e033SAneesh Kumar K.V if (!pmd_present(pmd))
12338890e033SAneesh Kumar K.V return false;
12348890e033SAneesh Kumar K.V
1235ab624762SAneesh Kumar K.V if (radix_enabled())
1236ab624762SAneesh Kumar K.V return radix__pmd_trans_huge(pmd);
1237ab624762SAneesh Kumar K.V return hash__pmd_trans_huge(pmd);
1238ab624762SAneesh Kumar K.V }
1239ab624762SAneesh Kumar K.V
pud_trans_huge(pud_t pud)124027af67f3SAneesh Kumar K.V static inline int pud_trans_huge(pud_t pud)
124127af67f3SAneesh Kumar K.V {
124227af67f3SAneesh Kumar K.V if (!pud_present(pud))
124327af67f3SAneesh Kumar K.V return false;
124427af67f3SAneesh Kumar K.V
124527af67f3SAneesh Kumar K.V if (radix_enabled())
124627af67f3SAneesh Kumar K.V return radix__pud_trans_huge(pud);
124727af67f3SAneesh Kumar K.V return 0;
124827af67f3SAneesh Kumar K.V }
124927af67f3SAneesh Kumar K.V
125027af67f3SAneesh Kumar K.V
1251ab624762SAneesh Kumar K.V #define __HAVE_ARCH_PMD_SAME
pmd_same(pmd_t pmd_a,pmd_t pmd_b)1252ab624762SAneesh Kumar K.V static inline int pmd_same(pmd_t pmd_a, pmd_t pmd_b)
1253ab624762SAneesh Kumar K.V {
1254ab624762SAneesh Kumar K.V if (radix_enabled())
1255ab624762SAneesh Kumar K.V return radix__pmd_same(pmd_a, pmd_b);
1256ab624762SAneesh Kumar K.V return hash__pmd_same(pmd_a, pmd_b);
1257ab624762SAneesh Kumar K.V }
1258ab624762SAneesh Kumar K.V
125927af67f3SAneesh Kumar K.V #define pud_same pud_same
pud_same(pud_t pud_a,pud_t pud_b)126027af67f3SAneesh Kumar K.V static inline int pud_same(pud_t pud_a, pud_t pud_b)
126127af67f3SAneesh Kumar K.V {
126227af67f3SAneesh Kumar K.V if (radix_enabled())
126327af67f3SAneesh Kumar K.V return radix__pud_same(pud_a, pud_b);
126427af67f3SAneesh Kumar K.V return hash__pud_same(pud_a, pud_b);
126527af67f3SAneesh Kumar K.V }
126627af67f3SAneesh Kumar K.V
126727af67f3SAneesh Kumar K.V
__pmd_mkhuge(pmd_t pmd)126853f45eccSAneesh Kumar K.V static inline pmd_t __pmd_mkhuge(pmd_t pmd)
12693dfcb315SAneesh Kumar K.V {
1270ab624762SAneesh Kumar K.V if (radix_enabled())
1271ab624762SAneesh Kumar K.V return radix__pmd_mkhuge(pmd);
1272ab624762SAneesh Kumar K.V return hash__pmd_mkhuge(pmd);
12733dfcb315SAneesh Kumar K.V }
12743dfcb315SAneesh Kumar K.V
__pud_mkhuge(pud_t pud)127527af67f3SAneesh Kumar K.V static inline pud_t __pud_mkhuge(pud_t pud)
127627af67f3SAneesh Kumar K.V {
127727af67f3SAneesh Kumar K.V if (radix_enabled())
127827af67f3SAneesh Kumar K.V return radix__pud_mkhuge(pud);
127927af67f3SAneesh Kumar K.V BUG();
128027af67f3SAneesh Kumar K.V return pud;
128127af67f3SAneesh Kumar K.V }
128227af67f3SAneesh Kumar K.V
128353f45eccSAneesh Kumar K.V /*
128453f45eccSAneesh Kumar K.V * pfn_pmd return a pmd_t that can be used as pmd pte entry.
128553f45eccSAneesh Kumar K.V */
pmd_mkhuge(pmd_t pmd)128653f45eccSAneesh Kumar K.V static inline pmd_t pmd_mkhuge(pmd_t pmd)
128753f45eccSAneesh Kumar K.V {
128853f45eccSAneesh Kumar K.V #ifdef CONFIG_DEBUG_VM
128953f45eccSAneesh Kumar K.V if (radix_enabled())
129053f45eccSAneesh Kumar K.V WARN_ON((pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE)) == 0);
129153f45eccSAneesh Kumar K.V else
129253f45eccSAneesh Kumar K.V WARN_ON((pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE | H_PAGE_THP_HUGE)) !=
129353f45eccSAneesh Kumar K.V cpu_to_be64(_PAGE_PTE | H_PAGE_THP_HUGE));
129453f45eccSAneesh Kumar K.V #endif
129553f45eccSAneesh Kumar K.V return pmd;
129653f45eccSAneesh Kumar K.V }
129753f45eccSAneesh Kumar K.V
pud_mkhuge(pud_t pud)129827af67f3SAneesh Kumar K.V static inline pud_t pud_mkhuge(pud_t pud)
129927af67f3SAneesh Kumar K.V {
130027af67f3SAneesh Kumar K.V #ifdef CONFIG_DEBUG_VM
130127af67f3SAneesh Kumar K.V if (radix_enabled())
130227af67f3SAneesh Kumar K.V WARN_ON((pud_raw(pud) & cpu_to_be64(_PAGE_PTE)) == 0);
130327af67f3SAneesh Kumar K.V else
130427af67f3SAneesh Kumar K.V WARN_ON(1);
130527af67f3SAneesh Kumar K.V #endif
130627af67f3SAneesh Kumar K.V return pud;
130727af67f3SAneesh Kumar K.V }
130827af67f3SAneesh Kumar K.V
130927af67f3SAneesh Kumar K.V
13103dfcb315SAneesh Kumar K.V #define __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS
13113dfcb315SAneesh Kumar K.V extern int pmdp_set_access_flags(struct vm_area_struct *vma,
13123dfcb315SAneesh Kumar K.V unsigned long address, pmd_t *pmdp,
13133dfcb315SAneesh Kumar K.V pmd_t entry, int dirty);
131427af67f3SAneesh Kumar K.V #define __HAVE_ARCH_PUDP_SET_ACCESS_FLAGS
131527af67f3SAneesh Kumar K.V extern int pudp_set_access_flags(struct vm_area_struct *vma,
131627af67f3SAneesh Kumar K.V unsigned long address, pud_t *pudp,
131727af67f3SAneesh Kumar K.V pud_t entry, int dirty);
13183dfcb315SAneesh Kumar K.V
13193dfcb315SAneesh Kumar K.V #define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
13203dfcb315SAneesh Kumar K.V extern int pmdp_test_and_clear_young(struct vm_area_struct *vma,
13213dfcb315SAneesh Kumar K.V unsigned long address, pmd_t *pmdp);
132227af67f3SAneesh Kumar K.V #define __HAVE_ARCH_PUDP_TEST_AND_CLEAR_YOUNG
132327af67f3SAneesh Kumar K.V extern int pudp_test_and_clear_young(struct vm_area_struct *vma,
132427af67f3SAneesh Kumar K.V unsigned long address, pud_t *pudp);
132527af67f3SAneesh Kumar K.V
13263dfcb315SAneesh Kumar K.V
13273dfcb315SAneesh Kumar K.V #define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR
pmdp_huge_get_and_clear(struct mm_struct * mm,unsigned long addr,pmd_t * pmdp)13283df33f12SAneesh Kumar K.V static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
13293df33f12SAneesh Kumar K.V unsigned long addr, pmd_t *pmdp)
13303df33f12SAneesh Kumar K.V {
1331bde3eb62SAneesh Kumar K.V if (radix_enabled())
1332bde3eb62SAneesh Kumar K.V return radix__pmdp_huge_get_and_clear(mm, addr, pmdp);
13333df33f12SAneesh Kumar K.V return hash__pmdp_huge_get_and_clear(mm, addr, pmdp);
13343df33f12SAneesh Kumar K.V }
13353dfcb315SAneesh Kumar K.V
133627af67f3SAneesh Kumar K.V #define __HAVE_ARCH_PUDP_HUGE_GET_AND_CLEAR
pudp_huge_get_and_clear(struct mm_struct * mm,unsigned long addr,pud_t * pudp)133727af67f3SAneesh Kumar K.V static inline pud_t pudp_huge_get_and_clear(struct mm_struct *mm,
133827af67f3SAneesh Kumar K.V unsigned long addr, pud_t *pudp)
133927af67f3SAneesh Kumar K.V {
134027af67f3SAneesh Kumar K.V if (radix_enabled())
134127af67f3SAneesh Kumar K.V return radix__pudp_huge_get_and_clear(mm, addr, pudp);
134227af67f3SAneesh Kumar K.V BUG();
134327af67f3SAneesh Kumar K.V return *pudp;
134427af67f3SAneesh Kumar K.V }
134527af67f3SAneesh Kumar K.V
pmdp_collapse_flush(struct vm_area_struct * vma,unsigned long address,pmd_t * pmdp)13463df33f12SAneesh Kumar K.V static inline pmd_t pmdp_collapse_flush(struct vm_area_struct *vma,
13473df33f12SAneesh Kumar K.V unsigned long address, pmd_t *pmdp)
13483df33f12SAneesh Kumar K.V {
1349bde3eb62SAneesh Kumar K.V if (radix_enabled())
1350bde3eb62SAneesh Kumar K.V return radix__pmdp_collapse_flush(vma, address, pmdp);
13513df33f12SAneesh Kumar K.V return hash__pmdp_collapse_flush(vma, address, pmdp);
13523df33f12SAneesh Kumar K.V }
13533dfcb315SAneesh Kumar K.V #define pmdp_collapse_flush pmdp_collapse_flush
13543dfcb315SAneesh Kumar K.V
135575358ea3SAneesh Kumar K.V #define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR_FULL
135675358ea3SAneesh Kumar K.V pmd_t pmdp_huge_get_and_clear_full(struct vm_area_struct *vma,
135775358ea3SAneesh Kumar K.V unsigned long addr,
135875358ea3SAneesh Kumar K.V pmd_t *pmdp, int full);
135975358ea3SAneesh Kumar K.V
136027af67f3SAneesh Kumar K.V #define __HAVE_ARCH_PUDP_HUGE_GET_AND_CLEAR_FULL
136127af67f3SAneesh Kumar K.V pud_t pudp_huge_get_and_clear_full(struct vm_area_struct *vma,
136227af67f3SAneesh Kumar K.V unsigned long addr,
136327af67f3SAneesh Kumar K.V pud_t *pudp, int full);
136427af67f3SAneesh Kumar K.V
13653dfcb315SAneesh Kumar K.V #define __HAVE_ARCH_PGTABLE_DEPOSIT
pgtable_trans_huge_deposit(struct mm_struct * mm,pmd_t * pmdp,pgtable_t pgtable)13663df33f12SAneesh Kumar K.V static inline void pgtable_trans_huge_deposit(struct mm_struct *mm,
13673df33f12SAneesh Kumar K.V pmd_t *pmdp, pgtable_t pgtable)
13683df33f12SAneesh Kumar K.V {
1369bde3eb62SAneesh Kumar K.V if (radix_enabled())
1370bde3eb62SAneesh Kumar K.V return radix__pgtable_trans_huge_deposit(mm, pmdp, pgtable);
13713df33f12SAneesh Kumar K.V return hash__pgtable_trans_huge_deposit(mm, pmdp, pgtable);
13723df33f12SAneesh Kumar K.V }
13733df33f12SAneesh Kumar K.V
13743dfcb315SAneesh Kumar K.V #define __HAVE_ARCH_PGTABLE_WITHDRAW
pgtable_trans_huge_withdraw(struct mm_struct * mm,pmd_t * pmdp)13753df33f12SAneesh Kumar K.V static inline pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm,
13763df33f12SAneesh Kumar K.V pmd_t *pmdp)
13773df33f12SAneesh Kumar K.V {
1378bde3eb62SAneesh Kumar K.V if (radix_enabled())
1379bde3eb62SAneesh Kumar K.V return radix__pgtable_trans_huge_withdraw(mm, pmdp);
13803df33f12SAneesh Kumar K.V return hash__pgtable_trans_huge_withdraw(mm, pmdp);
13813df33f12SAneesh Kumar K.V }
13823dfcb315SAneesh Kumar K.V
13833dfcb315SAneesh Kumar K.V #define __HAVE_ARCH_PMDP_INVALIDATE
13848cc931e0SAneesh Kumar K.V extern pmd_t pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
13853dfcb315SAneesh Kumar K.V pmd_t *pmdp);
13863dfcb315SAneesh Kumar K.V
13873dfcb315SAneesh Kumar K.V #define pmd_move_must_withdraw pmd_move_must_withdraw
13883dfcb315SAneesh Kumar K.V struct spinlock;
1389579b9239SAneesh Kumar K.V extern int pmd_move_must_withdraw(struct spinlock *new_pmd_ptl,
13901dd38b6cSAneesh Kumar K.V struct spinlock *old_pmd_ptl,
1391579b9239SAneesh Kumar K.V struct vm_area_struct *vma);
13923dfcb315SAneesh Kumar K.V /*
1393579b9239SAneesh Kumar K.V * Hash translation mode use the deposited table to store hash pte
1394579b9239SAneesh Kumar K.V * slot information.
13953dfcb315SAneesh Kumar K.V */
1396953c66c2SAneesh Kumar K.V #define arch_needs_pgtable_deposit arch_needs_pgtable_deposit
arch_needs_pgtable_deposit(void)1397953c66c2SAneesh Kumar K.V static inline bool arch_needs_pgtable_deposit(void)
1398953c66c2SAneesh Kumar K.V {
1399953c66c2SAneesh Kumar K.V if (radix_enabled())
1400953c66c2SAneesh Kumar K.V return false;
1401953c66c2SAneesh Kumar K.V return true;
1402953c66c2SAneesh Kumar K.V }
1403fa4531f7SAneesh Kumar K.V extern void serialize_against_pte_lookup(struct mm_struct *mm);
1404953c66c2SAneesh Kumar K.V
1405ebd31197SOliver O'Halloran
pmd_mkdevmap(pmd_t pmd)1406ebd31197SOliver O'Halloran static inline pmd_t pmd_mkdevmap(pmd_t pmd)
1407ebd31197SOliver O'Halloran {
140836b78402SAneesh Kumar K.V if (radix_enabled())
140936b78402SAneesh Kumar K.V return radix__pmd_mkdevmap(pmd);
141036b78402SAneesh Kumar K.V return hash__pmd_mkdevmap(pmd);
1411ebd31197SOliver O'Halloran }
1412ebd31197SOliver O'Halloran
pud_mkdevmap(pud_t pud)141327af67f3SAneesh Kumar K.V static inline pud_t pud_mkdevmap(pud_t pud)
141427af67f3SAneesh Kumar K.V {
141527af67f3SAneesh Kumar K.V if (radix_enabled())
141627af67f3SAneesh Kumar K.V return radix__pud_mkdevmap(pud);
141727af67f3SAneesh Kumar K.V BUG();
141827af67f3SAneesh Kumar K.V return pud;
141927af67f3SAneesh Kumar K.V }
142027af67f3SAneesh Kumar K.V
pmd_devmap(pmd_t pmd)1421ebd31197SOliver O'Halloran static inline int pmd_devmap(pmd_t pmd)
1422ebd31197SOliver O'Halloran {
1423ebd31197SOliver O'Halloran return pte_devmap(pmd_pte(pmd));
1424ebd31197SOliver O'Halloran }
1425ebd31197SOliver O'Halloran
pud_devmap(pud_t pud)1426ebd31197SOliver O'Halloran static inline int pud_devmap(pud_t pud)
1427ebd31197SOliver O'Halloran {
142827af67f3SAneesh Kumar K.V return pte_devmap(pud_pte(pud));
1429ebd31197SOliver O'Halloran }
1430ebd31197SOliver O'Halloran
pgd_devmap(pgd_t pgd)1431ebd31197SOliver O'Halloran static inline int pgd_devmap(pgd_t pgd)
1432ebd31197SOliver O'Halloran {
1433ebd31197SOliver O'Halloran return 0;
1434ebd31197SOliver O'Halloran }
14356a1ea362SAneesh Kumar K.V #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
1436ebd31197SOliver O'Halloran
14375b323367SAneesh Kumar K.V #define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
14385b323367SAneesh Kumar K.V pte_t ptep_modify_prot_start(struct vm_area_struct *, unsigned long, pte_t *);
14395b323367SAneesh Kumar K.V void ptep_modify_prot_commit(struct vm_area_struct *, unsigned long,
14405b323367SAneesh Kumar K.V pte_t *, pte_t, pte_t);
14415b323367SAneesh Kumar K.V
14425b323367SAneesh Kumar K.V /*
14435b323367SAneesh Kumar K.V * Returns true for a R -> RW upgrade of pte
14445b323367SAneesh Kumar K.V */
is_pte_rw_upgrade(unsigned long old_val,unsigned long new_val)14455b323367SAneesh Kumar K.V static inline bool is_pte_rw_upgrade(unsigned long old_val, unsigned long new_val)
14465b323367SAneesh Kumar K.V {
14475b323367SAneesh Kumar K.V if (!(old_val & _PAGE_READ))
14485b323367SAneesh Kumar K.V return false;
14495b323367SAneesh Kumar K.V
14505b323367SAneesh Kumar K.V if ((!(old_val & _PAGE_WRITE)) && (new_val & _PAGE_WRITE))
14515b323367SAneesh Kumar K.V return true;
14525b323367SAneesh Kumar K.V
14535b323367SAneesh Kumar K.V return false;
14545b323367SAneesh Kumar K.V }
1455029d9252SMichael Ellerman
1456d6eaceddSAneesh Kumar K.V /*
1457d6eaceddSAneesh Kumar K.V * Like pmd_huge() and pmd_large(), but works regardless of config options
1458d6eaceddSAneesh Kumar K.V */
1459d6eaceddSAneesh Kumar K.V #define pmd_is_leaf pmd_is_leaf
1460070434b1SSteven Price #define pmd_leaf pmd_is_leaf
pmd_is_leaf(pmd_t pmd)1461d6eaceddSAneesh Kumar K.V static inline bool pmd_is_leaf(pmd_t pmd)
1462d6eaceddSAneesh Kumar K.V {
1463d6eaceddSAneesh Kumar K.V return !!(pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE));
1464d6eaceddSAneesh Kumar K.V }
1465d6eaceddSAneesh Kumar K.V
1466d6eaceddSAneesh Kumar K.V #define pud_is_leaf pud_is_leaf
1467070434b1SSteven Price #define pud_leaf pud_is_leaf
pud_is_leaf(pud_t pud)1468d6eaceddSAneesh Kumar K.V static inline bool pud_is_leaf(pud_t pud)
1469d6eaceddSAneesh Kumar K.V {
1470d6eaceddSAneesh Kumar K.V return !!(pud_raw(pud) & cpu_to_be64(_PAGE_PTE));
1471d6eaceddSAneesh Kumar K.V }
1472d6eaceddSAneesh Kumar K.V
14733dfcb315SAneesh Kumar K.V #endif /* __ASSEMBLY__ */
14743dfcb315SAneesh Kumar K.V #endif /* _ASM_POWERPC_BOOK3S_64_PGTABLE_H_ */
1475