summaryrefslogtreecommitdiff
path: root/recipes-graphics
diff options
context:
space:
mode:
authorDominik Sliwa <dominik.sliwa@toradex.com>2016-12-15 14:22:05 +0100
committerMarcel Ziswiler <marcel.ziswiler@toradex.com>2017-01-11 12:03:36 +0100
commit74a74be23feb5d44121f059e1ab96787be4b7532 (patch)
treefece7a2f7713323611ee79af38a34b98b8fd6446 /recipes-graphics
parent66898c40b3772c19d8d076c4fac6324379e72629 (diff)
apalis-tk1: Mainline kernel machine
This patch adds mainline linux based Apalis TK1 machine. It includes compatible recipes for libdrm, mesa, Xorg, and weston. Signed-off-by: Dominik Sliwa <dominik.sliwa@toradex.com> Acked-by: Max Krummenacher <max.krummenacher@toradex.com>
Diffstat (limited to 'recipes-graphics')
-rw-r--r--recipes-graphics/drm/files/0001-Add-drmModeAddFB2WithModifiers-which-takes-format-mo.patch82
-rw-r--r--recipes-graphics/drm/files/0001-sync-kernel-UAPI.patch51
-rw-r--r--recipes-graphics/drm/libdrm_%.bbappend16
-rw-r--r--recipes-graphics/mesa/mesa_%.bbappend6
-rw-r--r--recipes-graphics/wayland/files/0001-compositor-drm-Add-new-gbm-struct-to-allow-for-a-sep.patch181
-rw-r--r--recipes-graphics/wayland/files/0002-compositor-drm-Add-support-for-Tegra-Jetson-TK1.patch195
-rw-r--r--recipes-graphics/wayland/files/0003-Add-glFinish-to-DRM-backend-to-avoid-tearing.patch48
-rw-r--r--recipes-graphics/wayland/files/0004-use-name-based-detection-of-display-and-render-nodes.patch73
-rw-r--r--recipes-graphics/wayland/weston_%.bbappend12
-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.bbappend20
12 files changed, 900 insertions, 1 deletions
diff --git a/recipes-graphics/drm/files/0001-Add-drmModeAddFB2WithModifiers-which-takes-format-mo.patch b/recipes-graphics/drm/files/0001-Add-drmModeAddFB2WithModifiers-which-takes-format-mo.patch
new file mode 100644
index 0000000..36cc8e2
--- /dev/null
+++ b/recipes-graphics/drm/files/0001-Add-drmModeAddFB2WithModifiers-which-takes-format-mo.patch
@@ -0,0 +1,82 @@
+From abfa680dbdfa4600105d904f4903c047d453cdb5 Mon Sep 17 00:00:00 2001
+From: "Kristian H. Kristensen" <hoegsberg@chromium.org>
+Date: Thu, 8 Sep 2016 13:08:59 -0700
+Subject: [PATCH] Add drmModeAddFB2WithModifiers() which takes format modifiers
+
+The only other user of this feature open codes the ioctl. Let's add an
+entry point for this to libdrm.
+
+Signed-off-by: Kristian H. Kristensen <hoegsberg@chromium.org>
+Reviewed-by: Rob Clark <robdclark@gmail.com>
+---
+ xf86drmMode.c | 21 +++++++++++++++++----
+ xf86drmMode.h | 7 +++++++
+ 2 files changed, 24 insertions(+), 4 deletions(-)
+
+diff --git a/xf86drmMode.c b/xf86drmMode.c
+index f7b5948..228c6e4 100644
+--- a/xf86drmMode.c
++++ b/xf86drmMode.c
+@@ -270,10 +270,10 @@ int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
+ return 0;
+ }
+
+-int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
+- uint32_t pixel_format, uint32_t bo_handles[4],
+- uint32_t pitches[4], uint32_t offsets[4],
+- uint32_t *buf_id, uint32_t flags)
++int drmModeAddFB2WithModifiers(int fd, uint32_t width, uint32_t height,
++ uint32_t pixel_format, uint32_t bo_handles[4],
++ uint32_t pitches[4], uint32_t offsets[4],
++ uint64_t modifier[4], uint32_t *buf_id, uint32_t flags)
+ {
+ struct drm_mode_fb_cmd2 f;
+ int ret;
+@@ -286,6 +286,8 @@ int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
+ memcpy(f.handles, bo_handles, 4 * sizeof(bo_handles[0]));
+ memcpy(f.pitches, pitches, 4 * sizeof(pitches[0]));
+ memcpy(f.offsets, offsets, 4 * sizeof(offsets[0]));
++ if (modifier)
++ memcpy(f.modifier, modifier, 4 * sizeof(modifier[0]));
+
+ if ((ret = DRM_IOCTL(fd, DRM_IOCTL_MODE_ADDFB2, &f)))
+ return ret;
+@@ -294,6 +296,17 @@ int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
+ return 0;
+ }
+
++int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
++ uint32_t pixel_format, uint32_t bo_handles[4],
++ uint32_t pitches[4], uint32_t offsets[4],
++ uint32_t *buf_id, uint32_t flags)
++{
++ return drmModeAddFB2WithModifiers(fd, width, height,
++ pixel_format, bo_handles,
++ pitches, offsets, NULL,
++ buf_id, flags);
++}
++
+ int drmModeRmFB(int fd, uint32_t bufferId)
+ {
+ return DRM_IOCTL(fd, DRM_IOCTL_MODE_RMFB, &bufferId);
+diff --git a/xf86drmMode.h b/xf86drmMode.h
+index 4de7bbb..1a02fed 100644
+--- a/xf86drmMode.h
++++ b/xf86drmMode.h
+@@ -369,6 +369,13 @@ extern int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
+ uint32_t pixel_format, uint32_t bo_handles[4],
+ uint32_t pitches[4], uint32_t offsets[4],
+ uint32_t *buf_id, uint32_t flags);
++
++/* ...with format modifiers */
++int drmModeAddFB2WithModifiers(int fd, uint32_t width, uint32_t height,
++ uint32_t pixel_format, uint32_t bo_handles[4],
++ uint32_t pitches[4], uint32_t offsets[4],
++ uint64_t modifier[4], uint32_t *buf_id, uint32_t flags);
++
+ /**
+ * Destroies the given framebuffer.
+ */
+--
+2.9.3
+
diff --git a/recipes-graphics/drm/files/0001-sync-kernel-UAPI.patch b/recipes-graphics/drm/files/0001-sync-kernel-UAPI.patch
new file mode 100644
index 0000000..19e69aa
--- /dev/null
+++ b/recipes-graphics/drm/files/0001-sync-kernel-UAPI.patch
@@ -0,0 +1,51 @@
+From 9bfdb183a7c50266caa97e5fcbabeaf54db6c2a1 Mon Sep 17 00:00:00 2001
+From: Alexandre Courbot <acourbot@nvidia.com>
+Date: Tue, 20 Sep 2016 11:33:51 +0900
+Subject: [PATCH] sync kernel UAPI
+
+---
+ include/drm/drm_fourcc.h | 23 +++++++++++++++++++++++
+ 1 file changed, 23 insertions(+)
+
+diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
+index 4d8da69..7fed8a2 100644
+--- a/include/drm/drm_fourcc.h
++++ b/include/drm/drm_fourcc.h
+@@ -26,6 +26,10 @@
+
+ #include "drm.h"
+
++#if defined(__cplusplus)
++extern "C" {
++#endif
++
+ #define fourcc_code(a, b, c, d) ((__u32)(a) | ((__u32)(b) << 8) | \
+ ((__u32)(c) << 16) | ((__u32)(d) << 24))
+
+@@ -229,4 +233,23 @@
+ */
+ #define DRM_FORMAT_MOD_SAMSUNG_64_32_TILE fourcc_mod_code(SAMSUNG, 1)
+
++
++/* NVIDIA Frame buffer modifiers */
++
++#define NV_FORMAT_MOD_TEGRA_SHIFT 32
++
++#define NV_FORMAT_MOD_TEGRA_TILED \
++ fourcc_mod_code(NV, 1ULL << NV_FORMAT_MOD_TEGRA_SHIFT)
++
++#define NV_FORMAT_MOD_TEGRA_BLOCK_MASK \
++ fourcc_mod_code(NV, 2ULL << NV_FORMAT_MOD_TEGRA_SHIFT)
++#define NV_FORMAT_MOD_TEGRA_BLOCK_VALUE(m) \
++ (m & ((1ULL << NV_FORMAT_MOD_TEGRA_SHIFT) - 1))
++#define NV_FORMAT_MOD_TEGRA_BLOCK(v) \
++ (NV_FORMAT_MOD_TEGRA_BLOCK_MASK | NV_FORMAT_MOD_TEGRA_BLOCK_VALUE(v))
++
++#if defined(__cplusplus)
++}
++#endif
++
+ #endif /* DRM_FOURCC_H */
+--
+2.9.3
+
diff --git a/recipes-graphics/drm/libdrm_%.bbappend b/recipes-graphics/drm/libdrm_%.bbappend
new file mode 100644
index 0000000..c035f18
--- /dev/null
+++ b/recipes-graphics/drm/libdrm_%.bbappend
@@ -0,0 +1,16 @@
+FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
+
+SRC_URI += "\
+ file://0001-Add-drmModeAddFB2WithModifiers-which-takes-format-mo.patch \
+ file://0001-sync-kernel-UAPI.patch \
+ "
+PACKAGES += "\
+ ${PN}-tegra \
+ \
+ "
+FILES_${PN}-tegra = "${libdir}/libdrm_tegra.so.*"
+
+EXTRA_OECONF_append += "\
+ --enable-tegra-experimental-api \
+ "
+
diff --git a/recipes-graphics/mesa/mesa_%.bbappend b/recipes-graphics/mesa/mesa_%.bbappend
index b63e8f2..52b9e33 100644
--- a/recipes-graphics/mesa/mesa_%.bbappend
+++ b/recipes-graphics/mesa/mesa_%.bbappend
@@ -20,8 +20,12 @@ DEPENDS_REMOVE = "linux-driver-package"
DEPENDS_REMOVE_tegra124 = ""
DEPENDS_remove = "${DEPENDS_REMOVE}"
+#####
+## Tegra TK1 mainline kernel
+
+PACKAGECONFIG_append_tegra124m = "dri3 egl gles gallium "
# until meta-jetson-tk1 adds it through its bbappend:
DEPENDS_append_tegra124= " linux-driver-package "
-SRC_URI_append_tegra123 = " tegra-path-add.patch" \ No newline at end of file
+SRC_URI_append_tegra123 = " tegra-path-add.patch"
diff --git a/recipes-graphics/wayland/files/0001-compositor-drm-Add-new-gbm-struct-to-allow-for-a-sep.patch b/recipes-graphics/wayland/files/0001-compositor-drm-Add-new-gbm-struct-to-allow-for-a-sep.patch
new file mode 100644
index 0000000..cbd2cd5
--- /dev/null
+++ b/recipes-graphics/wayland/files/0001-compositor-drm-Add-new-gbm-struct-to-allow-for-a-sep.patch
@@ -0,0 +1,181 @@
+From 0719ed96aa2c41afe342f4c3c19e4ca91f270be2 Mon Sep 17 00:00:00 2001
+From: James Thomas <james.thomas@codethink.co.uk>
+Date: Fri, 20 Jun 2014 12:12:26 +0100
+Subject: [PATCH 1/6] compositor-drm: Add new gbm struct to allow for a
+ separate gbm device
+
+This is needed for devices like tegra jetson where the gbm device is not
+the same as the drm device
+---
+ src/compositor-drm.c | 48 +++++++++++++++++++++++++++---------------------
+ 1 file changed, 27 insertions(+), 21 deletions(-)
+
+diff --git a/src/compositor-drm.c b/src/compositor-drm.c
+index 893877d..5db86dc 100644
+--- a/src/compositor-drm.c
++++ b/src/compositor-drm.c
+@@ -90,8 +90,11 @@ struct drm_backend {
+ int fd;
+ char *filename;
+ } drm;
+- struct gbm_device *gbm;
+- uint32_t *crtcs;
++ struct {
++ int fd;
++ char *filename;
++ } gbm;
++ struct gbm_device *gbm_device; uint32_t *crtcs;
+ int num_crtcs;
+ uint32_t crtc_allocator;
+ uint32_t connector_allocator;
+@@ -478,7 +481,7 @@ drm_output_prepare_scanout_view(struct drm_output *output,
+
+ if (ev->geometry.x != output->base.x ||
+ ev->geometry.y != output->base.y ||
+- buffer == NULL || b->gbm == NULL ||
++ buffer == NULL || b->gbm_device == NULL ||
+ buffer->width != output->base.current_mode->width ||
+ buffer->height != output->base.current_mode->height ||
+ output->base.transform != viewport->buffer.transform ||
+@@ -488,7 +491,7 @@ drm_output_prepare_scanout_view(struct drm_output *output,
+ if (ev->geometry.scissor_enabled)
+ return NULL;
+
+- bo = gbm_bo_import(b->gbm, GBM_BO_IMPORT_WL_BUFFER,
++ bo = gbm_bo_import(b->gbm_device, GBM_BO_IMPORT_WL_BUFFER,
+ buffer->resource, GBM_BO_USE_SCANOUT);
+
+ /* Unable to use the buffer for scanout */
+@@ -923,7 +926,7 @@ drm_output_prepare_overlay_view(struct drm_output *output,
+ uint32_t format;
+ wl_fixed_t sx1, sy1, sx2, sy2;
+
+- if (b->gbm == NULL)
++ if (b->gbm_device == NULL)
+ return NULL;
+
+ if (viewport->buffer.transform != output->base.transform)
+@@ -985,13 +988,13 @@ drm_output_prepare_overlay_view(struct drm_output *output,
+ if (dmabuf->attributes.n_planes != 1 || dmabuf->attributes.offset[0] != 0)
+ return NULL;
+
+- bo = gbm_bo_import(b->gbm, GBM_BO_IMPORT_FD, &gbm_dmabuf,
++ bo = gbm_bo_import(b->gbm_device, GBM_BO_IMPORT_FD, &gbm_dmabuf,
+ GBM_BO_USE_SCANOUT);
+ #else
+ return NULL;
+ #endif
+ } else {
+- bo = gbm_bo_import(b->gbm, GBM_BO_IMPORT_WL_BUFFER,
++ bo = gbm_bo_import(b->gbm_device, GBM_BO_IMPORT_WL_BUFFER,
+ buffer_resource, GBM_BO_USE_SCANOUT);
+ }
+ if (!bo)
+@@ -1091,7 +1094,7 @@ drm_output_prepare_cursor_view(struct drm_output *output,
+ if (ev->transform.enabled &&
+ (ev->transform.matrix.type > WESTON_MATRIX_TRANSFORM_TRANSLATE))
+ return NULL;
+- if (b->gbm == NULL)
++ if (b->gbm_device == NULL)
+ return NULL;
+ if (output->base.transform != WL_OUTPUT_TRANSFORM_NORMAL)
+ return NULL;
+@@ -1493,6 +1496,9 @@ init_drm(struct drm_backend *b, struct udev_device *device)
+ b->drm.fd = fd;
+ b->drm.filename = strdup(filename);
+
++ b->gbm.fd = fd;
++ b->gbm.filename = b->drm.filename;
++
+ ret = drmGetCap(fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap);
+ if (ret == 0 && cap == 1)
+ clk_id = CLOCK_MONOTONIC;
+@@ -1579,7 +1585,7 @@ drm_backend_create_gl_renderer(struct drm_backend *b)
+ n_formats = 3;
+ if (gl_renderer->create(b->compositor,
+ EGL_PLATFORM_GBM_KHR,
+- (void *)b->gbm,
++ (void *)b->gbm_device,
+ gl_renderer->opaque_attribs,
+ format,
+ n_formats) < 0) {
+@@ -1592,13 +1598,13 @@ drm_backend_create_gl_renderer(struct drm_backend *b)
+ static int
+ init_egl(struct drm_backend *b)
+ {
+- b->gbm = create_gbm_device(b->drm.fd);
++ b->gbm_device = create_gbm_device(b->gbm.fd);
+
+- if (!b->gbm)
++ if (!b->gbm_device)
+ return -1;
+
+ if (drm_backend_create_gl_renderer(b) < 0) {
+- gbm_device_destroy(b->gbm);
++ gbm_device_destroy(b->gbm_device);
+ return -1;
+ }
+
+@@ -1831,7 +1837,7 @@ drm_output_init_egl(struct drm_output *output, struct drm_backend *b)
+ };
+ int i, flags, n_formats = 1;
+
+- output->gbm_surface = gbm_surface_create(b->gbm,
++ output->gbm_surface = gbm_surface_create(b->gbm_device,
+ output->base.current_mode->width,
+ output->base.current_mode->height,
+ format[0],
+@@ -1862,7 +1868,7 @@ drm_output_init_egl(struct drm_output *output, struct drm_backend *b)
+ continue;
+
+ output->gbm_cursor_bo[i] =
+- gbm_bo_create(b->gbm, b->cursor_width, b->cursor_height,
++ gbm_bo_create(b->gbm_device, b->cursor_width, b->cursor_height,
+ GBM_FORMAT_ARGB8888, flags);
+ }
+
+@@ -2703,8 +2709,8 @@ drm_destroy(struct weston_compositor *ec)
+
+ weston_compositor_shutdown(ec);
+
+- if (b->gbm)
+- gbm_device_destroy(b->gbm);
++ if (b->gbm_device)
++ gbm_device_destroy(b->gbm_device);
+
+ weston_launcher_destroy(ec->launcher);
+
+@@ -2989,8 +2995,8 @@ switch_to_gl_renderer(struct drm_backend *b)
+
+ weston_log("Switching to GL renderer\n");
+
+- b->gbm = create_gbm_device(b->drm.fd);
+- if (!b->gbm) {
++ b->gbm_device = create_gbm_device(b->drm.fd);
++ if (!b->gbm_device) {
+ weston_log("Failed to create gbm device. "
+ "Aborting renderer switch\n");
+ return;
+@@ -3002,7 +3008,7 @@ switch_to_gl_renderer(struct drm_backend *b)
+ b->compositor->renderer->destroy(b->compositor);
+
+ if (drm_backend_create_gl_renderer(b) < 0) {
+- gbm_device_destroy(b->gbm);
++ gbm_device_destroy(b->gbm_device);
+ weston_log("Failed to create GL renderer. Quitting.\n");
+ /* FIXME: we need a function to shutdown cleanly */
+ assert(0);
+@@ -3191,8 +3197,8 @@ err_drm_source:
+ err_udev_input:
+ udev_input_destroy(&b->input);
+ err_sprite:
+- if (b->gbm)
+- gbm_device_destroy(b->gbm);
++ if (b->gbm_device)
++ gbm_device_destroy(b->gbm_device);
+ destroy_sprites(b);
+ err_udev_dev:
+ udev_device_unref(drm_device);
+--
+2.9.3
+
diff --git a/recipes-graphics/wayland/files/0002-compositor-drm-Add-support-for-Tegra-Jetson-TK1.patch b/recipes-graphics/wayland/files/0002-compositor-drm-Add-support-for-Tegra-Jetson-TK1.patch
new file mode 100644
index 0000000..83aafe7
--- /dev/null
+++ b/recipes-graphics/wayland/files/0002-compositor-drm-Add-support-for-Tegra-Jetson-TK1.patch
@@ -0,0 +1,195 @@
+From 22cbce65feeb49f547f412ab77a9430773b692b8 Mon Sep 17 00:00:00 2001
+From: James Thomas <james.thomas@codethink.co.uk>
+Date: Fri, 20 Jun 2014 12:42:32 +0000
+Subject: [PATCH 2/6] compositor-drm: Add support for Tegra Jetson TK1
+
+Update configure.ac to add check for libdrm_tegra
+---
+ configure.ac | 18 ++++++++++
+ src/compositor-drm.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++--
+ 2 files changed, 109 insertions(+), 3 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index 97a7769..fbb2c8c 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -133,6 +133,23 @@ fi
+ PKG_CHECK_MODULES(LIBDRM, [libdrm],
+ [AC_DEFINE(HAVE_LIBDRM, 1, [Define if libdrm is available]) have_libdrm=yes], have_libdrm=no)
+
++AC_ARG_ENABLE(libdrm-tegra,
++ AS_HELP_STRING([--disable-libdrm-tegra],
++ [do not build support for nvidia Jetson TK1]),,
++ enable_libdrm_tegra=auto)
++
++if test "x$enable_libdrm_tegra" != "xno"; then
++ PKG_CHECK_MODULES(LIBDRM_TEGRA,
++ libdrm_tegra,
++ have_libdrm_tegra=yes,
++ have_libdrm_tegra=no)
++ if test "x$have_libdrm_tegra" = "xno" -a "x$enable_libdrm_tegra" = "xyes"; then
++ AC_MSG_ERROR([Tegra support explicitly requested, but libdrm_tegra not found])
++ fi
++ AS_IF([test "x$have_libdrm_tegra" = "xyes"],
++ AC_DEFINE([HAVE_DRM_TEGRA], [1], [Enable tegra support in drm backend]))
++fi
++
+ AC_ARG_ENABLE(x11-compositor, [ --enable-x11-compositor],,
+ enable_x11_compositor=yes)
+ AM_CONDITIONAL(ENABLE_X11_COMPOSITOR, test x$enable_x11_compositor = xyes)
+@@ -699,4 +716,5 @@ AC_MSG_RESULT([
+ libwebp Support ${have_webp}
+ libunwind Support ${have_libunwind}
+ VA H.264 encoding Support ${have_libva}
++ Tegra DRM Support ${have_libdrm_tegra}
+ ])
+diff --git a/src/compositor-drm.c b/src/compositor-drm.c
+index 5db86dc..90cae10 100644
+--- a/src/compositor-drm.c
++++ b/src/compositor-drm.c
+@@ -45,6 +45,9 @@
+
+ #include <gbm.h>
+ #include <libudev.h>
++#ifdef HAVE_DRM_TEGRA
++#include <tegra_drm.h>
++#endif
+
+ #include "compositor.h"
+ #include "compositor-drm.h"
+@@ -226,6 +229,32 @@ static struct gl_renderer_interface *gl_renderer;
+
+ static const char default_seat[] = "seat0";
+
++static int
++drm_tegra_import(int fd, uint32_t handle)
++{
++ #ifdef HAVE_DRM_TEGRA
++ struct drm_tegra_gem_set_tiling args;
++ int err;
++
++ memset(&args, 0, sizeof(args));
++ args.handle = handle;
++ args.mode = DRM_TEGRA_GEM_TILING_MODE_BLOCK;
++ args.value = 4;
++
++ err = ioctl(fd, DRM_IOCTL_TEGRA_GEM_SET_TILING, &args);
++ if (err < 0) {
++ weston_log("failed to set tiling parameters: %m\n");
++ return -errno;
++ }
++ return 0;
++ #else
++ weston_log("DRM device is a tegra but weston compiled without "
++ "libdrm tegra");
++
++ return -1;
++ #endif
++}
++
+ static void
+ drm_output_set_cursor(struct drm_output *output);
+
+@@ -368,6 +397,32 @@ drm_fb_get_from_bo(struct gbm_bo *bo,
+ fb->size = fb->stride * height;
+ fb->fd = backend->drm.fd;
+
++ if (backend->drm.fd != backend->gbm.fd) {
++ int fd;
++
++ ret = drmPrimeHandleToFD(backend->gbm.fd, fb->handle, 0,
++ &fd);
++ if (ret) {
++ weston_log("failed to export bo: %m\n");
++ goto err_free;
++ }
++
++ ret = drmPrimeFDToHandle(backend->drm.fd, fd, &fb->handle);
++ if (ret) {
++ weston_log("failed to import bo: %m\n");
++ goto err_free;
++ }
++
++ close(fd);
++
++ ret = drm_tegra_import(backend->drm.fd, fb->handle);
++ if (ret < 0) {
++ weston_log("failed to import handle: %s\n",
++ strerror(-ret));
++ goto err_free;
++ }
++ }
++
+ if (backend->min_width > width || width > backend->max_width ||
+ backend->min_height > height ||
+ height > backend->max_height) {
+@@ -1496,8 +1551,14 @@ init_drm(struct drm_backend *b, struct udev_device *device)
+ b->drm.fd = fd;
+ b->drm.filename = strdup(filename);
+
+- b->gbm.fd = fd;
+- b->gbm.filename = b->drm.filename;
++ if (b->gbm.filename) {
++ fd = weston_launcher_open(b->compositor->launcher, b->gbm.filename,
++ O_RDWR);
++ b->gbm.fd = fd;
++ } else {
++ b->gbm.fd = fd;
++ b->gbm.filename = b->drm.filename;
++ }
+
+ ret = drmGetCap(fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap);
+ if (ret == 0 && cap == 1)
+@@ -2808,7 +2869,7 @@ find_primary_gpu(struct drm_backend *b, const char *seat)
+ struct udev_enumerate *e;
+ struct udev_list_entry *entry;
+ const char *path, *device_seat, *id;
+- struct udev_device *device, *drm_device, *pci;
++ struct udev_device *device, *drm_device, *pci, *soc = NULL;
+
+ e = udev_enumerate_new(b->udev);
+ udev_enumerate_add_match_subsystem(e, "drm");
+@@ -2818,6 +2879,7 @@ find_primary_gpu(struct drm_backend *b, const char *seat)
+ drm_device = NULL;
+ udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
+ path = udev_list_entry_get_name(entry);
++ weston_log("udev path = %s\n", path);
+ device = udev_device_new_from_syspath(b->udev, path);
+ if (!device)
+ continue;
+@@ -2839,6 +2901,32 @@ find_primary_gpu(struct drm_backend *b, const char *seat)
+ drm_device = device;
+ break;
+ }
++ } else {
++ soc = udev_device_get_parent_with_subsystem_devtype(
++ device,
++ "soc",
++ NULL);
++ if (soc) {
++ id = udev_device_get_sysattr_value(soc,
++ "family");
++ if (id && !strcmp(id, "Tegra")) {
++ if (drm_device) {
++ /* Previously have found the
++ * drm device, use this device
++ * as the GBM device
++ */
++ if (udev_device_get_devnode(
++ device)) {
++ b->gbm.filename = strdup(
++ udev_device_get_devnode(device));
++ break;
++ }
++ continue;
++ }
++ drm_device = device;
++ continue;
++ }
++ }
+ }
+
+ if (!drm_device)
+--
+2.9.3
+
diff --git a/recipes-graphics/wayland/files/0003-Add-glFinish-to-DRM-backend-to-avoid-tearing.patch b/recipes-graphics/wayland/files/0003-Add-glFinish-to-DRM-backend-to-avoid-tearing.patch
new file mode 100644
index 0000000..c7426a4
--- /dev/null
+++ b/recipes-graphics/wayland/files/0003-Add-glFinish-to-DRM-backend-to-avoid-tearing.patch
@@ -0,0 +1,48 @@
+From 412880dfeb9951f9e807ed36e293805bc97beb32 Mon Sep 17 00:00:00 2001
+From: Alexandre Courbot <acourbot@nvidia.com>
+Date: Thu, 24 Sep 2015 13:19:02 +0900
+Subject: [PATCH 3/6] Add glFinish to DRM backend to avoid tearing
+
+---
+ Makefile.am | 3 ++-
+ src/compositor-drm.c | 2 ++
+ 2 files changed, 4 insertions(+), 1 deletion(-)
+
+diff --git a/Makefile.am b/Makefile.am
+index 00b74e5..071d540 100644
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -281,8 +281,9 @@ drm_backend_la_LIBADD = \
+ $(COMPOSITOR_LIBS) \
+ $(DRM_COMPOSITOR_LIBS) \
+ $(INPUT_BACKEND_LIBS) \
+- libshared.la \
+ $(CLOCK_GETTIME_LIBS) \
++ $(SIMPLE_EGL_CLIENT_LIBS) \
++ libshared.la -lrt \
+ libsession-helper.la
+ drm_backend_la_CFLAGS = \
+ $(COMPOSITOR_CFLAGS) \
+diff --git a/src/compositor-drm.c b/src/compositor-drm.c
+index 90cae10..17ba640 100644
+--- a/src/compositor-drm.c
++++ b/src/compositor-drm.c
+@@ -715,6 +715,7 @@ drm_output_repaint(struct weston_output *output_base,
+ output_base->set_dpms(output_base, WESTON_DPMS_ON);
+ }
+
++ glFinish();
+ if (drmModePageFlip(backend->drm.fd, output->crtc_id,
+ output->next->fb_id,
+ DRM_MODE_PAGE_FLIP_EVENT, output) < 0) {
+@@ -838,6 +839,7 @@ drm_output_start_repaint_loop(struct weston_output *output_base)
+ */
+ fb_id = output->current->fb_id;
+
++ glFinish();
+ if (drmModePageFlip(backend->drm.fd, output->crtc_id, fb_id,
+ DRM_MODE_PAGE_FLIP_EVENT, output) < 0) {
+ weston_log("queueing pageflip failed: %m\n");
+--
+2.9.3
+
diff --git a/recipes-graphics/wayland/files/0004-use-name-based-detection-of-display-and-render-nodes.patch b/recipes-graphics/wayland/files/0004-use-name-based-detection-of-display-and-render-nodes.patch
new file mode 100644
index 0000000..a5969ab
--- /dev/null
+++ b/recipes-graphics/wayland/files/0004-use-name-based-detection-of-display-and-render-nodes.patch
@@ -0,0 +1,73 @@
+From 6c8d3da72fabd2a915e18dbf9fb65b7c1134d65d Mon Sep 17 00:00:00 2001
+From: Alexandre Courbot <acourbot@nvidia.com>
+Date: Fri, 9 Sep 2016 15:06:27 +0900
+Subject: [PATCH 4/6] use name-based detection of display and render nodes
+
+The previous detection scheme assumed that the graphics nodes were under
+"soc0". This is no longer true for Jetson TX1. Instead, assume that
+card0 is the display node, and card1 the render one.
+---
+ src/compositor-drm.c | 39 ++++++++-------------------------------
+ 1 file changed, 8 insertions(+), 31 deletions(-)
+
+diff --git a/src/compositor-drm.c b/src/compositor-drm.c
+index 17ba640..214fc41 100644
+--- a/src/compositor-drm.c
++++ b/src/compositor-drm.c
+@@ -2871,7 +2871,7 @@ find_primary_gpu(struct drm_backend *b, const char *seat)
+ struct udev_enumerate *e;
+ struct udev_list_entry *entry;
+ const char *path, *device_seat, *id;
+- struct udev_device *device, *drm_device, *pci, *soc = NULL;
++ struct udev_device *device, *drm_device, *pci;
+
+ e = udev_enumerate_new(b->udev);
+ udev_enumerate_add_match_subsystem(e, "drm");
+@@ -2904,37 +2904,14 @@ find_primary_gpu(struct drm_backend *b, const char *seat)
+ break;
+ }
+ } else {
+- soc = udev_device_get_parent_with_subsystem_devtype(
+- device,
+- "soc",
+- NULL);
+- if (soc) {
+- id = udev_device_get_sysattr_value(soc,
+- "family");
+- if (id && !strcmp(id, "Tegra")) {
+- if (drm_device) {
+- /* Previously have found the
+- * drm device, use this device
+- * as the GBM device
+- */
+- if (udev_device_get_devnode(
+- device)) {
+- b->gbm.filename = strdup(
+- udev_device_get_devnode(device));
+- break;
+- }
+- continue;
+- }
+- drm_device = device;
+- continue;
+- }
+- }
++ id = udev_device_get_sysname(device);
++ if (!strcmp(id, "card0"))
++ drm_device = device;
++ else if (!strcmp(id, "card1"))
++ b->gbm.filename = strdup(udev_device_get_devnode(device));
++ else
++ udev_device_unref(device);
+ }
+-
+- if (!drm_device)
+- drm_device = device;
+- else
+- udev_device_unref(device);
+ }
+
+ udev_enumerate_unref(e);
+--
+2.9.3
+
diff --git a/recipes-graphics/wayland/weston_%.bbappend b/recipes-graphics/wayland/weston_%.bbappend
new file mode 100644
index 0000000..cb57c9b
--- /dev/null
+++ b/recipes-graphics/wayland/weston_%.bbappend
@@ -0,0 +1,12 @@
+FILESEXTRAPATHS_prepend_tegra124m := "${THISDIR}/files:"
+
+PACKAGE_ARCH_tegra124m = "${MACHINE_ARCH}"
+
+COMPATIBLE_MACHINE_tegra124m = "(apalis-tk1-mainline)"
+
+SRC_URI_append_tegra124m = "\
+ file://0001-compositor-drm-Add-new-gbm-struct-to-allow-for-a-sep.patch \
+ file://0002-compositor-drm-Add-support-for-Tegra-Jetson-TK1.patch \
+ file://0003-Add-glFinish-to-DRM-backend-to-avoid-tearing.patch \
+ file://0004-use-name-based-detection-of-display-and-render-nodes.patch \
+ "
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
new file mode 100644
index 0000000..39b92e8
--- /dev/null
+++ b/recipes-graphics/xorg-xserver/xserver-xorg-1.18.4/0001-HACK-use-render-nodes-and-tegra-tiling-format.patch
@@ -0,0 +1,145 @@
+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
new file mode 100644
index 0000000..f27c2a9
--- /dev/null
+++ b/recipes-graphics/xorg-xserver/xserver-xorg-1.18.4/0002-HACK-enable-GLX-with-DRI3.patch
@@ -0,0 +1,72 @@
+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
new file mode 100644
index 0000000..746f367
--- /dev/null
+++ b/recipes-graphics/xorg-xserver/xserver-xorg_1.18.4.bbappend
@@ -0,0 +1,20 @@
+# 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)"
+
+# provided by xf86-input-evdev_2.10.0
+do_install_append () {
+ rm -f ${D}/usr/share/X11/xorg.conf.d/10-evdev.conf
+}
+
+PACKAGECONFIG_tegra124m ?= "dri2 dri3 xshmfence glamor xwayland udev ${XORG_CRYPTO} "
+