1 From 3a766fb852b53316f4b4c0b37ec801a5b188093b Mon Sep 17 00:00:00 2001
2 From: Damian Hobson-Garcia <dhobsong@igel.co.jp>
3 Date: Wed, 16 Dec 2020 16:21:57 +0900
4 Subject: [PATCH] Add DRM lease support
8 drm-common.c | 21 +++++++++++++++++++--
9 drm-common.h | 9 ++++++---
11 kmscube.c | 12 +++++++++---
13 meson_options.txt | 5 +++++
15 8 files changed, 49 insertions(+), 13 deletions(-)
17 diff --git a/drm-atomic.c b/drm-atomic.c
18 index d748772..8cb3ca5 100644
21 @@ -337,12 +337,12 @@ static int get_plane_id(void)
25 -const struct drm * init_drm_atomic(const char *device, const char *mode_str, unsigned int vrefresh)
26 +const struct drm * init_drm_atomic(const char *device, const char *mode_str, unsigned int vrefresh, int lease)
31 - ret = init_drm(&drm, device, mode_str, vrefresh);
32 + ret = init_drm(&drm, device, mode_str, vrefresh, lease);
36 diff --git a/drm-common.c b/drm-common.c
37 index b9d61c1..6e7d1ce 100644
42 #include "drm-common.h"
44 +#ifdef HAVE_DRM_LEASE
45 +#include "dlmclient.h"
49 gbm_bo_get_modifier(struct gbm_bo *bo);
51 @@ -169,6 +173,19 @@ static int get_resources(int fd, drmModeRes **resources)
55 +static int open_device(struct drm *drm, const char *device, int lease)
58 + return open(device, O_RDWR);
60 +#ifdef HAVE_DRM_LEASE
61 + drm->lease = dlm_get_lease(device);
63 + return dlm_lease_fd(drm->lease);
68 #define MAX_DRM_DEVICES 64
70 static int find_drm_device(drmModeRes **resources)
71 @@ -208,7 +225,7 @@ static int find_drm_device(drmModeRes **resources)
75 -int init_drm(struct drm *drm, const char *device, const char *mode_str, unsigned int vrefresh)
76 +int init_drm(struct drm *drm, const char *device, const char *mode_str, unsigned int vrefresh, int lease)
78 drmModeRes *resources;
79 drmModeConnector *connector = NULL;
80 @@ -216,7 +233,7 @@ int init_drm(struct drm *drm, const char *device, const char *mode_str, unsigned
84 - drm->fd = open(device, O_RDWR);
85 + drm->fd = open_device(drm, device, lease);
86 ret = get_resources(drm->fd, &resources);
87 if (ret < 0 && errno == EOPNOTSUPP)
88 printf("%s does not look like a modeset device\n", device);
89 diff --git a/drm-common.h b/drm-common.h
90 index c4eb886..5119e79 100644
93 @@ -51,6 +51,9 @@ struct connector {
97 + /* only used for DRM lease */
98 + struct dlm_lease *lease;
100 /* only used for atomic: */
103 @@ -73,8 +76,8 @@ struct drm_fb {
105 struct drm_fb * drm_fb_get_from_bo(struct gbm_bo *bo);
107 -int init_drm(struct drm *drm, const char *device, const char *mode_str, unsigned int vrefresh);
108 -const struct drm * init_drm_legacy(const char *device, const char *mode_str, unsigned int vrefresh);
109 -const struct drm * init_drm_atomic(const char *device, const char *mode_str, unsigned int vrefresh);
110 +int init_drm(struct drm *drm, const char *device, const char *mode_str, unsigned int vrefresh, int lease);
111 +const struct drm * init_drm_legacy(const char *device, const char *mode_str, unsigned int vrefresh, int lease);
112 +const struct drm * init_drm_atomic(const char *device, const char *mode_str, unsigned int vrefresh, int lease);
114 #endif /* _DRM_COMMON_H */
115 diff --git a/drm-legacy.c b/drm-legacy.c
116 index 56a0fed..03db13d 100644
119 @@ -122,11 +122,11 @@ static int legacy_run(const struct gbm *gbm, const struct egl *egl)
123 -const struct drm * init_drm_legacy(const char *device, const char *mode_str, unsigned int vrefresh)
124 +const struct drm * init_drm_legacy(const char *device, const char *mode_str, unsigned int vrefresh, int lease)
128 - ret = init_drm(&drm, device, mode_str, vrefresh);
129 + ret = init_drm(&drm, device, mode_str, vrefresh, lease);
133 diff --git a/kmscube.c b/kmscube.c
134 index f14c1d9..abb5bdd 100644
137 @@ -41,12 +41,13 @@ static const struct egl *egl;
138 static const struct gbm *gbm;
139 static const struct drm *drm;
141 -static const char *shortopts = "AD:M:m:V:v:";
142 +static const char *shortopts = "AD:LM:m:V:v:";
144 static const struct option longopts[] = {
145 {"atomic", no_argument, 0, 'A'},
146 {"device", required_argument, 0, 'D'},
147 {"format", required_argument, 0, 'f'},
148 + {"drm-lease", no_argument, 0, 'L'},
149 {"mode", required_argument, 0, 'M'},
150 {"modifier", required_argument, 0, 'm'},
151 {"samples", required_argument, 0, 's'},
152 @@ -62,6 +63,9 @@ static void usage(const char *name)
154 " -A, --atomic use atomic modesetting and fencing\n"
155 " -D, --device=DEVICE use the given device\n"
156 +#ifdef HAVE_DRM_LEASE
157 + " -L, --drm-lease the given device is the name of a DRM lease:\n"
159 " -M, --mode=MODE specify mode, one of:\n"
160 " smooth - smooth shaded cube (default)\n"
161 " rgba - rgba textured cube\n"
162 @@ -87,6 +89,7 @@ int main(int argc, char *argv[])
163 uint64_t modifier = DRM_FORMAT_MOD_LINEAR;
169 unsigned int vrefresh = 0;
170 @@ -119,6 +122,11 @@ int main(int argc, char *argv[])
171 fourcc[2], fourcc[3]);
174 +#ifdef HAVE_DRM_LEASE
180 if (strcmp(optarg, "smooth") == 0) {
182 @@ -164,9 +170,9 @@ int main(int argc, char *argv[])
186 - drm = init_drm_atomic(device, mode_str, vrefresh);
187 + drm = init_drm_atomic(device, mode_str, vrefresh, lease);
189 - drm = init_drm_legacy(device, mode_str, vrefresh);
190 + drm = init_drm_legacy(device, mode_str, vrefresh, lease);
192 printf("failed to initialize %s DRM\n", atomic ? "atomic" : "legacy");
194 diff --git a/meson.build b/meson.build
195 index df9c315..1b47a52 100644
198 @@ -91,6 +91,11 @@ else
199 message('Building without gstreamer support')
202 +if get_option('drm_lease').enabled()
203 + dep_common += dependency('libdlmclient')
204 + add_project_arguments('-DHAVE_DRM_LEASE', language : 'c')
207 executable('kmscube', sources, dependencies : dep_common, install : true)
210 diff --git a/meson_options.txt b/meson_options.txt
211 index 1ed8abc..d932a1c 100644
212 --- a/meson_options.txt
213 +++ b/meson_options.txt
214 @@ -3,3 +3,8 @@ option(
216 description : 'Enable support for gstreamer and cube-video'
221 + description : 'Enable support for running as a DRM lease client'
223 diff --git a/texturator.c b/texturator.c
224 index 3d09e9e..9b87f0d 100644
227 @@ -948,7 +948,7 @@ int main(int argc, char *argv[])
230 /* no real need for atomic here: */
231 - drm = init_drm_legacy(device, mode_str, vrefresh);
232 + drm = init_drm_legacy(device, mode_str, vrefresh, 0);
234 printf("failed to initialize DRM\n");