blob: 8f870c9c4574ca2ad58e8aa117f4bb27ebdc22ca [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)
42#define ETHOSU_IOCTL_BUFFER_CREATE ETHOSU_IOR(0x10, \
43 struct ethosu_uapi_buffer_create)
44#define ETHOSU_IOCTL_BUFFER_SET ETHOSU_IOR(0x11, \
45 struct ethosu_uapi_buffer)
46#define ETHOSU_IOCTL_BUFFER_GET ETHOSU_IOW(0x12, \
47 struct ethosu_uapi_buffer)
48#define ETHOSU_IOCTL_NETWORK_CREATE ETHOSU_IOR(0x20, \
49 struct ethosu_uapi_network_create)
50#define ETHOSU_IOCTL_INFERENCE_CREATE ETHOSU_IOR(0x30, \
51 struct ethosu_uapi_inference_create)
Per Åstrandf7e407a2020-10-23 21:25:05 +020052#define ETHOSU_IOCTL_INFERENCE_STATUS ETHOSU_IOR(0x31, \
53 struct ethosu_uapi_result_status)
Kristofer Jonsson116a6352020-08-20 17:25:23 +020054
Kristofer Jonssonb74492c2020-09-10 13:26:01 +020055/* Maximum number of IFM/OFM file descriptors per network */
56#define ETHOSU_FD_MAX 16
57
Per Åstrandf7e407a2020-10-23 21:25:05 +020058/* Maximum number of PMUs available */
59#define ETHOSU_PMU_EVENT_MAX 4
60
Kristofer Jonsson116a6352020-08-20 17:25:23 +020061/****************************************************************************
62 * Types
63 ****************************************************************************/
64
65/**
66 * enum ethosu_uapi_status - Status
67 */
68enum ethosu_uapi_status {
69 ETHOSU_UAPI_STATUS_OK,
70 ETHOSU_UAPI_STATUS_ERROR
71};
72
73/**
74 * struct ethosu_uapi_buffer_create - Create buffer request
75 * @capacity: Maximum capacity of the buffer
76 */
77struct ethosu_uapi_buffer_create {
78 __u32 capacity;
79};
80
81/**
82 * struct ethosu_uapi_buffer - Buffer descriptor
83 * @offset: Offset to where the data starts
84 * @size: Size of the data
85 *
86 * 'offset + size' must not exceed the capacity of the buffer.
87 */
88struct ethosu_uapi_buffer {
89 __u32 offset;
90 __u32 size;
91};
92
93/**
94 * struct ethosu_uapi_network_create - Create network request
95 * @fd: Buffer file descriptor
96 */
97struct ethosu_uapi_network_create {
98 __u32 fd;
99};
100
101/**
Per Åstrandf7e407a2020-10-23 21:25:05 +0200102 * struct ethosu_uapi_pmu_config - Configure performance counters
103 * @events: Array of counters to configure, set to non-zero for
104 * each counter to enable corresponding event.
105 * @cycle_count: Set to enable the cycle counter.
106 */
107struct ethosu_uapi_pmu_config {
108 __u32 events[ETHOSU_PMU_EVENT_MAX];
109 __u32 cycle_count;
110};
111
112/**
113 * struct ethosu_uapi_pmu_counts - Status of performance counters
114 * @events: Count for respective configured events.
115 * @cycle_count: Count for cycle counter.
116 */
117struct ethosu_uapi_pmu_counts {
118 __u32 events[ETHOSU_PMU_EVENT_MAX];
119 __u64 cycle_count;
120};
121
122/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200123 * struct ethosu_uapi_inference_create - Create network request
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200124 * @ifm_count: Number of IFM file descriptors
125 * @ifm_fd: IFM buffer file descriptors
126 * @ofm_count: Number of OFM file descriptors
127 * @ofm_fd: OFM buffer file descriptors
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200128 */
129struct ethosu_uapi_inference_create {
Per Åstrandf7e407a2020-10-23 21:25:05 +0200130 __u32 ifm_count;
131 __u32 ifm_fd[ETHOSU_FD_MAX];
132 __u32 ofm_count;
133 __u32 ofm_fd[ETHOSU_FD_MAX];
134 struct ethosu_uapi_pmu_config pmu_config;
135};
136
137/**
138 * struct ethosu_uapi_result_status - Status of inference
139 * @status Status of run inference.
140 * @pmu_config Configured performance counters.
141 * @pmu_count Perfomance counters values, when status is
142 * ETHOSU_UAPI_STATUS_OK.
143 */
144struct ethosu_uapi_result_status {
145 enum ethosu_uapi_status status;
146 struct ethosu_uapi_pmu_config pmu_config;
147 struct ethosu_uapi_pmu_counts pmu_count;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200148};
149
150#endif