Update RPC layer initialization in SE proxy SP

Change ffa_call_ep to ts_rpc_endpoint_sp.

Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: I297fea525f6a8772d7bc5c8cd39a3711c243c843
diff --git a/deployments/se-proxy/env/commonsp/se_proxy_sp.c b/deployments/se-proxy/env/commonsp/se_proxy_sp.c
index 5990bb2..155e948 100644
--- a/deployments/se-proxy/env/commonsp/se_proxy_sp.c
+++ b/deployments/se-proxy/env/commonsp/se_proxy_sp.c
@@ -3,8 +3,8 @@
  * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
  */
 
-#include "rpc/ffarpc/endpoint/ffarpc_call_ep.h"
-#include "rpc/common/demux/rpc_demux.h"
+#include "components/rpc/common/endpoint/rpc_service_interface.h"
+#include "components/rpc/ts_rpc/endpoint/sp/ts_rpc_endpoint_sp.h"
 #include "config/ramstore/config_ramstore.h"
 #include "config/loader/sp/sp_config_loader.h"
 #include "sp_api.h"
@@ -18,13 +18,13 @@
 
 void __noreturn sp_main(union ffa_boot_info *boot_info)
 {
-	struct ffa_call_ep ffarpc_call_ep = { 0 };
+	struct ts_rpc_endpoint_sp rpc_endpoint = { 0 };
 	struct sp_msg req_msg = { 0 };
 	struct sp_msg resp_msg = { 0 };
-	struct rpc_demux rpc_demux = { 0 };
-	struct rpc_interface *rpc_iface = NULL;
+	struct rpc_service_interface *rpc_iface = NULL;
 	uint16_t own_id = 0;
 	sp_result result = SP_RESULT_INTERNAL_ERROR;
+	rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
 
 	/* Boot phase */
 	if (!sp_init(&own_id)) {
@@ -39,14 +39,12 @@
 		goto fatal_error;
 	}
 
-	rpc_iface = rpc_demux_init(&rpc_demux);
-	if (!rpc_iface) {
-		EMSG("Failed to initialize RPC demux");
+	rpc_status = ts_rpc_endpoint_sp_init(&rpc_endpoint, 4, 16);
+	if (rpc_status != RPC_SUCCESS) {
+		EMSG("Failed to initialize RPC endpoint: %d", rpc_status);
 		goto fatal_error;
 	}
 
-	ffa_call_ep_init(&ffarpc_call_ep, rpc_iface, own_id);
-
 	/* Create service proxies */
 	rpc_iface = its_proxy_create();
 	if (!rpc_iface) {
@@ -54,28 +52,47 @@
 		goto fatal_error;
 	}
 
-	rpc_demux_attach(&rpc_demux, SE_PROXY_INTERFACE_ID_ITS, rpc_iface);
+	rpc_status = ts_rpc_endpoint_sp_add_service(&rpc_endpoint, rpc_iface);
+	if (rpc_status != RPC_SUCCESS) {
+		EMSG("Failed to add service to RPC endpoint: %d", rpc_status);
+		goto fatal_error;
+	}
 
 	rpc_iface = ps_proxy_create();
 	if (!rpc_iface) {
 		EMSG("Failed to create PS proxy");
 		goto fatal_error;
 	}
-	rpc_demux_attach(&rpc_demux, SE_PROXY_INTERFACE_ID_PS, rpc_iface);
+
+	rpc_status = ts_rpc_endpoint_sp_add_service(&rpc_endpoint, rpc_iface);
+	if (rpc_status != RPC_SUCCESS) {
+		EMSG("Failed to add service to RPC endpoint: %d", rpc_status);
+		goto fatal_error;
+	}
 
 	rpc_iface = crypto_proxy_create();
 	if (!rpc_iface) {
 		EMSG("Failed to create Crypto proxy");
 		goto fatal_error;
 	}
-	rpc_demux_attach(&rpc_demux, SE_PROXY_INTERFACE_ID_CRYPTO, rpc_iface);
+
+	rpc_status = ts_rpc_endpoint_sp_add_service(&rpc_endpoint, rpc_iface);
+	if (rpc_status != RPC_SUCCESS) {
+		EMSG("Failed to add service to RPC endpoint: %d", rpc_status);
+		goto fatal_error;
+	}
 
 	rpc_iface = attest_proxy_create();
 	if (!rpc_iface) {
 		EMSG("Failed to create Attestation proxy");
 		goto fatal_error;
 	}
-	rpc_demux_attach(&rpc_demux, SE_PROXY_INTERFACE_ID_ATTEST, rpc_iface);
+
+	rpc_status = ts_rpc_endpoint_sp_add_service(&rpc_endpoint, rpc_iface);
+	if (rpc_status != RPC_SUCCESS) {
+		EMSG("Failed to add service to RPC endpoint: %d", rpc_status);
+		goto fatal_error;
+	}
 
 	/* End of boot phase */
 	result = sp_msg_wait(&req_msg);
@@ -85,7 +102,7 @@
 	}
 
 	while (1) {
-		ffa_call_ep_receive(&ffarpc_call_ep, &req_msg, &resp_msg);
+		ts_rpc_endpoint_sp_receive(&rpc_endpoint, &req_msg, &resp_msg);
 
 		result = sp_msg_send_direct_resp(&resp_msg, &req_msg);
 		if (result != SP_RESULT_OK) {
diff --git a/deployments/se-proxy/env/commonsp/se_proxy_sp.cmake b/deployments/se-proxy/env/commonsp/se_proxy_sp.cmake
index 32bb8e9..c052f42 100644
--- a/deployments/se-proxy/env/commonsp/se_proxy_sp.cmake
+++ b/deployments/se-proxy/env/commonsp/se_proxy_sp.cmake
@@ -20,7 +20,8 @@
 		"components/config/ramstore"
 		"components/config/loader/sp"
 		"components/messaging/ffa/libsp"
-		"components/rpc/ffarpc/endpoint"
+		"components/rpc/ts_rpc/common"
+		"components/rpc/ts_rpc/endpoint/sp"
 )
 
 target_sources(se-proxy PRIVATE
diff --git a/deployments/se-proxy/infra/corstone1000/service_proxy_factory.c b/deployments/se-proxy/infra/corstone1000/service_proxy_factory.c
index bacab1d..6885f92 100644
--- a/deployments/se-proxy/infra/corstone1000/service_proxy_factory.c
+++ b/deployments/se-proxy/infra/corstone1000/service_proxy_factory.c
@@ -7,12 +7,13 @@
 
 #include <stddef.h>
 #include <psa/sid.h>
-#include <rpc/common/endpoint/rpc_interface.h>
+#include "rpc/common/endpoint/rpc_service_interface.h"
 #include <rpc/psa_ipc/caller/sp/psa_ipc_caller.h>
 #include <service/attestation/provider/attest_provider.h>
 #include <service/attestation/provider/serializer/packed-c/packedc_attest_provider_serializer.h>
 #include <service/crypto/factory/crypto_provider_factory.h>
 #include <service/secure_storage/frontend/secure_storage_provider/secure_storage_provider.h>
+#include "service/secure_storage/frontend/secure_storage_provider/secure_storage_uuid.h"
 #include <trace.h>
 
 /* backends */
@@ -20,41 +21,55 @@
 #include <service/secure_storage/backend/secure_storage_ipc/secure_storage_ipc.h>
 #include <service/attestation/client/psa/iat_client.h>
 
-struct psa_ipc_caller psa_ipc;
+static const struct rpc_uuid dummy_uuid = { 0 };
 
-struct rpc_interface *attest_proxy_create(void)
+struct rpc_service_interface *attest_proxy_create(void)
 {
-	struct rpc_interface *attest_iface;
-	struct rpc_caller *attest_caller;
+	struct rpc_service_interface *attest_iface = NULL;
+	rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
 
 	/* Static objects for proxy instance */
-	static struct attest_provider attest_provider;
+	static struct rpc_caller_interface psa_ipc = { 0 };
+	static struct rpc_caller_session rpc_session = { 0 };
+	static struct attest_provider attest_provider = { 0 };
 
-	attest_caller = psa_ipc_caller_init(&psa_ipc);
-	if (!attest_caller)
+	rpc_status = psa_ipc_caller_init(&psa_ipc);
+	if (rpc_status != RPC_SUCCESS)
+		return NULL;
+
+	rpc_status = rpc_caller_session_open(&rpc_session, &psa_ipc, &dummy_uuid, 0, 0);
+	if (rpc_status != RPC_SUCCESS)
 		return NULL;
 
 	/* Initialize the service provider */
 	attest_iface = attest_provider_init(&attest_provider);
-	psa_iat_client_init(&psa_ipc.rpc_caller);
+	psa_iat_client_init(&rpc_session);
 
 	attest_provider_register_serializer(&attest_provider,
-		TS_RPC_ENCODING_PACKED_C, packedc_attest_provider_serializer_instance());
+					    packedc_attest_provider_serializer_instance());
 
 	return attest_iface;
 }
 
-struct rpc_interface *crypto_proxy_create(void)
+struct rpc_service_interface *crypto_proxy_create(void)
 {
-	struct rpc_interface *crypto_iface = NULL;
+	struct rpc_service_interface *crypto_iface = NULL;
 	struct crypto_provider *crypto_provider;
-	struct rpc_caller *crypto_caller;
+	rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
 
-	crypto_caller = psa_ipc_caller_init(&psa_ipc);
-	if (!crypto_caller)
+	/* Static objects for proxy instance */
+	static struct rpc_caller_interface psa_ipc = { 0 };
+	static struct rpc_caller_session rpc_session = { 0 };
+
+	rpc_status = psa_ipc_caller_init(&psa_ipc);
+	if (rpc_status != RPC_SUCCESS)
 		return NULL;
 
-	if (crypto_ipc_backend_init(&psa_ipc.rpc_caller) != PSA_SUCCESS)
+	rpc_status = rpc_caller_session_open(&rpc_session, &psa_ipc, &dummy_uuid, 0, 0);
+	if (rpc_status != RPC_SUCCESS)
+		return NULL;
+
+	if (crypto_ipc_backend_init(&rpc_session) != PSA_SUCCESS)
 		return NULL;
 
 	crypto_provider = crypto_provider_factory_create();
@@ -63,34 +78,54 @@
 	return crypto_iface;
 }
 
-struct rpc_interface *ps_proxy_create(void)
+struct rpc_service_interface *ps_proxy_create(void)
 {
 	static struct secure_storage_provider ps_provider;
 	static struct secure_storage_ipc ps_backend;
-	struct rpc_caller *storage_caller;
 	struct storage_backend *backend;
+	rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+	const struct rpc_uuid ps_uuid = { .uuid = TS_PSA_PROTECTED_STORAGE_UUID };
 
-	storage_caller = psa_ipc_caller_init(&psa_ipc);
-	if (!storage_caller)
+	/* Static objects for proxy instance */
+	static struct rpc_caller_interface psa_ipc = { 0 };
+	static struct rpc_caller_session rpc_session = { 0 };
+
+	rpc_status = psa_ipc_caller_init(&psa_ipc);
+	if (rpc_status != RPC_SUCCESS)
 		return NULL;
-	backend = secure_storage_ipc_init(&ps_backend, &psa_ipc.rpc_caller);
+
+	rpc_status = rpc_caller_session_open(&rpc_session, &psa_ipc, &dummy_uuid, 0, 0);
+	if (rpc_status != RPC_SUCCESS)
+		return NULL;
+
+	backend = secure_storage_ipc_init(&ps_backend, &rpc_session);
 	ps_backend.service_handle = TFM_PROTECTED_STORAGE_SERVICE_HANDLE;
 
-	return secure_storage_provider_init(&ps_provider, backend);
+	return secure_storage_provider_init(&ps_provider, backend, &ps_uuid);
 }
 
-struct rpc_interface *its_proxy_create(void)
+struct rpc_service_interface *its_proxy_create(void)
 {
 	static struct secure_storage_provider its_provider;
 	static struct secure_storage_ipc its_backend;
-	struct rpc_caller *storage_caller;
 	struct storage_backend *backend;
+	rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+	const struct rpc_uuid its_uuid = { .uuid = TS_PSA_INTERNAL_TRUSTED_STORAGE_UUID };
 
-	storage_caller = psa_ipc_caller_init(&psa_ipc);
-	if (!storage_caller)
+	/* Static objects for proxy instance */
+	static struct rpc_caller_interface psa_ipc = { 0 };
+	static struct rpc_caller_session rpc_session = { 0 };
+
+	rpc_status = psa_ipc_caller_init(&psa_ipc);
+	if (rpc_status != RPC_SUCCESS)
 		return NULL;
-	backend = secure_storage_ipc_init(&its_backend, &psa_ipc.rpc_caller);
+
+	rpc_status = rpc_caller_session_open(&rpc_session, &psa_ipc, &dummy_uuid, 0, 0);
+	if (rpc_status != RPC_SUCCESS)
+		return NULL;
+
+	backend = secure_storage_ipc_init(&its_backend, &rpc_session);
 	its_backend.service_handle = TFM_INTERNAL_TRUSTED_STORAGE_SERVICE_HANDLE;
 
-	return secure_storage_provider_init(&its_provider, backend);
+	return secure_storage_provider_init(&its_provider, backend, &its_uuid);
 }
diff --git a/deployments/se-proxy/infra/service_proxy_factory.h b/deployments/se-proxy/infra/service_proxy_factory.h
index 298d407..caaea79 100644
--- a/deployments/se-proxy/infra/service_proxy_factory.h
+++ b/deployments/se-proxy/infra/service_proxy_factory.h
@@ -7,16 +7,16 @@
 #ifndef SERVICE_PROXY_FACTORY_H
 #define SERVICE_PROXY_FACTORY_H
 
-#include <rpc/common/endpoint/rpc_interface.h>
+#include "components/rpc/common/endpoint/rpc_service_interface.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-struct rpc_interface *attest_proxy_create(void);
-struct rpc_interface *crypto_proxy_create(void);
-struct rpc_interface *ps_proxy_create(void);
-struct rpc_interface *its_proxy_create(void);
+struct rpc_service_interface *attest_proxy_create(void);
+struct rpc_service_interface *crypto_proxy_create(void);
+struct rpc_service_interface *ps_proxy_create(void);
+struct rpc_service_interface *its_proxy_create(void);
 
 #ifdef __cplusplus
 }
diff --git a/deployments/se-proxy/infra/stub/service_proxy_factory.c b/deployments/se-proxy/infra/stub/service_proxy_factory.c
index acfb6e8..4cec9ce 100644
--- a/deployments/se-proxy/infra/stub/service_proxy_factory.c
+++ b/deployments/se-proxy/infra/stub/service_proxy_factory.c
@@ -5,36 +5,37 @@
  */
 
 #include <stddef.h>
-#include <rpc/common/endpoint/rpc_interface.h>
-#include <service/attestation/provider/attest_provider.h>
-#include <service/attestation/provider/serializer/packed-c/packedc_attest_provider_serializer.h>
-#include <service/crypto/factory/crypto_provider_factory.h>
-#include <service/secure_storage/frontend/secure_storage_provider/secure_storage_provider.h>
+#include "rpc/common/endpoint/rpc_service_interface.h"
+#include "service/attestation/provider/attest_provider.h"
+#include "service/attestation/provider/serializer/packed-c/packedc_attest_provider_serializer.h"
+#include "service/crypto/factory/crypto_provider_factory.h"
+#include "service/secure_storage/frontend/secure_storage_provider/secure_storage_provider.h"
+#include "service/secure_storage/frontend/secure_storage_provider/secure_storage_uuid.h"
 
 /* Stub backends */
 #include <service/crypto/backend/stub/stub_crypto_backend.h>
 #include <service/secure_storage/backend/mock_store/mock_store.h>
 
-struct rpc_interface *attest_proxy_create(void)
+struct rpc_service_interface *attest_proxy_create(void)
 {
-	struct rpc_interface *attest_iface;
+	struct rpc_service_interface *attest_iface = NULL;
 
 	/* Static objects for proxy instance */
-	static struct attest_provider attest_provider;
+	static struct attest_provider attest_provider = { 0 };
 
 	/* Initialize the service provider */
 	attest_iface = attest_provider_init(&attest_provider);
 
 	attest_provider_register_serializer(&attest_provider,
-		TS_RPC_ENCODING_PACKED_C, packedc_attest_provider_serializer_instance());
+					    packedc_attest_provider_serializer_instance());
 
 	return attest_iface;
 }
 
