blob: 49e8da7574809fc553abc3976286bcd7d7b37c9a [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_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)
Jonny Svärd7c24c772021-01-14 19:53:17 +010046#define ETHOSU_IOCTL_VERSION_REQ ETHOSU_IO(0x01)
Per Åstrand7f9a4e32022-05-18 09:18:27 +020047#define ETHOSU_IOCTL_CAPABILITIES_REQ ETHOSU_IOR(0x02, \
48 struct ethosu_uapi_device_capabilities)
Kristofer Jonsson116a6352020-08-20 17:25:23 +020049#define ETHOSU_IOCTL_BUFFER_CREATE ETHOSU_IOR(0x10, \
50 struct ethosu_uapi_buffer_create)
51#define ETHOSU_IOCTL_BUFFER_SET ETHOSU_IOR(0x11, \
52 struct ethosu_uapi_buffer)
53#define ETHOSU_IOCTL_BUFFER_GET ETHOSU_IOW(0x12, \
54 struct ethosu_uapi_buffer)
55#define ETHOSU_IOCTL_NETWORK_CREATE ETHOSU_IOR(0x20, \
56 struct ethosu_uapi_network_create)
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +010057#define ETHOSU_IOCTL_NETWORK_INFO ETHOSU_IOR(0x21, \
58 struct ethosu_uapi_network_info)
Kristofer Jonsson116a6352020-08-20 17:25:23 +020059#define ETHOSU_IOCTL_INFERENCE_CREATE ETHOSU_IOR(0x30, \
60 struct ethosu_uapi_inference_create)
Per Åstrandf7e407a2020-10-23 21:25:05 +020061#define ETHOSU_IOCTL_INFERENCE_STATUS ETHOSU_IOR(0x31, \
62 struct ethosu_uapi_result_status)
Davide Grohmann7e8f5082022-03-23 12:48:45 +010063#define ETHOSU_IOCTL_INFERENCE_CANCEL ETHOSU_IOR(0x32, \
64 struct ethosu_uapi_cancel_inference_status)
Kristofer Jonsson116a6352020-08-20 17:25:23 +020065
Kristofer Jonssonb74492c2020-09-10 13:26:01 +020066/* Maximum number of IFM/OFM file descriptors per network */
67#define ETHOSU_FD_MAX 16
68
Per Åstrandf7e407a2020-10-23 21:25:05 +020069/* Maximum number of PMUs available */
Jonny Svärdb5aa9042021-12-17 17:08:10 +010070#define ETHOSU_PMU_EVENT_MAX 8
Per Åstrandf7e407a2020-10-23 21:25:05 +020071
Kristofer Jonsson116a6352020-08-20 17:25:23 +020072/****************************************************************************
73 * Types
74 ****************************************************************************/
75
76/**
77 * enum ethosu_uapi_status - Status
78 */
79enum ethosu_uapi_status {
80 ETHOSU_UAPI_STATUS_OK,
Davide Grohmann82d22582022-04-25 12:52:38 +020081 ETHOSU_UAPI_STATUS_ERROR,
82 ETHOSU_UAPI_STATUS_RUNNING,
83 ETHOSU_UAPI_STATUS_REJECTED,
Davide Grohmann7e8f5082022-03-23 12:48:45 +010084 ETHOSU_UAPI_STATUS_ABORTED,
85 ETHOSU_UAPI_STATUS_ABORTING,
Kristofer Jonsson116a6352020-08-20 17:25:23 +020086};
87
88/**
89 * struct ethosu_uapi_buffer_create - Create buffer request
90 * @capacity: Maximum capacity of the buffer
91 */
92struct ethosu_uapi_buffer_create {
93 __u32 capacity;
94};
95
96/**
97 * struct ethosu_uapi_buffer - Buffer descriptor
98 * @offset: Offset to where the data starts
99 * @size: Size of the data
100 *
101 * 'offset + size' must not exceed the capacity of the buffer.
102 */
103struct ethosu_uapi_buffer {
104 __u32 offset;
105 __u32 size;
106};
107
108/**
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100109 * enum ethosu_uapi_network_create - Network buffer type.
110 * @ETHOSU_UAPI_NETWORK_BUFFER: Network is stored in a buffer handle.
111 * @ETHOSU_UAPI_NETWORK_INDEX: Network is built into firmware and referenced by
112 * index.
113 */
114enum ethosu_uapi_network_type {
115 ETHOSU_UAPI_NETWORK_BUFFER = 1,
116 ETHOSU_UAPI_NETWORK_INDEX
117};
118
119/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200120 * struct ethosu_uapi_network_create - Create network request
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100121 * @type: Buffer type. See @ethosu_uapi_network_type.
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200122 * @fd: Buffer file descriptor
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100123 * @index: Buffer index compiled into firmware binary.
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200124 */
125struct ethosu_uapi_network_create {
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100126 uint32_t type;
127 union {
128 __u32 fd;
129 __u32 index;
130 };
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200131};
132
133/**
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100134 * struct ethosu_uapi_network_info - Network info
135 * @desc: Network description
136 * @ifm_count: Number of IFM buffers
137 * @ifm_size: IFM buffer sizes
138 * @ofm_count: Number of OFM buffers
139 * @ofm_size: OFM buffer sizes
140 */
141struct ethosu_uapi_network_info {
142 char desc[32];
143 __u32 ifm_count;
144 __u32 ifm_size[ETHOSU_FD_MAX];
145 __u32 ofm_count;
146 __u32 ofm_size[ETHOSU_FD_MAX];
147};
148
149/**
Per Åstrandf7e407a2020-10-23 21:25:05 +0200150 * struct ethosu_uapi_pmu_config - Configure performance counters
151 * @events: Array of counters to configure, set to non-zero for
152 * each counter to enable corresponding event.
153 * @cycle_count: Set to enable the cycle counter.
154 */
155struct ethosu_uapi_pmu_config {
156 __u32 events[ETHOSU_PMU_EVENT_MAX];
157 __u32 cycle_count;
158};
159
160/**
161 * struct ethosu_uapi_pmu_counts - Status of performance counters
162 * @events: Count for respective configured events.
163 * @cycle_count: Count for cycle counter.
164 */
165struct ethosu_uapi_pmu_counts {
166 __u32 events[ETHOSU_PMU_EVENT_MAX];
167 __u64 cycle_count;
168};
169
170/**
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200171 * struct ethosu_uapi_device_hw_id - Device hardware identification
172 * @version_status: Version status
173 * @version_minor: Version minor
174 * @version_major: Version major
175 * @product_major: Product major
176 * @arch_patch_rev: Architecture version patch
177 * @arch_minor_rev: Architecture version minor
178 * @arch_major_rev: Architecture version major
179 */
180struct ethosu_uapi_device_hw_id {
181 __u32 version_status;
182 __u32 version_minor;
183 __u32 version_major;
184 __u32 product_major;
185 __u32 arch_patch_rev;
186 __u32 arch_minor_rev;
187 __u32 arch_major_rev;
188};
189
190/**
191 * struct ethosu_uapi_device_hw_cfg - Device hardware configuration
192 * @macs_per_cc: MACs per clock cycle
193 * @cmd_stream_version: NPU command stream version
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200194 * @custom_dma: Custom DMA enabled
195 */
196struct ethosu_uapi_device_hw_cfg {
197 __u32 macs_per_cc;
198 __u32 cmd_stream_version;
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200199 __u32 custom_dma;
200};
201
202/**
Per Åstrand7f9a4e32022-05-18 09:18:27 +0200203 * struct ethosu_uapi_device_capabilities - Device capabilities
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200204 * @hw_id: Hardware identification
205 * @hw_cfg: Hardware configuration
206 * @driver_patch_rev: Driver version patch
207 * @driver_minor_rev: Driver version minor
208 * @driver_major_rev: Driver version major
209 */
210struct ethosu_uapi_device_capabilities {
211 struct ethosu_uapi_device_hw_id hw_id;
212 struct ethosu_uapi_device_hw_cfg hw_cfg;
213 __u32 driver_patch_rev;
214 __u32 driver_minor_rev;
215 __u32 driver_major_rev;
216};
217
218/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200219 * struct ethosu_uapi_inference_create - Create network request
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200220 * @ifm_count: Number of IFM file descriptors
221 * @ifm_fd: IFM buffer file descriptors
222 * @ofm_count: Number of OFM file descriptors
223 * @ofm_fd: OFM buffer file descriptors
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200224 */
225struct ethosu_uapi_inference_create {
Per Åstrandf7e407a2020-10-23 21:25:05 +0200226 __u32 ifm_count;
227 __u32 ifm_fd[ETHOSU_FD_MAX];
228 __u32 ofm_count;
229 __u32 ofm_fd[ETHOSU_FD_MAX];
230 struct ethosu_uapi_pmu_config pmu_config;
231};
232
233/**
234 * struct ethosu_uapi_result_status - Status of inference
235 * @status Status of run inference.
236 * @pmu_config Configured performance counters.
237 * @pmu_count Perfomance counters values, when status is
238 * ETHOSU_UAPI_STATUS_OK.
239 */
240struct ethosu_uapi_result_status {
241 enum ethosu_uapi_status status;
242 struct ethosu_uapi_pmu_config pmu_config;
243 struct ethosu_uapi_pmu_counts pmu_count;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200244};
245
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100246/**
247 * struct ethosu_uapi_cancel_status - Status of inference cancellation.
248 * @status OK if inference cancellation was performed, ERROR otherwise.
249 */
250struct ethosu_uapi_cancel_inference_status {
251 enum ethosu_uapi_status status;
252};
253
Per Åstrandc823bcf2021-01-12 13:11:13 +0100254#ifdef __cplusplus
255} /* namespace EthosU */
256#endif
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200257#endif