pkgsrc-WIP-changes archive

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

libdrm-dfbsd: Fixes to enable full use on FreeBSD and DragonFly



Module Name:	pkgsrc-wip
Committed By:	David Shao <davshao%gmail.com@localhost>
Pushed By:	dshao
Date:		Mon Mar 6 20:19:50 2017 -0800
Changeset:	ba52b3693f78cd6d94eef1f5d6e160e83a6ea398

Modified Files:
	libdrm-dfbsd/Makefile
	libdrm-dfbsd/PLIST
	libdrm-dfbsd/TODO
	libdrm-dfbsd/distinfo
	libdrm-dfbsd/patches/patch-ab
	libdrm-dfbsd/patches/patch-xf86drmMode.c
Added Files:
	libdrm-dfbsd/patches/patch-intel_intel__decode.c
	libdrm-dfbsd/patches/patch-xf86atomic.h
Removed Files:
	libdrm-dfbsd/patches/patch-xf86drmMode.h

Log Message:
libdrm-dfbsd: Fixes to enable full use on FreeBSD and DragonFly

Changes:
* CRITICAL: FDO Bug 100077 libdrm atomic_add_unless() fix enabling
glxgears to function on DragonFly and FreeBSD

* Refinements to patch-xf86drm.c.

* Dropped commenting out FreeBSD check modesetting code since now
  works with latest xf86-video-intel git driver.

* Dropped api change for crtc from signed to unsigned.

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

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

diffstat:
 libdrm-dfbsd/Makefile                            |  27 +-
 libdrm-dfbsd/PLIST                               |   3 +
 libdrm-dfbsd/TODO                                |   4 +-
 libdrm-dfbsd/distinfo                            |   7 +-
 libdrm-dfbsd/patches/patch-ab                    | 340 ++++++++++++++++++++---
 libdrm-dfbsd/patches/patch-intel_intel__decode.c |  24 ++
 libdrm-dfbsd/patches/patch-xf86atomic.h          |  18 ++
 libdrm-dfbsd/patches/patch-xf86drmMode.c         |  64 +----
 libdrm-dfbsd/patches/patch-xf86drmMode.h         |  13 -
 9 files changed, 386 insertions(+), 114 deletions(-)

diffs:
diff --git a/libdrm-dfbsd/Makefile b/libdrm-dfbsd/Makefile
index faee8bbee9..30a78fcd9a 100644
--- a/libdrm-dfbsd/Makefile
+++ b/libdrm-dfbsd/Makefile
@@ -22,7 +22,7 @@ GNU_CONFIGURE=		yes
 
 SUBST_CLASSES+=		atomic
 SUBST_FILES.atomic=	xf86drm.h
-SUBST_MESSAGE.atomic=	Configuring xf86drm.h's atomic operations.
+SUBST_MESSAGE.atomic=	Configuring xf86drm.h atomic operations.
 SUBST_STAGE.atomic=	pre-configure
 SUBST_VARS.atomic=	ATOMIC_OPS_CHECK
 
@@ -34,8 +34,6 @@ ATOMIC_OPS_CHECK=	1
 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
 
@@ -52,4 +50,27 @@ PLIST.arm=	yes
 #.else
 #CONFIGURE_ARGS+=	--disable-intel
 .endif
+
+PKG_OPTIONS_VAR=	PKG_OPTIONS.libdrm
+PKG_SUPPORTED_OPTIONS=	pthreadstubs libkms
+
+.if !empty(MACHINE_ARCH:Mi386) || !empty(MACHINE_ARCH:Mx86_64)
+PKG_SUGGESTED_OPTIONS+=	libkms
+.endif
+
+.include "../../mk/bsd.options.mk"
+
+.if !empty(PKG_OPTIONS:Mpthreadstubs)
+CONFIGURE_ARGS+=	PTHREADSTUBS_CFLAGS=-I${PREFIX}/include \
+			PTHREADSTUBS_LIBS=-L${PREFIX}/lib
+.endif
+
+PLIST_VARS+=	libkms	
+.if !empty(PKG_OPTIONS:Mlibkms)
+PLIST.libkms=	yes
+CONFIGURE_ARGS+=	--enable-libkms
+.else
+CONFIGURE_ARGS+=	--disable-libkms
+.endif
+
 .include "../../mk/bsd.pkg.mk"
