xref: /openbmc/linux/arch/powerpc/include/asm/book3s/32/pgtable.h (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
23dfcb315SAneesh Kumar K.V #ifndef _ASM_POWERPC_BOOK3S_32_PGTABLE_H
33dfcb315SAneesh Kumar K.V #define _ASM_POWERPC_BOOK3S_32_PGTABLE_H
43dfcb315SAneesh Kumar K.V 
53dfcb315SAneesh Kumar K.V #include <asm-generic/pgtable-nopmd.h>
63dfcb315SAneesh Kumar K.V 
7ca8cc369SChristophe Leroy /*
8ca8cc369SChristophe Leroy  * The "classic" 32-bit implementation of the PowerPC MMU uses a hash
9ca8cc369SChristophe Leroy  * table containing PTEs, together with a set of 16 segment registers,
10ca8cc369SChristophe Leroy  * to define the virtual to physical address mapping.
11ca8cc369SChristophe Leroy  *
12ca8cc369SChristophe Leroy  * We use the hash table as an extended TLB, i.e. a cache of currently
13ca8cc369SChristophe Leroy  * active mappings.  We maintain a two-level page table tree, much
14ca8cc369SChristophe Leroy  * like that used by the i386, for the sake of the Linux memory
15ca8cc369SChristophe Leroy  * management code.  Low-level assembler code in hash_low_32.S
16ca8cc369SChristophe Leroy  * (procedure hash_page) is responsible for extracting ptes from the
17ca8cc369SChristophe Leroy  * tree and putting them into the hash table when necessary, and
18ca8cc369SChristophe Leroy  * updating the accessed and modified bits in the page table tree.
19ca8cc369SChristophe Leroy  */
20ca8cc369SChristophe Leroy 
21ca8cc369SChristophe Leroy #define _PAGE_PRESENT	0x001	/* software: pte contains a translation */
22ca8cc369SChristophe Leroy #define _PAGE_HASHPTE	0x002	/* hash_page has made an HPTE for this pte */
23ca8cc369SChristophe Leroy #define _PAGE_USER	0x004	/* usermode access allowed */
24ca8cc369SChristophe Leroy #define _PAGE_GUARDED	0x008	/* G: prohibit speculative access */
25ca8cc369SChristophe Leroy #define _PAGE_COHERENT	0x010	/* M: enforce memory coherence (SMP systems) */
26ca8cc369SChristophe Leroy #define _PAGE_NO_CACHE	0x020	/* I: cache inhibit */
27ca8cc369SChristophe Leroy #define _PAGE_WRITETHRU	0x040	/* W: cache write-through */
28ca8cc369SChristophe Leroy #define _PAGE_DIRTY	0x080	/* C: page changed */
29ca8cc369SChristophe Leroy #define _PAGE_ACCESSED	0x100	/* R: page referenced */
30ca8cc369SChristophe Leroy #define _PAGE_EXEC	0x200	/* software: exec allowed */
31ca8cc369SChristophe Leroy #define _PAGE_RW	0x400	/* software: user write access allowed */
32ca8cc369SChristophe Leroy #define _PAGE_SPECIAL	0x800	/* software: Special page */
33ca8cc369SChristophe Leroy 
34ca8cc369SChristophe Leroy #ifdef CONFIG_PTE_64BIT
35ca8cc369SChristophe Leroy /* We never clear the high word of the pte */
36ca8cc369SChristophe Leroy #define _PTE_NONE_MASK	(0xffffffff00000000ULL | _PAGE_HASHPTE)
37ca8cc369SChristophe Leroy #else
38ca8cc369SChristophe Leroy #define _PTE_NONE_MASK	_PAGE_HASHPTE
39ca8cc369SChristophe Leroy #endif
40ca8cc369SChristophe Leroy 
41ca8cc369SChristophe Leroy #define _PMD_PRESENT	0
42ca8cc369SChristophe Leroy #define _PMD_PRESENT_MASK (PAGE_MASK)
43ca8cc369SChristophe Leroy #define _PMD_BAD	(~PAGE_MASK)
443dfcb315SAneesh Kumar K.V 
458897ebffSDavid Hildenbrand /* We borrow the _PAGE_USER bit to store the exclusive marker in swap PTEs. */
468897ebffSDavid Hildenbrand #define _PAGE_SWP_EXCLUSIVE	_PAGE_USER
478897ebffSDavid Hildenbrand 
48cbbb8683SAneesh Kumar K.V /* And here we include common definitions */
49b2133bd7SChristophe Leroy 
50b2133bd7SChristophe Leroy #define _PAGE_KERNEL_RO		0
51385e89d5SChristophe Leroy #define _PAGE_KERNEL_ROX	(_PAGE_EXEC)
52b2133bd7SChristophe Leroy #define _PAGE_KERNEL_RW		(_PAGE_DIRTY | _PAGE_RW)
53385e89d5SChristophe Leroy #define _PAGE_KERNEL_RWX	(_PAGE_DIRTY | _PAGE_RW | _PAGE_EXEC)
54b2133bd7SChristophe Leroy 
55b2133bd7SChristophe Leroy #define _PAGE_HPTEFLAGS _PAGE_HASHPTE
56b2133bd7SChristophe Leroy 
57b2133bd7SChristophe Leroy #ifndef __ASSEMBLY__
58b2133bd7SChristophe Leroy 
pte_user(pte_t pte)59b2133bd7SChristophe Leroy static inline bool pte_user(pte_t pte)
60b2133bd7SChristophe Leroy {
61b2133bd7SChristophe Leroy 	return pte_val(pte) & _PAGE_USER;
62b2133bd7SChristophe Leroy }
63b2133bd7SChristophe Leroy #endif /* __ASSEMBLY__ */
64b2133bd7SChristophe Leroy 
65b2133bd7SChristophe Leroy /*
66b2133bd7SChristophe Leroy  * Location of the PFN in the PTE. Most 32-bit platforms use the same
67b2133bd7SChristophe Leroy  * as _PAGE_SHIFT here (ie, naturally aligned).
68b2133bd7SChristophe Leroy  * Platform who don't just pre-define the value so we don't override it here.
69b2133bd7SChristophe Leroy  */
70b2133bd7SChristophe Leroy #define PTE_RPN_SHIFT	(PAGE_SHIFT)
71b2133bd7SChristophe Leroy 
72b2133bd7SChristophe Leroy /*
73b2133bd7SChristophe Leroy  * The mask covered by the RPN must be a ULL on 32-bit platforms with
74b2133bd7SChristophe Leroy  * 64-bit PTEs.
75b2133bd7SChristophe Leroy  */
76b2133bd7SChristophe Leroy #ifdef CONFIG_PTE_64BIT
77b2133bd7SChristophe Leroy #define PTE_RPN_MASK	(~((1ULL << PTE_RPN_SHIFT) - 1))
78cef39703SArnd Bergmann #define MAX_POSSIBLE_PHYSMEM_BITS 36
79b2133bd7SChristophe Leroy #else
80b2133bd7SChristophe Leroy #define PTE_RPN_MASK	(~((1UL << PTE_RPN_SHIFT) - 1))
81cef39703SArnd Bergmann #define MAX_POSSIBLE_PHYSMEM_BITS 32
82b2133bd7SChristophe Leroy #endif
83b2133bd7SChristophe Leroy 
84b2133bd7SChristophe Leroy /*
85b2133bd7SChristophe Leroy  * _PAGE_CHG_MASK masks of bits that are to be preserved across
86b2133bd7SChristophe Leroy  * pgprot changes.
87b2133bd7SChristophe Leroy  */
88b2133bd7SChristophe Leroy #define _PAGE_CHG_MASK	(PTE_RPN_MASK | _PAGE_HASHPTE | _PAGE_DIRTY | \
89b2133bd7SChristophe Leroy 			 _PAGE_ACCESSED | _PAGE_SPECIAL)
90b2133bd7SChristophe Leroy 
91b2133bd7SChristophe Leroy /*
92b2133bd7SChristophe Leroy  * We define 2 sets of base prot bits, one for basic pages (ie,
93b2133bd7SChristophe Leroy  * cacheable kernel and user pages) and one for non cacheable
94b2133bd7SChristophe Leroy  * pages. We always set _PAGE_COHERENT when SMP is enabled or
95b2133bd7SChristophe Leroy  * the processor might need it for DMA coherency.
96b2133bd7SChristophe Leroy  */
97b2133bd7SChristophe Leroy #define _PAGE_BASE_NC	(_PAGE_PRESENT | _PAGE_ACCESSED)
98b2133bd7SChristophe Leroy #define _PAGE_BASE	(_PAGE_BASE_NC | _PAGE_COHERENT)
99b2133bd7SChristophe Leroy 
100b2133bd7SChristophe Leroy /*
101b2133bd7SChristophe Leroy  * Permission masks used to generate the __P and __S table.
102b2133bd7SChristophe Leroy  *
103b2133bd7SChristophe Leroy  * Note:__pgprot is defined in arch/powerpc/include/asm/page.h
104b2133bd7SChristophe Leroy  *
105b2133bd7SChristophe Leroy  * Write permissions imply read permissions for now.
106b2133bd7SChristophe Leroy  */
107b2133bd7SChristophe Leroy #define PAGE_NONE	__pgprot(_PAGE_BASE)
108b2133bd7SChristophe Leroy #define PAGE_SHARED	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW)
109385e89d5SChristophe Leroy #define PAGE_SHARED_X	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | _PAGE_EXEC)
110b2133bd7SChristophe Leroy #define PAGE_COPY	__pgprot(_PAGE_BASE | _PAGE_USER)
111385e89d5SChristophe Leroy #define PAGE_COPY_X	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
112b2133bd7SChristophe Leroy #define PAGE_READONLY	__pgprot(_PAGE_BASE | _PAGE_USER)
113385e89d5SChristophe Leroy #define PAGE_READONLY_X	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
114b2133bd7SChristophe Leroy 
115b2133bd7SChristophe Leroy /* Permission masks used for kernel mappings */
116b2133bd7SChristophe Leroy #define PAGE_KERNEL	__pgprot(_PAGE_BASE | _PAGE_KERNEL_RW)
117b2133bd7SChristophe Leroy #define PAGE_KERNEL_NC	__pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | _PAGE_NO_CACHE)
1186cc07821SChristophe Leroy #define PAGE_KERNEL_NCG	__pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | _PAGE_NO_CACHE | _PAGE_GUARDED)
119b2133bd7SChristophe Leroy #define PAGE_KERNEL_X	__pgprot(_PAGE_BASE | _PAGE_KERNEL_RWX)
120b2133bd7SChristophe Leroy #define PAGE_KERNEL_RO	__pgprot(_PAGE_BASE | _PAGE_KERNEL_RO)
121b2133bd7SChristophe Leroy #define PAGE_KERNEL_ROX	__pgprot(_PAGE_BASE | _PAGE_KERNEL_ROX)
122b2133bd7SChristophe Leroy 
1239b081e10SChristophe Leroy #define PTE_INDEX_SIZE	PTE_SHIFT
1249b081e10SChristophe Leroy #define PMD_INDEX_SIZE	0
1259b081e10SChristophe Leroy #define PUD_INDEX_SIZE	0
1269b081e10SChristophe Leroy #define PGD_INDEX_SIZE	(32 - PGDIR_SHIFT)
1279b081e10SChristophe Leroy 
1289b081e10SChristophe Leroy #define PMD_CACHE_INDEX	PMD_INDEX_SIZE
129fae22116SAneesh Kumar K.V #define PUD_CACHE_INDEX	PUD_INDEX_SIZE
1309b081e10SChristophe Leroy 
1319b081e10SChristophe Leroy #ifndef __ASSEMBLY__
1329b081e10SChristophe Leroy #define PTE_TABLE_SIZE	(sizeof(pte_t) << PTE_INDEX_SIZE)
1339b081e10SChristophe Leroy #define PMD_TABLE_SIZE	0
1349b081e10SChristophe Leroy #define PUD_TABLE_SIZE	0
1359b081e10SChristophe Leroy #define PGD_TABLE_SIZE	(sizeof(pgd_t) << PGD_INDEX_SIZE)
136974b9b2cSMike Rapoport 
137974b9b2cSMike Rapoport /* Bits to mask out from a PMD to get to the PTE page */
138974b9b2cSMike Rapoport #define PMD_MASKED_BITS		(PTE_TABLE_SIZE - 1)
1399b081e10SChristophe Leroy #endif	/* __ASSEMBLY__ */
1409b081e10SChristophe Leroy 
1419b081e10SChristophe Leroy #define PTRS_PER_PTE	(1 << PTE_INDEX_SIZE)
1429b081e10SChristophe Leroy #define PTRS_PER_PGD	(1 << PGD_INDEX_SIZE)
1439b081e10SChristophe Leroy 
1443dfcb315SAneesh Kumar K.V /*
1453dfcb315SAneesh Kumar K.V  * The normal case is that PTEs are 32-bits and we have a 1-page
1463dfcb315SAneesh Kumar K.V  * 1024-entry pgdir pointing to 1-page 1024-entry PTE pages.  -- paulus
1473dfcb315SAneesh Kumar K.V  *
1483dfcb315SAneesh Kumar K.V  * For any >32-bit physical address platform, we can use the following
1493dfcb315SAneesh Kumar K.V  * two level page table layout where the pgdir is 8KB and the MS 13 bits
1503dfcb315SAneesh Kumar K.V  * are an index to the second level table.  The combined pgdir/pmd first
1513dfcb315SAneesh Kumar K.V  * level has 2048 entries and the second level has 512 64-bit PTE entries.
1523dfcb315SAneesh Kumar K.V  * -Matt
1533dfcb315SAneesh Kumar K.V  */
1543dfcb315SAneesh Kumar K.V /* PGDIR_SHIFT determines what a top-level page table entry can map */
1559b081e10SChristophe Leroy #define PGDIR_SHIFT	(PAGE_SHIFT + PTE_INDEX_SIZE)
1563dfcb315SAneesh Kumar K.V #define PGDIR_SIZE	(1UL << PGDIR_SHIFT)
1573dfcb315SAneesh Kumar K.V #define PGDIR_MASK	(~(PGDIR_SIZE-1))
1583dfcb315SAneesh Kumar K.V 
1593dfcb315SAneesh Kumar K.V #define USER_PTRS_PER_PGD	(TASK_SIZE / PGDIR_SIZE)
160a67beca0SChristophe Leroy 
161a67beca0SChristophe Leroy #ifndef __ASSEMBLY__
162a67beca0SChristophe Leroy 
163a67beca0SChristophe Leroy int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot);
164aec98260SChristophe Leroy void unmap_kernel_page(unsigned long va);
165a67beca0SChristophe Leroy 
166a67beca0SChristophe Leroy #endif /* !__ASSEMBLY__ */
167a67beca0SChristophe Leroy 
1683dfcb315SAneesh Kumar K.V /*
1693dfcb315SAneesh Kumar K.V  * This is the bottom of the PKMAP area with HIGHMEM or an arbitrary
1703dfcb315SAneesh Kumar K.V  * value (for now) on others, from where we can start layout kernel
1713dfcb315SAneesh Kumar K.V  * virtual space that goes below PKMAP and FIXMAP
1723dfcb315SAneesh Kumar K.V  */
173a67beca0SChristophe Leroy #include <asm/fixmap.h>
174a67beca0SChristophe Leroy 
1753dfcb315SAneesh Kumar K.V /*
1763dfcb315SAneesh Kumar K.V  * ioremap_bot starts at that address. Early ioremaps move down from there,
1773dfcb315SAneesh Kumar K.V  * until mem_init() at which point this becomes the top of the vmalloc
1783dfcb315SAneesh Kumar K.V  * and ioremap space
1793dfcb315SAneesh Kumar K.V  */
180f2902a2fSChristoph Hellwig #ifdef CONFIG_HIGHMEM
181f2902a2fSChristoph Hellwig #define IOREMAP_TOP	PKMAP_BASE
1823dfcb315SAneesh Kumar K.V #else
183f2902a2fSChristoph Hellwig #define IOREMAP_TOP	FIXADDR_START
1843dfcb315SAneesh Kumar K.V #endif
1853dfcb315SAneesh Kumar K.V 
1864a45b746SChristophe Leroy /* PPC32 shares vmalloc area with ioremap */
1874a45b746SChristophe Leroy #define IOREMAP_START	VMALLOC_START
1884a45b746SChristophe Leroy #define IOREMAP_END	VMALLOC_END
1894a45b746SChristophe Leroy 
1903dfcb315SAneesh Kumar K.V /*
1913dfcb315SAneesh Kumar K.V  * Just any arbitrary offset to the start of the vmalloc VM area: the
1923dfcb315SAneesh Kumar K.V  * current 16MB value just means that there will be a 64MB "hole" after the
1933dfcb315SAneesh Kumar K.V  * physical memory until the kernel virtual memory starts.  That means that
1943dfcb315SAneesh Kumar K.V  * any out-of-bounds memory accesses will hopefully be caught.
1953dfcb315SAneesh Kumar K.V  * The vmalloc() routines leaves a hole of 4kB between each vmalloced
1963dfcb315SAneesh Kumar K.V  * area for the same reason. ;)
1973dfcb315SAneesh Kumar K.V  *
1983dfcb315SAneesh Kumar K.V  * We no longer map larger than phys RAM with the BATs so we don't have
1993dfcb315SAneesh Kumar K.V  * to worry about the VMALLOC_OFFSET causing problems.  We do have to worry
2003dfcb315SAneesh Kumar K.V  * about clashes between our early calls to ioremap() that start growing down
2013dfcb315SAneesh Kumar K.V  * from ioremap_base being run into the VM area allocations (growing upwards
2023dfcb315SAneesh Kumar K.V  * from VMALLOC_START).  For this reason we have ioremap_bot to check when
2033dfcb315SAneesh Kumar K.V  * we actually run into our mappings setup in the early boot with the VM
2043dfcb315SAneesh Kumar K.V  * system.  This really does become a problem for machines with good amounts
2053dfcb315SAneesh Kumar K.V  * of RAM.  -- Cort
2063dfcb315SAneesh Kumar K.V  */
2073dfcb315SAneesh Kumar K.V #define VMALLOC_OFFSET (0x1000000) /* 16M */
20863b2bc61SChristophe Leroy 
2093dfcb315SAneesh Kumar K.V #define VMALLOC_START ((((long)high_memory + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1)))
2103d4247fcSChristophe Leroy 
2113d4247fcSChristophe Leroy #ifdef CONFIG_KASAN_VMALLOC
212e96d904eSChristophe Leroy #define VMALLOC_END	ALIGN_DOWN(ioremap_bot, PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
2133d4247fcSChristophe Leroy #else
2143dfcb315SAneesh Kumar K.V #define VMALLOC_END	ioremap_bot
2153d4247fcSChristophe Leroy #endif
2163dfcb315SAneesh Kumar K.V 
2176ca05532SChristophe Leroy #define MODULES_END	ALIGN_DOWN(PAGE_OFFSET, SZ_256M)
2186ca05532SChristophe Leroy #define MODULES_VADDR	(MODULES_END - SZ_256M)
2196ca05532SChristophe Leroy 
220cbbb8683SAneesh Kumar K.V #ifndef __ASSEMBLY__
221cbbb8683SAneesh Kumar K.V #include <linux/sched.h>
222cbbb8683SAneesh Kumar K.V #include <linux/threads.h>
223cbbb8683SAneesh Kumar K.V 
2249b081e10SChristophe Leroy /* Bits to mask out from a PGD to get to the PUD page */
2259b081e10SChristophe Leroy #define PGD_MASKED_BITS		0
226cbbb8683SAneesh Kumar K.V 
227cbbb8683SAneesh Kumar K.V #define pte_ERROR(e) \
228cbbb8683SAneesh Kumar K.V 	pr_err("%s:%d: bad pte %llx.\n", __FILE__, __LINE__, \
229cbbb8683SAneesh Kumar K.V 		(unsigned long long)pte_val(e))
230cbbb8683SAneesh Kumar K.V #define pgd_ERROR(e) \
231cbbb8683SAneesh Kumar K.V 	pr_err("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
2323dfcb315SAneesh Kumar K.V /*
2333dfcb315SAneesh Kumar K.V  * Bits in a linux-style PTE.  These match the bits in the
2343dfcb315SAneesh Kumar K.V  * (hardware-defined) PowerPC PTE as closely as possible.
2353dfcb315SAneesh Kumar K.V  */
2363dfcb315SAneesh Kumar K.V 
2373dfcb315SAneesh Kumar K.V #define pte_clear(mm, addr, ptep) \
23806f52524SChristophe Leroy 	do { pte_update(mm, addr, ptep, ~_PAGE_HASHPTE, 0, 0); } while (0)
2393dfcb315SAneesh Kumar K.V 
2403dfcb315SAneesh Kumar K.V #define pmd_none(pmd)		(!pmd_val(pmd))
2413dfcb315SAneesh Kumar K.V #define	pmd_bad(pmd)		(pmd_val(pmd) & _PMD_BAD)
2423dfcb315SAneesh Kumar K.V #define	pmd_present(pmd)	(pmd_val(pmd) & _PMD_PRESENT_MASK)
pmd_clear(pmd_t * pmdp)243f281b5d5SAneesh Kumar K.V static inline void pmd_clear(pmd_t *pmdp)
244f281b5d5SAneesh Kumar K.V {
245f281b5d5SAneesh Kumar K.V 	*pmdp = __pmd(0);
246f281b5d5SAneesh Kumar K.V }
247f281b5d5SAneesh Kumar K.V 
2483dfcb315SAneesh Kumar K.V 
2493dfcb315SAneesh Kumar K.V /*
2503dfcb315SAneesh Kumar K.V  * When flushing the tlb entry for a page, we also need to flush the hash
2513dfcb315SAneesh Kumar K.V  * table entry.  flush_hash_pages is assembler (for speed) in hashtable.S.
2523dfcb315SAneesh Kumar K.V  */
2533dfcb315SAneesh Kumar K.V extern int flush_hash_pages(unsigned context, unsigned long va,
2543dfcb315SAneesh Kumar K.V 			    unsigned long pmdval, int count);
2553dfcb315SAneesh Kumar K.V 
2563dfcb315SAneesh Kumar K.V /* Add an HPTE to the hash table */
2573dfcb315SAneesh Kumar K.V extern void add_hash_page(unsigned context, unsigned long va,
2583dfcb315SAneesh Kumar K.V 			  unsigned long pmdval);
2593dfcb315SAneesh Kumar K.V 
2603dfcb315SAneesh Kumar K.V /* Flush an entry from the TLB/hash table */
flush_hash_entry(struct mm_struct * mm,pte_t * ptep,unsigned long addr)26180007a17SChristophe Leroy static inline void flush_hash_entry(struct mm_struct *mm, pte_t *ptep, unsigned long addr)
26280007a17SChristophe Leroy {
26380007a17SChristophe Leroy 	if (mmu_has_feature(MMU_FTR_HPTE_TABLE)) {
26480007a17SChristophe Leroy 		unsigned long ptephys = __pa(ptep) & PAGE_MASK;
26580007a17SChristophe Leroy 
26680007a17SChristophe Leroy 		flush_hash_pages(mm->context.id, addr, ptephys, 1);
26780007a17SChristophe Leroy 	}
26880007a17SChristophe Leroy }
2693dfcb315SAneesh Kumar K.V 
2703dfcb315SAneesh Kumar K.V /*
2713dfcb315SAneesh Kumar K.V  * PTE updates. This function is called whenever an existing
2723dfcb315SAneesh Kumar K.V  * valid PTE is updated. This does -not- include set_pte_at()
2733dfcb315SAneesh Kumar K.V  * which nowadays only sets a new PTE.
2743dfcb315SAneesh Kumar K.V  *
2753dfcb315SAneesh Kumar K.V  * Depending on the type of MMU, we may need to use atomic updates
2763dfcb315SAneesh Kumar K.V  * and the PTE may be either 32 or 64 bit wide. In the later case,
2773dfcb315SAneesh Kumar K.V  * when using atomic updates, only the low part of the PTE is
2783dfcb315SAneesh Kumar K.V  * accessed atomically.
2793dfcb315SAneesh Kumar K.V  */
pte_update(struct mm_struct * mm,unsigned long addr,pte_t * p,unsigned long clr,unsigned long set,int huge)28006f52524SChristophe Leroy static inline pte_basic_t pte_update(struct mm_struct *mm, unsigned long addr, pte_t *p,
28106f52524SChristophe Leroy 				     unsigned long clr, unsigned long set, int huge)
2823dfcb315SAneesh Kumar K.V {
2831c1bf294SChristophe Leroy 	pte_basic_t old;
2844291d085SChristophe Leroy 
2854291d085SChristophe Leroy 	if (mmu_has_feature(MMU_FTR_HPTE_TABLE)) {
2863dfcb315SAneesh Kumar K.V 		unsigned long tmp;
2873dfcb315SAneesh Kumar K.V 
2884291d085SChristophe Leroy 		asm volatile(
2891c1bf294SChristophe Leroy #ifndef CONFIG_PTE_64BIT
2901c1bf294SChristophe Leroy 	"1:	lwarx	%0, 0, %3\n"
2911c1bf294SChristophe Leroy 	"	andc	%1, %0, %4\n"
2921c1bf294SChristophe Leroy #else
2931c1bf294SChristophe Leroy 	"1:	lwarx	%L0, 0, %3\n"
2941c1bf294SChristophe Leroy 	"	lwz	%0, -4(%3)\n"
2951c1bf294SChristophe Leroy 	"	andc	%1, %L0, %4\n"
2961c1bf294SChristophe Leroy #endif
2971c1bf294SChristophe Leroy 	"	or	%1, %1, %5\n"
2981c1bf294SChristophe Leroy 	"	stwcx.	%1, 0, %3\n"
2991c1bf294SChristophe Leroy 	"	bne-	1b"
3003dfcb315SAneesh Kumar K.V 		: "=&r" (old), "=&r" (tmp), "=m" (*p)
3011c1bf294SChristophe Leroy #ifndef CONFIG_PTE_64BIT
3021c1bf294SChristophe Leroy 		: "r" (p),
3031c1bf294SChristophe Leroy #else
3041c1bf294SChristophe Leroy 		: "b" ((unsigned long)(p) + 4),
3051c1bf294SChristophe Leroy #endif
3061c1bf294SChristophe Leroy 		  "r" (clr), "r" (set), "m" (*p)
3073dfcb315SAneesh Kumar K.V 		: "cc" );
3084291d085SChristophe Leroy 	} else {
3094291d085SChristophe Leroy 		old = pte_val(*p);
3104291d085SChristophe Leroy 
3114291d085SChristophe Leroy 		*p = __pte((old & ~(pte_basic_t)clr) | set);
3124291d085SChristophe Leroy 	}
3133dfcb315SAneesh Kumar K.V 
3143dfcb315SAneesh Kumar K.V 	return old;
3153dfcb315SAneesh Kumar K.V }
3163dfcb315SAneesh Kumar K.V 
3173dfcb315SAneesh Kumar K.V /*
3183dfcb315SAneesh Kumar K.V  * 2.6 calls this without flushing the TLB entry; this is wrong
3193dfcb315SAneesh Kumar K.V  * for our hash-based implementation, we fix that up here.
3203dfcb315SAneesh Kumar K.V  */
3213dfcb315SAneesh Kumar K.V #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
__ptep_test_and_clear_young(struct mm_struct * mm,unsigned long addr,pte_t * ptep)322c7fa7701SChristophe Leroy static inline int __ptep_test_and_clear_young(struct mm_struct *mm,
323c7fa7701SChristophe Leroy 					      unsigned long addr, pte_t *ptep)
3243dfcb315SAneesh Kumar K.V {
3253dfcb315SAneesh Kumar K.V 	unsigned long old;
32606f52524SChristophe Leroy 	old = pte_update(mm, addr, ptep, _PAGE_ACCESSED, 0, 0);
32780007a17SChristophe Leroy 	if (old & _PAGE_HASHPTE)
32880007a17SChristophe Leroy 		flush_hash_entry(mm, ptep, addr);
32980007a17SChristophe Leroy 
3303dfcb315SAneesh Kumar K.V 	return (old & _PAGE_ACCESSED) != 0;
3313dfcb315SAneesh Kumar K.V }
3323dfcb315SAneesh Kumar K.V #define ptep_test_and_clear_young(__vma, __addr, __ptep) \
333c7fa7701SChristophe Leroy 	__ptep_test_and_clear_young((__vma)->vm_mm, __addr, __ptep)
3343dfcb315SAneesh Kumar K.V 
3353dfcb315SAneesh Kumar K.V #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
ptep_get_and_clear(struct mm_struct * mm,unsigned long addr,pte_t * ptep)3363dfcb315SAneesh Kumar K.V static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
3373dfcb315SAneesh Kumar K.V 				       pte_t *ptep)
3383dfcb315SAneesh Kumar K.V {
33906f52524SChristophe Leroy 	return __pte(pte_update(mm, addr, ptep, ~_PAGE_HASHPTE, 0, 0));
3403dfcb315SAneesh Kumar K.V }
3413dfcb315SAneesh Kumar K.V 
3423dfcb315SAneesh Kumar K.V #define __HAVE_ARCH_PTEP_SET_WRPROTECT
ptep_set_wrprotect(struct mm_struct * mm,unsigned long addr,pte_t * ptep)3433dfcb315SAneesh Kumar K.V static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,
3443dfcb315SAneesh Kumar K.V 				      pte_t *ptep)
3453dfcb315SAneesh Kumar K.V {
34606f52524SChristophe Leroy 	pte_update(mm, addr, ptep, _PAGE_RW, 0, 0);
3473dfcb315SAneesh Kumar K.V }
3483dfcb315SAneesh Kumar K.V 
__ptep_set_access_flags(struct vm_area_struct * vma,pte_t * ptep,pte_t entry,unsigned long address,int psize)349e4c1112cSAneesh Kumar K.V static inline void __ptep_set_access_flags(struct vm_area_struct *vma,
350b3603e17SAneesh Kumar K.V 					   pte_t *ptep, pte_t entry,
351e4c1112cSAneesh Kumar K.V 					   unsigned long address,
352e4c1112cSAneesh Kumar K.V 					   int psize)
3533dfcb315SAneesh Kumar K.V {
3543dfcb315SAneesh Kumar K.V 	unsigned long set = pte_val(entry) &
355385e89d5SChristophe Leroy 		(_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC);
3563dfcb315SAneesh Kumar K.V 
35706f52524SChristophe Leroy 	pte_update(vma->vm_mm, address, ptep, 0, set, 0);
358bd5050e3SAneesh Kumar K.V 
359bd5050e3SAneesh Kumar K.V 	flush_tlb_page(vma, address);
3603dfcb315SAneesh Kumar K.V }
3613dfcb315SAneesh Kumar K.V 
3623dfcb315SAneesh Kumar K.V #define __HAVE_ARCH_PTE_SAME
3633dfcb315SAneesh Kumar K.V #define pte_same(A,B)	(((pte_val(A) ^ pte_val(B)) & ~_PAGE_HASHPTE) == 0)
3643dfcb315SAneesh Kumar K.V 
3659e996c21SMatthew Wilcox (Oracle) #define pmd_pfn(pmd)		(pmd_val(pmd) >> PAGE_SHIFT)
3669e996c21SMatthew Wilcox (Oracle) #define pmd_page(pmd)		pfn_to_page(pmd_pfn(pmd))
3673dfcb315SAneesh Kumar K.V 
3683dfcb315SAneesh Kumar K.V /*
3698897ebffSDavid Hildenbrand  * Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that
3708897ebffSDavid Hildenbrand  * are !pte_none() && !pte_present().
3718897ebffSDavid Hildenbrand  *
3728897ebffSDavid Hildenbrand  * Format of swap PTEs (32bit PTEs):
3738897ebffSDavid Hildenbrand  *
3748897ebffSDavid Hildenbrand  *                         1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
3758897ebffSDavid Hildenbrand  *   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
3768897ebffSDavid Hildenbrand  *   <----------------- offset --------------------> < type -> E H P
3778897ebffSDavid Hildenbrand  *
3788897ebffSDavid Hildenbrand  *   E is the exclusive marker that is not stored in swap entries.
3798897ebffSDavid Hildenbrand  *   _PAGE_PRESENT (P) and __PAGE_HASHPTE (H) must be 0.
3808897ebffSDavid Hildenbrand  *
3818897ebffSDavid Hildenbrand  * For 64bit PTEs, the offset is extended by 32bit.
3823dfcb315SAneesh Kumar K.V  */
3833dfcb315SAneesh Kumar K.V #define __swp_type(entry)		((entry).val & 0x1f)
3843dfcb315SAneesh Kumar K.V #define __swp_offset(entry)		((entry).val >> 5)
3858897ebffSDavid Hildenbrand #define __swp_entry(type, offset)	((swp_entry_t) { ((type) & 0x1f) | ((offset) << 5) })
3863dfcb315SAneesh Kumar K.V #define __pte_to_swp_entry(pte)		((swp_entry_t) { pte_val(pte) >> 3 })
3873dfcb315SAneesh Kumar K.V #define __swp_entry_to_pte(x)		((pte_t) { (x).val << 3 })
3883dfcb315SAneesh Kumar K.V 
pte_swp_exclusive(pte_t pte)3898897ebffSDavid Hildenbrand static inline int pte_swp_exclusive(pte_t pte)
3908897ebffSDavid Hildenbrand {
3918897ebffSDavid Hildenbrand 	return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
3928897ebffSDavid Hildenbrand }
3938897ebffSDavid Hildenbrand 
pte_swp_mkexclusive(pte_t pte)3948897ebffSDavid Hildenbrand static inline pte_t pte_swp_mkexclusive(pte_t pte)
3958897ebffSDavid Hildenbrand {
3968897ebffSDavid Hildenbrand 	return __pte(pte_val(pte) | _PAGE_SWP_EXCLUSIVE);
3978897ebffSDavid Hildenbrand }
3988897ebffSDavid Hildenbrand 
pte_swp_clear_exclusive(pte_t pte)3998897ebffSDavid Hildenbrand static inline pte_t pte_swp_clear_exclusive(pte_t pte)
4008897ebffSDavid Hildenbrand {
4018897ebffSDavid Hildenbrand 	return __pte(pte_val(pte) & ~_PAGE_SWP_EXCLUSIVE);
4028897ebffSDavid Hildenbrand }
4038897ebffSDavid Hildenbrand 
4041ca72129SAneesh Kumar K.V /* Generic accessors to PTE bits */
pte_write(pte_t pte)4051ca72129SAneesh Kumar K.V static inline int pte_write(pte_t pte)		{ return !!(pte_val(pte) & _PAGE_RW);}
pte_read(pte_t pte)406ca8afd40SChristophe Leroy static inline int pte_read(pte_t pte)		{ return 1; }
pte_dirty(pte_t pte)4071ca72129SAneesh Kumar K.V static inline int pte_dirty(pte_t pte)		{ return !!(pte_val(pte) & _PAGE_DIRTY); }
pte_young(pte_t pte)4081ca72129SAneesh Kumar K.V static inline int pte_young(pte_t pte)		{ return !!(pte_val(pte) & _PAGE_ACCESSED); }
pte_special(pte_t pte)4091ca72129SAneesh Kumar K.V static inline int pte_special(pte_t pte)	{ return !!(pte_val(pte) & _PAGE_SPECIAL); }
pte_none(pte_t pte)4101ca72129SAneesh Kumar K.V static inline int pte_none(pte_t pte)		{ return (pte_val(pte) & ~_PTE_NONE_MASK) == 0; }
pte_exec(pte_t pte)411385e89d5SChristophe Leroy static inline bool pte_exec(pte_t pte)		{ return pte_val(pte) & _PAGE_EXEC; }
4121ca72129SAneesh Kumar K.V 
pte_present(pte_t pte)4131ca72129SAneesh Kumar K.V static inline int pte_present(pte_t pte)
4141ca72129SAneesh Kumar K.V {
4151ca72129SAneesh Kumar K.V 	return pte_val(pte) & _PAGE_PRESENT;
4161ca72129SAneesh Kumar K.V }
4171ca72129SAneesh Kumar K.V 
pte_hw_valid(pte_t pte)418daba7902SChristophe Leroy static inline bool pte_hw_valid(pte_t pte)
419daba7902SChristophe Leroy {
420daba7902SChristophe Leroy 	return pte_val(pte) & _PAGE_PRESENT;
421daba7902SChristophe Leroy }
422daba7902SChristophe Leroy 
pte_hashpte(pte_t pte)423daba7902SChristophe Leroy static inline bool pte_hashpte(pte_t pte)
424daba7902SChristophe Leroy {
425daba7902SChristophe Leroy 	return !!(pte_val(pte) & _PAGE_HASHPTE);
426daba7902SChristophe Leroy }
427daba7902SChristophe Leroy 
pte_ci(pte_t pte)428daba7902SChristophe Leroy static inline bool pte_ci(pte_t pte)
429daba7902SChristophe Leroy {
430daba7902SChristophe Leroy 	return !!(pte_val(pte) & _PAGE_NO_CACHE);
431daba7902SChristophe Leroy }
432daba7902SChristophe Leroy 
4335769beafSAneesh Kumar K.V /*
4345769beafSAneesh Kumar K.V  * We only find page table entry in the last level
4355769beafSAneesh Kumar K.V  * Hence no need for other accessors
4365769beafSAneesh Kumar K.V  */
4375769beafSAneesh Kumar K.V #define pte_access_permitted pte_access_permitted
pte_access_permitted(pte_t pte,bool write)4385769beafSAneesh Kumar K.V static inline bool pte_access_permitted(pte_t pte, bool write)
4395769beafSAneesh Kumar K.V {
4405769beafSAneesh Kumar K.V 	/*
4415769beafSAneesh Kumar K.V 	 * A read-only access is controlled by _PAGE_USER bit.
4425769beafSAneesh Kumar K.V 	 * We have _PAGE_READ set for WRITE and EXECUTE
4435769beafSAneesh Kumar K.V 	 */
44426973fa5SChristophe Leroy 	if (!pte_present(pte) || !pte_user(pte) || !pte_read(pte))
44526973fa5SChristophe Leroy 		return false;
4465769beafSAneesh Kumar K.V 
44726973fa5SChristophe Leroy 	if (write && !pte_write(pte))
4485769beafSAneesh Kumar K.V 		return false;
4495769beafSAneesh Kumar K.V 
4505769beafSAneesh Kumar K.V 	return true;
4515769beafSAneesh Kumar K.V }
4525769beafSAneesh Kumar K.V 
4531ca72129SAneesh Kumar K.V /* Conversion functions: convert a page and protection to a page entry,
4541ca72129SAneesh Kumar K.V  * and a page entry and page directory to the page they refer to.
4551ca72129SAneesh Kumar K.V  *
4561ca72129SAneesh Kumar K.V  * Even if PTEs can be unsigned long long, a PFN is always an unsigned
4571ca72129SAneesh Kumar K.V  * long for now.
4581ca72129SAneesh Kumar K.V  */
pfn_pte(unsigned long pfn,pgprot_t pgprot)4591ca72129SAneesh Kumar K.V static inline pte_t pfn_pte(unsigned long pfn, pgprot_t pgprot)
4601ca72129SAneesh Kumar K.V {
4611ca72129SAneesh Kumar K.V 	return __pte(((pte_basic_t)(pfn) << PTE_RPN_SHIFT) |
4621ca72129SAneesh Kumar K.V 		     pgprot_val(pgprot));
4631ca72129SAneesh Kumar K.V }
4641ca72129SAneesh Kumar K.V 
4651ca72129SAneesh Kumar K.V /* Generic modifiers for PTE bits */
pte_wrprotect(pte_t pte)4661ca72129SAneesh Kumar K.V static inline pte_t pte_wrprotect(pte_t pte)
4671ca72129SAneesh Kumar K.V {
4681ca72129SAneesh Kumar K.V 	return __pte(pte_val(pte) & ~_PAGE_RW);
4691ca72129SAneesh Kumar K.V }
4701ca72129SAneesh Kumar K.V 
pte_exprotect(pte_t pte)471daba7902SChristophe Leroy static inline pte_t pte_exprotect(pte_t pte)
472daba7902SChristophe Leroy {
473385e89d5SChristophe Leroy 	return __pte(pte_val(pte) & ~_PAGE_EXEC);
474daba7902SChristophe Leroy }
475daba7902SChristophe Leroy 
pte_mkclean(pte_t pte)4761ca72129SAneesh Kumar K.V static inline pte_t pte_mkclean(pte_t pte)
4771ca72129SAneesh Kumar K.V {
4781ca72129SAneesh Kumar K.V 	return __pte(pte_val(pte) & ~_PAGE_DIRTY);
4791ca72129SAneesh Kumar K.V }
4801ca72129SAneesh Kumar K.V 
pte_mkold(pte_t pte)4811ca72129SAneesh Kumar K.V static inline pte_t pte_mkold(pte_t pte)
4821ca72129SAneesh Kumar K.V {
4831ca72129SAneesh Kumar K.V 	return __pte(pte_val(pte) & ~_PAGE_ACCESSED);
4841ca72129SAneesh Kumar K.V }
4851ca72129SAneesh Kumar K.V 
pte_mkexec(pte_t pte)486daba7902SChristophe Leroy static inline pte_t pte_mkexec(pte_t pte)
487daba7902SChristophe Leroy {
488385e89d5SChristophe Leroy 	return __pte(pte_val(pte) | _PAGE_EXEC);
489daba7902SChristophe Leroy }
490daba7902SChristophe Leroy 
pte_mkpte(pte_t pte)491daba7902SChristophe Leroy static inline pte_t pte_mkpte(pte_t pte)
492daba7902SChristophe Leroy {
493daba7902SChristophe Leroy 	return pte;
494daba7902SChristophe Leroy }
495daba7902SChristophe Leroy 
pte_mkwrite_novma(pte_t pte)4962f0584f3SRick Edgecombe static inline pte_t pte_mkwrite_novma(pte_t pte)
4971ca72129SAneesh Kumar K.V {
4981ca72129SAneesh Kumar K.V 	return __pte(pte_val(pte) | _PAGE_RW);
4991ca72129SAneesh Kumar K.V }
5001ca72129SAneesh Kumar K.V 
pte_mkdirty(pte_t pte)5011ca72129SAneesh Kumar K.V static inline pte_t pte_mkdirty(pte_t pte)
5021ca72129SAneesh Kumar K.V {
5031ca72129SAneesh Kumar K.V 	return __pte(pte_val(pte) | _PAGE_DIRTY);
5041ca72129SAneesh Kumar K.V }
5051ca72129SAneesh Kumar K.V 
pte_mkyoung(pte_t pte)5061ca72129SAneesh Kumar K.V static inline pte_t pte_mkyoung(pte_t pte)
5071ca72129SAneesh Kumar K.V {
5081ca72129SAneesh Kumar K.V 	return __pte(pte_val(pte) | _PAGE_ACCESSED);
5091ca72129SAneesh Kumar K.V }
5101ca72129SAneesh Kumar K.V 
pte_mkspecial(pte_t pte)5111ca72129SAneesh Kumar K.V static inline pte_t pte_mkspecial(pte_t pte)
5121ca72129SAneesh Kumar K.V {
5131ca72129SAneesh Kumar K.V 	return __pte(pte_val(pte) | _PAGE_SPECIAL);
5141ca72129SAneesh Kumar K.V }
5151ca72129SAneesh Kumar K.V 
pte_mkhuge(pte_t pte)5161ca72129SAneesh Kumar K.V static inline pte_t pte_mkhuge(pte_t pte)
5171ca72129SAneesh Kumar K.V {
5181ca72129SAneesh Kumar K.V 	return pte;
5191ca72129SAneesh Kumar K.V }
5201ca72129SAneesh Kumar K.V 
pte_mkprivileged(pte_t pte)521daba7902SChristophe Leroy static inline pte_t pte_mkprivileged(pte_t pte)
522daba7902SChristophe Leroy {
523daba7902SChristophe Leroy 	return __pte(pte_val(pte) & ~_PAGE_USER);
524daba7902SChristophe Leroy }
525daba7902SChristophe Leroy 
pte_mkuser(pte_t pte)526daba7902SChristophe Leroy static inline pte_t pte_mkuser(pte_t pte)
527daba7902SChristophe Leroy {
528daba7902SChristophe Leroy 	return __pte(pte_val(pte) | _PAGE_USER);
529daba7902SChristophe Leroy }
530daba7902SChristophe Leroy 
pte_modify(pte_t pte,pgprot_t newprot)5311ca72129SAneesh Kumar K.V static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
5321ca72129SAneesh Kumar K.V {
5331ca72129SAneesh Kumar K.V 	return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
5341ca72129SAneesh Kumar K.V }
5351ca72129SAneesh Kumar K.V 
5361ca72129SAneesh Kumar K.V 
5371ca72129SAneesh Kumar K.V 
5381ca72129SAneesh Kumar K.V /* This low level function performs the actual PTE insertion
539*7cb0094bSChristophe Leroy  * Setting the PTE depends on the MMU type and other factors.
540*7cb0094bSChristophe Leroy  *
541*7cb0094bSChristophe Leroy  * First case is 32-bit in UP mode with 32-bit PTEs, we need to preserve
542*7cb0094bSChristophe Leroy  * the _PAGE_HASHPTE bit since we may not have invalidated the previous
543*7cb0094bSChristophe Leroy  * translation in the hash yet (done in a subsequent flush_tlb_xxx())
544*7cb0094bSChristophe Leroy  * and see we need to keep track that this PTE needs invalidating.
545*7cb0094bSChristophe Leroy  *
546*7cb0094bSChristophe Leroy  * Second case is 32-bit with 64-bit PTE.  In this case, we
5471ca72129SAneesh Kumar K.V  * can just store as long as we do the two halves in the right order
5481ca72129SAneesh Kumar K.V  * with a barrier in between. This is possible because we take care,
5491ca72129SAneesh Kumar K.V  * in the hash code, to pre-invalidate if the PTE was already hashed,
5501ca72129SAneesh Kumar K.V  * which synchronizes us with any concurrent invalidation.
551*7cb0094bSChristophe Leroy  * In the percpu case, we fallback to the simple update preserving
552*7cb0094bSChristophe Leroy  * the hash bits (ie, same as the non-SMP case).
553*7cb0094bSChristophe Leroy  *
554*7cb0094bSChristophe Leroy  * Third case is 32-bit in SMP mode with 32-bit PTEs. We use the
555*7cb0094bSChristophe Leroy  * helper pte_update() which does an atomic update. We need to do that
556*7cb0094bSChristophe Leroy  * because a concurrent invalidation can clear _PAGE_HASHPTE. If it's a
557*7cb0094bSChristophe Leroy  * per-CPU PTE such as a kmap_atomic, we also do a simple update preserving
558*7cb0094bSChristophe Leroy  * the hash bits instead.
5591ca72129SAneesh Kumar K.V  */
__set_pte_at(struct mm_struct * mm,unsigned long addr,pte_t * ptep,pte_t pte,int percpu)560*7cb0094bSChristophe Leroy static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,
561*7cb0094bSChristophe Leroy 				pte_t *ptep, pte_t pte, int percpu)
562*7cb0094bSChristophe Leroy {
563*7cb0094bSChristophe Leroy 	if ((!IS_ENABLED(CONFIG_SMP) && !IS_ENABLED(CONFIG_PTE_64BIT)) || percpu) {
564*7cb0094bSChristophe Leroy 		*ptep = __pte((pte_val(*ptep) & _PAGE_HASHPTE) |
565*7cb0094bSChristophe Leroy 			      (pte_val(pte) & ~_PAGE_HASHPTE));
566*7cb0094bSChristophe Leroy 	} else if (IS_ENABLED(CONFIG_PTE_64BIT)) {
5671ca72129SAneesh Kumar K.V 		if (pte_val(*ptep) & _PAGE_HASHPTE)
5681ca72129SAneesh Kumar K.V 			flush_hash_entry(mm, ptep, addr);
5691ca72129SAneesh Kumar K.V 
570*7cb0094bSChristophe Leroy 		asm volatile("stw%X0 %2,%0; eieio; stw%X1 %L2,%1" :
571*7cb0094bSChristophe Leroy 			     "=m" (*ptep), "=m" (*((unsigned char *)ptep+4)) :
572*7cb0094bSChristophe Leroy 			     "r" (pte) : "memory");
573*7cb0094bSChristophe Leroy 	} else {
574*7cb0094bSChristophe Leroy 		pte_update(mm, addr, ptep, ~_PAGE_HASHPTE, pte_val(pte), 0);
575*7cb0094bSChristophe Leroy 	}
5761ca72129SAneesh Kumar K.V }
5771ca72129SAneesh Kumar K.V 
5781ca72129SAneesh Kumar K.V /*
5791ca72129SAneesh Kumar K.V  * Macro to mark a page protection value as "uncacheable".
5801ca72129SAneesh Kumar K.V  */
5811ca72129SAneesh Kumar K.V 
5821ca72129SAneesh Kumar K.V #define _PAGE_CACHE_CTL	(_PAGE_COHERENT | _PAGE_GUARDED | _PAGE_NO_CACHE | \
5831ca72129SAneesh Kumar K.V 			 _PAGE_WRITETHRU)
5841ca72129SAneesh Kumar K.V 
5851ca72129SAneesh Kumar K.V #define pgprot_noncached pgprot_noncached
pgprot_noncached(pgprot_t prot)5861ca72129SAneesh Kumar K.V static inline pgprot_t pgprot_noncached(pgprot_t prot)
5871ca72129SAneesh Kumar K.V {
5881ca72129SAneesh Kumar K.V 	return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) |
5891ca72129SAneesh Kumar K.V 			_PAGE_NO_CACHE | _PAGE_GUARDED);
5901ca72129SAneesh Kumar K.V }
5911ca72129SAneesh Kumar K.V 
5921ca72129SAneesh Kumar K.V #define pgprot_noncached_wc pgprot_noncached_wc
pgprot_noncached_wc(pgprot_t prot)5931ca72129SAneesh Kumar K.V static inline pgprot_t pgprot_noncached_wc(pgprot_t prot)
5941ca72129SAneesh Kumar K.V {
5951ca72129SAneesh Kumar K.V 	return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) |
5961ca72129SAneesh Kumar K.V 			_PAGE_NO_CACHE);
5971ca72129SAneesh Kumar K.V }
5981ca72129SAneesh Kumar K.V 
5991ca72129SAneesh Kumar K.V #define pgprot_cached pgprot_cached
pgprot_cached(pgprot_t prot)6001ca72129SAneesh Kumar K.V static inline pgprot_t pgprot_cached(pgprot_t prot)
6011ca72129SAneesh Kumar K.V {
6021ca72129SAneesh Kumar K.V 	return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) |
6031ca72129SAneesh Kumar K.V 			_PAGE_COHERENT);
6041ca72129SAneesh Kumar K.V }
6051ca72129SAneesh Kumar K.V 
6061ca72129SAneesh Kumar K.V #define pgprot_cached_wthru pgprot_cached_wthru
pgprot_cached_wthru(pgprot_t prot)6071ca72129SAneesh Kumar K.V static inline pgprot_t pgprot_cached_wthru(pgprot_t prot)
6081ca72129SAneesh Kumar K.V {
6091ca72129SAneesh Kumar K.V 	return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) |
6101ca72129SAneesh Kumar K.V 			_PAGE_COHERENT | _PAGE_WRITETHRU);
6111ca72129SAneesh Kumar K.V }
6121ca72129SAneesh Kumar K.V 
6131ca72129SAneesh Kumar K.V #define pgprot_cached_noncoherent pgprot_cached_noncoherent
pgprot_cached_noncoherent(pgprot_t prot)6141ca72129SAneesh Kumar K.V static inline pgprot_t pgprot_cached_noncoherent(pgprot_t prot)
6151ca72129SAneesh Kumar K.V {
6161ca72129SAneesh Kumar K.V 	return __pgprot(pgprot_val(prot) & ~_PAGE_CACHE_CTL);
6171ca72129SAneesh Kumar K.V }
6181ca72129SAneesh Kumar K.V 
6191ca72129SAneesh Kumar K.V #define pgprot_writecombine pgprot_writecombine
pgprot_writecombine(pgprot_t prot)6201ca72129SAneesh Kumar K.V static inline pgprot_t pgprot_writecombine(pgprot_t prot)
6211ca72129SAneesh Kumar K.V {
6221ca72129SAneesh Kumar K.V 	return pgprot_noncached_wc(prot);
6231ca72129SAneesh Kumar K.V }
6241ca72129SAneesh Kumar K.V 
6253dfcb315SAneesh Kumar K.V #endif /* !__ASSEMBLY__ */
6263dfcb315SAneesh Kumar K.V 
6273dfcb315SAneesh Kumar K.V #endif /*  _ASM_POWERPC_BOOK3S_32_PGTABLE_H */
628