Add FF-A v1.1 format FFA_PARTITION_INFO_GET support

FF-A v1.0 and v1.1 functions are conditionally compiled based on the
selected FF-A version macro value.

Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: I03fbdaa14202134066e693f74103a2a3be765a10
diff --git a/components/messaging/ffa/libsp/ffa.c b/components/messaging/ffa/libsp/ffa.c
index 1afe44d..89fd8fe 100644
--- a/components/messaging/ffa/libsp/ffa.c
+++ b/components/messaging/ffa/libsp/ffa.c
@@ -173,6 +173,7 @@
 	return FFA_OK;
 }
 
+#if CFG_FFA_VERSION == FFA_VERSION_1_0
 ffa_result ffa_partition_info_get(const struct ffa_uuid *uuid, uint32_t *count)
 {
 	struct ffa_params result = {0};
@@ -193,6 +194,31 @@
 	*count = result.a2;
 	return FFA_OK;
 }
+#elif CFG_FFA_VERSION >= FFA_VERSION_1_1
+ffa_result ffa_partition_info_get(const struct ffa_uuid *uuid, uint32_t flags, uint32_t *count,
+				  uint32_t *size)
+{
+	struct ffa_params result = {0};
+	uint32_t abi_uuid[4] = {0};
+
+	ffa_uuid_to_abi_format(uuid, abi_uuid);
+
+	ffa_svc(FFA_PARTITION_INFO_GET, abi_uuid[0], abi_uuid[1], abi_uuid[2],
+		abi_uuid[3], flags, FFA_PARAM_MBZ, FFA_PARAM_MBZ,
+		&result);
+
+	if (result.a0 == FFA_ERROR) {
+		*count = UINT32_C(0);
+		*size = UINT32_C(0);
+		return ffa_get_errorcode(&result);
+	}
+
+	assert(result.a0 == FFA_SUCCESS_32);
+	*count = result.a2;
+	*size = result.a3;
+	return FFA_OK;
+}
+#endif /* CFG_FFA_VERSION */
 
 ffa_result ffa_id_get(uint16_t *id)
 {
diff --git a/components/messaging/ffa/libsp/include/ffa_api.h b/components/messaging/ffa/libsp/include/ffa_api.h
index e18e381..82541f7 100644
--- a/components/messaging/ffa/libsp/include/ffa_api.h
+++ b/components/messaging/ffa/libsp/include/ffa_api.h
@@ -82,12 +82,14 @@
  */
 ffa_result ffa_rxtx_unmap(uint16_t id);
 
+#if CFG_FFA_VERSION == FFA_VERSION_1_0
 /**
- * @brief      Requests the SPM to return information about the partition of
+ * @brief      Requests the SPM to return information about the partitions of
  *             the system. Nil UUID can be used to return information about all
  *             the SPs of the system. The information is returned in the RX
  *             buffer of the caller as an array of ffa_partition_information
  *             structures.
+ *             This is an FF-A v1.0 call.
  *
  * @param[in]  uuid   The uuid
  * @param[out] count  Count of partition information descriptors populated in
@@ -96,6 +98,27 @@
  * @return     The FF-A error status code
  */
 ffa_result ffa_partition_info_get(const struct ffa_uuid *uuid, uint32_t *count);
+#elif CFG_FFA_VERSION >= FFA_VERSION_1_1
+
+/**
+ * @brief      Requests the SPM to return information about the partitions of
+ *             the system. Nil UUID can be used to return information about all
+ *             the SPs of the system. The information is returned in the RX
+ *             buffer of the caller as an array of ffa_partition_information
+ *             structures.
+ *             By settings the flags parameter, the function can be instructed
+ *             to only return the count of SPs with the matching UUID.
+ *             This is an FF-A v1.1 call.
+ *
+ * @param[in]  uuid     The uuid
+ * @param[in]  flags	FFA_PARTITION_INFO_GET_FLAG_* flag value
+ * @param[out] count    Count of matching SPs
+ * @param[out] size     Size of the partition information descriptors
+ * @return ffa_result
+ */
+ffa_result ffa_partition_info_get(const struct ffa_uuid *uuid, uint32_t flags,
+				  uint32_t *count, uint32_t *size);
+#endif /* CFG_FFA_VERSION */
 
 /**
  * @brief      Returns the 16 bit ID of the calling FF-A component
diff --git a/components/messaging/ffa/libsp/include/ffa_api_defines.h b/components/messaging/ffa/libsp/include/ffa_api_defines.h
index 007860f..65a429c 100644
--- a/components/messaging/ffa/libsp/include/ffa_api_defines.h
+++ b/components/messaging/ffa/libsp/include/ffa_api_defines.h
@@ -154,9 +154,28 @@
 #define FFA_RXTX_UNMAP_ID_MASK				GENMASK_32(15, 0)
 
 /* FFA_PARTITION_INFO_GET */
+#if CFG_FFA_VERSION >= FFA_VERSION_1_1
+#define FFA_PARTITION_INFO_GET_FLAG_COUNT_ONLY		BIT32(0)
+#endif /* CFG_FFA_VERSION */
+
 #define FFA_PARTITION_SUPPORTS_DIRECT_REQUESTS		BIT32(0)
 #define FFA_PARTITION_CAN_SEND_DIRECT_REQUESTS		BIT32(1)
 #define FFA_PARTITION_SUPPORTS_INDIRECT_REQUESTS	BIT32(2)
+#if CFG_FFA_VERSION >= FFA_VERSION_1_1
+#define FFA_PARTITION_SUPPORTS_NOTIFICATIONS		BIT32(3)
+
+#define FFA_PARTITION_PART_ID_SHIFT			UINT32_C(4)
+#define FFA_PARTITION_PART_ID_MASK			GENMASK_32(1, 0)
+#define FFA_PARTITION_PART_ID_PE_ENDPOINT_ID		UINT16_C(0)
+#define FFA_PARTITION_PART_ID_SEPID_INDEPENDENT		UINT16_C(1)
+#define FFA_PARTITION_PART_ID_SEPID_DEPENDENT		UINT16_C(2)
+#define FFA_PARTITION_PART_ID_PE_AUX_ID			UINT16_C(3)
+
+#define FFA_PARTITION_INFORM_VM_CREATE			BIT32(6)
+#define FFA_PARTITION_INFORM_VM_DESTROY			BIT32(7)
+
+#define FFA_PARTITION_AARCH64_EXECUTION_STATE		BIT32(8)
+#endif /* CFG_FFA_VERSION */
 
 /* FFA_ID_GET */
 #define FFA_ID_GET_ID_SHIFT				UINT32_C(0)
diff --git a/components/messaging/ffa/libsp/include/ffa_api_types.h b/components/messaging/ffa/libsp/include/ffa_api_types.h
index 7156c02..0e7e6ae 100644
--- a/components/messaging/ffa/libsp/include/ffa_api_types.h
+++ b/components/messaging/ffa/libsp/include/ffa_api_types.h
@@ -7,6 +7,7 @@
 #define LIBSP_INCLUDE_FFA_API_TYPES_H_
 
 #include "compiler.h"
+#include "ffa_api_defines.h"
 #include <stddef.h>
 #include <stdint.h>
 
@@ -90,12 +91,16 @@
 };
 
 /**
- * @brief Table 8.25: Partition information descriptor
+ * @brief Table 8.25: Partition information descriptor (FF-A v1.0)
+ *        Table 13.37: Partition information descriptor (FF-A v1.1)
  */
 struct ffa_partition_information {
 	uint16_t partition_id;
 	uint16_t execution_context_count;
 	uint32_t partition_properties;
+#if CFG_FFA_VERSION >= FFA_VERSION_1_1
+	struct ffa_uuid uuid;
+#endif
 } __packed;
 
 /**
diff --git a/components/messaging/ffa/libsp/include/sp_discovery.h b/components/messaging/ffa/libsp/include/sp_discovery.h
index 977c875..968aee8 100644
--- a/components/messaging/ffa/libsp/include/sp_discovery.h
+++ b/components/messaging/ffa/libsp/include/sp_discovery.h
@@ -19,12 +19,33 @@
 	uint8_t uuid[16];
 };
 
+#if CFG_FFA_VERSION >= FFA_VERSION_1_1
+enum sp_partition_id_type {
+	sp_partition_id_type_pe_endpoint_id = 0,
+	sp_partition_id_type_sepid_independent,
+	sp_partition_id_type_sepid_dependent,
+	sp_partition_id_type_auxiliary_id
+};
+
+enum sp_execution_state {
+	sp_execution_state_aarch32 = 0,
+	sp_execution_state_aarch64,
+};
+#endif /* CFG_FFA_VERSION */
+
 struct sp_partition_info {
 	uint16_t partition_id;
 	uint16_t execution_context_count;
 	bool supports_direct_requests;
 	bool can_send_direct_requests;
 	bool supports_indirect_requests;
+#if CFG_FFA_VERSION >= FFA_VERSION_1_1
+	enum sp_partition_id_type partition_id_type;
+	bool inform_vm_create;
+	bool inform_vm_destroy;
+	enum sp_execution_state execution_state;
+	struct sp_uuid uuid;
+#endif /* CFG_FFA_VERSION */
 };
 
 /**
@@ -87,6 +108,19 @@
 sp_result sp_discovery_partition_info_get_all(struct sp_partition_info info[],
 					      uint32_t *count);
 
+#if CFG_FFA_VERSION >= FFA_VERSION_1_1
+/**
+ * @brief          Queries the count of partitions.
+ *
+ * @param[in]      uuid  The UUID of the partition
+ * @param[out]     count The count of matching partitions
+ *
+ * @return         The SP API result
+ */
+sp_result sp_discovery_partition_info_get_count(const struct sp_uuid *uuid,
+						uint32_t *count);
+#endif /* CFG_FFA_VERSION */
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/components/messaging/ffa/libsp/mock/mock_ffa_api.cpp b/components/messaging/ffa/libsp/mock/mock_ffa_api.cpp
index 38637cf..f3cd0f5 100644
--- a/components/messaging/ffa/libsp/mock/mock_ffa_api.cpp
+++ b/components/messaging/ffa/libsp/mock/mock_ffa_api.cpp
@@ -90,6 +90,7 @@
 		.returnIntValue();
 }
 
