summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlora Cui <Flora.Cui@amd.com>2016-08-11 15:26:16 +0800
committerQiang Yu <Qiang.Yu@amd.com>2017-05-17 11:15:02 +0800
commit6107b89f0fdb216f9db28ee279311581d41c3c4f (patch)
tree9e823533af846bd223ebbc52e938cfb329fc5e53
parent469d1b02e999379da8a2f0ce365d340184794865 (diff)
tests/amdgpu: add direct gma test
Change-Id: Ib00252eff16a84f16f01039ff39f957bff903bae Signed-off-by: Flora Cui <Flora.Cui@amd.com>
-rw-r--r--tests/amdgpu/bo_tests.c64
1 files changed, 63 insertions, 1 deletions
diff --git a/tests/amdgpu/bo_tests.c b/tests/amdgpu/bo_tests.c
index 83f42a9c..930a0733 100644
--- a/tests/amdgpu/bo_tests.c
+++ b/tests/amdgpu/bo_tests.c
@@ -26,6 +26,7 @@
#endif
#include <stdio.h>
+#include <inttypes.h>
#include "CUnit/Basic.h"
@@ -47,7 +48,7 @@ static void amdgpu_bo_export_import(void);
static void amdgpu_bo_metadata(void);
static void amdgpu_bo_map_unmap(void);
static void amdgpu_get_fb_id_and_handle(void);
-
+static void amdgpu_bo_direct_gma(void);
CU_TestInfo bo_tests[] = {
{ "Export/Import", amdgpu_bo_export_import },
@@ -56,6 +57,7 @@ CU_TestInfo bo_tests[] = {
#endif
{ "CPU map/unmap", amdgpu_bo_map_unmap },
{ "GET FB_ID AND FB_HANDLE", amdgpu_get_fb_id_and_handle },
+ { "Direct GMA", amdgpu_bo_direct_gma },
CU_TEST_INFO_NULL,
};
@@ -217,3 +219,63 @@ static void amdgpu_get_fb_id_and_handle(void)
CU_ASSERT_EQUAL(r, 0);
CU_ASSERT_NOT_EQUAL(output.buf_handle, 0);
}
+
+#define TEST_LOOP 20
+static void amdgpu_bo_direct_gma(void)
+{
+ amdgpu_bo_handle buf_handle[TEST_LOOP] = {0};
+ amdgpu_bo_handle buf_handle_import[TEST_LOOP] = {0};
+ uint32_t *ptr[TEST_LOOP] = {0};
+ struct amdgpu_bo_alloc_request req = {0};
+ struct drm_amdgpu_capability cap;
+ uint64_t size=4096, phys_addr, remain;
+ int i, j, r;
+
+ amdgpu_query_capability(device_handle, &cap);
+ if(!(cap.flag & AMDGPU_CAPABILITY_DIRECT_GMA_FLAG))
+ return;
+
+ printf("direct_gma_size is %d MB\n", cap.direct_gma_size);
+ remain = cap.direct_gma_size << 20;
+
+ req.preferred_heap = AMDGPU_GEM_DOMAIN_DGMA;
+ for (i = 0; i < TEST_LOOP; i++) {
+ req.alloc_size = size;
+ r = amdgpu_bo_alloc(device_handle, &req, &buf_handle[i]);
+ CU_ASSERT_EQUAL(r, 0);
+
+ r = amdgpu_bo_get_phys_address(buf_handle[i], &phys_addr);
+ CU_ASSERT_EQUAL(r, 0);
+ printf("bo_size %"PRIx64" phys_addr %"PRIx64"\n", size, phys_addr);
+ r = amdgpu_create_bo_from_phys_mem(device_handle, phys_addr, size, &buf_handle_import[i]);
+ CU_ASSERT_EQUAL(r, 0);
+ r = amdgpu_bo_cpu_map(buf_handle_import[i], (void **)&ptr[i]);
+ CU_ASSERT_EQUAL(r, 0);
+
+ for (j = 0; j < (size / 4); ++j)
+ ptr[i][j] = 0xdeadbeef;
+ remain -= size;
+ size <<= 1;
+ printf("test loop %d finished, remain %"PRIx64", try to alloc %"PRIx64"\n", i, remain, size);
+ if (remain < size)
+ break;
+
+ }
+
+ for (i = 0; i < TEST_LOOP; i++) {
+ if (ptr[i]) {
+ r = amdgpu_bo_cpu_unmap(buf_handle_import[i]);
+ CU_ASSERT_EQUAL(r, 0);
+ }
+
+ if (buf_handle_import[i]) {
+ r = amdgpu_bo_free(buf_handle_import[i]);
+ CU_ASSERT_EQUAL(r, 0);
+ }
+
+ if (buf_handle[i]) {
+ r = amdgpu_bo_free(buf_handle[i]);
+ CU_ASSERT_EQUAL(r, 0);
+ }
+ }
+}