[Freedreno] [PATCH libdrm v2 1/2] freedreno: use drmPrime wrappers to import/export prime bo's

Varad Gautam varadgautam at gmail.com
Sun Aug 23 10:49:04 PDT 2015


v2: split to acquire table_lock in a separate commit

Signed-off-by: Varad Gautam <varadgautam at gmail.com>
---
 freedreno/freedreno_bo.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/freedreno/freedreno_bo.c b/freedreno/freedreno_bo.c
index 596bfbc..0d2847f 100644
--- a/freedreno/freedreno_bo.c
+++ b/freedreno/freedreno_bo.c
@@ -230,18 +230,25 @@ 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);
+	ret = drmPrimeFDToHandle(dev->fd, fd, &handle);
+
 	if (ret) {
-		return NULL;
+		bo = NULL;
+		goto out_unlock;
 	}
 
+	bo = lookup_bo(dev->handle_table, handle);
+	if (bo)
+		return bo;
+
 	/* 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;
 
 	return bo;
@@ -381,19 +388,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