blob: b6820f5d93892e7fb16f6568cda59c111af16d6f [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
79/**
80 * \brief This function initialises the HW used for isolation, and sets the
81 * default configuration for them.
82 * This function is called during TF-M core early startup, after DB init
Mate Toth-Palb9c33552019-07-10 16:13:20 +020083 *
84 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +080085 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +020086enum tfm_plat_err_t tfm_spm_hal_setup_isolation_hw(void);
Edison Ai1c266ae2019-03-20 11:21:21 +080087
88/**
89 * \brief Configure peripherals for a partition based on the platfotm data from
90 * the DB
91 *
92 * This function is called during partition initialisation (before calling the
93 * init function for the partition)
94 *
95 * \param[in] platform_data The platform fields of the partition DB record to
96 * be used for configuration. Can be NULL.
97 */
98void tfm_spm_hal_configure_default_isolation(
99 const struct tfm_spm_partition_platform_data_t *platform_data);
100/**
101 * \brief Configures the system debug properties.
102 * The default configuration of this function should disable secure debug
103 * when either DAUTH_NONE or DAUTH_NS_ONLY define is set. It is up to the
104 * platform owner to decide if secure debug can be turned on in their
105 * system, if DAUTH_FULL define is present.
106 * The DAUTH_CHIP_DEFAULT define should not be considered a safe default
107 * option unless explicitly noted by the chip vendor.
108 * The implementation has to expect that one of those defines is going to
109 * be set. Otherwise, a compile error needs to be triggered.
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_init_debug(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800114
115/**
Mate Toth-Pal3e2ebd02019-05-07 14:22:16 +0200116 * \brief Enables the fault handlers and sets priorities.
117 *
118 * Secure fault (if present) must have the highest possible priority
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_enable_fault_handlers(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800123
124/**
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100125 * \brief Configures the system reset request properties
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200126 *
127 * \return Returns values as specified by the \ref tfm_plat_err_t
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100128 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200129enum tfm_plat_err_t tfm_spm_hal_system_reset_cfg(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800130
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100131/**
Edison Ai1c266ae2019-03-20 11:21:21 +0800132 * \brief Configures all external interrupts to target the
133 * NS state, apart for the ones associated to secure
134 * peripherals (plus MPC and PPC)
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200135 *
136 * \return Returns values as specified by the \ref tfm_plat_err_t
Edison Ai1c266ae2019-03-20 11:21:21 +0800137 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200138enum tfm_plat_err_t tfm_spm_hal_nvic_interrupt_target_state_cfg(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800139
140/**
141 * \brief This function enable the interrupts associated
142 * to the secure peripherals (plus the isolation boundary violation
143 * interrupts)
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_enable(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800148
149/**
150 * \brief Get the VTOR value of non-secure image
151 *
152 * \return Returns the address where the vector table of the non-secure image
153 * is located
154 */
155uint32_t tfm_spm_hal_get_ns_VTOR(void);
156
157/**
158 * \brief Get the initial address of non-secure image main stack
159 *
160 * \return Returns the initial non-secure MSP
161 */
162uint32_t tfm_spm_hal_get_ns_MSP(void);
163
164/**
165 * \brief Get the entry point of the non-secure image
166 *
167 * \return Returns the address of the non-secure image entry point
168 */
169uint32_t tfm_spm_hal_get_ns_entry_point(void);
170
Mate Toth-Pal94925722019-06-27 15:10:48 +0200171/**
172 * \brief Set the priority of a secure IRQ
173 *
174 * \param[in] irq_line The IRQ to set the priority for. Might be less than 0
175 * \param[in] priority The priority to set. [0..255]
176 *
177 * \details This function sets the priority for the IRQ passed in the parameter.
178 * The precision of the priority value might be adjusted to match the
179 * available priority bits in the underlying target platform.
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200180 *
181 * \return Returns values as specified by the \ref tfm_plat_err_t
Mate Toth-Pal94925722019-06-27 15:10:48 +0200182 */
Mate Toth-Palb9c33552019-07-10 16:13:20 +0200183enum tfm_plat_err_t tfm_spm_hal_set_secure_irq_priority(int32_t irq_line,
184 uint32_t priority);
Edison Ai1c266ae2019-03-20 11:21:21 +0800185
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200186/**
187 * \brief Clears a pending IRQ
188 *
189 * \param[in] irq_line The IRQ to clear pending for.
190 */
191void tfm_spm_hal_clear_pending_irq(int32_t irq_line);
192
193/**
194 * \brief Enables an IRQ
195 *
196 * \param[in] irq_line The IRQ to be enabled.
197 */
198void tfm_spm_hal_enable_irq(int32_t irq_line);
199
200/**
201 * \brief Disables an IRQ
202 *
203 * \param[in] irq_line The IRQ to be disabled
204 */
205void tfm_spm_hal_disable_irq(int32_t irq_line);
206
207/**
208 * \brief Set the target state of an IRQ
209 *
210 * \param[in] irq_line The IRQ to set the priority for.
211 * \param[in] target_state Target state to ret for the IRQ.
212 *
213 * \return TFM_IRQ_TARGET_STATE_SECURE if interrupt is assigned
214 * to Secure
215 * TFM_IRQ_TARGET_STATE_NON_SECURE if interrupt is
216 * assigned to Non-Secure
217 */
218enum irq_target_state_t tfm_spm_hal_set_irq_target_state(
219 int32_t irq_line,
220 enum irq_target_state_t target_state);
221
Edison Ai1c266ae2019-03-20 11:21:21 +0800222#endif /* __TFM_SPM_HAL_H__ */