From 132ba667f4a88bb182e2d2abc7c4e60699398380 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 28 Feb 2008 12:59:39 +1000 Subject: drm: add a check for if modesetting is supported. 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 | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'libdrm/xf86drmMode.c') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 52fef81b..717e1fe2 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -41,6 +41,8 @@ #include "xf86drm.h" #include #include +#include +#include #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; + +} -- cgit v1.2.3