162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci *
362306a36Sopenharmony_ci * Copyright 2016-2022 HabanaLabs, Ltd.
462306a36Sopenharmony_ci * All Rights Reserved.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef HABANALABSP_H_
962306a36Sopenharmony_ci#define HABANALABSP_H_
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include "../include/common/cpucp_if.h"
1262306a36Sopenharmony_ci#include "../include/common/qman_if.h"
1362306a36Sopenharmony_ci#include "../include/hw_ip/mmu/mmu_general.h"
1462306a36Sopenharmony_ci#include <uapi/drm/habanalabs_accel.h>
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#include <linux/cdev.h>
1762306a36Sopenharmony_ci#include <linux/iopoll.h>
1862306a36Sopenharmony_ci#include <linux/irqreturn.h>
1962306a36Sopenharmony_ci#include <linux/dma-direction.h>
2062306a36Sopenharmony_ci#include <linux/scatterlist.h>
2162306a36Sopenharmony_ci#include <linux/hashtable.h>
2262306a36Sopenharmony_ci#include <linux/debugfs.h>
2362306a36Sopenharmony_ci#include <linux/rwsem.h>
2462306a36Sopenharmony_ci#include <linux/eventfd.h>
2562306a36Sopenharmony_ci#include <linux/bitfield.h>
2662306a36Sopenharmony_ci#include <linux/genalloc.h>
2762306a36Sopenharmony_ci#include <linux/sched/signal.h>
2862306a36Sopenharmony_ci#include <linux/io-64-nonatomic-lo-hi.h>
2962306a36Sopenharmony_ci#include <linux/coresight.h>
3062306a36Sopenharmony_ci#include <linux/dma-buf.h>
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#include "security.h"
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci#define HL_NAME				"habanalabs"
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_cistruct hl_device;
3762306a36Sopenharmony_cistruct hl_fpriv;
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci#define PCI_VENDOR_ID_HABANALABS	0x1da3
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci/* Use upper bits of mmap offset to store habana driver specific information.
4262306a36Sopenharmony_ci * bits[63:59] - Encode mmap type
4362306a36Sopenharmony_ci * bits[45:0]  - mmap offset value
4462306a36Sopenharmony_ci *
4562306a36Sopenharmony_ci * NOTE: struct vm_area_struct.vm_pgoff uses offset in pages. Hence, these
4662306a36Sopenharmony_ci *  defines are w.r.t to PAGE_SIZE
4762306a36Sopenharmony_ci */
4862306a36Sopenharmony_ci#define HL_MMAP_TYPE_SHIFT		(59 - PAGE_SHIFT)
4962306a36Sopenharmony_ci#define HL_MMAP_TYPE_MASK		(0x1full << HL_MMAP_TYPE_SHIFT)
5062306a36Sopenharmony_ci#define HL_MMAP_TYPE_TS_BUFF		(0x10ull << HL_MMAP_TYPE_SHIFT)
5162306a36Sopenharmony_ci#define HL_MMAP_TYPE_BLOCK		(0x4ull << HL_MMAP_TYPE_SHIFT)
5262306a36Sopenharmony_ci#define HL_MMAP_TYPE_CB			(0x2ull << HL_MMAP_TYPE_SHIFT)
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci#define HL_MMAP_OFFSET_VALUE_MASK	(0x1FFFFFFFFFFFull >> PAGE_SHIFT)
5562306a36Sopenharmony_ci#define HL_MMAP_OFFSET_VALUE_GET(off)	(off & HL_MMAP_OFFSET_VALUE_MASK)
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci#define HL_PENDING_RESET_PER_SEC		10
5862306a36Sopenharmony_ci#define HL_PENDING_RESET_MAX_TRIALS		60 /* 10 minutes */
5962306a36Sopenharmony_ci#define HL_PENDING_RESET_LONG_SEC		60
6062306a36Sopenharmony_ci/*
6162306a36Sopenharmony_ci * In device fini, wait 10 minutes for user processes to be terminated after we kill them.
6262306a36Sopenharmony_ci * This is needed to prevent situation of clearing resources while user processes are still alive.
6362306a36Sopenharmony_ci */
6462306a36Sopenharmony_ci#define HL_WAIT_PROCESS_KILL_ON_DEVICE_FINI	600
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci#define HL_HARD_RESET_MAX_TIMEOUT	120
6762306a36Sopenharmony_ci#define HL_PLDM_HARD_RESET_MAX_TIMEOUT	(HL_HARD_RESET_MAX_TIMEOUT * 3)
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci#define HL_DEVICE_TIMEOUT_USEC		1000000 /* 1 s */
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci#define HL_HEARTBEAT_PER_USEC		5000000 /* 5 s */
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci#define HL_PLL_LOW_JOB_FREQ_USEC	5000000 /* 5 s */
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci#define HL_CPUCP_INFO_TIMEOUT_USEC	10000000 /* 10s */
7662306a36Sopenharmony_ci#define HL_CPUCP_EEPROM_TIMEOUT_USEC	10000000 /* 10s */
7762306a36Sopenharmony_ci#define HL_CPUCP_MON_DUMP_TIMEOUT_USEC	10000000 /* 10s */
7862306a36Sopenharmony_ci#define HL_CPUCP_SEC_ATTEST_INFO_TINEOUT_USEC 10000000 /* 10s */
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci#define HL_FW_STATUS_POLL_INTERVAL_USEC		10000 /* 10ms */
8162306a36Sopenharmony_ci#define HL_FW_COMMS_STATUS_PLDM_POLL_INTERVAL_USEC	1000000 /* 1s */
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci#define HL_PCI_ELBI_TIMEOUT_MSEC	10 /* 10ms */
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci#define HL_SIM_MAX_TIMEOUT_US		100000000 /* 100s */
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci#define HL_INVALID_QUEUE		UINT_MAX
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci#define HL_COMMON_USER_CQ_INTERRUPT_ID	0xFFF
9062306a36Sopenharmony_ci#define HL_COMMON_DEC_INTERRUPT_ID	0xFFE
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci#define HL_STATE_DUMP_HIST_LEN		5
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci/* Default value for device reset trigger , an invalid value */
9562306a36Sopenharmony_ci#define HL_RESET_TRIGGER_DEFAULT	0xFF
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci#define OBJ_NAMES_HASH_TABLE_BITS	7 /* 1 << 7 buckets */
9862306a36Sopenharmony_ci#define SYNC_TO_ENGINE_HASH_TABLE_BITS	7 /* 1 << 7 buckets */
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci/* Memory */
10162306a36Sopenharmony_ci#define MEM_HASH_TABLE_BITS		7 /* 1 << 7 buckets */
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci/* MMU */
10462306a36Sopenharmony_ci#define MMU_HASH_TABLE_BITS		7 /* 1 << 7 buckets */
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci/**
10762306a36Sopenharmony_ci * enum hl_mmu_page_table_location - mmu page table location
10862306a36Sopenharmony_ci * @MMU_DR_PGT: page-table is located on device DRAM.
10962306a36Sopenharmony_ci * @MMU_HR_PGT: page-table is located on host memory.
11062306a36Sopenharmony_ci * @MMU_NUM_PGT_LOCATIONS: number of page-table locations currently supported.
11162306a36Sopenharmony_ci */
11262306a36Sopenharmony_cienum hl_mmu_page_table_location {
11362306a36Sopenharmony_ci	MMU_DR_PGT = 0,		/* device-dram-resident MMU PGT */
11462306a36Sopenharmony_ci	MMU_HR_PGT,		/* host resident MMU PGT */
11562306a36Sopenharmony_ci	MMU_NUM_PGT_LOCATIONS	/* num of PGT locations */
11662306a36Sopenharmony_ci};
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci/*
11962306a36Sopenharmony_ci * HL_RSVD_SOBS 'sync stream' reserved sync objects per QMAN stream
12062306a36Sopenharmony_ci * HL_RSVD_MONS 'sync stream' reserved monitors per QMAN stream
12162306a36Sopenharmony_ci */
12262306a36Sopenharmony_ci#define HL_RSVD_SOBS			2
12362306a36Sopenharmony_ci#define HL_RSVD_MONS			1
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci/*
12662306a36Sopenharmony_ci * HL_COLLECTIVE_RSVD_MSTR_MONS 'collective' reserved monitors per QMAN stream
12762306a36Sopenharmony_ci */
12862306a36Sopenharmony_ci#define HL_COLLECTIVE_RSVD_MSTR_MONS	2
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci#define HL_MAX_SOB_VAL			(1 << 15)
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ci#define IS_POWER_OF_2(n)		(n != 0 && ((n & (n - 1)) == 0))
13362306a36Sopenharmony_ci#define IS_MAX_PENDING_CS_VALID(n)	(IS_POWER_OF_2(n) && (n > 1))
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci#define HL_PCI_NUM_BARS			6
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci/* Completion queue entry relates to completed job */
13862306a36Sopenharmony_ci#define HL_COMPLETION_MODE_JOB		0
13962306a36Sopenharmony_ci/* Completion queue entry relates to completed command submission */
14062306a36Sopenharmony_ci#define HL_COMPLETION_MODE_CS		1
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci#define HL_MAX_DCORES			8
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci/* DMA alloc/free wrappers */
14562306a36Sopenharmony_ci#define hl_asic_dma_alloc_coherent(hdev, size, dma_handle, flags) \
14662306a36Sopenharmony_ci	hl_asic_dma_alloc_coherent_caller(hdev, size, dma_handle, flags, __func__)
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci#define hl_asic_dma_pool_zalloc(hdev, size, mem_flags, dma_handle) \
14962306a36Sopenharmony_ci	hl_asic_dma_pool_zalloc_caller(hdev, size, mem_flags, dma_handle, __func__)
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci#define hl_asic_dma_free_coherent(hdev, size, cpu_addr, dma_handle) \
15262306a36Sopenharmony_ci	hl_asic_dma_free_coherent_caller(hdev, size, cpu_addr, dma_handle, __func__)
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci#define hl_asic_dma_pool_free(hdev, vaddr, dma_addr) \
15562306a36Sopenharmony_ci	hl_asic_dma_pool_free_caller(hdev, vaddr, dma_addr, __func__)
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ci/*
15862306a36Sopenharmony_ci * Reset Flags
15962306a36Sopenharmony_ci *
16062306a36Sopenharmony_ci * - HL_DRV_RESET_HARD
16162306a36Sopenharmony_ci *       If set do hard reset to all engines. If not set reset just
16262306a36Sopenharmony_ci *       compute/DMA engines.
16362306a36Sopenharmony_ci *
16462306a36Sopenharmony_ci * - HL_DRV_RESET_FROM_RESET_THR
16562306a36Sopenharmony_ci *       Set if the caller is the hard-reset thread
16662306a36Sopenharmony_ci *
16762306a36Sopenharmony_ci * - HL_DRV_RESET_HEARTBEAT
16862306a36Sopenharmony_ci *       Set if reset is due to heartbeat
16962306a36Sopenharmony_ci *
17062306a36Sopenharmony_ci * - HL_DRV_RESET_TDR
17162306a36Sopenharmony_ci *       Set if reset is due to TDR
17262306a36Sopenharmony_ci *
17362306a36Sopenharmony_ci * - HL_DRV_RESET_DEV_RELEASE
17462306a36Sopenharmony_ci *       Set if reset is due to device release
17562306a36Sopenharmony_ci *
17662306a36Sopenharmony_ci * - HL_DRV_RESET_BYPASS_REQ_TO_FW
17762306a36Sopenharmony_ci *       F/W will perform the reset. No need to ask it to reset the device. This is relevant
17862306a36Sopenharmony_ci *       only when running with secured f/w
17962306a36Sopenharmony_ci *
18062306a36Sopenharmony_ci * - HL_DRV_RESET_FW_FATAL_ERR
18162306a36Sopenharmony_ci *       Set if reset is due to a fatal error from FW
18262306a36Sopenharmony_ci *
18362306a36Sopenharmony_ci * - HL_DRV_RESET_DELAY
18462306a36Sopenharmony_ci *       Set if a delay should be added before the reset
18562306a36Sopenharmony_ci *
18662306a36Sopenharmony_ci * - HL_DRV_RESET_FROM_WD_THR
18762306a36Sopenharmony_ci *       Set if the caller is the device release watchdog thread
18862306a36Sopenharmony_ci */
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci#define HL_DRV_RESET_HARD		(1 << 0)
19162306a36Sopenharmony_ci#define HL_DRV_RESET_FROM_RESET_THR	(1 << 1)
19262306a36Sopenharmony_ci#define HL_DRV_RESET_HEARTBEAT		(1 << 2)
19362306a36Sopenharmony_ci#define HL_DRV_RESET_TDR		(1 << 3)
19462306a36Sopenharmony_ci#define HL_DRV_RESET_DEV_RELEASE	(1 << 4)
19562306a36Sopenharmony_ci#define HL_DRV_RESET_BYPASS_REQ_TO_FW	(1 << 5)
19662306a36Sopenharmony_ci#define HL_DRV_RESET_FW_FATAL_ERR	(1 << 6)
19762306a36Sopenharmony_ci#define HL_DRV_RESET_DELAY		(1 << 7)
19862306a36Sopenharmony_ci#define HL_DRV_RESET_FROM_WD_THR	(1 << 8)
19962306a36Sopenharmony_ci
20062306a36Sopenharmony_ci/*
20162306a36Sopenharmony_ci * Security
20262306a36Sopenharmony_ci */
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_ci#define HL_PB_SHARED		1
20562306a36Sopenharmony_ci#define HL_PB_NA		0
20662306a36Sopenharmony_ci#define HL_PB_SINGLE_INSTANCE	1
20762306a36Sopenharmony_ci#define HL_BLOCK_SIZE		0x1000
20862306a36Sopenharmony_ci#define HL_BLOCK_GLBL_ERR_MASK	0xF40
20962306a36Sopenharmony_ci#define HL_BLOCK_GLBL_ERR_ADDR	0xF44
21062306a36Sopenharmony_ci#define HL_BLOCK_GLBL_ERR_CAUSE	0xF48
21162306a36Sopenharmony_ci#define HL_BLOCK_GLBL_SEC_OFFS	0xF80
21262306a36Sopenharmony_ci#define HL_BLOCK_GLBL_SEC_SIZE	(HL_BLOCK_SIZE - HL_BLOCK_GLBL_SEC_OFFS)
21362306a36Sopenharmony_ci#define HL_BLOCK_GLBL_SEC_LEN	(HL_BLOCK_GLBL_SEC_SIZE / sizeof(u32))
21462306a36Sopenharmony_ci#define UNSET_GLBL_SEC_BIT(array, b) ((array)[((b) / 32)] |= (1 << ((b) % 32)))
21562306a36Sopenharmony_ci
21662306a36Sopenharmony_cienum hl_protection_levels {
21762306a36Sopenharmony_ci	SECURED_LVL,
21862306a36Sopenharmony_ci	PRIVILEGED_LVL,
21962306a36Sopenharmony_ci	NON_SECURED_LVL
22062306a36Sopenharmony_ci};
22162306a36Sopenharmony_ci
22262306a36Sopenharmony_ci/**
22362306a36Sopenharmony_ci * struct iterate_module_ctx - HW module iterator
22462306a36Sopenharmony_ci * @fn: function to apply to each HW module instance
22562306a36Sopenharmony_ci * @data: optional internal data to the function iterator
22662306a36Sopenharmony_ci * @rc: return code for optional use of iterator/iterator-caller
22762306a36Sopenharmony_ci */
22862306a36Sopenharmony_cistruct iterate_module_ctx {
22962306a36Sopenharmony_ci	/*
23062306a36Sopenharmony_ci	 * callback for the HW module iterator
23162306a36Sopenharmony_ci	 * @hdev: pointer to the habanalabs device structure
23262306a36Sopenharmony_ci	 * @block: block (ASIC specific definition can be dcore/hdcore)
23362306a36Sopenharmony_ci	 * @inst: HW module instance within the block
23462306a36Sopenharmony_ci	 * @offset: current HW module instance offset from the 1-st HW module instance
23562306a36Sopenharmony_ci	 *          in the 1-st block
23662306a36Sopenharmony_ci	 * @ctx: the iterator context.
23762306a36Sopenharmony_ci	 */
23862306a36Sopenharmony_ci	void (*fn)(struct hl_device *hdev, int block, int inst, u32 offset,
23962306a36Sopenharmony_ci			struct iterate_module_ctx *ctx);
24062306a36Sopenharmony_ci	void *data;
24162306a36Sopenharmony_ci	int rc;
24262306a36Sopenharmony_ci};
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_cistruct hl_block_glbl_sec {
24562306a36Sopenharmony_ci	u32 sec_array[HL_BLOCK_GLBL_SEC_LEN];
24662306a36Sopenharmony_ci};
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_ci#define HL_MAX_SOBS_PER_MONITOR	8
24962306a36Sopenharmony_ci
25062306a36Sopenharmony_ci/**
25162306a36Sopenharmony_ci * struct hl_gen_wait_properties - properties for generating a wait CB
25262306a36Sopenharmony_ci * @data: command buffer
25362306a36Sopenharmony_ci * @q_idx: queue id is used to extract fence register address
25462306a36Sopenharmony_ci * @size: offset in command buffer
25562306a36Sopenharmony_ci * @sob_base: SOB base to use in this wait CB
25662306a36Sopenharmony_ci * @sob_val: SOB value to wait for
25762306a36Sopenharmony_ci * @mon_id: monitor to use in this wait CB
25862306a36Sopenharmony_ci * @sob_mask: each bit represents a SOB offset from sob_base to be used
25962306a36Sopenharmony_ci */
26062306a36Sopenharmony_cistruct hl_gen_wait_properties {
26162306a36Sopenharmony_ci	void	*data;
26262306a36Sopenharmony_ci	u32	q_idx;
26362306a36Sopenharmony_ci	u32	size;
26462306a36Sopenharmony_ci	u16	sob_base;
26562306a36Sopenharmony_ci	u16	sob_val;
26662306a36Sopenharmony_ci	u16	mon_id;
26762306a36Sopenharmony_ci	u8	sob_mask;
26862306a36Sopenharmony_ci};
26962306a36Sopenharmony_ci
27062306a36Sopenharmony_ci/**
27162306a36Sopenharmony_ci * struct pgt_info - MMU hop page info.
27262306a36Sopenharmony_ci * @node: hash linked-list node for the pgts on host (shadow pgts for device resident MMU and
27362306a36Sopenharmony_ci *        actual pgts for host resident MMU).
27462306a36Sopenharmony_ci * @phys_addr: physical address of the pgt.
27562306a36Sopenharmony_ci * @virt_addr: host virtual address of the pgt (see above device/host resident).
27662306a36Sopenharmony_ci * @shadow_addr: shadow hop in the host for device resident MMU.
27762306a36Sopenharmony_ci * @ctx: pointer to the owner ctx.
27862306a36Sopenharmony_ci * @num_of_ptes: indicates how many ptes are used in the pgt. used only for dynamically
27962306a36Sopenharmony_ci *               allocated HOPs (all HOPs but HOP0)
28062306a36Sopenharmony_ci *
28162306a36Sopenharmony_ci * The MMU page tables hierarchy can be placed either on the device's DRAM (in which case shadow
28262306a36Sopenharmony_ci * pgts will be stored on host memory) or on host memory (in which case no shadow is required).
28362306a36Sopenharmony_ci *
28462306a36Sopenharmony_ci * When a new level (hop) is needed during mapping this structure will be used to describe
28562306a36Sopenharmony_ci * the newly allocated hop as well as to track number of PTEs in it.
28662306a36Sopenharmony_ci * During unmapping, if no valid PTEs remained in the page of a newly allocated hop, it is
28762306a36Sopenharmony_ci * freed with its pgt_info structure.
28862306a36Sopenharmony_ci */
28962306a36Sopenharmony_cistruct pgt_info {
29062306a36Sopenharmony_ci	struct hlist_node	node;
29162306a36Sopenharmony_ci	u64			phys_addr;
29262306a36Sopenharmony_ci	u64			virt_addr;
29362306a36Sopenharmony_ci	u64			shadow_addr;
29462306a36Sopenharmony_ci	struct hl_ctx		*ctx;
29562306a36Sopenharmony_ci	int			num_of_ptes;
29662306a36Sopenharmony_ci};
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_ci/**
29962306a36Sopenharmony_ci * enum hl_pci_match_mode - pci match mode per region
30062306a36Sopenharmony_ci * @PCI_ADDRESS_MATCH_MODE: address match mode
30162306a36Sopenharmony_ci * @PCI_BAR_MATCH_MODE: bar match mode
30262306a36Sopenharmony_ci */
30362306a36Sopenharmony_cienum hl_pci_match_mode {
30462306a36Sopenharmony_ci	PCI_ADDRESS_MATCH_MODE,
30562306a36Sopenharmony_ci	PCI_BAR_MATCH_MODE
30662306a36Sopenharmony_ci};
30762306a36Sopenharmony_ci
30862306a36Sopenharmony_ci/**
30962306a36Sopenharmony_ci * enum hl_fw_component - F/W components to read version through registers.
31062306a36Sopenharmony_ci * @FW_COMP_BOOT_FIT: boot fit.
31162306a36Sopenharmony_ci * @FW_COMP_PREBOOT: preboot.
31262306a36Sopenharmony_ci * @FW_COMP_LINUX: linux.
31362306a36Sopenharmony_ci */
31462306a36Sopenharmony_cienum hl_fw_component {
31562306a36Sopenharmony_ci	FW_COMP_BOOT_FIT,
31662306a36Sopenharmony_ci	FW_COMP_PREBOOT,
31762306a36Sopenharmony_ci	FW_COMP_LINUX,
31862306a36Sopenharmony_ci};
31962306a36Sopenharmony_ci
32062306a36Sopenharmony_ci/**
32162306a36Sopenharmony_ci * enum hl_fw_types - F/W types present in the system
32262306a36Sopenharmony_ci * @FW_TYPE_NONE: no FW component indication
32362306a36Sopenharmony_ci * @FW_TYPE_LINUX: Linux image for device CPU
32462306a36Sopenharmony_ci * @FW_TYPE_BOOT_CPU: Boot image for device CPU
32562306a36Sopenharmony_ci * @FW_TYPE_PREBOOT_CPU: Indicates pre-loaded CPUs are present in the system
32662306a36Sopenharmony_ci *                       (preboot, ppboot etc...)
32762306a36Sopenharmony_ci * @FW_TYPE_ALL_TYPES: Mask for all types
32862306a36Sopenharmony_ci */
32962306a36Sopenharmony_cienum hl_fw_types {
33062306a36Sopenharmony_ci	FW_TYPE_NONE = 0x0,
33162306a36Sopenharmony_ci	FW_TYPE_LINUX = 0x1,
33262306a36Sopenharmony_ci	FW_TYPE_BOOT_CPU = 0x2,
33362306a36Sopenharmony_ci	FW_TYPE_PREBOOT_CPU = 0x4,
33462306a36Sopenharmony_ci	FW_TYPE_ALL_TYPES =
33562306a36Sopenharmony_ci		(FW_TYPE_LINUX | FW_TYPE_BOOT_CPU | FW_TYPE_PREBOOT_CPU)
33662306a36Sopenharmony_ci};
33762306a36Sopenharmony_ci
33862306a36Sopenharmony_ci/**
33962306a36Sopenharmony_ci * enum hl_queue_type - Supported QUEUE types.
34062306a36Sopenharmony_ci * @QUEUE_TYPE_NA: queue is not available.
34162306a36Sopenharmony_ci * @QUEUE_TYPE_EXT: external queue which is a DMA channel that may access the
34262306a36Sopenharmony_ci *                  host.
34362306a36Sopenharmony_ci * @QUEUE_TYPE_INT: internal queue that performs DMA inside the device's
34462306a36Sopenharmony_ci *			memories and/or operates the compute engines.
34562306a36Sopenharmony_ci * @QUEUE_TYPE_CPU: S/W queue for communication with the device's CPU.
34662306a36Sopenharmony_ci * @QUEUE_TYPE_HW: queue of DMA and compute engines jobs, for which completion
34762306a36Sopenharmony_ci *                 notifications are sent by H/W.
34862306a36Sopenharmony_ci */
34962306a36Sopenharmony_cienum hl_queue_type {
35062306a36Sopenharmony_ci	QUEUE_TYPE_NA,
35162306a36Sopenharmony_ci	QUEUE_TYPE_EXT,
35262306a36Sopenharmony_ci	QUEUE_TYPE_INT,
35362306a36Sopenharmony_ci	QUEUE_TYPE_CPU,
35462306a36Sopenharmony_ci	QUEUE_TYPE_HW
35562306a36Sopenharmony_ci};
35662306a36Sopenharmony_ci
35762306a36Sopenharmony_cienum hl_cs_type {
35862306a36Sopenharmony_ci	CS_TYPE_DEFAULT,
35962306a36Sopenharmony_ci	CS_TYPE_SIGNAL,
36062306a36Sopenharmony_ci	CS_TYPE_WAIT,
36162306a36Sopenharmony_ci	CS_TYPE_COLLECTIVE_WAIT,
36262306a36Sopenharmony_ci	CS_RESERVE_SIGNALS,
36362306a36Sopenharmony_ci	CS_UNRESERVE_SIGNALS,
36462306a36Sopenharmony_ci	CS_TYPE_ENGINE_CORE,
36562306a36Sopenharmony_ci	CS_TYPE_ENGINES,
36662306a36Sopenharmony_ci	CS_TYPE_FLUSH_PCI_HBW_WRITES,
36762306a36Sopenharmony_ci};
36862306a36Sopenharmony_ci
36962306a36Sopenharmony_ci/*
37062306a36Sopenharmony_ci * struct hl_inbound_pci_region - inbound region descriptor
37162306a36Sopenharmony_ci * @mode: pci match mode for this region
37262306a36Sopenharmony_ci * @addr: region target address
37362306a36Sopenharmony_ci * @size: region size in bytes
37462306a36Sopenharmony_ci * @offset_in_bar: offset within bar (address match mode)
37562306a36Sopenharmony_ci * @bar: bar id
37662306a36Sopenharmony_ci */
37762306a36Sopenharmony_cistruct hl_inbound_pci_region {
37862306a36Sopenharmony_ci	enum hl_pci_match_mode	mode;
37962306a36Sopenharmony_ci	u64			addr;
38062306a36Sopenharmony_ci	u64			size;
38162306a36Sopenharmony_ci	u64			offset_in_bar;
38262306a36Sopenharmony_ci	u8			bar;
38362306a36Sopenharmony_ci};
38462306a36Sopenharmony_ci
38562306a36Sopenharmony_ci/*
38662306a36Sopenharmony_ci * struct hl_outbound_pci_region - outbound region descriptor
38762306a36Sopenharmony_ci * @addr: region target address
38862306a36Sopenharmony_ci * @size: region size in bytes
38962306a36Sopenharmony_ci */
39062306a36Sopenharmony_cistruct hl_outbound_pci_region {
39162306a36Sopenharmony_ci	u64	addr;
39262306a36Sopenharmony_ci	u64	size;
39362306a36Sopenharmony_ci};
39462306a36Sopenharmony_ci
39562306a36Sopenharmony_ci/*
39662306a36Sopenharmony_ci * enum queue_cb_alloc_flags - Indicates queue support for CBs that
39762306a36Sopenharmony_ci * allocated by Kernel or by User
39862306a36Sopenharmony_ci * @CB_ALLOC_KERNEL: support only CBs that allocated by Kernel
39962306a36Sopenharmony_ci * @CB_ALLOC_USER: support only CBs that allocated by User
40062306a36Sopenharmony_ci */
40162306a36Sopenharmony_cienum queue_cb_alloc_flags {
40262306a36Sopenharmony_ci	CB_ALLOC_KERNEL = 0x1,
40362306a36Sopenharmony_ci	CB_ALLOC_USER   = 0x2
40462306a36Sopenharmony_ci};
40562306a36Sopenharmony_ci
40662306a36Sopenharmony_ci/*
40762306a36Sopenharmony_ci * struct hl_hw_sob - H/W SOB info.
40862306a36Sopenharmony_ci * @hdev: habanalabs device structure.
40962306a36Sopenharmony_ci * @kref: refcount of this SOB. The SOB will reset once the refcount is zero.
41062306a36Sopenharmony_ci * @sob_id: id of this SOB.
41162306a36Sopenharmony_ci * @sob_addr: the sob offset from the base address.
41262306a36Sopenharmony_ci * @q_idx: the H/W queue that uses this SOB.
41362306a36Sopenharmony_ci * @need_reset: reset indication set when switching to the other sob.
41462306a36Sopenharmony_ci */
41562306a36Sopenharmony_cistruct hl_hw_sob {
41662306a36Sopenharmony_ci	struct hl_device	*hdev;
41762306a36Sopenharmony_ci	struct kref		kref;
41862306a36Sopenharmony_ci	u32			sob_id;
41962306a36Sopenharmony_ci	u32			sob_addr;
42062306a36Sopenharmony_ci	u32			q_idx;
42162306a36Sopenharmony_ci	bool			need_reset;
42262306a36Sopenharmony_ci};
42362306a36Sopenharmony_ci
42462306a36Sopenharmony_cienum hl_collective_mode {
42562306a36Sopenharmony_ci	HL_COLLECTIVE_NOT_SUPPORTED = 0x0,
42662306a36Sopenharmony_ci	HL_COLLECTIVE_MASTER = 0x1,
42762306a36Sopenharmony_ci	HL_COLLECTIVE_SLAVE = 0x2
42862306a36Sopenharmony_ci};
42962306a36Sopenharmony_ci
43062306a36Sopenharmony_ci/**
43162306a36Sopenharmony_ci * struct hw_queue_properties - queue information.
43262306a36Sopenharmony_ci * @type: queue type.
43362306a36Sopenharmony_ci * @cb_alloc_flags: bitmap which indicates if the hw queue supports CB
43462306a36Sopenharmony_ci *                  that allocated by the Kernel driver and therefore,
43562306a36Sopenharmony_ci *                  a CB handle can be provided for jobs on this queue.
43662306a36Sopenharmony_ci *                  Otherwise, a CB address must be provided.
43762306a36Sopenharmony_ci * @collective_mode: collective mode of current queue
43862306a36Sopenharmony_ci * @driver_only: true if only the driver is allowed to send a job to this queue,
43962306a36Sopenharmony_ci *               false otherwise.
44062306a36Sopenharmony_ci * @binned: True if the queue is binned out and should not be used
44162306a36Sopenharmony_ci * @supports_sync_stream: True if queue supports sync stream
44262306a36Sopenharmony_ci */
44362306a36Sopenharmony_cistruct hw_queue_properties {
44462306a36Sopenharmony_ci	enum hl_queue_type		type;
44562306a36Sopenharmony_ci	enum queue_cb_alloc_flags	cb_alloc_flags;
44662306a36Sopenharmony_ci	enum hl_collective_mode		collective_mode;
44762306a36Sopenharmony_ci	u8				driver_only;
44862306a36Sopenharmony_ci	u8				binned;
44962306a36Sopenharmony_ci	u8				supports_sync_stream;
45062306a36Sopenharmony_ci};
45162306a36Sopenharmony_ci
45262306a36Sopenharmony_ci/**
45362306a36Sopenharmony_ci * enum vm_type - virtual memory mapping request information.
45462306a36Sopenharmony_ci * @VM_TYPE_USERPTR: mapping of user memory to device virtual address.
45562306a36Sopenharmony_ci * @VM_TYPE_PHYS_PACK: mapping of DRAM memory to device virtual address.
45662306a36Sopenharmony_ci */
45762306a36Sopenharmony_cienum vm_type {
45862306a36Sopenharmony_ci	VM_TYPE_USERPTR = 0x1,
45962306a36Sopenharmony_ci	VM_TYPE_PHYS_PACK = 0x2
46062306a36Sopenharmony_ci};
46162306a36Sopenharmony_ci
46262306a36Sopenharmony_ci/**
46362306a36Sopenharmony_ci * enum mmu_op_flags - mmu operation relevant information.
46462306a36Sopenharmony_ci * @MMU_OP_USERPTR: operation on user memory (host resident).
46562306a36Sopenharmony_ci * @MMU_OP_PHYS_PACK: operation on DRAM (device resident).
46662306a36Sopenharmony_ci * @MMU_OP_CLEAR_MEMCACHE: operation has to clear memcache.
46762306a36Sopenharmony_ci * @MMU_OP_SKIP_LOW_CACHE_INV: operation is allowed to skip parts of cache invalidation.
46862306a36Sopenharmony_ci */
46962306a36Sopenharmony_cienum mmu_op_flags {
47062306a36Sopenharmony_ci	MMU_OP_USERPTR = 0x1,
47162306a36Sopenharmony_ci	MMU_OP_PHYS_PACK = 0x2,
47262306a36Sopenharmony_ci	MMU_OP_CLEAR_MEMCACHE = 0x4,
47362306a36Sopenharmony_ci	MMU_OP_SKIP_LOW_CACHE_INV = 0x8,
47462306a36Sopenharmony_ci};
47562306a36Sopenharmony_ci
47662306a36Sopenharmony_ci
47762306a36Sopenharmony_ci/**
47862306a36Sopenharmony_ci * enum hl_device_hw_state - H/W device state. use this to understand whether
47962306a36Sopenharmony_ci *                           to do reset before hw_init or not
48062306a36Sopenharmony_ci * @HL_DEVICE_HW_STATE_CLEAN: H/W state is clean. i.e. after hard reset
48162306a36Sopenharmony_ci * @HL_DEVICE_HW_STATE_DIRTY: H/W state is dirty. i.e. we started to execute
48262306a36Sopenharmony_ci *                            hw_init
48362306a36Sopenharmony_ci */
48462306a36Sopenharmony_cienum hl_device_hw_state {
48562306a36Sopenharmony_ci	HL_DEVICE_HW_STATE_CLEAN = 0,
48662306a36Sopenharmony_ci	HL_DEVICE_HW_STATE_DIRTY
48762306a36Sopenharmony_ci};
48862306a36Sopenharmony_ci
48962306a36Sopenharmony_ci#define HL_MMU_VA_ALIGNMENT_NOT_NEEDED 0
49062306a36Sopenharmony_ci
49162306a36Sopenharmony_ci/**
49262306a36Sopenharmony_ci * struct hl_mmu_properties - ASIC specific MMU address translation properties.
49362306a36Sopenharmony_ci * @start_addr: virtual start address of the memory region.
49462306a36Sopenharmony_ci * @end_addr: virtual end address of the memory region.
49562306a36Sopenharmony_ci * @hop_shifts: array holds HOPs shifts.
49662306a36Sopenharmony_ci * @hop_masks: array holds HOPs masks.
49762306a36Sopenharmony_ci * @last_mask: mask to get the bit indicating this is the last hop.
49862306a36Sopenharmony_ci * @pgt_size: size for page tables.
49962306a36Sopenharmony_ci * @supported_pages_mask: bitmask for supported page size (relevant only for MMUs
50062306a36Sopenharmony_ci *                        supporting multiple page size).
50162306a36Sopenharmony_ci * @page_size: default page size used to allocate memory.
50262306a36Sopenharmony_ci * @num_hops: The amount of hops supported by the translation table.
50362306a36Sopenharmony_ci * @hop_table_size: HOP table size.
50462306a36Sopenharmony_ci * @hop0_tables_total_size: total size for all HOP0 tables.
50562306a36Sopenharmony_ci * @host_resident: Should the MMU page table reside in host memory or in the
50662306a36Sopenharmony_ci *                 device DRAM.
50762306a36Sopenharmony_ci */
50862306a36Sopenharmony_cistruct hl_mmu_properties {
50962306a36Sopenharmony_ci	u64	start_addr;
51062306a36Sopenharmony_ci	u64	end_addr;
51162306a36Sopenharmony_ci	u64	hop_shifts[MMU_HOP_MAX];
51262306a36Sopenharmony_ci	u64	hop_masks[MMU_HOP_MAX];
51362306a36Sopenharmony_ci	u64	last_mask;
51462306a36Sopenharmony_ci	u64	pgt_size;
51562306a36Sopenharmony_ci	u64	supported_pages_mask;
51662306a36Sopenharmony_ci	u32	page_size;
51762306a36Sopenharmony_ci	u32	num_hops;
51862306a36Sopenharmony_ci	u32	hop_table_size;
51962306a36Sopenharmony_ci	u32	hop0_tables_total_size;
52062306a36Sopenharmony_ci	u8	host_resident;
52162306a36Sopenharmony_ci};
52262306a36Sopenharmony_ci
52362306a36Sopenharmony_ci/**
52462306a36Sopenharmony_ci * struct hl_hints_range - hint addresses reserved va range.
52562306a36Sopenharmony_ci * @start_addr: start address of the va range.
52662306a36Sopenharmony_ci * @end_addr: end address of the va range.
52762306a36Sopenharmony_ci */
52862306a36Sopenharmony_cistruct hl_hints_range {
52962306a36Sopenharmony_ci	u64 start_addr;
53062306a36Sopenharmony_ci	u64 end_addr;
53162306a36Sopenharmony_ci};
53262306a36Sopenharmony_ci
53362306a36Sopenharmony_ci/**
53462306a36Sopenharmony_ci * struct asic_fixed_properties - ASIC specific immutable properties.
53562306a36Sopenharmony_ci * @hw_queues_props: H/W queues properties.
53662306a36Sopenharmony_ci * @special_blocks: points to an array containing special blocks info.
53762306a36Sopenharmony_ci * @skip_special_blocks_cfg: special blocks skip configs.
53862306a36Sopenharmony_ci * @cpucp_info: received various information from CPU-CP regarding the H/W, e.g.
53962306a36Sopenharmony_ci *		available sensors.
54062306a36Sopenharmony_ci * @uboot_ver: F/W U-boot version.
54162306a36Sopenharmony_ci * @preboot_ver: F/W Preboot version.
54262306a36Sopenharmony_ci * @dmmu: DRAM MMU address translation properties.
54362306a36Sopenharmony_ci * @pmmu: PCI (host) MMU address translation properties.
54462306a36Sopenharmony_ci * @pmmu_huge: PCI (host) MMU address translation properties for memory
54562306a36Sopenharmony_ci *              allocated with huge pages.
54662306a36Sopenharmony_ci * @hints_dram_reserved_va_range: dram hint addresses reserved range.
54762306a36Sopenharmony_ci * @hints_host_reserved_va_range: host hint addresses reserved range.
54862306a36Sopenharmony_ci * @hints_host_hpage_reserved_va_range: host huge page hint addresses reserved
54962306a36Sopenharmony_ci *                                      range.
55062306a36Sopenharmony_ci * @sram_base_address: SRAM physical start address.
55162306a36Sopenharmony_ci * @sram_end_address: SRAM physical end address.
55262306a36Sopenharmony_ci * @sram_user_base_address - SRAM physical start address for user access.
55362306a36Sopenharmony_ci * @dram_base_address: DRAM physical start address.
55462306a36Sopenharmony_ci * @dram_end_address: DRAM physical end address.
55562306a36Sopenharmony_ci * @dram_user_base_address: DRAM physical start address for user access.
55662306a36Sopenharmony_ci * @dram_size: DRAM total size.
55762306a36Sopenharmony_ci * @dram_pci_bar_size: size of PCI bar towards DRAM.
55862306a36Sopenharmony_ci * @max_power_default: max power of the device after reset.
55962306a36Sopenharmony_ci * @dc_power_default: power consumed by the device in mode idle.
56062306a36Sopenharmony_ci * @dram_size_for_default_page_mapping: DRAM size needed to map to avoid page
56162306a36Sopenharmony_ci *                                      fault.
56262306a36Sopenharmony_ci * @pcie_dbi_base_address: Base address of the PCIE_DBI block.
56362306a36Sopenharmony_ci * @pcie_aux_dbi_reg_addr: Address of the PCIE_AUX DBI register.
56462306a36Sopenharmony_ci * @mmu_pgt_addr: base physical address in DRAM of MMU page tables.
56562306a36Sopenharmony_ci * @mmu_dram_default_page_addr: DRAM default page physical address.
56662306a36Sopenharmony_ci * @tpc_enabled_mask: which TPCs are enabled.
56762306a36Sopenharmony_ci * @tpc_binning_mask: which TPCs are binned. 0 means usable and 1 means binned.
56862306a36Sopenharmony_ci * @dram_enabled_mask: which DRAMs are enabled.
56962306a36Sopenharmony_ci * @dram_binning_mask: which DRAMs are binned. 0 means usable, 1 means binned.
57062306a36Sopenharmony_ci * @dram_hints_align_mask: dram va hint addresses alignment mask which is used
57162306a36Sopenharmony_ci *                  for hints validity check.
57262306a36Sopenharmony_ci * @cfg_base_address: config space base address.
57362306a36Sopenharmony_ci * @mmu_cache_mng_addr: address of the MMU cache.
57462306a36Sopenharmony_ci * @mmu_cache_mng_size: size of the MMU cache.
57562306a36Sopenharmony_ci * @device_dma_offset_for_host_access: the offset to add to host DMA addresses
57662306a36Sopenharmony_ci *                                     to enable the device to access them.
57762306a36Sopenharmony_ci * @host_base_address: host physical start address for host DMA from device
57862306a36Sopenharmony_ci * @host_end_address: host physical end address for host DMA from device
57962306a36Sopenharmony_ci * @max_freq_value: current max clk frequency.
58062306a36Sopenharmony_ci * @engine_core_interrupt_reg_addr: interrupt register address for engine core to use
58162306a36Sopenharmony_ci *                                  in order to raise events toward FW.
58262306a36Sopenharmony_ci * @clk_pll_index: clock PLL index that specify which PLL determines the clock
58362306a36Sopenharmony_ci *                 we display to the user
58462306a36Sopenharmony_ci * @mmu_pgt_size: MMU page tables total size.
58562306a36Sopenharmony_ci * @mmu_pte_size: PTE size in MMU page tables.
58662306a36Sopenharmony_ci * @mmu_hop_table_size: MMU hop table size.
58762306a36Sopenharmony_ci * @mmu_hop0_tables_total_size: total size of MMU hop0 tables.
58862306a36Sopenharmony_ci * @dram_page_size: page size for MMU DRAM allocation.
58962306a36Sopenharmony_ci * @cfg_size: configuration space size on SRAM.
59062306a36Sopenharmony_ci * @sram_size: total size of SRAM.
59162306a36Sopenharmony_ci * @max_asid: maximum number of open contexts (ASIDs).
59262306a36Sopenharmony_ci * @num_of_events: number of possible internal H/W IRQs.
59362306a36Sopenharmony_ci * @psoc_pci_pll_nr: PCI PLL NR value.
59462306a36Sopenharmony_ci * @psoc_pci_pll_nf: PCI PLL NF value.
59562306a36Sopenharmony_ci * @psoc_pci_pll_od: PCI PLL OD value.
59662306a36Sopenharmony_ci * @psoc_pci_pll_div_factor: PCI PLL DIV FACTOR 1 value.
59762306a36Sopenharmony_ci * @psoc_timestamp_frequency: frequency of the psoc timestamp clock.
59862306a36Sopenharmony_ci * @high_pll: high PLL frequency used by the device.
59962306a36Sopenharmony_ci * @cb_pool_cb_cnt: number of CBs in the CB pool.
60062306a36Sopenharmony_ci * @cb_pool_cb_size: size of each CB in the CB pool.
60162306a36Sopenharmony_ci * @decoder_enabled_mask: which decoders are enabled.
60262306a36Sopenharmony_ci * @decoder_binning_mask: which decoders are binned, 0 means usable and 1 means binned.
60362306a36Sopenharmony_ci * @rotator_enabled_mask: which rotators are enabled.
60462306a36Sopenharmony_ci * @edma_enabled_mask: which EDMAs are enabled.
60562306a36Sopenharmony_ci * @edma_binning_mask: which EDMAs are binned, 0 means usable and 1 means
60662306a36Sopenharmony_ci *                     binned (at most one binned DMA).
60762306a36Sopenharmony_ci * @max_pending_cs: maximum of concurrent pending command submissions
60862306a36Sopenharmony_ci * @max_queues: maximum amount of queues in the system
60962306a36Sopenharmony_ci * @fw_preboot_cpu_boot_dev_sts0: bitmap representation of preboot cpu
61062306a36Sopenharmony_ci *                                capabilities reported by FW, bit description
61162306a36Sopenharmony_ci *                                can be found in CPU_BOOT_DEV_STS0
61262306a36Sopenharmony_ci * @fw_preboot_cpu_boot_dev_sts1: bitmap representation of preboot cpu
61362306a36Sopenharmony_ci *                                capabilities reported by FW, bit description
61462306a36Sopenharmony_ci *                                can be found in CPU_BOOT_DEV_STS1
61562306a36Sopenharmony_ci * @fw_bootfit_cpu_boot_dev_sts0: bitmap representation of boot cpu security
61662306a36Sopenharmony_ci *                                status reported by FW, bit description can be
61762306a36Sopenharmony_ci *                                found in CPU_BOOT_DEV_STS0
61862306a36Sopenharmony_ci * @fw_bootfit_cpu_boot_dev_sts1: bitmap representation of boot cpu security
61962306a36Sopenharmony_ci *                                status reported by FW, bit description can be
62062306a36Sopenharmony_ci *                                found in CPU_BOOT_DEV_STS1
62162306a36Sopenharmony_ci * @fw_app_cpu_boot_dev_sts0: bitmap representation of application security
62262306a36Sopenharmony_ci *                            status reported by FW, bit description can be
62362306a36Sopenharmony_ci *                            found in CPU_BOOT_DEV_STS0
62462306a36Sopenharmony_ci * @fw_app_cpu_boot_dev_sts1: bitmap representation of application security
62562306a36Sopenharmony_ci *                            status reported by FW, bit description can be
62662306a36Sopenharmony_ci *                            found in CPU_BOOT_DEV_STS1
62762306a36Sopenharmony_ci * @max_dec: maximum number of decoders
62862306a36Sopenharmony_ci * @hmmu_hif_enabled_mask: mask of HMMUs/HIFs that are not isolated (enabled)
62962306a36Sopenharmony_ci *                         1- enabled, 0- isolated.
63062306a36Sopenharmony_ci * @faulty_dram_cluster_map: mask of faulty DRAM cluster.
63162306a36Sopenharmony_ci *                         1- faulty cluster, 0- good cluster.
63262306a36Sopenharmony_ci * @xbar_edge_enabled_mask: mask of XBAR_EDGEs that are not isolated (enabled)
63362306a36Sopenharmony_ci *                          1- enabled, 0- isolated.
63462306a36Sopenharmony_ci * @device_mem_alloc_default_page_size: may be different than dram_page_size only for ASICs for
63562306a36Sopenharmony_ci *                                      which the property supports_user_set_page_size is true
63662306a36Sopenharmony_ci *                                      (i.e. the DRAM supports multiple page sizes), otherwise
63762306a36Sopenharmony_ci *                                      it will shall  be equal to dram_page_size.
63862306a36Sopenharmony_ci * @num_engine_cores: number of engine cpu cores.
63962306a36Sopenharmony_ci * @max_num_of_engines: maximum number of all engines in the ASIC.
64062306a36Sopenharmony_ci * @num_of_special_blocks: special_blocks array size.
64162306a36Sopenharmony_ci * @glbl_err_cause_num: global err cause number.
64262306a36Sopenharmony_ci * @hbw_flush_reg: register to read to generate HBW flush. value of 0 means HBW flush is
64362306a36Sopenharmony_ci *                 not supported.
64462306a36Sopenharmony_ci * @collective_first_sob: first sync object available for collective use
64562306a36Sopenharmony_ci * @collective_first_mon: first monitor available for collective use
64662306a36Sopenharmony_ci * @sync_stream_first_sob: first sync object available for sync stream use
64762306a36Sopenharmony_ci * @sync_stream_first_mon: first monitor available for sync stream use
64862306a36Sopenharmony_ci * @first_available_user_sob: first sob available for the user
64962306a36Sopenharmony_ci * @first_available_user_mon: first monitor available for the user
65062306a36Sopenharmony_ci * @first_available_user_interrupt: first available interrupt reserved for the user
65162306a36Sopenharmony_ci * @first_available_cq: first available CQ for the user.
65262306a36Sopenharmony_ci * @user_interrupt_count: number of user interrupts.
65362306a36Sopenharmony_ci * @user_dec_intr_count: number of decoder interrupts exposed to user.
65462306a36Sopenharmony_ci * @tpc_interrupt_id: interrupt id for TPC to use in order to raise events towards the host.
65562306a36Sopenharmony_ci * @eq_interrupt_id: interrupt id for EQ, uses to synchronize EQ interrupts in hard-reset.
65662306a36Sopenharmony_ci * @cache_line_size: device cache line size.
65762306a36Sopenharmony_ci * @server_type: Server type that the ASIC is currently installed in.
65862306a36Sopenharmony_ci *               The value is according to enum hl_server_type in uapi file.
65962306a36Sopenharmony_ci * @completion_queues_count: number of completion queues.
66062306a36Sopenharmony_ci * @completion_mode: 0 - job based completion, 1 - cs based completion
66162306a36Sopenharmony_ci * @mme_master_slave_mode: 0 - Each MME works independently, 1 - MME works
66262306a36Sopenharmony_ci *                         in Master/Slave mode
66362306a36Sopenharmony_ci * @fw_security_enabled: true if security measures are enabled in firmware,
66462306a36Sopenharmony_ci *                       false otherwise
66562306a36Sopenharmony_ci * @fw_cpu_boot_dev_sts0_valid: status bits are valid and can be fetched from
66662306a36Sopenharmony_ci *                              BOOT_DEV_STS0
66762306a36Sopenharmony_ci * @fw_cpu_boot_dev_sts1_valid: status bits are valid and can be fetched from
66862306a36Sopenharmony_ci *                              BOOT_DEV_STS1
66962306a36Sopenharmony_ci * @dram_supports_virtual_memory: is there an MMU towards the DRAM
67062306a36Sopenharmony_ci * @hard_reset_done_by_fw: true if firmware is handling hard reset flow
67162306a36Sopenharmony_ci * @num_functional_hbms: number of functional HBMs in each DCORE.
67262306a36Sopenharmony_ci * @hints_range_reservation: device support hint addresses range reservation.
67362306a36Sopenharmony_ci * @iatu_done_by_fw: true if iATU configuration is being done by FW.
67462306a36Sopenharmony_ci * @dynamic_fw_load: is dynamic FW load is supported.
67562306a36Sopenharmony_ci * @gic_interrupts_enable: true if FW is not blocking GIC controller,
67662306a36Sopenharmony_ci *                         false otherwise.
67762306a36Sopenharmony_ci * @use_get_power_for_reset_history: To support backward compatibility for Goya
67862306a36Sopenharmony_ci *                                   and Gaudi
67962306a36Sopenharmony_ci * @supports_compute_reset: is a reset which is not a hard-reset supported by this asic.
68062306a36Sopenharmony_ci * @allow_inference_soft_reset: true if the ASIC supports soft reset that is
68162306a36Sopenharmony_ci *                              initiated by user or TDR. This is only true
68262306a36Sopenharmony_ci *                              in inference ASICs, as there is no real-world
68362306a36Sopenharmony_ci *                              use-case of doing soft-reset in training (due
68462306a36Sopenharmony_ci *                              to the fact that training runs on multiple
68562306a36Sopenharmony_ci *                              devices)
68662306a36Sopenharmony_ci * @configurable_stop_on_err: is stop-on-error option configurable via debugfs.
68762306a36Sopenharmony_ci * @set_max_power_on_device_init: true if need to set max power in F/W on device init.
68862306a36Sopenharmony_ci * @supports_user_set_page_size: true if user can set the allocation page size.
68962306a36Sopenharmony_ci * @dma_mask: the dma mask to be set for this device
69062306a36Sopenharmony_ci * @supports_advanced_cpucp_rc: true if new cpucp opcodes are supported.
69162306a36Sopenharmony_ci * @supports_engine_modes: true if changing engines/engine_cores modes is supported.
69262306a36Sopenharmony_ci */
69362306a36Sopenharmony_cistruct asic_fixed_properties {
69462306a36Sopenharmony_ci	struct hw_queue_properties	*hw_queues_props;
69562306a36Sopenharmony_ci	struct hl_special_block_info	*special_blocks;
69662306a36Sopenharmony_ci	struct hl_skip_blocks_cfg	skip_special_blocks_cfg;
69762306a36Sopenharmony_ci	struct cpucp_info		cpucp_info;
69862306a36Sopenharmony_ci	char				uboot_ver[VERSION_MAX_LEN];
69962306a36Sopenharmony_ci	char				preboot_ver[VERSION_MAX_LEN];
70062306a36Sopenharmony_ci	struct hl_mmu_properties	dmmu;
70162306a36Sopenharmony_ci	struct hl_mmu_properties	pmmu;
70262306a36Sopenharmony_ci	struct hl_mmu_properties	pmmu_huge;
70362306a36Sopenharmony_ci	struct hl_hints_range		hints_dram_reserved_va_range;
70462306a36Sopenharmony_ci	struct hl_hints_range		hints_host_reserved_va_range;
70562306a36Sopenharmony_ci	struct hl_hints_range		hints_host_hpage_reserved_va_range;
70662306a36Sopenharmony_ci	u64				sram_base_address;
70762306a36Sopenharmony_ci	u64				sram_end_address;
70862306a36Sopenharmony_ci	u64				sram_user_base_address;
70962306a36Sopenharmony_ci	u64				dram_base_address;
71062306a36Sopenharmony_ci	u64				dram_end_address;
71162306a36Sopenharmony_ci	u64				dram_user_base_address;
71262306a36Sopenharmony_ci	u64				dram_size;
71362306a36Sopenharmony_ci	u64				dram_pci_bar_size;
71462306a36Sopenharmony_ci	u64				max_power_default;
71562306a36Sopenharmony_ci	u64				dc_power_default;
71662306a36Sopenharmony_ci	u64				dram_size_for_default_page_mapping;
71762306a36Sopenharmony_ci	u64				pcie_dbi_base_address;
71862306a36Sopenharmony_ci	u64				pcie_aux_dbi_reg_addr;
71962306a36Sopenharmony_ci	u64				mmu_pgt_addr;
72062306a36Sopenharmony_ci	u64				mmu_dram_default_page_addr;
72162306a36Sopenharmony_ci	u64				tpc_enabled_mask;
72262306a36Sopenharmony_ci	u64				tpc_binning_mask;
72362306a36Sopenharmony_ci	u64				dram_enabled_mask;
72462306a36Sopenharmony_ci	u64				dram_binning_mask;
72562306a36Sopenharmony_ci	u64				dram_hints_align_mask;
72662306a36Sopenharmony_ci	u64				cfg_base_address;
72762306a36Sopenharmony_ci	u64				mmu_cache_mng_addr;
72862306a36Sopenharmony_ci	u64				mmu_cache_mng_size;
72962306a36Sopenharmony_ci	u64				device_dma_offset_for_host_access;
73062306a36Sopenharmony_ci	u64				host_base_address;
73162306a36Sopenharmony_ci	u64				host_end_address;
73262306a36Sopenharmony_ci	u64				max_freq_value;
73362306a36Sopenharmony_ci	u64				engine_core_interrupt_reg_addr;
73462306a36Sopenharmony_ci	u32				clk_pll_index;
73562306a36Sopenharmony_ci	u32				mmu_pgt_size;
73662306a36Sopenharmony_ci	u32				mmu_pte_size;
73762306a36Sopenharmony_ci	u32				mmu_hop_table_size;
73862306a36Sopenharmony_ci	u32				mmu_hop0_tables_total_size;
73962306a36Sopenharmony_ci	u32				dram_page_size;
74062306a36Sopenharmony_ci	u32				cfg_size;
74162306a36Sopenharmony_ci	u32				sram_size;
74262306a36Sopenharmony_ci	u32				max_asid;
74362306a36Sopenharmony_ci	u32				num_of_events;
74462306a36Sopenharmony_ci	u32				psoc_pci_pll_nr;
74562306a36Sopenharmony_ci	u32				psoc_pci_pll_nf;
74662306a36Sopenharmony_ci	u32				psoc_pci_pll_od;
74762306a36Sopenharmony_ci	u32				psoc_pci_pll_div_factor;
74862306a36Sopenharmony_ci	u32				psoc_timestamp_frequency;
74962306a36Sopenharmony_ci	u32				high_pll;
75062306a36Sopenharmony_ci	u32				cb_pool_cb_cnt;
75162306a36Sopenharmony_ci	u32				cb_pool_cb_size;
75262306a36Sopenharmony_ci	u32				decoder_enabled_mask;
75362306a36Sopenharmony_ci	u32				decoder_binning_mask;
75462306a36Sopenharmony_ci	u32				rotator_enabled_mask;
75562306a36Sopenharmony_ci	u32				edma_enabled_mask;
75662306a36Sopenharmony_ci	u32				edma_binning_mask;
75762306a36Sopenharmony_ci	u32				max_pending_cs;
75862306a36Sopenharmony_ci	u32				max_queues;
75962306a36Sopenharmony_ci	u32				fw_preboot_cpu_boot_dev_sts0;
76062306a36Sopenharmony_ci	u32				fw_preboot_cpu_boot_dev_sts1;
76162306a36Sopenharmony_ci	u32				fw_bootfit_cpu_boot_dev_sts0;
76262306a36Sopenharmony_ci	u32				fw_bootfit_cpu_boot_dev_sts1;
76362306a36Sopenharmony_ci	u32				fw_app_cpu_boot_dev_sts0;
76462306a36Sopenharmony_ci	u32				fw_app_cpu_boot_dev_sts1;
76562306a36Sopenharmony_ci	u32				max_dec;
76662306a36Sopenharmony_ci	u32				hmmu_hif_enabled_mask;
76762306a36Sopenharmony_ci	u32				faulty_dram_cluster_map;
76862306a36Sopenharmony_ci	u32				xbar_edge_enabled_mask;
76962306a36Sopenharmony_ci	u32				device_mem_alloc_default_page_size;
77062306a36Sopenharmony_ci	u32				num_engine_cores;
77162306a36Sopenharmony_ci	u32				max_num_of_engines;
77262306a36Sopenharmony_ci	u32				num_of_special_blocks;
77362306a36Sopenharmony_ci	u32				glbl_err_cause_num;
77462306a36Sopenharmony_ci	u32				hbw_flush_reg;
77562306a36Sopenharmony_ci	u16				collective_first_sob;
77662306a36Sopenharmony_ci	u16				collective_first_mon;
77762306a36Sopenharmony_ci	u16				sync_stream_first_sob;
77862306a36Sopenharmony_ci	u16				sync_stream_first_mon;
77962306a36Sopenharmony_ci	u16				first_available_user_sob[HL_MAX_DCORES];
78062306a36Sopenharmony_ci	u16				first_available_user_mon[HL_MAX_DCORES];
78162306a36Sopenharmony_ci	u16				first_available_user_interrupt;
78262306a36Sopenharmony_ci	u16				first_available_cq[HL_MAX_DCORES];
78362306a36Sopenharmony_ci	u16				user_interrupt_count;
78462306a36Sopenharmony_ci	u16				user_dec_intr_count;
78562306a36Sopenharmony_ci	u16				tpc_interrupt_id;
78662306a36Sopenharmony_ci	u16				eq_interrupt_id;
78762306a36Sopenharmony_ci	u16				cache_line_size;
78862306a36Sopenharmony_ci	u16				server_type;
78962306a36Sopenharmony_ci	u8				completion_queues_count;
79062306a36Sopenharmony_ci	u8				completion_mode;
79162306a36Sopenharmony_ci	u8				mme_master_slave_mode;
79262306a36Sopenharmony_ci	u8				fw_security_enabled;
79362306a36Sopenharmony_ci	u8				fw_cpu_boot_dev_sts0_valid;
79462306a36Sopenharmony_ci	u8				fw_cpu_boot_dev_sts1_valid;
79562306a36Sopenharmony_ci	u8				dram_supports_virtual_memory;
79662306a36Sopenharmony_ci	u8				hard_reset_done_by_fw;
79762306a36Sopenharmony_ci	u8				num_functional_hbms;
79862306a36Sopenharmony_ci	u8				hints_range_reservation;
79962306a36Sopenharmony_ci	u8				iatu_done_by_fw;
80062306a36Sopenharmony_ci	u8				dynamic_fw_load;
80162306a36Sopenharmony_ci	u8				gic_interrupts_enable;
80262306a36Sopenharmony_ci	u8				use_get_power_for_reset_history;
80362306a36Sopenharmony_ci	u8				supports_compute_reset;
80462306a36Sopenharmony_ci	u8				allow_inference_soft_reset;
80562306a36Sopenharmony_ci	u8				configurable_stop_on_err;
80662306a36Sopenharmony_ci	u8				set_max_power_on_device_init;
80762306a36Sopenharmony_ci	u8				supports_user_set_page_size;
80862306a36Sopenharmony_ci	u8				dma_mask;
80962306a36Sopenharmony_ci	u8				supports_advanced_cpucp_rc;
81062306a36Sopenharmony_ci	u8				supports_engine_modes;
81162306a36Sopenharmony_ci};
81262306a36Sopenharmony_ci
81362306a36Sopenharmony_ci/**
81462306a36Sopenharmony_ci * struct hl_fence - software synchronization primitive
81562306a36Sopenharmony_ci * @completion: fence is implemented using completion
81662306a36Sopenharmony_ci * @refcount: refcount for this fence
81762306a36Sopenharmony_ci * @cs_sequence: sequence of the corresponding command submission
81862306a36Sopenharmony_ci * @stream_master_qid_map: streams masters QID bitmap to represent all streams
81962306a36Sopenharmony_ci *                         masters QIDs that multi cs is waiting on
82062306a36Sopenharmony_ci * @error: mark this fence with error
82162306a36Sopenharmony_ci * @timestamp: timestamp upon completion
82262306a36Sopenharmony_ci * @mcs_handling_done: indicates that corresponding command submission has
82362306a36Sopenharmony_ci *                     finished msc handling, this does not mean it was part
82462306a36Sopenharmony_ci *                     of the mcs
82562306a36Sopenharmony_ci */
82662306a36Sopenharmony_cistruct hl_fence {
82762306a36Sopenharmony_ci	struct completion	completion;
82862306a36Sopenharmony_ci	struct kref		refcount;
82962306a36Sopenharmony_ci	u64			cs_sequence;
83062306a36Sopenharmony_ci	u32			stream_master_qid_map;
83162306a36Sopenharmony_ci	int			error;
83262306a36Sopenharmony_ci	ktime_t			timestamp;
83362306a36Sopenharmony_ci	u8			mcs_handling_done;
83462306a36Sopenharmony_ci};
83562306a36Sopenharmony_ci
83662306a36Sopenharmony_ci/**
83762306a36Sopenharmony_ci * struct hl_cs_compl - command submission completion object.
83862306a36Sopenharmony_ci * @base_fence: hl fence object.
83962306a36Sopenharmony_ci * @lock: spinlock to protect fence.
84062306a36Sopenharmony_ci * @hdev: habanalabs device structure.
84162306a36Sopenharmony_ci * @hw_sob: the H/W SOB used in this signal/wait CS.
84262306a36Sopenharmony_ci * @encaps_sig_hdl: encaps signals handler.
84362306a36Sopenharmony_ci * @cs_seq: command submission sequence number.
84462306a36Sopenharmony_ci * @type: type of the CS - signal/wait.
84562306a36Sopenharmony_ci * @sob_val: the SOB value that is used in this signal/wait CS.
84662306a36Sopenharmony_ci * @sob_group: the SOB group that is used in this collective wait CS.
84762306a36Sopenharmony_ci * @encaps_signals: indication whether it's a completion object of cs with
84862306a36Sopenharmony_ci * encaps signals or not.
84962306a36Sopenharmony_ci */
85062306a36Sopenharmony_cistruct hl_cs_compl {
85162306a36Sopenharmony_ci	struct hl_fence		base_fence;
85262306a36Sopenharmony_ci	spinlock_t		lock;
85362306a36Sopenharmony_ci	struct hl_device	*hdev;
85462306a36Sopenharmony_ci	struct hl_hw_sob	*hw_sob;
85562306a36Sopenharmony_ci	struct hl_cs_encaps_sig_handle *encaps_sig_hdl;
85662306a36Sopenharmony_ci	u64			cs_seq;
85762306a36Sopenharmony_ci	enum hl_cs_type		type;
85862306a36Sopenharmony_ci	u16			sob_val;
85962306a36Sopenharmony_ci	u16			sob_group;
86062306a36Sopenharmony_ci	bool			encaps_signals;
86162306a36Sopenharmony_ci};
86262306a36Sopenharmony_ci
86362306a36Sopenharmony_ci/*
86462306a36Sopenharmony_ci * Command Buffers
86562306a36Sopenharmony_ci */
86662306a36Sopenharmony_ci
86762306a36Sopenharmony_ci/**
86862306a36Sopenharmony_ci * struct hl_ts_buff - describes a timestamp buffer.
86962306a36Sopenharmony_ci * @kernel_buff_address: Holds the internal buffer's kernel virtual address.
87062306a36Sopenharmony_ci * @user_buff_address: Holds the user buffer's kernel virtual address.
87162306a36Sopenharmony_ci * @kernel_buff_size: Holds the internal kernel buffer size.
87262306a36Sopenharmony_ci */
87362306a36Sopenharmony_cistruct hl_ts_buff {
87462306a36Sopenharmony_ci	void			*kernel_buff_address;
87562306a36Sopenharmony_ci	void			*user_buff_address;
87662306a36Sopenharmony_ci	u32			kernel_buff_size;
87762306a36Sopenharmony_ci};
87862306a36Sopenharmony_ci
87962306a36Sopenharmony_cistruct hl_mmap_mem_buf;
88062306a36Sopenharmony_ci
88162306a36Sopenharmony_ci/**
88262306a36Sopenharmony_ci * struct hl_mem_mgr - describes unified memory manager for mappable memory chunks.
88362306a36Sopenharmony_ci * @dev: back pointer to the owning device
88462306a36Sopenharmony_ci * @lock: protects handles
88562306a36Sopenharmony_ci * @handles: an idr holding all active handles to the memory buffers in the system.
88662306a36Sopenharmony_ci */
88762306a36Sopenharmony_cistruct hl_mem_mgr {
88862306a36Sopenharmony_ci	struct device *dev;
88962306a36Sopenharmony_ci	spinlock_t lock;
89062306a36Sopenharmony_ci	struct idr handles;
89162306a36Sopenharmony_ci};
89262306a36Sopenharmony_ci
89362306a36Sopenharmony_ci/**
89462306a36Sopenharmony_ci * struct hl_mmap_mem_buf_behavior - describes unified memory manager buffer behavior
89562306a36Sopenharmony_ci * @topic: string identifier used for logging
89662306a36Sopenharmony_ci * @mem_id: memory type identifier, embedded in the handle and used to identify
89762306a36Sopenharmony_ci *          the memory type by handle.
89862306a36Sopenharmony_ci * @alloc: callback executed on buffer allocation, shall allocate the memory,
89962306a36Sopenharmony_ci *         set it under buffer private, and set mappable size.
90062306a36Sopenharmony_ci * @mmap: callback executed on mmap, must map the buffer to vma
90162306a36Sopenharmony_ci * @release: callback executed on release, must free the resources used by the buffer
90262306a36Sopenharmony_ci */
90362306a36Sopenharmony_cistruct hl_mmap_mem_buf_behavior {
90462306a36Sopenharmony_ci	const char *topic;
90562306a36Sopenharmony_ci	u64 mem_id;
90662306a36Sopenharmony_ci
90762306a36Sopenharmony_ci	int (*alloc)(struct hl_mmap_mem_buf *buf, gfp_t gfp, void *args);
90862306a36Sopenharmony_ci	int (*mmap)(struct hl_mmap_mem_buf *buf, struct vm_area_struct *vma, void *args);
90962306a36Sopenharmony_ci	void (*release)(struct hl_mmap_mem_buf *buf);
91062306a36Sopenharmony_ci};
91162306a36Sopenharmony_ci
91262306a36Sopenharmony_ci/**
91362306a36Sopenharmony_ci * struct hl_mmap_mem_buf - describes a single unified memory buffer
91462306a36Sopenharmony_ci * @behavior: buffer behavior
91562306a36Sopenharmony_ci * @mmg: back pointer to the unified memory manager
91662306a36Sopenharmony_ci * @refcount: reference counter for buffer users
91762306a36Sopenharmony_ci * @private: pointer to buffer behavior private data
91862306a36Sopenharmony_ci * @mmap: atomic boolean indicating whether or not the buffer is mapped right now
91962306a36Sopenharmony_ci * @real_mapped_size: the actual size of buffer mapped, after part of it may be released,
92062306a36Sopenharmony_ci *                   may change at runtime.
92162306a36Sopenharmony_ci * @mappable_size: the original mappable size of the buffer, does not change after
92262306a36Sopenharmony_ci *                 the allocation.
92362306a36Sopenharmony_ci * @handle: the buffer id in mmg handles store
92462306a36Sopenharmony_ci */
92562306a36Sopenharmony_cistruct hl_mmap_mem_buf {
92662306a36Sopenharmony_ci	struct hl_mmap_mem_buf_behavior *behavior;
92762306a36Sopenharmony_ci	struct hl_mem_mgr *mmg;
92862306a36Sopenharmony_ci	struct kref refcount;
92962306a36Sopenharmony_ci	void *private;
93062306a36Sopenharmony_ci	atomic_t mmap;
93162306a36Sopenharmony_ci	u64 real_mapped_size;
93262306a36Sopenharmony_ci	u64 mappable_size;
93362306a36Sopenharmony_ci	u64 handle;
93462306a36Sopenharmony_ci};
93562306a36Sopenharmony_ci
93662306a36Sopenharmony_ci/**
93762306a36Sopenharmony_ci * struct hl_cb - describes a Command Buffer.
93862306a36Sopenharmony_ci * @hdev: pointer to device this CB belongs to.
93962306a36Sopenharmony_ci * @ctx: pointer to the CB owner's context.
94062306a36Sopenharmony_ci * @buf: back pointer to the parent mappable memory buffer
94162306a36Sopenharmony_ci * @debugfs_list: node in debugfs list of command buffers.
94262306a36Sopenharmony_ci * @pool_list: node in pool list of command buffers.
94362306a36Sopenharmony_ci * @kernel_address: Holds the CB's kernel virtual address.
94462306a36Sopenharmony_ci * @virtual_addr: Holds the CB's virtual address.
94562306a36Sopenharmony_ci * @bus_address: Holds the CB's DMA address.
94662306a36Sopenharmony_ci * @size: holds the CB's size.
94762306a36Sopenharmony_ci * @roundup_size: holds the cb size after roundup to page size.
94862306a36Sopenharmony_ci * @cs_cnt: holds number of CS that this CB participates in.
94962306a36Sopenharmony_ci * @is_handle_destroyed: atomic boolean indicating whether or not the CB handle was destroyed.
95062306a36Sopenharmony_ci * @is_pool: true if CB was acquired from the pool, false otherwise.
95162306a36Sopenharmony_ci * @is_internal: internally allocated
95262306a36Sopenharmony_ci * @is_mmu_mapped: true if the CB is mapped to the device's MMU.
95362306a36Sopenharmony_ci */
95462306a36Sopenharmony_cistruct hl_cb {
95562306a36Sopenharmony_ci	struct hl_device	*hdev;
95662306a36Sopenharmony_ci	struct hl_ctx		*ctx;
95762306a36Sopenharmony_ci	struct hl_mmap_mem_buf	*buf;
95862306a36Sopenharmony_ci	struct list_head	debugfs_list;
95962306a36Sopenharmony_ci	struct list_head	pool_list;
96062306a36Sopenharmony_ci	void			*kernel_address;
96162306a36Sopenharmony_ci	u64			virtual_addr;
96262306a36Sopenharmony_ci	dma_addr_t		bus_address;
96362306a36Sopenharmony_ci	u32			size;
96462306a36Sopenharmony_ci	u32			roundup_size;
96562306a36Sopenharmony_ci	atomic_t		cs_cnt;
96662306a36Sopenharmony_ci	atomic_t		is_handle_destroyed;
96762306a36Sopenharmony_ci	u8			is_pool;
96862306a36Sopenharmony_ci	u8			is_internal;
96962306a36Sopenharmony_ci	u8			is_mmu_mapped;
97062306a36Sopenharmony_ci};
97162306a36Sopenharmony_ci
97262306a36Sopenharmony_ci
97362306a36Sopenharmony_ci/*
97462306a36Sopenharmony_ci * QUEUES
97562306a36Sopenharmony_ci */
97662306a36Sopenharmony_ci
97762306a36Sopenharmony_cistruct hl_cs_job;
97862306a36Sopenharmony_ci
97962306a36Sopenharmony_ci/* Queue length of external and HW queues */
98062306a36Sopenharmony_ci#define HL_QUEUE_LENGTH			4096
98162306a36Sopenharmony_ci#define HL_QUEUE_SIZE_IN_BYTES		(HL_QUEUE_LENGTH * HL_BD_SIZE)
98262306a36Sopenharmony_ci
98362306a36Sopenharmony_ci#if (HL_MAX_JOBS_PER_CS > HL_QUEUE_LENGTH)
98462306a36Sopenharmony_ci#error "HL_QUEUE_LENGTH must be greater than HL_MAX_JOBS_PER_CS"
98562306a36Sopenharmony_ci#endif
98662306a36Sopenharmony_ci
98762306a36Sopenharmony_ci/* HL_CQ_LENGTH is in units of struct hl_cq_entry */
98862306a36Sopenharmony_ci#define HL_CQ_LENGTH			HL_QUEUE_LENGTH
98962306a36Sopenharmony_ci#define HL_CQ_SIZE_IN_BYTES		(HL_CQ_LENGTH * HL_CQ_ENTRY_SIZE)
99062306a36Sopenharmony_ci
99162306a36Sopenharmony_ci/* Must be power of 2 */
99262306a36Sopenharmony_ci#define HL_EQ_LENGTH			64
99362306a36Sopenharmony_ci#define HL_EQ_SIZE_IN_BYTES		(HL_EQ_LENGTH * HL_EQ_ENTRY_SIZE)
99462306a36Sopenharmony_ci
99562306a36Sopenharmony_ci/* Host <-> CPU-CP shared memory size */
99662306a36Sopenharmony_ci#define HL_CPU_ACCESSIBLE_MEM_SIZE	SZ_2M
99762306a36Sopenharmony_ci
99862306a36Sopenharmony_ci/**
99962306a36Sopenharmony_ci * struct hl_sync_stream_properties -
100062306a36Sopenharmony_ci *     describes a H/W queue sync stream properties
100162306a36Sopenharmony_ci * @hw_sob: array of the used H/W SOBs by this H/W queue.
100262306a36Sopenharmony_ci * @next_sob_val: the next value to use for the currently used SOB.
100362306a36Sopenharmony_ci * @base_sob_id: the base SOB id of the SOBs used by this queue.
100462306a36Sopenharmony_ci * @base_mon_id: the base MON id of the MONs used by this queue.
100562306a36Sopenharmony_ci * @collective_mstr_mon_id: the MON ids of the MONs used by this master queue
100662306a36Sopenharmony_ci *                          in order to sync with all slave queues.
100762306a36Sopenharmony_ci * @collective_slave_mon_id: the MON id used by this slave queue in order to
100862306a36Sopenharmony_ci *                           sync with its master queue.
100962306a36Sopenharmony_ci * @collective_sob_id: current SOB id used by this collective slave queue
101062306a36Sopenharmony_ci *                     to signal its collective master queue upon completion.
101162306a36Sopenharmony_ci * @curr_sob_offset: the id offset to the currently used SOB from the
101262306a36Sopenharmony_ci *                   HL_RSVD_SOBS that are being used by this queue.
101362306a36Sopenharmony_ci */
101462306a36Sopenharmony_cistruct hl_sync_stream_properties {
101562306a36Sopenharmony_ci	struct hl_hw_sob hw_sob[HL_RSVD_SOBS];
101662306a36Sopenharmony_ci	u16		next_sob_val;
101762306a36Sopenharmony_ci	u16		base_sob_id;
101862306a36Sopenharmony_ci	u16		base_mon_id;
101962306a36Sopenharmony_ci	u16		collective_mstr_mon_id[HL_COLLECTIVE_RSVD_MSTR_MONS];
102062306a36Sopenharmony_ci	u16		collective_slave_mon_id;
102162306a36Sopenharmony_ci	u16		collective_sob_id;
102262306a36Sopenharmony_ci	u8		curr_sob_offset;
102362306a36Sopenharmony_ci};
102462306a36Sopenharmony_ci
102562306a36Sopenharmony_ci/**
102662306a36Sopenharmony_ci * struct hl_encaps_signals_mgr - describes sync stream encapsulated signals
102762306a36Sopenharmony_ci * handlers manager
102862306a36Sopenharmony_ci * @lock: protects handles.
102962306a36Sopenharmony_ci * @handles: an idr to hold all encapsulated signals handles.
103062306a36Sopenharmony_ci */
103162306a36Sopenharmony_cistruct hl_encaps_signals_mgr {
103262306a36Sopenharmony_ci	spinlock_t		lock;
103362306a36Sopenharmony_ci	struct idr		handles;
103462306a36Sopenharmony_ci};
103562306a36Sopenharmony_ci
103662306a36Sopenharmony_ci/**
103762306a36Sopenharmony_ci * struct hl_hw_queue - describes a H/W transport queue.
103862306a36Sopenharmony_ci * @shadow_queue: pointer to a shadow queue that holds pointers to jobs.
103962306a36Sopenharmony_ci * @sync_stream_prop: sync stream queue properties
104062306a36Sopenharmony_ci * @queue_type: type of queue.
104162306a36Sopenharmony_ci * @collective_mode: collective mode of current queue
104262306a36Sopenharmony_ci * @kernel_address: holds the queue's kernel virtual address.
104362306a36Sopenharmony_ci * @bus_address: holds the queue's DMA address.
104462306a36Sopenharmony_ci * @pi: holds the queue's pi value.
104562306a36Sopenharmony_ci * @ci: holds the queue's ci value, AS CALCULATED BY THE DRIVER (not real ci).
104662306a36Sopenharmony_ci * @hw_queue_id: the id of the H/W queue.
104762306a36Sopenharmony_ci * @cq_id: the id for the corresponding CQ for this H/W queue.
104862306a36Sopenharmony_ci * @msi_vec: the IRQ number of the H/W queue.
104962306a36Sopenharmony_ci * @int_queue_len: length of internal queue (number of entries).
105062306a36Sopenharmony_ci * @valid: is the queue valid (we have array of 32 queues, not all of them
105162306a36Sopenharmony_ci *         exist).
105262306a36Sopenharmony_ci * @supports_sync_stream: True if queue supports sync stream
105362306a36Sopenharmony_ci */
105462306a36Sopenharmony_cistruct hl_hw_queue {
105562306a36Sopenharmony_ci	struct hl_cs_job			**shadow_queue;
105662306a36Sopenharmony_ci	struct hl_sync_stream_properties	sync_stream_prop;
105762306a36Sopenharmony_ci	enum hl_queue_type			queue_type;
105862306a36Sopenharmony_ci	enum hl_collective_mode			collective_mode;
105962306a36Sopenharmony_ci	void					*kernel_address;
106062306a36Sopenharmony_ci	dma_addr_t				bus_address;
106162306a36Sopenharmony_ci	u32					pi;
106262306a36Sopenharmony_ci	atomic_t				ci;
106362306a36Sopenharmony_ci	u32					hw_queue_id;
106462306a36Sopenharmony_ci	u32					cq_id;
106562306a36Sopenharmony_ci	u32					msi_vec;
106662306a36Sopenharmony_ci	u16					int_queue_len;
106762306a36Sopenharmony_ci	u8					valid;
106862306a36Sopenharmony_ci	u8					supports_sync_stream;
106962306a36Sopenharmony_ci};
107062306a36Sopenharmony_ci
107162306a36Sopenharmony_ci/**
107262306a36Sopenharmony_ci * struct hl_cq - describes a completion queue
107362306a36Sopenharmony_ci * @hdev: pointer to the device structure
107462306a36Sopenharmony_ci * @kernel_address: holds the queue's kernel virtual address
107562306a36Sopenharmony_ci * @bus_address: holds the queue's DMA address
107662306a36Sopenharmony_ci * @cq_idx: completion queue index in array
107762306a36Sopenharmony_ci * @hw_queue_id: the id of the matching H/W queue
107862306a36Sopenharmony_ci * @ci: ci inside the queue
107962306a36Sopenharmony_ci * @pi: pi inside the queue
108062306a36Sopenharmony_ci * @free_slots_cnt: counter of free slots in queue
108162306a36Sopenharmony_ci */
108262306a36Sopenharmony_cistruct hl_cq {
108362306a36Sopenharmony_ci	struct hl_device	*hdev;
108462306a36Sopenharmony_ci	void			*kernel_address;
108562306a36Sopenharmony_ci	dma_addr_t		bus_address;
108662306a36Sopenharmony_ci	u32			cq_idx;
108762306a36Sopenharmony_ci	u32			hw_queue_id;
108862306a36Sopenharmony_ci	u32			ci;
108962306a36Sopenharmony_ci	u32			pi;
109062306a36Sopenharmony_ci	atomic_t		free_slots_cnt;
109162306a36Sopenharmony_ci};
109262306a36Sopenharmony_ci
109362306a36Sopenharmony_cienum hl_user_interrupt_type {
109462306a36Sopenharmony_ci	HL_USR_INTERRUPT_CQ = 0,
109562306a36Sopenharmony_ci	HL_USR_INTERRUPT_DECODER,
109662306a36Sopenharmony_ci	HL_USR_INTERRUPT_TPC,
109762306a36Sopenharmony_ci	HL_USR_INTERRUPT_UNEXPECTED
109862306a36Sopenharmony_ci};
109962306a36Sopenharmony_ci
110062306a36Sopenharmony_ci/**
110162306a36Sopenharmony_ci * struct hl_user_interrupt - holds user interrupt information
110262306a36Sopenharmony_ci * @hdev: pointer to the device structure
110362306a36Sopenharmony_ci * @type: user interrupt type
110462306a36Sopenharmony_ci * @wait_list_head: head to the list of user threads pending on this interrupt
110562306a36Sopenharmony_ci * @wait_list_lock: protects wait_list_head
110662306a36Sopenharmony_ci * @timestamp: last timestamp taken upon interrupt
110762306a36Sopenharmony_ci * @interrupt_id: msix interrupt id
110862306a36Sopenharmony_ci */
110962306a36Sopenharmony_cistruct hl_user_interrupt {
111062306a36Sopenharmony_ci	struct hl_device		*hdev;
111162306a36Sopenharmony_ci	enum hl_user_interrupt_type	type;
111262306a36Sopenharmony_ci	struct list_head		wait_list_head;
111362306a36Sopenharmony_ci	spinlock_t			wait_list_lock;
111462306a36Sopenharmony_ci	ktime_t				timestamp;
111562306a36Sopenharmony_ci	u32				interrupt_id;
111662306a36Sopenharmony_ci};
111762306a36Sopenharmony_ci
111862306a36Sopenharmony_ci/**
111962306a36Sopenharmony_ci * struct timestamp_reg_free_node - holds the timestamp registration free objects node
112062306a36Sopenharmony_ci * @free_objects_node: node in the list free_obj_jobs
112162306a36Sopenharmony_ci * @cq_cb: pointer to cq command buffer to be freed
112262306a36Sopenharmony_ci * @buf: pointer to timestamp buffer to be freed
112362306a36Sopenharmony_ci */
112462306a36Sopenharmony_cistruct timestamp_reg_free_node {
112562306a36Sopenharmony_ci	struct list_head	free_objects_node;
112662306a36Sopenharmony_ci	struct hl_cb		*cq_cb;
112762306a36Sopenharmony_ci	struct hl_mmap_mem_buf	*buf;
112862306a36Sopenharmony_ci};
112962306a36Sopenharmony_ci
113062306a36Sopenharmony_ci/* struct timestamp_reg_work_obj - holds the timestamp registration free objects job
113162306a36Sopenharmony_ci * the job will be to pass over the free_obj_jobs list and put refcount to objects
113262306a36Sopenharmony_ci * in each node of the list
113362306a36Sopenharmony_ci * @free_obj: workqueue object to free timestamp registration node objects
113462306a36Sopenharmony_ci * @hdev: pointer to the device structure
113562306a36Sopenharmony_ci * @free_obj_head: list of free jobs nodes (node type timestamp_reg_free_node)
113662306a36Sopenharmony_ci */
113762306a36Sopenharmony_cistruct timestamp_reg_work_obj {
113862306a36Sopenharmony_ci	struct work_struct	free_obj;
113962306a36Sopenharmony_ci	struct hl_device	*hdev;
114062306a36Sopenharmony_ci	struct list_head	*free_obj_head;
114162306a36Sopenharmony_ci};
114262306a36Sopenharmony_ci
114362306a36Sopenharmony_ci/* struct timestamp_reg_info - holds the timestamp registration related data.
114462306a36Sopenharmony_ci * @buf: pointer to the timestamp buffer which include both user/kernel buffers.
114562306a36Sopenharmony_ci *       relevant only when doing timestamps records registration.
114662306a36Sopenharmony_ci * @cq_cb: pointer to CQ counter CB.
114762306a36Sopenharmony_ci * @timestamp_kernel_addr: timestamp handle address, where to set timestamp
114862306a36Sopenharmony_ci *                         relevant only when doing timestamps records
114962306a36Sopenharmony_ci *                         registration.
115062306a36Sopenharmony_ci * @in_use: indicates if the node already in use. relevant only when doing
115162306a36Sopenharmony_ci *          timestamps records registration, since in this case the driver
115262306a36Sopenharmony_ci *          will have it's own buffer which serve as a records pool instead of
115362306a36Sopenharmony_ci *          allocating records dynamically.
115462306a36Sopenharmony_ci */
115562306a36Sopenharmony_cistruct timestamp_reg_info {
115662306a36Sopenharmony_ci	struct hl_mmap_mem_buf	*buf;
115762306a36Sopenharmony_ci	struct hl_cb		*cq_cb;
115862306a36Sopenharmony_ci	u64			*timestamp_kernel_addr;
115962306a36Sopenharmony_ci	u8			in_use;
116062306a36Sopenharmony_ci};
116162306a36Sopenharmony_ci
116262306a36Sopenharmony_ci/**
116362306a36Sopenharmony_ci * struct hl_user_pending_interrupt - holds a context to a user thread
116462306a36Sopenharmony_ci *                                    pending on an interrupt
116562306a36Sopenharmony_ci * @ts_reg_info: holds the timestamps registration nodes info
116662306a36Sopenharmony_ci * @wait_list_node: node in the list of user threads pending on an interrupt
116762306a36Sopenharmony_ci * @fence: hl fence object for interrupt completion
116862306a36Sopenharmony_ci * @cq_target_value: CQ target value
116962306a36Sopenharmony_ci * @cq_kernel_addr: CQ kernel address, to be used in the cq interrupt
117062306a36Sopenharmony_ci *                  handler for target value comparison
117162306a36Sopenharmony_ci */
117262306a36Sopenharmony_cistruct hl_user_pending_interrupt {
117362306a36Sopenharmony_ci	struct timestamp_reg_info	ts_reg_info;
117462306a36Sopenharmony_ci	struct list_head		wait_list_node;
117562306a36Sopenharmony_ci	struct hl_fence			fence;
117662306a36Sopenharmony_ci	u64				cq_target_value;
117762306a36Sopenharmony_ci	u64				*cq_kernel_addr;
117862306a36Sopenharmony_ci};
117962306a36Sopenharmony_ci
118062306a36Sopenharmony_ci/**
118162306a36Sopenharmony_ci * struct hl_eq - describes the event queue (single one per device)
118262306a36Sopenharmony_ci * @hdev: pointer to the device structure
118362306a36Sopenharmony_ci * @kernel_address: holds the queue's kernel virtual address
118462306a36Sopenharmony_ci * @bus_address: holds the queue's DMA address
118562306a36Sopenharmony_ci * @ci: ci inside the queue
118662306a36Sopenharmony_ci * @prev_eqe_index: the index of the previous event queue entry. The index of
118762306a36Sopenharmony_ci *                  the current entry's index must be +1 of the previous one.
118862306a36Sopenharmony_ci * @check_eqe_index: do we need to check the index of the current entry vs. the
118962306a36Sopenharmony_ci *                   previous one. This is for backward compatibility with older
119062306a36Sopenharmony_ci *                   firmwares
119162306a36Sopenharmony_ci */
119262306a36Sopenharmony_cistruct hl_eq {
119362306a36Sopenharmony_ci	struct hl_device	*hdev;
119462306a36Sopenharmony_ci	void			*kernel_address;
119562306a36Sopenharmony_ci	dma_addr_t		bus_address;
119662306a36Sopenharmony_ci	u32			ci;
119762306a36Sopenharmony_ci	u32			prev_eqe_index;
119862306a36Sopenharmony_ci	bool			check_eqe_index;
119962306a36Sopenharmony_ci};
120062306a36Sopenharmony_ci
120162306a36Sopenharmony_ci/**
120262306a36Sopenharmony_ci * struct hl_dec - describes a decoder sw instance.
120362306a36Sopenharmony_ci * @hdev: pointer to the device structure.
120462306a36Sopenharmony_ci * @abnrm_intr_work: workqueue work item to run when decoder generates an error interrupt.
120562306a36Sopenharmony_ci * @core_id: ID of the decoder.
120662306a36Sopenharmony_ci * @base_addr: base address of the decoder.
120762306a36Sopenharmony_ci */
120862306a36Sopenharmony_cistruct hl_dec {
120962306a36Sopenharmony_ci	struct hl_device	*hdev;
121062306a36Sopenharmony_ci	struct work_struct	abnrm_intr_work;
121162306a36Sopenharmony_ci	u32			core_id;
121262306a36Sopenharmony_ci	u32			base_addr;
121362306a36Sopenharmony_ci};
121462306a36Sopenharmony_ci
121562306a36Sopenharmony_ci/**
121662306a36Sopenharmony_ci * enum hl_asic_type - supported ASIC types.
121762306a36Sopenharmony_ci * @ASIC_INVALID: Invalid ASIC type.
121862306a36Sopenharmony_ci * @ASIC_GOYA: Goya device (HL-1000).
121962306a36Sopenharmony_ci * @ASIC_GAUDI: Gaudi device (HL-2000).
122062306a36Sopenharmony_ci * @ASIC_GAUDI_SEC: Gaudi secured device (HL-2000).
122162306a36Sopenharmony_ci * @ASIC_GAUDI2: Gaudi2 device.
122262306a36Sopenharmony_ci * @ASIC_GAUDI2B: Gaudi2B device.
122362306a36Sopenharmony_ci * @ASIC_GAUDI2C: Gaudi2C device.
122462306a36Sopenharmony_ci */
122562306a36Sopenharmony_cienum hl_asic_type {
122662306a36Sopenharmony_ci	ASIC_INVALID,
122762306a36Sopenharmony_ci	ASIC_GOYA,
122862306a36Sopenharmony_ci	ASIC_GAUDI,
122962306a36Sopenharmony_ci	ASIC_GAUDI_SEC,
123062306a36Sopenharmony_ci	ASIC_GAUDI2,
123162306a36Sopenharmony_ci	ASIC_GAUDI2B,
123262306a36Sopenharmony_ci	ASIC_GAUDI2C,
123362306a36Sopenharmony_ci};
123462306a36Sopenharmony_ci
123562306a36Sopenharmony_cistruct hl_cs_parser;
123662306a36Sopenharmony_ci
123762306a36Sopenharmony_ci/**
123862306a36Sopenharmony_ci * enum hl_pm_mng_profile - power management profile.
123962306a36Sopenharmony_ci * @PM_AUTO: internal clock is set by the Linux driver.
124062306a36Sopenharmony_ci * @PM_MANUAL: internal clock is set by the user.
124162306a36Sopenharmony_ci * @PM_LAST: last power management type.
124262306a36Sopenharmony_ci */
124362306a36Sopenharmony_cienum hl_pm_mng_profile {
124462306a36Sopenharmony_ci	PM_AUTO = 1,
124562306a36Sopenharmony_ci	PM_MANUAL,
124662306a36Sopenharmony_ci	PM_LAST
124762306a36Sopenharmony_ci};
124862306a36Sopenharmony_ci
124962306a36Sopenharmony_ci/**
125062306a36Sopenharmony_ci * enum hl_pll_frequency - PLL frequency.
125162306a36Sopenharmony_ci * @PLL_HIGH: high frequency.
125262306a36Sopenharmony_ci * @PLL_LOW: low frequency.
125362306a36Sopenharmony_ci * @PLL_LAST: last frequency values that were configured by the user.
125462306a36Sopenharmony_ci */
125562306a36Sopenharmony_cienum hl_pll_frequency {
125662306a36Sopenharmony_ci	PLL_HIGH = 1,
125762306a36Sopenharmony_ci	PLL_LOW,
125862306a36Sopenharmony_ci	PLL_LAST
125962306a36Sopenharmony_ci};
126062306a36Sopenharmony_ci
126162306a36Sopenharmony_ci#define PLL_REF_CLK 50
126262306a36Sopenharmony_ci
126362306a36Sopenharmony_cienum div_select_defs {
126462306a36Sopenharmony_ci	DIV_SEL_REF_CLK = 0,
126562306a36Sopenharmony_ci	DIV_SEL_PLL_CLK = 1,
126662306a36Sopenharmony_ci	DIV_SEL_DIVIDED_REF = 2,
126762306a36Sopenharmony_ci	DIV_SEL_DIVIDED_PLL = 3,
126862306a36Sopenharmony_ci};
126962306a36Sopenharmony_ci
127062306a36Sopenharmony_cienum debugfs_access_type {
127162306a36Sopenharmony_ci	DEBUGFS_READ8,
127262306a36Sopenharmony_ci	DEBUGFS_WRITE8,
127362306a36Sopenharmony_ci	DEBUGFS_READ32,
127462306a36Sopenharmony_ci	DEBUGFS_WRITE32,
127562306a36Sopenharmony_ci	DEBUGFS_READ64,
127662306a36Sopenharmony_ci	DEBUGFS_WRITE64,
127762306a36Sopenharmony_ci};
127862306a36Sopenharmony_ci
127962306a36Sopenharmony_cienum pci_region {
128062306a36Sopenharmony_ci	PCI_REGION_CFG,
128162306a36Sopenharmony_ci	PCI_REGION_SRAM,
128262306a36Sopenharmony_ci	PCI_REGION_DRAM,
128362306a36Sopenharmony_ci	PCI_REGION_SP_SRAM,
128462306a36Sopenharmony_ci	PCI_REGION_NUMBER,
128562306a36Sopenharmony_ci};
128662306a36Sopenharmony_ci
128762306a36Sopenharmony_ci/**
128862306a36Sopenharmony_ci * struct pci_mem_region - describe memory region in a PCI bar
128962306a36Sopenharmony_ci * @region_base: region base address
129062306a36Sopenharmony_ci * @region_size: region size
129162306a36Sopenharmony_ci * @bar_size: size of the BAR
129262306a36Sopenharmony_ci * @offset_in_bar: region offset into the bar
129362306a36Sopenharmony_ci * @bar_id: bar ID of the region
129462306a36Sopenharmony_ci * @used: if used 1, otherwise 0
129562306a36Sopenharmony_ci */
129662306a36Sopenharmony_cistruct pci_mem_region {
129762306a36Sopenharmony_ci	u64 region_base;
129862306a36Sopenharmony_ci	u64 region_size;
129962306a36Sopenharmony_ci	u64 bar_size;
130062306a36Sopenharmony_ci	u64 offset_in_bar;
130162306a36Sopenharmony_ci	u8 bar_id;
130262306a36Sopenharmony_ci	u8 used;
130362306a36Sopenharmony_ci};
130462306a36Sopenharmony_ci
130562306a36Sopenharmony_ci/**
130662306a36Sopenharmony_ci * struct static_fw_load_mgr - static FW load manager
130762306a36Sopenharmony_ci * @preboot_version_max_off: max offset to preboot version
130862306a36Sopenharmony_ci * @boot_fit_version_max_off: max offset to boot fit version
130962306a36Sopenharmony_ci * @kmd_msg_to_cpu_reg: register address for KDM->CPU messages
131062306a36Sopenharmony_ci * @cpu_cmd_status_to_host_reg: register address for CPU command status response
131162306a36Sopenharmony_ci * @cpu_boot_status_reg: boot status register
131262306a36Sopenharmony_ci * @cpu_boot_dev_status0_reg: boot device status register 0
131362306a36Sopenharmony_ci * @cpu_boot_dev_status1_reg: boot device status register 1
131462306a36Sopenharmony_ci * @boot_err0_reg: boot error register 0
131562306a36Sopenharmony_ci * @boot_err1_reg: boot error register 1
131662306a36Sopenharmony_ci * @preboot_version_offset_reg: SRAM offset to preboot version register
131762306a36Sopenharmony_ci * @boot_fit_version_offset_reg: SRAM offset to boot fit version register
131862306a36Sopenharmony_ci * @sram_offset_mask: mask for getting offset into the SRAM
131962306a36Sopenharmony_ci * @cpu_reset_wait_msec: used when setting WFE via kmd_msg_to_cpu_reg
132062306a36Sopenharmony_ci */
132162306a36Sopenharmony_cistruct static_fw_load_mgr {
132262306a36Sopenharmony_ci	u64 preboot_version_max_off;
132362306a36Sopenharmony_ci	u64 boot_fit_version_max_off;
132462306a36Sopenharmony_ci	u32 kmd_msg_to_cpu_reg;
132562306a36Sopenharmony_ci	u32 cpu_cmd_status_to_host_reg;
132662306a36Sopenharmony_ci	u32 cpu_boot_status_reg;
132762306a36Sopenharmony_ci	u32 cpu_boot_dev_status0_reg;
132862306a36Sopenharmony_ci	u32 cpu_boot_dev_status1_reg;
132962306a36Sopenharmony_ci	u32 boot_err0_reg;
133062306a36Sopenharmony_ci	u32 boot_err1_reg;
133162306a36Sopenharmony_ci	u32 preboot_version_offset_reg;
133262306a36Sopenharmony_ci	u32 boot_fit_version_offset_reg;
133362306a36Sopenharmony_ci	u32 sram_offset_mask;
133462306a36Sopenharmony_ci	u32 cpu_reset_wait_msec;
133562306a36Sopenharmony_ci};
133662306a36Sopenharmony_ci
133762306a36Sopenharmony_ci/**
133862306a36Sopenharmony_ci * struct fw_response - FW response to LKD command
133962306a36Sopenharmony_ci * @ram_offset: descriptor offset into the RAM
134062306a36Sopenharmony_ci * @ram_type: RAM type containing the descriptor (SRAM/DRAM)
134162306a36Sopenharmony_ci * @status: command status
134262306a36Sopenharmony_ci */
134362306a36Sopenharmony_cistruct fw_response {
134462306a36Sopenharmony_ci	u32 ram_offset;
134562306a36Sopenharmony_ci	u8 ram_type;
134662306a36Sopenharmony_ci	u8 status;
134762306a36Sopenharmony_ci};
134862306a36Sopenharmony_ci
134962306a36Sopenharmony_ci/**
135062306a36Sopenharmony_ci * struct dynamic_fw_load_mgr - dynamic FW load manager
135162306a36Sopenharmony_ci * @response: FW to LKD response
135262306a36Sopenharmony_ci * @comm_desc: the communication descriptor with FW
135362306a36Sopenharmony_ci * @image_region: region to copy the FW image to
135462306a36Sopenharmony_ci * @fw_image_size: size of FW image to load
135562306a36Sopenharmony_ci * @wait_for_bl_timeout: timeout for waiting for boot loader to respond
135662306a36Sopenharmony_ci * @fw_desc_valid: true if FW descriptor has been validated and hence the data can be used
135762306a36Sopenharmony_ci */
135862306a36Sopenharmony_cistruct dynamic_fw_load_mgr {
135962306a36Sopenharmony_ci	struct fw_response response;
136062306a36Sopenharmony_ci	struct lkd_fw_comms_desc comm_desc;
136162306a36Sopenharmony_ci	struct pci_mem_region *image_region;
136262306a36Sopenharmony_ci	size_t fw_image_size;
136362306a36Sopenharmony_ci	u32 wait_for_bl_timeout;
136462306a36Sopenharmony_ci	bool fw_desc_valid;
136562306a36Sopenharmony_ci};
136662306a36Sopenharmony_ci
136762306a36Sopenharmony_ci/**
136862306a36Sopenharmony_ci * struct pre_fw_load_props - needed properties for pre-FW load
136962306a36Sopenharmony_ci * @cpu_boot_status_reg: cpu_boot_status register address
137062306a36Sopenharmony_ci * @sts_boot_dev_sts0_reg: sts_boot_dev_sts0 register address
137162306a36Sopenharmony_ci * @sts_boot_dev_sts1_reg: sts_boot_dev_sts1 register address
137262306a36Sopenharmony_ci * @boot_err0_reg: boot_err0 register address
137362306a36Sopenharmony_ci * @boot_err1_reg: boot_err1 register address
137462306a36Sopenharmony_ci * @wait_for_preboot_timeout: timeout to poll for preboot ready
137562306a36Sopenharmony_ci */
137662306a36Sopenharmony_cistruct pre_fw_load_props {
137762306a36Sopenharmony_ci	u32 cpu_boot_status_reg;
137862306a36Sopenharmony_ci	u32 sts_boot_dev_sts0_reg;
137962306a36Sopenharmony_ci	u32 sts_boot_dev_sts1_reg;
138062306a36Sopenharmony_ci	u32 boot_err0_reg;
138162306a36Sopenharmony_ci	u32 boot_err1_reg;
138262306a36Sopenharmony_ci	u32 wait_for_preboot_timeout;
138362306a36Sopenharmony_ci};
138462306a36Sopenharmony_ci
138562306a36Sopenharmony_ci/**
138662306a36Sopenharmony_ci * struct fw_image_props - properties of FW image
138762306a36Sopenharmony_ci * @image_name: name of the image
138862306a36Sopenharmony_ci * @src_off: offset in src FW to copy from
138962306a36Sopenharmony_ci * @copy_size: amount of bytes to copy (0 to copy the whole binary)
139062306a36Sopenharmony_ci */
139162306a36Sopenharmony_cistruct fw_image_props {
139262306a36Sopenharmony_ci	char *image_name;
139362306a36Sopenharmony_ci	u32 src_off;
139462306a36Sopenharmony_ci	u32 copy_size;
139562306a36Sopenharmony_ci};
139662306a36Sopenharmony_ci
139762306a36Sopenharmony_ci/**
139862306a36Sopenharmony_ci * struct fw_load_mgr - manager FW loading process
139962306a36Sopenharmony_ci * @dynamic_loader: specific structure for dynamic load
140062306a36Sopenharmony_ci * @static_loader: specific structure for static load
140162306a36Sopenharmony_ci * @pre_fw_load_props: parameter for pre FW load
140262306a36Sopenharmony_ci * @boot_fit_img: boot fit image properties
140362306a36Sopenharmony_ci * @linux_img: linux image properties
140462306a36Sopenharmony_ci * @cpu_timeout: CPU response timeout in usec
140562306a36Sopenharmony_ci * @boot_fit_timeout: Boot fit load timeout in usec
140662306a36Sopenharmony_ci * @skip_bmc: should BMC be skipped
140762306a36Sopenharmony_ci * @sram_bar_id: SRAM bar ID
140862306a36Sopenharmony_ci * @dram_bar_id: DRAM bar ID
140962306a36Sopenharmony_ci * @fw_comp_loaded: bitmask of loaded FW components. set bit meaning loaded
141062306a36Sopenharmony_ci *                  component. values are set according to enum hl_fw_types.
141162306a36Sopenharmony_ci */
141262306a36Sopenharmony_cistruct fw_load_mgr {
141362306a36Sopenharmony_ci	union {
141462306a36Sopenharmony_ci		struct dynamic_fw_load_mgr dynamic_loader;
141562306a36Sopenharmony_ci		struct static_fw_load_mgr static_loader;
141662306a36Sopenharmony_ci	};
141762306a36Sopenharmony_ci	struct pre_fw_load_props pre_fw_load;
141862306a36Sopenharmony_ci	struct fw_image_props boot_fit_img;
141962306a36Sopenharmony_ci	struct fw_image_props linux_img;
142062306a36Sopenharmony_ci	u32 cpu_timeout;
142162306a36Sopenharmony_ci	u32 boot_fit_timeout;
142262306a36Sopenharmony_ci	u8 skip_bmc;
142362306a36Sopenharmony_ci	u8 sram_bar_id;
142462306a36Sopenharmony_ci	u8 dram_bar_id;
142562306a36Sopenharmony_ci	u8 fw_comp_loaded;
142662306a36Sopenharmony_ci};
142762306a36Sopenharmony_ci
142862306a36Sopenharmony_cistruct hl_cs;
142962306a36Sopenharmony_ci
143062306a36Sopenharmony_ci/**
143162306a36Sopenharmony_ci * struct engines_data - asic engines data
143262306a36Sopenharmony_ci * @buf: buffer for engines data in ascii
143362306a36Sopenharmony_ci * @actual_size: actual size of data that was written by the driver to the allocated buffer
143462306a36Sopenharmony_ci * @allocated_buf_size: total size of allocated buffer
143562306a36Sopenharmony_ci */
143662306a36Sopenharmony_cistruct engines_data {
143762306a36Sopenharmony_ci	char *buf;
143862306a36Sopenharmony_ci	int actual_size;
143962306a36Sopenharmony_ci	u32 allocated_buf_size;
144062306a36Sopenharmony_ci};
144162306a36Sopenharmony_ci
144262306a36Sopenharmony_ci/**
144362306a36Sopenharmony_ci * struct hl_asic_funcs - ASIC specific functions that are can be called from
144462306a36Sopenharmony_ci *                        common code.
144562306a36Sopenharmony_ci * @early_init: sets up early driver state (pre sw_init), doesn't configure H/W.
144662306a36Sopenharmony_ci * @early_fini: tears down what was done in early_init.
144762306a36Sopenharmony_ci * @late_init: sets up late driver/hw state (post hw_init) - Optional.
144862306a36Sopenharmony_ci * @late_fini: tears down what was done in late_init (pre hw_fini) - Optional.
144962306a36Sopenharmony_ci * @sw_init: sets up driver state, does not configure H/W.
145062306a36Sopenharmony_ci * @sw_fini: tears down driver state, does not configure H/W.
145162306a36Sopenharmony_ci * @hw_init: sets up the H/W state.
145262306a36Sopenharmony_ci * @hw_fini: tears down the H/W state.
145362306a36Sopenharmony_ci * @halt_engines: halt engines, needed for reset sequence. This also disables
145462306a36Sopenharmony_ci *                interrupts from the device. Should be called before
145562306a36Sopenharmony_ci *                hw_fini and before CS rollback.
145662306a36Sopenharmony_ci * @suspend: handles IP specific H/W or SW changes for suspend.
145762306a36Sopenharmony_ci * @resume: handles IP specific H/W or SW changes for resume.
145862306a36Sopenharmony_ci * @mmap: maps a memory.
145962306a36Sopenharmony_ci * @ring_doorbell: increment PI on a given QMAN.
146062306a36Sopenharmony_ci * @pqe_write: Write the PQ entry to the PQ. This is ASIC-specific
146162306a36Sopenharmony_ci *             function because the PQs are located in different memory areas
146262306a36Sopenharmony_ci *             per ASIC (SRAM, DRAM, Host memory) and therefore, the method of
146362306a36Sopenharmony_ci *             writing the PQE must match the destination memory area
146462306a36Sopenharmony_ci *             properties.
146562306a36Sopenharmony_ci * @asic_dma_alloc_coherent: Allocate coherent DMA memory by calling
146662306a36Sopenharmony_ci *                           dma_alloc_coherent(). This is ASIC function because
146762306a36Sopenharmony_ci *                           its implementation is not trivial when the driver
146862306a36Sopenharmony_ci *                           is loaded in simulation mode (not upstreamed).
146962306a36Sopenharmony_ci * @asic_dma_free_coherent:  Free coherent DMA memory by calling
147062306a36Sopenharmony_ci *                           dma_free_coherent(). This is ASIC function because
147162306a36Sopenharmony_ci *                           its implementation is not trivial when the driver
147262306a36Sopenharmony_ci *                           is loaded in simulation mode (not upstreamed).
147362306a36Sopenharmony_ci * @scrub_device_mem: Scrub the entire SRAM and DRAM.
147462306a36Sopenharmony_ci * @scrub_device_dram: Scrub the dram memory of the device.
147562306a36Sopenharmony_ci * @get_int_queue_base: get the internal queue base address.
147662306a36Sopenharmony_ci * @test_queues: run simple test on all queues for sanity check.
147762306a36Sopenharmony_ci * @asic_dma_pool_zalloc: small DMA allocation of coherent memory from DMA pool.
147862306a36Sopenharmony_ci *                        size of allocation is HL_DMA_POOL_BLK_SIZE.
147962306a36Sopenharmony_ci * @asic_dma_pool_free: free small DMA allocation from pool.
148062306a36Sopenharmony_ci * @cpu_accessible_dma_pool_alloc: allocate CPU PQ packet from DMA pool.
148162306a36Sopenharmony_ci * @cpu_accessible_dma_pool_free: free CPU PQ packet from DMA pool.
148262306a36Sopenharmony_ci * @asic_dma_unmap_single: unmap a single DMA buffer
148362306a36Sopenharmony_ci * @asic_dma_map_single: map a single buffer to a DMA
148462306a36Sopenharmony_ci * @hl_dma_unmap_sgtable: DMA unmap scatter-gather table.
148562306a36Sopenharmony_ci * @cs_parser: parse Command Submission.
148662306a36Sopenharmony_ci * @asic_dma_map_sgtable: DMA map scatter-gather table.
148762306a36Sopenharmony_ci * @add_end_of_cb_packets: Add packets to the end of CB, if device requires it.
148862306a36Sopenharmony_ci * @update_eq_ci: update event queue CI.
148962306a36Sopenharmony_ci * @context_switch: called upon ASID context switch.
149062306a36Sopenharmony_ci * @restore_phase_topology: clear all SOBs amd MONs.
149162306a36Sopenharmony_ci * @debugfs_read_dma: debug interface for reading up to 2MB from the device's
149262306a36Sopenharmony_ci *                    internal memory via DMA engine.
149362306a36Sopenharmony_ci * @add_device_attr: add ASIC specific device attributes.
149462306a36Sopenharmony_ci * @handle_eqe: handle event queue entry (IRQ) from CPU-CP.
149562306a36Sopenharmony_ci * @get_events_stat: retrieve event queue entries histogram.
149662306a36Sopenharmony_ci * @read_pte: read MMU page table entry from DRAM.
149762306a36Sopenharmony_ci * @write_pte: write MMU page table entry to DRAM.
149862306a36Sopenharmony_ci * @mmu_invalidate_cache: flush MMU STLB host/DRAM cache, either with soft
149962306a36Sopenharmony_ci *                        (L1 only) or hard (L0 & L1) flush.
150062306a36Sopenharmony_ci * @mmu_invalidate_cache_range: flush specific MMU STLB cache lines with ASID-VA-size mask.
150162306a36Sopenharmony_ci * @mmu_prefetch_cache_range: pre-fetch specific MMU STLB cache lines with ASID-VA-size mask.
150262306a36Sopenharmony_ci * @send_heartbeat: send is-alive packet to CPU-CP and verify response.
150362306a36Sopenharmony_ci * @debug_coresight: perform certain actions on Coresight for debugging.
150462306a36Sopenharmony_ci * @is_device_idle: return true if device is idle, false otherwise.
150562306a36Sopenharmony_ci * @compute_reset_late_init: perform certain actions needed after a compute reset
150662306a36Sopenharmony_ci * @hw_queues_lock: acquire H/W queues lock.
150762306a36Sopenharmony_ci * @hw_queues_unlock: release H/W queues lock.
150862306a36Sopenharmony_ci * @get_pci_id: retrieve PCI ID.
150962306a36Sopenharmony_ci * @get_eeprom_data: retrieve EEPROM data from F/W.
151062306a36Sopenharmony_ci * @get_monitor_dump: retrieve monitor registers dump from F/W.
151162306a36Sopenharmony_ci * @send_cpu_message: send message to F/W. If the message is timedout, the
151262306a36Sopenharmony_ci *                    driver will eventually reset the device. The timeout can
151362306a36Sopenharmony_ci *                    be determined by the calling function or it can be 0 and
151462306a36Sopenharmony_ci *                    then the timeout is the default timeout for the specific
151562306a36Sopenharmony_ci *                    ASIC
151662306a36Sopenharmony_ci * @get_hw_state: retrieve the H/W state
151762306a36Sopenharmony_ci * @pci_bars_map: Map PCI BARs.
151862306a36Sopenharmony_ci * @init_iatu: Initialize the iATU unit inside the PCI controller.
151962306a36Sopenharmony_ci * @rreg: Read a register. Needed for simulator support.
152062306a36Sopenharmony_ci * @wreg: Write a register. Needed for simulator support.
152162306a36Sopenharmony_ci * @halt_coresight: stop the ETF and ETR traces.
152262306a36Sopenharmony_ci * @ctx_init: context dependent initialization.
152362306a36Sopenharmony_ci * @ctx_fini: context dependent cleanup.
152462306a36Sopenharmony_ci * @pre_schedule_cs: Perform pre-CS-scheduling operations.
152562306a36Sopenharmony_ci * @get_queue_id_for_cq: Get the H/W queue id related to the given CQ index.
152662306a36Sopenharmony_ci * @load_firmware_to_device: load the firmware to the device's memory
152762306a36Sopenharmony_ci * @load_boot_fit_to_device: load boot fit to device's memory
152862306a36Sopenharmony_ci * @get_signal_cb_size: Get signal CB size.
152962306a36Sopenharmony_ci * @get_wait_cb_size: Get wait CB size.
153062306a36Sopenharmony_ci * @gen_signal_cb: Generate a signal CB.
153162306a36Sopenharmony_ci * @gen_wait_cb: Generate a wait CB.
153262306a36Sopenharmony_ci * @reset_sob: Reset a SOB.
153362306a36Sopenharmony_ci * @reset_sob_group: Reset SOB group
153462306a36Sopenharmony_ci * @get_device_time: Get the device time.
153562306a36Sopenharmony_ci * @pb_print_security_errors: print security errors according block and cause
153662306a36Sopenharmony_ci * @collective_wait_init_cs: Generate collective master/slave packets
153762306a36Sopenharmony_ci *                           and place them in the relevant cs jobs
153862306a36Sopenharmony_ci * @collective_wait_create_jobs: allocate collective wait cs jobs
153962306a36Sopenharmony_ci * @get_dec_base_addr: get the base address of a given decoder.
154062306a36Sopenharmony_ci * @scramble_addr: Routine to scramble the address prior of mapping it
154162306a36Sopenharmony_ci *                 in the MMU.
154262306a36Sopenharmony_ci * @descramble_addr: Routine to de-scramble the address prior of
154362306a36Sopenharmony_ci *                   showing it to users.
154462306a36Sopenharmony_ci * @ack_protection_bits_errors: ack and dump all security violations
154562306a36Sopenharmony_ci * @get_hw_block_id: retrieve a HW block id to be used by the user to mmap it.
154662306a36Sopenharmony_ci *                   also returns the size of the block if caller supplies
154762306a36Sopenharmony_ci *                   a valid pointer for it
154862306a36Sopenharmony_ci * @hw_block_mmap: mmap a HW block with a given id.
154962306a36Sopenharmony_ci * @enable_events_from_fw: send interrupt to firmware to notify them the
155062306a36Sopenharmony_ci *                         driver is ready to receive asynchronous events. This
155162306a36Sopenharmony_ci *                         function should be called during the first init and
155262306a36Sopenharmony_ci *                         after every hard-reset of the device
155362306a36Sopenharmony_ci * @ack_mmu_errors: check and ack mmu errors, page fault, access violation.
155462306a36Sopenharmony_ci * @get_msi_info: Retrieve asic-specific MSI ID of the f/w async event
155562306a36Sopenharmony_ci * @map_pll_idx_to_fw_idx: convert driver specific per asic PLL index to
155662306a36Sopenharmony_ci *                         generic f/w compatible PLL Indexes
155762306a36Sopenharmony_ci * @init_firmware_preload_params: initialize pre FW-load parameters.
155862306a36Sopenharmony_ci * @init_firmware_loader: initialize data for FW loader.
155962306a36Sopenharmony_ci * @init_cpu_scrambler_dram: Enable CPU specific DRAM scrambling
156062306a36Sopenharmony_ci * @state_dump_init: initialize constants required for state dump
156162306a36Sopenharmony_ci * @get_sob_addr: get SOB base address offset.
156262306a36Sopenharmony_ci * @set_pci_memory_regions: setting properties of PCI memory regions
156362306a36Sopenharmony_ci * @get_stream_master_qid_arr: get pointer to stream masters QID array
156462306a36Sopenharmony_ci * @check_if_razwi_happened: check if there was a razwi due to RR violation.
156562306a36Sopenharmony_ci * @access_dev_mem: access device memory
156662306a36Sopenharmony_ci * @set_dram_bar_base: set the base of the DRAM BAR
156762306a36Sopenharmony_ci * @set_engine_cores: set a config command to engine cores
156862306a36Sopenharmony_ci * @set_engines: set a config command to user engines
156962306a36Sopenharmony_ci * @send_device_activity: indication to FW about device availability
157062306a36Sopenharmony_ci * @set_dram_properties: set DRAM related properties.
157162306a36Sopenharmony_ci * @set_binning_masks: set binning/enable masks for all relevant components.
157262306a36Sopenharmony_ci */
157362306a36Sopenharmony_cistruct hl_asic_funcs {
157462306a36Sopenharmony_ci	int (*early_init)(struct hl_device *hdev);
157562306a36Sopenharmony_ci	int (*early_fini)(struct hl_device *hdev);
157662306a36Sopenharmony_ci	int (*late_init)(struct hl_device *hdev);
157762306a36Sopenharmony_ci	void (*late_fini)(struct hl_device *hdev);
157862306a36Sopenharmony_ci	int (*sw_init)(struct hl_device *hdev);
157962306a36Sopenharmony_ci	int (*sw_fini)(struct hl_device *hdev);
158062306a36Sopenharmony_ci	int (*hw_init)(struct hl_device *hdev);
158162306a36Sopenharmony_ci	int (*hw_fini)(struct hl_device *hdev, bool hard_reset, bool fw_reset);
158262306a36Sopenharmony_ci	void (*halt_engines)(struct hl_device *hdev, bool hard_reset, bool fw_reset);
158362306a36Sopenharmony_ci	int (*suspend)(struct hl_device *hdev);
158462306a36Sopenharmony_ci	int (*resume)(struct hl_device *hdev);
158562306a36Sopenharmony_ci	int (*mmap)(struct hl_device *hdev, struct vm_area_struct *vma,
158662306a36Sopenharmony_ci			void *cpu_addr, dma_addr_t dma_addr, size_t size);
158762306a36Sopenharmony_ci	void (*ring_doorbell)(struct hl_device *hdev, u32 hw_queue_id, u32 pi);
158862306a36Sopenharmony_ci	void (*pqe_write)(struct hl_device *hdev, __le64 *pqe,
158962306a36Sopenharmony_ci			struct hl_bd *bd);
159062306a36Sopenharmony_ci	void* (*asic_dma_alloc_coherent)(struct hl_device *hdev, size_t size,
159162306a36Sopenharmony_ci					dma_addr_t *dma_handle, gfp_t flag);
159262306a36Sopenharmony_ci	void (*asic_dma_free_coherent)(struct hl_device *hdev, size_t size,
159362306a36Sopenharmony_ci					void *cpu_addr, dma_addr_t dma_handle);
159462306a36Sopenharmony_ci	int (*scrub_device_mem)(struct hl_device *hdev);
159562306a36Sopenharmony_ci	int (*scrub_device_dram)(struct hl_device *hdev, u64 val);
159662306a36Sopenharmony_ci	void* (*get_int_queue_base)(struct hl_device *hdev, u32 queue_id,
159762306a36Sopenharmony_ci				dma_addr_t *dma_handle, u16 *queue_len);
159862306a36Sopenharmony_ci	int (*test_queues)(struct hl_device *hdev);
159962306a36Sopenharmony_ci	void* (*asic_dma_pool_zalloc)(struct hl_device *hdev, size_t size,
160062306a36Sopenharmony_ci				gfp_t mem_flags, dma_addr_t *dma_handle);
160162306a36Sopenharmony_ci	void (*asic_dma_pool_free)(struct hl_device *hdev, void *vaddr,
160262306a36Sopenharmony_ci				dma_addr_t dma_addr);
160362306a36Sopenharmony_ci	void* (*cpu_accessible_dma_pool_alloc)(struct hl_device *hdev,
160462306a36Sopenharmony_ci				size_t size, dma_addr_t *dma_handle);
160562306a36Sopenharmony_ci	void (*cpu_accessible_dma_pool_free)(struct hl_device *hdev,
160662306a36Sopenharmony_ci				size_t size, void *vaddr);
160762306a36Sopenharmony_ci	void (*asic_dma_unmap_single)(struct hl_device *hdev,
160862306a36Sopenharmony_ci				dma_addr_t dma_addr, int len,
160962306a36Sopenharmony_ci				enum dma_data_direction dir);
161062306a36Sopenharmony_ci	dma_addr_t (*asic_dma_map_single)(struct hl_device *hdev,
161162306a36Sopenharmony_ci				void *addr, int len,
161262306a36Sopenharmony_ci				enum dma_data_direction dir);
161362306a36Sopenharmony_ci	void (*hl_dma_unmap_sgtable)(struct hl_device *hdev,
161462306a36Sopenharmony_ci				struct sg_table *sgt,
161562306a36Sopenharmony_ci				enum dma_data_direction dir);
161662306a36Sopenharmony_ci	int (*cs_parser)(struct hl_device *hdev, struct hl_cs_parser *parser);
161762306a36Sopenharmony_ci	int (*asic_dma_map_sgtable)(struct hl_device *hdev, struct sg_table *sgt,
161862306a36Sopenharmony_ci				enum dma_data_direction dir);
161962306a36Sopenharmony_ci	void (*add_end_of_cb_packets)(struct hl_device *hdev,
162062306a36Sopenharmony_ci					void *kernel_address, u32 len,
162162306a36Sopenharmony_ci					u32 original_len,
162262306a36Sopenharmony_ci					u64 cq_addr, u32 cq_val, u32 msix_num,
162362306a36Sopenharmony_ci					bool eb);
162462306a36Sopenharmony_ci	void (*update_eq_ci)(struct hl_device *hdev, u32 val);
162562306a36Sopenharmony_ci	int (*context_switch)(struct hl_device *hdev, u32 asid);
162662306a36Sopenharmony_ci	void (*restore_phase_topology)(struct hl_device *hdev);
162762306a36Sopenharmony_ci	int (*debugfs_read_dma)(struct hl_device *hdev, u64 addr, u32 size,
162862306a36Sopenharmony_ci				void *blob_addr);
162962306a36Sopenharmony_ci	void (*add_device_attr)(struct hl_device *hdev, struct attribute_group *dev_clk_attr_grp,
163062306a36Sopenharmony_ci				struct attribute_group *dev_vrm_attr_grp);
163162306a36Sopenharmony_ci	void (*handle_eqe)(struct hl_device *hdev,
163262306a36Sopenharmony_ci				struct hl_eq_entry *eq_entry);
163362306a36Sopenharmony_ci	void* (*get_events_stat)(struct hl_device *hdev, bool aggregate,
163462306a36Sopenharmony_ci				u32 *size);
163562306a36Sopenharmony_ci	u64 (*read_pte)(struct hl_device *hdev, u64 addr);
163662306a36Sopenharmony_ci	void (*write_pte)(struct hl_device *hdev, u64 addr, u64 val);
163762306a36Sopenharmony_ci	int (*mmu_invalidate_cache)(struct hl_device *hdev, bool is_hard,
163862306a36Sopenharmony_ci					u32 flags);
163962306a36Sopenharmony_ci	int (*mmu_invalidate_cache_range)(struct hl_device *hdev, bool is_hard,
164062306a36Sopenharmony_ci				u32 flags, u32 asid, u64 va, u64 size);
164162306a36Sopenharmony_ci	int (*mmu_prefetch_cache_range)(struct hl_ctx *ctx, u32 flags, u32 asid, u64 va, u64 size);
164262306a36Sopenharmony_ci	int (*send_heartbeat)(struct hl_device *hdev);
164362306a36Sopenharmony_ci	int (*debug_coresight)(struct hl_device *hdev, struct hl_ctx *ctx, void *data);
164462306a36Sopenharmony_ci	bool (*is_device_idle)(struct hl_device *hdev, u64 *mask_arr, u8 mask_len,
164562306a36Sopenharmony_ci				struct engines_data *e);
164662306a36Sopenharmony_ci	int (*compute_reset_late_init)(struct hl_device *hdev);
164762306a36Sopenharmony_ci	void (*hw_queues_lock)(struct hl_device *hdev);
164862306a36Sopenharmony_ci	void (*hw_queues_unlock)(struct hl_device *hdev);
164962306a36Sopenharmony_ci	u32 (*get_pci_id)(struct hl_device *hdev);
165062306a36Sopenharmony_ci	int (*get_eeprom_data)(struct hl_device *hdev, void *data, size_t max_size);
165162306a36Sopenharmony_ci	int (*get_monitor_dump)(struct hl_device *hdev, void *data);
165262306a36Sopenharmony_ci	int (*send_cpu_message)(struct hl_device *hdev, u32 *msg,
165362306a36Sopenharmony_ci				u16 len, u32 timeout, u64 *result);
165462306a36Sopenharmony_ci	int (*pci_bars_map)(struct hl_device *hdev);
165562306a36Sopenharmony_ci	int (*init_iatu)(struct hl_device *hdev);
165662306a36Sopenharmony_ci	u32 (*rreg)(struct hl_device *hdev, u32 reg);
165762306a36Sopenharmony_ci	void (*wreg)(struct hl_device *hdev, u32 reg, u32 val);
165862306a36Sopenharmony_ci	void (*halt_coresight)(struct hl_device *hdev, struct hl_ctx *ctx);
165962306a36Sopenharmony_ci	int (*ctx_init)(struct hl_ctx *ctx);
166062306a36Sopenharmony_ci	void (*ctx_fini)(struct hl_ctx *ctx);
166162306a36Sopenharmony_ci	int (*pre_schedule_cs)(struct hl_cs *cs);
166262306a36Sopenharmony_ci	u32 (*get_queue_id_for_cq)(struct hl_device *hdev, u32 cq_idx);
166362306a36Sopenharmony_ci	int (*load_firmware_to_device)(struct hl_device *hdev);
166462306a36Sopenharmony_ci	int (*load_boot_fit_to_device)(struct hl_device *hdev);
166562306a36Sopenharmony_ci	u32 (*get_signal_cb_size)(struct hl_device *hdev);
166662306a36Sopenharmony_ci	u32 (*get_wait_cb_size)(struct hl_device *hdev);
166762306a36Sopenharmony_ci	u32 (*gen_signal_cb)(struct hl_device *hdev, void *data, u16 sob_id,
166862306a36Sopenharmony_ci			u32 size, bool eb);
166962306a36Sopenharmony_ci	u32 (*gen_wait_cb)(struct hl_device *hdev,
167062306a36Sopenharmony_ci			struct hl_gen_wait_properties *prop);
167162306a36Sopenharmony_ci	void (*reset_sob)(struct hl_device *hdev, void *data);
167262306a36Sopenharmony_ci	void (*reset_sob_group)(struct hl_device *hdev, u16 sob_group);
167362306a36Sopenharmony_ci	u64 (*get_device_time)(struct hl_device *hdev);
167462306a36Sopenharmony_ci	void (*pb_print_security_errors)(struct hl_device *hdev,
167562306a36Sopenharmony_ci			u32 block_addr, u32 cause, u32 offended_addr);
167662306a36Sopenharmony_ci	int (*collective_wait_init_cs)(struct hl_cs *cs);
167762306a36Sopenharmony_ci	int (*collective_wait_create_jobs)(struct hl_device *hdev,
167862306a36Sopenharmony_ci			struct hl_ctx *ctx, struct hl_cs *cs,
167962306a36Sopenharmony_ci			u32 wait_queue_id, u32 collective_engine_id,
168062306a36Sopenharmony_ci			u32 encaps_signal_offset);
168162306a36Sopenharmony_ci	u32 (*get_dec_base_addr)(struct hl_device *hdev, u32 core_id);
168262306a36Sopenharmony_ci	u64 (*scramble_addr)(struct hl_device *hdev, u64 addr);
168362306a36Sopenharmony_ci	u64 (*descramble_addr)(struct hl_device *hdev, u64 addr);
168462306a36Sopenharmony_ci	void (*ack_protection_bits_errors)(struct hl_device *hdev);
168562306a36Sopenharmony_ci	int (*get_hw_block_id)(struct hl_device *hdev, u64 block_addr,
168662306a36Sopenharmony_ci				u32 *block_size, u32 *block_id);
168762306a36Sopenharmony_ci	int (*hw_block_mmap)(struct hl_device *hdev, struct vm_area_struct *vma,
168862306a36Sopenharmony_ci			u32 block_id, u32 block_size);
168962306a36Sopenharmony_ci	void (*enable_events_from_fw)(struct hl_device *hdev);
169062306a36Sopenharmony_ci	int (*ack_mmu_errors)(struct hl_device *hdev, u64 mmu_cap_mask);
169162306a36Sopenharmony_ci	void (*get_msi_info)(__le32 *table);
169262306a36Sopenharmony_ci	int (*map_pll_idx_to_fw_idx)(u32 pll_idx);
169362306a36Sopenharmony_ci	void (*init_firmware_preload_params)(struct hl_device *hdev);
169462306a36Sopenharmony_ci	void (*init_firmware_loader)(struct hl_device *hdev);
169562306a36Sopenharmony_ci	void (*init_cpu_scrambler_dram)(struct hl_device *hdev);
169662306a36Sopenharmony_ci	void (*state_dump_init)(struct hl_device *hdev);
169762306a36Sopenharmony_ci	u32 (*get_sob_addr)(struct hl_device *hdev, u32 sob_id);
169862306a36Sopenharmony_ci	void (*set_pci_memory_regions)(struct hl_device *hdev);
169962306a36Sopenharmony_ci	u32* (*get_stream_master_qid_arr)(void);
170062306a36Sopenharmony_ci	void (*check_if_razwi_happened)(struct hl_device *hdev);
170162306a36Sopenharmony_ci	int (*mmu_get_real_page_size)(struct hl_device *hdev, struct hl_mmu_properties *mmu_prop,
170262306a36Sopenharmony_ci					u32 page_size, u32 *real_page_size, bool is_dram_addr);
170362306a36Sopenharmony_ci	int (*access_dev_mem)(struct hl_device *hdev, enum pci_region region_type,
170462306a36Sopenharmony_ci				u64 addr, u64 *val, enum debugfs_access_type acc_type);
170562306a36Sopenharmony_ci	u64 (*set_dram_bar_base)(struct hl_device *hdev, u64 addr);
170662306a36Sopenharmony_ci	int (*set_engine_cores)(struct hl_device *hdev, u32 *core_ids,
170762306a36Sopenharmony_ci					u32 num_cores, u32 core_command);
170862306a36Sopenharmony_ci	int (*set_engines)(struct hl_device *hdev, u32 *engine_ids,
170962306a36Sopenharmony_ci					u32 num_engines, u32 engine_command);
171062306a36Sopenharmony_ci	int (*send_device_activity)(struct hl_device *hdev, bool open);
171162306a36Sopenharmony_ci	int (*set_dram_properties)(struct hl_device *hdev);
171262306a36Sopenharmony_ci	int (*set_binning_masks)(struct hl_device *hdev);
171362306a36Sopenharmony_ci};
171462306a36Sopenharmony_ci
171562306a36Sopenharmony_ci
171662306a36Sopenharmony_ci/*
171762306a36Sopenharmony_ci * CONTEXTS
171862306a36Sopenharmony_ci */
171962306a36Sopenharmony_ci
172062306a36Sopenharmony_ci#define HL_KERNEL_ASID_ID	0
172162306a36Sopenharmony_ci
172262306a36Sopenharmony_ci/**
172362306a36Sopenharmony_ci * enum hl_va_range_type - virtual address range type.
172462306a36Sopenharmony_ci * @HL_VA_RANGE_TYPE_HOST: range type of host pages
172562306a36Sopenharmony_ci * @HL_VA_RANGE_TYPE_HOST_HUGE: range type of host huge pages
172662306a36Sopenharmony_ci * @HL_VA_RANGE_TYPE_DRAM: range type of dram pages
172762306a36Sopenharmony_ci */
172862306a36Sopenharmony_cienum hl_va_range_type {
172962306a36Sopenharmony_ci	HL_VA_RANGE_TYPE_HOST,
173062306a36Sopenharmony_ci	HL_VA_RANGE_TYPE_HOST_HUGE,
173162306a36Sopenharmony_ci	HL_VA_RANGE_TYPE_DRAM,
173262306a36Sopenharmony_ci	HL_VA_RANGE_TYPE_MAX
173362306a36Sopenharmony_ci};
173462306a36Sopenharmony_ci
173562306a36Sopenharmony_ci/**
173662306a36Sopenharmony_ci * struct hl_va_range - virtual addresses range.
173762306a36Sopenharmony_ci * @lock: protects the virtual addresses list.
173862306a36Sopenharmony_ci * @list: list of virtual addresses blocks available for mappings.
173962306a36Sopenharmony_ci * @start_addr: range start address.
174062306a36Sopenharmony_ci * @end_addr: range end address.
174162306a36Sopenharmony_ci * @page_size: page size of this va range.
174262306a36Sopenharmony_ci */
174362306a36Sopenharmony_cistruct hl_va_range {
174462306a36Sopenharmony_ci	struct mutex		lock;
174562306a36Sopenharmony_ci	struct list_head	list;
174662306a36Sopenharmony_ci	u64			start_addr;
174762306a36Sopenharmony_ci	u64			end_addr;
174862306a36Sopenharmony_ci	u32			page_size;
174962306a36Sopenharmony_ci};
175062306a36Sopenharmony_ci
175162306a36Sopenharmony_ci/**
175262306a36Sopenharmony_ci * struct hl_cs_counters_atomic - command submission counters
175362306a36Sopenharmony_ci * @out_of_mem_drop_cnt: dropped due to memory allocation issue
175462306a36Sopenharmony_ci * @parsing_drop_cnt: dropped due to error in packet parsing
175562306a36Sopenharmony_ci * @queue_full_drop_cnt: dropped due to queue full
175662306a36Sopenharmony_ci * @device_in_reset_drop_cnt: dropped due to device in reset
175762306a36Sopenharmony_ci * @max_cs_in_flight_drop_cnt: dropped due to maximum CS in-flight
175862306a36Sopenharmony_ci * @validation_drop_cnt: dropped due to error in validation
175962306a36Sopenharmony_ci */
176062306a36Sopenharmony_cistruct hl_cs_counters_atomic {
176162306a36Sopenharmony_ci	atomic64_t out_of_mem_drop_cnt;
176262306a36Sopenharmony_ci	atomic64_t parsing_drop_cnt;
176362306a36Sopenharmony_ci	atomic64_t queue_full_drop_cnt;
176462306a36Sopenharmony_ci	atomic64_t device_in_reset_drop_cnt;
176562306a36Sopenharmony_ci	atomic64_t max_cs_in_flight_drop_cnt;
176662306a36Sopenharmony_ci	atomic64_t validation_drop_cnt;
176762306a36Sopenharmony_ci};
176862306a36Sopenharmony_ci
176962306a36Sopenharmony_ci/**
177062306a36Sopenharmony_ci * struct hl_dmabuf_priv - a dma-buf private object.
177162306a36Sopenharmony_ci * @dmabuf: pointer to dma-buf object.
177262306a36Sopenharmony_ci * @ctx: pointer to the dma-buf owner's context.
177362306a36Sopenharmony_ci * @phys_pg_pack: pointer to physical page pack if the dma-buf was exported
177462306a36Sopenharmony_ci *                where virtual memory is supported.
177562306a36Sopenharmony_ci * @memhash_hnode: pointer to the memhash node. this object holds the export count.
177662306a36Sopenharmony_ci * @device_address: physical address of the device's memory. Relevant only
177762306a36Sopenharmony_ci *                  if phys_pg_pack is NULL (dma-buf was exported from address).
177862306a36Sopenharmony_ci *                  The total size can be taken from the dmabuf object.
177962306a36Sopenharmony_ci */
178062306a36Sopenharmony_cistruct hl_dmabuf_priv {
178162306a36Sopenharmony_ci	struct dma_buf			*dmabuf;
178262306a36Sopenharmony_ci	struct hl_ctx			*ctx;
178362306a36Sopenharmony_ci	struct hl_vm_phys_pg_pack	*phys_pg_pack;
178462306a36Sopenharmony_ci	struct hl_vm_hash_node		*memhash_hnode;
178562306a36Sopenharmony_ci	uint64_t			device_address;
178662306a36Sopenharmony_ci};
178762306a36Sopenharmony_ci
178862306a36Sopenharmony_ci#define HL_CS_OUTCOME_HISTORY_LEN 256
178962306a36Sopenharmony_ci
179062306a36Sopenharmony_ci/**
179162306a36Sopenharmony_ci * struct hl_cs_outcome - represents a single completed CS outcome
179262306a36Sopenharmony_ci * @list_link: link to either container's used list or free list
179362306a36Sopenharmony_ci * @map_link: list to the container hash map
179462306a36Sopenharmony_ci * @ts: completion ts
179562306a36Sopenharmony_ci * @seq: the original cs sequence
179662306a36Sopenharmony_ci * @error: error code cs completed with, if any
179762306a36Sopenharmony_ci */
179862306a36Sopenharmony_cistruct hl_cs_outcome {
179962306a36Sopenharmony_ci	struct list_head list_link;
180062306a36Sopenharmony_ci	struct hlist_node map_link;
180162306a36Sopenharmony_ci	ktime_t ts;
180262306a36Sopenharmony_ci	u64 seq;
180362306a36Sopenharmony_ci	int error;
180462306a36Sopenharmony_ci};
180562306a36Sopenharmony_ci
180662306a36Sopenharmony_ci/**
180762306a36Sopenharmony_ci * struct hl_cs_outcome_store - represents a limited store of completed CS outcomes
180862306a36Sopenharmony_ci * @outcome_map: index of completed CS searchable by sequence number
180962306a36Sopenharmony_ci * @used_list: list of outcome objects currently in use
181062306a36Sopenharmony_ci * @free_list: list of outcome objects currently not in use
181162306a36Sopenharmony_ci * @nodes_pool: a static pool of pre-allocated outcome objects
181262306a36Sopenharmony_ci * @db_lock: any operation on the store must take this lock
181362306a36Sopenharmony_ci */
181462306a36Sopenharmony_cistruct hl_cs_outcome_store {
181562306a36Sopenharmony_ci	DECLARE_HASHTABLE(outcome_map, 8);
181662306a36Sopenharmony_ci	struct list_head used_list;
181762306a36Sopenharmony_ci	struct list_head free_list;
181862306a36Sopenharmony_ci	struct hl_cs_outcome nodes_pool[HL_CS_OUTCOME_HISTORY_LEN];
181962306a36Sopenharmony_ci	spinlock_t db_lock;
182062306a36Sopenharmony_ci};
182162306a36Sopenharmony_ci
182262306a36Sopenharmony_ci/**
182362306a36Sopenharmony_ci * struct hl_ctx - user/kernel context.
182462306a36Sopenharmony_ci * @mem_hash: holds mapping from virtual address to virtual memory area
182562306a36Sopenharmony_ci *		descriptor (hl_vm_phys_pg_list or hl_userptr).
182662306a36Sopenharmony_ci * @mmu_shadow_hash: holds a mapping from shadow address to pgt_info structure.
182762306a36Sopenharmony_ci * @hr_mmu_phys_hash: if host-resident MMU is used, holds a mapping from
182862306a36Sopenharmony_ci *                    MMU-hop-page physical address to its host-resident
182962306a36Sopenharmony_ci *                    pgt_info structure.
183062306a36Sopenharmony_ci * @hpriv: pointer to the private (Kernel Driver) data of the process (fd).
183162306a36Sopenharmony_ci * @hdev: pointer to the device structure.
183262306a36Sopenharmony_ci * @refcount: reference counter for the context. Context is released only when
183362306a36Sopenharmony_ci *		this hits 0. It is incremented on CS and CS_WAIT.
183462306a36Sopenharmony_ci * @cs_pending: array of hl fence objects representing pending CS.
183562306a36Sopenharmony_ci * @outcome_store: storage data structure used to remember outcomes of completed
183662306a36Sopenharmony_ci *                 command submissions for a long time after CS id wraparound.
183762306a36Sopenharmony_ci * @va_range: holds available virtual addresses for host and dram mappings.
183862306a36Sopenharmony_ci * @mem_hash_lock: protects the mem_hash.
183962306a36Sopenharmony_ci * @hw_block_list_lock: protects the HW block memory list.
184062306a36Sopenharmony_ci * @debugfs_list: node in debugfs list of contexts.
184162306a36Sopenharmony_ci * @hw_block_mem_list: list of HW block virtual mapped addresses.
184262306a36Sopenharmony_ci * @cs_counters: context command submission counters.
184362306a36Sopenharmony_ci * @cb_va_pool: device VA pool for command buffers which are mapped to the
184462306a36Sopenharmony_ci *              device's MMU.
184562306a36Sopenharmony_ci * @sig_mgr: encaps signals handle manager.
184662306a36Sopenharmony_ci * @cb_va_pool_base: the base address for the device VA pool
184762306a36Sopenharmony_ci * @cs_sequence: sequence number for CS. Value is assigned to a CS and passed
184862306a36Sopenharmony_ci *			to user so user could inquire about CS. It is used as
184962306a36Sopenharmony_ci *			index to cs_pending array.
185062306a36Sopenharmony_ci * @dram_default_hops: array that holds all hops addresses needed for default
185162306a36Sopenharmony_ci *                     DRAM mapping.
185262306a36Sopenharmony_ci * @cs_lock: spinlock to protect cs_sequence.
185362306a36Sopenharmony_ci * @dram_phys_mem: amount of used physical DRAM memory by this context.
185462306a36Sopenharmony_ci * @thread_ctx_switch_token: token to prevent multiple threads of the same
185562306a36Sopenharmony_ci *				context	from running the context switch phase.
185662306a36Sopenharmony_ci *				Only a single thread should run it.
185762306a36Sopenharmony_ci * @thread_ctx_switch_wait_token: token to prevent the threads that didn't run
185862306a36Sopenharmony_ci *				the context switch phase from moving to their
185962306a36Sopenharmony_ci *				execution phase before the context switch phase
186062306a36Sopenharmony_ci *				has finished.
186162306a36Sopenharmony_ci * @asid: context's unique address space ID in the device's MMU.
186262306a36Sopenharmony_ci * @handle: context's opaque handle for user
186362306a36Sopenharmony_ci */
186462306a36Sopenharmony_cistruct hl_ctx {
186562306a36Sopenharmony_ci	DECLARE_HASHTABLE(mem_hash, MEM_HASH_TABLE_BITS);
186662306a36Sopenharmony_ci	DECLARE_HASHTABLE(mmu_shadow_hash, MMU_HASH_TABLE_BITS);
186762306a36Sopenharmony_ci	DECLARE_HASHTABLE(hr_mmu_phys_hash, MMU_HASH_TABLE_BITS);
186862306a36Sopenharmony_ci	struct hl_fpriv			*hpriv;
186962306a36Sopenharmony_ci	struct hl_device		*hdev;
187062306a36Sopenharmony_ci	struct kref			refcount;
187162306a36Sopenharmony_ci	struct hl_fence			**cs_pending;
187262306a36Sopenharmony_ci	struct hl_cs_outcome_store	outcome_store;
187362306a36Sopenharmony_ci	struct hl_va_range		*va_range[HL_VA_RANGE_TYPE_MAX];
187462306a36Sopenharmony_ci	struct mutex			mem_hash_lock;
187562306a36Sopenharmony_ci	struct mutex			hw_block_list_lock;
187662306a36Sopenharmony_ci	struct list_head		debugfs_list;
187762306a36Sopenharmony_ci	struct list_head		hw_block_mem_list;
187862306a36Sopenharmony_ci	struct hl_cs_counters_atomic	cs_counters;
187962306a36Sopenharmony_ci	struct gen_pool			*cb_va_pool;
188062306a36Sopenharmony_ci	struct hl_encaps_signals_mgr	sig_mgr;
188162306a36Sopenharmony_ci	u64				cb_va_pool_base;
188262306a36Sopenharmony_ci	u64				cs_sequence;
188362306a36Sopenharmony_ci	u64				*dram_default_hops;
188462306a36Sopenharmony_ci	spinlock_t			cs_lock;
188562306a36Sopenharmony_ci	atomic64_t			dram_phys_mem;
188662306a36Sopenharmony_ci	atomic_t			thread_ctx_switch_token;
188762306a36Sopenharmony_ci	u32				thread_ctx_switch_wait_token;
188862306a36Sopenharmony_ci	u32				asid;
188962306a36Sopenharmony_ci	u32				handle;
189062306a36Sopenharmony_ci};
189162306a36Sopenharmony_ci
189262306a36Sopenharmony_ci/**
189362306a36Sopenharmony_ci * struct hl_ctx_mgr - for handling multiple contexts.
189462306a36Sopenharmony_ci * @lock: protects ctx_handles.
189562306a36Sopenharmony_ci * @handles: idr to hold all ctx handles.
189662306a36Sopenharmony_ci */
189762306a36Sopenharmony_cistruct hl_ctx_mgr {
189862306a36Sopenharmony_ci	struct mutex	lock;
189962306a36Sopenharmony_ci	struct idr	handles;
190062306a36Sopenharmony_ci};
190162306a36Sopenharmony_ci
190262306a36Sopenharmony_ci
190362306a36Sopenharmony_ci/*
190462306a36Sopenharmony_ci * COMMAND SUBMISSIONS
190562306a36Sopenharmony_ci */
190662306a36Sopenharmony_ci
190762306a36Sopenharmony_ci/**
190862306a36Sopenharmony_ci * struct hl_userptr - memory mapping chunk information
190962306a36Sopenharmony_ci * @vm_type: type of the VM.
191062306a36Sopenharmony_ci * @job_node: linked-list node for hanging the object on the Job's list.
191162306a36Sopenharmony_ci * @pages: pointer to struct page array
191262306a36Sopenharmony_ci * @npages: size of @pages array
191362306a36Sopenharmony_ci * @sgt: pointer to the scatter-gather table that holds the pages.
191462306a36Sopenharmony_ci * @dir: for DMA unmapping, the direction must be supplied, so save it.
191562306a36Sopenharmony_ci * @debugfs_list: node in debugfs list of command submissions.
191662306a36Sopenharmony_ci * @pid: the pid of the user process owning the memory
191762306a36Sopenharmony_ci * @addr: user-space virtual address of the start of the memory area.
191862306a36Sopenharmony_ci * @size: size of the memory area to pin & map.
191962306a36Sopenharmony_ci * @dma_mapped: true if the SG was mapped to DMA addresses, false otherwise.
192062306a36Sopenharmony_ci */
192162306a36Sopenharmony_cistruct hl_userptr {
192262306a36Sopenharmony_ci	enum vm_type		vm_type; /* must be first */
192362306a36Sopenharmony_ci	struct list_head	job_node;
192462306a36Sopenharmony_ci	struct page		**pages;
192562306a36Sopenharmony_ci	unsigned int		npages;
192662306a36Sopenharmony_ci	struct sg_table		*sgt;
192762306a36Sopenharmony_ci	enum dma_data_direction dir;
192862306a36Sopenharmony_ci	struct list_head	debugfs_list;
192962306a36Sopenharmony_ci	pid_t			pid;
193062306a36Sopenharmony_ci	u64			addr;
193162306a36Sopenharmony_ci	u64			size;
193262306a36Sopenharmony_ci	u8			dma_mapped;
193362306a36Sopenharmony_ci};
193462306a36Sopenharmony_ci
193562306a36Sopenharmony_ci/**
193662306a36Sopenharmony_ci * struct hl_cs - command submission.
193762306a36Sopenharmony_ci * @jobs_in_queue_cnt: per each queue, maintain counter of submitted jobs.
193862306a36Sopenharmony_ci * @ctx: the context this CS belongs to.
193962306a36Sopenharmony_ci * @job_list: list of the CS's jobs in the various queues.
194062306a36Sopenharmony_ci * @job_lock: spinlock for the CS's jobs list. Needed for free_job.
194162306a36Sopenharmony_ci * @refcount: reference counter for usage of the CS.
194262306a36Sopenharmony_ci * @fence: pointer to the fence object of this CS.
194362306a36Sopenharmony_ci * @signal_fence: pointer to the fence object of the signal CS (used by wait
194462306a36Sopenharmony_ci *                CS only).
194562306a36Sopenharmony_ci * @finish_work: workqueue object to run when CS is completed by H/W.
194662306a36Sopenharmony_ci * @work_tdr: delayed work node for TDR.
194762306a36Sopenharmony_ci * @mirror_node : node in device mirror list of command submissions.
194862306a36Sopenharmony_ci * @staged_cs_node: node in the staged cs list.
194962306a36Sopenharmony_ci * @debugfs_list: node in debugfs list of command submissions.
195062306a36Sopenharmony_ci * @encaps_sig_hdl: holds the encaps signals handle.
195162306a36Sopenharmony_ci * @sequence: the sequence number of this CS.
195262306a36Sopenharmony_ci * @staged_sequence: the sequence of the staged submission this CS is part of,
195362306a36Sopenharmony_ci *                   relevant only if staged_cs is set.
195462306a36Sopenharmony_ci * @timeout_jiffies: cs timeout in jiffies.
195562306a36Sopenharmony_ci * @submission_time_jiffies: submission time of the cs
195662306a36Sopenharmony_ci * @type: CS_TYPE_*.
195762306a36Sopenharmony_ci * @jobs_cnt: counter of submitted jobs on all queues.
195862306a36Sopenharmony_ci * @encaps_sig_hdl_id: encaps signals handle id, set for the first staged cs.
195962306a36Sopenharmony_ci * @completion_timestamp: timestamp of the last completed cs job.
196062306a36Sopenharmony_ci * @sob_addr_offset: sob offset from the configuration base address.
196162306a36Sopenharmony_ci * @initial_sob_count: count of completed signals in SOB before current submission of signal or
196262306a36Sopenharmony_ci *                     cs with encaps signals.
196362306a36Sopenharmony_ci * @submitted: true if CS was submitted to H/W.
196462306a36Sopenharmony_ci * @completed: true if CS was completed by device.
196562306a36Sopenharmony_ci * @timedout : true if CS was timedout.
196662306a36Sopenharmony_ci * @tdr_active: true if TDR was activated for this CS (to prevent
196762306a36Sopenharmony_ci *		double TDR activation).
196862306a36Sopenharmony_ci * @aborted: true if CS was aborted due to some device error.
196962306a36Sopenharmony_ci * @timestamp: true if a timestamp must be captured upon completion.
197062306a36Sopenharmony_ci * @staged_last: true if this is the last staged CS and needs completion.
197162306a36Sopenharmony_ci * @staged_first: true if this is the first staged CS and we need to receive
197262306a36Sopenharmony_ci *                timeout for this CS.
197362306a36Sopenharmony_ci * @staged_cs: true if this CS is part of a staged submission.
197462306a36Sopenharmony_ci * @skip_reset_on_timeout: true if we shall not reset the device in case
197562306a36Sopenharmony_ci *                         timeout occurs (debug scenario).
197662306a36Sopenharmony_ci * @encaps_signals: true if this CS has encaps reserved signals.
197762306a36Sopenharmony_ci */
197862306a36Sopenharmony_cistruct hl_cs {
197962306a36Sopenharmony_ci	u16			*jobs_in_queue_cnt;
198062306a36Sopenharmony_ci	struct hl_ctx		*ctx;
198162306a36Sopenharmony_ci	struct list_head	job_list;
198262306a36Sopenharmony_ci	spinlock_t		job_lock;
198362306a36Sopenharmony_ci	struct kref		refcount;
198462306a36Sopenharmony_ci	struct hl_fence		*fence;
198562306a36Sopenharmony_ci	struct hl_fence		*signal_fence;
198662306a36Sopenharmony_ci	struct work_struct	finish_work;
198762306a36Sopenharmony_ci	struct delayed_work	work_tdr;
198862306a36Sopenharmony_ci	struct list_head	mirror_node;
198962306a36Sopenharmony_ci	struct list_head	staged_cs_node;
199062306a36Sopenharmony_ci	struct list_head	debugfs_list;
199162306a36Sopenharmony_ci	struct hl_cs_encaps_sig_handle *encaps_sig_hdl;
199262306a36Sopenharmony_ci	ktime_t			completion_timestamp;
199362306a36Sopenharmony_ci	u64			sequence;
199462306a36Sopenharmony_ci	u64			staged_sequence;
199562306a36Sopenharmony_ci	u64			timeout_jiffies;
199662306a36Sopenharmony_ci	u64			submission_time_jiffies;
199762306a36Sopenharmony_ci	enum hl_cs_type		type;
199862306a36Sopenharmony_ci	u32			jobs_cnt;
199962306a36Sopenharmony_ci	u32			encaps_sig_hdl_id;
200062306a36Sopenharmony_ci	u32			sob_addr_offset;
200162306a36Sopenharmony_ci	u16			initial_sob_count;
200262306a36Sopenharmony_ci	u8			submitted;
200362306a36Sopenharmony_ci	u8			completed;
200462306a36Sopenharmony_ci	u8			timedout;
200562306a36Sopenharmony_ci	u8			tdr_active;
200662306a36Sopenharmony_ci	u8			aborted;
200762306a36Sopenharmony_ci	u8			timestamp;
200862306a36Sopenharmony_ci	u8			staged_last;
200962306a36Sopenharmony_ci	u8			staged_first;
201062306a36Sopenharmony_ci	u8			staged_cs;
201162306a36Sopenharmony_ci	u8			skip_reset_on_timeout;
201262306a36Sopenharmony_ci	u8			encaps_signals;
201362306a36Sopenharmony_ci};
201462306a36Sopenharmony_ci
201562306a36Sopenharmony_ci/**
201662306a36Sopenharmony_ci * struct hl_cs_job - command submission job.
201762306a36Sopenharmony_ci * @cs_node: the node to hang on the CS jobs list.
201862306a36Sopenharmony_ci * @cs: the CS this job belongs to.
201962306a36Sopenharmony_ci * @user_cb: the CB we got from the user.
202062306a36Sopenharmony_ci * @patched_cb: in case of patching, this is internal CB which is submitted on
202162306a36Sopenharmony_ci *		the queue instead of the CB we got from the IOCTL.
202262306a36Sopenharmony_ci * @finish_work: workqueue object to run when job is completed.
202362306a36Sopenharmony_ci * @userptr_list: linked-list of userptr mappings that belong to this job and
202462306a36Sopenharmony_ci *			wait for completion.
202562306a36Sopenharmony_ci * @debugfs_list: node in debugfs list of command submission jobs.
202662306a36Sopenharmony_ci * @refcount: reference counter for usage of the CS job.
202762306a36Sopenharmony_ci * @queue_type: the type of the H/W queue this job is submitted to.
202862306a36Sopenharmony_ci * @timestamp: timestamp upon job completion
202962306a36Sopenharmony_ci * @id: the id of this job inside a CS.
203062306a36Sopenharmony_ci * @hw_queue_id: the id of the H/W queue this job is submitted to.
203162306a36Sopenharmony_ci * @user_cb_size: the actual size of the CB we got from the user.
203262306a36Sopenharmony_ci * @job_cb_size: the actual size of the CB that we put on the queue.
203362306a36Sopenharmony_ci * @encaps_sig_wait_offset: encapsulated signals offset, which allow user
203462306a36Sopenharmony_ci *                          to wait on part of the reserved signals.
203562306a36Sopenharmony_ci * @is_kernel_allocated_cb: true if the CB handle we got from the user holds a
203662306a36Sopenharmony_ci *                          handle to a kernel-allocated CB object, false
203762306a36Sopenharmony_ci *                          otherwise (SRAM/DRAM/host address).
203862306a36Sopenharmony_ci * @contains_dma_pkt: whether the JOB contains at least one DMA packet. This
203962306a36Sopenharmony_ci *                    info is needed later, when adding the 2xMSG_PROT at the
204062306a36Sopenharmony_ci *                    end of the JOB, to know which barriers to put in the
204162306a36Sopenharmony_ci *                    MSG_PROT packets. Relevant only for GAUDI as GOYA doesn't
204262306a36Sopenharmony_ci *                    have streams so the engine can't be busy by another
204362306a36Sopenharmony_ci *                    stream.
204462306a36Sopenharmony_ci */
204562306a36Sopenharmony_cistruct hl_cs_job {
204662306a36Sopenharmony_ci	struct list_head	cs_node;
204762306a36Sopenharmony_ci	struct hl_cs		*cs;
204862306a36Sopenharmony_ci	struct hl_cb		*user_cb;
204962306a36Sopenharmony_ci	struct hl_cb		*patched_cb;
205062306a36Sopenharmony_ci	struct work_struct	finish_work;
205162306a36Sopenharmony_ci	struct list_head	userptr_list;
205262306a36Sopenharmony_ci	struct list_head	debugfs_list;
205362306a36Sopenharmony_ci	struct kref		refcount;
205462306a36Sopenharmony_ci	enum hl_queue_type	queue_type;
205562306a36Sopenharmony_ci	ktime_t			timestamp;
205662306a36Sopenharmony_ci	u32			id;
205762306a36Sopenharmony_ci	u32			hw_queue_id;
205862306a36Sopenharmony_ci	u32			user_cb_size;
205962306a36Sopenharmony_ci	u32			job_cb_size;
206062306a36Sopenharmony_ci	u32			encaps_sig_wait_offset;
206162306a36Sopenharmony_ci	u8			is_kernel_allocated_cb;
206262306a36Sopenharmony_ci	u8			contains_dma_pkt;
206362306a36Sopenharmony_ci};
206462306a36Sopenharmony_ci
206562306a36Sopenharmony_ci/**
206662306a36Sopenharmony_ci * struct hl_cs_parser - command submission parser properties.
206762306a36Sopenharmony_ci * @user_cb: the CB we got from the user.
206862306a36Sopenharmony_ci * @patched_cb: in case of patching, this is internal CB which is submitted on
206962306a36Sopenharmony_ci *		the queue instead of the CB we got from the IOCTL.
207062306a36Sopenharmony_ci * @job_userptr_list: linked-list of userptr mappings that belong to the related
207162306a36Sopenharmony_ci *			job and wait for completion.
207262306a36Sopenharmony_ci * @cs_sequence: the sequence number of the related CS.
207362306a36Sopenharmony_ci * @queue_type: the type of the H/W queue this job is submitted to.
207462306a36Sopenharmony_ci * @ctx_id: the ID of the context the related CS belongs to.
207562306a36Sopenharmony_ci * @hw_queue_id: the id of the H/W queue this job is submitted to.
207662306a36Sopenharmony_ci * @user_cb_size: the actual size of the CB we got from the user.
207762306a36Sopenharmony_ci * @patched_cb_size: the size of the CB after parsing.
207862306a36Sopenharmony_ci * @job_id: the id of the related job inside the related CS.
207962306a36Sopenharmony_ci * @is_kernel_allocated_cb: true if the CB handle we got from the user holds a
208062306a36Sopenharmony_ci *                          handle to a kernel-allocated CB object, false
208162306a36Sopenharmony_ci *                          otherwise (SRAM/DRAM/host address).
208262306a36Sopenharmony_ci * @contains_dma_pkt: whether the JOB contains at least one DMA packet. This
208362306a36Sopenharmony_ci *                    info is needed later, when adding the 2xMSG_PROT at the
208462306a36Sopenharmony_ci *                    end of the JOB, to know which barriers to put in the
208562306a36Sopenharmony_ci *                    MSG_PROT packets. Relevant only for GAUDI as GOYA doesn't
208662306a36Sopenharmony_ci *                    have streams so the engine can't be busy by another
208762306a36Sopenharmony_ci *                    stream.
208862306a36Sopenharmony_ci * @completion: true if we need completion for this CS.
208962306a36Sopenharmony_ci */
209062306a36Sopenharmony_cistruct hl_cs_parser {
209162306a36Sopenharmony_ci	struct hl_cb		*user_cb;
209262306a36Sopenharmony_ci	struct hl_cb		*patched_cb;
209362306a36Sopenharmony_ci	struct list_head	*job_userptr_list;
209462306a36Sopenharmony_ci	u64			cs_sequence;
209562306a36Sopenharmony_ci	enum hl_queue_type	queue_type;
209662306a36Sopenharmony_ci	u32			ctx_id;
209762306a36Sopenharmony_ci	u32			hw_queue_id;
209862306a36Sopenharmony_ci	u32			user_cb_size;
209962306a36Sopenharmony_ci	u32			patched_cb_size;
210062306a36Sopenharmony_ci	u8			job_id;
210162306a36Sopenharmony_ci	u8			is_kernel_allocated_cb;
210262306a36Sopenharmony_ci	u8			contains_dma_pkt;
210362306a36Sopenharmony_ci	u8			completion;
210462306a36Sopenharmony_ci};
210562306a36Sopenharmony_ci
210662306a36Sopenharmony_ci/*
210762306a36Sopenharmony_ci * MEMORY STRUCTURE
210862306a36Sopenharmony_ci */
210962306a36Sopenharmony_ci
211062306a36Sopenharmony_ci/**
211162306a36Sopenharmony_ci * struct hl_vm_hash_node - hash element from virtual address to virtual
211262306a36Sopenharmony_ci *				memory area descriptor (hl_vm_phys_pg_list or
211362306a36Sopenharmony_ci *				hl_userptr).
211462306a36Sopenharmony_ci * @node: node to hang on the hash table in context object.
211562306a36Sopenharmony_ci * @vaddr: key virtual address.
211662306a36Sopenharmony_ci * @handle: memory handle for device memory allocation.
211762306a36Sopenharmony_ci * @ptr: value pointer (hl_vm_phys_pg_list or hl_userptr).
211862306a36Sopenharmony_ci * @export_cnt: number of exports from within the VA block.
211962306a36Sopenharmony_ci */
212062306a36Sopenharmony_cistruct hl_vm_hash_node {
212162306a36Sopenharmony_ci	struct hlist_node	node;
212262306a36Sopenharmony_ci	u64			vaddr;
212362306a36Sopenharmony_ci	u64			handle;
212462306a36Sopenharmony_ci	void			*ptr;
212562306a36Sopenharmony_ci	int			export_cnt;
212662306a36Sopenharmony_ci};
212762306a36Sopenharmony_ci
212862306a36Sopenharmony_ci/**
212962306a36Sopenharmony_ci * struct hl_vm_hw_block_list_node - list element from user virtual address to
213062306a36Sopenharmony_ci *				HW block id.
213162306a36Sopenharmony_ci * @node: node to hang on the list in context object.
213262306a36Sopenharmony_ci * @ctx: the context this node belongs to.
213362306a36Sopenharmony_ci * @vaddr: virtual address of the HW block.
213462306a36Sopenharmony_ci * @block_size: size of the block.
213562306a36Sopenharmony_ci * @mapped_size: size of the block which is mapped. May change if partial un-mappings are done.
213662306a36Sopenharmony_ci * @id: HW block id (handle).
213762306a36Sopenharmony_ci */
213862306a36Sopenharmony_cistruct hl_vm_hw_block_list_node {
213962306a36Sopenharmony_ci	struct list_head	node;
214062306a36Sopenharmony_ci	struct hl_ctx		*ctx;
214162306a36Sopenharmony_ci	unsigned long		vaddr;
214262306a36Sopenharmony_ci	u32			block_size;
214362306a36Sopenharmony_ci	u32			mapped_size;
214462306a36Sopenharmony_ci	u32			id;
214562306a36Sopenharmony_ci};
214662306a36Sopenharmony_ci
214762306a36Sopenharmony_ci/**
214862306a36Sopenharmony_ci * struct hl_vm_phys_pg_pack - physical page pack.
214962306a36Sopenharmony_ci * @vm_type: describes the type of the virtual area descriptor.
215062306a36Sopenharmony_ci * @pages: the physical page array.
215162306a36Sopenharmony_ci * @npages: num physical pages in the pack.
215262306a36Sopenharmony_ci * @total_size: total size of all the pages in this list.
215362306a36Sopenharmony_ci * @exported_size: buffer exported size.
215462306a36Sopenharmony_ci * @node: used to attach to deletion list that is used when all the allocations are cleared
215562306a36Sopenharmony_ci *        at the teardown of the context.
215662306a36Sopenharmony_ci * @mapping_cnt: number of shared mappings.
215762306a36Sopenharmony_ci * @asid: the context related to this list.
215862306a36Sopenharmony_ci * @page_size: size of each page in the pack.
215962306a36Sopenharmony_ci * @flags: HL_MEM_* flags related to this list.
216062306a36Sopenharmony_ci * @handle: the provided handle related to this list.
216162306a36Sopenharmony_ci * @offset: offset from the first page.
216262306a36Sopenharmony_ci * @contiguous: is contiguous physical memory.
216362306a36Sopenharmony_ci * @created_from_userptr: is product of host virtual address.
216462306a36Sopenharmony_ci */
216562306a36Sopenharmony_cistruct hl_vm_phys_pg_pack {
216662306a36Sopenharmony_ci	enum vm_type		vm_type; /* must be first */
216762306a36Sopenharmony_ci	u64			*pages;
216862306a36Sopenharmony_ci	u64			npages;
216962306a36Sopenharmony_ci	u64			total_size;
217062306a36Sopenharmony_ci	u64			exported_size;
217162306a36Sopenharmony_ci	struct list_head	node;
217262306a36Sopenharmony_ci	atomic_t		mapping_cnt;
217362306a36Sopenharmony_ci	u32			asid;
217462306a36Sopenharmony_ci	u32			page_size;
217562306a36Sopenharmony_ci	u32			flags;
217662306a36Sopenharmony_ci	u32			handle;
217762306a36Sopenharmony_ci	u32			offset;
217862306a36Sopenharmony_ci	u8			contiguous;
217962306a36Sopenharmony_ci	u8			created_from_userptr;
218062306a36Sopenharmony_ci};
218162306a36Sopenharmony_ci
218262306a36Sopenharmony_ci/**
218362306a36Sopenharmony_ci * struct hl_vm_va_block - virtual range block information.
218462306a36Sopenharmony_ci * @node: node to hang on the virtual range list in context object.
218562306a36Sopenharmony_ci * @start: virtual range start address.
218662306a36Sopenharmony_ci * @end: virtual range end address.
218762306a36Sopenharmony_ci * @size: virtual range size.
218862306a36Sopenharmony_ci */
218962306a36Sopenharmony_cistruct hl_vm_va_block {
219062306a36Sopenharmony_ci	struct list_head	node;
219162306a36Sopenharmony_ci	u64			start;
219262306a36Sopenharmony_ci	u64			end;
219362306a36Sopenharmony_ci	u64			size;
219462306a36Sopenharmony_ci};
219562306a36Sopenharmony_ci
219662306a36Sopenharmony_ci/**
219762306a36Sopenharmony_ci * struct hl_vm - virtual memory manager for MMU.
219862306a36Sopenharmony_ci * @dram_pg_pool: pool for DRAM physical pages of 2MB.
219962306a36Sopenharmony_ci * @dram_pg_pool_refcount: reference counter for the pool usage.
220062306a36Sopenharmony_ci * @idr_lock: protects the phys_pg_list_handles.
220162306a36Sopenharmony_ci * @phys_pg_pack_handles: idr to hold all device allocations handles.
220262306a36Sopenharmony_ci * @init_done: whether initialization was done. We need this because VM
220362306a36Sopenharmony_ci *		initialization might be skipped during device initialization.
220462306a36Sopenharmony_ci */
220562306a36Sopenharmony_cistruct hl_vm {
220662306a36Sopenharmony_ci	struct gen_pool		*dram_pg_pool;
220762306a36Sopenharmony_ci	struct kref		dram_pg_pool_refcount;
220862306a36Sopenharmony_ci	spinlock_t		idr_lock;
220962306a36Sopenharmony_ci	struct idr		phys_pg_pack_handles;
221062306a36Sopenharmony_ci	u8			init_done;
221162306a36Sopenharmony_ci};
221262306a36Sopenharmony_ci
221362306a36Sopenharmony_ci
221462306a36Sopenharmony_ci/*
221562306a36Sopenharmony_ci * DEBUG, PROFILING STRUCTURE
221662306a36Sopenharmony_ci */
221762306a36Sopenharmony_ci
221862306a36Sopenharmony_ci/**
221962306a36Sopenharmony_ci * struct hl_debug_params - Coresight debug parameters.
222062306a36Sopenharmony_ci * @input: pointer to component specific input parameters.
222162306a36Sopenharmony_ci * @output: pointer to component specific output parameters.
222262306a36Sopenharmony_ci * @output_size: size of output buffer.
222362306a36Sopenharmony_ci * @reg_idx: relevant register ID.
222462306a36Sopenharmony_ci * @op: component operation to execute.
222562306a36Sopenharmony_ci * @enable: true if to enable component debugging, false otherwise.
222662306a36Sopenharmony_ci */
222762306a36Sopenharmony_cistruct hl_debug_params {
222862306a36Sopenharmony_ci	void *input;
222962306a36Sopenharmony_ci	void *output;
223062306a36Sopenharmony_ci	u32 output_size;
223162306a36Sopenharmony_ci	u32 reg_idx;
223262306a36Sopenharmony_ci	u32 op;
223362306a36Sopenharmony_ci	bool enable;
223462306a36Sopenharmony_ci};
223562306a36Sopenharmony_ci
223662306a36Sopenharmony_ci/**
223762306a36Sopenharmony_ci * struct hl_notifier_event - holds the notifier data structure
223862306a36Sopenharmony_ci * @eventfd: the event file descriptor to raise the notifications
223962306a36Sopenharmony_ci * @lock: mutex lock to protect the notifier data flows
224062306a36Sopenharmony_ci * @events_mask: indicates the bitmap events
224162306a36Sopenharmony_ci */
224262306a36Sopenharmony_cistruct hl_notifier_event {
224362306a36Sopenharmony_ci	struct eventfd_ctx	*eventfd;
224462306a36Sopenharmony_ci	struct mutex		lock;
224562306a36Sopenharmony_ci	u64			events_mask;
224662306a36Sopenharmony_ci};
224762306a36Sopenharmony_ci
224862306a36Sopenharmony_ci/*
224962306a36Sopenharmony_ci * FILE PRIVATE STRUCTURE
225062306a36Sopenharmony_ci */
225162306a36Sopenharmony_ci
225262306a36Sopenharmony_ci/**
225362306a36Sopenharmony_ci * struct hl_fpriv - process information stored in FD private data.
225462306a36Sopenharmony_ci * @hdev: habanalabs device structure.
225562306a36Sopenharmony_ci * @filp: pointer to the given file structure.
225662306a36Sopenharmony_ci * @taskpid: current process ID.
225762306a36Sopenharmony_ci * @ctx: current executing context. TODO: remove for multiple ctx per process
225862306a36Sopenharmony_ci * @ctx_mgr: context manager to handle multiple context for this FD.
225962306a36Sopenharmony_ci * @mem_mgr: manager descriptor for memory exportable via mmap
226062306a36Sopenharmony_ci * @notifier_event: notifier eventfd towards user process
226162306a36Sopenharmony_ci * @debugfs_list: list of relevant ASIC debugfs.
226262306a36Sopenharmony_ci * @dev_node: node in the device list of file private data
226362306a36Sopenharmony_ci * @refcount: number of related contexts.
226462306a36Sopenharmony_ci * @restore_phase_mutex: lock for context switch and restore phase.
226562306a36Sopenharmony_ci * @ctx_lock: protects the pointer to current executing context pointer. TODO: remove for multiple
226662306a36Sopenharmony_ci *            ctx per process.
226762306a36Sopenharmony_ci */
226862306a36Sopenharmony_cistruct hl_fpriv {
226962306a36Sopenharmony_ci	struct hl_device		*hdev;
227062306a36Sopenharmony_ci	struct file			*filp;
227162306a36Sopenharmony_ci	struct pid			*taskpid;
227262306a36Sopenharmony_ci	struct hl_ctx			*ctx;
227362306a36Sopenharmony_ci	struct hl_ctx_mgr		ctx_mgr;
227462306a36Sopenharmony_ci	struct hl_mem_mgr		mem_mgr;
227562306a36Sopenharmony_ci	struct hl_notifier_event	notifier_event;
227662306a36Sopenharmony_ci	struct list_head		debugfs_list;
227762306a36Sopenharmony_ci	struct list_head		dev_node;
227862306a36Sopenharmony_ci	struct kref			refcount;
227962306a36Sopenharmony_ci	struct mutex			restore_phase_mutex;
228062306a36Sopenharmony_ci	struct mutex			ctx_lock;
228162306a36Sopenharmony_ci};
228262306a36Sopenharmony_ci
228362306a36Sopenharmony_ci
228462306a36Sopenharmony_ci/*
228562306a36Sopenharmony_ci * DebugFS
228662306a36Sopenharmony_ci */
228762306a36Sopenharmony_ci
228862306a36Sopenharmony_ci/**
228962306a36Sopenharmony_ci * struct hl_info_list - debugfs file ops.
229062306a36Sopenharmony_ci * @name: file name.
229162306a36Sopenharmony_ci * @show: function to output information.
229262306a36Sopenharmony_ci * @write: function to write to the file.
229362306a36Sopenharmony_ci */
229462306a36Sopenharmony_cistruct hl_info_list {
229562306a36Sopenharmony_ci	const char	*name;
229662306a36Sopenharmony_ci	int		(*show)(struct seq_file *s, void *data);
229762306a36Sopenharmony_ci	ssize_t		(*write)(struct file *file, const char __user *buf,
229862306a36Sopenharmony_ci				size_t count, loff_t *f_pos);
229962306a36Sopenharmony_ci};
230062306a36Sopenharmony_ci
230162306a36Sopenharmony_ci/**
230262306a36Sopenharmony_ci * struct hl_debugfs_entry - debugfs dentry wrapper.
230362306a36Sopenharmony_ci * @info_ent: dentry related ops.
230462306a36Sopenharmony_ci * @dev_entry: ASIC specific debugfs manager.
230562306a36Sopenharmony_ci */
230662306a36Sopenharmony_cistruct hl_debugfs_entry {
230762306a36Sopenharmony_ci	const struct hl_info_list	*info_ent;
230862306a36Sopenharmony_ci	struct hl_dbg_device_entry	*dev_entry;
230962306a36Sopenharmony_ci};
231062306a36Sopenharmony_ci
231162306a36Sopenharmony_ci/**
231262306a36Sopenharmony_ci * struct hl_dbg_device_entry - ASIC specific debugfs manager.
231362306a36Sopenharmony_ci * @root: root dentry.
231462306a36Sopenharmony_ci * @hdev: habanalabs device structure.
231562306a36Sopenharmony_ci * @entry_arr: array of available hl_debugfs_entry.
231662306a36Sopenharmony_ci * @file_list: list of available debugfs files.
231762306a36Sopenharmony_ci * @file_mutex: protects file_list.
231862306a36Sopenharmony_ci * @cb_list: list of available CBs.
231962306a36Sopenharmony_ci * @cb_spinlock: protects cb_list.
232062306a36Sopenharmony_ci * @cs_list: list of available CSs.
232162306a36Sopenharmony_ci * @cs_spinlock: protects cs_list.
232262306a36Sopenharmony_ci * @cs_job_list: list of available CB jobs.
232362306a36Sopenharmony_ci * @cs_job_spinlock: protects cs_job_list.
232462306a36Sopenharmony_ci * @userptr_list: list of available userptrs (virtual memory chunk descriptor).
232562306a36Sopenharmony_ci * @userptr_spinlock: protects userptr_list.
232662306a36Sopenharmony_ci * @ctx_mem_hash_list: list of available contexts with MMU mappings.
232762306a36Sopenharmony_ci * @ctx_mem_hash_mutex: protects list of available contexts with MMU mappings.
232862306a36Sopenharmony_ci * @data_dma_blob_desc: data DMA descriptor of blob.
232962306a36Sopenharmony_ci * @mon_dump_blob_desc: monitor dump descriptor of blob.
233062306a36Sopenharmony_ci * @state_dump: data of the system states in case of a bad cs.
233162306a36Sopenharmony_ci * @state_dump_sem: protects state_dump.
233262306a36Sopenharmony_ci * @addr: next address to read/write from/to in read/write32.
233362306a36Sopenharmony_ci * @mmu_addr: next virtual address to translate to physical address in mmu_show.
233462306a36Sopenharmony_ci * @mmu_cap_mask: mmu hw capability mask, to be used in mmu_ack_error.
233562306a36Sopenharmony_ci * @userptr_lookup: the target user ptr to look up for on demand.
233662306a36Sopenharmony_ci * @mmu_asid: ASID to use while translating in mmu_show.
233762306a36Sopenharmony_ci * @state_dump_head: index of the latest state dump
233862306a36Sopenharmony_ci * @i2c_bus: generic u8 debugfs file for bus value to use in i2c_data_read.
233962306a36Sopenharmony_ci * @i2c_addr: generic u8 debugfs file for address value to use in i2c_data_read.
234062306a36Sopenharmony_ci * @i2c_reg: generic u8 debugfs file for register value to use in i2c_data_read.
234162306a36Sopenharmony_ci * @i2c_len: generic u8 debugfs file for length value to use in i2c_data_read.
234262306a36Sopenharmony_ci */
234362306a36Sopenharmony_cistruct hl_dbg_device_entry {
234462306a36Sopenharmony_ci	struct dentry			*root;
234562306a36Sopenharmony_ci	struct hl_device		*hdev;
234662306a36Sopenharmony_ci	struct hl_debugfs_entry		*entry_arr;
234762306a36Sopenharmony_ci	struct list_head		file_list;
234862306a36Sopenharmony_ci	struct mutex			file_mutex;
234962306a36Sopenharmony_ci	struct list_head		cb_list;
235062306a36Sopenharmony_ci	spinlock_t			cb_spinlock;
235162306a36Sopenharmony_ci	struct list_head		cs_list;
235262306a36Sopenharmony_ci	spinlock_t			cs_spinlock;
235362306a36Sopenharmony_ci	struct list_head		cs_job_list;
235462306a36Sopenharmony_ci	spinlock_t			cs_job_spinlock;
235562306a36Sopenharmony_ci	struct list_head		userptr_list;
235662306a36Sopenharmony_ci	spinlock_t			userptr_spinlock;
235762306a36Sopenharmony_ci	struct list_head		ctx_mem_hash_list;
235862306a36Sopenharmony_ci	struct mutex			ctx_mem_hash_mutex;
235962306a36Sopenharmony_ci	struct debugfs_blob_wrapper	data_dma_blob_desc;
236062306a36Sopenharmony_ci	struct debugfs_blob_wrapper	mon_dump_blob_desc;
236162306a36Sopenharmony_ci	char				*state_dump[HL_STATE_DUMP_HIST_LEN];
236262306a36Sopenharmony_ci	struct rw_semaphore		state_dump_sem;
236362306a36Sopenharmony_ci	u64				addr;
236462306a36Sopenharmony_ci	u64				mmu_addr;
236562306a36Sopenharmony_ci	u64				mmu_cap_mask;
236662306a36Sopenharmony_ci	u64				userptr_lookup;
236762306a36Sopenharmony_ci	u32				mmu_asid;
236862306a36Sopenharmony_ci	u32				state_dump_head;
236962306a36Sopenharmony_ci	u8				i2c_bus;
237062306a36Sopenharmony_ci	u8				i2c_addr;
237162306a36Sopenharmony_ci	u8				i2c_reg;
237262306a36Sopenharmony_ci	u8				i2c_len;
237362306a36Sopenharmony_ci};
237462306a36Sopenharmony_ci
237562306a36Sopenharmony_ci/**
237662306a36Sopenharmony_ci * struct hl_hw_obj_name_entry - single hw object name, member of
237762306a36Sopenharmony_ci * hl_state_dump_specs
237862306a36Sopenharmony_ci * @node: link to the containing hash table
237962306a36Sopenharmony_ci * @name: hw object name
238062306a36Sopenharmony_ci * @id: object identifier
238162306a36Sopenharmony_ci */
238262306a36Sopenharmony_cistruct hl_hw_obj_name_entry {
238362306a36Sopenharmony_ci	struct hlist_node	node;
238462306a36Sopenharmony_ci	const char		*name;
238562306a36Sopenharmony_ci	u32			id;
238662306a36Sopenharmony_ci};
238762306a36Sopenharmony_ci
238862306a36Sopenharmony_cienum hl_state_dump_specs_props {
238962306a36Sopenharmony_ci	SP_SYNC_OBJ_BASE_ADDR,
239062306a36Sopenharmony_ci	SP_NEXT_SYNC_OBJ_ADDR,
239162306a36Sopenharmony_ci	SP_SYNC_OBJ_AMOUNT,
239262306a36Sopenharmony_ci	SP_MON_OBJ_WR_ADDR_LOW,
239362306a36Sopenharmony_ci	SP_MON_OBJ_WR_ADDR_HIGH,
239462306a36Sopenharmony_ci	SP_MON_OBJ_WR_DATA,
239562306a36Sopenharmony_ci	SP_MON_OBJ_ARM_DATA,
239662306a36Sopenharmony_ci	SP_MON_OBJ_STATUS,
239762306a36Sopenharmony_ci	SP_MONITORS_AMOUNT,
239862306a36Sopenharmony_ci	SP_TPC0_CMDQ,
239962306a36Sopenharmony_ci	SP_TPC0_CFG_SO,
240062306a36Sopenharmony_ci	SP_NEXT_TPC,
240162306a36Sopenharmony_ci	SP_MME_CMDQ,
240262306a36Sopenharmony_ci	SP_MME_CFG_SO,
240362306a36Sopenharmony_ci	SP_NEXT_MME,
240462306a36Sopenharmony_ci	SP_DMA_CMDQ,
240562306a36Sopenharmony_ci	SP_DMA_CFG_SO,
240662306a36Sopenharmony_ci	SP_DMA_QUEUES_OFFSET,
240762306a36Sopenharmony_ci	SP_NUM_OF_MME_ENGINES,
240862306a36Sopenharmony_ci	SP_SUB_MME_ENG_NUM,
240962306a36Sopenharmony_ci	SP_NUM_OF_DMA_ENGINES,
241062306a36Sopenharmony_ci	SP_NUM_OF_TPC_ENGINES,
241162306a36Sopenharmony_ci	SP_ENGINE_NUM_OF_QUEUES,
241262306a36Sopenharmony_ci	SP_ENGINE_NUM_OF_STREAMS,
241362306a36Sopenharmony_ci	SP_ENGINE_NUM_OF_FENCES,
241462306a36Sopenharmony_ci	SP_FENCE0_CNT_OFFSET,
241562306a36Sopenharmony_ci	SP_FENCE0_RDATA_OFFSET,
241662306a36Sopenharmony_ci	SP_CP_STS_OFFSET,
241762306a36Sopenharmony_ci	SP_NUM_CORES,
241862306a36Sopenharmony_ci
241962306a36Sopenharmony_ci	SP_MAX
242062306a36Sopenharmony_ci};
242162306a36Sopenharmony_ci
242262306a36Sopenharmony_cienum hl_sync_engine_type {
242362306a36Sopenharmony_ci	ENGINE_TPC,
242462306a36Sopenharmony_ci	ENGINE_DMA,
242562306a36Sopenharmony_ci	ENGINE_MME,
242662306a36Sopenharmony_ci};
242762306a36Sopenharmony_ci
242862306a36Sopenharmony_ci/**
242962306a36Sopenharmony_ci * struct hl_mon_state_dump - represents a state dump of a single monitor
243062306a36Sopenharmony_ci * @id: monitor id
243162306a36Sopenharmony_ci * @wr_addr_low: address monitor will write to, low bits
243262306a36Sopenharmony_ci * @wr_addr_high: address monitor will write to, high bits
243362306a36Sopenharmony_ci * @wr_data: data monitor will write
243462306a36Sopenharmony_ci * @arm_data: register value containing monitor configuration
243562306a36Sopenharmony_ci * @status: monitor status
243662306a36Sopenharmony_ci */
243762306a36Sopenharmony_cistruct hl_mon_state_dump {
243862306a36Sopenharmony_ci	u32		id;
243962306a36Sopenharmony_ci	u32		wr_addr_low;
244062306a36Sopenharmony_ci	u32		wr_addr_high;
244162306a36Sopenharmony_ci	u32		wr_data;
244262306a36Sopenharmony_ci	u32		arm_data;
244362306a36Sopenharmony_ci	u32		status;
244462306a36Sopenharmony_ci};
244562306a36Sopenharmony_ci
244662306a36Sopenharmony_ci/**
244762306a36Sopenharmony_ci * struct hl_sync_to_engine_map_entry - sync object id to engine mapping entry
244862306a36Sopenharmony_ci * @engine_type: type of the engine
244962306a36Sopenharmony_ci * @engine_id: id of the engine
245062306a36Sopenharmony_ci * @sync_id: id of the sync object
245162306a36Sopenharmony_ci */
245262306a36Sopenharmony_cistruct hl_sync_to_engine_map_entry {
245362306a36Sopenharmony_ci	struct hlist_node		node;
245462306a36Sopenharmony_ci	enum hl_sync_engine_type	engine_type;
245562306a36Sopenharmony_ci	u32				engine_id;
245662306a36Sopenharmony_ci	u32				sync_id;
245762306a36Sopenharmony_ci};
245862306a36Sopenharmony_ci
245962306a36Sopenharmony_ci/**
246062306a36Sopenharmony_ci * struct hl_sync_to_engine_map - maps sync object id to associated engine id
246162306a36Sopenharmony_ci * @tb: hash table containing the mapping, each element is of type
246262306a36Sopenharmony_ci *      struct hl_sync_to_engine_map_entry
246362306a36Sopenharmony_ci */
246462306a36Sopenharmony_cistruct hl_sync_to_engine_map {
246562306a36Sopenharmony_ci	DECLARE_HASHTABLE(tb, SYNC_TO_ENGINE_HASH_TABLE_BITS);
246662306a36Sopenharmony_ci};
246762306a36Sopenharmony_ci
246862306a36Sopenharmony_ci/**
246962306a36Sopenharmony_ci * struct hl_state_dump_specs_funcs - virtual functions used by the state dump
247062306a36Sopenharmony_ci * @gen_sync_to_engine_map: generate a hash map from sync obj id to its engine
247162306a36Sopenharmony_ci * @print_single_monitor: format monitor data as string
247262306a36Sopenharmony_ci * @monitor_valid: return true if given monitor dump is valid
247362306a36Sopenharmony_ci * @print_fences_single_engine: format fences data as string
247462306a36Sopenharmony_ci */
247562306a36Sopenharmony_cistruct hl_state_dump_specs_funcs {
247662306a36Sopenharmony_ci	int (*gen_sync_to_engine_map)(struct hl_device *hdev,
247762306a36Sopenharmony_ci				struct hl_sync_to_engine_map *map);
247862306a36Sopenharmony_ci	int (*print_single_monitor)(char **buf, size_t *size, size_t *offset,
247962306a36Sopenharmony_ci				    struct hl_device *hdev,
248062306a36Sopenharmony_ci				    struct hl_mon_state_dump *mon);
248162306a36Sopenharmony_ci	int (*monitor_valid)(struct hl_mon_state_dump *mon);
248262306a36Sopenharmony_ci	int (*print_fences_single_engine)(struct hl_device *hdev,
248362306a36Sopenharmony_ci					u64 base_offset,
248462306a36Sopenharmony_ci					u64 status_base_offset,
248562306a36Sopenharmony_ci					enum hl_sync_engine_type engine_type,
248662306a36Sopenharmony_ci					u32 engine_id, char **buf,
248762306a36Sopenharmony_ci					size_t *size, size_t *offset);
248862306a36Sopenharmony_ci};
248962306a36Sopenharmony_ci
249062306a36Sopenharmony_ci/**
249162306a36Sopenharmony_ci * struct hl_state_dump_specs - defines ASIC known hw objects names
249262306a36Sopenharmony_ci * @so_id_to_str_tb: sync objects names index table
249362306a36Sopenharmony_ci * @monitor_id_to_str_tb: monitors names index table
249462306a36Sopenharmony_ci * @funcs: virtual functions used for state dump
249562306a36Sopenharmony_ci * @sync_namager_names: readable names for sync manager if available (ex: N_E)
249662306a36Sopenharmony_ci * @props: pointer to a per asic const props array required for state dump
249762306a36Sopenharmony_ci */
249862306a36Sopenharmony_cistruct hl_state_dump_specs {
249962306a36Sopenharmony_ci	DECLARE_HASHTABLE(so_id_to_str_tb, OBJ_NAMES_HASH_TABLE_BITS);
250062306a36Sopenharmony_ci	DECLARE_HASHTABLE(monitor_id_to_str_tb, OBJ_NAMES_HASH_TABLE_BITS);
250162306a36Sopenharmony_ci	struct hl_state_dump_specs_funcs	funcs;
250262306a36Sopenharmony_ci	const char * const			*sync_namager_names;
250362306a36Sopenharmony_ci	s64					*props;
250462306a36Sopenharmony_ci};
250562306a36Sopenharmony_ci
250662306a36Sopenharmony_ci
250762306a36Sopenharmony_ci/*
250862306a36Sopenharmony_ci * DEVICES
250962306a36Sopenharmony_ci */
251062306a36Sopenharmony_ci
251162306a36Sopenharmony_ci#define HL_STR_MAX	32
251262306a36Sopenharmony_ci
251362306a36Sopenharmony_ci#define HL_DEV_STS_MAX (HL_DEVICE_STATUS_LAST + 1)
251462306a36Sopenharmony_ci
251562306a36Sopenharmony_ci/* Theoretical limit only. A single host can only contain up to 4 or 8 PCIe
251662306a36Sopenharmony_ci * x16 cards. In extreme cases, there are hosts that can accommodate 16 cards.
251762306a36Sopenharmony_ci */
251862306a36Sopenharmony_ci#define HL_MAX_MINORS	256
251962306a36Sopenharmony_ci
252062306a36Sopenharmony_ci/*
252162306a36Sopenharmony_ci * Registers read & write functions.
252262306a36Sopenharmony_ci */
252362306a36Sopenharmony_ci
252462306a36Sopenharmony_ciu32 hl_rreg(struct hl_device *hdev, u32 reg);
252562306a36Sopenharmony_civoid hl_wreg(struct hl_device *hdev, u32 reg, u32 val);
252662306a36Sopenharmony_ci
252762306a36Sopenharmony_ci#define RREG32(reg) hdev->asic_funcs->rreg(hdev, (reg))
252862306a36Sopenharmony_ci#define WREG32(reg, v) hdev->asic_funcs->wreg(hdev, (reg), (v))
252962306a36Sopenharmony_ci#define DREG32(reg) pr_info("REGISTER: " #reg " : 0x%08X\n",	\
253062306a36Sopenharmony_ci			hdev->asic_funcs->rreg(hdev, (reg)))
253162306a36Sopenharmony_ci
253262306a36Sopenharmony_ci#define WREG32_P(reg, val, mask)				\
253362306a36Sopenharmony_ci	do {							\
253462306a36Sopenharmony_ci		u32 tmp_ = RREG32(reg);				\
253562306a36Sopenharmony_ci		tmp_ &= (mask);					\
253662306a36Sopenharmony_ci		tmp_ |= ((val) & ~(mask));			\
253762306a36Sopenharmony_ci		WREG32(reg, tmp_);				\
253862306a36Sopenharmony_ci	} while (0)
253962306a36Sopenharmony_ci#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
254062306a36Sopenharmony_ci#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
254162306a36Sopenharmony_ci
254262306a36Sopenharmony_ci#define RMWREG32_SHIFTED(reg, val, mask) WREG32_P(reg, val, ~(mask))
254362306a36Sopenharmony_ci
254462306a36Sopenharmony_ci#define RMWREG32(reg, val, mask) RMWREG32_SHIFTED(reg, (val) << __ffs(mask), mask)
254562306a36Sopenharmony_ci
254662306a36Sopenharmony_ci#define RREG32_MASK(reg, mask) ((RREG32(reg) & mask) >> __ffs(mask))
254762306a36Sopenharmony_ci
254862306a36Sopenharmony_ci#define REG_FIELD_SHIFT(reg, field) reg##_##field##_SHIFT
254962306a36Sopenharmony_ci#define REG_FIELD_MASK(reg, field) reg##_##field##_MASK
255062306a36Sopenharmony_ci#define WREG32_FIELD(reg, offset, field, val)	\
255162306a36Sopenharmony_ci	WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & \
255262306a36Sopenharmony_ci				~REG_FIELD_MASK(reg, field)) | \
255362306a36Sopenharmony_ci				(val) << REG_FIELD_SHIFT(reg, field))
255462306a36Sopenharmony_ci
255562306a36Sopenharmony_ci/* Timeout should be longer when working with simulator but cap the
255662306a36Sopenharmony_ci * increased timeout to some maximum
255762306a36Sopenharmony_ci */
255862306a36Sopenharmony_ci#define hl_poll_timeout_common(hdev, addr, val, cond, sleep_us, timeout_us, elbi) \
255962306a36Sopenharmony_ci({ \
256062306a36Sopenharmony_ci	ktime_t __timeout; \
256162306a36Sopenharmony_ci	u32 __elbi_read; \
256262306a36Sopenharmony_ci	int __rc = 0; \
256362306a36Sopenharmony_ci	__timeout = ktime_add_us(ktime_get(), timeout_us); \
256462306a36Sopenharmony_ci	might_sleep_if(sleep_us); \
256562306a36Sopenharmony_ci	for (;;) { \
256662306a36Sopenharmony_ci		if (elbi) { \
256762306a36Sopenharmony_ci			__rc = hl_pci_elbi_read(hdev, addr, &__elbi_read); \
256862306a36Sopenharmony_ci			if (__rc) \
256962306a36Sopenharmony_ci				break; \
257062306a36Sopenharmony_ci			(val) = __elbi_read; \
257162306a36Sopenharmony_ci		} else {\
257262306a36Sopenharmony_ci			(val) = RREG32(lower_32_bits(addr)); \
257362306a36Sopenharmony_ci		} \
257462306a36Sopenharmony_ci		if (cond) \
257562306a36Sopenharmony_ci			break; \
257662306a36Sopenharmony_ci		if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \
257762306a36Sopenharmony_ci			if (elbi) { \
257862306a36Sopenharmony_ci				__rc = hl_pci_elbi_read(hdev, addr, &__elbi_read); \
257962306a36Sopenharmony_ci				if (__rc) \
258062306a36Sopenharmony_ci					break; \
258162306a36Sopenharmony_ci				(val) = __elbi_read; \
258262306a36Sopenharmony_ci			} else {\
258362306a36Sopenharmony_ci				(val) = RREG32(lower_32_bits(addr)); \
258462306a36Sopenharmony_ci			} \
258562306a36Sopenharmony_ci			break; \
258662306a36Sopenharmony_ci		} \
258762306a36Sopenharmony_ci		if (sleep_us) \
258862306a36Sopenharmony_ci			usleep_range((sleep_us >> 2) + 1, sleep_us); \
258962306a36Sopenharmony_ci	} \
259062306a36Sopenharmony_ci	__rc ? __rc : ((cond) ? 0 : -ETIMEDOUT); \
259162306a36Sopenharmony_ci})
259262306a36Sopenharmony_ci
259362306a36Sopenharmony_ci#define hl_poll_timeout(hdev, addr, val, cond, sleep_us, timeout_us) \
259462306a36Sopenharmony_ci		hl_poll_timeout_common(hdev, addr, val, cond, sleep_us, timeout_us, false)
259562306a36Sopenharmony_ci
259662306a36Sopenharmony_ci#define hl_poll_timeout_elbi(hdev, addr, val, cond, sleep_us, timeout_us) \
259762306a36Sopenharmony_ci		hl_poll_timeout_common(hdev, addr, val, cond, sleep_us, timeout_us, true)
259862306a36Sopenharmony_ci
259962306a36Sopenharmony_ci/*
260062306a36Sopenharmony_ci * poll array of register addresses.
260162306a36Sopenharmony_ci * condition is satisfied if all registers values match the expected value.
260262306a36Sopenharmony_ci * once some register in the array satisfies the condition it will not be polled again,
260362306a36Sopenharmony_ci * this is done both for efficiency and due to some registers are "clear on read".
260462306a36Sopenharmony_ci * TODO: use read from PCI bar in other places in the code (SW-91406)
260562306a36Sopenharmony_ci */
260662306a36Sopenharmony_ci#define hl_poll_reg_array_timeout_common(hdev, addr_arr, arr_size, expected_val, sleep_us, \
260762306a36Sopenharmony_ci						timeout_us, elbi) \
260862306a36Sopenharmony_ci({ \
260962306a36Sopenharmony_ci	ktime_t __timeout; \
261062306a36Sopenharmony_ci	u64 __elem_bitmask; \
261162306a36Sopenharmony_ci	u32 __read_val;	\
261262306a36Sopenharmony_ci	u8 __arr_idx;	\
261362306a36Sopenharmony_ci	int __rc = 0; \
261462306a36Sopenharmony_ci	\
261562306a36Sopenharmony_ci	__timeout = ktime_add_us(ktime_get(), timeout_us); \
261662306a36Sopenharmony_ci	might_sleep_if(sleep_us); \
261762306a36Sopenharmony_ci	if (arr_size >= 64) \
261862306a36Sopenharmony_ci		__rc = -EINVAL; \
261962306a36Sopenharmony_ci	else \
262062306a36Sopenharmony_ci		__elem_bitmask = BIT_ULL(arr_size) - 1; \
262162306a36Sopenharmony_ci	for (;;) { \
262262306a36Sopenharmony_ci		if (__rc) \
262362306a36Sopenharmony_ci			break; \
262462306a36Sopenharmony_ci		for (__arr_idx = 0; __arr_idx < (arr_size); __arr_idx++) {	\
262562306a36Sopenharmony_ci			if (!(__elem_bitmask & BIT_ULL(__arr_idx)))	\
262662306a36Sopenharmony_ci				continue;	\
262762306a36Sopenharmony_ci			if (elbi) { \
262862306a36Sopenharmony_ci				__rc = hl_pci_elbi_read(hdev, (addr_arr)[__arr_idx], &__read_val); \
262962306a36Sopenharmony_ci				if (__rc) \
263062306a36Sopenharmony_ci					break; \
263162306a36Sopenharmony_ci			} else { \
263262306a36Sopenharmony_ci				__read_val = RREG32(lower_32_bits(addr_arr[__arr_idx])); \
263362306a36Sopenharmony_ci			} \
263462306a36Sopenharmony_ci			if (__read_val == (expected_val))	\
263562306a36Sopenharmony_ci				__elem_bitmask &= ~BIT_ULL(__arr_idx);	\
263662306a36Sopenharmony_ci		}	\
263762306a36Sopenharmony_ci		if (__rc || (__elem_bitmask == 0)) \
263862306a36Sopenharmony_ci			break; \
263962306a36Sopenharmony_ci		if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) \
264062306a36Sopenharmony_ci			break; \
264162306a36Sopenharmony_ci		if (sleep_us) \
264262306a36Sopenharmony_ci			usleep_range((sleep_us >> 2) + 1, sleep_us); \
264362306a36Sopenharmony_ci	} \
264462306a36Sopenharmony_ci	__rc ? __rc : ((__elem_bitmask == 0) ? 0 : -ETIMEDOUT); \
264562306a36Sopenharmony_ci})
264662306a36Sopenharmony_ci
264762306a36Sopenharmony_ci#define hl_poll_reg_array_timeout(hdev, addr_arr, arr_size, expected_val, sleep_us, \
264862306a36Sopenharmony_ci					timeout_us) \
264962306a36Sopenharmony_ci	hl_poll_reg_array_timeout_common(hdev, addr_arr, arr_size, expected_val, sleep_us, \
265062306a36Sopenharmony_ci						timeout_us, false)
265162306a36Sopenharmony_ci
265262306a36Sopenharmony_ci#define hl_poll_reg_array_timeout_elbi(hdev, addr_arr, arr_size, expected_val, sleep_us, \
265362306a36Sopenharmony_ci					timeout_us) \
265462306a36Sopenharmony_ci	hl_poll_reg_array_timeout_common(hdev, addr_arr, arr_size, expected_val, sleep_us, \
265562306a36Sopenharmony_ci						timeout_us, true)
265662306a36Sopenharmony_ci
265762306a36Sopenharmony_ci/*
265862306a36Sopenharmony_ci * address in this macro points always to a memory location in the
265962306a36Sopenharmony_ci * host's (server's) memory. That location is updated asynchronously
266062306a36Sopenharmony_ci * either by the direct access of the device or by another core.
266162306a36Sopenharmony_ci *
266262306a36Sopenharmony_ci * To work both in LE and BE architectures, we need to distinguish between the
266362306a36Sopenharmony_ci * two states (device or another core updates the memory location). Therefore,
266462306a36Sopenharmony_ci * if mem_written_by_device is true, the host memory being polled will be
266562306a36Sopenharmony_ci * updated directly by the device. If false, the host memory being polled will
266662306a36Sopenharmony_ci * be updated by host CPU. Required so host knows whether or not the memory
266762306a36Sopenharmony_ci * might need to be byte-swapped before returning value to caller.
266862306a36Sopenharmony_ci */
266962306a36Sopenharmony_ci#define hl_poll_timeout_memory(hdev, addr, val, cond, sleep_us, timeout_us, \
267062306a36Sopenharmony_ci				mem_written_by_device) \
267162306a36Sopenharmony_ci({ \
267262306a36Sopenharmony_ci	ktime_t __timeout; \
267362306a36Sopenharmony_ci	\
267462306a36Sopenharmony_ci	__timeout = ktime_add_us(ktime_get(), timeout_us); \
267562306a36Sopenharmony_ci	might_sleep_if(sleep_us); \
267662306a36Sopenharmony_ci	for (;;) { \
267762306a36Sopenharmony_ci		/* Verify we read updates done by other cores or by device */ \
267862306a36Sopenharmony_ci		mb(); \
267962306a36Sopenharmony_ci		(val) = *((u32 *)(addr)); \
268062306a36Sopenharmony_ci		if (mem_written_by_device) \
268162306a36Sopenharmony_ci			(val) = le32_to_cpu(*(__le32 *) &(val)); \
268262306a36Sopenharmony_ci		if (cond) \
268362306a36Sopenharmony_ci			break; \
268462306a36Sopenharmony_ci		if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \
268562306a36Sopenharmony_ci			(val) = *((u32 *)(addr)); \
268662306a36Sopenharmony_ci			if (mem_written_by_device) \
268762306a36Sopenharmony_ci				(val) = le32_to_cpu(*(__le32 *) &(val)); \
268862306a36Sopenharmony_ci			break; \
268962306a36Sopenharmony_ci		} \
269062306a36Sopenharmony_ci		if (sleep_us) \
269162306a36Sopenharmony_ci			usleep_range((sleep_us >> 2) + 1, sleep_us); \
269262306a36Sopenharmony_ci	} \
269362306a36Sopenharmony_ci	(cond) ? 0 : -ETIMEDOUT; \
269462306a36Sopenharmony_ci})
269562306a36Sopenharmony_ci
269662306a36Sopenharmony_ci#define HL_USR_MAPPED_BLK_INIT(blk, base, sz) \
269762306a36Sopenharmony_ci({ \
269862306a36Sopenharmony_ci	struct user_mapped_block *p = blk; \
269962306a36Sopenharmony_ci\
270062306a36Sopenharmony_ci	p->address = base; \
270162306a36Sopenharmony_ci	p->size = sz; \
270262306a36Sopenharmony_ci})
270362306a36Sopenharmony_ci
270462306a36Sopenharmony_ci#define HL_USR_INTR_STRUCT_INIT(usr_intr, hdev, intr_id, intr_type) \
270562306a36Sopenharmony_ci({ \
270662306a36Sopenharmony_ci	usr_intr.hdev = hdev; \
270762306a36Sopenharmony_ci	usr_intr.interrupt_id = intr_id; \
270862306a36Sopenharmony_ci	usr_intr.type = intr_type; \
270962306a36Sopenharmony_ci	INIT_LIST_HEAD(&usr_intr.wait_list_head); \
271062306a36Sopenharmony_ci	spin_lock_init(&usr_intr.wait_list_lock); \
271162306a36Sopenharmony_ci})
271262306a36Sopenharmony_ci
271362306a36Sopenharmony_cistruct hwmon_chip_info;
271462306a36Sopenharmony_ci
271562306a36Sopenharmony_ci/**
271662306a36Sopenharmony_ci * struct hl_device_reset_work - reset work wrapper.
271762306a36Sopenharmony_ci * @reset_work: reset work to be done.
271862306a36Sopenharmony_ci * @hdev: habanalabs device structure.
271962306a36Sopenharmony_ci * @flags: reset flags.
272062306a36Sopenharmony_ci */
272162306a36Sopenharmony_cistruct hl_device_reset_work {
272262306a36Sopenharmony_ci	struct delayed_work	reset_work;
272362306a36Sopenharmony_ci	struct hl_device	*hdev;
272462306a36Sopenharmony_ci	u32			flags;
272562306a36Sopenharmony_ci};
272662306a36Sopenharmony_ci
272762306a36Sopenharmony_ci/**
272862306a36Sopenharmony_ci * struct hl_mmu_hr_pgt_priv - used for holding per-device mmu host-resident
272962306a36Sopenharmony_ci * page-table internal information.
273062306a36Sopenharmony_ci * @mmu_pgt_pool: pool of page tables used by a host-resident MMU for
273162306a36Sopenharmony_ci *                allocating hops.
273262306a36Sopenharmony_ci * @mmu_asid_hop0: per-ASID array of host-resident hop0 tables.
273362306a36Sopenharmony_ci */
273462306a36Sopenharmony_cistruct hl_mmu_hr_priv {
273562306a36Sopenharmony_ci	struct gen_pool	*mmu_pgt_pool;
273662306a36Sopenharmony_ci	struct pgt_info	*mmu_asid_hop0;
273762306a36Sopenharmony_ci};
273862306a36Sopenharmony_ci
273962306a36Sopenharmony_ci/**
274062306a36Sopenharmony_ci * struct hl_mmu_dr_pgt_priv - used for holding per-device mmu device-resident
274162306a36Sopenharmony_ci * page-table internal information.
274262306a36Sopenharmony_ci * @mmu_pgt_pool: pool of page tables used by MMU for allocating hops.
274362306a36Sopenharmony_ci * @mmu_shadow_hop0: shadow array of hop0 tables.
274462306a36Sopenharmony_ci */
274562306a36Sopenharmony_cistruct hl_mmu_dr_priv {
274662306a36Sopenharmony_ci	struct gen_pool *mmu_pgt_pool;
274762306a36Sopenharmony_ci	void *mmu_shadow_hop0;
274862306a36Sopenharmony_ci};
274962306a36Sopenharmony_ci
275062306a36Sopenharmony_ci/**
275162306a36Sopenharmony_ci * struct hl_mmu_priv - used for holding per-device mmu internal information.
275262306a36Sopenharmony_ci * @dr: information on the device-resident MMU, when exists.
275362306a36Sopenharmony_ci * @hr: information on the host-resident MMU, when exists.
275462306a36Sopenharmony_ci */
275562306a36Sopenharmony_cistruct hl_mmu_priv {
275662306a36Sopenharmony_ci	struct hl_mmu_dr_priv dr;
275762306a36Sopenharmony_ci	struct hl_mmu_hr_priv hr;
275862306a36Sopenharmony_ci};
275962306a36Sopenharmony_ci
276062306a36Sopenharmony_ci/**
276162306a36Sopenharmony_ci * struct hl_mmu_per_hop_info - A structure describing one TLB HOP and its entry
276262306a36Sopenharmony_ci *                that was created in order to translate a virtual address to a
276362306a36Sopenharmony_ci *                physical one.
276462306a36Sopenharmony_ci * @hop_addr: The address of the hop.
276562306a36Sopenharmony_ci * @hop_pte_addr: The address of the hop entry.
276662306a36Sopenharmony_ci * @hop_pte_val: The value in the hop entry.
276762306a36Sopenharmony_ci */
276862306a36Sopenharmony_cistruct hl_mmu_per_hop_info {
276962306a36Sopenharmony_ci	u64 hop_addr;
277062306a36Sopenharmony_ci	u64 hop_pte_addr;
277162306a36Sopenharmony_ci	u64 hop_pte_val;
277262306a36Sopenharmony_ci};
277362306a36Sopenharmony_ci
277462306a36Sopenharmony_ci/**
277562306a36Sopenharmony_ci * struct hl_mmu_hop_info - A structure describing the TLB hops and their
277662306a36Sopenharmony_ci * hop-entries that were created in order to translate a virtual address to a
277762306a36Sopenharmony_ci * physical one.
277862306a36Sopenharmony_ci * @scrambled_vaddr: The value of the virtual address after scrambling. This
277962306a36Sopenharmony_ci *                   address replaces the original virtual-address when mapped
278062306a36Sopenharmony_ci *                   in the MMU tables.
278162306a36Sopenharmony_ci * @unscrambled_paddr: The un-scrambled physical address.
278262306a36Sopenharmony_ci * @hop_info: Array holding the per-hop information used for the translation.
278362306a36Sopenharmony_ci * @used_hops: The number of hops used for the translation.
278462306a36Sopenharmony_ci * @range_type: virtual address range type.
278562306a36Sopenharmony_ci */
278662306a36Sopenharmony_cistruct hl_mmu_hop_info {
278762306a36Sopenharmony_ci	u64 scrambled_vaddr;
278862306a36Sopenharmony_ci	u64 unscrambled_paddr;
278962306a36Sopenharmony_ci	struct hl_mmu_per_hop_info hop_info[MMU_ARCH_6_HOPS];
279062306a36Sopenharmony_ci	u32 used_hops;
279162306a36Sopenharmony_ci	enum hl_va_range_type range_type;
279262306a36Sopenharmony_ci};
279362306a36Sopenharmony_ci
279462306a36Sopenharmony_ci/**
279562306a36Sopenharmony_ci * struct hl_hr_mmu_funcs - Device related host resident MMU functions.
279662306a36Sopenharmony_ci * @get_hop0_pgt_info: get page table info structure for HOP0.
279762306a36Sopenharmony_ci * @get_pgt_info: get page table info structure for HOP other than HOP0.
279862306a36Sopenharmony_ci * @add_pgt_info: add page table info structure to hash.
279962306a36Sopenharmony_ci * @get_tlb_mapping_params: get mapping parameters needed for getting TLB info for specific mapping.
280062306a36Sopenharmony_ci */
280162306a36Sopenharmony_cistruct hl_hr_mmu_funcs {
280262306a36Sopenharmony_ci	struct pgt_info *(*get_hop0_pgt_info)(struct hl_ctx *ctx);
280362306a36Sopenharmony_ci	struct pgt_info *(*get_pgt_info)(struct hl_ctx *ctx, u64 phys_hop_addr);
280462306a36Sopenharmony_ci	void (*add_pgt_info)(struct hl_ctx *ctx, struct pgt_info *pgt_info, dma_addr_t phys_addr);
280562306a36Sopenharmony_ci	int (*get_tlb_mapping_params)(struct hl_device *hdev, struct hl_mmu_properties **mmu_prop,
280662306a36Sopenharmony_ci								struct hl_mmu_hop_info *hops,
280762306a36Sopenharmony_ci								u64 virt_addr, bool *is_huge);
280862306a36Sopenharmony_ci};
280962306a36Sopenharmony_ci
281062306a36Sopenharmony_ci/**
281162306a36Sopenharmony_ci * struct hl_mmu_funcs - Device related MMU functions.
281262306a36Sopenharmony_ci * @init: initialize the MMU module.
281362306a36Sopenharmony_ci * @fini: release the MMU module.
281462306a36Sopenharmony_ci * @ctx_init: Initialize a context for using the MMU module.
281562306a36Sopenharmony_ci * @ctx_fini: disable a ctx from using the mmu module.
281662306a36Sopenharmony_ci * @map: maps a virtual address to physical address for a context.
281762306a36Sopenharmony_ci * @unmap: unmap a virtual address of a context.
281862306a36Sopenharmony_ci * @flush: flush all writes from all cores to reach device MMU.
281962306a36Sopenharmony_ci * @swap_out: marks all mapping of the given context as swapped out.
282062306a36Sopenharmony_ci * @swap_in: marks all mapping of the given context as swapped in.
282162306a36Sopenharmony_ci * @get_tlb_info: returns the list of hops and hop-entries used that were
282262306a36Sopenharmony_ci *                created in order to translate the giver virtual address to a
282362306a36Sopenharmony_ci *                physical one.
282462306a36Sopenharmony_ci * @hr_funcs: functions specific to host resident MMU.
282562306a36Sopenharmony_ci */
282662306a36Sopenharmony_cistruct hl_mmu_funcs {
282762306a36Sopenharmony_ci	int (*init)(struct hl_device *hdev);
282862306a36Sopenharmony_ci	void (*fini)(struct hl_device *hdev);
282962306a36Sopenharmony_ci	int (*ctx_init)(struct hl_ctx *ctx);
283062306a36Sopenharmony_ci	void (*ctx_fini)(struct hl_ctx *ctx);
283162306a36Sopenharmony_ci	int (*map)(struct hl_ctx *ctx, u64 virt_addr, u64 phys_addr, u32 page_size,
283262306a36Sopenharmony_ci				bool is_dram_addr);
283362306a36Sopenharmony_ci	int (*unmap)(struct hl_ctx *ctx, u64 virt_addr, bool is_dram_addr);
283462306a36Sopenharmony_ci	void (*flush)(struct hl_ctx *ctx);
283562306a36Sopenharmony_ci	void (*swap_out)(struct hl_ctx *ctx);
283662306a36Sopenharmony_ci	void (*swap_in)(struct hl_ctx *ctx);
283762306a36Sopenharmony_ci	int (*get_tlb_info)(struct hl_ctx *ctx, u64 virt_addr, struct hl_mmu_hop_info *hops);
283862306a36Sopenharmony_ci	struct hl_hr_mmu_funcs hr_funcs;
283962306a36Sopenharmony_ci};
284062306a36Sopenharmony_ci
284162306a36Sopenharmony_ci/**
284262306a36Sopenharmony_ci * struct hl_prefetch_work - prefetch work structure handler
284362306a36Sopenharmony_ci * @prefetch_work: actual work struct.
284462306a36Sopenharmony_ci * @ctx: compute context.
284562306a36Sopenharmony_ci * @va: virtual address to pre-fetch.
284662306a36Sopenharmony_ci * @size: pre-fetch size.
284762306a36Sopenharmony_ci * @flags: operation flags.
284862306a36Sopenharmony_ci * @asid: ASID for maintenance operation.
284962306a36Sopenharmony_ci */
285062306a36Sopenharmony_cistruct hl_prefetch_work {
285162306a36Sopenharmony_ci	struct work_struct	prefetch_work;
285262306a36Sopenharmony_ci	struct hl_ctx		*ctx;
285362306a36Sopenharmony_ci	u64			va;
285462306a36Sopenharmony_ci	u64			size;
285562306a36Sopenharmony_ci	u32			flags;
285662306a36Sopenharmony_ci	u32			asid;
285762306a36Sopenharmony_ci};
285862306a36Sopenharmony_ci
285962306a36Sopenharmony_ci/*
286062306a36Sopenharmony_ci * number of user contexts allowed to call wait_for_multi_cs ioctl in
286162306a36Sopenharmony_ci * parallel
286262306a36Sopenharmony_ci */
286362306a36Sopenharmony_ci#define MULTI_CS_MAX_USER_CTX	2
286462306a36Sopenharmony_ci
286562306a36Sopenharmony_ci/**
286662306a36Sopenharmony_ci * struct multi_cs_completion - multi CS wait completion.
286762306a36Sopenharmony_ci * @completion: completion of any of the CS in the list
286862306a36Sopenharmony_ci * @lock: spinlock for the completion structure
286962306a36Sopenharmony_ci * @timestamp: timestamp for the multi-CS completion
287062306a36Sopenharmony_ci * @stream_master_qid_map: bitmap of all stream masters on which the multi-CS
287162306a36Sopenharmony_ci *                        is waiting
287262306a36Sopenharmony_ci * @used: 1 if in use, otherwise 0
287362306a36Sopenharmony_ci */
287462306a36Sopenharmony_cistruct multi_cs_completion {
287562306a36Sopenharmony_ci	struct completion	completion;
287662306a36Sopenharmony_ci	spinlock_t		lock;
287762306a36Sopenharmony_ci	s64			timestamp;
287862306a36Sopenharmony_ci	u32			stream_master_qid_map;
287962306a36Sopenharmony_ci	u8			used;
288062306a36Sopenharmony_ci};
288162306a36Sopenharmony_ci
288262306a36Sopenharmony_ci/**
288362306a36Sopenharmony_ci * struct multi_cs_data - internal data for multi CS call
288462306a36Sopenharmony_ci * @ctx: pointer to the context structure
288562306a36Sopenharmony_ci * @fence_arr: array of fences of all CSs
288662306a36Sopenharmony_ci * @seq_arr: array of CS sequence numbers
288762306a36Sopenharmony_ci * @timeout_jiffies: timeout in jiffies for waiting for CS to complete
288862306a36Sopenharmony_ci * @timestamp: timestamp of first completed CS
288962306a36Sopenharmony_ci * @wait_status: wait for CS status
289062306a36Sopenharmony_ci * @completion_bitmap: bitmap of completed CSs (1- completed, otherwise 0)
289162306a36Sopenharmony_ci * @arr_len: fence_arr and seq_arr array length
289262306a36Sopenharmony_ci * @gone_cs: indication of gone CS (1- there was gone CS, otherwise 0)
289362306a36Sopenharmony_ci * @update_ts: update timestamp. 1- update the timestamp, otherwise 0.
289462306a36Sopenharmony_ci */
289562306a36Sopenharmony_cistruct multi_cs_data {
289662306a36Sopenharmony_ci	struct hl_ctx	*ctx;
289762306a36Sopenharmony_ci	struct hl_fence	**fence_arr;
289862306a36Sopenharmony_ci	u64		*seq_arr;
289962306a36Sopenharmony_ci	s64		timeout_jiffies;
290062306a36Sopenharmony_ci	s64		timestamp;
290162306a36Sopenharmony_ci	long		wait_status;
290262306a36Sopenharmony_ci	u32		completion_bitmap;
290362306a36Sopenharmony_ci	u8		arr_len;
290462306a36Sopenharmony_ci	u8		gone_cs;
290562306a36Sopenharmony_ci	u8		update_ts;
290662306a36Sopenharmony_ci};
290762306a36Sopenharmony_ci
290862306a36Sopenharmony_ci/**
290962306a36Sopenharmony_ci * struct hl_clk_throttle_timestamp - current/last clock throttling timestamp
291062306a36Sopenharmony_ci * @start: timestamp taken when 'start' event is received in driver
291162306a36Sopenharmony_ci * @end: timestamp taken when 'end' event is received in driver
291262306a36Sopenharmony_ci */
291362306a36Sopenharmony_cistruct hl_clk_throttle_timestamp {
291462306a36Sopenharmony_ci	ktime_t		start;
291562306a36Sopenharmony_ci	ktime_t		end;
291662306a36Sopenharmony_ci};
291762306a36Sopenharmony_ci
291862306a36Sopenharmony_ci/**
291962306a36Sopenharmony_ci * struct hl_clk_throttle - keeps current/last clock throttling timestamps
292062306a36Sopenharmony_ci * @timestamp: timestamp taken by driver and firmware, index 0 refers to POWER
292162306a36Sopenharmony_ci *             index 1 refers to THERMAL
292262306a36Sopenharmony_ci * @lock: protects this structure as it can be accessed from both event queue
292362306a36Sopenharmony_ci *        context and info_ioctl context
292462306a36Sopenharmony_ci * @current_reason: bitmask represents the current clk throttling reasons
292562306a36Sopenharmony_ci * @aggregated_reason: bitmask represents aggregated clk throttling reasons since driver load
292662306a36Sopenharmony_ci */
292762306a36Sopenharmony_cistruct hl_clk_throttle {
292862306a36Sopenharmony_ci	struct hl_clk_throttle_timestamp timestamp[HL_CLK_THROTTLE_TYPE_MAX];
292962306a36Sopenharmony_ci	struct mutex	lock;
293062306a36Sopenharmony_ci	u32		current_reason;
293162306a36Sopenharmony_ci	u32		aggregated_reason;
293262306a36Sopenharmony_ci};
293362306a36Sopenharmony_ci
293462306a36Sopenharmony_ci/**
293562306a36Sopenharmony_ci * struct user_mapped_block - describes a hw block allowed to be mmapped by user
293662306a36Sopenharmony_ci * @address: physical HW block address
293762306a36Sopenharmony_ci * @size: allowed size for mmap
293862306a36Sopenharmony_ci */
293962306a36Sopenharmony_cistruct user_mapped_block {
294062306a36Sopenharmony_ci	u32 address;
294162306a36Sopenharmony_ci	u32 size;
294262306a36Sopenharmony_ci};
294362306a36Sopenharmony_ci
294462306a36Sopenharmony_ci/**
294562306a36Sopenharmony_ci * struct cs_timeout_info - info of last CS timeout occurred.
294662306a36Sopenharmony_ci * @timestamp: CS timeout timestamp.
294762306a36Sopenharmony_ci * @write_enable: if set writing to CS parameters in the structure is enabled. otherwise - disabled,
294862306a36Sopenharmony_ci *                so the first (root cause) CS timeout will not be overwritten.
294962306a36Sopenharmony_ci * @seq: CS timeout sequence number.
295062306a36Sopenharmony_ci */
295162306a36Sopenharmony_cistruct cs_timeout_info {
295262306a36Sopenharmony_ci	ktime_t		timestamp;
295362306a36Sopenharmony_ci	atomic_t	write_enable;
295462306a36Sopenharmony_ci	u64		seq;
295562306a36Sopenharmony_ci};
295662306a36Sopenharmony_ci
295762306a36Sopenharmony_ci#define MAX_QMAN_STREAMS_INFO		4
295862306a36Sopenharmony_ci#define OPCODE_INFO_MAX_ADDR_SIZE	8
295962306a36Sopenharmony_ci/**
296062306a36Sopenharmony_ci * struct undefined_opcode_info - info about last undefined opcode error
296162306a36Sopenharmony_ci * @timestamp: timestamp of the undefined opcode error
296262306a36Sopenharmony_ci * @cb_addr_streams: CB addresses (per stream) that are currently exists in the PQ
296362306a36Sopenharmony_ci *                   entries. In case all streams array entries are
296462306a36Sopenharmony_ci *                   filled with values, it means the execution was in Lower-CP.
296562306a36Sopenharmony_ci * @cq_addr: the address of the current handled command buffer
296662306a36Sopenharmony_ci * @cq_size: the size of the current handled command buffer
296762306a36Sopenharmony_ci * @cb_addr_streams_len: num of streams - actual len of cb_addr_streams array.
296862306a36Sopenharmony_ci *                       should be equal to 1 in case of undefined opcode
296962306a36Sopenharmony_ci *                       in Upper-CP (specific stream) and equal to 4 in case
297062306a36Sopenharmony_ci *                       of undefined opcode in Lower-CP.
297162306a36Sopenharmony_ci * @engine_id: engine-id that the error occurred on
297262306a36Sopenharmony_ci * @stream_id: the stream id the error occurred on. In case the stream equals to
297362306a36Sopenharmony_ci *             MAX_QMAN_STREAMS_INFO it means the error occurred on a Lower-CP.
297462306a36Sopenharmony_ci * @write_enable: if set, writing to undefined opcode parameters in the structure
297562306a36Sopenharmony_ci *                 is enable so the first (root cause) undefined opcode will not be
297662306a36Sopenharmony_ci *                 overwritten.
297762306a36Sopenharmony_ci */
297862306a36Sopenharmony_cistruct undefined_opcode_info {
297962306a36Sopenharmony_ci	ktime_t timestamp;
298062306a36Sopenharmony_ci	u64 cb_addr_streams[MAX_QMAN_STREAMS_INFO][OPCODE_INFO_MAX_ADDR_SIZE];
298162306a36Sopenharmony_ci	u64 cq_addr;
298262306a36Sopenharmony_ci	u32 cq_size;
298362306a36Sopenharmony_ci	u32 cb_addr_streams_len;
298462306a36Sopenharmony_ci	u32 engine_id;
298562306a36Sopenharmony_ci	u32 stream_id;
298662306a36Sopenharmony_ci	bool write_enable;
298762306a36Sopenharmony_ci};
298862306a36Sopenharmony_ci
298962306a36Sopenharmony_ci/**
299062306a36Sopenharmony_ci * struct page_fault_info - page fault information.
299162306a36Sopenharmony_ci * @page_fault: holds information collected during a page fault.
299262306a36Sopenharmony_ci * @user_mappings: buffer containing user mappings.
299362306a36Sopenharmony_ci * @num_of_user_mappings: number of user mappings.
299462306a36Sopenharmony_ci * @page_fault_detected: if set as 1, then a page-fault was discovered for the
299562306a36Sopenharmony_ci *                       first time after the driver has finished booting-up.
299662306a36Sopenharmony_ci *                       Since we're looking for the page-fault's root cause,
299762306a36Sopenharmony_ci *                       we don't care of the others that might follow it-
299862306a36Sopenharmony_ci *                       so once changed to 1, it will remain that way.
299962306a36Sopenharmony_ci * @page_fault_info_available: indicates that a page fault info is now available.
300062306a36Sopenharmony_ci */
300162306a36Sopenharmony_cistruct page_fault_info {
300262306a36Sopenharmony_ci	struct hl_page_fault_info	page_fault;
300362306a36Sopenharmony_ci	struct hl_user_mapping		*user_mappings;
300462306a36Sopenharmony_ci	u64				num_of_user_mappings;
300562306a36Sopenharmony_ci	atomic_t			page_fault_detected;
300662306a36Sopenharmony_ci	bool				page_fault_info_available;
300762306a36Sopenharmony_ci};
300862306a36Sopenharmony_ci
300962306a36Sopenharmony_ci/**
301062306a36Sopenharmony_ci * struct razwi_info - RAZWI information.
301162306a36Sopenharmony_ci * @razwi: holds information collected during a RAZWI
301262306a36Sopenharmony_ci * @razwi_detected: if set as 1, then a RAZWI was discovered for the
301362306a36Sopenharmony_ci *                  first time after the driver has finished booting-up.
301462306a36Sopenharmony_ci *                  Since we're looking for the RAZWI's root cause,
301562306a36Sopenharmony_ci *                  we don't care of the others that might follow it-
301662306a36Sopenharmony_ci *                  so once changed to 1, it will remain that way.
301762306a36Sopenharmony_ci * @razwi_info_available: indicates that a RAZWI info is now available.
301862306a36Sopenharmony_ci */
301962306a36Sopenharmony_cistruct razwi_info {
302062306a36Sopenharmony_ci	struct hl_info_razwi_event	razwi;
302162306a36Sopenharmony_ci	atomic_t			razwi_detected;
302262306a36Sopenharmony_ci	bool				razwi_info_available;
302362306a36Sopenharmony_ci};
302462306a36Sopenharmony_ci
302562306a36Sopenharmony_ci/**
302662306a36Sopenharmony_ci * struct hw_err_info - HW error information.
302762306a36Sopenharmony_ci * @event: holds information on the event.
302862306a36Sopenharmony_ci * @event_detected: if set as 1, then a HW event was discovered for the
302962306a36Sopenharmony_ci *                  first time after the driver has finished booting-up.
303062306a36Sopenharmony_ci *                  currently we assume that only fatal events (that require hard-reset) are
303162306a36Sopenharmony_ci *                  reported so we don't care of the others that might follow it.
303262306a36Sopenharmony_ci *                  so once changed to 1, it will remain that way.
303362306a36Sopenharmony_ci *                  TODO: support multiple events.
303462306a36Sopenharmony_ci * @event_info_available: indicates that a HW event info is now available.
303562306a36Sopenharmony_ci */
303662306a36Sopenharmony_cistruct hw_err_info {
303762306a36Sopenharmony_ci	struct hl_info_hw_err_event	event;
303862306a36Sopenharmony_ci	atomic_t			event_detected;
303962306a36Sopenharmony_ci	bool				event_info_available;
304062306a36Sopenharmony_ci};
304162306a36Sopenharmony_ci
304262306a36Sopenharmony_ci/**
304362306a36Sopenharmony_ci * struct fw_err_info - FW error information.
304462306a36Sopenharmony_ci * @event: holds information on the event.
304562306a36Sopenharmony_ci * @event_detected: if set as 1, then a FW event was discovered for the
304662306a36Sopenharmony_ci *                  first time after the driver has finished booting-up.
304762306a36Sopenharmony_ci *                  currently we assume that only fatal events (that require hard-reset) are
304862306a36Sopenharmony_ci *                  reported so we don't care of the others that might follow it.
304962306a36Sopenharmony_ci *                  so once changed to 1, it will remain that way.
305062306a36Sopenharmony_ci *                  TODO: support multiple events.
305162306a36Sopenharmony_ci * @event_info_available: indicates that a HW event info is now available.
305262306a36Sopenharmony_ci */
305362306a36Sopenharmony_cistruct fw_err_info {
305462306a36Sopenharmony_ci	struct hl_info_fw_err_event	event;
305562306a36Sopenharmony_ci	atomic_t			event_detected;
305662306a36Sopenharmony_ci	bool				event_info_available;
305762306a36Sopenharmony_ci};
305862306a36Sopenharmony_ci
305962306a36Sopenharmony_ci/**
306062306a36Sopenharmony_ci * struct hl_error_info - holds information collected during an error.
306162306a36Sopenharmony_ci * @cs_timeout: CS timeout error information.
306262306a36Sopenharmony_ci * @razwi_info: RAZWI information.
306362306a36Sopenharmony_ci * @undef_opcode: undefined opcode information.
306462306a36Sopenharmony_ci * @page_fault_info: page fault information.
306562306a36Sopenharmony_ci * @hw_err: (fatal) hardware error information.
306662306a36Sopenharmony_ci * @fw_err: firmware error information.
306762306a36Sopenharmony_ci */
306862306a36Sopenharmony_cistruct hl_error_info {
306962306a36Sopenharmony_ci	struct cs_timeout_info		cs_timeout;
307062306a36Sopenharmony_ci	struct razwi_info		razwi_info;
307162306a36Sopenharmony_ci	struct undefined_opcode_info	undef_opcode;
307262306a36Sopenharmony_ci	struct page_fault_info		page_fault_info;
307362306a36Sopenharmony_ci	struct hw_err_info		hw_err;
307462306a36Sopenharmony_ci	struct fw_err_info		fw_err;
307562306a36Sopenharmony_ci};
307662306a36Sopenharmony_ci
307762306a36Sopenharmony_ci/**
307862306a36Sopenharmony_ci * struct hl_reset_info - holds current device reset information.
307962306a36Sopenharmony_ci * @lock: lock to protect critical reset flows.
308062306a36Sopenharmony_ci * @compute_reset_cnt: number of compute resets since the driver was loaded.
308162306a36Sopenharmony_ci * @hard_reset_cnt: number of hard resets since the driver was loaded.
308262306a36Sopenharmony_ci * @hard_reset_schedule_flags: hard reset is scheduled to after current compute reset,
308362306a36Sopenharmony_ci *                             here we hold the hard reset flags.
308462306a36Sopenharmony_ci * @in_reset: is device in reset flow.
308562306a36Sopenharmony_ci * @in_compute_reset: Device is currently in reset but not in hard-reset.
308662306a36Sopenharmony_ci * @needs_reset: true if reset_on_lockup is false and device should be reset
308762306a36Sopenharmony_ci *               due to lockup.
308862306a36Sopenharmony_ci * @hard_reset_pending: is there a hard reset work pending.
308962306a36Sopenharmony_ci * @curr_reset_cause: saves an enumerated reset cause when a hard reset is
309062306a36Sopenharmony_ci *                    triggered, and cleared after it is shared with preboot.
309162306a36Sopenharmony_ci * @prev_reset_trigger: saves the previous trigger which caused a reset, overridden
309262306a36Sopenharmony_ci *                      with a new value on next reset
309362306a36Sopenharmony_ci * @reset_trigger_repeated: set if device reset is triggered more than once with
309462306a36Sopenharmony_ci *                          same cause.
309562306a36Sopenharmony_ci * @skip_reset_on_timeout: Skip device reset if CS has timed out, wait for it to
309662306a36Sopenharmony_ci *                         complete instead.
309762306a36Sopenharmony_ci * @watchdog_active: true if a device release watchdog work is scheduled.
309862306a36Sopenharmony_ci */
309962306a36Sopenharmony_cistruct hl_reset_info {
310062306a36Sopenharmony_ci	spinlock_t	lock;
310162306a36Sopenharmony_ci	u32		compute_reset_cnt;
310262306a36Sopenharmony_ci	u32		hard_reset_cnt;
310362306a36Sopenharmony_ci	u32		hard_reset_schedule_flags;
310462306a36Sopenharmony_ci	u8		in_reset;
310562306a36Sopenharmony_ci	u8		in_compute_reset;
310662306a36Sopenharmony_ci	u8		needs_reset;
310762306a36Sopenharmony_ci	u8		hard_reset_pending;
310862306a36Sopenharmony_ci	u8		curr_reset_cause;
310962306a36Sopenharmony_ci	u8		prev_reset_trigger;
311062306a36Sopenharmony_ci	u8		reset_trigger_repeated;
311162306a36Sopenharmony_ci	u8		skip_reset_on_timeout;
311262306a36Sopenharmony_ci	u8		watchdog_active;
311362306a36Sopenharmony_ci};
311462306a36Sopenharmony_ci
311562306a36Sopenharmony_ci/**
311662306a36Sopenharmony_ci * struct hl_device - habanalabs device structure.
311762306a36Sopenharmony_ci * @pdev: pointer to PCI device, can be NULL in case of simulator device.
311862306a36Sopenharmony_ci * @pcie_bar_phys: array of available PCIe bars physical addresses.
311962306a36Sopenharmony_ci *		   (required only for PCI address match mode)
312062306a36Sopenharmony_ci * @pcie_bar: array of available PCIe bars virtual addresses.
312162306a36Sopenharmony_ci * @rmmio: configuration area address on SRAM.
312262306a36Sopenharmony_ci * @hclass: pointer to the habanalabs class.
312362306a36Sopenharmony_ci * @cdev: related char device.
312462306a36Sopenharmony_ci * @cdev_ctrl: char device for control operations only (INFO IOCTL)
312562306a36Sopenharmony_ci * @dev: related kernel basic device structure.
312662306a36Sopenharmony_ci * @dev_ctrl: related kernel device structure for the control device
312762306a36Sopenharmony_ci * @work_heartbeat: delayed work for CPU-CP is-alive check.
312862306a36Sopenharmony_ci * @device_reset_work: delayed work which performs hard reset
312962306a36Sopenharmony_ci * @device_release_watchdog_work: watchdog work that performs hard reset if user doesn't release
313062306a36Sopenharmony_ci *                                device upon certain error cases.
313162306a36Sopenharmony_ci * @asic_name: ASIC specific name.
313262306a36Sopenharmony_ci * @asic_type: ASIC specific type.
313362306a36Sopenharmony_ci * @completion_queue: array of hl_cq.
313462306a36Sopenharmony_ci * @user_interrupt: array of hl_user_interrupt. upon the corresponding user
313562306a36Sopenharmony_ci *                  interrupt, driver will monitor the list of fences
313662306a36Sopenharmony_ci *                  registered to this interrupt.
313762306a36Sopenharmony_ci * @tpc_interrupt: single TPC interrupt for all TPCs.
313862306a36Sopenharmony_ci * @unexpected_error_interrupt: single interrupt for unexpected user error indication.
313962306a36Sopenharmony_ci * @common_user_cq_interrupt: common user CQ interrupt for all user CQ interrupts.
314062306a36Sopenharmony_ci *                         upon any user CQ interrupt, driver will monitor the
314162306a36Sopenharmony_ci *                         list of fences registered to this common structure.
314262306a36Sopenharmony_ci * @common_decoder_interrupt: common decoder interrupt for all user decoder interrupts.
314362306a36Sopenharmony_ci * @shadow_cs_queue: pointer to a shadow queue that holds pointers to
314462306a36Sopenharmony_ci *                   outstanding command submissions.
314562306a36Sopenharmony_ci * @cq_wq: work queues of completion queues for executing work in process
314662306a36Sopenharmony_ci *         context.
314762306a36Sopenharmony_ci * @eq_wq: work queue of event queue for executing work in process context.
314862306a36Sopenharmony_ci * @cs_cmplt_wq: work queue of CS completions for executing work in process
314962306a36Sopenharmony_ci *               context.
315062306a36Sopenharmony_ci * @ts_free_obj_wq: work queue for timestamp registration objects release.
315162306a36Sopenharmony_ci * @prefetch_wq: work queue for MMU pre-fetch operations.
315262306a36Sopenharmony_ci * @reset_wq: work queue for device reset procedure.
315362306a36Sopenharmony_ci * @kernel_ctx: Kernel driver context structure.
315462306a36Sopenharmony_ci * @kernel_queues: array of hl_hw_queue.
315562306a36Sopenharmony_ci * @cs_mirror_list: CS mirror list for TDR.
315662306a36Sopenharmony_ci * @cs_mirror_lock: protects cs_mirror_list.
315762306a36Sopenharmony_ci * @kernel_mem_mgr: memory manager for memory buffers with lifespan of driver.
315862306a36Sopenharmony_ci * @event_queue: event queue for IRQ from CPU-CP.
315962306a36Sopenharmony_ci * @dma_pool: DMA pool for small allocations.
316062306a36Sopenharmony_ci * @cpu_accessible_dma_mem: Host <-> CPU-CP shared memory CPU address.
316162306a36Sopenharmony_ci * @cpu_accessible_dma_address: Host <-> CPU-CP shared memory DMA address.
316262306a36Sopenharmony_ci * @cpu_accessible_dma_pool: Host <-> CPU-CP shared memory pool.
316362306a36Sopenharmony_ci * @asid_bitmap: holds used/available ASIDs.
316462306a36Sopenharmony_ci * @asid_mutex: protects asid_bitmap.
316562306a36Sopenharmony_ci * @send_cpu_message_lock: enforces only one message in Host <-> CPU-CP queue.
316662306a36Sopenharmony_ci * @debug_lock: protects critical section of setting debug mode for device
316762306a36Sopenharmony_ci * @mmu_lock: protects the MMU page tables and invalidation h/w. Although the
316862306a36Sopenharmony_ci *            page tables are per context, the invalidation h/w is per MMU.
316962306a36Sopenharmony_ci *            Therefore, we can't allow multiple contexts (we only have two,
317062306a36Sopenharmony_ci *            user and kernel) to access the invalidation h/w at the same time.
317162306a36Sopenharmony_ci *            In addition, any change to the PGT, modifying the MMU hash or
317262306a36Sopenharmony_ci *            walking the PGT requires talking this lock.
317362306a36Sopenharmony_ci * @asic_prop: ASIC specific immutable properties.
317462306a36Sopenharmony_ci * @asic_funcs: ASIC specific functions.
317562306a36Sopenharmony_ci * @asic_specific: ASIC specific information to use only from ASIC files.
317662306a36Sopenharmony_ci * @vm: virtual memory manager for MMU.
317762306a36Sopenharmony_ci * @hwmon_dev: H/W monitor device.
317862306a36Sopenharmony_ci * @hl_chip_info: ASIC's sensors information.
317962306a36Sopenharmony_ci * @device_status_description: device status description.
318062306a36Sopenharmony_ci * @hl_debugfs: device's debugfs manager.
318162306a36Sopenharmony_ci * @cb_pool: list of pre allocated CBs.
318262306a36Sopenharmony_ci * @cb_pool_lock: protects the CB pool.
318362306a36Sopenharmony_ci * @internal_cb_pool_virt_addr: internal command buffer pool virtual address.
318462306a36Sopenharmony_ci * @internal_cb_pool_dma_addr: internal command buffer pool dma address.
318562306a36Sopenharmony_ci * @internal_cb_pool: internal command buffer memory pool.
318662306a36Sopenharmony_ci * @internal_cb_va_base: internal cb pool mmu virtual address base
318762306a36Sopenharmony_ci * @fpriv_list: list of file private data structures. Each structure is created
318862306a36Sopenharmony_ci *              when a user opens the device
318962306a36Sopenharmony_ci * @fpriv_ctrl_list: list of file private data structures. Each structure is created
319062306a36Sopenharmony_ci *              when a user opens the control device
319162306a36Sopenharmony_ci * @fpriv_list_lock: protects the fpriv_list
319262306a36Sopenharmony_ci * @fpriv_ctrl_list_lock: protects the fpriv_ctrl_list
319362306a36Sopenharmony_ci * @aggregated_cs_counters: aggregated cs counters among all contexts
319462306a36Sopenharmony_ci * @mmu_priv: device-specific MMU data.
319562306a36Sopenharmony_ci * @mmu_func: device-related MMU functions.
319662306a36Sopenharmony_ci * @dec: list of decoder sw instance
319762306a36Sopenharmony_ci * @fw_loader: FW loader manager.
319862306a36Sopenharmony_ci * @pci_mem_region: array of memory regions in the PCI
319962306a36Sopenharmony_ci * @state_dump_specs: constants and dictionaries needed to dump system state.
320062306a36Sopenharmony_ci * @multi_cs_completion: array of multi-CS completion.
320162306a36Sopenharmony_ci * @clk_throttling: holds information about current/previous clock throttling events
320262306a36Sopenharmony_ci * @captured_err_info: holds information about errors.
320362306a36Sopenharmony_ci * @reset_info: holds current device reset information.
320462306a36Sopenharmony_ci * @stream_master_qid_arr: pointer to array with QIDs of master streams.
320562306a36Sopenharmony_ci * @fw_inner_major_ver: the major of current loaded preboot inner version.
320662306a36Sopenharmony_ci * @fw_inner_minor_ver: the minor of current loaded preboot inner version.
320762306a36Sopenharmony_ci * @fw_sw_major_ver: the major of current loaded preboot SW version.
320862306a36Sopenharmony_ci * @fw_sw_minor_ver: the minor of current loaded preboot SW version.
320962306a36Sopenharmony_ci * @fw_sw_sub_minor_ver: the sub-minor of current loaded preboot SW version.
321062306a36Sopenharmony_ci * @dram_used_mem: current DRAM memory consumption.
321162306a36Sopenharmony_ci * @memory_scrub_val: the value to which the dram will be scrubbed to using cb scrub_device_dram
321262306a36Sopenharmony_ci * @timeout_jiffies: device CS timeout value.
321362306a36Sopenharmony_ci * @max_power: the max power of the device, as configured by the sysadmin. This
321462306a36Sopenharmony_ci *             value is saved so in case of hard-reset, the driver will restore
321562306a36Sopenharmony_ci *             this value and update the F/W after the re-initialization
321662306a36Sopenharmony_ci * @boot_error_status_mask: contains a mask of the device boot error status.
321762306a36Sopenharmony_ci *                          Each bit represents a different error, according to
321862306a36Sopenharmony_ci *                          the defines in hl_boot_if.h. If the bit is cleared,
321962306a36Sopenharmony_ci *                          the error will be ignored by the driver during
322062306a36Sopenharmony_ci *                          device initialization. Mainly used to debug and
322162306a36Sopenharmony_ci *                          workaround firmware bugs
322262306a36Sopenharmony_ci * @dram_pci_bar_start: start bus address of PCIe bar towards DRAM.
322362306a36Sopenharmony_ci * @last_successful_open_ktime: timestamp (ktime) of the last successful device open.
322462306a36Sopenharmony_ci * @last_successful_open_jif: timestamp (jiffies) of the last successful
322562306a36Sopenharmony_ci *                            device open.
322662306a36Sopenharmony_ci * @last_open_session_duration_jif: duration (jiffies) of the last device open
322762306a36Sopenharmony_ci *                                  session.
322862306a36Sopenharmony_ci * @open_counter: number of successful device open operations.
322962306a36Sopenharmony_ci * @fw_poll_interval_usec: FW status poll interval in usec.
323062306a36Sopenharmony_ci *                         used for CPU boot status
323162306a36Sopenharmony_ci * @fw_comms_poll_interval_usec: FW comms/protocol poll interval in usec.
323262306a36Sopenharmony_ci *                                  used for COMMs protocols cmds(COMMS_STS_*)
323362306a36Sopenharmony_ci * @dram_binning: contains mask of drams that is received from the f/w which indicates which
323462306a36Sopenharmony_ci *                drams are binned-out
323562306a36Sopenharmony_ci * @tpc_binning: contains mask of tpc engines that is received from the f/w which indicates which
323662306a36Sopenharmony_ci *               tpc engines are binned-out
323762306a36Sopenharmony_ci * @dmabuf_export_cnt: number of dma-buf exporting.
323862306a36Sopenharmony_ci * @card_type: Various ASICs have several card types. This indicates the card
323962306a36Sopenharmony_ci *             type of the current device.
324062306a36Sopenharmony_ci * @major: habanalabs kernel driver major.
324162306a36Sopenharmony_ci * @high_pll: high PLL profile frequency.
324262306a36Sopenharmony_ci * @decoder_binning: contains mask of decoder engines that is received from the f/w which
324362306a36Sopenharmony_ci *                   indicates which decoder engines are binned-out
324462306a36Sopenharmony_ci * @edma_binning: contains mask of edma engines that is received from the f/w which
324562306a36Sopenharmony_ci *                   indicates which edma engines are binned-out
324662306a36Sopenharmony_ci * @device_release_watchdog_timeout_sec: device release watchdog timeout value in seconds.
324762306a36Sopenharmony_ci * @rotator_binning: contains mask of rotators engines that is received from the f/w
324862306a36Sopenharmony_ci *			which indicates which rotator engines are binned-out(Gaudi3 and above).
324962306a36Sopenharmony_ci * @id: device minor.
325062306a36Sopenharmony_ci * @id_control: minor of the control device.
325162306a36Sopenharmony_ci * @cdev_idx: char device index. Used for setting its name.
325262306a36Sopenharmony_ci * @cpu_pci_msb_addr: 50-bit extension bits for the device CPU's 40-bit
325362306a36Sopenharmony_ci *                    addresses.
325462306a36Sopenharmony_ci * @is_in_dram_scrub: true if dram scrub operation is on going.
325562306a36Sopenharmony_ci * @disabled: is device disabled.
325662306a36Sopenharmony_ci * @late_init_done: is late init stage was done during initialization.
325762306a36Sopenharmony_ci * @hwmon_initialized: is H/W monitor sensors was initialized.
325862306a36Sopenharmony_ci * @reset_on_lockup: true if a reset should be done in case of stuck CS, false
325962306a36Sopenharmony_ci *                   otherwise.
326062306a36Sopenharmony_ci * @dram_default_page_mapping: is DRAM default page mapping enabled.
326162306a36Sopenharmony_ci * @memory_scrub: true to perform device memory scrub in various locations,
326262306a36Sopenharmony_ci *                such as context-switch, context close, page free, etc.
326362306a36Sopenharmony_ci * @pmmu_huge_range: is a different virtual addresses range used for PMMU with
326462306a36Sopenharmony_ci *                   huge pages.
326562306a36Sopenharmony_ci * @init_done: is the initialization of the device done.
326662306a36Sopenharmony_ci * @device_cpu_disabled: is the device CPU disabled (due to timeouts)
326762306a36Sopenharmony_ci * @in_debug: whether the device is in a state where the profiling/tracing infrastructure
326862306a36Sopenharmony_ci *            can be used. This indication is needed because in some ASICs we need to do
326962306a36Sopenharmony_ci *            specific operations to enable that infrastructure.
327062306a36Sopenharmony_ci * @cdev_sysfs_debugfs_created: were char devices and sysfs/debugfs files created.
327162306a36Sopenharmony_ci * @stop_on_err: true if engines should stop on error.
327262306a36Sopenharmony_ci * @supports_sync_stream: is sync stream supported.
327362306a36Sopenharmony_ci * @sync_stream_queue_idx: helper index for sync stream queues initialization.
327462306a36Sopenharmony_ci * @collective_mon_idx: helper index for collective initialization
327562306a36Sopenharmony_ci * @supports_coresight: is CoreSight supported.
327662306a36Sopenharmony_ci * @supports_cb_mapping: is mapping a CB to the device's MMU supported.
327762306a36Sopenharmony_ci * @process_kill_trial_cnt: number of trials reset thread tried killing
327862306a36Sopenharmony_ci *                          user processes
327962306a36Sopenharmony_ci * @device_fini_pending: true if device_fini was called and might be
328062306a36Sopenharmony_ci *                       waiting for the reset thread to finish
328162306a36Sopenharmony_ci * @supports_staged_submission: true if staged submissions are supported
328262306a36Sopenharmony_ci * @device_cpu_is_halted: Flag to indicate whether the device CPU was already
328362306a36Sopenharmony_ci *                        halted. We can't halt it again because the COMMS
328462306a36Sopenharmony_ci *                        protocol will throw an error. Relevant only for
328562306a36Sopenharmony_ci *                        cases where Linux was not loaded to device CPU
328662306a36Sopenharmony_ci * @supports_wait_for_multi_cs: true if wait for multi CS is supported
328762306a36Sopenharmony_ci * @is_compute_ctx_active: Whether there is an active compute context executing.
328862306a36Sopenharmony_ci * @compute_ctx_in_release: true if the current compute context is being released.
328962306a36Sopenharmony_ci * @supports_mmu_prefetch: true if prefetch is supported, otherwise false.
329062306a36Sopenharmony_ci * @reset_upon_device_release: reset the device when the user closes the file descriptor of the
329162306a36Sopenharmony_ci *                             device.
329262306a36Sopenharmony_ci * @supports_ctx_switch: true if a ctx switch is required upon first submission.
329362306a36Sopenharmony_ci * @support_preboot_binning: true if we support read binning info from preboot.
329462306a36Sopenharmony_ci * @nic_ports_mask: Controls which NIC ports are enabled. Used only for testing.
329562306a36Sopenharmony_ci * @fw_components: Controls which f/w components to load to the device. There are multiple f/w
329662306a36Sopenharmony_ci *                 stages and sometimes we want to stop at a certain stage. Used only for testing.
329762306a36Sopenharmony_ci * @mmu_disable: Disable the device MMU(s). Used only for testing.
329862306a36Sopenharmony_ci * @cpu_queues_enable: Whether to enable queues communication vs. the f/w. Used only for testing.
329962306a36Sopenharmony_ci * @pldm: Whether we are running in Palladium environment. Used only for testing.
330062306a36Sopenharmony_ci * @hard_reset_on_fw_events: Whether to do device hard-reset when a fatal event is received from
330162306a36Sopenharmony_ci *                           the f/w. Used only for testing.
330262306a36Sopenharmony_ci * @bmc_enable: Whether we are running in a box with BMC. Used only for testing.
330362306a36Sopenharmony_ci * @reset_on_preboot_fail: Whether to reset the device if preboot f/w fails to load.
330462306a36Sopenharmony_ci *                         Used only for testing.
330562306a36Sopenharmony_ci * @heartbeat: Controls if we want to enable the heartbeat mechanism vs. the f/w, which verifies
330662306a36Sopenharmony_ci *             that the f/w is always alive. Used only for testing.
330762306a36Sopenharmony_ci */
330862306a36Sopenharmony_cistruct hl_device {
330962306a36Sopenharmony_ci	struct pci_dev			*pdev;
331062306a36Sopenharmony_ci	u64				pcie_bar_phys[HL_PCI_NUM_BARS];
331162306a36Sopenharmony_ci	void __iomem			*pcie_bar[HL_PCI_NUM_BARS];
331262306a36Sopenharmony_ci	void __iomem			*rmmio;
331362306a36Sopenharmony_ci	struct class			*hclass;
331462306a36Sopenharmony_ci	struct cdev			cdev;
331562306a36Sopenharmony_ci	struct cdev			cdev_ctrl;
331662306a36Sopenharmony_ci	struct device			*dev;
331762306a36Sopenharmony_ci	struct device			*dev_ctrl;
331862306a36Sopenharmony_ci	struct delayed_work		work_heartbeat;
331962306a36Sopenharmony_ci	struct hl_device_reset_work	device_reset_work;
332062306a36Sopenharmony_ci	struct hl_device_reset_work	device_release_watchdog_work;
332162306a36Sopenharmony_ci	char				asic_name[HL_STR_MAX];
332262306a36Sopenharmony_ci	char				status[HL_DEV_STS_MAX][HL_STR_MAX];
332362306a36Sopenharmony_ci	enum hl_asic_type		asic_type;
332462306a36Sopenharmony_ci	struct hl_cq			*completion_queue;
332562306a36Sopenharmony_ci	struct hl_user_interrupt	*user_interrupt;
332662306a36Sopenharmony_ci	struct hl_user_interrupt	tpc_interrupt;
332762306a36Sopenharmony_ci	struct hl_user_interrupt	unexpected_error_interrupt;
332862306a36Sopenharmony_ci	struct hl_user_interrupt	common_user_cq_interrupt;
332962306a36Sopenharmony_ci	struct hl_user_interrupt	common_decoder_interrupt;
333062306a36Sopenharmony_ci	struct hl_cs			**shadow_cs_queue;
333162306a36Sopenharmony_ci	struct workqueue_struct		**cq_wq;
333262306a36Sopenharmony_ci	struct workqueue_struct		*eq_wq;
333362306a36Sopenharmony_ci	struct workqueue_struct		*cs_cmplt_wq;
333462306a36Sopenharmony_ci	struct workqueue_struct		*ts_free_obj_wq;
333562306a36Sopenharmony_ci	struct workqueue_struct		*prefetch_wq;
333662306a36Sopenharmony_ci	struct workqueue_struct		*reset_wq;
333762306a36Sopenharmony_ci	struct hl_ctx			*kernel_ctx;
333862306a36Sopenharmony_ci	struct hl_hw_queue		*kernel_queues;
333962306a36Sopenharmony_ci	struct list_head		cs_mirror_list;
334062306a36Sopenharmony_ci	spinlock_t			cs_mirror_lock;
334162306a36Sopenharmony_ci	struct hl_mem_mgr		kernel_mem_mgr;
334262306a36Sopenharmony_ci	struct hl_eq			event_queue;
334362306a36Sopenharmony_ci	struct dma_pool			*dma_pool;
334462306a36Sopenharmony_ci	void				*cpu_accessible_dma_mem;
334562306a36Sopenharmony_ci	dma_addr_t			cpu_accessible_dma_address;
334662306a36Sopenharmony_ci	struct gen_pool			*cpu_accessible_dma_pool;
334762306a36Sopenharmony_ci	unsigned long			*asid_bitmap;
334862306a36Sopenharmony_ci	struct mutex			asid_mutex;
334962306a36Sopenharmony_ci	struct mutex			send_cpu_message_lock;
335062306a36Sopenharmony_ci	struct mutex			debug_lock;
335162306a36Sopenharmony_ci	struct mutex			mmu_lock;
335262306a36Sopenharmony_ci	struct asic_fixed_properties	asic_prop;
335362306a36Sopenharmony_ci	const struct hl_asic_funcs	*asic_funcs;
335462306a36Sopenharmony_ci	void				*asic_specific;
335562306a36Sopenharmony_ci	struct hl_vm			vm;
335662306a36Sopenharmony_ci	struct device			*hwmon_dev;
335762306a36Sopenharmony_ci	struct hwmon_chip_info		*hl_chip_info;
335862306a36Sopenharmony_ci
335962306a36Sopenharmony_ci	struct hl_dbg_device_entry	hl_debugfs;
336062306a36Sopenharmony_ci
336162306a36Sopenharmony_ci	struct list_head		cb_pool;
336262306a36Sopenharmony_ci	spinlock_t			cb_pool_lock;
336362306a36Sopenharmony_ci
336462306a36Sopenharmony_ci	void				*internal_cb_pool_virt_addr;
336562306a36Sopenharmony_ci	dma_addr_t			internal_cb_pool_dma_addr;
336662306a36Sopenharmony_ci	struct gen_pool			*internal_cb_pool;
336762306a36Sopenharmony_ci	u64				internal_cb_va_base;
336862306a36Sopenharmony_ci
336962306a36Sopenharmony_ci	struct list_head		fpriv_list;
337062306a36Sopenharmony_ci	struct list_head		fpriv_ctrl_list;
337162306a36Sopenharmony_ci	struct mutex			fpriv_list_lock;
337262306a36Sopenharmony_ci	struct mutex			fpriv_ctrl_list_lock;
337362306a36Sopenharmony_ci
337462306a36Sopenharmony_ci	struct hl_cs_counters_atomic	aggregated_cs_counters;
337562306a36Sopenharmony_ci
337662306a36Sopenharmony_ci	struct hl_mmu_priv		mmu_priv;
337762306a36Sopenharmony_ci	struct hl_mmu_funcs		mmu_func[MMU_NUM_PGT_LOCATIONS];
337862306a36Sopenharmony_ci
337962306a36Sopenharmony_ci	struct hl_dec			*dec;
338062306a36Sopenharmony_ci
338162306a36Sopenharmony_ci	struct fw_load_mgr		fw_loader;
338262306a36Sopenharmony_ci
338362306a36Sopenharmony_ci	struct pci_mem_region		pci_mem_region[PCI_REGION_NUMBER];
338462306a36Sopenharmony_ci
338562306a36Sopenharmony_ci	struct hl_state_dump_specs	state_dump_specs;
338662306a36Sopenharmony_ci
338762306a36Sopenharmony_ci	struct multi_cs_completion	multi_cs_completion[
338862306a36Sopenharmony_ci							MULTI_CS_MAX_USER_CTX];
338962306a36Sopenharmony_ci	struct hl_clk_throttle		clk_throttling;
339062306a36Sopenharmony_ci	struct hl_error_info		captured_err_info;
339162306a36Sopenharmony_ci
339262306a36Sopenharmony_ci	struct hl_reset_info		reset_info;
339362306a36Sopenharmony_ci
339462306a36Sopenharmony_ci	u32				*stream_master_qid_arr;
339562306a36Sopenharmony_ci	u32				fw_inner_major_ver;
339662306a36Sopenharmony_ci	u32				fw_inner_minor_ver;
339762306a36Sopenharmony_ci	u32				fw_sw_major_ver;
339862306a36Sopenharmony_ci	u32				fw_sw_minor_ver;
339962306a36Sopenharmony_ci	u32				fw_sw_sub_minor_ver;
340062306a36Sopenharmony_ci	atomic64_t			dram_used_mem;
340162306a36Sopenharmony_ci	u64				memory_scrub_val;
340262306a36Sopenharmony_ci	u64				timeout_jiffies;
340362306a36Sopenharmony_ci	u64				max_power;
340462306a36Sopenharmony_ci	u64				boot_error_status_mask;
340562306a36Sopenharmony_ci	u64				dram_pci_bar_start;
340662306a36Sopenharmony_ci	u64				last_successful_open_jif;
340762306a36Sopenharmony_ci	u64				last_open_session_duration_jif;
340862306a36Sopenharmony_ci	u64				open_counter;
340962306a36Sopenharmony_ci	u64				fw_poll_interval_usec;
341062306a36Sopenharmony_ci	ktime_t				last_successful_open_ktime;
341162306a36Sopenharmony_ci	u64				fw_comms_poll_interval_usec;
341262306a36Sopenharmony_ci	u64				dram_binning;
341362306a36Sopenharmony_ci	u64				tpc_binning;
341462306a36Sopenharmony_ci	atomic_t			dmabuf_export_cnt;
341562306a36Sopenharmony_ci	enum cpucp_card_types		card_type;
341662306a36Sopenharmony_ci	u32				major;
341762306a36Sopenharmony_ci	u32				high_pll;
341862306a36Sopenharmony_ci	u32				decoder_binning;
341962306a36Sopenharmony_ci	u32				edma_binning;
342062306a36Sopenharmony_ci	u32				device_release_watchdog_timeout_sec;
342162306a36Sopenharmony_ci	u32				rotator_binning;
342262306a36Sopenharmony_ci	u16				id;
342362306a36Sopenharmony_ci	u16				id_control;
342462306a36Sopenharmony_ci	u16				cdev_idx;
342562306a36Sopenharmony_ci	u16				cpu_pci_msb_addr;
342662306a36Sopenharmony_ci	u8				is_in_dram_scrub;
342762306a36Sopenharmony_ci	u8				disabled;
342862306a36Sopenharmony_ci	u8				late_init_done;
342962306a36Sopenharmony_ci	u8				hwmon_initialized;
343062306a36Sopenharmony_ci	u8				reset_on_lockup;
343162306a36Sopenharmony_ci	u8				dram_default_page_mapping;
343262306a36Sopenharmony_ci	u8				memory_scrub;
343362306a36Sopenharmony_ci	u8				pmmu_huge_range;
343462306a36Sopenharmony_ci	u8				init_done;
343562306a36Sopenharmony_ci	u8				device_cpu_disabled;
343662306a36Sopenharmony_ci	u8				in_debug;
343762306a36Sopenharmony_ci	u8				cdev_sysfs_debugfs_created;
343862306a36Sopenharmony_ci	u8				stop_on_err;
343962306a36Sopenharmony_ci	u8				supports_sync_stream;
344062306a36Sopenharmony_ci	u8				sync_stream_queue_idx;
344162306a36Sopenharmony_ci	u8				collective_mon_idx;
344262306a36Sopenharmony_ci	u8				supports_coresight;
344362306a36Sopenharmony_ci	u8				supports_cb_mapping;
344462306a36Sopenharmony_ci	u8				process_kill_trial_cnt;
344562306a36Sopenharmony_ci	u8				device_fini_pending;
344662306a36Sopenharmony_ci	u8				supports_staged_submission;
344762306a36Sopenharmony_ci	u8				device_cpu_is_halted;
344862306a36Sopenharmony_ci	u8				supports_wait_for_multi_cs;
344962306a36Sopenharmony_ci	u8				stream_master_qid_arr_size;
345062306a36Sopenharmony_ci	u8				is_compute_ctx_active;
345162306a36Sopenharmony_ci	u8				compute_ctx_in_release;
345262306a36Sopenharmony_ci	u8				supports_mmu_prefetch;
345362306a36Sopenharmony_ci	u8				reset_upon_device_release;
345462306a36Sopenharmony_ci	u8				supports_ctx_switch;
345562306a36Sopenharmony_ci	u8				support_preboot_binning;
345662306a36Sopenharmony_ci
345762306a36Sopenharmony_ci	/* Parameters for bring-up to be upstreamed */
345862306a36Sopenharmony_ci	u64				nic_ports_mask;
345962306a36Sopenharmony_ci	u64				fw_components;
346062306a36Sopenharmony_ci	u8				mmu_disable;
346162306a36Sopenharmony_ci	u8				cpu_queues_enable;
346262306a36Sopenharmony_ci	u8				pldm;
346362306a36Sopenharmony_ci	u8				hard_reset_on_fw_events;
346462306a36Sopenharmony_ci	u8				bmc_enable;
346562306a36Sopenharmony_ci	u8				reset_on_preboot_fail;
346662306a36Sopenharmony_ci	u8				heartbeat;
346762306a36Sopenharmony_ci};
346862306a36Sopenharmony_ci
346962306a36Sopenharmony_ci
347062306a36Sopenharmony_ci/**
347162306a36Sopenharmony_ci * struct hl_cs_encaps_sig_handle - encapsulated signals handle structure
347262306a36Sopenharmony_ci * @refcount: refcount used to protect removing this id when several
347362306a36Sopenharmony_ci *            wait cs are used to wait of the reserved encaps signals.
347462306a36Sopenharmony_ci * @hdev: pointer to habanalabs device structure.
347562306a36Sopenharmony_ci * @hw_sob: pointer to  H/W SOB used in the reservation.
347662306a36Sopenharmony_ci * @ctx: pointer to the user's context data structure
347762306a36Sopenharmony_ci * @cs_seq: staged cs sequence which contains encapsulated signals
347862306a36Sopenharmony_ci * @id: idr handler id to be used to fetch the handler info
347962306a36Sopenharmony_ci * @q_idx: stream queue index
348062306a36Sopenharmony_ci * @pre_sob_val: current SOB value before reservation
348162306a36Sopenharmony_ci * @count: signals number
348262306a36Sopenharmony_ci */
348362306a36Sopenharmony_cistruct hl_cs_encaps_sig_handle {
348462306a36Sopenharmony_ci	struct kref refcount;
348562306a36Sopenharmony_ci	struct hl_device *hdev;
348662306a36Sopenharmony_ci	struct hl_hw_sob *hw_sob;
348762306a36Sopenharmony_ci	struct hl_ctx *ctx;
348862306a36Sopenharmony_ci	u64  cs_seq;
348962306a36Sopenharmony_ci	u32  id;
349062306a36Sopenharmony_ci	u32  q_idx;
349162306a36Sopenharmony_ci	u32  pre_sob_val;
349262306a36Sopenharmony_ci	u32  count;
349362306a36Sopenharmony_ci};
349462306a36Sopenharmony_ci
349562306a36Sopenharmony_ci/**
349662306a36Sopenharmony_ci * struct hl_info_fw_err_info - firmware error information structure
349762306a36Sopenharmony_ci * @err_type: The type of error detected (or reported).
349862306a36Sopenharmony_ci * @event_mask: Pointer to the event mask to be modified with the detected error flag
349962306a36Sopenharmony_ci *              (can be NULL)
350062306a36Sopenharmony_ci * @event_id: The id of the event that reported the error
350162306a36Sopenharmony_ci *            (applicable when err_type is HL_INFO_FW_REPORTED_ERR).
350262306a36Sopenharmony_ci */
350362306a36Sopenharmony_cistruct hl_info_fw_err_info {
350462306a36Sopenharmony_ci	enum hl_info_fw_err_type err_type;
350562306a36Sopenharmony_ci	u64 *event_mask;
350662306a36Sopenharmony_ci	u16 event_id;
350762306a36Sopenharmony_ci};
350862306a36Sopenharmony_ci
350962306a36Sopenharmony_ci/*
351062306a36Sopenharmony_ci * IOCTLs
351162306a36Sopenharmony_ci */
351262306a36Sopenharmony_ci
351362306a36Sopenharmony_ci/**
351462306a36Sopenharmony_ci * typedef hl_ioctl_t - typedef for ioctl function in the driver
351562306a36Sopenharmony_ci * @hpriv: pointer to the FD's private data, which contains state of
351662306a36Sopenharmony_ci *		user process
351762306a36Sopenharmony_ci * @data: pointer to the input/output arguments structure of the IOCTL
351862306a36Sopenharmony_ci *
351962306a36Sopenharmony_ci * Return: 0 for success, negative value for error
352062306a36Sopenharmony_ci */
352162306a36Sopenharmony_citypedef int hl_ioctl_t(struct hl_fpriv *hpriv, void *data);
352262306a36Sopenharmony_ci
352362306a36Sopenharmony_ci/**
352462306a36Sopenharmony_ci * struct hl_ioctl_desc - describes an IOCTL entry of the driver.
352562306a36Sopenharmony_ci * @cmd: the IOCTL code as created by the kernel macros.
352662306a36Sopenharmony_ci * @func: pointer to the driver's function that should be called for this IOCTL.
352762306a36Sopenharmony_ci */
352862306a36Sopenharmony_cistruct hl_ioctl_desc {
352962306a36Sopenharmony_ci	unsigned int cmd;
353062306a36Sopenharmony_ci	hl_ioctl_t *func;
353162306a36Sopenharmony_ci};
353262306a36Sopenharmony_ci
353362306a36Sopenharmony_cistatic inline bool hl_is_fw_sw_ver_below(struct hl_device *hdev, u32 fw_sw_major, u32 fw_sw_minor)
353462306a36Sopenharmony_ci{
353562306a36Sopenharmony_ci	if (hdev->fw_sw_major_ver < fw_sw_major)
353662306a36Sopenharmony_ci		return true;
353762306a36Sopenharmony_ci	if (hdev->fw_sw_major_ver > fw_sw_major)
353862306a36Sopenharmony_ci		return false;
353962306a36Sopenharmony_ci	if (hdev->fw_sw_minor_ver < fw_sw_minor)
354062306a36Sopenharmony_ci		return true;
354162306a36Sopenharmony_ci	return false;
354262306a36Sopenharmony_ci}
354362306a36Sopenharmony_ci
354462306a36Sopenharmony_ci/*
354562306a36Sopenharmony_ci * Kernel module functions that can be accessed by entire module
354662306a36Sopenharmony_ci */
354762306a36Sopenharmony_ci
354862306a36Sopenharmony_ci/**
354962306a36Sopenharmony_ci * hl_get_sg_info() - get number of pages and the DMA address from SG list.
355062306a36Sopenharmony_ci * @sg: the SG list.
355162306a36Sopenharmony_ci * @dma_addr: pointer to DMA address to return.
355262306a36Sopenharmony_ci *
355362306a36Sopenharmony_ci * Calculate the number of consecutive pages described by the SG list. Take the
355462306a36Sopenharmony_ci * offset of the address in the first page, add to it the length and round it up
355562306a36Sopenharmony_ci * to the number of needed pages.
355662306a36Sopenharmony_ci */
355762306a36Sopenharmony_cistatic inline u32 hl_get_sg_info(struct scatterlist *sg, dma_addr_t *dma_addr)
355862306a36Sopenharmony_ci{
355962306a36Sopenharmony_ci	*dma_addr = sg_dma_address(sg);
356062306a36Sopenharmony_ci
356162306a36Sopenharmony_ci	return ((((*dma_addr) & (PAGE_SIZE - 1)) + sg_dma_len(sg)) +
356262306a36Sopenharmony_ci			(PAGE_SIZE - 1)) >> PAGE_SHIFT;
356362306a36Sopenharmony_ci}
356462306a36Sopenharmony_ci
356562306a36Sopenharmony_ci/**
356662306a36Sopenharmony_ci * hl_mem_area_inside_range() - Checks whether address+size are inside a range.
356762306a36Sopenharmony_ci * @address: The start address of the area we want to validate.
356862306a36Sopenharmony_ci * @size: The size in bytes of the area we want to validate.
356962306a36Sopenharmony_ci * @range_start_address: The start address of the valid range.
357062306a36Sopenharmony_ci * @range_end_address: The end address of the valid range.
357162306a36Sopenharmony_ci *
357262306a36Sopenharmony_ci * Return: true if the area is inside the valid range, false otherwise.
357362306a36Sopenharmony_ci */
357462306a36Sopenharmony_cistatic inline bool hl_mem_area_inside_range(u64 address, u64 size,
357562306a36Sopenharmony_ci				u64 range_start_address, u64 range_end_address)
357662306a36Sopenharmony_ci{
357762306a36Sopenharmony_ci	u64 end_address = address + size;
357862306a36Sopenharmony_ci
357962306a36Sopenharmony_ci	if ((address >= range_start_address) &&
358062306a36Sopenharmony_ci			(end_address <= range_end_address) &&
358162306a36Sopenharmony_ci			(end_address > address))
358262306a36Sopenharmony_ci		return true;
358362306a36Sopenharmony_ci
358462306a36Sopenharmony_ci	return false;
358562306a36Sopenharmony_ci}
358662306a36Sopenharmony_ci
358762306a36Sopenharmony_ci/**
358862306a36Sopenharmony_ci * hl_mem_area_crosses_range() - Checks whether address+size crossing a range.
358962306a36Sopenharmony_ci * @address: The start address of the area we want to validate.
359062306a36Sopenharmony_ci * @size: The size in bytes of the area we want to validate.
359162306a36Sopenharmony_ci * @range_start_address: The start address of the valid range.
359262306a36Sopenharmony_ci * @range_end_address: The end address of the valid range.
359362306a36Sopenharmony_ci *
359462306a36Sopenharmony_ci * Return: true if the area overlaps part or all of the valid range,
359562306a36Sopenharmony_ci *		false otherwise.
359662306a36Sopenharmony_ci */
359762306a36Sopenharmony_cistatic inline bool hl_mem_area_crosses_range(u64 address, u32 size,
359862306a36Sopenharmony_ci				u64 range_start_address, u64 range_end_address)
359962306a36Sopenharmony_ci{
360062306a36Sopenharmony_ci	u64 end_address = address + size - 1;
360162306a36Sopenharmony_ci
360262306a36Sopenharmony_ci	return ((address <= range_end_address) && (range_start_address <= end_address));
360362306a36Sopenharmony_ci}
360462306a36Sopenharmony_ci
360562306a36Sopenharmony_ciuint64_t hl_set_dram_bar_default(struct hl_device *hdev, u64 addr);
360662306a36Sopenharmony_civoid *hl_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size, dma_addr_t *dma_handle);
360762306a36Sopenharmony_civoid hl_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size, void *vaddr);
360862306a36Sopenharmony_civoid *hl_asic_dma_alloc_coherent_caller(struct hl_device *hdev, size_t size, dma_addr_t *dma_handle,
360962306a36Sopenharmony_ci					gfp_t flag, const char *caller);
361062306a36Sopenharmony_civoid hl_asic_dma_free_coherent_caller(struct hl_device *hdev, size_t size, void *cpu_addr,
361162306a36Sopenharmony_ci					dma_addr_t dma_handle, const char *caller);
361262306a36Sopenharmony_civoid *hl_asic_dma_pool_zalloc_caller(struct hl_device *hdev, size_t size, gfp_t mem_flags,
361362306a36Sopenharmony_ci					dma_addr_t *dma_handle, const char *caller);
361462306a36Sopenharmony_civoid hl_asic_dma_pool_free_caller(struct hl_device *hdev, void *vaddr, dma_addr_t dma_addr,
361562306a36Sopenharmony_ci					const char *caller);
361662306a36Sopenharmony_ciint hl_dma_map_sgtable(struct hl_device *hdev, struct sg_table *sgt, enum dma_data_direction dir);
361762306a36Sopenharmony_civoid hl_dma_unmap_sgtable(struct hl_device *hdev, struct sg_table *sgt,
361862306a36Sopenharmony_ci				enum dma_data_direction dir);
361962306a36Sopenharmony_ciint hl_access_sram_dram_region(struct hl_device *hdev, u64 addr, u64 *val,
362062306a36Sopenharmony_ci	enum debugfs_access_type acc_type, enum pci_region region_type, bool set_dram_bar);
362162306a36Sopenharmony_ciint hl_access_cfg_region(struct hl_device *hdev, u64 addr, u64 *val,
362262306a36Sopenharmony_ci	enum debugfs_access_type acc_type);
362362306a36Sopenharmony_ciint hl_access_dev_mem(struct hl_device *hdev, enum pci_region region_type,
362462306a36Sopenharmony_ci			u64 addr, u64 *val, enum debugfs_access_type acc_type);
362562306a36Sopenharmony_ciint hl_device_open(struct inode *inode, struct file *filp);
362662306a36Sopenharmony_ciint hl_device_open_ctrl(struct inode *inode, struct file *filp);
362762306a36Sopenharmony_cibool hl_device_operational(struct hl_device *hdev,
362862306a36Sopenharmony_ci		enum hl_device_status *status);
362962306a36Sopenharmony_cibool hl_ctrl_device_operational(struct hl_device *hdev,
363062306a36Sopenharmony_ci		enum hl_device_status *status);
363162306a36Sopenharmony_cienum hl_device_status hl_device_status(struct hl_device *hdev);
363262306a36Sopenharmony_ciint hl_device_set_debug_mode(struct hl_device *hdev, struct hl_ctx *ctx, bool enable);
363362306a36Sopenharmony_ciint hl_hw_queues_create(struct hl_device *hdev);
363462306a36Sopenharmony_civoid hl_hw_queues_destroy(struct hl_device *hdev);
363562306a36Sopenharmony_ciint hl_hw_queue_send_cb_no_cmpl(struct hl_device *hdev, u32 hw_queue_id,
363662306a36Sopenharmony_ci		u32 cb_size, u64 cb_ptr);
363762306a36Sopenharmony_civoid hl_hw_queue_submit_bd(struct hl_device *hdev, struct hl_hw_queue *q,
363862306a36Sopenharmony_ci		u32 ctl, u32 len, u64 ptr);
363962306a36Sopenharmony_ciint hl_hw_queue_schedule_cs(struct hl_cs *cs);
364062306a36Sopenharmony_ciu32 hl_hw_queue_add_ptr(u32 ptr, u16 val);
364162306a36Sopenharmony_civoid hl_hw_queue_inc_ci_kernel(struct hl_device *hdev, u32 hw_queue_id);
364262306a36Sopenharmony_civoid hl_hw_queue_update_ci(struct hl_cs *cs);
364362306a36Sopenharmony_civoid hl_hw_queue_reset(struct hl_device *hdev, bool hard_reset);
364462306a36Sopenharmony_ci
364562306a36Sopenharmony_ci#define hl_queue_inc_ptr(p)		hl_hw_queue_add_ptr(p, 1)
364662306a36Sopenharmony_ci#define hl_pi_2_offset(pi)		((pi) & (HL_QUEUE_LENGTH - 1))
364762306a36Sopenharmony_ci
364862306a36Sopenharmony_ciint hl_cq_init(struct hl_device *hdev, struct hl_cq *q, u32 hw_queue_id);
364962306a36Sopenharmony_civoid hl_cq_fini(struct hl_device *hdev, struct hl_cq *q);
365062306a36Sopenharmony_ciint hl_eq_init(struct hl_device *hdev, struct hl_eq *q);
365162306a36Sopenharmony_civoid hl_eq_fini(struct hl_device *hdev, struct hl_eq *q);
365262306a36Sopenharmony_civoid hl_cq_reset(struct hl_device *hdev, struct hl_cq *q);
365362306a36Sopenharmony_civoid hl_eq_reset(struct hl_device *hdev, struct hl_eq *q);
365462306a36Sopenharmony_ciirqreturn_t hl_irq_handler_cq(int irq, void *arg);
365562306a36Sopenharmony_ciirqreturn_t hl_irq_handler_eq(int irq, void *arg);
365662306a36Sopenharmony_ciirqreturn_t hl_irq_handler_dec_abnrm(int irq, void *arg);
365762306a36Sopenharmony_ciirqreturn_t hl_irq_handler_user_interrupt(int irq, void *arg);
365862306a36Sopenharmony_ciirqreturn_t hl_irq_user_interrupt_thread_handler(int irq, void *arg);
365962306a36Sopenharmony_ciu32 hl_cq_inc_ptr(u32 ptr);
366062306a36Sopenharmony_ci
366162306a36Sopenharmony_ciint hl_asid_init(struct hl_device *hdev);
366262306a36Sopenharmony_civoid hl_asid_fini(struct hl_device *hdev);
366362306a36Sopenharmony_ciunsigned long hl_asid_alloc(struct hl_device *hdev);
366462306a36Sopenharmony_civoid hl_asid_free(struct hl_device *hdev, unsigned long asid);
366562306a36Sopenharmony_ci
366662306a36Sopenharmony_ciint hl_ctx_create(struct hl_device *hdev, struct hl_fpriv *hpriv);
366762306a36Sopenharmony_civoid hl_ctx_free(struct hl_device *hdev, struct hl_ctx *ctx);
366862306a36Sopenharmony_ciint hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx);
366962306a36Sopenharmony_civoid hl_ctx_do_release(struct kref *ref);
367062306a36Sopenharmony_civoid hl_ctx_get(struct hl_ctx *ctx);
367162306a36Sopenharmony_ciint hl_ctx_put(struct hl_ctx *ctx);
367262306a36Sopenharmony_cistruct hl_ctx *hl_get_compute_ctx(struct hl_device *hdev);
367362306a36Sopenharmony_cistruct hl_fence *hl_ctx_get_fence(struct hl_ctx *ctx, u64 seq);
367462306a36Sopenharmony_ciint hl_ctx_get_fences(struct hl_ctx *ctx, u64 *seq_arr,
367562306a36Sopenharmony_ci				struct hl_fence **fence, u32 arr_len);
367662306a36Sopenharmony_civoid hl_ctx_mgr_init(struct hl_ctx_mgr *mgr);
367762306a36Sopenharmony_civoid hl_ctx_mgr_fini(struct hl_device *hdev, struct hl_ctx_mgr *mgr);
367862306a36Sopenharmony_ci
367962306a36Sopenharmony_ciint hl_device_init(struct hl_device *hdev);
368062306a36Sopenharmony_civoid hl_device_fini(struct hl_device *hdev);
368162306a36Sopenharmony_ciint hl_device_suspend(struct hl_device *hdev);
368262306a36Sopenharmony_ciint hl_device_resume(struct hl_device *hdev);
368362306a36Sopenharmony_ciint hl_device_reset(struct hl_device *hdev, u32 flags);
368462306a36Sopenharmony_ciint hl_device_cond_reset(struct hl_device *hdev, u32 flags, u64 event_mask);
368562306a36Sopenharmony_civoid hl_hpriv_get(struct hl_fpriv *hpriv);
368662306a36Sopenharmony_ciint hl_hpriv_put(struct hl_fpriv *hpriv);
368762306a36Sopenharmony_ciint hl_device_utilization(struct hl_device *hdev, u32 *utilization);
368862306a36Sopenharmony_ci
368962306a36Sopenharmony_ciint hl_build_hwmon_channel_info(struct hl_device *hdev,
369062306a36Sopenharmony_ci		struct cpucp_sensor *sensors_arr);
369162306a36Sopenharmony_ci
369262306a36Sopenharmony_civoid hl_notifier_event_send_all(struct hl_device *hdev, u64 event_mask);
369362306a36Sopenharmony_ci
369462306a36Sopenharmony_ciint hl_sysfs_init(struct hl_device *hdev);
369562306a36Sopenharmony_civoid hl_sysfs_fini(struct hl_device *hdev);
369662306a36Sopenharmony_ci
369762306a36Sopenharmony_ciint hl_hwmon_init(struct hl_device *hdev);
369862306a36Sopenharmony_civoid hl_hwmon_fini(struct hl_device *hdev);
369962306a36Sopenharmony_civoid hl_hwmon_release_resources(struct hl_device *hdev);
370062306a36Sopenharmony_ci
370162306a36Sopenharmony_ciint hl_cb_create(struct hl_device *hdev, struct hl_mem_mgr *mmg,
370262306a36Sopenharmony_ci			struct hl_ctx *ctx, u32 cb_size, bool internal_cb,
370362306a36Sopenharmony_ci			bool map_cb, u64 *handle);
370462306a36Sopenharmony_ciint hl_cb_destroy(struct hl_mem_mgr *mmg, u64 cb_handle);
370562306a36Sopenharmony_ciint hl_hw_block_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma);
370662306a36Sopenharmony_cistruct hl_cb *hl_cb_get(struct hl_mem_mgr *mmg, u64 handle);
370762306a36Sopenharmony_civoid hl_cb_put(struct hl_cb *cb);
370862306a36Sopenharmony_cistruct hl_cb *hl_cb_kernel_create(struct hl_device *hdev, u32 cb_size,
370962306a36Sopenharmony_ci					bool internal_cb);
371062306a36Sopenharmony_ciint hl_cb_pool_init(struct hl_device *hdev);
371162306a36Sopenharmony_ciint hl_cb_pool_fini(struct hl_device *hdev);
371262306a36Sopenharmony_ciint hl_cb_va_pool_init(struct hl_ctx *ctx);
371362306a36Sopenharmony_civoid hl_cb_va_pool_fini(struct hl_ctx *ctx);
371462306a36Sopenharmony_ci
371562306a36Sopenharmony_civoid hl_cs_rollback_all(struct hl_device *hdev, bool skip_wq_flush);
371662306a36Sopenharmony_cistruct hl_cs_job *hl_cs_allocate_job(struct hl_device *hdev,
371762306a36Sopenharmony_ci		enum hl_queue_type queue_type, bool is_kernel_allocated_cb);
371862306a36Sopenharmony_civoid hl_sob_reset_error(struct kref *ref);
371962306a36Sopenharmony_ciint hl_gen_sob_mask(u16 sob_base, u8 sob_mask, u8 *mask);
372062306a36Sopenharmony_civoid hl_fence_put(struct hl_fence *fence);
372162306a36Sopenharmony_civoid hl_fences_put(struct hl_fence **fence, int len);
372262306a36Sopenharmony_civoid hl_fence_get(struct hl_fence *fence);
372362306a36Sopenharmony_civoid cs_get(struct hl_cs *cs);
372462306a36Sopenharmony_cibool cs_needs_completion(struct hl_cs *cs);
372562306a36Sopenharmony_cibool cs_needs_timeout(struct hl_cs *cs);
372662306a36Sopenharmony_cibool is_staged_cs_last_exists(struct hl_device *hdev, struct hl_cs *cs);
372762306a36Sopenharmony_cistruct hl_cs *hl_staged_cs_find_first(struct hl_device *hdev, u64 cs_seq);
372862306a36Sopenharmony_civoid hl_multi_cs_completion_init(struct hl_device *hdev);
372962306a36Sopenharmony_ciu32 hl_get_active_cs_num(struct hl_device *hdev);
373062306a36Sopenharmony_ci
373162306a36Sopenharmony_civoid goya_set_asic_funcs(struct hl_device *hdev);
373262306a36Sopenharmony_civoid gaudi_set_asic_funcs(struct hl_device *hdev);
373362306a36Sopenharmony_civoid gaudi2_set_asic_funcs(struct hl_device *hdev);
373462306a36Sopenharmony_ci
373562306a36Sopenharmony_ciint hl_vm_ctx_init(struct hl_ctx *ctx);
373662306a36Sopenharmony_civoid hl_vm_ctx_fini(struct hl_ctx *ctx);
373762306a36Sopenharmony_ci
373862306a36Sopenharmony_ciint hl_vm_init(struct hl_device *hdev);
373962306a36Sopenharmony_civoid hl_vm_fini(struct hl_device *hdev);
374062306a36Sopenharmony_ci
374162306a36Sopenharmony_civoid hl_hw_block_mem_init(struct hl_ctx *ctx);
374262306a36Sopenharmony_civoid hl_hw_block_mem_fini(struct hl_ctx *ctx);
374362306a36Sopenharmony_ci
374462306a36Sopenharmony_ciu64 hl_reserve_va_block(struct hl_device *hdev, struct hl_ctx *ctx,
374562306a36Sopenharmony_ci		enum hl_va_range_type type, u64 size, u32 alignment);
374662306a36Sopenharmony_ciint hl_unreserve_va_block(struct hl_device *hdev, struct hl_ctx *ctx,
374762306a36Sopenharmony_ci		u64 start_addr, u64 size);
374862306a36Sopenharmony_ciint hl_pin_host_memory(struct hl_device *hdev, u64 addr, u64 size,
374962306a36Sopenharmony_ci			struct hl_userptr *userptr);
375062306a36Sopenharmony_civoid hl_unpin_host_memory(struct hl_device *hdev, struct hl_userptr *userptr);
375162306a36Sopenharmony_civoid hl_userptr_delete_list(struct hl_device *hdev,
375262306a36Sopenharmony_ci				struct list_head *userptr_list);
375362306a36Sopenharmony_cibool hl_userptr_is_pinned(struct hl_device *hdev, u64 addr, u32 size,
375462306a36Sopenharmony_ci				struct list_head *userptr_list,
375562306a36Sopenharmony_ci				struct hl_userptr **userptr);
375662306a36Sopenharmony_ci
375762306a36Sopenharmony_ciint hl_mmu_init(struct hl_device *hdev);
375862306a36Sopenharmony_civoid hl_mmu_fini(struct hl_device *hdev);
375962306a36Sopenharmony_ciint hl_mmu_ctx_init(struct hl_ctx *ctx);
376062306a36Sopenharmony_civoid hl_mmu_ctx_fini(struct hl_ctx *ctx);
376162306a36Sopenharmony_ciint hl_mmu_map_page(struct hl_ctx *ctx, u64 virt_addr, u64 phys_addr,
376262306a36Sopenharmony_ci		u32 page_size, bool flush_pte);
376362306a36Sopenharmony_ciint hl_mmu_get_real_page_size(struct hl_device *hdev, struct hl_mmu_properties *mmu_prop,
376462306a36Sopenharmony_ci				u32 page_size, u32 *real_page_size, bool is_dram_addr);
376562306a36Sopenharmony_ciint hl_mmu_unmap_page(struct hl_ctx *ctx, u64 virt_addr, u32 page_size,
376662306a36Sopenharmony_ci		bool flush_pte);
376762306a36Sopenharmony_ciint hl_mmu_map_contiguous(struct hl_ctx *ctx, u64 virt_addr,
376862306a36Sopenharmony_ci					u64 phys_addr, u32 size);
376962306a36Sopenharmony_ciint hl_mmu_unmap_contiguous(struct hl_ctx *ctx, u64 virt_addr, u32 size);
377062306a36Sopenharmony_ciint hl_mmu_invalidate_cache(struct hl_device *hdev, bool is_hard, u32 flags);
377162306a36Sopenharmony_ciint hl_mmu_invalidate_cache_range(struct hl_device *hdev, bool is_hard,
377262306a36Sopenharmony_ci					u32 flags, u32 asid, u64 va, u64 size);
377362306a36Sopenharmony_ciint hl_mmu_prefetch_cache_range(struct hl_ctx *ctx, u32 flags, u32 asid, u64 va, u64 size);
377462306a36Sopenharmony_ciu64 hl_mmu_get_next_hop_addr(struct hl_ctx *ctx, u64 curr_pte);
377562306a36Sopenharmony_ciu64 hl_mmu_get_hop_pte_phys_addr(struct hl_ctx *ctx, struct hl_mmu_properties *mmu_prop,
377662306a36Sopenharmony_ci					u8 hop_idx, u64 hop_addr, u64 virt_addr);
377762306a36Sopenharmony_civoid hl_mmu_hr_flush(struct hl_ctx *ctx);
377862306a36Sopenharmony_ciint hl_mmu_hr_init(struct hl_device *hdev, struct hl_mmu_hr_priv *hr_priv, u32 hop_table_size,
377962306a36Sopenharmony_ci			u64 pgt_size);
378062306a36Sopenharmony_civoid hl_mmu_hr_fini(struct hl_device *hdev, struct hl_mmu_hr_priv *hr_priv, u32 hop_table_size);
378162306a36Sopenharmony_civoid hl_mmu_hr_free_hop_remove_pgt(struct pgt_info *pgt_info, struct hl_mmu_hr_priv *hr_priv,
378262306a36Sopenharmony_ci				u32 hop_table_size);
378362306a36Sopenharmony_ciu64 hl_mmu_hr_pte_phys_to_virt(struct hl_ctx *ctx, struct pgt_info *pgt, u64 phys_pte_addr,
378462306a36Sopenharmony_ci							u32 hop_table_size);
378562306a36Sopenharmony_civoid hl_mmu_hr_write_pte(struct hl_ctx *ctx, struct pgt_info *pgt_info, u64 phys_pte_addr,
378662306a36Sopenharmony_ci							u64 val, u32 hop_table_size);
378762306a36Sopenharmony_civoid hl_mmu_hr_clear_pte(struct hl_ctx *ctx, struct pgt_info *pgt_info, u64 phys_pte_addr,
378862306a36Sopenharmony_ci							u32 hop_table_size);
378962306a36Sopenharmony_ciint hl_mmu_hr_put_pte(struct hl_ctx *ctx, struct pgt_info *pgt_info, struct hl_mmu_hr_priv *hr_priv,
379062306a36Sopenharmony_ci							u32 hop_table_size);
379162306a36Sopenharmony_civoid hl_mmu_hr_get_pte(struct hl_ctx *ctx, struct hl_hr_mmu_funcs *hr_func, u64 phys_hop_addr);
379262306a36Sopenharmony_cistruct pgt_info *hl_mmu_hr_get_next_hop_pgt_info(struct hl_ctx *ctx,
379362306a36Sopenharmony_ci							struct hl_hr_mmu_funcs *hr_func,
379462306a36Sopenharmony_ci							u64 curr_pte);
379562306a36Sopenharmony_cistruct pgt_info *hl_mmu_hr_alloc_hop(struct hl_ctx *ctx, struct hl_mmu_hr_priv *hr_priv,
379662306a36Sopenharmony_ci							struct hl_hr_mmu_funcs *hr_func,
379762306a36Sopenharmony_ci							struct hl_mmu_properties *mmu_prop);
379862306a36Sopenharmony_cistruct pgt_info *hl_mmu_hr_get_alloc_next_hop(struct hl_ctx *ctx,
379962306a36Sopenharmony_ci							struct hl_mmu_hr_priv *hr_priv,
380062306a36Sopenharmony_ci							struct hl_hr_mmu_funcs *hr_func,
380162306a36Sopenharmony_ci							struct hl_mmu_properties *mmu_prop,
380262306a36Sopenharmony_ci							u64 curr_pte, bool *is_new_hop);
380362306a36Sopenharmony_ciint hl_mmu_hr_get_tlb_info(struct hl_ctx *ctx, u64 virt_addr, struct hl_mmu_hop_info *hops,
380462306a36Sopenharmony_ci							struct hl_hr_mmu_funcs *hr_func);
380562306a36Sopenharmony_ciint hl_mmu_if_set_funcs(struct hl_device *hdev);
380662306a36Sopenharmony_civoid hl_mmu_v1_set_funcs(struct hl_device *hdev, struct hl_mmu_funcs *mmu);
380762306a36Sopenharmony_civoid hl_mmu_v2_hr_set_funcs(struct hl_device *hdev, struct hl_mmu_funcs *mmu);
380862306a36Sopenharmony_ciint hl_mmu_va_to_pa(struct hl_ctx *ctx, u64 virt_addr, u64 *phys_addr);
380962306a36Sopenharmony_ciint hl_mmu_get_tlb_info(struct hl_ctx *ctx, u64 virt_addr,
381062306a36Sopenharmony_ci			struct hl_mmu_hop_info *hops);
381162306a36Sopenharmony_ciu64 hl_mmu_scramble_addr(struct hl_device *hdev, u64 addr);
381262306a36Sopenharmony_ciu64 hl_mmu_descramble_addr(struct hl_device *hdev, u64 addr);
381362306a36Sopenharmony_cibool hl_is_dram_va(struct hl_device *hdev, u64 virt_addr);
381462306a36Sopenharmony_ci
381562306a36Sopenharmony_ciint hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name,
381662306a36Sopenharmony_ci				void __iomem *dst, u32 src_offset, u32 size);
381762306a36Sopenharmony_ciint hl_fw_send_pci_access_msg(struct hl_device *hdev, u32 opcode, u64 value);
381862306a36Sopenharmony_ciint hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg,
381962306a36Sopenharmony_ci				u16 len, u32 timeout, u64 *result);
382062306a36Sopenharmony_ciint hl_fw_unmask_irq(struct hl_device *hdev, u16 event_type);
382162306a36Sopenharmony_ciint hl_fw_unmask_irq_arr(struct hl_device *hdev, const u32 *irq_arr,
382262306a36Sopenharmony_ci		size_t irq_arr_size);
382362306a36Sopenharmony_ciint hl_fw_test_cpu_queue(struct hl_device *hdev);
382462306a36Sopenharmony_civoid *hl_fw_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size,
382562306a36Sopenharmony_ci						dma_addr_t *dma_handle);
382662306a36Sopenharmony_civoid hl_fw_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size,
382762306a36Sopenharmony_ci					void *vaddr);
382862306a36Sopenharmony_ciint hl_fw_send_heartbeat(struct hl_device *hdev);
382962306a36Sopenharmony_ciint hl_fw_cpucp_info_get(struct hl_device *hdev,
383062306a36Sopenharmony_ci				u32 sts_boot_dev_sts0_reg,
383162306a36Sopenharmony_ci				u32 sts_boot_dev_sts1_reg, u32 boot_err0_reg,
383262306a36Sopenharmony_ci				u32 boot_err1_reg);
383362306a36Sopenharmony_ciint hl_fw_cpucp_handshake(struct hl_device *hdev,
383462306a36Sopenharmony_ci				u32 sts_boot_dev_sts0_reg,
383562306a36Sopenharmony_ci				u32 sts_boot_dev_sts1_reg, u32 boot_err0_reg,
383662306a36Sopenharmony_ci				u32 boot_err1_reg);
383762306a36Sopenharmony_ciint hl_fw_get_eeprom_data(struct hl_device *hdev, void *data, size_t max_size);
383862306a36Sopenharmony_ciint hl_fw_get_monitor_dump(struct hl_device *hdev, void *data);
383962306a36Sopenharmony_ciint hl_fw_cpucp_pci_counters_get(struct hl_device *hdev,
384062306a36Sopenharmony_ci		struct hl_info_pci_counters *counters);
384162306a36Sopenharmony_ciint hl_fw_cpucp_total_energy_get(struct hl_device *hdev,
384262306a36Sopenharmony_ci			u64 *total_energy);
384362306a36Sopenharmony_ciint get_used_pll_index(struct hl_device *hdev, u32 input_pll_index,
384462306a36Sopenharmony_ci						enum pll_index *pll_index);
384562306a36Sopenharmony_ciint hl_fw_cpucp_pll_info_get(struct hl_device *hdev, u32 pll_index,
384662306a36Sopenharmony_ci		u16 *pll_freq_arr);
384762306a36Sopenharmony_ciint hl_fw_cpucp_power_get(struct hl_device *hdev, u64 *power);
384862306a36Sopenharmony_civoid hl_fw_ask_hard_reset_without_linux(struct hl_device *hdev);
384962306a36Sopenharmony_civoid hl_fw_ask_halt_machine_without_linux(struct hl_device *hdev);
385062306a36Sopenharmony_ciint hl_fw_init_cpu(struct hl_device *hdev);
385162306a36Sopenharmony_ciint hl_fw_wait_preboot_ready(struct hl_device *hdev);
385262306a36Sopenharmony_ciint hl_fw_read_preboot_status(struct hl_device *hdev);
385362306a36Sopenharmony_ciint hl_fw_dynamic_send_protocol_cmd(struct hl_device *hdev,
385462306a36Sopenharmony_ci				struct fw_load_mgr *fw_loader,
385562306a36Sopenharmony_ci				enum comms_cmd cmd, unsigned int size,
385662306a36Sopenharmony_ci				bool wait_ok, u32 timeout);
385762306a36Sopenharmony_ciint hl_fw_dram_replaced_row_get(struct hl_device *hdev,
385862306a36Sopenharmony_ci				struct cpucp_hbm_row_info *info);
385962306a36Sopenharmony_ciint hl_fw_dram_pending_row_get(struct hl_device *hdev, u32 *pend_rows_num);
386062306a36Sopenharmony_ciint hl_fw_cpucp_engine_core_asid_set(struct hl_device *hdev, u32 asid);
386162306a36Sopenharmony_ciint hl_fw_send_device_activity(struct hl_device *hdev, bool open);
386262306a36Sopenharmony_ciint hl_fw_send_soft_reset(struct hl_device *hdev);
386362306a36Sopenharmony_ciint hl_pci_bars_map(struct hl_device *hdev, const char * const name[3],
386462306a36Sopenharmony_ci			bool is_wc[3]);
386562306a36Sopenharmony_ciint hl_pci_elbi_read(struct hl_device *hdev, u64 addr, u32 *data);
386662306a36Sopenharmony_ciint hl_pci_iatu_write(struct hl_device *hdev, u32 addr, u32 data);
386762306a36Sopenharmony_ciint hl_pci_set_inbound_region(struct hl_device *hdev, u8 region,
386862306a36Sopenharmony_ci		struct hl_inbound_pci_region *pci_region);
386962306a36Sopenharmony_ciint hl_pci_set_outbound_region(struct hl_device *hdev,
387062306a36Sopenharmony_ci		struct hl_outbound_pci_region *pci_region);
387162306a36Sopenharmony_cienum pci_region hl_get_pci_memory_region(struct hl_device *hdev, u64 addr);
387262306a36Sopenharmony_ciint hl_pci_init(struct hl_device *hdev);
387362306a36Sopenharmony_civoid hl_pci_fini(struct hl_device *hdev);
387462306a36Sopenharmony_ci
387562306a36Sopenharmony_cilong hl_fw_get_frequency(struct hl_device *hdev, u32 pll_index, bool curr);
387662306a36Sopenharmony_civoid hl_fw_set_frequency(struct hl_device *hdev, u32 pll_index, u64 freq);
387762306a36Sopenharmony_ciint hl_get_temperature(struct hl_device *hdev, int sensor_index, u32 attr, long *value);
387862306a36Sopenharmony_ciint hl_set_temperature(struct hl_device *hdev, int sensor_index, u32 attr, long value);
387962306a36Sopenharmony_ciint hl_get_voltage(struct hl_device *hdev, int sensor_index, u32 attr, long *value);
388062306a36Sopenharmony_ciint hl_get_current(struct hl_device *hdev, int sensor_index, u32 attr, long *value);
388162306a36Sopenharmony_ciint hl_get_fan_speed(struct hl_device *hdev, int sensor_index, u32 attr, long *value);
388262306a36Sopenharmony_ciint hl_get_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr, long *value);
388362306a36Sopenharmony_civoid hl_set_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr, long value);
388462306a36Sopenharmony_cilong hl_fw_get_max_power(struct hl_device *hdev);
388562306a36Sopenharmony_civoid hl_fw_set_max_power(struct hl_device *hdev);
388662306a36Sopenharmony_ciint hl_fw_get_sec_attest_info(struct hl_device *hdev, struct cpucp_sec_attest_info *sec_attest_info,
388762306a36Sopenharmony_ci				u32 nonce);
388862306a36Sopenharmony_ciint hl_set_voltage(struct hl_device *hdev, int sensor_index, u32 attr, long value);
388962306a36Sopenharmony_ciint hl_set_current(struct hl_device *hdev, int sensor_index, u32 attr, long value);
389062306a36Sopenharmony_ciint hl_set_power(struct hl_device *hdev, int sensor_index, u32 attr, long value);
389162306a36Sopenharmony_ciint hl_get_power(struct hl_device *hdev, int sensor_index, u32 attr, long *value);
389262306a36Sopenharmony_ciint hl_fw_get_clk_rate(struct hl_device *hdev, u32 *cur_clk, u32 *max_clk);
389362306a36Sopenharmony_civoid hl_fw_set_pll_profile(struct hl_device *hdev);
389462306a36Sopenharmony_civoid hl_sysfs_add_dev_clk_attr(struct hl_device *hdev, struct attribute_group *dev_clk_attr_grp);
389562306a36Sopenharmony_civoid hl_sysfs_add_dev_vrm_attr(struct hl_device *hdev, struct attribute_group *dev_vrm_attr_grp);
389662306a36Sopenharmony_ciint hl_fw_send_generic_request(struct hl_device *hdev, enum hl_passthrough_type sub_opcode,
389762306a36Sopenharmony_ci						dma_addr_t buff, u32 *size);
389862306a36Sopenharmony_ci
389962306a36Sopenharmony_civoid hw_sob_get(struct hl_hw_sob *hw_sob);
390062306a36Sopenharmony_civoid hw_sob_put(struct hl_hw_sob *hw_sob);
390162306a36Sopenharmony_civoid hl_encaps_release_handle_and_put_ctx(struct kref *ref);
390262306a36Sopenharmony_civoid hl_encaps_release_handle_and_put_sob_ctx(struct kref *ref);
390362306a36Sopenharmony_civoid hl_hw_queue_encaps_sig_set_sob_info(struct hl_device *hdev,
390462306a36Sopenharmony_ci			struct hl_cs *cs, struct hl_cs_job *job,
390562306a36Sopenharmony_ci			struct hl_cs_compl *cs_cmpl);
390662306a36Sopenharmony_ci
390762306a36Sopenharmony_ciint hl_dec_init(struct hl_device *hdev);
390862306a36Sopenharmony_civoid hl_dec_fini(struct hl_device *hdev);
390962306a36Sopenharmony_civoid hl_dec_ctx_fini(struct hl_ctx *ctx);
391062306a36Sopenharmony_ci
391162306a36Sopenharmony_civoid hl_release_pending_user_interrupts(struct hl_device *hdev);
391262306a36Sopenharmony_civoid hl_abort_waiting_for_cs_completions(struct hl_device *hdev);
391362306a36Sopenharmony_ciint hl_cs_signal_sob_wraparound_handler(struct hl_device *hdev, u32 q_idx,
391462306a36Sopenharmony_ci			struct hl_hw_sob **hw_sob, u32 count, bool encaps_sig);
391562306a36Sopenharmony_ci
391662306a36Sopenharmony_ciint hl_state_dump(struct hl_device *hdev);
391762306a36Sopenharmony_ciconst char *hl_state_dump_get_sync_name(struct hl_device *hdev, u32 sync_id);
391862306a36Sopenharmony_ciconst char *hl_state_dump_get_monitor_name(struct hl_device *hdev,
391962306a36Sopenharmony_ci					struct hl_mon_state_dump *mon);
392062306a36Sopenharmony_civoid hl_state_dump_free_sync_to_engine_map(struct hl_sync_to_engine_map *map);
392162306a36Sopenharmony_ci__printf(4, 5) int hl_snprintf_resize(char **buf, size_t *size, size_t *offset,
392262306a36Sopenharmony_ci					const char *format, ...);
392362306a36Sopenharmony_cichar *hl_format_as_binary(char *buf, size_t buf_len, u32 n);
392462306a36Sopenharmony_ciconst char *hl_sync_engine_to_string(enum hl_sync_engine_type engine_type);
392562306a36Sopenharmony_ci
392662306a36Sopenharmony_civoid hl_mem_mgr_init(struct device *dev, struct hl_mem_mgr *mmg);
392762306a36Sopenharmony_civoid hl_mem_mgr_fini(struct hl_mem_mgr *mmg);
392862306a36Sopenharmony_civoid hl_mem_mgr_idr_destroy(struct hl_mem_mgr *mmg);
392962306a36Sopenharmony_ciint hl_mem_mgr_mmap(struct hl_mem_mgr *mmg, struct vm_area_struct *vma,
393062306a36Sopenharmony_ci		    void *args);
393162306a36Sopenharmony_cistruct hl_mmap_mem_buf *hl_mmap_mem_buf_get(struct hl_mem_mgr *mmg,
393262306a36Sopenharmony_ci						   u64 handle);
393362306a36Sopenharmony_ciint hl_mmap_mem_buf_put_handle(struct hl_mem_mgr *mmg, u64 handle);
393462306a36Sopenharmony_ciint hl_mmap_mem_buf_put(struct hl_mmap_mem_buf *buf);
393562306a36Sopenharmony_cistruct hl_mmap_mem_buf *
393662306a36Sopenharmony_cihl_mmap_mem_buf_alloc(struct hl_mem_mgr *mmg,
393762306a36Sopenharmony_ci		      struct hl_mmap_mem_buf_behavior *behavior, gfp_t gfp,
393862306a36Sopenharmony_ci		      void *args);
393962306a36Sopenharmony_ci__printf(2, 3) void hl_engine_data_sprintf(struct engines_data *e, const char *fmt, ...);
394062306a36Sopenharmony_civoid hl_capture_razwi(struct hl_device *hdev, u64 addr, u16 *engine_id, u16 num_of_engines,
394162306a36Sopenharmony_ci			u8 flags);
394262306a36Sopenharmony_civoid hl_handle_razwi(struct hl_device *hdev, u64 addr, u16 *engine_id, u16 num_of_engines,
394362306a36Sopenharmony_ci			u8 flags, u64 *event_mask);
394462306a36Sopenharmony_civoid hl_capture_page_fault(struct hl_device *hdev, u64 addr, u16 eng_id, bool is_pmmu);
394562306a36Sopenharmony_civoid hl_handle_page_fault(struct hl_device *hdev, u64 addr, u16 eng_id, bool is_pmmu,
394662306a36Sopenharmony_ci				u64 *event_mask);
394762306a36Sopenharmony_civoid hl_handle_critical_hw_err(struct hl_device *hdev, u16 event_id, u64 *event_mask);
394862306a36Sopenharmony_civoid hl_handle_fw_err(struct hl_device *hdev, struct hl_info_fw_err_info *info);
394962306a36Sopenharmony_civoid hl_enable_err_info_capture(struct hl_error_info *captured_err_info);
395062306a36Sopenharmony_ci
395162306a36Sopenharmony_ci#ifdef CONFIG_DEBUG_FS
395262306a36Sopenharmony_ci
395362306a36Sopenharmony_civoid hl_debugfs_init(void);
395462306a36Sopenharmony_civoid hl_debugfs_fini(void);
395562306a36Sopenharmony_ciint hl_debugfs_device_init(struct hl_device *hdev);
395662306a36Sopenharmony_civoid hl_debugfs_device_fini(struct hl_device *hdev);
395762306a36Sopenharmony_civoid hl_debugfs_add_device(struct hl_device *hdev);
395862306a36Sopenharmony_civoid hl_debugfs_remove_device(struct hl_device *hdev);
395962306a36Sopenharmony_civoid hl_debugfs_add_file(struct hl_fpriv *hpriv);
396062306a36Sopenharmony_civoid hl_debugfs_remove_file(struct hl_fpriv *hpriv);
396162306a36Sopenharmony_civoid hl_debugfs_add_cb(struct hl_cb *cb);
396262306a36Sopenharmony_civoid hl_debugfs_remove_cb(struct hl_cb *cb);
396362306a36Sopenharmony_civoid hl_debugfs_add_cs(struct hl_cs *cs);
396462306a36Sopenharmony_civoid hl_debugfs_remove_cs(struct hl_cs *cs);
396562306a36Sopenharmony_civoid hl_debugfs_add_job(struct hl_device *hdev, struct hl_cs_job *job);
396662306a36Sopenharmony_civoid hl_debugfs_remove_job(struct hl_device *hdev, struct hl_cs_job *job);
396762306a36Sopenharmony_civoid hl_debugfs_add_userptr(struct hl_device *hdev, struct hl_userptr *userptr);
396862306a36Sopenharmony_civoid hl_debugfs_remove_userptr(struct hl_device *hdev,
396962306a36Sopenharmony_ci				struct hl_userptr *userptr);
397062306a36Sopenharmony_civoid hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx);
397162306a36Sopenharmony_civoid hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx);
397262306a36Sopenharmony_civoid hl_debugfs_set_state_dump(struct hl_device *hdev, char *data,
397362306a36Sopenharmony_ci					unsigned long length);
397462306a36Sopenharmony_ci
397562306a36Sopenharmony_ci#else
397662306a36Sopenharmony_ci
397762306a36Sopenharmony_cistatic inline void __init hl_debugfs_init(void)
397862306a36Sopenharmony_ci{
397962306a36Sopenharmony_ci}
398062306a36Sopenharmony_ci
398162306a36Sopenharmony_cistatic inline void hl_debugfs_fini(void)
398262306a36Sopenharmony_ci{
398362306a36Sopenharmony_ci}
398462306a36Sopenharmony_ci
398562306a36Sopenharmony_cistatic inline int hl_debugfs_device_init(struct hl_device *hdev)
398662306a36Sopenharmony_ci{
398762306a36Sopenharmony_ci	return 0;
398862306a36Sopenharmony_ci}
398962306a36Sopenharmony_ci
399062306a36Sopenharmony_cistatic inline void hl_debugfs_device_fini(struct hl_device *hdev)
399162306a36Sopenharmony_ci{
399262306a36Sopenharmony_ci}
399362306a36Sopenharmony_ci
399462306a36Sopenharmony_cistatic inline void hl_debugfs_add_device(struct hl_device *hdev)
399562306a36Sopenharmony_ci{
399662306a36Sopenharmony_ci}
399762306a36Sopenharmony_ci
399862306a36Sopenharmony_cistatic inline void hl_debugfs_remove_device(struct hl_device *hdev)
399962306a36Sopenharmony_ci{
400062306a36Sopenharmony_ci}
400162306a36Sopenharmony_ci
400262306a36Sopenharmony_cistatic inline void hl_debugfs_add_file(struct hl_fpriv *hpriv)
400362306a36Sopenharmony_ci{
400462306a36Sopenharmony_ci}
400562306a36Sopenharmony_ci
400662306a36Sopenharmony_cistatic inline void hl_debugfs_remove_file(struct hl_fpriv *hpriv)
400762306a36Sopenharmony_ci{
400862306a36Sopenharmony_ci}
400962306a36Sopenharmony_ci
401062306a36Sopenharmony_cistatic inline void hl_debugfs_add_cb(struct hl_cb *cb)
401162306a36Sopenharmony_ci{
401262306a36Sopenharmony_ci}
401362306a36Sopenharmony_ci
401462306a36Sopenharmony_cistatic inline void hl_debugfs_remove_cb(struct hl_cb *cb)
401562306a36Sopenharmony_ci{
401662306a36Sopenharmony_ci}
401762306a36Sopenharmony_ci
401862306a36Sopenharmony_cistatic inline void hl_debugfs_add_cs(struct hl_cs *cs)
401962306a36Sopenharmony_ci{
402062306a36Sopenharmony_ci}
402162306a36Sopenharmony_ci
402262306a36Sopenharmony_cistatic inline void hl_debugfs_remove_cs(struct hl_cs *cs)
402362306a36Sopenharmony_ci{
402462306a36Sopenharmony_ci}
402562306a36Sopenharmony_ci
402662306a36Sopenharmony_cistatic inline void hl_debugfs_add_job(struct hl_device *hdev,
402762306a36Sopenharmony_ci					struct hl_cs_job *job)
402862306a36Sopenharmony_ci{
402962306a36Sopenharmony_ci}
403062306a36Sopenharmony_ci
403162306a36Sopenharmony_cistatic inline void hl_debugfs_remove_job(struct hl_device *hdev,
403262306a36Sopenharmony_ci					struct hl_cs_job *job)
403362306a36Sopenharmony_ci{
403462306a36Sopenharmony_ci}
403562306a36Sopenharmony_ci
403662306a36Sopenharmony_cistatic inline void hl_debugfs_add_userptr(struct hl_device *hdev,
403762306a36Sopenharmony_ci					struct hl_userptr *userptr)
403862306a36Sopenharmony_ci{
403962306a36Sopenharmony_ci}
404062306a36Sopenharmony_ci
404162306a36Sopenharmony_cistatic inline void hl_debugfs_remove_userptr(struct hl_device *hdev,
404262306a36Sopenharmony_ci					struct hl_userptr *userptr)
404362306a36Sopenharmony_ci{
404462306a36Sopenharmony_ci}
404562306a36Sopenharmony_ci
404662306a36Sopenharmony_cistatic inline void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev,
404762306a36Sopenharmony_ci					struct hl_ctx *ctx)
404862306a36Sopenharmony_ci{
404962306a36Sopenharmony_ci}
405062306a36Sopenharmony_ci
405162306a36Sopenharmony_cistatic inline void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev,
405262306a36Sopenharmony_ci					struct hl_ctx *ctx)
405362306a36Sopenharmony_ci{
405462306a36Sopenharmony_ci}
405562306a36Sopenharmony_ci
405662306a36Sopenharmony_cistatic inline void hl_debugfs_set_state_dump(struct hl_device *hdev,
405762306a36Sopenharmony_ci					char *data, unsigned long length)
405862306a36Sopenharmony_ci{
405962306a36Sopenharmony_ci}
406062306a36Sopenharmony_ci
406162306a36Sopenharmony_ci#endif
406262306a36Sopenharmony_ci
406362306a36Sopenharmony_ci/* Security */
406462306a36Sopenharmony_ciint hl_unsecure_register(struct hl_device *hdev, u32 mm_reg_addr, int offset,
406562306a36Sopenharmony_ci		const u32 pb_blocks[], struct hl_block_glbl_sec sgs_array[],
406662306a36Sopenharmony_ci		int array_size);
406762306a36Sopenharmony_ciint hl_unsecure_registers(struct hl_device *hdev, const u32 mm_reg_array[],
406862306a36Sopenharmony_ci		int mm_array_size, int offset, const u32 pb_blocks[],
406962306a36Sopenharmony_ci		struct hl_block_glbl_sec sgs_array[], int blocks_array_size);
407062306a36Sopenharmony_civoid hl_config_glbl_sec(struct hl_device *hdev, const u32 pb_blocks[],
407162306a36Sopenharmony_ci		struct hl_block_glbl_sec sgs_array[], u32 block_offset,
407262306a36Sopenharmony_ci		int array_size);
407362306a36Sopenharmony_civoid hl_secure_block(struct hl_device *hdev,
407462306a36Sopenharmony_ci		struct hl_block_glbl_sec sgs_array[], int array_size);
407562306a36Sopenharmony_ciint hl_init_pb_with_mask(struct hl_device *hdev, u32 num_dcores,
407662306a36Sopenharmony_ci		u32 dcore_offset, u32 num_instances, u32 instance_offset,
407762306a36Sopenharmony_ci		const u32 pb_blocks[], u32 blocks_array_size,
407862306a36Sopenharmony_ci		const u32 *regs_array, u32 regs_array_size, u64 mask);
407962306a36Sopenharmony_ciint hl_init_pb(struct hl_device *hdev, u32 num_dcores, u32 dcore_offset,
408062306a36Sopenharmony_ci		u32 num_instances, u32 instance_offset,
408162306a36Sopenharmony_ci		const u32 pb_blocks[], u32 blocks_array_size,
408262306a36Sopenharmony_ci		const u32 *regs_array, u32 regs_array_size);
408362306a36Sopenharmony_ciint hl_init_pb_ranges_with_mask(struct hl_device *hdev, u32 num_dcores,
408462306a36Sopenharmony_ci		u32 dcore_offset, u32 num_instances, u32 instance_offset,
408562306a36Sopenharmony_ci		const u32 pb_blocks[], u32 blocks_array_size,
408662306a36Sopenharmony_ci		const struct range *regs_range_array, u32 regs_range_array_size,
408762306a36Sopenharmony_ci		u64 mask);
408862306a36Sopenharmony_ciint hl_init_pb_ranges(struct hl_device *hdev, u32 num_dcores,
408962306a36Sopenharmony_ci		u32 dcore_offset, u32 num_instances, u32 instance_offset,
409062306a36Sopenharmony_ci		const u32 pb_blocks[], u32 blocks_array_size,
409162306a36Sopenharmony_ci		const struct range *regs_range_array,
409262306a36Sopenharmony_ci		u32 regs_range_array_size);
409362306a36Sopenharmony_ciint hl_init_pb_single_dcore(struct hl_device *hdev, u32 dcore_offset,
409462306a36Sopenharmony_ci		u32 num_instances, u32 instance_offset,
409562306a36Sopenharmony_ci		const u32 pb_blocks[], u32 blocks_array_size,
409662306a36Sopenharmony_ci		const u32 *regs_array, u32 regs_array_size);
409762306a36Sopenharmony_ciint hl_init_pb_ranges_single_dcore(struct hl_device *hdev, u32 dcore_offset,
409862306a36Sopenharmony_ci		u32 num_instances, u32 instance_offset,
409962306a36Sopenharmony_ci		const u32 pb_blocks[], u32 blocks_array_size,
410062306a36Sopenharmony_ci		const struct range *regs_range_array,
410162306a36Sopenharmony_ci		u32 regs_range_array_size);
410262306a36Sopenharmony_civoid hl_ack_pb(struct hl_device *hdev, u32 num_dcores, u32 dcore_offset,
410362306a36Sopenharmony_ci		u32 num_instances, u32 instance_offset,
410462306a36Sopenharmony_ci		const u32 pb_blocks[], u32 blocks_array_size);
410562306a36Sopenharmony_civoid hl_ack_pb_with_mask(struct hl_device *hdev, u32 num_dcores,
410662306a36Sopenharmony_ci		u32 dcore_offset, u32 num_instances, u32 instance_offset,
410762306a36Sopenharmony_ci		const u32 pb_blocks[], u32 blocks_array_size, u64 mask);
410862306a36Sopenharmony_civoid hl_ack_pb_single_dcore(struct hl_device *hdev, u32 dcore_offset,
410962306a36Sopenharmony_ci		u32 num_instances, u32 instance_offset,
411062306a36Sopenharmony_ci		const u32 pb_blocks[], u32 blocks_array_size);
411162306a36Sopenharmony_ci
411262306a36Sopenharmony_ci/* IOCTLs */
411362306a36Sopenharmony_cilong hl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
411462306a36Sopenharmony_cilong hl_ioctl_control(struct file *filep, unsigned int cmd, unsigned long arg);
411562306a36Sopenharmony_ciint hl_cb_ioctl(struct hl_fpriv *hpriv, void *data);
411662306a36Sopenharmony_ciint hl_cs_ioctl(struct hl_fpriv *hpriv, void *data);
411762306a36Sopenharmony_ciint hl_wait_ioctl(struct hl_fpriv *hpriv, void *data);
411862306a36Sopenharmony_ciint hl_mem_ioctl(struct hl_fpriv *hpriv, void *data);
411962306a36Sopenharmony_ci
412062306a36Sopenharmony_ci#endif /* HABANALABSP_H_ */
4121