1 
2 /*
3  * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  */
8 
9 #ifndef PSA_CLIENT_H
10 #define PSA_CLIENT_H
11 
12 #include <stddef.h>
13 #include <stdint.h>
14 
15 #include <psa/error.h>
16 
17 #ifndef IOVEC_LEN
18 #define IOVEC_LEN(arr) ((uint32_t)(sizeof(arr)/sizeof(arr[0])))
19 #endif
20 /*********************** PSA Client Macros and Types *************************/
21 /**
22  * The version of the PSA Framework API that is being used to build the calling
23  * firmware. Only part of features of FF-M v1.1 have been implemented. FF-M v1.1
24  * is compatible with v1.0.
25  */
26 #define PSA_FRAMEWORK_VERSION	(0x0101u)
27 /**
28  * Return value from psa_version() if the requested RoT Service is not present
29  * in the system.
30  */
31 #define PSA_VERSION_NONE	(0u)
32 /**
33  * The zero-value null handle can be assigned to variables used in clients and
34  * RoT Services, indicating that there is no current connection or message.
35  */
36 #define PSA_NULL_HANDLE		((psa_handle_t)0)
37 /**
38  * Tests whether a handle value returned by psa_connect() is valid.
39  */
40 #define PSA_HANDLE_IS_VALID(handle)	((psa_handle_t)(handle) > 0)
41 /**
42  * Converts the handle value returned from a failed call psa_connect() into
43  * an error code.
44  */
45 #define PSA_HANDLE_TO_ERROR(handle)	((psa_status_t)(handle))
46 /**
47  * Maximum number of input and output vectors for a request to psa_call().
48  */
49 #define PSA_MAX_IOVEC		(4u)
50 /**
51  * An IPC message type that indicates a generic client request.
52  */
53 #define PSA_IPC_CALL		(0)
54 typedef int32_t psa_handle_t;
55 /**
56  * A read-only input memory region provided to an RoT Service.
57  */
58 typedef struct psa_invec {
59 	const void *base;	/*!< the start address of the memory buffer */
60 	size_t len;		/*!< the size in bytes                      */
61 } psa_invec;
62 /**
63  * A writable output memory region provided to an RoT Service.
64  */
65 typedef struct psa_outvec {
66 	void *base;		/*!< the start address of the memory buffer */
67 	size_t len;		/*!< the size in bytes                      */
68 } psa_outvec;
69 
70 /**
71  * Call an RoT Service on an established connection.
72  *
73  * handle	A handle to an established connection.
74  * type		The request type. Must be zero(PSA_IPC_CALL) or positive.
75  * in_vec	Array of input psa_invec structures.
76  * in_len	Number of input psa_invec structures.
77  * out_vec	Array of output psa_outvec structures.
78  * out_len	Number of output psa_outvec structures.
79  *
80  * Return value >=0	RoT Service-specific status value.
81  * Return value <0	RoT Service-specific error code.
82  *
83  * PSA_ERROR_PROGRAMMER_ERROR:
84  *	- The connection has been terminated by the RoT Service.
85  *
86  * The call is a PROGRAMMER ERROR if one or more of the following are true:
87  *	- An invalid handle was passed.
88  *	- The connection is already handling a request.
89  *	- type < 0.
90  *	- An invalid memory reference was provided.
91  *	- in_len + out_len > PSA_MAX_IOVEC.
92  *	- The message is unrecognized by the RoT.
93  *	- Service or incorrectly formatted.
94  */
95 psa_status_t psa_call(psa_handle_t handle,
96 		      int32_t type,
97 		      const psa_invec *in_vec,
98 		      size_t in_len,
99 		      psa_outvec *out_vec,
100 		      size_t out_len);
101 
102 #endif /* PSA_CLIENT_H */
103