blob: 1e53c917d6135b949c490884ceeca8800520492e [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)
Kristofer Jonsson116a6352020-08-20 17:25:23 +020047#define ETHOSU_IOCTL_BUFFER_CREATE ETHOSU_IOR(0x10, \
48 struct ethosu_uapi_buffer_create)
49#define ETHOSU_IOCTL_BUFFER_SET ETHOSU_IOR(0x11, \
50 struct ethosu_uapi_buffer)
51#define ETHOSU_IOCTL_BUFFER_GET ETHOSU_IOW(0x12, \
52 struct ethosu_uapi_buffer)
53#define ETHOSU_IOCTL_NETWORK_CREATE ETHOSU_IOR(0x20, \
54 struct ethosu_uapi_network_create)
55#define ETHOSU_IOCTL_INFERENCE_CREATE ETHOSU_IOR(0x30, \
56 struct ethosu_uapi_inference_create)
Per Åstrandf7e407a2020-10-23 21:25:05 +020057#define ETHOSU_IOCTL_INFERENCE_STATUS ETHOSU_IOR(0x31, \
58 struct ethosu_uapi_result_status)
Kristofer Jonsson116a6352020-08-20 17:25:23 +020059
Kristofer Jonssonb74492c2020-09-10 13:26:01 +020060/* Maximum number of IFM/OFM file descriptors per network */
61#define ETHOSU_FD_MAX 16
62
Per Åstrandf7e407a2020-10-23 21:25:05 +020063/* Maximum number of PMUs available */
64#define ETHOSU_PMU_EVENT_MAX 4
65
Kristofer Jonsson116a6352020-08-20 17:25:23 +020066/****************************************************************************
67 * Types
68 ****************************************************************************/
69
70/**
71 * enum ethosu_uapi_status - Status
72 */
73enum ethosu_uapi_status {
74 ETHOSU_UAPI_STATUS_OK,
75 ETHOSU_UAPI_STATUS_ERROR
76};
77
78/**
79 * struct ethosu_uapi_buffer_create - Create buffer request
80 * @capacity: Maximum capacity of the buffer
81 */
82struct ethosu_uapi_buffer_create {
83 __u32 capacity;
84};
85
86/**
87 * struct ethosu_uapi_buffer - Buffer descriptor
88 * @offset: Offset to where the data starts
89 * @size: Size of the data
90 *
91 * 'offset + size' must not exceed the capacity of the buffer.
92 */
93struct ethosu_uapi_buffer {
94 __u32 offset;
95 __u32 size;
96};
97
98/**
99 * struct ethosu_uapi_network_create - Create network request
100 * @fd: Buffer file descriptor
101 */
102struct ethosu_uapi_network_create {
103 __u32 fd;
104};
105
106/**
Per Åstrandf7e407a2020-10-23 21:25:05 +0200107 * struct ethosu_uapi_pmu_config - Configure performance counters
108 * @events: Array of counters to configure, set to non-zero for
109 * each counter to enable corresponding event.
110 * @cycle_count: Set to enable the cycle counter.
111 */
112struct ethosu_uapi_pmu_config {
113 __u32 events[ETHOSU_PMU_EVENT_MAX];
114 __u32 cycle_count;
115};
116
117/**
118 * struct ethosu_uapi_pmu_counts - Status of performance counters
119 * @events: Count for respective configured events.
120 * @cycle_count: Count for cycle counter.
121 */
122struct ethosu_uapi_pmu_counts {
123 __u32 events[ETHOSU_PMU_EVENT_MAX];
124 __u64 cycle_count;
125};
126
127/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200128 * struct ethosu_uapi_inference_create - Create network request
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200129 * @ifm_count: Number of IFM file descriptors
130 * @ifm_fd: IFM buffer file descriptors
131 * @ofm_count: Number of OFM file descriptors
132 * @ofm_fd: OFM buffer file descriptors
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200133 */
134struct ethosu_uapi_inference_create {
Per Åstrandf7e407a2020-10-23 21:25:05 +0200135 __u32 ifm_count;
136 __u32 ifm_fd[ETHOSU_FD_MAX];
137 __u32 ofm_count;
138 __u32 ofm_fd[ETHOSU_FD_MAX];
139 struct ethosu_uapi_pmu_config pmu_config;
140};
141
142/**
143 * struct ethosu_uapi_result_status - Status of inference
144 * @status Status of run inference.
145 * @pmu_config Configured performance counters.
146 * @pmu_count Perfomance counters values, when status is
147 * ETHOSU_UAPI_STATUS_OK.
148 */
149struct ethosu_uapi_result_status {
150 enum ethosu_uapi_status status;
151 struct ethosu_uapi_pmu_config pmu_config;
152 struct ethosu_uapi_pmu_counts pmu_count;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200153};
154
Per Åstrandc823bcf2021-01-12 13:11:13 +0100155#ifdef __cplusplus
156} /* namespace EthosU */
157#endif
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200158#endif