2 * fixmap.h: compile-time virtual memory allocation
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
8 * Copyright (C) 1998 Ingo Molnar
10 * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
16 #include <linux/config.h>
17 #include <linux/kernel.h>
19 #include <asm/apicdef.h>
21 #include <linux/threads.h>
22 #include <asm/kmap_types.h>
25 * Here we define all the compile-time 'special' virtual
26 * addresses. The point is to have a constant address at
27 * compile time, but to set the physical address only
28 * in the boot process. We allocate these special addresses
29 * from the end of virtual memory (0xffffe000) backwards.
30 * Also this lets us do fail-safe vmalloc(), we
31 * can guarantee that these special addresses and
32 * vmalloc()-ed addresses never overlap.
34 * these 'compile-time allocated' memory buffers are
35 * fixed-size 4k pages. (or larger if used with an increment
36 * highger than 1) use fixmap_set(idx,phys) to associate
37 * physical memory with fixmap indices.
39 * TLB entries of such buffers will not be flushed across
44 * on UP currently we will have no trace of the fixmap mechanizm,
45 * no page table allocations, etc. This might change in the
46 * future, say framebuffers for the console driver(s) could be
49 enum fixed_addresses {
52 #ifdef CONFIG_X86_LOCAL_APIC
53 FIX_APIC_BASE, /* local (CPU) APIC) -- required for SMP or not */
57 #ifdef CONFIG_X86_IO_APIC
59 FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS-1,
61 #ifdef CONFIG_X86_VISWS_APIC
62 FIX_CO_CPU, /* Cobalt timer */
63 FIX_CO_APIC, /* Cobalt APIC Redirection Table */
64 FIX_LI_PCIA, /* Lithium PCI Bridge A */
65 FIX_LI_PCIB, /* Lithium PCI Bridge B */
74 FIX_ENTRY_TRAMPOLINE_1,
75 FIX_ENTRY_TRAMPOLINE_0,
76 #ifdef CONFIG_X86_CYCLONE_TIMER
77 FIX_CYCLONE_TIMER, /*cyclone timer register*/
80 FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */
81 FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
82 #ifdef CONFIG_ACPI_BOOT
84 FIX_ACPI_END = FIX_ACPI_BEGIN + FIX_ACPI_PAGES - 1,
86 #ifdef CONFIG_PCI_MMCONFIG
89 __end_of_permanent_fixed_addresses,
90 /* temporary boot-time mappings, used before ioremap() is functional */
91 #define NR_FIX_BTMAPS 16
92 FIX_BTMAP_END = __end_of_permanent_fixed_addresses,
93 FIX_BTMAP_BEGIN = FIX_BTMAP_END + NR_FIX_BTMAPS - 1,
95 __end_of_fixed_addresses
98 extern void __set_fixmap (enum fixed_addresses idx,
99 unsigned long phys, pgprot_t flags);
101 #define set_fixmap(idx, phys) \
102 __set_fixmap(idx, phys, PAGE_KERNEL)
104 * Some hardware wants to get fixmapped without caching.
106 #define set_fixmap_nocache(idx, phys) \
107 __set_fixmap(idx, phys, PAGE_KERNEL_NOCACHE)
109 #define clear_fixmap(idx) \
110 __set_fixmap(idx, 0, __pgprot(0))
113 * used by vmalloc.c and various other places.
115 * Leave one empty page between vmalloc'ed areas and
116 * the start of the fixmap.
118 * IMPORTANT: we have to align FIXADDR_TOP so that the virtual stack
119 * is THREAD_SIZE aligned.
121 #define FIXADDR_TOP (0xffffe000UL & ~(THREAD_SIZE-1))
122 #define __FIXADDR_SIZE (__end_of_permanent_fixed_addresses << PAGE_SHIFT)
123 #define FIXADDR_START (FIXADDR_TOP - __FIXADDR_SIZE)
125 #define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
126 #define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
129 * This is the range that is readable by user mode, and things
130 * acting like user mode such as get_user_pages.
132 #define FIXADDR_USER_START (__fix_to_virt(FIX_VSYSCALL))
133 #define FIXADDR_USER_END (FIXADDR_USER_START + PAGE_SIZE)
136 extern void __this_fixmap_does_not_exist(void);
139 * 'index to address' translation. If anyone tries to use the idx
140 * directly without tranlation, we catch the bug with a NULL-deference
141 * kernel oops. Illegal ranges of incoming indices are caught too.
143 static inline unsigned long fix_to_virt(const unsigned int idx)
146 * this branch gets completely eliminated after inlining,
147 * except when someone tries to use fixaddr indices in an
148 * illegal way. (such as mixing up address types or using
149 * out-of-range indices).
151 * If it doesn't get removed, the linker will complain
152 * loudly with a reasonably clear error message..
154 if (idx >= __end_of_fixed_addresses)
155 __this_fixmap_does_not_exist();
157 return __fix_to_virt(idx);
160 static inline unsigned long virt_to_fix(const unsigned long vaddr)
162 BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
163 return __virt_to_fix(vaddr);