pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

libdrm-dfbsd-meson: Import libdrm-2.4.97 git meson as wip/libdrm-dfbsd-meson



Module Name:	pkgsrc-wip
Committed By:	David Shao <davshao%gmail.com@localhost>
Pushed By:	dshao
Date:		Wed Feb 27 15:19:13 2019 -0800
Changeset:	0c55526fe72fcce5875d2cfaf6942f4f7d09f9c5

Modified Files:
	Makefile
Added Files:
	libdrm-dfbsd-meson/DESCR
	libdrm-dfbsd-meson/Makefile
	libdrm-dfbsd-meson/PLIST
	libdrm-dfbsd-meson/PLIST.DragonFly
	libdrm-dfbsd-meson/PLIST.FreeBSD
	libdrm-dfbsd-meson/PLIST.Linux
	libdrm-dfbsd-meson/TODO
	libdrm-dfbsd-meson/buildlink3.mk
	libdrm-dfbsd-meson/builtin.mk
	libdrm-dfbsd-meson/distinfo
	libdrm-dfbsd-meson/patches/patch-ac
	libdrm-dfbsd-meson/patches/patch-include_drm_drm.h
	libdrm-dfbsd-meson/patches/patch-libkms_vmwgfx.c
	libdrm-dfbsd-meson/patches/patch-libsync.h
	libdrm-dfbsd-meson/patches/patch-meson.build
	libdrm-dfbsd-meson/patches/patch-xf86atomic.h
	libdrm-dfbsd-meson/patches/patch-xf86drm.c
	libdrm-dfbsd-meson/patches/patch-xf86drmMode.c
	libdrm-dfbsd-meson/patches/patch-xf86drmMode.h

Log Message:
libdrm-dfbsd-meson: Import libdrm-2.4.97 git meson as wip/libdrm-dfbsd-meson

meson build version of libdrm latest git
Not sure what to do about libkms for FreeBSD and Dragonfly.

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=0c55526fe72fcce5875d2cfaf6942f4f7d09f9c5

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 Makefile                                           |   1 +
 libdrm-dfbsd-meson/DESCR                           |   3 +
 libdrm-dfbsd-meson/Makefile                        | 101 ++++
 libdrm-dfbsd-meson/PLIST                           |  82 +++
 libdrm-dfbsd-meson/PLIST.DragonFly                 |   7 +
 libdrm-dfbsd-meson/PLIST.FreeBSD                   |   7 +
 libdrm-dfbsd-meson/PLIST.Linux                     |   4 +
 libdrm-dfbsd-meson/TODO                            |   8 +
 libdrm-dfbsd-meson/buildlink3.mk                   |  13 +
 libdrm-dfbsd-meson/builtin.mk                      |  10 +
 libdrm-dfbsd-meson/distinfo                        |  15 +
 libdrm-dfbsd-meson/patches/patch-ac                |  40 ++
 libdrm-dfbsd-meson/patches/patch-include_drm_drm.h |  18 +
 libdrm-dfbsd-meson/patches/patch-libkms_vmwgfx.c   |  37 ++
 libdrm-dfbsd-meson/patches/patch-libsync.h         |  24 +
 libdrm-dfbsd-meson/patches/patch-meson.build       |  26 +
 libdrm-dfbsd-meson/patches/patch-xf86atomic.h      |  21 +
 libdrm-dfbsd-meson/patches/patch-xf86drm.c         | 639 +++++++++++++++++++++
 libdrm-dfbsd-meson/patches/patch-xf86drmMode.c     | 124 ++++
 libdrm-dfbsd-meson/patches/patch-xf86drmMode.h     |  20 +
 20 files changed, 1200 insertions(+)

diffs:
diff --git a/Makefile b/Makefile
index 5063e77295..d66f920c7f 100644
--- a/Makefile
+++ b/Makefile
@@ -1813,6 +1813,7 @@ SUBDIR+=	libdjconsole
 SUBDIR+=	libdmx
 SUBDIR+=	libdoozer
 SUBDIR+=	libdrm-dfbsd
+SUBDIR+=	libdrm-dfbsd-meson
 SUBDIR+=	libdssialsacompat
 SUBDIR+=	libecc
 SUBDIR+=	libechonest
