1 From 180b3f71ef411c88d4fd40a90ef75ef1a694805e Mon Sep 17 00:00:00 2001
2 From: Marius Vlad <marius.vlad@collabora.com>
3 Date: Thu, 2 May 2024 19:45:41 +0300
4 Subject: [PATCH 2/2] Add DRM lease support
6 Add a command line option to use a DRM lease instead of a primary node for
7 output when using the DRM backend.
9 Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
10 Signed-off-by: Damian Hobson-Garcia <dhobsong@igel.co.jp>
12 compositor/drm-lease.c | 51 +++++++++++++++++++++++++++++++++++++
13 compositor/drm-lease.h | 40 +++++++++++++++++++++++++++++
14 compositor/main.c | 9 +++++++
15 compositor/meson.build | 6 +++++
16 libweston/backend-drm/drm.c | 1 +
17 meson_options.txt | 7 +++++
18 6 files changed, 114 insertions(+)
19 create mode 100644 compositor/drm-lease.c
20 create mode 100644 compositor/drm-lease.h
22 diff --git a/compositor/drm-lease.c b/compositor/drm-lease.c
24 index 0000000..11ee2e4
26 +++ b/compositor/drm-lease.c
29 + * Copyright © 2021 IGEL Co., Ltd.
31 + * Permission is hereby granted, free of charge, to any person obtaining
32 + * a copy of this software and associated documentation files (the
33 + * "Software"), to deal in the Software without restriction, including
34 + * without limitation the rights to use, copy, modify, merge, publish,
35 + * distribute, sublicense, and/or sell copies of the Software, and to
36 + * permit persons to whom the Software is furnished to do so, subject to
37 + * the following conditions:
39 + * The above copyright notice and this permission notice (including the
40 + * next paragraph) shall be included in all copies or substantial
41 + * portions of the Software.
43 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
44 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
45 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
46 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
47 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
48 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
49 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
53 +#include "drm-lease.h"
55 +#include <libweston/libweston.h>
57 +int get_drm_lease(struct dlm_lease **drm_lease, const char *drm_lease_name) {
58 + if (!drm_lease_name)
62 + struct dlm_lease *lease = dlm_get_lease(drm_lease_name);
64 + drm_fd = dlm_lease_fd(lease);
66 + dlm_release_lease(lease);
69 + weston_log("Could not get DRM lease %s\n", drm_lease_name);
75 +void release_drm_lease(struct dlm_lease *lease) {
77 + dlm_release_lease(lease);
79 diff --git a/compositor/drm-lease.h b/compositor/drm-lease.h
81 index 0000000..a102e4c
83 +++ b/compositor/drm-lease.h
86 + * Copyright © 2021 IGEL Co., Ltd.
88 + * Permission is hereby granted, free of charge, to any person obtaining
89 + * a copy of this software and associated documentation files (the
90 + * "Software"), to deal in the Software without restriction, including
91 + * without limitation the rights to use, copy, modify, merge, publish,
92 + * distribute, sublicense, and/or sell copies of the Software, and to
93 + * permit persons to whom the Software is furnished to do so, subject to
94 + * the following conditions:
96 + * The above copyright notice and this permission notice (including the
97 + * next paragraph) shall be included in all copies or substantial
98 + * portions of the Software.
100 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
101 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
102 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
103 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
104 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
105 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
106 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
112 +#ifdef BUILD_DRM_LEASE_CLIENT
113 +#include <dlmclient.h>
114 +int get_drm_lease(struct dlm_lease **drm_lease, const char *drm_lease_name);
115 +void release_drm_lease(struct dlm_lease *drm_lease);
118 +int get_drm_lease(struct dlm_lease **drm_lease, const char *drm_lease_name) {
121 +void release_drm_lease(struct dlm_lease *drm_lease) {
125 diff --git a/compositor/main.c b/compositor/main.c
126 index 0e3d375..bb8e27e 100644
127 --- a/compositor/main.c
128 +++ b/compositor/main.c
130 #include <libweston/weston-log.h>
131 #include <libweston/remoting-plugin.h>
132 #include <libweston/pipewire-plugin.h>
133 +#include "drm-lease.h"
135 #define WINDOW_TITLE "Weston Compositor"
136 /* flight recorder size (in bytes) */
137 @@ -152,6 +153,7 @@ struct wet_compositor {
138 bool drm_backend_loaded;
139 struct wl_listener screenshot_auth;
140 enum require_outputs require_outputs;
141 + struct dlm_lease *drm_lease;
144 static FILE *weston_logfile = NULL;
145 @@ -718,6 +720,9 @@ usage(int error_code)
146 " --drm-device=CARD\tThe DRM device to use for rendering and output, e.g. \"card0\".\n"
147 " --additional-devices=CARD\tSecondary DRM devices to use for output only, e.g. \"card1,card2\".\n"
148 " --use-pixman\t\tUse the pixman (CPU) renderer (deprecated alias for --renderer=pixman)\n"
149 +#ifdef BUILD_DRM_LEASE_CLIENT
150 + " --drm-lease=lease\tUse the specified DRM lease. e.g \"card0-HDMI-A-1\"\n"
152 " --current-mode\tPrefer current KMS mode over EDID preferred mode\n"
153 " --continue-without-input\tAllow the compositor to start without input devices\n\n");
155 @@ -3025,6 +3030,7 @@ load_drm_backend(struct weston_compositor *c, int *argc, char **argv,
156 struct wet_backend *wb;
157 bool without_input = false;
158 bool force_pixman = false;
159 + char *drm_lease_name = NULL;
161 wet->drm_use_current_mode = false;
163 @@ -3036,6 +3042,7 @@ load_drm_backend(struct weston_compositor *c, int *argc, char **argv,
164 const struct weston_option options[] = {
165 { WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
166 { WESTON_OPTION_STRING, "drm-device", 0, &config.specific_device },
167 + { WESTON_OPTION_STRING, "drm-lease", 0, &drm_lease_name },
168 { WESTON_OPTION_STRING, "additional-devices", 0, &config.additional_devices},
169 { WESTON_OPTION_BOOLEAN, "current-mode", 0, &wet->drm_use_current_mode },
170 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &force_pixman },
171 @@ -3067,6 +3074,7 @@ load_drm_backend(struct weston_compositor *c, int *argc, char **argv,
172 config.base.struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION;
173 config.base.struct_size = sizeof(struct weston_drm_backend_config);
174 config.configure_device = configure_input_device;
175 + config.device_fd = get_drm_lease(&wet->drm_lease, drm_lease_name);
177 wb = wet_compositor_load_backend(c, WESTON_BACKEND_DRM, &config.base,
178 drm_heads_changed, NULL);
179 @@ -3080,6 +3088,7 @@ load_drm_backend(struct weston_compositor *c, int *argc, char **argv,
180 free(config.gbm_format);
181 free(config.seat_id);
182 free(config.specific_device);
183 + free(drm_lease_name);
187 diff --git a/compositor/meson.build b/compositor/meson.build
188 index 7b49c48..d0f7c6a 100644
189 --- a/compositor/meson.build
190 +++ b/compositor/meson.build
191 @@ -25,6 +25,12 @@ if get_option('xwayland')
192 config_h.set_quoted('XSERVER_PATH', get_option('xwayland-path'))
195 +if get_option('drm-lease')
196 + deps_weston += dependency('libdlmclient')
197 + srcs_weston += 'drm-lease.c'
198 + config_h.set('BUILD_DRM_LEASE_CLIENT', '1')
201 libexec_weston = shared_library(
203 sources: srcs_weston,
204 diff --git a/libweston/backend-drm/drm.c b/libweston/backend-drm/drm.c
205 index 4e78ad0..3b747ed 100644
206 --- a/libweston/backend-drm/drm.c
207 +++ b/libweston/backend-drm/drm.c
208 @@ -4150,6 +4150,7 @@ config_init_to_defaults(struct weston_drm_backend_config *config)
210 config->renderer = WESTON_RENDERER_AUTO;
211 config->use_pixman_shadow = true;
212 + config->device_fd = -1;
216 diff --git a/meson_options.txt b/meson_options.txt
217 index ac355f1..b0d32a0 100644
218 --- a/meson_options.txt
219 +++ b/meson_options.txt
220 @@ -105,6 +105,13 @@ option(
221 description: 'Virtual remote output with Pipewire on DRM backend'
228 + description: 'Support for running weston with a leased DRM Master'