Merge branch 'for-5.14' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
[linux-2.6-microblaze.git] / include / uapi / misc / habanalabs.h
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
2  *
3  * Copyright 2016-2020 HabanaLabs, Ltd.
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 #define GAUDI_DRIVER_SRAM_RESERVED_SIZE_FROM_START      0x80    /* 128 bytes */
20
21 /*
22  * 128 SOBs reserved for collective wait
23  * 16 SOBs reserved for sync stream
24  */
25 #define GAUDI_FIRST_AVAILABLE_W_S_SYNC_OBJECT           144
26
27 /*
28  * 64 monitors reserved for collective wait
29  * 8 monitors reserved for sync stream
30  */
31 #define GAUDI_FIRST_AVAILABLE_W_S_MONITOR               72
32
33 /*
34  * Goya queue Numbering
35  *
36  * The external queues (PCI DMA channels) MUST be before the internal queues
37  * and each group (PCI DMA channels and internal) must be contiguous inside
38  * itself but there can be a gap between the two groups (although not
39  * recommended)
40  */
41
42 enum goya_queue_id {
43         GOYA_QUEUE_ID_DMA_0 = 0,
44         GOYA_QUEUE_ID_DMA_1 = 1,
45         GOYA_QUEUE_ID_DMA_2 = 2,
46         GOYA_QUEUE_ID_DMA_3 = 3,
47         GOYA_QUEUE_ID_DMA_4 = 4,
48         GOYA_QUEUE_ID_CPU_PQ = 5,
49         GOYA_QUEUE_ID_MME = 6,  /* Internal queues start here */
50         GOYA_QUEUE_ID_TPC0 = 7,
51         GOYA_QUEUE_ID_TPC1 = 8,
52         GOYA_QUEUE_ID_TPC2 = 9,
53         GOYA_QUEUE_ID_TPC3 = 10,
54         GOYA_QUEUE_ID_TPC4 = 11,
55         GOYA_QUEUE_ID_TPC5 = 12,
56         GOYA_QUEUE_ID_TPC6 = 13,
57         GOYA_QUEUE_ID_TPC7 = 14,
58         GOYA_QUEUE_ID_SIZE
59 };
60
61 /*
62  * Gaudi queue Numbering
63  * External queues (PCI DMA channels) are DMA_0_*, DMA_1_* and DMA_5_*.
64  * Except one CPU queue, all the rest are internal queues.
65  */
66
67 enum gaudi_queue_id {
68         GAUDI_QUEUE_ID_DMA_0_0 = 0,     /* external */
69         GAUDI_QUEUE_ID_DMA_0_1 = 1,     /* external */
70         GAUDI_QUEUE_ID_DMA_0_2 = 2,     /* external */
71         GAUDI_QUEUE_ID_DMA_0_3 = 3,     /* external */
72         GAUDI_QUEUE_ID_DMA_1_0 = 4,     /* external */
73         GAUDI_QUEUE_ID_DMA_1_1 = 5,     /* external */
74         GAUDI_QUEUE_ID_DMA_1_2 = 6,     /* external */
75         GAUDI_QUEUE_ID_DMA_1_3 = 7,     /* external */
76         GAUDI_QUEUE_ID_CPU_PQ = 8,      /* CPU */
77         GAUDI_QUEUE_ID_DMA_2_0 = 9,     /* internal */
78         GAUDI_QUEUE_ID_DMA_2_1 = 10,    /* internal */
79         GAUDI_QUEUE_ID_DMA_2_2 = 11,    /* internal */
80         GAUDI_QUEUE_ID_DMA_2_3 = 12,    /* internal */
81         GAUDI_QUEUE_ID_DMA_3_0 = 13,    /* internal */
82         GAUDI_QUEUE_ID_DMA_3_1 = 14,    /* internal */
83         GAUDI_QUEUE_ID_DMA_3_2 = 15,    /* internal */
84         GAUDI_QUEUE_ID_DMA_3_3 = 16,    /* internal */
85         GAUDI_QUEUE_ID_DMA_4_0 = 17,    /* internal */
86         GAUDI_QUEUE_ID_DMA_4_1 = 18,    /* internal */
87         GAUDI_QUEUE_ID_DMA_4_2 = 19,    /* internal */
88         GAUDI_QUEUE_ID_DMA_4_3 = 20,    /* internal */
89         GAUDI_QUEUE_ID_DMA_5_0 = 21,    /* internal */
90         GAUDI_QUEUE_ID_DMA_5_1 = 22,    /* internal */
91         GAUDI_QUEUE_ID_DMA_5_2 = 23,    /* internal */
92         GAUDI_QUEUE_ID_DMA_5_3 = 24,    /* internal */
93         GAUDI_QUEUE_ID_DMA_6_0 = 25,    /* internal */
94         GAUDI_QUEUE_ID_DMA_6_1 = 26,    /* internal */
95         GAUDI_QUEUE_ID_DMA_6_2 = 27,    /* internal */
96         GAUDI_QUEUE_ID_DMA_6_3 = 28,    /* internal */
97         GAUDI_QUEUE_ID_DMA_7_0 = 29,    /* internal */
98         GAUDI_QUEUE_ID_DMA_7_1 = 30,    /* internal */
99         GAUDI_QUEUE_ID_DMA_7_2 = 31,    /* internal */
100         GAUDI_QUEUE_ID_DMA_7_3 = 32,    /* internal */
101         GAUDI_QUEUE_ID_MME_0_0 = 33,    /* internal */
102         GAUDI_QUEUE_ID_MME_0_1 = 34,    /* internal */
103         GAUDI_QUEUE_ID_MME_0_2 = 35,    /* internal */
104         GAUDI_QUEUE_ID_MME_0_3 = 36,    /* internal */
105         GAUDI_QUEUE_ID_MME_1_0 = 37,    /* internal */
106         GAUDI_QUEUE_ID_MME_1_1 = 38,    /* internal */
107         GAUDI_QUEUE_ID_MME_1_2 = 39,    /* internal */
108         GAUDI_QUEUE_ID_MME_1_3 = 40,    /* internal */
109         GAUDI_QUEUE_ID_TPC_0_0 = 41,    /* internal */
110         GAUDI_QUEUE_ID_TPC_0_1 = 42,    /* internal */
111         GAUDI_QUEUE_ID_TPC_0_2 = 43,    /* internal */
112         GAUDI_QUEUE_ID_TPC_0_3 = 44,    /* internal */
113         GAUDI_QUEUE_ID_TPC_1_0 = 45,    /* internal */
114         GAUDI_QUEUE_ID_TPC_1_1 = 46,    /* internal */
115         GAUDI_QUEUE_ID_TPC_1_2 = 47,    /* internal */
116         GAUDI_QUEUE_ID_TPC_1_3 = 48,    /* internal */
117         GAUDI_QUEUE_ID_TPC_2_0 = 49,    /* internal */
118         GAUDI_QUEUE_ID_TPC_2_1 = 50,    /* internal */
119         GAUDI_QUEUE_ID_TPC_2_2 = 51,    /* internal */
120         GAUDI_QUEUE_ID_TPC_2_3 = 52,    /* internal */
121         GAUDI_QUEUE_ID_TPC_3_0 = 53,    /* internal */
122         GAUDI_QUEUE_ID_TPC_3_1 = 54,    /* internal */
123         GAUDI_QUEUE_ID_TPC_3_2 = 55,    /* internal */
124         GAUDI_QUEUE_ID_TPC_3_3 = 56,    /* internal */
125         GAUDI_QUEUE_ID_TPC_4_0 = 57,    /* internal */
126         GAUDI_QUEUE_ID_TPC_4_1 = 58,    /* internal */
127         GAUDI_QUEUE_ID_TPC_4_2 = 59,    /* internal */
128         GAUDI_QUEUE_ID_TPC_4_3 = 60,    /* internal */
129         GAUDI_QUEUE_ID_TPC_5_0 = 61,    /* internal */
130         GAUDI_QUEUE_ID_TPC_5_1 = 62,    /* internal */
131         GAUDI_QUEUE_ID_TPC_5_2 = 63,    /* internal */
132         GAUDI_QUEUE_ID_TPC_5_3 = 64,    /* internal */
133         GAUDI_QUEUE_ID_TPC_6_0 = 65,    /* internal */
134         GAUDI_QUEUE_ID_TPC_6_1 = 66,    /* internal */
135         GAUDI_QUEUE_ID_TPC_6_2 = 67,    /* internal */
136         GAUDI_QUEUE_ID_TPC_6_3 = 68,    /* internal */
137         GAUDI_QUEUE_ID_TPC_7_0 = 69,    /* internal */
138         GAUDI_QUEUE_ID_TPC_7_1 = 70,    /* internal */
139         GAUDI_QUEUE_ID_TPC_7_2 = 71,    /* internal */
140         GAUDI_QUEUE_ID_TPC_7_3 = 72,    /* internal */
141         GAUDI_QUEUE_ID_NIC_0_0 = 73,    /* internal */
142         GAUDI_QUEUE_ID_NIC_0_1 = 74,    /* internal */
143         GAUDI_QUEUE_ID_NIC_0_2 = 75,    /* internal */
144         GAUDI_QUEUE_ID_NIC_0_3 = 76,    /* internal */
145         GAUDI_QUEUE_ID_NIC_1_0 = 77,    /* internal */
146         GAUDI_QUEUE_ID_NIC_1_1 = 78,    /* internal */
147         GAUDI_QUEUE_ID_NIC_1_2 = 79,    /* internal */
148         GAUDI_QUEUE_ID_NIC_1_3 = 80,    /* internal */
149         GAUDI_QUEUE_ID_NIC_2_0 = 81,    /* internal */
150         GAUDI_QUEUE_ID_NIC_2_1 = 82,    /* internal */
151         GAUDI_QUEUE_ID_NIC_2_2 = 83,    /* internal */
152         GAUDI_QUEUE_ID_NIC_2_3 = 84,    /* internal */
153         GAUDI_QUEUE_ID_NIC_3_0 = 85,    /* internal */
154         GAUDI_QUEUE_ID_NIC_3_1 = 86,    /* internal */
155         GAUDI_QUEUE_ID_NIC_3_2 = 87,    /* internal */
156         GAUDI_QUEUE_ID_NIC_3_3 = 88,    /* internal */
157         GAUDI_QUEUE_ID_NIC_4_0 = 89,    /* internal */
158         GAUDI_QUEUE_ID_NIC_4_1 = 90,    /* internal */
159         GAUDI_QUEUE_ID_NIC_4_2 = 91,    /* internal */
160         GAUDI_QUEUE_ID_NIC_4_3 = 92,    /* internal */
161         GAUDI_QUEUE_ID_NIC_5_0 = 93,    /* internal */
162         GAUDI_QUEUE_ID_NIC_5_1 = 94,    /* internal */
163         GAUDI_QUEUE_ID_NIC_5_2 = 95,    /* internal */
164         GAUDI_QUEUE_ID_NIC_5_3 = 96,    /* internal */
165         GAUDI_QUEUE_ID_NIC_6_0 = 97,    /* internal */
166         GAUDI_QUEUE_ID_NIC_6_1 = 98,    /* internal */
167         GAUDI_QUEUE_ID_NIC_6_2 = 99,    /* internal */
168         GAUDI_QUEUE_ID_NIC_6_3 = 100,   /* internal */
169         GAUDI_QUEUE_ID_NIC_7_0 = 101,   /* internal */
170         GAUDI_QUEUE_ID_NIC_7_1 = 102,   /* internal */
171         GAUDI_QUEUE_ID_NIC_7_2 = 103,   /* internal */
172         GAUDI_QUEUE_ID_NIC_7_3 = 104,   /* internal */
173         GAUDI_QUEUE_ID_NIC_8_0 = 105,   /* internal */
174         GAUDI_QUEUE_ID_NIC_8_1 = 106,   /* internal */
175         GAUDI_QUEUE_ID_NIC_8_2 = 107,   /* internal */
176         GAUDI_QUEUE_ID_NIC_8_3 = 108,   /* internal */
177         GAUDI_QUEUE_ID_NIC_9_0 = 109,   /* internal */
178         GAUDI_QUEUE_ID_NIC_9_1 = 110,   /* internal */
179         GAUDI_QUEUE_ID_NIC_9_2 = 111,   /* internal */
180         GAUDI_QUEUE_ID_NIC_9_3 = 112,   /* internal */
181         GAUDI_QUEUE_ID_SIZE
182 };
183
184 /*
185  * Engine Numbering
186  *
187  * Used in the "busy_engines_mask" field in `struct hl_info_hw_idle'
188  */
189
190 enum goya_engine_id {
191         GOYA_ENGINE_ID_DMA_0 = 0,
192         GOYA_ENGINE_ID_DMA_1,
193         GOYA_ENGINE_ID_DMA_2,
194         GOYA_ENGINE_ID_DMA_3,
195         GOYA_ENGINE_ID_DMA_4,
196         GOYA_ENGINE_ID_MME_0,
197         GOYA_ENGINE_ID_TPC_0,
198         GOYA_ENGINE_ID_TPC_1,
199         GOYA_ENGINE_ID_TPC_2,
200         GOYA_ENGINE_ID_TPC_3,
201         GOYA_ENGINE_ID_TPC_4,
202         GOYA_ENGINE_ID_TPC_5,
203         GOYA_ENGINE_ID_TPC_6,
204         GOYA_ENGINE_ID_TPC_7,
205         GOYA_ENGINE_ID_SIZE
206 };
207
208 enum gaudi_engine_id {
209         GAUDI_ENGINE_ID_DMA_0 = 0,
210         GAUDI_ENGINE_ID_DMA_1,
211         GAUDI_ENGINE_ID_DMA_2,
212         GAUDI_ENGINE_ID_DMA_3,
213         GAUDI_ENGINE_ID_DMA_4,
214         GAUDI_ENGINE_ID_DMA_5,
215         GAUDI_ENGINE_ID_DMA_6,
216         GAUDI_ENGINE_ID_DMA_7,
217         GAUDI_ENGINE_ID_MME_0,
218         GAUDI_ENGINE_ID_MME_1,
219         GAUDI_ENGINE_ID_MME_2,
220         GAUDI_ENGINE_ID_MME_3,
221         GAUDI_ENGINE_ID_TPC_0,
222         GAUDI_ENGINE_ID_TPC_1,
223         GAUDI_ENGINE_ID_TPC_2,
224         GAUDI_ENGINE_ID_TPC_3,
225         GAUDI_ENGINE_ID_TPC_4,
226         GAUDI_ENGINE_ID_TPC_5,
227         GAUDI_ENGINE_ID_TPC_6,
228         GAUDI_ENGINE_ID_TPC_7,
229         GAUDI_ENGINE_ID_NIC_0,
230         GAUDI_ENGINE_ID_NIC_1,
231         GAUDI_ENGINE_ID_NIC_2,
232         GAUDI_ENGINE_ID_NIC_3,
233         GAUDI_ENGINE_ID_NIC_4,
234         GAUDI_ENGINE_ID_NIC_5,
235         GAUDI_ENGINE_ID_NIC_6,
236         GAUDI_ENGINE_ID_NIC_7,
237         GAUDI_ENGINE_ID_NIC_8,
238         GAUDI_ENGINE_ID_NIC_9,
239         GAUDI_ENGINE_ID_SIZE
240 };
241
242 /*
243  * ASIC specific PLL index
244  *
245  * Used to retrieve in frequency info of different IPs via
246  * HL_INFO_PLL_FREQUENCY under HL_IOCTL_INFO IOCTL. The enums need to be
247  * used as an index in struct hl_pll_frequency_info
248  */
249
250 enum hl_goya_pll_index {
251         HL_GOYA_CPU_PLL = 0,
252         HL_GOYA_IC_PLL,
253         HL_GOYA_MC_PLL,
254         HL_GOYA_MME_PLL,
255         HL_GOYA_PCI_PLL,
256         HL_GOYA_EMMC_PLL,
257         HL_GOYA_TPC_PLL,
258         HL_GOYA_PLL_MAX
259 };
260
261 enum hl_gaudi_pll_index {
262         HL_GAUDI_CPU_PLL = 0,
263         HL_GAUDI_PCI_PLL,
264         HL_GAUDI_SRAM_PLL,
265         HL_GAUDI_HBM_PLL,
266         HL_GAUDI_NIC_PLL,
267         HL_GAUDI_DMA_PLL,
268         HL_GAUDI_MESH_PLL,
269         HL_GAUDI_MME_PLL,
270         HL_GAUDI_TPC_PLL,
271         HL_GAUDI_IF_PLL,
272         HL_GAUDI_PLL_MAX
273 };
274
275 enum hl_device_status {
276         HL_DEVICE_STATUS_OPERATIONAL,
277         HL_DEVICE_STATUS_IN_RESET,
278         HL_DEVICE_STATUS_MALFUNCTION,
279         HL_DEVICE_STATUS_NEEDS_RESET
280 };
281
282 /* Opcode for management ioctl
283  *
284  * HW_IP_INFO            - Receive information about different IP blocks in the
285  *                         device.
286  * HL_INFO_HW_EVENTS     - Receive an array describing how many times each event
287  *                         occurred since the last hard reset.
288  * HL_INFO_DRAM_USAGE    - Retrieve the dram usage inside the device and of the
289  *                         specific context. This is relevant only for devices
290  *                         where the dram is managed by the kernel driver
291  * HL_INFO_HW_IDLE       - Retrieve information about the idle status of each
292  *                         internal engine.
293  * HL_INFO_DEVICE_STATUS - Retrieve the device's status. This opcode doesn't
294  *                         require an open context.
295  * HL_INFO_DEVICE_UTILIZATION  - Retrieve the total utilization of the device
296  *                               over the last period specified by the user.
297  *                               The period can be between 100ms to 1s, in
298  *                               resolution of 100ms. The return value is a
299  *                               percentage of the utilization rate.
300  * HL_INFO_HW_EVENTS_AGGREGATE - Receive an array describing how many times each
301  *                               event occurred since the driver was loaded.
302  * HL_INFO_CLK_RATE            - Retrieve the current and maximum clock rate
303  *                               of the device in MHz. The maximum clock rate is
304  *                               configurable via sysfs parameter
305  * HL_INFO_RESET_COUNT   - Retrieve the counts of the soft and hard reset
306  *                         operations performed on the device since the last
307  *                         time the driver was loaded.
308  * HL_INFO_TIME_SYNC     - Retrieve the device's time alongside the host's time
309  *                         for synchronization.
310  * HL_INFO_CS_COUNTERS   - Retrieve command submission counters
311  * HL_INFO_PCI_COUNTERS  - Retrieve PCI counters
312  * HL_INFO_CLK_THROTTLE_REASON - Retrieve clock throttling reason
313  * HL_INFO_SYNC_MANAGER  - Retrieve sync manager info per dcore
314  * HL_INFO_TOTAL_ENERGY  - Retrieve total energy consumption
315  * HL_INFO_PLL_FREQUENCY - Retrieve PLL frequency
316  */
317 #define HL_INFO_HW_IP_INFO              0
318 #define HL_INFO_HW_EVENTS               1
319 #define HL_INFO_DRAM_USAGE              2
320 #define HL_INFO_HW_IDLE                 3
321 #define HL_INFO_DEVICE_STATUS           4
322 #define HL_INFO_DEVICE_UTILIZATION      6
323 #define HL_INFO_HW_EVENTS_AGGREGATE     7
324 #define HL_INFO_CLK_RATE                8
325 #define HL_INFO_RESET_COUNT             9
326 #define HL_INFO_TIME_SYNC               10
327 #define HL_INFO_CS_COUNTERS             11
328 #define HL_INFO_PCI_COUNTERS            12
329 #define HL_INFO_CLK_THROTTLE_REASON     13
330 #define HL_INFO_SYNC_MANAGER            14
331 #define HL_INFO_TOTAL_ENERGY            15
332 #define HL_INFO_PLL_FREQUENCY           16
333 #define HL_INFO_POWER                   17
334
335 #define HL_INFO_VERSION_MAX_LEN 128
336 #define HL_INFO_CARD_NAME_MAX_LEN       16
337
338 struct hl_info_hw_ip_info {
339         __u64 sram_base_address;
340         __u64 dram_base_address;
341         __u64 dram_size;
342         __u32 sram_size;
343         __u32 num_of_events;
344         __u32 device_id; /* PCI Device ID */
345         __u32 module_id; /* For mezzanine cards in servers (From OCP spec.) */
346         __u32 reserved;
347         __u16 first_available_interrupt_id;
348         __u16 reserved2;
349         __u32 cpld_version;
350         __u32 psoc_pci_pll_nr;
351         __u32 psoc_pci_pll_nf;
352         __u32 psoc_pci_pll_od;
353         __u32 psoc_pci_pll_div_factor;
354         __u8 tpc_enabled_mask;
355         __u8 dram_enabled;
356         __u8 pad[2];
357         __u8 cpucp_version[HL_INFO_VERSION_MAX_LEN];
358         __u8 card_name[HL_INFO_CARD_NAME_MAX_LEN];
359         __u64 reserved3;
360         __u64 dram_page_size;
361 };
362
363 struct hl_info_dram_usage {
364         __u64 dram_free_mem;
365         __u64 ctx_dram_mem;
366 };
367
368 #define HL_BUSY_ENGINES_MASK_EXT_SIZE   2
369
370 struct hl_info_hw_idle {
371         __u32 is_idle;
372         /*
373          * Bitmask of busy engines.
374          * Bits definition is according to `enum <chip>_enging_id'.
375          */
376         __u32 busy_engines_mask;
377
378         /*
379          * Extended Bitmask of busy engines.
380          * Bits definition is according to `enum <chip>_enging_id'.
381          */
382         __u64 busy_engines_mask_ext[HL_BUSY_ENGINES_MASK_EXT_SIZE];
383 };
384
385 struct hl_info_device_status {
386         __u32 status;
387         __u32 pad;
388 };
389
390 struct hl_info_device_utilization {
391         __u32 utilization;
392         __u32 pad;
393 };
394
395 struct hl_info_clk_rate {
396         __u32 cur_clk_rate_mhz;
397         __u32 max_clk_rate_mhz;
398 };
399
400 struct hl_info_reset_count {
401         __u32 hard_reset_cnt;
402         __u32 soft_reset_cnt;
403 };
404
405 struct hl_info_time_sync {
406         __u64 device_time;
407         __u64 host_time;
408 };
409
410 /**
411  * struct hl_info_pci_counters - pci counters
412  * @rx_throughput: PCI rx throughput KBps
413  * @tx_throughput: PCI tx throughput KBps
414  * @replay_cnt: PCI replay counter
415  */
416 struct hl_info_pci_counters {
417         __u64 rx_throughput;
418         __u64 tx_throughput;
419         __u64 replay_cnt;
420 };
421
422 #define HL_CLK_THROTTLE_POWER   0x1
423 #define HL_CLK_THROTTLE_THERMAL 0x2
424
425 /**
426  * struct hl_info_clk_throttle - clock throttling reason
427  * @clk_throttling_reason: each bit represents a clk throttling reason
428  */
429 struct hl_info_clk_throttle {
430         __u32 clk_throttling_reason;
431 };
432
433 /**
434  * struct hl_info_energy - device energy information
435  * @total_energy_consumption: total device energy consumption
436  */
437 struct hl_info_energy {
438         __u64 total_energy_consumption;
439 };
440
441 #define HL_PLL_NUM_OUTPUTS 4
442
443 struct hl_pll_frequency_info {
444         __u16 output[HL_PLL_NUM_OUTPUTS];
445 };
446
447 /**
448  * struct hl_power_info - power information
449  * @power: power consumption
450  */
451 struct hl_power_info {
452         __u64 power;
453 };
454
455 /**
456  * struct hl_info_sync_manager - sync manager information
457  * @first_available_sync_object: first available sob
458  * @first_available_monitor: first available monitor
459  * @first_available_cq: first available cq
460  */
461 struct hl_info_sync_manager {
462         __u32 first_available_sync_object;
463         __u32 first_available_monitor;
464         __u32 first_available_cq;
465         __u32 reserved;
466 };
467
468 /**
469  * struct hl_info_cs_counters - command submission counters
470  * @total_out_of_mem_drop_cnt: total dropped due to memory allocation issue
471  * @ctx_out_of_mem_drop_cnt: context dropped due to memory allocation issue
472  * @total_parsing_drop_cnt: total dropped due to error in packet parsing
473  * @ctx_parsing_drop_cnt: context dropped due to error in packet parsing
474  * @total_queue_full_drop_cnt: total dropped due to queue full
475  * @ctx_queue_full_drop_cnt: context dropped due to queue full
476  * @total_device_in_reset_drop_cnt: total dropped due to device in reset
477  * @ctx_device_in_reset_drop_cnt: context dropped due to device in reset
478  * @total_max_cs_in_flight_drop_cnt: total dropped due to maximum CS in-flight
479  * @ctx_max_cs_in_flight_drop_cnt: context dropped due to maximum CS in-flight
480  * @total_validation_drop_cnt: total dropped due to validation error
481  * @ctx_validation_drop_cnt: context dropped due to validation error
482  */
483 struct hl_info_cs_counters {
484         __u64 total_out_of_mem_drop_cnt;
485         __u64 ctx_out_of_mem_drop_cnt;
486         __u64 total_parsing_drop_cnt;
487         __u64 ctx_parsing_drop_cnt;
488         __u64 total_queue_full_drop_cnt;
489         __u64 ctx_queue_full_drop_cnt;
490         __u64 total_device_in_reset_drop_cnt;
491         __u64 ctx_device_in_reset_drop_cnt;
492         __u64 total_max_cs_in_flight_drop_cnt;
493         __u64 ctx_max_cs_in_flight_drop_cnt;
494         __u64 total_validation_drop_cnt;
495         __u64 ctx_validation_drop_cnt;
496 };
497
498 enum gaudi_dcores {
499         HL_GAUDI_WS_DCORE,
500         HL_GAUDI_WN_DCORE,
501         HL_GAUDI_EN_DCORE,
502         HL_GAUDI_ES_DCORE
503 };
504
505 struct hl_info_args {
506         /* Location of relevant struct in userspace */
507         __u64 return_pointer;
508         /*
509          * The size of the return value. Just like "size" in "snprintf",
510          * it limits how many bytes the kernel can write
511          *
512          * For hw_events array, the size should be
513          * hl_info_hw_ip_info.num_of_events * sizeof(__u32)
514          */
515         __u32 return_size;
516
517         /* HL_INFO_* */
518         __u32 op;
519
520         union {
521                 /* Dcore id for which the information is relevant.
522                  * For Gaudi refer to 'enum gaudi_dcores'
523                  */
524                 __u32 dcore_id;
525                 /* Context ID - Currently not in use */
526                 __u32 ctx_id;
527                 /* Period value for utilization rate (100ms - 1000ms, in 100ms
528                  * resolution.
529                  */
530                 __u32 period_ms;
531                 /* PLL frequency retrieval */
532                 __u32 pll_index;
533         };
534
535         __u32 pad;
536 };
537
538 /* Opcode to create a new command buffer */
539 #define HL_CB_OP_CREATE         0
540 /* Opcode to destroy previously created command buffer */
541 #define HL_CB_OP_DESTROY        1
542 /* Opcode to retrieve information about a command buffer */
543 #define HL_CB_OP_INFO           2
544
545 /* 2MB minus 32 bytes for 2xMSG_PROT */
546 #define HL_MAX_CB_SIZE          (0x200000 - 32)
547
548 /* Indicates whether the command buffer should be mapped to the device's MMU */
549 #define HL_CB_FLAGS_MAP         0x1
550
551 struct hl_cb_in {
552         /* Handle of CB or 0 if we want to create one */
553         __u64 cb_handle;
554         /* HL_CB_OP_* */
555         __u32 op;
556         /* Size of CB. Maximum size is HL_MAX_CB_SIZE. The minimum size that
557          * will be allocated, regardless of this parameter's value, is PAGE_SIZE
558          */
559         __u32 cb_size;
560         /* Context ID - Currently not in use */
561         __u32 ctx_id;
562         /* HL_CB_FLAGS_* */
563         __u32 flags;
564 };
565
566 struct hl_cb_out {
567         union {
568                 /* Handle of CB */
569                 __u64 cb_handle;
570
571                 /* Information about CB */
572                 struct {
573                         /* Usage count of CB */
574                         __u32 usage_cnt;
575                         __u32 pad;
576                 };
577         };
578 };
579
580 union hl_cb_args {
581         struct hl_cb_in in;
582         struct hl_cb_out out;
583 };
584
585 /* HL_CS_CHUNK_FLAGS_ values
586  *
587  * HL_CS_CHUNK_FLAGS_USER_ALLOC_CB:
588  *      Indicates if the CB was allocated and mapped by userspace.
589  *      User allocated CB is a command buffer allocated by the user, via malloc
590  *      (or similar). After allocating the CB, the user invokes “memory ioctl”
591  *      to map the user memory into a device virtual address. The user provides
592  *      this address via the cb_handle field. The interface provides the
593  *      ability to create a large CBs, Which aren’t limited to
594  *      “HL_MAX_CB_SIZE”. Therefore, it increases the PCI-DMA queues
595  *      throughput. This CB allocation method also reduces the use of Linux
596  *      DMA-able memory pool. Which are limited and used by other Linux
597  *      sub-systems.
598  */
599 #define HL_CS_CHUNK_FLAGS_USER_ALLOC_CB 0x1
600
601 /*
602  * This structure size must always be fixed to 64-bytes for backward
603  * compatibility
604  */
605 struct hl_cs_chunk {
606         union {
607                 /* For external queue, this represents a Handle of CB on the
608                  * Host.
609                  * For internal queue in Goya, this represents an SRAM or
610                  * a DRAM address of the internal CB. In Gaudi, this might also
611                  * represent a mapped host address of the CB.
612                  *
613                  * A mapped host address is in the device address space, after
614                  * a host address was mapped by the device MMU.
615                  */
616                 __u64 cb_handle;
617
618                 /* Relevant only when HL_CS_FLAGS_WAIT or
619                  * HL_CS_FLAGS_COLLECTIVE_WAIT is set.
620                  * This holds address of array of u64 values that contain
621                  * signal CS sequence numbers. The wait described by this job
622                  * will listen on all those signals (wait event per signal)
623                  */
624                 __u64 signal_seq_arr;
625         };
626
627         /* Index of queue to put the CB on */
628         __u32 queue_index;
629
630         union {
631                 /*
632                  * Size of command buffer with valid packets
633                  * Can be smaller then actual CB size
634                  */
635                 __u32 cb_size;
636
637                 /* Relevant only when HL_CS_FLAGS_WAIT or
638                  * HL_CS_FLAGS_COLLECTIVE_WAIT is set.
639                  * Number of entries in signal_seq_arr
640                  */
641                 __u32 num_signal_seq_arr;
642         };
643
644         /* HL_CS_CHUNK_FLAGS_* */
645         __u32 cs_chunk_flags;
646
647         /* Relevant only when HL_CS_FLAGS_COLLECTIVE_WAIT is set.
648          * This holds the collective engine ID. The wait described by this job
649          * will sync with this engine and with all NICs before completion.
650          */
651         __u32 collective_engine_id;
652
653         /* Align structure to 64 bytes */
654         __u32 pad[10];
655 };
656
657 /* SIGNAL and WAIT/COLLECTIVE_WAIT flags are mutually exclusive */
658 #define HL_CS_FLAGS_FORCE_RESTORE               0x1
659 #define HL_CS_FLAGS_SIGNAL                      0x2
660 #define HL_CS_FLAGS_WAIT                        0x4
661 #define HL_CS_FLAGS_COLLECTIVE_WAIT             0x8
662 #define HL_CS_FLAGS_TIMESTAMP                   0x20
663 #define HL_CS_FLAGS_STAGED_SUBMISSION           0x40
664 #define HL_CS_FLAGS_STAGED_SUBMISSION_FIRST     0x80
665 #define HL_CS_FLAGS_STAGED_SUBMISSION_LAST      0x100
666 #define HL_CS_FLAGS_CUSTOM_TIMEOUT              0x200
667
668 #define HL_CS_STATUS_SUCCESS            0
669
670 #define HL_MAX_JOBS_PER_CS              512
671
672 struct hl_cs_in {
673
674         /* this holds address of array of hl_cs_chunk for restore phase */
675         __u64 chunks_restore;
676
677         /* holds address of array of hl_cs_chunk for execution phase */
678         __u64 chunks_execute;
679
680         /* Sequence number of a staged submission CS
681          * valid only if HL_CS_FLAGS_STAGED_SUBMISSION is set
682          */
683         __u64 seq;
684
685         /* Number of chunks in restore phase array. Maximum number is
686          * HL_MAX_JOBS_PER_CS
687          */
688         __u32 num_chunks_restore;
689
690         /* Number of chunks in execution array. Maximum number is
691          * HL_MAX_JOBS_PER_CS
692          */
693         __u32 num_chunks_execute;
694
695         /* timeout in seconds - valid only if HL_CS_FLAGS_CUSTOM_TIMEOUT
696          * is set
697          */
698         __u32 timeout;
699
700         /* HL_CS_FLAGS_* */
701         __u32 cs_flags;
702
703         /* Context ID - Currently not in use */
704         __u32 ctx_id;
705 };
706
707 struct hl_cs_out {
708         /*
709          * seq holds the sequence number of the CS to pass to wait ioctl. All
710          * values are valid except for 0 and ULLONG_MAX
711          */
712         __u64 seq;
713         /* HL_CS_STATUS_* */
714         __u32 status;
715         __u32 pad;
716 };
717
718 union hl_cs_args {
719         struct hl_cs_in in;
720         struct hl_cs_out out;
721 };
722
723 #define HL_WAIT_CS_FLAGS_INTERRUPT      0x2
724 #define HL_WAIT_CS_FLAGS_INTERRUPT_MASK 0xFFF00000
725
726 struct hl_wait_cs_in {
727         union {
728                 struct {
729                         /* Command submission sequence number */
730                         __u64 seq;
731                         /* Absolute timeout to wait for command submission
732                          * in microseconds
733                          */
734                         __u64 timeout_us;
735                 };
736
737                 struct {
738                         /* User address for completion comparison.
739                          * upon interrupt, driver will compare the value pointed
740                          * by this address with the supplied target value.
741                          * in order not to perform any comparison, set address
742                          * to all 1s.
743                          * Relevant only when HL_WAIT_CS_FLAGS_INTERRUPT is set
744                          */
745                         __u64 addr;
746                         /* Target value for completion comparison */
747                         __u32 target;
748                         /* Absolute timeout to wait for interrupt
749                          * in microseconds
750                          */
751                         __u32 interrupt_timeout_us;
752                 };
753         };
754
755         /* Context ID - Currently not in use */
756         __u32 ctx_id;
757         /* HL_WAIT_CS_FLAGS_*
758          * If HL_WAIT_CS_FLAGS_INTERRUPT is set, this field should include
759          * interrupt id according to HL_WAIT_CS_FLAGS_INTERRUPT_MASK, in order
760          * not to specify an interrupt id ,set mask to all 1s.
761          */
762         __u32 flags;
763 };
764
765 #define HL_WAIT_CS_STATUS_COMPLETED     0
766 #define HL_WAIT_CS_STATUS_BUSY          1
767 #define HL_WAIT_CS_STATUS_TIMEDOUT      2
768 #define HL_WAIT_CS_STATUS_ABORTED       3
769 #define HL_WAIT_CS_STATUS_INTERRUPTED   4
770
771 #define HL_WAIT_CS_STATUS_FLAG_GONE             0x1
772 #define HL_WAIT_CS_STATUS_FLAG_TIMESTAMP_VLD    0x2
773
774 struct hl_wait_cs_out {
775         /* HL_WAIT_CS_STATUS_* */
776         __u32 status;
777         /* HL_WAIT_CS_STATUS_FLAG* */
778         __u32 flags;
779         /* valid only if HL_WAIT_CS_STATUS_FLAG_TIMESTAMP_VLD is set */
780         __s64 timestamp_nsec;
781 };
782
783 union hl_wait_cs_args {
784         struct hl_wait_cs_in in;
785         struct hl_wait_cs_out out;
786 };
787
788 /* Opcode to allocate device memory */
789 #define HL_MEM_OP_ALLOC                 0
790 /* Opcode to free previously allocated device memory */
791 #define HL_MEM_OP_FREE                  1
792 /* Opcode to map host and device memory */
793 #define HL_MEM_OP_MAP                   2
794 /* Opcode to unmap previously mapped host and device memory */
795 #define HL_MEM_OP_UNMAP                 3
796 /* Opcode to map a hw block */
797 #define HL_MEM_OP_MAP_BLOCK             4
798
799 /* Memory flags */
800 #define HL_MEM_CONTIGUOUS       0x1
801 #define HL_MEM_SHARED           0x2
802 #define HL_MEM_USERPTR          0x4
803
804 struct hl_mem_in {
805         union {
806                 /* HL_MEM_OP_ALLOC- allocate device memory */
807                 struct {
808                         /* Size to alloc */
809                         __u64 mem_size;
810                 } alloc;
811
812                 /* HL_MEM_OP_FREE - free device memory */
813                 struct {
814                         /* Handle returned from HL_MEM_OP_ALLOC */
815                         __u64 handle;
816                 } free;
817
818                 /* HL_MEM_OP_MAP - map device memory */
819                 struct {
820                         /*
821                          * Requested virtual address of mapped memory.
822                          * The driver will try to map the requested region to
823                          * this hint address, as long as the address is valid
824                          * and not already mapped. The user should check the
825                          * returned address of the IOCTL to make sure he got
826                          * the hint address. Passing 0 here means that the
827                          * driver will choose the address itself.
828                          */
829                         __u64 hint_addr;
830                         /* Handle returned from HL_MEM_OP_ALLOC */
831                         __u64 handle;
832                 } map_device;
833
834                 /* HL_MEM_OP_MAP - map host memory */
835                 struct {
836                         /* Address of allocated host memory */
837                         __u64 host_virt_addr;
838                         /*
839                          * Requested virtual address of mapped memory.
840                          * The driver will try to map the requested region to
841                          * this hint address, as long as the address is valid
842                          * and not already mapped. The user should check the
843                          * returned address of the IOCTL to make sure he got
844                          * the hint address. Passing 0 here means that the
845                          * driver will choose the address itself.
846                          */
847                         __u64 hint_addr;
848                         /* Size of allocated host memory */
849                         __u64 mem_size;
850                 } map_host;
851
852                 /* HL_MEM_OP_MAP_BLOCK - map a hw block */
853                 struct {
854                         /*
855                          * HW block address to map, a handle and size will be
856                          * returned to the user and will be used to mmap the
857                          * relevant block. Only addresses from configuration
858                          * space are allowed.
859                          */
860                         __u64 block_addr;
861                 } map_block;
862
863                 /* HL_MEM_OP_UNMAP - unmap host memory */
864                 struct {
865                         /* Virtual address returned from HL_MEM_OP_MAP */
866                         __u64 device_virt_addr;
867                 } unmap;
868         };
869
870         /* HL_MEM_OP_* */
871         __u32 op;
872         /* HL_MEM_* flags */
873         __u32 flags;
874         /* Context ID - Currently not in use */
875         __u32 ctx_id;
876         __u32 pad;
877 };
878
879 struct hl_mem_out {
880         union {
881                 /*
882                  * Used for HL_MEM_OP_MAP as the virtual address that was
883                  * assigned in the device VA space.
884                  * A value of 0 means the requested operation failed.
885                  */
886                 __u64 device_virt_addr;
887
888                 /*
889                  * Used in HL_MEM_OP_ALLOC
890                  * This is the assigned handle for the allocated memory
891                  */
892                 __u64 handle;
893
894                 struct {
895                         /*
896                          * Used in HL_MEM_OP_MAP_BLOCK.
897                          * This is the assigned handle for the mapped block
898                          */
899                         __u64 block_handle;
900
901                         /*
902                          * Used in HL_MEM_OP_MAP_BLOCK
903                          * This is the size of the mapped block
904                          */
905                         __u32 block_size;
906
907                         __u32 pad;
908                 };
909         };
910 };
911
912 union hl_mem_args {
913         struct hl_mem_in in;
914         struct hl_mem_out out;
915 };
916
917 #define HL_DEBUG_MAX_AUX_VALUES         10
918
919 struct hl_debug_params_etr {
920         /* Address in memory to allocate buffer */
921         __u64 buffer_address;
922
923         /* Size of buffer to allocate */
924         __u64 buffer_size;
925
926         /* Sink operation mode: SW fifo, HW fifo, Circular buffer */
927         __u32 sink_mode;
928         __u32 pad;
929 };
930
931 struct hl_debug_params_etf {
932         /* Address in memory to allocate buffer */
933         __u64 buffer_address;
934
935         /* Size of buffer to allocate */
936         __u64 buffer_size;
937
938         /* Sink operation mode: SW fifo, HW fifo, Circular buffer */
939         __u32 sink_mode;
940         __u32 pad;
941 };
942
943 struct hl_debug_params_stm {
944         /* Two bit masks for HW event and Stimulus Port */
945         __u64 he_mask;
946         __u64 sp_mask;
947
948         /* Trace source ID */
949         __u32 id;
950
951         /* Frequency for the timestamp register */
952         __u32 frequency;
953 };
954
955 struct hl_debug_params_bmon {
956         /* Two address ranges that the user can request to filter */
957         __u64 start_addr0;
958         __u64 addr_mask0;
959
960         __u64 start_addr1;
961         __u64 addr_mask1;
962
963         /* Capture window configuration */
964         __u32 bw_win;
965         __u32 win_capture;
966
967         /* Trace source ID */
968         __u32 id;
969         __u32 pad;
970 };
971
972 struct hl_debug_params_spmu {
973         /* Event types selection */
974         __u64 event_types[HL_DEBUG_MAX_AUX_VALUES];
975
976         /* Number of event types selection */
977         __u32 event_types_num;
978         __u32 pad;
979 };
980
981 /* Opcode for ETR component */
982 #define HL_DEBUG_OP_ETR         0
983 /* Opcode for ETF component */
984 #define HL_DEBUG_OP_ETF         1
985 /* Opcode for STM component */
986 #define HL_DEBUG_OP_STM         2
987 /* Opcode for FUNNEL component */
988 #define HL_DEBUG_OP_FUNNEL      3
989 /* Opcode for BMON component */
990 #define HL_DEBUG_OP_BMON        4
991 /* Opcode for SPMU component */
992 #define HL_DEBUG_OP_SPMU        5
993 /* Opcode for timestamp (deprecated) */
994 #define HL_DEBUG_OP_TIMESTAMP   6
995 /* Opcode for setting the device into or out of debug mode. The enable
996  * variable should be 1 for enabling debug mode and 0 for disabling it
997  */
998 #define HL_DEBUG_OP_SET_MODE    7
999
1000 struct hl_debug_args {
1001         /*
1002          * Pointer to user input structure.
1003          * This field is relevant to specific opcodes.
1004          */
1005         __u64 input_ptr;
1006         /* Pointer to user output structure */
1007         __u64 output_ptr;
1008         /* Size of user input structure */
1009         __u32 input_size;
1010         /* Size of user output structure */
1011         __u32 output_size;
1012         /* HL_DEBUG_OP_* */
1013         __u32 op;
1014         /*
1015          * Register index in the component, taken from the debug_regs_index enum
1016          * in the various ASIC header files
1017          */
1018         __u32 reg_idx;
1019         /* Enable/disable */
1020         __u32 enable;
1021         /* Context ID - Currently not in use */
1022         __u32 ctx_id;
1023 };
1024
1025 /*
1026  * Various information operations such as:
1027  * - H/W IP information
1028  * - Current dram usage
1029  *
1030  * The user calls this IOCTL with an opcode that describes the required
1031  * information. The user should supply a pointer to a user-allocated memory
1032  * chunk, which will be filled by the driver with the requested information.
1033  *
1034  * The user supplies the maximum amount of size to copy into the user's memory,
1035  * in order to prevent data corruption in case of differences between the
1036  * definitions of structures in kernel and userspace, e.g. in case of old
1037  * userspace and new kernel driver
1038  */
1039 #define HL_IOCTL_INFO   \
1040                 _IOWR('H', 0x01, struct hl_info_args)
1041
1042 /*
1043  * Command Buffer
1044  * - Request a Command Buffer
1045  * - Destroy a Command Buffer
1046  *
1047  * The command buffers are memory blocks that reside in DMA-able address
1048  * space and are physically contiguous so they can be accessed by the device
1049  * directly. They are allocated using the coherent DMA API.
1050  *
1051  * When creating a new CB, the IOCTL returns a handle of it, and the user-space
1052  * process needs to use that handle to mmap the buffer so it can access them.
1053  *
1054  * In some instances, the device must access the command buffer through the
1055  * device's MMU, and thus its memory should be mapped. In these cases, user can
1056  * indicate the driver that such a mapping is required.
1057  * The resulting device virtual address will be used internally by the driver,
1058  * and won't be returned to user.
1059  *
1060  */
1061 #define HL_IOCTL_CB             \
1062                 _IOWR('H', 0x02, union hl_cb_args)
1063
1064 /*
1065  * Command Submission
1066  *
1067  * To submit work to the device, the user need to call this IOCTL with a set
1068  * of JOBS. That set of JOBS constitutes a CS object.
1069  * Each JOB will be enqueued on a specific queue, according to the user's input.
1070  * There can be more then one JOB per queue.
1071  *
1072  * The CS IOCTL will receive two sets of JOBS. One set is for "restore" phase
1073  * and a second set is for "execution" phase.
1074  * The JOBS on the "restore" phase are enqueued only after context-switch
1075  * (or if its the first CS for this context). The user can also order the
1076  * driver to run the "restore" phase explicitly
1077  *
1078  * There are two types of queues - external and internal. External queues
1079  * are DMA queues which transfer data from/to the Host. All other queues are
1080  * internal. The driver will get completion notifications from the device only
1081  * on JOBS which are enqueued in the external queues.
1082  *
1083  * For jobs on external queues, the user needs to create command buffers
1084  * through the CB ioctl and give the CB's handle to the CS ioctl. For jobs on
1085  * internal queues, the user needs to prepare a "command buffer" with packets
1086  * on either the device SRAM/DRAM or the host, and give the device address of
1087  * that buffer to the CS ioctl.
1088  *
1089  * This IOCTL is asynchronous in regard to the actual execution of the CS. This
1090  * means it returns immediately after ALL the JOBS were enqueued on their
1091  * relevant queues. Therefore, the user mustn't assume the CS has been completed
1092  * or has even started to execute.
1093  *
1094  * Upon successful enqueue, the IOCTL returns a sequence number which the user
1095  * can use with the "Wait for CS" IOCTL to check whether the handle's CS
1096  * external JOBS have been completed. Note that if the CS has internal JOBS
1097  * which can execute AFTER the external JOBS have finished, the driver might
1098  * report that the CS has finished executing BEFORE the internal JOBS have
1099  * actually finished executing.
1100  *
1101  * Even though the sequence number increments per CS, the user can NOT
1102  * automatically assume that if CS with sequence number N finished, then CS
1103  * with sequence number N-1 also finished. The user can make this assumption if
1104  * and only if CS N and CS N-1 are exactly the same (same CBs for the same
1105  * queues).
1106  */
1107 #define HL_IOCTL_CS                     \
1108                 _IOWR('H', 0x03, union hl_cs_args)
1109
1110 /*
1111  * Wait for Command Submission
1112  *
1113  * The user can call this IOCTL with a handle it received from the CS IOCTL
1114  * to wait until the handle's CS has finished executing. The user will wait
1115  * inside the kernel until the CS has finished or until the user-requested
1116  * timeout has expired.
1117  *
1118  * If the timeout value is 0, the driver won't sleep at all. It will check
1119  * the status of the CS and return immediately
1120  *
1121  * The return value of the IOCTL is a standard Linux error code. The possible
1122  * values are:
1123  *
1124  * EINTR     - Kernel waiting has been interrupted, e.g. due to OS signal
1125  *             that the user process received
1126  * ETIMEDOUT - The CS has caused a timeout on the device
1127  * EIO       - The CS was aborted (usually because the device was reset)
1128  * ENODEV    - The device wants to do hard-reset (so user need to close FD)
1129  *
1130  * The driver also returns a custom define inside the IOCTL which can be:
1131  *
1132  * HL_WAIT_CS_STATUS_COMPLETED   - The CS has been completed successfully (0)
1133  * HL_WAIT_CS_STATUS_BUSY        - The CS is still executing (0)
1134  * HL_WAIT_CS_STATUS_TIMEDOUT    - The CS has caused a timeout on the device
1135  *                                 (ETIMEDOUT)
1136  * HL_WAIT_CS_STATUS_ABORTED     - The CS was aborted, usually because the
1137  *                                 device was reset (EIO)
1138  * HL_WAIT_CS_STATUS_INTERRUPTED - Waiting for the CS was interrupted (EINTR)
1139  *
1140  */
1141
1142 #define HL_IOCTL_WAIT_CS                        \
1143                 _IOWR('H', 0x04, union hl_wait_cs_args)
1144
1145 /*
1146  * Memory
1147  * - Map host memory to device MMU
1148  * - Unmap host memory from device MMU
1149  *
1150  * This IOCTL allows the user to map host memory to the device MMU
1151  *
1152  * For host memory, the IOCTL doesn't allocate memory. The user is supposed
1153  * to allocate the memory in user-space (malloc/new). The driver pins the
1154  * physical pages (up to the allowed limit by the OS), assigns a virtual
1155  * address in the device VA space and initializes the device MMU.
1156  *
1157  * There is an option for the user to specify the requested virtual address.
1158  *
1159  */
1160 #define HL_IOCTL_MEMORY         \
1161                 _IOWR('H', 0x05, union hl_mem_args)
1162
1163 /*
1164  * Debug
1165  * - Enable/disable the ETR/ETF/FUNNEL/STM/BMON/SPMU debug traces
1166  *
1167  * This IOCTL allows the user to get debug traces from the chip.
1168  *
1169  * Before the user can send configuration requests of the various
1170  * debug/profile engines, it needs to set the device into debug mode.
1171  * This is because the debug/profile infrastructure is shared component in the
1172  * device and we can't allow multiple users to access it at the same time.
1173  *
1174  * Once a user set the device into debug mode, the driver won't allow other
1175  * users to "work" with the device, i.e. open a FD. If there are multiple users
1176  * opened on the device, the driver won't allow any user to debug the device.
1177  *
1178  * For each configuration request, the user needs to provide the register index
1179  * and essential data such as buffer address and size.
1180  *
1181  * Once the user has finished using the debug/profile engines, he should
1182  * set the device into non-debug mode, i.e. disable debug mode.
1183  *
1184  * The driver can decide to "kick out" the user if he abuses this interface.
1185  *
1186  */
1187 #define HL_IOCTL_DEBUG          \
1188                 _IOWR('H', 0x06, struct hl_debug_args)
1189
1190 #define HL_COMMAND_START        0x01
1191 #define HL_COMMAND_END          0x07
1192
1193 #endif /* HABANALABS_H_ */