sip_svc_setup.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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, 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 <tools_share/uuid.h>
  14. #include "ipi_mailbox_svc.h"
  15. #include "plat_private.h"
  16. #include "pm_svc_main.h"
  17. /* SMC function IDs for SiP Service queries */
  18. #define VERSAL_NET_SIP_SVC_UID (0x8200ff01U)
  19. #define VERSAL_NET_SIP_SVC_VERSION (0x8200ff03U)
  20. /* SiP Service Calls version numbers */
  21. #define SIP_SVC_VERSION_MAJOR (0U)
  22. #define SIP_SVC_VERSION_MINOR (1U)
  23. /* These macros are used to identify PM calls from the SMC function ID */
  24. #define SIP_FID_MASK GENMASK(23, 16)
  25. #define XLNX_FID_MASK GENMASK(23, 12)
  26. #define PM_FID_VALUE 0u
  27. #define IPI_FID_VALUE 0x1000u
  28. #define is_pm_fid(_fid) (((_fid) & XLNX_FID_MASK) == PM_FID_VALUE)
  29. #define is_ipi_fid(_fid) (((_fid) & XLNX_FID_MASK) == IPI_FID_VALUE)
  30. /* SiP Service UUID */
  31. DEFINE_SVC_UUID2(versal_net_sip_uuid,
  32. 0x80d4c25a, 0xebaf, 0x11eb, 0x94, 0x68,
  33. 0x0b, 0x4e, 0x3b, 0x8f, 0xc3, 0x60);
  34. /**
  35. * sip_svc_setup() - Setup SiP Service
  36. *
  37. * Return: 0 on success, negative error code on failure.
  38. *
  39. */
  40. static int32_t sip_svc_setup(void)
  41. {
  42. return sip_svc_setup_init();
  43. }
  44. /*
  45. * sip_svc_smc_handler() - Top-level SiP Service SMC handler
  46. *
  47. * Handler for all SiP SMC calls. Handles standard SIP requests
  48. * and calls PM SMC handler if the call is for a PM-API function.
  49. */
  50. static uintptr_t sip_svc_smc_handler(uint32_t smc_fid,
  51. u_register_t x1,
  52. u_register_t x2,
  53. u_register_t x3,
  54. u_register_t x4,
  55. void *cookie,
  56. void *handle,
  57. u_register_t flags)
  58. {
  59. VERBOSE("SMCID: 0x%08x, x1: 0x%016" PRIx64 ", x2: 0x%016" PRIx64 ", x3: 0x%016" PRIx64 ", x4: 0x%016" PRIx64 "\n",
  60. smc_fid, x1, x2, x3, x4);
  61. if (smc_fid & SIP_FID_MASK) {
  62. WARN("SMC out of SiP assinged range: 0x%x\n", smc_fid);
  63. SMC_RET1(handle, SMC_UNK);
  64. }
  65. /* Let PM SMC handler deal with PM-related requests */
  66. if (is_pm_fid(smc_fid)) {
  67. return smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle,
  68. flags);
  69. }
  70. /* Let IPI SMC handler deal with IPI-related requests if platform */
  71. if (is_ipi_fid(smc_fid)) {
  72. return ipi_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
  73. }
  74. /* Let PM SMC handler deal with PM-related requests */
  75. switch (smc_fid) {
  76. case VERSAL_NET_SIP_SVC_UID:
  77. SMC_UUID_RET(handle, versal_net_sip_uuid);
  78. case VERSAL_NET_SIP_SVC_VERSION:
  79. SMC_RET2(handle, SIP_SVC_VERSION_MAJOR, SIP_SVC_VERSION_MINOR);
  80. default:
  81. WARN("Unimplemented SiP Service Call: 0x%x\n", smc_fid);
  82. SMC_RET1(handle, SMC_UNK);
  83. }
  84. }
  85. /* Register PM Service Calls as runtime service */
  86. DECLARE_RT_SVC(
  87. sip_svc,
  88. OEN_SIP_START,
  89. OEN_SIP_END,
  90. SMC_TYPE_FAST,
  91. sip_svc_setup,
  92. sip_svc_smc_handler);