1 #ifndef _LINUX_HIGHMEM_H 2 #define _LINUX_HIGHMEM_H 3 4 #include <linux/fs.h> 5 #include <linux/mm.h> 6 #include <linux/uaccess.h> 7 8 #include <asm/cacheflush.h> 9 10 #ifndef ARCH_HAS_FLUSH_ANON_PAGE 11 static inline void flush_anon_page(struct vm_area_struct *vma, struct page *page, unsigned long vmaddr) 12 { 13 } 14 #endif 15 16 #ifndef ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE 17 static inline void flush_kernel_dcache_page(struct page *page) 18 { 19 } 20 #endif 21 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 extern unsigned long totalhigh_pages; 29 30 #else /* CONFIG_HIGHMEM */ 31 32 static inline unsigned int nr_free_highpages(void) { return 0; } 33 34 #define totalhigh_pages 0 35 36 #ifndef ARCH_HAS_KMAP 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 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)) 49 #define kmap_atomic_to_page(ptr) virt_to_page(ptr) 50 #endif 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 99 #ifndef __HAVE_ARCH_COPY_USER_HIGHPAGE 100 101 static inline void copy_user_highpage(struct page *to, struct page *from, 102 unsigned long vaddr, struct vm_area_struct *vma) 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 115 #endif 116 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 */ 129