[igt-dev] [PATCH i-g-t] lib/i915/gem_mman: Add helper routine to check GTT version
Stuart Summers
stuart.summers at intel.com
Sun Nov 17 14:39:16 UTC 2019
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 at 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 = >t_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 = >t_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
More information about the igt-dev
mailing list