1/*
2 * fixmap.h: compile-time virtual memory allocation
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License.  See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 1998 Ingo Molnar
9 *
10 * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
11 */
12
13#ifndef _ASM_FIXMAP_H
14#define _ASM_FIXMAP_H
15
16
17/* used by vmalloc.c, vsyscall.lds.S.
18 *
19 * Leave one empty page between vmalloc'ed areas and
20 * the start of the fixmap.
21 */
22extern unsigned long __FIXADDR_TOP;
23#define FIXADDR_USER_START     __fix_to_virt(FIX_VDSO)
24#define FIXADDR_USER_END       __fix_to_virt(FIX_VDSO - 1)
25
26#ifndef __ASSEMBLY__
27#include <linux/kernel.h>
28#include <asm/acpi.h>
29#include <asm/apicdef.h>
30#include <asm/page.h>
31#ifdef CONFIG_HIGHMEM
32#include <linux/threads.h>
33#include <asm/kmap_types.h>
34#endif
35
36/*
37 * Here we define all the compile-time 'special' virtual
38 * addresses. The point is to have a constant address at
39 * compile time, but to set the physical address only
40 * in the boot process. We allocate these special addresses
41 * from the end of virtual memory (0xfffff000) backwards.
42 * Also this lets us do fail-safe vmalloc(), we
43 * can guarantee that these special addresses and
44 * vmalloc()-ed addresses never overlap.
45 *
46 * these 'compile-time allocated' memory buffers are
47 * fixed-size 4k pages. (or larger if used with an increment
48 * highger than 1) use fixmap_set(idx,phys) to associate
49 * physical memory with fixmap indices.
50 *
51 * TLB entries of such buffers will not be flushed across
52 * task switches.
53 */
54enum fixed_addresses {
55	FIX_HOLE,
56	FIX_VDSO,
57#ifdef CONFIG_X86_LOCAL_APIC
58	FIX_APIC_BASE,	/* local (CPU) APIC) -- required for SMP or not */
59#endif
60#ifdef CONFIG_X86_IO_APIC
61	FIX_IO_APIC_BASE_0,
62	FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS-1,
63#endif
64#ifdef CONFIG_X86_VISWS_APIC
65	FIX_CO_CPU,	/* Cobalt timer */
66	FIX_CO_APIC,	/* Cobalt APIC Redirection Table */
67	FIX_LI_PCIA,	/* Lithium PCI Bridge A */
68	FIX_LI_PCIB,	/* Lithium PCI Bridge B */
69#endif
70#ifdef CONFIG_X86_F00F_BUG
71	FIX_F00F_IDT,	/* Virtual mapping for IDT */
72#endif
73#ifdef CONFIG_X86_CYCLONE_TIMER
74	FIX_CYCLONE_TIMER, /*cyclone timer register*/
75#endif
76#ifdef CONFIG_HIGHMEM
77	FIX_KMAP_BEGIN,	/* reserved pte's for temporary kernel mappings */
78	FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
79#endif
80#ifdef CONFIG_ACPI
81	FIX_ACPI_BEGIN,
82	FIX_ACPI_END = FIX_ACPI_BEGIN + FIX_ACPI_PAGES - 1,
83#endif
84#ifdef CONFIG_PCI_MMCONFIG
85	FIX_PCIE_MCFG,
86#endif
87#ifdef CONFIG_PARAVIRT
88	FIX_PARAVIRT_BOOTMAP,
89#endif
90	__end_of_permanent_fixed_addresses,
91	/* temporary boot-time mappings, used before ioremap() is functional */
92#define NR_FIX_BTMAPS	16
93	FIX_BTMAP_END = __end_of_permanent_fixed_addresses,
94	FIX_BTMAP_BEGIN = FIX_BTMAP_END + NR_FIX_BTMAPS - 1,
95	FIX_WP_TEST,
96	__end_of_fixed_addresses
97};
98
99extern void __set_fixmap (enum fixed_addresses idx,
100					unsigned long phys, pgprot_t flags);
101extern void reserve_top_address(unsigned long reserve);
102
103#define set_fixmap(idx, phys) \
104		__set_fixmap(idx, phys, PAGE_KERNEL)
105/*
106 * Some hardware wants to get fixmapped without caching.
107 */
108#define set_fixmap_nocache(idx, phys) \
109		__set_fixmap(idx, phys, PAGE_KERNEL_NOCACHE)
110
111#define clear_fixmap(idx) \
112		__set_fixmap(idx, 0, __pgprot(0))
113
114#define FIXADDR_TOP	((unsigned long)__FIXADDR_TOP)
115
116#define __FIXADDR_SIZE	(__end_of_permanent_fixed_addresses << PAGE_SHIFT)
117#define __FIXADDR_BOOT_SIZE	(__end_of_fixed_addresses << PAGE_SHIFT)
118#define FIXADDR_START		(FIXADDR_TOP - __FIXADDR_SIZE)
119#define FIXADDR_BOOT_START	(FIXADDR_TOP - __FIXADDR_BOOT_SIZE)
120
121#define __fix_to_virt(x)	(FIXADDR_TOP - ((x) << PAGE_SHIFT))
122#define __virt_to_fix(x)	((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
123
124extern void __this_fixmap_does_not_exist(void);
125
126/*
127 * 'index to address' translation. If anyone tries to use the idx
128 * directly without tranlation, we catch the bug with a NULL-deference
129 * kernel oops. Illegal ranges of incoming indices are caught too.
130 */
131static __always_inline unsigned long fix_to_virt(const unsigned int idx)
132{
133	/*
134	 * this branch gets completely eliminated after inlining,
135	 * except when someone tries to use fixaddr indices in an
136	 * illegal way. (such as mixing up address types or using
137	 * out-of-range indices).
138	 *
139	 * If it doesn't get removed, the linker will complain
140	 * loudly with a reasonably clear error message..
141	 */
142	if (idx >= __end_of_fixed_addresses)
143		__this_fixmap_does_not_exist();
144
145        return __fix_to_virt(idx);
146}
147
148static inline unsigned long virt_to_fix(const unsigned long vaddr)
149{
150	BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
151	return __virt_to_fix(vaddr);
152}
153
154#endif /* !__ASSEMBLY__ */
155#endif
156