Align service locator implementations for Linux with RPC layer changes

Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: I7e8527c9217b95b4792f2dd24d9bccab2b81ee82
diff --git a/components/service/locator/linux/ffa/linuxffa_location_strategy.c b/components/service/locator/linux/ffa/linuxffa_location_strategy.c
index 330449b..d49c077 100644
--- a/components/service/locator/linux/ffa/linuxffa_location_strategy.c
+++ b/components/service/locator/linux/ffa/linuxffa_location_strategy.c
@@ -6,204 +6,74 @@
 
 #include "linuxffa_location_strategy.h"
 #include "linuxffa_service_context.h"
-#include <common/uuid/uuid.h>
-#include <service/locator/service_name.h>
-#include <rpc/ffarpc/caller/linux/ffarpc_caller.h>
-#include <deployments/se-proxy/se_proxy_interfaces.h>
+#include "common/uuid/uuid.h"
+#include "service/locator/service_name.h"
+#include "components/service/attestation/provider/attestation_uuid.h"
+#include "components/service/block_storage/provider/block_storage_uuid.h"
+#include "components/service/crypto/provider/crypto_uuid.h"
+#include "components/service/fwu/provider/fwu_uuid.h"
+#include "components/service/secure_storage/frontend/secure_storage_provider/secure_storage_uuid.h"
+#include "components/service/test_runner/provider/test_runner_uuid.h"
 #include <stddef.h>
 #include <string.h>
 #include <stdbool.h>
 #include <stdint.h>
 
-/*
- * There is the potential for there to be alternative deployment possibilities
- * for a service instance.  This will depend on deployment decisions such as
- * running one service instance per SP, or multiple services per SP.  The FFA
- * location strategy accommodates this by allowing for more than one suggestion
- * for a service to partition mapping.
- */
-#define MAX_PARTITION_SUGGESTIONS           (4)
 
-/*
- * The maximum number of partition instances, identified by a particular UUID,
- * that may be discovered.
- */
-#define MAX_PARTITION_INSTANCES             (4)
+static struct service_context *query(const char *sn);
+static const struct rpc_uuid *suggest_ts_service_uuids(const char *sn);
 
-/*
- * Structure to specify the location of a service endpoint reachable via FFA.
- */
-struct ffa_service_location
-{
-	struct uuid_canonical uuid;
-	uint16_t iface_id;
-};
-
-
-static struct service_context *query(const char *sn,
-	int *status);
-static size_t suggest_tf_org_partition_uuids(const char *sn,
-	struct ffa_service_location *candidates, size_t candidate_limit);
-static size_t use_ffa_partition_uuid(const char *sn,
-	struct ffa_service_location *candidates, size_t candidate_limit);
-static bool discover_partition(const char *sn,
-	struct uuid_canonical *uuid, const char *dev_path, uint16_t *partition_id);
-
-const struct service_location_strategy *linuxffa_location_strategy(void)
+const struct service_location_strategy *linux_ts_location_strategy(void)
 {
 	static const struct service_location_strategy strategy = { query };
 	return &strategy;
 }
 
