Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 1 | /* |
Jamie Fox | b93da8b | 2018-12-13 18:27:30 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2019, Arm Limited. All rights reserved. |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef __TFM_SST_DEFS_H__ |
| 9 | #define __TFM_SST_DEFS_H__ |
| 10 | |
Jamie Fox | b93da8b | 2018-12-13 18:27:30 +0000 | [diff] [blame] | 11 | #include <limits.h> |
| 12 | #include "psa_protected_storage.h" |
| 13 | #include "tfm_api.h" |
| 14 | |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 15 | #ifdef __cplusplus |
| 16 | extern "C" { |
| 17 | #endif |
| 18 | |
Jamie Fox | b93da8b | 2018-12-13 18:27:30 +0000 | [diff] [blame] | 19 | /* The return value is shared with the TF-M partition status value. |
| 20 | * The SST return codes shouldn't overlap with predefined TF-M status values. |
| 21 | */ |
| 22 | #define TFM_SST_ERR_OFFSET (TFM_PARTITION_SPECIFIC_ERROR_MIN) |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 23 | |
Jamie Fox | b93da8b | 2018-12-13 18:27:30 +0000 | [diff] [blame] | 24 | /** |
| 25 | * \enum tfm_sst_err_t |
Marc Moreno Berengue | 10d0d36 | 2018-06-18 14:15:56 +0100 | [diff] [blame] | 26 | * |
Jamie Fox | b93da8b | 2018-12-13 18:27:30 +0000 | [diff] [blame] | 27 | * \brief TF-M Secure Storage service error types |
Marc Moreno Berengue | 10d0d36 | 2018-06-18 14:15:56 +0100 | [diff] [blame] | 28 | * |
| 29 | */ |
Jamie Fox | b93da8b | 2018-12-13 18:27:30 +0000 | [diff] [blame] | 30 | enum tfm_sst_err_t { |
| 31 | TFM_SST_ERR_SUCCESS = 0, |
| 32 | TFM_SST_ERR_WRITE_ONCE = TFM_SST_ERR_OFFSET, |
| 33 | TFM_SST_ERR_FLAGS_NOT_SUPPORTED, |
| 34 | TFM_SST_ERR_INSUFFICIENT_SPACE, |
| 35 | TFM_SST_ERR_STORAGE_FAILURE, |
| 36 | TFM_SST_ERR_UID_NOT_FOUND, |
| 37 | TFM_SST_ERR_INCORRECT_SIZE, |
| 38 | TFM_SST_ERR_OFFSET_INVALID, |
| 39 | TFM_SST_ERR_INVALID_ARGUMENT, |
| 40 | TFM_SST_ERR_DATA_CORRUPT, |
| 41 | TFM_SST_ERR_AUTH_FAILED, |
| 42 | TFM_SST_ERR_OPERATION_FAILED, |
| 43 | TFM_SST_ERR_NOT_SUPPORTED, |
| 44 | /* Add an invalid return code which forces the size of the type as well */ |
| 45 | TFM_SST_ERR_INVALID = INT_MAX |
Marc Moreno Berengue | 10d0d36 | 2018-06-18 14:15:56 +0100 | [diff] [blame] | 46 | }; |
| 47 | |
Jamie Fox | b93da8b | 2018-12-13 18:27:30 +0000 | [diff] [blame] | 48 | /** |
| 49 | * \brief A macro to translate TF-M API return values including the offset |
| 50 | * needed by TF-M, to the corresponding PSA value. |
Marc Moreno Berengue | 675b6e9 | 2018-06-14 17:31:01 +0100 | [diff] [blame] | 51 | */ |
Jamie Fox | b93da8b | 2018-12-13 18:27:30 +0000 | [diff] [blame] | 52 | #define TFM_SST_PSA_RETURN(err) ( \ |
| 53 | (err) == TFM_SST_ERR_SUCCESS ? err : \ |
| 54 | (err) >= TFM_SST_ERR_WRITE_ONCE ? ((err) - (TFM_SST_ERR_WRITE_ONCE - 1)) : \ |
| 55 | TFM_SST_ERR_INVALID \ |
| 56 | ) |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 57 | |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 58 | #ifdef __cplusplus |
| 59 | } |
| 60 | #endif |
| 61 | |
| 62 | #endif /* __TFM_SST_DEFS_H__ */ |