Extend RPC parameters

The RPC model is extended to include parameters for identifying
an RPC interface instance at an endpoint and another for
identifying the parameter encoding.  The interface ID parameter
allows multiple service interfaces to be co-located.  The encoding
parameter allows clients to use different parameter serialization
schemes and to specify the format in each RPC request.

Signed-off-by: julhal01 <julian.hall@arm.com>
Change-Id: I201b3417dc0e9f655113b9931db3494e41f1d74b
diff --git a/protocols/rpc/common/packed-c/encoding.h b/protocols/rpc/common/packed-c/encoding.h
new file mode 100644
index 0000000..cd7093c
--- /dev/null
+++ b/protocols/rpc/common/packed-c/encoding.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PROTOCOLS_RPC_COMMON_ENCODING_H
+#define PROTOCOLS_RPC_COMMON_ENCODING_H
+
+/*
+ * Encodings used for parameter serialization.
+ */
+enum
+{
+    /*
+     * Packed-c encoding.  A lightweight serialization scheme with
+     * C language definition files.
+     */
+    TS_RPC_ENCODING_PACKED_C        =  0,
+
+    /*
+     * Protocol Buffers serialization scheme with language independent
+     * definition files.  Supports client code generation using definition
+     * files.
+     */
+    TS_RPC_ENCODING_PROTOBUF        =  1,
+
+    /*
+     * The limit of known encodings.  As new encodings are added,
+     * the limit value should be allowed to increase.  An RPC interface
+     * that was built before a new encoding was added should safely
+     * reject an unsupported encoding.
+     */
+    TS_RPC_ENCODING_LIMIT
+};
+
+#endif /* PROTOCOLS_RPC_COMMON_ENCODING_H */
diff --git a/protocols/rpc/common/packed-c/header.h b/protocols/rpc/common/packed-c/header.h
new file mode 100644
index 0000000..2542dbd
--- /dev/null
+++ b/protocols/rpc/common/packed-c/header.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PROTOCOLS_RPC_COMMON_HEADER_H
+#define PROTOCOLS_RPC_COMMON_HEADER_H
+
+#include <stdint.h>
+
+/*
+ * Defines an RPC request header that may be used for a packed-c serialization
+ * of common RPC fields.  Different RPC protocols my carry some or all of these
+ * fields in a protocol specific way.  If a particular protocol does't, this
+ * structure provides a common definition that may be used.
+ */
+struct __attribute__ ((__packed__)) ts_rpc_req_hdr
+{
+    /*
+     * A trustworthy identifier for the call originator.  Used for access control, applied
+     * at the remote RPC interface.  This ID will have been added by an intermediary running
+     * at a higher privilege level than the caller.  Example caller_ids could be the UID
+     * or SELinux label associated with a calling process.  The caller_id may be supplemented
+     * by a source identity from the messaging layer (e.g. the source partition ID).
+     */
+    uint32_t caller_id;
+
+    /*
+     * Identifies a particular RPC interface instance that is reachable at a messaging
+     * endpoint.  Allows multiple services to be co-located at a single messaging endpoint.
+     */
+    uint16_t interface_id;
+
+    /*
+     * Identifies the requested operation to call.
+     */
+    uint16_t opcode;
+
+    /*
+     * Identifies the encoding scheme used to serialize request and response parameters.
+     * It is the responsibility of the caller to specify an encoding that the destination
+     * RPC interface can handle.  Must be set to a meaningful value, even if there are
+     * no request parameters.  This is because response parameters will beb serialized
+     * using the same encoding.
+     */
+    uint16_t encoding;
+
+    /*
+     * Specifies the length in bytes of the serialized parameters.
+     */
+    uint16_t param_len;
+};
+
+/*
+ * Defines the coresponding response header, used for returning status and
+ * any output parameters, serialized using the same encoding as specified in
+ * the request header.
+ */
+struct __attribute__ ((__packed__)) ts_rpc_resp_hdr
+{
+    /*
+     * Returns the RPC layer status.  Only if a value of TS_RPC_CALL_ACCEPTED
+     * is returned should the opstatus value be consider.  The RPC status is
+     * kept separate from the opstatus to allow a service specific status coding
+     * namespace to coexist with the RPC status namespace.
+     */
+    int16_t rpc_status;
+
+    /*
+     * Returns the status of the requested operation.  The meaning of this status
+     * code will be service specific.
+     */
+    int16_t op_status;
+
+    /*
+     * Specifies the length in bytes of the serialized parameters.
+     */
+    uint16_t param_len;
+};
+
+#endif /* PROTOCOLS_RPC_COMMON_HEADER_H */
diff --git a/protocols/rpc/common/packed-c/status.h b/protocols/rpc/common/packed-c/status.h
index 7f78429..3838240 100644
--- a/protocols/rpc/common/packed-c/status.h
+++ b/protocols/rpc/common/packed-c/status.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -13,16 +13,19 @@
  * 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)
+enum
+{
+    TS_RPC_CALL_ACCEPTED                            =  0,
+    TS_RPC_ERROR_EP_DOES_NOT_EXIT                   = -1,
+    TS_RPC_ERROR_INVALID_OPCODE                     = -2,
+    TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED        = -3,
+    TS_RPC_ERROR_INVALID_REQ_BODY                   = -4,
+    TS_RPC_ERROR_INVALID_RESP_BODY                  = -5,
+    TS_RPC_ERROR_RESOURCE_FAILURE                   = -6,
+    TS_RPC_ERROR_NOT_READY                          = -7,
+    TS_RPC_ERROR_INVALID_TRANSACTION                = -8,
+    TS_RPC_ERROR_INTERNAL                           = -9,
+    TS_RPC_ERROR_INVALID_PARAMETER                  = -10
+};
 
 #endif /* PROTOCOLS_RPC_COMMON_STATUS_H */