[weston PATCH] simple-dmabuf-drm: support etnaviv drm as well

Guido Günther agx at sigxcpu.org
Mon Mar 12 15:41:46 UTC 2018


Since freedreno and etnaviv can live in parallel allow to build in
different DRM backends.
---
 Makefile.am                 |   6 ++-
 clients/simple-dmabuf-drm.c | 122 +++++++++++++++++++++++++++++++++++---------
 configure.ac                |  29 +++++++----
 3 files changed, 121 insertions(+), 36 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index e028a2a1..19319fa2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -624,7 +624,11 @@ nodist_weston_simple_dmabuf_drm_SOURCES =		\
 	protocol/linux-dmabuf-unstable-v1-protocol.c \
 	protocol/linux-dmabuf-unstable-v1-client-protocol.h
 weston_simple_dmabuf_drm_CFLAGS = $(AM_CFLAGS) $(SIMPLE_DMABUF_DRM_CLIENT_CFLAGS)
-weston_simple_dmabuf_drm_LDADD = $(SIMPLE_DMABUF_DRM_CLIENT_LIBS) $(LIBDRM_PLATFORM_LIBS) libshared.la
+weston_simple_dmabuf_drm_LDADD = $(SIMPLE_DMABUF_DRM_CLIENT_LIBS) \
+	$(LIBDRM_PLATFORM_FREEDRENO_LIBS) \
+	$(LIBDRM_PLATFORM_ETNAVIV_LIBS)   \
+	$(LIBDRM_PLATFORM_INTEL_LIBS)     \
+	libshared.la
 endif
 
 if BUILD_SIMPLE_DMABUF_V4L_CLIENT
diff --git a/clients/simple-dmabuf-drm.c b/clients/simple-dmabuf-drm.c
index 1073930f..8b7acd39 100644
--- a/clients/simple-dmabuf-drm.c
+++ b/clients/simple-dmabuf-drm.c
@@ -44,9 +44,13 @@
 #ifdef HAVE_LIBDRM_INTEL
 #include <i915_drm.h>
 #include <intel_bufmgr.h>
-#elif HAVE_LIBDRM_FREEDRENO
+#endif
+#ifdef HAVE_LIBDRM_FREEDRENO
 #include <freedreno/freedreno_drmif.h>
 #endif
+#ifdef HAVE_LIBDRM_ETNAVIV
+#include <etnaviv_drmif.h>
+#endif
 #include <drm_fourcc.h>
 
 #include <wayland-client.h>
@@ -93,11 +97,16 @@ struct buffer {
 
 #ifdef HAVE_LIBDRM_INTEL
 	drm_intel_bufmgr *bufmgr;
-	drm_intel_bo *bo;
-#elif HAVE_LIBDRM_FREEDRENO
+	drm_intel_bo *intel_bo;
+#endif /* HAVE_LIBDRM_INTEL */
+#if HAVE_LIBDRM_FREEDRENO
 	struct fd_device *fd_dev;
-	struct fd_bo *bo;
+	struct fd_bo *fd_bo;
 #endif /* HAVE_LIBDRM_FREEDRENO */
+#if HAVE_LIBDRM_ETNAVIV
+	struct etna_device *etna_dev;
+	struct etna_bo *etna_bo;
+#endif /* HAVE_LIBDRM_ETNAVIV */
 
 	uint32_t gem_handle;
 	int dmabuf_fd;
@@ -152,15 +161,15 @@ intel_alloc_bo(struct buffer *my_buf)
 
 	assert(my_buf->bufmgr);
 
-	my_buf->bo = drm_intel_bo_alloc_tiled(my_buf->bufmgr, "test",
-					      my_buf->width, my_buf->height,
-					      (my_buf->bpp / 8), &tiling,
-					      &my_buf->stride, 0);
+	my_buf->intel_bo = drm_intel_bo_alloc_tiled(my_buf->bufmgr, "test",
+						    my_buf->width, my_buf->height,
+						    (my_buf->bpp / 8), &tiling,
+						    &my_buf->stride, 0);
 
 	printf("buffer allocated w %d, h %d, stride %lu, size %lu\n",
-	       my_buf->width, my_buf->height, my_buf->stride, my_buf->bo->size);
+	       my_buf->width, my_buf->height, my_buf->stride, my_buf->intel_bo->size);
 
-	if (!my_buf->bo)
+	if (!my_buf->intel_bo)
 		return 0;
 
 	if (tiling != I915_TILING_NONE)
@@ -172,16 +181,16 @@ intel_alloc_bo(struct buffer *my_buf)
 static void
 intel_free_bo(struct buffer *my_buf)
 {
-	drm_intel_bo_unreference(my_buf->bo);
+	drm_intel_bo_unreference(my_buf->intel_bo);
 }
 
 static int
 intel_map_bo(struct buffer *my_buf)
 {
-	if (drm_intel_gem_bo_map_gtt(my_buf->bo) != 0)
+	if (drm_intel_gem_bo_map_gtt(my_buf->intel_bo) != 0)
 		return 0;
 
-	my_buf->mmap = my_buf->bo->virtual;
+	my_buf->mmap = my_buf->intel_bo->virtual;
 
 	return 1;
 }