-struct rpc_interface *crypto_proxy_create(void)
+struct rpc_service_interface *crypto_proxy_create(void)
 {
-	struct rpc_interface *crypto_iface = NULL;
-	struct crypto_provider *crypto_provider;
+	struct rpc_service_interface *crypto_iface = NULL;
+	struct crypto_provider *crypto_provider = NULL;
 
 	if (stub_crypto_backend_init() == PSA_SUCCESS) {
 
@@ -45,22 +46,24 @@
 	return crypto_iface;
 }
 
-struct rpc_interface *ps_proxy_create(void)
+struct rpc_service_interface *ps_proxy_create(void)
 {
 	static struct mock_store ps_backend;
 	static struct secure_storage_provider ps_provider;
+	const struct rpc_uuid service_uuid = { .uuid = TS_PSA_PROTECTED_STORAGE_UUID };
 
 	struct storage_backend *backend = mock_store_init(&ps_backend);
 
-	return secure_storage_provider_init(&ps_provider, backend);
+	return secure_storage_provider_init(&ps_provider, backend, &service_uuid);
 }
 
-struct rpc_interface *its_proxy_create(void)
+struct rpc_service_interface *its_proxy_create(void)
 {
 	static struct mock_store its_backend;
 	static struct secure_storage_provider its_provider;
+	const struct rpc_uuid service_uuid = { .uuid = TS_PSA_INTERNAL_TRUSTED_STORAGE_UUID };
 
 	struct storage_backend *backend = mock_store_init(&its_backend);
 
-	return secure_storage_provider_init(&its_provider, backend);
+	return secure_storage_provider_init(&its_provider, backend, &service_uuid);
 }
diff --git a/deployments/se-proxy/se-proxy.cmake b/deployments/se-proxy/se-proxy.cmake
index 2643cfb..53bbf95 100644
--- a/deployments/se-proxy/se-proxy.cmake
+++ b/deployments/se-proxy/se-proxy.cmake
@@ -10,13 +10,11 @@
 	COMPONENTS
 		"components/common/tlv"
 		"components/rpc/common/interface"
-		"components/rpc/common/demux"
+		"components/rpc/common/endpoint"
 		"components/service/common/include"
 		"components/service/common/serializer/protobuf"
 		"components/service/common/client"
 		"components/service/common/provider"
-		"components/service/discovery/provider"
-		"components/service/discovery/provider/serializer/packed-c"
 		"components/service/crypto/client/psa"
 		"components/service/crypto/include"
 		"components/service/crypto/provider"