xref: /openbmc/linux/drivers/gpu/drm/amd/amdkfd/kfd_priv.h (revision 819ec5ac)
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>
394a488a7aSOded Gabbay #include <kgd_kfd_interface.h>
404a488a7aSOded Gabbay 
41e596b903SYong Zhao #include "amd_shared.h"
42e596b903SYong Zhao 
43af47b390SLaura Abbott #define KFD_MAX_RING_ENTRY_SIZE	8
44af47b390SLaura Abbott 
455b5c4e40SEvgeny Pinchuk #define KFD_SYSFS_FILE_MODE 0444
465b5c4e40SEvgeny Pinchuk 
47df03ef93SHarish Kasiviswanathan /* GPU ID hash width in bits */
48df03ef93SHarish Kasiviswanathan #define KFD_GPU_ID_HASH_WIDTH 16
49df03ef93SHarish Kasiviswanathan 
50df03ef93SHarish Kasiviswanathan /* Use upper bits of mmap offset to store KFD driver specific information.
51df03ef93SHarish Kasiviswanathan  * BITS[63:62] - Encode MMAP type
52df03ef93SHarish Kasiviswanathan  * BITS[61:46] - Encode gpu_id. To identify to which GPU the offset belongs to
53df03ef93SHarish Kasiviswanathan  * BITS[45:0]  - MMAP offset value
54df03ef93SHarish Kasiviswanathan  *
55df03ef93SHarish Kasiviswanathan  * NOTE: struct vm_area_struct.vm_pgoff uses offset in pages. Hence, these
56df03ef93SHarish Kasiviswanathan  *  defines are w.r.t to PAGE_SIZE
57df03ef93SHarish Kasiviswanathan  */
58df03ef93SHarish Kasiviswanathan #define KFD_MMAP_TYPE_SHIFT	(62 - PAGE_SHIFT)
59df03ef93SHarish Kasiviswanathan #define KFD_MMAP_TYPE_MASK	(0x3ULL << KFD_MMAP_TYPE_SHIFT)
60df03ef93SHarish Kasiviswanathan #define KFD_MMAP_TYPE_DOORBELL	(0x3ULL << KFD_MMAP_TYPE_SHIFT)
61df03ef93SHarish Kasiviswanathan #define KFD_MMAP_TYPE_EVENTS	(0x2ULL << KFD_MMAP_TYPE_SHIFT)
62df03ef93SHarish Kasiviswanathan #define KFD_MMAP_TYPE_RESERVED_MEM	(0x1ULL << KFD_MMAP_TYPE_SHIFT)
63d33ea570SOak Zeng #define KFD_MMAP_TYPE_MMIO	(0x0ULL << KFD_MMAP_TYPE_SHIFT)
64df03ef93SHarish Kasiviswanathan 
65df03ef93SHarish Kasiviswanathan #define KFD_MMAP_GPU_ID_SHIFT (46 - PAGE_SHIFT)
66df03ef93SHarish Kasiviswanathan #define KFD_MMAP_GPU_ID_MASK (((1ULL << KFD_GPU_ID_HASH_WIDTH) - 1) \
67df03ef93SHarish Kasiviswanathan 				<< KFD_MMAP_GPU_ID_SHIFT)
68df03ef93SHarish Kasiviswanathan #define KFD_MMAP_GPU_ID(gpu_id) ((((uint64_t)gpu_id) << KFD_MMAP_GPU_ID_SHIFT)\
69df03ef93SHarish Kasiviswanathan 				& KFD_MMAP_GPU_ID_MASK)
70df03ef93SHarish Kasiviswanathan #define KFD_MMAP_GPU_ID_GET(offset)    ((offset & KFD_MMAP_GPU_ID_MASK) \
71df03ef93SHarish Kasiviswanathan 				>> KFD_MMAP_GPU_ID_SHIFT)
72df03ef93SHarish Kasiviswanathan 
73df03ef93SHarish Kasiviswanathan #define KFD_MMAP_OFFSET_VALUE_MASK	(0x3FFFFFFFFFFFULL >> PAGE_SHIFT)
74df03ef93SHarish Kasiviswanathan #define KFD_MMAP_OFFSET_VALUE_GET(offset) (offset & KFD_MMAP_OFFSET_VALUE_MASK)
75f3a39818SAndrew Lewycky 
76ed6e6a34SBen Goz /*
77ed6e6a34SBen Goz  * When working with cp scheduler we should assign the HIQ manually or via
78e7016d8eSYong Zhao  * the amdgpu driver to a fixed hqd slot, here are the fixed HIQ hqd slot
79ed6e6a34SBen Goz  * definitions for Kaveri. In Kaveri only the first ME queues participates
80ed6e6a34SBen Goz  * in the cp scheduling taking that in mind we set the HIQ slot in the
81ed6e6a34SBen Goz  * second ME.
82ed6e6a34SBen Goz  */
83ed6e6a34SBen Goz #define KFD_CIK_HIQ_PIPE 4
84ed6e6a34SBen Goz #define KFD_CIK_HIQ_QUEUE 0
85ed6e6a34SBen Goz 
865b5c4e40SEvgeny Pinchuk /* Macro for allocating structures */
875b5c4e40SEvgeny Pinchuk #define kfd_alloc_struct(ptr_to_struct)	\
885b5c4e40SEvgeny Pinchuk 	((typeof(ptr_to_struct)) kzalloc(sizeof(*ptr_to_struct), GFP_KERNEL))
895b5c4e40SEvgeny Pinchuk 
9019f6d2a6SOded Gabbay #define KFD_MAX_NUM_OF_PROCESSES 512
91b8cbab04SOded Gabbay #define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS 1024
9219f6d2a6SOded Gabbay 
9319f6d2a6SOded Gabbay /*
94373d7080SFelix Kuehling  * Size of the per-process TBA+TMA buffer: 2 pages
95373d7080SFelix Kuehling  *
96373d7080SFelix Kuehling  * The first page is the TBA used for the CWSR ISA code. The second
97373d7080SFelix Kuehling  * page is used as TMA for daisy changing a user-mode trap handler.
98373d7080SFelix Kuehling  */
99373d7080SFelix Kuehling #define KFD_CWSR_TBA_TMA_SIZE (PAGE_SIZE * 2)
100373d7080SFelix Kuehling #define KFD_CWSR_TMA_OFFSET PAGE_SIZE
101373d7080SFelix Kuehling 
10274523943SYong Zhao #define KFD_MAX_NUM_OF_QUEUES_PER_DEVICE		\
10374523943SYong Zhao 	(KFD_MAX_NUM_OF_PROCESSES *			\
10474523943SYong Zhao 			KFD_MAX_NUM_OF_QUEUES_PER_PROCESS)
10574523943SYong Zhao 
10674523943SYong Zhao #define KFD_KERNEL_QUEUE_SIZE 2048
10774523943SYong Zhao 
10814328aa5SPhilip Cox #define KFD_UNMAP_LATENCY_MS	(4000)
10914328aa5SPhilip Cox 
110373d7080SFelix Kuehling /*
1111f86805aSYong Zhao  * 512 = 0x200
1121f86805aSYong Zhao  * The doorbell index distance between SDMA RLC (2*i) and (2*i+1) in the
1131f86805aSYong Zhao  * same SDMA engine on SOC15, which has 8-byte doorbells for SDMA.
1141f86805aSYong Zhao  * 512 8-byte doorbell distance (i.e. one page away) ensures that SDMA RLC
1151f86805aSYong Zhao  * (2*i+1) doorbells (in terms of the lower 12 bit address) lie exactly in
1161f86805aSYong Zhao  * the OFFSET and SIZE set in registers like BIF_SDMA0_DOORBELL_RANGE.
1171f86805aSYong Zhao  */
1181f86805aSYong Zhao #define KFD_QUEUE_DOORBELL_MIRROR_OFFSET 512
1191f86805aSYong Zhao 
1201f86805aSYong Zhao 
1211f86805aSYong Zhao /*
122b8cbab04SOded Gabbay  * Kernel module parameter to specify maximum number of supported queues per
123b8cbab04SOded Gabbay  * device
12419f6d2a6SOded Gabbay  */
125b8cbab04SOded Gabbay extern int max_num_of_queues_per_device;
12619f6d2a6SOded Gabbay 
127ed6e6a34SBen Goz 
12831c21fecSBen Goz /* Kernel module parameter to specify the scheduling policy */
12931c21fecSBen Goz extern int sched_policy;
13031c21fecSBen Goz 
131a99c6d4fSFelix Kuehling /*
132a99c6d4fSFelix Kuehling  * Kernel module parameter to specify the maximum process
133a99c6d4fSFelix Kuehling  * number per HW scheduler
134a99c6d4fSFelix Kuehling  */
135a99c6d4fSFelix Kuehling extern int hws_max_conc_proc;
136a99c6d4fSFelix Kuehling 
137373d7080SFelix Kuehling extern int cwsr_enable;
138373d7080SFelix Kuehling 
13981663016SOded Gabbay /*
14081663016SOded Gabbay  * Kernel module parameter to specify whether to send sigterm to HSA process on
14181663016SOded Gabbay  * unhandled exception
14281663016SOded Gabbay  */
14381663016SOded Gabbay extern int send_sigterm;
14481663016SOded Gabbay 
145ebcfd1e2SFelix Kuehling /*
146374200b1SFelix Kuehling  * This kernel module is used to simulate large bar machine on non-large bar
147374200b1SFelix Kuehling  * enabled machines.
148374200b1SFelix Kuehling  */
149374200b1SFelix Kuehling extern int debug_largebar;
150374200b1SFelix Kuehling 
151374200b1SFelix Kuehling /*
152ebcfd1e2SFelix Kuehling  * Ignore CRAT table during KFD initialization, can be used to work around
153ebcfd1e2SFelix Kuehling  * broken CRAT tables on some AMD systems
154ebcfd1e2SFelix Kuehling  */
155ebcfd1e2SFelix Kuehling extern int ignore_crat;
156ebcfd1e2SFelix Kuehling 
157bed4f110SFelix Kuehling /*
158bed4f110SFelix Kuehling  * Set sh_mem_config.retry_disable on Vega10
159bed4f110SFelix Kuehling  */
1602b281977SYong Zhao extern int noretry;
161bed4f110SFelix Kuehling 
1620e9a860cSYong Zhao /*
1630e9a860cSYong Zhao  * Halt if HWS hang is detected
1640e9a860cSYong Zhao  */
1650e9a860cSYong Zhao extern int halt_if_hws_hang;
1660e9a860cSYong Zhao 
16729e76462SOak Zeng /*
16829e76462SOak Zeng  * Whether MEC FW support GWS barriers
16929e76462SOak Zeng  */
17029e76462SOak Zeng extern bool hws_gws_support;
17129e76462SOak Zeng 
17214328aa5SPhilip Cox /*
17314328aa5SPhilip Cox  * Queue preemption timeout in ms
17414328aa5SPhilip Cox  */
17514328aa5SPhilip Cox extern int queue_preemption_timeout_ms;
17614328aa5SPhilip Cox 
177ed6e6a34SBen Goz enum cache_policy {
178ed6e6a34SBen Goz 	cache_policy_coherent,
179ed6e6a34SBen Goz 	cache_policy_noncoherent
180ed6e6a34SBen Goz };
181ed6e6a34SBen Goz 
18214328aa5SPhilip Cox #define KFD_IS_VI(chip) ((chip) >= CHIP_CARRIZO && (chip) <= CHIP_POLARIS11)
18314328aa5SPhilip Cox #define KFD_IS_DGPU(chip) (((chip) >= CHIP_TONGA && \
18414328aa5SPhilip Cox 			   (chip) <= CHIP_NAVI10) || \
18514328aa5SPhilip Cox 			   (chip) == CHIP_HAWAII)
186ef568db7SFelix Kuehling #define KFD_IS_SOC15(chip) ((chip) >= CHIP_VEGA10)
187ef568db7SFelix Kuehling 
188f3a39818SAndrew Lewycky struct kfd_event_interrupt_class {
189f3a39818SAndrew Lewycky 	bool (*interrupt_isr)(struct kfd_dev *dev,
19058e69886SLan Xiao 			const uint32_t *ih_ring_entry, uint32_t *patched_ihre,
19158e69886SLan Xiao 			bool *patched_flag);
192f3a39818SAndrew Lewycky 	void (*interrupt_wq)(struct kfd_dev *dev,
193f3a39818SAndrew Lewycky 			const uint32_t *ih_ring_entry);
194f3a39818SAndrew Lewycky };
195f3a39818SAndrew Lewycky 
1964a488a7aSOded Gabbay struct kfd_device_info {
197e596b903SYong Zhao 	enum amd_asic_type asic_family;
198f3a39818SAndrew Lewycky 	const struct kfd_event_interrupt_class *event_interrupt_class;
1994a488a7aSOded Gabbay 	unsigned int max_pasid_bits;
200992839adSYair Shachar 	unsigned int max_no_of_hqd;
201ada2b29cSFelix Kuehling 	unsigned int doorbell_size;
2024a488a7aSOded Gabbay 	size_t ih_ring_entry_size;
203f7c826adSAlexey Skidanov 	uint8_t num_of_watch_points;
20419f6d2a6SOded Gabbay 	uint16_t mqd_size_aligned;
205373d7080SFelix Kuehling 	bool supports_cwsr;
20664d1c3a4SFelix Kuehling 	bool needs_iommu_device;
2073ee2d00cSFelix Kuehling 	bool needs_pci_atomics;
20898bb9222SYong Zhao 	unsigned int num_sdma_engines;
2091b4670f6SOak Zeng 	unsigned int num_xgmi_sdma_engines;
210d5094189SShaoyun Liu 	unsigned int num_sdma_queues_per_engine;
2114a488a7aSOded Gabbay };
2124a488a7aSOded Gabbay 
21336b5c08fSOded Gabbay struct kfd_mem_obj {
21436b5c08fSOded Gabbay 	uint32_t range_start;
21536b5c08fSOded Gabbay 	uint32_t range_end;
21636b5c08fSOded Gabbay 	uint64_t gpu_addr;
21736b5c08fSOded Gabbay 	uint32_t *cpu_ptr;
218b91d43ddSFelix Kuehling 	void *gtt_mem;
21936b5c08fSOded Gabbay };
22036b5c08fSOded Gabbay 
22144008d7aSYong Zhao struct kfd_vmid_info {
22244008d7aSYong Zhao 	uint32_t first_vmid_kfd;
22344008d7aSYong Zhao 	uint32_t last_vmid_kfd;
22444008d7aSYong Zhao 	uint32_t vmid_num_kfd;
22544008d7aSYong Zhao };
22644008d7aSYong Zhao 
2274a488a7aSOded Gabbay struct kfd_dev {
2284a488a7aSOded Gabbay 	struct kgd_dev *kgd;
2294a488a7aSOded Gabbay 
2304a488a7aSOded Gabbay 	const struct kfd_device_info *device_info;
2314a488a7aSOded Gabbay 	struct pci_dev *pdev;
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 					 */
23919f6d2a6SOded Gabbay 	size_t doorbell_id_offset;	/* Doorbell offset (from KFD doorbell
24019f6d2a6SOded Gabbay 					 * to HW doorbell, GFX reserved some
24119f6d2a6SOded Gabbay 					 * at the start)
24219f6d2a6SOded Gabbay 					 */
24319f6d2a6SOded Gabbay 	u32 __iomem *doorbell_kernel_ptr; /* This is a pointer for a doorbells
24419f6d2a6SOded Gabbay 					   * page used by kernel queue
24519f6d2a6SOded Gabbay 					   */
24619f6d2a6SOded Gabbay 
2474a488a7aSOded Gabbay 	struct kgd2kfd_shared_resources shared_resources;
24844008d7aSYong Zhao 	struct kfd_vmid_info vm_info;
2494a488a7aSOded Gabbay 
250cea405b1SXihan Zhang 	const struct kfd2kgd_calls *kfd2kgd;
251cea405b1SXihan Zhang 	struct mutex doorbell_mutex;
252f761d8bdSJoe Perches 	DECLARE_BITMAP(doorbell_available_index,
253f761d8bdSJoe Perches 			KFD_MAX_NUM_OF_QUEUES_PER_PROCESS);
254cea405b1SXihan Zhang 
25536b5c08fSOded Gabbay 	void *gtt_mem;
25636b5c08fSOded Gabbay 	uint64_t gtt_start_gpu_addr;
25736b5c08fSOded Gabbay 	void *gtt_start_cpu_ptr;
25836b5c08fSOded Gabbay 	void *gtt_sa_bitmap;
25936b5c08fSOded Gabbay 	struct mutex gtt_sa_lock;
26036b5c08fSOded Gabbay 	unsigned int gtt_sa_chunk_size;
26136b5c08fSOded Gabbay 	unsigned int gtt_sa_num_of_chunks;
26236b5c08fSOded Gabbay 
2632249d558SAndrew Lewycky 	/* Interrupts */
26404ad47bdSAndres Rodriguez 	struct kfifo ih_fifo;
26548e876a2SAndres Rodriguez 	struct workqueue_struct *ih_wq;
2662249d558SAndrew Lewycky 	struct work_struct interrupt_work;
2672249d558SAndrew Lewycky 	spinlock_t interrupt_lock;
2682249d558SAndrew Lewycky 
269ed6e6a34SBen Goz 	/* QCM Device instance */
270ed6e6a34SBen Goz 	struct device_queue_manager *dqm;
2714a488a7aSOded Gabbay 
272ed6e6a34SBen Goz 	bool init_complete;
2732249d558SAndrew Lewycky 	/*
2742249d558SAndrew Lewycky 	 * Interrupts of interest to KFD are copied
2752249d558SAndrew Lewycky 	 * from the HW ring into a SW ring.
2762249d558SAndrew Lewycky 	 */
2772249d558SAndrew Lewycky 	bool interrupts_active;
278fbeb661bSYair Shachar 
279fbeb661bSYair Shachar 	/* Debug manager */
280fbeb661bSYair Shachar 	struct kfd_dbgmgr *dbgmgr;
281373d7080SFelix Kuehling 
2825ade6c9cSFelix Kuehling 	/* Firmware versions */
2835ade6c9cSFelix Kuehling 	uint16_t mec_fw_version;
2845ade6c9cSFelix Kuehling 	uint16_t sdma_fw_version;
2855ade6c9cSFelix Kuehling 
286a99c6d4fSFelix Kuehling 	/* Maximum process number mapped to HW scheduler */
287a99c6d4fSFelix Kuehling 	unsigned int max_proc_per_quantum;
288a99c6d4fSFelix Kuehling 
289373d7080SFelix Kuehling 	/* CWSR */
290373d7080SFelix Kuehling 	bool cwsr_enabled;
291373d7080SFelix Kuehling 	const void *cwsr_isa;
292373d7080SFelix Kuehling 	unsigned int cwsr_isa_size;
2930c1690e3SShaoyun Liu 
2940c1690e3SShaoyun Liu 	/* xGMI */
2950c1690e3SShaoyun Liu 	uint64_t hive_id;
296d35f00d8SEric Huang 
297d35f00d8SEric Huang 	bool pci_atomic_requested;
2989b54d201SEric Huang 
2999b54d201SEric Huang 	/* SRAM ECC flag */
3009b54d201SEric Huang 	atomic_t sram_ecc_flag;
301f756e631SHarish Kasiviswanathan 
302f756e631SHarish Kasiviswanathan 	/* Compute Profile ref. count */
303f756e631SHarish Kasiviswanathan 	atomic_t compute_profile;
304e09d4fc8SOak Zeng 
305e09d4fc8SOak Zeng 	/* Global GWS resource shared b/t processes*/
306e09d4fc8SOak Zeng 	void *gws;
3074a488a7aSOded Gabbay };
3084a488a7aSOded Gabbay 
30919f6d2a6SOded Gabbay enum kfd_mempool {
31019f6d2a6SOded Gabbay 	KFD_MEMPOOL_SYSTEM_CACHEABLE = 1,
31119f6d2a6SOded Gabbay 	KFD_MEMPOOL_SYSTEM_WRITECOMBINE = 2,
31219f6d2a6SOded Gabbay 	KFD_MEMPOOL_FRAMEBUFFER = 3,
31319f6d2a6SOded Gabbay };
31419f6d2a6SOded Gabbay 
3154a488a7aSOded Gabbay /* Character device interface */
3164a488a7aSOded Gabbay int kfd_chardev_init(void);
3174a488a7aSOded Gabbay void kfd_chardev_exit(void);
3184a488a7aSOded Gabbay struct device *kfd_chardev(void);
3194a488a7aSOded Gabbay 
320241f24f8SBen Goz /**
3217da2bcf8SYong Zhao  * enum kfd_unmap_queues_filter
322241f24f8SBen Goz  *
3237da2bcf8SYong Zhao  * @KFD_UNMAP_QUEUES_FILTER_SINGLE_QUEUE: Preempts single queue.
324241f24f8SBen Goz  *
3257da2bcf8SYong Zhao  * @KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES: Preempts all queues in the
326241f24f8SBen Goz  *						running queues list.
327241f24f8SBen Goz  *
3287da2bcf8SYong Zhao  * @KFD_UNMAP_QUEUES_FILTER_BY_PASID: Preempts queues that belongs to
329241f24f8SBen Goz  *						specific process.
330241f24f8SBen Goz  *
331241f24f8SBen Goz  */
3327da2bcf8SYong Zhao enum kfd_unmap_queues_filter {
3337da2bcf8SYong Zhao 	KFD_UNMAP_QUEUES_FILTER_SINGLE_QUEUE,
3347da2bcf8SYong Zhao 	KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES,
3357da2bcf8SYong Zhao 	KFD_UNMAP_QUEUES_FILTER_DYNAMIC_QUEUES,
3367da2bcf8SYong Zhao 	KFD_UNMAP_QUEUES_FILTER_BY_PASID
337241f24f8SBen Goz };
33819f6d2a6SOded Gabbay 
339ed8aab45SBen Goz /**
340ed8aab45SBen Goz  * enum kfd_queue_type
341ed8aab45SBen Goz  *
342ed8aab45SBen Goz  * @KFD_QUEUE_TYPE_COMPUTE: Regular user mode queue type.
343ed8aab45SBen Goz  *
344ed8aab45SBen Goz  * @KFD_QUEUE_TYPE_SDMA: Sdma user mode queue type.
345ed8aab45SBen Goz  *
346ed8aab45SBen Goz  * @KFD_QUEUE_TYPE_HIQ: HIQ queue type.
347ed8aab45SBen Goz  *
348ed8aab45SBen Goz  * @KFD_QUEUE_TYPE_DIQ: DIQ queue type.
349ed8aab45SBen Goz  */
350ed8aab45SBen Goz enum kfd_queue_type  {
351ed8aab45SBen Goz 	KFD_QUEUE_TYPE_COMPUTE,
352ed8aab45SBen Goz 	KFD_QUEUE_TYPE_SDMA,
353ed8aab45SBen Goz 	KFD_QUEUE_TYPE_HIQ,
3541b4670f6SOak Zeng 	KFD_QUEUE_TYPE_DIQ,
3551b4670f6SOak Zeng 	KFD_QUEUE_TYPE_SDMA_XGMI
356ed8aab45SBen Goz };
357ed8aab45SBen Goz 
3586e99df57SBen Goz enum kfd_queue_format {
3596e99df57SBen Goz 	KFD_QUEUE_FORMAT_PM4,
3606e99df57SBen Goz 	KFD_QUEUE_FORMAT_AQL
3616e99df57SBen Goz };
3626e99df57SBen Goz 
3630ccbc7cdSOak Zeng enum KFD_QUEUE_PRIORITY {
3640ccbc7cdSOak Zeng 	KFD_QUEUE_PRIORITY_MINIMUM = 0,
3650ccbc7cdSOak Zeng 	KFD_QUEUE_PRIORITY_MAXIMUM = 15
3660ccbc7cdSOak Zeng };
3670ccbc7cdSOak Zeng 
368ed8aab45SBen Goz /**
369ed8aab45SBen Goz  * struct queue_properties
370ed8aab45SBen Goz  *
371ed8aab45SBen Goz  * @type: The queue type.
372ed8aab45SBen Goz  *
373ed8aab45SBen Goz  * @queue_id: Queue identifier.
374ed8aab45SBen Goz  *
375ed8aab45SBen Goz  * @queue_address: Queue ring buffer address.
376ed8aab45SBen Goz  *
377ed8aab45SBen Goz  * @queue_size: Queue ring buffer size.
378ed8aab45SBen Goz  *
379ed8aab45SBen Goz  * @priority: Defines the queue priority relative to other queues in the
380ed8aab45SBen Goz  * process.
381ed8aab45SBen Goz  * This is just an indication and HW scheduling may override the priority as
382ed8aab45SBen Goz  * necessary while keeping the relative prioritization.
383ed8aab45SBen Goz  * the priority granularity is from 0 to f which f is the highest priority.
384ed8aab45SBen Goz  * currently all queues are initialized with the highest priority.
385ed8aab45SBen Goz  *
386ed8aab45SBen Goz  * @queue_percent: This field is partially implemented and currently a zero in
387ed8aab45SBen Goz  * this field defines that the queue is non active.
388ed8aab45SBen Goz  *
389ed8aab45SBen Goz  * @read_ptr: User space address which points to the number of dwords the
390ed8aab45SBen Goz  * cp read from the ring buffer. This field updates automatically by the H/W.
391ed8aab45SBen Goz  *
392ed8aab45SBen Goz  * @write_ptr: Defines the number of dwords written to the ring buffer.
393ed8aab45SBen Goz  *
394ed8aab45SBen Goz  * @doorbell_ptr: This field aim is to notify the H/W of new packet written to
3958eabaf54SKent Russell  * the queue ring buffer. This field should be similar to write_ptr and the
3968eabaf54SKent Russell  * user should update this field after he updated the write_ptr.
397ed8aab45SBen Goz  *
398ed8aab45SBen Goz  * @doorbell_off: The doorbell offset in the doorbell pci-bar.
399ed8aab45SBen Goz  *
4008eabaf54SKent Russell  * @is_interop: Defines if this is a interop queue. Interop queue means that
4018eabaf54SKent Russell  * the queue can access both graphics and compute resources.
402ed8aab45SBen Goz  *
40326103436SFelix Kuehling  * @is_evicted: Defines if the queue is evicted. Only active queues
40426103436SFelix Kuehling  * are evicted, rendering them inactive.
40526103436SFelix Kuehling  *
40626103436SFelix Kuehling  * @is_active: Defines if the queue is active or not. @is_active and
40726103436SFelix Kuehling  * @is_evicted are protected by the DQM lock.
408ed8aab45SBen Goz  *
409ed8aab45SBen Goz  * @vmid: If the scheduling mode is no cp scheduling the field defines the vmid
410ed8aab45SBen Goz  * of the queue.
411ed8aab45SBen Goz  *
412ed8aab45SBen Goz  * This structure represents the queue properties for each queue no matter if
413ed8aab45SBen Goz  * it's user mode or kernel mode queue.
414ed8aab45SBen Goz  *
415ed8aab45SBen Goz  */
416ed8aab45SBen Goz struct queue_properties {
417ed8aab45SBen Goz 	enum kfd_queue_type type;
4186e99df57SBen Goz 	enum kfd_queue_format format;
419ed8aab45SBen Goz 	unsigned int queue_id;
420ed8aab45SBen Goz 	uint64_t queue_address;
421ed8aab45SBen Goz 	uint64_t  queue_size;
422ed8aab45SBen Goz 	uint32_t priority;
423ed8aab45SBen Goz 	uint32_t queue_percent;
424ed8aab45SBen Goz 	uint32_t *read_ptr;
425ed8aab45SBen Goz 	uint32_t *write_ptr;
426ada2b29cSFelix Kuehling 	void __iomem *doorbell_ptr;
427ed8aab45SBen Goz 	uint32_t doorbell_off;
428ed8aab45SBen Goz 	bool is_interop;
42926103436SFelix Kuehling 	bool is_evicted;
430ed8aab45SBen Goz 	bool is_active;
431ed8aab45SBen Goz 	/* Not relevant for user mode queues in cp scheduling */
432ed8aab45SBen Goz 	unsigned int vmid;
43377669eb8SBen Goz 	/* Relevant only for sdma queues*/
43477669eb8SBen Goz 	uint32_t sdma_engine_id;
43577669eb8SBen Goz 	uint32_t sdma_queue_id;
43677669eb8SBen Goz 	uint32_t sdma_vm_addr;
437ff3d04a1SBen Goz 	/* Relevant only for VI */
438ff3d04a1SBen Goz 	uint64_t eop_ring_buffer_address;
439ff3d04a1SBen Goz 	uint32_t eop_ring_buffer_size;
440ff3d04a1SBen Goz 	uint64_t ctx_save_restore_area_address;
441ff3d04a1SBen Goz 	uint32_t ctx_save_restore_area_size;
442373d7080SFelix Kuehling 	uint32_t ctl_stack_size;
443373d7080SFelix Kuehling 	uint64_t tba_addr;
444373d7080SFelix Kuehling 	uint64_t tma_addr;
44539e7f331SFelix Kuehling 	/* Relevant for CU */
44639e7f331SFelix Kuehling 	uint32_t cu_mask_count; /* Must be a multiple of 32 */
44739e7f331SFelix Kuehling 	uint32_t *cu_mask;
448ed8aab45SBen Goz };
449ed8aab45SBen Goz 
450bb2d2128SFelix Kuehling #define QUEUE_IS_ACTIVE(q) ((q).queue_size > 0 &&	\
451bb2d2128SFelix Kuehling 			    (q).queue_address != 0 &&	\
452bb2d2128SFelix Kuehling 			    (q).queue_percent > 0 &&	\
453bb2d2128SFelix Kuehling 			    !(q).is_evicted)
454bb2d2128SFelix Kuehling 
455ed8aab45SBen Goz /**
456ed8aab45SBen Goz  * struct queue
457ed8aab45SBen Goz  *
458ed8aab45SBen Goz  * @list: Queue linked list.
459ed8aab45SBen Goz  *
460ed8aab45SBen Goz  * @mqd: The queue MQD.
461ed8aab45SBen Goz  *
462ed8aab45SBen Goz  * @mqd_mem_obj: The MQD local gpu memory object.
463ed8aab45SBen Goz  *
464ed8aab45SBen Goz  * @gart_mqd_addr: The MQD gart mc address.
465ed8aab45SBen Goz  *
466ed8aab45SBen Goz  * @properties: The queue properties.
467ed8aab45SBen Goz  *
468ed8aab45SBen Goz  * @mec: Used only in no cp scheduling mode and identifies to micro engine id
469ed8aab45SBen Goz  *	 that the queue should be execute on.
470ed8aab45SBen Goz  *
4718eabaf54SKent Russell  * @pipe: Used only in no cp scheduling mode and identifies the queue's pipe
4728eabaf54SKent Russell  *	  id.
473ed8aab45SBen Goz  *
474ed8aab45SBen Goz  * @queue: Used only in no cp scheduliong mode and identifies the queue's slot.
475ed8aab45SBen Goz  *
476ed8aab45SBen Goz  * @process: The kfd process that created this queue.
477ed8aab45SBen Goz  *
478ed8aab45SBen Goz  * @device: The kfd device that created this queue.
479ed8aab45SBen Goz  *
480eb82da1dSOak Zeng  * @gws: Pointing to gws kgd_mem if this is a gws control queue; NULL
481eb82da1dSOak Zeng  * otherwise.
482eb82da1dSOak Zeng  *
483ed8aab45SBen Goz  * This structure represents user mode compute queues.
484ed8aab45SBen Goz  * It contains all the necessary data to handle such queues.
485ed8aab45SBen Goz  *
486ed8aab45SBen Goz  */
487ed8aab45SBen Goz 
488ed8aab45SBen Goz struct queue {
489ed8aab45SBen Goz 	struct list_head list;
490ed8aab45SBen Goz 	void *mqd;
491ed8aab45SBen Goz 	struct kfd_mem_obj *mqd_mem_obj;
492ed8aab45SBen Goz 	uint64_t gart_mqd_addr;
493ed8aab45SBen Goz 	struct queue_properties properties;
494ed8aab45SBen Goz 
495ed8aab45SBen Goz 	uint32_t mec;
496ed8aab45SBen Goz 	uint32_t pipe;
497ed8aab45SBen Goz 	uint32_t queue;
498ed8aab45SBen Goz 
49977669eb8SBen Goz 	unsigned int sdma_id;
500ef568db7SFelix Kuehling 	unsigned int doorbell_id;
50177669eb8SBen Goz 
502ed8aab45SBen Goz 	struct kfd_process	*process;
503ed8aab45SBen Goz 	struct kfd_dev		*device;
504eb82da1dSOak Zeng 	void *gws;
505ed8aab45SBen Goz };
506ed8aab45SBen Goz 
5076e99df57SBen Goz /*
5086e99df57SBen Goz  * Please read the kfd_mqd_manager.h description.
5096e99df57SBen Goz  */
5106e99df57SBen Goz enum KFD_MQD_TYPE {
51185d258f9SBen Goz 	KFD_MQD_TYPE_COMPUTE = 0,	/* for no cp scheduling */
51285d258f9SBen Goz 	KFD_MQD_TYPE_HIQ,		/* for hiq */
51385d258f9SBen Goz 	KFD_MQD_TYPE_CP,		/* for cp queues and diq */
51485d258f9SBen Goz 	KFD_MQD_TYPE_SDMA,		/* for sdma queues */
51559f650a0SOak Zeng 	KFD_MQD_TYPE_DIQ,		/* for diq */
5166e99df57SBen Goz 	KFD_MQD_TYPE_MAX
5176e99df57SBen Goz };
5186e99df57SBen Goz 
5190ccbc7cdSOak Zeng enum KFD_PIPE_PRIORITY {
5200ccbc7cdSOak Zeng 	KFD_PIPE_PRIORITY_CS_LOW = 0,
5210ccbc7cdSOak Zeng 	KFD_PIPE_PRIORITY_CS_MEDIUM,
5220ccbc7cdSOak Zeng 	KFD_PIPE_PRIORITY_CS_HIGH
5230ccbc7cdSOak Zeng };
5240ccbc7cdSOak Zeng 
525241f24f8SBen Goz struct scheduling_resources {
526241f24f8SBen Goz 	unsigned int vmid_mask;
527241f24f8SBen Goz 	enum kfd_queue_type type;
528241f24f8SBen Goz 	uint64_t queue_mask;
529241f24f8SBen Goz 	uint64_t gws_mask;
530241f24f8SBen Goz 	uint32_t oac_mask;
531241f24f8SBen Goz 	uint32_t gds_heap_base;
532241f24f8SBen Goz 	uint32_t gds_heap_size;
533241f24f8SBen Goz };
534241f24f8SBen Goz 
535241f24f8SBen Goz struct process_queue_manager {
536241f24f8SBen Goz 	/* data */
537241f24f8SBen Goz 	struct kfd_process	*process;
538241f24f8SBen Goz 	struct list_head	queues;
539241f24f8SBen Goz 	unsigned long		*queue_slot_bitmap;
540241f24f8SBen Goz };
541241f24f8SBen Goz 
542241f24f8SBen Goz struct qcm_process_device {
543241f24f8SBen Goz 	/* The Device Queue Manager that owns this data */
544241f24f8SBen Goz 	struct device_queue_manager *dqm;
545241f24f8SBen Goz 	struct process_queue_manager *pqm;
546241f24f8SBen Goz 	/* Queues list */
547241f24f8SBen Goz 	struct list_head queues_list;
548241f24f8SBen Goz 	struct list_head priv_queue_list;
549241f24f8SBen Goz 
550241f24f8SBen Goz 	unsigned int queue_count;
551241f24f8SBen Goz 	unsigned int vmid;
552241f24f8SBen Goz 	bool is_debug;
55326103436SFelix Kuehling 	unsigned int evicted; /* eviction counter, 0=active */
5549fd3f1bfSFelix Kuehling 
5559fd3f1bfSFelix Kuehling 	/* This flag tells if we should reset all wavefronts on
5569fd3f1bfSFelix Kuehling 	 * process termination
5579fd3f1bfSFelix Kuehling 	 */
5589fd3f1bfSFelix Kuehling 	bool reset_wavefronts;
5599fd3f1bfSFelix Kuehling 
560241f24f8SBen Goz 	/*
561241f24f8SBen Goz 	 * All the memory management data should be here too
562241f24f8SBen Goz 	 */
563241f24f8SBen Goz 	uint64_t gds_context_area;
564435e2f97SYong Zhao 	/* Contains page table flags such as AMDGPU_PTE_VALID since gfx9 */
565e715c6d0SShaoyun Liu 	uint64_t page_table_base;
566241f24f8SBen Goz 	uint32_t sh_mem_config;
567241f24f8SBen Goz 	uint32_t sh_mem_bases;
568241f24f8SBen Goz 	uint32_t sh_mem_ape1_base;
569241f24f8SBen Goz 	uint32_t sh_mem_ape1_limit;
570241f24f8SBen Goz 	uint32_t gds_size;
571241f24f8SBen Goz 	uint32_t num_gws;
572241f24f8SBen Goz 	uint32_t num_oac;
5736a1c9510SMoses Reuben 	uint32_t sh_hidden_private_base;
574373d7080SFelix Kuehling 
575373d7080SFelix Kuehling 	/* CWSR memory */
576373d7080SFelix Kuehling 	void *cwsr_kaddr;
577d01994c2SFelix Kuehling 	uint64_t cwsr_base;
578373d7080SFelix Kuehling 	uint64_t tba_addr;
579373d7080SFelix Kuehling 	uint64_t tma_addr;
580d01994c2SFelix Kuehling 
581d01994c2SFelix Kuehling 	/* IB memory */
582d01994c2SFelix Kuehling 	uint64_t ib_base;
583552764b6SFelix Kuehling 	void *ib_kaddr;
584ef568db7SFelix Kuehling 
585ef568db7SFelix Kuehling 	/* doorbell resources per process per device */
586ef568db7SFelix Kuehling 	unsigned long *doorbell_bitmap;
587241f24f8SBen Goz };
588241f24f8SBen Goz 
58926103436SFelix Kuehling /* KFD Memory Eviction */
59026103436SFelix Kuehling 
59126103436SFelix Kuehling /* Approx. wait time before attempting to restore evicted BOs */
59226103436SFelix Kuehling #define PROCESS_RESTORE_TIME_MS 100
59326103436SFelix Kuehling /* Approx. back off time if restore fails due to lack of memory */
59426103436SFelix Kuehling #define PROCESS_BACK_OFF_TIME_MS 100
59526103436SFelix Kuehling /* Approx. time before evicting the process again */
59626103436SFelix Kuehling #define PROCESS_ACTIVE_TIME_MS 10
59726103436SFelix Kuehling 
5985ec7e028SFelix Kuehling /* 8 byte handle containing GPU ID in the most significant 4 bytes and
5995ec7e028SFelix Kuehling  * idr_handle in the least significant 4 bytes
6005ec7e028SFelix Kuehling  */
6015ec7e028SFelix Kuehling #define MAKE_HANDLE(gpu_id, idr_handle) \
6025ec7e028SFelix Kuehling 	(((uint64_t)(gpu_id) << 32) + idr_handle)
6035ec7e028SFelix Kuehling #define GET_GPU_ID(handle) (handle >> 32)
6045ec7e028SFelix Kuehling #define GET_IDR_HANDLE(handle) (handle & 0xFFFFFFFF)
6055ec7e028SFelix Kuehling 
606733fa1f7SYong Zhao enum kfd_pdd_bound {
607733fa1f7SYong Zhao 	PDD_UNBOUND = 0,
608733fa1f7SYong Zhao 	PDD_BOUND,
609733fa1f7SYong Zhao 	PDD_BOUND_SUSPENDED,
610733fa1f7SYong Zhao };
611733fa1f7SYong Zhao 
61219f6d2a6SOded Gabbay /* Data that is per-process-per device. */
61319f6d2a6SOded Gabbay struct kfd_process_device {
61419f6d2a6SOded Gabbay 	/*
61519f6d2a6SOded Gabbay 	 * List of all per-device data for a process.
61619f6d2a6SOded Gabbay 	 * Starts from kfd_process.per_device_data.
61719f6d2a6SOded Gabbay 	 */
61819f6d2a6SOded Gabbay 	struct list_head per_device_list;
61919f6d2a6SOded Gabbay 
62019f6d2a6SOded Gabbay 	/* The device that owns this data. */
62119f6d2a6SOded Gabbay 	struct kfd_dev *dev;
62219f6d2a6SOded Gabbay 
6239fd3f1bfSFelix Kuehling 	/* The process that owns this kfd_process_device. */
6249fd3f1bfSFelix Kuehling 	struct kfd_process *process;
62519f6d2a6SOded Gabbay 
62645102048SBen Goz 	/* per-process-per device QCM data structure */
62745102048SBen Goz 	struct qcm_process_device qpd;
62845102048SBen Goz 
62919f6d2a6SOded Gabbay 	/*Apertures*/
63019f6d2a6SOded Gabbay 	uint64_t lds_base;
63119f6d2a6SOded Gabbay 	uint64_t lds_limit;
63219f6d2a6SOded Gabbay 	uint64_t gpuvm_base;
63319f6d2a6SOded Gabbay 	uint64_t gpuvm_limit;
63419f6d2a6SOded Gabbay 	uint64_t scratch_base;
63519f6d2a6SOded Gabbay 	uint64_t scratch_limit;
63619f6d2a6SOded Gabbay 
637403575c4SFelix Kuehling 	/* VM context for GPUVM allocations */
638b84394e2SFelix Kuehling 	struct file *drm_file;
639403575c4SFelix Kuehling 	void *vm;
640403575c4SFelix Kuehling 
64152b29d73SFelix Kuehling 	/* GPUVM allocations storage */
64252b29d73SFelix Kuehling 	struct idr alloc_idr;
64352b29d73SFelix Kuehling 
6449fd3f1bfSFelix Kuehling 	/* Flag used to tell the pdd has dequeued from the dqm.
6459fd3f1bfSFelix Kuehling 	 * This is used to prevent dev->dqm->ops.process_termination() from
6469fd3f1bfSFelix Kuehling 	 * being called twice when it is already called in IOMMU callback
6479fd3f1bfSFelix Kuehling 	 * function.
648a82918f1SBen Goz 	 */
6499fd3f1bfSFelix Kuehling 	bool already_dequeued;
65064d1c3a4SFelix Kuehling 
65164d1c3a4SFelix Kuehling 	/* Is this process/pasid bound to this device? (amd_iommu_bind_pasid) */
65264d1c3a4SFelix Kuehling 	enum kfd_pdd_bound bound;
65319f6d2a6SOded Gabbay };
65419f6d2a6SOded Gabbay 
65552a5fdceSAlexey Skidanov #define qpd_to_pdd(x) container_of(x, struct kfd_process_device, qpd)
65652a5fdceSAlexey Skidanov 
6574a488a7aSOded Gabbay /* Process data */
6584a488a7aSOded Gabbay struct kfd_process {
65919f6d2a6SOded Gabbay 	/*
66019f6d2a6SOded Gabbay 	 * kfd_process are stored in an mm_struct*->kfd_process*
66119f6d2a6SOded Gabbay 	 * hash table (kfd_processes in kfd_process.c)
66219f6d2a6SOded Gabbay 	 */
66319f6d2a6SOded Gabbay 	struct hlist_node kfd_processes;
66419f6d2a6SOded Gabbay 
6659b56bb11SFelix Kuehling 	/*
6669b56bb11SFelix Kuehling 	 * Opaque pointer to mm_struct. We don't hold a reference to
6679b56bb11SFelix Kuehling 	 * it so it should never be dereferenced from here. This is
6689b56bb11SFelix Kuehling 	 * only used for looking up processes by their mm.
6699b56bb11SFelix Kuehling 	 */
6709b56bb11SFelix Kuehling 	void *mm;
67119f6d2a6SOded Gabbay 
6725ce10687SFelix Kuehling 	struct kref ref;
6735ce10687SFelix Kuehling 	struct work_struct release_work;
6745ce10687SFelix Kuehling 
67519f6d2a6SOded Gabbay 	struct mutex mutex;
67619f6d2a6SOded Gabbay 
67719f6d2a6SOded Gabbay 	/*
67819f6d2a6SOded Gabbay 	 * In any process, the thread that started main() is the lead
67919f6d2a6SOded Gabbay 	 * thread and outlives the rest.
68019f6d2a6SOded Gabbay 	 * It is here because amd_iommu_bind_pasid wants a task_struct.
681894a8293SFelix Kuehling 	 * It can also be used for safely getting a reference to the
682894a8293SFelix Kuehling 	 * mm_struct of the process.
68319f6d2a6SOded Gabbay 	 */
68419f6d2a6SOded Gabbay 	struct task_struct *lead_thread;
68519f6d2a6SOded Gabbay 
68619f6d2a6SOded Gabbay 	/* We want to receive a notification when the mm_struct is destroyed */
68719f6d2a6SOded Gabbay 	struct mmu_notifier mmu_notifier;
68819f6d2a6SOded Gabbay 
68919f6d2a6SOded Gabbay 	/* Use for delayed freeing of kfd_process structure */
69019f6d2a6SOded Gabbay 	struct rcu_head	rcu;
69119f6d2a6SOded Gabbay 
69219f6d2a6SOded Gabbay 	unsigned int pasid;
693a91e70e3SFelix Kuehling 	unsigned int doorbell_index;
69419f6d2a6SOded Gabbay 
69519f6d2a6SOded Gabbay 	/*
69619f6d2a6SOded Gabbay 	 * List of kfd_process_device structures,
69719f6d2a6SOded Gabbay 	 * one for each device the process is using.
69819f6d2a6SOded Gabbay 	 */
69919f6d2a6SOded Gabbay 	struct list_head per_device_data;
70019f6d2a6SOded Gabbay 
70145102048SBen Goz 	struct process_queue_manager pqm;
70245102048SBen Goz 
70319f6d2a6SOded Gabbay 	/*Is the user space process 32 bit?*/
70419f6d2a6SOded Gabbay 	bool is_32bit_user_mode;
705f3a39818SAndrew Lewycky 
706f3a39818SAndrew Lewycky 	/* Event-related data */
707f3a39818SAndrew Lewycky 	struct mutex event_mutex;
708482f0777SFelix Kuehling 	/* Event ID allocator and lookup */
709482f0777SFelix Kuehling 	struct idr event_idr;
71050cb7dd9SFelix Kuehling 	/* Event page */
71150cb7dd9SFelix Kuehling 	struct kfd_signal_page *signal_page;
712b9a5d0a5SFelix Kuehling 	size_t signal_mapped_size;
713f3a39818SAndrew Lewycky 	size_t signal_event_count;
714c986169fSFelix Kuehling 	bool signal_event_limit_reached;
715403575c4SFelix Kuehling 
716403575c4SFelix Kuehling 	/* Information used for memory eviction */
717403575c4SFelix Kuehling 	void *kgd_process_info;
718403575c4SFelix Kuehling 	/* Eviction fence that is attached to all the BOs of this process. The
719403575c4SFelix Kuehling 	 * fence will be triggered during eviction and new one will be created
720403575c4SFelix Kuehling 	 * during restore
721403575c4SFelix Kuehling 	 */
722403575c4SFelix Kuehling 	struct dma_fence *ef;
72326103436SFelix Kuehling 
72426103436SFelix Kuehling 	/* Work items for evicting and restoring BOs */
72526103436SFelix Kuehling 	struct delayed_work eviction_work;
72626103436SFelix Kuehling 	struct delayed_work restore_work;
72726103436SFelix Kuehling 	/* seqno of the last scheduled eviction */
72826103436SFelix Kuehling 	unsigned int last_eviction_seqno;
72926103436SFelix Kuehling 	/* Approx. the last timestamp (in jiffies) when the process was
73026103436SFelix Kuehling 	 * restored after an eviction
73126103436SFelix Kuehling 	 */
73226103436SFelix Kuehling 	unsigned long last_restore_timestamp;
733de9f26bbSKent Russell 
734de9f26bbSKent Russell 	/* Kobj for our procfs */
735de9f26bbSKent Russell 	struct kobject *kobj;
736de9f26bbSKent Russell 	struct attribute attr_pasid;
7374a488a7aSOded Gabbay };
7384a488a7aSOded Gabbay 
73964d1c3a4SFelix Kuehling #define KFD_PROCESS_TABLE_SIZE 5 /* bits: 32 entries */
74064d1c3a4SFelix Kuehling extern DECLARE_HASHTABLE(kfd_processes_table, KFD_PROCESS_TABLE_SIZE);
74164d1c3a4SFelix Kuehling extern struct srcu_struct kfd_processes_srcu;
74264d1c3a4SFelix Kuehling 
74376baee6cSOded Gabbay /**
74476baee6cSOded Gabbay  * Ioctl function type.
74576baee6cSOded Gabbay  *
74676baee6cSOded Gabbay  * \param filep pointer to file structure.
74776baee6cSOded Gabbay  * \param p amdkfd process pointer.
74876baee6cSOded Gabbay  * \param data pointer to arg that was copied from user.
74976baee6cSOded Gabbay  */
75076baee6cSOded Gabbay typedef int amdkfd_ioctl_t(struct file *filep, struct kfd_process *p,
75176baee6cSOded Gabbay 				void *data);
75276baee6cSOded Gabbay 
75376baee6cSOded Gabbay struct amdkfd_ioctl_desc {
75476baee6cSOded Gabbay 	unsigned int cmd;
75576baee6cSOded Gabbay 	int flags;
75676baee6cSOded Gabbay 	amdkfd_ioctl_t *func;
75776baee6cSOded Gabbay 	unsigned int cmd_drv;
75876baee6cSOded Gabbay 	const char *name;
75976baee6cSOded Gabbay };
76067f7cf9fSshaoyunl bool kfd_dev_is_large_bar(struct kfd_dev *dev);
76176baee6cSOded Gabbay 
7621679ae8fSFelix Kuehling int kfd_process_create_wq(void);
76319f6d2a6SOded Gabbay void kfd_process_destroy_wq(void);
764373d7080SFelix Kuehling struct kfd_process *kfd_create_process(struct file *filep);
76519f6d2a6SOded Gabbay struct kfd_process *kfd_get_process(const struct task_struct *);
766f3a39818SAndrew Lewycky struct kfd_process *kfd_lookup_process_by_pasid(unsigned int pasid);
76726103436SFelix Kuehling struct kfd_process *kfd_lookup_process_by_mm(const struct mm_struct *mm);
768abb208a8SFelix Kuehling void kfd_unref_process(struct kfd_process *p);
7696b95e797SFelix Kuehling int kfd_process_evict_queues(struct kfd_process *p);
7706b95e797SFelix Kuehling int kfd_process_restore_queues(struct kfd_process *p);
77126103436SFelix Kuehling void kfd_suspend_all_processes(void);
77226103436SFelix Kuehling int kfd_resume_all_processes(void);
77319f6d2a6SOded Gabbay 
774b84394e2SFelix Kuehling int kfd_process_device_init_vm(struct kfd_process_device *pdd,
775b84394e2SFelix Kuehling 			       struct file *drm_file);
77664c7f8cfSBen Goz struct kfd_process_device *kfd_bind_process_to_device(struct kfd_dev *dev,
77764c7f8cfSBen Goz 						struct kfd_process *p);
77819f6d2a6SOded Gabbay struct kfd_process_device *kfd_get_process_device_data(struct kfd_dev *dev,
779093c7d8cSAlexey Skidanov 							struct kfd_process *p);
780093c7d8cSAlexey Skidanov struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev,
781093c7d8cSAlexey Skidanov 							struct kfd_process *p);
78219f6d2a6SOded Gabbay 
783df03ef93SHarish Kasiviswanathan int kfd_reserved_mem_mmap(struct kfd_dev *dev, struct kfd_process *process,
784373d7080SFelix Kuehling 			  struct vm_area_struct *vma);
785373d7080SFelix Kuehling 
78652b29d73SFelix Kuehling /* KFD process API for creating and translating handles */
78752b29d73SFelix Kuehling int kfd_process_device_create_obj_handle(struct kfd_process_device *pdd,
78852b29d73SFelix Kuehling 					void *mem);
78952b29d73SFelix Kuehling void *kfd_process_device_translate_handle(struct kfd_process_device *p,
79052b29d73SFelix Kuehling 					int handle);
79152b29d73SFelix Kuehling void kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd,
79252b29d73SFelix Kuehling 					int handle);
79352b29d73SFelix Kuehling 
794775921edSAlexey Skidanov /* Process device data iterator */
7958eabaf54SKent Russell struct kfd_process_device *kfd_get_first_process_device_data(
7968eabaf54SKent Russell 							struct kfd_process *p);
7978eabaf54SKent Russell struct kfd_process_device *kfd_get_next_process_device_data(
7988eabaf54SKent Russell 						struct kfd_process *p,
799775921edSAlexey Skidanov 						struct kfd_process_device *pdd);
800775921edSAlexey Skidanov bool kfd_has_process_device_data(struct kfd_process *p);
801775921edSAlexey Skidanov 
80219f6d2a6SOded Gabbay /* PASIDs */
80319f6d2a6SOded Gabbay int kfd_pasid_init(void);
80419f6d2a6SOded Gabbay void kfd_pasid_exit(void);
80519f6d2a6SOded Gabbay bool kfd_set_pasid_limit(unsigned int new_limit);
80619f6d2a6SOded Gabbay unsigned int kfd_get_pasid_limit(void);
80719f6d2a6SOded Gabbay unsigned int kfd_pasid_alloc(void);
80819f6d2a6SOded Gabbay void kfd_pasid_free(unsigned int pasid);
80919f6d2a6SOded Gabbay 
81019f6d2a6SOded Gabbay /* Doorbells */
811ef568db7SFelix Kuehling size_t kfd_doorbell_process_slice(struct kfd_dev *kfd);
812735df2baSFelix Kuehling int kfd_doorbell_init(struct kfd_dev *kfd);
813735df2baSFelix Kuehling void kfd_doorbell_fini(struct kfd_dev *kfd);
814df03ef93SHarish Kasiviswanathan int kfd_doorbell_mmap(struct kfd_dev *dev, struct kfd_process *process,
815df03ef93SHarish Kasiviswanathan 		      struct vm_area_struct *vma);
816ada2b29cSFelix Kuehling void __iomem *kfd_get_kernel_doorbell(struct kfd_dev *kfd,
81719f6d2a6SOded Gabbay 					unsigned int *doorbell_off);
81819f6d2a6SOded Gabbay void kfd_release_kernel_doorbell(struct kfd_dev *kfd, u32 __iomem *db_addr);
81919f6d2a6SOded Gabbay u32 read_kernel_doorbell(u32 __iomem *db);
820ada2b29cSFelix Kuehling void write_kernel_doorbell(void __iomem *db, u32 value);
8219d7d0248SFelix Kuehling void write_kernel_doorbell64(void __iomem *db, u64 value);
822ef568db7SFelix Kuehling unsigned int kfd_doorbell_id_to_offset(struct kfd_dev *kfd,
82319f6d2a6SOded Gabbay 					struct kfd_process *process,
824ef568db7SFelix Kuehling 					unsigned int doorbell_id);
825a91e70e3SFelix Kuehling phys_addr_t kfd_get_process_doorbells(struct kfd_dev *dev,
826a91e70e3SFelix Kuehling 					struct kfd_process *process);
827a91e70e3SFelix Kuehling int kfd_alloc_process_doorbells(struct kfd_process *process);
828a91e70e3SFelix Kuehling void kfd_free_process_doorbells(struct kfd_process *process);
82919f6d2a6SOded Gabbay 
8306e81090bSOded Gabbay /* GTT Sub-Allocator */
8316e81090bSOded Gabbay 
8326e81090bSOded Gabbay int kfd_gtt_sa_allocate(struct kfd_dev *kfd, unsigned int size,
8336e81090bSOded Gabbay 			struct kfd_mem_obj **mem_obj);
8346e81090bSOded Gabbay 
8356e81090bSOded Gabbay int kfd_gtt_sa_free(struct kfd_dev *kfd, struct kfd_mem_obj *mem_obj);
8366e81090bSOded Gabbay 
8374a488a7aSOded Gabbay extern struct device *kfd_device;
8384a488a7aSOded Gabbay 
839de9f26bbSKent Russell /* KFD's procfs */
840de9f26bbSKent Russell void kfd_procfs_init(void);
841de9f26bbSKent Russell void kfd_procfs_shutdown(void);
842de9f26bbSKent Russell 
8435b5c4e40SEvgeny Pinchuk /* Topology */
8445b5c4e40SEvgeny Pinchuk int kfd_topology_init(void);
8455b5c4e40SEvgeny Pinchuk void kfd_topology_shutdown(void);
8465b5c4e40SEvgeny Pinchuk int kfd_topology_add_device(struct kfd_dev *gpu);
8475b5c4e40SEvgeny Pinchuk int kfd_topology_remove_device(struct kfd_dev *gpu);
8483a87177eSHarish Kasiviswanathan struct kfd_topology_device *kfd_topology_device_by_proximity_domain(
8493a87177eSHarish Kasiviswanathan 						uint32_t proximity_domain);
85044d8cc6fSYong Zhao struct kfd_topology_device *kfd_topology_device_by_id(uint32_t gpu_id);
8515b5c4e40SEvgeny Pinchuk struct kfd_dev *kfd_device_by_id(uint32_t gpu_id);
8525b5c4e40SEvgeny Pinchuk struct kfd_dev *kfd_device_by_pci_dev(const struct pci_dev *pdev);
8531dde0ea9SFelix Kuehling struct kfd_dev *kfd_device_by_kgd(const struct kgd_dev *kgd);
8546d82eb0eSHarish Kasiviswanathan int kfd_topology_enum_kfd_devices(uint8_t idx, struct kfd_dev **kdev);
855520b8fb7SFelix Kuehling int kfd_numa_node_to_apic_id(int numa_node_id);
8565b5c4e40SEvgeny Pinchuk 
8574a488a7aSOded Gabbay /* Interrupts */
8582249d558SAndrew Lewycky int kfd_interrupt_init(struct kfd_dev *dev);
8592249d558SAndrew Lewycky void kfd_interrupt_exit(struct kfd_dev *dev);
8602249d558SAndrew Lewycky bool enqueue_ih_ring_entry(struct kfd_dev *kfd,	const void *ih_ring_entry);
86158e69886SLan Xiao bool interrupt_is_wanted(struct kfd_dev *dev,
86258e69886SLan Xiao 				const uint32_t *ih_ring_entry,
86358e69886SLan Xiao 				uint32_t *patched_ihre, bool *flag);
8644a488a7aSOded Gabbay 
86519f6d2a6SOded Gabbay /* amdkfd Apertures */
86619f6d2a6SOded Gabbay int kfd_init_apertures(struct kfd_process *process);
86719f6d2a6SOded Gabbay 
868ed6e6a34SBen Goz /* Queue Context Management */
869e88a614cSEdward O'Callaghan int init_queue(struct queue **q, const struct queue_properties *properties);
870ed6e6a34SBen Goz void uninit_queue(struct queue *q);
87145102048SBen Goz void print_queue_properties(struct queue_properties *q);
872ed6e6a34SBen Goz void print_queue(struct queue *q);
873ed6e6a34SBen Goz 
8744b8f589bSBen Goz struct mqd_manager *mqd_manager_init_cik(enum KFD_MQD_TYPE type,
8754b8f589bSBen Goz 		struct kfd_dev *dev);
876ee04955aSFelix Kuehling struct mqd_manager *mqd_manager_init_cik_hawaii(enum KFD_MQD_TYPE type,
877ee04955aSFelix Kuehling 		struct kfd_dev *dev);
8784b8f589bSBen Goz struct mqd_manager *mqd_manager_init_vi(enum KFD_MQD_TYPE type,
8794b8f589bSBen Goz 		struct kfd_dev *dev);
880ee04955aSFelix Kuehling struct mqd_manager *mqd_manager_init_vi_tonga(enum KFD_MQD_TYPE type,
881ee04955aSFelix Kuehling 		struct kfd_dev *dev);
882b91d43ddSFelix Kuehling struct mqd_manager *mqd_manager_init_v9(enum KFD_MQD_TYPE type,
883b91d43ddSFelix Kuehling 		struct kfd_dev *dev);
88414328aa5SPhilip Cox struct mqd_manager *mqd_manager_init_v10(enum KFD_MQD_TYPE type,
88514328aa5SPhilip Cox 		struct kfd_dev *dev);
88664c7f8cfSBen Goz struct device_queue_manager *device_queue_manager_init(struct kfd_dev *dev);
88764c7f8cfSBen Goz void device_queue_manager_uninit(struct device_queue_manager *dqm);
888241f24f8SBen Goz struct kernel_queue *kernel_queue_init(struct kfd_dev *dev,
889241f24f8SBen Goz 					enum kfd_queue_type type);
890241f24f8SBen Goz void kernel_queue_uninit(struct kernel_queue *kq);
8912640c3faSshaoyunl int kfd_process_vm_fault(struct device_queue_manager *dqm, unsigned int pasid);
892241f24f8SBen Goz 
89345102048SBen Goz /* Process Queue Manager */
89445102048SBen Goz struct process_queue_node {
89545102048SBen Goz 	struct queue *q;
89645102048SBen Goz 	struct kernel_queue *kq;
89745102048SBen Goz 	struct list_head process_queue_list;
89845102048SBen Goz };
89945102048SBen Goz 
9009fd3f1bfSFelix Kuehling void kfd_process_dequeue_from_device(struct kfd_process_device *pdd);
9019fd3f1bfSFelix Kuehling void kfd_process_dequeue_from_all_devices(struct kfd_process *p);
90245102048SBen Goz int pqm_init(struct process_queue_manager *pqm, struct kfd_process *p);
90345102048SBen Goz void pqm_uninit(struct process_queue_manager *pqm);
90445102048SBen Goz int pqm_create_queue(struct process_queue_manager *pqm,
90545102048SBen Goz 			    struct kfd_dev *dev,
90645102048SBen Goz 			    struct file *f,
90745102048SBen Goz 			    struct queue_properties *properties,
90845102048SBen Goz 			    unsigned int *qid);
90945102048SBen Goz int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid);
91045102048SBen Goz int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid,
91145102048SBen Goz 			struct queue_properties *p);
91239e7f331SFelix Kuehling int pqm_set_cu_mask(struct process_queue_manager *pqm, unsigned int qid,
91339e7f331SFelix Kuehling 			struct queue_properties *p);
914eb82da1dSOak Zeng int pqm_set_gws(struct process_queue_manager *pqm, unsigned int qid,
915eb82da1dSOak Zeng 			void *gws);
916fbeb661bSYair Shachar struct kernel_queue *pqm_get_kernel_queue(struct process_queue_manager *pqm,
917fbeb661bSYair Shachar 						unsigned int qid);
9185df099e8SJay Cornwall int pqm_get_wave_state(struct process_queue_manager *pqm,
9195df099e8SJay Cornwall 		       unsigned int qid,
9205df099e8SJay Cornwall 		       void __user *ctl_stack,
9215df099e8SJay Cornwall 		       u32 *ctl_stack_used_size,
9225df099e8SJay Cornwall 		       u32 *save_area_used_size);
92345102048SBen Goz 
924788bf83dSYair Shachar int amdkfd_fence_wait_timeout(unsigned int *fence_addr,
925788bf83dSYair Shachar 			      unsigned int fence_value,
9268c72c3d7SYong Zhao 			      unsigned int timeout_ms);
927788bf83dSYair Shachar 
928ed6e6a34SBen Goz /* Packet Manager */
929ed6e6a34SBen Goz 
93064c7f8cfSBen Goz #define KFD_FENCE_COMPLETED (100)
93164c7f8cfSBen Goz #define KFD_FENCE_INIT   (10)
932241f24f8SBen Goz 
933ed6e6a34SBen Goz struct packet_manager {
934ed6e6a34SBen Goz 	struct device_queue_manager *dqm;
935ed6e6a34SBen Goz 	struct kernel_queue *priv_queue;
936ed6e6a34SBen Goz 	struct mutex lock;
937ed6e6a34SBen Goz 	bool allocated;
938ed6e6a34SBen Goz 	struct kfd_mem_obj *ib_buffer_obj;
939851a645eSFelix Kuehling 	unsigned int ib_size_bytes;
940819ec5acSFelix Kuehling 	bool is_over_subscription;
941f6e27ff1SFelix Kuehling 
942f6e27ff1SFelix Kuehling 	const struct packet_manager_funcs *pmf;
943ed6e6a34SBen Goz };
944ed6e6a34SBen Goz 
945f6e27ff1SFelix Kuehling struct packet_manager_funcs {
946f6e27ff1SFelix Kuehling 	/* Support ASIC-specific packet formats for PM4 packets */
947f6e27ff1SFelix Kuehling 	int (*map_process)(struct packet_manager *pm, uint32_t *buffer,
948f6e27ff1SFelix Kuehling 			struct qcm_process_device *qpd);
949f6e27ff1SFelix Kuehling 	int (*runlist)(struct packet_manager *pm, uint32_t *buffer,
950f6e27ff1SFelix Kuehling 			uint64_t ib, size_t ib_size_in_dwords, bool chain);
951f6e27ff1SFelix Kuehling 	int (*set_resources)(struct packet_manager *pm, uint32_t *buffer,
952f6e27ff1SFelix Kuehling 			struct scheduling_resources *res);
953f6e27ff1SFelix Kuehling 	int (*map_queues)(struct packet_manager *pm, uint32_t *buffer,
954f6e27ff1SFelix Kuehling 			struct queue *q, bool is_static);
955f6e27ff1SFelix Kuehling 	int (*unmap_queues)(struct packet_manager *pm, uint32_t *buffer,
956f6e27ff1SFelix Kuehling 			enum kfd_queue_type type,
957f6e27ff1SFelix Kuehling 			enum kfd_unmap_queues_filter mode,
958f6e27ff1SFelix Kuehling 			uint32_t filter_param, bool reset,
959f6e27ff1SFelix Kuehling 			unsigned int sdma_engine);
960f6e27ff1SFelix Kuehling 	int (*query_status)(struct packet_manager *pm, uint32_t *buffer,
961f6e27ff1SFelix Kuehling 			uint64_t fence_address,	uint32_t fence_value);
962f6e27ff1SFelix Kuehling 	int (*release_mem)(uint64_t gpu_addr, uint32_t *buffer);
963f6e27ff1SFelix Kuehling 
964f6e27ff1SFelix Kuehling 	/* Packet sizes */
965f6e27ff1SFelix Kuehling 	int map_process_size;
966f6e27ff1SFelix Kuehling 	int runlist_size;
967f6e27ff1SFelix Kuehling 	int set_resources_size;
968f6e27ff1SFelix Kuehling 	int map_queues_size;
969f6e27ff1SFelix Kuehling 	int unmap_queues_size;
970f6e27ff1SFelix Kuehling 	int query_status_size;
971f6e27ff1SFelix Kuehling 	int release_mem_size;
972f6e27ff1SFelix Kuehling };
973f6e27ff1SFelix Kuehling 
974f6e27ff1SFelix Kuehling extern const struct packet_manager_funcs kfd_vi_pm_funcs;
975454150b1SFelix Kuehling extern const struct packet_manager_funcs kfd_v9_pm_funcs;
97614328aa5SPhilip Cox extern const struct packet_manager_funcs kfd_v10_pm_funcs;
977f6e27ff1SFelix Kuehling 
97864c7f8cfSBen Goz int pm_init(struct packet_manager *pm, struct device_queue_manager *dqm);
97964c7f8cfSBen Goz void pm_uninit(struct packet_manager *pm);
98064c7f8cfSBen Goz int pm_send_set_resources(struct packet_manager *pm,
98164c7f8cfSBen Goz 				struct scheduling_resources *res);
98264c7f8cfSBen Goz int pm_send_runlist(struct packet_manager *pm, struct list_head *dqm_queues);
98364c7f8cfSBen Goz int pm_send_query_status(struct packet_manager *pm, uint64_t fence_address,
98464c7f8cfSBen Goz 				uint32_t fence_value);
98564c7f8cfSBen Goz 
98664c7f8cfSBen Goz int pm_send_unmap_queue(struct packet_manager *pm, enum kfd_queue_type type,
9877da2bcf8SYong Zhao 			enum kfd_unmap_queues_filter mode,
98864c7f8cfSBen Goz 			uint32_t filter_param, bool reset,
98964c7f8cfSBen Goz 			unsigned int sdma_engine);
99064c7f8cfSBen Goz 
991241f24f8SBen Goz void pm_release_ib(struct packet_manager *pm);
992241f24f8SBen Goz 
993454150b1SFelix Kuehling /* Following PM funcs can be shared among VI and AI */
994454150b1SFelix Kuehling unsigned int pm_build_pm4_header(unsigned int opcode, size_t packet_size);
995454150b1SFelix Kuehling int pm_set_resources_vi(struct packet_manager *pm, uint32_t *buffer,
996454150b1SFelix Kuehling 			struct scheduling_resources *res);
997454150b1SFelix Kuehling 
99814328aa5SPhilip Cox 
99919f6d2a6SOded Gabbay uint64_t kfd_get_number_elems(struct kfd_dev *kfd);
100019f6d2a6SOded Gabbay 
1001f3a39818SAndrew Lewycky /* Events */
1002f3a39818SAndrew Lewycky extern const struct kfd_event_interrupt_class event_interrupt_class_cik;
1003ca750681SFelix Kuehling extern const struct kfd_event_interrupt_class event_interrupt_class_v9;
1004ca750681SFelix Kuehling 
1005930c5ff4SAlexey Skidanov extern const struct kfd_device_global_init_class device_global_init_class_cik;
1006f3a39818SAndrew Lewycky 
1007f3a39818SAndrew Lewycky void kfd_event_init_process(struct kfd_process *p);
1008f3a39818SAndrew Lewycky void kfd_event_free_process(struct kfd_process *p);
1009f3a39818SAndrew Lewycky int kfd_event_mmap(struct kfd_process *process, struct vm_area_struct *vma);
1010f3a39818SAndrew Lewycky int kfd_wait_on_events(struct kfd_process *p,
101159d3e8beSAlexey Skidanov 		       uint32_t num_events, void __user *data,
1012f3a39818SAndrew Lewycky 		       bool all, uint32_t user_timeout_ms,
1013fdf0c833SFelix Kuehling 		       uint32_t *wait_result);
1014f3a39818SAndrew Lewycky void kfd_signal_event_interrupt(unsigned int pasid, uint32_t partial_id,
1015f3a39818SAndrew Lewycky 				uint32_t valid_id_bits);
101659d3e8beSAlexey Skidanov void kfd_signal_iommu_event(struct kfd_dev *dev,
101759d3e8beSAlexey Skidanov 		unsigned int pasid, unsigned long address,
101859d3e8beSAlexey Skidanov 		bool is_write_requested, bool is_execute_requested);
1019930c5ff4SAlexey Skidanov void kfd_signal_hw_exception_event(unsigned int pasid);
1020f3a39818SAndrew Lewycky int kfd_set_event(struct kfd_process *p, uint32_t event_id);
1021f3a39818SAndrew Lewycky int kfd_reset_event(struct kfd_process *p, uint32_t event_id);
10220fc8011fSFelix Kuehling int kfd_event_page_set(struct kfd_process *p, void *kernel_address,
10230fc8011fSFelix Kuehling 		       uint64_t size);
1024f3a39818SAndrew Lewycky int kfd_event_create(struct file *devkfd, struct kfd_process *p,
1025f3a39818SAndrew Lewycky 		     uint32_t event_type, bool auto_reset, uint32_t node_id,
1026f3a39818SAndrew Lewycky 		     uint32_t *event_id, uint32_t *event_trigger_data,
1027f3a39818SAndrew Lewycky 		     uint64_t *event_page_offset, uint32_t *event_slot_index);
1028f3a39818SAndrew Lewycky int kfd_event_destroy(struct kfd_process *p, uint32_t event_id);
1029f3a39818SAndrew Lewycky 
10302640c3faSshaoyunl void kfd_signal_vm_fault_event(struct kfd_dev *dev, unsigned int pasid,
10312640c3faSshaoyunl 				struct kfd_vm_fault_info *info);
10322640c3faSshaoyunl 
1033e42051d2SShaoyun Liu void kfd_signal_reset_event(struct kfd_dev *dev);
1034e42051d2SShaoyun Liu 
1035403575c4SFelix Kuehling void kfd_flush_tlb(struct kfd_process_device *pdd);
1036403575c4SFelix Kuehling 
1037c3447e81SBen Goz int dbgdev_wave_reset_wavefronts(struct kfd_dev *dev, struct kfd_process *p);
1038c3447e81SBen Goz 
1039e42051d2SShaoyun Liu bool kfd_is_locked(void);
1040e42051d2SShaoyun Liu 
1041f756e631SHarish Kasiviswanathan /* Compute profile */
1042f756e631SHarish Kasiviswanathan void kfd_inc_compute_active(struct kfd_dev *dev);
1043f756e631SHarish Kasiviswanathan void kfd_dec_compute_active(struct kfd_dev *dev);
1044f756e631SHarish Kasiviswanathan 
1045851a645eSFelix Kuehling /* Debugfs */
1046851a645eSFelix Kuehling #if defined(CONFIG_DEBUG_FS)
1047851a645eSFelix Kuehling 
1048851a645eSFelix Kuehling void kfd_debugfs_init(void);
1049851a645eSFelix Kuehling void kfd_debugfs_fini(void);
1050851a645eSFelix Kuehling int kfd_debugfs_mqds_by_process(struct seq_file *m, void *data);
1051851a645eSFelix Kuehling int pqm_debugfs_mqds(struct seq_file *m, void *data);
1052851a645eSFelix Kuehling int kfd_debugfs_hqds_by_device(struct seq_file *m, void *data);
1053851a645eSFelix Kuehling int dqm_debugfs_hqds(struct seq_file *m, void *data);
1054851a645eSFelix Kuehling int kfd_debugfs_rls_by_device(struct seq_file *m, void *data);
1055851a645eSFelix Kuehling int pm_debugfs_runlist(struct seq_file *m, void *data);
1056851a645eSFelix Kuehling 
1057a29ec470SShaoyun Liu int kfd_debugfs_hang_hws(struct kfd_dev *dev);
1058a29ec470SShaoyun Liu int pm_debugfs_hang_hws(struct packet_manager *pm);
1059a29ec470SShaoyun Liu int dqm_debugfs_execute_queues(struct device_queue_manager *dqm);
1060a29ec470SShaoyun Liu 
1061851a645eSFelix Kuehling #else
1062851a645eSFelix Kuehling 
1063851a645eSFelix Kuehling static inline void kfd_debugfs_init(void) {}
1064851a645eSFelix Kuehling static inline void kfd_debugfs_fini(void) {}
1065851a645eSFelix Kuehling 
1066851a645eSFelix Kuehling #endif
1067851a645eSFelix Kuehling 
10684a488a7aSOded Gabbay #endif
1069