-static struct service_context *query(const char *sn, int *status)
+static struct service_context *query(const char *sn)
 {
-	struct service_context *result = NULL;
-	struct ffa_service_location candidate_locations[MAX_PARTITION_SUGGESTIONS];
-	size_t num_suggestons = 0;
-	size_t suggeston_index;
-	char dev_path[16] = {0};
-
-	if (!ffarpc_caller_check_version())
-		return NULL;
-
-	if (ffarpc_caller_find_dev_path(dev_path, sizeof(dev_path)))
-		return NULL;
+	const struct rpc_uuid *service_uuid = NULL;
 
 	/* Determine one or more candidate partition UUIDs from the specified service name. */
-	if (sn_check_authority(sn, "trustedfirmware.org")) {
-		num_suggestons =
-			suggest_tf_org_partition_uuids(sn, candidate_locations, MAX_PARTITION_SUGGESTIONS);
-	}
-	else if (sn_check_authority(sn, "ffa")) {
-		num_suggestons =
-			use_ffa_partition_uuid(sn, candidate_locations, MAX_PARTITION_SUGGESTIONS);
-	}
+	if (!sn_check_authority(sn, "trustedfirmware.org"))
+		return NULL;
 
-	/* Attempt to discover suitable partitions */
-	for (suggeston_index = 0; suggeston_index < num_suggestons; ++suggeston_index) {
+	service_uuid = suggest_ts_service_uuids(sn);
+	if (!service_uuid)
+		return NULL;
 
-		uint16_t partition_id;
-
-		if (discover_partition(sn, &candidate_locations[suggeston_index].uuid,
-			dev_path, &partition_id)) {
-
-			struct linuxffa_service_context *new_context =
-				linuxffa_service_context_create(dev_path,
-					partition_id, candidate_locations[suggeston_index].iface_id);
-
-			if (new_context) result = &new_context->service_context;
-			break;
-		}
-	}
-
-	return result;
+	return (struct service_context *)linux_ts_service_context_create(service_uuid);
 }
 
 /*
- * Returns a list of partition UUIDs and interface IDs to identify partitions that
- * could potentially host the requested service.  This mapping is based trustedfirmware.org
- * ffa partition UUIDs. There may be multiple UUIDs because of different deployment decisions
- * such as dedicated SP, SP hosting multiple services.
+ * Returns a list of service UUIDs to identify partitions that could potentially host the requested
+ * service.  This mapping is based trustedfirmware.org service UUIDs. There may be multiple UUIDs
+ * because of different deployment decisions such as dedicated SP, SP hosting multiple services.
  */