@@ -189,15 +198,16 @@ intel_map_bo(struct buffer *my_buf)
 static int
 intel_bo_export_to_prime(struct buffer *buffer)
 {
-	return drm_intel_bo_gem_export_to_prime(buffer->bo, &buffer->dmabuf_fd);
+	return drm_intel_bo_gem_export_to_prime(buffer->intel_bo, &buffer->dmabuf_fd);
 }
 
 static void
 intel_unmap_bo(struct buffer *my_buf)
 {
-	drm_intel_gem_bo_unmap_gtt(my_buf->bo);
+	drm_intel_gem_bo_unmap_gtt(my_buf->intel_bo);
 }
-#elif HAVE_LIBDRM_FREEDRENO
+#endif /* HAVE_LIBDRM_INTEL */
+#ifdef HAVE_LIBDRM_FREEDRENO
 #define ALIGN(v, a) ((v + a - 1) & ~(a - 1))
 
 static
@@ -207,9 +217,9 @@ int fd_alloc_bo(struct buffer *buf)
 	int size = buf->width * buf->height * buf->bpp / 8;
 	buf->fd_dev = fd_device_new(buf->drm_fd);
 
-	buf->bo = fd_bo_new(buf->fd_dev, size, flags);
+	buf->fd_bo = fd_bo_new(buf->fd_dev, size, flags);
 
-	if (!buf->bo)
+	if (!buf->fd_bo)
 		return 0;
 	buf->stride = ALIGN(buf->width, 32) * buf->bpp / 8;
 	return 1;
