blob: 3756d9c20d81bc69dbcabe0e1ccc43d9ea35b278 [file] [log] [blame]
Edison Ai1c266ae2019-03-20 11:21:21 +08001/*
Mate Toth-Pal5e6d0342019-11-22 11:43:20 +01002 * Copyright (c) 2018-2020, 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"
David Hu520dcd02019-11-18 16:04:36 +080013#ifdef TFM_MULTI_CORE_TOPOLOGY
14#include "tfm_multi_core.h"
15#endif
Mate Toth-Palb9c33552019-07-10 16:13:20 +020016#include "tfm_plat_defs.h"
Edison Ai1c266ae2019-03-20 11:21:21 +080017
18/**
19 * \brief Holds peripheral specific data fields required to manage the
20 * peripherals isolation
21 *
22 * This structure has to be defined in the platform directory, and may have
23 * different definition for each platform. The structure should contain fields
24 * that describe the peripheral for the functions that are prototyped in this
25 * file and are responsible for configuring the isolation of the peripherals.
26 *
27 * Pointers to structures of this type are managed by the SPM, and passed to the
28 * necessary function on isolation request. The pointers are also defined by the
29 * platform in the header file tfm_peripherals_def.h. For details on this, see
30 * the documentation of that file.
31 */
32struct tfm_spm_partition_platform_data_t;
33
Mate Toth-Pal4341de02018-10-02 12:55:47 +020034enum irq_target_state_t {
35 TFM_IRQ_TARGET_STATE_SECURE,
36 TFM_IRQ_TARGET_STATE_NON_SECURE,
37};
38
Edison Ai14dd1372019-07-11 18:02:18 +080039#ifdef TFM_PSA_API
Edison Ai1c266ae2019-03-20 11:21:21 +080040/**
41 * \brief Holds SPM db fields that define the memory regions used by a
42 * partition.
43 */
44struct tfm_spm_partition_memory_data_t
45{
46 uint32_t code_start; /*!< Start of the code memory of this partition. */
47 uint32_t code_limit; /*!< Address of the byte beyond the end of the code
48 * memory of this partition.
49 */
50 uint32_t ro_start; /*!< Start of the read only memory of this
51 * partition.
52 */
53 uint32_t ro_limit; /*!< Address of the byte beyond the end of the read
54 * only memory of this partition.
55 */
56 uint32_t rw_start; /*!< Start of the data region of this partition. */
57 uint32_t rw_limit; /*!< Address of the byte beyond the end of the data
58 * region of this partition.
59 */
60 uint32_t zi_start; /*!< Start of the zero initialised data region of
61 * this partition.
62 */
63 uint32_t zi_limit; /*!< Address of the byte beyond the end of the zero
64 * initialised region of this partition.
65 */
66 uint32_t stack_bottom; /*!< The bottom of the stack for the partition. */
67 uint32_t stack_top; /*!< The top of the stack for the partition. */
68};
Miklos Balintdd02bb32019-05-26 21:13:12 +020069#endif
Edison Ai1c266ae2019-03-20 11:21:21 +080070
71/**
72 * \brief This function initialises the HW used for isolation, and sets the
73 * default configuration for them.
74 *
75 * This function is called during TF-M core early startup, before DB init
Mate Toth-Palb9c33552019-07-10 16:13:20 +020076 *
77 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +080078 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +020079enum tfm_plat_err_t tfm_spm_hal_init_isolation_hw(void);
Edison Ai1c266ae2019-03-20 11:21:21 +080080
Edison Ai1dfd7b12020-02-23 14:16:08 +080081#ifdef CONFIG_TFM_ENABLE_MEMORY_PROTECT
Edison Ai1c266ae2019-03-20 11:21:21 +080082/**
83 * \brief This function initialises the HW used for isolation, and sets the
84 * default configuration for them.
85 * This function is called during TF-M core early startup, after DB init
Mate Toth-Palb9c33552019-07-10 16:13:20 +020086 *
87 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +080088 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +020089enum tfm_plat_err_t tfm_spm_hal_setup_isolation_hw(void);
Edison Ai1dfd7b12020-02-23 14:16:08 +080090#endif /* CONFIG_TFM_ENABLE_MEMORY_PROTECT */
Edison Ai1c266ae2019-03-20 11:21:21 +080091
92/**
Mate Toth-Pal5e6d0342019-11-22 11:43:20 +010093 * \brief Configure peripherals for a partition based on the platform data and
94 * partition index from the DB
Edison Ai1c266ae2019-03-20 11:21:21 +080095 *
96 * This function is called during partition initialisation (before calling the
97 * init function for the partition)
98 *
Mate Toth-Pal5e6d0342019-11-22 11:43:20 +010099 * \param[in] partition_idx The index of the partition that this peripheral
100 * is assigned to.
Edison Ai1c266ae2019-03-20 11:21:21 +0800101 * \param[in] platform_data The platform fields of the partition DB record to
Edison Ai6be3df12020-02-14 22:14:33 +0800102 * be used for configuration.
103 *
104 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800105 */
Edison Ai6be3df12020-02-14 22:14:33 +0800106enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
Mate Toth-Pal5e6d0342019-11-22 11:43:20 +0100107 uint32_t partition_idx,
Edison Ai1c266ae2019-03-20 11:21:21 +0800108 const struct tfm_spm_partition_platform_data_t *platform_data);
109/**
110 * \brief Configures the system debug properties.
111 * The default configuration of this function should disable secure debug
112 * when either DAUTH_NONE or DAUTH_NS_ONLY define is set. It is up to the
113 * platform owner to decide if secure debug can be turned on in their
114 * system, if DAUTH_FULL define is present.
115 * The DAUTH_CHIP_DEFAULT define should not be considered a safe default
116 * option unless explicitly noted by the chip vendor.
117 * The implementation has to expect that one of those defines is going to
118 * be set. Otherwise, a compile error needs to be triggered.
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200119 *
120 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800121 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200122enum tfm_plat_err_t tfm_spm_hal_init_debug(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800123
124/**
Mate Toth-Pal3e2ebd02019-05-07 14:22:16 +0200125 * \brief Enables the fault handlers and sets priorities.
126 *
127 * Secure fault (if present) must have the highest possible priority
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200128 *
129 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800130 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200131enum tfm_plat_err_t tfm_spm_hal_enable_fault_handlers(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800132
133/**
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100134 * \brief Configures the system reset request properties
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200135 *
136 * \return Returns values as specified by the \ref tfm_plat_err_t
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100137 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200138enum tfm_plat_err_t tfm_spm_hal_system_reset_cfg(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800139
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100140/**
Edison Ai1c266ae2019-03-20 11:21:21 +0800141 * \brief Configures all external interrupts to target the
142 * NS state, apart for the ones associated to secure
143 * peripherals (plus MPC and PPC)
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200144 *
145 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800146 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200147enum tfm_plat_err_t tfm_spm_hal_nvic_interrupt_target_state_cfg(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800148
149/**
150 * \brief This function enable the interrupts associated
151 * to the secure peripherals (plus the isolation boundary violation
152 * interrupts)
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200153 *
154 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800155 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200156enum tfm_plat_err_t tfm_spm_hal_nvic_interrupt_enable(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800157
158/**
159 * \brief Get the VTOR value of non-secure image
160 *
161 * \return Returns the address where the vector table of the non-secure image
162 * is located
163 */
164uint32_t tfm_spm_hal_get_ns_VTOR(void);
165
166/**
167 * \brief Get the initial address of non-secure image main stack
168 *
169 * \return Returns the initial non-secure MSP
170 */
171uint32_t tfm_spm_hal_get_ns_MSP(void);
172
173/**
174 * \brief Get the entry point of the non-secure image
175 *
176 * \return Returns the address of the non-secure image entry point
177 */
178uint32_t tfm_spm_hal_get_ns_entry_point(void);
179
Mate Toth-Pal94925722019-06-27 15:10:48 +0200180/**
181 * \brief Set the priority of a secure IRQ
182 *
183 * \param[in] irq_line The IRQ to set the priority for. Might be less than 0
184 * \param[in] priority The priority to set. [0..255]
185 *
186 * \details This function sets the priority for the IRQ passed in the parameter.
187 * The precision of the priority value might be adjusted to match the
188 * available priority bits in the underlying target platform.
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200189 *
190 * \return Returns values as specified by the \ref tfm_plat_err_t
Mate Toth-Pal94925722019-06-27 15:10:48 +0200191 */
TTornblomfaf74f52020-03-04 17:56:27 +0100192enum tfm_plat_err_t tfm_spm_hal_set_secure_irq_priority(IRQn_Type irq_line,
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200193 uint32_t priority);
Edison Ai1c266ae2019-03-20 11:21:21 +0800194
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200195/**
196 * \brief Clears a pending IRQ
197 *
198 * \param[in] irq_line The IRQ to clear pending for.
199 */
TTornblomfaf74f52020-03-04 17:56:27 +0100200void tfm_spm_hal_clear_pending_irq(IRQn_Type irq_line);
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200201
202/**
203 * \brief Enables an IRQ
204 *
205 * \param[in] irq_line The IRQ to be enabled.
206 */
TTornblomfaf74f52020-03-04 17:56:27 +0100207void tfm_spm_hal_enable_irq(IRQn_Type irq_line);
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200208
209/**
210 * \brief Disables an IRQ
211 *
212 * \param[in] irq_line The IRQ to be disabled
213 */
TTornblomfaf74f52020-03-04 17:56:27 +0100214void tfm_spm_hal_disable_irq(IRQn_Type irq_line);
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200215
216/**
217 * \brief Set the target state of an IRQ
218 *
219 * \param[in] irq_line The IRQ to set the priority for.
220 * \param[in] target_state Target state to ret for the IRQ.
221 *
222 * \return TFM_IRQ_TARGET_STATE_SECURE if interrupt is assigned
223 * to Secure
224 * TFM_IRQ_TARGET_STATE_NON_SECURE if interrupt is
225 * assigned to Non-Secure
226 */
227enum irq_target_state_t tfm_spm_hal_set_irq_target_state(
TTornblomfaf74f52020-03-04 17:56:27 +0100228 IRQn_Type irq_line,
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200229 enum irq_target_state_t target_state);
230
David Hu520dcd02019-11-18 16:04:36 +0800231#ifdef TFM_MULTI_CORE_TOPOLOGY
232/**
233 * \brief Performs the necessary actions to start the non-secure CPU running
234 * the code at the specified address.
235 *
236 * \param[in] start_addr The entry point address of non-secure code.
237 */
238void tfm_spm_hal_boot_ns_cpu(uintptr_t start_addr);
239
240/**
241 * \brief Called on the secure CPU.
242 * Flags that the secure CPU has completed its initialization
243 * Waits, if necessary, for the non-secure CPU to flag that
244 * it has completed its initialisation
245 */
246void tfm_spm_hal_wait_for_ns_cpu_ready(void);
247
248/**
249 * \brief Retrieve the current active security configuration information and
250 * fills the \ref security_attr_info_t.
251 *
252 * \param[in] p Base address of target memory region
253 * \param[in] s Size of target memory region
254 * \param[out] p_attr Address of \ref security_attr_info_t to be filled
255 *
256 * \return void
257 */
258void tfm_spm_hal_get_mem_security_attr(const void *p, size_t s,
259 struct security_attr_info_t *p_attr);
260
261/**
262 * \brief Retrieve the secure memory protection configuration information and
263 * fills the \ref mem_attr_info_t.
264 *
265 * \param[in] p Base address of target memory region
266 * \param[in] s Size of target memory region
267 * \param[out] p_attr Address of \ref mem_attr_info_t to be filled
268 *
269 * \return void
270 */
271void tfm_spm_hal_get_secure_access_attr(const void *p, size_t s,
272 struct mem_attr_info_t *p_attr);
273
274/**
275 * \brief Retrieve the non-secure memory protection configuration information
276 * and fills the \ref mem_attr_info_t.
277 *
278 * \param[in] p Base address of target memory region
279 * \param[in] s Size of target memory region
280 * \param[out] p_attr Address of \ref mem_attr_info_t to be filled
281 *
282 * \return void
283 */
284void tfm_spm_hal_get_ns_access_attr(const void *p, size_t s,
285 struct mem_attr_info_t *p_attr);
286
287#endif /*TFM_MULTI_CORE_TOPOLOGY*/
288
Ioannis Glaropoulos130248c2020-07-30 15:09:01 +0200289#if !defined(__SAUREGION_PRESENT) || (__SAUREGION_PRESENT == 0)
290/**
291 * \brief Platform-specific check whether the current partition has access to a memory range
292 *
293 * The function checks whether the current partition has access to a memory range,
294 * taking into consideration the implementation-defined attribution unit that is
295 * present on a particular platform.
296 *
297 * \param[in] p The start address of the range to check
298 * \param[in] s The size of the range to check
299 * \param[in] flags The flags to pass to the cmse_check_address_range func
300 *
301 * \return True if the access is granted, false otherwise.
302 */
303bool tfm_spm_hal_has_access_to_region(const void *p, size_t s,
304 int flags);
305#endif /* !defined(__SAUREGION_PRESENT) || (__SAUREGION_PRESENT == 0) */
306
Edison Ai1c266ae2019-03-20 11:21:21 +0800307#endif /* __TFM_SPM_HAL_H__ */