162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu> 462306a36Sopenharmony_ci * Copyright (C) 2007-2009 PetaLogix 562306a36Sopenharmony_ci * Copyright (C) 2007 John Williams <john.williams@petalogix.com> 662306a36Sopenharmony_ci * based on v850 version which was 762306a36Sopenharmony_ci * Copyright (C) 2001,02,03 NEC Electronics Corporation 862306a36Sopenharmony_ci * Copyright (C) 2001,02,03 Miles Bader <miles@gnu.org> 962306a36Sopenharmony_ci */ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#ifndef _ASM_MICROBLAZE_CACHEFLUSH_H 1262306a36Sopenharmony_ci#define _ASM_MICROBLAZE_CACHEFLUSH_H 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci/* Somebody depends on this; sigh... */ 1562306a36Sopenharmony_ci#include <linux/mm.h> 1662306a36Sopenharmony_ci#include <linux/io.h> 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci/* Look at Documentation/core-api/cachetlb.rst */ 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci/* 2162306a36Sopenharmony_ci * Cache handling functions. 2262306a36Sopenharmony_ci * Microblaze has a write-through data cache, meaning that the data cache 2362306a36Sopenharmony_ci * never needs to be flushed. The only flushing operations that are 2462306a36Sopenharmony_ci * implemented are to invalidate the instruction cache. These are called 2562306a36Sopenharmony_ci * after loading a user application into memory, we must invalidate the 2662306a36Sopenharmony_ci * instruction cache to make sure we don't fetch old, bad code. 2762306a36Sopenharmony_ci */ 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci/* struct cache, d=dcache, i=icache, fl = flush, iv = invalidate, 3062306a36Sopenharmony_ci * suffix r = range */ 3162306a36Sopenharmony_cistruct scache { 3262306a36Sopenharmony_ci /* icache */ 3362306a36Sopenharmony_ci void (*ie)(void); /* enable */ 3462306a36Sopenharmony_ci void (*id)(void); /* disable */ 3562306a36Sopenharmony_ci void (*ifl)(void); /* flush */ 3662306a36Sopenharmony_ci void (*iflr)(unsigned long a, unsigned long b); 3762306a36Sopenharmony_ci void (*iin)(void); /* invalidate */ 3862306a36Sopenharmony_ci void (*iinr)(unsigned long a, unsigned long b); 3962306a36Sopenharmony_ci /* dcache */ 4062306a36Sopenharmony_ci void (*de)(void); /* enable */ 4162306a36Sopenharmony_ci void (*dd)(void); /* disable */ 4262306a36Sopenharmony_ci void (*dfl)(void); /* flush */ 4362306a36Sopenharmony_ci void (*dflr)(unsigned long a, unsigned long b); 4462306a36Sopenharmony_ci void (*din)(void); /* invalidate */ 4562306a36Sopenharmony_ci void (*dinr)(unsigned long a, unsigned long b); 4662306a36Sopenharmony_ci}; 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci/* microblaze cache */ 4962306a36Sopenharmony_ciextern struct scache *mbc; 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_civoid microblaze_cache_init(void); 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci#define enable_icache() mbc->ie(); 5462306a36Sopenharmony_ci#define disable_icache() mbc->id(); 5562306a36Sopenharmony_ci#define flush_icache() mbc->ifl(); 5662306a36Sopenharmony_ci#define flush_icache_range(start, end) mbc->iflr(start, end); 5762306a36Sopenharmony_ci#define invalidate_icache() mbc->iin(); 5862306a36Sopenharmony_ci#define invalidate_icache_range(start, end) mbc->iinr(start, end); 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci#define enable_dcache() mbc->de(); 6162306a36Sopenharmony_ci#define disable_dcache() mbc->dd(); 6262306a36Sopenharmony_ci/* FIXME for LL-temac driver */ 6362306a36Sopenharmony_ci#define invalidate_dcache() mbc->din(); 6462306a36Sopenharmony_ci#define invalidate_dcache_range(start, end) mbc->dinr(start, end); 6562306a36Sopenharmony_ci#define flush_dcache() mbc->dfl(); 6662306a36Sopenharmony_ci#define flush_dcache_range(start, end) mbc->dflr(start, end); 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 6962306a36Sopenharmony_ci/* MS: We have to implement it because of rootfs-jffs2 issue on WB */ 7062306a36Sopenharmony_ci#define flush_dcache_page(page) \ 7162306a36Sopenharmony_cido { \ 7262306a36Sopenharmony_ci unsigned long addr = (unsigned long) page_address(page); /* virtual */ \ 7362306a36Sopenharmony_ci addr = (u32)virt_to_phys((void *)addr); \ 7462306a36Sopenharmony_ci flush_dcache_range((unsigned) (addr), (unsigned) (addr) + PAGE_SIZE); \ 7562306a36Sopenharmony_ci} while (0); 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_cistatic inline void flush_dcache_folio(struct folio *folio) 7862306a36Sopenharmony_ci{ 7962306a36Sopenharmony_ci unsigned long addr = folio_pfn(folio) << PAGE_SHIFT; 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci flush_dcache_range(addr, addr + folio_size(folio)); 8262306a36Sopenharmony_ci} 8362306a36Sopenharmony_ci#define flush_dcache_folio flush_dcache_folio 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci#define flush_cache_page(vma, vmaddr, pfn) \ 8662306a36Sopenharmony_ci flush_dcache_range(pfn << PAGE_SHIFT, (pfn << PAGE_SHIFT) + PAGE_SIZE); 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_cistatic inline void copy_to_user_page(struct vm_area_struct *vma, 8962306a36Sopenharmony_ci struct page *page, unsigned long vaddr, 9062306a36Sopenharmony_ci void *dst, void *src, int len) 9162306a36Sopenharmony_ci{ 9262306a36Sopenharmony_ci u32 addr = virt_to_phys(dst); 9362306a36Sopenharmony_ci memcpy(dst, src, len); 9462306a36Sopenharmony_ci if (vma->vm_flags & VM_EXEC) { 9562306a36Sopenharmony_ci invalidate_icache_range(addr, addr + PAGE_SIZE); 9662306a36Sopenharmony_ci flush_dcache_range(addr, addr + PAGE_SIZE); 9762306a36Sopenharmony_ci } 9862306a36Sopenharmony_ci} 9962306a36Sopenharmony_ci#define copy_to_user_page copy_to_user_page 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci#include <asm-generic/cacheflush.h> 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci#endif /* _ASM_MICROBLAZE_CACHEFLUSH_H */ 104