blob: 903316dff7b313593b61aa4207677d7103ad495b [file] [log] [blame]
Kristofer Jonsson116a6352020-08-20 17:25:23 +02001/*
2 * (C) COPYRIGHT 2020 ARM Limited. All rights reserved.
3 *
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)
56#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)
Kristofer Jonsson116a6352020-08-20 17:25:23 +020060
Kristofer Jonssonb74492c2020-09-10 13:26:01 +020061/* Maximum number of IFM/OFM file descriptors per network */
62#define ETHOSU_FD_MAX 16
63
Per Åstrandf7e407a2020-10-23 21:25:05 +020064/* Maximum number of PMUs available */
Jonny Svärdb5aa9042021-12-17 17:08:10 +010065#define ETHOSU_PMU_EVENT_MAX 8
Per Åstrandf7e407a2020-10-23 21:25:05 +020066
Kristofer Jonsson116a6352020-08-20 17:25:23 +020067/****************************************************************************
68 * Types
69 ****************************************************************************/
70
71/**
72 * enum ethosu_uapi_status - Status
73 */
74enum ethosu_uapi_status {
75 ETHOSU_UAPI_STATUS_OK,
76 ETHOSU_UAPI_STATUS_ERROR
77};
78
79/**
80 * struct ethosu_uapi_buffer_create - Create buffer request
81 * @capacity: Maximum capacity of the buffer
82 */
83struct ethosu_uapi_buffer_create {
84 __u32 capacity;
85};
86
87/**
88 * struct ethosu_uapi_buffer - Buffer descriptor
89 * @offset: Offset to where the data starts
90 * @size: Size of the data
91 *
92 * 'offset + size' must not exceed the capacity of the buffer.
93 */
94struct ethosu_uapi_buffer {
95 __u32 offset;
96 __u32 size;
97};
98
99/**
100 * struct ethosu_uapi_network_create - Create network request
101 * @fd: Buffer file descriptor
102 */
103struct ethosu_uapi_network_create {
104 __u32 fd;
105};
106
107/**
Per Åstrandf7e407a2020-10-23 21:25:05 +0200108 * struct ethosu_uapi_pmu_config - Configure performance counters
109 * @events: Array of counters to configure, set to non-zero for
110 * each counter to enable corresponding event.
111 * @cycle_count: Set to enable the cycle counter.
112 */
113struct ethosu_uapi_pmu_config {
114 __u32 events[ETHOSU_PMU_EVENT_MAX];
115 __u32 cycle_count;
116};
117
118/**
119 * struct ethosu_uapi_pmu_counts - Status of performance counters
120 * @events: Count for respective configured events.
121 * @cycle_count: Count for cycle counter.
122 */
123struct ethosu_uapi_pmu_counts {
124 __u32 events[ETHOSU_PMU_EVENT_MAX];
125 __u64 cycle_count;
126};
127
128/**
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200129 * struct ethosu_uapi_device_hw_id - Device hardware identification
130 * @version_status: Version status
131 * @version_minor: Version minor
132 * @version_major: Version major
133 * @product_major: Product major
134 * @arch_patch_rev: Architecture version patch
135 * @arch_minor_rev: Architecture version minor
136 * @arch_major_rev: Architecture version major
137 */
138struct ethosu_uapi_device_hw_id {
139 __u32 version_status;
140 __u32 version_minor;
141 __u32 version_major;
142 __u32 product_major;
143 __u32 arch_patch_rev;
144 __u32 arch_minor_rev;
145 __u32 arch_major_rev;
146};
147
148/**
149 * struct ethosu_uapi_device_hw_cfg - Device hardware configuration
150 * @macs_per_cc: MACs per clock cycle
151 * @cmd_stream_version: NPU command stream version
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200152 * @custom_dma: Custom DMA enabled
153 */
154struct ethosu_uapi_device_hw_cfg {
155 __u32 macs_per_cc;
156 __u32 cmd_stream_version;
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200157 __u32 custom_dma;
158};
159
160/**
161 * struct ethosu_uapi_capabilities - Device capabilities
162 * @hw_id: Hardware identification
163 * @hw_cfg: Hardware configuration
164 * @driver_patch_rev: Driver version patch
165 * @driver_minor_rev: Driver version minor
166 * @driver_major_rev: Driver version major
167 */
168struct ethosu_uapi_device_capabilities {
169 struct ethosu_uapi_device_hw_id hw_id;
170 struct ethosu_uapi_device_hw_cfg hw_cfg;
171 __u32 driver_patch_rev;
172 __u32 driver_minor_rev;
173 __u32 driver_major_rev;
174};
175
176/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200177 * struct ethosu_uapi_inference_create - Create network request
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200178 * @ifm_count: Number of IFM file descriptors
179 * @ifm_fd: IFM buffer file descriptors
180 * @ofm_count: Number of OFM file descriptors
181 * @ofm_fd: OFM buffer file descriptors
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200182 */
183struct ethosu_uapi_inference_create {
Per Åstrandf7e407a2020-10-23 21:25:05 +0200184 __u32 ifm_count;
185 __u32 ifm_fd[ETHOSU_FD_MAX];
186 __u32 ofm_count;
187 __u32 ofm_fd[ETHOSU_FD_MAX];
188 struct ethosu_uapi_pmu_config pmu_config;
189};
190
191/**
192 * struct ethosu_uapi_result_status - Status of inference
193 * @status Status of run inference.
194 * @pmu_config Configured performance counters.
195 * @pmu_count Perfomance counters values, when status is
196 * ETHOSU_UAPI_STATUS_OK.
197 */
198struct ethosu_uapi_result_status {
199 enum ethosu_uapi_status status;
200 struct ethosu_uapi_pmu_config pmu_config;
201 struct ethosu_uapi_pmu_counts pmu_count;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200202};
203
Per Åstrandc823bcf2021-01-12 13:11:13 +0100204#ifdef __cplusplus
205} /* namespace EthosU */
206#endif
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200207#endif