xref: /OK3568_Linux_fs/kernel/arch/mips/include/asm/octeon/cvmx-scratch.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 file provides support for the processor local scratch memory.
31*4882a593Smuzhiyun  * Scratch memory is byte addressable - all addresses are byte addresses.
32*4882a593Smuzhiyun  *
33*4882a593Smuzhiyun  */
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun #ifndef __CVMX_SCRATCH_H__
36*4882a593Smuzhiyun #define __CVMX_SCRATCH_H__
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun /*
39*4882a593Smuzhiyun  * Note: This define must be a long, not a long long in order to
40*4882a593Smuzhiyun  * compile without warnings for both 32bit and 64bit.
41*4882a593Smuzhiyun  */
42*4882a593Smuzhiyun #define CVMX_SCRATCH_BASE	(-32768l)	/* 0xffffffffffff8000 */
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun /**
45*4882a593Smuzhiyun  * Reads an 8 bit value from the processor local scratchpad memory.
46*4882a593Smuzhiyun  *
47*4882a593Smuzhiyun  * @address: byte address to read from
48*4882a593Smuzhiyun  *
49*4882a593Smuzhiyun  * Returns value read
50*4882a593Smuzhiyun  */
cvmx_scratch_read8(uint64_t address)51*4882a593Smuzhiyun static inline uint8_t cvmx_scratch_read8(uint64_t address)
52*4882a593Smuzhiyun {
53*4882a593Smuzhiyun 	return *CASTPTR(volatile uint8_t, CVMX_SCRATCH_BASE + address);
54*4882a593Smuzhiyun }
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun /**
57*4882a593Smuzhiyun  * Reads a 16 bit value from the processor local scratchpad memory.
58*4882a593Smuzhiyun  *
59*4882a593Smuzhiyun  * @address: byte address to read from
60*4882a593Smuzhiyun  *
61*4882a593Smuzhiyun  * Returns value read
62*4882a593Smuzhiyun  */
cvmx_scratch_read16(uint64_t address)63*4882a593Smuzhiyun static inline uint16_t cvmx_scratch_read16(uint64_t address)
64*4882a593Smuzhiyun {
65*4882a593Smuzhiyun 	return *CASTPTR(volatile uint16_t, CVMX_SCRATCH_BASE + address);
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun /**
69*4882a593Smuzhiyun  * Reads a 32 bit value from the processor local scratchpad memory.
70*4882a593Smuzhiyun  *
71*4882a593Smuzhiyun  * @address: byte address to read from
72*4882a593Smuzhiyun  *
73*4882a593Smuzhiyun  * Returns value read
74*4882a593Smuzhiyun  */
cvmx_scratch_read32(uint64_t address)75*4882a593Smuzhiyun static inline uint32_t cvmx_scratch_read32(uint64_t address)
76*4882a593Smuzhiyun {
77*4882a593Smuzhiyun 	return *CASTPTR(volatile uint32_t, CVMX_SCRATCH_BASE + address);
78*4882a593Smuzhiyun }
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun /**
81*4882a593Smuzhiyun  * Reads a 64 bit value from the processor local scratchpad memory.
82*4882a593Smuzhiyun  *
83*4882a593Smuzhiyun  * @address: byte address to read from
84*4882a593Smuzhiyun  *
85*4882a593Smuzhiyun  * Returns value read
86*4882a593Smuzhiyun  */
cvmx_scratch_read64(uint64_t address)87*4882a593Smuzhiyun static inline uint64_t cvmx_scratch_read64(uint64_t address)
88*4882a593Smuzhiyun {
89*4882a593Smuzhiyun 	return *CASTPTR(volatile uint64_t, CVMX_SCRATCH_BASE + address);
90*4882a593Smuzhiyun }
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun /**
93*4882a593Smuzhiyun  * Writes an 8 bit value to the processor local scratchpad memory.
94*4882a593Smuzhiyun  *
95*4882a593Smuzhiyun  * @address: byte address to write to
96*4882a593Smuzhiyun  * @value:   value to write
97*4882a593Smuzhiyun  */
cvmx_scratch_write8(uint64_t address,uint64_t value)98*4882a593Smuzhiyun static inline void cvmx_scratch_write8(uint64_t address, uint64_t value)
99*4882a593Smuzhiyun {
100*4882a593Smuzhiyun 	*CASTPTR(volatile uint8_t, CVMX_SCRATCH_BASE + address) =
101*4882a593Smuzhiyun 	    (uint8_t) value;
102*4882a593Smuzhiyun }
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun /**
105*4882a593Smuzhiyun  * Writes a 32 bit value to the processor local scratchpad memory.
106*4882a593Smuzhiyun  *
107*4882a593Smuzhiyun  * @address: byte address to write to
108*4882a593Smuzhiyun  * @value:   value to write
109*4882a593Smuzhiyun  */
cvmx_scratch_write16(uint64_t address,uint64_t value)110*4882a593Smuzhiyun static inline void cvmx_scratch_write16(uint64_t address, uint64_t value)
111*4882a593Smuzhiyun {
112*4882a593Smuzhiyun 	*CASTPTR(volatile uint16_t, CVMX_SCRATCH_BASE + address) =
113*4882a593Smuzhiyun 	    (uint16_t) value;
114*4882a593Smuzhiyun }
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun /**
117*4882a593Smuzhiyun  * Writes a 16 bit value to the processor local scratchpad memory.
118*4882a593Smuzhiyun  *
119*4882a593Smuzhiyun  * @address: byte address to write to
120*4882a593Smuzhiyun  * @value:   value to write
121*4882a593Smuzhiyun  */
cvmx_scratch_write32(uint64_t address,uint64_t value)122*4882a593Smuzhiyun static inline void cvmx_scratch_write32(uint64_t address, uint64_t value)
123*4882a593Smuzhiyun {
124*4882a593Smuzhiyun 	*CASTPTR(volatile uint32_t, CVMX_SCRATCH_BASE + address) =
125*4882a593Smuzhiyun 	    (uint32_t) value;
126*4882a593Smuzhiyun }
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun /**
129*4882a593Smuzhiyun  * Writes a 64 bit value to the processor local scratchpad memory.
130*4882a593Smuzhiyun  *
131*4882a593Smuzhiyun  * @address: byte address to write to
132*4882a593Smuzhiyun  * @value:   value to write
133*4882a593Smuzhiyun  */
cvmx_scratch_write64(uint64_t address,uint64_t value)134*4882a593Smuzhiyun static inline void cvmx_scratch_write64(uint64_t address, uint64_t value)
135*4882a593Smuzhiyun {
136*4882a593Smuzhiyun 	*CASTPTR(volatile uint64_t, CVMX_SCRATCH_BASE + address) = value;
137*4882a593Smuzhiyun }
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun #endif /* __CVMX_SCRATCH_H__ */
140