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