18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
48c2ecf20Sopenharmony_ci * Copyright 2003 PathScale, Inc.
58c2ecf20Sopenharmony_ci * Derived from include/asm-i386/pgtable.h
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef __UM_PGTABLE_H
98c2ecf20Sopenharmony_ci#define __UM_PGTABLE_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <asm/fixmap.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define _PAGE_PRESENT	0x001
148c2ecf20Sopenharmony_ci#define _PAGE_NEWPAGE	0x002
158c2ecf20Sopenharmony_ci#define _PAGE_NEWPROT	0x004
168c2ecf20Sopenharmony_ci#define _PAGE_RW	0x020
178c2ecf20Sopenharmony_ci#define _PAGE_USER	0x040
188c2ecf20Sopenharmony_ci#define _PAGE_ACCESSED	0x080
198c2ecf20Sopenharmony_ci#define _PAGE_DIRTY	0x100
208c2ecf20Sopenharmony_ci/* If _PAGE_PRESENT is clear, we use these: */
218c2ecf20Sopenharmony_ci#define _PAGE_PROTNONE	0x010	/* if the user mapped it with PROT_NONE;
228c2ecf20Sopenharmony_ci				   pte_present gives true */
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#ifdef CONFIG_3_LEVEL_PGTABLES
258c2ecf20Sopenharmony_ci#include <asm/pgtable-3level.h>
268c2ecf20Sopenharmony_ci#else
278c2ecf20Sopenharmony_ci#include <asm/pgtable-2level.h>
288c2ecf20Sopenharmony_ci#endif
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ciextern pgd_t swapper_pg_dir[PTRS_PER_PGD];
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci/* zero page used for uninitialized stuff */
338c2ecf20Sopenharmony_ciextern unsigned long *empty_zero_page;
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/* Just any arbitrary offset to the start of the vmalloc VM area: the
368c2ecf20Sopenharmony_ci * current 8MB value just means that there will be a 8MB "hole" after the
378c2ecf20Sopenharmony_ci * physical memory until the kernel virtual memory starts.  That means that
388c2ecf20Sopenharmony_ci * any out-of-bounds memory accesses will hopefully be caught.
398c2ecf20Sopenharmony_ci * The vmalloc() routines leaves a hole of 4kB between each vmalloced
408c2ecf20Sopenharmony_ci * area for the same reason. ;)
418c2ecf20Sopenharmony_ci */
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciextern unsigned long end_iomem;
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#define VMALLOC_OFFSET	(__va_space)
468c2ecf20Sopenharmony_ci#define VMALLOC_START ((end_iomem + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1))
478c2ecf20Sopenharmony_ci#define PKMAP_BASE ((FIXADDR_START - LAST_PKMAP * PAGE_SIZE) & PMD_MASK)
488c2ecf20Sopenharmony_ci#define VMALLOC_END	(FIXADDR_START-2*PAGE_SIZE)
498c2ecf20Sopenharmony_ci#define MODULES_VADDR	VMALLOC_START
508c2ecf20Sopenharmony_ci#define MODULES_END	VMALLOC_END
518c2ecf20Sopenharmony_ci#define MODULES_LEN	(MODULES_VADDR - MODULES_END)
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#define _PAGE_TABLE	(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED | _PAGE_DIRTY)
548c2ecf20Sopenharmony_ci#define _KERNPG_TABLE	(_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY)
558c2ecf20Sopenharmony_ci#define _PAGE_CHG_MASK	(PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
568c2ecf20Sopenharmony_ci#define __PAGE_KERNEL_EXEC                                              \
578c2ecf20Sopenharmony_ci	 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED)
588c2ecf20Sopenharmony_ci#define PAGE_NONE	__pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED)
598c2ecf20Sopenharmony_ci#define PAGE_SHARED	__pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED)
608c2ecf20Sopenharmony_ci#define PAGE_COPY	__pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
618c2ecf20Sopenharmony_ci#define PAGE_READONLY	__pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
628c2ecf20Sopenharmony_ci#define PAGE_KERNEL	__pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED)
638c2ecf20Sopenharmony_ci#define PAGE_KERNEL_EXEC	__pgprot(__PAGE_KERNEL_EXEC)
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci/*
668c2ecf20Sopenharmony_ci * The i386 can't do page protection for execute, and considers that the same
678c2ecf20Sopenharmony_ci * are read.
688c2ecf20Sopenharmony_ci * Also, write permissions imply read permissions. This is the closest we can
698c2ecf20Sopenharmony_ci * get..
708c2ecf20Sopenharmony_ci */
718c2ecf20Sopenharmony_ci#define __P000	PAGE_NONE
728c2ecf20Sopenharmony_ci#define __P001	PAGE_READONLY
738c2ecf20Sopenharmony_ci#define __P010	PAGE_COPY
748c2ecf20Sopenharmony_ci#define __P011	PAGE_COPY
758c2ecf20Sopenharmony_ci#define __P100	PAGE_READONLY
768c2ecf20Sopenharmony_ci#define __P101	PAGE_READONLY
778c2ecf20Sopenharmony_ci#define __P110	PAGE_COPY
788c2ecf20Sopenharmony_ci#define __P111	PAGE_COPY
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci#define __S000	PAGE_NONE
818c2ecf20Sopenharmony_ci#define __S001	PAGE_READONLY
828c2ecf20Sopenharmony_ci#define __S010	PAGE_SHARED
838c2ecf20Sopenharmony_ci#define __S011	PAGE_SHARED
848c2ecf20Sopenharmony_ci#define __S100	PAGE_READONLY
858c2ecf20Sopenharmony_ci#define __S101	PAGE_READONLY
868c2ecf20Sopenharmony_ci#define __S110	PAGE_SHARED
878c2ecf20Sopenharmony_ci#define __S111	PAGE_SHARED
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci/*
908c2ecf20Sopenharmony_ci * ZERO_PAGE is a global shared page that is always zero: used
918c2ecf20Sopenharmony_ci * for zero-mapped memory areas etc..
928c2ecf20Sopenharmony_ci */
938c2ecf20Sopenharmony_ci#define ZERO_PAGE(vaddr) virt_to_page(empty_zero_page)
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci#define pte_clear(mm,addr,xp) pte_set_val(*(xp), (phys_t) 0, __pgprot(_PAGE_NEWPAGE))
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci#define pmd_none(x)	(!((unsigned long)pmd_val(x) & ~_PAGE_NEWPAGE))
988c2ecf20Sopenharmony_ci#define	pmd_bad(x)	((pmd_val(x) & (~PAGE_MASK & ~_PAGE_USER)) != _KERNPG_TABLE)
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci#define pmd_present(x)	(pmd_val(x) & _PAGE_PRESENT)
1018c2ecf20Sopenharmony_ci#define pmd_clear(xp)	do { pmd_val(*(xp)) = _PAGE_NEWPAGE; } while (0)
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#define pmd_newpage(x)  (pmd_val(x) & _PAGE_NEWPAGE)
1048c2ecf20Sopenharmony_ci#define pmd_mkuptodate(x) (pmd_val(x) &= ~_PAGE_NEWPAGE)
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci#define pud_newpage(x)  (pud_val(x) & _PAGE_NEWPAGE)
1078c2ecf20Sopenharmony_ci#define pud_mkuptodate(x) (pud_val(x) &= ~_PAGE_NEWPAGE)
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci#define p4d_newpage(x)  (p4d_val(x) & _PAGE_NEWPAGE)
1108c2ecf20Sopenharmony_ci#define p4d_mkuptodate(x) (p4d_val(x) &= ~_PAGE_NEWPAGE)
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#define pmd_page(pmd) phys_to_page(pmd_val(pmd) & PAGE_MASK)
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci#define pte_page(x) pfn_to_page(pte_pfn(x))
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci#define pte_present(x)	pte_get_bits(x, (_PAGE_PRESENT | _PAGE_PROTNONE))
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci/*
1198c2ecf20Sopenharmony_ci * =================================
1208c2ecf20Sopenharmony_ci * Flags checking section.
1218c2ecf20Sopenharmony_ci * =================================
1228c2ecf20Sopenharmony_ci */
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistatic inline int pte_none(pte_t pte)
1258c2ecf20Sopenharmony_ci{
1268c2ecf20Sopenharmony_ci	return pte_is_zero(pte);
1278c2ecf20Sopenharmony_ci}
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci/*
1308c2ecf20Sopenharmony_ci * The following only work if pte_present() is true.
1318c2ecf20Sopenharmony_ci * Undefined behaviour if not..
1328c2ecf20Sopenharmony_ci */
1338c2ecf20Sopenharmony_cistatic inline int pte_read(pte_t pte)
1348c2ecf20Sopenharmony_ci{
1358c2ecf20Sopenharmony_ci	return((pte_get_bits(pte, _PAGE_USER)) &&
1368c2ecf20Sopenharmony_ci	       !(pte_get_bits(pte, _PAGE_PROTNONE)));
1378c2ecf20Sopenharmony_ci}
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_cistatic inline int pte_exec(pte_t pte){
1408c2ecf20Sopenharmony_ci	return((pte_get_bits(pte, _PAGE_USER)) &&
1418c2ecf20Sopenharmony_ci	       !(pte_get_bits(pte, _PAGE_PROTNONE)));
1428c2ecf20Sopenharmony_ci}
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_cistatic inline int pte_write(pte_t pte)
1458c2ecf20Sopenharmony_ci{
1468c2ecf20Sopenharmony_ci	return((pte_get_bits(pte, _PAGE_RW)) &&
1478c2ecf20Sopenharmony_ci	       !(pte_get_bits(pte, _PAGE_PROTNONE)));
1488c2ecf20Sopenharmony_ci}
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_cistatic inline int pte_dirty(pte_t pte)
1518c2ecf20Sopenharmony_ci{
1528c2ecf20Sopenharmony_ci	return pte_get_bits(pte, _PAGE_DIRTY);
1538c2ecf20Sopenharmony_ci}
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_cistatic inline int pte_young(pte_t pte)
1568c2ecf20Sopenharmony_ci{
1578c2ecf20Sopenharmony_ci	return pte_get_bits(pte, _PAGE_ACCESSED);
1588c2ecf20Sopenharmony_ci}
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_cistatic inline int pte_newpage(pte_t pte)
1618c2ecf20Sopenharmony_ci{
1628c2ecf20Sopenharmony_ci	return pte_get_bits(pte, _PAGE_NEWPAGE);
1638c2ecf20Sopenharmony_ci}
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_cistatic inline int pte_newprot(pte_t pte)
1668c2ecf20Sopenharmony_ci{
1678c2ecf20Sopenharmony_ci	return(pte_present(pte) && (pte_get_bits(pte, _PAGE_NEWPROT)));
1688c2ecf20Sopenharmony_ci}
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci/*
1718c2ecf20Sopenharmony_ci * =================================
1728c2ecf20Sopenharmony_ci * Flags setting section.
1738c2ecf20Sopenharmony_ci * =================================
1748c2ecf20Sopenharmony_ci */
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_cistatic inline pte_t pte_mknewprot(pte_t pte)
1778c2ecf20Sopenharmony_ci{
1788c2ecf20Sopenharmony_ci	pte_set_bits(pte, _PAGE_NEWPROT);
1798c2ecf20Sopenharmony_ci	return(pte);
1808c2ecf20Sopenharmony_ci}
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_cistatic inline pte_t pte_mkclean(pte_t pte)
1838c2ecf20Sopenharmony_ci{
1848c2ecf20Sopenharmony_ci	pte_clear_bits(pte, _PAGE_DIRTY);
1858c2ecf20Sopenharmony_ci	return(pte);
1868c2ecf20Sopenharmony_ci}
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_cistatic inline pte_t pte_mkold(pte_t pte)
1898c2ecf20Sopenharmony_ci{
1908c2ecf20Sopenharmony_ci	pte_clear_bits(pte, _PAGE_ACCESSED);
1918c2ecf20Sopenharmony_ci	return(pte);
1928c2ecf20Sopenharmony_ci}
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_cistatic inline pte_t pte_wrprotect(pte_t pte)
1958c2ecf20Sopenharmony_ci{
1968c2ecf20Sopenharmony_ci	if (likely(pte_get_bits(pte, _PAGE_RW)))
1978c2ecf20Sopenharmony_ci		pte_clear_bits(pte, _PAGE_RW);
1988c2ecf20Sopenharmony_ci	else
1998c2ecf20Sopenharmony_ci		return pte;
2008c2ecf20Sopenharmony_ci	return(pte_mknewprot(pte));
2018c2ecf20Sopenharmony_ci}
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_cistatic inline pte_t pte_mkread(pte_t pte)
2048c2ecf20Sopenharmony_ci{
2058c2ecf20Sopenharmony_ci	if (unlikely(pte_get_bits(pte, _PAGE_USER)))
2068c2ecf20Sopenharmony_ci		return pte;
2078c2ecf20Sopenharmony_ci	pte_set_bits(pte, _PAGE_USER);
2088c2ecf20Sopenharmony_ci	return(pte_mknewprot(pte));
2098c2ecf20Sopenharmony_ci}
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_cistatic inline pte_t pte_mkdirty(pte_t pte)
2128c2ecf20Sopenharmony_ci{
2138c2ecf20Sopenharmony_ci	pte_set_bits(pte, _PAGE_DIRTY);
2148c2ecf20Sopenharmony_ci	return(pte);
2158c2ecf20Sopenharmony_ci}
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_cistatic inline pte_t pte_mkyoung(pte_t pte)
2188c2ecf20Sopenharmony_ci{
2198c2ecf20Sopenharmony_ci	pte_set_bits(pte, _PAGE_ACCESSED);
2208c2ecf20Sopenharmony_ci	return(pte);
2218c2ecf20Sopenharmony_ci}
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_cistatic inline pte_t pte_mkwrite(pte_t pte)
2248c2ecf20Sopenharmony_ci{
2258c2ecf20Sopenharmony_ci	if (unlikely(pte_get_bits(pte,  _PAGE_RW)))
2268c2ecf20Sopenharmony_ci		return pte;
2278c2ecf20Sopenharmony_ci	pte_set_bits(pte, _PAGE_RW);
2288c2ecf20Sopenharmony_ci	return(pte_mknewprot(pte));
2298c2ecf20Sopenharmony_ci}
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_cistatic inline pte_t pte_mkuptodate(pte_t pte)
2328c2ecf20Sopenharmony_ci{
2338c2ecf20Sopenharmony_ci	pte_clear_bits(pte, _PAGE_NEWPAGE);
2348c2ecf20Sopenharmony_ci	if(pte_present(pte))
2358c2ecf20Sopenharmony_ci		pte_clear_bits(pte, _PAGE_NEWPROT);
2368c2ecf20Sopenharmony_ci	return(pte);
2378c2ecf20Sopenharmony_ci}
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_cistatic inline pte_t pte_mknewpage(pte_t pte)
2408c2ecf20Sopenharmony_ci{
2418c2ecf20Sopenharmony_ci	pte_set_bits(pte, _PAGE_NEWPAGE);
2428c2ecf20Sopenharmony_ci	return(pte);
2438c2ecf20Sopenharmony_ci}
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_cistatic inline void set_pte(pte_t *pteptr, pte_t pteval)
2468c2ecf20Sopenharmony_ci{
2478c2ecf20Sopenharmony_ci	pte_copy(*pteptr, pteval);
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci	/* If it's a swap entry, it needs to be marked _PAGE_NEWPAGE so
2508c2ecf20Sopenharmony_ci	 * fix_range knows to unmap it.  _PAGE_NEWPROT is specific to
2518c2ecf20Sopenharmony_ci	 * mapped pages.
2528c2ecf20Sopenharmony_ci	 */
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci	*pteptr = pte_mknewpage(*pteptr);
2558c2ecf20Sopenharmony_ci	if(pte_present(*pteptr)) *pteptr = pte_mknewprot(*pteptr);
2568c2ecf20Sopenharmony_ci}
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_cistatic inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
2598c2ecf20Sopenharmony_ci			      pte_t *pteptr, pte_t pteval)
2608c2ecf20Sopenharmony_ci{
2618c2ecf20Sopenharmony_ci	set_pte(pteptr, pteval);
2628c2ecf20Sopenharmony_ci}
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci#define __HAVE_ARCH_PTE_SAME
2658c2ecf20Sopenharmony_cistatic inline int pte_same(pte_t pte_a, pte_t pte_b)
2668c2ecf20Sopenharmony_ci{
2678c2ecf20Sopenharmony_ci	return !((pte_val(pte_a) ^ pte_val(pte_b)) & ~_PAGE_NEWPAGE);
2688c2ecf20Sopenharmony_ci}
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci/*
2718c2ecf20Sopenharmony_ci * Conversion functions: convert a page and protection to a page entry,
2728c2ecf20Sopenharmony_ci * and a page entry and page directory to the page they refer to.
2738c2ecf20Sopenharmony_ci */
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci#define phys_to_page(phys) pfn_to_page(phys_to_pfn(phys))
2768c2ecf20Sopenharmony_ci#define __virt_to_page(virt) phys_to_page(__pa(virt))
2778c2ecf20Sopenharmony_ci#define page_to_phys(page) pfn_to_phys(page_to_pfn(page))
2788c2ecf20Sopenharmony_ci#define virt_to_page(addr) __virt_to_page((const unsigned long) addr)
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_ci#define mk_pte(page, pgprot) \
2818c2ecf20Sopenharmony_ci	({ pte_t pte;					\
2828c2ecf20Sopenharmony_ci							\
2838c2ecf20Sopenharmony_ci	pte_set_val(pte, page_to_phys(page), (pgprot));	\
2848c2ecf20Sopenharmony_ci	if (pte_present(pte))				\
2858c2ecf20Sopenharmony_ci		pte_mknewprot(pte_mknewpage(pte));	\
2868c2ecf20Sopenharmony_ci	pte;})
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_cistatic inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2898c2ecf20Sopenharmony_ci{
2908c2ecf20Sopenharmony_ci	pte_set_val(pte, (pte_val(pte) & _PAGE_CHG_MASK), newprot);
2918c2ecf20Sopenharmony_ci	return pte;
2928c2ecf20Sopenharmony_ci}
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci/*
2958c2ecf20Sopenharmony_ci * the pmd page can be thought of an array like this: pmd_t[PTRS_PER_PMD]
2968c2ecf20Sopenharmony_ci *
2978c2ecf20Sopenharmony_ci * this macro returns the index of the entry in the pmd page which would
2988c2ecf20Sopenharmony_ci * control the given virtual address
2998c2ecf20Sopenharmony_ci */
3008c2ecf20Sopenharmony_ci#define pmd_page_vaddr(pmd) ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_cistruct mm_struct;
3038c2ecf20Sopenharmony_ciextern pte_t *virt_to_pte(struct mm_struct *mm, unsigned long addr);
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci#define update_mmu_cache(vma,address,ptep) do ; while (0)
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci/* Encode and de-code a swap entry */
3088c2ecf20Sopenharmony_ci#define __swp_type(x)			(((x).val >> 5) & 0x1f)
3098c2ecf20Sopenharmony_ci#define __swp_offset(x)			((x).val >> 11)
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci#define __swp_entry(type, offset) \
3128c2ecf20Sopenharmony_ci	((swp_entry_t) { ((type) << 5) | ((offset) << 11) })
3138c2ecf20Sopenharmony_ci#define __pte_to_swp_entry(pte) \
3148c2ecf20Sopenharmony_ci	((swp_entry_t) { pte_val(pte_mkuptodate(pte)) })
3158c2ecf20Sopenharmony_ci#define __swp_entry_to_pte(x)		((pte_t) { (x).val })
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci#define kern_addr_valid(addr) (1)
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci/* Clear a kernel PTE and flush it from the TLB */
3208c2ecf20Sopenharmony_ci#define kpte_clear_flush(ptep, vaddr)		\
3218c2ecf20Sopenharmony_cido {						\
3228c2ecf20Sopenharmony_ci	pte_clear(&init_mm, (vaddr), (ptep));	\
3238c2ecf20Sopenharmony_ci	__flush_tlb_one((vaddr));		\
3248c2ecf20Sopenharmony_ci} while (0)
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ci#endif
327