1 // SPDX-License-Identifier: GPL-2.0-only
3 * arch/arm/mm/highmem.c -- ARM highmem support
5 * Author: Nicolas Pitre
6 * Created: september 8, 2008
7 * Copyright: Marvell Semiconductors Inc.
10 #include <linux/module.h>
11 #include <linux/highmem.h>
12 #include <linux/interrupt.h>
13 #include <asm/fixmap.h>
14 #include <asm/cacheflush.h>
15 #include <asm/tlbflush.h>
18 static inline void set_fixmap_pte(int idx
, pte_t pte
)
20 unsigned long vaddr
= __fix_to_virt(idx
);
21 pte_t
*ptep
= pte_offset_kernel(pmd_off_k(vaddr
), vaddr
);
23 set_pte_ext(ptep
, pte
, 0);
24 local_flush_tlb_kernel_page(vaddr
);
27 static inline pte_t
get_fixmap_pte(unsigned long vaddr
)
29 pte_t
*ptep
= pte_offset_kernel(pmd_off_k(vaddr
), vaddr
);
34 void *kmap(struct page
*page
)
37 if (!PageHighMem(page
))
38 return page_address(page
);
39 return kmap_high(page
);
43 void kunmap(struct page
*page
)
45 BUG_ON(in_interrupt());
46 if (!PageHighMem(page
))
50 EXPORT_SYMBOL(kunmap
);
52 void *kmap_atomic(struct page
*page
)
61 if (!PageHighMem(page
))
62 return page_address(page
);
64 #ifdef CONFIG_DEBUG_HIGHMEM
66 * There is no cache coherency issue when non VIVT, so force the
67 * dedicated kmap usage for better debugging purposes in that case.
73 kmap
= kmap_high_get(page
);
77 type
= kmap_atomic_idx_push();
79 idx
= FIX_KMAP_BEGIN
+ type
+ KM_TYPE_NR
* smp_processor_id();
80 vaddr
= __fix_to_virt(idx
);
81 #ifdef CONFIG_DEBUG_HIGHMEM
83 * With debugging enabled, kunmap_atomic forces that entry to 0.
84 * Make sure it was indeed properly unmapped.
86 BUG_ON(!pte_none(get_fixmap_pte(vaddr
)));
89 * When debugging is off, kunmap_atomic leaves the previous mapping
90 * in place, so the contained TLB flush ensures the TLB is updated
91 * with the new mapping.
93 set_fixmap_pte(idx
, mk_pte(page
, kmap_prot
));
97 EXPORT_SYMBOL(kmap_atomic
);
99 void __kunmap_atomic(void *kvaddr
)
101 unsigned long vaddr
= (unsigned long) kvaddr
& PAGE_MASK
;
104 if (kvaddr
>= (void *)FIXADDR_START
) {
105 type
= kmap_atomic_idx();
106 idx
= FIX_KMAP_BEGIN
+ type
+ KM_TYPE_NR
* smp_processor_id();
109 __cpuc_flush_dcache_area((void *)vaddr
, PAGE_SIZE
);
110 #ifdef CONFIG_DEBUG_HIGHMEM
111 BUG_ON(vaddr
!= __fix_to_virt(idx
));
112 set_fixmap_pte(idx
, __pte(0));
114 (void) idx
; /* to kill a warning */
116 kmap_atomic_idx_pop();
117 } else if (vaddr
>= PKMAP_ADDR(0) && vaddr
< PKMAP_ADDR(LAST_PKMAP
)) {
118 /* this address was obtained through kmap_high_get() */
119 kunmap_high(pte_page(pkmap_page_table
[PKMAP_NR(vaddr
)]));
124 EXPORT_SYMBOL(__kunmap_atomic
);
126 void *kmap_atomic_pfn(unsigned long pfn
)
130 struct page
*page
= pfn_to_page(pfn
);
134 if (!PageHighMem(page
))
135 return page_address(page
);
137 type
= kmap_atomic_idx_push();
138 idx
= FIX_KMAP_BEGIN
+ type
+ KM_TYPE_NR
* smp_processor_id();
139 vaddr
= __fix_to_virt(idx
);
140 #ifdef CONFIG_DEBUG_HIGHMEM
141 BUG_ON(!pte_none(get_fixmap_pte(vaddr
)));
143 set_fixmap_pte(idx
, pfn_pte(pfn
, kmap_prot
));
145 return (void *)vaddr
;