octeon-model.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /***********************license start***************
  2. * Author: Cavium Networks
  3. *
  4. * Contact: support@caviumnetworks.com
  5. * This file is part of the OCTEON SDK
  6. *
  7. * Copyright (c) 2003-2008 Cavium Networks
  8. *
  9. * This file is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License, Version 2, as
  11. * published by the Free Software Foundation.
  12. *
  13. * This file is distributed in the hope that it will be useful, but
  14. * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  16. * NONINFRINGEMENT. See the GNU General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this file; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. * or visit http://www.gnu.org/licenses/.
  23. *
  24. * This file may also be available under a different license from Cavium.
  25. * Contact Cavium Networks for more information
  26. ***********************license end**************************************/
  27. /*
  28. *
  29. * File defining different Octeon model IDs and macros to
  30. * compare them.
  31. *
  32. */
  33. #ifndef __OCTEON_MODEL_H__
  34. #define __OCTEON_MODEL_H__
  35. /*
  36. * The defines below should be used with the OCTEON_IS_MODEL() macro
  37. * to determine what model of chip the software is running on. Models
  38. * ending in 'XX' match multiple models (families), while specific
  39. * models match only that model. If a pass (revision) is specified,
  40. * then only that revision will be matched. Care should be taken when
  41. * checking for both specific models and families that the specific
  42. * models are checked for first. While these defines are similar to
  43. * the processor ID, they are not intended to be used by anything
  44. * other that the OCTEON_IS_MODEL framework, and the values are
  45. * subject to change at anytime without notice.
  46. *
  47. * NOTE: only the OCTEON_IS_MODEL() macro/function and the OCTEON_CN*
  48. * macros should be used outside of this file. All other macros are
  49. * for internal use only, and may change without notice.
  50. */
  51. /* Flag bits in top byte */
  52. /* Ignores revision in model checks */
  53. #define OM_IGNORE_REVISION 0x01000000
  54. /* Check submodels */
  55. #define OM_CHECK_SUBMODEL 0x02000000
  56. /* Match all models previous than the one specified */
  57. #define OM_MATCH_PREVIOUS_MODELS 0x04000000
  58. /* Ignores the minor revison on newer parts */
  59. #define OM_IGNORE_MINOR_REVISION 0x08000000
  60. #define OM_FLAG_MASK 0xff000000
  61. #define OM_MATCH_5XXX_FAMILY_MODELS 0x20000000 /* Match all cn5XXX Octeon models. */
  62. #define OM_MATCH_6XXX_FAMILY_MODELS 0x40000000 /* Match all cn6XXX Octeon models. */
  63. /*
  64. * CN6XXX models with new revision encoding
  65. */
  66. #define OCTEON_CN63XX_PASS1_0 0x000d9000
  67. #define OCTEON_CN63XX_PASS1_1 0x000d9001
  68. #define OCTEON_CN63XX_PASS1_2 0x000d9002
  69. #define OCTEON_CN63XX_PASS2_0 0x000d9008
  70. #define OCTEON_CN63XX (OCTEON_CN63XX_PASS2_0 | OM_IGNORE_REVISION)
  71. #define OCTEON_CN63XX_PASS1_X (OCTEON_CN63XX_PASS1_0 | OM_IGNORE_MINOR_REVISION)
  72. #define OCTEON_CN63XX_PASS2_X (OCTEON_CN63XX_PASS2_0 | OM_IGNORE_MINOR_REVISION)
  73. /*
  74. * CN5XXX models with new revision encoding
  75. */
  76. #define OCTEON_CN58XX_PASS1_0 0x000d0300
  77. #define OCTEON_CN58XX_PASS1_1 0x000d0301
  78. #define OCTEON_CN58XX_PASS1_2 0x000d0303
  79. #define OCTEON_CN58XX_PASS2_0 0x000d0308
  80. #define OCTEON_CN58XX_PASS2_1 0x000d0309
  81. #define OCTEON_CN58XX_PASS2_2 0x000d030a
  82. #define OCTEON_CN58XX_PASS2_3 0x000d030b
  83. #define OCTEON_CN58XX (OCTEON_CN58XX_PASS1_0 | OM_IGNORE_REVISION)
  84. #define OCTEON_CN58XX_PASS1_X (OCTEON_CN58XX_PASS1_0 \
  85. | OM_IGNORE_MINOR_REVISION)
  86. #define OCTEON_CN58XX_PASS2_X (OCTEON_CN58XX_PASS2_0 \
  87. | OM_IGNORE_MINOR_REVISION)
  88. #define OCTEON_CN58XX_PASS1 OCTEON_CN58XX_PASS1_X
  89. #define OCTEON_CN58XX_PASS2 OCTEON_CN58XX_PASS2_X
  90. #define OCTEON_CN56XX_PASS1_0 0x000d0400
  91. #define OCTEON_CN56XX_PASS1_1 0x000d0401
  92. #define OCTEON_CN56XX_PASS2_0 0x000d0408
  93. #define OCTEON_CN56XX_PASS2_1 0x000d0409
  94. #define OCTEON_CN56XX (OCTEON_CN56XX_PASS2_0 | OM_IGNORE_REVISION)
  95. #define OCTEON_CN56XX_PASS1_X (OCTEON_CN56XX_PASS1_0 \
  96. | OM_IGNORE_MINOR_REVISION)
  97. #define OCTEON_CN56XX_PASS2_X (OCTEON_CN56XX_PASS2_0 \
  98. | OM_IGNORE_MINOR_REVISION)
  99. #define OCTEON_CN56XX_PASS1 OCTEON_CN56XX_PASS1_X
  100. #define OCTEON_CN56XX_PASS2 OCTEON_CN56XX_PASS2_X
  101. #define OCTEON_CN57XX OCTEON_CN56XX
  102. #define OCTEON_CN57XX_PASS1 OCTEON_CN56XX_PASS1
  103. #define OCTEON_CN57XX_PASS2 OCTEON_CN56XX_PASS2
  104. #define OCTEON_CN55XX OCTEON_CN56XX
  105. #define OCTEON_CN55XX_PASS1 OCTEON_CN56XX_PASS1
  106. #define OCTEON_CN55XX_PASS2 OCTEON_CN56XX_PASS2
  107. #define OCTEON_CN54XX OCTEON_CN56XX
  108. #define OCTEON_CN54XX_PASS1 OCTEON_CN56XX_PASS1
  109. #define OCTEON_CN54XX_PASS2 OCTEON_CN56XX_PASS2
  110. #define OCTEON_CN50XX_PASS1_0 0x000d0600
  111. #define OCTEON_CN50XX (OCTEON_CN50XX_PASS1_0 | OM_IGNORE_REVISION)
  112. #define OCTEON_CN50XX_PASS1_X (OCTEON_CN50XX_PASS1_0 \
  113. | OM_IGNORE_MINOR_REVISION)
  114. #define OCTEON_CN50XX_PASS1 OCTEON_CN50XX_PASS1_X
  115. /*
  116. * NOTE: Octeon CN5000F model is not identifiable using the
  117. * OCTEON_IS_MODEL() functions, but are treated as CN50XX.
  118. */
  119. #define OCTEON_CN52XX_PASS1_0 0x000d0700
  120. #define OCTEON_CN52XX_PASS2_0 0x000d0708
  121. #define OCTEON_CN52XX (OCTEON_CN52XX_PASS2_0 | OM_IGNORE_REVISION)
  122. #define OCTEON_CN52XX_PASS1_X (OCTEON_CN52XX_PASS1_0 \
  123. | OM_IGNORE_MINOR_REVISION)
  124. #define OCTEON_CN52XX_PASS2_X (OCTEON_CN52XX_PASS2_0 \
  125. | OM_IGNORE_MINOR_REVISION)
  126. #define OCTEON_CN52XX_PASS1 OCTEON_CN52XX_PASS1_X
  127. #define OCTEON_CN52XX_PASS2 OCTEON_CN52XX_PASS2_X
  128. /*
  129. * CN3XXX models with old revision enconding
  130. */
  131. #define OCTEON_CN38XX_PASS1 0x000d0000
  132. #define OCTEON_CN38XX_PASS2 0x000d0001
  133. #define OCTEON_CN38XX_PASS3 0x000d0003
  134. #define OCTEON_CN38XX (OCTEON_CN38XX_PASS3 | OM_IGNORE_REVISION)
  135. #define OCTEON_CN36XX OCTEON_CN38XX
  136. #define OCTEON_CN36XX_PASS2 OCTEON_CN38XX_PASS2
  137. #define OCTEON_CN36XX_PASS3 OCTEON_CN38XX_PASS3
  138. /* The OCTEON_CN31XX matches CN31XX models and the CN3020 */
  139. #define OCTEON_CN31XX_PASS1 0x000d0100
  140. #define OCTEON_CN31XX_PASS1_1 0x000d0102
  141. #define OCTEON_CN31XX (OCTEON_CN31XX_PASS1 | OM_IGNORE_REVISION)
  142. /*
  143. * This model is only used for internal checks, it is not a valid
  144. * model for the OCTEON_MODEL environment variable. This matches the
  145. * CN3010 and CN3005 but NOT the CN3020.
  146. */
  147. #define OCTEON_CN30XX_PASS1 0x000d0200
  148. #define OCTEON_CN30XX_PASS1_1 0x000d0202
  149. #define OCTEON_CN30XX (OCTEON_CN30XX_PASS1 | OM_IGNORE_REVISION)
  150. #define OCTEON_CN3005_PASS1 (0x000d0210 | OM_CHECK_SUBMODEL)
  151. #define OCTEON_CN3005_PASS1_0 (0x000d0210 | OM_CHECK_SUBMODEL)
  152. #define OCTEON_CN3005_PASS1_1 (0x000d0212 | OM_CHECK_SUBMODEL)
  153. #define OCTEON_CN3005 (OCTEON_CN3005_PASS1 | OM_IGNORE_REVISION \
  154. | OM_CHECK_SUBMODEL)
  155. #define OCTEON_CN3010_PASS1 (0x000d0200 | OM_CHECK_SUBMODEL)
  156. #define OCTEON_CN3010_PASS1_0 (0x000d0200 | OM_CHECK_SUBMODEL)
  157. #define OCTEON_CN3010_PASS1_1 (0x000d0202 | OM_CHECK_SUBMODEL)
  158. #define OCTEON_CN3010 (OCTEON_CN3010_PASS1 | OM_IGNORE_REVISION \
  159. | OM_CHECK_SUBMODEL)
  160. #define OCTEON_CN3020_PASS1 (0x000d0110 | OM_CHECK_SUBMODEL)
  161. #define OCTEON_CN3020_PASS1_0 (0x000d0110 | OM_CHECK_SUBMODEL)
  162. #define OCTEON_CN3020_PASS1_1 (0x000d0112 | OM_CHECK_SUBMODEL)
  163. #define OCTEON_CN3020 (OCTEON_CN3020_PASS1 | OM_IGNORE_REVISION \
  164. | OM_CHECK_SUBMODEL)
  165. /* This matches the complete family of CN3xxx CPUs, and not subsequent models */
  166. #define OCTEON_CN3XXX (OCTEON_CN58XX_PASS1_0 \
  167. | OM_MATCH_PREVIOUS_MODELS \
  168. | OM_IGNORE_REVISION)
  169. #define OCTEON_CN5XXX (OCTEON_CN58XX_PASS1_0 | OM_MATCH_5XXX_FAMILY_MODELS)
  170. #define OCTEON_CN6XXX (OCTEON_CN63XX_PASS1_0 | OM_MATCH_6XXX_FAMILY_MODELS)
  171. /* The revision byte (low byte) has two different encodings.
  172. * CN3XXX:
  173. *
  174. * bits
  175. * <7:5>: reserved (0)
  176. * <4>: alternate package
  177. * <3:0>: revision
  178. *
  179. * CN5XXX:
  180. *
  181. * bits
  182. * <7>: reserved (0)
  183. * <6>: alternate package
  184. * <5:3>: major revision
  185. * <2:0>: minor revision
  186. *
  187. */
  188. /* Masks used for the various types of model/family/revision matching */
  189. #define OCTEON_38XX_FAMILY_MASK 0x00ffff00
  190. #define OCTEON_38XX_FAMILY_REV_MASK 0x00ffff0f
  191. #define OCTEON_38XX_MODEL_MASK 0x00ffff10
  192. #define OCTEON_38XX_MODEL_REV_MASK (OCTEON_38XX_FAMILY_REV_MASK \
  193. | OCTEON_38XX_MODEL_MASK)
  194. /* CN5XXX and later use different layout of bits in the revision ID field */
  195. #define OCTEON_58XX_FAMILY_MASK OCTEON_38XX_FAMILY_MASK
  196. #define OCTEON_58XX_FAMILY_REV_MASK 0x00ffff3f
  197. #define OCTEON_58XX_MODEL_MASK 0x00ffffc0
  198. #define OCTEON_58XX_MODEL_REV_MASK (OCTEON_58XX_FAMILY_REV_MASK \
  199. | OCTEON_58XX_MODEL_MASK)
  200. #define OCTEON_58XX_MODEL_MINOR_REV_MASK (OCTEON_58XX_MODEL_REV_MASK \
  201. & 0x00fffff8)
  202. #define OCTEON_5XXX_MODEL_MASK 0x00ff0fc0
  203. #define __OCTEON_MATCH_MASK__(x, y, z) (((x) & (z)) == ((y) & (z)))
  204. /* NOTE: This is for internal (to this file) use only. */
  205. static inline int __OCTEON_IS_MODEL_COMPILE__(uint32_t arg_model,
  206. uint32_t chip_model)
  207. {
  208. uint32_t rev_and_sub = OM_IGNORE_REVISION | OM_CHECK_SUBMODEL;
  209. if ((arg_model & OCTEON_38XX_FAMILY_MASK) < OCTEON_CN58XX_PASS1_0) {
  210. if (((arg_model & OM_FLAG_MASK) == rev_and_sub) &&
  211. __OCTEON_MATCH_MASK__(chip_model, arg_model,
  212. OCTEON_38XX_MODEL_MASK))
  213. return 1;
  214. if (((arg_model & OM_FLAG_MASK) == 0) &&
  215. __OCTEON_MATCH_MASK__(chip_model, arg_model,
  216. OCTEON_38XX_FAMILY_REV_MASK))
  217. return 1;
  218. if (((arg_model & OM_FLAG_MASK) == OM_IGNORE_REVISION) &&
  219. __OCTEON_MATCH_MASK__(chip_model, arg_model,
  220. OCTEON_38XX_FAMILY_MASK))
  221. return 1;
  222. if (((arg_model & OM_FLAG_MASK) == OM_CHECK_SUBMODEL) &&
  223. __OCTEON_MATCH_MASK__((chip_model), (arg_model),
  224. OCTEON_38XX_MODEL_REV_MASK))
  225. return 1;
  226. if ((arg_model & OM_MATCH_PREVIOUS_MODELS) &&
  227. ((chip_model & OCTEON_38XX_MODEL_MASK) <
  228. (arg_model & OCTEON_38XX_MODEL_MASK)))
  229. return 1;
  230. } else {
  231. if (((arg_model & OM_FLAG_MASK) == rev_and_sub) &&
  232. __OCTEON_MATCH_MASK__((chip_model), (arg_model),
  233. OCTEON_58XX_MODEL_MASK))
  234. return 1;
  235. if (((arg_model & OM_FLAG_MASK) == 0) &&
  236. __OCTEON_MATCH_MASK__((chip_model), (arg_model),
  237. OCTEON_58XX_FAMILY_REV_MASK))
  238. return 1;
  239. if (((arg_model & OM_FLAG_MASK) == OM_IGNORE_MINOR_REVISION) &&
  240. __OCTEON_MATCH_MASK__((chip_model), (arg_model),
  241. OCTEON_58XX_MODEL_MINOR_REV_MASK))
  242. return 1;
  243. if (((arg_model & OM_FLAG_MASK) == OM_IGNORE_REVISION) &&
  244. __OCTEON_MATCH_MASK__((chip_model), (arg_model),
  245. OCTEON_58XX_FAMILY_MASK))
  246. return 1;
  247. if (((arg_model & OM_FLAG_MASK) == OM_CHECK_SUBMODEL) &&
  248. __OCTEON_MATCH_MASK__((chip_model), (arg_model),
  249. OCTEON_58XX_MODEL_REV_MASK))
  250. return 1;
  251. if (((arg_model & OM_MATCH_5XXX_FAMILY_MODELS) == OM_MATCH_5XXX_FAMILY_MODELS) &&
  252. ((chip_model) >= OCTEON_CN58XX_PASS1_0) && ((chip_model) < OCTEON_CN63XX_PASS1_0))
  253. return 1;
  254. if (((arg_model & OM_MATCH_6XXX_FAMILY_MODELS) == OM_MATCH_6XXX_FAMILY_MODELS) &&
  255. ((chip_model) >= OCTEON_CN63XX_PASS1_0))
  256. return 1;
  257. if ((arg_model & OM_MATCH_PREVIOUS_MODELS) &&
  258. ((chip_model & OCTEON_58XX_MODEL_MASK) <
  259. (arg_model & OCTEON_58XX_MODEL_MASK)))
  260. return 1;
  261. }
  262. return 0;
  263. }
  264. /* forward declarations */
  265. static inline uint32_t cvmx_get_proc_id(void) __attribute__ ((pure));
  266. static inline uint64_t cvmx_read_csr(uint64_t csr_addr);
  267. /* NOTE: This for internal use only!!!!! */
  268. static inline int __octeon_is_model_runtime__(uint32_t model)
  269. {
  270. uint32_t cpuid = cvmx_get_proc_id();
  271. /*
  272. * Check for special case of mismarked 3005 samples. We only
  273. * need to check if the sub model isn't being ignored.
  274. */
  275. if ((model & OM_CHECK_SUBMODEL) == OM_CHECK_SUBMODEL) {
  276. if (cpuid == OCTEON_CN3010_PASS1 \
  277. && (cvmx_read_csr(0x80011800800007B8ull) & (1ull << 34)))
  278. cpuid |= 0x10;
  279. }
  280. return __OCTEON_IS_MODEL_COMPILE__(model, cpuid);
  281. }
  282. /*
  283. * The OCTEON_IS_MODEL macro should be used for all Octeon model
  284. * checking done in a program. This should be kept runtime if at all
  285. * possible. Any compile time (#if OCTEON_IS_MODEL) usage must be
  286. * condtionalized with OCTEON_IS_COMMON_BINARY() if runtime checking
  287. * support is required.
  288. */
  289. #define OCTEON_IS_MODEL(x) __octeon_is_model_runtime__(x)
  290. #define OCTEON_IS_COMMON_BINARY() 1
  291. #undef OCTEON_MODEL
  292. const char *octeon_model_get_string(uint32_t chip_id);
  293. const char *octeon_model_get_string_buffer(uint32_t chip_id, char *buffer);
  294. #include "octeon-feature.h"
  295. #endif /* __OCTEON_MODEL_H__ */