octeon-model.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2020 Marvell International Ltd.
  4. */
  5. #ifndef __OCTEON_MODEL_H__
  6. #define __OCTEON_MODEL_H__
  7. /*
  8. * NOTE: These must match what is checked in common-config.mk
  9. * Defines to represent the different versions of Octeon.
  10. *
  11. * IMPORTANT: When the default pass is updated for an Octeon Model,
  12. * the corresponding change must also be made in the oct-sim script.
  13. *
  14. * The defines below should be used with the OCTEON_IS_MODEL() macro to
  15. * determine what model of chip the software is running on. Models ending
  16. * in 'XX' match multiple models (families), while specific models match only
  17. * that model. If a pass (revision) is specified, then only that revision
  18. * will be matched. Care should be taken when checking for both specific
  19. * models and families that the specific models are checked for first.
  20. * While these defines are similar to the processor ID, they are not intended
  21. * to be used by anything other that the OCTEON_IS_MODEL framework, and
  22. * the values are subject to change at anytime without notice.
  23. *
  24. * NOTE: only the OCTEON_IS_MODEL() macro/function and the OCTEON_CN* macros
  25. * should be used outside of this file. All other macros are for internal
  26. * use only, and may change without notice.
  27. */
  28. #include <asm/mipsregs.h>
  29. #define OCTEON_FAMILY_MASK 0x00ffff00
  30. #define OCTEON_PRID_MASK 0x00ffffff
  31. /* Flag bits in top byte */
  32. /* Ignores revision in model checks */
  33. #define OM_IGNORE_REVISION 0x01000000
  34. /* Check submodels */
  35. #define OM_CHECK_SUBMODEL 0x02000000
  36. /* Match all models previous than the one specified */
  37. #define OM_MATCH_PREVIOUS_MODELS 0x04000000
  38. /* Ignores the minor revison on newer parts */
  39. #define OM_IGNORE_MINOR_REVISION 0x08000000
  40. #define OM_FLAG_MASK 0xff000000
  41. /* Match all cn5XXX Octeon models. */
  42. #define OM_MATCH_5XXX_FAMILY_MODELS 0x20000000
  43. /* Match all cn6XXX Octeon models. */
  44. #define OM_MATCH_6XXX_FAMILY_MODELS 0x40000000
  45. /* Match all cnf7XXX Octeon models. */
  46. #define OM_MATCH_F7XXX_FAMILY_MODELS 0x80000000
  47. /* Match all cn7XXX Octeon models. */
  48. #define OM_MATCH_7XXX_FAMILY_MODELS 0x10000000
  49. #define OM_MATCH_FAMILY_MODELS (OM_MATCH_5XXX_FAMILY_MODELS | \
  50. OM_MATCH_6XXX_FAMILY_MODELS | \
  51. OM_MATCH_F7XXX_FAMILY_MODELS | \
  52. OM_MATCH_7XXX_FAMILY_MODELS)
  53. /*
  54. * CN7XXX models with new revision encoding
  55. */
  56. #define OCTEON_CNF75XX_PASS1_0 0x000d9800
  57. #define OCTEON_CNF75XX_PASS1_2 0x000d9802
  58. #define OCTEON_CNF75XX_PASS1_3 0x000d9803
  59. #define OCTEON_CNF75XX (OCTEON_CNF75XX_PASS1_0 | OM_IGNORE_REVISION)
  60. #define OCTEON_CNF75XX_PASS1_X \
  61. (OCTEON_CNF75XX_PASS1_0 | OM_IGNORE_MINOR_REVISION)
  62. #define OCTEON_CN73XX_PASS1_0 0x000d9700
  63. #define OCTEON_CN73XX_PASS1_1 0x000d9701
  64. #define OCTEON_CN73XX_PASS1_2 0x000d9702
  65. #define OCTEON_CN73XX_PASS1_3 0x000d9703
  66. #define OCTEON_CN73XX (OCTEON_CN73XX_PASS1_0 | OM_IGNORE_REVISION)
  67. #define OCTEON_CN73XX_PASS1_X \
  68. (OCTEON_CN73XX_PASS1_0 | OM_IGNORE_MINOR_REVISION)
  69. #define OCTEON_CN72XX OCTEON_CN73XX
  70. #define OCTEON_CN23XX OCTEON_CN73XX
  71. #define OCTEON_CN23XX_PASS1_2 OCTEON_CN73XX_PASS1_2
  72. #define OCTEON_CN23XX_PASS1_3 OCTEON_CN73XX_PASS1_3
  73. #define OCTEON_CN70XX_PASS1_0 0x000d9600
  74. #define OCTEON_CN70XX_PASS1_1 0x000d9601
  75. #define OCTEON_CN70XX_PASS1_2 0x000d9602
  76. #define OCTEON_CN70XX_PASS2_0 0x000d9608
  77. #define OCTEON_CN70XX (OCTEON_CN70XX_PASS1_0 | OM_IGNORE_REVISION)
  78. #define OCTEON_CN70XX_PASS1_X \
  79. (OCTEON_CN70XX_PASS1_0 | OM_IGNORE_MINOR_REVISION)
  80. #define OCTEON_CN70XX_PASS2_X \
  81. (OCTEON_CN70XX_PASS2_0 | OM_IGNORE_MINOR_REVISION)
  82. #define OCTEON_CN71XX OCTEON_CN70XX
  83. #define OCTEON_CN78XX_PASS1_0 0x000d9500
  84. #define OCTEON_CN78XX_PASS1_1 0x000d9501
  85. #define OCTEON_CN78XX_PASS2_0 0x000d9508
  86. #define OCTEON_CN78XX (OCTEON_CN78XX_PASS2_0 | OM_IGNORE_REVISION)
  87. #define OCTEON_CN78XX_PASS1_X \
  88. (OCTEON_CN78XX_PASS1_0 | OM_IGNORE_MINOR_REVISION)
  89. #define OCTEON_CN78XX_PASS2_X \
  90. (OCTEON_CN78XX_PASS2_0 | OM_IGNORE_MINOR_REVISION)
  91. #define OCTEON_CN76XX (0x000d9540 | OM_CHECK_SUBMODEL)
  92. /*
  93. * CNF7XXX models with new revision encoding
  94. */
  95. #define OCTEON_CNF71XX_PASS1_0 0x000d9400
  96. #define OCTEON_CNF71XX_PASS1_1 0x000d9401
  97. #define OCTEON_CNF71XX (OCTEON_CNF71XX_PASS1_0 | OM_IGNORE_REVISION)
  98. #define OCTEON_CNF71XX_PASS1_X \
  99. (OCTEON_CNF71XX_PASS1_0 | OM_IGNORE_MINOR_REVISION)
  100. /*
  101. * CN6XXX models with new revision encoding
  102. */
  103. #define OCTEON_CN68XX_PASS1_0 0x000d9100
  104. #define OCTEON_CN68XX_PASS1_1 0x000d9101
  105. #define OCTEON_CN68XX_PASS2_0 0x000d9108
  106. #define OCTEON_CN68XX_PASS2_1 0x000d9109
  107. #define OCTEON_CN68XX_PASS2_2 0x000d910a
  108. #define OCTEON_CN68XX (OCTEON_CN68XX_PASS2_0 | OM_IGNORE_REVISION)
  109. #define OCTEON_CN68XX_PASS1_X \
  110. (OCTEON_CN68XX_PASS1_0 | OM_IGNORE_MINOR_REVISION)
  111. #define OCTEON_CN68XX_PASS2_X \
  112. (OCTEON_CN68XX_PASS2_0 | OM_IGNORE_MINOR_REVISION)
  113. #define OCTEON_CN68XX_PASS1 OCTEON_CN68XX_PASS1_X
  114. #define OCTEON_CN68XX_PASS2 OCTEON_CN68XX_PASS2_X
  115. #define OCTEON_CN66XX_PASS1_0 0x000d9200
  116. #define OCTEON_CN66XX_PASS1_2 0x000d9202
  117. #define OCTEON_CN66XX (OCTEON_CN66XX_PASS1_0 | OM_IGNORE_REVISION)
  118. #define OCTEON_CN66XX_PASS1_X \
  119. (OCTEON_CN66XX_PASS1_0 | OM_IGNORE_MINOR_REVISION)
  120. #define OCTEON_CN63XX_PASS1_0 0x000d9000
  121. #define OCTEON_CN63XX_PASS1_1 0x000d9001
  122. #define OCTEON_CN63XX_PASS1_2 0x000d9002
  123. #define OCTEON_CN63XX_PASS2_0 0x000d9008
  124. #define OCTEON_CN63XX_PASS2_1 0x000d9009
  125. #define OCTEON_CN63XX_PASS2_2 0x000d900a
  126. #define OCTEON_CN63XX (OCTEON_CN63XX_PASS2_0 | OM_IGNORE_REVISION)
  127. #define OCTEON_CN63XX_PASS1_X \
  128. (OCTEON_CN63XX_PASS1_0 | OM_IGNORE_MINOR_REVISION)
  129. #define OCTEON_CN63XX_PASS2_X \
  130. (OCTEON_CN63XX_PASS2_0 | OM_IGNORE_MINOR_REVISION)
  131. /* CN62XX is same as CN63XX with 1 MB cache */
  132. #define OCTEON_CN62XX OCTEON_CN63XX
  133. #define OCTEON_CN61XX_PASS1_0 0x000d9300
  134. #define OCTEON_CN61XX_PASS1_1 0x000d9301
  135. #define OCTEON_CN61XX (OCTEON_CN61XX_PASS1_0 | OM_IGNORE_REVISION)
  136. #define OCTEON_CN61XX_PASS1_X \
  137. (OCTEON_CN61XX_PASS1_0 | OM_IGNORE_MINOR_REVISION)
  138. /* CN60XX is same as CN61XX with 512 KB cache */
  139. #define OCTEON_CN60XX OCTEON_CN61XX
  140. /* This matches the complete family of CN3xxx CPUs, and not subsequent models */
  141. #define OCTEON_CN6XXX \
  142. (OCTEON_CN63XX_PASS1_0 | OM_MATCH_6XXX_FAMILY_MODELS)
  143. #define OCTEON_CNF7XXX \
  144. (OCTEON_CNF71XX_PASS1_0 | OM_MATCH_F7XXX_FAMILY_MODELS)
  145. #define OCTEON_CN7XXX \
  146. (OCTEON_CN78XX_PASS1_0 | OM_MATCH_7XXX_FAMILY_MODELS)
  147. /*
  148. * The revision byte (low byte) has two different encodings.
  149. * CN3XXX:
  150. *
  151. * bits
  152. * <7:5>: reserved (0)
  153. * <4>: alternate package
  154. * <3:0>: revision
  155. *
  156. * CN5XXX and older models:
  157. *
  158. * bits
  159. * <7>: reserved (0)
  160. * <6>: alternate package
  161. * <5:3>: major revision
  162. * <2:0>: minor revision
  163. */
  164. /* Masks used for the various types of model/family/revision matching */
  165. #define OCTEON_38XX_FAMILY_MASK 0x00ffff00
  166. #define OCTEON_38XX_FAMILY_REV_MASK 0x00ffff0f
  167. #define OCTEON_38XX_MODEL_MASK 0x00ffff10
  168. #define OCTEON_38XX_MODEL_REV_MASK \
  169. (OCTEON_38XX_FAMILY_REV_MASK | OCTEON_38XX_MODEL_MASK)
  170. /* CN5XXX and later use different layout of bits in the revision ID field */
  171. #define OCTEON_58XX_FAMILY_MASK OCTEON_38XX_FAMILY_MASK
  172. #define OCTEON_58XX_FAMILY_REV_MASK 0x00ffff3f
  173. #define OCTEON_58XX_MODEL_MASK 0x00ffff40
  174. #define OCTEON_58XX_MODEL_REV_MASK \
  175. (OCTEON_58XX_FAMILY_REV_MASK | OCTEON_58XX_MODEL_MASK)
  176. #define OCTEON_58XX_MODEL_MINOR_REV_MASK \
  177. (OCTEON_58XX_MODEL_REV_MASK & 0x00ffff38)
  178. #define OCTEON_5XXX_MODEL_MASK 0x00ff0fc0
  179. #define __OCTEON_MATCH_MASK__(X, Y, Z) \
  180. ({ \
  181. typeof(X) x = (X); \
  182. typeof(Y) y = (Y); \
  183. typeof(Z) z = (Z); \
  184. (x & z) == (y & z); \
  185. })
  186. /*
  187. * __OCTEON_IS_MODEL_COMPILE__(arg_model, chip_model)
  188. * returns true if chip_model is identical or belong to the OCTEON
  189. * model group specified in arg_model.
  190. */
  191. /* Helper macros to make to following macro compacter */
  192. #define OM_MASK OM_FLAG_MASK
  193. #define OM_MATCH_MASK __OCTEON_MATCH_MASK__
  194. #define OM_MATCH_PREVIOUS OM_MATCH_PREVIOUS_MODELS
  195. #define __OCTEON_IS_MODEL_COMPILE__(A, B) \
  196. ({ \
  197. typeof(A) a = (A); \
  198. typeof(B) b = (B); \
  199. (((((((a) & OM_MASK) == (OM_IGNORE_REVISION | OM_CHECK_SUBMODEL)) && \
  200. OM_MATCH_MASK((b), (a), OCTEON_58XX_MODEL_MASK)) || \
  201. ((((a) & OM_MASK) == 0) && \
  202. OM_MATCH_MASK((b), (a), OCTEON_58XX_FAMILY_REV_MASK)) || \
  203. ((((a) & OM_MASK) == OM_IGNORE_MINOR_REVISION) && \
  204. OM_MATCH_MASK((b), (a), OCTEON_58XX_MODEL_MINOR_REV_MASK)) || \
  205. ((((a) & OM_MASK) == OM_CHECK_SUBMODEL) && \
  206. OM_MATCH_MASK((b), (a), OCTEON_58XX_MODEL_MASK)) || \
  207. ((((a) & OM_MASK) == OM_IGNORE_REVISION) && \
  208. OM_MATCH_MASK((b), (a), OCTEON_58XX_FAMILY_MASK)) || \
  209. ((((a) & (OM_MATCH_5XXX_FAMILY_MODELS)) == \
  210. OM_MATCH_5XXX_FAMILY_MODELS) && \
  211. ((b & OCTEON_PRID_MASK) < OCTEON_CN63XX_PASS1_0)) || \
  212. ((((a) & (OM_MATCH_6XXX_FAMILY_MODELS)) == \
  213. OM_MATCH_6XXX_FAMILY_MODELS) && \
  214. ((b & OCTEON_PRID_MASK) >= OCTEON_CN63XX_PASS1_0) && \
  215. ((b & OCTEON_PRID_MASK) < OCTEON_CNF71XX_PASS1_0)) || \
  216. ((((a) & (OM_MATCH_F7XXX_FAMILY_MODELS)) == \
  217. OM_MATCH_F7XXX_FAMILY_MODELS) && \
  218. ((b & OCTEON_PRID_MASK) >= OCTEON_CNF71XX_PASS1_0) && \
  219. ((b & OCTEON_PRID_MASK) < OCTEON_CN78XX_PASS1_0)) || \
  220. ((((a) & (OM_MATCH_7XXX_FAMILY_MODELS)) == \
  221. OM_MATCH_7XXX_FAMILY_MODELS) && ((b & OCTEON_PRID_MASK) >= \
  222. OCTEON_CN78XX_PASS1_0)) || \
  223. ((((a) & (OM_MATCH_PREVIOUS)) == OM_MATCH_PREVIOUS) && \
  224. (((b) & OCTEON_58XX_MODEL_MASK) < ((a) & OCTEON_58XX_MODEL_MASK))) \
  225. ))); \
  226. })
  227. #ifndef __ASSEMBLY__
  228. #ifndef OCTEON_IS_MODEL
  229. static inline int __octeon_is_model_runtime_internal__(u32 model)
  230. {
  231. u32 cpuid = read_c0_prid();
  232. return __OCTEON_IS_MODEL_COMPILE__(model, cpuid);
  233. }
  234. static inline int __octeon_is_model_runtime__(u32 model)
  235. {
  236. return __octeon_is_model_runtime_internal__(model);
  237. }
  238. /*
  239. * The OCTEON_IS_MODEL macro should be used for all Octeon model checking done
  240. * in a program.
  241. * This should be kept runtime if at all possible and must be conditionalized
  242. * with OCTEON_IS_COMMON_BINARY() if runtime checking support is required.
  243. *
  244. * Use of the macro in preprocessor directives ( #if OCTEON_IS_MODEL(...) )
  245. * is NOT SUPPORTED, and should be replaced with CVMX_COMPILED_FOR()
  246. * I.e.:
  247. * #if OCTEON_IS_MODEL(OCTEON_CN56XX) -> #if CVMX_COMPILED_FOR(OCTEON_CN56XX)
  248. */
  249. #define OCTEON_IS_MODEL(x) __octeon_is_model_runtime__(x)
  250. #define OCTEON_IS_COMMON_BINARY() 1
  251. #undef OCTEON_MODEL
  252. #endif
  253. #define OCTEON_IS_OCTEON2() \
  254. (OCTEON_IS_MODEL(OCTEON_CN6XXX) || OCTEON_IS_MODEL(OCTEON_CNF71XX))
  255. #define OCTEON_IS_OCTEON3() OCTEON_IS_MODEL(OCTEON_CN7XXX)
  256. const char *octeon_model_get_string(u32 chip_id);
  257. const char *octeon_model_get_string_buffer(u32 chip_id, char *buffer);
  258. /**
  259. * Return the octeon family, i.e., ProcessorID of the PrID register.
  260. *
  261. * Return: the octeon family on success, ((u32)-1) on error.
  262. */
  263. static inline u32 cvmx_get_octeon_family(void)
  264. {
  265. return (read_c0_prid() & OCTEON_FAMILY_MASK);
  266. }
  267. #endif /* __ASSEMBLY__ */
  268. #endif /* __OCTEON_MODEL_H__ */