Add RSS Communication Protocol components

The Corstone-1000 platform uses RSS Communication Protocol
to communicate between the Secure Enclave and the Host processor.

This uses the previously copied RSS Comm Protocol-related files
and has minor modifications to make them work correctly in
Trusted Services. Currently, only the Embed Protocol is supported
from the RSS Comms.

A new messaging and RPC component was made, and both of them follows the
previous OpenAMP and psa_ipc components' structures.

Modified the SE-Proxy deployment to use this new protocol instead of
the OpenAMP.

Signed-off-by: Bence Balogh <bence.balogh@arm.com>
Change-Id: Ia0d2c71396006404f28b8f1338dbbb939237cf62
diff --git a/components/messaging/rss_comms/sp/component.cmake b/components/messaging/rss_comms/sp/component.cmake
new file mode 100644
index 0000000..b9b7c4f
--- /dev/null
+++ b/components/messaging/rss_comms/sp/component.cmake
@@ -0,0 +1,27 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+if (NOT DEFINED TGT)
+	message(FATAL_ERROR "mandatory parameter TGT is not defined.")
+endif()
+
+set_property(TARGET ${TGT} APPEND PROPERTY PUBLIC_HEADER
+	"${CMAKE_CURRENT_LIST_DIR}/rss_comms_messenger_api.h"
+	)
+
+target_sources(${TGT} PRIVATE
+	"${CMAKE_CURRENT_LIST_DIR}/rss_comms_messenger.c"
+	"${CMAKE_CURRENT_LIST_DIR}/rss_comms_platform.c"
+	)
+
+target_include_directories(${TGT}
+	 PUBLIC
+		"${CMAKE_CURRENT_LIST_DIR}"
+	)
+
+set_property(TARGET ${TGT} APPEND PROPERTY TS_PLATFORM_DRIVER_DEPENDENCIES
+	"mhu"
+)
diff --git a/components/messaging/rss_comms/sp/rss_comms_messenger.c b/components/messaging/rss_comms/sp/rss_comms_messenger.c
new file mode 100644
index 0000000..644181e
--- /dev/null
+++ b/components/messaging/rss_comms/sp/rss_comms_messenger.c
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <errno.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <trace.h>
+
+#include "protocols/rpc/common/packed-c/status.h"
+#include "rss_comms_messenger_api.h"
+#include "rss_comms_platform_api.h"
+
+struct rss_comms_msg {
+	uint8_t *req_buf;
+	size_t req_len;
+	uint8_t *resp_buf;
+};
+
+int rss_comms_messenger_init(struct rss_comms_messenger *rss_comms)
+{
+	int ret = 0;
+
+	if (!rss_comms || rss_comms->msg || rss_comms->platform)
+		return -1;
+
+	rss_comms->msg = calloc(1, sizeof(struct rss_comms_msg));
+	if (!rss_comms->msg)
+		return -1;
+
+	rss_comms->platform = rss_comms_platform_init();
+	if (!rss_comms->platform) {
+		EMSG("Platform init failed");
+		free(rss_comms->msg);
+		rss_comms->msg = NULL;
+		return ret;
+	}
+
+	return 0;
+}
+
+void rss_comms_messenger_deinit(struct rss_comms_messenger *rss_comms)
+{
+	struct rss_comms_msg *msg = NULL;
+
+	if (!rss_comms)
+		return;
+
+	if (rss_comms->msg) {
+		msg = (struct rss_comms_msg *)rss_comms->msg;
+
+		if (msg->req_buf)
+			free(msg->req_buf);
+		if (msg->resp_buf)
+			free(msg->resp_buf);
+
+		free(msg);
+		rss_comms->msg = NULL;
+	}
+
+	rss_comms_platform_deinit(rss_comms->platform);
+	rss_comms->platform = NULL;
+}
+
+int rss_comms_messenger_call_invoke(struct rss_comms_messenger *rss_comms, uint8_t **resp_buf,
+				    size_t *resp_len)
+{
+	struct rss_comms_msg *msg = NULL;
+	int ret = 0;
+
+	if (!rss_comms || !resp_buf || !resp_len) {
+		EMSG("Invalid arguments");
+		return -1;
+	}
+
+	if (!rss_comms->msg) {
+		EMSG("msg is null");
+		return -1;
+	}
+
+	msg = (struct rss_comms_msg *)rss_comms->msg;
+	*resp_buf = calloc(1, *resp_len);
+
+	if (!(*resp_buf))
+		return -1;
+
+	ret = rss_comms_platform_invoke(rss_comms->platform, *resp_buf, msg->req_buf, resp_len,
+					msg->req_len);
+
+	if (ret < 0) {
+		free(*resp_buf);
+		*resp_buf = NULL;
+		return ret;
+	}
+
+	msg->resp_buf = *resp_buf;
+
+	return 0;
+}
+
+int rss_comms_messenger_call_begin(struct rss_comms_messenger *rss_comms, uint8_t **req_buf,
+				   size_t req_len)
+{
+	int ret = 0;
+	struct rss_comms_msg *msg = NULL;
+
+	if (!rss_comms || !req_buf || !rss_comms->msg)
+		return -1;
+
+	if (req_len > UINT32_MAX || req_len == 0) {
+		EMSG("req_len invalid: %lu", req_len);
+		return -1;
+	}
+
+	msg = (struct rss_comms_msg *)rss_comms->msg;
+
+	if (msg->req_buf)
+		return -1;
+
+	msg->req_buf = calloc(1, req_len);
+
+	if (!msg->req_buf)
+		return -1;
+
+	*req_buf = msg->req_buf;
+	msg->req_len = req_len;
+
+	ret = rss_comms_platform_begin(rss_comms->platform, *req_buf, req_len);
+
+	return ret;
+}
+
+void rss_comms_messenger_call_end(struct rss_comms_messenger *rss_comms)
+{
+	int ret = 0;
+	struct rss_comms_msg *msg = NULL;
+
+	if (!rss_comms || !rss_comms->msg)
+		return;
+
+	msg = (struct rss_comms_msg *)rss_comms->msg;
+
+	if (msg->req_buf)
+		free(msg->req_buf);
+
+	if (msg->resp_buf)
+		free(msg->resp_buf);
+
+	msg->req_len = 0;
+	msg->req_buf = NULL;
+	msg->resp_buf = NULL;
+
+	ret = rss_comms_platform_end(rss_comms->platform);
+
+	if (ret < 0) {
+		EMSG("Platform end failed: %d", ret);
+		return;
+	}
+}
diff --git a/components/messaging/rss_comms/sp/rss_comms_messenger_api.h b/components/messaging/rss_comms/sp/rss_comms_messenger_api.h
new file mode 100644
index 0000000..02bb6b5
--- /dev/null
+++ b/components/messaging/rss_comms/sp/rss_comms_messenger_api.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef __RSS_COMMS_MESSENGER_API_H__
+#define __RSS_COMMS_MESSENGER_API_H__
+
+#include <stddef.h>
+#include <stdint.h>
+
+struct rss_comms_messenger {
+	void *msg;
+	void *platform;
+};
+
+int rss_comms_messenger_init(struct rss_comms_messenger *rss_comms);
+void rss_comms_messenger_deinit(struct rss_comms_messenger *rss_comms);
+int rss_comms_messenger_call_invoke(struct rss_comms_messenger *rss_comms, uint8_t **resp_buf,
+				    size_t *resp_len);
+int rss_comms_messenger_call_begin(struct rss_comms_messenger *rss_comms, uint8_t **req_buf,
+				   size_t req_len);
+void rss_comms_messenger_call_end(struct rss_comms_messenger *rss_comms);
+
+#endif /* __RSS_COMMS_MESSENGER_API_H__ */
diff --git a/components/messaging/rss_comms/sp/rss_comms_platform.c b/components/messaging/rss_comms/sp/rss_comms_platform.c
new file mode 100644
index 0000000..5e09db2
--- /dev/null
+++ b/components/messaging/rss_comms/sp/rss_comms_platform.c
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <trace.h>
+
+#include "platform/interface/mhu_interface.h"
+#include "rss_comms_messenger_api.h"
+#include "rss_comms_platform_api.h"
+
+struct rss_comms_platform {
+	struct platform_mhu_driver rx_dev;
+	struct platform_mhu_driver tx_dev;
+};
+
+struct rss_comms_platform *rss_comms_platform_init(void)
+{
+	struct rss_comms_platform *rss_comms_plat = NULL;
+	int ret = 0;
+
+	rss_comms_plat = calloc(1, sizeof(*rss_comms_plat));
+	if (!rss_comms_plat) {
+		EMSG("rss_comms calloc dev failed");
+		return NULL;
+	}
+
+	ret = platform_mhu_create(&rss_comms_plat->rx_dev, "mhu-receiver", true);
+	if (ret < 0)
+		goto free_plat;
+
+	ret = platform_mhu_create(&rss_comms_plat->tx_dev, "mhu-sender", false);
+	if (ret < 0)
+		goto free_rx_dev;
+
+	return rss_comms_plat;
+
+free_rx_dev:
+	platform_mhu_destroy(&rss_comms_plat->rx_dev);
+free_plat:
+	free(rss_comms_plat);
+
+	return NULL;
+}
+
+int rss_comms_platform_deinit(struct rss_comms_platform *rss_comms_plat)
+{
+	if (!rss_comms_plat)
+		return -1;
+
+	platform_mhu_destroy(&rss_comms_plat->rx_dev);
+	platform_mhu_destroy(&rss_comms_plat->tx_dev);
+
+	free(rss_comms_plat);
+
+	return 0;
+}
+
+int rss_comms_platform_invoke(struct rss_comms_platform *rss_comms_plat, uint8_t *resp_buf,
+			      uint8_t *req_buf, size_t *resp_len, size_t req_len)
+{
+	struct platform_mhu_driver *rx_dev = NULL;
+	struct platform_mhu_driver *tx_dev = NULL;
+	int err = 0;
+
+	if (!rss_comms_plat || !resp_buf || !req_buf)
+		return -1;
+
+	rx_dev = &rss_comms_plat->rx_dev;
+	tx_dev = &rss_comms_plat->tx_dev;
+
+	if (!tx_dev->iface || !tx_dev->iface->send)
+		return -1;
+
+	err = tx_dev->iface->send(tx_dev->context, req_buf, req_len);
+	if (err != 0) {
+		EMSG("mhu send data failed!");
+		return -1;
+	}
+
+	if (!rx_dev->iface || !rx_dev->iface->wait_data || !rx_dev->iface->receive)
+		return -1;
+
+	err = rx_dev->iface->wait_data(rx_dev->context);
+	if (err != 0) {
+		EMSG("mhu wait for signal failed!");
+		return -1;
+	}
+
+	err = rx_dev->iface->receive(rx_dev->context, resp_buf, resp_len);
+	if (err != 0) {
+		EMSG("mhu receive data failed!");
+		return -1;
+	}
+
+	return 0;
+}
+
+int rss_comms_platform_begin(struct rss_comms_platform *rss_comms_plat, uint8_t *req_buf,
+			     size_t req_len)
+{
+	return 0;
+}
+
+int rss_comms_platform_end(struct rss_comms_platform *rss_comms_plat)
+{
+	return 0;
+}
diff --git a/components/messaging/rss_comms/sp/rss_comms_platform_api.h b/components/messaging/rss_comms/sp/rss_comms_platform_api.h
new file mode 100644
index 0000000..ed55506
--- /dev/null
+++ b/components/messaging/rss_comms/sp/rss_comms_platform_api.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef __RSS_COMMS_PLATFORM_API_H__
+#define __RSS_COMMS_PLATFORM_API_H__
+
+#include <stdint.h>
+
+struct rss_comms_platform;
+
+struct rss_comms_platform *rss_comms_platform_init(void);
+int rss_comms_platform_deinit(struct rss_comms_platform *rss_comms_plat);
+int rss_comms_platform_invoke(struct rss_comms_platform *rss_comms_plat, uint8_t *resp_buf,
+			      uint8_t *req_buf, size_t *resp_len, size_t req_len);
+int rss_comms_platform_begin(struct rss_comms_platform *rss_comms_plat, uint8_t *req_buf,
+			     size_t req_len);
+int rss_comms_platform_end(struct rss_comms_platform *rss_comms_plat);
+
+#endif /* __RSS_COMMS_PLATFORM_API_H__ */