aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/highmem.h
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
committerGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
commitc71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch)
treeecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /include/linux/highmem.h
parentea53c912f8a86a8567697115b6a0d8152beee5c8 (diff)
parent6a00f206debf8a5c8899055726ad127dbeeed098 (diff)
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts: litmus/sched_cedf.c
Diffstat (limited to 'include/linux/highmem.h')
-rw-r--r--include/linux/highmem.h78
1 files changed, 54 insertions, 24 deletions
diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index e3060ef85b6d..3a93f73a8acc 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -5,6 +5,7 @@
5#include <linux/kernel.h> 5#include <linux/kernel.h>
6#include <linux/mm.h> 6#include <linux/mm.h>
7#include <linux/uaccess.h> 7#include <linux/uaccess.h>
8#include <linux/hardirq.h>
8 9
9#include <asm/cacheflush.h> 10#include <asm/cacheflush.h>
10 11
@@ -28,18 +29,6 @@ static inline void invalidate_kernel_vmap_range(void *vaddr, int size)
28 29
29#include <asm/kmap_types.h> 30#include <asm/kmap_types.h>
30 31
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 32#ifdef CONFIG_HIGHMEM
44#include <asm/highmem.h> 33#include <asm/highmem.h>
45 34
@@ -66,19 +55,19 @@ static inline void kunmap(struct page *page)
66{ 55{
67} 56}
68 57
69static inline void *kmap_atomic(struct page *page, enum km_type idx) 58static inline void *__kmap_atomic(struct page *page)
70{ 59{
71 pagefault_disable(); 60 pagefault_disable();
72 return page_address(page); 61 return page_address(page);
73} 62}
74#define kmap_atomic_prot(page, idx, prot) kmap_atomic(page, idx) 63#define kmap_atomic_prot(page, prot) __kmap_atomic(page)
75 64
76static inline void kunmap_atomic_notypecheck(void *addr, enum km_type idx) 65static inline void __kunmap_atomic(void *addr)
77{ 66{
78 pagefault_enable(); 67 pagefault_enable();
79} 68}
80 69
81#define kmap_atomic_pfn(pfn, idx) kmap_atomic(pfn_to_page(pfn), (idx)) 70#define kmap_atomic_pfn(pfn) kmap_atomic(pfn_to_page(pfn))
82#define kmap_atomic_to_page(ptr) virt_to_page(ptr) 71#define kmap_atomic_to_page(ptr) virt_to_page(ptr)
83 72
84#define kmap_flush_unused() do {} while(0) 73#define kmap_flush_unused() do {} while(0)
@@ -86,12 +75,53 @@ static inline void kunmap_atomic_notypecheck(void *addr, enum km_type idx)
86 75
87#endif /* CONFIG_HIGHMEM */ 76#endif /* CONFIG_HIGHMEM */
88 77
89/* Prevent people trying to call kunmap_atomic() as if it were kunmap() */ 78#if defined(CONFIG_HIGHMEM) || defined(CONFIG_X86_32)
90/* kunmap_atomic() should get the return value of kmap_atomic, not the page. */ 79
91#define kunmap_atomic(addr, idx) do { \ 80DECLARE_PER_CPU(int, __kmap_atomic_idx);
92 BUILD_BUG_ON(__same_type((addr), struct page *)); \ 81
93 kunmap_atomic_notypecheck((addr), (idx)); \ 82static inline int kmap_atomic_idx_push(void)
94 } while (0) 83{
84 int idx = __this_cpu_inc_return(__kmap_atomic_idx) - 1;
85
86#ifdef CONFIG_DEBUG_HIGHMEM
87 WARN_ON_ONCE(in_irq() && !irqs_disabled());
88 BUG_ON(idx > KM_TYPE_NR);
89#endif
90 return idx;
91}
92
93static inline int kmap_atomic_idx(void)
94{
95 return __this_cpu_read(__kmap_atomic_idx) - 1;
96}
97
98static inline void kmap_atomic_idx_pop(void)
99{
100#ifdef CONFIG_DEBUG_HIGHMEM
101 int idx = __this_cpu_dec_return(__kmap_atomic_idx);
102
103 BUG_ON(idx < 0);
104#else
105 __this_cpu_dec(__kmap_atomic_idx);
106#endif
107}
108
109#endif
110
111/*
112 * Make both: kmap_atomic(page, idx) and kmap_atomic(page) work.
113 */
114#define kmap_atomic(page, args...) __kmap_atomic(page)
115
116/*
117 * Prevent people trying to call kunmap_atomic() as if it were kunmap()
118 * kunmap_atomic() should get the return value of kmap_atomic, not the page.
119 */
120#define kunmap_atomic(addr, args...) \
121do { \
122 BUILD_BUG_ON(__same_type((addr), struct page *)); \
123 __kunmap_atomic(addr); \
124} while (0)
95 125
96/* when CONFIG_HIGHMEM is not set these will be plain clear/copy_page */ 126/* when CONFIG_HIGHMEM is not set these will be plain clear/copy_page */
97#ifndef clear_user_highpage 127#ifndef clear_user_highpage
@@ -201,8 +231,8 @@ static inline void copy_user_highpage(struct page *to, struct page *from,
201 vfrom = kmap_atomic(from, KM_USER0); 231 vfrom = kmap_atomic(from, KM_USER0);
202 vto = kmap_atomic(to, KM_USER1); 232 vto = kmap_atomic(to, KM_USER1);
203 copy_user_page(vto, vfrom, vaddr, to); 233 copy_user_page(vto, vfrom, vaddr, to);
204 kunmap_atomic(vfrom, KM_USER0);
205 kunmap_atomic(vto, KM_USER1); 234 kunmap_atomic(vto, KM_USER1);
235 kunmap_atomic(vfrom, KM_USER0);
206} 236}
207 237
208#endif 238#endif
@@ -214,8 +244,8 @@ static inline void copy_highpage(struct page *to, struct page *from)
214 vfrom = kmap_atomic(from, KM_USER0); 244 vfrom = kmap_atomic(from, KM_USER0);
215 vto = kmap_atomic(to, KM_USER1); 245 vto = kmap_atomic(to, KM_USER1);
216 copy_page(vto, vfrom); 246 copy_page(vto, vfrom);
217 kunmap_atomic(vfrom, KM_USER0);
218 kunmap_atomic(vto, KM_USER1); 247 kunmap_atomic(vto, KM_USER1);
248 kunmap_atomic(vfrom, KM_USER0);
219} 249}
220 250
221#endif /* _LINUX_HIGHMEM_H */ 251#endif /* _LINUX_HIGHMEM_H */