blob: 1fc8637b713b11b39ba90bafda685b61d2c7b72a [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
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#include <stdint.h>
16#include <stddef.h>
17
18/* ******** ******** PSA Common API ******** ******** */
19
20/* FixMe: PSA FF v0.9 has not been released. All PSA API subject to change */
21#define PSA_FRAMEWORK_VERSION (0x0009)
22
23#define PSA_VERSION_NONE (0)
24
25/* PSA response types */
26#define PSA_SUCCESS (0)
27#define PSA_CONNECTION_REFUSED (INT32_MIN + 1)
28#define PSA_DROP_CONNECTION (INT32_MIN)
29
30/* PSA message handles */
31#define PSA_NULL_HANDLE ((psa_handle_t)0)
32
33typedef int32_t psa_error_t;
34typedef int32_t psa_handle_t;
Mate Toth-Pal2a6f8c22018-12-13 16:37:17 +010035typedef int32_t psa_status_t;
Miklos Balint9ecb24c2018-03-29 15:30:28 +020036
37/**
38 * A read-only input memory region provided to a RoT Service.
39 */
40typedef struct psa_invec {
41 const void *base; /*!< the start address of the memory buffer */
42 size_t len; /*!< the size in bytes */
43} psa_invec;
44
45/**
46 * A writable output memory region provided to a RoT Service.
47 */
48typedef struct psa_outvec {
49 void *base; /*!< the start address of the memory buffer */
50 size_t len; /*!< the size in bytes */
51} psa_outvec;
52
53/**
54 * \brief Retrieve the version of the PSA Framework API that is implemented.
55 *
56 * \return The version of the PSA Framework implementation that is providing
57 * the runtime services to the caller.
58 * \return The major and minor version are encoded as follows:
59 * \arg version[15:8] -- major version number
60 * \arg version[7:0] -- minor version number
61 */
62uint32_t psa_framework_version(void);
63
64/* ******** ******** PSA Client API ******** ******** */
65
66/**
67 * \brief Retrieve the minor version of a RoT Service or indicate that
68 * it is not present on this system.
69 *
70 * \param[in] sid ID of the RoT Service to query
71 *
72 * \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 Service
75 */
76uint32_t psa_version(uint32_t sid);
77
78/**
79 * \brief Connect to a RoT Service by its SID.
80 *
81 * \param[in] sid ID of the RoT Service to connect to
82 * \param[in] minor_version Requested version of the RoT Service
83 *
84 * \retval >0 A handle for the connection
85 * \retval PSA_CONNECTION_REFUSED The RoT Service has refused the connection
86 * \retval "Does not return" The RoT Service ID and version are not
87 * supported, or the caller is not permitted
88 * to access the service
89 */
90psa_handle_t psa_connect(uint32_t sid, uint32_t minor_version);
91
92/**
93 * \brief Calls a RoT Service on an established connection.
94 *
95 * \param[in] handle A handle to an established connection
96 * \param[in] in_vec Array of input \ref psa_invec structures
97 * \param[in] in_len Number of input \ref psa_invec structures
98 * \param[in] out_vec Array of input \ref psa_outvec structures
99 * \param[in] in_len Number of input \ref psa_outvec structures
100 *
101 * \retval >=0 Application-specific return code
102 * \retval <0 Application-specific error code
103 * \retval PSA_DROP_CONNECTION The connection has been dropped by the RoT
104 * Service. This indicates that either this or
105 * a previous message was invalid
106 * \retval "Does not return" The call is invalid, one or more of the following
107 * are true:
108 * \arg An invalid handle was passed
109 * \arg An invalid memory reference was provided
110 * \arg in_len + out_len > PSA_MAX_IOVEC
111 * \arg The message is unrecognized by the RoT Service
112 * or incorrectly formatted
113 */
114psa_error_t psa_call(psa_handle_t handle,
115 const psa_invec *in_vec,
116 size_t in_len,
117 const psa_outvec *out_vec,
118 size_t out_len);
119
120/**
121 * \brief Closes a connection to a RoT Service.
122 *
123 * \param[in] handle A handle to an established connection, or the
124 * null handle
125 *
126 * \retval void Success
127 * \retval "Does not return" An invalid handle was provided that is not the
128 * null handle
129 */
130void psa_close(psa_handle_t handle);
131
132#ifdef __cplusplus
133}
134#endif
135
136#endif /* __PSA_CLIENT_H__ */