1 // SPDX-License-Identifier: GPL-2.0
3 * highmem.c: virtual kernel memory mappings for high memory
5 * PowerPC version, stolen from the i386 version.
7 * Used in CONFIG_HIGHMEM systems for memory pages which
8 * are not addressable by direct kernel virtual addresses.
10 * Copyright (C) 1999 Gerhard Wichert, Siemens AG
14 * Redesigned the x86 32-bit VM architecture to deal with
15 * up to 16 Terrabyte physical memory. With current x86 CPUs
16 * we now support up to 64 Gigabytes physical RAM.
20 * Reworked for PowerPC by various contributors. Moved from
21 * highmem.h by Benjamin Herrenschmidt (c) 2009 IBM Corp.
24 #include <linux/export.h>
25 #include <linux/highmem.h>
28 * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap
29 * gives a more generic (and caching) interface. But kmap_atomic can
30 * be used in IRQ contexts, so in some (very limited) cases we need
33 #include <asm/tlbflush.h>
35 void *kmap_atomic_high_prot(struct page *page, pgprot_t prot)
41 type = kmap_atomic_idx_push();
42 idx = type + KM_TYPE_NR*smp_processor_id();
43 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
44 #ifdef CONFIG_DEBUG_HIGHMEM
45 BUG_ON(!pte_none(*(kmap_pte-idx)));
47 set_pte_at(&init_mm, vaddr, kmap_pte-idx, mk_pte(page, prot));
48 local_flush_tlb_page(NULL, vaddr);
50 return (void *) vaddr;
52 EXPORT_SYMBOL(kmap_atomic_high_prot);
54 void kunmap_atomic_high(void *kvaddr)
56 unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
60 if (vaddr < __fix_to_virt(FIX_KMAP_END))
63 type = kmap_atomic_idx();
65 idx = type + KM_TYPE_NR * smp_processor_id();
66 #ifdef CONFIG_DEBUG_HIGHMEM
67 BUG_ON(vaddr != __fix_to_virt(FIX_KMAP_BEGIN + idx));
70 * force other mappings to Oops if they'll try to access
71 * this pte without first remap it
73 pte_clear(&init_mm, vaddr, kmap_pte-idx);
74 local_flush_tlb_page(NULL, vaddr);
76 kmap_atomic_idx_pop();
78 EXPORT_SYMBOL(kunmap_atomic_high);