Add generic RPC layer
Adds generic RPC caller and endpoint. This is the base for specialized
RPC communication using e.g. FF-A messaging. The protocol description
is implemented in two flavours: packed C structures and protobuf.
Change-Id: I17f450b7272bd4008fc20fe8f716a253f6754000
Signed-off-by: Julian Hall <julian.hall@arm.com>
diff --git a/protocols/rpc/common/packed-c/component.cmake b/protocols/rpc/common/packed-c/component.cmake
new file mode 100644
index 0000000..041f7d5
--- /dev/null
+++ b/protocols/rpc/common/packed-c/component.cmake
@@ -0,0 +1,14 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, 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()
+
+target_include_directories(${TGT}
+ PRIVATE
+ "${CMAKE_CURRENT_LIST_DIR}"
+ )
diff --git a/protocols/rpc/common/packed-c/status.h b/protocols/rpc/common/packed-c/status.h
new file mode 100644
index 0000000..7f78429
--- /dev/null
+++ b/protocols/rpc/common/packed-c/status.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PROTOCOLS_RPC_COMMON_STATUS_H
+#define PROTOCOLS_RPC_COMMON_STATUS_H
+
+/* Common RPC status codes for C/C++
+ *
+ * Alignment of these definitions with other defintions for
+ * alternative languages is checked through a set of test cases.
+ * These status values are aligned to PSA definitions.
+ */
+#define TS_RPC_CALL_ACCEPTED (0)
+#define TS_RPC_ERROR_EP_DOES_NOT_EXIT (-1)
+#define TS_RPC_ERROR_INVALID_OPCODE (-2)
+#define TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED (-3)
+#define TS_RPC_ERROR_INVALID_REQ_BODY (-4)
+#define TS_RPC_ERROR_INVALID_RESP_BODY (-5)
+#define TS_RPC_ERROR_RESOURCE_FAILURE (-6)
+#define TS_RPC_ERROR_NOT_READY (-7)
+#define TS_RPC_ERROR_INVALID_TRANSACTION (-8)
+#define TS_RPC_ERROR_INTERNAL (-9)
+#define TS_RPC_ERROR_INVALID_PARAMETER (-10)
+
+#endif /* PROTOCOLS_RPC_COMMON_STATUS_H */
diff --git a/protocols/rpc/common/packed-c/test/check_rpc_status_packed-c.cpp b/protocols/rpc/common/packed-c/test/check_rpc_status_packed-c.cpp
new file mode 100644
index 0000000..c377957
--- /dev/null
+++ b/protocols/rpc/common/packed-c/test/check_rpc_status_packed-c.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+#include <rpc/common/protobuf/status.pb.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <CppUTest/TestHarness.h>
+
+/*
+ * Check alignment of packed-c protocol values.
+ */
+TEST_GROUP(PackedCrpcCommonProtocolChecks) {
+
+};
+
+TEST(PackedCrpcCommonProtocolChecks, checkRpcStatusCodes) {
+
+ /*
+ * Check alignment between packed-c and protobuf rpc status codes
+ */
+ CHECK_EQUAL(TS_RPC_CALL_ACCEPTED, ts_rpc_Status_CALL_ACCEPTED);
+ CHECK_EQUAL(TS_RPC_ERROR_EP_DOES_NOT_EXIT, ts_rpc_Status_ERROR_EP_DOES_NOT_EXIT);
+ CHECK_EQUAL(TS_RPC_ERROR_INVALID_OPCODE, ts_rpc_Status_ERROR_INVALID_OPCODE);
+ CHECK_EQUAL(TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED, ts_rpc_Status_ERROR_SERIALIZATION_NOT_SUPPORTED);
+ CHECK_EQUAL(TS_RPC_ERROR_INVALID_REQ_BODY, ts_rpc_Status_ERROR_INVALID_REQ_BODY);
+ CHECK_EQUAL(TS_RPC_ERROR_INVALID_RESP_BODY, ts_rpc_Status_ERROR_INVALID_RESP_BODY);
+ CHECK_EQUAL(TS_RPC_ERROR_RESOURCE_FAILURE, ts_rpc_Status_ERROR_RESOURCE_FAILURE);
+ CHECK_EQUAL(TS_RPC_ERROR_NOT_READY, ts_rpc_Status_ERROR_NOT_READY);
+ CHECK_EQUAL(TS_RPC_ERROR_INVALID_TRANSACTION, ts_rpc_Status_ERROR_INVALID_TRANSACTION);
+ CHECK_EQUAL(TS_RPC_ERROR_INTERNAL, ts_rpc_Status_ERROR_INTERNAL);
+ CHECK_EQUAL(TS_RPC_ERROR_INVALID_PARAMETER, ts_rpc_Status_ERROR_INVALID_PARAMETER);
+}
\ No newline at end of file
diff --git a/protocols/rpc/common/packed-c/test/component.cmake b/protocols/rpc/common/packed-c/test/component.cmake
new file mode 100644
index 0000000..28a896b
--- /dev/null
+++ b/protocols/rpc/common/packed-c/test/component.cmake
@@ -0,0 +1,14 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, 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()
+
+target_sources(${TGT} PRIVATE
+ "${CMAKE_CURRENT_LIST_DIR}/check_rpc_status_packed-c.cpp"
+ )
+
diff --git a/protocols/rpc/common/protobuf/component.cmake b/protocols/rpc/common/protobuf/component.cmake
new file mode 100644
index 0000000..8155c2d
--- /dev/null
+++ b/protocols/rpc/common/protobuf/component.cmake
@@ -0,0 +1,13 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, 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 PROTOBUF_FILES
+ "${CMAKE_CURRENT_LIST_DIR}/status.proto"
+ )
diff --git a/protocols/rpc/common/protobuf/status.proto b/protocols/rpc/common/protobuf/status.proto
new file mode 100644
index 0000000..aa5cb08
--- /dev/null
+++ b/protocols/rpc/common/protobuf/status.proto
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+syntax = "proto3";
+
+package ts_rpc;
+
+/* Common RPC status codes */
+enum Status {
+ CALL_ACCEPTED = 0;
+ ERROR_EP_DOES_NOT_EXIT = -1;
+ ERROR_INVALID_OPCODE = -2;
+ ERROR_SERIALIZATION_NOT_SUPPORTED = -3;
+ ERROR_INVALID_REQ_BODY = -4;
+ ERROR_INVALID_RESP_BODY = -5;
+ ERROR_RESOURCE_FAILURE = -6;
+ ERROR_NOT_READY = -7;
+ ERROR_INVALID_TRANSACTION = -8;
+ ERROR_INTERNAL = -9;
+ ERROR_INVALID_PARAMETER = -10;
+}