sip_svc_setup.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (c) 2013-2020, Arm Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2023, 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/runtime_svc.h>
  10. #include <tools_share/uuid.h>
  11. #include <custom_svc.h>
  12. #include "ipi_mailbox_svc.h"
  13. #include "pm_defs.h"
  14. #include "zynqmp_pm_svc_main.h"
  15. /* SMC function IDs for SiP Service queries */
  16. #define ZYNQMP_SIP_SVC_UID U(0x8200ff01)
  17. #define ZYNQMP_SIP_SVC_VERSION U(0x8200ff03)
  18. /* SiP Service Calls version numbers */
  19. #define SIP_SVC_VERSION_MAJOR 0
  20. #define SIP_SVC_VERSION_MINOR 1
  21. /* These macros are used to identify PM, IPI calls from the SMC function ID */
  22. #define SIP_FID_MASK GENMASK(23, 16)
  23. #define XLNX_FID_MASK GENMASK(23, 12)
  24. #define PM_FID_VALUE 0u
  25. #define IPI_FID_VALUE 0x1000u
  26. #define is_pm_fid(_fid) (((_fid) & XLNX_FID_MASK) == PM_FID_VALUE)
  27. #define is_ipi_fid(_fid) (((_fid) & XLNX_FID_MASK) == IPI_FID_VALUE)
  28. /* SiP Service UUID */
  29. DEFINE_SVC_UUID2(zynqmp_sip_uuid,
  30. 0x5c9b1b2a, 0x0586, 0x2340, 0xa6, 0x1b,
  31. 0xb9, 0x25, 0x82, 0x2d, 0xe3, 0xa5);
  32. /**
  33. * sip_svc_setup() - Setup SiP Service.
  34. *
  35. * Return: On success, the initialization function must return 0.
  36. * Any other return value will cause the framework to ignore
  37. * the service.
  38. *
  39. * Invokes PM setup.
  40. */
  41. static int32_t sip_svc_setup(void)
  42. {
  43. /* PM implementation as SiP Service */
  44. return pm_setup();
  45. }
  46. /**
  47. * sip_svc_smc_handler() - Top-level SiP Service SMC handler
  48. * @smc_fid: Function Identifier.
  49. * @x1: SMC64 Arguments 1 from kernel.
  50. * @x2: SMC64 Arguments 2 from kernel.
  51. * @x3: SMC64 Arguments 3 from kernel(upper 32-bits).
  52. * @x4: SMC64 Arguments 4 from kernel.
  53. * @cookie: Unused
  54. * @handle: Pointer to caller's context structure.
  55. * @flags: SECURE_FLAG or NON_SECURE_FLAG.
  56. *
  57. * Handler for all SiP SMC calls. Handles standard SIP requests
  58. * and calls PM SMC handler if the call is for a PM-API function.
  59. *
  60. * Return: Unused.
  61. */
  62. static uintptr_t sip_svc_smc_handler(uint32_t smc_fid,
  63. u_register_t x1,
  64. u_register_t x2,
  65. u_register_t x3,
  66. u_register_t x4,
  67. void *cookie,
  68. void *handle,
  69. u_register_t flags)
  70. {
  71. VERBOSE("SMCID: 0x%08x, x1: 0x%016" PRIx64 ", x2: 0x%016" PRIx64 ", x3: 0x%016" PRIx64 ", x4: 0x%016" PRIx64 "\n",
  72. smc_fid, x1, x2, x3, x4);
  73. if ((smc_fid & (uint32_t)SIP_FID_MASK) != 0U) {
  74. WARN("SMC out of SiP assinged range: 0x%x\n", smc_fid);
  75. SMC_RET1(handle, SMC_UNK);
  76. }
  77. /* Let PM SMC handler deal with PM-related requests */
  78. if (is_pm_fid(smc_fid)) {
  79. return pm_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle,
  80. flags);
  81. }
  82. /* Let IPI SMC handler deal with IPI-related requests */
  83. if (is_ipi_fid(smc_fid)) {
  84. return ipi_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle,
  85. flags);
  86. }
  87. switch (smc_fid) {
  88. case ZYNQMP_SIP_SVC_UID:
  89. SMC_UUID_RET(handle, zynqmp_sip_uuid);
  90. case ZYNQMP_SIP_SVC_VERSION:
  91. SMC_RET2(handle, SIP_SVC_VERSION_MAJOR, SIP_SVC_VERSION_MINOR);
  92. case ZYNQMP_SIP_SVC_CUSTOM:
  93. case ZYNQMP_SIP_SVC64_CUSTOM:
  94. return custom_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
  95. handle, flags);
  96. default:
  97. WARN("Unimplemented SiP Service Call: 0x%x\n", smc_fid);
  98. SMC_RET1(handle, SMC_UNK);
  99. }
  100. }
  101. /* Register PM Service Calls as runtime service */
  102. DECLARE_RT_SVC(
  103. sip_svc,
  104. OEN_SIP_START,
  105. OEN_SIP_END,
  106. (uint8_t)SMC_TYPE_FAST,
  107. sip_svc_setup,
  108. sip_svc_smc_handler);