1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_PGTABLE_64_DEFS_H
3 #define _ASM_X86_PGTABLE_64_DEFS_H
5 #include <asm/sparsemem.h>
8 #include <linux/types.h>
12 * These are used to make use of C type-checking..
14 typedef unsigned long pteval_t;
15 typedef unsigned long pmdval_t;
16 typedef unsigned long pudval_t;
17 typedef unsigned long p4dval_t;
18 typedef unsigned long pgdval_t;
19 typedef unsigned long pgprotval_t;
21 typedef struct { pteval_t pte; } pte_t;
23 #endif /* !__ASSEMBLY__ */
25 #define SHARED_KERNEL_PMD 0
27 #ifdef CONFIG_X86_5LEVEL
30 * PGDIR_SHIFT determines what a top-level page table entry can map
32 #define PGDIR_SHIFT 48
33 #define PTRS_PER_PGD 512
36 * 4th level page in 5-level paging case
39 #define PTRS_PER_P4D 512
40 #define P4D_SIZE (_AC(1, UL) << P4D_SHIFT)
41 #define P4D_MASK (~(P4D_SIZE - 1))
43 #define MAX_POSSIBLE_PHYSMEM_BITS 52
45 #else /* CONFIG_X86_5LEVEL */
48 * PGDIR_SHIFT determines what a top-level page table entry can map
50 #define PGDIR_SHIFT 39
51 #define PTRS_PER_PGD 512
53 #endif /* CONFIG_X86_5LEVEL */
59 #define PTRS_PER_PUD 512
62 * PMD_SHIFT determines the size of the area a middle-level
66 #define PTRS_PER_PMD 512
69 * entries per page directory level
71 #define PTRS_PER_PTE 512
73 #define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
74 #define PMD_MASK (~(PMD_SIZE - 1))
75 #define PUD_SIZE (_AC(1, UL) << PUD_SHIFT)
76 #define PUD_MASK (~(PUD_SIZE - 1))
77 #define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT)
78 #define PGDIR_MASK (~(PGDIR_SIZE - 1))
81 * See Documentation/x86/x86_64/mm.txt for a description of the memory map.
83 * Be very careful vs. KASLR when changing anything here. The KASLR address
84 * range must not overlap with anything except the KASAN shadow area, which
85 * is correct as KASAN disables KASLR.
87 #define MAXMEM _AC(__AC(1, UL) << MAX_PHYSMEM_BITS, UL)
89 #ifdef CONFIG_X86_5LEVEL
90 # define VMALLOC_SIZE_TB _AC(12800, UL)
91 # define __VMALLOC_BASE _AC(0xffa0000000000000, UL)
92 # define __VMEMMAP_BASE _AC(0xffd4000000000000, UL)
94 # define VMALLOC_SIZE_TB _AC(32, UL)
95 # define __VMALLOC_BASE _AC(0xffffc90000000000, UL)
96 # define __VMEMMAP_BASE _AC(0xffffea0000000000, UL)
99 #define GUARD_HOLE_PGD_ENTRY -256UL
100 #define GUARD_HOLE_SIZE (16UL << PGDIR_SHIFT)
101 #define GUARD_HOLE_BASE_ADDR (GUARD_HOLE_PGD_ENTRY << PGDIR_SHIFT)
102 #define GUARD_HOLE_END_ADDR (GUARD_HOLE_BASE_ADDR + GUARD_HOLE_SIZE)
104 #define LDT_PGD_ENTRY -240UL
105 #define LDT_BASE_ADDR (LDT_PGD_ENTRY << PGDIR_SHIFT)
107 #ifdef CONFIG_RANDOMIZE_MEMORY
108 # define VMALLOC_START vmalloc_base
109 # define VMEMMAP_START vmemmap_base
111 # define VMALLOC_START __VMALLOC_BASE
112 # define VMEMMAP_START __VMEMMAP_BASE
113 #endif /* CONFIG_RANDOMIZE_MEMORY */
115 #define VMALLOC_END (VMALLOC_START + _AC((VMALLOC_SIZE_TB << 40) - 1, UL))
117 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
118 /* The module sections ends with the start of the fixmap */
119 #define MODULES_END _AC(0xffffffffff000000, UL)
120 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
122 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
123 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << P4D_SHIFT)
125 #define CPU_ENTRY_AREA_PGD _AC(-4, UL)
126 #define CPU_ENTRY_AREA_BASE (CPU_ENTRY_AREA_PGD << P4D_SHIFT)
128 #define EFI_VA_START ( -4 * (_AC(1, UL) << 30))
129 #define EFI_VA_END (-68 * (_AC(1, UL) << 30))
131 #define EARLY_DYNAMIC_PAGE_TABLES 64
133 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */