0001
0002
0003
0004
0005
0006
0007
0008 #ifndef HABANALABSP_H_
0009 #define HABANALABSP_H_
0010
0011 #include "../include/common/cpucp_if.h"
0012 #include "../include/common/qman_if.h"
0013 #include "../include/hw_ip/mmu/mmu_general.h"
0014 #include <uapi/misc/habanalabs.h>
0015
0016 #include <linux/cdev.h>
0017 #include <linux/iopoll.h>
0018 #include <linux/irqreturn.h>
0019 #include <linux/dma-direction.h>
0020 #include <linux/scatterlist.h>
0021 #include <linux/hashtable.h>
0022 #include <linux/debugfs.h>
0023 #include <linux/rwsem.h>
0024 #include <linux/eventfd.h>
0025 #include <linux/bitfield.h>
0026 #include <linux/genalloc.h>
0027 #include <linux/sched/signal.h>
0028 #include <linux/io-64-nonatomic-lo-hi.h>
0029 #include <linux/coresight.h>
0030 #include <linux/dma-buf.h>
0031
0032 #define HL_NAME "habanalabs"
0033
0034 struct hl_device;
0035 struct hl_fpriv;
0036
0037
0038
0039
0040
0041
0042
0043
0044 #define HL_MMAP_TYPE_SHIFT (59 - PAGE_SHIFT)
0045 #define HL_MMAP_TYPE_MASK (0x1full << HL_MMAP_TYPE_SHIFT)
0046 #define HL_MMAP_TYPE_TS_BUFF (0x10ull << HL_MMAP_TYPE_SHIFT)
0047 #define HL_MMAP_TYPE_BLOCK (0x4ull << HL_MMAP_TYPE_SHIFT)
0048 #define HL_MMAP_TYPE_CB (0x2ull << HL_MMAP_TYPE_SHIFT)
0049
0050 #define HL_MMAP_OFFSET_VALUE_MASK (0x1FFFFFFFFFFFull >> PAGE_SHIFT)
0051 #define HL_MMAP_OFFSET_VALUE_GET(off) (off & HL_MMAP_OFFSET_VALUE_MASK)
0052
0053 #define HL_PENDING_RESET_PER_SEC 10
0054 #define HL_PENDING_RESET_MAX_TRIALS 60
0055 #define HL_PENDING_RESET_LONG_SEC 60
0056
0057 #define HL_HARD_RESET_MAX_TIMEOUT 120
0058 #define HL_PLDM_HARD_RESET_MAX_TIMEOUT (HL_HARD_RESET_MAX_TIMEOUT * 3)
0059
0060 #define HL_DEVICE_TIMEOUT_USEC 1000000
0061
0062 #define HL_HEARTBEAT_PER_USEC 5000000
0063
0064 #define HL_PLL_LOW_JOB_FREQ_USEC 5000000
0065
0066 #define HL_CPUCP_INFO_TIMEOUT_USEC 10000000
0067 #define HL_CPUCP_EEPROM_TIMEOUT_USEC 10000000
0068 #define HL_CPUCP_MON_DUMP_TIMEOUT_USEC 10000000
0069
0070 #define HL_FW_STATUS_POLL_INTERVAL_USEC 10000
0071 #define HL_FW_COMMS_STATUS_PLDM_POLL_INTERVAL_USEC 1000000
0072
0073 #define HL_PCI_ELBI_TIMEOUT_MSEC 10
0074
0075 #define HL_SIM_MAX_TIMEOUT_US 100000000
0076
0077 #define HL_INVALID_QUEUE UINT_MAX
0078
0079 #define HL_COMMON_USER_CQ_INTERRUPT_ID 0xFFF
0080 #define HL_COMMON_DEC_INTERRUPT_ID 0xFFE
0081
0082 #define HL_STATE_DUMP_HIST_LEN 5
0083
0084
0085 #define HL_RESET_TRIGGER_DEFAULT 0xFF
0086
0087 #define OBJ_NAMES_HASH_TABLE_BITS 7
0088 #define SYNC_TO_ENGINE_HASH_TABLE_BITS 7
0089
0090
0091 #define MEM_HASH_TABLE_BITS 7
0092
0093
0094 #define MMU_HASH_TABLE_BITS 7
0095
0096
0097
0098
0099
0100
0101
0102 enum hl_mmu_page_table_location {
0103 MMU_DR_PGT = 0,
0104 MMU_HR_PGT,
0105 MMU_NUM_PGT_LOCATIONS
0106 };
0107
0108
0109
0110
0111
0112
0113
0114 enum hl_mmu_enablement {
0115 MMU_EN_NONE = 0,
0116 MMU_EN_ALL = 1,
0117 MMU_EN_PMMU_ONLY = 3,
0118 };
0119
0120
0121
0122
0123
0124 #define HL_RSVD_SOBS 2
0125 #define HL_RSVD_MONS 1
0126
0127
0128
0129
0130 #define HL_COLLECTIVE_RSVD_MSTR_MONS 2
0131
0132 #define HL_MAX_SOB_VAL (1 << 15)
0133
0134 #define IS_POWER_OF_2(n) (n != 0 && ((n & (n - 1)) == 0))
0135 #define IS_MAX_PENDING_CS_VALID(n) (IS_POWER_OF_2(n) && (n > 1))
0136
0137 #define HL_PCI_NUM_BARS 6
0138
0139
0140 #define HL_COMPLETION_MODE_JOB 0
0141
0142 #define HL_COMPLETION_MODE_CS 1
0143
0144 #define HL_MAX_DCORES 8
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176 #define HL_DRV_RESET_HARD (1 << 0)
0177 #define HL_DRV_RESET_FROM_RESET_THR (1 << 1)
0178 #define HL_DRV_RESET_HEARTBEAT (1 << 2)
0179 #define HL_DRV_RESET_TDR (1 << 3)
0180 #define HL_DRV_RESET_DEV_RELEASE (1 << 4)
0181 #define HL_DRV_RESET_BYPASS_REQ_TO_FW (1 << 5)
0182 #define HL_DRV_RESET_FW_FATAL_ERR (1 << 6)
0183 #define HL_DRV_RESET_DELAY (1 << 7)
0184
0185
0186
0187
0188
0189 #define HL_PB_SHARED 1
0190 #define HL_PB_NA 0
0191 #define HL_PB_SINGLE_INSTANCE 1
0192 #define HL_BLOCK_SIZE 0x1000
0193 #define HL_BLOCK_GLBL_ERR_MASK 0xF40
0194 #define HL_BLOCK_GLBL_ERR_ADDR 0xF44
0195 #define HL_BLOCK_GLBL_ERR_CAUSE 0xF48
0196 #define HL_BLOCK_GLBL_SEC_OFFS 0xF80
0197 #define HL_BLOCK_GLBL_SEC_SIZE (HL_BLOCK_SIZE - HL_BLOCK_GLBL_SEC_OFFS)
0198 #define HL_BLOCK_GLBL_SEC_LEN (HL_BLOCK_GLBL_SEC_SIZE / sizeof(u32))
0199 #define UNSET_GLBL_SEC_BIT(array, b) ((array)[((b) / 32)] |= (1 << ((b) % 32)))
0200
0201 enum hl_protection_levels {
0202 SECURED_LVL,
0203 PRIVILEGED_LVL,
0204 NON_SECURED_LVL
0205 };
0206
0207
0208
0209
0210
0211
0212 struct iterate_module_ctx {
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222 void (*fn)(struct hl_device *hdev, int block, int inst, u32 offset, void *data);
0223 void *data;
0224 };
0225
0226 struct hl_block_glbl_sec {
0227 u32 sec_array[HL_BLOCK_GLBL_SEC_LEN];
0228 };
0229
0230 #define HL_MAX_SOBS_PER_MONITOR 8
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242 struct hl_gen_wait_properties {
0243 void *data;
0244 u32 q_idx;
0245 u32 size;
0246 u16 sob_base;
0247 u16 sob_val;
0248 u16 mon_id;
0249 u8 sob_mask;
0250 };
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271 struct pgt_info {
0272 struct hlist_node node;
0273 u64 phys_addr;
0274 u64 virt_addr;
0275 u64 shadow_addr;
0276 struct hl_ctx *ctx;
0277 int num_of_ptes;
0278 };
0279
0280
0281
0282
0283
0284
0285 enum hl_pci_match_mode {
0286 PCI_ADDRESS_MATCH_MODE,
0287 PCI_BAR_MATCH_MODE
0288 };
0289
0290
0291
0292
0293
0294
0295
0296 enum hl_fw_component {
0297 FW_COMP_BOOT_FIT,
0298 FW_COMP_PREBOOT,
0299 FW_COMP_LINUX,
0300 };
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311 enum hl_fw_types {
0312 FW_TYPE_NONE = 0x0,
0313 FW_TYPE_LINUX = 0x1,
0314 FW_TYPE_BOOT_CPU = 0x2,
0315 FW_TYPE_PREBOOT_CPU = 0x4,
0316 FW_TYPE_ALL_TYPES =
0317 (FW_TYPE_LINUX | FW_TYPE_BOOT_CPU | FW_TYPE_PREBOOT_CPU)
0318 };
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331 enum hl_queue_type {
0332 QUEUE_TYPE_NA,
0333 QUEUE_TYPE_EXT,
0334 QUEUE_TYPE_INT,
0335 QUEUE_TYPE_CPU,
0336 QUEUE_TYPE_HW
0337 };
0338
0339 enum hl_cs_type {
0340 CS_TYPE_DEFAULT,
0341 CS_TYPE_SIGNAL,
0342 CS_TYPE_WAIT,
0343 CS_TYPE_COLLECTIVE_WAIT,
0344 CS_RESERVE_SIGNALS,
0345 CS_UNRESERVE_SIGNALS
0346 };
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356 struct hl_inbound_pci_region {
0357 enum hl_pci_match_mode mode;
0358 u64 addr;
0359 u64 size;
0360 u64 offset_in_bar;
0361 u8 bar;
0362 };
0363
0364
0365
0366
0367
0368
0369 struct hl_outbound_pci_region {
0370 u64 addr;
0371 u64 size;
0372 };
0373
0374
0375
0376
0377
0378
0379
0380 enum queue_cb_alloc_flags {
0381 CB_ALLOC_KERNEL = 0x1,
0382 CB_ALLOC_USER = 0x2
0383 };
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394 struct hl_hw_sob {
0395 struct hl_device *hdev;
0396 struct kref kref;
0397 u32 sob_id;
0398 u32 sob_addr;
0399 u32 q_idx;
0400 bool need_reset;
0401 };
0402
0403 enum hl_collective_mode {
0404 HL_COLLECTIVE_NOT_SUPPORTED = 0x0,
0405 HL_COLLECTIVE_MASTER = 0x1,
0406 HL_COLLECTIVE_SLAVE = 0x2
0407 };
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419
0420
0421
0422 struct hw_queue_properties {
0423 enum hl_queue_type type;
0424 enum queue_cb_alloc_flags cb_alloc_flags;
0425 enum hl_collective_mode collective_mode;
0426 u8 driver_only;
0427 u8 binned;
0428 u8 supports_sync_stream;
0429 };
0430
0431
0432
0433
0434
0435
0436 enum vm_type {
0437 VM_TYPE_USERPTR = 0x1,
0438 VM_TYPE_PHYS_PACK = 0x2
0439 };
0440
0441
0442
0443
0444
0445
0446
0447
0448 enum mmu_op_flags {
0449 MMU_OP_USERPTR = 0x1,
0450 MMU_OP_PHYS_PACK = 0x2,
0451 MMU_OP_CLEAR_MEMCACHE = 0x4,
0452 MMU_OP_SKIP_LOW_CACHE_INV = 0x8,
0453 };
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463 enum hl_device_hw_state {
0464 HL_DEVICE_HW_STATE_CLEAN = 0,
0465 HL_DEVICE_HW_STATE_DIRTY
0466 };
0467
0468 #define HL_MMU_VA_ALIGNMENT_NOT_NEEDED 0
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487 struct hl_mmu_properties {
0488 u64 start_addr;
0489 u64 end_addr;
0490 u64 hop_shifts[MMU_HOP_MAX];
0491 u64 hop_masks[MMU_HOP_MAX];
0492 u64 last_mask;
0493 u64 pgt_size;
0494 u64 supported_pages_mask;
0495 u32 page_size;
0496 u32 num_hops;
0497 u32 hop_table_size;
0498 u32 hop0_tables_total_size;
0499 u8 host_resident;
0500 };
0501
0502
0503
0504
0505
0506
0507 struct hl_hints_range {
0508 u64 start_addr;
0509 u64 end_addr;
0510 };
0511
0512
0513
0514
0515
0516
0517
0518
0519
0520
0521
0522
0523
0524
0525
0526
0527
0528
0529
0530
0531
0532
0533
0534
0535
0536
0537
0538
0539
0540
0541
0542
0543
0544
0545
0546
0547
0548
0549
0550
0551
0552
0553
0554
0555
0556
0557
0558
0559
0560
0561
0562
0563
0564
0565
0566
0567
0568
0569
0570
0571
0572
0573
0574
0575
0576
0577
0578
0579
0580
0581
0582
0583
0584
0585
0586
0587
0588
0589
0590
0591
0592
0593
0594
0595
0596
0597
0598
0599
0600
0601
0602
0603
0604
0605
0606
0607
0608
0609
0610
0611
0612
0613
0614
0615
0616
0617
0618
0619
0620
0621
0622
0623
0624
0625
0626
0627
0628
0629
0630
0631
0632
0633
0634
0635
0636
0637
0638
0639
0640
0641
0642
0643
0644
0645
0646
0647
0648
0649
0650
0651
0652
0653
0654
0655
0656
0657
0658
0659
0660
0661
0662 struct asic_fixed_properties {
0663 struct hw_queue_properties *hw_queues_props;
0664 struct cpucp_info cpucp_info;
0665 char uboot_ver[VERSION_MAX_LEN];
0666 char preboot_ver[VERSION_MAX_LEN];
0667 struct hl_mmu_properties dmmu;
0668 struct hl_mmu_properties pmmu;
0669 struct hl_mmu_properties pmmu_huge;
0670 struct hl_hints_range hints_dram_reserved_va_range;
0671 struct hl_hints_range hints_host_reserved_va_range;
0672 struct hl_hints_range hints_host_hpage_reserved_va_range;
0673 u64 sram_base_address;
0674 u64 sram_end_address;
0675 u64 sram_user_base_address;
0676 u64 dram_base_address;
0677 u64 dram_end_address;
0678 u64 dram_user_base_address;
0679 u64 dram_size;
0680 u64 dram_pci_bar_size;
0681 u64 max_power_default;
0682 u64 dc_power_default;
0683 u64 dram_size_for_default_page_mapping;
0684 u64 pcie_dbi_base_address;
0685 u64 pcie_aux_dbi_reg_addr;
0686 u64 mmu_pgt_addr;
0687 u64 mmu_dram_default_page_addr;
0688 u64 tpc_enabled_mask;
0689 u64 tpc_binning_mask;
0690 u64 dram_enabled_mask;
0691 u64 dram_binning_mask;
0692 u64 cb_va_start_addr;
0693 u64 cb_va_end_addr;
0694 u64 dram_hints_align_mask;
0695 u64 cfg_base_address;
0696 u64 mmu_cache_mng_addr;
0697 u64 mmu_cache_mng_size;
0698 u64 device_dma_offset_for_host_access;
0699 u64 host_base_address;
0700 u64 host_end_address;
0701 u64 max_freq_value;
0702 u32 clk_pll_index;
0703 u32 mmu_pgt_size;
0704 u32 mmu_pte_size;
0705 u32 mmu_hop_table_size;
0706 u32 mmu_hop0_tables_total_size;
0707 u32 dram_page_size;
0708 u32 cfg_size;
0709 u32 sram_size;
0710 u32 max_asid;
0711 u32 num_of_events;
0712 u32 psoc_pci_pll_nr;
0713 u32 psoc_pci_pll_nf;
0714 u32 psoc_pci_pll_od;
0715 u32 psoc_pci_pll_div_factor;
0716 u32 psoc_timestamp_frequency;
0717 u32 high_pll;
0718 u32 cb_pool_cb_cnt;
0719 u32 cb_pool_cb_size;
0720 u32 decoder_enabled_mask;
0721 u32 decoder_binning_mask;
0722 u32 edma_enabled_mask;
0723 u32 edma_binning_mask;
0724 u32 max_pending_cs;
0725 u32 max_queues;
0726 u32 fw_preboot_cpu_boot_dev_sts0;
0727 u32 fw_preboot_cpu_boot_dev_sts1;
0728 u32 fw_bootfit_cpu_boot_dev_sts0;
0729 u32 fw_bootfit_cpu_boot_dev_sts1;
0730 u32 fw_app_cpu_boot_dev_sts0;
0731 u32 fw_app_cpu_boot_dev_sts1;
0732 u32 max_dec;
0733 u32 hmmu_hif_enabled_mask;
0734 u32 faulty_dram_cluster_map;
0735 u32 xbar_edge_enabled_mask;
0736 u32 device_mem_alloc_default_page_size;
0737 u16 collective_first_sob;
0738 u16 collective_first_mon;
0739 u16 sync_stream_first_sob;
0740 u16 sync_stream_first_mon;
0741 u16 first_available_user_sob[HL_MAX_DCORES];
0742 u16 first_available_user_mon[HL_MAX_DCORES];
0743 u16 first_available_user_interrupt;
0744 u16 first_available_cq[HL_MAX_DCORES];
0745 u16 user_interrupt_count;
0746 u16 user_dec_intr_count;
0747 u16 cache_line_size;
0748 u16 server_type;
0749 u8 completion_queues_count;
0750 u8 completion_mode;
0751 u8 mme_master_slave_mode;
0752 u8 fw_security_enabled;
0753 u8 fw_cpu_boot_dev_sts0_valid;
0754 u8 fw_cpu_boot_dev_sts1_valid;
0755 u8 dram_supports_virtual_memory;
0756 u8 hard_reset_done_by_fw;
0757 u8 num_functional_hbms;
0758 u8 hints_range_reservation;
0759 u8 iatu_done_by_fw;
0760 u8 dynamic_fw_load;
0761 u8 gic_interrupts_enable;
0762 u8 use_get_power_for_reset_history;
0763 u8 supports_compute_reset;
0764 u8 allow_inference_soft_reset;
0765 u8 configurable_stop_on_err;
0766 u8 set_max_power_on_device_init;
0767 u8 supports_user_set_page_size;
0768 u8 dma_mask;
0769 };
0770
0771
0772
0773
0774
0775
0776
0777
0778
0779
0780
0781
0782
0783
0784 struct hl_fence {
0785 struct completion completion;
0786 struct kref refcount;
0787 u64 cs_sequence;
0788 u32 stream_master_qid_map;
0789 int error;
0790 ktime_t timestamp;
0791 u8 mcs_handling_done;
0792 };
0793
0794
0795
0796
0797
0798
0799
0800
0801
0802
0803
0804
0805
0806
0807
0808 struct hl_cs_compl {
0809 struct hl_fence base_fence;
0810 spinlock_t lock;
0811 struct hl_device *hdev;
0812 struct hl_hw_sob *hw_sob;
0813 struct hl_cs_encaps_sig_handle *encaps_sig_hdl;
0814 u64 cs_seq;
0815 enum hl_cs_type type;
0816 u16 sob_val;
0817 u16 sob_group;
0818 bool encaps_signals;
0819 };
0820
0821
0822
0823
0824
0825
0826
0827
0828
0829
0830
0831 struct hl_ts_buff {
0832 void *kernel_buff_address;
0833 void *user_buff_address;
0834 u32 kernel_buff_size;
0835 };
0836
0837 struct hl_mmap_mem_buf;
0838
0839
0840
0841
0842
0843
0844
0845 struct hl_mem_mgr {
0846 struct device *dev;
0847 spinlock_t lock;
0848 struct idr handles;
0849 };
0850
0851
0852
0853
0854
0855
0856
0857
0858
0859
0860
0861 struct hl_mmap_mem_buf_behavior {
0862 const char *topic;
0863 u64 mem_id;
0864
0865 int (*alloc)(struct hl_mmap_mem_buf *buf, gfp_t gfp, void *args);
0866 int (*mmap)(struct hl_mmap_mem_buf *buf, struct vm_area_struct *vma, void *args);
0867 void (*release)(struct hl_mmap_mem_buf *buf);
0868 };
0869
0870
0871
0872
0873
0874
0875
0876
0877
0878
0879
0880
0881
0882
0883 struct hl_mmap_mem_buf {
0884 struct hl_mmap_mem_buf_behavior *behavior;
0885 struct hl_mem_mgr *mmg;
0886 struct kref refcount;
0887 void *private;
0888 atomic_t mmap;
0889 u64 real_mapped_size;
0890 u64 mappable_size;
0891 u64 handle;
0892 };
0893
0894
0895
0896
0897
0898
0899
0900
0901
0902
0903
0904
0905
0906
0907
0908
0909
0910
0911 struct hl_cb {
0912 struct hl_device *hdev;
0913 struct hl_ctx *ctx;
0914 struct hl_mmap_mem_buf *buf;
0915 struct list_head debugfs_list;
0916 struct list_head pool_list;
0917 struct list_head va_block_list;
0918 void *kernel_address;
0919 dma_addr_t bus_address;
0920 u32 size;
0921 atomic_t cs_cnt;
0922 u8 is_pool;
0923 u8 is_internal;
0924 u8 is_mmu_mapped;
0925 };
0926
0927
0928
0929
0930
0931
0932 struct hl_cs_job;
0933
0934
0935 #define HL_QUEUE_LENGTH 4096
0936 #define HL_QUEUE_SIZE_IN_BYTES (HL_QUEUE_LENGTH * HL_BD_SIZE)
0937
0938 #if (HL_MAX_JOBS_PER_CS > HL_QUEUE_LENGTH)
0939 #error "HL_QUEUE_LENGTH must be greater than HL_MAX_JOBS_PER_CS"
0940 #endif
0941
0942
0943 #define HL_CQ_LENGTH HL_QUEUE_LENGTH
0944 #define HL_CQ_SIZE_IN_BYTES (HL_CQ_LENGTH * HL_CQ_ENTRY_SIZE)
0945
0946
0947 #define HL_EQ_LENGTH 64
0948 #define HL_EQ_SIZE_IN_BYTES (HL_EQ_LENGTH * HL_EQ_ENTRY_SIZE)
0949
0950
0951 #define HL_CPU_ACCESSIBLE_MEM_SIZE SZ_2M
0952
0953
0954
0955
0956
0957
0958
0959
0960
0961
0962
0963
0964
0965
0966
0967
0968
0969 struct hl_sync_stream_properties {
0970 struct hl_hw_sob hw_sob[HL_RSVD_SOBS];
0971 u16 next_sob_val;
0972 u16 base_sob_id;
0973 u16 base_mon_id;
0974 u16 collective_mstr_mon_id[HL_COLLECTIVE_RSVD_MSTR_MONS];
0975 u16 collective_slave_mon_id;
0976 u16 collective_sob_id;
0977 u8 curr_sob_offset;
0978 };
0979
0980
0981
0982
0983
0984
0985
0986 struct hl_encaps_signals_mgr {
0987 spinlock_t lock;
0988 struct idr handles;
0989 };
0990
0991
0992
0993
0994
0995
0996
0997
0998
0999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009 struct hl_hw_queue {
1010 struct hl_cs_job **shadow_queue;
1011 struct hl_sync_stream_properties sync_stream_prop;
1012 enum hl_queue_type queue_type;
1013 enum hl_collective_mode collective_mode;
1014 void *kernel_address;
1015 dma_addr_t bus_address;
1016 u32 pi;
1017 atomic_t ci;
1018 u32 hw_queue_id;
1019 u32 cq_id;
1020 u32 msi_vec;
1021 u16 int_queue_len;
1022 u8 valid;
1023 u8 supports_sync_stream;
1024 };
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037 struct hl_cq {
1038 struct hl_device *hdev;
1039 void *kernel_address;
1040 dma_addr_t bus_address;
1041 u32 cq_idx;
1042 u32 hw_queue_id;
1043 u32 ci;
1044 u32 pi;
1045 atomic_t free_slots_cnt;
1046 };
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056 struct hl_user_interrupt {
1057 struct hl_device *hdev;
1058 struct list_head wait_list_head;
1059 spinlock_t wait_list_lock;
1060 u32 interrupt_id;
1061 bool is_decoder;
1062 };
1063
1064
1065
1066
1067
1068
1069
1070 struct timestamp_reg_free_node {
1071 struct list_head free_objects_node;
1072 struct hl_cb *cq_cb;
1073 struct hl_mmap_mem_buf *buf;
1074 };
1075
1076
1077
1078
1079
1080
1081
1082
1083 struct timestamp_reg_work_obj {
1084 struct work_struct free_obj;
1085 struct hl_device *hdev;
1086 struct list_head *free_obj_head;
1087 };
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101 struct timestamp_reg_info {
1102 struct hl_mmap_mem_buf *buf;
1103 struct hl_cb *cq_cb;
1104 u64 *timestamp_kernel_addr;
1105 u8 in_use;
1106 };
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118 struct hl_user_pending_interrupt {
1119 struct timestamp_reg_info ts_reg_info;
1120 struct list_head wait_list_node;
1121 struct hl_fence fence;
1122 u64 cq_target_value;
1123 u64 *cq_kernel_addr;
1124 };
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138 struct hl_eq {
1139 struct hl_device *hdev;
1140 void *kernel_address;
1141 dma_addr_t bus_address;
1142 u32 ci;
1143 u32 prev_eqe_index;
1144 bool check_eqe_index;
1145 };
1146
1147
1148
1149
1150
1151
1152
1153
1154 struct hl_dec {
1155 struct hl_device *hdev;
1156 struct work_struct completion_abnrm_work;
1157 u32 core_id;
1158 u32 base_addr;
1159 };
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170 enum hl_asic_type {
1171 ASIC_INVALID,
1172 ASIC_GOYA,
1173 ASIC_GAUDI,
1174 ASIC_GAUDI_SEC,
1175 ASIC_GAUDI2,
1176 ASIC_GAUDI2_SEC,
1177 };
1178
1179 struct hl_cs_parser;
1180
1181
1182
1183
1184
1185
1186
1187 enum hl_pm_mng_profile {
1188 PM_AUTO = 1,
1189 PM_MANUAL,
1190 PM_LAST
1191 };
1192
1193
1194
1195
1196
1197
1198
1199 enum hl_pll_frequency {
1200 PLL_HIGH = 1,
1201 PLL_LOW,
1202 PLL_LAST
1203 };
1204
1205 #define PLL_REF_CLK 50
1206
1207 enum div_select_defs {
1208 DIV_SEL_REF_CLK = 0,
1209 DIV_SEL_PLL_CLK = 1,
1210 DIV_SEL_DIVIDED_REF = 2,
1211 DIV_SEL_DIVIDED_PLL = 3,
1212 };
1213
1214 enum debugfs_access_type {
1215 DEBUGFS_READ8,
1216 DEBUGFS_WRITE8,
1217 DEBUGFS_READ32,
1218 DEBUGFS_WRITE32,
1219 DEBUGFS_READ64,
1220 DEBUGFS_WRITE64,
1221 };
1222
1223 enum pci_region {
1224 PCI_REGION_CFG,
1225 PCI_REGION_SRAM,
1226 PCI_REGION_DRAM,
1227 PCI_REGION_SP_SRAM,
1228 PCI_REGION_NUMBER,
1229 };
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240 struct pci_mem_region {
1241 u64 region_base;
1242 u64 region_size;
1243 u64 bar_size;
1244 u64 offset_in_bar;
1245 u8 bar_id;
1246 u8 used;
1247 };
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265 struct static_fw_load_mgr {
1266 u64 preboot_version_max_off;
1267 u64 boot_fit_version_max_off;
1268 u32 kmd_msg_to_cpu_reg;
1269 u32 cpu_cmd_status_to_host_reg;
1270 u32 cpu_boot_status_reg;
1271 u32 cpu_boot_dev_status0_reg;
1272 u32 cpu_boot_dev_status1_reg;
1273 u32 boot_err0_reg;
1274 u32 boot_err1_reg;
1275 u32 preboot_version_offset_reg;
1276 u32 boot_fit_version_offset_reg;
1277 u32 sram_offset_mask;
1278 u32 cpu_reset_wait_msec;
1279 };
1280
1281
1282
1283
1284
1285
1286
1287 struct fw_response {
1288 u32 ram_offset;
1289 u8 ram_type;
1290 u8 status;
1291 };
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302 struct dynamic_fw_load_mgr {
1303 struct fw_response response;
1304 struct lkd_fw_comms_desc comm_desc;
1305 struct pci_mem_region *image_region;
1306 size_t fw_image_size;
1307 u32 wait_for_bl_timeout;
1308 bool fw_desc_valid;
1309 };
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320 struct pre_fw_load_props {
1321 u32 cpu_boot_status_reg;
1322 u32 sts_boot_dev_sts0_reg;
1323 u32 sts_boot_dev_sts1_reg;
1324 u32 boot_err0_reg;
1325 u32 boot_err1_reg;
1326 u32 wait_for_preboot_timeout;
1327 };
1328
1329
1330
1331
1332
1333
1334
1335 struct fw_image_props {
1336 char *image_name;
1337 u32 src_off;
1338 u32 copy_size;
1339 };
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356 struct fw_load_mgr {
1357 union {
1358 struct dynamic_fw_load_mgr dynamic_loader;
1359 struct static_fw_load_mgr static_loader;
1360 };
1361 struct pre_fw_load_props pre_fw_load;
1362 struct fw_image_props boot_fit_img;
1363 struct fw_image_props linux_img;
1364 u32 cpu_timeout;
1365 u32 boot_fit_timeout;
1366 u8 skip_bmc;
1367 u8 sram_bar_id;
1368 u8 dram_bar_id;
1369 u8 fw_comp_loaded;
1370 };
1371
1372 struct hl_cs;
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502 struct hl_asic_funcs {
1503 int (*early_init)(struct hl_device *hdev);
1504 int (*early_fini)(struct hl_device *hdev);
1505 int (*late_init)(struct hl_device *hdev);
1506 void (*late_fini)(struct hl_device *hdev);
1507 int (*sw_init)(struct hl_device *hdev);
1508 int (*sw_fini)(struct hl_device *hdev);
1509 int (*hw_init)(struct hl_device *hdev);
1510 void (*hw_fini)(struct hl_device *hdev, bool hard_reset, bool fw_reset);
1511 void (*halt_engines)(struct hl_device *hdev, bool hard_reset, bool fw_reset);
1512 int (*suspend)(struct hl_device *hdev);
1513 int (*resume)(struct hl_device *hdev);
1514 int (*mmap)(struct hl_device *hdev, struct vm_area_struct *vma,
1515 void *cpu_addr, dma_addr_t dma_addr, size_t size);
1516 void (*ring_doorbell)(struct hl_device *hdev, u32 hw_queue_id, u32 pi);
1517 void (*pqe_write)(struct hl_device *hdev, __le64 *pqe,
1518 struct hl_bd *bd);
1519 void* (*asic_dma_alloc_coherent)(struct hl_device *hdev, size_t size,
1520 dma_addr_t *dma_handle, gfp_t flag);
1521 void (*asic_dma_free_coherent)(struct hl_device *hdev, size_t size,
1522 void *cpu_addr, dma_addr_t dma_handle);
1523 int (*scrub_device_mem)(struct hl_device *hdev);
1524 int (*scrub_device_dram)(struct hl_device *hdev, u64 val);
1525 void* (*get_int_queue_base)(struct hl_device *hdev, u32 queue_id,
1526 dma_addr_t *dma_handle, u16 *queue_len);
1527 int (*test_queues)(struct hl_device *hdev);
1528 void* (*asic_dma_pool_zalloc)(struct hl_device *hdev, size_t size,
1529 gfp_t mem_flags, dma_addr_t *dma_handle);
1530 void (*asic_dma_pool_free)(struct hl_device *hdev, void *vaddr,
1531 dma_addr_t dma_addr);
1532 void* (*cpu_accessible_dma_pool_alloc)(struct hl_device *hdev,
1533 size_t size, dma_addr_t *dma_handle);
1534 void (*cpu_accessible_dma_pool_free)(struct hl_device *hdev,
1535 size_t size, void *vaddr);
1536 void (*asic_dma_unmap_single)(struct hl_device *hdev,
1537 dma_addr_t dma_addr, int len,
1538 enum dma_data_direction dir);
1539 dma_addr_t (*asic_dma_map_single)(struct hl_device *hdev,
1540 void *addr, int len,
1541 enum dma_data_direction dir);
1542 void (*hl_dma_unmap_sgtable)(struct hl_device *hdev,
1543 struct sg_table *sgt,
1544 enum dma_data_direction dir);
1545 int (*cs_parser)(struct hl_device *hdev, struct hl_cs_parser *parser);
1546 int (*asic_dma_map_sgtable)(struct hl_device *hdev, struct sg_table *sgt,
1547 enum dma_data_direction dir);
1548 void (*add_end_of_cb_packets)(struct hl_device *hdev,
1549 void *kernel_address, u32 len,
1550 u32 original_len,
1551 u64 cq_addr, u32 cq_val, u32 msix_num,
1552 bool eb);
1553 void (*update_eq_ci)(struct hl_device *hdev, u32 val);
1554 int (*context_switch)(struct hl_device *hdev, u32 asid);
1555 void (*restore_phase_topology)(struct hl_device *hdev);
1556 int (*debugfs_read_dma)(struct hl_device *hdev, u64 addr, u32 size,
1557 void *blob_addr);
1558 void (*add_device_attr)(struct hl_device *hdev, struct attribute_group *dev_clk_attr_grp,
1559 struct attribute_group *dev_vrm_attr_grp);
1560 void (*handle_eqe)(struct hl_device *hdev,
1561 struct hl_eq_entry *eq_entry);
1562 void* (*get_events_stat)(struct hl_device *hdev, bool aggregate,
1563 u32 *size);
1564 u64 (*read_pte)(struct hl_device *hdev, u64 addr);
1565 void (*write_pte)(struct hl_device *hdev, u64 addr, u64 val);
1566 int (*mmu_invalidate_cache)(struct hl_device *hdev, bool is_hard,
1567 u32 flags);
1568 int (*mmu_invalidate_cache_range)(struct hl_device *hdev, bool is_hard,
1569 u32 flags, u32 asid, u64 va, u64 size);
1570 int (*mmu_prefetch_cache_range)(struct hl_ctx *ctx, u32 flags, u32 asid, u64 va, u64 size);
1571 int (*send_heartbeat)(struct hl_device *hdev);
1572 int (*debug_coresight)(struct hl_device *hdev, struct hl_ctx *ctx, void *data);
1573 bool (*is_device_idle)(struct hl_device *hdev, u64 *mask_arr,
1574 u8 mask_len, struct seq_file *s);
1575 int (*non_hard_reset_late_init)(struct hl_device *hdev);
1576 void (*hw_queues_lock)(struct hl_device *hdev);
1577 void (*hw_queues_unlock)(struct hl_device *hdev);
1578 void (*kdma_lock)(struct hl_device *hdev, int dcore_id);
1579 void (*kdma_unlock)(struct hl_device *hdev, int dcore_id);
1580 u32 (*get_pci_id)(struct hl_device *hdev);
1581 int (*get_eeprom_data)(struct hl_device *hdev, void *data, size_t max_size);
1582 int (*get_monitor_dump)(struct hl_device *hdev, void *data);
1583 int (*send_cpu_message)(struct hl_device *hdev, u32 *msg,
1584 u16 len, u32 timeout, u64 *result);
1585 int (*pci_bars_map)(struct hl_device *hdev);
1586 int (*init_iatu)(struct hl_device *hdev);
1587 u32 (*rreg)(struct hl_device *hdev, u32 reg);
1588 void (*wreg)(struct hl_device *hdev, u32 reg, u32 val);
1589 void (*halt_coresight)(struct hl_device *hdev, struct hl_ctx *ctx);
1590 int (*ctx_init)(struct hl_ctx *ctx);
1591 void (*ctx_fini)(struct hl_ctx *ctx);
1592 int (*pre_schedule_cs)(struct hl_cs *cs);
1593 u32 (*get_queue_id_for_cq)(struct hl_device *hdev, u32 cq_idx);
1594 int (*load_firmware_to_device)(struct hl_device *hdev);
1595 int (*load_boot_fit_to_device)(struct hl_device *hdev);
1596 u32 (*get_signal_cb_size)(struct hl_device *hdev);
1597 u32 (*get_wait_cb_size)(struct hl_device *hdev);
1598 u32 (*gen_signal_cb)(struct hl_device *hdev, void *data, u16 sob_id,
1599 u32 size, bool eb);
1600 u32 (*gen_wait_cb)(struct hl_device *hdev,
1601 struct hl_gen_wait_properties *prop);
1602 void (*reset_sob)(struct hl_device *hdev, void *data);
1603 void (*reset_sob_group)(struct hl_device *hdev, u16 sob_group);
1604 u64 (*get_device_time)(struct hl_device *hdev);
1605 void (*pb_print_security_errors)(struct hl_device *hdev,
1606 u32 block_addr, u32 cause, u32 offended_addr);
1607 int (*collective_wait_init_cs)(struct hl_cs *cs);
1608 int (*collective_wait_create_jobs)(struct hl_device *hdev,
1609 struct hl_ctx *ctx, struct hl_cs *cs,
1610 u32 wait_queue_id, u32 collective_engine_id,
1611 u32 encaps_signal_offset);
1612 u32 (*get_dec_base_addr)(struct hl_device *hdev, u32 core_id);
1613 u64 (*scramble_addr)(struct hl_device *hdev, u64 addr);
1614 u64 (*descramble_addr)(struct hl_device *hdev, u64 addr);
1615 void (*ack_protection_bits_errors)(struct hl_device *hdev);
1616 int (*get_hw_block_id)(struct hl_device *hdev, u64 block_addr,
1617 u32 *block_size, u32 *block_id);
1618 int (*hw_block_mmap)(struct hl_device *hdev, struct vm_area_struct *vma,
1619 u32 block_id, u32 block_size);
1620 void (*enable_events_from_fw)(struct hl_device *hdev);
1621 int (*ack_mmu_errors)(struct hl_device *hdev, u64 mmu_cap_mask);
1622 void (*get_msi_info)(__le32 *table);
1623 int (*map_pll_idx_to_fw_idx)(u32 pll_idx);
1624 void (*init_firmware_preload_params)(struct hl_device *hdev);
1625 void (*init_firmware_loader)(struct hl_device *hdev);
1626 void (*init_cpu_scrambler_dram)(struct hl_device *hdev);
1627 void (*state_dump_init)(struct hl_device *hdev);
1628 u32 (*get_sob_addr)(struct hl_device *hdev, u32 sob_id);
1629 void (*set_pci_memory_regions)(struct hl_device *hdev);
1630 u32* (*get_stream_master_qid_arr)(void);
1631 void (*check_if_razwi_happened)(struct hl_device *hdev);
1632 int (*mmu_get_real_page_size)(struct hl_device *hdev, struct hl_mmu_properties *mmu_prop,
1633 u32 page_size, u32 *real_page_size, bool is_dram_addr);
1634 int (*access_dev_mem)(struct hl_device *hdev, enum pci_region region_type,
1635 u64 addr, u64 *val, enum debugfs_access_type acc_type);
1636 u64 (*set_dram_bar_base)(struct hl_device *hdev, u64 addr);
1637 };
1638
1639
1640
1641
1642
1643
1644 #define HL_KERNEL_ASID_ID 0
1645
1646
1647
1648
1649
1650
1651
1652 enum hl_va_range_type {
1653 HL_VA_RANGE_TYPE_HOST,
1654 HL_VA_RANGE_TYPE_HOST_HUGE,
1655 HL_VA_RANGE_TYPE_DRAM,
1656 HL_VA_RANGE_TYPE_MAX
1657 };
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667 struct hl_va_range {
1668 struct mutex lock;
1669 struct list_head list;
1670 u64 start_addr;
1671 u64 end_addr;
1672 u32 page_size;
1673 };
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684 struct hl_cs_counters_atomic {
1685 atomic64_t out_of_mem_drop_cnt;
1686 atomic64_t parsing_drop_cnt;
1687 atomic64_t queue_full_drop_cnt;
1688 atomic64_t device_in_reset_drop_cnt;
1689 atomic64_t max_cs_in_flight_drop_cnt;
1690 atomic64_t validation_drop_cnt;
1691 };
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703 struct hl_dmabuf_priv {
1704 struct dma_buf *dmabuf;
1705 struct hl_ctx *ctx;
1706 struct hl_vm_phys_pg_pack *phys_pg_pack;
1707 uint64_t device_address;
1708 };
1709
1710 #define HL_CS_OUTCOME_HISTORY_LEN 256
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720 struct hl_cs_outcome {
1721 struct list_head list_link;
1722 struct hlist_node map_link;
1723 ktime_t ts;
1724 u64 seq;
1725 int error;
1726 };
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736 struct hl_cs_outcome_store {
1737 DECLARE_HASHTABLE(outcome_map, 8);
1738 struct list_head used_list;
1739 struct list_head free_list;
1740 struct hl_cs_outcome nodes_pool[HL_CS_OUTCOME_HISTORY_LEN];
1741 spinlock_t db_lock;
1742 };
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787 struct hl_ctx {
1788 DECLARE_HASHTABLE(mem_hash, MEM_HASH_TABLE_BITS);
1789 DECLARE_HASHTABLE(mmu_shadow_hash, MMU_HASH_TABLE_BITS);
1790 DECLARE_HASHTABLE(hr_mmu_phys_hash, MMU_HASH_TABLE_BITS);
1791 struct hl_fpriv *hpriv;
1792 struct hl_device *hdev;
1793 struct kref refcount;
1794 struct hl_fence **cs_pending;
1795 struct hl_cs_outcome_store outcome_store;
1796 struct hl_va_range *va_range[HL_VA_RANGE_TYPE_MAX];
1797 struct mutex mem_hash_lock;
1798 struct mutex mmu_lock;
1799 struct mutex hw_block_list_lock;
1800 struct list_head debugfs_list;
1801 struct list_head hw_block_mem_list;
1802 struct hl_cs_counters_atomic cs_counters;
1803 struct gen_pool *cb_va_pool;
1804 struct hl_encaps_signals_mgr sig_mgr;
1805 u64 cs_sequence;
1806 u64 *dram_default_hops;
1807 spinlock_t cs_lock;
1808 atomic64_t dram_phys_mem;
1809 atomic_t thread_ctx_switch_token;
1810 u32 thread_ctx_switch_wait_token;
1811 u32 asid;
1812 u32 handle;
1813 };
1814
1815
1816
1817
1818
1819
1820 struct hl_ctx_mgr {
1821 struct mutex lock;
1822 struct idr handles;
1823 };
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845 struct hl_userptr {
1846 enum vm_type vm_type;
1847 struct list_head job_node;
1848 struct page **pages;
1849 unsigned int npages;
1850 struct sg_table *sgt;
1851 enum dma_data_direction dir;
1852 struct list_head debugfs_list;
1853 pid_t pid;
1854 u64 addr;
1855 u64 size;
1856 u8 dma_mapped;
1857 };
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901 struct hl_cs {
1902 u16 *jobs_in_queue_cnt;
1903 struct hl_ctx *ctx;
1904 struct list_head job_list;
1905 spinlock_t job_lock;
1906 struct kref refcount;
1907 struct hl_fence *fence;
1908 struct hl_fence *signal_fence;
1909 struct work_struct finish_work;
1910 struct delayed_work work_tdr;
1911 struct list_head mirror_node;
1912 struct list_head staged_cs_node;
1913 struct list_head debugfs_list;
1914 struct hl_cs_encaps_sig_handle *encaps_sig_hdl;
1915 u64 sequence;
1916 u64 staged_sequence;
1917 u64 timeout_jiffies;
1918 u64 submission_time_jiffies;
1919 enum hl_cs_type type;
1920 u32 jobs_cnt;
1921 u32 encaps_sig_hdl_id;
1922 u32 sob_addr_offset;
1923 u16 initial_sob_count;
1924 u8 submitted;
1925 u8 completed;
1926 u8 timedout;
1927 u8 tdr_active;
1928 u8 aborted;
1929 u8 timestamp;
1930 u8 staged_last;
1931 u8 staged_first;
1932 u8 staged_cs;
1933 u8 skip_reset_on_timeout;
1934 u8 encaps_signals;
1935 };
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966 struct hl_cs_job {
1967 struct list_head cs_node;
1968 struct hl_cs *cs;
1969 struct hl_cb *user_cb;
1970 struct hl_cb *patched_cb;
1971 struct work_struct finish_work;
1972 struct list_head userptr_list;
1973 struct list_head debugfs_list;
1974 struct kref refcount;
1975 enum hl_queue_type queue_type;
1976 u32 id;
1977 u32 hw_queue_id;
1978 u32 user_cb_size;
1979 u32 job_cb_size;
1980 u32 encaps_sig_wait_offset;
1981 u8 is_kernel_allocated_cb;
1982 u8 contains_dma_pkt;
1983 };
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010 struct hl_cs_parser {
2011 struct hl_cb *user_cb;
2012 struct hl_cb *patched_cb;
2013 struct list_head *job_userptr_list;
2014 u64 cs_sequence;
2015 enum hl_queue_type queue_type;
2016 u32 ctx_id;
2017 u32 hw_queue_id;
2018 u32 user_cb_size;
2019 u32 patched_cb_size;
2020 u8 job_id;
2021 u8 is_kernel_allocated_cb;
2022 u8 contains_dma_pkt;
2023 u8 completion;
2024 };
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038 struct hl_vm_hash_node {
2039 struct hlist_node node;
2040 u64 vaddr;
2041 void *ptr;
2042 };
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053 struct hl_vm_hw_block_list_node {
2054 struct list_head node;
2055 struct hl_ctx *ctx;
2056 unsigned long vaddr;
2057 u32 size;
2058 u32 id;
2059 };
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079 struct hl_vm_phys_pg_pack {
2080 enum vm_type vm_type;
2081 u64 *pages;
2082 u64 npages;
2083 u64 total_size;
2084 struct list_head node;
2085 atomic_t mapping_cnt;
2086 u32 exporting_cnt;
2087 u32 asid;
2088 u32 page_size;
2089 u32 flags;
2090 u32 handle;
2091 u32 offset;
2092 u8 contiguous;
2093 u8 created_from_userptr;
2094 };
2095
2096
2097
2098
2099
2100
2101
2102
2103 struct hl_vm_va_block {
2104 struct list_head node;
2105 u64 start;
2106 u64 end;
2107 u64 size;
2108 };
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119 struct hl_vm {
2120 struct gen_pool *dram_pg_pool;
2121 struct kref dram_pg_pool_refcount;
2122 spinlock_t idr_lock;
2123 struct idr phys_pg_pack_handles;
2124 u8 init_done;
2125 };
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141 struct hl_debug_params {
2142 void *input;
2143 void *output;
2144 u32 output_size;
2145 u32 reg_idx;
2146 u32 op;
2147 bool enable;
2148 };
2149
2150
2151
2152
2153
2154
2155
2156 struct hl_notifier_event {
2157 struct eventfd_ctx *eventfd;
2158 struct mutex lock;
2159 u64 events_mask;
2160 };
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182 struct hl_fpriv {
2183 struct hl_device *hdev;
2184 struct file *filp;
2185 struct pid *taskpid;
2186 struct hl_ctx *ctx;
2187 struct hl_ctx_mgr ctx_mgr;
2188 struct hl_mem_mgr mem_mgr;
2189 struct hl_notifier_event notifier_event;
2190 struct list_head debugfs_list;
2191 struct list_head dev_node;
2192 struct kref refcount;
2193 struct mutex restore_phase_mutex;
2194 struct mutex ctx_lock;
2195 };
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208 struct hl_info_list {
2209 const char *name;
2210 int (*show)(struct seq_file *s, void *data);
2211 ssize_t (*write)(struct file *file, const char __user *buf,
2212 size_t count, loff_t *f_pos);
2213 };
2214
2215
2216
2217
2218
2219
2220 struct hl_debugfs_entry {
2221 const struct hl_info_list *info_ent;
2222 struct hl_dbg_device_entry *dev_entry;
2223 };
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257 struct hl_dbg_device_entry {
2258 struct dentry *root;
2259 struct hl_device *hdev;
2260 struct hl_debugfs_entry *entry_arr;
2261 struct list_head file_list;
2262 struct mutex file_mutex;
2263 struct list_head cb_list;
2264 spinlock_t cb_spinlock;
2265 struct list_head cs_list;
2266 spinlock_t cs_spinlock;
2267 struct list_head cs_job_list;
2268 spinlock_t cs_job_spinlock;
2269 struct list_head userptr_list;
2270 spinlock_t userptr_spinlock;
2271 struct list_head ctx_mem_hash_list;
2272 spinlock_t ctx_mem_hash_spinlock;
2273 struct debugfs_blob_wrapper data_dma_blob_desc;
2274 struct debugfs_blob_wrapper mon_dump_blob_desc;
2275 char *state_dump[HL_STATE_DUMP_HIST_LEN];
2276 struct rw_semaphore state_dump_sem;
2277 u64 addr;
2278 u64 mmu_addr;
2279 u64 mmu_cap_mask;
2280 u64 userptr_lookup;
2281 u32 mmu_asid;
2282 u32 state_dump_head;
2283 u8 i2c_bus;
2284 u8 i2c_addr;
2285 u8 i2c_reg;
2286 u8 i2c_len;
2287 };
2288
2289
2290
2291
2292
2293
2294
2295
2296 struct hl_hw_obj_name_entry {
2297 struct hlist_node node;
2298 const char *name;
2299 u32 id;
2300 };
2301
2302 enum hl_state_dump_specs_props {
2303 SP_SYNC_OBJ_BASE_ADDR,
2304 SP_NEXT_SYNC_OBJ_ADDR,
2305 SP_SYNC_OBJ_AMOUNT,
2306 SP_MON_OBJ_WR_ADDR_LOW,
2307 SP_MON_OBJ_WR_ADDR_HIGH,
2308 SP_MON_OBJ_WR_DATA,
2309 SP_MON_OBJ_ARM_DATA,
2310 SP_MON_OBJ_STATUS,
2311 SP_MONITORS_AMOUNT,
2312 SP_TPC0_CMDQ,
2313 SP_TPC0_CFG_SO,
2314 SP_NEXT_TPC,
2315 SP_MME_CMDQ,
2316 SP_MME_CFG_SO,
2317 SP_NEXT_MME,
2318 SP_DMA_CMDQ,
2319 SP_DMA_CFG_SO,
2320 SP_DMA_QUEUES_OFFSET,
2321 SP_NUM_OF_MME_ENGINES,
2322 SP_SUB_MME_ENG_NUM,
2323 SP_NUM_OF_DMA_ENGINES,
2324 SP_NUM_OF_TPC_ENGINES,
2325 SP_ENGINE_NUM_OF_QUEUES,
2326 SP_ENGINE_NUM_OF_STREAMS,
2327 SP_ENGINE_NUM_OF_FENCES,
2328 SP_FENCE0_CNT_OFFSET,
2329 SP_FENCE0_RDATA_OFFSET,
2330 SP_CP_STS_OFFSET,
2331 SP_NUM_CORES,
2332
2333 SP_MAX
2334 };
2335
2336 enum hl_sync_engine_type {
2337 ENGINE_TPC,
2338 ENGINE_DMA,
2339 ENGINE_MME,
2340 };
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351 struct hl_mon_state_dump {
2352 u32 id;
2353 u32 wr_addr_low;
2354 u32 wr_addr_high;
2355 u32 wr_data;
2356 u32 arm_data;
2357 u32 status;
2358 };
2359
2360
2361
2362
2363
2364
2365
2366 struct hl_sync_to_engine_map_entry {
2367 struct hlist_node node;
2368 enum hl_sync_engine_type engine_type;
2369 u32 engine_id;
2370 u32 sync_id;
2371 };
2372
2373
2374
2375
2376
2377
2378 struct hl_sync_to_engine_map {
2379 DECLARE_HASHTABLE(tb, SYNC_TO_ENGINE_HASH_TABLE_BITS);
2380 };
2381
2382
2383
2384
2385
2386
2387
2388
2389 struct hl_state_dump_specs_funcs {
2390 int (*gen_sync_to_engine_map)(struct hl_device *hdev,
2391 struct hl_sync_to_engine_map *map);
2392 int (*print_single_monitor)(char **buf, size_t *size, size_t *offset,
2393 struct hl_device *hdev,
2394 struct hl_mon_state_dump *mon);
2395 int (*monitor_valid)(struct hl_mon_state_dump *mon);
2396 int (*print_fences_single_engine)(struct hl_device *hdev,
2397 u64 base_offset,
2398 u64 status_base_offset,
2399 enum hl_sync_engine_type engine_type,
2400 u32 engine_id, char **buf,
2401 size_t *size, size_t *offset);
2402 };
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412 struct hl_state_dump_specs {
2413 DECLARE_HASHTABLE(so_id_to_str_tb, OBJ_NAMES_HASH_TABLE_BITS);
2414 DECLARE_HASHTABLE(monitor_id_to_str_tb, OBJ_NAMES_HASH_TABLE_BITS);
2415 struct hl_state_dump_specs_funcs funcs;
2416 const char * const *sync_namager_names;
2417 s64 *props;
2418 };
2419
2420
2421
2422
2423
2424
2425 #define HL_STR_MAX 32
2426
2427 #define HL_DEV_STS_MAX (HL_DEVICE_STATUS_LAST + 1)
2428
2429
2430
2431
2432 #define HL_MAX_MINORS 256
2433
2434
2435
2436
2437
2438 u32 hl_rreg(struct hl_device *hdev, u32 reg);
2439 void hl_wreg(struct hl_device *hdev, u32 reg, u32 val);
2440
2441 #define RREG32(reg) hdev->asic_funcs->rreg(hdev, (reg))
2442 #define WREG32(reg, v) hdev->asic_funcs->wreg(hdev, (reg), (v))
2443 #define DREG32(reg) pr_info("REGISTER: " #reg " : 0x%08X\n", \
2444 hdev->asic_funcs->rreg(hdev, (reg)))
2445
2446 #define WREG32_P(reg, val, mask) \
2447 do { \
2448 u32 tmp_ = RREG32(reg); \
2449 tmp_ &= (mask); \
2450 tmp_ |= ((val) & ~(mask)); \
2451 WREG32(reg, tmp_); \
2452 } while (0)
2453 #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
2454 #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
2455
2456 #define RMWREG32(reg, val, mask) \
2457 do { \
2458 u32 tmp_ = RREG32(reg); \
2459 tmp_ &= ~(mask); \
2460 tmp_ |= ((val) << __ffs(mask)); \
2461 WREG32(reg, tmp_); \
2462 } while (0)
2463
2464 #define RREG32_MASK(reg, mask) ((RREG32(reg) & mask) >> __ffs(mask))
2465
2466 #define REG_FIELD_SHIFT(reg, field) reg##_##field##_SHIFT
2467 #define REG_FIELD_MASK(reg, field) reg##_##field##_MASK
2468 #define WREG32_FIELD(reg, offset, field, val) \
2469 WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & \
2470 ~REG_FIELD_MASK(reg, field)) | \
2471 (val) << REG_FIELD_SHIFT(reg, field))
2472
2473
2474
2475
2476 #define hl_poll_timeout_common(hdev, addr, val, cond, sleep_us, timeout_us, elbi) \
2477 ({ \
2478 ktime_t __timeout; \
2479 u32 __elbi_read; \
2480 int __rc = 0; \
2481 if (hdev->pdev) \
2482 __timeout = ktime_add_us(ktime_get(), timeout_us); \
2483 else \
2484 __timeout = ktime_add_us(ktime_get(),\
2485 min((u64)(timeout_us * 10), \
2486 (u64) HL_SIM_MAX_TIMEOUT_US)); \
2487 might_sleep_if(sleep_us); \
2488 for (;;) { \
2489 if (elbi) { \
2490 __rc = hl_pci_elbi_read(hdev, addr, &__elbi_read); \
2491 if (__rc) \
2492 break; \
2493 (val) = __elbi_read; \
2494 } else {\
2495 (val) = RREG32((u32)addr); \
2496 } \
2497 if (cond) \
2498 break; \
2499 if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \
2500 if (elbi) { \
2501 __rc = hl_pci_elbi_read(hdev, addr, &__elbi_read); \
2502 if (__rc) \
2503 break; \
2504 (val) = __elbi_read; \
2505 } else {\
2506 (val) = RREG32((u32)addr); \
2507 } \
2508 break; \
2509 } \
2510 if (sleep_us) \
2511 usleep_range((sleep_us >> 2) + 1, sleep_us); \
2512 } \
2513 __rc ? __rc : ((cond) ? 0 : -ETIMEDOUT); \
2514 })
2515
2516 #define hl_poll_timeout(hdev, addr, val, cond, sleep_us, timeout_us) \
2517 hl_poll_timeout_common(hdev, addr, val, cond, sleep_us, timeout_us, false)
2518
2519 #define hl_poll_timeout_elbi(hdev, addr, val, cond, sleep_us, timeout_us) \
2520 hl_poll_timeout_common(hdev, addr, val, cond, sleep_us, timeout_us, true)
2521
2522
2523
2524
2525
2526
2527
2528
2529 #define hl_poll_reg_array_timeout_common(hdev, addr_arr, arr_size, expected_val, sleep_us, \
2530 timeout_us, elbi) \
2531 ({ \
2532 ktime_t __timeout; \
2533 u64 __elem_bitmask; \
2534 u32 __read_val; \
2535 u8 __arr_idx; \
2536 int __rc = 0; \
2537 \
2538 if (hdev->pdev) \
2539 __timeout = ktime_add_us(ktime_get(), timeout_us); \
2540 else \
2541 __timeout = ktime_add_us(ktime_get(),\
2542 min(((u64)timeout_us * 10), \
2543 (u64) HL_SIM_MAX_TIMEOUT_US)); \
2544 \
2545 might_sleep_if(sleep_us); \
2546 if (arr_size >= 64) \
2547 __rc = -EINVAL; \
2548 else \
2549 __elem_bitmask = BIT_ULL(arr_size) - 1; \
2550 for (;;) { \
2551 if (__rc) \
2552 break; \
2553 for (__arr_idx = 0; __arr_idx < (arr_size); __arr_idx++) { \
2554 if (!(__elem_bitmask & BIT_ULL(__arr_idx))) \
2555 continue; \
2556 if (elbi) { \
2557 __rc = hl_pci_elbi_read(hdev, (addr_arr)[__arr_idx], &__read_val); \
2558 if (__rc) \
2559 break; \
2560 } else { \
2561 __read_val = RREG32((u32)(addr_arr)[__arr_idx]); \
2562 } \
2563 if (__read_val == (expected_val)) \
2564 __elem_bitmask &= ~BIT_ULL(__arr_idx); \
2565 } \
2566 if (__rc || (__elem_bitmask == 0)) \
2567 break; \
2568 if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) \
2569 break; \
2570 if (sleep_us) \
2571 usleep_range((sleep_us >> 2) + 1, sleep_us); \
2572 } \
2573 __rc ? __rc : ((__elem_bitmask == 0) ? 0 : -ETIMEDOUT); \
2574 })
2575
2576 #define hl_poll_reg_array_timeout(hdev, addr_arr, arr_size, expected_val, sleep_us, \
2577 timeout_us) \
2578 hl_poll_reg_array_timeout_common(hdev, addr_arr, arr_size, expected_val, sleep_us, \
2579 timeout_us, false)
2580
2581 #define hl_poll_reg_array_timeout_elbi(hdev, addr_arr, arr_size, expected_val, sleep_us, \
2582 timeout_us) \
2583 hl_poll_reg_array_timeout_common(hdev, addr_arr, arr_size, expected_val, sleep_us, \
2584 timeout_us, true)
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598 #define hl_poll_timeout_memory(hdev, addr, val, cond, sleep_us, timeout_us, \
2599 mem_written_by_device) \
2600 ({ \
2601 ktime_t __timeout; \
2602 if (hdev->pdev) \
2603 __timeout = ktime_add_us(ktime_get(), timeout_us); \
2604 else \
2605 __timeout = ktime_add_us(ktime_get(),\
2606 min((u64)(timeout_us * 100), \
2607 (u64) HL_SIM_MAX_TIMEOUT_US)); \
2608 might_sleep_if(sleep_us); \
2609 for (;;) { \
2610 \
2611 mb(); \
2612 (val) = *((u32 *)(addr)); \
2613 if (mem_written_by_device) \
2614 (val) = le32_to_cpu(*(__le32 *) &(val)); \
2615 if (cond) \
2616 break; \
2617 if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \
2618 (val) = *((u32 *)(addr)); \
2619 if (mem_written_by_device) \
2620 (val) = le32_to_cpu(*(__le32 *) &(val)); \
2621 break; \
2622 } \
2623 if (sleep_us) \
2624 usleep_range((sleep_us >> 2) + 1, sleep_us); \
2625 } \
2626 (cond) ? 0 : -ETIMEDOUT; \
2627 })
2628
2629 #define HL_USR_MAPPED_BLK_INIT(blk, base, sz) \
2630 ({ \
2631 struct user_mapped_block *p = blk; \
2632 \
2633 p->address = base; \
2634 p->size = sz; \
2635 })
2636
2637 #define HL_USR_INTR_STRUCT_INIT(usr_intr, hdev, intr_id, decoder) \
2638 ({ \
2639 usr_intr.hdev = hdev; \
2640 usr_intr.interrupt_id = intr_id; \
2641 usr_intr.is_decoder = decoder; \
2642 INIT_LIST_HEAD(&usr_intr.wait_list_head); \
2643 spin_lock_init(&usr_intr.wait_list_lock); \
2644 })
2645
2646 struct hwmon_chip_info;
2647
2648
2649
2650
2651
2652
2653
2654
2655 struct hl_device_reset_work {
2656 struct workqueue_struct *wq;
2657 struct delayed_work reset_work;
2658 struct hl_device *hdev;
2659 u32 flags;
2660 };
2661
2662
2663
2664
2665
2666
2667
2668
2669 struct hl_mmu_hr_priv {
2670 struct gen_pool *mmu_pgt_pool;
2671 struct pgt_info *mmu_asid_hop0;
2672 };
2673
2674
2675
2676
2677
2678
2679
2680 struct hl_mmu_dr_priv {
2681 struct gen_pool *mmu_pgt_pool;
2682 void *mmu_shadow_hop0;
2683 };
2684
2685
2686
2687
2688
2689
2690 struct hl_mmu_priv {
2691 struct hl_mmu_dr_priv dr;
2692 struct hl_mmu_hr_priv hr;
2693 };
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703 struct hl_mmu_per_hop_info {
2704 u64 hop_addr;
2705 u64 hop_pte_addr;
2706 u64 hop_pte_val;
2707 };
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721 struct hl_mmu_hop_info {
2722 u64 scrambled_vaddr;
2723 u64 unscrambled_paddr;
2724 struct hl_mmu_per_hop_info hop_info[MMU_ARCH_6_HOPS];
2725 u32 used_hops;
2726 enum hl_va_range_type range_type;
2727 };
2728
2729
2730
2731
2732
2733
2734
2735
2736 struct hl_hr_mmu_funcs {
2737 struct pgt_info *(*get_hop0_pgt_info)(struct hl_ctx *ctx);
2738 struct pgt_info *(*get_pgt_info)(struct hl_ctx *ctx, u64 phys_hop_addr);
2739 void (*add_pgt_info)(struct hl_ctx *ctx, struct pgt_info *pgt_info, dma_addr_t phys_addr);
2740 int (*get_tlb_mapping_params)(struct hl_device *hdev, struct hl_mmu_properties **mmu_prop,
2741 struct hl_mmu_hop_info *hops,
2742 u64 virt_addr, bool *is_huge);
2743 };
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761 struct hl_mmu_funcs {
2762 int (*init)(struct hl_device *hdev);
2763 void (*fini)(struct hl_device *hdev);
2764 int (*ctx_init)(struct hl_ctx *ctx);
2765 void (*ctx_fini)(struct hl_ctx *ctx);
2766 int (*map)(struct hl_ctx *ctx, u64 virt_addr, u64 phys_addr, u32 page_size,
2767 bool is_dram_addr);
2768 int (*unmap)(struct hl_ctx *ctx, u64 virt_addr, bool is_dram_addr);
2769 void (*flush)(struct hl_ctx *ctx);
2770 void (*swap_out)(struct hl_ctx *ctx);
2771 void (*swap_in)(struct hl_ctx *ctx);
2772 int (*get_tlb_info)(struct hl_ctx *ctx, u64 virt_addr, struct hl_mmu_hop_info *hops);
2773 struct hl_hr_mmu_funcs hr_funcs;
2774 };
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785 struct hl_prefetch_work {
2786 struct work_struct pf_work;
2787 struct hl_ctx *ctx;
2788 u64 va;
2789 u64 size;
2790 u32 flags;
2791 u32 asid;
2792 };
2793
2794
2795
2796
2797
2798 #define MULTI_CS_MAX_USER_CTX 2
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809 struct multi_cs_completion {
2810 struct completion completion;
2811 spinlock_t lock;
2812 s64 timestamp;
2813 u32 stream_master_qid_map;
2814 u8 used;
2815 };
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830 struct multi_cs_data {
2831 struct hl_ctx *ctx;
2832 struct hl_fence **fence_arr;
2833 u64 *seq_arr;
2834 s64 timeout_jiffies;
2835 s64 timestamp;
2836 long wait_status;
2837 u32 completion_bitmap;
2838 u8 arr_len;
2839 u8 gone_cs;
2840 u8 update_ts;
2841 };
2842
2843
2844
2845
2846
2847
2848 struct hl_clk_throttle_timestamp {
2849 ktime_t start;
2850 ktime_t end;
2851 };
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862 struct hl_clk_throttle {
2863 struct hl_clk_throttle_timestamp timestamp[HL_CLK_THROTTLE_TYPE_MAX];
2864 struct mutex lock;
2865 u32 current_reason;
2866 u32 aggregated_reason;
2867 };
2868
2869
2870
2871
2872
2873
2874 struct user_mapped_block {
2875 u32 address;
2876 u32 size;
2877 };
2878
2879
2880
2881
2882
2883
2884
2885
2886 struct cs_timeout_info {
2887 ktime_t timestamp;
2888 atomic_t write_enable;
2889 u64 seq;
2890 };
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906 struct razwi_info {
2907 ktime_t timestamp;
2908 atomic_t write_enable;
2909 u64 addr;
2910 u16 engine_id_1;
2911 u16 engine_id_2;
2912 u8 non_engine_initiator;
2913 u8 type;
2914 };
2915
2916 #define MAX_QMAN_STREAMS_INFO 4
2917 #define OPCODE_INFO_MAX_ADDR_SIZE 8
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937 struct undefined_opcode_info {
2938 ktime_t timestamp;
2939 u64 cb_addr_streams[MAX_QMAN_STREAMS_INFO][OPCODE_INFO_MAX_ADDR_SIZE];
2940 u64 cq_addr;
2941 u32 cq_size;
2942 u32 cb_addr_streams_len;
2943 u32 engine_id;
2944 u32 stream_id;
2945 bool write_enable;
2946 };
2947
2948
2949
2950
2951
2952
2953
2954 struct last_error_session_info {
2955 struct cs_timeout_info cs_timeout;
2956 struct razwi_info razwi;
2957 struct undefined_opcode_info undef_opcode;
2958 };
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981 struct hl_reset_info {
2982 spinlock_t lock;
2983 u32 compute_reset_cnt;
2984 u32 hard_reset_cnt;
2985 u32 hard_reset_schedule_flags;
2986 u8 in_reset;
2987 u8 in_compute_reset;
2988 u8 needs_reset;
2989 u8 hard_reset_pending;
2990
2991 u8 curr_reset_cause;
2992 u8 prev_reset_trigger;
2993 u8 reset_trigger_repeated;
2994
2995 u8 skip_reset_on_timeout;
2996 };
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169 struct hl_device {
3170 struct pci_dev *pdev;
3171 u64 pcie_bar_phys[HL_PCI_NUM_BARS];
3172 void __iomem *pcie_bar[HL_PCI_NUM_BARS];
3173 void __iomem *rmmio;
3174 struct cdev cdev;
3175 struct cdev cdev_ctrl;
3176 struct device *dev;
3177 struct device *dev_ctrl;
3178 struct delayed_work work_heartbeat;
3179 struct hl_device_reset_work device_reset_work;
3180 char asic_name[HL_STR_MAX];
3181 char status[HL_DEV_STS_MAX][HL_STR_MAX];
3182 enum hl_asic_type asic_type;
3183 struct hl_cq *completion_queue;
3184 struct hl_user_interrupt *user_interrupt;
3185 struct hl_user_interrupt common_user_cq_interrupt;
3186 struct hl_user_interrupt common_decoder_interrupt;
3187 struct hl_cs **shadow_cs_queue;
3188 struct workqueue_struct **cq_wq;
3189 struct workqueue_struct *eq_wq;
3190 struct workqueue_struct *cs_cmplt_wq;
3191 struct workqueue_struct *ts_free_obj_wq;
3192 struct workqueue_struct *pf_wq;
3193 struct hl_ctx *kernel_ctx;
3194 struct hl_hw_queue *kernel_queues;
3195 struct list_head cs_mirror_list;
3196 spinlock_t cs_mirror_lock;
3197 struct hl_mem_mgr kernel_mem_mgr;
3198 struct hl_eq event_queue;
3199 struct dma_pool *dma_pool;
3200 void *cpu_accessible_dma_mem;
3201 dma_addr_t cpu_accessible_dma_address;
3202 struct gen_pool *cpu_accessible_dma_pool;
3203 unsigned long *asid_bitmap;
3204 struct mutex asid_mutex;
3205 struct mutex send_cpu_message_lock;
3206 struct mutex debug_lock;
3207 struct asic_fixed_properties asic_prop;
3208 const struct hl_asic_funcs *asic_funcs;
3209 void *asic_specific;
3210 struct hl_vm vm;
3211 struct device *hwmon_dev;
3212 struct hwmon_chip_info *hl_chip_info;
3213
3214 struct hl_dbg_device_entry hl_debugfs;
3215
3216 struct list_head cb_pool;
3217 spinlock_t cb_pool_lock;
3218
3219 void *internal_cb_pool_virt_addr;
3220 dma_addr_t internal_cb_pool_dma_addr;
3221 struct gen_pool *internal_cb_pool;
3222 u64 internal_cb_va_base;
3223
3224 struct list_head fpriv_list;
3225 struct list_head fpriv_ctrl_list;
3226 struct mutex fpriv_list_lock;
3227 struct mutex fpriv_ctrl_list_lock;
3228
3229 struct hl_cs_counters_atomic aggregated_cs_counters;
3230
3231 struct hl_mmu_priv mmu_priv;
3232 struct hl_mmu_funcs mmu_func[MMU_NUM_PGT_LOCATIONS];
3233
3234 struct hl_dec *dec;
3235
3236 struct fw_load_mgr fw_loader;
3237
3238 struct pci_mem_region pci_mem_region[PCI_REGION_NUMBER];
3239
3240 struct hl_state_dump_specs state_dump_specs;
3241
3242 struct multi_cs_completion multi_cs_completion[
3243 MULTI_CS_MAX_USER_CTX];
3244 struct hl_clk_throttle clk_throttling;
3245 struct last_error_session_info last_error;
3246
3247 struct hl_reset_info reset_info;
3248
3249 u32 *stream_master_qid_arr;
3250 u32 fw_major_version;
3251 u32 fw_minor_version;
3252 atomic64_t dram_used_mem;
3253 u64 memory_scrub_val;
3254 u64 timeout_jiffies;
3255 u64 max_power;
3256 u64 boot_error_status_mask;
3257 u64 dram_pci_bar_start;
3258 u64 last_successful_open_jif;
3259 u64 last_open_session_duration_jif;
3260 u64 open_counter;
3261 u64 fw_poll_interval_usec;
3262 ktime_t last_successful_open_ktime;
3263 u64 fw_comms_poll_interval_usec;
3264 u64 dram_binning;
3265 u64 tpc_binning;
3266
3267 enum cpucp_card_types card_type;
3268 u32 major;
3269 u32 high_pll;
3270 u32 decoder_binning;
3271 u32 edma_binning;
3272 u16 id;
3273 u16 id_control;
3274 u16 cpu_pci_msb_addr;
3275 u8 is_in_dram_scrub;
3276 u8 disabled;
3277 u8 late_init_done;
3278 u8 hwmon_initialized;
3279 u8 reset_on_lockup;
3280 u8 dram_default_page_mapping;
3281 u8 memory_scrub;
3282 u8 pmmu_huge_range;
3283 u8 init_done;
3284 u8 device_cpu_disabled;
3285 u8 in_debug;
3286 u8 cdev_sysfs_created;
3287 u8 stop_on_err;
3288 u8 supports_sync_stream;
3289 u8 sync_stream_queue_idx;
3290 u8 collective_mon_idx;
3291 u8 supports_coresight;
3292 u8 supports_cb_mapping;
3293 u8 process_kill_trial_cnt;
3294 u8 device_fini_pending;
3295 u8 supports_staged_submission;
3296 u8 device_cpu_is_halted;
3297 u8 supports_wait_for_multi_cs;
3298 u8 stream_master_qid_arr_size;
3299 u8 is_compute_ctx_active;
3300 u8 compute_ctx_in_release;
3301 u8 supports_mmu_prefetch;
3302 u8 reset_upon_device_release;
3303
3304
3305 u64 nic_ports_mask;
3306 u64 fw_components;
3307 u8 mmu_enable;
3308 u8 cpu_queues_enable;
3309 u8 pldm;
3310 u8 hard_reset_on_fw_events;
3311 u8 bmc_enable;
3312 u8 reset_on_preboot_fail;
3313 u8 heartbeat;
3314 };
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330 struct hl_cs_encaps_sig_handle {
3331 struct kref refcount;
3332 struct hl_device *hdev;
3333 struct hl_hw_sob *hw_sob;
3334 struct hl_ctx *ctx;
3335 u64 cs_seq;
3336 u32 id;
3337 u32 q_idx;
3338 u32 pre_sob_val;
3339 u32 count;
3340 };
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354 typedef int hl_ioctl_t(struct hl_fpriv *hpriv, void *data);
3355
3356
3357
3358
3359
3360
3361 struct hl_ioctl_desc {
3362 unsigned int cmd;
3363 hl_ioctl_t *func;
3364 };
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380 static inline u32 hl_get_sg_info(struct scatterlist *sg, dma_addr_t *dma_addr)
3381 {
3382 *dma_addr = sg_dma_address(sg);
3383
3384 return ((((*dma_addr) & (PAGE_SIZE - 1)) + sg_dma_len(sg)) +
3385 (PAGE_SIZE - 1)) >> PAGE_SHIFT;
3386 }
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397 static inline bool hl_mem_area_inside_range(u64 address, u64 size,
3398 u64 range_start_address, u64 range_end_address)
3399 {
3400 u64 end_address = address + size;
3401
3402 if ((address >= range_start_address) &&
3403 (end_address <= range_end_address) &&
3404 (end_address > address))
3405 return true;
3406
3407 return false;
3408 }
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420 static inline bool hl_mem_area_crosses_range(u64 address, u32 size,
3421 u64 range_start_address, u64 range_end_address)
3422 {
3423 u64 end_address = address + size - 1;
3424
3425 return ((address <= range_end_address) && (range_start_address <= end_address));
3426 }
3427
3428 uint64_t hl_set_dram_bar_default(struct hl_device *hdev, u64 addr);
3429 void *hl_asic_dma_alloc_coherent(struct hl_device *hdev, size_t size, dma_addr_t *dma_handle,
3430 gfp_t flag);
3431 void hl_asic_dma_free_coherent(struct hl_device *hdev, size_t size, void *cpu_addr,
3432 dma_addr_t dma_handle);
3433 void *hl_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size, dma_addr_t *dma_handle);
3434 void hl_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size, void *vaddr);
3435 void *hl_asic_dma_pool_zalloc(struct hl_device *hdev, size_t size, gfp_t mem_flags,
3436 dma_addr_t *dma_handle);
3437 void hl_asic_dma_pool_free(struct hl_device *hdev, void *vaddr, dma_addr_t dma_addr);
3438 int hl_dma_map_sgtable(struct hl_device *hdev, struct sg_table *sgt, enum dma_data_direction dir);
3439 void hl_dma_unmap_sgtable(struct hl_device *hdev, struct sg_table *sgt,
3440 enum dma_data_direction dir);
3441 int hl_access_cfg_region(struct hl_device *hdev, u64 addr, u64 *val,
3442 enum debugfs_access_type acc_type);
3443 int hl_access_dev_mem(struct hl_device *hdev, enum pci_region region_type,
3444 u64 addr, u64 *val, enum debugfs_access_type acc_type);
3445 int hl_device_open(struct inode *inode, struct file *filp);
3446 int hl_device_open_ctrl(struct inode *inode, struct file *filp);
3447 bool hl_device_operational(struct hl_device *hdev,
3448 enum hl_device_status *status);
3449 enum hl_device_status hl_device_status(struct hl_device *hdev);
3450 int hl_device_set_debug_mode(struct hl_device *hdev, struct hl_ctx *ctx, bool enable);
3451 int hl_hw_queues_create(struct hl_device *hdev);
3452 void hl_hw_queues_destroy(struct hl_device *hdev);
3453 int hl_hw_queue_send_cb_no_cmpl(struct hl_device *hdev, u32 hw_queue_id,
3454 u32 cb_size, u64 cb_ptr);
3455 void hl_hw_queue_submit_bd(struct hl_device *hdev, struct hl_hw_queue *q,
3456 u32 ctl, u32 len, u64 ptr);
3457 int hl_hw_queue_schedule_cs(struct hl_cs *cs);
3458 u32 hl_hw_queue_add_ptr(u32 ptr, u16 val);
3459 void hl_hw_queue_inc_ci_kernel(struct hl_device *hdev, u32 hw_queue_id);
3460 void hl_hw_queue_update_ci(struct hl_cs *cs);
3461 void hl_hw_queue_reset(struct hl_device *hdev, bool hard_reset);
3462
3463 #define hl_queue_inc_ptr(p) hl_hw_queue_add_ptr(p, 1)
3464 #define hl_pi_2_offset(pi) ((pi) & (HL_QUEUE_LENGTH - 1))
3465
3466 int hl_cq_init(struct hl_device *hdev, struct hl_cq *q, u32 hw_queue_id);
3467 void hl_cq_fini(struct hl_device *hdev, struct hl_cq *q);
3468 int hl_eq_init(struct hl_device *hdev, struct hl_eq *q);
3469 void hl_eq_fini(struct hl_device *hdev, struct hl_eq *q);
3470 void hl_cq_reset(struct hl_device *hdev, struct hl_cq *q);
3471 void hl_eq_reset(struct hl_device *hdev, struct hl_eq *q);
3472 irqreturn_t hl_irq_handler_cq(int irq, void *arg);
3473 irqreturn_t hl_irq_handler_eq(int irq, void *arg);
3474 irqreturn_t hl_irq_handler_dec_abnrm(int irq, void *arg);
3475 irqreturn_t hl_irq_handler_user_interrupt(int irq, void *arg);
3476 irqreturn_t hl_irq_handler_default(int irq, void *arg);
3477 u32 hl_cq_inc_ptr(u32 ptr);
3478
3479 int hl_asid_init(struct hl_device *hdev);
3480 void hl_asid_fini(struct hl_device *hdev);
3481 unsigned long hl_asid_alloc(struct hl_device *hdev);
3482 void hl_asid_free(struct hl_device *hdev, unsigned long asid);
3483
3484 int hl_ctx_create(struct hl_device *hdev, struct hl_fpriv *hpriv);
3485 void hl_ctx_free(struct hl_device *hdev, struct hl_ctx *ctx);
3486 int hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx);
3487 void hl_ctx_do_release(struct kref *ref);
3488 void hl_ctx_get(struct hl_ctx *ctx);
3489 int hl_ctx_put(struct hl_ctx *ctx);
3490 struct hl_ctx *hl_get_compute_ctx(struct hl_device *hdev);
3491 struct hl_fence *hl_ctx_get_fence(struct hl_ctx *ctx, u64 seq);
3492 int hl_ctx_get_fences(struct hl_ctx *ctx, u64 *seq_arr,
3493 struct hl_fence **fence, u32 arr_len);
3494 void hl_ctx_mgr_init(struct hl_ctx_mgr *mgr);
3495 void hl_ctx_mgr_fini(struct hl_device *hdev, struct hl_ctx_mgr *mgr);
3496
3497 int hl_device_init(struct hl_device *hdev, struct class *hclass);
3498 void hl_device_fini(struct hl_device *hdev);
3499 int hl_device_suspend(struct hl_device *hdev);
3500 int hl_device_resume(struct hl_device *hdev);
3501 int hl_device_reset(struct hl_device *hdev, u32 flags);
3502 void hl_hpriv_get(struct hl_fpriv *hpriv);
3503 int hl_hpriv_put(struct hl_fpriv *hpriv);
3504 int hl_device_utilization(struct hl_device *hdev, u32 *utilization);
3505
3506 int hl_build_hwmon_channel_info(struct hl_device *hdev,
3507 struct cpucp_sensor *sensors_arr);
3508
3509 void hl_notifier_event_send_all(struct hl_device *hdev, u64 event_mask);
3510
3511 int hl_sysfs_init(struct hl_device *hdev);
3512 void hl_sysfs_fini(struct hl_device *hdev);
3513
3514 int hl_hwmon_init(struct hl_device *hdev);
3515 void hl_hwmon_fini(struct hl_device *hdev);
3516
3517 int hl_cb_create(struct hl_device *hdev, struct hl_mem_mgr *mmg,
3518 struct hl_ctx *ctx, u32 cb_size, bool internal_cb,
3519 bool map_cb, u64 *handle);
3520 int hl_cb_destroy(struct hl_mem_mgr *mmg, u64 cb_handle);
3521 int hl_hw_block_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma);
3522 struct hl_cb *hl_cb_get(struct hl_mem_mgr *mmg, u64 handle);
3523 void hl_cb_put(struct hl_cb *cb);
3524 struct hl_cb *hl_cb_kernel_create(struct hl_device *hdev, u32 cb_size,
3525 bool internal_cb);
3526 int hl_cb_pool_init(struct hl_device *hdev);
3527 int hl_cb_pool_fini(struct hl_device *hdev);
3528 int hl_cb_va_pool_init(struct hl_ctx *ctx);
3529 void hl_cb_va_pool_fini(struct hl_ctx *ctx);
3530
3531 void hl_cs_rollback_all(struct hl_device *hdev, bool skip_wq_flush);
3532 struct hl_cs_job *hl_cs_allocate_job(struct hl_device *hdev,
3533 enum hl_queue_type queue_type, bool is_kernel_allocated_cb);
3534 void hl_sob_reset_error(struct kref *ref);
3535 int hl_gen_sob_mask(u16 sob_base, u8 sob_mask, u8 *mask);
3536 void hl_fence_put(struct hl_fence *fence);
3537 void hl_fences_put(struct hl_fence **fence, int len);
3538 void hl_fence_get(struct hl_fence *fence);
3539 void cs_get(struct hl_cs *cs);
3540 bool cs_needs_completion(struct hl_cs *cs);
3541 bool cs_needs_timeout(struct hl_cs *cs);
3542 bool is_staged_cs_last_exists(struct hl_device *hdev, struct hl_cs *cs);
3543 struct hl_cs *hl_staged_cs_find_first(struct hl_device *hdev, u64 cs_seq);
3544 void hl_multi_cs_completion_init(struct hl_device *hdev);
3545
3546 void goya_set_asic_funcs(struct hl_device *hdev);
3547 void gaudi_set_asic_funcs(struct hl_device *hdev);
3548 void gaudi2_set_asic_funcs(struct hl_device *hdev);
3549
3550 int hl_vm_ctx_init(struct hl_ctx *ctx);
3551 void hl_vm_ctx_fini(struct hl_ctx *ctx);
3552
3553 int hl_vm_init(struct hl_device *hdev);
3554 void hl_vm_fini(struct hl_device *hdev);
3555
3556 void hl_hw_block_mem_init(struct hl_ctx *ctx);
3557 void hl_hw_block_mem_fini(struct hl_ctx *ctx);
3558
3559 u64 hl_reserve_va_block(struct hl_device *hdev, struct hl_ctx *ctx,
3560 enum hl_va_range_type type, u32 size, u32 alignment);
3561 int hl_unreserve_va_block(struct hl_device *hdev, struct hl_ctx *ctx,
3562 u64 start_addr, u64 size);
3563 int hl_pin_host_memory(struct hl_device *hdev, u64 addr, u64 size,
3564 struct hl_userptr *userptr);
3565 void hl_unpin_host_memory(struct hl_device *hdev, struct hl_userptr *userptr);
3566 void hl_userptr_delete_list(struct hl_device *hdev,
3567 struct list_head *userptr_list);
3568 bool hl_userptr_is_pinned(struct hl_device *hdev, u64 addr, u32 size,
3569 struct list_head *userptr_list,
3570 struct hl_userptr **userptr);
3571
3572 int hl_mmu_init(struct hl_device *hdev);
3573 void hl_mmu_fini(struct hl_device *hdev);
3574 int hl_mmu_ctx_init(struct hl_ctx *ctx);
3575 void hl_mmu_ctx_fini(struct hl_ctx *ctx);
3576 int hl_mmu_map_page(struct hl_ctx *ctx, u64 virt_addr, u64 phys_addr,
3577 u32 page_size, bool flush_pte);
3578 int hl_mmu_get_real_page_size(struct hl_device *hdev, struct hl_mmu_properties *mmu_prop,
3579 u32 page_size, u32 *real_page_size, bool is_dram_addr);
3580 int hl_mmu_unmap_page(struct hl_ctx *ctx, u64 virt_addr, u32 page_size,
3581 bool flush_pte);
3582 int hl_mmu_map_contiguous(struct hl_ctx *ctx, u64 virt_addr,
3583 u64 phys_addr, u32 size);
3584 int hl_mmu_unmap_contiguous(struct hl_ctx *ctx, u64 virt_addr, u32 size);
3585 int hl_mmu_invalidate_cache(struct hl_device *hdev, bool is_hard, u32 flags);
3586 int hl_mmu_invalidate_cache_range(struct hl_device *hdev, bool is_hard,
3587 u32 flags, u32 asid, u64 va, u64 size);
3588 int hl_mmu_prefetch_cache_range(struct hl_ctx *ctx, u32 flags, u32 asid, u64 va, u64 size);
3589 u64 hl_mmu_get_next_hop_addr(struct hl_ctx *ctx, u64 curr_pte);
3590 u64 hl_mmu_get_hop_pte_phys_addr(struct hl_ctx *ctx, struct hl_mmu_properties *mmu_prop,
3591 u8 hop_idx, u64 hop_addr, u64 virt_addr);
3592 void hl_mmu_hr_flush(struct hl_ctx *ctx);
3593 int hl_mmu_hr_init(struct hl_device *hdev, struct hl_mmu_hr_priv *hr_priv, u32 hop_table_size,
3594 u64 pgt_size);
3595 void hl_mmu_hr_fini(struct hl_device *hdev, struct hl_mmu_hr_priv *hr_priv, u32 hop_table_size);
3596 void hl_mmu_hr_free_hop_remove_pgt(struct pgt_info *pgt_info, struct hl_mmu_hr_priv *hr_priv,
3597 u32 hop_table_size);
3598 u64 hl_mmu_hr_pte_phys_to_virt(struct hl_ctx *ctx, struct pgt_info *pgt, u64 phys_pte_addr,
3599 u32 hop_table_size);
3600 void hl_mmu_hr_write_pte(struct hl_ctx *ctx, struct pgt_info *pgt_info, u64 phys_pte_addr,
3601 u64 val, u32 hop_table_size);
3602 void hl_mmu_hr_clear_pte(struct hl_ctx *ctx, struct pgt_info *pgt_info, u64 phys_pte_addr,
3603 u32 hop_table_size);
3604 int hl_mmu_hr_put_pte(struct hl_ctx *ctx, struct pgt_info *pgt_info, struct hl_mmu_hr_priv *hr_priv,
3605 u32 hop_table_size);
3606 void hl_mmu_hr_get_pte(struct hl_ctx *ctx, struct hl_hr_mmu_funcs *hr_func, u64 phys_hop_addr);
3607 struct pgt_info *hl_mmu_hr_get_next_hop_pgt_info(struct hl_ctx *ctx,
3608 struct hl_hr_mmu_funcs *hr_func,
3609 u64 curr_pte);
3610 struct pgt_info *hl_mmu_hr_alloc_hop(struct hl_ctx *ctx, struct hl_mmu_hr_priv *hr_priv,
3611 struct hl_hr_mmu_funcs *hr_func,
3612 struct hl_mmu_properties *mmu_prop);
3613 struct pgt_info *hl_mmu_hr_get_alloc_next_hop(struct hl_ctx *ctx,
3614 struct hl_mmu_hr_priv *hr_priv,
3615 struct hl_hr_mmu_funcs *hr_func,
3616 struct hl_mmu_properties *mmu_prop,
3617 u64 curr_pte, bool *is_new_hop);
3618 int hl_mmu_hr_get_tlb_info(struct hl_ctx *ctx, u64 virt_addr, struct hl_mmu_hop_info *hops,
3619 struct hl_hr_mmu_funcs *hr_func);
3620 void hl_mmu_swap_out(struct hl_ctx *ctx);
3621 void hl_mmu_swap_in(struct hl_ctx *ctx);
3622 int hl_mmu_if_set_funcs(struct hl_device *hdev);
3623 void hl_mmu_v1_set_funcs(struct hl_device *hdev, struct hl_mmu_funcs *mmu);
3624 void hl_mmu_v2_hr_set_funcs(struct hl_device *hdev, struct hl_mmu_funcs *mmu);
3625 int hl_mmu_va_to_pa(struct hl_ctx *ctx, u64 virt_addr, u64 *phys_addr);
3626 int hl_mmu_get_tlb_info(struct hl_ctx *ctx, u64 virt_addr,
3627 struct hl_mmu_hop_info *hops);
3628 u64 hl_mmu_scramble_addr(struct hl_device *hdev, u64 addr);
3629 u64 hl_mmu_descramble_addr(struct hl_device *hdev, u64 addr);
3630 bool hl_is_dram_va(struct hl_device *hdev, u64 virt_addr);
3631
3632 int hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name,
3633 void __iomem *dst, u32 src_offset, u32 size);
3634 int hl_fw_send_pci_access_msg(struct hl_device *hdev, u32 opcode, u64 value);
3635 int hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg,
3636 u16 len, u32 timeout, u64 *result);
3637 int hl_fw_unmask_irq(struct hl_device *hdev, u16 event_type);
3638 int hl_fw_unmask_irq_arr(struct hl_device *hdev, const u32 *irq_arr,
3639 size_t irq_arr_size);
3640 int hl_fw_test_cpu_queue(struct hl_device *hdev);
3641 void *hl_fw_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size,
3642 dma_addr_t *dma_handle);
3643 void hl_fw_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size,
3644 void *vaddr);
3645 int hl_fw_send_heartbeat(struct hl_device *hdev);
3646 int hl_fw_cpucp_info_get(struct hl_device *hdev,
3647 u32 sts_boot_dev_sts0_reg,
3648 u32 sts_boot_dev_sts1_reg, u32 boot_err0_reg,
3649 u32 boot_err1_reg);
3650 int hl_fw_cpucp_handshake(struct hl_device *hdev,
3651 u32 sts_boot_dev_sts0_reg,
3652 u32 sts_boot_dev_sts1_reg, u32 boot_err0_reg,
3653 u32 boot_err1_reg);
3654 int hl_fw_get_eeprom_data(struct hl_device *hdev, void *data, size_t max_size);
3655 int hl_fw_get_monitor_dump(struct hl_device *hdev, void *data);
3656 int hl_fw_cpucp_pci_counters_get(struct hl_device *hdev,
3657 struct hl_info_pci_counters *counters);
3658 int hl_fw_cpucp_total_energy_get(struct hl_device *hdev,
3659 u64 *total_energy);
3660 int get_used_pll_index(struct hl_device *hdev, u32 input_pll_index,
3661 enum pll_index *pll_index);
3662 int hl_fw_cpucp_pll_info_get(struct hl_device *hdev, u32 pll_index,
3663 u16 *pll_freq_arr);
3664 int hl_fw_cpucp_power_get(struct hl_device *hdev, u64 *power);
3665 void hl_fw_ask_hard_reset_without_linux(struct hl_device *hdev);
3666 void hl_fw_ask_halt_machine_without_linux(struct hl_device *hdev);
3667 int hl_fw_init_cpu(struct hl_device *hdev);
3668 int hl_fw_read_preboot_status(struct hl_device *hdev);
3669 int hl_fw_dynamic_send_protocol_cmd(struct hl_device *hdev,
3670 struct fw_load_mgr *fw_loader,
3671 enum comms_cmd cmd, unsigned int size,
3672 bool wait_ok, u32 timeout);
3673 int hl_fw_dram_replaced_row_get(struct hl_device *hdev,
3674 struct cpucp_hbm_row_info *info);
3675 int hl_fw_dram_pending_row_get(struct hl_device *hdev, u32 *pend_rows_num);
3676 int hl_fw_cpucp_engine_core_asid_set(struct hl_device *hdev, u32 asid);
3677 int hl_pci_bars_map(struct hl_device *hdev, const char * const name[3],
3678 bool is_wc[3]);
3679 int hl_pci_elbi_read(struct hl_device *hdev, u64 addr, u32 *data);
3680 int hl_pci_iatu_write(struct hl_device *hdev, u32 addr, u32 data);
3681 int hl_pci_set_inbound_region(struct hl_device *hdev, u8 region,
3682 struct hl_inbound_pci_region *pci_region);
3683 int hl_pci_set_outbound_region(struct hl_device *hdev,
3684 struct hl_outbound_pci_region *pci_region);
3685 enum pci_region hl_get_pci_memory_region(struct hl_device *hdev, u64 addr);
3686 int hl_pci_init(struct hl_device *hdev);
3687 void hl_pci_fini(struct hl_device *hdev);
3688
3689 long hl_fw_get_frequency(struct hl_device *hdev, u32 pll_index, bool curr);
3690 void hl_fw_set_frequency(struct hl_device *hdev, u32 pll_index, u64 freq);
3691 int hl_get_temperature(struct hl_device *hdev, int sensor_index, u32 attr, long *value);
3692 int hl_set_temperature(struct hl_device *hdev, int sensor_index, u32 attr, long value);
3693 int hl_get_voltage(struct hl_device *hdev, int sensor_index, u32 attr, long *value);
3694 int hl_get_current(struct hl_device *hdev, int sensor_index, u32 attr, long *value);
3695 int hl_get_fan_speed(struct hl_device *hdev, int sensor_index, u32 attr, long *value);
3696 int hl_get_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr, long *value);
3697 void hl_set_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr, long value);
3698 long hl_fw_get_max_power(struct hl_device *hdev);
3699 void hl_fw_set_max_power(struct hl_device *hdev);
3700 int hl_set_voltage(struct hl_device *hdev, int sensor_index, u32 attr, long value);
3701 int hl_set_current(struct hl_device *hdev, int sensor_index, u32 attr, long value);
3702 int hl_set_power(struct hl_device *hdev, int sensor_index, u32 attr, long value);
3703 int hl_get_power(struct hl_device *hdev, int sensor_index, u32 attr, long *value);
3704 int hl_fw_get_clk_rate(struct hl_device *hdev, u32 *cur_clk, u32 *max_clk);
3705 void hl_fw_set_pll_profile(struct hl_device *hdev);
3706 void hl_sysfs_add_dev_clk_attr(struct hl_device *hdev, struct attribute_group *dev_clk_attr_grp);
3707 void hl_sysfs_add_dev_vrm_attr(struct hl_device *hdev, struct attribute_group *dev_vrm_attr_grp);
3708
3709 void hw_sob_get(struct hl_hw_sob *hw_sob);
3710 void hw_sob_put(struct hl_hw_sob *hw_sob);
3711 void hl_encaps_handle_do_release(struct kref *ref);
3712 void hl_hw_queue_encaps_sig_set_sob_info(struct hl_device *hdev,
3713 struct hl_cs *cs, struct hl_cs_job *job,
3714 struct hl_cs_compl *cs_cmpl);
3715
3716 int hl_dec_init(struct hl_device *hdev);
3717 void hl_dec_fini(struct hl_device *hdev);
3718 void hl_dec_ctx_fini(struct hl_ctx *ctx);
3719
3720 void hl_release_pending_user_interrupts(struct hl_device *hdev);
3721 int hl_cs_signal_sob_wraparound_handler(struct hl_device *hdev, u32 q_idx,
3722 struct hl_hw_sob **hw_sob, u32 count, bool encaps_sig);
3723
3724 int hl_state_dump(struct hl_device *hdev);
3725 const char *hl_state_dump_get_sync_name(struct hl_device *hdev, u32 sync_id);
3726 const char *hl_state_dump_get_monitor_name(struct hl_device *hdev,
3727 struct hl_mon_state_dump *mon);
3728 void hl_state_dump_free_sync_to_engine_map(struct hl_sync_to_engine_map *map);
3729 __printf(4, 5) int hl_snprintf_resize(char **buf, size_t *size, size_t *offset,
3730 const char *format, ...);
3731 char *hl_format_as_binary(char *buf, size_t buf_len, u32 n);
3732 const char *hl_sync_engine_to_string(enum hl_sync_engine_type engine_type);
3733
3734 void hl_mem_mgr_init(struct device *dev, struct hl_mem_mgr *mmg);
3735 void hl_mem_mgr_fini(struct hl_mem_mgr *mmg);
3736 int hl_mem_mgr_mmap(struct hl_mem_mgr *mmg, struct vm_area_struct *vma,
3737 void *args);
3738 struct hl_mmap_mem_buf *hl_mmap_mem_buf_get(struct hl_mem_mgr *mmg,
3739 u64 handle);
3740 int hl_mmap_mem_buf_put_handle(struct hl_mem_mgr *mmg, u64 handle);
3741 int hl_mmap_mem_buf_put(struct hl_mmap_mem_buf *buf);
3742 struct hl_mmap_mem_buf *
3743 hl_mmap_mem_buf_alloc(struct hl_mem_mgr *mmg,
3744 struct hl_mmap_mem_buf_behavior *behavior, gfp_t gfp,
3745 void *args);
3746
3747 #ifdef CONFIG_DEBUG_FS
3748
3749 void hl_debugfs_init(void);
3750 void hl_debugfs_fini(void);
3751 void hl_debugfs_add_device(struct hl_device *hdev);
3752 void hl_debugfs_remove_device(struct hl_device *hdev);
3753 void hl_debugfs_add_file(struct hl_fpriv *hpriv);
3754 void hl_debugfs_remove_file(struct hl_fpriv *hpriv);
3755 void hl_debugfs_add_cb(struct hl_cb *cb);
3756 void hl_debugfs_remove_cb(struct hl_cb *cb);
3757 void hl_debugfs_add_cs(struct hl_cs *cs);
3758 void hl_debugfs_remove_cs(struct hl_cs *cs);
3759 void hl_debugfs_add_job(struct hl_device *hdev, struct hl_cs_job *job);
3760 void hl_debugfs_remove_job(struct hl_device *hdev, struct hl_cs_job *job);
3761 void hl_debugfs_add_userptr(struct hl_device *hdev, struct hl_userptr *userptr);
3762 void hl_debugfs_remove_userptr(struct hl_device *hdev,
3763 struct hl_userptr *userptr);
3764 void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx);
3765 void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx);
3766 void hl_debugfs_set_state_dump(struct hl_device *hdev, char *data,
3767 unsigned long length);
3768
3769 #else
3770
3771 static inline void __init hl_debugfs_init(void)
3772 {
3773 }
3774
3775 static inline void hl_debugfs_fini(void)
3776 {
3777 }
3778
3779 static inline void hl_debugfs_add_device(struct hl_device *hdev)
3780 {
3781 }
3782
3783 static inline void hl_debugfs_remove_device(struct hl_device *hdev)
3784 {
3785 }
3786
3787 static inline void hl_debugfs_add_file(struct hl_fpriv *hpriv)
3788 {
3789 }
3790
3791 static inline void hl_debugfs_remove_file(struct hl_fpriv *hpriv)
3792 {
3793 }
3794
3795 static inline void hl_debugfs_add_cb(struct hl_cb *cb)
3796 {
3797 }
3798
3799 static inline void hl_debugfs_remove_cb(struct hl_cb *cb)
3800 {
3801 }
3802
3803 static inline void hl_debugfs_add_cs(struct hl_cs *cs)
3804 {
3805 }
3806
3807 static inline void hl_debugfs_remove_cs(struct hl_cs *cs)
3808 {
3809 }
3810
3811 static inline void hl_debugfs_add_job(struct hl_device *hdev,
3812 struct hl_cs_job *job)
3813 {
3814 }
3815
3816 static inline void hl_debugfs_remove_job(struct hl_device *hdev,
3817 struct hl_cs_job *job)
3818 {
3819 }
3820
3821 static inline void hl_debugfs_add_userptr(struct hl_device *hdev,
3822 struct hl_userptr *userptr)
3823 {
3824 }
3825
3826 static inline void hl_debugfs_remove_userptr(struct hl_device *hdev,
3827 struct hl_userptr *userptr)
3828 {
3829 }
3830
3831 static inline void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev,
3832 struct hl_ctx *ctx)
3833 {
3834 }
3835
3836 static inline void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev,
3837 struct hl_ctx *ctx)
3838 {
3839 }
3840
3841 static inline void hl_debugfs_set_state_dump(struct hl_device *hdev,
3842 char *data, unsigned long length)
3843 {
3844 }
3845
3846 #endif
3847
3848
3849 int hl_unsecure_register(struct hl_device *hdev, u32 mm_reg_addr, int offset,
3850 const u32 pb_blocks[], struct hl_block_glbl_sec sgs_array[],
3851 int array_size);
3852 int hl_unsecure_registers(struct hl_device *hdev, const u32 mm_reg_array[],
3853 int mm_array_size, int offset, const u32 pb_blocks[],
3854 struct hl_block_glbl_sec sgs_array[], int blocks_array_size);
3855 void hl_config_glbl_sec(struct hl_device *hdev, const u32 pb_blocks[],
3856 struct hl_block_glbl_sec sgs_array[], u32 block_offset,
3857 int array_size);
3858 void hl_secure_block(struct hl_device *hdev,
3859 struct hl_block_glbl_sec sgs_array[], int array_size);
3860 int hl_init_pb_with_mask(struct hl_device *hdev, u32 num_dcores,
3861 u32 dcore_offset, u32 num_instances, u32 instance_offset,
3862 const u32 pb_blocks[], u32 blocks_array_size,
3863 const u32 *regs_array, u32 regs_array_size, u64 mask);
3864 int hl_init_pb(struct hl_device *hdev, u32 num_dcores, u32 dcore_offset,
3865 u32 num_instances, u32 instance_offset,
3866 const u32 pb_blocks[], u32 blocks_array_size,
3867 const u32 *regs_array, u32 regs_array_size);
3868 int hl_init_pb_ranges_with_mask(struct hl_device *hdev, u32 num_dcores,
3869 u32 dcore_offset, u32 num_instances, u32 instance_offset,
3870 const u32 pb_blocks[], u32 blocks_array_size,
3871 const struct range *regs_range_array, u32 regs_range_array_size,
3872 u64 mask);
3873 int hl_init_pb_ranges(struct hl_device *hdev, u32 num_dcores,
3874 u32 dcore_offset, u32 num_instances, u32 instance_offset,
3875 const u32 pb_blocks[], u32 blocks_array_size,
3876 const struct range *regs_range_array,
3877 u32 regs_range_array_size);
3878 int hl_init_pb_single_dcore(struct hl_device *hdev, u32 dcore_offset,
3879 u32 num_instances, u32 instance_offset,
3880 const u32 pb_blocks[], u32 blocks_array_size,
3881 const u32 *regs_array, u32 regs_array_size);
3882 int hl_init_pb_ranges_single_dcore(struct hl_device *hdev, u32 dcore_offset,
3883 u32 num_instances, u32 instance_offset,
3884 const u32 pb_blocks[], u32 blocks_array_size,
3885 const struct range *regs_range_array,
3886 u32 regs_range_array_size);
3887 void hl_ack_pb(struct hl_device *hdev, u32 num_dcores, u32 dcore_offset,
3888 u32 num_instances, u32 instance_offset,
3889 const u32 pb_blocks[], u32 blocks_array_size);
3890 void hl_ack_pb_with_mask(struct hl_device *hdev, u32 num_dcores,
3891 u32 dcore_offset, u32 num_instances, u32 instance_offset,
3892 const u32 pb_blocks[], u32 blocks_array_size, u64 mask);
3893 void hl_ack_pb_single_dcore(struct hl_device *hdev, u32 dcore_offset,
3894 u32 num_instances, u32 instance_offset,
3895 const u32 pb_blocks[], u32 blocks_array_size);
3896
3897
3898 long hl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
3899 long hl_ioctl_control(struct file *filep, unsigned int cmd, unsigned long arg);
3900 int hl_cb_ioctl(struct hl_fpriv *hpriv, void *data);
3901 int hl_cs_ioctl(struct hl_fpriv *hpriv, void *data);
3902 int hl_wait_ioctl(struct hl_fpriv *hpriv, void *data);
3903 int hl_mem_ioctl(struct hl_fpriv *hpriv, void *data);
3904
3905 #endif