xref: /openbmc/linux/arch/alpha/include/asm/pgtable.h (revision 63497b71)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2024b246eSLinus Torvalds #ifndef _ALPHA_PGTABLE_H
3024b246eSLinus Torvalds #define _ALPHA_PGTABLE_H
4024b246eSLinus Torvalds 
5a73c9489SMike Rapoport #include <asm-generic/pgtable-nopud.h>
6024b246eSLinus Torvalds 
7024b246eSLinus Torvalds /*
8024b246eSLinus Torvalds  * This file contains the functions and defines necessary to modify and use
9024b246eSLinus Torvalds  * the Alpha page table tree.
10024b246eSLinus Torvalds  *
11024b246eSLinus Torvalds  * This hopefully works with any standard Alpha page-size, as defined
12024b246eSLinus Torvalds  * in <asm/page.h> (currently 8192).
13024b246eSLinus Torvalds  */
14024b246eSLinus Torvalds #include <linux/mmzone.h>
15024b246eSLinus Torvalds 
16024b246eSLinus Torvalds #include <asm/page.h>
17024b246eSLinus Torvalds #include <asm/processor.h>	/* For TASK_SIZE */
18024b246eSLinus Torvalds #include <asm/machvec.h>
19ec221208SDavid Howells #include <asm/setup.h>
20024b246eSLinus Torvalds 
21024b246eSLinus Torvalds struct mm_struct;
22024b246eSLinus Torvalds struct vm_area_struct;
23024b246eSLinus Torvalds 
24024b246eSLinus Torvalds /* Certain architectures need to do special things when PTEs
25024b246eSLinus Torvalds  * within a page table are directly modified.  Thus, the following
26024b246eSLinus Torvalds  * hook is made available.
27024b246eSLinus Torvalds  */
28024b246eSLinus Torvalds #define set_pte(pteptr, pteval) ((*(pteptr)) = (pteval))
29024b246eSLinus Torvalds 
30024b246eSLinus Torvalds /* PMD_SHIFT determines the size of the area a second-level page table can map */
31024b246eSLinus Torvalds #define PMD_SHIFT	(PAGE_SHIFT + (PAGE_SHIFT-3))
32024b246eSLinus Torvalds #define PMD_SIZE	(1UL << PMD_SHIFT)
33024b246eSLinus Torvalds #define PMD_MASK	(~(PMD_SIZE-1))
34024b246eSLinus Torvalds 
35024b246eSLinus Torvalds /* PGDIR_SHIFT determines what a third-level page table entry can map */
36024b246eSLinus Torvalds #define PGDIR_SHIFT	(PAGE_SHIFT + 2*(PAGE_SHIFT-3))
37024b246eSLinus Torvalds #define PGDIR_SIZE	(1UL << PGDIR_SHIFT)
38024b246eSLinus Torvalds #define PGDIR_MASK	(~(PGDIR_SIZE-1))
39024b246eSLinus Torvalds 
40024b246eSLinus Torvalds /*
41024b246eSLinus Torvalds  * Entries per page directory level:  the Alpha is three-level, with
42024b246eSLinus Torvalds  * all levels having a one-page page table.
43024b246eSLinus Torvalds  */
44024b246eSLinus Torvalds #define PTRS_PER_PTE	(1UL << (PAGE_SHIFT-3))
45024b246eSLinus Torvalds #define PTRS_PER_PMD	(1UL << (PAGE_SHIFT-3))
46024b246eSLinus Torvalds #define PTRS_PER_PGD	(1UL << (PAGE_SHIFT-3))
47024b246eSLinus Torvalds #define USER_PTRS_PER_PGD	(TASK_SIZE / PGDIR_SIZE)
48024b246eSLinus Torvalds 
49024b246eSLinus Torvalds /* Number of pointers that fit on a page:  this will go away. */
50024b246eSLinus Torvalds #define PTRS_PER_PAGE	(1UL << (PAGE_SHIFT-3))
51024b246eSLinus Torvalds 
52024b246eSLinus Torvalds #ifdef CONFIG_ALPHA_LARGE_VMALLOC
53024b246eSLinus Torvalds #define VMALLOC_START		0xfffffe0000000000
54024b246eSLinus Torvalds #else
55024b246eSLinus Torvalds #define VMALLOC_START		(-2*PGDIR_SIZE)
56024b246eSLinus Torvalds #endif
57024b246eSLinus Torvalds #define VMALLOC_END		(-PGDIR_SIZE)
58024b246eSLinus Torvalds 
59024b246eSLinus Torvalds /*
60024b246eSLinus Torvalds  * OSF/1 PAL-code-imposed page table bits
61024b246eSLinus Torvalds  */
62024b246eSLinus Torvalds #define _PAGE_VALID	0x0001
63024b246eSLinus Torvalds #define _PAGE_FOR	0x0002	/* used for page protection (fault on read) */
64024b246eSLinus Torvalds #define _PAGE_FOW	0x0004	/* used for page protection (fault on write) */
65024b246eSLinus Torvalds #define _PAGE_FOE	0x0008	/* used for page protection (fault on exec) */
66024b246eSLinus Torvalds #define _PAGE_ASM	0x0010
67024b246eSLinus Torvalds #define _PAGE_KRE	0x0100	/* xxx - see below on the "accessed" bit */
68024b246eSLinus Torvalds #define _PAGE_URE	0x0200	/* xxx */
69024b246eSLinus Torvalds #define _PAGE_KWE	0x1000	/* used to do the dirty bit in software */
70024b246eSLinus Torvalds #define _PAGE_UWE	0x2000	/* used to do the dirty bit in software */
71024b246eSLinus Torvalds 
72024b246eSLinus Torvalds /* .. and these are ours ... */
73024b246eSLinus Torvalds #define _PAGE_DIRTY	0x20000
74024b246eSLinus Torvalds #define _PAGE_ACCESSED	0x40000
75024b246eSLinus Torvalds 
76a172d512SDavid Hildenbrand /* We borrow bit 39 to store the exclusive marker in swap PTEs. */
77a172d512SDavid Hildenbrand #define _PAGE_SWP_EXCLUSIVE	0x8000000000UL
78a172d512SDavid Hildenbrand 
79024b246eSLinus Torvalds /*
80024b246eSLinus Torvalds  * NOTE! The "accessed" bit isn't necessarily exact:  it can be kept exactly
81024b246eSLinus Torvalds  * by software (use the KRE/URE/KWE/UWE bits appropriately), but I'll fake it.
82024b246eSLinus Torvalds  * Under Linux/AXP, the "accessed" bit just means "read", and I'll just use
83024b246eSLinus Torvalds  * the KRE/URE bits to watch for it. That way we don't need to overload the
84024b246eSLinus Torvalds  * KWE/UWE bits with both handling dirty and accessed.
85024b246eSLinus Torvalds  *
86024b246eSLinus Torvalds  * Note that the kernel uses the accessed bit just to check whether to page
87024b246eSLinus Torvalds  * out a page or not, so it doesn't have to be exact anyway.
88024b246eSLinus Torvalds  */
89024b246eSLinus Torvalds 
90024b246eSLinus Torvalds #define __DIRTY_BITS	(_PAGE_DIRTY | _PAGE_KWE | _PAGE_UWE)
91024b246eSLinus Torvalds #define __ACCESS_BITS	(_PAGE_ACCESSED | _PAGE_KRE | _PAGE_URE)
92024b246eSLinus Torvalds 
93024b246eSLinus Torvalds #define _PFN_MASK	0xFFFFFFFF00000000UL
94024b246eSLinus Torvalds 
95024b246eSLinus Torvalds #define _PAGE_TABLE	(_PAGE_VALID | __DIRTY_BITS | __ACCESS_BITS)
96024b246eSLinus Torvalds #define _PAGE_CHG_MASK	(_PFN_MASK | __DIRTY_BITS | __ACCESS_BITS)
97024b246eSLinus Torvalds 
98024b246eSLinus Torvalds /*
99024b246eSLinus Torvalds  * All the normal masks have the "page accessed" bits on, as any time they are used,
100024b246eSLinus Torvalds  * the page is accessed. They are cleared only by the page-out routines
101024b246eSLinus Torvalds  */
102024b246eSLinus Torvalds #define PAGE_NONE	__pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOR | _PAGE_FOW | _PAGE_FOE)
103024b246eSLinus Torvalds #define PAGE_SHARED	__pgprot(_PAGE_VALID | __ACCESS_BITS)
104024b246eSLinus Torvalds #define PAGE_COPY	__pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
105024b246eSLinus Torvalds #define PAGE_READONLY	__pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
106024b246eSLinus Torvalds #define PAGE_KERNEL	__pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
107024b246eSLinus Torvalds 
108024b246eSLinus Torvalds #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
109024b246eSLinus Torvalds 
110024b246eSLinus Torvalds #define _PAGE_P(x) _PAGE_NORMAL((x) | (((x) & _PAGE_FOW)?0:_PAGE_FOW))
111024b246eSLinus Torvalds #define _PAGE_S(x) _PAGE_NORMAL(x)
112024b246eSLinus Torvalds 
113024b246eSLinus Torvalds /*
114024b246eSLinus Torvalds  * The hardware can handle write-only mappings, but as the Alpha
115024b246eSLinus Torvalds  * architecture does byte-wide writes with a read-modify-write
116024b246eSLinus Torvalds  * sequence, it's not practical to have write-without-read privs.
117024b246eSLinus Torvalds  * Thus the "-w- -> rw-" and "-wx -> rwx" mapping here (and in
118024b246eSLinus Torvalds  * arch/alpha/mm/fault.c)
119024b246eSLinus Torvalds  */
120024b246eSLinus Torvalds 	/* xwr */
121024b246eSLinus Torvalds 
122024b246eSLinus Torvalds /*
123024b246eSLinus Torvalds  * pgprot_noncached() is only for infiniband pci support, and a real
124024b246eSLinus Torvalds  * implementation for RAM would be more complicated.
125024b246eSLinus Torvalds  */
126024b246eSLinus Torvalds #define pgprot_noncached(prot)	(prot)
127024b246eSLinus Torvalds 
128024b246eSLinus Torvalds /*
129024b246eSLinus Torvalds  * BAD_PAGETABLE is used when we need a bogus page-table, while
130024b246eSLinus Torvalds  * BAD_PAGE is used for a bogus page.
131024b246eSLinus Torvalds  *
132024b246eSLinus Torvalds  * ZERO_PAGE is a global shared page that is always zero:  used
133024b246eSLinus Torvalds  * for zero-mapped memory areas etc..
134024b246eSLinus Torvalds  */
135024b246eSLinus Torvalds extern pte_t __bad_page(void);
136024b246eSLinus Torvalds extern pmd_t * __bad_pagetable(void);
137024b246eSLinus Torvalds 
138024b246eSLinus Torvalds extern unsigned long __zero_page(void);
139024b246eSLinus Torvalds 
140024b246eSLinus Torvalds #define BAD_PAGETABLE	__bad_pagetable()
141024b246eSLinus Torvalds #define BAD_PAGE	__bad_page()
142024b246eSLinus Torvalds #define ZERO_PAGE(vaddr)	(virt_to_page(ZERO_PGE))
143024b246eSLinus Torvalds 
144024b246eSLinus Torvalds /* number of bits that fit into a memory pointer */
145024b246eSLinus Torvalds #define BITS_PER_PTR			(8*sizeof(unsigned long))
146024b246eSLinus Torvalds 
147024b246eSLinus Torvalds /* to align the pointer to a pointer address */
148024b246eSLinus Torvalds #define PTR_MASK			(~(sizeof(void*)-1))
149024b246eSLinus Torvalds 
150024b246eSLinus Torvalds /* sizeof(void*)==1<<SIZEOF_PTR_LOG2 */
151024b246eSLinus Torvalds #define SIZEOF_PTR_LOG2			3
152024b246eSLinus Torvalds 
153024b246eSLinus Torvalds /* to find an entry in a page-table */
154024b246eSLinus Torvalds #define PAGE_PTR(address)		\
155024b246eSLinus Torvalds   ((unsigned long)(address)>>(PAGE_SHIFT-SIZEOF_PTR_LOG2)&PTR_MASK&~PAGE_MASK)
156024b246eSLinus Torvalds 
157024b246eSLinus Torvalds /*
158024b246eSLinus Torvalds  * On certain platforms whose physical address space can overlap KSEG,
159024b246eSLinus Torvalds  * namely EV6 and above, we must re-twiddle the physaddr to restore the
160024b246eSLinus Torvalds  * correct high-order bits.
161024b246eSLinus Torvalds  *
162024b246eSLinus Torvalds  * This is extremely confusing until you realize that this is actually
163024b246eSLinus Torvalds  * just working around a userspace bug.  The X server was intending to
164024b246eSLinus Torvalds  * provide the physical address but instead provided the KSEG address.
165024b246eSLinus Torvalds  * Or tried to, except it's not representable.
166024b246eSLinus Torvalds  *
167024b246eSLinus Torvalds  * On Tsunami there's nothing meaningful at 0x40000000000, so this is
168024b246eSLinus Torvalds  * a safe thing to do.  Come the first core logic that does put something
169024b246eSLinus Torvalds  * in this area -- memory or whathaveyou -- then this hack will have
170024b246eSLinus Torvalds  * to go away.  So be prepared!
171024b246eSLinus Torvalds  */
172024b246eSLinus Torvalds 
173024b246eSLinus Torvalds #if defined(CONFIG_ALPHA_GENERIC) && defined(USE_48_BIT_KSEG)
174024b246eSLinus Torvalds #error "EV6-only feature in a generic kernel"
175024b246eSLinus Torvalds #endif
176024b246eSLinus Torvalds #if defined(CONFIG_ALPHA_GENERIC) || \
177024b246eSLinus Torvalds     (defined(CONFIG_ALPHA_EV6) && !defined(USE_48_BIT_KSEG))
178024b246eSLinus Torvalds #define KSEG_PFN	(0xc0000000000UL >> PAGE_SHIFT)
179024b246eSLinus Torvalds #define PHYS_TWIDDLE(pfn) \
180024b246eSLinus Torvalds   ((((pfn) & KSEG_PFN) == (0x40000000000UL >> PAGE_SHIFT)) \
181024b246eSLinus Torvalds   ? ((pfn) ^= KSEG_PFN) : (pfn))
182024b246eSLinus Torvalds #else
183024b246eSLinus Torvalds #define PHYS_TWIDDLE(pfn) (pfn)
184024b246eSLinus Torvalds #endif
185024b246eSLinus Torvalds 
186024b246eSLinus Torvalds /*
187024b246eSLinus Torvalds  * Conversion functions:  convert a page and protection to a page entry,
188024b246eSLinus Torvalds  * and a page entry and page directory to the page they refer to.
189024b246eSLinus Torvalds  */
19036d40290SMike Rapoport #define page_to_pa(page)	(page_to_pfn(page) << PAGE_SHIFT)
191*63497b71SMatthew Wilcox (Oracle) #define PFN_PTE_SHIFT		32
192*63497b71SMatthew Wilcox (Oracle) #define pte_pfn(pte)		(pte_val(pte) >> PFN_PTE_SHIFT)
19336d40290SMike Rapoport 
194024b246eSLinus Torvalds #define pte_page(pte)	pfn_to_page(pte_pfn(pte))
195024b246eSLinus Torvalds #define mk_pte(page, pgprot)						\
196024b246eSLinus Torvalds ({									\
197024b246eSLinus Torvalds 	pte_t pte;							\
198024b246eSLinus Torvalds 									\
199024b246eSLinus Torvalds 	pte_val(pte) = (page_to_pfn(page) << 32) | pgprot_val(pgprot);	\
200024b246eSLinus Torvalds 	pte;								\
201024b246eSLinus Torvalds })
202024b246eSLinus Torvalds 
pfn_pte(unsigned long physpfn,pgprot_t pgprot)203024b246eSLinus Torvalds extern inline pte_t pfn_pte(unsigned long physpfn, pgprot_t pgprot)
204024b246eSLinus Torvalds { pte_t pte; pte_val(pte) = (PHYS_TWIDDLE(physpfn) << 32) | pgprot_val(pgprot); return pte; }
205024b246eSLinus Torvalds 
pte_modify(pte_t pte,pgprot_t newprot)206024b246eSLinus Torvalds extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
207024b246eSLinus Torvalds { pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; }
208024b246eSLinus Torvalds 
pmd_set(pmd_t * pmdp,pte_t * ptep)209024b246eSLinus Torvalds extern inline void pmd_set(pmd_t * pmdp, pte_t * ptep)
210024b246eSLinus Torvalds { pmd_val(*pmdp) = _PAGE_TABLE | ((((unsigned long) ptep) - PAGE_OFFSET) << (32-PAGE_SHIFT)); }
211024b246eSLinus Torvalds 
pud_set(pud_t * pudp,pmd_t * pmdp)212a73c9489SMike Rapoport extern inline void pud_set(pud_t * pudp, pmd_t * pmdp)
213a73c9489SMike Rapoport { pud_val(*pudp) = _PAGE_TABLE | ((((unsigned long) pmdp) - PAGE_OFFSET) << (32-PAGE_SHIFT)); }
214024b246eSLinus Torvalds 
215024b246eSLinus Torvalds 
216024b246eSLinus Torvalds extern inline unsigned long
pmd_page_vaddr(pmd_t pmd)217024b246eSLinus Torvalds pmd_page_vaddr(pmd_t pmd)
218024b246eSLinus Torvalds {
219024b246eSLinus Torvalds 	return ((pmd_val(pmd) & _PFN_MASK) >> (32-PAGE_SHIFT)) + PAGE_OFFSET;
220024b246eSLinus Torvalds }
221024b246eSLinus Torvalds 
2227106c51eSMike Rapoport #define pmd_pfn(pmd)	(pmd_val(pmd) >> 32)
22336d40290SMike Rapoport #define pmd_page(pmd)	(pfn_to_page(pmd_val(pmd) >> 32))
22436d40290SMike Rapoport #define pud_page(pud)	(pfn_to_page(pud_val(pud) >> 32))
225024b246eSLinus Torvalds 
pud_pgtable(pud_t pgd)2269cf6fa24SAneesh Kumar K.V extern inline pmd_t *pud_pgtable(pud_t pgd)
2279cf6fa24SAneesh Kumar K.V {
2289cf6fa24SAneesh Kumar K.V 	return (pmd_t *)(PAGE_OFFSET + ((pud_val(pgd) & _PFN_MASK) >> (32-PAGE_SHIFT)));
2299cf6fa24SAneesh Kumar K.V }
230024b246eSLinus Torvalds 
pte_none(pte_t pte)231024b246eSLinus Torvalds extern inline int pte_none(pte_t pte)		{ return !pte_val(pte); }
pte_present(pte_t pte)232024b246eSLinus Torvalds extern inline int pte_present(pte_t pte)	{ return pte_val(pte) & _PAGE_VALID; }
pte_clear(struct mm_struct * mm,unsigned long addr,pte_t * ptep)233024b246eSLinus Torvalds extern inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
234024b246eSLinus Torvalds {
235024b246eSLinus Torvalds 	pte_val(*ptep) = 0;
236024b246eSLinus Torvalds }
237024b246eSLinus Torvalds 
pmd_none(pmd_t pmd)238024b246eSLinus Torvalds extern inline int pmd_none(pmd_t pmd)		{ return !pmd_val(pmd); }
pmd_bad(pmd_t pmd)239024b246eSLinus Torvalds extern inline int pmd_bad(pmd_t pmd)		{ return (pmd_val(pmd) & ~_PFN_MASK) != _PAGE_TABLE; }
pmd_present(pmd_t pmd)240024b246eSLinus Torvalds extern inline int pmd_present(pmd_t pmd)	{ return pmd_val(pmd) & _PAGE_VALID; }
pmd_clear(pmd_t * pmdp)241024b246eSLinus Torvalds extern inline void pmd_clear(pmd_t * pmdp)	{ pmd_val(*pmdp) = 0; }
242024b246eSLinus Torvalds 
pud_none(pud_t pud)243a73c9489SMike Rapoport extern inline int pud_none(pud_t pud)		{ return !pud_val(pud); }
pud_bad(pud_t pud)244a73c9489SMike Rapoport extern inline int pud_bad(pud_t pud)		{ return (pud_val(pud) & ~_PFN_MASK) != _PAGE_TABLE; }
pud_present(pud_t pud)245a73c9489SMike Rapoport extern inline int pud_present(pud_t pud)	{ return pud_val(pud) & _PAGE_VALID; }
pud_clear(pud_t * pudp)246a73c9489SMike Rapoport extern inline void pud_clear(pud_t * pudp)	{ pud_val(*pudp) = 0; }
247024b246eSLinus Torvalds 
248024b246eSLinus Torvalds /*
249024b246eSLinus Torvalds  * The following only work if pte_present() is true.
250024b246eSLinus Torvalds  * Undefined behaviour if not..
251024b246eSLinus Torvalds  */
pte_write(pte_t pte)252024b246eSLinus Torvalds extern inline int pte_write(pte_t pte)		{ return !(pte_val(pte) & _PAGE_FOW); }
pte_dirty(pte_t pte)253024b246eSLinus Torvalds extern inline int pte_dirty(pte_t pte)		{ return pte_val(pte) & _PAGE_DIRTY; }
pte_young(pte_t pte)254024b246eSLinus Torvalds extern inline int pte_young(pte_t pte)		{ return pte_val(pte) & _PAGE_ACCESSED; }
255024b246eSLinus Torvalds 
pte_wrprotect(pte_t pte)256024b246eSLinus Torvalds extern inline pte_t pte_wrprotect(pte_t pte)	{ pte_val(pte) |= _PAGE_FOW; return pte; }
pte_mkclean(pte_t pte)257024b246eSLinus Torvalds extern inline pte_t pte_mkclean(pte_t pte)	{ pte_val(pte) &= ~(__DIRTY_BITS); return pte; }
pte_mkold(pte_t pte)258024b246eSLinus Torvalds extern inline pte_t pte_mkold(pte_t pte)	{ pte_val(pte) &= ~(__ACCESS_BITS); return pte; }
pte_mkwrite_novma(pte_t pte)259024b246eSLinus Torvalds extern inline pte_t pte_mkwrite_novma(pte_t pte){ pte_val(pte) &= ~_PAGE_FOW; return pte; }
pte_mkdirty(pte_t pte)260024b246eSLinus Torvalds extern inline pte_t pte_mkdirty(pte_t pte)	{ pte_val(pte) |= __DIRTY_BITS; return pte; }
pte_mkyoung(pte_t pte)261024b246eSLinus Torvalds extern inline pte_t pte_mkyoung(pte_t pte)	{ pte_val(pte) |= __ACCESS_BITS; return pte; }
262024b246eSLinus Torvalds 
263024b246eSLinus Torvalds /*
264bb7cdd38SWill Deacon  * The smp_rmb() in the following functions are required to order the load of
265bb7cdd38SWill Deacon  * *dir (the pointer in the top level page table) with any subsequent load of
266bb7cdd38SWill Deacon  * the returned pmd_t *ret (ret is data dependent on *dir).
267024b246eSLinus Torvalds  *
268024b246eSLinus Torvalds  * If this ordering is not enforced, the CPU might load an older value of
269024b246eSLinus Torvalds  * *ret, which may be uninitialized data. See mm/memory.c:__pte_alloc for
270024b246eSLinus Torvalds  * more details.
271024b246eSLinus Torvalds  *
272024b246eSLinus Torvalds  * Note that we never change the mm->pgd pointer after the task is running, so
273024b246eSLinus Torvalds  * pgd_offset does not require such a barrier.
274024b246eSLinus Torvalds  */
275024b246eSLinus Torvalds 
276024b246eSLinus Torvalds /* Find an entry in the second-level page table.. */
pmd_offset(pud_t * dir,unsigned long address)277a73c9489SMike Rapoport extern inline pmd_t * pmd_offset(pud_t * dir, unsigned long address)
278024b246eSLinus Torvalds {
2799cf6fa24SAneesh Kumar K.V 	pmd_t *ret = pud_pgtable(*dir) + ((address >> PMD_SHIFT) & (PTRS_PER_PAGE - 1));
280bb7cdd38SWill Deacon 	smp_rmb(); /* see above */
281024b246eSLinus Torvalds 	return ret;
282024b246eSLinus Torvalds }
283974b9b2cSMike Rapoport #define pmd_offset pmd_offset
284024b246eSLinus Torvalds 
285024b246eSLinus Torvalds /* Find an entry in the third-level page table.. */
pte_offset_kernel(pmd_t * dir,unsigned long address)286024b246eSLinus Torvalds extern inline pte_t * pte_offset_kernel(pmd_t * dir, unsigned long address)
287024b246eSLinus Torvalds {
288024b246eSLinus Torvalds 	pte_t *ret = (pte_t *) pmd_page_vaddr(*dir)
289024b246eSLinus Torvalds 		+ ((address >> PAGE_SHIFT) & (PTRS_PER_PAGE - 1));
290bb7cdd38SWill Deacon 	smp_rmb(); /* see above */
291024b246eSLinus Torvalds 	return ret;
292024b246eSLinus Torvalds }
293974b9b2cSMike Rapoport #define pte_offset_kernel pte_offset_kernel
294024b246eSLinus Torvalds 
295024b246eSLinus Torvalds extern pgd_t swapper_pg_dir[1024];
296024b246eSLinus Torvalds 
297024b246eSLinus Torvalds /*
298024b246eSLinus Torvalds  * The Alpha doesn't have any external MMU info:  the kernel page
299024b246eSLinus Torvalds  * tables contain all the necessary information.
300024b246eSLinus Torvalds  */
update_mmu_cache(struct vm_area_struct * vma,unsigned long address,pte_t * ptep)301024b246eSLinus Torvalds extern inline void update_mmu_cache(struct vm_area_struct * vma,
3024b3073e1SRussell King 	unsigned long address, pte_t *ptep)
303024b246eSLinus Torvalds {
304024b246eSLinus Torvalds }
305024b246eSLinus Torvalds 
update_mmu_cache_range(struct vm_fault * vmf,struct vm_area_struct * vma,unsigned long address,pte_t * ptep,unsigned int nr)306*63497b71SMatthew Wilcox (Oracle) static inline void update_mmu_cache_range(struct vm_fault *vmf,
307*63497b71SMatthew Wilcox (Oracle) 		struct vm_area_struct *vma, unsigned long address,
308*63497b71SMatthew Wilcox (Oracle) 		pte_t *ptep, unsigned int nr)
309*63497b71SMatthew Wilcox (Oracle) {
310*63497b71SMatthew Wilcox (Oracle) }
311*63497b71SMatthew Wilcox (Oracle) 
312024b246eSLinus Torvalds /*
313a172d512SDavid Hildenbrand  * Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that
314a172d512SDavid Hildenbrand  * are !pte_none() && !pte_present().
315a172d512SDavid Hildenbrand  *
316a172d512SDavid Hildenbrand  * Format of swap PTEs:
317a172d512SDavid Hildenbrand  *
318a172d512SDavid Hildenbrand  *   6 6 6 6 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3
319a172d512SDavid Hildenbrand  *   3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2
320a172d512SDavid Hildenbrand  *   <------------------- offset ------------------> E <--- type -->
321a172d512SDavid Hildenbrand  *
322a172d512SDavid Hildenbrand  *   3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
323a172d512SDavid Hildenbrand  *   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
324a172d512SDavid Hildenbrand  *   <--------------------------- zeroes -------------------------->
325a172d512SDavid Hildenbrand  *
326a172d512SDavid Hildenbrand  *   E is the exclusive marker that is not stored in swap entries.
327024b246eSLinus Torvalds  */
mk_swap_pte(unsigned long type,unsigned long offset)328024b246eSLinus Torvalds extern inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
329a172d512SDavid Hildenbrand { pte_t pte; pte_val(pte) = ((type & 0x7f) << 32) | (offset << 40); return pte; }
330024b246eSLinus Torvalds 
331a172d512SDavid Hildenbrand #define __swp_type(x)		(((x).val >> 32) & 0x7f)
332024b246eSLinus Torvalds #define __swp_offset(x)		((x).val >> 40)
333024b246eSLinus Torvalds #define __swp_entry(type, off)	((swp_entry_t) { pte_val(mk_swap_pte((type), (off))) })
334024b246eSLinus Torvalds #define __pte_to_swp_entry(pte)	((swp_entry_t) { pte_val(pte) })
335024b246eSLinus Torvalds #define __swp_entry_to_pte(x)	((pte_t) { (x).val })
336024b246eSLinus Torvalds 
pte_swp_exclusive(pte_t pte)337a172d512SDavid Hildenbrand static inline int pte_swp_exclusive(pte_t pte)
338a172d512SDavid Hildenbrand {
339a172d512SDavid Hildenbrand 	return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
340a172d512SDavid Hildenbrand }
341a172d512SDavid Hildenbrand 
pte_swp_mkexclusive(pte_t pte)342a172d512SDavid Hildenbrand static inline pte_t pte_swp_mkexclusive(pte_t pte)
343a172d512SDavid Hildenbrand {
344a172d512SDavid Hildenbrand 	pte_val(pte) |= _PAGE_SWP_EXCLUSIVE;
345a172d512SDavid Hildenbrand 	return pte;
346a172d512SDavid Hildenbrand }
347a172d512SDavid Hildenbrand 
pte_swp_clear_exclusive(pte_t pte)348a172d512SDavid Hildenbrand static inline pte_t pte_swp_clear_exclusive(pte_t pte)
349a172d512SDavid Hildenbrand {
350a172d512SDavid Hildenbrand 	pte_val(pte) &= ~_PAGE_SWP_EXCLUSIVE;
351a172d512SDavid Hildenbrand 	return pte;
352a172d512SDavid Hildenbrand }
353a172d512SDavid Hildenbrand 
354024b246eSLinus Torvalds #define pte_ERROR(e) \
355024b246eSLinus Torvalds 	printk("%s:%d: bad pte %016lx.\n", __FILE__, __LINE__, pte_val(e))
356024b246eSLinus Torvalds #define pmd_ERROR(e) \
357024b246eSLinus Torvalds 	printk("%s:%d: bad pmd %016lx.\n", __FILE__, __LINE__, pmd_val(e))
358024b246eSLinus Torvalds #define pgd_ERROR(e) \
359024b246eSLinus Torvalds 	printk("%s:%d: bad pgd %016lx.\n", __FILE__, __LINE__, pgd_val(e))
360024b246eSLinus Torvalds 
361024b246eSLinus Torvalds extern void paging_init(void);
362024b246eSLinus Torvalds 
363024b246eSLinus Torvalds /* We have our own get_unmapped_area to cope with ADDR_LIMIT_32BIT.  */
364024b246eSLinus Torvalds #define HAVE_ARCH_UNMAPPED_AREA
365024b246eSLinus Torvalds 
366024b246eSLinus Torvalds #endif /* _ALPHA_PGTABLE_H */
367