^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2009 Wind River Systems Inc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Based on asm/pgtable-32.h from mips which is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 2003 Ralf Baechle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (C) 1999, 2000, 2001 Silicon Graphics, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * License. See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #ifndef _ASM_NIOS2_PGTABLE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define _ASM_NIOS2_PGTABLE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/tlbflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <asm/pgtable-bits.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <asm-generic/pgtable-nopmd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define FIRST_USER_ADDRESS 0UL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define VMALLOC_START CONFIG_NIOS2_KERNEL_MMU_REGION_BASE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define VMALLOC_END (CONFIG_NIOS2_KERNEL_REGION_BASE - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct mm_struct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* Helper macro */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define MKP(x, w, r) __pgprot(_PAGE_PRESENT | _PAGE_CACHED | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) ((x) ? _PAGE_EXEC : 0) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) ((r) ? _PAGE_READ : 0) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) ((w) ? _PAGE_WRITE : 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * These are the macros that generic kernel code needs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * (to populate protection_map[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /* Remove W bit on private pages for COW support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define __P000 MKP(0, 0, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define __P001 MKP(0, 0, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define __P010 MKP(0, 0, 0) /* COW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define __P011 MKP(0, 0, 1) /* COW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define __P100 MKP(1, 0, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define __P101 MKP(1, 0, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define __P110 MKP(1, 0, 0) /* COW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define __P111 MKP(1, 0, 1) /* COW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) /* Shared pages can have exact HW mapping */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define __S000 MKP(0, 0, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define __S001 MKP(0, 0, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define __S010 MKP(0, 1, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define __S011 MKP(0, 1, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define __S100 MKP(1, 0, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define __S101 MKP(1, 0, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define __S110 MKP(1, 1, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define __S111 MKP(1, 1, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /* Used all over the kernel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define PAGE_KERNEL __pgprot(_PAGE_PRESENT | _PAGE_CACHED | _PAGE_READ | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) _PAGE_WRITE | _PAGE_EXEC | _PAGE_GLOBAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_CACHED | _PAGE_READ | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) _PAGE_WRITE | _PAGE_ACCESSED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define PAGE_COPY MKP(0, 0, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define PGD_ORDER 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define PTE_ORDER 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define PTRS_PER_PGD ((PAGE_SIZE << PGD_ORDER) / sizeof(pgd_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define PTRS_PER_PTE ((PAGE_SIZE << PTE_ORDER) / sizeof(pte_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define USER_PTRS_PER_PGD \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) (CONFIG_NIOS2_KERNEL_MMU_REGION_BASE / PGDIR_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define PGDIR_SHIFT 22
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define PGDIR_MASK (~(PGDIR_SIZE-1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * ZERO_PAGE is a global shared page that is always zero: used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * for zero-mapped memory areas etc..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) extern pte_t invalid_pte_table[PAGE_SIZE/sizeof(pte_t)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * (pmds are folded into puds so this doesn't get actually called,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * but the define is needed for a generic inline function.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static inline void set_pmd(pmd_t *pmdptr, pmd_t pmdval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) *pmdptr = pmdval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static inline int pte_write(pte_t pte) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) { return pte_val(pte) & _PAGE_WRITE; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static inline int pte_dirty(pte_t pte) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) { return pte_val(pte) & _PAGE_DIRTY; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static inline int pte_young(pte_t pte) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) { return pte_val(pte) & _PAGE_ACCESSED; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define pgprot_noncached pgprot_noncached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static inline pgprot_t pgprot_noncached(pgprot_t _prot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) unsigned long prot = pgprot_val(_prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) prot &= ~_PAGE_CACHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return __pgprot(prot);
^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) static inline int pte_none(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return !(pte_val(pte) & ~(_PAGE_GLOBAL|0xf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static inline int pte_present(pte_t pte) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) { return pte_val(pte) & _PAGE_PRESENT; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * The following only work if pte_present() is true.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * Undefined behaviour if not..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static inline pte_t pte_wrprotect(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) pte_val(pte) &= ~_PAGE_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static inline pte_t pte_mkclean(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) pte_val(pte) &= ~_PAGE_DIRTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static inline pte_t pte_mkold(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) pte_val(pte) &= ~_PAGE_ACCESSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static inline pte_t pte_mkwrite(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) pte_val(pte) |= _PAGE_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static inline pte_t pte_mkdirty(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) pte_val(pte) |= _PAGE_DIRTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return pte;
^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 pte_t pte_mkyoung(pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) pte_val(pte) |= _PAGE_ACCESSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return pte;
^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) static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) const unsigned long mask = _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static inline int pmd_present(pmd_t pmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return (pmd_val(pmd) != (unsigned long) invalid_pte_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) && (pmd_val(pmd) != 0UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static inline void pmd_clear(pmd_t *pmdp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) pmd_val(*pmdp) = (unsigned long) invalid_pte_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) #define pte_pfn(pte) (pte_val(pte) & 0xfffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) #define pfn_pte(pfn, prot) (__pte(pfn | pgprot_val(prot)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #define pte_page(pte) (pfn_to_page(pte_pfn(pte)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * Store a linux PTE into the linux page table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static inline void set_pte(pte_t *ptep, pte_t pteval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) *ptep = pteval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) pte_t *ptep, pte_t pteval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) unsigned long paddr = (unsigned long)page_to_virt(pte_page(pteval));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) flush_dcache_range(paddr, paddr + PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) set_pte(ptep, pteval);
^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 int pmd_none(pmd_t pmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return (pmd_val(pmd) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) (unsigned long) invalid_pte_table) || (pmd_val(pmd) == 0UL);
^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) #define pmd_bad(pmd) (pmd_val(pmd) & ~PAGE_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static inline void pte_clear(struct mm_struct *mm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) unsigned long addr, pte_t *ptep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) pte_t null;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) pte_val(null) = (addr >> PAGE_SHIFT) & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) set_pte_at(mm, addr, ptep, null);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * Conversion functions: convert a page and protection to a page entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * and a page entry and page directory to the page they refer to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #define mk_pte(page, prot) (pfn_pte(page_to_pfn(page), prot))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * Conversion functions: convert a page and protection to a page entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * and a page entry and page directory to the page they refer to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) #define pmd_phys(pmd) virt_to_phys((void *)pmd_val(pmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) #define pmd_page(pmd) (pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static inline unsigned long pmd_page_vaddr(pmd_t pmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return pmd_val(pmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #define pte_ERROR(e) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) pr_err("%s:%d: bad pte %08lx.\n", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) __FILE__, __LINE__, pte_val(e))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) #define pgd_ERROR(e) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) pr_err("%s:%d: bad pgd %08lx.\n", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) __FILE__, __LINE__, pgd_val(e))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * Encode and decode a swap entry (must be !pte_none(pte) && !pte_present(pte):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * 31 30 29 28 27 26 25 24 23 22 21 20 19 18 ... 1 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * 0 0 0 0 type. 0 0 0 0 0 0 offset.........
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * This gives us up to 2**2 = 4 swap files and 2**20 * 4K = 4G per swap file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * Note that the offset field is always non-zero, thus !pte_none(pte) is always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * true.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) #define __swp_type(swp) (((swp).val >> 26) & 0x3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) #define __swp_offset(swp) ((swp).val & 0xfffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) #define __swp_entry(type, off) ((swp_entry_t) { (((type) & 0x3) << 26) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) | ((off) & 0xfffff) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) #define __swp_entry_to_pte(swp) ((pte_t) { (swp).val })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) #define kern_addr_valid(addr) (1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) extern void __init paging_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) extern void __init mmu_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) extern void update_mmu_cache(struct vm_area_struct *vma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) unsigned long address, pte_t *pte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) #endif /* _ASM_NIOS2_PGTABLE_H */