@@ -74,6 +74,7 @@ tests/gem_readwrite
tests/openclose
tests/setversion
tests/updatedraw
+tests/same_device_but_type
tests/modeprint/modeprint
tests/modetest/modetest
tests/kmstest/kmstest
@@ -46,6 +46,7 @@ TESTS = \
setversion \
updatedraw \
name_from_fd \
+ same_device_but_type \
$(NULL)
SUBDIRS += vbltest $(NULL)
new file mode 100644
@@ -0,0 +1,52 @@
+/*
+ * Copyright © 2012
+ *
+ * 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:
+ * Martin Peres <martin.peres@labri.fr>
+ *
+ */
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <limits.h>
+#include "drmtest.h"
+
+/**
+ * Checks drmGetSameDeviceButType
+ */
+int main(int argc, char **argv)
+{
+ int fd, ret;
+ drm_set_version_t sv, version;
+ const char *name = "/dev/dri/card0";
+ char *render;
+ int i;
+
+ render = drmGetSameDeviceButType(name, DRM_NODE_RENDER);
+ assert(strcmp(render, name) == 0);
+ drmFree(render);
+
+ render = drmGetSameDeviceButType("/no_device", DRM_NODE_RENDER);
+ assert(render == NULL);
+
+ return 0;
+}
@@ -2602,6 +2602,50 @@ char *drmGetDeviceNameFromFd(int fd)
return NULL;
}
+/**
+ * Generate the path to a different type (render node, control node, etc...)
+ * but for the same actual drm device.
+ *
+ * \param device a path to an existing drm device type.
+ * \param type the new type that should be returned.
+ *
+ * \return the path to the same drm device but to a different type if success.
+ * NULL otherwise.
+ */
+char *drmGetSameDeviceButType(const char *device, int type)
+{
+ char base_path[64], name[64], *path, *device_name;
+ struct stat sbuf;
+ int i;
+
+ /* get the device name (ie /card0) */
+ device_name=strrchr(device, '/');
+ if (!device_name)
+ return NULL;
+
+ /* get the device's drm folder (ie /sys/class/drm/card0/device/drm */
+ snprintf(base_path, sizeof(base_path), "/sys/class/drm/%s/device/drm",
+ device_name + 1);
+
+ /* search for the type in the base path */
+ device_name = NULL;
+ for (i = 0; i < DRM_MAX_MINOR; i++) {
+ drmDevicePath(name, sizeof(name), base_path, type, i);
+ if (stat(name, &sbuf) == 0) {
+ device_name = strrchr(name, '/');
+ break;
+ }
+ }
+ if (!device_name)
+ return NULL;
+
+ /* create a more appropriate path for the device (/dev/dri/card0) */
+ path = malloc(64);
+ snprintf(path, 64, "%s/%s", DRM_DIR_NAME, device_name + 1);
+
+ return path;
+}
+
int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd)
{
struct drm_prime_handle args;
@@ -733,6 +733,7 @@ typedef struct _drmEventContext {
extern int drmHandleEvent(int fd, drmEventContextPtr evctx);
extern char *drmGetDeviceNameFromFd(int fd);
+extern char *drmGetSameDeviceButType(const char *device, int type);
extern int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd);
extern int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle);