summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile_Ecore_Drm2.am1
-rw-r--r--src/lib/ecore_drm2/Ecore_Drm2.h80
-rw-r--r--src/lib/ecore_drm2/ecore_drm2_device.c184
-rw-r--r--src/lib/ecore_drm2/ecore_drm2_private.h25
4 files changed, 290 insertions, 0 deletions
diff --git a/src/Makefile_Ecore_Drm2.am b/src/Makefile_Ecore_Drm2.am
index 2818b0e760..59e9865aa3 100644
--- a/src/Makefile_Ecore_Drm2.am
+++ b/src/Makefile_Ecore_Drm2.am
@@ -9,6 +9,7 @@ dist_installed_ecoredrm2mainheaders_DATA = \
9 lib/ecore_drm2/Ecore_Drm2.h 9 lib/ecore_drm2/Ecore_Drm2.h
10 10
11lib_ecore_drm2_libecore_drm2_la_SOURCES = \ 11lib_ecore_drm2_libecore_drm2_la_SOURCES = \
12lib/ecore_drm2/ecore_drm2_device.c \
12lib/ecore_drm2/ecore_drm2.c \ 13lib/ecore_drm2/ecore_drm2.c \
13lib/ecore_drm2/ecore_drm2_private.h 14lib/ecore_drm2/ecore_drm2_private.h
14 15
diff --git a/src/lib/ecore_drm2/Ecore_Drm2.h b/src/lib/ecore_drm2/Ecore_Drm2.h
index b2bbd15e02..bf08be22c5 100644
--- a/src/lib/ecore_drm2/Ecore_Drm2.h
+++ b/src/lib/ecore_drm2/Ecore_Drm2.h
@@ -28,6 +28,9 @@
28 28
29# ifdef EFL_BETA_API_SUPPORT 29# ifdef EFL_BETA_API_SUPPORT
30 30
31/* opaque structure to represent a drm device */
32typedef struct _Ecore_Drm2_Device Ecore_Drm2_Device;
33
31/** 34/**
32 * @file 35 * @file
33 * @brief Ecore functions for dealing with drm, virtual terminals 36 * @brief Ecore functions for dealing with drm, virtual terminals
@@ -69,6 +72,83 @@ EAPI int ecore_drm2_init(void);
69 */ 72 */
70EAPI int ecore_drm2_shutdown(void); 73EAPI int ecore_drm2_shutdown(void);
71 74
75/**
76 * @defgroup Ecore_Drm2_Device_Group Drm device functions
77 *
78 * Functions that deal with finding, opening, closing, or obtaining various
79 * information about a drm device
80 */
81
82/**
83 * Try to find a drm device on a given seat
84 *
85 * @param seat
86 * @param tty
87 * @param sync
88 *
89 * @return A newly allocated Ecore_Drm2_Device on success, NULL otherwise
90 *
91 * @ingroup Ecore_Drm2_Device_Group
92 * @since 1.18
93 */
94EAPI Ecore_Drm2_Device *ecore_drm2_device_find(const char *seat, unsigned int tty, Eina_Bool sync);
95
96/**
97 * Try to open a given Ecore_Drm2_Device
98 *
99 * @param device
100 *
101 * @return A valid file descriptor if open succeeds, -1 otherwise.
102 *
103 * @ingroup Ecore_Drm2_Device_Group
104 * @since 1.18
105 */
106EAPI int ecore_drm2_device_open(Ecore_Drm2_Device *device);
107
108/**
109 * Close an open Ecore_Drm2_Device
110 *
111 * @param device
112 *
113 * @ingroup Ecore_Drm2_Device_Group
114 * @since 1.18
115 */
116EAPI void ecore_drm2_device_close(Ecore_Drm2_Device *device);
117
118/**
119 * Free a given Ecore_Drm2_Device
120 *
121 * @param device
122 *
123 * @ingroup Ecore_Drm2_Device_Group
124 * @since 1.18
125 */
126EAPI void ecore_drm2_device_free(Ecore_Drm2_Device *device);
127
128/**
129 * Get the type of clock used by a given Ecore_Drm2_Device
130 *
131 * @param device
132 *
133 * @return The clockid_t used by this drm device
134 *
135 * @ingroup Ecore_Drm2_Device_Group
136 * @since 1.18
137 */
138EAPI int ecore_drm2_device_clock_id_get(Ecore_Drm2_Device *device);
139
140/**
141 * Get the size of the cursor supported by a given Ecore_Drm2_Device
142 *
143 * @param device
144 * @param width
145 * @param height
146 *
147 * @ingroup Ecore_Drm2_Device_Group
148 * @since 1.18
149 */
150EAPI void ecore_drm2_device_cursor_size_get(Ecore_Drm2_Device *device, int *width, int *height);
151
72# endif 152# endif
73 153
74#endif 154#endif
diff --git a/src/lib/ecore_drm2/ecore_drm2_device.c b/src/lib/ecore_drm2/ecore_drm2_device.c
new file mode 100644
index 0000000000..b47028bdf4
--- /dev/null
+++ b/src/lib/ecore_drm2/ecore_drm2_device.c
@@ -0,0 +1,184 @@
1#include "ecore_drm2_private.h"
2
3#ifndef DRM_CAP_CURSOR_WIDTH
4# define DRM_CAP_CURSOR_WIDTH 0x8
5#endif
6
7#ifndef DRM_CAP_CURSOR_HEIGHT
8# define DRM_CAP_CURSOR_HEIGHT 0x9
9#endif
10
11static const char *
12_drm2_device_find(const char *seat)
13{
14 Eina_List *devs, *l;
15 const char *dev, *ret = NULL;
16 Eina_Bool found = EINA_FALSE;
17 Eina_Bool platform = EINA_FALSE;
18
19 devs = eeze_udev_find_by_subsystem_sysname("drm", "card[0-9]*");
20 if (!devs) return NULL;
21
22 EINA_LIST_FOREACH(devs, l, dev)
23 {
24 const char *dpath, *dseat, *dparent;
25
26 dpath = eeze_udev_syspath_get_devpath(dev);
27 if (!dpath) continue;
28
29 dseat = eeze_udev_syspath_get_property(dev, "ID_SEAT");
30 if (!dseat) dseat = eina_stringshare_add("seat0");
31
32 if ((seat) && (strcmp(seat, dseat)))
33 goto cont;
34 else if (strcmp(dseat, "seat0"))
35 goto cont;
36
37 dparent = eeze_udev_syspath_get_parent_filtered(dev, "pci", NULL);
38 if (!dparent)
39 {
40 dparent =
41 eeze_udev_syspath_get_parent_filtered(dev, "platform", NULL);
42 platform = EINA_TRUE;
43 }
44
45 if (dparent)
46 {
47 if (!platform)
48 {
49 const char *id;
50
51 id = eeze_udev_syspath_get_sysattr(dparent, "boot_vga");
52 if (id)
53 {
54 if (!strcmp(id, "1")) found = EINA_TRUE;
55 eina_stringshare_del(id);
56 }
57 }
58 else
59 found = EINA_TRUE;
60
61 eina_stringshare_del(dparent);
62 }
63
64cont:
65 eina_stringshare_del(dpath);
66 eina_stringshare_del(dseat);
67 if (found) break;
68 }
69
70 if (!found) goto out;
71
72 ret = eeze_udev_syspath_get_devpath(dev);
73
74out:
75 EINA_LIST_FREE(devs, dev)
76 eina_stringshare_del(dev);
77
78 return ret;
79}
80
81EAPI Ecore_Drm2_Device *
82ecore_drm2_device_find(const char *seat, unsigned int tty, Eina_Bool sync)
83{
84 Ecore_Drm2_Device *dev;
85
86 dev = calloc(1, sizeof(Ecore_Drm2_Device));
87 if (!dev) return NULL;
88
89 dev->em = elput_manager_connect(seat, tty, sync);
90 if (!dev->em)
91 {
92 ERR("Could not connect to input manager");
93 goto man_err;
94 }
95
96 dev->path = _drm2_device_find(seat);
97 if (!dev->path)
98 {
99 ERR("Could not find drm device on seat %s", seat);
100 goto path_err;
101 }
102
103 return dev;
104
105path_err:
106 elput_manager_disconnect(dev->em);
107man_err:
108 free(dev);
109 return NULL;
110}
111
112EAPI int
113ecore_drm2_device_open(Ecore_Drm2_Device *device)
114{
115 EINA_SAFETY_ON_NULL_RETURN_VAL(device, -1);
116
117 device->fd = elput_manager_open(device->em, device->path, -1);
118
119 DBG("Device Path: %s", device->path);
120 DBG("Device Fd: %d", device->fd);
121
122 /* NB: Not going to enable planes if we don't support atomic */
123 /* if (drmSetClientCap(device->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1) < 0) */
124 /* ERR("Could not set Universal Plane support: %m"); */
125
126 return device->fd;
127}
128
129EAPI void
130ecore_drm2_device_close(Ecore_Drm2_Device *device)
131{
132 EINA_SAFETY_ON_NULL_RETURN(device);
133 EINA_SAFETY_ON_TRUE_RETURN(device->fd < 0);
134
135 elput_manager_close(device->em, device->fd);
136}
137
138EAPI void
139ecore_drm2_device_free(Ecore_Drm2_Device *device)
140{
141 EINA_SAFETY_ON_NULL_RETURN(device);
142
143 eina_stringshare_del(device->path);
144 free(device);
145}
146
147EAPI int
148ecore_drm2_device_clock_id_get(Ecore_Drm2_Device *device)
149{
150 uint64_t caps;
151 int ret;
152
153 EINA_SAFETY_ON_NULL_RETURN_VAL(device, -1);
154 EINA_SAFETY_ON_TRUE_RETURN_VAL((device->fd < 0), -1);
155
156 ret = drmGetCap(device->fd, DRM_CAP_TIMESTAMP_MONOTONIC, &caps);
157 if ((ret == 0) && (caps == 1))
158 return CLOCK_MONOTONIC;
159 else
160 return CLOCK_REALTIME;
161}
162
163EAPI void
164ecore_drm2_device_cursor_size_get(Ecore_Drm2_Device *device, int *width, int *height)
165{
166 uint64_t caps;
167 int ret;
168
169 EINA_SAFETY_ON_NULL_RETURN(device);
170 EINA_SAFETY_ON_TRUE_RETURN((device->fd < 0));
171
172 if (width)
173 {
174 *width = 64;
175 ret = drmGetCap(device->fd, DRM_CAP_CURSOR_WIDTH, &caps);
176 if (ret == 0) *width = caps;
177 }
178 if (height)
179 {
180 *height = 64;
181 ret = drmGetCap(device->fd, DRM_CAP_CURSOR_HEIGHT, &caps);
182 if (ret == 0) *height = caps;
183 }
184}
diff --git a/src/lib/ecore_drm2/ecore_drm2_private.h b/src/lib/ecore_drm2/ecore_drm2_private.h
index 6177e8e436..6b4b90f0e5 100644
--- a/src/lib/ecore_drm2/ecore_drm2_private.h
+++ b/src/lib/ecore_drm2/ecore_drm2_private.h
@@ -55,4 +55,29 @@ extern int _ecore_drm2_log_dom;
55# endif 55# endif
56# define CRIT(...) EINA_LOG_DOM_CRIT(_ecore_drm2_log_dom, __VA_ARGS__) 56# define CRIT(...) EINA_LOG_DOM_CRIT(_ecore_drm2_log_dom, __VA_ARGS__)
57 57
58struct _Ecore_Drm2_Device
59{
60 Elput_Manager *em;
61
62 int fd;
63 const char *path;
64
65 int num_crtcs;
66 uint32_t *crtcs;
67
68 struct
69 {
70 uint32_t crtc, conn;
71 } alloc;
72
73 struct
74 {
75 uint32_t width, height;
76 } min, max;
77
78 Eeze_Udev_Watch *watch;
79
80 Eina_List *outputs;
81};
82
58#endif 83#endif