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