-static size_t suggest_tf_org_partition_uuids(const char *sn,
-	struct ffa_service_location *candidates, size_t candidate_limit)
+static const struct rpc_uuid *suggest_ts_service_uuids(const char *sn)
 {
-	const struct service_to_uuid
+	static const struct service_to_uuid
 	{
 		const char *service;
-		const char *uuid;
-		uint16_t iface_id;
+		struct rpc_uuid uuid;
 	}
 	partition_lookup[] =
 	{
-		/* Services in dedicated SPs */
-		{"crypto",                      "d9df52d5-16a2-4bb2-9aa4-d26d3b84e8c0", 0},
-		{"internal-trusted-storage",    "dc1eef48-b17a-4ccf-ac8b-dfcff7711b14", 0},
-		{"protected-storage",           "751bf801-3dde-4768-a514-0f10aeed1790", 0},
-		{"test-runner",                 "33c75baf-ac6a-4fe4-8ac7-e9909bee2d17", 0},
-		{"attestation",                 "a1baf155-8876-4695-8f7c-54955e8db974", 0},
-		{"block-storage",               "63646e80-eb52-462f-ac4f-8cdf3987519c", 0},
-		{"fwu",                         "6823a838-1b06-470e-9774-0cce8bfb53fd", 0},
-
-		/* Secure Enclave proxy accessed services */
-		{"crypto",                      "46bb39d1-b4d9-45b5-88ff-040027dab249", SE_PROXY_INTERFACE_ID_CRYPTO},
-		{"internal-trusted-storage",    "46bb39d1-b4d9-45b5-88ff-040027dab249", SE_PROXY_INTERFACE_ID_ITS},
-		{"protected-storage",           "46bb39d1-b4d9-45b5-88ff-040027dab249", SE_PROXY_INTERFACE_ID_PS},
-		{"attestation",                 "46bb39d1-b4d9-45b5-88ff-040027dab249", SE_PROXY_INTERFACE_ID_ATTEST},
-		{NULL,                          NULL,                                   0}
+		{"crypto-protobuf",             {.uuid = TS_PSA_CRYPTO_PROTOBUF_SERVICE_UUID}},
+		{"crypto",                      {.uuid = TS_PSA_CRYPTO_SERVICE_UUID}},
+		{"internal-trusted-storage",    {.uuid = TS_PSA_INTERNAL_TRUSTED_STORAGE_UUID}},
+		{"protected-storage",           {.uuid = TS_PSA_PROTECTED_STORAGE_UUID}},
+		{"test-runner",                 {.uuid = TS_TEST_RUNNER_SERVICE_UUID}},
+		{"attestation",                 {.uuid = TS_PSA_ATTESTATION_SERVICE_UUID}},
+		{"block-storage",               {.uuid = TS_BLOCK_STORAGE_SERVICE_UUID}},
+		{"fwu",                         {.uuid = TS_FWU_SERVICE_UUID}},
+		{NULL,                          {.uuid = {0}}}
 	};
 
-	const struct service_to_uuid *entry = &partition_lookup[0];
-	size_t num_suggestions = 0;
+	const struct service_to_uuid *entry = NULL;
 
-	while (entry->service && (num_suggestions < candidate_limit)) {
+	for (entry = &partition_lookup[0]; entry->service != NULL; entry++)
+		if (sn_check_service(sn, entry->service))
+			return &entry->uuid;
 
-		if (sn_check_service(sn, entry->service)) {
-
-			memcpy(candidates[num_suggestions].uuid.characters, entry->uuid,
-				UUID_CANONICAL_FORM_LEN + 1);
-
-			candidates[num_suggestions].iface_id = entry->iface_id;
-
-			++num_suggestions;
-		}
-
-		++entry;
-	}
-
-	return num_suggestions;
-}
-
-/*
- * When an ffa service name where the service field is an explicit UUID is used, the UUID
- * is used directly for partition discovery.
- */
-static size_t use_ffa_partition_uuid(const char *sn,
-	struct ffa_service_location *candidates, size_t candidate_limit)
-{
-	size_t num_suggestions = 0;
-
-	if ((num_suggestions < candidate_limit) &&
-		(sn_read_service(sn, candidates[num_suggestions].uuid.characters,
-			UUID_CANONICAL_FORM_LEN + 1) == UUID_CANONICAL_FORM_LEN)) {
-
-		candidates[num_suggestions].iface_id = 0;
-
-		++num_suggestions;
-	}
-
-	return num_suggestions;
-}
-
-/*
- * Attempt to discover the partition that hosts the requested service instance.
- */
-static bool discover_partition(const char *sn,
-	struct uuid_canonical *uuid, const char *dev_path, uint16_t *partition_id)
-{
-	bool discovered = false;
-
-	if (uuid_is_valid(uuid->characters) == UUID_CANONICAL_FORM_LEN) {
-
-		struct ffarpc_caller ffarpc_caller;
-		unsigned int required_instance = sn_get_service_instance(sn);
-
-		ffarpc_caller_init(&ffarpc_caller, dev_path);
-
-		uint16_t discovered_partitions[MAX_PARTITION_INSTANCES];
-		size_t discovered_count;
-
-		discovered_count = ffarpc_caller_discover(&ffarpc_caller, uuid,
-										discovered_partitions, MAX_PARTITION_INSTANCES);
-
-		if ((discovered_count > 0) && (required_instance < discovered_count)) {
-
-			*partition_id = discovered_partitions[required_instance];
-			discovered = true;
-		}
-
-		ffarpc_caller_deinit(&ffarpc_caller);
-	}
-
-	return discovered;
+	return NULL;
 }
diff --git a/components/service/locator/linux/ffa/linuxffa_location_strategy.h b/components/service/locator/linux/ffa/linuxffa_location_strategy.h
index 6bb7eeb..da8260c 100644
--- a/components/service/locator/linux/ffa/linuxffa_location_strategy.h
+++ b/components/service/locator/linux/ffa/linuxffa_location_strategy.h
@@ -7,7 +7,7 @@
 #ifndef LINUXFFA_LOCATION_STRATEGY_H
 #define LINUXFFA_LOCATION_STRATEGY_H
 
