18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci *
38c2ecf20Sopenharmony_ci * Copyright 2016-2019 HabanaLabs, Ltd.
48c2ecf20Sopenharmony_ci * All Rights Reserved.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef HABANALABSP_H_
98c2ecf20Sopenharmony_ci#define HABANALABSP_H_
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include "../include/common/cpucp_if.h"
128c2ecf20Sopenharmony_ci#include "../include/common/qman_if.h"
138c2ecf20Sopenharmony_ci#include <uapi/misc/habanalabs.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <linux/cdev.h>
168c2ecf20Sopenharmony_ci#include <linux/iopoll.h>
178c2ecf20Sopenharmony_ci#include <linux/irqreturn.h>
188c2ecf20Sopenharmony_ci#include <linux/dma-direction.h>
198c2ecf20Sopenharmony_ci#include <linux/scatterlist.h>
208c2ecf20Sopenharmony_ci#include <linux/hashtable.h>
218c2ecf20Sopenharmony_ci#include <linux/bitfield.h>
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define HL_NAME				"habanalabs"
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/* Use upper bits of mmap offset to store habana driver specific information.
268c2ecf20Sopenharmony_ci * bits[63:62] - Encode mmap type
278c2ecf20Sopenharmony_ci * bits[45:0]  - mmap offset value
288c2ecf20Sopenharmony_ci *
298c2ecf20Sopenharmony_ci * NOTE: struct vm_area_struct.vm_pgoff uses offset in pages. Hence, these
308c2ecf20Sopenharmony_ci *  defines are w.r.t to PAGE_SIZE
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_ci#define HL_MMAP_TYPE_SHIFT		(62 - PAGE_SHIFT)
338c2ecf20Sopenharmony_ci#define HL_MMAP_TYPE_MASK		(0x3ull << HL_MMAP_TYPE_SHIFT)
348c2ecf20Sopenharmony_ci#define HL_MMAP_TYPE_CB			(0x2ull << HL_MMAP_TYPE_SHIFT)
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define HL_MMAP_OFFSET_VALUE_MASK	(0x3FFFFFFFFFFFull >> PAGE_SHIFT)
378c2ecf20Sopenharmony_ci#define HL_MMAP_OFFSET_VALUE_GET(off)	(off & HL_MMAP_OFFSET_VALUE_MASK)
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define HL_PENDING_RESET_PER_SEC	30
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#define HL_HARD_RESET_MAX_TIMEOUT	120
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define HL_DEVICE_TIMEOUT_USEC		1000000 /* 1 s */
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#define HL_HEARTBEAT_PER_USEC		5000000 /* 5 s */
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#define HL_PLL_LOW_JOB_FREQ_USEC	5000000 /* 5 s */
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define HL_CPUCP_INFO_TIMEOUT_USEC	10000000 /* 10s */
508c2ecf20Sopenharmony_ci#define HL_CPUCP_EEPROM_TIMEOUT_USEC	10000000 /* 10s */
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define HL_PCI_ELBI_TIMEOUT_MSEC	10 /* 10ms */
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define HL_SIM_MAX_TIMEOUT_US		10000000 /* 10s */
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#define HL_IDLE_BUSY_TS_ARR_SIZE	4096
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/* Memory */
598c2ecf20Sopenharmony_ci#define MEM_HASH_TABLE_BITS		7 /* 1 << 7 buckets */
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci/* MMU */
628c2ecf20Sopenharmony_ci#define MMU_HASH_TABLE_BITS		7 /* 1 << 7 buckets */
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/*
658c2ecf20Sopenharmony_ci * HL_RSVD_SOBS 'sync stream' reserved sync objects per QMAN stream
668c2ecf20Sopenharmony_ci * HL_RSVD_MONS 'sync stream' reserved monitors per QMAN stream
678c2ecf20Sopenharmony_ci */
688c2ecf20Sopenharmony_ci#define HL_RSVD_SOBS			4
698c2ecf20Sopenharmony_ci#define HL_RSVD_MONS			2
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#define HL_RSVD_SOBS_IN_USE		2
728c2ecf20Sopenharmony_ci#define HL_RSVD_MONS_IN_USE		1
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#define HL_MAX_SOB_VAL			(1 << 15)
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci#define IS_POWER_OF_2(n)		(n != 0 && ((n & (n - 1)) == 0))
778c2ecf20Sopenharmony_ci#define IS_MAX_PENDING_CS_VALID(n)	(IS_POWER_OF_2(n) && (n > 1))
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci#define HL_PCI_NUM_BARS			6
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci#define HL_MAX_DCORES			4
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci/**
848c2ecf20Sopenharmony_ci * struct pgt_info - MMU hop page info.
858c2ecf20Sopenharmony_ci * @node: hash linked-list node for the pgts shadow hash of pgts.
868c2ecf20Sopenharmony_ci * @phys_addr: physical address of the pgt.
878c2ecf20Sopenharmony_ci * @shadow_addr: shadow hop in the host.
888c2ecf20Sopenharmony_ci * @ctx: pointer to the owner ctx.
898c2ecf20Sopenharmony_ci * @num_of_ptes: indicates how many ptes are used in the pgt.
908c2ecf20Sopenharmony_ci *
918c2ecf20Sopenharmony_ci * The MMU page tables hierarchy is placed on the DRAM. When a new level (hop)
928c2ecf20Sopenharmony_ci * is needed during mapping, a new page is allocated and this structure holds
938c2ecf20Sopenharmony_ci * its essential information. During unmapping, if no valid PTEs remained in the
948c2ecf20Sopenharmony_ci * page, it is freed with its pgt_info structure.
958c2ecf20Sopenharmony_ci */
968c2ecf20Sopenharmony_cistruct pgt_info {
978c2ecf20Sopenharmony_ci	struct hlist_node	node;
988c2ecf20Sopenharmony_ci	u64			phys_addr;
998c2ecf20Sopenharmony_ci	u64			shadow_addr;
1008c2ecf20Sopenharmony_ci	struct hl_ctx		*ctx;
1018c2ecf20Sopenharmony_ci	int			num_of_ptes;
1028c2ecf20Sopenharmony_ci};
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cistruct hl_device;
1058c2ecf20Sopenharmony_cistruct hl_fpriv;
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci/**
1088c2ecf20Sopenharmony_ci * enum hl_pci_match_mode - pci match mode per region
1098c2ecf20Sopenharmony_ci * @PCI_ADDRESS_MATCH_MODE: address match mode
1108c2ecf20Sopenharmony_ci * @PCI_BAR_MATCH_MODE: bar match mode
1118c2ecf20Sopenharmony_ci */
1128c2ecf20Sopenharmony_cienum hl_pci_match_mode {
1138c2ecf20Sopenharmony_ci	PCI_ADDRESS_MATCH_MODE,
1148c2ecf20Sopenharmony_ci	PCI_BAR_MATCH_MODE
1158c2ecf20Sopenharmony_ci};
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci/**
1188c2ecf20Sopenharmony_ci * enum hl_fw_component - F/W components to read version through registers.
1198c2ecf20Sopenharmony_ci * @FW_COMP_UBOOT: u-boot.
1208c2ecf20Sopenharmony_ci * @FW_COMP_PREBOOT: preboot.
1218c2ecf20Sopenharmony_ci */
1228c2ecf20Sopenharmony_cienum hl_fw_component {
1238c2ecf20Sopenharmony_ci	FW_COMP_UBOOT,
1248c2ecf20Sopenharmony_ci	FW_COMP_PREBOOT
1258c2ecf20Sopenharmony_ci};
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci/**
1288c2ecf20Sopenharmony_ci * enum hl_queue_type - Supported QUEUE types.
1298c2ecf20Sopenharmony_ci * @QUEUE_TYPE_NA: queue is not available.
1308c2ecf20Sopenharmony_ci * @QUEUE_TYPE_EXT: external queue which is a DMA channel that may access the
1318c2ecf20Sopenharmony_ci *                  host.
1328c2ecf20Sopenharmony_ci * @QUEUE_TYPE_INT: internal queue that performs DMA inside the device's
1338c2ecf20Sopenharmony_ci *			memories and/or operates the compute engines.
1348c2ecf20Sopenharmony_ci * @QUEUE_TYPE_CPU: S/W queue for communication with the device's CPU.
1358c2ecf20Sopenharmony_ci * @QUEUE_TYPE_HW: queue of DMA and compute engines jobs, for which completion
1368c2ecf20Sopenharmony_ci *                 notifications are sent by H/W.
1378c2ecf20Sopenharmony_ci */
1388c2ecf20Sopenharmony_cienum hl_queue_type {
1398c2ecf20Sopenharmony_ci	QUEUE_TYPE_NA,
1408c2ecf20Sopenharmony_ci	QUEUE_TYPE_EXT,
1418c2ecf20Sopenharmony_ci	QUEUE_TYPE_INT,
1428c2ecf20Sopenharmony_ci	QUEUE_TYPE_CPU,
1438c2ecf20Sopenharmony_ci	QUEUE_TYPE_HW
1448c2ecf20Sopenharmony_ci};
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_cienum hl_cs_type {
1478c2ecf20Sopenharmony_ci	CS_TYPE_DEFAULT,
1488c2ecf20Sopenharmony_ci	CS_TYPE_SIGNAL,
1498c2ecf20Sopenharmony_ci	CS_TYPE_WAIT
1508c2ecf20Sopenharmony_ci};
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/*
1538c2ecf20Sopenharmony_ci * struct hl_inbound_pci_region - inbound region descriptor
1548c2ecf20Sopenharmony_ci * @mode: pci match mode for this region
1558c2ecf20Sopenharmony_ci * @addr: region target address
1568c2ecf20Sopenharmony_ci * @size: region size in bytes
1578c2ecf20Sopenharmony_ci * @offset_in_bar: offset within bar (address match mode)
1588c2ecf20Sopenharmony_ci * @bar: bar id
1598c2ecf20Sopenharmony_ci */
1608c2ecf20Sopenharmony_cistruct hl_inbound_pci_region {
1618c2ecf20Sopenharmony_ci	enum hl_pci_match_mode	mode;
1628c2ecf20Sopenharmony_ci	u64			addr;
1638c2ecf20Sopenharmony_ci	u64			size;
1648c2ecf20Sopenharmony_ci	u64			offset_in_bar;
1658c2ecf20Sopenharmony_ci	u8			bar;
1668c2ecf20Sopenharmony_ci};
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci/*
1698c2ecf20Sopenharmony_ci * struct hl_outbound_pci_region - outbound region descriptor
1708c2ecf20Sopenharmony_ci * @addr: region target address
1718c2ecf20Sopenharmony_ci * @size: region size in bytes
1728c2ecf20Sopenharmony_ci */
1738c2ecf20Sopenharmony_cistruct hl_outbound_pci_region {
1748c2ecf20Sopenharmony_ci	u64	addr;
1758c2ecf20Sopenharmony_ci	u64	size;
1768c2ecf20Sopenharmony_ci};
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci/*
1798c2ecf20Sopenharmony_ci * struct hl_hw_sob - H/W SOB info.
1808c2ecf20Sopenharmony_ci * @hdev: habanalabs device structure.
1818c2ecf20Sopenharmony_ci * @kref: refcount of this SOB. The SOB will reset once the refcount is zero.
1828c2ecf20Sopenharmony_ci * @sob_id: id of this SOB.
1838c2ecf20Sopenharmony_ci * @q_idx: the H/W queue that uses this SOB.
1848c2ecf20Sopenharmony_ci */
1858c2ecf20Sopenharmony_cistruct hl_hw_sob {
1868c2ecf20Sopenharmony_ci	struct hl_device	*hdev;
1878c2ecf20Sopenharmony_ci	struct kref		kref;
1888c2ecf20Sopenharmony_ci	u32			sob_id;
1898c2ecf20Sopenharmony_ci	u32			q_idx;
1908c2ecf20Sopenharmony_ci};
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci/**
1938c2ecf20Sopenharmony_ci * struct hw_queue_properties - queue information.
1948c2ecf20Sopenharmony_ci * @type: queue type.
1958c2ecf20Sopenharmony_ci * @driver_only: true if only the driver is allowed to send a job to this queue,
1968c2ecf20Sopenharmony_ci *               false otherwise.
1978c2ecf20Sopenharmony_ci * @requires_kernel_cb: true if a CB handle must be provided for jobs on this
1988c2ecf20Sopenharmony_ci *                      queue, false otherwise (a CB address must be provided).
1998c2ecf20Sopenharmony_ci * @supports_sync_stream: True if queue supports sync stream
2008c2ecf20Sopenharmony_ci */
2018c2ecf20Sopenharmony_cistruct hw_queue_properties {
2028c2ecf20Sopenharmony_ci	enum hl_queue_type	type;
2038c2ecf20Sopenharmony_ci	u8			driver_only;
2048c2ecf20Sopenharmony_ci	u8			requires_kernel_cb;
2058c2ecf20Sopenharmony_ci	u8			supports_sync_stream;
2068c2ecf20Sopenharmony_ci};
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci/**
2098c2ecf20Sopenharmony_ci * enum vm_type_t - virtual memory mapping request information.
2108c2ecf20Sopenharmony_ci * @VM_TYPE_USERPTR: mapping of user memory to device virtual address.
2118c2ecf20Sopenharmony_ci * @VM_TYPE_PHYS_PACK: mapping of DRAM memory to device virtual address.
2128c2ecf20Sopenharmony_ci */
2138c2ecf20Sopenharmony_cienum vm_type_t {
2148c2ecf20Sopenharmony_ci	VM_TYPE_USERPTR = 0x1,
2158c2ecf20Sopenharmony_ci	VM_TYPE_PHYS_PACK = 0x2
2168c2ecf20Sopenharmony_ci};
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci/**
2198c2ecf20Sopenharmony_ci * enum hl_device_hw_state - H/W device state. use this to understand whether
2208c2ecf20Sopenharmony_ci *                           to do reset before hw_init or not
2218c2ecf20Sopenharmony_ci * @HL_DEVICE_HW_STATE_CLEAN: H/W state is clean. i.e. after hard reset
2228c2ecf20Sopenharmony_ci * @HL_DEVICE_HW_STATE_DIRTY: H/W state is dirty. i.e. we started to execute
2238c2ecf20Sopenharmony_ci *                            hw_init
2248c2ecf20Sopenharmony_ci */
2258c2ecf20Sopenharmony_cienum hl_device_hw_state {
2268c2ecf20Sopenharmony_ci	HL_DEVICE_HW_STATE_CLEAN = 0,
2278c2ecf20Sopenharmony_ci	HL_DEVICE_HW_STATE_DIRTY
2288c2ecf20Sopenharmony_ci};
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci/**
2318c2ecf20Sopenharmony_ci * struct hl_mmu_properties - ASIC specific MMU address translation properties.
2328c2ecf20Sopenharmony_ci * @start_addr: virtual start address of the memory region.
2338c2ecf20Sopenharmony_ci * @end_addr: virtual end address of the memory region.
2348c2ecf20Sopenharmony_ci * @hop0_shift: shift of hop 0 mask.
2358c2ecf20Sopenharmony_ci * @hop1_shift: shift of hop 1 mask.
2368c2ecf20Sopenharmony_ci * @hop2_shift: shift of hop 2 mask.
2378c2ecf20Sopenharmony_ci * @hop3_shift: shift of hop 3 mask.
2388c2ecf20Sopenharmony_ci * @hop4_shift: shift of hop 4 mask.
2398c2ecf20Sopenharmony_ci * @hop5_shift: shift of hop 5 mask.
2408c2ecf20Sopenharmony_ci * @hop0_mask: mask to get the PTE address in hop 0.
2418c2ecf20Sopenharmony_ci * @hop1_mask: mask to get the PTE address in hop 1.
2428c2ecf20Sopenharmony_ci * @hop2_mask: mask to get the PTE address in hop 2.
2438c2ecf20Sopenharmony_ci * @hop3_mask: mask to get the PTE address in hop 3.
2448c2ecf20Sopenharmony_ci * @hop4_mask: mask to get the PTE address in hop 4.
2458c2ecf20Sopenharmony_ci * @hop5_mask: mask to get the PTE address in hop 5.
2468c2ecf20Sopenharmony_ci * @page_size: default page size used to allocate memory.
2478c2ecf20Sopenharmony_ci * @num_hops: The amount of hops supported by the translation table.
2488c2ecf20Sopenharmony_ci */
2498c2ecf20Sopenharmony_cistruct hl_mmu_properties {
2508c2ecf20Sopenharmony_ci	u64	start_addr;
2518c2ecf20Sopenharmony_ci	u64	end_addr;
2528c2ecf20Sopenharmony_ci	u64	hop0_shift;
2538c2ecf20Sopenharmony_ci	u64	hop1_shift;
2548c2ecf20Sopenharmony_ci	u64	hop2_shift;
2558c2ecf20Sopenharmony_ci	u64	hop3_shift;
2568c2ecf20Sopenharmony_ci	u64	hop4_shift;
2578c2ecf20Sopenharmony_ci	u64	hop5_shift;
2588c2ecf20Sopenharmony_ci	u64	hop0_mask;
2598c2ecf20Sopenharmony_ci	u64	hop1_mask;
2608c2ecf20Sopenharmony_ci	u64	hop2_mask;
2618c2ecf20Sopenharmony_ci	u64	hop3_mask;
2628c2ecf20Sopenharmony_ci	u64	hop4_mask;
2638c2ecf20Sopenharmony_ci	u64	hop5_mask;
2648c2ecf20Sopenharmony_ci	u32	page_size;
2658c2ecf20Sopenharmony_ci	u32	num_hops;
2668c2ecf20Sopenharmony_ci};
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci/**
2698c2ecf20Sopenharmony_ci * struct asic_fixed_properties - ASIC specific immutable properties.
2708c2ecf20Sopenharmony_ci * @hw_queues_props: H/W queues properties.
2718c2ecf20Sopenharmony_ci * @cpucp_info: received various information from CPU-CP regarding the H/W, e.g.
2728c2ecf20Sopenharmony_ci *		available sensors.
2738c2ecf20Sopenharmony_ci * @uboot_ver: F/W U-boot version.
2748c2ecf20Sopenharmony_ci * @preboot_ver: F/W Preboot version.
2758c2ecf20Sopenharmony_ci * @dmmu: DRAM MMU address translation properties.
2768c2ecf20Sopenharmony_ci * @pmmu: PCI (host) MMU address translation properties.
2778c2ecf20Sopenharmony_ci * @pmmu_huge: PCI (host) MMU address translation properties for memory
2788c2ecf20Sopenharmony_ci *              allocated with huge pages.
2798c2ecf20Sopenharmony_ci * @sram_base_address: SRAM physical start address.
2808c2ecf20Sopenharmony_ci * @sram_end_address: SRAM physical end address.
2818c2ecf20Sopenharmony_ci * @sram_user_base_address - SRAM physical start address for user access.
2828c2ecf20Sopenharmony_ci * @dram_base_address: DRAM physical start address.
2838c2ecf20Sopenharmony_ci * @dram_end_address: DRAM physical end address.
2848c2ecf20Sopenharmony_ci * @dram_user_base_address: DRAM physical start address for user access.
2858c2ecf20Sopenharmony_ci * @dram_size: DRAM total size.
2868c2ecf20Sopenharmony_ci * @dram_pci_bar_size: size of PCI bar towards DRAM.
2878c2ecf20Sopenharmony_ci * @max_power_default: max power of the device after reset
2888c2ecf20Sopenharmony_ci * @dram_size_for_default_page_mapping: DRAM size needed to map to avoid page
2898c2ecf20Sopenharmony_ci *                                      fault.
2908c2ecf20Sopenharmony_ci * @pcie_dbi_base_address: Base address of the PCIE_DBI block.
2918c2ecf20Sopenharmony_ci * @pcie_aux_dbi_reg_addr: Address of the PCIE_AUX DBI register.
2928c2ecf20Sopenharmony_ci * @mmu_pgt_addr: base physical address in DRAM of MMU page tables.
2938c2ecf20Sopenharmony_ci * @mmu_dram_default_page_addr: DRAM default page physical address.
2948c2ecf20Sopenharmony_ci * @cb_va_start_addr: virtual start address of command buffers which are mapped
2958c2ecf20Sopenharmony_ci *                    to the device's MMU.
2968c2ecf20Sopenharmony_ci * @cb_va_end_addr: virtual end address of command buffers which are mapped to
2978c2ecf20Sopenharmony_ci *                  the device's MMU.
2988c2ecf20Sopenharmony_ci * @mmu_pgt_size: MMU page tables total size.
2998c2ecf20Sopenharmony_ci * @mmu_pte_size: PTE size in MMU page tables.
3008c2ecf20Sopenharmony_ci * @mmu_hop_table_size: MMU hop table size.
3018c2ecf20Sopenharmony_ci * @mmu_hop0_tables_total_size: total size of MMU hop0 tables.
3028c2ecf20Sopenharmony_ci * @dram_page_size: page size for MMU DRAM allocation.
3038c2ecf20Sopenharmony_ci * @cfg_size: configuration space size on SRAM.
3048c2ecf20Sopenharmony_ci * @sram_size: total size of SRAM.
3058c2ecf20Sopenharmony_ci * @max_asid: maximum number of open contexts (ASIDs).
3068c2ecf20Sopenharmony_ci * @num_of_events: number of possible internal H/W IRQs.
3078c2ecf20Sopenharmony_ci * @psoc_pci_pll_nr: PCI PLL NR value.
3088c2ecf20Sopenharmony_ci * @psoc_pci_pll_nf: PCI PLL NF value.
3098c2ecf20Sopenharmony_ci * @psoc_pci_pll_od: PCI PLL OD value.
3108c2ecf20Sopenharmony_ci * @psoc_pci_pll_div_factor: PCI PLL DIV FACTOR 1 value.
3118c2ecf20Sopenharmony_ci * @psoc_timestamp_frequency: frequency of the psoc timestamp clock.
3128c2ecf20Sopenharmony_ci * @high_pll: high PLL frequency used by the device.
3138c2ecf20Sopenharmony_ci * @cb_pool_cb_cnt: number of CBs in the CB pool.
3148c2ecf20Sopenharmony_ci * @cb_pool_cb_size: size of each CB in the CB pool.
3158c2ecf20Sopenharmony_ci * @max_pending_cs: maximum of concurrent pending command submissions
3168c2ecf20Sopenharmony_ci * @max_queues: maximum amount of queues in the system
3178c2ecf20Sopenharmony_ci * @sync_stream_first_sob: first sync object available for sync stream use
3188c2ecf20Sopenharmony_ci * @sync_stream_first_mon: first monitor available for sync stream use
3198c2ecf20Sopenharmony_ci * @first_available_user_sob: first sob available for the user
3208c2ecf20Sopenharmony_ci * @first_available_user_mon: first monitor available for the user
3218c2ecf20Sopenharmony_ci * @tpc_enabled_mask: which TPCs are enabled.
3228c2ecf20Sopenharmony_ci * @completion_queues_count: number of completion queues.
3238c2ecf20Sopenharmony_ci * @fw_security_disabled: true if security measures are disabled in firmware,
3248c2ecf20Sopenharmony_ci *                        false otherwise
3258c2ecf20Sopenharmony_ci */
3268c2ecf20Sopenharmony_cistruct asic_fixed_properties {
3278c2ecf20Sopenharmony_ci	struct hw_queue_properties	*hw_queues_props;
3288c2ecf20Sopenharmony_ci	struct cpucp_info		cpucp_info;
3298c2ecf20Sopenharmony_ci	char				uboot_ver[VERSION_MAX_LEN];
3308c2ecf20Sopenharmony_ci	char				preboot_ver[VERSION_MAX_LEN];
3318c2ecf20Sopenharmony_ci	struct hl_mmu_properties	dmmu;
3328c2ecf20Sopenharmony_ci	struct hl_mmu_properties	pmmu;
3338c2ecf20Sopenharmony_ci	struct hl_mmu_properties	pmmu_huge;
3348c2ecf20Sopenharmony_ci	u64				sram_base_address;
3358c2ecf20Sopenharmony_ci	u64				sram_end_address;
3368c2ecf20Sopenharmony_ci	u64				sram_user_base_address;
3378c2ecf20Sopenharmony_ci	u64				dram_base_address;
3388c2ecf20Sopenharmony_ci	u64				dram_end_address;
3398c2ecf20Sopenharmony_ci	u64				dram_user_base_address;
3408c2ecf20Sopenharmony_ci	u64				dram_size;
3418c2ecf20Sopenharmony_ci	u64				dram_pci_bar_size;
3428c2ecf20Sopenharmony_ci	u64				max_power_default;
3438c2ecf20Sopenharmony_ci	u64				dram_size_for_default_page_mapping;
3448c2ecf20Sopenharmony_ci	u64				pcie_dbi_base_address;
3458c2ecf20Sopenharmony_ci	u64				pcie_aux_dbi_reg_addr;
3468c2ecf20Sopenharmony_ci	u64				mmu_pgt_addr;
3478c2ecf20Sopenharmony_ci	u64				mmu_dram_default_page_addr;
3488c2ecf20Sopenharmony_ci	u64				cb_va_start_addr;
3498c2ecf20Sopenharmony_ci	u64				cb_va_end_addr;
3508c2ecf20Sopenharmony_ci	u32				mmu_pgt_size;
3518c2ecf20Sopenharmony_ci	u32				mmu_pte_size;
3528c2ecf20Sopenharmony_ci	u32				mmu_hop_table_size;
3538c2ecf20Sopenharmony_ci	u32				mmu_hop0_tables_total_size;
3548c2ecf20Sopenharmony_ci	u32				dram_page_size;
3558c2ecf20Sopenharmony_ci	u32				cfg_size;
3568c2ecf20Sopenharmony_ci	u32				sram_size;
3578c2ecf20Sopenharmony_ci	u32				max_asid;
3588c2ecf20Sopenharmony_ci	u32				num_of_events;
3598c2ecf20Sopenharmony_ci	u32				psoc_pci_pll_nr;
3608c2ecf20Sopenharmony_ci	u32				psoc_pci_pll_nf;
3618c2ecf20Sopenharmony_ci	u32				psoc_pci_pll_od;
3628c2ecf20Sopenharmony_ci	u32				psoc_pci_pll_div_factor;
3638c2ecf20Sopenharmony_ci	u32				psoc_timestamp_frequency;
3648c2ecf20Sopenharmony_ci	u32				high_pll;
3658c2ecf20Sopenharmony_ci	u32				cb_pool_cb_cnt;
3668c2ecf20Sopenharmony_ci	u32				cb_pool_cb_size;
3678c2ecf20Sopenharmony_ci	u32				max_pending_cs;
3688c2ecf20Sopenharmony_ci	u32				max_queues;
3698c2ecf20Sopenharmony_ci	u16				sync_stream_first_sob;
3708c2ecf20Sopenharmony_ci	u16				sync_stream_first_mon;
3718c2ecf20Sopenharmony_ci	u16				first_available_user_sob[HL_MAX_DCORES];
3728c2ecf20Sopenharmony_ci	u16				first_available_user_mon[HL_MAX_DCORES];
3738c2ecf20Sopenharmony_ci	u8				tpc_enabled_mask;
3748c2ecf20Sopenharmony_ci	u8				completion_queues_count;
3758c2ecf20Sopenharmony_ci	u8				fw_security_disabled;
3768c2ecf20Sopenharmony_ci};
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ci/**
3798c2ecf20Sopenharmony_ci * struct hl_fence - software synchronization primitive
3808c2ecf20Sopenharmony_ci * @completion: fence is implemented using completion
3818c2ecf20Sopenharmony_ci * @refcount: refcount for this fence
3828c2ecf20Sopenharmony_ci * @error: mark this fence with error
3838c2ecf20Sopenharmony_ci *
3848c2ecf20Sopenharmony_ci */
3858c2ecf20Sopenharmony_cistruct hl_fence {
3868c2ecf20Sopenharmony_ci	struct completion	completion;
3878c2ecf20Sopenharmony_ci	struct kref		refcount;
3888c2ecf20Sopenharmony_ci	int			error;
3898c2ecf20Sopenharmony_ci};
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_ci/**
3928c2ecf20Sopenharmony_ci * struct hl_cs_compl - command submission completion object.
3938c2ecf20Sopenharmony_ci * @base_fence: hl fence object.
3948c2ecf20Sopenharmony_ci * @lock: spinlock to protect fence.
3958c2ecf20Sopenharmony_ci * @hdev: habanalabs device structure.
3968c2ecf20Sopenharmony_ci * @hw_sob: the H/W SOB used in this signal/wait CS.
3978c2ecf20Sopenharmony_ci * @cs_seq: command submission sequence number.
3988c2ecf20Sopenharmony_ci * @type: type of the CS - signal/wait.
3998c2ecf20Sopenharmony_ci * @sob_val: the SOB value that is used in this signal/wait CS.
4008c2ecf20Sopenharmony_ci */
4018c2ecf20Sopenharmony_cistruct hl_cs_compl {
4028c2ecf20Sopenharmony_ci	struct hl_fence		base_fence;
4038c2ecf20Sopenharmony_ci	spinlock_t		lock;
4048c2ecf20Sopenharmony_ci	struct hl_device	*hdev;
4058c2ecf20Sopenharmony_ci	struct hl_hw_sob	*hw_sob;
4068c2ecf20Sopenharmony_ci	u64			cs_seq;
4078c2ecf20Sopenharmony_ci	enum hl_cs_type		type;
4088c2ecf20Sopenharmony_ci	u16			sob_val;
4098c2ecf20Sopenharmony_ci};
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_ci/*
4128c2ecf20Sopenharmony_ci * Command Buffers
4138c2ecf20Sopenharmony_ci */
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ci/**
4168c2ecf20Sopenharmony_ci * struct hl_cb_mgr - describes a Command Buffer Manager.
4178c2ecf20Sopenharmony_ci * @cb_lock: protects cb_handles.
4188c2ecf20Sopenharmony_ci * @cb_handles: an idr to hold all command buffer handles.
4198c2ecf20Sopenharmony_ci */
4208c2ecf20Sopenharmony_cistruct hl_cb_mgr {
4218c2ecf20Sopenharmony_ci	spinlock_t		cb_lock;
4228c2ecf20Sopenharmony_ci	struct idr		cb_handles; /* protected by cb_lock */
4238c2ecf20Sopenharmony_ci};
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_ci/**
4268c2ecf20Sopenharmony_ci * struct hl_cb - describes a Command Buffer.
4278c2ecf20Sopenharmony_ci * @refcount: reference counter for usage of the CB.
4288c2ecf20Sopenharmony_ci * @hdev: pointer to device this CB belongs to.
4298c2ecf20Sopenharmony_ci * @ctx: pointer to the CB owner's context.
4308c2ecf20Sopenharmony_ci * @lock: spinlock to protect mmap/cs flows.
4318c2ecf20Sopenharmony_ci * @debugfs_list: node in debugfs list of command buffers.
4328c2ecf20Sopenharmony_ci * @pool_list: node in pool list of command buffers.
4338c2ecf20Sopenharmony_ci * @va_block_list: list of virtual addresses blocks of the CB if it is mapped to
4348c2ecf20Sopenharmony_ci *                 the device's MMU.
4358c2ecf20Sopenharmony_ci * @id: the CB's ID.
4368c2ecf20Sopenharmony_ci * @kernel_address: Holds the CB's kernel virtual address.
4378c2ecf20Sopenharmony_ci * @bus_address: Holds the CB's DMA address.
4388c2ecf20Sopenharmony_ci * @mmap_size: Holds the CB's size that was mmaped.
4398c2ecf20Sopenharmony_ci * @size: holds the CB's size.
4408c2ecf20Sopenharmony_ci * @cs_cnt: holds number of CS that this CB participates in.
4418c2ecf20Sopenharmony_ci * @mmap: true if the CB is currently mmaped to user.
4428c2ecf20Sopenharmony_ci * @is_pool: true if CB was acquired from the pool, false otherwise.
4438c2ecf20Sopenharmony_ci * @is_internal: internaly allocated
4448c2ecf20Sopenharmony_ci * @is_mmu_mapped: true if the CB is mapped to the device's MMU.
4458c2ecf20Sopenharmony_ci */
4468c2ecf20Sopenharmony_cistruct hl_cb {
4478c2ecf20Sopenharmony_ci	struct kref		refcount;
4488c2ecf20Sopenharmony_ci	struct hl_device	*hdev;
4498c2ecf20Sopenharmony_ci	struct hl_ctx		*ctx;
4508c2ecf20Sopenharmony_ci	spinlock_t		lock;
4518c2ecf20Sopenharmony_ci	struct list_head	debugfs_list;
4528c2ecf20Sopenharmony_ci	struct list_head	pool_list;
4538c2ecf20Sopenharmony_ci	struct list_head	va_block_list;
4548c2ecf20Sopenharmony_ci	u64			id;
4558c2ecf20Sopenharmony_ci	void			*kernel_address;
4568c2ecf20Sopenharmony_ci	dma_addr_t		bus_address;
4578c2ecf20Sopenharmony_ci	u32			mmap_size;
4588c2ecf20Sopenharmony_ci	u32			size;
4598c2ecf20Sopenharmony_ci	u32			cs_cnt;
4608c2ecf20Sopenharmony_ci	u8			mmap;
4618c2ecf20Sopenharmony_ci	u8			is_pool;
4628c2ecf20Sopenharmony_ci	u8			is_internal;
4638c2ecf20Sopenharmony_ci	u8			is_mmu_mapped;
4648c2ecf20Sopenharmony_ci};
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_ci/*
4688c2ecf20Sopenharmony_ci * QUEUES
4698c2ecf20Sopenharmony_ci */
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_cistruct hl_cs_job;
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci/* Queue length of external and HW queues */
4748c2ecf20Sopenharmony_ci#define HL_QUEUE_LENGTH			4096
4758c2ecf20Sopenharmony_ci#define HL_QUEUE_SIZE_IN_BYTES		(HL_QUEUE_LENGTH * HL_BD_SIZE)
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci#if (HL_MAX_JOBS_PER_CS > HL_QUEUE_LENGTH)
4788c2ecf20Sopenharmony_ci#error "HL_QUEUE_LENGTH must be greater than HL_MAX_JOBS_PER_CS"
4798c2ecf20Sopenharmony_ci#endif
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ci/* HL_CQ_LENGTH is in units of struct hl_cq_entry */
4828c2ecf20Sopenharmony_ci#define HL_CQ_LENGTH			HL_QUEUE_LENGTH
4838c2ecf20Sopenharmony_ci#define HL_CQ_SIZE_IN_BYTES		(HL_CQ_LENGTH * HL_CQ_ENTRY_SIZE)
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_ci/* Must be power of 2 */
4868c2ecf20Sopenharmony_ci#define HL_EQ_LENGTH			64
4878c2ecf20Sopenharmony_ci#define HL_EQ_SIZE_IN_BYTES		(HL_EQ_LENGTH * HL_EQ_ENTRY_SIZE)
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci/* Host <-> CPU-CP shared memory size */
4908c2ecf20Sopenharmony_ci#define HL_CPU_ACCESSIBLE_MEM_SIZE	SZ_2M
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_ci/**
4938c2ecf20Sopenharmony_ci * struct hl_hw_queue - describes a H/W transport queue.
4948c2ecf20Sopenharmony_ci * @hw_sob: array of the used H/W SOBs by this H/W queue.
4958c2ecf20Sopenharmony_ci * @shadow_queue: pointer to a shadow queue that holds pointers to jobs.
4968c2ecf20Sopenharmony_ci * @queue_type: type of queue.
4978c2ecf20Sopenharmony_ci * @kernel_address: holds the queue's kernel virtual address.
4988c2ecf20Sopenharmony_ci * @bus_address: holds the queue's DMA address.
4998c2ecf20Sopenharmony_ci * @pi: holds the queue's pi value.
5008c2ecf20Sopenharmony_ci * @ci: holds the queue's ci value, AS CALCULATED BY THE DRIVER (not real ci).
5018c2ecf20Sopenharmony_ci * @hw_queue_id: the id of the H/W queue.
5028c2ecf20Sopenharmony_ci * @cq_id: the id for the corresponding CQ for this H/W queue.
5038c2ecf20Sopenharmony_ci * @msi_vec: the IRQ number of the H/W queue.
5048c2ecf20Sopenharmony_ci * @int_queue_len: length of internal queue (number of entries).
5058c2ecf20Sopenharmony_ci * @next_sob_val: the next value to use for the currently used SOB.
5068c2ecf20Sopenharmony_ci * @base_sob_id: the base SOB id of the SOBs used by this queue.
5078c2ecf20Sopenharmony_ci * @base_mon_id: the base MON id of the MONs used by this queue.
5088c2ecf20Sopenharmony_ci * @valid: is the queue valid (we have array of 32 queues, not all of them
5098c2ecf20Sopenharmony_ci *         exist).
5108c2ecf20Sopenharmony_ci * @curr_sob_offset: the id offset to the currently used SOB from the
5118c2ecf20Sopenharmony_ci *                   HL_RSVD_SOBS that are being used by this queue.
5128c2ecf20Sopenharmony_ci * @supports_sync_stream: True if queue supports sync stream
5138c2ecf20Sopenharmony_ci */
5148c2ecf20Sopenharmony_cistruct hl_hw_queue {
5158c2ecf20Sopenharmony_ci	struct hl_hw_sob	hw_sob[HL_RSVD_SOBS];
5168c2ecf20Sopenharmony_ci	struct hl_cs_job	**shadow_queue;
5178c2ecf20Sopenharmony_ci	enum hl_queue_type	queue_type;
5188c2ecf20Sopenharmony_ci	void			*kernel_address;
5198c2ecf20Sopenharmony_ci	dma_addr_t		bus_address;
5208c2ecf20Sopenharmony_ci	u32			pi;
5218c2ecf20Sopenharmony_ci	atomic_t		ci;
5228c2ecf20Sopenharmony_ci	u32			hw_queue_id;
5238c2ecf20Sopenharmony_ci	u32			cq_id;
5248c2ecf20Sopenharmony_ci	u32			msi_vec;
5258c2ecf20Sopenharmony_ci	u16			int_queue_len;
5268c2ecf20Sopenharmony_ci	u16			next_sob_val;
5278c2ecf20Sopenharmony_ci	u16			base_sob_id;
5288c2ecf20Sopenharmony_ci	u16			base_mon_id;
5298c2ecf20Sopenharmony_ci	u8			valid;
5308c2ecf20Sopenharmony_ci	u8			curr_sob_offset;
5318c2ecf20Sopenharmony_ci	u8			supports_sync_stream;
5328c2ecf20Sopenharmony_ci};
5338c2ecf20Sopenharmony_ci
5348c2ecf20Sopenharmony_ci/**
5358c2ecf20Sopenharmony_ci * struct hl_cq - describes a completion queue
5368c2ecf20Sopenharmony_ci * @hdev: pointer to the device structure
5378c2ecf20Sopenharmony_ci * @kernel_address: holds the queue's kernel virtual address
5388c2ecf20Sopenharmony_ci * @bus_address: holds the queue's DMA address
5398c2ecf20Sopenharmony_ci * @cq_idx: completion queue index in array
5408c2ecf20Sopenharmony_ci * @hw_queue_id: the id of the matching H/W queue
5418c2ecf20Sopenharmony_ci * @ci: ci inside the queue
5428c2ecf20Sopenharmony_ci * @pi: pi inside the queue
5438c2ecf20Sopenharmony_ci * @free_slots_cnt: counter of free slots in queue
5448c2ecf20Sopenharmony_ci */
5458c2ecf20Sopenharmony_cistruct hl_cq {
5468c2ecf20Sopenharmony_ci	struct hl_device	*hdev;
5478c2ecf20Sopenharmony_ci	void			*kernel_address;
5488c2ecf20Sopenharmony_ci	dma_addr_t		bus_address;
5498c2ecf20Sopenharmony_ci	u32			cq_idx;
5508c2ecf20Sopenharmony_ci	u32			hw_queue_id;
5518c2ecf20Sopenharmony_ci	u32			ci;
5528c2ecf20Sopenharmony_ci	u32			pi;
5538c2ecf20Sopenharmony_ci	atomic_t		free_slots_cnt;
5548c2ecf20Sopenharmony_ci};
5558c2ecf20Sopenharmony_ci
5568c2ecf20Sopenharmony_ci/**
5578c2ecf20Sopenharmony_ci * struct hl_eq - describes the event queue (single one per device)
5588c2ecf20Sopenharmony_ci * @hdev: pointer to the device structure
5598c2ecf20Sopenharmony_ci * @kernel_address: holds the queue's kernel virtual address
5608c2ecf20Sopenharmony_ci * @bus_address: holds the queue's DMA address
5618c2ecf20Sopenharmony_ci * @ci: ci inside the queue
5628c2ecf20Sopenharmony_ci */
5638c2ecf20Sopenharmony_cistruct hl_eq {
5648c2ecf20Sopenharmony_ci	struct hl_device	*hdev;
5658c2ecf20Sopenharmony_ci	void			*kernel_address;
5668c2ecf20Sopenharmony_ci	dma_addr_t		bus_address;
5678c2ecf20Sopenharmony_ci	u32			ci;
5688c2ecf20Sopenharmony_ci};
5698c2ecf20Sopenharmony_ci
5708c2ecf20Sopenharmony_ci
5718c2ecf20Sopenharmony_ci/*
5728c2ecf20Sopenharmony_ci * ASICs
5738c2ecf20Sopenharmony_ci */
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_ci/**
5768c2ecf20Sopenharmony_ci * enum hl_asic_type - supported ASIC types.
5778c2ecf20Sopenharmony_ci * @ASIC_INVALID: Invalid ASIC type.
5788c2ecf20Sopenharmony_ci * @ASIC_GOYA: Goya device.
5798c2ecf20Sopenharmony_ci * @ASIC_GAUDI: Gaudi device.
5808c2ecf20Sopenharmony_ci */
5818c2ecf20Sopenharmony_cienum hl_asic_type {
5828c2ecf20Sopenharmony_ci	ASIC_INVALID,
5838c2ecf20Sopenharmony_ci	ASIC_GOYA,
5848c2ecf20Sopenharmony_ci	ASIC_GAUDI
5858c2ecf20Sopenharmony_ci};
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_cistruct hl_cs_parser;
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_ci/**
5908c2ecf20Sopenharmony_ci * enum hl_pm_mng_profile - power management profile.
5918c2ecf20Sopenharmony_ci * @PM_AUTO: internal clock is set by the Linux driver.
5928c2ecf20Sopenharmony_ci * @PM_MANUAL: internal clock is set by the user.
5938c2ecf20Sopenharmony_ci * @PM_LAST: last power management type.
5948c2ecf20Sopenharmony_ci */
5958c2ecf20Sopenharmony_cienum hl_pm_mng_profile {
5968c2ecf20Sopenharmony_ci	PM_AUTO = 1,
5978c2ecf20Sopenharmony_ci	PM_MANUAL,
5988c2ecf20Sopenharmony_ci	PM_LAST
5998c2ecf20Sopenharmony_ci};
6008c2ecf20Sopenharmony_ci
6018c2ecf20Sopenharmony_ci/**
6028c2ecf20Sopenharmony_ci * enum hl_pll_frequency - PLL frequency.
6038c2ecf20Sopenharmony_ci * @PLL_HIGH: high frequency.
6048c2ecf20Sopenharmony_ci * @PLL_LOW: low frequency.
6058c2ecf20Sopenharmony_ci * @PLL_LAST: last frequency values that were configured by the user.
6068c2ecf20Sopenharmony_ci */
6078c2ecf20Sopenharmony_cienum hl_pll_frequency {
6088c2ecf20Sopenharmony_ci	PLL_HIGH = 1,
6098c2ecf20Sopenharmony_ci	PLL_LOW,
6108c2ecf20Sopenharmony_ci	PLL_LAST
6118c2ecf20Sopenharmony_ci};
6128c2ecf20Sopenharmony_ci
6138c2ecf20Sopenharmony_ci#define PLL_REF_CLK 50
6148c2ecf20Sopenharmony_ci
6158c2ecf20Sopenharmony_cienum div_select_defs {
6168c2ecf20Sopenharmony_ci	DIV_SEL_REF_CLK = 0,
6178c2ecf20Sopenharmony_ci	DIV_SEL_PLL_CLK = 1,
6188c2ecf20Sopenharmony_ci	DIV_SEL_DIVIDED_REF = 2,
6198c2ecf20Sopenharmony_ci	DIV_SEL_DIVIDED_PLL = 3,
6208c2ecf20Sopenharmony_ci};
6218c2ecf20Sopenharmony_ci
6228c2ecf20Sopenharmony_ci/**
6238c2ecf20Sopenharmony_ci * struct hl_asic_funcs - ASIC specific functions that are can be called from
6248c2ecf20Sopenharmony_ci *                        common code.
6258c2ecf20Sopenharmony_ci * @early_init: sets up early driver state (pre sw_init), doesn't configure H/W.
6268c2ecf20Sopenharmony_ci * @early_fini: tears down what was done in early_init.
6278c2ecf20Sopenharmony_ci * @late_init: sets up late driver/hw state (post hw_init) - Optional.
6288c2ecf20Sopenharmony_ci * @late_fini: tears down what was done in late_init (pre hw_fini) - Optional.
6298c2ecf20Sopenharmony_ci * @sw_init: sets up driver state, does not configure H/W.
6308c2ecf20Sopenharmony_ci * @sw_fini: tears down driver state, does not configure H/W.
6318c2ecf20Sopenharmony_ci * @hw_init: sets up the H/W state.
6328c2ecf20Sopenharmony_ci * @hw_fini: tears down the H/W state.
6338c2ecf20Sopenharmony_ci * @halt_engines: halt engines, needed for reset sequence. This also disables
6348c2ecf20Sopenharmony_ci *                interrupts from the device. Should be called before
6358c2ecf20Sopenharmony_ci *                hw_fini and before CS rollback.
6368c2ecf20Sopenharmony_ci * @suspend: handles IP specific H/W or SW changes for suspend.
6378c2ecf20Sopenharmony_ci * @resume: handles IP specific H/W or SW changes for resume.
6388c2ecf20Sopenharmony_ci * @cb_mmap: maps a CB.
6398c2ecf20Sopenharmony_ci * @ring_doorbell: increment PI on a given QMAN.
6408c2ecf20Sopenharmony_ci * @pqe_write: Write the PQ entry to the PQ. This is ASIC-specific
6418c2ecf20Sopenharmony_ci *             function because the PQs are located in different memory areas
6428c2ecf20Sopenharmony_ci *             per ASIC (SRAM, DRAM, Host memory) and therefore, the method of
6438c2ecf20Sopenharmony_ci *             writing the PQE must match the destination memory area
6448c2ecf20Sopenharmony_ci *             properties.
6458c2ecf20Sopenharmony_ci * @asic_dma_alloc_coherent: Allocate coherent DMA memory by calling
6468c2ecf20Sopenharmony_ci *                           dma_alloc_coherent(). This is ASIC function because
6478c2ecf20Sopenharmony_ci *                           its implementation is not trivial when the driver
6488c2ecf20Sopenharmony_ci *                           is loaded in simulation mode (not upstreamed).
6498c2ecf20Sopenharmony_ci * @asic_dma_free_coherent:  Free coherent DMA memory by calling
6508c2ecf20Sopenharmony_ci *                           dma_free_coherent(). This is ASIC function because
6518c2ecf20Sopenharmony_ci *                           its implementation is not trivial when the driver
6528c2ecf20Sopenharmony_ci *                           is loaded in simulation mode (not upstreamed).
6538c2ecf20Sopenharmony_ci * @get_int_queue_base: get the internal queue base address.
6548c2ecf20Sopenharmony_ci * @test_queues: run simple test on all queues for sanity check.
6558c2ecf20Sopenharmony_ci * @asic_dma_pool_zalloc: small DMA allocation of coherent memory from DMA pool.
6568c2ecf20Sopenharmony_ci *                        size of allocation is HL_DMA_POOL_BLK_SIZE.
6578c2ecf20Sopenharmony_ci * @asic_dma_pool_free: free small DMA allocation from pool.
6588c2ecf20Sopenharmony_ci * @cpu_accessible_dma_pool_alloc: allocate CPU PQ packet from DMA pool.
6598c2ecf20Sopenharmony_ci * @cpu_accessible_dma_pool_free: free CPU PQ packet from DMA pool.
6608c2ecf20Sopenharmony_ci * @hl_dma_unmap_sg: DMA unmap scatter-gather list.
6618c2ecf20Sopenharmony_ci * @cs_parser: parse Command Submission.
6628c2ecf20Sopenharmony_ci * @asic_dma_map_sg: DMA map scatter-gather list.
6638c2ecf20Sopenharmony_ci * @get_dma_desc_list_size: get number of LIN_DMA packets required for CB.
6648c2ecf20Sopenharmony_ci * @add_end_of_cb_packets: Add packets to the end of CB, if device requires it.
6658c2ecf20Sopenharmony_ci * @update_eq_ci: update event queue CI.
6668c2ecf20Sopenharmony_ci * @context_switch: called upon ASID context switch.
6678c2ecf20Sopenharmony_ci * @restore_phase_topology: clear all SOBs amd MONs.
6688c2ecf20Sopenharmony_ci * @debugfs_read32: debug interface for reading u32 from DRAM/SRAM.
6698c2ecf20Sopenharmony_ci * @debugfs_write32: debug interface for writing u32 to DRAM/SRAM.
6708c2ecf20Sopenharmony_ci * @add_device_attr: add ASIC specific device attributes.
6718c2ecf20Sopenharmony_ci * @handle_eqe: handle event queue entry (IRQ) from CPU-CP.
6728c2ecf20Sopenharmony_ci * @set_pll_profile: change PLL profile (manual/automatic).
6738c2ecf20Sopenharmony_ci * @get_events_stat: retrieve event queue entries histogram.
6748c2ecf20Sopenharmony_ci * @read_pte: read MMU page table entry from DRAM.
6758c2ecf20Sopenharmony_ci * @write_pte: write MMU page table entry to DRAM.
6768c2ecf20Sopenharmony_ci * @mmu_invalidate_cache: flush MMU STLB host/DRAM cache, either with soft
6778c2ecf20Sopenharmony_ci *                        (L1 only) or hard (L0 & L1) flush.
6788c2ecf20Sopenharmony_ci * @mmu_invalidate_cache_range: flush specific MMU STLB cache lines with
6798c2ecf20Sopenharmony_ci *                              ASID-VA-size mask.
6808c2ecf20Sopenharmony_ci * @send_heartbeat: send is-alive packet to CPU-CP and verify response.
6818c2ecf20Sopenharmony_ci * @set_clock_gating: enable/disable clock gating per engine according to
6828c2ecf20Sopenharmony_ci *                    clock gating mask in hdev
6838c2ecf20Sopenharmony_ci * @disable_clock_gating: disable clock gating completely
6848c2ecf20Sopenharmony_ci * @debug_coresight: perform certain actions on Coresight for debugging.
6858c2ecf20Sopenharmony_ci * @is_device_idle: return true if device is idle, false otherwise.
6868c2ecf20Sopenharmony_ci * @soft_reset_late_init: perform certain actions needed after soft reset.
6878c2ecf20Sopenharmony_ci * @hw_queues_lock: acquire H/W queues lock.
6888c2ecf20Sopenharmony_ci * @hw_queues_unlock: release H/W queues lock.
6898c2ecf20Sopenharmony_ci * @get_pci_id: retrieve PCI ID.
6908c2ecf20Sopenharmony_ci * @get_eeprom_data: retrieve EEPROM data from F/W.
6918c2ecf20Sopenharmony_ci * @send_cpu_message: send message to F/W. If the message is timedout, the
6928c2ecf20Sopenharmony_ci *                    driver will eventually reset the device. The timeout can
6938c2ecf20Sopenharmony_ci *                    be determined by the calling function or it can be 0 and
6948c2ecf20Sopenharmony_ci *                    then the timeout is the default timeout for the specific
6958c2ecf20Sopenharmony_ci *                    ASIC
6968c2ecf20Sopenharmony_ci * @get_hw_state: retrieve the H/W state
6978c2ecf20Sopenharmony_ci * @pci_bars_map: Map PCI BARs.
6988c2ecf20Sopenharmony_ci * @init_iatu: Initialize the iATU unit inside the PCI controller.
6998c2ecf20Sopenharmony_ci * @rreg: Read a register. Needed for simulator support.
7008c2ecf20Sopenharmony_ci * @wreg: Write a register. Needed for simulator support.
7018c2ecf20Sopenharmony_ci * @halt_coresight: stop the ETF and ETR traces.
7028c2ecf20Sopenharmony_ci * @ctx_init: context dependent initialization.
7038c2ecf20Sopenharmony_ci * @get_clk_rate: Retrieve the ASIC current and maximum clock rate in MHz
7048c2ecf20Sopenharmony_ci * @get_queue_id_for_cq: Get the H/W queue id related to the given CQ index.
7058c2ecf20Sopenharmony_ci * @read_device_fw_version: read the device's firmware versions that are
7068c2ecf20Sopenharmony_ci *                          contained in registers
7078c2ecf20Sopenharmony_ci * @load_firmware_to_device: load the firmware to the device's memory
7088c2ecf20Sopenharmony_ci * @load_boot_fit_to_device: load boot fit to device's memory
7098c2ecf20Sopenharmony_ci * @get_signal_cb_size: Get signal CB size.
7108c2ecf20Sopenharmony_ci * @get_wait_cb_size: Get wait CB size.
7118c2ecf20Sopenharmony_ci * @gen_signal_cb: Generate a signal CB.
7128c2ecf20Sopenharmony_ci * @gen_wait_cb: Generate a wait CB.
7138c2ecf20Sopenharmony_ci * @reset_sob: Reset a SOB.
7148c2ecf20Sopenharmony_ci * @set_dma_mask_from_fw: set the DMA mask in the driver according to the
7158c2ecf20Sopenharmony_ci *                        firmware configuration
7168c2ecf20Sopenharmony_ci * @get_device_time: Get the device time.
7178c2ecf20Sopenharmony_ci */
7188c2ecf20Sopenharmony_cistruct hl_asic_funcs {
7198c2ecf20Sopenharmony_ci	int (*early_init)(struct hl_device *hdev);
7208c2ecf20Sopenharmony_ci	int (*early_fini)(struct hl_device *hdev);
7218c2ecf20Sopenharmony_ci	int (*late_init)(struct hl_device *hdev);
7228c2ecf20Sopenharmony_ci	void (*late_fini)(struct hl_device *hdev);
7238c2ecf20Sopenharmony_ci	int (*sw_init)(struct hl_device *hdev);
7248c2ecf20Sopenharmony_ci	int (*sw_fini)(struct hl_device *hdev);
7258c2ecf20Sopenharmony_ci	int (*hw_init)(struct hl_device *hdev);
7268c2ecf20Sopenharmony_ci	void (*hw_fini)(struct hl_device *hdev, bool hard_reset);
7278c2ecf20Sopenharmony_ci	void (*halt_engines)(struct hl_device *hdev, bool hard_reset);
7288c2ecf20Sopenharmony_ci	int (*suspend)(struct hl_device *hdev);
7298c2ecf20Sopenharmony_ci	int (*resume)(struct hl_device *hdev);
7308c2ecf20Sopenharmony_ci	int (*cb_mmap)(struct hl_device *hdev, struct vm_area_struct *vma,
7318c2ecf20Sopenharmony_ci			void *cpu_addr, dma_addr_t dma_addr, size_t size);
7328c2ecf20Sopenharmony_ci	void (*ring_doorbell)(struct hl_device *hdev, u32 hw_queue_id, u32 pi);
7338c2ecf20Sopenharmony_ci	void (*pqe_write)(struct hl_device *hdev, __le64 *pqe,
7348c2ecf20Sopenharmony_ci			struct hl_bd *bd);
7358c2ecf20Sopenharmony_ci	void* (*asic_dma_alloc_coherent)(struct hl_device *hdev, size_t size,
7368c2ecf20Sopenharmony_ci					dma_addr_t *dma_handle, gfp_t flag);
7378c2ecf20Sopenharmony_ci	void (*asic_dma_free_coherent)(struct hl_device *hdev, size_t size,
7388c2ecf20Sopenharmony_ci					void *cpu_addr, dma_addr_t dma_handle);
7398c2ecf20Sopenharmony_ci	void* (*get_int_queue_base)(struct hl_device *hdev, u32 queue_id,
7408c2ecf20Sopenharmony_ci				dma_addr_t *dma_handle, u16 *queue_len);
7418c2ecf20Sopenharmony_ci	int (*test_queues)(struct hl_device *hdev);
7428c2ecf20Sopenharmony_ci	void* (*asic_dma_pool_zalloc)(struct hl_device *hdev, size_t size,
7438c2ecf20Sopenharmony_ci				gfp_t mem_flags, dma_addr_t *dma_handle);
7448c2ecf20Sopenharmony_ci	void (*asic_dma_pool_free)(struct hl_device *hdev, void *vaddr,
7458c2ecf20Sopenharmony_ci				dma_addr_t dma_addr);
7468c2ecf20Sopenharmony_ci	void* (*cpu_accessible_dma_pool_alloc)(struct hl_device *hdev,
7478c2ecf20Sopenharmony_ci				size_t size, dma_addr_t *dma_handle);
7488c2ecf20Sopenharmony_ci	void (*cpu_accessible_dma_pool_free)(struct hl_device *hdev,
7498c2ecf20Sopenharmony_ci				size_t size, void *vaddr);
7508c2ecf20Sopenharmony_ci	void (*hl_dma_unmap_sg)(struct hl_device *hdev,
7518c2ecf20Sopenharmony_ci				struct scatterlist *sgl, int nents,
7528c2ecf20Sopenharmony_ci				enum dma_data_direction dir);
7538c2ecf20Sopenharmony_ci	int (*cs_parser)(struct hl_device *hdev, struct hl_cs_parser *parser);
7548c2ecf20Sopenharmony_ci	int (*asic_dma_map_sg)(struct hl_device *hdev,
7558c2ecf20Sopenharmony_ci				struct scatterlist *sgl, int nents,
7568c2ecf20Sopenharmony_ci				enum dma_data_direction dir);
7578c2ecf20Sopenharmony_ci	u32 (*get_dma_desc_list_size)(struct hl_device *hdev,
7588c2ecf20Sopenharmony_ci					struct sg_table *sgt);
7598c2ecf20Sopenharmony_ci	void (*add_end_of_cb_packets)(struct hl_device *hdev,
7608c2ecf20Sopenharmony_ci					void *kernel_address, u32 len,
7618c2ecf20Sopenharmony_ci					u64 cq_addr, u32 cq_val, u32 msix_num,
7628c2ecf20Sopenharmony_ci					bool eb);
7638c2ecf20Sopenharmony_ci	void (*update_eq_ci)(struct hl_device *hdev, u32 val);
7648c2ecf20Sopenharmony_ci	int (*context_switch)(struct hl_device *hdev, u32 asid);
7658c2ecf20Sopenharmony_ci	void (*restore_phase_topology)(struct hl_device *hdev);
7668c2ecf20Sopenharmony_ci	int (*debugfs_read32)(struct hl_device *hdev, u64 addr, u32 *val);
7678c2ecf20Sopenharmony_ci	int (*debugfs_write32)(struct hl_device *hdev, u64 addr, u32 val);
7688c2ecf20Sopenharmony_ci	int (*debugfs_read64)(struct hl_device *hdev, u64 addr, u64 *val);
7698c2ecf20Sopenharmony_ci	int (*debugfs_write64)(struct hl_device *hdev, u64 addr, u64 val);
7708c2ecf20Sopenharmony_ci	void (*add_device_attr)(struct hl_device *hdev,
7718c2ecf20Sopenharmony_ci				struct attribute_group *dev_attr_grp);
7728c2ecf20Sopenharmony_ci	void (*handle_eqe)(struct hl_device *hdev,
7738c2ecf20Sopenharmony_ci				struct hl_eq_entry *eq_entry);
7748c2ecf20Sopenharmony_ci	void (*set_pll_profile)(struct hl_device *hdev,
7758c2ecf20Sopenharmony_ci			enum hl_pll_frequency freq);
7768c2ecf20Sopenharmony_ci	void* (*get_events_stat)(struct hl_device *hdev, bool aggregate,
7778c2ecf20Sopenharmony_ci				u32 *size);
7788c2ecf20Sopenharmony_ci	u64 (*read_pte)(struct hl_device *hdev, u64 addr);
7798c2ecf20Sopenharmony_ci	void (*write_pte)(struct hl_device *hdev, u64 addr, u64 val);
7808c2ecf20Sopenharmony_ci	int (*mmu_invalidate_cache)(struct hl_device *hdev, bool is_hard,
7818c2ecf20Sopenharmony_ci					u32 flags);
7828c2ecf20Sopenharmony_ci	int (*mmu_invalidate_cache_range)(struct hl_device *hdev, bool is_hard,
7838c2ecf20Sopenharmony_ci			u32 asid, u64 va, u64 size);
7848c2ecf20Sopenharmony_ci	int (*send_heartbeat)(struct hl_device *hdev);
7858c2ecf20Sopenharmony_ci	void (*set_clock_gating)(struct hl_device *hdev);
7868c2ecf20Sopenharmony_ci	void (*disable_clock_gating)(struct hl_device *hdev);
7878c2ecf20Sopenharmony_ci	int (*debug_coresight)(struct hl_device *hdev, void *data);
7888c2ecf20Sopenharmony_ci	bool (*is_device_idle)(struct hl_device *hdev, u64 *mask,
7898c2ecf20Sopenharmony_ci				struct seq_file *s);
7908c2ecf20Sopenharmony_ci	int (*soft_reset_late_init)(struct hl_device *hdev);
7918c2ecf20Sopenharmony_ci	void (*hw_queues_lock)(struct hl_device *hdev);
7928c2ecf20Sopenharmony_ci	void (*hw_queues_unlock)(struct hl_device *hdev);
7938c2ecf20Sopenharmony_ci	u32 (*get_pci_id)(struct hl_device *hdev);
7948c2ecf20Sopenharmony_ci	int (*get_eeprom_data)(struct hl_device *hdev, void *data,
7958c2ecf20Sopenharmony_ci				size_t max_size);
7968c2ecf20Sopenharmony_ci	int (*send_cpu_message)(struct hl_device *hdev, u32 *msg,
7978c2ecf20Sopenharmony_ci				u16 len, u32 timeout, long *result);
7988c2ecf20Sopenharmony_ci	enum hl_device_hw_state (*get_hw_state)(struct hl_device *hdev);
7998c2ecf20Sopenharmony_ci	int (*pci_bars_map)(struct hl_device *hdev);
8008c2ecf20Sopenharmony_ci	int (*init_iatu)(struct hl_device *hdev);
8018c2ecf20Sopenharmony_ci	u32 (*rreg)(struct hl_device *hdev, u32 reg);
8028c2ecf20Sopenharmony_ci	void (*wreg)(struct hl_device *hdev, u32 reg, u32 val);
8038c2ecf20Sopenharmony_ci	void (*halt_coresight)(struct hl_device *hdev);
8048c2ecf20Sopenharmony_ci	int (*ctx_init)(struct hl_ctx *ctx);
8058c2ecf20Sopenharmony_ci	int (*get_clk_rate)(struct hl_device *hdev, u32 *cur_clk, u32 *max_clk);
8068c2ecf20Sopenharmony_ci	u32 (*get_queue_id_for_cq)(struct hl_device *hdev, u32 cq_idx);
8078c2ecf20Sopenharmony_ci	void (*read_device_fw_version)(struct hl_device *hdev,
8088c2ecf20Sopenharmony_ci					enum hl_fw_component fwc);
8098c2ecf20Sopenharmony_ci	int (*load_firmware_to_device)(struct hl_device *hdev);
8108c2ecf20Sopenharmony_ci	int (*load_boot_fit_to_device)(struct hl_device *hdev);
8118c2ecf20Sopenharmony_ci	u32 (*get_signal_cb_size)(struct hl_device *hdev);
8128c2ecf20Sopenharmony_ci	u32 (*get_wait_cb_size)(struct hl_device *hdev);
8138c2ecf20Sopenharmony_ci	void (*gen_signal_cb)(struct hl_device *hdev, void *data, u16 sob_id);
8148c2ecf20Sopenharmony_ci	void (*gen_wait_cb)(struct hl_device *hdev, void *data, u16 sob_id,
8158c2ecf20Sopenharmony_ci				u16 sob_val, u16 mon_id, u32 q_idx);
8168c2ecf20Sopenharmony_ci	void (*reset_sob)(struct hl_device *hdev, void *data);
8178c2ecf20Sopenharmony_ci	void (*set_dma_mask_from_fw)(struct hl_device *hdev);
8188c2ecf20Sopenharmony_ci	u64 (*get_device_time)(struct hl_device *hdev);
8198c2ecf20Sopenharmony_ci};
8208c2ecf20Sopenharmony_ci
8218c2ecf20Sopenharmony_ci
8228c2ecf20Sopenharmony_ci/*
8238c2ecf20Sopenharmony_ci * CONTEXTS
8248c2ecf20Sopenharmony_ci */
8258c2ecf20Sopenharmony_ci
8268c2ecf20Sopenharmony_ci#define HL_KERNEL_ASID_ID	0
8278c2ecf20Sopenharmony_ci
8288c2ecf20Sopenharmony_ci/**
8298c2ecf20Sopenharmony_ci * struct hl_va_range - virtual addresses range.
8308c2ecf20Sopenharmony_ci * @lock: protects the virtual addresses list.
8318c2ecf20Sopenharmony_ci * @list: list of virtual addresses blocks available for mappings.
8328c2ecf20Sopenharmony_ci * @start_addr: range start address.
8338c2ecf20Sopenharmony_ci * @end_addr: range end address.
8348c2ecf20Sopenharmony_ci */
8358c2ecf20Sopenharmony_cistruct hl_va_range {
8368c2ecf20Sopenharmony_ci	struct mutex		lock;
8378c2ecf20Sopenharmony_ci	struct list_head	list;
8388c2ecf20Sopenharmony_ci	u64			start_addr;
8398c2ecf20Sopenharmony_ci	u64			end_addr;
8408c2ecf20Sopenharmony_ci};
8418c2ecf20Sopenharmony_ci
8428c2ecf20Sopenharmony_ci/**
8438c2ecf20Sopenharmony_ci * struct hl_ctx - user/kernel context.
8448c2ecf20Sopenharmony_ci * @mem_hash: holds mapping from virtual address to virtual memory area
8458c2ecf20Sopenharmony_ci *		descriptor (hl_vm_phys_pg_list or hl_userptr).
8468c2ecf20Sopenharmony_ci * @mmu_shadow_hash: holds a mapping from shadow address to pgt_info structure.
8478c2ecf20Sopenharmony_ci * @hpriv: pointer to the private (Kernel Driver) data of the process (fd).
8488c2ecf20Sopenharmony_ci * @hdev: pointer to the device structure.
8498c2ecf20Sopenharmony_ci * @refcount: reference counter for the context. Context is released only when
8508c2ecf20Sopenharmony_ci *		this hits 0l. It is incremented on CS and CS_WAIT.
8518c2ecf20Sopenharmony_ci * @cs_pending: array of hl fence objects representing pending CS.
8528c2ecf20Sopenharmony_ci * @host_va_range: holds available virtual addresses for host mappings.
8538c2ecf20Sopenharmony_ci * @host_huge_va_range: holds available virtual addresses for host mappings
8548c2ecf20Sopenharmony_ci *                      with huge pages.
8558c2ecf20Sopenharmony_ci * @dram_va_range: holds available virtual addresses for DRAM mappings.
8568c2ecf20Sopenharmony_ci * @mem_hash_lock: protects the mem_hash.
8578c2ecf20Sopenharmony_ci * @mmu_lock: protects the MMU page tables. Any change to the PGT, modifying the
8588c2ecf20Sopenharmony_ci *            MMU hash or walking the PGT requires talking this lock.
8598c2ecf20Sopenharmony_ci * @debugfs_list: node in debugfs list of contexts.
8608c2ecf20Sopenharmony_ci * @cb_va_pool: device VA pool for command buffers which are mapped to the
8618c2ecf20Sopenharmony_ci *              device's MMU.
8628c2ecf20Sopenharmony_ci * @cs_sequence: sequence number for CS. Value is assigned to a CS and passed
8638c2ecf20Sopenharmony_ci *			to user so user could inquire about CS. It is used as
8648c2ecf20Sopenharmony_ci *			index to cs_pending array.
8658c2ecf20Sopenharmony_ci * @dram_default_hops: array that holds all hops addresses needed for default
8668c2ecf20Sopenharmony_ci *                     DRAM mapping.
8678c2ecf20Sopenharmony_ci * @cs_lock: spinlock to protect cs_sequence.
8688c2ecf20Sopenharmony_ci * @dram_phys_mem: amount of used physical DRAM memory by this context.
8698c2ecf20Sopenharmony_ci * @thread_ctx_switch_token: token to prevent multiple threads of the same
8708c2ecf20Sopenharmony_ci *				context	from running the context switch phase.
8718c2ecf20Sopenharmony_ci *				Only a single thread should run it.
8728c2ecf20Sopenharmony_ci * @thread_ctx_switch_wait_token: token to prevent the threads that didn't run
8738c2ecf20Sopenharmony_ci *				the context switch phase from moving to their
8748c2ecf20Sopenharmony_ci *				execution phase before the context switch phase
8758c2ecf20Sopenharmony_ci *				has finished.
8768c2ecf20Sopenharmony_ci * @asid: context's unique address space ID in the device's MMU.
8778c2ecf20Sopenharmony_ci * @handle: context's opaque handle for user
8788c2ecf20Sopenharmony_ci */
8798c2ecf20Sopenharmony_cistruct hl_ctx {
8808c2ecf20Sopenharmony_ci	DECLARE_HASHTABLE(mem_hash, MEM_HASH_TABLE_BITS);
8818c2ecf20Sopenharmony_ci	DECLARE_HASHTABLE(mmu_shadow_hash, MMU_HASH_TABLE_BITS);
8828c2ecf20Sopenharmony_ci	struct hl_fpriv		*hpriv;
8838c2ecf20Sopenharmony_ci	struct hl_device	*hdev;
8848c2ecf20Sopenharmony_ci	struct kref		refcount;
8858c2ecf20Sopenharmony_ci	struct hl_fence		**cs_pending;
8868c2ecf20Sopenharmony_ci	struct hl_va_range	*host_va_range;
8878c2ecf20Sopenharmony_ci	struct hl_va_range	*host_huge_va_range;
8888c2ecf20Sopenharmony_ci	struct hl_va_range	*dram_va_range;
8898c2ecf20Sopenharmony_ci	struct mutex		mem_hash_lock;
8908c2ecf20Sopenharmony_ci	struct mutex		mmu_lock;
8918c2ecf20Sopenharmony_ci	struct list_head	debugfs_list;
8928c2ecf20Sopenharmony_ci	struct hl_cs_counters	cs_counters;
8938c2ecf20Sopenharmony_ci	struct gen_pool		*cb_va_pool;
8948c2ecf20Sopenharmony_ci	u64			cs_sequence;
8958c2ecf20Sopenharmony_ci	u64			*dram_default_hops;
8968c2ecf20Sopenharmony_ci	spinlock_t		cs_lock;
8978c2ecf20Sopenharmony_ci	atomic64_t		dram_phys_mem;
8988c2ecf20Sopenharmony_ci	atomic_t		thread_ctx_switch_token;
8998c2ecf20Sopenharmony_ci	u32			thread_ctx_switch_wait_token;
9008c2ecf20Sopenharmony_ci	u32			asid;
9018c2ecf20Sopenharmony_ci	u32			handle;
9028c2ecf20Sopenharmony_ci};
9038c2ecf20Sopenharmony_ci
9048c2ecf20Sopenharmony_ci/**
9058c2ecf20Sopenharmony_ci * struct hl_ctx_mgr - for handling multiple contexts.
9068c2ecf20Sopenharmony_ci * @ctx_lock: protects ctx_handles.
9078c2ecf20Sopenharmony_ci * @ctx_handles: idr to hold all ctx handles.
9088c2ecf20Sopenharmony_ci */
9098c2ecf20Sopenharmony_cistruct hl_ctx_mgr {
9108c2ecf20Sopenharmony_ci	struct mutex		ctx_lock;
9118c2ecf20Sopenharmony_ci	struct idr		ctx_handles;
9128c2ecf20Sopenharmony_ci};
9138c2ecf20Sopenharmony_ci
9148c2ecf20Sopenharmony_ci
9158c2ecf20Sopenharmony_ci
9168c2ecf20Sopenharmony_ci/*
9178c2ecf20Sopenharmony_ci * COMMAND SUBMISSIONS
9188c2ecf20Sopenharmony_ci */
9198c2ecf20Sopenharmony_ci
9208c2ecf20Sopenharmony_ci/**
9218c2ecf20Sopenharmony_ci * struct hl_userptr - memory mapping chunk information
9228c2ecf20Sopenharmony_ci * @vm_type: type of the VM.
9238c2ecf20Sopenharmony_ci * @job_node: linked-list node for hanging the object on the Job's list.
9248c2ecf20Sopenharmony_ci * @vec: pointer to the frame vector.
9258c2ecf20Sopenharmony_ci * @sgt: pointer to the scatter-gather table that holds the pages.
9268c2ecf20Sopenharmony_ci * @dir: for DMA unmapping, the direction must be supplied, so save it.
9278c2ecf20Sopenharmony_ci * @debugfs_list: node in debugfs list of command submissions.
9288c2ecf20Sopenharmony_ci * @addr: user-space virtual address of the start of the memory area.
9298c2ecf20Sopenharmony_ci * @size: size of the memory area to pin & map.
9308c2ecf20Sopenharmony_ci * @dma_mapped: true if the SG was mapped to DMA addresses, false otherwise.
9318c2ecf20Sopenharmony_ci */
9328c2ecf20Sopenharmony_cistruct hl_userptr {
9338c2ecf20Sopenharmony_ci	enum vm_type_t		vm_type; /* must be first */
9348c2ecf20Sopenharmony_ci	struct list_head	job_node;
9358c2ecf20Sopenharmony_ci	struct frame_vector	*vec;
9368c2ecf20Sopenharmony_ci	struct sg_table		*sgt;
9378c2ecf20Sopenharmony_ci	enum dma_data_direction dir;
9388c2ecf20Sopenharmony_ci	struct list_head	debugfs_list;
9398c2ecf20Sopenharmony_ci	u64			addr;
9408c2ecf20Sopenharmony_ci	u32			size;
9418c2ecf20Sopenharmony_ci	u8			dma_mapped;
9428c2ecf20Sopenharmony_ci};
9438c2ecf20Sopenharmony_ci
9448c2ecf20Sopenharmony_ci/**
9458c2ecf20Sopenharmony_ci * struct hl_cs - command submission.
9468c2ecf20Sopenharmony_ci * @jobs_in_queue_cnt: per each queue, maintain counter of submitted jobs.
9478c2ecf20Sopenharmony_ci * @ctx: the context this CS belongs to.
9488c2ecf20Sopenharmony_ci * @job_list: list of the CS's jobs in the various queues.
9498c2ecf20Sopenharmony_ci * @job_lock: spinlock for the CS's jobs list. Needed for free_job.
9508c2ecf20Sopenharmony_ci * @refcount: reference counter for usage of the CS.
9518c2ecf20Sopenharmony_ci * @fence: pointer to the fence object of this CS.
9528c2ecf20Sopenharmony_ci * @signal_fence: pointer to the fence object of the signal CS (used by wait
9538c2ecf20Sopenharmony_ci *                CS only).
9548c2ecf20Sopenharmony_ci * @finish_work: workqueue object to run when CS is completed by H/W.
9558c2ecf20Sopenharmony_ci * @work_tdr: delayed work node for TDR.
9568c2ecf20Sopenharmony_ci * @mirror_node : node in device mirror list of command submissions.
9578c2ecf20Sopenharmony_ci * @debugfs_list: node in debugfs list of command submissions.
9588c2ecf20Sopenharmony_ci * @sequence: the sequence number of this CS.
9598c2ecf20Sopenharmony_ci * @type: CS_TYPE_*.
9608c2ecf20Sopenharmony_ci * @submitted: true if CS was submitted to H/W.
9618c2ecf20Sopenharmony_ci * @completed: true if CS was completed by device.
9628c2ecf20Sopenharmony_ci * @timedout : true if CS was timedout.
9638c2ecf20Sopenharmony_ci * @tdr_active: true if TDR was activated for this CS (to prevent
9648c2ecf20Sopenharmony_ci *		double TDR activation).
9658c2ecf20Sopenharmony_ci * @aborted: true if CS was aborted due to some device error.
9668c2ecf20Sopenharmony_ci */
9678c2ecf20Sopenharmony_cistruct hl_cs {
9688c2ecf20Sopenharmony_ci	u16			*jobs_in_queue_cnt;
9698c2ecf20Sopenharmony_ci	struct hl_ctx		*ctx;
9708c2ecf20Sopenharmony_ci	struct list_head	job_list;
9718c2ecf20Sopenharmony_ci	spinlock_t		job_lock;
9728c2ecf20Sopenharmony_ci	struct kref		refcount;
9738c2ecf20Sopenharmony_ci	struct hl_fence		*fence;
9748c2ecf20Sopenharmony_ci	struct hl_fence		*signal_fence;
9758c2ecf20Sopenharmony_ci	struct work_struct	finish_work;
9768c2ecf20Sopenharmony_ci	struct delayed_work	work_tdr;
9778c2ecf20Sopenharmony_ci	struct list_head	mirror_node;
9788c2ecf20Sopenharmony_ci	struct list_head	debugfs_list;
9798c2ecf20Sopenharmony_ci	u64			sequence;
9808c2ecf20Sopenharmony_ci	enum hl_cs_type		type;
9818c2ecf20Sopenharmony_ci	u8			submitted;
9828c2ecf20Sopenharmony_ci	u8			completed;
9838c2ecf20Sopenharmony_ci	u8			timedout;
9848c2ecf20Sopenharmony_ci	u8			tdr_active;
9858c2ecf20Sopenharmony_ci	u8			aborted;
9868c2ecf20Sopenharmony_ci};
9878c2ecf20Sopenharmony_ci
9888c2ecf20Sopenharmony_ci/**
9898c2ecf20Sopenharmony_ci * struct hl_cs_job - command submission job.
9908c2ecf20Sopenharmony_ci * @cs_node: the node to hang on the CS jobs list.
9918c2ecf20Sopenharmony_ci * @cs: the CS this job belongs to.
9928c2ecf20Sopenharmony_ci * @user_cb: the CB we got from the user.
9938c2ecf20Sopenharmony_ci * @patched_cb: in case of patching, this is internal CB which is submitted on
9948c2ecf20Sopenharmony_ci *		the queue instead of the CB we got from the IOCTL.
9958c2ecf20Sopenharmony_ci * @finish_work: workqueue object to run when job is completed.
9968c2ecf20Sopenharmony_ci * @userptr_list: linked-list of userptr mappings that belong to this job and
9978c2ecf20Sopenharmony_ci *			wait for completion.
9988c2ecf20Sopenharmony_ci * @debugfs_list: node in debugfs list of command submission jobs.
9998c2ecf20Sopenharmony_ci * @queue_type: the type of the H/W queue this job is submitted to.
10008c2ecf20Sopenharmony_ci * @id: the id of this job inside a CS.
10018c2ecf20Sopenharmony_ci * @hw_queue_id: the id of the H/W queue this job is submitted to.
10028c2ecf20Sopenharmony_ci * @user_cb_size: the actual size of the CB we got from the user.
10038c2ecf20Sopenharmony_ci * @job_cb_size: the actual size of the CB that we put on the queue.
10048c2ecf20Sopenharmony_ci * @is_kernel_allocated_cb: true if the CB handle we got from the user holds a
10058c2ecf20Sopenharmony_ci *                          handle to a kernel-allocated CB object, false
10068c2ecf20Sopenharmony_ci *                          otherwise (SRAM/DRAM/host address).
10078c2ecf20Sopenharmony_ci * @contains_dma_pkt: whether the JOB contains at least one DMA packet. This
10088c2ecf20Sopenharmony_ci *                    info is needed later, when adding the 2xMSG_PROT at the
10098c2ecf20Sopenharmony_ci *                    end of the JOB, to know which barriers to put in the
10108c2ecf20Sopenharmony_ci *                    MSG_PROT packets. Relevant only for GAUDI as GOYA doesn't
10118c2ecf20Sopenharmony_ci *                    have streams so the engine can't be busy by another
10128c2ecf20Sopenharmony_ci *                    stream.
10138c2ecf20Sopenharmony_ci */
10148c2ecf20Sopenharmony_cistruct hl_cs_job {
10158c2ecf20Sopenharmony_ci	struct list_head	cs_node;
10168c2ecf20Sopenharmony_ci	struct hl_cs		*cs;
10178c2ecf20Sopenharmony_ci	struct hl_cb		*user_cb;
10188c2ecf20Sopenharmony_ci	struct hl_cb		*patched_cb;
10198c2ecf20Sopenharmony_ci	struct work_struct	finish_work;
10208c2ecf20Sopenharmony_ci	struct list_head	userptr_list;
10218c2ecf20Sopenharmony_ci	struct list_head	debugfs_list;
10228c2ecf20Sopenharmony_ci	enum hl_queue_type	queue_type;
10238c2ecf20Sopenharmony_ci	u32			id;
10248c2ecf20Sopenharmony_ci	u32			hw_queue_id;
10258c2ecf20Sopenharmony_ci	u32			user_cb_size;
10268c2ecf20Sopenharmony_ci	u32			job_cb_size;
10278c2ecf20Sopenharmony_ci	u8			is_kernel_allocated_cb;
10288c2ecf20Sopenharmony_ci	u8			contains_dma_pkt;
10298c2ecf20Sopenharmony_ci};
10308c2ecf20Sopenharmony_ci
10318c2ecf20Sopenharmony_ci/**
10328c2ecf20Sopenharmony_ci * struct hl_cs_parser - command submission parser properties.
10338c2ecf20Sopenharmony_ci * @user_cb: the CB we got from the user.
10348c2ecf20Sopenharmony_ci * @patched_cb: in case of patching, this is internal CB which is submitted on
10358c2ecf20Sopenharmony_ci *		the queue instead of the CB we got from the IOCTL.
10368c2ecf20Sopenharmony_ci * @job_userptr_list: linked-list of userptr mappings that belong to the related
10378c2ecf20Sopenharmony_ci *			job and wait for completion.
10388c2ecf20Sopenharmony_ci * @cs_sequence: the sequence number of the related CS.
10398c2ecf20Sopenharmony_ci * @queue_type: the type of the H/W queue this job is submitted to.
10408c2ecf20Sopenharmony_ci * @ctx_id: the ID of the context the related CS belongs to.
10418c2ecf20Sopenharmony_ci * @hw_queue_id: the id of the H/W queue this job is submitted to.
10428c2ecf20Sopenharmony_ci * @user_cb_size: the actual size of the CB we got from the user.
10438c2ecf20Sopenharmony_ci * @patched_cb_size: the size of the CB after parsing.
10448c2ecf20Sopenharmony_ci * @job_id: the id of the related job inside the related CS.
10458c2ecf20Sopenharmony_ci * @is_kernel_allocated_cb: true if the CB handle we got from the user holds a
10468c2ecf20Sopenharmony_ci *                          handle to a kernel-allocated CB object, false
10478c2ecf20Sopenharmony_ci *                          otherwise (SRAM/DRAM/host address).
10488c2ecf20Sopenharmony_ci * @contains_dma_pkt: whether the JOB contains at least one DMA packet. This
10498c2ecf20Sopenharmony_ci *                    info is needed later, when adding the 2xMSG_PROT at the
10508c2ecf20Sopenharmony_ci *                    end of the JOB, to know which barriers to put in the
10518c2ecf20Sopenharmony_ci *                    MSG_PROT packets. Relevant only for GAUDI as GOYA doesn't
10528c2ecf20Sopenharmony_ci *                    have streams so the engine can't be busy by another
10538c2ecf20Sopenharmony_ci *                    stream.
10548c2ecf20Sopenharmony_ci */
10558c2ecf20Sopenharmony_cistruct hl_cs_parser {
10568c2ecf20Sopenharmony_ci	struct hl_cb		*user_cb;
10578c2ecf20Sopenharmony_ci	struct hl_cb		*patched_cb;
10588c2ecf20Sopenharmony_ci	struct list_head	*job_userptr_list;
10598c2ecf20Sopenharmony_ci	u64			cs_sequence;
10608c2ecf20Sopenharmony_ci	enum hl_queue_type	queue_type;
10618c2ecf20Sopenharmony_ci	u32			ctx_id;
10628c2ecf20Sopenharmony_ci	u32			hw_queue_id;
10638c2ecf20Sopenharmony_ci	u32			user_cb_size;
10648c2ecf20Sopenharmony_ci	u32			patched_cb_size;
10658c2ecf20Sopenharmony_ci	u8			job_id;
10668c2ecf20Sopenharmony_ci	u8			is_kernel_allocated_cb;
10678c2ecf20Sopenharmony_ci	u8			contains_dma_pkt;
10688c2ecf20Sopenharmony_ci};
10698c2ecf20Sopenharmony_ci
10708c2ecf20Sopenharmony_ci
10718c2ecf20Sopenharmony_ci/*
10728c2ecf20Sopenharmony_ci * MEMORY STRUCTURE
10738c2ecf20Sopenharmony_ci */
10748c2ecf20Sopenharmony_ci
10758c2ecf20Sopenharmony_ci/**
10768c2ecf20Sopenharmony_ci * struct hl_vm_hash_node - hash element from virtual address to virtual
10778c2ecf20Sopenharmony_ci *				memory area descriptor (hl_vm_phys_pg_list or
10788c2ecf20Sopenharmony_ci *				hl_userptr).
10798c2ecf20Sopenharmony_ci * @node: node to hang on the hash table in context object.
10808c2ecf20Sopenharmony_ci * @vaddr: key virtual address.
10818c2ecf20Sopenharmony_ci * @ptr: value pointer (hl_vm_phys_pg_list or hl_userptr).
10828c2ecf20Sopenharmony_ci */
10838c2ecf20Sopenharmony_cistruct hl_vm_hash_node {
10848c2ecf20Sopenharmony_ci	struct hlist_node	node;
10858c2ecf20Sopenharmony_ci	u64			vaddr;
10868c2ecf20Sopenharmony_ci	void			*ptr;
10878c2ecf20Sopenharmony_ci};
10888c2ecf20Sopenharmony_ci
10898c2ecf20Sopenharmony_ci/**
10908c2ecf20Sopenharmony_ci * struct hl_vm_phys_pg_pack - physical page pack.
10918c2ecf20Sopenharmony_ci * @vm_type: describes the type of the virtual area descriptor.
10928c2ecf20Sopenharmony_ci * @pages: the physical page array.
10938c2ecf20Sopenharmony_ci * @npages: num physical pages in the pack.
10948c2ecf20Sopenharmony_ci * @total_size: total size of all the pages in this list.
10958c2ecf20Sopenharmony_ci * @mapping_cnt: number of shared mappings.
10968c2ecf20Sopenharmony_ci * @asid: the context related to this list.
10978c2ecf20Sopenharmony_ci * @page_size: size of each page in the pack.
10988c2ecf20Sopenharmony_ci * @flags: HL_MEM_* flags related to this list.
10998c2ecf20Sopenharmony_ci * @handle: the provided handle related to this list.
11008c2ecf20Sopenharmony_ci * @offset: offset from the first page.
11018c2ecf20Sopenharmony_ci * @contiguous: is contiguous physical memory.
11028c2ecf20Sopenharmony_ci * @created_from_userptr: is product of host virtual address.
11038c2ecf20Sopenharmony_ci */
11048c2ecf20Sopenharmony_cistruct hl_vm_phys_pg_pack {
11058c2ecf20Sopenharmony_ci	enum vm_type_t		vm_type; /* must be first */
11068c2ecf20Sopenharmony_ci	u64			*pages;
11078c2ecf20Sopenharmony_ci	u64			npages;
11088c2ecf20Sopenharmony_ci	u64			total_size;
11098c2ecf20Sopenharmony_ci	atomic_t		mapping_cnt;
11108c2ecf20Sopenharmony_ci	u32			asid;
11118c2ecf20Sopenharmony_ci	u32			page_size;
11128c2ecf20Sopenharmony_ci	u32			flags;
11138c2ecf20Sopenharmony_ci	u32			handle;
11148c2ecf20Sopenharmony_ci	u32			offset;
11158c2ecf20Sopenharmony_ci	u8			contiguous;
11168c2ecf20Sopenharmony_ci	u8			created_from_userptr;
11178c2ecf20Sopenharmony_ci};
11188c2ecf20Sopenharmony_ci
11198c2ecf20Sopenharmony_ci/**
11208c2ecf20Sopenharmony_ci * struct hl_vm_va_block - virtual range block information.
11218c2ecf20Sopenharmony_ci * @node: node to hang on the virtual range list in context object.
11228c2ecf20Sopenharmony_ci * @start: virtual range start address.
11238c2ecf20Sopenharmony_ci * @end: virtual range end address.
11248c2ecf20Sopenharmony_ci * @size: virtual range size.
11258c2ecf20Sopenharmony_ci */
11268c2ecf20Sopenharmony_cistruct hl_vm_va_block {
11278c2ecf20Sopenharmony_ci	struct list_head	node;
11288c2ecf20Sopenharmony_ci	u64			start;
11298c2ecf20Sopenharmony_ci	u64			end;
11308c2ecf20Sopenharmony_ci	u64			size;
11318c2ecf20Sopenharmony_ci};
11328c2ecf20Sopenharmony_ci
11338c2ecf20Sopenharmony_ci/**
11348c2ecf20Sopenharmony_ci * struct hl_vm - virtual memory manager for MMU.
11358c2ecf20Sopenharmony_ci * @dram_pg_pool: pool for DRAM physical pages of 2MB.
11368c2ecf20Sopenharmony_ci * @dram_pg_pool_refcount: reference counter for the pool usage.
11378c2ecf20Sopenharmony_ci * @idr_lock: protects the phys_pg_list_handles.
11388c2ecf20Sopenharmony_ci * @phys_pg_pack_handles: idr to hold all device allocations handles.
11398c2ecf20Sopenharmony_ci * @init_done: whether initialization was done. We need this because VM
11408c2ecf20Sopenharmony_ci *		initialization might be skipped during device initialization.
11418c2ecf20Sopenharmony_ci */
11428c2ecf20Sopenharmony_cistruct hl_vm {
11438c2ecf20Sopenharmony_ci	struct gen_pool		*dram_pg_pool;
11448c2ecf20Sopenharmony_ci	struct kref		dram_pg_pool_refcount;
11458c2ecf20Sopenharmony_ci	spinlock_t		idr_lock;
11468c2ecf20Sopenharmony_ci	struct idr		phys_pg_pack_handles;
11478c2ecf20Sopenharmony_ci	u8			init_done;
11488c2ecf20Sopenharmony_ci};
11498c2ecf20Sopenharmony_ci
11508c2ecf20Sopenharmony_ci
11518c2ecf20Sopenharmony_ci/*
11528c2ecf20Sopenharmony_ci * DEBUG, PROFILING STRUCTURE
11538c2ecf20Sopenharmony_ci */
11548c2ecf20Sopenharmony_ci
11558c2ecf20Sopenharmony_ci/**
11568c2ecf20Sopenharmony_ci * struct hl_debug_params - Coresight debug parameters.
11578c2ecf20Sopenharmony_ci * @input: pointer to component specific input parameters.
11588c2ecf20Sopenharmony_ci * @output: pointer to component specific output parameters.
11598c2ecf20Sopenharmony_ci * @output_size: size of output buffer.
11608c2ecf20Sopenharmony_ci * @reg_idx: relevant register ID.
11618c2ecf20Sopenharmony_ci * @op: component operation to execute.
11628c2ecf20Sopenharmony_ci * @enable: true if to enable component debugging, false otherwise.
11638c2ecf20Sopenharmony_ci */
11648c2ecf20Sopenharmony_cistruct hl_debug_params {
11658c2ecf20Sopenharmony_ci	void *input;
11668c2ecf20Sopenharmony_ci	void *output;
11678c2ecf20Sopenharmony_ci	u32 output_size;
11688c2ecf20Sopenharmony_ci	u32 reg_idx;
11698c2ecf20Sopenharmony_ci	u32 op;
11708c2ecf20Sopenharmony_ci	bool enable;
11718c2ecf20Sopenharmony_ci};
11728c2ecf20Sopenharmony_ci
11738c2ecf20Sopenharmony_ci/*
11748c2ecf20Sopenharmony_ci * FILE PRIVATE STRUCTURE
11758c2ecf20Sopenharmony_ci */
11768c2ecf20Sopenharmony_ci
11778c2ecf20Sopenharmony_ci/**
11788c2ecf20Sopenharmony_ci * struct hl_fpriv - process information stored in FD private data.
11798c2ecf20Sopenharmony_ci * @hdev: habanalabs device structure.
11808c2ecf20Sopenharmony_ci * @filp: pointer to the given file structure.
11818c2ecf20Sopenharmony_ci * @taskpid: current process ID.
11828c2ecf20Sopenharmony_ci * @ctx: current executing context. TODO: remove for multiple ctx per process
11838c2ecf20Sopenharmony_ci * @ctx_mgr: context manager to handle multiple context for this FD.
11848c2ecf20Sopenharmony_ci * @cb_mgr: command buffer manager to handle multiple buffers for this FD.
11858c2ecf20Sopenharmony_ci * @debugfs_list: list of relevant ASIC debugfs.
11868c2ecf20Sopenharmony_ci * @dev_node: node in the device list of file private data
11878c2ecf20Sopenharmony_ci * @refcount: number of related contexts.
11888c2ecf20Sopenharmony_ci * @restore_phase_mutex: lock for context switch and restore phase.
11898c2ecf20Sopenharmony_ci * @is_control: true for control device, false otherwise
11908c2ecf20Sopenharmony_ci */
11918c2ecf20Sopenharmony_cistruct hl_fpriv {
11928c2ecf20Sopenharmony_ci	struct hl_device	*hdev;
11938c2ecf20Sopenharmony_ci	struct file		*filp;
11948c2ecf20Sopenharmony_ci	struct pid		*taskpid;
11958c2ecf20Sopenharmony_ci	struct hl_ctx		*ctx;
11968c2ecf20Sopenharmony_ci	struct hl_ctx_mgr	ctx_mgr;
11978c2ecf20Sopenharmony_ci	struct hl_cb_mgr	cb_mgr;
11988c2ecf20Sopenharmony_ci	struct list_head	debugfs_list;
11998c2ecf20Sopenharmony_ci	struct list_head	dev_node;
12008c2ecf20Sopenharmony_ci	struct kref		refcount;
12018c2ecf20Sopenharmony_ci	struct mutex		restore_phase_mutex;
12028c2ecf20Sopenharmony_ci	u8			is_control;
12038c2ecf20Sopenharmony_ci};
12048c2ecf20Sopenharmony_ci
12058c2ecf20Sopenharmony_ci
12068c2ecf20Sopenharmony_ci/*
12078c2ecf20Sopenharmony_ci * DebugFS
12088c2ecf20Sopenharmony_ci */
12098c2ecf20Sopenharmony_ci
12108c2ecf20Sopenharmony_ci/**
12118c2ecf20Sopenharmony_ci * struct hl_info_list - debugfs file ops.
12128c2ecf20Sopenharmony_ci * @name: file name.
12138c2ecf20Sopenharmony_ci * @show: function to output information.
12148c2ecf20Sopenharmony_ci * @write: function to write to the file.
12158c2ecf20Sopenharmony_ci */
12168c2ecf20Sopenharmony_cistruct hl_info_list {
12178c2ecf20Sopenharmony_ci	const char	*name;
12188c2ecf20Sopenharmony_ci	int		(*show)(struct seq_file *s, void *data);
12198c2ecf20Sopenharmony_ci	ssize_t		(*write)(struct file *file, const char __user *buf,
12208c2ecf20Sopenharmony_ci				size_t count, loff_t *f_pos);
12218c2ecf20Sopenharmony_ci};
12228c2ecf20Sopenharmony_ci
12238c2ecf20Sopenharmony_ci/**
12248c2ecf20Sopenharmony_ci * struct hl_debugfs_entry - debugfs dentry wrapper.
12258c2ecf20Sopenharmony_ci * @dent: base debugfs entry structure.
12268c2ecf20Sopenharmony_ci * @info_ent: dentry realted ops.
12278c2ecf20Sopenharmony_ci * @dev_entry: ASIC specific debugfs manager.
12288c2ecf20Sopenharmony_ci */
12298c2ecf20Sopenharmony_cistruct hl_debugfs_entry {
12308c2ecf20Sopenharmony_ci	struct dentry			*dent;
12318c2ecf20Sopenharmony_ci	const struct hl_info_list	*info_ent;
12328c2ecf20Sopenharmony_ci	struct hl_dbg_device_entry	*dev_entry;
12338c2ecf20Sopenharmony_ci};
12348c2ecf20Sopenharmony_ci
12358c2ecf20Sopenharmony_ci/**
12368c2ecf20Sopenharmony_ci * struct hl_dbg_device_entry - ASIC specific debugfs manager.
12378c2ecf20Sopenharmony_ci * @root: root dentry.
12388c2ecf20Sopenharmony_ci * @hdev: habanalabs device structure.
12398c2ecf20Sopenharmony_ci * @entry_arr: array of available hl_debugfs_entry.
12408c2ecf20Sopenharmony_ci * @file_list: list of available debugfs files.
12418c2ecf20Sopenharmony_ci * @file_mutex: protects file_list.
12428c2ecf20Sopenharmony_ci * @cb_list: list of available CBs.
12438c2ecf20Sopenharmony_ci * @cb_spinlock: protects cb_list.
12448c2ecf20Sopenharmony_ci * @cs_list: list of available CSs.
12458c2ecf20Sopenharmony_ci * @cs_spinlock: protects cs_list.
12468c2ecf20Sopenharmony_ci * @cs_job_list: list of available CB jobs.
12478c2ecf20Sopenharmony_ci * @cs_job_spinlock: protects cs_job_list.
12488c2ecf20Sopenharmony_ci * @userptr_list: list of available userptrs (virtual memory chunk descriptor).
12498c2ecf20Sopenharmony_ci * @userptr_spinlock: protects userptr_list.
12508c2ecf20Sopenharmony_ci * @ctx_mem_hash_list: list of available contexts with MMU mappings.
12518c2ecf20Sopenharmony_ci * @ctx_mem_hash_spinlock: protects cb_list.
12528c2ecf20Sopenharmony_ci * @addr: next address to read/write from/to in read/write32.
12538c2ecf20Sopenharmony_ci * @mmu_addr: next virtual address to translate to physical address in mmu_show.
12548c2ecf20Sopenharmony_ci * @mmu_asid: ASID to use while translating in mmu_show.
12558c2ecf20Sopenharmony_ci * @i2c_bus: generic u8 debugfs file for bus value to use in i2c_data_read.
12568c2ecf20Sopenharmony_ci * @i2c_bus: generic u8 debugfs file for address value to use in i2c_data_read.
12578c2ecf20Sopenharmony_ci * @i2c_bus: generic u8 debugfs file for register value to use in i2c_data_read.
12588c2ecf20Sopenharmony_ci */
12598c2ecf20Sopenharmony_cistruct hl_dbg_device_entry {
12608c2ecf20Sopenharmony_ci	struct dentry			*root;
12618c2ecf20Sopenharmony_ci	struct hl_device		*hdev;
12628c2ecf20Sopenharmony_ci	struct hl_debugfs_entry		*entry_arr;
12638c2ecf20Sopenharmony_ci	struct list_head		file_list;
12648c2ecf20Sopenharmony_ci	struct mutex			file_mutex;
12658c2ecf20Sopenharmony_ci	struct list_head		cb_list;
12668c2ecf20Sopenharmony_ci	spinlock_t			cb_spinlock;
12678c2ecf20Sopenharmony_ci	struct list_head		cs_list;
12688c2ecf20Sopenharmony_ci	spinlock_t			cs_spinlock;
12698c2ecf20Sopenharmony_ci	struct list_head		cs_job_list;
12708c2ecf20Sopenharmony_ci	spinlock_t			cs_job_spinlock;
12718c2ecf20Sopenharmony_ci	struct list_head		userptr_list;
12728c2ecf20Sopenharmony_ci	spinlock_t			userptr_spinlock;
12738c2ecf20Sopenharmony_ci	struct list_head		ctx_mem_hash_list;
12748c2ecf20Sopenharmony_ci	spinlock_t			ctx_mem_hash_spinlock;
12758c2ecf20Sopenharmony_ci	u64				addr;
12768c2ecf20Sopenharmony_ci	u64				mmu_addr;
12778c2ecf20Sopenharmony_ci	u32				mmu_asid;
12788c2ecf20Sopenharmony_ci	u8				i2c_bus;
12798c2ecf20Sopenharmony_ci	u8				i2c_addr;
12808c2ecf20Sopenharmony_ci	u8				i2c_reg;
12818c2ecf20Sopenharmony_ci};
12828c2ecf20Sopenharmony_ci
12838c2ecf20Sopenharmony_ci
12848c2ecf20Sopenharmony_ci/*
12858c2ecf20Sopenharmony_ci * DEVICES
12868c2ecf20Sopenharmony_ci */
12878c2ecf20Sopenharmony_ci
12888c2ecf20Sopenharmony_ci/* Theoretical limit only. A single host can only contain up to 4 or 8 PCIe
12898c2ecf20Sopenharmony_ci * x16 cards. In extreme cases, there are hosts that can accommodate 16 cards.
12908c2ecf20Sopenharmony_ci */
12918c2ecf20Sopenharmony_ci#define HL_MAX_MINORS	256
12928c2ecf20Sopenharmony_ci
12938c2ecf20Sopenharmony_ci/*
12948c2ecf20Sopenharmony_ci * Registers read & write functions.
12958c2ecf20Sopenharmony_ci */
12968c2ecf20Sopenharmony_ci
12978c2ecf20Sopenharmony_ciu32 hl_rreg(struct hl_device *hdev, u32 reg);
12988c2ecf20Sopenharmony_civoid hl_wreg(struct hl_device *hdev, u32 reg, u32 val);
12998c2ecf20Sopenharmony_ci
13008c2ecf20Sopenharmony_ci#define RREG32(reg) hdev->asic_funcs->rreg(hdev, (reg))
13018c2ecf20Sopenharmony_ci#define WREG32(reg, v) hdev->asic_funcs->wreg(hdev, (reg), (v))
13028c2ecf20Sopenharmony_ci#define DREG32(reg) pr_info("REGISTER: " #reg " : 0x%08X\n",	\
13038c2ecf20Sopenharmony_ci			hdev->asic_funcs->rreg(hdev, (reg)))
13048c2ecf20Sopenharmony_ci
13058c2ecf20Sopenharmony_ci#define WREG32_P(reg, val, mask)				\
13068c2ecf20Sopenharmony_ci	do {							\
13078c2ecf20Sopenharmony_ci		u32 tmp_ = RREG32(reg);				\
13088c2ecf20Sopenharmony_ci		tmp_ &= (mask);					\
13098c2ecf20Sopenharmony_ci		tmp_ |= ((val) & ~(mask));			\
13108c2ecf20Sopenharmony_ci		WREG32(reg, tmp_);				\
13118c2ecf20Sopenharmony_ci	} while (0)
13128c2ecf20Sopenharmony_ci#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
13138c2ecf20Sopenharmony_ci#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
13148c2ecf20Sopenharmony_ci
13158c2ecf20Sopenharmony_ci#define RMWREG32(reg, val, mask)				\
13168c2ecf20Sopenharmony_ci	do {							\
13178c2ecf20Sopenharmony_ci		u32 tmp_ = RREG32(reg);				\
13188c2ecf20Sopenharmony_ci		tmp_ &= ~(mask);				\
13198c2ecf20Sopenharmony_ci		tmp_ |= ((val) << __ffs(mask));			\
13208c2ecf20Sopenharmony_ci		WREG32(reg, tmp_);				\
13218c2ecf20Sopenharmony_ci	} while (0)
13228c2ecf20Sopenharmony_ci
13238c2ecf20Sopenharmony_ci#define RREG32_MASK(reg, mask) ((RREG32(reg) & mask) >> __ffs(mask))
13248c2ecf20Sopenharmony_ci
13258c2ecf20Sopenharmony_ci#define REG_FIELD_SHIFT(reg, field) reg##_##field##_SHIFT
13268c2ecf20Sopenharmony_ci#define REG_FIELD_MASK(reg, field) reg##_##field##_MASK
13278c2ecf20Sopenharmony_ci#define WREG32_FIELD(reg, offset, field, val)	\
13288c2ecf20Sopenharmony_ci	WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & \
13298c2ecf20Sopenharmony_ci				~REG_FIELD_MASK(reg, field)) | \
13308c2ecf20Sopenharmony_ci				(val) << REG_FIELD_SHIFT(reg, field))
13318c2ecf20Sopenharmony_ci
13328c2ecf20Sopenharmony_ci/* Timeout should be longer when working with simulator but cap the
13338c2ecf20Sopenharmony_ci * increased timeout to some maximum
13348c2ecf20Sopenharmony_ci */
13358c2ecf20Sopenharmony_ci#define hl_poll_timeout(hdev, addr, val, cond, sleep_us, timeout_us) \
13368c2ecf20Sopenharmony_ci({ \
13378c2ecf20Sopenharmony_ci	ktime_t __timeout; \
13388c2ecf20Sopenharmony_ci	if (hdev->pdev) \
13398c2ecf20Sopenharmony_ci		__timeout = ktime_add_us(ktime_get(), timeout_us); \
13408c2ecf20Sopenharmony_ci	else \
13418c2ecf20Sopenharmony_ci		__timeout = ktime_add_us(ktime_get(),\
13428c2ecf20Sopenharmony_ci				min((u64)(timeout_us * 10), \
13438c2ecf20Sopenharmony_ci					(u64) HL_SIM_MAX_TIMEOUT_US)); \
13448c2ecf20Sopenharmony_ci	might_sleep_if(sleep_us); \
13458c2ecf20Sopenharmony_ci	for (;;) { \
13468c2ecf20Sopenharmony_ci		(val) = RREG32(addr); \
13478c2ecf20Sopenharmony_ci		if (cond) \
13488c2ecf20Sopenharmony_ci			break; \
13498c2ecf20Sopenharmony_ci		if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \
13508c2ecf20Sopenharmony_ci			(val) = RREG32(addr); \
13518c2ecf20Sopenharmony_ci			break; \
13528c2ecf20Sopenharmony_ci		} \
13538c2ecf20Sopenharmony_ci		if (sleep_us) \
13548c2ecf20Sopenharmony_ci			usleep_range((sleep_us >> 2) + 1, sleep_us); \
13558c2ecf20Sopenharmony_ci	} \
13568c2ecf20Sopenharmony_ci	(cond) ? 0 : -ETIMEDOUT; \
13578c2ecf20Sopenharmony_ci})
13588c2ecf20Sopenharmony_ci
13598c2ecf20Sopenharmony_ci/*
13608c2ecf20Sopenharmony_ci * address in this macro points always to a memory location in the
13618c2ecf20Sopenharmony_ci * host's (server's) memory. That location is updated asynchronously
13628c2ecf20Sopenharmony_ci * either by the direct access of the device or by another core.
13638c2ecf20Sopenharmony_ci *
13648c2ecf20Sopenharmony_ci * To work both in LE and BE architectures, we need to distinguish between the
13658c2ecf20Sopenharmony_ci * two states (device or another core updates the memory location). Therefore,
13668c2ecf20Sopenharmony_ci * if mem_written_by_device is true, the host memory being polled will be
13678c2ecf20Sopenharmony_ci * updated directly by the device. If false, the host memory being polled will
13688c2ecf20Sopenharmony_ci * be updated by host CPU. Required so host knows whether or not the memory
13698c2ecf20Sopenharmony_ci * might need to be byte-swapped before returning value to caller.
13708c2ecf20Sopenharmony_ci */
13718c2ecf20Sopenharmony_ci#define hl_poll_timeout_memory(hdev, addr, val, cond, sleep_us, timeout_us, \
13728c2ecf20Sopenharmony_ci				mem_written_by_device) \
13738c2ecf20Sopenharmony_ci({ \
13748c2ecf20Sopenharmony_ci	ktime_t __timeout; \
13758c2ecf20Sopenharmony_ci	if (hdev->pdev) \
13768c2ecf20Sopenharmony_ci		__timeout = ktime_add_us(ktime_get(), timeout_us); \
13778c2ecf20Sopenharmony_ci	else \
13788c2ecf20Sopenharmony_ci		__timeout = ktime_add_us(ktime_get(),\
13798c2ecf20Sopenharmony_ci				min((u64)(timeout_us * 10), \
13808c2ecf20Sopenharmony_ci					(u64) HL_SIM_MAX_TIMEOUT_US)); \
13818c2ecf20Sopenharmony_ci	might_sleep_if(sleep_us); \
13828c2ecf20Sopenharmony_ci	for (;;) { \
13838c2ecf20Sopenharmony_ci		/* Verify we read updates done by other cores or by device */ \
13848c2ecf20Sopenharmony_ci		mb(); \
13858c2ecf20Sopenharmony_ci		(val) = *((u32 *)(addr)); \
13868c2ecf20Sopenharmony_ci		if (mem_written_by_device) \
13878c2ecf20Sopenharmony_ci			(val) = le32_to_cpu(*(__le32 *) &(val)); \
13888c2ecf20Sopenharmony_ci		if (cond) \
13898c2ecf20Sopenharmony_ci			break; \
13908c2ecf20Sopenharmony_ci		if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \
13918c2ecf20Sopenharmony_ci			(val) = *((u32 *)(addr)); \
13928c2ecf20Sopenharmony_ci			if (mem_written_by_device) \
13938c2ecf20Sopenharmony_ci				(val) = le32_to_cpu(*(__le32 *) &(val)); \
13948c2ecf20Sopenharmony_ci			break; \
13958c2ecf20Sopenharmony_ci		} \
13968c2ecf20Sopenharmony_ci		if (sleep_us) \
13978c2ecf20Sopenharmony_ci			usleep_range((sleep_us >> 2) + 1, sleep_us); \
13988c2ecf20Sopenharmony_ci	} \
13998c2ecf20Sopenharmony_ci	(cond) ? 0 : -ETIMEDOUT; \
14008c2ecf20Sopenharmony_ci})
14018c2ecf20Sopenharmony_ci
14028c2ecf20Sopenharmony_ci#define hl_poll_timeout_device_memory(hdev, addr, val, cond, sleep_us, \
14038c2ecf20Sopenharmony_ci					timeout_us) \
14048c2ecf20Sopenharmony_ci({ \
14058c2ecf20Sopenharmony_ci	ktime_t __timeout; \
14068c2ecf20Sopenharmony_ci	if (hdev->pdev) \
14078c2ecf20Sopenharmony_ci		__timeout = ktime_add_us(ktime_get(), timeout_us); \
14088c2ecf20Sopenharmony_ci	else \
14098c2ecf20Sopenharmony_ci		__timeout = ktime_add_us(ktime_get(),\
14108c2ecf20Sopenharmony_ci				min((u64)(timeout_us * 10), \
14118c2ecf20Sopenharmony_ci					(u64) HL_SIM_MAX_TIMEOUT_US)); \
14128c2ecf20Sopenharmony_ci	might_sleep_if(sleep_us); \
14138c2ecf20Sopenharmony_ci	for (;;) { \
14148c2ecf20Sopenharmony_ci		(val) = readl(addr); \
14158c2ecf20Sopenharmony_ci		if (cond) \
14168c2ecf20Sopenharmony_ci			break; \
14178c2ecf20Sopenharmony_ci		if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \
14188c2ecf20Sopenharmony_ci			(val) = readl(addr); \
14198c2ecf20Sopenharmony_ci			break; \
14208c2ecf20Sopenharmony_ci		} \
14218c2ecf20Sopenharmony_ci		if (sleep_us) \
14228c2ecf20Sopenharmony_ci			usleep_range((sleep_us >> 2) + 1, sleep_us); \
14238c2ecf20Sopenharmony_ci	} \
14248c2ecf20Sopenharmony_ci	(cond) ? 0 : -ETIMEDOUT; \
14258c2ecf20Sopenharmony_ci})
14268c2ecf20Sopenharmony_ci
14278c2ecf20Sopenharmony_cistruct hwmon_chip_info;
14288c2ecf20Sopenharmony_ci
14298c2ecf20Sopenharmony_ci/**
14308c2ecf20Sopenharmony_ci * struct hl_device_reset_work - reset workqueue task wrapper.
14318c2ecf20Sopenharmony_ci * @reset_work: reset work to be done.
14328c2ecf20Sopenharmony_ci * @hdev: habanalabs device structure.
14338c2ecf20Sopenharmony_ci */
14348c2ecf20Sopenharmony_cistruct hl_device_reset_work {
14358c2ecf20Sopenharmony_ci	struct work_struct		reset_work;
14368c2ecf20Sopenharmony_ci	struct hl_device		*hdev;
14378c2ecf20Sopenharmony_ci};
14388c2ecf20Sopenharmony_ci
14398c2ecf20Sopenharmony_ci/**
14408c2ecf20Sopenharmony_ci * struct hl_device_idle_busy_ts - used for calculating device utilization rate.
14418c2ecf20Sopenharmony_ci * @idle_to_busy_ts: timestamp where device changed from idle to busy.
14428c2ecf20Sopenharmony_ci * @busy_to_idle_ts: timestamp where device changed from busy to idle.
14438c2ecf20Sopenharmony_ci */
14448c2ecf20Sopenharmony_cistruct hl_device_idle_busy_ts {
14458c2ecf20Sopenharmony_ci	ktime_t				idle_to_busy_ts;
14468c2ecf20Sopenharmony_ci	ktime_t				busy_to_idle_ts;
14478c2ecf20Sopenharmony_ci};
14488c2ecf20Sopenharmony_ci
14498c2ecf20Sopenharmony_ci
14508c2ecf20Sopenharmony_ci/**
14518c2ecf20Sopenharmony_ci * struct hl_mmu_priv - used for holding per-device mmu internal information.
14528c2ecf20Sopenharmony_ci * @mmu_pgt_pool: pool of page tables used by MMU for allocating hops.
14538c2ecf20Sopenharmony_ci * @mmu_shadow_hop0: shadow array of hop0 tables.
14548c2ecf20Sopenharmony_ci */
14558c2ecf20Sopenharmony_cistruct hl_mmu_priv {
14568c2ecf20Sopenharmony_ci	struct gen_pool *mmu_pgt_pool;
14578c2ecf20Sopenharmony_ci	void *mmu_shadow_hop0;
14588c2ecf20Sopenharmony_ci};
14598c2ecf20Sopenharmony_ci
14608c2ecf20Sopenharmony_ci/**
14618c2ecf20Sopenharmony_ci * struct hl_mmu_funcs - Device related MMU functions.
14628c2ecf20Sopenharmony_ci * @init: initialize the MMU module.
14638c2ecf20Sopenharmony_ci * @fini: release the MMU module.
14648c2ecf20Sopenharmony_ci * @ctx_init: Initialize a context for using the MMU module.
14658c2ecf20Sopenharmony_ci * @ctx_fini: disable a ctx from using the mmu module.
14668c2ecf20Sopenharmony_ci * @map: maps a virtual address to physical address for a context.
14678c2ecf20Sopenharmony_ci * @unmap: unmap a virtual address of a context.
14688c2ecf20Sopenharmony_ci * @flush: flush all writes from all cores to reach device MMU.
14698c2ecf20Sopenharmony_ci * @swap_out: marks all mapping of the given context as swapped out.
14708c2ecf20Sopenharmony_ci * @swap_in: marks all mapping of the given context as swapped in.
14718c2ecf20Sopenharmony_ci */
14728c2ecf20Sopenharmony_cistruct hl_mmu_funcs {
14738c2ecf20Sopenharmony_ci	int (*init)(struct hl_device *hdev);
14748c2ecf20Sopenharmony_ci	void (*fini)(struct hl_device *hdev);
14758c2ecf20Sopenharmony_ci	int (*ctx_init)(struct hl_ctx *ctx);
14768c2ecf20Sopenharmony_ci	void (*ctx_fini)(struct hl_ctx *ctx);
14778c2ecf20Sopenharmony_ci	int (*map)(struct hl_ctx *ctx,
14788c2ecf20Sopenharmony_ci			u64 virt_addr, u64 phys_addr, u32 page_size,
14798c2ecf20Sopenharmony_ci			bool is_dram_addr);
14808c2ecf20Sopenharmony_ci	int (*unmap)(struct hl_ctx *ctx,
14818c2ecf20Sopenharmony_ci			u64 virt_addr, bool is_dram_addr);
14828c2ecf20Sopenharmony_ci	void (*flush)(struct hl_ctx *ctx);
14838c2ecf20Sopenharmony_ci	void (*swap_out)(struct hl_ctx *ctx);
14848c2ecf20Sopenharmony_ci	void (*swap_in)(struct hl_ctx *ctx);
14858c2ecf20Sopenharmony_ci};
14868c2ecf20Sopenharmony_ci
14878c2ecf20Sopenharmony_ci/**
14888c2ecf20Sopenharmony_ci * struct hl_device - habanalabs device structure.
14898c2ecf20Sopenharmony_ci * @pdev: pointer to PCI device, can be NULL in case of simulator device.
14908c2ecf20Sopenharmony_ci * @pcie_bar_phys: array of available PCIe bars physical addresses.
14918c2ecf20Sopenharmony_ci *		   (required only for PCI address match mode)
14928c2ecf20Sopenharmony_ci * @pcie_bar: array of available PCIe bars virtual addresses.
14938c2ecf20Sopenharmony_ci * @rmmio: configuration area address on SRAM.
14948c2ecf20Sopenharmony_ci * @cdev: related char device.
14958c2ecf20Sopenharmony_ci * @cdev_ctrl: char device for control operations only (INFO IOCTL)
14968c2ecf20Sopenharmony_ci * @dev: related kernel basic device structure.
14978c2ecf20Sopenharmony_ci * @dev_ctrl: related kernel device structure for the control device
14988c2ecf20Sopenharmony_ci * @work_freq: delayed work to lower device frequency if possible.
14998c2ecf20Sopenharmony_ci * @work_heartbeat: delayed work for CPU-CP is-alive check.
15008c2ecf20Sopenharmony_ci * @asic_name: ASIC specific name.
15018c2ecf20Sopenharmony_ci * @asic_type: ASIC specific type.
15028c2ecf20Sopenharmony_ci * @completion_queue: array of hl_cq.
15038c2ecf20Sopenharmony_ci * @cq_wq: work queues of completion queues for executing work in process
15048c2ecf20Sopenharmony_ci *         context.
15058c2ecf20Sopenharmony_ci * @eq_wq: work queue of event queue for executing work in process context.
15068c2ecf20Sopenharmony_ci * @kernel_ctx: Kernel driver context structure.
15078c2ecf20Sopenharmony_ci * @kernel_queues: array of hl_hw_queue.
15088c2ecf20Sopenharmony_ci * @hw_queues_mirror_list: CS mirror list for TDR.
15098c2ecf20Sopenharmony_ci * @hw_queues_mirror_lock: protects hw_queues_mirror_list.
15108c2ecf20Sopenharmony_ci * @kernel_cb_mgr: command buffer manager for creating/destroying/handling CGs.
15118c2ecf20Sopenharmony_ci * @event_queue: event queue for IRQ from CPU-CP.
15128c2ecf20Sopenharmony_ci * @dma_pool: DMA pool for small allocations.
15138c2ecf20Sopenharmony_ci * @cpu_accessible_dma_mem: Host <-> CPU-CP shared memory CPU address.
15148c2ecf20Sopenharmony_ci * @cpu_accessible_dma_address: Host <-> CPU-CP shared memory DMA address.
15158c2ecf20Sopenharmony_ci * @cpu_accessible_dma_pool: Host <-> CPU-CP shared memory pool.
15168c2ecf20Sopenharmony_ci * @asid_bitmap: holds used/available ASIDs.
15178c2ecf20Sopenharmony_ci * @asid_mutex: protects asid_bitmap.
15188c2ecf20Sopenharmony_ci * @send_cpu_message_lock: enforces only one message in Host <-> CPU-CP queue.
15198c2ecf20Sopenharmony_ci * @debug_lock: protects critical section of setting debug mode for device
15208c2ecf20Sopenharmony_ci * @asic_prop: ASIC specific immutable properties.
15218c2ecf20Sopenharmony_ci * @asic_funcs: ASIC specific functions.
15228c2ecf20Sopenharmony_ci * @asic_specific: ASIC specific information to use only from ASIC files.
15238c2ecf20Sopenharmony_ci * @vm: virtual memory manager for MMU.
15248c2ecf20Sopenharmony_ci * @mmu_cache_lock: protects MMU cache invalidation as it can serve one context.
15258c2ecf20Sopenharmony_ci * @hwmon_dev: H/W monitor device.
15268c2ecf20Sopenharmony_ci * @pm_mng_profile: current power management profile.
15278c2ecf20Sopenharmony_ci * @hl_chip_info: ASIC's sensors information.
15288c2ecf20Sopenharmony_ci * @hl_debugfs: device's debugfs manager.
15298c2ecf20Sopenharmony_ci * @cb_pool: list of preallocated CBs.
15308c2ecf20Sopenharmony_ci * @cb_pool_lock: protects the CB pool.
15318c2ecf20Sopenharmony_ci * @internal_cb_pool_virt_addr: internal command buffer pool virtual address.
15328c2ecf20Sopenharmony_ci * @internal_cb_pool_dma_addr: internal command buffer pool dma address.
15338c2ecf20Sopenharmony_ci * @internal_cb_pool: internal command buffer memory pool.
15348c2ecf20Sopenharmony_ci * @internal_cb_va_base: internal cb pool mmu virtual address base
15358c2ecf20Sopenharmony_ci * @fpriv_list: list of file private data structures. Each structure is created
15368c2ecf20Sopenharmony_ci *              when a user opens the device
15378c2ecf20Sopenharmony_ci * @fpriv_list_lock: protects the fpriv_list
15388c2ecf20Sopenharmony_ci * @compute_ctx: current compute context executing.
15398c2ecf20Sopenharmony_ci * @idle_busy_ts_arr: array to hold time stamps of transitions from idle to busy
15408c2ecf20Sopenharmony_ci *                    and vice-versa
15418c2ecf20Sopenharmony_ci * @aggregated_cs_counters: aggregated cs counters among all contexts
15428c2ecf20Sopenharmony_ci * @mmu_priv: device-specific MMU data.
15438c2ecf20Sopenharmony_ci * @mmu_func: device-related MMU functions.
15448c2ecf20Sopenharmony_ci * @dram_used_mem: current DRAM memory consumption.
15458c2ecf20Sopenharmony_ci * @timeout_jiffies: device CS timeout value.
15468c2ecf20Sopenharmony_ci * @max_power: the max power of the device, as configured by the sysadmin. This
15478c2ecf20Sopenharmony_ci *             value is saved so in case of hard-reset, the driver will restore
15488c2ecf20Sopenharmony_ci *             this value and update the F/W after the re-initialization
15498c2ecf20Sopenharmony_ci * @clock_gating_mask: is clock gating enabled. bitmask that represents the
15508c2ecf20Sopenharmony_ci *                     different engines. See debugfs-driver-habanalabs for
15518c2ecf20Sopenharmony_ci *                     details.
15528c2ecf20Sopenharmony_ci * @in_reset: is device in reset flow.
15538c2ecf20Sopenharmony_ci * @curr_pll_profile: current PLL profile.
15548c2ecf20Sopenharmony_ci * @card_type: Various ASICs have several card types. This indicates the card
15558c2ecf20Sopenharmony_ci *             type of the current device.
15568c2ecf20Sopenharmony_ci * @cs_active_cnt: number of active command submissions on this device (active
15578c2ecf20Sopenharmony_ci *                 means already in H/W queues)
15588c2ecf20Sopenharmony_ci * @major: habanalabs kernel driver major.
15598c2ecf20Sopenharmony_ci * @high_pll: high PLL profile frequency.
15608c2ecf20Sopenharmony_ci * @soft_reset_cnt: number of soft reset since the driver was loaded.
15618c2ecf20Sopenharmony_ci * @hard_reset_cnt: number of hard reset since the driver was loaded.
15628c2ecf20Sopenharmony_ci * @idle_busy_ts_idx: index of current entry in idle_busy_ts_arr
15638c2ecf20Sopenharmony_ci * @clk_throttling_reason: bitmask represents the current clk throttling reasons
15648c2ecf20Sopenharmony_ci * @id: device minor.
15658c2ecf20Sopenharmony_ci * @id_control: minor of the control device
15668c2ecf20Sopenharmony_ci * @cpu_pci_msb_addr: 50-bit extension bits for the device CPU's 40-bit
15678c2ecf20Sopenharmony_ci *                    addresses.
15688c2ecf20Sopenharmony_ci * @disabled: is device disabled.
15698c2ecf20Sopenharmony_ci * @late_init_done: is late init stage was done during initialization.
15708c2ecf20Sopenharmony_ci * @hwmon_initialized: is H/W monitor sensors was initialized.
15718c2ecf20Sopenharmony_ci * @hard_reset_pending: is there a hard reset work pending.
15728c2ecf20Sopenharmony_ci * @heartbeat: is heartbeat sanity check towards CPU-CP enabled.
15738c2ecf20Sopenharmony_ci * @reset_on_lockup: true if a reset should be done in case of stuck CS, false
15748c2ecf20Sopenharmony_ci *                   otherwise.
15758c2ecf20Sopenharmony_ci * @dram_supports_virtual_memory: is MMU enabled towards DRAM.
15768c2ecf20Sopenharmony_ci * @dram_default_page_mapping: is DRAM default page mapping enabled.
15778c2ecf20Sopenharmony_ci * @pmmu_huge_range: is a different virtual addresses range used for PMMU with
15788c2ecf20Sopenharmony_ci *                   huge pages.
15798c2ecf20Sopenharmony_ci * @init_done: is the initialization of the device done.
15808c2ecf20Sopenharmony_ci * @mmu_enable: is MMU enabled.
15818c2ecf20Sopenharmony_ci * @mmu_huge_page_opt: is MMU huge pages optimization enabled.
15828c2ecf20Sopenharmony_ci * @device_cpu_disabled: is the device CPU disabled (due to timeouts)
15838c2ecf20Sopenharmony_ci * @dma_mask: the dma mask that was set for this device
15848c2ecf20Sopenharmony_ci * @in_debug: is device under debug. This, together with fpriv_list, enforces
15858c2ecf20Sopenharmony_ci *            that only a single user is configuring the debug infrastructure.
15868c2ecf20Sopenharmony_ci * @power9_64bit_dma_enable: true to enable 64-bit DMA mask support. Relevant
15878c2ecf20Sopenharmony_ci *                           only to POWER9 machines.
15888c2ecf20Sopenharmony_ci * @cdev_sysfs_created: were char devices and sysfs nodes created.
15898c2ecf20Sopenharmony_ci * @stop_on_err: true if engines should stop on error.
15908c2ecf20Sopenharmony_ci * @supports_sync_stream: is sync stream supported.
15918c2ecf20Sopenharmony_ci * @sync_stream_queue_idx: helper index for sync stream queues initialization.
15928c2ecf20Sopenharmony_ci * @supports_coresight: is CoreSight supported.
15938c2ecf20Sopenharmony_ci * @supports_soft_reset: is soft reset supported.
15948c2ecf20Sopenharmony_ci * @supports_cb_mapping: is mapping a CB to the device's MMU supported.
15958c2ecf20Sopenharmony_ci */
15968c2ecf20Sopenharmony_cistruct hl_device {
15978c2ecf20Sopenharmony_ci	struct pci_dev			*pdev;
15988c2ecf20Sopenharmony_ci	u64				pcie_bar_phys[HL_PCI_NUM_BARS];
15998c2ecf20Sopenharmony_ci	void __iomem			*pcie_bar[HL_PCI_NUM_BARS];
16008c2ecf20Sopenharmony_ci	void __iomem			*rmmio;
16018c2ecf20Sopenharmony_ci	struct cdev			cdev;
16028c2ecf20Sopenharmony_ci	struct cdev			cdev_ctrl;
16038c2ecf20Sopenharmony_ci	struct device			*dev;
16048c2ecf20Sopenharmony_ci	struct device			*dev_ctrl;
16058c2ecf20Sopenharmony_ci	struct delayed_work		work_freq;
16068c2ecf20Sopenharmony_ci	struct delayed_work		work_heartbeat;
16078c2ecf20Sopenharmony_ci	char				asic_name[32];
16088c2ecf20Sopenharmony_ci	enum hl_asic_type		asic_type;
16098c2ecf20Sopenharmony_ci	struct hl_cq			*completion_queue;
16108c2ecf20Sopenharmony_ci	struct workqueue_struct		**cq_wq;
16118c2ecf20Sopenharmony_ci	struct workqueue_struct		*eq_wq;
16128c2ecf20Sopenharmony_ci	struct hl_ctx			*kernel_ctx;
16138c2ecf20Sopenharmony_ci	struct hl_hw_queue		*kernel_queues;
16148c2ecf20Sopenharmony_ci	struct list_head		hw_queues_mirror_list;
16158c2ecf20Sopenharmony_ci	spinlock_t			hw_queues_mirror_lock;
16168c2ecf20Sopenharmony_ci	struct hl_cb_mgr		kernel_cb_mgr;
16178c2ecf20Sopenharmony_ci	struct hl_eq			event_queue;
16188c2ecf20Sopenharmony_ci	struct dma_pool			*dma_pool;
16198c2ecf20Sopenharmony_ci	void				*cpu_accessible_dma_mem;
16208c2ecf20Sopenharmony_ci	dma_addr_t			cpu_accessible_dma_address;
16218c2ecf20Sopenharmony_ci	struct gen_pool			*cpu_accessible_dma_pool;
16228c2ecf20Sopenharmony_ci	unsigned long			*asid_bitmap;
16238c2ecf20Sopenharmony_ci	struct mutex			asid_mutex;
16248c2ecf20Sopenharmony_ci	struct mutex			send_cpu_message_lock;
16258c2ecf20Sopenharmony_ci	struct mutex			debug_lock;
16268c2ecf20Sopenharmony_ci	struct asic_fixed_properties	asic_prop;
16278c2ecf20Sopenharmony_ci	const struct hl_asic_funcs	*asic_funcs;
16288c2ecf20Sopenharmony_ci	void				*asic_specific;
16298c2ecf20Sopenharmony_ci	struct hl_vm			vm;
16308c2ecf20Sopenharmony_ci	struct mutex			mmu_cache_lock;
16318c2ecf20Sopenharmony_ci	struct device			*hwmon_dev;
16328c2ecf20Sopenharmony_ci	enum hl_pm_mng_profile		pm_mng_profile;
16338c2ecf20Sopenharmony_ci	struct hwmon_chip_info		*hl_chip_info;
16348c2ecf20Sopenharmony_ci
16358c2ecf20Sopenharmony_ci	struct hl_dbg_device_entry	hl_debugfs;
16368c2ecf20Sopenharmony_ci
16378c2ecf20Sopenharmony_ci	struct list_head		cb_pool;
16388c2ecf20Sopenharmony_ci	spinlock_t			cb_pool_lock;
16398c2ecf20Sopenharmony_ci
16408c2ecf20Sopenharmony_ci	void				*internal_cb_pool_virt_addr;
16418c2ecf20Sopenharmony_ci	dma_addr_t			internal_cb_pool_dma_addr;
16428c2ecf20Sopenharmony_ci	struct gen_pool			*internal_cb_pool;
16438c2ecf20Sopenharmony_ci	u64				internal_cb_va_base;
16448c2ecf20Sopenharmony_ci
16458c2ecf20Sopenharmony_ci	struct list_head		fpriv_list;
16468c2ecf20Sopenharmony_ci	struct mutex			fpriv_list_lock;
16478c2ecf20Sopenharmony_ci
16488c2ecf20Sopenharmony_ci	struct hl_ctx			*compute_ctx;
16498c2ecf20Sopenharmony_ci
16508c2ecf20Sopenharmony_ci	struct hl_device_idle_busy_ts	*idle_busy_ts_arr;
16518c2ecf20Sopenharmony_ci
16528c2ecf20Sopenharmony_ci	struct hl_cs_counters		aggregated_cs_counters;
16538c2ecf20Sopenharmony_ci
16548c2ecf20Sopenharmony_ci	struct hl_mmu_priv		mmu_priv;
16558c2ecf20Sopenharmony_ci	struct hl_mmu_funcs		mmu_func;
16568c2ecf20Sopenharmony_ci
16578c2ecf20Sopenharmony_ci	atomic64_t			dram_used_mem;
16588c2ecf20Sopenharmony_ci	u64				timeout_jiffies;
16598c2ecf20Sopenharmony_ci	u64				max_power;
16608c2ecf20Sopenharmony_ci	u64				clock_gating_mask;
16618c2ecf20Sopenharmony_ci	atomic_t			in_reset;
16628c2ecf20Sopenharmony_ci	enum hl_pll_frequency		curr_pll_profile;
16638c2ecf20Sopenharmony_ci	enum cpucp_card_types		card_type;
16648c2ecf20Sopenharmony_ci	int				cs_active_cnt;
16658c2ecf20Sopenharmony_ci	u32				major;
16668c2ecf20Sopenharmony_ci	u32				high_pll;
16678c2ecf20Sopenharmony_ci	u32				soft_reset_cnt;
16688c2ecf20Sopenharmony_ci	u32				hard_reset_cnt;
16698c2ecf20Sopenharmony_ci	u32				idle_busy_ts_idx;
16708c2ecf20Sopenharmony_ci	u32				clk_throttling_reason;
16718c2ecf20Sopenharmony_ci	u16				id;
16728c2ecf20Sopenharmony_ci	u16				id_control;
16738c2ecf20Sopenharmony_ci	u16				cpu_pci_msb_addr;
16748c2ecf20Sopenharmony_ci	u8				disabled;
16758c2ecf20Sopenharmony_ci	u8				late_init_done;
16768c2ecf20Sopenharmony_ci	u8				hwmon_initialized;
16778c2ecf20Sopenharmony_ci	u8				hard_reset_pending;
16788c2ecf20Sopenharmony_ci	u8				heartbeat;
16798c2ecf20Sopenharmony_ci	u8				reset_on_lockup;
16808c2ecf20Sopenharmony_ci	u8				dram_supports_virtual_memory;
16818c2ecf20Sopenharmony_ci	u8				dram_default_page_mapping;
16828c2ecf20Sopenharmony_ci	u8				pmmu_huge_range;
16838c2ecf20Sopenharmony_ci	u8				init_done;
16848c2ecf20Sopenharmony_ci	u8				device_cpu_disabled;
16858c2ecf20Sopenharmony_ci	u8				dma_mask;
16868c2ecf20Sopenharmony_ci	u8				in_debug;
16878c2ecf20Sopenharmony_ci	u8				power9_64bit_dma_enable;
16888c2ecf20Sopenharmony_ci	u8				cdev_sysfs_created;
16898c2ecf20Sopenharmony_ci	u8				stop_on_err;
16908c2ecf20Sopenharmony_ci	u8				supports_sync_stream;
16918c2ecf20Sopenharmony_ci	u8				sync_stream_queue_idx;
16928c2ecf20Sopenharmony_ci	u8				supports_coresight;
16938c2ecf20Sopenharmony_ci	u8				supports_soft_reset;
16948c2ecf20Sopenharmony_ci	u8				supports_cb_mapping;
16958c2ecf20Sopenharmony_ci
16968c2ecf20Sopenharmony_ci	/* Parameters for bring-up */
16978c2ecf20Sopenharmony_ci	u8				mmu_enable;
16988c2ecf20Sopenharmony_ci	u8				mmu_huge_page_opt;
16998c2ecf20Sopenharmony_ci	u8				cpu_enable;
17008c2ecf20Sopenharmony_ci	u8				reset_pcilink;
17018c2ecf20Sopenharmony_ci	u8				cpu_queues_enable;
17028c2ecf20Sopenharmony_ci	u8				fw_loading;
17038c2ecf20Sopenharmony_ci	u8				pldm;
17048c2ecf20Sopenharmony_ci	u8				axi_drain;
17058c2ecf20Sopenharmony_ci	u8				sram_scrambler_enable;
17068c2ecf20Sopenharmony_ci	u8				dram_scrambler_enable;
17078c2ecf20Sopenharmony_ci	u8				hard_reset_on_fw_events;
17088c2ecf20Sopenharmony_ci	u8				bmc_enable;
17098c2ecf20Sopenharmony_ci	u8				rl_enable;
17108c2ecf20Sopenharmony_ci};
17118c2ecf20Sopenharmony_ci
17128c2ecf20Sopenharmony_ci
17138c2ecf20Sopenharmony_ci/*
17148c2ecf20Sopenharmony_ci * IOCTLs
17158c2ecf20Sopenharmony_ci */
17168c2ecf20Sopenharmony_ci
17178c2ecf20Sopenharmony_ci/**
17188c2ecf20Sopenharmony_ci * typedef hl_ioctl_t - typedef for ioctl function in the driver
17198c2ecf20Sopenharmony_ci * @hpriv: pointer to the FD's private data, which contains state of
17208c2ecf20Sopenharmony_ci *		user process
17218c2ecf20Sopenharmony_ci * @data: pointer to the input/output arguments structure of the IOCTL
17228c2ecf20Sopenharmony_ci *
17238c2ecf20Sopenharmony_ci * Return: 0 for success, negative value for error
17248c2ecf20Sopenharmony_ci */
17258c2ecf20Sopenharmony_citypedef int hl_ioctl_t(struct hl_fpriv *hpriv, void *data);
17268c2ecf20Sopenharmony_ci
17278c2ecf20Sopenharmony_ci/**
17288c2ecf20Sopenharmony_ci * struct hl_ioctl_desc - describes an IOCTL entry of the driver.
17298c2ecf20Sopenharmony_ci * @cmd: the IOCTL code as created by the kernel macros.
17308c2ecf20Sopenharmony_ci * @func: pointer to the driver's function that should be called for this IOCTL.
17318c2ecf20Sopenharmony_ci */
17328c2ecf20Sopenharmony_cistruct hl_ioctl_desc {
17338c2ecf20Sopenharmony_ci	unsigned int cmd;
17348c2ecf20Sopenharmony_ci	hl_ioctl_t *func;
17358c2ecf20Sopenharmony_ci};
17368c2ecf20Sopenharmony_ci
17378c2ecf20Sopenharmony_ci
17388c2ecf20Sopenharmony_ci/*
17398c2ecf20Sopenharmony_ci * Kernel module functions that can be accessed by entire module
17408c2ecf20Sopenharmony_ci */
17418c2ecf20Sopenharmony_ci
17428c2ecf20Sopenharmony_ci/**
17438c2ecf20Sopenharmony_ci * hl_mem_area_inside_range() - Checks whether address+size are inside a range.
17448c2ecf20Sopenharmony_ci * @address: The start address of the area we want to validate.
17458c2ecf20Sopenharmony_ci * @size: The size in bytes of the area we want to validate.
17468c2ecf20Sopenharmony_ci * @range_start_address: The start address of the valid range.
17478c2ecf20Sopenharmony_ci * @range_end_address: The end address of the valid range.
17488c2ecf20Sopenharmony_ci *
17498c2ecf20Sopenharmony_ci * Return: true if the area is inside the valid range, false otherwise.
17508c2ecf20Sopenharmony_ci */
17518c2ecf20Sopenharmony_cistatic inline bool hl_mem_area_inside_range(u64 address, u64 size,
17528c2ecf20Sopenharmony_ci				u64 range_start_address, u64 range_end_address)
17538c2ecf20Sopenharmony_ci{
17548c2ecf20Sopenharmony_ci	u64 end_address = address + size;
17558c2ecf20Sopenharmony_ci
17568c2ecf20Sopenharmony_ci	if ((address >= range_start_address) &&
17578c2ecf20Sopenharmony_ci			(end_address <= range_end_address) &&
17588c2ecf20Sopenharmony_ci			(end_address > address))
17598c2ecf20Sopenharmony_ci		return true;
17608c2ecf20Sopenharmony_ci
17618c2ecf20Sopenharmony_ci	return false;
17628c2ecf20Sopenharmony_ci}
17638c2ecf20Sopenharmony_ci
17648c2ecf20Sopenharmony_ci/**
17658c2ecf20Sopenharmony_ci * hl_mem_area_crosses_range() - Checks whether address+size crossing a range.
17668c2ecf20Sopenharmony_ci * @address: The start address of the area we want to validate.
17678c2ecf20Sopenharmony_ci * @size: The size in bytes of the area we want to validate.
17688c2ecf20Sopenharmony_ci * @range_start_address: The start address of the valid range.
17698c2ecf20Sopenharmony_ci * @range_end_address: The end address of the valid range.
17708c2ecf20Sopenharmony_ci *
17718c2ecf20Sopenharmony_ci * Return: true if the area overlaps part or all of the valid range,
17728c2ecf20Sopenharmony_ci *		false otherwise.
17738c2ecf20Sopenharmony_ci */
17748c2ecf20Sopenharmony_cistatic inline bool hl_mem_area_crosses_range(u64 address, u32 size,
17758c2ecf20Sopenharmony_ci				u64 range_start_address, u64 range_end_address)
17768c2ecf20Sopenharmony_ci{
17778c2ecf20Sopenharmony_ci	u64 end_address = address + size;
17788c2ecf20Sopenharmony_ci
17798c2ecf20Sopenharmony_ci	if ((address >= range_start_address) &&
17808c2ecf20Sopenharmony_ci			(address < range_end_address))
17818c2ecf20Sopenharmony_ci		return true;
17828c2ecf20Sopenharmony_ci
17838c2ecf20Sopenharmony_ci	if ((end_address >= range_start_address) &&
17848c2ecf20Sopenharmony_ci			(end_address < range_end_address))
17858c2ecf20Sopenharmony_ci		return true;
17868c2ecf20Sopenharmony_ci
17878c2ecf20Sopenharmony_ci	if ((address < range_start_address) &&
17888c2ecf20Sopenharmony_ci			(end_address >= range_end_address))
17898c2ecf20Sopenharmony_ci		return true;
17908c2ecf20Sopenharmony_ci
17918c2ecf20Sopenharmony_ci	return false;
17928c2ecf20Sopenharmony_ci}
17938c2ecf20Sopenharmony_ci
17948c2ecf20Sopenharmony_ciint hl_device_open(struct inode *inode, struct file *filp);
17958c2ecf20Sopenharmony_ciint hl_device_open_ctrl(struct inode *inode, struct file *filp);
17968c2ecf20Sopenharmony_cibool hl_device_disabled_or_in_reset(struct hl_device *hdev);
17978c2ecf20Sopenharmony_cienum hl_device_status hl_device_status(struct hl_device *hdev);
17988c2ecf20Sopenharmony_ciint hl_device_set_debug_mode(struct hl_device *hdev, bool enable);
17998c2ecf20Sopenharmony_ciint create_hdev(struct hl_device **dev, struct pci_dev *pdev,
18008c2ecf20Sopenharmony_ci		enum hl_asic_type asic_type, int minor);
18018c2ecf20Sopenharmony_civoid destroy_hdev(struct hl_device *hdev);
18028c2ecf20Sopenharmony_ciint hl_hw_queues_create(struct hl_device *hdev);
18038c2ecf20Sopenharmony_civoid hl_hw_queues_destroy(struct hl_device *hdev);
18048c2ecf20Sopenharmony_ciint hl_hw_queue_send_cb_no_cmpl(struct hl_device *hdev, u32 hw_queue_id,
18058c2ecf20Sopenharmony_ci				u32 cb_size, u64 cb_ptr);
18068c2ecf20Sopenharmony_ciint hl_hw_queue_schedule_cs(struct hl_cs *cs);
18078c2ecf20Sopenharmony_ciu32 hl_hw_queue_add_ptr(u32 ptr, u16 val);
18088c2ecf20Sopenharmony_civoid hl_hw_queue_inc_ci_kernel(struct hl_device *hdev, u32 hw_queue_id);
18098c2ecf20Sopenharmony_civoid hl_int_hw_queue_update_ci(struct hl_cs *cs);
18108c2ecf20Sopenharmony_civoid hl_hw_queue_reset(struct hl_device *hdev, bool hard_reset);
18118c2ecf20Sopenharmony_ci
18128c2ecf20Sopenharmony_ci#define hl_queue_inc_ptr(p)		hl_hw_queue_add_ptr(p, 1)
18138c2ecf20Sopenharmony_ci#define hl_pi_2_offset(pi)		((pi) & (HL_QUEUE_LENGTH - 1))
18148c2ecf20Sopenharmony_ci
18158c2ecf20Sopenharmony_ciint hl_cq_init(struct hl_device *hdev, struct hl_cq *q, u32 hw_queue_id);
18168c2ecf20Sopenharmony_civoid hl_cq_fini(struct hl_device *hdev, struct hl_cq *q);
18178c2ecf20Sopenharmony_ciint hl_eq_init(struct hl_device *hdev, struct hl_eq *q);
18188c2ecf20Sopenharmony_civoid hl_eq_fini(struct hl_device *hdev, struct hl_eq *q);
18198c2ecf20Sopenharmony_civoid hl_cq_reset(struct hl_device *hdev, struct hl_cq *q);
18208c2ecf20Sopenharmony_civoid hl_eq_reset(struct hl_device *hdev, struct hl_eq *q);
18218c2ecf20Sopenharmony_ciirqreturn_t hl_irq_handler_cq(int irq, void *arg);
18228c2ecf20Sopenharmony_ciirqreturn_t hl_irq_handler_eq(int irq, void *arg);
18238c2ecf20Sopenharmony_ciu32 hl_cq_inc_ptr(u32 ptr);
18248c2ecf20Sopenharmony_ci
18258c2ecf20Sopenharmony_ciint hl_asid_init(struct hl_device *hdev);
18268c2ecf20Sopenharmony_civoid hl_asid_fini(struct hl_device *hdev);
18278c2ecf20Sopenharmony_ciunsigned long hl_asid_alloc(struct hl_device *hdev);
18288c2ecf20Sopenharmony_civoid hl_asid_free(struct hl_device *hdev, unsigned long asid);
18298c2ecf20Sopenharmony_ci
18308c2ecf20Sopenharmony_ciint hl_ctx_create(struct hl_device *hdev, struct hl_fpriv *hpriv);
18318c2ecf20Sopenharmony_civoid hl_ctx_free(struct hl_device *hdev, struct hl_ctx *ctx);
18328c2ecf20Sopenharmony_ciint hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx);
18338c2ecf20Sopenharmony_civoid hl_ctx_do_release(struct kref *ref);
18348c2ecf20Sopenharmony_civoid hl_ctx_get(struct hl_device *hdev,	struct hl_ctx *ctx);
18358c2ecf20Sopenharmony_ciint hl_ctx_put(struct hl_ctx *ctx);
18368c2ecf20Sopenharmony_cistruct hl_fence *hl_ctx_get_fence(struct hl_ctx *ctx, u64 seq);
18378c2ecf20Sopenharmony_civoid hl_ctx_mgr_init(struct hl_ctx_mgr *mgr);
18388c2ecf20Sopenharmony_civoid hl_ctx_mgr_fini(struct hl_device *hdev, struct hl_ctx_mgr *mgr);
18398c2ecf20Sopenharmony_ci
18408c2ecf20Sopenharmony_ciint hl_device_init(struct hl_device *hdev, struct class *hclass);
18418c2ecf20Sopenharmony_civoid hl_device_fini(struct hl_device *hdev);
18428c2ecf20Sopenharmony_ciint hl_device_suspend(struct hl_device *hdev);
18438c2ecf20Sopenharmony_ciint hl_device_resume(struct hl_device *hdev);
18448c2ecf20Sopenharmony_ciint hl_device_reset(struct hl_device *hdev, bool hard_reset,
18458c2ecf20Sopenharmony_ci			bool from_hard_reset_thread);
18468c2ecf20Sopenharmony_civoid hl_hpriv_get(struct hl_fpriv *hpriv);
18478c2ecf20Sopenharmony_civoid hl_hpriv_put(struct hl_fpriv *hpriv);
18488c2ecf20Sopenharmony_ciint hl_device_set_frequency(struct hl_device *hdev, enum hl_pll_frequency freq);
18498c2ecf20Sopenharmony_ciuint32_t hl_device_utilization(struct hl_device *hdev, uint32_t period_ms);
18508c2ecf20Sopenharmony_ci
18518c2ecf20Sopenharmony_ciint hl_build_hwmon_channel_info(struct hl_device *hdev,
18528c2ecf20Sopenharmony_ci		struct cpucp_sensor *sensors_arr);
18538c2ecf20Sopenharmony_ci
18548c2ecf20Sopenharmony_ciint hl_sysfs_init(struct hl_device *hdev);
18558c2ecf20Sopenharmony_civoid hl_sysfs_fini(struct hl_device *hdev);
18568c2ecf20Sopenharmony_ci
18578c2ecf20Sopenharmony_ciint hl_hwmon_init(struct hl_device *hdev);
18588c2ecf20Sopenharmony_civoid hl_hwmon_fini(struct hl_device *hdev);
18598c2ecf20Sopenharmony_ci
18608c2ecf20Sopenharmony_ciint hl_cb_create(struct hl_device *hdev, struct hl_cb_mgr *mgr,
18618c2ecf20Sopenharmony_ci			struct hl_ctx *ctx, u32 cb_size, bool internal_cb,
18628c2ecf20Sopenharmony_ci			bool map_cb, u64 *handle);
18638c2ecf20Sopenharmony_ciint hl_cb_destroy(struct hl_device *hdev, struct hl_cb_mgr *mgr, u64 cb_handle);
18648c2ecf20Sopenharmony_ciint hl_cb_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma);
18658c2ecf20Sopenharmony_cistruct hl_cb *hl_cb_get(struct hl_device *hdev,	struct hl_cb_mgr *mgr,
18668c2ecf20Sopenharmony_ci			u32 handle);
18678c2ecf20Sopenharmony_civoid hl_cb_put(struct hl_cb *cb);
18688c2ecf20Sopenharmony_civoid hl_cb_mgr_init(struct hl_cb_mgr *mgr);
18698c2ecf20Sopenharmony_civoid hl_cb_mgr_fini(struct hl_device *hdev, struct hl_cb_mgr *mgr);
18708c2ecf20Sopenharmony_cistruct hl_cb *hl_cb_kernel_create(struct hl_device *hdev, u32 cb_size,
18718c2ecf20Sopenharmony_ci					bool internal_cb);
18728c2ecf20Sopenharmony_ciint hl_cb_pool_init(struct hl_device *hdev);
18738c2ecf20Sopenharmony_ciint hl_cb_pool_fini(struct hl_device *hdev);
18748c2ecf20Sopenharmony_ciint hl_cb_va_pool_init(struct hl_ctx *ctx);
18758c2ecf20Sopenharmony_civoid hl_cb_va_pool_fini(struct hl_ctx *ctx);
18768c2ecf20Sopenharmony_ci
18778c2ecf20Sopenharmony_civoid hl_cs_rollback_all(struct hl_device *hdev);
18788c2ecf20Sopenharmony_cistruct hl_cs_job *hl_cs_allocate_job(struct hl_device *hdev,
18798c2ecf20Sopenharmony_ci		enum hl_queue_type queue_type, bool is_kernel_allocated_cb);
18808c2ecf20Sopenharmony_civoid hl_sob_reset_error(struct kref *ref);
18818c2ecf20Sopenharmony_civoid hl_fence_put(struct hl_fence *fence);
18828c2ecf20Sopenharmony_civoid hl_fence_get(struct hl_fence *fence);
18838c2ecf20Sopenharmony_ci
18848c2ecf20Sopenharmony_civoid goya_set_asic_funcs(struct hl_device *hdev);
18858c2ecf20Sopenharmony_civoid gaudi_set_asic_funcs(struct hl_device *hdev);
18868c2ecf20Sopenharmony_ci
18878c2ecf20Sopenharmony_ciint hl_vm_ctx_init(struct hl_ctx *ctx);
18888c2ecf20Sopenharmony_civoid hl_vm_ctx_fini(struct hl_ctx *ctx);
18898c2ecf20Sopenharmony_ci
18908c2ecf20Sopenharmony_ciint hl_vm_init(struct hl_device *hdev);
18918c2ecf20Sopenharmony_civoid hl_vm_fini(struct hl_device *hdev);
18928c2ecf20Sopenharmony_ci
18938c2ecf20Sopenharmony_ciint hl_pin_host_memory(struct hl_device *hdev, u64 addr, u64 size,
18948c2ecf20Sopenharmony_ci			struct hl_userptr *userptr);
18958c2ecf20Sopenharmony_civoid hl_unpin_host_memory(struct hl_device *hdev, struct hl_userptr *userptr);
18968c2ecf20Sopenharmony_civoid hl_userptr_delete_list(struct hl_device *hdev,
18978c2ecf20Sopenharmony_ci				struct list_head *userptr_list);
18988c2ecf20Sopenharmony_cibool hl_userptr_is_pinned(struct hl_device *hdev, u64 addr, u32 size,
18998c2ecf20Sopenharmony_ci				struct list_head *userptr_list,
19008c2ecf20Sopenharmony_ci				struct hl_userptr **userptr);
19018c2ecf20Sopenharmony_ci
19028c2ecf20Sopenharmony_ciint hl_mmu_init(struct hl_device *hdev);
19038c2ecf20Sopenharmony_civoid hl_mmu_fini(struct hl_device *hdev);
19048c2ecf20Sopenharmony_ciint hl_mmu_ctx_init(struct hl_ctx *ctx);
19058c2ecf20Sopenharmony_civoid hl_mmu_ctx_fini(struct hl_ctx *ctx);
19068c2ecf20Sopenharmony_ciint hl_mmu_map(struct hl_ctx *ctx, u64 virt_addr, u64 phys_addr,
19078c2ecf20Sopenharmony_ci		u32 page_size, bool flush_pte);
19088c2ecf20Sopenharmony_ciint hl_mmu_unmap(struct hl_ctx *ctx, u64 virt_addr, u32 page_size,
19098c2ecf20Sopenharmony_ci		bool flush_pte);
19108c2ecf20Sopenharmony_civoid hl_mmu_swap_out(struct hl_ctx *ctx);
19118c2ecf20Sopenharmony_civoid hl_mmu_swap_in(struct hl_ctx *ctx);
19128c2ecf20Sopenharmony_ciint hl_mmu_if_set_funcs(struct hl_device *hdev);
19138c2ecf20Sopenharmony_civoid hl_mmu_v1_set_funcs(struct hl_device *hdev);
19148c2ecf20Sopenharmony_ci
19158c2ecf20Sopenharmony_ciint hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name,
19168c2ecf20Sopenharmony_ci				void __iomem *dst);
19178c2ecf20Sopenharmony_ciint hl_fw_send_pci_access_msg(struct hl_device *hdev, u32 opcode);
19188c2ecf20Sopenharmony_ciint hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg,
19198c2ecf20Sopenharmony_ci				u16 len, u32 timeout, long *result);
19208c2ecf20Sopenharmony_ciint hl_fw_unmask_irq(struct hl_device *hdev, u16 event_type);
19218c2ecf20Sopenharmony_ciint hl_fw_unmask_irq_arr(struct hl_device *hdev, const u32 *irq_arr,
19228c2ecf20Sopenharmony_ci		size_t irq_arr_size);
19238c2ecf20Sopenharmony_ciint hl_fw_test_cpu_queue(struct hl_device *hdev);
19248c2ecf20Sopenharmony_civoid *hl_fw_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size,
19258c2ecf20Sopenharmony_ci						dma_addr_t *dma_handle);
19268c2ecf20Sopenharmony_civoid hl_fw_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size,
19278c2ecf20Sopenharmony_ci					void *vaddr);
19288c2ecf20Sopenharmony_ciint hl_fw_send_heartbeat(struct hl_device *hdev);
19298c2ecf20Sopenharmony_ciint hl_fw_cpucp_info_get(struct hl_device *hdev);
19308c2ecf20Sopenharmony_ciint hl_fw_get_eeprom_data(struct hl_device *hdev, void *data, size_t max_size);
19318c2ecf20Sopenharmony_ciint hl_fw_cpucp_pci_counters_get(struct hl_device *hdev,
19328c2ecf20Sopenharmony_ci		struct hl_info_pci_counters *counters);
19338c2ecf20Sopenharmony_ciint hl_fw_cpucp_total_energy_get(struct hl_device *hdev,
19348c2ecf20Sopenharmony_ci			u64 *total_energy);
19358c2ecf20Sopenharmony_ciint hl_fw_init_cpu(struct hl_device *hdev, u32 cpu_boot_status_reg,
19368c2ecf20Sopenharmony_ci			u32 msg_to_cpu_reg, u32 cpu_msg_status_reg,
19378c2ecf20Sopenharmony_ci			u32 boot_err0_reg, bool skip_bmc,
19388c2ecf20Sopenharmony_ci			u32 cpu_timeout, u32 boot_fit_timeout);
19398c2ecf20Sopenharmony_ciint hl_fw_read_preboot_ver(struct hl_device *hdev, u32 cpu_boot_status_reg,
19408c2ecf20Sopenharmony_ci				u32 boot_err0_reg, u32 timeout);
19418c2ecf20Sopenharmony_ci
19428c2ecf20Sopenharmony_ciint hl_pci_bars_map(struct hl_device *hdev, const char * const name[3],
19438c2ecf20Sopenharmony_ci			bool is_wc[3]);
19448c2ecf20Sopenharmony_ciint hl_pci_iatu_write(struct hl_device *hdev, u32 addr, u32 data);
19458c2ecf20Sopenharmony_ciint hl_pci_set_inbound_region(struct hl_device *hdev, u8 region,
19468c2ecf20Sopenharmony_ci		struct hl_inbound_pci_region *pci_region);
19478c2ecf20Sopenharmony_ciint hl_pci_set_outbound_region(struct hl_device *hdev,
19488c2ecf20Sopenharmony_ci		struct hl_outbound_pci_region *pci_region);
19498c2ecf20Sopenharmony_ciint hl_pci_init(struct hl_device *hdev, u32 cpu_boot_status_reg,
19508c2ecf20Sopenharmony_ci		u32 boot_err0_reg, u32 preboot_ver_timeout);
19518c2ecf20Sopenharmony_civoid hl_pci_fini(struct hl_device *hdev);
19528c2ecf20Sopenharmony_ci
19538c2ecf20Sopenharmony_cilong hl_get_frequency(struct hl_device *hdev, u32 pll_index, bool curr);
19548c2ecf20Sopenharmony_civoid hl_set_frequency(struct hl_device *hdev, u32 pll_index, u64 freq);
19558c2ecf20Sopenharmony_ciint hl_get_temperature(struct hl_device *hdev,
19568c2ecf20Sopenharmony_ci		       int sensor_index, u32 attr, long *value);
19578c2ecf20Sopenharmony_ciint hl_set_temperature(struct hl_device *hdev,
19588c2ecf20Sopenharmony_ci		       int sensor_index, u32 attr, long value);
19598c2ecf20Sopenharmony_ciint hl_get_voltage(struct hl_device *hdev,
19608c2ecf20Sopenharmony_ci		   int sensor_index, u32 attr, long *value);
19618c2ecf20Sopenharmony_ciint hl_get_current(struct hl_device *hdev,
19628c2ecf20Sopenharmony_ci		   int sensor_index, u32 attr, long *value);
19638c2ecf20Sopenharmony_ciint hl_get_fan_speed(struct hl_device *hdev,
19648c2ecf20Sopenharmony_ci		     int sensor_index, u32 attr, long *value);
19658c2ecf20Sopenharmony_ciint hl_get_pwm_info(struct hl_device *hdev,
19668c2ecf20Sopenharmony_ci		    int sensor_index, u32 attr, long *value);
19678c2ecf20Sopenharmony_civoid hl_set_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr,
19688c2ecf20Sopenharmony_ci			long value);
19698c2ecf20Sopenharmony_ciu64 hl_get_max_power(struct hl_device *hdev);
19708c2ecf20Sopenharmony_civoid hl_set_max_power(struct hl_device *hdev);
19718c2ecf20Sopenharmony_ciint hl_set_voltage(struct hl_device *hdev,
19728c2ecf20Sopenharmony_ci			int sensor_index, u32 attr, long value);
19738c2ecf20Sopenharmony_ciint hl_set_current(struct hl_device *hdev,
19748c2ecf20Sopenharmony_ci			int sensor_index, u32 attr, long value);
19758c2ecf20Sopenharmony_ci
19768c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS
19778c2ecf20Sopenharmony_ci
19788c2ecf20Sopenharmony_civoid hl_debugfs_init(void);
19798c2ecf20Sopenharmony_civoid hl_debugfs_fini(void);
19808c2ecf20Sopenharmony_civoid hl_debugfs_add_device(struct hl_device *hdev);
19818c2ecf20Sopenharmony_civoid hl_debugfs_remove_device(struct hl_device *hdev);
19828c2ecf20Sopenharmony_civoid hl_debugfs_add_file(struct hl_fpriv *hpriv);
19838c2ecf20Sopenharmony_civoid hl_debugfs_remove_file(struct hl_fpriv *hpriv);
19848c2ecf20Sopenharmony_civoid hl_debugfs_add_cb(struct hl_cb *cb);
19858c2ecf20Sopenharmony_civoid hl_debugfs_remove_cb(struct hl_cb *cb);
19868c2ecf20Sopenharmony_civoid hl_debugfs_add_cs(struct hl_cs *cs);
19878c2ecf20Sopenharmony_civoid hl_debugfs_remove_cs(struct hl_cs *cs);
19888c2ecf20Sopenharmony_civoid hl_debugfs_add_job(struct hl_device *hdev, struct hl_cs_job *job);
19898c2ecf20Sopenharmony_civoid hl_debugfs_remove_job(struct hl_device *hdev, struct hl_cs_job *job);
19908c2ecf20Sopenharmony_civoid hl_debugfs_add_userptr(struct hl_device *hdev, struct hl_userptr *userptr);
19918c2ecf20Sopenharmony_civoid hl_debugfs_remove_userptr(struct hl_device *hdev,
19928c2ecf20Sopenharmony_ci				struct hl_userptr *userptr);
19938c2ecf20Sopenharmony_civoid hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx);
19948c2ecf20Sopenharmony_civoid hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx);
19958c2ecf20Sopenharmony_ci
19968c2ecf20Sopenharmony_ci#else
19978c2ecf20Sopenharmony_ci
19988c2ecf20Sopenharmony_cistatic inline void __init hl_debugfs_init(void)
19998c2ecf20Sopenharmony_ci{
20008c2ecf20Sopenharmony_ci}
20018c2ecf20Sopenharmony_ci
20028c2ecf20Sopenharmony_cistatic inline void hl_debugfs_fini(void)
20038c2ecf20Sopenharmony_ci{
20048c2ecf20Sopenharmony_ci}
20058c2ecf20Sopenharmony_ci
20068c2ecf20Sopenharmony_cistatic inline void hl_debugfs_add_device(struct hl_device *hdev)
20078c2ecf20Sopenharmony_ci{
20088c2ecf20Sopenharmony_ci}
20098c2ecf20Sopenharmony_ci
20108c2ecf20Sopenharmony_cistatic inline void hl_debugfs_remove_device(struct hl_device *hdev)
20118c2ecf20Sopenharmony_ci{
20128c2ecf20Sopenharmony_ci}
20138c2ecf20Sopenharmony_ci
20148c2ecf20Sopenharmony_cistatic inline void hl_debugfs_add_file(struct hl_fpriv *hpriv)
20158c2ecf20Sopenharmony_ci{
20168c2ecf20Sopenharmony_ci}
20178c2ecf20Sopenharmony_ci
20188c2ecf20Sopenharmony_cistatic inline void hl_debugfs_remove_file(struct hl_fpriv *hpriv)
20198c2ecf20Sopenharmony_ci{
20208c2ecf20Sopenharmony_ci}
20218c2ecf20Sopenharmony_ci
20228c2ecf20Sopenharmony_cistatic inline void hl_debugfs_add_cb(struct hl_cb *cb)
20238c2ecf20Sopenharmony_ci{
20248c2ecf20Sopenharmony_ci}
20258c2ecf20Sopenharmony_ci
20268c2ecf20Sopenharmony_cistatic inline void hl_debugfs_remove_cb(struct hl_cb *cb)
20278c2ecf20Sopenharmony_ci{
20288c2ecf20Sopenharmony_ci}
20298c2ecf20Sopenharmony_ci
20308c2ecf20Sopenharmony_cistatic inline void hl_debugfs_add_cs(struct hl_cs *cs)
20318c2ecf20Sopenharmony_ci{
20328c2ecf20Sopenharmony_ci}
20338c2ecf20Sopenharmony_ci
20348c2ecf20Sopenharmony_cistatic inline void hl_debugfs_remove_cs(struct hl_cs *cs)
20358c2ecf20Sopenharmony_ci{
20368c2ecf20Sopenharmony_ci}
20378c2ecf20Sopenharmony_ci
20388c2ecf20Sopenharmony_cistatic inline void hl_debugfs_add_job(struct hl_device *hdev,
20398c2ecf20Sopenharmony_ci					struct hl_cs_job *job)
20408c2ecf20Sopenharmony_ci{
20418c2ecf20Sopenharmony_ci}
20428c2ecf20Sopenharmony_ci
20438c2ecf20Sopenharmony_cistatic inline void hl_debugfs_remove_job(struct hl_device *hdev,
20448c2ecf20Sopenharmony_ci					struct hl_cs_job *job)
20458c2ecf20Sopenharmony_ci{
20468c2ecf20Sopenharmony_ci}
20478c2ecf20Sopenharmony_ci
20488c2ecf20Sopenharmony_cistatic inline void hl_debugfs_add_userptr(struct hl_device *hdev,
20498c2ecf20Sopenharmony_ci					struct hl_userptr *userptr)
20508c2ecf20Sopenharmony_ci{
20518c2ecf20Sopenharmony_ci}
20528c2ecf20Sopenharmony_ci
20538c2ecf20Sopenharmony_cistatic inline void hl_debugfs_remove_userptr(struct hl_device *hdev,
20548c2ecf20Sopenharmony_ci					struct hl_userptr *userptr)
20558c2ecf20Sopenharmony_ci{
20568c2ecf20Sopenharmony_ci}
20578c2ecf20Sopenharmony_ci
20588c2ecf20Sopenharmony_cistatic inline void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev,
20598c2ecf20Sopenharmony_ci					struct hl_ctx *ctx)
20608c2ecf20Sopenharmony_ci{
20618c2ecf20Sopenharmony_ci}
20628c2ecf20Sopenharmony_ci
20638c2ecf20Sopenharmony_cistatic inline void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev,
20648c2ecf20Sopenharmony_ci					struct hl_ctx *ctx)
20658c2ecf20Sopenharmony_ci{
20668c2ecf20Sopenharmony_ci}
20678c2ecf20Sopenharmony_ci
20688c2ecf20Sopenharmony_ci#endif
20698c2ecf20Sopenharmony_ci
20708c2ecf20Sopenharmony_ci/* IOCTLs */
20718c2ecf20Sopenharmony_cilong hl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
20728c2ecf20Sopenharmony_cilong hl_ioctl_control(struct file *filep, unsigned int cmd, unsigned long arg);
20738c2ecf20Sopenharmony_ciint hl_cb_ioctl(struct hl_fpriv *hpriv, void *data);
20748c2ecf20Sopenharmony_ciint hl_cs_ioctl(struct hl_fpriv *hpriv, void *data);
20758c2ecf20Sopenharmony_ciint hl_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data);
20768c2ecf20Sopenharmony_ciint hl_mem_ioctl(struct hl_fpriv *hpriv, void *data);
20778c2ecf20Sopenharmony_ci
20788c2ecf20Sopenharmony_ci#endif /* HABANALABSP_H_ */
2079