Imre Kis | 1ff7a52 | 2023-07-26 12:41:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef RPC_INTERFACE_H |
| 8 | #define RPC_INTERFACE_H |
| 9 | |
| 10 | #include "rpc_status.h" |
| 11 | #include "rpc_uuid.h" |
| 12 | #include <stddef.h> |
| 13 | #include <stdint.h> |
| 14 | |
| 15 | #ifdef EXPORT_PUBLIC_INTERFACE_RPC_SERVICE |
| 16 | #define RPC_SERVICE_EXPORTED __attribute__((__visibility__("default"))) |
| 17 | #else |
| 18 | #define RPC_SERVICE_EXPORTED |
| 19 | #endif |
| 20 | |
| 21 | #ifdef __cplusplus |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
| 25 | /** |
| 26 | * @brief RPC buffer |
| 27 | * |
| 28 | * Describes an RPC buffer by its data pointer, size and the used data length. |
| 29 | */ |
| 30 | struct rpc_buffer { |
| 31 | uint8_t *data; |
| 32 | size_t data_length; |
| 33 | size_t size; |
| 34 | }; |
| 35 | |
| 36 | /** |
| 37 | * @brief RPC request |
| 38 | * |
| 39 | * The service should select the requested function by the opcode field. The call's request and |
| 40 | * response parameter buffer is accessible via the request and response rpc_buffers. The response's |
| 41 | * size must be indicated by the service through setting the data_length field of the response. |
| 42 | * The services can identify the caller via the source_id and client_id fields. |
| 43 | */ |
| 44 | struct rpc_request { |
| 45 | uint16_t source_id; /** Call source ID (i.e. FF-A source ID) */ |
| 46 | uint8_t interface_id; /** Service interface ID */ |
| 47 | uint16_t opcode; /** Opcode of the required function */ |
| 48 | uint32_t client_id; /** Client ID for further caller identification */ |
| 49 | service_status_t service_status; /** Service specific status code */ |
| 50 | struct rpc_buffer request; /** Request buffer */ |
| 51 | struct rpc_buffer response; /** Response buffer */ |
| 52 | }; |
| 53 | |
| 54 | /** |
| 55 | * @brief RPC service interface |
| 56 | * |
| 57 | * An endpoint (i.e. secure partition) can implement multiple services which are identified by their |
| 58 | * service UUID. Once an endpoint receives an RPC call, it selects the matching |
| 59 | * rpc_service_interface instance, builds the rpc_request structure and calls the interface's |
| 60 | * receive function. |
| 61 | * If the service is not able to parse the request (invalid opcode, request or response buffer) |
| 62 | * it should return an rpc_status_t value indicating the issue with the RPC request. Otherwise it |
| 63 | * must return RPC_SUCCESS. |
| 64 | * Service level status codes should be passed in a service specific way. |
| 65 | */ |
| 66 | struct rpc_service_interface { |
| 67 | void *context; |
| 68 | struct rpc_uuid uuid; |
| 69 | |
| 70 | rpc_status_t (*receive)(void *context, struct rpc_request *request); |
| 71 | }; |
| 72 | |
| 73 | /** |
| 74 | * @brief Call the receive function of the RPC interface. |
| 75 | * |
| 76 | * @param service The service instance |
| 77 | * @param request RPC request |
| 78 | * @return rpc_status_t |
| 79 | */ |
| 80 | RPC_SERVICE_EXPORTED |
| 81 | rpc_status_t rpc_service_receive(struct rpc_service_interface *service, |
| 82 | struct rpc_request *request); |
| 83 | |
| 84 | #ifdef __cplusplus |
| 85 | } |
| 86 | #endif |
| 87 | |
| 88 | #endif /* RPC_INTERFACE_H */ |