xref: /linux/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h (revision 30f1c0421ec5f47ab4375eb0fc34e64f79fb0a25)
1130e0371SOded Gabbay /*
2130e0371SOded Gabbay  * Copyright 2014 Advanced Micro Devices, Inc.
3130e0371SOded Gabbay  *
4130e0371SOded Gabbay  * Permission is hereby granted, free of charge, to any person obtaining a
5130e0371SOded Gabbay  * copy of this software and associated documentation files (the "Software"),
6130e0371SOded Gabbay  * to deal in the Software without restriction, including without limitation
7130e0371SOded Gabbay  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8130e0371SOded Gabbay  * and/or sell copies of the Software, and to permit persons to whom the
9130e0371SOded Gabbay  * Software is furnished to do so, subject to the following conditions:
10130e0371SOded Gabbay  *
11130e0371SOded Gabbay  * The above copyright notice and this permission notice shall be included in
12130e0371SOded Gabbay  * all copies or substantial portions of the Software.
13130e0371SOded Gabbay  *
14130e0371SOded Gabbay  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15130e0371SOded Gabbay  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16130e0371SOded Gabbay  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17130e0371SOded Gabbay  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18130e0371SOded Gabbay  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19130e0371SOded Gabbay  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20130e0371SOded Gabbay  * OTHER DEALINGS IN THE SOFTWARE.
21130e0371SOded Gabbay  */
22130e0371SOded Gabbay 
23130e0371SOded Gabbay /* amdgpu_amdkfd.h defines the private interface between amdgpu and amdkfd. */
24130e0371SOded Gabbay 
25130e0371SOded Gabbay #ifndef AMDGPU_AMDKFD_H_INCLUDED
26130e0371SOded Gabbay #define AMDGPU_AMDKFD_H_INCLUDED
27130e0371SOded Gabbay 
28130e0371SOded Gabbay #include <linux/types.h>
2970539bd7SFelix Kuehling #include <linux/mmu_context.h>
30130e0371SOded Gabbay #include <kgd_kfd_interface.h>
31130e0371SOded Gabbay 
32130e0371SOded Gabbay struct amdgpu_device;
33130e0371SOded Gabbay 
34130e0371SOded Gabbay struct kgd_mem {
35130e0371SOded Gabbay 	struct amdgpu_bo *bo;
36130e0371SOded Gabbay 	uint64_t gpu_addr;
37130e0371SOded Gabbay 	void *cpu_ptr;
38130e0371SOded Gabbay };
39130e0371SOded Gabbay 
40efb1c658SOded Gabbay int amdgpu_amdkfd_init(void);
41130e0371SOded Gabbay void amdgpu_amdkfd_fini(void);
42130e0371SOded Gabbay 
43dc102c43SAndres Rodriguez void amdgpu_amdkfd_suspend(struct amdgpu_device *adev);
44dc102c43SAndres Rodriguez int amdgpu_amdkfd_resume(struct amdgpu_device *adev);
45dc102c43SAndres Rodriguez void amdgpu_amdkfd_interrupt(struct amdgpu_device *adev,
46130e0371SOded Gabbay 			const void *ih_ring_entry);
47dc102c43SAndres Rodriguez void amdgpu_amdkfd_device_probe(struct amdgpu_device *adev);
48dc102c43SAndres Rodriguez void amdgpu_amdkfd_device_init(struct amdgpu_device *adev);
49dc102c43SAndres Rodriguez void amdgpu_amdkfd_device_fini(struct amdgpu_device *adev);
50130e0371SOded Gabbay 
51130e0371SOded Gabbay struct kfd2kgd_calls *amdgpu_amdkfd_gfx_7_get_functions(void);
52ff758a12SBen Goz struct kfd2kgd_calls *amdgpu_amdkfd_gfx_8_0_get_functions(void);
53130e0371SOded Gabbay 
54130e0371SOded Gabbay /* Shared API */
55130e0371SOded Gabbay int alloc_gtt_mem(struct kgd_dev *kgd, size_t size,
56130e0371SOded Gabbay 			void **mem_obj, uint64_t *gpu_addr,
57130e0371SOded Gabbay 			void **cpu_ptr);
58130e0371SOded Gabbay void free_gtt_mem(struct kgd_dev *kgd, void *mem_obj);
59130e0371SOded Gabbay uint64_t get_vmem_size(struct kgd_dev *kgd);
60*30f1c042SHarish Kasiviswanathan void get_local_mem_info(struct kgd_dev *kgd,
61*30f1c042SHarish Kasiviswanathan 			struct kfd_local_mem_info *mem_info);
62130e0371SOded Gabbay uint64_t get_gpu_clock_counter(struct kgd_dev *kgd);
63130e0371SOded Gabbay 
64130e0371SOded Gabbay uint32_t get_max_engine_clock_in_mhz(struct kgd_dev *kgd);
65ebdebf42SFlora Cui void get_cu_info(struct kgd_dev *kgd, struct kfd_cu_info *cu_info);
66130e0371SOded Gabbay 
6770539bd7SFelix Kuehling #define read_user_wptr(mmptr, wptr, dst)				\
6870539bd7SFelix Kuehling 	({								\
6970539bd7SFelix Kuehling 		bool valid = false;					\
7070539bd7SFelix Kuehling 		if ((mmptr) && (wptr)) {				\
7170539bd7SFelix Kuehling 			if ((mmptr) == current->mm) {			\
7270539bd7SFelix Kuehling 				valid = !get_user((dst), (wptr));	\
7370539bd7SFelix Kuehling 			} else if (current->mm == NULL) {		\
7470539bd7SFelix Kuehling 				use_mm(mmptr);				\
7570539bd7SFelix Kuehling 				valid = !get_user((dst), (wptr));	\
7670539bd7SFelix Kuehling 				unuse_mm(mmptr);			\
7770539bd7SFelix Kuehling 			}						\
7870539bd7SFelix Kuehling 		}							\
7970539bd7SFelix Kuehling 		valid;							\
8070539bd7SFelix Kuehling 	})
8170539bd7SFelix Kuehling 
82130e0371SOded Gabbay #endif /* AMDGPU_AMDKFD_H_INCLUDED */
83