^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright 2003 PathScale, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Derived from include/asm-i386/pgtable.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #ifndef __UM_PGTABLE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define __UM_PGTABLE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <asm/fixmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define _PAGE_PRESENT 0x001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define _PAGE_NEWPAGE 0x002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define _PAGE_NEWPROT 0x004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define _PAGE_RW 0x020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define _PAGE_USER 0x040
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define _PAGE_ACCESSED 0x080
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define _PAGE_DIRTY 0x100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /* If _PAGE_PRESENT is clear, we use these: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define _PAGE_PROTNONE 0x010 /* if the user mapped it with PROT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) pte_present gives true */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #ifdef CONFIG_3_LEVEL_PGTABLES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <asm/pgtable-3level.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <asm/pgtable-2level.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /* zero page used for uninitialized stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) extern unsigned long *empty_zero_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* Just any arbitrary offset to the start of the vmalloc VM area: the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * current 8MB value just means that there will be a 8MB "hole" after the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * physical memory until the kernel virtual memory starts. That means that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * any out-of-bounds memory accesses will hopefully be caught.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * The vmalloc() routines leaves a hole of 4kB between each vmalloced
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * area for the same reason. ;)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) extern unsigned long end_iomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define VMALLOC_OFFSET (__va_space)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define VMALLOC_START ((end_iomem + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define PKMAP_BASE ((FIXADDR_START - LAST_PKMAP * PAGE_SIZE) & PMD_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define VMALLOC_END (FIXADDR_START-2*PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define MODULES_VADDR VMALLOC_START
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define MODULES_END VMALLOC_END
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define MODULES_LEN (MODULES_VADDR - MODULES_END)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define _PAGE_TABLE (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED | _PAGE_DIRTY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define _KERNPG_TABLE (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define __PAGE_KERNEL_EXEC \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define PAGE_NONE __pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define PAGE_KERNEL __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define PAGE_KERNEL_EXEC __pgprot(__PAGE_KERNEL_EXEC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * The i386 can't do page protection for execute, and considers that the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * are read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * Also, write permissions imply read permissions. This is the closest we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * get..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define __P000 PAGE_NONE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define __P001 PAGE_READONLY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define __P010 PAGE_COPY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define __P011 PAGE_COPY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define __P100 PAGE_READONLY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define __P101 PAGE_READONLY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define __P110 PAGE_COPY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define __P111 PAGE_COPY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define __S000 PAGE_NONE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #define __S001 PAGE_READONLY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define __S010 PAGE_SHARED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #define __S011 PAGE_SHARED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define __S100 PAGE_READONLY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #define __S101 PAGE_READONLY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #define __S110 PAGE_SHARED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #define __S111 PAGE_SHARED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * ZERO_PAGE is a global shared page that is always zero: used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * for zero-mapped memory areas etc..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define ZERO_PAGE(vaddr) virt_to_page(empty_zero_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #define pte_clear(mm,addr,xp) pte_set_val(*(xp), (phys_t) 0, __pgprot(_PAGE_NEWPAGE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define pmd_none(x) (!((unsigned long)pmd_val(x) & ~_PAGE_NEWPAGE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #define pmd_bad(x) ((pmd_val(x) & (~PAGE_MASK & ~_PAGE_USER)) != _KERNPG_TABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define pmd_present(x) (pmd_val(x) & _PAGE_PRESENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define pmd_clear(xp) do { pmd_val(*(xp)) = _PAGE_NEWPAGE; } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define pmd_newpage(x) (pmd_val(x) & _PAGE_NEWPAGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define pmd_mkuptodate(x) (pmd_val(x) &= ~_PAGE_NEWPAGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define pud_newpage(x) (pud_val(x) & _PAGE_NEWPAGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define pud_mkuptodate(x) (pud_val(x) &= ~_PAGE_NEWPAGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define p4d_newpage(x) (p4d_val(x) & _PAGE_NEWPAGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define p4d_mkuptodate(x) (p4d_val(x) &= ~_PAGE_NEWPAGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define pmd_page(pmd) phys_to_page(pmd_val(pmd) & PAGE_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #define pte_page(x) pfn_to_page(pte_pfn(x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define pte_present(x) pte_get_bits(x, (_PAGE_PRESENT | _PAGE_PROTNONE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * =================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * Flags checking section.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * =================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static inline int pte_none(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return pte_is_zero(pte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * The following only work if pte_present() is true.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * Undefined behaviour if not..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static inline int pte_read(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return((pte_get_bits(pte, _PAGE_USER)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) !(pte_get_bits(pte, _PAGE_PROTNONE)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static inline int pte_exec(pte_t pte){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return((pte_get_bits(pte, _PAGE_USER)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) !(pte_get_bits(pte, _PAGE_PROTNONE)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static inline int pte_write(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return((pte_get_bits(pte, _PAGE_RW)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) !(pte_get_bits(pte, _PAGE_PROTNONE)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static inline int pte_dirty(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return pte_get_bits(pte, _PAGE_DIRTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static inline int pte_young(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return pte_get_bits(pte, _PAGE_ACCESSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static inline int pte_newpage(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return pte_get_bits(pte, _PAGE_NEWPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static inline int pte_newprot(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) return(pte_present(pte) && (pte_get_bits(pte, _PAGE_NEWPROT)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * =================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * Flags setting section.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * =================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static inline pte_t pte_mknewprot(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) pte_set_bits(pte, _PAGE_NEWPROT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return(pte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static inline pte_t pte_mkclean(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) pte_clear_bits(pte, _PAGE_DIRTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return(pte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static inline pte_t pte_mkold(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) pte_clear_bits(pte, _PAGE_ACCESSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return(pte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static inline pte_t pte_wrprotect(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (likely(pte_get_bits(pte, _PAGE_RW)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) pte_clear_bits(pte, _PAGE_RW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return(pte_mknewprot(pte));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static inline pte_t pte_mkread(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (unlikely(pte_get_bits(pte, _PAGE_USER)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) pte_set_bits(pte, _PAGE_USER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) return(pte_mknewprot(pte));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static inline pte_t pte_mkdirty(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) pte_set_bits(pte, _PAGE_DIRTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return(pte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static inline pte_t pte_mkyoung(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) pte_set_bits(pte, _PAGE_ACCESSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return(pte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static inline pte_t pte_mkwrite(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (unlikely(pte_get_bits(pte, _PAGE_RW)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) pte_set_bits(pte, _PAGE_RW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return(pte_mknewprot(pte));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static inline pte_t pte_mkuptodate(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) pte_clear_bits(pte, _PAGE_NEWPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if(pte_present(pte))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) pte_clear_bits(pte, _PAGE_NEWPROT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return(pte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static inline pte_t pte_mknewpage(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) pte_set_bits(pte, _PAGE_NEWPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return(pte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static inline void set_pte(pte_t *pteptr, pte_t pteval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) pte_copy(*pteptr, pteval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) /* If it's a swap entry, it needs to be marked _PAGE_NEWPAGE so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * fix_range knows to unmap it. _PAGE_NEWPROT is specific to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * mapped pages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) *pteptr = pte_mknewpage(*pteptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if(pte_present(*pteptr)) *pteptr = pte_mknewprot(*pteptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) pte_t *pteptr, pte_t pteval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) set_pte(pteptr, pteval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) #define __HAVE_ARCH_PTE_SAME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static inline int pte_same(pte_t pte_a, pte_t pte_b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return !((pte_val(pte_a) ^ pte_val(pte_b)) & ~_PAGE_NEWPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * Conversion functions: convert a page and protection to a page entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * and a page entry and page directory to the page they refer to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) #define phys_to_page(phys) pfn_to_page(phys_to_pfn(phys))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) #define __virt_to_page(virt) phys_to_page(__pa(virt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) #define page_to_phys(page) pfn_to_phys(page_to_pfn(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) #define virt_to_page(addr) __virt_to_page((const unsigned long) addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) #define mk_pte(page, pgprot) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) ({ pte_t pte; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) pte_set_val(pte, page_to_phys(page), (pgprot)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (pte_present(pte)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) pte_mknewprot(pte_mknewpage(pte)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) pte;})
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) pte_set_val(pte, (pte_val(pte) & _PAGE_CHG_MASK), newprot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) return pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) * the pmd page can be thought of an array like this: pmd_t[PTRS_PER_PMD]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * this macro returns the index of the entry in the pmd page which would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * control the given virtual address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) #define pmd_page_vaddr(pmd) ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) struct mm_struct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) extern pte_t *virt_to_pte(struct mm_struct *mm, unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) #define update_mmu_cache(vma,address,ptep) do ; while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) /* Encode and de-code a swap entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) #define __swp_type(x) (((x).val >> 5) & 0x1f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) #define __swp_offset(x) ((x).val >> 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) #define __swp_entry(type, offset) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) ((swp_entry_t) { ((type) << 5) | ((offset) << 11) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) #define __pte_to_swp_entry(pte) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) ((swp_entry_t) { pte_val(pte_mkuptodate(pte)) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) #define kern_addr_valid(addr) (1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) /* Clear a kernel PTE and flush it from the TLB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) #define kpte_clear_flush(ptep, vaddr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) pte_clear(&init_mm, (vaddr), (ptep)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) __flush_tlb_one((vaddr)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) #endif