blob: 01b0f98f9929c84f30015b8bc906e87eabc53543 [file] [log] [blame]
Ingo Molnar3ec96782008-04-25 18:25:25 +02001#ifndef _ASM_FIXMAP_H
2#define _ASM_FIXMAP_H
3
Thomas Gleixner96a388d2007-10-11 11:20:03 +02004#ifdef CONFIG_X86_32
5# include "fixmap_32.h"
6#else
7# include "fixmap_64.h"
8#endif
Ingo Molnar3ec96782008-04-25 18:25:25 +02009
Jeremy Fitzhardinge944256e2008-06-17 11:41:49 -070010extern void __set_fixmap(enum fixed_addresses idx,
11 unsigned long phys, pgprot_t flags);
12#define set_fixmap(idx, phys) \
13 __set_fixmap(idx, phys, PAGE_KERNEL)
14
15/*
16 * Some hardware wants to get fixmapped without caching.
17 */
18#define set_fixmap_nocache(idx, phys) \
19 __set_fixmap(idx, phys, PAGE_KERNEL_NOCACHE)
20
Ingo Molnar3ec96782008-04-25 18:25:25 +020021#define clear_fixmap(idx) \
22 __set_fixmap(idx, 0, __pgprot(0))
23
Jeremy Fitzhardinge944256e2008-06-17 11:41:49 -070024#define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
25#define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
26
27extern void __this_fixmap_does_not_exist(void);
28
29/*
30 * 'index to address' translation. If anyone tries to use the idx
31 * directly without translation, we catch the bug with a NULL-deference
32 * kernel oops. Illegal ranges of incoming indices are caught too.
33 */
34static __always_inline unsigned long fix_to_virt(const unsigned int idx)
35{
36 /*
37 * this branch gets completely eliminated after inlining,
38 * except when someone tries to use fixaddr indices in an
39 * illegal way. (such as mixing up address types or using
40 * out-of-range indices).
41 *
42 * If it doesn't get removed, the linker will complain
43 * loudly with a reasonably clear error message..
44 */
45 if (idx >= __end_of_fixed_addresses)
46 __this_fixmap_does_not_exist();
47
48 return __fix_to_virt(idx);
49}
50
51static inline unsigned long virt_to_fix(const unsigned long vaddr)
52{
53 BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
54 return __virt_to_fix(vaddr);
55}
Ingo Molnar3ec96782008-04-25 18:25:25 +020056#endif