sb1250_defs.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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
  12. *
  13. *********************************************************************
  14. *
  15. * Copyright 2000,2001,2002,2003
  16. * Broadcom Corporation. All rights reserved.
  17. *
  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.
  22. *
  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.
  27. *
  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,
  31. * MA 02111-1307 USA
  32. ********************************************************************* */
  33. #ifndef _SB1250_DEFS_H
  34. #define _SB1250_DEFS_H
  35. /*
  36. * These headers require ANSI C89 string concatenation, and GCC or other
  37. * 'long long' (64-bit integer) support.
  38. */
  39. #if !defined(__STDC__) && !defined(_MSC_VER)
  40. #error SiByte headers require ANSI C89 support
  41. #endif
  42. /* *********************************************************************
  43. * Macros for feature tests, used to enable include file features
  44. * for chip features only present in certain chip revisions.
  45. *
  46. * SIBYTE_HDR_FEATURES may be defined to be the mask value chip/revision
  47. * which is to be exposed by the headers. If undefined, it defaults to
  48. * "all features."
  49. *
  50. * Use like:
  51. *
  52. * #define SIBYTE_HDR_FEATURES SIBYTE_HDR_FMASK_112x_PASS1
  53. *
  54. * Generate defines only for that revision of chip.
  55. *
  56. * #if SIBYTE_HDR_FEATURE(chip,pass)
  57. *
  58. * True if header features for that revision or later of
  59. * that particular chip type are enabled in SIBYTE_HDR_FEATURES.
  60. * (Use this to bracket #defines for features present in a given
  61. * revision and later.)
  62. *
  63. * Note that there is no implied ordering between chip types.
  64. *
  65. * Note also that 'chip' and 'pass' must textually exactly
  66. * match the defines below. So, for example,
  67. * SIBYTE_HDR_FEATURE(112x, PASS1) is OK, but
  68. * SIBYTE_HDR_FEATURE(1120, pass1) is not (for two reasons).
  69. *
  70. * #if SIBYTE_HDR_FEATURE_UP_TO(chip,pass)
  71. *
  72. * Same as SIBYTE_HDR_FEATURE, but true for the named revision
  73. * and earlier revisions of the named chip type.
  74. *
  75. * #if SIBYTE_HDR_FEATURE_EXACT(chip,pass)
  76. *
  77. * Same as SIBYTE_HDR_FEATURE, but only true for the named
  78. * revision of the named chip type. (Note that this CANNOT
  79. * be used to verify that you're compiling only for that
  80. * particular chip/revision. It will be true any time this
  81. * chip/revision is included in SIBYTE_HDR_FEATURES.)
  82. *
  83. * #if SIBYTE_HDR_FEATURE_CHIP(chip)
  84. *
  85. * True if header features for (any revision of) that chip type
  86. * are enabled in SIBYTE_HDR_FEATURES. (Use this to bracket
  87. * #defines for features specific to a given chip type.)
  88. *
  89. * Mask values currently include room for additional revisions of each
  90. * chip type, but can be renumbered at will. Note that they MUST fit
  91. * into 31 bits and may not include C type constructs, for safe use in
  92. * CPP conditionals. Bit positions within chip types DO indicate
  93. * ordering, so be careful when adding support for new minor revs.
  94. ********************************************************************* */
  95. #define SIBYTE_HDR_FMASK_1250_ALL 0x00000ff
  96. #define SIBYTE_HDR_FMASK_1250_PASS1 0x0000001
  97. #define SIBYTE_HDR_FMASK_1250_PASS2 0x0000002
  98. #define SIBYTE_HDR_FMASK_1250_PASS3 0x0000004
  99. #define SIBYTE_HDR_FMASK_112x_ALL 0x0000f00
  100. #define SIBYTE_HDR_FMASK_112x_PASS1 0x0000100
  101. /* Bit mask for chip/revision. (use _ALL for all revisions of a chip). */
  102. #define SIBYTE_HDR_FMASK(chip, pass) \
  103. (SIBYTE_HDR_FMASK_ ## chip ## _ ## pass)
  104. #define SIBYTE_HDR_FMASK_ALLREVS(chip) \
  105. (SIBYTE_HDR_FMASK_ ## chip ## _ALL)
  106. #define SIBYTE_HDR_FMASK_ALL \
  107. (SIBYTE_HDR_FMASK_1250_ALL | SIBYTE_HDR_FMASK_112x_ALL)
  108. #ifndef SIBYTE_HDR_FEATURES
  109. #define SIBYTE_HDR_FEATURES SIBYTE_HDR_FMASK_ALL
  110. #endif
  111. /* Bit mask for revisions of chip exclusively before the named revision. */
  112. #define SIBYTE_HDR_FMASK_BEFORE(chip, pass) \
  113. ((SIBYTE_HDR_FMASK(chip, pass) - 1) & SIBYTE_HDR_FMASK_ALLREVS(chip))
  114. /* Bit mask for revisions of chip exclusively after the named revision. */
  115. #define SIBYTE_HDR_FMASK_AFTER(chip, pass) \
  116. (~(SIBYTE_HDR_FMASK(chip, pass) \
  117. | (SIBYTE_HDR_FMASK(chip, pass) - 1)) & SIBYTE_HDR_FMASK_ALLREVS(chip))
  118. /* True if header features enabled for (any revision of) that chip type. */
  119. #define SIBYTE_HDR_FEATURE_CHIP(chip) \
  120. (!! (SIBYTE_HDR_FMASK_ALLREVS(chip) & SIBYTE_HDR_FEATURES))
  121. /* True if header features enabled for that rev or later, inclusive. */
  122. #define SIBYTE_HDR_FEATURE(chip, pass) \
  123. (!! ((SIBYTE_HDR_FMASK(chip, pass) \
  124. | SIBYTE_HDR_FMASK_AFTER(chip, pass)) & SIBYTE_HDR_FEATURES))
  125. /* True if header features enabled for exactly that rev. */
  126. #define SIBYTE_HDR_FEATURE_EXACT(chip, pass) \
  127. (!! (SIBYTE_HDR_FMASK(chip, pass) & SIBYTE_HDR_FEATURES))
  128. /* True if header features enabled for that rev or before, inclusive. */
  129. #define SIBYTE_HDR_FEATURE_UP_TO(chip, pass) \
  130. (!! ((SIBYTE_HDR_FMASK(chip, pass) \
  131. | SIBYTE_HDR_FMASK_BEFORE(chip, pass)) & SIBYTE_HDR_FEATURES))
  132. /* *********************************************************************
  133. * Naming schemes for constants in these files:
  134. *
  135. * M_xxx MASK constant (identifies bits in a register).
  136. * For multi-bit fields, all bits in the field will
  137. * be set.
  138. *
  139. * K_xxx "Code" constant (value for data in a multi-bit
  140. * field). The value is right justified.
  141. *
  142. * V_xxx "Value" constant. This is the same as the
  143. * corresponding "K_xxx" constant, except it is
  144. * shifted to the correct position in the register.
  145. *
  146. * S_xxx SHIFT constant. This is the number of bits that
  147. * a field value (code) needs to be shifted
  148. * (towards the left) to put the value in the right
  149. * position for the register.
  150. *
  151. * A_xxx ADDRESS constant. This will be a physical
  152. * address. Use the PHYS_TO_K1 macro to generate
  153. * a K1SEG address.
  154. *
  155. * R_xxx RELATIVE offset constant. This is an offset from
  156. * an A_xxx constant (usually the first register in
  157. * a group).
  158. *
  159. * G_xxx(X) GET value. This macro obtains a multi-bit field
  160. * from a register, masks it, and shifts it to
  161. * the bottom of the register (retrieving a K_xxx
  162. * value, for example).
  163. *
  164. * V_xxx(X) VALUE. This macro computes the value of a
  165. * K_xxx constant shifted to the correct position
  166. * in the register.
  167. ********************************************************************* */
  168. /*
  169. * Cast to 64-bit number. Presumably the syntax is different in
  170. * assembly language.
  171. *
  172. * Note: you'll need to define uint32_t and uint64_t in your headers.
  173. */
  174. #if !defined(__ASSEMBLER__)
  175. #define _SB_MAKE64(x) ((uint64_t)(x))
  176. #define _SB_MAKE32(x) ((uint32_t)(x))
  177. #else
  178. #define _SB_MAKE64(x) (x)
  179. #define _SB_MAKE32(x) (x)
  180. #endif
  181. /*
  182. * Make a mask for 1 bit at position 'n'
  183. */
  184. #define _SB_MAKEMASK1(n) (_SB_MAKE64(1) << _SB_MAKE64(n))
  185. #define _SB_MAKEMASK1_32(n) (_SB_MAKE32(1) << _SB_MAKE32(n))
  186. /*
  187. * Make a mask for 'v' bits at position 'n'
  188. */
  189. #define _SB_MAKEMASK(v,n) (_SB_MAKE64((_SB_MAKE64(1)<<(v))-1) << _SB_MAKE64(n))
  190. #define _SB_MAKEMASK_32(v,n) (_SB_MAKE32((_SB_MAKE32(1)<<(v))-1) << _SB_MAKE32(n))
  191. /*
  192. * Make a value at 'v' at bit position 'n'
  193. */
  194. #define _SB_MAKEVALUE(v,n) (_SB_MAKE64(v) << _SB_MAKE64(n))
  195. #define _SB_MAKEVALUE_32(v,n) (_SB_MAKE32(v) << _SB_MAKE32(n))
  196. #define _SB_GETVALUE(v,n,m) ((_SB_MAKE64(v) & _SB_MAKE64(m)) >> _SB_MAKE64(n))
  197. #define _SB_GETVALUE_32(v,n,m) ((_SB_MAKE32(v) & _SB_MAKE32(m)) >> _SB_MAKE32(n))
  198. /*
  199. * Macros to read/write on-chip registers
  200. * XXX should we do the PHYS_TO_K1 here?
  201. */
  202. #if defined(__mips64) && !defined(__ASSEMBLER__)
  203. #define SBWRITECSR(csr,val) *((volatile uint64_t *) PHYS_TO_K1(csr)) = (val)
  204. #define SBREADCSR(csr) (*((volatile uint64_t *) PHYS_TO_K1(csr)))
  205. #endif /* __ASSEMBLER__ */
  206. #endif