-#include <service_locator.h>
+#include "service_locator.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -15,10 +15,10 @@
 
 /*
  * Returns a service_location_strategy for locating a service instance
- * hosted in a secure partition, accessed using FFA from Linux userspace.
- * Relies on an FFA Linux kernel driver.
+ * hosted in a secure partition, accessed using TS RPC from Linux userspace.
+ * Relies on an TS Linux kernel driver.
  */
-const struct service_location_strategy *linuxffa_location_strategy(void);
+const struct service_location_strategy *linux_ts_location_strategy(void);
 
 #ifdef __cplusplus
 }
diff --git a/components/service/locator/linux/ffa/linuxffa_service_context.c b/components/service/locator/linux/ffa/linuxffa_service_context.c
index 7548095..ad6ebc2 100644
--- a/components/service/locator/linux/ffa/linuxffa_service_context.c
+++ b/components/service/locator/linux/ffa/linuxffa_service_context.c
@@ -5,87 +5,94 @@
  */
 
 #include "linuxffa_service_context.h"
-#include <rpc/ffarpc/caller/linux/ffarpc_caller.h>
+#include "components/rpc/ts_rpc/caller/linux/ts_rpc_caller_linux.h"
 #include <stdlib.h>
 #include <string.h>
 
+struct linux_ts_service_context
+{
+    struct service_context service_context;
+    struct rpc_caller_interface caller;
+    struct rpc_uuid service_uuid;
+};
+
 /* Concrete service_context methods */
-static rpc_session_handle linuxffa_service_context_open(void *context, struct rpc_caller **caller);
-static void linuxffa_service_context_close(void *context, rpc_session_handle session_handle);
-static void linuxffa_service_context_relinquish(void *context);
+static struct rpc_caller_session *linux_ts_service_context_open(void *context);
+static void linux_ts_service_context_close(void *context, struct rpc_caller_session *session);
+static void linux_ts_service_context_relinquish(void *context);
 
 
-struct linuxffa_service_context *linuxffa_service_context_create(const char *dev_path,
-    uint16_t partition_id, uint16_t iface_id)
+struct linux_ts_service_context *linux_ts_service_context_create(const struct rpc_uuid *service_uuid)
+
 {
-    struct linuxffa_service_context *new_context =
-        (struct linuxffa_service_context*)malloc(sizeof(struct linuxffa_service_context));
+	struct linux_ts_service_context *new_context = NULL;
+	rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
 
-    if (new_context) {
-        new_context->ffa_dev_path = strdup(dev_path);
-        if (!new_context->ffa_dev_path) {
-            free(new_context);
-            return NULL;
-        }
+	if (!service_uuid)
+		return NULL;
 
-        new_context->partition_id = partition_id;
-        new_context->iface_id = iface_id;
+	new_context = (struct linux_ts_service_context *)
+		calloc(1, sizeof(struct linux_ts_service_context));
+	if (!new_context)
+		return NULL;
 
-        new_context->service_context.context = new_context;
-        new_context->service_context.open = linuxffa_service_context_open;
-        new_context->service_context.close = linuxffa_service_context_close;
-        new_context->service_context.relinquish = linuxffa_service_context_relinquish;
-    }
+	rpc_status = ts_rpc_caller_linux_init(&new_context->caller);
+	if (rpc_status != RPC_SUCCESS) {
+		free(new_context);
+		return NULL;
+	}
 
-    return new_context;
+	memcpy(&new_context->service_uuid, service_uuid, sizeof(new_context->service_uuid));
+
+	new_context->service_context.context = new_context;
+	new_context->service_context.open = linux_ts_service_context_open;
+	new_context->service_context.close = linux_ts_service_context_close;
+	new_context->service_context.relinquish = linux_ts_service_context_relinquish;
+
+	return new_context;
 }
 
