blob: 2228b251896f777eb9b2af88174cf23c2fba7d41 [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>
Chendi Sun0f7d2822022-10-28 12:24:12 +080013#include <stdbool.h>
Xinyu Zhang6ad07032022-08-10 14:45:56 +080014#include "fih.h"
Kevin Peng93fb9f52020-09-17 11:45:54 +080015#include "tfm_hal_defs.h"
Ken Liuce58bfc2021-05-12 17:54:48 +080016#include "load/partition_defs.h"
17#include "load/asset_defs.h"
Kevin Peng93fb9f52020-09-17 11:45:54 +080018
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23/* Memory access attributes */
24#define TFM_HAL_ACCESS_EXECUTABLE (1UL << 0)
25#define TFM_HAL_ACCESS_READABLE (1UL << 1)
26#define TFM_HAL_ACCESS_WRITABLE (1UL << 2)
27#define TFM_HAL_ACCESS_UNPRIVILEGED (1UL << 3)
28#define TFM_HAL_ACCESS_DEVICE (1UL << 4)
29#define TFM_HAL_ACCESS_NS (1UL << 5)
30
Summer Qin56725eb2022-05-06 15:23:40 +080031#define TFM_HAL_ACCESS_READWRITE \
32 (TFM_HAL_ACCESS_READABLE | TFM_HAL_ACCESS_WRITABLE)
33
Tamas Band28286e2020-11-27 12:58:39 +000034#ifdef TFM_FIH_PROFILE_ON
Tamas Band28286e2020-11-27 12:58:39 +000035
Tamas Band28286e2020-11-27 12:58:39 +000036/**
Kevin Peng38788a12021-09-08 16:23:50 +080037 * \brief This function is responsible for checking all critical isolation
38 configurations.
39 *
40 * \return TFM_HAL_SUCCESS - the verification passed.
41 * TFM_HAL_ERROR_GENERIC - the verification failed.
42 */
43fih_int tfm_hal_verify_static_boundaries(void);
44
Xinyu Zhang6ad07032022-08-10 14:45:56 +080045#endif /* TFM_FIH_PROFILE_ON */
Tamas Band28286e2020-11-27 12:58:39 +000046/**
47 * \brief Sets up the static isolation boundaries which are constant throughout
48 * the runtime of the system, including the SPE/NSPE and partition
49 * boundaries.
50 *
Chendi Sun0f7d2822022-10-28 12:24:12 +080051 * \param[out] p_spm_boundary Pointer of the boundary value
52 *
Tamas Band28286e2020-11-27 12:58:39 +000053 * \return TFM_HAL_SUCCESS - the isolation boundaries have been set up.
54 * TFM_HAL_ERROR_GENERIC - failed to set up the isolation boundaries.
Tamas Band28286e2020-11-27 12:58:39 +000055 */
Chendi Sun0f7d2822022-10-28 12:24:12 +080056FIH_RET_TYPE(enum tfm_hal_status_t) tfm_hal_set_up_static_boundaries(
57 uintptr_t *p_spm_boundary);
Kevin Peng93fb9f52020-09-17 11:45:54 +080058
Tamas Band28286e2020-11-27 12:58:39 +000059/**
Ken Liu967ffa92022-05-25 15:13:34 +080060 * \brief Activate one Secure Partition boundary.
Tamas Band28286e2020-11-27 12:58:39 +000061 *
Ken Liuce58bfc2021-05-12 17:54:48 +080062 * \param[in] p_ldinf Partition load information.
Ken Liu967ffa92022-05-25 15:13:34 +080063 * \param[in] boundary Platform boundary value for partition.
Tamas Band28286e2020-11-27 12:58:39 +000064 *
Ken Liuce58bfc2021-05-12 17:54:48 +080065 * \return TFM_HAL_SUCCESS The isolation boundaries update succeeded.
66 * TFM_HAL_ERROR_GENERIC Failed to update the isolation boundaries.
Tamas Band28286e2020-11-27 12:58:39 +000067 */
Xinyu Zhang6ad07032022-08-10 14:45:56 +080068FIH_RET_TYPE(enum tfm_hal_status_t) tfm_hal_activate_boundary(
Ken Liuce58bfc2021-05-12 17:54:48 +080069 const struct partition_load_info_t *p_ldinf,
Ken Liu967ffa92022-05-25 15:13:34 +080070 uintptr_t boundary);
Tamas Band28286e2020-11-27 12:58:39 +000071
Kevin Peng93fb9f52020-09-17 11:45:54 +080072/**
Summer Qin56725eb2022-05-06 15:23:40 +080073 * \brief This API checks if a given range of memory can be accessed with
74 * specified access types in boundary. The boundary belongs to
75 * a partition which contains all asset info.
Kevin Peng93fb9f52020-09-17 11:45:54 +080076 *
Summer Qin56725eb2022-05-06 15:23:40 +080077 * \param[in] boundary The boundary that the given memory is to be
78 * checked with.
79 * \param[in] base The base address of the region.
80 * \param[in] size The size of the region.
81 * \param[in] access_type The memory access types to be checked between
82 * given memory and boundaries.
Kevin Peng93fb9f52020-09-17 11:45:54 +080083 *
84 * \return TFM_HAL_SUCCESS - The memory region has the access permissions.
85 * TFM_HAL_ERROR_MEM_FAULT - The memory region has not the access
86 * permissions.
87 * TFM_HAL_ERROR_INVALID_INPUT - Invalid inputs.
88 * TFM_HAL_ERROR_GENERIC - An error occurred.
89 */
Xinyu Zhang6ad07032022-08-10 14:45:56 +080090FIH_RET_TYPE(enum tfm_hal_status_t) tfm_hal_memory_check(
91 uintptr_t boundary, uintptr_t base,
Summer Qin56725eb2022-05-06 15:23:40 +080092 size_t size, uint32_t access_type);
Kevin Peng93fb9f52020-09-17 11:45:54 +080093
Ken Liuce58bfc2021-05-12 17:54:48 +080094/**
95 * \brief This API binds partition boundaries with the platform. The platform
96 * maintains the platform-specific settings for SPM further
Ken Liu967ffa92022-05-25 15:13:34 +080097 * usage, such as update partition boundaries or
Ken Liuce58bfc2021-05-12 17:54:48 +080098 * check resource accessibility. The platform needs to manage
Ken Liu967ffa92022-05-25 15:13:34 +080099 * the settings with internal mechanism, and return a value
100 * to SPM. SPM delivers this value back to platform when
101 * necessary. And SPM checks this value to decide if the
Ken Liuce58bfc2021-05-12 17:54:48 +0800102 * platform-specific settings need to be updated. Hence
Ken Liu967ffa92022-05-25 15:13:34 +0800103 * multiple partitions can have the same value if they have
Ken Liuce58bfc2021-05-12 17:54:48 +0800104 * the same platform-specific settings, depending on isolation level.
105 *
106 * \param[in] p_ldinf Partition load information.
Ken Liu967ffa92022-05-25 15:13:34 +0800107 * \param[in] p_boundary Pointer of the boundary value
Ken Liuce58bfc2021-05-12 17:54:48 +0800108 *
Ken Liu967ffa92022-05-25 15:13:34 +0800109 * \return TFM_HAL_SUCCESS - A platform value bound successfully.
110 * TFM_HAL_ERROR_GENERIC - Error occurred while binding.
Ken Liuce58bfc2021-05-12 17:54:48 +0800111 */
Xinyu Zhang6ad07032022-08-10 14:45:56 +0800112FIH_RET_TYPE(enum tfm_hal_status_t) tfm_hal_bind_boundary(
Ken Liuce58bfc2021-05-12 17:54:48 +0800113 const struct partition_load_info_t *p_ldinf,
Ken Liu967ffa92022-05-25 15:13:34 +0800114 uintptr_t *p_boundary);
Ken Liuce58bfc2021-05-12 17:54:48 +0800115
Chendi Sun0f7d2822022-10-28 12:24:12 +0800116/**
117 * \brief This API let the platform decide if a boundary switch is needed.
118 *
119 * \param[in] boundary_from The current boundary to be switched.
120 * \param[in] boundary_to The target boundary to be switched to.
121 *
122 * \return true - a switching is needed.
123 * false - do not need a switch.
124 */
Chris Brand272317e2024-04-05 15:29:32 -0700125FIH_RET_TYPE(bool) tfm_hal_boundary_need_switch(uintptr_t boundary_from,
126 uintptr_t boundary_to);
Chendi Sun0f7d2822022-10-28 12:24:12 +0800127
Roman Mazurak96585b82024-04-03 14:35:00 +0300128#if CONFIG_TFM_POST_PARTITION_INIT_HOOK == 1
129/**
130 * \brief This API let the platform to finish static isolation after all partitions
131 * have been bound.
132 *
133 * It's called by SPM right before starting scheduler.
134 *
135 * \return TFM_HAL_SUCCESS - Booting has been successful.
136 * TFM_HAL_ERROR_GENERIC - Error occurred.
137 */
138FIH_RET_TYPE(enum tfm_hal_status_t) tfm_hal_post_partition_init_hook(void);
139#endif /* CONFIG_TFM_POST_PARTITION_INIT_HOOK == 1 */
140
Kevin Peng93fb9f52020-09-17 11:45:54 +0800141#ifdef __cplusplus
142}
143#endif
144
145#endif /* __TFM_HAL_ISOLATION_H__ */