Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 1 | From 791a1302d7b779f3aeee7d6f7c9fac00b4244c1b Mon Sep 17 00:00:00 2001 |
| 2 | From: Vishnu Banavath <vishnu.banavath@arm.com> |
| 3 | Date: Fri, 3 Dec 2021 19:05:18 +0000 |
| 4 | Subject: [PATCH] add psa client definitions for ff-m |
| 5 | |
| 6 | Add PSA client definitions in common include to add future |
| 7 | ff-m support. |
| 8 | |
| 9 | Signed-off-by: Rui Miguel Silva <rui.silva@arm.com> |
| 10 | Signed-off-by: Vishnu Banavath <vishnu.banavath@arm.com> |
| 11 | |
| 12 | Upstream-Status: Pending [Not submitted to upstream yet] |
| 13 | Signed-off-by: Vishnu Banavath <vishnu.banavath@arm.com> |
| 14 | |
| 15 | |
| 16 | --- |
| 17 | .../service/common/include/psa/client.h | 194 ++++++++++++++++++ |
| 18 | components/service/common/include/psa/sid.h | 71 +++++++ |
| 19 | 2 files changed, 265 insertions(+) |
| 20 | create mode 100644 components/service/common/include/psa/client.h |
| 21 | create mode 100644 components/service/common/include/psa/sid.h |
| 22 | |
| 23 | diff --git a/components/service/common/include/psa/client.h b/components/service/common/include/psa/client.h |
| 24 | new file mode 100644 |
| 25 | index 00000000..69ccf14f |
| 26 | --- /dev/null |
| 27 | +++ b/components/service/common/include/psa/client.h |
| 28 | @@ -0,0 +1,194 @@ |
| 29 | +/* |
| 30 | + * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved. |
| 31 | + * |
| 32 | + * SPDX-License-Identifier: BSD-3-Clause |
| 33 | + */ |
| 34 | + |
| 35 | +#ifndef SERVICE_PSA_IPC_H |
| 36 | +#define SERVICE_PSA_IPC_H |
| 37 | + |
| 38 | +#include <stddef.h> |
| 39 | +#include <stdint.h> |
| 40 | + |
| 41 | +#include <rpc_caller.h> |
| 42 | +#include <psa/error.h> |
| 43 | + |
| 44 | +#ifdef __cplusplus |
| 45 | +extern "C" { |
| 46 | +#endif |
| 47 | + |
| 48 | +#ifndef IOVEC_LEN |
| 49 | +#define IOVEC_LEN(arr) ((uint32_t)(sizeof(arr)/sizeof(arr[0]))) |
| 50 | +#endif |
| 51 | + |
| 52 | +/*********************** PSA Client Macros and Types *************************/ |
| 53 | + |
| 54 | +typedef int32_t psa_handle_t; |
| 55 | + |
| 56 | +/** |
| 57 | + * The version of the PSA Framework API that is being used to build the calling |
| 58 | + * firmware. Only part of features of FF-M v1.1 have been implemented. FF-M v1.1 |
| 59 | + * is compatible with v1.0. |
| 60 | + */ |
| 61 | +#define PSA_FRAMEWORK_VERSION (0x0101u) |
| 62 | + |
| 63 | +/** |
| 64 | + * Return value from psa_version() if the requested RoT Service is not present |
| 65 | + * in the system. |
| 66 | + */ |
| 67 | +#define PSA_VERSION_NONE (0u) |
| 68 | + |
| 69 | +/** |
| 70 | + * The zero-value null handle can be assigned to variables used in clients and |
| 71 | + * RoT Services, indicating that there is no current connection or message. |
| 72 | + */ |
| 73 | +#define PSA_NULL_HANDLE ((psa_handle_t)0) |
| 74 | + |
| 75 | +/** |
| 76 | + * Tests whether a handle value returned by psa_connect() is valid. |
| 77 | + */ |
| 78 | +#define PSA_HANDLE_IS_VALID(handle) ((psa_handle_t)(handle) > 0) |
| 79 | + |
| 80 | +/** |
| 81 | + * Converts the handle value returned from a failed call psa_connect() into |
| 82 | + * an error code. |
| 83 | + */ |
| 84 | +#define PSA_HANDLE_TO_ERROR(handle) ((psa_status_t)(handle)) |
| 85 | + |
| 86 | +/** |
| 87 | + * Maximum number of input and output vectors for a request to psa_call(). |
| 88 | + */ |
| 89 | +#define PSA_MAX_IOVEC (4u) |
| 90 | + |
| 91 | +/** |
| 92 | + * An IPC message type that indicates a generic client request. |
| 93 | + */ |
| 94 | +#define PSA_IPC_CALL (0) |
| 95 | + |
| 96 | +/** |
| 97 | + * A read-only input memory region provided to an RoT Service. |
| 98 | + */ |
| 99 | +struct __attribute__ ((__packed__)) psa_invec { |
| 100 | + uint32_t base; /*!< the start address of the memory buffer */ |
| 101 | + uint32_t len; /*!< the size in bytes */ |
| 102 | +}; |
| 103 | + |
| 104 | +/** |
| 105 | + * A writable output memory region provided to an RoT Service. |
| 106 | + */ |
| 107 | +struct __attribute__ ((__packed__)) psa_outvec { |
| 108 | + uint32_t base; /*!< the start address of the memory buffer */ |
| 109 | + uint32_t len; /*!< the size in bytes */ |
| 110 | +}; |
| 111 | + |
| 112 | +/*************************** PSA Client API **********************************/ |
| 113 | + |
| 114 | +/** |
| 115 | + * \brief Retrieve the version of the PSA Framework API that is implemented. |
| 116 | + * |
| 117 | + * \param[in] rpc_caller RPC caller to use |
| 118 | + * \return version The version of the PSA Framework implementation |
| 119 | + * that is providing the runtime services to the |
| 120 | + * caller. The major and minor version are encoded |
| 121 | + * as follows: |
| 122 | + * \arg version[15:8] -- major version number. |
| 123 | + * \arg version[7:0] -- minor version number. |
| 124 | + */ |
| 125 | +uint32_t psa_framework_version(struct rpc_caller *caller); |
| 126 | + |
| 127 | +/** |
| 128 | + * \brief Retrieve the version of an RoT Service or indicate that it is not |
| 129 | + * present on this system. |
| 130 | + * |
| 131 | + * \param[in] rpc_caller RPC caller to use |
| 132 | + * \param[in] sid ID of the RoT Service to query. |
| 133 | + * |
| 134 | + * \retval PSA_VERSION_NONE The RoT Service is not implemented, or the |
| 135 | + * caller is not permitted to access the service. |
| 136 | + * \retval > 0 The version of the implemented RoT Service. |
| 137 | + */ |
| 138 | +uint32_t psa_version(struct rpc_caller *caller, uint32_t sid); |
| 139 | + |
| 140 | +/** |
| 141 | + * \brief Connect to an RoT Service by its SID. |
| 142 | + * |
| 143 | + * \param[in] rpc_caller RPC caller to use |
| 144 | + * \param[in] sid ID of the RoT Service to connect to. |
| 145 | + * \param[in] version Requested version of the RoT Service. |
| 146 | + * |
| 147 | + * \retval > 0 A handle for the connection. |
| 148 | + * \retval PSA_ERROR_CONNECTION_REFUSED The SPM or RoT Service has refused the |
| 149 | + * connection. |
| 150 | + * \retval PSA_ERROR_CONNECTION_BUSY The SPM or RoT Service cannot make the |
| 151 | + * connection at the moment. |
| 152 | + * \retval "PROGRAMMER ERROR" The call is a PROGRAMMER ERROR if one or more |
| 153 | + * of the following are true: |
| 154 | + * \arg The RoT Service ID is not present. |
| 155 | + * \arg The RoT Service version is not supported. |
| 156 | + * \arg The caller is not allowed to access the RoT |
| 157 | + * service. |
| 158 | + */ |
| 159 | +psa_handle_t psa_connect(struct rpc_caller *caller, uint32_t sid, |
| 160 | + uint32_t version); |
| 161 | + |
| 162 | +/** |
| 163 | + * \brief Call an RoT Service on an established connection. |
| 164 | + * |
| 165 | + * \note FF-M 1.0 proposes 6 parameters for psa_call but the secure gateway ABI |
| 166 | + * support at most 4 parameters. TF-M chooses to encode 'in_len', |
| 167 | + * 'out_len', and 'type' into a 32-bit integer to improve efficiency. |
| 168 | + * Compared with struct-based encoding, this method saves extra memory |
| 169 | + * check and memory copy operation. The disadvantage is that the 'type' |
| 170 | + * range has to be reduced into a 16-bit integer. So with this encoding, |
| 171 | + * the valid range for 'type' is 0-32767. |
| 172 | + * |
| 173 | + * \param[in] rpc_caller RPC caller to use |
| 174 | + * \param[in] handle A handle to an established connection. |
| 175 | + * \param[in] type The request type. |
| 176 | + * Must be zero( \ref PSA_IPC_CALL) or positive. |
| 177 | + * \param[in] in_vec Array of input \ref psa_invec structures. |
| 178 | + * \param[in] in_len Number of input \ref psa_invec structures. |
| 179 | + * \param[in,out] out_vec Array of output \ref psa_outvec structures. |
| 180 | + * \param[in] out_len Number of output \ref psa_outvec structures. |
| 181 | + * |
| 182 | + * \retval >=0 RoT Service-specific status value. |
| 183 | + * \retval <0 RoT Service-specific error code. |
| 184 | + * \retval PSA_ERROR_PROGRAMMER_ERROR The connection has been terminated by the |
| 185 | + * RoT Service. The call is a PROGRAMMER ERROR if |
| 186 | + * one or more of the following are true: |
| 187 | + * \arg An invalid handle was passed. |
| 188 | + * \arg The connection is already handling a request. |
| 189 | + * \arg type < 0. |
| 190 | + * \arg An invalid memory reference was provided. |
| 191 | + * \arg in_len + out_len > PSA_MAX_IOVEC. |
| 192 | + * \arg The message is unrecognized by the RoT |
| 193 | + * Service or incorrectly formatted. |
| 194 | + */ |
| 195 | +psa_status_t psa_call(struct rpc_caller *caller, psa_handle_t handle, |
| 196 | + int32_t type, const struct psa_invec *in_vec, |
| 197 | + size_t in_len, struct psa_outvec *out_vec, size_t out_len); |
| 198 | + |
| 199 | +/** |
| 200 | + * \brief Close a connection to an RoT Service. |
| 201 | + * |
| 202 | + * \param[in] rpc_caller RPC caller to use |
| 203 | + * \param[in] handle A handle to an established connection, or the |
| 204 | + * null handle. |
| 205 | + * |
| 206 | + * \retval void Success. |
| 207 | + * \retval "PROGRAMMER ERROR" The call is a PROGRAMMER ERROR if one or more |
| 208 | + * of the following are true: |
| 209 | + * \arg An invalid handle was provided that is not |
| 210 | + * the null handle. |
| 211 | + * \arg The connection is currently handling a |
| 212 | + * request. |
| 213 | + */ |
| 214 | +void psa_close(struct rpc_caller *caller, psa_handle_t handle); |
| 215 | + |
| 216 | +#ifdef __cplusplus |
| 217 | +} |
| 218 | +#endif |
| 219 | + |
| 220 | +#endif /* SERVICE_PSA_IPC_H */ |
| 221 | + |
| 222 | + |
| 223 | diff --git a/components/service/common/include/psa/sid.h b/components/service/common/include/psa/sid.h |
| 224 | new file mode 100644 |
| 225 | index 00000000..aaa973c6 |
| 226 | --- /dev/null |
| 227 | +++ b/components/service/common/include/psa/sid.h |
| 228 | @@ -0,0 +1,71 @@ |
| 229 | +/* |
| 230 | + * Copyright (c) 2019-2021, Arm Limited. All rights reserved. |
| 231 | + * |
| 232 | + * SPDX-License-Identifier: BSD-3-Clause |
| 233 | + * |
| 234 | + */ |
| 235 | + |
| 236 | +#ifndef __PSA_MANIFEST_SID_H__ |
| 237 | +#define __PSA_MANIFEST_SID_H__ |
| 238 | + |
| 239 | +#ifdef __cplusplus |
| 240 | +extern "C" { |
| 241 | +#endif |
| 242 | + |
| 243 | +/******** TFM_SP_PS ********/ |
| 244 | +#define TFM_PROTECTED_STORAGE_SERVICE_SID (0x00000060U) |
| 245 | +#define TFM_PROTECTED_STORAGE_SERVICE_VERSION (1U) |
| 246 | +#define TFM_PROTECTED_STORAGE_SERVICE_HANDLE (0x40000101U) |
| 247 | + |
| 248 | +/* Invalid UID */ |
| 249 | +#define TFM_PS_INVALID_UID 0 |
| 250 | + |
| 251 | +/* PS message types that distinguish PS services. */ |
| 252 | +#define TFM_PS_SET 1001 |
| 253 | +#define TFM_PS_GET 1002 |
| 254 | +#define TFM_PS_GET_INFO 1003 |
| 255 | +#define TFM_PS_REMOVE 1004 |
| 256 | +#define TFM_PS_GET_SUPPORT 1005 |
| 257 | + |
| 258 | +/******** TFM_SP_ITS ********/ |
| 259 | +#define TFM_INTERNAL_TRUSTED_STORAGE_SERVICE_SID (0x00000070U) |
| 260 | +#define TFM_INTERNAL_TRUSTED_STORAGE_SERVICE_VERSION (1U) |
| 261 | +#define TFM_INTERNAL_TRUSTED_STORAGE_SERVICE_HANDLE (0x40000102U) |
| 262 | + |
| 263 | +/******** TFM_SP_CRYPTO ********/ |
| 264 | +#define TFM_CRYPTO_SID (0x00000080U) |
| 265 | +#define TFM_CRYPTO_VERSION (1U) |
| 266 | +#define TFM_CRYPTO_HANDLE (0x40000100U) |
| 267 | + |
| 268 | +/******** TFM_SP_PLATFORM ********/ |
| 269 | +#define TFM_SP_PLATFORM_SYSTEM_RESET_SID (0x00000040U) |
| 270 | +#define TFM_SP_PLATFORM_SYSTEM_RESET_VERSION (1U) |
| 271 | +#define TFM_SP_PLATFORM_IOCTL_SID (0x00000041U) |
| 272 | +#define TFM_SP_PLATFORM_IOCTL_VERSION (1U) |
| 273 | +#define TFM_SP_PLATFORM_NV_COUNTER_SID (0x00000042U) |
| 274 | +#define TFM_SP_PLATFORM_NV_COUNTER_VERSION (1U) |
| 275 | + |
| 276 | +/******** TFM_SP_INITIAL_ATTESTATION ********/ |
| 277 | +#define TFM_ATTESTATION_SERVICE_SID (0x00000020U) |
| 278 | +#define TFM_ATTESTATION_SERVICE_VERSION (1U) |
| 279 | +#define TFM_ATTESTATION_SERVICE_HANDLE (0x40000103U) |
| 280 | + |
| 281 | +/******** TFM_SP_FWU ********/ |
| 282 | +#define TFM_FWU_WRITE_SID (0x000000A0U) |
| 283 | +#define TFM_FWU_WRITE_VERSION (1U) |
| 284 | +#define TFM_FWU_INSTALL_SID (0x000000A1U) |
| 285 | +#define TFM_FWU_INSTALL_VERSION (1U) |
| 286 | +#define TFM_FWU_ABORT_SID (0x000000A2U) |
| 287 | +#define TFM_FWU_ABORT_VERSION (1U) |
| 288 | +#define TFM_FWU_QUERY_SID (0x000000A3U) |
| 289 | +#define TFM_FWU_QUERY_VERSION (1U) |
| 290 | +#define TFM_FWU_REQUEST_REBOOT_SID (0x000000A4U) |
| 291 | +#define TFM_FWU_REQUEST_REBOOT_VERSION (1U) |
| 292 | +#define TFM_FWU_ACCEPT_SID (0x000000A5U) |
| 293 | +#define TFM_FWU_ACCEPT_VERSION (1U) |
| 294 | + |
| 295 | +#ifdef __cplusplus |
| 296 | +} |
| 297 | +#endif |
| 298 | + |
| 299 | +#endif /* __PSA_MANIFEST_SID_H__ */ |