[igt-dev] [PATCH i-g-t 1/2] lib/i915/gem_mman: Add functions to get mmap and gtt versions
Stuart Summers
stuart.summers at intel.com
Tue Nov 19 18:16:18 UTC 2019
Move these checks out to separate functions to make the code
more readable and reuseable.
Signed-off-by: Stuart Summers <stuart.summers at intel.com>
---
lib/i915/gem_mman.c | 42 +++++++++++++++++++++++++++---------------
1 file changed, 27 insertions(+), 15 deletions(-)
diff --git a/lib/i915/gem_mman.c b/lib/i915/gem_mman.c
index 6256627b..a0e34aef 100644
--- a/lib/i915/gem_mman.c
+++ b/lib/i915/gem_mman.c
@@ -101,29 +101,41 @@ int gem_munmap(void *ptr, uint64_t size)
return ret;
}
+static int 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;
+}
+
+static int get_mmap_version(int fd)
+{
+ struct drm_i915_getparam gp;
+ int mmap_version = -1;
+
+ memset(&gp, 0, sizeof(gp));
+ gp.param = I915_PARAM_MMAP_VERSION;
+ gp.value = &mmap_version;
+ ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
+
+ return mmap_version;
+}
+
bool gem_mmap__has_wc(int fd)
{
static int has_wc = -1;
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 (get_mmap_version(fd) >= 1 && get_gtt_version(fd) >= 2) {
struct drm_i915_gem_mmap arg;
/* Does this device support wc-mmaps ? */
--
2.21.0.5.gaeb582a983
More information about the igt-dev
mailing list