162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * OpenRISC Linux 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Linux architectural port borrowing liberally from similar works of 662306a36Sopenharmony_ci * others. All original copyrights apply as per the original source 762306a36Sopenharmony_ci * declaration. 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * OpenRISC implementation: 1062306a36Sopenharmony_ci * Copyright (C) Jan Henrik Weinstock <jan.weinstock@rwth-aachen.de> 1162306a36Sopenharmony_ci * et al. 1262306a36Sopenharmony_ci */ 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#ifndef __ASM_CACHEFLUSH_H 1562306a36Sopenharmony_ci#define __ASM_CACHEFLUSH_H 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#include <linux/mm.h> 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci/* 2062306a36Sopenharmony_ci * Helper function for flushing or invalidating entire pages from data 2162306a36Sopenharmony_ci * and instruction caches. SMP needs a little extra work, since we need 2262306a36Sopenharmony_ci * to flush the pages on all cpus. 2362306a36Sopenharmony_ci */ 2462306a36Sopenharmony_ciextern void local_dcache_page_flush(struct page *page); 2562306a36Sopenharmony_ciextern void local_icache_page_inv(struct page *page); 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci/* 2862306a36Sopenharmony_ci * Data cache flushing always happen on the local cpu. Instruction cache 2962306a36Sopenharmony_ci * invalidations need to be broadcasted to all other cpu in the system in 3062306a36Sopenharmony_ci * case of SMP configurations. 3162306a36Sopenharmony_ci */ 3262306a36Sopenharmony_ci#ifndef CONFIG_SMP 3362306a36Sopenharmony_ci#define dcache_page_flush(page) local_dcache_page_flush(page) 3462306a36Sopenharmony_ci#define icache_page_inv(page) local_icache_page_inv(page) 3562306a36Sopenharmony_ci#else /* CONFIG_SMP */ 3662306a36Sopenharmony_ci#define dcache_page_flush(page) local_dcache_page_flush(page) 3762306a36Sopenharmony_ci#define icache_page_inv(page) smp_icache_page_inv(page) 3862306a36Sopenharmony_ciextern void smp_icache_page_inv(struct page *page); 3962306a36Sopenharmony_ci#endif /* CONFIG_SMP */ 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci/* 4262306a36Sopenharmony_ci * Synchronizes caches. Whenever a cpu writes executable code to memory, this 4362306a36Sopenharmony_ci * should be called to make sure the processor sees the newly written code. 4462306a36Sopenharmony_ci */ 4562306a36Sopenharmony_cistatic inline void sync_icache_dcache(struct page *page) 4662306a36Sopenharmony_ci{ 4762306a36Sopenharmony_ci if (!IS_ENABLED(CONFIG_DCACHE_WRITETHROUGH)) 4862306a36Sopenharmony_ci dcache_page_flush(page); 4962306a36Sopenharmony_ci icache_page_inv(page); 5062306a36Sopenharmony_ci} 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci/* 5362306a36Sopenharmony_ci * Pages with this bit set need not be flushed/invalidated, since 5462306a36Sopenharmony_ci * they have not changed since last flush. New pages start with 5562306a36Sopenharmony_ci * PG_arch_1 not set and are therefore dirty by default. 5662306a36Sopenharmony_ci */ 5762306a36Sopenharmony_ci#define PG_dc_clean PG_arch_1 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_cistatic inline void flush_dcache_folio(struct folio *folio) 6062306a36Sopenharmony_ci{ 6162306a36Sopenharmony_ci clear_bit(PG_dc_clean, &folio->flags); 6262306a36Sopenharmony_ci} 6362306a36Sopenharmony_ci#define flush_dcache_folio flush_dcache_folio 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 6662306a36Sopenharmony_cistatic inline void flush_dcache_page(struct page *page) 6762306a36Sopenharmony_ci{ 6862306a36Sopenharmony_ci flush_dcache_folio(page_folio(page)); 6962306a36Sopenharmony_ci} 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci#define flush_icache_user_page(vma, page, addr, len) \ 7262306a36Sopenharmony_cido { \ 7362306a36Sopenharmony_ci if (vma->vm_flags & VM_EXEC) \ 7462306a36Sopenharmony_ci sync_icache_dcache(page); \ 7562306a36Sopenharmony_ci} while (0) 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci#include <asm-generic/cacheflush.h> 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci#endif /* __ASM_CACHEFLUSH_H */ 80