[igt-dev] [PATCH i-g-t 01/35] lib/gem_submission: Add gem_has_relocations() check

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Tue Feb 16 11:39:33 UTC 2021


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

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
Cc: Petri Latvala <petri.latvala at intel.com>
---
 lib/i915/gem_submission.c | 30 ++++++++++++++++++++++++++++++
 lib/i915/gem_submission.h |  1 +
 2 files changed, 31 insertions(+)

diff --git a/lib/i915/gem_submission.c b/lib/i915/gem_submission.c
index 320340a5d..051f9d046 100644
--- a/lib/i915/gem_submission.c
+++ b/lib/i915/gem_submission.c
@@ -398,3 +398,33 @@ unsigned int gem_submission_measure(int i915, unsigned int engine)
 
 	return 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;
+}
diff --git a/lib/i915/gem_submission.h b/lib/i915/gem_submission.h
index 773e7b516..0faba6a3e 100644
--- a/lib/i915/gem_submission.h
+++ b/lib/i915/gem_submission.h
@@ -49,5 +49,6 @@ void gem_require_blitter(int i915);
 unsigned int gem_submission_measure(int i915, unsigned int engine);
 
 void gem_test_engine(int fd, unsigned int engine);
+bool gem_has_relocations(int fd);
 
 #endif /* GEM_SUBMISSION_H */
-- 
2.26.0



More information about the igt-dev mailing list