refactor(ff-a): add payload getters
Add `ffa_partition_msg_payload` and `ffa_partition_msg_payload_const`
functions for accessing the the payload of the partition message.
These functions are necessary because the `.payload` field does not
necessary correspond to the `.offset` field.
Change-Id: I91246a084ccb68c02809b3e1afe85b07482bfb1b
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
diff --git a/inc/vmapi/hf/ffa.h b/inc/vmapi/hf/ffa.h
index 93c9228..875bd94 100644
--- a/inc/vmapi/hf/ffa.h
+++ b/inc/vmapi/hf/ffa.h
@@ -553,6 +553,21 @@
static_assert(sizeof(struct ffa_partition_msg) == HF_MAILBOX_SIZE,
"FF-A message size must match mailbox size");
+/**
+ * Get the partition message's payload, according to the header's `offset`
+ * field.
+ */
+static inline void *ffa_partition_msg_payload(struct ffa_partition_msg *msg)
+{
+ return (char *)msg + msg->header.offset;
+}
+
+static inline const void *ffa_partition_msg_payload_const(
+ const struct ffa_partition_msg *msg)
+{
+ return (const char *)msg + msg->header.offset;
+}
+
/* The maximum length possible for a single message. */
#define FFA_MSG_PAYLOAD_MAX HF_MAILBOX_SIZE
diff --git a/test/hftest/service_common.c b/test/hftest/service_common.c
index 6ac9162..78f6400 100644
--- a/test/hftest/service_common.c
+++ b/test/hftest/service_common.c
@@ -287,7 +287,7 @@
struct fdt fdt;
const ffa_id_t own_id = hf_vm_get_id();
ffa_notifications_bitmap_t bitmap;
- struct ffa_partition_msg *message;
+ const struct ffa_partition_msg *message;
uint32_t vcpu = get_current_vcpu_index();
ctx = hftest_get_context();
@@ -356,7 +356,8 @@
ASSERT_EQ(hf_interrupt_get(), HF_NOTIFICATION_PENDING_INTID);
}
- memiter_init(&args, message->payload, message->header.size);
+ memiter_init(&args, ffa_partition_msg_payload_const(message),
+ message->header.size);
/* Find service handler. */
service = find_service(&args);
diff --git a/test/inc/test/vmapi/ffa.h b/test/inc/test/vmapi/ffa.h
index 290c0a4..897eb0b 100644
--- a/test/inc/test/vmapi/ffa.h
+++ b/test/inc/test/vmapi/ffa.h
@@ -64,7 +64,8 @@
struct mailbox_buffers set_up_mailbox(void);
void mailbox_unmap_buffers(struct mailbox_buffers *mb);
-void mailbox_receive_retry(void *buffer, size_t buffer_size, void *recv,
+void mailbox_receive_retry(void *payload, size_t payload_size,
+ const void *recv_buf,
struct ffa_partition_rxtx_header *header);
ffa_memory_handle_t send_memory_and_retrieve_request_multi_receiver(
uint32_t share_func, void *tx_buffer, ffa_id_t sender,
diff --git a/test/vmapi/common/arch/aarch64/exception_handler.c b/test/vmapi/common/arch/aarch64/exception_handler.c
index 6ace93e..6eff1f7 100644
--- a/test/vmapi/common/arch/aarch64/exception_handler.c
+++ b/test/vmapi/common/arch/aarch64/exception_handler.c
@@ -9,6 +9,7 @@
#include "test/vmapi/arch/exception_handler.h"
#include "hf/dlog.h"
+#include "hf/ffa.h"
#include "vmapi/hf/call.h"
@@ -70,8 +71,8 @@
*/
ffa_rxtx_header_init(&exception_msg->header, hf_vm_get_id(),
HF_PRIMARY_VM_ID, sizeof(int));
- memcpy_s(exception_msg->payload, FFA_MSG_PAYLOAD_MAX,
- (const void *)&exception_handler_exception_count,
+ memcpy_s(ffa_partition_msg_payload(exception_msg), FFA_MSG_PAYLOAD_MAX,
+ &exception_handler_exception_count,
sizeof(exception_handler_exception_count));
EXPECT_EQ(ffa_msg_send2(0).func, FFA_SUCCESS_32);
ffa_yield();
@@ -84,7 +85,8 @@
{
struct ffa_partition_msg *exception_msg =
(struct ffa_partition_msg *)recv_buf;
- int exception_count = *((const int *)exception_msg->payload);
+ int exception_count =
+ *((const int *)ffa_partition_msg_payload_const(exception_msg));
struct ffa_value ret;
ffa_notifications_bitmap_t fwk_notif;
diff --git a/test/vmapi/common/ffa.c b/test/vmapi/common/ffa.c
index 13871ba..f895572 100644
--- a/test/vmapi/common/ffa.c
+++ b/test/vmapi/common/ffa.c
@@ -49,19 +49,19 @@
* Try to receive a message from the mailbox, blocking if necessary, and
* retrying if interrupted.
*/
-void mailbox_receive_retry(void *buffer, size_t buffer_size, void *recv,
+void mailbox_receive_retry(void *payload, size_t payload_size,
+ const void *recv_buf,
struct ffa_partition_rxtx_header *header)
{
const struct ffa_partition_msg *message;
- const uint32_t *payload;
ffa_id_t sender;
struct ffa_value ret;
ffa_notifications_bitmap_t fwk_notif = 0U;
const ffa_id_t own_id = hf_vm_get_id();
- ASSERT_LE(buffer_size, FFA_MSG_PAYLOAD_MAX);
+ ASSERT_LE(payload_size, FFA_MSG_PAYLOAD_MAX);
ASSERT_TRUE(header != NULL);
- ASSERT_TRUE(recv != NULL);
+ ASSERT_TRUE(recv_buf != NULL);
/* Check notification and wait if not messages. */
while (fwk_notif == 0U) {
@@ -78,10 +78,8 @@
}
}
- message = (const struct ffa_partition_msg *)recv;
- memcpy_s(header, sizeof(*header), message,
- sizeof(struct ffa_partition_rxtx_header));
-
+ message = (const struct ffa_partition_msg *)recv_buf;
+ *header = message->header;
sender = header->sender;
if (is_ffa_hyp_buffer_full_notification(fwk_notif)) {
@@ -92,12 +90,11 @@
/* Check receiver ID against own ID. */
ASSERT_EQ(header->sender, own_id);
- ASSERT_LE(header->size, buffer_size);
-
- payload = (const uint32_t *)message->payload;
+ ASSERT_LE(header->size, payload_size);
/* Get message to free the RX buffer. */
- memcpy_s(buffer, buffer_size, payload, header->size);
+ memcpy_s(payload, payload_size,
+ ffa_partition_msg_payload_const(message), header->size);
EXPECT_EQ(ffa_rx_release().func, FFA_SUCCESS_32);
}
@@ -548,7 +545,7 @@
{
uint32_t msg_size;
ffa_id_t sender;
- struct ffa_memory_region *retrieve_request;
+ const struct ffa_memory_region *retrieve_request;
ffa_memory_handle_t retrieved_handle;
const struct ffa_partition_msg *retrv_message =
get_mailbox_message(recv_buf);
@@ -559,13 +556,13 @@
sender = retrv_message->header.sender;
msg_size = retrv_message->header.size;
- retrieve_request = (struct ffa_memory_region *)retrv_message->payload;
+ retrieve_request = ffa_partition_msg_payload_const(retrv_message);
retrieved_handle = retrieve_request->handle;
if (ret_handle != NULL) {
*ret_handle = retrieved_handle;
}
- memcpy_s(send_buf, HF_MAILBOX_SIZE, retrv_message->payload, msg_size);
+ memcpy_s(send_buf, HF_MAILBOX_SIZE, retrieve_request, msg_size);
ASSERT_EQ(ffa_rx_release().func, FFA_SUCCESS_32);
@@ -599,7 +596,7 @@
uint32_t msg_size;
struct ffa_value ret;
ffa_id_t sender;
- struct ffa_memory_region *retrieve_request;
+ const struct ffa_memory_region *retrieve_request;
const struct ffa_partition_msg *retrv_message =
get_mailbox_message(recv_buf);
@@ -608,7 +605,7 @@
sender = retrv_message->header.sender;
msg_size = retrv_message->header.size;
- retrieve_request = (struct ffa_memory_region *)retrv_message->payload;
+ retrieve_request = ffa_partition_msg_payload_const(retrv_message);
memcpy_s(send_buf, HF_MAILBOX_SIZE, retrieve_request, msg_size);
ASSERT_EQ(ffa_rx_release().func, FFA_SUCCESS_32);
@@ -746,7 +743,6 @@
const struct ffa_partition_msg *message;
struct ffa_partition_rxtx_header header;
ffa_id_t source_vm_id;
- const uint32_t *payload;
struct ffa_value ret;
ffa_notifications_bitmap_t fwk_notif;
const ffa_id_t own_id = hf_vm_get_id();
@@ -781,10 +777,9 @@
ASSERT_EQ(header.receiver, own_id);
ASSERT_LE(header.size, buffer_size);
- payload = (const uint32_t *)message->payload;
-
/* Get message to free the RX buffer. */
- memcpy_s(buffer, buffer_size, payload, header.size);
+ memcpy_s(buffer, buffer_size, ffa_partition_msg_payload_const(message),
+ header.size);
EXPECT_EQ(ffa_rx_release().func, FFA_SUCCESS_32);