blob: 4627cb97a2c4f7db1c94b1671035a53117830de3 [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)
Davide Grohmann35ce6c82021-06-01 15:03:51 +020047#define ETHOSU_IOCTL_CAPABILITIES_REQ ETHOSU_IO(0x02)
Kristofer Jonsson116a6352020-08-20 17:25:23 +020048#define ETHOSU_IOCTL_BUFFER_CREATE ETHOSU_IOR(0x10, \
49 struct ethosu_uapi_buffer_create)
50#define ETHOSU_IOCTL_BUFFER_SET ETHOSU_IOR(0x11, \
51 struct ethosu_uapi_buffer)
52#define ETHOSU_IOCTL_BUFFER_GET ETHOSU_IOW(0x12, \
53 struct ethosu_uapi_buffer)
54#define ETHOSU_IOCTL_NETWORK_CREATE ETHOSU_IOR(0x20, \
55 struct ethosu_uapi_network_create)
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +010056#define ETHOSU_IOCTL_NETWORK_INFO ETHOSU_IOR(0x21, \
57 struct ethosu_uapi_network_info)
Kristofer Jonsson116a6352020-08-20 17:25:23 +020058#define ETHOSU_IOCTL_INFERENCE_CREATE ETHOSU_IOR(0x30, \
59 struct ethosu_uapi_inference_create)
Per Åstrandf7e407a2020-10-23 21:25:05 +020060#define ETHOSU_IOCTL_INFERENCE_STATUS ETHOSU_IOR(0x31, \
61 struct ethosu_uapi_result_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
Kristofer Jonsson116a6352020-08-20 17:25:23 +020069/****************************************************************************
70 * Types
71 ****************************************************************************/
72
73/**
74 * enum ethosu_uapi_status - Status
75 */
76enum ethosu_uapi_status {
77 ETHOSU_UAPI_STATUS_OK,
Davide Grohmann82d22582022-04-25 12:52:38 +020078 ETHOSU_UAPI_STATUS_ERROR,
79 ETHOSU_UAPI_STATUS_RUNNING,
80 ETHOSU_UAPI_STATUS_REJECTED,
Kristofer Jonsson116a6352020-08-20 17:25:23 +020081};
82
83/**
84 * struct ethosu_uapi_buffer_create - Create buffer request
85 * @capacity: Maximum capacity of the buffer
86 */
87struct ethosu_uapi_buffer_create {
88 __u32 capacity;
89};
90
91/**
92 * struct ethosu_uapi_buffer - Buffer descriptor
93 * @offset: Offset to where the data starts
94 * @size: Size of the data
95 *
96 * 'offset + size' must not exceed the capacity of the buffer.
97 */
98struct ethosu_uapi_buffer {
99 __u32 offset;
100 __u32 size;
101};
102
103/**
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100104 * enum ethosu_uapi_network_create - Network buffer type.
105 * @ETHOSU_UAPI_NETWORK_BUFFER: Network is stored in a buffer handle.
106 * @ETHOSU_UAPI_NETWORK_INDEX: Network is built into firmware and referenced by
107 * index.
108 */
109enum ethosu_uapi_network_type {
110 ETHOSU_UAPI_NETWORK_BUFFER = 1,
111 ETHOSU_UAPI_NETWORK_INDEX
112};
113
114/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200115 * struct ethosu_uapi_network_create - Create network request
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100116 * @type: Buffer type. See @ethosu_uapi_network_type.
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200117 * @fd: Buffer file descriptor
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100118 * @index: Buffer index compiled into firmware binary.
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200119 */
120struct ethosu_uapi_network_create {
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100121 uint32_t type;
122 union {
123 __u32 fd;
124 __u32 index;
125 };
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200126};
127
128/**
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100129 * struct ethosu_uapi_network_info - Network info
130 * @desc: Network description
131 * @ifm_count: Number of IFM buffers
132 * @ifm_size: IFM buffer sizes
133 * @ofm_count: Number of OFM buffers
134 * @ofm_size: OFM buffer sizes
135 */
136struct ethosu_uapi_network_info {
137 char desc[32];
138 __u32 ifm_count;
139 __u32 ifm_size[ETHOSU_FD_MAX];
140 __u32 ofm_count;
141 __u32 ofm_size[ETHOSU_FD_MAX];
142};
143
144/**
Per Åstrandf7e407a2020-10-23 21:25:05 +0200145 * struct ethosu_uapi_pmu_config - Configure performance counters
146 * @events: Array of counters to configure, set to non-zero for
147 * each counter to enable corresponding event.
148 * @cycle_count: Set to enable the cycle counter.
149 */
150struct ethosu_uapi_pmu_config {
151 __u32 events[ETHOSU_PMU_EVENT_MAX];
152 __u32 cycle_count;
153};
154
155/**
156 * struct ethosu_uapi_pmu_counts - Status of performance counters
157 * @events: Count for respective configured events.
158 * @cycle_count: Count for cycle counter.
159 */
160struct ethosu_uapi_pmu_counts {
161 __u32 events[ETHOSU_PMU_EVENT_MAX];
162 __u64 cycle_count;
163};
164
165/**
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200166 * struct ethosu_uapi_device_hw_id - Device hardware identification
167 * @version_status: Version status
168 * @version_minor: Version minor
169 * @version_major: Version major
170 * @product_major: Product major
171 * @arch_patch_rev: Architecture version patch
172 * @arch_minor_rev: Architecture version minor
173 * @arch_major_rev: Architecture version major
174 */
175struct ethosu_uapi_device_hw_id {
176 __u32 version_status;
177 __u32 version_minor;
178 __u32 version_major;
179 __u32 product_major;
180 __u32 arch_patch_rev;
181 __u32 arch_minor_rev;
182 __u32 arch_major_rev;
183};
184
185/**
186 * struct ethosu_uapi_device_hw_cfg - Device hardware configuration
187 * @macs_per_cc: MACs per clock cycle
188 * @cmd_stream_version: NPU command stream version
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200189 * @custom_dma: Custom DMA enabled
190 */
191struct ethosu_uapi_device_hw_cfg {
192 __u32 macs_per_cc;
193 __u32 cmd_stream_version;
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200194 __u32 custom_dma;
195};
196
197/**
198 * struct ethosu_uapi_capabilities - Device capabilities
199 * @hw_id: Hardware identification
200 * @hw_cfg: Hardware configuration
201 * @driver_patch_rev: Driver version patch
202 * @driver_minor_rev: Driver version minor
203 * @driver_major_rev: Driver version major
204 */
205struct ethosu_uapi_device_capabilities {
206 struct ethosu_uapi_device_hw_id hw_id;
207 struct ethosu_uapi_device_hw_cfg hw_cfg;
208 __u32 driver_patch_rev;
209 __u32 driver_minor_rev;
210 __u32 driver_major_rev;
211};
212
213/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200214 * struct ethosu_uapi_inference_create - Create network request
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200215 * @ifm_count: Number of IFM file descriptors
216 * @ifm_fd: IFM buffer file descriptors
217 * @ofm_count: Number of OFM file descriptors
218 * @ofm_fd: OFM buffer file descriptors
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200219 */
220struct ethosu_uapi_inference_create {
Per Åstrandf7e407a2020-10-23 21:25:05 +0200221 __u32 ifm_count;
222 __u32 ifm_fd[ETHOSU_FD_MAX];
223 __u32 ofm_count;
224 __u32 ofm_fd[ETHOSU_FD_MAX];
225 struct ethosu_uapi_pmu_config pmu_config;
226};
227
228/**
229 * struct ethosu_uapi_result_status - Status of inference
230 * @status Status of run inference.
231 * @pmu_config Configured performance counters.
232 * @pmu_count Perfomance counters values, when status is
233 * ETHOSU_UAPI_STATUS_OK.
234 */
235struct ethosu_uapi_result_status {
236 enum ethosu_uapi_status status;
237 struct ethosu_uapi_pmu_config pmu_config;
238 struct ethosu_uapi_pmu_counts pmu_count;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200239};
240
Per Åstrandc823bcf2021-01-12 13:11:13 +0100241#ifdef __cplusplus
242} /* namespace EthosU */
243#endif
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200244#endif