Mistake on this page?
Report an issue in GitHub or email us
tfm_spm.h
1 /*
2  * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 #ifndef __TFM_SPM_H__
8 #define __TFM_SPM_H__
9 
10 #include <stdbool.h>
11 #include "tfm_list.h"
12 #include "tfm_secure_api.h"
13 
14 #ifndef TFM_SPM_MAX_ROT_SERV_NUM
15 #define TFM_SPM_MAX_ROT_SERV_NUM 28
16 #endif
17 #define TFM_VERSION_POLICY_RELAXED 0
18 #define TFM_VERSION_POLICY_STRICT 1
19 
20 #ifndef TFM_CONN_HANDLE_MAX_NUM
21 #define TFM_CONN_HANDLE_MAX_NUM 32
22 #endif
23 
24 /* RoT connection handle list */
26  psa_handle_t handle; /* Handle value */
27  void *rhandle; /* Reverse handle value */
28  struct tfm_list_node_t list; /* list node */
29 };
30 
31 /* Service database defined by manifest */
33  char *name; /* Service name */
34  uint32_t partition_id; /* Partition ID which service belong to */
35  psa_signal_t signal; /* Service signal */
36  uint32_t sid; /* Service identifier */
37  bool non_secure_client; /* If can be called by non secure client */
38  uint32_t minor_version; /* Minor version */
39  uint32_t minor_policy; /* Minor version policy */
40 };
41 
42 /* RoT Service data */
44  struct tfm_spm_service_db_t *service_db; /* Service database pointer */
45  struct tfm_spm_ipc_partition_t *partition; /*
46  * Point to secure partition
47  * data
48  */
49  struct tfm_list_node_t handle_list; /* Service handle list */
50  struct tfm_msg_queue_t msg_queue; /* Message queue */
51  struct tfm_list_node_t list; /* For list operation */
52 };
53 
54 /*
55  * FixMe: This structure is for IPC partition which is different with library
56  * mode partition. There needs to be an alignment for IPC partition database
57  * and library mode database.
58  */
59 /* Secure Partition data */
61  int32_t index; /* Partition index */
62  int32_t id; /* Secure partition ID */
63  struct tfm_event_t signal_evnt; /* Event signal */
64  uint32_t signals; /* Service signals had been triggered*/
65  uint32_t signal_mask; /* Service signal mask passed by psa_wait() */
66  struct tfm_list_node_t service_list;/* Service list */
67 };
68 
69 /*************************** Extended SPM functions **************************/
70 
71 /**
72  * \brief Get the running partition ID.
73  *
74  * \return Returns the partition ID
75  */
76 uint32_t tfm_spm_partition_get_running_partition_id_ext(void);
77 
78 /**
79  * \brief Get the current partition mode.
80  *
81  * \param[in] partition_idx Index of current partition
82  *
83  * \retval TFM_PARTITION_PRIVILEGED_MODE Privileged mode
84  * \retval TFM_PARTITION_UNPRIVILEGED_MODE Unprivileged mode
85  */
86 uint32_t tfm_spm_partition_get_privileged_mode(uint32_t partition_idx);
87 
88 /******************** Service handle management functions ********************/
89 
90 /**
91  * \brief Create connection handle for client connect
92  *
93  * \param[in] service Target service context pointer
94  *
95  * \retval PSA_NULL_HANDLE Create failed \ref PSA_NULL_HANDLE
96  * \retval >0 Service handle created, \ref psa_handle_t
97  */
98 psa_handle_t tfm_spm_create_conn_handle(struct tfm_spm_service_t *service);
99 
100 /**
101  * \brief Free connection handle which not used anymore.
102  *
103  * \param[in] service Target service context pointer
104  * \param[in] conn_handle Connection handle created by
105  * tfm_spm_create_conn_handle(), \ref psa_handle_t
106  *
107  * \retval IPC_SUCCESS Success
108  * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
109  * \retval "Does not return" Panic for not find service by handle
110  */
111 int32_t tfm_spm_free_conn_handle(struct tfm_spm_service_t *service,
112  psa_handle_t conn_handle);
113 
114 /**
115  * \brief Set reverse handle value for connection.
116  *
117  * \param[in] service Target service context pointer
118  * \param[in] conn_handle Connection handle created by
119  * tfm_spm_create_conn_handle(), \ref psa_handle_t
120  * \param[in] rhandle rhandle need to save
121  *
122  * \retval IPC_SUCCESS Success
123  * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
124  * \retval "Does not return" Panic for not find handle node
125  */
126 int32_t tfm_spm_set_rhandle(struct tfm_spm_service_t *service,
127  psa_handle_t conn_handle,
128  void *rhandle);
129 
130 /**
131  * \brief Get reverse handle value from connection hanlde.
132  *
133  * \param[in] service Target service context pointer
134  * \param[in] conn_handle Connection handle created by
135  * tfm_spm_create_conn_handle(), \ref psa_handle_t
136  *
137  * \retval void * Success
138  * \retval "Does not return" Panic for those:
139  * service pointer are NULL
140  * hanlde is \ref PSA_NULL_HANDLE
141  * handle node does not be found
142  */
143 void *tfm_spm_get_rhandle(struct tfm_spm_service_t *service,
144  psa_handle_t conn_handle);
145 
146 /******************** Partition management functions *************************/
147 
148 /**
149  * \brief Get current running partition context.
150  *
151  * \retval NULL Failed
152  * \retval "Not NULL" Return the parttion context pointer
153  * \ref spm_partition_t structures
154  */
155 struct tfm_spm_ipc_partition_t *tfm_spm_get_running_partition(void);
156 
157 /**
158  * \brief Get the service context by signal.
159  *
160  * \param[in] partition Partition context pointer
161  * \ref spm_partition_t structures
162  * \param[in] signal Signal associated with inputs to the Secure
163  * Partition, \ref psa_signal_t
164  *
165  * \retval NULL Failed
166  * \retval "Not NULL" Target service context pointer,
167  * \ref spm_service_t structures
168  */
169 struct tfm_spm_service_t *
170 tfm_spm_get_service_by_signal(struct tfm_spm_ipc_partition_t *partition,
171  psa_signal_t signal);
172 
173 /**
174  * \brief Get the service context by service ID.
175  *
176  * \param[in] sid RoT Service identity
177  *
178  * \retval NULL Failed
179  * \retval "Not NULL" Target service context pointer,
180  * \ref spm_service_t structures
181  */
182 struct tfm_spm_service_t *tfm_spm_get_service_by_sid(uint32_t sid);
183 
184 /**
185  * \brief Get the service context by connection handle.
186  *
187  * \param[in] conn_handle Connection handle created by
188  * tfm_spm_create_conn_handle()
189  *
190  * \retval NULL Failed
191  * \retval "Not NULL" Target service context pointer,
192  * \ref spm_service_t structures
193  */
194 struct tfm_spm_service_t *
195  tfm_spm_get_service_by_handle(psa_handle_t conn_handle);
196 
197 /**
198  * \brief Get the partition context by partition ID.
199  *
200  * \param[in] partition_id Partition identity
201  *
202  * \retval NULL Failed
203  * \retval "Not NULL" Target partition context pointer,
204  * \ref spm_partition_t structures
205  */
207  tfm_spm_get_partition_by_id(int32_t partition_id);
208 
209 /************************ Message functions **********************************/
210 
211 /**
212  * \brief Get message context by message handle.
213  *
214  * \param[in] msg_handle Message handle which is a reference generated
215  * by the SPM to a specific message.
216  *
217  * \return The message body context pointer
218  * \ref msg_body_t structures
219  */
220 struct tfm_msg_body_t *tfm_spm_get_msg_from_handle(psa_handle_t msg_handle);
221 
222 /**
223  * \brief Create a message for PSA client call.
224  *
225  * \param[in] service Target service context pointer, which can be
226  * obtained by partition management functions
227  * \prarm[in] handle Connect handle return by psa_connect(). Should
228  * be \ref PSA_NULL_HANDLE in psa_connect().
229  * \param[in] type Message type, PSA_IPC_CONNECT, PSA_IPC_CALL or
230  * PSA_IPC_DISCONNECT
231  * \param[in] ns_caller Whether from NS caller
232  * \param[in] invec Array of input \ref psa_invec structures
233  * \param[in] in_len Number of input \ref psa_invec structures
234  * \param[in] outvec Array of output \ref psa_outvec structures
235  * \param[in] out_len Number of output \ref psa_outvec structures
236  * \param[in] caller_outvec Array of caller output \ref psa_outvec structures
237  *
238  * \retval NULL Failed
239  * \retval "Not NULL" New message body pointer \ref msg_body_t structures
240  */
241 struct tfm_msg_body_t *tfm_spm_create_msg(struct tfm_spm_service_t *service,
242  psa_handle_t handle,
243  uint32_t type, int32_t ns_caller,
244  psa_invec *invec, size_t in_len,
245  psa_outvec *outvec, size_t out_len,
246  psa_outvec *caller_outvec);
247 
248 /**
249  * \brief Free message which unused anymore
250  *
251  * \param[in] msg Message pointer which want to free
252  * \ref msg_body_t structures
253  *
254  * \retval void Success
255  * \retval "Does not return" Failed
256  */
257 void tfm_spm_free_msg(struct tfm_msg_body_t *msg);
258 
259 /**
260  * \brief Send message and wake up the SP who is waiting on
261  * message queue, block the current thread and
262  * scheduler triggered
263  *
264  * \param[in] service Target service context pointer, which can be
265  * obtained by partition management functions
266  * \param[in] msg message created by spm_create_msg()
267  * \ref msg_body_t structures
268  *
269  * \retval IPC_SUCCESS Success
270  * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
271  * \retval IPC_ERROR_GENERIC Failed to enqueue message to service message queue
272  */
273 int32_t tfm_spm_send_event(struct tfm_spm_service_t *service,
274  struct tfm_msg_body_t *msg);
275 
276 /**
277  * \brief Check the client minor version according to
278  * version policy
279  *
280  * \param[in] service Target service context pointer, which can be get
281  * by partition management functions
282  * \param[in] minor_version Client support minor version
283  *
284  * \retval IPC_SUCCESS Success
285  * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
286  * \retval IPC_ERROR_VERSION Check failed
287  */
288 int32_t tfm_spm_check_client_version(struct tfm_spm_service_t *service,
289  uint32_t minor_version);
290 
291 /**
292  * \brief Check the memory reference is valid.
293  *
294  * \param[in] buffer Pointer of memory reference
295  * \param[in] len Length of memory reference in bytes
296  * \param[in] ns_caller From non-secure caller
297  * \param[in] access Type of access specified by the
298  * \ref tfm_memory_access_e
299  * \param[in] privileged Privileged mode or unprivileged mode:
300  * \ref TFM_PARTITION_UNPRIVILEGED_MODE
301  * \ref TFM_PARTITION_PRIVILEGED_MODE
302  *
303  * \retval IPC_SUCCESS Success
304  * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
305  * \retval IPC_ERROR_MEMORY_CHECK Check failed
306  */
307 int32_t tfm_memory_check(void *buffer, size_t len, int32_t ns_caller,
308  enum tfm_memory_access_e access,
309  uint32_t privileged);
310 
311 /* This function should be called before schedule function */
312 void tfm_spm_init(void);
313 
314 /*
315  * PendSV specified function.
316  *
317  * Parameters :
318  * ctxb - State context storage pointer
319  *
320  * Notes:
321  * This is a staging API. Scheduler should be called in SPM finally and
322  * this function will be obsoleted later.
323  */
324 void tfm_pendsv_do_schedule(struct tfm_state_context_ext *ctxb);
325 
326 #endif
Structure which describes a scatter-gather output buffer.
Definition: client.h:54
Structure that describes a scatter-gather input buffer.
Definition: client.h:48
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.