1 From 24ece5f73b7c9377e14d74c2b14c9ae3504edcc3 Mon Sep 17 00:00:00 2001
2 From: Damian Hobson-Garcia <dhobsong@igel.co.jp>
3 Date: Fri, 5 Mar 2021 19:24:35 +0900
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 compositor/drm-lease.c | 53 ++++++++++++++++++++++++++++++++++++++++++
10 compositor/drm-lease.h | 40 +++++++++++++++++++++++++++++++
11 compositor/main.c | 11 ++++++++-
12 compositor/meson.build | 5 ++++
13 meson_options.txt | 7 ++++++
14 5 files changed, 115 insertions(+), 1 deletion(-)
15 create mode 100644 compositor/drm-lease.c
16 create mode 100644 compositor/drm-lease.h
18 diff --git a/compositor/drm-lease.c b/compositor/drm-lease.c
20 index 00000000..fdb1f5e2
22 +++ b/compositor/drm-lease.c
25 + * Copyright © 2021 IGEL Co., Ltd.
27 + * Permission is hereby granted, free of charge, to any person obtaining
28 + * a copy of this software and associated documentation files (the
29 + * "Software"), to deal in the Software without restriction, including
30 + * without limitation the rights to use, copy, modify, merge, publish,
31 + * distribute, sublicense, and/or sell copies of the Software, and to
32 + * permit persons to whom the Software is furnished to do so, subject to
33 + * the following conditions:
35 + * The above copyright notice and this permission notice (including the
36 + * next paragraph) shall be included in all copies or substantial
37 + * portions of the Software.
39 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
40 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
41 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
42 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
43 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
44 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
45 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
49 +#include "drm-lease.h"
51 +#include <libweston/libweston.h>
53 +int get_drm_lease(struct dlm_lease **drm_lease, const char *drm_lease_name) {
54 + if (!drm_lease_name)
58 + struct dlm_lease *lease = dlm_get_lease(drm_lease_name);
60 + drm_fd = dlm_lease_fd(lease);
62 + dlm_release_lease(lease);
65 + weston_log("Could not get DRM lease %s\n", drm_lease_name);
71 +void release_drm_lease(struct dlm_lease *lease) {
73 + dlm_release_lease(lease);
77 diff --git a/compositor/drm-lease.h b/compositor/drm-lease.h
79 index 00000000..a102e4cb
81 +++ b/compositor/drm-lease.h
84 + * Copyright © 2021 IGEL Co., Ltd.
86 + * Permission is hereby granted, free of charge, to any person obtaining
87 + * a copy of this software and associated documentation files (the
88 + * "Software"), to deal in the Software without restriction, including
89 + * without limitation the rights to use, copy, modify, merge, publish,
90 + * distribute, sublicense, and/or sell copies of the Software, and to
91 + * permit persons to whom the Software is furnished to do so, subject to
92 + * the following conditions:
94 + * The above copyright notice and this permission notice (including the
95 + * next paragraph) shall be included in all copies or substantial
96 + * portions of the Software.
98 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
99 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
100 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
101 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
102 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
103 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
104 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
110 +#ifdef BUILD_DRM_LEASE_CLIENT
111 +#include <dlmclient.h>
112 +int get_drm_lease(struct dlm_lease **drm_lease, const char *drm_lease_name);
113 +void release_drm_lease(struct dlm_lease *drm_lease);
116 +int get_drm_lease(struct dlm_lease **drm_lease, const char *drm_lease_name) {
119 +void release_drm_lease(struct dlm_lease *drm_lease) {
123 diff --git a/compositor/main.c b/compositor/main.c
124 index 7d5373f7..dae754aa 100644
125 --- a/compositor/main.c
126 +++ b/compositor/main.c
128 #include <libweston/weston-log.h>
129 #include "../remoting/remoting-plugin.h"
130 #include "../pipewire/pipewire-plugin.h"
131 +#include "drm-lease.h"
133 #define WINDOW_TITLE "Weston Compositor"
134 /* flight recorder size (in bytes) */
135 @@ -122,6 +123,7 @@ struct wet_compositor {
136 int (*simple_output_configure)(struct weston_output *output);
138 struct wl_list layoutput_list; /**< wet_layoutput::compositor_link */
139 + struct dlm_lease *drm_lease;
142 static FILE *weston_logfile = NULL;
143 @@ -669,6 +671,9 @@ usage(int error_code)
144 " --seat=SEAT\t\tThe seat that weston should run on, instead of the seat defined in XDG_SEAT\n"
145 " --tty=TTY\t\tThe tty to use\n"
146 " --drm-device=CARD\tThe DRM device to use, e.g. \"card0\".\n"
147 +#ifdef BUILD_DRM_LEASE_CLIENT
148 + " --drm-lease=lease\tUse the specified DRM lease. e.g \"card0-HDMI-A-1\"\n"
150 " --use-pixman\t\tUse the pixman (CPU) renderer\n"
151 " --current-mode\tPrefer current KMS mode over EDID preferred mode\n\n");
153 @@ -2481,6 +2486,7 @@ load_drm_backend(struct weston_compositor *c,
154 struct weston_config_section *section;
155 struct wet_compositor *wet = to_wet_compositor(c);
157 + char *drm_lease_name = NULL;
159 wet->drm_use_current_mode = false;
161 @@ -2492,6 +2498,7 @@ load_drm_backend(struct weston_compositor *c,
162 { WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
163 { WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
164 { WESTON_OPTION_STRING, "drm-device", 0, &config.specific_device },
165 + { WESTON_OPTION_STRING, "drm-lease", 0, &drm_lease_name },
166 { WESTON_OPTION_BOOLEAN, "current-mode", 0, &wet->drm_use_current_mode },
167 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
169 @@ -2510,7 +2517,7 @@ load_drm_backend(struct weston_compositor *c,
170 config.base.struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION;
171 config.base.struct_size = sizeof(struct weston_drm_backend_config);
172 config.configure_device = configure_input_device;
173 - config.device_fd = -1;
174 + config.device_fd = get_drm_lease(&wet->drm_lease, drm_lease_name);
176 wet->heads_changed_listener.notify = drm_heads_changed;
177 weston_compositor_add_heads_changed_listener(c,
178 @@ -2527,6 +2534,7 @@ load_drm_backend(struct weston_compositor *c,
180 free(config.gbm_format);
181 free(config.seat_id);
182 + free(drm_lease_name);
186 @@ -3373,6 +3381,7 @@ out:
188 /* free(NULL) is valid, and it won't be NULL if it's used */
189 free(wet.parsed_options);
190 + release_drm_lease(wet.drm_lease);
193 wl_protocol_logger_destroy(protologger);
194 diff --git a/compositor/meson.build b/compositor/meson.build
195 index e1334d6a..e5b82a88 100644
196 --- a/compositor/meson.build
197 +++ b/compositor/meson.build
198 @@ -25,6 +25,11 @@ if get_option('xwayland')
199 srcs_weston += 'xwayland.c'
200 config_h.set_quoted('XSERVER_PATH', get_option('xwayland-path'))
202 +if get_option('drm-lease')
203 + deps_weston += dependency('libdlmclient')
204 + srcs_weston += 'drm-lease.c'
205 + config_h.set('BUILD_DRM_LEASE_CLIENT', '1')
208 libexec_weston = shared_library(
210 diff --git a/meson_options.txt b/meson_options.txt
211 index 73ef2c34..9cb27536 100644
212 --- a/meson_options.txt
213 +++ b/meson_options.txt
214 @@ -113,6 +113,13 @@ option(
215 description: 'Virtual remote output with Pipewire on DRM backend'
222 + description: 'Support for running weston with a leased DRM Master'