blob: 2e8558ae9627f709f28b85955b58935ce8c224f9 [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
Jamie Foxcc31d402019-01-28 17:13:52 +000017#include "psa/client.h"
David Hu7c67fb82019-05-16 17:35:39 +080018
Edison Aib3e56962018-09-04 19:12:31 +080019/********************** PSA Secure Partition Macros and Types ****************/
20
Miklos Balint9ecb24c2018-03-29 15:30:28 +020021/* PSA wait timeouts */
22#define PSA_POLL (0x00000000u)
23#define PSA_BLOCK (0x80000000u)
24
Edison Aib3e56962018-09-04 19:12:31 +080025/* A mask value that includes all Secure Partition signals */
26#define PSA_WAIT_ANY (~0u)
27
28/* Doorbell signal */
Miklos Balint9ecb24c2018-03-29 15:30:28 +020029#define PSA_DOORBELL (0x00000008u)
30
31/* PSA message types */
32#define PSA_IPC_CONNECT (1)
33#define PSA_IPC_CALL (2)
34#define PSA_IPC_DISCONNECT (3)
35
Edison Aib3e56962018-09-04 19:12:31 +080036/* Maximum number of input and output vectors */
Miklos Balint9ecb24c2018-03-29 15:30:28 +020037#define PSA_MAX_IOVEC (4)
38
Edison Aib3e56962018-09-04 19:12:31 +080039/* Return code from psa_get() */
40#define PSA_ERR_NOMSG (INT32_MIN + 3)
41
42/* Store a set of one or more Secure Partition signals */
Miklos Balint9ecb24c2018-03-29 15:30:28 +020043typedef uint32_t psa_signal_t;
44
45/**
Edison Aib3e56962018-09-04 19:12:31 +080046 * Describe a message received by an RoT Service after calling \ref psa_get().
Miklos Balint9ecb24c2018-03-29 15:30:28 +020047 */
48typedef struct psa_msg_t {
Edison Aib3e56962018-09-04 19:12:31 +080049 uint32_t type; /* One of the following values:
50 * \ref PSA_IPC_CONNECT
51 * \ref PSA_IPC_CALL
52 * \ref PSA_IPC_DISCONNECT
53 */
54 psa_handle_t handle; /* A reference generated by the SPM to the
55 * message returned by psa_get().
56 */
57 int32_t client_id; /* Partition ID of the sender of the message */
58 void *rhandle; /* Be useful for binding a connection to some
59 * application-specific data or function
60 * pointer within the RoT Service
61 * implementation.
62 */
63 size_t in_size[PSA_MAX_IOVEC]; /* Provide the size of each client input
64 * vector in bytes.
65 */
66 size_t out_size[PSA_MAX_IOVEC];/* Provide the size of each client output
67 * vector in bytes.
68 */
Miklos Balint9ecb24c2018-03-29 15:30:28 +020069} psa_msg_t;
70
Edison Aib3e56962018-09-04 19:12:31 +080071/************************* PSA Secure Partition API **************************/
Miklos Balint9ecb24c2018-03-29 15:30:28 +020072
73/**
Edison Aib3e56962018-09-04 19:12:31 +080074 * \brief Return the Secure Partition interrupt signals that have been asserted
75 * from a subset of signals provided by the caller.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020076 *
Edison Aib3e56962018-09-04 19:12:31 +080077 * \param[in] signal_mask A set of signals to query. Signals that are not
78 * in this set will be ignored.
79 * \param[in] timeout Specify either blocking \ref PSA_BLOCK or
80 * polling \ref PSA_POLL operation.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020081 *
Edison Aib3e56962018-09-04 19:12:31 +080082 * \retval >0 At least one signal is asserted.
83 * \retval 0 No signals are asserted. This is only seen when
84 * a polling timeout is used.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020085 */
Edison Aib3e56962018-09-04 19:12:31 +080086psa_signal_t psa_wait(psa_signal_t signal_mask, uint32_t timeout);
Miklos Balint9ecb24c2018-03-29 15:30:28 +020087
88/**
Edison Aib3e56962018-09-04 19:12:31 +080089 * \brief Retrieve the message which corresponds to a given RoT Service signal
Miklos Balint9ecb24c2018-03-29 15:30:28 +020090 * and remove the message from the RoT Service queue.
91 *
Edison Aib3e56962018-09-04 19:12:31 +080092 * \param[in] signal The signal value for an asserted RoT Service.
93 * \param[out] msg Pointer to \ref psa_msg_t object for receiving
94 * the message.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020095 *
Edison Aib3e56962018-09-04 19:12:31 +080096 * \retval PSA_SUCCESS Success, *msg will contain the delivered
97 * message.
98 * \retval PSA_ERR_NOMSG Message could not be delivered.
99 * \retval "Does not return" The call is invalid because one or more of the
100 * following are true:
101 * \arg signal has more than a single bit set.
102 * \arg signal does not correspond to an RoT Service.
103 * \arg The RoT Service signal is not currently
104 * asserted.
105 * \arg The msg pointer provided is not a valid memory
106 * reference.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200107 */
Edison Aib3e56962018-09-04 19:12:31 +0800108psa_status_t psa_get(psa_signal_t signal, psa_msg_t *msg);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200109
110/**
Edison Aib3e56962018-09-04 19:12:31 +0800111 * \brief Associate some RoT Service private data with a client connection.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200112 *
Edison Aib3e56962018-09-04 19:12:31 +0800113 * \param[in] msg_handle Handle for the client's message.
114 * \param[in] rhandle Reverse handle allocated by the RoT Service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200115 *
Edison Aib3e56962018-09-04 19:12:31 +0800116 * \retval void Success, rhandle will be provided with all
117 * subsequent messages delivered on this
118 * connection.
119 * \retval "Does not return" msg_handle is invalid.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200120 */
121void psa_set_rhandle(psa_handle_t msg_handle, void *rhandle);
122
123/**
Edison Aib3e56962018-09-04 19:12:31 +0800124 * \brief Read a message parameter or part of a message parameter from a client
125 * input vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200126 *
Edison Aib3e56962018-09-04 19:12:31 +0800127 * \param[in] msg_handle Handle for the client's message.
128 * \param[in] invec_idx Index of the input vector to read from. Must be
129 * less than \ref PSA_MAX_IOVEC.
130 * \param[out] buffer Buffer in the Secure Partition to copy the
131 * requested data to.
132 * \param[in] num_bytes Maximum number of bytes to be read from the
133 * client input vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200134 *
Edison Aib3e56962018-09-04 19:12:31 +0800135 * \retval >0 Number of bytes copied.
136 * \retval 0 There was no remaining data in this input
137 * vector.
138 * \retval "Does not return" The call is invalid, one or more of the
139 * following are true:
140 * \arg msg_handle is invalid.
141 * \arg msg_handle does not refer to a
142 * \ref PSA_IPC_CALL message.
143 * \arg invec_idx is equal to or greater than
144 * \ref PSA_MAX_IOVEC.
145 * \arg the memory reference for buffer is invalid or
146 * not writable.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200147 */
148size_t psa_read(psa_handle_t msg_handle, uint32_t invec_idx,
Edison Aib3e56962018-09-04 19:12:31 +0800149 void *buffer, size_t num_bytes);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200150
151/**
Edison Aib3e56962018-09-04 19:12:31 +0800152 * \brief Skip over part of a client input vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200153 *
Edison Aib3e56962018-09-04 19:12:31 +0800154 * \param[in] msg_handle Handle for the client's message.
155 * \param[in] invec_idx Index of input vector to skip from. Must be
156 * less than \ref PSA_MAX_IOVEC.
157 * \param[in] num_bytes Maximum number of bytes to skip in the client
158 * input vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200159 *
Edison Aib3e56962018-09-04 19:12:31 +0800160 * \retval >0 Number of bytes skipped.
161 * \retval 0 There was no remaining data in this input
162 * vector.
163 * \retval "Does not return" The call is invalid, one or more of the
164 * following are true:
165 * \arg msg_handle is invalid.
166 * \arg msg_handle does not refer to a
167 * \ref PSA_IPC_CALL message.
168 * \arg invec_idx is equal to or greater than
169 * \ref PSA_MAX_IOVEC.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200170 */
171size_t psa_skip(psa_handle_t msg_handle, uint32_t invec_idx, size_t num_bytes);
172
173/**
Edison Aib3e56962018-09-04 19:12:31 +0800174 * \brief Write a message response to a client output vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200175 *
Edison Aib3e56962018-09-04 19:12:31 +0800176 * \param[in] msg_handle Handle for the client's message.
177 * \param[out] outvec_idx Index of output vector in message to write to.
178 * Must be less than \ref PSA_MAX_IOVEC.
179 * \param[in] buffer Buffer with the data to write.
180 * \param[in] num_bytes Number of bytes to write to the client output
181 * vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200182 *
Edison Aib3e56962018-09-04 19:12:31 +0800183 * \retval void Success
184 * \retval "Does not return" The call is invalid, one or more of the
185 * following are true:
186 * \arg msg_handle is invalid.
187 * \arg msg_handle does not refer to a
188 * \ref PSA_IPC_CALL message.
189 * \arg outvec_idx is equal to or greater than
190 * \ref PSA_MAX_IOVEC.
191 * \arg The memory reference for buffer is invalid.
192 * \arg The call attempts to write data past the end
193 * of the client output vector.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200194 */
195void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx,
Edison Aib3e56962018-09-04 19:12:31 +0800196 const void *buffer, size_t num_bytes);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200197
198/**
Edison Aib3e56962018-09-04 19:12:31 +0800199 * \brief Complete handling of a specific message and unblock the client.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200200 *
Edison Aib3e56962018-09-04 19:12:31 +0800201 * \param[in] msg_handle Handle for the client's message.
202 * \param[in] status Message result value to be reported to the
203 * client.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200204 *
Edison Aib3e56962018-09-04 19:12:31 +0800205 * \retval void Success.
206 * \retval "Does not return" The call is invalid, one or more of the
207 * following are true:
208 * \arg msg_handle is invalid.
209 * \arg An invalid status code is specified for the
210 * type of message.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200211 */
Edison Aib3e56962018-09-04 19:12:31 +0800212void psa_reply(psa_handle_t msg_handle, psa_status_t status);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200213
214/**
Edison Aib3e56962018-09-04 19:12:31 +0800215 * \brief Send a PSA_DOORBELL signal to a specific Secure Partition.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200216 *
Edison Aib3e56962018-09-04 19:12:31 +0800217 * \param[in] partition_id Secure Partition ID of the target partition.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200218 *
Edison Aib3e56962018-09-04 19:12:31 +0800219 * \retval void Success.
220 * \retval "Does not return" partition_id does not correspond to a Secure
221 * Partition.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200222 */
223void psa_notify(int32_t partition_id);
224
225/**
Edison Aib3e56962018-09-04 19:12:31 +0800226 * \brief Clear the PSA_DOORBELL signal.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200227 *
Edison Aib3e56962018-09-04 19:12:31 +0800228 * \retval void Success.
229 * \retval "Does not return" The Secure Partition's doorbell signal is not
230 * currently asserted.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200231 */
232void psa_clear(void);
233
234/**
Edison Aib3e56962018-09-04 19:12:31 +0800235 * \brief Inform the SPM that an interrupt has been handled (end of interrupt).
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200236 *
Edison Aib3e56962018-09-04 19:12:31 +0800237 * \param[in] irq_signal The interrupt signal that has been processed.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200238 *
Edison Aib3e56962018-09-04 19:12:31 +0800239 * \retval void Success.
240 * \retval "Does not return" The call is invalid, one or more of the
241 * following are true:
242 * \arg irq_signal is not an interrupt signal.
243 * \arg irq_signal indicates more than one signal.
244 * \arg irq_signal is not currently asserted.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200245 */
Edison Aib3e56962018-09-04 19:12:31 +0800246void psa_eoi(psa_signal_t irq_signal);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200247
248#ifdef __cplusplus
249}
250#endif
251
252#endif /* __PSA_SERVICE_H__ */