Mesa (master): gallium: Add renderonly-based support for pl111+vc4.

Eric Anholt anholt at kemper.freedesktop.org
Thu Jun 15 19:40:38 UTC 2017


Module: Mesa
Branch: master
Commit: 7029ec05e2c7cb9f9fe34070161be7d190a7581e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7029ec05e2c7cb9f9fe34070161be7d190a7581e

Author: Eric Anholt <eric at anholt.net>
Date:   Mon May  8 15:57:21 2017 -0700

gallium: Add renderonly-based support for pl111+vc4.

This follows the model of imx (display) and etnaviv (render): pl111 is a
display-only device, so when asked to do GL for it, we see if we have a
vc4 renderer, make the vc4 screen, and have vc4 call back to pl111 to do
scanout allocations.

The difference from etnaviv is that we share the same BO between vc4 and
pl111, rather than having a vc4 bo and a pl11 bo and copies between the
two.  The only mismatch between their requirements is that vc4 requires
4-pixel (at 32bpp) stride alignment, while pl111 requires that stride
match width.  The kernel will reject any modesets to an incorrect stride,
so the 3D driver doesn't need to worry about that.

v2: Rebase on Android rework, drop unused include.
v3: Fix another Android bug, from Rob Herring's build-testing.

Reviewed-by: Christian Gmeiner <christian.gmeiner at gmail.com>

---

 .travis.yml                                        |  2 +-
 Android.mk                                         |  3 +-
 Makefile.am                                        |  2 +-
 configure.ac                                       | 12 ++++-
 src/gallium/Android.mk                             |  1 +
 src/gallium/Makefile.am                            |  4 ++
 .../auxiliary/pipe-loader/pipe_loader_drm.c        |  5 ++
 src/gallium/auxiliary/target-helpers/drm_helper.h  | 23 +++++++++
 .../auxiliary/target-helpers/drm_helper_public.h   |  3 ++
 src/gallium/drivers/pl111/Android.mk               | 38 +++++++++++++++
 src/gallium/drivers/pl111/Automake.inc             |  9 ++++
 src/gallium/drivers/pl111/Makefile.am              |  8 ++++
 src/gallium/drivers/pl111/Makefile.sources         |  2 +
 src/gallium/drivers/vc4/vc4_resource.c             | 38 +++++++++++++++
 src/gallium/drivers/vc4/vc4_resource.h             |  1 +
 src/gallium/drivers/vc4/vc4_screen.c               | 12 ++++-
 src/gallium/drivers/vc4/vc4_screen.h               |  5 +-
 src/gallium/targets/dri/Makefile.am                |  1 +
 src/gallium/targets/dri/target.c                   |  3 ++
 src/gallium/winsys/pl111/drm/Android.mk            | 33 +++++++++++++
 src/gallium/winsys/pl111/drm/Makefile.am           | 34 +++++++++++++
 src/gallium/winsys/pl111/drm/Makefile.sources      |  3 ++
 src/gallium/winsys/pl111/drm/pl111_drm_public.h    | 34 +++++++++++++
 src/gallium/winsys/pl111/drm/pl111_drm_winsys.c    | 55 ++++++++++++++++++++++
 src/gallium/winsys/vc4/drm/vc4_drm_public.h        |  2 +
 src/gallium/winsys/vc4/drm/vc4_drm_winsys.c        | 10 +++-
 26 files changed, 335 insertions(+), 8 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 0ab186957d..82d21eb539 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -89,7 +89,7 @@ matrix:
         - DRI_LOADERS="--disable-glx --disable-gbm --disable-egl"
         - DRI_DRIVERS=""
         - GALLIUM_ST="--enable-dri --disable-opencl --disable-xa --disable-nine --disable-xvmc --disable-vdpau --disable-va --disable-omx --disable-gallium-osmesa"
