xref: /openbmc/linux/arch/x86/include/asm/fixmap.h (revision 2468f933)
1c577b098SGustavo F. Padovan /*
2c577b098SGustavo F. Padovan  * fixmap.h: compile-time virtual memory allocation
3c577b098SGustavo F. Padovan  *
4c577b098SGustavo F. Padovan  * This file is subject to the terms and conditions of the GNU General Public
5c577b098SGustavo F. Padovan  * License.  See the file "COPYING" in the main directory of this archive
6c577b098SGustavo F. Padovan  * for more details.
7c577b098SGustavo F. Padovan  *
8c577b098SGustavo F. Padovan  * Copyright (C) 1998 Ingo Molnar
9c577b098SGustavo F. Padovan  *
10c577b098SGustavo F. Padovan  * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
11c577b098SGustavo F. Padovan  * x86_32 and x86_64 integration by Gustavo F. Padovan, February 2009
12c577b098SGustavo F. Padovan  */
13c577b098SGustavo F. Padovan 
141965aae3SH. Peter Anvin #ifndef _ASM_X86_FIXMAP_H
151965aae3SH. Peter Anvin #define _ASM_X86_FIXMAP_H
16bb898558SAl Viro 
17*14df3267SThomas Gleixner #include <asm/kmap_size.h>
18*14df3267SThomas Gleixner 
1905ab1d8aSFeng Tang /*
2005ab1d8aSFeng Tang  * Exposed to assembly code for setting up initial page tables. Cannot be
2105ab1d8aSFeng Tang  * calculated in assembly code (fixmap entries are an enum), but is sanity
2205ab1d8aSFeng Tang  * checked in the actual fixmap C code to make sure that the fixmap is
2305ab1d8aSFeng Tang  * covered fully.
2405ab1d8aSFeng Tang  */
25*14df3267SThomas Gleixner #ifndef CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP
2605ab1d8aSFeng Tang # define FIXMAP_PMD_NUM	2
27*14df3267SThomas Gleixner #else
28*14df3267SThomas Gleixner # define KM_PMDS	(KM_MAX_IDX * ((CONFIG_NR_CPUS + 511) / 512))
29*14df3267SThomas Gleixner # define FIXMAP_PMD_NUM (KM_PMDS + 2)
30*14df3267SThomas Gleixner #endif
3105ab1d8aSFeng Tang /* fixmap starts downwards from the 507th entry in level2_fixmap_pgt */
3205ab1d8aSFeng Tang #define FIXMAP_PMD_TOP	507
3305ab1d8aSFeng Tang 
34c577b098SGustavo F. Padovan #ifndef __ASSEMBLY__
35c577b098SGustavo F. Padovan #include <linux/kernel.h>
36c577b098SGustavo F. Padovan #include <asm/apicdef.h>
37c577b098SGustavo F. Padovan #include <asm/page.h>
380cd39f46SPeter Zijlstra #include <asm/pgtable_types.h>
39bb898558SAl Viro #ifdef CONFIG_X86_32
40c577b098SGustavo F. Padovan #include <linux/threads.h>
41bb898558SAl Viro #else
42f40c3300SAndy Lutomirski #include <uapi/asm/vsyscall.h>
43c577b098SGustavo F. Padovan #endif
44c577b098SGustavo F. Padovan 
45c577b098SGustavo F. Padovan /*
46c577b098SGustavo F. Padovan  * We can't declare FIXADDR_TOP as variable for x86_64 because vsyscall
47c577b098SGustavo F. Padovan  * uses fixmaps that relies on FIXADDR_TOP for proper address calculation.
48c577b098SGustavo F. Padovan  * Because of this, FIXADDR_TOP x86 integration was left as later work.
49c577b098SGustavo F. Padovan  */
50c577b098SGustavo F. Padovan #ifdef CONFIG_X86_32
51c84b82ddSCao jin /*
52c577b098SGustavo F. Padovan  * Leave one empty page between vmalloc'ed areas and
53c577b098SGustavo F. Padovan  * the start of the fixmap.
54c577b098SGustavo F. Padovan  */
55c577b098SGustavo F. Padovan extern unsigned long __FIXADDR_TOP;
56c577b098SGustavo F. Padovan #define FIXADDR_TOP	((unsigned long)__FIXADDR_TOP)
57c577b098SGustavo F. Padovan #else
58f40c3300SAndy Lutomirski #define FIXADDR_TOP	(round_up(VSYSCALL_ADDR + PAGE_SIZE, 1<<PMD_SHIFT) - \
59f40c3300SAndy Lutomirski 			 PAGE_SIZE)
60c577b098SGustavo F. Padovan #endif
61c577b098SGustavo F. Padovan 
62ef8813abSAndy Lutomirski /*
63c577b098SGustavo F. Padovan  * Here we define all the compile-time 'special' virtual
64c577b098SGustavo F. Padovan  * addresses. The point is to have a constant address at
65c577b098SGustavo F. Padovan  * compile time, but to set the physical address only
66c577b098SGustavo F. Padovan  * in the boot process.
67c577b098SGustavo F. Padovan  * for x86_32: We allocate these special addresses
68c577b098SGustavo F. Padovan  * from the end of virtual memory (0xfffff000) backwards.
69c577b098SGustavo F. Padovan  * Also this lets us do fail-safe vmalloc(), we
70c577b098SGustavo F. Padovan  * can guarantee that these special addresses and
71c577b098SGustavo F. Padovan  * vmalloc()-ed addresses never overlap.
72c577b098SGustavo F. Padovan  *
73c577b098SGustavo F. Padovan  * These 'compile-time allocated' memory buffers are
74c577b098SGustavo F. Padovan  * fixed-size 4k pages (or larger if used with an increment
75c577b098SGustavo F. Padovan  * higher than 1). Use set_fixmap(idx,phys) to associate
76c577b098SGustavo F. Padovan  * physical memory with fixmap indices.
77c577b098SGustavo F. Padovan  *
78c577b098SGustavo F. Padovan  * TLB entries of such buffers will not be flushed across
79c577b098SGustavo F. Padovan  * task switches.
80c577b098SGustavo F. Padovan  */
81c577b098SGustavo F. Padovan enum fixed_addresses {
82c577b098SGustavo F. Padovan #ifdef CONFIG_X86_32
83c577b098SGustavo F. Padovan 	FIX_HOLE,
84c577b098SGustavo F. Padovan #else
851ad83c85SAndy Lutomirski #ifdef CONFIG_X86_VSYSCALL_EMULATION
86f40c3300SAndy Lutomirski 	VSYSCALL_PAGE = (FIXADDR_TOP - VSYSCALL_ADDR) >> PAGE_SHIFT,
871ad83c85SAndy Lutomirski #endif
88cbdce7b2SJan Beulich #endif
89c577b098SGustavo F. Padovan 	FIX_DBGP_BASE,
90c577b098SGustavo F. Padovan 	FIX_EARLYCON_MEM_BASE,
91ff30a054SJan Beulich #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
92ff30a054SJan Beulich 	FIX_OHCI1394_BASE,
93ff30a054SJan Beulich #endif
94c577b098SGustavo F. Padovan #ifdef CONFIG_X86_LOCAL_APIC
95c577b098SGustavo F. Padovan 	FIX_APIC_BASE,	/* local (CPU) APIC) -- required for SMP or not */
96c577b098SGustavo F. Padovan #endif
97c577b098SGustavo F. Padovan #ifdef CONFIG_X86_IO_APIC
98c577b098SGustavo F. Padovan 	FIX_IO_APIC_BASE_0,
99c577b098SGustavo F. Padovan 	FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS - 1,
100c577b098SGustavo F. Padovan #endif
101*14df3267SThomas Gleixner #ifdef CONFIG_KMAP_LOCAL
102c577b098SGustavo F. Padovan 	FIX_KMAP_BEGIN,	/* reserved pte's for temporary kernel mappings */
103157e118bSThomas Gleixner 	FIX_KMAP_END = FIX_KMAP_BEGIN + (KM_MAX_IDX * NR_CPUS) - 1,
104c577b098SGustavo F. Padovan #ifdef CONFIG_PCI_MMCONFIG
105c577b098SGustavo F. Padovan 	FIX_PCIE_MCFG,
106c577b098SGustavo F. Padovan #endif
107c577b098SGustavo F. Padovan #endif
108ecac7181SJuergen Gross #ifdef CONFIG_PARAVIRT_XXL
109c577b098SGustavo F. Padovan 	FIX_PARAVIRT_BOOTMAP,
110c577b098SGustavo F. Padovan #endif
11169218e47SThomas Garnier 
1124f89fa28SJames Morse #ifdef CONFIG_ACPI_APEI_GHES
1134f89fa28SJames Morse 	/* Used for GHES mapping from assorted contexts */
1144f89fa28SJames Morse 	FIX_APEI_GHES_IRQ,
1154f89fa28SJames Morse 	FIX_APEI_GHES_NMI,
1164f89fa28SJames Morse #endif
1174f89fa28SJames Morse 
118fa36e956SArjan van de Ven 	__end_of_permanent_fixed_addresses,
119fa36e956SArjan van de Ven 
120c577b098SGustavo F. Padovan 	/*
1213eddc69fSDave Young 	 * 512 temporary boot-time mappings, used by early_ioremap(),
122c577b098SGustavo F. Padovan 	 * before ioremap() is functional.
123c577b098SGustavo F. Padovan 	 *
1243eddc69fSDave Young 	 * If necessary we round it up to the next 512 pages boundary so
125c84b82ddSCao jin 	 * that we can have a single pmd entry and a single pte table:
126c577b098SGustavo F. Padovan 	 */
127c577b098SGustavo F. Padovan #define NR_FIX_BTMAPS		64
1283eddc69fSDave Young #define FIX_BTMAPS_SLOTS	8
129499a5f1eSJan Beulich #define TOTAL_FIX_BTMAPS	(NR_FIX_BTMAPS * FIX_BTMAPS_SLOTS)
130499a5f1eSJan Beulich 	FIX_BTMAP_END =
131499a5f1eSJan Beulich 	 (__end_of_permanent_fixed_addresses ^
132499a5f1eSJan Beulich 	  (__end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS - 1)) &
133499a5f1eSJan Beulich 	 -PTRS_PER_PTE
134499a5f1eSJan Beulich 	 ? __end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS -
135499a5f1eSJan Beulich 	   (__end_of_permanent_fixed_addresses & (TOTAL_FIX_BTMAPS - 1))
136499a5f1eSJan Beulich 	 : __end_of_permanent_fixed_addresses,
137499a5f1eSJan Beulich 	FIX_BTMAP_BEGIN = FIX_BTMAP_END + TOTAL_FIX_BTMAPS - 1,
138c577b098SGustavo F. Padovan #ifdef CONFIG_X86_32
139c577b098SGustavo F. Padovan 	FIX_WP_TEST,
140c577b098SGustavo F. Padovan #endif
14131625340SJoseph Cihula #ifdef CONFIG_INTEL_TXT
14231625340SJoseph Cihula 	FIX_TBOOT_BASE,
14331625340SJoseph Cihula #endif
144c577b098SGustavo F. Padovan 	__end_of_fixed_addresses
145c577b098SGustavo F. Padovan };
146c577b098SGustavo F. Padovan 
147c577b098SGustavo F. Padovan 
148c577b098SGustavo F. Padovan extern void reserve_top_address(unsigned long reserve);
149c577b098SGustavo F. Padovan 
150c577b098SGustavo F. Padovan #define FIXADDR_SIZE		(__end_of_permanent_fixed_addresses << PAGE_SHIFT)
151c577b098SGustavo F. Padovan #define FIXADDR_START		(FIXADDR_TOP - FIXADDR_SIZE)
15255f49fcbSWilliam Grant #define FIXADDR_TOT_SIZE	(__end_of_fixed_addresses << PAGE_SHIFT)
15355f49fcbSWilliam Grant #define FIXADDR_TOT_START	(FIXADDR_TOP - FIXADDR_TOT_SIZE)
154bb898558SAl Viro 
155bb898558SAl Viro extern int fixmaps_set;
156bb898558SAl Viro 
157fd940934SKeith Packard extern pte_t *pkmap_page_table;
158fd940934SKeith Packard 
159bb898558SAl Viro void __native_set_fixmap(enum fixed_addresses idx, pte_t pte);
160f53e2cd0SSami Tolvanen void native_set_fixmap(unsigned /* enum fixed_addresses */ idx,
1613b3809acSMasami Hiramatsu 		       phys_addr_t phys, pgprot_t flags);
162bb898558SAl Viro 
163fdc0269eSJuergen Gross #ifndef CONFIG_PARAVIRT_XXL
__set_fixmap(enum fixed_addresses idx,phys_addr_t phys,pgprot_t flags)164bb898558SAl Viro static inline void __set_fixmap(enum fixed_addresses idx,
1653b3809acSMasami Hiramatsu 				phys_addr_t phys, pgprot_t flags)
166bb898558SAl Viro {
167bb898558SAl Viro 	native_set_fixmap(idx, phys, flags);
168bb898558SAl Viro }
169bb898558SAl Viro #endif
170bb898558SAl Viro 
17121729f81STom Lendacky /*
17221729f81STom Lendacky  * FIXMAP_PAGE_NOCACHE is used for MMIO. Memory encryption is not
17321729f81STom Lendacky  * supported for MMIO addresses, so make sure that the memory encryption
17421729f81STom Lendacky  * mask is not part of the page attributes.
17521729f81STom Lendacky  */
17621729f81STom Lendacky #define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_IO_NOCACHE
17721729f81STom Lendacky 
178f88a68faSTom Lendacky /*
179f88a68faSTom Lendacky  * Early memremap routines used for in-place encryption. The mappings created
180f88a68faSTom Lendacky  * by these routines are intended to be used as temporary mappings.
181f88a68faSTom Lendacky  */
182f88a68faSTom Lendacky void __init *early_memremap_encrypted(resource_size_t phys_addr,
183f88a68faSTom Lendacky 				      unsigned long size);
184f88a68faSTom Lendacky void __init *early_memremap_encrypted_wp(resource_size_t phys_addr,
185f88a68faSTom Lendacky 					 unsigned long size);
186f88a68faSTom Lendacky void __init *early_memremap_decrypted(resource_size_t phys_addr,
187f88a68faSTom Lendacky 				      unsigned long size);
188f88a68faSTom Lendacky void __init *early_memremap_decrypted_wp(resource_size_t phys_addr,
189f88a68faSTom Lendacky 					 unsigned long size);
190f88a68faSTom Lendacky 
191114cefc8SMark Salter #include <asm-generic/fixmap.h>
1925a47c7daSFeng Tang 
1935b7c73e0SMark Salter #define __late_set_fixmap(idx, phys, flags) __set_fixmap(idx, phys, flags)
1945b7c73e0SMark Salter #define __late_clear_fixmap(idx) __set_fixmap(idx, 0, __pgprot(0))
1955b7c73e0SMark Salter 
1965b7c73e0SMark Salter void __early_set_fixmap(enum fixed_addresses idx,
1975b7c73e0SMark Salter 			phys_addr_t phys, pgprot_t flags);
1985b7c73e0SMark Salter 
199c577b098SGustavo F. Padovan #endif /* !__ASSEMBLY__ */
2001965aae3SH. Peter Anvin #endif /* _ASM_X86_FIXMAP_H */
201