OSDN Git Service

Fix minigbm against older kernel DRM versions.
authorAlistair Strachan <astrachan@google.com>
Tue, 20 Mar 2018 18:10:51 +0000 (11:10 -0700)
committerchrome-bot <chrome-bot@chromium.org>
Wed, 21 Mar 2018 05:21:11 +0000 (22:21 -0700)
In 4.4, the DRM implementation only allowed DRM_CLOEXEC to be specified to
drmPrimeHandleToFD(), but it gave you a read/write mapping when mmap'ed.

In newer kernels the DRM_RDWR flag needs to be specified to get a
read/write mapping.

Try the new way, and if that fails, try the old way. If the handle
conversion fails for any reason other than this flag check, it'll
still fail.

Change-Id: I7fabb6a0d23e7b9b70f970aad0bc243a76583e33
Reviewed-on: https://chromium-review.googlesource.com/971461
Commit-Ready: Alistair Strachan <astrachan@google.com>
Tested-by: Alistair Strachan <astrachan@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
drv.c

diff --git a/drv.c b/drv.c
index d548448..4dca8e1 100644 (file)
--- a/drv.c
+++ b/drv.c
@@ -555,6 +555,10 @@ int drv_bo_get_plane_fd(struct bo *bo, size_t plane)
 
        ret = drmPrimeHandleToFD(bo->drv->fd, bo->handles[plane].u32, DRM_CLOEXEC | DRM_RDWR, &fd);
 
+       // Older DRM implementations blocked DRM_RDWR, but gave a read/write mapping anyways
+       if (ret)
+               ret = drmPrimeHandleToFD(bo->drv->fd, bo->handles[plane].u32, DRM_CLOEXEC, &fd);
+
        return (ret) ? ret : fd;
 }