el3_spmd_logical_sp.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Copyright (c) 2023, ARM Limited and Contributors. All rights reserved.
  3. * SPDX-License-Identifier: BSD-3-Clause
  4. */
  5. #ifndef EL3_SPMD_LOGICAL_SP_H
  6. #define EL3_SPMD_LOGICAL_SP_H
  7. #include <common/bl_common.h>
  8. #include <lib/cassert.h>
  9. #include <services/ffa_svc.h>
  10. /*******************************************************************************
  11. * Structure definition, typedefs & constants for the SPMD Logical Partitions.
  12. ******************************************************************************/
  13. typedef struct spmd_spm_core_context spmd_spm_core_context_t;
  14. /* Prototype for SPMD logical partition initializing function. */
  15. typedef int32_t (*ffa_spmd_lp_init_t)(void);
  16. /* SPMD Logical Partition Descriptor. */
  17. struct spmd_lp_desc {
  18. ffa_spmd_lp_init_t init;
  19. uint16_t sp_id;
  20. uint32_t properties;
  21. uint32_t uuid[4]; /* Little Endian. */
  22. const char *debug_name;
  23. };
  24. struct ffa_value {
  25. uint64_t func;
  26. uint64_t arg1;
  27. uint64_t arg2;
  28. uint64_t arg3;
  29. uint64_t arg4;
  30. uint64_t arg5;
  31. uint64_t arg6;
  32. uint64_t arg7;
  33. uint64_t arg8;
  34. uint64_t arg9;
  35. uint64_t arg10;
  36. uint64_t arg11;
  37. uint64_t arg12;
  38. uint64_t arg13;
  39. uint64_t arg14;
  40. uint64_t arg15;
  41. uint64_t arg16;
  42. uint64_t arg17;
  43. };
  44. /* Convenience macro to declare a SPMD logical partition descriptor. */
  45. #define DECLARE_SPMD_LOGICAL_PARTITION(_name, _init, _sp_id, _uuid, _properties) \
  46. static const struct spmd_lp_desc __partition_desc_ ## _name \
  47. __section(".spmd_lp_descs") __used = { \
  48. .debug_name = #_name, \
  49. .init = (_init), \
  50. .sp_id = (_sp_id), \
  51. .uuid = _uuid, \
  52. .properties = (_properties), \
  53. }
  54. IMPORT_SYM(uintptr_t, __SPMD_LP_DESCS_START__, SPMD_LP_DESCS_START);
  55. IMPORT_SYM(uintptr_t, __SPMD_LP_DESCS_END__, SPMD_LP_DESCS_END);
  56. #define SPMD_LP_DESCS_COUNT ((SPMD_LP_DESCS_END - SPMD_LP_DESCS_START) \
  57. / sizeof(struct spmd_lp_desc))
  58. CASSERT(sizeof(struct spmd_lp_desc) == 40, assert_spmd_lp_desc_size_mismatch);
  59. /*
  60. * Reserve 63 IDs for SPMD Logical Partitions. Currently, 0xFFC0 to 0xFFFE
  61. * is reserved.
  62. */
  63. #define SPMD_LP_ID_END (SPMD_DIRECT_MSG_ENDPOINT_ID - 1)
  64. #define SPMD_LP_ID_START (SPMD_LP_ID_END - 62)
  65. /*
  66. * TODO: Arbitrary number. Can make this platform specific in the future,
  67. * no known use cases for more LPs at this point.
  68. */
  69. #define EL3_SPMD_MAX_NUM_LP U(5)
  70. static inline bool is_spmd_lp_id(unsigned int id)
  71. {
  72. #if ENABLE_SPMD_LP
  73. return (id >= SPMD_LP_ID_START && id <= SPMD_LP_ID_END);
  74. #else
  75. return false;
  76. #endif
  77. }
  78. static inline bool is_ffa_error(struct ffa_value *retval)
  79. {
  80. return retval->func == FFA_ERROR;
  81. }
  82. static inline bool is_ffa_success(struct ffa_value *retval)
  83. {
  84. return (retval->func == FFA_SUCCESS_SMC32) ||
  85. (retval->func == FFA_SUCCESS_SMC64);
  86. }
  87. static inline bool is_ffa_direct_msg_resp(struct ffa_value *retval)
  88. {
  89. return (retval->func == FFA_MSG_SEND_DIRECT_RESP_SMC32) ||
  90. (retval->func == FFA_MSG_SEND_DIRECT_RESP_SMC64);
  91. }
  92. static inline uint16_t ffa_partition_info_regs_get_last_idx(
  93. struct ffa_value *args)
  94. {
  95. return (uint16_t)(args->arg2 & 0xFFFFU);
  96. }
  97. static inline uint16_t ffa_partition_info_regs_get_curr_idx(
  98. struct ffa_value *args)
  99. {
  100. return (uint16_t)((args->arg2 >> 16) & 0xFFFFU);
  101. }
  102. static inline uint16_t ffa_partition_info_regs_get_tag(struct ffa_value *args)
  103. {
  104. return (uint16_t)((args->arg2 >> 32) & 0xFFFFU);
  105. }
  106. static inline uint16_t ffa_partition_info_regs_get_desc_size(
  107. struct ffa_value *args)
  108. {
  109. return (uint16_t)(args->arg2 >> 48);
  110. }
  111. uint64_t spmd_el3_populate_logical_partition_info(void *handle, uint64_t x1,
  112. uint64_t x2, uint64_t x3);
  113. bool ffa_partition_info_regs_get_part_info(
  114. struct ffa_value *args, uint8_t idx,
  115. struct ffa_partition_info_v1_1 *partition_info);
  116. bool spmd_el3_invoke_partition_info_get(
  117. const uint32_t target_uuid[4],
  118. const uint16_t start_index,
  119. const uint16_t tag,
  120. struct ffa_value *retval);
  121. void spmd_logical_sp_set_spmc_initialized(void);
  122. void spmc_logical_sp_set_spmc_failure(void);
  123. int32_t spmd_logical_sp_init(void);
  124. bool is_spmd_logical_sp_dir_req_in_progress(
  125. spmd_spm_core_context_t *ctx);
  126. bool is_spmd_logical_sp_info_regs_req_in_progress(
  127. spmd_spm_core_context_t *ctx);
  128. bool spmd_el3_ffa_msg_direct_req(uint64_t x1,
  129. uint64_t x2,
  130. uint64_t x3,
  131. uint64_t x4,
  132. void *handle,
  133. struct ffa_value *retval);
  134. uintptr_t plat_spmd_logical_sp_smc_handler(unsigned int smc_fid,
  135. u_register_t x1,
  136. u_register_t x2,
  137. u_register_t x3,
  138. u_register_t x4,
  139. void *cookie,
  140. void *handle,
  141. u_register_t flags);
  142. #endif /* EL3_SPMD_LOGICAL_SP_H */