blob: 079613dd7aaebb1874a3d5069d6d69a0723565d8 [file] [log] [blame]
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
2 *
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +03003 * Copyright 2016-2020 HabanaLabs, Ltd.
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02004 * 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 Gabbay9494a8d2019-02-16 00:39:17 +020020/*
21 * Queue Numbering
22 *
Oded Gabbay90027292019-04-03 09:51:04 +030023 * 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 Gabbay9494a8d2019-02-16 00:39:17 +020025 * itself but there can be a gap between the two groups (although not
26 * recommended)
27 */
28
29enum goya_queue_id {
30 GOYA_QUEUE_ID_DMA_0 = 0,
Dotan Barak4fd2cb12019-08-12 10:23:33 +030031 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 Gabbay9494a8d2019-02-16 00:39:17 +020045 GOYA_QUEUE_ID_SIZE
46};
47
Tomer Tayare8960ca2019-07-01 13:59:45 +000048/*
49 * Engine Numbering
50 *
51 * Used in the "busy_engines_mask" field in `struct hl_info_hw_idle'
52 */
53
54enum 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 Zooraa957082019-03-24 10:15:44 +020072enum hl_device_status {
73 HL_DEVICE_STATUS_OPERATIONAL,
74 HL_DEVICE_STATUS_IN_RESET,
75 HL_DEVICE_STATUS_MALFUNCTION
76};
77
Oded Gabbayf388ec72019-07-16 08:55:04 +030078/* Opcode for management ioctl
79 *
Oded Gabbay75b3cb22019-08-28 17:32:04 +030080 * 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 Gabbayf388ec72019-07-16 08:55:04 +030089 * HL_INFO_DEVICE_STATUS - Retrieve the device's status. This opcode doesn't
90 * require an open context.
Oded Gabbay62c1e122019-10-10 15:48:59 +030091 * 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 Gabbaye9730762019-08-28 21:51:52 +030096 * HL_INFO_HW_EVENTS_AGGREGATE - Receive an array describing how many times each
97 * event occurred since the driver was loaded.
Oded Gabbay62c1e122019-10-10 15:48:59 +030098 * 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 Haimovski52c01b02019-11-03 16:26:44 +0200101 * 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 Tayar25e7aeb2020-03-31 22:46:36 +0300104 * HL_INFO_TIME_SYNC - Retrieve the device's time alongside the host's time
105 * for synchronization.
Oded Gabbayf388ec72019-07-16 08:55:04 +0300106 */
Oded Gabbay75b3cb22019-08-28 17:32:04 +0300107#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 Gabbaye9730762019-08-28 21:51:52 +0300113#define HL_INFO_HW_EVENTS_AGGREGATE 7
Oded Gabbay62c1e122019-10-10 15:48:59 +0300114#define HL_INFO_CLK_RATE 8
Moti Haimovski52c01b02019-11-03 16:26:44 +0200115#define HL_INFO_RESET_COUNT 9
Tomer Tayar25e7aeb2020-03-31 22:46:36 +0300116#define HL_INFO_TIME_SYNC 10
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200117
118#define HL_INFO_VERSION_MAX_LEN 128
Oded Gabbay91edbf22019-10-16 11:53:52 +0300119#define HL_INFO_CARD_NAME_MAX_LEN 16
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200120
121struct 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 Shpigelmanfca72fb2020-05-03 17:35:54 +0300128 __u32 module_id; /* For mezzanine cards in servers (From OCP spec.) */
129 __u32 reserved[2];
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200130 __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 Gabbay91edbf22019-10-16 11:53:52 +0300139 __u8 card_name[HL_INFO_CARD_NAME_MAX_LEN];
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200140};
141
142struct hl_info_dram_usage {
143 __u64 dram_free_mem;
144 __u64 ctx_dram_mem;
145};
146
147struct hl_info_hw_idle {
148 __u32 is_idle;
Tomer Tayare8960ca2019-07-01 13:59:45 +0000149 /*
150 * Bitmask of busy engines.
151 * Bits definition is according to `enum <chip>_enging_id'.
152 */
153 __u32 busy_engines_mask;
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200154};
155
Dalit Ben Zooraa957082019-03-24 10:15:44 +0200156struct hl_info_device_status {
157 __u32 status;
158 __u32 pad;
159};
160
Oded Gabbay75b3cb22019-08-28 17:32:04 +0300161struct hl_info_device_utilization {
162 __u32 utilization;
163 __u32 pad;
164};
165
Oded Gabbay62c1e122019-10-10 15:48:59 +0300166struct hl_info_clk_rate {
167 __u32 cur_clk_rate_mhz;
168 __u32 max_clk_rate_mhz;
169};
170
Moti Haimovski52c01b02019-11-03 16:26:44 +0200171struct hl_info_reset_count {
172 __u32 hard_reset_cnt;
173 __u32 soft_reset_cnt;
174};
175
Tomer Tayar25e7aeb2020-03-31 22:46:36 +0300176struct hl_info_time_sync {
177 __u64 device_time;
178 __u64 host_time;
179};
180
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200181struct 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 Gabbay75b3cb22019-08-28 17:32:04 +0300196 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 Gabbayd8dd7b02019-02-16 00:39:23 +0200205 __u32 pad;
206};
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200207
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200208/* 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 Gabbay39b42512020-04-17 12:12:13 +0300213/* 2MB minus 32 bytes for 2xMSG_PROT */
214#define HL_MAX_CB_SIZE (0x200000 - 32)
Oded Gabbay5d101252019-11-10 16:08:26 +0200215
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200216struct 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 Gabbay5d101252019-11-10 16:08:26 +0200221 /* 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 Gabbay541664d32019-02-28 11:55:44 +0200223 */
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200224 __u32 cb_size;
225 /* Context ID - Currently not in use */
226 __u32 ctx_id;
227 __u32 pad;
228};
229
230struct hl_cb_out {
231 /* Handle of CB */
232 __u64 cb_handle;
233};
234
235union hl_cb_args {
236 struct hl_cb_in in;
237 struct hl_cb_out out;
238};
239
240/*
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200241 * This structure size must always be fixed to 64-bytes for backward
242 * compatibility
243 */
244struct hl_cs_chunk {
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300245 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 Gabbayeff6f4a2019-02-16 00:39:21 +0200265 /* Index of queue to put the CB on */
266 __u32 queue_index;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300267
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 Gabbayeff6f4a2019-02-16 00:39:21 +0200281 /* HL_CS_CHUNK_FLAGS_* */
282 __u32 cs_chunk_flags;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300283
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200284 /* Align structure to 64 bytes */
285 __u32 pad[11];
286};
287
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300288/* SIGNAL and WAIT flags are mutually exclusive */
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200289#define HL_CS_FLAGS_FORCE_RESTORE 0x1
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300290#define HL_CS_FLAGS_SIGNAL 0x2
291#define HL_CS_FLAGS_WAIT 0x4
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200292
293#define HL_CS_STATUS_SUCCESS 0
294
Oded Gabbay5d101252019-11-10 16:08:26 +0200295#define HL_MAX_JOBS_PER_CS 512
296
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200297struct hl_cs_in {
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300298
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200299 /* this holds address of array of hl_cs_chunk for restore phase */
300 __u64 chunks_restore;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300301
302 /* holds address of array of hl_cs_chunk for execution phase */
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200303 __u64 chunks_execute;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300304
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200305 /* this holds address of array of hl_cs_chunk for store phase -
306 * Currently not in use
307 */
308 __u64 chunks_store;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300309
Oded Gabbay5d101252019-11-10 16:08:26 +0200310 /* Number of chunks in restore phase array. Maximum number is
311 * HL_MAX_JOBS_PER_CS
312 */
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200313 __u32 num_chunks_restore;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300314
Oded Gabbay5d101252019-11-10 16:08:26 +0200315 /* Number of chunks in execution array. Maximum number is
316 * HL_MAX_JOBS_PER_CS
317 */
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200318 __u32 num_chunks_execute;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300319
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200320 /* Number of chunks in restore phase array - Currently not in use */
321 __u32 num_chunks_store;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300322
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200323 /* HL_CS_FLAGS_* */
324 __u32 cs_flags;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300325
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200326 /* Context ID - Currently not in use */
327 __u32 ctx_id;
328};
329
330struct hl_cs_out {
Oded Gabbaye1266002019-03-07 14:20:05 +0200331 /*
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 Gabbayeff6f4a2019-02-16 00:39:21 +0200335 __u64 seq;
336 /* HL_CS_STATUS_* */
337 __u32 status;
338 __u32 pad;
339};
340
341union hl_cs_args {
342 struct hl_cs_in in;
343 struct hl_cs_out out;
344};
345
346struct 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
362struct hl_wait_cs_out {
363 /* HL_WAIT_CS_STATUS_* */
364 __u32 status;
365 __u32 pad;
366};
367
368union hl_wait_cs_args {
369 struct hl_wait_cs_in in;
370 struct hl_wait_cs_out out;
371};
372
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200373/* 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
387struct hl_mem_in {
388 union {
389 /* HL_MEM_OP_ALLOC- allocate device memory */
390 struct {
391 /* Size to alloc */
Oded Gabbay230afe72019-02-27 00:19:18 +0200392 __u64 mem_size;
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200393 } 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 Gabbay4c172bb2019-08-30 16:59:33 +0300405 * 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 Shpigelman0feaf862019-02-16 00:39:22 +0200408 * returned address of the IOCTL to make sure he got
Oded Gabbay4c172bb2019-08-30 16:59:33 +0300409 * the hint address. Passing 0 here means that the
410 * driver will choose the address itself.
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200411 */
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 Gabbay4c172bb2019-08-30 16:59:33 +0300423 * 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 Shpigelman0feaf862019-02-16 00:39:22 +0200426 * returned address of the IOCTL to make sure he got
Oded Gabbay4c172bb2019-08-30 16:59:33 +0300427 * the hint address. Passing 0 here means that the
428 * driver will choose the address itself.
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200429 */
430 __u64 hint_addr;
431 /* Size of allocated host memory */
Oded Gabbay230afe72019-02-27 00:19:18 +0200432 __u64 mem_size;
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200433 } 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
451struct 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
468union hl_mem_args {
469 struct hl_mem_in in;
470 struct hl_mem_out out;
471};
472
Omer Shpigelman315bc052019-04-01 22:31:22 +0300473#define HL_DEBUG_MAX_AUX_VALUES 10
474
475struct 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
487struct 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
499struct 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
511struct hl_debug_params_bmon {
Oded Gabbayd6911712019-04-21 16:20:46 +0300512 /* 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 Shpigelman315bc052019-04-01 22:31:22 +0300518
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
528struct 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 Tayar413cf572019-08-27 16:14:18 +0000549/* Opcode for timestamp (deprecated) */
Omer Shpigelman315bc052019-04-01 22:31:22 +0300550#define HL_DEBUG_OP_TIMESTAMP 6
Oded Gabbay2add64e2019-05-04 16:30:00 +0300551/* 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 Shpigelman315bc052019-04-01 22:31:22 +0300555
556struct 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 Gabbayeff6f4a2019-02-16 00:39:21 +0200581/*
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200582 * 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 Gabbaybe5d9262019-02-16 00:39:15 +0200599 * 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 Gabbayeff6f4a2019-02-16 00:39:21 +0200614/*
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 Gabbay90027292019-04-03 09:51:04 +0300622 * 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 Gabbayeff6f4a2019-02-16 00:39:21 +0200628 * 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 Gabbay541664d32019-02-28 11:55:44 +0200633 * 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 Shpigelmanf9e5f292020-05-07 13:41:16 +0300636 * on either the device SRAM/DRAM or the host, and give the device address of
637 * that buffer to the CS ioctl.
Oded Gabbay541664d32019-02-28 11:55:44 +0200638 *
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200639 * 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 Gabbay90027292019-04-03 09:51:04 +0300644 * Upon successful enqueue, the IOCTL returns a sequence number which the user
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200645 * 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 Shpigelmanf9e5f292020-05-07 13:41:16 +0300649 * actually finished executing.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200650 *
Oded Gabbay90027292019-04-03 09:51:04 +0300651 * 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 Gabbayeff6f4a2019-02-16 00:39:21 +0200656 */
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 Tayarf4356142019-10-02 13:53:52 +0000665 * inside the kernel until the CS has finished or until the user-requested
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200666 * 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 Shpigelman0feaf862019-02-16 00:39:22 +0200692/*
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 Shpigelman315bc052019-04-01 22:31:22 +0300710/*
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 Gabbay2add64e2019-05-04 16:30:00 +0300716 * 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 Shpigelman315bc052019-04-01 22:31:22 +0300732 *
733 */
734#define HL_IOCTL_DEBUG \
735 _IOWR('H', 0x06, struct hl_debug_args)
736
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200737#define HL_COMMAND_START 0x01
Omer Shpigelman315bc052019-04-01 22:31:22 +0300738#define HL_COMMAND_END 0x07
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200739
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200740#endif /* HABANALABS_H_ */