summaryrefslogtreecommitdiff
path: root/recipes-graphics/xorg-xserver/xserver-xorg-1.18.4/0001-HACK-use-render-nodes-and-tegra-tiling-format.patch
blob: 39b92e820d59e31f05fd1547b70d7699b881a272 (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
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