@@ -218,13 +228,13 @@ int fd_alloc_bo(struct buffer *buf)
 static
 void fd_free_bo(struct buffer *buf)
 {
-	fd_bo_del(buf->bo);
+	fd_bo_del(buf->fd_bo);
 }
 
 static
 int fd_bo_export_to_prime(struct buffer *buf)
 {
-	buf->dmabuf_fd = fd_bo_dmabuf(buf->bo);
+	buf->dmabuf_fd = fd_bo_dmabuf(buf->fd_bo);
 	if (buf->dmabuf_fd > 0)
 		return 0;
 
@@ -234,7 +244,7 @@ int fd_bo_export_to_prime(struct buffer *buf)
 static
 int fd_map_bo(struct buffer *buf)
 {
-	buf->mmap = fd_bo_map(buf->bo);
+	buf->mmap = fd_bo_map(buf->fd_bo);
 
 	if (buf->mmap != NULL)
 		return 1;
@@ -246,7 +256,57 @@ static
 void fd_unmap_bo(struct buffer *buf)
 {
 }
-#endif
+#endif /* HAVE_LIBDRM_FREEDRENO */
+#ifdef HAVE_LIBDRM_ETNAVIV
+#define ALIGN(v, a) ((v + a - 1) & ~(a - 1))
+
+static
+int etna_alloc_bo(struct buffer *buf)
+{
+	int flags = DRM_ETNA_GEM_CACHE_WC;
+	int size = buf->width * buf->height * buf->bpp / 8;
+	buf->etna_dev = etna_device_new(buf->drm_fd);
+
+	buf->etna_bo = etna_bo_new(buf->etna_dev, size, flags);
+
+	if (!buf->etna_bo)
+		return 0;
+	buf->stride = ALIGN(buf->width, 32) * buf->bpp / 8;
+	return 1;
+}
+
+static
+void etna_free_bo(struct buffer *buf)
+{
+	etna_bo_del(buf->etna_bo);
+}
+
+static
+int etna_bo_export_to_prime(struct buffer *buf)
+{
+	buf->dmabuf_fd = etna_bo_dmabuf(buf->etna_bo);
+	if (buf->dmabuf_fd > 0)
+		return 0;
+
+	return 1;
+}
+
+static
+int etna_map_bo(struct buffer *buf)
+{
+	buf->mmap = etna_bo_map(buf->etna_bo);
+
+	if (buf->mmap != NULL)
+		return 1;
+
+	return 0;
+}
+
+static
+void etna_unmap_bo(struct buffer *buf)
+{
+}
+#endif /* HAVE_LIBDRM_ENTAVIV */
 
 static void
 fill_content(struct buffer *my_buf)
@@ -278,9 +338,13 @@ drm_device_destroy(struct buffer *buf)
 {
 #ifdef HAVE_LIBDRM_INTEL
 	drm_intel_bufmgr_destroy(buf->bufmgr);
-#elif HAVE_LIBDRM_FREEDRENO
+#endif
+#ifdef HAVE_LIBDRM_FREEDRENO
 	fd_device_del(buf->fd_dev);
 #endif
+#ifdef HAVE_LIBDRM_ETNAVIV
+	etna_device_del(buf->etna_dev);
+#endif
 
 	close(buf->drm_fd);
 }
@@ -308,7 +372,8 @@ drm_device_init(struct buffer *buf)
 		dev->map_bo = intel_map_bo;
 		dev->unmap_bo = intel_unmap_bo;
 	}
-#elif HAVE_LIBDRM_FREEDRENO
+#endif
+#ifdef HAVE_LIBDRM_FREEDRENO
 	else if (!strcmp(dev->name, "msm")) {
 		dev->alloc_bo = fd_alloc_bo;
 		dev->free_bo = fd_free_bo;
@@ -316,6 +381,15 @@ drm_device_init(struct buffer *buf)
 		dev->map_bo = fd_map_bo;
 		dev->unmap_bo = fd_unmap_bo;
 	}
+#endif
+#ifdef HAVE_LIBDRM_ETNAVIV
+	else if (!strcmp(dev->name, "etnaviv")) {
+		dev->alloc_bo = etna_alloc_bo;
+		dev->free_bo = etna_free_bo;
+		dev->export_bo_to_prime = etna_bo_export_to_prime;
+		dev->map_bo = etna_map_bo;
+		dev->unmap_bo = etna_unmap_bo;
+	}
 #endif
 	else {
 		fprintf(stderr, "Error: drm device %s unsupported.\n",
diff --git a/configure.ac b/configure.ac
index 0b326ccc..6880a4aa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -384,19 +384,26 @@ AC_ARG_ENABLE(simple-dmabuf-drm-client,
                              [do not build the simple dmabuf drm client]),,
               enable_simple_dmabuf_drm_client="auto")
 if ! test "x$enable_simple_dmabuf_drm_client" = "xno"; then
-  PKG_CHECK_MODULES(SIMPLE_DMABUF_DRM_CLIENT, [wayland-client libdrm egl],
-    [PKG_CHECK_MODULES(LIBDRM_PLATFORM, [libdrm_freedreno],
-      AC_DEFINE([HAVE_LIBDRM_FREEDRENO], [1], [Build freedreno dmabuf client]) have_simple_dmabuf_drm_client=freedreno,
-    [PKG_CHECK_MODULES(LIBDRM_PLATFORM, [libdrm_intel],
-      AC_DEFINE([HAVE_LIBDRM_INTEL], [1], [Build intel dmabuf client]) have_simple_dmabuf_drm_client=intel,
-    have_simple_dmabuf_drm_client=unsupported)])],
-  have_simple_dmabuf_drm_client=unsupported)
-
-  if test "x$have_simple_dmabuf_drm_client" = "xunsupported" -a "x$enable_simple_dmabuf_drm_client" = "xyes"; then
-    AC_MSG_ERROR([DRM dmabuf client explicitly enabled, but libdrm_intel or libdrm_freedreno not found])
+  PKG_CHECK_MODULES(SIMPLE_DMABUF_DRM_CLIENT, [wayland-client libdrm egl], [have_simple_dmabuf_libs=yes],
+		    [have_simple_dmabuf_libs=no])
+
+  PKG_CHECK_MODULES(LIBDRM_PLATFORM_FREEDRENO, [libdrm_freedreno],
+      AC_DEFINE([HAVE_LIBDRM_FREEDRENO], [1], [Build freedreno dmabuf client]) have_simple_dmabuf_drm_client=yes,
+      [have_freedreno=no])
+  PKG_CHECK_MODULES(LIBDRM_PLATFORM_ETNAVIV, [libdrm_etnaviv],
+      AC_DEFINE([HAVE_LIBDRM_ETNAVIV], [1], [Build etnaviv dmabuf client]) have_simple_dmabuf_drm_client=yes,
+      [have_etnaviv=no])
+  PKG_CHECK_MODULES(LIBDRM_PLATFORM_INTEL, [libdrm_intel],
+      AC_DEFINE([HAVE_LIBDRM_INTEL], [1], [Build intel dmabuf client]) have_simple_dmabuf_drm_client=yes,
+      [have_intel=no])
+
+  if test "x$have_simple_dmabuf_drm_client" != "xyes" -o \
+          "xhave_simple_dmabuf_libs" = "no" -a \
+	  "x$enable_simple_dmabuf_drm_client" = "xyes"; then
+    AC_MSG_ERROR([DRM dmabuf client explicitly enabled, but libdrm_intel, libdrm_freedreno or libdrm_etnaviv not found])
   fi
 
-  if test "x$have_simple_dmabuf_drm_client" = "xfreedreno" -o "x$have_simple_dmabuf_drm_client" = "xintel"; then
+  if test "x$have_simple_dmabuf_drm_client" = "xyes" -a "xhave_simple_dmabuf_libs"; then
     enable_simple_dmabuf_drm_client="yes"
   fi
 fi
-- 
2.16.1



More information about the wayland-devel mailing list