1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * fixmap.h: compile-time virtual memory allocation
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * This file is subject to the terms and conditions of the GNU General Public
5*4882a593Smuzhiyun * License. See the file "COPYING" in the main directory of this archive
6*4882a593Smuzhiyun * for more details.
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * Copyright (C) 1998 Ingo Molnar
9*4882a593Smuzhiyun *
10*4882a593Smuzhiyun * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
11*4882a593Smuzhiyun * x86_32 and x86_64 integration by Gustavo F. Padovan, February 2009
12*4882a593Smuzhiyun * Break out common bits to asm-generic by Mark Salter, November 2013
13*4882a593Smuzhiyun */
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun #ifndef __ASM_GENERIC_FIXMAP_H
16*4882a593Smuzhiyun #define __ASM_GENERIC_FIXMAP_H
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun #include <linux/bug.h>
19*4882a593Smuzhiyun #include <linux/mm_types.h>
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun #define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
22*4882a593Smuzhiyun #define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun #ifndef __ASSEMBLY__
25*4882a593Smuzhiyun /*
26*4882a593Smuzhiyun * 'index to address' translation. If anyone tries to use the idx
27*4882a593Smuzhiyun * directly without translation, we catch the bug with a NULL-deference
28*4882a593Smuzhiyun * kernel oops. Illegal ranges of incoming indices are caught too.
29*4882a593Smuzhiyun */
fix_to_virt(const unsigned int idx)30*4882a593Smuzhiyun static __always_inline unsigned long fix_to_virt(const unsigned int idx)
31*4882a593Smuzhiyun {
32*4882a593Smuzhiyun BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
33*4882a593Smuzhiyun return __fix_to_virt(idx);
34*4882a593Smuzhiyun }
35*4882a593Smuzhiyun
virt_to_fix(const unsigned long vaddr)36*4882a593Smuzhiyun static inline unsigned long virt_to_fix(const unsigned long vaddr)
37*4882a593Smuzhiyun {
38*4882a593Smuzhiyun BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
39*4882a593Smuzhiyun return __virt_to_fix(vaddr);
40*4882a593Smuzhiyun }
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun /*
43*4882a593Smuzhiyun * Provide some reasonable defaults for page flags.
44*4882a593Smuzhiyun * Not all architectures use all of these different types and some
45*4882a593Smuzhiyun * architectures use different names.
46*4882a593Smuzhiyun */
47*4882a593Smuzhiyun #ifndef FIXMAP_PAGE_NORMAL
48*4882a593Smuzhiyun #define FIXMAP_PAGE_NORMAL PAGE_KERNEL
49*4882a593Smuzhiyun #endif
50*4882a593Smuzhiyun #if !defined(FIXMAP_PAGE_RO) && defined(PAGE_KERNEL_RO)
51*4882a593Smuzhiyun #define FIXMAP_PAGE_RO PAGE_KERNEL_RO
52*4882a593Smuzhiyun #endif
53*4882a593Smuzhiyun #ifndef FIXMAP_PAGE_NOCACHE
54*4882a593Smuzhiyun #define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE
55*4882a593Smuzhiyun #endif
56*4882a593Smuzhiyun #ifndef FIXMAP_PAGE_IO
57*4882a593Smuzhiyun #define FIXMAP_PAGE_IO PAGE_KERNEL_IO
58*4882a593Smuzhiyun #endif
59*4882a593Smuzhiyun #ifndef FIXMAP_PAGE_CLEAR
60*4882a593Smuzhiyun #define FIXMAP_PAGE_CLEAR __pgprot(0)
61*4882a593Smuzhiyun #endif
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun #ifndef set_fixmap
64*4882a593Smuzhiyun #define set_fixmap(idx, phys) \
65*4882a593Smuzhiyun __set_fixmap(idx, phys, FIXMAP_PAGE_NORMAL)
66*4882a593Smuzhiyun #endif
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun #ifndef clear_fixmap
69*4882a593Smuzhiyun #define clear_fixmap(idx) \
70*4882a593Smuzhiyun __set_fixmap(idx, 0, FIXMAP_PAGE_CLEAR)
71*4882a593Smuzhiyun #endif
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun /* Return a pointer with offset calculated */
74*4882a593Smuzhiyun #define __set_fixmap_offset(idx, phys, flags) \
75*4882a593Smuzhiyun ({ \
76*4882a593Smuzhiyun unsigned long ________addr; \
77*4882a593Smuzhiyun __set_fixmap(idx, phys, flags); \
78*4882a593Smuzhiyun ________addr = fix_to_virt(idx) + ((phys) & (PAGE_SIZE - 1)); \
79*4882a593Smuzhiyun ________addr; \
80*4882a593Smuzhiyun })
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun #define set_fixmap_offset(idx, phys) \
83*4882a593Smuzhiyun __set_fixmap_offset(idx, phys, FIXMAP_PAGE_NORMAL)
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun /*
86*4882a593Smuzhiyun * Some hardware wants to get fixmapped without caching.
87*4882a593Smuzhiyun */
88*4882a593Smuzhiyun #define set_fixmap_nocache(idx, phys) \
89*4882a593Smuzhiyun __set_fixmap(idx, phys, FIXMAP_PAGE_NOCACHE)
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun #define set_fixmap_offset_nocache(idx, phys) \
92*4882a593Smuzhiyun __set_fixmap_offset(idx, phys, FIXMAP_PAGE_NOCACHE)
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun /*
95*4882a593Smuzhiyun * Some fixmaps are for IO
96*4882a593Smuzhiyun */
97*4882a593Smuzhiyun #define set_fixmap_io(idx, phys) \
98*4882a593Smuzhiyun __set_fixmap(idx, phys, FIXMAP_PAGE_IO)
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun #define set_fixmap_offset_io(idx, phys) \
101*4882a593Smuzhiyun __set_fixmap_offset(idx, phys, FIXMAP_PAGE_IO)
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun #endif /* __ASSEMBLY__ */
104*4882a593Smuzhiyun #endif /* __ASM_GENERIC_FIXMAP_H */
105