blob: 509f153d650d9e1a05de6bff30836487e42d6bda [file] [log] [blame]
Edison Ai1c266ae2019-03-20 11:21:21 +08001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
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
31#if TFM_LVL != 1
32/**
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};
61#endif
62
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/**
104 * \brief Enables the fault handlers
105 */
106void enable_fault_handlers(void);
107
108/**
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100109 * \brief Configures the system reset request properties
110 */
111void system_reset_cfg(void);
Edison Ai1c266ae2019-03-20 11:21:21 +0800112
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100113/**
Edison Ai1c266ae2019-03-20 11:21:21 +0800114 * \brief Configures all external interrupts to target the
115 * NS state, apart for the ones associated to secure
116 * peripherals (plus MPC and PPC)
117 */
118void nvic_interrupt_target_state_cfg(void);
119
120/**
121 * \brief This function enable the interrupts associated
122 * to the secure peripherals (plus the isolation boundary violation
123 * interrupts)
124 */
125void nvic_interrupt_enable(void);
126
127/**
128 * \brief Get the VTOR value of non-secure image
129 *
130 * \return Returns the address where the vector table of the non-secure image
131 * is located
132 */
133uint32_t tfm_spm_hal_get_ns_VTOR(void);
134
135/**
136 * \brief Get the initial address of non-secure image main stack
137 *
138 * \return Returns the initial non-secure MSP
139 */
140uint32_t tfm_spm_hal_get_ns_MSP(void);
141
142/**
143 * \brief Get the entry point of the non-secure image
144 *
145 * \return Returns the address of the non-secure image entry point
146 */
147uint32_t tfm_spm_hal_get_ns_entry_point(void);
148
149
150#if TFM_LVL != 1
151/**
152 * \brief Configure the sandbox for a partition.
153 *
154 * \param[in] memory_data The memory ranges from the partition DB for this
155 * partition
156 * \param[in] platform_data The platform fields of the partition DB record
157 * for this partition. Can be NULL.
158 *
159 * \return Returns the result operation as per \ref spm_err_t
160 */
161enum spm_err_t tfm_spm_hal_partition_sandbox_config(
162 const struct tfm_spm_partition_memory_data_t *memory_data,
163 const struct tfm_spm_partition_platform_data_t *platform_data);
164
165/**
166 * \brief Deconfigure the sandbox for a partition.
167 *
168 * \param[in] memory_data The memory ranges from the partition DB for this
169 * partition
170 * \param[in] platform_data The platform fields of the partition DB record
171 * for this partition. Can be NULL.
172 *
173 * \return Returns the result operation as per \ref spm_err_t
174 */
175enum spm_err_t tfm_spm_hal_partition_sandbox_deconfig(
176 const struct tfm_spm_partition_memory_data_t *memory_data,
177 const struct tfm_spm_partition_platform_data_t *platform_data);
178
179/**
180 * \brief Set the share region mode
181 *
182 * \param[in] share The mode to set
183 *
184 * \return Returns the result operation as per \ref spm_err_t
185 */
186enum spm_err_t tfm_spm_hal_set_share_region(
187 enum tfm_buffer_share_region_e share);
188#endif
189
190#endif /* __TFM_SPM_HAL_H__ */