blob: 835155ac072856f5db33a1ae1941d4b4ae742245 [file] [log] [blame]
Kevin Peng93fb9f52020-09-17 11:45:54 +08001/*
Ken Liu967ffa92022-05-25 15:13:34 +08002 * Copyright (c) 2020-2022, Arm Limited. All rights reserved.
Kevin Peng93fb9f52020-09-17 11:45:54 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef __TFM_HAL_ISOLATION_H__
9#define __TFM_HAL_ISOLATION_H__
10
11#include <stddef.h>
12#include <stdint.h>
13#include "tfm_hal_defs.h"
Ken Liuce58bfc2021-05-12 17:54:48 +080014#include "load/partition_defs.h"
15#include "load/asset_defs.h"
Kevin Peng93fb9f52020-09-17 11:45:54 +080016
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21/* Memory access attributes */
22#define TFM_HAL_ACCESS_EXECUTABLE (1UL << 0)
23#define TFM_HAL_ACCESS_READABLE (1UL << 1)
24#define TFM_HAL_ACCESS_WRITABLE (1UL << 2)
25#define TFM_HAL_ACCESS_UNPRIVILEGED (1UL << 3)
26#define TFM_HAL_ACCESS_DEVICE (1UL << 4)
27#define TFM_HAL_ACCESS_NS (1UL << 5)
28
Summer Qin56725eb2022-05-06 15:23:40 +080029#define TFM_HAL_ACCESS_READWRITE \
30 (TFM_HAL_ACCESS_READABLE | TFM_HAL_ACCESS_WRITABLE)
31
Tamas Band28286e2020-11-27 12:58:39 +000032#ifdef TFM_FIH_PROFILE_ON
Ken Liuce58bfc2021-05-12 17:54:48 +080033#include "fih.h"
Kevin Peng93fb9f52020-09-17 11:45:54 +080034/**
35 * \brief Sets up the static isolation boundaries which are constant throughout
36 * the runtime of the system, including the SPE/NSPE and partition
37 * boundaries.
38 *
39 * \return TFM_HAL_SUCCESS - the isolation boundaries have been set up.
40 * TFM_HAL_ERROR_GENERIC - failed to set up the isolation boundaries.
41 */
Tamas Band28286e2020-11-27 12:58:39 +000042fih_int tfm_hal_set_up_static_boundaries(void);
43
Tamas Band28286e2020-11-27 12:58:39 +000044/**
Kevin Peng38788a12021-09-08 16:23:50 +080045 * \brief This function is responsible for checking all critical isolation
46 configurations.
47 *
48 * \return TFM_HAL_SUCCESS - the verification passed.
49 * TFM_HAL_ERROR_GENERIC - the verification failed.
50 */
51fih_int tfm_hal_verify_static_boundaries(void);
52
53/**
Ken Liu967ffa92022-05-25 15:13:34 +080054 * \brief Activate one Secure Partition boundary.
Tamas Band28286e2020-11-27 12:58:39 +000055 *
Ken Liuce58bfc2021-05-12 17:54:48 +080056 * \param[in] p_ldinf Partition load information.
Ken Liu967ffa92022-05-25 15:13:34 +080057 * \param[in] boundary Platform boundary value for partition.
Tamas Band28286e2020-11-27 12:58:39 +000058 *
Ken Liuce58bfc2021-05-12 17:54:48 +080059 * \return TFM_HAL_SUCCESS The isolation boundaries update succeeded.
60 * TFM_HAL_ERROR_GENERIC Failed to update the isolation boundaries.
Tamas Band28286e2020-11-27 12:58:39 +000061 *
62 * \note When FIH_ENABLE_DOUBLE_VARS is enabled, the return code will be
63 * wrapped and protected in \ref fih_int structure.
64 */
Ken Liu967ffa92022-05-25 15:13:34 +080065fih_int tfm_hal_activate_boundary(const struct partition_load_info_t *p_ldinf,
66 uintptr_t boundary);
Tamas Band28286e2020-11-27 12:58:39 +000067#else /* TFM_FIH_PROFILE_ON */
68/**
69 * \brief Sets up the static isolation boundaries which are constant throughout
70 * the runtime of the system, including the SPE/NSPE and partition
71 * boundaries.
72 *
73 * \return TFM_HAL_SUCCESS - the isolation boundaries have been set up.
74 * TFM_HAL_ERROR_GENERIC - failed to set up the isolation boundaries.
Tamas Band28286e2020-11-27 12:58:39 +000075 */
Kevin Peng93fb9f52020-09-17 11:45:54 +080076enum tfm_hal_status_t tfm_hal_set_up_static_boundaries(void);
77
Tamas Band28286e2020-11-27 12:58:39 +000078/**
Ken Liu967ffa92022-05-25 15:13:34 +080079 * \brief Activate one Secure Partition boundary.
Tamas Band28286e2020-11-27 12:58:39 +000080 *
Ken Liuce58bfc2021-05-12 17:54:48 +080081 * \param[in] p_ldinf Partition load information.
Ken Liu967ffa92022-05-25 15:13:34 +080082 * \param[in] boundary Platform boundary value for partition.
Tamas Band28286e2020-11-27 12:58:39 +000083 *
Ken Liuce58bfc2021-05-12 17:54:48 +080084 * \return TFM_HAL_SUCCESS The isolation boundaries update succeeded.
85 * TFM_HAL_ERROR_GENERIC Failed to update the isolation boundaries.
Tamas Band28286e2020-11-27 12:58:39 +000086 */
Ken Liu967ffa92022-05-25 15:13:34 +080087enum tfm_hal_status_t tfm_hal_activate_boundary(
Ken Liuce58bfc2021-05-12 17:54:48 +080088 const struct partition_load_info_t *p_ldinf,
Ken Liu967ffa92022-05-25 15:13:34 +080089 uintptr_t boundary);
Tamas Band28286e2020-11-27 12:58:39 +000090#endif /* TFM_FIH_PROFILE_ON */
91
Kevin Peng93fb9f52020-09-17 11:45:54 +080092/**
Summer Qin56725eb2022-05-06 15:23:40 +080093 * \brief This API checks if a given range of memory can be accessed with
94 * specified access types in boundary. The boundary belongs to
95 * a partition which contains all asset info.
Kevin Peng93fb9f52020-09-17 11:45:54 +080096 *
Summer Qin56725eb2022-05-06 15:23:40 +080097 * \param[in] boundary The boundary that the given memory is to be
98 * checked with.
99 * \param[in] base The base address of the region.
100 * \param[in] size The size of the region.
101 * \param[in] access_type The memory access types to be checked between
102 * given memory and boundaries.
Kevin Peng93fb9f52020-09-17 11:45:54 +0800103 *
104 * \return TFM_HAL_SUCCESS - The memory region has the access permissions.
105 * TFM_HAL_ERROR_MEM_FAULT - The memory region has not the access
106 * permissions.
107 * TFM_HAL_ERROR_INVALID_INPUT - Invalid inputs.
108 * TFM_HAL_ERROR_GENERIC - An error occurred.
109 */
Summer Qin56725eb2022-05-06 15:23:40 +0800110enum tfm_hal_status_t tfm_hal_memory_check(uintptr_t boundary, uintptr_t base,
111 size_t size, uint32_t access_type);
Kevin Peng93fb9f52020-09-17 11:45:54 +0800112
Ken Liuce58bfc2021-05-12 17:54:48 +0800113/**
114 * \brief This API binds partition boundaries with the platform. The platform
115 * maintains the platform-specific settings for SPM further
Ken Liu967ffa92022-05-25 15:13:34 +0800116 * usage, such as update partition boundaries or
Ken Liuce58bfc2021-05-12 17:54:48 +0800117 * check resource accessibility. The platform needs to manage
Ken Liu967ffa92022-05-25 15:13:34 +0800118 * the settings with internal mechanism, and return a value
119 * to SPM. SPM delivers this value back to platform when
120 * necessary. And SPM checks this value to decide if the
Ken Liuce58bfc2021-05-12 17:54:48 +0800121 * platform-specific settings need to be updated. Hence
Ken Liu967ffa92022-05-25 15:13:34 +0800122 * multiple partitions can have the same value if they have
Ken Liuce58bfc2021-05-12 17:54:48 +0800123 * the same platform-specific settings, depending on isolation level.
124 *
125 * \param[in] p_ldinf Partition load information.
Ken Liu967ffa92022-05-25 15:13:34 +0800126 * \param[in] p_boundary Pointer of the boundary value
Ken Liuce58bfc2021-05-12 17:54:48 +0800127 *
Ken Liu967ffa92022-05-25 15:13:34 +0800128 * \return TFM_HAL_SUCCESS - A platform value bound successfully.
129 * TFM_HAL_ERROR_GENERIC - Error occurred while binding.
Ken Liuce58bfc2021-05-12 17:54:48 +0800130 */
Ken Liu967ffa92022-05-25 15:13:34 +0800131enum tfm_hal_status_t tfm_hal_bind_boundary(
Ken Liuce58bfc2021-05-12 17:54:48 +0800132 const struct partition_load_info_t *p_ldinf,
Ken Liu967ffa92022-05-25 15:13:34 +0800133 uintptr_t *p_boundary);
Ken Liuce58bfc2021-05-12 17:54:48 +0800134
Kevin Peng93fb9f52020-09-17 11:45:54 +0800135#ifdef __cplusplus
136}
137#endif
138
139#endif /* __TFM_HAL_ISOLATION_H__ */