pkgsrc-WIP-changes archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
libdrm-dfbsd: Replace libdrm Net/Free/DragonFly BSD xf86drm.c
Module Name: pkgsrc-wip
Committed By: David Shao <davshao%gmail.com@localhost>
Pushed By: dshao
Date: Tue Jan 17 00:25:40 2017 -0800
Changeset: f753fd37c9913ed9ee15956f10f187b33e9df0f3
Modified Files:
Makefile
Added Files:
libdrm-dfbsd/DESCR
libdrm-dfbsd/Makefile
libdrm-dfbsd/PLIST
libdrm-dfbsd/PLIST.DragonFly
libdrm-dfbsd/PLIST.FreeBSD
libdrm-dfbsd/PLIST.Linux
libdrm-dfbsd/TODO
libdrm-dfbsd/buildlink3.mk
libdrm-dfbsd/builtin.mk
libdrm-dfbsd/distinfo
libdrm-dfbsd/patches/patch-ab
libdrm-dfbsd/patches/patch-ac
libdrm-dfbsd/patches/patch-include_drm_drm.h
libdrm-dfbsd/patches/patch-libkms_vmwgfx.c
libdrm-dfbsd/patches/patch-radeon_radeon__bo__gem.c
libdrm-dfbsd/patches/patch-radeon_radeon__cs__gem.c
libdrm-dfbsd/patches/patch-xf86drmMode.c
libdrm-dfbsd/patches/patch-xf86drmMode.h
Log Message:
libdrm-dfbsd: Replace libdrm Net/Free/DragonFly BSD xf86drm.c
Implements changes to libdrm to work with mesa 13.0.2 discussed in
pkg/51795
(x11/libdrm update xf86drm.c for mesa 13.0.2 needs negotiation)
On NetBSD modular xorg requires kernel changes discussed in
kernel/51786
(mesa 13.0.2 libdrm 2.4.74 Radeon needs kernel support, new ioctl or sysctl)
To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=f753fd37c9913ed9ee15956f10f187b33e9df0f3
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
diffstat:
Makefile | 1 +
libdrm-dfbsd/DESCR | 3 +
libdrm-dfbsd/Makefile | 55 ++
libdrm-dfbsd/PLIST | 60 ++
libdrm-dfbsd/PLIST.DragonFly | 4 +
libdrm-dfbsd/PLIST.FreeBSD | 4 +
libdrm-dfbsd/PLIST.Linux | 4 +
libdrm-dfbsd/TODO | 5 +
libdrm-dfbsd/buildlink3.mk | 13 +
libdrm-dfbsd/builtin.mk | 8 +
libdrm-dfbsd/distinfo | 14 +
libdrm-dfbsd/patches/patch-ab | 628 +++++++++++++++++++++
libdrm-dfbsd/patches/patch-ac | 40 ++
libdrm-dfbsd/patches/patch-include_drm_drm.h | 18 +
libdrm-dfbsd/patches/patch-libkms_vmwgfx.c | 17 +
.../patches/patch-radeon_radeon__bo__gem.c | 27 +
.../patches/patch-radeon_radeon__cs__gem.c | 16 +
libdrm-dfbsd/patches/patch-xf86drmMode.c | 69 +++
libdrm-dfbsd/patches/patch-xf86drmMode.h | 13 +
19 files changed, 999 insertions(+)
diffs:
diff --git a/Makefile b/Makefile
index cca78e9..07e71a2 100644
--- a/Makefile
+++ b/Makefile
@@ -1569,6 +1569,7 @@ SUBDIR+= libdisasm
SUBDIR+= libdjconsole
SUBDIR+= libdmx
SUBDIR+= libdoozer
+SUBDIR+= libdrm-dfbsd
SUBDIR+= libdssialsacompat
SUBDIR+= libecc
SUBDIR+= libee
diff --git a/libdrm-dfbsd/DESCR b/libdrm-dfbsd/DESCR
new file mode 100644
index 0000000..c8be56c
--- /dev/null
+++ b/libdrm-dfbsd/DESCR
@@ -0,0 +1,3 @@
+This package provides a library which offers a userspace interface
+to kernel DRM (Direct Rendering Manager) services for access to
+graphics hardware.
diff --git a/libdrm-dfbsd/Makefile b/libdrm-dfbsd/Makefile
new file mode 100644
index 0000000..b8e7913
--- /dev/null
+++ b/libdrm-dfbsd/Makefile
@@ -0,0 +1,55 @@
+# $NetBSD: Makefile,v 1.67 2016/11/30 12:37:40 wiz Exp $
+
+DISTNAME= libdrm-2.4.74
+CATEGORIES= x11 graphics
+MASTER_SITES= http://dri.freedesktop.org/libdrm/
+EXTRACT_SUFX= .tar.bz2
+
+MAINTAINER= joerg%NetBSD.org@localhost
+HOMEPAGE= http://dri.freedesktop.org/wiki/DRM
+COMMENT= Userspace interface to kernel DRM services
+
+ONLY_FOR_PLATFORM= NetBSD-*-* DragonFly-*-* FreeBSD-*-* OpenBSD-*-* \
+ Linux-*-* SunOS-*-*
+
+USE_PKGLOCALEDIR= yes
+USE_TOOLS+= pkg-config
+USE_LIBTOOL= yes
+PKGCONFIG_OVERRIDE+= libdrm.pc.in
+GNU_CONFIGURE= yes
+
+.include "../../mk/bsd.prefs.mk"
+
+SUBST_CLASSES+= atomic
+SUBST_FILES.atomic= xf86drm.h
+SUBST_MESSAGE.atomic= Configuring xf86drm.h's atomic operations.
+SUBST_STAGE.atomic= pre-configure
+SUBST_VARS.atomic= ATOMIC_OPS_CHECK
+
+ATOMIC_OPS_CHECK= 0
+.if exists(${CROSS_DESTDIR}/usr/include/sys/atomic.h)
+ATOMIC_OPS_CHECK= 1
+.else
+. include "../../devel/libatomic_ops/buildlink3.mk"
+CONFIGURE_ENV+= drm_cv_atomic_primitives=libatomic-ops
+.endif
+
+CONFIGURE_ARGS+= PTHREADSTUBS_CFLAGS=-I${PREFIX}/include \
+ PTHREADSTUBS_LIBS=-L${PREFIX}/lib
+CONFIGURE_ARGS+= --disable-manpages
+CONFIGURE_ARGS+= --disable-valgrind
+
+PLIST_VARS+= intel arm
+.if !empty(MACHINE_ARCH:Mi386) || !empty(MACHINE_ARCH:Mx86_64)
+# libpciaccess is needed to build support for the intel KMS API,
+# libdrm_intel.so.
+.include "../../sysutils/libpciaccess/buildlink3.mk"
+PLIST.intel= yes
+.elif !empty(MACHINE_ARCH:Marm*) || \
+ !empty(MACHINE_ARCH:Mearm*) || \
+ !empty(MACHINE_ARCH:Maarch64)
+PLIST.arm= yes
+#.else
+#CONFIGURE_ARGS+= --disable-intel
+.endif
+.include "../../mk/bsd.pkg.mk"
diff --git a/libdrm-dfbsd/PLIST b/libdrm-dfbsd/PLIST
new file mode 100644
index 0000000..26c3944
--- /dev/null
+++ b/libdrm-dfbsd/PLIST
@@ -0,0 +1,60 @@
+@comment $NetBSD: PLIST,v 1.19 2016/11/15 10:05:52 wiz Exp $
+${PLIST.arm}include/freedreno/freedreno_drmif.h
+${PLIST.arm}include/freedreno/freedreno_ringbuffer.h
+include/libdrm/amdgpu.h
+include/libdrm/amdgpu_drm.h
+include/libdrm/drm.h
+include/libdrm/drm_fourcc.h
+include/libdrm/drm_mode.h
+include/libdrm/drm_sarea.h
+include/libdrm/i915_drm.h
+${PLIST.intel}include/libdrm/intel_aub.h
+${PLIST.intel}include/libdrm/intel_bufmgr.h
+${PLIST.intel}include/libdrm/intel_debug.h
+include/libdrm/mach64_drm.h
+include/libdrm/mga_drm.h
+include/libdrm/nouveau/nouveau.h
+include/libdrm/nouveau/nvif/cl0080.h
+include/libdrm/nouveau/nvif/cl9097.h
+include/libdrm/nouveau/nvif/class.h
+include/libdrm/nouveau/nvif/if0002.h
+include/libdrm/nouveau/nvif/if0003.h
+include/libdrm/nouveau/nvif/ioctl.h
+include/libdrm/nouveau/nvif/unpack.h
+include/libdrm/nouveau_drm.h
+include/libdrm/qxl_drm.h
+include/libdrm/r128_drm.h
+include/libdrm/r600_pci_ids.h
+include/libdrm/radeon_bo.h
+include/libdrm/radeon_bo_gem.h
+include/libdrm/radeon_bo_int.h
+include/libdrm/radeon_cs.h
+include/libdrm/radeon_cs_gem.h
+include/libdrm/radeon_cs_int.h
+include/libdrm/radeon_drm.h
+include/libdrm/radeon_surface.h
+include/libdrm/savage_drm.h
+include/libdrm/sis_drm.h
+include/libdrm/tegra_drm.h
+include/libdrm/vc4_drm.h
+${PLIST.arm}include/libdrm/vc4_packet.h
+${PLIST.arm}include/libdrm/vc4_qpu_defines.h
+include/libdrm/via_drm.h
+include/libdrm/virtgpu_drm.h
+include/libdrm/vmwgfx_drm.h
+include/libsync.h
+include/xf86drm.h
+include/xf86drmMode.h
+lib/libdrm.la
+lib/libdrm_amdgpu.la
+${PLIST.arm}lib/libdrm_freedreno.la
+${PLIST.intel}lib/libdrm_intel.la
+lib/libdrm_nouveau.la
+lib/libdrm_radeon.la
+lib/pkgconfig/libdrm.pc
+lib/pkgconfig/libdrm_amdgpu.pc
+${PLIST.arm}lib/pkgconfig/libdrm_freedreno.pc
+${PLIST.intel}lib/pkgconfig/libdrm_intel.pc
+lib/pkgconfig/libdrm_nouveau.pc
+lib/pkgconfig/libdrm_radeon.pc
+${PLIST.arm}lib/pkgconfig/libdrm_vc4.pc
diff --git a/libdrm-dfbsd/PLIST.DragonFly b/libdrm-dfbsd/PLIST.DragonFly
new file mode 100644
index 0000000..14df7d9
--- /dev/null
+++ b/libdrm-dfbsd/PLIST.DragonFly
@@ -0,0 +1,4 @@
+@comment $NetBSD: PLIST.DragonFly,v 1.1 2014/06/01 06:37:46 ryoon Exp $
+include/libkms/libkms.h
+lib/libkms.la
+lib/pkgconfig/libkms.pc
diff --git a/libdrm-dfbsd/PLIST.FreeBSD b/libdrm-dfbsd/PLIST.FreeBSD
new file mode 100644
index 0000000..12622ca
--- /dev/null
+++ b/libdrm-dfbsd/PLIST.FreeBSD
@@ -0,0 +1,4 @@
+@comment $NetBSD: PLIST.FreeBSD,v 1.1 2014/04/18 09:43:29 asau Exp $
+include/libkms/libkms.h
+lib/libkms.la
+lib/pkgconfig/libkms.pc
diff --git a/libdrm-dfbsd/PLIST.Linux b/libdrm-dfbsd/PLIST.Linux
new file mode 100644
index 0000000..54ca079
--- /dev/null
+++ b/libdrm-dfbsd/PLIST.Linux
@@ -0,0 +1,4 @@
+@comment $NetBSD: PLIST.Linux,v 1.1 2012/05/14 03:56:58 sbd Exp $
+include/libkms/libkms.h
+lib/libkms.la
+lib/pkgconfig/libkms.pc
diff --git a/libdrm-dfbsd/TODO b/libdrm-dfbsd/TODO
new file mode 100644
index 0000000..a53cda6
--- /dev/null
+++ b/libdrm-dfbsd/TODO
@@ -0,0 +1,5 @@
+Copy port to x11/libdrm, do not install from wip.
+
+Implements changes to libdrm to work with mesa 13.0.2 discussed in
+pkg/51795
+(x11/libdrm update xf86drm.c for mesa 13.0.2 needs negotiation)
diff --git a/libdrm-dfbsd/buildlink3.mk b/libdrm-dfbsd/buildlink3.mk
new file mode 100644
index 0000000..1a1f3f2
--- /dev/null
+++ b/libdrm-dfbsd/buildlink3.mk
@@ -0,0 +1,13 @@
+# $NetBSD: buildlink3.mk,v 1.7 2013/05/16 05:43:14 richard Exp $
+
+BUILDLINK_TREE+= libdrm
+
+.if !defined(LIBDRM_BUILDLINK3_MK)
+LIBDRM_BUILDLINK3_MK:=
+
+BUILDLINK_API_DEPENDS.libdrm+= libdrm>=2.4.15
+BUILDLINK_PKGSRCDIR.libdrm?= ../../x11/libdrm
+BUILDLINK_INCDIRS.libdrm?= include/libdrm
+.endif # LIBDRM_BUILDLINK3_MK
+
+BUILDLINK_TREE+= -libdrm
diff --git a/libdrm-dfbsd/builtin.mk b/libdrm-dfbsd/builtin.mk
new file mode 100644
index 0000000..d9fe1b4
--- /dev/null
+++ b/libdrm-dfbsd/builtin.mk
@@ -0,0 +1,8 @@
+# $NetBSD: builtin.mk,v 1.3 2014/03/10 11:05:53 jperkin Exp $
+
+BUILTIN_PKG:= libdrm
+PKGCONFIG_FILE.libdrm= ${X11BASE}/lib/pkgconfig/libdrm.pc
+PKGCONFIG_FILE.libdrm+= ${X11BASE}/lib${LIBABISUFFIX}/pkgconfig/libdrm.pc
+
+.include "../../mk/buildlink3/pkgconfig-builtin.mk"
+.include "../../mk/x11.builtin.mk"
diff --git a/libdrm-dfbsd/distinfo b/libdrm-dfbsd/distinfo
new file mode 100644
index 0000000..7502588
--- /dev/null
+++ b/libdrm-dfbsd/distinfo
@@ -0,0 +1,14 @@
+$NetBSD: distinfo,v 1.67 2016/11/30 12:37:40 wiz Exp $
+
+SHA1 (libdrm-2.4.74.tar.bz2) = 0d9c02d5d2c6c2fac862cb687bf45bc20d129017
+RMD160 (libdrm-2.4.74.tar.bz2) = 8ebc6e850ab576928c011f7b2d1e67fc42d37209
+SHA512 (libdrm-2.4.74.tar.bz2) = 5b9784bf00bb8179ad59f2fbe5600b51ede3f79dd1ea2cb50485ffaabf74e83d766b2deb6833b99692a303e6780286ecce41b88a2d7c15f9e839bc7182a8879d
+Size (libdrm-2.4.74.tar.bz2) = 781730 bytes
+SHA1 (patch-ab) = 9e9db1e44618f0072e2dfcbb24fb3268c944ecdf
+SHA1 (patch-ac) = 67c998df7dfc0dabc86320ea6d015cede3e464ea
+SHA1 (patch-include_drm_drm.h) = 48a912f40bf2b2a1c23edbe4446fa7869212f17b
+SHA1 (patch-libkms_vmwgfx.c) = d2204c0b79098c6c36b7f282b486c58c6354bd1d
+SHA1 (patch-radeon_radeon__bo__gem.c) = 4924fde172b2a2a713d47bf7b60a6b52851d7a8f
+SHA1 (patch-radeon_radeon__cs__gem.c) = 516b5dd6408c10a4f33f2815b3719e34a16d863a
+SHA1 (patch-xf86drmMode.c) = 508a1e4bae40243c5445ec51084e760279d35ba6
+SHA1 (patch-xf86drmMode.h) = a28b02887389be8670193c119f711901af61a6b2
diff --git a/libdrm-dfbsd/patches/patch-ab b/libdrm-dfbsd/patches/patch-ab
new file mode 100644
index 0000000..1892aff
--- /dev/null
+++ b/libdrm-dfbsd/patches/patch-ab
@@ -0,0 +1,628 @@
+$NetBSD: patch-ab,v 1.8 2015/08/14 17:12:35 wiz Exp $
+
+Patches from OpenBSD xenocara adapted for NetBSD.
+
+Patches from https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=214580
+and code from libdevq 0.0.4.
+
+Tries to account for DragonFly major number not well defined.
+
+Tries to account for FreeBSD device control64D to be ignored.
+
+--- xf86drm.c.orig 2016-11-29 11:15:10.000000000 +0000
++++ xf86drm.c
+@@ -31,6 +31,36 @@
+ * DEALINGS IN THE SOFTWARE.
+ */
+
++/* Port for FreeBSD and DragonFly uses code from libdevq 0.0.4
++ * https://github.com/freebsd/libdevq
++ * with copyright notice:
++ *
++ * Copyright (c) 2014 Jean-Sebastien Pedron <dumbbell%FreeBSD.org@localhost>
++ * Copyright (c) 2016 Koop Mast <kwm%FreeBSD.org@localhost>
++ * All rights reserved.
++ *
++ * Redistribution and use in source and binary forms, with or without
++ * modification, are permitted provided that the following conditions
++ * are met:
++ * 1. Redistributions of source code must retain the above copyright
++ * notice, this list of conditions and the following disclaimer
++ * in this position and unchanged.
++ * 2. Redistributions in binary form must reproduce the above copyright
++ * notice, this list of conditions and the following disclaimer in the
++ * documentation and/or other materials provided with the distribution.
++ *
++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
++ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
++ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
++ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
++ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
++ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
++ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
++ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
++ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
++ */
++
+ #ifdef HAVE_CONFIG_H
+ # include <config.h>
+ #endif
+@@ -72,6 +102,10 @@
+
+ #include "util_math.h"
+
++#if defined(__FreeBSD__) || defined(__DragonFly__)
++#include <sys/sysctl.h>
++#endif
++
+ #ifdef __OpenBSD__
+ #define DRM_PRIMARY_MINOR_NAME "drm"
+ #define DRM_CONTROL_MINOR_NAME "drmC"
+@@ -82,12 +116,22 @@
+ #define DRM_RENDER_MINOR_NAME "renderD"
+ #endif
+
+-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
+-#define DRM_MAJOR 145
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
++#define DRM_MAJOR 0
++#endif
++
++#if defined(__DragonFly__)
++/* DragonFly's devfs dynamically allocates major numbers.
++ * Sometimes the majors do not match,
++ * so keep track of the first major seen.
++ */
++#define DRM_MAJOR 64
++static int maj_firstseen = -1;
+ #endif
+
+ #ifdef __NetBSD__
+-#define DRM_MAJOR 34
++#undef DRM_MAJOR
++#define DRM_MAJOR 180
+ #endif
+
+ #ifdef __OpenBSD__
+@@ -102,6 +146,23 @@
+ #define DRM_MAJOR 226 /* Linux */
+ #endif
+
++#if defined(__NetBSD__)
++/* From OpenBSD xenocara/lib/libdrm/xf86drm.c */
++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(0x0f, struct drm_pciinfo)
++#endif
++
+ #define DRM_MSG_VERBOSITY 3
+
+ #define memclear(s) memset(&s, 0, sizeof(s))
+@@ -532,6 +593,7 @@ static int drmGetMinorType(int minor)
+ }
+ }
+
++#if !defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__NetBSD__)
+ static const char *drmGetMinorName(int type)
+ {
+ switch (type) {
+@@ -545,6 +607,7 @@ static const char *drmGetMinorName(int t
+ return NULL;
+ }
+ }
++#endif
+
+ /**
+ * Open the device by bus ID.
+@@ -2718,7 +2781,11 @@ int drmGetNodeTypeFromFd(int fd)
+ maj = major(sbuf.st_rdev);
+ min = minor(sbuf.st_rdev);
+
++#if defined(__DragonFly__)
++ if (((maj != DRM_MAJOR) && (maj != maj_firstseen)) || (maj < 0) || !S_ISCHR(sbuf.st_mode)) {
++#else
+ if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) {
++#endif
+ errno = EINVAL;
+ return -1;
+ }
+@@ -2817,6 +2884,15 @@ static char *drmGetMinorNameForFD(int fd
+
+ out_close_dir:
+ closedir(sysdir);
++#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__)
++ struct stat buf;
++ char name[64];
++
++ fstat(fd, &buf);
++ snprintf(name, sizeof(name), "/dev/%s",
++ devname(buf.st_rdev, S_IFCHR));
++
++ return strdup(name);
+ #else
+ #warning "Missing implementation of drmGetMinorNameForFD"
+ #endif
+@@ -2854,6 +2930,12 @@ static int drmParseSubsystemType(int maj
+ return DRM_BUS_PCI;
+
+ return -EINVAL;
++#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__)
++ /* XXX: Don't know how to get the subsystem type, hardcode for now.
++ * The code following the call to this function needs depends on
++ * information provided by the /pci subsystem on linux. No replacement
++ * found yet for FreeBSD. */
++ return DRM_BUS_PCI;
+ #else
+ #warning "Missing implementation of drmParseSubsystemType"
+ return -EINVAL;
+@@ -2896,6 +2978,82 @@ static int drmParsePciBusInfo(int maj, i
+ info->func = func;
+
+ return 0;
++#elif defined(__NetBSD__)
++/* From OpenBSD xenocara/lib/libdrm/xf86drm.c */
++ struct drm_pciinfo pinfo;
++ int fd;
++
++ drmMsg("NetBSD: drmParsePciBusInfo(): Before drmOpenMinor min (%d)\n", min);
++
++ fd = drmOpenMinor(min, 0, DRM_NODE_PRIMARY);
++ if (fd < 0)
++ return -errno;
++
++ drmMsg("Before drmIoctl (0x0f) using fd (%d)\n", fd);
++
++ 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;
++#elif (defined(__FreeBSD__) || defined(__DragonFly__))
++/* Read the hw.dri.$min.busid sysctl
++ * Adapted from function devq_device_get_pcibusaddr(),
++ * project devq version 0.0.4, file src/freebsd/device.c
++ */
++ char sysctl_name[32], sysctl_value[128];
++ const char *busid_format;
++ size_t sysctl_value_len;
++ int domain, bus, dev, func;
++ int ret;
++ snprintf(sysctl_name, 31, "hw.dri.%d.busid", min);
++
++ drmMsg("Reading sysctl_name (%s)\n", sysctl_name);
++
++ busid_format = "pci:%d:%d:%d.%d";
++ sysctl_value_len = sizeof(sysctl_value);
++ memset(sysctl_value, 0, sysctl_value_len);
++ ret = sysctlbyname(sysctl_name, sysctl_value, &sysctl_value_len,
++ NULL, 0);
++ if (ret != 0) {
++ /*
++ * If hw.dri.$n.busid isn't available, fallback on
++ * hw.dri.$n.name.
++ */
++ busid_format = "%*s %*s pci:%d:%d:%d.%d";
++ sysctl_value_len = sizeof(sysctl_value);
++ memset(sysctl_value, 0, sysctl_value_len);
++ sprintf(sysctl_name, "hw.dri.%d.name", dev);
++
++ drmMsg("Reading sysctl_name (%s)\n", sysctl_name);
++
++ ret = sysctlbyname(sysctl_name, sysctl_value, &sysctl_value_len,
++ NULL, 0);
++ }
++
++ if (ret != 0)
++ return (-EINVAL);
++
++ drmMsg("Scanning sysctl_value (%s) using busid_format (%s)\n",
++ sysctl_value, busid_format);
++
++ if (sscanf(sysctl_value, busid_format,
++ &domain, &bus, &dev, &func) != 4)
++ return -EINVAL;
++
++ info->domain = domain;
++ info->bus = bus;
++ info->dev = dev;
++ info->func = func;
++
++ return 0;
+ #else
+ #warning "Missing implementation of drmParsePciBusInfo"
+ return -EINVAL;
+@@ -2946,8 +3104,87 @@ static int drmGetMaxNodeName(void)
+ 3 /* length of the node number */;
+ }
+
++#if defined(__FreeBSD__) || defined(__DragonFly__)
++/* Uses function of name prefixed by devq_
++ * from libdevq 0.0.4, file src/freebsd/device.c
++ */
++static int
++compare_vgapci_busaddr(int i, int *domain, int *bus, int *slot,
++ int *function)
++{
++ int ret;
++ char sysctl_name[32], sysctl_value[128];
++ size_t sysctl_value_len;
++
++ snprintf(sysctl_name, 31, "dev.vgapci.%d.%%location", i);
++
++ drmMsg("Reading sysctl_name (%s)\n", sysctl_name);
++
++ sysctl_value_len = sizeof(sysctl_value);
++ memset(sysctl_value, 0, sysctl_value_len);
++ ret = sysctlbyname(sysctl_name, sysctl_value,
++ &sysctl_value_len, NULL, 0);
++ if (ret != 0)
++ return (-1);
++
++ drmMsg("Read sysctl_value (%s)\n", sysctl_value);
++
++ /*
++ * dev.vgapci.$m.%location can have two formats:
++ * o "pci0:2:0:0 handle=\_SB_.PCI0.PEG3.MXM3" (FreeBSD 11+)
++ * o "slot=1 function=0" (DragonFly or up-to FreeBSD 10)
++ */
++
++ ret = sscanf(sysctl_value, "pci%d:%d:%d:%d %*s",
++ domain, bus, slot, function);
++
++ if (ret == 4)
++ drmMsg("compare_vgapci_busaddr(): domain (%d), bus (%d), slot (%d), function (%d)\n",
++ *domain, *bus, *slot, *function);
++
++ if (ret == 4)
++ return (0);
++
++ ret = sscanf(sysctl_value, "slot=%d function=%d %*s",
++ slot, function);
++ if (ret != 2)
++ return (-1);
++
++ snprintf(sysctl_name, 31, "dev.vgapci.%d.%%parent", i);
++
++ drmMsg("Reading sysctl_name (%s)\n", sysctl_name);
++
++ sysctl_value_len = sizeof(sysctl_value);
++ memset(sysctl_value, 0, sysctl_value_len);
++ ret = sysctlbyname(sysctl_name, sysctl_value,
++ &sysctl_value_len, NULL, 0);
++ if (ret != 0)
++ return (-1);
++
++ drmMsg("Read sysctl_value (%s)\n", sysctl_value);
++
++ ret = sscanf(sysctl_value, "pci%d", bus);
++ if (ret != 1)
++ return (-1);
++
++ /* FIXME: What domain to assume? */
++ *domain = 0;
++
++ drmMsg("compare_vgapci_busaddr(): domain (%d), bus (%d), slot (%d), function (%d)\n",
++ *domain, *bus, *slot, *function);
++
++ return (0);
++}
++#endif
++
++#if !defined(__FreeBSD__) && !defined(__DragonFly__)
+ static int drmParsePciDeviceInfo(const char *d_name,
+ drmPciDeviceInfoPtr device)
++#else
++static int drmParsePciDeviceInfoBSD(const char *d_name,
++ drmPciDeviceInfoPtr device,
++ drmPciBusInfoPtr info)
++#endif
+ {
+ #ifdef __linux__
+ char path[PATH_MAX + 1];
+@@ -2971,6 +3208,112 @@ static int drmParsePciDeviceInfo(const c
+ device->subdevice_id = config[46] | (config[47] << 8);
+
+ return 0;
++#elif defined(__NetBSD__)
++/* From OpenBSD xenocara/lib/libdrm/xf86drm.c */
++ struct drm_pciinfo pinfo;
++ char buf[PATH_MAX + 1];
++ int fd, n;
++
++ n = snprintf(buf, sizeof(buf), "%s/%s", DRM_DIR_NAME, d_name);
++ if (n == -1 || n >= sizeof(buf))
++ return -errno;
++
++ drmMsg("NetBSD: drmParsePciDeviceInfo(): open (%s)\n", buf);
++ fd = open(buf, O_RDWR, 0);
++
++ if (fd < 0)
++ return -errno;
++
++ drmMsg("Before drmIoctl (0x0f) with fd (%d)\n", fd);
++ 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;
++#elif defined(__FreeBSD__) || defined(__DragonFly__)
++/* Adapted from function devq_device_get_pciid_full_from_fd(),
++ * from libdevq 0.0.4, file src/freebsd/device.c,
++ */
++ unsigned int vendor_id = 0, device_id = 0, subvendor_id = 0,
++ subdevice_id = 0, revision_id = 0;
++ int i, ret;
++ char sysctl_name[32], sysctl_value[128];
++ size_t sysctl_value_len;
++
++/*
++ * Now, look at all dev.vgapci.$m trees until we find the
++ * correct device. We specifically look at:
++ * o dev.vgapci.$m.%location
++ * o dev.vgapci.$m.%parent
++ */
++ for (i = 0; i < DRM_MAX_FDS; ++i) {
++ int tmp_domain, tmp_bus, tmp_slot, tmp_function;
++
++ ret = compare_vgapci_busaddr(i, &tmp_domain, &tmp_bus,
++ &tmp_slot, &tmp_function);
++
++ if (ret == 0 &&
++ tmp_domain == info->domain &&
++ tmp_bus == info->bus &&
++ tmp_slot == info->dev &&
++ tmp_function == info->func)
++ break;
++ }
++
++ if (i == DRM_MAX_FDS) {
++ drmMsg("All DRM_MAX_FDS (%d) vgapci tried!\n", DRM_MAX_FDS);
++ errno = ENOENT;
++ return (-1);
++ }
++
++/*
++ * Ok, we have the right tree. Let's read dev.vgapci.$m.%pnpinfo
++ * to gather the PCI ID.
++ */
++ snprintf(sysctl_name, 31, "dev.vgapci.%d.%%pnpinfo", i);
++
++ drmMsg("Reading sysctl_name (%s)\n", sysctl_name);
++
++ sysctl_value_len = sizeof(sysctl_value);
++ memset(sysctl_value, 0, sysctl_value_len);
++ ret = sysctlbyname(sysctl_name, sysctl_value,
++ &sysctl_value_len, NULL, 0);
++ if (ret != 0)
++ return (-1);
++
++ drmMsg("Read sysctl_value (%s)\n", sysctl_value);
++
++#if defined(__DragonFly__)
++/* DragonFly has a device class field following the subdevice field */
++ ret = sscanf(sysctl_value,
++ "vendor=0x%04x device=0x%04x subvendor=0x%04x subdevice=0x%04x %*s",
++ &vendor_id, &device_id, &subvendor_id, &subdevice_id);
++#else /* FreeBSD */
++ ret = sscanf(sysctl_value,
++ "vendor=0x%04x device=0x%04x subvendor=0x%04x subdevice=0x%04x",
++ &vendor_id, &device_id, &subvendor_id, &subdevice_id);
++#endif
++ if (ret != 4) {
++ errno = EINVAL;
++ return (-1);
++ }
++
++ device->vendor_id = (uint16_t) vendor_id;
++ device->device_id = (uint16_t) device_id;
++ device->subvendor_id = (uint16_t) subvendor_id;
++ device->subdevice_id = (uint16_t) subdevice_id;
++ /* XXX: add code to find out revision id */
++ device->revision_id = (uint8_t) revision_id;
++
++ return 0;
+ #else
+ #warning "Missing implementation of drmParsePciDeviceInfo"
+ return -EINVAL;
+@@ -3006,6 +3349,9 @@ static int drmProcessPciDevice(drmDevice
+ int ret, i;
+ char *addr;
+
++ drmMsg("libdrm, file xf86drm.c, drmProcessPciDevice() called\n");
++ drmMsg(" node (%s), node_type (%d)\n", node, node_type);
++
+ *device = calloc(1, sizeof(drmDevice) +
+ (DRM_NODE_MAX * (sizeof(void *) + max_node_str)) +
+ sizeof(drmPciBusInfo) +
+@@ -3030,19 +3376,41 @@ static int drmProcessPciDevice(drmDevice
+
+ (*device)->businfo.pci = (drmPciBusInfoPtr)addr;
+
++ drmMsg("Before drmParsePciBusInfo(): maj (%d), min (%d)\n", maj, min);
+ ret = drmParsePciBusInfo(maj, min, (*device)->businfo.pci);
++ drmMsg("After drmParsePciBusInfo(): return value (%d)\n", ret);
++
+ if (ret)
+ goto free_device;
+
++ drmMsg("d domain == %04x\n", (*device)->businfo.pci->domain);
++ drmMsg("d bus == %02x\n", (*device)->businfo.pci->bus);
++ drmMsg("d dev == %02x\n", (*device)->businfo.pci->dev);
++ drmMsg("d func == %1u\n", (*device)->businfo.pci->func);
++
+ // Fetch the device info if the user has requested it
+ if (fetch_deviceinfo) {
+ addr += sizeof(drmPciBusInfo);
+ (*device)->deviceinfo.pci = (drmPciDeviceInfoPtr)addr;
+
++ drmMsg("Before drmParsePciDeviceInfo(): d_name (%s)\n", d_name);
++#if defined(__FreeBSD__) || defined(__DragonFly__)
++ ret = drmParsePciDeviceInfoBSD(d_name, (*device)->deviceinfo.pci,
++ (*device)->businfo.pci);
++#else
+ ret = drmParsePciDeviceInfo(d_name, (*device)->deviceinfo.pci);
++#endif
++ drmMsg("After drmParsePciDeviceInfo(): return value (%d)\n", ret);
+ if (ret)
+ goto free_device;
+ }
++
++ drmMsg("d vendor_id == %04x\n", (*device)->deviceinfo.pci->vendor_id);
++ drmMsg("d device_id == %04x\n", (*device)->deviceinfo.pci->device_id);
++ drmMsg("d subvendor_id == %04x\n", (*device)->deviceinfo.pci->subvendor_id);
++ drmMsg("d subdevice_id == %04x\n", (*device)->deviceinfo.pci->subdevice_id);
++ drmMsg("d revision_id == %02x\n", (*device)->deviceinfo.pci->revision_id);
++
+ return 0;
+
+ free_device:
+@@ -3096,6 +3464,8 @@ int drmGetDevice(int fd, drmDevicePtr *d
+ int max_count = 16;
+ dev_t find_rdev;
+
++ drmMsg("libdrm, file xf86drm.c, drmGetDevice(): fd == %d\n", fd);
++
+ if (fd == -1 || device == NULL)
+ return -EINVAL;
+
+@@ -3106,15 +3476,35 @@ int drmGetDevice(int fd, drmDevicePtr *d
+ maj = major(sbuf.st_rdev);
+ min = minor(sbuf.st_rdev);
+
++ drmMsg("DRM_MAJOR == %d, fd maj == %d, min == %d\n", DRM_MAJOR, maj, min);
++
+ if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
++#if defined(__DragonFly__)
++ {
++ if ((maj_firstseen < 0) && (maj >= 0) && S_ISCHR(sbuf.st_mode)) {
++ maj_firstseen = maj;
++ drmMsg("First seen maj (%d) != DRM_MAJOR (%d)\n", maj, DRM_MAJOR);
++ }
++ else if (maj == maj_firstseen) {
++ drmMsg("maj == maj_firstseen (%d)\n", maj_firstseen);
++ }
++ else {
++ return -EINVAL;
++ }
++ }
++#else
+ return -EINVAL;
++#endif
+
+ subsystem_type = drmParseSubsystemType(maj, min);
++ drmMsg("fd subsystem_type == %d\n", subsystem_type);
+
+ local_devices = calloc(max_count, sizeof(drmDevicePtr));
+ if (local_devices == NULL)
+ return -ENOMEM;
+
++ drmMsg("Opening DRM_DIR_NAME (%s)\n", DRM_DIR_NAME);
++
+ sysdir = opendir(DRM_DIR_NAME);
+ if (!sysdir) {
+ ret = -errno;
+@@ -3123,10 +3513,20 @@ int drmGetDevice(int fd, drmDevicePtr *d
+
+ i = 0;
+ while ((dent = readdir(sysdir))) {
++
++ drmMsg("Examining dent->d_name (%s)\n", dent->d_name);
++
+ node_type = drmGetNodeType(dent->d_name);
+ if (node_type < 0)
+ continue;
+
++#if defined(__FreeBSD__)
++/* FreeBSD has /dev/dri/control64D devices which are not relevant */
++ drmMsg("Examining node_type (%d)\n", node_type);
++ if (node_type > 0)
++ continue;
++#endif
++
+ snprintf(node, PATH_MAX, "%s/%s", DRM_DIR_NAME, dent->d_name);
+ if (stat(node, &sbuf))
+ continue;
+@@ -3134,16 +3534,32 @@ int drmGetDevice(int fd, drmDevicePtr *d
+ maj = major(sbuf.st_rdev);
+ min = minor(sbuf.st_rdev);
+
++ drmMsg("Device node (%s) has maj (%d), min (%d)\n", node, maj, min);
++
++#if defined(__DragonFly__)
++ if (((maj != DRM_MAJOR) && (maj != maj_firstseen)) || (maj < 0) || !S_ISCHR(sbuf.st_mode))
++#else
+ if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
++#endif
+ continue;
+
++ drmMsg(" and subsystem_type (%d) compared to DRM_BUS_PCI (%d)\n",
++ drmParseSubsystemType(maj, min), DRM_BUS_PCI);
+ if (drmParseSubsystemType(maj, min) != subsystem_type)
+ continue;
+
++#if defined (__FreeBSD__) || defined(__DragonFly__)
++/* Use basically 0 from card0 instead of the minor number */
++ if (sscanf(dent->d_name, "card%d", &min) != 1)
++ min = 0;
++#endif
++
+ switch (subsystem_type) {
+ case DRM_BUS_PCI:
++ drmMsg("Before drmProcessPciDevice(): card (%d), node_type (%d)\n", min, node_type);
+ ret = drmProcessPciDevice(&d, dent->d_name, node, node_type,
+ maj, min, true);
++ drmMsg("After drmProcessPciDevice(): return value (%d)\n", ret);
+ if (ret)
+ goto free_devices;
+
+@@ -3234,6 +3650,12 @@ int drmGetDevices(drmDevicePtr devices[]
+ if (node_type < 0)
+ continue;
+
++#if defined(__FreeBSD__)
++/* FreeBSD has /dev/dri/control64D devices which are not relevant */
++ if (node_type > 0)
++ continue;
++#endif
++
+ snprintf(node, PATH_MAX, "%s/%s", DRM_DIR_NAME, dent->d_name);
+ if (stat(node, &sbuf))
+ continue;
+@@ -3241,7 +3663,11 @@ int drmGetDevices(drmDevicePtr devices[]
+ maj = major(sbuf.st_rdev);
+ min = minor(sbuf.st_rdev);
+
++#if defined(__DragonFly__)
++ if (((maj != DRM_MAJOR) && (maj != maj_firstseen)) || (maj < 0) || !S_ISCHR(sbuf.st_mode))
++#else
+ if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
++#endif
+ continue;
+
+ subsystem_type = drmParseSubsystemType(maj, min);
diff --git a/libdrm-dfbsd/patches/patch-ac b/libdrm-dfbsd/patches/patch-ac
new file mode 100644
index 0000000..2b11b37
--- /dev/null
+++ b/libdrm-dfbsd/patches/patch-ac
@@ -0,0 +1,40 @@
+$NetBSD: patch-ac,v 1.4 2012/02/16 20:30:56 hans Exp $
+
+--- xf86drm.h.orig 2010-03-05 23:21:13.000000000 +0000
++++ xf86drm.h
+@@ -35,7 +35,11 @@
+ #define _XF86DRM_H_
+
+ #include <stdarg.h>
++#if @ATOMIC_OPS_CHECK@
++#include <sys/atomic.h>
++#else
+ #include <sys/types.h>
++#endif
+ #include <stdint.h>
+ #include <drm.h>
+
+@@ -55,6 +59,9 @@
+ #else /* One of the *BSDs */
+
+ #include <sys/ioccom.h>
++#ifdef __sun
++#define _IOC(d, x, y, t) ((int)((uint32_t)(d | (((sizeof (t)) & IOCPARM_MASK)<<16) | (x<<8) | y)))
++#endif
+ #define DRM_IOCTL_NR(n) ((n) & 0xff)
+ #define DRM_IOC_VOID IOC_VOID
+ #define DRM_IOC_READ IOC_OUT
+@@ -333,7 +340,12 @@ typedef struct _drmSetVersion {
+ #define DRM_LOCK_HELD 0x80000000U /**< Hardware lock is held */
+ #define DRM_LOCK_CONT 0x40000000U /**< Hardware lock is contended */
+
+-#if defined(__GNUC__) && (__GNUC__ >= 2)
++#if @ATOMIC_OPS_CHECK@ /* configured by pkgsrc */
++
++#define DRM_CAS(lock, old, new, __ret) \
++ (__ret = atomic_cas_uint(&__drm_dummy_lock(lock), (old), (new)) != (old));
++
++#elif defined(__GNUC__) && (__GNUC__ >= 2)
+ # if defined(__i386) || defined(__AMD64__) || defined(__x86_64__) || defined(__amd64__)
+ /* Reflect changes here to drmP.h */
+ #define DRM_CAS(lock,old,new,__ret) \
diff --git a/libdrm-dfbsd/patches/patch-include_drm_drm.h b/libdrm-dfbsd/patches/patch-include_drm_drm.h
new file mode 100644
index 0000000..adff81a
--- /dev/null
+++ b/libdrm-dfbsd/patches/patch-include_drm_drm.h
@@ -0,0 +1,18 @@
+$NetBSD: patch-include_drm_drm.h,v 1.4 2016/04/29 11:17:34 wiz Exp $
+
+Fix compilation on systems that don't provide O_CLOEXEC.
+
+--- include/drm/drm.h.orig 2016-04-28 00:44:16.000000000 +0000
++++ include/drm/drm.h
+@@ -674,7 +674,11 @@ struct drm_set_client_cap {
+ };
+
+ #define DRM_RDWR O_RDWR
++#ifdef O_CLOEXEC
+ #define DRM_CLOEXEC O_CLOEXEC
++#else
++#define DRM_CLOEXEC 0
++#endif
+ struct drm_prime_handle {
+ __u32 handle;
+
diff --git a/libdrm-dfbsd/patches/patch-libkms_vmwgfx.c b/libdrm-dfbsd/patches/patch-libkms_vmwgfx.c
new file mode 100644
index 0000000..bedfefa
--- /dev/null
+++ b/libdrm-dfbsd/patches/patch-libkms_vmwgfx.c
@@ -0,0 +1,17 @@
+$NetBSD: patch-libkms_vmwgfx.c,v 1.3 2015/05/07 06:31:06 wiz Exp $
+
+Provide compatibility errno number for non-Linux.
+
+--- libkms/vmwgfx.c.orig 2015-05-06 23:04:31.000000000 +0000
++++ libkms/vmwgfx.c
+@@ -39,6 +39,10 @@
+ #include "libdrm_macros.h"
+ #include "vmwgfx_drm.h"
+
++#ifndef ERESTART
++#define ERESTART 85
++#endif
++
+ struct vmwgfx_bo
+ {
+ struct kms_bo base;
diff --git a/libdrm-dfbsd/patches/patch-radeon_radeon__bo__gem.c b/libdrm-dfbsd/patches/patch-radeon_radeon__bo__gem.c
new file mode 100644
index 0000000..977864f
--- /dev/null
+++ b/libdrm-dfbsd/patches/patch-radeon_radeon__bo__gem.c
@@ -0,0 +1,27 @@
+$NetBSD: patch-radeon_radeon__bo__gem.c,v 1.1 2014/10/26 10:20:10 wiz Exp $
+
+--- radeon/radeon_bo_gem.c.orig 2014-09-28 16:19:54.000000000 +0000
++++ radeon/radeon_bo_gem.c
+@@ -178,8 +178,8 @@ static int bo_map(struct radeon_bo_int *
+ boi, boi->handle, r);
+ return r;
+ }
+- ptr = drm_mmap(0, args.size, PROT_READ|PROT_WRITE, MAP_SHARED, boi->bom->fd, args.addr_ptr);
+- if (ptr == MAP_FAILED)
++ r = drmMap(boi->bom->fd, args.addr_ptr, args.size, &ptr);
++ if (r)
+ return -errno;
+ bo_gem->priv_ptr = ptr;
+ wait:
+@@ -252,9 +252,10 @@ static int bo_set_tiling(struct radeon_b
+ static int bo_get_tiling(struct radeon_bo_int *boi, uint32_t *tiling_flags,
+ uint32_t *pitch)
+ {
+- struct drm_radeon_gem_set_tiling args = {};
++ struct drm_radeon_gem_set_tiling args;
+ int r;
+
++ memset(&args, 0, sizeof args);
+ args.handle = boi->handle;
+
+ r = drmCommandWriteRead(boi->bom->fd,
diff --git a/libdrm-dfbsd/patches/patch-radeon_radeon__cs__gem.c b/libdrm-dfbsd/patches/patch-radeon_radeon__cs__gem.c
new file mode 100644
index 0000000..ebe3d7f
--- /dev/null
+++ b/libdrm-dfbsd/patches/patch-radeon_radeon__cs__gem.c
@@ -0,0 +1,16 @@
+$NetBSD: patch-radeon_radeon__cs__gem.c,v 1.1 2014/10/26 10:20:10 wiz Exp $
+
+--- radeon/radeon_cs_gem.c.orig 2014-09-28 16:19:54.000000000 +0000
++++ radeon/radeon_cs_gem.c
+@@ -525,9 +525,10 @@ static struct radeon_cs_funcs radeon_cs_
+
+ static int radeon_get_device_id(int fd, uint32_t *device_id)
+ {
+- struct drm_radeon_info info = {};
++ struct drm_radeon_info info;
+ int r;
+
++ memset(&info, 0, sizeof info);
+ *device_id = 0;
+ info.request = RADEON_INFO_DEVICE_ID;
+ info.value = (uintptr_t)device_id;
diff --git a/libdrm-dfbsd/patches/patch-xf86drmMode.c b/libdrm-dfbsd/patches/patch-xf86drmMode.c
new file mode 100644
index 0000000..bd843d6
--- /dev/null
+++ b/libdrm-dfbsd/patches/patch-xf86drmMode.c
@@ -0,0 +1,69 @@
+$NetBSD: patch-xf86drmMode.c,v 1.2 2015/04/11 10:02:11 sevan Exp $
+
+Disable checking for hw.dri.%d.modesetting.
+This sysctl is only available if a KMS module is loaded. But the libdrm
+check happens before X got a chance of loading the KMS module.
+
+--- xf86drmMode.c.orig 2015-03-18 17:33:36.000000000 +0000
++++ xf86drmMode.c
+@@ -771,38 +771,20 @@ int drmCheckModesettingSupported(const c
+ 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 0;
++#elif defined(__NetBSD__)
++ int fd;
++ static const struct drm_mode_card_res zero_res;
++ struct drm_mode_card_res res = zero_res;
++ int ret;
++
++ fd = drmOpen(NULL, busid);
++ if (fd == -1)
+ 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);
+- }
++ ret = drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res);
++ drmClose(fd);
++ if (ret == 0)
++ return 0;
+ #elif defined(__DragonFly__)
+ return 0;
+ #endif
+@@ -907,7 +889,7 @@ int drmModePageFlip(int fd, uint32_t crt
+
+ int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
+ uint32_t fb_id, uint32_t flags,
+- int32_t crtc_x, int32_t crtc_y,
++ uint32_t crtc_x, uint32_t crtc_y,
+ uint32_t crtc_w, uint32_t crtc_h,
+ uint32_t src_x, uint32_t src_y,
+ uint32_t src_w, uint32_t src_h)
diff --git a/libdrm-dfbsd/patches/patch-xf86drmMode.h b/libdrm-dfbsd/patches/patch-xf86drmMode.h
new file mode 100644
index 0000000..8a20d90
--- /dev/null
+++ b/libdrm-dfbsd/patches/patch-xf86drmMode.h
@@ -0,0 +1,13 @@
+$NetBSD: patch-xf86drmMode.h,v 1.1 2014/10/26 10:20:10 wiz Exp $
+
+--- xf86drmMode.h.orig 2014-06-14 12:33:26.000000000 +0000
++++ xf86drmMode.h
+@@ -449,7 +449,7 @@ extern drmModePlaneResPtr drmModeGetPlan
+ extern drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id);
+ extern int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
+ uint32_t fb_id, uint32_t flags,
+- int32_t crtc_x, int32_t crtc_y,
++ uint32_t crtc_x, uint32_t crtc_y,
+ uint32_t crtc_w, uint32_t crtc_h,
+ uint32_t src_x, uint32_t src_y,
+ uint32_t src_w, uint32_t src_h);
Home |
Main Index |
Thread Index |
Old Index