sip_svc_setup.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) 2018-2019, Arm Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2018-2022, Xilinx, Inc. All rights reserved.
  4. * Copyright (c) 2022-2024, Advanced Micro Devices, Inc. All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. /* Top level SMC handler for SiP calls. Dispatch PM calls to PM SMC handler. */
  9. #include <errno.h>
  10. #include <inttypes.h>
  11. #include <common/debug.h>
  12. #include <common/runtime_svc.h>
  13. #include <drivers/scmi-msg.h>
  14. #include <scmi.h>
  15. #include <tools_share/uuid.h>
  16. #include "ipi_mailbox_svc.h"
  17. #include "plat_private.h"
  18. #include "pm_svc_main.h"
  19. /* SMC function IDs for SiP Service queries */
  20. #define SIP_SVC_UID (0x8200ff01U)
  21. #define SIP_SVC_VERSION (0x8200ff03U)
  22. /* SiP Service Calls version numbers */
  23. #define SIP_SVC_VERSION_MAJOR (0U)
  24. #define SIP_SVC_VERSION_MINOR (1U)
  25. /* These macros are used to identify PM calls from the SMC function ID */
  26. #define SIP_FID_MASK GENMASK(23, 16)
  27. #define XLNX_FID_MASK GENMASK(23, 12)
  28. #define PM_FID_VALUE 0u
  29. #define IPI_FID_VALUE 0x1000u
  30. #define is_pm_fid(_fid) (((_fid) & XLNX_FID_MASK) == PM_FID_VALUE)
  31. #define is_ipi_fid(_fid) (((_fid) & XLNX_FID_MASK) == IPI_FID_VALUE)
  32. /* SiP Service UUID */
  33. DEFINE_SVC_UUID2(_sip_uuid,
  34. 0x0499eb70, 0x5ed0, 0x11ee, 0xb3, 0x0a,
  35. 0x87, 0xd1, 0x1d, 0x4f, 0x8a, 0x9b);
  36. /**
  37. * sip_svc_setup() - Setup SiP Service
  38. *
  39. * Return: 0 on success, negative error code on failure.
  40. *
  41. */
  42. static int32_t sip_svc_setup(void)
  43. {
  44. return sip_svc_setup_init();
  45. }
  46. /*
  47. * sip_svc_smc_handler() - Top-level SiP Service SMC handler
  48. *
  49. * Handler for all SiP SMC calls. Handles standard SIP requests
  50. * and calls PM SMC handler if the call is for a PM-API function.
  51. */
  52. static uintptr_t sip_svc_smc_handler(uint32_t smc_fid,
  53. u_register_t x1,
  54. u_register_t x2,
  55. u_register_t x3,
  56. u_register_t x4,
  57. void *cookie,
  58. void *handle,
  59. u_register_t flags)
  60. {
  61. VERBOSE("SMCID: 0x%08x, x1: 0x%016" PRIx64 ", x2: 0x%016" PRIx64 ", x3: 0x%016" PRIx64 ", x4: 0x%016" PRIx64 "\n",
  62. smc_fid, x1, x2, x3, x4);
  63. if ((smc_fid & SIP_FID_MASK) != 0) {
  64. WARN("SMC out of SiP assinged range: 0x%x\n", smc_fid);
  65. SMC_RET1(handle, SMC_UNK);
  66. }
  67. /* Let PM SMC handler deal with PM-related requests */
  68. if (is_pm_fid(smc_fid)) {
  69. return smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
  70. }
  71. /* Let IPI SMC handler deal with IPI-related requests if platform */
  72. if (is_ipi_fid(smc_fid)) {
  73. return ipi_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
  74. }
  75. /* Let PM SMC handler deal with PM-related requests */
  76. switch (smc_fid) {
  77. case SIP_SVC_UID:
  78. SMC_UUID_RET(handle, _sip_uuid);
  79. case SIP_SVC_VERSION:
  80. SMC_RET2(handle, SIP_SVC_VERSION_MAJOR, SIP_SVC_VERSION_MINOR);
  81. case SIP_SCMI:
  82. if (platform_id != EMU) {
  83. scmi_smt_fastcall_smc_entry(0);
  84. SMC_RET1(handle, 0);
  85. }
  86. WARN("SCMI is not working on EMU\n");
  87. SMC_RET1(handle, SMC_UNK);
  88. default:
  89. WARN("Unimplemented SiP Service Call: 0x%x\n", smc_fid);
  90. SMC_RET1(handle, SMC_UNK);
  91. }
  92. }
  93. /* Register PM Service Calls as runtime service */
  94. DECLARE_RT_SVC(
  95. sip_svc,
  96. OEN_SIP_START,
  97. OEN_SIP_END,
  98. SMC_TYPE_FAST,
  99. sip_svc_setup,
  100. sip_svc_smc_handler);