blob: ea5780b518ef2887737d7ce5eff28d0b4041638d [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>
Peter Zijlstraad76fb62006-12-06 20:32:21 -08006#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
8#include <asm/cacheflush.h>
9
James Bottomley03beb072006-03-26 01:36:57 -080010#ifndef ARCH_HAS_FLUSH_ANON_PAGE
11static inline void flush_anon_page(struct page *page, unsigned long vmaddr)
12{
13}
14#endif
15
James Bottomley5a3a5a92006-03-26 01:36:59 -080016#ifndef ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE
17static inline void flush_kernel_dcache_page(struct page *page)
18{
19}
20#endif
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#ifdef CONFIG_HIGHMEM
23
24#include <asm/highmem.h>
25
26/* declarations for linux/mm/highmem.c */
27unsigned int nr_free_highpages(void);
Christoph Lameterc1f60a52006-09-25 23:31:11 -070028extern unsigned long totalhigh_pages;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#else /* CONFIG_HIGHMEM */
31
32static inline unsigned int nr_free_highpages(void) { return 0; }
33
Christoph Lameterc1f60a52006-09-25 23:31:11 -070034#define totalhigh_pages 0
35
James Bottomleya6ca1b92006-09-25 23:30:55 -070036#ifndef ARCH_HAS_KMAP
Linus Torvalds1da177e2005-04-16 15:20:36 -070037static 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 Zijlstraad76fb62006-12-06 20:32:21 -080045#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 Torvalds1da177e2005-04-16 15:20:36 -070049#define kmap_atomic_to_page(ptr) virt_to_page(ptr)
James Bottomleya6ca1b92006-09-25 23:30:55 -070050#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52#endif /* CONFIG_HIGHMEM */
53
54/* when CONFIG_HIGHMEM is not set these will be plain clear/copy_page */
55static 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
65static inline struct page *
66alloc_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
77static 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 */
87static 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 Nemoto77fff4a2006-12-12 17:14:54 +000099#ifndef __HAVE_ARCH_COPY_USER_HIGHPAGE
100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101static inline void copy_user_highpage(struct page *to, struct page *from, unsigned long vaddr)
102{
103 char *vfrom, *vto;
104
105 vfrom = kmap_atomic(from, KM_USER0);
106 vto = kmap_atomic(to, KM_USER1);
107 copy_user_page(vto, vfrom, vaddr, to);
108 kunmap_atomic(vfrom, KM_USER0);
109 kunmap_atomic(vto, KM_USER1);
110 /* Make sure this page is cleared on other CPU's too before using it */
111 smp_wmb();
112}
113
Atsushi Nemoto77fff4a2006-12-12 17:14:54 +0000114#endif
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116static inline void copy_highpage(struct page *to, struct page *from)
117{
118 char *vfrom, *vto;
119
120 vfrom = kmap_atomic(from, KM_USER0);
121 vto = kmap_atomic(to, KM_USER1);
122 copy_page(vto, vfrom);
123 kunmap_atomic(vfrom, KM_USER0);
124 kunmap_atomic(vto, KM_USER1);
125}
126
127#endif /* _LINUX_HIGHMEM_H */