blob: 6453aede8bad5a0c76c0c9cb69714ad54bbba18a [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
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#include <inttypes.h>
16
Edison Aib3e56962018-09-04 19:12:31 +080017/********************** PSA Secure Partition Macros and Types ****************/
18
Miklos Balint9ecb24c2018-03-29 15:30:28 +020019/* PSA wait timeouts */
20#define PSA_POLL (0x00000000u)
21#define PSA_BLOCK (0x80000000u)
22
Edison Aib3e56962018-09-04 19:12:31 +080023/* A mask value that includes all Secure Partition signals */
24#define PSA_WAIT_ANY (~0u)
25
26/* Doorbell signal */
Miklos Balint9ecb24c2018-03-29 15:30:28 +020027#define PSA_DOORBELL (0x00000008u)
28
29/* PSA message types */
30#define PSA_IPC_CONNECT (1)
31#define PSA_IPC_CALL (2)
32#define PSA_IPC_DISCONNECT (3)
33
Edison Aib3e56962018-09-04 19:12:31 +080034/* Maximum number of input and output vectors */
Miklos Balint9ecb24c2018-03-29 15:30:28 +020035#define PSA_MAX_IOVEC (4)
36
Edison Aib3e56962018-09-04 19:12:31 +080037/* Return code from psa_get() */
38#define PSA_ERR_NOMSG (INT32_MIN + 3)
39
40/* Store a set of one or more Secure Partition signals */
Miklos Balint9ecb24c2018-03-29 15:30:28 +020041typedef uint32_t psa_signal_t;
42
43/**
Edison Aib3e56962018-09-04 19:12:31 +080044 * Describe a message received by an RoT Service after calling \ref psa_get().
Miklos Balint9ecb24c2018-03-29 15:30:28 +020045 */
46typedef struct psa_msg_t {
Edison Aib3e56962018-09-04 19:12:31 +080047 uint32_t type; /* One of the following values:
48 * \ref PSA_IPC_CONNECT
49 * \ref PSA_IPC_CALL
50 * \ref PSA_IPC_DISCONNECT
51 */
52 psa_handle_t handle; /* A reference generated by the SPM to the
53 * message returned by psa_get().
54 */
55 int32_t client_id; /* Partition ID of the sender of the message */
56 void *rhandle; /* Be useful for binding a connection to some
57 * application-specific data or function
58 * pointer within the RoT Service
59 * implementation.
60 */
61 size_t in_size[PSA_MAX_IOVEC]; /* Provide the size of each client input
62 * vector in bytes.
63 */
64 size_t out_size[PSA_MAX_IOVEC];/* Provide the size of each client output
65 * vector in bytes.
66 */
Miklos Balint9ecb24c2018-03-29 15:30:28 +020067} psa_msg_t;
68
Edison Aib3e56962018-09-04 19:12:31 +080069/************************* PSA Secure Partition API **************************/
Miklos Balint9ecb24c2018-03-29 15:30:28 +020070
71/**
Edison Aib3e56962018-09-04 19:12:31 +080072 * \brief Return the Secure Partition interrupt signals that have been asserted
73 * from a subset of signals provided by the caller.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020074 *
Edison Aib3e56962018-09-04 19:12:31 +080075 * \param[in] signal_mask A set of signals to query. Signals that are not
76 * in this set will be ignored.
77 * \param[in] timeout Specify either blocking \ref PSA_BLOCK or
78 * polling \ref PSA_POLL operation.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020079 *
Edison Aib3e56962018-09-04 19:12:31 +080080 * \retval >0 At least one signal is asserted.
81 * \retval 0 No signals are asserted. This is only seen when
82 * a polling timeout is used.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020083 */
Edison Aib3e56962018-09-04 19:12:31 +080084psa_signal_t psa_wait(psa_signal_t signal_mask, uint32_t timeout);
Miklos Balint9ecb24c2018-03-29 15:30:28 +020085
86/**
Edison Aib3e56962018-09-04 19:12:31 +080087 * \brief Retrieve the message which corresponds to a given RoT Service signal
Miklos Balint9ecb24c2018-03-29 15:30:28 +020088 * and remove the message from the RoT Service queue.
89 *
Edison Aib3e56962018-09-04 19:12:31 +080090 * \param[in] signal The signal value for an asserted RoT Service.
91 * \param[out] msg Pointer to \ref psa_msg_t object for receiving
92 * the message.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020093 *
Edison Aib3e56962018-09-04 19:12:31 +080094 * \retval PSA_SUCCESS Success, *msg will contain the delivered
95 * message.
96 * \retval PSA_ERR_NOMSG Message could not be delivered.
97 * \retval "Does not return" The call is invalid because one or more of the
98 * following are true:
99 * \arg signal has more than a single bit set.
100 * \arg signal does not correspond to an RoT Service.
101 * \arg The RoT Service signal is not currently
102 * asserted.
103 * \arg The msg pointer provided is not a valid memory
104 * reference.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200105 */
Edison Aib3e56962018-09-04 19:12:31 +0800106psa_status_t psa_get(psa_signal_t signal, psa_msg_t *msg);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200107
108/**
Edison Aib3e56962018-09-04 19:12:31 +0800109 * \brief Associate some RoT Service private data with a client connection.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200110 *
Edison Aib3e56962018-09-04 19:12:31 +0800111 * \param[in] msg_handle Handle for the client's message.
112 * \param[in] rhandle Reverse handle allocated by the RoT Service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200113 *
Edison Aib3e56962018-09-04 19:12:31 +0800114 * \retval void Success, rhandle will be provided with all
115 * subsequent messages delivered on this
116 * connection.
117 * \retval "Does not return" msg_handle is invalid.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200118 */
119void psa_set_rhandle(psa_handle_t msg_handle, void *rhandle);
120
121/**
Edison Aib3e56962018-09-04 19:12:31 +0800122 * \brief Read a message parameter or part of a message parameter from a client
123 * input vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200124 *
Edison Aib3e56962018-09-04 19:12:31 +0800125 * \param[in] msg_handle Handle for the client's message.
126 * \param[in] invec_idx Index of the input vector to read from. Must be
127 * less than \ref PSA_MAX_IOVEC.
128 * \param[out] buffer Buffer in the Secure Partition to copy the
129 * requested data to.
130 * \param[in] num_bytes Maximum number of bytes to be read from the
131 * client input vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200132 *
Edison Aib3e56962018-09-04 19:12:31 +0800133 * \retval >0 Number of bytes copied.
134 * \retval 0 There was no remaining data in this input
135 * vector.
136 * \retval "Does not return" The call is invalid, one or more of the
137 * following are true:
138 * \arg msg_handle is invalid.
139 * \arg msg_handle does not refer to a
140 * \ref PSA_IPC_CALL message.
141 * \arg invec_idx is equal to or greater than
142 * \ref PSA_MAX_IOVEC.
143 * \arg the memory reference for buffer is invalid or
144 * not writable.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200145 */
146size_t psa_read(psa_handle_t msg_handle, uint32_t invec_idx,
Edison Aib3e56962018-09-04 19:12:31 +0800147 void *buffer, size_t num_bytes);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200148
149/**
Edison Aib3e56962018-09-04 19:12:31 +0800150 * \brief Skip over part of a client input vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200151 *
Edison Aib3e56962018-09-04 19:12:31 +0800152 * \param[in] msg_handle Handle for the client's message.
153 * \param[in] invec_idx Index of input vector to skip from. Must be
154 * less than \ref PSA_MAX_IOVEC.
155 * \param[in] num_bytes Maximum number of bytes to skip in the client
156 * input vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200157 *
Edison Aib3e56962018-09-04 19:12:31 +0800158 * \retval >0 Number of bytes skipped.
159 * \retval 0 There was no remaining data in this input
160 * vector.
161 * \retval "Does not return" The call is invalid, one or more of the
162 * following are true:
163 * \arg msg_handle is invalid.
164 * \arg msg_handle does not refer to a
165 * \ref PSA_IPC_CALL message.
166 * \arg invec_idx is equal to or greater than
167 * \ref PSA_MAX_IOVEC.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200168 */
169size_t psa_skip(psa_handle_t msg_handle, uint32_t invec_idx, size_t num_bytes);
170
171/**
Edison Aib3e56962018-09-04 19:12:31 +0800172 * \brief Write a message response to a client output vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200173 *
Edison Aib3e56962018-09-04 19:12:31 +0800174 * \param[in] msg_handle Handle for the client's message.
175 * \param[out] outvec_idx Index of output vector in message to write to.
176 * Must be less than \ref PSA_MAX_IOVEC.
177 * \param[in] buffer Buffer with the data to write.
178 * \param[in] num_bytes Number of bytes to write to the client output
179 * vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200180 *
Edison Aib3e56962018-09-04 19:12:31 +0800181 * \retval void Success
182 * \retval "Does not return" The call is invalid, one or more of the
183 * following are true:
184 * \arg msg_handle is invalid.
185 * \arg msg_handle does not refer to a
186 * \ref PSA_IPC_CALL message.
187 * \arg outvec_idx is equal to or greater than
188 * \ref PSA_MAX_IOVEC.
189 * \arg The memory reference for buffer is invalid.
190 * \arg The call attempts to write data past the end
191 * of the client output vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200192 */
193void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx,
Edison Aib3e56962018-09-04 19:12:31 +0800194 const void *buffer, size_t num_bytes);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200195
196/**
Edison Aib3e56962018-09-04 19:12:31 +0800197 * \brief Complete handling of a specific message and unblock the client.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200198 *
Edison Aib3e56962018-09-04 19:12:31 +0800199 * \param[in] msg_handle Handle for the client's message.
200 * \param[in] status Message result value to be reported to the
201 * client.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200202 *
Edison Aib3e56962018-09-04 19:12:31 +0800203 * \retval void Success.
204 * \retval "Does not return" The call is invalid, one or more of the
205 * following are true:
206 * \arg msg_handle is invalid.
207 * \arg An invalid status code is specified for the
208 * type of message.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200209 */
Edison Aib3e56962018-09-04 19:12:31 +0800210void psa_reply(psa_handle_t msg_handle, psa_status_t status);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200211
212/**
Edison Aib3e56962018-09-04 19:12:31 +0800213 * \brief Send a PSA_DOORBELL signal to a specific Secure Partition.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200214 *
Edison Aib3e56962018-09-04 19:12:31 +0800215 * \param[in] partition_id Secure Partition ID of the target partition.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200216 *
Edison Aib3e56962018-09-04 19:12:31 +0800217 * \retval void Success.
218 * \retval "Does not return" partition_id does not correspond to a Secure
219 * Partition.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200220 */
221void psa_notify(int32_t partition_id);
222
223/**
Edison Aib3e56962018-09-04 19:12:31 +0800224 * \brief Clear the PSA_DOORBELL signal.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200225 *
Edison Aib3e56962018-09-04 19:12:31 +0800226 * \retval void Success.
227 * \retval "Does not return" The Secure Partition's doorbell signal is not
228 * currently asserted.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200229 */
230void psa_clear(void);
231
232/**
Edison Aib3e56962018-09-04 19:12:31 +0800233 * \brief Inform the SPM that an interrupt has been handled (end of interrupt).
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200234 *
Edison Aib3e56962018-09-04 19:12:31 +0800235 * \param[in] irq_signal The interrupt signal that has been processed.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200236 *
Edison Aib3e56962018-09-04 19:12:31 +0800237 * \retval void Success.
238 * \retval "Does not return" The call is invalid, one or more of the
239 * following are true:
240 * \arg irq_signal is not an interrupt signal.
241 * \arg irq_signal indicates more than one signal.
242 * \arg irq_signal is not currently asserted.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200243 */
Edison Aib3e56962018-09-04 19:12:31 +0800244void psa_eoi(psa_signal_t irq_signal);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200245
246#ifdef __cplusplus
247}
248#endif
249
250#endif /* __PSA_SERVICE_H__ */