-static rpc_session_handle linuxffa_service_context_open(void *context, struct rpc_caller **caller)
+static struct rpc_caller_session *linux_ts_service_context_open(void *context)
 {
-    struct linuxffa_service_context *this_context = (struct linuxffa_service_context*)context;
-    rpc_session_handle session_handle = NULL;
-    struct ffarpc_caller *ffarpc_caller =
-        (struct ffarpc_caller*)malloc(sizeof(struct ffarpc_caller));
+	struct linux_ts_service_context *this_context = (struct linux_ts_service_context *)context;
+	struct rpc_caller_session *session = NULL;
+	rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
 
-    if (ffarpc_caller) {
+	if (!context)
+		return NULL;
 
-        int status;
-        *caller = ffarpc_caller_init(ffarpc_caller, this_context->ffa_dev_path);
-        status = ffarpc_caller_open(ffarpc_caller,
-            this_context->partition_id, this_context->iface_id);
+	session = (struct rpc_caller_session *)calloc(1, sizeof(struct rpc_caller_session));
+	if (!session)
+		return NULL;
 
-		if (status == 0) {
-            /* Successfully opened session */
-            session_handle = ffarpc_caller;
-		}
-		else {
-            /* Failed to open session */
-			ffarpc_caller_close(ffarpc_caller);
-            ffarpc_caller_deinit(ffarpc_caller);
-            free(ffarpc_caller);
-		}
-    }
+	rpc_status = rpc_caller_session_find_and_open(session, &this_context->caller,
+						      &this_context->service_uuid, 8192);
+	if (rpc_status != RPC_SUCCESS) {
+		free(session);
+		return NULL;
+	}
 
-    return session_handle;
+	return session;
 }
 
-static void linuxffa_service_context_close(void *context, rpc_session_handle session_handle)
+static void linux_ts_service_context_close(void *context, struct rpc_caller_session *session)
 {
-    struct ffarpc_caller *ffarpc_caller = (struct ffarpc_caller*)session_handle;
+	(void)context;
 
-    (void)context;
+	if (!session)
+		return;
 
-    if (ffarpc_caller) {
-
-		ffarpc_caller_close(ffarpc_caller);
-        ffarpc_caller_deinit(ffarpc_caller);
-        free(ffarpc_caller);
-    }
+	rpc_caller_session_close(session);
+	free(session);
 }
 
-static void linuxffa_service_context_relinquish(void *context)
+static void linux_ts_service_context_relinquish(void *context)
 {
-    struct linuxffa_service_context *this_context = (struct linuxffa_service_context*)context;
-    free(this_context->ffa_dev_path);
-    free(this_context);
-}
+	struct linux_ts_service_context *this_context = (struct linux_ts_service_context *)context;
+
+	if (!context)
+		return;
+
+	ts_rpc_caller_linux_deinit(&this_context->caller);
+	free(context);
+}
\ No newline at end of file
diff --git a/components/service/locator/linux/ffa/linuxffa_service_context.h b/components/service/locator/linux/ffa/linuxffa_service_context.h
index 2f6fc26..196f534 100644
--- a/components/service/locator/linux/ffa/linuxffa_service_context.h
+++ b/components/service/locator/linux/ffa/linuxffa_service_context.h
@@ -7,7 +7,7 @@
 #ifndef LINUXFFA_SERVICE_CONTEXT_H
 #define LINUXFFA_SERVICE_CONTEXT_H
 
-#include <service_locator.h>
+#include "service_locator.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -18,20 +18,13 @@
  * a partition, accessed via FFA.  This service_context is suitable
  * for use by client applications running in Linux userspace.
  */
