drm-lease: Add weston DRM lease integration
[AGL/meta-agl-devel.git] / meta-agl-drm-lease / recipes-graphics / weston / weston / 0002-Add-DRM-lease-support.patch
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
5
6 Add a command line option to use a DRM lease instead of a primary node for
7 output when using the DRM backend.
8 ---
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
17
18 diff --git a/compositor/drm-lease.c b/compositor/drm-lease.c
19 new file mode 100644
20 index 00000000..fdb1f5e2
21 --- /dev/null
22 +++ b/compositor/drm-lease.c
23 @@ -0,0 +1,53 @@
24 +/*
25 + * Copyright © 2021 IGEL Co., Ltd.
26 + *
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:
34 + *
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.
38 + *
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
46 + * SOFTWARE.
47 + */
48 +
49 +#include "drm-lease.h"
50 +
51 +#include <libweston/libweston.h>
52 +
53 +int get_drm_lease(struct dlm_lease **drm_lease, const char *drm_lease_name) {
54 +       if (!drm_lease_name)
55 +               return -1;
56 +
57 +       int drm_fd;
58 +       struct dlm_lease *lease = dlm_get_lease(drm_lease_name);
59 +       if (lease) {
60 +               drm_fd = dlm_lease_fd(lease);
61 +               if (drm_fd < 0)
62 +                       dlm_release_lease(lease);
63 +       }
64 +       if (drm_fd < 0)
65 +           weston_log("Could not get DRM lease %s\n", drm_lease_name);
66 +
67 +        *drm_lease = lease;
68 +       return drm_fd;
69 +}
70 +
71 +void release_drm_lease(struct dlm_lease *lease) {
72 +       if (lease)
73 +               dlm_release_lease(lease);
74 +}
75 +
76 +
77 diff --git a/compositor/drm-lease.h b/compositor/drm-lease.h
78 new file mode 100644
79 index 00000000..a102e4cb
80 --- /dev/null
81 +++ b/compositor/drm-lease.h
82 @@ -0,0 +1,40 @@
83 +/*
84 + * Copyright © 2021 IGEL Co., Ltd.
85 + *
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:
93 + *
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.
97 + *
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
105 + * SOFTWARE.
106 + */
107 +
108 +#include "config.h"
109 +
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);
114 +#else
115 +struct dlm_lease;
116 +int get_drm_lease(struct dlm_lease **drm_lease, const char *drm_lease_name) {
117 +       return -1;
118 +}
119 +void release_drm_lease(struct dlm_lease *drm_lease) {
120 +}
121 +
122 +#endif
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
127 @@ -65,6 +65,7 @@
128  #include <libweston/weston-log.h>
129  #include "../remoting/remoting-plugin.h"
130  #include "../pipewire/pipewire-plugin.h"
131 +#include "drm-lease.h"
132  
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);
137         bool init_failed;
138         struct wl_list layoutput_list;  /**< wet_layoutput::compositor_link */
139 +       struct dlm_lease *drm_lease;
140  };
141  
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"
149 +#endif
150                 "  --use-pixman\t\tUse the pixman (CPU) renderer\n"
151                 "  --current-mode\tPrefer current KMS mode over EDID preferred mode\n\n");
152  #endif
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);
156         int ret = 0;
157 +       char *drm_lease_name = NULL;
158  
159         wet->drm_use_current_mode = false;
160  
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 },
168         };
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);
175  
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,
179  
180         free(config.gbm_format);
181         free(config.seat_id);
182 +       free(drm_lease_name);
183  
184         return ret;
185  }
186 @@ -3373,6 +3381,7 @@ out:
187  
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);
191  
192         if (protologger)
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'))
201  endif
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')
206 +endif
207  
208  libexec_weston = shared_library(
209         'exec_weston',
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'
216  )
217  
218 +option(
219 +        'drm-lease',
220 +        type: 'boolean',
221 +        value: false,
222 +        description: 'Support for running weston with a leased DRM Master'
223 +)
224 +
225  option(
226         'shell-desktop',
227         type: 'boolean',
228 -- 
229 2.25.1
230