Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / mips / sibyte / include / sb1250_defs.h
blob439e6a118f825234a7aaafbee261c37d27e658e9
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.
9 * SB1250 specification level: User's manual 1/02/02
11 *********************************************************************
13 * Copyright 2000,2001,2002,2003,2004
14 * Broadcom Corporation. All rights reserved.
16 * This software is furnished under license and may be used and
17 * copied only in accordance with the following terms and
18 * conditions. Subject to these conditions, you may download,
19 * copy, install, use, modify and distribute modified or unmodified
20 * copies of this software in source and/or binary form. No title
21 * or ownership is transferred hereby.
23 * 1) Any source code used, modified or distributed must reproduce
24 * and retain this copyright notice and list of conditions
25 * as they appear in the source file.
27 * 2) No right is granted to use any trade name, trademark, or
28 * logo of Broadcom Corporation. The "Broadcom Corporation"
29 * name may not be used to endorse or promote products derived
30 * from this software without the prior written permission of
31 * Broadcom Corporation.
33 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
34 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
35 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
37 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
38 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
39 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
40 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
41 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
43 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
44 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
45 * THE POSSIBILITY OF SUCH DAMAGE.
46 ********************************************************************* */
48 #ifndef _SB1250_DEFS_H
49 #define _SB1250_DEFS_H
52 * These headers require ANSI C89 string concatenation, and GCC or other
53 * 'long long' (64-bit integer) support.
55 #if !defined(__STDC__) && !defined(_MSC_VER)
56 #error SiByte headers require ANSI C89 support
57 #endif
60 /* *********************************************************************
61 * Macros for feature tests, used to enable include file features
62 * for chip features only present in certain chip revisions.
64 * SIBYTE_HDR_FEATURES may be defined to be the mask value chip/revision
65 * which is to be exposed by the headers. If undefined, it defaults to
66 * "all features."
68 * Use like:
70 * #define SIBYTE_HDR_FEATURES SIBYTE_HDR_FMASK_112x_PASS1
72 * Generate defines only for that revision of chip.
74 * #if SIBYTE_HDR_FEATURE(chip,pass)
76 * True if header features for that revision or later of
77 * that particular chip type are enabled in SIBYTE_HDR_FEATURES.
78 * (Use this to bracket #defines for features present in a given
79 * revision and later.)
81 * Note that there is no implied ordering between chip types.
83 * Note also that 'chip' and 'pass' must textually exactly
84 * match the defines below. So, for example,
85 * SIBYTE_HDR_FEATURE(112x, PASS1) is OK, but
86 * SIBYTE_HDR_FEATURE(1120, pass1) is not (for two reasons).
88 * #if SIBYTE_HDR_FEATURE_UP_TO(chip,pass)
90 * Same as SIBYTE_HDR_FEATURE, but true for the named revision
91 * and earlier revisions of the named chip type.
93 * #if SIBYTE_HDR_FEATURE_EXACT(chip,pass)
95 * Same as SIBYTE_HDR_FEATURE, but only true for the named
96 * revision of the named chip type. (Note that this CANNOT
97 * be used to verify that you're compiling only for that
98 * particular chip/revision. It will be true any time this
99 * chip/revision is included in SIBYTE_HDR_FEATURES.)
101 * #if SIBYTE_HDR_FEATURE_CHIP(chip)
103 * True if header features for (any revision of) that chip type
104 * are enabled in SIBYTE_HDR_FEATURES. (Use this to bracket
105 * #defines for features specific to a given chip type.)
107 * Mask values currently include room for additional revisions of each
108 * chip type, but can be renumbered at will. Note that they MUST fit
109 * into 31 bits and may not include C type constructs, for safe use in
110 * CPP conditionals. Bit positions within chip types DO indicate
111 * ordering, so be careful when adding support for new minor revs.
112 ********************************************************************* */
114 #define SIBYTE_HDR_FMASK_1250_ALL 0x000000ff
115 #define SIBYTE_HDR_FMASK_1250_PASS1 0x00000001
116 #define SIBYTE_HDR_FMASK_1250_PASS2 0x00000002
117 #define SIBYTE_HDR_FMASK_1250_PASS3 0x00000004
119 #define SIBYTE_HDR_FMASK_112x_ALL 0x00000f00
120 #define SIBYTE_HDR_FMASK_112x_PASS1 0x00000100
122 #define SIBYTE_HDR_FMASK_1480_ALL 0x0000f000
123 #define SIBYTE_HDR_FMASK_1480_PASS1 0x00001000
124 #define SIBYTE_HDR_FMASK_1480_PASS2 0x00002000
126 /* Bit mask for chip/revision. (use _ALL for all revisions of a chip). */
127 #define SIBYTE_HDR_FMASK(chip, pass) \
128 (SIBYTE_HDR_FMASK_ ## chip ## _ ## pass)
129 #define SIBYTE_HDR_FMASK_ALLREVS(chip) \
130 (SIBYTE_HDR_FMASK_ ## chip ## _ALL)
132 /* Default constant value for all chips, all revisions */
133 #define SIBYTE_HDR_FMASK_ALL \
134 (SIBYTE_HDR_FMASK_1250_ALL | SIBYTE_HDR_FMASK_112x_ALL \
135 | SIBYTE_HDR_FMASK_1480_ALL)
137 /* This one is used for the "original" BCM1250/BCM112x chips. We use this
138 to weed out constants and macros that do not exist on later chips like
139 the BCM1480 */
140 #define SIBYTE_HDR_FMASK_1250_112x_ALL \
141 (SIBYTE_HDR_FMASK_1250_ALL | SIBYTE_HDR_FMASK_112x_ALL)
142 #define SIBYTE_HDR_FMASK_1250_112x SIBYTE_HDR_FMASK_1250_112x_ALL
144 #ifndef SIBYTE_HDR_FEATURES
145 #define SIBYTE_HDR_FEATURES SIBYTE_HDR_FMASK_ALL
146 #endif
149 /* Bit mask for revisions of chip exclusively before the named revision. */
150 #define SIBYTE_HDR_FMASK_BEFORE(chip, pass) \
151 ((SIBYTE_HDR_FMASK(chip, pass) - 1) & SIBYTE_HDR_FMASK_ALLREVS(chip))
153 /* Bit mask for revisions of chip exclusively after the named revision. */
154 #define SIBYTE_HDR_FMASK_AFTER(chip, pass) \
155 (~(SIBYTE_HDR_FMASK(chip, pass) \
156 | (SIBYTE_HDR_FMASK(chip, pass) - 1)) & SIBYTE_HDR_FMASK_ALLREVS(chip))
159 /* True if header features enabled for (any revision of) that chip type. */
160 #define SIBYTE_HDR_FEATURE_CHIP(chip) \
161 (!! (SIBYTE_HDR_FMASK_ALLREVS(chip) & SIBYTE_HDR_FEATURES))
163 /* True for all versions of the BCM1250 and BCM1125, but not true for
164 anything else */
165 #define SIBYTE_HDR_FEATURE_1250_112x \
166 (SIBYTE_HDR_FEATURE_CHIP(1250) || SIBYTE_HDR_FEATURE_CHIP(112x))
167 /* (!! (SIBYTE_HDR_FEATURES & SIBYHTE_HDR_FMASK_1250_112x)) */
169 /* True if header features enabled for that rev or later, inclusive. */
170 #define SIBYTE_HDR_FEATURE(chip, pass) \
171 (!! ((SIBYTE_HDR_FMASK(chip, pass) \
172 | SIBYTE_HDR_FMASK_AFTER(chip, pass)) & SIBYTE_HDR_FEATURES))
174 /* True if header features enabled for exactly that rev. */
175 #define SIBYTE_HDR_FEATURE_EXACT(chip, pass) \
176 (!! (SIBYTE_HDR_FMASK(chip, pass) & SIBYTE_HDR_FEATURES))
178 /* True if header features enabled for that rev or before, inclusive. */
179 #define SIBYTE_HDR_FEATURE_UP_TO(chip, pass) \
180 (!! ((SIBYTE_HDR_FMASK(chip, pass) \
181 | SIBYTE_HDR_FMASK_BEFORE(chip, pass)) & SIBYTE_HDR_FEATURES))
184 /* *********************************************************************
185 * Naming schemes for constants in these files:
187 * M_xxx MASK constant (identifies bits in a register).
188 * For multi-bit fields, all bits in the field will
189 * be set.
191 * K_xxx "Code" constant (value for data in a multi-bit
192 * field). The value is right justified.
194 * V_xxx "Value" constant. This is the same as the
195 * corresponding "K_xxx" constant, except it is
196 * shifted to the correct position in the register.
198 * S_xxx SHIFT constant. This is the number of bits that
199 * a field value (code) needs to be shifted
200 * (towards the left) to put the value in the right
201 * position for the register.
203 * A_xxx ADDRESS constant. This will be a physical
204 * address. Use the PHYS_TO_K1 macro to generate
205 * a K1SEG address.
207 * R_xxx RELATIVE offset constant. This is an offset from
208 * an A_xxx constant (usually the first register in
209 * a group).
211 * G_xxx(X) GET value. This macro obtains a multi-bit field
212 * from a register, masks it, and shifts it to
213 * the bottom of the register (retrieving a K_xxx
214 * value, for example).
216 * V_xxx(X) VALUE. This macro computes the value of a
217 * K_xxx constant shifted to the correct position
218 * in the register.
219 ********************************************************************* */
225 * Cast to 64-bit number. Presumably the syntax is different in
226 * assembly language.
228 * Note: you'll need to define uint32_t and uint64_t in your headers.
231 #if !defined(__ASSEMBLER__)
232 #define _SB_MAKE64(x) ((uint64_t)(x))
233 #define _SB_MAKE32(x) ((uint32_t)(x))
234 #else
235 #define _SB_MAKE64(x) (x)
236 #define _SB_MAKE32(x) (x)
237 #endif
241 * Make a mask for 1 bit at position 'n'
244 #define _SB_MAKEMASK1(n) (_SB_MAKE64(1) << _SB_MAKE64(n))
245 #define _SB_MAKEMASK1_32(n) (_SB_MAKE32(1) << _SB_MAKE32(n))
248 * Make a mask for 'v' bits at position 'n'
251 #define _SB_MAKEMASK(v,n) (_SB_MAKE64((_SB_MAKE64(1)<<(v))-1) << _SB_MAKE64(n))
252 #define _SB_MAKEMASK_32(v,n) (_SB_MAKE32((_SB_MAKE32(1)<<(v))-1) << _SB_MAKE32(n))
255 * Make a value at 'v' at bit position 'n'
258 #define _SB_MAKEVALUE(v,n) (_SB_MAKE64(v) << _SB_MAKE64(n))
259 #define _SB_MAKEVALUE_32(v,n) (_SB_MAKE32(v) << _SB_MAKE32(n))
261 #define _SB_GETVALUE(v,n,m) ((_SB_MAKE64(v) & _SB_MAKE64(m)) >> _SB_MAKE64(n))
262 #define _SB_GETVALUE_32(v,n,m) ((_SB_MAKE32(v) & _SB_MAKE32(m)) >> _SB_MAKE32(n))
265 * Macros to read/write on-chip registers
266 * XXX should we do the PHYS_TO_K1 here?
270 #if defined(__mips64) && !defined(__ASSEMBLER__)
271 #define SBWRITECSR(csr,val) *((volatile uint64_t *) PHYS_TO_K1(csr)) = (val)
272 #define SBREADCSR(csr) (*((volatile uint64_t *) PHYS_TO_K1(csr)))
273 #endif /* __ASSEMBLER__ */
275 #endif