[igt-dev] [PATCH 2/7] lib/amdgpu: add bo allocation helper function

vitaly.prosyak at amd.com vitaly.prosyak at amd.com
Thu Jul 21 00:39:17 UTC 2022


From: Vitaly Prosyak <vitaly.prosyak at amd.com>

Signed-off-by: Vitaly Prosyak <vitaly.prosyak at amd.com>
---
 lib/amdgpu/amd_memory.c | 33 +++++++++++++++++++++++++++++++++
 lib/amdgpu/amd_memory.h |  4 ++++
 2 files changed, 37 insertions(+)

diff --git a/lib/amdgpu/amd_memory.c b/lib/amdgpu/amd_memory.c
index b0fa18c6b..344551fcc 100644
--- a/lib/amdgpu/amd_memory.c
+++ b/lib/amdgpu/amd_memory.c
@@ -69,6 +69,39 @@
 	return buf_handle;
 }
 
+ /**
+  *
+  * @param dev
+  * @param size
+  * @param alignment
+  * @param heap
+  * @param flags
+  * @param bo
+  * @return
+  */
+int
+amdgpu_bo_alloc_wrap(amdgpu_device_handle dev, unsigned size,
+		     unsigned alignment, unsigned heap, uint64_t flags,
+		     amdgpu_bo_handle *bo)
+{
+	amdgpu_bo_handle buf_handle;
+	int r;
+	struct amdgpu_bo_alloc_request req = {
+		.alloc_size = size,
+		.phys_alignment = alignment,
+		.preferred_heap = heap,
+		.flags = flags,
+	};
+
+	r = amdgpu_bo_alloc(dev, &req, &buf_handle);
+	if (r)
+		return r;
+
+	*bo = buf_handle;
+
+	return 0;
+}
+
  /**
   *
   * @param bo
diff --git a/lib/amdgpu/amd_memory.h b/lib/amdgpu/amd_memory.h
index d7f32926a..80bf979f4 100644
--- a/lib/amdgpu/amd_memory.h
+++ b/lib/amdgpu/amd_memory.h
@@ -38,6 +38,10 @@ gpu_mem_alloc(amdgpu_device_handle device_handle,
 				      uint64_t flags,
 				      uint64_t *vmc_addr,
 				      amdgpu_va_handle *va_handle);
+int
+amdgpu_bo_alloc_wrap(amdgpu_device_handle dev, unsigned size,
+		     unsigned alignment, unsigned heap, uint64_t flags,
+		     amdgpu_bo_handle *bo);
 
 void
 gpu_mem_free(amdgpu_bo_handle bo,
-- 
2.25.1



More information about the igt-dev mailing list