1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */ 2*4882a593Smuzhiyun #ifndef _ASM_X86_PGTABLE_32_H 3*4882a593Smuzhiyun #define _ASM_X86_PGTABLE_32_H 4*4882a593Smuzhiyun 5*4882a593Smuzhiyun #include <asm/pgtable_32_types.h> 6*4882a593Smuzhiyun 7*4882a593Smuzhiyun /* 8*4882a593Smuzhiyun * The Linux memory management assumes a three-level page table setup. On 9*4882a593Smuzhiyun * the i386, we use that, but "fold" the mid level into the top-level page 10*4882a593Smuzhiyun * table, so that we physically have the same two-level page table as the 11*4882a593Smuzhiyun * i386 mmu expects. 12*4882a593Smuzhiyun * 13*4882a593Smuzhiyun * This file contains the functions and defines necessary to modify and use 14*4882a593Smuzhiyun * the i386 page table tree. 15*4882a593Smuzhiyun */ 16*4882a593Smuzhiyun #ifndef __ASSEMBLY__ 17*4882a593Smuzhiyun #include <asm/processor.h> 18*4882a593Smuzhiyun #include <linux/threads.h> 19*4882a593Smuzhiyun #include <asm/paravirt.h> 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun #include <linux/bitops.h> 22*4882a593Smuzhiyun #include <linux/list.h> 23*4882a593Smuzhiyun #include <linux/spinlock.h> 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun struct mm_struct; 26*4882a593Smuzhiyun struct vm_area_struct; 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun extern pgd_t swapper_pg_dir[1024]; 29*4882a593Smuzhiyun extern pgd_t initial_page_table[1024]; 30*4882a593Smuzhiyun extern pmd_t initial_pg_pmd[]; 31*4882a593Smuzhiyun 32*4882a593Smuzhiyun void paging_init(void); 33*4882a593Smuzhiyun void sync_initial_page_table(void); 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun #ifdef CONFIG_X86_PAE 36*4882a593Smuzhiyun # include <asm/pgtable-3level.h> 37*4882a593Smuzhiyun #else 38*4882a593Smuzhiyun # include <asm/pgtable-2level.h> 39*4882a593Smuzhiyun #endif 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun /* Clear a kernel PTE and flush it from the TLB */ 42*4882a593Smuzhiyun #define kpte_clear_flush(ptep, vaddr) \ 43*4882a593Smuzhiyun do { \ 44*4882a593Smuzhiyun pte_clear(&init_mm, (vaddr), (ptep)); \ 45*4882a593Smuzhiyun flush_tlb_one_kernel((vaddr)); \ 46*4882a593Smuzhiyun } while (0) 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun #endif /* !__ASSEMBLY__ */ 49*4882a593Smuzhiyun 50*4882a593Smuzhiyun /* 51*4882a593Smuzhiyun * kern_addr_valid() is (1) for FLATMEM and (0) for SPARSEMEM 52*4882a593Smuzhiyun */ 53*4882a593Smuzhiyun #ifdef CONFIG_FLATMEM 54*4882a593Smuzhiyun #define kern_addr_valid(addr) (1) 55*4882a593Smuzhiyun #else 56*4882a593Smuzhiyun #define kern_addr_valid(kaddr) (0) 57*4882a593Smuzhiyun #endif 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun /* 60*4882a593Smuzhiyun * This is how much memory in addition to the memory covered up to 61*4882a593Smuzhiyun * and including _end we need mapped initially. 62*4882a593Smuzhiyun * We need: 63*4882a593Smuzhiyun * (KERNEL_IMAGE_SIZE/4096) / 1024 pages (worst case, non PAE) 64*4882a593Smuzhiyun * (KERNEL_IMAGE_SIZE/4096) / 512 + 4 pages (worst case for PAE) 65*4882a593Smuzhiyun * 66*4882a593Smuzhiyun * Modulo rounding, each megabyte assigned here requires a kilobyte of 67*4882a593Smuzhiyun * memory, which is currently unreclaimed. 68*4882a593Smuzhiyun * 69*4882a593Smuzhiyun * This should be a multiple of a page. 70*4882a593Smuzhiyun * 71*4882a593Smuzhiyun * KERNEL_IMAGE_SIZE should be greater than pa(_end) 72*4882a593Smuzhiyun * and small than max_low_pfn, otherwise will waste some page table entries 73*4882a593Smuzhiyun */ 74*4882a593Smuzhiyun #if PTRS_PER_PMD > 1 75*4882a593Smuzhiyun #define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD) 76*4882a593Smuzhiyun #else 77*4882a593Smuzhiyun #define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD) 78*4882a593Smuzhiyun #endif 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun /* 81*4882a593Smuzhiyun * Number of possible pages in the lowmem region. 82*4882a593Smuzhiyun * 83*4882a593Smuzhiyun * We shift 2 by 31 instead of 1 by 32 to the left in order to avoid a 84*4882a593Smuzhiyun * gas warning about overflowing shift count when gas has been compiled 85*4882a593Smuzhiyun * with only a host target support using a 32-bit type for internal 86*4882a593Smuzhiyun * representation. 87*4882a593Smuzhiyun */ 88*4882a593Smuzhiyun #define LOWMEM_PAGES ((((_ULL(2)<<31) - __PAGE_OFFSET) >> PAGE_SHIFT)) 89*4882a593Smuzhiyun 90*4882a593Smuzhiyun #endif /* _ASM_X86_PGTABLE_32_H */ 91