sb1250_defs.h 9.6 KB

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