blob: 3d128f40b2f087ff36250a3835f49fae101dd5d6 [file] [log] [blame]
David Hu49ec08a2019-09-23 16:13:41 +08001/*
David Hude3f79f2019-11-14 16:56:51 +08002 * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
David Hu49ec08a2019-09-23 16:13:41 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8/*
9 * This is header file of common mailbox objects shared by NSPE and SPE.
10 * Please refer to tfm_ns_mailbox.h for the definitions only used in NSPE
11 * mailbox library.
12 * Please refer to tfm_spe_mailbox.h for the SPE specific definitions and APIs.
13 */
14
15#ifndef __TFM_MAILBOX_H__
16#define __TFM_MAILBOX_H__
17
David Hu3684ee72019-11-12 18:43:34 +080018#include <stdbool.h>
David Hu49ec08a2019-09-23 16:13:41 +080019#include <stdint.h>
20#include <stddef.h>
David Hude3f79f2019-11-14 16:56:51 +080021#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
22#include "device_cfg.h"
23#endif
David Hu49ec08a2019-09-23 16:13:41 +080024#include "psa/client.h"
25
David Hu49041522019-11-18 13:48:09 +080026#ifdef __cplusplus
27extern "C" {
28#endif
29
David Hu49ec08a2019-09-23 16:13:41 +080030/*
David Hude3f79f2019-11-14 16:56:51 +080031 * If multiple outstanding NS PSA Client calls is enabled, multi-core platform
32 * should define the number of mailbox queue slots NUM_MAILBOX_QUEUE_SLOT in
33 * platform device_cfg.h.
34 * Otherwise, NUM_MAILBOX_QUEUE_SLOT is defined as 1.
David Hu49ec08a2019-09-23 16:13:41 +080035 */
David Hude3f79f2019-11-14 16:56:51 +080036#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
37#ifndef NUM_MAILBOX_QUEUE_SLOT
38#error "Error: Platform doesn't define NUM_MAILBOX_QUEUE_SLOT for mailbox queue"
39#endif
40
41#if (NUM_MAILBOX_QUEUE_SLOT < 2)
42#error "Error: Invalid NUM_MAILBOX_QUEUE_SLOT. The value should be more than 1"
43#endif
44
45/*
46 * The number of slots should be no more than the number of bits in
47 * mailbox_queue_status_t.
48 * Here the value is hardcoded. A better way is to define a sizeof() to
49 * calculate the bits in mailbox_queue_status_t and dump it with pragma message.
50 */
51#if (NUM_MAILBOX_QUEUE_SLOT > 32)
52#error "Error: Invalid NUM_MAILBOX_QUEUE_SLOT. The value should be no more than 32"
53#endif
54#else /* TFM_MULTI_CORE_MULTI_CLIENT_CALL */
55/* Force the number of mailbox queue slots as 1. */
56#undef NUM_MAILBOX_QUEUE_SLOT
David Hu49ec08a2019-09-23 16:13:41 +080057#define NUM_MAILBOX_QUEUE_SLOT (1)
David Hude3f79f2019-11-14 16:56:51 +080058#endif /* TFM_MULTI_CORE_MULTI_CLIENT_CALL */
David Hu49ec08a2019-09-23 16:13:41 +080059
60/* PSA client call type value */
61#define MAILBOX_PSA_FRAMEWORK_VERSION (0x1)
62#define MAILBOX_PSA_VERSION (0x2)
63#define MAILBOX_PSA_CONNECT (0x3)
64#define MAILBOX_PSA_CALL (0x4)
65#define MAILBOX_PSA_CLOSE (0x5)
66
67/* Return code of mailbox APIs */
68#define MAILBOX_SUCCESS (0)
69#define MAILBOX_QUEUE_FULL (INT32_MIN + 1)
70#define MAILBOX_INVAL_PARAMS (INT32_MIN + 2)
71#define MAILBOX_NO_PERMS (INT32_MIN + 3)
72#define MAILBOX_NO_PEND_EVENT (INT32_MIN + 4)
73#define MAILBOX_CHAN_BUSY (INT32_MIN + 5)
74#define MAILBOX_CALLBACK_REG_ERROR (INT32_MIN + 6)
75#define MAILBOX_INIT_ERROR (INT32_MIN + 7)
76
77/*
78 * This structure holds the parameters used in a PSA client call.
79 */
80struct psa_client_params_t {
81 union {
82 struct {
83 uint32_t sid;
84 } psa_version_params;
85
86 struct {
87 uint32_t sid;
Jaykumar Pitambarbhai Patel3a986022019-10-08 17:37:15 +053088 uint32_t version;
David Hu49ec08a2019-09-23 16:13:41 +080089 } psa_connect_params;
90
91 struct {
92 psa_handle_t handle;
93 int32_t type;
94 const psa_invec *in_vec;
95 size_t in_len;
96 psa_outvec *out_vec;
97 size_t out_len;
98 } psa_call_params;
99
100 struct {
101 psa_handle_t handle;
102 } psa_close_params;
103 };
104};
105
106/* Mailbox message passed from NSPE to SPE to deliver a PSA client call */
107struct mailbox_msg_t {
108 uint32_t call_type; /* PSA client call type */
109 struct psa_client_params_t params; /* Contain parameters used in PSA
110 * client call
111 */
112
113 int32_t client_id; /* Optional client ID of the
114 * non-secure caller.
115 * It is required to identify the
116 * non-secure task when NSPE OS
117 * enforces non-secure task isolation
118 */
119};
120
121/* A handle to a mailbox message in use */
122typedef int32_t mailbox_msg_handle_t;
123
124#define MAILBOX_MSG_NULL_HANDLE ((mailbox_msg_handle_t)0)
125
126/*
127 * Mailbox reply structure in non-secure memory
128 * to hold the PSA client call return result from SPE
129 */
130struct mailbox_reply_t {
131 int32_t return_val;
132};
133
134/* A single slot structure in NSPE mailbox queue */
135struct ns_mailbox_slot_t {
136 struct mailbox_msg_t msg;
137 struct mailbox_reply_t reply;
David Hu3684ee72019-11-12 18:43:34 +0800138 const void *owner; /* Handle of the owner task of this
139 * slot
140 */
141 bool is_woken; /* Indicate that owner task has been
142 * or should be woken up, after the
143 * replied is received.
144 */
David Hu49ec08a2019-09-23 16:13:41 +0800145};
146
147typedef uint32_t mailbox_queue_status_t;
148
149/* NSPE mailbox queue */
150struct ns_mailbox_queue_t {
151 mailbox_queue_status_t empty_slots; /* Bitmask of empty slots */
152 mailbox_queue_status_t pend_slots; /* Bitmask of slots pending
153 * for SPE handling
154 */
155 mailbox_queue_status_t replied_slots; /* Bitmask of active slots
156 * containing PSA client call
157 * return result
158 */
159
160 struct ns_mailbox_slot_t queue[NUM_MAILBOX_QUEUE_SLOT];
David Hu65cbfb82019-11-15 17:18:12 +0800161
162#ifdef TFM_MULTI_CORE_TEST
163 uint32_t nr_tx; /* The total number of
164 * submission of NS PSA Client
165 * calls from NS task via
166 * mailbox.
167 */
168 uint32_t nr_used_slots; /* The total number of used
169 * mailbox queue slots each time
170 * NS thread requests a mailbox
171 * queue slot.
172 */
173#endif
David Hu49ec08a2019-09-23 16:13:41 +0800174};
175
David Hu49041522019-11-18 13:48:09 +0800176#ifdef __cplusplus
177}
178#endif
179
David Hu49ec08a2019-09-23 16:13:41 +0800180#endif /* __TFM_MAILBOX_H__ */