Re: [igt-dev] [RFC 3/5] igt/lib: Add wrapper to check if gtt mapping is available

Chris Wilson
2019-02-21T19:49:24Z

Quoting Antonio Argenziano (2019-02-21 19:27:43)
> Add wrapper to get mmap_gtt version number and another to check if
> gtt mapping is at all available.
>
> Cc: Katarzyna Dec <katarzyna.dec@intel.com>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Matthew Auld <matthew.auld@intel.com>
> Signed-off-by: Antonio Argenziano <antonio.argenziano@intel.com>
> Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
> ---
> lib/ioctl_wrappers.c | 47 ++++++++++++++++++++++++++++++++++++--------
> lib/ioctl_wrappers.h | 11 +++++++++++
> 2 files changed, 50 insertions(+), 8 deletions(-)
>
> diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
> index d9b46088..25dd8ad3 100644
> --- a/lib/ioctl_wrappers.c
> +++ b/lib/ioctl_wrappers.c
> @@ -659,6 +659,42 @@ static bool has_mmap_offset(int fd)
> return has_mmap_offset > 0;
> }
>
> +/**
> + * gem_mmap__gtt_version:
> + * @fd: open i915 drm file descriptor
> + *
> + * This wraps I915_PARAM_MMAP_GTT_VERSION. It will return the supported feature
> + * set for gtt mapping. Since the mappable aperture in not always present, this
> + * function will return '-1' in case there is none.
> + */
> +static int gem_mmap__gtt_version(int fd)
> +{
> + static int gtt_version = ~0;
> +
> + if (gtt_version == ~0) {
> + struct drm_i915_getparam gp;
> +
> + gtt_version = 0;
> +
> + memset(&gp, 0, sizeof(gp));
> + gp.param = I915_PARAM_MMAP_GTT_VERSION;
> + gp.value = &gtt_version;
> + ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
> +
> + if(errno == -ENODEV)
> + gtt_version = -1; /* No mappable aperture */

errno is only valid after a failed syscall.

We the undersigned thoroughly dislike errno
-Chris