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