blob: ce83adafcf2d97561cd37ae97b63187422af3085 [file] [log] [blame]
Oded Gabbayc4d66342019-02-16 00:39:11 +02001/* SPDX-License-Identifier: GPL-2.0
2 *
3 * Copyright 2016-2019 HabanaLabs, Ltd.
4 * All Rights Reserved.
5 *
6 */
7
8#ifndef HABANALABSP_H_
9#define HABANALABSP_H_
10
Oded Gabbay839c4802019-02-16 00:39:16 +020011#include "include/armcp_if.h"
Oded Gabbay9494a8d2019-02-16 00:39:17 +020012#include "include/qman_if.h"
Oded Gabbay839c4802019-02-16 00:39:16 +020013
Oded Gabbayc4d66342019-02-16 00:39:11 +020014#include <linux/cdev.h>
Oded Gabbay839c4802019-02-16 00:39:16 +020015#include <linux/iopoll.h>
Oded Gabbay1251f232019-02-16 00:39:18 +020016#include <linux/irqreturn.h>
Oded Gabbayeff6f4a2019-02-16 00:39:21 +020017#include <linux/dma-fence.h>
18#include <linux/dma-direction.h>
19#include <linux/scatterlist.h>
Omer Shpigelman0feaf862019-02-16 00:39:22 +020020#include <linux/hashtable.h>
Oded Gabbayc4d66342019-02-16 00:39:11 +020021
22#define HL_NAME "habanalabs"
23
Oded Gabbaybe5d9262019-02-16 00:39:15 +020024#define HL_MMAP_CB_MASK (0x8000000000000000ull >> PAGE_SHIFT)
25
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +020026#define HL_PENDING_RESET_PER_SEC 5
27
Oded Gabbay839c4802019-02-16 00:39:16 +020028#define HL_DEVICE_TIMEOUT_USEC 1000000 /* 1 s */
29
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +020030#define HL_HEARTBEAT_PER_USEC 5000000 /* 5 s */
31
Oded Gabbayd91389b2019-02-16 00:39:19 +020032#define HL_PLL_LOW_JOB_FREQ_USEC 5000000 /* 5 s */
33
Tomer Tayar3110c602019-03-04 10:22:09 +020034#define HL_ARMCP_INFO_TIMEOUT_USEC 10000000 /* 10s */
35#define HL_ARMCP_EEPROM_TIMEOUT_USEC 10000000 /* 10s */
36
Omer Shpigelmana1e537b2019-05-13 14:44:50 +030037#define HL_PCI_ELBI_TIMEOUT_MSEC 10 /* 10ms */
38
Oded Gabbay99b9d7b2019-02-16 00:39:13 +020039#define HL_MAX_QUEUES 128
40
Oded Gabbayeff6f4a2019-02-16 00:39:21 +020041#define HL_MAX_JOBS_PER_CS 64
42
43/* MUST BE POWER OF 2 and larger than 1 */
44#define HL_MAX_PENDING_CS 64
45
Omer Shpigelman0feaf862019-02-16 00:39:22 +020046/* Memory */
47#define MEM_HASH_TABLE_BITS 7 /* 1 << 7 buckets */
48
49/* MMU */
50#define MMU_HASH_TABLE_BITS 7 /* 1 << 7 buckets */
51
52/**
53 * struct pgt_info - MMU hop page info.
Omer Shpigelman66542c32019-02-24 09:17:55 +020054 * @node: hash linked-list node for the pgts shadow hash of pgts.
55 * @phys_addr: physical address of the pgt.
56 * @shadow_addr: shadow hop in the host.
Omer Shpigelman0feaf862019-02-16 00:39:22 +020057 * @ctx: pointer to the owner ctx.
58 * @num_of_ptes: indicates how many ptes are used in the pgt.
59 *
60 * The MMU page tables hierarchy is placed on the DRAM. When a new level (hop)
61 * is needed during mapping, a new page is allocated and this structure holds
62 * its essential information. During unmapping, if no valid PTEs remained in the
63 * page, it is freed with its pgt_info structure.
64 */
65struct pgt_info {
Omer Shpigelman66542c32019-02-24 09:17:55 +020066 struct hlist_node node;
67 u64 phys_addr;
68 u64 shadow_addr;
69 struct hl_ctx *ctx;
70 int num_of_ptes;
Omer Shpigelman0feaf862019-02-16 00:39:22 +020071};
72
Oded Gabbayc4d66342019-02-16 00:39:11 +020073struct hl_device;
Oded Gabbaybe5d9262019-02-16 00:39:15 +020074struct hl_fpriv;
Oded Gabbayc4d66342019-02-16 00:39:11 +020075
Oded Gabbay9494a8d2019-02-16 00:39:17 +020076/**
77 * enum hl_queue_type - Supported QUEUE types.
78 * @QUEUE_TYPE_NA: queue is not available.
79 * @QUEUE_TYPE_EXT: external queue which is a DMA channel that may access the
80 * host.
81 * @QUEUE_TYPE_INT: internal queue that performs DMA inside the device's
82 * memories and/or operates the compute engines.
83 * @QUEUE_TYPE_CPU: S/W queue for communication with the device's CPU.
84 */
85enum hl_queue_type {
86 QUEUE_TYPE_NA,
87 QUEUE_TYPE_EXT,
88 QUEUE_TYPE_INT,
89 QUEUE_TYPE_CPU
90};
91
92/**
93 * struct hw_queue_properties - queue information.
94 * @type: queue type.
95 * @kmd_only: true if only KMD is allowed to send a job to this queue, false
96 * otherwise.
97 */
98struct hw_queue_properties {
99 enum hl_queue_type type;
100 u8 kmd_only;
101};
Oded Gabbayc4d66342019-02-16 00:39:11 +0200102
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200103/**
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200104 * enum vm_type_t - virtual memory mapping request information.
105 * @VM_TYPE_USERPTR: mapping of user memory to device virtual address.
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200106 * @VM_TYPE_PHYS_PACK: mapping of DRAM memory to device virtual address.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200107 */
108enum vm_type_t {
109 VM_TYPE_USERPTR,
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200110 VM_TYPE_PHYS_PACK
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200111};
112
113/**
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +0200114 * enum hl_device_hw_state - H/W device state. use this to understand whether
115 * to do reset before hw_init or not
116 * @HL_DEVICE_HW_STATE_CLEAN: H/W state is clean. i.e. after hard reset
117 * @HL_DEVICE_HW_STATE_DIRTY: H/W state is dirty. i.e. we started to execute
118 * hw_init
119 */
120enum hl_device_hw_state {
121 HL_DEVICE_HW_STATE_CLEAN = 0,
122 HL_DEVICE_HW_STATE_DIRTY
123};
124
125/**
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200126 * struct asic_fixed_properties - ASIC specific immutable properties.
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200127 * @hw_queues_props: H/W queues properties.
Omer Shpigelmand1287492019-05-05 13:24:24 +0300128 * @armcp_info: received various information from ArmCP regarding the H/W, e.g.
Oded Gabbayd91389b2019-02-16 00:39:19 +0200129 * available sensors.
Oded Gabbay839c4802019-02-16 00:39:16 +0200130 * @uboot_ver: F/W U-boot version.
131 * @preboot_ver: F/W Preboot version.
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200132 * @sram_base_address: SRAM physical start address.
133 * @sram_end_address: SRAM physical end address.
134 * @sram_user_base_address - SRAM physical start address for user access.
135 * @dram_base_address: DRAM physical start address.
136 * @dram_end_address: DRAM physical end address.
137 * @dram_user_base_address: DRAM physical start address for user access.
138 * @dram_size: DRAM total size.
139 * @dram_pci_bar_size: size of PCI bar towards DRAM.
Oded Gabbayd91389b2019-02-16 00:39:19 +0200140 * @max_power_default: max power of the device after reset
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200141 * @va_space_host_start_address: base address of virtual memory range for
142 * mapping host memory.
143 * @va_space_host_end_address: end address of virtual memory range for
144 * mapping host memory.
145 * @va_space_dram_start_address: base address of virtual memory range for
146 * mapping DRAM memory.
147 * @va_space_dram_end_address: end address of virtual memory range for
148 * mapping DRAM memory.
Omer Shpigelman27ca384c2019-02-28 10:46:11 +0200149 * @dram_size_for_default_page_mapping: DRAM size needed to map to avoid page
150 * fault.
Tomer Tayarb6f897d2019-03-05 16:48:42 +0200151 * @pcie_dbi_base_address: Base address of the PCIE_DBI block.
152 * @pcie_aux_dbi_reg_addr: Address of the PCIE_AUX DBI register.
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200153 * @mmu_pgt_addr: base physical address in DRAM of MMU page tables.
Omer Shpigelman27ca384c2019-02-28 10:46:11 +0200154 * @mmu_dram_default_page_addr: DRAM default page physical address.
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200155 * @mmu_pgt_size: MMU page tables total size.
156 * @mmu_pte_size: PTE size in MMU page tables.
157 * @mmu_hop_table_size: MMU hop table size.
158 * @mmu_hop0_tables_total_size: total size of MMU hop0 tables.
159 * @dram_page_size: page size for MMU DRAM allocation.
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200160 * @cfg_size: configuration space size on SRAM.
161 * @sram_size: total size of SRAM.
162 * @max_asid: maximum number of open contexts (ASIDs).
Oded Gabbay1251f232019-02-16 00:39:18 +0200163 * @num_of_events: number of possible internal H/W IRQs.
Oded Gabbayd91389b2019-02-16 00:39:19 +0200164 * @psoc_pci_pll_nr: PCI PLL NR value.
165 * @psoc_pci_pll_nf: PCI PLL NF value.
166 * @psoc_pci_pll_od: PCI PLL OD value.
167 * @psoc_pci_pll_div_factor: PCI PLL DIV FACTOR 1 value.
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200168 * @completion_queues_count: number of completion queues.
169 * @high_pll: high PLL frequency used by the device.
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200170 * @cb_pool_cb_cnt: number of CBs in the CB pool.
171 * @cb_pool_cb_size: size of each CB in the CB pool.
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200172 * @tpc_enabled_mask: which TPCs are enabled.
173 */
174struct asic_fixed_properties {
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200175 struct hw_queue_properties hw_queues_props[HL_MAX_QUEUES];
Oded Gabbayd91389b2019-02-16 00:39:19 +0200176 struct armcp_info armcp_info;
Oded Gabbay839c4802019-02-16 00:39:16 +0200177 char uboot_ver[VERSION_MAX_LEN];
178 char preboot_ver[VERSION_MAX_LEN];
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200179 u64 sram_base_address;
180 u64 sram_end_address;
181 u64 sram_user_base_address;
182 u64 dram_base_address;
183 u64 dram_end_address;
184 u64 dram_user_base_address;
185 u64 dram_size;
186 u64 dram_pci_bar_size;
Oded Gabbayd91389b2019-02-16 00:39:19 +0200187 u64 max_power_default;
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200188 u64 va_space_host_start_address;
189 u64 va_space_host_end_address;
190 u64 va_space_dram_start_address;
191 u64 va_space_dram_end_address;
Omer Shpigelman27ca384c2019-02-28 10:46:11 +0200192 u64 dram_size_for_default_page_mapping;
Tomer Tayarb6f897d2019-03-05 16:48:42 +0200193 u64 pcie_dbi_base_address;
194 u64 pcie_aux_dbi_reg_addr;
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200195 u64 mmu_pgt_addr;
Omer Shpigelman27ca384c2019-02-28 10:46:11 +0200196 u64 mmu_dram_default_page_addr;
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200197 u32 mmu_pgt_size;
198 u32 mmu_pte_size;
199 u32 mmu_hop_table_size;
200 u32 mmu_hop0_tables_total_size;
201 u32 dram_page_size;
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200202 u32 cfg_size;
203 u32 sram_size;
204 u32 max_asid;
Oded Gabbay1251f232019-02-16 00:39:18 +0200205 u32 num_of_events;
Oded Gabbayd91389b2019-02-16 00:39:19 +0200206 u32 psoc_pci_pll_nr;
207 u32 psoc_pci_pll_nf;
208 u32 psoc_pci_pll_od;
209 u32 psoc_pci_pll_div_factor;
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200210 u32 high_pll;
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200211 u32 cb_pool_cb_cnt;
212 u32 cb_pool_cb_size;
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200213 u8 completion_queues_count;
214 u8 tpc_enabled_mask;
215};
216
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200217/**
218 * struct hl_dma_fence - wrapper for fence object used by command submissions.
219 * @base_fence: kernel fence object.
220 * @lock: spinlock to protect fence.
221 * @hdev: habanalabs device structure.
222 * @cs_seq: command submission sequence number.
223 */
224struct hl_dma_fence {
225 struct dma_fence base_fence;
226 spinlock_t lock;
227 struct hl_device *hdev;
228 u64 cs_seq;
229};
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200230
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200231/*
232 * Command Buffers
233 */
234
235#define HL_MAX_CB_SIZE 0x200000 /* 2MB */
236
237/**
238 * struct hl_cb_mgr - describes a Command Buffer Manager.
239 * @cb_lock: protects cb_handles.
240 * @cb_handles: an idr to hold all command buffer handles.
241 */
242struct hl_cb_mgr {
243 spinlock_t cb_lock;
244 struct idr cb_handles; /* protected by cb_lock */
245};
246
247/**
248 * struct hl_cb - describes a Command Buffer.
249 * @refcount: reference counter for usage of the CB.
250 * @hdev: pointer to device this CB belongs to.
251 * @lock: spinlock to protect mmap/cs flows.
Oded Gabbayc2164772019-02-16 00:39:24 +0200252 * @debugfs_list: node in debugfs list of command buffers.
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200253 * @pool_list: node in pool list of command buffers.
254 * @kernel_address: Holds the CB's kernel virtual address.
255 * @bus_address: Holds the CB's DMA address.
256 * @mmap_size: Holds the CB's size that was mmaped.
257 * @size: holds the CB's size.
258 * @id: the CB's ID.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200259 * @cs_cnt: holds number of CS that this CB participates in.
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200260 * @ctx_id: holds the ID of the owner's context.
261 * @mmap: true if the CB is currently mmaped to user.
262 * @is_pool: true if CB was acquired from the pool, false otherwise.
263 */
264struct hl_cb {
265 struct kref refcount;
266 struct hl_device *hdev;
267 spinlock_t lock;
Oded Gabbayc2164772019-02-16 00:39:24 +0200268 struct list_head debugfs_list;
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200269 struct list_head pool_list;
270 u64 kernel_address;
271 dma_addr_t bus_address;
272 u32 mmap_size;
273 u32 size;
274 u32 id;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200275 u32 cs_cnt;
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200276 u32 ctx_id;
277 u8 mmap;
278 u8 is_pool;
279};
280
281
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200282/*
283 * QUEUES
284 */
285
286struct hl_cs_job;
287
288/*
289 * Currently, there are two limitations on the maximum length of a queue:
290 *
291 * 1. The memory footprint of the queue. The current allocated space for the
292 * queue is PAGE_SIZE. Because each entry in the queue is HL_BD_SIZE,
293 * the maximum length of the queue can be PAGE_SIZE / HL_BD_SIZE,
294 * which currently is 4096/16 = 256 entries.
295 *
296 * To increase that, we need either to decrease the size of the
297 * BD (difficult), or allocate more than a single page (easier).
298 *
299 * 2. Because the size of the JOB handle field in the BD CTL / completion queue
300 * is 10-bit, we can have up to 1024 open jobs per hardware queue.
301 * Therefore, each queue can hold up to 1024 entries.
302 *
303 * HL_QUEUE_LENGTH is in units of struct hl_bd.
304 * HL_QUEUE_LENGTH * sizeof(struct hl_bd) should be <= HL_PAGE_SIZE
305 */
306
307#define HL_PAGE_SIZE 4096 /* minimum page size */
308/* Must be power of 2 (HL_PAGE_SIZE / HL_BD_SIZE) */
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200309#define HL_QUEUE_LENGTH 256
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200310#define HL_QUEUE_SIZE_IN_BYTES (HL_QUEUE_LENGTH * HL_BD_SIZE)
311
312/*
313 * HL_CQ_LENGTH is in units of struct hl_cq_entry.
314 * HL_CQ_LENGTH should be <= HL_PAGE_SIZE
315 */
316#define HL_CQ_LENGTH HL_QUEUE_LENGTH
317#define HL_CQ_SIZE_IN_BYTES (HL_CQ_LENGTH * HL_CQ_ENTRY_SIZE)
318
Oded Gabbay1251f232019-02-16 00:39:18 +0200319/* Must be power of 2 (HL_PAGE_SIZE / HL_EQ_ENTRY_SIZE) */
320#define HL_EQ_LENGTH 64
321#define HL_EQ_SIZE_IN_BYTES (HL_EQ_LENGTH * HL_EQ_ENTRY_SIZE)
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200322
Oded Gabbay95b5a8b2019-05-29 17:30:04 +0300323/* KMD <-> ArmCP shared memory size */
324#define HL_CPU_ACCESSIBLE_MEM_SIZE SZ_2M
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200325
326/**
327 * struct hl_hw_queue - describes a H/W transport queue.
328 * @shadow_queue: pointer to a shadow queue that holds pointers to jobs.
329 * @queue_type: type of queue.
330 * @kernel_address: holds the queue's kernel virtual address.
331 * @bus_address: holds the queue's DMA address.
332 * @pi: holds the queue's pi value.
333 * @ci: holds the queue's ci value, AS CALCULATED BY THE DRIVER (not real ci).
334 * @hw_queue_id: the id of the H/W queue.
335 * @int_queue_len: length of internal queue (number of entries).
336 * @valid: is the queue valid (we have array of 32 queues, not all of them
337 * exists).
338 */
339struct hl_hw_queue {
340 struct hl_cs_job **shadow_queue;
341 enum hl_queue_type queue_type;
342 u64 kernel_address;
343 dma_addr_t bus_address;
344 u32 pi;
345 u32 ci;
346 u32 hw_queue_id;
347 u16 int_queue_len;
348 u8 valid;
349};
350
351/**
352 * struct hl_cq - describes a completion queue
353 * @hdev: pointer to the device structure
354 * @kernel_address: holds the queue's kernel virtual address
355 * @bus_address: holds the queue's DMA address
356 * @hw_queue_id: the id of the matching H/W queue
357 * @ci: ci inside the queue
358 * @pi: pi inside the queue
359 * @free_slots_cnt: counter of free slots in queue
360 */
361struct hl_cq {
362 struct hl_device *hdev;
363 u64 kernel_address;
364 dma_addr_t bus_address;
365 u32 hw_queue_id;
366 u32 ci;
367 u32 pi;
368 atomic_t free_slots_cnt;
369};
Oded Gabbay0861e412019-02-16 00:39:14 +0200370
Oded Gabbay1251f232019-02-16 00:39:18 +0200371/**
372 * struct hl_eq - describes the event queue (single one per device)
373 * @hdev: pointer to the device structure
374 * @kernel_address: holds the queue's kernel virtual address
375 * @bus_address: holds the queue's DMA address
376 * @ci: ci inside the queue
377 */
378struct hl_eq {
379 struct hl_device *hdev;
380 u64 kernel_address;
381 dma_addr_t bus_address;
382 u32 ci;
383};
384
Oded Gabbay0861e412019-02-16 00:39:14 +0200385
Oded Gabbayc4d66342019-02-16 00:39:11 +0200386/*
387 * ASICs
388 */
389
390/**
391 * enum hl_asic_type - supported ASIC types.
Oded Gabbayc4d66342019-02-16 00:39:11 +0200392 * @ASIC_INVALID: Invalid ASIC type.
Oded Gabbay29593842019-04-04 14:33:34 +0300393 * @ASIC_GOYA: Goya device.
Oded Gabbayc4d66342019-02-16 00:39:11 +0200394 */
395enum hl_asic_type {
Oded Gabbay29593842019-04-04 14:33:34 +0300396 ASIC_INVALID,
397 ASIC_GOYA
Oded Gabbayc4d66342019-02-16 00:39:11 +0200398};
399
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200400struct hl_cs_parser;
401
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200402/**
Oded Gabbayd91389b2019-02-16 00:39:19 +0200403 * enum hl_pm_mng_profile - power management profile.
404 * @PM_AUTO: internal clock is set by KMD.
405 * @PM_MANUAL: internal clock is set by the user.
406 * @PM_LAST: last power management type.
407 */
408enum hl_pm_mng_profile {
409 PM_AUTO = 1,
410 PM_MANUAL,
411 PM_LAST
412};
413
414/**
415 * enum hl_pll_frequency - PLL frequency.
416 * @PLL_HIGH: high frequency.
417 * @PLL_LOW: low frequency.
418 * @PLL_LAST: last frequency values that were configured by the user.
419 */
420enum hl_pll_frequency {
421 PLL_HIGH = 1,
422 PLL_LOW,
423 PLL_LAST
424};
425
426/**
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200427 * struct hl_asic_funcs - ASIC specific functions that are can be called from
428 * common code.
429 * @early_init: sets up early driver state (pre sw_init), doesn't configure H/W.
430 * @early_fini: tears down what was done in early_init.
Oded Gabbayd91389b2019-02-16 00:39:19 +0200431 * @late_init: sets up late driver/hw state (post hw_init) - Optional.
432 * @late_fini: tears down what was done in late_init (pre hw_fini) - Optional.
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200433 * @sw_init: sets up driver state, does not configure H/W.
434 * @sw_fini: tears down driver state, does not configure H/W.
Oded Gabbay839c4802019-02-16 00:39:16 +0200435 * @hw_init: sets up the H/W state.
436 * @hw_fini: tears down the H/W state.
Oded Gabbay1251f232019-02-16 00:39:18 +0200437 * @halt_engines: halt engines, needed for reset sequence. This also disables
438 * interrupts from the device. Should be called before
439 * hw_fini and before CS rollback.
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200440 * @suspend: handles IP specific H/W or SW changes for suspend.
441 * @resume: handles IP specific H/W or SW changes for resume.
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200442 * @cb_mmap: maps a CB.
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200443 * @ring_doorbell: increment PI on a given QMAN.
Oded Gabbayb9040c92019-08-08 15:45:58 +0300444 * @pqe_write: Write the PQ entry to the PQ. This is ASIC-specific
445 * function because the PQs are located in different memory areas
446 * per ASIC (SRAM, DRAM, Host memory) and therefore, the method of
447 * writing the PQE must match the destination memory area
448 * properties.
Oded Gabbayd9c3aa82019-05-01 11:47:04 +0300449 * @asic_dma_alloc_coherent: Allocate coherent DMA memory by calling
450 * dma_alloc_coherent(). This is ASIC function because
451 * its implementation is not trivial when the driver
452 * is loaded in simulation mode (not upstreamed).
453 * @asic_dma_free_coherent: Free coherent DMA memory by calling
454 * dma_free_coherent(). This is ASIC function because
455 * its implementation is not trivial when the driver
456 * is loaded in simulation mode (not upstreamed).
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200457 * @get_int_queue_base: get the internal queue base address.
458 * @test_queues: run simple test on all queues for sanity check.
Oded Gabbayd9c3aa82019-05-01 11:47:04 +0300459 * @asic_dma_pool_zalloc: small DMA allocation of coherent memory from DMA pool.
460 * size of allocation is HL_DMA_POOL_BLK_SIZE.
461 * @asic_dma_pool_free: free small DMA allocation from pool.
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200462 * @cpu_accessible_dma_pool_alloc: allocate CPU PQ packet from DMA pool.
463 * @cpu_accessible_dma_pool_free: free CPU PQ packet from DMA pool.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200464 * @hl_dma_unmap_sg: DMA unmap scatter-gather list.
465 * @cs_parser: parse Command Submission.
466 * @asic_dma_map_sg: DMA map scatter-gather list.
467 * @get_dma_desc_list_size: get number of LIN_DMA packets required for CB.
468 * @add_end_of_cb_packets: Add packets to the end of CB, if device requires it.
Oded Gabbay1251f232019-02-16 00:39:18 +0200469 * @update_eq_ci: update event queue CI.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200470 * @context_switch: called upon ASID context switch.
471 * @restore_phase_topology: clear all SOBs amd MONs.
Oded Gabbayc2164772019-02-16 00:39:24 +0200472 * @debugfs_read32: debug interface for reading u32 from DRAM/SRAM.
473 * @debugfs_write32: debug interface for writing u32 to DRAM/SRAM.
Oded Gabbayd91389b2019-02-16 00:39:19 +0200474 * @add_device_attr: add ASIC specific device attributes.
Oded Gabbay1251f232019-02-16 00:39:18 +0200475 * @handle_eqe: handle event queue entry (IRQ) from ArmCP.
Oded Gabbayd91389b2019-02-16 00:39:19 +0200476 * @set_pll_profile: change PLL profile (manual/automatic).
Oded Gabbay1251f232019-02-16 00:39:18 +0200477 * @get_events_stat: retrieve event queue entries histogram.
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200478 * @read_pte: read MMU page table entry from DRAM.
479 * @write_pte: write MMU page table entry to DRAM.
480 * @mmu_invalidate_cache: flush MMU STLB cache, either with soft (L1 only) or
481 * hard (L0 & L1) flush.
482 * @mmu_invalidate_cache_range: flush specific MMU STLB cache lines with
483 * ASID-VA-size mask.
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +0200484 * @send_heartbeat: send is-alive packet to ArmCP and verify response.
Omer Shpigelman315bc052019-04-01 22:31:22 +0300485 * @debug_coresight: perform certain actions on Coresight for debugging.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200486 * @is_device_idle: return true if device is idle, false otherwise.
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +0200487 * @soft_reset_late_init: perform certain actions needed after soft reset.
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200488 * @hw_queues_lock: acquire H/W queues lock.
489 * @hw_queues_unlock: release H/W queues lock.
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200490 * @get_pci_id: retrieve PCI ID.
Oded Gabbayd91389b2019-02-16 00:39:19 +0200491 * @get_eeprom_data: retrieve EEPROM data from F/W.
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200492 * @send_cpu_message: send buffer to ArmCP.
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +0200493 * @get_hw_state: retrieve the H/W state
Tomer Tayarb6f897d2019-03-05 16:48:42 +0200494 * @pci_bars_map: Map PCI BARs.
Oded Gabbaya38693d2019-04-28 10:18:35 +0300495 * @set_dram_bar_base: Set DRAM BAR to map specific device address. Returns
496 * old address the bar pointed to or U64_MAX for failure
Tomer Tayarb6f897d2019-03-05 16:48:42 +0200497 * @init_iatu: Initialize the iATU unit inside the PCI controller.
Oded Gabbayb2377e02019-04-22 11:49:06 +0300498 * @rreg: Read a register. Needed for simulator support.
499 * @wreg: Write a register. Needed for simulator support.
Omer Shpigelman89225ce2019-05-01 14:38:38 +0300500 * @halt_coresight: stop the ETF and ETR traces.
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200501 */
502struct hl_asic_funcs {
503 int (*early_init)(struct hl_device *hdev);
504 int (*early_fini)(struct hl_device *hdev);
Oded Gabbayd91389b2019-02-16 00:39:19 +0200505 int (*late_init)(struct hl_device *hdev);
506 void (*late_fini)(struct hl_device *hdev);
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200507 int (*sw_init)(struct hl_device *hdev);
508 int (*sw_fini)(struct hl_device *hdev);
Oded Gabbay839c4802019-02-16 00:39:16 +0200509 int (*hw_init)(struct hl_device *hdev);
510 void (*hw_fini)(struct hl_device *hdev, bool hard_reset);
Oded Gabbay1251f232019-02-16 00:39:18 +0200511 void (*halt_engines)(struct hl_device *hdev, bool hard_reset);
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200512 int (*suspend)(struct hl_device *hdev);
513 int (*resume)(struct hl_device *hdev);
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200514 int (*cb_mmap)(struct hl_device *hdev, struct vm_area_struct *vma,
515 u64 kaddress, phys_addr_t paddress, u32 size);
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200516 void (*ring_doorbell)(struct hl_device *hdev, u32 hw_queue_id, u32 pi);
Oded Gabbayb9040c92019-08-08 15:45:58 +0300517 void (*pqe_write)(struct hl_device *hdev, __le64 *pqe,
518 struct hl_bd *bd);
Oded Gabbayd9c3aa82019-05-01 11:47:04 +0300519 void* (*asic_dma_alloc_coherent)(struct hl_device *hdev, size_t size,
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200520 dma_addr_t *dma_handle, gfp_t flag);
Oded Gabbayd9c3aa82019-05-01 11:47:04 +0300521 void (*asic_dma_free_coherent)(struct hl_device *hdev, size_t size,
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200522 void *cpu_addr, dma_addr_t dma_handle);
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200523 void* (*get_int_queue_base)(struct hl_device *hdev, u32 queue_id,
524 dma_addr_t *dma_handle, u16 *queue_len);
525 int (*test_queues)(struct hl_device *hdev);
Oded Gabbayd9c3aa82019-05-01 11:47:04 +0300526 void* (*asic_dma_pool_zalloc)(struct hl_device *hdev, size_t size,
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200527 gfp_t mem_flags, dma_addr_t *dma_handle);
Oded Gabbayd9c3aa82019-05-01 11:47:04 +0300528 void (*asic_dma_pool_free)(struct hl_device *hdev, void *vaddr,
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200529 dma_addr_t dma_addr);
530 void* (*cpu_accessible_dma_pool_alloc)(struct hl_device *hdev,
531 size_t size, dma_addr_t *dma_handle);
532 void (*cpu_accessible_dma_pool_free)(struct hl_device *hdev,
533 size_t size, void *vaddr);
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200534 void (*hl_dma_unmap_sg)(struct hl_device *hdev,
Tomer Tayar94cb6692019-05-01 11:28:15 +0300535 struct scatterlist *sgl, int nents,
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200536 enum dma_data_direction dir);
537 int (*cs_parser)(struct hl_device *hdev, struct hl_cs_parser *parser);
538 int (*asic_dma_map_sg)(struct hl_device *hdev,
Tomer Tayar94cb6692019-05-01 11:28:15 +0300539 struct scatterlist *sgl, int nents,
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200540 enum dma_data_direction dir);
541 u32 (*get_dma_desc_list_size)(struct hl_device *hdev,
542 struct sg_table *sgt);
Oded Gabbay921a4652019-05-12 16:53:16 +0300543 void (*add_end_of_cb_packets)(struct hl_device *hdev,
544 u64 kernel_address, u32 len,
545 u64 cq_addr, u32 cq_val, u32 msix_num);
Oded Gabbay1251f232019-02-16 00:39:18 +0200546 void (*update_eq_ci)(struct hl_device *hdev, u32 val);
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200547 int (*context_switch)(struct hl_device *hdev, u32 asid);
548 void (*restore_phase_topology)(struct hl_device *hdev);
Oded Gabbayc2164772019-02-16 00:39:24 +0200549 int (*debugfs_read32)(struct hl_device *hdev, u64 addr, u32 *val);
550 int (*debugfs_write32)(struct hl_device *hdev, u64 addr, u32 val);
Oded Gabbayd91389b2019-02-16 00:39:19 +0200551 void (*add_device_attr)(struct hl_device *hdev,
552 struct attribute_group *dev_attr_grp);
Oded Gabbay1251f232019-02-16 00:39:18 +0200553 void (*handle_eqe)(struct hl_device *hdev,
554 struct hl_eq_entry *eq_entry);
Oded Gabbayd91389b2019-02-16 00:39:19 +0200555 void (*set_pll_profile)(struct hl_device *hdev,
556 enum hl_pll_frequency freq);
Oded Gabbay1251f232019-02-16 00:39:18 +0200557 void* (*get_events_stat)(struct hl_device *hdev, u32 *size);
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200558 u64 (*read_pte)(struct hl_device *hdev, u64 addr);
559 void (*write_pte)(struct hl_device *hdev, u64 addr, u64 val);
560 void (*mmu_invalidate_cache)(struct hl_device *hdev, bool is_hard);
561 void (*mmu_invalidate_cache_range)(struct hl_device *hdev, bool is_hard,
562 u32 asid, u64 va, u64 size);
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +0200563 int (*send_heartbeat)(struct hl_device *hdev);
Omer Shpigelman315bc052019-04-01 22:31:22 +0300564 int (*debug_coresight)(struct hl_device *hdev, void *data);
Tomer Tayare8960ca2019-07-01 13:59:45 +0000565 bool (*is_device_idle)(struct hl_device *hdev, u32 *mask,
566 struct seq_file *s);
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +0200567 int (*soft_reset_late_init)(struct hl_device *hdev);
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200568 void (*hw_queues_lock)(struct hl_device *hdev);
569 void (*hw_queues_unlock)(struct hl_device *hdev);
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200570 u32 (*get_pci_id)(struct hl_device *hdev);
Oded Gabbayd91389b2019-02-16 00:39:19 +0200571 int (*get_eeprom_data)(struct hl_device *hdev, void *data,
572 size_t max_size);
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200573 int (*send_cpu_message)(struct hl_device *hdev, u32 *msg,
574 u16 len, u32 timeout, long *result);
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +0200575 enum hl_device_hw_state (*get_hw_state)(struct hl_device *hdev);
Tomer Tayarb6f897d2019-03-05 16:48:42 +0200576 int (*pci_bars_map)(struct hl_device *hdev);
Oded Gabbaya38693d2019-04-28 10:18:35 +0300577 u64 (*set_dram_bar_base)(struct hl_device *hdev, u64 addr);
Tomer Tayarb6f897d2019-03-05 16:48:42 +0200578 int (*init_iatu)(struct hl_device *hdev);
Oded Gabbayb2377e02019-04-22 11:49:06 +0300579 u32 (*rreg)(struct hl_device *hdev, u32 reg);
580 void (*wreg)(struct hl_device *hdev, u32 reg, u32 val);
Omer Shpigelman89225ce2019-05-01 14:38:38 +0300581 void (*halt_coresight)(struct hl_device *hdev);
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200582};
Oded Gabbayc4d66342019-02-16 00:39:11 +0200583
Oded Gabbay0861e412019-02-16 00:39:14 +0200584
585/*
586 * CONTEXTS
587 */
588
589#define HL_KERNEL_ASID_ID 0
590
591/**
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200592 * struct hl_va_range - virtual addresses range.
593 * @lock: protects the virtual addresses list.
594 * @list: list of virtual addresses blocks available for mappings.
595 * @start_addr: range start address.
596 * @end_addr: range end address.
597 */
598struct hl_va_range {
599 struct mutex lock;
600 struct list_head list;
601 u64 start_addr;
602 u64 end_addr;
603};
604
605/**
Oded Gabbay0861e412019-02-16 00:39:14 +0200606 * struct hl_ctx - user/kernel context.
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200607 * @mem_hash: holds mapping from virtual address to virtual memory area
608 * descriptor (hl_vm_phys_pg_list or hl_userptr).
Omer Shpigelman66542c32019-02-24 09:17:55 +0200609 * @mmu_phys_hash: holds a mapping from physical address to pgt_info structure.
610 * @mmu_shadow_hash: holds a mapping from shadow address to pgt_info structure.
Oded Gabbay0861e412019-02-16 00:39:14 +0200611 * @hpriv: pointer to the private (KMD) data of the process (fd).
612 * @hdev: pointer to the device structure.
613 * @refcount: reference counter for the context. Context is released only when
614 * this hits 0l. It is incremented on CS and CS_WAIT.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200615 * @cs_pending: array of DMA fence objects representing pending CS.
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200616 * @host_va_range: holds available virtual addresses for host mappings.
617 * @dram_va_range: holds available virtual addresses for DRAM mappings.
618 * @mem_hash_lock: protects the mem_hash.
619 * @mmu_lock: protects the MMU page tables. Any change to the PGT, modifing the
620 * MMU hash or walking the PGT requires talking this lock
Oded Gabbayc2164772019-02-16 00:39:24 +0200621 * @debugfs_list: node in debugfs list of contexts.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200622 * @cs_sequence: sequence number for CS. Value is assigned to a CS and passed
623 * to user so user could inquire about CS. It is used as
624 * index to cs_pending array.
Omer Shpigelman27ca384c2019-02-28 10:46:11 +0200625 * @dram_default_hops: array that holds all hops addresses needed for default
626 * DRAM mapping.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200627 * @cs_lock: spinlock to protect cs_sequence.
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200628 * @dram_phys_mem: amount of used physical DRAM memory by this context.
Oded Gabbay027d35d2019-04-25 20:15:42 +0300629 * @thread_ctx_switch_token: token to prevent multiple threads of the same
630 * context from running the context switch phase.
631 * Only a single thread should run it.
632 * @thread_ctx_switch_wait_token: token to prevent the threads that didn't run
633 * the context switch phase from moving to their
634 * execution phase before the context switch phase
635 * has finished.
Oded Gabbay0861e412019-02-16 00:39:14 +0200636 * @asid: context's unique address space ID in the device's MMU.
637 */
638struct hl_ctx {
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200639 DECLARE_HASHTABLE(mem_hash, MEM_HASH_TABLE_BITS);
Omer Shpigelman66542c32019-02-24 09:17:55 +0200640 DECLARE_HASHTABLE(mmu_phys_hash, MMU_HASH_TABLE_BITS);
641 DECLARE_HASHTABLE(mmu_shadow_hash, MMU_HASH_TABLE_BITS);
Oded Gabbay0861e412019-02-16 00:39:14 +0200642 struct hl_fpriv *hpriv;
643 struct hl_device *hdev;
644 struct kref refcount;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200645 struct dma_fence *cs_pending[HL_MAX_PENDING_CS];
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200646 struct hl_va_range host_va_range;
647 struct hl_va_range dram_va_range;
648 struct mutex mem_hash_lock;
649 struct mutex mmu_lock;
Oded Gabbayc2164772019-02-16 00:39:24 +0200650 struct list_head debugfs_list;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200651 u64 cs_sequence;
Omer Shpigelman27ca384c2019-02-28 10:46:11 +0200652 u64 *dram_default_hops;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200653 spinlock_t cs_lock;
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200654 atomic64_t dram_phys_mem;
Oded Gabbay027d35d2019-04-25 20:15:42 +0300655 atomic_t thread_ctx_switch_token;
656 u32 thread_ctx_switch_wait_token;
Oded Gabbay0861e412019-02-16 00:39:14 +0200657 u32 asid;
658};
659
660/**
661 * struct hl_ctx_mgr - for handling multiple contexts.
662 * @ctx_lock: protects ctx_handles.
663 * @ctx_handles: idr to hold all ctx handles.
664 */
665struct hl_ctx_mgr {
666 struct mutex ctx_lock;
667 struct idr ctx_handles;
668};
669
670
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200671
672/*
673 * COMMAND SUBMISSIONS
674 */
675
676/**
677 * struct hl_userptr - memory mapping chunk information
678 * @vm_type: type of the VM.
679 * @job_node: linked-list node for hanging the object on the Job's list.
680 * @vec: pointer to the frame vector.
681 * @sgt: pointer to the scatter-gather table that holds the pages.
682 * @dir: for DMA unmapping, the direction must be supplied, so save it.
683 * @debugfs_list: node in debugfs list of command submissions.
684 * @addr: user-space virtual pointer to the start of the memory area.
685 * @size: size of the memory area to pin & map.
686 * @dma_mapped: true if the SG was mapped to DMA addresses, false otherwise.
687 */
688struct hl_userptr {
689 enum vm_type_t vm_type; /* must be first */
690 struct list_head job_node;
691 struct frame_vector *vec;
692 struct sg_table *sgt;
693 enum dma_data_direction dir;
694 struct list_head debugfs_list;
695 u64 addr;
696 u32 size;
697 u8 dma_mapped;
698};
699
700/**
701 * struct hl_cs - command submission.
702 * @jobs_in_queue_cnt: per each queue, maintain counter of submitted jobs.
703 * @ctx: the context this CS belongs to.
704 * @job_list: list of the CS's jobs in the various queues.
705 * @job_lock: spinlock for the CS's jobs list. Needed for free_job.
706 * @refcount: reference counter for usage of the CS.
707 * @fence: pointer to the fence object of this CS.
708 * @work_tdr: delayed work node for TDR.
709 * @mirror_node : node in device mirror list of command submissions.
Oded Gabbayc2164772019-02-16 00:39:24 +0200710 * @debugfs_list: node in debugfs list of command submissions.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200711 * @sequence: the sequence number of this CS.
712 * @submitted: true if CS was submitted to H/W.
713 * @completed: true if CS was completed by device.
714 * @timedout : true if CS was timedout.
715 * @tdr_active: true if TDR was activated for this CS (to prevent
716 * double TDR activation).
717 * @aborted: true if CS was aborted due to some device error.
718 */
719struct hl_cs {
720 u8 jobs_in_queue_cnt[HL_MAX_QUEUES];
721 struct hl_ctx *ctx;
722 struct list_head job_list;
723 spinlock_t job_lock;
724 struct kref refcount;
725 struct dma_fence *fence;
726 struct delayed_work work_tdr;
727 struct list_head mirror_node;
Oded Gabbayc2164772019-02-16 00:39:24 +0200728 struct list_head debugfs_list;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200729 u64 sequence;
730 u8 submitted;
731 u8 completed;
732 u8 timedout;
733 u8 tdr_active;
734 u8 aborted;
735};
736
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200737/**
738 * struct hl_cs_job - command submission job.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200739 * @cs_node: the node to hang on the CS jobs list.
740 * @cs: the CS this job belongs to.
741 * @user_cb: the CB we got from the user.
742 * @patched_cb: in case of patching, this is internal CB which is submitted on
743 * the queue instead of the CB we got from the IOCTL.
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200744 * @finish_work: workqueue object to run when job is completed.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200745 * @userptr_list: linked-list of userptr mappings that belong to this job and
746 * wait for completion.
Oded Gabbayc2164772019-02-16 00:39:24 +0200747 * @debugfs_list: node in debugfs list of command submission jobs.
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200748 * @id: the id of this job inside a CS.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200749 * @hw_queue_id: the id of the H/W queue this job is submitted to.
750 * @user_cb_size: the actual size of the CB we got from the user.
751 * @job_cb_size: the actual size of the CB that we put on the queue.
752 * @ext_queue: whether the job is for external queue or internal queue.
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200753 */
754struct hl_cs_job {
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200755 struct list_head cs_node;
756 struct hl_cs *cs;
757 struct hl_cb *user_cb;
758 struct hl_cb *patched_cb;
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200759 struct work_struct finish_work;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200760 struct list_head userptr_list;
Oded Gabbayc2164772019-02-16 00:39:24 +0200761 struct list_head debugfs_list;
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200762 u32 id;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200763 u32 hw_queue_id;
764 u32 user_cb_size;
765 u32 job_cb_size;
766 u8 ext_queue;
767};
768
769/**
770 * struct hl_cs_parser - command submission paerser properties.
771 * @user_cb: the CB we got from the user.
772 * @patched_cb: in case of patching, this is internal CB which is submitted on
773 * the queue instead of the CB we got from the IOCTL.
774 * @job_userptr_list: linked-list of userptr mappings that belong to the related
775 * job and wait for completion.
776 * @cs_sequence: the sequence number of the related CS.
777 * @ctx_id: the ID of the context the related CS belongs to.
778 * @hw_queue_id: the id of the H/W queue this job is submitted to.
779 * @user_cb_size: the actual size of the CB we got from the user.
780 * @patched_cb_size: the size of the CB after parsing.
781 * @ext_queue: whether the job is for external queue or internal queue.
782 * @job_id: the id of the related job inside the related CS.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200783 */
784struct hl_cs_parser {
785 struct hl_cb *user_cb;
786 struct hl_cb *patched_cb;
787 struct list_head *job_userptr_list;
788 u64 cs_sequence;
789 u32 ctx_id;
790 u32 hw_queue_id;
791 u32 user_cb_size;
792 u32 patched_cb_size;
793 u8 ext_queue;
794 u8 job_id;
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200795};
Oded Gabbayd91389b2019-02-16 00:39:19 +0200796
797
Oded Gabbayc4d66342019-02-16 00:39:11 +0200798/*
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200799 * MEMORY STRUCTURE
800 */
801
802/**
803 * struct hl_vm_hash_node - hash element from virtual address to virtual
804 * memory area descriptor (hl_vm_phys_pg_list or
805 * hl_userptr).
806 * @node: node to hang on the hash table in context object.
807 * @vaddr: key virtual address.
808 * @ptr: value pointer (hl_vm_phys_pg_list or hl_userptr).
809 */
810struct hl_vm_hash_node {
811 struct hlist_node node;
812 u64 vaddr;
813 void *ptr;
814};
815
816/**
817 * struct hl_vm_phys_pg_pack - physical page pack.
818 * @vm_type: describes the type of the virtual area descriptor.
819 * @pages: the physical page array.
Omer Shpigelmanbfb1ce12019-03-05 10:59:16 +0200820 * @npages: num physical pages in the pack.
821 * @total_size: total size of all the pages in this list.
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200822 * @mapping_cnt: number of shared mappings.
823 * @asid: the context related to this list.
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200824 * @page_size: size of each page in the pack.
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200825 * @flags: HL_MEM_* flags related to this list.
826 * @handle: the provided handle related to this list.
827 * @offset: offset from the first page.
828 * @contiguous: is contiguous physical memory.
829 * @created_from_userptr: is product of host virtual address.
830 */
831struct hl_vm_phys_pg_pack {
832 enum vm_type_t vm_type; /* must be first */
833 u64 *pages;
Omer Shpigelmanbfb1ce12019-03-05 10:59:16 +0200834 u64 npages;
835 u64 total_size;
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200836 atomic_t mapping_cnt;
837 u32 asid;
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200838 u32 page_size;
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200839 u32 flags;
840 u32 handle;
841 u32 offset;
842 u8 contiguous;
843 u8 created_from_userptr;
844};
845
846/**
847 * struct hl_vm_va_block - virtual range block information.
848 * @node: node to hang on the virtual range list in context object.
849 * @start: virtual range start address.
850 * @end: virtual range end address.
851 * @size: virtual range size.
852 */
853struct hl_vm_va_block {
854 struct list_head node;
855 u64 start;
856 u64 end;
857 u64 size;
858};
859
860/**
861 * struct hl_vm - virtual memory manager for MMU.
862 * @dram_pg_pool: pool for DRAM physical pages of 2MB.
863 * @dram_pg_pool_refcount: reference counter for the pool usage.
864 * @idr_lock: protects the phys_pg_list_handles.
865 * @phys_pg_pack_handles: idr to hold all device allocations handles.
866 * @init_done: whether initialization was done. We need this because VM
867 * initialization might be skipped during device initialization.
868 */
869struct hl_vm {
870 struct gen_pool *dram_pg_pool;
871 struct kref dram_pg_pool_refcount;
872 spinlock_t idr_lock;
873 struct idr phys_pg_pack_handles;
874 u8 init_done;
875};
876
Omer Shpigelman315bc052019-04-01 22:31:22 +0300877
878/*
879 * DEBUG, PROFILING STRUCTURE
880 */
881
882/**
883 * struct hl_debug_params - Coresight debug parameters.
884 * @input: pointer to component specific input parameters.
885 * @output: pointer to component specific output parameters.
886 * @output_size: size of output buffer.
887 * @reg_idx: relevant register ID.
888 * @op: component operation to execute.
889 * @enable: true if to enable component debugging, false otherwise.
890 */
891struct hl_debug_params {
892 void *input;
893 void *output;
894 u32 output_size;
895 u32 reg_idx;
896 u32 op;
897 bool enable;
898};
899
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200900/*
Oded Gabbayc4d66342019-02-16 00:39:11 +0200901 * FILE PRIVATE STRUCTURE
902 */
903
904/**
905 * struct hl_fpriv - process information stored in FD private data.
906 * @hdev: habanalabs device structure.
907 * @filp: pointer to the given file structure.
908 * @taskpid: current process ID.
Oded Gabbay0861e412019-02-16 00:39:14 +0200909 * @ctx: current executing context.
910 * @ctx_mgr: context manager to handle multiple context for this FD.
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200911 * @cb_mgr: command buffer manager to handle multiple buffers for this FD.
Oded Gabbayc2164772019-02-16 00:39:24 +0200912 * @debugfs_list: list of relevant ASIC debugfs.
Oded Gabbayc4d66342019-02-16 00:39:11 +0200913 * @refcount: number of related contexts.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200914 * @restore_phase_mutex: lock for context switch and restore phase.
Oded Gabbayc4d66342019-02-16 00:39:11 +0200915 */
916struct hl_fpriv {
917 struct hl_device *hdev;
918 struct file *filp;
919 struct pid *taskpid;
Oded Gabbay0861e412019-02-16 00:39:14 +0200920 struct hl_ctx *ctx; /* TODO: remove for multiple ctx */
921 struct hl_ctx_mgr ctx_mgr;
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200922 struct hl_cb_mgr cb_mgr;
Oded Gabbayc2164772019-02-16 00:39:24 +0200923 struct list_head debugfs_list;
Oded Gabbayc4d66342019-02-16 00:39:11 +0200924 struct kref refcount;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200925 struct mutex restore_phase_mutex;
Oded Gabbayc4d66342019-02-16 00:39:11 +0200926};
927
928
929/*
Oded Gabbayc2164772019-02-16 00:39:24 +0200930 * DebugFS
931 */
932
933/**
934 * struct hl_info_list - debugfs file ops.
935 * @name: file name.
936 * @show: function to output information.
937 * @write: function to write to the file.
938 */
939struct hl_info_list {
940 const char *name;
941 int (*show)(struct seq_file *s, void *data);
942 ssize_t (*write)(struct file *file, const char __user *buf,
943 size_t count, loff_t *f_pos);
944};
945
946/**
947 * struct hl_debugfs_entry - debugfs dentry wrapper.
948 * @dent: base debugfs entry structure.
949 * @info_ent: dentry realted ops.
950 * @dev_entry: ASIC specific debugfs manager.
951 */
952struct hl_debugfs_entry {
953 struct dentry *dent;
954 const struct hl_info_list *info_ent;
955 struct hl_dbg_device_entry *dev_entry;
956};
957
958/**
959 * struct hl_dbg_device_entry - ASIC specific debugfs manager.
960 * @root: root dentry.
961 * @hdev: habanalabs device structure.
962 * @entry_arr: array of available hl_debugfs_entry.
963 * @file_list: list of available debugfs files.
964 * @file_mutex: protects file_list.
965 * @cb_list: list of available CBs.
966 * @cb_spinlock: protects cb_list.
967 * @cs_list: list of available CSs.
968 * @cs_spinlock: protects cs_list.
969 * @cs_job_list: list of available CB jobs.
970 * @cs_job_spinlock: protects cs_job_list.
971 * @userptr_list: list of available userptrs (virtual memory chunk descriptor).
972 * @userptr_spinlock: protects userptr_list.
973 * @ctx_mem_hash_list: list of available contexts with MMU mappings.
974 * @ctx_mem_hash_spinlock: protects cb_list.
975 * @addr: next address to read/write from/to in read/write32.
976 * @mmu_addr: next virtual address to translate to physical address in mmu_show.
977 * @mmu_asid: ASID to use while translating in mmu_show.
978 * @i2c_bus: generic u8 debugfs file for bus value to use in i2c_data_read.
979 * @i2c_bus: generic u8 debugfs file for address value to use in i2c_data_read.
980 * @i2c_bus: generic u8 debugfs file for register value to use in i2c_data_read.
981 */
982struct hl_dbg_device_entry {
983 struct dentry *root;
984 struct hl_device *hdev;
985 struct hl_debugfs_entry *entry_arr;
986 struct list_head file_list;
987 struct mutex file_mutex;
988 struct list_head cb_list;
989 spinlock_t cb_spinlock;
990 struct list_head cs_list;
991 spinlock_t cs_spinlock;
992 struct list_head cs_job_list;
993 spinlock_t cs_job_spinlock;
994 struct list_head userptr_list;
995 spinlock_t userptr_spinlock;
996 struct list_head ctx_mem_hash_list;
997 spinlock_t ctx_mem_hash_spinlock;
998 u64 addr;
999 u64 mmu_addr;
1000 u32 mmu_asid;
1001 u8 i2c_bus;
1002 u8 i2c_addr;
1003 u8 i2c_reg;
1004};
1005
1006
1007/*
Oded Gabbayc4d66342019-02-16 00:39:11 +02001008 * DEVICES
1009 */
1010
1011/* Theoretical limit only. A single host can only contain up to 4 or 8 PCIe
1012 * x16 cards. In extereme cases, there are hosts that can accommodate 16 cards
1013 */
1014#define HL_MAX_MINORS 256
1015
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001016/*
1017 * Registers read & write functions.
1018 */
1019
1020u32 hl_rreg(struct hl_device *hdev, u32 reg);
1021void hl_wreg(struct hl_device *hdev, u32 reg, u32 val);
1022
Oded Gabbayb2377e02019-04-22 11:49:06 +03001023#define RREG32(reg) hdev->asic_funcs->rreg(hdev, (reg))
1024#define WREG32(reg, v) hdev->asic_funcs->wreg(hdev, (reg), (v))
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001025#define DREG32(reg) pr_info("REGISTER: " #reg " : 0x%08X\n", \
Oded Gabbayb2377e02019-04-22 11:49:06 +03001026 hdev->asic_funcs->rreg(hdev, (reg)))
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001027
1028#define WREG32_P(reg, val, mask) \
1029 do { \
1030 u32 tmp_ = RREG32(reg); \
1031 tmp_ &= (mask); \
1032 tmp_ |= ((val) & ~(mask)); \
1033 WREG32(reg, tmp_); \
1034 } while (0)
1035#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
1036#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
1037
1038#define REG_FIELD_SHIFT(reg, field) reg##_##field##_SHIFT
1039#define REG_FIELD_MASK(reg, field) reg##_##field##_MASK
1040#define WREG32_FIELD(reg, field, val) \
1041 WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | \
1042 (val) << REG_FIELD_SHIFT(reg, field))
1043
Oded Gabbayb2377e02019-04-22 11:49:06 +03001044#define hl_poll_timeout(hdev, addr, val, cond, sleep_us, timeout_us) \
1045({ \
Dalit Ben Zoorb1b53772019-04-30 17:18:51 +03001046 ktime_t __timeout; \
1047 /* timeout should be longer when working with simulator */ \
1048 if (hdev->pdev) \
1049 __timeout = ktime_add_us(ktime_get(), timeout_us); \
1050 else \
1051 __timeout = ktime_add_us(ktime_get(), (timeout_us * 10)); \
Oded Gabbayb2377e02019-04-22 11:49:06 +03001052 might_sleep_if(sleep_us); \
1053 for (;;) { \
1054 (val) = RREG32(addr); \
1055 if (cond) \
1056 break; \
1057 if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \
1058 (val) = RREG32(addr); \
1059 break; \
1060 } \
1061 if (sleep_us) \
1062 usleep_range((sleep_us >> 2) + 1, sleep_us); \
1063 } \
1064 (cond) ? 0 : -ETIMEDOUT; \
1065})
1066
Oded Gabbaya08b51a2019-05-09 01:48:23 +03001067/*
1068 * address in this macro points always to a memory location in the
1069 * host's (server's) memory. That location is updated asynchronously
Ben Segal2aa4e412019-07-18 12:27:00 +00001070 * either by the direct access of the device or by another core.
1071 *
1072 * To work both in LE and BE architectures, we need to distinguish between the
1073 * two states (device or another core updates the memory location). Therefore,
1074 * if mem_written_by_device is true, the host memory being polled will be
1075 * updated directly by the device. If false, the host memory being polled will
1076 * be updated by host CPU. Required so host knows whether or not the memory
1077 * might need to be byte-swapped before returning value to caller.
Oded Gabbaya08b51a2019-05-09 01:48:23 +03001078 */
Ben Segal2aa4e412019-07-18 12:27:00 +00001079#define hl_poll_timeout_memory(hdev, addr, val, cond, sleep_us, timeout_us, \
1080 mem_written_by_device) \
Oded Gabbaya08b51a2019-05-09 01:48:23 +03001081({ \
1082 ktime_t __timeout; \
1083 /* timeout should be longer when working with simulator */ \
1084 if (hdev->pdev) \
1085 __timeout = ktime_add_us(ktime_get(), timeout_us); \
1086 else \
1087 __timeout = ktime_add_us(ktime_get(), (timeout_us * 10)); \
1088 might_sleep_if(sleep_us); \
1089 for (;;) { \
1090 /* Verify we read updates done by other cores or by device */ \
1091 mb(); \
1092 (val) = *((u32 *) (uintptr_t) (addr)); \
Ben Segal2aa4e412019-07-18 12:27:00 +00001093 if (mem_written_by_device) \
1094 (val) = le32_to_cpu(val); \
Oded Gabbaya08b51a2019-05-09 01:48:23 +03001095 if (cond) \
1096 break; \
1097 if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \
1098 (val) = *((u32 *) (uintptr_t) (addr)); \
Ben Segal2aa4e412019-07-18 12:27:00 +00001099 if (mem_written_by_device) \
1100 (val) = le32_to_cpu(val); \
Oded Gabbaya08b51a2019-05-09 01:48:23 +03001101 break; \
1102 } \
1103 if (sleep_us) \
1104 usleep_range((sleep_us >> 2) + 1, sleep_us); \
1105 } \
1106 (cond) ? 0 : -ETIMEDOUT; \
1107})
1108
1109#define hl_poll_timeout_device_memory(hdev, addr, val, cond, sleep_us, \
1110 timeout_us) \
1111({ \
1112 ktime_t __timeout; \
1113 /* timeout should be longer when working with simulator */ \
1114 if (hdev->pdev) \
1115 __timeout = ktime_add_us(ktime_get(), timeout_us); \
1116 else \
1117 __timeout = ktime_add_us(ktime_get(), (timeout_us * 10)); \
1118 might_sleep_if(sleep_us); \
1119 for (;;) { \
1120 (val) = readl(addr); \
1121 if (cond) \
1122 break; \
1123 if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \
1124 (val) = readl(addr); \
1125 break; \
1126 } \
1127 if (sleep_us) \
1128 usleep_range((sleep_us >> 2) + 1, sleep_us); \
1129 } \
1130 (cond) ? 0 : -ETIMEDOUT; \
1131})
Oded Gabbayb2377e02019-04-22 11:49:06 +03001132
Oded Gabbayd91389b2019-02-16 00:39:19 +02001133struct hwmon_chip_info;
1134
Oded Gabbayc4d66342019-02-16 00:39:11 +02001135/**
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02001136 * struct hl_device_reset_work - reset workqueue task wrapper.
1137 * @reset_work: reset work to be done.
1138 * @hdev: habanalabs device structure.
1139 */
1140struct hl_device_reset_work {
1141 struct work_struct reset_work;
1142 struct hl_device *hdev;
1143};
1144
1145/**
Oded Gabbayc4d66342019-02-16 00:39:11 +02001146 * struct hl_device - habanalabs device structure.
1147 * @pdev: pointer to PCI device, can be NULL in case of simulator device.
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001148 * @pcie_bar: array of available PCIe bars.
1149 * @rmmio: configuration area address on SRAM.
Oded Gabbayc4d66342019-02-16 00:39:11 +02001150 * @cdev: related char device.
1151 * @dev: realted kernel basic device structure.
Oded Gabbayd91389b2019-02-16 00:39:19 +02001152 * @work_freq: delayed work to lower device frequency if possible.
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02001153 * @work_heartbeat: delayed work for ArmCP is-alive check.
Oded Gabbayc4d66342019-02-16 00:39:11 +02001154 * @asic_name: ASIC specific nmae.
1155 * @asic_type: ASIC specific type.
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001156 * @completion_queue: array of hl_cq.
1157 * @cq_wq: work queue of completion queues for executing work in process context
1158 * @eq_wq: work queue of event queue for executing work in process context.
Oded Gabbay0861e412019-02-16 00:39:14 +02001159 * @kernel_ctx: KMD context structure.
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001160 * @kernel_queues: array of hl_hw_queue.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001161 * @hw_queues_mirror_list: CS mirror list for TDR.
1162 * @hw_queues_mirror_lock: protects hw_queues_mirror_list.
Oded Gabbaybe5d9262019-02-16 00:39:15 +02001163 * @kernel_cb_mgr: command buffer manager for creating/destroying/handling CGs.
Oded Gabbay1251f232019-02-16 00:39:18 +02001164 * @event_queue: event queue for IRQ from ArmCP.
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001165 * @dma_pool: DMA pool for small allocations.
1166 * @cpu_accessible_dma_mem: KMD <-> ArmCP shared memory CPU address.
1167 * @cpu_accessible_dma_address: KMD <-> ArmCP shared memory DMA address.
1168 * @cpu_accessible_dma_pool: KMD <-> ArmCP shared memory pool.
Oded Gabbay0861e412019-02-16 00:39:14 +02001169 * @asid_bitmap: holds used/available ASIDs.
1170 * @asid_mutex: protects asid_bitmap.
1171 * @fd_open_cnt_lock: lock for updating fd_open_cnt in hl_device_open. Although
1172 * fd_open_cnt is atomic, we need this lock to serialize
1173 * the open function because the driver currently supports
1174 * only a single process at a time. In addition, we need a
1175 * lock here so we can flush user processes which are opening
1176 * the device while we are trying to hard reset it
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001177 * @send_cpu_message_lock: enforces only one message in KMD <-> ArmCP queue.
Oded Gabbay19734972019-05-04 17:36:06 +03001178 * @debug_lock: protects critical section of setting debug mode for device
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001179 * @asic_prop: ASIC specific immutable properties.
1180 * @asic_funcs: ASIC specific functions.
1181 * @asic_specific: ASIC specific information to use only from ASIC files.
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001182 * @mmu_pgt_pool: pool of available MMU hops.
1183 * @vm: virtual memory manager for MMU.
Omer Shpigelman66542c32019-02-24 09:17:55 +02001184 * @mmu_cache_lock: protects MMU cache invalidation as it can serve one context.
1185 * @mmu_shadow_hop0: shadow mapping of the MMU hop 0 zone.
Oded Gabbayd91389b2019-02-16 00:39:19 +02001186 * @hwmon_dev: H/W monitor device.
1187 * @pm_mng_profile: current power management profile.
1188 * @hl_chip_info: ASIC's sensors information.
Oded Gabbayc2164772019-02-16 00:39:24 +02001189 * @hl_debugfs: device's debugfs manager.
Oded Gabbaybe5d9262019-02-16 00:39:15 +02001190 * @cb_pool: list of preallocated CBs.
1191 * @cb_pool_lock: protects the CB pool.
Oded Gabbay0861e412019-02-16 00:39:14 +02001192 * @user_ctx: current user context executing.
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001193 * @dram_used_mem: current DRAM memory consumption.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001194 * @timeout_jiffies: device CS timeout value.
Oded Gabbayd91389b2019-02-16 00:39:19 +02001195 * @max_power: the max power of the device, as configured by the sysadmin. This
1196 * value is saved so in case of hard-reset, KMD will restore this
1197 * value and update the F/W after the re-initialization
Oded Gabbaycbaa99e2019-03-03 15:13:15 +02001198 * @in_reset: is device in reset flow.
1199 * @curr_pll_profile: current PLL profile.
1200 * @fd_open_cnt: number of open user processes.
1201 * @cs_active_cnt: number of active command submissions on this device (active
1202 * means already in H/W queues)
Oded Gabbayc4d66342019-02-16 00:39:11 +02001203 * @major: habanalabs KMD major.
Oded Gabbayd91389b2019-02-16 00:39:19 +02001204 * @high_pll: high PLL profile frequency.
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02001205 * @soft_reset_cnt: number of soft reset since KMD loading.
1206 * @hard_reset_cnt: number of hard reset since KMD loading.
Oded Gabbayc4d66342019-02-16 00:39:11 +02001207 * @id: device minor.
1208 * @disabled: is device disabled.
Oded Gabbayd91389b2019-02-16 00:39:19 +02001209 * @late_init_done: is late init stage was done during initialization.
1210 * @hwmon_initialized: is H/W monitor sensors was initialized.
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02001211 * @hard_reset_pending: is there a hard reset work pending.
1212 * @heartbeat: is heartbeat sanity check towards ArmCP enabled.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001213 * @reset_on_lockup: true if a reset should be done in case of stuck CS, false
1214 * otherwise.
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001215 * @dram_supports_virtual_memory: is MMU enabled towards DRAM.
Omer Shpigelman27ca384c2019-02-28 10:46:11 +02001216 * @dram_default_page_mapping: is DRAM default page mapping enabled.
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02001217 * @init_done: is the initialization of the device done.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001218 * @mmu_enable: is MMU enabled.
Oded Gabbaya28ce422019-02-28 10:46:12 +02001219 * @device_cpu_disabled: is the device CPU disabled (due to timeouts)
Oded Gabbayd9973872019-03-07 18:03:23 +02001220 * @dma_mask: the dma mask that was set for this device
Oded Gabbay19734972019-05-04 17:36:06 +03001221 * @in_debug: is device under debug. This, together with fd_open_cnt, enforces
1222 * that only a single user is configuring the debug infrastructure.
Oded Gabbayc4d66342019-02-16 00:39:11 +02001223 */
1224struct hl_device {
1225 struct pci_dev *pdev;
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001226 void __iomem *pcie_bar[6];
1227 void __iomem *rmmio;
Oded Gabbayc4d66342019-02-16 00:39:11 +02001228 struct cdev cdev;
1229 struct device *dev;
Oded Gabbayd91389b2019-02-16 00:39:19 +02001230 struct delayed_work work_freq;
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02001231 struct delayed_work work_heartbeat;
Oded Gabbayc4d66342019-02-16 00:39:11 +02001232 char asic_name[16];
1233 enum hl_asic_type asic_type;
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001234 struct hl_cq *completion_queue;
1235 struct workqueue_struct *cq_wq;
Oded Gabbay1251f232019-02-16 00:39:18 +02001236 struct workqueue_struct *eq_wq;
Oded Gabbay0861e412019-02-16 00:39:14 +02001237 struct hl_ctx *kernel_ctx;
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001238 struct hl_hw_queue *kernel_queues;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001239 struct list_head hw_queues_mirror_list;
1240 spinlock_t hw_queues_mirror_lock;
Oded Gabbaybe5d9262019-02-16 00:39:15 +02001241 struct hl_cb_mgr kernel_cb_mgr;
Oded Gabbay1251f232019-02-16 00:39:18 +02001242 struct hl_eq event_queue;
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001243 struct dma_pool *dma_pool;
1244 void *cpu_accessible_dma_mem;
1245 dma_addr_t cpu_accessible_dma_address;
1246 struct gen_pool *cpu_accessible_dma_pool;
Oded Gabbay0861e412019-02-16 00:39:14 +02001247 unsigned long *asid_bitmap;
1248 struct mutex asid_mutex;
1249 /* TODO: remove fd_open_cnt_lock for multiple process support */
1250 struct mutex fd_open_cnt_lock;
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001251 struct mutex send_cpu_message_lock;
Oded Gabbay19734972019-05-04 17:36:06 +03001252 struct mutex debug_lock;
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001253 struct asic_fixed_properties asic_prop;
1254 const struct hl_asic_funcs *asic_funcs;
1255 void *asic_specific;
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001256 struct gen_pool *mmu_pgt_pool;
1257 struct hl_vm vm;
1258 struct mutex mmu_cache_lock;
Omer Shpigelman66542c32019-02-24 09:17:55 +02001259 void *mmu_shadow_hop0;
Oded Gabbayd91389b2019-02-16 00:39:19 +02001260 struct device *hwmon_dev;
1261 enum hl_pm_mng_profile pm_mng_profile;
1262 struct hwmon_chip_info *hl_chip_info;
Oded Gabbaybe5d9262019-02-16 00:39:15 +02001263
Oded Gabbayc2164772019-02-16 00:39:24 +02001264 struct hl_dbg_device_entry hl_debugfs;
1265
Oded Gabbaybe5d9262019-02-16 00:39:15 +02001266 struct list_head cb_pool;
1267 spinlock_t cb_pool_lock;
1268
Oded Gabbay0861e412019-02-16 00:39:14 +02001269 /* TODO: remove user_ctx for multiple process support */
1270 struct hl_ctx *user_ctx;
Oded Gabbayd91389b2019-02-16 00:39:19 +02001271
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001272 atomic64_t dram_used_mem;
Oded Gabbaycbaa99e2019-03-03 15:13:15 +02001273 u64 timeout_jiffies;
1274 u64 max_power;
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02001275 atomic_t in_reset;
Oded Gabbayd91389b2019-02-16 00:39:19 +02001276 atomic_t curr_pll_profile;
Oded Gabbay0861e412019-02-16 00:39:14 +02001277 atomic_t fd_open_cnt;
Oded Gabbaycbaa99e2019-03-03 15:13:15 +02001278 atomic_t cs_active_cnt;
Oded Gabbayc4d66342019-02-16 00:39:11 +02001279 u32 major;
Oded Gabbayd91389b2019-02-16 00:39:19 +02001280 u32 high_pll;
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02001281 u32 soft_reset_cnt;
1282 u32 hard_reset_cnt;
Oded Gabbayc4d66342019-02-16 00:39:11 +02001283 u16 id;
1284 u8 disabled;
Oded Gabbayd91389b2019-02-16 00:39:19 +02001285 u8 late_init_done;
1286 u8 hwmon_initialized;
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02001287 u8 hard_reset_pending;
1288 u8 heartbeat;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001289 u8 reset_on_lockup;
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001290 u8 dram_supports_virtual_memory;
Omer Shpigelman27ca384c2019-02-28 10:46:11 +02001291 u8 dram_default_page_mapping;
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02001292 u8 init_done;
Oded Gabbaya28ce422019-02-28 10:46:12 +02001293 u8 device_cpu_disabled;
Oded Gabbayd9973872019-03-07 18:03:23 +02001294 u8 dma_mask;
Oded Gabbay19734972019-05-04 17:36:06 +03001295 u8 in_debug;
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001296
1297 /* Parameters for bring-up */
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001298 u8 mmu_enable;
Oded Gabbay839c4802019-02-16 00:39:16 +02001299 u8 cpu_enable;
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001300 u8 reset_pcilink;
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001301 u8 cpu_queues_enable;
Oded Gabbay839c4802019-02-16 00:39:16 +02001302 u8 fw_loading;
1303 u8 pldm;
Oded Gabbayc4d66342019-02-16 00:39:11 +02001304};
1305
1306
1307/*
1308 * IOCTLs
1309 */
1310
1311/**
1312 * typedef hl_ioctl_t - typedef for ioctl function in the driver
1313 * @hpriv: pointer to the FD's private data, which contains state of
1314 * user process
1315 * @data: pointer to the input/output arguments structure of the IOCTL
1316 *
1317 * Return: 0 for success, negative value for error
1318 */
1319typedef int hl_ioctl_t(struct hl_fpriv *hpriv, void *data);
1320
1321/**
1322 * struct hl_ioctl_desc - describes an IOCTL entry of the driver.
1323 * @cmd: the IOCTL code as created by the kernel macros.
1324 * @func: pointer to the driver's function that should be called for this IOCTL.
1325 */
1326struct hl_ioctl_desc {
1327 unsigned int cmd;
1328 hl_ioctl_t *func;
1329};
1330
1331
1332/*
1333 * Kernel module functions that can be accessed by entire module
1334 */
1335
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001336/**
1337 * hl_mem_area_inside_range() - Checks whether address+size are inside a range.
1338 * @address: The start address of the area we want to validate.
1339 * @size: The size in bytes of the area we want to validate.
1340 * @range_start_address: The start address of the valid range.
1341 * @range_end_address: The end address of the valid range.
1342 *
1343 * Return: true if the area is inside the valid range, false otherwise.
1344 */
1345static inline bool hl_mem_area_inside_range(u64 address, u32 size,
1346 u64 range_start_address, u64 range_end_address)
1347{
1348 u64 end_address = address + size;
1349
1350 if ((address >= range_start_address) &&
1351 (end_address <= range_end_address) &&
1352 (end_address > address))
1353 return true;
1354
1355 return false;
1356}
1357
1358/**
1359 * hl_mem_area_crosses_range() - Checks whether address+size crossing a range.
1360 * @address: The start address of the area we want to validate.
1361 * @size: The size in bytes of the area we want to validate.
1362 * @range_start_address: The start address of the valid range.
1363 * @range_end_address: The end address of the valid range.
1364 *
1365 * Return: true if the area overlaps part or all of the valid range,
1366 * false otherwise.
1367 */
1368static inline bool hl_mem_area_crosses_range(u64 address, u32 size,
1369 u64 range_start_address, u64 range_end_address)
1370{
1371 u64 end_address = address + size;
1372
1373 if ((address >= range_start_address) &&
1374 (address < range_end_address))
1375 return true;
1376
1377 if ((end_address >= range_start_address) &&
1378 (end_address < range_end_address))
1379 return true;
1380
1381 if ((address < range_start_address) &&
1382 (end_address >= range_end_address))
1383 return true;
1384
1385 return false;
1386}
1387
Oded Gabbayc4d66342019-02-16 00:39:11 +02001388int hl_device_open(struct inode *inode, struct file *filp);
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02001389bool hl_device_disabled_or_in_reset(struct hl_device *hdev);
Dalit Ben Zooraa957082019-03-24 10:15:44 +02001390enum hl_device_status hl_device_status(struct hl_device *hdev);
Oded Gabbay19734972019-05-04 17:36:06 +03001391int hl_device_set_debug_mode(struct hl_device *hdev, bool enable);
Oded Gabbayc4d66342019-02-16 00:39:11 +02001392int create_hdev(struct hl_device **dev, struct pci_dev *pdev,
1393 enum hl_asic_type asic_type, int minor);
1394void destroy_hdev(struct hl_device *hdev);
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001395int hl_hw_queues_create(struct hl_device *hdev);
1396void hl_hw_queues_destroy(struct hl_device *hdev);
1397int hl_hw_queue_send_cb_no_cmpl(struct hl_device *hdev, u32 hw_queue_id,
1398 u32 cb_size, u64 cb_ptr);
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001399int hl_hw_queue_schedule_cs(struct hl_cs *cs);
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001400u32 hl_hw_queue_add_ptr(u32 ptr, u16 val);
1401void hl_hw_queue_inc_ci_kernel(struct hl_device *hdev, u32 hw_queue_id);
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001402void hl_int_hw_queue_update_ci(struct hl_cs *cs);
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02001403void hl_hw_queue_reset(struct hl_device *hdev, bool hard_reset);
Oded Gabbayc4d66342019-02-16 00:39:11 +02001404
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001405#define hl_queue_inc_ptr(p) hl_hw_queue_add_ptr(p, 1)
1406#define hl_pi_2_offset(pi) ((pi) & (HL_QUEUE_LENGTH - 1))
1407
1408int hl_cq_init(struct hl_device *hdev, struct hl_cq *q, u32 hw_queue_id);
1409void hl_cq_fini(struct hl_device *hdev, struct hl_cq *q);
Oded Gabbay1251f232019-02-16 00:39:18 +02001410int hl_eq_init(struct hl_device *hdev, struct hl_eq *q);
1411void hl_eq_fini(struct hl_device *hdev, struct hl_eq *q);
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02001412void hl_cq_reset(struct hl_device *hdev, struct hl_cq *q);
1413void hl_eq_reset(struct hl_device *hdev, struct hl_eq *q);
Oded Gabbay1251f232019-02-16 00:39:18 +02001414irqreturn_t hl_irq_handler_cq(int irq, void *arg);
1415irqreturn_t hl_irq_handler_eq(int irq, void *arg);
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001416u32 hl_cq_inc_ptr(u32 ptr);
1417
Oded Gabbay0861e412019-02-16 00:39:14 +02001418int hl_asid_init(struct hl_device *hdev);
1419void hl_asid_fini(struct hl_device *hdev);
1420unsigned long hl_asid_alloc(struct hl_device *hdev);
1421void hl_asid_free(struct hl_device *hdev, unsigned long asid);
1422
1423int hl_ctx_create(struct hl_device *hdev, struct hl_fpriv *hpriv);
1424void hl_ctx_free(struct hl_device *hdev, struct hl_ctx *ctx);
1425int hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx);
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001426void hl_ctx_do_release(struct kref *ref);
1427void hl_ctx_get(struct hl_device *hdev, struct hl_ctx *ctx);
Oded Gabbay0861e412019-02-16 00:39:14 +02001428int hl_ctx_put(struct hl_ctx *ctx);
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001429struct dma_fence *hl_ctx_get_fence(struct hl_ctx *ctx, u64 seq);
Oded Gabbay0861e412019-02-16 00:39:14 +02001430void hl_ctx_mgr_init(struct hl_ctx_mgr *mgr);
1431void hl_ctx_mgr_fini(struct hl_device *hdev, struct hl_ctx_mgr *mgr);
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001432
Oded Gabbayc4d66342019-02-16 00:39:11 +02001433int hl_device_init(struct hl_device *hdev, struct class *hclass);
1434void hl_device_fini(struct hl_device *hdev);
1435int hl_device_suspend(struct hl_device *hdev);
1436int hl_device_resume(struct hl_device *hdev);
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02001437int hl_device_reset(struct hl_device *hdev, bool hard_reset,
1438 bool from_hard_reset_thread);
Oded Gabbay0861e412019-02-16 00:39:14 +02001439void hl_hpriv_get(struct hl_fpriv *hpriv);
1440void hl_hpriv_put(struct hl_fpriv *hpriv);
Oded Gabbayd91389b2019-02-16 00:39:19 +02001441int hl_device_set_frequency(struct hl_device *hdev, enum hl_pll_frequency freq);
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001442
Oded Gabbayd91389b2019-02-16 00:39:19 +02001443int hl_build_hwmon_channel_info(struct hl_device *hdev,
1444 struct armcp_sensor *sensors_arr);
1445
1446int hl_sysfs_init(struct hl_device *hdev);
1447void hl_sysfs_fini(struct hl_device *hdev);
1448
1449int hl_hwmon_init(struct hl_device *hdev);
1450void hl_hwmon_fini(struct hl_device *hdev);
Oded Gabbayc4d66342019-02-16 00:39:11 +02001451
Oded Gabbaybe5d9262019-02-16 00:39:15 +02001452int hl_cb_create(struct hl_device *hdev, struct hl_cb_mgr *mgr, u32 cb_size,
1453 u64 *handle, int ctx_id);
1454int hl_cb_destroy(struct hl_device *hdev, struct hl_cb_mgr *mgr, u64 cb_handle);
1455int hl_cb_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma);
1456struct hl_cb *hl_cb_get(struct hl_device *hdev, struct hl_cb_mgr *mgr,
1457 u32 handle);
1458void hl_cb_put(struct hl_cb *cb);
1459void hl_cb_mgr_init(struct hl_cb_mgr *mgr);
1460void hl_cb_mgr_fini(struct hl_device *hdev, struct hl_cb_mgr *mgr);
1461struct hl_cb *hl_cb_kernel_create(struct hl_device *hdev, u32 cb_size);
1462int hl_cb_pool_init(struct hl_device *hdev);
1463int hl_cb_pool_fini(struct hl_device *hdev);
1464
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001465void hl_cs_rollback_all(struct hl_device *hdev);
1466struct hl_cs_job *hl_cs_allocate_job(struct hl_device *hdev, bool ext_queue);
1467
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001468void goya_set_asic_funcs(struct hl_device *hdev);
1469
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001470int hl_vm_ctx_init(struct hl_ctx *ctx);
1471void hl_vm_ctx_fini(struct hl_ctx *ctx);
1472
1473int hl_vm_init(struct hl_device *hdev);
1474void hl_vm_fini(struct hl_device *hdev);
1475
Oded Gabbay230afe72019-02-27 00:19:18 +02001476int hl_pin_host_memory(struct hl_device *hdev, u64 addr, u64 size,
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001477 struct hl_userptr *userptr);
1478int hl_unpin_host_memory(struct hl_device *hdev, struct hl_userptr *userptr);
1479void hl_userptr_delete_list(struct hl_device *hdev,
1480 struct list_head *userptr_list);
1481bool hl_userptr_is_pinned(struct hl_device *hdev, u64 addr, u32 size,
1482 struct list_head *userptr_list,
1483 struct hl_userptr **userptr);
1484
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001485int hl_mmu_init(struct hl_device *hdev);
1486void hl_mmu_fini(struct hl_device *hdev);
Omer Shpigelman27ca384c2019-02-28 10:46:11 +02001487int hl_mmu_ctx_init(struct hl_ctx *ctx);
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001488void hl_mmu_ctx_fini(struct hl_ctx *ctx);
1489int hl_mmu_map(struct hl_ctx *ctx, u64 virt_addr, u64 phys_addr, u32 page_size);
1490int hl_mmu_unmap(struct hl_ctx *ctx, u64 virt_addr, u32 page_size);
1491void hl_mmu_swap_out(struct hl_ctx *ctx);
1492void hl_mmu_swap_in(struct hl_ctx *ctx);
1493
Tomer Tayar3110c602019-03-04 10:22:09 +02001494int hl_fw_push_fw_to_device(struct hl_device *hdev, const char *fw_name,
1495 void __iomem *dst);
1496int hl_fw_send_pci_access_msg(struct hl_device *hdev, u32 opcode);
1497int hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg,
1498 u16 len, u32 timeout, long *result);
1499int hl_fw_test_cpu_queue(struct hl_device *hdev);
1500void *hl_fw_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size,
1501 dma_addr_t *dma_handle);
1502void hl_fw_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size,
1503 void *vaddr);
1504int hl_fw_send_heartbeat(struct hl_device *hdev);
1505int hl_fw_armcp_info_get(struct hl_device *hdev);
1506int hl_fw_get_eeprom_data(struct hl_device *hdev, void *data, size_t max_size);
1507
Tomer Tayarb6f897d2019-03-05 16:48:42 +02001508int hl_pci_bars_map(struct hl_device *hdev, const char * const name[3],
1509 bool is_wc[3]);
1510int hl_pci_iatu_write(struct hl_device *hdev, u32 addr, u32 data);
1511int hl_pci_set_dram_bar_base(struct hl_device *hdev, u8 inbound_region, u8 bar,
1512 u64 addr);
1513int hl_pci_init_iatu(struct hl_device *hdev, u64 sram_base_address,
Tomer Tayar94cb6692019-05-01 11:28:15 +03001514 u64 dram_base_address, u64 host_phys_base_address,
1515 u64 host_phys_size);
Oded Gabbayd9973872019-03-07 18:03:23 +02001516int hl_pci_init(struct hl_device *hdev, u8 dma_mask);
Tomer Tayarb6f897d2019-03-05 16:48:42 +02001517void hl_pci_fini(struct hl_device *hdev);
Oded Gabbayd9973872019-03-07 18:03:23 +02001518int hl_pci_set_dma_mask(struct hl_device *hdev, u8 dma_mask);
Tomer Tayarb6f897d2019-03-05 16:48:42 +02001519
Oded Gabbayd91389b2019-02-16 00:39:19 +02001520long hl_get_frequency(struct hl_device *hdev, u32 pll_index, bool curr);
1521void hl_set_frequency(struct hl_device *hdev, u32 pll_index, u64 freq);
1522long hl_get_temperature(struct hl_device *hdev, int sensor_index, u32 attr);
1523long hl_get_voltage(struct hl_device *hdev, int sensor_index, u32 attr);
1524long hl_get_current(struct hl_device *hdev, int sensor_index, u32 attr);
1525long hl_get_fan_speed(struct hl_device *hdev, int sensor_index, u32 attr);
1526long hl_get_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr);
1527void hl_set_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr,
1528 long value);
1529u64 hl_get_max_power(struct hl_device *hdev);
1530void hl_set_max_power(struct hl_device *hdev, u64 value);
1531
Oded Gabbayc2164772019-02-16 00:39:24 +02001532#ifdef CONFIG_DEBUG_FS
1533
1534void hl_debugfs_init(void);
1535void hl_debugfs_fini(void);
1536void hl_debugfs_add_device(struct hl_device *hdev);
1537void hl_debugfs_remove_device(struct hl_device *hdev);
1538void hl_debugfs_add_file(struct hl_fpriv *hpriv);
1539void hl_debugfs_remove_file(struct hl_fpriv *hpriv);
1540void hl_debugfs_add_cb(struct hl_cb *cb);
1541void hl_debugfs_remove_cb(struct hl_cb *cb);
1542void hl_debugfs_add_cs(struct hl_cs *cs);
1543void hl_debugfs_remove_cs(struct hl_cs *cs);
1544void hl_debugfs_add_job(struct hl_device *hdev, struct hl_cs_job *job);
1545void hl_debugfs_remove_job(struct hl_device *hdev, struct hl_cs_job *job);
1546void hl_debugfs_add_userptr(struct hl_device *hdev, struct hl_userptr *userptr);
1547void hl_debugfs_remove_userptr(struct hl_device *hdev,
1548 struct hl_userptr *userptr);
1549void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx);
1550void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx);
1551
1552#else
1553
1554static inline void __init hl_debugfs_init(void)
1555{
1556}
1557
1558static inline void hl_debugfs_fini(void)
1559{
1560}
1561
1562static inline void hl_debugfs_add_device(struct hl_device *hdev)
1563{
1564}
1565
1566static inline void hl_debugfs_remove_device(struct hl_device *hdev)
1567{
1568}
1569
1570static inline void hl_debugfs_add_file(struct hl_fpriv *hpriv)
1571{
1572}
1573
1574static inline void hl_debugfs_remove_file(struct hl_fpriv *hpriv)
1575{
1576}
1577
1578static inline void hl_debugfs_add_cb(struct hl_cb *cb)
1579{
1580}
1581
1582static inline void hl_debugfs_remove_cb(struct hl_cb *cb)
1583{
1584}
1585
1586static inline void hl_debugfs_add_cs(struct hl_cs *cs)
1587{
1588}
1589
1590static inline void hl_debugfs_remove_cs(struct hl_cs *cs)
1591{
1592}
1593
1594static inline void hl_debugfs_add_job(struct hl_device *hdev,
1595 struct hl_cs_job *job)
1596{
1597}
1598
1599static inline void hl_debugfs_remove_job(struct hl_device *hdev,
1600 struct hl_cs_job *job)
1601{
1602}
1603
1604static inline void hl_debugfs_add_userptr(struct hl_device *hdev,
1605 struct hl_userptr *userptr)
1606{
1607}
1608
1609static inline void hl_debugfs_remove_userptr(struct hl_device *hdev,
1610 struct hl_userptr *userptr)
1611{
1612}
1613
1614static inline void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev,
1615 struct hl_ctx *ctx)
1616{
1617}
1618
1619static inline void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev,
1620 struct hl_ctx *ctx)
1621{
1622}
1623
1624#endif
1625
Oded Gabbaybe5d9262019-02-16 00:39:15 +02001626/* IOCTLs */
1627long hl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
1628int hl_cb_ioctl(struct hl_fpriv *hpriv, void *data);
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001629int hl_cs_ioctl(struct hl_fpriv *hpriv, void *data);
1630int hl_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data);
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001631int hl_mem_ioctl(struct hl_fpriv *hpriv, void *data);
Oded Gabbaybe5d9262019-02-16 00:39:15 +02001632
Oded Gabbayc4d66342019-02-16 00:39:11 +02001633#endif /* HABANALABSP_H_ */