1 /***********************license start***************
2 * Author: Cavium Networks
3 *
4 * Contact: support@caviumnetworks.com
5 * This file is part of the OCTEON SDK
6 *
7 * Copyright (c) 2003-2008 Cavium Networks
8 *
9 * This file is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License, Version 2, as
11 * published by the Free Software Foundation.
12 *
13 * This file is distributed in the hope that it will be useful, but
14 * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16 * NONINFRINGEMENT. See the GNU General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this file; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * or visit http://www.gnu.org/licenses/.
23 *
24 * This file may also be available under a different license from Cavium.
25 * Contact Cavium Networks for more information
26 ***********************license end**************************************/
27
28 /**
29 *
30 * This file provides support for the processor local scratch memory.
31 * Scratch memory is byte addressable - all addresses are byte addresses.
32 *
33 */
34
35 #ifndef __CVMX_SCRATCH_H__
36 #define __CVMX_SCRATCH_H__
37
38 /*
39 * Note: This define must be a long, not a long long in order to
40 * compile without warnings for both 32bit and 64bit.
41 */
42 #define CVMX_SCRATCH_BASE (-32768l) /* 0xffffffffffff8000 */
43
44 /**
45 * Reads an 8 bit value from the processor local scratchpad memory.
46 *
47 * @address: byte address to read from
48 *
49 * Returns value read
50 */
cvmx_scratch_read8(uint64_t address)51 static inline uint8_t cvmx_scratch_read8(uint64_t address)
52 {
53 return *CASTPTR(volatile uint8_t, CVMX_SCRATCH_BASE + address);
54 }
55
56 /**
57 * Reads a 16 bit value from the processor local scratchpad memory.
58 *
59 * @address: byte address to read from
60 *
61 * Returns value read
62 */
cvmx_scratch_read16(uint64_t address)63 static inline uint16_t cvmx_scratch_read16(uint64_t address)
64 {
65 return *CASTPTR(volatile uint16_t, CVMX_SCRATCH_BASE + address);
66 }
67
68 /**
69 * Reads a 32 bit value from the processor local scratchpad memory.
70 *
71 * @address: byte address to read from
72 *
73 * Returns value read
74 */
cvmx_scratch_read32(uint64_t address)75 static inline uint32_t cvmx_scratch_read32(uint64_t address)
76 {
77 return *CASTPTR(volatile uint32_t, CVMX_SCRATCH_BASE + address);
78 }
79
80 /**
81 * Reads a 64 bit value from the processor local scratchpad memory.
82 *
83 * @address: byte address to read from
84 *
85 * Returns value read
86 */
cvmx_scratch_read64(uint64_t address)87 static inline uint64_t cvmx_scratch_read64(uint64_t address)
88 {
89 return *CASTPTR(volatile uint64_t, CVMX_SCRATCH_BASE + address);
90 }
91
92 /**
93 * Writes an 8 bit value to the processor local scratchpad memory.
94 *
95 * @address: byte address to write to
96 * @value: value to write
97 */
cvmx_scratch_write8(uint64_t address,uint64_t value)98 static inline void cvmx_scratch_write8(uint64_t address, uint64_t value)
99 {
100 *CASTPTR(volatile uint8_t, CVMX_SCRATCH_BASE + address) =
101 (uint8_t) value;
102 }
103
104 /**
105 * Writes a 32 bit value to the processor local scratchpad memory.
106 *
107 * @address: byte address to write to
108 * @value: value to write
109 */
cvmx_scratch_write16(uint64_t address,uint64_t value)110 static inline void cvmx_scratch_write16(uint64_t address, uint64_t value)
111 {
112 *CASTPTR(volatile uint16_t, CVMX_SCRATCH_BASE + address) =
113 (uint16_t) value;
114 }
115
116 /**
117 * Writes a 16 bit value to the processor local scratchpad memory.
118 *
119 * @address: byte address to write to
120 * @value: value to write
121 */
cvmx_scratch_write32(uint64_t address,uint64_t value)122 static inline void cvmx_scratch_write32(uint64_t address, uint64_t value)
123 {
124 *CASTPTR(volatile uint32_t, CVMX_SCRATCH_BASE + address) =
125 (uint32_t) value;
126 }
127
128 /**
129 * Writes a 64 bit value to the processor local scratchpad memory.
130 *
131 * @address: byte address to write to
132 * @value: value to write
133 */
cvmx_scratch_write64(uint64_t address,uint64_t value)134 static inline void cvmx_scratch_write64(uint64_t address, uint64_t value)
135 {
136 *CASTPTR(volatile uint64_t, CVMX_SCRATCH_BASE + address) = value;
137 }
138
139 #endif /* __CVMX_SCRATCH_H__ */
140