18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _ALPHA_PGTABLE_H
38c2ecf20Sopenharmony_ci#define _ALPHA_PGTABLE_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <asm-generic/pgtable-nopud.h>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci/*
88c2ecf20Sopenharmony_ci * This file contains the functions and defines necessary to modify and use
98c2ecf20Sopenharmony_ci * the Alpha page table tree.
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * This hopefully works with any standard Alpha page-size, as defined
128c2ecf20Sopenharmony_ci * in <asm/page.h> (currently 8192).
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_ci#include <linux/mmzone.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include <asm/page.h>
178c2ecf20Sopenharmony_ci#include <asm/processor.h>	/* For TASK_SIZE */
188c2ecf20Sopenharmony_ci#include <asm/machvec.h>
198c2ecf20Sopenharmony_ci#include <asm/setup.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistruct mm_struct;
228c2ecf20Sopenharmony_cistruct vm_area_struct;
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/* Certain architectures need to do special things when PTEs
258c2ecf20Sopenharmony_ci * within a page table are directly modified.  Thus, the following
268c2ecf20Sopenharmony_ci * hook is made available.
278c2ecf20Sopenharmony_ci */
288c2ecf20Sopenharmony_ci#define set_pte(pteptr, pteval) ((*(pteptr)) = (pteval))
298c2ecf20Sopenharmony_ci#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/* PMD_SHIFT determines the size of the area a second-level page table can map */
328c2ecf20Sopenharmony_ci#define PMD_SHIFT	(PAGE_SHIFT + (PAGE_SHIFT-3))
338c2ecf20Sopenharmony_ci#define PMD_SIZE	(1UL << PMD_SHIFT)
348c2ecf20Sopenharmony_ci#define PMD_MASK	(~(PMD_SIZE-1))
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/* PGDIR_SHIFT determines what a third-level page table entry can map */
378c2ecf20Sopenharmony_ci#define PGDIR_SHIFT	(PAGE_SHIFT + 2*(PAGE_SHIFT-3))
388c2ecf20Sopenharmony_ci#define PGDIR_SIZE	(1UL << PGDIR_SHIFT)
398c2ecf20Sopenharmony_ci#define PGDIR_MASK	(~(PGDIR_SIZE-1))
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/*
428c2ecf20Sopenharmony_ci * Entries per page directory level:  the Alpha is three-level, with
438c2ecf20Sopenharmony_ci * all levels having a one-page page table.
448c2ecf20Sopenharmony_ci */
458c2ecf20Sopenharmony_ci#define PTRS_PER_PTE	(1UL << (PAGE_SHIFT-3))
468c2ecf20Sopenharmony_ci#define PTRS_PER_PMD	(1UL << (PAGE_SHIFT-3))
478c2ecf20Sopenharmony_ci#define PTRS_PER_PGD	(1UL << (PAGE_SHIFT-3))
488c2ecf20Sopenharmony_ci#define USER_PTRS_PER_PGD	(TASK_SIZE / PGDIR_SIZE)
498c2ecf20Sopenharmony_ci#define FIRST_USER_ADDRESS	0UL
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/* Number of pointers that fit on a page:  this will go away. */
528c2ecf20Sopenharmony_ci#define PTRS_PER_PAGE	(1UL << (PAGE_SHIFT-3))
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#ifdef CONFIG_ALPHA_LARGE_VMALLOC
558c2ecf20Sopenharmony_ci#define VMALLOC_START		0xfffffe0000000000
568c2ecf20Sopenharmony_ci#else
578c2ecf20Sopenharmony_ci#define VMALLOC_START		(-2*PGDIR_SIZE)
588c2ecf20Sopenharmony_ci#endif
598c2ecf20Sopenharmony_ci#define VMALLOC_END		(-PGDIR_SIZE)
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci/*
628c2ecf20Sopenharmony_ci * OSF/1 PAL-code-imposed page table bits
638c2ecf20Sopenharmony_ci */
648c2ecf20Sopenharmony_ci#define _PAGE_VALID	0x0001
658c2ecf20Sopenharmony_ci#define _PAGE_FOR	0x0002	/* used for page protection (fault on read) */
668c2ecf20Sopenharmony_ci#define _PAGE_FOW	0x0004	/* used for page protection (fault on write) */
678c2ecf20Sopenharmony_ci#define _PAGE_FOE	0x0008	/* used for page protection (fault on exec) */
688c2ecf20Sopenharmony_ci#define _PAGE_ASM	0x0010
698c2ecf20Sopenharmony_ci#define _PAGE_KRE	0x0100	/* xxx - see below on the "accessed" bit */
708c2ecf20Sopenharmony_ci#define _PAGE_URE	0x0200	/* xxx */
718c2ecf20Sopenharmony_ci#define _PAGE_KWE	0x1000	/* used to do the dirty bit in software */
728c2ecf20Sopenharmony_ci#define _PAGE_UWE	0x2000	/* used to do the dirty bit in software */
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/* .. and these are ours ... */
758c2ecf20Sopenharmony_ci#define _PAGE_DIRTY	0x20000
768c2ecf20Sopenharmony_ci#define _PAGE_ACCESSED	0x40000
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci/*
798c2ecf20Sopenharmony_ci * NOTE! The "accessed" bit isn't necessarily exact:  it can be kept exactly
808c2ecf20Sopenharmony_ci * by software (use the KRE/URE/KWE/UWE bits appropriately), but I'll fake it.
818c2ecf20Sopenharmony_ci * Under Linux/AXP, the "accessed" bit just means "read", and I'll just use
828c2ecf20Sopenharmony_ci * the KRE/URE bits to watch for it. That way we don't need to overload the
838c2ecf20Sopenharmony_ci * KWE/UWE bits with both handling dirty and accessed.
848c2ecf20Sopenharmony_ci *
858c2ecf20Sopenharmony_ci * Note that the kernel uses the accessed bit just to check whether to page
868c2ecf20Sopenharmony_ci * out a page or not, so it doesn't have to be exact anyway.
878c2ecf20Sopenharmony_ci */
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#define __DIRTY_BITS	(_PAGE_DIRTY | _PAGE_KWE | _PAGE_UWE)
908c2ecf20Sopenharmony_ci#define __ACCESS_BITS	(_PAGE_ACCESSED | _PAGE_KRE | _PAGE_URE)
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#define _PFN_MASK	0xFFFFFFFF00000000UL
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci#define _PAGE_TABLE	(_PAGE_VALID | __DIRTY_BITS | __ACCESS_BITS)
958c2ecf20Sopenharmony_ci#define _PAGE_CHG_MASK	(_PFN_MASK | __DIRTY_BITS | __ACCESS_BITS)
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci/*
988c2ecf20Sopenharmony_ci * All the normal masks have the "page accessed" bits on, as any time they are used,
998c2ecf20Sopenharmony_ci * the page is accessed. They are cleared only by the page-out routines
1008c2ecf20Sopenharmony_ci */
1018c2ecf20Sopenharmony_ci#define PAGE_NONE	__pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOR | _PAGE_FOW | _PAGE_FOE)
1028c2ecf20Sopenharmony_ci#define PAGE_SHARED	__pgprot(_PAGE_VALID | __ACCESS_BITS)
1038c2ecf20Sopenharmony_ci#define PAGE_COPY	__pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
1048c2ecf20Sopenharmony_ci#define PAGE_READONLY	__pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
1058c2ecf20Sopenharmony_ci#define PAGE_KERNEL	__pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci#define _PAGE_P(x) _PAGE_NORMAL((x) | (((x) & _PAGE_FOW)?0:_PAGE_FOW))
1108c2ecf20Sopenharmony_ci#define _PAGE_S(x) _PAGE_NORMAL(x)
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci/*
1138c2ecf20Sopenharmony_ci * The hardware can handle write-only mappings, but as the Alpha
1148c2ecf20Sopenharmony_ci * architecture does byte-wide writes with a read-modify-write
1158c2ecf20Sopenharmony_ci * sequence, it's not practical to have write-without-read privs.
1168c2ecf20Sopenharmony_ci * Thus the "-w- -> rw-" and "-wx -> rwx" mapping here (and in
1178c2ecf20Sopenharmony_ci * arch/alpha/mm/fault.c)
1188c2ecf20Sopenharmony_ci */
1198c2ecf20Sopenharmony_ci	/* xwr */
1208c2ecf20Sopenharmony_ci#define __P000	_PAGE_P(_PAGE_FOE | _PAGE_FOW | _PAGE_FOR)
1218c2ecf20Sopenharmony_ci#define __P001	_PAGE_P(_PAGE_FOE | _PAGE_FOW)
1228c2ecf20Sopenharmony_ci#define __P010	_PAGE_P(_PAGE_FOE)
1238c2ecf20Sopenharmony_ci#define __P011	_PAGE_P(_PAGE_FOE)
1248c2ecf20Sopenharmony_ci#define __P100	_PAGE_P(_PAGE_FOW | _PAGE_FOR)
1258c2ecf20Sopenharmony_ci#define __P101	_PAGE_P(_PAGE_FOW)
1268c2ecf20Sopenharmony_ci#define __P110	_PAGE_P(0)
1278c2ecf20Sopenharmony_ci#define __P111	_PAGE_P(0)
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci#define __S000	_PAGE_S(_PAGE_FOE | _PAGE_FOW | _PAGE_FOR)
1308c2ecf20Sopenharmony_ci#define __S001	_PAGE_S(_PAGE_FOE | _PAGE_FOW)
1318c2ecf20Sopenharmony_ci#define __S010	_PAGE_S(_PAGE_FOE)
1328c2ecf20Sopenharmony_ci#define __S011	_PAGE_S(_PAGE_FOE)
1338c2ecf20Sopenharmony_ci#define __S100	_PAGE_S(_PAGE_FOW | _PAGE_FOR)
1348c2ecf20Sopenharmony_ci#define __S101	_PAGE_S(_PAGE_FOW)
1358c2ecf20Sopenharmony_ci#define __S110	_PAGE_S(0)
1368c2ecf20Sopenharmony_ci#define __S111	_PAGE_S(0)
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci/*
1398c2ecf20Sopenharmony_ci * pgprot_noncached() is only for infiniband pci support, and a real
1408c2ecf20Sopenharmony_ci * implementation for RAM would be more complicated.
1418c2ecf20Sopenharmony_ci */
1428c2ecf20Sopenharmony_ci#define pgprot_noncached(prot)	(prot)
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci/*
1458c2ecf20Sopenharmony_ci * BAD_PAGETABLE is used when we need a bogus page-table, while
1468c2ecf20Sopenharmony_ci * BAD_PAGE is used for a bogus page.
1478c2ecf20Sopenharmony_ci *
1488c2ecf20Sopenharmony_ci * ZERO_PAGE is a global shared page that is always zero:  used
1498c2ecf20Sopenharmony_ci * for zero-mapped memory areas etc..
1508c2ecf20Sopenharmony_ci */
1518c2ecf20Sopenharmony_ciextern pte_t __bad_page(void);
1528c2ecf20Sopenharmony_ciextern pmd_t * __bad_pagetable(void);
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ciextern unsigned long __zero_page(void);
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci#define BAD_PAGETABLE	__bad_pagetable()
1578c2ecf20Sopenharmony_ci#define BAD_PAGE	__bad_page()
1588c2ecf20Sopenharmony_ci#define ZERO_PAGE(vaddr)	(virt_to_page(ZERO_PGE))
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci/* number of bits that fit into a memory pointer */
1618c2ecf20Sopenharmony_ci#define BITS_PER_PTR			(8*sizeof(unsigned long))
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci/* to align the pointer to a pointer address */
1648c2ecf20Sopenharmony_ci#define PTR_MASK			(~(sizeof(void*)-1))
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci/* sizeof(void*)==1<<SIZEOF_PTR_LOG2 */
1678c2ecf20Sopenharmony_ci#define SIZEOF_PTR_LOG2			3
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci/* to find an entry in a page-table */
1708c2ecf20Sopenharmony_ci#define PAGE_PTR(address)		\
1718c2ecf20Sopenharmony_ci  ((unsigned long)(address)>>(PAGE_SHIFT-SIZEOF_PTR_LOG2)&PTR_MASK&~PAGE_MASK)
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci/*
1748c2ecf20Sopenharmony_ci * On certain platforms whose physical address space can overlap KSEG,
1758c2ecf20Sopenharmony_ci * namely EV6 and above, we must re-twiddle the physaddr to restore the
1768c2ecf20Sopenharmony_ci * correct high-order bits.
1778c2ecf20Sopenharmony_ci *
1788c2ecf20Sopenharmony_ci * This is extremely confusing until you realize that this is actually
1798c2ecf20Sopenharmony_ci * just working around a userspace bug.  The X server was intending to
1808c2ecf20Sopenharmony_ci * provide the physical address but instead provided the KSEG address.
1818c2ecf20Sopenharmony_ci * Or tried to, except it's not representable.
1828c2ecf20Sopenharmony_ci *
1838c2ecf20Sopenharmony_ci * On Tsunami there's nothing meaningful at 0x40000000000, so this is
1848c2ecf20Sopenharmony_ci * a safe thing to do.  Come the first core logic that does put something
1858c2ecf20Sopenharmony_ci * in this area -- memory or whathaveyou -- then this hack will have
1868c2ecf20Sopenharmony_ci * to go away.  So be prepared!
1878c2ecf20Sopenharmony_ci */
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci#if defined(CONFIG_ALPHA_GENERIC) && defined(USE_48_BIT_KSEG)
1908c2ecf20Sopenharmony_ci#error "EV6-only feature in a generic kernel"
1918c2ecf20Sopenharmony_ci#endif
1928c2ecf20Sopenharmony_ci#if defined(CONFIG_ALPHA_GENERIC) || \
1938c2ecf20Sopenharmony_ci    (defined(CONFIG_ALPHA_EV6) && !defined(USE_48_BIT_KSEG))
1948c2ecf20Sopenharmony_ci#define KSEG_PFN	(0xc0000000000UL >> PAGE_SHIFT)
1958c2ecf20Sopenharmony_ci#define PHYS_TWIDDLE(pfn) \
1968c2ecf20Sopenharmony_ci  ((((pfn) & KSEG_PFN) == (0x40000000000UL >> PAGE_SHIFT)) \
1978c2ecf20Sopenharmony_ci  ? ((pfn) ^= KSEG_PFN) : (pfn))
1988c2ecf20Sopenharmony_ci#else
1998c2ecf20Sopenharmony_ci#define PHYS_TWIDDLE(pfn) (pfn)
2008c2ecf20Sopenharmony_ci#endif
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci/*
2038c2ecf20Sopenharmony_ci * Conversion functions:  convert a page and protection to a page entry,
2048c2ecf20Sopenharmony_ci * and a page entry and page directory to the page they refer to.
2058c2ecf20Sopenharmony_ci */
2068c2ecf20Sopenharmony_ci#ifndef CONFIG_DISCONTIGMEM
2078c2ecf20Sopenharmony_ci#define page_to_pa(page)	(((page) - mem_map) << PAGE_SHIFT)
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci#define pte_pfn(pte)	(pte_val(pte) >> 32)
2108c2ecf20Sopenharmony_ci#define pte_page(pte)	pfn_to_page(pte_pfn(pte))
2118c2ecf20Sopenharmony_ci#define mk_pte(page, pgprot)						\
2128c2ecf20Sopenharmony_ci({									\
2138c2ecf20Sopenharmony_ci	pte_t pte;							\
2148c2ecf20Sopenharmony_ci									\
2158c2ecf20Sopenharmony_ci	pte_val(pte) = (page_to_pfn(page) << 32) | pgprot_val(pgprot);	\
2168c2ecf20Sopenharmony_ci	pte;								\
2178c2ecf20Sopenharmony_ci})
2188c2ecf20Sopenharmony_ci#endif
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ciextern inline pte_t pfn_pte(unsigned long physpfn, pgprot_t pgprot)
2218c2ecf20Sopenharmony_ci{ pte_t pte; pte_val(pte) = (PHYS_TWIDDLE(physpfn) << 32) | pgprot_val(pgprot); return pte; }
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ciextern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2248c2ecf20Sopenharmony_ci{ pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; }
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ciextern inline void pmd_set(pmd_t * pmdp, pte_t * ptep)
2278c2ecf20Sopenharmony_ci{ pmd_val(*pmdp) = _PAGE_TABLE | ((((unsigned long) ptep) - PAGE_OFFSET) << (32-PAGE_SHIFT)); }
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ciextern inline void pud_set(pud_t * pudp, pmd_t * pmdp)
2308c2ecf20Sopenharmony_ci{ pud_val(*pudp) = _PAGE_TABLE | ((((unsigned long) pmdp) - PAGE_OFFSET) << (32-PAGE_SHIFT)); }
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ciextern inline unsigned long
2348c2ecf20Sopenharmony_cipmd_page_vaddr(pmd_t pmd)
2358c2ecf20Sopenharmony_ci{
2368c2ecf20Sopenharmony_ci	return ((pmd_val(pmd) & _PFN_MASK) >> (32-PAGE_SHIFT)) + PAGE_OFFSET;
2378c2ecf20Sopenharmony_ci}
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci#ifndef CONFIG_DISCONTIGMEM
2408c2ecf20Sopenharmony_ci#define pmd_page(pmd)	(mem_map + ((pmd_val(pmd) & _PFN_MASK) >> 32))
2418c2ecf20Sopenharmony_ci#define pud_page(pud)	(mem_map + ((pud_val(pud) & _PFN_MASK) >> 32))
2428c2ecf20Sopenharmony_ci#endif
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ciextern inline pmd_t *pud_pgtable(pud_t pgd)
2458c2ecf20Sopenharmony_ci{
2468c2ecf20Sopenharmony_ci	return (pmd_t *)(PAGE_OFFSET + ((pud_val(pgd) & _PFN_MASK) >> (32-PAGE_SHIFT)));
2478c2ecf20Sopenharmony_ci}
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ciextern inline int pte_none(pte_t pte)		{ return !pte_val(pte); }
2508c2ecf20Sopenharmony_ciextern inline int pte_present(pte_t pte)	{ return pte_val(pte) & _PAGE_VALID; }
2518c2ecf20Sopenharmony_ciextern inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
2528c2ecf20Sopenharmony_ci{
2538c2ecf20Sopenharmony_ci	pte_val(*ptep) = 0;
2548c2ecf20Sopenharmony_ci}
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ciextern inline int pmd_none(pmd_t pmd)		{ return !pmd_val(pmd); }
2578c2ecf20Sopenharmony_ciextern inline int pmd_bad(pmd_t pmd)		{ return (pmd_val(pmd) & ~_PFN_MASK) != _PAGE_TABLE; }
2588c2ecf20Sopenharmony_ciextern inline int pmd_present(pmd_t pmd)	{ return pmd_val(pmd) & _PAGE_VALID; }
2598c2ecf20Sopenharmony_ciextern inline void pmd_clear(pmd_t * pmdp)	{ pmd_val(*pmdp) = 0; }
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ciextern inline int pud_none(pud_t pud)		{ return !pud_val(pud); }
2628c2ecf20Sopenharmony_ciextern inline int pud_bad(pud_t pud)		{ return (pud_val(pud) & ~_PFN_MASK) != _PAGE_TABLE; }
2638c2ecf20Sopenharmony_ciextern inline int pud_present(pud_t pud)	{ return pud_val(pud) & _PAGE_VALID; }
2648c2ecf20Sopenharmony_ciextern inline void pud_clear(pud_t * pudp)	{ pud_val(*pudp) = 0; }
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ci/*
2678c2ecf20Sopenharmony_ci * The following only work if pte_present() is true.
2688c2ecf20Sopenharmony_ci * Undefined behaviour if not..
2698c2ecf20Sopenharmony_ci */
2708c2ecf20Sopenharmony_ciextern inline int pte_write(pte_t pte)		{ return !(pte_val(pte) & _PAGE_FOW); }
2718c2ecf20Sopenharmony_ciextern inline int pte_dirty(pte_t pte)		{ return pte_val(pte) & _PAGE_DIRTY; }
2728c2ecf20Sopenharmony_ciextern inline int pte_young(pte_t pte)		{ return pte_val(pte) & _PAGE_ACCESSED; }
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ciextern inline pte_t pte_wrprotect(pte_t pte)	{ pte_val(pte) |= _PAGE_FOW; return pte; }
2758c2ecf20Sopenharmony_ciextern inline pte_t pte_mkclean(pte_t pte)	{ pte_val(pte) &= ~(__DIRTY_BITS); return pte; }
2768c2ecf20Sopenharmony_ciextern inline pte_t pte_mkold(pte_t pte)	{ pte_val(pte) &= ~(__ACCESS_BITS); return pte; }
2778c2ecf20Sopenharmony_ciextern inline pte_t pte_mkwrite(pte_t pte)	{ pte_val(pte) &= ~_PAGE_FOW; return pte; }
2788c2ecf20Sopenharmony_ciextern inline pte_t pte_mkdirty(pte_t pte)	{ pte_val(pte) |= __DIRTY_BITS; return pte; }
2798c2ecf20Sopenharmony_ciextern inline pte_t pte_mkyoung(pte_t pte)	{ pte_val(pte) |= __ACCESS_BITS; return pte; }
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci/*
2828c2ecf20Sopenharmony_ci * The smp_rmb() in the following functions are required to order the load of
2838c2ecf20Sopenharmony_ci * *dir (the pointer in the top level page table) with any subsequent load of
2848c2ecf20Sopenharmony_ci * the returned pmd_t *ret (ret is data dependent on *dir).
2858c2ecf20Sopenharmony_ci *
2868c2ecf20Sopenharmony_ci * If this ordering is not enforced, the CPU might load an older value of
2878c2ecf20Sopenharmony_ci * *ret, which may be uninitialized data. See mm/memory.c:__pte_alloc for
2888c2ecf20Sopenharmony_ci * more details.
2898c2ecf20Sopenharmony_ci *
2908c2ecf20Sopenharmony_ci * Note that we never change the mm->pgd pointer after the task is running, so
2918c2ecf20Sopenharmony_ci * pgd_offset does not require such a barrier.
2928c2ecf20Sopenharmony_ci */
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci/* Find an entry in the second-level page table.. */
2958c2ecf20Sopenharmony_ciextern inline pmd_t * pmd_offset(pud_t * dir, unsigned long address)
2968c2ecf20Sopenharmony_ci{
2978c2ecf20Sopenharmony_ci	pmd_t *ret = pud_pgtable(*dir) + ((address >> PMD_SHIFT) & (PTRS_PER_PAGE - 1));
2988c2ecf20Sopenharmony_ci	smp_rmb(); /* see above */
2998c2ecf20Sopenharmony_ci	return ret;
3008c2ecf20Sopenharmony_ci}
3018c2ecf20Sopenharmony_ci#define pmd_offset pmd_offset
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci/* Find an entry in the third-level page table.. */
3048c2ecf20Sopenharmony_ciextern inline pte_t * pte_offset_kernel(pmd_t * dir, unsigned long address)
3058c2ecf20Sopenharmony_ci{
3068c2ecf20Sopenharmony_ci	pte_t *ret = (pte_t *) pmd_page_vaddr(*dir)
3078c2ecf20Sopenharmony_ci		+ ((address >> PAGE_SHIFT) & (PTRS_PER_PAGE - 1));
3088c2ecf20Sopenharmony_ci	smp_rmb(); /* see above */
3098c2ecf20Sopenharmony_ci	return ret;
3108c2ecf20Sopenharmony_ci}
3118c2ecf20Sopenharmony_ci#define pte_offset_kernel pte_offset_kernel
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ciextern pgd_t swapper_pg_dir[1024];
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci/*
3168c2ecf20Sopenharmony_ci * The Alpha doesn't have any external MMU info:  the kernel page
3178c2ecf20Sopenharmony_ci * tables contain all the necessary information.
3188c2ecf20Sopenharmony_ci */
3198c2ecf20Sopenharmony_ciextern inline void update_mmu_cache(struct vm_area_struct * vma,
3208c2ecf20Sopenharmony_ci	unsigned long address, pte_t *ptep)
3218c2ecf20Sopenharmony_ci{
3228c2ecf20Sopenharmony_ci}
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ci/*
3258c2ecf20Sopenharmony_ci * Non-present pages:  high 24 bits are offset, next 8 bits type,
3268c2ecf20Sopenharmony_ci * low 32 bits zero.
3278c2ecf20Sopenharmony_ci */
3288c2ecf20Sopenharmony_ciextern inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
3298c2ecf20Sopenharmony_ci{ pte_t pte; pte_val(pte) = (type << 32) | (offset << 40); return pte; }
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_ci#define __swp_type(x)		(((x).val >> 32) & 0xff)
3328c2ecf20Sopenharmony_ci#define __swp_offset(x)		((x).val >> 40)
3338c2ecf20Sopenharmony_ci#define __swp_entry(type, off)	((swp_entry_t) { pte_val(mk_swap_pte((type), (off))) })
3348c2ecf20Sopenharmony_ci#define __pte_to_swp_entry(pte)	((swp_entry_t) { pte_val(pte) })
3358c2ecf20Sopenharmony_ci#define __swp_entry_to_pte(x)	((pte_t) { (x).val })
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci#ifndef CONFIG_DISCONTIGMEM
3388c2ecf20Sopenharmony_ci#define kern_addr_valid(addr)	(1)
3398c2ecf20Sopenharmony_ci#endif
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci#define pte_ERROR(e) \
3428c2ecf20Sopenharmony_ci	printk("%s:%d: bad pte %016lx.\n", __FILE__, __LINE__, pte_val(e))
3438c2ecf20Sopenharmony_ci#define pmd_ERROR(e) \
3448c2ecf20Sopenharmony_ci	printk("%s:%d: bad pmd %016lx.\n", __FILE__, __LINE__, pmd_val(e))
3458c2ecf20Sopenharmony_ci#define pgd_ERROR(e) \
3468c2ecf20Sopenharmony_ci	printk("%s:%d: bad pgd %016lx.\n", __FILE__, __LINE__, pgd_val(e))
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ciextern void paging_init(void);
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci/* We have our own get_unmapped_area to cope with ADDR_LIMIT_32BIT.  */
3518c2ecf20Sopenharmony_ci#define HAVE_ARCH_UNMAPPED_AREA
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci#endif /* _ALPHA_PGTABLE_H */
354