This commit was manufactured by cvs2svn to create branch
[linux-2.6.git] / include / asm-i386 / fixmap.h
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 #include <linux/config.h>
17 #include <linux/kernel.h>
18 #include <asm/acpi.h>
19 #include <asm/apicdef.h>
20 #include <asm/page.h>
21 #include <linux/threads.h>
22 #include <asm/kmap_types.h>
23
24 /*
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.
33  *
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.
38  *
39  * TLB entries of such buffers will not be flushed across
40  * task switches.
41  */
42
43 /*
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
47  * fix-mapped?
48  */
49 enum fixed_addresses {
50         FIX_HOLE,
51         FIX_VSYSCALL,
52 #ifdef CONFIG_X86_LOCAL_APIC
53         FIX_APIC_BASE,  /* local (CPU) APIC) -- required for SMP or not */
54 #else
55         FIX_VSTACK_HOLE_1,
56 #endif
57 #ifdef CONFIG_X86_IO_APIC
58         FIX_IO_APIC_BASE_0,
59         FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS-1,
60 #endif
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 */
66 #endif
67         FIX_IDT,
68         FIX_GDT_1,
69         FIX_GDT_0,
70         FIX_TSS_3,
71         FIX_TSS_2,
72         FIX_TSS_1,
73         FIX_TSS_0,
74         FIX_ENTRY_TRAMPOLINE_1,
75         FIX_ENTRY_TRAMPOLINE_0,
76 #ifdef CONFIG_X86_CYCLONE_TIMER
77         FIX_CYCLONE_TIMER, /*cyclone timer register*/
78         FIX_VSTACK_HOLE_2,
79 #endif 
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
83         FIX_ACPI_BEGIN,
84         FIX_ACPI_END = FIX_ACPI_BEGIN + FIX_ACPI_PAGES - 1,
85 #endif
86 #ifdef CONFIG_PCI_MMCONFIG
87         FIX_PCIE_MCFG,
88 #endif
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,
94         FIX_WP_TEST,
95         __end_of_fixed_addresses
96 };
97
98 extern void __set_fixmap (enum fixed_addresses idx,
99                                         unsigned long phys, pgprot_t flags);
100
101 #define set_fixmap(idx, phys) \
102                 __set_fixmap(idx, phys, PAGE_KERNEL)
103 /*
104  * Some hardware wants to get fixmapped without caching.
105  */
106 #define set_fixmap_nocache(idx, phys) \
107                 __set_fixmap(idx, phys, PAGE_KERNEL_NOCACHE)
108
109 #define clear_fixmap(idx) \
110                 __set_fixmap(idx, 0, __pgprot(0))
111
112 /*
113  * used by vmalloc.c and various other places.
114  *
115  * Leave one empty page between vmalloc'ed areas and
116  * the start of the fixmap.
117  *
118  * IMPORTANT: we have to align FIXADDR_TOP so that the virtual stack
119  * is THREAD_SIZE aligned.
120  */
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)
124
125 #define __fix_to_virt(x)        (FIXADDR_TOP - ((x) << PAGE_SHIFT))
126 #define __virt_to_fix(x)        ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
127
128 /*
129  * This is the range that is readable by user mode, and things
130  * acting like user mode such as get_user_pages.
131  */
132 #define FIXADDR_USER_START      (__fix_to_virt(FIX_VSYSCALL))
133 #define FIXADDR_USER_END        (FIXADDR_USER_START + PAGE_SIZE)
134
135
136 extern void __this_fixmap_does_not_exist(void);
137
138 /*
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.
142  */
143 static inline unsigned long fix_to_virt(const unsigned int idx)
144 {
145         /*
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).
150          *
151          * If it doesn't get removed, the linker will complain
152          * loudly with a reasonably clear error message..
153          */
154         if (idx >= __end_of_fixed_addresses)
155                 __this_fixmap_does_not_exist();
156
157         return __fix_to_virt(idx);
158 }
159
160 static inline unsigned long virt_to_fix(const unsigned long vaddr)
161 {
162         BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
163         return __virt_to_fix(vaddr);
164 }
165
166 #endif