tegra_platform.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /*
  2. * Copyright (c) 2016-2021, ARM Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2020-2023, NVIDIA Corporation. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #include <arch_helpers.h>
  8. #include <assert.h>
  9. #include <lib/mmio.h>
  10. #include <lib/smccc.h>
  11. #include <services/arm_arch_svc.h>
  12. #include <tegra_def.h>
  13. #include <tegra_platform.h>
  14. #include <tegra_private.h>
  15. /*******************************************************************************
  16. * Tegra platforms
  17. ******************************************************************************/
  18. typedef enum tegra_platform {
  19. TEGRA_PLATFORM_SILICON = 0U,
  20. TEGRA_PLATFORM_QT,
  21. TEGRA_PLATFORM_FPGA,
  22. TEGRA_PLATFORM_EMULATION,
  23. TEGRA_PLATFORM_LINSIM,
  24. TEGRA_PLATFORM_UNIT_FPGA,
  25. TEGRA_PLATFORM_VIRT_DEV_KIT,
  26. TEGRA_PLATFORM_MAX,
  27. } tegra_platform_t;
  28. /*******************************************************************************
  29. * Tegra macros defining all the SoC minor versions
  30. ******************************************************************************/
  31. #define TEGRA_MINOR_QT U(0)
  32. #define TEGRA_MINOR_FPGA U(1)
  33. #define TEGRA_MINOR_ASIM_QT U(2)
  34. #define TEGRA_MINOR_ASIM_LINSIM U(3)
  35. #define TEGRA_MINOR_DSIM_ASIM_LINSIM U(4)
  36. #define TEGRA_MINOR_UNIT_FPGA U(5)
  37. #define TEGRA_MINOR_VIRT_DEV_KIT U(6)
  38. /*******************************************************************************
  39. * Tegra macros defining all the SoC pre_si_platform
  40. ******************************************************************************/
  41. #define TEGRA_PRE_SI_QT U(1)
  42. #define TEGRA_PRE_SI_FPGA U(2)
  43. #define TEGRA_PRE_SI_UNIT_FPGA U(3)
  44. #define TEGRA_PRE_SI_ASIM_QT U(4)
  45. #define TEGRA_PRE_SI_ASIM_LINSIM U(5)
  46. #define TEGRA_PRE_SI_DSIM_ASIM_LINSIM U(6)
  47. #define TEGRA_PRE_SI_VDK U(8)
  48. /*
  49. * Read the chip ID value
  50. */
  51. static uint32_t tegra_get_chipid(void)
  52. {
  53. return mmio_read_32(TEGRA_MISC_BASE + HARDWARE_REVISION_OFFSET);
  54. }
  55. /*
  56. * Read the chip's major version from chip ID value
  57. */
  58. uint32_t tegra_get_chipid_major(void)
  59. {
  60. return (tegra_get_chipid() >> MAJOR_VERSION_SHIFT) & MAJOR_VERSION_MASK;
  61. }
  62. /*
  63. * Read the chip's minor version from the chip ID value
  64. */
  65. uint32_t tegra_get_chipid_minor(void)
  66. {
  67. return (tegra_get_chipid() >> MINOR_VERSION_SHIFT) & MINOR_VERSION_MASK;
  68. }
  69. /*
  70. * Read the chip's pre_si_platform valus from the chip ID value
  71. */
  72. static uint32_t tegra_get_chipid_pre_si_platform(void)
  73. {
  74. return (tegra_get_chipid() >> PRE_SI_PLATFORM_SHIFT) & PRE_SI_PLATFORM_MASK;
  75. }
  76. bool tegra_chipid_is_t186(void)
  77. {
  78. uint32_t chip_id = (tegra_get_chipid() >> CHIP_ID_SHIFT) & CHIP_ID_MASK;
  79. return (chip_id == TEGRA_CHIPID_TEGRA18);
  80. }
  81. bool tegra_chipid_is_t210(void)
  82. {
  83. uint32_t chip_id = (tegra_get_chipid() >> CHIP_ID_SHIFT) & CHIP_ID_MASK;
  84. return (chip_id == TEGRA_CHIPID_TEGRA21);
  85. }
  86. bool tegra_chipid_is_t210_b01(void)
  87. {
  88. return (tegra_chipid_is_t210() && (tegra_get_chipid_major() == 0x2U));
  89. }
  90. bool tegra_chipid_is_t194(void)
  91. {
  92. uint32_t chip_id = (tegra_get_chipid() >> CHIP_ID_SHIFT) & CHIP_ID_MASK;
  93. return (chip_id == TEGRA_CHIPID_TEGRA19);
  94. }
  95. /*
  96. * Read the chip ID value and derive the platform
  97. */
  98. static tegra_platform_t tegra_get_platform(void)
  99. {
  100. uint32_t major, minor, pre_si_platform;
  101. tegra_platform_t ret;
  102. /* get the major/minor chip ID values */
  103. major = tegra_get_chipid_major();
  104. minor = tegra_get_chipid_minor();
  105. pre_si_platform = tegra_get_chipid_pre_si_platform();
  106. if (major == 0U) {
  107. /*
  108. * The minor version number is used by simulation platforms
  109. */
  110. switch (minor) {
  111. /*
  112. * Cadence's QuickTurn emulation system is a Solaris-based
  113. * chip emulation system
  114. */
  115. case TEGRA_MINOR_QT:
  116. case TEGRA_MINOR_ASIM_QT:
  117. ret = TEGRA_PLATFORM_QT;
  118. break;
  119. /*
  120. * FPGAs are used during early software/hardware development
  121. */
  122. case TEGRA_MINOR_FPGA:
  123. ret = TEGRA_PLATFORM_FPGA;
  124. break;
  125. /*
  126. * Linsim is a reconfigurable, clock-driven, mixed RTL/cmodel
  127. * simulation framework.
  128. */
  129. case TEGRA_MINOR_ASIM_LINSIM:
  130. case TEGRA_MINOR_DSIM_ASIM_LINSIM:
  131. ret = TEGRA_PLATFORM_LINSIM;
  132. break;
  133. /*
  134. * Unit FPGAs run the actual hardware block IP on the FPGA with
  135. * the other parts of the system using Linsim.
  136. */
  137. case TEGRA_MINOR_UNIT_FPGA:
  138. ret = TEGRA_PLATFORM_UNIT_FPGA;
  139. break;
  140. /*
  141. * The Virtualizer Development Kit (VDK) is the standard chip
  142. * development from Synopsis.
  143. */
  144. case TEGRA_MINOR_VIRT_DEV_KIT:
  145. ret = TEGRA_PLATFORM_VIRT_DEV_KIT;
  146. break;
  147. default:
  148. ret = TEGRA_PLATFORM_MAX;
  149. break;
  150. }
  151. } else if (pre_si_platform > 0U) {
  152. switch (pre_si_platform) {
  153. /*
  154. * Cadence's QuickTurn emulation system is a Solaris-based
  155. * chip emulation system
  156. */
  157. case TEGRA_PRE_SI_QT:
  158. case TEGRA_PRE_SI_ASIM_QT:
  159. ret = TEGRA_PLATFORM_QT;
  160. break;
  161. /*
  162. * FPGAs are used during early software/hardware development
  163. */
  164. case TEGRA_PRE_SI_FPGA:
  165. ret = TEGRA_PLATFORM_FPGA;
  166. break;
  167. /*
  168. * Linsim is a reconfigurable, clock-driven, mixed RTL/cmodel
  169. * simulation framework.
  170. */
  171. case TEGRA_PRE_SI_ASIM_LINSIM:
  172. case TEGRA_PRE_SI_DSIM_ASIM_LINSIM:
  173. ret = TEGRA_PLATFORM_LINSIM;
  174. break;
  175. /*
  176. * Unit FPGAs run the actual hardware block IP on the FPGA with
  177. * the other parts of the system using Linsim.
  178. */
  179. case TEGRA_PRE_SI_UNIT_FPGA:
  180. ret = TEGRA_PLATFORM_UNIT_FPGA;
  181. break;
  182. /*
  183. * The Virtualizer Development Kit (VDK) is the standard chip
  184. * development from Synopsis.
  185. */
  186. case TEGRA_PRE_SI_VDK:
  187. ret = TEGRA_PLATFORM_VIRT_DEV_KIT;
  188. break;
  189. default:
  190. ret = TEGRA_PLATFORM_MAX;
  191. break;
  192. }
  193. } else {
  194. /* Actual silicon platforms have a non-zero major version */
  195. ret = TEGRA_PLATFORM_SILICON;
  196. }
  197. return ret;
  198. }
  199. bool tegra_platform_is_silicon(void)
  200. {
  201. return ((tegra_get_platform() == TEGRA_PLATFORM_SILICON) ? true : false);
  202. }
  203. bool tegra_platform_is_qt(void)
  204. {
  205. return ((tegra_get_platform() == TEGRA_PLATFORM_QT) ? true : false);
  206. }
  207. bool tegra_platform_is_linsim(void)
  208. {
  209. tegra_platform_t plat = tegra_get_platform();
  210. return (((plat == TEGRA_PLATFORM_LINSIM) ||
  211. (plat == TEGRA_PLATFORM_UNIT_FPGA)) ? true : false);
  212. }
  213. bool tegra_platform_is_fpga(void)
  214. {
  215. return ((tegra_get_platform() == TEGRA_PLATFORM_FPGA) ? true : false);
  216. }
  217. bool tegra_platform_is_emulation(void)
  218. {
  219. return (tegra_get_platform() == TEGRA_PLATFORM_EMULATION);
  220. }
  221. bool tegra_platform_is_unit_fpga(void)
  222. {
  223. return ((tegra_get_platform() == TEGRA_PLATFORM_UNIT_FPGA) ? true : false);
  224. }
  225. bool tegra_platform_is_virt_dev_kit(void)
  226. {
  227. return ((tegra_get_platform() == TEGRA_PLATFORM_VIRT_DEV_KIT) ? true : false);
  228. }
  229. /*
  230. * This function returns soc version which mainly consist of below fields
  231. *
  232. * soc_version[30:24] = JEP-106 continuation code for the SiP
  233. * soc_version[23:16] = JEP-106 identification code with parity bit for the SiP
  234. * soc_version[0:15] = chip identification
  235. */
  236. int32_t plat_get_soc_version(void)
  237. {
  238. uint32_t chip_id = (tegra_get_chipid() >> CHIP_ID_SHIFT) & CHIP_ID_MASK;
  239. uint32_t major_rev = tegra_get_chipid_major();
  240. uint32_t manfid = SOC_ID_SET_JEP_106(JEDEC_NVIDIA_BKID, JEDEC_NVIDIA_MFID);
  241. return (int32_t)(manfid | (((chip_id << MAJOR_VERSION_SHIFT) | major_rev) &
  242. SOC_ID_IMPL_DEF_MASK));
  243. }
  244. /*
  245. * This function returns soc revision in below format
  246. *
  247. * soc_revision[8:15] = major version number
  248. * soc_revision[0:7] = minor version number
  249. */
  250. int32_t plat_get_soc_revision(void)
  251. {
  252. return (int32_t)(((tegra_get_chipid_major() << 8) | tegra_get_chipid_minor()) &
  253. SOC_ID_REV_MASK);
  254. }
  255. /*****************************************************************************
  256. * plat_is_smccc_feature_available() - This function checks whether SMCCC feature
  257. * is availabile for the platform or not.
  258. * @fid: SMCCC function id
  259. *
  260. * Return SMC_ARCH_CALL_SUCCESS if SMCCC feature is available and
  261. * SMC_ARCH_CALL_NOT_SUPPORTED otherwise.
  262. *****************************************************************************/
  263. int32_t plat_is_smccc_feature_available(u_register_t fid)
  264. {
  265. switch (fid) {
  266. case SMCCC_ARCH_SOC_ID:
  267. return SMC_ARCH_CALL_SUCCESS;
  268. default:
  269. return SMC_ARCH_CALL_NOT_SUPPORTED;
  270. }
  271. }