aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/highmem.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/highmem.h')
-rw-r--r--include/linux/highmem.h74
1 files changed, 50 insertions, 24 deletions
diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index e3060ef85b6d..e9138198e823 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -28,18 +28,6 @@ static inline void invalidate_kernel_vmap_range(void *vaddr, int size)
28 28
29#include <asm/kmap_types.h> 29#include <asm/kmap_types.h>
30 30
31#ifdef CONFIG_DEBUG_HIGHMEM
32
33void debug_kmap_atomic(enum km_type type);
34
35#else
36
37static inline void debug_kmap_atomic(enum km_type type)
38{
39}
40
41#endif
42
43#ifdef CONFIG_HIGHMEM 31#ifdef CONFIG_HIGHMEM
44#include <asm/highmem.h> 32#include <asm/highmem.h>
45 33
@@ -66,19 +54,19 @@ static inline void kunmap(struct page *page)
66{ 54{
67} 55}
68 56
69static inline void *kmap_atomic(struct page *page, enum km_type idx) 57static inline void *__kmap_atomic(struct page *page)
70{ 58{
71 pagefault_disable(); 59 pagefault_disable();
72 return page_address(page); 60 return page_address(page);
73} 61}
74#define kmap_atomic_prot(page, idx, prot) kmap_atomic(page, idx) 62#define kmap_atomic_prot(page, prot) __kmap_atomic(page)
75 63
76static inline void kunmap_atomic_notypecheck(void *addr, enum km_type idx) 64static inline void __kunmap_atomic(void *addr)
77{ 65{
78 pagefault_enable(); 66 pagefault_enable();
79} 67}
80 68
81#define kmap_atomic_pfn(pfn, idx) kmap_atomic(pfn_to_page(pfn), (idx)) 69#define kmap_atomic_pfn(pfn) kmap_atomic(pfn_to_page(pfn))
82#define kmap_atomic_to_page(ptr) virt_to_page(ptr) 70#define kmap_atomic_to_page(ptr) virt_to_page(ptr)
83 71
84#define kmap_flush_unused() do {} while(0) 72#define kmap_flush_unused() do {} while(0)
@@ -86,12 +74,50 @@ static inline void kunmap_atomic_notypecheck(void *addr, enum km_type idx)
86 74
87#endif /* CONFIG_HIGHMEM */ 75#endif /* CONFIG_HIGHMEM */
88 76
89/* Prevent people trying to call kunmap_atomic() as if it were kunmap() */ 77#if defined(CONFIG_HIGHMEM) || defined(CONFIG_X86_32)
90/* kunmap_atomic() should get the return value of kmap_atomic, not the page. */ 78
91#define kunmap_atomic(addr, idx) do { \ 79DECLARE_PER_CPU(int, __kmap_atomic_idx);
92 BUILD_BUG_ON(__same_type((addr), struct page *)); \ 80
93 kunmap_atomic_notypecheck((addr), (idx)); \ 81static inline int kmap_atomic_idx_push(void)
94 } while (0) 82{
83 int idx = __get_cpu_var(__kmap_atomic_idx)++;
84#ifdef CONFIG_DEBUG_HIGHMEM
85 WARN_ON_ONCE(in_irq() && !irqs_disabled());
86 BUG_ON(idx > KM_TYPE_NR);
87#endif
88 return idx;
89}
90
91static inline int kmap_atomic_idx(void)
92{
93 return __get_cpu_var(__kmap_atomic_idx) - 1;
94}
95
96static inline int kmap_atomic_idx_pop(void)
97{
98 int idx = --__get_cpu_var(__kmap_atomic_idx);
99#ifdef CONFIG_DEBUG_HIGHMEM
100 BUG_ON(idx < 0);
101#endif
102 return idx;
103}
104
105#endif
106
107/*
108 * Make both: kmap_atomic(page, idx) and kmap_atomic(page) work.
109 */
110#define kmap_atomic(page, args...) __kmap_atomic(page)
111
112/*
113 * Prevent people trying to call kunmap_atomic() as if it were kunmap()
114 * kunmap_atomic() should get the return value of kmap_atomic, not the page.
115 */
116#define kunmap_atomic(addr, args...) \
117do { \
118 BUILD_BUG_ON(__same_type((addr), struct page *)); \
119 __kunmap_atomic(addr); \
120} while (0)
95 121
96/* when CONFIG_HIGHMEM is not set these will be plain clear/copy_page */ 122/* when CONFIG_HIGHMEM is not set these will be plain clear/copy_page */
97#ifndef clear_user_highpage 123#ifndef clear_user_highpage
@@ -201,8 +227,8 @@ static inline void copy_user_highpage(struct page *to, struct page *from,
201 vfrom = kmap_atomic(from, KM_USER0); 227 vfrom = kmap_atomic(from, KM_USER0);
202 vto = kmap_atomic(to, KM_USER1); 228 vto = kmap_atomic(to, KM_USER1);
203 copy_user_page(vto, vfrom, vaddr, to); 229 copy_user_page(vto, vfrom, vaddr, to);
204 kunmap_atomic(vfrom, KM_USER0);
205 kunmap_atomic(vto, KM_USER1); 230 kunmap_atomic(vto, KM_USER1);
231 kunmap_atomic(vfrom, KM_USER0);
206} 232}
207 233
208#endif 234#endif
@@ -214,8 +240,8 @@ static inline void copy_highpage(struct page *to, struct page *from)
214 vfrom = kmap_atomic(from, KM_USER0); 240 vfrom = kmap_atomic(from, KM_USER0);
215 vto = kmap_atomic(to, KM_USER1); 241 vto = kmap_atomic(to, KM_USER1);
216 copy_page(vto, vfrom); 242 copy_page(vto, vfrom);
217 kunmap_atomic(vfrom, KM_USER0);
218 kunmap_atomic(vto, KM_USER1); 243 kunmap_atomic(vto, KM_USER1);
244 kunmap_atomic(vfrom, KM_USER0);
219} 245}
220 246
221#endif /* _LINUX_HIGHMEM_H */ 247#endif /* _LINUX_HIGHMEM_H */