summaryrefslogtreecommitdiff
path: root/recipes-graphics/mesa/mesa/0001-gallium-add-tegra-support.patch
blob: f47e2c5b6c39dba85f581aef6e09449d1d7bfa97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
From 2ec5a4bc8eec0908275f3a3259376f1ad8efaaa6 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 1/4] 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>

forward port to mesa 17.0.2
Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>

forward port to mesa 17.1.7
Signed-off-by: Dominik Sliwa <dominik.sliwa@toradex.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       |  4 ++
 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              | 10 +++
 src/gallium/targets/dri/Makefile.am                |  2 +
 src/gallium/targets/dri/target.c                   |  4 ++
 .../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           | 34 ++++++++++
 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    | 74 ++++++++++++++++++++++
 src/mesa/drivers/dri/nouveau/nouveau_screen.h      |  1 +
 21 files changed, 262 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 fd346c8..790388b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -79,6 +79,7 @@ LIBDRM_INTEL_REQUIRED=2.4.75
 LIBDRM_NVVIEUX_REQUIRED=2.4.66
 LIBDRM_NOUVEAU_REQUIRED=2.4.66
 LIBDRM_FREEDRENO_REQUIRED=2.4.74
+LIBDRM_TEGRA_REQUIRED=2.4.66
 LIBDRM_VC4_REQUIRED=2.4.69
 LIBDRM_ETNAVIV_REQUIRED=2.4.80
 
@@ -1245,7 +1246,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,svga,swrast,swr,vc4,virgl,etnaviv,imx,tegra"
         @<:@default=r300,r600,svga,swrast@:>@])],
     [with_gallium_drivers="$withval"],
     [with_gallium_drivers="$GALLIUM_DRIVERS_DEFAULT"])
@@ -2518,6 +2519,13 @@ if test -n "$with_gallium_drivers"; then
                 require_basic_egl "virgl"
             fi
             ;;
+        xtegra)
+#            PKG_CHECK_MODULES([TEGRA], [libdrm_tegra >= $LIBDRM_TEGRA_REQUIRED])
+            HAVE_GALLIUM_TEGRA=yes
+            require_libdrm "tegra"
+#            gallium_require_drm_loader
+#            require_egl_drm "tegra"
+            ;;
         *)
             AC_MSG_ERROR([Unknown Gallium driver: $driver])
             ;;
