1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef __ASM_GENERIC_FIXMAP_H
16#define __ASM_GENERIC_FIXMAP_H
17
18#include <linux/bug.h>
19
20#define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
21#define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
22
23#ifndef __ASSEMBLY__
24
25
26
27
28
29static __always_inline unsigned long fix_to_virt(const unsigned int idx)
30{
31 BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
32 return __fix_to_virt(idx);
33}
34
35static inline unsigned long virt_to_fix(const unsigned long vaddr)
36{
37 BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
38 return __virt_to_fix(vaddr);
39}
40
41
42
43
44
45
46#ifndef FIXMAP_PAGE_NORMAL
47#define FIXMAP_PAGE_NORMAL PAGE_KERNEL
48#endif
49#if !defined(FIXMAP_PAGE_RO) && defined(PAGE_KERNEL_RO)
50#define FIXMAP_PAGE_RO PAGE_KERNEL_RO
51#endif
52#ifndef FIXMAP_PAGE_NOCACHE
53#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE
54#endif
55#ifndef FIXMAP_PAGE_IO
56#define FIXMAP_PAGE_IO PAGE_KERNEL_IO
57#endif
58#ifndef FIXMAP_PAGE_CLEAR
59#define FIXMAP_PAGE_CLEAR __pgprot(0)
60#endif
61
62#ifndef set_fixmap
63#define set_fixmap(idx, phys) \
64 __set_fixmap(idx, phys, FIXMAP_PAGE_NORMAL)
65#endif
66
67#ifndef clear_fixmap
68#define clear_fixmap(idx) \
69 __set_fixmap(idx, 0, FIXMAP_PAGE_CLEAR)
70#endif
71
72
73#define __set_fixmap_offset(idx, phys, flags) \
74({ \
75 unsigned long ________addr; \
76 __set_fixmap(idx, phys, flags); \
77 ________addr = fix_to_virt(idx) + ((phys) & (PAGE_SIZE - 1)); \
78 ________addr; \
79})
80
81#define set_fixmap_offset(idx, phys) \
82 __set_fixmap_offset(idx, phys, FIXMAP_PAGE_NORMAL)
83
84
85
86
87#define set_fixmap_nocache(idx, phys) \
88 __set_fixmap(idx, phys, FIXMAP_PAGE_NOCACHE)
89
90#define set_fixmap_offset_nocache(idx, phys) \
91 __set_fixmap_offset(idx, phys, FIXMAP_PAGE_NOCACHE)
92
93
94
95
96#define set_fixmap_io(idx, phys) \
97 __set_fixmap(idx, phys, FIXMAP_PAGE_IO)
98
99#define set_fixmap_offset_io(idx, phys) \
100 __set_fixmap_offset(idx, phys, FIXMAP_PAGE_IO)
101
102#endif
103#endif
104