+#if CFG_FFA_VERSION == FFA_VERSION_1_0
 void expect_ffa_partition_info_get(const struct ffa_uuid *uuid,
 				   const uint32_t *count, ffa_result result)
 {
@@ -109,6 +110,31 @@
 		.withOutputParameter("count", count)
 		.returnIntValue();
 }
+#elif CFG_FFA_VERSION >= FFA_VERSION_1_1
+void expect_ffa_partition_info_get(const struct ffa_uuid *uuid, uint32_t flags,
+				   const uint32_t *count, const uint32_t *size,
+				   ffa_result result)
+{
+	mock().expectOneCall("ffa_partition_info_get")
+		.withMemoryBufferParameter("uuid", (const unsigned char *)uuid, sizeof(*uuid))
+		.withUnsignedIntParameter("flags", flags)
+		.withOutputParameterReturning("count", count, sizeof(*count))
+		.withOutputParameterReturning("size", size, sizeof(*size))
+		.andReturnValue(result);
+}
+
+ffa_result ffa_partition_info_get(const struct ffa_uuid *uuid, uint32_t flags, uint32_t *count,
+				  uint32_t *size)
+{
+	return mock()
+		.actualCall("ffa_partition_info_get")
+		.withMemoryBufferParameter("uuid", (const unsigned char *)uuid, sizeof(*uuid))
+		.withUnsignedIntParameter("flags", flags)
+		.withOutputParameter("count", count)
+		.withOutputParameter("size", size)
+		.returnIntValue();
+}
+#endif /* CFG_FFA_VERSION */
 
 void expect_ffa_id_get(const uint16_t *id, ffa_result result)
 {
diff --git a/components/messaging/ffa/libsp/mock/mock_ffa_api.h b/components/messaging/ffa/libsp/mock/mock_ffa_api.h
index 9c3dbc8..10dafcd 100644
--- a/components/messaging/ffa/libsp/mock/mock_ffa_api.h
+++ b/components/messaging/ffa/libsp/mock/mock_ffa_api.h
@@ -23,8 +23,14 @@
 
 void expect_ffa_rxtx_unmap(uint16_t id, ffa_result result);
 
+#if CFG_FFA_VERSION == FFA_VERSION_1_0
 void expect_ffa_partition_info_get(const struct ffa_uuid *uuid,
 				   const uint32_t *count, ffa_result result);
+#elif CFG_FFA_VERSION >= FFA_VERSION_1_1
+void expect_ffa_partition_info_get(const struct ffa_uuid *uuid, uint32_t flags,
+				   const uint32_t *count, const uint32_t *size,
+				   ffa_result result);
+#endif /* CFG_FFA_VERSION */
 
 void expect_ffa_id_get(const uint16_t *id, ffa_result result);
 
diff --git a/components/messaging/ffa/libsp/mock/test/test_mock_ffa_api.cpp b/components/messaging/ffa/libsp/mock/test/test_mock_ffa_api.cpp
index 8b793d3..f85c816 100644
--- a/components/messaging/ffa/libsp/mock/test/test_mock_ffa_api.cpp
+++ b/components/messaging/ffa/libsp/mock/test/test_mock_ffa_api.cpp
@@ -73,18 +73,37 @@
 	LONGS_EQUAL(result, ffa_rxtx_unmap(id));
 }
 
