Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. |
| 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 | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 60 | ETHOSU_CORE_MSG_MAX |
| 61 | }; |
| 62 | |
| 63 | /** |
| 64 | * struct ethosu_core_msg - Message header |
| 65 | */ |
| 66 | struct ethosu_core_msg { |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 67 | uint32_t magic; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 68 | uint32_t type; |
| 69 | uint32_t length; |
| 70 | }; |
| 71 | |
| 72 | /** |
| 73 | * struct ethosu_core_queue_header - Message queue header |
| 74 | */ |
| 75 | struct ethosu_core_queue_header { |
| 76 | uint32_t size; |
| 77 | uint32_t read; |
| 78 | uint32_t write; |
| 79 | }; |
| 80 | |
| 81 | /** |
| 82 | * struct ethosu_core_queue - Message queue |
| 83 | * |
| 84 | * Dynamically sized message queue. |
| 85 | */ |
| 86 | struct ethosu_core_queue { |
| 87 | struct ethosu_core_queue_header header; |
| 88 | uint8_t data[]; |
| 89 | }; |
| 90 | |
| 91 | enum ethosu_core_status { |
| 92 | ETHOSU_CORE_STATUS_OK, |
| 93 | ETHOSU_CORE_STATUS_ERROR |
| 94 | }; |
| 95 | |
| 96 | struct ethosu_core_buffer { |
| 97 | uint32_t ptr; |
| 98 | uint32_t size; |
| 99 | }; |
| 100 | |
| 101 | struct ethosu_core_inference_req { |
| 102 | uint64_t user_arg; |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 103 | uint32_t ifm_count; |
| 104 | struct ethosu_core_buffer ifm[ETHOSU_CORE_BUFFER_MAX]; |
| 105 | uint32_t ofm_count; |
| 106 | struct ethosu_core_buffer ofm[ETHOSU_CORE_BUFFER_MAX]; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 107 | struct ethosu_core_buffer network; |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 108 | uint8_t pmu_event_config[ETHOSU_CORE_PMU_MAX]; |
| 109 | uint32_t pmu_cycle_counter_enable; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | struct ethosu_core_inference_rsp { |
| 113 | uint64_t user_arg; |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 114 | uint32_t ofm_count; |
| 115 | uint32_t ofm_size[ETHOSU_CORE_BUFFER_MAX]; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 116 | uint32_t status; |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 117 | uint8_t pmu_event_config[ETHOSU_CORE_PMU_MAX]; |
| 118 | uint32_t pmu_event_count[ETHOSU_CORE_PMU_MAX]; |
| 119 | uint32_t pmu_cycle_counter_enable; |
| 120 | uint64_t pmu_cycle_counter_count; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 121 | }; |
| 122 | |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 123 | /** |
| 124 | * struct ethosu_core_msg_verson - Message protocol version |
| 125 | */ |
| 126 | struct ethosu_core_msg_version { |
| 127 | uint8_t major; |
| 128 | uint8_t minor; |
| 129 | uint8_t patch; |
| 130 | uint8_t _reserved; |
| 131 | }; |
| 132 | |
| 133 | /** |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 134 | * struct ethosu_core_capabilities_req - Message capabilities request |
| 135 | */ |
| 136 | struct ethosu_core_capabilities_req { |
| 137 | uint64_t user_arg; |
| 138 | }; |
| 139 | |
| 140 | /** |
| 141 | * struct ethosu_core_capabilities_rsp - Message capabilities response |
| 142 | */ |
| 143 | struct ethosu_core_msg_capabilities_rsp { |
| 144 | uint64_t user_arg; |
| 145 | uint32_t version_status; |
| 146 | uint32_t version_minor; |
| 147 | uint32_t version_major; |
| 148 | uint32_t product_major; |
| 149 | uint32_t arch_patch_rev; |
| 150 | uint32_t arch_minor_rev; |
| 151 | uint32_t arch_major_rev; |
| 152 | uint32_t driver_patch_rev; |
| 153 | uint32_t driver_minor_rev; |
| 154 | uint32_t driver_major_rev; |
| 155 | uint32_t macs_per_cc; |
| 156 | uint32_t cmd_stream_version; |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 157 | uint32_t custom_dma; |
| 158 | }; |
| 159 | |
| 160 | /** |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 161 | * enum ethosu_core_msg_err_type - Error types |
| 162 | */ |
| 163 | enum ethosu_core_msg_err_type { |
| 164 | ETHOSU_CORE_MSG_ERR_GENERIC = 0, |
| 165 | ETHOSU_CORE_MSG_ERR_UNSUPPORTED_TYPE, |
| 166 | ETHOSU_CORE_MSG_ERR_INVALID_PAYLOAD, |
| 167 | ETHOSU_CORE_MSG_ERR_INVALID_SIZE, |
| 168 | ETHOSU_CORE_MSG_ERR_INVALID_MAGIC, |
| 169 | ETHOSU_CORE_MSG_ERR_MAX |
| 170 | }; |
| 171 | |
| 172 | /** |
| 173 | * struct ethosu_core_msg_err - Error message struct |
| 174 | */ |
| 175 | struct ethosu_core_msg_err { |
| 176 | uint32_t type; /* optional use of extra error code */ |
| 177 | char msg[128]; |
| 178 | }; |
Per Åstrand | c823bcf | 2021-01-12 13:11:13 +0100 | [diff] [blame] | 179 | #ifdef __cplusplus |
| 180 | } /*namespace EthosU */ |
| 181 | #endif |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 182 | |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 183 | #endif |