blob: 3458b171856105674ad6bbb88017495d973d02f4 [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"
14
15/**
16 * \brief Holds peripheral specific data fields required to manage the
17 * peripherals isolation
18 *
19 * This structure has to be defined in the platform directory, and may have
20 * different definition for each platform. The structure should contain fields
21 * that describe the peripheral for the functions that are prototyped in this
22 * file and are responsible for configuring the isolation of the peripherals.
23 *
24 * Pointers to structures of this type are managed by the SPM, and passed to the
25 * necessary function on isolation request. The pointers are also defined by the
26 * platform in the header file tfm_peripherals_def.h. For details on this, see
27 * the documentation of that file.
28 */
29struct tfm_spm_partition_platform_data_t;
30
Miklos Balintdd02bb32019-05-26 21:13:12 +020031#if defined (TFM_PSA_API) || (TFM_LVL != 1)
Edison Ai1c266ae2019-03-20 11:21:21 +080032/**
33 * \brief Holds SPM db fields that define the memory regions used by a
34 * partition.
35 */
36struct tfm_spm_partition_memory_data_t
37{
38 uint32_t code_start; /*!< Start of the code memory of this partition. */
39 uint32_t code_limit; /*!< Address of the byte beyond the end of the code
40 * memory of this partition.
41 */
42 uint32_t ro_start; /*!< Start of the read only memory of this
43 * partition.
44 */
45 uint32_t ro_limit; /*!< Address of the byte beyond the end of the read
46 * only memory of this partition.
47 */
48 uint32_t rw_start; /*!< Start of the data region of this partition. */
49 uint32_t rw_limit; /*!< Address of the byte beyond the end of the data
50 * region of this partition.
51 */
52 uint32_t zi_start; /*!< Start of the zero initialised data region of
53 * this partition.
54 */
55 uint32_t zi_limit; /*!< Address of the byte beyond the end of the zero
56 * initialised region of this partition.
57 */
58 uint32_t stack_bottom; /*!< The bottom of the stack for the partition. */
59 uint32_t stack_top; /*!< The top of the stack for the partition. */
60};
Miklos Balintdd02bb32019-05-26 21:13:12 +020061#endif
Edison Ai1c266ae2019-03-20 11:21:21 +080062
63/**
64 * \brief This function initialises the HW used for isolation, and sets the
65 * default configuration for them.
66 *
67 * This function is called during TF-M core early startup, before DB init
68 */
69void tfm_spm_hal_init_isolation_hw(void);
70
71/**
72 * \brief This function initialises the HW used for isolation, and sets the
73 * default configuration for them.
74 * This function is called during TF-M core early startup, after DB init
75 */
76void tfm_spm_hal_setup_isolation_hw(void);
77
78/**
79 * \brief Configure peripherals for a partition based on the platfotm data from
80 * the DB
81 *
82 * This function is called during partition initialisation (before calling the
83 * init function for the partition)
84 *
85 * \param[in] platform_data The platform fields of the partition DB record to
86 * be used for configuration. Can be NULL.
87 */
88void tfm_spm_hal_configure_default_isolation(
89 const struct tfm_spm_partition_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 */
101void tfm_spm_hal_init_debug(void);
102
103/**
Mate Toth-Pal3e2ebd02019-05-07 14:22:16 +0200104 * \brief Enables the fault handlers and sets priorities.
105 *
106 * Secure fault (if present) must have the highest possible priority
Edison Ai1c266ae2019-03-20 11:21:21 +0800107 */
108void enable_fault_handlers(void);
109
110/**
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100111 * \brief Configures the system reset request properties
112 */
113void system_reset_cfg(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800114
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100115/**
Edison Ai1c266ae2019-03-20 11:21:21 +0800116 * \brief Configures all external interrupts to target the
117 * NS state, apart for the ones associated to secure
118 * peripherals (plus MPC and PPC)
119 */
120void nvic_interrupt_target_state_cfg(void);
121
122/**
123 * \brief This function enable the interrupts associated
124 * to the secure peripherals (plus the isolation boundary violation
125 * interrupts)
126 */
127void nvic_interrupt_enable(void);
128
129/**
130 * \brief Get the VTOR value of non-secure image
131 *
132 * \return Returns the address where the vector table of the non-secure image
133 * is located
134 */
135uint32_t tfm_spm_hal_get_ns_VTOR(void);
136
137/**
138 * \brief Get the initial address of non-secure image main stack
139 *
140 * \return Returns the initial non-secure MSP
141 */
142uint32_t tfm_spm_hal_get_ns_MSP(void);
143
144/**
145 * \brief Get the entry point of the non-secure image
146 *
147 * \return Returns the address of the non-secure image entry point
148 */
149uint32_t tfm_spm_hal_get_ns_entry_point(void);
150
Mate Toth-Pal94925722019-06-27 15:10:48 +0200151/**
152 * \brief Set the priority of a secure IRQ
153 *
154 * \param[in] irq_line The IRQ to set the priority for. Might be less than 0
155 * \param[in] priority The priority to set. [0..255]
156 *
157 * \details This function sets the priority for the IRQ passed in the parameter.
158 * The precision of the priority value might be adjusted to match the
159 * available priority bits in the underlying target platform.
160 */
161void tfm_spm_hal_set_secure_irq_priority(int32_t irq_line, uint32_t priority);
Edison Ai1c266ae2019-03-20 11:21:21 +0800162
Miklos Balintdd02bb32019-05-26 21:13:12 +0200163#if (TFM_LVL != 1) && !defined(TFM_PSA_API)
Edison Ai1c266ae2019-03-20 11:21:21 +0800164/**
165 * \brief Configure the sandbox for a partition.
166 *
167 * \param[in] memory_data The memory ranges from the partition DB for this
168 * partition
169 * \param[in] platform_data The platform fields of the partition DB record
170 * for this partition. Can be NULL.
171 *
172 * \return Returns the result operation as per \ref spm_err_t
173 */
174enum spm_err_t tfm_spm_hal_partition_sandbox_config(
175 const struct tfm_spm_partition_memory_data_t *memory_data,
176 const struct tfm_spm_partition_platform_data_t *platform_data);
177
178/**
179 * \brief Deconfigure the sandbox for a partition.
180 *
181 * \param[in] memory_data The memory ranges from the partition DB for this
182 * partition
183 * \param[in] platform_data The platform fields of the partition DB record
184 * for this partition. Can be NULL.
185 *
186 * \return Returns the result operation as per \ref spm_err_t
187 */
188enum spm_err_t tfm_spm_hal_partition_sandbox_deconfig(
189 const struct tfm_spm_partition_memory_data_t *memory_data,
190 const struct tfm_spm_partition_platform_data_t *platform_data);
191
192/**
193 * \brief Set the share region mode
194 *
195 * \param[in] share The mode to set
196 *
197 * \return Returns the result operation as per \ref spm_err_t
198 */
199enum spm_err_t tfm_spm_hal_set_share_region(
200 enum tfm_buffer_share_region_e share);
201#endif
202
203#endif /* __TFM_SPM_HAL_H__ */