summaryrefslogtreecommitdiffstats
path: root/meta-agl-drm-lease/recipes-graphics/weston/weston/0002-Add-DRM-lease-support.patch
blob: a2249460fe5f0df836c93ddd8c55e576347c94dc (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
From 5c315a4e4ab5e0d0376508f72c6f8a8070251c3f Mon Sep 17 00:00:00 2001
From: Damian Hobson-Garcia <dhobsong@igel.co.jp>
Date: Mon, 11 Apr 2022 18:43:06 +0900
Subject: [PATCH 2/3] Add DRM lease support

Add a command line option to use a DRM lease instead of a primary node for
output when using the DRM backend.

%% original patch: 0002-Add-DRM-lease-support.patch
---
 compositor/drm-lease.c      | 53 +++++++++++++++++++++++++++++++++++++
 compositor/drm-lease.h      | 40 ++++++++++++++++++++++++++++
 compositor/main.c           | 10 +++++++
 compositor/meson.build      |  5 ++++
 libweston/backend-drm/drm.c |  1 +
 meson_options.txt           |  7 +++++
 6 files changed, 116 insertions(+)
 create mode 100644 compositor/drm-lease.c
 create mode 100644 compositor/drm-lease.h

diff --git a/compositor/drm-lease.c b/compositor/drm-lease.c
new file mode 100644
index 0000000..fdb1f5e
--- /dev/null
+++ b/compositor/drm-lease.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright © 2021 IGEL Co., Ltd.
+ *
+ * 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 "drm-lease.h"
+
+#include <libweston/libweston.h>
+
+int get_drm_lease(struct dlm_lease **drm_lease, const char *drm_lease_name) {
+	if (!drm_lease_name)
+		return -1;
+
+	int drm_fd;
+	struct dlm_lease *lease = dlm_get_lease(drm_lease_name);
+	if (lease) {
+		drm_fd = dlm_lease_fd(lease);
+		if (drm_fd < 0)
+			dlm_release_lease(lease);
+	}
+	if (drm_fd < 0)
+	    weston_log("Could not get DRM lease %s\n", drm_lease_name);
+
+        *drm_lease = lease;
+	return drm_fd;
+}
+
+void release_drm_lease(struct dlm_lease *lease) {
+	if (lease)
+		dlm_release_lease(lease);
+}
+
+
diff --git a/compositor/drm-lease.h b/compositor/drm-lease.h
new file mode 100644
index 0000000..a102e4c
--- /dev/null
+++ b/compositor/drm-lease.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright © 2021 IGEL Co., Ltd.
+ *
+ * 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 "config.h"
+
+#ifdef BUILD_DRM_LEASE_CLIENT
+#include <dlmclient.h>
+int get_drm_lease(struct dlm_lease **drm_lease, const char *drm_lease_name);
+void release_drm_lease(struct dlm_lease *drm_lease);
+#else
+struct dlm_lease;
+int get_drm_lease(struct dlm_lease **drm_lease, const char *drm_lease_name) {
+	return -1;
+}
+void release_drm_lease(struct dlm_lease *drm_lease) {
+}
+
+#endif
diff --git a/compositor/main.c b/compositor/main.c
index 322f2ff..419ad06 100644
--- a/compositor/main.c
+++ b/compositor/main.c
@@ -65,6 +65,7 @@
 #include <libweston/weston-log.h>
 #include <libweston/remoting-plugin.h>
 #include <libweston/pipewire-plugin.h>
+#include "drm-lease.h"
 
 #define WINDOW_TITLE "Weston Compositor"
 /* flight recorder size (in bytes) */
@@ -127,6 +128,7 @@ struct wet_compositor {
 	pid_t autolaunch_pid;
 	bool autolaunch_watch;
 	bool use_color_manager;
+	struct dlm_lease *drm_lease;
 };
 
 static FILE *weston_logfile = NULL;
@@ -687,6 +689,9 @@ usage(int error_code)
 		"  --seat=SEAT\t\tThe seat that weston should run on, instead of the seat defined in XDG_SEAT\n"
 		"  --tty=TTY\t\tThe tty to use\n"
 		"  --drm-device=CARD\tThe DRM device to use, e.g. \"card0\".\n"
+#ifdef BUILD_DRM_LEASE_CLIENT
+		"  --drm-lease=lease\tUse the specified DRM lease. e.g \"card0-HDMI-A-1\"\n"
+#endif
 		"  --use-pixman\t\tUse the pixman (CPU) renderer\n"
 		"  --current-mode\tPrefer current KMS mode over EDID preferred mode\n"
 		"  --continue-without-input\tAllow the compositor to start without input devices\n\n");
