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