Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 1 | /* |
Jonny Svärd | f1e675a | 2023-07-14 14:04:37 +0200 | [diff] [blame] | 2 | * Copyright (c) 2020-2023 Arm Limited. |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 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 | * |
Jonny Svärd | f1e675a | 2023-07-14 14:04:37 +0200 | [diff] [blame] | 18 | * SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note |
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) |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 48 | #define ETHOSU_IOCTL_BUFFER_CREATE ETHOSU_IOR(0x10, \ |
| 49 | struct ethosu_uapi_buffer_create) |
| 50 | #define ETHOSU_IOCTL_BUFFER_SET ETHOSU_IOR(0x11, \ |
| 51 | struct ethosu_uapi_buffer) |
| 52 | #define ETHOSU_IOCTL_BUFFER_GET ETHOSU_IOW(0x12, \ |
| 53 | struct ethosu_uapi_buffer) |
| 54 | #define ETHOSU_IOCTL_NETWORK_CREATE ETHOSU_IOR(0x20, \ |
| 55 | struct ethosu_uapi_network_create) |
Kristofer Jonsson | 3c6a260 | 2022-03-10 11:17:29 +0100 | [diff] [blame] | 56 | #define ETHOSU_IOCTL_NETWORK_INFO ETHOSU_IOR(0x21, \ |
| 57 | struct ethosu_uapi_network_info) |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 58 | #define ETHOSU_IOCTL_INFERENCE_CREATE ETHOSU_IOR(0x30, \ |
| 59 | struct ethosu_uapi_inference_create) |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 60 | #define ETHOSU_IOCTL_INFERENCE_STATUS ETHOSU_IOR(0x31, \ |
| 61 | struct ethosu_uapi_result_status) |
Davide Grohmann | 7e8f508 | 2022-03-23 12:48:45 +0100 | [diff] [blame] | 62 | #define ETHOSU_IOCTL_INFERENCE_CANCEL ETHOSU_IOR(0x32, \ |
| 63 | struct ethosu_uapi_cancel_inference_status) |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 64 | |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 65 | /* Maximum number of IFM/OFM file descriptors per network */ |
| 66 | #define ETHOSU_FD_MAX 16 |
| 67 | |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 68 | /* Maximum number of PMUs available */ |
Jonny Svärd | b5aa904 | 2021-12-17 17:08:10 +0100 | [diff] [blame] | 69 | #define ETHOSU_PMU_EVENT_MAX 8 |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 70 | |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 71 | /**************************************************************************** |
| 72 | * Types |
| 73 | ****************************************************************************/ |
| 74 | |
| 75 | /** |
| 76 | * enum ethosu_uapi_status - Status |
| 77 | */ |
| 78 | enum ethosu_uapi_status { |
| 79 | ETHOSU_UAPI_STATUS_OK, |
Davide Grohmann | 82d2258 | 2022-04-25 12:52:38 +0200 | [diff] [blame] | 80 | ETHOSU_UAPI_STATUS_ERROR, |
| 81 | ETHOSU_UAPI_STATUS_RUNNING, |
| 82 | ETHOSU_UAPI_STATUS_REJECTED, |
Davide Grohmann | 7e8f508 | 2022-03-23 12:48:45 +0100 | [diff] [blame] | 83 | ETHOSU_UAPI_STATUS_ABORTED, |
| 84 | ETHOSU_UAPI_STATUS_ABORTING, |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | /** |
| 88 | * struct ethosu_uapi_buffer_create - Create buffer request |
| 89 | * @capacity: Maximum capacity of the buffer |
| 90 | */ |
| 91 | struct ethosu_uapi_buffer_create { |
| 92 | __u32 capacity; |
| 93 | }; |
| 94 | |
| 95 | /** |
| 96 | * struct ethosu_uapi_buffer - Buffer descriptor |
| 97 | * @offset: Offset to where the data starts |
| 98 | * @size: Size of the data |
| 99 | * |
| 100 | * 'offset + size' must not exceed the capacity of the buffer. |
| 101 | */ |
| 102 | struct ethosu_uapi_buffer { |
| 103 | __u32 offset; |
| 104 | __u32 size; |
| 105 | }; |
| 106 | |
| 107 | /** |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 108 | * enum ethosu_uapi_network_create - Network buffer type. |
| 109 | * @ETHOSU_UAPI_NETWORK_BUFFER: Network is stored in a buffer handle. |
| 110 | * @ETHOSU_UAPI_NETWORK_INDEX: Network is built into firmware and referenced by |
| 111 | * index. |
| 112 | */ |
| 113 | enum ethosu_uapi_network_type { |
| 114 | ETHOSU_UAPI_NETWORK_BUFFER = 1, |
| 115 | ETHOSU_UAPI_NETWORK_INDEX |
| 116 | }; |
| 117 | |
| 118 | /** |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 119 | * struct ethosu_uapi_network_create - Create network request |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 120 | * @type: Buffer type. See @ethosu_uapi_network_type. |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 121 | * @fd: Buffer file descriptor |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 122 | * @index: Buffer index compiled into firmware binary. |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 123 | */ |
| 124 | struct ethosu_uapi_network_create { |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 125 | uint32_t type; |
| 126 | union { |
| 127 | __u32 fd; |
| 128 | __u32 index; |
| 129 | }; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | /** |
Kristofer Jonsson | 3c6a260 | 2022-03-10 11:17:29 +0100 | [diff] [blame] | 133 | * struct ethosu_uapi_network_info - Network info |
| 134 | * @desc: Network description |
| 135 | * @ifm_count: Number of IFM buffers |
| 136 | * @ifm_size: IFM buffer sizes |
| 137 | * @ofm_count: Number of OFM buffers |
| 138 | * @ofm_size: OFM buffer sizes |
| 139 | */ |
| 140 | struct ethosu_uapi_network_info { |
| 141 | char desc[32]; |
| 142 | __u32 ifm_count; |
| 143 | __u32 ifm_size[ETHOSU_FD_MAX]; |
| 144 | __u32 ofm_count; |
| 145 | __u32 ofm_size[ETHOSU_FD_MAX]; |
| 146 | }; |
| 147 | |
| 148 | /** |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 149 | * struct ethosu_uapi_pmu_config - Configure performance counters |
| 150 | * @events: Array of counters to configure, set to non-zero for |
| 151 | * each counter to enable corresponding event. |
| 152 | * @cycle_count: Set to enable the cycle counter. |
| 153 | */ |
| 154 | struct ethosu_uapi_pmu_config { |
| 155 | __u32 events[ETHOSU_PMU_EVENT_MAX]; |
| 156 | __u32 cycle_count; |
| 157 | }; |
| 158 | |
| 159 | /** |
| 160 | * struct ethosu_uapi_pmu_counts - Status of performance counters |
| 161 | * @events: Count for respective configured events. |
| 162 | * @cycle_count: Count for cycle counter. |
| 163 | */ |
| 164 | struct ethosu_uapi_pmu_counts { |
| 165 | __u32 events[ETHOSU_PMU_EVENT_MAX]; |
| 166 | __u64 cycle_count; |
| 167 | }; |
| 168 | |
| 169 | /** |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 170 | * struct ethosu_uapi_device_hw_id - Device hardware identification |
| 171 | * @version_status: Version status |
| 172 | * @version_minor: Version minor |
| 173 | * @version_major: Version major |
| 174 | * @product_major: Product major |
| 175 | * @arch_patch_rev: Architecture version patch |
| 176 | * @arch_minor_rev: Architecture version minor |
| 177 | * @arch_major_rev: Architecture version major |
| 178 | */ |
| 179 | struct ethosu_uapi_device_hw_id { |
| 180 | __u32 version_status; |
| 181 | __u32 version_minor; |
| 182 | __u32 version_major; |
| 183 | __u32 product_major; |
| 184 | __u32 arch_patch_rev; |
| 185 | __u32 arch_minor_rev; |
| 186 | __u32 arch_major_rev; |
| 187 | }; |
| 188 | |
| 189 | /** |
| 190 | * struct ethosu_uapi_device_hw_cfg - Device hardware configuration |
| 191 | * @macs_per_cc: MACs per clock cycle |
| 192 | * @cmd_stream_version: NPU command stream version |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 193 | * @custom_dma: Custom DMA enabled |
| 194 | */ |
| 195 | struct ethosu_uapi_device_hw_cfg { |
| 196 | __u32 macs_per_cc; |
| 197 | __u32 cmd_stream_version; |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 198 | __u32 custom_dma; |
| 199 | }; |
| 200 | |
| 201 | /** |
Per Åstrand | 7f9a4e3 | 2022-05-18 09:18:27 +0200 | [diff] [blame] | 202 | * struct ethosu_uapi_device_capabilities - Device capabilities |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 203 | * @hw_id: Hardware identification |
| 204 | * @hw_cfg: Hardware configuration |
| 205 | * @driver_patch_rev: Driver version patch |
| 206 | * @driver_minor_rev: Driver version minor |
| 207 | * @driver_major_rev: Driver version major |
| 208 | */ |
| 209 | struct ethosu_uapi_device_capabilities { |
| 210 | struct ethosu_uapi_device_hw_id hw_id; |
| 211 | struct ethosu_uapi_device_hw_cfg hw_cfg; |
| 212 | __u32 driver_patch_rev; |
| 213 | __u32 driver_minor_rev; |
| 214 | __u32 driver_major_rev; |
| 215 | }; |
| 216 | |
| 217 | /** |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 218 | * struct ethosu_uapi_inference_create - Create network request |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 219 | * @ifm_count: Number of IFM file descriptors |
| 220 | * @ifm_fd: IFM buffer file descriptors |
| 221 | * @ofm_count: Number of OFM file descriptors |
| 222 | * @ofm_fd: OFM buffer file descriptors |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 223 | */ |
| 224 | struct ethosu_uapi_inference_create { |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 225 | __u32 ifm_count; |
| 226 | __u32 ifm_fd[ETHOSU_FD_MAX]; |
| 227 | __u32 ofm_count; |
| 228 | __u32 ofm_fd[ETHOSU_FD_MAX]; |
| 229 | struct ethosu_uapi_pmu_config pmu_config; |
| 230 | }; |
| 231 | |
| 232 | /** |
| 233 | * struct ethosu_uapi_result_status - Status of inference |
| 234 | * @status Status of run inference. |
| 235 | * @pmu_config Configured performance counters. |
| 236 | * @pmu_count Perfomance counters values, when status is |
| 237 | * ETHOSU_UAPI_STATUS_OK. |
| 238 | */ |
| 239 | struct ethosu_uapi_result_status { |
| 240 | enum ethosu_uapi_status status; |
| 241 | struct ethosu_uapi_pmu_config pmu_config; |
| 242 | struct ethosu_uapi_pmu_counts pmu_count; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 243 | }; |
| 244 | |
Davide Grohmann | 7e8f508 | 2022-03-23 12:48:45 +0100 | [diff] [blame] | 245 | /** |
| 246 | * struct ethosu_uapi_cancel_status - Status of inference cancellation. |
| 247 | * @status OK if inference cancellation was performed, ERROR otherwise. |
| 248 | */ |
| 249 | struct ethosu_uapi_cancel_inference_status { |
| 250 | enum ethosu_uapi_status status; |
| 251 | }; |
| 252 | |
Per Åstrand | c823bcf | 2021-01-12 13:11:13 +0100 | [diff] [blame] | 253 | #ifdef __cplusplus |
| 254 | } /* namespace EthosU */ |
| 255 | #endif |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 256 | #endif |