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