blob: 324622456059da32b7010d1969b368bca6469417 [file] [log] [blame]
Patrick Williams975a06f2022-10-21 14:42:47 -05001From 8c1bc5a7ae525d64802e2a06746f698f54cf07ca Mon Sep 17 00:00:00 2001
2From: Vishnu Banavath <vishnu.banavath@arm.com>
3Date: Fri, 3 Dec 2021 19:05:18 +0000
4Subject: [PATCH 04/19] add psa client definitions for ff-m
5
6Add PSA client definitions in common include to add future
7ff-m support.
8
9Upstream-Status: Pending
10Signed-off-by: Vishnu Banavath <vishnu.banavath@arm.com>
11Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
12---
13 .../service/common/include/psa/client.h | 194 ++++++++++++++++++
14 components/service/common/include/psa/sid.h | 71 +++++++
15 2 files changed, 265 insertions(+)
16 create mode 100644 components/service/common/include/psa/client.h
17 create mode 100644 components/service/common/include/psa/sid.h
18
19diff --git a/components/service/common/include/psa/client.h b/components/service/common/include/psa/client.h
20new file mode 100644
21index 000000000000..69ccf14f40a3
22--- /dev/null
23+++ b/components/service/common/include/psa/client.h
24@@ -0,0 +1,194 @@
25+/*
26+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
27+ *
28+ * SPDX-License-Identifier: BSD-3-Clause
29+ */
30+
31+#ifndef SERVICE_PSA_IPC_H
32+#define SERVICE_PSA_IPC_H
33+
34+#include <stddef.h>
35+#include <stdint.h>
36+
37+#include <rpc_caller.h>
38+#include <psa/error.h>
39+
40+#ifdef __cplusplus
41+extern "C" {
42+#endif
43+
44+#ifndef IOVEC_LEN
45+#define IOVEC_LEN(arr) ((uint32_t)(sizeof(arr)/sizeof(arr[0])))
46+#endif
47+
48+/*********************** PSA Client Macros and Types *************************/
49+
50+typedef int32_t psa_handle_t;
51+
52+/**
53+ * The version of the PSA Framework API that is being used to build the calling
54+ * firmware. Only part of features of FF-M v1.1 have been implemented. FF-M v1.1
55+ * is compatible with v1.0.
56+ */
57+#define PSA_FRAMEWORK_VERSION (0x0101u)
58+
59+/**
60+ * Return value from psa_version() if the requested RoT Service is not present
61+ * in the system.
62+ */
63+#define PSA_VERSION_NONE (0u)
64+
65+/**
66+ * The zero-value null handle can be assigned to variables used in clients and
67+ * RoT Services, indicating that there is no current connection or message.
68+ */
69+#define PSA_NULL_HANDLE ((psa_handle_t)0)
70+
71+/**
72+ * Tests whether a handle value returned by psa_connect() is valid.
73+ */
74+#define PSA_HANDLE_IS_VALID(handle) ((psa_handle_t)(handle) > 0)
75+
76+/**
77+ * Converts the handle value returned from a failed call psa_connect() into
78+ * an error code.
79+ */
80+#define PSA_HANDLE_TO_ERROR(handle) ((psa_status_t)(handle))
81+
82+/**
83+ * Maximum number of input and output vectors for a request to psa_call().
84+ */
85+#define PSA_MAX_IOVEC (4u)
86+
87+/**
88+ * An IPC message type that indicates a generic client request.
89+ */
90+#define PSA_IPC_CALL (0)
91+
92+/**
93+ * A read-only input memory region provided to an RoT Service.
94+ */
95+struct __attribute__ ((__packed__)) psa_invec {
96+ uint32_t base; /*!< the start address of the memory buffer */
97+ uint32_t len; /*!< the size in bytes */
98+};
99+
100+/**
101+ * A writable output memory region provided to an RoT Service.
102+ */
103+struct __attribute__ ((__packed__)) psa_outvec {
104+ uint32_t base; /*!< the start address of the memory buffer */
105+ uint32_t len; /*!< the size in bytes */
106+};
107+
108+/*************************** PSA Client API **********************************/
109+
110+/**
111+ * \brief Retrieve the version of the PSA Framework API that is implemented.
112+ *
113+ * \param[in] rpc_caller RPC caller to use
114+ * \return version The version of the PSA Framework implementation
115+ * that is providing the runtime services to the
116+ * caller. The major and minor version are encoded
117+ * as follows:
118+ * \arg version[15:8] -- major version number.
119+ * \arg version[7:0] -- minor version number.
120+ */
121+uint32_t psa_framework_version(struct rpc_caller *caller);
122+
123+/**
124+ * \brief Retrieve the version of an RoT Service or indicate that it is not
125+ * present on this system.
126+ *
127+ * \param[in] rpc_caller RPC caller to use
128+ * \param[in] sid ID of the RoT Service to query.
129+ *
130+ * \retval PSA_VERSION_NONE The RoT Service is not implemented, or the
131+ * caller is not permitted to access the service.
132+ * \retval > 0 The version of the implemented RoT Service.
133+ */
134+uint32_t psa_version(struct rpc_caller *caller, uint32_t sid);
135+
136+/**
137+ * \brief Connect to an RoT Service by its SID.
138+ *
139+ * \param[in] rpc_caller RPC caller to use
140+ * \param[in] sid ID of the RoT Service to connect to.
141+ * \param[in] version Requested version of the RoT Service.
142+ *
143+ * \retval > 0 A handle for the connection.
144+ * \retval PSA_ERROR_CONNECTION_REFUSED The SPM or RoT Service has refused the
145+ * connection.
146+ * \retval PSA_ERROR_CONNECTION_BUSY The SPM or RoT Service cannot make the
147+ * connection at the moment.
148+ * \retval "PROGRAMMER ERROR" The call is a PROGRAMMER ERROR if one or more
149+ * of the following are true:
150+ * \arg The RoT Service ID is not present.
151+ * \arg The RoT Service version is not supported.
152+ * \arg The caller is not allowed to access the RoT
153+ * service.
154+ */
155+psa_handle_t psa_connect(struct rpc_caller *caller, uint32_t sid,
156+ uint32_t version);
157+
158+/**
159+ * \brief Call an RoT Service on an established connection.
160+ *
161+ * \note FF-M 1.0 proposes 6 parameters for psa_call but the secure gateway ABI
162+ * support at most 4 parameters. TF-M chooses to encode 'in_len',
163+ * 'out_len', and 'type' into a 32-bit integer to improve efficiency.
164+ * Compared with struct-based encoding, this method saves extra memory
165+ * check and memory copy operation. The disadvantage is that the 'type'
166+ * range has to be reduced into a 16-bit integer. So with this encoding,
167+ * the valid range for 'type' is 0-32767.
168+ *
169+ * \param[in] rpc_caller RPC caller to use
170+ * \param[in] handle A handle to an established connection.
171+ * \param[in] type The request type.
172+ * Must be zero( \ref PSA_IPC_CALL) or positive.
173+ * \param[in] in_vec Array of input \ref psa_invec structures.
174+ * \param[in] in_len Number of input \ref psa_invec structures.
175+ * \param[in,out] out_vec Array of output \ref psa_outvec structures.
176+ * \param[in] out_len Number of output \ref psa_outvec structures.
177+ *
178+ * \retval >=0 RoT Service-specific status value.
179+ * \retval <0 RoT Service-specific error code.
180+ * \retval PSA_ERROR_PROGRAMMER_ERROR The connection has been terminated by the
181+ * RoT Service. The call is a PROGRAMMER ERROR if
182+ * one or more of the following are true:
183+ * \arg An invalid handle was passed.
184+ * \arg The connection is already handling a request.
185+ * \arg type < 0.
186+ * \arg An invalid memory reference was provided.
187+ * \arg in_len + out_len > PSA_MAX_IOVEC.
188+ * \arg The message is unrecognized by the RoT
189+ * Service or incorrectly formatted.
190+ */
191+psa_status_t psa_call(struct rpc_caller *caller, psa_handle_t handle,
192+ int32_t type, const struct psa_invec *in_vec,
193+ size_t in_len, struct psa_outvec *out_vec, size_t out_len);
194+
195+/**
196+ * \brief Close a connection to an RoT Service.
197+ *
198+ * \param[in] rpc_caller RPC caller to use
199+ * \param[in] handle A handle to an established connection, or the
200+ * null handle.
201+ *
202+ * \retval void Success.
203+ * \retval "PROGRAMMER ERROR" The call is a PROGRAMMER ERROR if one or more
204+ * of the following are true:
205+ * \arg An invalid handle was provided that is not
206+ * the null handle.
207+ * \arg The connection is currently handling a
208+ * request.
209+ */
210+void psa_close(struct rpc_caller *caller, psa_handle_t handle);
211+
212+#ifdef __cplusplus
213+}
214+#endif
215+
216+#endif /* SERVICE_PSA_IPC_H */
217+
218+
219diff --git a/components/service/common/include/psa/sid.h b/components/service/common/include/psa/sid.h
220new file mode 100644
221index 000000000000..aaa973c6e987
222--- /dev/null
223+++ b/components/service/common/include/psa/sid.h
224@@ -0,0 +1,71 @@
225+/*
226+ * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
227+ *
228+ * SPDX-License-Identifier: BSD-3-Clause
229+ *
230+ */
231+
232+#ifndef __PSA_MANIFEST_SID_H__
233+#define __PSA_MANIFEST_SID_H__
234+
235+#ifdef __cplusplus
236+extern "C" {
237+#endif
238+
239+/******** TFM_SP_PS ********/
240+#define TFM_PROTECTED_STORAGE_SERVICE_SID (0x00000060U)
241+#define TFM_PROTECTED_STORAGE_SERVICE_VERSION (1U)
242+#define TFM_PROTECTED_STORAGE_SERVICE_HANDLE (0x40000101U)
243+
244+/* Invalid UID */
245+#define TFM_PS_INVALID_UID 0
246+
247+/* PS message types that distinguish PS services. */
248+#define TFM_PS_SET 1001
249+#define TFM_PS_GET 1002
250+#define TFM_PS_GET_INFO 1003
251+#define TFM_PS_REMOVE 1004
252+#define TFM_PS_GET_SUPPORT 1005
253+
254+/******** TFM_SP_ITS ********/
255+#define TFM_INTERNAL_TRUSTED_STORAGE_SERVICE_SID (0x00000070U)
256+#define TFM_INTERNAL_TRUSTED_STORAGE_SERVICE_VERSION (1U)
257+#define TFM_INTERNAL_TRUSTED_STORAGE_SERVICE_HANDLE (0x40000102U)
258+
259+/******** TFM_SP_CRYPTO ********/
260+#define TFM_CRYPTO_SID (0x00000080U)
261+#define TFM_CRYPTO_VERSION (1U)
262+#define TFM_CRYPTO_HANDLE (0x40000100U)
263+
264+/******** TFM_SP_PLATFORM ********/
265+#define TFM_SP_PLATFORM_SYSTEM_RESET_SID (0x00000040U)
266+#define TFM_SP_PLATFORM_SYSTEM_RESET_VERSION (1U)
267+#define TFM_SP_PLATFORM_IOCTL_SID (0x00000041U)
268+#define TFM_SP_PLATFORM_IOCTL_VERSION (1U)
269+#define TFM_SP_PLATFORM_NV_COUNTER_SID (0x00000042U)
270+#define TFM_SP_PLATFORM_NV_COUNTER_VERSION (1U)
271+
272+/******** TFM_SP_INITIAL_ATTESTATION ********/
273+#define TFM_ATTESTATION_SERVICE_SID (0x00000020U)
274+#define TFM_ATTESTATION_SERVICE_VERSION (1U)
275+#define TFM_ATTESTATION_SERVICE_HANDLE (0x40000103U)
276+
277+/******** TFM_SP_FWU ********/
278+#define TFM_FWU_WRITE_SID (0x000000A0U)
279+#define TFM_FWU_WRITE_VERSION (1U)
280+#define TFM_FWU_INSTALL_SID (0x000000A1U)
281+#define TFM_FWU_INSTALL_VERSION (1U)
282+#define TFM_FWU_ABORT_SID (0x000000A2U)
283+#define TFM_FWU_ABORT_VERSION (1U)
284+#define TFM_FWU_QUERY_SID (0x000000A3U)
285+#define TFM_FWU_QUERY_VERSION (1U)
286+#define TFM_FWU_REQUEST_REBOOT_SID (0x000000A4U)
287+#define TFM_FWU_REQUEST_REBOOT_VERSION (1U)
288+#define TFM_FWU_ACCEPT_SID (0x000000A5U)
289+#define TFM_FWU_ACCEPT_VERSION (1U)
290+
291+#ifdef __cplusplus
292+}
293+#endif
294+
295+#endif /* __PSA_MANIFEST_SID_H__ */
296--
2972.38.0
298