Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 1 | /* |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 2 | * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved. |
Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 7 | #ifndef RPC_INTERFACE_H |
| 8 | #define RPC_INTERFACE_H |
Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 9 | |
| 10 | #include <stddef.h> |
| 11 | #include <stdint.h> |
| 12 | #include <rpc_status.h> |
| 13 | |
| 14 | #ifdef __cplusplus |
| 15 | extern "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 | */ |
| 24 | struct call_param_buf { |
| 25 | size_t size; |
| 26 | size_t data_len; |
| 27 | void *data; |
| 28 | }; |
| 29 | |
| 30 | static 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 | |
| 41 | static 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 Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 54 | /** \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 | */ |
| 59 | struct call_req { |
| 60 | uint32_t caller_id; |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 61 | uint32_t interface_id; |
Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 62 | uint32_t opcode; |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 63 | uint32_t encoding; |
Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 64 | int opstatus; |
Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 65 | struct call_param_buf req_buf; |
| 66 | struct call_param_buf resp_buf; |
| 67 | }; |
| 68 | |
| 69 | static inline uint32_t call_req_get_caller_id(const struct call_req *req) |
| 70 | { |
| 71 | return req->caller_id; |
| 72 | } |
| 73 | |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 74 | static inline uint32_t call_req_get_interface_id(const struct call_req *req) |
| 75 | { |
| 76 | return req->interface_id; |
| 77 | } |
| 78 | |
Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 79 | static inline uint32_t call_req_get_opcode(const struct call_req *req) |
| 80 | { |
| 81 | return req->opcode; |
| 82 | } |
| 83 | |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 84 | static inline uint32_t call_req_get_encoding(const struct call_req *req) |
| 85 | { |
| 86 | return req->encoding; |
| 87 | } |
| 88 | |
Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 89 | static inline int call_req_get_opstatus(const struct call_req *req) |
| 90 | { |
| 91 | return req->opstatus; |
| 92 | } |
| 93 | |
| 94 | static inline void call_req_set_opstatus(struct call_req *req, int opstatus) |
| 95 | { |
| 96 | req->opstatus = opstatus; |
| 97 | } |
| 98 | |
Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 99 | static inline struct call_param_buf *call_req_get_req_buf(struct call_req *req) |
| 100 | { |
| 101 | return &req->req_buf; |
| 102 | } |
| 103 | |
| 104 | static inline struct call_param_buf *call_req_get_resp_buf(struct call_req *req) |
| 105 | { |
| 106 | return &req->resp_buf; |
| 107 | } |
| 108 | |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 109 | /** \brief RPC interface |
Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 110 | * |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 111 | * A generalized RPC interface. Provides a standard interface for a |
Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 112 | * call endpoint that handles incoming call requests. |
| 113 | */ |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 114 | struct rpc_interface |
Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 115 | { |
| 116 | void *context; |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 117 | rpc_status_t (*receive)(struct rpc_interface *iface, struct call_req *req); |
Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 118 | }; |
| 119 | |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 120 | static inline rpc_status_t rpc_interface_receive(struct rpc_interface *iface, |
Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 121 | struct call_req *req) |
| 122 | { |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 123 | return iface->receive(iface, req); |
Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | #ifdef __cplusplus |
| 127 | } |
| 128 | #endif |
| 129 | |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 130 | #endif /* RPC_INTERFACE_H */ |