feat(ff-a): report RXTX buffer size in FFA_FEATURES

FF-A v1.2 ALP1 requires that FFA_FEATURES with function id=FFA_RXTX_MAP
must report the minimum and maximum buffer sizes required for the RXTX
buffers. The patch does this when the ffa version is at least 1.2.

Change-Id: I7e765fdec4bcad3a09c4a04af57c690474a21a5a
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
diff --git a/inc/hf/ffa_memory_internal.h b/inc/hf/ffa_memory_internal.h
index dac131d..f240ca2 100644
--- a/inc/hf/ffa_memory_internal.h
+++ b/inc/hf/ffa_memory_internal.h
@@ -49,6 +49,10 @@
 static_assert(sizeof(((struct ffa_memory_region){0}).receiver_count == 4),
 	      "struct ffa_memory_region::receiver_count must be 4 bytes long");
 
+static_assert(sizeof(struct ffa_features_rxtx_map_params) == 4,
+	      "struct ffa_features_rxtx_map_params must be 4 "
+	      "bytes long");
+
 struct ffa_memory_share_state {
 	/**
 	 * The memory region being shared, or NULL if this share state is
diff --git a/inc/vmapi/hf/ffa.h b/inc/vmapi/hf/ffa.h
index acaff6d..6a1324a 100644
--- a/inc/vmapi/hf/ffa.h
+++ b/inc/vmapi/hf/ffa.h
@@ -1288,6 +1288,32 @@
 	struct ffa_memory_region_constituent *dest,
 	const struct ffa_memory_region_constituent *src);
 
+struct ffa_features_rxtx_map_params {
+	/*
+	 * Bit[0:1]:
+	 * Minimum buffer size and alignment boundary:
+	 * 0b00: 4K
+	 * 0b01: 64K
+	 * 0b10: 16K
+	 * 0b11: Reserved
+	 */
+	uint8_t min_buf_size : 2;
+	/*
+	 * Bit[2:15]:
+	 * Reserved (MBZ)
+	 */
+	uint16_t mbz : 14;
+	/*
+	 * Bit[16:32]:
+	 * Maximum buffer size in number of pages
+	 * Only present on version 1.2 or later
+	 */
+	uint16_t max_buf_size : 16;
+};
+
+#define FFA_RXTX_MAP_MIN_BUF_4K 0
+#define FFA_RXTX_MAP_MAX_BUF_PAGE_COUNT 1
+
 /**
  * Endpoint RX/TX descriptor, as defined by Table 13.27 in FF-A v1.1 EAC0.
  * It's used by the Hypervisor to describe the RX/TX buffers mapped by a VM
diff --git a/src/api.c b/src/api.c
index 9cb7c6c..196c8e7 100644
--- a/src/api.c
+++ b/src/api.c
@@ -2454,7 +2454,6 @@
 	case FFA_VERSION_32:
 	case FFA_FEATURES_32:
 	case FFA_RX_RELEASE_32:
-	case FFA_RXTX_MAP_64:
 	case FFA_RXTX_UNMAP_32:
 	case FFA_PARTITION_INFO_GET_32:
 	case FFA_ID_GET_32:
@@ -2497,6 +2496,24 @@
 	case FFA_MSG_SEND_DIRECT_RESP2_64:
 #endif
 		return (struct ffa_value){.func = FFA_SUCCESS_32};
+	case FFA_RXTX_MAP_64: {
+		uint32_t arg2 = 0;
+		struct ffa_features_rxtx_map_params params = {
+			.min_buf_size = FFA_RXTX_MAP_MIN_BUF_4K,
+			.mbz = 0,
+			.max_buf_size =
+				(ffa_version >= MAKE_FFA_VERSION(1, 2))
+					? FFA_RXTX_MAP_MAX_BUF_PAGE_COUNT
+					: 0,
+		};
+
+		memcpy_s(&arg2, sizeof(arg2), &params, sizeof(params));
+		return (struct ffa_value){
+			.func = FFA_SUCCESS_32,
+			.arg2 = arg2,
+		};
+	}
+
 	case FFA_MEM_RETRIEVE_REQ_32:
 		if ((input_property & FFA_FEATURES_MEM_RETRIEVE_REQ_MBZ_MASK) !=
 		    0U) {