-TEST(mock_ffa_api, ffa_partition_info_get)
+#if CFG_FFA_VERSION == FFA_VERSION_1_0
+TEST(mock_ffa_api, ffa_partition_info_get_v1_0)
 {
 	const struct ffa_uuid uuid = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54,
 				       0x32, 0x10, 0x01, 0x23, 0x45, 0x67,
 				       0x89, 0xab, 0xcd, 0xef };
-	const uint32_t expect_count = 0xff00ee11U;
+	const uint32_t expected_count = 0xff00ee11U;
 	uint32_t count = 0;
 
-	expect_ffa_partition_info_get(&uuid, &expect_count, result);
+	expect_ffa_partition_info_get(&uuid, &expected_count, result);
 	LONGS_EQUAL(result, ffa_partition_info_get(&uuid, &count));
-	UNSIGNED_LONGS_EQUAL(expect_count, count);
+	UNSIGNED_LONGS_EQUAL(expected_count, count);
 }
+#elif CFG_FFA_VERSION >= FFA_VERSION_1_1
+TEST(mock_ffa_api, ffa_partition_info_get_v1_1)
+{
+	const struct ffa_uuid uuid = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54,
+				       0x32, 0x10, 0x01, 0x23, 0x45, 0x67,
+				       0x89, 0xab, 0xcd, 0xef };
+	const uint32_t flags = 0xabcdef01;
+	const uint32_t expected_count = 0xff00ee11U;
+	const uint32_t expected_size = 0xff00ee11U;
+	uint32_t count = 0;
+	uint32_t size = 0;
+
+	expect_ffa_partition_info_get(&uuid, flags, &expected_count, &expected_size, result);
+	LONGS_EQUAL(result, ffa_partition_info_get(&uuid, flags, &count, &size));
+	UNSIGNED_LONGS_EQUAL(expected_count, count);
+	UNSIGNED_LONGS_EQUAL(expected_size, size);
+}
+#endif /* CFG_FFA_VERSION */
 
 TEST(mock_ffa_api, ffa_id_get)
 {
diff --git a/components/messaging/ffa/libsp/sp_discovery.c b/components/messaging/ffa/libsp/sp_discovery.c
index 7f92b6b..cbe66ce 100644
--- a/components/messaging/ffa/libsp/sp_discovery.c
+++ b/components/messaging/ffa/libsp/sp_discovery.c
@@ -51,13 +51,22 @@
 		props & FFA_PARTITION_CAN_SEND_DIRECT_REQUESTS;
 	sp_info->supports_indirect_requests =
 		props & FFA_PARTITION_SUPPORTS_INDIRECT_REQUESTS;
+#if CFG_FFA_VERSION >= FFA_VERSION_1_1
+	sp_info->partition_id_type =
+		(props >> FFA_PARTITION_PART_ID_SHIFT) & FFA_PARTITION_PART_ID_MASK;
+	sp_info->inform_vm_create = props & FFA_PARTITION_INFORM_VM_CREATE;
+	sp_info->inform_vm_destroy = props & FFA_PARTITION_INFORM_VM_DESTROY;
+	if (props & FFA_PARTITION_AARCH64_EXECUTION_STATE)
+		sp_info->execution_state = sp_execution_state_aarch64;
+	else
+		sp_info->execution_state = sp_execution_state_aarch32;
+	memcpy(sp_info->uuid.uuid, ffa_info->uuid.uuid, sizeof(sp_info->uuid.uuid));
+
+#endif /* CFG_FFA_VERSION */
 }
 
