ffa_helpers.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (c) 2022, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef FFA_HELPERS_H
  7. #define FFA_HELPERS_H
  8. #include <stdint.h>
  9. #include "../../services/std_svc/spm/el3_spmc/spmc.h"
  10. #include "../../services/std_svc/spm/el3_spmc/spmc_shared_mem.h"
  11. #include <services/el3_spmc_ffa_memory.h>
  12. #include <services/ffa_svc.h>
  13. #include "tsp_private.h"
  14. static inline uint32_t ffa_func_id(smc_args_t val)
  15. {
  16. return (uint32_t) val._regs[0];
  17. }
  18. static inline int32_t ffa_error_code(smc_args_t val)
  19. {
  20. return (uint32_t) val._regs[2];
  21. }
  22. extern uint8_t mem_region_buffer[4096 * 2] __aligned(PAGE_SIZE);
  23. #define REGION_BUF_SIZE sizeof(mem_region_buffer)
  24. /** The maximum number of recipients a memory region may be sent to. */
  25. #define MAX_MEM_SHARE_RECIPIENTS 2U
  26. /* FFA Memory Management mode flags. */
  27. #define FFA_FLAG_SHARE_MEMORY (1U << 3)
  28. #define FFA_FLAG_LEND_MEMORY (1U << 4)
  29. #define FFA_FLAG_MEMORY_MASK (3U << 3)
  30. #define FFA_MEM_HANDLE_LOW(x) (x & 0xFFFFFFFF)
  31. #define FFA_MEM_HANDLE_HIGH(x) (x >> 32)
  32. #define FFA_MEM_PERM_DATA_OFFSET 0
  33. #define FFA_MEM_PERM_DATA_MASK 0x3
  34. static inline uint32_t ffa_mem_relinquish_init(
  35. struct ffa_mem_relinquish_descriptor *relinquish_request,
  36. uint64_t handle, ffa_mtd_flag32_t flags,
  37. ffa_endpoint_id16_t sender)
  38. {
  39. relinquish_request->handle = handle;
  40. relinquish_request->flags = flags;
  41. relinquish_request->endpoint_count = 1;
  42. relinquish_request->endpoint_array[0] = sender;
  43. return sizeof(struct ffa_mem_relinquish_descriptor) + sizeof(ffa_endpoint_id16_t);
  44. }
  45. /**
  46. * Gets the `ffa_comp_mrd` for the given receiver from an
  47. * `ffa_mtd`, or NULL if it is not valid.
  48. */
  49. static inline struct ffa_comp_mrd *
  50. ffa_memory_region_get_composite(struct ffa_mtd *memory_region,
  51. uint32_t receiver_index)
  52. {
  53. struct ffa_emad_v1_0 *receivers;
  54. uint32_t offset;
  55. receivers = (struct ffa_emad_v1_0 *)
  56. ((uint8_t *) memory_region +
  57. memory_region->emad_offset +
  58. (memory_region->emad_size * receiver_index));
  59. offset = receivers->comp_mrd_offset;
  60. if (offset == 0U) {
  61. return NULL;
  62. }
  63. return (struct ffa_comp_mrd *)
  64. ((uint8_t *) memory_region + offset);
  65. }
  66. static inline uint32_t ffa_get_data_access_attr(ffa_mem_perm8_t perm)
  67. {
  68. return ((perm >> FFA_MEM_PERM_DATA_OFFSET) & FFA_MEM_PERM_DATA_MASK);
  69. }
  70. smc_args_t ffa_mem_frag_rx(uint64_t handle, uint32_t recv_length);
  71. bool ffa_mem_relinquish(void);
  72. bool ffa_rx_release(void);
  73. bool memory_relinquish(struct ffa_mem_relinquish_descriptor *m, uint64_t handle,
  74. ffa_endpoint_id16_t id);
  75. bool ffa_rxtx_map(uintptr_t send, uintptr_t recv, uint32_t pages);
  76. bool memory_retrieve(struct mailbox *mb,
  77. struct ffa_mtd **retrieved,
  78. uint64_t handle, ffa_endpoint_id16_t sender,
  79. ffa_endpoint_id16_t *receivers, uint32_t receiver_count,
  80. ffa_mtd_flag32_t flags, uint32_t *frag_length,
  81. uint32_t *total_length);
  82. smc_args_t ffa_msg_send_direct_req(ffa_endpoint_id16_t sender,
  83. ffa_endpoint_id16_t receiver,
  84. uint32_t arg3,
  85. uint32_t arg4,
  86. uint32_t arg5,
  87. uint32_t arg6,
  88. uint32_t arg7);
  89. smc_args_t *ffa_msg_send_direct_resp(ffa_endpoint_id16_t sender,
  90. ffa_endpoint_id16_t receiver,
  91. uint32_t arg3,
  92. uint32_t arg4,
  93. uint32_t arg5,
  94. uint32_t arg6,
  95. uint32_t arg7);
  96. #endif /* FFA_HELPERS_H */