|
From: <eve...@ke...> - 2016-12-05 17:55:41
|
configure.ac | 7 -
libkms/Makefile.am | 4
libkms/linux.c | 94 ----------------
tests/Makefile.am | 46 +------
tests/auth.c | 138 -----------------------
tests/dristat.c | 285 ------------------------------------------------
tests/drmdevice.c | 23 ++-
tests/drmtest.c | 135 -----------------------
tests/drmtest.h | 40 ------
tests/getclient.c | 61 ----------
tests/getstats.c | 50 --------
tests/getversion.c | 49 --------
tests/lock.c | 264 ---------------------------------------------
tests/name_from_fd.c | 58 ---------
tests/openclose.c | 37 ------
tests/setversion.c | 91 ---------------
tests/updatedraw.c | 154 --------------------------
xf86drm.c | 297 ++++++++++++++++++++++++++++++++++++++++++++++++---
xf86drm.h | 4
19 files changed, 308 insertions(+), 1529 deletions(-)
New commits:
commit 08257927231e4f51c38e1d2bdbb8db0c2d4aec40
Author: Jonathan Gray <js...@js...>
Date: Thu Dec 1 15:18:43 2016 +1100
xf86drm: implement an OpenBSD specific drmGetDevice2
DRI devices on OpenBSD are not in their own directory. They reside in
/dev with a large number of statically generated /dev nodes.
Avoid stat'ing all of /dev on OpenBSD by implementing this custom path.
v2:
- use drmGetMinorType to get node type
- adapt to drmProcessPciDevice changes
- verify drmParseSubsystemType type is PCI
- add a comment describing why this was added
Signed-off-by: Jonathan Gray <js...@js...>
Reviewed-by: Emil Velikov <emi...@gm...>
diff --git a/xf86drm.c b/xf86drm.c
index 5635381..2e8c956 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -3251,6 +3251,67 @@ drm_device_validate_flags(uint32_t flags)
*/
int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device)
{
+#ifdef __OpenBSD__
+ /*
+ * DRI device nodes on OpenBSD are not in their own directory, they reside
+ * in /dev along with a large number of statically generated /dev nodes.
+ * Avoid stat'ing all of /dev needlessly by implementing this custom path.
+ */
+ drmDevicePtr d;
+ struct stat sbuf;
+ char node[PATH_MAX + 1];
+ const char *dev_name;
+ int node_type, subsystem_type;
+ int maj, min, n, ret;
+
+ if (fd == -1 || device == NULL)
+ return -EINVAL;
+
+ if (fstat(fd, &sbuf))
+ return -errno;
+
+ maj = major(sbuf.st_rdev);
+ min = minor(sbuf.st_rdev);
+
+ if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
+ return -EINVAL;
+
+ node_type = drmGetMinorType(min);
+ if (node_type == -1)
+ return -ENODEV;
+
+ switch (node_type) {
+ case DRM_NODE_PRIMARY:
+ dev_name = DRM_DEV_NAME;
+ break;
+ case DRM_NODE_CONTROL:
+ dev_name = DRM_CONTROL_DEV_NAME;
+ break;
+ case DRM_NODE_RENDER:
+ dev_name = DRM_RENDER_DEV_NAME;
+ break;
+ default:
+ return -EINVAL;
+ };
+
+ n = snprintf(node, PATH_MAX, dev_name, DRM_DIR_NAME, min);
+ if (n == -1 || n >= PATH_MAX)
+ return -errno;
+ if (stat(node, &sbuf))
+ return -EINVAL;
+
+ subsystem_type = drmParseSubsystemType(maj, min);
+ if (subsystem_type != DRM_BUS_PCI)
+ return -ENODEV;
+
+ ret = drmProcessPciDevice(&d, node, node_type, maj, min, true, flags);
+ if (ret)
+ return ret;
+
+ *device = d;
+
+ return 0;
+#else
drmDevicePtr *local_devices;
drmDevicePtr d;
DIR *sysdir;
@@ -3360,6 +3421,7 @@ free_devices:
free_locals:
free(local_devices);
return ret;
+#endif
}
/**
commit fd190564daa4cd530833a94606646730a5c0ee6c
Author: Jonathan Gray <js...@js...>
Date: Thu Dec 1 15:18:42 2016 +1100
xf86drm: implement drmParsePciBusInfo for OpenBSD
Implement drmParsePciBusInfo for OpenBSD by using the new
DRM_IOCTL_GET_PCIINFO ioctl.
v2: use drmGetMinorType to get node type instead of always
using DRM_NODE_PRIMARY.
Signed-off-by: Jonathan Gray <js...@js...>
Reviewed-by: Emil Velikov <emi...@gm...>
diff --git a/xf86drm.c b/xf86drm.c
index f0fc4ee..5635381 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2947,6 +2947,30 @@ static int drmParsePciBusInfo(int maj, int min, drmPciBusInfoPtr info)
info->func = func;
return 0;
+#elif defined(__OpenBSD__)
+ struct drm_pciinfo pinfo;
+ int fd, type;
+
+ type = drmGetMinorType(min);
+ if (type == -1)
+ return -ENODEV;
+
+ fd = drmOpenMinor(min, 0, type);
+ if (fd < 0)
+ return -errno;
+
+ if (drmIoctl(fd, DRM_IOCTL_GET_PCIINFO, &pinfo)) {
+ close(fd);
+ return -errno;
+ }
+ close(fd);
+
+ info->domain = pinfo.domain;
+ info->bus = pinfo.bus;
+ info->dev = pinfo.dev;
+ info->func = pinfo.func;
+
+ return 0;
#else
#warning "Missing implementation of drmParsePciBusInfo"
return -EINVAL;
commit c0ef1d078800a43611136e65be3c9c7472ac9d3f
Author: Jonathan Gray <js...@js...>
Date: Thu Dec 1 15:18:41 2016 +1100
xf86drm: implement drmParsePciDeviceInfo for OpenBSD
Implement drmParsePciDeviceInfo for OpenBSD by using the new
DRM_IOCTL_GET_PCIINFO ioctl.
v2: adapt to drmParsePciDeviceInfo changes and use drmOpenMinor
Signed-off-by: Jonathan Gray <js...@js...>
Reviewed-by: Emil Velikov <emi...@gm...>
diff --git a/xf86drm.c b/xf86drm.c
index a889d48..f0fc4ee 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -102,6 +102,22 @@
#define DRM_MAJOR 226 /* Linux */
#endif
+#ifdef __OpenBSD__
+struct drm_pciinfo {
+ uint16_t domain;
+ uint8_t bus;
+ uint8_t dev;
+ uint8_t func;
+ uint16_t vendor_id;
+ uint16_t device_id;
+ uint16_t subvendor_id;
+ uint16_t subdevice_id;
+ uint8_t revision_id;
+};
+
+#define DRM_IOCTL_GET_PCIINFO DRM_IOR(0x15, struct drm_pciinfo)
+#endif
+
#define DRM_MSG_VERBOSITY 3
#define memclear(s) memset(&s, 0, sizeof(s))
@@ -3061,6 +3077,31 @@ static int drmParsePciDeviceInfo(int maj, int min,
return parse_config_sysfs_file(maj, min, device);
return 0;
+#elif defined(__OpenBSD__)
+ struct drm_pciinfo pinfo;
+ int fd, type;
+
+ type = drmGetMinorType(min);
+ if (type == -1)
+ return -ENODEV;
+
+ fd = drmOpenMinor(min, 0, type);
+ if (fd < 0)
+ return -errno;
+
+ if (drmIoctl(fd, DRM_IOCTL_GET_PCIINFO, &pinfo)) {
+ close(fd);
+ return -errno;
+ }
+ close(fd);
+
+ device->vendor_id = pinfo.vendor_id;
+ device->device_id = pinfo.device_id;
+ device->revision_id = pinfo.revision_id;
+ device->subvendor_id = pinfo.subvendor_id;
+ device->subdevice_id = pinfo.subdevice_id;
+
+ return 0;
#else
#warning "Missing implementation of drmParsePciDeviceInfo"
return -EINVAL;
commit d05b9f2dde17e60996437332219b4b568f7edefa
Author: Jonathan Gray <js...@js...>
Date: Thu Dec 1 15:18:40 2016 +1100
xf86drm: implement drmParseSubsystemType for OpenBSD
Implement drmParseSubsystemType for OpenBSD by always returning
DRM_BUS_PCI. No non-pci drm drivers are in the kernel and this is
unlikely to change anytime soon as the existing ones aren't permissively
licensed.
Signed-off-by: Jonathan Gray <js...@js...>
Reviewed-by: Emil Velikov <emi...@gm...>
diff --git a/xf86drm.c b/xf86drm.c
index 65764de..a889d48 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2887,6 +2887,8 @@ static int drmParseSubsystemType(int maj, int min)
return DRM_BUS_PCI;
return -EINVAL;
+#elif defined(__OpenBSD__)
+ return DRM_BUS_PCI;
#else
#warning "Missing implementation of drmParseSubsystemType"
return -EINVAL;
commit f189011b362a2dff3ab914523e546cc96f53df39
Author: Jonathan Gray <js...@js...>
Date: Thu Dec 1 15:18:39 2016 +1100
xf86drm: implement drmGetMinorNameForFD for non-sysfs
Implement drmGetMinorNameForFD for systems without sysfs by
adapting drm_get_device_name_for_fd() from the Mesa loader.
v2: use type parameter to select dev name instead of always
using DRM_DEV_NAME
Signed-off-by: Jonathan Gray <js...@js...>
Reviewed-by: Emil Velikov <emi...@gm...>
diff --git a/xf86drm.c b/xf86drm.c
index a886768..65764de 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2818,7 +2818,40 @@ static char *drmGetMinorNameForFD(int fd, int type)
out_close_dir:
closedir(sysdir);
#else
-#warning "Missing implementation of drmGetMinorNameForFD"
+ struct stat sbuf;
+ char buf[PATH_MAX + 1];
+ const char *dev_name;
+ unsigned int maj, min;
+ int n;
+
+ if (fstat(fd, &sbuf))
+ return NULL;
+
+ maj = major(sbuf.st_rdev);
+ min = minor(sbuf.st_rdev);
+
+ if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
+ return NULL;
+
+ switch (type) {
+ case DRM_NODE_PRIMARY:
+ dev_name = DRM_DEV_NAME;
+ break;
+ case DRM_NODE_CONTROL:
+ dev_name = DRM_CONTROL_DEV_NAME;
+ break;
+ case DRM_NODE_RENDER:
+ dev_name = DRM_RENDER_DEV_NAME;
+ break;
+ default:
+ return NULL;
+ };
+
+ n = snprintf(buf, sizeof(buf), dev_name, DRM_DIR_NAME, min);
+ if (n == -1 || n >= sizeof(buf))
+ return NULL;
+
+ return strdup(buf);
#endif
return NULL;
}
commit 5c1c91b3d381a51ea57fb68242f8645e63d806bd
Author: Emil Velikov <emi...@gm...>
Date: Wed Nov 30 19:04:33 2016 +0000
tests: automake: reorder makefile contents
Purely cosmetic changes.
Signed-off-by: Emil Velikov <emi...@gm...>
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 136ccce..0355a92 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -26,6 +26,10 @@ if HAVE_ETNAVIV
SUBDIRS += etnaviv
endif
+if HAVE_NOUVEAU
+SUBDIRS += nouveau
+endif
+
AM_CFLAGS = \
$(WARN_CFLAGS)\
-I $(top_srcdir)/include/drm \
@@ -33,16 +37,11 @@ AM_CFLAGS = \
LDADD = $(top_builddir)/libdrm.la
-check_PROGRAMS = \
- drmdevice
-
-if HAVE_NOUVEAU
-SUBDIRS += nouveau
-endif
-
TESTS = \
drmsl \
hash \
random
-check_PROGRAMS += $(TESTS)
+check_PROGRAMS = \
+ $(TESTS) \
+ drmdevice
commit 0ec7252a1deba3bac78b5ba1ebd2898f6bbf0332
Author: Emil Velikov <emi...@gm...>
Date: Wed Nov 30 18:43:18 2016 +0000
configure: remove libudev checks
Library is no longer used.
Signed-off-by: Emil Velikov <emi...@gm...>
diff --git a/configure.ac b/configure.ac
index 708c562..e0597c3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -451,13 +451,6 @@ fi
AC_MSG_RESULT([$CAIRO])
AM_CONDITIONAL(HAVE_CAIRO, [test "x$CAIRO" = xyes])
-# For enumerating devices in test case
-PKG_CHECK_MODULES(LIBUDEV, libudev, [HAVE_LIBUDEV=yes], [HAVE_LIBUDEV=no])
-if test "x$HAVE_LIBUDEV" = xyes; then
- AC_DEFINE(HAVE_LIBUDEV, 1, [Have libudev support])
-fi
-AM_CONDITIONAL(HAVE_LIBUDEV, [test "x$HAVE_LIBUDEV" = xyes])
-
# xsltproc for docbook manpages
AC_ARG_ENABLE([manpages],
AS_HELP_STRING([--enable-manpages], [enable manpages @<:@default=auto@:>@]),
commit 9b05d403992c0ca181a920561d27931871909eb7
Author: Emil Velikov <emi...@gm...>
Date: Wed Nov 30 18:39:07 2016 +0000
kms: remove commented out libudev code
Cc: Jakob Bornecrantz <wal...@gm...>
Signed-off-by: Emil Velikov <emi...@gm...>
diff --git a/libkms/Makefile.am b/libkms/Makefile.am
index 7c1debe..461fc35 100644
--- a/libkms/Makefile.am
+++ b/libkms/Makefile.am
@@ -10,10 +10,6 @@ libkms_ladir = $(libdir)
libkms_la_LDFLAGS = -version-number 1:0:0 -no-undefined
libkms_la_LIBADD = ../libdrm.la
-#if HAVE_LIBUDEV
-#libkms_la_LIBADD += $(LIBUDEV_LIBS)
-#endif
-
libkms_la_SOURCES = $(LIBKMS_FILES)
if HAVE_VMWGFX
diff --git a/libkms/linux.c b/libkms/linux.c
index 69eb1aa..0b50777 100644
--- a/libkms/linux.c
+++ b/libkms/linux.c
@@ -141,105 +141,11 @@ linux_from_sysfs(int fd, struct kms_driver **out)
return ret;
}
-#if 0
-#define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE
-#include <libudev.h>
-
-struct create_record
-{
- unsigned vendor;
- unsigned chip;
- int (*func)(int fd, struct kms_driver **out);
-};
-
-static const struct create_record table[] = {
- { 0x8086, 0x2a42, intel_create }, /* i965 */
-#ifdef HAVE_VMWGFX
- { 0x15ad, 0x0405, vmwgfx_create }, /* VMware vGPU */
-#endif
- { 0, 0, NULL },
-};
-
-static int
-linux_get_pciid_from_fd(int fd, unsigned *vendor_id, unsigned *chip_id)
-{
- struct udev *udev;
- struct udev_device *device;
- struct udev_device *parent;
- const char *pci_id;
- struct stat buffer;
- int ret;
-
- ret = fstat(fd, &buffer);
- if (ret)
- return -EINVAL;
-
- if (!S_ISCHR(buffer.st_mode))
- return -EINVAL;
-
- udev = udev_new();
- if (!udev)
- return -ENOMEM;
-
- device = udev_device_new_from_devnum(udev, 'c', buffer.st_rdev);
- if (!device)
- goto err_free_udev;
-
- parent = udev_device_get_parent(device);
- if (!parent)
- goto err_free_device;
-
- pci_id = udev_device_get_property_value(parent, "PCI_ID");
- if (!pci_id)
- goto err_free_device;
-
- if (sscanf(pci_id, "%x:%x", vendor_id, chip_id) != 2)
- goto err_free_device;
-
- udev_device_unref(device);
- udev_unref(udev);
-
- return 0;
-
-err_free_device:
- udev_device_unref(device);
-err_free_udev:
- udev_unref(udev);
- return -EINVAL;
-}
-
-static int
-linux_from_udev(int fd, struct kms_driver **out)
-{
- unsigned vendor_id, chip_id;
- int ret, i;
-
- ret = linux_get_pciid_from_fd(fd, &vendor_id, &chip_id);
- if (ret)
- return ret;
-
- for (i = 0; table[i].func; i++)
- if (table[i].vendor == vendor_id && table[i].chip == chip_id)
- return table[i].func(fd, out);
-
- return -ENOSYS;
-}
-#else
-static int
-linux_from_udev(int fd, struct kms_driver **out)
-{
- return -ENOSYS;
-}
-#endif
-
drm_private int
linux_create(int fd, struct kms_driver **out)
{
if (!dumb_create(fd, out))
return 0;
- if (!linux_from_udev(fd, out))
- return 0;
-
return linux_from_sysfs(fd, out);
}
commit 0c80fddd1d01206756bf2a3227cdf1efbfb16aaf
Author: Emil Velikov <emi...@gm...>
Date: Wed Nov 30 18:23:51 2016 +0000
tests: remove useless legacy tests
All of these 'tests' cover UMS functionality which is neither being
worked on or actively maintained.
The only cases where developers touch UMS code is to unwrap it from the
KMS codepaths and ensure that those are secure.
Anyone who feels strong about having these around can revive them, but
in all honestly do consider _seriously_ what you're doing ;-)
Signed-off-by: Emil Velikov <emi...@gm...>
Acked-by: Daniel Vetter <dan...@ff...>
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4a499e4..136ccce 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -34,11 +34,7 @@ AM_CFLAGS = \
LDADD = $(top_builddir)/libdrm.la
check_PROGRAMS = \
- dristat \
- drmdevice \
- drmstat
-
-dristat_LDADD = -lm
+ drmdevice
if HAVE_NOUVEAU
SUBDIRS += nouveau
@@ -49,31 +45,4 @@ TESTS = \
hash \
random
-if HAVE_LIBUDEV
-
-check_LTLIBRARIES = libdrmtest.la
-
-libdrmtest_la_SOURCES = \
- drmtest.c \
- drmtest.h
-
-LDADD += \
- libdrmtest.la \
- $(LIBUDEV_LIBS)
-
-
-XFAIL_TESTS = \
- auth \
- lock
-
-TESTS += \
- openclose \
- getversion \
- getclient \
- getstats \
- setversion \
- updatedraw \
- name_from_fd
-endif
-
check_PROGRAMS += $(TESTS)
diff --git a/tests/auth.c b/tests/auth.c
deleted file mode 100644
index 9147b11..0000000
--- a/tests/auth.c
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright © 2007 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- *
- * Authors:
- * Eric Anholt <er...@an...>
- *
- */
-
-#include <limits.h>
-#include <sys/ioctl.h>
-#include "drmtest.h"
-
-enum auth_event {
- SERVER_READY,
- CLIENT_MAGIC,
- CLIENT_DONE,
-};
-
-int commfd[2];
-
-static void wait_event(int pipe, enum auth_event expected_event)
-{
- int ret;
- enum auth_event event;
- unsigned char in;
-
- ret = read(commfd[pipe], &in, 1);
- if (ret == -1)
- err(1, "read error");
- event = in;
-
- if (event != expected_event)
- errx(1, "unexpected event: %d\n", event);
-}
-
-static void
-send_event(int pipe, enum auth_event send_event)
-{
- int ret;
- unsigned char event;
-
- event = send_event;
- ret = write(commfd[pipe], &event, 1);
- if (ret == -1)
- err(1, "failed to send event %d", event);
-}
-
-static void client()
-{
- struct drm_auth auth;
- int drmfd, ret;
-
- /* XXX: Should make sure we open the same DRM as the master */
- wait_event(0, SERVER_READY);
-
- drmfd = drm_open_any();
-
- /* Get a client magic number and pass it to the master for auth. */
- auth.magic = 0; /* Quiet valgrind */
- ret = ioctl(drmfd, DRM_IOCTL_GET_MAGIC, &auth);
- if (ret == -1)
- err(1, "Couldn't get client magic");
- send_event(0, CLIENT_MAGIC);
- ret = write(commfd[0], &auth.magic, sizeof(auth.magic));
- if (ret == -1)
- err(1, "Couldn't write auth data");
-
- /* Signal that the client is completely done. */
- send_event(0, CLIENT_DONE);
-}
-
-static void server()
-{
- int drmfd, ret;
- struct drm_auth auth;
-
- drmfd = drm_open_any_master();
-
- auth.magic = 0xd0d0d0d0;
- ret = ioctl(drmfd, DRM_IOCTL_AUTH_MAGIC, &auth);
- if (ret != -1 || errno != EINVAL)
- errx(1, "Authenticating bad magic succeeded\n");
-
- send_event(1, SERVER_READY);
-
- wait_event(1, CLIENT_MAGIC);
- ret = read(commfd[1], &auth.magic, sizeof(auth.magic));
- if (ret == -1)
- err(1, "Failure to read client magic");
-
- ret = ioctl(drmfd, DRM_IOCTL_AUTH_MAGIC, &auth);
- if (ret == -1)
- err(1, "Failure to authenticate client magic\n");
-
- wait_event(1, CLIENT_DONE);
-}
-
-/**
- * Checks DRM authentication mechanisms.
- */
-int main(int argc, char **argv)
-{
- int ret;
-
- ret = pipe(commfd);
- if (ret == -1)
- err(1, "Couldn't create pipe");
-
- ret = fork();
- if (ret == -1)
- err(1, "failure to fork client");
- if (ret == 0)
- client();
- else
- server();
-
- return 0;
-}
-
diff --git a/tests/dristat.c b/tests/dristat.c
deleted file mode 100644
index cca4b03..0000000
--- a/tests/dristat.c
+++ /dev/null
@@ -1,285 +0,0 @@
-/* dristat.c --
- * Created: Mon Jan 15 05:05:07 2001 by fa...@ac...
- *
- * Copyright 2000 VA Linux Systems, Inc., Fremont, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors: Rickard E. (Rik) Faith <fa...@va...>
- *
- */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include "xf86drm.h"
-#include "xf86drmRandom.c"
-#include "xf86drmHash.c"
-#include "xf86drm.c"
-
-#define DRM_VERSION 0x00000001
-#define DRM_MEMORY 0x00000002
-#define DRM_CLIENTS 0x00000004
-#define DRM_STATS 0x00000008
-#define DRM_BUSID 0x00000010
-
-static void getversion(int fd)
-{
- drmVersionPtr version;
-
- version = drmGetVersion(fd);
- if (version) {
- printf(" Version information:\n");
- printf(" Name: %s\n", version->name ? version->name : "?");
- printf(" Version: %d.%d.%d\n",
- version->version_major,
- version->version_minor,
- version->version_patchlevel);
- printf(" Date: %s\n", version->date ? version->date : "?");
- printf(" Desc: %s\n", version->desc ? version->desc : "?");
- drmFreeVersion(version);
- } else {
- printf(" No version information available\n");
- }
-}
-
-static void getbusid(int fd)
-{
- const char *busid = drmGetBusid(fd);
-
- printf(" Busid: %s\n", *busid ? busid : "(not set)");
- drmFreeBusid(busid);
-}
-
-
-static void getvm(int fd)
-{
- int i;
- const char *typename;
- char flagname[33];
- drm_handle_t offset;
- drmSize size;
- drmMapType type;
- drmMapFlags flags;
- drm_handle_t handle;
- int mtrr;
-
- printf(" VM map information:\n");
- printf(" flags: (R)estricted (r)ead/(w)rite (l)ocked (k)ernel (W)rite-combine (L)ock:\n");
- printf(" slot offset size type flags address mtrr\n");
-
- for (i = 0;
- !drmGetMap(fd, i, &offset, &size, &type, &flags, &handle, &mtrr);
- i++) {
-
- switch (type) {
- case DRM_FRAME_BUFFER: typename = "FB"; break;
- case DRM_REGISTERS: typename = "REG"; break;
- case DRM_SHM: typename = "SHM"; break;
- case DRM_AGP: typename = "AGP"; break;
- case DRM_SCATTER_GATHER: typename = "SG"; break;
- case DRM_CONSISTENT: typename = "CON"; break;
- default: typename = "???"; break;
- }
-
- flagname[0] = (flags & DRM_RESTRICTED) ? 'R' : ' ';
- flagname[1] = (flags & DRM_READ_ONLY) ? 'r' : 'w';
- flagname[2] = (flags & DRM_LOCKED) ? 'l' : ' ';
- flagname[3] = (flags & DRM_KERNEL) ? 'k' : ' ';
- flagname[4] = (flags & DRM_WRITE_COMBINING) ? 'W' : ' ';
- flagname[5] = (flags & DRM_CONTAINS_LOCK) ? 'L' : ' ';
- flagname[6] = '\0';
-
- printf(" %4d 0x%08lx 0x%08lx %3.3s %6.6s 0x%08lx ",
- i, (unsigned long)offset, (unsigned long)size,
- typename, flagname, (unsigned long)handle);
- if (mtrr < 0) printf("none\n");
- else printf("%4d\n", mtrr);
- }
-}
-
-static void getclients(int fd)
-{
- int i;
- int auth;
- int pid;
- int uid;
- unsigned long magic;
- unsigned long iocs;
- char buf[64];
- char cmd[40];
- int procfd;
-
- printf(" DRI client information:\n");
- printf(" a pid uid magic ioctls prog\n");
-
- for (i = 0; !drmGetClient(fd, i, &auth, &pid, &uid, &magic, &iocs); i++) {
- sprintf(buf, "/proc/%d/cmdline", pid);
- memset(cmd, 0, sizeof(cmd));
- if ((procfd = open(buf, O_RDONLY, 0)) >= 0) {
- read(procfd, cmd, sizeof(cmd)-1);
- close(procfd);
- }
- if (*cmd) {
- char *pt;
-
- for (pt = cmd; *pt; pt++) if (!isprint(*pt)) *pt = ' ';
- printf(" %c %5d %5d %10lu %10lu %s\n",
- auth ? 'y' : 'n', pid, uid, magic, iocs, cmd);
- } else {
- printf(" %c %5d %5d %10lu %10lu\n",
- auth ? 'y' : 'n', pid, uid, magic, iocs);
- }
- }
-}
-
-static void printhuman(unsigned long value, const char *name, int mult)
-{
- const char *p;
- double f;
- /* Print width 5 number in width 6 space */
- if (value < 100000) {
- printf(" %5lu", value);
- return;
- }
-
- p = name;
- f = (double)value / (double)mult;
- if (f < 10.0) {
- printf(" %4.2f%c", f, *p);
- return;
- }
-
- p++;
- f = (double)value / (double)mult;
- if (f < 10.0) {
- printf(" %4.2f%c", f, *p);
- return;
- }
-
- p++;
- f = (double)value / (double)mult;
- if (f < 10.0) {
- printf(" %4.2f%c", f, *p);
- return;
- }
-}
-
-static void getstats(int fd, int i)
-{
- drmStatsT prev, curr;
- unsigned j;
- double rate;
-
- printf(" System statistics:\n");
-
- if (drmGetStats(fd, &prev)) return;
- if (!i) {
- for (j = 0; j < prev.count; j++) {
- printf(" ");
- printf(prev.data[j].long_format, prev.data[j].long_name);
- if (prev.data[j].isvalue) printf(" 0x%08lx\n", prev.data[j].value);
- else printf(" %10lu\n", prev.data[j].value);
- }
- return;
- }
-
- printf(" ");
- for (j = 0; j < prev.count; j++)
- if (!prev.data[j].verbose) {
- printf(" ");
- printf(prev.data[j].rate_format, prev.data[j].rate_name);
- }
- printf("\n");
-
- for (;;) {
- sleep(i);
- if (drmGetStats(fd, &curr)) return;
- printf(" ");
- for (j = 0; j < curr.count; j++) {
- if (curr.data[j].verbose) continue;
- if (curr.data[j].isvalue) {
- printf(" %08lx", curr.data[j].value);
- } else {
- rate = (curr.data[j].value - prev.data[j].value) / (double)i;
- printhuman(rate, curr.data[j].mult_names, curr.data[j].mult);
- }
- }
- printf("\n");
- memcpy(&prev, &curr, sizeof(prev));
- }
-
-}
-
-int main(int argc, char **argv)
-{
- int c;
- int mask = 0;
- int minor = 0;
- int interval = 0;
- int fd;
- char buf[64];
- int i;
-
- while ((c = getopt(argc, argv, "avmcsbM:i:")) != EOF)
- switch (c) {
- case 'a': mask = ~0; break;
- case 'v': mask |= DRM_VERSION; break;
- case 'm': mask |= DRM_MEMORY; break;
- case 'c': mask |= DRM_CLIENTS; break;
- case 's': mask |= DRM_STATS; break;
- case 'b': mask |= DRM_BUSID; break;
- case 'i': interval = strtol(optarg, NULL, 0); break;
- case 'M': minor = strtol(optarg, NULL, 0); break;
- default:
- fprintf( stderr, "Usage: dristat [options]\n\n" );
- fprintf( stderr, "Displays DRM information. Use with no arguments to display available cards.\n\n" );
- fprintf( stderr, " -a Show all available information\n" );
- fprintf( stderr, " -b Show DRM bus ID's\n" );
- fprintf( stderr, " -c Display information about DRM clients\n" );
- fprintf( stderr, " -i [interval] Continuously display statistics every [interval] seconds\n" );
- fprintf( stderr, " -v Display DRM module and card version information\n" );
- fprintf( stderr, " -m Display memory use information\n" );
- fprintf( stderr, " -s Display DRM statistics\n" );
- fprintf( stderr, " -M [minor] Select card by minor number\n" );
- return 1;
- }
-
- for (i = 0; i < 16; i++) if (!minor || i == minor) {
- sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, i);
- fd = drmOpenMinor(i, 1, DRM_NODE_PRIMARY);
- if (fd >= 0) {
- printf("%s\n", buf);
- if (mask & DRM_BUSID) getbusid(fd);
- if (mask & DRM_VERSION) getversion(fd);
- if (mask & DRM_MEMORY) getvm(fd);
- if (mask & DRM_CLIENTS) getclients(fd);
- if (mask & DRM_STATS) getstats(fd, interval);
- close(fd);
- }
- }
-
- return 0;
-}
diff --git a/tests/drmtest.c b/tests/drmtest.c
deleted file mode 100644
index 022994a..0000000
--- a/tests/drmtest.c
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright © 2007 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- *
- * Authors:
- * Eric Anholt <er...@an...>
- *
- */
-
-#include <string.h>
-#include <fcntl.h>
-#include <fnmatch.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include "drmtest.h"
-
-#define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE
-#include <libudev.h>
-
-static int is_master(int fd)
-{
- drm_client_t client;
- int ret;
-
- /* Check that we're the only opener and authed. */
- client.idx = 0;
- ret = ioctl(fd, DRM_IOCTL_GET_CLIENT, &client);
- assert (ret == 0);
- if (!client.auth)
- return 0;
- client.idx = 1;
- ret = ioctl(fd, DRM_IOCTL_GET_CLIENT, &client);
- if (ret != -1 || errno != EINVAL)
- return 0;
-
- return 1;
-}
-
-/** Open the first DRM device matching the criteria */
-int drm_open_matching(const char *pci_glob, int flags)
-{
- struct udev *udev;
- struct udev_enumerate *e;
- struct udev_device *device, *parent;
- struct udev_list_entry *entry;
- const char *pci_id, *path;
- const char *usub, *dnode;
- int fd;
-
- udev = udev_new();
- if (udev == NULL) {
- fprintf(stderr, "failed to initialize udev context\n");
- abort();
- }
-
- fd = -1;
- e = udev_enumerate_new(udev);
- udev_enumerate_add_match_subsystem(e, "drm");
- udev_enumerate_scan_devices(e);
- udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
- path = udev_list_entry_get_name(entry);
- device = udev_device_new_from_syspath(udev, path);
- parent = udev_device_get_parent(device);
- usub = udev_device_get_subsystem(parent);
- /* Filter out KMS output devices. */
- if (!usub || (strcmp(usub, "pci") != 0))
- continue;
- pci_id = udev_device_get_property_value(parent, "PCI_ID");
- if (fnmatch(pci_glob, pci_id, 0) != 0)
- continue;
- dnode = udev_device_get_devnode(device);
- if (strstr(dnode, "control"))
- continue;
- fd = open(dnode, O_RDWR);
- if (fd < 0)
- continue;
- if ((flags & DRM_TEST_MASTER) && !is_master(fd)) {
- close(fd);
- fd = -1;
- continue;
- }
-
- break;
- }
- udev_enumerate_unref(e);
- udev_unref(udev);
-
- return fd;
-}
-
-int drm_open_any(void)
-{
- int fd = drm_open_matching("*:*", 0);
-
- if (fd < 0) {
- fprintf(stderr, "failed to open any drm device\n");
- exit(0);
- }
-
- return fd;
-}
-
-/**
- * Open the first DRM device we can find where we end up being the master.
- */
-int drm_open_any_master(void)
-{
- int fd = drm_open_matching("*:*", DRM_TEST_MASTER);
-
- if (fd < 0) {
- fprintf(stderr, "failed to open any drm device\n");
- exit(0);
- }
-
- return fd;
-
-}
diff --git a/tests/drmtest.h b/tests/drmtest.h
deleted file mode 100644
index 55bb446..0000000
--- a/tests/drmtest.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright © 2007 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- *
- * Authors:
- * Eric Anholt <er...@an...>
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <assert.h>
-#include <errno.h>
-
-#include "xf86drm.h"
-
-#define DRM_TEST_MASTER 0x01
-
-int drm_open_any(void);
-int drm_open_any_master(void);
-int drm_open_matching(const char *pci_glob, int flags);
diff --git a/tests/getclient.c b/tests/getclient.c
deleted file mode 100644
index 481ce11..0000000
--- a/tests/getclient.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright © 2007 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- *
- * Authors:
- * Eric Anholt <er...@an...>
- *
- */
-
-#include <limits.h>
-#include <sys/ioctl.h>
-#include "drmtest.h"
-
-/**
- * Checks DRM_IOCTL_GET_CLIENT.
- */
-int main(int argc, char **argv)
-{
- int fd, ret;
- drm_client_t client;
-
- fd = drm_open_any();
-
- /* Look for client index 0. This should exist whether we're operating
- * on an otherwise unused drm device, or the X Server is running on
- * the device.
- */
- client.idx = 0;
- ret = ioctl(fd, DRM_IOCTL_GET_CLIENT, &client);
- assert(ret == 0);
-
- /* Look for some absurd client index and make sure it's invalid.
- * The DRM drivers currently always return data, so the user has
- * no real way to detect when the list has terminated. That's bad,
- * and this test is XFAIL as a result.
- */
- client.idx = 0x7fffffff;
- ret = ioctl(fd, DRM_IOCTL_GET_CLIENT, &client);
- assert(ret == -1 && errno == EINVAL);
-
- close(fd);
- return 0;
-}
diff --git a/tests/getstats.c b/tests/getstats.c
deleted file mode 100644
index 8a7d299..0000000
--- a/tests/getstats.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright © 2007 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- *
- * Authors:
- * Eric Anholt <er...@an...>
- *
- */
-
-#include <limits.h>
-#include <sys/ioctl.h>
-#include "drmtest.h"
-
-/**
- * Checks DRM_IOCTL_GET_STATS.
- *
- * I don't care too much about the actual contents, just that the kernel
- * doesn't crash.
- */
-int main(int argc, char **argv)
-{
- int fd, ret;
- drm_stats_t stats;
-
- fd = drm_open_any();
-
- ret = ioctl(fd, DRM_IOCTL_GET_STATS, &stats);
- assert(ret == 0);
-
- close(fd);
- return 0;
-}
diff --git a/tests/getversion.c b/tests/getversion.c
deleted file mode 100644
index bcec469..0000000
--- a/tests/getversion.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright © 2007 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- *
- * Authors:
- * Eric Anholt <er...@an...>
- *
- */
-
-#include <string.h>
-#include "drmtest.h"
-
-/**
- * Checks DRM_IOCTL_GET_VERSION and libdrm's drmGetVersion() interface to it.
- */
-int main(int argc, char **argv)
-{
- int fd;
- drmVersionPtr v;
-
- fd = drm_open_any();
- v = drmGetVersion(fd);
- assert(strlen(v->name) != 0);
- assert(strlen(v->date) != 0);
- assert(strlen(v->desc) != 0);
- if (strcmp(v->name, "i915") == 0)
- assert(v->version_major >= 1);
- drmFreeVersion(v);
- close(fd);
- return 0;
-}
diff --git a/tests/lock.c b/tests/lock.c
deleted file mode 100644
index 365681b..0000000
--- a/tests/lock.c
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * Copyright © 2007 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- *
- * Authors:
- * Eric Anholt <er...@an...>
- *
- */
-
-/** @file lock.c
- * Tests various potential failures of the DRM locking mechanisms
- */
-
-#include <limits.h>
-#include <sys/ioctl.h>
-#include "drmtest.h"
-
-enum auth_event {
- SERVER_READY,
- CLIENT_MAGIC,
- SERVER_LOCKED,
- CLIENT_LOCKED,
-};
-
-int commfd[2];
-unsigned int lock1 = 0x00001111;
-unsigned int lock2 = 0x00002222;
-
-/* return time in milliseconds */
-static unsigned int
-get_millis()
-{
- struct timeval tv;
-
- gettimeofday(&tv, NULL);
- return tv.tv_sec * 1000 + tv.tv_usec / 1000;
-}
-
-static void
-wait_event(int pipe, enum auth_event expected_event)
-{
- int ret;
- enum auth_event event;
- unsigned char in;
-
- ret = read(commfd[pipe], &in, 1);
- if (ret == -1)
- err(1, "read error");
- event = in;
-
- if (event != expected_event)
- errx(1, "unexpected event: %d\n", event);
-}
-
-static void
-send_event(int pipe, enum auth_event send_event)
-{
- int ret;
- unsigned char event;
-
- event = send_event;
- ret = write(commfd[pipe], &event, 1);
- if (ret == -1)
- err(1, "failed to send event %d", event);
-}
-
-static void
-client_auth(int drmfd)
-{
- struct drm_auth auth;
- int ret;
-
- /* Get a client magic number and pass it to the master for auth. */
- ret = ioctl(drmfd, DRM_IOCTL_GET_MAGIC, &auth);
- if (ret == -1)
- err(1, "Couldn't get client magic");
- send_event(0, CLIENT_MAGIC);
- ret = write(commfd[0], &auth.magic, sizeof(auth.magic));
- if (ret == -1)
- err(1, "Couldn't write auth data");
-}
-
-static void
-server_auth(int drmfd)
-{
- struct drm_auth auth;
- int ret;
-
- send_event(1, SERVER_READY);
- wait_event(1, CLIENT_MAGIC);
- ret = read(commfd[1], &auth.magic, sizeof(auth.magic));
- if (ret == -1)
- err(1, "Failure to read client magic");
-
- ret = ioctl(drmfd, DRM_IOCTL_AUTH_MAGIC, &auth);
- if (ret == -1)
- err(1, "Failure to authenticate client magic\n");
-}
-
-/** Tests that locking is successful in normal conditions */
-static void
-test_lock_unlock(int drmfd)
-{
- int ret;
-
- ret = drmGetLock(drmfd, lock1, 0);
- if (ret != 0)
- err(1, "Locking failed");
- ret = drmUnlock(drmfd, lock1);
- if (ret != 0)
- err(1, "Unlocking failed");
-}
-
-/** Tests that unlocking the lock while it's not held works correctly */
-static void
-test_unlock_unlocked(int drmfd)
-{
- int ret;
-
- ret = drmUnlock(drmfd, lock1);
- if (ret == 0)
- err(1, "Unlocking unlocked lock succeeded");
-}
-
-/** Tests that unlocking a lock held by another context fails appropriately */
-static void
-test_unlock_unowned(int drmfd)
-{
- int ret;
-
- ret = drmGetLock(drmfd, lock1, 0);
- assert(ret == 0);
- ret = drmUnlock(drmfd, lock2);
- if (ret == 0)
- errx(1, "Unlocking other context's lock succeeded");
- ret = drmUnlock(drmfd, lock1);
- assert(ret == 0);
-}
-
-/**
- * Tests that an open/close by the same process doesn't result in the lock
- * being dropped.
- */
-static void test_open_close_locked(drmfd)
-{
- int ret, tempfd;
-
- ret = drmGetLock(drmfd, lock1, 0);
- assert(ret == 0);
- /* XXX: Need to make sure that this is the same device as drmfd */
- tempfd = drm_open_any();
- close(tempfd);
- ret = drmUnlock(drmfd, lock1);
- if (ret != 0)
- errx(1, "lock lost during open/close by same pid");
-}
-
-static void client()
-{
- int drmfd, ret;
- unsigned int time;
-
- wait_event(0, SERVER_READY);
-
- /* XXX: Should make sure we open the same DRM as the master */
- drmfd = drm_open_any();
-
- client_auth(drmfd);
-
- /* Wait for the server to grab the lock, then grab it ourselves (to
- * contest it). Hopefully we hit it within the window of when the
- * server locks.
- */
- wait_event(0, SERVER_LOCKED);
- ret = drmGetLock(drmfd, lock2, 0);
- time = get_millis();
- if (ret != 0)
- err(1, "Failed to get lock on client\n");
- drmUnlock(drmfd, lock2);
-
- /* Tell the server that our locking completed, and when it did */
- send_event(0, CLIENT_LOCKED);
- ret = write(commfd[0], &time, sizeof(time));
-
- close(drmfd);
- exit(0);
-}
-
-static void server()
-{
- int drmfd, tempfd, ret;
- unsigned int client_time, unlock_time;
-
- drmfd = drm_open_any_master();
-
- test_lock_unlock(drmfd);
- test_unlock_unlocked(drmfd);
- test_unlock_unowned(drmfd);
- test_open_close_locked(drmfd);
-
- /* Perform the authentication sequence with the client. */
- server_auth(drmfd);
-
- /* Now, test that the client attempting to lock while the server
- * holds the lock works correctly.
- */
- ret = drmGetLock(drmfd, lock1, 0);
- assert(ret == 0);
- send_event(1, SERVER_LOCKED);
- /* Wait a while for the client to do its thing */
- sleep(1);
- ret = drmUnlock(drmfd, lock1);
- assert(ret == 0);
- unlock_time = get_millis();
-
- wait_event(1, CLIENT_LOCKED);
- ret = read(commfd[1], &client_time, sizeof(client_time));
- if (ret == -1)
- err(1, "Failure to read client magic");
-
- if (client_time < unlock_time)
- errx(1, "Client took lock before server released it");
-
- close(drmfd);
-}
-
-int main(int argc, char **argv)
-{
- int ret;
-
-
- ret = pipe(commfd);
- if (ret == -1)
- err(1, "Couldn't create pipe");
-
- ret = fork();
- if (ret == -1)
- err(1, "failure to fork client");
- if (ret == 0)
- client();
- else
- server();
-
- return 0;
-}
-
diff --git a/tests/name_from_fd.c b/tests/name_from_fd.c
deleted file mode 100644
index 5264681..0000000
--- a/tests/name_from_fd.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright © 2009 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- *
- * Authors:
- * Kristian Høgsberg <kr...@bi...>
- *
- */
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <string.h>
-#include "drmtest.h"
-
-/**
- * Checks drmGetDeviceNameFromFd
- *
- * This tests that we can get the actual version out, and that setting invalid
- * major/minor numbers fails appropriately. It does not check the actual
- * behavior differenses resulting from an increased DI version.
- */
-int main(int argc, char **argv)
-{
- int fd;
- const char *name = "/dev/dri/card0";
- char *v;
-
- fd = open("/dev/dri/card0", O_RDWR);
- if (fd < 0)
- return 0;
-
- v = drmGetDeviceNameFromFd(fd);
- close(fd);
-
- assert(strcmp(name, v) == 0);
- drmFree(v);
-
- return 0;
-}
diff --git a/tests/openclose.c b/tests/openclose.c
deleted file mode 100644
index 946a445..0000000
--- a/tests/openclose.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright © 2007 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- *
- * Authors:
- * Eric Anholt <er...@an...>
- *
- */
-
-#include "drmtest.h"
-
-int main(int argc, char **argv)
-{
- int fd;
-
- fd = drm_open_any();
- close(fd);
- return 0;
-}
diff --git a/tests/setversion.c b/tests/setversion.c
deleted file mode 100644
index 2f7b529..0000000
--- a/tests/setversion.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright © 2007 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- *
- * Authors:
- * Eric Anholt <er...@an...>
- *
- */
-
-#include <limits.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include "drmtest.h"
-
-/**
- * Checks DRM_IOCTL_SET_VERSION.
- *
- * This tests that we can get the actual version out, and that setting invalid
- * major/minor numbers fails appropriately. It does not check the actual
- * behavior differenses resulting from an increased DI version.
- */
-int main(int argc, char **argv)
-{
- int fd, ret;
- drm_set_version_t sv, version;
-
- if (getuid() != 0) {
- fprintf(stderr, "setversion test requires root, skipping\n");
- return 0;
- }
-
- fd = drm_open_any_master();
-
- /* First, check that we can get the DD/DI versions. */
- memset(&version, 0, sizeof(version));
- version.drm_di_major = -1;
- version.drm_di_minor = -1;
- version.drm_dd_major = -1;
- version.drm_dd_minor = -1;
- ret = ioctl(fd, DRM_IOCTL_SET_VERSION, &version);
- assert(ret == 0);
- assert(version.drm_di_major != -1);
- assert(version.drm_di_minor != -1);
- assert(version.drm_dd_major != -1);
- assert(version.drm_dd_minor != -1);
-
- /* Check that an invalid DI major fails */
- sv = version;
- sv.drm_di_major++;
- ret = ioctl(fd, DRM_IOCTL_SET_VERSION, &sv);
- assert(ret == -1 && errno == EINVAL);
-
- /* Check that an invalid DI minor fails */
- sv = version;
- sv.drm_di_major++;
- ret = ioctl(fd, DRM_IOCTL_SET_VERSION, &sv);
- assert(ret == -1 && errno == EINVAL);
-
- /* Check that an invalid DD major fails */
- sv = version;
- sv.drm_dd_major++;
- ret = ioctl(fd, DRM_IOCTL_SET_VERSION, &sv);
- assert(ret == -1 && errno == EINVAL);
-
- /* Check that an invalid DD minor fails */
- sv = version;
- sv.drm_dd_minor++;
- ret = ioctl(fd, DRM_IOCTL_SET_VERSION, &sv);
- assert(ret == -1 && errno == EINVAL);
-
- close(fd);
- return 0;
-}
diff --git a/tests/updatedraw.c b/tests/updatedraw.c
deleted file mode 100644
index d01fa96..0000000
--- a/tests/updatedraw.c
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Copyright © 2007 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- *
- * Authors:
- * Eric Anholt <er...@an...>
- *
- */
-
-#include <sys/ioctl.h>
-#include "drmtest.h"
-
-static void
-set_draw_cliprects_empty(int fd, int drawable)
-{
- int ret;
- struct drm_update_draw update;
-
- update.handle = drawable;
- update.type = DRM_DRAWABLE_CLIPRECTS;
- update.num = 0;
- update.data = 0;
-
- ret = ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update);
- assert(ret == 0);
-}
-
-static void
-set_draw_cliprects_empty_fail(int fd, int drawable)
-{
- int ret;
- struct drm_update_draw update;
-
- update.handle = drawable;
- update.type = DRM_DRAWABLE_CLIPRECTS;
- update.num = 0;
- update.data = 0;
-
- ret = ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update);
- assert(ret == -1 && errno == EINVAL);
-}
-
-static void
-set_draw_cliprects_2(int fd, int drawable)
-{
- int ret;
- struct drm_update_draw update;
- drm_clip_rect_t rects[2];
-
- rects[0].x1 = 0;
- rects[0].y1 = 0;
- rects[0].x2 = 10;
- rects[0].y2 = 10;
-
- rects[1].x1 = 10;
- rects[1].y1 = 10;
- rects[1].x2 = 20;
- rects[1].y2 = 20;
-
- update.handle = drawable;
- update.type = DRM_DRAWABLE_CLIPRECTS;
- update.num = 2;
- update.data = (unsigned long long)(uintptr_t)&rects;
-
- ret = ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update);
- assert(ret == 0);
-}
-
-static int add_drawable(int fd)
-{
- drm_draw_t drawarg;
- int ret;
-
- /* Create a drawable.
- * IOCTL_ADD_DRAW is RDWR, though it should really just be RD
- */
- drawarg.handle = 0;
- ret = ioctl(fd, DRM_IOCTL_ADD_DRAW, &drawarg);
- assert(ret == 0);
- return drawarg.handle;
-}
-
-static int rm_drawable(int fd, int drawable, int fail)
-{
- drm_draw_t drawarg;
- int ret;
-
- /* Create a drawable.
- * IOCTL_ADD_DRAW is RDWR, though it should really just be RD
- */
- drawarg.handle = drawable;
- ret = ioctl(fd, DRM_IOCTL_RM_DRAW, &drawarg);
- if (!fail)
- assert(ret == 0);
- else
- assert(ret == -1 && errno == EINVAL);
-
- return drawarg.handle;
-}
-
-/**
- * Tests drawable management: adding, removing, and updating the cliprects of
- * drawables.
- */
-int main(int argc, char **argv)
-{
- int fd, d1, d2;
-
- if (getuid() != 0) {
- fprintf(stderr, "updatedraw test requires root, skipping\n");
- return 0;
- }
-
- fd = drm_open_any_master();
-
- d1 = add_drawable(fd);
- d2 = add_drawable(fd);
- /* Do a series of cliprect updates */
- set_draw_cliprects_empty(fd, d1);
- set_draw_cliprects_empty(fd, d2);
- set_draw_cliprects_2(fd, d1);
- set_draw_cliprects_empty(fd, d1);
-
- /* Remove our drawables */
- rm_drawable(fd, d1, 0);
- rm_drawable(fd, d2, 0);
-
- /* Check that removing an unknown drawable returns error */
- rm_drawable(fd, 0x7fffffff, 1);
-
- /* Attempt to set cliprects on a nonexistent drawable */
- set_draw_cliprects_empty_fail(fd, d1);
-
- close(fd);
- return 0;
-}
commit b305238ceb5092dd9d78c06e4dbe99a1e0287ba6
Author: Emil Velikov <emi...@co...>
Date: Wed Nov 30 19:13:04 2016 +0000
tests/drmdevice: use drmGetDevice[s]2
Pass along DRM_DEVICE_GET_PCI_REVISION only when the individual nodes
are opened and update the printed messages accordingly.
v2: Attribute for the flag rename, call drmGetDevices2 w/o the flag.
v3: Keep drmParsePciDeviceInfo() hunk in previous patch.
Signed-off-by: Emil Velikov <emi...@co...>
Reviewed-by: Michel Dänzer <mic...@am...>
diff --git a/tests/drmdevice.c b/tests/drmdevice.c
index 72e7066..8c4f091 100644
--- a/tests/drmdevice.c
+++ b/tests/drmdevice.c
@@ -24,6 +24,7 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -32,7 +33,7 @@
static void
-print_device_info(drmDevicePtr device, int i)
+print_device_info(drmDevicePtr device, int i, bool print_revision)
{
printf("device[%i]\n", i);
printf("\tavailable_nodes %04x\n", device->available_nodes);
@@ -56,7 +57,11 @@ print_device_info(drmDevicePtr device, int i)
printf("\t\t\tdevice_id\t%04x\n", device->deviceinfo.pci->device_id);
printf("\t\t\tsubvendor_id\t%04x\n", device->deviceinfo.pci->subvendor_id);
printf("\t\t\tsubdevice_id\t%04x\n", device->deviceinfo.pci->subdevice_id);
- printf("\t\t\trevision_id\t%02x\n", device->deviceinfo.pci->revision_id);
+ if (print_revision)
+ printf("\t\t\trevision_id\t%02x\n", device->deviceinfo.pci->revision_id);
+ else
+ printf("\t\t\trevision_id\tIGNORED\n");
+
} else {
printf("Unknown/unhandled bustype\n");
}
@@ -70,10 +75,10 @@ main(void)
drmDevicePtr device;
int fd, ret, max_devices;
- max_devices = drmGetDevices(NULL, 0);
+ max_devices = drmGetDevices2(0, NULL, 0);
if (max_devices <= 0) {
- printf("drmGetDevices() has returned %d\n", max_devices);
+ printf("drmGetDevices2() has returned %d\n", max_devices);
return -1;
}
@@ -83,15 +88,15 @@ main(void)
return -1;
}
- ret = drmGetDevices(devices, max_devices);
+ ret = drmGetDevices2(0, devices, max_devices);
if (ret < 0) {
- printf("drmGetDevices() returned an error %d\n", ret);
+ printf("drmGetDevices2() returned an error %d\n", ret);
free(devices);
return -1;
}
for (int i = 0; i < ret; i++) {
- print_device_info(devices[i], i);
+ print_device_info(devices[i], i, false);
for (int j = 0; j < DRM_NODE_MAX; j++) {
if (devices[i]->available_nodes & 1 << j) {
@@ -102,8 +107,8 @@ main(void)
continue;
}
- if (drmGetDevice(fd, &device) == 0) {
- print_device_info(device, i);
+ if (drmGetDevice2(fd, DRM_DEVICE_GET_PCI_REVISION, &device) == 0) {
+ print_device_info(device, i, true);
drmFreeDevice(&device);
}
close(fd);
commit 11687bf4180f7e21045ed9c4730533c40fe01ea5
Author: Emil Velikov <emi...@co...>
Date: Wed Nov 30 17:24:21 2016 +0000
xf86drm: introduce drmGetDevice[s]2
Relative to the original version, here one can provide a flags bitmask.
Currently only DRM_DEVICE_IGNORE_PCI_REVISION is supported.
Implementation detail:
If it's set, we will only parse the separate sysfs files and we won't
touch the config one. The latter awakes the device (causing delays)
which is the core reason why this API was introduced.
v2:
- Initialize revision to 0xff if it's unread.
- Change DRM_DEVICE_IGNORE_PCI_REVISION to D...
[truncated message content] |