Path: blob/master/drivers/accel/habanalabs/common/habanalabs.h
29282 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 593#define HL_DBGFS_CFG_ACCESS_HIST_LEN 2094#define HL_DBGFS_CFG_ACCESS_HIST_TIMEOUT_SEC 2 /* 2s */9596/* Default value for device reset trigger , an invalid value */97#define HL_RESET_TRIGGER_DEFAULT 0xFF9899#define OBJ_NAMES_HASH_TABLE_BITS 7 /* 1 << 7 buckets */100#define SYNC_TO_ENGINE_HASH_TABLE_BITS 7 /* 1 << 7 buckets */101102/* Memory */103#define MEM_HASH_TABLE_BITS 7 /* 1 << 7 buckets */104105/* MMU */106#define MMU_HASH_TABLE_BITS 7 /* 1 << 7 buckets */107108#define TIMESTAMP_FREE_NODES_NUM 512109110/**111* enum hl_mmu_page_table_location - mmu page table location112* @MMU_DR_PGT: page-table is located on device DRAM.113* @MMU_HR_PGT: page-table is located on host memory.114* @MMU_NUM_PGT_LOCATIONS: number of page-table locations currently supported.115*/116enum hl_mmu_page_table_location {117MMU_DR_PGT = 0, /* device-dram-resident MMU PGT */118MMU_HR_PGT, /* host resident MMU PGT */119MMU_NUM_PGT_LOCATIONS /* num of PGT locations */120};121122/*123* HL_RSVD_SOBS 'sync stream' reserved sync objects per QMAN stream124* HL_RSVD_MONS 'sync stream' reserved monitors per QMAN stream125*/126#define HL_RSVD_SOBS 2127#define HL_RSVD_MONS 1128129/*130* HL_COLLECTIVE_RSVD_MSTR_MONS 'collective' reserved monitors per QMAN stream131*/132#define HL_COLLECTIVE_RSVD_MSTR_MONS 2133134#define HL_MAX_SOB_VAL (1 << 15)135136#define IS_POWER_OF_2(n) (n != 0 && ((n & (n - 1)) == 0))137#define IS_MAX_PENDING_CS_VALID(n) (IS_POWER_OF_2(n) && (n > 1))138139#define HL_PCI_NUM_BARS 6140141/* Completion queue entry relates to completed job */142#define HL_COMPLETION_MODE_JOB 0143/* Completion queue entry relates to completed command submission */144#define HL_COMPLETION_MODE_CS 1145146#define HL_MAX_DCORES 8147148/* DMA alloc/free wrappers */149#define hl_asic_dma_alloc_coherent(hdev, size, dma_handle, flags) \150hl_asic_dma_alloc_coherent_caller(hdev, size, dma_handle, flags, __func__)151152#define hl_asic_dma_pool_zalloc(hdev, size, mem_flags, dma_handle) \153hl_asic_dma_pool_zalloc_caller(hdev, size, mem_flags, dma_handle, __func__)154155#define hl_asic_dma_free_coherent(hdev, size, cpu_addr, dma_handle) \156hl_asic_dma_free_coherent_caller(hdev, size, cpu_addr, dma_handle, __func__)157158#define hl_asic_dma_pool_free(hdev, vaddr, dma_addr) \159hl_asic_dma_pool_free_caller(hdev, vaddr, dma_addr, __func__)160161#define hl_dma_map_sgtable(hdev, sgt, dir) \162hl_dma_map_sgtable_caller(hdev, sgt, dir, __func__)163#define hl_dma_unmap_sgtable(hdev, sgt, dir) \164hl_dma_unmap_sgtable_caller(hdev, sgt, dir, __func__)165166/*167* Reset Flags168*169* - HL_DRV_RESET_HARD170* If set do hard reset to all engines. If not set reset just171* compute/DMA engines.172*173* - HL_DRV_RESET_FROM_RESET_THR174* Set if the caller is the hard-reset thread175*176* - HL_DRV_RESET_HEARTBEAT177* Set if reset is due to heartbeat178*179* - HL_DRV_RESET_TDR180* Set if reset is due to TDR181*182* - HL_DRV_RESET_DEV_RELEASE183* Set if reset is due to device release184*185* - HL_DRV_RESET_BYPASS_REQ_TO_FW186* F/W will perform the reset. No need to ask it to reset the device. This is relevant187* only when running with secured f/w188*189* - HL_DRV_RESET_FW_FATAL_ERR190* Set if reset is due to a fatal error from FW191*192* - HL_DRV_RESET_DELAY193* Set if a delay should be added before the reset194*195* - HL_DRV_RESET_FROM_WD_THR196* Set if the caller is the device release watchdog thread197*/198199#define HL_DRV_RESET_HARD (1 << 0)200#define HL_DRV_RESET_FROM_RESET_THR (1 << 1)201#define HL_DRV_RESET_HEARTBEAT (1 << 2)202#define HL_DRV_RESET_TDR (1 << 3)203#define HL_DRV_RESET_DEV_RELEASE (1 << 4)204#define HL_DRV_RESET_BYPASS_REQ_TO_FW (1 << 5)205#define HL_DRV_RESET_FW_FATAL_ERR (1 << 6)206#define HL_DRV_RESET_DELAY (1 << 7)207#define HL_DRV_RESET_FROM_WD_THR (1 << 8)208209/*210* Security211*/212213#define HL_PB_SHARED 1214#define HL_PB_NA 0215#define HL_PB_SINGLE_INSTANCE 1216#define HL_BLOCK_SIZE 0x1000217#define HL_BLOCK_GLBL_ERR_MASK 0xF40218#define HL_BLOCK_GLBL_ERR_ADDR 0xF44219#define HL_BLOCK_GLBL_ERR_CAUSE 0xF48220#define HL_BLOCK_GLBL_SEC_OFFS 0xF80221#define HL_BLOCK_GLBL_SEC_SIZE (HL_BLOCK_SIZE - HL_BLOCK_GLBL_SEC_OFFS)222#define HL_BLOCK_GLBL_SEC_LEN (HL_BLOCK_GLBL_SEC_SIZE / sizeof(u32))223#define UNSET_GLBL_SEC_BIT(array, b) ((array)[((b) / 32)] |= (1 << ((b) % 32)))224225enum hl_protection_levels {226SECURED_LVL,227PRIVILEGED_LVL,228NON_SECURED_LVL229};230231/**232* struct iterate_module_ctx - HW module iterator233* @fn: function to apply to each HW module instance234* @data: optional internal data to the function iterator235* @rc: return code for optional use of iterator/iterator-caller236*/237struct iterate_module_ctx {238/*239* callback for the HW module iterator240* @hdev: pointer to the habanalabs device structure241* @block: block (ASIC specific definition can be dcore/hdcore)242* @inst: HW module instance within the block243* @offset: current HW module instance offset from the 1-st HW module instance244* in the 1-st block245* @ctx: the iterator context.246*/247void (*fn)(struct hl_device *hdev, int block, int inst, u32 offset,248struct iterate_module_ctx *ctx);249void *data;250int rc;251};252253struct hl_block_glbl_sec {254u32 sec_array[HL_BLOCK_GLBL_SEC_LEN];255};256257#define HL_MAX_SOBS_PER_MONITOR 8258259/**260* struct hl_gen_wait_properties - properties for generating a wait CB261* @data: command buffer262* @q_idx: queue id is used to extract fence register address263* @size: offset in command buffer264* @sob_base: SOB base to use in this wait CB265* @sob_val: SOB value to wait for266* @mon_id: monitor to use in this wait CB267* @sob_mask: each bit represents a SOB offset from sob_base to be used268*/269struct hl_gen_wait_properties {270void *data;271u32 q_idx;272u32 size;273u16 sob_base;274u16 sob_val;275u16 mon_id;276u8 sob_mask;277};278279/**280* struct pgt_info - MMU hop page info.281* @node: hash linked-list node for the pgts on host (shadow pgts for device resident MMU and282* actual pgts for host resident MMU).283* @phys_addr: physical address of the pgt.284* @virt_addr: host virtual address of the pgt (see above device/host resident).285* @shadow_addr: shadow hop in the host for device resident MMU.286* @ctx: pointer to the owner ctx.287* @num_of_ptes: indicates how many ptes are used in the pgt. used only for dynamically288* allocated HOPs (all HOPs but HOP0)289*290* The MMU page tables hierarchy can be placed either on the device's DRAM (in which case shadow291* pgts will be stored on host memory) or on host memory (in which case no shadow is required).292*293* When a new level (hop) is needed during mapping this structure will be used to describe294* the newly allocated hop as well as to track number of PTEs in it.295* During unmapping, if no valid PTEs remained in the page of a newly allocated hop, it is296* freed with its pgt_info structure.297*/298struct pgt_info {299struct hlist_node node;300u64 phys_addr;301u64 virt_addr;302u64 shadow_addr;303struct hl_ctx *ctx;304int num_of_ptes;305};306307/**308* enum hl_pci_match_mode - pci match mode per region309* @PCI_ADDRESS_MATCH_MODE: address match mode310* @PCI_BAR_MATCH_MODE: bar match mode311*/312enum hl_pci_match_mode {313PCI_ADDRESS_MATCH_MODE,314PCI_BAR_MATCH_MODE315};316317/**318* enum hl_fw_component - F/W components to read version through registers.319* @FW_COMP_BOOT_FIT: boot fit.320* @FW_COMP_PREBOOT: preboot.321* @FW_COMP_LINUX: linux.322*/323enum hl_fw_component {324FW_COMP_BOOT_FIT,325FW_COMP_PREBOOT,326FW_COMP_LINUX,327};328329/**330* enum hl_fw_types - F/W types present in the system331* @FW_TYPE_NONE: no FW component indication332* @FW_TYPE_LINUX: Linux image for device CPU333* @FW_TYPE_BOOT_CPU: Boot image for device CPU334* @FW_TYPE_PREBOOT_CPU: Indicates pre-loaded CPUs are present in the system335* (preboot, ppboot etc...)336* @FW_TYPE_ALL_TYPES: Mask for all types337*/338enum hl_fw_types {339FW_TYPE_NONE = 0x0,340FW_TYPE_LINUX = 0x1,341FW_TYPE_BOOT_CPU = 0x2,342FW_TYPE_PREBOOT_CPU = 0x4,343FW_TYPE_ALL_TYPES =344(FW_TYPE_LINUX | FW_TYPE_BOOT_CPU | FW_TYPE_PREBOOT_CPU)345};346347/**348* enum hl_queue_type - Supported QUEUE types.349* @QUEUE_TYPE_NA: queue is not available.350* @QUEUE_TYPE_EXT: external queue which is a DMA channel that may access the351* host.352* @QUEUE_TYPE_INT: internal queue that performs DMA inside the device's353* memories and/or operates the compute engines.354* @QUEUE_TYPE_CPU: S/W queue for communication with the device's CPU.355* @QUEUE_TYPE_HW: queue of DMA and compute engines jobs, for which completion356* notifications are sent by H/W.357*/358enum hl_queue_type {359QUEUE_TYPE_NA,360QUEUE_TYPE_EXT,361QUEUE_TYPE_INT,362QUEUE_TYPE_CPU,363QUEUE_TYPE_HW364};365366enum hl_cs_type {367CS_TYPE_DEFAULT,368CS_TYPE_SIGNAL,369CS_TYPE_WAIT,370CS_TYPE_COLLECTIVE_WAIT,371CS_RESERVE_SIGNALS,372CS_UNRESERVE_SIGNALS,373CS_TYPE_ENGINE_CORE,374CS_TYPE_ENGINES,375CS_TYPE_FLUSH_PCI_HBW_WRITES,376};377378/*379* struct hl_inbound_pci_region - inbound region descriptor380* @mode: pci match mode for this region381* @addr: region target address382* @size: region size in bytes383* @offset_in_bar: offset within bar (address match mode)384* @bar: bar id385*/386struct hl_inbound_pci_region {387enum hl_pci_match_mode mode;388u64 addr;389u64 size;390u64 offset_in_bar;391u8 bar;392};393394/*395* struct hl_outbound_pci_region - outbound region descriptor396* @addr: region target address397* @size: region size in bytes398*/399struct hl_outbound_pci_region {400u64 addr;401u64 size;402};403404/*405* enum queue_cb_alloc_flags - Indicates queue support for CBs that406* allocated by Kernel or by User407* @CB_ALLOC_KERNEL: support only CBs that allocated by Kernel408* @CB_ALLOC_USER: support only CBs that allocated by User409*/410enum queue_cb_alloc_flags {411CB_ALLOC_KERNEL = 0x1,412CB_ALLOC_USER = 0x2413};414415/*416* struct hl_hw_sob - H/W SOB info.417* @hdev: habanalabs device structure.418* @kref: refcount of this SOB. The SOB will reset once the refcount is zero.419* @sob_id: id of this SOB.420* @sob_addr: the sob offset from the base address.421* @q_idx: the H/W queue that uses this SOB.422* @need_reset: reset indication set when switching to the other sob.423*/424struct hl_hw_sob {425struct hl_device *hdev;426struct kref kref;427u32 sob_id;428u32 sob_addr;429u32 q_idx;430bool need_reset;431};432433enum hl_collective_mode {434HL_COLLECTIVE_NOT_SUPPORTED = 0x0,435HL_COLLECTIVE_MASTER = 0x1,436HL_COLLECTIVE_SLAVE = 0x2437};438439/**440* struct hw_queue_properties - queue information.441* @type: queue type.442* @cb_alloc_flags: bitmap which indicates if the hw queue supports CB443* that allocated by the Kernel driver and therefore,444* a CB handle can be provided for jobs on this queue.445* Otherwise, a CB address must be provided.446* @collective_mode: collective mode of current queue447* @q_dram_bd_address: PQ dram address, used when PQ need to reside in DRAM.448* @driver_only: true if only the driver is allowed to send a job to this queue,449* false otherwise.450* @binned: True if the queue is binned out and should not be used451* @supports_sync_stream: True if queue supports sync stream452* @dram_bd: True if the bd should be copied to dram, needed for PQ which has been allocated on dram453*/454struct hw_queue_properties {455enum hl_queue_type type;456enum queue_cb_alloc_flags cb_alloc_flags;457enum hl_collective_mode collective_mode;458u64 q_dram_bd_address;459u8 driver_only;460u8 binned;461u8 supports_sync_stream;462u8 dram_bd;463};464465/**466* enum vm_type - virtual memory mapping request information.467* @VM_TYPE_USERPTR: mapping of user memory to device virtual address.468* @VM_TYPE_PHYS_PACK: mapping of DRAM memory to device virtual address.469*/470enum vm_type {471VM_TYPE_USERPTR = 0x1,472VM_TYPE_PHYS_PACK = 0x2473};474475/**476* enum mmu_op_flags - mmu operation relevant information.477* @MMU_OP_USERPTR: operation on user memory (host resident).478* @MMU_OP_PHYS_PACK: operation on DRAM (device resident).479* @MMU_OP_CLEAR_MEMCACHE: operation has to clear memcache.480* @MMU_OP_SKIP_LOW_CACHE_INV: operation is allowed to skip parts of cache invalidation.481*/482enum mmu_op_flags {483MMU_OP_USERPTR = 0x1,484MMU_OP_PHYS_PACK = 0x2,485MMU_OP_CLEAR_MEMCACHE = 0x4,486MMU_OP_SKIP_LOW_CACHE_INV = 0x8,487};488489490/**491* enum hl_device_hw_state - H/W device state. use this to understand whether492* to do reset before hw_init or not493* @HL_DEVICE_HW_STATE_CLEAN: H/W state is clean. i.e. after hard reset494* @HL_DEVICE_HW_STATE_DIRTY: H/W state is dirty. i.e. we started to execute495* hw_init496*/497enum hl_device_hw_state {498HL_DEVICE_HW_STATE_CLEAN = 0,499HL_DEVICE_HW_STATE_DIRTY500};501502#define HL_MMU_VA_ALIGNMENT_NOT_NEEDED 0503504/**505* struct hl_mmu_properties - ASIC specific MMU address translation properties.506* @start_addr: virtual start address of the memory region.507* @end_addr: virtual end address of the memory region.508* @hop_shifts: array holds HOPs shifts.509* @hop_masks: array holds HOPs masks.510* @last_mask: mask to get the bit indicating this is the last hop.511* @pgt_size: size for page tables.512* @supported_pages_mask: bitmask for supported page size (relevant only for MMUs513* supporting multiple page size).514* @page_size: default page size used to allocate memory.515* @num_hops: The amount of hops supported by the translation table.516* @hop_table_size: HOP table size.517* @hop0_tables_total_size: total size for all HOP0 tables.518* @host_resident: Should the MMU page table reside in host memory or in the519* device DRAM.520*/521struct hl_mmu_properties {522u64 start_addr;523u64 end_addr;524u64 hop_shifts[MMU_HOP_MAX];525u64 hop_masks[MMU_HOP_MAX];526u64 last_mask;527u64 pgt_size;528u64 supported_pages_mask;529u32 page_size;530u32 num_hops;531u32 hop_table_size;532u32 hop0_tables_total_size;533u8 host_resident;534};535536/**537* struct hl_hints_range - hint addresses reserved va range.538* @start_addr: start address of the va range.539* @end_addr: end address of the va range.540*/541struct hl_hints_range {542u64 start_addr;543u64 end_addr;544};545546/**547* struct asic_fixed_properties - ASIC specific immutable properties.548* @hw_queues_props: H/W queues properties.549* @special_blocks: points to an array containing special blocks info.550* @skip_special_blocks_cfg: special blocks skip configs.551* @cpucp_info: received various information from CPU-CP regarding the H/W, e.g.552* available sensors.553* @uboot_ver: F/W U-boot version.554* @preboot_ver: F/W Preboot version.555* @dmmu: DRAM MMU address translation properties.556* @pmmu: PCI (host) MMU address translation properties.557* @pmmu_huge: PCI (host) MMU address translation properties for memory558* allocated with huge pages.559* @hints_dram_reserved_va_range: dram hint addresses reserved range.560* @hints_host_reserved_va_range: host hint addresses reserved range.561* @hints_host_hpage_reserved_va_range: host huge page hint addresses reserved range.562* @sram_base_address: SRAM physical start address.563* @sram_end_address: SRAM physical end address.564* @sram_user_base_address - SRAM physical start address for user access.565* @dram_base_address: DRAM physical start address.566* @dram_end_address: DRAM physical end address.567* @dram_user_base_address: DRAM physical start address for user access.568* @dram_size: DRAM total size.569* @dram_pci_bar_size: size of PCI bar towards DRAM.570* @max_power_default: max power of the device after reset.571* @dc_power_default: power consumed by the device in mode idle.572* @dram_size_for_default_page_mapping: DRAM size needed to map to avoid page573* fault.574* @pcie_dbi_base_address: Base address of the PCIE_DBI block.575* @pcie_aux_dbi_reg_addr: Address of the PCIE_AUX DBI register.576* @mmu_pgt_addr: base physical address in DRAM of MMU page tables.577* @mmu_dram_default_page_addr: DRAM default page physical address.578* @tpc_enabled_mask: which TPCs are enabled.579* @tpc_binning_mask: which TPCs are binned. 0 means usable and 1 means binned.580* @dram_enabled_mask: which DRAMs are enabled.581* @dram_binning_mask: which DRAMs are binned. 0 means usable, 1 means binned.582* @dram_hints_align_mask: dram va hint addresses alignment mask which is used583* for hints validity check.584* @cfg_base_address: config space base address.585* @mmu_cache_mng_addr: address of the MMU cache.586* @mmu_cache_mng_size: size of the MMU cache.587* @device_dma_offset_for_host_access: the offset to add to host DMA addresses588* to enable the device to access them.589* @host_base_address: host physical start address for host DMA from device590* @host_end_address: host physical end address for host DMA from device591* @max_freq_value: current max clk frequency.592* @engine_core_interrupt_reg_addr: interrupt register address for engine core to use593* in order to raise events toward FW.594* @clk_pll_index: clock PLL index that specify which PLL determines the clock595* we display to the user596* @mmu_pgt_size: MMU page tables total size.597* @mmu_pte_size: PTE size in MMU page tables.598* @dram_page_size: The DRAM physical page size.599* @cfg_size: configuration space size on SRAM.600* @sram_size: total size of SRAM.601* @max_asid: maximum number of open contexts (ASIDs).602* @num_of_events: number of possible internal H/W IRQs.603* @psoc_pci_pll_nr: PCI PLL NR value.604* @psoc_pci_pll_nf: PCI PLL NF value.605* @psoc_pci_pll_od: PCI PLL OD value.606* @psoc_pci_pll_div_factor: PCI PLL DIV FACTOR 1 value.607* @psoc_timestamp_frequency: frequency of the psoc timestamp clock.608* @high_pll: high PLL frequency used by the device.609* @cb_pool_cb_cnt: number of CBs in the CB pool.610* @cb_pool_cb_size: size of each CB in the CB pool.611* @decoder_enabled_mask: which decoders are enabled.612* @decoder_binning_mask: which decoders are binned, 0 means usable and 1 means binned.613* @rotator_enabled_mask: which rotators are enabled.614* @edma_enabled_mask: which EDMAs are enabled.615* @edma_binning_mask: which EDMAs are binned, 0 means usable and 1 means616* binned (at most one binned DMA).617* @max_pending_cs: maximum of concurrent pending command submissions618* @max_queues: maximum amount of queues in the system619* @fw_preboot_cpu_boot_dev_sts0: bitmap representation of preboot cpu620* capabilities reported by FW, bit description621* can be found in CPU_BOOT_DEV_STS0622* @fw_preboot_cpu_boot_dev_sts1: bitmap representation of preboot cpu623* capabilities reported by FW, bit description624* can be found in CPU_BOOT_DEV_STS1625* @fw_bootfit_cpu_boot_dev_sts0: bitmap representation of boot cpu security626* status reported by FW, bit description can be627* found in CPU_BOOT_DEV_STS0628* @fw_bootfit_cpu_boot_dev_sts1: bitmap representation of boot cpu security629* status reported by FW, bit description can be630* found in CPU_BOOT_DEV_STS1631* @fw_app_cpu_boot_dev_sts0: bitmap representation of application security632* status reported by FW, bit description can be633* found in CPU_BOOT_DEV_STS0634* @fw_app_cpu_boot_dev_sts1: bitmap representation of application security635* status reported by FW, bit description can be636* found in CPU_BOOT_DEV_STS1637* @max_dec: maximum number of decoders638* @hmmu_hif_enabled_mask: mask of HMMUs/HIFs that are not isolated (enabled)639* 1- enabled, 0- isolated.640* @faulty_dram_cluster_map: mask of faulty DRAM cluster.641* 1- faulty cluster, 0- good cluster.642* @xbar_edge_enabled_mask: mask of XBAR_EDGEs that are not isolated (enabled)643* 1- enabled, 0- isolated.644* @device_mem_alloc_default_page_size: may be different than dram_page_size only for ASICs for645* which the property supports_user_set_page_size is true646* (i.e. the DRAM supports multiple page sizes), otherwise647* it will shall be equal to dram_page_size.648* @num_engine_cores: number of engine cpu cores.649* @max_num_of_engines: maximum number of all engines in the ASIC.650* @num_of_special_blocks: special_blocks array size.651* @glbl_err_max_cause_num: global err max cause number.652* @hbw_flush_reg: register to read to generate HBW flush. value of 0 means HBW flush is653* not supported.654* @reserved_fw_mem_size: size of dram memory reserved for FW.655* @fw_event_queue_size: queue size for events from CPU-CP.656* A value of 0 means using the default HL_EQ_SIZE_IN_BYTES value.657* @collective_first_sob: first sync object available for collective use658* @collective_first_mon: first monitor available for collective use659* @sync_stream_first_sob: first sync object available for sync stream use660* @sync_stream_first_mon: first monitor available for sync stream use661* @first_available_user_sob: first sob available for the user662* @first_available_user_mon: first monitor available for the user663* @first_available_user_interrupt: first available interrupt reserved for the user664* @first_available_cq: first available CQ for the user.665* @user_interrupt_count: number of user interrupts.666* @user_dec_intr_count: number of decoder interrupts exposed to user.667* @tpc_interrupt_id: interrupt id for TPC to use in order to raise events towards the host.668* @eq_interrupt_id: interrupt id for EQ, uses to synchronize EQ interrupts in hard-reset.669* @cache_line_size: device cache line size.670* @server_type: Server type that the ASIC is currently installed in.671* The value is according to enum hl_server_type in uapi file.672* @completion_queues_count: number of completion queues.673* @completion_mode: 0 - job based completion, 1 - cs based completion674* @mme_master_slave_mode: 0 - Each MME works independently, 1 - MME works675* in Master/Slave mode676* @fw_security_enabled: true if security measures are enabled in firmware,677* false otherwise678* @fw_cpu_boot_dev_sts0_valid: status bits are valid and can be fetched from679* BOOT_DEV_STS0680* @fw_cpu_boot_dev_sts1_valid: status bits are valid and can be fetched from681* BOOT_DEV_STS1682* @dram_supports_virtual_memory: is there an MMU towards the DRAM683* @hard_reset_done_by_fw: true if firmware is handling hard reset flow684* @num_functional_hbms: number of functional HBMs in each DCORE.685* @hints_range_reservation: device support hint addresses range reservation.686* @iatu_done_by_fw: true if iATU configuration is being done by FW.687* @dynamic_fw_load: is dynamic FW load is supported.688* @gic_interrupts_enable: true if FW is not blocking GIC controller,689* false otherwise.690* @use_get_power_for_reset_history: To support backward compatibility for Goya691* and Gaudi692* @supports_compute_reset: is a reset which is not a hard-reset supported by this asic.693* @allow_inference_soft_reset: true if the ASIC supports soft reset that is694* initiated by user or TDR. This is only true695* in inference ASICs, as there is no real-world696* use-case of doing soft-reset in training (due697* to the fact that training runs on multiple698* devices)699* @configurable_stop_on_err: is stop-on-error option configurable via debugfs.700* @set_max_power_on_device_init: true if need to set max power in F/W on device init.701* @supports_user_set_page_size: true if user can set the allocation page size.702* @dma_mask: the dma mask to be set for this device.703* @supports_advanced_cpucp_rc: true if new cpucp opcodes are supported.704* @supports_engine_modes: true if changing engines/engine_cores modes is supported.705* @support_dynamic_resereved_fw_size: true if we support dynamic reserved size for fw.706* @supports_nvme: indicates whether the asic supports NVMe P2P DMA.707*/708struct asic_fixed_properties {709struct hw_queue_properties *hw_queues_props;710struct hl_special_block_info *special_blocks;711struct hl_skip_blocks_cfg skip_special_blocks_cfg;712struct cpucp_info cpucp_info;713char uboot_ver[VERSION_MAX_LEN];714char preboot_ver[VERSION_MAX_LEN];715struct hl_mmu_properties dmmu;716struct hl_mmu_properties pmmu;717struct hl_mmu_properties pmmu_huge;718struct hl_hints_range hints_dram_reserved_va_range;719struct hl_hints_range hints_host_reserved_va_range;720struct hl_hints_range hints_host_hpage_reserved_va_range;721u64 sram_base_address;722u64 sram_end_address;723u64 sram_user_base_address;724u64 dram_base_address;725u64 dram_end_address;726u64 dram_user_base_address;727u64 dram_size;728u64 dram_pci_bar_size;729u64 max_power_default;730u64 dc_power_default;731u64 dram_size_for_default_page_mapping;732u64 pcie_dbi_base_address;733u64 pcie_aux_dbi_reg_addr;734u64 mmu_pgt_addr;735u64 mmu_dram_default_page_addr;736u64 tpc_enabled_mask;737u64 tpc_binning_mask;738u64 dram_enabled_mask;739u64 dram_binning_mask;740u64 dram_hints_align_mask;741u64 cfg_base_address;742u64 mmu_cache_mng_addr;743u64 mmu_cache_mng_size;744u64 device_dma_offset_for_host_access;745u64 host_base_address;746u64 host_end_address;747u64 max_freq_value;748u64 engine_core_interrupt_reg_addr;749u32 clk_pll_index;750u32 mmu_pgt_size;751u32 mmu_pte_size;752u32 dram_page_size;753u32 cfg_size;754u32 sram_size;755u32 max_asid;756u32 num_of_events;757u32 psoc_pci_pll_nr;758u32 psoc_pci_pll_nf;759u32 psoc_pci_pll_od;760u32 psoc_pci_pll_div_factor;761u32 psoc_timestamp_frequency;762u32 high_pll;763u32 cb_pool_cb_cnt;764u32 cb_pool_cb_size;765u32 decoder_enabled_mask;766u32 decoder_binning_mask;767u32 rotator_enabled_mask;768u32 edma_enabled_mask;769u32 edma_binning_mask;770u32 max_pending_cs;771u32 max_queues;772u32 fw_preboot_cpu_boot_dev_sts0;773u32 fw_preboot_cpu_boot_dev_sts1;774u32 fw_bootfit_cpu_boot_dev_sts0;775u32 fw_bootfit_cpu_boot_dev_sts1;776u32 fw_app_cpu_boot_dev_sts0;777u32 fw_app_cpu_boot_dev_sts1;778u32 max_dec;779u32 hmmu_hif_enabled_mask;780u32 faulty_dram_cluster_map;781u32 xbar_edge_enabled_mask;782u32 device_mem_alloc_default_page_size;783u32 num_engine_cores;784u32 max_num_of_engines;785u32 num_of_special_blocks;786u32 glbl_err_max_cause_num;787u32 hbw_flush_reg;788u32 reserved_fw_mem_size;789u32 fw_event_queue_size;790u16 collective_first_sob;791u16 collective_first_mon;792u16 sync_stream_first_sob;793u16 sync_stream_first_mon;794u16 first_available_user_sob[HL_MAX_DCORES];795u16 first_available_user_mon[HL_MAX_DCORES];796u16 first_available_user_interrupt;797u16 first_available_cq[HL_MAX_DCORES];798u16 user_interrupt_count;799u16 user_dec_intr_count;800u16 tpc_interrupt_id;801u16 eq_interrupt_id;802u16 cache_line_size;803u16 server_type;804u8 completion_queues_count;805u8 completion_mode;806u8 mme_master_slave_mode;807u8 fw_security_enabled;808u8 fw_cpu_boot_dev_sts0_valid;809u8 fw_cpu_boot_dev_sts1_valid;810u8 dram_supports_virtual_memory;811u8 hard_reset_done_by_fw;812u8 num_functional_hbms;813u8 hints_range_reservation;814u8 iatu_done_by_fw;815u8 dynamic_fw_load;816u8 gic_interrupts_enable;817u8 use_get_power_for_reset_history;818u8 supports_compute_reset;819u8 allow_inference_soft_reset;820u8 configurable_stop_on_err;821u8 set_max_power_on_device_init;822u8 supports_user_set_page_size;823u8 dma_mask;824u8 supports_advanced_cpucp_rc;825u8 supports_engine_modes;826u8 support_dynamic_resereved_fw_size;827u8 supports_nvme;828};829830/**831* struct hl_fence - software synchronization primitive832* @completion: fence is implemented using completion833* @refcount: refcount for this fence834* @cs_sequence: sequence of the corresponding command submission835* @stream_master_qid_map: streams masters QID bitmap to represent all streams836* masters QIDs that multi cs is waiting on837* @error: mark this fence with error838* @timestamp: timestamp upon completion839* @mcs_handling_done: indicates that corresponding command submission has840* finished msc handling, this does not mean it was part841* of the mcs842*/843struct hl_fence {844struct completion completion;845struct kref refcount;846u64 cs_sequence;847u32 stream_master_qid_map;848int error;849ktime_t timestamp;850u8 mcs_handling_done;851};852853/**854* struct hl_cs_compl - command submission completion object.855* @base_fence: hl fence object.856* @lock: spinlock to protect fence.857* @hdev: habanalabs device structure.858* @hw_sob: the H/W SOB used in this signal/wait CS.859* @encaps_sig_hdl: encaps signals handler.860* @cs_seq: command submission sequence number.861* @type: type of the CS - signal/wait.862* @sob_val: the SOB value that is used in this signal/wait CS.863* @sob_group: the SOB group that is used in this collective wait CS.864* @encaps_signals: indication whether it's a completion object of cs with865* encaps signals or not.866*/867struct hl_cs_compl {868struct hl_fence base_fence;869spinlock_t lock;870struct hl_device *hdev;871struct hl_hw_sob *hw_sob;872struct hl_cs_encaps_sig_handle *encaps_sig_hdl;873u64 cs_seq;874enum hl_cs_type type;875u16 sob_val;876u16 sob_group;877bool encaps_signals;878};879880/*881* Command Buffers882*/883884/**885* struct hl_ts_buff - describes a timestamp buffer.886* @kernel_buff_address: Holds the internal buffer's kernel virtual address.887* @user_buff_address: Holds the user buffer's kernel virtual address.888* @kernel_buff_size: Holds the internal kernel buffer size.889*/890struct hl_ts_buff {891void *kernel_buff_address;892void *user_buff_address;893u32 kernel_buff_size;894};895896struct hl_mmap_mem_buf;897898/**899* struct hl_mem_mgr - describes unified memory manager for mappable memory chunks.900* @dev: back pointer to the owning device901* @lock: protects handles902* @handles: an idr holding all active handles to the memory buffers in the system.903*/904struct hl_mem_mgr {905struct device *dev;906spinlock_t lock;907struct idr handles;908};909910/**911* struct hl_mem_mgr_fini_stats - describes statistics returned during memory manager teardown.912* @n_busy_cb: the amount of CB handles that could not be removed913* @n_busy_ts: the amount of TS handles that could not be removed914* @n_busy_other: the amount of any other type of handles that could not be removed915*/916struct hl_mem_mgr_fini_stats {917u32 n_busy_cb;918u32 n_busy_ts;919u32 n_busy_other;920};921922/**923* struct hl_mmap_mem_buf_behavior - describes unified memory manager buffer behavior924* @topic: string identifier used for logging925* @mem_id: memory type identifier, embedded in the handle and used to identify926* the memory type by handle.927* @alloc: callback executed on buffer allocation, shall allocate the memory,928* set it under buffer private, and set mappable size.929* @mmap: callback executed on mmap, must map the buffer to vma930* @release: callback executed on release, must free the resources used by the buffer931*/932struct hl_mmap_mem_buf_behavior {933const char *topic;934u64 mem_id;935936int (*alloc)(struct hl_mmap_mem_buf *buf, gfp_t gfp, void *args);937int (*mmap)(struct hl_mmap_mem_buf *buf, struct vm_area_struct *vma, void *args);938void (*release)(struct hl_mmap_mem_buf *buf);939};940941/**942* struct hl_mmap_mem_buf - describes a single unified memory buffer943* @behavior: buffer behavior944* @mmg: back pointer to the unified memory manager945* @refcount: reference counter for buffer users946* @private: pointer to buffer behavior private data947* @mmap: atomic boolean indicating whether or not the buffer is mapped right now948* @real_mapped_size: the actual size of buffer mapped, after part of it may be released,949* may change at runtime.950* @mappable_size: the original mappable size of the buffer, does not change after951* the allocation.952* @handle: the buffer id in mmg handles store953*/954struct hl_mmap_mem_buf {955struct hl_mmap_mem_buf_behavior *behavior;956struct hl_mem_mgr *mmg;957struct kref refcount;958void *private;959atomic_t mmap;960u64 real_mapped_size;961u64 mappable_size;962u64 handle;963};964965/**966* struct hl_cb - describes a Command Buffer.967* @hdev: pointer to device this CB belongs to.968* @ctx: pointer to the CB owner's context.969* @buf: back pointer to the parent mappable memory buffer970* @debugfs_list: node in debugfs list of command buffers.971* @pool_list: node in pool list of command buffers.972* @kernel_address: Holds the CB's kernel virtual address.973* @virtual_addr: Holds the CB's virtual address.974* @bus_address: Holds the CB's DMA address.975* @size: holds the CB's size.976* @roundup_size: holds the cb size after roundup to page size.977* @cs_cnt: holds number of CS that this CB participates in.978* @is_handle_destroyed: atomic boolean indicating whether or not the CB handle was destroyed.979* @is_pool: true if CB was acquired from the pool, false otherwise.980* @is_internal: internally allocated981* @is_mmu_mapped: true if the CB is mapped to the device's MMU.982*/983struct hl_cb {984struct hl_device *hdev;985struct hl_ctx *ctx;986struct hl_mmap_mem_buf *buf;987struct list_head debugfs_list;988struct list_head pool_list;989void *kernel_address;990u64 virtual_addr;991dma_addr_t bus_address;992u32 size;993u32 roundup_size;994atomic_t cs_cnt;995atomic_t is_handle_destroyed;996u8 is_pool;997u8 is_internal;998u8 is_mmu_mapped;999};100010011002/*1003* QUEUES1004*/10051006struct hl_cs_job;10071008/* Queue length of external and HW queues */1009#define HL_QUEUE_LENGTH 40961010#define HL_QUEUE_SIZE_IN_BYTES (HL_QUEUE_LENGTH * HL_BD_SIZE)10111012#if (HL_MAX_JOBS_PER_CS > HL_QUEUE_LENGTH)1013#error "HL_QUEUE_LENGTH must be greater than HL_MAX_JOBS_PER_CS"1014#endif10151016/* HL_CQ_LENGTH is in units of struct hl_cq_entry */1017#define HL_CQ_LENGTH HL_QUEUE_LENGTH1018#define HL_CQ_SIZE_IN_BYTES (HL_CQ_LENGTH * HL_CQ_ENTRY_SIZE)10191020/* Must be power of 2 */1021#define HL_EQ_LENGTH 641022#define HL_EQ_SIZE_IN_BYTES (HL_EQ_LENGTH * HL_EQ_ENTRY_SIZE)10231024/* Host <-> CPU-CP shared memory size */1025#define HL_CPU_ACCESSIBLE_MEM_SIZE SZ_2M10261027/**1028* struct hl_sync_stream_properties -1029* describes a H/W queue sync stream properties1030* @hw_sob: array of the used H/W SOBs by this H/W queue.1031* @next_sob_val: the next value to use for the currently used SOB.1032* @base_sob_id: the base SOB id of the SOBs used by this queue.1033* @base_mon_id: the base MON id of the MONs used by this queue.1034* @collective_mstr_mon_id: the MON ids of the MONs used by this master queue1035* in order to sync with all slave queues.1036* @collective_slave_mon_id: the MON id used by this slave queue in order to1037* sync with its master queue.1038* @collective_sob_id: current SOB id used by this collective slave queue1039* to signal its collective master queue upon completion.1040* @curr_sob_offset: the id offset to the currently used SOB from the1041* HL_RSVD_SOBS that are being used by this queue.1042*/1043struct hl_sync_stream_properties {1044struct hl_hw_sob hw_sob[HL_RSVD_SOBS];1045u16 next_sob_val;1046u16 base_sob_id;1047u16 base_mon_id;1048u16 collective_mstr_mon_id[HL_COLLECTIVE_RSVD_MSTR_MONS];1049u16 collective_slave_mon_id;1050u16 collective_sob_id;1051u8 curr_sob_offset;1052};10531054/**1055* struct hl_encaps_signals_mgr - describes sync stream encapsulated signals1056* handlers manager1057* @lock: protects handles.1058* @handles: an idr to hold all encapsulated signals handles.1059*/1060struct hl_encaps_signals_mgr {1061spinlock_t lock;1062struct idr handles;1063};10641065/**1066* struct hl_hw_queue - describes a H/W transport queue.1067* @shadow_queue: pointer to a shadow queue that holds pointers to jobs.1068* @sync_stream_prop: sync stream queue properties1069* @queue_type: type of queue.1070* @collective_mode: collective mode of current queue1071* @kernel_address: holds the queue's kernel virtual address.1072* @bus_address: holds the queue's DMA address.1073* @pq_dram_address: hold the dram address when the PQ is allocated, used when dram_bd is true in1074* queue properites.1075* @pi: holds the queue's pi value.1076* @ci: holds the queue's ci value, AS CALCULATED BY THE DRIVER (not real ci).1077* @hw_queue_id: the id of the H/W queue.1078* @cq_id: the id for the corresponding CQ for this H/W queue.1079* @msi_vec: the IRQ number of the H/W queue.1080* @int_queue_len: length of internal queue (number of entries).1081* @valid: is the queue valid (we have array of 32 queues, not all of them1082* exist).1083* @supports_sync_stream: True if queue supports sync stream1084* @dram_bd: True if the bd should be copied to dram, needed for PQ which has been allocated on dram1085*/1086struct hl_hw_queue {1087struct hl_cs_job **shadow_queue;1088struct hl_sync_stream_properties sync_stream_prop;1089enum hl_queue_type queue_type;1090enum hl_collective_mode collective_mode;1091void *kernel_address;1092dma_addr_t bus_address;1093u64 pq_dram_address;1094u32 pi;1095atomic_t ci;1096u32 hw_queue_id;1097u32 cq_id;1098u32 msi_vec;1099u16 int_queue_len;1100u8 valid;1101u8 supports_sync_stream;1102u8 dram_bd;1103};11041105/**1106* struct hl_cq - describes a completion queue1107* @hdev: pointer to the device structure1108* @kernel_address: holds the queue's kernel virtual address1109* @bus_address: holds the queue's DMA address1110* @cq_idx: completion queue index in array1111* @hw_queue_id: the id of the matching H/W queue1112* @ci: ci inside the queue1113* @pi: pi inside the queue1114* @free_slots_cnt: counter of free slots in queue1115*/1116struct hl_cq {1117struct hl_device *hdev;1118void *kernel_address;1119dma_addr_t bus_address;1120u32 cq_idx;1121u32 hw_queue_id;1122u32 ci;1123u32 pi;1124atomic_t free_slots_cnt;1125};11261127enum hl_user_interrupt_type {1128HL_USR_INTERRUPT_CQ = 0,1129HL_USR_INTERRUPT_DECODER,1130HL_USR_INTERRUPT_TPC,1131HL_USR_INTERRUPT_UNEXPECTED1132};11331134/**1135* struct hl_ts_free_jobs - holds user interrupt ts free nodes related data1136* @free_nodes_pool: pool of nodes to be used for free timestamp jobs1137* @free_nodes_length: number of nodes in free_nodes_pool1138* @next_avail_free_node_idx: index of the next free node in the pool1139*1140* the free nodes pool must be protected by the user interrupt lock1141* to avoid race between different interrupts which are using the same1142* ts buffer with different offsets.1143*/1144struct hl_ts_free_jobs {1145struct timestamp_reg_free_node *free_nodes_pool;1146u32 free_nodes_length;1147u32 next_avail_free_node_idx;1148};11491150/**1151* struct hl_user_interrupt - holds user interrupt information1152* @hdev: pointer to the device structure1153* @ts_free_jobs_data: timestamp free jobs related data1154* @type: user interrupt type1155* @wait_list_head: head to the list of user threads pending on this interrupt1156* @ts_list_head: head to the list of timestamp records1157* @wait_list_lock: protects wait_list_head1158* @ts_list_lock: protects ts_list_head1159* @timestamp: last timestamp taken upon interrupt1160* @interrupt_id: msix interrupt id1161*/1162struct hl_user_interrupt {1163struct hl_device *hdev;1164struct hl_ts_free_jobs ts_free_jobs_data;1165enum hl_user_interrupt_type type;1166struct list_head wait_list_head;1167struct list_head ts_list_head;1168spinlock_t wait_list_lock;1169spinlock_t ts_list_lock;1170ktime_t timestamp;1171u32 interrupt_id;1172};11731174/**1175* struct timestamp_reg_free_node - holds the timestamp registration free objects node1176* @free_objects_node: node in the list free_obj_jobs1177* @cq_cb: pointer to cq command buffer to be freed1178* @buf: pointer to timestamp buffer to be freed1179* @in_use: indicates whether the node still in use in workqueue thread.1180* @dynamic_alloc: indicates whether the node was allocated dynamically in the interrupt handler1181*/1182struct timestamp_reg_free_node {1183struct list_head free_objects_node;1184struct hl_cb *cq_cb;1185struct hl_mmap_mem_buf *buf;1186atomic_t in_use;1187u8 dynamic_alloc;1188};11891190/* struct timestamp_reg_work_obj - holds the timestamp registration free objects job1191* the job will be to pass over the free_obj_jobs list and put refcount to objects1192* in each node of the list1193* @free_obj: workqueue object to free timestamp registration node objects1194* @hdev: pointer to the device structure1195* @free_obj_head: list of free jobs nodes (node type timestamp_reg_free_node)1196* @dynamic_alloc_free_obj_head: list of free jobs nodes which were dynamically allocated in the1197* interrupt handler.1198*/1199struct timestamp_reg_work_obj {1200struct work_struct free_obj;1201struct hl_device *hdev;1202struct list_head *free_obj_head;1203struct list_head *dynamic_alloc_free_obj_head;1204};12051206/* struct timestamp_reg_info - holds the timestamp registration related data.1207* @buf: pointer to the timestamp buffer which include both user/kernel buffers.1208* relevant only when doing timestamps records registration.1209* @cq_cb: pointer to CQ counter CB.1210* @interrupt: interrupt that the node hanged on it's wait list.1211* @timestamp_kernel_addr: timestamp handle address, where to set timestamp1212* relevant only when doing timestamps records1213* registration.1214* @in_use: indicates if the node already in use. relevant only when doing1215* timestamps records registration, since in this case the driver1216* will have it's own buffer which serve as a records pool instead of1217* allocating records dynamically.1218*/1219struct timestamp_reg_info {1220struct hl_mmap_mem_buf *buf;1221struct hl_cb *cq_cb;1222struct hl_user_interrupt *interrupt;1223u64 *timestamp_kernel_addr;1224bool in_use;1225};12261227/**1228* struct hl_user_pending_interrupt - holds a context to a user thread1229* pending on an interrupt1230* @ts_reg_info: holds the timestamps registration nodes info1231* @list_node: node in the list of user threads pending on an interrupt or timestamp1232* @fence: hl fence object for interrupt completion1233* @cq_target_value: CQ target value1234* @cq_kernel_addr: CQ kernel address, to be used in the cq interrupt1235* handler for target value comparison1236*/1237struct hl_user_pending_interrupt {1238struct timestamp_reg_info ts_reg_info;1239struct list_head list_node;1240struct hl_fence fence;1241u64 cq_target_value;1242u64 *cq_kernel_addr;1243};12441245/**1246* struct hl_eq - describes the event queue (single one per device)1247* @hdev: pointer to the device structure1248* @kernel_address: holds the queue's kernel virtual address1249* @bus_address: holds the queue's DMA address1250* @size: the event queue size1251* @ci: ci inside the queue1252* @prev_eqe_index: the index of the previous event queue entry. The index of1253* the current entry's index must be +1 of the previous one.1254* @check_eqe_index: do we need to check the index of the current entry vs. the1255* previous one. This is for backward compatibility with older1256* firmwares1257*/1258struct hl_eq {1259struct hl_device *hdev;1260void *kernel_address;1261dma_addr_t bus_address;1262u32 size;1263u32 ci;1264u32 prev_eqe_index;1265bool check_eqe_index;1266};12671268/**1269* struct hl_dec - describes a decoder sw instance.1270* @hdev: pointer to the device structure.1271* @abnrm_intr_work: workqueue work item to run when decoder generates an error interrupt.1272* @core_id: ID of the decoder.1273* @base_addr: base address of the decoder.1274*/1275struct hl_dec {1276struct hl_device *hdev;1277struct work_struct abnrm_intr_work;1278u32 core_id;1279u32 base_addr;1280};12811282/**1283* enum hl_asic_type - supported ASIC types.1284* @ASIC_INVALID: Invalid ASIC type.1285* @ASIC_GOYA: Goya device (HL-1000).1286* @ASIC_GAUDI: Gaudi device (HL-2000).1287* @ASIC_GAUDI_SEC: Gaudi secured device (HL-2000).1288* @ASIC_GAUDI2: Gaudi2 device.1289* @ASIC_GAUDI2B: Gaudi2B device.1290* @ASIC_GAUDI2C: Gaudi2C device.1291* @ASIC_GAUDI2D: Gaudi2D device.1292*/1293enum hl_asic_type {1294ASIC_INVALID,12951296ASIC_GOYA,1297ASIC_GAUDI,1298ASIC_GAUDI_SEC,1299ASIC_GAUDI2,1300ASIC_GAUDI2B,1301ASIC_GAUDI2C,1302ASIC_GAUDI2D,1303};13041305struct hl_cs_parser;13061307/**1308* enum hl_pm_mng_profile - power management profile.1309* @PM_AUTO: internal clock is set by the Linux driver.1310* @PM_MANUAL: internal clock is set by the user.1311* @PM_LAST: last power management type.1312*/1313enum hl_pm_mng_profile {1314PM_AUTO = 1,1315PM_MANUAL,1316PM_LAST1317};13181319/**1320* enum hl_pll_frequency - PLL frequency.1321* @PLL_HIGH: high frequency.1322* @PLL_LOW: low frequency.1323* @PLL_LAST: last frequency values that were configured by the user.1324*/1325enum hl_pll_frequency {1326PLL_HIGH = 1,1327PLL_LOW,1328PLL_LAST1329};13301331#define PLL_REF_CLK 5013321333enum div_select_defs {1334DIV_SEL_REF_CLK = 0,1335DIV_SEL_PLL_CLK = 1,1336DIV_SEL_DIVIDED_REF = 2,1337DIV_SEL_DIVIDED_PLL = 3,1338};13391340enum debugfs_access_type {1341DEBUGFS_READ8,1342DEBUGFS_WRITE8,1343DEBUGFS_READ32,1344DEBUGFS_WRITE32,1345DEBUGFS_READ64,1346DEBUGFS_WRITE64,1347};13481349enum pci_region {1350PCI_REGION_CFG,1351PCI_REGION_SRAM,1352PCI_REGION_DRAM,1353PCI_REGION_SP_SRAM,1354PCI_REGION_NUMBER,1355};13561357/**1358* struct pci_mem_region - describe memory region in a PCI bar1359* @region_base: region base address1360* @region_size: region size1361* @bar_size: size of the BAR1362* @offset_in_bar: region offset into the bar1363* @bar_id: bar ID of the region1364* @used: if used 1, otherwise 01365*/1366struct pci_mem_region {1367u64 region_base;1368u64 region_size;1369u64 bar_size;1370u64 offset_in_bar;1371u8 bar_id;1372u8 used;1373};13741375/**1376* struct static_fw_load_mgr - static FW load manager1377* @preboot_version_max_off: max offset to preboot version1378* @boot_fit_version_max_off: max offset to boot fit version1379* @kmd_msg_to_cpu_reg: register address for KDM->CPU messages1380* @cpu_cmd_status_to_host_reg: register address for CPU command status response1381* @cpu_boot_status_reg: boot status register1382* @cpu_boot_dev_status0_reg: boot device status register 01383* @cpu_boot_dev_status1_reg: boot device status register 11384* @boot_err0_reg: boot error register 01385* @boot_err1_reg: boot error register 11386* @preboot_version_offset_reg: SRAM offset to preboot version register1387* @boot_fit_version_offset_reg: SRAM offset to boot fit version register1388* @sram_offset_mask: mask for getting offset into the SRAM1389* @cpu_reset_wait_msec: used when setting WFE via kmd_msg_to_cpu_reg1390*/1391struct static_fw_load_mgr {1392u64 preboot_version_max_off;1393u64 boot_fit_version_max_off;1394u32 kmd_msg_to_cpu_reg;1395u32 cpu_cmd_status_to_host_reg;1396u32 cpu_boot_status_reg;1397u32 cpu_boot_dev_status0_reg;1398u32 cpu_boot_dev_status1_reg;1399u32 boot_err0_reg;1400u32 boot_err1_reg;1401u32 preboot_version_offset_reg;1402u32 boot_fit_version_offset_reg;1403u32 sram_offset_mask;1404u32 cpu_reset_wait_msec;1405};14061407/**1408* struct fw_response - FW response to LKD command1409* @ram_offset: descriptor offset into the RAM1410* @ram_type: RAM type containing the descriptor (SRAM/DRAM)1411* @status: command status1412*/1413struct fw_response {1414u32 ram_offset;1415u8 ram_type;1416u8 status;1417};14181419/**1420* struct dynamic_fw_load_mgr - dynamic FW load manager1421* @response: FW to LKD response1422* @comm_desc: the communication descriptor with FW1423* @image_region: region to copy the FW image to1424* @fw_image_size: size of FW image to load1425* @wait_for_bl_timeout: timeout for waiting for boot loader to respond1426* @fw_desc_valid: true if FW descriptor has been validated and hence the data can be used1427*/1428struct dynamic_fw_load_mgr {1429struct fw_response response;1430struct lkd_fw_comms_desc comm_desc;1431struct pci_mem_region *image_region;1432size_t fw_image_size;1433u32 wait_for_bl_timeout;1434bool fw_desc_valid;1435};14361437/**1438* struct pre_fw_load_props - needed properties for pre-FW load1439* @cpu_boot_status_reg: cpu_boot_status register address1440* @sts_boot_dev_sts0_reg: sts_boot_dev_sts0 register address1441* @sts_boot_dev_sts1_reg: sts_boot_dev_sts1 register address1442* @boot_err0_reg: boot_err0 register address1443* @boot_err1_reg: boot_err1 register address1444* @wait_for_preboot_timeout: timeout to poll for preboot ready1445* @wait_for_preboot_extended_timeout: timeout to pull for preboot ready in case where we know1446* preboot needs longer time.1447*/1448struct pre_fw_load_props {1449u32 cpu_boot_status_reg;1450u32 sts_boot_dev_sts0_reg;1451u32 sts_boot_dev_sts1_reg;1452u32 boot_err0_reg;1453u32 boot_err1_reg;1454u32 wait_for_preboot_timeout;1455u32 wait_for_preboot_extended_timeout;1456};14571458/**1459* struct fw_image_props - properties of FW image1460* @image_name: name of the image1461* @src_off: offset in src FW to copy from1462* @copy_size: amount of bytes to copy (0 to copy the whole binary)1463*/1464struct fw_image_props {1465char *image_name;1466u32 src_off;1467u32 copy_size;1468};14691470/**1471* struct fw_load_mgr - manager FW loading process1472* @dynamic_loader: specific structure for dynamic load1473* @static_loader: specific structure for static load1474* @pre_fw_load_props: parameter for pre FW load1475* @boot_fit_img: boot fit image properties1476* @linux_img: linux image properties1477* @cpu_timeout: CPU response timeout in usec1478* @boot_fit_timeout: Boot fit load timeout in usec1479* @skip_bmc: should BMC be skipped1480* @sram_bar_id: SRAM bar ID1481* @dram_bar_id: DRAM bar ID1482* @fw_comp_loaded: bitmask of loaded FW components. set bit meaning loaded1483* component. values are set according to enum hl_fw_types.1484*/1485struct fw_load_mgr {1486union {1487struct dynamic_fw_load_mgr dynamic_loader;1488struct static_fw_load_mgr static_loader;1489};1490struct pre_fw_load_props pre_fw_load;1491struct fw_image_props boot_fit_img;1492struct fw_image_props linux_img;1493u32 cpu_timeout;1494u32 boot_fit_timeout;1495u8 skip_bmc;1496u8 sram_bar_id;1497u8 dram_bar_id;1498u8 fw_comp_loaded;1499};15001501struct hl_cs;15021503/**1504* struct engines_data - asic engines data1505* @buf: buffer for engines data in ascii1506* @actual_size: actual size of data that was written by the driver to the allocated buffer1507* @allocated_buf_size: total size of allocated buffer1508*/1509struct engines_data {1510char *buf;1511int actual_size;1512u32 allocated_buf_size;1513};15141515/**1516* struct hl_asic_funcs - ASIC specific functions that are can be called from1517* common code.1518* @early_init: sets up early driver state (pre sw_init), doesn't configure H/W.1519* @early_fini: tears down what was done in early_init.1520* @late_init: sets up late driver/hw state (post hw_init) - Optional.1521* @late_fini: tears down what was done in late_init (pre hw_fini) - Optional.1522* @sw_init: sets up driver state, does not configure H/W.1523* @sw_fini: tears down driver state, does not configure H/W.1524* @hw_init: sets up the H/W state.1525* @hw_fini: tears down the H/W state.1526* @halt_engines: halt engines, needed for reset sequence. This also disables1527* interrupts from the device. Should be called before1528* hw_fini and before CS rollback.1529* @suspend: handles IP specific H/W or SW changes for suspend.1530* @resume: handles IP specific H/W or SW changes for resume.1531* @mmap: maps a memory.1532* @ring_doorbell: increment PI on a given QMAN.1533* @pqe_write: Write the PQ entry to the PQ. This is ASIC-specific1534* function because the PQs are located in different memory areas1535* per ASIC (SRAM, DRAM, Host memory) and therefore, the method of1536* writing the PQE must match the destination memory area1537* properties.1538* @asic_dma_alloc_coherent: Allocate coherent DMA memory by calling1539* dma_alloc_coherent(). This is ASIC function because1540* its implementation is not trivial when the driver1541* is loaded in simulation mode (not upstreamed).1542* @asic_dma_free_coherent: Free coherent DMA memory by calling1543* dma_free_coherent(). This is ASIC function because1544* its implementation is not trivial when the driver1545* is loaded in simulation mode (not upstreamed).1546* @scrub_device_mem: Scrub the entire SRAM and DRAM.1547* @scrub_device_dram: Scrub the dram memory of the device.1548* @get_int_queue_base: get the internal queue base address.1549* @test_queues: run simple test on all queues for sanity check.1550* @asic_dma_pool_zalloc: small DMA allocation of coherent memory from DMA pool.1551* size of allocation is HL_DMA_POOL_BLK_SIZE.1552* @asic_dma_pool_free: free small DMA allocation from pool.1553* @cpu_accessible_dma_pool_alloc: allocate CPU PQ packet from DMA pool.1554* @cpu_accessible_dma_pool_free: free CPU PQ packet from DMA pool.1555* @dma_unmap_sgtable: DMA unmap scatter-gather table.1556* @dma_map_sgtable: DMA map scatter-gather table.1557* @cs_parser: parse Command Submission.1558* @add_end_of_cb_packets: Add packets to the end of CB, if device requires it.1559* @update_eq_ci: update event queue CI.1560* @context_switch: called upon ASID context switch.1561* @restore_phase_topology: clear all SOBs amd MONs.1562* @debugfs_read_dma: debug interface for reading up to 2MB from the device's1563* internal memory via DMA engine.1564* @add_device_attr: add ASIC specific device attributes.1565* @handle_eqe: handle event queue entry (IRQ) from CPU-CP.1566* @get_events_stat: retrieve event queue entries histogram.1567* @read_pte: read MMU page table entry from DRAM.1568* @write_pte: write MMU page table entry to DRAM.1569* @mmu_invalidate_cache: flush MMU STLB host/DRAM cache, either with soft1570* (L1 only) or hard (L0 & L1) flush.1571* @mmu_invalidate_cache_range: flush specific MMU STLB cache lines with ASID-VA-size mask.1572* @mmu_prefetch_cache_range: pre-fetch specific MMU STLB cache lines with ASID-VA-size mask.1573* @send_heartbeat: send is-alive packet to CPU-CP and verify response.1574* @debug_coresight: perform certain actions on Coresight for debugging.1575* @is_device_idle: return true if device is idle, false otherwise.1576* @compute_reset_late_init: perform certain actions needed after a compute reset1577* @hw_queues_lock: acquire H/W queues lock.1578* @hw_queues_unlock: release H/W queues lock.1579* @get_pci_id: retrieve PCI ID.1580* @get_eeprom_data: retrieve EEPROM data from F/W.1581* @get_monitor_dump: retrieve monitor registers dump from F/W.1582* @send_cpu_message: send message to F/W. If the message is timedout, the1583* driver will eventually reset the device. The timeout can1584* be determined by the calling function or it can be 0 and1585* then the timeout is the default timeout for the specific1586* ASIC1587* @get_hw_state: retrieve the H/W state1588* @pci_bars_map: Map PCI BARs.1589* @init_iatu: Initialize the iATU unit inside the PCI controller.1590* @rreg: Read a register. Needed for simulator support.1591* @wreg: Write a register. Needed for simulator support.1592* @halt_coresight: stop the ETF and ETR traces.1593* @ctx_init: context dependent initialization.1594* @ctx_fini: context dependent cleanup.1595* @pre_schedule_cs: Perform pre-CS-scheduling operations.1596* @get_queue_id_for_cq: Get the H/W queue id related to the given CQ index.1597* @load_firmware_to_device: load the firmware to the device's memory1598* @load_boot_fit_to_device: load boot fit to device's memory1599* @get_signal_cb_size: Get signal CB size.1600* @get_wait_cb_size: Get wait CB size.1601* @gen_signal_cb: Generate a signal CB.1602* @gen_wait_cb: Generate a wait CB.1603* @reset_sob: Reset a SOB.1604* @reset_sob_group: Reset SOB group1605* @get_device_time: Get the device time.1606* @pb_print_security_errors: print security errors according block and cause1607* @collective_wait_init_cs: Generate collective master/slave packets1608* and place them in the relevant cs jobs1609* @collective_wait_create_jobs: allocate collective wait cs jobs1610* @get_dec_base_addr: get the base address of a given decoder.1611* @scramble_addr: Routine to scramble the address prior of mapping it1612* in the MMU.1613* @descramble_addr: Routine to de-scramble the address prior of1614* showing it to users.1615* @ack_protection_bits_errors: ack and dump all security violations1616* @get_hw_block_id: retrieve a HW block id to be used by the user to mmap it.1617* also returns the size of the block if caller supplies1618* a valid pointer for it1619* @hw_block_mmap: mmap a HW block with a given id.1620* @enable_events_from_fw: send interrupt to firmware to notify them the1621* driver is ready to receive asynchronous events. This1622* function should be called during the first init and1623* after every hard-reset of the device1624* @ack_mmu_errors: check and ack mmu errors, page fault, access violation.1625* @get_msi_info: Retrieve asic-specific MSI ID of the f/w async event1626* @map_pll_idx_to_fw_idx: convert driver specific per asic PLL index to1627* generic f/w compatible PLL Indexes1628* @init_firmware_preload_params: initialize pre FW-load parameters.1629* @init_firmware_loader: initialize data for FW loader.1630* @init_cpu_scrambler_dram: Enable CPU specific DRAM scrambling1631* @state_dump_init: initialize constants required for state dump1632* @get_sob_addr: get SOB base address offset.1633* @set_pci_memory_regions: setting properties of PCI memory regions1634* @get_stream_master_qid_arr: get pointer to stream masters QID array1635* @check_if_razwi_happened: check if there was a razwi due to RR violation.1636* @access_dev_mem: access device memory1637* @set_dram_bar_base: set the base of the DRAM BAR1638* @set_engine_cores: set a config command to engine cores1639* @set_engines: set a config command to user engines1640* @send_device_activity: indication to FW about device availability1641* @set_dram_properties: set DRAM related properties.1642* @set_binning_masks: set binning/enable masks for all relevant components.1643*/1644struct hl_asic_funcs {1645int (*early_init)(struct hl_device *hdev);1646int (*early_fini)(struct hl_device *hdev);1647int (*late_init)(struct hl_device *hdev);1648void (*late_fini)(struct hl_device *hdev);1649int (*sw_init)(struct hl_device *hdev);1650int (*sw_fini)(struct hl_device *hdev);1651int (*hw_init)(struct hl_device *hdev);1652int (*hw_fini)(struct hl_device *hdev, bool hard_reset, bool fw_reset);1653void (*halt_engines)(struct hl_device *hdev, bool hard_reset, bool fw_reset);1654int (*suspend)(struct hl_device *hdev);1655int (*resume)(struct hl_device *hdev);1656int (*mmap)(struct hl_device *hdev, struct vm_area_struct *vma,1657void *cpu_addr, dma_addr_t dma_addr, size_t size);1658void (*ring_doorbell)(struct hl_device *hdev, u32 hw_queue_id, u32 pi);1659void (*pqe_write)(struct hl_device *hdev, __le64 *pqe,1660struct hl_bd *bd);1661void* (*asic_dma_alloc_coherent)(struct hl_device *hdev, size_t size,1662dma_addr_t *dma_handle, gfp_t flag);1663void (*asic_dma_free_coherent)(struct hl_device *hdev, size_t size,1664void *cpu_addr, dma_addr_t dma_handle);1665int (*scrub_device_mem)(struct hl_device *hdev);1666int (*scrub_device_dram)(struct hl_device *hdev, u64 val);1667void* (*get_int_queue_base)(struct hl_device *hdev, u32 queue_id,1668dma_addr_t *dma_handle, u16 *queue_len);1669int (*test_queues)(struct hl_device *hdev);1670void* (*asic_dma_pool_zalloc)(struct hl_device *hdev, size_t size,1671gfp_t mem_flags, dma_addr_t *dma_handle);1672void (*asic_dma_pool_free)(struct hl_device *hdev, void *vaddr,1673dma_addr_t dma_addr);1674void* (*cpu_accessible_dma_pool_alloc)(struct hl_device *hdev,1675size_t size, dma_addr_t *dma_handle);1676void (*cpu_accessible_dma_pool_free)(struct hl_device *hdev,1677size_t size, void *vaddr);1678void (*dma_unmap_sgtable)(struct hl_device *hdev, struct sg_table *sgt,1679enum dma_data_direction dir);1680int (*dma_map_sgtable)(struct hl_device *hdev, struct sg_table *sgt,1681enum dma_data_direction dir);1682int (*cs_parser)(struct hl_device *hdev, struct hl_cs_parser *parser);1683void (*add_end_of_cb_packets)(struct hl_device *hdev,1684void *kernel_address, u32 len,1685u32 original_len,1686u64 cq_addr, u32 cq_val, u32 msix_num,1687bool eb);1688void (*update_eq_ci)(struct hl_device *hdev, u32 val);1689int (*context_switch)(struct hl_device *hdev, u32 asid);1690void (*restore_phase_topology)(struct hl_device *hdev);1691int (*debugfs_read_dma)(struct hl_device *hdev, u64 addr, u32 size,1692void *blob_addr);1693void (*add_device_attr)(struct hl_device *hdev, struct attribute_group *dev_clk_attr_grp,1694struct attribute_group *dev_vrm_attr_grp);1695void (*handle_eqe)(struct hl_device *hdev,1696struct hl_eq_entry *eq_entry);1697void* (*get_events_stat)(struct hl_device *hdev, bool aggregate,1698u32 *size);1699u64 (*read_pte)(struct hl_device *hdev, u64 addr);1700void (*write_pte)(struct hl_device *hdev, u64 addr, u64 val);1701int (*mmu_invalidate_cache)(struct hl_device *hdev, bool is_hard,1702u32 flags);1703int (*mmu_invalidate_cache_range)(struct hl_device *hdev, bool is_hard,1704u32 flags, u32 asid, u64 va, u64 size);1705int (*mmu_prefetch_cache_range)(struct hl_ctx *ctx, u32 flags, u32 asid, u64 va, u64 size);1706int (*send_heartbeat)(struct hl_device *hdev);1707int (*debug_coresight)(struct hl_device *hdev, struct hl_ctx *ctx, void *data);1708bool (*is_device_idle)(struct hl_device *hdev, u64 *mask_arr, u8 mask_len,1709struct engines_data *e);1710int (*compute_reset_late_init)(struct hl_device *hdev);1711void (*hw_queues_lock)(struct hl_device *hdev);1712void (*hw_queues_unlock)(struct hl_device *hdev);1713u32 (*get_pci_id)(struct hl_device *hdev);1714int (*get_eeprom_data)(struct hl_device *hdev, void *data, size_t max_size);1715int (*get_monitor_dump)(struct hl_device *hdev, void *data);1716int (*send_cpu_message)(struct hl_device *hdev, u32 *msg,1717u16 len, u32 timeout, u64 *result);1718int (*pci_bars_map)(struct hl_device *hdev);1719int (*init_iatu)(struct hl_device *hdev);1720u32 (*rreg)(struct hl_device *hdev, u32 reg);1721void (*wreg)(struct hl_device *hdev, u32 reg, u32 val);1722void (*halt_coresight)(struct hl_device *hdev, struct hl_ctx *ctx);1723int (*ctx_init)(struct hl_ctx *ctx);1724void (*ctx_fini)(struct hl_ctx *ctx);1725int (*pre_schedule_cs)(struct hl_cs *cs);1726u32 (*get_queue_id_for_cq)(struct hl_device *hdev, u32 cq_idx);1727int (*load_firmware_to_device)(struct hl_device *hdev);1728int (*load_boot_fit_to_device)(struct hl_device *hdev);1729u32 (*get_signal_cb_size)(struct hl_device *hdev);1730u32 (*get_wait_cb_size)(struct hl_device *hdev);1731u32 (*gen_signal_cb)(struct hl_device *hdev, void *data, u16 sob_id,1732u32 size, bool eb);1733u32 (*gen_wait_cb)(struct hl_device *hdev,1734struct hl_gen_wait_properties *prop);1735void (*reset_sob)(struct hl_device *hdev, void *data);1736void (*reset_sob_group)(struct hl_device *hdev, u16 sob_group);1737u64 (*get_device_time)(struct hl_device *hdev);1738void (*pb_print_security_errors)(struct hl_device *hdev,1739u32 block_addr, u32 cause, u32 offended_addr);1740int (*collective_wait_init_cs)(struct hl_cs *cs);1741int (*collective_wait_create_jobs)(struct hl_device *hdev,1742struct hl_ctx *ctx, struct hl_cs *cs,1743u32 wait_queue_id, u32 collective_engine_id,1744u32 encaps_signal_offset);1745u32 (*get_dec_base_addr)(struct hl_device *hdev, u32 core_id);1746u64 (*scramble_addr)(struct hl_device *hdev, u64 addr);1747u64 (*descramble_addr)(struct hl_device *hdev, u64 addr);1748void (*ack_protection_bits_errors)(struct hl_device *hdev);1749int (*get_hw_block_id)(struct hl_device *hdev, u64 block_addr,1750u32 *block_size, u32 *block_id);1751int (*hw_block_mmap)(struct hl_device *hdev, struct vm_area_struct *vma,1752u32 block_id, u32 block_size);1753void (*enable_events_from_fw)(struct hl_device *hdev);1754int (*ack_mmu_errors)(struct hl_device *hdev, u64 mmu_cap_mask);1755void (*get_msi_info)(__le32 *table);1756int (*map_pll_idx_to_fw_idx)(u32 pll_idx);1757void (*init_firmware_preload_params)(struct hl_device *hdev);1758void (*init_firmware_loader)(struct hl_device *hdev);1759void (*init_cpu_scrambler_dram)(struct hl_device *hdev);1760void (*state_dump_init)(struct hl_device *hdev);1761u32 (*get_sob_addr)(struct hl_device *hdev, u32 sob_id);1762void (*set_pci_memory_regions)(struct hl_device *hdev);1763u32* (*get_stream_master_qid_arr)(void);1764void (*check_if_razwi_happened)(struct hl_device *hdev);1765int (*mmu_get_real_page_size)(struct hl_device *hdev, struct hl_mmu_properties *mmu_prop,1766u32 page_size, u32 *real_page_size, bool is_dram_addr);1767int (*access_dev_mem)(struct hl_device *hdev, enum pci_region region_type,1768u64 addr, u64 *val, enum debugfs_access_type acc_type);1769u64 (*set_dram_bar_base)(struct hl_device *hdev, u64 addr);1770int (*set_engine_cores)(struct hl_device *hdev, u32 *core_ids,1771u32 num_cores, u32 core_command);1772int (*set_engines)(struct hl_device *hdev, u32 *engine_ids,1773u32 num_engines, u32 engine_command);1774int (*send_device_activity)(struct hl_device *hdev, bool open);1775int (*set_dram_properties)(struct hl_device *hdev);1776int (*set_binning_masks)(struct hl_device *hdev);1777};177817791780/*1781* CONTEXTS1782*/17831784#define HL_KERNEL_ASID_ID 017851786/**1787* enum hl_va_range_type - virtual address range type.1788* @HL_VA_RANGE_TYPE_HOST: range type of host pages1789* @HL_VA_RANGE_TYPE_HOST_HUGE: range type of host huge pages1790* @HL_VA_RANGE_TYPE_DRAM: range type of dram pages1791*/1792enum hl_va_range_type {1793HL_VA_RANGE_TYPE_HOST,1794HL_VA_RANGE_TYPE_HOST_HUGE,1795HL_VA_RANGE_TYPE_DRAM,1796HL_VA_RANGE_TYPE_MAX1797};17981799/**1800* struct hl_va_range - virtual addresses range.1801* @lock: protects the virtual addresses list.1802* @list: list of virtual addresses blocks available for mappings.1803* @start_addr: range start address.1804* @end_addr: range end address.1805* @page_size: page size of this va range.1806*/1807struct hl_va_range {1808struct mutex lock;1809struct list_head list;1810u64 start_addr;1811u64 end_addr;1812u32 page_size;1813};18141815/**1816* struct hl_cs_counters_atomic - command submission counters1817* @out_of_mem_drop_cnt: dropped due to memory allocation issue1818* @parsing_drop_cnt: dropped due to error in packet parsing1819* @queue_full_drop_cnt: dropped due to queue full1820* @device_in_reset_drop_cnt: dropped due to device in reset1821* @max_cs_in_flight_drop_cnt: dropped due to maximum CS in-flight1822* @validation_drop_cnt: dropped due to error in validation1823*/1824struct hl_cs_counters_atomic {1825atomic64_t out_of_mem_drop_cnt;1826atomic64_t parsing_drop_cnt;1827atomic64_t queue_full_drop_cnt;1828atomic64_t device_in_reset_drop_cnt;1829atomic64_t max_cs_in_flight_drop_cnt;1830atomic64_t validation_drop_cnt;1831};18321833/**1834* struct hl_dmabuf_priv - a dma-buf private object.1835* @dmabuf: pointer to dma-buf object.1836* @ctx: pointer to the dma-buf owner's context.1837* @phys_pg_pack: pointer to physical page pack if the dma-buf was exported1838* where virtual memory is supported.1839* @memhash_hnode: pointer to the memhash node. this object holds the export count.1840* @offset: the offset into the buffer from which the memory is exported.1841* Relevant only if virtual memory is supported and phys_pg_pack is being used.1842* device_phys_addr: physical address of the device's memory. Relevant only1843* if phys_pg_pack is NULL (dma-buf was exported from address).1844* The total size can be taken from the dmabuf object.1845*/1846struct hl_dmabuf_priv {1847struct dma_buf *dmabuf;1848struct hl_ctx *ctx;1849struct hl_vm_phys_pg_pack *phys_pg_pack;1850struct hl_vm_hash_node *memhash_hnode;1851u64 offset;1852u64 device_phys_addr;1853};18541855#define HL_CS_OUTCOME_HISTORY_LEN 25618561857/**1858* struct hl_cs_outcome - represents a single completed CS outcome1859* @list_link: link to either container's used list or free list1860* @map_link: list to the container hash map1861* @ts: completion ts1862* @seq: the original cs sequence1863* @error: error code cs completed with, if any1864*/1865struct hl_cs_outcome {1866struct list_head list_link;1867struct hlist_node map_link;1868ktime_t ts;1869u64 seq;1870int error;1871};18721873/**1874* struct hl_cs_outcome_store - represents a limited store of completed CS outcomes1875* @outcome_map: index of completed CS searchable by sequence number1876* @used_list: list of outcome objects currently in use1877* @free_list: list of outcome objects currently not in use1878* @nodes_pool: a static pool of pre-allocated outcome objects1879* @db_lock: any operation on the store must take this lock1880*/1881struct hl_cs_outcome_store {1882DECLARE_HASHTABLE(outcome_map, 8);1883struct list_head used_list;1884struct list_head free_list;1885struct hl_cs_outcome nodes_pool[HL_CS_OUTCOME_HISTORY_LEN];1886spinlock_t db_lock;1887};18881889/**1890* struct hl_ctx - user/kernel context.1891* @mem_hash: holds mapping from virtual address to virtual memory area1892* descriptor (hl_vm_phys_pg_list or hl_userptr).1893* @mmu_shadow_hash: holds a mapping from shadow address to pgt_info structure.1894* @hr_mmu_phys_hash: if host-resident MMU is used, holds a mapping from1895* MMU-hop-page physical address to its host-resident1896* pgt_info structure.1897* @hpriv: pointer to the private (Kernel Driver) data of the process (fd).1898* @hdev: pointer to the device structure.1899* @refcount: reference counter for the context. Context is released only when1900* this hits 0. It is incremented on CS and CS_WAIT.1901* @cs_pending: array of hl fence objects representing pending CS.1902* @outcome_store: storage data structure used to remember outcomes of completed1903* command submissions for a long time after CS id wraparound.1904* @va_range: holds available virtual addresses for host and dram mappings.1905* @mem_hash_lock: protects the mem_hash.1906* @hw_block_list_lock: protects the HW block memory list.1907* @ts_reg_lock: timestamp registration ioctls lock.1908* @debugfs_list: node in debugfs list of contexts.1909* @hw_block_mem_list: list of HW block virtual mapped addresses.1910* @cs_counters: context command submission counters.1911* @cb_va_pool: device VA pool for command buffers which are mapped to the1912* device's MMU.1913* @sig_mgr: encaps signals handle manager.1914* @cb_va_pool_base: the base address for the device VA pool1915* @cs_sequence: sequence number for CS. Value is assigned to a CS and passed1916* to user so user could inquire about CS. It is used as1917* index to cs_pending array.1918* @dram_default_hops: array that holds all hops addresses needed for default1919* DRAM mapping.1920* @cs_lock: spinlock to protect cs_sequence.1921* @dram_phys_mem: amount of used physical DRAM memory by this context.1922* @thread_ctx_switch_token: token to prevent multiple threads of the same1923* context from running the context switch phase.1924* Only a single thread should run it.1925* @thread_ctx_switch_wait_token: token to prevent the threads that didn't run1926* the context switch phase from moving to their1927* execution phase before the context switch phase1928* has finished.1929* @asid: context's unique address space ID in the device's MMU.1930* @handle: context's opaque handle for user1931*/1932struct hl_ctx {1933DECLARE_HASHTABLE(mem_hash, MEM_HASH_TABLE_BITS);1934DECLARE_HASHTABLE(mmu_shadow_hash, MMU_HASH_TABLE_BITS);1935DECLARE_HASHTABLE(hr_mmu_phys_hash, MMU_HASH_TABLE_BITS);1936struct hl_fpriv *hpriv;1937struct hl_device *hdev;1938struct kref refcount;1939struct hl_fence **cs_pending;1940struct hl_cs_outcome_store outcome_store;1941struct hl_va_range *va_range[HL_VA_RANGE_TYPE_MAX];1942struct mutex mem_hash_lock;1943struct mutex hw_block_list_lock;1944struct mutex ts_reg_lock;1945struct list_head debugfs_list;1946struct list_head hw_block_mem_list;1947struct hl_cs_counters_atomic cs_counters;1948struct gen_pool *cb_va_pool;1949struct hl_encaps_signals_mgr sig_mgr;1950u64 cb_va_pool_base;1951u64 cs_sequence;1952u64 *dram_default_hops;1953spinlock_t cs_lock;1954atomic64_t dram_phys_mem;1955atomic_t thread_ctx_switch_token;1956u32 thread_ctx_switch_wait_token;1957u32 asid;1958u32 handle;1959};19601961/**1962* struct hl_ctx_mgr - for handling multiple contexts.1963* @lock: protects ctx_handles.1964* @handles: idr to hold all ctx handles.1965*/1966struct hl_ctx_mgr {1967struct mutex lock;1968struct idr handles;1969};197019711972/*1973* COMMAND SUBMISSIONS1974*/19751976/**1977* struct hl_userptr - memory mapping chunk information1978* @vm_type: type of the VM.1979* @job_node: linked-list node for hanging the object on the Job's list.1980* @pages: pointer to struct page array1981* @npages: size of @pages array1982* @sgt: pointer to the scatter-gather table that holds the pages.1983* @dir: for DMA unmapping, the direction must be supplied, so save it.1984* @debugfs_list: node in debugfs list of command submissions.1985* @pid: the pid of the user process owning the memory1986* @addr: user-space virtual address of the start of the memory area.1987* @size: size of the memory area to pin & map.1988* @dma_mapped: true if the SG was mapped to DMA addresses, false otherwise.1989*/1990struct hl_userptr {1991enum vm_type vm_type; /* must be first */1992struct list_head job_node;1993struct page **pages;1994unsigned int npages;1995struct sg_table *sgt;1996enum dma_data_direction dir;1997struct list_head debugfs_list;1998pid_t pid;1999u64 addr;2000u64 size;2001u8 dma_mapped;2002};20032004/**2005* struct hl_cs - command submission.2006* @jobs_in_queue_cnt: per each queue, maintain counter of submitted jobs.2007* @ctx: the context this CS belongs to.2008* @job_list: list of the CS's jobs in the various queues.2009* @job_lock: spinlock for the CS's jobs list. Needed for free_job.2010* @refcount: reference counter for usage of the CS.2011* @fence: pointer to the fence object of this CS.2012* @signal_fence: pointer to the fence object of the signal CS (used by wait2013* CS only).2014* @finish_work: workqueue object to run when CS is completed by H/W.2015* @work_tdr: delayed work node for TDR.2016* @mirror_node : node in device mirror list of command submissions.2017* @staged_cs_node: node in the staged cs list.2018* @debugfs_list: node in debugfs list of command submissions.2019* @encaps_sig_hdl: holds the encaps signals handle.2020* @sequence: the sequence number of this CS.2021* @staged_sequence: the sequence of the staged submission this CS is part of,2022* relevant only if staged_cs is set.2023* @timeout_jiffies: cs timeout in jiffies.2024* @submission_time_jiffies: submission time of the cs2025* @type: CS_TYPE_*.2026* @jobs_cnt: counter of submitted jobs on all queues.2027* @encaps_sig_hdl_id: encaps signals handle id, set for the first staged cs.2028* @completion_timestamp: timestamp of the last completed cs job.2029* @sob_addr_offset: sob offset from the configuration base address.2030* @initial_sob_count: count of completed signals in SOB before current submission of signal or2031* cs with encaps signals.2032* @submitted: true if CS was submitted to H/W.2033* @completed: true if CS was completed by device.2034* @timedout : true if CS was timedout.2035* @tdr_active: true if TDR was activated for this CS (to prevent2036* double TDR activation).2037* @aborted: true if CS was aborted due to some device error.2038* @timestamp: true if a timestamp must be captured upon completion.2039* @staged_last: true if this is the last staged CS and needs completion.2040* @staged_first: true if this is the first staged CS and we need to receive2041* timeout for this CS.2042* @staged_cs: true if this CS is part of a staged submission.2043* @skip_reset_on_timeout: true if we shall not reset the device in case2044* timeout occurs (debug scenario).2045* @encaps_signals: true if this CS has encaps reserved signals.2046*/2047struct hl_cs {2048u16 *jobs_in_queue_cnt;2049struct hl_ctx *ctx;2050struct list_head job_list;2051spinlock_t job_lock;2052struct kref refcount;2053struct hl_fence *fence;2054struct hl_fence *signal_fence;2055struct work_struct finish_work;2056struct delayed_work work_tdr;2057struct list_head mirror_node;2058struct list_head staged_cs_node;2059struct list_head debugfs_list;2060struct hl_cs_encaps_sig_handle *encaps_sig_hdl;2061ktime_t completion_timestamp;2062u64 sequence;2063u64 staged_sequence;2064u64 timeout_jiffies;2065u64 submission_time_jiffies;2066enum hl_cs_type type;2067u32 jobs_cnt;2068u32 encaps_sig_hdl_id;2069u32 sob_addr_offset;2070u16 initial_sob_count;2071u8 submitted;2072u8 completed;2073u8 timedout;2074u8 tdr_active;2075u8 aborted;2076u8 timestamp;2077u8 staged_last;2078u8 staged_first;2079u8 staged_cs;2080u8 skip_reset_on_timeout;2081u8 encaps_signals;2082};20832084/**2085* struct hl_cs_job - command submission job.2086* @cs_node: the node to hang on the CS jobs list.2087* @cs: the CS this job belongs to.2088* @user_cb: the CB we got from the user.2089* @patched_cb: in case of patching, this is internal CB which is submitted on2090* the queue instead of the CB we got from the IOCTL.2091* @finish_work: workqueue object to run when job is completed.2092* @userptr_list: linked-list of userptr mappings that belong to this job and2093* wait for completion.2094* @debugfs_list: node in debugfs list of command submission jobs.2095* @refcount: reference counter for usage of the CS job.2096* @queue_type: the type of the H/W queue this job is submitted to.2097* @timestamp: timestamp upon job completion2098* @id: the id of this job inside a CS.2099* @hw_queue_id: the id of the H/W queue this job is submitted to.2100* @user_cb_size: the actual size of the CB we got from the user.2101* @job_cb_size: the actual size of the CB that we put on the queue.2102* @encaps_sig_wait_offset: encapsulated signals offset, which allow user2103* to wait on part of the reserved signals.2104* @is_kernel_allocated_cb: true if the CB handle we got from the user holds a2105* handle to a kernel-allocated CB object, false2106* otherwise (SRAM/DRAM/host address).2107* @contains_dma_pkt: whether the JOB contains at least one DMA packet. This2108* info is needed later, when adding the 2xMSG_PROT at the2109* end of the JOB, to know which barriers to put in the2110* MSG_PROT packets. Relevant only for GAUDI as GOYA doesn't2111* have streams so the engine can't be busy by another2112* stream.2113*/2114struct hl_cs_job {2115struct list_head cs_node;2116struct hl_cs *cs;2117struct hl_cb *user_cb;2118struct hl_cb *patched_cb;2119struct work_struct finish_work;2120struct list_head userptr_list;2121struct list_head debugfs_list;2122struct kref refcount;2123enum hl_queue_type queue_type;2124ktime_t timestamp;2125u32 id;2126u32 hw_queue_id;2127u32 user_cb_size;2128u32 job_cb_size;2129u32 encaps_sig_wait_offset;2130u8 is_kernel_allocated_cb;2131u8 contains_dma_pkt;2132};21332134/**2135* struct hl_cs_parser - command submission parser properties.2136* @user_cb: the CB we got from the user.2137* @patched_cb: in case of patching, this is internal CB which is submitted on2138* the queue instead of the CB we got from the IOCTL.2139* @job_userptr_list: linked-list of userptr mappings that belong to the related2140* job and wait for completion.2141* @cs_sequence: the sequence number of the related CS.2142* @queue_type: the type of the H/W queue this job is submitted to.2143* @ctx_id: the ID of the context the related CS belongs to.2144* @hw_queue_id: the id of the H/W queue this job is submitted to.2145* @user_cb_size: the actual size of the CB we got from the user.2146* @patched_cb_size: the size of the CB after parsing.2147* @job_id: the id of the related job inside the related CS.2148* @is_kernel_allocated_cb: true if the CB handle we got from the user holds a2149* handle to a kernel-allocated CB object, false2150* otherwise (SRAM/DRAM/host address).2151* @contains_dma_pkt: whether the JOB contains at least one DMA packet. This2152* info is needed later, when adding the 2xMSG_PROT at the2153* end of the JOB, to know which barriers to put in the2154* MSG_PROT packets. Relevant only for GAUDI as GOYA doesn't2155* have streams so the engine can't be busy by another2156* stream.2157* @completion: true if we need completion for this CS.2158*/2159struct hl_cs_parser {2160struct hl_cb *user_cb;2161struct hl_cb *patched_cb;2162struct list_head *job_userptr_list;2163u64 cs_sequence;2164enum hl_queue_type queue_type;2165u32 ctx_id;2166u32 hw_queue_id;2167u32 user_cb_size;2168u32 patched_cb_size;2169u8 job_id;2170u8 is_kernel_allocated_cb;2171u8 contains_dma_pkt;2172u8 completion;2173};21742175/*2176* MEMORY STRUCTURE2177*/21782179/**2180* struct hl_vm_hash_node - hash element from virtual address to virtual2181* memory area descriptor (hl_vm_phys_pg_list or2182* hl_userptr).2183* @node: node to hang on the hash table in context object.2184* @vaddr: key virtual address.2185* @handle: memory handle for device memory allocation.2186* @ptr: value pointer (hl_vm_phys_pg_list or hl_userptr).2187* @export_cnt: number of exports from within the VA block.2188*/2189struct hl_vm_hash_node {2190struct hlist_node node;2191u64 vaddr;2192u64 handle;2193void *ptr;2194int export_cnt;2195};21962197/**2198* struct hl_vm_hw_block_list_node - list element from user virtual address to2199* HW block id.2200* @node: node to hang on the list in context object.2201* @ctx: the context this node belongs to.2202* @vaddr: virtual address of the HW block.2203* @block_size: size of the block.2204* @mapped_size: size of the block which is mapped. May change if partial un-mappings are done.2205* @id: HW block id (handle).2206*/2207struct hl_vm_hw_block_list_node {2208struct list_head node;2209struct hl_ctx *ctx;2210unsigned long vaddr;2211u32 block_size;2212u32 mapped_size;2213u32 id;2214};22152216/**2217* struct hl_vm_phys_pg_pack - physical page pack.2218* @vm_type: describes the type of the virtual area descriptor.2219* @pages: the physical page array.2220* @npages: num physical pages in the pack.2221* @total_size: total size of all the pages in this list.2222* @node: used to attach to deletion list that is used when all the allocations are cleared2223* at the teardown of the context.2224* @mapping_cnt: number of shared mappings.2225* @asid: the context related to this list.2226* @page_size: size of each page in the pack.2227* @flags: HL_MEM_* flags related to this list.2228* @handle: the provided handle related to this list.2229* @offset: offset from the first page.2230* @contiguous: is contiguous physical memory.2231* @created_from_userptr: is product of host virtual address.2232*/2233struct hl_vm_phys_pg_pack {2234enum vm_type vm_type; /* must be first */2235u64 *pages;2236u64 npages;2237u64 total_size;2238struct list_head node;2239atomic_t mapping_cnt;2240u32 asid;2241u32 page_size;2242u32 flags;2243u32 handle;2244u32 offset;2245u8 contiguous;2246u8 created_from_userptr;2247};22482249/**2250* struct hl_vm_va_block - virtual range block information.2251* @node: node to hang on the virtual range list in context object.2252* @start: virtual range start address.2253* @end: virtual range end address.2254* @size: virtual range size.2255*/2256struct hl_vm_va_block {2257struct list_head node;2258u64 start;2259u64 end;2260u64 size;2261};22622263/**2264* struct hl_vm - virtual memory manager for MMU.2265* @dram_pg_pool: pool for DRAM physical pages of 2MB.2266* @dram_pg_pool_refcount: reference counter for the pool usage.2267* @idr_lock: protects the phys_pg_list_handles.2268* @phys_pg_pack_handles: idr to hold all device allocations handles.2269* @init_done: whether initialization was done. We need this because VM2270* initialization might be skipped during device initialization.2271*/2272struct hl_vm {2273struct gen_pool *dram_pg_pool;2274struct kref dram_pg_pool_refcount;2275spinlock_t idr_lock;2276struct idr phys_pg_pack_handles;2277u8 init_done;2278};22792280#ifdef CONFIG_HL_HLDIO2281#include "hldio.h"2282#endif22832284/*2285* DEBUG, PROFILING STRUCTURE2286*/22872288/**2289* struct hl_debug_params - Coresight debug parameters.2290* @input: pointer to component specific input parameters.2291* @output: pointer to component specific output parameters.2292* @output_size: size of output buffer.2293* @reg_idx: relevant register ID.2294* @op: component operation to execute.2295* @enable: true if to enable component debugging, false otherwise.2296*/2297struct hl_debug_params {2298void *input;2299void *output;2300u32 output_size;2301u32 reg_idx;2302u32 op;2303bool enable;2304};23052306/**2307* struct hl_notifier_event - holds the notifier data structure2308* @eventfd: the event file descriptor to raise the notifications2309* @lock: mutex lock to protect the notifier data flows2310* @events_mask: indicates the bitmap events2311*/2312struct hl_notifier_event {2313struct eventfd_ctx *eventfd;2314struct mutex lock;2315u64 events_mask;2316};23172318/*2319* FILE PRIVATE STRUCTURE2320*/23212322/**2323* struct hl_fpriv - process information stored in FD private data.2324* @hdev: habanalabs device structure.2325* @file_priv: pointer to the DRM file private data structure.2326* @taskpid: current process ID.2327* @ctx: current executing context. TODO: remove for multiple ctx per process2328* @ctx_mgr: context manager to handle multiple context for this FD.2329* @mem_mgr: manager descriptor for memory exportable via mmap2330* @notifier_event: notifier eventfd towards user process2331* @debugfs_list: list of relevant ASIC debugfs.2332* @dev_node: node in the device list of file private data2333* @refcount: number of related contexts.2334* @restore_phase_mutex: lock for context switch and restore phase.2335* @ctx_lock: protects the pointer to current executing context pointer. TODO: remove for multiple2336* ctx per process.2337*/2338struct hl_fpriv {2339struct hl_device *hdev;2340struct drm_file *file_priv;2341struct pid *taskpid;2342struct hl_ctx *ctx;2343struct hl_ctx_mgr ctx_mgr;2344struct hl_mem_mgr mem_mgr;2345struct hl_notifier_event notifier_event;2346struct list_head debugfs_list;2347struct list_head dev_node;2348struct kref refcount;2349struct mutex restore_phase_mutex;2350struct mutex ctx_lock;2351};23522353/*2354* DebugFS2355*/23562357/**2358* struct hl_info_list - debugfs file ops.2359* @name: file name.2360* @show: function to output information.2361* @write: function to write to the file.2362*/2363struct hl_info_list {2364const char *name;2365int (*show)(struct seq_file *s, void *data);2366ssize_t (*write)(struct file *file, const char __user *buf,2367size_t count, loff_t *f_pos);2368};23692370/**2371* struct hl_debugfs_entry - debugfs dentry wrapper.2372* @info_ent: dentry related ops.2373* @dev_entry: ASIC specific debugfs manager.2374*/2375struct hl_debugfs_entry {2376const struct hl_info_list *info_ent;2377struct hl_dbg_device_entry *dev_entry;2378};237923802381/**2382* struct hl_dbg_device_entry - ASIC specific debugfs manager.2383* @root: root dentry.2384* @hdev: habanalabs device structure.2385* @entry_arr: array of available hl_debugfs_entry.2386* @file_list: list of available debugfs files.2387* @file_mutex: protects file_list.2388* @cb_list: list of available CBs.2389* @cb_spinlock: protects cb_list.2390* @cs_list: list of available CSs.2391* @cs_spinlock: protects cs_list.2392* @cs_job_list: list of available CB jobs.2393* @cs_job_spinlock: protects cs_job_list.2394* @userptr_list: list of available userptrs (virtual memory chunk descriptor).2395* @userptr_spinlock: protects userptr_list.2396* @ctx_mem_hash_list: list of available contexts with MMU mappings.2397* @ctx_mem_hash_mutex: protects list of available contexts with MMU mappings.2398* @data_dma_blob_desc: data DMA descriptor of blob.2399* @mon_dump_blob_desc: monitor dump descriptor of blob.2400* @state_dump: data of the system states in case of a bad cs.2401* @state_dump_sem: protects state_dump.2402* @addr: next address to read/write from/to in read/write32.2403* @mmu_addr: next virtual address to translate to physical address in mmu_show.2404* @mmu_cap_mask: mmu hw capability mask, to be used in mmu_ack_error.2405* @userptr_lookup: the target user ptr to look up for on demand.2406* @mmu_asid: ASID to use while translating in mmu_show.2407* @state_dump_head: index of the latest state dump2408* @i2c_bus: generic u8 debugfs file for bus value to use in i2c_data_read.2409* @i2c_addr: generic u8 debugfs file for address value to use in i2c_data_read.2410* @i2c_reg: generic u8 debugfs file for register value to use in i2c_data_read.2411* @i2c_len: generic u8 debugfs file for length value to use in i2c_data_read.2412* @dio_stats: Direct I/O statistics2413*/2414struct hl_dbg_device_entry {2415struct dentry *root;2416struct hl_device *hdev;2417struct hl_debugfs_entry *entry_arr;2418struct list_head file_list;2419struct mutex file_mutex;2420struct list_head cb_list;2421spinlock_t cb_spinlock;2422struct list_head cs_list;2423spinlock_t cs_spinlock;2424struct list_head cs_job_list;2425spinlock_t cs_job_spinlock;2426struct list_head userptr_list;2427spinlock_t userptr_spinlock;2428struct list_head ctx_mem_hash_list;2429struct mutex ctx_mem_hash_mutex;2430struct debugfs_blob_wrapper data_dma_blob_desc;2431struct debugfs_blob_wrapper mon_dump_blob_desc;2432char *state_dump[HL_STATE_DUMP_HIST_LEN];2433struct rw_semaphore state_dump_sem;2434u64 addr;2435u64 mmu_addr;2436u64 mmu_cap_mask;2437u64 userptr_lookup;2438u32 mmu_asid;2439u32 state_dump_head;2440u8 i2c_bus;2441u8 i2c_addr;2442u8 i2c_reg;2443u8 i2c_len;2444#ifdef CONFIG_HL_HLDIO2445struct hl_dio_stats dio_stats;2446#endif2447};24482449/**2450* struct hl_debugfs_cfg_access_entry - single debugfs config access object, member of2451* hl_debugfs_cfg_access.2452* @seconds_since_epoch: seconds since January 1, 1970, used for time comparisons.2453* @debugfs_type: the debugfs operation requested, can be READ32, WRITE32, READ64 or WRITE64.2454* @addr: the requested address to access.2455* @valid: if set, this entry has valid data for dumping at interrupt time.2456*/2457struct hl_debugfs_cfg_access_entry {2458ktime_t seconds_since_epoch;2459enum debugfs_access_type debugfs_type;2460u64 addr;2461bool valid;2462};24632464/**2465* struct hl_debugfs_cfg_access - saves debugfs config region access requests history.2466* @cfg_access_list: list of objects describing config region access requests.2467* @head: next valid index to add new entry to in cfg_access_list.2468*/2469struct hl_debugfs_cfg_access {2470struct hl_debugfs_cfg_access_entry cfg_access_list[HL_DBGFS_CFG_ACCESS_HIST_LEN];2471u32 head;2472spinlock_t lock; /* protects head and entries */2473};24742475/**2476* struct hl_hw_obj_name_entry - single hw object name, member of2477* hl_state_dump_specs2478* @node: link to the containing hash table2479* @name: hw object name2480* @id: object identifier2481*/2482struct hl_hw_obj_name_entry {2483struct hlist_node node;2484const char *name;2485u32 id;2486};24872488enum hl_state_dump_specs_props {2489SP_SYNC_OBJ_BASE_ADDR,2490SP_NEXT_SYNC_OBJ_ADDR,2491SP_SYNC_OBJ_AMOUNT,2492SP_MON_OBJ_WR_ADDR_LOW,2493SP_MON_OBJ_WR_ADDR_HIGH,2494SP_MON_OBJ_WR_DATA,2495SP_MON_OBJ_ARM_DATA,2496SP_MON_OBJ_STATUS,2497SP_MONITORS_AMOUNT,2498SP_TPC0_CMDQ,2499SP_TPC0_CFG_SO,2500SP_NEXT_TPC,2501SP_MME_CMDQ,2502SP_MME_CFG_SO,2503SP_NEXT_MME,2504SP_DMA_CMDQ,2505SP_DMA_CFG_SO,2506SP_DMA_QUEUES_OFFSET,2507SP_NUM_OF_MME_ENGINES,2508SP_SUB_MME_ENG_NUM,2509SP_NUM_OF_DMA_ENGINES,2510SP_NUM_OF_TPC_ENGINES,2511SP_ENGINE_NUM_OF_QUEUES,2512SP_ENGINE_NUM_OF_STREAMS,2513SP_ENGINE_NUM_OF_FENCES,2514SP_FENCE0_CNT_OFFSET,2515SP_FENCE0_RDATA_OFFSET,2516SP_CP_STS_OFFSET,2517SP_NUM_CORES,25182519SP_MAX2520};25212522enum hl_sync_engine_type {2523ENGINE_TPC,2524ENGINE_DMA,2525ENGINE_MME,2526};25272528/**2529* struct hl_mon_state_dump - represents a state dump of a single monitor2530* @id: monitor id2531* @wr_addr_low: address monitor will write to, low bits2532* @wr_addr_high: address monitor will write to, high bits2533* @wr_data: data monitor will write2534* @arm_data: register value containing monitor configuration2535* @status: monitor status2536*/2537struct hl_mon_state_dump {2538u32 id;2539u32 wr_addr_low;2540u32 wr_addr_high;2541u32 wr_data;2542u32 arm_data;2543u32 status;2544};25452546/**2547* struct hl_sync_to_engine_map_entry - sync object id to engine mapping entry2548* @engine_type: type of the engine2549* @engine_id: id of the engine2550* @sync_id: id of the sync object2551*/2552struct hl_sync_to_engine_map_entry {2553struct hlist_node node;2554enum hl_sync_engine_type engine_type;2555u32 engine_id;2556u32 sync_id;2557};25582559/**2560* struct hl_sync_to_engine_map - maps sync object id to associated engine id2561* @tb: hash table containing the mapping, each element is of type2562* struct hl_sync_to_engine_map_entry2563*/2564struct hl_sync_to_engine_map {2565DECLARE_HASHTABLE(tb, SYNC_TO_ENGINE_HASH_TABLE_BITS);2566};25672568/**2569* struct hl_state_dump_specs_funcs - virtual functions used by the state dump2570* @gen_sync_to_engine_map: generate a hash map from sync obj id to its engine2571* @print_single_monitor: format monitor data as string2572* @monitor_valid: return true if given monitor dump is valid2573* @print_fences_single_engine: format fences data as string2574*/2575struct hl_state_dump_specs_funcs {2576int (*gen_sync_to_engine_map)(struct hl_device *hdev,2577struct hl_sync_to_engine_map *map);2578int (*print_single_monitor)(char **buf, size_t *size, size_t *offset,2579struct hl_device *hdev,2580struct hl_mon_state_dump *mon);2581int (*monitor_valid)(struct hl_mon_state_dump *mon);2582int (*print_fences_single_engine)(struct hl_device *hdev,2583u64 base_offset,2584u64 status_base_offset,2585enum hl_sync_engine_type engine_type,2586u32 engine_id, char **buf,2587size_t *size, size_t *offset);2588};25892590/**2591* struct hl_state_dump_specs - defines ASIC known hw objects names2592* @so_id_to_str_tb: sync objects names index table2593* @monitor_id_to_str_tb: monitors names index table2594* @funcs: virtual functions used for state dump2595* @sync_namager_names: readable names for sync manager if available (ex: N_E)2596* @props: pointer to a per asic const props array required for state dump2597*/2598struct hl_state_dump_specs {2599DECLARE_HASHTABLE(so_id_to_str_tb, OBJ_NAMES_HASH_TABLE_BITS);2600DECLARE_HASHTABLE(monitor_id_to_str_tb, OBJ_NAMES_HASH_TABLE_BITS);2601struct hl_state_dump_specs_funcs funcs;2602const char * const *sync_namager_names;2603s64 *props;2604};260526062607/*2608* DEVICES2609*/26102611#define HL_STR_MAX 6426122613#define HL_DEV_STS_MAX (HL_DEVICE_STATUS_LAST + 1)26142615/* Theoretical limit only. A single host can only contain up to 4 or 8 PCIe2616* x16 cards. In extreme cases, there are hosts that can accommodate 16 cards.2617*/2618#define HL_MAX_MINORS 25626192620/*2621* Registers read & write functions.2622*/26232624u32 hl_rreg(struct hl_device *hdev, u32 reg);2625void hl_wreg(struct hl_device *hdev, u32 reg, u32 val);26262627#define RREG32(reg) hdev->asic_funcs->rreg(hdev, (reg))2628#define WREG32(reg, v) hdev->asic_funcs->wreg(hdev, (reg), (v))2629#define DREG32(reg) pr_info("REGISTER: " #reg " : 0x%08X\n", \2630hdev->asic_funcs->rreg(hdev, (reg)))26312632#define WREG32_P(reg, val, mask) \2633do { \2634u32 tmp_ = RREG32(reg); \2635tmp_ &= (mask); \2636tmp_ |= ((val) & ~(mask)); \2637WREG32(reg, tmp_); \2638} while (0)2639#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)2640#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))26412642#define RMWREG32_SHIFTED(reg, val, mask) WREG32_P(reg, val, ~(mask))26432644#define RMWREG32(reg, val, mask) RMWREG32_SHIFTED(reg, (val) << __ffs(mask), mask)26452646#define RREG32_MASK(reg, mask) ((RREG32(reg) & mask) >> __ffs(mask))26472648#define REG_FIELD_SHIFT(reg, field) reg##_##field##_SHIFT2649#define REG_FIELD_MASK(reg, field) reg##_##field##_MASK2650#define WREG32_FIELD(reg, offset, field, val) \2651WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & \2652~REG_FIELD_MASK(reg, field)) | \2653(val) << REG_FIELD_SHIFT(reg, field))26542655/* Timeout should be longer when working with simulator but cap the2656* increased timeout to some maximum2657*/2658#define hl_poll_timeout_common(hdev, addr, val, cond, sleep_us, timeout_us, elbi) \2659({ \2660ktime_t __timeout; \2661u32 __elbi_read; \2662int __rc = 0; \2663__timeout = ktime_add_us(ktime_get(), timeout_us); \2664might_sleep_if(sleep_us); \2665for (;;) { \2666if (elbi) { \2667__rc = hl_pci_elbi_read(hdev, addr, &__elbi_read); \2668if (__rc) \2669break; \2670(val) = __elbi_read; \2671} else {\2672(val) = RREG32(lower_32_bits(addr)); \2673} \2674if (cond) \2675break; \2676if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \2677if (elbi) { \2678__rc = hl_pci_elbi_read(hdev, addr, &__elbi_read); \2679if (__rc) \2680break; \2681(val) = __elbi_read; \2682} else {\2683(val) = RREG32(lower_32_bits(addr)); \2684} \2685break; \2686} \2687if (sleep_us) \2688usleep_range((sleep_us >> 2) + 1, sleep_us); \2689} \2690__rc ? __rc : ((cond) ? 0 : -ETIMEDOUT); \2691})26922693#define hl_poll_timeout(hdev, addr, val, cond, sleep_us, timeout_us) \2694hl_poll_timeout_common(hdev, addr, val, cond, sleep_us, timeout_us, false)26952696#define hl_poll_timeout_elbi(hdev, addr, val, cond, sleep_us, timeout_us) \2697hl_poll_timeout_common(hdev, addr, val, cond, sleep_us, timeout_us, true)26982699/*2700* poll array of register addresses.2701* condition is satisfied if all registers values match the expected value.2702* once some register in the array satisfies the condition it will not be polled again,2703* this is done both for efficiency and due to some registers are "clear on read".2704* TODO: use read from PCI bar in other places in the code (SW-91406)2705*/2706#define hl_poll_reg_array_timeout_common(hdev, addr_arr, arr_size, expected_val, sleep_us, \2707timeout_us, elbi) \2708({ \2709ktime_t __timeout; \2710u64 __elem_bitmask; \2711u32 __read_val; \2712u8 __arr_idx; \2713int __rc = 0; \2714\2715__timeout = ktime_add_us(ktime_get(), timeout_us); \2716might_sleep_if(sleep_us); \2717if (arr_size >= 64) \2718__rc = -EINVAL; \2719else \2720__elem_bitmask = BIT_ULL(arr_size) - 1; \2721for (;;) { \2722if (__rc) \2723break; \2724for (__arr_idx = 0; __arr_idx < (arr_size); __arr_idx++) { \2725if (!(__elem_bitmask & BIT_ULL(__arr_idx))) \2726continue; \2727if (elbi) { \2728__rc = hl_pci_elbi_read(hdev, (addr_arr)[__arr_idx], &__read_val); \2729if (__rc) \2730break; \2731} else { \2732__read_val = RREG32(lower_32_bits(addr_arr[__arr_idx])); \2733} \2734if (__read_val == (expected_val)) \2735__elem_bitmask &= ~BIT_ULL(__arr_idx); \2736} \2737if (__rc || (__elem_bitmask == 0)) \2738break; \2739if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) \2740break; \2741if (sleep_us) \2742usleep_range((sleep_us >> 2) + 1, sleep_us); \2743} \2744__rc ? __rc : ((__elem_bitmask == 0) ? 0 : -ETIMEDOUT); \2745})27462747#define hl_poll_reg_array_timeout(hdev, addr_arr, arr_size, expected_val, sleep_us, \2748timeout_us) \2749hl_poll_reg_array_timeout_common(hdev, addr_arr, arr_size, expected_val, sleep_us, \2750timeout_us, false)27512752#define hl_poll_reg_array_timeout_elbi(hdev, addr_arr, arr_size, expected_val, sleep_us, \2753timeout_us) \2754hl_poll_reg_array_timeout_common(hdev, addr_arr, arr_size, expected_val, sleep_us, \2755timeout_us, true)27562757/*2758* address in this macro points always to a memory location in the2759* host's (server's) memory. That location is updated asynchronously2760* either by the direct access of the device or by another core.2761*2762* To work both in LE and BE architectures, we need to distinguish between the2763* two states (device or another core updates the memory location). Therefore,2764* if mem_written_by_device is true, the host memory being polled will be2765* updated directly by the device. If false, the host memory being polled will2766* be updated by host CPU. Required so host knows whether or not the memory2767* might need to be byte-swapped before returning value to caller.2768*2769* On the first 4 polling iterations the macro goes to sleep for short period of2770* time that gradually increases and reaches sleep_us on the fifth iteration.2771*/2772#define hl_poll_timeout_memory(hdev, addr, val, cond, sleep_us, timeout_us, \2773mem_written_by_device) \2774({ \2775u64 __sleep_step_us; \2776ktime_t __timeout; \2777u8 __step = 8; \2778\2779__timeout = ktime_add_us(ktime_get(), timeout_us); \2780might_sleep_if(sleep_us); \2781for (;;) { \2782/* Verify we read updates done by other cores or by device */ \2783mb(); \2784(val) = *((u32 *)(addr)); \2785if (mem_written_by_device) \2786(val) = le32_to_cpu(*(__le32 *) &(val)); \2787if (cond) \2788break; \2789if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \2790(val) = *((u32 *)(addr)); \2791if (mem_written_by_device) \2792(val) = le32_to_cpu(*(__le32 *) &(val)); \2793break; \2794} \2795__sleep_step_us = sleep_us >> __step; \2796if (__sleep_step_us) \2797usleep_range((__sleep_step_us >> 2) + 1, __sleep_step_us); \2798__step >>= 1; \2799} \2800(cond) ? 0 : -ETIMEDOUT; \2801})28022803#define HL_USR_MAPPED_BLK_INIT(blk, base, sz) \2804({ \2805struct user_mapped_block *p = blk; \2806\2807p->address = base; \2808p->size = sz; \2809})28102811#define HL_USR_INTR_STRUCT_INIT(usr_intr, hdev, intr_id, intr_type) \2812({ \2813usr_intr.hdev = hdev; \2814usr_intr.interrupt_id = intr_id; \2815usr_intr.type = intr_type; \2816INIT_LIST_HEAD(&usr_intr.wait_list_head); \2817spin_lock_init(&usr_intr.wait_list_lock); \2818INIT_LIST_HEAD(&usr_intr.ts_list_head); \2819spin_lock_init(&usr_intr.ts_list_lock); \2820})28212822struct hwmon_chip_info;28232824/**2825* struct hl_device_reset_work - reset work wrapper.2826* @reset_work: reset work to be done.2827* @hdev: habanalabs device structure.2828* @flags: reset flags.2829*/2830struct hl_device_reset_work {2831struct delayed_work reset_work;2832struct hl_device *hdev;2833u32 flags;2834};28352836/**2837* struct hl_mmu_hr_pgt_priv - used for holding per-device mmu host-resident2838* page-table internal information.2839* @mmu_pgt_pool: pool of page tables used by a host-resident MMU for2840* allocating hops.2841* @mmu_asid_hop0: per-ASID array of host-resident hop0 tables.2842*/2843struct hl_mmu_hr_priv {2844struct gen_pool *mmu_pgt_pool;2845struct pgt_info *mmu_asid_hop0;2846};28472848/**2849* struct hl_mmu_dr_pgt_priv - used for holding per-device mmu device-resident2850* page-table internal information.2851* @mmu_pgt_pool: pool of page tables used by MMU for allocating hops.2852* @mmu_shadow_hop0: shadow array of hop0 tables.2853*/2854struct hl_mmu_dr_priv {2855struct gen_pool *mmu_pgt_pool;2856void *mmu_shadow_hop0;2857};28582859/**2860* struct hl_mmu_priv - used for holding per-device mmu internal information.2861* @dr: information on the device-resident MMU, when exists.2862* @hr: information on the host-resident MMU, when exists.2863*/2864struct hl_mmu_priv {2865struct hl_mmu_dr_priv dr;2866struct hl_mmu_hr_priv hr;2867};28682869/**2870* struct hl_mmu_per_hop_info - A structure describing one TLB HOP and its entry2871* that was created in order to translate a virtual address to a2872* physical one.2873* @hop_addr: The address of the hop.2874* @hop_pte_addr: The address of the hop entry.2875* @hop_pte_val: The value in the hop entry.2876*/2877struct hl_mmu_per_hop_info {2878u64 hop_addr;2879u64 hop_pte_addr;2880u64 hop_pte_val;2881};28822883/**2884* struct hl_mmu_hop_info - A structure describing the TLB hops and their2885* hop-entries that were created in order to translate a virtual address to a2886* physical one.2887* @scrambled_vaddr: The value of the virtual address after scrambling. This2888* address replaces the original virtual-address when mapped2889* in the MMU tables.2890* @unscrambled_paddr: The un-scrambled physical address.2891* @hop_info: Array holding the per-hop information used for the translation.2892* @used_hops: The number of hops used for the translation.2893* @range_type: virtual address range type.2894*/2895struct hl_mmu_hop_info {2896u64 scrambled_vaddr;2897u64 unscrambled_paddr;2898struct hl_mmu_per_hop_info hop_info[MMU_ARCH_6_HOPS];2899u32 used_hops;2900enum hl_va_range_type range_type;2901};29022903/**2904* struct hl_hr_mmu_funcs - Device related host resident MMU functions.2905* @get_hop0_pgt_info: get page table info structure for HOP0.2906* @get_pgt_info: get page table info structure for HOP other than HOP0.2907* @add_pgt_info: add page table info structure to hash.2908* @get_tlb_mapping_params: get mapping parameters needed for getting TLB info for specific mapping.2909*/2910struct hl_hr_mmu_funcs {2911struct pgt_info *(*get_hop0_pgt_info)(struct hl_ctx *ctx);2912struct pgt_info *(*get_pgt_info)(struct hl_ctx *ctx, u64 phys_hop_addr);2913void (*add_pgt_info)(struct hl_ctx *ctx, struct pgt_info *pgt_info, dma_addr_t phys_addr);2914int (*get_tlb_mapping_params)(struct hl_device *hdev, struct hl_mmu_properties **mmu_prop,2915struct hl_mmu_hop_info *hops,2916u64 virt_addr, bool *is_huge);2917};29182919/**2920* struct hl_mmu_funcs - Device related MMU functions.2921* @init: initialize the MMU module.2922* @fini: release the MMU module.2923* @ctx_init: Initialize a context for using the MMU module.2924* @ctx_fini: disable a ctx from using the mmu module.2925* @map: maps a virtual address to physical address for a context.2926* @unmap: unmap a virtual address of a context.2927* @flush: flush all writes from all cores to reach device MMU.2928* @swap_out: marks all mapping of the given context as swapped out.2929* @swap_in: marks all mapping of the given context as swapped in.2930* @get_tlb_info: returns the list of hops and hop-entries used that were2931* created in order to translate the giver virtual address to a2932* physical one.2933* @hr_funcs: functions specific to host resident MMU.2934*/2935struct hl_mmu_funcs {2936int (*init)(struct hl_device *hdev);2937void (*fini)(struct hl_device *hdev);2938int (*ctx_init)(struct hl_ctx *ctx);2939void (*ctx_fini)(struct hl_ctx *ctx);2940int (*map)(struct hl_ctx *ctx, u64 virt_addr, u64 phys_addr, u32 page_size,2941bool is_dram_addr);2942int (*unmap)(struct hl_ctx *ctx, u64 virt_addr, bool is_dram_addr);2943void (*flush)(struct hl_ctx *ctx);2944void (*swap_out)(struct hl_ctx *ctx);2945void (*swap_in)(struct hl_ctx *ctx);2946int (*get_tlb_info)(struct hl_ctx *ctx, u64 virt_addr, struct hl_mmu_hop_info *hops);2947struct hl_hr_mmu_funcs hr_funcs;2948};29492950/**2951* struct hl_prefetch_work - prefetch work structure handler2952* @prefetch_work: actual work struct.2953* @ctx: compute context.2954* @va: virtual address to pre-fetch.2955* @size: pre-fetch size.2956* @flags: operation flags.2957* @asid: ASID for maintenance operation.2958*/2959struct hl_prefetch_work {2960struct work_struct prefetch_work;2961struct hl_ctx *ctx;2962u64 va;2963u64 size;2964u32 flags;2965u32 asid;2966};29672968/*2969* number of user contexts allowed to call wait_for_multi_cs ioctl in2970* parallel2971*/2972#define MULTI_CS_MAX_USER_CTX 229732974/**2975* struct multi_cs_completion - multi CS wait completion.2976* @completion: completion of any of the CS in the list2977* @lock: spinlock for the completion structure2978* @timestamp: timestamp for the multi-CS completion2979* @stream_master_qid_map: bitmap of all stream masters on which the multi-CS2980* is waiting2981* @used: 1 if in use, otherwise 02982*/2983struct multi_cs_completion {2984struct completion completion;2985spinlock_t lock;2986s64 timestamp;2987u32 stream_master_qid_map;2988u8 used;2989};29902991/**2992* struct multi_cs_data - internal data for multi CS call2993* @ctx: pointer to the context structure2994* @fence_arr: array of fences of all CSs2995* @seq_arr: array of CS sequence numbers2996* @timeout_jiffies: timeout in jiffies for waiting for CS to complete2997* @timestamp: timestamp of first completed CS2998* @wait_status: wait for CS status2999* @completion_bitmap: bitmap of completed CSs (1- completed, otherwise 0)3000* @arr_len: fence_arr and seq_arr array length3001* @gone_cs: indication of gone CS (1- there was gone CS, otherwise 0)3002* @update_ts: update timestamp. 1- update the timestamp, otherwise 0.3003*/3004struct multi_cs_data {3005struct hl_ctx *ctx;3006struct hl_fence **fence_arr;3007u64 *seq_arr;3008s64 timeout_jiffies;3009s64 timestamp;3010long wait_status;3011u32 completion_bitmap;3012u8 arr_len;3013u8 gone_cs;3014u8 update_ts;3015};30163017/**3018* struct hl_clk_throttle_timestamp - current/last clock throttling timestamp3019* @start: timestamp taken when 'start' event is received in driver3020* @end: timestamp taken when 'end' event is received in driver3021*/3022struct hl_clk_throttle_timestamp {3023ktime_t start;3024ktime_t end;3025};30263027/**3028* struct hl_clk_throttle - keeps current/last clock throttling timestamps3029* @timestamp: timestamp taken by driver and firmware, index 0 refers to POWER3030* index 1 refers to THERMAL3031* @lock: protects this structure as it can be accessed from both event queue3032* context and info_ioctl context3033* @current_reason: bitmask represents the current clk throttling reasons3034* @aggregated_reason: bitmask represents aggregated clk throttling reasons since driver load3035*/3036struct hl_clk_throttle {3037struct hl_clk_throttle_timestamp timestamp[HL_CLK_THROTTLE_TYPE_MAX];3038struct mutex lock;3039u32 current_reason;3040u32 aggregated_reason;3041};30423043/**3044* struct user_mapped_block - describes a hw block allowed to be mmapped by user3045* @address: physical HW block address3046* @size: allowed size for mmap3047*/3048struct user_mapped_block {3049u32 address;3050u32 size;3051};30523053/**3054* struct cs_timeout_info - info of last CS timeout occurred.3055* @timestamp: CS timeout timestamp.3056* @write_enable: if set writing to CS parameters in the structure is enabled. otherwise - disabled,3057* so the first (root cause) CS timeout will not be overwritten.3058* @seq: CS timeout sequence number.3059*/3060struct cs_timeout_info {3061ktime_t timestamp;3062atomic_t write_enable;3063u64 seq;3064};30653066#define MAX_QMAN_STREAMS_INFO 43067#define OPCODE_INFO_MAX_ADDR_SIZE 83068/**3069* struct undefined_opcode_info - info about last undefined opcode error3070* @timestamp: timestamp of the undefined opcode error3071* @cb_addr_streams: CB addresses (per stream) that are currently exists in the PQ3072* entries. In case all streams array entries are3073* filled with values, it means the execution was in Lower-CP.3074* @cq_addr: the address of the current handled command buffer3075* @cq_size: the size of the current handled command buffer3076* @cb_addr_streams_len: num of streams - actual len of cb_addr_streams array.3077* should be equal to 1 in case of undefined opcode3078* in Upper-CP (specific stream) and equal to 4 in case3079* of undefined opcode in Lower-CP.3080* @engine_id: engine-id that the error occurred on3081* @stream_id: the stream id the error occurred on. In case the stream equals to3082* MAX_QMAN_STREAMS_INFO it means the error occurred on a Lower-CP.3083* @write_enable: if set, writing to undefined opcode parameters in the structure3084* is enable so the first (root cause) undefined opcode will not be3085* overwritten.3086*/3087struct undefined_opcode_info {3088ktime_t timestamp;3089u64 cb_addr_streams[MAX_QMAN_STREAMS_INFO][OPCODE_INFO_MAX_ADDR_SIZE];3090u64 cq_addr;3091u32 cq_size;3092u32 cb_addr_streams_len;3093u32 engine_id;3094u32 stream_id;3095bool write_enable;3096};30973098/**3099* struct page_fault_info - page fault information.3100* @page_fault: holds information collected during a page fault.3101* @user_mappings: buffer containing user mappings.3102* @num_of_user_mappings: number of user mappings.3103* @page_fault_detected: if set as 1, then a page-fault was discovered for the3104* first time after the driver has finished booting-up.3105* Since we're looking for the page-fault's root cause,3106* we don't care of the others that might follow it-3107* so once changed to 1, it will remain that way.3108* @page_fault_info_available: indicates that a page fault info is now available.3109*/3110struct page_fault_info {3111struct hl_page_fault_info page_fault;3112struct hl_user_mapping *user_mappings;3113u64 num_of_user_mappings;3114atomic_t page_fault_detected;3115bool page_fault_info_available;3116};31173118/**3119* struct razwi_info - RAZWI information.3120* @razwi: holds information collected during a RAZWI3121* @razwi_detected: if set as 1, then a RAZWI was discovered for the3122* first time after the driver has finished booting-up.3123* Since we're looking for the RAZWI's root cause,3124* we don't care of the others that might follow it-3125* so once changed to 1, it will remain that way.3126* @razwi_info_available: indicates that a RAZWI info is now available.3127*/3128struct razwi_info {3129struct hl_info_razwi_event razwi;3130atomic_t razwi_detected;3131bool razwi_info_available;3132};31333134/**3135* struct hw_err_info - HW error information.3136* @event: holds information on the event.3137* @event_detected: if set as 1, then a HW event was discovered for the3138* first time after the driver has finished booting-up.3139* currently we assume that only fatal events (that require hard-reset) are3140* reported so we don't care of the others that might follow it.3141* so once changed to 1, it will remain that way.3142* TODO: support multiple events.3143* @event_info_available: indicates that a HW event info is now available.3144*/3145struct hw_err_info {3146struct hl_info_hw_err_event event;3147atomic_t event_detected;3148bool event_info_available;3149};31503151/**3152* struct fw_err_info - FW error information.3153* @event: holds information on the event.3154* @event_detected: if set as 1, then a FW event was discovered for the3155* first time after the driver has finished booting-up.3156* currently we assume that only fatal events (that require hard-reset) are3157* reported so we don't care of the others that might follow it.3158* so once changed to 1, it will remain that way.3159* TODO: support multiple events.3160* @event_info_available: indicates that a HW event info is now available.3161*/3162struct fw_err_info {3163struct hl_info_fw_err_event event;3164atomic_t event_detected;3165bool event_info_available;3166};31673168/**3169* struct engine_err_info - engine error information.3170* @event: holds information on the event.3171* @event_detected: if set as 1, then an engine event was discovered for the3172* first time after the driver has finished booting-up.3173* @event_info_available: indicates that an engine event info is now available.3174*/3175struct engine_err_info {3176struct hl_info_engine_err_event event;3177atomic_t event_detected;3178bool event_info_available;3179};318031813182/**3183* struct hl_error_info - holds information collected during an error.3184* @cs_timeout: CS timeout error information.3185* @razwi_info: RAZWI information.3186* @undef_opcode: undefined opcode information.3187* @page_fault_info: page fault information.3188* @hw_err: (fatal) hardware error information.3189* @fw_err: firmware error information.3190* @engine_err: engine error information.3191*/3192struct hl_error_info {3193struct cs_timeout_info cs_timeout;3194struct razwi_info razwi_info;3195struct undefined_opcode_info undef_opcode;3196struct page_fault_info page_fault_info;3197struct hw_err_info hw_err;3198struct fw_err_info fw_err;3199struct engine_err_info engine_err;3200};32013202/**3203* struct hl_reset_info - holds current device reset information.3204* @lock: lock to protect critical reset flows.3205* @compute_reset_cnt: number of compute resets since the driver was loaded.3206* @hard_reset_cnt: number of hard resets since the driver was loaded.3207* @hard_reset_schedule_flags: hard reset is scheduled to after current compute reset,3208* here we hold the hard reset flags.3209* @in_reset: is device in reset flow.3210* @in_compute_reset: Device is currently in reset but not in hard-reset.3211* @needs_reset: true if reset_on_lockup is false and device should be reset3212* due to lockup.3213* @hard_reset_pending: is there a hard reset work pending.3214* @curr_reset_cause: saves an enumerated reset cause when a hard reset is3215* triggered, and cleared after it is shared with preboot.3216* @prev_reset_trigger: saves the previous trigger which caused a reset, overridden3217* with a new value on next reset3218* @reset_trigger_repeated: set if device reset is triggered more than once with3219* same cause.3220* @skip_reset_on_timeout: Skip device reset if CS has timed out, wait for it to3221* complete instead.3222* @watchdog_active: true if a device release watchdog work is scheduled.3223*/3224struct hl_reset_info {3225spinlock_t lock;3226u32 compute_reset_cnt;3227u32 hard_reset_cnt;3228u32 hard_reset_schedule_flags;3229u8 in_reset;3230u8 in_compute_reset;3231u8 needs_reset;3232u8 hard_reset_pending;3233u8 curr_reset_cause;3234u8 prev_reset_trigger;3235u8 reset_trigger_repeated;3236u8 skip_reset_on_timeout;3237u8 watchdog_active;3238};32393240/**3241* struct eq_heartbeat_debug_info - stores debug info to be used upon heartbeat failure.3242* @last_pq_heartbeat_ts: timestamp of the last test packet that was sent to FW.3243* This packet is the trigger in FW to send the EQ heartbeat event.3244* @last_eq_heartbeat_ts: timestamp of the last EQ heartbeat event that was received from FW.3245* @heartbeat_event_counter: number of heartbeat events received.3246* @cpu_queue_id: used to read the queue pi/ci3247*/3248struct eq_heartbeat_debug_info {3249time64_t last_pq_heartbeat_ts;3250time64_t last_eq_heartbeat_ts;3251u32 heartbeat_event_counter;3252u32 cpu_queue_id;3253};32543255/**3256* struct hl_device - habanalabs device structure.3257* @pdev: pointer to PCI device, can be NULL in case of simulator device.3258* @pcie_bar_phys: array of available PCIe bars physical addresses.3259* (required only for PCI address match mode)3260* @pcie_bar: array of available PCIe bars virtual addresses.3261* @rmmio: configuration area address on SRAM.3262* @drm: related DRM device.3263* @cdev_ctrl: char device for control operations only (INFO IOCTL)3264* @dev: related kernel basic device structure.3265* @dev_ctrl: related kernel device structure for the control device3266* @work_heartbeat: delayed work for CPU-CP is-alive check.3267* @device_reset_work: delayed work which performs hard reset3268* @device_release_watchdog_work: watchdog work that performs hard reset if user doesn't release3269* device upon certain error cases.3270* @asic_name: ASIC specific name.3271* @asic_type: ASIC specific type.3272* @completion_queue: array of hl_cq.3273* @user_interrupt: array of hl_user_interrupt. upon the corresponding user3274* interrupt, driver will monitor the list of fences3275* registered to this interrupt.3276* @tpc_interrupt: single TPC interrupt for all TPCs.3277* @unexpected_error_interrupt: single interrupt for unexpected user error indication.3278* @common_user_cq_interrupt: common user CQ interrupt for all user CQ interrupts.3279* upon any user CQ interrupt, driver will monitor the3280* list of fences registered to this common structure.3281* @common_decoder_interrupt: common decoder interrupt for all user decoder interrupts.3282* @shadow_cs_queue: pointer to a shadow queue that holds pointers to3283* outstanding command submissions.3284* @cq_wq: work queues of completion queues for executing work in process3285* context.3286* @eq_wq: work queue of event queue for executing work in process context.3287* @cs_cmplt_wq: work queue of CS completions for executing work in process3288* context.3289* @ts_free_obj_wq: work queue for timestamp registration objects release.3290* @prefetch_wq: work queue for MMU pre-fetch operations.3291* @reset_wq: work queue for device reset procedure.3292* @kernel_ctx: Kernel driver context structure.3293* @kernel_queues: array of hl_hw_queue.3294* @cs_mirror_list: CS mirror list for TDR.3295* @cs_mirror_lock: protects cs_mirror_list.3296* @kernel_mem_mgr: memory manager for memory buffers with lifespan of driver.3297* @event_queue: event queue for IRQ from CPU-CP.3298* @dma_pool: DMA pool for small allocations.3299* @cpu_accessible_dma_mem: Host <-> CPU-CP shared memory CPU address.3300* @cpu_accessible_dma_address: Host <-> CPU-CP shared memory DMA address.3301* @cpu_accessible_dma_pool: Host <-> CPU-CP shared memory pool.3302* @asid_bitmap: holds used/available ASIDs.3303* @asid_mutex: protects asid_bitmap.3304* @send_cpu_message_lock: enforces only one message in Host <-> CPU-CP queue.3305* @debug_lock: protects critical section of setting debug mode for device3306* @mmu_lock: protects the MMU page tables and invalidation h/w. Although the3307* page tables are per context, the invalidation h/w is per MMU.3308* Therefore, we can't allow multiple contexts (we only have two,3309* user and kernel) to access the invalidation h/w at the same time.3310* In addition, any change to the PGT, modifying the MMU hash or3311* walking the PGT requires talking this lock.3312* @asic_prop: ASIC specific immutable properties.3313* @asic_funcs: ASIC specific functions.3314* @asic_specific: ASIC specific information to use only from ASIC files.3315* @vm: virtual memory manager for MMU.3316* @hwmon_dev: H/W monitor device.3317* @hl_chip_info: ASIC's sensors information.3318* @device_status_description: device status description.3319* @hl_debugfs: device's debugfs manager.3320* @debugfs_cfg_accesses: list of last debugfs config region accesses.3321* @cb_pool: list of pre allocated CBs.3322* @cb_pool_lock: protects the CB pool.3323* @internal_cb_pool_virt_addr: internal command buffer pool virtual address.3324* @internal_cb_pool_dma_addr: internal command buffer pool dma address.3325* @internal_cb_pool: internal command buffer memory pool.3326* @internal_cb_va_base: internal cb pool mmu virtual address base3327* @fpriv_list: list of file private data structures. Each structure is created3328* when a user opens the device3329* @fpriv_ctrl_list: list of file private data structures. Each structure is created3330* when a user opens the control device3331* @fpriv_list_lock: protects the fpriv_list3332* @fpriv_ctrl_list_lock: protects the fpriv_ctrl_list3333* @aggregated_cs_counters: aggregated cs counters among all contexts3334* @mmu_priv: device-specific MMU data.3335* @mmu_func: device-related MMU functions.3336* @dec: list of decoder sw instance3337* @fw_loader: FW loader manager.3338* @pci_mem_region: array of memory regions in the PCI3339* @state_dump_specs: constants and dictionaries needed to dump system state.3340* @multi_cs_completion: array of multi-CS completion.3341* @clk_throttling: holds information about current/previous clock throttling events3342* @captured_err_info: holds information about errors.3343* @reset_info: holds current device reset information.3344* @heartbeat_debug_info: counters used to debug heartbeat failures.3345* @hldio: describes habanalabs direct storage interaction interface.3346* @irq_affinity_mask: mask of available CPU cores for user and decoder interrupt handling.3347* @stream_master_qid_arr: pointer to array with QIDs of master streams.3348* @fw_inner_major_ver: the major of current loaded preboot inner version.3349* @fw_inner_minor_ver: the minor of current loaded preboot inner version.3350* @fw_sw_major_ver: the major of current loaded preboot SW version.3351* @fw_sw_minor_ver: the minor of current loaded preboot SW version.3352* @fw_sw_sub_minor_ver: the sub-minor of current loaded preboot SW version.3353* @dram_used_mem: current DRAM memory consumption.3354* @memory_scrub_val: the value to which the dram will be scrubbed to using cb scrub_device_dram3355* @timeout_jiffies: device CS timeout value.3356* @max_power: the max power of the device, as configured by the sysadmin. This3357* value is saved so in case of hard-reset, the driver will restore3358* this value and update the F/W after the re-initialization3359* @boot_error_status_mask: contains a mask of the device boot error status.3360* Each bit represents a different error, according to3361* the defines in hl_boot_if.h. If the bit is cleared,3362* the error will be ignored by the driver during3363* device initialization. Mainly used to debug and3364* workaround firmware bugs3365* @dram_pci_bar_start: start bus address of PCIe bar towards DRAM.3366* @last_successful_open_ktime: timestamp (ktime) of the last successful device open.3367* @last_successful_open_jif: timestamp (jiffies) of the last successful3368* device open.3369* @last_open_session_duration_jif: duration (jiffies) of the last device open3370* session.3371* @open_counter: number of successful device open operations.3372* @fw_poll_interval_usec: FW status poll interval in usec.3373* used for CPU boot status3374* @fw_comms_poll_interval_usec: FW comms/protocol poll interval in usec.3375* used for COMMs protocols cmds(COMMS_STS_*)3376* @dram_binning: contains mask of drams that is received from the f/w which indicates which3377* drams are binned-out3378* @tpc_binning: contains mask of tpc engines that is received from the f/w which indicates which3379* tpc engines are binned-out3380* @dmabuf_export_cnt: number of dma-buf exporting.3381* @card_type: Various ASICs have several card types. This indicates the card3382* type of the current device.3383* @major: habanalabs kernel driver major.3384* @high_pll: high PLL profile frequency.3385* @decoder_binning: contains mask of decoder engines that is received from the f/w which3386* indicates which decoder engines are binned-out3387* @edma_binning: contains mask of edma engines that is received from the f/w which3388* indicates which edma engines are binned-out3389* @device_release_watchdog_timeout_sec: device release watchdog timeout value in seconds.3390* @rotator_binning: contains mask of rotators engines that is received from the f/w3391* which indicates which rotator engines are binned-out(Gaudi3 and above).3392* @id: device minor.3393* @cdev_idx: char device index.3394* @cpu_pci_msb_addr: 50-bit extension bits for the device CPU's 40-bit3395* addresses.3396* @is_in_dram_scrub: true if dram scrub operation is on going.3397* @disabled: is device disabled.3398* @cpld_shutdown: is cpld shutdown.3399* @late_init_done: is late init stage was done during initialization.3400* @hwmon_initialized: is H/W monitor sensors was initialized.3401* @reset_on_lockup: true if a reset should be done in case of stuck CS, false3402* otherwise.3403* @dram_default_page_mapping: is DRAM default page mapping enabled.3404* @memory_scrub: true to perform device memory scrub in various locations,3405* such as context-switch, context close, page free, etc.3406* @pmmu_huge_range: is a different virtual addresses range used for PMMU with3407* huge pages.3408* @init_done: is the initialization of the device done.3409* @device_cpu_disabled: is the device CPU disabled (due to timeouts)3410* @in_debug: whether the device is in a state where the profiling/tracing infrastructure3411* can be used. This indication is needed because in some ASICs we need to do3412* specific operations to enable that infrastructure.3413* @cdev_sysfs_debugfs_created: were char devices and sysfs/debugfs files created.3414* @stop_on_err: true if engines should stop on error.3415* @supports_sync_stream: is sync stream supported.3416* @sync_stream_queue_idx: helper index for sync stream queues initialization.3417* @collective_mon_idx: helper index for collective initialization3418* @supports_coresight: is CoreSight supported.3419* @supports_cb_mapping: is mapping a CB to the device's MMU supported.3420* @process_kill_trial_cnt: number of trials reset thread tried killing3421* user processes3422* @device_fini_pending: true if device_fini was called and might be3423* waiting for the reset thread to finish3424* @supports_staged_submission: true if staged submissions are supported3425* @device_cpu_is_halted: Flag to indicate whether the device CPU was already3426* halted. We can't halt it again because the COMMS3427* protocol will throw an error. Relevant only for3428* cases where Linux was not loaded to device CPU3429* @supports_wait_for_multi_cs: true if wait for multi CS is supported3430* @is_compute_ctx_active: Whether there is an active compute context executing.3431* @compute_ctx_in_release: true if the current compute context is being released.3432* @supports_mmu_prefetch: true if prefetch is supported, otherwise false.3433* @reset_upon_device_release: reset the device when the user closes the file descriptor of the3434* device.3435* @supports_ctx_switch: true if a ctx switch is required upon first submission.3436* @support_preboot_binning: true if we support read binning info from preboot.3437* @eq_heartbeat_received: indication that eq heartbeat event has received from FW.3438* @nic_ports_mask: Controls which NIC ports are enabled. Used only for testing.3439* @fw_components: Controls which f/w components to load to the device. There are multiple f/w3440* stages and sometimes we want to stop at a certain stage. Used only for testing.3441* @mmu_disable: Disable the device MMU(s). Used only for testing.3442* @cpu_queues_enable: Whether to enable queues communication vs. the f/w. Used only for testing.3443* @pldm: Whether we are running in Palladium environment. Used only for testing.3444* @hard_reset_on_fw_events: Whether to do device hard-reset when a fatal event is received from3445* the f/w. Used only for testing.3446* @bmc_enable: Whether we are running in a box with BMC. Used only for testing.3447* @reset_on_preboot_fail: Whether to reset the device if preboot f/w fails to load.3448* Used only for testing.3449* @heartbeat: Controls if we want to enable the heartbeat mechanism vs. the f/w, which verifies3450* that the f/w is always alive. Used only for testing.3451*/3452struct hl_device {3453struct pci_dev *pdev;3454u64 pcie_bar_phys[HL_PCI_NUM_BARS];3455void __iomem *pcie_bar[HL_PCI_NUM_BARS];3456void __iomem *rmmio;3457struct drm_device drm;3458struct cdev cdev_ctrl;3459struct device *dev;3460struct device *dev_ctrl;3461struct delayed_work work_heartbeat;3462struct hl_device_reset_work device_reset_work;3463struct hl_device_reset_work device_release_watchdog_work;3464char asic_name[HL_STR_MAX];3465char status[HL_DEV_STS_MAX][HL_STR_MAX];3466enum hl_asic_type asic_type;3467struct hl_cq *completion_queue;3468struct hl_user_interrupt *user_interrupt;3469struct hl_user_interrupt tpc_interrupt;3470struct hl_user_interrupt unexpected_error_interrupt;3471struct hl_user_interrupt common_user_cq_interrupt;3472struct hl_user_interrupt common_decoder_interrupt;3473struct hl_cs **shadow_cs_queue;3474struct workqueue_struct **cq_wq;3475struct workqueue_struct *eq_wq;3476struct workqueue_struct *cs_cmplt_wq;3477struct workqueue_struct *ts_free_obj_wq;3478struct workqueue_struct *prefetch_wq;3479struct workqueue_struct *reset_wq;3480struct hl_ctx *kernel_ctx;3481struct hl_hw_queue *kernel_queues;3482struct list_head cs_mirror_list;3483spinlock_t cs_mirror_lock;3484struct hl_mem_mgr kernel_mem_mgr;3485struct hl_eq event_queue;3486struct dma_pool *dma_pool;3487void *cpu_accessible_dma_mem;3488dma_addr_t cpu_accessible_dma_address;3489struct gen_pool *cpu_accessible_dma_pool;3490unsigned long *asid_bitmap;3491struct mutex asid_mutex;3492struct mutex send_cpu_message_lock;3493struct mutex debug_lock;3494struct mutex mmu_lock;3495struct asic_fixed_properties asic_prop;3496const struct hl_asic_funcs *asic_funcs;3497void *asic_specific;3498struct hl_vm vm;3499struct device *hwmon_dev;3500struct hwmon_chip_info *hl_chip_info;35013502struct hl_dbg_device_entry hl_debugfs;3503struct hl_debugfs_cfg_access debugfs_cfg_accesses;35043505struct list_head cb_pool;3506spinlock_t cb_pool_lock;35073508void *internal_cb_pool_virt_addr;3509dma_addr_t internal_cb_pool_dma_addr;3510struct gen_pool *internal_cb_pool;3511u64 internal_cb_va_base;35123513struct list_head fpriv_list;3514struct list_head fpriv_ctrl_list;3515struct mutex fpriv_list_lock;3516struct mutex fpriv_ctrl_list_lock;35173518struct hl_cs_counters_atomic aggregated_cs_counters;35193520struct hl_mmu_priv mmu_priv;3521struct hl_mmu_funcs mmu_func[MMU_NUM_PGT_LOCATIONS];35223523struct hl_dec *dec;35243525struct fw_load_mgr fw_loader;35263527struct pci_mem_region pci_mem_region[PCI_REGION_NUMBER];35283529struct hl_state_dump_specs state_dump_specs;35303531struct multi_cs_completion multi_cs_completion[3532MULTI_CS_MAX_USER_CTX];3533struct hl_clk_throttle clk_throttling;3534struct hl_error_info captured_err_info;35353536struct hl_reset_info reset_info;35373538struct eq_heartbeat_debug_info heartbeat_debug_info;3539#ifdef CONFIG_HL_HLDIO3540struct hl_dio hldio;3541#endif3542cpumask_t irq_affinity_mask;35433544u32 *stream_master_qid_arr;3545u32 fw_inner_major_ver;3546u32 fw_inner_minor_ver;3547u32 fw_sw_major_ver;3548u32 fw_sw_minor_ver;3549u32 fw_sw_sub_minor_ver;3550atomic64_t dram_used_mem;3551u64 memory_scrub_val;3552u64 timeout_jiffies;3553u64 max_power;3554u64 boot_error_status_mask;3555u64 dram_pci_bar_start;3556u64 last_successful_open_jif;3557u64 last_open_session_duration_jif;3558u64 open_counter;3559u64 fw_poll_interval_usec;3560ktime_t last_successful_open_ktime;3561u64 fw_comms_poll_interval_usec;3562u64 dram_binning;3563u64 tpc_binning;3564atomic_t dmabuf_export_cnt;3565enum cpucp_card_types card_type;3566u32 major;3567u32 high_pll;3568u32 decoder_binning;3569u32 edma_binning;3570u32 device_release_watchdog_timeout_sec;3571u32 rotator_binning;3572u16 id;3573u16 cdev_idx;3574u16 cpu_pci_msb_addr;3575u8 is_in_dram_scrub;3576u8 disabled;3577u8 cpld_shutdown;3578u8 late_init_done;3579u8 hwmon_initialized;3580u8 reset_on_lockup;3581u8 dram_default_page_mapping;3582u8 memory_scrub;3583u8 pmmu_huge_range;3584u8 init_done;3585u8 device_cpu_disabled;3586u8 in_debug;3587u8 cdev_sysfs_debugfs_created;3588u8 stop_on_err;3589u8 supports_sync_stream;3590u8 sync_stream_queue_idx;3591u8 collective_mon_idx;3592u8 supports_coresight;3593u8 supports_cb_mapping;3594u8 process_kill_trial_cnt;3595u8 device_fini_pending;3596u8 supports_staged_submission;3597u8 device_cpu_is_halted;3598u8 supports_wait_for_multi_cs;3599u8 stream_master_qid_arr_size;3600u8 is_compute_ctx_active;3601u8 compute_ctx_in_release;3602u8 supports_mmu_prefetch;3603u8 reset_upon_device_release;3604u8 supports_ctx_switch;3605u8 support_preboot_binning;3606u8 eq_heartbeat_received;36073608/* Parameters for bring-up to be upstreamed */3609u64 nic_ports_mask;3610u64 fw_components;3611u8 mmu_disable;3612u8 cpu_queues_enable;3613u8 pldm;3614u8 hard_reset_on_fw_events;3615u8 bmc_enable;3616u8 reset_on_preboot_fail;3617u8 heartbeat;3618};36193620/* Retrieve PCI device name in case of a PCI device or dev name in simulator */3621#define HL_DEV_NAME(hdev) \3622((hdev)->pdev ? dev_name(&(hdev)->pdev->dev) : "NA-DEVICE")36233624/**3625* struct hl_cs_encaps_sig_handle - encapsulated signals handle structure3626* @refcount: refcount used to protect removing this id when several3627* wait cs are used to wait of the reserved encaps signals.3628* @hdev: pointer to habanalabs device structure.3629* @hw_sob: pointer to H/W SOB used in the reservation.3630* @ctx: pointer to the user's context data structure3631* @cs_seq: staged cs sequence which contains encapsulated signals3632* @id: idr handler id to be used to fetch the handler info3633* @q_idx: stream queue index3634* @pre_sob_val: current SOB value before reservation3635* @count: signals number3636*/3637struct hl_cs_encaps_sig_handle {3638struct kref refcount;3639struct hl_device *hdev;3640struct hl_hw_sob *hw_sob;3641struct hl_ctx *ctx;3642u64 cs_seq;3643u32 id;3644u32 q_idx;3645u32 pre_sob_val;3646u32 count;3647};36483649/**3650* struct hl_info_fw_err_info - firmware error information structure3651* @err_type: The type of error detected (or reported).3652* @event_mask: Pointer to the event mask to be modified with the detected error flag3653* (can be NULL)3654* @event_id: The id of the event that reported the error3655* (applicable when err_type is HL_INFO_FW_REPORTED_ERR).3656*/3657struct hl_info_fw_err_info {3658enum hl_info_fw_err_type err_type;3659u64 *event_mask;3660u16 event_id;3661};36623663/*3664* IOCTLs3665*/36663667/**3668* typedef hl_ioctl_t - typedef for ioctl function in the driver3669* @hpriv: pointer to the FD's private data, which contains state of3670* user process3671* @data: pointer to the input/output arguments structure of the IOCTL3672*3673* Return: 0 for success, negative value for error3674*/3675typedef int hl_ioctl_t(struct hl_fpriv *hpriv, void *data);36763677/**3678* struct hl_ioctl_desc - describes an IOCTL entry of the driver.3679* @cmd: the IOCTL code as created by the kernel macros.3680* @func: pointer to the driver's function that should be called for this IOCTL.3681*/3682struct hl_ioctl_desc {3683unsigned int cmd;3684hl_ioctl_t *func;3685};36863687/*3688* Kernel module functions that can be accessed by entire module3689*/36903691/**3692* hl_get_sg_info() - get number of pages and the DMA address from SG list.3693* @sg: the SG list.3694* @dma_addr: pointer to DMA address to return.3695*3696* Calculate the number of consecutive pages described by the SG list. Take the3697* offset of the address in the first page, add to it the length and round it up3698* to the number of needed pages.3699*/3700static inline u32 hl_get_sg_info(struct scatterlist *sg, dma_addr_t *dma_addr)3701{3702*dma_addr = sg_dma_address(sg);37033704return ((((*dma_addr) & (PAGE_SIZE - 1)) + sg_dma_len(sg)) +3705(PAGE_SIZE - 1)) >> PAGE_SHIFT;3706}37073708/**3709* hl_mem_area_inside_range() - Checks whether address+size are inside a range.3710* @address: The start address of the area we want to validate.3711* @size: The size in bytes of the area we want to validate.3712* @range_start_address: The start address of the valid range.3713* @range_end_address: The end address of the valid range.3714*3715* Return: true if the area is inside the valid range, false otherwise.3716*/3717static inline bool hl_mem_area_inside_range(u64 address, u64 size,3718u64 range_start_address, u64 range_end_address)3719{3720u64 end_address = address + size;37213722if ((address >= range_start_address) &&3723(end_address <= range_end_address) &&3724(end_address > address))3725return true;37263727return false;3728}37293730static inline struct hl_device *to_hl_device(struct drm_device *ddev)3731{3732return container_of(ddev, struct hl_device, drm);3733}37343735/**3736* hl_mem_area_crosses_range() - Checks whether address+size crossing a range.3737* @address: The start address of the area we want to validate.3738* @size: The size in bytes of the area we want to validate.3739* @range_start_address: The start address of the valid range.3740* @range_end_address: The end address of the valid range.3741*3742* Return: true if the area overlaps part or all of the valid range,3743* false otherwise.3744*/3745static inline bool hl_mem_area_crosses_range(u64 address, u32 size,3746u64 range_start_address, u64 range_end_address)3747{3748u64 end_address = address + size - 1;37493750return ((address <= range_end_address) && (range_start_address <= end_address));3751}37523753uint64_t hl_set_dram_bar_default(struct hl_device *hdev, u64 addr);3754void *hl_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size, dma_addr_t *dma_handle);3755void hl_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size, void *vaddr);3756void *hl_asic_dma_alloc_coherent_caller(struct hl_device *hdev, size_t size, dma_addr_t *dma_handle,3757gfp_t flag, const char *caller);3758void hl_asic_dma_free_coherent_caller(struct hl_device *hdev, size_t size, void *cpu_addr,3759dma_addr_t dma_handle, const char *caller);3760void *hl_asic_dma_pool_zalloc_caller(struct hl_device *hdev, size_t size, gfp_t mem_flags,3761dma_addr_t *dma_handle, const char *caller);3762void hl_asic_dma_pool_free_caller(struct hl_device *hdev, void *vaddr, dma_addr_t dma_addr,3763const char *caller);3764int hl_dma_map_sgtable_caller(struct hl_device *hdev, struct sg_table *sgt,3765enum dma_data_direction dir, const char *caller);3766void hl_dma_unmap_sgtable_caller(struct hl_device *hdev, struct sg_table *sgt,3767enum dma_data_direction dir, const char *caller);3768int hl_asic_dma_map_sgtable(struct hl_device *hdev, struct sg_table *sgt,3769enum dma_data_direction dir);3770void hl_asic_dma_unmap_sgtable(struct hl_device *hdev, struct sg_table *sgt,3771enum dma_data_direction dir);3772int hl_access_sram_dram_region(struct hl_device *hdev, u64 addr, u64 *val,3773enum debugfs_access_type acc_type, enum pci_region region_type, bool set_dram_bar);3774int hl_access_cfg_region(struct hl_device *hdev, u64 addr, u64 *val,3775enum debugfs_access_type acc_type);3776int hl_access_dev_mem(struct hl_device *hdev, enum pci_region region_type,3777u64 addr, u64 *val, enum debugfs_access_type acc_type);37783779int hl_mmap(struct file *filp, struct vm_area_struct *vma);37803781int hl_device_open(struct drm_device *drm, struct drm_file *file_priv);3782void hl_device_release(struct drm_device *ddev, struct drm_file *file_priv);37833784int hl_device_open_ctrl(struct inode *inode, struct file *filp);3785bool hl_device_operational(struct hl_device *hdev,3786enum hl_device_status *status);3787bool hl_ctrl_device_operational(struct hl_device *hdev,3788enum hl_device_status *status);3789enum hl_device_status hl_device_status(struct hl_device *hdev);3790int hl_device_set_debug_mode(struct hl_device *hdev, struct hl_ctx *ctx, bool enable);3791int hl_hw_queues_create(struct hl_device *hdev);3792void hl_hw_queues_destroy(struct hl_device *hdev);3793int hl_hw_queue_send_cb_no_cmpl(struct hl_device *hdev, u32 hw_queue_id,3794u32 cb_size, u64 cb_ptr);3795void hl_hw_queue_submit_bd(struct hl_device *hdev, struct hl_hw_queue *q,3796u32 ctl, u32 len, u64 ptr);3797int hl_hw_queue_schedule_cs(struct hl_cs *cs);3798u32 hl_hw_queue_add_ptr(u32 ptr, u16 val);3799void hl_hw_queue_inc_ci_kernel(struct hl_device *hdev, u32 hw_queue_id);3800void hl_hw_queue_update_ci(struct hl_cs *cs);3801void hl_hw_queue_reset(struct hl_device *hdev, bool hard_reset);38023803#define hl_queue_inc_ptr(p) hl_hw_queue_add_ptr(p, 1)3804#define hl_pi_2_offset(pi) ((pi) & (HL_QUEUE_LENGTH - 1))38053806int hl_cq_init(struct hl_device *hdev, struct hl_cq *q, u32 hw_queue_id);3807void hl_cq_fini(struct hl_device *hdev, struct hl_cq *q);3808int hl_eq_init(struct hl_device *hdev, struct hl_eq *q);3809void hl_eq_fini(struct hl_device *hdev, struct hl_eq *q);3810void hl_cq_reset(struct hl_device *hdev, struct hl_cq *q);3811void hl_eq_reset(struct hl_device *hdev, struct hl_eq *q);3812void hl_eq_dump(struct hl_device *hdev, struct hl_eq *q);3813irqreturn_t hl_irq_handler_cq(int irq, void *arg);3814irqreturn_t hl_irq_handler_eq(int irq, void *arg);3815irqreturn_t hl_irq_handler_dec_abnrm(int irq, void *arg);3816irqreturn_t hl_irq_user_interrupt_handler(int irq, void *arg);3817irqreturn_t hl_irq_user_interrupt_thread_handler(int irq, void *arg);3818irqreturn_t hl_irq_eq_error_interrupt_thread_handler(int irq, void *arg);3819u32 hl_cq_inc_ptr(u32 ptr);38203821int hl_asid_init(struct hl_device *hdev);3822void hl_asid_fini(struct hl_device *hdev);3823unsigned long hl_asid_alloc(struct hl_device *hdev);3824void hl_asid_free(struct hl_device *hdev, unsigned long asid);38253826int hl_ctx_create(struct hl_device *hdev, struct hl_fpriv *hpriv);3827void hl_ctx_free(struct hl_device *hdev, struct hl_ctx *ctx);3828int hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx);3829void hl_ctx_do_release(struct kref *ref);3830void hl_ctx_get(struct hl_ctx *ctx);3831int hl_ctx_put(struct hl_ctx *ctx);3832struct hl_ctx *hl_get_compute_ctx(struct hl_device *hdev);3833struct hl_fence *hl_ctx_get_fence(struct hl_ctx *ctx, u64 seq);3834int hl_ctx_get_fences(struct hl_ctx *ctx, u64 *seq_arr,3835struct hl_fence **fence, u32 arr_len);3836void hl_ctx_mgr_init(struct hl_ctx_mgr *mgr);3837void hl_ctx_mgr_fini(struct hl_device *hdev, struct hl_ctx_mgr *mgr);38383839int hl_device_init(struct hl_device *hdev);3840void hl_device_fini(struct hl_device *hdev);3841int hl_device_suspend(struct hl_device *hdev);3842int hl_device_resume(struct hl_device *hdev);3843int hl_device_reset(struct hl_device *hdev, u32 flags);3844int hl_device_cond_reset(struct hl_device *hdev, u32 flags, u64 event_mask);3845void hl_hpriv_get(struct hl_fpriv *hpriv);3846int hl_hpriv_put(struct hl_fpriv *hpriv);3847int hl_device_utilization(struct hl_device *hdev, u32 *utilization);38483849int hl_build_hwmon_channel_info(struct hl_device *hdev,3850struct cpucp_sensor *sensors_arr);38513852void hl_notifier_event_send_all(struct hl_device *hdev, u64 event_mask);38533854int hl_sysfs_init(struct hl_device *hdev);3855void hl_sysfs_fini(struct hl_device *hdev);38563857int hl_hwmon_init(struct hl_device *hdev);3858void hl_hwmon_fini(struct hl_device *hdev);3859void hl_hwmon_release_resources(struct hl_device *hdev);38603861int hl_cb_create(struct hl_device *hdev, struct hl_mem_mgr *mmg,3862struct hl_ctx *ctx, u32 cb_size, bool internal_cb,3863bool map_cb, u64 *handle);3864int hl_cb_destroy(struct hl_mem_mgr *mmg, u64 cb_handle);3865int hl_hw_block_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma);3866struct hl_cb *hl_cb_get(struct hl_mem_mgr *mmg, u64 handle);3867void hl_cb_put(struct hl_cb *cb);3868struct hl_cb *hl_cb_kernel_create(struct hl_device *hdev, u32 cb_size,3869bool internal_cb);3870int hl_cb_pool_init(struct hl_device *hdev);3871int hl_cb_pool_fini(struct hl_device *hdev);3872int hl_cb_va_pool_init(struct hl_ctx *ctx);3873void hl_cb_va_pool_fini(struct hl_ctx *ctx);38743875void hl_cs_rollback_all(struct hl_device *hdev, bool skip_wq_flush);3876struct hl_cs_job *hl_cs_allocate_job(struct hl_device *hdev,3877enum hl_queue_type queue_type, bool is_kernel_allocated_cb);3878void hl_sob_reset_error(struct kref *ref);3879int hl_gen_sob_mask(u16 sob_base, u8 sob_mask, u8 *mask);3880void hl_fence_put(struct hl_fence *fence);3881void hl_fences_put(struct hl_fence **fence, int len);3882void hl_fence_get(struct hl_fence *fence);3883void cs_get(struct hl_cs *cs);3884bool cs_needs_completion(struct hl_cs *cs);3885bool cs_needs_timeout(struct hl_cs *cs);3886bool is_staged_cs_last_exists(struct hl_device *hdev, struct hl_cs *cs);3887struct hl_cs *hl_staged_cs_find_first(struct hl_device *hdev, u64 cs_seq);3888void hl_multi_cs_completion_init(struct hl_device *hdev);3889u32 hl_get_active_cs_num(struct hl_device *hdev);38903891void goya_set_asic_funcs(struct hl_device *hdev);3892void gaudi_set_asic_funcs(struct hl_device *hdev);3893void gaudi2_set_asic_funcs(struct hl_device *hdev);38943895int hl_vm_ctx_init(struct hl_ctx *ctx);3896void hl_vm_ctx_fini(struct hl_ctx *ctx);38973898int hl_vm_init(struct hl_device *hdev);3899void hl_vm_fini(struct hl_device *hdev);39003901void hl_hw_block_mem_init(struct hl_ctx *ctx);3902void hl_hw_block_mem_fini(struct hl_ctx *ctx);39033904u64 hl_reserve_va_block(struct hl_device *hdev, struct hl_ctx *ctx,3905enum hl_va_range_type type, u64 size, u32 alignment);3906int hl_unreserve_va_block(struct hl_device *hdev, struct hl_ctx *ctx,3907u64 start_addr, u64 size);3908int hl_pin_host_memory(struct hl_device *hdev, u64 addr, u64 size,3909struct hl_userptr *userptr);3910void hl_unpin_host_memory(struct hl_device *hdev, struct hl_userptr *userptr);3911void hl_userptr_delete_list(struct hl_device *hdev,3912struct list_head *userptr_list);3913bool hl_userptr_is_pinned(struct hl_device *hdev, u64 addr, u32 size,3914struct list_head *userptr_list,3915struct hl_userptr **userptr);39163917int hl_mmu_init(struct hl_device *hdev);3918void hl_mmu_fini(struct hl_device *hdev);3919int hl_mmu_ctx_init(struct hl_ctx *ctx);3920void hl_mmu_ctx_fini(struct hl_ctx *ctx);3921int hl_mmu_map_page(struct hl_ctx *ctx, u64 virt_addr, u64 phys_addr,3922u32 page_size, bool flush_pte);3923int hl_mmu_get_real_page_size(struct hl_device *hdev, struct hl_mmu_properties *mmu_prop,3924u32 page_size, u32 *real_page_size, bool is_dram_addr);3925int hl_mmu_unmap_page(struct hl_ctx *ctx, u64 virt_addr, u32 page_size,3926bool flush_pte);3927int hl_mmu_map_contiguous(struct hl_ctx *ctx, u64 virt_addr,3928u64 phys_addr, u32 size);3929int hl_mmu_unmap_contiguous(struct hl_ctx *ctx, u64 virt_addr, u32 size);3930int hl_mmu_invalidate_cache(struct hl_device *hdev, bool is_hard, u32 flags);3931int hl_mmu_invalidate_cache_range(struct hl_device *hdev, bool is_hard,3932u32 flags, u32 asid, u64 va, u64 size);3933int hl_mmu_prefetch_cache_range(struct hl_ctx *ctx, u32 flags, u32 asid, u64 va, u64 size);3934u64 hl_mmu_get_next_hop_addr(struct hl_ctx *ctx, u64 curr_pte);3935u64 hl_mmu_get_hop_pte_phys_addr(struct hl_ctx *ctx, struct hl_mmu_properties *mmu_prop,3936u8 hop_idx, u64 hop_addr, u64 virt_addr);3937void hl_mmu_hr_flush(struct hl_ctx *ctx);3938int hl_mmu_hr_init(struct hl_device *hdev, struct hl_mmu_hr_priv *hr_priv, u32 hop_table_size,3939u64 pgt_size);3940void hl_mmu_hr_fini(struct hl_device *hdev, struct hl_mmu_hr_priv *hr_priv, u32 hop_table_size);3941void hl_mmu_hr_free_hop_remove_pgt(struct pgt_info *pgt_info, struct hl_mmu_hr_priv *hr_priv,3942u32 hop_table_size);3943u64 hl_mmu_hr_pte_phys_to_virt(struct hl_ctx *ctx, struct pgt_info *pgt, u64 phys_pte_addr,3944u32 hop_table_size);3945void hl_mmu_hr_write_pte(struct hl_ctx *ctx, struct pgt_info *pgt_info, u64 phys_pte_addr,3946u64 val, u32 hop_table_size);3947void hl_mmu_hr_clear_pte(struct hl_ctx *ctx, struct pgt_info *pgt_info, u64 phys_pte_addr,3948u32 hop_table_size);3949int hl_mmu_hr_put_pte(struct hl_ctx *ctx, struct pgt_info *pgt_info, struct hl_mmu_hr_priv *hr_priv,3950u32 hop_table_size);3951void hl_mmu_hr_get_pte(struct hl_ctx *ctx, struct hl_hr_mmu_funcs *hr_func, u64 phys_hop_addr);3952struct pgt_info *hl_mmu_hr_get_next_hop_pgt_info(struct hl_ctx *ctx,3953struct hl_hr_mmu_funcs *hr_func,3954u64 curr_pte);3955struct pgt_info *hl_mmu_hr_alloc_hop(struct hl_ctx *ctx, struct hl_mmu_hr_priv *hr_priv,3956struct hl_hr_mmu_funcs *hr_func,3957struct hl_mmu_properties *mmu_prop);3958struct pgt_info *hl_mmu_hr_get_alloc_next_hop(struct hl_ctx *ctx,3959struct hl_mmu_hr_priv *hr_priv,3960struct hl_hr_mmu_funcs *hr_func,3961struct hl_mmu_properties *mmu_prop,3962u64 curr_pte, bool *is_new_hop);3963int hl_mmu_hr_get_tlb_info(struct hl_ctx *ctx, u64 virt_addr, struct hl_mmu_hop_info *hops,3964struct hl_hr_mmu_funcs *hr_func);3965int hl_mmu_if_set_funcs(struct hl_device *hdev);3966void hl_mmu_v1_set_funcs(struct hl_device *hdev, struct hl_mmu_funcs *mmu);3967void hl_mmu_v2_set_funcs(struct hl_device *hdev, struct hl_mmu_funcs *mmu);3968void hl_mmu_v2_hr_set_funcs(struct hl_device *hdev, struct hl_mmu_funcs *mmu);3969int hl_mmu_va_to_pa(struct hl_ctx *ctx, u64 virt_addr, u64 *phys_addr);3970int hl_mmu_get_tlb_info(struct hl_ctx *ctx, u64 virt_addr,3971struct hl_mmu_hop_info *hops);3972u64 hl_mmu_scramble_addr(struct hl_device *hdev, u64 addr);3973u64 hl_mmu_descramble_addr(struct hl_device *hdev, u64 addr);3974bool hl_is_dram_va(struct hl_device *hdev, u64 virt_addr);3975struct pgt_info *hl_mmu_dr_get_pgt_info(struct hl_ctx *ctx, u64 hop_addr);3976void hl_mmu_dr_free_hop(struct hl_ctx *ctx, u64 hop_addr);3977void hl_mmu_dr_free_pgt_node(struct hl_ctx *ctx, struct pgt_info *pgt_info);3978u64 hl_mmu_dr_get_phys_hop0_addr(struct hl_ctx *ctx);3979u64 hl_mmu_dr_get_hop0_addr(struct hl_ctx *ctx);3980void hl_mmu_dr_write_pte(struct hl_ctx *ctx, u64 shadow_pte_addr, u64 val);3981void hl_mmu_dr_write_final_pte(struct hl_ctx *ctx, u64 shadow_pte_addr, u64 val);3982void hl_mmu_dr_clear_pte(struct hl_ctx *ctx, u64 pte_addr);3983u64 hl_mmu_dr_get_phys_addr(struct hl_ctx *ctx, u64 shadow_addr);3984void hl_mmu_dr_get_pte(struct hl_ctx *ctx, u64 hop_addr);3985int hl_mmu_dr_put_pte(struct hl_ctx *ctx, u64 hop_addr);3986u64 hl_mmu_dr_get_alloc_next_hop_addr(struct hl_ctx *ctx, u64 curr_pte, bool *is_new_hop);3987u64 hl_mmu_dr_alloc_hop(struct hl_ctx *ctx);3988void hl_mmu_dr_flush(struct hl_ctx *ctx);3989int hl_mmu_dr_init(struct hl_device *hdev);3990void hl_mmu_dr_fini(struct hl_device *hdev);39913992int hl_fw_version_cmp(struct hl_device *hdev, u32 major, u32 minor, u32 subminor);3993int hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name,3994void __iomem *dst, u32 src_offset, u32 size);3995int hl_fw_send_pci_access_msg(struct hl_device *hdev, u32 opcode, u64 value);3996int hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg,3997u16 len, u32 timeout, u64 *result);3998int hl_fw_unmask_irq(struct hl_device *hdev, u16 event_type);3999int hl_fw_unmask_irq_arr(struct hl_device *hdev, const u32 *irq_arr,4000size_t irq_arr_size);4001int hl_fw_test_cpu_queue(struct hl_device *hdev);4002void *hl_fw_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size,4003dma_addr_t *dma_handle);4004void hl_fw_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size,4005void *vaddr);4006int hl_fw_send_heartbeat(struct hl_device *hdev);4007int hl_fw_cpucp_info_get(struct hl_device *hdev,4008u32 sts_boot_dev_sts0_reg,4009u32 sts_boot_dev_sts1_reg, u32 boot_err0_reg,4010u32 boot_err1_reg);4011int hl_fw_cpucp_handshake(struct hl_device *hdev,4012u32 sts_boot_dev_sts0_reg,4013u32 sts_boot_dev_sts1_reg, u32 boot_err0_reg,4014u32 boot_err1_reg);4015int hl_fw_get_eeprom_data(struct hl_device *hdev, void *data, size_t max_size);4016int hl_fw_get_monitor_dump(struct hl_device *hdev, void *data);4017int hl_fw_cpucp_pci_counters_get(struct hl_device *hdev,4018struct hl_info_pci_counters *counters);4019int hl_fw_cpucp_total_energy_get(struct hl_device *hdev,4020u64 *total_energy);4021int get_used_pll_index(struct hl_device *hdev, u32 input_pll_index,4022enum pll_index *pll_index);4023int hl_fw_cpucp_pll_info_get(struct hl_device *hdev, u32 pll_index,4024u16 *pll_freq_arr);4025int hl_fw_cpucp_power_get(struct hl_device *hdev, u64 *power);4026void hl_fw_ask_hard_reset_without_linux(struct hl_device *hdev);4027void hl_fw_ask_halt_machine_without_linux(struct hl_device *hdev);4028int hl_fw_init_cpu(struct hl_device *hdev);4029int hl_fw_wait_preboot_ready(struct hl_device *hdev);4030int hl_fw_read_preboot_status(struct hl_device *hdev);4031int hl_fw_dynamic_send_protocol_cmd(struct hl_device *hdev,4032struct fw_load_mgr *fw_loader,4033enum comms_cmd cmd, unsigned int size,4034bool wait_ok, u32 timeout);4035int hl_fw_dram_replaced_row_get(struct hl_device *hdev,4036struct cpucp_hbm_row_info *info);4037int hl_fw_dram_pending_row_get(struct hl_device *hdev, u32 *pend_rows_num);4038int hl_fw_cpucp_engine_core_asid_set(struct hl_device *hdev, u32 asid);4039int hl_fw_send_device_activity(struct hl_device *hdev, bool open);4040int hl_fw_send_soft_reset(struct hl_device *hdev);4041int hl_pci_bars_map(struct hl_device *hdev, const char * const name[3],4042bool is_wc[3]);4043int hl_pci_elbi_read(struct hl_device *hdev, u64 addr, u32 *data);4044int hl_pci_iatu_write(struct hl_device *hdev, u32 addr, u32 data);4045int hl_pci_set_inbound_region(struct hl_device *hdev, u8 region,4046struct hl_inbound_pci_region *pci_region);4047int hl_pci_set_outbound_region(struct hl_device *hdev,4048struct hl_outbound_pci_region *pci_region);4049enum pci_region hl_get_pci_memory_region(struct hl_device *hdev, u64 addr);4050int hl_pci_init(struct hl_device *hdev);4051void hl_pci_fini(struct hl_device *hdev);40524053long hl_fw_get_frequency(struct hl_device *hdev, u32 pll_index, bool curr);4054void hl_fw_set_frequency(struct hl_device *hdev, u32 pll_index, u64 freq);4055int hl_get_temperature(struct hl_device *hdev, int sensor_index, u32 attr, long *value);4056int hl_set_temperature(struct hl_device *hdev, int sensor_index, u32 attr, long value);4057int hl_get_voltage(struct hl_device *hdev, int sensor_index, u32 attr, long *value);4058int hl_get_current(struct hl_device *hdev, int sensor_index, u32 attr, long *value);4059int hl_get_fan_speed(struct hl_device *hdev, int sensor_index, u32 attr, long *value);4060int hl_get_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr, long *value);4061void hl_set_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr, long value);4062long hl_fw_get_max_power(struct hl_device *hdev);4063void hl_fw_set_max_power(struct hl_device *hdev);4064int hl_fw_get_sec_attest_info(struct hl_device *hdev, struct cpucp_sec_attest_info *sec_attest_info,4065u32 nonce);4066int hl_fw_get_dev_info_signed(struct hl_device *hdev,4067struct cpucp_dev_info_signed *dev_info_signed, u32 nonce);4068int hl_set_voltage(struct hl_device *hdev, int sensor_index, u32 attr, long value);4069int hl_set_current(struct hl_device *hdev, int sensor_index, u32 attr, long value);4070int hl_set_power(struct hl_device *hdev, int sensor_index, u32 attr, long value);4071int hl_get_power(struct hl_device *hdev, int sensor_index, u32 attr, long *value);4072int hl_fw_get_clk_rate(struct hl_device *hdev, u32 *cur_clk, u32 *max_clk);4073void hl_fw_set_pll_profile(struct hl_device *hdev);4074void hl_sysfs_add_dev_clk_attr(struct hl_device *hdev, struct attribute_group *dev_clk_attr_grp);4075void hl_sysfs_add_dev_vrm_attr(struct hl_device *hdev, struct attribute_group *dev_vrm_attr_grp);4076int hl_fw_send_generic_request(struct hl_device *hdev, enum hl_passthrough_type sub_opcode,4077dma_addr_t buff, u32 *size);40784079void hw_sob_get(struct hl_hw_sob *hw_sob);4080void hw_sob_put(struct hl_hw_sob *hw_sob);4081void hl_encaps_release_handle_and_put_ctx(struct kref *ref);4082void hl_encaps_release_handle_and_put_sob_ctx(struct kref *ref);4083void hl_hw_queue_encaps_sig_set_sob_info(struct hl_device *hdev,4084struct hl_cs *cs, struct hl_cs_job *job,4085struct hl_cs_compl *cs_cmpl);40864087int hl_dec_init(struct hl_device *hdev);4088void hl_dec_fini(struct hl_device *hdev);4089void hl_dec_ctx_fini(struct hl_ctx *ctx);40904091void hl_release_pending_user_interrupts(struct hl_device *hdev);4092void hl_abort_waiting_for_cs_completions(struct hl_device *hdev);4093int hl_cs_signal_sob_wraparound_handler(struct hl_device *hdev, u32 q_idx,4094struct hl_hw_sob **hw_sob, u32 count, bool encaps_sig);40954096int hl_state_dump(struct hl_device *hdev);4097const char *hl_state_dump_get_sync_name(struct hl_device *hdev, u32 sync_id);4098const char *hl_state_dump_get_monitor_name(struct hl_device *hdev,4099struct hl_mon_state_dump *mon);4100void hl_state_dump_free_sync_to_engine_map(struct hl_sync_to_engine_map *map);4101__printf(4, 5) int hl_snprintf_resize(char **buf, size_t *size, size_t *offset,4102const char *format, ...);4103char *hl_format_as_binary(char *buf, size_t buf_len, u32 n);4104const char *hl_sync_engine_to_string(enum hl_sync_engine_type engine_type);41054106void hl_mem_mgr_init(struct device *dev, struct hl_mem_mgr *mmg);4107void hl_mem_mgr_fini(struct hl_mem_mgr *mmg, struct hl_mem_mgr_fini_stats *stats);4108void hl_mem_mgr_idr_destroy(struct hl_mem_mgr *mmg);4109int hl_mem_mgr_mmap(struct hl_mem_mgr *mmg, struct vm_area_struct *vma,4110void *args);4111struct hl_mmap_mem_buf *hl_mmap_mem_buf_get(struct hl_mem_mgr *mmg,4112u64 handle);4113int hl_mmap_mem_buf_put_handle(struct hl_mem_mgr *mmg, u64 handle);4114int hl_mmap_mem_buf_put(struct hl_mmap_mem_buf *buf);4115struct hl_mmap_mem_buf *4116hl_mmap_mem_buf_alloc(struct hl_mem_mgr *mmg,4117struct hl_mmap_mem_buf_behavior *behavior, gfp_t gfp,4118void *args);4119__printf(2, 3) void hl_engine_data_sprintf(struct engines_data *e, const char *fmt, ...);4120void hl_capture_razwi(struct hl_device *hdev, u64 addr, u16 *engine_id, u16 num_of_engines,4121u8 flags);4122void hl_handle_razwi(struct hl_device *hdev, u64 addr, u16 *engine_id, u16 num_of_engines,4123u8 flags, u64 *event_mask);4124void hl_capture_page_fault(struct hl_device *hdev, u64 addr, u16 eng_id, bool is_pmmu);4125void hl_handle_page_fault(struct hl_device *hdev, u64 addr, u16 eng_id, bool is_pmmu,4126u64 *event_mask);4127void hl_handle_critical_hw_err(struct hl_device *hdev, u16 event_id, u64 *event_mask);4128void hl_handle_fw_err(struct hl_device *hdev, struct hl_info_fw_err_info *info);4129void hl_capture_engine_err(struct hl_device *hdev, u16 engine_id, u16 error_count);4130void hl_enable_err_info_capture(struct hl_error_info *captured_err_info);4131void hl_init_cpu_for_irq(struct hl_device *hdev);4132void hl_set_irq_affinity(struct hl_device *hdev, int irq);4133void hl_eq_heartbeat_event_handle(struct hl_device *hdev);4134void hl_handle_clk_change_event(struct hl_device *hdev, u16 event_type, u64 *event_mask);4135void hl_eq_cpld_shutdown_event_handle(struct hl_device *hdev, u16 event_id, u64 *event_mask);41364137#ifdef CONFIG_DEBUG_FS41384139int hl_debugfs_device_init(struct hl_device *hdev);4140void hl_debugfs_device_fini(struct hl_device *hdev);4141void hl_debugfs_add_device(struct hl_device *hdev);4142void hl_debugfs_add_file(struct hl_fpriv *hpriv);4143void hl_debugfs_remove_file(struct hl_fpriv *hpriv);4144void hl_debugfs_add_cb(struct hl_cb *cb);4145void hl_debugfs_remove_cb(struct hl_cb *cb);4146void hl_debugfs_add_cs(struct hl_cs *cs);4147void hl_debugfs_remove_cs(struct hl_cs *cs);4148void hl_debugfs_add_job(struct hl_device *hdev, struct hl_cs_job *job);4149void hl_debugfs_remove_job(struct hl_device *hdev, struct hl_cs_job *job);4150void hl_debugfs_add_userptr(struct hl_device *hdev, struct hl_userptr *userptr);4151void hl_debugfs_remove_userptr(struct hl_device *hdev,4152struct hl_userptr *userptr);4153void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx);4154void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx);4155void hl_debugfs_set_state_dump(struct hl_device *hdev, char *data,4156unsigned long length);4157void hl_debugfs_cfg_access_history_dump(struct hl_device *hdev);41584159#else41604161static inline int hl_debugfs_device_init(struct hl_device *hdev)4162{4163return 0;4164}41654166static inline void hl_debugfs_device_fini(struct hl_device *hdev)4167{4168}41694170static inline void hl_debugfs_add_device(struct hl_device *hdev)4171{4172}41734174static inline void hl_debugfs_add_file(struct hl_fpriv *hpriv)4175{4176}41774178static inline void hl_debugfs_remove_file(struct hl_fpriv *hpriv)4179{4180}41814182static inline void hl_debugfs_add_cb(struct hl_cb *cb)4183{4184}41854186static inline void hl_debugfs_remove_cb(struct hl_cb *cb)4187{4188}41894190static inline void hl_debugfs_add_cs(struct hl_cs *cs)4191{4192}41934194static inline void hl_debugfs_remove_cs(struct hl_cs *cs)4195{4196}41974198static inline void hl_debugfs_add_job(struct hl_device *hdev,4199struct hl_cs_job *job)4200{4201}42024203static inline void hl_debugfs_remove_job(struct hl_device *hdev,4204struct hl_cs_job *job)4205{4206}42074208static inline void hl_debugfs_add_userptr(struct hl_device *hdev,4209struct hl_userptr *userptr)4210{4211}42124213static inline void hl_debugfs_remove_userptr(struct hl_device *hdev,4214struct hl_userptr *userptr)4215{4216}42174218static inline void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev,4219struct hl_ctx *ctx)4220{4221}42224223static inline void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev,4224struct hl_ctx *ctx)4225{4226}42274228static inline void hl_debugfs_set_state_dump(struct hl_device *hdev,4229char *data, unsigned long length)4230{4231}42324233static inline void hl_debugfs_cfg_access_history_dump(struct hl_device *hdev)4234{4235}42364237#endif42384239/* Security */4240int hl_unsecure_register(struct hl_device *hdev, u32 mm_reg_addr, int offset,4241const u32 pb_blocks[], struct hl_block_glbl_sec sgs_array[],4242int array_size);4243int hl_unsecure_registers(struct hl_device *hdev, const u32 mm_reg_array[],4244int mm_array_size, int offset, const u32 pb_blocks[],4245struct hl_block_glbl_sec sgs_array[], int blocks_array_size);4246void hl_config_glbl_sec(struct hl_device *hdev, const u32 pb_blocks[],4247struct hl_block_glbl_sec sgs_array[], u32 block_offset,4248int array_size);4249void hl_secure_block(struct hl_device *hdev,4250struct hl_block_glbl_sec sgs_array[], int array_size);4251int hl_init_pb_with_mask(struct hl_device *hdev, u32 num_dcores,4252u32 dcore_offset, u32 num_instances, u32 instance_offset,4253const u32 pb_blocks[], u32 blocks_array_size,4254const u32 *regs_array, u32 regs_array_size, u64 mask);4255int hl_init_pb(struct hl_device *hdev, u32 num_dcores, u32 dcore_offset,4256u32 num_instances, u32 instance_offset,4257const u32 pb_blocks[], u32 blocks_array_size,4258const u32 *regs_array, u32 regs_array_size);4259int hl_init_pb_ranges_with_mask(struct hl_device *hdev, u32 num_dcores,4260u32 dcore_offset, u32 num_instances, u32 instance_offset,4261const u32 pb_blocks[], u32 blocks_array_size,4262const struct range *regs_range_array, u32 regs_range_array_size,4263u64 mask);4264int hl_init_pb_ranges(struct hl_device *hdev, u32 num_dcores,4265u32 dcore_offset, u32 num_instances, u32 instance_offset,4266const u32 pb_blocks[], u32 blocks_array_size,4267const struct range *regs_range_array,4268u32 regs_range_array_size);4269int hl_init_pb_single_dcore(struct hl_device *hdev, u32 dcore_offset,4270u32 num_instances, u32 instance_offset,4271const u32 pb_blocks[], u32 blocks_array_size,4272const u32 *regs_array, u32 regs_array_size);4273int hl_init_pb_ranges_single_dcore(struct hl_device *hdev, u32 dcore_offset,4274u32 num_instances, u32 instance_offset,4275const u32 pb_blocks[], u32 blocks_array_size,4276const struct range *regs_range_array,4277u32 regs_range_array_size);4278void hl_ack_pb(struct hl_device *hdev, u32 num_dcores, u32 dcore_offset,4279u32 num_instances, u32 instance_offset,4280const u32 pb_blocks[], u32 blocks_array_size);4281void hl_ack_pb_with_mask(struct hl_device *hdev, u32 num_dcores,4282u32 dcore_offset, u32 num_instances, u32 instance_offset,4283const u32 pb_blocks[], u32 blocks_array_size, u64 mask);4284void hl_ack_pb_single_dcore(struct hl_device *hdev, u32 dcore_offset,4285u32 num_instances, u32 instance_offset,4286const u32 pb_blocks[], u32 blocks_array_size);42874288/* IOCTLs */4289long hl_ioctl_control(struct file *filep, unsigned int cmd, unsigned long arg);4290int hl_info_ioctl(struct drm_device *ddev, void *data, struct drm_file *file_priv);4291int hl_cb_ioctl(struct drm_device *ddev, void *data, struct drm_file *file_priv);4292int hl_cs_ioctl(struct drm_device *ddev, void *data, struct drm_file *file_priv);4293int hl_wait_ioctl(struct drm_device *ddev, void *data, struct drm_file *file_priv);4294int hl_mem_ioctl(struct drm_device *ddev, void *data, struct drm_file *file_priv);4295int hl_debug_ioctl(struct drm_device *ddev, void *data, struct drm_file *file_priv);42964297#endif /* HABANALABSP_H_ */429842994300