18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * arch/arm/include/asm/outercache.h 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2010 ARM Ltd. 68c2ecf20Sopenharmony_ci * Written by Catalin Marinas <catalin.marinas@arm.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifndef __ASM_OUTERCACHE_H 108c2ecf20Sopenharmony_ci#define __ASM_OUTERCACHE_H 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/types.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_cistruct l2x0_regs; 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_cistruct outer_cache_fns { 178c2ecf20Sopenharmony_ci void (*inv_range)(unsigned long, unsigned long); 188c2ecf20Sopenharmony_ci void (*clean_range)(unsigned long, unsigned long); 198c2ecf20Sopenharmony_ci void (*flush_range)(unsigned long, unsigned long); 208c2ecf20Sopenharmony_ci void (*flush_all)(void); 218c2ecf20Sopenharmony_ci void (*disable)(void); 228c2ecf20Sopenharmony_ci#ifdef CONFIG_OUTER_CACHE_SYNC 238c2ecf20Sopenharmony_ci void (*sync)(void); 248c2ecf20Sopenharmony_ci#endif 258c2ecf20Sopenharmony_ci void (*resume)(void); 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci /* This is an ARM L2C thing */ 288c2ecf20Sopenharmony_ci void (*write_sec)(unsigned long, unsigned); 298c2ecf20Sopenharmony_ci void (*configure)(const struct l2x0_regs *); 308c2ecf20Sopenharmony_ci}; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ciextern struct outer_cache_fns outer_cache; 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#ifdef CONFIG_OUTER_CACHE 358c2ecf20Sopenharmony_ci/** 368c2ecf20Sopenharmony_ci * outer_inv_range - invalidate range of outer cache lines 378c2ecf20Sopenharmony_ci * @start: starting physical address, inclusive 388c2ecf20Sopenharmony_ci * @end: end physical address, exclusive 398c2ecf20Sopenharmony_ci */ 408c2ecf20Sopenharmony_cistatic inline void outer_inv_range(phys_addr_t start, phys_addr_t end) 418c2ecf20Sopenharmony_ci{ 428c2ecf20Sopenharmony_ci if (outer_cache.inv_range) 438c2ecf20Sopenharmony_ci outer_cache.inv_range(start, end); 448c2ecf20Sopenharmony_ci} 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci/** 478c2ecf20Sopenharmony_ci * outer_clean_range - clean dirty outer cache lines 488c2ecf20Sopenharmony_ci * @start: starting physical address, inclusive 498c2ecf20Sopenharmony_ci * @end: end physical address, exclusive 508c2ecf20Sopenharmony_ci */ 518c2ecf20Sopenharmony_cistatic inline void outer_clean_range(phys_addr_t start, phys_addr_t end) 528c2ecf20Sopenharmony_ci{ 538c2ecf20Sopenharmony_ci if (outer_cache.clean_range) 548c2ecf20Sopenharmony_ci outer_cache.clean_range(start, end); 558c2ecf20Sopenharmony_ci} 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci/** 588c2ecf20Sopenharmony_ci * outer_flush_range - clean and invalidate outer cache lines 598c2ecf20Sopenharmony_ci * @start: starting physical address, inclusive 608c2ecf20Sopenharmony_ci * @end: end physical address, exclusive 618c2ecf20Sopenharmony_ci */ 628c2ecf20Sopenharmony_cistatic inline void outer_flush_range(phys_addr_t start, phys_addr_t end) 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci if (outer_cache.flush_range) 658c2ecf20Sopenharmony_ci outer_cache.flush_range(start, end); 668c2ecf20Sopenharmony_ci} 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci/** 698c2ecf20Sopenharmony_ci * outer_flush_all - clean and invalidate all cache lines in the outer cache 708c2ecf20Sopenharmony_ci * 718c2ecf20Sopenharmony_ci * Note: depending on implementation, this may not be atomic - it must 728c2ecf20Sopenharmony_ci * only be called with interrupts disabled and no other active outer 738c2ecf20Sopenharmony_ci * cache masters. 748c2ecf20Sopenharmony_ci * 758c2ecf20Sopenharmony_ci * It is intended that this function is only used by implementations 768c2ecf20Sopenharmony_ci * needing to override the outer_cache.disable() method due to security. 778c2ecf20Sopenharmony_ci * (Some implementations perform this as a clean followed by an invalidate.) 788c2ecf20Sopenharmony_ci */ 798c2ecf20Sopenharmony_cistatic inline void outer_flush_all(void) 808c2ecf20Sopenharmony_ci{ 818c2ecf20Sopenharmony_ci if (outer_cache.flush_all) 828c2ecf20Sopenharmony_ci outer_cache.flush_all(); 838c2ecf20Sopenharmony_ci} 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci/** 868c2ecf20Sopenharmony_ci * outer_disable - clean, invalidate and disable the outer cache 878c2ecf20Sopenharmony_ci * 888c2ecf20Sopenharmony_ci * Disable the outer cache, ensuring that any data contained in the outer 898c2ecf20Sopenharmony_ci * cache is pushed out to lower levels of system memory. The note and 908c2ecf20Sopenharmony_ci * conditions above concerning outer_flush_all() applies here. 918c2ecf20Sopenharmony_ci */ 928c2ecf20Sopenharmony_ciextern void outer_disable(void); 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci/** 958c2ecf20Sopenharmony_ci * outer_resume - restore the cache configuration and re-enable outer cache 968c2ecf20Sopenharmony_ci * 978c2ecf20Sopenharmony_ci * Restore any configuration that the cache had when previously enabled, 988c2ecf20Sopenharmony_ci * and re-enable the outer cache. 998c2ecf20Sopenharmony_ci */ 1008c2ecf20Sopenharmony_cistatic inline void outer_resume(void) 1018c2ecf20Sopenharmony_ci{ 1028c2ecf20Sopenharmony_ci if (outer_cache.resume) 1038c2ecf20Sopenharmony_ci outer_cache.resume(); 1048c2ecf20Sopenharmony_ci} 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci#else 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistatic inline void outer_inv_range(phys_addr_t start, phys_addr_t end) 1098c2ecf20Sopenharmony_ci{ } 1108c2ecf20Sopenharmony_cistatic inline void outer_clean_range(phys_addr_t start, phys_addr_t end) 1118c2ecf20Sopenharmony_ci{ } 1128c2ecf20Sopenharmony_cistatic inline void outer_flush_range(phys_addr_t start, phys_addr_t end) 1138c2ecf20Sopenharmony_ci{ } 1148c2ecf20Sopenharmony_cistatic inline void outer_flush_all(void) { } 1158c2ecf20Sopenharmony_cistatic inline void outer_disable(void) { } 1168c2ecf20Sopenharmony_cistatic inline void outer_resume(void) { } 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci#endif 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci#endif /* __ASM_OUTERCACHE_H */ 121