Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Stuart Summers <stuart.summers@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t] lib/i915/gem_mman: Add helper routine to check GTT version
Date: Sun, 17 Nov 2019 06:39:16 -0800	[thread overview]
Message-ID: <20191117143916.110714-1-stuart.summers@intel.com> (raw)

Add a check to gem_pread and gem_pwrite to only allow GTT subtests
when the GTT version is at least 1.

Also add a minor change to gem_mmap_gtt to use the GTT_VERSION IOCTL
macro instead of hard coding the value.

Signed-off-by: Stuart Summers <stuart.summers@intel.com>
---
 lib/i915/gem_mman.c       | 26 +++++++++++++++++++-------
 lib/i915/gem_mman.h       |  2 ++
 tests/i915/gem_mmap_gtt.c |  2 +-
 tests/i915/gem_pread.c    |  3 +++
 tests/i915/gem_pwrite.c   |  3 +++
 5 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/lib/i915/gem_mman.c b/lib/i915/gem_mman.c
index 6256627b..cdd37f86 100644
--- a/lib/i915/gem_mman.c
+++ b/lib/i915/gem_mman.c
@@ -40,6 +40,24 @@
 #define VG(x) do {} while (0)
 #endif
 
+static int gem_mmap_get_gtt_version(int fd)
+{
+	struct drm_i915_getparam gp;
+	int gtt_version = -1;
+
+	memset(&gp, 0, sizeof(gp));
+	gp.param = I915_PARAM_MMAP_GTT_VERSION;
+	gp.value = &gtt_version;
+	ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
+
+	return gtt_version;
+}
+
+bool gem_mmap_has_gtt(int fd)
+{
+	return gem_mmap_get_gtt_version(fd) > 0;
+}
+
 /**
  * __gem_mmap__gtt:
  * @fd: open i915 drm file descriptor
@@ -108,22 +126,16 @@ bool gem_mmap__has_wc(int fd)
 	if (has_wc == -1) {
 		struct drm_i915_getparam gp;
 		int mmap_version = -1;
-		int gtt_version = -1;
 
 		has_wc = 0;
 
-		memset(&gp, 0, sizeof(gp));
-		gp.param = I915_PARAM_MMAP_GTT_VERSION;
-		gp.value = &gtt_version;
-		ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
-
 		memset(&gp, 0, sizeof(gp));
 		gp.param = I915_PARAM_MMAP_VERSION;
 		gp.value = &mmap_version;
 		ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
 
 		/* Do we have the new mmap_ioctl with DOMAIN_WC? */
-		if (mmap_version >= 1 && gtt_version >= 2) {
+		if (mmap_version >= 1 && gem_mmap_get_gtt_version(fd) >= 2) {
 			struct drm_i915_gem_mmap arg;
 
 			/* Does this device support wc-mmaps ? */
diff --git a/lib/i915/gem_mman.h b/lib/i915/gem_mman.h
index 096ff592..65d1a886 100644
--- a/lib/i915/gem_mman.h
+++ b/lib/i915/gem_mman.h
@@ -25,6 +25,8 @@
 #ifndef GEM_MMAN_H
 #define GEM_MMAN_H
 
+bool gem_mmap_has_gtt(int fd);
+
 void *gem_mmap__gtt(int fd, uint32_t handle, uint64_t size, unsigned prot);
 void *gem_mmap__cpu(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot);
 
diff --git a/tests/i915/gem_mmap_gtt.c b/tests/i915/gem_mmap_gtt.c
index a5f9d934..5e9ae9e5 100644
--- a/tests/i915/gem_mmap_gtt.c
+++ b/tests/i915/gem_mmap_gtt.c
@@ -294,7 +294,7 @@ static int mmap_gtt_version(int i915)
 {
 	int val = 0;
 	struct drm_i915_getparam gp = {
-		gp.param = 40, /* MMAP_GTT_VERSION */
+		gp.param = I915_PARAM_MMAP_GTT_VERSION,
 		gp.value = &val,
 	};
 
diff --git a/tests/i915/gem_pread.c b/tests/i915/gem_pread.c
index 5b926ab0..f6e02c72 100644
--- a/tests/i915/gem_pread.c
+++ b/tests/i915/gem_pread.c
@@ -47,6 +47,9 @@ static void *wrap_gem_mmap__gtt(int i915, uint32_t handle,
 				uint64_t offset, uint64_t length,
 				unsigned int prot)
 {
+	if (!gem_mmap_has_gtt(i915))
+		return NULL;
+
 	return gem_mmap__gtt(i915, handle, length, prot);
 }
 
diff --git a/tests/i915/gem_pwrite.c b/tests/i915/gem_pwrite.c
index 69f823d5..cde4d6ce 100644
--- a/tests/i915/gem_pwrite.c
+++ b/tests/i915/gem_pwrite.c
@@ -47,6 +47,9 @@ static void *wrap_gem_mmap__gtt(int i915, uint32_t handle,
 				uint64_t offset, uint64_t length,
 				unsigned int prot)
 {
+	if (!gem_mmap_has_gtt(i915))
+		return NULL;
+
 	return gem_mmap__gtt(i915, handle, length, prot);
 }
 
-- 
2.22.0

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

             reply	other threads:[~2019-11-17 14:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-17 14:39 Stuart Summers [this message]
2019-11-17 14:41 ` [igt-dev] [PATCH i-g-t] lib/i915/gem_mman: Add helper routine to check GTT version Chris Wilson
2019-11-17 22:12   ` Summers, Stuart
2019-11-18 10:24     ` Chris Wilson
2019-11-17 15:08 ` [igt-dev] ✗ Fi.CI.BAT: failure for " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191117143916.110714-1-stuart.summers@intel.com \
    --to=stuart.summers@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox