162306a36Sopenharmony_ci/***********************license start*************** 262306a36Sopenharmony_ci * Author: Cavium Networks 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Contact: support@caviumnetworks.com 562306a36Sopenharmony_ci * This file is part of the OCTEON SDK 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Copyright (c) 2003-2008 Cavium Networks 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * This file is free software; you can redistribute it and/or modify 1062306a36Sopenharmony_ci * it under the terms of the GNU General Public License, Version 2, as 1162306a36Sopenharmony_ci * published by the Free Software Foundation. 1262306a36Sopenharmony_ci * 1362306a36Sopenharmony_ci * This file is distributed in the hope that it will be useful, but 1462306a36Sopenharmony_ci * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty 1562306a36Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or 1662306a36Sopenharmony_ci * NONINFRINGEMENT. See the GNU General Public License for more 1762306a36Sopenharmony_ci * details. 1862306a36Sopenharmony_ci * 1962306a36Sopenharmony_ci * You should have received a copy of the GNU General Public License 2062306a36Sopenharmony_ci * along with this file; if not, write to the Free Software 2162306a36Sopenharmony_ci * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 2262306a36Sopenharmony_ci * or visit http://www.gnu.org/licenses/. 2362306a36Sopenharmony_ci * 2462306a36Sopenharmony_ci * This file may also be available under a different license from Cavium. 2562306a36Sopenharmony_ci * Contact Cavium Networks for more information 2662306a36Sopenharmony_ci ***********************license end**************************************/ 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci/* 2962306a36Sopenharmony_ci * 3062306a36Sopenharmony_ci * This is file defines ASM primitives for the executive. 3162306a36Sopenharmony_ci */ 3262306a36Sopenharmony_ci#ifndef __CVMX_ASM_H__ 3362306a36Sopenharmony_ci#define __CVMX_ASM_H__ 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#include <asm/octeon/octeon-model.h> 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci/* other useful stuff */ 3862306a36Sopenharmony_ci#define CVMX_SYNC asm volatile ("sync" : : : "memory") 3962306a36Sopenharmony_ci/* String version of SYNCW macro for using in inline asm constructs */ 4062306a36Sopenharmony_ci#define CVMX_SYNCW_STR "syncw\nsyncw\n" 4162306a36Sopenharmony_ci#ifdef __OCTEON__ 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci/* Deprecated, will be removed in future release */ 4462306a36Sopenharmony_ci#define CVMX_SYNCIO asm volatile ("nop") 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci#define CVMX_SYNCIOBDMA asm volatile ("synciobdma" : : : "memory") 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci/* Deprecated, will be removed in future release */ 4962306a36Sopenharmony_ci#define CVMX_SYNCIOALL asm volatile ("nop") 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci/* 5262306a36Sopenharmony_ci * We actually use two syncw instructions in a row when we need a write 5362306a36Sopenharmony_ci * memory barrier. This is because the CN3XXX series of Octeons have 5462306a36Sopenharmony_ci * errata Core-401. This can cause a single syncw to not enforce 5562306a36Sopenharmony_ci * ordering under very rare conditions. Even if it is rare, better safe 5662306a36Sopenharmony_ci * than sorry. 5762306a36Sopenharmony_ci */ 5862306a36Sopenharmony_ci#define CVMX_SYNCW asm volatile ("syncw\n\tsyncw" : : : "memory") 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci/* 6162306a36Sopenharmony_ci * Define new sync instructions to be normal SYNC instructions for 6262306a36Sopenharmony_ci * operating systems that use threads. 6362306a36Sopenharmony_ci */ 6462306a36Sopenharmony_ci#define CVMX_SYNCWS CVMX_SYNCW 6562306a36Sopenharmony_ci#define CVMX_SYNCS CVMX_SYNC 6662306a36Sopenharmony_ci#define CVMX_SYNCWS_STR CVMX_SYNCW_STR 6762306a36Sopenharmony_ci#else 6862306a36Sopenharmony_ci/* 6962306a36Sopenharmony_ci * Not using a Cavium compiler, always use the slower sync so the 7062306a36Sopenharmony_ci * assembler stays happy. 7162306a36Sopenharmony_ci */ 7262306a36Sopenharmony_ci/* Deprecated, will be removed in future release */ 7362306a36Sopenharmony_ci#define CVMX_SYNCIO asm volatile ("nop") 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci#define CVMX_SYNCIOBDMA asm volatile ("sync" : : : "memory") 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci/* Deprecated, will be removed in future release */ 7862306a36Sopenharmony_ci#define CVMX_SYNCIOALL asm volatile ("nop") 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci#define CVMX_SYNCW asm volatile ("sync" : : : "memory") 8162306a36Sopenharmony_ci#define CVMX_SYNCWS CVMX_SYNCW 8262306a36Sopenharmony_ci#define CVMX_SYNCS CVMX_SYNC 8362306a36Sopenharmony_ci#define CVMX_SYNCWS_STR CVMX_SYNCW_STR 8462306a36Sopenharmony_ci#endif 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci/* 8762306a36Sopenharmony_ci * CVMX_PREPARE_FOR_STORE makes each byte of the block unpredictable 8862306a36Sopenharmony_ci * (actually old value or zero) until that byte is stored to (by this or 8962306a36Sopenharmony_ci * another processor. Note that the value of each byte is not only 9062306a36Sopenharmony_ci * unpredictable, but may also change again - up until the point when one 9162306a36Sopenharmony_ci * of the cores stores to the byte. 9262306a36Sopenharmony_ci */ 9362306a36Sopenharmony_ci#define CVMX_PREPARE_FOR_STORE(address, offset) \ 9462306a36Sopenharmony_ci asm volatile ("pref 30, " CVMX_TMP_STR(offset) "(%[rbase])" : : \ 9562306a36Sopenharmony_ci [rbase] "d" (address)) 9662306a36Sopenharmony_ci/* 9762306a36Sopenharmony_ci * This is a command headed to the L2 controller to tell it to clear 9862306a36Sopenharmony_ci * its dirty bit for a block. Basically, SW is telling HW that the 9962306a36Sopenharmony_ci * current version of the block will not be used. 10062306a36Sopenharmony_ci */ 10162306a36Sopenharmony_ci#define CVMX_DONT_WRITE_BACK(address, offset) \ 10262306a36Sopenharmony_ci asm volatile ("pref 29, " CVMX_TMP_STR(offset) "(%[rbase])" : : \ 10362306a36Sopenharmony_ci [rbase] "d" (address)) 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci/* flush stores, invalidate entire icache */ 10662306a36Sopenharmony_ci#define CVMX_ICACHE_INVALIDATE \ 10762306a36Sopenharmony_ci { CVMX_SYNC; asm volatile ("synci 0($0)" : : ); } 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci/* flush stores, invalidate entire icache */ 11062306a36Sopenharmony_ci#define CVMX_ICACHE_INVALIDATE2 \ 11162306a36Sopenharmony_ci { CVMX_SYNC; asm volatile ("cache 0, 0($0)" : : ); } 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci/* complete prefetches, invalidate entire dcache */ 11462306a36Sopenharmony_ci#define CVMX_DCACHE_INVALIDATE \ 11562306a36Sopenharmony_ci { CVMX_SYNC; asm volatile ("cache 9, 0($0)" : : ); } 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci#define CVMX_CACHE(op, address, offset) \ 11862306a36Sopenharmony_ci asm volatile ("cache " CVMX_TMP_STR(op) ", " CVMX_TMP_STR(offset) "(%[rbase])" \ 11962306a36Sopenharmony_ci : : [rbase] "d" (address) ) 12062306a36Sopenharmony_ci/* fetch and lock the state. */ 12162306a36Sopenharmony_ci#define CVMX_CACHE_LCKL2(address, offset) CVMX_CACHE(31, address, offset) 12262306a36Sopenharmony_ci/* unlock the state. */ 12362306a36Sopenharmony_ci#define CVMX_CACHE_WBIL2(address, offset) CVMX_CACHE(23, address, offset) 12462306a36Sopenharmony_ci/* invalidate the cache block and clear the USED bits for the block */ 12562306a36Sopenharmony_ci#define CVMX_CACHE_WBIL2I(address, offset) CVMX_CACHE(3, address, offset) 12662306a36Sopenharmony_ci/* load virtual tag and data for the L2 cache block into L2C_TAD0_TAG register */ 12762306a36Sopenharmony_ci#define CVMX_CACHE_LTGL2I(address, offset) CVMX_CACHE(7, address, offset) 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci#define CVMX_POP(result, input) \ 13062306a36Sopenharmony_ci asm ("pop %[rd],%[rs]" : [rd] "=d" (result) : [rs] "d" (input)) 13162306a36Sopenharmony_ci#define CVMX_DPOP(result, input) \ 13262306a36Sopenharmony_ci asm ("dpop %[rd],%[rs]" : [rd] "=d" (result) : [rs] "d" (input)) 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci/* some new cop0-like stuff */ 13562306a36Sopenharmony_ci#define CVMX_RDHWR(result, regstr) \ 13662306a36Sopenharmony_ci asm volatile ("rdhwr %[rt],$" CVMX_TMP_STR(regstr) : [rt] "=d" (result)) 13762306a36Sopenharmony_ci#define CVMX_RDHWRNV(result, regstr) \ 13862306a36Sopenharmony_ci asm ("rdhwr %[rt],$" CVMX_TMP_STR(regstr) : [rt] "=d" (result)) 13962306a36Sopenharmony_ci#endif /* __CVMX_ASM_H__ */ 140