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 | |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 22 | #define PSA_FRAMEWORK_VERSION (0x0100) |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 23 | |
| 24 | #define PSA_VERSION_NONE (0) |
| 25 | |
| 26 | /* PSA response types */ |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 27 | #define PSA_CONNECTION_REFUSED (INT32_MIN + 1) |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 28 | #define PSA_CONNECTION_BUSY (INT32_MIN + 2) |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 29 | #define PSA_DROP_CONNECTION (INT32_MIN) |
| 30 | |
| 31 | /* PSA message handles */ |
| 32 | #define PSA_NULL_HANDLE ((psa_handle_t)0) |
| 33 | |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 34 | typedef int32_t psa_handle_t; |
| 35 | |
| 36 | /** |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 37 | * A read-only input memory region provided to an RoT Service. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 38 | */ |
| 39 | typedef struct psa_invec { |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 40 | const void *base; /*!< the start address of the memory buffer */ |
| 41 | size_t len; /*!< the size in bytes */ |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 42 | } psa_invec; |
| 43 | |
| 44 | /** |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 45 | * A writable output memory region provided to an RoT Service. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 46 | */ |
| 47 | typedef struct psa_outvec { |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 48 | void *base; /*!< the start address of the memory buffer */ |
| 49 | size_t len; /*!< the size in bytes */ |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 50 | } psa_outvec; |
| 51 | |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 52 | /*************************** PSA Client API **********************************/ |
| 53 | |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 54 | /** |
| 55 | * \brief Retrieve the version of the PSA Framework API that is implemented. |
| 56 | * |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 57 | * \return version The version of the PSA Framework implementation |
| 58 | * that is providing the runtime services to the |
| 59 | * caller. The major and minor version are encoded |
| 60 | * as follows: |
| 61 | * \arg version[15:8] -- major version number. |
| 62 | * \arg version[7:0] -- minor version number. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 63 | */ |
| 64 | uint32_t psa_framework_version(void); |
| 65 | |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 66 | /** |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 67 | * \brief Retrieve the minor version of an RoT Service or indicate that it is |
| 68 | * not present on this system. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 69 | * |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 70 | * \param[in] sid ID of the RoT Service to query. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 71 | * |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 72 | * \retval PSA_VERSION_NONE The RoT Service is not implemented, or the |
| 73 | * caller is not permitted to access the service. |
| 74 | * \retval > 0 The minor version of the implemented RoT |
| 75 | * Service. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 76 | */ |
| 77 | uint32_t psa_version(uint32_t sid); |
| 78 | |
| 79 | /** |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 80 | * \brief Connect to an RoT Service by its SID. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 81 | * |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 82 | * \param[in] sid ID of the RoT Service to connect to. |
| 83 | * \param[in] minor_version Requested version of the RoT Service. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 84 | * |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 85 | * \retval > 0 A handle for the connection. |
| 86 | * \retval PSA_CONNECTION_REFUSED The SPM or RoT Service has refused the |
| 87 | * connection. |
| 88 | * \retval PSA_CONNECTION_BUSY The SPM or RoT Service cannot make the |
| 89 | * connection at the moment. |
| 90 | * \retval "Does not return" The RoT Service ID and version are not |
| 91 | * supported, or the caller is not permitted to |
| 92 | * access the service. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 93 | */ |
| 94 | psa_handle_t psa_connect(uint32_t sid, uint32_t minor_version); |
| 95 | |
| 96 | /** |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 97 | * \brief Call an RoT Service on an established connection. |
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 | * \param[in] handle A handle to an established connection. |
| 100 | * \param[in] in_vec Array of input \ref psa_invec structures. |
| 101 | * \param[in] in_len Number of input \ref psa_invec structures. |
| 102 | * \param[in/out] out_vec Array of output \ref psa_outvec structures. |
| 103 | * \param[in] out_len Number of output \ref psa_outvec structures. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 104 | * |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 105 | * \retval >=0 RoT Service-specific status value. |
| 106 | * \retval <0 RoT Service-specific error code. |
| 107 | * \retval PSA_DROP_CONNECTION The connection has been dropped by the RoT |
| 108 | * Service. This indicates that either this or |
| 109 | * a previous message was invalid. |
| 110 | * \retval "Does not return" The call is invalid, one or more of the |
| 111 | * following are true: |
| 112 | * \arg An invalid handle was passed. |
| 113 | * \arg The connection is already handling a request. |
| 114 | * \arg An invalid memory reference was provided. |
| 115 | * \arg in_len + out_len > PSA_MAX_IOVEC. |
| 116 | * \arg The message is unrecognized by the RoT |
| 117 | * Service or incorrectly formatted. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 118 | */ |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 119 | psa_status_t psa_call(psa_handle_t handle, |
| 120 | const psa_invec *in_vec, |
| 121 | size_t in_len, |
| 122 | psa_outvec *out_vec, |
| 123 | size_t out_len); |
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 Close a connection to an RoT Service. |
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, or the |
| 129 | * null handle. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 130 | * |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 131 | * \retval void Success. |
| 132 | * \retval "Does not return" The call is invalid, one or more of the |
| 133 | * following are true: |
| 134 | * \arg An invalid handle was provided that is not |
| 135 | * the null handle. |
| 136 | * \arg The connection is handling a request. |
Miklos Balint | 9ecb24c | 2018-03-29 15:30:28 +0200 | [diff] [blame] | 137 | */ |
| 138 | void psa_close(psa_handle_t handle); |
| 139 | |
| 140 | #ifdef __cplusplus |
| 141 | } |
| 142 | #endif |
| 143 | |
| 144 | #endif /* __PSA_CLIENT_H__ */ |