blob: 4311186b1058ff0afb219baf9fb178de79d0d48f [file] [log] [blame]
Kristofer Jonsson116a6352020-08-20 17:25:23 +02001/*
Mikael Olssond4ad9e52024-02-07 11:22:26 +01002 * SPDX-FileCopyrightText: Copyright 2020-2024 Arm Limited and/or its affiliates <open-source-office@arm.com>
Ledion Daja00f83c02023-10-04 17:01:52 +02003 * 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 Olssone43c8c22024-02-20 15:48:47 +010070#define ETHOSU_KERNEL_DRIVER_VERSION_MAJOR 4
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 {
Mikael Olssone87446c2023-12-15 17:17:06 +0100172 __u64 events[ETHOSU_PMU_EVENT_MAX];
Per Åstrandf7e407a2020-10-23 21:25:05 +0200173 __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/**
Mikael Olssone43c8c22024-02-20 15:48:47 +0100197 * enum ethosu_uapi_device_type - NPU device type
198 * @ETHOSU_UAPI_DEVICE_UNKNOWN: Unknown NPU device type
199 * @ETHOSU_UAPI_DEVICE_SUBSYSTEM: NPU managed by a subsystem communicated with
200 * via a mailbox
201 * @ETHOSU_UAPI_DEVICE_DIRECT: NPU directly managed by the kernel driver
Mikael Olssondc18cea2024-02-16 11:04:46 +0100202 */
Mikael Olssone43c8c22024-02-20 15:48:47 +0100203enum ethosu_uapi_device_type {
204 ETHOSU_UAPI_DEVICE_UNKNOWN = 0,
205 ETHOSU_UAPI_DEVICE_SUBSYSTEM,
206 ETHOSU_UAPI_DEVICE_DIRECT,
Mikael Olssondc18cea2024-02-16 11:04:46 +0100207};
208
209/**
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200210 * struct ethosu_uapi_device_hw_cfg - Device hardware configuration
211 * @macs_per_cc: MACs per clock cycle
212 * @cmd_stream_version: NPU command stream version
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200213 * @custom_dma: Custom DMA enabled
Mikael Olssondc18cea2024-02-16 11:04:46 +0100214 * @type: NPU device type
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200215 */
216struct ethosu_uapi_device_hw_cfg {
217 __u32 macs_per_cc;
218 __u32 cmd_stream_version;
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200219 __u32 custom_dma;
Mikael Olssondc18cea2024-02-16 11:04:46 +0100220 __u32 type;
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200221};
222
223/**
Per Åstrand7f9a4e32022-05-18 09:18:27 +0200224 * struct ethosu_uapi_device_capabilities - Device capabilities
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200225 * @hw_id: Hardware identification
226 * @hw_cfg: Hardware configuration
227 * @driver_patch_rev: Driver version patch
228 * @driver_minor_rev: Driver version minor
229 * @driver_major_rev: Driver version major
230 */
231struct ethosu_uapi_device_capabilities {
232 struct ethosu_uapi_device_hw_id hw_id;
233 struct ethosu_uapi_device_hw_cfg hw_cfg;
234 __u32 driver_patch_rev;
235 __u32 driver_minor_rev;
236 __u32 driver_major_rev;
237};
238
239/**
Ledion Daja00f83c02023-10-04 17:01:52 +0200240 * struct ethosu_uapi_inference_create - Create inference request
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200241 * @ifm_count: Number of IFM file descriptors
242 * @ifm_fd: IFM buffer file descriptors
243 * @ofm_count: Number of OFM file descriptors
244 * @ofm_fd: OFM buffer file descriptors
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200245 */
246struct ethosu_uapi_inference_create {
Per Åstrandf7e407a2020-10-23 21:25:05 +0200247 __u32 ifm_count;
248 __u32 ifm_fd[ETHOSU_FD_MAX];
249 __u32 ofm_count;
250 __u32 ofm_fd[ETHOSU_FD_MAX];
251 struct ethosu_uapi_pmu_config pmu_config;
252};
253
254/**
255 * struct ethosu_uapi_result_status - Status of inference
256 * @status Status of run inference.
257 * @pmu_config Configured performance counters.
258 * @pmu_count Perfomance counters values, when status is
259 * ETHOSU_UAPI_STATUS_OK.
260 */
261struct ethosu_uapi_result_status {
Ledion Dajac2eaf262023-10-03 17:33:28 +0200262 __u32 status;
Per Åstrandf7e407a2020-10-23 21:25:05 +0200263 struct ethosu_uapi_pmu_config pmu_config;
264 struct ethosu_uapi_pmu_counts pmu_count;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200265};
266
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100267/**
Ledion Daja00f83c02023-10-04 17:01:52 +0200268 * struct ethosu_uapi_cancel_inference_status - Status of inference
269 * cancellation.
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100270 * @status OK if inference cancellation was performed, ERROR otherwise.
271 */
272struct ethosu_uapi_cancel_inference_status {
Ledion Dajac2eaf262023-10-03 17:33:28 +0200273 __u32 status;
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100274};
275
Per Åstrandc823bcf2021-01-12 13:11:13 +0100276#ifdef __cplusplus
277} /* namespace EthosU */
278#endif
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200279#endif