Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 1 | /* |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 2 | * Copyright (c) 2020-2022 Arm Limited. |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 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_INTERFACE_H |
| 22 | #define ETHOSU_CORE_INTERFACE_H |
| 23 | |
| 24 | #ifdef __KERNEL__ |
| 25 | #include <linux/types.h> |
| 26 | #else |
| 27 | #include <stdint.h> |
| 28 | #endif |
| 29 | |
Per Åstrand | c823bcf | 2021-01-12 13:11:13 +0100 | [diff] [blame] | 30 | #ifdef __cplusplus |
| 31 | namespace EthosU { |
| 32 | #endif |
| 33 | |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 34 | /** Maximum number of IFM/OFM buffers per inference */ |
| 35 | #define ETHOSU_CORE_BUFFER_MAX 16 |
| 36 | |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 37 | /** Maximum number of PMU counters to be returned for inference */ |
Jonny Svärd | b5aa904 | 2021-12-17 17:08:10 +0100 | [diff] [blame] | 38 | #define ETHOSU_CORE_PMU_MAX 8 |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 39 | |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 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 | |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 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 { |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 51 | ETHOSU_CORE_MSG_ERR = 1, |
| 52 | ETHOSU_CORE_MSG_PING, |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 53 | ETHOSU_CORE_MSG_PONG, |
| 54 | ETHOSU_CORE_MSG_INFERENCE_REQ, |
| 55 | ETHOSU_CORE_MSG_INFERENCE_RSP, |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 56 | ETHOSU_CORE_MSG_VERSION_REQ, |
| 57 | ETHOSU_CORE_MSG_VERSION_RSP, |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 58 | ETHOSU_CORE_MSG_CAPABILITIES_REQ, |
| 59 | ETHOSU_CORE_MSG_CAPABILITIES_RSP, |
Kristofer Jonsson | 3c6a260 | 2022-03-10 11:17:29 +0100 | [diff] [blame] | 60 | ETHOSU_CORE_MSG_NETWORK_INFO_REQ, |
| 61 | ETHOSU_CORE_MSG_NETWORK_INFO_RSP, |
Davide Grohmann | 7e8f508 | 2022-03-23 12:48:45 +0100 | [diff] [blame] | 62 | ETHOSU_CORE_MSG_CANCEL_INFERENCE_REQ, |
| 63 | ETHOSU_CORE_MSG_CANCEL_INFERENCE_RSP, |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 64 | ETHOSU_CORE_MSG_MAX |
| 65 | }; |
| 66 | |
| 67 | /** |
| 68 | * struct ethosu_core_msg - Message header |
| 69 | */ |
| 70 | struct ethosu_core_msg { |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 71 | uint32_t magic; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 72 | uint32_t type; |
| 73 | uint32_t length; |
| 74 | }; |
| 75 | |
| 76 | /** |
| 77 | * struct ethosu_core_queue_header - Message queue header |
| 78 | */ |
| 79 | struct ethosu_core_queue_header { |
| 80 | uint32_t size; |
| 81 | uint32_t read; |
| 82 | uint32_t write; |
| 83 | }; |
| 84 | |
| 85 | /** |
| 86 | * struct ethosu_core_queue - Message queue |
| 87 | * |
| 88 | * Dynamically sized message queue. |
| 89 | */ |
| 90 | struct ethosu_core_queue { |
| 91 | struct ethosu_core_queue_header header; |
| 92 | uint8_t data[]; |
| 93 | }; |
| 94 | |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 95 | /** |
| 96 | * enum ethosu_core_status - Status |
| 97 | */ |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 98 | enum ethosu_core_status { |
| 99 | ETHOSU_CORE_STATUS_OK, |
Davide Grohmann | 82d2258 | 2022-04-25 12:52:38 +0200 | [diff] [blame] | 100 | ETHOSU_CORE_STATUS_ERROR, |
| 101 | ETHOSU_CORE_STATUS_RUNNING, |
| 102 | ETHOSU_CORE_STATUS_REJECTED, |
Davide Grohmann | 7e8f508 | 2022-03-23 12:48:45 +0100 | [diff] [blame] | 103 | ETHOSU_CORE_STATUS_ABORTED, |
| 104 | ETHOSU_CORE_STATUS_ABORTING, |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 105 | }; |
| 106 | |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 107 | /** |
| 108 | * struct ethosu_core_buffer - Buffer descriptor |
| 109 | * |
| 110 | * Pointer and size to a buffer withing the Ethos-U |
| 111 | * address space. |
| 112 | */ |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 113 | struct ethosu_core_buffer { |
| 114 | uint32_t ptr; |
| 115 | uint32_t size; |
| 116 | }; |
| 117 | |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 118 | /** |
| 119 | * enum ethosu_core_network_type - Network buffer type |
| 120 | */ |
| 121 | enum ethosu_core_network_type { |
| 122 | ETHOSU_CORE_NETWORK_BUFFER = 1, |
| 123 | ETHOSU_CORE_NETWORK_INDEX |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 124 | }; |
| 125 | |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 126 | /** |
| 127 | * struct ethosu_core_network_buffer - Network buffer |
| 128 | */ |
| 129 | struct ethosu_core_network_buffer { |
| 130 | uint32_t type; |
| 131 | union { |
| 132 | struct ethosu_core_buffer buffer; |
| 133 | uint32_t index; |
| 134 | }; |
| 135 | }; |
| 136 | |
| 137 | /** |
| 138 | * struct ethosu_core_inference_req - Inference request |
| 139 | */ |
| 140 | struct ethosu_core_inference_req { |
| 141 | uint64_t user_arg; |
| 142 | uint32_t ifm_count; |
| 143 | struct ethosu_core_buffer ifm[ETHOSU_CORE_BUFFER_MAX]; |
| 144 | uint32_t ofm_count; |
| 145 | struct ethosu_core_buffer ofm[ETHOSU_CORE_BUFFER_MAX]; |
| 146 | struct ethosu_core_network_buffer network; |
| 147 | uint8_t pmu_event_config[ETHOSU_CORE_PMU_MAX]; |
| 148 | uint32_t pmu_cycle_counter_enable; |
| 149 | }; |
| 150 | |
| 151 | /** |
| 152 | * struct ethosu_core_inference_rsp - Inference response |
| 153 | */ |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 154 | struct ethosu_core_inference_rsp { |
| 155 | uint64_t user_arg; |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 156 | uint32_t ofm_count; |
| 157 | uint32_t ofm_size[ETHOSU_CORE_BUFFER_MAX]; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 158 | uint32_t status; |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 159 | uint8_t pmu_event_config[ETHOSU_CORE_PMU_MAX]; |
| 160 | uint32_t pmu_event_count[ETHOSU_CORE_PMU_MAX]; |
| 161 | uint32_t pmu_cycle_counter_enable; |
| 162 | uint64_t pmu_cycle_counter_count; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 163 | }; |
| 164 | |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 165 | /** |
Kristofer Jonsson | 3c6a260 | 2022-03-10 11:17:29 +0100 | [diff] [blame] | 166 | * struct ethosu_core_network_info_req - Network information request |
| 167 | */ |
| 168 | struct ethosu_core_network_info_req { |
| 169 | uint64_t user_arg; |
| 170 | struct ethosu_core_network_buffer network; |
| 171 | }; |
| 172 | |
| 173 | /** |
| 174 | * struct ethosu_core_network_info_rsp - Network information response |
| 175 | */ |
| 176 | struct ethosu_core_network_info_rsp { |
| 177 | uint64_t user_arg; |
| 178 | char desc[32]; |
| 179 | uint32_t ifm_count; |
| 180 | uint32_t ifm_size[ETHOSU_CORE_BUFFER_MAX]; |
| 181 | uint32_t ofm_count; |
| 182 | uint32_t ofm_size[ETHOSU_CORE_BUFFER_MAX]; |
| 183 | uint32_t status; |
| 184 | }; |
| 185 | |
| 186 | /** |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 187 | * struct ethosu_core_msg_version - Message protocol version |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 188 | */ |
| 189 | struct ethosu_core_msg_version { |
| 190 | uint8_t major; |
| 191 | uint8_t minor; |
| 192 | uint8_t patch; |
| 193 | uint8_t _reserved; |
| 194 | }; |
| 195 | |
| 196 | /** |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 197 | * struct ethosu_core_capabilities_req - Message capabilities request |
| 198 | */ |
| 199 | struct ethosu_core_capabilities_req { |
| 200 | uint64_t user_arg; |
| 201 | }; |
| 202 | |
| 203 | /** |
| 204 | * struct ethosu_core_capabilities_rsp - Message capabilities response |
| 205 | */ |
| 206 | struct ethosu_core_msg_capabilities_rsp { |
| 207 | uint64_t user_arg; |
| 208 | uint32_t version_status; |
| 209 | uint32_t version_minor; |
| 210 | uint32_t version_major; |
| 211 | uint32_t product_major; |
| 212 | uint32_t arch_patch_rev; |
| 213 | uint32_t arch_minor_rev; |
| 214 | uint32_t arch_major_rev; |
| 215 | uint32_t driver_patch_rev; |
| 216 | uint32_t driver_minor_rev; |
| 217 | uint32_t driver_major_rev; |
| 218 | uint32_t macs_per_cc; |
| 219 | uint32_t cmd_stream_version; |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 220 | uint32_t custom_dma; |
| 221 | }; |
| 222 | |
| 223 | /** |
Davide Grohmann | 7e8f508 | 2022-03-23 12:48:45 +0100 | [diff] [blame] | 224 | * struct ethosu_core_cancel_inference_req - Message cancel inference request |
| 225 | */ |
| 226 | struct ethosu_core_cancel_inference_req { |
| 227 | uint64_t user_arg; |
| 228 | uint64_t inference_handle; |
| 229 | }; |
| 230 | |
| 231 | /** |
| 232 | * struct ethosu_core_cancel_inference_rsp - Message cancel inference response |
| 233 | */ |
| 234 | struct ethosu_core_cancel_inference_rsp { |
| 235 | uint64_t user_arg; |
| 236 | uint32_t status; |
| 237 | }; |
| 238 | |
| 239 | /** |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 240 | * enum ethosu_core_msg_err_type - Error types |
| 241 | */ |
| 242 | enum ethosu_core_msg_err_type { |
| 243 | ETHOSU_CORE_MSG_ERR_GENERIC = 0, |
| 244 | ETHOSU_CORE_MSG_ERR_UNSUPPORTED_TYPE, |
| 245 | ETHOSU_CORE_MSG_ERR_INVALID_PAYLOAD, |
| 246 | ETHOSU_CORE_MSG_ERR_INVALID_SIZE, |
| 247 | ETHOSU_CORE_MSG_ERR_INVALID_MAGIC, |
| 248 | ETHOSU_CORE_MSG_ERR_MAX |
| 249 | }; |
| 250 | |
| 251 | /** |
| 252 | * struct ethosu_core_msg_err - Error message struct |
| 253 | */ |
| 254 | struct ethosu_core_msg_err { |
| 255 | uint32_t type; /* optional use of extra error code */ |
| 256 | char msg[128]; |
| 257 | }; |
Per Åstrand | c823bcf | 2021-01-12 13:11:13 +0100 | [diff] [blame] | 258 | #ifdef __cplusplus |
| 259 | } /*namespace EthosU */ |
| 260 | #endif |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 261 | |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 262 | #endif |