summaryrefslogtreecommitdiffstats
path: root/meta-agl-drm-lease/recipes-graphics/kmscube/kmscube/0002-Add-DRM-lease-support.patch
blob: 0366bef0b9305c97921b3bda8856aa49bde19b56 (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
From 3a766fb852b53316f4b4c0b37ec801a5b188093b Mon Sep 17 00:00:00 2001
From: Damian Hobson-Garcia <dhobsong@igel.co.jp>
Date: Wed, 16 Dec 2020 16:21:57 +0900
Subject: [PATCH] Add DRM lease support

---
 drm-atomic.c      |  4 ++--
 drm-common.c      | 21 +++++++++++++++++++--
 drm-common.h      |  9 ++++++---
 drm-legacy.c      |  4 ++--
 kmscube.c         | 12 +++++++++---
 meson.build       |  5 +++++
 meson_options.txt |  5 +++++
 texturator.c      |  2 +-
 8 files changed, 49 insertions(+), 13 deletions(-)

diff --git a/drm-atomic.c b/drm-atomic.c
index d748772..8cb3ca5 100644
--- a/drm-atomic.c
+++ b/drm-atomic.c
@@ -337,12 +337,12 @@ static int get_plane_id(void)
 	return ret;
 }
 
-const struct drm * init_drm_atomic(const char *device, const char *mode_str, unsigned int vrefresh)
+const struct drm * init_drm_atomic(const char *device, const char *mode_str, unsigned int vrefresh, int lease)
 {
 	uint32_t plane_id;
 	int ret;
 
-	ret = init_drm(&drm, device, mode_str, vrefresh);
+	ret = init_drm(&drm, device, mode_str, vrefresh, lease);
 	if (ret)
 		return NULL;
 
diff --git a/drm-common.c b/drm-common.c
index b9d61c1..6e7d1ce 100644
--- a/drm-common.c
+++ b/drm-common.c
@@ -32,6 +32,10 @@
 #include "common.h"
 #include "drm-common.h"
 
+#ifdef HAVE_DRM_LEASE
+#include "dlmclient.h"
+#endif
+
 WEAK uint64_t
 gbm_bo_get_modifier(struct gbm_bo *bo);
 
@@ -169,6 +173,19 @@ static int get_resources(int fd, drmModeRes **resources)
 	return 0;
 }
 
+static int open_device(struct drm *drm, const char *device, int lease)
+{
+        if (!lease)
+                return open(device, O_RDWR);
+
+#ifdef HAVE_DRM_LEASE
+	drm->lease = dlm_get_lease(device);
+	if (drm->lease)
+	    return dlm_lease_fd(drm->lease);
+#endif
+	return -1;
+}
+
 #define MAX_DRM_DEVICES 64
 
 static int find_drm_device(drmModeRes **resources)
@@ -208,7 +225,7 @@ static int find_drm_device(drmModeRes **resources)
 	return fd;
 }
 
