1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
3 * Copyright 2016-2020 HabanaLabs, Ltd.
11 #include <linux/types.h>
12 #include <linux/ioctl.h>
15 * Defines that are asic-specific but constitutes as ABI between kernel driver
18 #define GOYA_KMD_SRAM_RESERVED_SIZE_FROM_START 0x8000 /* 32KB */
19 #define GAUDI_DRIVER_SRAM_RESERVED_SIZE_FROM_START 0x80 /* 128 bytes */
21 #define GAUDI_FIRST_AVAILABLE_W_S_SYNC_OBJECT 48
22 #define GAUDI_FIRST_AVAILABLE_W_S_MONITOR 24
24 * Goya queue Numbering
26 * The external queues (PCI DMA channels) MUST be before the internal queues
27 * and each group (PCI DMA channels and internal) must be contiguous inside
28 * itself but there can be a gap between the two groups (although not
33 GOYA_QUEUE_ID_DMA_0 = 0,
34 GOYA_QUEUE_ID_DMA_1 = 1,
35 GOYA_QUEUE_ID_DMA_2 = 2,
36 GOYA_QUEUE_ID_DMA_3 = 3,
37 GOYA_QUEUE_ID_DMA_4 = 4,
38 GOYA_QUEUE_ID_CPU_PQ = 5,
39 GOYA_QUEUE_ID_MME = 6, /* Internal queues start here */
40 GOYA_QUEUE_ID_TPC0 = 7,
41 GOYA_QUEUE_ID_TPC1 = 8,
42 GOYA_QUEUE_ID_TPC2 = 9,
43 GOYA_QUEUE_ID_TPC3 = 10,
44 GOYA_QUEUE_ID_TPC4 = 11,
45 GOYA_QUEUE_ID_TPC5 = 12,
46 GOYA_QUEUE_ID_TPC6 = 13,
47 GOYA_QUEUE_ID_TPC7 = 14,
52 * Gaudi queue Numbering
53 * External queues (PCI DMA channels) are DMA_0_*, DMA_1_* and DMA_5_*.
54 * Except one CPU queue, all the rest are internal queues.
58 GAUDI_QUEUE_ID_DMA_0_0 = 0, /* external */
59 GAUDI_QUEUE_ID_DMA_0_1 = 1, /* external */
60 GAUDI_QUEUE_ID_DMA_0_2 = 2, /* external */
61 GAUDI_QUEUE_ID_DMA_0_3 = 3, /* external */
62 GAUDI_QUEUE_ID_DMA_1_0 = 4, /* external */
63 GAUDI_QUEUE_ID_DMA_1_1 = 5, /* external */
64 GAUDI_QUEUE_ID_DMA_1_2 = 6, /* external */
65 GAUDI_QUEUE_ID_DMA_1_3 = 7, /* external */
66 GAUDI_QUEUE_ID_CPU_PQ = 8, /* CPU */
67 GAUDI_QUEUE_ID_DMA_2_0 = 9, /* internal */
68 GAUDI_QUEUE_ID_DMA_2_1 = 10, /* internal */
69 GAUDI_QUEUE_ID_DMA_2_2 = 11, /* internal */
70 GAUDI_QUEUE_ID_DMA_2_3 = 12, /* internal */
71 GAUDI_QUEUE_ID_DMA_3_0 = 13, /* internal */
72 GAUDI_QUEUE_ID_DMA_3_1 = 14, /* internal */
73 GAUDI_QUEUE_ID_DMA_3_2 = 15, /* internal */
74 GAUDI_QUEUE_ID_DMA_3_3 = 16, /* internal */
75 GAUDI_QUEUE_ID_DMA_4_0 = 17, /* internal */
76 GAUDI_QUEUE_ID_DMA_4_1 = 18, /* internal */
77 GAUDI_QUEUE_ID_DMA_4_2 = 19, /* internal */
78 GAUDI_QUEUE_ID_DMA_4_3 = 20, /* internal */
79 GAUDI_QUEUE_ID_DMA_5_0 = 21, /* external */
80 GAUDI_QUEUE_ID_DMA_5_1 = 22, /* external */
81 GAUDI_QUEUE_ID_DMA_5_2 = 23, /* external */
82 GAUDI_QUEUE_ID_DMA_5_3 = 24, /* external */
83 GAUDI_QUEUE_ID_DMA_6_0 = 25, /* internal */
84 GAUDI_QUEUE_ID_DMA_6_1 = 26, /* internal */
85 GAUDI_QUEUE_ID_DMA_6_2 = 27, /* internal */
86 GAUDI_QUEUE_ID_DMA_6_3 = 28, /* internal */
87 GAUDI_QUEUE_ID_DMA_7_0 = 29, /* internal */
88 GAUDI_QUEUE_ID_DMA_7_1 = 30, /* internal */
89 GAUDI_QUEUE_ID_DMA_7_2 = 31, /* internal */
90 GAUDI_QUEUE_ID_DMA_7_3 = 32, /* internal */
91 GAUDI_QUEUE_ID_MME_0_0 = 33, /* internal */
92 GAUDI_QUEUE_ID_MME_0_1 = 34, /* internal */
93 GAUDI_QUEUE_ID_MME_0_2 = 35, /* internal */
94 GAUDI_QUEUE_ID_MME_0_3 = 36, /* internal */
95 GAUDI_QUEUE_ID_MME_1_0 = 37, /* internal */
96 GAUDI_QUEUE_ID_MME_1_1 = 38, /* internal */
97 GAUDI_QUEUE_ID_MME_1_2 = 39, /* internal */
98 GAUDI_QUEUE_ID_MME_1_3 = 40, /* internal */
99 GAUDI_QUEUE_ID_TPC_0_0 = 41, /* internal */
100 GAUDI_QUEUE_ID_TPC_0_1 = 42, /* internal */
101 GAUDI_QUEUE_ID_TPC_0_2 = 43, /* internal */
102 GAUDI_QUEUE_ID_TPC_0_3 = 44, /* internal */
103 GAUDI_QUEUE_ID_TPC_1_0 = 45, /* internal */
104 GAUDI_QUEUE_ID_TPC_1_1 = 46, /* internal */
105 GAUDI_QUEUE_ID_TPC_1_2 = 47, /* internal */
106 GAUDI_QUEUE_ID_TPC_1_3 = 48, /* internal */
107 GAUDI_QUEUE_ID_TPC_2_0 = 49, /* internal */
108 GAUDI_QUEUE_ID_TPC_2_1 = 50, /* internal */
109 GAUDI_QUEUE_ID_TPC_2_2 = 51, /* internal */
110 GAUDI_QUEUE_ID_TPC_2_3 = 52, /* internal */
111 GAUDI_QUEUE_ID_TPC_3_0 = 53, /* internal */
112 GAUDI_QUEUE_ID_TPC_3_1 = 54, /* internal */
113 GAUDI_QUEUE_ID_TPC_3_2 = 55, /* internal */
114 GAUDI_QUEUE_ID_TPC_3_3 = 56, /* internal */
115 GAUDI_QUEUE_ID_TPC_4_0 = 57, /* internal */
116 GAUDI_QUEUE_ID_TPC_4_1 = 58, /* internal */
117 GAUDI_QUEUE_ID_TPC_4_2 = 59, /* internal */
118 GAUDI_QUEUE_ID_TPC_4_3 = 60, /* internal */
119 GAUDI_QUEUE_ID_TPC_5_0 = 61, /* internal */
120 GAUDI_QUEUE_ID_TPC_5_1 = 62, /* internal */
121 GAUDI_QUEUE_ID_TPC_5_2 = 63, /* internal */
122 GAUDI_QUEUE_ID_TPC_5_3 = 64, /* internal */
123 GAUDI_QUEUE_ID_TPC_6_0 = 65, /* internal */
124 GAUDI_QUEUE_ID_TPC_6_1 = 66, /* internal */
125 GAUDI_QUEUE_ID_TPC_6_2 = 67, /* internal */
126 GAUDI_QUEUE_ID_TPC_6_3 = 68, /* internal */
127 GAUDI_QUEUE_ID_TPC_7_0 = 69, /* internal */
128 GAUDI_QUEUE_ID_TPC_7_1 = 70, /* internal */
129 GAUDI_QUEUE_ID_TPC_7_2 = 71, /* internal */
130 GAUDI_QUEUE_ID_TPC_7_3 = 72, /* internal */
131 GAUDI_QUEUE_ID_NIC_0_0 = 73, /* internal */
132 GAUDI_QUEUE_ID_NIC_0_1 = 74, /* internal */
133 GAUDI_QUEUE_ID_NIC_0_2 = 75, /* internal */
134 GAUDI_QUEUE_ID_NIC_0_3 = 76, /* internal */
135 GAUDI_QUEUE_ID_NIC_1_0 = 77, /* internal */
136 GAUDI_QUEUE_ID_NIC_1_1 = 78, /* internal */
137 GAUDI_QUEUE_ID_NIC_1_2 = 79, /* internal */
138 GAUDI_QUEUE_ID_NIC_1_3 = 80, /* internal */
139 GAUDI_QUEUE_ID_NIC_2_0 = 81, /* internal */
140 GAUDI_QUEUE_ID_NIC_2_1 = 82, /* internal */
141 GAUDI_QUEUE_ID_NIC_2_2 = 83, /* internal */
142 GAUDI_QUEUE_ID_NIC_2_3 = 84, /* internal */
143 GAUDI_QUEUE_ID_NIC_3_0 = 85, /* internal */
144 GAUDI_QUEUE_ID_NIC_3_1 = 86, /* internal */
145 GAUDI_QUEUE_ID_NIC_3_2 = 87, /* internal */
146 GAUDI_QUEUE_ID_NIC_3_3 = 88, /* internal */
147 GAUDI_QUEUE_ID_NIC_4_0 = 89, /* internal */
148 GAUDI_QUEUE_ID_NIC_4_1 = 90, /* internal */
149 GAUDI_QUEUE_ID_NIC_4_2 = 91, /* internal */
150 GAUDI_QUEUE_ID_NIC_4_3 = 92, /* internal */
151 GAUDI_QUEUE_ID_NIC_5_0 = 93, /* internal */
152 GAUDI_QUEUE_ID_NIC_5_1 = 94, /* internal */
153 GAUDI_QUEUE_ID_NIC_5_2 = 95, /* internal */
154 GAUDI_QUEUE_ID_NIC_5_3 = 96, /* internal */
155 GAUDI_QUEUE_ID_NIC_6_0 = 97, /* internal */
156 GAUDI_QUEUE_ID_NIC_6_1 = 98, /* internal */
157 GAUDI_QUEUE_ID_NIC_6_2 = 99, /* internal */
158 GAUDI_QUEUE_ID_NIC_6_3 = 100, /* internal */
159 GAUDI_QUEUE_ID_NIC_7_0 = 101, /* internal */
160 GAUDI_QUEUE_ID_NIC_7_1 = 102, /* internal */
161 GAUDI_QUEUE_ID_NIC_7_2 = 103, /* internal */
162 GAUDI_QUEUE_ID_NIC_7_3 = 104, /* internal */
163 GAUDI_QUEUE_ID_NIC_8_0 = 105, /* internal */
164 GAUDI_QUEUE_ID_NIC_8_1 = 106, /* internal */
165 GAUDI_QUEUE_ID_NIC_8_2 = 107, /* internal */
166 GAUDI_QUEUE_ID_NIC_8_3 = 108, /* internal */
167 GAUDI_QUEUE_ID_NIC_9_0 = 109, /* internal */
168 GAUDI_QUEUE_ID_NIC_9_1 = 110, /* internal */
169 GAUDI_QUEUE_ID_NIC_9_2 = 111, /* internal */
170 GAUDI_QUEUE_ID_NIC_9_3 = 112, /* internal */
177 * Used in the "busy_engines_mask" field in `struct hl_info_hw_idle'
180 enum goya_engine_id {
181 GOYA_ENGINE_ID_DMA_0 = 0,
182 GOYA_ENGINE_ID_DMA_1,
183 GOYA_ENGINE_ID_DMA_2,
184 GOYA_ENGINE_ID_DMA_3,
185 GOYA_ENGINE_ID_DMA_4,
186 GOYA_ENGINE_ID_MME_0,
187 GOYA_ENGINE_ID_TPC_0,
188 GOYA_ENGINE_ID_TPC_1,
189 GOYA_ENGINE_ID_TPC_2,
190 GOYA_ENGINE_ID_TPC_3,
191 GOYA_ENGINE_ID_TPC_4,
192 GOYA_ENGINE_ID_TPC_5,
193 GOYA_ENGINE_ID_TPC_6,
194 GOYA_ENGINE_ID_TPC_7,
198 enum gaudi_engine_id {
199 GAUDI_ENGINE_ID_DMA_0 = 0,
200 GAUDI_ENGINE_ID_DMA_1,
201 GAUDI_ENGINE_ID_DMA_2,
202 GAUDI_ENGINE_ID_DMA_3,
203 GAUDI_ENGINE_ID_DMA_4,
204 GAUDI_ENGINE_ID_DMA_5,
205 GAUDI_ENGINE_ID_DMA_6,
206 GAUDI_ENGINE_ID_DMA_7,
207 GAUDI_ENGINE_ID_MME_0,
208 GAUDI_ENGINE_ID_MME_1,
209 GAUDI_ENGINE_ID_MME_2,
210 GAUDI_ENGINE_ID_MME_3,
211 GAUDI_ENGINE_ID_TPC_0,
212 GAUDI_ENGINE_ID_TPC_1,
213 GAUDI_ENGINE_ID_TPC_2,
214 GAUDI_ENGINE_ID_TPC_3,
215 GAUDI_ENGINE_ID_TPC_4,
216 GAUDI_ENGINE_ID_TPC_5,
217 GAUDI_ENGINE_ID_TPC_6,
218 GAUDI_ENGINE_ID_TPC_7,
219 GAUDI_ENGINE_ID_NIC_0,
220 GAUDI_ENGINE_ID_NIC_1,
221 GAUDI_ENGINE_ID_NIC_2,
222 GAUDI_ENGINE_ID_NIC_3,
223 GAUDI_ENGINE_ID_NIC_4,
224 GAUDI_ENGINE_ID_NIC_5,
225 GAUDI_ENGINE_ID_NIC_6,
226 GAUDI_ENGINE_ID_NIC_7,
227 GAUDI_ENGINE_ID_NIC_8,
228 GAUDI_ENGINE_ID_NIC_9,
232 enum hl_device_status {
233 HL_DEVICE_STATUS_OPERATIONAL,
234 HL_DEVICE_STATUS_IN_RESET,
235 HL_DEVICE_STATUS_MALFUNCTION
238 /* Opcode for management ioctl
240 * HW_IP_INFO - Receive information about different IP blocks in the
242 * HL_INFO_HW_EVENTS - Receive an array describing how many times each event
243 * occurred since the last hard reset.
244 * HL_INFO_DRAM_USAGE - Retrieve the dram usage inside the device and of the
245 * specific context. This is relevant only for devices
246 * where the dram is managed by the kernel driver
247 * HL_INFO_HW_IDLE - Retrieve information about the idle status of each
249 * HL_INFO_DEVICE_STATUS - Retrieve the device's status. This opcode doesn't
250 * require an open context.
251 * HL_INFO_DEVICE_UTILIZATION - Retrieve the total utilization of the device
252 * over the last period specified by the user.
253 * The period can be between 100ms to 1s, in
254 * resolution of 100ms. The return value is a
255 * percentage of the utilization rate.
256 * HL_INFO_HW_EVENTS_AGGREGATE - Receive an array describing how many times each
257 * event occurred since the driver was loaded.
258 * HL_INFO_CLK_RATE - Retrieve the current and maximum clock rate
259 * of the device in MHz. The maximum clock rate is
260 * configurable via sysfs parameter
261 * HL_INFO_RESET_COUNT - Retrieve the counts of the soft and hard reset
262 * operations performed on the device since the last
263 * time the driver was loaded.
264 * HL_INFO_TIME_SYNC - Retrieve the device's time alongside the host's time
265 * for synchronization.
266 * HL_INFO_CS_COUNTERS - Retrieve command submission counters
268 #define HL_INFO_HW_IP_INFO 0
269 #define HL_INFO_HW_EVENTS 1
270 #define HL_INFO_DRAM_USAGE 2
271 #define HL_INFO_HW_IDLE 3
272 #define HL_INFO_DEVICE_STATUS 4
273 #define HL_INFO_DEVICE_UTILIZATION 6
274 #define HL_INFO_HW_EVENTS_AGGREGATE 7
275 #define HL_INFO_CLK_RATE 8
276 #define HL_INFO_RESET_COUNT 9
277 #define HL_INFO_TIME_SYNC 10
278 #define HL_INFO_CS_COUNTERS 11
280 #define HL_INFO_VERSION_MAX_LEN 128
281 #define HL_INFO_CARD_NAME_MAX_LEN 16
283 struct hl_info_hw_ip_info {
284 __u64 sram_base_address;
285 __u64 dram_base_address;
289 __u32 device_id; /* PCI Device ID */
290 __u32 module_id; /* For mezzanine cards in servers (From OCP spec.) */
292 __u32 armcp_cpld_version;
293 __u32 psoc_pci_pll_nr;
294 __u32 psoc_pci_pll_nf;
295 __u32 psoc_pci_pll_od;
296 __u32 psoc_pci_pll_div_factor;
297 __u8 tpc_enabled_mask;
300 __u8 armcp_version[HL_INFO_VERSION_MAX_LEN];
301 __u8 card_name[HL_INFO_CARD_NAME_MAX_LEN];
304 struct hl_info_dram_usage {
309 struct hl_info_hw_idle {
312 * Bitmask of busy engines.
313 * Bits definition is according to `enum <chip>_enging_id'.
315 __u32 busy_engines_mask;
318 struct hl_info_device_status {
323 struct hl_info_device_utilization {
328 struct hl_info_clk_rate {
329 __u32 cur_clk_rate_mhz;
330 __u32 max_clk_rate_mhz;
333 struct hl_info_reset_count {
334 __u32 hard_reset_cnt;
335 __u32 soft_reset_cnt;
338 struct hl_info_time_sync {
344 * struct hl_info_cs_counters - command submission counters
345 * @out_of_mem_drop_cnt: dropped due to memory allocation issue
346 * @parsing_drop_cnt: dropped due to error in packet parsing
347 * @queue_full_drop_cnt: dropped due to queue full
348 * @device_in_reset_drop_cnt: dropped due to device in reset
350 struct hl_cs_counters {
351 __u64 out_of_mem_drop_cnt;
352 __u64 parsing_drop_cnt;
353 __u64 queue_full_drop_cnt;
354 __u64 device_in_reset_drop_cnt;
357 struct hl_info_cs_counters {
358 struct hl_cs_counters cs_counters;
359 struct hl_cs_counters ctx_cs_counters;
362 struct hl_info_args {
363 /* Location of relevant struct in userspace */
364 __u64 return_pointer;
366 * The size of the return value. Just like "size" in "snprintf",
367 * it limits how many bytes the kernel can write
369 * For hw_events array, the size should be
370 * hl_info_hw_ip_info.num_of_events * sizeof(__u32)
378 /* Context ID - Currently not in use */
380 /* Period value for utilization rate (100ms - 1000ms, in 100ms
389 /* Opcode to create a new command buffer */
390 #define HL_CB_OP_CREATE 0
391 /* Opcode to destroy previously created command buffer */
392 #define HL_CB_OP_DESTROY 1
394 /* 2MB minus 32 bytes for 2xMSG_PROT */
395 #define HL_MAX_CB_SIZE (0x200000 - 32)
398 /* Handle of CB or 0 if we want to create one */
402 /* Size of CB. Maximum size is HL_MAX_CB_SIZE. The minimum size that
403 * will be allocated, regardless of this parameter's value, is PAGE_SIZE
406 /* Context ID - Currently not in use */
418 struct hl_cb_out out;
422 * This structure size must always be fixed to 64-bytes for backward
427 /* For external queue, this represents a Handle of CB on the
429 * For internal queue in Goya, this represents an SRAM or
430 * a DRAM address of the internal CB. In Gaudi, this might also
431 * represent a mapped host address of the CB.
433 * A mapped host address is in the device address space, after
434 * a host address was mapped by the device MMU.
438 /* Relevant only when HL_CS_FLAGS_WAIT is set.
439 * This holds address of array of u64 values that contain
440 * signal CS sequence numbers. The wait described by this job
441 * will listen on all those signals (wait event per signal)
443 __u64 signal_seq_arr;
446 /* Index of queue to put the CB on */
451 * Size of command buffer with valid packets
452 * Can be smaller then actual CB size
456 /* Relevant only when HL_CS_FLAGS_WAIT is set.
457 * Number of entries in signal_seq_arr
459 __u32 num_signal_seq_arr;
462 /* HL_CS_CHUNK_FLAGS_* */
463 __u32 cs_chunk_flags;
465 /* Align structure to 64 bytes */
469 /* SIGNAL and WAIT flags are mutually exclusive */
470 #define HL_CS_FLAGS_FORCE_RESTORE 0x1
471 #define HL_CS_FLAGS_SIGNAL 0x2
472 #define HL_CS_FLAGS_WAIT 0x4
474 #define HL_CS_STATUS_SUCCESS 0
476 #define HL_MAX_JOBS_PER_CS 512
480 /* this holds address of array of hl_cs_chunk for restore phase */
481 __u64 chunks_restore;
483 /* holds address of array of hl_cs_chunk for execution phase */
484 __u64 chunks_execute;
486 /* this holds address of array of hl_cs_chunk for store phase -
487 * Currently not in use
491 /* Number of chunks in restore phase array. Maximum number is
494 __u32 num_chunks_restore;
496 /* Number of chunks in execution array. Maximum number is
499 __u32 num_chunks_execute;
501 /* Number of chunks in restore phase array - Currently not in use */
502 __u32 num_chunks_store;
507 /* Context ID - Currently not in use */
513 * seq holds the sequence number of the CS to pass to wait ioctl. All
514 * values are valid except for 0 and ULLONG_MAX
524 struct hl_cs_out out;
527 struct hl_wait_cs_in {
528 /* Command submission sequence number */
530 /* Absolute timeout to wait in microseconds */
532 /* Context ID - Currently not in use */
537 #define HL_WAIT_CS_STATUS_COMPLETED 0
538 #define HL_WAIT_CS_STATUS_BUSY 1
539 #define HL_WAIT_CS_STATUS_TIMEDOUT 2
540 #define HL_WAIT_CS_STATUS_ABORTED 3
541 #define HL_WAIT_CS_STATUS_INTERRUPTED 4
543 struct hl_wait_cs_out {
544 /* HL_WAIT_CS_STATUS_* */
549 union hl_wait_cs_args {
550 struct hl_wait_cs_in in;
551 struct hl_wait_cs_out out;
554 /* Opcode to allocate device memory */
555 #define HL_MEM_OP_ALLOC 0
556 /* Opcode to free previously allocated device memory */
557 #define HL_MEM_OP_FREE 1
558 /* Opcode to map host and device memory */
559 #define HL_MEM_OP_MAP 2
560 /* Opcode to unmap previously mapped host and device memory */
561 #define HL_MEM_OP_UNMAP 3
564 #define HL_MEM_CONTIGUOUS 0x1
565 #define HL_MEM_SHARED 0x2
566 #define HL_MEM_USERPTR 0x4
570 /* HL_MEM_OP_ALLOC- allocate device memory */
576 /* HL_MEM_OP_FREE - free device memory */
578 /* Handle returned from HL_MEM_OP_ALLOC */
582 /* HL_MEM_OP_MAP - map device memory */
585 * Requested virtual address of mapped memory.
586 * The driver will try to map the requested region to
587 * this hint address, as long as the address is valid
588 * and not already mapped. The user should check the
589 * returned address of the IOCTL to make sure he got
590 * the hint address. Passing 0 here means that the
591 * driver will choose the address itself.
594 /* Handle returned from HL_MEM_OP_ALLOC */
598 /* HL_MEM_OP_MAP - map host memory */
600 /* Address of allocated host memory */
601 __u64 host_virt_addr;
603 * Requested virtual address of mapped memory.
604 * The driver will try to map the requested region to
605 * this hint address, as long as the address is valid
606 * and not already mapped. The user should check the
607 * returned address of the IOCTL to make sure he got
608 * the hint address. Passing 0 here means that the
609 * driver will choose the address itself.
612 /* Size of allocated host memory */
616 /* HL_MEM_OP_UNMAP - unmap host memory */
618 /* Virtual address returned from HL_MEM_OP_MAP */
619 __u64 device_virt_addr;
627 /* Context ID - Currently not in use */
635 * Used for HL_MEM_OP_MAP as the virtual address that was
636 * assigned in the device VA space.
637 * A value of 0 means the requested operation failed.
639 __u64 device_virt_addr;
642 * Used for HL_MEM_OP_ALLOC. This is the assigned
643 * handle for the allocated memory
651 struct hl_mem_out out;
654 #define HL_DEBUG_MAX_AUX_VALUES 10
656 struct hl_debug_params_etr {
657 /* Address in memory to allocate buffer */
658 __u64 buffer_address;
660 /* Size of buffer to allocate */
663 /* Sink operation mode: SW fifo, HW fifo, Circular buffer */
668 struct hl_debug_params_etf {
669 /* Address in memory to allocate buffer */
670 __u64 buffer_address;
672 /* Size of buffer to allocate */
675 /* Sink operation mode: SW fifo, HW fifo, Circular buffer */
680 struct hl_debug_params_stm {
681 /* Two bit masks for HW event and Stimulus Port */
685 /* Trace source ID */
688 /* Frequency for the timestamp register */
692 struct hl_debug_params_bmon {
693 /* Two address ranges that the user can request to filter */
700 /* Capture window configuration */
704 /* Trace source ID */
709 struct hl_debug_params_spmu {
710 /* Event types selection */
711 __u64 event_types[HL_DEBUG_MAX_AUX_VALUES];
713 /* Number of event types selection */
714 __u32 event_types_num;
718 /* Opcode for ETR component */
719 #define HL_DEBUG_OP_ETR 0
720 /* Opcode for ETF component */
721 #define HL_DEBUG_OP_ETF 1
722 /* Opcode for STM component */
723 #define HL_DEBUG_OP_STM 2
724 /* Opcode for FUNNEL component */
725 #define HL_DEBUG_OP_FUNNEL 3
726 /* Opcode for BMON component */
727 #define HL_DEBUG_OP_BMON 4
728 /* Opcode for SPMU component */
729 #define HL_DEBUG_OP_SPMU 5
730 /* Opcode for timestamp (deprecated) */
731 #define HL_DEBUG_OP_TIMESTAMP 6
732 /* Opcode for setting the device into or out of debug mode. The enable
733 * variable should be 1 for enabling debug mode and 0 for disabling it
735 #define HL_DEBUG_OP_SET_MODE 7
737 struct hl_debug_args {
739 * Pointer to user input structure.
740 * This field is relevant to specific opcodes.
743 /* Pointer to user output structure */
745 /* Size of user input structure */
747 /* Size of user output structure */
752 * Register index in the component, taken from the debug_regs_index enum
753 * in the various ASIC header files
758 /* Context ID - Currently not in use */
763 * Various information operations such as:
764 * - H/W IP information
765 * - Current dram usage
767 * The user calls this IOCTL with an opcode that describes the required
768 * information. The user should supply a pointer to a user-allocated memory
769 * chunk, which will be filled by the driver with the requested information.
771 * The user supplies the maximum amount of size to copy into the user's memory,
772 * in order to prevent data corruption in case of differences between the
773 * definitions of structures in kernel and userspace, e.g. in case of old
774 * userspace and new kernel driver
776 #define HL_IOCTL_INFO \
777 _IOWR('H', 0x01, struct hl_info_args)
781 * - Request a Command Buffer
782 * - Destroy a Command Buffer
784 * The command buffers are memory blocks that reside in DMA-able address
785 * space and are physically contiguous so they can be accessed by the device
786 * directly. They are allocated using the coherent DMA API.
788 * When creating a new CB, the IOCTL returns a handle of it, and the user-space
789 * process needs to use that handle to mmap the buffer so it can access them.
792 #define HL_IOCTL_CB \
793 _IOWR('H', 0x02, union hl_cb_args)
798 * To submit work to the device, the user need to call this IOCTL with a set
799 * of JOBS. That set of JOBS constitutes a CS object.
800 * Each JOB will be enqueued on a specific queue, according to the user's input.
801 * There can be more then one JOB per queue.
803 * The CS IOCTL will receive three sets of JOBS. One set is for "restore" phase,
804 * a second set is for "execution" phase and a third set is for "store" phase.
805 * The JOBS on the "restore" phase are enqueued only after context-switch
806 * (or if its the first CS for this context). The user can also order the
807 * driver to run the "restore" phase explicitly
809 * There are two types of queues - external and internal. External queues
810 * are DMA queues which transfer data from/to the Host. All other queues are
811 * internal. The driver will get completion notifications from the device only
812 * on JOBS which are enqueued in the external queues.
814 * For jobs on external queues, the user needs to create command buffers
815 * through the CB ioctl and give the CB's handle to the CS ioctl. For jobs on
816 * internal queues, the user needs to prepare a "command buffer" with packets
817 * on either the device SRAM/DRAM or the host, and give the device address of
818 * that buffer to the CS ioctl.
820 * This IOCTL is asynchronous in regard to the actual execution of the CS. This
821 * means it returns immediately after ALL the JOBS were enqueued on their
822 * relevant queues. Therefore, the user mustn't assume the CS has been completed
823 * or has even started to execute.
825 * Upon successful enqueue, the IOCTL returns a sequence number which the user
826 * can use with the "Wait for CS" IOCTL to check whether the handle's CS
827 * external JOBS have been completed. Note that if the CS has internal JOBS
828 * which can execute AFTER the external JOBS have finished, the driver might
829 * report that the CS has finished executing BEFORE the internal JOBS have
830 * actually finished executing.
832 * Even though the sequence number increments per CS, the user can NOT
833 * automatically assume that if CS with sequence number N finished, then CS
834 * with sequence number N-1 also finished. The user can make this assumption if
835 * and only if CS N and CS N-1 are exactly the same (same CBs for the same
838 #define HL_IOCTL_CS \
839 _IOWR('H', 0x03, union hl_cs_args)
842 * Wait for Command Submission
844 * The user can call this IOCTL with a handle it received from the CS IOCTL
845 * to wait until the handle's CS has finished executing. The user will wait
846 * inside the kernel until the CS has finished or until the user-requested
847 * timeout has expired.
849 * The return value of the IOCTL is a standard Linux error code. The possible
852 * EINTR - Kernel waiting has been interrupted, e.g. due to OS signal
853 * that the user process received
854 * ETIMEDOUT - The CS has caused a timeout on the device
855 * EIO - The CS was aborted (usually because the device was reset)
856 * ENODEV - The device wants to do hard-reset (so user need to close FD)
858 * The driver also returns a custom define inside the IOCTL which can be:
860 * HL_WAIT_CS_STATUS_COMPLETED - The CS has been completed successfully (0)
861 * HL_WAIT_CS_STATUS_BUSY - The CS is still executing (0)
862 * HL_WAIT_CS_STATUS_TIMEDOUT - The CS has caused a timeout on the device
864 * HL_WAIT_CS_STATUS_ABORTED - The CS was aborted, usually because the
865 * device was reset (EIO)
866 * HL_WAIT_CS_STATUS_INTERRUPTED - Waiting for the CS was interrupted (EINTR)
870 #define HL_IOCTL_WAIT_CS \
871 _IOWR('H', 0x04, union hl_wait_cs_args)
875 * - Map host memory to device MMU
876 * - Unmap host memory from device MMU
878 * This IOCTL allows the user to map host memory to the device MMU
880 * For host memory, the IOCTL doesn't allocate memory. The user is supposed
881 * to allocate the memory in user-space (malloc/new). The driver pins the
882 * physical pages (up to the allowed limit by the OS), assigns a virtual
883 * address in the device VA space and initializes the device MMU.
885 * There is an option for the user to specify the requested virtual address.
888 #define HL_IOCTL_MEMORY \
889 _IOWR('H', 0x05, union hl_mem_args)
893 * - Enable/disable the ETR/ETF/FUNNEL/STM/BMON/SPMU debug traces
895 * This IOCTL allows the user to get debug traces from the chip.
897 * Before the user can send configuration requests of the various
898 * debug/profile engines, it needs to set the device into debug mode.
899 * This is because the debug/profile infrastructure is shared component in the
900 * device and we can't allow multiple users to access it at the same time.
902 * Once a user set the device into debug mode, the driver won't allow other
903 * users to "work" with the device, i.e. open a FD. If there are multiple users
904 * opened on the device, the driver won't allow any user to debug the device.
906 * For each configuration request, the user needs to provide the register index
907 * and essential data such as buffer address and size.
909 * Once the user has finished using the debug/profile engines, he should
910 * set the device into non-debug mode, i.e. disable debug mode.
912 * The driver can decide to "kick out" the user if he abuses this interface.
915 #define HL_IOCTL_DEBUG \
916 _IOWR('H', 0x06, struct hl_debug_args)
918 #define HL_COMMAND_START 0x01
919 #define HL_COMMAND_END 0x07
921 #endif /* HABANALABS_H_ */