xref: /openbmc/linux/arch/microblaze/include/asm/cacheflush.h (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
14726dd60SMichal Simek /* SPDX-License-Identifier: GPL-2.0 */
28beb8503SMichal Simek /*
346fb9be9SMichal Simek  * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
446fb9be9SMichal Simek  * Copyright (C) 2007-2009 PetaLogix
58beb8503SMichal Simek  * Copyright (C) 2007 John Williams <john.williams@petalogix.com>
68beb8503SMichal Simek  * based on v850 version which was
78beb8503SMichal Simek  * Copyright (C) 2001,02,03 NEC Electronics Corporation
88beb8503SMichal Simek  * Copyright (C) 2001,02,03 Miles Bader <miles@gnu.org>
98beb8503SMichal Simek  */
108beb8503SMichal Simek 
118beb8503SMichal Simek #ifndef _ASM_MICROBLAZE_CACHEFLUSH_H
128beb8503SMichal Simek #define _ASM_MICROBLAZE_CACHEFLUSH_H
138beb8503SMichal Simek 
148beb8503SMichal Simek /* Somebody depends on this; sigh... */
158beb8503SMichal Simek #include <linux/mm.h>
1679e87830SMichal Simek #include <linux/io.h>
178beb8503SMichal Simek 
185fb94e9cSMauro Carvalho Chehab /* Look at Documentation/core-api/cachetlb.rst */
192ee2ff87SMichal Simek 
208beb8503SMichal Simek /*
218beb8503SMichal Simek  * Cache handling functions.
228beb8503SMichal Simek  * Microblaze has a write-through data cache, meaning that the data cache
238beb8503SMichal Simek  * never needs to be flushed.  The only flushing operations that are
248beb8503SMichal Simek  * implemented are to invalidate the instruction cache.  These are called
258beb8503SMichal Simek  * after loading a user application into memory, we must invalidate the
268beb8503SMichal Simek  * instruction cache to make sure we don't fetch old, bad code.
278beb8503SMichal Simek  */
288beb8503SMichal Simek 
292ee2ff87SMichal Simek /* struct cache, d=dcache, i=icache, fl = flush, iv = invalidate,
302ee2ff87SMichal Simek  * suffix r = range */
312ee2ff87SMichal Simek struct scache {
322ee2ff87SMichal Simek 	/* icache */
332ee2ff87SMichal Simek 	void (*ie)(void); /* enable */
342ee2ff87SMichal Simek 	void (*id)(void); /* disable */
352ee2ff87SMichal Simek 	void (*ifl)(void); /* flush */
362ee2ff87SMichal Simek 	void (*iflr)(unsigned long a, unsigned long b);
372ee2ff87SMichal Simek 	void (*iin)(void); /* invalidate */
382ee2ff87SMichal Simek 	void (*iinr)(unsigned long a, unsigned long b);
392ee2ff87SMichal Simek 	/* dcache */
402ee2ff87SMichal Simek 	void (*de)(void); /* enable */
412ee2ff87SMichal Simek 	void (*dd)(void); /* disable */
422ee2ff87SMichal Simek 	void (*dfl)(void); /* flush */
432ee2ff87SMichal Simek 	void (*dflr)(unsigned long a, unsigned long b);
442ee2ff87SMichal Simek 	void (*din)(void); /* invalidate */
452ee2ff87SMichal Simek 	void (*dinr)(unsigned long a, unsigned long b);
462ee2ff87SMichal Simek };
472ee2ff87SMichal Simek 
482ee2ff87SMichal Simek /* microblaze cache */
492ee2ff87SMichal Simek extern struct scache *mbc;
502ee2ff87SMichal Simek 
512ee2ff87SMichal Simek void microblaze_cache_init(void);
522ee2ff87SMichal Simek 
532ee2ff87SMichal Simek #define enable_icache()					mbc->ie();
542ee2ff87SMichal Simek #define disable_icache()				mbc->id();
552ee2ff87SMichal Simek #define flush_icache()					mbc->ifl();
562ee2ff87SMichal Simek #define flush_icache_range(start, end)			mbc->iflr(start, end);
572ee2ff87SMichal Simek #define invalidate_icache()				mbc->iin();
582ee2ff87SMichal Simek #define invalidate_icache_range(start, end)		mbc->iinr(start, end);
592ee2ff87SMichal Simek 
602ee2ff87SMichal Simek #define enable_dcache()					mbc->de();
612ee2ff87SMichal Simek #define disable_dcache()				mbc->dd();
628beb8503SMichal Simek /* FIXME for LL-temac driver */
632ee2ff87SMichal Simek #define invalidate_dcache()				mbc->din();
642ee2ff87SMichal Simek #define invalidate_dcache_range(start, end)		mbc->dinr(start, end);
652ee2ff87SMichal Simek #define flush_dcache()					mbc->dfl();
662ee2ff87SMichal Simek #define flush_dcache_range(start, end)			mbc->dflr(start, end);
678beb8503SMichal Simek 
6879e87830SMichal Simek #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
6979e87830SMichal Simek /* MS: We have to implement it because of rootfs-jffs2 issue on WB */
7079e87830SMichal Simek #define flush_dcache_page(page) \
7179e87830SMichal Simek do { \
7279e87830SMichal Simek 	unsigned long addr = (unsigned long) page_address(page); /* virtual */ \
7379e87830SMichal Simek 	addr = (u32)virt_to_phys((void *)addr); \
7479e87830SMichal Simek 	flush_dcache_range((unsigned) (addr), (unsigned) (addr) + PAGE_SIZE); \
7579e87830SMichal Simek } while (0);
7679e87830SMichal Simek 
flush_dcache_folio(struct folio * folio)77*27a8b944SMatthew Wilcox (Oracle) static inline void flush_dcache_folio(struct folio *folio)
78*27a8b944SMatthew Wilcox (Oracle) {
79*27a8b944SMatthew Wilcox (Oracle) 	unsigned long addr = folio_pfn(folio) << PAGE_SHIFT;
80*27a8b944SMatthew Wilcox (Oracle) 
81*27a8b944SMatthew Wilcox (Oracle) 	flush_dcache_range(addr, addr + folio_size(folio));
82*27a8b944SMatthew Wilcox (Oracle) }
83*27a8b944SMatthew Wilcox (Oracle) #define flush_dcache_folio flush_dcache_folio
84*27a8b944SMatthew Wilcox (Oracle) 
85a706729cSMichal Simek #define flush_cache_page(vma, vmaddr, pfn) \
86a706729cSMichal Simek 	flush_dcache_range(pfn << PAGE_SHIFT, (pfn << PAGE_SHIFT) + PAGE_SIZE);
878beb8503SMichal Simek 
copy_to_user_page(struct vm_area_struct * vma,struct page * page,unsigned long vaddr,void * dst,void * src,int len)8862bc82a8SMichal Simek static inline void copy_to_user_page(struct vm_area_struct *vma,
8962bc82a8SMichal Simek 				     struct page *page, unsigned long vaddr,
9062bc82a8SMichal Simek 				     void *dst, void *src, int len)
9162bc82a8SMichal Simek {
9262bc82a8SMichal Simek 	u32 addr = virt_to_phys(dst);
9362bc82a8SMichal Simek 	memcpy(dst, src, len);
9462bc82a8SMichal Simek 	if (vma->vm_flags & VM_EXEC) {
9562bc82a8SMichal Simek 		invalidate_icache_range(addr, addr + PAGE_SIZE);
9662bc82a8SMichal Simek 		flush_dcache_range(addr, addr + PAGE_SIZE);
9762bc82a8SMichal Simek 	}
9862bc82a8SMichal Simek }
9903518c82SChristoph Hellwig #define copy_to_user_page copy_to_user_page
1008beb8503SMichal Simek 
10103518c82SChristoph Hellwig #include <asm-generic/cacheflush.h>
1028beb8503SMichal Simek 
1038beb8503SMichal Simek #endif /* _ASM_MICROBLAZE_CACHEFLUSH_H */
104