1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_HIGHMEM_INTERNAL_H
3 #define _LINUX_HIGHMEM_INTERNAL_H
6 * Outside of CONFIG_HIGHMEM to support X86 32bit iomap_atomic() cruft.
8 #ifdef CONFIG_KMAP_LOCAL
9 void *__kmap_local_pfn_prot(unsigned long pfn
, pgprot_t prot
);
10 void *__kmap_local_page_prot(struct page
*page
, pgprot_t prot
);
11 void kunmap_local_indexed(void *vaddr
);
12 void kmap_local_fork(struct task_struct
*tsk
);
13 void __kmap_local_sched_out(void);
14 void __kmap_local_sched_in(void);
15 static inline void kmap_assert_nomap(void)
17 DEBUG_LOCKS_WARN_ON(current
->kmap_ctrl
.idx
);
20 static inline void kmap_local_fork(struct task_struct
*tsk
) { }
21 static inline void kmap_assert_nomap(void) { }
25 #include <asm/highmem.h>
27 #ifndef ARCH_HAS_KMAP_FLUSH_TLB
28 static inline void kmap_flush_tlb(unsigned long addr
) { }
32 #define kmap_prot PAGE_KERNEL
35 void *kmap_high(struct page
*page
);
36 void kunmap_high(struct page
*page
);
37 void __kmap_flush_unused(void);
38 struct page
*__kmap_to_page(void *addr
);
40 static inline void *kmap(struct page
*page
)
45 if (!PageHighMem(page
))
46 addr
= page_address(page
);
48 addr
= kmap_high(page
);
49 kmap_flush_tlb((unsigned long)addr
);
53 static inline void kunmap(struct page
*page
)
56 if (!PageHighMem(page
))
61 static inline struct page
*kmap_to_page(void *addr
)
63 return __kmap_to_page(addr
);
66 static inline void kmap_flush_unused(void)
68 __kmap_flush_unused();
71 static inline void *kmap_local_page(struct page
*page
)
73 return __kmap_local_page_prot(page
, kmap_prot
);
76 static inline void *kmap_local_page_prot(struct page
*page
, pgprot_t prot
)
78 return __kmap_local_page_prot(page
, prot
);
81 static inline void *kmap_local_pfn(unsigned long pfn
)
83 return __kmap_local_pfn_prot(pfn
, kmap_prot
);
86 static inline void __kunmap_local(void *vaddr
)
88 kunmap_local_indexed(vaddr
);
91 static inline void *kmap_atomic_prot(struct page
*page
, pgprot_t prot
)
93 if (IS_ENABLED(CONFIG_PREEMPT_RT
))
99 return __kmap_local_page_prot(page
, prot
);
102 static inline void *kmap_atomic(struct page
*page
)
104 return kmap_atomic_prot(page
, kmap_prot
);
107 static inline void *kmap_atomic_pfn(unsigned long pfn
)
109 if (IS_ENABLED(CONFIG_PREEMPT_RT
))
115 return __kmap_local_pfn_prot(pfn
, kmap_prot
);
118 static inline void __kunmap_atomic(void *addr
)
120 kunmap_local_indexed(addr
);
122 if (IS_ENABLED(CONFIG_PREEMPT_RT
))
128 unsigned int __nr_free_highpages(void);
129 extern atomic_long_t _totalhigh_pages
;
131 static inline unsigned int nr_free_highpages(void)
133 return __nr_free_highpages();
136 static inline unsigned long totalhigh_pages(void)
138 return (unsigned long)atomic_long_read(&_totalhigh_pages
);
141 static inline void totalhigh_pages_add(long count
)
143 atomic_long_add(count
, &_totalhigh_pages
);
146 #else /* CONFIG_HIGHMEM */
148 static inline struct page
*kmap_to_page(void *addr
)
150 return virt_to_page(addr
);
153 static inline void *kmap(struct page
*page
)
156 return page_address(page
);
159 static inline void kunmap_high(struct page
*page
) { }
160 static inline void kmap_flush_unused(void) { }
162 static inline void kunmap(struct page
*page
)
164 #ifdef ARCH_HAS_FLUSH_ON_KUNMAP
165 kunmap_flush_on_unmap(page_address(page
));
169 static inline void *kmap_local_page(struct page
*page
)
171 return page_address(page
);
174 static inline void *kmap_local_page_prot(struct page
*page
, pgprot_t prot
)
176 return kmap_local_page(page
);
179 static inline void *kmap_local_pfn(unsigned long pfn
)
181 return kmap_local_page(pfn_to_page(pfn
));
184 static inline void __kunmap_local(void *addr
)
186 #ifdef ARCH_HAS_FLUSH_ON_KUNMAP
187 kunmap_flush_on_unmap(addr
);
191 static inline void *kmap_atomic(struct page
*page
)
193 if (IS_ENABLED(CONFIG_PREEMPT_RT
))
198 return page_address(page
);
201 static inline void *kmap_atomic_prot(struct page
*page
, pgprot_t prot
)
203 return kmap_atomic(page
);
206 static inline void *kmap_atomic_pfn(unsigned long pfn
)
208 return kmap_atomic(pfn_to_page(pfn
));
211 static inline void __kunmap_atomic(void *addr
)
213 #ifdef ARCH_HAS_FLUSH_ON_KUNMAP
214 kunmap_flush_on_unmap(addr
);
217 if (IS_ENABLED(CONFIG_PREEMPT_RT
))
223 static inline unsigned int nr_free_highpages(void) { return 0; }
224 static inline unsigned long totalhigh_pages(void) { return 0UL; }
226 #endif /* CONFIG_HIGHMEM */
229 * Prevent people trying to call kunmap_atomic() as if it were kunmap()
230 * kunmap_atomic() should get the return value of kmap_atomic, not the page.
232 #define kunmap_atomic(__addr) \
234 BUILD_BUG_ON(__same_type((__addr), struct page *)); \
235 __kunmap_atomic(__addr); \
238 #define kunmap_local(__addr) \
240 BUILD_BUG_ON(__same_type((__addr), struct page *)); \
241 __kunmap_local(__addr); \