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