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
11#ifndef _ASM_FIXMAP_H
12#define _ASM_FIXMAP_H
13
14#include <linux/kernel.h>
15#include <asm/apicdef.h>
16#include <asm/page.h>
17#include <asm/vsyscall.h>
18
19/*
20 * Here we define all the compile-time 'special' virtual
21 * addresses. The point is to have a constant address at
22 * compile time, but to set the physical address only
23 * in the boot process.
24 *
25 * these 'compile-time allocated' memory buffers are
26 * fixed-size 4k pages. (or larger if used with an increment
27 * highger than 1) use fixmap_set(idx,phys) to associate
28 * physical memory with fixmap indices.
29 *
30 * TLB entries of such buffers will not be flushed across
31 * task switches.
32 */
33
34enum fixed_addresses {
35	VSYSCALL_LAST_PAGE,
36	VSYSCALL_FIRST_PAGE = VSYSCALL_LAST_PAGE + ((VSYSCALL_END-VSYSCALL_START) >> PAGE_SHIFT) - 1,
37	VSYSCALL_HPET,
38	FIX_HPET_BASE,
39	FIX_APIC_BASE,	/* local (CPU) APIC) -- required for SMP or not */
40	FIX_IO_APIC_BASE_0,
41	FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS-1,
42	__end_of_fixed_addresses
43};
44
45extern void __set_fixmap (enum fixed_addresses idx,
46					unsigned long phys, pgprot_t flags);
47
48#define set_fixmap(idx, phys) \
49		__set_fixmap(idx, phys, PAGE_KERNEL)
50/*
51 * Some hardware wants to get fixmapped without caching.
52 */
53#define set_fixmap_nocache(idx, phys) \
54		__set_fixmap(idx, phys, PAGE_KERNEL_NOCACHE)
55
56#define FIXADDR_TOP	(VSYSCALL_END-PAGE_SIZE)
57#define FIXADDR_SIZE	(__end_of_fixed_addresses << PAGE_SHIFT)
58#define FIXADDR_START	(FIXADDR_TOP - FIXADDR_SIZE)
59
60/* Only covers 32bit vsyscalls currently. Need another set for 64bit. */
61#define FIXADDR_USER_START	((unsigned long)VSYSCALL32_VSYSCALL)
62#define FIXADDR_USER_END	(FIXADDR_USER_START + PAGE_SIZE)
63
64#define __fix_to_virt(x)	(FIXADDR_TOP - ((x) << PAGE_SHIFT))
65
66extern void __this_fixmap_does_not_exist(void);
67
68/*
69 * 'index to address' translation. If anyone tries to use the idx
70 * directly without translation, we catch the bug with a NULL-deference
71 * kernel oops. Illegal ranges of incoming indices are caught too.
72 */
73static __always_inline unsigned long fix_to_virt(const unsigned int idx)
74{
75	/*
76	 * this branch gets completely eliminated after inlining,
77	 * except when someone tries to use fixaddr indices in an
78	 * illegal way. (such as mixing up address types or using
79	 * out-of-range indices).
80	 *
81	 * If it doesn't get removed, the linker will complain
82	 * loudly with a reasonably clear error message..
83	 */
84	if (idx >= __end_of_fixed_addresses)
85		__this_fixmap_does_not_exist();
86
87        return __fix_to_virt(idx);
88}
89
90#endif
91