blob: 120cdf579ffb45babd40aaa24c37d1031464b962 [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/**
Ken Liuce58bfc2021-05-12 17:54:48 +080042 * \brief Update the isolation boundaries.
Tamas Band28286e2020-11-27 12:58:39 +000043 *
Ken Liuce58bfc2021-05-12 17:54:48 +080044 * \param[in] p_ldinf Partition load information.
45 * \param[in] p_boundaries Platform boundary handle for partition.
Tamas Band28286e2020-11-27 12:58:39 +000046 *
Ken Liuce58bfc2021-05-12 17:54:48 +080047 * \return TFM_HAL_SUCCESS The isolation boundaries update succeeded.
48 * TFM_HAL_ERROR_GENERIC Failed to update the isolation boundaries.
Tamas Band28286e2020-11-27 12:58:39 +000049 *
50 * \note When FIH_ENABLE_DOUBLE_VARS is enabled, the return code will be
51 * wrapped and protected in \ref fih_int structure.
52 */
Ken Liuce58bfc2021-05-12 17:54:48 +080053fih_int tfm_hal_update_boundaries(const struct partition_load_info_t *p_ldinf,
54 void *p_boundaries);
Tamas Band28286e2020-11-27 12:58:39 +000055#else /* TFM_FIH_PROFILE_ON */
56/**
57 * \brief Sets up the static isolation boundaries which are constant throughout
58 * the runtime of the system, including the SPE/NSPE and partition
59 * boundaries.
60 *
61 * \return TFM_HAL_SUCCESS - the isolation boundaries have been set up.
62 * TFM_HAL_ERROR_GENERIC - failed to set up the isolation boundaries.
Tamas Band28286e2020-11-27 12:58:39 +000063 */
Kevin Peng93fb9f52020-09-17 11:45:54 +080064enum tfm_hal_status_t tfm_hal_set_up_static_boundaries(void);
65
Tamas Band28286e2020-11-27 12:58:39 +000066/**
Ken Liuce58bfc2021-05-12 17:54:48 +080067 * \brief Update the isolation boundaries.
Tamas Band28286e2020-11-27 12:58:39 +000068 *
Ken Liuce58bfc2021-05-12 17:54:48 +080069 * \param[in] p_ldinf Partition load information.
70 * \param[in] p_boundaries Platform boundary handle for partition.
Tamas Band28286e2020-11-27 12:58:39 +000071 *
Ken Liuce58bfc2021-05-12 17:54:48 +080072 * \return TFM_HAL_SUCCESS The isolation boundaries update succeeded.
73 * TFM_HAL_ERROR_GENERIC Failed to update the isolation boundaries.
Tamas Band28286e2020-11-27 12:58:39 +000074 */
Ken Liuce58bfc2021-05-12 17:54:48 +080075enum tfm_hal_status_t tfm_hal_update_boundaries(
76 const struct partition_load_info_t *p_ldinf,
77 void *p_boundaries);
Tamas Band28286e2020-11-27 12:58:39 +000078#endif /* TFM_FIH_PROFILE_ON */
79
Kevin Peng93fb9f52020-09-17 11:45:54 +080080/**
81 * \brief This API checks if the memory region defined by base and size
82 * matches the given attributes - attr.
83 * The attributes can include NSPE access, privileged mode, and
84 * read-write permissions.
85 *
86 * \param[in] base The base address of the region.
87 * \param[in] size The size of the region.
88 * \param[in] attr The memory access attributes.
89 *
90 * \return TFM_HAL_SUCCESS - The memory region has the access permissions.
91 * TFM_HAL_ERROR_MEM_FAULT - The memory region has not the access
92 * permissions.
93 * TFM_HAL_ERROR_INVALID_INPUT - Invalid inputs.
94 * TFM_HAL_ERROR_GENERIC - An error occurred.
95 */
96enum tfm_hal_status_t tfm_hal_memory_has_access(uintptr_t base,
97 size_t size,
98 uint32_t attr);
99
Ken Liuce58bfc2021-05-12 17:54:48 +0800100/**
101 * \brief This API binds partition boundaries with the platform. The platform
102 * maintains the platform-specific settings for SPM further
103 * usage, such as update partition hardware boundaries or
104 * check resource accessibility. The platform needs to manage
105 * the settings with internal mechanism, and return a handle
106 * to SPM. SPM delivers this handle back to platform when
107 * necessary. And SPM checks this handle to decide if the
108 * platform-specific settings need to be updated. Hence
109 * multiple partitions can have the same handle if they have
110 * the same platform-specific settings, depending on isolation level.
111 *
112 * \param[in] p_ldinf Partition load information.
113 * \param[in] pp_boundaries Pointer of the boundary handle
114 *
115 * \return TFM_HAL_SUCCESS - A platform handle binding success.
116 * TFM_HAL_ERROR_GENERIC - Error occured while binding.
117 */
118enum tfm_hal_status_t tfm_hal_bind_boundaries(
119 const struct partition_load_info_t *p_ldinf,
120 void **pp_boundaries);
121
Kevin Peng93fb9f52020-09-17 11:45:54 +0800122#ifdef __cplusplus
123}
124#endif
125
126#endif /* __TFM_HAL_ISOLATION_H__ */