Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note |
| 2 | * |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 3 | * Copyright 2016-2020 HabanaLabs, Ltd. |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 4 | * All Rights Reserved. |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef HABANALABS_H_ |
| 9 | #define HABANALABS_H_ |
| 10 | |
| 11 | #include <linux/types.h> |
| 12 | #include <linux/ioctl.h> |
| 13 | |
| 14 | /* |
| 15 | * Defines that are asic-specific but constitutes as ABI between kernel driver |
| 16 | * and userspace |
| 17 | */ |
| 18 | #define GOYA_KMD_SRAM_RESERVED_SIZE_FROM_START 0x8000 /* 32KB */ |
| 19 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 20 | /* |
| 21 | * Queue Numbering |
| 22 | * |
Oded Gabbay | 9002729 | 2019-04-03 09:51:04 +0300 | [diff] [blame] | 23 | * The external queues (PCI DMA channels) MUST be before the internal queues |
| 24 | * and each group (PCI DMA channels and internal) must be contiguous inside |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 25 | * itself but there can be a gap between the two groups (although not |
| 26 | * recommended) |
| 27 | */ |
| 28 | |
| 29 | enum goya_queue_id { |
| 30 | GOYA_QUEUE_ID_DMA_0 = 0, |
Dotan Barak | 4fd2cb1 | 2019-08-12 10:23:33 +0300 | [diff] [blame] | 31 | GOYA_QUEUE_ID_DMA_1 = 1, |
| 32 | GOYA_QUEUE_ID_DMA_2 = 2, |
| 33 | GOYA_QUEUE_ID_DMA_3 = 3, |
| 34 | GOYA_QUEUE_ID_DMA_4 = 4, |
| 35 | GOYA_QUEUE_ID_CPU_PQ = 5, |
| 36 | GOYA_QUEUE_ID_MME = 6, /* Internal queues start here */ |
| 37 | GOYA_QUEUE_ID_TPC0 = 7, |
| 38 | GOYA_QUEUE_ID_TPC1 = 8, |
| 39 | GOYA_QUEUE_ID_TPC2 = 9, |
| 40 | GOYA_QUEUE_ID_TPC3 = 10, |
| 41 | GOYA_QUEUE_ID_TPC4 = 11, |
| 42 | GOYA_QUEUE_ID_TPC5 = 12, |
| 43 | GOYA_QUEUE_ID_TPC6 = 13, |
| 44 | GOYA_QUEUE_ID_TPC7 = 14, |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 45 | GOYA_QUEUE_ID_SIZE |
| 46 | }; |
| 47 | |
Tomer Tayar | e8960ca | 2019-07-01 13:59:45 +0000 | [diff] [blame] | 48 | /* |
| 49 | * Engine Numbering |
| 50 | * |
| 51 | * Used in the "busy_engines_mask" field in `struct hl_info_hw_idle' |
| 52 | */ |
| 53 | |
| 54 | enum goya_engine_id { |
| 55 | GOYA_ENGINE_ID_DMA_0 = 0, |
| 56 | GOYA_ENGINE_ID_DMA_1, |
| 57 | GOYA_ENGINE_ID_DMA_2, |
| 58 | GOYA_ENGINE_ID_DMA_3, |
| 59 | GOYA_ENGINE_ID_DMA_4, |
| 60 | GOYA_ENGINE_ID_MME_0, |
| 61 | GOYA_ENGINE_ID_TPC_0, |
| 62 | GOYA_ENGINE_ID_TPC_1, |
| 63 | GOYA_ENGINE_ID_TPC_2, |
| 64 | GOYA_ENGINE_ID_TPC_3, |
| 65 | GOYA_ENGINE_ID_TPC_4, |
| 66 | GOYA_ENGINE_ID_TPC_5, |
| 67 | GOYA_ENGINE_ID_TPC_6, |
| 68 | GOYA_ENGINE_ID_TPC_7, |
| 69 | GOYA_ENGINE_ID_SIZE |
| 70 | }; |
| 71 | |
Dalit Ben Zoor | aa95708 | 2019-03-24 10:15:44 +0200 | [diff] [blame] | 72 | enum hl_device_status { |
| 73 | HL_DEVICE_STATUS_OPERATIONAL, |
| 74 | HL_DEVICE_STATUS_IN_RESET, |
| 75 | HL_DEVICE_STATUS_MALFUNCTION |
| 76 | }; |
| 77 | |
Oded Gabbay | f388ec7 | 2019-07-16 08:55:04 +0300 | [diff] [blame] | 78 | /* Opcode for management ioctl |
| 79 | * |
Oded Gabbay | 75b3cb2 | 2019-08-28 17:32:04 +0300 | [diff] [blame] | 80 | * HW_IP_INFO - Receive information about different IP blocks in the |
| 81 | * device. |
| 82 | * HL_INFO_HW_EVENTS - Receive an array describing how many times each event |
| 83 | * occurred since the last hard reset. |
| 84 | * HL_INFO_DRAM_USAGE - Retrieve the dram usage inside the device and of the |
| 85 | * specific context. This is relevant only for devices |
| 86 | * where the dram is managed by the kernel driver |
| 87 | * HL_INFO_HW_IDLE - Retrieve information about the idle status of each |
| 88 | * internal engine. |
Oded Gabbay | f388ec7 | 2019-07-16 08:55:04 +0300 | [diff] [blame] | 89 | * HL_INFO_DEVICE_STATUS - Retrieve the device's status. This opcode doesn't |
| 90 | * require an open context. |
Oded Gabbay | 62c1e12 | 2019-10-10 15:48:59 +0300 | [diff] [blame] | 91 | * HL_INFO_DEVICE_UTILIZATION - Retrieve the total utilization of the device |
| 92 | * over the last period specified by the user. |
| 93 | * The period can be between 100ms to 1s, in |
| 94 | * resolution of 100ms. The return value is a |
| 95 | * percentage of the utilization rate. |
Oded Gabbay | e973076 | 2019-08-28 21:51:52 +0300 | [diff] [blame] | 96 | * HL_INFO_HW_EVENTS_AGGREGATE - Receive an array describing how many times each |
| 97 | * event occurred since the driver was loaded. |
Oded Gabbay | 62c1e12 | 2019-10-10 15:48:59 +0300 | [diff] [blame] | 98 | * HL_INFO_CLK_RATE - Retrieve the current and maximum clock rate |
| 99 | * of the device in MHz. The maximum clock rate is |
| 100 | * configurable via sysfs parameter |
Moti Haimovski | 52c01b0 | 2019-11-03 16:26:44 +0200 | [diff] [blame] | 101 | * HL_INFO_RESET_COUNT - Retrieve the counts of the soft and hard reset |
| 102 | * operations performed on the device since the last |
| 103 | * time the driver was loaded. |
Tomer Tayar | 25e7aeb | 2020-03-31 22:46:36 +0300 | [diff] [blame] | 104 | * HL_INFO_TIME_SYNC - Retrieve the device's time alongside the host's time |
| 105 | * for synchronization. |
Oded Gabbay | f388ec7 | 2019-07-16 08:55:04 +0300 | [diff] [blame] | 106 | */ |
Oded Gabbay | 75b3cb2 | 2019-08-28 17:32:04 +0300 | [diff] [blame] | 107 | #define HL_INFO_HW_IP_INFO 0 |
| 108 | #define HL_INFO_HW_EVENTS 1 |
| 109 | #define HL_INFO_DRAM_USAGE 2 |
| 110 | #define HL_INFO_HW_IDLE 3 |
| 111 | #define HL_INFO_DEVICE_STATUS 4 |
| 112 | #define HL_INFO_DEVICE_UTILIZATION 6 |
Oded Gabbay | e973076 | 2019-08-28 21:51:52 +0300 | [diff] [blame] | 113 | #define HL_INFO_HW_EVENTS_AGGREGATE 7 |
Oded Gabbay | 62c1e12 | 2019-10-10 15:48:59 +0300 | [diff] [blame] | 114 | #define HL_INFO_CLK_RATE 8 |
Moti Haimovski | 52c01b0 | 2019-11-03 16:26:44 +0200 | [diff] [blame] | 115 | #define HL_INFO_RESET_COUNT 9 |
Tomer Tayar | 25e7aeb | 2020-03-31 22:46:36 +0300 | [diff] [blame] | 116 | #define HL_INFO_TIME_SYNC 10 |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 117 | |
| 118 | #define HL_INFO_VERSION_MAX_LEN 128 |
Oded Gabbay | 91edbf2 | 2019-10-16 11:53:52 +0300 | [diff] [blame] | 119 | #define HL_INFO_CARD_NAME_MAX_LEN 16 |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 120 | |
| 121 | struct hl_info_hw_ip_info { |
| 122 | __u64 sram_base_address; |
| 123 | __u64 dram_base_address; |
| 124 | __u64 dram_size; |
| 125 | __u32 sram_size; |
| 126 | __u32 num_of_events; |
| 127 | __u32 device_id; /* PCI Device ID */ |
Omer Shpigelman | fca72fb | 2020-05-03 17:35:54 +0300 | [diff] [blame^] | 128 | __u32 module_id; /* For mezzanine cards in servers (From OCP spec.) */ |
| 129 | __u32 reserved[2]; |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 130 | __u32 armcp_cpld_version; |
| 131 | __u32 psoc_pci_pll_nr; |
| 132 | __u32 psoc_pci_pll_nf; |
| 133 | __u32 psoc_pci_pll_od; |
| 134 | __u32 psoc_pci_pll_div_factor; |
| 135 | __u8 tpc_enabled_mask; |
| 136 | __u8 dram_enabled; |
| 137 | __u8 pad[2]; |
| 138 | __u8 armcp_version[HL_INFO_VERSION_MAX_LEN]; |
Oded Gabbay | 91edbf2 | 2019-10-16 11:53:52 +0300 | [diff] [blame] | 139 | __u8 card_name[HL_INFO_CARD_NAME_MAX_LEN]; |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | struct hl_info_dram_usage { |
| 143 | __u64 dram_free_mem; |
| 144 | __u64 ctx_dram_mem; |
| 145 | }; |
| 146 | |
| 147 | struct hl_info_hw_idle { |
| 148 | __u32 is_idle; |
Tomer Tayar | e8960ca | 2019-07-01 13:59:45 +0000 | [diff] [blame] | 149 | /* |
| 150 | * Bitmask of busy engines. |
| 151 | * Bits definition is according to `enum <chip>_enging_id'. |
| 152 | */ |
| 153 | __u32 busy_engines_mask; |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 154 | }; |
| 155 | |
Dalit Ben Zoor | aa95708 | 2019-03-24 10:15:44 +0200 | [diff] [blame] | 156 | struct hl_info_device_status { |
| 157 | __u32 status; |
| 158 | __u32 pad; |
| 159 | }; |
| 160 | |
Oded Gabbay | 75b3cb2 | 2019-08-28 17:32:04 +0300 | [diff] [blame] | 161 | struct hl_info_device_utilization { |
| 162 | __u32 utilization; |
| 163 | __u32 pad; |
| 164 | }; |
| 165 | |
Oded Gabbay | 62c1e12 | 2019-10-10 15:48:59 +0300 | [diff] [blame] | 166 | struct hl_info_clk_rate { |
| 167 | __u32 cur_clk_rate_mhz; |
| 168 | __u32 max_clk_rate_mhz; |
| 169 | }; |
| 170 | |
Moti Haimovski | 52c01b0 | 2019-11-03 16:26:44 +0200 | [diff] [blame] | 171 | struct hl_info_reset_count { |
| 172 | __u32 hard_reset_cnt; |
| 173 | __u32 soft_reset_cnt; |
| 174 | }; |
| 175 | |
Tomer Tayar | 25e7aeb | 2020-03-31 22:46:36 +0300 | [diff] [blame] | 176 | struct hl_info_time_sync { |
| 177 | __u64 device_time; |
| 178 | __u64 host_time; |
| 179 | }; |
| 180 | |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 181 | struct hl_info_args { |
| 182 | /* Location of relevant struct in userspace */ |
| 183 | __u64 return_pointer; |
| 184 | /* |
| 185 | * The size of the return value. Just like "size" in "snprintf", |
| 186 | * it limits how many bytes the kernel can write |
| 187 | * |
| 188 | * For hw_events array, the size should be |
| 189 | * hl_info_hw_ip_info.num_of_events * sizeof(__u32) |
| 190 | */ |
| 191 | __u32 return_size; |
| 192 | |
| 193 | /* HL_INFO_* */ |
| 194 | __u32 op; |
| 195 | |
Oded Gabbay | 75b3cb2 | 2019-08-28 17:32:04 +0300 | [diff] [blame] | 196 | union { |
| 197 | /* Context ID - Currently not in use */ |
| 198 | __u32 ctx_id; |
| 199 | /* Period value for utilization rate (100ms - 1000ms, in 100ms |
| 200 | * resolution. |
| 201 | */ |
| 202 | __u32 period_ms; |
| 203 | }; |
| 204 | |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 205 | __u32 pad; |
| 206 | }; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 207 | |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 208 | /* Opcode to create a new command buffer */ |
| 209 | #define HL_CB_OP_CREATE 0 |
| 210 | /* Opcode to destroy previously created command buffer */ |
| 211 | #define HL_CB_OP_DESTROY 1 |
| 212 | |
Oded Gabbay | 39b4251 | 2020-04-17 12:12:13 +0300 | [diff] [blame] | 213 | /* 2MB minus 32 bytes for 2xMSG_PROT */ |
| 214 | #define HL_MAX_CB_SIZE (0x200000 - 32) |
Oded Gabbay | 5d10125 | 2019-11-10 16:08:26 +0200 | [diff] [blame] | 215 | |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 216 | struct hl_cb_in { |
| 217 | /* Handle of CB or 0 if we want to create one */ |
| 218 | __u64 cb_handle; |
| 219 | /* HL_CB_OP_* */ |
| 220 | __u32 op; |
Oded Gabbay | 5d10125 | 2019-11-10 16:08:26 +0200 | [diff] [blame] | 221 | /* Size of CB. Maximum size is HL_MAX_CB_SIZE. The minimum size that |
| 222 | * will be allocated, regardless of this parameter's value, is PAGE_SIZE |
Oded Gabbay | 541664d3 | 2019-02-28 11:55:44 +0200 | [diff] [blame] | 223 | */ |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 224 | __u32 cb_size; |
| 225 | /* Context ID - Currently not in use */ |
| 226 | __u32 ctx_id; |
| 227 | __u32 pad; |
| 228 | }; |
| 229 | |
| 230 | struct hl_cb_out { |
| 231 | /* Handle of CB */ |
| 232 | __u64 cb_handle; |
| 233 | }; |
| 234 | |
| 235 | union hl_cb_args { |
| 236 | struct hl_cb_in in; |
| 237 | struct hl_cb_out out; |
| 238 | }; |
| 239 | |
| 240 | /* |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 241 | * This structure size must always be fixed to 64-bytes for backward |
| 242 | * compatibility |
| 243 | */ |
| 244 | struct hl_cs_chunk { |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 245 | union { |
| 246 | /* For external queue, this represents a Handle of CB on the |
| 247 | * Host. |
| 248 | * For internal queue in Goya, this represents an SRAM or |
| 249 | * a DRAM address of the internal CB. In Gaudi, this might also |
| 250 | * represent a mapped host address of the CB. |
| 251 | * |
| 252 | * A mapped host address is in the device address space, after |
| 253 | * a host address was mapped by the device MMU. |
| 254 | */ |
| 255 | __u64 cb_handle; |
| 256 | |
| 257 | /* Relevant only when HL_CS_FLAGS_WAIT is set. |
| 258 | * This holds address of array of u64 values that contain |
| 259 | * signal CS sequence numbers. The wait described by this job |
| 260 | * will listen on all those signals (wait event per signal) |
| 261 | */ |
| 262 | __u64 signal_seq_arr; |
| 263 | }; |
| 264 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 265 | /* Index of queue to put the CB on */ |
| 266 | __u32 queue_index; |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 267 | |
| 268 | union { |
| 269 | /* |
| 270 | * Size of command buffer with valid packets |
| 271 | * Can be smaller then actual CB size |
| 272 | */ |
| 273 | __u32 cb_size; |
| 274 | |
| 275 | /* Relevant only when HL_CS_FLAGS_WAIT is set. |
| 276 | * Number of entries in signal_seq_arr |
| 277 | */ |
| 278 | __u32 num_signal_seq_arr; |
| 279 | }; |
| 280 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 281 | /* HL_CS_CHUNK_FLAGS_* */ |
| 282 | __u32 cs_chunk_flags; |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 283 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 284 | /* Align structure to 64 bytes */ |
| 285 | __u32 pad[11]; |
| 286 | }; |
| 287 | |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 288 | /* SIGNAL and WAIT flags are mutually exclusive */ |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 289 | #define HL_CS_FLAGS_FORCE_RESTORE 0x1 |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 290 | #define HL_CS_FLAGS_SIGNAL 0x2 |
| 291 | #define HL_CS_FLAGS_WAIT 0x4 |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 292 | |
| 293 | #define HL_CS_STATUS_SUCCESS 0 |
| 294 | |
Oded Gabbay | 5d10125 | 2019-11-10 16:08:26 +0200 | [diff] [blame] | 295 | #define HL_MAX_JOBS_PER_CS 512 |
| 296 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 297 | struct hl_cs_in { |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 298 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 299 | /* this holds address of array of hl_cs_chunk for restore phase */ |
| 300 | __u64 chunks_restore; |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 301 | |
| 302 | /* holds address of array of hl_cs_chunk for execution phase */ |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 303 | __u64 chunks_execute; |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 304 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 305 | /* this holds address of array of hl_cs_chunk for store phase - |
| 306 | * Currently not in use |
| 307 | */ |
| 308 | __u64 chunks_store; |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 309 | |
Oded Gabbay | 5d10125 | 2019-11-10 16:08:26 +0200 | [diff] [blame] | 310 | /* Number of chunks in restore phase array. Maximum number is |
| 311 | * HL_MAX_JOBS_PER_CS |
| 312 | */ |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 313 | __u32 num_chunks_restore; |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 314 | |
Oded Gabbay | 5d10125 | 2019-11-10 16:08:26 +0200 | [diff] [blame] | 315 | /* Number of chunks in execution array. Maximum number is |
| 316 | * HL_MAX_JOBS_PER_CS |
| 317 | */ |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 318 | __u32 num_chunks_execute; |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 319 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 320 | /* Number of chunks in restore phase array - Currently not in use */ |
| 321 | __u32 num_chunks_store; |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 322 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 323 | /* HL_CS_FLAGS_* */ |
| 324 | __u32 cs_flags; |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 325 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 326 | /* Context ID - Currently not in use */ |
| 327 | __u32 ctx_id; |
| 328 | }; |
| 329 | |
| 330 | struct hl_cs_out { |
Oded Gabbay | e126600 | 2019-03-07 14:20:05 +0200 | [diff] [blame] | 331 | /* |
| 332 | * seq holds the sequence number of the CS to pass to wait ioctl. All |
| 333 | * values are valid except for 0 and ULLONG_MAX |
| 334 | */ |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 335 | __u64 seq; |
| 336 | /* HL_CS_STATUS_* */ |
| 337 | __u32 status; |
| 338 | __u32 pad; |
| 339 | }; |
| 340 | |
| 341 | union hl_cs_args { |
| 342 | struct hl_cs_in in; |
| 343 | struct hl_cs_out out; |
| 344 | }; |
| 345 | |
| 346 | struct hl_wait_cs_in { |
| 347 | /* Command submission sequence number */ |
| 348 | __u64 seq; |
| 349 | /* Absolute timeout to wait in microseconds */ |
| 350 | __u64 timeout_us; |
| 351 | /* Context ID - Currently not in use */ |
| 352 | __u32 ctx_id; |
| 353 | __u32 pad; |
| 354 | }; |
| 355 | |
| 356 | #define HL_WAIT_CS_STATUS_COMPLETED 0 |
| 357 | #define HL_WAIT_CS_STATUS_BUSY 1 |
| 358 | #define HL_WAIT_CS_STATUS_TIMEDOUT 2 |
| 359 | #define HL_WAIT_CS_STATUS_ABORTED 3 |
| 360 | #define HL_WAIT_CS_STATUS_INTERRUPTED 4 |
| 361 | |
| 362 | struct hl_wait_cs_out { |
| 363 | /* HL_WAIT_CS_STATUS_* */ |
| 364 | __u32 status; |
| 365 | __u32 pad; |
| 366 | }; |
| 367 | |
| 368 | union hl_wait_cs_args { |
| 369 | struct hl_wait_cs_in in; |
| 370 | struct hl_wait_cs_out out; |
| 371 | }; |
| 372 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 373 | /* Opcode to alloc device memory */ |
| 374 | #define HL_MEM_OP_ALLOC 0 |
| 375 | /* Opcode to free previously allocated device memory */ |
| 376 | #define HL_MEM_OP_FREE 1 |
| 377 | /* Opcode to map host memory */ |
| 378 | #define HL_MEM_OP_MAP 2 |
| 379 | /* Opcode to unmap previously mapped host memory */ |
| 380 | #define HL_MEM_OP_UNMAP 3 |
| 381 | |
| 382 | /* Memory flags */ |
| 383 | #define HL_MEM_CONTIGUOUS 0x1 |
| 384 | #define HL_MEM_SHARED 0x2 |
| 385 | #define HL_MEM_USERPTR 0x4 |
| 386 | |
| 387 | struct hl_mem_in { |
| 388 | union { |
| 389 | /* HL_MEM_OP_ALLOC- allocate device memory */ |
| 390 | struct { |
| 391 | /* Size to alloc */ |
Oded Gabbay | 230afe7 | 2019-02-27 00:19:18 +0200 | [diff] [blame] | 392 | __u64 mem_size; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 393 | } alloc; |
| 394 | |
| 395 | /* HL_MEM_OP_FREE - free device memory */ |
| 396 | struct { |
| 397 | /* Handle returned from HL_MEM_OP_ALLOC */ |
| 398 | __u64 handle; |
| 399 | } free; |
| 400 | |
| 401 | /* HL_MEM_OP_MAP - map device memory */ |
| 402 | struct { |
| 403 | /* |
| 404 | * Requested virtual address of mapped memory. |
Oded Gabbay | 4c172bb | 2019-08-30 16:59:33 +0300 | [diff] [blame] | 405 | * The driver will try to map the requested region to |
| 406 | * this hint address, as long as the address is valid |
| 407 | * and not already mapped. The user should check the |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 408 | * returned address of the IOCTL to make sure he got |
Oded Gabbay | 4c172bb | 2019-08-30 16:59:33 +0300 | [diff] [blame] | 409 | * the hint address. Passing 0 here means that the |
| 410 | * driver will choose the address itself. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 411 | */ |
| 412 | __u64 hint_addr; |
| 413 | /* Handle returned from HL_MEM_OP_ALLOC */ |
| 414 | __u64 handle; |
| 415 | } map_device; |
| 416 | |
| 417 | /* HL_MEM_OP_MAP - map host memory */ |
| 418 | struct { |
| 419 | /* Address of allocated host memory */ |
| 420 | __u64 host_virt_addr; |
| 421 | /* |
| 422 | * Requested virtual address of mapped memory. |
Oded Gabbay | 4c172bb | 2019-08-30 16:59:33 +0300 | [diff] [blame] | 423 | * The driver will try to map the requested region to |
| 424 | * this hint address, as long as the address is valid |
| 425 | * and not already mapped. The user should check the |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 426 | * returned address of the IOCTL to make sure he got |
Oded Gabbay | 4c172bb | 2019-08-30 16:59:33 +0300 | [diff] [blame] | 427 | * the hint address. Passing 0 here means that the |
| 428 | * driver will choose the address itself. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 429 | */ |
| 430 | __u64 hint_addr; |
| 431 | /* Size of allocated host memory */ |
Oded Gabbay | 230afe7 | 2019-02-27 00:19:18 +0200 | [diff] [blame] | 432 | __u64 mem_size; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 433 | } map_host; |
| 434 | |
| 435 | /* HL_MEM_OP_UNMAP - unmap host memory */ |
| 436 | struct { |
| 437 | /* Virtual address returned from HL_MEM_OP_MAP */ |
| 438 | __u64 device_virt_addr; |
| 439 | } unmap; |
| 440 | }; |
| 441 | |
| 442 | /* HL_MEM_OP_* */ |
| 443 | __u32 op; |
| 444 | /* HL_MEM_* flags */ |
| 445 | __u32 flags; |
| 446 | /* Context ID - Currently not in use */ |
| 447 | __u32 ctx_id; |
| 448 | __u32 pad; |
| 449 | }; |
| 450 | |
| 451 | struct hl_mem_out { |
| 452 | union { |
| 453 | /* |
| 454 | * Used for HL_MEM_OP_MAP as the virtual address that was |
| 455 | * assigned in the device VA space. |
| 456 | * A value of 0 means the requested operation failed. |
| 457 | */ |
| 458 | __u64 device_virt_addr; |
| 459 | |
| 460 | /* |
| 461 | * Used for HL_MEM_OP_ALLOC. This is the assigned |
| 462 | * handle for the allocated memory |
| 463 | */ |
| 464 | __u64 handle; |
| 465 | }; |
| 466 | }; |
| 467 | |
| 468 | union hl_mem_args { |
| 469 | struct hl_mem_in in; |
| 470 | struct hl_mem_out out; |
| 471 | }; |
| 472 | |
Omer Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 473 | #define HL_DEBUG_MAX_AUX_VALUES 10 |
| 474 | |
| 475 | struct hl_debug_params_etr { |
| 476 | /* Address in memory to allocate buffer */ |
| 477 | __u64 buffer_address; |
| 478 | |
| 479 | /* Size of buffer to allocate */ |
| 480 | __u64 buffer_size; |
| 481 | |
| 482 | /* Sink operation mode: SW fifo, HW fifo, Circular buffer */ |
| 483 | __u32 sink_mode; |
| 484 | __u32 pad; |
| 485 | }; |
| 486 | |
| 487 | struct hl_debug_params_etf { |
| 488 | /* Address in memory to allocate buffer */ |
| 489 | __u64 buffer_address; |
| 490 | |
| 491 | /* Size of buffer to allocate */ |
| 492 | __u64 buffer_size; |
| 493 | |
| 494 | /* Sink operation mode: SW fifo, HW fifo, Circular buffer */ |
| 495 | __u32 sink_mode; |
| 496 | __u32 pad; |
| 497 | }; |
| 498 | |
| 499 | struct hl_debug_params_stm { |
| 500 | /* Two bit masks for HW event and Stimulus Port */ |
| 501 | __u64 he_mask; |
| 502 | __u64 sp_mask; |
| 503 | |
| 504 | /* Trace source ID */ |
| 505 | __u32 id; |
| 506 | |
| 507 | /* Frequency for the timestamp register */ |
| 508 | __u32 frequency; |
| 509 | }; |
| 510 | |
| 511 | struct hl_debug_params_bmon { |
Oded Gabbay | d691171 | 2019-04-21 16:20:46 +0300 | [diff] [blame] | 512 | /* Two address ranges that the user can request to filter */ |
| 513 | __u64 start_addr0; |
| 514 | __u64 addr_mask0; |
| 515 | |
| 516 | __u64 start_addr1; |
| 517 | __u64 addr_mask1; |
Omer Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 518 | |
| 519 | /* Capture window configuration */ |
| 520 | __u32 bw_win; |
| 521 | __u32 win_capture; |
| 522 | |
| 523 | /* Trace source ID */ |
| 524 | __u32 id; |
| 525 | __u32 pad; |
| 526 | }; |
| 527 | |
| 528 | struct hl_debug_params_spmu { |
| 529 | /* Event types selection */ |
| 530 | __u64 event_types[HL_DEBUG_MAX_AUX_VALUES]; |
| 531 | |
| 532 | /* Number of event types selection */ |
| 533 | __u32 event_types_num; |
| 534 | __u32 pad; |
| 535 | }; |
| 536 | |
| 537 | /* Opcode for ETR component */ |
| 538 | #define HL_DEBUG_OP_ETR 0 |
| 539 | /* Opcode for ETF component */ |
| 540 | #define HL_DEBUG_OP_ETF 1 |
| 541 | /* Opcode for STM component */ |
| 542 | #define HL_DEBUG_OP_STM 2 |
| 543 | /* Opcode for FUNNEL component */ |
| 544 | #define HL_DEBUG_OP_FUNNEL 3 |
| 545 | /* Opcode for BMON component */ |
| 546 | #define HL_DEBUG_OP_BMON 4 |
| 547 | /* Opcode for SPMU component */ |
| 548 | #define HL_DEBUG_OP_SPMU 5 |
Tomer Tayar | 413cf57 | 2019-08-27 16:14:18 +0000 | [diff] [blame] | 549 | /* Opcode for timestamp (deprecated) */ |
Omer Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 550 | #define HL_DEBUG_OP_TIMESTAMP 6 |
Oded Gabbay | 2add64e | 2019-05-04 16:30:00 +0300 | [diff] [blame] | 551 | /* Opcode for setting the device into or out of debug mode. The enable |
| 552 | * variable should be 1 for enabling debug mode and 0 for disabling it |
| 553 | */ |
| 554 | #define HL_DEBUG_OP_SET_MODE 7 |
Omer Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 555 | |
| 556 | struct hl_debug_args { |
| 557 | /* |
| 558 | * Pointer to user input structure. |
| 559 | * This field is relevant to specific opcodes. |
| 560 | */ |
| 561 | __u64 input_ptr; |
| 562 | /* Pointer to user output structure */ |
| 563 | __u64 output_ptr; |
| 564 | /* Size of user input structure */ |
| 565 | __u32 input_size; |
| 566 | /* Size of user output structure */ |
| 567 | __u32 output_size; |
| 568 | /* HL_DEBUG_OP_* */ |
| 569 | __u32 op; |
| 570 | /* |
| 571 | * Register index in the component, taken from the debug_regs_index enum |
| 572 | * in the various ASIC header files |
| 573 | */ |
| 574 | __u32 reg_idx; |
| 575 | /* Enable/disable */ |
| 576 | __u32 enable; |
| 577 | /* Context ID - Currently not in use */ |
| 578 | __u32 ctx_id; |
| 579 | }; |
| 580 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 581 | /* |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 582 | * Various information operations such as: |
| 583 | * - H/W IP information |
| 584 | * - Current dram usage |
| 585 | * |
| 586 | * The user calls this IOCTL with an opcode that describes the required |
| 587 | * information. The user should supply a pointer to a user-allocated memory |
| 588 | * chunk, which will be filled by the driver with the requested information. |
| 589 | * |
| 590 | * The user supplies the maximum amount of size to copy into the user's memory, |
| 591 | * in order to prevent data corruption in case of differences between the |
| 592 | * definitions of structures in kernel and userspace, e.g. in case of old |
| 593 | * userspace and new kernel driver |
| 594 | */ |
| 595 | #define HL_IOCTL_INFO \ |
| 596 | _IOWR('H', 0x01, struct hl_info_args) |
| 597 | |
| 598 | /* |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 599 | * Command Buffer |
| 600 | * - Request a Command Buffer |
| 601 | * - Destroy a Command Buffer |
| 602 | * |
| 603 | * The command buffers are memory blocks that reside in DMA-able address |
| 604 | * space and are physically contiguous so they can be accessed by the device |
| 605 | * directly. They are allocated using the coherent DMA API. |
| 606 | * |
| 607 | * When creating a new CB, the IOCTL returns a handle of it, and the user-space |
| 608 | * process needs to use that handle to mmap the buffer so it can access them. |
| 609 | * |
| 610 | */ |
| 611 | #define HL_IOCTL_CB \ |
| 612 | _IOWR('H', 0x02, union hl_cb_args) |
| 613 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 614 | /* |
| 615 | * Command Submission |
| 616 | * |
| 617 | * To submit work to the device, the user need to call this IOCTL with a set |
| 618 | * of JOBS. That set of JOBS constitutes a CS object. |
| 619 | * Each JOB will be enqueued on a specific queue, according to the user's input. |
| 620 | * There can be more then one JOB per queue. |
| 621 | * |
Oded Gabbay | 9002729 | 2019-04-03 09:51:04 +0300 | [diff] [blame] | 622 | * The CS IOCTL will receive three sets of JOBS. One set is for "restore" phase, |
| 623 | * a second set is for "execution" phase and a third set is for "store" phase. |
| 624 | * The JOBS on the "restore" phase are enqueued only after context-switch |
| 625 | * (or if its the first CS for this context). The user can also order the |
| 626 | * driver to run the "restore" phase explicitly |
| 627 | * |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 628 | * There are two types of queues - external and internal. External queues |
| 629 | * are DMA queues which transfer data from/to the Host. All other queues are |
| 630 | * internal. The driver will get completion notifications from the device only |
| 631 | * on JOBS which are enqueued in the external queues. |
| 632 | * |
Oded Gabbay | 541664d3 | 2019-02-28 11:55:44 +0200 | [diff] [blame] | 633 | * For jobs on external queues, the user needs to create command buffers |
| 634 | * through the CB ioctl and give the CB's handle to the CS ioctl. For jobs on |
| 635 | * internal queues, the user needs to prepare a "command buffer" with packets |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 636 | * on either the device SRAM/DRAM or the host, and give the device address of |
| 637 | * that buffer to the CS ioctl. |
Oded Gabbay | 541664d3 | 2019-02-28 11:55:44 +0200 | [diff] [blame] | 638 | * |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 639 | * This IOCTL is asynchronous in regard to the actual execution of the CS. This |
| 640 | * means it returns immediately after ALL the JOBS were enqueued on their |
| 641 | * relevant queues. Therefore, the user mustn't assume the CS has been completed |
| 642 | * or has even started to execute. |
| 643 | * |
Oded Gabbay | 9002729 | 2019-04-03 09:51:04 +0300 | [diff] [blame] | 644 | * Upon successful enqueue, the IOCTL returns a sequence number which the user |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 645 | * can use with the "Wait for CS" IOCTL to check whether the handle's CS |
| 646 | * external JOBS have been completed. Note that if the CS has internal JOBS |
| 647 | * which can execute AFTER the external JOBS have finished, the driver might |
| 648 | * report that the CS has finished executing BEFORE the internal JOBS have |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 649 | * actually finished executing. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 650 | * |
Oded Gabbay | 9002729 | 2019-04-03 09:51:04 +0300 | [diff] [blame] | 651 | * Even though the sequence number increments per CS, the user can NOT |
| 652 | * automatically assume that if CS with sequence number N finished, then CS |
| 653 | * with sequence number N-1 also finished. The user can make this assumption if |
| 654 | * and only if CS N and CS N-1 are exactly the same (same CBs for the same |
| 655 | * queues). |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 656 | */ |
| 657 | #define HL_IOCTL_CS \ |
| 658 | _IOWR('H', 0x03, union hl_cs_args) |
| 659 | |
| 660 | /* |
| 661 | * Wait for Command Submission |
| 662 | * |
| 663 | * The user can call this IOCTL with a handle it received from the CS IOCTL |
| 664 | * to wait until the handle's CS has finished executing. The user will wait |
Tomer Tayar | f435614 | 2019-10-02 13:53:52 +0000 | [diff] [blame] | 665 | * inside the kernel until the CS has finished or until the user-requested |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 666 | * timeout has expired. |
| 667 | * |
| 668 | * The return value of the IOCTL is a standard Linux error code. The possible |
| 669 | * values are: |
| 670 | * |
| 671 | * EINTR - Kernel waiting has been interrupted, e.g. due to OS signal |
| 672 | * that the user process received |
| 673 | * ETIMEDOUT - The CS has caused a timeout on the device |
| 674 | * EIO - The CS was aborted (usually because the device was reset) |
| 675 | * ENODEV - The device wants to do hard-reset (so user need to close FD) |
| 676 | * |
| 677 | * The driver also returns a custom define inside the IOCTL which can be: |
| 678 | * |
| 679 | * HL_WAIT_CS_STATUS_COMPLETED - The CS has been completed successfully (0) |
| 680 | * HL_WAIT_CS_STATUS_BUSY - The CS is still executing (0) |
| 681 | * HL_WAIT_CS_STATUS_TIMEDOUT - The CS has caused a timeout on the device |
| 682 | * (ETIMEDOUT) |
| 683 | * HL_WAIT_CS_STATUS_ABORTED - The CS was aborted, usually because the |
| 684 | * device was reset (EIO) |
| 685 | * HL_WAIT_CS_STATUS_INTERRUPTED - Waiting for the CS was interrupted (EINTR) |
| 686 | * |
| 687 | */ |
| 688 | |
| 689 | #define HL_IOCTL_WAIT_CS \ |
| 690 | _IOWR('H', 0x04, union hl_wait_cs_args) |
| 691 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 692 | /* |
| 693 | * Memory |
| 694 | * - Map host memory to device MMU |
| 695 | * - Unmap host memory from device MMU |
| 696 | * |
| 697 | * This IOCTL allows the user to map host memory to the device MMU |
| 698 | * |
| 699 | * For host memory, the IOCTL doesn't allocate memory. The user is supposed |
| 700 | * to allocate the memory in user-space (malloc/new). The driver pins the |
| 701 | * physical pages (up to the allowed limit by the OS), assigns a virtual |
| 702 | * address in the device VA space and initializes the device MMU. |
| 703 | * |
| 704 | * There is an option for the user to specify the requested virtual address. |
| 705 | * |
| 706 | */ |
| 707 | #define HL_IOCTL_MEMORY \ |
| 708 | _IOWR('H', 0x05, union hl_mem_args) |
| 709 | |
Omer Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 710 | /* |
| 711 | * Debug |
| 712 | * - Enable/disable the ETR/ETF/FUNNEL/STM/BMON/SPMU debug traces |
| 713 | * |
| 714 | * This IOCTL allows the user to get debug traces from the chip. |
| 715 | * |
Oded Gabbay | 2add64e | 2019-05-04 16:30:00 +0300 | [diff] [blame] | 716 | * Before the user can send configuration requests of the various |
| 717 | * debug/profile engines, it needs to set the device into debug mode. |
| 718 | * This is because the debug/profile infrastructure is shared component in the |
| 719 | * device and we can't allow multiple users to access it at the same time. |
| 720 | * |
| 721 | * Once a user set the device into debug mode, the driver won't allow other |
| 722 | * users to "work" with the device, i.e. open a FD. If there are multiple users |
| 723 | * opened on the device, the driver won't allow any user to debug the device. |
| 724 | * |
| 725 | * For each configuration request, the user needs to provide the register index |
| 726 | * and essential data such as buffer address and size. |
| 727 | * |
| 728 | * Once the user has finished using the debug/profile engines, he should |
| 729 | * set the device into non-debug mode, i.e. disable debug mode. |
| 730 | * |
| 731 | * The driver can decide to "kick out" the user if he abuses this interface. |
Omer Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 732 | * |
| 733 | */ |
| 734 | #define HL_IOCTL_DEBUG \ |
| 735 | _IOWR('H', 0x06, struct hl_debug_args) |
| 736 | |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 737 | #define HL_COMMAND_START 0x01 |
Omer Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 738 | #define HL_COMMAND_END 0x07 |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 739 | |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 740 | #endif /* HABANALABS_H_ */ |