blob: bb23b7a097ce4549cec0e6450c50dd6ca8833227 [file] [log] [blame]
David Hu49ec08a2019-09-23 16:13:41 +08001/*
2 * Copyright (c) 2019, Arm Limited. All rights reserved.
3 *
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
18#include <stdint.h>
19#include <stddef.h>
20#include "psa/client.h"
21
David Hu49041522019-11-18 13:48:09 +080022#ifdef __cplusplus
23extern "C" {
24#endif
25
David Hu49ec08a2019-09-23 16:13:41 +080026/*
27 * The number of slots in NSPE mailbox queue and SPE mailbox queue.
28 * So far only one slot is supported in either NSPE mailbox queue or
29 * SPE mailbox queue.
30 */
31#define NUM_MAILBOX_QUEUE_SLOT (1)
32
33/* PSA client call type value */
34#define MAILBOX_PSA_FRAMEWORK_VERSION (0x1)
35#define MAILBOX_PSA_VERSION (0x2)
36#define MAILBOX_PSA_CONNECT (0x3)
37#define MAILBOX_PSA_CALL (0x4)
38#define MAILBOX_PSA_CLOSE (0x5)
39
40/* Return code of mailbox APIs */
41#define MAILBOX_SUCCESS (0)
42#define MAILBOX_QUEUE_FULL (INT32_MIN + 1)
43#define MAILBOX_INVAL_PARAMS (INT32_MIN + 2)
44#define MAILBOX_NO_PERMS (INT32_MIN + 3)
45#define MAILBOX_NO_PEND_EVENT (INT32_MIN + 4)
46#define MAILBOX_CHAN_BUSY (INT32_MIN + 5)
47#define MAILBOX_CALLBACK_REG_ERROR (INT32_MIN + 6)
48#define MAILBOX_INIT_ERROR (INT32_MIN + 7)
49
50/*
51 * This structure holds the parameters used in a PSA client call.
52 */
53struct psa_client_params_t {
54 union {
55 struct {
56 uint32_t sid;
57 } psa_version_params;
58
59 struct {
60 uint32_t sid;
Jaykumar Pitambarbhai Patel3a986022019-10-08 17:37:15 +053061 uint32_t version;
David Hu49ec08a2019-09-23 16:13:41 +080062 } psa_connect_params;
63
64 struct {
65 psa_handle_t handle;
66 int32_t type;
67 const psa_invec *in_vec;
68 size_t in_len;
69 psa_outvec *out_vec;
70 size_t out_len;
71 } psa_call_params;
72
73 struct {
74 psa_handle_t handle;
75 } psa_close_params;
76 };
77};
78
79/* Mailbox message passed from NSPE to SPE to deliver a PSA client call */
80struct mailbox_msg_t {
81 uint32_t call_type; /* PSA client call type */
82 struct psa_client_params_t params; /* Contain parameters used in PSA
83 * client call
84 */
85
86 int32_t client_id; /* Optional client ID of the
87 * non-secure caller.
88 * It is required to identify the
89 * non-secure task when NSPE OS
90 * enforces non-secure task isolation
91 */
92};
93
94/* A handle to a mailbox message in use */
95typedef int32_t mailbox_msg_handle_t;
96
97#define MAILBOX_MSG_NULL_HANDLE ((mailbox_msg_handle_t)0)
98
99/*
100 * Mailbox reply structure in non-secure memory
101 * to hold the PSA client call return result from SPE
102 */
103struct mailbox_reply_t {
104 int32_t return_val;
105};
106
107/* A single slot structure in NSPE mailbox queue */
108struct ns_mailbox_slot_t {
109 struct mailbox_msg_t msg;
110 struct mailbox_reply_t reply;
David Hu06ebac72019-09-29 16:01:54 +0800111 const void *owner; /* Handle of the owner task of this
David Hu49ec08a2019-09-23 16:13:41 +0800112 * slot
113 */
114};
115
116typedef uint32_t mailbox_queue_status_t;
117
118/* NSPE mailbox queue */
119struct ns_mailbox_queue_t {
120 mailbox_queue_status_t empty_slots; /* Bitmask of empty slots */
121 mailbox_queue_status_t pend_slots; /* Bitmask of slots pending
122 * for SPE handling
123 */
124 mailbox_queue_status_t replied_slots; /* Bitmask of active slots
125 * containing PSA client call
126 * return result
127 */
128
129 struct ns_mailbox_slot_t queue[NUM_MAILBOX_QUEUE_SLOT];
130};
131
David Hu49041522019-11-18 13:48:09 +0800132#ifdef __cplusplus
133}
134#endif
135
David Hu49ec08a2019-09-23 16:13:41 +0800136#endif /* __TFM_MAILBOX_H__ */