aboutsummaryrefslogtreecommitdiff
path: root/kernel/uapi/ethosu.h
blob: 8f870c9c4574ca2ad58e8aa117f4bb27ebdc22ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
 * (C) COPYRIGHT 2020 ARM Limited. All rights reserved.
 *
 * This program is free software and is provided to you under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation, and any use by you of this program is subject to the terms
 * of such GNU licence.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you can access it online at
 * http://www.gnu.org/licenses/gpl-2.0.html.
 *
 * SPDX-License-Identifier: GPL-2.0-only
 */

#ifndef ETHOSU_H
#define ETHOSU_H

/****************************************************************************
 * Includes
 ****************************************************************************/

#include <linux/ioctl.h>
#include <linux/types.h>

/****************************************************************************
 * Defines
 ****************************************************************************/

#define ETHOSU_IOCTL_BASE               0x01
#define ETHOSU_IO(nr)                   _IO(ETHOSU_IOCTL_BASE, nr)
#define ETHOSU_IOR(nr, type)            _IOR(ETHOSU_IOCTL_BASE, nr, type)
#define ETHOSU_IOW(nr, type)            _IOW(ETHOSU_IOCTL_BASE, nr, type)
#define ETHOSU_IOWR(nr, type)           _IOWR(ETHOSU_IOCTL_BASE, nr, type)

#define ETHOSU_IOCTL_PING               ETHOSU_IO(0x00)
#define ETHOSU_IOCTL_BUFFER_CREATE      ETHOSU_IOR(0x10, \
						   struct ethosu_uapi_buffer_create)
#define ETHOSU_IOCTL_BUFFER_SET         ETHOSU_IOR(0x11, \
						   struct ethosu_uapi_buffer)
#define ETHOSU_IOCTL_BUFFER_GET         ETHOSU_IOW(0x12, \
						   struct ethosu_uapi_buffer)
#define ETHOSU_IOCTL_NETWORK_CREATE     ETHOSU_IOR(0x20, \
						   struct ethosu_uapi_network_create)
#define ETHOSU_IOCTL_INFERENCE_CREATE   ETHOSU_IOR(0x30, \
						   struct ethosu_uapi_inference_create)
#define ETHOSU_IOCTL_INFERENCE_STATUS   ETHOSU_IOR(0x31, \
						   struct ethosu_uapi_result_status)

/* Maximum number of IFM/OFM file descriptors per network */
#define ETHOSU_FD_MAX                   16

/* Maximum number of PMUs available */
#define ETHOSU_PMU_EVENT_MAX             4

/****************************************************************************
 * Types
 ****************************************************************************/

/**
 * enum ethosu_uapi_status - Status
 */
enum ethosu_uapi_status {
	ETHOSU_UAPI_STATUS_OK,
	ETHOSU_UAPI_STATUS_ERROR
};

/**
 * struct ethosu_uapi_buffer_create - Create buffer request
 * @capacity:	Maximum capacity of the buffer
 */
struct ethosu_uapi_buffer_create {
	__u32 capacity;
};

/**
 * struct ethosu_uapi_buffer - Buffer descriptor
 * @offset:	Offset to where the data starts
 * @size:	Size of the data
 *
 * 'offset + size' must not exceed the capacity of the buffer.
 */
struct ethosu_uapi_buffer {
	__u32 offset;
	__u32 size;
};

/**
 * struct ethosu_uapi_network_create - Create network request
 * @fd:		Buffer file descriptor
 */
struct ethosu_uapi_network_create {
	__u32 fd;
};

/**
 * struct ethosu_uapi_pmu_config - Configure performance counters
 * @events:             Array of counters to configure, set to non-zero for
 *                      each counter to enable corresponding event.
 * @cycle_count:        Set to enable the cycle counter.
 */
struct ethosu_uapi_pmu_config {
	__u32 events[ETHOSU_PMU_EVENT_MAX];
	__u32 cycle_count;
};

/**
 * struct ethosu_uapi_pmu_counts - Status of performance counters
 * @events:             Count for respective configured events.
 * @cycle_count:        Count for cycle counter.
 */
struct ethosu_uapi_pmu_counts {
	__u32 events[ETHOSU_PMU_EVENT_MAX];
	__u64 cycle_count;
};

/**
 * struct ethosu_uapi_inference_create - Create network request
 * @ifm_count:		Number of IFM file descriptors
 * @ifm_fd:		IFM buffer file descriptors
 * @ofm_count:		Number of OFM file descriptors
 * @ofm_fd:		OFM buffer file descriptors
 */
struct ethosu_uapi_inference_create {
	__u32                         ifm_count;
	__u32                         ifm_fd[ETHOSU_FD_MAX];
	__u32                         ofm_count;
	__u32                         ofm_fd[ETHOSU_FD_MAX];
	struct ethosu_uapi_pmu_config pmu_config;
};

/**
 * struct ethosu_uapi_result_status - Status of inference
 * @status	Status of run inference.
 * @pmu_config	Configured performance counters.
 * @pmu_count	Perfomance counters values, when status is
 *              ETHOSU_UAPI_STATUS_OK.
 */
struct ethosu_uapi_result_status {
	enum ethosu_uapi_status       status;
	struct ethosu_uapi_pmu_config pmu_config;
	struct ethosu_uapi_pmu_counts pmu_count;
};

#endif