Path: blob/master/drivers/accel/habanalabs/common/habanalabs.h
26436 views
/* SPDX-License-Identifier: GPL-2.01*2* Copyright 2016-2023 HabanaLabs, Ltd.3* All Rights Reserved.4*5*/67#ifndef HABANALABSP_H_8#define HABANALABSP_H_910#include <linux/habanalabs/cpucp_if.h>11#include "../include/common/qman_if.h"12#include "../include/hw_ip/mmu/mmu_general.h"13#include <uapi/drm/habanalabs_accel.h>1415#include <linux/cdev.h>16#include <linux/iopoll.h>17#include <linux/irqreturn.h>18#include <linux/dma-direction.h>19#include <linux/scatterlist.h>20#include <linux/hashtable.h>21#include <linux/debugfs.h>22#include <linux/rwsem.h>23#include <linux/eventfd.h>24#include <linux/bitfield.h>25#include <linux/genalloc.h>26#include <linux/sched/signal.h>27#include <linux/io-64-nonatomic-lo-hi.h>28#include <linux/coresight.h>29#include <linux/dma-buf.h>3031#include <drm/drm_device.h>32#include <drm/drm_file.h>3334#include "security.h"3536#define HL_NAME "habanalabs"3738struct hl_device;39struct hl_fpriv;4041#define PCI_VENDOR_ID_HABANALABS 0x1da34243/* Use upper bits of mmap offset to store habana driver specific information.44* bits[63:59] - Encode mmap type45* bits[45:0] - mmap offset value46*47* NOTE: struct vm_area_struct.vm_pgoff uses offset in pages. Hence, these48* defines are w.r.t to PAGE_SIZE49*/50#define HL_MMAP_TYPE_SHIFT (59 - PAGE_SHIFT)51#define HL_MMAP_TYPE_MASK (0x1full << HL_MMAP_TYPE_SHIFT)52#define HL_MMAP_TYPE_TS_BUFF (0x10ull << HL_MMAP_TYPE_SHIFT)53#define HL_MMAP_TYPE_BLOCK (0x4ull << HL_MMAP_TYPE_SHIFT)54#define HL_MMAP_TYPE_CB (0x2ull << HL_MMAP_TYPE_SHIFT)5556#define HL_MMAP_OFFSET_VALUE_MASK (0x1FFFFFFFFFFFull >> PAGE_SHIFT)57#define HL_MMAP_OFFSET_VALUE_GET(off) (off & HL_MMAP_OFFSET_VALUE_MASK)5859#define HL_PENDING_RESET_PER_SEC 1060#define HL_PENDING_RESET_MAX_TRIALS 60 /* 10 minutes */61#define HL_PENDING_RESET_LONG_SEC 6062/*63* In device fini, wait 10 minutes for user processes to be terminated after we kill them.64* This is needed to prevent situation of clearing resources while user processes are still alive.65*/66#define HL_WAIT_PROCESS_KILL_ON_DEVICE_FINI 6006768#define HL_HARD_RESET_MAX_TIMEOUT 12069#define HL_PLDM_HARD_RESET_MAX_TIMEOUT (HL_HARD_RESET_MAX_TIMEOUT * 3)7071#define HL_DEVICE_TIMEOUT_USEC 1000000 /* 1 s */7273#define HL_HEARTBEAT_PER_USEC 10000000 /* 10 s */7475#define HL_PLL_LOW_JOB_FREQ_USEC 5000000 /* 5 s */7677#define HL_CPUCP_INFO_TIMEOUT_USEC 10000000 /* 10s */78#define HL_CPUCP_EEPROM_TIMEOUT_USEC 10000000 /* 10s */79#define HL_CPUCP_MON_DUMP_TIMEOUT_USEC 10000000 /* 10s */80#define HL_CPUCP_SEC_ATTEST_INFO_TINEOUT_USEC 10000000 /* 10s */8182#define HL_FW_STATUS_POLL_INTERVAL_USEC 10000 /* 10ms */83#define HL_FW_COMMS_STATUS_PLDM_POLL_INTERVAL_USEC 1000000 /* 1s */8485#define HL_PCI_ELBI_TIMEOUT_MSEC 10 /* 10ms */8687#define HL_INVALID_QUEUE UINT_MAX8889#define HL_COMMON_USER_CQ_INTERRUPT_ID 0xFFF90#define HL_COMMON_DEC_INTERRUPT_ID 0xFFE9192#define HL_STATE_DUMP_HIST_LEN 59394/* Default value for device reset trigger , an invalid value */95#define HL_RESET_TRIGGER_DEFAULT 0xFF9697#define OBJ_NAMES_HASH_TABLE_BITS 7 /* 1 << 7 buckets */98#define SYNC_TO_ENGINE_HASH_TABLE_BITS 7 /* 1 << 7 buckets */99100/* Memory */101#define MEM_HASH_TABLE_BITS 7 /* 1 << 7 buckets */102103/* MMU */104#define MMU_HASH_TABLE_BITS 7 /* 1 << 7 buckets */105106#define TIMESTAMP_FREE_NODES_NUM 512107108/**109* enum hl_mmu_page_table_location - mmu page table location110* @MMU_DR_PGT: page-table is located on device DRAM.111* @MMU_HR_PGT: page-table is located on host memory.112* @MMU_NUM_PGT_LOCATIONS: number of page-table locations currently supported.113*/114enum hl_mmu_page_table_location {115MMU_DR_PGT = 0, /* device-dram-resident MMU PGT */116MMU_HR_PGT, /* host resident MMU PGT */117MMU_NUM_PGT_LOCATIONS /* num of PGT locations */118};119120/*121* HL_RSVD_SOBS 'sync stream' reserved sync objects per QMAN stream122* HL_RSVD_MONS 'sync stream' reserved monitors per QMAN stream123*/124#define HL_RSVD_SOBS 2125#define HL_RSVD_MONS 1126127/*128* HL_COLLECTIVE_RSVD_MSTR_MONS 'collective' reserved monitors per QMAN stream129*/130#define HL_COLLECTIVE_RSVD_MSTR_MONS 2131132#define HL_MAX_SOB_VAL (1 << 15)133134#define IS_POWER_OF_2(n) (n != 0 && ((n & (n - 1)) == 0))135#define IS_MAX_PENDING_CS_VALID(n) (IS_POWER_OF_2(n) && (n > 1))136137#define HL_PCI_NUM_BARS 6138139/* Completion queue entry relates to completed job */140#define HL_COMPLETION_MODE_JOB 0141/* Completion queue entry relates to completed command submission */142#define HL_COMPLETION_MODE_CS 1143144#define HL_MAX_DCORES 8145146/* DMA alloc/free wrappers */147#define hl_asic_dma_alloc_coherent(hdev, size, dma_handle, flags) \148hl_asic_dma_alloc_coherent_caller(hdev, size, dma_handle, flags, __func__)149150#define hl_asic_dma_pool_zalloc(hdev, size, mem_flags, dma_handle) \151hl_asic_dma_pool_zalloc_caller(hdev, size, mem_flags, dma_handle, __func__)152153#define hl_asic_dma_free_coherent(hdev, size, cpu_addr, dma_handle) \154hl_asic_dma_free_coherent_caller(hdev, size, cpu_addr, dma_handle, __func__)155156#define hl_asic_dma_pool_free(hdev, vaddr, dma_addr) \157hl_asic_dma_pool_free_caller(hdev, vaddr, dma_addr, __func__)158159#define hl_dma_map_sgtable(hdev, sgt, dir) \160hl_dma_map_sgtable_caller(hdev, sgt, dir, __func__)161#define hl_dma_unmap_sgtable(hdev, sgt, dir) \162hl_dma_unmap_sgtable_caller(hdev, sgt, dir, __func__)163164/*165* Reset Flags166*167* - HL_DRV_RESET_HARD168* If set do hard reset to all engines. If not set reset just169* compute/DMA engines.170*171* - HL_DRV_RESET_FROM_RESET_THR172* Set if the caller is the hard-reset thread173*174* - HL_DRV_RESET_HEARTBEAT175* Set if reset is due to heartbeat176*177* - HL_DRV_RESET_TDR178* Set if reset is due to TDR179*180* - HL_DRV_RESET_DEV_RELEASE181* Set if reset is due to device release182*183* - HL_DRV_RESET_BYPASS_REQ_TO_FW184* F/W will perform the reset. No need to ask it to reset the device. This is relevant185* only when running with secured f/w186*187* - HL_DRV_RESET_FW_FATAL_ERR188* Set if reset is due to a fatal error from FW189*190* - HL_DRV_RESET_DELAY191* Set if a delay should be added before the reset192*193* - HL_DRV_RESET_FROM_WD_THR194* Set if the caller is the device release watchdog thread195*/196197#define HL_DRV_RESET_HARD (1 << 0)198#define HL_DRV_RESET_FROM_RESET_THR (1 << 1)199#define HL_DRV_RESET_HEARTBEAT (1 << 2)200#define HL_DRV_RESET_TDR (1 << 3)201#define HL_DRV_RESET_DEV_RELEASE (1 << 4)202#define HL_DRV_RESET_BYPASS_REQ_TO_FW (1 << 5)203#define HL_DRV_RESET_FW_FATAL_ERR (1 << 6)204#define HL_DRV_RESET_DELAY (1 << 7)205#define HL_DRV_RESET_FROM_WD_THR (1 << 8)206207/*208* Security209*/210211#define HL_PB_SHARED 1212#define HL_PB_NA 0213#define HL_PB_SINGLE_INSTANCE 1214#define HL_BLOCK_SIZE 0x1000215#define HL_BLOCK_GLBL_ERR_MASK 0xF40216#define HL_BLOCK_GLBL_ERR_ADDR 0xF44217#define HL_BLOCK_GLBL_ERR_CAUSE 0xF48218#define HL_BLOCK_GLBL_SEC_OFFS 0xF80219#define HL_BLOCK_GLBL_SEC_SIZE (HL_BLOCK_SIZE - HL_BLOCK_GLBL_SEC_OFFS)220#define HL_BLOCK_GLBL_SEC_LEN (HL_BLOCK_GLBL_SEC_SIZE / sizeof(u32))221#define UNSET_GLBL_SEC_BIT(array, b) ((array)[((b) / 32)] |= (1 << ((b) % 32)))222223enum hl_protection_levels {224SECURED_LVL,225PRIVILEGED_LVL,226NON_SECURED_LVL227};228229/**230* struct iterate_module_ctx - HW module iterator231* @fn: function to apply to each HW module instance232* @data: optional internal data to the function iterator233* @rc: return code for optional use of iterator/iterator-caller234*/235struct iterate_module_ctx {236/*237* callback for the HW module iterator238* @hdev: pointer to the habanalabs device structure239* @block: block (ASIC specific definition can be dcore/hdcore)240* @inst: HW module instance within the block241* @offset: current HW module instance offset from the 1-st HW module instance242* in the 1-st block243* @ctx: the iterator context.244*/245void (*fn)(struct hl_device *hdev, int block, int inst, u32 offset,246struct iterate_module_ctx *ctx);247void *data;248int rc;249};250251struct hl_block_glbl_sec {252u32 sec_array[HL_BLOCK_GLBL_SEC_LEN];253};254255#define HL_MAX_SOBS_PER_MONITOR 8256257/**258* struct hl_gen_wait_properties - properties for generating a wait CB259* @data: command buffer260* @q_idx: queue id is used to extract fence register address261* @size: offset in command buffer262* @sob_base: SOB base to use in this wait CB263* @sob_val: SOB value to wait for264* @mon_id: monitor to use in this wait CB265* @sob_mask: each bit represents a SOB offset from sob_base to be used266*/267struct hl_gen_wait_properties {268void *data;269u32 q_idx;270u32 size;271u16 sob_base;272u16 sob_val;273u16 mon_id;274u8 sob_mask;275};276277/**278* struct pgt_info - MMU hop page info.279* @node: hash linked-list node for the pgts on host (shadow pgts for device resident MMU and280* actual pgts for host resident MMU).281* @phys_addr: physical address of the pgt.282* @virt_addr: host virtual address of the pgt (see above device/host resident).283* @shadow_addr: shadow hop in the host for device resident MMU.284* @ctx: pointer to the owner ctx.285* @num_of_ptes: indicates how many ptes are used in the pgt. used only for dynamically286* allocated HOPs (all HOPs but HOP0)287*288* The MMU page tables hierarchy can be placed either on the device's DRAM (in which case shadow289* pgts will be stored on host memory) or on host memory (in which case no shadow is required).290*291* When a new level (hop) is needed during mapping this structure will be used to describe292* the newly allocated hop as well as to track number of PTEs in it.293* During unmapping, if no valid PTEs remained in the page of a newly allocated hop, it is294* freed with its pgt_info structure.295*/296struct pgt_info {297struct hlist_node node;298u64 phys_addr;299u64 virt_addr;300u64 shadow_addr;301struct hl_ctx *ctx;302int num_of_ptes;303};304305/**306* enum hl_pci_match_mode - pci match mode per region307* @PCI_ADDRESS_MATCH_MODE: address match mode308* @PCI_BAR_MATCH_MODE: bar match mode309*/310enum hl_pci_match_mode {311PCI_ADDRESS_MATCH_MODE,312PCI_BAR_MATCH_MODE313};314315/**316* enum hl_fw_component - F/W components to read version through registers.317* @FW_COMP_BOOT_FIT: boot fit.318* @FW_COMP_PREBOOT: preboot.319* @FW_COMP_LINUX: linux.320*/321enum hl_fw_component {322FW_COMP_BOOT_FIT,323FW_COMP_PREBOOT,324FW_COMP_LINUX,325};326327/**328* enum hl_fw_types - F/W types present in the system329* @FW_TYPE_NONE: no FW component indication330* @FW_TYPE_LINUX: Linux image for device CPU331* @FW_TYPE_BOOT_CPU: Boot image for device CPU332* @FW_TYPE_PREBOOT_CPU: Indicates pre-loaded CPUs are present in the system333* (preboot, ppboot etc...)334* @FW_TYPE_ALL_TYPES: Mask for all types335*/336enum hl_fw_types {337FW_TYPE_NONE = 0x0,338FW_TYPE_LINUX = 0x1,339FW_TYPE_BOOT_CPU = 0x2,340FW_TYPE_PREBOOT_CPU = 0x4,341FW_TYPE_ALL_TYPES =342(FW_TYPE_LINUX | FW_TYPE_BOOT_CPU | FW_TYPE_PREBOOT_CPU)343};344345/**346* enum hl_queue_type - Supported QUEUE types.347* @QUEUE_TYPE_NA: queue is not available.348* @QUEUE_TYPE_EXT: external queue which is a DMA channel that may access the349* host.350* @QUEUE_TYPE_INT: internal queue that performs DMA inside the device's351* memories and/or operates the compute engines.352* @QUEUE_TYPE_CPU: S/W queue for communication with the device's CPU.353* @QUEUE_TYPE_HW: queue of DMA and compute engines jobs, for which completion354* notifications are sent by H/W.355*/356enum hl_queue_type {357QUEUE_TYPE_NA,358QUEUE_TYPE_EXT,359QUEUE_TYPE_INT,360QUEUE_TYPE_CPU,361QUEUE_TYPE_HW362};363364enum hl_cs_type {365CS_TYPE_DEFAULT,366CS_TYPE_SIGNAL,367CS_TYPE_WAIT,368CS_TYPE_COLLECTIVE_WAIT,369CS_RESERVE_SIGNALS,370CS_UNRESERVE_SIGNALS,371CS_TYPE_ENGINE_CORE,372CS_TYPE_ENGINES,373CS_TYPE_FLUSH_PCI_HBW_WRITES,374};375376/*377* struct hl_inbound_pci_region - inbound region descriptor378* @mode: pci match mode for this region379* @addr: region target address380* @size: region size in bytes381* @offset_in_bar: offset within bar (address match mode)382* @bar: bar id383*/384struct hl_inbound_pci_region {385enum hl_pci_match_mode mode;386u64 addr;387u64 size;388u64 offset_in_bar;389u8 bar;390};391392/*393* struct hl_outbound_pci_region - outbound region descriptor394* @addr: region target address395* @size: region size in bytes396*/397struct hl_outbound_pci_region {398u64 addr;399u64 size;400};401402/*403* enum queue_cb_alloc_flags - Indicates queue support for CBs that404* allocated by Kernel or by User405* @CB_ALLOC_KERNEL: support only CBs that allocated by Kernel406* @CB_ALLOC_USER: support only CBs that allocated by User407*/408enum queue_cb_alloc_flags {409CB_ALLOC_KERNEL = 0x1,410CB_ALLOC_USER = 0x2411};412413/*414* struct hl_hw_sob - H/W SOB info.415* @hdev: habanalabs device structure.416* @kref: refcount of this SOB. The SOB will reset once the refcount is zero.417* @sob_id: id of this SOB.418* @sob_addr: the sob offset from the base address.419* @q_idx: the H/W queue that uses this SOB.420* @need_reset: reset indication set when switching to the other sob.421*/422struct hl_hw_sob {423struct hl_device *hdev;424struct kref kref;425u32 sob_id;426u32 sob_addr;427u32 q_idx;428bool need_reset;429};430431enum hl_collective_mode {432HL_COLLECTIVE_NOT_SUPPORTED = 0x0,433HL_COLLECTIVE_MASTER = 0x1,434HL_COLLECTIVE_SLAVE = 0x2435};436437/**438* struct hw_queue_properties - queue information.439* @type: queue type.440* @cb_alloc_flags: bitmap which indicates if the hw queue supports CB441* that allocated by the Kernel driver and therefore,442* a CB handle can be provided for jobs on this queue.443* Otherwise, a CB address must be provided.444* @collective_mode: collective mode of current queue445* @q_dram_bd_address: PQ dram address, used when PQ need to reside in DRAM.446* @driver_only: true if only the driver is allowed to send a job to this queue,447* false otherwise.448* @binned: True if the queue is binned out and should not be used449* @supports_sync_stream: True if queue supports sync stream450* @dram_bd: True if the bd should be copied to dram, needed for PQ which has been allocated on dram451*/452struct hw_queue_properties {453enum hl_queue_type type;454enum queue_cb_alloc_flags cb_alloc_flags;455enum hl_collective_mode collective_mode;456u64 q_dram_bd_address;457u8 driver_only;458u8 binned;459u8 supports_sync_stream;460u8 dram_bd;461};462463/**464* enum vm_type - virtual memory mapping request information.465* @VM_TYPE_USERPTR: mapping of user memory to device virtual address.466* @VM_TYPE_PHYS_PACK: mapping of DRAM memory to device virtual address.467*/468enum vm_type {469VM_TYPE_USERPTR = 0x1,470VM_TYPE_PHYS_PACK = 0x2471};472473/**474* enum mmu_op_flags - mmu operation relevant information.475* @MMU_OP_USERPTR: operation on user memory (host resident).476* @MMU_OP_PHYS_PACK: operation on DRAM (device resident).477* @MMU_OP_CLEAR_MEMCACHE: operation has to clear memcache.478* @MMU_OP_SKIP_LOW_CACHE_INV: operation is allowed to skip parts of cache invalidation.479*/480enum mmu_op_flags {481MMU_OP_USERPTR = 0x1,482MMU_OP_PHYS_PACK = 0x2,483MMU_OP_CLEAR_MEMCACHE = 0x4,484MMU_OP_SKIP_LOW_CACHE_INV = 0x8,485};486487488/**489* enum hl_device_hw_state - H/W device state. use this to understand whether490* to do reset before hw_init or not491* @HL_DEVICE_HW_STATE_CLEAN: H/W state is clean. i.e. after hard reset492* @HL_DEVICE_HW_STATE_DIRTY: H/W state is dirty. i.e. we started to execute493* hw_init494*/495enum hl_device_hw_state {496HL_DEVICE_HW_STATE_CLEAN = 0,497HL_DEVICE_HW_STATE_DIRTY498};499500#define HL_MMU_VA_ALIGNMENT_NOT_NEEDED 0501502/**503* struct hl_mmu_properties - ASIC specific MMU address translation properties.504* @start_addr: virtual start address of the memory region.505* @end_addr: virtual end address of the memory region.506* @hop_shifts: array holds HOPs shifts.507* @hop_masks: array holds HOPs masks.508* @last_mask: mask to get the bit indicating this is the last hop.509* @pgt_size: size for page tables.510* @supported_pages_mask: bitmask for supported page size (relevant only for MMUs511* supporting multiple page size).512* @page_size: default page size used to allocate memory.513* @num_hops: The amount of hops supported by the translation table.514* @hop_table_size: HOP table size.515* @hop0_tables_total_size: total size for all HOP0 tables.516* @host_resident: Should the MMU page table reside in host memory or in the517* device DRAM.518*/519struct hl_mmu_properties {520u64 start_addr;521u64 end_addr;522u64 hop_shifts[MMU_HOP_MAX];523u64 hop_masks[MMU_HOP_MAX];524u64 last_mask;525u64 pgt_size;526u64 supported_pages_mask;527u32 page_size;528u32 num_hops;529u32 hop_table_size;530u32 hop0_tables_total_size;531u8 host_resident;532};533534/**535* struct hl_hints_range - hint addresses reserved va range.536* @start_addr: start address of the va range.537* @end_addr: end address of the va range.538*/539struct hl_hints_range {540u64 start_addr;541u64 end_addr;542};543544/**545* struct asic_fixed_properties - ASIC specific immutable properties.546* @hw_queues_props: H/W queues properties.547* @special_blocks: points to an array containing special blocks info.548* @skip_special_blocks_cfg: special blocks skip configs.549* @cpucp_info: received various information from CPU-CP regarding the H/W, e.g.550* available sensors.551* @uboot_ver: F/W U-boot version.552* @preboot_ver: F/W Preboot version.553* @dmmu: DRAM MMU address translation properties.554* @pmmu: PCI (host) MMU address translation properties.555* @pmmu_huge: PCI (host) MMU address translation properties for memory556* allocated with huge pages.557* @hints_dram_reserved_va_range: dram hint addresses reserved range.558* @hints_host_reserved_va_range: host hint addresses reserved range.559* @hints_host_hpage_reserved_va_range: host huge page hint addresses reserved range.560* @sram_base_address: SRAM physical start address.561* @sram_end_address: SRAM physical end address.562* @sram_user_base_address - SRAM physical start address for user access.563* @dram_base_address: DRAM physical start address.564* @dram_end_address: DRAM physical end address.565* @dram_user_base_address: DRAM physical start address for user access.566* @dram_size: DRAM total size.567* @dram_pci_bar_size: size of PCI bar towards DRAM.568* @max_power_default: max power of the device after reset.569* @dc_power_default: power consumed by the device in mode idle.570* @dram_size_for_default_page_mapping: DRAM size needed to map to avoid page571* fault.572* @pcie_dbi_base_address: Base address of the PCIE_DBI block.573* @pcie_aux_dbi_reg_addr: Address of the PCIE_AUX DBI register.574* @mmu_pgt_addr: base physical address in DRAM of MMU page tables.575* @mmu_dram_default_page_addr: DRAM default page physical address.576* @tpc_enabled_mask: which TPCs are enabled.577* @tpc_binning_mask: which TPCs are binned. 0 means usable and 1 means binned.578* @dram_enabled_mask: which DRAMs are enabled.579* @dram_binning_mask: which DRAMs are binned. 0 means usable, 1 means binned.580* @dram_hints_align_mask: dram va hint addresses alignment mask which is used581* for hints validity check.582* @cfg_base_address: config space base address.583* @mmu_cache_mng_addr: address of the MMU cache.584* @mmu_cache_mng_size: size of the MMU cache.585* @device_dma_offset_for_host_access: the offset to add to host DMA addresses586* to enable the device to access them.587* @host_base_address: host physical start address for host DMA from device588* @host_end_address: host physical end address for host DMA from device589* @max_freq_value: current max clk frequency.590* @engine_core_interrupt_reg_addr: interrupt register address for engine core to use591* in order to raise events toward FW.592* @clk_pll_index: clock PLL index that specify which PLL determines the clock593* we display to the user594* @mmu_pgt_size: MMU page tables total size.595* @mmu_pte_size: PTE size in MMU page tables.596* @dram_page_size: The DRAM physical page size.597* @cfg_size: configuration space size on SRAM.598* @sram_size: total size of SRAM.599* @max_asid: maximum number of open contexts (ASIDs).600* @num_of_events: number of possible internal H/W IRQs.601* @psoc_pci_pll_nr: PCI PLL NR value.602* @psoc_pci_pll_nf: PCI PLL NF value.603* @psoc_pci_pll_od: PCI PLL OD value.604* @psoc_pci_pll_div_factor: PCI PLL DIV FACTOR 1 value.605* @psoc_timestamp_frequency: frequency of the psoc timestamp clock.606* @high_pll: high PLL frequency used by the device.607* @cb_pool_cb_cnt: number of CBs in the CB pool.608* @cb_pool_cb_size: size of each CB in the CB pool.609* @decoder_enabled_mask: which decoders are enabled.610* @decoder_binning_mask: which decoders are binned, 0 means usable and 1 means binned.611* @rotator_enabled_mask: which rotators are enabled.612* @edma_enabled_mask: which EDMAs are enabled.613* @edma_binning_mask: which EDMAs are binned, 0 means usable and 1 means614* binned (at most one binned DMA).615* @max_pending_cs: maximum of concurrent pending command submissions616* @max_queues: maximum amount of queues in the system617* @fw_preboot_cpu_boot_dev_sts0: bitmap representation of preboot cpu618* capabilities reported by FW, bit description619* can be found in CPU_BOOT_DEV_STS0620* @fw_preboot_cpu_boot_dev_sts1: bitmap representation of preboot cpu621* capabilities reported by FW, bit description622* can be found in CPU_BOOT_DEV_STS1623* @fw_bootfit_cpu_boot_dev_sts0: bitmap representation of boot cpu security624* status reported by FW, bit description can be625* found in CPU_BOOT_DEV_STS0626* @fw_bootfit_cpu_boot_dev_sts1: bitmap representation of boot cpu security627* status reported by FW, bit description can be628* found in CPU_BOOT_DEV_STS1629* @fw_app_cpu_boot_dev_sts0: bitmap representation of application security630* status reported by FW, bit description can be631* found in CPU_BOOT_DEV_STS0632* @fw_app_cpu_boot_dev_sts1: bitmap representation of application security633* status reported by FW, bit description can be634* found in CPU_BOOT_DEV_STS1635* @max_dec: maximum number of decoders636* @hmmu_hif_enabled_mask: mask of HMMUs/HIFs that are not isolated (enabled)637* 1- enabled, 0- isolated.638* @faulty_dram_cluster_map: mask of faulty DRAM cluster.639* 1- faulty cluster, 0- good cluster.640* @xbar_edge_enabled_mask: mask of XBAR_EDGEs that are not isolated (enabled)641* 1- enabled, 0- isolated.642* @device_mem_alloc_default_page_size: may be different than dram_page_size only for ASICs for643* which the property supports_user_set_page_size is true644* (i.e. the DRAM supports multiple page sizes), otherwise645* it will shall be equal to dram_page_size.646* @num_engine_cores: number of engine cpu cores.647* @max_num_of_engines: maximum number of all engines in the ASIC.648* @num_of_special_blocks: special_blocks array size.649* @glbl_err_max_cause_num: global err max cause number.650* @hbw_flush_reg: register to read to generate HBW flush. value of 0 means HBW flush is651* not supported.652* @reserved_fw_mem_size: size of dram memory reserved for FW.653* @fw_event_queue_size: queue size for events from CPU-CP.654* A value of 0 means using the default HL_EQ_SIZE_IN_BYTES value.655* @collective_first_sob: first sync object available for collective use656* @collective_first_mon: first monitor available for collective use657* @sync_stream_first_sob: first sync object available for sync stream use658* @sync_stream_first_mon: first monitor available for sync stream use659* @first_available_user_sob: first sob available for the user660* @first_available_user_mon: first monitor available for the user661* @first_available_user_interrupt: first available interrupt reserved for the user662* @first_available_cq: first available CQ for the user.663* @user_interrupt_count: number of user interrupts.664* @user_dec_intr_count: number of decoder interrupts exposed to user.665* @tpc_interrupt_id: interrupt id for TPC to use in order to raise events towards the host.666* @eq_interrupt_id: interrupt id for EQ, uses to synchronize EQ interrupts in hard-reset.667* @cache_line_size: device cache line size.668* @server_type: Server type that the ASIC is currently installed in.669* The value is according to enum hl_server_type in uapi file.670* @completion_queues_count: number of completion queues.671* @completion_mode: 0 - job based completion, 1 - cs based completion672* @mme_master_slave_mode: 0 - Each MME works independently, 1 - MME works673* in Master/Slave mode674* @fw_security_enabled: true if security measures are enabled in firmware,675* false otherwise676* @fw_cpu_boot_dev_sts0_valid: status bits are valid and can be fetched from677* BOOT_DEV_STS0678* @fw_cpu_boot_dev_sts1_valid: status bits are valid and can be fetched from679* BOOT_DEV_STS1680* @dram_supports_virtual_memory: is there an MMU towards the DRAM681* @hard_reset_done_by_fw: true if firmware is handling hard reset flow682* @num_functional_hbms: number of functional HBMs in each DCORE.683* @hints_range_reservation: device support hint addresses range reservation.684* @iatu_done_by_fw: true if iATU configuration is being done by FW.685* @dynamic_fw_load: is dynamic FW load is supported.686* @gic_interrupts_enable: true if FW is not blocking GIC controller,687* false otherwise.688* @use_get_power_for_reset_history: To support backward compatibility for Goya689* and Gaudi690* @supports_compute_reset: is a reset which is not a hard-reset supported by this asic.691* @allow_inference_soft_reset: true if the ASIC supports soft reset that is692* initiated by user or TDR. This is only true693* in inference ASICs, as there is no real-world694* use-case of doing soft-reset in training (due695* to the fact that training runs on multiple696* devices)697* @configurable_stop_on_err: is stop-on-error option configurable via debugfs.698* @set_max_power_on_device_init: true if need to set max power in F/W on device init.699* @supports_user_set_page_size: true if user can set the allocation page size.700* @dma_mask: the dma mask to be set for this device.701* @supports_advanced_cpucp_rc: true if new cpucp opcodes are supported.702* @supports_engine_modes: true if changing engines/engine_cores modes is supported.703* @support_dynamic_resereved_fw_size: true if we support dynamic reserved size for fw.704*/705struct asic_fixed_properties {706struct hw_queue_properties *hw_queues_props;707struct hl_special_block_info *special_blocks;708struct hl_skip_blocks_cfg skip_special_blocks_cfg;709struct cpucp_info cpucp_info;710char uboot_ver[VERSION_MAX_LEN];711char preboot_ver[VERSION_MAX_LEN];712struct hl_mmu_properties dmmu;713struct hl_mmu_properties pmmu;714struct hl_mmu_properties pmmu_huge;715struct hl_hints_range hints_dram_reserved_va_range;716struct hl_hints_range hints_host_reserved_va_range;717struct hl_hints_range hints_host_hpage_reserved_va_range;718u64 sram_base_address;719u64 sram_end_address;720u64 sram_user_base_address;721u64 dram_base_address;722u64 dram_end_address;723u64 dram_user_base_address;724u64 dram_size;725u64 dram_pci_bar_size;726u64 max_power_default;727u64 dc_power_default;728u64 dram_size_for_default_page_mapping;729u64 pcie_dbi_base_address;730u64 pcie_aux_dbi_reg_addr;731u64 mmu_pgt_addr;732u64 mmu_dram_default_page_addr;733u64 tpc_enabled_mask;734u64 tpc_binning_mask;735u64 dram_enabled_mask;736u64 dram_binning_mask;737u64 dram_hints_align_mask;738u64 cfg_base_address;739u64 mmu_cache_mng_addr;740u64 mmu_cache_mng_size;741u64 device_dma_offset_for_host_access;742u64 host_base_address;743u64 host_end_address;744u64 max_freq_value;745u64 engine_core_interrupt_reg_addr;746u32 clk_pll_index;747u32 mmu_pgt_size;748u32 mmu_pte_size;749u32 dram_page_size;750u32 cfg_size;751u32 sram_size;752u32 max_asid;753u32 num_of_events;754u32 psoc_pci_pll_nr;755u32 psoc_pci_pll_nf;756u32 psoc_pci_pll_od;757u32 psoc_pci_pll_div_factor;758u32 psoc_timestamp_frequency;759u32 high_pll;760u32 cb_pool_cb_cnt;761u32 cb_pool_cb_size;762u32 decoder_enabled_mask;763u32 decoder_binning_mask;764u32 rotator_enabled_mask;765u32 edma_enabled_mask;766u32 edma_binning_mask;767u32 max_pending_cs;768u32 max_queues;769u32 fw_preboot_cpu_boot_dev_sts0;770u32 fw_preboot_cpu_boot_dev_sts1;771u32 fw_bootfit_cpu_boot_dev_sts0;772u32 fw_bootfit_cpu_boot_dev_sts1;773u32 fw_app_cpu_boot_dev_sts0;774u32 fw_app_cpu_boot_dev_sts1;775u32 max_dec;776u32 hmmu_hif_enabled_mask;777u32 faulty_dram_cluster_map;778u32 xbar_edge_enabled_mask;779u32 device_mem_alloc_default_page_size;780u32 num_engine_cores;781u32 max_num_of_engines;782u32 num_of_special_blocks;783u32 glbl_err_max_cause_num;784u32 hbw_flush_reg;785u32 reserved_fw_mem_size;786u32 fw_event_queue_size;787u16 collective_first_sob;788u16 collective_first_mon;789u16 sync_stream_first_sob;790u16 sync_stream_first_mon;791u16 first_available_user_sob[HL_MAX_DCORES];792u16 first_available_user_mon[HL_MAX_DCORES];793u16 first_available_user_interrupt;794u16 first_available_cq[HL_MAX_DCORES];795u16 user_interrupt_count;796u16 user_dec_intr_count;797u16 tpc_interrupt_id;798u16 eq_interrupt_id;799u16 cache_line_size;800u16 server_type;801u8 completion_queues_count;802u8 completion_mode;803u8 mme_master_slave_mode;804u8 fw_security_enabled;805u8 fw_cpu_boot_dev_sts0_valid;806u8 fw_cpu_boot_dev_sts1_valid;807u8 dram_supports_virtual_memory;808u8 hard_reset_done_by_fw;809u8 num_functional_hbms;810u8 hints_range_reservation;811u8 iatu_done_by_fw;812u8 dynamic_fw_load;813u8 gic_interrupts_enable;814u8 use_get_power_for_reset_history;815u8 supports_compute_reset;816u8 allow_inference_soft_reset;817u8 configurable_stop_on_err;818u8 set_max_power_on_device_init;819u8 supports_user_set_page_size;820u8 dma_mask;821u8 supports_advanced_cpucp_rc;822u8 supports_engine_modes;823u8 support_dynamic_resereved_fw_size;824};825826/**827* struct hl_fence - software synchronization primitive828* @completion: fence is implemented using completion829* @refcount: refcount for this fence830* @cs_sequence: sequence of the corresponding command submission831* @stream_master_qid_map: streams masters QID bitmap to represent all streams832* masters QIDs that multi cs is waiting on833* @error: mark this fence with error834* @timestamp: timestamp upon completion835* @mcs_handling_done: indicates that corresponding command submission has836* finished msc handling, this does not mean it was part837* of the mcs838*/839struct hl_fence {840struct completion completion;841struct kref refcount;842u64 cs_sequence;843u32 stream_master_qid_map;844int error;845ktime_t timestamp;846u8 mcs_handling_done;847};848849/**850* struct hl_cs_compl - command submission completion object.851* @base_fence: hl fence object.852* @lock: spinlock to protect fence.853* @hdev: habanalabs device structure.854* @hw_sob: the H/W SOB used in this signal/wait CS.855* @encaps_sig_hdl: encaps signals handler.856* @cs_seq: command submission sequence number.857* @type: type of the CS - signal/wait.858* @sob_val: the SOB value that is used in this signal/wait CS.859* @sob_group: the SOB group that is used in this collective wait CS.860* @encaps_signals: indication whether it's a completion object of cs with861* encaps signals or not.862*/863struct hl_cs_compl {864struct hl_fence base_fence;865spinlock_t lock;866struct hl_device *hdev;867struct hl_hw_sob *hw_sob;868struct hl_cs_encaps_sig_handle *encaps_sig_hdl;869u64 cs_seq;870enum hl_cs_type type;871u16 sob_val;872u16 sob_group;873bool encaps_signals;874};875876/*877* Command Buffers878*/879880/**881* struct hl_ts_buff - describes a timestamp buffer.882* @kernel_buff_address: Holds the internal buffer's kernel virtual address.883* @user_buff_address: Holds the user buffer's kernel virtual address.884* @kernel_buff_size: Holds the internal kernel buffer size.885*/886struct hl_ts_buff {887void *kernel_buff_address;888void *user_buff_address;889u32 kernel_buff_size;890};891892struct hl_mmap_mem_buf;893894/**895* struct hl_mem_mgr - describes unified memory manager for mappable memory chunks.896* @dev: back pointer to the owning device897* @lock: protects handles898* @handles: an idr holding all active handles to the memory buffers in the system.899*/900struct hl_mem_mgr {901struct device *dev;902spinlock_t lock;903struct idr handles;904};905906/**907* struct hl_mem_mgr_fini_stats - describes statistics returned during memory manager teardown.908* @n_busy_cb: the amount of CB handles that could not be removed909* @n_busy_ts: the amount of TS handles that could not be removed910* @n_busy_other: the amount of any other type of handles that could not be removed911*/912struct hl_mem_mgr_fini_stats {913u32 n_busy_cb;914u32 n_busy_ts;915u32 n_busy_other;916};917918/**919* struct hl_mmap_mem_buf_behavior - describes unified memory manager buffer behavior920* @topic: string identifier used for logging921* @mem_id: memory type identifier, embedded in the handle and used to identify922* the memory type by handle.923* @alloc: callback executed on buffer allocation, shall allocate the memory,924* set it under buffer private, and set mappable size.925* @mmap: callback executed on mmap, must map the buffer to vma926* @release: callback executed on release, must free the resources used by the buffer927*/928struct hl_mmap_mem_buf_behavior {929const char *topic;930u64 mem_id;931932int (*alloc)(struct hl_mmap_mem_buf *buf, gfp_t gfp, void *args);933int (*mmap)(struct hl_mmap_mem_buf *buf, struct vm_area_struct *vma, void *args);934void (*release)(struct hl_mmap_mem_buf *buf);935};936937/**938* struct hl_mmap_mem_buf - describes a single unified memory buffer939* @behavior: buffer behavior940* @mmg: back pointer to the unified memory manager941* @refcount: reference counter for buffer users942* @private: pointer to buffer behavior private data943* @mmap: atomic boolean indicating whether or not the buffer is mapped right now944* @real_mapped_size: the actual size of buffer mapped, after part of it may be released,945* may change at runtime.946* @mappable_size: the original mappable size of the buffer, does not change after947* the allocation.948* @handle: the buffer id in mmg handles store949*/950struct hl_mmap_mem_buf {951struct hl_mmap_mem_buf_behavior *behavior;952struct hl_mem_mgr *mmg;953struct kref refcount;954void *private;955atomic_t mmap;956u64 real_mapped_size;957u64 mappable_size;958u64 handle;959};960961/**962* struct hl_cb - describes a Command Buffer.963* @hdev: pointer to device this CB belongs to.964* @ctx: pointer to the CB owner's context.965* @buf: back pointer to the parent mappable memory buffer966* @debugfs_list: node in debugfs list of command buffers.967* @pool_list: node in pool list of command buffers.968* @kernel_address: Holds the CB's kernel virtual address.969* @virtual_addr: Holds the CB's virtual address.970* @bus_address: Holds the CB's DMA address.971* @size: holds the CB's size.972* @roundup_size: holds the cb size after roundup to page size.973* @cs_cnt: holds number of CS that this CB participates in.974* @is_handle_destroyed: atomic boolean indicating whether or not the CB handle was destroyed.975* @is_pool: true if CB was acquired from the pool, false otherwise.976* @is_internal: internally allocated977* @is_mmu_mapped: true if the CB is mapped to the device's MMU.978*/979struct hl_cb {980struct hl_device *hdev;981struct hl_ctx *ctx;982struct hl_mmap_mem_buf *buf;983struct list_head debugfs_list;984struct list_head pool_list;985void *kernel_address;986u64 virtual_addr;987dma_addr_t bus_address;988u32 size;989u32 roundup_size;990atomic_t cs_cnt;991atomic_t is_handle_destroyed;992u8 is_pool;993u8 is_internal;994u8 is_mmu_mapped;995};996997998/*999* QUEUES1000*/10011002struct hl_cs_job;10031004/* Queue length of external and HW queues */1005#define HL_QUEUE_LENGTH 40961006#define HL_QUEUE_SIZE_IN_BYTES (HL_QUEUE_LENGTH * HL_BD_SIZE)10071008#if (HL_MAX_JOBS_PER_CS > HL_QUEUE_LENGTH)1009#error "HL_QUEUE_LENGTH must be greater than HL_MAX_JOBS_PER_CS"1010#endif10111012/* HL_CQ_LENGTH is in units of struct hl_cq_entry */1013#define HL_CQ_LENGTH HL_QUEUE_LENGTH1014#define HL_CQ_SIZE_IN_BYTES (HL_CQ_LENGTH * HL_CQ_ENTRY_SIZE)10151016/* Must be power of 2 */1017#define HL_EQ_LENGTH 641018#define HL_EQ_SIZE_IN_BYTES (HL_EQ_LENGTH * HL_EQ_ENTRY_SIZE)10191020/* Host <-> CPU-CP shared memory size */1021#define HL_CPU_ACCESSIBLE_MEM_SIZE SZ_2M10221023/**1024* struct hl_sync_stream_properties -1025* describes a H/W queue sync stream properties1026* @hw_sob: array of the used H/W SOBs by this H/W queue.1027* @next_sob_val: the next value to use for the currently used SOB.1028* @base_sob_id: the base SOB id of the SOBs used by this queue.1029* @base_mon_id: the base MON id of the MONs used by this queue.1030* @collective_mstr_mon_id: the MON ids of the MONs used by this master queue1031* in order to sync with all slave queues.1032* @collective_slave_mon_id: the MON id used by this slave queue in order to1033* sync with its master queue.1034* @collective_sob_id: current SOB id used by this collective slave queue1035* to signal its collective master queue upon completion.1036* @curr_sob_offset: the id offset to the currently used SOB from the1037* HL_RSVD_SOBS that are being used by this queue.1038*/1039struct hl_sync_stream_properties {1040struct hl_hw_sob hw_sob[HL_RSVD_SOBS];1041u16 next_sob_val;1042u16 base_sob_id;1043u16 base_mon_id;1044u16 collective_mstr_mon_id[HL_COLLECTIVE_RSVD_MSTR_MONS];1045u16 collective_slave_mon_id;1046u16 collective_sob_id;1047u8 curr_sob_offset;1048};10491050/**1051* struct hl_encaps_signals_mgr - describes sync stream encapsulated signals1052* handlers manager1053* @lock: protects handles.1054* @handles: an idr to hold all encapsulated signals handles.1055*/1056struct hl_encaps_signals_mgr {1057spinlock_t lock;1058struct idr handles;1059};10601061/**1062* struct hl_hw_queue - describes a H/W transport queue.1063* @shadow_queue: pointer to a shadow queue that holds pointers to jobs.1064* @sync_stream_prop: sync stream queue properties1065* @queue_type: type of queue.1066* @collective_mode: collective mode of current queue1067* @kernel_address: holds the queue's kernel virtual address.1068* @bus_address: holds the queue's DMA address.1069* @pq_dram_address: hold the dram address when the PQ is allocated, used when dram_bd is true in1070* queue properites.1071* @pi: holds the queue's pi value.1072* @ci: holds the queue's ci value, AS CALCULATED BY THE DRIVER (not real ci).1073* @hw_queue_id: the id of the H/W queue.1074* @cq_id: the id for the corresponding CQ for this H/W queue.1075* @msi_vec: the IRQ number of the H/W queue.1076* @int_queue_len: length of internal queue (number of entries).1077* @valid: is the queue valid (we have array of 32 queues, not all of them1078* exist).1079* @supports_sync_stream: True if queue supports sync stream1080* @dram_bd: True if the bd should be copied to dram, needed for PQ which has been allocated on dram1081*/1082struct hl_hw_queue {1083struct hl_cs_job **shadow_queue;1084struct hl_sync_stream_properties sync_stream_prop;1085enum hl_queue_type queue_type;1086enum hl_collective_mode collective_mode;1087void *kernel_address;1088dma_addr_t bus_address;1089u64 pq_dram_address;1090u32 pi;1091atomic_t ci;1092u32 hw_queue_id;1093u32 cq_id;1094u32 msi_vec;1095u16 int_queue_len;1096u8 valid;1097u8 supports_sync_stream;1098u8 dram_bd;1099};11001101/**1102* struct hl_cq - describes a completion queue1103* @hdev: pointer to the device structure1104* @kernel_address: holds the queue's kernel virtual address1105* @bus_address: holds the queue's DMA address1106* @cq_idx: completion queue index in array1107* @hw_queue_id: the id of the matching H/W queue1108* @ci: ci inside the queue1109* @pi: pi inside the queue1110* @free_slots_cnt: counter of free slots in queue1111*/1112struct hl_cq {1113struct hl_device *hdev;1114void *kernel_address;1115dma_addr_t bus_address;1116u32 cq_idx;1117u32 hw_queue_id;1118u32 ci;1119u32 pi;1120atomic_t free_slots_cnt;1121};11221123enum hl_user_interrupt_type {1124HL_USR_INTERRUPT_CQ = 0,1125HL_USR_INTERRUPT_DECODER,1126HL_USR_INTERRUPT_TPC,1127HL_USR_INTERRUPT_UNEXPECTED1128};11291130/**1131* struct hl_ts_free_jobs - holds user interrupt ts free nodes related data1132* @free_nodes_pool: pool of nodes to be used for free timestamp jobs1133* @free_nodes_length: number of nodes in free_nodes_pool1134* @next_avail_free_node_idx: index of the next free node in the pool1135*1136* the free nodes pool must be protected by the user interrupt lock1137* to avoid race between different interrupts which are using the same1138* ts buffer with different offsets.1139*/1140struct hl_ts_free_jobs {1141struct timestamp_reg_free_node *free_nodes_pool;1142u32 free_nodes_length;1143u32 next_avail_free_node_idx;1144};11451146/**1147* struct hl_user_interrupt - holds user interrupt information1148* @hdev: pointer to the device structure1149* @ts_free_jobs_data: timestamp free jobs related data1150* @type: user interrupt type1151* @wait_list_head: head to the list of user threads pending on this interrupt1152* @ts_list_head: head to the list of timestamp records1153* @wait_list_lock: protects wait_list_head1154* @ts_list_lock: protects ts_list_head1155* @timestamp: last timestamp taken upon interrupt1156* @interrupt_id: msix interrupt id1157*/1158struct hl_user_interrupt {1159struct hl_device *hdev;1160struct hl_ts_free_jobs ts_free_jobs_data;1161enum hl_user_interrupt_type type;1162struct list_head wait_list_head;1163struct list_head ts_list_head;1164spinlock_t wait_list_lock;1165spinlock_t ts_list_lock;1166ktime_t timestamp;1167u32 interrupt_id;1168};11691170/**1171* struct timestamp_reg_free_node - holds the timestamp registration free objects node1172* @free_objects_node: node in the list free_obj_jobs1173* @cq_cb: pointer to cq command buffer to be freed1174* @buf: pointer to timestamp buffer to be freed1175* @in_use: indicates whether the node still in use in workqueue thread.1176* @dynamic_alloc: indicates whether the node was allocated dynamically in the interrupt handler1177*/1178struct timestamp_reg_free_node {1179struct list_head free_objects_node;1180struct hl_cb *cq_cb;1181struct hl_mmap_mem_buf *buf;1182atomic_t in_use;1183u8 dynamic_alloc;1184};11851186/* struct timestamp_reg_work_obj - holds the timestamp registration free objects job1187* the job will be to pass over the free_obj_jobs list and put refcount to objects1188* in each node of the list1189* @free_obj: workqueue object to free timestamp registration node objects1190* @hdev: pointer to the device structure1191* @free_obj_head: list of free jobs nodes (node type timestamp_reg_free_node)1192* @dynamic_alloc_free_obj_head: list of free jobs nodes which were dynamically allocated in the1193* interrupt handler.1194*/1195struct timestamp_reg_work_obj {1196struct work_struct free_obj;1197struct hl_device *hdev;1198struct list_head *free_obj_head;1199struct list_head *dynamic_alloc_free_obj_head;1200};12011202/* struct timestamp_reg_info - holds the timestamp registration related data.1203* @buf: pointer to the timestamp buffer which include both user/kernel buffers.1204* relevant only when doing timestamps records registration.1205* @cq_cb: pointer to CQ counter CB.1206* @interrupt: interrupt that the node hanged on it's wait list.1207* @timestamp_kernel_addr: timestamp handle address, where to set timestamp1208* relevant only when doing timestamps records1209* registration.1210* @in_use: indicates if the node already in use. relevant only when doing1211* timestamps records registration, since in this case the driver1212* will have it's own buffer which serve as a records pool instead of1213* allocating records dynamically.1214*/1215struct timestamp_reg_info {1216struct hl_mmap_mem_buf *buf;1217struct hl_cb *cq_cb;1218struct hl_user_interrupt *interrupt;1219u64 *timestamp_kernel_addr;1220bool in_use;1221};12221223/**1224* struct hl_user_pending_interrupt - holds a context to a user thread1225* pending on an interrupt1226* @ts_reg_info: holds the timestamps registration nodes info1227* @list_node: node in the list of user threads pending on an interrupt or timestamp1228* @fence: hl fence object for interrupt completion1229* @cq_target_value: CQ target value1230* @cq_kernel_addr: CQ kernel address, to be used in the cq interrupt1231* handler for target value comparison1232*/1233struct hl_user_pending_interrupt {1234struct timestamp_reg_info ts_reg_info;1235struct list_head list_node;1236struct hl_fence fence;1237u64 cq_target_value;1238u64 *cq_kernel_addr;1239};12401241/**1242* struct hl_eq - describes the event queue (single one per device)1243* @hdev: pointer to the device structure1244* @kernel_address: holds the queue's kernel virtual address1245* @bus_address: holds the queue's DMA address1246* @size: the event queue size1247* @ci: ci inside the queue1248* @prev_eqe_index: the index of the previous event queue entry. The index of1249* the current entry's index must be +1 of the previous one.1250* @check_eqe_index: do we need to check the index of the current entry vs. the1251* previous one. This is for backward compatibility with older1252* firmwares1253*/1254struct hl_eq {1255struct hl_device *hdev;1256void *kernel_address;1257dma_addr_t bus_address;1258u32 size;1259u32 ci;1260u32 prev_eqe_index;1261bool check_eqe_index;1262};12631264/**1265* struct hl_dec - describes a decoder sw instance.1266* @hdev: pointer to the device structure.1267* @abnrm_intr_work: workqueue work item to run when decoder generates an error interrupt.1268* @core_id: ID of the decoder.1269* @base_addr: base address of the decoder.1270*/1271struct hl_dec {1272struct hl_device *hdev;1273struct work_struct abnrm_intr_work;1274u32 core_id;1275u32 base_addr;1276};12771278/**1279* enum hl_asic_type - supported ASIC types.1280* @ASIC_INVALID: Invalid ASIC type.1281* @ASIC_GOYA: Goya device (HL-1000).1282* @ASIC_GAUDI: Gaudi device (HL-2000).1283* @ASIC_GAUDI_SEC: Gaudi secured device (HL-2000).1284* @ASIC_GAUDI2: Gaudi2 device.1285* @ASIC_GAUDI2B: Gaudi2B device.1286* @ASIC_GAUDI2C: Gaudi2C device.1287* @ASIC_GAUDI2D: Gaudi2D device.1288*/1289enum hl_asic_type {1290ASIC_INVALID,12911292ASIC_GOYA,1293ASIC_GAUDI,1294ASIC_GAUDI_SEC,1295ASIC_GAUDI2,1296ASIC_GAUDI2B,1297ASIC_GAUDI2C,1298ASIC_GAUDI2D,1299};13001301struct hl_cs_parser;13021303/**1304* enum hl_pm_mng_profile - power management profile.1305* @PM_AUTO: internal clock is set by the Linux driver.1306* @PM_MANUAL: internal clock is set by the user.1307* @PM_LAST: last power management type.1308*/1309enum hl_pm_mng_profile {1310PM_AUTO = 1,1311PM_MANUAL,1312PM_LAST1313};13141315/**1316* enum hl_pll_frequency - PLL frequency.1317* @PLL_HIGH: high frequency.1318* @PLL_LOW: low frequency.1319* @PLL_LAST: last frequency values that were configured by the user.1320*/1321enum hl_pll_frequency {1322PLL_HIGH = 1,1323PLL_LOW,1324PLL_LAST1325};13261327#define PLL_REF_CLK 5013281329enum div_select_defs {1330DIV_SEL_REF_CLK = 0,1331DIV_SEL_PLL_CLK = 1,1332DIV_SEL_DIVIDED_REF = 2,1333DIV_SEL_DIVIDED_PLL = 3,1334};13351336enum debugfs_access_type {1337DEBUGFS_READ8,1338DEBUGFS_WRITE8,1339DEBUGFS_READ32,1340DEBUGFS_WRITE32,1341DEBUGFS_READ64,1342DEBUGFS_WRITE64,1343};13441345enum pci_region {1346PCI_REGION_CFG,1347PCI_REGION_SRAM,1348PCI_REGION_DRAM,1349PCI_REGION_SP_SRAM,1350PCI_REGION_NUMBER,1351};13521353/**1354* struct pci_mem_region - describe memory region in a PCI bar1355* @region_base: region base address1356* @region_size: region size1357* @bar_size: size of the BAR1358* @offset_in_bar: region offset into the bar1359* @bar_id: bar ID of the region1360* @used: if used 1, otherwise 01361*/1362struct pci_mem_region {1363u64 region_base;1364u64 region_size;1365u64 bar_size;1366u64 offset_in_bar;1367u8 bar_id;1368u8 used;1369};13701371/**1372* struct static_fw_load_mgr - static FW load manager1373* @preboot_version_max_off: max offset to preboot version1374* @boot_fit_version_max_off: max offset to boot fit version1375* @kmd_msg_to_cpu_reg: register address for KDM->CPU messages1376* @cpu_cmd_status_to_host_reg: register address for CPU command status response1377* @cpu_boot_status_reg: boot status register1378* @cpu_boot_dev_status0_reg: boot device status register 01379* @cpu_boot_dev_status1_reg: boot device status register 11380* @boot_err0_reg: boot error register 01381* @boot_err1_reg: boot error register 11382* @preboot_version_offset_reg: SRAM offset to preboot version register1383* @boot_fit_version_offset_reg: SRAM offset to boot fit version register1384* @sram_offset_mask: mask for getting offset into the SRAM1385* @cpu_reset_wait_msec: used when setting WFE via kmd_msg_to_cpu_reg1386*/1387struct static_fw_load_mgr {1388u64 preboot_version_max_off;1389u64 boot_fit_version_max_off;1390u32 kmd_msg_to_cpu_reg;1391u32 cpu_cmd_status_to_host_reg;1392u32 cpu_boot_status_reg;1393u32 cpu_boot_dev_status0_reg;1394u32 cpu_boot_dev_status1_reg;1395u32 boot_err0_reg;1396u32 boot_err1_reg;1397u32 preboot_version_offset_reg;1398u32 boot_fit_version_offset_reg;1399u32 sram_offset_mask;1400u32 cpu_reset_wait_msec;1401};14021403/**1404* struct fw_response - FW response to LKD command1405* @ram_offset: descriptor offset into the RAM1406* @ram_type: RAM type containing the descriptor (SRAM/DRAM)1407* @status: command status1408*/1409struct fw_response {1410u32 ram_offset;1411u8 ram_type;1412u8 status;1413};14141415/**1416* struct dynamic_fw_load_mgr - dynamic FW load manager1417* @response: FW to LKD response1418* @comm_desc: the communication descriptor with FW1419* @image_region: region to copy the FW image to1420* @fw_image_size: size of FW image to load1421* @wait_for_bl_timeout: timeout for waiting for boot loader to respond1422* @fw_desc_valid: true if FW descriptor has been validated and hence the data can be used1423*/1424struct dynamic_fw_load_mgr {1425struct fw_response response;1426struct lkd_fw_comms_desc comm_desc;1427struct pci_mem_region *image_region;1428size_t fw_image_size;1429u32 wait_for_bl_timeout;1430bool fw_desc_valid;1431};14321433/**1434* struct pre_fw_load_props - needed properties for pre-FW load1435* @cpu_boot_status_reg: cpu_boot_status register address1436* @sts_boot_dev_sts0_reg: sts_boot_dev_sts0 register address1437* @sts_boot_dev_sts1_reg: sts_boot_dev_sts1 register address1438* @boot_err0_reg: boot_err0 register address1439* @boot_err1_reg: boot_err1 register address1440* @wait_for_preboot_timeout: timeout to poll for preboot ready1441* @wait_for_preboot_extended_timeout: timeout to pull for preboot ready in case where we know1442* preboot needs longer time.1443*/1444struct pre_fw_load_props {1445u32 cpu_boot_status_reg;1446u32 sts_boot_dev_sts0_reg;1447u32 sts_boot_dev_sts1_reg;1448u32 boot_err0_reg;1449u32 boot_err1_reg;1450u32 wait_for_preboot_timeout;1451u32 wait_for_preboot_extended_timeout;1452};14531454/**1455* struct fw_image_props - properties of FW image1456* @image_name: name of the image1457* @src_off: offset in src FW to copy from1458* @copy_size: amount of bytes to copy (0 to copy the whole binary)1459*/1460struct fw_image_props {1461char *image_name;1462u32 src_off;1463u32 copy_size;1464};14651466/**1467* struct fw_load_mgr - manager FW loading process1468* @dynamic_loader: specific structure for dynamic load1469* @static_loader: specific structure for static load1470* @pre_fw_load_props: parameter for pre FW load1471* @boot_fit_img: boot fit image properties1472* @linux_img: linux image properties1473* @cpu_timeout: CPU response timeout in usec1474* @boot_fit_timeout: Boot fit load timeout in usec1475* @skip_bmc: should BMC be skipped1476* @sram_bar_id: SRAM bar ID1477* @dram_bar_id: DRAM bar ID1478* @fw_comp_loaded: bitmask of loaded FW components. set bit meaning loaded1479* component. values are set according to enum hl_fw_types.1480*/1481struct fw_load_mgr {1482union {1483struct dynamic_fw_load_mgr dynamic_loader;1484struct static_fw_load_mgr static_loader;1485};1486struct pre_fw_load_props pre_fw_load;1487struct fw_image_props boot_fit_img;1488struct fw_image_props linux_img;1489u32 cpu_timeout;1490u32 boot_fit_timeout;1491u8 skip_bmc;1492u8 sram_bar_id;1493u8 dram_bar_id;1494u8 fw_comp_loaded;1495};14961497struct hl_cs;14981499/**1500* struct engines_data - asic engines data1501* @buf: buffer for engines data in ascii1502* @actual_size: actual size of data that was written by the driver to the allocated buffer1503* @allocated_buf_size: total size of allocated buffer1504*/1505struct engines_data {1506char *buf;1507int actual_size;1508u32 allocated_buf_size;1509};15101511/**1512* struct hl_asic_funcs - ASIC specific functions that are can be called from1513* common code.1514* @early_init: sets up early driver state (pre sw_init), doesn't configure H/W.1515* @early_fini: tears down what was done in early_init.1516* @late_init: sets up late driver/hw state (post hw_init) - Optional.1517* @late_fini: tears down what was done in late_init (pre hw_fini) - Optional.1518* @sw_init: sets up driver state, does not configure H/W.1519* @sw_fini: tears down driver state, does not configure H/W.1520* @hw_init: sets up the H/W state.1521* @hw_fini: tears down the H/W state.1522* @halt_engines: halt engines, needed for reset sequence. This also disables1523* interrupts from the device. Should be called before1524* hw_fini and before CS rollback.1525* @suspend: handles IP specific H/W or SW changes for suspend.1526* @resume: handles IP specific H/W or SW changes for resume.1527* @mmap: maps a memory.1528* @ring_doorbell: increment PI on a given QMAN.1529* @pqe_write: Write the PQ entry to the PQ. This is ASIC-specific1530* function because the PQs are located in different memory areas1531* per ASIC (SRAM, DRAM, Host memory) and therefore, the method of1532* writing the PQE must match the destination memory area1533* properties.1534* @asic_dma_alloc_coherent: Allocate coherent DMA memory by calling1535* dma_alloc_coherent(). This is ASIC function because1536* its implementation is not trivial when the driver1537* is loaded in simulation mode (not upstreamed).1538* @asic_dma_free_coherent: Free coherent DMA memory by calling1539* dma_free_coherent(). This is ASIC function because1540* its implementation is not trivial when the driver1541* is loaded in simulation mode (not upstreamed).1542* @scrub_device_mem: Scrub the entire SRAM and DRAM.1543* @scrub_device_dram: Scrub the dram memory of the device.1544* @get_int_queue_base: get the internal queue base address.1545* @test_queues: run simple test on all queues for sanity check.1546* @asic_dma_pool_zalloc: small DMA allocation of coherent memory from DMA pool.1547* size of allocation is HL_DMA_POOL_BLK_SIZE.1548* @asic_dma_pool_free: free small DMA allocation from pool.1549* @cpu_accessible_dma_pool_alloc: allocate CPU PQ packet from DMA pool.1550* @cpu_accessible_dma_pool_free: free CPU PQ packet from DMA pool.1551* @dma_unmap_sgtable: DMA unmap scatter-gather table.1552* @dma_map_sgtable: DMA map scatter-gather table.1553* @cs_parser: parse Command Submission.1554* @add_end_of_cb_packets: Add packets to the end of CB, if device requires it.1555* @update_eq_ci: update event queue CI.1556* @context_switch: called upon ASID context switch.1557* @restore_phase_topology: clear all SOBs amd MONs.1558* @debugfs_read_dma: debug interface for reading up to 2MB from the device's1559* internal memory via DMA engine.1560* @add_device_attr: add ASIC specific device attributes.1561* @handle_eqe: handle event queue entry (IRQ) from CPU-CP.1562* @get_events_stat: retrieve event queue entries histogram.1563* @read_pte: read MMU page table entry from DRAM.1564* @write_pte: write MMU page table entry to DRAM.1565* @mmu_invalidate_cache: flush MMU STLB host/DRAM cache, either with soft1566* (L1 only) or hard (L0 & L1) flush.1567* @mmu_invalidate_cache_range: flush specific MMU STLB cache lines with ASID-VA-size mask.1568* @mmu_prefetch_cache_range: pre-fetch specific MMU STLB cache lines with ASID-VA-size mask.1569* @send_heartbeat: send is-alive packet to CPU-CP and verify response.1570* @debug_coresight: perform certain actions on Coresight for debugging.1571* @is_device_idle: return true if device is idle, false otherwise.1572* @compute_reset_late_init: perform certain actions needed after a compute reset1573* @hw_queues_lock: acquire H/W queues lock.1574* @hw_queues_unlock: release H/W queues lock.1575* @get_pci_id: retrieve PCI ID.1576* @get_eeprom_data: retrieve EEPROM data from F/W.1577* @get_monitor_dump: retrieve monitor registers dump from F/W.1578* @send_cpu_message: send message to F/W. If the message is timedout, the1579* driver will eventually reset the device. The timeout can1580* be determined by the calling function or it can be 0 and1581* then the timeout is the default timeout for the specific1582* ASIC1583* @get_hw_state: retrieve the H/W state1584* @pci_bars_map: Map PCI BARs.1585* @init_iatu: Initialize the iATU unit inside the PCI controller.1586* @rreg: Read a register. Needed for simulator support.1587* @wreg: Write a register. Needed for simulator support.1588* @halt_coresight: stop the ETF and ETR traces.1589* @ctx_init: context dependent initialization.1590* @ctx_fini: context dependent cleanup.1591* @pre_schedule_cs: Perform pre-CS-scheduling operations.1592* @get_queue_id_for_cq: Get the H/W queue id related to the given CQ index.1593* @load_firmware_to_device: load the firmware to the device's memory1594* @load_boot_fit_to_device: load boot fit to device's memory1595* @get_signal_cb_size: Get signal CB size.1596* @get_wait_cb_size: Get wait CB size.1597* @gen_signal_cb: Generate a signal CB.1598* @gen_wait_cb: Generate a wait CB.1599* @reset_sob: Reset a SOB.1600* @reset_sob_group: Reset SOB group1601* @get_device_time: Get the device time.1602* @pb_print_security_errors: print security errors according block and cause1603* @collective_wait_init_cs: Generate collective master/slave packets1604* and place them in the relevant cs jobs1605* @collective_wait_create_jobs: allocate collective wait cs jobs1606* @get_dec_base_addr: get the base address of a given decoder.1607* @scramble_addr: Routine to scramble the address prior of mapping it1608* in the MMU.1609* @descramble_addr: Routine to de-scramble the address prior of1610* showing it to users.1611* @ack_protection_bits_errors: ack and dump all security violations1612* @get_hw_block_id: retrieve a HW block id to be used by the user to mmap it.1613* also returns the size of the block if caller supplies1614* a valid pointer for it1615* @hw_block_mmap: mmap a HW block with a given id.1616* @enable_events_from_fw: send interrupt to firmware to notify them the1617* driver is ready to receive asynchronous events. This1618* function should be called during the first init and1619* after every hard-reset of the device1620* @ack_mmu_errors: check and ack mmu errors, page fault, access violation.1621* @get_msi_info: Retrieve asic-specific MSI ID of the f/w async event1622* @map_pll_idx_to_fw_idx: convert driver specific per asic PLL index to1623* generic f/w compatible PLL Indexes1624* @init_firmware_preload_params: initialize pre FW-load parameters.1625* @init_firmware_loader: initialize data for FW loader.1626* @init_cpu_scrambler_dram: Enable CPU specific DRAM scrambling1627* @state_dump_init: initialize constants required for state dump1628* @get_sob_addr: get SOB base address offset.1629* @set_pci_memory_regions: setting properties of PCI memory regions1630* @get_stream_master_qid_arr: get pointer to stream masters QID array1631* @check_if_razwi_happened: check if there was a razwi due to RR violation.1632* @access_dev_mem: access device memory1633* @set_dram_bar_base: set the base of the DRAM BAR1634* @set_engine_cores: set a config command to engine cores1635* @set_engines: set a config command to user engines1636* @send_device_activity: indication to FW about device availability1637* @set_dram_properties: set DRAM related properties.1638* @set_binning_masks: set binning/enable masks for all relevant components.1639*/1640struct hl_asic_funcs {1641int (*early_init)(struct hl_device *hdev);1642int (*early_fini)(struct hl_device *hdev);1643int (*late_init)(struct hl_device *hdev);1644void (*late_fini)(struct hl_device *hdev);1645int (*sw_init)(struct hl_device *hdev);1646int (*sw_fini)(struct hl_device *hdev);1647int (*hw_init)(struct hl_device *hdev);1648int (*hw_fini)(struct hl_device *hdev, bool hard_reset, bool fw_reset);1649void (*halt_engines)(struct hl_device *hdev, bool hard_reset, bool fw_reset);1650int (*suspend)(struct hl_device *hdev);1651int (*resume)(struct hl_device *hdev);1652int (*mmap)(struct hl_device *hdev, struct vm_area_struct *vma,1653void *cpu_addr, dma_addr_t dma_addr, size_t size);1654void (*ring_doorbell)(struct hl_device *hdev, u32 hw_queue_id, u32 pi);1655void (*pqe_write)(struct hl_device *hdev, __le64 *pqe,1656struct hl_bd *bd);1657void* (*asic_dma_alloc_coherent)(struct hl_device *hdev, size_t size,1658dma_addr_t *dma_handle, gfp_t flag);1659void (*asic_dma_free_coherent)(struct hl_device *hdev, size_t size,1660void *cpu_addr, dma_addr_t dma_handle);1661int (*scrub_device_mem)(struct hl_device *hdev);1662int (*scrub_device_dram)(struct hl_device *hdev, u64 val);1663void* (*get_int_queue_base)(struct hl_device *hdev, u32 queue_id,1664dma_addr_t *dma_handle, u16 *queue_len);1665int (*test_queues)(struct hl_device *hdev);1666void* (*asic_dma_pool_zalloc)(struct hl_device *hdev, size_t size,1667gfp_t mem_flags, dma_addr_t *dma_handle);1668void (*asic_dma_pool_free)(struct hl_device *hdev, void *vaddr,1669dma_addr_t dma_addr);1670void* (*cpu_accessible_dma_pool_alloc)(struct hl_device *hdev,1671size_t size, dma_addr_t *dma_handle);1672void (*cpu_accessible_dma_pool_free)(struct hl_device *hdev,1673size_t size, void *vaddr);1674void (*dma_unmap_sgtable)(struct hl_device *hdev, struct sg_table *sgt,1675enum dma_data_direction dir);1676int (*dma_map_sgtable)(struct hl_device *hdev, struct sg_table *sgt,1677enum dma_data_direction dir);1678int (*cs_parser)(struct hl_device *hdev, struct hl_cs_parser *parser);1679void (*add_end_of_cb_packets)(struct hl_device *hdev,1680void *kernel_address, u32 len,1681u32 original_len,1682u64 cq_addr, u32 cq_val, u32 msix_num,1683bool eb);1684void (*update_eq_ci)(struct hl_device *hdev, u32 val);1685int (*context_switch)(struct hl_device *hdev, u32 asid);1686void (*restore_phase_topology)(struct hl_device *hdev);1687int (*debugfs_read_dma)(struct hl_device *hdev, u64 addr, u32 size,1688void *blob_addr);1689void (*add_device_attr)(struct hl_device *hdev, struct attribute_group *dev_clk_attr_grp,1690struct attribute_group *dev_vrm_attr_grp);1691void (*handle_eqe)(struct hl_device *hdev,1692struct hl_eq_entry *eq_entry);1693void* (*get_events_stat)(struct hl_device *hdev, bool aggregate,1694u32 *size);1695u64 (*read_pte)(struct hl_device *hdev, u64 addr);1696void (*write_pte)(struct hl_device *hdev, u64 addr, u64 val);1697int (*mmu_invalidate_cache)(struct hl_device *hdev, bool is_hard,1698u32 flags);1699int (*mmu_invalidate_cache_range)(struct hl_device *hdev, bool is_hard,1700u32 flags, u32 asid, u64 va, u64 size);1701int (*mmu_prefetch_cache_range)(struct hl_ctx *ctx, u32 flags, u32 asid, u64 va, u64 size);1702int (*send_heartbeat)(struct hl_device *hdev);1703int (*debug_coresight)(struct hl_device *hdev, struct hl_ctx *ctx, void *data);1704bool (*is_device_idle)(struct hl_device *hdev, u64 *mask_arr, u8 mask_len,1705struct engines_data *e);1706int (*compute_reset_late_init)(struct hl_device *hdev);1707void (*hw_queues_lock)(struct hl_device *hdev);1708void (*hw_queues_unlock)(struct hl_device *hdev);1709u32 (*get_pci_id)(struct hl_device *hdev);1710int (*get_eeprom_data)(struct hl_device *hdev, void *data, size_t max_size);1711int (*get_monitor_dump)(struct hl_device *hdev, void *data);1712int (*send_cpu_message)(struct hl_device *hdev, u32 *msg,1713u16 len, u32 timeout, u64 *result);1714int (*pci_bars_map)(struct hl_device *hdev);1715int (*init_iatu)(struct hl_device *hdev);1716u32 (*rreg)(struct hl_device *hdev, u32 reg);1717void (*wreg)(struct hl_device *hdev, u32 reg, u32 val);1718void (*halt_coresight)(struct hl_device *hdev, struct hl_ctx *ctx);1719int (*ctx_init)(struct hl_ctx *ctx);1720void (*ctx_fini)(struct hl_ctx *ctx);1721int (*pre_schedule_cs)(struct hl_cs *cs);1722u32 (*get_queue_id_for_cq)(struct hl_device *hdev, u32 cq_idx);1723int (*load_firmware_to_device)(struct hl_device *hdev);1724int (*load_boot_fit_to_device)(struct hl_device *hdev);1725u32 (*get_signal_cb_size)(struct hl_device *hdev);1726u32 (*get_wait_cb_size)(struct hl_device *hdev);1727u32 (*gen_signal_cb)(struct hl_device *hdev, void *data, u16 sob_id,1728u32 size, bool eb);1729u32 (*gen_wait_cb)(struct hl_device *hdev,1730struct hl_gen_wait_properties *prop);1731void (*reset_sob)(struct hl_device *hdev, void *data);1732void (*reset_sob_group)(struct hl_device *hdev, u16 sob_group);1733u64 (*get_device_time)(struct hl_device *hdev);1734void (*pb_print_security_errors)(struct hl_device *hdev,1735u32 block_addr, u32 cause, u32 offended_addr);1736int (*collective_wait_init_cs)(struct hl_cs *cs);1737int (*collective_wait_create_jobs)(struct hl_device *hdev,1738struct hl_ctx *ctx, struct hl_cs *cs,1739u32 wait_queue_id, u32 collective_engine_id,1740u32 encaps_signal_offset);1741u32 (*get_dec_base_addr)(struct hl_device *hdev, u32 core_id);1742u64 (*scramble_addr)(struct hl_device *hdev, u64 addr);1743u64 (*descramble_addr)(struct hl_device *hdev, u64 addr);1744void (*ack_protection_bits_errors)(struct hl_device *hdev);1745int (*get_hw_block_id)(struct hl_device *hdev, u64 block_addr,1746u32 *block_size, u32 *block_id);1747int (*hw_block_mmap)(struct hl_device *hdev, struct vm_area_struct *vma,1748u32 block_id, u32 block_size);1749void (*enable_events_from_fw)(struct hl_device *hdev);1750int (*ack_mmu_errors)(struct hl_device *hdev, u64 mmu_cap_mask);1751void (*get_msi_info)(__le32 *table);1752int (*map_pll_idx_to_fw_idx)(u32 pll_idx);1753void (*init_firmware_preload_params)(struct hl_device *hdev);1754void (*init_firmware_loader)(struct hl_device *hdev);1755void (*init_cpu_scrambler_dram)(struct hl_device *hdev);1756void (*state_dump_init)(struct hl_device *hdev);1757u32 (*get_sob_addr)(struct hl_device *hdev, u32 sob_id);1758void (*set_pci_memory_regions)(struct hl_device *hdev);1759u32* (*get_stream_master_qid_arr)(void);1760void (*check_if_razwi_happened)(struct hl_device *hdev);1761int (*mmu_get_real_page_size)(struct hl_device *hdev, struct hl_mmu_properties *mmu_prop,1762u32 page_size, u32 *real_page_size, bool is_dram_addr);1763int (*access_dev_mem)(struct hl_device *hdev, enum pci_region region_type,1764u64 addr, u64 *val, enum debugfs_access_type acc_type);1765u64 (*set_dram_bar_base)(struct hl_device *hdev, u64 addr);1766int (*set_engine_cores)(struct hl_device *hdev, u32 *core_ids,1767u32 num_cores, u32 core_command);1768int (*set_engines)(struct hl_device *hdev, u32 *engine_ids,1769u32 num_engines, u32 engine_command);1770int (*send_device_activity)(struct hl_device *hdev, bool open);1771int (*set_dram_properties)(struct hl_device *hdev);1772int (*set_binning_masks)(struct hl_device *hdev);1773};177417751776/*1777* CONTEXTS1778*/17791780#define HL_KERNEL_ASID_ID 017811782/**1783* enum hl_va_range_type - virtual address range type.1784* @HL_VA_RANGE_TYPE_HOST: range type of host pages1785* @HL_VA_RANGE_TYPE_HOST_HUGE: range type of host huge pages1786* @HL_VA_RANGE_TYPE_DRAM: range type of dram pages1787*/1788enum hl_va_range_type {1789HL_VA_RANGE_TYPE_HOST,1790HL_VA_RANGE_TYPE_HOST_HUGE,1791HL_VA_RANGE_TYPE_DRAM,1792HL_VA_RANGE_TYPE_MAX1793};17941795/**1796* struct hl_va_range - virtual addresses range.1797* @lock: protects the virtual addresses list.1798* @list: list of virtual addresses blocks available for mappings.1799* @start_addr: range start address.1800* @end_addr: range end address.1801* @page_size: page size of this va range.1802*/1803struct hl_va_range {1804struct mutex lock;1805struct list_head list;1806u64 start_addr;1807u64 end_addr;1808u32 page_size;1809};18101811/**1812* struct hl_cs_counters_atomic - command submission counters1813* @out_of_mem_drop_cnt: dropped due to memory allocation issue1814* @parsing_drop_cnt: dropped due to error in packet parsing1815* @queue_full_drop_cnt: dropped due to queue full1816* @device_in_reset_drop_cnt: dropped due to device in reset1817* @max_cs_in_flight_drop_cnt: dropped due to maximum CS in-flight1818* @validation_drop_cnt: dropped due to error in validation1819*/1820struct hl_cs_counters_atomic {1821atomic64_t out_of_mem_drop_cnt;1822atomic64_t parsing_drop_cnt;1823atomic64_t queue_full_drop_cnt;1824atomic64_t device_in_reset_drop_cnt;1825atomic64_t max_cs_in_flight_drop_cnt;1826atomic64_t validation_drop_cnt;1827};18281829/**1830* struct hl_dmabuf_priv - a dma-buf private object.1831* @dmabuf: pointer to dma-buf object.1832* @ctx: pointer to the dma-buf owner's context.1833* @phys_pg_pack: pointer to physical page pack if the dma-buf was exported1834* where virtual memory is supported.1835* @memhash_hnode: pointer to the memhash node. this object holds the export count.1836* @offset: the offset into the buffer from which the memory is exported.1837* Relevant only if virtual memory is supported and phys_pg_pack is being used.1838* device_phys_addr: physical address of the device's memory. Relevant only1839* if phys_pg_pack is NULL (dma-buf was exported from address).1840* The total size can be taken from the dmabuf object.1841*/1842struct hl_dmabuf_priv {1843struct dma_buf *dmabuf;1844struct hl_ctx *ctx;1845struct hl_vm_phys_pg_pack *phys_pg_pack;1846struct hl_vm_hash_node *memhash_hnode;1847u64 offset;1848u64 device_phys_addr;1849};18501851#define HL_CS_OUTCOME_HISTORY_LEN 25618521853/**1854* struct hl_cs_outcome - represents a single completed CS outcome1855* @list_link: link to either container's used list or free list1856* @map_link: list to the container hash map1857* @ts: completion ts1858* @seq: the original cs sequence1859* @error: error code cs completed with, if any1860*/1861struct hl_cs_outcome {1862struct list_head list_link;1863struct hlist_node map_link;1864ktime_t ts;1865u64 seq;1866int error;1867};18681869/**1870* struct hl_cs_outcome_store - represents a limited store of completed CS outcomes1871* @outcome_map: index of completed CS searchable by sequence number1872* @used_list: list of outcome objects currently in use1873* @free_list: list of outcome objects currently not in use1874* @nodes_pool: a static pool of pre-allocated outcome objects1875* @db_lock: any operation on the store must take this lock1876*/1877struct hl_cs_outcome_store {1878DECLARE_HASHTABLE(outcome_map, 8);1879struct list_head used_list;1880struct list_head free_list;1881struct hl_cs_outcome nodes_pool[HL_CS_OUTCOME_HISTORY_LEN];1882spinlock_t db_lock;1883};18841885/**1886* struct hl_ctx - user/kernel context.1887* @mem_hash: holds mapping from virtual address to virtual memory area1888* descriptor (hl_vm_phys_pg_list or hl_userptr).1889* @mmu_shadow_hash: holds a mapping from shadow address to pgt_info structure.1890* @hr_mmu_phys_hash: if host-resident MMU is used, holds a mapping from1891* MMU-hop-page physical address to its host-resident1892* pgt_info structure.1893* @hpriv: pointer to the private (Kernel Driver) data of the process (fd).1894* @hdev: pointer to the device structure.1895* @refcount: reference counter for the context. Context is released only when1896* this hits 0. It is incremented on CS and CS_WAIT.1897* @cs_pending: array of hl fence objects representing pending CS.1898* @outcome_store: storage data structure used to remember outcomes of completed1899* command submissions for a long time after CS id wraparound.1900* @va_range: holds available virtual addresses for host and dram mappings.1901* @mem_hash_lock: protects the mem_hash.1902* @hw_block_list_lock: protects the HW block memory list.1903* @ts_reg_lock: timestamp registration ioctls lock.1904* @debugfs_list: node in debugfs list of contexts.1905* @hw_block_mem_list: list of HW block virtual mapped addresses.1906* @cs_counters: context command submission counters.1907* @cb_va_pool: device VA pool for command buffers which are mapped to the1908* device's MMU.1909* @sig_mgr: encaps signals handle manager.1910* @cb_va_pool_base: the base address for the device VA pool1911* @cs_sequence: sequence number for CS. Value is assigned to a CS and passed1912* to user so user could inquire about CS. It is used as1913* index to cs_pending array.1914* @dram_default_hops: array that holds all hops addresses needed for default1915* DRAM mapping.1916* @cs_lock: spinlock to protect cs_sequence.1917* @dram_phys_mem: amount of used physical DRAM memory by this context.1918* @thread_ctx_switch_token: token to prevent multiple threads of the same1919* context from running the context switch phase.1920* Only a single thread should run it.1921* @thread_ctx_switch_wait_token: token to prevent the threads that didn't run1922* the context switch phase from moving to their1923* execution phase before the context switch phase1924* has finished.1925* @asid: context's unique address space ID in the device's MMU.1926* @handle: context's opaque handle for user1927*/1928struct hl_ctx {1929DECLARE_HASHTABLE(mem_hash, MEM_HASH_TABLE_BITS);1930DECLARE_HASHTABLE(mmu_shadow_hash, MMU_HASH_TABLE_BITS);1931DECLARE_HASHTABLE(hr_mmu_phys_hash, MMU_HASH_TABLE_BITS);1932struct hl_fpriv *hpriv;1933struct hl_device *hdev;1934struct kref refcount;1935struct hl_fence **cs_pending;1936struct hl_cs_outcome_store outcome_store;1937struct hl_va_range *va_range[HL_VA_RANGE_TYPE_MAX];1938struct mutex mem_hash_lock;1939struct mutex hw_block_list_lock;1940struct mutex ts_reg_lock;1941struct list_head debugfs_list;1942struct list_head hw_block_mem_list;1943struct hl_cs_counters_atomic cs_counters;1944struct gen_pool *cb_va_pool;1945struct hl_encaps_signals_mgr sig_mgr;1946u64 cb_va_pool_base;1947u64 cs_sequence;1948u64 *dram_default_hops;1949spinlock_t cs_lock;1950atomic64_t dram_phys_mem;1951atomic_t thread_ctx_switch_token;1952u32 thread_ctx_switch_wait_token;1953u32 asid;1954u32 handle;1955};19561957/**1958* struct hl_ctx_mgr - for handling multiple contexts.1959* @lock: protects ctx_handles.1960* @handles: idr to hold all ctx handles.1961*/1962struct hl_ctx_mgr {1963struct mutex lock;1964struct idr handles;1965};196619671968/*1969* COMMAND SUBMISSIONS1970*/19711972/**1973* struct hl_userptr - memory mapping chunk information1974* @vm_type: type of the VM.1975* @job_node: linked-list node for hanging the object on the Job's list.1976* @pages: pointer to struct page array1977* @npages: size of @pages array1978* @sgt: pointer to the scatter-gather table that holds the pages.1979* @dir: for DMA unmapping, the direction must be supplied, so save it.1980* @debugfs_list: node in debugfs list of command submissions.1981* @pid: the pid of the user process owning the memory1982* @addr: user-space virtual address of the start of the memory area.1983* @size: size of the memory area to pin & map.1984* @dma_mapped: true if the SG was mapped to DMA addresses, false otherwise.1985*/1986struct hl_userptr {1987enum vm_type vm_type; /* must be first */1988struct list_head job_node;1989struct page **pages;1990unsigned int npages;1991struct sg_table *sgt;1992enum dma_data_direction dir;1993struct list_head debugfs_list;1994pid_t pid;1995u64 addr;1996u64 size;1997u8 dma_mapped;1998};19992000/**2001* struct hl_cs - command submission.2002* @jobs_in_queue_cnt: per each queue, maintain counter of submitted jobs.2003* @ctx: the context this CS belongs to.2004* @job_list: list of the CS's jobs in the various queues.2005* @job_lock: spinlock for the CS's jobs list. Needed for free_job.2006* @refcount: reference counter for usage of the CS.2007* @fence: pointer to the fence object of this CS.2008* @signal_fence: pointer to the fence object of the signal CS (used by wait2009* CS only).2010* @finish_work: workqueue object to run when CS is completed by H/W.2011* @work_tdr: delayed work node for TDR.2012* @mirror_node : node in device mirror list of command submissions.2013* @staged_cs_node: node in the staged cs list.2014* @debugfs_list: node in debugfs list of command submissions.2015* @encaps_sig_hdl: holds the encaps signals handle.2016* @sequence: the sequence number of this CS.2017* @staged_sequence: the sequence of the staged submission this CS is part of,2018* relevant only if staged_cs is set.2019* @timeout_jiffies: cs timeout in jiffies.2020* @submission_time_jiffies: submission time of the cs2021* @type: CS_TYPE_*.2022* @jobs_cnt: counter of submitted jobs on all queues.2023* @encaps_sig_hdl_id: encaps signals handle id, set for the first staged cs.2024* @completion_timestamp: timestamp of the last completed cs job.2025* @sob_addr_offset: sob offset from the configuration base address.2026* @initial_sob_count: count of completed signals in SOB before current submission of signal or2027* cs with encaps signals.2028* @submitted: true if CS was submitted to H/W.2029* @completed: true if CS was completed by device.2030* @timedout : true if CS was timedout.2031* @tdr_active: true if TDR was activated for this CS (to prevent2032* double TDR activation).2033* @aborted: true if CS was aborted due to some device error.2034* @timestamp: true if a timestamp must be captured upon completion.2035* @staged_last: true if this is the last staged CS and needs completion.2036* @staged_first: true if this is the first staged CS and we need to receive2037* timeout for this CS.2038* @staged_cs: true if this CS is part of a staged submission.2039* @skip_reset_on_timeout: true if we shall not reset the device in case2040* timeout occurs (debug scenario).2041* @encaps_signals: true if this CS has encaps reserved signals.2042*/2043struct hl_cs {2044u16 *jobs_in_queue_cnt;2045struct hl_ctx *ctx;2046struct list_head job_list;2047spinlock_t job_lock;2048struct kref refcount;2049struct hl_fence *fence;2050struct hl_fence *signal_fence;2051struct work_struct finish_work;2052struct delayed_work work_tdr;2053struct list_head mirror_node;2054struct list_head staged_cs_node;2055struct list_head debugfs_list;2056struct hl_cs_encaps_sig_handle *encaps_sig_hdl;2057ktime_t completion_timestamp;2058u64 sequence;2059u64 staged_sequence;2060u64 timeout_jiffies;2061u64 submission_time_jiffies;2062enum hl_cs_type type;2063u32 jobs_cnt;2064u32 encaps_sig_hdl_id;2065u32 sob_addr_offset;2066u16 initial_sob_count;2067u8 submitted;2068u8 completed;2069u8 timedout;2070u8 tdr_active;2071u8 aborted;2072u8 timestamp;2073u8 staged_last;2074u8 staged_first;2075u8 staged_cs;2076u8 skip_reset_on_timeout;2077u8 encaps_signals;2078};20792080/**2081* struct hl_cs_job - command submission job.2082* @cs_node: the node to hang on the CS jobs list.2083* @cs: the CS this job belongs to.2084* @user_cb: the CB we got from the user.2085* @patched_cb: in case of patching, this is internal CB which is submitted on2086* the queue instead of the CB we got from the IOCTL.2087* @finish_work: workqueue object to run when job is completed.2088* @userptr_list: linked-list of userptr mappings that belong to this job and2089* wait for completion.2090* @debugfs_list: node in debugfs list of command submission jobs.2091* @refcount: reference counter for usage of the CS job.2092* @queue_type: the type of the H/W queue this job is submitted to.2093* @timestamp: timestamp upon job completion2094* @id: the id of this job inside a CS.2095* @hw_queue_id: the id of the H/W queue this job is submitted to.2096* @user_cb_size: the actual size of the CB we got from the user.2097* @job_cb_size: the actual size of the CB that we put on the queue.2098* @encaps_sig_wait_offset: encapsulated signals offset, which allow user2099* to wait on part of the reserved signals.2100* @is_kernel_allocated_cb: true if the CB handle we got from the user holds a2101* handle to a kernel-allocated CB object, false2102* otherwise (SRAM/DRAM/host address).2103* @contains_dma_pkt: whether the JOB contains at least one DMA packet. This2104* info is needed later, when adding the 2xMSG_PROT at the2105* end of the JOB, to know which barriers to put in the2106* MSG_PROT packets. Relevant only for GAUDI as GOYA doesn't2107* have streams so the engine can't be busy by another2108* stream.2109*/2110struct hl_cs_job {2111struct list_head cs_node;2112struct hl_cs *cs;2113struct hl_cb *user_cb;2114struct hl_cb *patched_cb;2115struct work_struct finish_work;2116struct list_head userptr_list;2117struct list_head debugfs_list;2118struct kref refcount;2119enum hl_queue_type queue_type;2120ktime_t timestamp;2121u32 id;2122u32 hw_queue_id;2123u32 user_cb_size;2124u32 job_cb_size;2125u32 encaps_sig_wait_offset;2126u8 is_kernel_allocated_cb;2127u8 contains_dma_pkt;2128};21292130/**2131* struct hl_cs_parser - command submission parser properties.2132* @user_cb: the CB we got from the user.2133* @patched_cb: in case of patching, this is internal CB which is submitted on2134* the queue instead of the CB we got from the IOCTL.2135* @job_userptr_list: linked-list of userptr mappings that belong to the related2136* job and wait for completion.2137* @cs_sequence: the sequence number of the related CS.2138* @queue_type: the type of the H/W queue this job is submitted to.2139* @ctx_id: the ID of the context the related CS belongs to.2140* @hw_queue_id: the id of the H/W queue this job is submitted to.2141* @user_cb_size: the actual size of the CB we got from the user.2142* @patched_cb_size: the size of the CB after parsing.2143* @job_id: the id of the related job inside the related CS.2144* @is_kernel_allocated_cb: true if the CB handle we got from the user holds a2145* handle to a kernel-allocated CB object, false2146* otherwise (SRAM/DRAM/host address).2147* @contains_dma_pkt: whether the JOB contains at least one DMA packet. This2148* info is needed later, when adding the 2xMSG_PROT at the2149* end of the JOB, to know which barriers to put in the2150* MSG_PROT packets. Relevant only for GAUDI as GOYA doesn't2151* have streams so the engine can't be busy by another2152* stream.2153* @completion: true if we need completion for this CS.2154*/2155struct hl_cs_parser {2156struct hl_cb *user_cb;2157struct hl_cb *patched_cb;2158struct list_head *job_userptr_list;2159u64 cs_sequence;2160enum hl_queue_type queue_type;2161u32 ctx_id;2162u32 hw_queue_id;2163u32 user_cb_size;2164u32 patched_cb_size;2165u8 job_id;2166u8 is_kernel_allocated_cb;2167u8 contains_dma_pkt;2168u8 completion;2169};21702171/*2172* MEMORY STRUCTURE2173*/21742175/**2176* struct hl_vm_hash_node - hash element from virtual address to virtual2177* memory area descriptor (hl_vm_phys_pg_list or2178* hl_userptr).2179* @node: node to hang on the hash table in context object.2180* @vaddr: key virtual address.2181* @handle: memory handle for device memory allocation.2182* @ptr: value pointer (hl_vm_phys_pg_list or hl_userptr).2183* @export_cnt: number of exports from within the VA block.2184*/2185struct hl_vm_hash_node {2186struct hlist_node node;2187u64 vaddr;2188u64 handle;2189void *ptr;2190int export_cnt;2191};21922193/**2194* struct hl_vm_hw_block_list_node - list element from user virtual address to2195* HW block id.2196* @node: node to hang on the list in context object.2197* @ctx: the context this node belongs to.2198* @vaddr: virtual address of the HW block.2199* @block_size: size of the block.2200* @mapped_size: size of the block which is mapped. May change if partial un-mappings are done.2201* @id: HW block id (handle).2202*/2203struct hl_vm_hw_block_list_node {2204struct list_head node;2205struct hl_ctx *ctx;2206unsigned long vaddr;2207u32 block_size;2208u32 mapped_size;2209u32 id;2210};22112212/**2213* struct hl_vm_phys_pg_pack - physical page pack.2214* @vm_type: describes the type of the virtual area descriptor.2215* @pages: the physical page array.2216* @npages: num physical pages in the pack.2217* @total_size: total size of all the pages in this list.2218* @node: used to attach to deletion list that is used when all the allocations are cleared2219* at the teardown of the context.2220* @mapping_cnt: number of shared mappings.2221* @asid: the context related to this list.2222* @page_size: size of each page in the pack.2223* @flags: HL_MEM_* flags related to this list.2224* @handle: the provided handle related to this list.2225* @offset: offset from the first page.2226* @contiguous: is contiguous physical memory.2227* @created_from_userptr: is product of host virtual address.2228*/2229struct hl_vm_phys_pg_pack {2230enum vm_type vm_type; /* must be first */2231u64 *pages;2232u64 npages;2233u64 total_size;2234struct list_head node;2235atomic_t mapping_cnt;2236u32 asid;2237u32 page_size;2238u32 flags;2239u32 handle;2240u32 offset;2241u8 contiguous;2242u8 created_from_userptr;2243};22442245/**2246* struct hl_vm_va_block - virtual range block information.2247* @node: node to hang on the virtual range list in context object.2248* @start: virtual range start address.2249* @end: virtual range end address.2250* @size: virtual range size.2251*/2252struct hl_vm_va_block {2253struct list_head node;2254u64 start;2255u64 end;2256u64 size;2257};22582259/**2260* struct hl_vm - virtual memory manager for MMU.2261* @dram_pg_pool: pool for DRAM physical pages of 2MB.2262* @dram_pg_pool_refcount: reference counter for the pool usage.2263* @idr_lock: protects the phys_pg_list_handles.2264* @phys_pg_pack_handles: idr to hold all device allocations handles.2265* @init_done: whether initialization was done. We need this because VM2266* initialization might be skipped during device initialization.2267*/2268struct hl_vm {2269struct gen_pool *dram_pg_pool;2270struct kref dram_pg_pool_refcount;2271spinlock_t idr_lock;2272struct idr phys_pg_pack_handles;2273u8 init_done;2274};227522762277/*2278* DEBUG, PROFILING STRUCTURE2279*/22802281/**2282* struct hl_debug_params - Coresight debug parameters.2283* @input: pointer to component specific input parameters.2284* @output: pointer to component specific output parameters.2285* @output_size: size of output buffer.2286* @reg_idx: relevant register ID.2287* @op: component operation to execute.2288* @enable: true if to enable component debugging, false otherwise.2289*/2290struct hl_debug_params {2291void *input;2292void *output;2293u32 output_size;2294u32 reg_idx;2295u32 op;2296bool enable;2297};22982299/**2300* struct hl_notifier_event - holds the notifier data structure2301* @eventfd: the event file descriptor to raise the notifications2302* @lock: mutex lock to protect the notifier data flows2303* @events_mask: indicates the bitmap events2304*/2305struct hl_notifier_event {2306struct eventfd_ctx *eventfd;2307struct mutex lock;2308u64 events_mask;2309};23102311/*2312* FILE PRIVATE STRUCTURE2313*/23142315/**2316* struct hl_fpriv - process information stored in FD private data.2317* @hdev: habanalabs device structure.2318* @file_priv: pointer to the DRM file private data structure.2319* @taskpid: current process ID.2320* @ctx: current executing context. TODO: remove for multiple ctx per process2321* @ctx_mgr: context manager to handle multiple context for this FD.2322* @mem_mgr: manager descriptor for memory exportable via mmap2323* @notifier_event: notifier eventfd towards user process2324* @debugfs_list: list of relevant ASIC debugfs.2325* @dev_node: node in the device list of file private data2326* @refcount: number of related contexts.2327* @restore_phase_mutex: lock for context switch and restore phase.2328* @ctx_lock: protects the pointer to current executing context pointer. TODO: remove for multiple2329* ctx per process.2330*/2331struct hl_fpriv {2332struct hl_device *hdev;2333struct drm_file *file_priv;2334struct pid *taskpid;2335struct hl_ctx *ctx;2336struct hl_ctx_mgr ctx_mgr;2337struct hl_mem_mgr mem_mgr;2338struct hl_notifier_event notifier_event;2339struct list_head debugfs_list;2340struct list_head dev_node;2341struct kref refcount;2342struct mutex restore_phase_mutex;2343struct mutex ctx_lock;2344};234523462347/*2348* DebugFS2349*/23502351/**2352* struct hl_info_list - debugfs file ops.2353* @name: file name.2354* @show: function to output information.2355* @write: function to write to the file.2356*/2357struct hl_info_list {2358const char *name;2359int (*show)(struct seq_file *s, void *data);2360ssize_t (*write)(struct file *file, const char __user *buf,2361size_t count, loff_t *f_pos);2362};23632364/**2365* struct hl_debugfs_entry - debugfs dentry wrapper.2366* @info_ent: dentry related ops.2367* @dev_entry: ASIC specific debugfs manager.2368*/2369struct hl_debugfs_entry {2370const struct hl_info_list *info_ent;2371struct hl_dbg_device_entry *dev_entry;2372};23732374/**2375* struct hl_dbg_device_entry - ASIC specific debugfs manager.2376* @root: root dentry.2377* @hdev: habanalabs device structure.2378* @entry_arr: array of available hl_debugfs_entry.2379* @file_list: list of available debugfs files.2380* @file_mutex: protects file_list.2381* @cb_list: list of available CBs.2382* @cb_spinlock: protects cb_list.2383* @cs_list: list of available CSs.2384* @cs_spinlock: protects cs_list.2385* @cs_job_list: list of available CB jobs.2386* @cs_job_spinlock: protects cs_job_list.2387* @userptr_list: list of available userptrs (virtual memory chunk descriptor).2388* @userptr_spinlock: protects userptr_list.2389* @ctx_mem_hash_list: list of available contexts with MMU mappings.2390* @ctx_mem_hash_mutex: protects list of available contexts with MMU mappings.2391* @data_dma_blob_desc: data DMA descriptor of blob.2392* @mon_dump_blob_desc: monitor dump descriptor of blob.2393* @state_dump: data of the system states in case of a bad cs.2394* @state_dump_sem: protects state_dump.2395* @addr: next address to read/write from/to in read/write32.2396* @mmu_addr: next virtual address to translate to physical address in mmu_show.2397* @mmu_cap_mask: mmu hw capability mask, to be used in mmu_ack_error.2398* @userptr_lookup: the target user ptr to look up for on demand.2399* @mmu_asid: ASID to use while translating in mmu_show.2400* @state_dump_head: index of the latest state dump2401* @i2c_bus: generic u8 debugfs file for bus value to use in i2c_data_read.2402* @i2c_addr: generic u8 debugfs file for address value to use in i2c_data_read.2403* @i2c_reg: generic u8 debugfs file for register value to use in i2c_data_read.2404* @i2c_len: generic u8 debugfs file for length value to use in i2c_data_read.2405*/2406struct hl_dbg_device_entry {2407struct dentry *root;2408struct hl_device *hdev;2409struct hl_debugfs_entry *entry_arr;2410struct list_head file_list;2411struct mutex file_mutex;2412struct list_head cb_list;2413spinlock_t cb_spinlock;2414struct list_head cs_list;2415spinlock_t cs_spinlock;2416struct list_head cs_job_list;2417spinlock_t cs_job_spinlock;2418struct list_head userptr_list;2419spinlock_t userptr_spinlock;2420struct list_head ctx_mem_hash_list;2421struct mutex ctx_mem_hash_mutex;2422struct debugfs_blob_wrapper data_dma_blob_desc;2423struct debugfs_blob_wrapper mon_dump_blob_desc;2424char *state_dump[HL_STATE_DUMP_HIST_LEN];2425struct rw_semaphore state_dump_sem;2426u64 addr;2427u64 mmu_addr;2428u64 mmu_cap_mask;2429u64 userptr_lookup;2430u32 mmu_asid;2431u32 state_dump_head;2432u8 i2c_bus;2433u8 i2c_addr;2434u8 i2c_reg;2435u8 i2c_len;2436};24372438/**2439* struct hl_hw_obj_name_entry - single hw object name, member of2440* hl_state_dump_specs2441* @node: link to the containing hash table2442* @name: hw object name2443* @id: object identifier2444*/2445struct hl_hw_obj_name_entry {2446struct hlist_node node;2447const char *name;2448u32 id;2449};24502451enum hl_state_dump_specs_props {2452SP_SYNC_OBJ_BASE_ADDR,2453SP_NEXT_SYNC_OBJ_ADDR,2454SP_SYNC_OBJ_AMOUNT,2455SP_MON_OBJ_WR_ADDR_LOW,2456SP_MON_OBJ_WR_ADDR_HIGH,2457SP_MON_OBJ_WR_DATA,2458SP_MON_OBJ_ARM_DATA,2459SP_MON_OBJ_STATUS,2460SP_MONITORS_AMOUNT,2461SP_TPC0_CMDQ,2462SP_TPC0_CFG_SO,2463SP_NEXT_TPC,2464SP_MME_CMDQ,2465SP_MME_CFG_SO,2466SP_NEXT_MME,2467SP_DMA_CMDQ,2468SP_DMA_CFG_SO,2469SP_DMA_QUEUES_OFFSET,2470SP_NUM_OF_MME_ENGINES,2471SP_SUB_MME_ENG_NUM,2472SP_NUM_OF_DMA_ENGINES,2473SP_NUM_OF_TPC_ENGINES,2474SP_ENGINE_NUM_OF_QUEUES,2475SP_ENGINE_NUM_OF_STREAMS,2476SP_ENGINE_NUM_OF_FENCES,2477SP_FENCE0_CNT_OFFSET,2478SP_FENCE0_RDATA_OFFSET,2479SP_CP_STS_OFFSET,2480SP_NUM_CORES,24812482SP_MAX2483};24842485enum hl_sync_engine_type {2486ENGINE_TPC,2487ENGINE_DMA,2488ENGINE_MME,2489};24902491/**2492* struct hl_mon_state_dump - represents a state dump of a single monitor2493* @id: monitor id2494* @wr_addr_low: address monitor will write to, low bits2495* @wr_addr_high: address monitor will write to, high bits2496* @wr_data: data monitor will write2497* @arm_data: register value containing monitor configuration2498* @status: monitor status2499*/2500struct hl_mon_state_dump {2501u32 id;2502u32 wr_addr_low;2503u32 wr_addr_high;2504u32 wr_data;2505u32 arm_data;2506u32 status;2507};25082509/**2510* struct hl_sync_to_engine_map_entry - sync object id to engine mapping entry2511* @engine_type: type of the engine2512* @engine_id: id of the engine2513* @sync_id: id of the sync object2514*/2515struct hl_sync_to_engine_map_entry {2516struct hlist_node node;2517enum hl_sync_engine_type engine_type;2518u32 engine_id;2519u32 sync_id;2520};25212522/**2523* struct hl_sync_to_engine_map - maps sync object id to associated engine id2524* @tb: hash table containing the mapping, each element is of type2525* struct hl_sync_to_engine_map_entry2526*/2527struct hl_sync_to_engine_map {2528DECLARE_HASHTABLE(tb, SYNC_TO_ENGINE_HASH_TABLE_BITS);2529};25302531/**2532* struct hl_state_dump_specs_funcs - virtual functions used by the state dump2533* @gen_sync_to_engine_map: generate a hash map from sync obj id to its engine2534* @print_single_monitor: format monitor data as string2535* @monitor_valid: return true if given monitor dump is valid2536* @print_fences_single_engine: format fences data as string2537*/2538struct hl_state_dump_specs_funcs {2539int (*gen_sync_to_engine_map)(struct hl_device *hdev,2540struct hl_sync_to_engine_map *map);2541int (*print_single_monitor)(char **buf, size_t *size, size_t *offset,2542struct hl_device *hdev,2543struct hl_mon_state_dump *mon);2544int (*monitor_valid)(struct hl_mon_state_dump *mon);2545int (*print_fences_single_engine)(struct hl_device *hdev,2546u64 base_offset,2547u64 status_base_offset,2548enum hl_sync_engine_type engine_type,2549u32 engine_id, char **buf,2550size_t *size, size_t *offset);2551};25522553/**2554* struct hl_state_dump_specs - defines ASIC known hw objects names2555* @so_id_to_str_tb: sync objects names index table2556* @monitor_id_to_str_tb: monitors names index table2557* @funcs: virtual functions used for state dump2558* @sync_namager_names: readable names for sync manager if available (ex: N_E)2559* @props: pointer to a per asic const props array required for state dump2560*/2561struct hl_state_dump_specs {2562DECLARE_HASHTABLE(so_id_to_str_tb, OBJ_NAMES_HASH_TABLE_BITS);2563DECLARE_HASHTABLE(monitor_id_to_str_tb, OBJ_NAMES_HASH_TABLE_BITS);2564struct hl_state_dump_specs_funcs funcs;2565const char * const *sync_namager_names;2566s64 *props;2567};256825692570/*2571* DEVICES2572*/25732574#define HL_STR_MAX 6425752576#define HL_DEV_STS_MAX (HL_DEVICE_STATUS_LAST + 1)25772578/* Theoretical limit only. A single host can only contain up to 4 or 8 PCIe2579* x16 cards. In extreme cases, there are hosts that can accommodate 16 cards.2580*/2581#define HL_MAX_MINORS 25625822583/*2584* Registers read & write functions.2585*/25862587u32 hl_rreg(struct hl_device *hdev, u32 reg);2588void hl_wreg(struct hl_device *hdev, u32 reg, u32 val);25892590#define RREG32(reg) hdev->asic_funcs->rreg(hdev, (reg))2591#define WREG32(reg, v) hdev->asic_funcs->wreg(hdev, (reg), (v))2592#define DREG32(reg) pr_info("REGISTER: " #reg " : 0x%08X\n", \2593hdev->asic_funcs->rreg(hdev, (reg)))25942595#define WREG32_P(reg, val, mask) \2596do { \2597u32 tmp_ = RREG32(reg); \2598tmp_ &= (mask); \2599tmp_ |= ((val) & ~(mask)); \2600WREG32(reg, tmp_); \2601} while (0)2602#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)2603#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))26042605#define RMWREG32_SHIFTED(reg, val, mask) WREG32_P(reg, val, ~(mask))26062607#define RMWREG32(reg, val, mask) RMWREG32_SHIFTED(reg, (val) << __ffs(mask), mask)26082609#define RREG32_MASK(reg, mask) ((RREG32(reg) & mask) >> __ffs(mask))26102611#define REG_FIELD_SHIFT(reg, field) reg##_##field##_SHIFT2612#define REG_FIELD_MASK(reg, field) reg##_##field##_MASK2613#define WREG32_FIELD(reg, offset, field, val) \2614WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & \2615~REG_FIELD_MASK(reg, field)) | \2616(val) << REG_FIELD_SHIFT(reg, field))26172618/* Timeout should be longer when working with simulator but cap the2619* increased timeout to some maximum2620*/2621#define hl_poll_timeout_common(hdev, addr, val, cond, sleep_us, timeout_us, elbi) \2622({ \2623ktime_t __timeout; \2624u32 __elbi_read; \2625int __rc = 0; \2626__timeout = ktime_add_us(ktime_get(), timeout_us); \2627might_sleep_if(sleep_us); \2628for (;;) { \2629if (elbi) { \2630__rc = hl_pci_elbi_read(hdev, addr, &__elbi_read); \2631if (__rc) \2632break; \2633(val) = __elbi_read; \2634} else {\2635(val) = RREG32(lower_32_bits(addr)); \2636} \2637if (cond) \2638break; \2639if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \2640if (elbi) { \2641__rc = hl_pci_elbi_read(hdev, addr, &__elbi_read); \2642if (__rc) \2643break; \2644(val) = __elbi_read; \2645} else {\2646(val) = RREG32(lower_32_bits(addr)); \2647} \2648break; \2649} \2650if (sleep_us) \2651usleep_range((sleep_us >> 2) + 1, sleep_us); \2652} \2653__rc ? __rc : ((cond) ? 0 : -ETIMEDOUT); \2654})26552656#define hl_poll_timeout(hdev, addr, val, cond, sleep_us, timeout_us) \2657hl_poll_timeout_common(hdev, addr, val, cond, sleep_us, timeout_us, false)26582659#define hl_poll_timeout_elbi(hdev, addr, val, cond, sleep_us, timeout_us) \2660hl_poll_timeout_common(hdev, addr, val, cond, sleep_us, timeout_us, true)26612662/*2663* poll array of register addresses.2664* condition is satisfied if all registers values match the expected value.2665* once some register in the array satisfies the condition it will not be polled again,2666* this is done both for efficiency and due to some registers are "clear on read".2667* TODO: use read from PCI bar in other places in the code (SW-91406)2668*/2669#define hl_poll_reg_array_timeout_common(hdev, addr_arr, arr_size, expected_val, sleep_us, \2670timeout_us, elbi) \2671({ \2672ktime_t __timeout; \2673u64 __elem_bitmask; \2674u32 __read_val; \2675u8 __arr_idx; \2676int __rc = 0; \2677\2678__timeout = ktime_add_us(ktime_get(), timeout_us); \2679might_sleep_if(sleep_us); \2680if (arr_size >= 64) \2681__rc = -EINVAL; \2682else \2683__elem_bitmask = BIT_ULL(arr_size) - 1; \2684for (;;) { \2685if (__rc) \2686break; \2687for (__arr_idx = 0; __arr_idx < (arr_size); __arr_idx++) { \2688if (!(__elem_bitmask & BIT_ULL(__arr_idx))) \2689continue; \2690if (elbi) { \2691__rc = hl_pci_elbi_read(hdev, (addr_arr)[__arr_idx], &__read_val); \2692if (__rc) \2693break; \2694} else { \2695__read_val = RREG32(lower_32_bits(addr_arr[__arr_idx])); \2696} \2697if (__read_val == (expected_val)) \2698__elem_bitmask &= ~BIT_ULL(__arr_idx); \2699} \2700if (__rc || (__elem_bitmask == 0)) \2701break; \2702if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) \2703break; \2704if (sleep_us) \2705usleep_range((sleep_us >> 2) + 1, sleep_us); \2706} \2707__rc ? __rc : ((__elem_bitmask == 0) ? 0 : -ETIMEDOUT); \2708})27092710#define hl_poll_reg_array_timeout(hdev, addr_arr, arr_size, expected_val, sleep_us, \2711timeout_us) \2712hl_poll_reg_array_timeout_common(hdev, addr_arr, arr_size, expected_val, sleep_us, \2713timeout_us, false)27142715#define hl_poll_reg_array_timeout_elbi(hdev, addr_arr, arr_size, expected_val, sleep_us, \2716timeout_us) \2717hl_poll_reg_array_timeout_common(hdev, addr_arr, arr_size, expected_val, sleep_us, \2718timeout_us, true)27192720/*2721* address in this macro points always to a memory location in the2722* host's (server's) memory. That location is updated asynchronously2723* either by the direct access of the device or by another core.2724*2725* To work both in LE and BE architectures, we need to distinguish between the2726* two states (device or another core updates the memory location). Therefore,2727* if mem_written_by_device is true, the host memory being polled will be2728* updated directly by the device. If false, the host memory being polled will2729* be updated by host CPU. Required so host knows whether or not the memory2730* might need to be byte-swapped before returning value to caller.2731*2732* On the first 4 polling iterations the macro goes to sleep for short period of2733* time that gradually increases and reaches sleep_us on the fifth iteration.2734*/2735#define hl_poll_timeout_memory(hdev, addr, val, cond, sleep_us, timeout_us, \2736mem_written_by_device) \2737({ \2738u64 __sleep_step_us; \2739ktime_t __timeout; \2740u8 __step = 8; \2741\2742__timeout = ktime_add_us(ktime_get(), timeout_us); \2743might_sleep_if(sleep_us); \2744for (;;) { \2745/* Verify we read updates done by other cores or by device */ \2746mb(); \2747(val) = *((u32 *)(addr)); \2748if (mem_written_by_device) \2749(val) = le32_to_cpu(*(__le32 *) &(val)); \2750if (cond) \2751break; \2752if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \2753(val) = *((u32 *)(addr)); \2754if (mem_written_by_device) \2755(val) = le32_to_cpu(*(__le32 *) &(val)); \2756break; \2757} \2758__sleep_step_us = sleep_us >> __step; \2759if (__sleep_step_us) \2760usleep_range((__sleep_step_us >> 2) + 1, __sleep_step_us); \2761__step >>= 1; \2762} \2763(cond) ? 0 : -ETIMEDOUT; \2764})27652766#define HL_USR_MAPPED_BLK_INIT(blk, base, sz) \2767({ \2768struct user_mapped_block *p = blk; \2769\2770p->address = base; \2771p->size = sz; \2772})27732774#define HL_USR_INTR_STRUCT_INIT(usr_intr, hdev, intr_id, intr_type) \2775({ \2776usr_intr.hdev = hdev; \2777usr_intr.interrupt_id = intr_id; \2778usr_intr.type = intr_type; \2779INIT_LIST_HEAD(&usr_intr.wait_list_head); \2780spin_lock_init(&usr_intr.wait_list_lock); \2781INIT_LIST_HEAD(&usr_intr.ts_list_head); \2782spin_lock_init(&usr_intr.ts_list_lock); \2783})27842785struct hwmon_chip_info;27862787/**2788* struct hl_device_reset_work - reset work wrapper.2789* @reset_work: reset work to be done.2790* @hdev: habanalabs device structure.2791* @flags: reset flags.2792*/2793struct hl_device_reset_work {2794struct delayed_work reset_work;2795struct hl_device *hdev;2796u32 flags;2797};27982799/**2800* struct hl_mmu_hr_pgt_priv - used for holding per-device mmu host-resident2801* page-table internal information.2802* @mmu_pgt_pool: pool of page tables used by a host-resident MMU for2803* allocating hops.2804* @mmu_asid_hop0: per-ASID array of host-resident hop0 tables.2805*/2806struct hl_mmu_hr_priv {2807struct gen_pool *mmu_pgt_pool;2808struct pgt_info *mmu_asid_hop0;2809};28102811/**2812* struct hl_mmu_dr_pgt_priv - used for holding per-device mmu device-resident2813* page-table internal information.2814* @mmu_pgt_pool: pool of page tables used by MMU for allocating hops.2815* @mmu_shadow_hop0: shadow array of hop0 tables.2816*/2817struct hl_mmu_dr_priv {2818struct gen_pool *mmu_pgt_pool;2819void *mmu_shadow_hop0;2820};28212822/**2823* struct hl_mmu_priv - used for holding per-device mmu internal information.2824* @dr: information on the device-resident MMU, when exists.2825* @hr: information on the host-resident MMU, when exists.2826*/2827struct hl_mmu_priv {2828struct hl_mmu_dr_priv dr;2829struct hl_mmu_hr_priv hr;2830};28312832/**2833* struct hl_mmu_per_hop_info - A structure describing one TLB HOP and its entry2834* that was created in order to translate a virtual address to a2835* physical one.2836* @hop_addr: The address of the hop.2837* @hop_pte_addr: The address of the hop entry.2838* @hop_pte_val: The value in the hop entry.2839*/2840struct hl_mmu_per_hop_info {2841u64 hop_addr;2842u64 hop_pte_addr;2843u64 hop_pte_val;2844};28452846/**2847* struct hl_mmu_hop_info - A structure describing the TLB hops and their2848* hop-entries that were created in order to translate a virtual address to a2849* physical one.2850* @scrambled_vaddr: The value of the virtual address after scrambling. This2851* address replaces the original virtual-address when mapped2852* in the MMU tables.2853* @unscrambled_paddr: The un-scrambled physical address.2854* @hop_info: Array holding the per-hop information used for the translation.2855* @used_hops: The number of hops used for the translation.2856* @range_type: virtual address range type.2857*/2858struct hl_mmu_hop_info {2859u64 scrambled_vaddr;2860u64 unscrambled_paddr;2861struct hl_mmu_per_hop_info hop_info[MMU_ARCH_6_HOPS];2862u32 used_hops;2863enum hl_va_range_type range_type;2864};28652866/**2867* struct hl_hr_mmu_funcs - Device related host resident MMU functions.2868* @get_hop0_pgt_info: get page table info structure for HOP0.2869* @get_pgt_info: get page table info structure for HOP other than HOP0.2870* @add_pgt_info: add page table info structure to hash.2871* @get_tlb_mapping_params: get mapping parameters needed for getting TLB info for specific mapping.2872*/2873struct hl_hr_mmu_funcs {2874struct pgt_info *(*get_hop0_pgt_info)(struct hl_ctx *ctx);2875struct pgt_info *(*get_pgt_info)(struct hl_ctx *ctx, u64 phys_hop_addr);2876void (*add_pgt_info)(struct hl_ctx *ctx, struct pgt_info *pgt_info, dma_addr_t phys_addr);2877int (*get_tlb_mapping_params)(struct hl_device *hdev, struct hl_mmu_properties **mmu_prop,2878struct hl_mmu_hop_info *hops,2879u64 virt_addr, bool *is_huge);2880};28812882/**2883* struct hl_mmu_funcs - Device related MMU functions.2884* @init: initialize the MMU module.2885* @fini: release the MMU module.2886* @ctx_init: Initialize a context for using the MMU module.2887* @ctx_fini: disable a ctx from using the mmu module.2888* @map: maps a virtual address to physical address for a context.2889* @unmap: unmap a virtual address of a context.2890* @flush: flush all writes from all cores to reach device MMU.2891* @swap_out: marks all mapping of the given context as swapped out.2892* @swap_in: marks all mapping of the given context as swapped in.2893* @get_tlb_info: returns the list of hops and hop-entries used that were2894* created in order to translate the giver virtual address to a2895* physical one.2896* @hr_funcs: functions specific to host resident MMU.2897*/2898struct hl_mmu_funcs {2899int (*init)(struct hl_device *hdev);2900void (*fini)(struct hl_device *hdev);2901int (*ctx_init)(struct hl_ctx *ctx);2902void (*ctx_fini)(struct hl_ctx *ctx);2903int (*map)(struct hl_ctx *ctx, u64 virt_addr, u64 phys_addr, u32 page_size,2904bool is_dram_addr);2905int (*unmap)(struct hl_ctx *ctx, u64 virt_addr, bool is_dram_addr);2906void (*flush)(struct hl_ctx *ctx);2907void (*swap_out)(struct hl_ctx *ctx);2908void (*swap_in)(struct hl_ctx *ctx);2909int (*get_tlb_info)(struct hl_ctx *ctx, u64 virt_addr, struct hl_mmu_hop_info *hops);2910struct hl_hr_mmu_funcs hr_funcs;2911};29122913/**2914* struct hl_prefetch_work - prefetch work structure handler2915* @prefetch_work: actual work struct.2916* @ctx: compute context.2917* @va: virtual address to pre-fetch.2918* @size: pre-fetch size.2919* @flags: operation flags.2920* @asid: ASID for maintenance operation.2921*/2922struct hl_prefetch_work {2923struct work_struct prefetch_work;2924struct hl_ctx *ctx;2925u64 va;2926u64 size;2927u32 flags;2928u32 asid;2929};29302931/*2932* number of user contexts allowed to call wait_for_multi_cs ioctl in2933* parallel2934*/2935#define MULTI_CS_MAX_USER_CTX 229362937/**2938* struct multi_cs_completion - multi CS wait completion.2939* @completion: completion of any of the CS in the list2940* @lock: spinlock for the completion structure2941* @timestamp: timestamp for the multi-CS completion2942* @stream_master_qid_map: bitmap of all stream masters on which the multi-CS2943* is waiting2944* @used: 1 if in use, otherwise 02945*/2946struct multi_cs_completion {2947struct completion completion;2948spinlock_t lock;2949s64 timestamp;2950u32 stream_master_qid_map;2951u8 used;2952};29532954/**2955* struct multi_cs_data - internal data for multi CS call2956* @ctx: pointer to the context structure2957* @fence_arr: array of fences of all CSs2958* @seq_arr: array of CS sequence numbers2959* @timeout_jiffies: timeout in jiffies for waiting for CS to complete2960* @timestamp: timestamp of first completed CS2961* @wait_status: wait for CS status2962* @completion_bitmap: bitmap of completed CSs (1- completed, otherwise 0)2963* @arr_len: fence_arr and seq_arr array length2964* @gone_cs: indication of gone CS (1- there was gone CS, otherwise 0)2965* @update_ts: update timestamp. 1- update the timestamp, otherwise 0.2966*/2967struct multi_cs_data {2968struct hl_ctx *ctx;2969struct hl_fence **fence_arr;2970u64 *seq_arr;2971s64 timeout_jiffies;2972s64 timestamp;2973long wait_status;2974u32 completion_bitmap;2975u8 arr_len;2976u8 gone_cs;2977u8 update_ts;2978};29792980/**2981* struct hl_clk_throttle_timestamp - current/last clock throttling timestamp2982* @start: timestamp taken when 'start' event is received in driver2983* @end: timestamp taken when 'end' event is received in driver2984*/2985struct hl_clk_throttle_timestamp {2986ktime_t start;2987ktime_t end;2988};29892990/**2991* struct hl_clk_throttle - keeps current/last clock throttling timestamps2992* @timestamp: timestamp taken by driver and firmware, index 0 refers to POWER2993* index 1 refers to THERMAL2994* @lock: protects this structure as it can be accessed from both event queue2995* context and info_ioctl context2996* @current_reason: bitmask represents the current clk throttling reasons2997* @aggregated_reason: bitmask represents aggregated clk throttling reasons since driver load2998*/2999struct hl_clk_throttle {3000struct hl_clk_throttle_timestamp timestamp[HL_CLK_THROTTLE_TYPE_MAX];3001struct mutex lock;3002u32 current_reason;3003u32 aggregated_reason;3004};30053006/**3007* struct user_mapped_block - describes a hw block allowed to be mmapped by user3008* @address: physical HW block address3009* @size: allowed size for mmap3010*/3011struct user_mapped_block {3012u32 address;3013u32 size;3014};30153016/**3017* struct cs_timeout_info - info of last CS timeout occurred.3018* @timestamp: CS timeout timestamp.3019* @write_enable: if set writing to CS parameters in the structure is enabled. otherwise - disabled,3020* so the first (root cause) CS timeout will not be overwritten.3021* @seq: CS timeout sequence number.3022*/3023struct cs_timeout_info {3024ktime_t timestamp;3025atomic_t write_enable;3026u64 seq;3027};30283029#define MAX_QMAN_STREAMS_INFO 43030#define OPCODE_INFO_MAX_ADDR_SIZE 83031/**3032* struct undefined_opcode_info - info about last undefined opcode error3033* @timestamp: timestamp of the undefined opcode error3034* @cb_addr_streams: CB addresses (per stream) that are currently exists in the PQ3035* entries. In case all streams array entries are3036* filled with values, it means the execution was in Lower-CP.3037* @cq_addr: the address of the current handled command buffer3038* @cq_size: the size of the current handled command buffer3039* @cb_addr_streams_len: num of streams - actual len of cb_addr_streams array.3040* should be equal to 1 in case of undefined opcode3041* in Upper-CP (specific stream) and equal to 4 in case3042* of undefined opcode in Lower-CP.3043* @engine_id: engine-id that the error occurred on3044* @stream_id: the stream id the error occurred on. In case the stream equals to3045* MAX_QMAN_STREAMS_INFO it means the error occurred on a Lower-CP.3046* @write_enable: if set, writing to undefined opcode parameters in the structure3047* is enable so the first (root cause) undefined opcode will not be3048* overwritten.3049*/3050struct undefined_opcode_info {3051ktime_t timestamp;3052u64 cb_addr_streams[MAX_QMAN_STREAMS_INFO][OPCODE_INFO_MAX_ADDR_SIZE];3053u64 cq_addr;3054u32 cq_size;3055u32 cb_addr_streams_len;3056u32 engine_id;3057u32 stream_id;3058bool write_enable;3059};30603061/**3062* struct page_fault_info - page fault information.3063* @page_fault: holds information collected during a page fault.3064* @user_mappings: buffer containing user mappings.3065* @num_of_user_mappings: number of user mappings.3066* @page_fault_detected: if set as 1, then a page-fault was discovered for the3067* first time after the driver has finished booting-up.3068* Since we're looking for the page-fault's root cause,3069* we don't care of the others that might follow it-3070* so once changed to 1, it will remain that way.3071* @page_fault_info_available: indicates that a page fault info is now available.3072*/3073struct page_fault_info {3074struct hl_page_fault_info page_fault;3075struct hl_user_mapping *user_mappings;3076u64 num_of_user_mappings;3077atomic_t page_fault_detected;3078bool page_fault_info_available;3079};30803081/**3082* struct razwi_info - RAZWI information.3083* @razwi: holds information collected during a RAZWI3084* @razwi_detected: if set as 1, then a RAZWI was discovered for the3085* first time after the driver has finished booting-up.3086* Since we're looking for the RAZWI's root cause,3087* we don't care of the others that might follow it-3088* so once changed to 1, it will remain that way.3089* @razwi_info_available: indicates that a RAZWI info is now available.3090*/3091struct razwi_info {3092struct hl_info_razwi_event razwi;3093atomic_t razwi_detected;3094bool razwi_info_available;3095};30963097/**3098* struct hw_err_info - HW error information.3099* @event: holds information on the event.3100* @event_detected: if set as 1, then a HW event was discovered for the3101* first time after the driver has finished booting-up.3102* currently we assume that only fatal events (that require hard-reset) are3103* reported so we don't care of the others that might follow it.3104* so once changed to 1, it will remain that way.3105* TODO: support multiple events.3106* @event_info_available: indicates that a HW event info is now available.3107*/3108struct hw_err_info {3109struct hl_info_hw_err_event event;3110atomic_t event_detected;3111bool event_info_available;3112};31133114/**3115* struct fw_err_info - FW error information.3116* @event: holds information on the event.3117* @event_detected: if set as 1, then a FW event was discovered for the3118* first time after the driver has finished booting-up.3119* currently we assume that only fatal events (that require hard-reset) are3120* reported so we don't care of the others that might follow it.3121* so once changed to 1, it will remain that way.3122* TODO: support multiple events.3123* @event_info_available: indicates that a HW event info is now available.3124*/3125struct fw_err_info {3126struct hl_info_fw_err_event event;3127atomic_t event_detected;3128bool event_info_available;3129};31303131/**3132* struct engine_err_info - engine error information.3133* @event: holds information on the event.3134* @event_detected: if set as 1, then an engine event was discovered for the3135* first time after the driver has finished booting-up.3136* @event_info_available: indicates that an engine event info is now available.3137*/3138struct engine_err_info {3139struct hl_info_engine_err_event event;3140atomic_t event_detected;3141bool event_info_available;3142};314331443145/**3146* struct hl_error_info - holds information collected during an error.3147* @cs_timeout: CS timeout error information.3148* @razwi_info: RAZWI information.3149* @undef_opcode: undefined opcode information.3150* @page_fault_info: page fault information.3151* @hw_err: (fatal) hardware error information.3152* @fw_err: firmware error information.3153* @engine_err: engine error information.3154*/3155struct hl_error_info {3156struct cs_timeout_info cs_timeout;3157struct razwi_info razwi_info;3158struct undefined_opcode_info undef_opcode;3159struct page_fault_info page_fault_info;3160struct hw_err_info hw_err;3161struct fw_err_info fw_err;3162struct engine_err_info engine_err;3163};31643165/**3166* struct hl_reset_info - holds current device reset information.3167* @lock: lock to protect critical reset flows.3168* @compute_reset_cnt: number of compute resets since the driver was loaded.3169* @hard_reset_cnt: number of hard resets since the driver was loaded.3170* @hard_reset_schedule_flags: hard reset is scheduled to after current compute reset,3171* here we hold the hard reset flags.3172* @in_reset: is device in reset flow.3173* @in_compute_reset: Device is currently in reset but not in hard-reset.3174* @needs_reset: true if reset_on_lockup is false and device should be reset3175* due to lockup.3176* @hard_reset_pending: is there a hard reset work pending.3177* @curr_reset_cause: saves an enumerated reset cause when a hard reset is3178* triggered, and cleared after it is shared with preboot.3179* @prev_reset_trigger: saves the previous trigger which caused a reset, overridden3180* with a new value on next reset3181* @reset_trigger_repeated: set if device reset is triggered more than once with3182* same cause.3183* @skip_reset_on_timeout: Skip device reset if CS has timed out, wait for it to3184* complete instead.3185* @watchdog_active: true if a device release watchdog work is scheduled.3186*/3187struct hl_reset_info {3188spinlock_t lock;3189u32 compute_reset_cnt;3190u32 hard_reset_cnt;3191u32 hard_reset_schedule_flags;3192u8 in_reset;3193u8 in_compute_reset;3194u8 needs_reset;3195u8 hard_reset_pending;3196u8 curr_reset_cause;3197u8 prev_reset_trigger;3198u8 reset_trigger_repeated;3199u8 skip_reset_on_timeout;3200u8 watchdog_active;3201};32023203/**3204* struct eq_heartbeat_debug_info - stores debug info to be used upon heartbeat failure.3205* @last_pq_heartbeat_ts: timestamp of the last test packet that was sent to FW.3206* This packet is the trigger in FW to send the EQ heartbeat event.3207* @last_eq_heartbeat_ts: timestamp of the last EQ heartbeat event that was received from FW.3208* @heartbeat_event_counter: number of heartbeat events received.3209* @cpu_queue_id: used to read the queue pi/ci3210*/3211struct eq_heartbeat_debug_info {3212time64_t last_pq_heartbeat_ts;3213time64_t last_eq_heartbeat_ts;3214u32 heartbeat_event_counter;3215u32 cpu_queue_id;3216};32173218/**3219* struct hl_device - habanalabs device structure.3220* @pdev: pointer to PCI device, can be NULL in case of simulator device.3221* @pcie_bar_phys: array of available PCIe bars physical addresses.3222* (required only for PCI address match mode)3223* @pcie_bar: array of available PCIe bars virtual addresses.3224* @rmmio: configuration area address on SRAM.3225* @drm: related DRM device.3226* @cdev_ctrl: char device for control operations only (INFO IOCTL)3227* @dev: related kernel basic device structure.3228* @dev_ctrl: related kernel device structure for the control device3229* @work_heartbeat: delayed work for CPU-CP is-alive check.3230* @device_reset_work: delayed work which performs hard reset3231* @device_release_watchdog_work: watchdog work that performs hard reset if user doesn't release3232* device upon certain error cases.3233* @asic_name: ASIC specific name.3234* @asic_type: ASIC specific type.3235* @completion_queue: array of hl_cq.3236* @user_interrupt: array of hl_user_interrupt. upon the corresponding user3237* interrupt, driver will monitor the list of fences3238* registered to this interrupt.3239* @tpc_interrupt: single TPC interrupt for all TPCs.3240* @unexpected_error_interrupt: single interrupt for unexpected user error indication.3241* @common_user_cq_interrupt: common user CQ interrupt for all user CQ interrupts.3242* upon any user CQ interrupt, driver will monitor the3243* list of fences registered to this common structure.3244* @common_decoder_interrupt: common decoder interrupt for all user decoder interrupts.3245* @shadow_cs_queue: pointer to a shadow queue that holds pointers to3246* outstanding command submissions.3247* @cq_wq: work queues of completion queues for executing work in process3248* context.3249* @eq_wq: work queue of event queue for executing work in process context.3250* @cs_cmplt_wq: work queue of CS completions for executing work in process3251* context.3252* @ts_free_obj_wq: work queue for timestamp registration objects release.3253* @prefetch_wq: work queue for MMU pre-fetch operations.3254* @reset_wq: work queue for device reset procedure.3255* @kernel_ctx: Kernel driver context structure.3256* @kernel_queues: array of hl_hw_queue.3257* @cs_mirror_list: CS mirror list for TDR.3258* @cs_mirror_lock: protects cs_mirror_list.3259* @kernel_mem_mgr: memory manager for memory buffers with lifespan of driver.3260* @event_queue: event queue for IRQ from CPU-CP.3261* @dma_pool: DMA pool for small allocations.3262* @cpu_accessible_dma_mem: Host <-> CPU-CP shared memory CPU address.3263* @cpu_accessible_dma_address: Host <-> CPU-CP shared memory DMA address.3264* @cpu_accessible_dma_pool: Host <-> CPU-CP shared memory pool.3265* @asid_bitmap: holds used/available ASIDs.3266* @asid_mutex: protects asid_bitmap.3267* @send_cpu_message_lock: enforces only one message in Host <-> CPU-CP queue.3268* @debug_lock: protects critical section of setting debug mode for device3269* @mmu_lock: protects the MMU page tables and invalidation h/w. Although the3270* page tables are per context, the invalidation h/w is per MMU.3271* Therefore, we can't allow multiple contexts (we only have two,3272* user and kernel) to access the invalidation h/w at the same time.3273* In addition, any change to the PGT, modifying the MMU hash or3274* walking the PGT requires talking this lock.3275* @asic_prop: ASIC specific immutable properties.3276* @asic_funcs: ASIC specific functions.3277* @asic_specific: ASIC specific information to use only from ASIC files.3278* @vm: virtual memory manager for MMU.3279* @hwmon_dev: H/W monitor device.3280* @hl_chip_info: ASIC's sensors information.3281* @device_status_description: device status description.3282* @hl_debugfs: device's debugfs manager.3283* @cb_pool: list of pre allocated CBs.3284* @cb_pool_lock: protects the CB pool.3285* @internal_cb_pool_virt_addr: internal command buffer pool virtual address.3286* @internal_cb_pool_dma_addr: internal command buffer pool dma address.3287* @internal_cb_pool: internal command buffer memory pool.3288* @internal_cb_va_base: internal cb pool mmu virtual address base3289* @fpriv_list: list of file private data structures. Each structure is created3290* when a user opens the device3291* @fpriv_ctrl_list: list of file private data structures. Each structure is created3292* when a user opens the control device3293* @fpriv_list_lock: protects the fpriv_list3294* @fpriv_ctrl_list_lock: protects the fpriv_ctrl_list3295* @aggregated_cs_counters: aggregated cs counters among all contexts3296* @mmu_priv: device-specific MMU data.3297* @mmu_func: device-related MMU functions.3298* @dec: list of decoder sw instance3299* @fw_loader: FW loader manager.3300* @pci_mem_region: array of memory regions in the PCI3301* @state_dump_specs: constants and dictionaries needed to dump system state.3302* @multi_cs_completion: array of multi-CS completion.3303* @clk_throttling: holds information about current/previous clock throttling events3304* @captured_err_info: holds information about errors.3305* @reset_info: holds current device reset information.3306* @heartbeat_debug_info: counters used to debug heartbeat failures.3307* @irq_affinity_mask: mask of available CPU cores for user and decoder interrupt handling.3308* @stream_master_qid_arr: pointer to array with QIDs of master streams.3309* @fw_inner_major_ver: the major of current loaded preboot inner version.3310* @fw_inner_minor_ver: the minor of current loaded preboot inner version.3311* @fw_sw_major_ver: the major of current loaded preboot SW version.3312* @fw_sw_minor_ver: the minor of current loaded preboot SW version.3313* @fw_sw_sub_minor_ver: the sub-minor of current loaded preboot SW version.3314* @dram_used_mem: current DRAM memory consumption.3315* @memory_scrub_val: the value to which the dram will be scrubbed to using cb scrub_device_dram3316* @timeout_jiffies: device CS timeout value.3317* @max_power: the max power of the device, as configured by the sysadmin. This3318* value is saved so in case of hard-reset, the driver will restore3319* this value and update the F/W after the re-initialization3320* @boot_error_status_mask: contains a mask of the device boot error status.3321* Each bit represents a different error, according to3322* the defines in hl_boot_if.h. If the bit is cleared,3323* the error will be ignored by the driver during3324* device initialization. Mainly used to debug and3325* workaround firmware bugs3326* @dram_pci_bar_start: start bus address of PCIe bar towards DRAM.3327* @last_successful_open_ktime: timestamp (ktime) of the last successful device open.3328* @last_successful_open_jif: timestamp (jiffies) of the last successful3329* device open.3330* @last_open_session_duration_jif: duration (jiffies) of the last device open3331* session.3332* @open_counter: number of successful device open operations.3333* @fw_poll_interval_usec: FW status poll interval in usec.3334* used for CPU boot status3335* @fw_comms_poll_interval_usec: FW comms/protocol poll interval in usec.3336* used for COMMs protocols cmds(COMMS_STS_*)3337* @dram_binning: contains mask of drams that is received from the f/w which indicates which3338* drams are binned-out3339* @tpc_binning: contains mask of tpc engines that is received from the f/w which indicates which3340* tpc engines are binned-out3341* @dmabuf_export_cnt: number of dma-buf exporting.3342* @card_type: Various ASICs have several card types. This indicates the card3343* type of the current device.3344* @major: habanalabs kernel driver major.3345* @high_pll: high PLL profile frequency.3346* @decoder_binning: contains mask of decoder engines that is received from the f/w which3347* indicates which decoder engines are binned-out3348* @edma_binning: contains mask of edma engines that is received from the f/w which3349* indicates which edma engines are binned-out3350* @device_release_watchdog_timeout_sec: device release watchdog timeout value in seconds.3351* @rotator_binning: contains mask of rotators engines that is received from the f/w3352* which indicates which rotator engines are binned-out(Gaudi3 and above).3353* @id: device minor.3354* @cdev_idx: char device index.3355* @cpu_pci_msb_addr: 50-bit extension bits for the device CPU's 40-bit3356* addresses.3357* @is_in_dram_scrub: true if dram scrub operation is on going.3358* @disabled: is device disabled.3359* @late_init_done: is late init stage was done during initialization.3360* @hwmon_initialized: is H/W monitor sensors was initialized.3361* @reset_on_lockup: true if a reset should be done in case of stuck CS, false3362* otherwise.3363* @dram_default_page_mapping: is DRAM default page mapping enabled.3364* @memory_scrub: true to perform device memory scrub in various locations,3365* such as context-switch, context close, page free, etc.3366* @pmmu_huge_range: is a different virtual addresses range used for PMMU with3367* huge pages.3368* @init_done: is the initialization of the device done.3369* @device_cpu_disabled: is the device CPU disabled (due to timeouts)3370* @in_debug: whether the device is in a state where the profiling/tracing infrastructure3371* can be used. This indication is needed because in some ASICs we need to do3372* specific operations to enable that infrastructure.3373* @cdev_sysfs_debugfs_created: were char devices and sysfs/debugfs files created.3374* @stop_on_err: true if engines should stop on error.3375* @supports_sync_stream: is sync stream supported.3376* @sync_stream_queue_idx: helper index for sync stream queues initialization.3377* @collective_mon_idx: helper index for collective initialization3378* @supports_coresight: is CoreSight supported.3379* @supports_cb_mapping: is mapping a CB to the device's MMU supported.3380* @process_kill_trial_cnt: number of trials reset thread tried killing3381* user processes3382* @device_fini_pending: true if device_fini was called and might be3383* waiting for the reset thread to finish3384* @supports_staged_submission: true if staged submissions are supported3385* @device_cpu_is_halted: Flag to indicate whether the device CPU was already3386* halted. We can't halt it again because the COMMS3387* protocol will throw an error. Relevant only for3388* cases where Linux was not loaded to device CPU3389* @supports_wait_for_multi_cs: true if wait for multi CS is supported3390* @is_compute_ctx_active: Whether there is an active compute context executing.3391* @compute_ctx_in_release: true if the current compute context is being released.3392* @supports_mmu_prefetch: true if prefetch is supported, otherwise false.3393* @reset_upon_device_release: reset the device when the user closes the file descriptor of the3394* device.3395* @supports_ctx_switch: true if a ctx switch is required upon first submission.3396* @support_preboot_binning: true if we support read binning info from preboot.3397* @eq_heartbeat_received: indication that eq heartbeat event has received from FW.3398* @nic_ports_mask: Controls which NIC ports are enabled. Used only for testing.3399* @fw_components: Controls which f/w components to load to the device. There are multiple f/w3400* stages and sometimes we want to stop at a certain stage. Used only for testing.3401* @mmu_disable: Disable the device MMU(s). Used only for testing.3402* @cpu_queues_enable: Whether to enable queues communication vs. the f/w. Used only for testing.3403* @pldm: Whether we are running in Palladium environment. Used only for testing.3404* @hard_reset_on_fw_events: Whether to do device hard-reset when a fatal event is received from3405* the f/w. Used only for testing.3406* @bmc_enable: Whether we are running in a box with BMC. Used only for testing.3407* @reset_on_preboot_fail: Whether to reset the device if preboot f/w fails to load.3408* Used only for testing.3409* @heartbeat: Controls if we want to enable the heartbeat mechanism vs. the f/w, which verifies3410* that the f/w is always alive. Used only for testing.3411*/3412struct hl_device {3413struct pci_dev *pdev;3414u64 pcie_bar_phys[HL_PCI_NUM_BARS];3415void __iomem *pcie_bar[HL_PCI_NUM_BARS];3416void __iomem *rmmio;3417struct drm_device drm;3418struct cdev cdev_ctrl;3419struct device *dev;3420struct device *dev_ctrl;3421struct delayed_work work_heartbeat;3422struct hl_device_reset_work device_reset_work;3423struct hl_device_reset_work device_release_watchdog_work;3424char asic_name[HL_STR_MAX];3425char status[HL_DEV_STS_MAX][HL_STR_MAX];3426enum hl_asic_type asic_type;3427struct hl_cq *completion_queue;3428struct hl_user_interrupt *user_interrupt;3429struct hl_user_interrupt tpc_interrupt;3430struct hl_user_interrupt unexpected_error_interrupt;3431struct hl_user_interrupt common_user_cq_interrupt;3432struct hl_user_interrupt common_decoder_interrupt;3433struct hl_cs **shadow_cs_queue;3434struct workqueue_struct **cq_wq;3435struct workqueue_struct *eq_wq;3436struct workqueue_struct *cs_cmplt_wq;3437struct workqueue_struct *ts_free_obj_wq;3438struct workqueue_struct *prefetch_wq;3439struct workqueue_struct *reset_wq;3440struct hl_ctx *kernel_ctx;3441struct hl_hw_queue *kernel_queues;3442struct list_head cs_mirror_list;3443spinlock_t cs_mirror_lock;3444struct hl_mem_mgr kernel_mem_mgr;3445struct hl_eq event_queue;3446struct dma_pool *dma_pool;3447void *cpu_accessible_dma_mem;3448dma_addr_t cpu_accessible_dma_address;3449struct gen_pool *cpu_accessible_dma_pool;3450unsigned long *asid_bitmap;3451struct mutex asid_mutex;3452struct mutex send_cpu_message_lock;3453struct mutex debug_lock;3454struct mutex mmu_lock;3455struct asic_fixed_properties asic_prop;3456const struct hl_asic_funcs *asic_funcs;3457void *asic_specific;3458struct hl_vm vm;3459struct device *hwmon_dev;3460struct hwmon_chip_info *hl_chip_info;34613462struct hl_dbg_device_entry hl_debugfs;34633464struct list_head cb_pool;3465spinlock_t cb_pool_lock;34663467void *internal_cb_pool_virt_addr;3468dma_addr_t internal_cb_pool_dma_addr;3469struct gen_pool *internal_cb_pool;3470u64 internal_cb_va_base;34713472struct list_head fpriv_list;3473struct list_head fpriv_ctrl_list;3474struct mutex fpriv_list_lock;3475struct mutex fpriv_ctrl_list_lock;34763477struct hl_cs_counters_atomic aggregated_cs_counters;34783479struct hl_mmu_priv mmu_priv;3480struct hl_mmu_funcs mmu_func[MMU_NUM_PGT_LOCATIONS];34813482struct hl_dec *dec;34833484struct fw_load_mgr fw_loader;34853486struct pci_mem_region pci_mem_region[PCI_REGION_NUMBER];34873488struct hl_state_dump_specs state_dump_specs;34893490struct multi_cs_completion multi_cs_completion[3491MULTI_CS_MAX_USER_CTX];3492struct hl_clk_throttle clk_throttling;3493struct hl_error_info captured_err_info;34943495struct hl_reset_info reset_info;34963497struct eq_heartbeat_debug_info heartbeat_debug_info;34983499cpumask_t irq_affinity_mask;35003501u32 *stream_master_qid_arr;3502u32 fw_inner_major_ver;3503u32 fw_inner_minor_ver;3504u32 fw_sw_major_ver;3505u32 fw_sw_minor_ver;3506u32 fw_sw_sub_minor_ver;3507atomic64_t dram_used_mem;3508u64 memory_scrub_val;3509u64 timeout_jiffies;3510u64 max_power;3511u64 boot_error_status_mask;3512u64 dram_pci_bar_start;3513u64 last_successful_open_jif;3514u64 last_open_session_duration_jif;3515u64 open_counter;3516u64 fw_poll_interval_usec;3517ktime_t last_successful_open_ktime;3518u64 fw_comms_poll_interval_usec;3519u64 dram_binning;3520u64 tpc_binning;3521atomic_t dmabuf_export_cnt;3522enum cpucp_card_types card_type;3523u32 major;3524u32 high_pll;3525u32 decoder_binning;3526u32 edma_binning;3527u32 device_release_watchdog_timeout_sec;3528u32 rotator_binning;3529u16 id;3530u16 cdev_idx;3531u16 cpu_pci_msb_addr;3532u8 is_in_dram_scrub;3533u8 disabled;3534u8 late_init_done;3535u8 hwmon_initialized;3536u8 reset_on_lockup;3537u8 dram_default_page_mapping;3538u8 memory_scrub;3539u8 pmmu_huge_range;3540u8 init_done;3541u8 device_cpu_disabled;3542u8 in_debug;3543u8 cdev_sysfs_debugfs_created;3544u8 stop_on_err;3545u8 supports_sync_stream;3546u8 sync_stream_queue_idx;3547u8 collective_mon_idx;3548u8 supports_coresight;3549u8 supports_cb_mapping;3550u8 process_kill_trial_cnt;3551u8 device_fini_pending;3552u8 supports_staged_submission;3553u8 device_cpu_is_halted;3554u8 supports_wait_for_multi_cs;3555u8 stream_master_qid_arr_size;3556u8 is_compute_ctx_active;3557u8 compute_ctx_in_release;3558u8 supports_mmu_prefetch;3559u8 reset_upon_device_release;3560u8 supports_ctx_switch;3561u8 support_preboot_binning;3562u8 eq_heartbeat_received;35633564/* Parameters for bring-up to be upstreamed */3565u64 nic_ports_mask;3566u64 fw_components;3567u8 mmu_disable;3568u8 cpu_queues_enable;3569u8 pldm;3570u8 hard_reset_on_fw_events;3571u8 bmc_enable;3572u8 reset_on_preboot_fail;3573u8 heartbeat;3574};35753576/* Retrieve PCI device name in case of a PCI device or dev name in simulator */3577#define HL_DEV_NAME(hdev) \3578((hdev)->pdev ? dev_name(&(hdev)->pdev->dev) : "NA-DEVICE")35793580/**3581* struct hl_cs_encaps_sig_handle - encapsulated signals handle structure3582* @refcount: refcount used to protect removing this id when several3583* wait cs are used to wait of the reserved encaps signals.3584* @hdev: pointer to habanalabs device structure.3585* @hw_sob: pointer to H/W SOB used in the reservation.3586* @ctx: pointer to the user's context data structure3587* @cs_seq: staged cs sequence which contains encapsulated signals3588* @id: idr handler id to be used to fetch the handler info3589* @q_idx: stream queue index3590* @pre_sob_val: current SOB value before reservation3591* @count: signals number3592*/3593struct hl_cs_encaps_sig_handle {3594struct kref refcount;3595struct hl_device *hdev;3596struct hl_hw_sob *hw_sob;3597struct hl_ctx *ctx;3598u64 cs_seq;3599u32 id;3600u32 q_idx;3601u32 pre_sob_val;3602u32 count;3603};36043605/**3606* struct hl_info_fw_err_info - firmware error information structure3607* @err_type: The type of error detected (or reported).3608* @event_mask: Pointer to the event mask to be modified with the detected error flag3609* (can be NULL)3610* @event_id: The id of the event that reported the error3611* (applicable when err_type is HL_INFO_FW_REPORTED_ERR).3612*/3613struct hl_info_fw_err_info {3614enum hl_info_fw_err_type err_type;3615u64 *event_mask;3616u16 event_id;3617};36183619/*3620* IOCTLs3621*/36223623/**3624* typedef hl_ioctl_t - typedef for ioctl function in the driver3625* @hpriv: pointer to the FD's private data, which contains state of3626* user process3627* @data: pointer to the input/output arguments structure of the IOCTL3628*3629* Return: 0 for success, negative value for error3630*/3631typedef int hl_ioctl_t(struct hl_fpriv *hpriv, void *data);36323633/**3634* struct hl_ioctl_desc - describes an IOCTL entry of the driver.3635* @cmd: the IOCTL code as created by the kernel macros.3636* @func: pointer to the driver's function that should be called for this IOCTL.3637*/3638struct hl_ioctl_desc {3639unsigned int cmd;3640hl_ioctl_t *func;3641};36423643/*3644* Kernel module functions that can be accessed by entire module3645*/36463647/**3648* hl_get_sg_info() - get number of pages and the DMA address from SG list.3649* @sg: the SG list.3650* @dma_addr: pointer to DMA address to return.3651*3652* Calculate the number of consecutive pages described by the SG list. Take the3653* offset of the address in the first page, add to it the length and round it up3654* to the number of needed pages.3655*/3656static inline u32 hl_get_sg_info(struct scatterlist *sg, dma_addr_t *dma_addr)3657{3658*dma_addr = sg_dma_address(sg);36593660return ((((*dma_addr) & (PAGE_SIZE - 1)) + sg_dma_len(sg)) +3661(PAGE_SIZE - 1)) >> PAGE_SHIFT;3662}36633664/**3665* hl_mem_area_inside_range() - Checks whether address+size are inside a range.3666* @address: The start address of the area we want to validate.3667* @size: The size in bytes of the area we want to validate.3668* @range_start_address: The start address of the valid range.3669* @range_end_address: The end address of the valid range.3670*3671* Return: true if the area is inside the valid range, false otherwise.3672*/3673static inline bool hl_mem_area_inside_range(u64 address, u64 size,3674u64 range_start_address, u64 range_end_address)3675{3676u64 end_address = address + size;36773678if ((address >= range_start_address) &&3679(end_address <= range_end_address) &&3680(end_address > address))3681return true;36823683return false;3684}36853686static inline struct hl_device *to_hl_device(struct drm_device *ddev)3687{3688return container_of(ddev, struct hl_device, drm);3689}36903691/**3692* hl_mem_area_crosses_range() - Checks whether address+size crossing a range.3693* @address: The start address of the area we want to validate.3694* @size: The size in bytes of the area we want to validate.3695* @range_start_address: The start address of the valid range.3696* @range_end_address: The end address of the valid range.3697*3698* Return: true if the area overlaps part or all of the valid range,3699* false otherwise.3700*/3701static inline bool hl_mem_area_crosses_range(u64 address, u32 size,3702u64 range_start_address, u64 range_end_address)3703{3704u64 end_address = address + size - 1;37053706return ((address <= range_end_address) && (range_start_address <= end_address));3707}37083709uint64_t hl_set_dram_bar_default(struct hl_device *hdev, u64 addr);3710void *hl_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size, dma_addr_t *dma_handle);3711void hl_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size, void *vaddr);3712void *hl_asic_dma_alloc_coherent_caller(struct hl_device *hdev, size_t size, dma_addr_t *dma_handle,3713gfp_t flag, const char *caller);3714void hl_asic_dma_free_coherent_caller(struct hl_device *hdev, size_t size, void *cpu_addr,3715dma_addr_t dma_handle, const char *caller);3716void *hl_asic_dma_pool_zalloc_caller(struct hl_device *hdev, size_t size, gfp_t mem_flags,3717dma_addr_t *dma_handle, const char *caller);3718void hl_asic_dma_pool_free_caller(struct hl_device *hdev, void *vaddr, dma_addr_t dma_addr,3719const char *caller);3720int hl_dma_map_sgtable_caller(struct hl_device *hdev, struct sg_table *sgt,3721enum dma_data_direction dir, const char *caller);3722void hl_dma_unmap_sgtable_caller(struct hl_device *hdev, struct sg_table *sgt,3723enum dma_data_direction dir, const char *caller);3724int hl_asic_dma_map_sgtable(struct hl_device *hdev, struct sg_table *sgt,3725enum dma_data_direction dir);3726void hl_asic_dma_unmap_sgtable(struct hl_device *hdev, struct sg_table *sgt,3727enum dma_data_direction dir);3728int hl_access_sram_dram_region(struct hl_device *hdev, u64 addr, u64 *val,3729enum debugfs_access_type acc_type, enum pci_region region_type, bool set_dram_bar);3730int hl_access_cfg_region(struct hl_device *hdev, u64 addr, u64 *val,3731enum debugfs_access_type acc_type);3732int hl_access_dev_mem(struct hl_device *hdev, enum pci_region region_type,3733u64 addr, u64 *val, enum debugfs_access_type acc_type);37343735int hl_mmap(struct file *filp, struct vm_area_struct *vma);37363737int hl_device_open(struct drm_device *drm, struct drm_file *file_priv);3738void hl_device_release(struct drm_device *ddev, struct drm_file *file_priv);37393740int hl_device_open_ctrl(struct inode *inode, struct file *filp);3741bool hl_device_operational(struct hl_device *hdev,3742enum hl_device_status *status);3743bool hl_ctrl_device_operational(struct hl_device *hdev,3744enum hl_device_status *status);3745enum hl_device_status hl_device_status(struct hl_device *hdev);3746int hl_device_set_debug_mode(struct hl_device *hdev, struct hl_ctx *ctx, bool enable);3747int hl_hw_queues_create(struct hl_device *hdev);3748void hl_hw_queues_destroy(struct hl_device *hdev);3749int hl_hw_queue_send_cb_no_cmpl(struct hl_device *hdev, u32 hw_queue_id,3750u32 cb_size, u64 cb_ptr);3751void hl_hw_queue_submit_bd(struct hl_device *hdev, struct hl_hw_queue *q,3752u32 ctl, u32 len, u64 ptr);3753int hl_hw_queue_schedule_cs(struct hl_cs *cs);3754u32 hl_hw_queue_add_ptr(u32 ptr, u16 val);3755void hl_hw_queue_inc_ci_kernel(struct hl_device *hdev, u32 hw_queue_id);3756void hl_hw_queue_update_ci(struct hl_cs *cs);3757void hl_hw_queue_reset(struct hl_device *hdev, bool hard_reset);37583759#define hl_queue_inc_ptr(p) hl_hw_queue_add_ptr(p, 1)3760#define hl_pi_2_offset(pi) ((pi) & (HL_QUEUE_LENGTH - 1))37613762int hl_cq_init(struct hl_device *hdev, struct hl_cq *q, u32 hw_queue_id);3763void hl_cq_fini(struct hl_device *hdev, struct hl_cq *q);3764int hl_eq_init(struct hl_device *hdev, struct hl_eq *q);3765void hl_eq_fini(struct hl_device *hdev, struct hl_eq *q);3766void hl_cq_reset(struct hl_device *hdev, struct hl_cq *q);3767void hl_eq_reset(struct hl_device *hdev, struct hl_eq *q);3768void hl_eq_dump(struct hl_device *hdev, struct hl_eq *q);3769irqreturn_t hl_irq_handler_cq(int irq, void *arg);3770irqreturn_t hl_irq_handler_eq(int irq, void *arg);3771irqreturn_t hl_irq_handler_dec_abnrm(int irq, void *arg);3772irqreturn_t hl_irq_user_interrupt_handler(int irq, void *arg);3773irqreturn_t hl_irq_user_interrupt_thread_handler(int irq, void *arg);3774irqreturn_t hl_irq_eq_error_interrupt_thread_handler(int irq, void *arg);3775u32 hl_cq_inc_ptr(u32 ptr);37763777int hl_asid_init(struct hl_device *hdev);3778void hl_asid_fini(struct hl_device *hdev);3779unsigned long hl_asid_alloc(struct hl_device *hdev);3780void hl_asid_free(struct hl_device *hdev, unsigned long asid);37813782int hl_ctx_create(struct hl_device *hdev, struct hl_fpriv *hpriv);3783void hl_ctx_free(struct hl_device *hdev, struct hl_ctx *ctx);3784int hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx);3785void hl_ctx_do_release(struct kref *ref);3786void hl_ctx_get(struct hl_ctx *ctx);3787int hl_ctx_put(struct hl_ctx *ctx);3788struct hl_ctx *hl_get_compute_ctx(struct hl_device *hdev);3789struct hl_fence *hl_ctx_get_fence(struct hl_ctx *ctx, u64 seq);3790int hl_ctx_get_fences(struct hl_ctx *ctx, u64 *seq_arr,3791struct hl_fence **fence, u32 arr_len);3792void hl_ctx_mgr_init(struct hl_ctx_mgr *mgr);3793void hl_ctx_mgr_fini(struct hl_device *hdev, struct hl_ctx_mgr *mgr);37943795int hl_device_init(struct hl_device *hdev);3796void hl_device_fini(struct hl_device *hdev);3797int hl_device_suspend(struct hl_device *hdev);3798int hl_device_resume(struct hl_device *hdev);3799int hl_device_reset(struct hl_device *hdev, u32 flags);3800int hl_device_cond_reset(struct hl_device *hdev, u32 flags, u64 event_mask);3801void hl_hpriv_get(struct hl_fpriv *hpriv);3802int hl_hpriv_put(struct hl_fpriv *hpriv);3803int hl_device_utilization(struct hl_device *hdev, u32 *utilization);38043805int hl_build_hwmon_channel_info(struct hl_device *hdev,3806struct cpucp_sensor *sensors_arr);38073808void hl_notifier_event_send_all(struct hl_device *hdev, u64 event_mask);38093810int hl_sysfs_init(struct hl_device *hdev);3811void hl_sysfs_fini(struct hl_device *hdev);38123813int hl_hwmon_init(struct hl_device *hdev);3814void hl_hwmon_fini(struct hl_device *hdev);3815void hl_hwmon_release_resources(struct hl_device *hdev);38163817int hl_cb_create(struct hl_device *hdev, struct hl_mem_mgr *mmg,3818struct hl_ctx *ctx, u32 cb_size, bool internal_cb,3819bool map_cb, u64 *handle);3820int hl_cb_destroy(struct hl_mem_mgr *mmg, u64 cb_handle);3821int hl_hw_block_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma);3822struct hl_cb *hl_cb_get(struct hl_mem_mgr *mmg, u64 handle);3823void hl_cb_put(struct hl_cb *cb);3824struct hl_cb *hl_cb_kernel_create(struct hl_device *hdev, u32 cb_size,3825bool internal_cb);3826int hl_cb_pool_init(struct hl_device *hdev);3827int hl_cb_pool_fini(struct hl_device *hdev);3828int hl_cb_va_pool_init(struct hl_ctx *ctx);3829void hl_cb_va_pool_fini(struct hl_ctx *ctx);38303831void hl_cs_rollback_all(struct hl_device *hdev, bool skip_wq_flush);3832struct hl_cs_job *hl_cs_allocate_job(struct hl_device *hdev,3833enum hl_queue_type queue_type, bool is_kernel_allocated_cb);3834void hl_sob_reset_error(struct kref *ref);3835int hl_gen_sob_mask(u16 sob_base, u8 sob_mask, u8 *mask);3836void hl_fence_put(struct hl_fence *fence);3837void hl_fences_put(struct hl_fence **fence, int len);3838void hl_fence_get(struct hl_fence *fence);3839void cs_get(struct hl_cs *cs);3840bool cs_needs_completion(struct hl_cs *cs);3841bool cs_needs_timeout(struct hl_cs *cs);3842bool is_staged_cs_last_exists(struct hl_device *hdev, struct hl_cs *cs);3843struct hl_cs *hl_staged_cs_find_first(struct hl_device *hdev, u64 cs_seq);3844void hl_multi_cs_completion_init(struct hl_device *hdev);3845u32 hl_get_active_cs_num(struct hl_device *hdev);38463847void goya_set_asic_funcs(struct hl_device *hdev);3848void gaudi_set_asic_funcs(struct hl_device *hdev);3849void gaudi2_set_asic_funcs(struct hl_device *hdev);38503851int hl_vm_ctx_init(struct hl_ctx *ctx);3852void hl_vm_ctx_fini(struct hl_ctx *ctx);38533854int hl_vm_init(struct hl_device *hdev);3855void hl_vm_fini(struct hl_device *hdev);38563857void hl_hw_block_mem_init(struct hl_ctx *ctx);3858void hl_hw_block_mem_fini(struct hl_ctx *ctx);38593860u64 hl_reserve_va_block(struct hl_device *hdev, struct hl_ctx *ctx,3861enum hl_va_range_type type, u64 size, u32 alignment);3862int hl_unreserve_va_block(struct hl_device *hdev, struct hl_ctx *ctx,3863u64 start_addr, u64 size);3864int hl_pin_host_memory(struct hl_device *hdev, u64 addr, u64 size,3865struct hl_userptr *userptr);3866void hl_unpin_host_memory(struct hl_device *hdev, struct hl_userptr *userptr);3867void hl_userptr_delete_list(struct hl_device *hdev,3868struct list_head *userptr_list);3869bool hl_userptr_is_pinned(struct hl_device *hdev, u64 addr, u32 size,3870struct list_head *userptr_list,3871struct hl_userptr **userptr);38723873int hl_mmu_init(struct hl_device *hdev);3874void hl_mmu_fini(struct hl_device *hdev);3875int hl_mmu_ctx_init(struct hl_ctx *ctx);3876void hl_mmu_ctx_fini(struct hl_ctx *ctx);3877int hl_mmu_map_page(struct hl_ctx *ctx, u64 virt_addr, u64 phys_addr,3878u32 page_size, bool flush_pte);3879int hl_mmu_get_real_page_size(struct hl_device *hdev, struct hl_mmu_properties *mmu_prop,3880u32 page_size, u32 *real_page_size, bool is_dram_addr);3881int hl_mmu_unmap_page(struct hl_ctx *ctx, u64 virt_addr, u32 page_size,3882bool flush_pte);3883int hl_mmu_map_contiguous(struct hl_ctx *ctx, u64 virt_addr,3884u64 phys_addr, u32 size);3885int hl_mmu_unmap_contiguous(struct hl_ctx *ctx, u64 virt_addr, u32 size);3886int hl_mmu_invalidate_cache(struct hl_device *hdev, bool is_hard, u32 flags);3887int hl_mmu_invalidate_cache_range(struct hl_device *hdev, bool is_hard,3888u32 flags, u32 asid, u64 va, u64 size);3889int hl_mmu_prefetch_cache_range(struct hl_ctx *ctx, u32 flags, u32 asid, u64 va, u64 size);3890u64 hl_mmu_get_next_hop_addr(struct hl_ctx *ctx, u64 curr_pte);3891u64 hl_mmu_get_hop_pte_phys_addr(struct hl_ctx *ctx, struct hl_mmu_properties *mmu_prop,3892u8 hop_idx, u64 hop_addr, u64 virt_addr);3893void hl_mmu_hr_flush(struct hl_ctx *ctx);3894int hl_mmu_hr_init(struct hl_device *hdev, struct hl_mmu_hr_priv *hr_priv, u32 hop_table_size,3895u64 pgt_size);3896void hl_mmu_hr_fini(struct hl_device *hdev, struct hl_mmu_hr_priv *hr_priv, u32 hop_table_size);3897void hl_mmu_hr_free_hop_remove_pgt(struct pgt_info *pgt_info, struct hl_mmu_hr_priv *hr_priv,3898u32 hop_table_size);3899u64 hl_mmu_hr_pte_phys_to_virt(struct hl_ctx *ctx, struct pgt_info *pgt, u64 phys_pte_addr,3900u32 hop_table_size);3901void hl_mmu_hr_write_pte(struct hl_ctx *ctx, struct pgt_info *pgt_info, u64 phys_pte_addr,3902u64 val, u32 hop_table_size);3903void hl_mmu_hr_clear_pte(struct hl_ctx *ctx, struct pgt_info *pgt_info, u64 phys_pte_addr,3904u32 hop_table_size);3905int hl_mmu_hr_put_pte(struct hl_ctx *ctx, struct pgt_info *pgt_info, struct hl_mmu_hr_priv *hr_priv,3906u32 hop_table_size);3907void hl_mmu_hr_get_pte(struct hl_ctx *ctx, struct hl_hr_mmu_funcs *hr_func, u64 phys_hop_addr);3908struct pgt_info *hl_mmu_hr_get_next_hop_pgt_info(struct hl_ctx *ctx,3909struct hl_hr_mmu_funcs *hr_func,3910u64 curr_pte);3911struct pgt_info *hl_mmu_hr_alloc_hop(struct hl_ctx *ctx, struct hl_mmu_hr_priv *hr_priv,3912struct hl_hr_mmu_funcs *hr_func,3913struct hl_mmu_properties *mmu_prop);3914struct pgt_info *hl_mmu_hr_get_alloc_next_hop(struct hl_ctx *ctx,3915struct hl_mmu_hr_priv *hr_priv,3916struct hl_hr_mmu_funcs *hr_func,3917struct hl_mmu_properties *mmu_prop,3918u64 curr_pte, bool *is_new_hop);3919int hl_mmu_hr_get_tlb_info(struct hl_ctx *ctx, u64 virt_addr, struct hl_mmu_hop_info *hops,3920struct hl_hr_mmu_funcs *hr_func);3921int hl_mmu_if_set_funcs(struct hl_device *hdev);3922void hl_mmu_v1_set_funcs(struct hl_device *hdev, struct hl_mmu_funcs *mmu);3923void hl_mmu_v2_set_funcs(struct hl_device *hdev, struct hl_mmu_funcs *mmu);3924void hl_mmu_v2_hr_set_funcs(struct hl_device *hdev, struct hl_mmu_funcs *mmu);3925int hl_mmu_va_to_pa(struct hl_ctx *ctx, u64 virt_addr, u64 *phys_addr);3926int hl_mmu_get_tlb_info(struct hl_ctx *ctx, u64 virt_addr,3927struct hl_mmu_hop_info *hops);3928u64 hl_mmu_scramble_addr(struct hl_device *hdev, u64 addr);3929u64 hl_mmu_descramble_addr(struct hl_device *hdev, u64 addr);3930bool hl_is_dram_va(struct hl_device *hdev, u64 virt_addr);3931struct pgt_info *hl_mmu_dr_get_pgt_info(struct hl_ctx *ctx, u64 hop_addr);3932void hl_mmu_dr_free_hop(struct hl_ctx *ctx, u64 hop_addr);3933void hl_mmu_dr_free_pgt_node(struct hl_ctx *ctx, struct pgt_info *pgt_info);3934u64 hl_mmu_dr_get_phys_hop0_addr(struct hl_ctx *ctx);3935u64 hl_mmu_dr_get_hop0_addr(struct hl_ctx *ctx);3936void hl_mmu_dr_write_pte(struct hl_ctx *ctx, u64 shadow_pte_addr, u64 val);3937void hl_mmu_dr_write_final_pte(struct hl_ctx *ctx, u64 shadow_pte_addr, u64 val);3938void hl_mmu_dr_clear_pte(struct hl_ctx *ctx, u64 pte_addr);3939u64 hl_mmu_dr_get_phys_addr(struct hl_ctx *ctx, u64 shadow_addr);3940void hl_mmu_dr_get_pte(struct hl_ctx *ctx, u64 hop_addr);3941int hl_mmu_dr_put_pte(struct hl_ctx *ctx, u64 hop_addr);3942u64 hl_mmu_dr_get_alloc_next_hop_addr(struct hl_ctx *ctx, u64 curr_pte, bool *is_new_hop);3943u64 hl_mmu_dr_alloc_hop(struct hl_ctx *ctx);3944void hl_mmu_dr_flush(struct hl_ctx *ctx);3945int hl_mmu_dr_init(struct hl_device *hdev);3946void hl_mmu_dr_fini(struct hl_device *hdev);39473948int hl_fw_version_cmp(struct hl_device *hdev, u32 major, u32 minor, u32 subminor);3949int hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name,3950void __iomem *dst, u32 src_offset, u32 size);3951int hl_fw_send_pci_access_msg(struct hl_device *hdev, u32 opcode, u64 value);3952int hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg,3953u16 len, u32 timeout, u64 *result);3954int hl_fw_unmask_irq(struct hl_device *hdev, u16 event_type);3955int hl_fw_unmask_irq_arr(struct hl_device *hdev, const u32 *irq_arr,3956size_t irq_arr_size);3957int hl_fw_test_cpu_queue(struct hl_device *hdev);3958void *hl_fw_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size,3959dma_addr_t *dma_handle);3960void hl_fw_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size,3961void *vaddr);3962int hl_fw_send_heartbeat(struct hl_device *hdev);3963int hl_fw_cpucp_info_get(struct hl_device *hdev,3964u32 sts_boot_dev_sts0_reg,3965u32 sts_boot_dev_sts1_reg, u32 boot_err0_reg,3966u32 boot_err1_reg);3967int hl_fw_cpucp_handshake(struct hl_device *hdev,3968u32 sts_boot_dev_sts0_reg,3969u32 sts_boot_dev_sts1_reg, u32 boot_err0_reg,3970u32 boot_err1_reg);3971int hl_fw_get_eeprom_data(struct hl_device *hdev, void *data, size_t max_size);3972int hl_fw_get_monitor_dump(struct hl_device *hdev, void *data);3973int hl_fw_cpucp_pci_counters_get(struct hl_device *hdev,3974struct hl_info_pci_counters *counters);3975int hl_fw_cpucp_total_energy_get(struct hl_device *hdev,3976u64 *total_energy);3977int get_used_pll_index(struct hl_device *hdev, u32 input_pll_index,3978enum pll_index *pll_index);3979int hl_fw_cpucp_pll_info_get(struct hl_device *hdev, u32 pll_index,3980u16 *pll_freq_arr);3981int hl_fw_cpucp_power_get(struct hl_device *hdev, u64 *power);3982void hl_fw_ask_hard_reset_without_linux(struct hl_device *hdev);3983void hl_fw_ask_halt_machine_without_linux(struct hl_device *hdev);3984int hl_fw_init_cpu(struct hl_device *hdev);3985int hl_fw_wait_preboot_ready(struct hl_device *hdev);3986int hl_fw_read_preboot_status(struct hl_device *hdev);3987int hl_fw_dynamic_send_protocol_cmd(struct hl_device *hdev,3988struct fw_load_mgr *fw_loader,3989enum comms_cmd cmd, unsigned int size,3990bool wait_ok, u32 timeout);3991int hl_fw_dram_replaced_row_get(struct hl_device *hdev,3992struct cpucp_hbm_row_info *info);3993int hl_fw_dram_pending_row_get(struct hl_device *hdev, u32 *pend_rows_num);3994int hl_fw_cpucp_engine_core_asid_set(struct hl_device *hdev, u32 asid);3995int hl_fw_send_device_activity(struct hl_device *hdev, bool open);3996int hl_fw_send_soft_reset(struct hl_device *hdev);3997int hl_pci_bars_map(struct hl_device *hdev, const char * const name[3],3998bool is_wc[3]);3999int hl_pci_elbi_read(struct hl_device *hdev, u64 addr, u32 *data);4000int hl_pci_iatu_write(struct hl_device *hdev, u32 addr, u32 data);4001int hl_pci_set_inbound_region(struct hl_device *hdev, u8 region,4002struct hl_inbound_pci_region *pci_region);4003int hl_pci_set_outbound_region(struct hl_device *hdev,4004struct hl_outbound_pci_region *pci_region);4005enum pci_region hl_get_pci_memory_region(struct hl_device *hdev, u64 addr);4006int hl_pci_init(struct hl_device *hdev);4007void hl_pci_fini(struct hl_device *hdev);40084009long hl_fw_get_frequency(struct hl_device *hdev, u32 pll_index, bool curr);4010void hl_fw_set_frequency(struct hl_device *hdev, u32 pll_index, u64 freq);4011int hl_get_temperature(struct hl_device *hdev, int sensor_index, u32 attr, long *value);4012int hl_set_temperature(struct hl_device *hdev, int sensor_index, u32 attr, long value);4013int hl_get_voltage(struct hl_device *hdev, int sensor_index, u32 attr, long *value);4014int hl_get_current(struct hl_device *hdev, int sensor_index, u32 attr, long *value);4015int hl_get_fan_speed(struct hl_device *hdev, int sensor_index, u32 attr, long *value);4016int hl_get_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr, long *value);4017void hl_set_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr, long value);4018long hl_fw_get_max_power(struct hl_device *hdev);4019void hl_fw_set_max_power(struct hl_device *hdev);4020int hl_fw_get_sec_attest_info(struct hl_device *hdev, struct cpucp_sec_attest_info *sec_attest_info,4021u32 nonce);4022int hl_fw_get_dev_info_signed(struct hl_device *hdev,4023struct cpucp_dev_info_signed *dev_info_signed, u32 nonce);4024int hl_set_voltage(struct hl_device *hdev, int sensor_index, u32 attr, long value);4025int hl_set_current(struct hl_device *hdev, int sensor_index, u32 attr, long value);4026int hl_set_power(struct hl_device *hdev, int sensor_index, u32 attr, long value);4027int hl_get_power(struct hl_device *hdev, int sensor_index, u32 attr, long *value);4028int hl_fw_get_clk_rate(struct hl_device *hdev, u32 *cur_clk, u32 *max_clk);4029void hl_fw_set_pll_profile(struct hl_device *hdev);4030void hl_sysfs_add_dev_clk_attr(struct hl_device *hdev, struct attribute_group *dev_clk_attr_grp);4031void hl_sysfs_add_dev_vrm_attr(struct hl_device *hdev, struct attribute_group *dev_vrm_attr_grp);4032int hl_fw_send_generic_request(struct hl_device *hdev, enum hl_passthrough_type sub_opcode,4033dma_addr_t buff, u32 *size);40344035void hw_sob_get(struct hl_hw_sob *hw_sob);4036void hw_sob_put(struct hl_hw_sob *hw_sob);4037void hl_encaps_release_handle_and_put_ctx(struct kref *ref);4038void hl_encaps_release_handle_and_put_sob_ctx(struct kref *ref);4039void hl_hw_queue_encaps_sig_set_sob_info(struct hl_device *hdev,4040struct hl_cs *cs, struct hl_cs_job *job,4041struct hl_cs_compl *cs_cmpl);40424043int hl_dec_init(struct hl_device *hdev);4044void hl_dec_fini(struct hl_device *hdev);4045void hl_dec_ctx_fini(struct hl_ctx *ctx);40464047void hl_release_pending_user_interrupts(struct hl_device *hdev);4048void hl_abort_waiting_for_cs_completions(struct hl_device *hdev);4049int hl_cs_signal_sob_wraparound_handler(struct hl_device *hdev, u32 q_idx,4050struct hl_hw_sob **hw_sob, u32 count, bool encaps_sig);40514052int hl_state_dump(struct hl_device *hdev);4053const char *hl_state_dump_get_sync_name(struct hl_device *hdev, u32 sync_id);4054const char *hl_state_dump_get_monitor_name(struct hl_device *hdev,4055struct hl_mon_state_dump *mon);4056void hl_state_dump_free_sync_to_engine_map(struct hl_sync_to_engine_map *map);4057__printf(4, 5) int hl_snprintf_resize(char **buf, size_t *size, size_t *offset,4058const char *format, ...);4059char *hl_format_as_binary(char *buf, size_t buf_len, u32 n);4060const char *hl_sync_engine_to_string(enum hl_sync_engine_type engine_type);40614062void hl_mem_mgr_init(struct device *dev, struct hl_mem_mgr *mmg);4063void hl_mem_mgr_fini(struct hl_mem_mgr *mmg, struct hl_mem_mgr_fini_stats *stats);4064void hl_mem_mgr_idr_destroy(struct hl_mem_mgr *mmg);4065int hl_mem_mgr_mmap(struct hl_mem_mgr *mmg, struct vm_area_struct *vma,4066void *args);4067struct hl_mmap_mem_buf *hl_mmap_mem_buf_get(struct hl_mem_mgr *mmg,4068u64 handle);4069int hl_mmap_mem_buf_put_handle(struct hl_mem_mgr *mmg, u64 handle);4070int hl_mmap_mem_buf_put(struct hl_mmap_mem_buf *buf);4071struct hl_mmap_mem_buf *4072hl_mmap_mem_buf_alloc(struct hl_mem_mgr *mmg,4073struct hl_mmap_mem_buf_behavior *behavior, gfp_t gfp,4074void *args);4075__printf(2, 3) void hl_engine_data_sprintf(struct engines_data *e, const char *fmt, ...);4076void hl_capture_razwi(struct hl_device *hdev, u64 addr, u16 *engine_id, u16 num_of_engines,4077u8 flags);4078void hl_handle_razwi(struct hl_device *hdev, u64 addr, u16 *engine_id, u16 num_of_engines,4079u8 flags, u64 *event_mask);4080void hl_capture_page_fault(struct hl_device *hdev, u64 addr, u16 eng_id, bool is_pmmu);4081void hl_handle_page_fault(struct hl_device *hdev, u64 addr, u16 eng_id, bool is_pmmu,4082u64 *event_mask);4083void hl_handle_critical_hw_err(struct hl_device *hdev, u16 event_id, u64 *event_mask);4084void hl_handle_fw_err(struct hl_device *hdev, struct hl_info_fw_err_info *info);4085void hl_capture_engine_err(struct hl_device *hdev, u16 engine_id, u16 error_count);4086void hl_enable_err_info_capture(struct hl_error_info *captured_err_info);4087void hl_init_cpu_for_irq(struct hl_device *hdev);4088void hl_set_irq_affinity(struct hl_device *hdev, int irq);4089void hl_eq_heartbeat_event_handle(struct hl_device *hdev);4090void hl_handle_clk_change_event(struct hl_device *hdev, u16 event_type, u64 *event_mask);40914092#ifdef CONFIG_DEBUG_FS40934094int hl_debugfs_device_init(struct hl_device *hdev);4095void hl_debugfs_device_fini(struct hl_device *hdev);4096void hl_debugfs_add_device(struct hl_device *hdev);4097void hl_debugfs_add_file(struct hl_fpriv *hpriv);4098void hl_debugfs_remove_file(struct hl_fpriv *hpriv);4099void hl_debugfs_add_cb(struct hl_cb *cb);4100void hl_debugfs_remove_cb(struct hl_cb *cb);4101void hl_debugfs_add_cs(struct hl_cs *cs);4102void hl_debugfs_remove_cs(struct hl_cs *cs);4103void hl_debugfs_add_job(struct hl_device *hdev, struct hl_cs_job *job);4104void hl_debugfs_remove_job(struct hl_device *hdev, struct hl_cs_job *job);4105void hl_debugfs_add_userptr(struct hl_device *hdev, struct hl_userptr *userptr);4106void hl_debugfs_remove_userptr(struct hl_device *hdev,4107struct hl_userptr *userptr);4108void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx);4109void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx);4110void hl_debugfs_set_state_dump(struct hl_device *hdev, char *data,4111unsigned long length);41124113#else41144115static inline int hl_debugfs_device_init(struct hl_device *hdev)4116{4117return 0;4118}41194120static inline void hl_debugfs_device_fini(struct hl_device *hdev)4121{4122}41234124static inline void hl_debugfs_add_device(struct hl_device *hdev)4125{4126}41274128static inline void hl_debugfs_add_file(struct hl_fpriv *hpriv)4129{4130}41314132static inline void hl_debugfs_remove_file(struct hl_fpriv *hpriv)4133{4134}41354136static inline void hl_debugfs_add_cb(struct hl_cb *cb)4137{4138}41394140static inline void hl_debugfs_remove_cb(struct hl_cb *cb)4141{4142}41434144static inline void hl_debugfs_add_cs(struct hl_cs *cs)4145{4146}41474148static inline void hl_debugfs_remove_cs(struct hl_cs *cs)4149{4150}41514152static inline void hl_debugfs_add_job(struct hl_device *hdev,4153struct hl_cs_job *job)4154{4155}41564157static inline void hl_debugfs_remove_job(struct hl_device *hdev,4158struct hl_cs_job *job)4159{4160}41614162static inline void hl_debugfs_add_userptr(struct hl_device *hdev,4163struct hl_userptr *userptr)4164{4165}41664167static inline void hl_debugfs_remove_userptr(struct hl_device *hdev,4168struct hl_userptr *userptr)4169{4170}41714172static inline void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev,4173struct hl_ctx *ctx)4174{4175}41764177static inline void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev,4178struct hl_ctx *ctx)4179{4180}41814182static inline void hl_debugfs_set_state_dump(struct hl_device *hdev,4183char *data, unsigned long length)4184{4185}41864187#endif41884189/* Security */4190int hl_unsecure_register(struct hl_device *hdev, u32 mm_reg_addr, int offset,4191const u32 pb_blocks[], struct hl_block_glbl_sec sgs_array[],4192int array_size);4193int hl_unsecure_registers(struct hl_device *hdev, const u32 mm_reg_array[],4194int mm_array_size, int offset, const u32 pb_blocks[],4195struct hl_block_glbl_sec sgs_array[], int blocks_array_size);4196void hl_config_glbl_sec(struct hl_device *hdev, const u32 pb_blocks[],4197struct hl_block_glbl_sec sgs_array[], u32 block_offset,4198int array_size);4199void hl_secure_block(struct hl_device *hdev,4200struct hl_block_glbl_sec sgs_array[], int array_size);4201int hl_init_pb_with_mask(struct hl_device *hdev, u32 num_dcores,4202u32 dcore_offset, u32 num_instances, u32 instance_offset,4203const u32 pb_blocks[], u32 blocks_array_size,4204const u32 *regs_array, u32 regs_array_size, u64 mask);4205int hl_init_pb(struct hl_device *hdev, u32 num_dcores, u32 dcore_offset,4206u32 num_instances, u32 instance_offset,4207const u32 pb_blocks[], u32 blocks_array_size,4208const u32 *regs_array, u32 regs_array_size);4209int hl_init_pb_ranges_with_mask(struct hl_device *hdev, u32 num_dcores,4210u32 dcore_offset, u32 num_instances, u32 instance_offset,4211const u32 pb_blocks[], u32 blocks_array_size,4212const struct range *regs_range_array, u32 regs_range_array_size,4213u64 mask);4214int hl_init_pb_ranges(struct hl_device *hdev, u32 num_dcores,4215u32 dcore_offset, u32 num_instances, u32 instance_offset,4216const u32 pb_blocks[], u32 blocks_array_size,4217const struct range *regs_range_array,4218u32 regs_range_array_size);4219int hl_init_pb_single_dcore(struct hl_device *hdev, u32 dcore_offset,4220u32 num_instances, u32 instance_offset,4221const u32 pb_blocks[], u32 blocks_array_size,4222const u32 *regs_array, u32 regs_array_size);4223int hl_init_pb_ranges_single_dcore(struct hl_device *hdev, u32 dcore_offset,4224u32 num_instances, u32 instance_offset,4225const u32 pb_blocks[], u32 blocks_array_size,4226const struct range *regs_range_array,4227u32 regs_range_array_size);4228void hl_ack_pb(struct hl_device *hdev, u32 num_dcores, u32 dcore_offset,4229u32 num_instances, u32 instance_offset,4230const u32 pb_blocks[], u32 blocks_array_size);4231void hl_ack_pb_with_mask(struct hl_device *hdev, u32 num_dcores,4232u32 dcore_offset, u32 num_instances, u32 instance_offset,4233const u32 pb_blocks[], u32 blocks_array_size, u64 mask);4234void hl_ack_pb_single_dcore(struct hl_device *hdev, u32 dcore_offset,4235u32 num_instances, u32 instance_offset,4236const u32 pb_blocks[], u32 blocks_array_size);42374238/* IOCTLs */4239long hl_ioctl_control(struct file *filep, unsigned int cmd, unsigned long arg);4240int hl_info_ioctl(struct drm_device *ddev, void *data, struct drm_file *file_priv);4241int hl_cb_ioctl(struct drm_device *ddev, void *data, struct drm_file *file_priv);4242int hl_cs_ioctl(struct drm_device *ddev, void *data, struct drm_file *file_priv);4243int hl_wait_ioctl(struct drm_device *ddev, void *data, struct drm_file *file_priv);4244int hl_mem_ioctl(struct drm_device *ddev, void *data, struct drm_file *file_priv);4245int hl_debug_ioctl(struct drm_device *ddev, void *data, struct drm_file *file_priv);42464247#endif /* HABANALABSP_H_ */424842494250