blob: 437f0a0e0781e2bba2f332aef31a987641efe1e7 [file] [log] [blame]
Kevin Peng93fb9f52020-09-17 11:45:54 +08001/*
Tamas Band28286e2020-11-27 12:58:39 +00002 * Copyright (c) 2020-2021, 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
Tamas Band28286e2020-11-27 12:58:39 +000029#ifdef TFM_FIH_PROFILE_ON
Ken Liuce58bfc2021-05-12 17:54:48 +080030#include "fih.h"
Kevin Peng93fb9f52020-09-17 11:45:54 +080031/**
32 * \brief Sets up the static isolation boundaries which are constant throughout
33 * the runtime of the system, including the SPE/NSPE and partition
34 * boundaries.
35 *
36 * \return TFM_HAL_SUCCESS - the isolation boundaries have been set up.
37 * TFM_HAL_ERROR_GENERIC - failed to set up the isolation boundaries.
38 */
Tamas Band28286e2020-11-27 12:58:39 +000039fih_int tfm_hal_set_up_static_boundaries(void);
40
Tamas Band28286e2020-11-27 12:58:39 +000041/**
Kevin Peng38788a12021-09-08 16:23:50 +080042 * \brief This function is responsible for checking all critical isolation
43 configurations.
44 *
45 * \return TFM_HAL_SUCCESS - the verification passed.
46 * TFM_HAL_ERROR_GENERIC - the verification failed.
47 */
48fih_int tfm_hal_verify_static_boundaries(void);
49
50/**
Ken Liuce58bfc2021-05-12 17:54:48 +080051 * \brief Update the isolation boundaries.
Tamas Band28286e2020-11-27 12:58:39 +000052 *
Ken Liuce58bfc2021-05-12 17:54:48 +080053 * \param[in] p_ldinf Partition load information.
54 * \param[in] p_boundaries Platform boundary handle for partition.
Tamas Band28286e2020-11-27 12:58:39 +000055 *
Ken Liuce58bfc2021-05-12 17:54:48 +080056 * \return TFM_HAL_SUCCESS The isolation boundaries update succeeded.
57 * TFM_HAL_ERROR_GENERIC Failed to update the isolation boundaries.
Tamas Band28286e2020-11-27 12:58:39 +000058 *
59 * \note When FIH_ENABLE_DOUBLE_VARS is enabled, the return code will be
60 * wrapped and protected in \ref fih_int structure.
61 */
Ken Liuce58bfc2021-05-12 17:54:48 +080062fih_int tfm_hal_update_boundaries(const struct partition_load_info_t *p_ldinf,
63 void *p_boundaries);
Tamas Band28286e2020-11-27 12:58:39 +000064#else /* TFM_FIH_PROFILE_ON */
65/**
66 * \brief Sets up the static isolation boundaries which are constant throughout
67 * the runtime of the system, including the SPE/NSPE and partition
68 * boundaries.
69 *
70 * \return TFM_HAL_SUCCESS - the isolation boundaries have been set up.
71 * TFM_HAL_ERROR_GENERIC - failed to set up the isolation boundaries.
Tamas Band28286e2020-11-27 12:58:39 +000072 */
Kevin Peng93fb9f52020-09-17 11:45:54 +080073enum tfm_hal_status_t tfm_hal_set_up_static_boundaries(void);
74
Tamas Band28286e2020-11-27 12:58:39 +000075/**
Ken Liuce58bfc2021-05-12 17:54:48 +080076 * \brief Update the isolation boundaries.
Tamas Band28286e2020-11-27 12:58:39 +000077 *
Ken Liuce58bfc2021-05-12 17:54:48 +080078 * \param[in] p_ldinf Partition load information.
79 * \param[in] p_boundaries Platform boundary handle for partition.
Tamas Band28286e2020-11-27 12:58:39 +000080 *
Ken Liuce58bfc2021-05-12 17:54:48 +080081 * \return TFM_HAL_SUCCESS The isolation boundaries update succeeded.
82 * TFM_HAL_ERROR_GENERIC Failed to update the isolation boundaries.
Tamas Band28286e2020-11-27 12:58:39 +000083 */
Ken Liuce58bfc2021-05-12 17:54:48 +080084enum tfm_hal_status_t tfm_hal_update_boundaries(
85 const struct partition_load_info_t *p_ldinf,
86 void *p_boundaries);
Tamas Band28286e2020-11-27 12:58:39 +000087#endif /* TFM_FIH_PROFILE_ON */
88
Kevin Peng93fb9f52020-09-17 11:45:54 +080089/**
90 * \brief This API checks if the memory region defined by base and size
91 * matches the given attributes - attr.
92 * The attributes can include NSPE access, privileged mode, and
93 * read-write permissions.
94 *
95 * \param[in] base The base address of the region.
96 * \param[in] size The size of the region.
97 * \param[in] attr The memory access attributes.
98 *
99 * \return TFM_HAL_SUCCESS - The memory region has the access permissions.
100 * TFM_HAL_ERROR_MEM_FAULT - The memory region has not the access
101 * permissions.
102 * TFM_HAL_ERROR_INVALID_INPUT - Invalid inputs.
103 * TFM_HAL_ERROR_GENERIC - An error occurred.
104 */
105enum tfm_hal_status_t tfm_hal_memory_has_access(uintptr_t base,
106 size_t size,
107 uint32_t attr);
108
Ken Liuce58bfc2021-05-12 17:54:48 +0800109/**
110 * \brief This API binds partition boundaries with the platform. The platform
111 * maintains the platform-specific settings for SPM further
112 * usage, such as update partition hardware boundaries or
113 * check resource accessibility. The platform needs to manage
114 * the settings with internal mechanism, and return a handle
115 * to SPM. SPM delivers this handle back to platform when
116 * necessary. And SPM checks this handle to decide if the
117 * platform-specific settings need to be updated. Hence
118 * multiple partitions can have the same handle if they have
119 * the same platform-specific settings, depending on isolation level.
120 *
121 * \param[in] p_ldinf Partition load information.
122 * \param[in] pp_boundaries Pointer of the boundary handle
123 *
124 * \return TFM_HAL_SUCCESS - A platform handle binding success.
125 * TFM_HAL_ERROR_GENERIC - Error occured while binding.
126 */
127enum tfm_hal_status_t tfm_hal_bind_boundaries(
128 const struct partition_load_info_t *p_ldinf,
129 void **pp_boundaries);
130
Kevin Peng93fb9f52020-09-17 11:45:54 +0800131#ifdef __cplusplus
132}
133#endif
134
135#endif /* __TFM_HAL_ISOLATION_H__ */