blob: cd12ae432cd3b263e58ac81a1b10cc17585b963d [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"
Mate Toth-Palb9c33552019-07-10 16:13:20 +020014#include "tfm_plat_defs.h"
Edison Ai1c266ae2019-03-20 11:21:21 +080015
16/**
17 * \brief Holds peripheral specific data fields required to manage the
18 * peripherals isolation
19 *
20 * This structure has to be defined in the platform directory, and may have
21 * different definition for each platform. The structure should contain fields
22 * that describe the peripheral for the functions that are prototyped in this
23 * file and are responsible for configuring the isolation of the peripherals.
24 *
25 * Pointers to structures of this type are managed by the SPM, and passed to the
26 * necessary function on isolation request. The pointers are also defined by the
27 * platform in the header file tfm_peripherals_def.h. For details on this, see
28 * the documentation of that file.
29 */
30struct tfm_spm_partition_platform_data_t;
31
Mate Toth-Pal4341de02018-10-02 12:55:47 +020032enum irq_target_state_t {
33 TFM_IRQ_TARGET_STATE_SECURE,
34 TFM_IRQ_TARGET_STATE_NON_SECURE,
35};
36
Edison Ai14dd1372019-07-11 18:02:18 +080037#ifdef TFM_PSA_API
Edison Ai1c266ae2019-03-20 11:21:21 +080038/**
39 * \brief Holds SPM db fields that define the memory regions used by a
40 * partition.
41 */
42struct tfm_spm_partition_memory_data_t
43{
44 uint32_t code_start; /*!< Start of the code memory of this partition. */
45 uint32_t code_limit; /*!< Address of the byte beyond the end of the code
46 * memory of this partition.
47 */
48 uint32_t ro_start; /*!< Start of the read only memory of this
49 * partition.
50 */
51 uint32_t ro_limit; /*!< Address of the byte beyond the end of the read
52 * only memory of this partition.
53 */
54 uint32_t rw_start; /*!< Start of the data region of this partition. */
55 uint32_t rw_limit; /*!< Address of the byte beyond the end of the data
56 * region of this partition.
57 */
58 uint32_t zi_start; /*!< Start of the zero initialised data region of
59 * this partition.
60 */
61 uint32_t zi_limit; /*!< Address of the byte beyond the end of the zero
62 * initialised region of this partition.
63 */
64 uint32_t stack_bottom; /*!< The bottom of the stack for the partition. */
65 uint32_t stack_top; /*!< The top of the stack for the partition. */
66};
Miklos Balintdd02bb32019-05-26 21:13:12 +020067#endif
Edison Ai1c266ae2019-03-20 11:21:21 +080068
69/**
Andrei Narkevitch5bba54c2019-09-23 14:09:13 -070070 * \brief This function initializes peripherals common to all platforms.
71 *
72 * Contrarily to SystemInit() intended for a high-priority hw initialization
73 * (for example clock and power subsystems), and called on a very early boot
74 * stage from startup code, this function is called from C code, hence variables
75 * and other drivers data are protected from being cleared up by the C library
76 * init.
77 * In addition to performing initialization common to all platforms, it also
78 * calls tfm_spm_hal_post_init_platform() function which implements
79 * initialization of platform-specific peripherals and other hw.
80 *
81 * \return Returns values as specified by the \ref tfm_plat_err_t
82 */
83enum tfm_plat_err_t tfm_spm_hal_post_init(void);
84
85/**
86 * \brief This function initializes platform-specific peripherals and hardware.
87 *
88 * Called from tfm_spm_hal_post_init(), this function is intended for
89 * platform-specific portion of hardware initialization.
90 *
91 * \return Returns values as specified by the \ref tfm_plat_err_t
92 */
93enum tfm_plat_err_t tfm_spm_hal_post_init_platform(void);
94
95/**
Edison Ai1c266ae2019-03-20 11:21:21 +080096 * \brief This function initialises the HW used for isolation, and sets the
97 * default configuration for them.
98 *
99 * This function is called during TF-M core early startup, before DB init
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200100 *
101 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800102 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200103enum tfm_plat_err_t tfm_spm_hal_init_isolation_hw(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800104
Edison Aic1b10902019-08-26 10:34:19 +0800105#if TFM_LVL != 1
Edison Ai1c266ae2019-03-20 11:21:21 +0800106/**
107 * \brief This function initialises the HW used for isolation, and sets the
108 * default configuration for them.
109 * This function is called during TF-M core early startup, after DB init
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200110 *
111 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800112 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200113enum tfm_plat_err_t tfm_spm_hal_setup_isolation_hw(void);
Edison Aic1b10902019-08-26 10:34:19 +0800114#endif
Edison Ai1c266ae2019-03-20 11:21:21 +0800115
116/**
117 * \brief Configure peripherals for a partition based on the platfotm data from
118 * the DB
119 *
120 * This function is called during partition initialisation (before calling the
121 * init function for the partition)
122 *
123 * \param[in] platform_data The platform fields of the partition DB record to
124 * be used for configuration. Can be NULL.
125 */
126void tfm_spm_hal_configure_default_isolation(
127 const struct tfm_spm_partition_platform_data_t *platform_data);
128/**
129 * \brief Configures the system debug properties.
130 * The default configuration of this function should disable secure debug
131 * when either DAUTH_NONE or DAUTH_NS_ONLY define is set. It is up to the
132 * platform owner to decide if secure debug can be turned on in their
133 * system, if DAUTH_FULL define is present.
134 * The DAUTH_CHIP_DEFAULT define should not be considered a safe default
135 * option unless explicitly noted by the chip vendor.
136 * The implementation has to expect that one of those defines is going to
137 * be set. Otherwise, a compile error needs to be triggered.
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200138 *
139 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800140 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200141enum tfm_plat_err_t tfm_spm_hal_init_debug(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800142
143/**
Mate Toth-Pal3e2ebd02019-05-07 14:22:16 +0200144 * \brief Enables the fault handlers and sets priorities.
145 *
146 * Secure fault (if present) must have the highest possible priority
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200147 *
148 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800149 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200150enum tfm_plat_err_t tfm_spm_hal_enable_fault_handlers(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800151
152/**
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100153 * \brief Configures the system reset request properties
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200154 *
155 * \return Returns values as specified by the \ref tfm_plat_err_t
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100156 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200157enum tfm_plat_err_t tfm_spm_hal_system_reset_cfg(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800158
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100159/**
Edison Ai1c266ae2019-03-20 11:21:21 +0800160 * \brief Configures all external interrupts to target the
161 * NS state, apart for the ones associated to secure
162 * peripherals (plus MPC and PPC)
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200163 *
164 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800165 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200166enum tfm_plat_err_t tfm_spm_hal_nvic_interrupt_target_state_cfg(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800167
168/**
169 * \brief This function enable the interrupts associated
170 * to the secure peripherals (plus the isolation boundary violation
171 * interrupts)
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200172 *
173 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800174 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200175enum tfm_plat_err_t tfm_spm_hal_nvic_interrupt_enable(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800176
177/**
178 * \brief Get the VTOR value of non-secure image
179 *
180 * \return Returns the address where the vector table of the non-secure image
181 * is located
182 */
183uint32_t tfm_spm_hal_get_ns_VTOR(void);
184
185/**
186 * \brief Get the initial address of non-secure image main stack
187 *
188 * \return Returns the initial non-secure MSP
189 */
190uint32_t tfm_spm_hal_get_ns_MSP(void);
191
192/**
193 * \brief Get the entry point of the non-secure image
194 *
195 * \return Returns the address of the non-secure image entry point
196 */
197uint32_t tfm_spm_hal_get_ns_entry_point(void);
198
Mate Toth-Pal94925722019-06-27 15:10:48 +0200199/**
200 * \brief Set the priority of a secure IRQ
201 *
202 * \param[in] irq_line The IRQ to set the priority for. Might be less than 0
203 * \param[in] priority The priority to set. [0..255]
204 *
205 * \details This function sets the priority for the IRQ passed in the parameter.
206 * The precision of the priority value might be adjusted to match the
207 * available priority bits in the underlying target platform.
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200208 *
209 * \return Returns values as specified by the \ref tfm_plat_err_t
Mate Toth-Pal94925722019-06-27 15:10:48 +0200210 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200211enum tfm_plat_err_t tfm_spm_hal_set_secure_irq_priority(int32_t irq_line,
212 uint32_t priority);
Edison Ai1c266ae2019-03-20 11:21:21 +0800213
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200214/**
215 * \brief Clears a pending IRQ
216 *
217 * \param[in] irq_line The IRQ to clear pending for.
218 */
219void tfm_spm_hal_clear_pending_irq(int32_t irq_line);
220
221/**
222 * \brief Enables an IRQ
223 *
224 * \param[in] irq_line The IRQ to be enabled.
225 */
226void tfm_spm_hal_enable_irq(int32_t irq_line);
227
228/**
229 * \brief Disables an IRQ
230 *
231 * \param[in] irq_line The IRQ to be disabled
232 */
233void tfm_spm_hal_disable_irq(int32_t irq_line);
234
235/**
236 * \brief Set the target state of an IRQ
237 *
238 * \param[in] irq_line The IRQ to set the priority for.
239 * \param[in] target_state Target state to ret for the IRQ.
240 *
241 * \return TFM_IRQ_TARGET_STATE_SECURE if interrupt is assigned
242 * to Secure
243 * TFM_IRQ_TARGET_STATE_NON_SECURE if interrupt is
244 * assigned to Non-Secure
245 */
246enum irq_target_state_t tfm_spm_hal_set_irq_target_state(
247 int32_t irq_line,
248 enum irq_target_state_t target_state);
249
Edison Ai1c266ae2019-03-20 11:21:21 +0800250#endif /* __TFM_SPM_HAL_H__ */