diff --git a/libdrm-dfbsd-meson/DESCR b/libdrm-dfbsd-meson/DESCR
new file mode 100644
index 0000000000..c8be56c6b4
--- /dev/null
+++ b/libdrm-dfbsd-meson/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-meson/Makefile b/libdrm-dfbsd-meson/Makefile
new file mode 100644
index 0000000000..a461956775
--- /dev/null
+++ b/libdrm-dfbsd-meson/Makefile
@@ -0,0 +1,101 @@
+# $NetBSD: Makefile,v 1.91 2019/01/22 21:50:47 wiz Exp $
+
+# 2019-02-01		amdgpu: add some raven marketing names
+COMMIT_ID=		6415bd3ced9d80137e30cb90837eb01932607882
+
+PORTNAME=		drm
+
+DISTNAME=		${PORTNAME}-${COMMIT_ID}
+PKGNAME=		libdrm-2.4.97
+# PKGREVISION=	2
+CATEGORIES=		x11 graphics
+MASTER_SITES=		http://cgit.freedesktop.org/mesa/${PORTNAME}/snapshot/
+EXTRACT_SUFX=		.tar.xz
+
+
+# DISTNAME=		libdrm-2.4.97
+# 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+=		gmake 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
+# Intel driver no longer needs libatomic_ops
+.if ${MACHINE_ARCH} != "i386" && ${MACHINE_ARCH} != x86_64
+.  include "../../devel/libatomic_ops/buildlink3.mk"
+CONFIGURE_ENV+=		drm_cv_atomic_primitives=libatomic-ops
+.endif
+.endif
+
+CONFIGURE_ARGS+=	PTHREADSTUBS_CFLAGS=-I${PREFIX}/include \
+			PTHREADSTUBS_LIBS=-L${PREFIX}/lib
+CONFIGURE_ARGS+=	--disable-manpages
+CONFIGURE_ARGS+=	--disable-valgrind
+MESON_ARGS+=	-Dman-pages=false
+MESON_ARGS+=	-Dvalgrind=false
+
+LDFLAGS.NetBSD+=	-lpci
+
+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
+
+PKG_OPTIONS_VAR=	PKG_OPTIONS.libdrm
+PKG_SUPPORTED_OPTIONS=	libkms
+PKG_SUGGESTED_OPTIONS=
+
+# .if !empty(MACHINE_ARCH:Mi386) || !empty(MACHINE_ARCH:Mx86_64)
+# PKG_SUGGESTED_OPTIONS+=	libkms
+# .endif
+
+.include "../../mk/bsd.options.mk"
+
+PLIST_VARS+=	libkms	
+.if !empty(PKG_OPTIONS:Mlibkms)
+PKGCONFIG_OVERRIDE+=	libkms.pc.in
+PLIST.libkms=	yes
+CONFIGURE_ARGS+=	--enable-libkms
+MESON_ARGS+=	-Dlibkms=true
+.else
+CONFIGURE_ARGS+=	--disable-libkms
+MESON_ARGS+=	-Dlibkms=false
+.endif
+
+# Meson
+# CPPFLAGS+=	-Wno-return-type
+.include "../../devel/py-meson/build.mk"
+
+.include "../../mk/bsd.pkg.mk"
diff --git a/libdrm-dfbsd-meson/PLIST b/libdrm-dfbsd-meson/PLIST
new file mode 100644
index 0000000000..a5f0496422
--- /dev/null
+++ b/libdrm-dfbsd-meson/PLIST
@@ -0,0 +1,82 @@
+@comment $NetBSD: PLIST,v 1.21 2018/09/02 08:34:34 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/msm_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.libkms}include/libkms/libkms.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
+@comment lib/libdrm.la
+lib/libdrm.so
+lib/libdrm.so.2
+lib/libdrm.so.2.4.0
+@comment lib/libdrm_amdgpu.la
+lib/libdrm_amdgpu.so
+lib/libdrm_amdgpu.so.1
+lib/libdrm_amdgpu.so.1.0.0
+${PLIST.arm}lib/libdrm_freedreno.la
+@comment ${PLIST.intel}lib/libdrm_intel.la
+${PLIST.intel}lib/libdrm_intel.so
+${PLIST.intel}lib/libdrm_intel.so.1
+${PLIST.intel}lib/libdrm_intel.so.1.0.0
+@comment lib/libdrm_nouveau.la
+lib/libdrm_nouveau.so
+lib/libdrm_nouveau.so.2
+lib/libdrm_nouveau.so.2.0.0
+@comment lib/libdrm_radeon.la
+lib/libdrm_radeon.so
+lib/libdrm_radeon.so.1
+lib/libdrm_radeon.so.1.0.1
+${PLIST.libkms}lib/libkms.so
+${PLIST.libkms}lib/libkms.so.1
+${PLIST.libkms}lib/libkms.so.1.0.0
+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
+${PLIST.libkms}lib/pkgconfig/libkms.pc
+share/libdrm/amdgpu.ids
diff --git a/libdrm-dfbsd-meson/PLIST.DragonFly b/libdrm-dfbsd-meson/PLIST.DragonFly
new file mode 100644
index 0000000000..799d3b721e
--- /dev/null
+++ b/libdrm-dfbsd-meson/PLIST.DragonFly
@@ -0,0 +1,7 @@
+@comment $NetBSD: PLIST.DragonFly,v 1.1 2014/06/01 06:37:46 ryoon Exp $
+@comment include/libkms/libkms.h
+@comment lib/libkms.la
+@comment ${PLIST.libkms}lib/libkms.so
+@comment ${PLIST.libkms}lib/libkms.so.1
+@comment ${PLIST.libkms}lib/libkms.so.1.0.0
+@comment lib/pkgconfig/libkms.pc
diff --git a/libdrm-dfbsd-meson/PLIST.FreeBSD b/libdrm-dfbsd-meson/PLIST.FreeBSD
new file mode 100644
index 0000000000..7f094e5b99
--- /dev/null
+++ b/libdrm-dfbsd-meson/PLIST.FreeBSD
@@ -0,0 +1,7 @@
+@comment $NetBSD: PLIST.FreeBSD,v 1.1 2014/04/18 09:43:29 asau Exp $
+@comment include/libkms/libkms.h
+@comment lib/libkms.la
+@comment ${PLIST.libkms}lib/libkms.so
+@comment ${PLIST.libkms}lib/libkms.so.1
+@comment ${PLIST.libkms}lib/libkms.so.1.0.0
+@comment lib/pkgconfig/libkms.pc
diff --git a/libdrm-dfbsd-meson/PLIST.Linux b/libdrm-dfbsd-meson/PLIST.Linux
new file mode 100644
index 0000000000..54ca07932e
--- /dev/null
+++ b/libdrm-dfbsd-meson/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-meson/TODO b/libdrm-dfbsd-meson/TODO
new file mode 100644
index 0000000000..ebfc9768f2
--- /dev/null
+++ b/libdrm-dfbsd-meson/TODO
@@ -0,0 +1,8 @@
+Copy port to x11/libdrm, do not install from wip.
+
+Implements changes to libdrm to work with mesa 17.0.1 discussed in
+pkg/51795
+(x11/libdrm update xf86drm.c for mesa 17.0.1 needs negotiation)
+
+Figure out why NetBSD prefers the incorrect version of
+atomic_add_unless that returns the c == unless comparison.
diff --git a/libdrm-dfbsd-meson/buildlink3.mk b/libdrm-dfbsd-meson/buildlink3.mk
new file mode 100644
index 0000000000..1a1f3f203c
--- /dev/null
+++ b/libdrm-dfbsd-meson/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-meson/builtin.mk b/libdrm-dfbsd-meson/builtin.mk
new file mode 100644
index 0000000000..ffe2489949
--- /dev/null
+++ b/libdrm-dfbsd-meson/builtin.mk
@@ -0,0 +1,10 @@
+# $NetBSD: builtin.mk,v 1.4 2018/06/01 15:05:43 maya Exp $
+
+BUILTIN_PKG:=	libdrm
+.for pcfile in libdrm libdrm_amdgpu libdrm_intel libdrm_nouveau libdrm_radeon
+PKGCONFIG_FILE.libdrm+=	${X11BASE}/lib/pkgconfig/${pcfile}.pc
+PKGCONFIG_FILE.libdrm+=	${X11BASE}/lib${LIBABISUFFIX}/pkgconfig/${pcfile}.pc
+.endfor
+
+.include "../../mk/buildlink3/pkgconfig-builtin.mk"
+.include "../../mk/x11.builtin.mk"
diff --git a/libdrm-dfbsd-meson/distinfo b/libdrm-dfbsd-meson/distinfo
new file mode 100644
index 0000000000..a90e76f094
--- /dev/null
+++ b/libdrm-dfbsd-meson/distinfo
@@ -0,0 +1,15 @@
+$NetBSD: distinfo,v 1.92 2019/01/22 21:50:47 wiz Exp $
+
+SHA1 (drm-6415bd3ced9d80137e30cb90837eb01932607882.tar.xz) = 08f240cb4473ca47127c450c10b17dedfad71ff3
+RMD160 (drm-6415bd3ced9d80137e30cb90837eb01932607882.tar.xz) = ab5f819db8e1e77e5cb6323163b90b71a835fdea
+SHA512 (drm-6415bd3ced9d80137e30cb90837eb01932607882.tar.xz) = 5a1ed905ca49bc2010be76a2b28e1b16d42ea9219ddc1291ebef50ce1e668d3a094be02ae38bc3ab8cea0404abda338863b4b5467012141f094185c78ead1aca
+Size (drm-6415bd3ced9d80137e30cb90837eb01932607882.tar.xz) = 395556 bytes
+SHA1 (patch-ac) = 67c998df7dfc0dabc86320ea6d015cede3e464ea
+SHA1 (patch-include_drm_drm.h) = 48a912f40bf2b2a1c23edbe4446fa7869212f17b
+SHA1 (patch-libkms_vmwgfx.c) = de56a4f1724bef5f237f183eca889b8cef3b81af
+SHA1 (patch-libsync.h) = 1e0603e72a54a069fc9d2ab2c9559d22381a69d3
+SHA1 (patch-meson.build) = 32b7b69c936d658a382a0b4e2b157649a9c4782d
+SHA1 (patch-xf86atomic.h) = 887db95db00125bdfa1ab298b2ccc555dec70366
+SHA1 (patch-xf86drm.c) = 3cd8c6a6e26728d92ec3fc03cfffa778a65c286b
+SHA1 (patch-xf86drmMode.c) = d7c6617ef54f76dc3dac00098adbb2f6fb02d685
+SHA1 (patch-xf86drmMode.h) = 265989e670cc7ead9bb5002e116e5ab56439ede6
diff --git a/libdrm-dfbsd-meson/patches/patch-ac b/libdrm-dfbsd-meson/patches/patch-ac
new file mode 100644
index 0000000000..2b11b37832
--- /dev/null
+++ b/libdrm-dfbsd-meson/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-meson/patches/patch-include_drm_drm.h b/libdrm-dfbsd-meson/patches/patch-include_drm_drm.h
new file mode 100644
index 0000000000..adff81aaef
--- /dev/null
+++ b/libdrm-dfbsd-meson/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-meson/patches/patch-libkms_vmwgfx.c b/libdrm-dfbsd-meson/patches/patch-libkms_vmwgfx.c
new file mode 100644
index 0000000000..3ed014c2f0
--- /dev/null
+++ b/libdrm-dfbsd-meson/patches/patch-libkms_vmwgfx.c
@@ -0,0 +1,37 @@
+$NetBSD: patch-libkms_vmwgfx.c,v 1.3 2015/05/07 06:31:06 wiz Exp $
+
+Provide compatibility errno number for non-Linux.
+
+From FreeBSD ports for graphics/libdrm version 2.4.84
+
+# the defintion of ERESTART is behind a check for _KERNEL, but
+# defining that causes errno to not be defined. fortunately, there's
+# an alternative switch. unfortunately, those differ by platform and
+# _WANT_KERNEL_ERRNO is too recent to be part of any release, so just
+# define ERESTART if we still don't have it after including errno.h
+
+--- libkms/vmwgfx.c.orig	2015-05-06 23:04:31.000000000 +0000
++++ libkms/vmwgfx.c
+@@ -26,10 +26,22 @@
+  **************************************************************************/
+ 
+ 
++#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
++#define _WANT_KERNEL_ERRNO
++#elif defined(__DragonFly__)
++#define _KERNEL_STRUCTURES
++#endif
+ #include <errno.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include "internal.h"
++#ifndef ERESTART
++#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__)
++#define ERESTART (-1)
++#else
++#define ERESTART 85
++#endif /* __FreeBSD__ || __DragonFly__ */
++#endif
+ 
+ #include "xf86drm.h"
+ #include "libdrm_macros.h"
diff --git a/libdrm-dfbsd-meson/patches/patch-libsync.h b/libdrm-dfbsd-meson/patches/patch-libsync.h
new file mode 100644
index 0000000000..41909f92a1
--- /dev/null
+++ b/libdrm-dfbsd-meson/patches/patch-libsync.h
@@ -0,0 +1,24 @@
+$NetBSD: patch-libsync.h,v 1.3 2019/01/22 21:50:47 wiz Exp $
+
+Fix public header on SunOS.
+If ETIME is not defined, use ETIMEDOUT.
+
+--- libsync.h.orig	2019-01-22 16:32:41.000000000 +0000
++++ libsync.h
+@@ -33,9 +33,16 @@
+ #include <stdint.h>
+ #include <string.h>
+ #include <sys/ioctl.h>
++#ifdef __sun
++#include <sys/filio.h>
++#endif
+ #include <sys/poll.h>
+ #include <unistd.h>
+ 
++#ifndef ETIME
++#define ETIME ETIMEDOUT
++#endif
++
+ #if defined(__cplusplus)
+ extern "C" {
+ #endif
diff --git a/libdrm-dfbsd-meson/patches/patch-meson.build b/libdrm-dfbsd-meson/patches/patch-meson.build
new file mode 100644
index 0000000000..c27a52d6e4
--- /dev/null
+++ b/libdrm-dfbsd-meson/patches/patch-meson.build
@@ -0,0 +1,26 @@
+$NetBSD$
+
+--- meson.build.orig	2019-02-01 05:26:48.000000000 +0000
++++ meson.build
+@@ -35,11 +35,7 @@ config.set10('UDEV', get_option('udev'))
+ with_freedreno_kgsl = get_option('freedreno-kgsl')
+ with_install_tests = get_option('install-test-programs')
+ 
+-if ['freebsd', 'dragonfly', 'netbsd'].contains(host_machine.system())
+-  dep_pthread_stubs = dependency('pthread-stubs', version : '>= 0.4')
+-else
+-  dep_pthread_stubs = []
+-endif
++dep_pthread_stubs = []
+ dep_threads = dependency('threads')
+ 
+ cc = meson.get_compiler('c')
+@@ -181,7 +177,7 @@ endif
+ dep_m = cc.find_library('m', required : false)
+ foreach header : ['sys/sysctl.h', 'sys/select.h', 'alloca.h']
+   config.set('HAVE_' + header.underscorify().to_upper(),
+-    cc.compiles('#include <@0@>'.format(header), name : '@0@ works'.format(header)))
++    cc.has_header(header))
+ endforeach
+ if cc.has_header_symbol('sys/sysmacros.h', 'major')
+   config.set10('MAJOR_IN_SYSMACROS', true)
diff --git a/libdrm-dfbsd-meson/patches/patch-xf86atomic.h b/libdrm-dfbsd-meson/patches/patch-xf86atomic.h
new file mode 100644
index 0000000000..da8af22050
--- /dev/null
+++ b/libdrm-dfbsd-meson/patches/patch-xf86atomic.h
@@ -0,0 +1,21 @@
+$NetBSD$
+
+This single patch allows glxgears to run properly on
+an Intel integrated graphics IvyBridge machine on DragonFly.
+libdrm atomic_add_unless() may reverse return value meaning
+https://bugs.freedesktop.org/show_bug.cgi?id=100077
+
+--- xf86atomic.h.orig	2015-09-22 04:34:51.000000000 +0000
++++ xf86atomic.h
+@@ -111,7 +111,11 @@ static inline int atomic_add_unless(atom
+ 	c = atomic_read(v);
+ 	while (c != unless && (old = atomic_cmpxchg(v, c, c + add)) != c)
+ 		c = old;
++#if defined(__FreeBSD__) || defined(__DragonFly__)
++	return c != unless;
++#else
+ 	return c == unless;
++#endif
+ }
+ 
+ #endif
diff --git a/libdrm-dfbsd-meson/patches/patch-xf86drm.c b/libdrm-dfbsd-meson/patches/patch-xf86drm.c
new file mode 100644
index 0000000000..5f5fc685af
--- /dev/null
+++ b/libdrm-dfbsd-meson/patches/patch-xf86drm.c
@@ -0,0 +1,639 @@
+$NetBSD: patch-xf86drm.c,v 1.4 2019/01/22 21:50:47 wiz Exp $
+
+Implement drmParseSubsystemType, drmParsePciBusInfo for NetBSD
+
+Patches from FreeBSD ports / DragonFly dports for graphics/libdrm 2.4.84.
+
+--- xf86drm.c.orig	2019-01-22 16:32:41.000000000 +0000
++++ xf86drm.c
+@@ -46,6 +46,11 @@
+ #include <signal.h>
+ #include <time.h>
+ #include <sys/types.h>
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++#ifdef HAVE_SYS_SYSCTL_H
++#include <sys/sysctl.h>
++#endif
++#endif
+ #include <sys/stat.h>
+ #define stat_t struct stat
+ #include <sys/ioctl.h>
+@@ -59,6 +64,10 @@
+ #endif
+ #include <math.h>
+ 
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++#include <sys/pciio.h>
++#endif
++
+ #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+ 
+ /* Not all systems have MAP_FAILED defined */
+@@ -82,11 +91,23 @@
+ #endif
+ 
+ #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
+-#define DRM_MAJOR 145
++#define DRM_MAJOR 0	/* Major ID unused on systems with devfs */
++#endif
++
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++#define DRM_NODE_NAME_MAX                   \
++    (sizeof(DRM_DIR_NAME) +                 \
++     MAX3(sizeof(DRM_PRIMARY_MINOR_NAME),   \
++         sizeof(DRM_CONTROL_MINOR_NAME),    \
++         sizeof(DRM_RENDER_MINOR_NAME))     \
++    + 3) /* length of the node number */
+ #endif
+ 
+ #ifdef __NetBSD__
+-#define DRM_MAJOR 34
++#define DRM_MAJOR 180
++#include <sys/param.h>
++#include <dev/pci/pcireg.h>
++#include <pci.h>
+ #endif
+ 
+ #ifdef __OpenBSD__
+@@ -101,7 +122,7 @@
+ #define DRM_MAJOR 226 /* Linux */
+ #endif
+ 
+-#if defined(__OpenBSD__) || defined(__DragonFly__)
++#if defined(__OpenBSD__)
+ struct drm_pciinfo {
+ 	uint16_t	domain;
+ 	uint8_t		bus;
+@@ -222,6 +243,35 @@ drm_public drmHashEntry *drmGetEntry(int
+     return entry;
+ }
+ 
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++static int drmGetMinorBase(int type);
++static int drmGetMinorType(int minor);
++
++static const char *drmGetDeviceName(int type)
++{
++    switch (type) {
++        case DRM_NODE_PRIMARY:
++            return DRM_DEV_NAME;
++        case DRM_NODE_CONTROL:
++            return DRM_CONTROL_DEV_NAME;
++        case DRM_NODE_RENDER:
++            return DRM_RENDER_DEV_NAME;
++        default:
++            return NULL;
++    }
++}
++
++static int drmGetNodeNumber(const char *name)
++{
++    size_t name_len = strnlen(name, DRM_NODE_NAME_MAX);
++    while (name_len && isdigit(name[name_len - 1]))
++        --name_len;
++    return strtol(name + name_len, NULL, 10);
++}
++
++static int drmGetNodeType(const char *name);
++#endif /* __FreeBSD__ || __DragonFly__ */
++
+ /**
+  * Compare two busid strings
+  *
+@@ -351,7 +401,11 @@ static int drmOpenDevice(dev_t dev, int
+         return -EINVAL;
+     };
+ 
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++    sprintf(buf, dev_name, DRM_DIR_NAME, minor + drmGetMinorBase(type));
++#else
+     sprintf(buf, dev_name, DRM_DIR_NAME, minor);
++#endif
+     drmMsg("drmOpenDevice: node name is %s\n", buf);
+ 
+     if (drm_server_info && drm_server_info->get_perms) {
+@@ -475,7 +529,11 @@ static int drmOpenMinor(int minor, int c
+         return -EINVAL;
+     };
+ 
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++    sprintf(buf, dev_name, DRM_DIR_NAME, minor + drmGetMinorBase(type));
++#else
+     sprintf(buf, dev_name, DRM_DIR_NAME, minor);
++#endif
+     if ((fd = open(buf, O_RDWR | O_CLOEXEC, 0)) >= 0)
+         return fd;
+     return -errno;
+@@ -519,12 +577,19 @@ drm_public int drmAvailable(void)
+ static int drmGetMinorBase(int type)
+ {
+     switch (type) {
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++        case DRM_NODE_PRIMARY:
++        case DRM_NODE_CONTROL:
++        case DRM_NODE_RENDER:
++            return type << 6;
++#else /* !__FreeBSD__ && !__DragonFly__ */
+     case DRM_NODE_PRIMARY:
+         return 0;
+     case DRM_NODE_CONTROL:
+         return 64;
+     case DRM_NODE_RENDER:
+         return 128;
++#endif /* __FreeBSD__ || __DragonFly__ */
+     default:
+         return -1;
+     };
+@@ -547,6 +612,7 @@ static int drmGetMinorType(int minor)
+     }
+ }
+ 
++#ifdef __linux__
+ static const char *drmGetMinorName(int type)
+ {
+     switch (type) {
+@@ -560,6 +626,7 @@ static const char *drmGetMinorName(int t
+         return NULL;
+     }
+ }
++#endif /* __linux__ */
+ 
+ /**
+  * Open the device by bus ID.
+@@ -2779,12 +2846,29 @@ static bool drmNodeIsDRM(int maj, int mi
+              maj, min);
+     return stat(path, &sbuf) == 0;
+ #else
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++    return !DRM_MAJOR || maj == DRM_MAJOR;
++#else
+     return maj == DRM_MAJOR;
+ #endif
++#endif
+ }
+ 
+ drm_public int drmGetNodeTypeFromFd(int fd)
+ {
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++    char *name = drmGetDeviceNameFromFd2(fd);
++    if (!name) {
++        errno = ENODEV;
++        return -1;
++    }
++
++    int type = drmGetNodeType(name);
++    free(name);
++    if (type < 0)
++        errno = ENODEV;
++    return type;
++#else
+     struct stat sbuf;
+     int maj, min, type;
+ 
+@@ -2803,6 +2887,7 @@ drm_public int drmGetNodeTypeFromFd(int
+     if (type == -1)
+         errno = ENODEV;
+     return type;
++#endif
+ }
+ 
+ drm_public int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags,
+@@ -2881,6 +2966,25 @@ static char *drmGetMinorNameForFD(int fd
+ 
+     closedir(sysdir);
+     return NULL;
++#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++    const char *dev_name = drmGetDeviceName(type);
++    if (!dev_name)
++        return NULL;
++
++    char *name = drmGetDeviceNameFromFd2(fd);
++    if (!name)
++        return NULL;
++
++    int oldnum = drmGetNodeNumber(name);
++    int oldtype = drmGetMinorType(oldnum);
++    if (oldtype < 0) {
++        free(name);
++        return NULL;
++    }
++
++    int newnum = oldnum - drmGetMinorBase(oldtype) + drmGetMinorBase(type);
++    snprintf(name, DRM_NODE_NAME_MAX, dev_name, DRM_DIR_NAME, newnum);
++    return name;
+ #else
+     struct stat sbuf;
+     char buf[PATH_MAX + 1];
+@@ -3014,7 +3118,66 @@ static int drmParseSubsystemType(int maj
+     }
+ 
+     return -EINVAL;
+-#elif defined(__OpenBSD__) || defined(__DragonFly__)
++#elif defined(__NetBSD__)
++    int type, fd;
++    drmSetVersion sv;
++    char *buf;
++    unsigned domain, bus, dev;
++    int func;
++    int ret;
++
++    /* Get the type of device we're looking for to pick the right pathname.  */
++    type = drmGetMinorType(min);
++    if (type == -1)
++	return -ENODEV;
++
++    /* Open the device.  Don't try to create it if it's not there.  */
++    fd = drmOpenMinor(min, 0, type);
++    if (fd < 0)
++	return -errno;
++
++    /*
++     * Set the interface version to 1.4 or 1.1, which has the effect of
++     * populating the bus id for us.
++     */
++    sv.drm_di_major = 1;
++    sv.drm_di_minor = 4;
++    sv.drm_dd_major = -1;
++    sv.drm_dd_minor = -1;
++    if (drmSetInterfaceVersion(fd, &sv)) {
++	sv.drm_di_major = 1;
++	sv.drm_di_minor = 1;
++	sv.drm_dd_major = -1;
++	sv.drm_dd_minor = -1;
++	if (drmSetInterfaceVersion(fd, &sv)) {
++	    /*
++	     * We're probably not the master.  Hope the master already
++	     * set the version to >=1.1 so that we can get the busid.
++	     */
++	}
++    }
++
++    /* Get the bus id.  */
++    buf = drmGetBusid(fd);
++
++    /* We're done with the device now.  */
++    (void)close(fd);
++
++    /* If there is no bus id, fail.  */
++    if (buf == NULL)
++	return -ENODEV;
++
++    /* Find a string we know about; otherwise -EINVAL.  */
++    ret = -EINVAL;
++    if (strncmp(buf, "pci:", 4) == 0)
++	ret = DRM_BUS_PCI;
++
++    /* We're done with the bus id.  */
++    free(buf);
++
++    /* Success or not, we're done.  */
++    return ret;
++#elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
+     return DRM_BUS_PCI;
+ #else
+ #warning "Missing implementation of drmParseSubsystemType"
+@@ -3022,6 +3185,7 @@ static int drmParseSubsystemType(int maj
+ #endif
+ }
+ 
++#ifdef __linux__
+ static void
+ get_pci_path(int maj, int min, char *pci_path)
+ {
+@@ -3037,8 +3201,14 @@ get_pci_path(int maj, int min, char *pci
+     if (term && strncmp(term, "/virtio", 7) == 0)
+         *term = 0;
+ }
++#endif
+ 
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++static int drmParsePciBusInfo(const char *node, int node_type,
++                              int maj, int min, drmPciBusInfoPtr info)
++#else
+ static int drmParsePciBusInfo(int maj, int min, drmPciBusInfoPtr info)
++#endif
+ {
+ #ifdef __linux__
+     unsigned int domain, bus, dev, func;
+@@ -3063,7 +3233,74 @@ static int drmParsePciBusInfo(int maj, i
+     info->func = func;
+ 
+     return 0;
+-#elif defined(__OpenBSD__) || defined(__DragonFly__)
++#elif defined(__NetBSD__)
++    int type, fd;
++    drmSetVersion sv;
++    char *buf;
++    unsigned domain, bus, dev;
++    int func;
++    int ret;
++
++    /* Get the type of device we're looking for to pick the right pathname.  */
++    type = drmGetMinorType(min);
++    if (type == -1)
++	return -ENODEV;
++
++    /* Open the device.  Don't try to create it if it's not there.  */
++    fd = drmOpenMinor(min, 0, type);
++    if (fd < 0)
++	return -errno;
++
++    /*
++     * Set the interface version to 1.4 or 1.1, which has the effect of
++     * populating the bus id for us.
++     */
++    sv.drm_di_major = 1;
++    sv.drm_di_minor = 4;
++    sv.drm_dd_major = -1;
++    sv.drm_dd_minor = -1;
++    if (drmSetInterfaceVersion(fd, &sv)) {
++	sv.drm_di_major = 1;
++	sv.drm_di_minor = 1;
++	sv.drm_dd_major = -1;
++	sv.drm_dd_minor = -1;
++	if (drmSetInterfaceVersion(fd, &sv)) {
++            /*
++	     * We're probably not the master.  Hope the master already
++	     * set the version to >=1.1 so that we can get the busid.
++	     */
++	}
++    }
++
++    /* Get the bus id.  */
++    buf = drmGetBusid(fd);
++
++    /* We're done with the device now.  */
++    (void)close(fd);
++
++    /* If there is no bus id, fail.  */
++    if (buf == NULL)
++	return -ENODEV;
++
++    /* Parse the bus id.  */
++    ret = sscanf(buf, "pci:%04x:%02x:%02x.%d", &domain, &bus, &dev, &func);
++
++    /* We're done with the bus id.  */
++    free(buf);
++
++    /* If scanf didn't return 4 -- domain, bus, dev, func -- then fail.  */
++    if (ret != 4)
++	return -ENODEV;
++
++    /* Populate the results.  */
++    info->domain = domain;
++    info->bus = bus;
++    info->dev = dev;
++    info->func = func;
++
++    /* Success!  */
++    return 0;
++#elif defined(__OpenBSD__)
+     struct drm_pciinfo pinfo;
+     int fd, type;
+ 
+@@ -3087,6 +3324,61 @@ static int drmParsePciBusInfo(int maj, i
+     info->func = pinfo.func;
+ 
+     return 0;
++#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++    /*
++     * Only the primary nodes can be mapped to hw.dri.%i via major/minor
++     * Determine the primary node by offset and use its major/minor pair
++     */
++    if (node_type != DRM_NODE_PRIMARY) {
++        char name[DRM_NODE_NAME_MAX];
++        snprintf(name, sizeof(name), DRM_DEV_NAME, DRM_DIR_NAME,
++                 drmGetNodeNumber(node) - drmGetMinorBase(node_type));
++
++        stat_t sbuf;
++        if (stat(name, &sbuf))
++            return -errno;
++
++        maj = major(sbuf.st_rdev);
++        min = minor(sbuf.st_rdev);
++
++    }
++    /*
++     * Major/minor appear after the driver name in the hw.dri.%i.name node
++     * Find the node with matching major/minor pair and parse the bus ID,
++     * which may be after the name or may be alone in hw.dri.%i.busid
++     */
++    #define bus_fmt "pci:%04x:%02x:%02x.%u"
++    #define name_fmt "%*s %x " bus_fmt
++    for (int i = 0; i < DRM_MAX_MINOR; ++i) {
++        char name[16], value[256];
++        size_t length = sizeof(value);
++        snprintf(name, sizeof(name), "hw.dri.%i.name", i);
++        if (sysctlbyname(name, value, &length, NULL, 0))
++            continue;
++
++        value[length] = '\0';
++        unsigned int rdev = 0, domain = 0, bus = 0, slot = 0, func = 0;
++        int vals = sscanf(value, name_fmt, &rdev, &domain, &bus, &slot, &func);
++
++	if (vals >= 1 && rdev == makedev(maj,min)) {
++            if (vals < 5) {
++                /* busid not in the name, try busid */
++                length = sizeof(value);
++                snprintf(name, sizeof(name), "hw.dri.%i.busid", i);
++                if (sysctlbyname(name, value, &length, NULL, 0))
++                    break;
++                value[length] = '\0';
++                if (sscanf(value, bus_fmt, &domain, &bus, &slot, &func) != 4)
++                    break;
++            }
++            info->domain = domain;
++            info->bus = bus;
++            info->dev = slot;
++            info->func = func;
++            return 0;
++        }
++    }
++    return -ENODEV;
+ #else
+ #warning "Missing implementation of drmParsePciBusInfo"
+     return -EINVAL;
+@@ -3135,7 +3427,11 @@ static int drmGetNodeType(const char *na
+         sizeof(DRM_RENDER_MINOR_NAME) - 1) == 0)
+         return DRM_NODE_RENDER;
+ 
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++    return -1;
++#else /* !__FreeBSD__ || __DragonFly__ */
+     return -EINVAL;
++#endif /* __FreeBSD__ || __DragonFly__ */
+ }
+ 
+ static int drmGetMaxNodeName(void)
+@@ -3218,6 +3514,9 @@ static int parse_config_sysfs_file(int m
+ #endif
+ 
+ static int drmParsePciDeviceInfo(int maj, int min,
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++                                 drmPciBusInfoPtr info,
++#endif
+                                  drmPciDeviceInfoPtr device,
+                                  uint32_t flags)
+ {
+@@ -3229,7 +3528,49 @@ static int drmParsePciDeviceInfo(int maj
+         return parse_config_sysfs_file(maj, min, device);
+ 
+     return 0;
+-#elif defined(__OpenBSD__) || defined(__DragonFly__)
++#elif defined(__NetBSD__)
++    drmPciBusInfo businfo;
++    char fname[PATH_MAX];
++    int pcifd;
++    pcireg_t id, class, subsys;
++    int ret;
++
++    /* Find where on the bus the device lives.  */
++    ret = drmParsePciBusInfo(maj, min, &businfo);
++    if (ret)
++	return ret;
++
++    /* Open the pciN device node to get at its config registers.  */
++    if (snprintf(fname, sizeof fname, "/dev/pci%u", businfo.domain)
++	>= sizeof fname)
++	return -ENODEV;
++    if ((pcifd = open(fname, O_RDONLY)) == -1)
++	return -errno;
++
++    ret = -1;
++    /* Read the id and class pci config registers.  */
++    if (pcibus_conf_read(pcifd, businfo.bus, businfo.dev, businfo.func,
++	    PCI_ID_REG, &id) == -1)
++	goto out;
++    if (pcibus_conf_read(pcifd, businfo.bus, businfo.dev, businfo.func,
++	    PCI_CLASS_REG, &class) == -1)
++	goto out;
++    if (pcibus_conf_read(pcifd, businfo.bus, businfo.dev, businfo.func,
++	    PCI_SUBSYS_ID_REG, &subsys) == -1)
++	goto out;
++
++    ret = 0;
++    device->vendor_id = PCI_VENDOR(id);
++    device->device_id = PCI_PRODUCT(id);
++    device->subvendor_id = PCI_SUBSYS_VENDOR(subsys);
++    device->subdevice_id = PCI_SUBSYS_ID(subsys);
++    device->revision_id = PCI_REVISION(class);
++out:
++    if (ret == -1)
++	ret = -errno;
++    close(pcifd);
++    return ret;
++#elif defined(__OpenBSD__)
+     struct drm_pciinfo pinfo;
+     int fd, type;
+ 
+@@ -3254,6 +3595,43 @@ static int drmParsePciDeviceInfo(int maj
+     device->subdevice_id = pinfo.subdevice_id;
+ 
+     return 0;
++#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++    struct pci_conf_io pc;
++    struct pci_match_conf patterns[1];
++    struct pci_conf results[1];
++
++    int fd = open("/dev/pci", O_RDONLY, 0);
++    if (fd < 0)
++        return -errno;
++
++    bzero(&patterns, sizeof(patterns));
++    patterns[0].pc_sel.pc_domain = info->domain;
++    patterns[0].pc_sel.pc_bus = info->bus;
++    patterns[0].pc_sel.pc_dev = info->dev;
++    patterns[0].pc_sel.pc_func = info->func;
++    patterns[0].flags = PCI_GETCONF_MATCH_DOMAIN | PCI_GETCONF_MATCH_BUS
++                      | PCI_GETCONF_MATCH_DEV | PCI_GETCONF_MATCH_FUNC;
++    bzero(&pc, sizeof(struct pci_conf_io));
++    pc.num_patterns = 1;
++    pc.pat_buf_len = sizeof(patterns);
++    pc.patterns = patterns;
++    pc.match_buf_len = sizeof(results);
++    pc.matches = results;
++
++    if (ioctl(fd, PCIOCGETCONF, &pc) || pc.status == PCI_GETCONF_ERROR) {
++        int error = errno;
++        close(fd);
++        return -error;
++    }
++    close(fd);
++
++    device->vendor_id = results[0].pc_vendor;
++    device->device_id = results[0].pc_device;
++    device->subvendor_id = results[0].pc_subvendor;
++    device->subdevice_id = results[0].pc_subdevice;
++    device->revision_id = results[0].pc_revid;
++
++    return 0;
+ #else
+ #warning "Missing implementation of drmParsePciDeviceInfo"
+     return -EINVAL;
+@@ -3380,18 +3758,42 @@ static int drmProcessPciDevice(drmDevice
+ 
+     dev->businfo.pci = (drmPciBusInfoPtr)addr;
+ 
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++    ret = drmParsePciBusInfo(node, node_type, maj, min, dev->businfo.pci);
++#else
+     ret = drmParsePciBusInfo(maj, min, dev->businfo.pci);
++#endif
+     if (ret)
+         goto free_device;
+ 
++    drmMsg("[drm] drmProcessPciDevice: DOMAIN    (%04x)\n", dev->businfo.pci->domain);
++    drmMsg("[drm] drmProcessPciDevice: BUS       (%02x)\n", dev->businfo.pci->bus);
++    drmMsg("[drm] drmProcessPciDevice: DEV       (%02x)\n", dev->businfo.pci->dev);
++    drmMsg("[drm] drmProcessPciDevice: FUNC      (%1u)\n",  dev->businfo.pci->func);
++
+     // Fetch the device info if the user has requested it
+     if (fetch_deviceinfo) {
+         addr += sizeof(drmPciBusInfo);
+         dev->deviceinfo.pci = (drmPciDeviceInfoPtr)addr;
+ 
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++        ret = drmParsePciDeviceInfo(maj, min, dev->businfo.pci, dev->deviceinfo.pci, flags);
++#else
+         ret = drmParsePciDeviceInfo(maj, min, dev->deviceinfo.pci, flags);
++#endif
+         if (ret)
+             goto free_device;
++
++        drmMsg("[drm] drmProcessPciDevice: VENDOR    (%04x)\n",
++            dev->deviceinfo.pci->vendor_id);
++        drmMsg("[drm] drmProcessPciDevice: DEVICE    (%04x)\n",
++            dev->deviceinfo.pci->device_id);
++        drmMsg("[drm] drmProcessPciDevice: SUBVENDOR (%04x)\n",
++            dev->deviceinfo.pci->subvendor_id);
++        drmMsg("[drm] drmProcessPciDevice: SUBDEVICE (%04x)\n",
++            dev->deviceinfo.pci->subdevice_id);
++        drmMsg("[drm] drmProcessPciDevice: REVISION  (%02x)\n",
++            dev->deviceinfo.pci->revision_id);
+     }
+ 
+     *device = dev;
+@@ -4099,6 +4501,23 @@ drm_public char *drmGetDeviceNameFromFd2
+     free(value);
+ 
+     return strdup(path);
++#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++    stat_t sbuf;
++    if (fstat(fd, &sbuf))
++        return NULL;
++
++    dev_t rdev = sbuf.st_rdev;
++    /* minor numbers don't depend on node name suffix, search for a match */
++    for (int i = 0; i < DRM_MAX_MINOR; ++i) {
++        char node[DRM_NODE_NAME_MAX];
++        for (int j = 0; j < DRM_NODE_MAX; ++j) {
++            snprintf(node, sizeof(node), drmGetDeviceName(j),
++                     DRM_DIR_NAME, drmGetMinorBase(j) + i);
++            if (stat(node, &sbuf) == 0 && sbuf.st_rdev == rdev)
++                return strdup(node);
++        }
++    }
++    return NULL;
+ #else
+     struct stat      sbuf;
+     char             node[PATH_MAX + 1];
diff --git a/libdrm-dfbsd-meson/patches/patch-xf86drmMode.c b/libdrm-dfbsd-meson/patches/patch-xf86drmMode.c
new file mode 100644
index 0000000000..88fcd336c9
--- /dev/null
+++ b/libdrm-dfbsd-meson/patches/patch-xf86drmMode.c
@@ -0,0 +1,124 @@
+$NetBSD: patch-xf86drmMode.c,v 1.5 2019/01/19 13:21:29 tnn Exp $
+ 
+FreeBSD/DragonFly/NetBSD support. From FreeBSD ports and NetBSD xsrc
+
+FreeBSD ports / DragonFly dports does not have patch for drmModeSetPlane.
+Android deliberately uses signed crtc_x and crtc_y
+"to allow a destination location that is partially off screen."
+
+--- xf86drmMode.c.orig	2018-10-16 14:49:03.000000000 +0000
++++ xf86drmMode.c
+@@ -43,6 +43,9 @@
+ #include <stdlib.h>
+ #include <sys/ioctl.h>
+ #ifdef HAVE_SYS_SYSCTL_H
++#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__)
++#include <sys/types.h>
++#endif
+ #include <sys/sysctl.h>
+ #endif
+ #include <stdio.h>
+@@ -799,42 +802,60 @@ drm_public int drmCheckModesettingSuppor
+ 	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;
++#elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__DragonFly__)
++	#define bus_fmt "pci:%04x:%02x:%02x.%u"
++	#define name_fmt "%*s %*s " bus_fmt
++	unsigned int d1 = 0, b1 = 0, s1 = 0, f1 = 0;
++	if (sscanf(busid, bus_fmt, &d1, &b1, &s1, &f1) != 4)
++                return -EINVAL;
++	/*
++	 * hw.dri.%i.bus is not always present and hw.dri.%i.name does not
++	 * always contain the busid, so try both for best chance of success
++	 */
++	for (int i = 0; i < DRM_MAX_MINOR; ++i) {
++		char name[22], value[256];
++		size_t length = sizeof(value);
++		snprintf(name, sizeof(name), "hw.dri.%i.name", i);
++		if (sysctlbyname(name, value, &length, NULL, 0))
++			continue;
+ 
+-	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);
++		value[length] = '\0';
++		unsigned int d2 = 0, b2 = 0, s2 = 0, f2 = 0;
++		switch (sscanf(value, name_fmt, &d2, &b2, &s2, &f2)) {
++		case 0: /* busid not in the name, try busid */
++			length = sizeof(value);
++			snprintf(name, sizeof(name), "hw.dri.%i.busid", i);
++			if (sysctlbyname(name, value, &length, NULL, 0))
++				continue;
+ 
+-	/* 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)
++			value[length] = '\0';
++			if (sscanf(value, bus_fmt, &d2, &b2, &s2, &f2) != 4)
+ 				continue;
+-			return -EINVAL;
++			/* fall through after parsing busid */
++
++		case 4: /* if we jumped here then busid was in the name */ 
++			if (d1 == d2 && b1 == b2 && s1 == s2 && f1 == f2) {
++			/*
++			 * Confirm the drm driver for this device supports KMS,
++			 * except on DragonFly where all the drm drivers do so
++			 * but only hw.dri.0.modesetting is present
++			 */ 
++			#ifndef __DragonFly__
++				int modesetting = 0;
++				length = sizeof(modesetting);
++				snprintf(name, sizeof(name), "hw.dri.%i.modesetting", i);
++				if (sysctlbyname(name, &modesetting, &length, NULL, 0)
++				 || length != sizeof(modesetting) || !modesetting)
++					return -ENOSYS;
++				else
++			#endif
++					return 0;
++			}
++		default:
++			break;
+ 		}
+-		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);
+ 	}
+-#elif defined(__DragonFly__)
+-	return 0;
+-#elif defined(__OpenBSD__)
++#elif defined(__OpenBSD__) || defined(__NetBSD__)
+ 	int	fd;
+ 	struct drm_mode_card_res res;
+ 	drmModeResPtr r = 0;
+@@ -987,7 +1008,11 @@ drm_public int drmModePageFlipTarget(int
+ 
+ drm_public int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
+ 		    uint32_t fb_id, uint32_t flags,
++#if !defined(__FreeBSD__) && !defined(__DragonFly__)
++		    uint32_t crtc_x, uint32_t crtc_y,
++#else
+ 		    int32_t crtc_x, int32_t crtc_y,
++#endif
+ 		    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-meson/patches/patch-xf86drmMode.h b/libdrm-dfbsd-meson/patches/patch-xf86drmMode.h
new file mode 100644
index 0000000000..0a7ac6a007
--- /dev/null
+++ b/libdrm-dfbsd-meson/patches/patch-xf86drmMode.h
@@ -0,0 +1,20 @@
+$NetBSD: patch-xf86drmMode.h,v 1.1 2014/10/26 10:20:10 wiz Exp $
+
+FreeBSD ports / DragonFly dports does not have patch for drmModeSetPlane.
+Android deliberately uses signed crtc_x and crtc_y
+"to allow a destination location that is partially off screen."
+
+--- xf86drmMode.h.orig	2014-06-14 12:33:26.000000000 +0000
++++ xf86drmMode.h
+@@ -485,7 +485,11 @@ 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,
++#if !defined(__FreeBSD__) && !defined(__DragonFly__)
++			   uint32_t crtc_x, uint32_t crtc_y,
++#else
+ 			   int32_t crtc_x, int32_t crtc_y,
++#endif
+ 			   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