1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * fixmap.h: compile-time virtual memory allocation
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * This file is subject to the terms and conditions of the GNU General Public
5*4882a593Smuzhiyun * License. See the file "COPYING" in the main directory of this archive
6*4882a593Smuzhiyun * for more details.
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * Copyright (C) 1998 Ingo Molnar
9*4882a593Smuzhiyun *
10*4882a593Smuzhiyun * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
11*4882a593Smuzhiyun * x86_32 and x86_64 integration by Gustavo F. Padovan, February 2009
12*4882a593Smuzhiyun */
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun #ifndef _ASM_X86_FIXMAP_H
15*4882a593Smuzhiyun #define _ASM_X86_FIXMAP_H
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun /*
18*4882a593Smuzhiyun * Exposed to assembly code for setting up initial page tables. Cannot be
19*4882a593Smuzhiyun * calculated in assembly code (fixmap entries are an enum), but is sanity
20*4882a593Smuzhiyun * checked in the actual fixmap C code to make sure that the fixmap is
21*4882a593Smuzhiyun * covered fully.
22*4882a593Smuzhiyun */
23*4882a593Smuzhiyun #define FIXMAP_PMD_NUM 2
24*4882a593Smuzhiyun /* fixmap starts downwards from the 507th entry in level2_fixmap_pgt */
25*4882a593Smuzhiyun #define FIXMAP_PMD_TOP 507
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun #ifndef __ASSEMBLY__
28*4882a593Smuzhiyun #include <linux/kernel.h>
29*4882a593Smuzhiyun #include <asm/apicdef.h>
30*4882a593Smuzhiyun #include <asm/page.h>
31*4882a593Smuzhiyun #include <asm/pgtable_types.h>
32*4882a593Smuzhiyun #ifdef CONFIG_X86_32
33*4882a593Smuzhiyun #include <linux/threads.h>
34*4882a593Smuzhiyun #include <asm/kmap_types.h>
35*4882a593Smuzhiyun #else
36*4882a593Smuzhiyun #include <uapi/asm/vsyscall.h>
37*4882a593Smuzhiyun #endif
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun /*
40*4882a593Smuzhiyun * We can't declare FIXADDR_TOP as variable for x86_64 because vsyscall
41*4882a593Smuzhiyun * uses fixmaps that relies on FIXADDR_TOP for proper address calculation.
42*4882a593Smuzhiyun * Because of this, FIXADDR_TOP x86 integration was left as later work.
43*4882a593Smuzhiyun */
44*4882a593Smuzhiyun #ifdef CONFIG_X86_32
45*4882a593Smuzhiyun /*
46*4882a593Smuzhiyun * Leave one empty page between vmalloc'ed areas and
47*4882a593Smuzhiyun * the start of the fixmap.
48*4882a593Smuzhiyun */
49*4882a593Smuzhiyun extern unsigned long __FIXADDR_TOP;
50*4882a593Smuzhiyun #define FIXADDR_TOP ((unsigned long)__FIXADDR_TOP)
51*4882a593Smuzhiyun #else
52*4882a593Smuzhiyun #define FIXADDR_TOP (round_up(VSYSCALL_ADDR + PAGE_SIZE, 1<<PMD_SHIFT) - \
53*4882a593Smuzhiyun PAGE_SIZE)
54*4882a593Smuzhiyun #endif
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun /*
57*4882a593Smuzhiyun * Here we define all the compile-time 'special' virtual
58*4882a593Smuzhiyun * addresses. The point is to have a constant address at
59*4882a593Smuzhiyun * compile time, but to set the physical address only
60*4882a593Smuzhiyun * in the boot process.
61*4882a593Smuzhiyun * for x86_32: We allocate these special addresses
62*4882a593Smuzhiyun * from the end of virtual memory (0xfffff000) backwards.
63*4882a593Smuzhiyun * Also this lets us do fail-safe vmalloc(), we
64*4882a593Smuzhiyun * can guarantee that these special addresses and
65*4882a593Smuzhiyun * vmalloc()-ed addresses never overlap.
66*4882a593Smuzhiyun *
67*4882a593Smuzhiyun * These 'compile-time allocated' memory buffers are
68*4882a593Smuzhiyun * fixed-size 4k pages (or larger if used with an increment
69*4882a593Smuzhiyun * higher than 1). Use set_fixmap(idx,phys) to associate
70*4882a593Smuzhiyun * physical memory with fixmap indices.
71*4882a593Smuzhiyun *
72*4882a593Smuzhiyun * TLB entries of such buffers will not be flushed across
73*4882a593Smuzhiyun * task switches.
74*4882a593Smuzhiyun */
75*4882a593Smuzhiyun enum fixed_addresses {
76*4882a593Smuzhiyun #ifdef CONFIG_X86_32
77*4882a593Smuzhiyun FIX_HOLE,
78*4882a593Smuzhiyun #else
79*4882a593Smuzhiyun #ifdef CONFIG_X86_VSYSCALL_EMULATION
80*4882a593Smuzhiyun VSYSCALL_PAGE = (FIXADDR_TOP - VSYSCALL_ADDR) >> PAGE_SHIFT,
81*4882a593Smuzhiyun #endif
82*4882a593Smuzhiyun #endif
83*4882a593Smuzhiyun FIX_DBGP_BASE,
84*4882a593Smuzhiyun FIX_EARLYCON_MEM_BASE,
85*4882a593Smuzhiyun #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
86*4882a593Smuzhiyun FIX_OHCI1394_BASE,
87*4882a593Smuzhiyun #endif
88*4882a593Smuzhiyun #ifdef CONFIG_X86_LOCAL_APIC
89*4882a593Smuzhiyun FIX_APIC_BASE, /* local (CPU) APIC) -- required for SMP or not */
90*4882a593Smuzhiyun #endif
91*4882a593Smuzhiyun #ifdef CONFIG_X86_IO_APIC
92*4882a593Smuzhiyun FIX_IO_APIC_BASE_0,
93*4882a593Smuzhiyun FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS - 1,
94*4882a593Smuzhiyun #endif
95*4882a593Smuzhiyun #ifdef CONFIG_X86_32
96*4882a593Smuzhiyun FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */
97*4882a593Smuzhiyun FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
98*4882a593Smuzhiyun #ifdef CONFIG_PCI_MMCONFIG
99*4882a593Smuzhiyun FIX_PCIE_MCFG,
100*4882a593Smuzhiyun #endif
101*4882a593Smuzhiyun #endif
102*4882a593Smuzhiyun #ifdef CONFIG_PARAVIRT_XXL
103*4882a593Smuzhiyun FIX_PARAVIRT_BOOTMAP,
104*4882a593Smuzhiyun #endif
105*4882a593Smuzhiyun #ifdef CONFIG_X86_INTEL_MID
106*4882a593Smuzhiyun FIX_LNW_VRTC,
107*4882a593Smuzhiyun #endif
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun #ifdef CONFIG_ACPI_APEI_GHES
110*4882a593Smuzhiyun /* Used for GHES mapping from assorted contexts */
111*4882a593Smuzhiyun FIX_APEI_GHES_IRQ,
112*4882a593Smuzhiyun FIX_APEI_GHES_NMI,
113*4882a593Smuzhiyun #endif
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun __end_of_permanent_fixed_addresses,
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun /*
118*4882a593Smuzhiyun * 512 temporary boot-time mappings, used by early_ioremap(),
119*4882a593Smuzhiyun * before ioremap() is functional.
120*4882a593Smuzhiyun *
121*4882a593Smuzhiyun * If necessary we round it up to the next 512 pages boundary so
122*4882a593Smuzhiyun * that we can have a single pmd entry and a single pte table:
123*4882a593Smuzhiyun */
124*4882a593Smuzhiyun #define NR_FIX_BTMAPS 64
125*4882a593Smuzhiyun #define FIX_BTMAPS_SLOTS 8
126*4882a593Smuzhiyun #define TOTAL_FIX_BTMAPS (NR_FIX_BTMAPS * FIX_BTMAPS_SLOTS)
127*4882a593Smuzhiyun FIX_BTMAP_END =
128*4882a593Smuzhiyun (__end_of_permanent_fixed_addresses ^
129*4882a593Smuzhiyun (__end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS - 1)) &
130*4882a593Smuzhiyun -PTRS_PER_PTE
131*4882a593Smuzhiyun ? __end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS -
132*4882a593Smuzhiyun (__end_of_permanent_fixed_addresses & (TOTAL_FIX_BTMAPS - 1))
133*4882a593Smuzhiyun : __end_of_permanent_fixed_addresses,
134*4882a593Smuzhiyun FIX_BTMAP_BEGIN = FIX_BTMAP_END + TOTAL_FIX_BTMAPS - 1,
135*4882a593Smuzhiyun #ifdef CONFIG_X86_32
136*4882a593Smuzhiyun FIX_WP_TEST,
137*4882a593Smuzhiyun #endif
138*4882a593Smuzhiyun #ifdef CONFIG_INTEL_TXT
139*4882a593Smuzhiyun FIX_TBOOT_BASE,
140*4882a593Smuzhiyun #endif
141*4882a593Smuzhiyun __end_of_fixed_addresses
142*4882a593Smuzhiyun };
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun extern void reserve_top_address(unsigned long reserve);
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun #define FIXADDR_SIZE (__end_of_permanent_fixed_addresses << PAGE_SHIFT)
148*4882a593Smuzhiyun #define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)
149*4882a593Smuzhiyun #define FIXADDR_TOT_SIZE (__end_of_fixed_addresses << PAGE_SHIFT)
150*4882a593Smuzhiyun #define FIXADDR_TOT_START (FIXADDR_TOP - FIXADDR_TOT_SIZE)
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun extern int fixmaps_set;
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun extern pte_t *kmap_pte;
155*4882a593Smuzhiyun extern pte_t *pkmap_page_table;
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun void __native_set_fixmap(enum fixed_addresses idx, pte_t pte);
158*4882a593Smuzhiyun void native_set_fixmap(unsigned /* enum fixed_addresses */ idx,
159*4882a593Smuzhiyun phys_addr_t phys, pgprot_t flags);
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun #ifndef CONFIG_PARAVIRT_XXL
__set_fixmap(enum fixed_addresses idx,phys_addr_t phys,pgprot_t flags)162*4882a593Smuzhiyun static inline void __set_fixmap(enum fixed_addresses idx,
163*4882a593Smuzhiyun phys_addr_t phys, pgprot_t flags)
164*4882a593Smuzhiyun {
165*4882a593Smuzhiyun native_set_fixmap(idx, phys, flags);
166*4882a593Smuzhiyun }
167*4882a593Smuzhiyun #endif
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun /*
170*4882a593Smuzhiyun * FIXMAP_PAGE_NOCACHE is used for MMIO. Memory encryption is not
171*4882a593Smuzhiyun * supported for MMIO addresses, so make sure that the memory encryption
172*4882a593Smuzhiyun * mask is not part of the page attributes.
173*4882a593Smuzhiyun */
174*4882a593Smuzhiyun #define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_IO_NOCACHE
175*4882a593Smuzhiyun
176*4882a593Smuzhiyun /*
177*4882a593Smuzhiyun * Early memremap routines used for in-place encryption. The mappings created
178*4882a593Smuzhiyun * by these routines are intended to be used as temporary mappings.
179*4882a593Smuzhiyun */
180*4882a593Smuzhiyun void __init *early_memremap_encrypted(resource_size_t phys_addr,
181*4882a593Smuzhiyun unsigned long size);
182*4882a593Smuzhiyun void __init *early_memremap_encrypted_wp(resource_size_t phys_addr,
183*4882a593Smuzhiyun unsigned long size);
184*4882a593Smuzhiyun void __init *early_memremap_decrypted(resource_size_t phys_addr,
185*4882a593Smuzhiyun unsigned long size);
186*4882a593Smuzhiyun void __init *early_memremap_decrypted_wp(resource_size_t phys_addr,
187*4882a593Smuzhiyun unsigned long size);
188*4882a593Smuzhiyun
189*4882a593Smuzhiyun #include <asm-generic/fixmap.h>
190*4882a593Smuzhiyun
191*4882a593Smuzhiyun #define __late_set_fixmap(idx, phys, flags) __set_fixmap(idx, phys, flags)
192*4882a593Smuzhiyun #define __late_clear_fixmap(idx) __set_fixmap(idx, 0, __pgprot(0))
193*4882a593Smuzhiyun
194*4882a593Smuzhiyun void __early_set_fixmap(enum fixed_addresses idx,
195*4882a593Smuzhiyun phys_addr_t phys, pgprot_t flags);
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun #endif /* !__ASSEMBLY__ */
198*4882a593Smuzhiyun #endif /* _ASM_X86_FIXMAP_H */
199