plat_arm_sip_svc.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (c) 2023-2024, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stdint.h>
  7. #include <errno.h>
  8. #include <common/debug.h>
  9. #include <common/runtime_svc.h>
  10. #include <plat/arm/common/arm_sip_svc.h>
  11. #include <plat/common/platform.h>
  12. #if ENABLE_RME && SPMD_SPM_AT_SEL2
  13. #include <lib/gpt_rme/gpt_rme.h>
  14. #endif
  15. #if ENABLE_SPMD_LP
  16. #include <services/el3_spmd_logical_sp.h>
  17. #endif
  18. #if (ENABLE_RME == 1) && (defined(SPD_spmd) && SPMD_SPM_AT_SEL2 == 1)
  19. static uint64_t plat_protect_memory(bool protect,
  20. bool secure_origin,
  21. const uint64_t base,
  22. const size_t size,
  23. void *handle)
  24. {
  25. uint64_t ret = SMC_INVALID_PARAM;
  26. uint64_t last_updated = 0;
  27. if (!secure_origin) {
  28. SMC_RET1(handle, SMC_UNK);
  29. /* Shall not be reached. */
  30. }
  31. if ((base % PAGE_SIZE_4KB) != 0U &&
  32. (size % PAGE_SIZE_4KB) != 0U) {
  33. VERBOSE("Base address must be aligned to 4k.\n");
  34. SMC_RET1(handle, SMC_INVALID_PARAM);
  35. /* Shall not be reached. */
  36. }
  37. if ((ULONG_MAX - base) < size) {
  38. VERBOSE("Base + Size results in overflow.\n");
  39. SMC_RET1(handle, SMC_INVALID_PARAM);
  40. /* Shall not be reached. */
  41. }
  42. for (uint64_t it = base; it < (base + size); it += PAGE_SIZE_4KB) {
  43. /*
  44. * If protect is true, add memory to secure PAS.
  45. * Else unprotect it, making part of non-secure PAS.
  46. */
  47. ret = protect
  48. ? gpt_delegate_pas(it, PAGE_SIZE_4KB,
  49. SMC_FROM_SECURE)
  50. : gpt_undelegate_pas(it, PAGE_SIZE_4KB,
  51. SMC_FROM_SECURE);
  52. switch (ret) {
  53. case 0:
  54. last_updated = it;
  55. break;
  56. case -EINVAL:
  57. SMC_RET2(handle, SMC_INVALID_PARAM, last_updated);
  58. break; /* Shall not be reached. */
  59. case -EPERM:
  60. SMC_RET2(handle, SMC_DENIED, last_updated);
  61. break; /* Shall not be reached. */
  62. default:
  63. ERROR("Unexpected return\n");
  64. panic();
  65. }
  66. }
  67. SMC_RET1(handle, SMC_OK);
  68. }
  69. #endif /* ENABLE_RME && SPMD_SPM_AT_SEL2 */
  70. uintptr_t plat_arm_sip_handler(uint32_t smc_fid,
  71. u_register_t x1,
  72. u_register_t x2,
  73. u_register_t x3,
  74. u_register_t x4,
  75. void *cookie,
  76. void *handle,
  77. u_register_t flags)
  78. {
  79. bool secure_origin;
  80. /* Determine which security state this SMC originated from */
  81. secure_origin = is_caller_secure(flags);
  82. (void) secure_origin;
  83. switch (smc_fid) {
  84. #if PLAT_TEST_SPM
  85. case ARM_SIP_SET_INTERRUPT_PENDING:
  86. if (!secure_origin) {
  87. SMC_RET1(handle, SMC_UNK);
  88. }
  89. VERBOSE("SiP Call- Set interrupt pending %d\n", (uint32_t)x1);
  90. plat_ic_set_interrupt_pending(x1);
  91. SMC_RET1(handle, SMC_OK);
  92. break; /* Not reached */
  93. #endif
  94. #if (ENABLE_RME == 1) && (defined(SPD_spmd) && SPMD_SPM_AT_SEL2 == 1)
  95. case PLAT_PROTECT_MEM_SMC64:
  96. VERBOSE("Sip Call - Protect memory\n");
  97. return plat_protect_memory(true, secure_origin, x1, x2, handle);
  98. break;
  99. case PLAT_UNPROTECT_MEM_SMC64:
  100. VERBOSE("Sip Call - Unprotect memory\n");
  101. return plat_protect_memory(false, secure_origin, x1, x2, handle);
  102. break;
  103. #endif
  104. }
  105. #if ENABLE_SPMD_LP
  106. return plat_spmd_logical_sp_smc_handler(smc_fid, x1, x2, x3, x4,
  107. cookie, handle, flags);
  108. #else
  109. WARN("Unimplemented ARM SiP Service Call: 0x%x\n", smc_fid);
  110. SMC_RET1(handle, SMC_UNK);
  111. #endif
  112. }