blob: dbe0e72a70b30da2684946d3ea50df94cc24e929 [file] [log] [blame]
Miklos Balint9ecb24c2018-03-29 15:30:28 +02001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
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;
35
36/**
37 * A read-only input memory region provided to a RoT Service.
38 */
39typedef struct psa_invec {
40 const void *base; /*!< the start address of the memory buffer */
41 size_t len; /*!< the size in bytes */
42} psa_invec;
43
44/**
45 * A writable output memory region provided to a RoT Service.
46 */
47typedef struct psa_outvec {
48 void *base; /*!< the start address of the memory buffer */
49 size_t len; /*!< the size in bytes */
50} psa_outvec;
51
52/**
53 * \brief Retrieve the version of the PSA Framework API that is implemented.
54 *
55 * \return The version of the PSA Framework implementation that is providing
56 * the runtime services to the caller.
57 * \return The major and minor version are encoded as follows:
58 * \arg version[15:8] -- major version number
59 * \arg version[7:0] -- minor version number
60 */
61uint32_t psa_framework_version(void);
62
63/* ******** ******** PSA Client API ******** ******** */
64
65/**
66 * \brief Retrieve the minor version of a RoT Service or indicate that
67 * it is not present on this system.
68 *
69 * \param[in] sid ID of the RoT Service to query
70 *
71 * \retval PSA_VERSION_NONE The RoT Service is not implemented, or the
72 * caller is not permitted to access the service
73 * \retval >0 The minor version of the implemented RoT Service
74 */
75uint32_t psa_version(uint32_t sid);
76
77/**
78 * \brief Connect to a RoT Service by its SID.
79 *
80 * \param[in] sid ID of the RoT Service to connect to
81 * \param[in] minor_version Requested version of the RoT Service
82 *
83 * \retval >0 A handle for the connection
84 * \retval PSA_CONNECTION_REFUSED The RoT Service has refused the connection
85 * \retval "Does not return" The RoT Service ID and version are not
86 * supported, or the caller is not permitted
87 * to access the service
88 */
89psa_handle_t psa_connect(uint32_t sid, uint32_t minor_version);
90
91/**
92 * \brief Calls a RoT Service on an established connection.
93 *
94 * \param[in] handle A handle to an established connection
95 * \param[in] in_vec Array of input \ref psa_invec structures
96 * \param[in] in_len Number of input \ref psa_invec structures
97 * \param[in] out_vec Array of input \ref psa_outvec structures
98 * \param[in] in_len Number of input \ref psa_outvec structures
99 *
100 * \retval >=0 Application-specific return code
101 * \retval <0 Application-specific error code
102 * \retval PSA_DROP_CONNECTION The connection has been dropped by the RoT
103 * Service. This indicates that either this or
104 * a previous message was invalid
105 * \retval "Does not return" The call is invalid, one or more of the following
106 * are true:
107 * \arg An invalid handle was passed
108 * \arg An invalid memory reference was provided
109 * \arg in_len + out_len > PSA_MAX_IOVEC
110 * \arg The message is unrecognized by the RoT Service
111 * or incorrectly formatted
112 */
113psa_error_t psa_call(psa_handle_t handle,
114 const psa_invec *in_vec,
115 size_t in_len,
116 const psa_outvec *out_vec,
117 size_t out_len);
118
119/**
120 * \brief Closes a connection to a RoT Service.
121 *
122 * \param[in] handle A handle to an established connection, or the
123 * null handle
124 *
125 * \retval void Success
126 * \retval "Does not return" An invalid handle was provided that is not the
127 * null handle
128 */
129void psa_close(psa_handle_t handle);
130
131#ifdef __cplusplus
132}
133#endif
134
135#endif /* __PSA_CLIENT_H__ */