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

Chris Wilson chris at chris-wilson.co.uk
Thu Feb 21 21:54:56 UTC 2019


Quoting Antonio Argenziano (2019-02-21 21:37:50)
> 
> 
> On 21/02/19 11:49, Chris Wilson wrote:
> > 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 at intel.com>
> >> Cc: Chris Wilson <chris at chris-wilson.co.uk>
> >> Cc: Matthew Auld <matthew.auld at intel.com>
> >> Signed-off-by: Antonio Argenziano <antonio.argenziano at intel.com>
> >> Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio at 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.
> 
> Indeed, thanks for spotting this!
> 
> > 
> > We the undersigned thoroughly dislike errno
> 
> Agreed, maybe another version value returned from the IOCTL or even a 
> new PARAM_HAS_MMAP_GTT?

Nah, I genuinely dislike the libc ioctl() wrapper and would much prefer
if we just returned the raw long value from the kernel sysenter.

libc_ioctl:
	push 6 args to stack
	sysenter
	ret = $eax
	if (IS_ERR_VALUE(ret)) {
		errno = ret;
		ret = -1;
	}
	return ret;
Gah,
-Chris


More information about the igt-dev mailing list