Home | History | Annotate | Line # | Download | only in include
sb1250_defs.h revision 1.3
      1  1.1  simonb /*  *********************************************************************
      2  1.1  simonb     *  SB1250 Board Support Package
      3  1.3  simonb     *
      4  1.3  simonb     *  Global constants and macros		File: sb1250_defs.h
      5  1.3  simonb     *
      6  1.1  simonb     *  This file contains macros and definitions used by the other
      7  1.1  simonb     *  include files.
      8  1.1  simonb     *
      9  1.3  simonb     *  SB1250 specification level:  User's manual 1/02/02
     10  1.3  simonb     *
     11  1.3  simonb     *  Author:  Mitch Lichtenberg (mpl (at) broadcom.com)
     12  1.3  simonb     *
     13  1.3  simonb     *********************************************************************
     14  1.1  simonb     *
     15  1.1  simonb     *  Copyright 2000,2001
     16  1.1  simonb     *  Broadcom Corporation. All rights reserved.
     17  1.3  simonb     *
     18  1.3  simonb     *  This software is furnished under license and may be used and
     19  1.3  simonb     *  copied only in accordance with the following terms and
     20  1.3  simonb     *  conditions.  Subject to these conditions, you may download,
     21  1.3  simonb     *  copy, install, use, modify and distribute modified or unmodified
     22  1.3  simonb     *  copies of this software in source and/or binary form.  No title
     23  1.1  simonb     *  or ownership is transferred hereby.
     24  1.3  simonb     *
     25  1.3  simonb     *  1) Any source code used, modified or distributed must reproduce
     26  1.3  simonb     *     and retain this copyright notice and list of conditions as
     27  1.1  simonb     *     they appear in the source file.
     28  1.3  simonb     *
     29  1.3  simonb     *  2) No right is granted to use any trade name, trademark, or
     30  1.3  simonb     *     logo of Broadcom Corporation. Neither the "Broadcom
     31  1.3  simonb     *     Corporation" name nor any trademark or logo of Broadcom
     32  1.3  simonb     *     Corporation may be used to endorse or promote products
     33  1.3  simonb     *     derived from this software without the prior written
     34  1.1  simonb     *     permission of Broadcom Corporation.
     35  1.3  simonb     *
     36  1.1  simonb     *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
     37  1.3  simonb     *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
     38  1.3  simonb     *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
     39  1.3  simonb     *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
     40  1.3  simonb     *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
     41  1.3  simonb     *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
     42  1.3  simonb     *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     43  1.3  simonb     *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     44  1.1  simonb     *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     45  1.3  simonb     *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     46  1.3  simonb     *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
     47  1.3  simonb     *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
     48  1.1  simonb     *     THE POSSIBILITY OF SUCH DAMAGE.
     49  1.1  simonb     ********************************************************************* */
     50  1.1  simonb 
     51  1.1  simonb 
     52  1.1  simonb /*  *********************************************************************
     53  1.1  simonb     *  Naming schemes for constants in these files:
     54  1.3  simonb     *
     55  1.3  simonb     *  M_xxx           MASK constant (identifies bits in a register).
     56  1.3  simonb     *                  For multi-bit fields, all bits in the field will
     57  1.3  simonb     *                  be set.
     58  1.3  simonb     *
     59  1.3  simonb     *  K_xxx           "Code" constant (value for data in a multi-bit
     60  1.3  simonb     *                  field).  The value is right justified.
     61  1.3  simonb     *
     62  1.3  simonb     *  V_xxx           "Value" constant.  This is the same as the
     63  1.3  simonb     *                  corresponding "K_xxx" constant, except it is
     64  1.3  simonb     *                  shifted to the correct position in the register.
     65  1.3  simonb     *
     66  1.3  simonb     *  S_xxx           SHIFT constant.  This is the number of bits that
     67  1.3  simonb     *                  a field value (code) needs to be shifted
     68  1.3  simonb     *                  (towards the left) to put the value in the right
     69  1.3  simonb     *                  position for the register.
     70  1.3  simonb     *
     71  1.3  simonb     *  A_xxx           ADDRESS constant.  This will be a physical
     72  1.3  simonb     *                  address.  Use the PHYS_TO_K1 macro to generate
     73  1.3  simonb     *                  a K1SEG address.
     74  1.3  simonb     *
     75  1.3  simonb     *  R_xxx           RELATIVE offset constant.  This is an offset from
     76  1.3  simonb     *                  an A_xxx constant (usually the first register in
     77  1.3  simonb     *                  a group).
     78  1.3  simonb     *
     79  1.3  simonb     *  G_xxx(X)        GET value.  This macro obtains a multi-bit field
     80  1.3  simonb     *                  from a register, masks it, and shifts it to
     81  1.3  simonb     *                  the bottom of the register (retrieving a K_xxx
     82  1.3  simonb     *                  value, for example).
     83  1.3  simonb     *
     84  1.3  simonb     *  V_xxx(X)        VALUE.  This macro computes the value of a
     85  1.3  simonb     *                  K_xxx constant shifted to the correct position
     86  1.3  simonb     *                  in the register.
     87  1.1  simonb     ********************************************************************* */
     88  1.1  simonb 
     89  1.1  simonb 
     90  1.1  simonb 
     91  1.1  simonb 
     92  1.1  simonb #ifndef _SB1250_DEFS_H
     93  1.3  simonb #define _SB1250_DEFS_H
     94  1.1  simonb 
     95  1.1  simonb /*
     96  1.3  simonb  * Cast to 64-bit number.  Presumably the syntax is different in
     97  1.1  simonb  * assembly language.
     98  1.1  simonb  *
     99  1.1  simonb  * Note: you'll need to define uint32_t and uint64_t in your headers.
    100  1.1  simonb  */
    101  1.1  simonb 
    102  1.1  simonb #if !defined(__ASSEMBLER__)
    103  1.3  simonb #define _SB_MAKE64(x) ((uint64_t)(x))
    104  1.3  simonb #define _SB_MAKE32(x) ((uint32_t)(x))
    105  1.1  simonb #else
    106  1.3  simonb #define _SB_MAKE64(x) (x)
    107  1.3  simonb #define _SB_MAKE32(x) (x)
    108  1.1  simonb #endif
    109  1.1  simonb 
    110  1.1  simonb 
    111  1.1  simonb /*
    112  1.1  simonb  * Make a mask for 1 bit at position 'n'
    113  1.1  simonb  */
    114  1.1  simonb 
    115  1.3  simonb #define _SB_MAKEMASK1(n) (_SB_MAKE64(1) << _SB_MAKE64(n))
    116  1.3  simonb #define _SB_MAKEMASK1_32(n) (_SB_MAKE32(1) << _SB_MAKE32(n))
    117  1.1  simonb 
    118  1.1  simonb /*
    119  1.1  simonb  * Make a mask for 'v' bits at position 'n'
    120  1.1  simonb  */
    121  1.1  simonb 
    122  1.3  simonb #define _SB_MAKEMASK(v,n) (_SB_MAKE64((_SB_MAKE64(1)<<(v))-1) << _SB_MAKE64(n))
    123  1.3  simonb #define _SB_MAKEMASK_32(v,n) (_SB_MAKE32((_SB_MAKE32(1)<<(v))-1) << _SB_MAKE32(n))
    124  1.1  simonb 
    125  1.1  simonb /*
    126  1.1  simonb  * Make a value at 'v' at bit position 'n'
    127  1.1  simonb  */
    128  1.1  simonb 
    129  1.3  simonb #define _SB_MAKEVALUE(v,n) (_SB_MAKE64(v) << _SB_MAKE64(n))
    130  1.3  simonb #define _SB_MAKEVALUE_32(v,n) (_SB_MAKE32(v) << _SB_MAKE32(n))
    131  1.1  simonb 
    132  1.3  simonb #define _SB_GETVALUE(v,n,m) ((_SB_MAKE64(v) & _SB_MAKE64(m)) >> _SB_MAKE64(n))
    133  1.3  simonb #define _SB_GETVALUE_32(v,n,m) ((_SB_MAKE32(v) & _SB_MAKE32(m)) >> _SB_MAKE32(n))
    134  1.1  simonb 
    135  1.1  simonb /*
    136  1.1  simonb  * Macros to read/write on-chip registers
    137  1.3  simonb  * XXX should we do the PHYS_TO_K1 here?
    138  1.1  simonb  */
    139  1.1  simonb 
    140  1.1  simonb 
    141  1.1  simonb #if !defined(__ASSEMBLER__)
    142  1.3  simonb #define SBWRITECSR(csr,val) *((volatile uint64_t *) MIPS_PHYS_TO_KSEG1(csr)) = (val)
    143  1.3  simonb #define SBREADCSR(csr) (*((volatile uint64_t *) MIPS_PHYS_TO_KSEG1(csr)))
    144  1.1  simonb #endif /* __ASSEMBLER__ */
    145  1.1  simonb 
    146  1.1  simonb #endif
    147