blob: 193b296ba1f2966a6230710b86b6e379aeb161aa [file] [log] [blame]
Kristofer Jonsson116a6352020-08-20 17:25:23 +02001/*
Kristofer Jonsson35de9e62022-03-08 13:25:45 +01002 * Copyright (c) 2020-2022 Arm Limited.
Kristofer Jonsson116a6352020-08-20 17:25:23 +02003 *
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 Åstrandc823bcf2021-01-12 13:11:13 +010030#ifdef __cplusplus
31namespace EthosU {
32#endif
33
Kristofer Jonssonb74492c2020-09-10 13:26:01 +020034/** Maximum number of IFM/OFM buffers per inference */
35#define ETHOSU_CORE_BUFFER_MAX 16
36
Per Åstrandf7e407a2020-10-23 21:25:05 +020037/** Maximum number of PMU counters to be returned for inference */
Jonny Svärdb5aa9042021-12-17 17:08:10 +010038#define ETHOSU_CORE_PMU_MAX 8
Per Åstrandf7e407a2020-10-23 21:25:05 +020039
Jonny Svärd7c24c772021-01-14 19:53:17 +010040#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 Jonsson116a6352020-08-20 17:25:23 +020045/**
46 * enum ethosu_core_msg_type - Message types
47 *
48 * Types for the messages sent between the host and the core subsystem.
49 */
50enum ethosu_core_msg_type {
Jonny Svärd7c24c772021-01-14 19:53:17 +010051 ETHOSU_CORE_MSG_ERR = 1,
52 ETHOSU_CORE_MSG_PING,
Kristofer Jonsson116a6352020-08-20 17:25:23 +020053 ETHOSU_CORE_MSG_PONG,
54 ETHOSU_CORE_MSG_INFERENCE_REQ,
55 ETHOSU_CORE_MSG_INFERENCE_RSP,
Jonny Svärd7c24c772021-01-14 19:53:17 +010056 ETHOSU_CORE_MSG_VERSION_REQ,
57 ETHOSU_CORE_MSG_VERSION_RSP,
Davide Grohmann35ce6c82021-06-01 15:03:51 +020058 ETHOSU_CORE_MSG_CAPABILITIES_REQ,
59 ETHOSU_CORE_MSG_CAPABILITIES_RSP,
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +010060 ETHOSU_CORE_MSG_NETWORK_INFO_REQ,
61 ETHOSU_CORE_MSG_NETWORK_INFO_RSP,
Davide Grohmann7e8f5082022-03-23 12:48:45 +010062 ETHOSU_CORE_MSG_CANCEL_INFERENCE_REQ,
63 ETHOSU_CORE_MSG_CANCEL_INFERENCE_RSP,
Kristofer Jonsson116a6352020-08-20 17:25:23 +020064 ETHOSU_CORE_MSG_MAX
65};
66
67/**
68 * struct ethosu_core_msg - Message header
69 */
70struct ethosu_core_msg {
Jonny Svärd7c24c772021-01-14 19:53:17 +010071 uint32_t magic;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020072 uint32_t type;
73 uint32_t length;
74};
75
76/**
77 * struct ethosu_core_queue_header - Message queue header
Kristofer Jonsson37060432022-06-28 11:27:07 +020078 *
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 Jonsson116a6352020-08-20 17:25:23 +020086 */
87struct ethosu_core_queue_header {
88 uint32_t size;
89 uint32_t read;
Kristofer Jonsson37060432022-06-28 11:27:07 +020090 uint32_t pad[6];
Kristofer Jonsson116a6352020-08-20 17:25:23 +020091 uint32_t write;
92};
93
94/**
95 * struct ethosu_core_queue - Message queue
96 *
97 * Dynamically sized message queue.
98 */
99struct ethosu_core_queue {
100 struct ethosu_core_queue_header header;
101 uint8_t data[];
102};
103
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100104/**
105 * enum ethosu_core_status - Status
106 */
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200107enum ethosu_core_status {
108 ETHOSU_CORE_STATUS_OK,
Davide Grohmann82d22582022-04-25 12:52:38 +0200109 ETHOSU_CORE_STATUS_ERROR,
110 ETHOSU_CORE_STATUS_RUNNING,
111 ETHOSU_CORE_STATUS_REJECTED,
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100112 ETHOSU_CORE_STATUS_ABORTED,
113 ETHOSU_CORE_STATUS_ABORTING,
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200114};
115
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100116/**
117 * struct ethosu_core_buffer - Buffer descriptor
118 *
119 * Pointer and size to a buffer withing the Ethos-U
120 * address space.
121 */
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200122struct ethosu_core_buffer {
123 uint32_t ptr;
124 uint32_t size;
125};
126
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100127/**
128 * enum ethosu_core_network_type - Network buffer type
129 */
130enum ethosu_core_network_type {
131 ETHOSU_CORE_NETWORK_BUFFER = 1,
132 ETHOSU_CORE_NETWORK_INDEX
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200133};
134
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100135/**
136 * struct ethosu_core_network_buffer - Network buffer
137 */
138struct 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 */
149struct 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 Jonsson116a6352020-08-20 17:25:23 +0200163struct ethosu_core_inference_rsp {
164 uint64_t user_arg;
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200165 uint32_t ofm_count;
166 uint32_t ofm_size[ETHOSU_CORE_BUFFER_MAX];
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200167 uint32_t status;
Per Åstrandf7e407a2020-10-23 21:25:05 +0200168 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 Jonsson116a6352020-08-20 17:25:23 +0200172};
173
Jonny Svärd7c24c772021-01-14 19:53:17 +0100174/**
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100175 * struct ethosu_core_network_info_req - Network information request
176 */
177struct 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 */
185struct 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 Jonsson35de9e62022-03-08 13:25:45 +0100196 * struct ethosu_core_msg_version - Message protocol version
Jonny Svärd7c24c772021-01-14 19:53:17 +0100197 */
198struct ethosu_core_msg_version {
199 uint8_t major;
200 uint8_t minor;
201 uint8_t patch;
202 uint8_t _reserved;
203};
204
205/**
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200206 * struct ethosu_core_capabilities_req - Message capabilities request
207 */
208struct ethosu_core_capabilities_req {
209 uint64_t user_arg;
210};
211
212/**
213 * struct ethosu_core_capabilities_rsp - Message capabilities response
214 */
215struct 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 Grohmann35ce6c82021-06-01 15:03:51 +0200229 uint32_t custom_dma;
230};
231
232/**
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100233 * struct ethosu_core_cancel_inference_req - Message cancel inference request
234 */
235struct 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 */
243struct ethosu_core_cancel_inference_rsp {
244 uint64_t user_arg;
245 uint32_t status;
246};
247
248/**
Jonny Svärd7c24c772021-01-14 19:53:17 +0100249 * enum ethosu_core_msg_err_type - Error types
250 */
251enum 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 */
263struct ethosu_core_msg_err {
264 uint32_t type; /* optional use of extra error code */
265 char msg[128];
266};
Per Åstrandc823bcf2021-01-12 13:11:13 +0100267#ifdef __cplusplus
268} /*namespace EthosU */
269#endif
Jonny Svärd7c24c772021-01-14 19:53:17 +0100270
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200271#endif