162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci#ifndef _ASM_HIGHMEM_H 362306a36Sopenharmony_ci#define _ASM_HIGHMEM_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci#include <asm/cachetype.h> 662306a36Sopenharmony_ci#include <asm/fixmap.h> 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#define PKMAP_BASE (PAGE_OFFSET - PMD_SIZE) 962306a36Sopenharmony_ci#define LAST_PKMAP PTRS_PER_PTE 1062306a36Sopenharmony_ci#define LAST_PKMAP_MASK (LAST_PKMAP - 1) 1162306a36Sopenharmony_ci#define PKMAP_NR(virt) (((virt) - PKMAP_BASE) >> PAGE_SHIFT) 1262306a36Sopenharmony_ci#define PKMAP_ADDR(nr) (PKMAP_BASE + ((nr) << PAGE_SHIFT)) 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#define flush_cache_kmaps() \ 1562306a36Sopenharmony_ci do { \ 1662306a36Sopenharmony_ci if (cache_is_vivt()) \ 1762306a36Sopenharmony_ci flush_cache_all(); \ 1862306a36Sopenharmony_ci } while (0) 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ciextern pte_t *pkmap_page_table; 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci/* 2362306a36Sopenharmony_ci * The reason for kmap_high_get() is to ensure that the currently kmap'd 2462306a36Sopenharmony_ci * page usage count does not decrease to zero while we're using its 2562306a36Sopenharmony_ci * existing virtual mapping in an atomic context. With a VIVT cache this 2662306a36Sopenharmony_ci * is essential to do, but with a VIPT cache this is only an optimization 2762306a36Sopenharmony_ci * so not to pay the price of establishing a second mapping if an existing 2862306a36Sopenharmony_ci * one can be used. However, on platforms without hardware TLB maintenance 2962306a36Sopenharmony_ci * broadcast, we simply cannot use ARCH_NEEDS_KMAP_HIGH_GET at all since 3062306a36Sopenharmony_ci * the locking involved must also disable IRQs which is incompatible with 3162306a36Sopenharmony_ci * the IPI mechanism used by global TLB operations. 3262306a36Sopenharmony_ci */ 3362306a36Sopenharmony_ci#define ARCH_NEEDS_KMAP_HIGH_GET 3462306a36Sopenharmony_ci#if defined(CONFIG_SMP) && defined(CONFIG_CPU_TLB_V6) 3562306a36Sopenharmony_ci#undef ARCH_NEEDS_KMAP_HIGH_GET 3662306a36Sopenharmony_ci#if defined(CONFIG_HIGHMEM) && defined(CONFIG_CPU_CACHE_VIVT) 3762306a36Sopenharmony_ci#error "The sum of features in your kernel config cannot be supported together" 3862306a36Sopenharmony_ci#endif 3962306a36Sopenharmony_ci#endif 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci/* 4262306a36Sopenharmony_ci * Needed to be able to broadcast the TLB invalidation for kmap. 4362306a36Sopenharmony_ci */ 4462306a36Sopenharmony_ci#ifdef CONFIG_ARM_ERRATA_798181 4562306a36Sopenharmony_ci#undef ARCH_NEEDS_KMAP_HIGH_GET 4662306a36Sopenharmony_ci#endif 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci#ifdef ARCH_NEEDS_KMAP_HIGH_GET 4962306a36Sopenharmony_ciextern void *kmap_high_get(struct page *page); 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_cistatic inline void *arch_kmap_local_high_get(struct page *page) 5262306a36Sopenharmony_ci{ 5362306a36Sopenharmony_ci if (IS_ENABLED(CONFIG_DEBUG_HIGHMEM) && !cache_is_vivt()) 5462306a36Sopenharmony_ci return NULL; 5562306a36Sopenharmony_ci return kmap_high_get(page); 5662306a36Sopenharmony_ci} 5762306a36Sopenharmony_ci#define arch_kmap_local_high_get arch_kmap_local_high_get 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci#else /* ARCH_NEEDS_KMAP_HIGH_GET */ 6062306a36Sopenharmony_cistatic inline void *kmap_high_get(struct page *page) 6162306a36Sopenharmony_ci{ 6262306a36Sopenharmony_ci return NULL; 6362306a36Sopenharmony_ci} 6462306a36Sopenharmony_ci#endif /* !ARCH_NEEDS_KMAP_HIGH_GET */ 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci#define arch_kmap_local_post_map(vaddr, pteval) \ 6762306a36Sopenharmony_ci local_flush_tlb_kernel_page(vaddr) 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci#define arch_kmap_local_pre_unmap(vaddr) \ 7062306a36Sopenharmony_cido { \ 7162306a36Sopenharmony_ci if (cache_is_vivt()) \ 7262306a36Sopenharmony_ci __cpuc_flush_dcache_area((void *)vaddr, PAGE_SIZE); \ 7362306a36Sopenharmony_ci} while (0) 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci#define arch_kmap_local_post_unmap(vaddr) \ 7662306a36Sopenharmony_ci local_flush_tlb_kernel_page(vaddr) 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci#endif 79