xref: /openbmc/linux/arch/x86/include/asm/fixmap.h (revision 71056ae2)
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 
17c577b098SGustavo F. Padovan #ifndef __ASSEMBLY__
18c577b098SGustavo F. Padovan #include <linux/kernel.h>
19c577b098SGustavo F. Padovan #include <asm/acpi.h>
20c577b098SGustavo F. Padovan #include <asm/apicdef.h>
21c577b098SGustavo F. Padovan #include <asm/page.h>
2271056ae2SMarcelo Tosatti #include <asm/pvclock.h>
23bb898558SAl Viro #ifdef CONFIG_X86_32
24c577b098SGustavo F. Padovan #include <linux/threads.h>
25c577b098SGustavo F. Padovan #include <asm/kmap_types.h>
26bb898558SAl Viro #else
27c577b098SGustavo F. Padovan #include <asm/vsyscall.h>
28c577b098SGustavo F. Padovan #endif
29c577b098SGustavo F. Padovan 
30c577b098SGustavo F. Padovan /*
31c577b098SGustavo F. Padovan  * We can't declare FIXADDR_TOP as variable for x86_64 because vsyscall
32c577b098SGustavo F. Padovan  * uses fixmaps that relies on FIXADDR_TOP for proper address calculation.
33c577b098SGustavo F. Padovan  * Because of this, FIXADDR_TOP x86 integration was left as later work.
34c577b098SGustavo F. Padovan  */
35c577b098SGustavo F. Padovan #ifdef CONFIG_X86_32
36c577b098SGustavo F. Padovan /* used by vmalloc.c, vsyscall.lds.S.
37c577b098SGustavo F. Padovan  *
38c577b098SGustavo F. Padovan  * Leave one empty page between vmalloc'ed areas and
39c577b098SGustavo F. Padovan  * the start of the fixmap.
40c577b098SGustavo F. Padovan  */
41c577b098SGustavo F. Padovan extern unsigned long __FIXADDR_TOP;
42c577b098SGustavo F. Padovan #define FIXADDR_TOP	((unsigned long)__FIXADDR_TOP)
43c577b098SGustavo F. Padovan 
44c577b098SGustavo F. Padovan #define FIXADDR_USER_START     __fix_to_virt(FIX_VDSO)
45c577b098SGustavo F. Padovan #define FIXADDR_USER_END       __fix_to_virt(FIX_VDSO - 1)
46c577b098SGustavo F. Padovan #else
47c577b098SGustavo F. Padovan #define FIXADDR_TOP	(VSYSCALL_END-PAGE_SIZE)
48c577b098SGustavo F. Padovan 
49c577b098SGustavo F. Padovan /* Only covers 32bit vsyscalls currently. Need another set for 64bit. */
50c577b098SGustavo F. Padovan #define FIXADDR_USER_START	((unsigned long)VSYSCALL32_VSYSCALL)
51c577b098SGustavo F. Padovan #define FIXADDR_USER_END	(FIXADDR_USER_START + PAGE_SIZE)
52c577b098SGustavo F. Padovan #endif
53c577b098SGustavo F. Padovan 
54c577b098SGustavo F. Padovan 
55c577b098SGustavo F. Padovan /*
56c577b098SGustavo F. Padovan  * Here we define all the compile-time 'special' virtual
57c577b098SGustavo F. Padovan  * addresses. The point is to have a constant address at
58c577b098SGustavo F. Padovan  * compile time, but to set the physical address only
59c577b098SGustavo F. Padovan  * in the boot process.
60c577b098SGustavo F. Padovan  * for x86_32: We allocate these special addresses
61c577b098SGustavo F. Padovan  * from the end of virtual memory (0xfffff000) backwards.
62c577b098SGustavo F. Padovan  * Also this lets us do fail-safe vmalloc(), we
63c577b098SGustavo F. Padovan  * can guarantee that these special addresses and
64c577b098SGustavo F. Padovan  * vmalloc()-ed addresses never overlap.
65c577b098SGustavo F. Padovan  *
66c577b098SGustavo F. Padovan  * These 'compile-time allocated' memory buffers are
67c577b098SGustavo F. Padovan  * fixed-size 4k pages (or larger if used with an increment
68c577b098SGustavo F. Padovan  * higher than 1). Use set_fixmap(idx,phys) to associate
69c577b098SGustavo F. Padovan  * physical memory with fixmap indices.
70c577b098SGustavo F. Padovan  *
71c577b098SGustavo F. Padovan  * TLB entries of such buffers will not be flushed across
72c577b098SGustavo F. Padovan  * task switches.
73c577b098SGustavo F. Padovan  */
74c577b098SGustavo F. Padovan enum fixed_addresses {
75c577b098SGustavo F. Padovan #ifdef CONFIG_X86_32
76c577b098SGustavo F. Padovan 	FIX_HOLE,
77c577b098SGustavo F. Padovan 	FIX_VDSO,
78c577b098SGustavo F. Padovan #else
79c577b098SGustavo F. Padovan 	VSYSCALL_LAST_PAGE,
80c577b098SGustavo F. Padovan 	VSYSCALL_FIRST_PAGE = VSYSCALL_LAST_PAGE
81c577b098SGustavo F. Padovan 			    + ((VSYSCALL_END-VSYSCALL_START) >> PAGE_SHIFT) - 1,
829fd67b4eSAndy Lutomirski 	VVAR_PAGE,
83c577b098SGustavo F. Padovan 	VSYSCALL_HPET,
84c577b098SGustavo F. Padovan #endif
8571056ae2SMarcelo Tosatti #ifdef CONFIG_PARAVIRT_CLOCK
8671056ae2SMarcelo Tosatti 	PVCLOCK_FIXMAP_BEGIN,
8771056ae2SMarcelo Tosatti 	PVCLOCK_FIXMAP_END = PVCLOCK_FIXMAP_BEGIN+PVCLOCK_VSYSCALL_NR_PAGES-1,
8871056ae2SMarcelo Tosatti #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
101c577b098SGustavo F. Padovan #ifdef CONFIG_X86_VISWS_APIC
102c577b098SGustavo F. Padovan 	FIX_CO_CPU,	/* Cobalt timer */
103c577b098SGustavo F. Padovan 	FIX_CO_APIC,	/* Cobalt APIC Redirection Table */
104c577b098SGustavo F. Padovan 	FIX_LI_PCIA,	/* Lithium PCI Bridge A */
105c577b098SGustavo F. Padovan 	FIX_LI_PCIB,	/* Lithium PCI Bridge B */
106c577b098SGustavo F. Padovan #endif
107c577b098SGustavo F. Padovan #ifdef CONFIG_X86_F00F_BUG
108c577b098SGustavo F. Padovan 	FIX_F00F_IDT,	/* Virtual mapping for IDT */
109c577b098SGustavo F. Padovan #endif
110c577b098SGustavo F. Padovan #ifdef CONFIG_X86_CYCLONE_TIMER
111c577b098SGustavo F. Padovan 	FIX_CYCLONE_TIMER, /*cyclone timer register*/
112c577b098SGustavo F. Padovan #endif
113c577b098SGustavo F. Padovan #ifdef CONFIG_X86_32
114c577b098SGustavo F. Padovan 	FIX_KMAP_BEGIN,	/* reserved pte's for temporary kernel mappings */
115c577b098SGustavo F. Padovan 	FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
116c577b098SGustavo F. Padovan #ifdef CONFIG_PCI_MMCONFIG
117c577b098SGustavo F. Padovan 	FIX_PCIE_MCFG,
118c577b098SGustavo F. Padovan #endif
119c577b098SGustavo F. Padovan #endif
120c577b098SGustavo F. Padovan #ifdef CONFIG_PARAVIRT
121c577b098SGustavo F. Padovan 	FIX_PARAVIRT_BOOTMAP,
122c577b098SGustavo F. Padovan #endif
12312b9d7ccSMathieu Desnoyers 	FIX_TEXT_POKE1,	/* reserve 2 pages for text_poke() */
12412b9d7ccSMathieu Desnoyers 	FIX_TEXT_POKE0, /* first page is last, because allocation is backward */
125933b9463SAlan Cox #ifdef	CONFIG_X86_INTEL_MID
1267309282cSFeng Tang 	FIX_LNW_VRTC,
1277309282cSFeng Tang #endif
128fa36e956SArjan van de Ven 	__end_of_permanent_fixed_addresses,
129fa36e956SArjan van de Ven 
130c577b098SGustavo F. Padovan 	/*
131c577b098SGustavo F. Padovan 	 * 256 temporary boot-time mappings, used by early_ioremap(),
132c577b098SGustavo F. Padovan 	 * before ioremap() is functional.
133c577b098SGustavo F. Padovan 	 *
134499a5f1eSJan Beulich 	 * If necessary we round it up to the next 256 pages boundary so
135499a5f1eSJan Beulich 	 * that we can have a single pgd entry and a single pte table:
136c577b098SGustavo F. Padovan 	 */
137c577b098SGustavo F. Padovan #define NR_FIX_BTMAPS		64
138c577b098SGustavo F. Padovan #define FIX_BTMAPS_SLOTS	4
139499a5f1eSJan Beulich #define TOTAL_FIX_BTMAPS	(NR_FIX_BTMAPS * FIX_BTMAPS_SLOTS)
140499a5f1eSJan Beulich 	FIX_BTMAP_END =
141499a5f1eSJan Beulich 	 (__end_of_permanent_fixed_addresses ^
142499a5f1eSJan Beulich 	  (__end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS - 1)) &
143499a5f1eSJan Beulich 	 -PTRS_PER_PTE
144499a5f1eSJan Beulich 	 ? __end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS -
145499a5f1eSJan Beulich 	   (__end_of_permanent_fixed_addresses & (TOTAL_FIX_BTMAPS - 1))
146499a5f1eSJan Beulich 	 : __end_of_permanent_fixed_addresses,
147499a5f1eSJan Beulich 	FIX_BTMAP_BEGIN = FIX_BTMAP_END + TOTAL_FIX_BTMAPS - 1,
148c577b098SGustavo F. Padovan #ifdef CONFIG_X86_32
149c577b098SGustavo F. Padovan 	FIX_WP_TEST,
150c577b098SGustavo F. Padovan #endif
15131625340SJoseph Cihula #ifdef CONFIG_INTEL_TXT
15231625340SJoseph Cihula 	FIX_TBOOT_BASE,
15331625340SJoseph Cihula #endif
154c577b098SGustavo F. Padovan 	__end_of_fixed_addresses
155c577b098SGustavo F. Padovan };
156c577b098SGustavo F. Padovan 
157c577b098SGustavo F. Padovan 
158c577b098SGustavo F. Padovan extern void reserve_top_address(unsigned long reserve);
159c577b098SGustavo F. Padovan 
160c577b098SGustavo F. Padovan #define FIXADDR_SIZE	(__end_of_permanent_fixed_addresses << PAGE_SHIFT)
161c577b098SGustavo F. Padovan #define FIXADDR_BOOT_SIZE	(__end_of_fixed_addresses << PAGE_SHIFT)
162c577b098SGustavo F. Padovan #define FIXADDR_START		(FIXADDR_TOP - FIXADDR_SIZE)
163c577b098SGustavo F. Padovan #define FIXADDR_BOOT_START	(FIXADDR_TOP - FIXADDR_BOOT_SIZE)
164bb898558SAl Viro 
165bb898558SAl Viro extern int fixmaps_set;
166bb898558SAl Viro 
167fd940934SKeith Packard extern pte_t *kmap_pte;
168fd940934SKeith Packard extern pgprot_t kmap_prot;
169fd940934SKeith Packard extern pte_t *pkmap_page_table;
170fd940934SKeith Packard 
171bb898558SAl Viro void __native_set_fixmap(enum fixed_addresses idx, pte_t pte);
172bb898558SAl Viro void native_set_fixmap(enum fixed_addresses idx,
1733b3809acSMasami Hiramatsu 		       phys_addr_t phys, pgprot_t flags);
174bb898558SAl Viro 
175bb898558SAl Viro #ifndef CONFIG_PARAVIRT
176bb898558SAl Viro static inline void __set_fixmap(enum fixed_addresses idx,
1773b3809acSMasami Hiramatsu 				phys_addr_t phys, pgprot_t flags)
178bb898558SAl Viro {
179bb898558SAl Viro 	native_set_fixmap(idx, phys, flags);
180bb898558SAl Viro }
181bb898558SAl Viro #endif
182bb898558SAl Viro 
183bb898558SAl Viro #define set_fixmap(idx, phys)				\
184bb898558SAl Viro 	__set_fixmap(idx, phys, PAGE_KERNEL)
185bb898558SAl Viro 
186bb898558SAl Viro /*
187bb898558SAl Viro  * Some hardware wants to get fixmapped without caching.
188bb898558SAl Viro  */
189bb898558SAl Viro #define set_fixmap_nocache(idx, phys)			\
190bb898558SAl Viro 	__set_fixmap(idx, phys, PAGE_KERNEL_NOCACHE)
191bb898558SAl Viro 
192bb898558SAl Viro #define clear_fixmap(idx)			\
193bb898558SAl Viro 	__set_fixmap(idx, 0, __pgprot(0))
194bb898558SAl Viro 
195bb898558SAl Viro #define __fix_to_virt(x)	(FIXADDR_TOP - ((x) << PAGE_SHIFT))
196bb898558SAl Viro #define __virt_to_fix(x)	((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
197bb898558SAl Viro 
198bb898558SAl Viro extern void __this_fixmap_does_not_exist(void);
199bb898558SAl Viro 
200bb898558SAl Viro /*
201bb898558SAl Viro  * 'index to address' translation. If anyone tries to use the idx
202bb898558SAl Viro  * directly without translation, we catch the bug with a NULL-deference
203bb898558SAl Viro  * kernel oops. Illegal ranges of incoming indices are caught too.
204bb898558SAl Viro  */
205bb898558SAl Viro static __always_inline unsigned long fix_to_virt(const unsigned int idx)
206bb898558SAl Viro {
207bb898558SAl Viro 	/*
208bb898558SAl Viro 	 * this branch gets completely eliminated after inlining,
209bb898558SAl Viro 	 * except when someone tries to use fixaddr indices in an
210bb898558SAl Viro 	 * illegal way. (such as mixing up address types or using
211bb898558SAl Viro 	 * out-of-range indices).
212bb898558SAl Viro 	 *
213bb898558SAl Viro 	 * If it doesn't get removed, the linker will complain
214bb898558SAl Viro 	 * loudly with a reasonably clear error message..
215bb898558SAl Viro 	 */
216bb898558SAl Viro 	if (idx >= __end_of_fixed_addresses)
217bb898558SAl Viro 		__this_fixmap_does_not_exist();
218bb898558SAl Viro 
219bb898558SAl Viro 	return __fix_to_virt(idx);
220bb898558SAl Viro }
221bb898558SAl Viro 
222bb898558SAl Viro static inline unsigned long virt_to_fix(const unsigned long vaddr)
223bb898558SAl Viro {
224bb898558SAl Viro 	BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
225bb898558SAl Viro 	return __virt_to_fix(vaddr);
226bb898558SAl Viro }
2275a47c7daSFeng Tang 
2285a47c7daSFeng Tang /* Return an pointer with offset calculated */
22991d95fdaSAndrew Morton static __always_inline unsigned long
23091d95fdaSAndrew Morton __set_fixmap_offset(enum fixed_addresses idx, phys_addr_t phys, pgprot_t flags)
2315a47c7daSFeng Tang {
2325a47c7daSFeng Tang 	__set_fixmap(idx, phys, flags);
2335a47c7daSFeng Tang 	return fix_to_virt(idx) + (phys & (PAGE_SIZE - 1));
2345a47c7daSFeng Tang }
2355a47c7daSFeng Tang 
2365a47c7daSFeng Tang #define set_fixmap_offset(idx, phys)			\
2375a47c7daSFeng Tang 	__set_fixmap_offset(idx, phys, PAGE_KERNEL)
2385a47c7daSFeng Tang 
2395a47c7daSFeng Tang #define set_fixmap_offset_nocache(idx, phys)			\
2405a47c7daSFeng Tang 	__set_fixmap_offset(idx, phys, PAGE_KERNEL_NOCACHE)
2415a47c7daSFeng Tang 
242c577b098SGustavo F. Padovan #endif /* !__ASSEMBLY__ */
2431965aae3SH. Peter Anvin #endif /* _ASM_X86_FIXMAP_H */
244