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 |
Kristofer Jonsson | 3706043 | 2022-06-28 11:27:07 +0200 | [diff] [blame] | 78 | * |
| 79 | * The read and write indices must be separated by at least one cache line, |
| 80 | * else updating the read index would also overwrite the write index when |
| 81 | * the cache line is flushed. Because of this the message queues should be |
| 82 | * placed on cache line aligned addresses. |
| 83 | * |
| 84 | * The cache line length for Cortex-M is typically fixed at 32 bytes. The |
| 85 | * kernel driver is setup to allocated non cached memory. |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 86 | */ |
| 87 | struct ethosu_core_queue_header { |
| 88 | uint32_t size; |
| 89 | uint32_t read; |
Kristofer Jonsson | 3706043 | 2022-06-28 11:27:07 +0200 | [diff] [blame] | 90 | uint32_t pad[6]; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 91 | uint32_t write; |
| 92 | }; |
| 93 | |
| 94 | /** |
| 95 | * struct ethosu_core_queue - Message queue |
| 96 | * |
| 97 | * Dynamically sized message queue. |
| 98 | */ |
| 99 | struct ethosu_core_queue { |
| 100 | struct ethosu_core_queue_header header; |
| 101 | uint8_t data[]; |
| 102 | }; |
| 103 | |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 104 | /** |
| 105 | * enum ethosu_core_status - Status |
| 106 | */ |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 107 | enum ethosu_core_status { |
| 108 | ETHOSU_CORE_STATUS_OK, |
Davide Grohmann | 82d2258 | 2022-04-25 12:52:38 +0200 | [diff] [blame] | 109 | ETHOSU_CORE_STATUS_ERROR, |
| 110 | ETHOSU_CORE_STATUS_RUNNING, |
| 111 | ETHOSU_CORE_STATUS_REJECTED, |
Davide Grohmann | 7e8f508 | 2022-03-23 12:48:45 +0100 | [diff] [blame] | 112 | ETHOSU_CORE_STATUS_ABORTED, |
| 113 | ETHOSU_CORE_STATUS_ABORTING, |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 114 | }; |
| 115 | |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 116 | /** |
| 117 | * struct ethosu_core_buffer - Buffer descriptor |
| 118 | * |
| 119 | * Pointer and size to a buffer withing the Ethos-U |
| 120 | * address space. |
| 121 | */ |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 122 | struct ethosu_core_buffer { |
| 123 | uint32_t ptr; |
| 124 | uint32_t size; |
| 125 | }; |
| 126 | |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 127 | /** |
| 128 | * enum ethosu_core_network_type - Network buffer type |
| 129 | */ |
| 130 | enum ethosu_core_network_type { |
| 131 | ETHOSU_CORE_NETWORK_BUFFER = 1, |
| 132 | ETHOSU_CORE_NETWORK_INDEX |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 133 | }; |
| 134 | |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 135 | /** |
| 136 | * struct ethosu_core_network_buffer - Network buffer |
| 137 | */ |
| 138 | struct ethosu_core_network_buffer { |
| 139 | uint32_t type; |
| 140 | union { |
| 141 | struct ethosu_core_buffer buffer; |
| 142 | uint32_t index; |
| 143 | }; |
| 144 | }; |
| 145 | |
| 146 | /** |
| 147 | * struct ethosu_core_inference_req - Inference request |
| 148 | */ |
| 149 | struct ethosu_core_inference_req { |
| 150 | uint64_t user_arg; |
| 151 | uint32_t ifm_count; |
| 152 | struct ethosu_core_buffer ifm[ETHOSU_CORE_BUFFER_MAX]; |
| 153 | uint32_t ofm_count; |
| 154 | struct ethosu_core_buffer ofm[ETHOSU_CORE_BUFFER_MAX]; |
| 155 | struct ethosu_core_network_buffer network; |
| 156 | uint8_t pmu_event_config[ETHOSU_CORE_PMU_MAX]; |
| 157 | uint32_t pmu_cycle_counter_enable; |
| 158 | }; |
| 159 | |
| 160 | /** |
| 161 | * struct ethosu_core_inference_rsp - Inference response |
| 162 | */ |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 163 | struct ethosu_core_inference_rsp { |
| 164 | uint64_t user_arg; |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 165 | uint32_t ofm_count; |
| 166 | uint32_t ofm_size[ETHOSU_CORE_BUFFER_MAX]; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 167 | uint32_t status; |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 168 | uint8_t pmu_event_config[ETHOSU_CORE_PMU_MAX]; |
| 169 | uint32_t pmu_event_count[ETHOSU_CORE_PMU_MAX]; |
| 170 | uint32_t pmu_cycle_counter_enable; |
| 171 | uint64_t pmu_cycle_counter_count; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 172 | }; |
| 173 | |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 174 | /** |
Kristofer Jonsson | 3c6a260 | 2022-03-10 11:17:29 +0100 | [diff] [blame] | 175 | * struct ethosu_core_network_info_req - Network information request |
| 176 | */ |
| 177 | struct ethosu_core_network_info_req { |
| 178 | uint64_t user_arg; |
| 179 | struct ethosu_core_network_buffer network; |
| 180 | }; |
| 181 | |
| 182 | /** |
| 183 | * struct ethosu_core_network_info_rsp - Network information response |
| 184 | */ |
| 185 | struct ethosu_core_network_info_rsp { |
| 186 | uint64_t user_arg; |
| 187 | char desc[32]; |
| 188 | uint32_t ifm_count; |
| 189 | uint32_t ifm_size[ETHOSU_CORE_BUFFER_MAX]; |
| 190 | uint32_t ofm_count; |
| 191 | uint32_t ofm_size[ETHOSU_CORE_BUFFER_MAX]; |
| 192 | uint32_t status; |
| 193 | }; |
| 194 | |
| 195 | /** |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 196 | * struct ethosu_core_msg_version - Message protocol version |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 197 | */ |
| 198 | struct ethosu_core_msg_version { |
| 199 | uint8_t major; |
| 200 | uint8_t minor; |
| 201 | uint8_t patch; |
| 202 | uint8_t _reserved; |
| 203 | }; |
| 204 | |
| 205 | /** |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 206 | * struct ethosu_core_capabilities_req - Message capabilities request |
| 207 | */ |
| 208 | struct ethosu_core_capabilities_req { |
| 209 | uint64_t user_arg; |
| 210 | }; |
| 211 | |
| 212 | /** |
| 213 | * struct ethosu_core_capabilities_rsp - Message capabilities response |
| 214 | */ |
| 215 | struct ethosu_core_msg_capabilities_rsp { |
| 216 | uint64_t user_arg; |
| 217 | uint32_t version_status; |
| 218 | uint32_t version_minor; |
| 219 | uint32_t version_major; |
| 220 | uint32_t product_major; |
| 221 | uint32_t arch_patch_rev; |
| 222 | uint32_t arch_minor_rev; |
| 223 | uint32_t arch_major_rev; |
| 224 | uint32_t driver_patch_rev; |
| 225 | uint32_t driver_minor_rev; |
| 226 | uint32_t driver_major_rev; |
| 227 | uint32_t macs_per_cc; |
| 228 | uint32_t cmd_stream_version; |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 229 | uint32_t custom_dma; |
| 230 | }; |
| 231 | |
| 232 | /** |
Davide Grohmann | 7e8f508 | 2022-03-23 12:48:45 +0100 | [diff] [blame] | 233 | * struct ethosu_core_cancel_inference_req - Message cancel inference request |
| 234 | */ |
| 235 | struct ethosu_core_cancel_inference_req { |
| 236 | uint64_t user_arg; |
| 237 | uint64_t inference_handle; |
| 238 | }; |
| 239 | |
| 240 | /** |
| 241 | * struct ethosu_core_cancel_inference_rsp - Message cancel inference response |
| 242 | */ |
| 243 | struct ethosu_core_cancel_inference_rsp { |
| 244 | uint64_t user_arg; |
| 245 | uint32_t status; |
| 246 | }; |
| 247 | |
| 248 | /** |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 249 | * enum ethosu_core_msg_err_type - Error types |
| 250 | */ |
| 251 | enum ethosu_core_msg_err_type { |
| 252 | ETHOSU_CORE_MSG_ERR_GENERIC = 0, |
| 253 | ETHOSU_CORE_MSG_ERR_UNSUPPORTED_TYPE, |
| 254 | ETHOSU_CORE_MSG_ERR_INVALID_PAYLOAD, |
| 255 | ETHOSU_CORE_MSG_ERR_INVALID_SIZE, |
| 256 | ETHOSU_CORE_MSG_ERR_INVALID_MAGIC, |
| 257 | ETHOSU_CORE_MSG_ERR_MAX |
| 258 | }; |
| 259 | |
| 260 | /** |
| 261 | * struct ethosu_core_msg_err - Error message struct |
| 262 | */ |
| 263 | struct ethosu_core_msg_err { |
| 264 | uint32_t type; /* optional use of extra error code */ |
| 265 | char msg[128]; |
| 266 | }; |
Per Åstrand | c823bcf | 2021-01-12 13:11:13 +0100 | [diff] [blame] | 267 | #ifdef __cplusplus |
| 268 | } /*namespace EthosU */ |
| 269 | #endif |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 270 | |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 271 | #endif |