blob: 44e5783548b6353c672a926809845f63cdba49b9 [file] [log] [blame]
Julian Hall6c59e4e2020-11-23 17:50:47 +01001/*
julhal01c3f4e9a2020-12-15 13:39:01 +00002 * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
Julian Hall6c59e4e2020-11-23 17:50:47 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
julhal01c3f4e9a2020-12-15 13:39:01 +00007#ifndef RPC_INTERFACE_H
8#define RPC_INTERFACE_H
Julian Hall6c59e4e2020-11-23 17:50:47 +01009
10#include <stddef.h>
11#include <stdint.h>
12#include <rpc_status.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18/* Definitions related to an rpc call endpoint */
19
20/** \brief Call parameter buffer
21 *
22 * Describes a buffer for holding call request and response parameters.
23 */
24struct call_param_buf {
25 size_t size;
26 size_t data_len;
27 void *data;
28};
29
30static inline struct call_param_buf call_param_buf_init_empty(void *data, size_t size)
31{
32 struct call_param_buf v;
33
34 v.size = size;
35 v.data_len = 0;
36 v.data = data;
37
38 return v;
39}
40
41static inline struct call_param_buf call_param_buf_init_full(void *data,
42 size_t size,
43 size_t data_len)
44{
45 struct call_param_buf v;
46
47 v.size = size;
48 v.data_len = data_len;
49 v.data = data;
50
51 return v;
52}
53
Julian Hall6c59e4e2020-11-23 17:50:47 +010054/** \brief Call request
55 *
56 * A call request object represents a request from a client that will
57 * be handled by a call endpoint.
58 */
59struct call_req {
60 uint32_t caller_id;
julhal01c3f4e9a2020-12-15 13:39:01 +000061 uint32_t interface_id;
Julian Hall6c59e4e2020-11-23 17:50:47 +010062 uint32_t opcode;
julhal01c3f4e9a2020-12-15 13:39:01 +000063 uint32_t encoding;
Julian Hall6c59e4e2020-11-23 17:50:47 +010064 int opstatus;
Julian Hall6c59e4e2020-11-23 17:50:47 +010065 struct call_param_buf req_buf;
66 struct call_param_buf resp_buf;
67};
68
69static inline uint32_t call_req_get_caller_id(const struct call_req *req)
70{
71 return req->caller_id;
72}
73
julhal01c3f4e9a2020-12-15 13:39:01 +000074static inline uint32_t call_req_get_interface_id(const struct call_req *req)
75{
76 return req->interface_id;
77}
78
Julian Hall6c59e4e2020-11-23 17:50:47 +010079static inline uint32_t call_req_get_opcode(const struct call_req *req)
80{
81 return req->opcode;
82}
83
julhal01c3f4e9a2020-12-15 13:39:01 +000084static inline uint32_t call_req_get_encoding(const struct call_req *req)
85{
86 return req->encoding;
87}
88
Julian Hall6c59e4e2020-11-23 17:50:47 +010089static inline int call_req_get_opstatus(const struct call_req *req)
90{
91 return req->opstatus;
92}
93
94static inline void call_req_set_opstatus(struct call_req *req, int opstatus)
95{
96 req->opstatus = opstatus;
97}
98
Julian Hall6c59e4e2020-11-23 17:50:47 +010099static inline struct call_param_buf *call_req_get_req_buf(struct call_req *req)
100{
101 return &req->req_buf;
102}
103
104static inline struct call_param_buf *call_req_get_resp_buf(struct call_req *req)
105{
106 return &req->resp_buf;
107}
108
julhal01c3f4e9a2020-12-15 13:39:01 +0000109/** \brief RPC interface
Julian Hall6c59e4e2020-11-23 17:50:47 +0100110 *
julhal01c3f4e9a2020-12-15 13:39:01 +0000111 * A generalized RPC interface. Provides a standard interface for a
Julian Hall6c59e4e2020-11-23 17:50:47 +0100112 * call endpoint that handles incoming call requests.
113 */
julhal01c3f4e9a2020-12-15 13:39:01 +0000114struct rpc_interface
Julian Hall6c59e4e2020-11-23 17:50:47 +0100115{
116 void *context;
julhal01c3f4e9a2020-12-15 13:39:01 +0000117 rpc_status_t (*receive)(struct rpc_interface *iface, struct call_req *req);
Julian Hall6c59e4e2020-11-23 17:50:47 +0100118};
119
julhal01c3f4e9a2020-12-15 13:39:01 +0000120static inline rpc_status_t rpc_interface_receive(struct rpc_interface *iface,
Julian Hall6c59e4e2020-11-23 17:50:47 +0100121 struct call_req *req)
122{
julhal01c3f4e9a2020-12-15 13:39:01 +0000123 return iface->receive(iface, req);
Julian Hall6c59e4e2020-11-23 17:50:47 +0100124}
125
126#ifdef __cplusplus
127}
128#endif
129
julhal01c3f4e9a2020-12-15 13:39:01 +0000130#endif /* RPC_INTERFACE_H */