diff options
Diffstat (limited to 'include/linux/highmem.h')
| -rw-r--r-- | include/linux/highmem.h | 75 |
1 files changed, 51 insertions, 24 deletions
diff --git a/include/linux/highmem.h b/include/linux/highmem.h index e3060ef85b6d..b676c585574e 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 | |||
| 33 | void debug_kmap_atomic(enum km_type type); | ||
| 34 | |||
| 35 | #else | ||
| 36 | |||
| 37 | static 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 | ||
| 69 | static inline void *kmap_atomic(struct page *page, enum km_type idx) | 58 | static 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 | ||
| 76 | static inline void kunmap_atomic_notypecheck(void *addr, enum km_type idx) | 65 | static 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,50 @@ 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 { \ | 80 | DECLARE_PER_CPU(int, __kmap_atomic_idx); |
| 92 | BUILD_BUG_ON(__same_type((addr), struct page *)); \ | 81 | |
| 93 | kunmap_atomic_notypecheck((addr), (idx)); \ | 82 | static inline int kmap_atomic_idx_push(void) |
| 94 | } while (0) | 83 | { |
| 84 | int idx = __get_cpu_var(__kmap_atomic_idx)++; | ||
| 85 | #ifdef CONFIG_DEBUG_HIGHMEM | ||
| 86 | WARN_ON_ONCE(in_irq() && !irqs_disabled()); | ||
| 87 | BUG_ON(idx > KM_TYPE_NR); | ||
| 88 | #endif | ||
| 89 | return idx; | ||
| 90 | } | ||
| 91 | |||
| 92 | static inline int kmap_atomic_idx(void) | ||
| 93 | { | ||
| 94 | return __get_cpu_var(__kmap_atomic_idx) - 1; | ||
| 95 | } | ||
| 96 | |||
| 97 | static inline int kmap_atomic_idx_pop(void) | ||
| 98 | { | ||
| 99 | int idx = --__get_cpu_var(__kmap_atomic_idx); | ||
| 100 | #ifdef CONFIG_DEBUG_HIGHMEM | ||
| 101 | BUG_ON(idx < 0); | ||
| 102 | #endif | ||
| 103 | return idx; | ||
| 104 | } | ||
| 105 | |||
| 106 | #endif | ||
| 107 | |||
| 108 | /* | ||
| 109 | * Make both: kmap_atomic(page, idx) and kmap_atomic(page) work. | ||
| 110 | */ | ||
| 111 | #define kmap_atomic(page, args...) __kmap_atomic(page) | ||
| 112 | |||
| 113 | /* | ||
| 114 | * Prevent people trying to call kunmap_atomic() as if it were kunmap() | ||
| 115 | * kunmap_atomic() should get the return value of kmap_atomic, not the page. | ||
| 116 | */ | ||
| 117 | #define kunmap_atomic(addr, args...) \ | ||
| 118 | do { \ | ||
| 119 | BUILD_BUG_ON(__same_type((addr), struct page *)); \ | ||
| 120 | __kunmap_atomic(addr); \ | ||
| 121 | } while (0) | ||
| 95 | 122 | ||
| 96 | /* when CONFIG_HIGHMEM is not set these will be plain clear/copy_page */ | 123 | /* when CONFIG_HIGHMEM is not set these will be plain clear/copy_page */ |
| 97 | #ifndef clear_user_highpage | 124 | #ifndef clear_user_highpage |
| @@ -201,8 +228,8 @@ static inline void copy_user_highpage(struct page *to, struct page *from, | |||
| 201 | vfrom = kmap_atomic(from, KM_USER0); | 228 | vfrom = kmap_atomic(from, KM_USER0); |
| 202 | vto = kmap_atomic(to, KM_USER1); | 229 | vto = kmap_atomic(to, KM_USER1); |
| 203 | copy_user_page(vto, vfrom, vaddr, to); | 230 | copy_user_page(vto, vfrom, vaddr, to); |
| 204 | kunmap_atomic(vfrom, KM_USER0); | ||
| 205 | kunmap_atomic(vto, KM_USER1); | 231 | kunmap_atomic(vto, KM_USER1); |
| 232 | kunmap_atomic(vfrom, KM_USER0); | ||
| 206 | } | 233 | } |
| 207 | 234 | ||
| 208 | #endif | 235 | #endif |
| @@ -214,8 +241,8 @@ static inline void copy_highpage(struct page *to, struct page *from) | |||
| 214 | vfrom = kmap_atomic(from, KM_USER0); | 241 | vfrom = kmap_atomic(from, KM_USER0); |
| 215 | vto = kmap_atomic(to, KM_USER1); | 242 | vto = kmap_atomic(to, KM_USER1); |
| 216 | copy_page(vto, vfrom); | 243 | copy_page(vto, vfrom); |
| 217 | kunmap_atomic(vfrom, KM_USER0); | ||
| 218 | kunmap_atomic(vto, KM_USER1); | 244 | kunmap_atomic(vto, KM_USER1); |
| 245 | kunmap_atomic(vfrom, KM_USER0); | ||
| 219 | } | 246 | } |
| 220 | 247 | ||
| 221 | #endif /* _LINUX_HIGHMEM_H */ | 248 | #endif /* _LINUX_HIGHMEM_H */ |
