blob: 35eaf60051a67bfd17856d54c7eea5d390969919 [file] [log] [blame]
Kristofer Jonsson116a6352020-08-20 17:25:23 +02001/*
Ledion Daja00f83c02023-10-04 17:01:52 +02002 * SPDX-FileCopyrightText: Copyright 2020-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
3 * SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note
Kristofer Jonsson116a6352020-08-20 17:25:23 +02004 *
5 * This program is free software and is provided to you under the terms of the
6 * GNU General Public License version 2 as published by the Free Software
7 * Foundation, and any use by you of this program is subject to the terms
8 * of such GNU licence.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, you can access it online at
17 * http://www.gnu.org/licenses/gpl-2.0.html.
18 *
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)
Kristofer Jonsson116a6352020-08-20 17:25:23 +020052#define ETHOSU_IOCTL_NETWORK_CREATE ETHOSU_IOR(0x20, \
53 struct ethosu_uapi_network_create)
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +010054#define ETHOSU_IOCTL_NETWORK_INFO ETHOSU_IOR(0x21, \
55 struct ethosu_uapi_network_info)
Kristofer Jonsson116a6352020-08-20 17:25:23 +020056#define ETHOSU_IOCTL_INFERENCE_CREATE ETHOSU_IOR(0x30, \
57 struct ethosu_uapi_inference_create)
Per Åstrandf7e407a2020-10-23 21:25:05 +020058#define ETHOSU_IOCTL_INFERENCE_STATUS ETHOSU_IOR(0x31, \
59 struct ethosu_uapi_result_status)
Davide Grohmann7e8f5082022-03-23 12:48:45 +010060#define ETHOSU_IOCTL_INFERENCE_CANCEL ETHOSU_IOR(0x32, \
61 struct ethosu_uapi_cancel_inference_status)
Kristofer Jonsson116a6352020-08-20 17:25:23 +020062
Kristofer Jonssonb74492c2020-09-10 13:26:01 +020063/* Maximum number of IFM/OFM file descriptors per network */
64#define ETHOSU_FD_MAX 16
65
Per Åstrandf7e407a2020-10-23 21:25:05 +020066/* Maximum number of PMUs available */
Jonny Svärdb5aa9042021-12-17 17:08:10 +010067#define ETHOSU_PMU_EVENT_MAX 8
Per Åstrandf7e407a2020-10-23 21:25:05 +020068
Mikael Olssonf1cfe192023-06-12 15:00:41 +020069/* Kernel driver version */
Mikael Olssonc081e592023-10-30 11:10:56 +010070#define ETHOSU_KERNEL_DRIVER_VERSION_MAJOR 3
Mikael Olssonf1cfe192023-06-12 15:00:41 +020071#define ETHOSU_KERNEL_DRIVER_VERSION_MINOR 0
72#define ETHOSU_KERNEL_DRIVER_VERSION_PATCH 0
73
Kristofer Jonsson116a6352020-08-20 17:25:23 +020074/****************************************************************************
75 * Types
76 ****************************************************************************/
77
78/**
79 * enum ethosu_uapi_status - Status
80 */
81enum ethosu_uapi_status {
82 ETHOSU_UAPI_STATUS_OK,
Davide Grohmann82d22582022-04-25 12:52:38 +020083 ETHOSU_UAPI_STATUS_ERROR,
84 ETHOSU_UAPI_STATUS_RUNNING,
85 ETHOSU_UAPI_STATUS_REJECTED,
Davide Grohmann7e8f5082022-03-23 12:48:45 +010086 ETHOSU_UAPI_STATUS_ABORTED,
87 ETHOSU_UAPI_STATUS_ABORTING,
Kristofer Jonsson116a6352020-08-20 17:25:23 +020088};
89
90/**
Mikael Olssonf1cfe192023-06-12 15:00:41 +020091 * struct ethosu_uapi_kernel_driver_version - Kernel driver version
92 * @major: Major version
93 * @minor: Minor version
94 * @patch: Patch version
95 */
96struct ethosu_uapi_kernel_driver_version {
97 __u32 major;
98 __u32 minor;
99 __u32 patch;
100};
101
102/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200103 * struct ethosu_uapi_buffer_create - Create buffer request
Mikael Olsson07545152023-10-17 13:05:38 +0200104 * @size: Size of the requested buffer
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200105 */
106struct ethosu_uapi_buffer_create {
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200107 __u32 size;
108};
109
110/**
Ledion Daja00f83c02023-10-04 17:01:52 +0200111 * enum ethosu_uapi_network_type - Network buffer type.
Mikael Olssonc081e592023-10-30 11:10:56 +0100112 * @ETHOSU_UAPI_NETWORK_USER_BUFFER: Network data is provided in a user
113 * buffer.
114 * @ETHOSU_UAPI_NETWORK_INDEX: Network is built into firmware and
115 * referenced by index.
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100116 */
117enum ethosu_uapi_network_type {
Mikael Olssonc081e592023-10-30 11:10:56 +0100118 ETHOSU_UAPI_NETWORK_USER_BUFFER = 1,
119 ETHOSU_UAPI_NETWORK_INDEX,
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100120};
121
122/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200123 * struct ethosu_uapi_network_create - Create network request
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100124 * @type: Buffer type. See @ethosu_uapi_network_type.
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200125 * @fd: Buffer file descriptor
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100126 * @index: Buffer index compiled into firmware binary.
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200127 */
128struct ethosu_uapi_network_create {
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100129 uint32_t type;
130 union {
Mikael Olssonc081e592023-10-30 11:10:56 +0100131 struct {
132 __u64 data_ptr;
133 __u32 size;
134 } network;
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100135 __u32 index;
136 };
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200137};
138
139/**
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100140 * struct ethosu_uapi_network_info - Network info
141 * @desc: Network description
142 * @ifm_count: Number of IFM buffers
143 * @ifm_size: IFM buffer sizes
144 * @ofm_count: Number of OFM buffers
145 * @ofm_size: OFM buffer sizes
146 */
147struct ethosu_uapi_network_info {
148 char desc[32];
149 __u32 ifm_count;
150 __u32 ifm_size[ETHOSU_FD_MAX];
151 __u32 ofm_count;
152 __u32 ofm_size[ETHOSU_FD_MAX];
153};
154
155/**
Per Åstrandf7e407a2020-10-23 21:25:05 +0200156 * struct ethosu_uapi_pmu_config - Configure performance counters
157 * @events: Array of counters to configure, set to non-zero for
158 * each counter to enable corresponding event.
159 * @cycle_count: Set to enable the cycle counter.
160 */
161struct ethosu_uapi_pmu_config {
162 __u32 events[ETHOSU_PMU_EVENT_MAX];
163 __u32 cycle_count;
164};
165
166/**
167 * struct ethosu_uapi_pmu_counts - Status of performance counters
168 * @events: Count for respective configured events.
169 * @cycle_count: Count for cycle counter.
170 */
171struct ethosu_uapi_pmu_counts {
172 __u32 events[ETHOSU_PMU_EVENT_MAX];
173 __u64 cycle_count;
174};
175
176/**
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200177 * struct ethosu_uapi_device_hw_id - Device hardware identification
178 * @version_status: Version status
179 * @version_minor: Version minor
180 * @version_major: Version major
181 * @product_major: Product major
182 * @arch_patch_rev: Architecture version patch
183 * @arch_minor_rev: Architecture version minor
184 * @arch_major_rev: Architecture version major
185 */
186struct ethosu_uapi_device_hw_id {
187 __u32 version_status;
188 __u32 version_minor;
189 __u32 version_major;
190 __u32 product_major;
191 __u32 arch_patch_rev;
192 __u32 arch_minor_rev;
193 __u32 arch_major_rev;
194};
195
196/**
197 * struct ethosu_uapi_device_hw_cfg - Device hardware configuration
198 * @macs_per_cc: MACs per clock cycle
199 * @cmd_stream_version: NPU command stream version
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200200 * @custom_dma: Custom DMA enabled
201 */
202struct ethosu_uapi_device_hw_cfg {
203 __u32 macs_per_cc;
204 __u32 cmd_stream_version;
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200205 __u32 custom_dma;
206};
207
208/**
Per Åstrand7f9a4e32022-05-18 09:18:27 +0200209 * struct ethosu_uapi_device_capabilities - Device capabilities
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200210 * @hw_id: Hardware identification
211 * @hw_cfg: Hardware configuration
212 * @driver_patch_rev: Driver version patch
213 * @driver_minor_rev: Driver version minor
214 * @driver_major_rev: Driver version major
215 */
216struct ethosu_uapi_device_capabilities {
217 struct ethosu_uapi_device_hw_id hw_id;
218 struct ethosu_uapi_device_hw_cfg hw_cfg;
219 __u32 driver_patch_rev;
220 __u32 driver_minor_rev;
221 __u32 driver_major_rev;
222};
223
224/**
Ledion Daja00f83c02023-10-04 17:01:52 +0200225 * struct ethosu_uapi_inference_create - Create inference request
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200226 * @ifm_count: Number of IFM file descriptors
227 * @ifm_fd: IFM buffer file descriptors
228 * @ofm_count: Number of OFM file descriptors
229 * @ofm_fd: OFM buffer file descriptors
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200230 */
231struct ethosu_uapi_inference_create {
Per Åstrandf7e407a2020-10-23 21:25:05 +0200232 __u32 ifm_count;
233 __u32 ifm_fd[ETHOSU_FD_MAX];
234 __u32 ofm_count;
235 __u32 ofm_fd[ETHOSU_FD_MAX];
236 struct ethosu_uapi_pmu_config pmu_config;
237};
238
239/**
240 * struct ethosu_uapi_result_status - Status of inference
241 * @status Status of run inference.
242 * @pmu_config Configured performance counters.
243 * @pmu_count Perfomance counters values, when status is
244 * ETHOSU_UAPI_STATUS_OK.
245 */
246struct ethosu_uapi_result_status {
Ledion Dajac2eaf262023-10-03 17:33:28 +0200247 __u32 status;
Per Åstrandf7e407a2020-10-23 21:25:05 +0200248 struct ethosu_uapi_pmu_config pmu_config;
249 struct ethosu_uapi_pmu_counts pmu_count;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200250};
251
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100252/**
Ledion Daja00f83c02023-10-04 17:01:52 +0200253 * struct ethosu_uapi_cancel_inference_status - Status of inference
254 * cancellation.
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100255 * @status OK if inference cancellation was performed, ERROR otherwise.
256 */
257struct ethosu_uapi_cancel_inference_status {
Ledion Dajac2eaf262023-10-03 17:33:28 +0200258 __u32 status;
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100259};
260
Per Åstrandc823bcf2021-01-12 13:11:13 +0100261#ifdef __cplusplus
262} /* namespace EthosU */
263#endif
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200264#endif