cvmx-scratch.h revision 232812
1/***********************license start***************
2 * Copyright (c) 2003-2010  Cavium Inc. (support@cavium.com). All rights
3 * reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 *   * Redistributions of source code must retain the above copyright
11 *     notice, this list of conditions and the following disclaimer.
12 *
13 *   * Redistributions in binary form must reproduce the above
14 *     copyright notice, this list of conditions and the following
15 *     disclaimer in the documentation and/or other materials provided
16 *     with the distribution.
17
18 *   * Neither the name of Cavium Inc. nor the names of
19 *     its contributors may be used to endorse or promote products
20 *     derived from this software without specific prior written
21 *     permission.
22
23 * This Software, including technical data, may be subject to U.S. export  control
24 * laws, including the U.S. Export Administration Act and its  associated
25 * regulations, and may be subject to export or import  regulations in other
26 * countries.
27
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
39
40
41
42
43
44
45
46/**
47 * @file
48 *
49 * This file provides support for the processor local scratch memory.
50 * Scratch memory is byte addressable - all addresses are byte addresses.
51 *
52 *
53 * <hr>$Revision: 70030 $<hr>
54 *
55 *
56 */
57
58
59#ifndef __CVMX_SCRATCH_H__
60#define __CVMX_SCRATCH_H__
61
62#ifdef	__cplusplus
63extern "C" {
64#endif
65
66/* Note: This define must be a long, not a long long in order to compile
67        without warnings for both 32bit and 64bit. */
68#define CVMX_SCRATCH_BASE       (-32768l) /* 0xffffffffffff8000 */
69
70
71/**
72 * Reads an 8 bit value from the processor local scratchpad memory.
73 *
74 * @param address byte address to read from
75 *
76 * @return value read
77 */
78static inline uint8_t cvmx_scratch_read8(uint64_t address)
79{
80    return *CASTPTR(volatile uint8_t, CVMX_SCRATCH_BASE + address);
81}
82/**
83 * Reads a 16 bit value from the processor local scratchpad memory.
84 *
85 * @param address byte address to read from
86 *
87 * @return value read
88 */
89static inline uint16_t cvmx_scratch_read16(uint64_t address)
90{
91    return *CASTPTR(volatile uint16_t, CVMX_SCRATCH_BASE + address);
92}
93/**
94 * Reads a 32 bit value from the processor local scratchpad memory.
95 *
96 * @param address byte address to read from
97 *
98 * @return value read
99 */
100static inline uint32_t cvmx_scratch_read32(uint64_t address)
101{
102    return *CASTPTR(volatile uint32_t, CVMX_SCRATCH_BASE + address);
103}
104/**
105 * Reads a 64 bit value from the processor local scratchpad memory.
106 *
107 * @param address byte address to read from
108 *
109 * @return value read
110 */
111static inline uint64_t cvmx_scratch_read64(uint64_t address)
112{
113    return *CASTPTR(volatile uint64_t, CVMX_SCRATCH_BASE + address);
114}
115
116
117
118/**
119 * Writes an 8 bit value to the processor local scratchpad memory.
120 *
121 * @param address byte address to write to
122 * @param value   value to write
123 */
124static inline void cvmx_scratch_write8(uint64_t address, uint64_t value)
125{
126    *CASTPTR(volatile uint8_t, CVMX_SCRATCH_BASE + address) = (uint8_t)value;
127}
128/**
129 * Writes a 32 bit value to the processor local scratchpad memory.
130 *
131 * @param address byte address to write to
132 * @param value   value to write
133 */
134static inline void cvmx_scratch_write16(uint64_t address, uint64_t value)
135{
136    *CASTPTR(volatile uint16_t, CVMX_SCRATCH_BASE + address) = (uint16_t)value;
137}
138/**
139 * Writes a 16 bit value to the processor local scratchpad memory.
140 *
141 * @param address byte address to write to
142 * @param value   value to write
143 */
144static inline void cvmx_scratch_write32(uint64_t address, uint64_t value)
145{
146    *CASTPTR(volatile uint32_t, CVMX_SCRATCH_BASE + address) = (uint32_t)value;
147}
148/**
149 * Writes a 64 bit value to the processor local scratchpad memory.
150 *
151 * @param address byte address to write to
152 * @param value   value to write
153 */
154static inline void cvmx_scratch_write64(uint64_t address, uint64_t value)
155{
156    *CASTPTR(volatile uint64_t, CVMX_SCRATCH_BASE + address) = value;
157}
158
159#ifdef	__cplusplus
160}
161#endif
162
163#endif /* __CVMX_SCRATCH_H__ */
164