[Freedreno] [PATCH libdrm 4/4] freedreno: use drmPrime wrappers to import/export prime bo's
Varad Gautam
varadgautam at gmail.com
Fri Aug 21 09:44:36 PDT 2015
Use drmPrimeFDToHandle() and drmPrimeHandleToFD() over drmIoctl() and
lock fd import to prevent race when importing a bo that's currently
being freed.
Signed-off-by: Varad Gautam <varadgautam at gmail.com>
---
freedreno/freedreno_bo.c | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/freedreno/freedreno_bo.c b/freedreno/freedreno_bo.c
index 596bfbc..aece972 100644
--- a/freedreno/freedreno_bo.c
+++ b/freedreno/freedreno_bo.c
@@ -230,20 +230,31 @@ fd_bo_from_dmabuf(struct fd_device *dev, int fd)
.fd = fd,
};
int ret, size;
+ uint32_t handle;
struct fd_bo *bo;
- ret = drmIoctl(dev->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &req);
+ pthread_mutex_lock(&table_lock);
+ ret = drmPrimeFDToHandle(dev->fd, fd, &handle);
+
if (ret) {
- return NULL;
+ bo = NULL;
+ goto out_unlock;
}
+ bo = lookup_bo(dev->handle_table, handle);
+ if (bo)
+ goto out_unlock;
+
/* lseek() to get bo size */
size = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_CUR);
- bo = fd_bo_from_handle(dev, req.handle, size);
+ bo = bo_from_handle(dev, size, handle);
bo->fd = fd;
+out_unlock:
+ pthread_mutex_unlock(&table_lock);
+
return bo;
}
@@ -381,19 +392,18 @@ uint32_t fd_bo_handle(struct fd_bo *bo)
int fd_bo_dmabuf(struct fd_bo *bo)
{
if (bo->fd < 0) {
- struct drm_prime_handle req = {
- .handle = bo->handle,
- .flags = DRM_CLOEXEC,
- };
- int ret;
+ int ret, prime_fd;
+
+ ret = drmPrimeHandleToFD(bo->dev->fd, bo->handle, DRM_CLOEXEC,
+ &prime_fd);
- ret = drmIoctl(bo->dev->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &req);
if (ret) {
return ret;
}
- bo->fd = req.fd;
+ bo->fd = prime_fd;
}
+
return dup(bo->fd);
}
--
2.4.6
More information about the Freedreno
mailing list