Kristofer Jonsson | 964c0ac | 2023-01-11 15:59:34 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020-2023 Arm Limited. |
| 3 | * |
| 4 | * This program is free software and is provided to you under the terms of the |
| 5 | * GNU General Public License version 2 as published by the Free Software |
| 6 | * Foundation, and any use by you of this program is subject to the terms |
| 7 | * of such GNU licence. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, you can access it online at |
| 16 | * http://www.gnu.org/licenses/gpl-2.0.html. |
| 17 | * |
| 18 | * SPDX-License-Identifier: GPL-2.0-only |
| 19 | */ |
| 20 | |
| 21 | #ifndef ETHOSU_CORE_RPMSG_H |
| 22 | #define ETHOSU_CORE_RPMSG_H |
| 23 | |
| 24 | #ifdef __KERNEL__ |
| 25 | #include <linux/types.h> |
| 26 | #else |
| 27 | #include <stdint.h> |
| 28 | #endif |
| 29 | |
| 30 | #ifdef __cplusplus |
| 31 | namespace EthosU { |
| 32 | #endif |
| 33 | |
| 34 | /** Maximum number of IFM/OFM buffers per inference */ |
| 35 | #define ETHOSU_CORE_BUFFER_MAX 16 |
| 36 | |
| 37 | /** Maximum number of PMU counters to be returned for inference */ |
| 38 | #define ETHOSU_CORE_PMU_MAX 8 |
| 39 | |
| 40 | #define ETHOSU_CORE_MSG_MAGIC 0x41457631 |
| 41 | #define ETHOSU_CORE_MSG_VERSION_MAJOR 0 |
| 42 | #define ETHOSU_CORE_MSG_VERSION_MINOR 2 |
| 43 | #define ETHOSU_CORE_MSG_VERSION_PATCH 0 |
| 44 | |
| 45 | /** |
| 46 | * enum ethosu_core_msg_type - Message types |
| 47 | * |
| 48 | * Types for the messages sent between the host and the core subsystem. |
| 49 | */ |
| 50 | enum ethosu_core_msg_type { |
| 51 | ETHOSU_CORE_MSG_ERR = 1, |
| 52 | ETHOSU_CORE_MSG_PING, |
| 53 | ETHOSU_CORE_MSG_PONG, |
| 54 | ETHOSU_CORE_MSG_INFERENCE_REQ, |
| 55 | ETHOSU_CORE_MSG_INFERENCE_RSP, |
| 56 | ETHOSU_CORE_MSG_VERSION_REQ, |
| 57 | ETHOSU_CORE_MSG_VERSION_RSP, |
| 58 | ETHOSU_CORE_MSG_CAPABILITIES_REQ, |
| 59 | ETHOSU_CORE_MSG_CAPABILITIES_RSP, |
| 60 | ETHOSU_CORE_MSG_NETWORK_INFO_REQ, |
| 61 | ETHOSU_CORE_MSG_NETWORK_INFO_RSP, |
| 62 | ETHOSU_CORE_MSG_CANCEL_INFERENCE_REQ, |
| 63 | ETHOSU_CORE_MSG_CANCEL_INFERENCE_RSP, |
| 64 | ETHOSU_CORE_MSG_MAX |
| 65 | }; |
| 66 | |
| 67 | /** |
| 68 | * struct ethosu_core_msg_header - Message header |
| 69 | */ |
| 70 | struct ethosu_core_msg_header { |
| 71 | uint32_t magic; |
| 72 | uint32_t type; |
| 73 | uint64_t msg_id; |
| 74 | }; |
| 75 | |
| 76 | /** |
| 77 | * enum ethosu_core_status - Status |
| 78 | */ |
| 79 | enum ethosu_core_status { |
| 80 | ETHOSU_CORE_STATUS_OK, |
| 81 | ETHOSU_CORE_STATUS_ERROR, |
| 82 | ETHOSU_CORE_STATUS_RUNNING, |
| 83 | ETHOSU_CORE_STATUS_REJECTED, |
| 84 | ETHOSU_CORE_STATUS_ABORTED, |
| 85 | ETHOSU_CORE_STATUS_ABORTING, |
| 86 | }; |
| 87 | |
| 88 | /** |
| 89 | * struct ethosu_core_buffer - Buffer descriptor |
| 90 | * |
| 91 | * Pointer and size to a buffer within the Ethos-U address space. |
| 92 | */ |
| 93 | struct ethosu_core_buffer { |
| 94 | uint32_t ptr; |
| 95 | uint32_t size; |
| 96 | }; |
| 97 | |
| 98 | /** |
| 99 | * enum ethosu_core_network_type - Network buffer type |
| 100 | */ |
| 101 | enum ethosu_core_network_type { |
| 102 | ETHOSU_CORE_NETWORK_BUFFER = 1, |
| 103 | ETHOSU_CORE_NETWORK_INDEX |
| 104 | }; |
| 105 | |
| 106 | /** |
| 107 | * struct ethosu_core_network_buffer - Network buffer |
| 108 | */ |
| 109 | struct ethosu_core_network_buffer { |
| 110 | uint32_t type; |
| 111 | union { |
| 112 | struct ethosu_core_buffer buffer; |
| 113 | uint32_t index; |
| 114 | }; |
| 115 | }; |
| 116 | |
| 117 | /** |
| 118 | * struct ethosu_core_msg_inference_req - Inference request |
| 119 | */ |
| 120 | struct ethosu_core_msg_inference_req { |
| 121 | uint32_t ifm_count; |
| 122 | struct ethosu_core_buffer ifm[ETHOSU_CORE_BUFFER_MAX]; |
| 123 | uint32_t ofm_count; |
| 124 | struct ethosu_core_buffer ofm[ETHOSU_CORE_BUFFER_MAX]; |
| 125 | struct ethosu_core_network_buffer network; |
| 126 | uint8_t pmu_event_config[ETHOSU_CORE_PMU_MAX]; |
| 127 | uint32_t pmu_cycle_counter_enable; |
| 128 | }; |
| 129 | |
| 130 | /** |
| 131 | * struct ethosu_core_msg_inference_rsp - Inference response |
| 132 | */ |
| 133 | struct ethosu_core_msg_inference_rsp { |
| 134 | uint32_t ofm_count; |
| 135 | uint32_t ofm_size[ETHOSU_CORE_BUFFER_MAX]; |
| 136 | uint32_t status; |
| 137 | uint8_t pmu_event_config[ETHOSU_CORE_PMU_MAX]; |
| 138 | uint32_t pmu_event_count[ETHOSU_CORE_PMU_MAX]; |
| 139 | uint32_t pmu_cycle_counter_enable; |
| 140 | uint64_t pmu_cycle_counter_count; |
| 141 | }; |
| 142 | |
| 143 | /** |
| 144 | * struct ethosu_core_msg_network_info_req - Network information request |
| 145 | */ |
| 146 | struct ethosu_core_msg_network_info_req { |
| 147 | struct ethosu_core_network_buffer network; |
| 148 | }; |
| 149 | |
| 150 | /** |
| 151 | * struct ethosu_core_msg_network_info_rsp - Network information response |
| 152 | */ |
| 153 | struct ethosu_core_msg_network_info_rsp { |
| 154 | char desc[32]; |
| 155 | uint32_t ifm_count; |
| 156 | uint32_t ifm_size[ETHOSU_CORE_BUFFER_MAX]; |
| 157 | uint32_t ofm_count; |
| 158 | uint32_t ofm_size[ETHOSU_CORE_BUFFER_MAX]; |
| 159 | uint32_t status; |
| 160 | }; |
| 161 | |
| 162 | /** |
| 163 | * struct ethosu_core_msg_version_rsp - Message protocol version |
| 164 | */ |
| 165 | struct ethosu_core_msg_version_rsp { |
| 166 | uint8_t major; |
| 167 | uint8_t minor; |
| 168 | uint8_t patch; |
| 169 | uint8_t _reserved; |
| 170 | }; |
| 171 | |
| 172 | /** |
| 173 | * struct ethosu_core_msg_capabilities_rsp - Message capabilities response |
| 174 | */ |
| 175 | struct ethosu_core_msg_capabilities_rsp { |
| 176 | uint32_t version_status; |
| 177 | uint32_t version_minor; |
| 178 | uint32_t version_major; |
| 179 | uint32_t product_major; |
| 180 | uint32_t arch_patch_rev; |
| 181 | uint32_t arch_minor_rev; |
| 182 | uint32_t arch_major_rev; |
| 183 | uint32_t driver_patch_rev; |
| 184 | uint32_t driver_minor_rev; |
| 185 | uint32_t driver_major_rev; |
| 186 | uint32_t macs_per_cc; |
| 187 | uint32_t cmd_stream_version; |
| 188 | uint32_t custom_dma; |
| 189 | }; |
| 190 | |
| 191 | /** |
| 192 | * struct ethosu_core_msg_cancel_inference_req - Message cancel inference |
| 193 | * request |
| 194 | */ |
| 195 | struct ethosu_core_msg_cancel_inference_req { |
| 196 | uint64_t inference_handle; |
| 197 | }; |
| 198 | |
| 199 | /** |
| 200 | * struct ethosu_core_msg_cancel_inference_rsp - Message cancel inference |
| 201 | * response |
| 202 | */ |
| 203 | struct ethosu_core_msg_cancel_inference_rsp { |
| 204 | uint32_t status; |
| 205 | }; |
| 206 | |
| 207 | /** |
| 208 | * enum ethosu_core_err_type - Error types |
| 209 | */ |
| 210 | enum ethosu_core_err_type { |
| 211 | ETHOSU_CORE_MSG_ERR_GENERIC = 0, |
| 212 | ETHOSU_CORE_MSG_ERR_UNSUPPORTED_TYPE, |
| 213 | ETHOSU_CORE_MSG_ERR_INVALID_PAYLOAD, |
| 214 | ETHOSU_CORE_MSG_ERR_INVALID_SIZE, |
| 215 | ETHOSU_CORE_MSG_ERR_INVALID_MAGIC, |
| 216 | ETHOSU_CORE_MSG_ERR_MAX |
| 217 | }; |
| 218 | |
| 219 | /** |
| 220 | * struct ethosu_core_msg_err - Error message struct |
| 221 | */ |
| 222 | struct ethosu_core_msg_err { |
| 223 | uint32_t type; /* optional use of extra error code */ |
| 224 | char msg[128]; |
| 225 | }; |
| 226 | |
| 227 | /** |
| 228 | * struct ethosu_core_rpmsg - Rpmsg message |
| 229 | */ |
| 230 | struct ethosu_core_rpmsg { |
| 231 | struct ethosu_core_msg_header header; |
| 232 | union { |
| 233 | struct ethosu_core_msg_inference_req inf_req; |
| 234 | struct ethosu_core_msg_inference_rsp inf_rsp; |
| 235 | struct ethosu_core_msg_network_info_req net_info_req; |
| 236 | struct ethosu_core_msg_network_info_rsp net_info_rsp; |
| 237 | struct ethosu_core_msg_capabilities_rsp cap_rsp; |
| 238 | struct ethosu_core_msg_cancel_inference_req cancel_req; |
| 239 | struct ethosu_core_msg_cancel_inference_rsp cancel_rsp; |
| 240 | struct ethosu_core_msg_version_rsp version_rsp; |
| 241 | struct ethosu_core_msg_err error; |
| 242 | }; |
| 243 | }; |
| 244 | |
| 245 | #ifdef __cplusplus |
| 246 | } /*namespace EthosU */ |
| 247 | #endif |
| 248 | |
| 249 | #endif /* ETHOSU_CORE_RPMSG_H */ |