/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Based on arch/arm/include/asm/cacheflush.h3*4* Copyright (C) 1999-2002 Russell King.5* Copyright (C) 2012 ARM Ltd.6*/7#ifndef __ASM_CACHEFLUSH_H8#define __ASM_CACHEFLUSH_H910#include <linux/kgdb.h>11#include <linux/mm.h>1213/*14* This flag is used to indicate that the page pointed to by a pte is clean15* and does not require cleaning before returning it to the user.16*/17#define PG_dcache_clean PG_arch_11819/*20* MM Cache Management21* ===================22*23* The arch/arm64/mm/cache.S implements these methods.24*25* Start addresses are inclusive and end addresses are exclusive; start26* addresses should be rounded down, end addresses up.27*28* See Documentation/core-api/cachetlb.rst for more information. Please note that29* the implementation assumes non-aliasing VIPT D-cache and (aliasing)30* VIPT I-cache.31*32* All functions below apply to the interval [start, end)33* - start - virtual start address (inclusive)34* - end - virtual end address (exclusive)35*36* caches_clean_inval_pou(start, end)37*38* Ensure coherency between the I-cache and the D-cache region to39* the Point of Unification.40*41* caches_clean_inval_user_pou(start, end)42*43* Ensure coherency between the I-cache and the D-cache region to44* the Point of Unification.45* Use only if the region might access user memory.46*47* icache_inval_pou(start, end)48*49* Invalidate I-cache region to the Point of Unification.50*51* dcache_clean_inval_poc(start, end)52*53* Clean and invalidate D-cache region to the Point of Coherency.54*55* dcache_inval_poc(start, end)56*57* Invalidate D-cache region to the Point of Coherency.58*59* dcache_clean_poc(start, end)60*61* Clean D-cache region to the Point of Coherency.62*63* dcache_clean_pop(start, end)64*65* Clean D-cache region to the Point of Persistence.66*67* dcache_clean_pou(start, end)68*69* Clean D-cache region to the Point of Unification.70*/71extern void caches_clean_inval_pou(unsigned long start, unsigned long end);72extern void icache_inval_pou(unsigned long start, unsigned long end);73extern void dcache_clean_inval_poc(unsigned long start, unsigned long end);74extern void dcache_inval_poc(unsigned long start, unsigned long end);75extern void dcache_clean_poc(unsigned long start, unsigned long end);76extern void dcache_clean_pop(unsigned long start, unsigned long end);77extern void dcache_clean_pou(unsigned long start, unsigned long end);78extern long caches_clean_inval_user_pou(unsigned long start, unsigned long end);79extern void sync_icache_aliases(unsigned long start, unsigned long end);8081static inline void flush_icache_range(unsigned long start, unsigned long end)82{83caches_clean_inval_pou(start, end);8485/*86* IPI all online CPUs so that they undergo a context synchronization87* event and are forced to refetch the new instructions.88*/8990/*91* KGDB performs cache maintenance with interrupts disabled, so we92* will deadlock trying to IPI the secondary CPUs. In theory, we can93* set CACHE_FLUSH_IS_SAFE to 0 to avoid this known issue, but that94* just means that KGDB will elide the maintenance altogether! As it95* turns out, KGDB uses IPIs to round-up the secondary CPUs during96* the patching operation, so we don't need extra IPIs here anyway.97* In which case, add a KGDB-specific bodge and return early.98*/99if (in_dbg_master())100return;101102kick_all_cpus_sync();103}104#define flush_icache_range flush_icache_range105106/*107* Copy user data from/to a page which is mapped into a different108* processes address space. Really, we want to allow our "user109* space" model to handle this.110*/111extern void copy_to_user_page(struct vm_area_struct *, struct page *,112unsigned long, void *, const void *, unsigned long);113#define copy_to_user_page copy_to_user_page114115/*116* flush_dcache_folio is used when the kernel has written to the page117* cache page at virtual address page->virtual.118*119* If this page isn't mapped (ie, folio_mapping == NULL), or it might120* have userspace mappings, then we _must_ always clean + invalidate121* the dcache entries associated with the kernel mapping.122*123* Otherwise we can defer the operation, and clean the cache when we are124* about to change to user space. This is the same method as used on SPARC64.125* See update_mmu_cache for the user space part.126*/127#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1128extern void flush_dcache_page(struct page *);129void flush_dcache_folio(struct folio *);130#define flush_dcache_folio flush_dcache_folio131132static __always_inline void icache_inval_all_pou(void)133{134if (alternative_has_cap_unlikely(ARM64_HAS_CACHE_DIC))135return;136137asm("ic ialluis");138dsb(ish);139}140141#include <asm-generic/cacheflush.h>142143#endif /* __ASM_CACHEFLUSH_H */144145146