plat_sip_calls.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (c) 2018, 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 <inttypes.h>
  8. #include <stdint.h>
  9. #include <arch.h>
  10. #include <arch_helpers.h>
  11. #include <assert.h>
  12. #include <common/bl_common.h>
  13. #include <common/debug.h>
  14. #include <common/runtime_svc.h>
  15. #include <errno.h>
  16. #include <lib/mmio.h>
  17. #include <lib/utils_def.h>
  18. #include <memctrl.h>
  19. #include <pmc.h>
  20. #include <tegra_private.h>
  21. #include <tegra_platform.h>
  22. #include <tegra_def.h>
  23. /*******************************************************************************
  24. * PMC parameters
  25. ******************************************************************************/
  26. #define PMC_READ U(0xaa)
  27. #define PMC_WRITE U(0xbb)
  28. /*******************************************************************************
  29. * Tegra210 SiP SMCs
  30. ******************************************************************************/
  31. #define TEGRA_SIP_PMC_COMMANDS U(0xC200FE00)
  32. /*******************************************************************************
  33. * This function is responsible for handling all T210 SiP calls
  34. ******************************************************************************/
  35. int plat_sip_handler(uint32_t smc_fid,
  36. uint64_t x1,
  37. uint64_t x2,
  38. uint64_t x3,
  39. uint64_t x4,
  40. const void *cookie,
  41. void *handle,
  42. uint64_t flags)
  43. {
  44. uint32_t val, ns;
  45. /* Determine which security state this SMC originated from */
  46. ns = is_caller_non_secure(flags);
  47. if (!ns)
  48. SMC_RET1(handle, SMC_UNK);
  49. if (smc_fid == TEGRA_SIP_PMC_COMMANDS) {
  50. /* check the address is within PMC range and is 4byte aligned */
  51. if ((x2 >= TEGRA_PMC_SIZE) || (x2 & 0x3)) {
  52. return -EINVAL;
  53. }
  54. switch (x2) {
  55. /* Black listed PMC registers */
  56. case PMC_SCRATCH1:
  57. case PMC_SCRATCH31 ... PMC_SCRATCH33:
  58. case PMC_SCRATCH40:
  59. case PMC_SCRATCH42:
  60. case PMC_SCRATCH43 ... PMC_SCRATCH48:
  61. case PMC_SCRATCH50 ... PMC_SCRATCH51:
  62. case PMC_SCRATCH56 ... PMC_SCRATCH57:
  63. /* PMC secure-only registers are not accessible */
  64. case PMC_DPD_ENABLE_0:
  65. case PMC_FUSE_CONTROL_0:
  66. case PMC_CRYPTO_OP_0:
  67. case PMC_TSC_MULT_0:
  68. case PMC_STICKY_BIT:
  69. ERROR("%s: error offset=0x%" PRIx64 "\n", __func__, x2);
  70. return -EFAULT;
  71. default:
  72. /* Valid register */
  73. break;
  74. }
  75. /* Perform PMC read/write */
  76. if (x1 == PMC_READ) {
  77. val = mmio_read_32((uint32_t)(TEGRA_PMC_BASE + x2));
  78. write_ctx_reg(get_gpregs_ctx(handle), CTX_GPREG_X1, val);
  79. } else if (x1 == PMC_WRITE) {
  80. mmio_write_32((uint32_t)(TEGRA_PMC_BASE + x2), (uint32_t)x3);
  81. } else {
  82. return -EINVAL;
  83. }
  84. } else {
  85. return -ENOTSUP;
  86. }
  87. return 0;
  88. }