-        - GALLIUM_DRIVERS="i915,nouveau,r300,r600,radeonsi,freedreno,svga,swrast,vc4,virgl,etnaviv,imx"
+        - GALLIUM_DRIVERS="i915,nouveau,pl111,r300,r600,radeonsi,freedreno,svga,swrast,vc4,virgl,etnaviv,imx"
         - VULKAN_DRIVERS=""
       addons:
         apt:
diff --git a/Android.mk b/Android.mk
index de37f4600f..418570e607 100644
--- a/Android.mk
+++ b/Android.mk
@@ -24,7 +24,7 @@
 # BOARD_GPU_DRIVERS should be defined.  The valid values are
 #
 #   classic drivers: i915 i965
-#   gallium drivers: swrast freedreno i915g nouveau r300g r600g radeonsi vc4 virgl vmwgfx
+#   gallium drivers: swrast freedreno i915g nouveau pl111 r300g r600g radeonsi vc4 virgl vmwgfx
 #
 # The main target is libGLES_mesa.  For each classic driver enabled, a DRI
 # module will also be built.  DRI modules will be loaded by libGLES_mesa.
@@ -51,6 +51,7 @@ gallium_drivers := \
 	freedreno.HAVE_GALLIUM_FREEDRENO \
 	i915g.HAVE_GALLIUM_I915 \
 	nouveau.HAVE_GALLIUM_NOUVEAU \
+	pl111.HAVE_GALLIUM_PL111 \
 	r300g.HAVE_GALLIUM_R300 \
 	r600g.HAVE_GALLIUM_R600 \
 	radeonsi.HAVE_GALLIUM_RADEONSI \
diff --git a/Makefile.am b/Makefile.am
index 787174d005..fee132e972 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -43,7 +43,7 @@ AM_DISTCHECK_CONFIGURE_FLAGS = \
 	--enable-llvm-shared-libs \
 	--with-platforms=x11,wayland,drm,surfaceless \
 	--with-dri-drivers=i915,i965,nouveau,radeon,r200,swrast \
-	--with-gallium-drivers=i915,nouveau,r300,r600,radeonsi,freedreno,svga,swrast,vc4,virgl,swr,etnaviv,imx \
+	--with-gallium-drivers=i915,nouveau,r300,pl111,r600,radeonsi,freedreno,svga,swrast,vc4,virgl,swr,etnaviv,imx \
 	--with-vulkan-drivers=intel,radeon
 
 ACLOCAL_AMFLAGS = -I m4
diff --git a/configure.ac b/configure.ac
index 6c67d27084..2eed43615a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1236,7 +1236,7 @@ GALLIUM_DRIVERS_DEFAULT="r300,r600,svga,swrast"
 AC_ARG_WITH([gallium-drivers],
     [AS_HELP_STRING([--with-gallium-drivers@<:@=DIRS...@:>@],
         [comma delimited Gallium drivers list, e.g.
-        "i915,nouveau,r300,r600,radeonsi,freedreno,svga,swrast,swr,vc4,virgl,etnaviv,imx"
+        "i915,nouveau,r300,r600,radeonsi,freedreno,pl111,svga,swrast,swr,vc4,virgl,etnaviv,imx"
         @<:@default=r300,r600,svga,swrast@:>@])],
     [with_gallium_drivers="$withval"],
     [with_gallium_drivers="$GALLIUM_DRIVERS_DEFAULT"])
@@ -2499,6 +2499,9 @@ if test -n "$with_gallium_drivers"; then
                                DEFINES="$DEFINES -DUSE_VC4_SIMULATOR"],
                               [USE_VC4_SIMULATOR=no])
             ;;
+        xpl111)
+            HAVE_GALLIUM_PL111=yes
+            ;;
         xvirgl)
             HAVE_GALLIUM_VIRGL=yes
             require_libdrm "virgl"
@@ -2528,6 +2531,10 @@ if test "x$HAVE_GALLIUM_ETNAVIV" != xyes -a "x$HAVE_GALLIUM_IMX" = xyes  ; then
     AC_MSG_ERROR([Building with imx requires etnaviv])
 fi
 
