summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Sliwa <dominik.sliwa@toradex.com>2017-01-09 17:35:46 +0100
committerDominik Sliwa <dominik.sliwa@toradex.com>2017-01-11 21:59:33 +0100
commit6c22936df0c551961df61cc428e6590d2f8bbb6d (patch)
tree163ad22e51e402a02ac2fd98156f1db0f750d3a1
parentd54c4ca13c2976671fb2e91b774ae1a94039715a (diff)
apalis-tk1-mainline: Move GPU acceleration support to mesa
Instead of patching every app, let's patch mesa to pretend that we have a normal GPU. based on: github.com/Gnurou/mesa/commits/renderonly Signed-off-by: Dominik Sliwa <dominik.sliwa@toradex.com> Acked-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
-rw-r--r--recipes-graphics/mesa/mesa/0001-gallium-add-renderonly-library.patch365
-rw-r--r--recipes-graphics/mesa/mesa/0004-gallium-add-tegra-support.patch514
-rw-r--r--recipes-graphics/mesa/mesa/0005-tegra-open-card1-instead-of-renderD128.patch29
-rw-r--r--recipes-graphics/mesa/mesa/0006-HACK-make-DRI-work-under-X.patch24
-rw-r--r--recipes-graphics/mesa/mesa/0008-remove-dependency-on-libdrm_tegra.patch48
-rw-r--r--recipes-graphics/mesa/mesa_%.bbappend24
-rw-r--r--recipes-graphics/xorg-xserver/xserver-xorg-1.18.4/0001-HACK-use-render-nodes-and-tegra-tiling-format.patch145
-rw-r--r--recipes-graphics/xorg-xserver/xserver-xorg-1.18.4/0002-HACK-enable-GLX-with-DRI3.patch72
-rw-r--r--recipes-graphics/xorg-xserver/xserver-xorg_1.18.4.bbappend6
-rw-r--r--recipes-kernel/linux/linux-toradex-mainline-4.9/0001-drm-tegra-add-tiling-FB-modifiers.patch128
-rw-r--r--recipes-kernel/linux/linux-toradex-mainline_4.9.bb1
11 files changed, 1132 insertions, 224 deletions
diff --git a/recipes-graphics/mesa/mesa/0001-gallium-add-renderonly-library.patch b/recipes-graphics/mesa/mesa/0001-gallium-add-renderonly-library.patch
new file mode 100644
index 0000000..884f59b
--- /dev/null
+++ b/recipes-graphics/mesa/mesa/0001-gallium-add-renderonly-library.patch
@@ -0,0 +1,365 @@
+From f8bf6404b0133a355a58c72fb4381943a0022959 Mon Sep 17 00:00:00 2001
+From: Christian Gmeiner <christian.gmeiner@gmail.com>
+Date: Sun, 27 Nov 2016 22:27:18 +0100
+Subject: [PATCH 1/8] gallium: add renderonly library
+
+This a very lightweight library to add basic support for
+renderonly GPUs. It does all the magic regarding in/exporting
+buffers etc. This library will likely break android support and
+hopefully will get replaced with a better solution based on gbm2.
+
+Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
+---
+ src/gallium/Automake.inc | 5 +
+ src/gallium/auxiliary/Makefile.am | 10 ++
+ src/gallium/auxiliary/Makefile.sources | 4 +
+ src/gallium/auxiliary/renderonly/renderonly.c | 199 ++++++++++++++++++++++++++
+ src/gallium/auxiliary/renderonly/renderonly.h | 81 +++++++++++
+ 5 files changed, 299 insertions(+)
+ create mode 100644 src/gallium/auxiliary/renderonly/renderonly.c
+ create mode 100644 src/gallium/auxiliary/renderonly/renderonly.h
+
+diff --git a/src/gallium/Automake.inc b/src/gallium/Automake.inc
+index 6fe2e22..6aadcb9 100644
+--- a/src/gallium/Automake.inc
++++ b/src/gallium/Automake.inc
+@@ -50,6 +50,11 @@ GALLIUM_COMMON_LIB_DEPS = \
+ $(PTHREAD_LIBS) \
+ $(DLOPEN_LIBS)
+
++if HAVE_LIBDRM
++GALLIUM_COMMON_LIB_DEPS += \
++ $(LIBDRM_LIBS)
++endif
++
+ GALLIUM_WINSYS_CFLAGS = \
+ -I$(top_srcdir)/src \
+ -I$(top_srcdir)/include \
+diff --git a/src/gallium/auxiliary/Makefile.am b/src/gallium/auxiliary/Makefile.am
+index 4a4a4fb..6b63cf1 100644
+--- a/src/gallium/auxiliary/Makefile.am
++++ b/src/gallium/auxiliary/Makefile.am
+@@ -20,6 +20,16 @@ libgallium_la_SOURCES = \
+ $(NIR_SOURCES) \
+ $(GENERATED_SOURCES)
+
++if HAVE_LIBDRM
++
++AM_CFLAGS += \
++ $(LIBDRM_CFLAGS)
++
++libgallium_la_SOURCES += \
++ $(RENDERONLY_SOURCES)
++
++endif
++
+ if HAVE_MESA_LLVM
+
+ AM_CFLAGS += \
+diff --git a/src/gallium/auxiliary/Makefile.sources b/src/gallium/auxiliary/Makefile.sources
+index 5d4fe30..8d3e4a9 100644
+--- a/src/gallium/auxiliary/Makefile.sources
++++ b/src/gallium/auxiliary/Makefile.sources
+@@ -435,3 +435,7 @@ GALLIVM_SOURCES := \
+ draw/draw_llvm_sample.c \
+ draw/draw_pt_fetch_shade_pipeline_llvm.c \
+ draw/draw_vs_llvm.c
++
++RENDERONLY_SOURCES := \
++ renderonly/renderonly.c \
++ renderonly/renderonly.h
+diff --git a/src/gallium/auxiliary/renderonly/renderonly.c b/src/gallium/auxiliary/renderonly/renderonly.c
+new file mode 100644
+index 0000000..c4ea784
+--- /dev/null
++++ b/src/gallium/auxiliary/renderonly/renderonly.c
+@@ -0,0 +1,199 @@
++/*
++ * Copyright (C) 2016 Christian Gmeiner <christian.gmeiner@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@gmail.com>
++ */
++
++#include "renderonly/renderonly.h"
++
++#include <errno.h>
++#include <fcntl.h>
++#include <stdio.h>
++#include <sys/ioctl.h>
++#include <xf86drm.h>
++
++#include "state_tracker/drm_driver.h"
++#include "pipe/p_screen.h"
++#include "util/u_memory.h"
++
++struct pipe_screen *
++renderonly_screen_create(int fd, const struct renderonly_ops *ops, void *priv)
++{
++ struct renderonly *ro;
++
++ ro = CALLOC_STRUCT(renderonly);
++ if (!ro)
++ return NULL;
++
++ ro->kms_fd = fd;
++ ro->ops = ops;
++ ro->priv = priv;
++
++ ro->screen = ops->create(ro);
++ if (!ro->screen)
++ goto cleanup;
++
++ return ro->screen;
++
++cleanup:
++ FREE(ro);
++
++ return NULL;
++}
++
++static bool
++use_kms_bumb_buffer(struct renderonly_scanout *scanout,
++ struct pipe_resource *rsc, struct renderonly *ro)
++{
++ struct winsys_handle handle;
++ int prime_fd, err;
++ struct drm_mode_create_dumb create_dumb = {
++ .width = rsc->width0,
++ .height = rsc->height0,
++ .bpp = 32,
++ };
++ struct drm_mode_destroy_dumb destroy_dumb = { };
++
++ /* create dumb buffer at scanout GPU */
++ err = ioctl(ro->kms_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb);
++ if (err < 0) {
++ fprintf(stderr, "DRM_IOCTL_MODE_CREATE_DUMB failed: %s\n",
++ strerror(errno));
++ return false;
++ }
++
++ scanout->handle = create_dumb.handle;
++ scanout->stride = create_dumb.pitch;
++
++ /* export dumb buffer */
++ err = drmPrimeHandleToFD(ro->kms_fd, create_dumb.handle, O_CLOEXEC,
++ &prime_fd);
++ if (err < 0) {
++ fprintf(stderr, "failed to export dumb buffer: %s\n", strerror(errno));
++ goto out_free_dumb;
++ }
++
++ /* import dumb buffer */
++ handle.type = DRM_API_HANDLE_TYPE_FD;
++ handle.handle = prime_fd;
++ handle.stride = create_dumb.pitch;
++
++ scanout->prime = ro->screen->resource_from_handle(ro->screen, rsc,
++ &handle, PIPE_HANDLE_USAGE_READ_WRITE);
++
++ if (!scanout->prime) {
++ fprintf(stderr, "failed to create resource_from_handle: %s\n", strerror(errno));
++ goto out_free_dumb;
++ }
++
++ return true;
++
++out_free_dumb:
++ destroy_dumb.handle = scanout->handle;
++ ioctl(ro->kms_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
++
++ return false;
++}
++
++static bool
++import_gpu_scanout(struct renderonly_scanout *scanout,
++ struct pipe_resource *rsc, struct renderonly *ro)
++{
++ struct pipe_screen *screen = ro->screen;
++ boolean status;
++ int fd, err;
++ struct winsys_handle handle = {
++ .type = DRM_API_HANDLE_TYPE_FD
++ };
++
++ status = screen->resource_get_handle(screen, rsc, &handle,
++ PIPE_HANDLE_USAGE_READ_WRITE);
++ if (!status)
++ return false;
++
++ scanout->stride = handle.stride;
++ fd = handle.handle;
++
++ err = drmPrimeFDToHandle(ro->kms_fd, fd, &scanout->handle);
++ close(fd);
++
++ if (err < 0) {
++ fprintf(stderr, "drmPrimeFDToHandle() failed: %s\n", strerror(errno));
++ return false;
++ }
++
++ if (ro->ops->tiling) {
++ err = ro->ops->tiling(ro->kms_fd, scanout->handle);
++ if (err < 0) {
++ fprintf(stderr, "failed to set tiling parameters: %s\n", strerror(errno));
++ close(scanout->handle);
++ return false;
++ }
++ }
++
++ return true;
++}
++
++struct renderonly_scanout *
++renderonly_scanout_for_resource(struct pipe_resource *rsc, struct renderonly *ro)
++{
++ struct renderonly_scanout *scanout;
++ bool ret;
++
++ scanout = CALLOC_STRUCT(renderonly_scanout);
++ if (!scanout)
++ return NULL;
++
++ if (ro->ops->intermediate_rendering)
++ ret = use_kms_bumb_buffer(scanout, rsc, ro);
++ else
++ ret = import_gpu_scanout(scanout, rsc, ro);
++
++ if (!ret) {
++ FREE(scanout);
++ scanout = NULL;
++ }
++
++ return scanout;
++}
++
++struct renderonly_scanout *
++renderonly_scanout_for_prime(struct pipe_resource *rsc, struct renderonly *ro)
++{
++ struct renderonly_scanout *scanout;
++
++ scanout = CALLOC_STRUCT(renderonly_scanout);
++ if (!scanout)
++ return NULL;
++
++ scanout->prime = rsc;
++
++ return scanout;
++}
++
++void
++renderonly_scanout_destroy(struct renderonly_scanout *scanout)
++{
++ close(scanout->handle);
++ FREE(scanout);
++}
+diff --git a/src/gallium/auxiliary/renderonly/renderonly.h b/src/gallium/auxiliary/renderonly/renderonly.h
+new file mode 100644
+index 0000000..5a98992
+--- /dev/null
++++ b/src/gallium/auxiliary/renderonly/renderonly.h
+@@ -0,0 +1,81 @@
++/*
++ * Copyright (C) 2016 Christian Gmeiner <christian.gmeiner@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@gmail.com>
++ */
++
++#ifndef RENDERONLY_H
++#define RENDERONLY_H
++
++#include <stdint.h>
++#include "state_tracker/drm_driver.h"
++#include "pipe/p_state.h"
++
++struct renderonly;
++
++struct renderonly_ops {
++ struct pipe_screen *(*create)(struct renderonly *ctx);
++ int (*tiling)(int fd, uint32_t handle);
++ bool intermediate_rendering;
++};
++
++struct renderonly {
++ int kms_fd;
++ const struct renderonly_ops *ops;
++ struct pipe_screen *screen;
++ void *priv;
++};
++
++struct pipe_screen *
++renderonly_screen_create(int fd, const struct renderonly_ops *ops, void *priv);
++
++struct renderonly_scanout {
++ uint32_t handle;
++ uint32_t stride;
++
++ struct pipe_resource *prime;
++};
++
++struct renderonly_scanout *
++renderonly_scanout_for_resource(struct pipe_resource *rsc, struct renderonly *ro);
++
++struct renderonly_scanout *
++renderonly_scanout_for_prime(struct pipe_resource *rsc, struct renderonly *ro);
++
++void
++renderonly_scanout_destroy(struct renderonly_scanout *scanout);
++
++static inline boolean
++renderonly_get_handle(struct renderonly_scanout *scanout,
++ struct winsys_handle *handle)
++{
++ if (!scanout)
++ return FALSE;
++
++ handle->handle = scanout->handle;
++ handle->stride = scanout->stride;
++
++ return TRUE;
++}
++
++#endif /* RENDERONLY_H_ */
+--
+2.9.3
+
diff --git a/recipes-graphics/mesa/mesa/0004-gallium-add-tegra-support.patch b/recipes-graphics/mesa/mesa/0004-gallium-add-tegra-support.patch
new file mode 100644
index 0000000..536d6cd
--- /dev/null
+++ b/recipes-graphics/mesa/mesa/0004-gallium-add-tegra-support.patch
@@ -0,0 +1,514 @@
+From 430452494ff5f3454290cb0c80f9d1dbd072ecff Mon Sep 17 00:00:00 2001
+From: Christian Gmeiner <christian.gmeiner@gmail.com>
+Date: Sun, 21 Aug 2016 22:10:12 +0200
+Subject: [PATCH 4/8] gallium: add tegra support
+
+Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
+[acourbot@nvidia.com: port to latest branch]
+Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
+---
+ configure.ac | 13 ++++++-
+ 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/nouveau/nouveau_buffer.c | 3 ++
+ src/gallium/drivers/nouveau/nouveau_buffer.h | 2 ++
+ src/gallium/drivers/nouveau/nouveau_screen.h | 3 ++
+ src/gallium/drivers/nouveau/nv50/nv50_miptree.c | 3 ++
+ src/gallium/drivers/nouveau/nvc0/nvc0_resource.c | 18 ++++++++--
+ src/gallium/drivers/tegra/Automake.inc | 9 +++++
+ src/gallium/drivers/tegra/Makefile.am | 9 +++++
+ src/gallium/targets/dri/Makefile.am | 2 ++
+ src/gallium/targets/dri/target.c | 11 ++++++
+ .../winsys/nouveau/drm/nouveau_drm_public.h | 2 ++
+ .../winsys/nouveau/drm/nouveau_drm_winsys.c | 10 ++++++
+ src/gallium/winsys/tegra/drm/Android.mk | 33 +++++++++++++++++
+ src/gallium/winsys/tegra/drm/Makefile.am | 33 +++++++++++++++++
+ src/gallium/winsys/tegra/drm/Makefile.sources | 3 ++
+ src/gallium/winsys/tegra/drm/tegra_drm_public.h | 8 +++++
+ src/gallium/winsys/tegra/drm/tegra_drm_winsys.c | 41 ++++++++++++++++++++++
+ 21 files changed, 235 insertions(+), 3 deletions(-)
+ create mode 100644 src/gallium/drivers/tegra/Automake.inc
+ create mode 100644 src/gallium/drivers/tegra/Makefile.am
+ create mode 100644 src/gallium/winsys/tegra/drm/Android.mk
+ create mode 100644 src/gallium/winsys/tegra/drm/Makefile.am
+ create mode 100644 src/gallium/winsys/tegra/drm/Makefile.sources
+ create mode 100644 src/gallium/winsys/tegra/drm/tegra_drm_public.h
+ create mode 100644 src/gallium/winsys/tegra/drm/tegra_drm_winsys.c
+
+diff --git a/configure.ac b/configure.ac
+index c0f81ce..3d288e8 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -77,6 +77,7 @@ LIBDRM_NOUVEAU_REQUIRED=2.4.66
+ LIBDRM_NVVIEUX_REQUIRED=2.4.66
+ LIBDRM_NOUVEAU_REQUIRED=2.4.66
+ LIBDRM_FREEDRENO_REQUIRED=2.4.67
++LIBDRM_TEGRA_REQUIRED=2.4.68
+ DRI2PROTO_REQUIRED=2.6
+ DRI3PROTO_REQUIRED=1.0
+ PRESENTPROTO_REQUIRED=1.0
+@@ -1021,7 +1022,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,ilo,nouveau,r300,r600,radeonsi,freedreno,svga,swrast,vc4,virgl"
++ "i915,ilo,nouveau,r300,r600,radeonsi,freedreno,svga,swrast,vc4,virgl,tegra"
+ @<:@default=r300,r600,svga,swrast@:>@])],
+ [with_gallium_drivers="$withval"],
+ [with_gallium_drivers="$GALLIUM_DRIVERS_DEFAULT"])
+@@ -2491,6 +2492,13 @@ if test -n "$with_gallium_drivers"; then
+ require_libdrm "virgl"
+ require_basic_egl "virgl"
+ ;;
++ xtegra)
++ PKG_CHECK_MODULES([TEGRA], [libdrm_tegra >= $LIBDRM_TEGRA_REQUIRED])
++ HAVE_GALLIUM_TEGRA=yes
++ gallium_require_drm "tegra"
++ gallium_require_drm_loader
++ require_egl_drm "tegra"
++ ;;
+ *)
+ AC_MSG_ERROR([Unknown Gallium driver: $driver])
+ ;;
+@@ -2582,6 +2590,7 @@ AM_CONDITIONAL(HAVE_GALLIUM_VC4, test "x$HAVE_GALLIUM_VC4" = xyes)
+ "x$HAVE_GALLIUM_SWR" = xyes)
+ AM_CONDITIONAL(HAVE_GALLIUM_VC4, test "x$HAVE_GALLIUM_VC4" = xyes)
+ AM_CONDITIONAL(HAVE_GALLIUM_VIRGL, test "x$HAVE_GALLIUM_VIRGL" = xyes)
++AM_CONDITIONAL(HAVE_GALLIUM_TEGRA, test "x$HAVE_GALLIUM_TEGRA" = xyes)
+
+ AM_CONDITIONAL(HAVE_GALLIUM_STATIC_TARGETS, test "x$enable_shared_pipe_drivers" = xno)
+
+@@ -2732,6 +2741,7 @@ AC_CONFIG_FILES([Makefile
+ src/gallium/drivers/imx/Makefile
+ src/gallium/drivers/vc4/Makefile
+ src/gallium/drivers/virgl/Makefile
++ src/gallium/drivers/tegra/Makefile
+ src/gallium/state_trackers/clover/Makefile
+ src/gallium/state_trackers/dri/Makefile
+ src/gallium/state_trackers/glx/xlib/Makefile
+@@ -2776,6 +2786,7 @@ AC_CONFIG_FILES([Makefile
+ src/gallium/winsys/vc4/drm/Makefile
+ src/gallium/winsys/virgl/drm/Makefile
+ src/gallium/winsys/virgl/vtest/Makefile
++ src/gallium/winsys/tegra/drm/Makefile
+ src/gbm/Makefile
+ src/gbm/main/gbm.pc
+ src/glx/Makefile
+diff --git a/src/gallium/Makefile.am b/src/gallium/Makefile.am
+index f910f31..0f887d2 100644
+--- a/src/gallium/Makefile.am
++++ b/src/gallium/Makefile.am
+@@ -100,6 +100,10 @@ if HAVE_GALLIUM_VIRGL
+ SUBDIRS += drivers/virgl winsys/virgl/drm winsys/virgl/vtest
+ endif
+
++if HAVE_GALLIUM_TEGRA
++SUBDIRS += drivers/tegra winsys/tegra/drm
++endif
++
+ ## the sw winsys'
+ SUBDIRS += winsys/sw/null
+
+diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
+index 6c89fe5..ff1166c 100644
+--- a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
++++ b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
+@@ -163,6 +163,12 @@ static const struct drm_driver_descriptor driver_descriptors[] = {
+ .create_screen = pipe_vc4_create_screen,
+ .configuration = configuration_query,
+ },
++ {
++ .name = "tegra",
++ .driver_name = "tegra",
++ .create_screen = pipe_tegra_create_screen,
++ .configuration = configuration_query,
++ },
+ };
+ #endif
+
+diff --git a/src/gallium/auxiliary/target-helpers/drm_helper.h b/src/gallium/auxiliary/target-helpers/drm_helper.h
+index fbb4ce4..22932d3 100644
+--- a/src/gallium/auxiliary/target-helpers/drm_helper.h
++++ b/src/gallium/auxiliary/target-helpers/drm_helper.h
+@@ -312,4 +312,27 @@ pipe_imx_drm_create_screen(int fd)
+
+ #endif
+
++#ifdef GALLIUM_TEGRA
++#include "tegra/drm/tegra_drm_public.h"
++
++struct pipe_screen *
++pipe_tegra_create_screen(int fd)
++{
++ struct pipe_screen *screen;
++
++ screen = tegra_drm_screen_create(fd);
++ return screen ? debug_screen_wrap(screen) : NULL;
++}
++
++#else
++
++struct pipe_screen *
++pipe_tegra_create_screen(int fd)
++{
++ fprintf(stderr, "tegra: driver missing\n");
++ return NULL;
++}
++
++#endif
++
+ #endif /* DRM_HELPER_H */
+diff --git a/src/gallium/auxiliary/target-helpers/drm_helper_public.h b/src/gallium/auxiliary/target-helpers/drm_helper_public.h
+index bc12b21..5525bdf 100644
+--- a/src/gallium/auxiliary/target-helpers/drm_helper_public.h
++++ b/src/gallium/auxiliary/target-helpers/drm_helper_public.h
+@@ -40,4 +40,7 @@ pipe_etna_create_screen(int fd);
+ struct pipe_screen *
+ pipe_imx_drm_create_screen(int fd);
+
++struct pipe_screen *
++pipe_tegra_create_screen(int fd);
++
+ #endif /* _DRM_HELPER_PUBLIC_H */
+diff --git a/src/gallium/drivers/nouveau/nouveau_buffer.c b/src/gallium/drivers/nouveau/nouveau_buffer.c
+index 17052b2..95dcaad 100644
+--- a/src/gallium/drivers/nouveau/nouveau_buffer.c
++++ b/src/gallium/drivers/nouveau/nouveau_buffer.c
+@@ -128,6 +128,9 @@ nouveau_buffer_destroy(struct pipe_screen *pscreen,
+
+ util_range_destroy(&res->valid_buffer_range);
+
++ if (res->scanout)
++ renderonly_scanout_destroy(res->scanout);
++
+ FREE(res);
+
+ NOUVEAU_DRV_STAT(nouveau_screen(pscreen), buf_obj_current_count, -1);
+diff --git a/src/gallium/drivers/nouveau/nouveau_buffer.h b/src/gallium/drivers/nouveau/nouveau_buffer.h
+index 3a33fae..c01fda4 100644
+--- a/src/gallium/drivers/nouveau/nouveau_buffer.h
++++ b/src/gallium/drivers/nouveau/nouveau_buffer.h
+@@ -50,6 +50,8 @@ struct nv04_resource {
+
+ /* buffer range that has been initialized */
+ struct util_range valid_buffer_range;
++
++ struct renderonly_scanout *scanout;
+ };
+
+ void
+diff --git a/src/gallium/drivers/nouveau/nouveau_screen.h b/src/gallium/drivers/nouveau/nouveau_screen.h
+index 28c4760..e0ec614 100644
+--- a/src/gallium/drivers/nouveau/nouveau_screen.h
++++ b/src/gallium/drivers/nouveau/nouveau_screen.h
+@@ -2,6 +2,7 @@
+ #define __NOUVEAU_SCREEN_H__
+
+ #include "pipe/p_screen.h"
++#include "renderonly/renderonly.h"
+ #include "util/u_memory.h"
+
+ #ifdef DEBUG
+@@ -59,6 +60,8 @@ struct nouveau_screen {
+ unsigned profiles_present;
+ } firmware_info;
+
++ struct renderonly *ro;
++
+ #ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS
+ union {
+ uint64_t v[29];
+diff --git a/src/gallium/drivers/nouveau/nv50/nv50_miptree.c b/src/gallium/drivers/nouveau/nv50/nv50_miptree.c
+index f2e304f..29e95a6 100644
+--- a/src/gallium/drivers/nouveau/nv50/nv50_miptree.c
++++ b/src/gallium/drivers/nouveau/nv50/nv50_miptree.c
+@@ -189,6 +189,9 @@ nv50_miptree_get_handle(struct pipe_screen *pscreen,
+ if (!mt || !mt->base.bo)
+ return false;
+
++ if (renderonly_get_handle(mt->base.scanout, whandle))
++ return TRUE;
++
+ stride = mt->level[0].pitch;
+
+ return nouveau_screen_bo_get_handle(pscreen,
+diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c b/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c
+index 9bafe3d..adfd61c 100644
+--- a/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c
++++ b/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c
+@@ -8,12 +8,26 @@ static struct pipe_resource *
+ nvc0_resource_create(struct pipe_screen *screen,
+ const struct pipe_resource *templ)
+ {
++ struct nouveau_screen *scr = nouveau_screen(screen);
++ struct pipe_resource *pres;
++
+ switch (templ->target) {
+ case PIPE_BUFFER:
+- return nouveau_buffer_create(screen, templ);
++ pres = nouveau_buffer_create(screen, templ);
++ break;
+ default:
+- return nvc0_miptree_create(screen, templ);
++ pres = nvc0_miptree_create(screen, templ);
++ break;
+ }
++
++ if (pres) {
++ struct nv04_resource *res = nv04_resource(pres);
++
++ if (templ->bind & PIPE_BIND_SCANOUT)
++ res->scanout = renderonly_scanout_for_resource(pres, scr->ro);
++ }
++
++ return pres;
+ }
+
+ static struct pipe_resource *
+diff --git a/src/gallium/drivers/tegra/Automake.inc b/src/gallium/drivers/tegra/Automake.inc
+new file mode 100644
+index 0000000..89e0441
+--- /dev/null
++++ b/src/gallium/drivers/tegra/Automake.inc
+@@ -0,0 +1,9 @@
++if HAVE_GALLIUM_TEGRA
++
++TARGET_DRIVERS += tegra
++TARGET_CPPFLAGS += -DGALLIUM_TEGRA
++TARGET_LIB_DEPS += \
++ $(top_builddir)/src/gallium/winsys/tegra/drm/libtegradrm.la \
++ $(LIBDRM_LIBS)
++
++endif
+diff --git a/src/gallium/drivers/tegra/Makefile.am b/src/gallium/drivers/tegra/Makefile.am
+new file mode 100644
+index 0000000..30f4689
+--- /dev/null
++++ b/src/gallium/drivers/tegra/Makefile.am
+@@ -0,0 +1,9 @@
++include $(top_srcdir)/src/gallium/Automake.inc
++
++AM_CPPFLAGS = \
++ $(GALLIUM_CFLAGS) \
++ $(TEGRA_CFLAGS)
++
++noinst_LTLIBRARIES = libtegra.la
++
++libtegra_la_SOURCES =
+diff --git a/src/gallium/targets/dri/Makefile.am b/src/gallium/targets/dri/Makefile.am
+index 06ade45..ed412d7 100644
+--- a/src/gallium/targets/dri/Makefile.am
++++ b/src/gallium/targets/dri/Makefile.am
+@@ -91,6 +91,8 @@ include $(top_srcdir)/src/gallium/drivers/vc4/Automake.inc
+
+ include $(top_srcdir)/src/gallium/drivers/virgl/Automake.inc
+
++include $(top_srcdir)/src/gallium/drivers/tegra/Automake.inc
++
+ include $(top_srcdir)/src/gallium/drivers/softpipe/Automake.inc
+ include $(top_srcdir)/src/gallium/drivers/llvmpipe/Automake.inc
+ include $(top_srcdir)/src/gallium/drivers/swr/Automake.inc
+diff --git a/src/gallium/targets/dri/target.c b/src/gallium/targets/dri/target.c
+index 01532e2..126cadf 100644
+--- a/src/gallium/targets/dri/target.c
++++ b/src/gallium/targets/dri/target.c
+@@ -162,3 +162,14 @@ PUBLIC const __DRIextension **__driDriverGetExtensions_i965(void)
+ }
+ #endif
+ #endif
++
++#if defined(GALLIUM_TEGRA)
++
++const __DRIextension **__driDriverGetExtensions_tegra(void);
++
++PUBLIC const __DRIextension **__driDriverGetExtensions_tegra(void)
++{
++ globalDriverAPI = &galliumdrm_driver_api;
++ return galliumdrm_driver_extensions;
++}
++#endif
+diff --git a/src/gallium/winsys/nouveau/drm/nouveau_drm_public.h b/src/gallium/winsys/nouveau/drm/nouveau_drm_public.h
+index 67b7c44..455ea77 100644
+--- a/src/gallium/winsys/nouveau/drm/nouveau_drm_public.h
++++ b/src/gallium/winsys/nouveau/drm/nouveau_drm_public.h
+@@ -3,7 +3,9 @@
+ #define __NOUVEAU_DRM_PUBLIC_H__
+
+ struct pipe_screen;
++struct renderonly;
+
+ struct pipe_screen *nouveau_drm_screen_create(int drmFD);
++struct pipe_screen *nouveau_drm_screen_create_renderonly(int fd, struct renderonly *ro);
+
+ #endif
+diff --git a/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c b/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c
+index cc9dfa7..acbd3fe 100644
+--- a/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c
++++ b/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c
+@@ -157,3 +157,13 @@ err:
+ pipe_mutex_unlock(nouveau_screen_mutex);
+ return NULL;
+ }
++
++struct pipe_screen *nouveau_drm_screen_create_renderonly(int fd, struct renderonly *ro)
++{
++ struct nouveau_screen *screen = nouveau_drm_screen_create(fd);
++
++ if (screen)
++ screen->ro = ro;
++
++ return screen;
++}
+diff --git a/src/gallium/winsys/tegra/drm/Android.mk b/src/gallium/winsys/tegra/drm/Android.mk
+new file mode 100644
+index 0000000..a48dca48
+--- /dev/null
++++ b/src/gallium/winsys/tegra/drm/Android.mk
+@@ -0,0 +1,33 @@
++# Copyright (C) 2014 Emil Velikov <emil.l.velikov@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_tegra
++
++include $(GALLIUM_COMMON_MK)
++include $(BUILD_STATIC_LIBRARY)
+diff --git a/src/gallium/winsys/tegra/drm/Makefile.am b/src/gallium/winsys/tegra/drm/Makefile.am
+new file mode 100644
+index 0000000..39068fe
+--- /dev/null
++++ b/src/gallium/winsys/tegra/drm/Makefile.am
+@@ -0,0 +1,33 @@
++# 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 \
++ $(GALLIUM_WINSYS_CFLAGS) \
++ $(TEGRA_CFLAGS)
++
++noinst_LTLIBRARIES = libtegradrm.la
++
++libtegradrm_la_SOURCES = $(C_SOURCES)
+diff --git a/src/gallium/winsys/tegra/drm/Makefile.sources b/src/gallium/winsys/tegra/drm/Makefile.sources
+new file mode 100644
+index 0000000..29a0edc
+--- /dev/null
++++ b/src/gallium/winsys/tegra/drm/Makefile.sources
+@@ -0,0 +1,3 @@
++C_SOURCES := \
++ tegra_drm_public.h \
++ tegra_drm_winsys.c
+diff --git a/src/gallium/winsys/tegra/drm/tegra_drm_public.h b/src/gallium/winsys/tegra/drm/tegra_drm_public.h
+new file mode 100644
+index 0000000..813268f
+--- /dev/null
++++ b/src/gallium/winsys/tegra/drm/tegra_drm_public.h
+@@ -0,0 +1,8 @@
++#ifndef __TEGRA_DRM_PUBLIC_H__
++#define __TEGRA_DRM_PUBLIC_H__
++
++struct pipe_screen;
++
++struct pipe_screen *tegra_drm_screen_create(int drmFD);
++
++#endif /* __TEGRA_DRM_PUBLIC_H__ */
+diff --git a/src/gallium/winsys/tegra/drm/tegra_drm_winsys.c b/src/gallium/winsys/tegra/drm/tegra_drm_winsys.c
+new file mode 100644
+index 0000000..361370d
+--- /dev/null
++++ b/src/gallium/winsys/tegra/drm/tegra_drm_winsys.c
+@@ -0,0 +1,41 @@
++#include "tegra_drm_public.h"
++
++#include "renderonly/renderonly.h"
++#include "../winsys/nouveau/drm/nouveau_drm_public.h"
++
++#include <fcntl.h>
++#include <libdrm/tegra_drm.h>
++#include <xf86drm.h>
++
++static struct pipe_screen *
++tegra_create(struct renderonly *ro)
++{
++ int fd = open("/dev/dri/renderD128", O_RDWR | O_CLOEXEC);
++
++ if (fd == -1)
++ return NULL;
++
++ return nouveau_drm_screen_create_renderonly(fd, ro);
++}
++
++static int
++tegra_tiling(int fd, uint32_t handle)
++{
++ struct drm_tegra_gem_set_tiling args = {
++ .handle = handle,
++ .mode = DRM_TEGRA_GEM_TILING_MODE_BLOCK,
++ .value = 4
++ };
++
++ return drmIoctl(fd, DRM_IOCTL_TEGRA_GEM_SET_TILING, &args);
++}
++
++static const struct renderonly_ops ro_ops = {
++ .create = tegra_create,
++ .tiling = tegra_tiling
++};
++
++struct pipe_screen *tegra_drm_screen_create(int fd)
++{
++ return renderonly_screen_create(fd, &ro_ops, NULL);
++}
+--
+2.9.3
+
diff --git a/recipes-graphics/mesa/mesa/0005-tegra-open-card1-instead-of-renderD128.patch b/recipes-graphics/mesa/mesa/0005-tegra-open-card1-instead-of-renderD128.patch
new file mode 100644
index 0000000..14a867a
--- /dev/null
+++ b/recipes-graphics/mesa/mesa/0005-tegra-open-card1-instead-of-renderD128.patch
@@ -0,0 +1,29 @@
+From a97f868a806ab4f1aaab88c72d4b55bfb18cc3cc Mon Sep 17 00:00:00 2001
+From: Alexandre Courbot <acourbot@nvidia.com>
+Date: Fri, 9 Dec 2016 17:04:16 +0900
+Subject: [PATCH 5/8] tegra: open card1 instead of renderD128
+
+Mesa wants to perform a FLINK ioctl to share GPU buffers. This ioctl is
+not valid on render-nodes.
+
+This fixes rendering with Weston, but GLX is still broken.
+---
+ src/gallium/winsys/tegra/drm/tegra_drm_winsys.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/gallium/winsys/tegra/drm/tegra_drm_winsys.c b/src/gallium/winsys/tegra/drm/tegra_drm_winsys.c
+index 361370d..e213942 100644
+--- a/src/gallium/winsys/tegra/drm/tegra_drm_winsys.c
++++ b/src/gallium/winsys/tegra/drm/tegra_drm_winsys.c
+@@ -10,7 +10,7 @@
+ static struct pipe_screen *
+ tegra_create(struct renderonly *ro)
+ {
+- int fd = open("/dev/dri/renderD128", O_RDWR | O_CLOEXEC);
++ int fd = open("/dev/dri/card1", O_RDWR | O_CLOEXEC);
+
+ if (fd == -1)
+ return NULL;
+--
+2.9.3
+
diff --git a/recipes-graphics/mesa/mesa/0006-HACK-make-DRI-work-under-X.patch b/recipes-graphics/mesa/mesa/0006-HACK-make-DRI-work-under-X.patch
new file mode 100644
index 0000000..ecafa3f
--- /dev/null
+++ b/recipes-graphics/mesa/mesa/0006-HACK-make-DRI-work-under-X.patch
@@ -0,0 +1,24 @@
+From bb572a449b8c168dbe6d723692e4c1c8801f15b8 Mon Sep 17 00:00:00 2001
+From: Alexandre Courbot <acourbot@nvidia.com>
+Date: Mon, 11 Jul 2016 14:44:59 +0900
+Subject: [PATCH 6/8] [HACK] make DRI work under X
+
+---
+ src/loader/loader_dri3_helper.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/src/loader/loader_dri3_helper.c b/src/loader/loader_dri3_helper.c
+index ca02e97..568a1c7 100644
+--- a/src/loader/loader_dri3_helper.c
++++ b/src/loader/loader_dri3_helper.c
+@@ -145,6 +145,7 @@ loader_dri3_drawable_init(xcb_connection_t *conn,
+ draw->drawable = drawable;
+ draw->dri_screen = dri_screen;
+ draw->is_different_gpu = is_different_gpu;
++ draw->is_different_gpu = 1;
+
+ draw->have_back = 0;
+ draw->have_fake_front = 0;
+--
+2.9.3
+
diff --git a/recipes-graphics/mesa/mesa/0008-remove-dependency-on-libdrm_tegra.patch b/recipes-graphics/mesa/mesa/0008-remove-dependency-on-libdrm_tegra.patch
new file mode 100644
index 0000000..0b6d6e9
--- /dev/null
+++ b/recipes-graphics/mesa/mesa/0008-remove-dependency-on-libdrm_tegra.patch
@@ -0,0 +1,48 @@
+From d2716d25609865bb31bb270ee2fdac3dec5047c6 Mon Sep 17 00:00:00 2001
+From: Alexandre Courbot <acourbot@nvidia.com>
+Date: Tue, 20 Dec 2016 15:20:20 +0900
+Subject: [PATCH 8/8] remove dependency on libdrm_tegra
+
+Functions provided by this library are not required as we perform ioctls
+directly.
+---
+ configure.ac | 2 --
+ src/gallium/winsys/tegra/drm/Makefile.am | 2 +-
+ 2 files changed, 1 insertion(+), 3 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index 8a7d833..7df9674 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -77,7 +77,6 @@ LIBDRM_NOUVEAU_REQUIRED=2.4.66
+ LIBDRM_NVVIEUX_REQUIRED=2.4.66
+ LIBDRM_NOUVEAU_REQUIRED=2.4.66
+ LIBDRM_FREEDRENO_REQUIRED=2.4.67
+-LIBDRM_TEGRA_REQUIRED=2.4.68
+ DRI2PROTO_REQUIRED=2.6
+ DRI3PROTO_REQUIRED=1.0
+ PRESENTPROTO_REQUIRED=1.0
+@@ -2493,7 +2492,6 @@ if test -n "$with_gallium_drivers"; then
+ require_basic_egl "virgl"
+ ;;
+ xtegra)
+- PKG_CHECK_MODULES([TEGRA], [libdrm_tegra >= $LIBDRM_TEGRA_REQUIRED])
+ HAVE_GALLIUM_TEGRA=yes
+ gallium_require_drm "tegra"
+ gallium_require_drm_loader
+diff --git a/src/gallium/winsys/tegra/drm/Makefile.am b/src/gallium/winsys/tegra/drm/Makefile.am
+index 39068fe..eada86a 100644
+--- a/src/gallium/winsys/tegra/drm/Makefile.am
++++ b/src/gallium/winsys/tegra/drm/Makefile.am
+@@ -26,7 +26,7 @@ include $(top_srcdir)/src/gallium/Automake.inc
+ AM_CFLAGS = \
+ -I$(top_srcdir)/src/gallium/drivers \
+ $(GALLIUM_WINSYS_CFLAGS) \
+- $(TEGRA_CFLAGS)
++ $(LIBDRM_CFLAGS)
+
+ noinst_LTLIBRARIES = libtegradrm.la
+
+--
+2.9.3
+
diff --git a/recipes-graphics/mesa/mesa_%.bbappend b/recipes-graphics/mesa/mesa_%.bbappend
index 52b9e33..1865a1d 100644
--- a/recipes-graphics/mesa/mesa_%.bbappend
+++ b/recipes-graphics/mesa/mesa_%.bbappend
@@ -23,7 +23,29 @@ DEPENDS_remove = "${DEPENDS_REMOVE}"
#####
## Tegra TK1 mainline kernel
-PACKAGECONFIG_append_tegra124m = "dri3 egl gles gallium "
+PACKAGECONFIG_append_tegra124m = "dri3 egl gles gallium gbm "
+
+PE_tegra124m = "99"
+
+FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
+
+EXTRA_OECONF_append_tegra124m = " --enable-texture-float --without-dri-drivers --enable-glx --enable-osmesa --enable-debug"
+
+SRC_URI_append_tegra124m = "\
+ file://0001-gallium-add-renderonly-library.patch \
+ file://0004-gallium-add-tegra-support.patch \
+ file://0005-tegra-open-card1-instead-of-renderD128.patch \
+ file://0006-HACK-make-DRI-work-under-X.patch \
+ file://0008-remove-dependency-on-libdrm_tegra.patch \
+ "
+PACKAGE_ARCH_tegra124m = "${MACHINE_ARCH}"
+
+DRIDRIVERS_tegra124m = " "
+
+GALLIUMDRIVERS_tegra124m = "tegra"
+
+COMPATIBLE_MACHINE_tegra124m = "(apalis-tk1-mainline)"
+
# until meta-jetson-tk1 adds it through its bbappend:
DEPENDS_append_tegra124= " linux-driver-package "
diff --git a/recipes-graphics/xorg-xserver/xserver-xorg-1.18.4/0001-HACK-use-render-nodes-and-tegra-tiling-format.patch b/recipes-graphics/xorg-xserver/xserver-xorg-1.18.4/0001-HACK-use-render-nodes-and-tegra-tiling-format.patch
deleted file mode 100644
index 39b92e8..0000000
--- a/recipes-graphics/xorg-xserver/xserver-xorg-1.18.4/0001-HACK-use-render-nodes-and-tegra-tiling-format.patch
+++ /dev/null
@@ -1,145 +0,0 @@
-From c9ba24058a5cae32c8d8431911485fba7c6d3a14 Mon Sep 17 00:00:00 2001
-From: Alexandre Courbot <acourbot@nvidia.com>
-Date: Thu, 24 Sep 2015 18:23:51 +0900
-Subject: [PATCH 1/7] [HACK] use render nodes and tegra tiling format
-
----
- glamor/glamor_egl.c | 5 +++
- hw/xfree86/drivers/modesetting/drmmode_display.c | 56 ++++++++++++++++++++++--
- hw/xfree86/drivers/modesetting/drmmode_display.h | 1 +
- 3 files changed, 58 insertions(+), 4 deletions(-)
-
-diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
-index 5aacbed..b6941f2 100644
---- a/glamor/glamor_egl.c
-+++ b/glamor/glamor_egl.c
-@@ -809,6 +809,11 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd)
- xf86GlamorEGLPrivateIndex = xf86AllocateScrnInfoPrivateIndex();
-
- scrn->privates[xf86GlamorEGLPrivateIndex].ptr = glamor_egl;
-+
-+
-+ fd = open("/dev/dri/renderD128", O_RDWR);
-+ xf86Msg(X_INFO, "Opening render node: %d\n", fd);
-+
- glamor_egl->fd = fd;
- #ifdef GLAMOR_HAS_GBM
- glamor_egl->gbm = gbm_create_device(glamor_egl->fd);
-diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
-index 9c54310..9c9fa27 100644
---- a/hw/xfree86/drivers/modesetting/drmmode_display.c
-+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
-@@ -50,6 +50,8 @@
-
- #include "driver.h"
-
-+#include <tegra_drm.h>
-+
- static Bool drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height);
-
- static Bool
-@@ -160,15 +162,61 @@ drmmode_bo_map(drmmode_ptr drmmode, drmmode_bo *bo)
- }
-
- static Bool
-+drmmode_tegra_import(drmmode_ptr drmmode, drmmode_bo *bo)
-+{
-+ struct drm_tegra_gem_set_tiling args;
-+ int err;
-+
-+ memset(&args, 0, sizeof(args));
-+ args.handle = bo->drm_handle;
-+ args.mode = DRM_TEGRA_GEM_TILING_MODE_BLOCK;
-+ args.value = 4;
-+
-+ err = ioctl(drmmode->fd, DRM_IOCTL_TEGRA_GEM_SET_TILING, &args);
-+ if (err < 0) {
-+ xf86Msg(X_ERROR, "failed to set tiling parameters\n");
-+ return FALSE;
-+ }
-+
-+ return TRUE;
-+}
-+
-+static Bool
- drmmode_create_bo(drmmode_ptr drmmode, drmmode_bo *bo,
- unsigned width, unsigned height, unsigned bpp)
- {
- #ifdef GLAMOR_HAS_GBM
-+ uint32_t handle;
-+ int fd;
-+ int ret;
-+
- if (drmmode->glamor) {
- bo->gbm = gbm_bo_create(drmmode->gbm, width, height,
- GBM_FORMAT_ARGB8888,
- GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT);
-- return bo->gbm != NULL;
-+
-+ if (bo->gbm == NULL)
-+ return FALSE;
-+
-+ handle = gbm_bo_get_handle(bo->gbm).u32;
-+
-+ ret = drmPrimeHandleToFD(gbm_device_get_fd(drmmode->gbm), handle, 0, &fd);
-+ if (ret) {
-+ xf86Msg(X_ERROR, "failed to export bo\n");
-+ return FALSE;
-+ }
-+
-+ ret = drmPrimeFDToHandle(drmmode->fd, fd, &handle);
-+ if (ret) {
-+ xf86Msg(X_ERROR, "failed to import bo\n");
-+ close(fd);
-+ return FALSE;
-+ }
-+
-+ close(fd);
-+ bo->drm_handle = handle;
-+
-+ return drmmode_tegra_import(drmmode, bo);
- }
- #endif
-
-@@ -410,7 +458,7 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
- pScrn->virtualX, pScrn->virtualY,
- pScrn->depth, drmmode->kbpp,
- drmmode_bo_get_pitch(&drmmode->front_bo),
-- drmmode_bo_get_handle(&drmmode->front_bo),
-+ drmmode->front_bo.drm_handle,
- &drmmode->fb_id);
- if (ret < 0) {
- ErrorF("failed to add fb %d\n", ret);
-@@ -712,7 +760,7 @@ drmmode_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
- ret = drmModeAddFB(drmmode->fd, width, height, crtc->scrn->depth,
- drmmode->kbpp,
- drmmode_bo_get_pitch(&drmmode_crtc->rotate_bo),
-- drmmode_bo_get_handle(&drmmode_crtc->rotate_bo),
-+ drmmode_crtc->rotate_bo.drm_handle,
- &drmmode_crtc->rotate_fb_id);
-
- if (ret) {
-@@ -1700,7 +1748,7 @@ drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height)
-
- ret = drmModeAddFB(drmmode->fd, width, height, scrn->depth,
- scrn->bitsPerPixel, pitch,
-- drmmode_bo_get_handle(&drmmode->front_bo),
-+ drmmode->front_bo.drm_handle,
- &drmmode->fb_id);
- if (ret)
- goto fail;
-diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
-index 9139ed4..547fd0d 100644
---- a/hw/xfree86/drivers/modesetting/drmmode_display.h
-+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
-@@ -41,6 +41,7 @@ typedef struct {
- #ifdef GLAMOR_HAS_GBM
- struct gbm_bo *gbm;
- #endif
-+ uint32_t drm_handle;
- } drmmode_bo;
-
- typedef struct {
---
-2.9.3
-
diff --git a/recipes-graphics/xorg-xserver/xserver-xorg-1.18.4/0002-HACK-enable-GLX-with-DRI3.patch b/recipes-graphics/xorg-xserver/xserver-xorg-1.18.4/0002-HACK-enable-GLX-with-DRI3.patch
deleted file mode 100644
index f27c2a9..0000000
--- a/recipes-graphics/xorg-xserver/xserver-xorg-1.18.4/0002-HACK-enable-GLX-with-DRI3.patch
+++ /dev/null
@@ -1,72 +0,0 @@
-From 1baf53e2b345ae7d883d4fa6c74f09188ea53b51 Mon Sep 17 00:00:00 2001
-From: Alexandre Courbot <acourbot@nvidia.com>
-Date: Fri, 25 Sep 2015 14:37:01 +0900
-Subject: [PATCH 2/7] [HACK] enable GLX with DRI3
-
----
- glamor/glamor_egl.c | 5 ++++-
- hw/xfree86/dri2/dri2.c | 5 ++++-
- hw/xfree86/drivers/modesetting/dri2.c | 5 +++--
- 3 files changed, 11 insertions(+), 4 deletions(-)
-
-diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
-index b6941f2..8d25171 100644
---- a/glamor/glamor_egl.c
-+++ b/glamor/glamor_egl.c
-@@ -724,6 +724,7 @@ glamor_egl_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx)
- glamor_ctx->make_current = glamor_egl_make_current;
-
- #ifdef DRI3
-+ xf86Msg(X_INFO, "DRI3 capable: %d\n", glamor_egl->dri3_capable);
- if (glamor_egl->dri3_capable) {
- glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
- /* Tell the core that we have the interfaces for import/export
-@@ -740,7 +741,9 @@ glamor_egl_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx)
- /* To do DRI3 device FD generation, we need to open a new fd
- * to the same device we were handed in originally.
- */
-- glamor_egl->device_path = drmGetDeviceNameFromFd(glamor_egl->fd);
-+ //glamor_egl->device_path = drmGetDeviceNameFromFd(glamor_egl->fd);
-+ glamor_egl->device_path = "/dev/dri/renderD128";
-+ xf86Msg(X_INFO, "DRI3 device name: %s %d\n", glamor_egl->device_path, glamor_egl->fd);
-
- if (!dri3_screen_init(screen, &glamor_dri3_info)) {
- xf86DrvMsg(scrn->scrnIndex, X_ERROR,
-diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
-index d55be19..00c5c61 100644
---- a/hw/xfree86/dri2/dri2.c
-+++ b/hw/xfree86/dri2/dri2.c
-@@ -1334,9 +1334,12 @@ DRI2Connect(ClientPtr client, ScreenPtr pScreen,
- return FALSE;
-
- *driverName = ds->driverNames[driver_id];
-- *deviceName = ds->deviceName;
-+ //*deviceName = ds->deviceName;
-+ *deviceName = "/dev/dri/renderD128";
- *fd = ds->fd;
-
-+ xf86Msg(X_INFO, "%s: %s %s %d\n", __func__, *driverName, *deviceName, *fd);
-+
- if (client) {
- DRI2ClientPtr dri2_client;
- dri2_client = dri2ClientPrivate(client);
-diff --git a/hw/xfree86/drivers/modesetting/dri2.c b/hw/xfree86/drivers/modesetting/dri2.c
-index 83cb3e0..3834a01 100644
---- a/hw/xfree86/drivers/modesetting/dri2.c
-+++ b/hw/xfree86/drivers/modesetting/dri2.c
-@@ -831,9 +831,10 @@ ms_dri2_screen_init(ScreenPtr screen)
- }
-
- memset(&info, '\0', sizeof(info));
-- info.fd = ms->fd;
-+ info.fd = gbm_device_get_fd(ms->drmmode.gbm);
-+ //info.fd = ms->fd;
- info.driverName = NULL; /* Compat field, unused. */
-- info.deviceName = drmGetDeviceNameFromFd(ms->fd);
-+ info.deviceName = drmGetDeviceNameFromFd(info.fd);
-
- info.version = 4;
- info.CreateBuffer = ms_dri2_create_buffer;
---
-2.9.3
-
diff --git a/recipes-graphics/xorg-xserver/xserver-xorg_1.18.4.bbappend b/recipes-graphics/xorg-xserver/xserver-xorg_1.18.4.bbappend
index 746f367..da88b89 100644
--- a/recipes-graphics/xorg-xserver/xserver-xorg_1.18.4.bbappend
+++ b/recipes-graphics/xorg-xserver/xserver-xorg_1.18.4.bbappend
@@ -1,12 +1,6 @@
# always latest and greatest.
PE_tegra124m = "99"
-FILESEXTRAPATHS_prepend := "${THISDIR}/xserver-xorg-${PV}:"
-
-SRC_URI_append_tegra124m = "\
- file://0001-HACK-use-render-nodes-and-tegra-tiling-format.patch \
- file://0002-HACK-enable-GLX-with-DRI3.patch \
- "
PACKAGE_ARCH_tegra124m = "${MACHINE_ARCH}"
COMPATIBLE_MACHINE_tegra124m = "(apalis-tk1-mainline)"
diff --git a/recipes-kernel/linux/linux-toradex-mainline-4.9/0001-drm-tegra-add-tiling-FB-modifiers.patch b/recipes-kernel/linux/linux-toradex-mainline-4.9/0001-drm-tegra-add-tiling-FB-modifiers.patch
new file mode 100644
index 0000000..48a560b
--- /dev/null
+++ b/recipes-kernel/linux/linux-toradex-mainline-4.9/0001-drm-tegra-add-tiling-FB-modifiers.patch
@@ -0,0 +1,128 @@
+From 779ca8b35effc59faeeb24ed20a61f95035928fd Mon Sep 17 00:00:00 2001
+From: Alexandre Courbot <acourbot@nvidia.com>
+Date: Fri, 16 Sep 2016 23:46:31 +0900
+Subject: [PATCH] drm/tegra: add tiling FB modifiers
+
+Add FB modifiers to allow user-space to specify that a surface is in one
+of the two tiling formats supported by Tegra chips, and add support in
+the tegradrm driver to handle them properly. This is necessary for the
+display controller to directly display buffers generated by the GPU.
+
+This feature is intended to replace the dedicated IOCTL enabled
+by TEGRA_STAGING and to provide a non-staging alternative to that
+solution.
+
+Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
+Acked-by: Daniel Vetter <daniel@ffwll.ch>
+---
+ drivers/gpu/drm/tegra/drm.c | 2 ++
+ drivers/gpu/drm/tegra/fb.c | 23 +++++++++++++++++++---
+ include/uapi/drm/drm_fourcc.h | 45 +++++++++++++++++++++++++++++++++++++++++++
+ 3 files changed, 67 insertions(+), 3 deletions(-)
+
+diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c
+index b8be3ee..13a1524 100644
+--- a/drivers/gpu/drm/tegra/drm.c
++++ b/drivers/gpu/drm/tegra/drm.c
+@@ -161,6 +161,8 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
+ drm->mode_config.max_width = 4096;
+ drm->mode_config.max_height = 4096;
+
++ drm->mode_config.allow_fb_modifiers = true;
++
+ drm->mode_config.funcs = &tegra_drm_mode_funcs;
+
+ err = tegra_drm_fb_prepare(drm);
+diff --git a/drivers/gpu/drm/tegra/fb.c b/drivers/gpu/drm/tegra/fb.c
+index e4a5ab0..3faf38a 100644
+--- a/drivers/gpu/drm/tegra/fb.c
++++ b/drivers/gpu/drm/tegra/fb.c
+@@ -52,9 +52,26 @@ int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
+ struct tegra_bo_tiling *tiling)
+ {
+ struct tegra_fb *fb = to_tegra_fb(framebuffer);
+-
+- /* TODO: handle YUV formats? */
+- *tiling = fb->planes[0]->tiling;
++ uint64_t modifier = fb->base.modifier;
++
++ switch (fourcc_mod_tegra_mod(modifier)) {
++ case NV_FORMAT_MOD_TEGRA_TILED:
++ tiling->mode = TEGRA_BO_TILING_MODE_TILED;
++ tiling->value = 0;
++ break;
++
++ case NV_FORMAT_MOD_TEGRA_16BX2_BLOCK(0):
++ tiling->mode = TEGRA_BO_TILING_MODE_BLOCK;
++ tiling->value = fourcc_mod_tegra_param(modifier);
++ if (tiling->value > 5)
++ return -EINVAL;
++ break;
++
++ default:
++ /* TODO: handle YUV formats? */
++ *tiling = fb->planes[0]->tiling;
++ break;
++ }
+
+ return 0;
+ }
+diff --git a/include/uapi/drm/drm_fourcc.h b/include/uapi/drm/drm_fourcc.h
+index a5890bf..967dfab 100644
+--- a/include/uapi/drm/drm_fourcc.h
++++ b/include/uapi/drm/drm_fourcc.h
+@@ -233,6 +233,51 @@ extern "C" {
+ */
+ #define DRM_FORMAT_MOD_SAMSUNG_64_32_TILE fourcc_mod_code(SAMSUNG, 1)
+
++
++/* NVIDIA Tegra frame buffer modifiers */
++
++/*
++ * Some modifiers take parameters, for example the number of vertical GOBs in
++ * a block. Reserve the lower 32 bits for parameters
++ */
++#define __fourcc_mod_tegra_mode_shift 32
++#define fourcc_mod_tegra_code(val, params) \
++ fourcc_mod_code(NV, ((((__u64)val) << __fourcc_mod_tegra_mode_shift) | params))
++#define fourcc_mod_tegra_mod(m) \
++ (m & ~((1ULL << __fourcc_mod_tegra_mode_shift) - 1))
++#define fourcc_mod_tegra_param(m) \
++ (m & ((1ULL << __fourcc_mod_tegra_mode_shift) - 1))
++
++/*
++ * Tegra Tiled Layout, used by Tegra 2, 3 and 4.
++ *
++ * Pixels are arranged in simple tiles of 16 x 16 bytes.
++ */
++#define NV_FORMAT_MOD_TEGRA_TILED fourcc_mod_tegra_code(1, 0)
++
++/*
++ * Tegra 16Bx2 Block Linear layout, used by TK1/TX1
++ *
++ * Pixels are arranged in 64x8 Groups Of Bytes (GOBs). GOBs are then stacked
++ * vertically by a power of 2 (1 to 32 GOBs) to form a block.
++ *
++ * Within a GOB, data is ordered as 16B x 2 lines sectors laid in Z-shape.
++ *
++ * Parameter 'v' is the log2 encoding of the number of GOBs stacked vertically.
++ * Valid values are:
++ *
++ * 0 == ONE_GOB
++ * 1 == TWO_GOBS
++ * 2 == FOUR_GOBS
++ * 3 == EIGHT_GOBS
++ * 4 == SIXTEEN_GOBS
++ * 5 == THIRTYTWO_GOBS
++ *
++ * Chapter 20 "Pixel Memory Formats" of the Tegra X1 TRM describes this format
++ * in full detail.
++ */
++#define NV_FORMAT_MOD_TEGRA_16BX2_BLOCK(v) fourcc_mod_tegra_code(2, v)
++
+ #if defined(__cplusplus)
+ }
+ #endif
+--
+2.9.3
+
diff --git a/recipes-kernel/linux/linux-toradex-mainline_4.9.bb b/recipes-kernel/linux/linux-toradex-mainline_4.9.bb
index 1d6ad91..f0ff5fe 100644
--- a/recipes-kernel/linux/linux-toradex-mainline_4.9.bb
+++ b/recipes-kernel/linux/linux-toradex-mainline_4.9.bb
@@ -27,6 +27,7 @@ SRC_URI = "https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-${PV}.tar.xz \
file://0002-igb-integrate-tools-only-device-support.patch \
file://0003-apalis_t30-tk1-igb-no-nvm-and-Ethernet-MAC-address-h.patch \
file://0004-mmc-tegra-apalis-tk1-hack-to-make-sd1-functional.patch \
+ file://0001-drm-tegra-add-tiling-FB-modifiers.patch \
"
COMPATIBLE_MACHINE = "(apalis-tk1-mainline|apalis-t30-mainline)"