blob: 5a6e55d5118eb7ba6887e6a3d8772e00c57f88eb [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,
Kristofer Jonsson116a6352020-08-20 17:25:23 +020062 ETHOSU_CORE_MSG_MAX
63};
64
65/**
66 * struct ethosu_core_msg - Message header
67 */
68struct ethosu_core_msg {
Jonny Svärd7c24c772021-01-14 19:53:17 +010069 uint32_t magic;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020070 uint32_t type;
71 uint32_t length;
72};
73
74/**
75 * struct ethosu_core_queue_header - Message queue header
76 */
77struct ethosu_core_queue_header {
78 uint32_t size;
79 uint32_t read;
80 uint32_t write;
81};
82
83/**
84 * struct ethosu_core_queue - Message queue
85 *
86 * Dynamically sized message queue.
87 */
88struct ethosu_core_queue {
89 struct ethosu_core_queue_header header;
90 uint8_t data[];
91};
92
Kristofer Jonsson35de9e62022-03-08 13:25:45 +010093/**
94 * enum ethosu_core_status - Status
95 */
Kristofer Jonsson116a6352020-08-20 17:25:23 +020096enum ethosu_core_status {
97 ETHOSU_CORE_STATUS_OK,
98 ETHOSU_CORE_STATUS_ERROR
99};
100
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100101/**
102 * struct ethosu_core_buffer - Buffer descriptor
103 *
104 * Pointer and size to a buffer withing the Ethos-U
105 * address space.
106 */
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200107struct ethosu_core_buffer {
108 uint32_t ptr;
109 uint32_t size;
110};
111
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100112/**
113 * enum ethosu_core_network_type - Network buffer type
114 */
115enum ethosu_core_network_type {
116 ETHOSU_CORE_NETWORK_BUFFER = 1,
117 ETHOSU_CORE_NETWORK_INDEX
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200118};
119
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100120/**
121 * struct ethosu_core_network_buffer - Network buffer
122 */
123struct ethosu_core_network_buffer {
124 uint32_t type;
125 union {
126 struct ethosu_core_buffer buffer;
127 uint32_t index;
128 };
129};
130
131/**
132 * struct ethosu_core_inference_req - Inference request
133 */
134struct ethosu_core_inference_req {
135 uint64_t user_arg;
136 uint32_t ifm_count;
137 struct ethosu_core_buffer ifm[ETHOSU_CORE_BUFFER_MAX];
138 uint32_t ofm_count;
139 struct ethosu_core_buffer ofm[ETHOSU_CORE_BUFFER_MAX];
140 struct ethosu_core_network_buffer network;
141 uint8_t pmu_event_config[ETHOSU_CORE_PMU_MAX];
142 uint32_t pmu_cycle_counter_enable;
143};
144
145/**
146 * struct ethosu_core_inference_rsp - Inference response
147 */
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200148struct ethosu_core_inference_rsp {
149 uint64_t user_arg;
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200150 uint32_t ofm_count;
151 uint32_t ofm_size[ETHOSU_CORE_BUFFER_MAX];
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200152 uint32_t status;
Per Åstrandf7e407a2020-10-23 21:25:05 +0200153 uint8_t pmu_event_config[ETHOSU_CORE_PMU_MAX];
154 uint32_t pmu_event_count[ETHOSU_CORE_PMU_MAX];
155 uint32_t pmu_cycle_counter_enable;
156 uint64_t pmu_cycle_counter_count;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200157};
158
Jonny Svärd7c24c772021-01-14 19:53:17 +0100159/**
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100160 * struct ethosu_core_network_info_req - Network information request
161 */
162struct ethosu_core_network_info_req {
163 uint64_t user_arg;
164 struct ethosu_core_network_buffer network;
165};
166
167/**
168 * struct ethosu_core_network_info_rsp - Network information response
169 */
170struct ethosu_core_network_info_rsp {
171 uint64_t user_arg;
172 char desc[32];
173 uint32_t ifm_count;
174 uint32_t ifm_size[ETHOSU_CORE_BUFFER_MAX];
175 uint32_t ofm_count;
176 uint32_t ofm_size[ETHOSU_CORE_BUFFER_MAX];
177 uint32_t status;
178};
179
180/**
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100181 * struct ethosu_core_msg_version - Message protocol version
Jonny Svärd7c24c772021-01-14 19:53:17 +0100182 */
183struct ethosu_core_msg_version {
184 uint8_t major;
185 uint8_t minor;
186 uint8_t patch;
187 uint8_t _reserved;
188};
189
190/**
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200191 * struct ethosu_core_capabilities_req - Message capabilities request
192 */
193struct ethosu_core_capabilities_req {
194 uint64_t user_arg;
195};
196
197/**
198 * struct ethosu_core_capabilities_rsp - Message capabilities response
199 */
200struct ethosu_core_msg_capabilities_rsp {
201 uint64_t user_arg;
202 uint32_t version_status;
203 uint32_t version_minor;
204 uint32_t version_major;
205 uint32_t product_major;
206 uint32_t arch_patch_rev;
207 uint32_t arch_minor_rev;
208 uint32_t arch_major_rev;
209 uint32_t driver_patch_rev;
210 uint32_t driver_minor_rev;
211 uint32_t driver_major_rev;
212 uint32_t macs_per_cc;
213 uint32_t cmd_stream_version;
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200214 uint32_t custom_dma;
215};
216
217/**
Jonny Svärd7c24c772021-01-14 19:53:17 +0100218 * enum ethosu_core_msg_err_type - Error types
219 */
220enum ethosu_core_msg_err_type {
221 ETHOSU_CORE_MSG_ERR_GENERIC = 0,
222 ETHOSU_CORE_MSG_ERR_UNSUPPORTED_TYPE,
223 ETHOSU_CORE_MSG_ERR_INVALID_PAYLOAD,
224 ETHOSU_CORE_MSG_ERR_INVALID_SIZE,
225 ETHOSU_CORE_MSG_ERR_INVALID_MAGIC,
226 ETHOSU_CORE_MSG_ERR_MAX
227};
228
229/**
230 * struct ethosu_core_msg_err - Error message struct
231 */
232struct ethosu_core_msg_err {
233 uint32_t type; /* optional use of extra error code */
234 char msg[128];
235};
Per Åstrandc823bcf2021-01-12 13:11:13 +0100236#ifdef __cplusplus
237} /*namespace EthosU */
238#endif
Jonny Svärd7c24c772021-01-14 19:53:17 +0100239
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200240#endif