-static sp_result
-partition_info_get(const struct sp_uuid *uuid,
-		   struct sp_partition_info info[],
-		   uint32_t *count,
-		   bool allow_nil_uuid)
+static sp_result partition_info_get(const struct sp_uuid *uuid, struct sp_partition_info info[],
+				    uint32_t *count, bool allow_nil_uuid)
 {
 	const struct ffa_partition_information *ffa_info = NULL;
 	uint32_t ffa_count = 0;
@@ -67,6 +76,7 @@
 	size_t buffer_size = 0;
 	struct ffa_uuid ffa_uuid = { 0 };
 	ffa_result ffa_res = FFA_OK;
+	uint32_t __maybe_unused ffa_size = 0;
 
 	if (count == NULL)
 		return SP_RESULT_INVALID_PARAMETERS;
@@ -90,17 +100,28 @@
 	/* Safely convert to FF-A UUID format */
 	memcpy(&ffa_uuid.uuid, uuid->uuid, sizeof(ffa_uuid.uuid));
 
+#if CFG_FFA_VERSION == FFA_VERSION_1_0
 	ffa_res = ffa_partition_info_get(&ffa_uuid, &ffa_count);
 	if (ffa_res != FFA_OK) {
 		sp_res = SP_RESULT_FFA(ffa_res);
 		goto out;
 	}
+#elif CFG_FFA_VERSION >= FFA_VERSION_1_1
+	ffa_res = ffa_partition_info_get(&ffa_uuid, 0, &ffa_count, &ffa_size);
+	if (ffa_res != FFA_OK) {
+		sp_res = SP_RESULT_FFA(ffa_res);
+		goto out;
+	}
+
+	if (ffa_size != sizeof(struct ffa_partition_information)) {
+		/* Non-matching structure size, this may happen in future FF-A versions */
+		sp_res = SP_RESULT_INTERNAL_ERROR;
+		goto out;
+	}
+#endif
 
 	if ((ffa_count * sizeof(struct ffa_partition_information)) > buffer_size) {
-		/*
-		 * The indicated amount of info structures doesn't fit into the
-		 * RX buffer.
-		 */
+		/* The indicated amount of info structures doesn't fit into the RX buffer */
 		sp_res = SP_RESULT_INTERNAL_ERROR;
 		goto out;
 	}
@@ -162,3 +183,34 @@
 {
 	return partition_info_get(&uuid_nil, info, count, true);
 }
+
+#if CFG_FFA_VERSION >= FFA_VERSION_1_1
+sp_result sp_discovery_partition_info_get_count(const struct sp_uuid *uuid, uint32_t *count)
+{
+	struct ffa_uuid ffa_uuid = { 0 };
+	ffa_result ffa_res = FFA_OK;
+	uint32_t ffa_size = 0;
+
+	if (count == NULL)
+		return SP_RESULT_INVALID_PARAMETERS;
+
+	*count = 0;
+
+	if (uuid == NULL)
+		return SP_RESULT_INVALID_PARAMETERS;
+
+	/* Safely convert to FF-A UUID format */
+	memcpy(&ffa_uuid.uuid, uuid->uuid, sizeof(ffa_uuid.uuid));
+
+	ffa_res = ffa_partition_info_get(&ffa_uuid, FFA_PARTITION_INFO_GET_FLAG_COUNT_ONLY, count,
+					 &ffa_size);
+	if (ffa_res != FFA_OK)
+		return SP_RESULT_FFA(ffa_res);
+
+	if (ffa_size != 0)
+		/* Size is MBZ if FFA_PARTITION_INFO_GET_FLAG_COUNT_ONLY is set */
+		return SP_RESULT_INTERNAL_ERROR;
+
+	return SP_RESULT_OK;
+}
+#endif /* CFG_FFA_VERSION */
diff --git a/components/messaging/ffa/libsp/test/test_ffa_api.cpp b/components/messaging/ffa/libsp/test/test_ffa_api.cpp
index 077028b..3c51e60 100644
--- a/components/messaging/ffa/libsp/test/test_ffa_api.cpp
+++ b/components/messaging/ffa/libsp/test/test_ffa_api.cpp
@@ -287,6 +287,7 @@
 	}
 }
 