diff --git a/libdrm-dfbsd/PLIST b/libdrm-dfbsd/PLIST
index 26c39449a4..d49ebf1ffb 100644
--- a/libdrm-dfbsd/PLIST
+++ b/libdrm-dfbsd/PLIST
@@ -37,6 +37,7 @@ 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
@@ -51,6 +52,7 @@ ${PLIST.arm}lib/libdrm_freedreno.la
 ${PLIST.intel}lib/libdrm_intel.la
 lib/libdrm_nouveau.la
 lib/libdrm_radeon.la
+${PLIST.libkms}lib/libkms.la
 lib/pkgconfig/libdrm.pc
 lib/pkgconfig/libdrm_amdgpu.pc
 ${PLIST.arm}lib/pkgconfig/libdrm_freedreno.pc
@@ -58,3 +60,4 @@ ${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
diff --git a/libdrm-dfbsd/TODO b/libdrm-dfbsd/TODO
index a53cda6b51..58bcf6fcfd 100644
--- a/libdrm-dfbsd/TODO
+++ b/libdrm-dfbsd/TODO
@@ -1,5 +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
+Implements changes to libdrm to work with mesa 17.0.0 discussed in
 pkg/51795
-(x11/libdrm update xf86drm.c for mesa 13.0.2 needs negotiation)
+(x11/libdrm update xf86drm.c for mesa 17.0.0 needs negotiation)
diff --git a/libdrm-dfbsd/distinfo b/libdrm-dfbsd/distinfo
index 67f7ab5b14..1b3259311c 100644
--- a/libdrm-dfbsd/distinfo
+++ b/libdrm-dfbsd/distinfo
@@ -4,11 +4,12 @@ SHA1 (libdrm-2.4.75.tar.bz2) = 335c088a9b20c6ce1e113e7d6104c54e8f365f88
 RMD160 (libdrm-2.4.75.tar.bz2) = 884db510421504acf4707b79cb907cc4879ba30a
 SHA512 (libdrm-2.4.75.tar.bz2) = 7d30029dfc384024eb6a82a04122064366572f5888ac4594fd9e02bc0a22ed2d154bef1840bd24f0543b77460d6359d7e424d424e10f4256ee3c898041be2292
 Size (libdrm-2.4.75.tar.bz2) = 774589 bytes
-SHA1 (patch-ab) = a6b975875c2cc24a3d034be8cfdd87f47d8e9e99
+SHA1 (patch-ab) = 2ad6b3a7c296da3e20f440ba0d1ebc809deaa73d
 SHA1 (patch-ac) = 67c998df7dfc0dabc86320ea6d015cede3e464ea
 SHA1 (patch-include_drm_drm.h) = 48a912f40bf2b2a1c23edbe4446fa7869212f17b
+SHA1 (patch-intel_intel__decode.c) = b22124dc63e02cd1eb3d7f5346722701a6ebf916
 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
+SHA1 (patch-xf86atomic.h) = 5585ba346cb8836d295060875b0fb5c87a404660
+SHA1 (patch-xf86drmMode.c) = 29485f5d03d2538145599fd74a28e2d2acd7d8d6
diff --git a/libdrm-dfbsd/patches/patch-ab b/libdrm-dfbsd/patches/patch-ab
index 01b7ef2fbe..9a69a3bb60 100644
--- a/libdrm-dfbsd/patches/patch-ab
+++ b/libdrm-dfbsd/patches/patch-ab
@@ -1,6 +1,9 @@
 $NetBSD: patch-ab,v 1.8 2015/08/14 17:12:35 wiz Exp $
 
-Patches from OpenBSD xenocara adapted for NetBSD.
+Code for OpenBSD adapted for NetBSD.  Assumes NetBSD kernel has been
+patched to use drm ioctl number 0x0f.
+
+Patches from FreeBSD ports libdrm 2.4.75.
 
 Patches from https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=214580
 and code from libdevq 0.0.4.
@@ -9,6 +12,12 @@ Tries to account for DragonFly major number not well defined.
 
 Tries to account for FreeBSD device control64D to be ignored.
 
+Many debugging messages added for use with LIBGL_DEBUG=verbose.
+
+Added code to deduce node type from a device name such as dri/card0
+for FreeBSD, DragonFly, and NetBSD, OSes that support devname().
+Moved static drmGetNodeType() for drmGetNodeTypeFromFd().
+
 --- xf86drm.c.orig	2017-01-28 01:15:16.000000000 +0000
 +++ xf86drm.c
 @@ -31,6 +31,36 @@
@@ -107,7 +116,22 @@ Tries to account for FreeBSD device control64D to be ignored.
  #endif
  
  #define DRM_MSG_VERBOSITY 3
-@@ -548,6 +596,7 @@ static int drmGetMinorType(int minor)
+@@ -189,7 +237,14 @@ drmIoctl(int fd, unsigned long request,
+ 
+     do {
+         ret = ioctl(fd, request, arg);
++#if defined(__FreeBSD__)
++/*
++ * FreeBSD Bug 204174: error code 512 (ERESTARTSYS) leaked from kernel space.
++ */
++    } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == 512));
++#else
+     } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
++#endif
+     return ret;
+ }
+ 
+@@ -548,6 +603,7 @@ static int drmGetMinorType(int minor)
      }
  }
  
