blob: cb54186007509562f4207c2409c9eb6c8059df96 [file] [log] [blame]
Edison Ai1c266ae2019-03-20 11:21:21 +08001/*
Summer Qind00e4db2019-05-09 18:03:52 +08002 * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
Edison Ai1c266ae2019-03-20 11:21:21 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef __TFM_SPM_HAL_H__
9#define __TFM_SPM_HAL_H__
10
11#include <stdint.h>
12#include "tfm_secure_api.h"
13#include "spm_api.h"
14
15/**
16 * \brief Holds peripheral specific data fields required to manage the
17 * peripherals isolation
18 *
19 * This structure has to be defined in the platform directory, and may have
20 * different definition for each platform. The structure should contain fields
21 * that describe the peripheral for the functions that are prototyped in this
22 * file and are responsible for configuring the isolation of the peripherals.
23 *
24 * Pointers to structures of this type are managed by the SPM, and passed to the
25 * necessary function on isolation request. The pointers are also defined by the
26 * platform in the header file tfm_peripherals_def.h. For details on this, see
27 * the documentation of that file.
28 */
29struct tfm_spm_partition_platform_data_t;
30
Mate Toth-Pal4341de02018-10-02 12:55:47 +020031enum irq_target_state_t {
32 TFM_IRQ_TARGET_STATE_SECURE,
33 TFM_IRQ_TARGET_STATE_NON_SECURE,
34};
35
Miklos Balintdd02bb32019-05-26 21:13:12 +020036#if defined (TFM_PSA_API) || (TFM_LVL != 1)
Edison Ai1c266ae2019-03-20 11:21:21 +080037/**
38 * \brief Holds SPM db fields that define the memory regions used by a
39 * partition.
40 */
41struct tfm_spm_partition_memory_data_t
42{
43 uint32_t code_start; /*!< Start of the code memory of this partition. */
44 uint32_t code_limit; /*!< Address of the byte beyond the end of the code
45 * memory of this partition.
46 */
47 uint32_t ro_start; /*!< Start of the read only memory of this
48 * partition.
49 */
50 uint32_t ro_limit; /*!< Address of the byte beyond the end of the read
51 * only memory of this partition.
52 */
53 uint32_t rw_start; /*!< Start of the data region of this partition. */
54 uint32_t rw_limit; /*!< Address of the byte beyond the end of the data
55 * region of this partition.
56 */
57 uint32_t zi_start; /*!< Start of the zero initialised data region of
58 * this partition.
59 */
60 uint32_t zi_limit; /*!< Address of the byte beyond the end of the zero
61 * initialised region of this partition.
62 */
63 uint32_t stack_bottom; /*!< The bottom of the stack for the partition. */
64 uint32_t stack_top; /*!< The top of the stack for the partition. */
65};
Miklos Balintdd02bb32019-05-26 21:13:12 +020066#endif
Edison Ai1c266ae2019-03-20 11:21:21 +080067
68/**
69 * \brief This function initialises the HW used for isolation, and sets the
70 * default configuration for them.
71 *
72 * This function is called during TF-M core early startup, before DB init
73 */
74void tfm_spm_hal_init_isolation_hw(void);
75
76/**
77 * \brief This function initialises the HW used for isolation, and sets the
78 * default configuration for them.
79 * This function is called during TF-M core early startup, after DB init
80 */
81void tfm_spm_hal_setup_isolation_hw(void);
82
83/**
84 * \brief Configure peripherals for a partition based on the platfotm data from
85 * the DB
86 *
87 * This function is called during partition initialisation (before calling the
88 * init function for the partition)
89 *
90 * \param[in] platform_data The platform fields of the partition DB record to
91 * be used for configuration. Can be NULL.
92 */
93void tfm_spm_hal_configure_default_isolation(
94 const struct tfm_spm_partition_platform_data_t *platform_data);
95/**
96 * \brief Configures the system debug properties.
97 * The default configuration of this function should disable secure debug
98 * when either DAUTH_NONE or DAUTH_NS_ONLY define is set. It is up to the
99 * platform owner to decide if secure debug can be turned on in their
100 * system, if DAUTH_FULL define is present.
101 * The DAUTH_CHIP_DEFAULT define should not be considered a safe default
102 * option unless explicitly noted by the chip vendor.
103 * The implementation has to expect that one of those defines is going to
104 * be set. Otherwise, a compile error needs to be triggered.
105 */
106void tfm_spm_hal_init_debug(void);
107
108/**
Mate Toth-Pal3e2ebd02019-05-07 14:22:16 +0200109 * \brief Enables the fault handlers and sets priorities.
110 *
111 * Secure fault (if present) must have the highest possible priority
Edison Ai1c266ae2019-03-20 11:21:21 +0800112 */
113void enable_fault_handlers(void);
114
115/**
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100116 * \brief Configures the system reset request properties
117 */
118void system_reset_cfg(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800119
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100120/**
Edison Ai1c266ae2019-03-20 11:21:21 +0800121 * \brief Configures all external interrupts to target the
122 * NS state, apart for the ones associated to secure
123 * peripherals (plus MPC and PPC)
124 */
125void nvic_interrupt_target_state_cfg(void);
126
127/**
128 * \brief This function enable the interrupts associated
129 * to the secure peripherals (plus the isolation boundary violation
130 * interrupts)
131 */
132void nvic_interrupt_enable(void);
133
134/**
135 * \brief Get the VTOR value of non-secure image
136 *
137 * \return Returns the address where the vector table of the non-secure image
138 * is located
139 */
140uint32_t tfm_spm_hal_get_ns_VTOR(void);
141
142/**
143 * \brief Get the initial address of non-secure image main stack
144 *
145 * \return Returns the initial non-secure MSP
146 */
147uint32_t tfm_spm_hal_get_ns_MSP(void);
148
149/**
150 * \brief Get the entry point of the non-secure image
151 *
152 * \return Returns the address of the non-secure image entry point
153 */
154uint32_t tfm_spm_hal_get_ns_entry_point(void);
155
Mate Toth-Pal94925722019-06-27 15:10:48 +0200156/**
157 * \brief Set the priority of a secure IRQ
158 *
159 * \param[in] irq_line The IRQ to set the priority for. Might be less than 0
160 * \param[in] priority The priority to set. [0..255]
161 *
162 * \details This function sets the priority for the IRQ passed in the parameter.
163 * The precision of the priority value might be adjusted to match the
164 * available priority bits in the underlying target platform.
165 */
166void tfm_spm_hal_set_secure_irq_priority(int32_t irq_line, uint32_t priority);
Edison Ai1c266ae2019-03-20 11:21:21 +0800167
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200168/**
169 * \brief Clears a pending IRQ
170 *
171 * \param[in] irq_line The IRQ to clear pending for.
172 */
173void tfm_spm_hal_clear_pending_irq(int32_t irq_line);
174
175/**
176 * \brief Enables an IRQ
177 *
178 * \param[in] irq_line The IRQ to be enabled.
179 */
180void tfm_spm_hal_enable_irq(int32_t irq_line);
181
182/**
183 * \brief Disables an IRQ
184 *
185 * \param[in] irq_line The IRQ to be disabled
186 */
187void tfm_spm_hal_disable_irq(int32_t irq_line);
188
189/**
190 * \brief Set the target state of an IRQ
191 *
192 * \param[in] irq_line The IRQ to set the priority for.
193 * \param[in] target_state Target state to ret for the IRQ.
194 *
195 * \return TFM_IRQ_TARGET_STATE_SECURE if interrupt is assigned
196 * to Secure
197 * TFM_IRQ_TARGET_STATE_NON_SECURE if interrupt is
198 * assigned to Non-Secure
199 */
200enum irq_target_state_t tfm_spm_hal_set_irq_target_state(
201 int32_t irq_line,
202 enum irq_target_state_t target_state);
203
Miklos Balintdd02bb32019-05-26 21:13:12 +0200204#if (TFM_LVL != 1) && !defined(TFM_PSA_API)
Edison Ai1c266ae2019-03-20 11:21:21 +0800205/**
206 * \brief Configure the sandbox for a partition.
207 *
208 * \param[in] memory_data The memory ranges from the partition DB for this
209 * partition
210 * \param[in] platform_data The platform fields of the partition DB record
211 * for this partition. Can be NULL.
212 *
213 * \return Returns the result operation as per \ref spm_err_t
214 */
215enum spm_err_t tfm_spm_hal_partition_sandbox_config(
216 const struct tfm_spm_partition_memory_data_t *memory_data,
217 const struct tfm_spm_partition_platform_data_t *platform_data);
218
219/**
220 * \brief Deconfigure the sandbox for a partition.
221 *
222 * \param[in] memory_data The memory ranges from the partition DB for this
223 * partition
224 * \param[in] platform_data The platform fields of the partition DB record
225 * for this partition. Can be NULL.
226 *
227 * \return Returns the result operation as per \ref spm_err_t
228 */
229enum spm_err_t tfm_spm_hal_partition_sandbox_deconfig(
230 const struct tfm_spm_partition_memory_data_t *memory_data,
231 const struct tfm_spm_partition_platform_data_t *platform_data);
232
233/**
234 * \brief Set the share region mode
235 *
236 * \param[in] share The mode to set
237 *
238 * \return Returns the result operation as per \ref spm_err_t
239 */
240enum spm_err_t tfm_spm_hal_set_share_region(
241 enum tfm_buffer_share_region_e share);
242#endif
243
244#endif /* __TFM_SPM_HAL_H__ */