Path: blob/master/arch/powerpc/include/asm/cacheflush.h
26481 views
/* SPDX-License-Identifier: GPL-2.0-or-later */1/*2*/3#ifndef _ASM_POWERPC_CACHEFLUSH_H4#define _ASM_POWERPC_CACHEFLUSH_H56#include <linux/mm.h>7#include <asm/cputable.h>8#include <asm/cpu_has_feature.h>910/*11* This flag is used to indicate that the page pointed to by a pte is clean12* and does not require cleaning before returning it to the user.13*/14#define PG_dcache_clean PG_arch_11516#ifdef CONFIG_PPC_BOOK3S_6417/*18* Book3s has no ptesync after setting a pte, so without this ptesync it's19* possible for a kernel virtual mapping access to return a spurious fault20* if it's accessed right after the pte is set. The page fault handler does21* not expect this type of fault. flush_cache_vmap is not exactly the right22* place to put this, but it seems to work well enough.23*/24static inline void flush_cache_vmap(unsigned long start, unsigned long end)25{26asm volatile("ptesync" ::: "memory");27}28#define flush_cache_vmap flush_cache_vmap29#endif /* CONFIG_PPC_BOOK3S_64 */3031#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 132/*33* This is called when a page has been modified by the kernel.34* It just marks the page as not i-cache clean. We do the i-cache35* flush later when the page is given to a user process, if necessary.36*/37static inline void flush_dcache_folio(struct folio *folio)38{39if (cpu_has_feature(CPU_FTR_COHERENT_ICACHE))40return;41/* avoid an atomic op if possible */42if (test_bit(PG_dcache_clean, &folio->flags))43clear_bit(PG_dcache_clean, &folio->flags);44}45#define flush_dcache_folio flush_dcache_folio4647static inline void flush_dcache_page(struct page *page)48{49flush_dcache_folio(page_folio(page));50}5152void flush_icache_range(unsigned long start, unsigned long stop);53#define flush_icache_range flush_icache_range5455void flush_icache_user_page(struct vm_area_struct *vma, struct page *page,56unsigned long addr, int len);57#define flush_icache_user_page flush_icache_user_page5859void flush_dcache_icache_folio(struct folio *folio);6061/**62* flush_dcache_range(): Write any modified data cache blocks out to memory and63* invalidate them. Does not invalidate the corresponding instruction cache64* blocks.65*66* @start: the start address67* @stop: the stop address (exclusive)68*/69static inline void flush_dcache_range(unsigned long start, unsigned long stop)70{71unsigned long shift = l1_dcache_shift();72unsigned long bytes = l1_dcache_bytes();73void *addr = (void *)(start & ~(bytes - 1));74unsigned long size = stop - (unsigned long)addr + (bytes - 1);75unsigned long i;7677if (IS_ENABLED(CONFIG_PPC64))78mb(); /* sync */7980for (i = 0; i < size >> shift; i++, addr += bytes)81dcbf(addr);82mb(); /* sync */8384}8586/*87* Write any modified data cache blocks out to memory.88* Does not invalidate the corresponding cache lines (especially for89* any corresponding instruction cache).90*/91static inline void clean_dcache_range(unsigned long start, unsigned long stop)92{93unsigned long shift = l1_dcache_shift();94unsigned long bytes = l1_dcache_bytes();95void *addr = (void *)(start & ~(bytes - 1));96unsigned long size = stop - (unsigned long)addr + (bytes - 1);97unsigned long i;9899for (i = 0; i < size >> shift; i++, addr += bytes)100dcbst(addr);101mb(); /* sync */102}103104/*105* Like above, but invalidate the D-cache. This is used by the 8xx106* to invalidate the cache so the PPC core doesn't get stale data107* from the CPM (no cache snooping here :-).108*/109static inline void invalidate_dcache_range(unsigned long start,110unsigned long stop)111{112unsigned long shift = l1_dcache_shift();113unsigned long bytes = l1_dcache_bytes();114void *addr = (void *)(start & ~(bytes - 1));115unsigned long size = stop - (unsigned long)addr + (bytes - 1);116unsigned long i;117118for (i = 0; i < size >> shift; i++, addr += bytes)119dcbi(addr);120mb(); /* sync */121}122123#ifdef CONFIG_44x124static inline void flush_instruction_cache(void)125{126iccci((void *)KERNELBASE);127isync();128}129#else130void flush_instruction_cache(void);131#endif132133#include <asm-generic/cacheflush.h>134135#endif /* _ASM_POWERPC_CACHEFLUSH_H */136137138