@@ -115,7 +139,7 @@ Tries to account for FreeBSD device control64D to be ignored.
  static const char *drmGetMinorName(int type)
  {
      switch (type) {
-@@ -561,6 +610,7 @@ static const char *drmGetMinorName(int t
+@@ -561,6 +617,7 @@ static const char *drmGetMinorName(int t
          return NULL;
      }
  }
@@ -123,19 +147,86 @@ Tries to account for FreeBSD device control64D to be ignored.
  
  /**
   * Open the device by bus ID.
-@@ -2734,7 +2784,11 @@ int drmGetNodeTypeFromFd(int fd)
-     maj = major(sbuf.st_rdev);
+@@ -2723,11 +2780,35 @@ char *drmGetDeviceNameFromFd(int fd)
+     return strdup(name);
+ }
+ 
++static int drmGetNodeType(const char *name)
++{
++    if (strncmp(name, DRM_PRIMARY_MINOR_NAME,
++        sizeof(DRM_PRIMARY_MINOR_NAME) - 1) == 0)
++        return DRM_NODE_PRIMARY;
++
++    if (strncmp(name, DRM_CONTROL_MINOR_NAME,
++        sizeof(DRM_CONTROL_MINOR_NAME ) - 1) == 0)
++        return DRM_NODE_CONTROL;
++
++    if (strncmp(name, DRM_RENDER_MINOR_NAME,
++        sizeof(DRM_RENDER_MINOR_NAME) - 1) == 0)
++        return DRM_NODE_RENDER;
++
++    return -EINVAL;
++}
++
+ int drmGetNodeTypeFromFd(int fd)
+ {
+     struct stat sbuf;
+     int maj, min, type;
+ 
++#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__)
++    char name[64];
++    char base_name[64];
++#endif
++
++    drmMsg("libdrm, file xf86drm.c, drmGetNodeTypeFromFd(): fd (%d)\n", fd);
++
+     if (fstat(fd, &sbuf))
+         return -1;
+ 
+@@ -2735,11 +2816,42 @@ int drmGetNodeTypeFromFd(int fd)
      min = minor(sbuf.st_rdev);
  
+     if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) {
 +#if defined(__DragonFly__)
-+    if (((maj != DRM_MAJOR) && (maj != maj_firstseen)) || (maj < 0) || !S_ISCHR(sbuf.st_mode)) {
++        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 {
++            errno = EINVAL;
++            return -1;
++        }
 +#else
-     if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) {
-+#endif
          errno = EINVAL;
          return -1;
++#endif
      }
-@@ -2833,6 +2887,15 @@ static char *drmGetMinorNameForFD(int fd
+ 
++#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__)
++    snprintf(name, sizeof(name), "%s",
++             devname(sbuf.st_rdev, S_IFCHR));
++
++    drmMsg("Name of device file (%s)\n", name);
++
++    memset(base_name, 0, sizeof(base_name));
++    sscanf(name, "dri/%s", base_name);
++
++    drmMsg("Basename of device file (%s)\n", base_name);
++
++    type = drmGetNodeType(base_name);
++#else
+     type = drmGetMinorType(min);
++#endif
++
++    drmMsg("Deduced fd node_type (%d)\n", type);
++
+     if (type == -1)
+         errno = ENODEV;
+     return type;
+@@ -2833,6 +2945,15 @@ static char *drmGetMinorNameForFD(int fd
  
  out_close_dir:
      closedir(sysdir);
@@ -151,7 +242,7 @@ Tries to account for FreeBSD device control64D to be ignored.
  #else
      struct stat sbuf;
      char buf[PATH_MAX + 1];
-@@ -2962,6 +3025,12 @@ static int drmParseSubsystemType(int maj
+@@ -2962,6 +3083,12 @@ static int drmParseSubsystemType(int maj
      return -EINVAL;
  #elif defined(__OpenBSD__)
      return DRM_BUS_PCI;
@@ -164,7 +255,7 @@ Tries to account for FreeBSD device control64D to be ignored.
  #else
  #warning "Missing implementation of drmParseSubsystemType"
      return -EINVAL;
-@@ -2993,18 +3062,27 @@ static int drmParsePciBusInfo(int maj, i
+@@ -2993,18 +3120,27 @@ static int drmParsePciBusInfo(int maj, i
      info->func = func;
  
      return 0;
@@ -193,12 +284,13 @@ Tries to account for FreeBSD device control64D to be ignored.
      if (drmIoctl(fd, DRM_IOCTL_GET_PCIINFO, &pinfo)) {
          close(fd);
          return -errno;
-@@ -3017,6 +3095,57 @@ static int drmParsePciBusInfo(int maj, i
+@@ -3017,6 +3153,58 @@ static int drmParsePciBusInfo(int maj, i
      info->func = pinfo.func;
  
      return 0;
 +#elif (defined(__FreeBSD__) || defined(__DragonFly__))
-+/* Read the hw.dri.$min.busid sysctl
++/*
++ * 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
 + */
@@ -224,7 +316,7 @@ Tries to account for FreeBSD device control64D to be ignored.
 +         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);
++         snprintf(sysctl_name, 31, "hw.dri.%d.name", min);
 +
 +         drmMsg("Reading sysctl_name (%s)\n", sysctl_name);
 +
@@ -251,7 +343,31 @@ Tries to account for FreeBSD device control64D to be ignored.
  #else
  #warning "Missing implementation of drmParsePciBusInfo"
      return -EINVAL;
-@@ -3145,9 +3274,89 @@ static int parse_config_sysfs_file(int m
+@@ -3051,23 +3239,6 @@ static int drmCompareBusInfo(drmDevicePt
+     return -1;
+ }
+ 
+-static int drmGetNodeType(const char *name)
+-{
+-    if (strncmp(name, DRM_PRIMARY_MINOR_NAME,
+-        sizeof(DRM_PRIMARY_MINOR_NAME) - 1) == 0)
+-        return DRM_NODE_PRIMARY;
+-
+-    if (strncmp(name, DRM_CONTROL_MINOR_NAME,
+-        sizeof(DRM_CONTROL_MINOR_NAME ) - 1) == 0)
+-        return DRM_NODE_CONTROL;
+-
+-    if (strncmp(name, DRM_RENDER_MINOR_NAME,
+-        sizeof(DRM_RENDER_MINOR_NAME) - 1) == 0)
+-        return DRM_NODE_RENDER;
+-
+-    return -EINVAL;
+-}
+-
+ static int drmGetMaxNodeName(void)
+ {
+     return sizeof(DRM_DIR_NAME) +
+@@ -3145,9 +3316,89 @@ static int parse_config_sysfs_file(int m
  }
  #endif
  
@@ -341,7 +457,7 @@ Tries to account for FreeBSD device control64D to be ignored.
  {
  #ifdef __linux__
      if (!(flags & DRM_DEVICE_GET_PCI_REVISION))
-@@ -3157,18 +3366,27 @@ static int drmParsePciDeviceInfo(int maj
+@@ -3157,18 +3408,27 @@ static int drmParsePciDeviceInfo(int maj
          return parse_config_sysfs_file(maj, min, device);
  
      return 0;
@@ -370,12 +486,13 @@ Tries to account for FreeBSD device control64D to be ignored.
      if (drmIoctl(fd, DRM_IOCTL_GET_PCIINFO, &pinfo)) {
          close(fd);
          return -errno;
-@@ -3182,6 +3400,82 @@ static int drmParsePciDeviceInfo(int maj
+@@ -3182,6 +3442,88 @@ static int drmParsePciDeviceInfo(int maj
      device->subdevice_id = pinfo.subdevice_id;
  
      return 0;
 +#elif defined(__FreeBSD__) || defined(__DragonFly__)
-+/* Adapted from function devq_device_get_pciid_full_from_fd(),
++/*
++ * 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, 
@@ -430,12 +547,17 @@ Tries to account for FreeBSD device control64D to be ignored.
 +#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=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=0x%04x device=0x%04x subvendor=0x%04x subdevice=0x%04x",
 +        &vendor_id, &device_id, &subvendor_id, &subdevice_id);
++    if (ret != 4) {
++        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);
++    }
 +#endif
 +    if (ret != 4) {
 +        errno = EINVAL;
@@ -453,7 +575,7 @@ Tries to account for FreeBSD device control64D to be ignored.
  #else
  #warning "Missing implementation of drmParsePciDeviceInfo"
      return -EINVAL;
-@@ -3299,6 +3593,9 @@ static int drmProcessPciDevice(drmDevice
+@@ -3299,6 +3641,9 @@ static int drmProcessPciDevice(drmDevice
      char *addr;
      int ret;
  
@@ -463,7 +585,7 @@ Tries to account for FreeBSD device control64D to be ignored.
      dev = drmDeviceAlloc(node_type, node, sizeof(drmPciBusInfo),
                           sizeof(drmPciDeviceInfo), &addr);
      if (!dev)
-@@ -3308,18 +3605,39 @@ static int drmProcessPciDevice(drmDevice
+@@ -3308,18 +3653,39 @@ static int drmProcessPciDevice(drmDevice
  
      dev->businfo.pci = (drmPciBusInfoPtr)addr;
  
@@ -503,10 +625,50 @@ Tries to account for FreeBSD device control64D to be ignored.
      }
  
      *device = dev;
-@@ -3773,6 +4091,11 @@ int drmGetDevice2(int fd, uint32_t flags
+@@ -3681,6 +4047,35 @@ drm_device_validate_flags(uint32_t flags
+         return (flags & ~DRM_DEVICE_GET_PCI_REVISION);
+ }
+ 
++#if defined(__FreeBSD__) || defined(__DragonFly__)
++/*
++ * XXX temporary workaround, because FreeBSD doesn't provide 
++ * pcibus device sysctl trees for renderD and controlD nodes (yet)
++ * Finds the corresponding /dev/dri/cardn device and also
++ * returns the number n.
++ */
++static int 
++drmBSDDeviceNameHack(const char *path, char *hacked_path, int length,
++                     int node_type)
++{
++    int start, number, base;
++    const char *errstr;
++
++    base = drmGetMinorBase(node_type);
++    if (node_type == DRM_NODE_RENDER) {
++        start = sizeof(DRM_RENDER_MINOR_NAME) - 1;
++    } else if (node_type == DRM_NODE_CONTROL) {
++        start = sizeof(DRM_CONTROL_MINOR_NAME) - 1;
++    } else {
++        start = sizeof(DRM_PRIMARY_MINOR_NAME) - 1;
++    }
++    number = strtonum(&(path[start]), 0, 256, &errstr) - base;
++    snprintf(hacked_path, length, "card%i", number);
++
++    return number;
++}
++#endif
++
+ /**
+  * Get information about the opened drm device
+  *
+@@ -3773,6 +4168,15 @@ int drmGetDevice2(int fd, uint32_t flags
      int max_count = 16;
      dev_t find_rdev;
  
++#if defined(__FreeBSD__) || defined(__DragonFly__)
++    char hacked_path[128];
++#endif
++
 +    drmMsg("libdrm, file xf86drm.c, drmGetDevice2(): fd (%d)\n", fd);
 +
 +    drmMsg("Before drm_device_validate_flags: flags (%d), DRM_DEVICE_GET_PCI_REVISION (%d)\n",
@@ -515,7 +677,7 @@ Tries to account for FreeBSD device control64D to be ignored.
      if (drm_device_validate_flags(flags))
          return -EINVAL;
  
-@@ -3786,15 +4109,35 @@ int drmGetDevice2(int fd, uint32_t flags
+@@ -3786,15 +4190,35 @@ int drmGetDevice2(int fd, uint32_t flags
      maj = major(sbuf.st_rdev);
      min = minor(sbuf.st_rdev);
  
@@ -551,11 +713,15 @@ Tries to account for FreeBSD device control64D to be ignored.
      sysdir = opendir(DRM_DIR_NAME);
      if (!sysdir) {
          ret = -errno;
-@@ -3803,10 +4146,22 @@ int drmGetDevice2(int fd, uint32_t flags
+@@ -3803,26 +4227,65 @@ int drmGetDevice2(int fd, uint32_t flags
  
      i = 0;
      while ((dent = readdir(sysdir))) {
 +
++#if defined(__FreeBSD__) || defined(__DragonFly__)
++        int number;
++#endif
++
 +        drmMsg("Examining dent->d_name (%s)\n", dent->d_name);
 +
          node_type = drmGetNodeType(dent->d_name);
@@ -565,16 +731,17 @@ Tries to account for FreeBSD device control64D to be ignored.
          if (node_type < 0)
              continue;
  
-+#if defined(__FreeBSD__)
-+/* FreeBSD has /dev/dri/control64D devices which are not relevant */
-+        if (node_type > 0)
-+            continue;
-+#endif
++#if defined(__FreeBSD__) || defined(__DragonFly__)
++        number = drmBSDDeviceNameHack(dent->d_name, hacked_path, 127,
++                                          node_type);
 +
++        snprintf(node, PATH_MAX, "%s/%s", DRM_DIR_NAME, hacked_path);
++#else
          snprintf(node, PATH_MAX, "%s/%s", DRM_DIR_NAME, dent->d_name);
++#endif
          if (stat(node, &sbuf))
              continue;
-@@ -3814,15 +4169,37 @@ int drmGetDevice2(int fd, uint32_t flags
+ 
          maj = major(sbuf.st_rdev);
          min = minor(sbuf.st_rdev);
  
@@ -593,34 +760,121 @@ Tries to account for FreeBSD device control64D to be ignored.
          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:
 +
++#if defined (__FreeBSD__) || defined(__DragonFly__)
++            drmMsg("Before drmProcessPciDevice(): number (%d), node_type (%d)\n",
++                number, node_type);
++
++            ret = drmProcessPciDevice(&d, node, node_type, maj, number, true, flags);
++#else
 +            drmMsg("Before drmProcessPciDevice(): min (%d), node_type (%d)\n",
 +                min, node_type);
 +
              ret = drmProcessPciDevice(&d, node, node_type, maj, min, true, flags);
-+
++#endif
 +            drmMsg("After drmProcessPciDevice():  return value (%d)\n", ret);
 +
              if (ret)
                  continue;
  
-@@ -3964,7 +4341,11 @@ int drmGetDevices2(uint32_t flags, drmDe
-         maj = major(sbuf.st_rdev);
+@@ -3938,6 +4401,15 @@ int drmGetDevices2(uint32_t flags, drmDe
+     int ret, i, node_count, device_count;
+     int max_count = 16;
+ 
++#if defined(__FreeBSD__) || defined(__DragonFly__)
++    char hacked_path[128];
++#endif
++
++    drmMsg("libdrm, file xf86drm.c, drmGetDevices2(): max_devices (%d)\n", max_devices);
++
++    drmMsg("Before drm_device_validate_flags: flags (%d), DRM_DEVICE_GET_PCI_REVISION (%d)\n",
++        flags, DRM_DEVICE_GET_PCI_REVISION);
++
+     if (drm_device_validate_flags(flags))
+         return -EINVAL;
+ 
+@@ -3953,11 +4425,23 @@ int drmGetDevices2(uint32_t flags, drmDe
+ 
+     i = 0;
+     while ((dent = readdir(sysdir))) {
++
++#if defined(__FreeBSD__) || defined(__DragonFly__)
++        int number;
++#endif
++
+         node_type = drmGetNodeType(dent->d_name);
+         if (node_type < 0)
+             continue;
+ 
++#if defined(__FreeBSD__) || defined(__DragonFly__)
++        number = drmBSDDeviceNameHack(dent->d_name, hacked_path, 127,
++                                          node_type);
++
++        snprintf(node, PATH_MAX, "%s/%s", DRM_DIR_NAME, hacked_path);
++#else
+         snprintf(node, PATH_MAX, "%s/%s", DRM_DIR_NAME, dent->d_name);
++#endif
+         if (stat(node, &sbuf))
+             continue;
+ 
+@@ -3965,7 +4449,22 @@ int drmGetDevices2(uint32_t flags, drmDe
          min = minor(sbuf.st_rdev);
  
+         if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
 +#if defined(__DragonFly__)
-+        if (((maj != DRM_MAJOR) && (maj != maj_firstseen)) || (maj < 0) || !S_ISCHR(sbuf.st_mode))
++        {
++            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 {
++                continue;
++            }
++        }
 +#else
-         if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
-+#endif
              continue;
++#endif
  
          subsystem_type = drmParseSubsystemType(maj, min);
+ 
+@@ -3974,8 +4473,13 @@ int drmGetDevices2(uint32_t flags, drmDe
+ 
+         switch (subsystem_type) {
+         case DRM_BUS_PCI:
++#if defined (__FreeBSD__) || defined(__DragonFly__)
++            ret = drmProcessPciDevice(&device, node, node_type,
++                                      maj, number, devices != NULL, flags);
++#else
+             ret = drmProcessPciDevice(&device, node, node_type,
+                                       maj, min, devices != NULL, flags);
++#endif
+             if (ret)
+                 continue;
+ 
+@@ -4095,6 +4599,21 @@ char *drmGetDeviceNameFromFd2(int fd)
+     free(value);
+ 
+     return strdup(path);
++#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__)
++    struct stat sbuf;
++    char path[64];
++
++    drmMsg("libdrm, file xf86drm.c, drmGetDeviceFromFd2(): fd (%d)\n", fd);
++
++    if (fstat(fd, &sbuf))
++        return NULL;
++
++    snprintf(path, sizeof(path), "/dev/%s",
++             devname(sbuf.st_rdev, S_IFCHR));
++
++    drmMsg("path from devname (%s)\n", path);
++
++    return strdup(path);
+ #else
+     struct stat      sbuf;
+     char             node[PATH_MAX + 1];
diff --git a/libdrm-dfbsd/patches/patch-intel_intel__decode.c b/libdrm-dfbsd/patches/patch-intel_intel__decode.c
new file mode 100644
index 0000000000..2359ea12e9
--- /dev/null
+++ b/libdrm-dfbsd/patches/patch-intel_intel__decode.c
@@ -0,0 +1,24 @@
+$NetBSD$
+
+intel: avoid null pointer dereference
+https://cgit.freedesktop.org/mesa/drm/commit/?id=5ee9cb4b4b6964bcd463b0490f3027e6ccfbf45a
+
+--- intel/intel_decode.c.orig	2016-12-13 02:45:20.000000000 +0000
++++ intel/intel_decode.c
+@@ -3899,7 +3899,7 @@ drm_intel_decode(struct drm_intel_decode
+ 	int ret;
+ 	unsigned int index = 0;
+ 	uint32_t devid;
+-	int size = ctx->base_count * 4;
++	int size;
+ 	void *temp;
+ 
+ 	if (!ctx)
+@@ -3909,6 +3909,7 @@ drm_intel_decode(struct drm_intel_decode
+ 	 * the batchbuffer.  This lets us avoid a bunch of length
+ 	 * checking in statically sized packets.
+ 	 */
++	size = ctx->base_count * 4;
+ 	temp = malloc(size + 4096);
+ 	memcpy(temp, ctx->base_data, size);
+ 	memset((char *)temp + size, 0xd0, 4096);
diff --git a/libdrm-dfbsd/patches/patch-xf86atomic.h b/libdrm-dfbsd/patches/patch-xf86atomic.h
new file mode 100644
index 0000000000..897c9dae1d
--- /dev/null
+++ b/libdrm-dfbsd/patches/patch-xf86atomic.h
@@ -0,0 +1,18 @@
+$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,7 @@ static inline int atomic_add_unless(atom
+ 	c = atomic_read(v);
+ 	while (c != unless && (old = atomic_cmpxchg(v, c, c + add)) != c)
+ 		c = old;
+-	return c == unless;
++	return c != unless;
+ }
+ 
+ #endif
diff --git a/libdrm-dfbsd/patches/patch-xf86drmMode.c b/libdrm-dfbsd/patches/patch-xf86drmMode.c
index bd843d66df..e780f109cd 100644
--- a/libdrm-dfbsd/patches/patch-xf86drmMode.c
+++ b/libdrm-dfbsd/patches/patch-xf86drmMode.c
@@ -1,25 +1,20 @@
 $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.
+Get rid of patch disabling checking for hw.dri.%d.modesetting on FreeBSD.
+This sysctl is only available if a KMS module is loaded.
+xf86-video-intel if checking for modesetting fails the first time
+tries to load the kernel module and then check again for modesetting. 
 
---- xf86drmMode.c.orig	2015-03-18 17:33:36.000000000 +0000
+Get rid of drmModeSetPlane patch (from NetBSD?)
+Android deliberately uses signed crtc_x and crtc_y
+"to allow a destination location that is partially off screen."
+
+--- xf86drmMode.c.orig	2017-01-28 01:15:16.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;
+@@ -829,6 +829,19 @@ int drmCheckModesettingSupported(const c
+ 			return -EINVAL;
+ 		return (modesetting ? 0 : -ENOSYS);
+ 	}
 +#elif defined(__NetBSD__)
 +	int fd;
 +	static const struct drm_mode_card_res zero_res;
@@ -28,29 +23,7 @@ check happens before X got a chance of loading the KMS module.
 + 
 +	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);
--	}
++		return -EINVAL;
 +	ret = drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res);
 +	drmClose(fd);
 +	if (ret == 0)
@@ -58,12 +31,3 @@ check happens before X got a chance of loading the KMS module.
  #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
deleted file mode 100644
index 8a20d90dc2..0000000000
--- a/libdrm-dfbsd/patches/patch-xf86drmMode.h
+++ /dev/null
@@ -1,13 +0,0 @@
-$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