xref: /OK3568_Linux_fs/kernel/arch/mips/include/asm/octeon/cvmx-asm.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /***********************license start***************
2*4882a593Smuzhiyun  * Author: Cavium Networks
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Contact: support@caviumnetworks.com
5*4882a593Smuzhiyun  * This file is part of the OCTEON SDK
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Copyright (c) 2003-2008 Cavium Networks
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * This file is free software; you can redistribute it and/or modify
10*4882a593Smuzhiyun  * it under the terms of the GNU General Public License, Version 2, as
11*4882a593Smuzhiyun  * published by the Free Software Foundation.
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * This file is distributed in the hope that it will be useful, but
14*4882a593Smuzhiyun  * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15*4882a593Smuzhiyun  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16*4882a593Smuzhiyun  * NONINFRINGEMENT.  See the GNU General Public License for more
17*4882a593Smuzhiyun  * details.
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  * You should have received a copy of the GNU General Public License
20*4882a593Smuzhiyun  * along with this file; if not, write to the Free Software
21*4882a593Smuzhiyun  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22*4882a593Smuzhiyun  * or visit http://www.gnu.org/licenses/.
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  * This file may also be available under a different license from Cavium.
25*4882a593Smuzhiyun  * Contact Cavium Networks for more information
26*4882a593Smuzhiyun  ***********************license end**************************************/
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun /*
29*4882a593Smuzhiyun  *
30*4882a593Smuzhiyun  * This is file defines ASM primitives for the executive.
31*4882a593Smuzhiyun  */
32*4882a593Smuzhiyun #ifndef __CVMX_ASM_H__
33*4882a593Smuzhiyun #define __CVMX_ASM_H__
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun #include <asm/octeon/octeon-model.h>
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun /* other useful stuff */
38*4882a593Smuzhiyun #define CVMX_SYNC asm volatile ("sync" : : : "memory")
39*4882a593Smuzhiyun /* String version of SYNCW macro for using in inline asm constructs */
40*4882a593Smuzhiyun #define CVMX_SYNCW_STR "syncw\nsyncw\n"
41*4882a593Smuzhiyun #ifdef __OCTEON__
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun /* Deprecated, will be removed in future release */
44*4882a593Smuzhiyun #define CVMX_SYNCIO asm volatile ("nop")
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun #define CVMX_SYNCIOBDMA asm volatile ("synciobdma" : : : "memory")
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun /* Deprecated, will be removed in future release */
49*4882a593Smuzhiyun #define CVMX_SYNCIOALL asm volatile ("nop")
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun /*
52*4882a593Smuzhiyun  * We actually use two syncw instructions in a row when we need a write
53*4882a593Smuzhiyun  * memory barrier. This is because the CN3XXX series of Octeons have
54*4882a593Smuzhiyun  * errata Core-401. This can cause a single syncw to not enforce
55*4882a593Smuzhiyun  * ordering under very rare conditions. Even if it is rare, better safe
56*4882a593Smuzhiyun  * than sorry.
57*4882a593Smuzhiyun  */
58*4882a593Smuzhiyun #define CVMX_SYNCW asm volatile ("syncw\n\tsyncw" : : : "memory")
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun /*
61*4882a593Smuzhiyun  * Define new sync instructions to be normal SYNC instructions for
62*4882a593Smuzhiyun  * operating systems that use threads.
63*4882a593Smuzhiyun  */
64*4882a593Smuzhiyun #define CVMX_SYNCWS CVMX_SYNCW
65*4882a593Smuzhiyun #define CVMX_SYNCS  CVMX_SYNC
66*4882a593Smuzhiyun #define CVMX_SYNCWS_STR CVMX_SYNCW_STR
67*4882a593Smuzhiyun #else
68*4882a593Smuzhiyun /*
69*4882a593Smuzhiyun  * Not using a Cavium compiler, always use the slower sync so the
70*4882a593Smuzhiyun  * assembler stays happy.
71*4882a593Smuzhiyun  */
72*4882a593Smuzhiyun /* Deprecated, will be removed in future release */
73*4882a593Smuzhiyun #define CVMX_SYNCIO asm volatile ("nop")
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun #define CVMX_SYNCIOBDMA asm volatile ("sync" : : : "memory")
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun /* Deprecated, will be removed in future release */
78*4882a593Smuzhiyun #define CVMX_SYNCIOALL asm volatile ("nop")
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun #define CVMX_SYNCW asm volatile ("sync" : : : "memory")
81*4882a593Smuzhiyun #define CVMX_SYNCWS CVMX_SYNCW
82*4882a593Smuzhiyun #define CVMX_SYNCS  CVMX_SYNC
83*4882a593Smuzhiyun #define CVMX_SYNCWS_STR CVMX_SYNCW_STR
84*4882a593Smuzhiyun #endif
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun /*
87*4882a593Smuzhiyun  * CVMX_PREPARE_FOR_STORE makes each byte of the block unpredictable
88*4882a593Smuzhiyun  * (actually old value or zero) until that byte is stored to (by this or
89*4882a593Smuzhiyun  * another processor. Note that the value of each byte is not only
90*4882a593Smuzhiyun  * unpredictable, but may also change again - up until the point when one
91*4882a593Smuzhiyun  * of the cores stores to the byte.
92*4882a593Smuzhiyun  */
93*4882a593Smuzhiyun #define CVMX_PREPARE_FOR_STORE(address, offset) \
94*4882a593Smuzhiyun 	asm volatile ("pref 30, " CVMX_TMP_STR(offset) "(%[rbase])" : : \
95*4882a593Smuzhiyun 	[rbase] "d" (address))
96*4882a593Smuzhiyun /*
97*4882a593Smuzhiyun  * This is a command headed to the L2 controller to tell it to clear
98*4882a593Smuzhiyun  * its dirty bit for a block. Basically, SW is telling HW that the
99*4882a593Smuzhiyun  * current version of the block will not be used.
100*4882a593Smuzhiyun  */
101*4882a593Smuzhiyun #define CVMX_DONT_WRITE_BACK(address, offset) \
102*4882a593Smuzhiyun 	asm volatile ("pref 29, " CVMX_TMP_STR(offset) "(%[rbase])" : : \
103*4882a593Smuzhiyun 	[rbase] "d" (address))
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun /* flush stores, invalidate entire icache */
106*4882a593Smuzhiyun #define CVMX_ICACHE_INVALIDATE \
107*4882a593Smuzhiyun 	{ CVMX_SYNC; asm volatile ("synci 0($0)" : : ); }
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun /* flush stores, invalidate entire icache */
110*4882a593Smuzhiyun #define CVMX_ICACHE_INVALIDATE2 \
111*4882a593Smuzhiyun 	{ CVMX_SYNC; asm volatile ("cache 0, 0($0)" : : ); }
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun /* complete prefetches, invalidate entire dcache */
114*4882a593Smuzhiyun #define CVMX_DCACHE_INVALIDATE \
115*4882a593Smuzhiyun 	{ CVMX_SYNC; asm volatile ("cache 9, 0($0)" : : ); }
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun #define CVMX_CACHE(op, address, offset)					\
118*4882a593Smuzhiyun 	asm volatile ("cache " CVMX_TMP_STR(op) ", " CVMX_TMP_STR(offset) "(%[rbase])" \
119*4882a593Smuzhiyun 		: : [rbase] "d" (address) )
120*4882a593Smuzhiyun /* fetch and lock the state. */
121*4882a593Smuzhiyun #define CVMX_CACHE_LCKL2(address, offset) CVMX_CACHE(31, address, offset)
122*4882a593Smuzhiyun /* unlock the state. */
123*4882a593Smuzhiyun #define CVMX_CACHE_WBIL2(address, offset) CVMX_CACHE(23, address, offset)
124*4882a593Smuzhiyun /* invalidate the cache block and clear the USED bits for the block */
125*4882a593Smuzhiyun #define CVMX_CACHE_WBIL2I(address, offset) CVMX_CACHE(3, address, offset)
126*4882a593Smuzhiyun /* load virtual tag and data for the L2 cache block into L2C_TAD0_TAG register */
127*4882a593Smuzhiyun #define CVMX_CACHE_LTGL2I(address, offset) CVMX_CACHE(7, address, offset)
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun #define CVMX_POP(result, input) \
130*4882a593Smuzhiyun 	asm ("pop %[rd],%[rs]" : [rd] "=d" (result) : [rs] "d" (input))
131*4882a593Smuzhiyun #define CVMX_DPOP(result, input) \
132*4882a593Smuzhiyun 	asm ("dpop %[rd],%[rs]" : [rd] "=d" (result) : [rs] "d" (input))
133*4882a593Smuzhiyun 
134*4882a593Smuzhiyun /* some new cop0-like stuff */
135*4882a593Smuzhiyun #define CVMX_RDHWR(result, regstr) \
136*4882a593Smuzhiyun 	asm volatile ("rdhwr %[rt],$" CVMX_TMP_STR(regstr) : [rt] "=d" (result))
137*4882a593Smuzhiyun #define CVMX_RDHWRNV(result, regstr) \
138*4882a593Smuzhiyun 	asm ("rdhwr %[rt],$" CVMX_TMP_STR(regstr) : [rt] "=d" (result))
139*4882a593Smuzhiyun #endif /* __CVMX_ASM_H__ */
140