blob: 012703399eebe4ea5d9f8ebcb52f0dc43ca3f09f [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
31/****************************************************************************
32 * Defines
33 ****************************************************************************/
34
35#define ETHOSU_IOCTL_BASE 0x01
36#define ETHOSU_IO(nr) _IO(ETHOSU_IOCTL_BASE, nr)
37#define ETHOSU_IOR(nr, type) _IOR(ETHOSU_IOCTL_BASE, nr, type)
38#define ETHOSU_IOW(nr, type) _IOW(ETHOSU_IOCTL_BASE, nr, type)
39#define ETHOSU_IOWR(nr, type) _IOWR(ETHOSU_IOCTL_BASE, nr, type)
40
41#define ETHOSU_IOCTL_PING ETHOSU_IO(0x00)
Jonny Svärd7c24c772021-01-14 19:53:17 +010042#define ETHOSU_IOCTL_VERSION_REQ ETHOSU_IO(0x01)
Kristofer Jonsson116a6352020-08-20 17:25:23 +020043#define ETHOSU_IOCTL_BUFFER_CREATE ETHOSU_IOR(0x10, \
44 struct ethosu_uapi_buffer_create)
45#define ETHOSU_IOCTL_BUFFER_SET ETHOSU_IOR(0x11, \
46 struct ethosu_uapi_buffer)
47#define ETHOSU_IOCTL_BUFFER_GET ETHOSU_IOW(0x12, \
48 struct ethosu_uapi_buffer)
49#define ETHOSU_IOCTL_NETWORK_CREATE ETHOSU_IOR(0x20, \
50 struct ethosu_uapi_network_create)
51#define ETHOSU_IOCTL_INFERENCE_CREATE ETHOSU_IOR(0x30, \
52 struct ethosu_uapi_inference_create)
Per Åstrandf7e407a2020-10-23 21:25:05 +020053#define ETHOSU_IOCTL_INFERENCE_STATUS ETHOSU_IOR(0x31, \
54 struct ethosu_uapi_result_status)
Kristofer Jonsson116a6352020-08-20 17:25:23 +020055
Kristofer Jonssonb74492c2020-09-10 13:26:01 +020056/* Maximum number of IFM/OFM file descriptors per network */
57#define ETHOSU_FD_MAX 16
58
Per Åstrandf7e407a2020-10-23 21:25:05 +020059/* Maximum number of PMUs available */
60#define ETHOSU_PMU_EVENT_MAX 4
61
Kristofer Jonsson116a6352020-08-20 17:25:23 +020062/****************************************************************************
63 * Types
64 ****************************************************************************/
65
66/**
67 * enum ethosu_uapi_status - Status
68 */
69enum ethosu_uapi_status {
70 ETHOSU_UAPI_STATUS_OK,
71 ETHOSU_UAPI_STATUS_ERROR
72};
73
74/**
75 * struct ethosu_uapi_buffer_create - Create buffer request
76 * @capacity: Maximum capacity of the buffer
77 */
78struct ethosu_uapi_buffer_create {
79 __u32 capacity;
80};
81
82/**
83 * struct ethosu_uapi_buffer - Buffer descriptor
84 * @offset: Offset to where the data starts
85 * @size: Size of the data
86 *
87 * 'offset + size' must not exceed the capacity of the buffer.
88 */
89struct ethosu_uapi_buffer {
90 __u32 offset;
91 __u32 size;
92};
93
94/**
95 * struct ethosu_uapi_network_create - Create network request
96 * @fd: Buffer file descriptor
97 */
98struct ethosu_uapi_network_create {
99 __u32 fd;
100};
101
102/**
Per Åstrandf7e407a2020-10-23 21:25:05 +0200103 * struct ethosu_uapi_pmu_config - Configure performance counters
104 * @events: Array of counters to configure, set to non-zero for
105 * each counter to enable corresponding event.
106 * @cycle_count: Set to enable the cycle counter.
107 */
108struct ethosu_uapi_pmu_config {
109 __u32 events[ETHOSU_PMU_EVENT_MAX];
110 __u32 cycle_count;
111};
112
113/**
114 * struct ethosu_uapi_pmu_counts - Status of performance counters
115 * @events: Count for respective configured events.
116 * @cycle_count: Count for cycle counter.
117 */
118struct ethosu_uapi_pmu_counts {
119 __u32 events[ETHOSU_PMU_EVENT_MAX];
120 __u64 cycle_count;
121};
122
123/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200124 * struct ethosu_uapi_inference_create - Create network request
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200125 * @ifm_count: Number of IFM file descriptors
126 * @ifm_fd: IFM buffer file descriptors
127 * @ofm_count: Number of OFM file descriptors
128 * @ofm_fd: OFM buffer file descriptors
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200129 */
130struct ethosu_uapi_inference_create {
Per Åstrandf7e407a2020-10-23 21:25:05 +0200131 __u32 ifm_count;
132 __u32 ifm_fd[ETHOSU_FD_MAX];
133 __u32 ofm_count;
134 __u32 ofm_fd[ETHOSU_FD_MAX];
135 struct ethosu_uapi_pmu_config pmu_config;
136};
137
138/**
139 * struct ethosu_uapi_result_status - Status of inference
140 * @status Status of run inference.
141 * @pmu_config Configured performance counters.
142 * @pmu_count Perfomance counters values, when status is
143 * ETHOSU_UAPI_STATUS_OK.
144 */
145struct ethosu_uapi_result_status {
146 enum ethosu_uapi_status status;
147 struct ethosu_uapi_pmu_config pmu_config;
148 struct ethosu_uapi_pmu_counts pmu_count;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200149};
150
151#endif