blob: 92263f7a014947995e7102b9efea11acc02f1912 [file] [log] [blame]
Miklos Balint386b8b52017-11-29 13:12:32 +00001/*
Mate Toth-Pal65291f32018-02-23 14:35:22 +01002 * Copyright (c) 2017-2018, Arm Limited. All rights reserved.
Miklos Balint386b8b52017-11-29 13:12:32 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef __SPM_API_H__
9#define __SPM_API_H__
10
11/* This file contains the apis exported by the SPM to tfm core */
12#include "service_defs.h"
13#include "secure_fw/core/tfm_secure_api.h"
14
15enum spm_err_t {
16 SPM_ERR_OK = 0,
17 SPM_ERR_SERV_DB_NOT_INIT,
18 SPM_ERR_SERV_ALREADY_ACTIVE,
19 SPM_ERR_SERV_NOT_AVAILABLE,
20 SPM_ERR_INVALID_CONFIG,
21};
22
Mate Toth-Pal65291f32018-02-23 14:35:22 +010023enum spm_part_state_t {
24 SPM_PART_STATE_UNINIT = 0,
25 SPM_PART_STATE_IDLE,
26 SPM_PART_STATE_RUNNING,
27 SPM_PART_STATE_SUSPENDED,
28 SPM_PART_STATE_BLOCKED,
29 SPM_PART_STATE_CLOSED,
30};
31
Miklos Balint386b8b52017-11-29 13:12:32 +000032/**
33 * \brief Configure isolated sandbox for a service
34 *
35 * \param[in] service_id Service id
36 *
37 * \return Error code \ref spm_err_t
38 *
39 * \note This function doesn't check if service_id is valid.
40 */
41enum spm_err_t tfm_spm_service_sandbox_config(uint32_t service_id);
42
43/**
44 * \brief Deconfigure sandbox for a service
45 *
46 * \param[in] service_id Service id
47 *
48 * \return Error code \ref spm_err_t
49 *
50 * \note This function doesn't check if service_id is valid.
51 */
52enum spm_err_t tfm_spm_service_sandbox_deconfig(uint32_t service_id);
53
54/**
55 * \brief Get saved stack pointer for a partition
56 *
57 * \param[in] service_id Service id
58 *
59 * \return Stack pointer value
60 *
61 * \note This function doesn't check if service_id is valid.
62 */
63uint32_t tfm_spm_service_get_stack(uint32_t service_id);
64
65/**
66 * \brief Get bottom of stack region for a service
67 *
68 * \param[in] service_id Service id
69 *
70 * \return Stack region bottom value
71 *
72 * \note This function doesn't check if service_id is valid.
73 */
74uint32_t tfm_spm_service_get_stack_bottom(uint32_t service_id);
75
76/**
77 * \brief Get top of stack region for a service
78 *
79 * \param[in] service_id Service id
80 *
81 * \return Stack region top value
82 *
83 * \note This function doesn't check if service_id is valid.
84 */
85uint32_t tfm_spm_service_get_stack_top(uint32_t service_id);
86
87/**
Mate Toth-Pal65291f32018-02-23 14:35:22 +010088 * \brief Get the current state of a service
89 *
90 * \param[in] service_id Service id
91 *
92 * \return The state of the specified service
93 *
94 * \note This function doesn't check if service_id is valid.
95 * \note The returned value has the value set of \ref spm_part_state_t.
96 */
97uint32_t tfm_spm_service_get_state(uint32_t service_id);
98
99/**
100 * \brief Get the Id of the caller of the service given
101 *
102 * \param[in] service_id Service id to get the caller of
103 *
104 * \return The Id of the caller service
105 *
106 * \note This function doesn't check if service_id is valid.
107 */
108uint32_t tfm_spm_service_get_caller_service_id(uint32_t service_id);
109
110/**
111 * \brief Get the original PSP of the service
112 *
113 * \param[in] service_id Service id
114 *
115 * \return The original PSP of the service
116 *
117 * \note This function doesn't check if service_id is valid.
118 */
119uint32_t tfm_spm_service_get_orig_psp(uint32_t service_id);
120
121/**
122 * \brief Get the original PSP limit of the service
123 *
124 * \param[in] service_id Service id
125 *
126 * \return The original PSP limit of the service
127 *
128 * \note This function doesn't check if service_id is valid.
129 */
130uint32_t tfm_spm_service_get_orig_psplim(uint32_t service_id);
131
132/**
133 * \brief Get the original link register value of the service
134 *
135 * \param[in] service_id Service id
136 *
137 * \return The original link register value of the service
138 *
139 * \note This function doesn't check if service_id is valid.
140 */
141uint32_t tfm_spm_service_get_orig_lr(uint32_t service_id);
142
143/**
144 * \brief Get the buffer share region of the service
145 *
146 * \param[in] service_id Service id
147 *
148 * \return The buffer share region of the service
149 *
150 * \note This function doesn't check if service_id is valid.
151 * \note The returned value has the value set of \ref tfm_buffer_share_region_e
152 */
153uint32_t tfm_spm_service_get_share(uint32_t service_id);
154
155/**
156 * \brief Returns the id of the service that has running state
157 *
158 * \return The Id of the service with the running state, if there is any set.
159 * 0 otherwise.
160 */
161uint32_t tfm_spm_service_get_running_service_id(void);
162
163/**
Miklos Balint386b8b52017-11-29 13:12:32 +0000164 * \brief Save stack pointer for service in database
165 *
166 * \param[in] service_id Service id
167 * \param[in] stack_ptr Stack pointer to be stored
168 *
169 * \note This function doesn't check if service_id is valid.
170 */
171void tfm_spm_service_set_stack(uint32_t service_id, uint32_t stack_ptr);
172
173/**
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100174 * \brief Set the current state of a service
175 *
176 * \param[in] service_id Service id
177 * \param[in] state The state to be set
178 *
179 * \note This function doesn't check if service_id is valid.
180 * \note The \ref state has to have the value set of \ref spm_part_state_t.
181 */
182void tfm_spm_service_set_state(uint32_t service_id, uint32_t state);
183
184/**
185 * \brief Set the caller service Id for a given service
186 *
187 * \param[in] service_id Service id
188 * \param[in] caller_service_id The Id of the caller service
189 *
190 * \note This function doesn't check if any of the service_ids is valid.
191 */
192void tfm_spm_service_set_caller_service_id(uint32_t service_id,
193 uint32_t caller_service_id);
194
195/**
196 * \brief Set the original PSP value of a service
197 *
198 * \param[in] service_id Service id
199 * \param[in] orig_psp The PSP value to set
200 *
201 * \note This function doesn't check if service_id is valid.
202 */
203void tfm_spm_service_set_orig_psp(uint32_t service_id, uint32_t orig_psp);
204
205/**
206 * \brief Set the original PSP limit value of a service
207 *
208 * \param[in] service_id Service id
209 * \param[in] orig_psplim The PSP limit value to set
210 *
211 * \note This function doesn't check if service_id is valid.
212 */
213void tfm_spm_service_set_orig_psplim(uint32_t service_id, uint32_t orig_psplim);
214
215/**
216 * \brief Set the original link register value of a service
217 *
218 * \param[in] service_id Service id
219 * \param[in] orig_lr The link register value to set
220 *
221 * \note This function doesn't check if service_id is valid.
222 */
223void tfm_spm_service_set_orig_lr(uint32_t service_id, uint32_t orig_lr);
224
225/**
226 * \brief Set the buffer share region of the service
227 *
228 * \param[in] service_id Service id
229 * \param[in] share The buffer share region to be set
230 *
231 * \return Error code \ref spm_err_t
232 *
233 * \note This function doesn't check if service_id is valid.
234 * \note share has to have the value set of \ref tfm_buffer_share_region_e
235 */
236enum spm_err_t tfm_spm_service_set_share(uint32_t service_id, uint32_t share);
237
238/**
Miklos Balint386b8b52017-11-29 13:12:32 +0000239 * \brief Initialize service database
240 *
241 * \return Error code \ref spm_err_t
242 */
243enum spm_err_t tfm_spm_db_init(void);
244
245/**
246 * \brief Apply default MPU configuration for execution
247 *
248 * \return Error code \ref spm_err_t
249 */
250enum spm_err_t tfm_spm_mpu_init(void);
251
252/**
253 * \brief Execute service init function
254 *
255 * \return Error code \ref spm_err_t
256 */
257enum spm_err_t tfm_spm_service_init(void);
258
259/**
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100260 * \brief Clears the context info from the database for a service.
Miklos Balint386b8b52017-11-29 13:12:32 +0000261 *
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100262 * \param[in] service_id Service id
Miklos Balint386b8b52017-11-29 13:12:32 +0000263 *
264 * \note This function doesn't check if service_id is valid.
265 */
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100266void tfm_spm_service_cleanup_context(uint32_t service_id);
Miklos Balint386b8b52017-11-29 13:12:32 +0000267
268#endif /*__SPM_API_H__ */