blob: a008c7384965253fb52852f60f237c8e9af1c4d8 [file] [log] [blame]
Ashutosh Singhf4d88672017-11-29 13:35:43 +00001/*
Jamie Foxb93da8b2018-12-13 18:27:30 +00002 * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
Ashutosh Singhf4d88672017-11-29 13:35:43 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef __TFM_SST_DEFS_H__
9#define __TFM_SST_DEFS_H__
10
Jamie Foxb93da8b2018-12-13 18:27:30 +000011#include <limits.h>
12#include "psa_protected_storage.h"
13#include "tfm_api.h"
14
Ashutosh Singhf4d88672017-11-29 13:35:43 +000015#ifdef __cplusplus
16extern "C" {
17#endif
18
Jamie Foxb93da8b2018-12-13 18:27:30 +000019/* 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 Singhf4d88672017-11-29 13:35:43 +000023
Jamie Foxb93da8b2018-12-13 18:27:30 +000024/**
25 * \enum tfm_sst_err_t
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +010026 *
Jamie Foxb93da8b2018-12-13 18:27:30 +000027 * \brief TF-M Secure Storage service error types
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +010028 *
29 */
Jamie Foxb93da8b2018-12-13 18:27:30 +000030enum 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 Berengue10d0d362018-06-18 14:15:56 +010046};
47
Jamie Foxb93da8b2018-12-13 18:27:30 +000048/**
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 Berengue675b6e92018-06-14 17:31:01 +010051 */
Jamie Foxb93da8b2018-12-13 18:27:30 +000052#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 Singhf4d88672017-11-29 13:35:43 +000057
Ashutosh Singhf4d88672017-11-29 13:35:43 +000058#ifdef __cplusplus
59}
60#endif
61
62#endif /* __TFM_SST_DEFS_H__ */