-struct linuxffa_service_context
-{
-    struct service_context service_context;
-    char *ffa_dev_path;
-    uint16_t partition_id;
-    uint16_t iface_id;
-};
+struct linux_ts_service_context;
 
 /*
- * Factory method to create a service context associated with theh specified
- * partition id and RPC interface instance.
+ * Factory method to create a service context associated with the specified
+ * service UUID.
  */
-struct linuxffa_service_context *linuxffa_service_context_create(const char *dev_path,
-    uint16_t partition_id, uint16_t iface_id);
+struct linux_ts_service_context *linux_ts_service_context_create(const struct rpc_uuid *service_uuid);
 
 #ifdef __cplusplus
 }
diff --git a/components/service/locator/linux/linux_env.c b/components/service/locator/linux/linux_env.c
index 4bef301..2d920c6 100644
--- a/components/service/locator/linux/linux_env.c
+++ b/components/service/locator/linux/linux_env.c
@@ -14,6 +14,6 @@
 	 * Register all service location strategies that could be used
 	 * to locate services from Linux userspace.
 	 */
-	service_locator_register_strategy(linuxffa_location_strategy());
+	service_locator_register_strategy(linux_ts_location_strategy());
 	service_locator_register_strategy(mm_communicate_location_strategy());
 }
diff --git a/components/service/locator/linux/mm_communicate/mm_communicate_location_strategy.c b/components/service/locator/linux/mm_communicate/mm_communicate_location_strategy.c
index b9f6a21..4c22756 100644
--- a/components/service/locator/linux/mm_communicate/mm_communicate_location_strategy.c
+++ b/components/service/locator/linux/mm_communicate/mm_communicate_location_strategy.c
@@ -12,8 +12,6 @@
 #include <rpc/mm_communicate/caller/linux/mm_communicate_caller.h>
 #include <protocols/service/smm_variable/smm_variable_proto.h>
 
