blob: 6df761a4503a3cd86a62ee7560062ce506bd38cf [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
24 * firmware.
25 */
26#define PSA_FRAMEWORK_VERSION (0x0100u)
Miklos Balint9ecb24c2018-03-29 15:30:28 +020027
Summer Qin4b1d03b2019-07-02 14:56:08 +080028/**
29 * Return value from psa_version() if the requested RoT Service is not present
30 * in the system.
31 */
32#define PSA_VERSION_NONE (0u)
Miklos Balint9ecb24c2018-03-29 15:30:28 +020033
Summer Qin4b1d03b2019-07-02 14:56:08 +080034/**
35 * The zero-value null handle can be assigned to variables used in clients and
36 * RoT Services, indicating that there is no current connection or message.
37 */
38#define PSA_NULL_HANDLE ((psa_handle_t)0)
Miklos Balint9ecb24c2018-03-29 15:30:28 +020039
Summer Qin4b1d03b2019-07-02 14:56:08 +080040/**
41 * Tests whether a handle value returned by psa_connect() is valid.
42 */
43#define PSA_HANDLE_IS_VALID(handle) ((psa_handle_t)(handle) > 0)
44
45/**
46 * Converts the handle value returned from a failed call psa_connect() into
47 * an error code.
48 */
49#define PSA_HANDLE_TO_ERROR(handle) ((psa_status_t)(handle))
50
51/**
52 * Maximum number of input and output vectors for a request to psa_call().
53 */
54#define PSA_MAX_IOVEC (4u)
55
56/**
57 * An IPC message type that indicates a generic client request.
58 */
59#define PSA_IPC_CALL (0)
Miklos Balint9ecb24c2018-03-29 15:30:28 +020060
Miklos Balint9ecb24c2018-03-29 15:30:28 +020061typedef int32_t psa_handle_t;
62
63/**
Edison Aib3e56962018-09-04 19:12:31 +080064 * A read-only input memory region provided to an RoT Service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020065 */
66typedef struct psa_invec {
Edison Aib3e56962018-09-04 19:12:31 +080067 const void *base; /*!< the start address of the memory buffer */
68 size_t len; /*!< the size in bytes */
Miklos Balint9ecb24c2018-03-29 15:30:28 +020069} psa_invec;
70
71/**
Edison Aib3e56962018-09-04 19:12:31 +080072 * A writable output memory region provided to an RoT Service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020073 */
74typedef struct psa_outvec {
Edison Aib3e56962018-09-04 19:12:31 +080075 void *base; /*!< the start address of the memory buffer */
76 size_t len; /*!< the size in bytes */
Miklos Balint9ecb24c2018-03-29 15:30:28 +020077} psa_outvec;
78
Edison Aib3e56962018-09-04 19:12:31 +080079/*************************** PSA Client API **********************************/
80
Miklos Balint9ecb24c2018-03-29 15:30:28 +020081/**
82 * \brief Retrieve the version of the PSA Framework API that is implemented.
83 *
Edison Aib3e56962018-09-04 19:12:31 +080084 * \return version The version of the PSA Framework implementation
85 * that is providing the runtime services to the
86 * caller. The major and minor version are encoded
87 * as follows:
88 * \arg version[15:8] -- major version number.
89 * \arg version[7:0] -- minor version number.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020090 */
91uint32_t psa_framework_version(void);
92
Miklos Balint9ecb24c2018-03-29 15:30:28 +020093/**
Summer Qin4b1d03b2019-07-02 14:56:08 +080094 * \brief Retrieve the version of an RoT Service or indicate that it is not
95 * present on this system.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020096 *
Edison Aib3e56962018-09-04 19:12:31 +080097 * \param[in] sid ID of the RoT Service to query.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020098 *
Edison Aib3e56962018-09-04 19:12:31 +080099 * \retval PSA_VERSION_NONE The RoT Service is not implemented, or the
100 * caller is not permitted to access the service.
Summer Qin4b1d03b2019-07-02 14:56:08 +0800101 * \retval > 0 The version of the implemented RoT Service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200102 */
103uint32_t psa_version(uint32_t sid);
104
105/**
Edison Aib3e56962018-09-04 19:12:31 +0800106 * \brief Connect to an RoT Service by its SID.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200107 *
Edison Aib3e56962018-09-04 19:12:31 +0800108 * \param[in] sid ID of the RoT Service to connect to.
Summer Qin4b1d03b2019-07-02 14:56:08 +0800109 * \param[in] version Requested version of the RoT Service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200110 *
Edison Aib3e56962018-09-04 19:12:31 +0800111 * \retval > 0 A handle for the connection.
Summer Qin4b1d03b2019-07-02 14:56:08 +0800112 * \retval PSA_ERROR_CONNECTION_REFUSED The SPM or RoT Service has refused the
Edison Aib3e56962018-09-04 19:12:31 +0800113 * connection.
Summer Qin4b1d03b2019-07-02 14:56:08 +0800114 * \retval PSA_ERROR_CONNECTION_BUSY The SPM or RoT Service cannot make the
Edison Aib3e56962018-09-04 19:12:31 +0800115 * connection at the moment.
Summer Qin4b1d03b2019-07-02 14:56:08 +0800116 * \retval "PROGRAMMER ERROR" The call is a PROGRAMMER ERROR if one or more
117 * of the following are true:
118 * \arg The RoT Service ID is not present.
119 * \arg The RoT Service version is not supported.
120 * \arg The caller is not allowed to access the RoT
121 * service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200122 */
Summer Qin4b1d03b2019-07-02 14:56:08 +0800123psa_handle_t psa_connect(uint32_t sid, uint32_t version);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200124
125/**
Edison Aib3e56962018-09-04 19:12:31 +0800126 * \brief Call an RoT Service on an established connection.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200127 *
Edison Aib3e56962018-09-04 19:12:31 +0800128 * \param[in] handle A handle to an established connection.
Edison Aib6d91ad2020-07-16 17:42:40 +0800129 * \param[in] type The request type.
Summer Qin632b3e02019-07-29 15:34:38 +0800130 * Must be zero( \ref PSA_IPC_CALL) or positive.
Edison Aib3e56962018-09-04 19:12:31 +0800131 * \param[in] in_vec Array of input \ref psa_invec structures.
132 * \param[in] in_len Number of input \ref psa_invec structures.
Shawn Shan7ef79ec2021-01-21 10:28:18 +0800133 * \param[in,out] out_vec Array of output \ref psa_outvec structures.
Edison Aib3e56962018-09-04 19:12:31 +0800134 * \param[in] out_len Number of output \ref psa_outvec structures.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200135 *
Edison Aib3e56962018-09-04 19:12:31 +0800136 * \retval >=0 RoT Service-specific status value.
137 * \retval <0 RoT Service-specific error code.
Summer Qin4b1d03b2019-07-02 14:56:08 +0800138 * \retval PSA_ERROR_PROGRAMMER_ERROR The connection has been terminated by the
139 * RoT Service. The call is a PROGRAMMER ERROR if
140 * one or more of the following are true:
Edison Aib3e56962018-09-04 19:12:31 +0800141 * \arg An invalid handle was passed.
142 * \arg The connection is already handling a request.
Summer Qin4b1d03b2019-07-02 14:56:08 +0800143 * \arg type < 0.
Edison Aib3e56962018-09-04 19:12:31 +0800144 * \arg An invalid memory reference was provided.
145 * \arg in_len + out_len > PSA_MAX_IOVEC.
146 * \arg The message is unrecognized by the RoT
147 * Service or incorrectly formatted.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200148 */
Summer Qin4b1d03b2019-07-02 14:56:08 +0800149psa_status_t psa_call(psa_handle_t handle, int32_t type,
Edison Aib3e56962018-09-04 19:12:31 +0800150 const psa_invec *in_vec,
151 size_t in_len,
152 psa_outvec *out_vec,
153 size_t out_len);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200154
155/**
Edison Aib3e56962018-09-04 19:12:31 +0800156 * \brief Close a connection to an RoT Service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200157 *
Edison Aib3e56962018-09-04 19:12:31 +0800158 * \param[in] handle A handle to an established connection, or the
159 * null handle.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200160 *
Edison Aib3e56962018-09-04 19:12:31 +0800161 * \retval void Success.
Summer Qin4b1d03b2019-07-02 14:56:08 +0800162 * \retval "PROGRAMMER ERROR" The call is a PROGRAMMER ERROR if one or more
163 * of the following are true:
Edison Aib3e56962018-09-04 19:12:31 +0800164 * \arg An invalid handle was provided that is not
165 * the null handle.
Summer Qin4b1d03b2019-07-02 14:56:08 +0800166 * \arg The connection is currently handling a
167 * request.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200168 */
169void psa_close(psa_handle_t handle);
170
171#ifdef __cplusplus
172}
173#endif
174
175#endif /* __PSA_CLIENT_H__ */