drm: add a check for if modesetting is supported.
authorDave Airlie <airlied@redhat.com>
Thu, 28 Feb 2008 02:59:39 +0000 (12:59 +1000)
committerDave Airlie <airlied@redhat.com>
Thu, 28 Feb 2008 02:59:39 +0000 (12:59 +1000)
This is Linux only code, it just uses sysfs to see if a control
device has been registered on the requested PCI ID

libdrm/xf86drmMode.c
libdrm/xf86drmMode.h

index 52fef81..717e1fe 100644 (file)
@@ -41,6 +41,8 @@
 #include "xf86drm.h"
 #include <drm.h>
 #include <string.h>
+#include <dirent.h>
+#include <errno.h>
 
 #define U642VOID(x) ((void *)(unsigned long)(x))
 #define VOID2U64(x) ((uint64_t)(unsigned long)(x))
@@ -571,3 +573,49 @@ int drmModeOutputSetProperty(int fd, uint32_t output_id, uint32_t property_id,
 
        return 0;
 }
+
+/*
+ * checks if a modesetting capable driver has attached to the pci id
+ * returns 0 if modesetting supported.
+ *  -EINVAL or invalid bus id
+ *  -ENOSYS if no modesetting support
+*/
+int drmCheckModesettingSupported(const char *busid)
+{
+#ifdef __linux__
+       char pci_dev_dir[1024];
+       char *bus_id_path;
+       char *bus_type;
+       int domain, bus, dev, func;
+       DIR *sysdir;
+       struct dirent *dent;
+       int found = 0, ret;
+
+       ret = sscanf(busid, "pci:%04x:%02x:%02x.%d", &domain, &bus, &dev, &func);
+       if (ret != 4)
+               return -EINVAL;
+
+       sprintf(pci_dev_dir, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/",
+               domain, bus, dev, func);
+
+       sysdir = opendir(pci_dev_dir);
+       if (!sysdir)
+               return -EINVAL;
+
+       dent = readdir(sysdir);
+       while (dent) {
+               if (!strncmp(dent->d_name, "drm:controlD", 12)) {
+                       found = 1;
+                       break;
+               }
+               
+               dent = readdir(sysdir);
+       }
+                       
+       closedir(sysdir);
+       if (found)
+               return 0;
+#endif
+       return -ENOSYS;
+
+}
index 7cc3cec..71e779d 100644 (file)
@@ -243,3 +243,4 @@ extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id);
 extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr);
 extern int drmModeOutputSetProperty(int fd, uint32_t output_id, uint32_t property_id,
                                    uint64_t value);
+extern int drmCheckModesettingSupported(const char *busid);