+#if CFG_FFA_VERSION == FFA_VERSION_1_0
 TEST(ffa_api, ffa_partition_info_get)
 {
 	const struct ffa_uuid uuid = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab,
@@ -339,6 +340,70 @@
 		ffa_partition_info_get(&uuid, &count);
 	}
 }
+#elif CFG_FFA_VERSION >= FFA_VERSION_1_1
+TEST(ffa_api, ffa_partition_info_get)
+{
+	const struct ffa_uuid uuid = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab,
+				       0xcd, 0xef, 0x12, 0x34, 0x56, 0x78,
+				       0x9a, 0xbc, 0xde, 0xf0 };
+	const uint32_t flags = 0x33445566;
+	uint32_t count = 0;
+	uint32_t size = 0;
+	const uint32_t count_result = 0xaabbccdd;
+	const uint32_t size_result = 0xeeff1122;
+
+	svc_result.a0 = 0x84000061;
+	svc_result.a2 = count_result;
+	svc_result.a3 = size_result;
+	expect_ffa_svc(0x84000068, 0x67452301, 0xefcdab89, 0x78563412,
+		       0xf0debc9a, flags, 0, 0, &svc_result);
+
+	ffa_result result = ffa_partition_info_get(&uuid, flags, &count, &size);
+	LONGS_EQUAL(FFA_OK, result);
+	UNSIGNED_LONGS_EQUAL(count_result, count);
+	UNSIGNED_LONGS_EQUAL(size_result, size);
+}
+
+TEST(ffa_api, ffa_partition_info_get_error)
+{
+	const struct ffa_uuid uuid = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab,
+				       0xcd, 0xef, 0x12, 0x34, 0x56, 0x78,
+				       0x9a, 0xbc, 0xde, 0xf0 };
+	const uint32_t flags = 0x33445566;
+	uint32_t count = 0x1234;
+	uint32_t size = 0x5678;
+
+	setup_error_response(-1);
+	expect_ffa_svc(0x84000068, 0x67452301, 0xefcdab89, 0x78563412,
+		       0xf0debc9a, flags, 0, 0, &svc_result);
+
+	ffa_result result = ffa_partition_info_get(&uuid, flags, &count, &size);
+	LONGS_EQUAL(-1, result);
+	UNSIGNED_LONGS_EQUAL(0, count);
+	UNSIGNED_LONGS_EQUAL(0, size);
+}
+
+TEST(ffa_api, ffa_partition_info_get_unknown_response)
+{
+	const struct ffa_uuid uuid = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab,
+				       0xcd, 0xef, 0x12, 0x34, 0x56, 0x78,
+				       0x9a, 0xbc, 0xde, 0xf0 };
+	const uint32_t flags = 0x33445566;
+	uint32_t count = 0;
+	uint32_t size = 0;
+	const uint32_t count_result = 0xaabbccdd;
+	assert_environment_t assert_env;
+
+	svc_result.a0 = 0x12345678;
+	svc_result.a2 = count_result;
+	expect_ffa_svc(0x84000068, 0x67452301, 0xefcdab89, 0x78563412,
+		       0xf0debc9a, flags, 0, 0, &svc_result);
+
+	if (SETUP_ASSERT_ENVIRONMENT(assert_env)) {
+		ffa_partition_info_get(&uuid, flags, &count, &size);
+	}
+}
+#endif /* CFG_FFA_VERSION */
 
 TEST(ffa_api, ffa_id_get)
 {
diff --git a/components/messaging/ffa/libsp/test/test_sp_discovery.cpp b/components/messaging/ffa/libsp/test/test_sp_discovery.cpp
index 5c48fe8..f19786f 100644
--- a/components/messaging/ffa/libsp/test/test_sp_discovery.cpp
+++ b/components/messaging/ffa/libsp/test/test_sp_discovery.cpp
@@ -225,6 +225,24 @@
 	MEMCMP_EQUAL(&expected_info, &info, sizeof(info));
 }
 