+if test "x$HAVE_GALLIUM_VC4" != xyes -a "x$HAVE_GALLIUM_PL111" = xyes  ; then
+    AC_MSG_ERROR([Building with pl111 requires vc4])
+fi
+
 dnl
 dnl Set defines and buildtime variables only when using LLVM.
 dnl
@@ -2592,6 +2599,7 @@ fi
 
 AM_CONDITIONAL(HAVE_GALLIUM_SVGA, test "x$HAVE_GALLIUM_SVGA" = xyes)
 AM_CONDITIONAL(HAVE_GALLIUM_I915, test "x$HAVE_GALLIUM_I915" = xyes)
+AM_CONDITIONAL(HAVE_GALLIUM_PL111, test "x$HAVE_GALLIUM_PL111" = xyes)
 AM_CONDITIONAL(HAVE_GALLIUM_R300, test "x$HAVE_GALLIUM_R300" = xyes)
 AM_CONDITIONAL(HAVE_GALLIUM_R600, test "x$HAVE_GALLIUM_R600" = xyes)
 AM_CONDITIONAL(HAVE_GALLIUM_RADEONSI, test "x$HAVE_GALLIUM_RADEONSI" = xyes)
@@ -2741,6 +2749,7 @@ AC_CONFIG_FILES([Makefile
 		src/gallium/drivers/llvmpipe/Makefile
 		src/gallium/drivers/noop/Makefile
 		src/gallium/drivers/nouveau/Makefile
+		src/gallium/drivers/pl111/Makefile
 		src/gallium/drivers/r300/Makefile
 		src/gallium/drivers/r600/Makefile
 		src/gallium/drivers/radeon/Makefile
@@ -2786,6 +2795,7 @@ AC_CONFIG_FILES([Makefile
 		src/gallium/winsys/freedreno/drm/Makefile
 		src/gallium/winsys/i915/drm/Makefile
 		src/gallium/winsys/nouveau/drm/Makefile
+		src/gallium/winsys/pl111/drm/Makefile
 		src/gallium/winsys/radeon/drm/Makefile
 		src/gallium/winsys/amdgpu/drm/Makefile
 		src/gallium/winsys/svga/drm/Makefile
diff --git a/src/gallium/Android.mk b/src/gallium/Android.mk
index 0915579127..451bba4d17 100644
--- a/src/gallium/Android.mk
+++ b/src/gallium/Android.mk
@@ -37,6 +37,7 @@ SUBDIRS += winsys/sw/dri drivers/softpipe
 SUBDIRS += winsys/freedreno/drm drivers/freedreno
 SUBDIRS += winsys/i915/drm drivers/i915
 SUBDIRS += winsys/nouveau/drm drivers/nouveau
+SUBDIRS += winsys/pl111/drm drivers/pl111
 SUBDIRS += winsys/radeon/drm drivers/r300
 SUBDIRS += winsys/radeon/drm drivers/r600 drivers/radeon
 SUBDIRS += winsys/radeon/drm winsys/amdgpu/drm drivers/radeonsi drivers/radeon
diff --git a/src/gallium/Makefile.am b/src/gallium/Makefile.am
index 38da63b069..9f98a7e28b 100644
--- a/src/gallium/Makefile.am
+++ b/src/gallium/Makefile.am
@@ -71,6 +71,10 @@ if HAVE_GALLIUM_IMX
 SUBDIRS += drivers/imx winsys/imx/drm
 endif
 
+if HAVE_GALLIUM_PL111
+SUBDIRS += drivers/pl111 winsys/pl111/drm
+endif
+
 ## swrast/softpipe
 if HAVE_GALLIUM_SOFTPIPE
 SUBDIRS += drivers/softpipe
diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
index a4f5cfc03c..0ba360e1ee 100644
--- a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
+++ b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
@@ -129,6 +129,11 @@ static const struct drm_driver_descriptor driver_descriptors[] = {
         .configuration = configuration_query,
     },
     {
+       .driver_name = "pl111",
+        .create_screen = pipe_pl111_create_screen,
+        .configuration = configuration_query,
+    },
+    {
         .driver_name = "virtio_gpu",
         .create_screen = pipe_virgl_create_screen,
         .configuration = configuration_query,
diff --git a/src/gallium/auxiliary/target-helpers/drm_helper.h b/src/gallium/auxiliary/target-helpers/drm_helper.h
index 3159df6c5d..1b071a6d36 100644
--- a/src/gallium/auxiliary/target-helpers/drm_helper.h
+++ b/src/gallium/auxiliary/target-helpers/drm_helper.h
@@ -57,6 +57,29 @@ pipe_nouveau_create_screen(int fd)
 
 #endif
 
+#ifdef GALLIUM_PL111
+#include "pl111/drm/pl111_drm_public.h"
+
+struct pipe_screen *
+pipe_pl111_create_screen(int fd)
+{
+   struct pipe_screen *screen;
+
+   screen = pl111_drm_screen_create(fd);
+   return screen ? debug_screen_wrap(screen) : NULL;
+}
+
+#else
+
+struct pipe_screen *
+pipe_pl111_create_screen(int fd)
+{
+   fprintf(stderr, "pl111: driver missing\n");
+   return NULL;
+}
+
+#endif
+
 #ifdef GALLIUM_R300
 #include "radeon/radeon_winsys.h"
 #include "radeon/drm/radeon_drm_public.h"
diff --git a/src/gallium/auxiliary/target-helpers/drm_helper_public.h b/src/gallium/auxiliary/target-helpers/drm_helper_public.h
index bc12b2155e..5abb5fc7b8 100644
--- a/src/gallium/auxiliary/target-helpers/drm_helper_public.h
+++ b/src/gallium/auxiliary/target-helpers/drm_helper_public.h
@@ -35,6 +35,9 @@ struct pipe_screen *
 pipe_vc4_create_screen(int fd);
 
 struct pipe_screen *
+pipe_pl111_create_screen(int fd);
+
+struct pipe_screen *
 pipe_etna_create_screen(int fd);
 
 struct pipe_screen *
diff --git a/src/gallium/drivers/pl111/Android.mk b/src/gallium/drivers/pl111/Android.mk
new file mode 100644
index 0000000000..0b00b4e9ce
--- /dev/null
+++ b/src/gallium/drivers/pl111/Android.mk
@@ -0,0 +1,38 @@
+# Copyright (C) 2014 Emil Velikov <emil.l.velikov at gmail.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+
+LOCAL_PATH := $(call my-dir)
+
+# get C_SOURCES
+include $(LOCAL_PATH)/Makefile.sources
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+	$(C_SOURCES)
+
+LOCAL_MODULE := libmesa_pipe_pl111
+
+include $(GALLIUM_COMMON_MK)
+include $(BUILD_STATIC_LIBRARY)
+
+ifneq ($(HAVE_GALLIUM_PL111),)
+$(eval GALLIUM_LIBS += $(LOCAL_MODULE) libmesa_winsys_pl111)
+endif
diff --git a/src/gallium/drivers/pl111/Automake.inc b/src/gallium/drivers/pl111/Automake.inc
new file mode 100644
index 0000000000..4ecd7dec98
--- /dev/null
+++ b/src/gallium/drivers/pl111/Automake.inc
@@ -0,0 +1,9 @@
+if HAVE_GALLIUM_PL111
+
+TARGET_DRIVERS += pl111
+TARGET_CPPFLAGS += -DGALLIUM_PL111
+TARGET_LIB_DEPS += \
+    $(top_builddir)/src/gallium/winsys/pl111/drm/libpl111drm.la \
+    $(LIBDRM_LIBS)
+
+endif
diff --git a/src/gallium/drivers/pl111/Makefile.am b/src/gallium/drivers/pl111/Makefile.am
new file mode 100644
index 0000000000..b3e95eeff4
--- /dev/null
+++ b/src/gallium/drivers/pl111/Makefile.am
@@ -0,0 +1,8 @@
+include $(top_srcdir)/src/gallium/Automake.inc
+
+AM_CPPFLAGS = \
+	$(GALLIUM_CFLAGS)
+
+noinst_LTLIBRARIES = libpl111.la
+
+libpl111_la_SOURCES = $(C_SOURCES)
diff --git a/src/gallium/drivers/pl111/Makefile.sources b/src/gallium/drivers/pl111/Makefile.sources
new file mode 100644
index 0000000000..20396753fd
--- /dev/null
+++ b/src/gallium/drivers/pl111/Makefile.sources
@@ -0,0 +1,2 @@
+C_SOURCES :=
+
diff --git a/src/gallium/drivers/vc4/vc4_resource.c b/src/gallium/drivers/vc4/vc4_resource.c
index db7faf7ce3..5aaa31d6e6 100644
--- a/src/gallium/drivers/vc4/vc4_resource.c
+++ b/src/gallium/drivers/vc4/vc4_resource.c
@@ -371,9 +371,14 @@ static void
 vc4_resource_destroy(struct pipe_screen *pscreen,
                      struct pipe_resource *prsc)
 {
+        struct vc4_screen *screen = vc4_screen(pscreen);
         struct vc4_resource *rsc = vc4_resource(prsc);
         pipe_resource_reference(&rsc->shadow_parent, NULL);
         vc4_bo_unreference(&rsc->bo);
+
+        if (rsc->scanout)
+                renderonly_scanout_destroy(rsc->scanout, screen->ro);
+
         free(rsc);
 }
 
@@ -384,6 +389,7 @@ vc4_resource_get_handle(struct pipe_screen *pscreen,
                         struct winsys_handle *whandle,
                         unsigned usage)
 {
+        struct vc4_screen *screen = vc4_screen(pscreen);
         struct vc4_resource *rsc = vc4_resource(prsc);
 
         whandle->stride = rsc->slices[0].stride;
@@ -396,11 +402,23 @@ vc4_resource_get_handle(struct pipe_screen *pscreen,
 
         switch (whandle->type) {
         case DRM_API_HANDLE_TYPE_SHARED:
+                if (screen->ro) {
+                        /* This could probably be supported, assuming that a
+                         * control node was used for pl111.
+                         */
+                        fprintf(stderr, "flink unsupported with pl111\n");
+                        return FALSE;
+                }
+
                 return vc4_bo_flink(rsc->bo, &whandle->handle);
         case DRM_API_HANDLE_TYPE_KMS:
+                if (screen->ro && renderonly_get_handle(rsc->scanout, whandle))
+                        return TRUE;
                 whandle->handle = rsc->bo->handle;
                 return TRUE;
         case DRM_API_HANDLE_TYPE_FD:
+                /* FDs are cross-device, so we can export directly from vc4.
+                 */
                 whandle->handle = vc4_bo_get_dmabuf(rsc->bo);
                 return whandle->handle != -1;
         }
@@ -553,6 +571,7 @@ struct pipe_resource *
 vc4_resource_create(struct pipe_screen *pscreen,
                     const struct pipe_resource *tmpl)
 {
+        struct vc4_screen *screen = vc4_screen(pscreen);
         struct vc4_resource *rsc = vc4_resource_setup(pscreen, tmpl);
         struct pipe_resource *prsc = &rsc->base;
 
@@ -577,6 +596,13 @@ vc4_resource_create(struct pipe_screen *pscreen,
         if (!vc4_resource_bo_alloc(rsc))
                 goto fail;
 
+        if (screen->ro && tmpl->bind & PIPE_BIND_SCANOUT) {
+                rsc->scanout =
+                        renderonly_scanout_for_resource(prsc, screen->ro);
+                if (!rsc->scanout)
+                        goto fail;
+        }
+
         return prsc;
 fail:
         vc4_resource_destroy(pscreen, prsc);
@@ -646,6 +672,18 @@ vc4_resource_from_handle(struct pipe_screen *pscreen,
 
         rsc->vc4_format = get_resource_texture_format(prsc);
 
+        if (screen->ro) {
+                /* Make sure that renderonly has a handle to our buffer in the
+                 * display's fd, so that a later renderonly_get_handle()
+                 * returns correct handles or GEM names.
+                 */
+                rsc->scanout =
+                        renderonly_create_gpu_import_for_resource(prsc,
+                                                                  screen->ro);
+                if (!rsc->scanout)
+                        goto fail;
+        }
+
         if (miptree_debug) {
                 fprintf(stderr,
                         "rsc import %p (format %d), %dx%d: "
diff --git a/src/gallium/drivers/vc4/vc4_resource.h b/src/gallium/drivers/vc4/vc4_resource.h
index 877db513ac..32e73dddb3 100644
--- a/src/gallium/drivers/vc4/vc4_resource.h
+++ b/src/gallium/drivers/vc4/vc4_resource.h
@@ -54,6 +54,7 @@ struct vc4_surface {
 struct vc4_resource {
         struct pipe_resource base;
         struct vc4_bo *bo;
+        struct renderonly_scanout *scanout;
         struct vc4_resource_slice slices[VC4_MAX_MIP_LEVELS];
         uint32_t cube_map_stride;
         int cpp;
diff --git a/src/gallium/drivers/vc4/vc4_screen.c b/src/gallium/drivers/vc4/vc4_screen.c
index b87aaf73f9..6b35abb10e 100644
--- a/src/gallium/drivers/vc4/vc4_screen.c
+++ b/src/gallium/drivers/vc4/vc4_screen.c
@@ -100,6 +100,7 @@ vc4_screen_destroy(struct pipe_screen *pscreen)
         util_hash_table_destroy(screen->bo_handles);
         vc4_bufmgr_destroy(pscreen);
         slab_destroy_parent(&screen->transfer_pool);
+        free(screen->ro);
 
 #if USE_VC4_SIMULATOR
         vc4_simulator_destroy(screen);
@@ -605,7 +606,7 @@ vc4_get_chip_info(struct vc4_screen *screen)
 }
 
 struct pipe_screen *
-vc4_screen_create(int fd)
+vc4_screen_create(int fd, struct renderonly *ro)
 {
         struct vc4_screen *screen = rzalloc(NULL, struct vc4_screen);
         struct pipe_screen *pscreen;
@@ -620,6 +621,15 @@ vc4_screen_create(int fd)
         pscreen->is_format_supported = vc4_screen_is_format_supported;
 
         screen->fd = fd;
+        if (ro) {
+                screen->ro = renderonly_dup(ro);
+                if (!screen->ro) {
+                        fprintf(stderr, "Failed to dup renderonly object\n");
+                        ralloc_free(screen);
+                        return NULL;
+                }
+        }
+
         list_inithead(&screen->bo_cache.time_list);
         (void) mtx_init(&screen->bo_handles_mutex, mtx_plain);
         screen->bo_handles = util_hash_table_create(handle_hash, handle_compare);
diff --git a/src/gallium/drivers/vc4/vc4_screen.h b/src/gallium/drivers/vc4/vc4_screen.h
index 0f80ffb346..295633db46 100644
--- a/src/gallium/drivers/vc4/vc4_screen.h
+++ b/src/gallium/drivers/vc4/vc4_screen.h
@@ -25,6 +25,7 @@
 #define VC4_SCREEN_H
 
 #include "pipe/p_screen.h"
+#include "renderonly/renderonly.h"
 #include "os/os_thread.h"
 #include "state_tracker/drm_driver.h"
 #include "util/list.h"
@@ -55,6 +56,8 @@ struct vc4_simulator_file;
 
 struct vc4_screen {
         struct pipe_screen base;
+        struct renderonly *ro;
+
         int fd;
 
         int v3d_ver;
@@ -101,7 +104,7 @@ vc4_screen(struct pipe_screen *screen)
         return (struct vc4_screen *)screen;
 }
 
-struct pipe_screen *vc4_screen_create(int fd);
+struct pipe_screen *vc4_screen_create(int fd, struct renderonly *ro);
 
 const void *
 vc4_screen_get_compiler_options(struct pipe_screen *pscreen,
diff --git a/src/gallium/targets/dri/Makefile.am b/src/gallium/targets/dri/Makefile.am
index e61df81228..2d2e1aecec 100644
--- a/src/gallium/targets/dri/Makefile.am
+++ b/src/gallium/targets/dri/Makefile.am
@@ -82,6 +82,7 @@ include $(top_srcdir)/src/gallium/drivers/svga/Automake.inc
 include $(top_srcdir)/src/gallium/drivers/freedreno/Automake.inc
 
 include $(top_srcdir)/src/gallium/drivers/vc4/Automake.inc
+include $(top_srcdir)/src/gallium/drivers/pl111/Automake.inc
 
 include $(top_srcdir)/src/gallium/drivers/virgl/Automake.inc
 
diff --git a/src/gallium/targets/dri/target.c b/src/gallium/targets/dri/target.c
index d24a61d156..a831e35bea 100644
--- a/src/gallium/targets/dri/target.c
+++ b/src/gallium/targets/dri/target.c
@@ -73,6 +73,9 @@ DEFINE_LOADER_DRM_ENTRYPOINT(virtio_gpu)
 
 #if defined(GALLIUM_VC4)
 DEFINE_LOADER_DRM_ENTRYPOINT(vc4)
+#if defined(GALLIUM_PL111)
+DEFINE_LOADER_DRM_ENTRYPOINT(pl111)
+#endif
 #endif
 
 #if defined(GALLIUM_ETNAVIV)
diff --git a/src/gallium/winsys/pl111/drm/Android.mk b/src/gallium/winsys/pl111/drm/Android.mk
new file mode 100644
index 0000000000..16edd97ade
--- /dev/null
+++ b/src/gallium/winsys/pl111/drm/Android.mk
@@ -0,0 +1,33 @@
+# Copyright (C) 2014 Emil Velikov <emil.l.velikov at gmail.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+
+LOCAL_PATH := $(call my-dir)
+
+# get C_SOURCES
+include $(LOCAL_PATH)/Makefile.sources
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(C_SOURCES)
+
+LOCAL_MODULE := libmesa_winsys_pl111
+
+include $(GALLIUM_COMMON_MK)
+include $(BUILD_STATIC_LIBRARY)
diff --git a/src/gallium/winsys/pl111/drm/Makefile.am b/src/gallium/winsys/pl111/drm/Makefile.am
new file mode 100644
index 0000000000..34027dcbaa
--- /dev/null
+++ b/src/gallium/winsys/pl111/drm/Makefile.am
@@ -0,0 +1,34 @@
+# Copyright © 2012 Intel Corporation
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+
+include Makefile.sources
+include $(top_srcdir)/src/gallium/Automake.inc
+
+AM_CFLAGS = \
+	-I$(top_srcdir)/src/gallium/drivers \
+	-I$(top_srcdir)/src/gallium/winsys \
+	$(GALLIUM_WINSYS_CFLAGS) \
+	$(LIBDRM_CFLAGS)
+
+noinst_LTLIBRARIES = libpl111drm.la
+
+libpl111drm_la_SOURCES = $(C_SOURCES)
diff --git a/src/gallium/winsys/pl111/drm/Makefile.sources b/src/gallium/winsys/pl111/drm/Makefile.sources
new file mode 100644
index 0000000000..b4496e66c0
--- /dev/null
+++ b/src/gallium/winsys/pl111/drm/Makefile.sources
@@ -0,0 +1,3 @@
+C_SOURCES := \
+   pl111_drm_public.h \
+   pl111_drm_winsys.c
diff --git a/src/gallium/winsys/pl111/drm/pl111_drm_public.h b/src/gallium/winsys/pl111/drm/pl111_drm_public.h
new file mode 100644
index 0000000000..f362b0f1f9
--- /dev/null
+++ b/src/gallium/winsys/pl111/drm/pl111_drm_public.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2016 Christian Gmeiner <christian.gmeiner at gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Authors:
+ *    Christian Gmeiner <christian.gmeiner at gmail.com>
+ */
+
+#ifndef __PL111_DRM_PUBLIC_H__
+#define __PL111_DRM_PUBLIC_H__
+
+struct pipe_screen;
+
+struct pipe_screen *pl111_drm_screen_create(int fd);
+
+#endif /* __PL111_DRM_PUBLIC_H__ */
diff --git a/src/gallium/winsys/pl111/drm/pl111_drm_winsys.c b/src/gallium/winsys/pl111/drm/pl111_drm_winsys.c
new file mode 100644
index 0000000000..ef7b080fba
--- /dev/null
+++ b/src/gallium/winsys/pl111/drm/pl111_drm_winsys.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2016 Christian Gmeiner <christian.gmeiner at gmail.com>
+ * Copyright (C) 2017 Broadcom
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "pl111_drm_public.h"
+#include "vc4/drm/vc4_drm_public.h"
+#include "xf86drm.h"
+
+#include "pipe/p_screen.h"
+#include "renderonly/renderonly.h"
+
+struct pipe_screen *pl111_drm_screen_create(int fd)
+{
+   struct renderonly ro = {
+      /* Passes the vc4-allocated BO through to the pl111 DRM device using
+       * PRIME buffer sharing.  The VC4 BO must be linear, which the SCANOUT
+       * flag on allocation will have ensured.
+       */
+      .create_for_resource = renderonly_create_gpu_import_for_resource,
+      .kms_fd = fd,
+      .gpu_fd = drmOpenWithType("vc4", NULL, DRM_NODE_RENDER),
+   };
+
+   if (ro.gpu_fd < 0)
+      return NULL;
+
+   struct pipe_screen *screen = vc4_drm_screen_create_renderonly(&ro);
+   if (!screen)
+      close(ro.gpu_fd);
+
+   return screen;
+}
diff --git a/src/gallium/winsys/vc4/drm/vc4_drm_public.h b/src/gallium/winsys/vc4/drm/vc4_drm_public.h
index f9d0585a3e..102c1487ba 100644
--- a/src/gallium/winsys/vc4/drm/vc4_drm_public.h
+++ b/src/gallium/winsys/vc4/drm/vc4_drm_public.h
@@ -25,7 +25,9 @@
 #define __VC4_DRM_PUBLIC_H__
 
 struct pipe_screen;
+struct renderonly;
 
 struct pipe_screen *vc4_drm_screen_create(int drmFD);
+struct pipe_screen *vc4_drm_screen_create_renderonly(struct renderonly *ro);
 
 #endif /* __VC4_DRM_PUBLIC_H__ */
diff --git a/src/gallium/winsys/vc4/drm/vc4_drm_winsys.c b/src/gallium/winsys/vc4/drm/vc4_drm_winsys.c
index 23fe8e7b9c..b2ffa90fe1 100644
--- a/src/gallium/winsys/vc4/drm/vc4_drm_winsys.c
+++ b/src/gallium/winsys/vc4/drm/vc4_drm_winsys.c
@@ -24,12 +24,18 @@
 #include <unistd.h>
 #include <fcntl.h>
 
+#include "renderonly/renderonly.h"
 #include "vc4_drm_public.h"
-
 #include "vc4/vc4_screen.h"
 
 struct pipe_screen *
 vc4_drm_screen_create(int fd)
 {
-	return vc4_screen_create(fcntl(fd, F_DUPFD_CLOEXEC, 3));
+   return vc4_screen_create(fcntl(fd, F_DUPFD_CLOEXEC, 3), NULL);
+}
+
+struct pipe_screen *
+vc4_drm_screen_create_renderonly(struct renderonly *ro)
+{
+   return vc4_screen_create(fcntl(ro->gpu_fd, F_DUPFD_CLOEXEC, 3), ro);
 }




More information about the mesa-commit mailing list