^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * highmem.c: virtual kernel memory mappings for high memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * PowerPC version, stolen from the i386 version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Used in CONFIG_HIGHMEM systems for memory pages which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * are not addressable by direct kernel virtual addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright (C) 1999 Gerhard Wichert, Siemens AG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Gerhard.Wichert@pdb.siemens.de
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Redesigned the x86 32-bit VM architecture to deal with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * up to 16 Terrabyte physical memory. With current x86 CPUs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * we now support up to 64 Gigabytes physical RAM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Copyright (C) 1999 Ingo Molnar <mingo@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Reworked for PowerPC by various contributors. Moved from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * highmem.h by Benjamin Herrenschmidt (c) 2009 IBM Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * gives a more generic (and caching) interface. But kmap_atomic can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * be used in IRQ contexts, so in some (very limited) cases we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <asm/tlbflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) void *kmap_atomic_high_prot(struct page *page, pgprot_t prot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) unsigned long vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) int idx, type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) type = kmap_atomic_idx_push();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) idx = type + KM_TYPE_NR*smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #ifdef CONFIG_DEBUG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) BUG_ON(!pte_none(*(kmap_pte-idx)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) set_pte_at(&init_mm, vaddr, kmap_pte-idx, mk_pte(page, prot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) local_flush_tlb_page(NULL, vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) return (void *) vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) EXPORT_SYMBOL(kmap_atomic_high_prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) void kunmap_atomic_high(void *kvaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) unsigned int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) if (vaddr < __fix_to_virt(FIX_KMAP_END))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) type = kmap_atomic_idx();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) idx = type + KM_TYPE_NR * smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #ifdef CONFIG_DEBUG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) BUG_ON(vaddr != __fix_to_virt(FIX_KMAP_BEGIN + idx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * force other mappings to Oops if they'll try to access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * this pte without first remap it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) pte_clear(&init_mm, vaddr, kmap_pte-idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) local_flush_tlb_page(NULL, vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) kmap_atomic_idx_pop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) EXPORT_SYMBOL(kunmap_atomic_high);