[igt-dev] [PATCH i-g-t v12 24/31] lib/ioctl_wrappers: Add gem_has_relocations() check

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Tue Jan 5 08:10:41 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 a928f894f..66f539103 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -904,6 +904,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 07879ae96..3394c39ae 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -118,6 +118,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