blob: 7aaafeba6b6428eee7d344c1d5f2d3cb5d172b50 [file] [log] [blame]
Edison Ai1c266ae2019-03-20 11:21:21 +08001/*
Tamas Band28286e2020-11-27 12:58:39 +00002 * Copyright (c) 2018-2021, 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>
Tamas Band28286e2020-11-27 12:58:39 +000012#include "fih.h"
Edison Ai1c266ae2019-03-20 11:21:21 +080013#include "tfm_secure_api.h"
David Hu520dcd02019-11-18 16:04:36 +080014#ifdef TFM_MULTI_CORE_TOPOLOGY
15#include "tfm_multi_core.h"
16#endif
Mate Toth-Palb9c33552019-07-10 16:13:20 +020017#include "tfm_plat_defs.h"
Edison Ai1c266ae2019-03-20 11:21:21 +080018
19/**
20 * \brief Holds peripheral specific data fields required to manage the
21 * peripherals isolation
22 *
23 * This structure has to be defined in the platform directory, and may have
24 * different definition for each platform. The structure should contain fields
25 * that describe the peripheral for the functions that are prototyped in this
26 * file and are responsible for configuring the isolation of the peripherals.
27 *
28 * Pointers to structures of this type are managed by the SPM, and passed to the
29 * necessary function on isolation request. The pointers are also defined by the
30 * platform in the header file tfm_peripherals_def.h. For details on this, see
31 * the documentation of that file.
32 */
Ken Liu172f1e32021-02-05 16:31:03 +080033struct platform_data_t;
Edison Ai1c266ae2019-03-20 11:21:21 +080034
Mate Toth-Pal4341de02018-10-02 12:55:47 +020035enum irq_target_state_t {
36 TFM_IRQ_TARGET_STATE_SECURE,
37 TFM_IRQ_TARGET_STATE_NON_SECURE,
38};
39
Edison Ai14dd1372019-07-11 18:02:18 +080040#ifdef TFM_PSA_API
Edison Ai1c266ae2019-03-20 11:21:21 +080041/**
42 * \brief Holds SPM db fields that define the memory regions used by a
43 * partition.
44 */
45struct tfm_spm_partition_memory_data_t
46{
Kevin Peng25b190b2020-10-30 17:10:45 +080047#if TFM_LVL == 3
48 uint32_t data_start; /* Start of the private data region of current
49 * partition. Specifically, the private data
50 * includes RW, ZI and the partition stack below.
51 */
52 uint32_t data_limit; /* Address of the byte beyond the end of the data
53 * region of this partition.
54 */
55#endif
56 uint32_t stack_bottom; /* The bottom of the stack for the partition. */
57 uint32_t stack_top; /* The top of the stack for the partition. */
Edison Ai1c266ae2019-03-20 11:21:21 +080058};
Miklos Balintdd02bb32019-05-26 21:13:12 +020059#endif
Edison Ai1c266ae2019-03-20 11:21:21 +080060
Tamas Band28286e2020-11-27 12:58:39 +000061#ifdef TFM_FIH_PROFILE_ON
62#ifdef CONFIG_TFM_ENABLE_MEMORY_PROTECT
63/**
64 * \brief This function initialises the HW used for isolation, and sets the
65 * default configuration for them.
66 * This function is called during TF-M core early startup, after DB init
67 *
68 * \return Returns values as specified by FIH specific platform error code.
69 */
70fih_int tfm_spm_hal_setup_isolation_hw(void);
71#endif /* CONFIG_TFM_ENABLE_MEMORY_PROTECT */
72
73/**
74 * \brief Configure peripherals for a partition based on the platform data and
75 * partition index from the DB
76 *
77 * This function is called during partition initialisation (before calling the
78 * init function for the partition)
79 *
80 * \param[in] partition_idx The index of the partition that this peripheral
81 * is assigned to.
82 * \param[in] platform_data The platform fields of the partition DB record to
83 * be used for configuration.
84 *
85 * \return Returns values as specified by FIH specific platform error code
86 */
87fih_int tfm_spm_hal_configure_default_isolation(
88 uint32_t partition_idx,
89 const struct platform_data_t *platform_data);
90/**
91 * \brief Configures the system debug properties.
92 * The default configuration of this function should disable secure debug
93 * when either DAUTH_NONE or DAUTH_NS_ONLY define is set. It is up to the
94 * platform owner to decide if secure debug can be turned on in their
95 * system, if DAUTH_FULL define is present.
96 * The DAUTH_CHIP_DEFAULT define should not be considered a safe default
97 * option unless explicitly noted by the chip vendor.
98 * The implementation has to expect that one of those defines is going to
99 * be set. Otherwise, a compile error needs to be triggered.
100 *
101 * \return Returns values as specified by FIH specific platform error code
102 */
103fih_int tfm_spm_hal_init_debug(void);
104
105/**
106 * \brief This function verifies the settings of HW used for memory isolation,
107 * to make sure that important settings was not skipped due to fault
108 * injection attacks.
109 *
110 * This function is called during TF-M core late startup, before passing
111 * execution to non-secure code.
112 *
113 * \return Returns values as specified by FIH specific platform error code
114 */
115fih_int tfm_spm_hal_verify_isolation_hw(void);
116#else /* TFM_FIH_PROFILE_ON */
Edison Ai1dfd7b12020-02-23 14:16:08 +0800117#ifdef CONFIG_TFM_ENABLE_MEMORY_PROTECT
Edison Ai1c266ae2019-03-20 11:21:21 +0800118/**
119 * \brief This function initialises the HW used for isolation, and sets the
120 * default configuration for them.
121 * This function is called during TF-M core early startup, after DB init
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200122 *
123 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800124 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200125enum tfm_plat_err_t tfm_spm_hal_setup_isolation_hw(void);
Edison Ai1dfd7b12020-02-23 14:16:08 +0800126#endif /* CONFIG_TFM_ENABLE_MEMORY_PROTECT */
Edison Ai1c266ae2019-03-20 11:21:21 +0800127
128/**
Mate Toth-Pal5e6d0342019-11-22 11:43:20 +0100129 * \brief Configure peripherals for a partition based on the platform data and
130 * partition index from the DB
Edison Ai1c266ae2019-03-20 11:21:21 +0800131 *
132 * This function is called during partition initialisation (before calling the
133 * init function for the partition)
134 *
Mate Toth-Pal5e6d0342019-11-22 11:43:20 +0100135 * \param[in] partition_idx The index of the partition that this peripheral
136 * is assigned to.
Edison Ai1c266ae2019-03-20 11:21:21 +0800137 * \param[in] platform_data The platform fields of the partition DB record to
Edison Ai6be3df12020-02-14 22:14:33 +0800138 * be used for configuration.
139 *
140 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800141 */
Edison Ai6be3df12020-02-14 22:14:33 +0800142enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
Mate Toth-Pal5e6d0342019-11-22 11:43:20 +0100143 uint32_t partition_idx,
Ken Liu172f1e32021-02-05 16:31:03 +0800144 const struct platform_data_t *platform_data);
Edison Ai1c266ae2019-03-20 11:21:21 +0800145/**
146 * \brief Configures the system debug properties.
147 * The default configuration of this function should disable secure debug
148 * when either DAUTH_NONE or DAUTH_NS_ONLY define is set. It is up to the
149 * platform owner to decide if secure debug can be turned on in their
150 * system, if DAUTH_FULL define is present.
151 * The DAUTH_CHIP_DEFAULT define should not be considered a safe default
152 * option unless explicitly noted by the chip vendor.
153 * The implementation has to expect that one of those defines is going to
154 * be set. Otherwise, a compile error needs to be triggered.
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200155 *
156 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800157 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200158enum tfm_plat_err_t tfm_spm_hal_init_debug(void);
Tamas Band28286e2020-11-27 12:58:39 +0000159#endif /* TFM_FIH_PROFILE_ON */
Edison Ai1c266ae2019-03-20 11:21:21 +0800160
161/**
Mate Toth-Pal3e2ebd02019-05-07 14:22:16 +0200162 * \brief Enables the fault handlers and sets priorities.
163 *
164 * Secure fault (if present) must have the highest possible priority
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200165 *
166 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800167 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200168enum tfm_plat_err_t tfm_spm_hal_enable_fault_handlers(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800169
170/**
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100171 * \brief Configures the system reset request properties
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200172 *
173 * \return Returns values as specified by the \ref tfm_plat_err_t
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100174 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200175enum tfm_plat_err_t tfm_spm_hal_system_reset_cfg(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800176
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100177/**
Edison Ai1c266ae2019-03-20 11:21:21 +0800178 * \brief Configures all external interrupts to target the
179 * NS state, apart for the ones associated to secure
180 * peripherals (plus MPC and PPC)
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200181 *
182 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800183 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200184enum tfm_plat_err_t tfm_spm_hal_nvic_interrupt_target_state_cfg(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800185
186/**
187 * \brief This function enable the interrupts associated
188 * to the secure peripherals (plus the isolation boundary violation
189 * interrupts)
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200190 *
191 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800192 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200193enum tfm_plat_err_t tfm_spm_hal_nvic_interrupt_enable(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800194
195/**
196 * \brief Get the VTOR value of non-secure image
197 *
198 * \return Returns the address where the vector table of the non-secure image
199 * is located
200 */
201uint32_t tfm_spm_hal_get_ns_VTOR(void);
202
203/**
204 * \brief Get the initial address of non-secure image main stack
205 *
206 * \return Returns the initial non-secure MSP
207 */
208uint32_t tfm_spm_hal_get_ns_MSP(void);
209
210/**
211 * \brief Get the entry point of the non-secure image
212 *
213 * \return Returns the address of the non-secure image entry point
214 */
215uint32_t tfm_spm_hal_get_ns_entry_point(void);
216
Mate Toth-Pal94925722019-06-27 15:10:48 +0200217/**
218 * \brief Set the priority of a secure IRQ
219 *
220 * \param[in] irq_line The IRQ to set the priority for. Might be less than 0
221 * \param[in] priority The priority to set. [0..255]
222 *
223 * \details This function sets the priority for the IRQ passed in the parameter.
224 * The precision of the priority value might be adjusted to match the
225 * available priority bits in the underlying target platform.
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200226 *
227 * \return Returns values as specified by the \ref tfm_plat_err_t
Mate Toth-Pal94925722019-06-27 15:10:48 +0200228 */
TTornblomfaf74f52020-03-04 17:56:27 +0100229enum tfm_plat_err_t tfm_spm_hal_set_secure_irq_priority(IRQn_Type irq_line,
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200230 uint32_t priority);
Edison Ai1c266ae2019-03-20 11:21:21 +0800231
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200232/**
233 * \brief Clears a pending IRQ
234 *
235 * \param[in] irq_line The IRQ to clear pending for.
236 */
TTornblomfaf74f52020-03-04 17:56:27 +0100237void tfm_spm_hal_clear_pending_irq(IRQn_Type irq_line);
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200238
239/**
240 * \brief Enables an IRQ
241 *
242 * \param[in] irq_line The IRQ to be enabled.
243 */
TTornblomfaf74f52020-03-04 17:56:27 +0100244void tfm_spm_hal_enable_irq(IRQn_Type irq_line);
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200245
246/**
247 * \brief Disables an IRQ
248 *
249 * \param[in] irq_line The IRQ to be disabled
250 */
TTornblomfaf74f52020-03-04 17:56:27 +0100251void tfm_spm_hal_disable_irq(IRQn_Type irq_line);
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200252
253/**
254 * \brief Set the target state of an IRQ
255 *
256 * \param[in] irq_line The IRQ to set the priority for.
257 * \param[in] target_state Target state to ret for the IRQ.
258 *
259 * \return TFM_IRQ_TARGET_STATE_SECURE if interrupt is assigned
260 * to Secure
261 * TFM_IRQ_TARGET_STATE_NON_SECURE if interrupt is
262 * assigned to Non-Secure
263 */
264enum irq_target_state_t tfm_spm_hal_set_irq_target_state(
TTornblomfaf74f52020-03-04 17:56:27 +0100265 IRQn_Type irq_line,
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200266 enum irq_target_state_t target_state);
267
David Hu520dcd02019-11-18 16:04:36 +0800268#ifdef TFM_MULTI_CORE_TOPOLOGY
269/**
270 * \brief Performs the necessary actions to start the non-secure CPU running
271 * the code at the specified address.
272 *
273 * \param[in] start_addr The entry point address of non-secure code.
274 */
275void tfm_spm_hal_boot_ns_cpu(uintptr_t start_addr);
276
277/**
278 * \brief Called on the secure CPU.
279 * Flags that the secure CPU has completed its initialization
280 * Waits, if necessary, for the non-secure CPU to flag that
281 * it has completed its initialisation
282 */
283void tfm_spm_hal_wait_for_ns_cpu_ready(void);
284
285/**
286 * \brief Retrieve the current active security configuration information and
287 * fills the \ref security_attr_info_t.
288 *
289 * \param[in] p Base address of target memory region
290 * \param[in] s Size of target memory region
291 * \param[out] p_attr Address of \ref security_attr_info_t to be filled
292 *
293 * \return void
294 */
295void tfm_spm_hal_get_mem_security_attr(const void *p, size_t s,
296 struct security_attr_info_t *p_attr);
297
298/**
299 * \brief Retrieve the secure memory protection configuration information and
300 * fills the \ref mem_attr_info_t.
301 *
302 * \param[in] p Base address of target memory region
303 * \param[in] s Size of target memory region
304 * \param[out] p_attr Address of \ref mem_attr_info_t to be filled
305 *
306 * \return void
307 */
308void tfm_spm_hal_get_secure_access_attr(const void *p, size_t s,
309 struct mem_attr_info_t *p_attr);
310
311/**
312 * \brief Retrieve the non-secure memory protection configuration information
313 * and fills the \ref mem_attr_info_t.
314 *
315 * \param[in] p Base address of target memory region
316 * \param[in] s Size of target memory region
317 * \param[out] p_attr Address of \ref mem_attr_info_t to be filled
318 *
319 * \return void
320 */
321void tfm_spm_hal_get_ns_access_attr(const void *p, size_t s,
322 struct mem_attr_info_t *p_attr);
323
324#endif /*TFM_MULTI_CORE_TOPOLOGY*/
325
Ioannis Glaropoulos130248c2020-07-30 15:09:01 +0200326#if !defined(__SAUREGION_PRESENT) || (__SAUREGION_PRESENT == 0)
327/**
328 * \brief Platform-specific check whether the current partition has access to a memory range
329 *
330 * The function checks whether the current partition has access to a memory range,
331 * taking into consideration the implementation-defined attribution unit that is
332 * present on a particular platform.
333 *
334 * \param[in] p The start address of the range to check
335 * \param[in] s The size of the range to check
336 * \param[in] flags The flags to pass to the cmse_check_address_range func
337 *
338 * \return True if the access is granted, false otherwise.
339 */
340bool tfm_spm_hal_has_access_to_region(const void *p, size_t s,
341 int flags);
342#endif /* !defined(__SAUREGION_PRESENT) || (__SAUREGION_PRESENT == 0) */
343
Edison Ai1c266ae2019-03-20 11:21:21 +0800344#endif /* __TFM_SPM_HAL_H__ */