+#if CFG_FFA_VERSION >= FFA_VERSION_1_1
+TEST(sp_discovery, sp_discovery_partition_info_invalid_desc_size)
+{
+	struct sp_uuid uuid = { 1 };
+	struct ffa_uuid ffa_uuid = { 1 };
+	uint32_t count = 1;
+	uint32_t size = 0;
+	struct sp_partition_info info = { 1 };
+	const struct sp_partition_info expected_info = { 0 };
+
+	expect_sp_rxtx_buffer_rx_get(&rx_buffer, &rx_buffer_size, SP_RESULT_OK);
+	expect_ffa_partition_info_get(&ffa_uuid, 0, &count, &size, FFA_OK);
+	LONGS_EQUAL(SP_RESULT_INTERNAL_ERROR,
+		    sp_discovery_partition_info_get(&uuid, &info, &count));
+	MEMCMP_EQUAL(&expected_info, &info, sizeof(info));
+}
+#endif
+
 TEST(sp_discovery, sp_discovery_partition_info_small_buffer)
 {
 	struct sp_uuid uuid = { 1 };
@@ -520,3 +538,65 @@
 	CHECK_FALSE(info[1].can_send_direct_requests);
 	CHECK_FALSE(info[1].supports_indirect_requests);
 }
+
+#if CFG_FFA_VERSION >= FFA_VERSION_1_1
+TEST(sp_discovery, sp_discovery_partition_info_get_count_null)
+{
+	struct sp_uuid uuid = { 1 };
+
+	LONGS_EQUAL(SP_RESULT_INVALID_PARAMETERS,
+		    sp_discovery_partition_info_get_count(&uuid, NULL));
+}
+
+TEST(sp_discovery, sp_discovery_partition_info_get_count_uuid_null)
+{
+	uint32_t count = 1;
+
+	LONGS_EQUAL(SP_RESULT_INVALID_PARAMETERS,
+		    sp_discovery_partition_info_get_count(NULL, &count));
+	UNSIGNED_LONGS_EQUAL(0, count);
+}
+
+TEST(sp_discovery, sp_discovery_partition_info_get_count_ffa_error)
+{
+	struct ffa_uuid ffa_uuid = { 1 };
+	struct sp_uuid sp_uuid = { 1 };
+	const uint32_t expected_count = 1;
+	const uint32_t expected_size = 0;
+	uint32_t count = 0;
+
+	expect_ffa_partition_info_get(&ffa_uuid, 0x01, &expected_count, &expected_size,
+					   result);
+	LONGS_EQUAL(result,
+		    sp_discovery_partition_info_get_count(&sp_uuid, &count));
+}
+
+TEST(sp_discovery, sp_discovery_partition_info_get_count_invalid_size)
+{
+	struct ffa_uuid ffa_uuid = { 1 };
+	struct sp_uuid sp_uuid = { 1 };
+	const uint32_t expected_count = 1;
+	const uint32_t expected_size = 11;
+	uint32_t count = 0;
+
+	expect_ffa_partition_info_get(&ffa_uuid, 0x01, &expected_count, &expected_size,
+					   FFA_OK);
+	LONGS_EQUAL(SP_RESULT_INTERNAL_ERROR,
+		    sp_discovery_partition_info_get_count(&sp_uuid, &count));
+}
+
+TEST(sp_discovery, sp_discovery_partition_info_get_count)
+{
+	struct ffa_uuid ffa_uuid = { 1 };
+	struct sp_uuid sp_uuid = { 1 };
+	const uint32_t expected_count = 1;
+	const uint32_t expected_size = 0;
+	uint32_t count = 0;
+
+	expect_ffa_partition_info_get(&ffa_uuid, 0x01, &expected_count, &expected_size,
+					   FFA_OK);
+	LONGS_EQUAL(SP_RESULT_OK,
+		    sp_discovery_partition_info_get_count(&sp_uuid, &count));
+	UNSIGNED_LONGS_EQUAL(expected_count, count);
+}
+#endif /* CFG_FFA_VERSION */