[igt-dev] [PATCH i-g-t v17 25/31] lib/ioctl_wrappers: Add gem_has_relocations() check
Zbigniew Kempczyński
zbigniew.kempczynski at intel.com
Fri Jan 15 12:57: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/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
More information about the igt-dev
mailing list