[PATCH libdrm] amdgpu: alloc vram for inject
Pan, Xinhui
Xinhui.Pan at amd.com
Mon Mar 25 07:49:58 UTC 2019
inject need a real valid address.
Signed-off-by: xinhui pan <xinhui.pan at amd.com>
---
tests/amdgpu/ras_tests.c | 53 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 52 insertions(+), 1 deletion(-)
diff --git a/tests/amdgpu/ras_tests.c b/tests/amdgpu/ras_tests.c
index 612ad1d7..d3f1750d 100644
--- a/tests/amdgpu/ras_tests.c
+++ b/tests/amdgpu/ras_tests.c
@@ -29,6 +29,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
+#include <stdlib.h>
#include "xf86drm.h"
const char *ras_block_string[] = {
@@ -452,6 +453,47 @@ static int amdgpu_ras_query_err_count(enum amdgpu_ras_block block,
return 0;
}
+typedef struct ________ras_inject_internal {
+ amdgpu_bo_handle bo_handle;
+ amdgpu_va_handle va_handle;
+ void *cpu;
+ uint64_t mc;
+} amdgpu_ras_handle;
+
+static int amdgpu_ras_alloc_vram_page(uint64_t *mc_address, void **handle)
+{
+ amdgpu_ras_handle h;
+ int r;
+
+ *handle = malloc(sizeof(amdgpu_ras_handle));
+ if (!*handle)
+ return -1;
+
+ r = amdgpu_bo_alloc_and_map(device_handle, 4096, 4096,
+ AMDGPU_GEM_DOMAIN_VRAM, 0,
+ &h.bo_handle, &h.cpu,
+ &h.mc, &h.va_handle);
+ if (r) {
+ free(*handle);
+ return r;
+ }
+
+ memset(h.cpu, 4096, 0);
+ memcpy(*handle, &h, sizeof(h));
+ *mc_address = h.mc;
+
+ return 0;
+}
+
+static void amdgpu_ras_free_vram_page(void *handle)
+{
+ amdgpu_ras_handle h = *(amdgpu_ras_handle *)handle;
+
+ free(handle);
+
+ amdgpu_bo_unmap_and_free(h.bo_handle, h.va_handle, h.mc, 4096);
+}
+
//tests
static void amdgpu_ras_features_test(int enable)
{
@@ -508,6 +550,14 @@ static void __amdgpu_ras_inject_test(void)
int ret;
int i;
unsigned long ue, ce, ue_old, ce_old;
+ uint64_t mc;
+ void *handle;
+
+ ret = amdgpu_ras_alloc_vram_page(&mc, &handle);
+ CU_ASSERT_EQUAL(ret, 0);
+
+ if (ret)
+ return;
data.op = 2;
for (i = 0; i < AMDGPU_RAS_BLOCK__LAST; i++) {
@@ -519,7 +569,7 @@ static void __amdgpu_ras_inject_test(void)
.sub_block_index = 0,
.name = "",
},
- .address = 0,
+ .address = mc,
.value = 0,
};
@@ -563,6 +613,7 @@ loop:
CU_ASSERT_EQUAL(ue_old + 1, ue);
CU_ASSERT_EQUAL(ce_old, ce);
}
+ amdgpu_ras_free_vram_page(handle);
}
static void amdgpu_ras_inject_test(void)
--
2.17.1
More information about the amd-gfx
mailing list