From ecfe4c613cdbc082e4a561ead120b40349b63f2b Mon Sep 17 00:00:00 2001 From: Zbigniew Kempczyński Date: Mon, 15 Mar 2021 17:58:06 +0100 Subject: lib/gem_submission: Add gem_has_relocations() check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add check which probes kernel supports relocation or not for i915 device. Signed-off-by: Zbigniew Kempczyński Signed-off-by: Chris Wilson Cc: Dominik Grzegorzek Cc: Petri Latvala Reviewed-by: Chris Wilson --- lib/i915/gem_submission.c | 30 ++++++++++++++++++++++++++++++ lib/i915/gem_submission.h | 1 + 2 files changed, 31 insertions(+) (limited to 'lib') 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 */ -- cgit v1.2.3