@@ -2626,6 +2631,7 @@ load_drm_backend(struct weston_compositor *c,
 	struct wet_compositor *wet = to_wet_compositor(c);
 	bool without_input = false;
 	int ret = 0;
+	char *drm_lease_name = NULL;
 
 	wet->drm_use_current_mode = false;
 
@@ -2637,6 +2643,7 @@ load_drm_backend(struct weston_compositor *c,
 		{ WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
 		{ WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
 		{ WESTON_OPTION_STRING, "drm-device", 0, &config.specific_device },
+		{ WESTON_OPTION_STRING, "drm-lease", 0, &drm_lease_name },
 		{ WESTON_OPTION_BOOLEAN, "current-mode", 0, &wet->drm_use_current_mode },
 		{ WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
 		{ WESTON_OPTION_BOOLEAN, "continue-without-input", false, &without_input }
@@ -2658,6 +2665,7 @@ load_drm_backend(struct weston_compositor *c,
 	config.base.struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION;
 	config.base.struct_size = sizeof(struct weston_drm_backend_config);
 	config.configure_device = configure_input_device;
+	config.device_fd = get_drm_lease(&wet->drm_lease, drm_lease_name);
 
 	wet->heads_changed_listener.notify = drm_heads_changed;
 	weston_compositor_add_heads_changed_listener(c,
@@ -2675,6 +2683,7 @@ load_drm_backend(struct weston_compositor *c,
 	free(config.gbm_format);
 	free(config.seat_id);
 	free(config.specific_device);
+	free(drm_lease_name);
 
 	return ret;
 }
@@ -3577,6 +3586,7 @@ out:
 
 	/* free(NULL) is valid, and it won't be NULL if it's used */
 	free(wet.parsed_options);
+	release_drm_lease(wet.drm_lease);
 
 	if (protologger)
 		wl_protocol_logger_destroy(protologger);
diff --git a/compositor/meson.build b/compositor/meson.build
index 8a54ea9..5700d25 100644
--- a/compositor/meson.build
+++ b/compositor/meson.build
@@ -25,6 +25,11 @@ if get_option('xwayland')
 	srcs_weston += 'xwayland.c'
 	config_h.set_quoted('XSERVER_PATH', get_option('xwayland-path'))
 endif
+if get_option('drm-lease')
+	deps_weston += dependency('libdlmclient')
+	srcs_weston += 'drm-lease.c'
+	config_h.set('BUILD_DRM_LEASE_CLIENT', '1')
+endif
 
 libexec_weston = shared_library(
 	'exec_weston',
diff --git a/libweston/backend-drm/drm.c b/libweston/backend-drm/drm.c
index 0707db7..03e80ce 100644
--- a/libweston/backend-drm/drm.c
+++ b/libweston/backend-drm/drm.c
@@ -3267,6 +3267,7 @@ static void
 config_init_to_defaults(struct weston_drm_backend_config *config)
 {
 	config->use_pixman_shadow = true;
+	config->device_fd = -1;
 }
 
 WL_EXPORT int
diff --git a/meson_options.txt b/meson_options.txt
index 8a527d7..db9f19b 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -106,6 +106,13 @@ option(
 	description: 'Virtual remote output with Pipewire on DRM backend'
 )
 
+option(
+        'drm-lease',
+        type: 'boolean',
+        value: false,
+        description: 'Support for running weston with a leased DRM Master'
+)
+
 option(
 	'shell-desktop',
 	type: 'boolean',
-- 
2.17.1