plat_sip_calls.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <common/debug.h>
  7. #include <common/runtime_svc.h>
  8. #include <lib/mmio.h>
  9. #include <crypt.h>
  10. #include <mtcmos.h>
  11. #include <mtk_sip_svc.h>
  12. #include <plat_sip_calls.h>
  13. #include <wdt.h>
  14. /* Authorized secure register list */
  15. enum {
  16. SREG_HDMI_COLOR_EN = 0x14000904
  17. };
  18. static const uint32_t authorized_sreg[] = {
  19. SREG_HDMI_COLOR_EN
  20. };
  21. #define authorized_sreg_cnt \
  22. (sizeof(authorized_sreg) / sizeof(authorized_sreg[0]))
  23. uint64_t mt_sip_set_authorized_sreg(uint32_t sreg, uint32_t val)
  24. {
  25. uint64_t i;
  26. for (i = 0; i < authorized_sreg_cnt; i++) {
  27. if (authorized_sreg[i] == sreg) {
  28. mmio_write_32(sreg, val);
  29. return MTK_SIP_E_SUCCESS;
  30. }
  31. }
  32. return MTK_SIP_E_INVALID_PARAM;
  33. }
  34. static uint64_t mt_sip_pwr_on_mtcmos(uint32_t val)
  35. {
  36. uint32_t ret;
  37. ret = mtcmos_non_cpu_ctrl(1, val);
  38. if (ret)
  39. return MTK_SIP_E_INVALID_PARAM;
  40. else
  41. return MTK_SIP_E_SUCCESS;
  42. }
  43. static uint64_t mt_sip_pwr_off_mtcmos(uint32_t val)
  44. {
  45. uint32_t ret;
  46. ret = mtcmos_non_cpu_ctrl(0, val);
  47. if (ret)
  48. return MTK_SIP_E_INVALID_PARAM;
  49. else
  50. return MTK_SIP_E_SUCCESS;
  51. }
  52. static uint64_t mt_sip_pwr_mtcmos_support(void)
  53. {
  54. return MTK_SIP_E_SUCCESS;
  55. }
  56. uint64_t mediatek_plat_sip_handler(uint32_t smc_fid,
  57. uint64_t x1,
  58. uint64_t x2,
  59. uint64_t x3,
  60. uint64_t x4,
  61. void *cookie,
  62. void *handle,
  63. uint64_t flags)
  64. {
  65. uint64_t ret;
  66. switch (smc_fid) {
  67. case MTK_SIP_PWR_ON_MTCMOS:
  68. ret = mt_sip_pwr_on_mtcmos((uint32_t)x1);
  69. SMC_RET1(handle, ret);
  70. case MTK_SIP_PWR_OFF_MTCMOS:
  71. ret = mt_sip_pwr_off_mtcmos((uint32_t)x1);
  72. SMC_RET1(handle, ret);
  73. case MTK_SIP_PWR_MTCMOS_SUPPORT:
  74. ret = mt_sip_pwr_mtcmos_support();
  75. SMC_RET1(handle, ret);
  76. case MTK_SIP_SET_HDCP_KEY_EX:
  77. ret = crypt_set_hdcp_key_ex(x1, x2, x3);
  78. SMC_RET1(handle, ret);
  79. case MTK_SIP_SET_HDCP_KEY_NUM:
  80. ret = crypt_set_hdcp_key_num((uint32_t)x1);
  81. SMC_RET1(handle, ret);
  82. case MTK_SIP_CLR_HDCP_KEY:
  83. ret = crypt_clear_hdcp_key();
  84. SMC_RET1(handle, ret);
  85. case MTK_SIP_SMC_WATCHDOG:
  86. return wdt_smc_handler(x1, x2, handle);
  87. default:
  88. ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
  89. break;
  90. }
  91. SMC_RET1(handle, SMC_UNK);
  92. }