From ae4db652377d8add444fa2d9dfe5a398d7f64a80 Mon Sep 17 00:00:00 2001 From: kostikbel Date: Thu, 21 Feb 2013 20:02:00 +0000 Subject: [PATCH 2/3] =?UTF-8?q?drm:=20Add=20support=20for=20FreeBSD=E2=80=99?= =?UTF-8?q?s=20libkms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch from http://people.freebsd.org/~kib/drm/libdrm.2.patch --- configure.ac | 1 + xf86drmMode.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) Index: libdrm-bisect/configure.ac =================================================================== --- libdrm-bisect.orig/configure.ac 2013-09-19 13:28:24.000000000 +0200 +++ libdrm-bisect/configure.ac 2013-09-19 13:28:24.744937559 +0200 @@ -185,6 +185,7 @@ if test "x$LIBKMS" = xauto ; then case $host_os in linux*) LIBKMS="yes" ;; + *freebsd*) LIBKMS="yes" ;; *) LIBKMS="no" ;; esac fi Index: libdrm-bisect/xf86drmMode.c =================================================================== --- libdrm-bisect.orig/xf86drmMode.c 2013-09-19 13:28:24.000000000 +0200 +++ libdrm-bisect/xf86drmMode.c 2013-09-19 13:32:43.085063015 +0200 @@ -704,7 +704,7 @@ */ int drmCheckModesettingSupported(const char *busid) { -#ifdef __linux__ +#if defined (__linux__) char pci_dev_dir[1024]; int domain, bus, dev, func; DIR *sysdir; @@ -754,6 +754,37 @@ closedir(sysdir); if (found) return 0; +#elif defined (__FreeBSD__) || defined(__FreeBSD_kernel__) + char kbusid[1024], sbusid[1024]; + char oid[128]; + int domain, bus, dev, func; + int i, modesetting, ret; + size_t len; + + ret = sscanf(busid, "pci:%04x:%02x:%02x.%d", &domain, &bus, &dev, &func); + if (ret != 4) + return -EINVAL; + snprintf(kbusid, sizeof(kbusid), "pci:%04x:%02x:%02x.%d", domain, bus, dev, func); + + /* How many GPUs do we expect in the machine? */ + for (i = 0; i < 16; i++) { + snprintf(oid, sizeof(oid), "hw.dri.%d.busid", i); + len = sizeof(sbusid); + ret = sysctlbyname(oid, sbusid, &len, NULL, 0); + if (ret == -1) { + if (errno == ENOENT) + continue; + return -EINVAL; + } + if (strcmp(sbusid, kbusid) != 0) + continue; + snprintf(oid, sizeof(oid), "hw.dri.%d.modesetting", i); + len = sizeof(modesetting); + ret = sysctlbyname(oid, &modesetting, &len, NULL, 0); + if (ret == -1 || len != sizeof(modesetting)) + return -EINVAL; + return (modesetting ? 0 : -ENOSYS); + } #endif return -ENOSYS;