@@ -2621,6 +2629,7 @@ AM_CONDITIONAL(HAVE_GALLIUM_SWRAST, test "x$HAVE_GALLIUM_SOFTPIPE" = xyes -o \
                                          "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)
 
@@ -2766,6 +2775,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
@@ -2809,6 +2819,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 38da63b..1df0d3c 100644
--- a/src/gallium/Makefile.am
+++ b/src/gallium/Makefile.am
@@ -95,6 +95,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 a4f5cfc..3cad124 100644
--- a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
+++ b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
@@ -139,6 +139,11 @@ static const struct drm_driver_descriptor driver_descriptors[] = {
         .configuration = configuration_query,
     },
     {
+        .driver_name = "tegra",
+        .create_screen = pipe_tegra_create_screen,
+        .configuration = configuration_query,
+    },
+    {
         .driver_name = "etnaviv",
         .create_screen = pipe_etna_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 3159df6..99b6cb5 100644
--- a/src/gallium/auxiliary/target-helpers/drm_helper.h
+++ b/src/gallium/auxiliary/target-helpers/drm_helper.h
@@ -284,4 +284,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 2c60441..b45cc7b 100644
--- a/src/gallium/drivers/nouveau/nouveau_buffer.c
+++ b/src/gallium/drivers/nouveau/nouveau_buffer.c
@@ -117,6 +117,7 @@ nouveau_buffer_destroy(struct pipe_screen *pscreen,
                        struct pipe_resource *presource)
 {
    struct nv04_resource *res = nv04_resource(presource);
+   struct nouveau_screen *scr = nouveau_screen(pscreen);
 
    nouveau_buffer_release_gpu_storage(res);
 
@@ -128,6 +129,9 @@ nouveau_buffer_destroy(struct pipe_screen *pscreen,
 
    util_range_destroy(&res->valid_buffer_range);
 
+   if (res->scanout)
+       renderonly_scanout_destroy(res->scanout, scr->ro);
+
    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 e4fbae9..b326c52 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/disk_cache.h"
 #include "util/u_memory.h"
 
@@ -62,6 +63,8 @@ struct nouveau_screen {
 
    struct disk_cache *disk_shader_cache;
 
+   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 && scr->ro)
+           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,10 @@
+include $(top_srcdir)/src/gallium/Automake.inc
+
+AM_CPPFLAGS = \
+	$(GALLIUM_CFLAGS) \
+	$(TEGRA_CFLAGS) \
+	$(LIBDRM_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 8363406..4bfcf3e 100644
--- a/src/gallium/targets/dri/Makefile.am
+++ b/src/gallium/targets/dri/Makefile.am
@@ -92,6 +92,8 @@ include $(top_srcdir)/src/gallium/drivers/virgl/Automake.inc
 include $(top_srcdir)/src/gallium/drivers/etnaviv/Automake.inc
 include $(top_srcdir)/src/gallium/drivers/imx/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 d24a61d..600557b 100644
--- a/src/gallium/targets/dri/target.c
+++ b/src/gallium/targets/dri/target.c
@@ -79,3 +79,7 @@ DEFINE_LOADER_DRM_ENTRYPOINT(vc4)
 DEFINE_LOADER_DRM_ENTRYPOINT(imx_drm)
 DEFINE_LOADER_DRM_ENTRYPOINT(etnaviv)
 #endif
+
+#if defined(GALLIUM_TEGRA)
+DEFINE_LOADER_DRM_ENTRYPOINT(tegra)
+#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 4ca2d35..8a457d5 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:
 	mtx_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 = renderonly_dup(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..a48dca4
--- /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,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 \
+	$(GALLIUM_WINSYS_CFLAGS) \
+	$(TEGRA_CFLAGS) \
+	$(LIBDRM_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..c439b8d
--- /dev/null
+++ b/src/gallium/winsys/tegra/drm/tegra_drm_winsys.c
@@ -0,0 +1,76 @@
+/*
+ * 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>
+ *    Alexandre Courbot <acourbot@nvidia.com>
+ */
+
+#include "tegra_drm_public.h"
+#include "../../nouveau/drm/nouveau_drm_public.h"
+#include "renderonly/renderonly.h"
+
+#include <libdrm/tegra_drm.h>
+#include <xf86drm.h>
+#include <stdio.h>
+
+static struct renderonly_scanout *
+tegra_create_with_tiling_for_resource(struct pipe_resource *rsc,
+                                      struct renderonly *ro)
+{
+   struct renderonly_scanout *scanout;
+
+   scanout = renderonly_create_gpu_import_for_resource(rsc, ro);
+   if (!scanout)
+      return NULL;
+
+   struct drm_tegra_gem_set_tiling args = {
+      .handle = scanout->handle,
+      .mode = DRM_TEGRA_GEM_TILING_MODE_BLOCK,
+      .value = 4
+   };
+
+   int ret = drmIoctl(ro->kms_fd, DRM_IOCTL_TEGRA_GEM_SET_TILING, &args);
+   if (ret)
+      return NULL;
+
+   return scanout;
+}
+
+struct pipe_screen *tegra_drm_screen_create(int fd)
+{
+   struct renderonly ro = {
+      .create_for_resource = tegra_create_with_tiling_for_resource,
+      .kms_fd = fd,
+      .gpu_fd = drmOpenWithType("nouveau", NULL, DRM_NODE_RENDER), 
+   };
+
+   if (ro.gpu_fd < 0)
+      return NULL;
+
+   struct pipe_screen *screen = nouveau_drm_screen_create_renderonly(ro.gpu_fd, &ro);
+   if (!screen)
+      drmClose(ro.gpu_fd);
+
+   /* printf("Tegra + Nouveau renderonly mode\n"); */
+   return screen;
+};
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_screen.h b/src/mesa/drivers/dri/nouveau/nouveau_screen.h
index e3c1928..720ee31 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_screen.h
+++ b/src/mesa/drivers/dri/nouveau/nouveau_screen.h
@@ -36,6 +36,7 @@ struct nouveau_screen {
 	struct nouveau_drm *drm;
 	struct nouveau_device *device;
 	const struct nouveau_driver *driver;
+    struct renderonly *ro;
 };
 
 #endif
-- 
2.7.4