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

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Fri Nov 20 11:31:24 UTC 2020


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 06431ce6..e7a3a5f4 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -1020,6 +1020,49 @@ uint64_t gem_global_aperture_size(int fd)
 	return aperture.aper_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 b76bea56..0d30cf5b 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -123,6 +123,7 @@ uint64_t gem_available_aperture_size(int fd);
 uint64_t gem_aperture_size(int fd);
 uint64_t gem_global_aperture_size(int fd);
 uint64_t gem_mappable_aperture_size(void);
+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