blob: d1bab32622df70b113100b89669df56c1cb5821e [file] [log] [blame]
Oded Gabbay130e0372015-06-12 21:35:14 +03001/*
2 * Copyright 2014 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23/* amdgpu_amdkfd.h defines the private interface between amdgpu and amdkfd. */
24
25#ifndef AMDGPU_AMDKFD_H_INCLUDED
26#define AMDGPU_AMDKFD_H_INCLUDED
27
28#include <linux/types.h>
Felix Kuehling70539bd2017-08-15 23:00:17 -040029#include <linux/mmu_context.h>
Oded Gabbay130e0372015-06-12 21:35:14 +030030#include <kgd_kfd_interface.h>
31
Felix Kuehlingd8d019c2018-02-06 20:32:35 -050032extern const struct kgd2kfd_calls *kgd2kfd;
33
Oded Gabbay130e0372015-06-12 21:35:14 +030034struct amdgpu_device;
35
36struct kgd_mem {
37 struct amdgpu_bo *bo;
38 uint64_t gpu_addr;
39 void *cpu_ptr;
40};
41
Felix Kuehlingd8d019c2018-02-06 20:32:35 -050042/* KFD Memory Eviction */
43struct amdgpu_amdkfd_fence {
44 struct dma_fence base;
45 struct mm_struct *mm;
46 spinlock_t lock;
47 char timeline_name[TASK_COMM_LEN];
48};
49
50struct amdgpu_amdkfd_fence *amdgpu_amdkfd_fence_create(u64 context,
51 struct mm_struct *mm);
52bool amdkfd_fence_check_mm(struct dma_fence *f, struct mm_struct *mm);
53struct amdgpu_amdkfd_fence *to_amdgpu_amdkfd_fence(struct dma_fence *f);
54
Oded Gabbayefb1c652016-02-09 13:30:12 +020055int amdgpu_amdkfd_init(void);
Oded Gabbay130e0372015-06-12 21:35:14 +030056void amdgpu_amdkfd_fini(void);
57
Andres Rodriguezdc102c42017-02-01 17:02:13 -050058void amdgpu_amdkfd_suspend(struct amdgpu_device *adev);
59int amdgpu_amdkfd_resume(struct amdgpu_device *adev);
60void amdgpu_amdkfd_interrupt(struct amdgpu_device *adev,
Oded Gabbay130e0372015-06-12 21:35:14 +030061 const void *ih_ring_entry);
Andres Rodriguezdc102c42017-02-01 17:02:13 -050062void amdgpu_amdkfd_device_probe(struct amdgpu_device *adev);
63void amdgpu_amdkfd_device_init(struct amdgpu_device *adev);
64void amdgpu_amdkfd_device_fini(struct amdgpu_device *adev);
Oded Gabbay130e0372015-06-12 21:35:14 +030065
66struct kfd2kgd_calls *amdgpu_amdkfd_gfx_7_get_functions(void);
Ben Gozff758a12014-10-07 14:43:07 +030067struct kfd2kgd_calls *amdgpu_amdkfd_gfx_8_0_get_functions(void);
Oded Gabbay130e0372015-06-12 21:35:14 +030068
Felix Kuehling155494d2018-02-06 20:32:36 -050069bool amdgpu_amdkfd_is_kfd_vmid(struct amdgpu_device *adev, u32 vmid);
70
Oded Gabbay130e0372015-06-12 21:35:14 +030071/* Shared API */
72int alloc_gtt_mem(struct kgd_dev *kgd, size_t size,
73 void **mem_obj, uint64_t *gpu_addr,
74 void **cpu_ptr);
75void free_gtt_mem(struct kgd_dev *kgd, void *mem_obj);
Harish Kasiviswanathan30f1c042017-12-08 23:08:42 -050076void get_local_mem_info(struct kgd_dev *kgd,
77 struct kfd_local_mem_info *mem_info);
Oded Gabbay130e0372015-06-12 21:35:14 +030078uint64_t get_gpu_clock_counter(struct kgd_dev *kgd);
79
80uint32_t get_max_engine_clock_in_mhz(struct kgd_dev *kgd);
Flora Cuiebdebf42017-12-08 23:08:40 -050081void get_cu_info(struct kgd_dev *kgd, struct kfd_cu_info *cu_info);
Kent Russell9f0a0b42017-12-08 23:09:05 -050082uint64_t amdgpu_amdkfd_get_vram_usage(struct kgd_dev *kgd);
Oded Gabbay130e0372015-06-12 21:35:14 +030083
Felix Kuehling70539bd2017-08-15 23:00:17 -040084#define read_user_wptr(mmptr, wptr, dst) \
85 ({ \
86 bool valid = false; \
87 if ((mmptr) && (wptr)) { \
88 if ((mmptr) == current->mm) { \
89 valid = !get_user((dst), (wptr)); \
90 } else if (current->mm == NULL) { \
91 use_mm(mmptr); \
92 valid = !get_user((dst), (wptr)); \
93 unuse_mm(mmptr); \
94 } \
95 } \
96 valid; \
97 })
98
Oded Gabbay130e0372015-06-12 21:35:14 +030099#endif /* AMDGPU_AMDKFD_H_INCLUDED */