summaryrefslogtreecommitdiffstats
path: root/meta-agl-drm-lease/recipes-core/psplash/files/0016-Imprement-drm-lease-support.patch
blob: 6a4bf38781673b371f741f640f615f803ebe455a (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
From 0fcca6600c7d74ec13986d3e9e795f4a7c8afe59 Mon Sep 17 00:00:00 2001
From: Hiroyuki Ishii <ishii.hiroyuki002@jp.panasonic.com>
Date: Tue, 27 Dec 2022 16:43:46 +0900
Subject: [PATCH 16/17] Imprement drm-lease support

Basic support to utilize drm-lease device via drm-lease-manager.

Known issue:
- --angle option does not work correctly with drm-lease enabled

Signed-off-by: Hiroyuki Ishii <ishii.hiroyuki002@jp.panasonic.com>
---
 Makefile.am         |  5 +++++
 configure.ac        |  9 +++++++++
 psplash-drm-lease.h | 10 ++++++++++
 psplash-drm.c       | 44 +++++++++++++++++++++++++++++++++++++++-----
 psplash.c           | 12 ++++++++++++
 5 files changed, 75 insertions(+), 5 deletions(-)
 create mode 100644 psplash-drm-lease.h

diff --git a/Makefile.am b/Makefile.am
index c3d4f03..3657889 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -19,6 +19,11 @@ psplash_CPPFLAGS += $(LIBDRM_CFLAGS) -DENABLE_DRM
 psplash_LDFLAGS += $(LIBDRM_LIBS)
 endif
 
+if ENABLE_DRM_LEASE
+psplash_CPPFLAGS += $(LIBDRM_LEASE_CFLAGS) -DENABLE_DRM_LEASE
+psplash_LDFLAGS += $(LIBDRM_LEASE_LIBS)
+endif
+
 if HAVE_SYSTEMD
 psplash_CPPFLAGS += $(SYSTEMD_CFLAGS) -DHAVE_SYSTEMD
 psplash_LDFLAGS += $(SYSTEMD_LIBS)
diff --git a/configure.ac b/configure.ac
index 2e5c4f5..1a752e3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -21,6 +21,15 @@ AS_IF([test "x$enable_drm" = "xyes"], [
 
 AM_CONDITIONAL([ENABLE_DRM], [test "x$enable_drm" = "xyes"])
 
+AC_ARG_ENABLE(drm-lease,
+    AS_HELP_STRING([--enable-drm-lease], [enable drm-lease (default is 'no')]))
+
+AS_IF([test "x$enable_drm_lease" = "xyes"], [
+    PKG_CHECK_MODULES(LIBDRM_LEASE, libdlmclient)
+])
+
+AM_CONDITIONAL([ENABLE_DRM_LEASE], [test "x$enable_drm_lease" = "xyes"])
+
 AC_ARG_WITH([systemd], AS_HELP_STRING([--with-systemd], [Build with systemd
 	     support]))
 
diff --git a/psplash-drm-lease.h b/psplash-drm-lease.h
new file mode 100644
index 0000000..46289c3
--- /dev/null
+++ b/psplash-drm-lease.h
@@ -0,0 +1,10 @@
+#ifndef _HAVE_PSPLASH_DRM_LEASE_H
+#define _HAVE_PSPLASH_DRM_LEASE_H
+#ifdef ENABLE_DRM_LEASE
+
+#include <dlmclient.h>
+
+void drm_set_lease_name(char *);
+
+#endif // ENABLE_DRM_LEASE
+#endif // _HAVE_PSPLASH_DRM_LEASE_H
diff --git a/psplash-drm.c b/psplash-drm.c
index fcb7507..a5aff90 100644
--- a/psplash-drm.c
+++ b/psplash-drm.c
@@ -39,6 +39,9 @@
 #include <xf86drm.h>
 #include <xf86drmMode.h>
 #include "psplash-drm.h"
+#ifdef ENABLE_DRM_LEASE
+#include "psplash-drm-lease.h"
+#endif
 
 #define MIN(a,b) ((a) < (b) ? (a) : (b))
 
@@ -53,6 +56,10 @@ static int modeset_setup_dev(int fd, drmModeRes *res, drmModeConnector *conn,
 static int modeset_open(int *out, const char *node);
 static int modeset_prepare(int fd);
 
+#ifdef ENABLE_DRM_LEASE
+char *drm_lease_name;
+#endif
+
 /*
  * When the linux kernel detects a graphics-card on your machine, it loads the
  * correct device driver (located in kernel-tree at ./drivers/gpu/drm/<xy>) and
@@ -662,6 +669,7 @@ PSplashDRM* psplash_drm_new(int angle, int dev_id)
 		perror("malloc");
 		goto error;
 	}
+	drm->fd = 0;
 	drm->canvas.priv = drm;
 	drm->canvas.flip = psplash_drm_flip;
 
@@ -670,12 +678,30 @@ PSplashDRM* psplash_drm_new(int angle, int dev_id)
 		card[13] = dev_id + 48;
 	}
 
-	fprintf(stderr, "using card '%s'\n", card);
+#ifdef ENABLE_DRM_LEASE
+	if (drm_lease_name) {
+		fprintf(stderr, "using drm lease '%s'\n", drm_lease_name);
+		struct dlm_lease *lease = dlm_get_lease(drm_lease_name);
+		if (lease) {
+			drm->fd = dlm_lease_fd(lease);
+			if (!drm->fd)
+				dlm_release_lease(lease);
+		}
+		if (!drm->fd) {
+			fprintf(stderr, "Could not get DRM lease %s\n", drm_lease_name);
+			goto error;
+		}
+	}
+#endif
 
-	/* open the DRM device */
-	ret = modeset_open(&drm->fd, card);
-	if (ret)
-		goto error;
+	if (!drm->fd) {
+		fprintf(stderr, "using card '%s'\n", card);
+
+		/* open the DRM device */
+		ret = modeset_open(&drm->fd, card);
+		if (ret)
+			goto error;
+	}
 
 	/* prepare all connectors and CRTCs */
 	ret = modeset_prepare(drm->fd);
@@ -758,6 +784,14 @@ void psplash_drm_destroy(PSplashDRM *drm)
 	free(drm);
 }
 
+#ifdef ENABLE_DRM_LEASE
+void drm_set_lease_name (char *name) {
+	if (!name)
+		return;
+	drm_lease_name = strdup(name);
+}
+#endif
+
 /*
  * I hope this was a short but easy overview of the DRM modesetting API. The DRM
  * API offers much more capabilities including:
diff --git a/psplash.c b/psplash.c
index ebf8d7a..4aa650d 100644
--- a/psplash.c
+++ b/psplash.c
@@ -15,6 +15,9 @@
 #ifdef ENABLE_DRM
 #include "psplash-drm.h"
 #endif
+#ifdef ENABLE_DRM_LEASE
+#include "psplash-drm-lease.h"
+#endif
 #include "psplash-config.h"
 #include "psplash-colors.h"
 #include "psplash-poky-img.h"
@@ -267,6 +270,15 @@ main (int argc, char** argv)
         continue;
     }
 #endif
+#ifdef ENABLE_DRM_LEASE
+    if (!strcmp(argv[i],"--drm-lease"))
+      {
+        if (++i >= argc) goto fail;
+        drm_set_lease_name(argv[i]);
+        use_drm = 1;
+        continue;
+      }
+#endif
 
     fail:
       fprintf(stderr,
-- 
2.25.1