Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_HIGHMEM_H |
| 2 | #define _LINUX_HIGHMEM_H |
| 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <linux/fs.h> |
| 5 | #include <linux/mm.h> |
Peter Zijlstra | ad76fb6 | 2006-12-06 20:32:21 -0800 | [diff] [blame] | 6 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | |
| 8 | #include <asm/cacheflush.h> |
| 9 | |
James Bottomley | 03beb07 | 2006-03-26 01:36:57 -0800 | [diff] [blame] | 10 | #ifndef ARCH_HAS_FLUSH_ANON_PAGE |
Russell King | a6f36be | 2006-12-30 22:24:19 +0000 | [diff] [blame] | 11 | static inline void flush_anon_page(struct vm_area_struct *vma, struct page *page, unsigned long vmaddr) |
James Bottomley | 03beb07 | 2006-03-26 01:36:57 -0800 | [diff] [blame] | 12 | { |
| 13 | } |
| 14 | #endif |
| 15 | |
James Bottomley | 5a3a5a9 | 2006-03-26 01:36:59 -0800 | [diff] [blame] | 16 | #ifndef ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE |
| 17 | static inline void flush_kernel_dcache_page(struct page *page) |
| 18 | { |
| 19 | } |
| 20 | #endif |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #ifdef CONFIG_HIGHMEM |
| 23 | |
| 24 | #include <asm/highmem.h> |
| 25 | |
| 26 | /* declarations for linux/mm/highmem.c */ |
| 27 | unsigned int nr_free_highpages(void); |
Christoph Lameter | c1f60a5 | 2006-09-25 23:31:11 -0700 | [diff] [blame] | 28 | extern unsigned long totalhigh_pages; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | #else /* CONFIG_HIGHMEM */ |
| 31 | |
| 32 | static inline unsigned int nr_free_highpages(void) { return 0; } |
| 33 | |
Christoph Lameter | c1f60a5 | 2006-09-25 23:31:11 -0700 | [diff] [blame] | 34 | #define totalhigh_pages 0 |
| 35 | |
James Bottomley | a6ca1b9 | 2006-09-25 23:30:55 -0700 | [diff] [blame] | 36 | #ifndef ARCH_HAS_KMAP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | static inline void *kmap(struct page *page) |
| 38 | { |
| 39 | might_sleep(); |
| 40 | return page_address(page); |
| 41 | } |
| 42 | |
| 43 | #define kunmap(page) do { (void) (page); } while (0) |
| 44 | |
Peter Zijlstra | ad76fb6 | 2006-12-06 20:32:21 -0800 | [diff] [blame] | 45 | #define kmap_atomic(page, idx) \ |
| 46 | ({ pagefault_disable(); page_address(page); }) |
| 47 | #define kunmap_atomic(addr, idx) do { pagefault_enable(); } while (0) |
| 48 | #define kmap_atomic_pfn(pfn, idx) kmap_atomic(pfn_to_page(pfn), (idx)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #define kmap_atomic_to_page(ptr) virt_to_page(ptr) |
James Bottomley | a6ca1b9 | 2006-09-25 23:30:55 -0700 | [diff] [blame] | 50 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | #endif /* CONFIG_HIGHMEM */ |
| 53 | |
| 54 | /* when CONFIG_HIGHMEM is not set these will be plain clear/copy_page */ |
| 55 | static inline void clear_user_highpage(struct page *page, unsigned long vaddr) |
| 56 | { |
| 57 | void *addr = kmap_atomic(page, KM_USER0); |
| 58 | clear_user_page(addr, vaddr, page); |
| 59 | kunmap_atomic(addr, KM_USER0); |
| 60 | /* Make sure this page is cleared on other CPU's too before using it */ |
| 61 | smp_wmb(); |
| 62 | } |
| 63 | |
| 64 | #ifndef __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE |
| 65 | static inline struct page * |
| 66 | alloc_zeroed_user_highpage(struct vm_area_struct *vma, unsigned long vaddr) |
| 67 | { |
| 68 | struct page *page = alloc_page_vma(GFP_HIGHUSER, vma, vaddr); |
| 69 | |
| 70 | if (page) |
| 71 | clear_user_highpage(page, vaddr); |
| 72 | |
| 73 | return page; |
| 74 | } |
| 75 | #endif |
| 76 | |
| 77 | static inline void clear_highpage(struct page *page) |
| 78 | { |
| 79 | void *kaddr = kmap_atomic(page, KM_USER0); |
| 80 | clear_page(kaddr); |
| 81 | kunmap_atomic(kaddr, KM_USER0); |
| 82 | } |
| 83 | |
| 84 | /* |
| 85 | * Same but also flushes aliased cache contents to RAM. |
| 86 | */ |
| 87 | static inline void memclear_highpage_flush(struct page *page, unsigned int offset, unsigned int size) |
| 88 | { |
| 89 | void *kaddr; |
| 90 | |
| 91 | BUG_ON(offset + size > PAGE_SIZE); |
| 92 | |
| 93 | kaddr = kmap_atomic(page, KM_USER0); |
| 94 | memset((char *)kaddr + offset, 0, size); |
| 95 | flush_dcache_page(page); |
| 96 | kunmap_atomic(kaddr, KM_USER0); |
| 97 | } |
| 98 | |
Atsushi Nemoto | 77fff4a | 2006-12-12 17:14:54 +0000 | [diff] [blame] | 99 | #ifndef __HAVE_ARCH_COPY_USER_HIGHPAGE |
| 100 | |
Atsushi Nemoto | 9de455b | 2006-12-12 17:14:55 +0000 | [diff] [blame] | 101 | static inline void copy_user_highpage(struct page *to, struct page *from, |
| 102 | unsigned long vaddr, struct vm_area_struct *vma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | { |
| 104 | char *vfrom, *vto; |
| 105 | |
| 106 | vfrom = kmap_atomic(from, KM_USER0); |
| 107 | vto = kmap_atomic(to, KM_USER1); |
| 108 | copy_user_page(vto, vfrom, vaddr, to); |
| 109 | kunmap_atomic(vfrom, KM_USER0); |
| 110 | kunmap_atomic(vto, KM_USER1); |
| 111 | /* Make sure this page is cleared on other CPU's too before using it */ |
| 112 | smp_wmb(); |
| 113 | } |
| 114 | |
Atsushi Nemoto | 77fff4a | 2006-12-12 17:14:54 +0000 | [diff] [blame] | 115 | #endif |
| 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | static inline void copy_highpage(struct page *to, struct page *from) |
| 118 | { |
| 119 | char *vfrom, *vto; |
| 120 | |
| 121 | vfrom = kmap_atomic(from, KM_USER0); |
| 122 | vto = kmap_atomic(to, KM_USER1); |
| 123 | copy_page(vto, vfrom); |
| 124 | kunmap_atomic(vfrom, KM_USER0); |
| 125 | kunmap_atomic(vto, KM_USER1); |
| 126 | } |
| 127 | |
| 128 | #endif /* _LINUX_HIGHMEM_H */ |