sb1250_defs.h revision 1.4 1 /* *********************************************************************
2 * SB1250 Board Support Package
3 *
4 * Global constants and macros File: sb1250_defs.h
5 *
6 * This file contains macros and definitions used by the other
7 * include files.
8 *
9 * SB1250 specification level: User's manual 1/02/02
10 *
11 * Author: Mitch Lichtenberg (mpl (at) broadcom.com)
12 *
13 *********************************************************************
14 *
15 * Copyright 2000,2001
16 * Broadcom Corporation. All rights reserved.
17 *
18 * This software is furnished under license and may be used and
19 * copied only in accordance with the following terms and
20 * conditions. Subject to these conditions, you may download,
21 * copy, install, use, modify and distribute modified or unmodified
22 * copies of this software in source and/or binary form. No title
23 * or ownership is transferred hereby.
24 *
25 * 1) Any source code used, modified or distributed must reproduce
26 * and retain this copyright notice and list of conditions as
27 * they appear in the source file.
28 *
29 * 2) No right is granted to use any trade name, trademark, or
30 * logo of Broadcom Corporation. Neither the "Broadcom
31 * Corporation" name nor any trademark or logo of Broadcom
32 * Corporation may be used to endorse or promote products
33 * derived from this software without the prior written
34 * permission of Broadcom Corporation.
35 *
36 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
37 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
38 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
39 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
40 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
41 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
42 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
43 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
44 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
45 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
46 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
47 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
48 * THE POSSIBILITY OF SUCH DAMAGE.
49 ********************************************************************* */
50
51 #ifndef _SB1250_DEFS_H
52 #define _SB1250_DEFS_H
53
54 /*
55 * These headers require ANSI C89 string concatenation, and GCC or other
56 * 'long long' (64-bit integer) support.
57 */
58 #if !defined(__STDC__) && !defined(_MSC_VER)
59 #error SiByte headers require ANSI C89 support
60 #endif
61
62
63 /* *********************************************************************
64 * Macros for feature tests, used to enable include file features
65 * for chip features only present in certain chip revisions.
66 *
67 * SIBYTE_HDR_FEATURES may be defined to be the mask value chip/revision
68 * which is to be exposed by the headers. If undefined, it defaults to
69 * "all features."
70 *
71 * Use like:
72 *
73 * #define SIBYTE_HDR_FEATURES SIBYTE_HDR_FMASK_112x_PASS1
74 *
75 * Generate defines only for that revision of chip.
76 *
77 * #if SIBYTE_HDR_FEATURE(chip,pass)
78 *
79 * True if header features for that revision or later of
80 * that particular chip type are enabled in SIBYTE_HDR_FEATURES.
81 * (Use this to bracket #defines for features present in a given
82 * revision and later.)
83 *
84 * Note that there is no implied ordering between chip types.
85 *
86 * Note also that 'chip' and 'pass' must textually exactly
87 * match the defines below. So, for example,
88 * SIBYTE_HDR_FEATURE(112x, PASS1) is OK, but
89 * SIBYTE_HDR_FEATURE(1120, pass1) is not (for two reasons).
90 *
91 * #if SIBYTE_HDR_FEATURE_UP_TO(chip,pass)
92 *
93 * Same as SIBYTE_HDR_FEATURE, but true for the named revision
94 * and earlier revisions of the named chip type.
95 *
96 * #if SIBYTE_HDR_FEATURE_EXACT(chip,pass)
97 *
98 * Same as SIBYTE_HDR_FEATURE, but only true for the named
99 * revision of the named chip type. (Note that this CANNOT
100 * be used to verify that you're compiling only for that
101 * particular chip/revision. It will be true any time this
102 * chip/revision is included in SIBYTE_HDR_FEATURES.)
103 *
104 * #if SIBYTE_HDR_FEATURE_CHIP(chip)
105 *
106 * True if header features for (any revision of) that chip type
107 * are enabled in SIBYTE_HDR_FEATURES. (Use this to bracket
108 * #defines for features specific to a given chip type.)
109 *
110 * Mask values currently include room for additional revisions of each
111 * chip type, but can be renumbered at will. Note that they MUST fit
112 * into 31 bits and may not include C type constructs, for safe use in
113 * CPP conditionals. Bit positions within chip types DO indicate
114 * ordering, so be careful when adding support for new minor revs.
115 ********************************************************************* */
116
117 #define SIBYTE_HDR_FMASK_1250_ALL 0x00000ff
118 #define SIBYTE_HDR_FMASK_1250_PASS1 0x0000001
119 #define SIBYTE_HDR_FMASK_1250_PASS2 0x0000002
120
121 #define SIBYTE_HDR_FMASK_112x_ALL 0x0000f00
122 #define SIBYTE_HDR_FMASK_112x_PASS1 0x0000100
123 #define SIBYTE_HDR_FMASK_112x_PASS3 0x0000200
124
125 /* Bit mask for chip/revision. (use _ALL for all revisions of a chip). */
126 #define SIBYTE_HDR_FMASK(chip, pass) \
127 (SIBYTE_HDR_FMASK_ ## chip ## _ ## pass)
128 #define SIBYTE_HDR_FMASK_ALLREVS(chip) \
129 (SIBYTE_HDR_FMASK_ ## chip ## _ALL)
130
131 #define SIBYTE_HDR_FMASK_ALL \
132 (SIBYTE_HDR_FMASK_1250_ALL | SIBYTE_HDR_FMASK_112x_ALL)
133
134 #ifndef SIBYTE_HDR_FEATURES
135 #define SIBYTE_HDR_FEATURES SIBYTE_HDR_FMASK_ALL
136 #endif
137
138
139 /* Bit mask for revisions of chip exclusively before the named revision. */
140 #define SIBYTE_HDR_FMASK_BEFORE(chip, pass) \
141 ((SIBYTE_HDR_FMASK(chip, pass) - 1) & SIBYTE_HDR_FMASK_ALLREVS(chip))
142
143 /* Bit mask for revisions of chip exclusively after the named revision. */
144 #define SIBYTE_HDR_FMASK_AFTER(chip, pass) \
145 (~(SIBYTE_HDR_FMASK(chip, pass) \
146 | (SIBYTE_HDR_FMASK(chip, pass) - 1)) & SIBYTE_HDR_FMASK_ALLREVS(chip))
147
148
149 /* True if header features enabled for (any revision of) that chip type. */
150 #define SIBYTE_HDR_FEATURE_CHIP(chip) \
151 (!! (SIBYTE_HDR_FMASK_ALLREVS(chip) & SIBYTE_HDR_FEATURES))
152
153 /* True if header features enabled for that rev or later, inclusive. */
154 #define SIBYTE_HDR_FEATURE(chip, pass) \
155 (!! ((SIBYTE_HDR_FMASK(chip, pass) \
156 | SIBYTE_HDR_FMASK_AFTER(chip, pass)) & SIBYTE_HDR_FEATURES))
157
158 /* True if header features enabled for exactly that rev. */
159 #define SIBYTE_HDR_FEATURE_EXACT(chip, pass) \
160 (!! (SIBYTE_HDR_FMASK(chip, pass) & SIBYTE_HDR_FEATURES))
161
162 /* True if header features enabled for that rev or before, inclusive. */
163 #define SIBYTE_HDR_FEATURE_UP_TO(chip, pass) \
164 (!! ((SIBYTE_HDR_FMASK(chip, pass) \
165 | SIBYTE_HDR_FMASK_BEFORE(chip, pass)) & SIBYTE_HDR_FEATURES))
166
167
168 /* *********************************************************************
169 * Naming schemes for constants in these files:
170 *
171 * M_xxx MASK constant (identifies bits in a register).
172 * For multi-bit fields, all bits in the field will
173 * be set.
174 *
175 * K_xxx "Code" constant (value for data in a multi-bit
176 * field). The value is right justified.
177 *
178 * V_xxx "Value" constant. This is the same as the
179 * corresponding "K_xxx" constant, except it is
180 * shifted to the correct position in the register.
181 *
182 * S_xxx SHIFT constant. This is the number of bits that
183 * a field value (code) needs to be shifted
184 * (towards the left) to put the value in the right
185 * position for the register.
186 *
187 * A_xxx ADDRESS constant. This will be a physical
188 * address. Use the PHYS_TO_K1 macro to generate
189 * a K1SEG address.
190 *
191 * R_xxx RELATIVE offset constant. This is an offset from
192 * an A_xxx constant (usually the first register in
193 * a group).
194 *
195 * G_xxx(X) GET value. This macro obtains a multi-bit field
196 * from a register, masks it, and shifts it to
197 * the bottom of the register (retrieving a K_xxx
198 * value, for example).
199 *
200 * V_xxx(X) VALUE. This macro computes the value of a
201 * K_xxx constant shifted to the correct position
202 * in the register.
203 ********************************************************************* */
204
205
206
207
208 /*
209 * Cast to 64-bit number. Presumably the syntax is different in
210 * assembly language.
211 *
212 * Note: you'll need to define uint32_t and uint64_t in your headers.
213 */
214
215 #if !defined(__ASSEMBLER__)
216 #define _SB_MAKE64(x) ((uint64_t)(x))
217 #define _SB_MAKE32(x) ((uint32_t)(x))
218 #else
219 #define _SB_MAKE64(x) (x)
220 #define _SB_MAKE32(x) (x)
221 #endif
222
223
224 /*
225 * Make a mask for 1 bit at position 'n'
226 */
227
228 #define _SB_MAKEMASK1(n) (_SB_MAKE64(1) << _SB_MAKE64(n))
229 #define _SB_MAKEMASK1_32(n) (_SB_MAKE32(1) << _SB_MAKE32(n))
230
231 /*
232 * Make a mask for 'v' bits at position 'n'
233 */
234
235 #define _SB_MAKEMASK(v,n) (_SB_MAKE64((_SB_MAKE64(1)<<(v))-1) << _SB_MAKE64(n))
236 #define _SB_MAKEMASK_32(v,n) (_SB_MAKE32((_SB_MAKE32(1)<<(v))-1) << _SB_MAKE32(n))
237
238 /*
239 * Make a value at 'v' at bit position 'n'
240 */
241
242 #define _SB_MAKEVALUE(v,n) (_SB_MAKE64(v) << _SB_MAKE64(n))
243 #define _SB_MAKEVALUE_32(v,n) (_SB_MAKE32(v) << _SB_MAKE32(n))
244
245 #define _SB_GETVALUE(v,n,m) ((_SB_MAKE64(v) & _SB_MAKE64(m)) >> _SB_MAKE64(n))
246 #define _SB_GETVALUE_32(v,n,m) ((_SB_MAKE32(v) & _SB_MAKE32(m)) >> _SB_MAKE32(n))
247
248 /*
249 * Macros to read/write on-chip registers
250 * XXX should we do the PHYS_TO_K1 here?
251 */
252
253
254 #if !defined(__ASSEMBLER__)
255 #define SBWRITECSR(csr,val) *((volatile uint64_t *) PHYS_TO_K1(csr)) = (val)
256 #define SBREADCSR(csr) (*((volatile uint64_t *) PHYS_TO_K1(csr)))
257 #endif /* __ASSEMBLER__ */
258
259 #endif
260