-int init_drm(struct drm *drm, const char *device, const char *mode_str, unsigned int vrefresh)
+int init_drm(struct drm *drm, const char *device, const char *mode_str, unsigned int vrefresh, int lease)
 {
 	drmModeRes *resources;
 	drmModeConnector *connector = NULL;
@@ -216,7 +233,7 @@ int init_drm(struct drm *drm, const char *device, const char *mode_str, unsigned
 	int i, ret, area;
 
 	if (device) {
-		drm->fd = open(device, O_RDWR);
+		drm->fd = open_device(drm, device, lease);
 		ret = get_resources(drm->fd, &resources);
 		if (ret < 0 && errno == EOPNOTSUPP)
 			printf("%s does not look like a modeset device\n", device);
diff --git a/drm-common.h b/drm-common.h
index c4eb886..5119e79 100644
--- a/drm-common.h
+++ b/drm-common.h
@@ -51,6 +51,9 @@ struct connector {
 struct drm {
 	int fd;
 
+        /* only used for DRM lease */
+        struct dlm_lease *lease;
+
 	/* only used for atomic: */
 	struct plane *plane;
 	struct crtc *crtc;
@@ -73,8 +76,8 @@ struct drm_fb {
 
 struct drm_fb * drm_fb_get_from_bo(struct gbm_bo *bo);
 
-int init_drm(struct drm *drm, const char *device, const char *mode_str, unsigned int vrefresh);
-const struct drm * init_drm_legacy(const char *device, const char *mode_str, unsigned int vrefresh);
-const struct drm * init_drm_atomic(const char *device, const char *mode_str, unsigned int vrefresh);
+int init_drm(struct drm *drm, const char *device, const char *mode_str, unsigned int vrefresh, int lease);
+const struct drm * init_drm_legacy(const char *device, const char *mode_str, unsigned int vrefresh, int lease);
+const struct drm * init_drm_atomic(const char *device, const char *mode_str, unsigned int vrefresh, int lease);
 
 #endif /* _DRM_COMMON_H */
diff --git a/drm-legacy.c b/drm-legacy.c
index 56a0fed..03db13d 100644
--- a/drm-legacy.c
+++ b/drm-legacy.c
@@ -122,11 +122,11 @@ static int legacy_run(const struct gbm *gbm, const struct egl *egl)
 	return 0;
 }
 
-const struct drm * init_drm_legacy(const char *device, const char *mode_str, unsigned int vrefresh)
+const struct drm * init_drm_legacy(const char *device, const char *mode_str, unsigned int vrefresh, int lease)
 {
 	int ret;
 
-	ret = init_drm(&drm, device, mode_str, vrefresh);
+	ret = init_drm(&drm, device, mode_str, vrefresh, lease);
 	if (ret)
 		return NULL;
 
diff --git a/kmscube.c b/kmscube.c
index f14c1d9..abb5bdd 100644
--- a/kmscube.c
+++ b/kmscube.c
@@ -41,12 +41,13 @@ static const struct egl *egl;
 static const struct gbm *gbm;
 static const struct drm *drm;
 
-static const char *shortopts = "AD:M:m:V:v:";
+static const char *shortopts = "AD:LM:m:V:v:";
 
 static const struct option longopts[] = {
 	{"atomic", no_argument,       0, 'A'},
 	{"device", required_argument, 0, 'D'},
 	{"format", required_argument, 0, 'f'},
+	{"drm-lease", no_argument, 0, 'L'},
 	{"mode",   required_argument, 0, 'M'},
 	{"modifier", required_argument, 0, 'm'},
 	{"samples",  required_argument, 0, 's'},
@@ -62,6 +63,9 @@ static void usage(const char *name)
 			"options:\n"
 			"    -A, --atomic             use atomic modesetting and fencing\n"
 			"    -D, --device=DEVICE      use the given device\n"
+#ifdef HAVE_DRM_LEASE
+			"    -L, --drm-lease          the given device is the name of a DRM lease:\n"
+#endif
 			"    -M, --mode=MODE          specify mode, one of:\n"
 			"        smooth    -  smooth shaded cube (default)\n"
 			"        rgba      -  rgba textured cube\n"
@@ -87,6 +89,7 @@ int main(int argc, char *argv[])
 	uint64_t modifier = DRM_FORMAT_MOD_LINEAR;
 	int samples = 0;
 	int atomic = 0;
+	int lease = 0;
 	int opt;
 	unsigned int len;
 	unsigned int vrefresh = 0;
@@ -119,6 +122,11 @@ int main(int argc, char *argv[])
 					     fourcc[2], fourcc[3]);
 			break;
 		}
+#ifdef HAVE_DRM_LEASE
+		case 'L':
+                        lease = 1;
+                        break;
+#endif
 		case 'M':
 			if (strcmp(optarg, "smooth") == 0) {
 				mode = SMOOTH;
@@ -164,9 +170,9 @@ int main(int argc, char *argv[])
 	}
 
 	if (atomic)
-		drm = init_drm_atomic(device, mode_str, vrefresh);
+		drm = init_drm_atomic(device, mode_str, vrefresh, lease);
 	else
-		drm = init_drm_legacy(device, mode_str, vrefresh);
+		drm = init_drm_legacy(device, mode_str, vrefresh, lease);
 	if (!drm) {
 		printf("failed to initialize %s DRM\n", atomic ? "atomic" : "legacy");
 		return -1;
diff --git a/meson.build b/meson.build
index df9c315..1b47a52 100644
--- a/meson.build
+++ b/meson.build
@@ -91,6 +91,11 @@ else
   message('Building without gstreamer support')
 endif
 
+if get_option('drm_lease').enabled()
+  dep_common += dependency('libdlmclient')
+  add_project_arguments('-DHAVE_DRM_LEASE', language : 'c')
+endif
+
 executable('kmscube', sources, dependencies : dep_common, install : true)
 
 
diff --git a/meson_options.txt b/meson_options.txt
index 1ed8abc..d932a1c 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -3,3 +3,8 @@ option(
   type : 'feature',
   description : 'Enable support for gstreamer and cube-video'
 )
+option(
+  'drm_lease',
+  type : 'feature',
+  description : 'Enable support for running as a DRM lease client'
+)
diff --git a/texturator.c b/texturator.c
index 3d09e9e..9b87f0d 100644
--- a/texturator.c
+++ b/texturator.c
@@ -948,7 +948,7 @@ int main(int argc, char *argv[])
 	print_summary();
 
 	/* no real need for atomic here: */
-	drm = init_drm_legacy(device, mode_str, vrefresh);
+	drm = init_drm_legacy(device, mode_str, vrefresh, 0);
 	if (!drm) {
 		printf("failed to initialize DRM\n");
 		return -1;