^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * arch/arm/mm/highmem.c -- ARM highmem support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Author: Nicolas Pitre
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Created: september 8, 2008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright: Marvell Semiconductors Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/fixmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <asm/tlbflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "mm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) static inline void set_fixmap_pte(int idx, pte_t pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) unsigned long vaddr = __fix_to_virt(idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) pte_t *ptep = virt_to_kpte(vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) set_pte_ext(ptep, pte, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) local_flush_tlb_kernel_page(vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static inline pte_t get_fixmap_pte(unsigned long vaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) pte_t *ptep = virt_to_kpte(vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) return *ptep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) void *kmap_atomic_high_prot(struct page *page, pgprot_t prot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) unsigned int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) unsigned long vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) void *kmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #ifdef CONFIG_DEBUG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * There is no cache coherency issue when non VIVT, so force the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * dedicated kmap usage for better debugging purposes in that case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (!cache_is_vivt())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) kmap = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) kmap = kmap_high_get(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) if (kmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return kmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) type = kmap_atomic_idx_push();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) idx = FIX_KMAP_BEGIN + type + KM_TYPE_NR * smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) vaddr = __fix_to_virt(idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #ifdef CONFIG_DEBUG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * With debugging enabled, kunmap_atomic forces that entry to 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * Make sure it was indeed properly unmapped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) BUG_ON(!pte_none(get_fixmap_pte(vaddr)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * When debugging is off, kunmap_atomic leaves the previous mapping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * in place, so the contained TLB flush ensures the TLB is updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * with the new mapping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) set_fixmap_pte(idx, mk_pte(page, prot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return (void *)vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) EXPORT_SYMBOL(kmap_atomic_high_prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) void kunmap_atomic_high(void *kvaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) int idx, type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (kvaddr >= (void *)FIXADDR_START) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) type = kmap_atomic_idx();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) idx = FIX_KMAP_BEGIN + type + KM_TYPE_NR * smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (cache_is_vivt())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) __cpuc_flush_dcache_area((void *)vaddr, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #ifdef CONFIG_DEBUG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) BUG_ON(vaddr != __fix_to_virt(idx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) set_fixmap_pte(idx, __pte(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) (void) idx; /* to kill a warning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) kmap_atomic_idx_pop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) } else if (vaddr >= PKMAP_ADDR(0) && vaddr < PKMAP_ADDR(LAST_PKMAP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /* this address was obtained through kmap_high_get() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) kunmap_high(pte_page(pkmap_page_table[PKMAP_NR(vaddr)]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) EXPORT_SYMBOL(kunmap_atomic_high);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) void *kmap_atomic_pfn(unsigned long pfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) unsigned long vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) int idx, type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct page *page = pfn_to_page(pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) pagefault_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (!PageHighMem(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) type = kmap_atomic_idx_push();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) idx = FIX_KMAP_BEGIN + type + KM_TYPE_NR * smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) vaddr = __fix_to_virt(idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #ifdef CONFIG_DEBUG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) BUG_ON(!pte_none(get_fixmap_pte(vaddr)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) set_fixmap_pte(idx, pfn_pte(pfn, kmap_prot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return (void *)vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }