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