blob: 9af3f6757b0c9ec271d43a41d4fe435fd4d27ad1 [file] [log] [blame]
Miklos Balint9ecb24c2018-03-29 15:30:28 +02001/*
Edison Aib3e56962018-09-04 19:12:31 +08002 * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
Miklos Balint9ecb24c2018-03-29 15:30:28 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef __PSA_SERVICE_H__
9#define __PSA_SERVICE_H__
10
Jamie Fox520fb4d2019-06-13 14:27:21 +010011#include <stddef.h>
12#include <stdint.h>
13
14#include "psa/error.h"
15#include "psa/client.h"
16
Miklos Balint9ecb24c2018-03-29 15:30:28 +020017#ifdef __cplusplus
18extern "C" {
19#endif
20
Edison Aib3e56962018-09-04 19:12:31 +080021/********************** PSA Secure Partition Macros and Types ****************/
22
Miklos Balint9ecb24c2018-03-29 15:30:28 +020023/* PSA wait timeouts */
24#define PSA_POLL (0x00000000u)
25#define PSA_BLOCK (0x80000000u)
26
Edison Aib3e56962018-09-04 19:12:31 +080027/* A mask value that includes all Secure Partition signals */
28#define PSA_WAIT_ANY (~0u)
29
30/* Doorbell signal */
Miklos Balint9ecb24c2018-03-29 15:30:28 +020031#define PSA_DOORBELL (0x00000008u)
32
33/* PSA message types */
34#define PSA_IPC_CONNECT (1)
35#define PSA_IPC_CALL (2)
36#define PSA_IPC_DISCONNECT (3)
37
Edison Aib3e56962018-09-04 19:12:31 +080038/* Maximum number of input and output vectors */
Miklos Balint9ecb24c2018-03-29 15:30:28 +020039#define PSA_MAX_IOVEC (4)
40
Edison Aib3e56962018-09-04 19:12:31 +080041/* Return code from psa_get() */
42#define PSA_ERR_NOMSG (INT32_MIN + 3)
43
44/* Store a set of one or more Secure Partition signals */
Miklos Balint9ecb24c2018-03-29 15:30:28 +020045typedef uint32_t psa_signal_t;
46
47/**
Edison Aib3e56962018-09-04 19:12:31 +080048 * Describe a message received by an RoT Service after calling \ref psa_get().
Miklos Balint9ecb24c2018-03-29 15:30:28 +020049 */
50typedef struct psa_msg_t {
Edison Aib3e56962018-09-04 19:12:31 +080051 uint32_t type; /* One of the following values:
52 * \ref PSA_IPC_CONNECT
53 * \ref PSA_IPC_CALL
54 * \ref PSA_IPC_DISCONNECT
55 */
56 psa_handle_t handle; /* A reference generated by the SPM to the
57 * message returned by psa_get().
58 */
59 int32_t client_id; /* Partition ID of the sender of the message */
60 void *rhandle; /* Be useful for binding a connection to some
61 * application-specific data or function
62 * pointer within the RoT Service
63 * implementation.
64 */
65 size_t in_size[PSA_MAX_IOVEC]; /* Provide the size of each client input
66 * vector in bytes.
67 */
68 size_t out_size[PSA_MAX_IOVEC];/* Provide the size of each client output
69 * vector in bytes.
70 */
Miklos Balint9ecb24c2018-03-29 15:30:28 +020071} psa_msg_t;
72
Edison Aib3e56962018-09-04 19:12:31 +080073/************************* PSA Secure Partition API **************************/
Miklos Balint9ecb24c2018-03-29 15:30:28 +020074
75/**
Edison Aib3e56962018-09-04 19:12:31 +080076 * \brief Return the Secure Partition interrupt signals that have been asserted
77 * from a subset of signals provided by the caller.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020078 *
Edison Aib3e56962018-09-04 19:12:31 +080079 * \param[in] signal_mask A set of signals to query. Signals that are not
80 * in this set will be ignored.
81 * \param[in] timeout Specify either blocking \ref PSA_BLOCK or
82 * polling \ref PSA_POLL operation.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020083 *
Edison Aib3e56962018-09-04 19:12:31 +080084 * \retval >0 At least one signal is asserted.
85 * \retval 0 No signals are asserted. This is only seen when
86 * a polling timeout is used.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020087 */
Edison Aib3e56962018-09-04 19:12:31 +080088psa_signal_t psa_wait(psa_signal_t signal_mask, uint32_t timeout);
Miklos Balint9ecb24c2018-03-29 15:30:28 +020089
90/**
Edison Aib3e56962018-09-04 19:12:31 +080091 * \brief Retrieve the message which corresponds to a given RoT Service signal
Miklos Balint9ecb24c2018-03-29 15:30:28 +020092 * and remove the message from the RoT Service queue.
93 *
Edison Aib3e56962018-09-04 19:12:31 +080094 * \param[in] signal The signal value for an asserted RoT Service.
95 * \param[out] msg Pointer to \ref psa_msg_t object for receiving
96 * the message.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020097 *
Edison Aib3e56962018-09-04 19:12:31 +080098 * \retval PSA_SUCCESS Success, *msg will contain the delivered
99 * message.
100 * \retval PSA_ERR_NOMSG Message could not be delivered.
101 * \retval "Does not return" The call is invalid because one or more of the
102 * following are true:
103 * \arg signal has more than a single bit set.
104 * \arg signal does not correspond to an RoT Service.
105 * \arg The RoT Service signal is not currently
106 * asserted.
107 * \arg The msg pointer provided is not a valid memory
108 * reference.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200109 */
Edison Aib3e56962018-09-04 19:12:31 +0800110psa_status_t psa_get(psa_signal_t signal, psa_msg_t *msg);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200111
112/**
Edison Aib3e56962018-09-04 19:12:31 +0800113 * \brief Associate some RoT Service private data with a client connection.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200114 *
Edison Aib3e56962018-09-04 19:12:31 +0800115 * \param[in] msg_handle Handle for the client's message.
116 * \param[in] rhandle Reverse handle allocated by the RoT Service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200117 *
Edison Aib3e56962018-09-04 19:12:31 +0800118 * \retval void Success, rhandle will be provided with all
119 * subsequent messages delivered on this
120 * connection.
121 * \retval "Does not return" msg_handle is invalid.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200122 */
123void psa_set_rhandle(psa_handle_t msg_handle, void *rhandle);
124
125/**
Edison Aib3e56962018-09-04 19:12:31 +0800126 * \brief Read a message parameter or part of a message parameter from a client
127 * input vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200128 *
Edison Aib3e56962018-09-04 19:12:31 +0800129 * \param[in] msg_handle Handle for the client's message.
130 * \param[in] invec_idx Index of the input vector to read from. Must be
131 * less than \ref PSA_MAX_IOVEC.
132 * \param[out] buffer Buffer in the Secure Partition to copy the
133 * requested data to.
134 * \param[in] num_bytes Maximum number of bytes to be read from the
135 * client input vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200136 *
Edison Aib3e56962018-09-04 19:12:31 +0800137 * \retval >0 Number of bytes copied.
138 * \retval 0 There was no remaining data in this input
139 * vector.
140 * \retval "Does not return" The call is invalid, one or more of the
141 * following are true:
142 * \arg msg_handle is invalid.
143 * \arg msg_handle does not refer to a
144 * \ref PSA_IPC_CALL message.
145 * \arg invec_idx is equal to or greater than
146 * \ref PSA_MAX_IOVEC.
147 * \arg the memory reference for buffer is invalid or
148 * not writable.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200149 */
150size_t psa_read(psa_handle_t msg_handle, uint32_t invec_idx,
Edison Aib3e56962018-09-04 19:12:31 +0800151 void *buffer, size_t num_bytes);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200152
153/**
Edison Aib3e56962018-09-04 19:12:31 +0800154 * \brief Skip over part of a client input vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200155 *
Edison Aib3e56962018-09-04 19:12:31 +0800156 * \param[in] msg_handle Handle for the client's message.
157 * \param[in] invec_idx Index of input vector to skip from. Must be
158 * less than \ref PSA_MAX_IOVEC.
159 * \param[in] num_bytes Maximum number of bytes to skip in the client
160 * input vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200161 *
Edison Aib3e56962018-09-04 19:12:31 +0800162 * \retval >0 Number of bytes skipped.
163 * \retval 0 There was no remaining data in this input
164 * vector.
165 * \retval "Does not return" The call is invalid, one or more of the
166 * following are true:
167 * \arg msg_handle is invalid.
168 * \arg msg_handle does not refer to a
169 * \ref PSA_IPC_CALL message.
170 * \arg invec_idx is equal to or greater than
171 * \ref PSA_MAX_IOVEC.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200172 */
173size_t psa_skip(psa_handle_t msg_handle, uint32_t invec_idx, size_t num_bytes);
174
175/**
Edison Aib3e56962018-09-04 19:12:31 +0800176 * \brief Write a message response to a client output vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200177 *
Edison Aib3e56962018-09-04 19:12:31 +0800178 * \param[in] msg_handle Handle for the client's message.
179 * \param[out] outvec_idx Index of output vector in message to write to.
180 * Must be less than \ref PSA_MAX_IOVEC.
181 * \param[in] buffer Buffer with the data to write.
182 * \param[in] num_bytes Number of bytes to write to the client output
183 * vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200184 *
Edison Aib3e56962018-09-04 19:12:31 +0800185 * \retval void Success
186 * \retval "Does not return" The call is invalid, one or more of the
187 * following are true:
188 * \arg msg_handle is invalid.
189 * \arg msg_handle does not refer to a
190 * \ref PSA_IPC_CALL message.
191 * \arg outvec_idx is equal to or greater than
192 * \ref PSA_MAX_IOVEC.
193 * \arg The memory reference for buffer is invalid.
194 * \arg The call attempts to write data past the end
195 * of the client output vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200196 */
197void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx,
Edison Aib3e56962018-09-04 19:12:31 +0800198 const void *buffer, size_t num_bytes);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200199
200/**
Edison Aib3e56962018-09-04 19:12:31 +0800201 * \brief Complete handling of a specific message and unblock the client.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200202 *
Edison Aib3e56962018-09-04 19:12:31 +0800203 * \param[in] msg_handle Handle for the client's message.
204 * \param[in] status Message result value to be reported to the
205 * client.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200206 *
Edison Aib3e56962018-09-04 19:12:31 +0800207 * \retval void Success.
208 * \retval "Does not return" The call is invalid, one or more of the
209 * following are true:
210 * \arg msg_handle is invalid.
211 * \arg An invalid status code is specified for the
212 * type of message.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200213 */
Edison Aib3e56962018-09-04 19:12:31 +0800214void psa_reply(psa_handle_t msg_handle, psa_status_t status);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200215
216/**
Edison Aib3e56962018-09-04 19:12:31 +0800217 * \brief Send a PSA_DOORBELL signal to a specific Secure Partition.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200218 *
Edison Aib3e56962018-09-04 19:12:31 +0800219 * \param[in] partition_id Secure Partition ID of the target partition.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200220 *
Edison Aib3e56962018-09-04 19:12:31 +0800221 * \retval void Success.
222 * \retval "Does not return" partition_id does not correspond to a Secure
223 * Partition.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200224 */
225void psa_notify(int32_t partition_id);
226
227/**
Edison Aib3e56962018-09-04 19:12:31 +0800228 * \brief Clear the PSA_DOORBELL signal.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200229 *
Edison Aib3e56962018-09-04 19:12:31 +0800230 * \retval void Success.
231 * \retval "Does not return" The Secure Partition's doorbell signal is not
232 * currently asserted.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200233 */
234void psa_clear(void);
235
236/**
Edison Aib3e56962018-09-04 19:12:31 +0800237 * \brief Inform the SPM that an interrupt has been handled (end of interrupt).
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200238 *
Edison Aib3e56962018-09-04 19:12:31 +0800239 * \param[in] irq_signal The interrupt signal that has been processed.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200240 *
Edison Aib3e56962018-09-04 19:12:31 +0800241 * \retval void Success.
242 * \retval "Does not return" The call is invalid, one or more of the
243 * following are true:
244 * \arg irq_signal is not an interrupt signal.
245 * \arg irq_signal indicates more than one signal.
246 * \arg irq_signal is not currently asserted.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200247 */
Edison Aib3e56962018-09-04 19:12:31 +0800248void psa_eoi(psa_signal_t irq_signal);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200249
250#ifdef __cplusplus
251}
252#endif
253
254#endif /* __PSA_SERVICE_H__ */