blob: 33e3f2d41582b9dcb621abf0931e8c0d15113165 [file] [log] [blame]
Miklos Balint9ecb24c2018-03-29 15:30:28 +02001/*
Mate Toth-Pal2a6f8c22018-12-13 16:37:17 +01002 * 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_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
Edison Aib3e56962018-09-04 19:12:31 +080022#define PSA_FRAMEWORK_VERSION (0x0100)
Miklos Balint9ecb24c2018-03-29 15:30:28 +020023
24#define PSA_VERSION_NONE (0)
25
26/* PSA response types */
Miklos Balint9ecb24c2018-03-29 15:30:28 +020027#define PSA_CONNECTION_REFUSED (INT32_MIN + 1)
Edison Aib3e56962018-09-04 19:12:31 +080028#define PSA_CONNECTION_BUSY (INT32_MIN + 2)
Miklos Balint9ecb24c2018-03-29 15:30:28 +020029#define PSA_DROP_CONNECTION (INT32_MIN)
30
31/* PSA message handles */
32#define PSA_NULL_HANDLE ((psa_handle_t)0)
33
Miklos Balint9ecb24c2018-03-29 15:30:28 +020034typedef int32_t psa_handle_t;
35
36/**
Edison Aib3e56962018-09-04 19:12:31 +080037 * A read-only input memory region provided to an RoT Service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020038 */
39typedef struct psa_invec {
Edison Aib3e56962018-09-04 19:12:31 +080040 const void *base; /*!< the start address of the memory buffer */
41 size_t len; /*!< the size in bytes */
Miklos Balint9ecb24c2018-03-29 15:30:28 +020042} psa_invec;
43
44/**
Edison Aib3e56962018-09-04 19:12:31 +080045 * A writable output memory region provided to an RoT Service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020046 */
47typedef struct psa_outvec {
Edison Aib3e56962018-09-04 19:12:31 +080048 void *base; /*!< the start address of the memory buffer */
49 size_t len; /*!< the size in bytes */
Miklos Balint9ecb24c2018-03-29 15:30:28 +020050} psa_outvec;
51
Edison Aib3e56962018-09-04 19:12:31 +080052/*************************** PSA Client API **********************************/
53
Miklos Balint9ecb24c2018-03-29 15:30:28 +020054/**
55 * \brief Retrieve the version of the PSA Framework API that is implemented.
56 *
Edison Aib3e56962018-09-04 19:12:31 +080057 * \return version The version of the PSA Framework implementation
58 * that is providing the runtime services to the
59 * caller. The major and minor version are encoded
60 * as follows:
61 * \arg version[15:8] -- major version number.
62 * \arg version[7:0] -- minor version number.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020063 */
64uint32_t psa_framework_version(void);
65
Miklos Balint9ecb24c2018-03-29 15:30:28 +020066/**
Edison Aib3e56962018-09-04 19:12:31 +080067 * \brief Retrieve the minor version of an RoT Service or indicate that it is
68 * not present on this system.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020069 *
Edison Aib3e56962018-09-04 19:12:31 +080070 * \param[in] sid ID of the RoT Service to query.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020071 *
Edison Aib3e56962018-09-04 19:12:31 +080072 * \retval PSA_VERSION_NONE The RoT Service is not implemented, or the
73 * caller is not permitted to access the service.
74 * \retval > 0 The minor version of the implemented RoT
75 * Service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020076 */
77uint32_t psa_version(uint32_t sid);
78
79/**
Edison Aib3e56962018-09-04 19:12:31 +080080 * \brief Connect to an RoT Service by its SID.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020081 *
Edison Aib3e56962018-09-04 19:12:31 +080082 * \param[in] sid ID of the RoT Service to connect to.
83 * \param[in] minor_version Requested version of the RoT Service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020084 *
Edison Aib3e56962018-09-04 19:12:31 +080085 * \retval > 0 A handle for the connection.
86 * \retval PSA_CONNECTION_REFUSED The SPM or RoT Service has refused the
87 * connection.
88 * \retval PSA_CONNECTION_BUSY The SPM or RoT Service cannot make the
89 * connection at the moment.
90 * \retval "Does not return" The RoT Service ID and version are not
91 * supported, or the caller is not permitted to
92 * access the service.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020093 */
94psa_handle_t psa_connect(uint32_t sid, uint32_t minor_version);
95
96/**
Edison Aib3e56962018-09-04 19:12:31 +080097 * \brief Call an RoT Service on an established connection.
Miklos Balint9ecb24c2018-03-29 15:30:28 +020098 *
Edison Aib3e56962018-09-04 19:12:31 +080099 * \param[in] handle A handle to an established connection.
100 * \param[in] in_vec Array of input \ref psa_invec structures.
101 * \param[in] in_len Number of input \ref psa_invec structures.
102 * \param[in/out] out_vec Array of output \ref psa_outvec structures.
103 * \param[in] out_len Number of output \ref psa_outvec structures.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200104 *
Edison Aib3e56962018-09-04 19:12:31 +0800105 * \retval >=0 RoT Service-specific status value.
106 * \retval <0 RoT Service-specific error code.
107 * \retval PSA_DROP_CONNECTION The connection has been dropped by the RoT
108 * Service. This indicates that either this or
109 * a previous message was invalid.
110 * \retval "Does not return" The call is invalid, one or more of the
111 * following are true:
112 * \arg An invalid handle was passed.
113 * \arg The connection is already handling a request.
114 * \arg An invalid memory reference was provided.
115 * \arg in_len + out_len > PSA_MAX_IOVEC.
116 * \arg The message is unrecognized by the RoT
117 * Service or incorrectly formatted.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200118 */
Edison Aib3e56962018-09-04 19:12:31 +0800119psa_status_t psa_call(psa_handle_t handle,
120 const psa_invec *in_vec,
121 size_t in_len,
122 psa_outvec *out_vec,
123 size_t out_len);
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200124
125/**
Edison Aib3e56962018-09-04 19:12:31 +0800126 * \brief Close a connection to an RoT Service.
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, or the
129 * null handle.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200130 *
Edison Aib3e56962018-09-04 19:12:31 +0800131 * \retval void Success.
132 * \retval "Does not return" The call is invalid, one or more of the
133 * following are true:
134 * \arg An invalid handle was provided that is not
135 * the null handle.
136 * \arg The connection is handling a request.
Miklos Balint9ecb24c2018-03-29 15:30:28 +0200137 */
138void psa_close(psa_handle_t handle);
139
140#ifdef __cplusplus
141}
142#endif
143
144#endif /* __PSA_CLIENT_H__ */