blob: 8fd2d13674c2e690dd7e2a32a2b970fc529c3c86 [file] [log] [blame]
Miklos Balint9ecb24c2018-03-29 15:30:28 +02001/*
Shawn Shan7ef79ec2021-01-21 10:28:18 +08002 * Copyright (c) 2018-2021, 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_CLIENT_H__
9#define __PSA_CLIENT_H__
10
Jamie Fox520fb4d2019-06-13 14:27:21 +010011#include <stddef.h>
12#include <stdint.h>
13
14#include "psa/error.h"
15
Miklos Balint9ecb24c2018-03-29 15:30:28 +020016#ifdef __cplusplus
17extern "C" {
18#endif
19
Edison Aib3e56962018-09-04 19:12:31 +080020/*********************** PSA Client Macros and Types *************************/
Miklos Balint9ecb24c2018-03-29 15:30:28 +020021
Summer Qin4b1d03b2019-07-02 14:56:08 +080022/**
23 * The version of the PSA Framework API that is being used to build the calling
Mingyang Sun9ac44d32021-03-12 14:47:46 +080024 * firmware. Only part of features of FF-M v1.1 have been implemented. FF-M v1.1
25 * is compatible with v1.0.
Summer Qin4b1d03b2019-07-02 14:56:08 +080026 */
Mingyang Sun9ac44d32021-03-12 14:47:46 +080027#define PSA_FRAMEWORK_VERSION (0x0101u)
Miklos Balint9ecb24c2018-03-29 15:30:28 +020028
Summer Qin4b1d03b2019-07-02 14:56:08 +080029/**
30 * Return value from psa_version() if the requested RoT Service is not present
31 * in the system.
32 */
33#define PSA_VERSION_NONE (0u)
Miklos Balint9ecb24c2018-03-29 15:30:28 +020034
Summer Qin4b1d03b2019-07-02 14:56:08 +080035/**
36 * The zero-value null handle can be assigned to variables used in clients and
37 * RoT Services, indicating that there is no current connection or message.
38 */
39#define PSA_NULL_HANDLE ((psa_handle_t)0)
Miklos Balint9ecb24c2018-03-29 15:30:28 +020040
Summer Qin4b1d03b2019-07-02 14:56:08 +080041/**
42 * Tests whether a handle value returned by psa_connect() is valid.
43 */
44#define PSA_HANDLE_IS_VALID(handle) ((psa_handle_t)(handle) > 0)
45
46/**
47 * Converts the handle value returned from a failed call psa_connect() into
48 * an error code.
49 */
50#define PSA_HANDLE_TO_ERROR(handle) ((psa_status_t)(handle))
51
52/**
53 * Maximum number of input and output vectors for a request to psa_call().
54 */
55#define PSA_MAX_IOVEC (4u)
56
57/**
58 * An IPC message type that indicates a generic client request.
59 */
60#define PSA_IPC_CALL (0)
Miklos Balint9ecb24c2018-03-29 15:30:28 +020061
Miklos Balint9ecb24c2018-03-29 15:30:28 +020062typedef int32_t psa_handle_t;
63
64/**
Edison Aib3e56962018-09-04 19:12:31 +080065 * A read-only input memory region provided to an RoT Service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020066 */
67typedef struct psa_invec {
Edison Aib3e56962018-09-04 19:12:31 +080068 const void *base; /*!< the start address of the memory buffer */
69 size_t len; /*!< the size in bytes */
Miklos Balint9ecb24c2018-03-29 15:30:28 +020070} psa_invec;
71
72/**
Edison Aib3e56962018-09-04 19:12:31 +080073 * A writable output memory region provided to an RoT Service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020074 */
75typedef struct psa_outvec {
Edison Aib3e56962018-09-04 19:12:31 +080076 void *base; /*!< the start address of the memory buffer */
77 size_t len; /*!< the size in bytes */
Miklos Balint9ecb24c2018-03-29 15:30:28 +020078} psa_outvec;
79
Edison Aib3e56962018-09-04 19:12:31 +080080/*************************** PSA Client API **********************************/
81
Miklos Balint9ecb24c2018-03-29 15:30:28 +020082/**
83 * \brief Retrieve the version of the PSA Framework API that is implemented.
84 *
Edison Aib3e56962018-09-04 19:12:31 +080085 * \return version The version of the PSA Framework implementation
86 * that is providing the runtime services to the
87 * caller. The major and minor version are encoded
88 * as follows:
89 * \arg version[15:8] -- major version number.
90 * \arg version[7:0] -- minor version number.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020091 */
92uint32_t psa_framework_version(void);
93
Miklos Balint9ecb24c2018-03-29 15:30:28 +020094/**
Summer Qin4b1d03b2019-07-02 14:56:08 +080095 * \brief Retrieve the version of an RoT Service or indicate that it is not
96 * present on this system.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020097 *
Edison Aib3e56962018-09-04 19:12:31 +080098 * \param[in] sid ID of the RoT Service to query.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020099 *
Edison Aib3e56962018-09-04 19:12:31 +0800100 * \retval PSA_VERSION_NONE The RoT Service is not implemented, or the
101 * caller is not permitted to access the service.
Summer Qin4b1d03b2019-07-02 14:56:08 +0800102 * \retval > 0 The version of the implemented RoT Service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200103 */
104uint32_t psa_version(uint32_t sid);
105
106/**
Edison Aib3e56962018-09-04 19:12:31 +0800107 * \brief Connect to an RoT Service by its SID.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200108 *
Edison Aib3e56962018-09-04 19:12:31 +0800109 * \param[in] sid ID of the RoT Service to connect to.
Summer Qin4b1d03b2019-07-02 14:56:08 +0800110 * \param[in] version Requested version of the RoT Service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200111 *
Edison Aib3e56962018-09-04 19:12:31 +0800112 * \retval > 0 A handle for the connection.
Summer Qin4b1d03b2019-07-02 14:56:08 +0800113 * \retval PSA_ERROR_CONNECTION_REFUSED The SPM or RoT Service has refused the
Edison Aib3e56962018-09-04 19:12:31 +0800114 * connection.
Summer Qin4b1d03b2019-07-02 14:56:08 +0800115 * \retval PSA_ERROR_CONNECTION_BUSY The SPM or RoT Service cannot make the
Edison Aib3e56962018-09-04 19:12:31 +0800116 * connection at the moment.
Summer Qin4b1d03b2019-07-02 14:56:08 +0800117 * \retval "PROGRAMMER ERROR" The call is a PROGRAMMER ERROR if one or more
118 * of the following are true:
119 * \arg The RoT Service ID is not present.
120 * \arg The RoT Service version is not supported.
121 * \arg The caller is not allowed to access the RoT
122 * service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200123 */
Summer Qin4b1d03b2019-07-02 14:56:08 +0800124psa_handle_t psa_connect(uint32_t sid, uint32_t version);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200125
126/**
Edison Aib3e56962018-09-04 19:12:31 +0800127 * \brief Call an RoT Service on an established connection.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200128 *
Edison Aib3e56962018-09-04 19:12:31 +0800129 * \param[in] handle A handle to an established connection.
Edison Aib6d91ad2020-07-16 17:42:40 +0800130 * \param[in] type The request type.
Summer Qin632b3e02019-07-29 15:34:38 +0800131 * Must be zero( \ref PSA_IPC_CALL) or positive.
Edison Aib3e56962018-09-04 19:12:31 +0800132 * \param[in] in_vec Array of input \ref psa_invec structures.
133 * \param[in] in_len Number of input \ref psa_invec structures.
Shawn Shan7ef79ec2021-01-21 10:28:18 +0800134 * \param[in,out] out_vec Array of output \ref psa_outvec structures.
Edison Aib3e56962018-09-04 19:12:31 +0800135 * \param[in] out_len Number of output \ref psa_outvec structures.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200136 *
Edison Aib3e56962018-09-04 19:12:31 +0800137 * \retval >=0 RoT Service-specific status value.
138 * \retval <0 RoT Service-specific error code.
Summer Qin4b1d03b2019-07-02 14:56:08 +0800139 * \retval PSA_ERROR_PROGRAMMER_ERROR The connection has been terminated by the
140 * RoT Service. The call is a PROGRAMMER ERROR if
141 * one or more of the following are true:
Edison Aib3e56962018-09-04 19:12:31 +0800142 * \arg An invalid handle was passed.
143 * \arg The connection is already handling a request.
Summer Qin4b1d03b2019-07-02 14:56:08 +0800144 * \arg type < 0.
Edison Aib3e56962018-09-04 19:12:31 +0800145 * \arg An invalid memory reference was provided.
146 * \arg in_len + out_len > PSA_MAX_IOVEC.
147 * \arg The message is unrecognized by the RoT
148 * Service or incorrectly formatted.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200149 */
Summer Qin4b1d03b2019-07-02 14:56:08 +0800150psa_status_t psa_call(psa_handle_t handle, int32_t type,
Edison Aib3e56962018-09-04 19:12:31 +0800151 const psa_invec *in_vec,
152 size_t in_len,
153 psa_outvec *out_vec,
154 size_t out_len);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200155
156/**
Edison Aib3e56962018-09-04 19:12:31 +0800157 * \brief Close a connection to an RoT Service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200158 *
Edison Aib3e56962018-09-04 19:12:31 +0800159 * \param[in] handle A handle to an established connection, or the
160 * null handle.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200161 *
Edison Aib3e56962018-09-04 19:12:31 +0800162 * \retval void Success.
Summer Qin4b1d03b2019-07-02 14:56:08 +0800163 * \retval "PROGRAMMER ERROR" The call is a PROGRAMMER ERROR if one or more
164 * of the following are true:
Edison Aib3e56962018-09-04 19:12:31 +0800165 * \arg An invalid handle was provided that is not
166 * the null handle.
Summer Qin4b1d03b2019-07-02 14:56:08 +0800167 * \arg The connection is currently handling a
168 * request.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200169 */
170void psa_close(psa_handle_t handle);
171
172#ifdef __cplusplus
173}
174#endif
175
176#endif /* __PSA_CLIENT_H__ */