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