Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_HIGHMEM_H |
| 2 | #define _LINUX_HIGHMEM_H |
| 3 | |
| 4 | #include <linux/config.h> |
| 5 | #include <linux/fs.h> |
| 6 | #include <linux/mm.h> |
| 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 |
| 11 | static inline void flush_anon_page(struct page *page, unsigned long vmaddr) |
| 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); |
| 28 | |
| 29 | #else /* CONFIG_HIGHMEM */ |
| 30 | |
| 31 | static inline unsigned int nr_free_highpages(void) { return 0; } |
| 32 | |
| 33 | static inline void *kmap(struct page *page) |
| 34 | { |
| 35 | might_sleep(); |
| 36 | return page_address(page); |
| 37 | } |
| 38 | |
| 39 | #define kunmap(page) do { (void) (page); } while (0) |
| 40 | |
| 41 | #define kmap_atomic(page, idx) page_address(page) |
| 42 | #define kunmap_atomic(addr, idx) do { } while (0) |
Vivek Goyal | 60e64d4 | 2005-06-25 14:58:19 -0700 | [diff] [blame] | 43 | #define kmap_atomic_pfn(pfn, idx) page_address(pfn_to_page(pfn)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #define kmap_atomic_to_page(ptr) virt_to_page(ptr) |
| 45 | |
| 46 | #endif /* CONFIG_HIGHMEM */ |
| 47 | |
| 48 | /* when CONFIG_HIGHMEM is not set these will be plain clear/copy_page */ |
| 49 | static inline void clear_user_highpage(struct page *page, unsigned long vaddr) |
| 50 | { |
| 51 | void *addr = kmap_atomic(page, KM_USER0); |
| 52 | clear_user_page(addr, vaddr, page); |
| 53 | kunmap_atomic(addr, KM_USER0); |
| 54 | /* Make sure this page is cleared on other CPU's too before using it */ |
| 55 | smp_wmb(); |
| 56 | } |
| 57 | |
| 58 | #ifndef __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE |
| 59 | static inline struct page * |
| 60 | alloc_zeroed_user_highpage(struct vm_area_struct *vma, unsigned long vaddr) |
| 61 | { |
| 62 | struct page *page = alloc_page_vma(GFP_HIGHUSER, vma, vaddr); |
| 63 | |
| 64 | if (page) |
| 65 | clear_user_highpage(page, vaddr); |
| 66 | |
| 67 | return page; |
| 68 | } |
| 69 | #endif |
| 70 | |
| 71 | static inline void clear_highpage(struct page *page) |
| 72 | { |
| 73 | void *kaddr = kmap_atomic(page, KM_USER0); |
| 74 | clear_page(kaddr); |
| 75 | kunmap_atomic(kaddr, KM_USER0); |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * Same but also flushes aliased cache contents to RAM. |
| 80 | */ |
| 81 | static inline void memclear_highpage_flush(struct page *page, unsigned int offset, unsigned int size) |
| 82 | { |
| 83 | void *kaddr; |
| 84 | |
| 85 | BUG_ON(offset + size > PAGE_SIZE); |
| 86 | |
| 87 | kaddr = kmap_atomic(page, KM_USER0); |
| 88 | memset((char *)kaddr + offset, 0, size); |
| 89 | flush_dcache_page(page); |
| 90 | kunmap_atomic(kaddr, KM_USER0); |
| 91 | } |
| 92 | |
| 93 | static inline void copy_user_highpage(struct page *to, struct page *from, unsigned long vaddr) |
| 94 | { |
| 95 | char *vfrom, *vto; |
| 96 | |
| 97 | vfrom = kmap_atomic(from, KM_USER0); |
| 98 | vto = kmap_atomic(to, KM_USER1); |
| 99 | copy_user_page(vto, vfrom, vaddr, to); |
| 100 | kunmap_atomic(vfrom, KM_USER0); |
| 101 | kunmap_atomic(vto, KM_USER1); |
| 102 | /* Make sure this page is cleared on other CPU's too before using it */ |
| 103 | smp_wmb(); |
| 104 | } |
| 105 | |
| 106 | static inline void copy_highpage(struct page *to, struct page *from) |
| 107 | { |
| 108 | char *vfrom, *vto; |
| 109 | |
| 110 | vfrom = kmap_atomic(from, KM_USER0); |
| 111 | vto = kmap_atomic(to, KM_USER1); |
| 112 | copy_page(vto, vfrom); |
| 113 | kunmap_atomic(vfrom, KM_USER0); |
| 114 | kunmap_atomic(vto, KM_USER1); |
| 115 | } |
| 116 | |
| 117 | #endif /* _LINUX_HIGHMEM_H */ |