aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Stultz2018-04-13 18:31:33 -0500
committerJohn Stultz2018-04-13 18:31:33 -0500
commit84f838d71a75125b14d361f0ed7d23a0ac521edf (patch)
treea7694dfdab2ca2b1d32e25071589c7ea0a992bd6 /xf86drm.c
parent2f9aea0661550a43c3d2ac33a5bc286870edd34e (diff)
parent35affe89d5f617a972b1cfee00c51cbe9e7c64a2 (diff)
downloadexternal-libdrm-84f838d71a75125b14d361f0ed7d23a0ac521edf.tar.gz
external-libdrm-84f838d71a75125b14d361f0ed7d23a0ac521edf.tar.xz
external-libdrm-84f838d71a75125b14d361f0ed7d23a0ac521edf.zip
Merge remote-tracking branch 'freedesktop/master' into aosp/master
This merges the freedesktop/master branch into aosp/master Change-Id: I3104d45924f67d37808154d04c15518394204478 Signed-off-by: John Stultz <john.stultz@linaro.org>
Diffstat (limited to 'xf86drm.c')
-rw-r--r--xf86drm.c243
1 files changed, 197 insertions, 46 deletions
diff --git a/xf86drm.c b/xf86drm.c
index 82fb0e22..390e1eb1 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -31,9 +31,6 @@
31 * DEALINGS IN THE SOFTWARE. 31 * DEALINGS IN THE SOFTWARE.
32 */ 32 */
33 33
34#ifdef HAVE_CONFIG_H
35# include <config.h>
36#endif
37#include <stdio.h> 34#include <stdio.h>
38#include <stdlib.h> 35#include <stdlib.h>
39#include <stdbool.h> 36#include <stdbool.h>
@@ -293,7 +290,7 @@ static int drmMatchBusID(const char *id1, const char *id2, int pci_domain_ok)
293 * If any other failure happened then it will output error mesage using 290 * If any other failure happened then it will output error mesage using
294 * drmMsg() call. 291 * drmMsg() call.
295 */ 292 */
296#if !defined(UDEV) 293#if !UDEV
297static int chown_check_return(const char *path, uid_t owner, gid_t group) 294static int chown_check_return(const char *path, uid_t owner, gid_t group)
298{ 295{
299 int rv; 296 int rv;
@@ -332,7 +329,7 @@ static int drmOpenDevice(dev_t dev, int minor, int type)
332 int fd; 329 int fd;
333 mode_t devmode = DRM_DEV_MODE, serv_mode; 330 mode_t devmode = DRM_DEV_MODE, serv_mode;
334 gid_t serv_group; 331 gid_t serv_group;
335#if !defined(UDEV) 332#if !UDEV
336 int isroot = !geteuid(); 333 int isroot = !geteuid();
337 uid_t user = DRM_DEV_UID; 334 uid_t user = DRM_DEV_UID;
338 gid_t group = DRM_DEV_GID; 335 gid_t group = DRM_DEV_GID;
@@ -361,7 +358,7 @@ static int drmOpenDevice(dev_t dev, int minor, int type)
361 devmode &= ~(S_IXUSR|S_IXGRP|S_IXOTH); 358 devmode &= ~(S_IXUSR|S_IXGRP|S_IXOTH);
362 } 359 }
363 360
364#if !defined(UDEV) 361#if !UDEV
365 if (stat(DRM_DIR_NAME, &st)) { 362 if (stat(DRM_DIR_NAME, &st)) {
366 if (!isroot) 363 if (!isroot)
367 return DRM_ERR_NOT_ROOT; 364 return DRM_ERR_NOT_ROOT;
@@ -414,7 +411,7 @@ wait_for_udev:
414 if (fd >= 0) 411 if (fd >= 0)
415 return fd; 412 return fd;
416 413
417#if !defined(UDEV) 414#if !UDEV
418 /* Check if the device node is not what we expect it to be, and recreate it 415 /* Check if the device node is not what we expect it to be, and recreate it
419 * and try again if so. 416 * and try again if so.
420 */ 417 */
@@ -866,8 +863,6 @@ drmVersionPtr drmGetVersion(int fd)
866 drmVersionPtr retval; 863 drmVersionPtr retval;
867 drm_version_t *version = drmMalloc(sizeof(*version)); 864 drm_version_t *version = drmMalloc(sizeof(*version));
868 865
869 memclear(*version);
870
871 if (drmIoctl(fd, DRM_IOCTL_VERSION, version)) { 866 if (drmIoctl(fd, DRM_IOCTL_VERSION, version)) {
872 drmFreeKernelVersion(version); 867 drmFreeKernelVersion(version);
873 return NULL; 868 return NULL;
@@ -994,8 +989,10 @@ char *drmGetBusid(int fd)
994 if (drmIoctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) 989 if (drmIoctl(fd, DRM_IOCTL_GET_UNIQUE, &u))
995 return NULL; 990 return NULL;
996 u.unique = drmMalloc(u.unique_len + 1); 991 u.unique = drmMalloc(u.unique_len + 1);
997 if (drmIoctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) 992 if (drmIoctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) {
993 drmFree(u.unique);
998 return NULL; 994 return NULL;
995 }
999 u.unique[u.unique_len] = '\0'; 996 u.unique[u.unique_len] = '\0';
1000 997
1001 return u.unique; 998 return u.unique;
@@ -1523,14 +1520,12 @@ drm_context_t *drmGetReservedContextList(int fd, int *count)
1523 1520
1524 if (!(list = drmMalloc(res.count * sizeof(*list)))) 1521 if (!(list = drmMalloc(res.count * sizeof(*list))))
1525 return NULL; 1522 return NULL;
1526 if (!(retval = drmMalloc(res.count * sizeof(*retval)))) { 1523 if (!(retval = drmMalloc(res.count * sizeof(*retval))))
1527 drmFree(list); 1524 goto err_free_list;
1528 return NULL;
1529 }
1530 1525
1531 res.contexts = list; 1526 res.contexts = list;
1532 if (drmIoctl(fd, DRM_IOCTL_RES_CTX, &res)) 1527 if (drmIoctl(fd, DRM_IOCTL_RES_CTX, &res))
1533 return NULL; 1528 goto err_free_context;
1534 1529
1535 for (i = 0; i < res.count; i++) 1530 for (i = 0; i < res.count; i++)
1536 retval[i] = list[i].handle; 1531 retval[i] = list[i].handle;
@@ -1538,6 +1533,12 @@ drm_context_t *drmGetReservedContextList(int fd, int *count)
1538 1533
1539 *count = res.count; 1534 *count = res.count;
1540 return retval; 1535 return retval;
1536
1537err_free_list:
1538 drmFree(list);
1539err_free_context:
1540 drmFree(retval);
1541 return NULL;
1541} 1542}
1542 1543
1543void drmFreeReservedContextList(drm_context_t *pt) 1544void drmFreeReservedContextList(drm_context_t *pt)
@@ -1691,6 +1692,43 @@ int drmUpdateDrawableInfo(int fd, drm_drawable_t handle,
1691 return 0; 1692 return 0;
1692} 1693}
1693 1694
1695int drmCrtcGetSequence(int fd, uint32_t crtcId, uint64_t *sequence, uint64_t *ns)
1696{
1697 struct drm_crtc_get_sequence get_seq;
1698 int ret;
1699
1700 memclear(get_seq);
1701 get_seq.crtc_id = crtcId;
1702 ret = drmIoctl(fd, DRM_IOCTL_CRTC_GET_SEQUENCE, &get_seq);
1703 if (ret)
1704 return ret;
1705
1706 if (sequence)
1707 *sequence = get_seq.sequence;
1708 if (ns)
1709 *ns = get_seq.sequence_ns;
1710 return 0;
1711}
1712
1713int drmCrtcQueueSequence(int fd, uint32_t crtcId, uint32_t flags, uint64_t sequence,
1714 uint64_t *sequence_queued, uint64_t user_data)
1715{
1716 struct drm_crtc_queue_sequence queue_seq;
1717 int ret;
1718
1719 memclear(queue_seq);
1720 queue_seq.crtc_id = crtcId;
1721 queue_seq.flags = flags;
1722 queue_seq.sequence = sequence;
1723 queue_seq.user_data = user_data;
1724
1725 ret = drmIoctl(fd, DRM_IOCTL_CRTC_QUEUE_SEQUENCE, &queue_seq);
1726 if (ret == 0 && sequence_queued)
1727 *sequence_queued = queue_seq.sequence;
1728
1729 return ret;
1730}
1731
1694/** 1732/**
1695 * Acquire the AGP device. 1733 * Acquire the AGP device.
1696 * 1734 *
@@ -2781,12 +2819,11 @@ static char *drmGetMinorNameForFD(int fd, int type)
2781{ 2819{
2782#ifdef __linux__ 2820#ifdef __linux__
2783 DIR *sysdir; 2821 DIR *sysdir;
2784 struct dirent *pent, *ent; 2822 struct dirent *ent;
2785 struct stat sbuf; 2823 struct stat sbuf;
2786 const char *name = drmGetMinorName(type); 2824 const char *name = drmGetMinorName(type);
2787 int len; 2825 int len;
2788 char dev_name[64], buf[64]; 2826 char dev_name[64], buf[64];
2789 long name_max;
2790 int maj, min; 2827 int maj, min;
2791 2828
2792 if (!name) 2829 if (!name)
@@ -2809,30 +2846,16 @@ static char *drmGetMinorNameForFD(int fd, int type)
2809 if (!sysdir) 2846 if (!sysdir)
2810 return NULL; 2847 return NULL;
2811 2848
2812 name_max = fpathconf(dirfd(sysdir), _PC_NAME_MAX); 2849 while ((ent = readdir(sysdir))) {
2813 if (name_max == -1)
2814 goto out_close_dir;
2815
2816 pent = malloc(offsetof(struct dirent, d_name) + name_max + 1);
2817 if (pent == NULL)
2818 goto out_close_dir;
2819
2820 while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) {
2821 if (strncmp(ent->d_name, name, len) == 0) { 2850 if (strncmp(ent->d_name, name, len) == 0) {
2822 snprintf(dev_name, sizeof(dev_name), DRM_DIR_NAME "/%s", 2851 snprintf(dev_name, sizeof(dev_name), DRM_DIR_NAME "/%s",
2823 ent->d_name); 2852 ent->d_name);
2824 2853
2825 free(pent);
2826 closedir(sysdir); 2854 closedir(sysdir);
2827
2828 return strdup(dev_name); 2855 return strdup(dev_name);
2829 } 2856 }
2830 } 2857 }
2831 2858 return NULL;
2832 free(pent);
2833
2834out_close_dir:
2835 closedir(sysdir);
2836#else 2859#else
2837 struct stat sbuf; 2860 struct stat sbuf;
2838 char buf[PATH_MAX + 1]; 2861 char buf[PATH_MAX + 1];
@@ -2873,7 +2896,6 @@ out_close_dir:
2873 2896
2874 return strdup(buf); 2897 return strdup(buf);
2875#endif 2898#endif
2876 return NULL;
2877} 2899}
2878 2900
2879char *drmGetPrimaryDeviceNameFromFd(int fd) 2901char *drmGetPrimaryDeviceNameFromFd(int fd)
@@ -3023,32 +3045,32 @@ static int drmParsePciBusInfo(int maj, int min, drmPciBusInfoPtr info)
3023#endif 3045#endif
3024} 3046}
3025 3047
3026static int drmCompareBusInfo(drmDevicePtr a, drmDevicePtr b) 3048int drmDevicesEqual(drmDevicePtr a, drmDevicePtr b)
3027{ 3049{
3028 if (a == NULL || b == NULL) 3050 if (a == NULL || b == NULL)
3029 return -1; 3051 return 0;
3030 3052
3031 if (a->bustype != b->bustype) 3053 if (a->bustype != b->bustype)
3032 return -1; 3054 return 0;
3033 3055
3034 switch (a->bustype) { 3056 switch (a->bustype) {
3035 case DRM_BUS_PCI: 3057 case DRM_BUS_PCI:
3036 return memcmp(a->businfo.pci, b->businfo.pci, sizeof(drmPciBusInfo)); 3058 return memcmp(a->businfo.pci, b->businfo.pci, sizeof(drmPciBusInfo)) == 0;
3037 3059
3038 case DRM_BUS_USB: 3060 case DRM_BUS_USB:
3039 return memcmp(a->businfo.usb, b->businfo.usb, sizeof(drmUsbBusInfo)); 3061 return memcmp(a->businfo.usb, b->businfo.usb, sizeof(drmUsbBusInfo)) == 0;
3040 3062
3041 case DRM_BUS_PLATFORM: 3063 case DRM_BUS_PLATFORM:
3042 return memcmp(a->businfo.platform, b->businfo.platform, sizeof(drmPlatformBusInfo)); 3064 return memcmp(a->businfo.platform, b->businfo.platform, sizeof(drmPlatformBusInfo)) == 0;
3043 3065
3044 case DRM_BUS_HOST1X: 3066 case DRM_BUS_HOST1X:
3045 return memcmp(a->businfo.host1x, b->businfo.host1x, sizeof(drmHost1xBusInfo)); 3067 return memcmp(a->businfo.host1x, b->businfo.host1x, sizeof(drmHost1xBusInfo)) == 0;
3046 3068
3047 default: 3069 default:
3048 break; 3070 break;
3049 } 3071 }
3050 3072
3051 return -1; 3073 return 0;
3052} 3074}
3053 3075
3054static int drmGetNodeType(const char *name) 3076static int drmGetNodeType(const char *name)
@@ -3663,7 +3685,7 @@ static void drmFoldDuplicatedDevices(drmDevicePtr local_devices[], int count)
3663 3685
3664 for (i = 0; i < count; i++) { 3686 for (i = 0; i < count; i++) {
3665 for (j = i + 1; j < count; j++) { 3687 for (j = i + 1; j < count; j++) {
3666 if (drmCompareBusInfo(local_devices[i], local_devices[j]) == 0) { 3688 if (drmDevicesEqual(local_devices[i], local_devices[j])) {
3667 local_devices[i]->available_nodes |= local_devices[j]->available_nodes; 3689 local_devices[i]->available_nodes |= local_devices[j]->available_nodes;
3668 node_type = log2(local_devices[j]->available_nodes); 3690 node_type = log2(local_devices[j]->available_nodes);
3669 memcpy(local_devices[i]->nodes[node_type], 3691 memcpy(local_devices[i]->nodes[node_type],
@@ -3985,7 +4007,7 @@ int drmGetDevices2(uint32_t flags, drmDevicePtr devices[], int max_devices)
3985 ret = drmProcessUsbDevice(&device, node, node_type, maj, min, 4007 ret = drmProcessUsbDevice(&device, node, node_type, maj, min,
3986 devices != NULL, flags); 4008 devices != NULL, flags);
3987 if (ret) 4009 if (ret)
3988 goto free_devices; 4010 continue;
3989 4011
3990 break; 4012 break;
3991 4013
@@ -3993,7 +4015,7 @@ int drmGetDevices2(uint32_t flags, drmDevicePtr devices[], int max_devices)
3993 ret = drmProcessPlatformDevice(&device, node, node_type, maj, min, 4015 ret = drmProcessPlatformDevice(&device, node, node_type, maj, min,
3994 devices != NULL, flags); 4016 devices != NULL, flags);
3995 if (ret) 4017 if (ret)
3996 goto free_devices; 4018 continue;
3997 4019
3998 break; 4020 break;
3999 4021
@@ -4001,7 +4023,7 @@ int drmGetDevices2(uint32_t flags, drmDevicePtr devices[], int max_devices)
4001 ret = drmProcessHost1xDevice(&device, node, node_type, maj, min, 4023 ret = drmProcessHost1xDevice(&device, node, node_type, maj, min,
4002 devices != NULL, flags); 4024 devices != NULL, flags);
4003 if (ret) 4025 if (ret)
4004 goto free_devices; 4026 continue;
4005 4027
4006 break; 4028 break;
4007 4029
@@ -4140,3 +4162,132 @@ char *drmGetDeviceNameFromFd2(int fd)
4140 return strdup(node); 4162 return strdup(node);
4141#endif 4163#endif
4142} 4164}
4165
4166int drmSyncobjCreate(int fd, uint32_t flags, uint32_t *handle)
4167{
4168 struct drm_syncobj_create args;
4169 int ret;
4170
4171 memclear(args);
4172 args.flags = flags;
4173 args.handle = 0;
4174 ret = drmIoctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &args);
4175 if (ret)
4176 return ret;
4177 *handle = args.handle;
4178 return 0;
4179}
4180
4181int drmSyncobjDestroy(int fd, uint32_t handle)
4182{
4183 struct drm_syncobj_destroy args;
4184
4185 memclear(args);
4186 args.handle = handle;
4187 return drmIoctl(fd, DRM_IOCTL_SYNCOBJ_DESTROY, &args);
4188}
4189
4190int drmSyncobjHandleToFD(int fd, uint32_t handle, int *obj_fd)
4191{
4192 struct drm_syncobj_handle args;
4193 int ret;
4194
4195 memclear(args);
4196 args.fd = -1;
4197 args.handle = handle;
4198 ret = drmIoctl(fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD, &args);
4199 if (ret)
4200 return ret;
4201 *obj_fd = args.fd;
4202 return 0;
4203}
4204
4205int drmSyncobjFDToHandle(int fd, int obj_fd, uint32_t *handle)
4206{
4207 struct drm_syncobj_handle args;
4208 int ret;
4209
4210 memclear(args);
4211 args.fd = obj_fd;
4212 args.handle = 0;
4213 ret = drmIoctl(fd, DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE, &args);
4214 if (ret)
4215 return ret;
4216 *handle = args.handle;
4217 return 0;
4218}
4219
4220int drmSyncobjImportSyncFile(int fd, uint32_t handle, int sync_file_fd)
4221{
4222 struct drm_syncobj_handle args;
4223
4224 memclear(args);
4225 args.fd = sync_file_fd;
4226 args.handle = handle;
4227 args.flags = DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE;
4228 return drmIoctl(fd, DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE, &args);
4229}
4230
4231int drmSyncobjExportSyncFile(int fd, uint32_t handle, int *sync_file_fd)
4232{
4233 struct drm_syncobj_handle args;
4234 int ret;
4235
4236 memclear(args);
4237 args.fd = -1;
4238 args.handle = handle;
4239 args.flags = DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE;
4240 ret = drmIoctl(fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD, &args);
4241 if (ret)
4242 return ret;
4243 *sync_file_fd = args.fd;
4244 return 0;
4245}
4246
4247int drmSyncobjWait(int fd, uint32_t *handles, unsigned num_handles,
4248 int64_t timeout_nsec, unsigned flags,
4249 uint32_t *first_signaled)
4250{
4251 struct drm_syncobj_wait args;
4252 int ret;
4253
4254 memclear(args);
4255 args.handles = (uintptr_t)handles;
4256 args.timeout_nsec = timeout_nsec;
4257 args.count_handles = num_handles;
4258 args.flags = flags;
4259
4260 ret = drmIoctl(fd, DRM_IOCTL_SYNCOBJ_WAIT, &args);
4261 if (ret < 0)
4262 return -errno;
4263
4264 if (first_signaled)
4265 *first_signaled = args.first_signaled;
4266 return ret;
4267}
4268
4269int drmSyncobjReset(int fd, const uint32_t *handles, uint32_t handle_count)
4270{
4271 struct drm_syncobj_array args;
4272 int ret;
4273
4274 memclear(args);
4275 args.handles = (uintptr_t)handles;
4276 args.count_handles = handle_count;
4277
4278 ret = drmIoctl(fd, DRM_IOCTL_SYNCOBJ_RESET, &args);
4279 return ret;
4280}
4281
4282int drmSyncobjSignal(int fd, const uint32_t *handles, uint32_t handle_count)
4283{
4284 struct drm_syncobj_array args;
4285 int ret;
4286
4287 memclear(args);
4288 args.handles = (uintptr_t)handles;
4289 args.count_handles = handle_count;
4290
4291 ret = drmIoctl(fd, DRM_IOCTL_SYNCOBJ_SIGNAL, &args);
4292 return ret;
4293}