plat_sip_calls.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <errno.h>
  8. #include <arch.h>
  9. #include <arch_helpers.h>
  10. #include <common/bl_common.h>
  11. #include <common/debug.h>
  12. #include <common/runtime_svc.h>
  13. #include <denver.h>
  14. #include <lib/el3_runtime/context_mgmt.h>
  15. #include <mce.h>
  16. #include <memctrl.h>
  17. #include <t18x_ari.h>
  18. #include <tegra_private.h>
  19. /*******************************************************************************
  20. * Offset to read the ref_clk counter value
  21. ******************************************************************************/
  22. #define REF_CLK_OFFSET 4ULL
  23. /*******************************************************************************
  24. * Tegra186 SiP SMCs
  25. ******************************************************************************/
  26. #define TEGRA_SIP_GET_ACTMON_CLK_COUNTERS 0xC2FFFE02
  27. #define TEGRA_SIP_MCE_CMD_ENTER_CSTATE 0xC2FFFF00
  28. #define TEGRA_SIP_MCE_CMD_UPDATE_CSTATE_INFO 0xC2FFFF01
  29. #define TEGRA_SIP_MCE_CMD_UPDATE_CROSSOVER_TIME 0xC2FFFF02
  30. #define TEGRA_SIP_MCE_CMD_READ_CSTATE_STATS 0xC2FFFF03
  31. #define TEGRA_SIP_MCE_CMD_WRITE_CSTATE_STATS 0xC2FFFF04
  32. #define TEGRA_SIP_MCE_CMD_IS_SC7_ALLOWED 0xC2FFFF05
  33. #define TEGRA_SIP_MCE_CMD_CC3_CTRL 0xC2FFFF07
  34. #define TEGRA_SIP_MCE_CMD_ECHO_DATA 0xC2FFFF08
  35. #define TEGRA_SIP_MCE_CMD_READ_VERSIONS 0xC2FFFF09
  36. #define TEGRA_SIP_MCE_CMD_ENUM_FEATURES 0xC2FFFF0A
  37. #define TEGRA_SIP_MCE_CMD_ROC_FLUSH_CACHE_TRBITS 0xC2FFFF0B
  38. #define TEGRA_SIP_MCE_CMD_ENUM_READ_MCA 0xC2FFFF0C
  39. #define TEGRA_SIP_MCE_CMD_ENUM_WRITE_MCA 0xC2FFFF0D
  40. #define TEGRA_SIP_MCE_CMD_ROC_FLUSH_CACHE 0xC2FFFF0E
  41. #define TEGRA_SIP_MCE_CMD_ROC_CLEAN_CACHE 0xC2FFFF0F
  42. #define TEGRA_SIP_MCE_CMD_ENABLE_LATIC 0xC2FFFF10
  43. #define TEGRA_SIP_MCE_CMD_UNCORE_PERFMON_REQ 0xC2FFFF11
  44. #define TEGRA_SIP_MCE_CMD_MISC_CCPLEX 0xC2FFFF12
  45. /*******************************************************************************
  46. * This function is responsible for handling all T186 SiP calls
  47. ******************************************************************************/
  48. int32_t plat_sip_handler(uint32_t smc_fid,
  49. uint64_t x1,
  50. uint64_t x2,
  51. uint64_t x3,
  52. uint64_t x4,
  53. const void *cookie,
  54. void *handle,
  55. uint64_t flags)
  56. {
  57. int32_t mce_ret, ret = 0;
  58. uint32_t impl, cpu;
  59. uint32_t base, core_clk_ctr, ref_clk_ctr;
  60. uint32_t local_smc_fid = smc_fid;
  61. uint64_t local_x1 = x1, local_x2 = x2, local_x3 = x3;
  62. (void)x4;
  63. (void)cookie;
  64. (void)flags;
  65. if (((smc_fid >> FUNCID_CC_SHIFT) & FUNCID_CC_MASK) == SMC_32) {
  66. /* 32-bit function, clear top parameter bits */
  67. local_x1 = (uint32_t)x1;
  68. local_x2 = (uint32_t)x2;
  69. local_x3 = (uint32_t)x3;
  70. }
  71. /*
  72. * Convert SMC FID to SMC64, to support SMC32/SMC64 configurations
  73. */
  74. local_smc_fid |= (SMC_64 << FUNCID_CC_SHIFT);
  75. switch (local_smc_fid) {
  76. /*
  77. * Micro Coded Engine (MCE) commands reside in the 0x82FFFF00 -
  78. * 0x82FFFFFF SiP SMC space
  79. */
  80. case TEGRA_SIP_MCE_CMD_ENTER_CSTATE:
  81. case TEGRA_SIP_MCE_CMD_UPDATE_CSTATE_INFO:
  82. case TEGRA_SIP_MCE_CMD_UPDATE_CROSSOVER_TIME:
  83. case TEGRA_SIP_MCE_CMD_READ_CSTATE_STATS:
  84. case TEGRA_SIP_MCE_CMD_WRITE_CSTATE_STATS:
  85. case TEGRA_SIP_MCE_CMD_IS_SC7_ALLOWED:
  86. case TEGRA_SIP_MCE_CMD_CC3_CTRL:
  87. case TEGRA_SIP_MCE_CMD_ECHO_DATA:
  88. case TEGRA_SIP_MCE_CMD_READ_VERSIONS:
  89. case TEGRA_SIP_MCE_CMD_ENUM_FEATURES:
  90. case TEGRA_SIP_MCE_CMD_ROC_FLUSH_CACHE_TRBITS:
  91. case TEGRA_SIP_MCE_CMD_ENUM_READ_MCA:
  92. case TEGRA_SIP_MCE_CMD_ENUM_WRITE_MCA:
  93. case TEGRA_SIP_MCE_CMD_ROC_FLUSH_CACHE:
  94. case TEGRA_SIP_MCE_CMD_ROC_CLEAN_CACHE:
  95. case TEGRA_SIP_MCE_CMD_ENABLE_LATIC:
  96. case TEGRA_SIP_MCE_CMD_UNCORE_PERFMON_REQ:
  97. case TEGRA_SIP_MCE_CMD_MISC_CCPLEX:
  98. /* clean up the high bits */
  99. local_smc_fid &= MCE_CMD_MASK;
  100. /* execute the command and store the result */
  101. mce_ret = mce_command_handler(local_smc_fid, local_x1, local_x2, local_x3);
  102. write_ctx_reg(get_gpregs_ctx(handle),
  103. CTX_GPREG_X0, (uint64_t)(mce_ret));
  104. break;
  105. /*
  106. * This function ID reads the Activity monitor's core/ref clock
  107. * counter values for a core/cluster.
  108. *
  109. * x1 = MPIDR of the target core
  110. * x2 = MIDR of the target core
  111. */
  112. case TEGRA_SIP_GET_ACTMON_CLK_COUNTERS:
  113. cpu = (uint32_t)x1 & MPIDR_CPU_MASK;
  114. impl = ((uint32_t)x2 >> MIDR_IMPL_SHIFT) & MIDR_IMPL_MASK;
  115. /* sanity check target CPU number */
  116. if (cpu > (uint32_t)PLATFORM_MAX_CPUS_PER_CLUSTER) {
  117. ret = -EINVAL;
  118. } else {
  119. /* get the base address for the current CPU */
  120. base = (impl == DENVER_IMPL) ? TEGRA_DENVER_ACTMON_CTR_BASE :
  121. TEGRA_ARM_ACTMON_CTR_BASE;
  122. /* read the clock counter values */
  123. core_clk_ctr = mmio_read_32(base + (8ULL * cpu));
  124. ref_clk_ctr = mmio_read_32(base + (8ULL * cpu) + REF_CLK_OFFSET);
  125. /* return the counter values as two different parameters */
  126. write_ctx_reg(get_gpregs_ctx(handle),
  127. CTX_GPREG_X1, (core_clk_ctr));
  128. write_ctx_reg(get_gpregs_ctx(handle),
  129. CTX_GPREG_X2, (ref_clk_ctr));
  130. }
  131. break;
  132. default:
  133. ret = -ENOTSUP;
  134. break;
  135. }
  136. return ret;
  137. }