blob: d82c9012d959e572e97f602c9b5d1328d2faf9e4 [file] [log] [blame]
Kristofer Jonsson116a6352020-08-20 17:25:23 +02001/*
Jonny Svärdf1e675a2023-07-14 14:04:37 +02002 * Copyright (c) 2020-2023 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 *
Jonny Svärdf1e675a2023-07-14 14:04:37 +020018 * SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note
Kristofer Jonsson116a6352020-08-20 17:25:23 +020019 */
20
21#ifndef ETHOSU_H
22#define ETHOSU_H
23
24/****************************************************************************
25 * Includes
26 ****************************************************************************/
27
28#include <linux/ioctl.h>
29#include <linux/types.h>
30
Per Åstrandc823bcf2021-01-12 13:11:13 +010031#ifdef __cplusplus
32namespace EthosU {
33#endif
34
Kristofer Jonsson116a6352020-08-20 17:25:23 +020035/****************************************************************************
36 * Defines
37 ****************************************************************************/
38
39#define ETHOSU_IOCTL_BASE 0x01
40#define ETHOSU_IO(nr) _IO(ETHOSU_IOCTL_BASE, nr)
41#define ETHOSU_IOR(nr, type) _IOR(ETHOSU_IOCTL_BASE, nr, type)
42#define ETHOSU_IOW(nr, type) _IOW(ETHOSU_IOCTL_BASE, nr, type)
43#define ETHOSU_IOWR(nr, type) _IOWR(ETHOSU_IOCTL_BASE, nr, type)
44
45#define ETHOSU_IOCTL_PING ETHOSU_IO(0x00)
Per Åstrand7f9a4e32022-05-18 09:18:27 +020046#define ETHOSU_IOCTL_CAPABILITIES_REQ ETHOSU_IOR(0x02, \
47 struct ethosu_uapi_device_capabilities)
Mikael Olssonf1cfe192023-06-12 15:00:41 +020048#define ETHOSU_IOCTL_DRIVER_VERSION_GET ETHOSU_IOR(0x03, \
49 struct ethosu_uapi_kernel_driver_version)
Kristofer Jonsson116a6352020-08-20 17:25:23 +020050#define ETHOSU_IOCTL_BUFFER_CREATE ETHOSU_IOR(0x10, \
51 struct ethosu_uapi_buffer_create)
52#define ETHOSU_IOCTL_BUFFER_SET ETHOSU_IOR(0x11, \
53 struct ethosu_uapi_buffer)
54#define ETHOSU_IOCTL_BUFFER_GET ETHOSU_IOW(0x12, \
55 struct ethosu_uapi_buffer)
56#define ETHOSU_IOCTL_NETWORK_CREATE ETHOSU_IOR(0x20, \
57 struct ethosu_uapi_network_create)
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +010058#define ETHOSU_IOCTL_NETWORK_INFO ETHOSU_IOR(0x21, \
59 struct ethosu_uapi_network_info)
Kristofer Jonsson116a6352020-08-20 17:25:23 +020060#define ETHOSU_IOCTL_INFERENCE_CREATE ETHOSU_IOR(0x30, \
61 struct ethosu_uapi_inference_create)
Per Åstrandf7e407a2020-10-23 21:25:05 +020062#define ETHOSU_IOCTL_INFERENCE_STATUS ETHOSU_IOR(0x31, \
63 struct ethosu_uapi_result_status)
Davide Grohmann7e8f5082022-03-23 12:48:45 +010064#define ETHOSU_IOCTL_INFERENCE_CANCEL ETHOSU_IOR(0x32, \
65 struct ethosu_uapi_cancel_inference_status)
Kristofer Jonsson116a6352020-08-20 17:25:23 +020066
Kristofer Jonssonb74492c2020-09-10 13:26:01 +020067/* Maximum number of IFM/OFM file descriptors per network */
68#define ETHOSU_FD_MAX 16
69
Per Åstrandf7e407a2020-10-23 21:25:05 +020070/* Maximum number of PMUs available */
Jonny Svärdb5aa9042021-12-17 17:08:10 +010071#define ETHOSU_PMU_EVENT_MAX 8
Per Åstrandf7e407a2020-10-23 21:25:05 +020072
Mikael Olssonf1cfe192023-06-12 15:00:41 +020073/* Kernel driver version */
74#define ETHOSU_KERNEL_DRIVER_VERSION_MAJOR 1
75#define ETHOSU_KERNEL_DRIVER_VERSION_MINOR 0
76#define ETHOSU_KERNEL_DRIVER_VERSION_PATCH 0
77
Kristofer Jonsson116a6352020-08-20 17:25:23 +020078/****************************************************************************
79 * Types
80 ****************************************************************************/
81
82/**
83 * enum ethosu_uapi_status - Status
84 */
85enum ethosu_uapi_status {
86 ETHOSU_UAPI_STATUS_OK,
Davide Grohmann82d22582022-04-25 12:52:38 +020087 ETHOSU_UAPI_STATUS_ERROR,
88 ETHOSU_UAPI_STATUS_RUNNING,
89 ETHOSU_UAPI_STATUS_REJECTED,
Davide Grohmann7e8f5082022-03-23 12:48:45 +010090 ETHOSU_UAPI_STATUS_ABORTED,
91 ETHOSU_UAPI_STATUS_ABORTING,
Kristofer Jonsson116a6352020-08-20 17:25:23 +020092};
93
94/**
Mikael Olssonf1cfe192023-06-12 15:00:41 +020095 * struct ethosu_uapi_kernel_driver_version - Kernel driver version
96 * @major: Major version
97 * @minor: Minor version
98 * @patch: Patch version
99 */
100struct ethosu_uapi_kernel_driver_version {
101 __u32 major;
102 __u32 minor;
103 __u32 patch;
104};
105
106/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200107 * struct ethosu_uapi_buffer_create - Create buffer request
108 * @capacity: Maximum capacity of the buffer
109 */
110struct ethosu_uapi_buffer_create {
111 __u32 capacity;
112};
113
114/**
115 * struct ethosu_uapi_buffer - Buffer descriptor
116 * @offset: Offset to where the data starts
117 * @size: Size of the data
118 *
119 * 'offset + size' must not exceed the capacity of the buffer.
120 */
121struct ethosu_uapi_buffer {
122 __u32 offset;
123 __u32 size;
124};
125
126/**
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100127 * enum ethosu_uapi_network_create - Network buffer type.
128 * @ETHOSU_UAPI_NETWORK_BUFFER: Network is stored in a buffer handle.
129 * @ETHOSU_UAPI_NETWORK_INDEX: Network is built into firmware and referenced by
130 * index.
131 */
132enum ethosu_uapi_network_type {
133 ETHOSU_UAPI_NETWORK_BUFFER = 1,
134 ETHOSU_UAPI_NETWORK_INDEX
135};
136
137/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200138 * struct ethosu_uapi_network_create - Create network request
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100139 * @type: Buffer type. See @ethosu_uapi_network_type.
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200140 * @fd: Buffer file descriptor
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100141 * @index: Buffer index compiled into firmware binary.
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200142 */
143struct ethosu_uapi_network_create {
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100144 uint32_t type;
145 union {
146 __u32 fd;
147 __u32 index;
148 };
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200149};
150
151/**
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100152 * struct ethosu_uapi_network_info - Network info
153 * @desc: Network description
154 * @ifm_count: Number of IFM buffers
155 * @ifm_size: IFM buffer sizes
156 * @ofm_count: Number of OFM buffers
157 * @ofm_size: OFM buffer sizes
158 */
159struct ethosu_uapi_network_info {
160 char desc[32];
161 __u32 ifm_count;
162 __u32 ifm_size[ETHOSU_FD_MAX];
163 __u32 ofm_count;
164 __u32 ofm_size[ETHOSU_FD_MAX];
165};
166
167/**
Per Åstrandf7e407a2020-10-23 21:25:05 +0200168 * struct ethosu_uapi_pmu_config - Configure performance counters
169 * @events: Array of counters to configure, set to non-zero for
170 * each counter to enable corresponding event.
171 * @cycle_count: Set to enable the cycle counter.
172 */
173struct ethosu_uapi_pmu_config {
174 __u32 events[ETHOSU_PMU_EVENT_MAX];
175 __u32 cycle_count;
176};
177
178/**
179 * struct ethosu_uapi_pmu_counts - Status of performance counters
180 * @events: Count for respective configured events.
181 * @cycle_count: Count for cycle counter.
182 */
183struct ethosu_uapi_pmu_counts {
184 __u32 events[ETHOSU_PMU_EVENT_MAX];
185 __u64 cycle_count;
186};
187
188/**
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200189 * struct ethosu_uapi_device_hw_id - Device hardware identification
190 * @version_status: Version status
191 * @version_minor: Version minor
192 * @version_major: Version major
193 * @product_major: Product major
194 * @arch_patch_rev: Architecture version patch
195 * @arch_minor_rev: Architecture version minor
196 * @arch_major_rev: Architecture version major
197 */
198struct ethosu_uapi_device_hw_id {
199 __u32 version_status;
200 __u32 version_minor;
201 __u32 version_major;
202 __u32 product_major;
203 __u32 arch_patch_rev;
204 __u32 arch_minor_rev;
205 __u32 arch_major_rev;
206};
207
208/**
209 * struct ethosu_uapi_device_hw_cfg - Device hardware configuration
210 * @macs_per_cc: MACs per clock cycle
211 * @cmd_stream_version: NPU command stream version
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200212 * @custom_dma: Custom DMA enabled
213 */
214struct ethosu_uapi_device_hw_cfg {
215 __u32 macs_per_cc;
216 __u32 cmd_stream_version;
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200217 __u32 custom_dma;
218};
219
220/**
Per Åstrand7f9a4e32022-05-18 09:18:27 +0200221 * struct ethosu_uapi_device_capabilities - Device capabilities
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200222 * @hw_id: Hardware identification
223 * @hw_cfg: Hardware configuration
224 * @driver_patch_rev: Driver version patch
225 * @driver_minor_rev: Driver version minor
226 * @driver_major_rev: Driver version major
227 */
228struct ethosu_uapi_device_capabilities {
229 struct ethosu_uapi_device_hw_id hw_id;
230 struct ethosu_uapi_device_hw_cfg hw_cfg;
231 __u32 driver_patch_rev;
232 __u32 driver_minor_rev;
233 __u32 driver_major_rev;
234};
235
236/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200237 * struct ethosu_uapi_inference_create - Create network request
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200238 * @ifm_count: Number of IFM file descriptors
239 * @ifm_fd: IFM buffer file descriptors
240 * @ofm_count: Number of OFM file descriptors
241 * @ofm_fd: OFM buffer file descriptors
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200242 */
243struct ethosu_uapi_inference_create {
Per Åstrandf7e407a2020-10-23 21:25:05 +0200244 __u32 ifm_count;
245 __u32 ifm_fd[ETHOSU_FD_MAX];
246 __u32 ofm_count;
247 __u32 ofm_fd[ETHOSU_FD_MAX];
248 struct ethosu_uapi_pmu_config pmu_config;
249};
250
251/**
252 * struct ethosu_uapi_result_status - Status of inference
253 * @status Status of run inference.
254 * @pmu_config Configured performance counters.
255 * @pmu_count Perfomance counters values, when status is
256 * ETHOSU_UAPI_STATUS_OK.
257 */
258struct ethosu_uapi_result_status {
259 enum ethosu_uapi_status status;
260 struct ethosu_uapi_pmu_config pmu_config;
261 struct ethosu_uapi_pmu_counts pmu_count;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200262};
263
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100264/**
265 * struct ethosu_uapi_cancel_status - Status of inference cancellation.
266 * @status OK if inference cancellation was performed, ERROR otherwise.
267 */
268struct ethosu_uapi_cancel_inference_status {
269 enum ethosu_uapi_status status;
270};
271
Per Åstrandc823bcf2021-01-12 13:11:13 +0100272#ifdef __cplusplus
273} /* namespace EthosU */
274#endif
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200275#endif