blob: 38f22ff4be9803b63c5eba5ce98c8bc740825062 [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/**
70 * \brief This function initialises the HW used for isolation, and sets the
71 * default configuration for them.
72 *
73 * This function is called during TF-M core early startup, before DB init
Mate Toth-Palb9c33552019-07-10 16:13:20 +020074 *
75 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +080076 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +020077enum tfm_plat_err_t tfm_spm_hal_init_isolation_hw(void);
Edison Ai1c266ae2019-03-20 11:21:21 +080078
Edison Aic1b10902019-08-26 10:34:19 +080079#if TFM_LVL != 1
Edison Ai1c266ae2019-03-20 11:21:21 +080080/**
81 * \brief This function initialises the HW used for isolation, and sets the
82 * default configuration for them.
83 * This function is called during TF-M core early startup, after DB init
Mate Toth-Palb9c33552019-07-10 16:13:20 +020084 *
85 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +080086 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +020087enum tfm_plat_err_t tfm_spm_hal_setup_isolation_hw(void);
Edison Aic1b10902019-08-26 10:34:19 +080088#endif
Edison Ai1c266ae2019-03-20 11:21:21 +080089
90/**
91 * \brief Configure peripherals for a partition based on the platfotm data from
92 * the DB
93 *
94 * This function is called during partition initialisation (before calling the
95 * init function for the partition)
96 *
97 * \param[in] platform_data The platform fields of the partition DB record to
98 * be used for configuration. Can be NULL.
99 */
100void tfm_spm_hal_configure_default_isolation(
101 const struct tfm_spm_partition_platform_data_t *platform_data);
102/**
103 * \brief Configures the system debug properties.
104 * The default configuration of this function should disable secure debug
105 * when either DAUTH_NONE or DAUTH_NS_ONLY define is set. It is up to the
106 * platform owner to decide if secure debug can be turned on in their
107 * system, if DAUTH_FULL define is present.
108 * The DAUTH_CHIP_DEFAULT define should not be considered a safe default
109 * option unless explicitly noted by the chip vendor.
110 * The implementation has to expect that one of those defines is going to
111 * be set. Otherwise, a compile error needs to be triggered.
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200112 *
113 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800114 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200115enum tfm_plat_err_t tfm_spm_hal_init_debug(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800116
117/**
Mate Toth-Pal3e2ebd02019-05-07 14:22:16 +0200118 * \brief Enables the fault handlers and sets priorities.
119 *
120 * Secure fault (if present) must have the highest possible priority
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200121 *
122 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800123 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200124enum tfm_plat_err_t tfm_spm_hal_enable_fault_handlers(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800125
126/**
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100127 * \brief Configures the system reset request properties
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200128 *
129 * \return Returns values as specified by the \ref tfm_plat_err_t
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100130 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200131enum tfm_plat_err_t tfm_spm_hal_system_reset_cfg(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800132
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100133/**
Edison Ai1c266ae2019-03-20 11:21:21 +0800134 * \brief Configures all external interrupts to target the
135 * NS state, apart for the ones associated to secure
136 * peripherals (plus MPC and PPC)
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200137 *
138 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800139 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200140enum tfm_plat_err_t tfm_spm_hal_nvic_interrupt_target_state_cfg(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800141
142/**
143 * \brief This function enable the interrupts associated
144 * to the secure peripherals (plus the isolation boundary violation
145 * interrupts)
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200146 *
147 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800148 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200149enum tfm_plat_err_t tfm_spm_hal_nvic_interrupt_enable(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800150
151/**
152 * \brief Get the VTOR value of non-secure image
153 *
154 * \return Returns the address where the vector table of the non-secure image
155 * is located
156 */
157uint32_t tfm_spm_hal_get_ns_VTOR(void);
158
159/**
160 * \brief Get the initial address of non-secure image main stack
161 *
162 * \return Returns the initial non-secure MSP
163 */
164uint32_t tfm_spm_hal_get_ns_MSP(void);
165
166/**
167 * \brief Get the entry point of the non-secure image
168 *
169 * \return Returns the address of the non-secure image entry point
170 */
171uint32_t tfm_spm_hal_get_ns_entry_point(void);
172
Mate Toth-Pal94925722019-06-27 15:10:48 +0200173/**
174 * \brief Set the priority of a secure IRQ
175 *
176 * \param[in] irq_line The IRQ to set the priority for. Might be less than 0
177 * \param[in] priority The priority to set. [0..255]
178 *
179 * \details This function sets the priority for the IRQ passed in the parameter.
180 * The precision of the priority value might be adjusted to match the
181 * available priority bits in the underlying target platform.
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200182 *
183 * \return Returns values as specified by the \ref tfm_plat_err_t
Mate Toth-Pal94925722019-06-27 15:10:48 +0200184 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200185enum tfm_plat_err_t tfm_spm_hal_set_secure_irq_priority(int32_t irq_line,
186 uint32_t priority);
Edison Ai1c266ae2019-03-20 11:21:21 +0800187
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200188/**
189 * \brief Clears a pending IRQ
190 *
191 * \param[in] irq_line The IRQ to clear pending for.
192 */
193void tfm_spm_hal_clear_pending_irq(int32_t irq_line);
194
195/**
196 * \brief Enables an IRQ
197 *
198 * \param[in] irq_line The IRQ to be enabled.
199 */
200void tfm_spm_hal_enable_irq(int32_t irq_line);
201
202/**
203 * \brief Disables an IRQ
204 *
205 * \param[in] irq_line The IRQ to be disabled
206 */
207void tfm_spm_hal_disable_irq(int32_t irq_line);
208
209/**
210 * \brief Set the target state of an IRQ
211 *
212 * \param[in] irq_line The IRQ to set the priority for.
213 * \param[in] target_state Target state to ret for the IRQ.
214 *
215 * \return TFM_IRQ_TARGET_STATE_SECURE if interrupt is assigned
216 * to Secure
217 * TFM_IRQ_TARGET_STATE_NON_SECURE if interrupt is
218 * assigned to Non-Secure
219 */
220enum irq_target_state_t tfm_spm_hal_set_irq_target_state(
221 int32_t irq_line,
222 enum irq_target_state_t target_state);
223
Edison Ai1c266ae2019-03-20 11:21:21 +0800224#endif /* __TFM_SPM_HAL_H__ */