Home | History | Annotate | Line # | Download | only in include
sb1250_defs.h revision 1.3
      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 
     52 /*  *********************************************************************
     53     *  Naming schemes for constants in these files:
     54     *
     55     *  M_xxx           MASK constant (identifies bits in a register).
     56     *                  For multi-bit fields, all bits in the field will
     57     *                  be set.
     58     *
     59     *  K_xxx           "Code" constant (value for data in a multi-bit
     60     *                  field).  The value is right justified.
     61     *
     62     *  V_xxx           "Value" constant.  This is the same as the
     63     *                  corresponding "K_xxx" constant, except it is
     64     *                  shifted to the correct position in the register.
     65     *
     66     *  S_xxx           SHIFT constant.  This is the number of bits that
     67     *                  a field value (code) needs to be shifted
     68     *                  (towards the left) to put the value in the right
     69     *                  position for the register.
     70     *
     71     *  A_xxx           ADDRESS constant.  This will be a physical
     72     *                  address.  Use the PHYS_TO_K1 macro to generate
     73     *                  a K1SEG address.
     74     *
     75     *  R_xxx           RELATIVE offset constant.  This is an offset from
     76     *                  an A_xxx constant (usually the first register in
     77     *                  a group).
     78     *
     79     *  G_xxx(X)        GET value.  This macro obtains a multi-bit field
     80     *                  from a register, masks it, and shifts it to
     81     *                  the bottom of the register (retrieving a K_xxx
     82     *                  value, for example).
     83     *
     84     *  V_xxx(X)        VALUE.  This macro computes the value of a
     85     *                  K_xxx constant shifted to the correct position
     86     *                  in the register.
     87     ********************************************************************* */
     88 
     89 
     90 
     91 
     92 #ifndef _SB1250_DEFS_H
     93 #define _SB1250_DEFS_H
     94 
     95 /*
     96  * Cast to 64-bit number.  Presumably the syntax is different in
     97  * assembly language.
     98  *
     99  * Note: you'll need to define uint32_t and uint64_t in your headers.
    100  */
    101 
    102 #if !defined(__ASSEMBLER__)
    103 #define _SB_MAKE64(x) ((uint64_t)(x))
    104 #define _SB_MAKE32(x) ((uint32_t)(x))
    105 #else
    106 #define _SB_MAKE64(x) (x)
    107 #define _SB_MAKE32(x) (x)
    108 #endif
    109 
    110 
    111 /*
    112  * Make a mask for 1 bit at position 'n'
    113  */
    114 
    115 #define _SB_MAKEMASK1(n) (_SB_MAKE64(1) << _SB_MAKE64(n))
    116 #define _SB_MAKEMASK1_32(n) (_SB_MAKE32(1) << _SB_MAKE32(n))
    117 
    118 /*
    119  * Make a mask for 'v' bits at position 'n'
    120  */
    121 
    122 #define _SB_MAKEMASK(v,n) (_SB_MAKE64((_SB_MAKE64(1)<<(v))-1) << _SB_MAKE64(n))
    123 #define _SB_MAKEMASK_32(v,n) (_SB_MAKE32((_SB_MAKE32(1)<<(v))-1) << _SB_MAKE32(n))
    124 
    125 /*
    126  * Make a value at 'v' at bit position 'n'
    127  */
    128 
    129 #define _SB_MAKEVALUE(v,n) (_SB_MAKE64(v) << _SB_MAKE64(n))
    130 #define _SB_MAKEVALUE_32(v,n) (_SB_MAKE32(v) << _SB_MAKE32(n))
    131 
    132 #define _SB_GETVALUE(v,n,m) ((_SB_MAKE64(v) & _SB_MAKE64(m)) >> _SB_MAKE64(n))
    133 #define _SB_GETVALUE_32(v,n,m) ((_SB_MAKE32(v) & _SB_MAKE32(m)) >> _SB_MAKE32(n))
    134 
    135 /*
    136  * Macros to read/write on-chip registers
    137  * XXX should we do the PHYS_TO_K1 here?
    138  */
    139 
    140 
    141 #if !defined(__ASSEMBLER__)
    142 #define SBWRITECSR(csr,val) *((volatile uint64_t *) MIPS_PHYS_TO_KSEG1(csr)) = (val)
    143 #define SBREADCSR(csr) (*((volatile uint64_t *) MIPS_PHYS_TO_KSEG1(csr)))
    144 #endif /* __ASSEMBLER__ */
    145 
    146 #endif
    147