14a488a7aSOded Gabbay /* 24a488a7aSOded Gabbay * Copyright 2014 Advanced Micro Devices, Inc. 34a488a7aSOded Gabbay * 44a488a7aSOded Gabbay * Permission is hereby granted, free of charge, to any person obtaining a 54a488a7aSOded Gabbay * copy of this software and associated documentation files (the "Software"), 64a488a7aSOded Gabbay * to deal in the Software without restriction, including without limitation 74a488a7aSOded Gabbay * the rights to use, copy, modify, merge, publish, distribute, sublicense, 84a488a7aSOded Gabbay * and/or sell copies of the Software, and to permit persons to whom the 94a488a7aSOded Gabbay * Software is furnished to do so, subject to the following conditions: 104a488a7aSOded Gabbay * 114a488a7aSOded Gabbay * The above copyright notice and this permission notice shall be included in 124a488a7aSOded Gabbay * all copies or substantial portions of the Software. 134a488a7aSOded Gabbay * 144a488a7aSOded Gabbay * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 154a488a7aSOded Gabbay * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 164a488a7aSOded Gabbay * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 174a488a7aSOded Gabbay * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 184a488a7aSOded Gabbay * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 194a488a7aSOded Gabbay * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 204a488a7aSOded Gabbay * OTHER DEALINGS IN THE SOFTWARE. 214a488a7aSOded Gabbay */ 224a488a7aSOded Gabbay 234a488a7aSOded Gabbay #ifndef KFD_PRIV_H_INCLUDED 244a488a7aSOded Gabbay #define KFD_PRIV_H_INCLUDED 254a488a7aSOded Gabbay 264a488a7aSOded Gabbay #include <linux/hashtable.h> 274a488a7aSOded Gabbay #include <linux/mmu_notifier.h> 284a488a7aSOded Gabbay #include <linux/mutex.h> 294a488a7aSOded Gabbay #include <linux/types.h> 304a488a7aSOded Gabbay #include <linux/atomic.h> 314a488a7aSOded Gabbay #include <linux/workqueue.h> 324a488a7aSOded Gabbay #include <linux/spinlock.h> 3319f6d2a6SOded Gabbay #include <linux/kfd_ioctl.h> 34482f0777SFelix Kuehling #include <linux/idr.h> 3504ad47bdSAndres Rodriguez #include <linux/kfifo.h> 36851a645eSFelix Kuehling #include <linux/seq_file.h> 375ce10687SFelix Kuehling #include <linux/kref.h> 38de9f26bbSKent Russell #include <linux/sysfs.h> 396b855f7bSHarish Kasiviswanathan #include <linux/device_cgroup.h> 401cd4d9eeSStephen Rothwell #include <drm/drm_file.h> 411cd4d9eeSStephen Rothwell #include <drm/drm_drv.h> 421cd4d9eeSStephen Rothwell #include <drm/drm_device.h> 434a488a7aSOded Gabbay #include <kgd_kfd_interface.h> 446d220a7eSAmber Lin #include <linux/swap.h> 454a488a7aSOded Gabbay 46e596b903SYong Zhao #include "amd_shared.h" 47e596b903SYong Zhao 48af47b390SLaura Abbott #define KFD_MAX_RING_ENTRY_SIZE 8 49af47b390SLaura Abbott 505b5c4e40SEvgeny Pinchuk #define KFD_SYSFS_FILE_MODE 0444 515b5c4e40SEvgeny Pinchuk 52df03ef93SHarish Kasiviswanathan /* GPU ID hash width in bits */ 53df03ef93SHarish Kasiviswanathan #define KFD_GPU_ID_HASH_WIDTH 16 54df03ef93SHarish Kasiviswanathan 55df03ef93SHarish Kasiviswanathan /* Use upper bits of mmap offset to store KFD driver specific information. 56df03ef93SHarish Kasiviswanathan * BITS[63:62] - Encode MMAP type 57df03ef93SHarish Kasiviswanathan * BITS[61:46] - Encode gpu_id. To identify to which GPU the offset belongs to 58df03ef93SHarish Kasiviswanathan * BITS[45:0] - MMAP offset value 59df03ef93SHarish Kasiviswanathan * 60df03ef93SHarish Kasiviswanathan * NOTE: struct vm_area_struct.vm_pgoff uses offset in pages. Hence, these 61df03ef93SHarish Kasiviswanathan * defines are w.r.t to PAGE_SIZE 62df03ef93SHarish Kasiviswanathan */ 6329453755SYong Zhao #define KFD_MMAP_TYPE_SHIFT 62 64df03ef93SHarish Kasiviswanathan #define KFD_MMAP_TYPE_MASK (0x3ULL << KFD_MMAP_TYPE_SHIFT) 65df03ef93SHarish Kasiviswanathan #define KFD_MMAP_TYPE_DOORBELL (0x3ULL << KFD_MMAP_TYPE_SHIFT) 66df03ef93SHarish Kasiviswanathan #define KFD_MMAP_TYPE_EVENTS (0x2ULL << KFD_MMAP_TYPE_SHIFT) 67df03ef93SHarish Kasiviswanathan #define KFD_MMAP_TYPE_RESERVED_MEM (0x1ULL << KFD_MMAP_TYPE_SHIFT) 68d33ea570SOak Zeng #define KFD_MMAP_TYPE_MMIO (0x0ULL << KFD_MMAP_TYPE_SHIFT) 69df03ef93SHarish Kasiviswanathan 7029453755SYong Zhao #define KFD_MMAP_GPU_ID_SHIFT 46 71df03ef93SHarish Kasiviswanathan #define KFD_MMAP_GPU_ID_MASK (((1ULL << KFD_GPU_ID_HASH_WIDTH) - 1) \ 72df03ef93SHarish Kasiviswanathan << KFD_MMAP_GPU_ID_SHIFT) 73df03ef93SHarish Kasiviswanathan #define KFD_MMAP_GPU_ID(gpu_id) ((((uint64_t)gpu_id) << KFD_MMAP_GPU_ID_SHIFT)\ 74df03ef93SHarish Kasiviswanathan & KFD_MMAP_GPU_ID_MASK) 7529453755SYong Zhao #define KFD_MMAP_GET_GPU_ID(offset) ((offset & KFD_MMAP_GPU_ID_MASK) \ 76df03ef93SHarish Kasiviswanathan >> KFD_MMAP_GPU_ID_SHIFT) 77df03ef93SHarish Kasiviswanathan 78ed6e6a34SBen Goz /* 79ed6e6a34SBen Goz * When working with cp scheduler we should assign the HIQ manually or via 80e7016d8eSYong Zhao * the amdgpu driver to a fixed hqd slot, here are the fixed HIQ hqd slot 81ed6e6a34SBen Goz * definitions for Kaveri. In Kaveri only the first ME queues participates 82ed6e6a34SBen Goz * in the cp scheduling taking that in mind we set the HIQ slot in the 83ed6e6a34SBen Goz * second ME. 84ed6e6a34SBen Goz */ 85ed6e6a34SBen Goz #define KFD_CIK_HIQ_PIPE 4 86ed6e6a34SBen Goz #define KFD_CIK_HIQ_QUEUE 0 87ed6e6a34SBen Goz 885b5c4e40SEvgeny Pinchuk /* Macro for allocating structures */ 895b5c4e40SEvgeny Pinchuk #define kfd_alloc_struct(ptr_to_struct) \ 905b5c4e40SEvgeny Pinchuk ((typeof(ptr_to_struct)) kzalloc(sizeof(*ptr_to_struct), GFP_KERNEL)) 915b5c4e40SEvgeny Pinchuk 9219f6d2a6SOded Gabbay #define KFD_MAX_NUM_OF_PROCESSES 512 93b8cbab04SOded Gabbay #define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS 1024 9419f6d2a6SOded Gabbay 9519f6d2a6SOded Gabbay /* 96373d7080SFelix Kuehling * Size of the per-process TBA+TMA buffer: 2 pages 97373d7080SFelix Kuehling * 98373d7080SFelix Kuehling * The first page is the TBA used for the CWSR ISA code. The second 99373d7080SFelix Kuehling * page is used as TMA for daisy changing a user-mode trap handler. 100373d7080SFelix Kuehling */ 101373d7080SFelix Kuehling #define KFD_CWSR_TBA_TMA_SIZE (PAGE_SIZE * 2) 102373d7080SFelix Kuehling #define KFD_CWSR_TMA_OFFSET PAGE_SIZE 103373d7080SFelix Kuehling 10474523943SYong Zhao #define KFD_MAX_NUM_OF_QUEUES_PER_DEVICE \ 10574523943SYong Zhao (KFD_MAX_NUM_OF_PROCESSES * \ 10674523943SYong Zhao KFD_MAX_NUM_OF_QUEUES_PER_PROCESS) 10774523943SYong Zhao 10874523943SYong Zhao #define KFD_KERNEL_QUEUE_SIZE 2048 10974523943SYong Zhao 11014328aa5SPhilip Cox #define KFD_UNMAP_LATENCY_MS (4000) 11114328aa5SPhilip Cox 112373d7080SFelix Kuehling /* 1131f86805aSYong Zhao * 512 = 0x200 1141f86805aSYong Zhao * The doorbell index distance between SDMA RLC (2*i) and (2*i+1) in the 1151f86805aSYong Zhao * same SDMA engine on SOC15, which has 8-byte doorbells for SDMA. 1161f86805aSYong Zhao * 512 8-byte doorbell distance (i.e. one page away) ensures that SDMA RLC 1171f86805aSYong Zhao * (2*i+1) doorbells (in terms of the lower 12 bit address) lie exactly in 1181f86805aSYong Zhao * the OFFSET and SIZE set in registers like BIF_SDMA0_DOORBELL_RANGE. 1191f86805aSYong Zhao */ 1201f86805aSYong Zhao #define KFD_QUEUE_DOORBELL_MIRROR_OFFSET 512 1211f86805aSYong Zhao 1221f86805aSYong Zhao 1231f86805aSYong Zhao /* 124b8cbab04SOded Gabbay * Kernel module parameter to specify maximum number of supported queues per 125b8cbab04SOded Gabbay * device 12619f6d2a6SOded Gabbay */ 127b8cbab04SOded Gabbay extern int max_num_of_queues_per_device; 12819f6d2a6SOded Gabbay 129ed6e6a34SBen Goz 13031c21fecSBen Goz /* Kernel module parameter to specify the scheduling policy */ 13131c21fecSBen Goz extern int sched_policy; 13231c21fecSBen Goz 133a99c6d4fSFelix Kuehling /* 134a99c6d4fSFelix Kuehling * Kernel module parameter to specify the maximum process 135a99c6d4fSFelix Kuehling * number per HW scheduler 136a99c6d4fSFelix Kuehling */ 137a99c6d4fSFelix Kuehling extern int hws_max_conc_proc; 138a99c6d4fSFelix Kuehling 139373d7080SFelix Kuehling extern int cwsr_enable; 140373d7080SFelix Kuehling 14181663016SOded Gabbay /* 14281663016SOded Gabbay * Kernel module parameter to specify whether to send sigterm to HSA process on 14381663016SOded Gabbay * unhandled exception 14481663016SOded Gabbay */ 14581663016SOded Gabbay extern int send_sigterm; 14681663016SOded Gabbay 147ebcfd1e2SFelix Kuehling /* 148374200b1SFelix Kuehling * This kernel module is used to simulate large bar machine on non-large bar 149374200b1SFelix Kuehling * enabled machines. 150374200b1SFelix Kuehling */ 151374200b1SFelix Kuehling extern int debug_largebar; 152374200b1SFelix Kuehling 153374200b1SFelix Kuehling /* 154ebcfd1e2SFelix Kuehling * Ignore CRAT table during KFD initialization, can be used to work around 155ebcfd1e2SFelix Kuehling * broken CRAT tables on some AMD systems 156ebcfd1e2SFelix Kuehling */ 157ebcfd1e2SFelix Kuehling extern int ignore_crat; 158ebcfd1e2SFelix Kuehling 159bed4f110SFelix Kuehling /* 160bed4f110SFelix Kuehling * Set sh_mem_config.retry_disable on Vega10 161bed4f110SFelix Kuehling */ 16275ee6487SFelix Kuehling extern int amdgpu_noretry; 163bed4f110SFelix Kuehling 1640e9a860cSYong Zhao /* 1650e9a860cSYong Zhao * Halt if HWS hang is detected 1660e9a860cSYong Zhao */ 1670e9a860cSYong Zhao extern int halt_if_hws_hang; 1680e9a860cSYong Zhao 16929e76462SOak Zeng /* 17029e76462SOak Zeng * Whether MEC FW support GWS barriers 17129e76462SOak Zeng */ 17229e76462SOak Zeng extern bool hws_gws_support; 17329e76462SOak Zeng 17414328aa5SPhilip Cox /* 17514328aa5SPhilip Cox * Queue preemption timeout in ms 17614328aa5SPhilip Cox */ 17714328aa5SPhilip Cox extern int queue_preemption_timeout_ms; 17814328aa5SPhilip Cox 179ed6e6a34SBen Goz enum cache_policy { 180ed6e6a34SBen Goz cache_policy_coherent, 181ed6e6a34SBen Goz cache_policy_noncoherent 182ed6e6a34SBen Goz }; 183ed6e6a34SBen Goz 184ef568db7SFelix Kuehling #define KFD_IS_SOC15(chip) ((chip) >= CHIP_VEGA10) 185ef568db7SFelix Kuehling 186f3a39818SAndrew Lewycky struct kfd_event_interrupt_class { 187f3a39818SAndrew Lewycky bool (*interrupt_isr)(struct kfd_dev *dev, 18858e69886SLan Xiao const uint32_t *ih_ring_entry, uint32_t *patched_ihre, 18958e69886SLan Xiao bool *patched_flag); 190f3a39818SAndrew Lewycky void (*interrupt_wq)(struct kfd_dev *dev, 191f3a39818SAndrew Lewycky const uint32_t *ih_ring_entry); 192f3a39818SAndrew Lewycky }; 193f3a39818SAndrew Lewycky 1944a488a7aSOded Gabbay struct kfd_device_info { 195e596b903SYong Zhao enum amd_asic_type asic_family; 196c181159aSYong Zhao const char *asic_name; 197f3a39818SAndrew Lewycky const struct kfd_event_interrupt_class *event_interrupt_class; 1984a488a7aSOded Gabbay unsigned int max_pasid_bits; 199992839adSYair Shachar unsigned int max_no_of_hqd; 200ada2b29cSFelix Kuehling unsigned int doorbell_size; 2014a488a7aSOded Gabbay size_t ih_ring_entry_size; 202f7c826adSAlexey Skidanov uint8_t num_of_watch_points; 20319f6d2a6SOded Gabbay uint16_t mqd_size_aligned; 204373d7080SFelix Kuehling bool supports_cwsr; 20564d1c3a4SFelix Kuehling bool needs_iommu_device; 2063ee2d00cSFelix Kuehling bool needs_pci_atomics; 20798bb9222SYong Zhao unsigned int num_sdma_engines; 2081b4670f6SOak Zeng unsigned int num_xgmi_sdma_engines; 209d5094189SShaoyun Liu unsigned int num_sdma_queues_per_engine; 2104a488a7aSOded Gabbay }; 2114a488a7aSOded Gabbay 21236b5c08fSOded Gabbay struct kfd_mem_obj { 21336b5c08fSOded Gabbay uint32_t range_start; 21436b5c08fSOded Gabbay uint32_t range_end; 21536b5c08fSOded Gabbay uint64_t gpu_addr; 21636b5c08fSOded Gabbay uint32_t *cpu_ptr; 217b91d43ddSFelix Kuehling void *gtt_mem; 21836b5c08fSOded Gabbay }; 21936b5c08fSOded Gabbay 22044008d7aSYong Zhao struct kfd_vmid_info { 22144008d7aSYong Zhao uint32_t first_vmid_kfd; 22244008d7aSYong Zhao uint32_t last_vmid_kfd; 22344008d7aSYong Zhao uint32_t vmid_num_kfd; 22444008d7aSYong Zhao }; 22544008d7aSYong Zhao 2264a488a7aSOded Gabbay struct kfd_dev { 2274a488a7aSOded Gabbay struct kgd_dev *kgd; 2284a488a7aSOded Gabbay 2294a488a7aSOded Gabbay const struct kfd_device_info *device_info; 2304a488a7aSOded Gabbay struct pci_dev *pdev; 2313a0c3423SHarish Kasiviswanathan struct drm_device *ddev; 2324a488a7aSOded Gabbay 2334a488a7aSOded Gabbay unsigned int id; /* topology stub index */ 2344a488a7aSOded Gabbay 23519f6d2a6SOded Gabbay phys_addr_t doorbell_base; /* Start of actual doorbells used by 23619f6d2a6SOded Gabbay * KFD. It is aligned for mapping 23719f6d2a6SOded Gabbay * into user mode 23819f6d2a6SOded Gabbay */ 239339903faSYong Zhao size_t doorbell_base_dw_offset; /* Offset from the start of the PCI 240339903faSYong Zhao * doorbell BAR to the first KFD 241339903faSYong Zhao * doorbell in dwords. GFX reserves 242339903faSYong Zhao * the segment before this offset. 24319f6d2a6SOded Gabbay */ 24419f6d2a6SOded Gabbay u32 __iomem *doorbell_kernel_ptr; /* This is a pointer for a doorbells 24519f6d2a6SOded Gabbay * page used by kernel queue 24619f6d2a6SOded Gabbay */ 24719f6d2a6SOded Gabbay 2484a488a7aSOded Gabbay struct kgd2kfd_shared_resources shared_resources; 24944008d7aSYong Zhao struct kfd_vmid_info vm_info; 2504a488a7aSOded Gabbay 251cea405b1SXihan Zhang const struct kfd2kgd_calls *kfd2kgd; 252cea405b1SXihan Zhang struct mutex doorbell_mutex; 253f761d8bdSJoe Perches DECLARE_BITMAP(doorbell_available_index, 254f761d8bdSJoe Perches KFD_MAX_NUM_OF_QUEUES_PER_PROCESS); 255cea405b1SXihan Zhang 25636b5c08fSOded Gabbay void *gtt_mem; 25736b5c08fSOded Gabbay uint64_t gtt_start_gpu_addr; 25836b5c08fSOded Gabbay void *gtt_start_cpu_ptr; 25936b5c08fSOded Gabbay void *gtt_sa_bitmap; 26036b5c08fSOded Gabbay struct mutex gtt_sa_lock; 26136b5c08fSOded Gabbay unsigned int gtt_sa_chunk_size; 26236b5c08fSOded Gabbay unsigned int gtt_sa_num_of_chunks; 26336b5c08fSOded Gabbay 2642249d558SAndrew Lewycky /* Interrupts */ 26504ad47bdSAndres Rodriguez struct kfifo ih_fifo; 26648e876a2SAndres Rodriguez struct workqueue_struct *ih_wq; 2672249d558SAndrew Lewycky struct work_struct interrupt_work; 2682249d558SAndrew Lewycky spinlock_t interrupt_lock; 2692249d558SAndrew Lewycky 270ed6e6a34SBen Goz /* QCM Device instance */ 271ed6e6a34SBen Goz struct device_queue_manager *dqm; 2724a488a7aSOded Gabbay 273ed6e6a34SBen Goz bool init_complete; 2742249d558SAndrew Lewycky /* 2752249d558SAndrew Lewycky * Interrupts of interest to KFD are copied 2762249d558SAndrew Lewycky * from the HW ring into a SW ring. 2772249d558SAndrew Lewycky */ 2782249d558SAndrew Lewycky bool interrupts_active; 279fbeb661bSYair Shachar 280fbeb661bSYair Shachar /* Debug manager */ 281fbeb661bSYair Shachar struct kfd_dbgmgr *dbgmgr; 282373d7080SFelix Kuehling 2835ade6c9cSFelix Kuehling /* Firmware versions */ 2845ade6c9cSFelix Kuehling uint16_t mec_fw_version; 28529633d0eSJoseph Greathouse uint16_t mec2_fw_version; 2865ade6c9cSFelix Kuehling uint16_t sdma_fw_version; 2875ade6c9cSFelix Kuehling 288a99c6d4fSFelix Kuehling /* Maximum process number mapped to HW scheduler */ 289a99c6d4fSFelix Kuehling unsigned int max_proc_per_quantum; 290a99c6d4fSFelix Kuehling 291373d7080SFelix Kuehling /* CWSR */ 292373d7080SFelix Kuehling bool cwsr_enabled; 293373d7080SFelix Kuehling const void *cwsr_isa; 294373d7080SFelix Kuehling unsigned int cwsr_isa_size; 2950c1690e3SShaoyun Liu 2960c1690e3SShaoyun Liu /* xGMI */ 2970c1690e3SShaoyun Liu uint64_t hive_id; 2980c663695SDivya Shikre 2990c663695SDivya Shikre /* UUID */ 3000c663695SDivya Shikre uint64_t unique_id; 301d35f00d8SEric Huang 302d35f00d8SEric Huang bool pci_atomic_requested; 3039b54d201SEric Huang 3049b54d201SEric Huang /* SRAM ECC flag */ 3059b54d201SEric Huang atomic_t sram_ecc_flag; 306f756e631SHarish Kasiviswanathan 307f756e631SHarish Kasiviswanathan /* Compute Profile ref. count */ 308f756e631SHarish Kasiviswanathan atomic_t compute_profile; 309e09d4fc8SOak Zeng 310e09d4fc8SOak Zeng /* Global GWS resource shared b/t processes*/ 311e09d4fc8SOak Zeng void *gws; 3124a488a7aSOded Gabbay }; 3134a488a7aSOded Gabbay 31419f6d2a6SOded Gabbay enum kfd_mempool { 31519f6d2a6SOded Gabbay KFD_MEMPOOL_SYSTEM_CACHEABLE = 1, 31619f6d2a6SOded Gabbay KFD_MEMPOOL_SYSTEM_WRITECOMBINE = 2, 31719f6d2a6SOded Gabbay KFD_MEMPOOL_FRAMEBUFFER = 3, 31819f6d2a6SOded Gabbay }; 31919f6d2a6SOded Gabbay 3204a488a7aSOded Gabbay /* Character device interface */ 3214a488a7aSOded Gabbay int kfd_chardev_init(void); 3224a488a7aSOded Gabbay void kfd_chardev_exit(void); 3234a488a7aSOded Gabbay struct device *kfd_chardev(void); 3244a488a7aSOded Gabbay 325241f24f8SBen Goz /** 3267da2bcf8SYong Zhao * enum kfd_unmap_queues_filter 327241f24f8SBen Goz * 3287da2bcf8SYong Zhao * @KFD_UNMAP_QUEUES_FILTER_SINGLE_QUEUE: Preempts single queue. 329241f24f8SBen Goz * 3307da2bcf8SYong Zhao * @KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES: Preempts all queues in the 331241f24f8SBen Goz * running queues list. 332241f24f8SBen Goz * 3337da2bcf8SYong Zhao * @KFD_UNMAP_QUEUES_FILTER_BY_PASID: Preempts queues that belongs to 334241f24f8SBen Goz * specific process. 335241f24f8SBen Goz * 336241f24f8SBen Goz */ 3377da2bcf8SYong Zhao enum kfd_unmap_queues_filter { 3387da2bcf8SYong Zhao KFD_UNMAP_QUEUES_FILTER_SINGLE_QUEUE, 3397da2bcf8SYong Zhao KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES, 3407da2bcf8SYong Zhao KFD_UNMAP_QUEUES_FILTER_DYNAMIC_QUEUES, 3417da2bcf8SYong Zhao KFD_UNMAP_QUEUES_FILTER_BY_PASID 342241f24f8SBen Goz }; 34319f6d2a6SOded Gabbay 344ed8aab45SBen Goz /** 345ed8aab45SBen Goz * enum kfd_queue_type 346ed8aab45SBen Goz * 347ed8aab45SBen Goz * @KFD_QUEUE_TYPE_COMPUTE: Regular user mode queue type. 348ed8aab45SBen Goz * 349ed8aab45SBen Goz * @KFD_QUEUE_TYPE_SDMA: Sdma user mode queue type. 350ed8aab45SBen Goz * 351ed8aab45SBen Goz * @KFD_QUEUE_TYPE_HIQ: HIQ queue type. 352ed8aab45SBen Goz * 353ed8aab45SBen Goz * @KFD_QUEUE_TYPE_DIQ: DIQ queue type. 354ed8aab45SBen Goz */ 355ed8aab45SBen Goz enum kfd_queue_type { 356ed8aab45SBen Goz KFD_QUEUE_TYPE_COMPUTE, 357ed8aab45SBen Goz KFD_QUEUE_TYPE_SDMA, 358ed8aab45SBen Goz KFD_QUEUE_TYPE_HIQ, 3591b4670f6SOak Zeng KFD_QUEUE_TYPE_DIQ, 3601b4670f6SOak Zeng KFD_QUEUE_TYPE_SDMA_XGMI 361ed8aab45SBen Goz }; 362ed8aab45SBen Goz 3636e99df57SBen Goz enum kfd_queue_format { 3646e99df57SBen Goz KFD_QUEUE_FORMAT_PM4, 3656e99df57SBen Goz KFD_QUEUE_FORMAT_AQL 3666e99df57SBen Goz }; 3676e99df57SBen Goz 3680ccbc7cdSOak Zeng enum KFD_QUEUE_PRIORITY { 3690ccbc7cdSOak Zeng KFD_QUEUE_PRIORITY_MINIMUM = 0, 3700ccbc7cdSOak Zeng KFD_QUEUE_PRIORITY_MAXIMUM = 15 3710ccbc7cdSOak Zeng }; 3720ccbc7cdSOak Zeng 373ed8aab45SBen Goz /** 374ed8aab45SBen Goz * struct queue_properties 375ed8aab45SBen Goz * 376ed8aab45SBen Goz * @type: The queue type. 377ed8aab45SBen Goz * 378ed8aab45SBen Goz * @queue_id: Queue identifier. 379ed8aab45SBen Goz * 380ed8aab45SBen Goz * @queue_address: Queue ring buffer address. 381ed8aab45SBen Goz * 382ed8aab45SBen Goz * @queue_size: Queue ring buffer size. 383ed8aab45SBen Goz * 384ed8aab45SBen Goz * @priority: Defines the queue priority relative to other queues in the 385ed8aab45SBen Goz * process. 386ed8aab45SBen Goz * This is just an indication and HW scheduling may override the priority as 387ed8aab45SBen Goz * necessary while keeping the relative prioritization. 388ed8aab45SBen Goz * the priority granularity is from 0 to f which f is the highest priority. 389ed8aab45SBen Goz * currently all queues are initialized with the highest priority. 390ed8aab45SBen Goz * 391ed8aab45SBen Goz * @queue_percent: This field is partially implemented and currently a zero in 392ed8aab45SBen Goz * this field defines that the queue is non active. 393ed8aab45SBen Goz * 394ed8aab45SBen Goz * @read_ptr: User space address which points to the number of dwords the 395ed8aab45SBen Goz * cp read from the ring buffer. This field updates automatically by the H/W. 396ed8aab45SBen Goz * 397ed8aab45SBen Goz * @write_ptr: Defines the number of dwords written to the ring buffer. 398ed8aab45SBen Goz * 399ed8aab45SBen Goz * @doorbell_ptr: This field aim is to notify the H/W of new packet written to 4008eabaf54SKent Russell * the queue ring buffer. This field should be similar to write_ptr and the 4018eabaf54SKent Russell * user should update this field after he updated the write_ptr. 402ed8aab45SBen Goz * 403ed8aab45SBen Goz * @doorbell_off: The doorbell offset in the doorbell pci-bar. 404ed8aab45SBen Goz * 4058eabaf54SKent Russell * @is_interop: Defines if this is a interop queue. Interop queue means that 4068eabaf54SKent Russell * the queue can access both graphics and compute resources. 407ed8aab45SBen Goz * 40826103436SFelix Kuehling * @is_evicted: Defines if the queue is evicted. Only active queues 40926103436SFelix Kuehling * are evicted, rendering them inactive. 41026103436SFelix Kuehling * 41126103436SFelix Kuehling * @is_active: Defines if the queue is active or not. @is_active and 41226103436SFelix Kuehling * @is_evicted are protected by the DQM lock. 413ed8aab45SBen Goz * 414b8020b03SJoseph Greathouse * @is_gws: Defines if the queue has been updated to be GWS-capable or not. 415b8020b03SJoseph Greathouse * @is_gws should be protected by the DQM lock, since changing it can yield the 416b8020b03SJoseph Greathouse * possibility of updating DQM state on number of GWS queues. 417b8020b03SJoseph Greathouse * 418ed8aab45SBen Goz * @vmid: If the scheduling mode is no cp scheduling the field defines the vmid 419ed8aab45SBen Goz * of the queue. 420ed8aab45SBen Goz * 421ed8aab45SBen Goz * This structure represents the queue properties for each queue no matter if 422ed8aab45SBen Goz * it's user mode or kernel mode queue. 423ed8aab45SBen Goz * 424ed8aab45SBen Goz */ 425ed8aab45SBen Goz struct queue_properties { 426ed8aab45SBen Goz enum kfd_queue_type type; 4276e99df57SBen Goz enum kfd_queue_format format; 428ed8aab45SBen Goz unsigned int queue_id; 429ed8aab45SBen Goz uint64_t queue_address; 430ed8aab45SBen Goz uint64_t queue_size; 431ed8aab45SBen Goz uint32_t priority; 432ed8aab45SBen Goz uint32_t queue_percent; 433ed8aab45SBen Goz uint32_t *read_ptr; 434ed8aab45SBen Goz uint32_t *write_ptr; 435ada2b29cSFelix Kuehling void __iomem *doorbell_ptr; 436ed8aab45SBen Goz uint32_t doorbell_off; 437ed8aab45SBen Goz bool is_interop; 43826103436SFelix Kuehling bool is_evicted; 439ed8aab45SBen Goz bool is_active; 440b8020b03SJoseph Greathouse bool is_gws; 441ed8aab45SBen Goz /* Not relevant for user mode queues in cp scheduling */ 442ed8aab45SBen Goz unsigned int vmid; 44377669eb8SBen Goz /* Relevant only for sdma queues*/ 44477669eb8SBen Goz uint32_t sdma_engine_id; 44577669eb8SBen Goz uint32_t sdma_queue_id; 44677669eb8SBen Goz uint32_t sdma_vm_addr; 447ff3d04a1SBen Goz /* Relevant only for VI */ 448ff3d04a1SBen Goz uint64_t eop_ring_buffer_address; 449ff3d04a1SBen Goz uint32_t eop_ring_buffer_size; 450ff3d04a1SBen Goz uint64_t ctx_save_restore_area_address; 451ff3d04a1SBen Goz uint32_t ctx_save_restore_area_size; 452373d7080SFelix Kuehling uint32_t ctl_stack_size; 453373d7080SFelix Kuehling uint64_t tba_addr; 454373d7080SFelix Kuehling uint64_t tma_addr; 45539e7f331SFelix Kuehling /* Relevant for CU */ 45639e7f331SFelix Kuehling uint32_t cu_mask_count; /* Must be a multiple of 32 */ 45739e7f331SFelix Kuehling uint32_t *cu_mask; 458ed8aab45SBen Goz }; 459ed8aab45SBen Goz 460bb2d2128SFelix Kuehling #define QUEUE_IS_ACTIVE(q) ((q).queue_size > 0 && \ 461bb2d2128SFelix Kuehling (q).queue_address != 0 && \ 462bb2d2128SFelix Kuehling (q).queue_percent > 0 && \ 463bb2d2128SFelix Kuehling !(q).is_evicted) 464bb2d2128SFelix Kuehling 465ed8aab45SBen Goz /** 466ed8aab45SBen Goz * struct queue 467ed8aab45SBen Goz * 468ed8aab45SBen Goz * @list: Queue linked list. 469ed8aab45SBen Goz * 470ed8aab45SBen Goz * @mqd: The queue MQD. 471ed8aab45SBen Goz * 472ed8aab45SBen Goz * @mqd_mem_obj: The MQD local gpu memory object. 473ed8aab45SBen Goz * 474ed8aab45SBen Goz * @gart_mqd_addr: The MQD gart mc address. 475ed8aab45SBen Goz * 476ed8aab45SBen Goz * @properties: The queue properties. 477ed8aab45SBen Goz * 478ed8aab45SBen Goz * @mec: Used only in no cp scheduling mode and identifies to micro engine id 479ed8aab45SBen Goz * that the queue should be execute on. 480ed8aab45SBen Goz * 4818eabaf54SKent Russell * @pipe: Used only in no cp scheduling mode and identifies the queue's pipe 4828eabaf54SKent Russell * id. 483ed8aab45SBen Goz * 484ed8aab45SBen Goz * @queue: Used only in no cp scheduliong mode and identifies the queue's slot. 485ed8aab45SBen Goz * 486ed8aab45SBen Goz * @process: The kfd process that created this queue. 487ed8aab45SBen Goz * 488ed8aab45SBen Goz * @device: The kfd device that created this queue. 489ed8aab45SBen Goz * 490eb82da1dSOak Zeng * @gws: Pointing to gws kgd_mem if this is a gws control queue; NULL 491eb82da1dSOak Zeng * otherwise. 492eb82da1dSOak Zeng * 493ed8aab45SBen Goz * This structure represents user mode compute queues. 494ed8aab45SBen Goz * It contains all the necessary data to handle such queues. 495ed8aab45SBen Goz * 496ed8aab45SBen Goz */ 497ed8aab45SBen Goz 498ed8aab45SBen Goz struct queue { 499ed8aab45SBen Goz struct list_head list; 500ed8aab45SBen Goz void *mqd; 501ed8aab45SBen Goz struct kfd_mem_obj *mqd_mem_obj; 502ed8aab45SBen Goz uint64_t gart_mqd_addr; 503ed8aab45SBen Goz struct queue_properties properties; 504ed8aab45SBen Goz 505ed8aab45SBen Goz uint32_t mec; 506ed8aab45SBen Goz uint32_t pipe; 507ed8aab45SBen Goz uint32_t queue; 508ed8aab45SBen Goz 50977669eb8SBen Goz unsigned int sdma_id; 510ef568db7SFelix Kuehling unsigned int doorbell_id; 51177669eb8SBen Goz 512ed8aab45SBen Goz struct kfd_process *process; 513ed8aab45SBen Goz struct kfd_dev *device; 514eb82da1dSOak Zeng void *gws; 5156d220a7eSAmber Lin 5166d220a7eSAmber Lin /* procfs */ 5176d220a7eSAmber Lin struct kobject kobj; 518ed8aab45SBen Goz }; 519ed8aab45SBen Goz 5206e99df57SBen Goz /* 5216e99df57SBen Goz * Please read the kfd_mqd_manager.h description. 5226e99df57SBen Goz */ 5236e99df57SBen Goz enum KFD_MQD_TYPE { 524d7c0b047SYong Zhao KFD_MQD_TYPE_HIQ = 0, /* for hiq */ 52585d258f9SBen Goz KFD_MQD_TYPE_CP, /* for cp queues and diq */ 52685d258f9SBen Goz KFD_MQD_TYPE_SDMA, /* for sdma queues */ 52759f650a0SOak Zeng KFD_MQD_TYPE_DIQ, /* for diq */ 5286e99df57SBen Goz KFD_MQD_TYPE_MAX 5296e99df57SBen Goz }; 5306e99df57SBen Goz 5310ccbc7cdSOak Zeng enum KFD_PIPE_PRIORITY { 5320ccbc7cdSOak Zeng KFD_PIPE_PRIORITY_CS_LOW = 0, 5330ccbc7cdSOak Zeng KFD_PIPE_PRIORITY_CS_MEDIUM, 5340ccbc7cdSOak Zeng KFD_PIPE_PRIORITY_CS_HIGH 5350ccbc7cdSOak Zeng }; 5360ccbc7cdSOak Zeng 537241f24f8SBen Goz struct scheduling_resources { 538241f24f8SBen Goz unsigned int vmid_mask; 539241f24f8SBen Goz enum kfd_queue_type type; 540241f24f8SBen Goz uint64_t queue_mask; 541241f24f8SBen Goz uint64_t gws_mask; 542241f24f8SBen Goz uint32_t oac_mask; 543241f24f8SBen Goz uint32_t gds_heap_base; 544241f24f8SBen Goz uint32_t gds_heap_size; 545241f24f8SBen Goz }; 546241f24f8SBen Goz 547241f24f8SBen Goz struct process_queue_manager { 548241f24f8SBen Goz /* data */ 549241f24f8SBen Goz struct kfd_process *process; 550241f24f8SBen Goz struct list_head queues; 551241f24f8SBen Goz unsigned long *queue_slot_bitmap; 552241f24f8SBen Goz }; 553241f24f8SBen Goz 554241f24f8SBen Goz struct qcm_process_device { 555241f24f8SBen Goz /* The Device Queue Manager that owns this data */ 556241f24f8SBen Goz struct device_queue_manager *dqm; 557241f24f8SBen Goz struct process_queue_manager *pqm; 558241f24f8SBen Goz /* Queues list */ 559241f24f8SBen Goz struct list_head queues_list; 560241f24f8SBen Goz struct list_head priv_queue_list; 561241f24f8SBen Goz 562241f24f8SBen Goz unsigned int queue_count; 563241f24f8SBen Goz unsigned int vmid; 564241f24f8SBen Goz bool is_debug; 56526103436SFelix Kuehling unsigned int evicted; /* eviction counter, 0=active */ 5669fd3f1bfSFelix Kuehling 5679fd3f1bfSFelix Kuehling /* This flag tells if we should reset all wavefronts on 5689fd3f1bfSFelix Kuehling * process termination 5699fd3f1bfSFelix Kuehling */ 5709fd3f1bfSFelix Kuehling bool reset_wavefronts; 5719fd3f1bfSFelix Kuehling 572b8020b03SJoseph Greathouse /* This flag tells us if this process has a GWS-capable 573b8020b03SJoseph Greathouse * queue that will be mapped into the runlist. It's 574b8020b03SJoseph Greathouse * possible to request a GWS BO, but not have the queue 575b8020b03SJoseph Greathouse * currently mapped, and this changes how the MAP_PROCESS 576b8020b03SJoseph Greathouse * PM4 packet is configured. 577b8020b03SJoseph Greathouse */ 578b8020b03SJoseph Greathouse bool mapped_gws_queue; 579b8020b03SJoseph Greathouse 580241f24f8SBen Goz /* 581241f24f8SBen Goz * All the memory management data should be here too 582241f24f8SBen Goz */ 583241f24f8SBen Goz uint64_t gds_context_area; 584435e2f97SYong Zhao /* Contains page table flags such as AMDGPU_PTE_VALID since gfx9 */ 585e715c6d0SShaoyun Liu uint64_t page_table_base; 586241f24f8SBen Goz uint32_t sh_mem_config; 587241f24f8SBen Goz uint32_t sh_mem_bases; 588241f24f8SBen Goz uint32_t sh_mem_ape1_base; 589241f24f8SBen Goz uint32_t sh_mem_ape1_limit; 590241f24f8SBen Goz uint32_t gds_size; 591241f24f8SBen Goz uint32_t num_gws; 592241f24f8SBen Goz uint32_t num_oac; 5936a1c9510SMoses Reuben uint32_t sh_hidden_private_base; 594373d7080SFelix Kuehling 595373d7080SFelix Kuehling /* CWSR memory */ 596373d7080SFelix Kuehling void *cwsr_kaddr; 597d01994c2SFelix Kuehling uint64_t cwsr_base; 598373d7080SFelix Kuehling uint64_t tba_addr; 599373d7080SFelix Kuehling uint64_t tma_addr; 600d01994c2SFelix Kuehling 601d01994c2SFelix Kuehling /* IB memory */ 602d01994c2SFelix Kuehling uint64_t ib_base; 603552764b6SFelix Kuehling void *ib_kaddr; 604ef568db7SFelix Kuehling 605ef568db7SFelix Kuehling /* doorbell resources per process per device */ 606ef568db7SFelix Kuehling unsigned long *doorbell_bitmap; 607241f24f8SBen Goz }; 608241f24f8SBen Goz 60926103436SFelix Kuehling /* KFD Memory Eviction */ 61026103436SFelix Kuehling 61126103436SFelix Kuehling /* Approx. wait time before attempting to restore evicted BOs */ 61226103436SFelix Kuehling #define PROCESS_RESTORE_TIME_MS 100 61326103436SFelix Kuehling /* Approx. back off time if restore fails due to lack of memory */ 61426103436SFelix Kuehling #define PROCESS_BACK_OFF_TIME_MS 100 61526103436SFelix Kuehling /* Approx. time before evicting the process again */ 61626103436SFelix Kuehling #define PROCESS_ACTIVE_TIME_MS 10 61726103436SFelix Kuehling 6185ec7e028SFelix Kuehling /* 8 byte handle containing GPU ID in the most significant 4 bytes and 6195ec7e028SFelix Kuehling * idr_handle in the least significant 4 bytes 6205ec7e028SFelix Kuehling */ 6215ec7e028SFelix Kuehling #define MAKE_HANDLE(gpu_id, idr_handle) \ 6225ec7e028SFelix Kuehling (((uint64_t)(gpu_id) << 32) + idr_handle) 6235ec7e028SFelix Kuehling #define GET_GPU_ID(handle) (handle >> 32) 6245ec7e028SFelix Kuehling #define GET_IDR_HANDLE(handle) (handle & 0xFFFFFFFF) 6255ec7e028SFelix Kuehling 626733fa1f7SYong Zhao enum kfd_pdd_bound { 627733fa1f7SYong Zhao PDD_UNBOUND = 0, 628733fa1f7SYong Zhao PDD_BOUND, 629733fa1f7SYong Zhao PDD_BOUND_SUSPENDED, 630733fa1f7SYong Zhao }; 631733fa1f7SYong Zhao 63219f6d2a6SOded Gabbay /* Data that is per-process-per device. */ 63319f6d2a6SOded Gabbay struct kfd_process_device { 63419f6d2a6SOded Gabbay /* 63519f6d2a6SOded Gabbay * List of all per-device data for a process. 63619f6d2a6SOded Gabbay * Starts from kfd_process.per_device_data. 63719f6d2a6SOded Gabbay */ 63819f6d2a6SOded Gabbay struct list_head per_device_list; 63919f6d2a6SOded Gabbay 64019f6d2a6SOded Gabbay /* The device that owns this data. */ 64119f6d2a6SOded Gabbay struct kfd_dev *dev; 64219f6d2a6SOded Gabbay 6439fd3f1bfSFelix Kuehling /* The process that owns this kfd_process_device. */ 6449fd3f1bfSFelix Kuehling struct kfd_process *process; 64519f6d2a6SOded Gabbay 64645102048SBen Goz /* per-process-per device QCM data structure */ 64745102048SBen Goz struct qcm_process_device qpd; 64845102048SBen Goz 64919f6d2a6SOded Gabbay /*Apertures*/ 65019f6d2a6SOded Gabbay uint64_t lds_base; 65119f6d2a6SOded Gabbay uint64_t lds_limit; 65219f6d2a6SOded Gabbay uint64_t gpuvm_base; 65319f6d2a6SOded Gabbay uint64_t gpuvm_limit; 65419f6d2a6SOded Gabbay uint64_t scratch_base; 65519f6d2a6SOded Gabbay uint64_t scratch_limit; 65619f6d2a6SOded Gabbay 657403575c4SFelix Kuehling /* VM context for GPUVM allocations */ 658b84394e2SFelix Kuehling struct file *drm_file; 659403575c4SFelix Kuehling void *vm; 660403575c4SFelix Kuehling 66152b29d73SFelix Kuehling /* GPUVM allocations storage */ 66252b29d73SFelix Kuehling struct idr alloc_idr; 66352b29d73SFelix Kuehling 6649fd3f1bfSFelix Kuehling /* Flag used to tell the pdd has dequeued from the dqm. 6659fd3f1bfSFelix Kuehling * This is used to prevent dev->dqm->ops.process_termination() from 6669fd3f1bfSFelix Kuehling * being called twice when it is already called in IOMMU callback 6679fd3f1bfSFelix Kuehling * function. 668a82918f1SBen Goz */ 6699fd3f1bfSFelix Kuehling bool already_dequeued; 6709593f4d6SRajneesh Bhardwaj bool runtime_inuse; 67164d1c3a4SFelix Kuehling 67264d1c3a4SFelix Kuehling /* Is this process/pasid bound to this device? (amd_iommu_bind_pasid) */ 67364d1c3a4SFelix Kuehling enum kfd_pdd_bound bound; 67419f6d2a6SOded Gabbay }; 67519f6d2a6SOded Gabbay 67652a5fdceSAlexey Skidanov #define qpd_to_pdd(x) container_of(x, struct kfd_process_device, qpd) 67752a5fdceSAlexey Skidanov 6784a488a7aSOded Gabbay /* Process data */ 6794a488a7aSOded Gabbay struct kfd_process { 68019f6d2a6SOded Gabbay /* 68119f6d2a6SOded Gabbay * kfd_process are stored in an mm_struct*->kfd_process* 68219f6d2a6SOded Gabbay * hash table (kfd_processes in kfd_process.c) 68319f6d2a6SOded Gabbay */ 68419f6d2a6SOded Gabbay struct hlist_node kfd_processes; 68519f6d2a6SOded Gabbay 6869b56bb11SFelix Kuehling /* 6879b56bb11SFelix Kuehling * Opaque pointer to mm_struct. We don't hold a reference to 6889b56bb11SFelix Kuehling * it so it should never be dereferenced from here. This is 6899b56bb11SFelix Kuehling * only used for looking up processes by their mm. 6909b56bb11SFelix Kuehling */ 6919b56bb11SFelix Kuehling void *mm; 69219f6d2a6SOded Gabbay 6935ce10687SFelix Kuehling struct kref ref; 6945ce10687SFelix Kuehling struct work_struct release_work; 6955ce10687SFelix Kuehling 69619f6d2a6SOded Gabbay struct mutex mutex; 69719f6d2a6SOded Gabbay 69819f6d2a6SOded Gabbay /* 69919f6d2a6SOded Gabbay * In any process, the thread that started main() is the lead 70019f6d2a6SOded Gabbay * thread and outlives the rest. 70119f6d2a6SOded Gabbay * It is here because amd_iommu_bind_pasid wants a task_struct. 702894a8293SFelix Kuehling * It can also be used for safely getting a reference to the 703894a8293SFelix Kuehling * mm_struct of the process. 70419f6d2a6SOded Gabbay */ 70519f6d2a6SOded Gabbay struct task_struct *lead_thread; 70619f6d2a6SOded Gabbay 70719f6d2a6SOded Gabbay /* We want to receive a notification when the mm_struct is destroyed */ 70819f6d2a6SOded Gabbay struct mmu_notifier mmu_notifier; 70919f6d2a6SOded Gabbay 7106027b1bfSYong Zhao uint16_t pasid; 711a91e70e3SFelix Kuehling unsigned int doorbell_index; 71219f6d2a6SOded Gabbay 71319f6d2a6SOded Gabbay /* 71419f6d2a6SOded Gabbay * List of kfd_process_device structures, 71519f6d2a6SOded Gabbay * one for each device the process is using. 71619f6d2a6SOded Gabbay */ 71719f6d2a6SOded Gabbay struct list_head per_device_data; 71819f6d2a6SOded Gabbay 71945102048SBen Goz struct process_queue_manager pqm; 72045102048SBen Goz 72119f6d2a6SOded Gabbay /*Is the user space process 32 bit?*/ 72219f6d2a6SOded Gabbay bool is_32bit_user_mode; 723f3a39818SAndrew Lewycky 724f3a39818SAndrew Lewycky /* Event-related data */ 725f3a39818SAndrew Lewycky struct mutex event_mutex; 726482f0777SFelix Kuehling /* Event ID allocator and lookup */ 727482f0777SFelix Kuehling struct idr event_idr; 72850cb7dd9SFelix Kuehling /* Event page */ 72950cb7dd9SFelix Kuehling struct kfd_signal_page *signal_page; 730b9a5d0a5SFelix Kuehling size_t signal_mapped_size; 731f3a39818SAndrew Lewycky size_t signal_event_count; 732c986169fSFelix Kuehling bool signal_event_limit_reached; 733403575c4SFelix Kuehling 734403575c4SFelix Kuehling /* Information used for memory eviction */ 735403575c4SFelix Kuehling void *kgd_process_info; 736403575c4SFelix Kuehling /* Eviction fence that is attached to all the BOs of this process. The 737403575c4SFelix Kuehling * fence will be triggered during eviction and new one will be created 738403575c4SFelix Kuehling * during restore 739403575c4SFelix Kuehling */ 740403575c4SFelix Kuehling struct dma_fence *ef; 74126103436SFelix Kuehling 74226103436SFelix Kuehling /* Work items for evicting and restoring BOs */ 74326103436SFelix Kuehling struct delayed_work eviction_work; 74426103436SFelix Kuehling struct delayed_work restore_work; 74526103436SFelix Kuehling /* seqno of the last scheduled eviction */ 74626103436SFelix Kuehling unsigned int last_eviction_seqno; 74726103436SFelix Kuehling /* Approx. the last timestamp (in jiffies) when the process was 74826103436SFelix Kuehling * restored after an eviction 74926103436SFelix Kuehling */ 75026103436SFelix Kuehling unsigned long last_restore_timestamp; 751de9f26bbSKent Russell 752de9f26bbSKent Russell /* Kobj for our procfs */ 753de9f26bbSKent Russell struct kobject *kobj; 7546d220a7eSAmber Lin struct kobject *kobj_queues; 755de9f26bbSKent Russell struct attribute attr_pasid; 7564a488a7aSOded Gabbay }; 7574a488a7aSOded Gabbay 75864d1c3a4SFelix Kuehling #define KFD_PROCESS_TABLE_SIZE 5 /* bits: 32 entries */ 75964d1c3a4SFelix Kuehling extern DECLARE_HASHTABLE(kfd_processes_table, KFD_PROCESS_TABLE_SIZE); 76064d1c3a4SFelix Kuehling extern struct srcu_struct kfd_processes_srcu; 76164d1c3a4SFelix Kuehling 76276baee6cSOded Gabbay /** 76376baee6cSOded Gabbay * Ioctl function type. 76476baee6cSOded Gabbay * 76576baee6cSOded Gabbay * \param filep pointer to file structure. 76676baee6cSOded Gabbay * \param p amdkfd process pointer. 76776baee6cSOded Gabbay * \param data pointer to arg that was copied from user. 76876baee6cSOded Gabbay */ 76976baee6cSOded Gabbay typedef int amdkfd_ioctl_t(struct file *filep, struct kfd_process *p, 77076baee6cSOded Gabbay void *data); 77176baee6cSOded Gabbay 77276baee6cSOded Gabbay struct amdkfd_ioctl_desc { 77376baee6cSOded Gabbay unsigned int cmd; 77476baee6cSOded Gabbay int flags; 77576baee6cSOded Gabbay amdkfd_ioctl_t *func; 77676baee6cSOded Gabbay unsigned int cmd_drv; 77776baee6cSOded Gabbay const char *name; 77876baee6cSOded Gabbay }; 77967f7cf9fSshaoyunl bool kfd_dev_is_large_bar(struct kfd_dev *dev); 78076baee6cSOded Gabbay 7811679ae8fSFelix Kuehling int kfd_process_create_wq(void); 78219f6d2a6SOded Gabbay void kfd_process_destroy_wq(void); 783373d7080SFelix Kuehling struct kfd_process *kfd_create_process(struct file *filep); 78419f6d2a6SOded Gabbay struct kfd_process *kfd_get_process(const struct task_struct *); 785f3a39818SAndrew Lewycky struct kfd_process *kfd_lookup_process_by_pasid(unsigned int pasid); 78626103436SFelix Kuehling struct kfd_process *kfd_lookup_process_by_mm(const struct mm_struct *mm); 787abb208a8SFelix Kuehling void kfd_unref_process(struct kfd_process *p); 7886b95e797SFelix Kuehling int kfd_process_evict_queues(struct kfd_process *p); 7896b95e797SFelix Kuehling int kfd_process_restore_queues(struct kfd_process *p); 79026103436SFelix Kuehling void kfd_suspend_all_processes(void); 79126103436SFelix Kuehling int kfd_resume_all_processes(void); 79219f6d2a6SOded Gabbay 793b84394e2SFelix Kuehling int kfd_process_device_init_vm(struct kfd_process_device *pdd, 794b84394e2SFelix Kuehling struct file *drm_file); 79564c7f8cfSBen Goz struct kfd_process_device *kfd_bind_process_to_device(struct kfd_dev *dev, 79664c7f8cfSBen Goz struct kfd_process *p); 79719f6d2a6SOded Gabbay struct kfd_process_device *kfd_get_process_device_data(struct kfd_dev *dev, 798093c7d8cSAlexey Skidanov struct kfd_process *p); 799093c7d8cSAlexey Skidanov struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev, 800093c7d8cSAlexey Skidanov struct kfd_process *p); 80119f6d2a6SOded Gabbay 802df03ef93SHarish Kasiviswanathan int kfd_reserved_mem_mmap(struct kfd_dev *dev, struct kfd_process *process, 803373d7080SFelix Kuehling struct vm_area_struct *vma); 804373d7080SFelix Kuehling 80552b29d73SFelix Kuehling /* KFD process API for creating and translating handles */ 80652b29d73SFelix Kuehling int kfd_process_device_create_obj_handle(struct kfd_process_device *pdd, 80752b29d73SFelix Kuehling void *mem); 80852b29d73SFelix Kuehling void *kfd_process_device_translate_handle(struct kfd_process_device *p, 80952b29d73SFelix Kuehling int handle); 81052b29d73SFelix Kuehling void kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd, 81152b29d73SFelix Kuehling int handle); 81252b29d73SFelix Kuehling 813775921edSAlexey Skidanov /* Process device data iterator */ 8148eabaf54SKent Russell struct kfd_process_device *kfd_get_first_process_device_data( 8158eabaf54SKent Russell struct kfd_process *p); 8168eabaf54SKent Russell struct kfd_process_device *kfd_get_next_process_device_data( 8178eabaf54SKent Russell struct kfd_process *p, 818775921edSAlexey Skidanov struct kfd_process_device *pdd); 819775921edSAlexey Skidanov bool kfd_has_process_device_data(struct kfd_process *p); 820775921edSAlexey Skidanov 82119f6d2a6SOded Gabbay /* PASIDs */ 82219f6d2a6SOded Gabbay int kfd_pasid_init(void); 82319f6d2a6SOded Gabbay void kfd_pasid_exit(void); 82419f6d2a6SOded Gabbay bool kfd_set_pasid_limit(unsigned int new_limit); 82519f6d2a6SOded Gabbay unsigned int kfd_get_pasid_limit(void); 82619f6d2a6SOded Gabbay unsigned int kfd_pasid_alloc(void); 82719f6d2a6SOded Gabbay void kfd_pasid_free(unsigned int pasid); 82819f6d2a6SOded Gabbay 82919f6d2a6SOded Gabbay /* Doorbells */ 830ef568db7SFelix Kuehling size_t kfd_doorbell_process_slice(struct kfd_dev *kfd); 831735df2baSFelix Kuehling int kfd_doorbell_init(struct kfd_dev *kfd); 832735df2baSFelix Kuehling void kfd_doorbell_fini(struct kfd_dev *kfd); 833df03ef93SHarish Kasiviswanathan int kfd_doorbell_mmap(struct kfd_dev *dev, struct kfd_process *process, 834df03ef93SHarish Kasiviswanathan struct vm_area_struct *vma); 835ada2b29cSFelix Kuehling void __iomem *kfd_get_kernel_doorbell(struct kfd_dev *kfd, 83619f6d2a6SOded Gabbay unsigned int *doorbell_off); 83719f6d2a6SOded Gabbay void kfd_release_kernel_doorbell(struct kfd_dev *kfd, u32 __iomem *db_addr); 83819f6d2a6SOded Gabbay u32 read_kernel_doorbell(u32 __iomem *db); 839ada2b29cSFelix Kuehling void write_kernel_doorbell(void __iomem *db, u32 value); 8409d7d0248SFelix Kuehling void write_kernel_doorbell64(void __iomem *db, u64 value); 841339903faSYong Zhao unsigned int kfd_get_doorbell_dw_offset_in_bar(struct kfd_dev *kfd, 84219f6d2a6SOded Gabbay struct kfd_process *process, 843ef568db7SFelix Kuehling unsigned int doorbell_id); 844a91e70e3SFelix Kuehling phys_addr_t kfd_get_process_doorbells(struct kfd_dev *dev, 845a91e70e3SFelix Kuehling struct kfd_process *process); 846a91e70e3SFelix Kuehling int kfd_alloc_process_doorbells(struct kfd_process *process); 847a91e70e3SFelix Kuehling void kfd_free_process_doorbells(struct kfd_process *process); 84819f6d2a6SOded Gabbay 8496e81090bSOded Gabbay /* GTT Sub-Allocator */ 8506e81090bSOded Gabbay 8516e81090bSOded Gabbay int kfd_gtt_sa_allocate(struct kfd_dev *kfd, unsigned int size, 8526e81090bSOded Gabbay struct kfd_mem_obj **mem_obj); 8536e81090bSOded Gabbay 8546e81090bSOded Gabbay int kfd_gtt_sa_free(struct kfd_dev *kfd, struct kfd_mem_obj *mem_obj); 8556e81090bSOded Gabbay 8564a488a7aSOded Gabbay extern struct device *kfd_device; 8574a488a7aSOded Gabbay 858de9f26bbSKent Russell /* KFD's procfs */ 859de9f26bbSKent Russell void kfd_procfs_init(void); 860de9f26bbSKent Russell void kfd_procfs_shutdown(void); 8616d220a7eSAmber Lin int kfd_procfs_add_queue(struct queue *q); 8626d220a7eSAmber Lin void kfd_procfs_del_queue(struct queue *q); 863de9f26bbSKent Russell 8645b5c4e40SEvgeny Pinchuk /* Topology */ 8655b5c4e40SEvgeny Pinchuk int kfd_topology_init(void); 8665b5c4e40SEvgeny Pinchuk void kfd_topology_shutdown(void); 8675b5c4e40SEvgeny Pinchuk int kfd_topology_add_device(struct kfd_dev *gpu); 8685b5c4e40SEvgeny Pinchuk int kfd_topology_remove_device(struct kfd_dev *gpu); 8693a87177eSHarish Kasiviswanathan struct kfd_topology_device *kfd_topology_device_by_proximity_domain( 8703a87177eSHarish Kasiviswanathan uint32_t proximity_domain); 87144d8cc6fSYong Zhao struct kfd_topology_device *kfd_topology_device_by_id(uint32_t gpu_id); 8725b5c4e40SEvgeny Pinchuk struct kfd_dev *kfd_device_by_id(uint32_t gpu_id); 8735b5c4e40SEvgeny Pinchuk struct kfd_dev *kfd_device_by_pci_dev(const struct pci_dev *pdev); 8741dde0ea9SFelix Kuehling struct kfd_dev *kfd_device_by_kgd(const struct kgd_dev *kgd); 8756d82eb0eSHarish Kasiviswanathan int kfd_topology_enum_kfd_devices(uint8_t idx, struct kfd_dev **kdev); 876520b8fb7SFelix Kuehling int kfd_numa_node_to_apic_id(int numa_node_id); 8775b5c4e40SEvgeny Pinchuk 8784a488a7aSOded Gabbay /* Interrupts */ 8792249d558SAndrew Lewycky int kfd_interrupt_init(struct kfd_dev *dev); 8802249d558SAndrew Lewycky void kfd_interrupt_exit(struct kfd_dev *dev); 8812249d558SAndrew Lewycky bool enqueue_ih_ring_entry(struct kfd_dev *kfd, const void *ih_ring_entry); 88258e69886SLan Xiao bool interrupt_is_wanted(struct kfd_dev *dev, 88358e69886SLan Xiao const uint32_t *ih_ring_entry, 88458e69886SLan Xiao uint32_t *patched_ihre, bool *flag); 8854a488a7aSOded Gabbay 88619f6d2a6SOded Gabbay /* amdkfd Apertures */ 88719f6d2a6SOded Gabbay int kfd_init_apertures(struct kfd_process *process); 88819f6d2a6SOded Gabbay 889ed6e6a34SBen Goz /* Queue Context Management */ 890e88a614cSEdward O'Callaghan int init_queue(struct queue **q, const struct queue_properties *properties); 891ed6e6a34SBen Goz void uninit_queue(struct queue *q); 89245102048SBen Goz void print_queue_properties(struct queue_properties *q); 893ed6e6a34SBen Goz void print_queue(struct queue *q); 894ed6e6a34SBen Goz 8954b8f589bSBen Goz struct mqd_manager *mqd_manager_init_cik(enum KFD_MQD_TYPE type, 8964b8f589bSBen Goz struct kfd_dev *dev); 897ee04955aSFelix Kuehling struct mqd_manager *mqd_manager_init_cik_hawaii(enum KFD_MQD_TYPE type, 898ee04955aSFelix Kuehling struct kfd_dev *dev); 8994b8f589bSBen Goz struct mqd_manager *mqd_manager_init_vi(enum KFD_MQD_TYPE type, 9004b8f589bSBen Goz struct kfd_dev *dev); 901ee04955aSFelix Kuehling struct mqd_manager *mqd_manager_init_vi_tonga(enum KFD_MQD_TYPE type, 902ee04955aSFelix Kuehling struct kfd_dev *dev); 903b91d43ddSFelix Kuehling struct mqd_manager *mqd_manager_init_v9(enum KFD_MQD_TYPE type, 904b91d43ddSFelix Kuehling struct kfd_dev *dev); 90514328aa5SPhilip Cox struct mqd_manager *mqd_manager_init_v10(enum KFD_MQD_TYPE type, 90614328aa5SPhilip Cox struct kfd_dev *dev); 90764c7f8cfSBen Goz struct device_queue_manager *device_queue_manager_init(struct kfd_dev *dev); 90864c7f8cfSBen Goz void device_queue_manager_uninit(struct device_queue_manager *dqm); 909241f24f8SBen Goz struct kernel_queue *kernel_queue_init(struct kfd_dev *dev, 910241f24f8SBen Goz enum kfd_queue_type type); 911c2a77fdeSFelix Kuehling void kernel_queue_uninit(struct kernel_queue *kq, bool hanging); 9122640c3faSshaoyunl int kfd_process_vm_fault(struct device_queue_manager *dqm, unsigned int pasid); 913241f24f8SBen Goz 91445102048SBen Goz /* Process Queue Manager */ 91545102048SBen Goz struct process_queue_node { 91645102048SBen Goz struct queue *q; 91745102048SBen Goz struct kernel_queue *kq; 91845102048SBen Goz struct list_head process_queue_list; 91945102048SBen Goz }; 92045102048SBen Goz 9219fd3f1bfSFelix Kuehling void kfd_process_dequeue_from_device(struct kfd_process_device *pdd); 9229fd3f1bfSFelix Kuehling void kfd_process_dequeue_from_all_devices(struct kfd_process *p); 92345102048SBen Goz int pqm_init(struct process_queue_manager *pqm, struct kfd_process *p); 92445102048SBen Goz void pqm_uninit(struct process_queue_manager *pqm); 92545102048SBen Goz int pqm_create_queue(struct process_queue_manager *pqm, 92645102048SBen Goz struct kfd_dev *dev, 92745102048SBen Goz struct file *f, 92845102048SBen Goz struct queue_properties *properties, 929e47a8b52SYong Zhao unsigned int *qid, 930e47a8b52SYong Zhao uint32_t *p_doorbell_offset_in_process); 93145102048SBen Goz int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid); 93245102048SBen Goz int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid, 93345102048SBen Goz struct queue_properties *p); 93439e7f331SFelix Kuehling int pqm_set_cu_mask(struct process_queue_manager *pqm, unsigned int qid, 93539e7f331SFelix Kuehling struct queue_properties *p); 936eb82da1dSOak Zeng int pqm_set_gws(struct process_queue_manager *pqm, unsigned int qid, 937eb82da1dSOak Zeng void *gws); 938fbeb661bSYair Shachar struct kernel_queue *pqm_get_kernel_queue(struct process_queue_manager *pqm, 939fbeb661bSYair Shachar unsigned int qid); 9405bb4b78bSOak Zeng struct queue *pqm_get_user_queue(struct process_queue_manager *pqm, 9415bb4b78bSOak Zeng unsigned int qid); 9425df099e8SJay Cornwall int pqm_get_wave_state(struct process_queue_manager *pqm, 9435df099e8SJay Cornwall unsigned int qid, 9445df099e8SJay Cornwall void __user *ctl_stack, 9455df099e8SJay Cornwall u32 *ctl_stack_used_size, 9465df099e8SJay Cornwall u32 *save_area_used_size); 94745102048SBen Goz 948788bf83dSYair Shachar int amdkfd_fence_wait_timeout(unsigned int *fence_addr, 949788bf83dSYair Shachar unsigned int fence_value, 9508c72c3d7SYong Zhao unsigned int timeout_ms); 951788bf83dSYair Shachar 952ed6e6a34SBen Goz /* Packet Manager */ 953ed6e6a34SBen Goz 95464c7f8cfSBen Goz #define KFD_FENCE_COMPLETED (100) 95564c7f8cfSBen Goz #define KFD_FENCE_INIT (10) 956241f24f8SBen Goz 957ed6e6a34SBen Goz struct packet_manager { 958ed6e6a34SBen Goz struct device_queue_manager *dqm; 959ed6e6a34SBen Goz struct kernel_queue *priv_queue; 960ed6e6a34SBen Goz struct mutex lock; 961ed6e6a34SBen Goz bool allocated; 962ed6e6a34SBen Goz struct kfd_mem_obj *ib_buffer_obj; 963851a645eSFelix Kuehling unsigned int ib_size_bytes; 964819ec5acSFelix Kuehling bool is_over_subscription; 965f6e27ff1SFelix Kuehling 966f6e27ff1SFelix Kuehling const struct packet_manager_funcs *pmf; 967ed6e6a34SBen Goz }; 968ed6e6a34SBen Goz 969f6e27ff1SFelix Kuehling struct packet_manager_funcs { 970f6e27ff1SFelix Kuehling /* Support ASIC-specific packet formats for PM4 packets */ 971f6e27ff1SFelix Kuehling int (*map_process)(struct packet_manager *pm, uint32_t *buffer, 972f6e27ff1SFelix Kuehling struct qcm_process_device *qpd); 973f6e27ff1SFelix Kuehling int (*runlist)(struct packet_manager *pm, uint32_t *buffer, 974f6e27ff1SFelix Kuehling uint64_t ib, size_t ib_size_in_dwords, bool chain); 975f6e27ff1SFelix Kuehling int (*set_resources)(struct packet_manager *pm, uint32_t *buffer, 976f6e27ff1SFelix Kuehling struct scheduling_resources *res); 977f6e27ff1SFelix Kuehling int (*map_queues)(struct packet_manager *pm, uint32_t *buffer, 978f6e27ff1SFelix Kuehling struct queue *q, bool is_static); 979f6e27ff1SFelix Kuehling int (*unmap_queues)(struct packet_manager *pm, uint32_t *buffer, 980f6e27ff1SFelix Kuehling enum kfd_queue_type type, 981f6e27ff1SFelix Kuehling enum kfd_unmap_queues_filter mode, 982f6e27ff1SFelix Kuehling uint32_t filter_param, bool reset, 983f6e27ff1SFelix Kuehling unsigned int sdma_engine); 984f6e27ff1SFelix Kuehling int (*query_status)(struct packet_manager *pm, uint32_t *buffer, 985f6e27ff1SFelix Kuehling uint64_t fence_address, uint32_t fence_value); 986f6e27ff1SFelix Kuehling int (*release_mem)(uint64_t gpu_addr, uint32_t *buffer); 987f6e27ff1SFelix Kuehling 988f6e27ff1SFelix Kuehling /* Packet sizes */ 989f6e27ff1SFelix Kuehling int map_process_size; 990f6e27ff1SFelix Kuehling int runlist_size; 991f6e27ff1SFelix Kuehling int set_resources_size; 992f6e27ff1SFelix Kuehling int map_queues_size; 993f6e27ff1SFelix Kuehling int unmap_queues_size; 994f6e27ff1SFelix Kuehling int query_status_size; 995f6e27ff1SFelix Kuehling int release_mem_size; 996f6e27ff1SFelix Kuehling }; 997f6e27ff1SFelix Kuehling 998f6e27ff1SFelix Kuehling extern const struct packet_manager_funcs kfd_vi_pm_funcs; 999454150b1SFelix Kuehling extern const struct packet_manager_funcs kfd_v9_pm_funcs; 1000f6e27ff1SFelix Kuehling 100164c7f8cfSBen Goz int pm_init(struct packet_manager *pm, struct device_queue_manager *dqm); 1002c2a77fdeSFelix Kuehling void pm_uninit(struct packet_manager *pm, bool hanging); 100364c7f8cfSBen Goz int pm_send_set_resources(struct packet_manager *pm, 100464c7f8cfSBen Goz struct scheduling_resources *res); 100564c7f8cfSBen Goz int pm_send_runlist(struct packet_manager *pm, struct list_head *dqm_queues); 100664c7f8cfSBen Goz int pm_send_query_status(struct packet_manager *pm, uint64_t fence_address, 100764c7f8cfSBen Goz uint32_t fence_value); 100864c7f8cfSBen Goz 100964c7f8cfSBen Goz int pm_send_unmap_queue(struct packet_manager *pm, enum kfd_queue_type type, 10107da2bcf8SYong Zhao enum kfd_unmap_queues_filter mode, 101164c7f8cfSBen Goz uint32_t filter_param, bool reset, 101264c7f8cfSBen Goz unsigned int sdma_engine); 101364c7f8cfSBen Goz 1014241f24f8SBen Goz void pm_release_ib(struct packet_manager *pm); 1015241f24f8SBen Goz 1016454150b1SFelix Kuehling /* Following PM funcs can be shared among VI and AI */ 1017454150b1SFelix Kuehling unsigned int pm_build_pm4_header(unsigned int opcode, size_t packet_size); 101814328aa5SPhilip Cox 101919f6d2a6SOded Gabbay uint64_t kfd_get_number_elems(struct kfd_dev *kfd); 102019f6d2a6SOded Gabbay 1021f3a39818SAndrew Lewycky /* Events */ 1022f3a39818SAndrew Lewycky extern const struct kfd_event_interrupt_class event_interrupt_class_cik; 1023ca750681SFelix Kuehling extern const struct kfd_event_interrupt_class event_interrupt_class_v9; 1024ca750681SFelix Kuehling 1025930c5ff4SAlexey Skidanov extern const struct kfd_device_global_init_class device_global_init_class_cik; 1026f3a39818SAndrew Lewycky 1027f3a39818SAndrew Lewycky void kfd_event_init_process(struct kfd_process *p); 1028f3a39818SAndrew Lewycky void kfd_event_free_process(struct kfd_process *p); 1029f3a39818SAndrew Lewycky int kfd_event_mmap(struct kfd_process *process, struct vm_area_struct *vma); 1030f3a39818SAndrew Lewycky int kfd_wait_on_events(struct kfd_process *p, 103159d3e8beSAlexey Skidanov uint32_t num_events, void __user *data, 1032f3a39818SAndrew Lewycky bool all, uint32_t user_timeout_ms, 1033fdf0c833SFelix Kuehling uint32_t *wait_result); 1034f3a39818SAndrew Lewycky void kfd_signal_event_interrupt(unsigned int pasid, uint32_t partial_id, 1035f3a39818SAndrew Lewycky uint32_t valid_id_bits); 103659d3e8beSAlexey Skidanov void kfd_signal_iommu_event(struct kfd_dev *dev, 103759d3e8beSAlexey Skidanov unsigned int pasid, unsigned long address, 103859d3e8beSAlexey Skidanov bool is_write_requested, bool is_execute_requested); 1039930c5ff4SAlexey Skidanov void kfd_signal_hw_exception_event(unsigned int pasid); 1040f3a39818SAndrew Lewycky int kfd_set_event(struct kfd_process *p, uint32_t event_id); 1041f3a39818SAndrew Lewycky int kfd_reset_event(struct kfd_process *p, uint32_t event_id); 10420fc8011fSFelix Kuehling int kfd_event_page_set(struct kfd_process *p, void *kernel_address, 10430fc8011fSFelix Kuehling uint64_t size); 1044f3a39818SAndrew Lewycky int kfd_event_create(struct file *devkfd, struct kfd_process *p, 1045f3a39818SAndrew Lewycky uint32_t event_type, bool auto_reset, uint32_t node_id, 1046f3a39818SAndrew Lewycky uint32_t *event_id, uint32_t *event_trigger_data, 1047f3a39818SAndrew Lewycky uint64_t *event_page_offset, uint32_t *event_slot_index); 1048f3a39818SAndrew Lewycky int kfd_event_destroy(struct kfd_process *p, uint32_t event_id); 1049f3a39818SAndrew Lewycky 10502640c3faSshaoyunl void kfd_signal_vm_fault_event(struct kfd_dev *dev, unsigned int pasid, 10512640c3faSshaoyunl struct kfd_vm_fault_info *info); 10522640c3faSshaoyunl 1053e42051d2SShaoyun Liu void kfd_signal_reset_event(struct kfd_dev *dev); 1054e42051d2SShaoyun Liu 1055403575c4SFelix Kuehling void kfd_flush_tlb(struct kfd_process_device *pdd); 1056403575c4SFelix Kuehling 1057c3447e81SBen Goz int dbgdev_wave_reset_wavefronts(struct kfd_dev *dev, struct kfd_process *p); 1058c3447e81SBen Goz 1059e42051d2SShaoyun Liu bool kfd_is_locked(void); 1060e42051d2SShaoyun Liu 1061f756e631SHarish Kasiviswanathan /* Compute profile */ 1062f756e631SHarish Kasiviswanathan void kfd_inc_compute_active(struct kfd_dev *dev); 1063f756e631SHarish Kasiviswanathan void kfd_dec_compute_active(struct kfd_dev *dev); 1064f756e631SHarish Kasiviswanathan 10656b855f7bSHarish Kasiviswanathan /* Cgroup Support */ 10666b855f7bSHarish Kasiviswanathan /* Check with device cgroup if @kfd device is accessible */ 10676b855f7bSHarish Kasiviswanathan static inline int kfd_devcgroup_check_permission(struct kfd_dev *kfd) 10686b855f7bSHarish Kasiviswanathan { 10696b855f7bSHarish Kasiviswanathan #if defined(CONFIG_CGROUP_DEVICE) 10706b855f7bSHarish Kasiviswanathan struct drm_device *ddev = kfd->ddev; 10716b855f7bSHarish Kasiviswanathan 10726b855f7bSHarish Kasiviswanathan return devcgroup_check_permission(DEVCG_DEV_CHAR, ddev->driver->major, 10736b855f7bSHarish Kasiviswanathan ddev->render->index, 10746b855f7bSHarish Kasiviswanathan DEVCG_ACC_WRITE | DEVCG_ACC_READ); 10756b855f7bSHarish Kasiviswanathan #else 10766b855f7bSHarish Kasiviswanathan return 0; 10776b855f7bSHarish Kasiviswanathan #endif 10786b855f7bSHarish Kasiviswanathan } 10796b855f7bSHarish Kasiviswanathan 1080851a645eSFelix Kuehling /* Debugfs */ 1081851a645eSFelix Kuehling #if defined(CONFIG_DEBUG_FS) 1082851a645eSFelix Kuehling 1083851a645eSFelix Kuehling void kfd_debugfs_init(void); 1084851a645eSFelix Kuehling void kfd_debugfs_fini(void); 1085851a645eSFelix Kuehling int kfd_debugfs_mqds_by_process(struct seq_file *m, void *data); 1086851a645eSFelix Kuehling int pqm_debugfs_mqds(struct seq_file *m, void *data); 1087851a645eSFelix Kuehling int kfd_debugfs_hqds_by_device(struct seq_file *m, void *data); 1088851a645eSFelix Kuehling int dqm_debugfs_hqds(struct seq_file *m, void *data); 1089851a645eSFelix Kuehling int kfd_debugfs_rls_by_device(struct seq_file *m, void *data); 1090851a645eSFelix Kuehling int pm_debugfs_runlist(struct seq_file *m, void *data); 1091851a645eSFelix Kuehling 1092a29ec470SShaoyun Liu int kfd_debugfs_hang_hws(struct kfd_dev *dev); 1093a29ec470SShaoyun Liu int pm_debugfs_hang_hws(struct packet_manager *pm); 1094a29ec470SShaoyun Liu int dqm_debugfs_execute_queues(struct device_queue_manager *dqm); 1095a29ec470SShaoyun Liu 1096851a645eSFelix Kuehling #else 1097851a645eSFelix Kuehling 1098851a645eSFelix Kuehling static inline void kfd_debugfs_init(void) {} 1099851a645eSFelix Kuehling static inline void kfd_debugfs_fini(void) {} 1100851a645eSFelix Kuehling 1101851a645eSFelix Kuehling #endif 1102851a645eSFelix Kuehling 11034a488a7aSOded Gabbay #endif 1104