summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorZbigniew Kempczyński <zbigniew.kempczynski@intel.com>2021-03-15 17:58:06 +0100
committerPetri Latvala <petri.latvala@intel.com>2021-03-16 11:08:39 +0200
commitecfe4c613cdbc082e4a561ead120b40349b63f2b (patch)
treea57abaffa9155ae27e14169d794a1854b170ce86 /lib
parentf3fd2cc23455929d0ef276e05e02416b86a6db91 (diff)
lib/gem_submission: Add gem_has_relocations() check
Add check which probes kernel supports relocation or not for i915 device. Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Cc: Dominik Grzegorzek <dominik.grzegorzek@intel.com> Cc: Petri Latvala <petri.latvala@intel.com> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'lib')
-rw-r--r--lib/i915/gem_submission.c30
-rw-r--r--lib/i915/gem_submission.h1
2 files changed, 31 insertions, 0 deletions
diff --git a/lib/i915/gem_submission.c b/lib/i915/gem_submission.c
index 320340a5..051f9d04 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 773e7b51..0faba6a3 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 */