18c2ecf20Sopenharmony_ci/***********************license start*************** 28c2ecf20Sopenharmony_ci * Author: Cavium Networks 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Contact: support@caviumnetworks.com 58c2ecf20Sopenharmony_ci * This file is part of the OCTEON SDK 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (c) 2003-2008 Cavium Networks 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * This file is free software; you can redistribute it and/or modify 108c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License, Version 2, as 118c2ecf20Sopenharmony_ci * published by the Free Software Foundation. 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * This file is distributed in the hope that it will be useful, but 148c2ecf20Sopenharmony_ci * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty 158c2ecf20Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or 168c2ecf20Sopenharmony_ci * NONINFRINGEMENT. See the GNU General Public License for more 178c2ecf20Sopenharmony_ci * details. 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License 208c2ecf20Sopenharmony_ci * along with this file; if not, write to the Free Software 218c2ecf20Sopenharmony_ci * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 228c2ecf20Sopenharmony_ci * or visit http://www.gnu.org/licenses/. 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci * This file may also be available under a different license from Cavium. 258c2ecf20Sopenharmony_ci * Contact Cavium Networks for more information 268c2ecf20Sopenharmony_ci ***********************license end**************************************/ 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/* 298c2ecf20Sopenharmony_ci * 308c2ecf20Sopenharmony_ci * This is file defines ASM primitives for the executive. 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_ci#ifndef __CVMX_ASM_H__ 338c2ecf20Sopenharmony_ci#define __CVMX_ASM_H__ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#include <asm/octeon/octeon-model.h> 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci/* other useful stuff */ 388c2ecf20Sopenharmony_ci#define CVMX_SYNC asm volatile ("sync" : : : "memory") 398c2ecf20Sopenharmony_ci/* String version of SYNCW macro for using in inline asm constructs */ 408c2ecf20Sopenharmony_ci#define CVMX_SYNCW_STR "syncw\nsyncw\n" 418c2ecf20Sopenharmony_ci#ifdef __OCTEON__ 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/* Deprecated, will be removed in future release */ 448c2ecf20Sopenharmony_ci#define CVMX_SYNCIO asm volatile ("nop") 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#define CVMX_SYNCIOBDMA asm volatile ("synciobdma" : : : "memory") 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci/* Deprecated, will be removed in future release */ 498c2ecf20Sopenharmony_ci#define CVMX_SYNCIOALL asm volatile ("nop") 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci/* 528c2ecf20Sopenharmony_ci * We actually use two syncw instructions in a row when we need a write 538c2ecf20Sopenharmony_ci * memory barrier. This is because the CN3XXX series of Octeons have 548c2ecf20Sopenharmony_ci * errata Core-401. This can cause a single syncw to not enforce 558c2ecf20Sopenharmony_ci * ordering under very rare conditions. Even if it is rare, better safe 568c2ecf20Sopenharmony_ci * than sorry. 578c2ecf20Sopenharmony_ci */ 588c2ecf20Sopenharmony_ci#define CVMX_SYNCW asm volatile ("syncw\n\tsyncw" : : : "memory") 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/* 618c2ecf20Sopenharmony_ci * Define new sync instructions to be normal SYNC instructions for 628c2ecf20Sopenharmony_ci * operating systems that use threads. 638c2ecf20Sopenharmony_ci */ 648c2ecf20Sopenharmony_ci#define CVMX_SYNCWS CVMX_SYNCW 658c2ecf20Sopenharmony_ci#define CVMX_SYNCS CVMX_SYNC 668c2ecf20Sopenharmony_ci#define CVMX_SYNCWS_STR CVMX_SYNCW_STR 678c2ecf20Sopenharmony_ci#else 688c2ecf20Sopenharmony_ci/* 698c2ecf20Sopenharmony_ci * Not using a Cavium compiler, always use the slower sync so the 708c2ecf20Sopenharmony_ci * assembler stays happy. 718c2ecf20Sopenharmony_ci */ 728c2ecf20Sopenharmony_ci/* Deprecated, will be removed in future release */ 738c2ecf20Sopenharmony_ci#define CVMX_SYNCIO asm volatile ("nop") 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci#define CVMX_SYNCIOBDMA asm volatile ("sync" : : : "memory") 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci/* Deprecated, will be removed in future release */ 788c2ecf20Sopenharmony_ci#define CVMX_SYNCIOALL asm volatile ("nop") 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci#define CVMX_SYNCW asm volatile ("sync" : : : "memory") 818c2ecf20Sopenharmony_ci#define CVMX_SYNCWS CVMX_SYNCW 828c2ecf20Sopenharmony_ci#define CVMX_SYNCS CVMX_SYNC 838c2ecf20Sopenharmony_ci#define CVMX_SYNCWS_STR CVMX_SYNCW_STR 848c2ecf20Sopenharmony_ci#endif 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci/* 878c2ecf20Sopenharmony_ci * CVMX_PREPARE_FOR_STORE makes each byte of the block unpredictable 888c2ecf20Sopenharmony_ci * (actually old value or zero) until that byte is stored to (by this or 898c2ecf20Sopenharmony_ci * another processor. Note that the value of each byte is not only 908c2ecf20Sopenharmony_ci * unpredictable, but may also change again - up until the point when one 918c2ecf20Sopenharmony_ci * of the cores stores to the byte. 928c2ecf20Sopenharmony_ci */ 938c2ecf20Sopenharmony_ci#define CVMX_PREPARE_FOR_STORE(address, offset) \ 948c2ecf20Sopenharmony_ci asm volatile ("pref 30, " CVMX_TMP_STR(offset) "(%[rbase])" : : \ 958c2ecf20Sopenharmony_ci [rbase] "d" (address)) 968c2ecf20Sopenharmony_ci/* 978c2ecf20Sopenharmony_ci * This is a command headed to the L2 controller to tell it to clear 988c2ecf20Sopenharmony_ci * its dirty bit for a block. Basically, SW is telling HW that the 998c2ecf20Sopenharmony_ci * current version of the block will not be used. 1008c2ecf20Sopenharmony_ci */ 1018c2ecf20Sopenharmony_ci#define CVMX_DONT_WRITE_BACK(address, offset) \ 1028c2ecf20Sopenharmony_ci asm volatile ("pref 29, " CVMX_TMP_STR(offset) "(%[rbase])" : : \ 1038c2ecf20Sopenharmony_ci [rbase] "d" (address)) 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci/* flush stores, invalidate entire icache */ 1068c2ecf20Sopenharmony_ci#define CVMX_ICACHE_INVALIDATE \ 1078c2ecf20Sopenharmony_ci { CVMX_SYNC; asm volatile ("synci 0($0)" : : ); } 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci/* flush stores, invalidate entire icache */ 1108c2ecf20Sopenharmony_ci#define CVMX_ICACHE_INVALIDATE2 \ 1118c2ecf20Sopenharmony_ci { CVMX_SYNC; asm volatile ("cache 0, 0($0)" : : ); } 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci/* complete prefetches, invalidate entire dcache */ 1148c2ecf20Sopenharmony_ci#define CVMX_DCACHE_INVALIDATE \ 1158c2ecf20Sopenharmony_ci { CVMX_SYNC; asm volatile ("cache 9, 0($0)" : : ); } 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci#define CVMX_CACHE(op, address, offset) \ 1188c2ecf20Sopenharmony_ci asm volatile ("cache " CVMX_TMP_STR(op) ", " CVMX_TMP_STR(offset) "(%[rbase])" \ 1198c2ecf20Sopenharmony_ci : : [rbase] "d" (address) ) 1208c2ecf20Sopenharmony_ci/* fetch and lock the state. */ 1218c2ecf20Sopenharmony_ci#define CVMX_CACHE_LCKL2(address, offset) CVMX_CACHE(31, address, offset) 1228c2ecf20Sopenharmony_ci/* unlock the state. */ 1238c2ecf20Sopenharmony_ci#define CVMX_CACHE_WBIL2(address, offset) CVMX_CACHE(23, address, offset) 1248c2ecf20Sopenharmony_ci/* invalidate the cache block and clear the USED bits for the block */ 1258c2ecf20Sopenharmony_ci#define CVMX_CACHE_WBIL2I(address, offset) CVMX_CACHE(3, address, offset) 1268c2ecf20Sopenharmony_ci/* load virtual tag and data for the L2 cache block into L2C_TAD0_TAG register */ 1278c2ecf20Sopenharmony_ci#define CVMX_CACHE_LTGL2I(address, offset) CVMX_CACHE(7, address, offset) 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci#define CVMX_POP(result, input) \ 1308c2ecf20Sopenharmony_ci asm ("pop %[rd],%[rs]" : [rd] "=d" (result) : [rs] "d" (input)) 1318c2ecf20Sopenharmony_ci#define CVMX_DPOP(result, input) \ 1328c2ecf20Sopenharmony_ci asm ("dpop %[rd],%[rs]" : [rd] "=d" (result) : [rs] "d" (input)) 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci/* some new cop0-like stuff */ 1358c2ecf20Sopenharmony_ci#define CVMX_RDHWR(result, regstr) \ 1368c2ecf20Sopenharmony_ci asm volatile ("rdhwr %[rt],$" CVMX_TMP_STR(regstr) : [rt] "=d" (result)) 1378c2ecf20Sopenharmony_ci#define CVMX_RDHWRNV(result, regstr) \ 1388c2ecf20Sopenharmony_ci asm ("rdhwr %[rt],$" CVMX_TMP_STR(regstr) : [rt] "=d" (result)) 1398c2ecf20Sopenharmony_ci#endif /* __CVMX_ASM_H__ */ 140