summaryrefslogtreecommitdiff
path: root/src/lib/ecore_drm2/ecore_drm2_device.c
diff options
context:
space:
mode:
authorChris Michael <cpmichael@osg.samsung.com>2016-05-02 10:40:47 -0400
committerChris Michael <cpmichael@osg.samsung.com>2016-05-27 11:57:53 -0400
commit9c7b6572875d5245ae69300936d1cb942bfd0498 (patch)
treedac2e60e6fef3019ab73699d16387c82f90e2d0d /src/lib/ecore_drm2/ecore_drm2_device.c
parenta0d3b955bfa18e807ef1067aa612a63d99bf7681 (diff)
ecore-drm2: Add API functions to work with a drm device
This commit adds new API functions to find, open, and close a drm device, along with API functions to retrieve clock_id and cursor size. Signed-off-by: Chris Michael <cpmichael@osg.samsung.com>
Diffstat (limited to 'src/lib/ecore_drm2/ecore_drm2_device.c')
-rw-r--r--src/lib/ecore_drm2/ecore_drm2_device.c184
1 files changed, 184 insertions, 0 deletions
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}