blob: 45eb97ef21bff46d2fc88f7ce4f1ac0b25fcdc78 [file] [log] [blame]
David Hu49ec08a2019-09-23 16:13:41 +08001/*
David Hu1bd1c7b2020-05-09 14:13:20 +08002 * Copyright (c) 2019-2021, 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)
David Hu1bd1c7b2020-05-09 14:13:20 +080076#define MAILBOX_GENERIC_ERROR (INT32_MIN + 8)
David Hu49ec08a2019-09-23 16:13:41 +080077
78/*
79 * This structure holds the parameters used in a PSA client call.
80 */
81struct psa_client_params_t {
82 union {
83 struct {
84 uint32_t sid;
85 } psa_version_params;
86
87 struct {
88 uint32_t sid;
Jaykumar Pitambarbhai Patel3a986022019-10-08 17:37:15 +053089 uint32_t version;
David Hu49ec08a2019-09-23 16:13:41 +080090 } psa_connect_params;
91
92 struct {
93 psa_handle_t handle;
94 int32_t type;
95 const psa_invec *in_vec;
96 size_t in_len;
97 psa_outvec *out_vec;
98 size_t out_len;
99 } psa_call_params;
100
101 struct {
102 psa_handle_t handle;
103 } psa_close_params;
104 };
105};
106
107/* Mailbox message passed from NSPE to SPE to deliver a PSA client call */
108struct mailbox_msg_t {
109 uint32_t call_type; /* PSA client call type */
110 struct psa_client_params_t params; /* Contain parameters used in PSA
111 * client call
112 */
113
114 int32_t client_id; /* Optional client ID of the
115 * non-secure caller.
116 * It is required to identify the
117 * non-secure task when NSPE OS
118 * enforces non-secure task isolation
119 */
120};
121
David Hu49ec08a2019-09-23 16:13:41 +0800122/*
123 * Mailbox reply structure in non-secure memory
124 * to hold the PSA client call return result from SPE
125 */
126struct mailbox_reply_t {
127 int32_t return_val;
128};
129
130/* A single slot structure in NSPE mailbox queue */
131struct ns_mailbox_slot_t {
132 struct mailbox_msg_t msg;
133 struct mailbox_reply_t reply;
David Hu3684ee72019-11-12 18:43:34 +0800134 const void *owner; /* Handle of the owner task of this
135 * slot
136 */
137 bool is_woken; /* Indicate that owner task has been
138 * or should be woken up, after the
139 * replied is received.
140 */
David Hu49ec08a2019-09-23 16:13:41 +0800141};
142
143typedef uint32_t mailbox_queue_status_t;
144
145/* NSPE mailbox queue */
146struct ns_mailbox_queue_t {
147 mailbox_queue_status_t empty_slots; /* Bitmask of empty slots */
148 mailbox_queue_status_t pend_slots; /* Bitmask of slots pending
149 * for SPE handling
150 */
151 mailbox_queue_status_t replied_slots; /* Bitmask of active slots
152 * containing PSA client call
153 * return result
154 */
155
156 struct ns_mailbox_slot_t queue[NUM_MAILBOX_QUEUE_SLOT];
David Hu65cbfb82019-11-15 17:18:12 +0800157
158#ifdef TFM_MULTI_CORE_TEST
159 uint32_t nr_tx; /* The total number of
160 * submission of NS PSA Client
161 * calls from NS task via
162 * mailbox.
163 */
164 uint32_t nr_used_slots; /* The total number of used
165 * mailbox queue slots each time
166 * NS thread requests a mailbox
167 * queue slot.
168 */
169#endif
David Hu49ec08a2019-09-23 16:13:41 +0800170};
171
David Hu49041522019-11-18 13:48:09 +0800172#ifdef __cplusplus
173}
174#endif
175
David Hu49ec08a2019-09-23 16:13:41 +0800176#endif /* __TFM_MAILBOX_H__ */