blob: cbcb918cb2657375a3b69dd143b5d77e5a488e6d [file] [log] [blame]
Valerio Setti4f4ade92024-05-03 17:28:04 +02001/* PSA Firmware Framework service header for psasim. */
2
3/*
4 * Copyright The Mbed TLS Contributors
5 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
6 */
7
8#ifndef __PSA_SERVICE_H__
9#define __PSA_SERVICE_H__
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14#include <stdlib.h>
15#include <stdint.h>
16#include <stddef.h>
17
Valerio Setti66fb1c12024-05-10 06:51:16 +020018#include "common.h"
Valerio Setti4f4ade92024-05-03 17:28:04 +020019
Valerio Setti655b9792024-05-09 12:20:40 +020020#include "psa/crypto.h"
21
Valerio Setti4f4ade92024-05-03 17:28:04 +020022/********************** PSA Secure Partition Macros and Types ****************/
23
24/* PSA wait timeouts */
25#define PSA_POLL (0x00000000u)
26#define PSA_BLOCK (0x80000000u)
27
28/* A mask value that includes all Secure Partition signals */
29#define PSA_WAIT_ANY (~0u)
30
31/* Doorbell signal */
32#define PSA_DOORBELL (0x00000008u)
33
34/* PSA message types */
35#define PSA_IPC_CONNECT (-1)
36#define PSA_IPC_DISCONNECT (-2)
37
38/* Return code from psa_get() */
39#define PSA_ERR_NOMSG (INT32_MIN + 3)
40
41/* Store a set of one or more Secure Partition signals */
42typedef uint32_t psa_signal_t;
43
44/**
45 * Describe a message received by an RoT Service after calling \ref psa_get().
46 */
47typedef struct psa_msg_t {
48 uint32_t type; /* One of the following values:
49 * \ref PSA_IPC_CONNECT
50 * \ref PSA_IPC_CALL
51 * \ref PSA_IPC_DISCONNECT
52 */
53 psa_handle_t handle; /* A reference generated by the SPM to the
54 * message returned by psa_get().
55 */
56 int32_t client_id; /* Partition ID of the sender of the message */
57 void *rhandle; /* Be useful for binding a connection to some
58 * application-specific data or function
59 * pointer within the RoT Service
60 * implementation.
61 */
62 size_t in_size[PSA_MAX_IOVEC]; /* Provide the size of each client input
63 * vector in bytes.
64 */
65 size_t out_size[PSA_MAX_IOVEC];/* Provide the size of each client output
66 * vector in bytes.
67 */
68} psa_msg_t;
69
70/************************* PSA Secure Partition API **************************/
71
72/**
73 * \brief Return the Secure Partition interrupt signals that have been asserted
74 * from a subset of signals provided by the caller.
75 *
76 * \param[in] signal_mask A set of signals to query. Signals that are not
77 * in this set will be ignored.
78 * \param[in] timeout Specify either blocking \ref PSA_BLOCK or
79 * polling \ref PSA_POLL operation.
80 *
81 * \retval >0 At least one signal is asserted.
82 * \retval 0 No signals are asserted. This is only seen when
83 * a polling timeout is used.
84 */
85psa_signal_t psa_wait(psa_signal_t signal_mask, uint32_t timeout);
86
87/**
88 * \brief Retrieve the message which corresponds to a given RoT Service signal
89 * and remove the message from the RoT Service queue.
90 *
91 * \param[in] signal The signal value for an asserted RoT Service.
92 * \param[out] msg Pointer to \ref psa_msg_t object for receiving
93 * the message.
94 *
95 * \retval PSA_SUCCESS Success, *msg will contain the delivered
96 * message.
97 * \retval PSA_ERR_NOMSG Message could not be delivered.
98 * \retval "Does not return" The call is invalid because one or more of the
99 * following are true:
100 * \arg signal has more than a single bit set.
101 * \arg signal does not correspond to an RoT Service.
102 * \arg The RoT Service signal is not currently
103 * asserted.
104 * \arg The msg pointer provided is not a valid memory
105 * reference.
106 */
107psa_status_t psa_get(psa_signal_t signal, psa_msg_t *msg);
108
109/**
110 * \brief Associate some RoT Service private data with a client connection.
111 *
112 * \param[in] msg_handle Handle for the client's message.
113 * \param[in] rhandle Reverse handle allocated by the RoT Service.
114 *
115 * \retval void Success, rhandle will be provided with all
116 * subsequent messages delivered on this
117 * connection.
118 * \retval "Does not return" msg_handle is invalid.
119 */
120void psa_set_rhandle(psa_handle_t msg_handle, void *rhandle);
121
122/**
123 * \brief Read a message parameter or part of a message parameter from a client
124 * input vector.
125 *
126 * \param[in] msg_handle Handle for the client's message.
127 * \param[in] invec_idx Index of the input vector to read from. Must be
128 * less than \ref PSA_MAX_IOVEC.
129 * \param[out] buffer Buffer in the Secure Partition to copy the
130 * requested data to.
131 * \param[in] num_bytes Maximum number of bytes to be read from the
132 * client input vector.
133 *
134 * \retval >0 Number of bytes copied.
135 * \retval 0 There was no remaining data in this input
136 * vector.
137 * \retval "Does not return" The call is invalid, one or more of the
138 * following are true:
139 * \arg msg_handle is invalid.
140 * \arg msg_handle does not refer to a
141 * \ref PSA_IPC_CALL message.
142 * \arg invec_idx is equal to or greater than
143 * \ref PSA_MAX_IOVEC.
144 * \arg the memory reference for buffer is invalid or
145 * not writable.
146 */
147size_t psa_read(psa_handle_t msg_handle, uint32_t invec_idx,
148 void *buffer, size_t num_bytes);
149
150/**
151 * \brief Skip over part of a client input vector.
152 *
153 * \param[in] msg_handle Handle for the client's message.
154 * \param[in] invec_idx Index of input vector to skip from. Must be
155 * less than \ref PSA_MAX_IOVEC.
156 * \param[in] num_bytes Maximum number of bytes to skip in the client
157 * input vector.
158 *
159 * \retval >0 Number of bytes skipped.
160 * \retval 0 There was no remaining data in this input
161 * vector.
162 * \retval "Does not return" The call is invalid, one or more of the
163 * following are true:
164 * \arg msg_handle is invalid.
165 * \arg msg_handle does not refer to a
166 * \ref PSA_IPC_CALL message.
167 * \arg invec_idx is equal to or greater than
168 * \ref PSA_MAX_IOVEC.
169 */
170size_t psa_skip(psa_handle_t msg_handle, uint32_t invec_idx, size_t num_bytes);
171
172/**
173 * \brief Write a message response to a client output vector.
174 *
175 * \param[in] msg_handle Handle for the client's message.
176 * \param[out] outvec_idx Index of output vector in message to write to.
177 * Must be less than \ref PSA_MAX_IOVEC.
178 * \param[in] buffer Buffer with the data to write.
179 * \param[in] num_bytes Number of bytes to write to the client output
180 * vector.
181 *
182 * \retval void Success
183 * \retval "Does not return" The call is invalid, one or more of the
184 * following are true:
185 * \arg msg_handle is invalid.
186 * \arg msg_handle does not refer to a
187 * \ref PSA_IPC_CALL message.
188 * \arg outvec_idx is equal to or greater than
189 * \ref PSA_MAX_IOVEC.
190 * \arg The memory reference for buffer is invalid.
191 * \arg The call attempts to write data past the end
192 * of the client output vector.
193 */
194void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx,
195 const void *buffer, size_t num_bytes);
196
197/**
198 * \brief Complete handling of a specific message and unblock the client.
199 *
200 * \param[in] msg_handle Handle for the client's message.
201 * \param[in] status Message result value to be reported to the
202 * client.
203 *
204 * \retval void Success.
205 * \retval "Does not return" The call is invalid, one or more of the
206 * following are true:
207 * \arg msg_handle is invalid.
208 * \arg An invalid status code is specified for the
209 * type of message.
210 */
211void psa_reply(psa_handle_t msg_handle, psa_status_t status);
212
213/**
214 * \brief Send a PSA_DOORBELL signal to a specific Secure Partition.
215 *
216 * \param[in] partition_id Secure Partition ID of the target partition.
217 *
218 * \retval void Success.
219 * \retval "Does not return" partition_id does not correspond to a Secure
220 * Partition.
221 */
222void psa_notify(int32_t partition_id);
223
224/**
225 * \brief Clear the PSA_DOORBELL signal.
226 *
227 * \retval void Success.
228 * \retval "Does not return" The Secure Partition's doorbell signal is not
229 * currently asserted.
230 */
231void psa_clear(void);
232
233/**
234 * \brief Inform the SPM that an interrupt has been handled (end of interrupt).
235 *
236 * \param[in] irq_signal The interrupt signal that has been processed.
237 *
238 * \retval void Success.
239 * \retval "Does not return" The call is invalid, one or more of the
240 * following are true:
241 * \arg irq_signal is not an interrupt signal.
242 * \arg irq_signal indicates more than one signal.
243 * \arg irq_signal is not currently asserted.
244 */
245void psa_eoi(psa_signal_t irq_signal);
246
247#define psa_panic(X) abort();
248
249#ifdef __cplusplus
250}
251#endif
252
253#endif /* __PSA_SERVICE_H__ */