drm/amdgpu: Add interface to alloc gws from amdgpu
authorOak Zeng <Oak.Zeng@amd.com>
Mon, 6 May 2019 14:48:37 +0000 (09:48 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 28 May 2019 19:44:05 +0000 (14:44 -0500)
Add amdgpu_amdkfd interface to alloc and free gws
from amdgpu

Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h

index a4780d5532be98f8b62d7a95ba83ce68c420bf4f..4af3989e4a755310a35d56ea28ebd13f91df10f8 100644 (file)
@@ -339,6 +339,40 @@ void amdgpu_amdkfd_free_gtt_mem(struct kgd_dev *kgd, void *mem_obj)
        amdgpu_bo_unref(&(bo));
 }
 
+int amdgpu_amdkfd_alloc_gws(struct kgd_dev *kgd, size_t size,
+                               void **mem_obj)
+{
+       struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
+       struct amdgpu_bo *bo = NULL;
+       struct amdgpu_bo_param bp;
+       int r;
+
+       memset(&bp, 0, sizeof(bp));
+       bp.size = size;
+       bp.byte_align = 1;
+       bp.domain = AMDGPU_GEM_DOMAIN_GWS;
+       bp.flags = AMDGPU_GEM_CREATE_NO_CPU_ACCESS;
+       bp.type = ttm_bo_type_device;
+       bp.resv = NULL;
+
+       r = amdgpu_bo_create(adev, &bp, &bo);
+       if (r) {
+               dev_err(adev->dev,
+                       "failed to allocate gws BO for amdkfd (%d)\n", r);
+               return r;
+       }
+
+       *mem_obj = bo;
+       return 0;
+}
+
+void amdgpu_amdkfd_free_gws(struct kgd_dev *kgd, void *mem_obj)
+{
+       struct amdgpu_bo *bo = (struct amdgpu_bo *)mem_obj;
+
+       amdgpu_bo_unref(&bo);
+}
+
 uint32_t amdgpu_amdkfd_get_fw_version(struct kgd_dev *kgd,
                                      enum kgd_engine_type type)
 {
index 57006432a36e8ca9c60e1843deae9be18146dd9e..c00c9749406e84e820af8e87e4dbcc2e69530b62 100644 (file)
@@ -153,6 +153,8 @@ int amdgpu_amdkfd_alloc_gtt_mem(struct kgd_dev *kgd, size_t size,
                                void **mem_obj, uint64_t *gpu_addr,
                                void **cpu_ptr, bool mqd_gfx9);
 void amdgpu_amdkfd_free_gtt_mem(struct kgd_dev *kgd, void *mem_obj);
+int amdgpu_amdkfd_alloc_gws(struct kgd_dev *kgd, size_t size, void **mem_obj);
+void amdgpu_amdkfd_free_gws(struct kgd_dev *kgd, void *mem_obj);
 uint32_t amdgpu_amdkfd_get_fw_version(struct kgd_dev *kgd,
                                      enum kgd_engine_type type);
 void amdgpu_amdkfd_get_local_mem_info(struct kgd_dev *kgd,