1d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitre#ifndef _ASM_HIGHMEM_H
2d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitre#define _ASM_HIGHMEM_H
3d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitre
4d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitre#include <asm/kmap_types.h>
5d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitre
6d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitre#define PKMAP_BASE		(PAGE_OFFSET - PMD_SIZE)
7d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitre#define LAST_PKMAP		PTRS_PER_PTE
8d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitre#define LAST_PKMAP_MASK		(LAST_PKMAP - 1)
9d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitre#define PKMAP_NR(virt)		(((virt) - PKMAP_BASE) >> PAGE_SHIFT)
10d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitre#define PKMAP_ADDR(nr)		(PKMAP_BASE + ((nr) << PAGE_SHIFT))
11d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitre
12d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitre#define kmap_prot		PAGE_KERNEL
13d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitre
147e5a69e83ba7a0d5917ad830f417cba8b8d6aa72Nicolas Pitre#define flush_cache_kmaps() \
157e5a69e83ba7a0d5917ad830f417cba8b8d6aa72Nicolas Pitre	do { \
167e5a69e83ba7a0d5917ad830f417cba8b8d6aa72Nicolas Pitre		if (cache_is_vivt()) \
177e5a69e83ba7a0d5917ad830f417cba8b8d6aa72Nicolas Pitre			flush_cache_all(); \
187e5a69e83ba7a0d5917ad830f417cba8b8d6aa72Nicolas Pitre	} while (0)
19d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitre
20d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitreextern pte_t *pkmap_page_table;
21a05e54c103b0b8e1dab5d04b411f1d48387c4903Liu Huaextern pte_t *fixmap_page_table;
22d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitre
23aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitreextern void *kmap_high(struct page *page);
24aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitreextern void kunmap_high(struct page *page);
25aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre
26aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre/*
27aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre * The reason for kmap_high_get() is to ensure that the currently kmap'd
28aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre * page usage count does not decrease to zero while we're using its
29aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre * existing virtual mapping in an atomic context.  With a VIVT cache this
30aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre * is essential to do, but with a VIPT cache this is only an optimization
31aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre * so not to pay the price of establishing a second mapping if an existing
32aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre * one can be used.  However, on platforms without hardware TLB maintenance
33aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre * broadcast, we simply cannot use ARCH_NEEDS_KMAP_HIGH_GET at all since
34aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre * the locking involved must also disable IRQs which is incompatible with
35aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre * the IPI mechanism used by global TLB operations.
36aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre */
3743377453af83b8ff8c1c731da1508bd6b84ebfeaNicolas Pitre#define ARCH_NEEDS_KMAP_HIGH_GET
38aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre#if defined(CONFIG_SMP) && defined(CONFIG_CPU_TLB_V6)
39aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre#undef ARCH_NEEDS_KMAP_HIGH_GET
40aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre#if defined(CONFIG_HIGHMEM) && defined(CONFIG_CPU_CACHE_VIVT)
41aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre#error "The sum of features in your kernel config cannot be supported together"
42aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre#endif
43aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre#endif
4443377453af83b8ff8c1c731da1508bd6b84ebfeaNicolas Pitre
4593dc68876b608da041fe40ed39424b0fcd5aa2fbCatalin Marinas/*
4693dc68876b608da041fe40ed39424b0fcd5aa2fbCatalin Marinas * Needed to be able to broadcast the TLB invalidation for kmap.
4793dc68876b608da041fe40ed39424b0fcd5aa2fbCatalin Marinas */
4893dc68876b608da041fe40ed39424b0fcd5aa2fbCatalin Marinas#ifdef CONFIG_ARM_ERRATA_798181
4993dc68876b608da041fe40ed39424b0fcd5aa2fbCatalin Marinas#undef ARCH_NEEDS_KMAP_HIGH_GET
5093dc68876b608da041fe40ed39424b0fcd5aa2fbCatalin Marinas#endif
5193dc68876b608da041fe40ed39424b0fcd5aa2fbCatalin Marinas
52aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre#ifdef ARCH_NEEDS_KMAP_HIGH_GET
5343377453af83b8ff8c1c731da1508bd6b84ebfeaNicolas Pitreextern void *kmap_high_get(struct page *page);
54aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre#else
55aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitrestatic inline void *kmap_high_get(struct page *page)
56aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre{
57aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre	return NULL;
58aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre}
59aaa50048f6ce44af66ce0389d4cc6a8348333271Nicolas Pitre#endif
60d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitre
617e5a69e83ba7a0d5917ad830f417cba8b8d6aa72Nicolas Pitre/*
627e5a69e83ba7a0d5917ad830f417cba8b8d6aa72Nicolas Pitre * The following functions are already defined by <linux/highmem.h>
637e5a69e83ba7a0d5917ad830f417cba8b8d6aa72Nicolas Pitre * when CONFIG_HIGHMEM is not set.
647e5a69e83ba7a0d5917ad830f417cba8b8d6aa72Nicolas Pitre */
657e5a69e83ba7a0d5917ad830f417cba8b8d6aa72Nicolas Pitre#ifdef CONFIG_HIGHMEM
66d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitreextern void *kmap(struct page *page);
67d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitreextern void kunmap(struct page *page);
68a24401bcf4a67c8fe17e649e74eeb09b08b79ef5Cong Wangextern void *kmap_atomic(struct page *page);
693e4d3af501cccdc8a8cca41bdbe57d54ad7e7e73Peter Zijlstraextern void __kunmap_atomic(void *kvaddr);
703e4d3af501cccdc8a8cca41bdbe57d54ad7e7e73Peter Zijlstraextern void *kmap_atomic_pfn(unsigned long pfn);
71d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitreextern struct page *kmap_atomic_to_page(const void *ptr);
727e5a69e83ba7a0d5917ad830f417cba8b8d6aa72Nicolas Pitre#endif
73d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitre
74d73cd42893f4cdc06e6829fea2347bb92cb789d1Nicolas Pitre#endif
75