Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 1 | /* |
Mate Toth-Pal | 2a6f8c2 | 2018-12-13 16:37:17 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2019, Arm Limited. All rights reserved. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef __PSA_CLIENT_H__ |
| 9 | #define __PSA_CLIENT_H__ |
| 10 | |
Jamie Fox | 520fb4d | 2019-06-13 14:27:21 +0100 | [diff] [blame] | 11 | #include <stddef.h> |
| 12 | #include <stdint.h> |
| 13 | |
| 14 | #include "psa/error.h" |
| 15 | |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 16 | #ifdef __cplusplus |
| 17 | extern "C" { |
| 18 | #endif |
| 19 | |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 20 | /*********************** PSA Client Macros and Types *************************/ |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 21 | |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 22 | /** |
| 23 | * The version of the PSA Framework API that is being used to build the calling |
| 24 | * firmware. |
| 25 | */ |
| 26 | #define PSA_FRAMEWORK_VERSION (0x0100u) |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 27 | |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 28 | /** |
| 29 | * Return value from psa_version() if the requested RoT Service is not present |
| 30 | * in the system. |
| 31 | */ |
| 32 | #define PSA_VERSION_NONE (0u) |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 33 | |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 34 | /** |
| 35 | * The zero-value null handle can be assigned to variables used in clients and |
| 36 | * RoT Services, indicating that there is no current connection or message. |
| 37 | */ |
| 38 | #define PSA_NULL_HANDLE ((psa_handle_t)0) |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 39 | |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 40 | /** |
| 41 | * Tests whether a handle value returned by psa_connect() is valid. |
| 42 | */ |
| 43 | #define PSA_HANDLE_IS_VALID(handle) ((psa_handle_t)(handle) > 0) |
| 44 | |
| 45 | /** |
| 46 | * Converts the handle value returned from a failed call psa_connect() into |
| 47 | * an error code. |
| 48 | */ |
| 49 | #define PSA_HANDLE_TO_ERROR(handle) ((psa_status_t)(handle)) |
| 50 | |
| 51 | /** |
| 52 | * Maximum number of input and output vectors for a request to psa_call(). |
| 53 | */ |
| 54 | #define PSA_MAX_IOVEC (4u) |
| 55 | |
| 56 | /** |
| 57 | * An IPC message type that indicates a generic client request. |
| 58 | */ |
| 59 | #define PSA_IPC_CALL (0) |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 60 | |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 61 | typedef int32_t psa_handle_t; |
| 62 | |
| 63 | /** |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 64 | * A read-only input memory region provided to an RoT Service. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 65 | */ |
| 66 | typedef struct psa_invec { |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 67 | const void *base; /*!< the start address of the memory buffer */ |
| 68 | size_t len; /*!< the size in bytes */ |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 69 | } psa_invec; |
| 70 | |
| 71 | /** |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 72 | * A writable output memory region provided to an RoT Service. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 73 | */ |
| 74 | typedef struct psa_outvec { |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 75 | void *base; /*!< the start address of the memory buffer */ |
| 76 | size_t len; /*!< the size in bytes */ |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 77 | } psa_outvec; |
| 78 | |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 79 | /*************************** PSA Client API **********************************/ |
| 80 | |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 81 | /** |
| 82 | * \brief Retrieve the version of the PSA Framework API that is implemented. |
| 83 | * |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 84 | * \return version The version of the PSA Framework implementation |
| 85 | * that is providing the runtime services to the |
| 86 | * caller. The major and minor version are encoded |
| 87 | * as follows: |
| 88 | * \arg version[15:8] -- major version number. |
| 89 | * \arg version[7:0] -- minor version number. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 90 | */ |
| 91 | uint32_t psa_framework_version(void); |
| 92 | |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 93 | /** |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 94 | * \brief Retrieve the version of an RoT Service or indicate that it is not |
| 95 | * present on this system. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 96 | * |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 97 | * \param[in] sid ID of the RoT Service to query. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 98 | * |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 99 | * \retval PSA_VERSION_NONE The RoT Service is not implemented, or the |
| 100 | * caller is not permitted to access the service. |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 101 | * \retval > 0 The version of the implemented RoT Service. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 102 | */ |
| 103 | uint32_t psa_version(uint32_t sid); |
| 104 | |
| 105 | /** |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 106 | * \brief Connect to an RoT Service by its SID. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 107 | * |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 108 | * \param[in] sid ID of the RoT Service to connect to. |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 109 | * \param[in] version Requested version of the RoT Service. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 110 | * |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 111 | * \retval > 0 A handle for the connection. |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 112 | * \retval PSA_ERROR_CONNECTION_REFUSED The SPM or RoT Service has refused the |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 113 | * connection. |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 114 | * \retval PSA_ERROR_CONNECTION_BUSY The SPM or RoT Service cannot make the |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 115 | * connection at the moment. |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 116 | * \retval "PROGRAMMER ERROR" The call is a PROGRAMMER ERROR if one or more |
| 117 | * of the following are true: |
| 118 | * \arg The RoT Service ID is not present. |
| 119 | * \arg The RoT Service version is not supported. |
| 120 | * \arg The caller is not allowed to access the RoT |
| 121 | * service. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 122 | */ |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 123 | psa_handle_t psa_connect(uint32_t sid, uint32_t version); |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 124 | |
| 125 | /** |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 126 | * \brief Call an RoT Service on an established connection. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 127 | * |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 128 | * \param[in] handle A handle to an established connection. |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 129 | * \param[in] type The reuqest type. |
Summer Qin | 632b3e0 | 2019-07-29 15:34:38 +0800 | [diff] [blame^] | 130 | * Must be zero( \ref PSA_IPC_CALL) or positive. |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 131 | * \param[in] in_vec Array of input \ref psa_invec structures. |
| 132 | * \param[in] in_len Number of input \ref psa_invec structures. |
| 133 | * \param[in/out] out_vec Array of output \ref psa_outvec structures. |
| 134 | * \param[in] out_len Number of output \ref psa_outvec structures. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 135 | * |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 136 | * \retval >=0 RoT Service-specific status value. |
| 137 | * \retval <0 RoT Service-specific error code. |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 138 | * \retval PSA_ERROR_PROGRAMMER_ERROR The connection has been terminated by the |
| 139 | * RoT Service. The call is a PROGRAMMER ERROR if |
| 140 | * one or more of the following are true: |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 141 | * \arg An invalid handle was passed. |
| 142 | * \arg The connection is already handling a request. |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 143 | * \arg type < 0. |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 144 | * \arg An invalid memory reference was provided. |
| 145 | * \arg in_len + out_len > PSA_MAX_IOVEC. |
| 146 | * \arg The message is unrecognized by the RoT |
| 147 | * Service or incorrectly formatted. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 148 | */ |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 149 | psa_status_t psa_call(psa_handle_t handle, int32_t type, |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 150 | const psa_invec *in_vec, |
| 151 | size_t in_len, |
| 152 | psa_outvec *out_vec, |
| 153 | size_t out_len); |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 154 | |
| 155 | /** |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 156 | * \brief Close a connection to an RoT Service. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 157 | * |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 158 | * \param[in] handle A handle to an established connection, or the |
| 159 | * null handle. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 160 | * |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 161 | * \retval void Success. |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 162 | * \retval "PROGRAMMER ERROR" The call is a PROGRAMMER ERROR if one or more |
| 163 | * of the following are true: |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 164 | * \arg An invalid handle was provided that is not |
| 165 | * the null handle. |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 166 | * \arg The connection is currently handling a |
| 167 | * request. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 168 | */ |
| 169 | void psa_close(psa_handle_t handle); |
| 170 | |
| 171 | #ifdef __cplusplus |
| 172 | } |
| 173 | #endif |
| 174 | |
| 175 | #endif /* __PSA_CLIENT_H__ */ |