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 ********************************************************************* 12 * 13 * Copyright 2000,2001,2002,2003,2004 14 * Broadcom Corporation. All rights reserved. 15 * 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. 22 * 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. 26 * 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. 32 * 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 ********************************************************************* */ 47 48#ifndef _SB1250_DEFS_H 49#define _SB1250_DEFS_H 50 51/* 52 * These headers require ANSI C89 string concatenation, and GCC or other 53 * 'long long' (64-bit integer) support. 54 */ 55#if !defined(__STDC__) && !defined(_MSC_VER) 56#error SiByte headers require ANSI C89 support 57#endif 58 59 60/* ********************************************************************* 61 * Macros for feature tests, used to enable include file features 62 * for chip features only present in certain chip revisions. 63 * 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." 67 * 68 * Use like: 69 * 70 * #define SIBYTE_HDR_FEATURES SIBYTE_HDR_FMASK_112x_PASS1 71 * 72 * Generate defines only for that revision of chip. 73 * 74 * #if SIBYTE_HDR_FEATURE(chip,pass) 75 * 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.) 80 * 81 * Note that there is no implied ordering between chip types. 82 * 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). 87 * 88 * #if SIBYTE_HDR_FEATURE_UP_TO(chip,pass) 89 * 90 * Same as SIBYTE_HDR_FEATURE, but true for the named revision 91 * and earlier revisions of the named chip type. 92 * 93 * #if SIBYTE_HDR_FEATURE_EXACT(chip,pass) 94 * 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.) 100 * 101 * #if SIBYTE_HDR_FEATURE_CHIP(chip) 102 * 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.) 106 * 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 ********************************************************************* */ 113 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 118 119#define SIBYTE_HDR_FMASK_112x_ALL 0x00000f00 120#define SIBYTE_HDR_FMASK_112x_PASS1 0x00000100 121 122#define SIBYTE_HDR_FMASK_1480_ALL 0x0000f000 123#define SIBYTE_HDR_FMASK_1480_PASS1 0x00001000 124#define SIBYTE_HDR_FMASK_1480_PASS2 0x00002000 125 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) 131 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) 136 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 143 144#ifndef SIBYTE_HDR_FEATURES 145#define SIBYTE_HDR_FEATURES SIBYTE_HDR_FMASK_ALL 146#endif 147 148 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)) 152 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)) 157 158 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)) 162 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)) */ 168 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)) 173 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)) 177 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)) 182 183 184/* ********************************************************************* 185 * Naming schemes for constants in these files: 186 * 187 * M_xxx MASK constant (identifies bits in a register). 188 * For multi-bit fields, all bits in the field will 189 * be set. 190 * 191 * K_xxx "Code" constant (value for data in a multi-bit 192 * field). The value is right justified. 193 * 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. 197 * 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. 202 * 203 * A_xxx ADDRESS constant. This will be a physical 204 * address. Use the PHYS_TO_K1 macro to generate 205 * a K1SEG address. 206 * 207 * R_xxx RELATIVE offset constant. This is an offset from 208 * an A_xxx constant (usually the first register in 209 * a group). 210 * 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). 215 * 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 ********************************************************************* */ 220 221 222 223 224/* 225 * Cast to 64-bit number. Presumably the syntax is different in 226 * assembly language. 227 * 228 * Note: you'll need to define uint32_t and uint64_t in your headers. 229 */ 230 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 238 239 240/* 241 * Make a mask for 1 bit at position 'n' 242 */ 243 244#define _SB_MAKEMASK1(n) (_SB_MAKE64(1) << _SB_MAKE64(n)) 245#define _SB_MAKEMASK1_32(n) (_SB_MAKE32(1) << _SB_MAKE32(n)) 246 247/* 248 * Make a mask for 'v' bits at position 'n' 249 */ 250 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)) 253 254/* 255 * Make a value at 'v' at bit position 'n' 256 */ 257 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)) 260 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)) 263 264/* 265 * Macros to read/write on-chip registers 266 * XXX should we do the PHYS_TO_K1 here? 267 */ 268 269 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__ */ 274 275#endif 276 277