blob: 60fc4413449bdd012a3a2130d4d2da01db9d1742 [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#include "amdgpu_amdkfd.h"
Jammy Zhou2f7d10b2015-07-22 11:29:01 +080024#include "amd_shared.h"
Oded Gabbay130e0372015-06-12 21:35:14 +030025#include <drm/drmP.h>
26#include "amdgpu.h"
Alex Deucher2db0cdb2017-06-07 12:59:29 -040027#include "amdgpu_gfx.h"
Oded Gabbay130e0372015-06-12 21:35:14 +030028#include <linux/module.h>
29
Oded Gabbay130e0372015-06-12 21:35:14 +030030const struct kgd2kfd_calls *kgd2kfd;
Kent Russell8eabaf52017-08-15 23:00:04 -040031bool (*kgd2kfd_init_p)(unsigned int, const struct kgd2kfd_calls**);
Oded Gabbay130e0372015-06-12 21:35:14 +030032
Felix Kuehling155494d2018-02-06 20:32:36 -050033static const unsigned int compute_vmid_bitmap = 0xFF00;
34
Oded Gabbayefb1c652016-02-09 13:30:12 +020035int amdgpu_amdkfd_init(void)
Oded Gabbay130e0372015-06-12 21:35:14 +030036{
Oded Gabbayefb1c652016-02-09 13:30:12 +020037 int ret;
38
Oded Gabbay130e0372015-06-12 21:35:14 +030039#if defined(CONFIG_HSA_AMD_MODULE)
Kent Russell8eabaf52017-08-15 23:00:04 -040040 int (*kgd2kfd_init_p)(unsigned int, const struct kgd2kfd_calls**);
Oded Gabbay130e0372015-06-12 21:35:14 +030041
42 kgd2kfd_init_p = symbol_request(kgd2kfd_init);
43
44 if (kgd2kfd_init_p == NULL)
Oded Gabbayefb1c652016-02-09 13:30:12 +020045 return -ENOENT;
46
47 ret = kgd2kfd_init_p(KFD_INTERFACE_VERSION, &kgd2kfd);
48 if (ret) {
49 symbol_put(kgd2kfd_init);
50 kgd2kfd = NULL;
51 }
52
53#elif defined(CONFIG_HSA_AMD)
54 ret = kgd2kfd_init(KFD_INTERFACE_VERSION, &kgd2kfd);
55 if (ret)
56 kgd2kfd = NULL;
57
58#else
59 ret = -ENOENT;
Oded Gabbay130e0372015-06-12 21:35:14 +030060#endif
Felix Kuehlinga46a2cd2018-02-06 20:32:38 -050061 amdgpu_amdkfd_gpuvm_init_mem_limits();
Oded Gabbayefb1c652016-02-09 13:30:12 +020062
63 return ret;
Oded Gabbay130e0372015-06-12 21:35:14 +030064}
65
Oded Gabbay130e0372015-06-12 21:35:14 +030066void amdgpu_amdkfd_fini(void)
67{
68 if (kgd2kfd) {
69 kgd2kfd->exit();
70 symbol_put(kgd2kfd_init);
71 }
72}
73
Andres Rodriguezdc102c42017-02-01 17:02:13 -050074void amdgpu_amdkfd_device_probe(struct amdgpu_device *adev)
Oded Gabbay130e0372015-06-12 21:35:14 +030075{
Felix Kuehling5c33f212017-07-28 16:54:54 -040076 const struct kfd2kgd_calls *kfd2kgd;
77
78 if (!kgd2kfd)
79 return;
80
81 switch (adev->asic_type) {
82#ifdef CONFIG_DRM_AMDGPU_CIK
83 case CHIP_KAVERI:
Felix Kuehling30d13422018-01-04 17:17:48 -050084 case CHIP_HAWAII:
Felix Kuehling5c33f212017-07-28 16:54:54 -040085 kfd2kgd = amdgpu_amdkfd_gfx_7_get_functions();
86 break;
87#endif
88 case CHIP_CARRIZO:
Felix Kuehling30d13422018-01-04 17:17:48 -050089 case CHIP_TONGA:
90 case CHIP_FIJI:
91 case CHIP_POLARIS10:
92 case CHIP_POLARIS11:
Felix Kuehling5c33f212017-07-28 16:54:54 -040093 kfd2kgd = amdgpu_amdkfd_gfx_8_0_get_functions();
94 break;
Felix Kuehlingd5a114a2018-04-10 17:33:01 -040095 case CHIP_VEGA10:
96 case CHIP_RAVEN:
97 kfd2kgd = amdgpu_amdkfd_gfx_9_0_get_functions();
98 break;
Felix Kuehling5c33f212017-07-28 16:54:54 -040099 default:
pding9953b722017-10-26 09:30:38 +0800100 dev_dbg(adev->dev, "kfd not supported on this ASIC\n");
Felix Kuehling5c33f212017-07-28 16:54:54 -0400101 return;
102 }
103
104 adev->kfd = kgd2kfd->probe((struct kgd_dev *)adev,
105 adev->pdev, kfd2kgd);
Oded Gabbay130e0372015-06-12 21:35:14 +0300106}
107
Alex Deucher22cb0162017-12-14 16:27:11 -0500108/**
109 * amdgpu_doorbell_get_kfd_info - Report doorbell configuration required to
110 * setup amdkfd
111 *
112 * @adev: amdgpu_device pointer
113 * @aperture_base: output returning doorbell aperture base physical address
114 * @aperture_size: output returning doorbell aperture size in bytes
115 * @start_offset: output returning # of doorbell bytes reserved for amdgpu.
116 *
117 * amdgpu and amdkfd share the doorbell aperture. amdgpu sets it up,
118 * takes doorbells required for its own rings and reports the setup to amdkfd.
119 * amdgpu reserved doorbells are at the start of the doorbell aperture.
120 */
121static void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
122 phys_addr_t *aperture_base,
123 size_t *aperture_size,
124 size_t *start_offset)
125{
126 /*
127 * The first num_doorbells are used by amdgpu.
128 * amdkfd takes whatever's left in the aperture.
129 */
130 if (adev->doorbell.size > adev->doorbell.num_doorbells * sizeof(u32)) {
131 *aperture_base = adev->doorbell.base;
132 *aperture_size = adev->doorbell.size;
133 *start_offset = adev->doorbell.num_doorbells * sizeof(u32);
134 } else {
135 *aperture_base = 0;
136 *aperture_size = 0;
137 *start_offset = 0;
138 }
139}
140
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500141void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
Oded Gabbay130e0372015-06-12 21:35:14 +0300142{
Andres Rodriguezd0b63bb32017-02-03 16:28:48 -0500143 int i;
144 int last_valid_bit;
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500145 if (adev->kfd) {
Oded Gabbay130e0372015-06-12 21:35:14 +0300146 struct kgd2kfd_shared_resources gpu_resources = {
Felix Kuehling155494d2018-02-06 20:32:36 -0500147 .compute_vmid_bitmap = compute_vmid_bitmap,
Andres Rodriguezd0b63bb32017-02-03 16:28:48 -0500148 .num_pipe_per_mec = adev->gfx.mec.num_pipe_per_mec,
Felix Kuehling155494d2018-02-06 20:32:36 -0500149 .num_queue_per_pipe = adev->gfx.mec.num_queue_per_pipe,
150 .gpuvm_size = min(adev->vm_manager.max_pfn
151 << AMDGPU_GPU_PAGE_SHIFT,
152 AMDGPU_VA_HOLE_START),
153 .drm_render_minor = adev->ddev->render->index
Oded Gabbay130e0372015-06-12 21:35:14 +0300154 };
155
Andres Rodriguezd0b63bb32017-02-03 16:28:48 -0500156 /* this is going to have a few of the MSBs set that we need to
157 * clear */
158 bitmap_complement(gpu_resources.queue_bitmap,
159 adev->gfx.mec.queue_bitmap,
160 KGD_MAX_QUEUES);
161
Andres Rodriguez7b2124a2017-04-06 00:10:53 -0400162 /* remove the KIQ bit as well */
163 if (adev->gfx.kiq.ring.ready)
Alex Deucher2db0cdb2017-06-07 12:59:29 -0400164 clear_bit(amdgpu_gfx_queue_to_bit(adev,
165 adev->gfx.kiq.ring.me - 1,
166 adev->gfx.kiq.ring.pipe,
167 adev->gfx.kiq.ring.queue),
Andres Rodriguez7b2124a2017-04-06 00:10:53 -0400168 gpu_resources.queue_bitmap);
169
Andres Rodriguezd0b63bb32017-02-03 16:28:48 -0500170 /* According to linux/bitmap.h we shouldn't use bitmap_clear if
171 * nbits is not compile time constant */
Jay Cornwall3447d222017-07-13 20:21:53 -0500172 last_valid_bit = 1 /* only first MEC can have compute queues */
Andres Rodriguezd0b63bb32017-02-03 16:28:48 -0500173 * adev->gfx.mec.num_pipe_per_mec
174 * adev->gfx.mec.num_queue_per_pipe;
175 for (i = last_valid_bit; i < KGD_MAX_QUEUES; ++i)
176 clear_bit(i, gpu_resources.queue_bitmap);
177
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500178 amdgpu_doorbell_get_kfd_info(adev,
Oded Gabbay130e0372015-06-12 21:35:14 +0300179 &gpu_resources.doorbell_physical_address,
180 &gpu_resources.doorbell_aperture_size,
181 &gpu_resources.doorbell_start_offset);
Felix Kuehling642a0e82018-04-10 17:33:02 -0400182 if (adev->asic_type >= CHIP_VEGA10) {
183 /* On SOC15 the BIF is involved in routing
184 * doorbells using the low 12 bits of the
185 * address. Communicate the assignments to
186 * KFD. KFD uses two doorbell pages per
187 * process in case of 64-bit doorbells so we
188 * can use each doorbell assignment twice.
189 */
190 gpu_resources.sdma_doorbell[0][0] =
191 AMDGPU_DOORBELL64_sDMA_ENGINE0;
192 gpu_resources.sdma_doorbell[0][1] =
193 AMDGPU_DOORBELL64_sDMA_ENGINE0 + 0x200;
194 gpu_resources.sdma_doorbell[1][0] =
195 AMDGPU_DOORBELL64_sDMA_ENGINE1;
196 gpu_resources.sdma_doorbell[1][1] =
197 AMDGPU_DOORBELL64_sDMA_ENGINE1 + 0x200;
198 /* Doorbells 0x0f0-0ff and 0x2f0-2ff are reserved for
199 * SDMA, IH and VCN. So don't use them for the CP.
200 */
201 gpu_resources.reserved_doorbell_mask = 0x1f0;
202 gpu_resources.reserved_doorbell_val = 0x0f0;
203 }
Oded Gabbay130e0372015-06-12 21:35:14 +0300204
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500205 kgd2kfd->device_init(adev->kfd, &gpu_resources);
Oded Gabbay130e0372015-06-12 21:35:14 +0300206 }
207}
208
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500209void amdgpu_amdkfd_device_fini(struct amdgpu_device *adev)
Oded Gabbay130e0372015-06-12 21:35:14 +0300210{
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500211 if (adev->kfd) {
212 kgd2kfd->device_exit(adev->kfd);
213 adev->kfd = NULL;
Oded Gabbay130e0372015-06-12 21:35:14 +0300214 }
215}
216
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500217void amdgpu_amdkfd_interrupt(struct amdgpu_device *adev,
Oded Gabbay130e0372015-06-12 21:35:14 +0300218 const void *ih_ring_entry)
219{
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500220 if (adev->kfd)
221 kgd2kfd->interrupt(adev->kfd, ih_ring_entry);
Oded Gabbay130e0372015-06-12 21:35:14 +0300222}
223
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500224void amdgpu_amdkfd_suspend(struct amdgpu_device *adev)
Oded Gabbay130e0372015-06-12 21:35:14 +0300225{
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500226 if (adev->kfd)
227 kgd2kfd->suspend(adev->kfd);
Oded Gabbay130e0372015-06-12 21:35:14 +0300228}
229
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500230int amdgpu_amdkfd_resume(struct amdgpu_device *adev)
Oded Gabbay130e0372015-06-12 21:35:14 +0300231{
232 int r = 0;
233
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500234 if (adev->kfd)
235 r = kgd2kfd->resume(adev->kfd);
Oded Gabbay130e0372015-06-12 21:35:14 +0300236
237 return r;
238}
239
Oded Gabbay130e0372015-06-12 21:35:14 +0300240int alloc_gtt_mem(struct kgd_dev *kgd, size_t size,
241 void **mem_obj, uint64_t *gpu_addr,
242 void **cpu_ptr)
243{
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500244 struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
Yong Zhao473fee42018-02-06 20:32:31 -0500245 struct amdgpu_bo *bo = NULL;
Chunming Zhou3216c6b2018-04-16 18:27:50 +0800246 struct amdgpu_bo_param bp;
Oded Gabbay130e0372015-06-12 21:35:14 +0300247 int r;
Yong Zhao473fee42018-02-06 20:32:31 -0500248 uint64_t gpu_addr_tmp = 0;
249 void *cpu_ptr_tmp = NULL;
Oded Gabbay130e0372015-06-12 21:35:14 +0300250
Chunming Zhou3216c6b2018-04-16 18:27:50 +0800251 memset(&bp, 0, sizeof(bp));
252 bp.size = size;
253 bp.byte_align = PAGE_SIZE;
254 bp.domain = AMDGPU_GEM_DOMAIN_GTT;
255 bp.flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC;
256 bp.type = ttm_bo_type_kernel;
257 bp.resv = NULL;
258 r = amdgpu_bo_create(adev, &bp, &bo);
Oded Gabbay130e0372015-06-12 21:35:14 +0300259 if (r) {
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500260 dev_err(adev->dev,
Oded Gabbay130e0372015-06-12 21:35:14 +0300261 "failed to allocate BO for amdkfd (%d)\n", r);
262 return r;
263 }
264
265 /* map the buffer */
Yong Zhao473fee42018-02-06 20:32:31 -0500266 r = amdgpu_bo_reserve(bo, true);
Oded Gabbay130e0372015-06-12 21:35:14 +0300267 if (r) {
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500268 dev_err(adev->dev, "(%d) failed to reserve bo for amdkfd\n", r);
Oded Gabbay130e0372015-06-12 21:35:14 +0300269 goto allocate_mem_reserve_bo_failed;
270 }
271
Yong Zhao473fee42018-02-06 20:32:31 -0500272 r = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT,
273 &gpu_addr_tmp);
Oded Gabbay130e0372015-06-12 21:35:14 +0300274 if (r) {
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500275 dev_err(adev->dev, "(%d) failed to pin bo for amdkfd\n", r);
Oded Gabbay130e0372015-06-12 21:35:14 +0300276 goto allocate_mem_pin_bo_failed;
277 }
Oded Gabbay130e0372015-06-12 21:35:14 +0300278
Yong Zhao473fee42018-02-06 20:32:31 -0500279 r = amdgpu_bo_kmap(bo, &cpu_ptr_tmp);
Oded Gabbay130e0372015-06-12 21:35:14 +0300280 if (r) {
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500281 dev_err(adev->dev,
Oded Gabbay130e0372015-06-12 21:35:14 +0300282 "(%d) failed to map bo to kernel for amdkfd\n", r);
283 goto allocate_mem_kmap_bo_failed;
284 }
Oded Gabbay130e0372015-06-12 21:35:14 +0300285
Yong Zhao473fee42018-02-06 20:32:31 -0500286 *mem_obj = bo;
287 *gpu_addr = gpu_addr_tmp;
288 *cpu_ptr = cpu_ptr_tmp;
289
290 amdgpu_bo_unreserve(bo);
Oded Gabbay130e0372015-06-12 21:35:14 +0300291
292 return 0;
293
294allocate_mem_kmap_bo_failed:
Yong Zhao473fee42018-02-06 20:32:31 -0500295 amdgpu_bo_unpin(bo);
Oded Gabbay130e0372015-06-12 21:35:14 +0300296allocate_mem_pin_bo_failed:
Yong Zhao473fee42018-02-06 20:32:31 -0500297 amdgpu_bo_unreserve(bo);
Oded Gabbay130e0372015-06-12 21:35:14 +0300298allocate_mem_reserve_bo_failed:
Yong Zhao473fee42018-02-06 20:32:31 -0500299 amdgpu_bo_unref(&bo);
Oded Gabbay130e0372015-06-12 21:35:14 +0300300
301 return r;
302}
303
304void free_gtt_mem(struct kgd_dev *kgd, void *mem_obj)
305{
Yong Zhao473fee42018-02-06 20:32:31 -0500306 struct amdgpu_bo *bo = (struct amdgpu_bo *) mem_obj;
Oded Gabbay130e0372015-06-12 21:35:14 +0300307
Yong Zhao473fee42018-02-06 20:32:31 -0500308 amdgpu_bo_reserve(bo, true);
309 amdgpu_bo_kunmap(bo);
310 amdgpu_bo_unpin(bo);
311 amdgpu_bo_unreserve(bo);
312 amdgpu_bo_unref(&(bo));
Oded Gabbay130e0372015-06-12 21:35:14 +0300313}
314
Harish Kasiviswanathan30f1c042017-12-08 23:08:42 -0500315void get_local_mem_info(struct kgd_dev *kgd,
316 struct kfd_local_mem_info *mem_info)
317{
318 struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
319 uint64_t address_mask = adev->dev->dma_mask ? ~*adev->dev->dma_mask :
320 ~((1ULL << 32) - 1);
Christian König770d13b2018-01-12 14:52:22 +0100321 resource_size_t aper_limit = adev->gmc.aper_base + adev->gmc.aper_size;
Harish Kasiviswanathan30f1c042017-12-08 23:08:42 -0500322
323 memset(mem_info, 0, sizeof(*mem_info));
Christian König770d13b2018-01-12 14:52:22 +0100324 if (!(adev->gmc.aper_base & address_mask || aper_limit & address_mask)) {
325 mem_info->local_mem_size_public = adev->gmc.visible_vram_size;
326 mem_info->local_mem_size_private = adev->gmc.real_vram_size -
327 adev->gmc.visible_vram_size;
Harish Kasiviswanathan30f1c042017-12-08 23:08:42 -0500328 } else {
329 mem_info->local_mem_size_public = 0;
Christian König770d13b2018-01-12 14:52:22 +0100330 mem_info->local_mem_size_private = adev->gmc.real_vram_size;
Harish Kasiviswanathan30f1c042017-12-08 23:08:42 -0500331 }
Christian König770d13b2018-01-12 14:52:22 +0100332 mem_info->vram_width = adev->gmc.vram_width;
Harish Kasiviswanathan30f1c042017-12-08 23:08:42 -0500333
Arnd Bergmannfb8baef2018-01-08 13:53:56 +0100334 pr_debug("Address base: %pap limit %pap public 0x%llx private 0x%llx\n",
Christian König770d13b2018-01-12 14:52:22 +0100335 &adev->gmc.aper_base, &aper_limit,
Harish Kasiviswanathan30f1c042017-12-08 23:08:42 -0500336 mem_info->local_mem_size_public,
337 mem_info->local_mem_size_private);
338
339 if (amdgpu_sriov_vf(adev))
340 mem_info->mem_clk_max = adev->clock.default_mclk / 100;
Shaoyun Liu7ba01f9e2018-03-14 14:44:58 -0400341 else if (adev->powerplay.pp_funcs)
Harish Kasiviswanathan30f1c042017-12-08 23:08:42 -0500342 mem_info->mem_clk_max = amdgpu_dpm_get_mclk(adev, false) / 100;
Shaoyun Liu7ba01f9e2018-03-14 14:44:58 -0400343 else
344 mem_info->mem_clk_max = 100;
Harish Kasiviswanathan30f1c042017-12-08 23:08:42 -0500345}
346
Oded Gabbay130e0372015-06-12 21:35:14 +0300347uint64_t get_gpu_clock_counter(struct kgd_dev *kgd)
348{
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500349 struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
Oded Gabbay130e0372015-06-12 21:35:14 +0300350
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500351 if (adev->gfx.funcs->get_gpu_clock_counter)
352 return adev->gfx.funcs->get_gpu_clock_counter(adev);
Oded Gabbay130e0372015-06-12 21:35:14 +0300353 return 0;
354}
355
356uint32_t get_max_engine_clock_in_mhz(struct kgd_dev *kgd)
357{
Andres Rodriguezdc102c42017-02-01 17:02:13 -0500358 struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
Oded Gabbay130e0372015-06-12 21:35:14 +0300359
Felix Kuehlinga9efcc12017-11-27 18:29:43 -0500360 /* the sclk is in quantas of 10kHz */
361 if (amdgpu_sriov_vf(adev))
362 return adev->clock.default_sclk / 100;
Shaoyun Liu7ba01f9e2018-03-14 14:44:58 -0400363 else if (adev->powerplay.pp_funcs)
364 return amdgpu_dpm_get_sclk(adev, false) / 100;
365 else
366 return 100;
Oded Gabbay130e0372015-06-12 21:35:14 +0300367}
Flora Cuiebdebf42017-12-08 23:08:40 -0500368
369void get_cu_info(struct kgd_dev *kgd, struct kfd_cu_info *cu_info)
370{
371 struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
372 struct amdgpu_cu_info acu_info = adev->gfx.cu_info;
373
374 memset(cu_info, 0, sizeof(*cu_info));
375 if (sizeof(cu_info->cu_bitmap) != sizeof(acu_info.bitmap))
376 return;
377
378 cu_info->cu_active_number = acu_info.number;
379 cu_info->cu_ao_mask = acu_info.ao_cu_mask;
380 memcpy(&cu_info->cu_bitmap[0], &acu_info.bitmap[0],
381 sizeof(acu_info.bitmap));
382 cu_info->num_shader_engines = adev->gfx.config.max_shader_engines;
383 cu_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
384 cu_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
385 cu_info->simd_per_cu = acu_info.simd_per_cu;
386 cu_info->max_waves_per_simd = acu_info.max_waves_per_simd;
387 cu_info->wave_front_size = acu_info.wave_front_size;
388 cu_info->max_scratch_slots_per_cu = acu_info.max_scratch_slots_per_cu;
389 cu_info->lds_size = acu_info.lds_size;
390}
Kent Russell9f0a0b42017-12-08 23:09:05 -0500391
392uint64_t amdgpu_amdkfd_get_vram_usage(struct kgd_dev *kgd)
393{
394 struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
395
396 return amdgpu_vram_mgr_usage(&adev->mman.bdev.man[TTM_PL_VRAM]);
397}
Felix Kuehling155494d2018-02-06 20:32:36 -0500398
Felix Kuehling4c660c82018-02-06 20:32:39 -0500399int amdgpu_amdkfd_submit_ib(struct kgd_dev *kgd, enum kgd_engine_type engine,
400 uint32_t vmid, uint64_t gpu_addr,
401 uint32_t *ib_cmd, uint32_t ib_len)
402{
403 struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
404 struct amdgpu_job *job;
405 struct amdgpu_ib *ib;
406 struct amdgpu_ring *ring;
407 struct dma_fence *f = NULL;
408 int ret;
409
410 switch (engine) {
411 case KGD_ENGINE_MEC1:
412 ring = &adev->gfx.compute_ring[0];
413 break;
414 case KGD_ENGINE_SDMA1:
415 ring = &adev->sdma.instance[0].ring;
416 break;
417 case KGD_ENGINE_SDMA2:
418 ring = &adev->sdma.instance[1].ring;
419 break;
420 default:
421 pr_err("Invalid engine in IB submission: %d\n", engine);
422 ret = -EINVAL;
423 goto err;
424 }
425
426 ret = amdgpu_job_alloc(adev, 1, &job, NULL);
427 if (ret)
428 goto err;
429
430 ib = &job->ibs[0];
431 memset(ib, 0, sizeof(struct amdgpu_ib));
432
433 ib->gpu_addr = gpu_addr;
434 ib->ptr = ib_cmd;
435 ib->length_dw = ib_len;
436 /* This works for NO_HWS. TODO: need to handle without knowing VMID */
437 job->vmid = vmid;
438
439 ret = amdgpu_ib_schedule(ring, 1, ib, job, &f);
440 if (ret) {
441 DRM_ERROR("amdgpu: failed to schedule IB.\n");
442 goto err_ib_sched;
443 }
444
445 ret = dma_fence_wait(f, false);
446
447err_ib_sched:
448 dma_fence_put(f);
449 amdgpu_job_free(job);
450err:
451 return ret;
452}
453
Felix Kuehling155494d2018-02-06 20:32:36 -0500454bool amdgpu_amdkfd_is_kfd_vmid(struct amdgpu_device *adev, u32 vmid)
455{
456 if (adev->kfd) {
457 if ((1 << vmid) & compute_vmid_bitmap)
458 return true;
459 }
460
461 return false;
462}