1 #ifndef _LINUX_HIGHMEM_H
2 #define _LINUX_HIGHMEM_H
6 #include <linux/uaccess.h>
8 #include <asm/cacheflush.h>
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
)
16 #ifndef ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE
17 static inline void flush_kernel_dcache_page(struct page
*page
)
24 #include <asm/highmem.h>
26 /* declarations for linux/mm/highmem.c */
27 unsigned int nr_free_highpages(void);
28 extern unsigned long totalhigh_pages
;
30 #else /* CONFIG_HIGHMEM */
32 static inline unsigned int nr_free_highpages(void) { return 0; }
34 #define totalhigh_pages 0
37 static inline void *kmap(struct page
*page
)
40 return page_address(page
);
43 #define kunmap(page) do { (void) (page); } while (0)
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)
52 #endif /* CONFIG_HIGHMEM */
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
)
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 */
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
)
68 struct page
*page
= alloc_page_vma(GFP_HIGHUSER
, vma
, vaddr
);
71 clear_user_highpage(page
, vaddr
);
77 static inline void clear_highpage(struct page
*page
)
79 void *kaddr
= kmap_atomic(page
, KM_USER0
);
81 kunmap_atomic(kaddr
, KM_USER0
);
85 * Same but also flushes aliased cache contents to RAM.
87 static inline void memclear_highpage_flush(struct page
*page
, unsigned int offset
, unsigned int size
)
91 BUG_ON(offset
+ size
> PAGE_SIZE
);
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
);
99 #ifndef __HAVE_ARCH_COPY_USER_HIGHPAGE
101 static inline void copy_user_highpage(struct page
*to
, struct page
*from
,
102 unsigned long vaddr
, struct vm_area_struct
*vma
)
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 */
117 static inline void copy_highpage(struct page
*to
, struct page
*from
)
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
);
128 #endif /* _LINUX_HIGHMEM_H */