Skip to contentSkip to conversation

libdrm/nouveau: add prime handle->bo and bo->handle support.

PATCH New Dave Airlie 1 participant 1 message Jul 16, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libdrm/nouveau: add prime handle->bo and bo->handle support.

From: Dave Airlie <[email protected]>

This adds prime support to nouveau libdrm.

---
 nouveau/nouveau.c |   35 +++++++++++++++++++++++++++++++++++
 nouveau/nouveau.h |    3 +++
 2 files changed, 38 insertions(+)
nouveau/nouveau.c +35 -0
index 5aa4107..940d933 100644
@@ -34,6 +34,7 @@
 #include <assert.h>
 #include <errno.h>
 #include <sys/mman.h>
+#include <fcntl.h>
 
 #include <xf86drm.h>
 #include <xf86atomic.h>
@@ -442,6 +443,40 @@ nouveau_bo_ref(struct nouveau_bo *bo, struct nouveau_bo **pref)
 }
 
 int
+nouveau_bo_prime_handle_ref(struct nouveau_device *dev, int prime_fd,
+			    struct nouveau_bo **bo)
+{
+	int ret;
+	unsigned int handle;
+
+	ret = drmPrimeFDToHandle(dev->fd, prime_fd, &handle);
+	if (ret) {
+		nouveau_bo_ref(NULL, bo);
+		return ret;
+	}
+
+	ret = nouveau_bo_wrap(dev, handle, bo);
+	if (ret) {
+		nouveau_bo_ref(NULL, bo);
+		return ret;
+	}
+
+	return 0;
+}
+
+int
+nouveau_bo_set_prime(struct nouveau_bo *bo, int *prime_fd)
+{
+	struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
+	int ret;
+
+	ret = drmPrimeHandleToFD(bo->device->fd, nvbo->base.handle, DRM_CLOEXEC, prime_fd);
+	if (ret)
+		return ret;
+	return 0;
+}
+
+int
 nouveau_bo_wait(struct nouveau_bo *bo, uint32_t access,
 		struct nouveau_client *client)
 {
nouveau/nouveau.h +3 -0
index 51a9598..c42eea7 100644
@@ -135,6 +135,9 @@ int  nouveau_bo_map(struct nouveau_bo *, uint32_t access,
 		    struct nouveau_client *);
 int  nouveau_bo_wait(struct nouveau_bo *, uint32_t access,
 		     struct nouveau_client *);
+int  nouveau_bo_prime_handle_ref(struct nouveau_device *dev, int prime_fd,
+				 struct nouveau_bo **);
+int  nouveau_bo_set_prime(struct nouveau_bo *bo, int *prime_fd);
 
 struct nouveau_bufref {
 	struct nouveau_list thead;
Signature · 1 line
1.7.10.2