Thread (34 messages) 34 messages, 3 authors, 2021-01-15

[igt-dev] [PATCH i-g-t v17 25/31] lib/ioctl_wrappers: Add gem_has_relocations() check

From: Zbigniew Kempczyński <hidden>
Date: 2021-01-15 12:58:33
Subsystem: library code, the rest · Maintainers: Andrew Morton, Linus Torvalds

Add check which probes kernel supports relocation or not
for i915 device.

Signed-off-by: Zbigniew Kempczyński <redacted>
Signed-off-by: Chris Wilson <redacted>
Cc: Dominik Grzegorzek <redacted>
Cc: Petri Latvala <redacted>
---
 lib/ioctl_wrappers.c | 30 ++++++++++++++++++++++++++++++
 lib/ioctl_wrappers.h |  1 +
 2 files changed, 31 insertions(+)
diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index 45415621b..27c3cb2ee 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -868,6 +868,36 @@ uint64_t gem_total_stolen_size(int fd)
 	return aperture.stolen_total_size;
 }
 
+/**
+ * gem_has_relocations:
+ * @fd: opened i915 drm file descriptor
+ *
+ * Feature test macro to query whether kernel allows for generation to
+ * use relocations.
+ *
+ * Returns: true if we can use relocations, otherwise false
+ */
+
+bool gem_has_relocations(int i915)
+{
+	struct drm_i915_gem_relocation_entry reloc = {};
+	struct drm_i915_gem_exec_object2 obj = {
+		.handle = gem_create(i915, 4096),
+		.relocs_ptr = to_user_pointer(&reloc),
+		.relocation_count = 1,
+	};
+	struct drm_i915_gem_execbuffer2 execbuf = {
+		.buffers_ptr = to_user_pointer(&obj),
+		.buffer_count = 1,
+	};
+	bool has_relocs;
+
+	has_relocs = __gem_execbuf(i915, &execbuf) == -ENOENT;
+	gem_close(i915, obj.handle);
+
+	return has_relocs;
+}
+
 /**
  * gem_has_softpin:
  * @fd: open i915 drm file descriptor
diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
index 69e198419..bccc2ac4d 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -116,6 +116,7 @@ int gem_gpu_reset_type(int fd);
 bool gem_gpu_reset_enabled(int fd);
 bool gem_engine_reset_enabled(int fd);
 uint64_t gem_total_stolen_size(int fd);
+bool gem_has_relocations(int fd);
 bool gem_has_softpin(int fd);
 bool gem_has_exec_fence(int fd);
 
-- 
2.26.0

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help