blob: a041d9ac4389f118dbf7b0910ddd8b5a562cf409 [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>
Xinyu Zhang6ad07032022-08-10 14:45:56 +080013#include "fih.h"
Kevin Peng93fb9f52020-09-17 11:45:54 +080014#include "tfm_hal_defs.h"
Ken Liuce58bfc2021-05-12 17:54:48 +080015#include "load/partition_defs.h"
16#include "load/asset_defs.h"
Kevin Peng93fb9f52020-09-17 11:45:54 +080017
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22/* Memory access attributes */
23#define TFM_HAL_ACCESS_EXECUTABLE (1UL << 0)
24#define TFM_HAL_ACCESS_READABLE (1UL << 1)
25#define TFM_HAL_ACCESS_WRITABLE (1UL << 2)
26#define TFM_HAL_ACCESS_UNPRIVILEGED (1UL << 3)
27#define TFM_HAL_ACCESS_DEVICE (1UL << 4)
28#define TFM_HAL_ACCESS_NS (1UL << 5)
29
Summer Qin56725eb2022-05-06 15:23:40 +080030#define TFM_HAL_ACCESS_READWRITE \
31 (TFM_HAL_ACCESS_READABLE | TFM_HAL_ACCESS_WRITABLE)
32
Tamas Band28286e2020-11-27 12:58:39 +000033#ifdef TFM_FIH_PROFILE_ON
Tamas Band28286e2020-11-27 12:58:39 +000034
Tamas Band28286e2020-11-27 12:58:39 +000035/**
Kevin Peng38788a12021-09-08 16:23:50 +080036 * \brief This function is responsible for checking all critical isolation
37 configurations.
38 *
39 * \return TFM_HAL_SUCCESS - the verification passed.
40 * TFM_HAL_ERROR_GENERIC - the verification failed.
41 */
42fih_int tfm_hal_verify_static_boundaries(void);
43
Xinyu Zhang6ad07032022-08-10 14:45:56 +080044#endif /* TFM_FIH_PROFILE_ON */
Tamas Band28286e2020-11-27 12:58:39 +000045/**
46 * \brief Sets up the static isolation boundaries which are constant throughout
47 * the runtime of the system, including the SPE/NSPE and partition
48 * boundaries.
49 *
50 * \return TFM_HAL_SUCCESS - the isolation boundaries have been set up.
51 * TFM_HAL_ERROR_GENERIC - failed to set up the isolation boundaries.
Tamas Band28286e2020-11-27 12:58:39 +000052 */
Xinyu Zhang6ad07032022-08-10 14:45:56 +080053FIH_RET_TYPE(enum tfm_hal_status_t) tfm_hal_set_up_static_boundaries(void);
Kevin Peng93fb9f52020-09-17 11:45:54 +080054
Tamas Band28286e2020-11-27 12:58:39 +000055/**
Ken Liu967ffa92022-05-25 15:13:34 +080056 * \brief Activate one Secure Partition boundary.
Tamas Band28286e2020-11-27 12:58:39 +000057 *
Ken Liuce58bfc2021-05-12 17:54:48 +080058 * \param[in] p_ldinf Partition load information.
Ken Liu967ffa92022-05-25 15:13:34 +080059 * \param[in] boundary Platform boundary value for partition.
Tamas Band28286e2020-11-27 12:58:39 +000060 *
Ken Liuce58bfc2021-05-12 17:54:48 +080061 * \return TFM_HAL_SUCCESS The isolation boundaries update succeeded.
62 * TFM_HAL_ERROR_GENERIC Failed to update the isolation boundaries.
Tamas Band28286e2020-11-27 12:58:39 +000063 */
Xinyu Zhang6ad07032022-08-10 14:45:56 +080064FIH_RET_TYPE(enum tfm_hal_status_t) tfm_hal_activate_boundary(
Ken Liuce58bfc2021-05-12 17:54:48 +080065 const struct partition_load_info_t *p_ldinf,
Ken Liu967ffa92022-05-25 15:13:34 +080066 uintptr_t boundary);
Tamas Band28286e2020-11-27 12:58:39 +000067
Kevin Peng93fb9f52020-09-17 11:45:54 +080068/**
Summer Qin56725eb2022-05-06 15:23:40 +080069 * \brief This API checks if a given range of memory can be accessed with
70 * specified access types in boundary. The boundary belongs to
71 * a partition which contains all asset info.
Kevin Peng93fb9f52020-09-17 11:45:54 +080072 *
Summer Qin56725eb2022-05-06 15:23:40 +080073 * \param[in] boundary The boundary that the given memory is to be
74 * checked with.
75 * \param[in] base The base address of the region.
76 * \param[in] size The size of the region.
77 * \param[in] access_type The memory access types to be checked between
78 * given memory and boundaries.
Kevin Peng93fb9f52020-09-17 11:45:54 +080079 *
80 * \return TFM_HAL_SUCCESS - The memory region has the access permissions.
81 * TFM_HAL_ERROR_MEM_FAULT - The memory region has not the access
82 * permissions.
83 * TFM_HAL_ERROR_INVALID_INPUT - Invalid inputs.
84 * TFM_HAL_ERROR_GENERIC - An error occurred.
85 */
Xinyu Zhang6ad07032022-08-10 14:45:56 +080086FIH_RET_TYPE(enum tfm_hal_status_t) tfm_hal_memory_check(
87 uintptr_t boundary, uintptr_t base,
Summer Qin56725eb2022-05-06 15:23:40 +080088 size_t size, uint32_t access_type);
Kevin Peng93fb9f52020-09-17 11:45:54 +080089
Ken Liuce58bfc2021-05-12 17:54:48 +080090/**
91 * \brief This API binds partition boundaries with the platform. The platform
92 * maintains the platform-specific settings for SPM further
Ken Liu967ffa92022-05-25 15:13:34 +080093 * usage, such as update partition boundaries or
Ken Liuce58bfc2021-05-12 17:54:48 +080094 * check resource accessibility. The platform needs to manage
Ken Liu967ffa92022-05-25 15:13:34 +080095 * the settings with internal mechanism, and return a value
96 * to SPM. SPM delivers this value back to platform when
97 * necessary. And SPM checks this value to decide if the
Ken Liuce58bfc2021-05-12 17:54:48 +080098 * platform-specific settings need to be updated. Hence
Ken Liu967ffa92022-05-25 15:13:34 +080099 * multiple partitions can have the same value if they have
Ken Liuce58bfc2021-05-12 17:54:48 +0800100 * the same platform-specific settings, depending on isolation level.
101 *
102 * \param[in] p_ldinf Partition load information.
Ken Liu967ffa92022-05-25 15:13:34 +0800103 * \param[in] p_boundary Pointer of the boundary value
Ken Liuce58bfc2021-05-12 17:54:48 +0800104 *
Ken Liu967ffa92022-05-25 15:13:34 +0800105 * \return TFM_HAL_SUCCESS - A platform value bound successfully.
106 * TFM_HAL_ERROR_GENERIC - Error occurred while binding.
Ken Liuce58bfc2021-05-12 17:54:48 +0800107 */
Xinyu Zhang6ad07032022-08-10 14:45:56 +0800108FIH_RET_TYPE(enum tfm_hal_status_t) tfm_hal_bind_boundary(
Ken Liuce58bfc2021-05-12 17:54:48 +0800109 const struct partition_load_info_t *p_ldinf,
Ken Liu967ffa92022-05-25 15:13:34 +0800110 uintptr_t *p_boundary);
Ken Liuce58bfc2021-05-12 17:54:48 +0800111
Kevin Peng93fb9f52020-09-17 11:45:54 +0800112#ifdef __cplusplus
113}
114#endif
115
116#endif /* __TFM_HAL_ISOLATION_H__ */