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 = virt_to_kpte(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 = virt_to_kpte(vaddr);
34 void *kmap_atomic_high_prot(struct page *page, pgprot_t prot)
41 #ifdef CONFIG_DEBUG_HIGHMEM
43 * There is no cache coherency issue when non VIVT, so force the
44 * dedicated kmap usage for better debugging purposes in that case.
50 kmap = kmap_high_get(page);
54 type = kmap_atomic_idx_push();
56 idx = FIX_KMAP_BEGIN + type + KM_TYPE_NR * smp_processor_id();
57 vaddr = __fix_to_virt(idx);
58 #ifdef CONFIG_DEBUG_HIGHMEM
60 * With debugging enabled, kunmap_atomic forces that entry to 0.
61 * Make sure it was indeed properly unmapped.
63 BUG_ON(!pte_none(get_fixmap_pte(vaddr)));
66 * When debugging is off, kunmap_atomic leaves the previous mapping
67 * in place, so the contained TLB flush ensures the TLB is updated
68 * with the new mapping.
70 set_fixmap_pte(idx, mk_pte(page, prot));
74 EXPORT_SYMBOL(kmap_atomic_high_prot);
76 void kunmap_atomic_high(void *kvaddr)
78 unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
81 if (kvaddr >= (void *)FIXADDR_START) {
82 type = kmap_atomic_idx();
83 idx = FIX_KMAP_BEGIN + type + KM_TYPE_NR * smp_processor_id();
86 __cpuc_flush_dcache_area((void *)vaddr, PAGE_SIZE);
87 #ifdef CONFIG_DEBUG_HIGHMEM
88 BUG_ON(vaddr != __fix_to_virt(idx));
89 set_fixmap_pte(idx, __pte(0));
91 (void) idx; /* to kill a warning */
93 kmap_atomic_idx_pop();
94 } else if (vaddr >= PKMAP_ADDR(0) && vaddr < PKMAP_ADDR(LAST_PKMAP)) {
95 /* this address was obtained through kmap_high_get() */
96 kunmap_high(pte_page(pkmap_page_table[PKMAP_NR(vaddr)]));
99 EXPORT_SYMBOL(kunmap_atomic_high);
101 void *kmap_atomic_pfn(unsigned long pfn)
105 struct page *page = pfn_to_page(pfn);
109 if (!PageHighMem(page))
110 return page_address(page);
112 type = kmap_atomic_idx_push();
113 idx = FIX_KMAP_BEGIN + type + KM_TYPE_NR * smp_processor_id();
114 vaddr = __fix_to_virt(idx);
115 #ifdef CONFIG_DEBUG_HIGHMEM
116 BUG_ON(!pte_none(get_fixmap_pte(vaddr)));
118 set_fixmap_pte(idx, pfn_pte(pfn, kmap_prot));
120 return (void *)vaddr;