[igt-dev] [PATCH i-g-t v14 26/33] lib/ioctl_wrappers: Add gem_has_relocations() check

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Thu Jan 14 12:22:26 UTC 2021


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

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

diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index 45415621b..1b4ca85da 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -868,6 +868,49 @@ 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 fd)
+{
+	struct drm_i915_gem_relocation_entry reloc;
+	struct drm_i915_gem_exec_object2 obj;
+	struct drm_i915_gem_execbuffer2 execbuf;
+	const uint32_t bbe = MI_BATCH_BUFFER_END;
+	unsigned int reloc_offset = 0x10;
+	int ret;
+
+	memset(&obj, 0, sizeof(obj));
+	obj.handle = gem_create(fd, 4096);
+	obj.relocs_ptr = to_user_pointer(&reloc);
+	obj.relocation_count = 1;
+	obj.offset = 1;
+	gem_write(fd, obj.handle, 0, &bbe, sizeof(bbe));
+
+	memset(&execbuf, 0, sizeof(execbuf));
+	execbuf.buffers_ptr = to_user_pointer(&obj);
+	execbuf.buffer_count = 1;
+	memset(&reloc, 0, sizeof(reloc));
+	reloc.offset = reloc_offset;
+	reloc.target_handle = obj.handle;
+	reloc.read_domains = I915_GEM_DOMAIN_INSTRUCTION;
+	reloc.presumed_offset = -1;
+
+	ret = __gem_execbuf(fd, &execbuf);
+	gem_close(fd, obj.handle);
+
+	if (!ret && obj.offset != reloc_offset)
+		return true;
+
+	return false;
+}
+
 /**
  * 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