[igt-dev] [PATCH i-g-t 2/3] lib/i915/gem_mman: add mmap_offset support

Chris Wilson chris at chris-wilson.co.uk
Tue Nov 26 15:29:39 UTC 2019


Quoting Zbigniew KempczyƄski (2019-11-26 10:05:55)

Due to how we have had to extend the ioctl, we cannot use a simple
trial-and-error approach, but need the API parameter:

> +bool __gem_mmap_offset__has_wc(int fd)
> +{
> +       int has_wc = 0;
> +       struct drm_i915_gem_mmap_offset arg;

       if (!gem_has_mmap_offset(fd))
               return false;

> +
> +       /* Does this device support wc-mmaps ? */
> +       memset(&arg, 0, sizeof(arg));
> +       arg.handle = gem_create(fd, 4096);
> +       arg.offset = 0;
> +       arg.flags = I915_MMAP_OFFSET_WC;
> +       has_wc = igt_ioctl(fd, DRM_IOCTL_I915_GEM_MMAP_OFFSET,
> +                          &arg) == 0;
> +       gem_close(fd, arg.handle);
> +
> +       errno = 0;
>  
>         return has_wc > 0;
>  }

> +void *__gem_mmap_offset(int fd, uint32_t handle, uint64_t offset, uint64_t size,
> +                       unsigned int prot, uint64_t flags)
> +{
> +       struct drm_i915_gem_mmap_offset arg;
> +       void *ptr;

	if (!gem_has_mmap_offset(fd))
		return NULL;

> +
> +       igt_assert(offset == 0);
> +
> +       memset(&arg, 0, sizeof(arg));
> +       arg.handle = handle;
> +       arg.flags = flags;
> +
> +       if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_MMAP_OFFSET, &arg))
> +               return NULL;
> +
> +       ptr = mmap64(0, size, prot, MAP_SHARED, fd, arg.offset + offset);
> +
> +       if (ptr == MAP_FAILED)
> +               ptr = NULL;
> +       else
> +               errno = 0;
> +
> +       return ptr;
> +}


More information about the igt-dev mailing list