Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 1 | /* |
Ledion Daja | 00f83c0 | 2023-10-04 17:01:52 +0200 | [diff] [blame] | 2 | * SPDX-FileCopyrightText: Copyright 2020-2023 Arm Limited and/or its affiliates <open-source-office@arm.com> |
| 3 | * SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 4 | * |
| 5 | * This program is free software and is provided to you under the terms of the |
| 6 | * GNU General Public License version 2 as published by the Free Software |
| 7 | * Foundation, and any use by you of this program is subject to the terms |
| 8 | * of such GNU licence. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, you can access it online at |
| 17 | * http://www.gnu.org/licenses/gpl-2.0.html. |
| 18 | * |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 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 Åstrand | c823bcf | 2021-01-12 13:11:13 +0100 | [diff] [blame] | 31 | #ifdef __cplusplus |
| 32 | namespace EthosU { |
| 33 | #endif |
| 34 | |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 35 | /**************************************************************************** |
| 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) |
Per Åstrand | 7f9a4e3 | 2022-05-18 09:18:27 +0200 | [diff] [blame] | 46 | #define ETHOSU_IOCTL_CAPABILITIES_REQ ETHOSU_IOR(0x02, \ |
| 47 | struct ethosu_uapi_device_capabilities) |
Mikael Olsson | f1cfe19 | 2023-06-12 15:00:41 +0200 | [diff] [blame] | 48 | #define ETHOSU_IOCTL_DRIVER_VERSION_GET ETHOSU_IOR(0x03, \ |
| 49 | struct ethosu_uapi_kernel_driver_version) |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 50 | #define ETHOSU_IOCTL_BUFFER_CREATE ETHOSU_IOR(0x10, \ |
| 51 | struct ethosu_uapi_buffer_create) |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 52 | #define ETHOSU_IOCTL_NETWORK_CREATE ETHOSU_IOR(0x20, \ |
| 53 | struct ethosu_uapi_network_create) |
Kristofer Jonsson | 3c6a260 | 2022-03-10 11:17:29 +0100 | [diff] [blame] | 54 | #define ETHOSU_IOCTL_NETWORK_INFO ETHOSU_IOR(0x21, \ |
| 55 | struct ethosu_uapi_network_info) |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 56 | #define ETHOSU_IOCTL_INFERENCE_CREATE ETHOSU_IOR(0x30, \ |
| 57 | struct ethosu_uapi_inference_create) |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 58 | #define ETHOSU_IOCTL_INFERENCE_STATUS ETHOSU_IOR(0x31, \ |
| 59 | struct ethosu_uapi_result_status) |
Davide Grohmann | 7e8f508 | 2022-03-23 12:48:45 +0100 | [diff] [blame] | 60 | #define ETHOSU_IOCTL_INFERENCE_CANCEL ETHOSU_IOR(0x32, \ |
| 61 | struct ethosu_uapi_cancel_inference_status) |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 62 | |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 63 | /* Maximum number of IFM/OFM file descriptors per network */ |
| 64 | #define ETHOSU_FD_MAX 16 |
| 65 | |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 66 | /* Maximum number of PMUs available */ |
Jonny Svärd | b5aa904 | 2021-12-17 17:08:10 +0100 | [diff] [blame] | 67 | #define ETHOSU_PMU_EVENT_MAX 8 |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 68 | |
Mikael Olsson | f1cfe19 | 2023-06-12 15:00:41 +0200 | [diff] [blame] | 69 | /* Kernel driver version */ |
Mikael Olsson | 0754515 | 2023-10-17 13:05:38 +0200 | [diff] [blame^] | 70 | #define ETHOSU_KERNEL_DRIVER_VERSION_MAJOR 2 |
Mikael Olsson | f1cfe19 | 2023-06-12 15:00:41 +0200 | [diff] [blame] | 71 | #define ETHOSU_KERNEL_DRIVER_VERSION_MINOR 0 |
| 72 | #define ETHOSU_KERNEL_DRIVER_VERSION_PATCH 0 |
| 73 | |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 74 | /**************************************************************************** |
| 75 | * Types |
| 76 | ****************************************************************************/ |
| 77 | |
| 78 | /** |
| 79 | * enum ethosu_uapi_status - Status |
| 80 | */ |
| 81 | enum ethosu_uapi_status { |
| 82 | ETHOSU_UAPI_STATUS_OK, |
Davide Grohmann | 82d2258 | 2022-04-25 12:52:38 +0200 | [diff] [blame] | 83 | ETHOSU_UAPI_STATUS_ERROR, |
| 84 | ETHOSU_UAPI_STATUS_RUNNING, |
| 85 | ETHOSU_UAPI_STATUS_REJECTED, |
Davide Grohmann | 7e8f508 | 2022-03-23 12:48:45 +0100 | [diff] [blame] | 86 | ETHOSU_UAPI_STATUS_ABORTED, |
| 87 | ETHOSU_UAPI_STATUS_ABORTING, |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | /** |
Mikael Olsson | f1cfe19 | 2023-06-12 15:00:41 +0200 | [diff] [blame] | 91 | * struct ethosu_uapi_kernel_driver_version - Kernel driver version |
| 92 | * @major: Major version |
| 93 | * @minor: Minor version |
| 94 | * @patch: Patch version |
| 95 | */ |
| 96 | struct ethosu_uapi_kernel_driver_version { |
| 97 | __u32 major; |
| 98 | __u32 minor; |
| 99 | __u32 patch; |
| 100 | }; |
| 101 | |
| 102 | /** |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 103 | * struct ethosu_uapi_buffer_create - Create buffer request |
Mikael Olsson | 0754515 | 2023-10-17 13:05:38 +0200 | [diff] [blame^] | 104 | * @size: Size of the requested buffer |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 105 | */ |
| 106 | struct ethosu_uapi_buffer_create { |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 107 | __u32 size; |
| 108 | }; |
| 109 | |
| 110 | /** |
Ledion Daja | 00f83c0 | 2023-10-04 17:01:52 +0200 | [diff] [blame] | 111 | * enum ethosu_uapi_network_type - Network buffer type. |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 112 | * @ETHOSU_UAPI_NETWORK_BUFFER: Network is stored in a buffer handle. |
| 113 | * @ETHOSU_UAPI_NETWORK_INDEX: Network is built into firmware and referenced by |
| 114 | * index. |
| 115 | */ |
| 116 | enum ethosu_uapi_network_type { |
| 117 | ETHOSU_UAPI_NETWORK_BUFFER = 1, |
| 118 | ETHOSU_UAPI_NETWORK_INDEX |
| 119 | }; |
| 120 | |
| 121 | /** |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 122 | * struct ethosu_uapi_network_create - Create network request |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 123 | * @type: Buffer type. See @ethosu_uapi_network_type. |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 124 | * @fd: Buffer file descriptor |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 125 | * @index: Buffer index compiled into firmware binary. |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 126 | */ |
| 127 | struct ethosu_uapi_network_create { |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 128 | uint32_t type; |
| 129 | union { |
| 130 | __u32 fd; |
| 131 | __u32 index; |
| 132 | }; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | /** |
Kristofer Jonsson | 3c6a260 | 2022-03-10 11:17:29 +0100 | [diff] [blame] | 136 | * struct ethosu_uapi_network_info - Network info |
| 137 | * @desc: Network description |
| 138 | * @ifm_count: Number of IFM buffers |
| 139 | * @ifm_size: IFM buffer sizes |
| 140 | * @ofm_count: Number of OFM buffers |
| 141 | * @ofm_size: OFM buffer sizes |
| 142 | */ |
| 143 | struct ethosu_uapi_network_info { |
| 144 | char desc[32]; |
| 145 | __u32 ifm_count; |
| 146 | __u32 ifm_size[ETHOSU_FD_MAX]; |
| 147 | __u32 ofm_count; |
| 148 | __u32 ofm_size[ETHOSU_FD_MAX]; |
| 149 | }; |
| 150 | |
| 151 | /** |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 152 | * struct ethosu_uapi_pmu_config - Configure performance counters |
| 153 | * @events: Array of counters to configure, set to non-zero for |
| 154 | * each counter to enable corresponding event. |
| 155 | * @cycle_count: Set to enable the cycle counter. |
| 156 | */ |
| 157 | struct ethosu_uapi_pmu_config { |
| 158 | __u32 events[ETHOSU_PMU_EVENT_MAX]; |
| 159 | __u32 cycle_count; |
| 160 | }; |
| 161 | |
| 162 | /** |
| 163 | * struct ethosu_uapi_pmu_counts - Status of performance counters |
| 164 | * @events: Count for respective configured events. |
| 165 | * @cycle_count: Count for cycle counter. |
| 166 | */ |
| 167 | struct ethosu_uapi_pmu_counts { |
| 168 | __u32 events[ETHOSU_PMU_EVENT_MAX]; |
| 169 | __u64 cycle_count; |
| 170 | }; |
| 171 | |
| 172 | /** |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 173 | * struct ethosu_uapi_device_hw_id - Device hardware identification |
| 174 | * @version_status: Version status |
| 175 | * @version_minor: Version minor |
| 176 | * @version_major: Version major |
| 177 | * @product_major: Product major |
| 178 | * @arch_patch_rev: Architecture version patch |
| 179 | * @arch_minor_rev: Architecture version minor |
| 180 | * @arch_major_rev: Architecture version major |
| 181 | */ |
| 182 | struct ethosu_uapi_device_hw_id { |
| 183 | __u32 version_status; |
| 184 | __u32 version_minor; |
| 185 | __u32 version_major; |
| 186 | __u32 product_major; |
| 187 | __u32 arch_patch_rev; |
| 188 | __u32 arch_minor_rev; |
| 189 | __u32 arch_major_rev; |
| 190 | }; |
| 191 | |
| 192 | /** |
| 193 | * struct ethosu_uapi_device_hw_cfg - Device hardware configuration |
| 194 | * @macs_per_cc: MACs per clock cycle |
| 195 | * @cmd_stream_version: NPU command stream version |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 196 | * @custom_dma: Custom DMA enabled |
| 197 | */ |
| 198 | struct ethosu_uapi_device_hw_cfg { |
| 199 | __u32 macs_per_cc; |
| 200 | __u32 cmd_stream_version; |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 201 | __u32 custom_dma; |
| 202 | }; |
| 203 | |
| 204 | /** |
Per Åstrand | 7f9a4e3 | 2022-05-18 09:18:27 +0200 | [diff] [blame] | 205 | * struct ethosu_uapi_device_capabilities - Device capabilities |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 206 | * @hw_id: Hardware identification |
| 207 | * @hw_cfg: Hardware configuration |
| 208 | * @driver_patch_rev: Driver version patch |
| 209 | * @driver_minor_rev: Driver version minor |
| 210 | * @driver_major_rev: Driver version major |
| 211 | */ |
| 212 | struct ethosu_uapi_device_capabilities { |
| 213 | struct ethosu_uapi_device_hw_id hw_id; |
| 214 | struct ethosu_uapi_device_hw_cfg hw_cfg; |
| 215 | __u32 driver_patch_rev; |
| 216 | __u32 driver_minor_rev; |
| 217 | __u32 driver_major_rev; |
| 218 | }; |
| 219 | |
| 220 | /** |
Ledion Daja | 00f83c0 | 2023-10-04 17:01:52 +0200 | [diff] [blame] | 221 | * struct ethosu_uapi_inference_create - Create inference request |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 222 | * @ifm_count: Number of IFM file descriptors |
| 223 | * @ifm_fd: IFM buffer file descriptors |
| 224 | * @ofm_count: Number of OFM file descriptors |
| 225 | * @ofm_fd: OFM buffer file descriptors |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 226 | */ |
| 227 | struct ethosu_uapi_inference_create { |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 228 | __u32 ifm_count; |
| 229 | __u32 ifm_fd[ETHOSU_FD_MAX]; |
| 230 | __u32 ofm_count; |
| 231 | __u32 ofm_fd[ETHOSU_FD_MAX]; |
| 232 | struct ethosu_uapi_pmu_config pmu_config; |
| 233 | }; |
| 234 | |
| 235 | /** |
| 236 | * struct ethosu_uapi_result_status - Status of inference |
| 237 | * @status Status of run inference. |
| 238 | * @pmu_config Configured performance counters. |
| 239 | * @pmu_count Perfomance counters values, when status is |
| 240 | * ETHOSU_UAPI_STATUS_OK. |
| 241 | */ |
| 242 | struct ethosu_uapi_result_status { |
Ledion Daja | c2eaf26 | 2023-10-03 17:33:28 +0200 | [diff] [blame] | 243 | __u32 status; |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 244 | struct ethosu_uapi_pmu_config pmu_config; |
| 245 | struct ethosu_uapi_pmu_counts pmu_count; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 246 | }; |
| 247 | |
Davide Grohmann | 7e8f508 | 2022-03-23 12:48:45 +0100 | [diff] [blame] | 248 | /** |
Ledion Daja | 00f83c0 | 2023-10-04 17:01:52 +0200 | [diff] [blame] | 249 | * struct ethosu_uapi_cancel_inference_status - Status of inference |
| 250 | * cancellation. |
Davide Grohmann | 7e8f508 | 2022-03-23 12:48:45 +0100 | [diff] [blame] | 251 | * @status OK if inference cancellation was performed, ERROR otherwise. |
| 252 | */ |
| 253 | struct ethosu_uapi_cancel_inference_status { |
Ledion Daja | c2eaf26 | 2023-10-03 17:33:28 +0200 | [diff] [blame] | 254 | __u32 status; |
Davide Grohmann | 7e8f508 | 2022-03-23 12:48:45 +0100 | [diff] [blame] | 255 | }; |
| 256 | |
Per Åstrand | c823bcf | 2021-01-12 13:11:13 +0100 | [diff] [blame] | 257 | #ifdef __cplusplus |
| 258 | } /* namespace EthosU */ |
| 259 | #endif |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 260 | #endif |