summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Makefile.sources2
-rw-r--r--lib/igt_amd.c56
-rw-r--r--lib/igt_amd.h31
-rw-r--r--lib/igt_fb.c9
-rw-r--r--lib/meson.build1
5 files changed, 98 insertions, 1 deletions
diff --git a/lib/Makefile.sources b/lib/Makefile.sources
index e00347f9..a1d25351 100644
--- a/lib/Makefile.sources
+++ b/lib/Makefile.sources
@@ -115,6 +115,8 @@ lib_source_list = \
igt_v3d.h \
igt_vc4.c \
igt_vc4.h \
+ igt_amd.c \
+ igt_amd.h \
$(NULL)
.PHONY: version.h.tmp
diff --git a/lib/igt_amd.c b/lib/igt_amd.c
new file mode 100644
index 00000000..abd3ad96
--- /dev/null
+++ b/lib/igt_amd.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2019 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "igt_amd.h"
+#include "igt.h"
+#include <amdgpu_drm.h>
+
+uint32_t igt_amd_create_bo(int fd, uint64_t size)
+{
+ union drm_amdgpu_gem_create create;
+
+ memset(&create, 0, sizeof(create));
+ create.in.bo_size = size;
+ create.in.alignment = 256;
+ create.in.domains = AMDGPU_GEM_DOMAIN_VRAM;
+ create.in.domain_flags = AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED
+ | AMDGPU_GEM_CREATE_VRAM_CLEARED;
+
+ do_ioctl(fd, DRM_IOCTL_AMDGPU_GEM_CREATE, &create);
+ igt_assert(create.out.handle);
+
+ return create.out.handle;
+}
+
+void *igt_amd_mmap_bo(int fd, uint32_t handle, uint64_t size, int prot)
+{
+ union drm_amdgpu_gem_mmap map;
+ void *ptr;
+
+ memset(&map, 0, sizeof(map));
+ map.in.handle = handle;
+
+ do_ioctl(fd, DRM_IOCTL_AMDGPU_GEM_MMAP, &map);
+
+ ptr = mmap(0, size, prot, MAP_SHARED, fd, map.out.addr_ptr);
+ return ptr == MAP_FAILED ? NULL : ptr;
+}
diff --git a/lib/igt_amd.h b/lib/igt_amd.h
new file mode 100644
index 00000000..f63d26f4
--- /dev/null
+++ b/lib/igt_amd.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2019 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef IGT_AMD_H
+#define IGT_AMD_H
+
+#include <stdint.h>
+
+uint32_t igt_amd_create_bo(int fd, uint64_t size);
+void *igt_amd_mmap_bo(int fd, uint32_t handle, uint64_t size, int prot);
+
+#endif /* IGT_AMD_H */
diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 6adf4222..f5c9a9f1 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -38,6 +38,7 @@
#include "igt_kms.h"
#include "igt_matrix.h"
#include "igt_vc4.h"
+#include "igt_amd.h"
#include "igt_x86.h"
#include "ioctl_wrappers.h"
#include "intel_batchbuffer.h"
@@ -763,7 +764,8 @@ static int create_bo_for_fb(struct igt_fb *fb)
* them, so we need to make sure to use a device BO then.
*/
if (fb->modifier || fb->size || fb->strides[0] ||
- (is_i915_device(fd) && igt_format_is_yuv(fb->drm_format)))
+ (is_i915_device(fd) && igt_format_is_yuv(fb->drm_format)) ||
+ (is_amdgpu_device(fd) && igt_format_is_yuv(fb->drm_format)))
device_bo = true;
/* Sets offets and stride if necessary. */
@@ -787,6 +789,8 @@ static int create_bo_for_fb(struct igt_fb *fb)
if (fb->modifier == DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED)
igt_vc4_set_tiling(fd, fb->gem_handle,
fb->modifier);
+ } else if (is_amdgpu_device(fd)) {
+ fb->gem_handle = igt_amd_create_bo(fd, fb->size);
} else {
igt_assert(false);
}
@@ -1832,6 +1836,9 @@ static void *map_bo(int fd, struct igt_fb *fb)
else if (is_vc4_device(fd))
ptr = igt_vc4_mmap_bo(fd, fb->gem_handle, fb->size,
PROT_READ | PROT_WRITE);
+ else if (is_amdgpu_device(fd))
+ ptr = igt_amd_mmap_bo(fd, fb->gem_handle, fb->size,
+ PROT_READ | PROT_WRITE);
else
igt_assert(false);
diff --git a/lib/meson.build b/lib/meson.build
index 89de06e6..a8462933 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -54,6 +54,7 @@ lib_sources = [
'igt_v3d.c',
'igt_vc4.c',
'igt_psr.c',
+ 'igt_amd.c'
]
lib_deps = [