-#define MAX_PARTITION_INSTANCES		(1)
-
 /* Structure to define the location of an smm service */
 struct smm_service_location
 {
@@ -36,7 +34,7 @@
 	{
 		{
 			.service = "smm-variable",
-			.uuid = "ed32d533-99e6-4209-9cc0-2d72cdd998a7",
+			.uuid = SMM_VARIABLE_CANONICAL_GUID,
 			.svc_guid = SMM_VARIABLE_GUID
 		},
 		{
@@ -69,62 +67,27 @@
 	return found;
 }
 
-bool discover_partition(const char *dev_path, struct smm_service_location *location)
+static struct service_context *query(const char *sn)
 {
-	bool discovered = false;
+	struct smm_service_location location = { 0 };
+	struct mm_communicate_service_context *new_context = NULL;
+	static const char *dev_path = "/sys/kernel/debug/arm_ffa_user";
 
-	if (uuid_is_valid(location->uuid.characters) == UUID_CANONICAL_FORM_LEN) {
 
-		struct mm_communicate_caller mm_communicate_caller;
+	if (!sn_check_authority(sn, "trustedfirmware.org"))
+		return NULL;
 
-		if (!mm_communicate_caller_check_version())
-			return false;
+	if (!find_candidate_location(sn, &location))
+		return NULL;
 
-		mm_communicate_caller_init(&mm_communicate_caller, dev_path);
+	new_context = mm_communicate_service_context_create(
+			dev_path,
+			location.partition_id,
+			&location.svc_guid);
+	if (!new_context)
+		return NULL;
 
-		uint16_t discovered_partitions[MAX_PARTITION_INSTANCES];
-		size_t discovered_count;
-
-		discovered_count = mm_communicate_caller_discover(
-			&mm_communicate_caller,
-			&location->uuid,
-			discovered_partitions,
-			MAX_PARTITION_INSTANCES);
-
-		if (discovered_count > 0) {
-
-			location->partition_id = discovered_partitions[0];
-			discovered = true;
-		}
-
-		mm_communicate_caller_deinit(&mm_communicate_caller);
-	}
-
-	return discovered;
-}
-
-static struct service_context *query(const char *sn, int *status)
-{
-	struct service_context *result = NULL;
-
-	if (!sn_check_authority(sn, "trustedfirmware.org")) return NULL;
-
-	struct smm_service_location location;
-	const char *dev_path = "/sys/kernel/debug/arm_ffa_user";
-
-	if (find_candidate_location(sn, &location) &&
-		discover_partition(dev_path, &location)) {
-
-		struct mm_communicate_service_context *new_context =
-			mm_communicate_service_context_create(
-				dev_path,
-				location.partition_id,
-				&location.svc_guid);
-
-		if (new_context) result = &new_context->service_context;
-	}
-
-	return result;
+	return &new_context->service_context;
 }
 
 const struct service_location_strategy *mm_communicate_location_strategy(void)
diff --git a/components/service/locator/linux/mm_communicate/mm_communicate_service_context.c b/components/service/locator/linux/mm_communicate/mm_communicate_service_context.c
index 358210f..5573795 100644
--- a/components/service/locator/linux/mm_communicate/mm_communicate_service_context.c
+++ b/components/service/locator/linux/mm_communicate/mm_communicate_service_context.c
@@ -4,100 +4,93 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
-#include <stdlib.h>
 #include <rpc/mm_communicate/caller/linux/mm_communicate_caller.h>
 #include "mm_communicate_service_context.h"
+#include <stdlib.h>
+#include <string.h>
 
 /* Concrete service_context methods */
-static rpc_session_handle mm_communicate_service_context_open(void *context,
-	struct rpc_caller **caller);
+static struct rpc_caller_session *mm_communicate_service_context_open(void *context);
 static void mm_communicate_service_context_close(void *context,
-	rpc_session_handle session_handle);
+	struct rpc_caller_session *session_handle);
 static void mm_communicate_service_context_relinquish(void *context);
 
+static void efi_guid_to_rpc_uuid(const EFI_GUID *guid, struct rpc_uuid *uuid)
+{
+	uuid->uuid[0] = (guid->Data1 >> 24) & 0xff;
+	uuid->uuid[1] = (guid->Data1 >> 16) & 0xff;
+	uuid->uuid[2] = (guid->Data1 >> 8) & 0xff;
+	uuid->uuid[3] = guid->Data1 & 0xff;
+	uuid->uuid[4] = (guid->Data2 >> 8) & 0xff;
+	uuid->uuid[5] = guid->Data2 & 0xff;
+	uuid->uuid[6] = (guid->Data3 >> 8) & 0xff;
+	uuid->uuid[7] = guid->Data3 & 0xff;
+	memcpy(&uuid->uuid[8], guid->Data4, sizeof(guid->Data4));
+}
 
 struct mm_communicate_service_context *mm_communicate_service_context_create(
 	const char *dev_path,
 	uint16_t partition_id,
 	const EFI_GUID *svc_guid)
 {
-	struct mm_communicate_service_context *new_context = (struct mm_communicate_service_context*)
-		malloc(sizeof(struct mm_communicate_service_context));
+	struct mm_communicate_service_context *new_context =
+		(struct mm_communicate_service_context*)calloc(1, sizeof(struct mm_communicate_service_context));
+	rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
 
-	if (new_context) {
+	if (!new_context)
+		return NULL;
 
-		new_context->ffa_dev_path = dev_path;
-		new_context->partition_id = partition_id;
-		new_context->svc_guid = *svc_guid;
-
-		new_context->service_context.context = new_context;
-		new_context->service_context.open = mm_communicate_service_context_open;
-		new_context->service_context.close = mm_communicate_service_context_close;
-		new_context->service_context.relinquish = mm_communicate_service_context_relinquish;
+	rpc_status = mm_communicate_caller_init(&new_context->caller, dev_path);
+	if (rpc_status != RPC_SUCCESS) {
+		free(new_context);
+		return NULL;
 	}
 
+	new_context->partition_id = partition_id;
+	new_context->svc_guid = *svc_guid;
+
+	new_context->service_context.context = new_context;
+	new_context->service_context.open = mm_communicate_service_context_open;
+	new_context->service_context.close = mm_communicate_service_context_close;
+	new_context->service_context.relinquish = mm_communicate_service_context_relinquish;
+
 	return new_context;
 }
 
-static rpc_session_handle mm_communicate_service_context_open(
-	void *context,
-	struct rpc_caller **caller)
+static struct rpc_caller_session *mm_communicate_service_context_open(void *context)
 {
 	struct mm_communicate_service_context *this_context =
 		(struct mm_communicate_service_context*)context;
+	struct rpc_caller_session *session = (struct rpc_caller_session *)calloc(1, sizeof(struct rpc_caller_session));
+	rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+	struct rpc_uuid service_uuid = { 0 };
 
-	rpc_session_handle session_handle = NULL;
-
-	if (!mm_communicate_caller_check_version())
+	if (!session)
 		return NULL;
 
-	struct mm_communicate_caller *mm_communicate_caller =
-		(struct mm_communicate_caller*)malloc(sizeof(struct mm_communicate_caller));
+	efi_guid_to_rpc_uuid(&this_context->svc_guid, &service_uuid);
 
-	if (mm_communicate_caller) {
-
-		*caller = mm_communicate_caller_init(mm_communicate_caller,
-			this_context->ffa_dev_path);
-		int status = mm_communicate_caller_open(mm_communicate_caller,
-			this_context->partition_id, &this_context->svc_guid);
-
-		if (status == 0) {
-			/* Successfully opened session */
-			session_handle = mm_communicate_caller;
-		}
-		else {
-			/* Failed to open session */
-			mm_communicate_caller_close(mm_communicate_caller);
-			mm_communicate_caller_deinit(mm_communicate_caller);
-			free(mm_communicate_caller);
-		}
+	/* The memory size is set to 0 because carveout configuration controls this. */
+	rpc_status = rpc_caller_session_find_and_open(session, &this_context->caller,
+						      &service_uuid, 0);
+	if (rpc_status != RPC_SUCCESS) {
+		free(session);
+		return NULL;
 	}
 
-	return session_handle;
+	return session;
 }
 
-static void mm_communicate_service_context_close(
-	void *context,
-	rpc_session_handle session_handle)
+static void mm_communicate_service_context_close(void *context, struct rpc_caller_session *session)
 {
-	struct mm_communicate_caller *mm_communicate_caller =
-		(struct mm_communicate_caller*)session_handle;
-
 	(void)context;
 
-	if (mm_communicate_caller) {
-
-		mm_communicate_caller_close(mm_communicate_caller);
-		mm_communicate_caller_deinit(mm_communicate_caller);
-		free(mm_communicate_caller);
-	}
+	rpc_caller_session_close(session);
+	free(session);
 }
 
 static void mm_communicate_service_context_relinquish(
 	void *context)
 {
-	struct mm_communicate_service_context *this_context =
-		(struct mm_communicate_service_context*)context;
-
-	free(this_context);
+	free(context);
 }
diff --git a/components/service/locator/linux/mm_communicate/mm_communicate_service_context.h b/components/service/locator/linux/mm_communicate/mm_communicate_service_context.h
index 6771c31..27535ce 100644
--- a/components/service/locator/linux/mm_communicate/mm_communicate_service_context.h
+++ b/components/service/locator/linux/mm_communicate/mm_communicate_service_context.h
@@ -22,7 +22,7 @@
 struct mm_communicate_service_context
 {
 	struct service_context service_context;
-	const char *ffa_dev_path;
+	struct rpc_caller_interface caller;
 	uint16_t partition_id;
 	EFI_GUID svc_guid;
 };