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/components/rpc/common/interface/rpc_caller.h b/components/rpc/common/interface/rpc_caller.h
new file mode 100644
index 0000000..a75bdd9
--- /dev/null
+++ b/components/rpc/common/interface/rpc_caller.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef RPC_CALLER_H
+#define RPC_CALLER_H
+
+#include <stddef.h>
+#include <stdint.h>
+#include "rpc_status.h"
+
+/*
+ * The rpc_caller puplic interface may be exported as a public interface to
+ * a shared library.
+ */
+#ifdef EXPORT_PUBLIC_INTERFACE_RPC_CALLER
+#define RPC_CALLER_EXPORTED __attribute__((__visibility__("default")))
+#else
+#define RPC_CALLER_EXPORTED
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Defines an abstract interface for calling operations provided by an rpc endpoint.
+ * Concrete specializations will map the an RPC or direct calling mechanism to
+ * suite the deployment.
+ */
+
+typedef void *rpc_call_handle;
+
+struct rpc_caller
+{
+	void *context;
+
+	/* A concrete rpc_caller implements these methods */
+	rpc_call_handle (*call_begin)(void *context, uint8_t **req_buf, size_t req_len);
+
+	rpc_status_t (*call_invoke)(void *context, rpc_call_handle handle, uint32_t opcode,
+		     	int *opstatus, uint8_t **resp_buf, size_t *resp_len);
+
+	void (*call_end)(void *context, rpc_call_handle handle);
+};
+
+/*
+ * Starts a call transaction. The returned handle is an identifier for the
+ * transaction and must be passed as a parameter to call_invoke() and
+ * call_end(). A concrete rpc_caller may perform resource allocation during
+ * this call. This will include a buffer for the request message parameters.
+ * Returns a NULL handle on failure.
+ */
+RPC_CALLER_EXPORTED rpc_call_handle rpc_caller_begin(struct rpc_caller *s,
+			uint8_t **req_buf, size_t req_len);
+
+/*
+ * Invokes the operation identified by the opcode. This method blocks
+ * until the operation completes. The status of the call is returned. An
+ * additional endpoint specific status value is also returned. If a response
+ * message was received, the concrete rpc_caller will have allocated a
+ * buffer for the reponse. This buffer will hold valid data until the point when
+ * call_end() is called for the transaction.
+ */
+RPC_CALLER_EXPORTED rpc_status_t rpc_caller_invoke(struct rpc_caller *s, rpc_call_handle handle,
+			uint32_t opcode, int *opstatus, uint8_t **resp_buf, size_t *resp_len);
+
+/*
+ * Ends the call transaction, allowing any resource associated with the
+ * transaction to be freed.
+ */
+RPC_CALLER_EXPORTED void rpc_caller_end(struct rpc_caller *s, rpc_call_handle handle);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* RPC_CALLER_H */