xref: /openbmc/linux/arch/x86/include/asm/pgtable_32.h (revision e025ab84)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21965aae3SH. Peter Anvin #ifndef _ASM_X86_PGTABLE_32_H
31965aae3SH. Peter Anvin #define _ASM_X86_PGTABLE_32_H
4bb898558SAl Viro 
5f402a65fSJeremy Fitzhardinge #include <asm/pgtable_32_types.h>
6bb898558SAl Viro 
7bb898558SAl Viro /*
8bb898558SAl Viro  * The Linux memory management assumes a three-level page table setup. On
9bb898558SAl Viro  * the i386, we use that, but "fold" the mid level into the top-level page
10bb898558SAl Viro  * table, so that we physically have the same two-level page table as the
11bb898558SAl Viro  * i386 mmu expects.
12bb898558SAl Viro  *
13bb898558SAl Viro  * This file contains the functions and defines necessary to modify and use
14bb898558SAl Viro  * the i386 page table tree.
15bb898558SAl Viro  */
16bb898558SAl Viro #ifndef __ASSEMBLY__
17bb898558SAl Viro #include <asm/processor.h>
18bb898558SAl Viro #include <linux/threads.h>
19bb898558SAl Viro #include <asm/paravirt.h>
20bb898558SAl Viro 
21bb898558SAl Viro #include <linux/bitops.h>
22bb898558SAl Viro #include <linux/list.h>
23bb898558SAl Viro #include <linux/spinlock.h>
24bb898558SAl Viro 
25bb898558SAl Viro struct mm_struct;
26bb898558SAl Viro struct vm_area_struct;
27bb898558SAl Viro 
28bb898558SAl Viro extern pgd_t swapper_pg_dir[1024];
29b40827faSBorislav Petkov extern pgd_t initial_page_table[1024];
301e620f9bSBoris Ostrovsky extern pmd_t initial_pg_pmd[];
31bb898558SAl Viro 
32bb898558SAl Viro void paging_init(void);
33945fd17aSThomas Gleixner void sync_initial_page_table(void);
34bb898558SAl Viro 
35bb898558SAl Viro #ifdef CONFIG_X86_PAE
36bb898558SAl Viro # include <asm/pgtable-3level.h>
37bb898558SAl Viro #else
38bb898558SAl Viro # include <asm/pgtable-2level.h>
39bb898558SAl Viro #endif
40bb898558SAl Viro 
41bb898558SAl Viro /* Clear a kernel PTE and flush it from the TLB */
42bb898558SAl Viro #define kpte_clear_flush(ptep, vaddr)		\
43bb898558SAl Viro do {						\
44bb898558SAl Viro 	pte_clear(&init_mm, (vaddr), (ptep));	\
4558430c5dSThomas Gleixner 	flush_tlb_one_kernel((vaddr));		\
46bb898558SAl Viro } while (0)
47bb898558SAl Viro 
48bb898558SAl Viro #endif /* !__ASSEMBLY__ */
49bb898558SAl Viro 
50bb898558SAl Viro /*
51*ea3186b9SArvind Sankar  * This is used to calculate the .brk reservation for initial pagetables.
52*ea3186b9SArvind Sankar  * Enough space is reserved to allocate pagetables sufficient to cover all
53*ea3186b9SArvind Sankar  * of LOWMEM_PAGES, which is an upper bound on the size of the direct map of
54*ea3186b9SArvind Sankar  * lowmem.
551e620f9bSBoris Ostrovsky  *
56*ea3186b9SArvind Sankar  * With PAE paging (PTRS_PER_PMD > 1), we allocate PTRS_PER_PGD == 4 pages for
57*ea3186b9SArvind Sankar  * the PMD's in addition to the pages required for the last level pagetables.
581e620f9bSBoris Ostrovsky  */
591e620f9bSBoris Ostrovsky #if PTRS_PER_PMD > 1
601e620f9bSBoris Ostrovsky #define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
611e620f9bSBoris Ostrovsky #else
621e620f9bSBoris Ostrovsky #define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
631e620f9bSBoris Ostrovsky #endif
641e620f9bSBoris Ostrovsky 
651e620f9bSBoris Ostrovsky /*
661e620f9bSBoris Ostrovsky  * Number of possible pages in the lowmem region.
671e620f9bSBoris Ostrovsky  *
681e620f9bSBoris Ostrovsky  * We shift 2 by 31 instead of 1 by 32 to the left in order to avoid a
691e620f9bSBoris Ostrovsky  * gas warning about overflowing shift count when gas has been compiled
701e620f9bSBoris Ostrovsky  * with only a host target support using a 32-bit type for internal
711e620f9bSBoris Ostrovsky  * representation.
721e620f9bSBoris Ostrovsky  */
7326515699SArnd Bergmann #define LOWMEM_PAGES ((((_ULL(2)<<31) - __PAGE_OFFSET) >> PAGE_SHIFT))
741e620f9bSBoris Ostrovsky 
751965aae3SH. Peter Anvin #endif /* _ASM_X86_PGTABLE_32_H */
76