xref: /OK3568_Linux_fs/kernel/arch/alpha/include/asm/pgtable.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _ALPHA_PGTABLE_H
3*4882a593Smuzhiyun #define _ALPHA_PGTABLE_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun #include <asm-generic/pgtable-nopud.h>
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun /*
8*4882a593Smuzhiyun  * This file contains the functions and defines necessary to modify and use
9*4882a593Smuzhiyun  * the Alpha page table tree.
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * This hopefully works with any standard Alpha page-size, as defined
12*4882a593Smuzhiyun  * in <asm/page.h> (currently 8192).
13*4882a593Smuzhiyun  */
14*4882a593Smuzhiyun #include <linux/mmzone.h>
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #include <asm/page.h>
17*4882a593Smuzhiyun #include <asm/processor.h>	/* For TASK_SIZE */
18*4882a593Smuzhiyun #include <asm/machvec.h>
19*4882a593Smuzhiyun #include <asm/setup.h>
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun struct mm_struct;
22*4882a593Smuzhiyun struct vm_area_struct;
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun /* Certain architectures need to do special things when PTEs
25*4882a593Smuzhiyun  * within a page table are directly modified.  Thus, the following
26*4882a593Smuzhiyun  * hook is made available.
27*4882a593Smuzhiyun  */
28*4882a593Smuzhiyun #define set_pte(pteptr, pteval) ((*(pteptr)) = (pteval))
29*4882a593Smuzhiyun #define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun /* PMD_SHIFT determines the size of the area a second-level page table can map */
32*4882a593Smuzhiyun #define PMD_SHIFT	(PAGE_SHIFT + (PAGE_SHIFT-3))
33*4882a593Smuzhiyun #define PMD_SIZE	(1UL << PMD_SHIFT)
34*4882a593Smuzhiyun #define PMD_MASK	(~(PMD_SIZE-1))
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun /* PGDIR_SHIFT determines what a third-level page table entry can map */
37*4882a593Smuzhiyun #define PGDIR_SHIFT	(PAGE_SHIFT + 2*(PAGE_SHIFT-3))
38*4882a593Smuzhiyun #define PGDIR_SIZE	(1UL << PGDIR_SHIFT)
39*4882a593Smuzhiyun #define PGDIR_MASK	(~(PGDIR_SIZE-1))
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun /*
42*4882a593Smuzhiyun  * Entries per page directory level:  the Alpha is three-level, with
43*4882a593Smuzhiyun  * all levels having a one-page page table.
44*4882a593Smuzhiyun  */
45*4882a593Smuzhiyun #define PTRS_PER_PTE	(1UL << (PAGE_SHIFT-3))
46*4882a593Smuzhiyun #define PTRS_PER_PMD	(1UL << (PAGE_SHIFT-3))
47*4882a593Smuzhiyun #define PTRS_PER_PGD	(1UL << (PAGE_SHIFT-3))
48*4882a593Smuzhiyun #define USER_PTRS_PER_PGD	(TASK_SIZE / PGDIR_SIZE)
49*4882a593Smuzhiyun #define FIRST_USER_ADDRESS	0UL
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun /* Number of pointers that fit on a page:  this will go away. */
52*4882a593Smuzhiyun #define PTRS_PER_PAGE	(1UL << (PAGE_SHIFT-3))
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun #ifdef CONFIG_ALPHA_LARGE_VMALLOC
55*4882a593Smuzhiyun #define VMALLOC_START		0xfffffe0000000000
56*4882a593Smuzhiyun #else
57*4882a593Smuzhiyun #define VMALLOC_START		(-2*PGDIR_SIZE)
58*4882a593Smuzhiyun #endif
59*4882a593Smuzhiyun #define VMALLOC_END		(-PGDIR_SIZE)
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun /*
62*4882a593Smuzhiyun  * OSF/1 PAL-code-imposed page table bits
63*4882a593Smuzhiyun  */
64*4882a593Smuzhiyun #define _PAGE_VALID	0x0001
65*4882a593Smuzhiyun #define _PAGE_FOR	0x0002	/* used for page protection (fault on read) */
66*4882a593Smuzhiyun #define _PAGE_FOW	0x0004	/* used for page protection (fault on write) */
67*4882a593Smuzhiyun #define _PAGE_FOE	0x0008	/* used for page protection (fault on exec) */
68*4882a593Smuzhiyun #define _PAGE_ASM	0x0010
69*4882a593Smuzhiyun #define _PAGE_KRE	0x0100	/* xxx - see below on the "accessed" bit */
70*4882a593Smuzhiyun #define _PAGE_URE	0x0200	/* xxx */
71*4882a593Smuzhiyun #define _PAGE_KWE	0x1000	/* used to do the dirty bit in software */
72*4882a593Smuzhiyun #define _PAGE_UWE	0x2000	/* used to do the dirty bit in software */
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun /* .. and these are ours ... */
75*4882a593Smuzhiyun #define _PAGE_DIRTY	0x20000
76*4882a593Smuzhiyun #define _PAGE_ACCESSED	0x40000
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun /*
79*4882a593Smuzhiyun  * NOTE! The "accessed" bit isn't necessarily exact:  it can be kept exactly
80*4882a593Smuzhiyun  * by software (use the KRE/URE/KWE/UWE bits appropriately), but I'll fake it.
81*4882a593Smuzhiyun  * Under Linux/AXP, the "accessed" bit just means "read", and I'll just use
82*4882a593Smuzhiyun  * the KRE/URE bits to watch for it. That way we don't need to overload the
83*4882a593Smuzhiyun  * KWE/UWE bits with both handling dirty and accessed.
84*4882a593Smuzhiyun  *
85*4882a593Smuzhiyun  * Note that the kernel uses the accessed bit just to check whether to page
86*4882a593Smuzhiyun  * out a page or not, so it doesn't have to be exact anyway.
87*4882a593Smuzhiyun  */
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun #define __DIRTY_BITS	(_PAGE_DIRTY | _PAGE_KWE | _PAGE_UWE)
90*4882a593Smuzhiyun #define __ACCESS_BITS	(_PAGE_ACCESSED | _PAGE_KRE | _PAGE_URE)
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun #define _PFN_MASK	0xFFFFFFFF00000000UL
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun #define _PAGE_TABLE	(_PAGE_VALID | __DIRTY_BITS | __ACCESS_BITS)
95*4882a593Smuzhiyun #define _PAGE_CHG_MASK	(_PFN_MASK | __DIRTY_BITS | __ACCESS_BITS)
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun /*
98*4882a593Smuzhiyun  * All the normal masks have the "page accessed" bits on, as any time they are used,
99*4882a593Smuzhiyun  * the page is accessed. They are cleared only by the page-out routines
100*4882a593Smuzhiyun  */
101*4882a593Smuzhiyun #define PAGE_NONE	__pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOR | _PAGE_FOW | _PAGE_FOE)
102*4882a593Smuzhiyun #define PAGE_SHARED	__pgprot(_PAGE_VALID | __ACCESS_BITS)
103*4882a593Smuzhiyun #define PAGE_COPY	__pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
104*4882a593Smuzhiyun #define PAGE_READONLY	__pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
105*4882a593Smuzhiyun #define PAGE_KERNEL	__pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun #define _PAGE_P(x) _PAGE_NORMAL((x) | (((x) & _PAGE_FOW)?0:_PAGE_FOW))
110*4882a593Smuzhiyun #define _PAGE_S(x) _PAGE_NORMAL(x)
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun /*
113*4882a593Smuzhiyun  * The hardware can handle write-only mappings, but as the Alpha
114*4882a593Smuzhiyun  * architecture does byte-wide writes with a read-modify-write
115*4882a593Smuzhiyun  * sequence, it's not practical to have write-without-read privs.
116*4882a593Smuzhiyun  * Thus the "-w- -> rw-" and "-wx -> rwx" mapping here (and in
117*4882a593Smuzhiyun  * arch/alpha/mm/fault.c)
118*4882a593Smuzhiyun  */
119*4882a593Smuzhiyun 	/* xwr */
120*4882a593Smuzhiyun #define __P000	_PAGE_P(_PAGE_FOE | _PAGE_FOW | _PAGE_FOR)
121*4882a593Smuzhiyun #define __P001	_PAGE_P(_PAGE_FOE | _PAGE_FOW)
122*4882a593Smuzhiyun #define __P010	_PAGE_P(_PAGE_FOE)
123*4882a593Smuzhiyun #define __P011	_PAGE_P(_PAGE_FOE)
124*4882a593Smuzhiyun #define __P100	_PAGE_P(_PAGE_FOW | _PAGE_FOR)
125*4882a593Smuzhiyun #define __P101	_PAGE_P(_PAGE_FOW)
126*4882a593Smuzhiyun #define __P110	_PAGE_P(0)
127*4882a593Smuzhiyun #define __P111	_PAGE_P(0)
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun #define __S000	_PAGE_S(_PAGE_FOE | _PAGE_FOW | _PAGE_FOR)
130*4882a593Smuzhiyun #define __S001	_PAGE_S(_PAGE_FOE | _PAGE_FOW)
131*4882a593Smuzhiyun #define __S010	_PAGE_S(_PAGE_FOE)
132*4882a593Smuzhiyun #define __S011	_PAGE_S(_PAGE_FOE)
133*4882a593Smuzhiyun #define __S100	_PAGE_S(_PAGE_FOW | _PAGE_FOR)
134*4882a593Smuzhiyun #define __S101	_PAGE_S(_PAGE_FOW)
135*4882a593Smuzhiyun #define __S110	_PAGE_S(0)
136*4882a593Smuzhiyun #define __S111	_PAGE_S(0)
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun /*
139*4882a593Smuzhiyun  * pgprot_noncached() is only for infiniband pci support, and a real
140*4882a593Smuzhiyun  * implementation for RAM would be more complicated.
141*4882a593Smuzhiyun  */
142*4882a593Smuzhiyun #define pgprot_noncached(prot)	(prot)
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun /*
145*4882a593Smuzhiyun  * BAD_PAGETABLE is used when we need a bogus page-table, while
146*4882a593Smuzhiyun  * BAD_PAGE is used for a bogus page.
147*4882a593Smuzhiyun  *
148*4882a593Smuzhiyun  * ZERO_PAGE is a global shared page that is always zero:  used
149*4882a593Smuzhiyun  * for zero-mapped memory areas etc..
150*4882a593Smuzhiyun  */
151*4882a593Smuzhiyun extern pte_t __bad_page(void);
152*4882a593Smuzhiyun extern pmd_t * __bad_pagetable(void);
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun extern unsigned long __zero_page(void);
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun #define BAD_PAGETABLE	__bad_pagetable()
157*4882a593Smuzhiyun #define BAD_PAGE	__bad_page()
158*4882a593Smuzhiyun #define ZERO_PAGE(vaddr)	(virt_to_page(ZERO_PGE))
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun /* number of bits that fit into a memory pointer */
161*4882a593Smuzhiyun #define BITS_PER_PTR			(8*sizeof(unsigned long))
162*4882a593Smuzhiyun 
163*4882a593Smuzhiyun /* to align the pointer to a pointer address */
164*4882a593Smuzhiyun #define PTR_MASK			(~(sizeof(void*)-1))
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun /* sizeof(void*)==1<<SIZEOF_PTR_LOG2 */
167*4882a593Smuzhiyun #define SIZEOF_PTR_LOG2			3
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun /* to find an entry in a page-table */
170*4882a593Smuzhiyun #define PAGE_PTR(address)		\
171*4882a593Smuzhiyun   ((unsigned long)(address)>>(PAGE_SHIFT-SIZEOF_PTR_LOG2)&PTR_MASK&~PAGE_MASK)
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun /*
174*4882a593Smuzhiyun  * On certain platforms whose physical address space can overlap KSEG,
175*4882a593Smuzhiyun  * namely EV6 and above, we must re-twiddle the physaddr to restore the
176*4882a593Smuzhiyun  * correct high-order bits.
177*4882a593Smuzhiyun  *
178*4882a593Smuzhiyun  * This is extremely confusing until you realize that this is actually
179*4882a593Smuzhiyun  * just working around a userspace bug.  The X server was intending to
180*4882a593Smuzhiyun  * provide the physical address but instead provided the KSEG address.
181*4882a593Smuzhiyun  * Or tried to, except it's not representable.
182*4882a593Smuzhiyun  *
183*4882a593Smuzhiyun  * On Tsunami there's nothing meaningful at 0x40000000000, so this is
184*4882a593Smuzhiyun  * a safe thing to do.  Come the first core logic that does put something
185*4882a593Smuzhiyun  * in this area -- memory or whathaveyou -- then this hack will have
186*4882a593Smuzhiyun  * to go away.  So be prepared!
187*4882a593Smuzhiyun  */
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun #if defined(CONFIG_ALPHA_GENERIC) && defined(USE_48_BIT_KSEG)
190*4882a593Smuzhiyun #error "EV6-only feature in a generic kernel"
191*4882a593Smuzhiyun #endif
192*4882a593Smuzhiyun #if defined(CONFIG_ALPHA_GENERIC) || \
193*4882a593Smuzhiyun     (defined(CONFIG_ALPHA_EV6) && !defined(USE_48_BIT_KSEG))
194*4882a593Smuzhiyun #define KSEG_PFN	(0xc0000000000UL >> PAGE_SHIFT)
195*4882a593Smuzhiyun #define PHYS_TWIDDLE(pfn) \
196*4882a593Smuzhiyun   ((((pfn) & KSEG_PFN) == (0x40000000000UL >> PAGE_SHIFT)) \
197*4882a593Smuzhiyun   ? ((pfn) ^= KSEG_PFN) : (pfn))
198*4882a593Smuzhiyun #else
199*4882a593Smuzhiyun #define PHYS_TWIDDLE(pfn) (pfn)
200*4882a593Smuzhiyun #endif
201*4882a593Smuzhiyun 
202*4882a593Smuzhiyun /*
203*4882a593Smuzhiyun  * Conversion functions:  convert a page and protection to a page entry,
204*4882a593Smuzhiyun  * and a page entry and page directory to the page they refer to.
205*4882a593Smuzhiyun  */
206*4882a593Smuzhiyun #ifndef CONFIG_DISCONTIGMEM
207*4882a593Smuzhiyun #define page_to_pa(page)	(((page) - mem_map) << PAGE_SHIFT)
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun #define pte_pfn(pte)	(pte_val(pte) >> 32)
210*4882a593Smuzhiyun #define pte_page(pte)	pfn_to_page(pte_pfn(pte))
211*4882a593Smuzhiyun #define mk_pte(page, pgprot)						\
212*4882a593Smuzhiyun ({									\
213*4882a593Smuzhiyun 	pte_t pte;							\
214*4882a593Smuzhiyun 									\
215*4882a593Smuzhiyun 	pte_val(pte) = (page_to_pfn(page) << 32) | pgprot_val(pgprot);	\
216*4882a593Smuzhiyun 	pte;								\
217*4882a593Smuzhiyun })
218*4882a593Smuzhiyun #endif
219*4882a593Smuzhiyun 
pfn_pte(unsigned long physpfn,pgprot_t pgprot)220*4882a593Smuzhiyun extern inline pte_t pfn_pte(unsigned long physpfn, pgprot_t pgprot)
221*4882a593Smuzhiyun { pte_t pte; pte_val(pte) = (PHYS_TWIDDLE(physpfn) << 32) | pgprot_val(pgprot); return pte; }
222*4882a593Smuzhiyun 
pte_modify(pte_t pte,pgprot_t newprot)223*4882a593Smuzhiyun extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
224*4882a593Smuzhiyun { pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; }
225*4882a593Smuzhiyun 
pmd_set(pmd_t * pmdp,pte_t * ptep)226*4882a593Smuzhiyun extern inline void pmd_set(pmd_t * pmdp, pte_t * ptep)
227*4882a593Smuzhiyun { pmd_val(*pmdp) = _PAGE_TABLE | ((((unsigned long) ptep) - PAGE_OFFSET) << (32-PAGE_SHIFT)); }
228*4882a593Smuzhiyun 
pud_set(pud_t * pudp,pmd_t * pmdp)229*4882a593Smuzhiyun extern inline void pud_set(pud_t * pudp, pmd_t * pmdp)
230*4882a593Smuzhiyun { pud_val(*pudp) = _PAGE_TABLE | ((((unsigned long) pmdp) - PAGE_OFFSET) << (32-PAGE_SHIFT)); }
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun 
233*4882a593Smuzhiyun extern inline unsigned long
pmd_page_vaddr(pmd_t pmd)234*4882a593Smuzhiyun pmd_page_vaddr(pmd_t pmd)
235*4882a593Smuzhiyun {
236*4882a593Smuzhiyun 	return ((pmd_val(pmd) & _PFN_MASK) >> (32-PAGE_SHIFT)) + PAGE_OFFSET;
237*4882a593Smuzhiyun }
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun #ifndef CONFIG_DISCONTIGMEM
240*4882a593Smuzhiyun #define pmd_page(pmd)	(mem_map + ((pmd_val(pmd) & _PFN_MASK) >> 32))
241*4882a593Smuzhiyun #define pud_page(pud)	(mem_map + ((pud_val(pud) & _PFN_MASK) >> 32))
242*4882a593Smuzhiyun #endif
243*4882a593Smuzhiyun 
pud_page_vaddr(pud_t pgd)244*4882a593Smuzhiyun extern inline unsigned long pud_page_vaddr(pud_t pgd)
245*4882a593Smuzhiyun { return PAGE_OFFSET + ((pud_val(pgd) & _PFN_MASK) >> (32-PAGE_SHIFT)); }
246*4882a593Smuzhiyun 
pte_none(pte_t pte)247*4882a593Smuzhiyun extern inline int pte_none(pte_t pte)		{ return !pte_val(pte); }
pte_present(pte_t pte)248*4882a593Smuzhiyun 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)249*4882a593Smuzhiyun extern inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
250*4882a593Smuzhiyun {
251*4882a593Smuzhiyun 	pte_val(*ptep) = 0;
252*4882a593Smuzhiyun }
253*4882a593Smuzhiyun 
pmd_none(pmd_t pmd)254*4882a593Smuzhiyun extern inline int pmd_none(pmd_t pmd)		{ return !pmd_val(pmd); }
pmd_bad(pmd_t pmd)255*4882a593Smuzhiyun extern inline int pmd_bad(pmd_t pmd)		{ return (pmd_val(pmd) & ~_PFN_MASK) != _PAGE_TABLE; }
pmd_present(pmd_t pmd)256*4882a593Smuzhiyun extern inline int pmd_present(pmd_t pmd)	{ return pmd_val(pmd) & _PAGE_VALID; }
pmd_clear(pmd_t * pmdp)257*4882a593Smuzhiyun extern inline void pmd_clear(pmd_t * pmdp)	{ pmd_val(*pmdp) = 0; }
258*4882a593Smuzhiyun 
pud_none(pud_t pud)259*4882a593Smuzhiyun extern inline int pud_none(pud_t pud)		{ return !pud_val(pud); }
pud_bad(pud_t pud)260*4882a593Smuzhiyun extern inline int pud_bad(pud_t pud)		{ return (pud_val(pud) & ~_PFN_MASK) != _PAGE_TABLE; }
pud_present(pud_t pud)261*4882a593Smuzhiyun extern inline int pud_present(pud_t pud)	{ return pud_val(pud) & _PAGE_VALID; }
pud_clear(pud_t * pudp)262*4882a593Smuzhiyun extern inline void pud_clear(pud_t * pudp)	{ pud_val(*pudp) = 0; }
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun /*
265*4882a593Smuzhiyun  * The following only work if pte_present() is true.
266*4882a593Smuzhiyun  * Undefined behaviour if not..
267*4882a593Smuzhiyun  */
pte_write(pte_t pte)268*4882a593Smuzhiyun extern inline int pte_write(pte_t pte)		{ return !(pte_val(pte) & _PAGE_FOW); }
pte_dirty(pte_t pte)269*4882a593Smuzhiyun extern inline int pte_dirty(pte_t pte)		{ return pte_val(pte) & _PAGE_DIRTY; }
pte_young(pte_t pte)270*4882a593Smuzhiyun extern inline int pte_young(pte_t pte)		{ return pte_val(pte) & _PAGE_ACCESSED; }
271*4882a593Smuzhiyun 
pte_wrprotect(pte_t pte)272*4882a593Smuzhiyun extern inline pte_t pte_wrprotect(pte_t pte)	{ pte_val(pte) |= _PAGE_FOW; return pte; }
pte_mkclean(pte_t pte)273*4882a593Smuzhiyun extern inline pte_t pte_mkclean(pte_t pte)	{ pte_val(pte) &= ~(__DIRTY_BITS); return pte; }
pte_mkold(pte_t pte)274*4882a593Smuzhiyun extern inline pte_t pte_mkold(pte_t pte)	{ pte_val(pte) &= ~(__ACCESS_BITS); return pte; }
pte_mkwrite(pte_t pte)275*4882a593Smuzhiyun extern inline pte_t pte_mkwrite(pte_t pte)	{ pte_val(pte) &= ~_PAGE_FOW; return pte; }
pte_mkdirty(pte_t pte)276*4882a593Smuzhiyun extern inline pte_t pte_mkdirty(pte_t pte)	{ pte_val(pte) |= __DIRTY_BITS; return pte; }
pte_mkyoung(pte_t pte)277*4882a593Smuzhiyun extern inline pte_t pte_mkyoung(pte_t pte)	{ pte_val(pte) |= __ACCESS_BITS; return pte; }
278*4882a593Smuzhiyun 
279*4882a593Smuzhiyun /*
280*4882a593Smuzhiyun  * The smp_rmb() in the following functions are required to order the load of
281*4882a593Smuzhiyun  * *dir (the pointer in the top level page table) with any subsequent load of
282*4882a593Smuzhiyun  * the returned pmd_t *ret (ret is data dependent on *dir).
283*4882a593Smuzhiyun  *
284*4882a593Smuzhiyun  * If this ordering is not enforced, the CPU might load an older value of
285*4882a593Smuzhiyun  * *ret, which may be uninitialized data. See mm/memory.c:__pte_alloc for
286*4882a593Smuzhiyun  * more details.
287*4882a593Smuzhiyun  *
288*4882a593Smuzhiyun  * Note that we never change the mm->pgd pointer after the task is running, so
289*4882a593Smuzhiyun  * pgd_offset does not require such a barrier.
290*4882a593Smuzhiyun  */
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun /* Find an entry in the second-level page table.. */
pmd_offset(pud_t * dir,unsigned long address)293*4882a593Smuzhiyun extern inline pmd_t * pmd_offset(pud_t * dir, unsigned long address)
294*4882a593Smuzhiyun {
295*4882a593Smuzhiyun 	pmd_t *ret = (pmd_t *) pud_page_vaddr(*dir) + ((address >> PMD_SHIFT) & (PTRS_PER_PAGE - 1));
296*4882a593Smuzhiyun 	smp_rmb(); /* see above */
297*4882a593Smuzhiyun 	return ret;
298*4882a593Smuzhiyun }
299*4882a593Smuzhiyun #define pmd_offset pmd_offset
300*4882a593Smuzhiyun 
301*4882a593Smuzhiyun /* Find an entry in the third-level page table.. */
pte_offset_kernel(pmd_t * dir,unsigned long address)302*4882a593Smuzhiyun extern inline pte_t * pte_offset_kernel(pmd_t * dir, unsigned long address)
303*4882a593Smuzhiyun {
304*4882a593Smuzhiyun 	pte_t *ret = (pte_t *) pmd_page_vaddr(*dir)
305*4882a593Smuzhiyun 		+ ((address >> PAGE_SHIFT) & (PTRS_PER_PAGE - 1));
306*4882a593Smuzhiyun 	smp_rmb(); /* see above */
307*4882a593Smuzhiyun 	return ret;
308*4882a593Smuzhiyun }
309*4882a593Smuzhiyun #define pte_offset_kernel pte_offset_kernel
310*4882a593Smuzhiyun 
311*4882a593Smuzhiyun extern pgd_t swapper_pg_dir[1024];
312*4882a593Smuzhiyun 
313*4882a593Smuzhiyun /*
314*4882a593Smuzhiyun  * The Alpha doesn't have any external MMU info:  the kernel page
315*4882a593Smuzhiyun  * tables contain all the necessary information.
316*4882a593Smuzhiyun  */
update_mmu_cache(struct vm_area_struct * vma,unsigned long address,pte_t * ptep)317*4882a593Smuzhiyun extern inline void update_mmu_cache(struct vm_area_struct * vma,
318*4882a593Smuzhiyun 	unsigned long address, pte_t *ptep)
319*4882a593Smuzhiyun {
320*4882a593Smuzhiyun }
321*4882a593Smuzhiyun 
322*4882a593Smuzhiyun /*
323*4882a593Smuzhiyun  * Non-present pages:  high 24 bits are offset, next 8 bits type,
324*4882a593Smuzhiyun  * low 32 bits zero.
325*4882a593Smuzhiyun  */
mk_swap_pte(unsigned long type,unsigned long offset)326*4882a593Smuzhiyun extern inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
327*4882a593Smuzhiyun { pte_t pte; pte_val(pte) = (type << 32) | (offset << 40); return pte; }
328*4882a593Smuzhiyun 
329*4882a593Smuzhiyun #define __swp_type(x)		(((x).val >> 32) & 0xff)
330*4882a593Smuzhiyun #define __swp_offset(x)		((x).val >> 40)
331*4882a593Smuzhiyun #define __swp_entry(type, off)	((swp_entry_t) { pte_val(mk_swap_pte((type), (off))) })
332*4882a593Smuzhiyun #define __pte_to_swp_entry(pte)	((swp_entry_t) { pte_val(pte) })
333*4882a593Smuzhiyun #define __swp_entry_to_pte(x)	((pte_t) { (x).val })
334*4882a593Smuzhiyun 
335*4882a593Smuzhiyun #ifndef CONFIG_DISCONTIGMEM
336*4882a593Smuzhiyun #define kern_addr_valid(addr)	(1)
337*4882a593Smuzhiyun #endif
338*4882a593Smuzhiyun 
339*4882a593Smuzhiyun #define pte_ERROR(e) \
340*4882a593Smuzhiyun 	printk("%s:%d: bad pte %016lx.\n", __FILE__, __LINE__, pte_val(e))
341*4882a593Smuzhiyun #define pmd_ERROR(e) \
342*4882a593Smuzhiyun 	printk("%s:%d: bad pmd %016lx.\n", __FILE__, __LINE__, pmd_val(e))
343*4882a593Smuzhiyun #define pgd_ERROR(e) \
344*4882a593Smuzhiyun 	printk("%s:%d: bad pgd %016lx.\n", __FILE__, __LINE__, pgd_val(e))
345*4882a593Smuzhiyun 
346*4882a593Smuzhiyun extern void paging_init(void);
347*4882a593Smuzhiyun 
348*4882a593Smuzhiyun /* We have our own get_unmapped_area to cope with ADDR_LIMIT_32BIT.  */
349*4882a593Smuzhiyun #define HAVE_ARCH_UNMAPPED_AREA
350*4882a593Smuzhiyun 
351*4882a593Smuzhiyun #endif /* _ALPHA_PGTABLE_H */
352