xref: /openbmc/linux/arch/x86/include/asm/fixmap.h (revision 12b9d7cc)
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>
22bb898558SAl Viro #ifdef CONFIG_X86_32
23c577b098SGustavo F. Padovan #include <linux/threads.h>
24c577b098SGustavo F. Padovan #include <asm/kmap_types.h>
25bb898558SAl Viro #else
26c577b098SGustavo F. Padovan #include <asm/vsyscall.h>
27c577b098SGustavo F. Padovan #endif
28c577b098SGustavo F. Padovan 
29c577b098SGustavo F. Padovan /*
30c577b098SGustavo F. Padovan  * We can't declare FIXADDR_TOP as variable for x86_64 because vsyscall
31c577b098SGustavo F. Padovan  * uses fixmaps that relies on FIXADDR_TOP for proper address calculation.
32c577b098SGustavo F. Padovan  * Because of this, FIXADDR_TOP x86 integration was left as later work.
33c577b098SGustavo F. Padovan  */
34c577b098SGustavo F. Padovan #ifdef CONFIG_X86_32
35c577b098SGustavo F. Padovan /* used by vmalloc.c, vsyscall.lds.S.
36c577b098SGustavo F. Padovan  *
37c577b098SGustavo F. Padovan  * Leave one empty page between vmalloc'ed areas and
38c577b098SGustavo F. Padovan  * the start of the fixmap.
39c577b098SGustavo F. Padovan  */
40c577b098SGustavo F. Padovan extern unsigned long __FIXADDR_TOP;
41c577b098SGustavo F. Padovan #define FIXADDR_TOP	((unsigned long)__FIXADDR_TOP)
42c577b098SGustavo F. Padovan 
43c577b098SGustavo F. Padovan #define FIXADDR_USER_START     __fix_to_virt(FIX_VDSO)
44c577b098SGustavo F. Padovan #define FIXADDR_USER_END       __fix_to_virt(FIX_VDSO - 1)
45c577b098SGustavo F. Padovan #else
46c577b098SGustavo F. Padovan #define FIXADDR_TOP	(VSYSCALL_END-PAGE_SIZE)
47c577b098SGustavo F. Padovan 
48c577b098SGustavo F. Padovan /* Only covers 32bit vsyscalls currently. Need another set for 64bit. */
49c577b098SGustavo F. Padovan #define FIXADDR_USER_START	((unsigned long)VSYSCALL32_VSYSCALL)
50c577b098SGustavo F. Padovan #define FIXADDR_USER_END	(FIXADDR_USER_START + PAGE_SIZE)
51c577b098SGustavo F. Padovan #endif
52c577b098SGustavo F. Padovan 
53c577b098SGustavo F. Padovan 
54c577b098SGustavo F. Padovan /*
55c577b098SGustavo F. Padovan  * Here we define all the compile-time 'special' virtual
56c577b098SGustavo F. Padovan  * addresses. The point is to have a constant address at
57c577b098SGustavo F. Padovan  * compile time, but to set the physical address only
58c577b098SGustavo F. Padovan  * in the boot process.
59c577b098SGustavo F. Padovan  * for x86_32: We allocate these special addresses
60c577b098SGustavo F. Padovan  * from the end of virtual memory (0xfffff000) backwards.
61c577b098SGustavo F. Padovan  * Also this lets us do fail-safe vmalloc(), we
62c577b098SGustavo F. Padovan  * can guarantee that these special addresses and
63c577b098SGustavo F. Padovan  * vmalloc()-ed addresses never overlap.
64c577b098SGustavo F. Padovan  *
65c577b098SGustavo F. Padovan  * These 'compile-time allocated' memory buffers are
66c577b098SGustavo F. Padovan  * fixed-size 4k pages (or larger if used with an increment
67c577b098SGustavo F. Padovan  * higher than 1). Use set_fixmap(idx,phys) to associate
68c577b098SGustavo F. Padovan  * physical memory with fixmap indices.
69c577b098SGustavo F. Padovan  *
70c577b098SGustavo F. Padovan  * TLB entries of such buffers will not be flushed across
71c577b098SGustavo F. Padovan  * task switches.
72c577b098SGustavo F. Padovan  */
73c577b098SGustavo F. Padovan enum fixed_addresses {
74c577b098SGustavo F. Padovan #ifdef CONFIG_X86_32
75c577b098SGustavo F. Padovan 	FIX_HOLE,
76c577b098SGustavo F. Padovan 	FIX_VDSO,
77c577b098SGustavo F. Padovan #else
78c577b098SGustavo F. Padovan 	VSYSCALL_LAST_PAGE,
79c577b098SGustavo F. Padovan 	VSYSCALL_FIRST_PAGE = VSYSCALL_LAST_PAGE
80c577b098SGustavo F. Padovan 			    + ((VSYSCALL_END-VSYSCALL_START) >> PAGE_SHIFT) - 1,
81c577b098SGustavo F. Padovan 	VSYSCALL_HPET,
82c577b098SGustavo F. Padovan #endif
83c577b098SGustavo F. Padovan 	FIX_DBGP_BASE,
84c577b098SGustavo F. Padovan 	FIX_EARLYCON_MEM_BASE,
85c577b098SGustavo F. Padovan #ifdef CONFIG_X86_LOCAL_APIC
86c577b098SGustavo F. Padovan 	FIX_APIC_BASE,	/* local (CPU) APIC) -- required for SMP or not */
87c577b098SGustavo F. Padovan #endif
88c577b098SGustavo F. Padovan #ifdef CONFIG_X86_IO_APIC
89c577b098SGustavo F. Padovan 	FIX_IO_APIC_BASE_0,
90c577b098SGustavo F. Padovan 	FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS - 1,
91c577b098SGustavo F. Padovan #endif
92c577b098SGustavo F. Padovan #ifdef CONFIG_X86_VISWS_APIC
93c577b098SGustavo F. Padovan 	FIX_CO_CPU,	/* Cobalt timer */
94c577b098SGustavo F. Padovan 	FIX_CO_APIC,	/* Cobalt APIC Redirection Table */
95c577b098SGustavo F. Padovan 	FIX_LI_PCIA,	/* Lithium PCI Bridge A */
96c577b098SGustavo F. Padovan 	FIX_LI_PCIB,	/* Lithium PCI Bridge B */
97c577b098SGustavo F. Padovan #endif
98c577b098SGustavo F. Padovan #ifdef CONFIG_X86_F00F_BUG
99c577b098SGustavo F. Padovan 	FIX_F00F_IDT,	/* Virtual mapping for IDT */
100c577b098SGustavo F. Padovan #endif
101c577b098SGustavo F. Padovan #ifdef CONFIG_X86_CYCLONE_TIMER
102c577b098SGustavo F. Padovan 	FIX_CYCLONE_TIMER, /*cyclone timer register*/
103c577b098SGustavo F. Padovan #endif
104c577b098SGustavo F. Padovan #ifdef CONFIG_X86_32
105c577b098SGustavo F. Padovan 	FIX_KMAP_BEGIN,	/* reserved pte's for temporary kernel mappings */
106c577b098SGustavo F. Padovan 	FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
107c577b098SGustavo F. Padovan #ifdef CONFIG_PCI_MMCONFIG
108c577b098SGustavo F. Padovan 	FIX_PCIE_MCFG,
109c577b098SGustavo F. Padovan #endif
110c577b098SGustavo F. Padovan #endif
111c577b098SGustavo F. Padovan #ifdef CONFIG_PARAVIRT
112c577b098SGustavo F. Padovan 	FIX_PARAVIRT_BOOTMAP,
113c577b098SGustavo F. Padovan #endif
11412b9d7ccSMathieu Desnoyers 	FIX_TEXT_POKE1,	/* reserve 2 pages for text_poke() */
11512b9d7ccSMathieu Desnoyers 	FIX_TEXT_POKE0, /* first page is last, because allocation is backward */
116c577b098SGustavo F. Padovan 	__end_of_permanent_fixed_addresses,
117c577b098SGustavo F. Padovan 	/*
118c577b098SGustavo F. Padovan 	 * 256 temporary boot-time mappings, used by early_ioremap(),
119c577b098SGustavo F. Padovan 	 * before ioremap() is functional.
120c577b098SGustavo F. Padovan 	 *
121c577b098SGustavo F. Padovan 	 * We round it up to the next 256 pages boundary so that we
122c577b098SGustavo F. Padovan 	 * can have a single pgd entry and a single pte table:
123c577b098SGustavo F. Padovan 	 */
124c577b098SGustavo F. Padovan #define NR_FIX_BTMAPS		64
125c577b098SGustavo F. Padovan #define FIX_BTMAPS_SLOTS	4
126c577b098SGustavo F. Padovan 	FIX_BTMAP_END = __end_of_permanent_fixed_addresses + 256 -
127c577b098SGustavo F. Padovan 			(__end_of_permanent_fixed_addresses & 255),
128c577b098SGustavo F. Padovan 	FIX_BTMAP_BEGIN = FIX_BTMAP_END + NR_FIX_BTMAPS*FIX_BTMAPS_SLOTS - 1,
129789d03f5SJan Beulich #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
130789d03f5SJan Beulich 	FIX_OHCI1394_BASE,
131789d03f5SJan Beulich #endif
132c577b098SGustavo F. Padovan #ifdef CONFIG_X86_32
133c577b098SGustavo F. Padovan 	FIX_WP_TEST,
134c577b098SGustavo F. Padovan #endif
135c577b098SGustavo F. Padovan 	__end_of_fixed_addresses
136c577b098SGustavo F. Padovan };
137c577b098SGustavo F. Padovan 
138c577b098SGustavo F. Padovan 
139c577b098SGustavo F. Padovan extern void reserve_top_address(unsigned long reserve);
140c577b098SGustavo F. Padovan 
141c577b098SGustavo F. Padovan #define FIXADDR_SIZE	(__end_of_permanent_fixed_addresses << PAGE_SHIFT)
142c577b098SGustavo F. Padovan #define FIXADDR_BOOT_SIZE	(__end_of_fixed_addresses << PAGE_SHIFT)
143c577b098SGustavo F. Padovan #define FIXADDR_START		(FIXADDR_TOP - FIXADDR_SIZE)
144c577b098SGustavo F. Padovan #define FIXADDR_BOOT_START	(FIXADDR_TOP - FIXADDR_BOOT_SIZE)
145bb898558SAl Viro 
146bb898558SAl Viro extern int fixmaps_set;
147bb898558SAl Viro 
148fd940934SKeith Packard extern pte_t *kmap_pte;
149fd940934SKeith Packard extern pgprot_t kmap_prot;
150fd940934SKeith Packard extern pte_t *pkmap_page_table;
151fd940934SKeith Packard 
152bb898558SAl Viro void __native_set_fixmap(enum fixed_addresses idx, pte_t pte);
153bb898558SAl Viro void native_set_fixmap(enum fixed_addresses idx,
1543b3809acSMasami Hiramatsu 		       phys_addr_t phys, pgprot_t flags);
155bb898558SAl Viro 
156bb898558SAl Viro #ifndef CONFIG_PARAVIRT
157bb898558SAl Viro static inline void __set_fixmap(enum fixed_addresses idx,
1583b3809acSMasami Hiramatsu 				phys_addr_t phys, pgprot_t flags)
159bb898558SAl Viro {
160bb898558SAl Viro 	native_set_fixmap(idx, phys, flags);
161bb898558SAl Viro }
162bb898558SAl Viro #endif
163bb898558SAl Viro 
164bb898558SAl Viro #define set_fixmap(idx, phys)				\
165bb898558SAl Viro 	__set_fixmap(idx, phys, PAGE_KERNEL)
166bb898558SAl Viro 
167bb898558SAl Viro /*
168bb898558SAl Viro  * Some hardware wants to get fixmapped without caching.
169bb898558SAl Viro  */
170bb898558SAl Viro #define set_fixmap_nocache(idx, phys)			\
171bb898558SAl Viro 	__set_fixmap(idx, phys, PAGE_KERNEL_NOCACHE)
172bb898558SAl Viro 
173bb898558SAl Viro #define clear_fixmap(idx)			\
174bb898558SAl Viro 	__set_fixmap(idx, 0, __pgprot(0))
175bb898558SAl Viro 
176bb898558SAl Viro #define __fix_to_virt(x)	(FIXADDR_TOP - ((x) << PAGE_SHIFT))
177bb898558SAl Viro #define __virt_to_fix(x)	((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
178bb898558SAl Viro 
179bb898558SAl Viro extern void __this_fixmap_does_not_exist(void);
180bb898558SAl Viro 
181bb898558SAl Viro /*
182bb898558SAl Viro  * 'index to address' translation. If anyone tries to use the idx
183bb898558SAl Viro  * directly without translation, we catch the bug with a NULL-deference
184bb898558SAl Viro  * kernel oops. Illegal ranges of incoming indices are caught too.
185bb898558SAl Viro  */
186bb898558SAl Viro static __always_inline unsigned long fix_to_virt(const unsigned int idx)
187bb898558SAl Viro {
188bb898558SAl Viro 	/*
189bb898558SAl Viro 	 * this branch gets completely eliminated after inlining,
190bb898558SAl Viro 	 * except when someone tries to use fixaddr indices in an
191bb898558SAl Viro 	 * illegal way. (such as mixing up address types or using
192bb898558SAl Viro 	 * out-of-range indices).
193bb898558SAl Viro 	 *
194bb898558SAl Viro 	 * If it doesn't get removed, the linker will complain
195bb898558SAl Viro 	 * loudly with a reasonably clear error message..
196bb898558SAl Viro 	 */
197bb898558SAl Viro 	if (idx >= __end_of_fixed_addresses)
198bb898558SAl Viro 		__this_fixmap_does_not_exist();
199bb898558SAl Viro 
200bb898558SAl Viro 	return __fix_to_virt(idx);
201bb898558SAl Viro }
202bb898558SAl Viro 
203bb898558SAl Viro static inline unsigned long virt_to_fix(const unsigned long vaddr)
204bb898558SAl Viro {
205bb898558SAl Viro 	BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
206bb898558SAl Viro 	return __virt_to_fix(vaddr);
207bb898558SAl Viro }
208c577b098SGustavo F. Padovan #endif /* !__ASSEMBLY__ */
2091965aae3SH. Peter Anvin #endif /* _ASM_X86_FIXMAP_H */
210