1 /* *********************************************************************
2 * SB1250 Board Support Package
4 * Global constants and macros File: sb1250_defs.h
6 * This file contains macros and definitions used by the other
9 * SB1250 specification level: User's manual 1/02/02
11 * Author: Mitch Lichtenberg (mpl@broadcom.com)
13 *********************************************************************
16 * Broadcom Corporation. All rights reserved.
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License as
20 * published by the Free Software Foundation; either version 2 of
21 * the License, or (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 ********************************************************************* */
35 /* *********************************************************************
36 * Naming schemes for constants in these files:
38 * M_xxx MASK constant (identifies bits in a register).
39 * For multi-bit fields, all bits in the field will
42 * K_xxx "Code" constant (value for data in a multi-bit
43 * field). The value is right justified.
45 * V_xxx "Value" constant. This is the same as the
46 * corresponding "K_xxx" constant, except it is
47 * shifted to the correct position in the register.
49 * S_xxx SHIFT constant. This is the number of bits that
50 * a field value (code) needs to be shifted
51 * (towards the left) to put the value in the right
52 * position for the register.
54 * A_xxx ADDRESS constant. This will be a physical
55 * address. Use the PHYS_TO_K1 macro to generate
58 * R_xxx RELATIVE offset constant. This is an offset from
59 * an A_xxx constant (usually the first register in
62 * G_xxx(X) GET value. This macro obtains a multi-bit field
63 * from a register, masks it, and shifts it to
64 * the bottom of the register (retrieving a K_xxx
65 * value, for example).
67 * V_xxx(X) VALUE. This macro computes the value of a
68 * K_xxx constant shifted to the correct position
70 ********************************************************************* */
75 #ifndef _SB1250_DEFS_H
76 #define _SB1250_DEFS_H
79 * Cast to 64-bit number. Presumably the syntax is different in
82 * Note: you'll need to define uint32_t and uint64_t in your headers.
85 #if !defined(__ASSEMBLY__)
86 #define _SB_MAKE64(x) ((uint64_t)(x))
87 #define _SB_MAKE32(x) ((uint32_t)(x))
89 #define _SB_MAKE64(x) (x)
90 #define _SB_MAKE32(x) (x)
95 * Make a mask for 1 bit at position 'n'
98 #define _SB_MAKEMASK1(n) (_SB_MAKE64(1) << _SB_MAKE64(n))
99 #define _SB_MAKEMASK1_32(n) (_SB_MAKE32(1) << _SB_MAKE32(n))
102 * Make a mask for 'v' bits at position 'n'
105 #define _SB_MAKEMASK(v,n) (_SB_MAKE64((_SB_MAKE64(1)<<(v))-1) << _SB_MAKE64(n))
106 #define _SB_MAKEMASK_32(v,n) (_SB_MAKE32((_SB_MAKE32(1)<<(v))-1) << _SB_MAKE32(n))
109 * Make a value at 'v' at bit position 'n'
112 #define _SB_MAKEVALUE(v,n) (_SB_MAKE64(v) << _SB_MAKE64(n))
113 #define _SB_MAKEVALUE_32(v,n) (_SB_MAKE32(v) << _SB_MAKE32(n))
115 #define _SB_GETVALUE(v,n,m) ((_SB_MAKE64(v) & _SB_MAKE64(m)) >> _SB_MAKE64(n))
116 #define _SB_GETVALUE_32(v,n,m) ((_SB_MAKE32(v) & _SB_MAKE32(m)) >> _SB_MAKE32(n))
119 * Macros to read/write on-chip registers
120 * XXX should we do the PHYS_TO_K1 here?
124 #if !defined(__ASSEMBLY__)
125 #define SBWRITECSR(csr,val) *((volatile uint64_t *) PHYS_TO_K1(csr)) = (val)
126 #define SBREADCSR(csr) (*((volatile uint64_t *) PHYS_TO_K1(csr)))
127 #endif /* __ASSEMBLY__ */