David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 1 | /* |
| 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 Hu | 4904152 | 2019-11-18 13:48:09 +0800 | [diff] [blame^] | 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 26 | /* |
| 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 | */ |
| 53 | struct 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 Patel | 3a98602 | 2019-10-08 17:37:15 +0530 | [diff] [blame] | 61 | uint32_t version; |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 62 | } 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 */ |
| 80 | struct 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 */ |
| 95 | typedef 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 | */ |
| 103 | struct mailbox_reply_t { |
| 104 | int32_t return_val; |
| 105 | }; |
| 106 | |
| 107 | /* A single slot structure in NSPE mailbox queue */ |
| 108 | struct ns_mailbox_slot_t { |
| 109 | struct mailbox_msg_t msg; |
| 110 | struct mailbox_reply_t reply; |
| 111 | |
| 112 | void *owner; /* Identification of the owner of this |
| 113 | * slot |
| 114 | */ |
| 115 | }; |
| 116 | |
| 117 | typedef uint32_t mailbox_queue_status_t; |
| 118 | |
| 119 | /* NSPE mailbox queue */ |
| 120 | struct ns_mailbox_queue_t { |
| 121 | mailbox_queue_status_t empty_slots; /* Bitmask of empty slots */ |
| 122 | mailbox_queue_status_t pend_slots; /* Bitmask of slots pending |
| 123 | * for SPE handling |
| 124 | */ |
| 125 | mailbox_queue_status_t replied_slots; /* Bitmask of active slots |
| 126 | * containing PSA client call |
| 127 | * return result |
| 128 | */ |
| 129 | |
| 130 | struct ns_mailbox_slot_t queue[NUM_MAILBOX_QUEUE_SLOT]; |
| 131 | }; |
| 132 | |
David Hu | 4904152 | 2019-11-18 13:48:09 +0800 | [diff] [blame^] | 133 | #ifdef __cplusplus |
| 134 | } |
| 135 | #endif |
| 136 | |
David Hu | 49ec08a | 2019-09-23 16:13:41 +0800 | [diff] [blame] | 137 | #endif /* __TFM_MAILBOX_H__ */ |