sip_svc_setup.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (c) 2018-2021, Arm Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2022-2024, Advanced Micro Devices, Inc. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. /* Top level SMC handler for SiP calls. Dispatch PM calls to PM SMC handler. */
  8. #include <inttypes.h>
  9. #include <common/debug.h>
  10. #include <common/runtime_svc.h>
  11. #include <tools_share/uuid.h>
  12. #include "ipi_mailbox_svc.h"
  13. #include "pm_svc_main.h"
  14. /* SMC function IDs for SiP Service queries */
  15. #define VERSAL_SIP_SVC_UID U(0x8200ff01)
  16. #define VERSAL_SIP_SVC_VERSION U(0x8200ff03)
  17. /* SiP Service Calls version numbers */
  18. #define SIP_SVC_VERSION_MAJOR U(0)
  19. #define SIP_SVC_VERSION_MINOR U(2)
  20. /* These macros are used to identify PM calls from the SMC function ID */
  21. #define SIP_FID_MASK GENMASK(23, 16)
  22. #define XLNX_FID_MASK GENMASK(23, 12)
  23. #define PM_FID_VALUE 0u
  24. #define IPI_FID_VALUE 0x1000u
  25. #define is_pm_fid(_fid) (((_fid) & XLNX_FID_MASK) == PM_FID_VALUE)
  26. #define is_ipi_fid(_fid) (((_fid) & XLNX_FID_MASK) == IPI_FID_VALUE)
  27. /* SiP Service UUID */
  28. DEFINE_SVC_UUID2(versal_sip_uuid,
  29. 0x2ab9e4ecU, 0x93b9U, 0x11e7U, 0xa0U, 0x19U,
  30. 0xdfU, 0xe0U, 0xdbU, 0xadU, 0x0aU, 0xe0U);
  31. /**
  32. * sip_svc_setup() - Setup SiP Service
  33. *
  34. * Return: 0 on success,negative error code on failure.
  35. *
  36. * Invokes PM setup.
  37. */
  38. static int32_t sip_svc_setup(void)
  39. {
  40. /* PM implementation as SiP Service */
  41. (void)pm_setup();
  42. return 0;
  43. }
  44. /**
  45. * sip_svc_smc_handler() - Top-level SiP Service SMC handler.
  46. * @smc_fid: Function Identifier.
  47. * @x1: SMC64 Arguments 1 from kernel.
  48. * @x2: SMC64 Arguments 2 from kernel.
  49. * @x3: SMC64 Arguments 3 from kernel(upper 32-bits).
  50. * @x4: SMC64 Arguments 4 from kernel.
  51. * @cookie: Unused
  52. * @handle: Pointer to caller's context structure.
  53. * @flags: SECURE_FLAG or NON_SECURE_FLAG.
  54. *
  55. * Handler for all SiP SMC calls. Handles standard SIP requests
  56. * and calls PM SMC handler if the call is for a PM-API function.
  57. *
  58. * Return: Unused.
  59. */
  60. static uintptr_t sip_svc_smc_handler(uint32_t smc_fid,
  61. u_register_t x1,
  62. u_register_t x2,
  63. u_register_t x3,
  64. u_register_t x4,
  65. void *cookie,
  66. void *handle,
  67. u_register_t flags)
  68. {
  69. VERBOSE("SMCID: 0x%08x, x1: 0x%016" PRIx64 ", x2: 0x%016" PRIx64 ", x3: 0x%016" PRIx64 ", x4: 0x%016" PRIx64 "\n",
  70. smc_fid, x1, x2, x3, x4);
  71. if ((smc_fid & SIP_FID_MASK) != 0U) {
  72. WARN("SMC out of SiP assinged range: 0x%x\n", smc_fid);
  73. SMC_RET1(handle, SMC_UNK);
  74. }
  75. /* Let PM SMC handler deal with PM-related requests */
  76. if (is_pm_fid(smc_fid)) {
  77. return pm_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle,
  78. flags);
  79. }
  80. /* Let IPI SMC handler deal with IPI-related requests */
  81. if (is_ipi_fid(smc_fid)) {
  82. return ipi_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle,
  83. flags);
  84. }
  85. /* Let PM SMC handler deal with PM-related requests */
  86. switch (smc_fid) {
  87. case VERSAL_SIP_SVC_UID:
  88. SMC_UUID_RET(handle, versal_sip_uuid);
  89. case VERSAL_SIP_SVC_VERSION:
  90. SMC_RET2(handle, SIP_SVC_VERSION_MAJOR, SIP_SVC_VERSION_MINOR);
  91. default:
  92. WARN("Unimplemented SiP Service Call: 0x%x\n", smc_fid);
  93. SMC_RET1(handle, SMC_UNK);
  94. }
  95. }
  96. /* Register PM Service Calls as runtime service */
  97. DECLARE_RT_SVC(
  98. sip_svc,
  99. OEN_SIP_START,
  100. OEN_SIP_END,
  101. SMC_TYPE_FAST,
  102. sip_svc_setup,
  103. sip_svc_smc_handler);