libdrm-dfbsd: Update wip/libdrm-dfbsd to 2.4.97

Have not switched over to DragonFly copying OpenBSD's ioctl yet.
This commit is contained in:
David Shao 2019-02-23 20:37:49 -08:00
parent 4a94d281fe
commit 859aad7056
13 changed files with 761 additions and 1315 deletions

View File

@ -1,6 +1,6 @@
# $NetBSD: Makefile,v 1.80 2018/03/07 12:12:35 wiz Exp $
# $NetBSD: Makefile,v 1.91 2019/01/22 21:50:47 wiz Exp $
DISTNAME= libdrm-2.4.91
DISTNAME= libdrm-2.4.97
CATEGORIES= x11 graphics
MASTER_SITES= http://dri.freedesktop.org/libdrm/
EXTRACT_SUFX= .tar.bz2
@ -16,14 +16,13 @@ USE_PKGLOCALEDIR= yes
USE_TOOLS+= gmake pkg-config
USE_LIBTOOL= yes
PKGCONFIG_OVERRIDE+= libdrm.pc.in
PKGCONFIG_OVERRIDE+= libkms.pc.in
GNU_CONFIGURE= yes
.include "../../mk/bsd.prefs.mk"
SUBST_CLASSES+= atomic
SUBST_FILES.atomic= xf86drm.h
SUBST_MESSAGE.atomic= Configuring xf86drm.h atomic operations.
SUBST_MESSAGE.atomic= Configuring xf86drm.h s atomic operations.
SUBST_STAGE.atomic= pre-configure
SUBST_VARS.atomic= ATOMIC_OPS_CHECK
@ -38,9 +37,13 @@ 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
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,
@ -56,29 +59,22 @@ PLIST.arm= yes
.endif
PKG_OPTIONS_VAR= PKG_OPTIONS.libdrm
PKG_SUPPORTED_OPTIONS= pthreadstubs libkms
PKG_SUGGESTED_OPTIONS+= pthreadstubs
PKG_SUPPORTED_OPTIONS= libkms
PKG_SUGGESTED_OPTIONS=
.if !empty(MACHINE_ARCH:Mi386) || !empty(MACHINE_ARCH:Mx86_64)
PKG_SUGGESTED_OPTIONS+= libkms
.endif
# avoid circular dependency in case cairo supports OpenGL (cairo->mesa-libs->libdrm->cairo)
CONFIGURE_ARGS+= --disable-cairo-tests
# .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
PLIST_VARS+= libkms
.if !empty(PKG_OPTIONS:Mlibkms)
PLIST.libkms= yes
PKGCONFIG_OVERRIDE+= libkms.pc.in
PLIST.libkms= yes
CONFIGURE_ARGS+= --enable-libkms
.else
CONFIGURE_ARGS+= --disable-libkms
#CONFIGURE_ARGS+= --disable-libkms
.endif
.include "../../mk/bsd.pkg.mk"

View File

@ -1,4 +1,4 @@
@comment $NetBSD: PLIST,v 1.20 2017/08/26 05:47:56 wiz Exp $
@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
@ -13,6 +13,7 @@ ${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

View File

@ -1,8 +1,10 @@
# $NetBSD: builtin.mk,v 1.3 2014/03/10 11:05:53 jperkin Exp $
# $NetBSD: builtin.mk,v 1.4 2018/06/01 15:05:43 maya Exp $
BUILTIN_PKG:= libdrm
PKGCONFIG_FILE.libdrm= ${X11BASE}/lib/pkgconfig/libdrm.pc
PKGCONFIG_FILE.libdrm+= ${X11BASE}/lib${LIBABISUFFIX}/pkgconfig/libdrm.pc
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"

View File

@ -1,15 +1,14 @@
$NetBSD: distinfo,v 1.80 2018/03/07 12:12:35 wiz Exp $
$NetBSD: distinfo,v 1.92 2019/01/22 21:50:47 wiz Exp $
SHA1 (libdrm-2.4.91.tar.bz2) = 44e42ce3cd41666e343ba393c73f6f1ad9fe1e74
RMD160 (libdrm-2.4.91.tar.bz2) = d1c35b94703fdfb944c54451fe65977d24d7a568
SHA512 (libdrm-2.4.91.tar.bz2) = 07578c00c121ba37033db7172590e26d1545f81c242bbce2cfb7fb904bde504822c275d6468e5c5d20360d0046ae73d9b058aa0459ba35eb11927141cc998772
Size (libdrm-2.4.91.tar.bz2) = 815419 bytes
SHA1 (patch-ab) = c2d32279cbf91e57ee1fd1d237186e029ebaffaf
SHA1 (patch-ac) = 87d34e929f6ebeaa7991d343b3025a0a3b276329
SHA1 (libdrm-2.4.97.tar.bz2) = 7635bec769a17edd140282fa2c46838c4a44bc91
RMD160 (libdrm-2.4.97.tar.bz2) = eb9b715aef37af8b879f45fb2ee5fbb9adbba31b
SHA512 (libdrm-2.4.97.tar.bz2) = 3e08ee9d6c9ce265d783a59b51e22449905ea73aa27f25a082a1e9e1532f7c99e1c9f7cb966eb0970be2a08e2e5993dc9aa55093b1bff548689fdb465e7145ed
Size (libdrm-2.4.97.tar.bz2) = 837329 bytes
SHA1 (patch-ac) = 67c998df7dfc0dabc86320ea6d015cede3e464ea
SHA1 (patch-include_drm_drm.h) = 48a912f40bf2b2a1c23edbe4446fa7869212f17b
SHA1 (patch-libkms_vmwgfx.c) = 159228d66cfa12bbbad268a8881ffdf5127799b5
SHA1 (patch-libsync.h) = 937d1150bf816e5f7809fa96ad7f981895bf99f5
SHA1 (patch-radeon_radeon__bo__gem.c) = 93a9238277f40813b3d1c1e6984106657d654dc7
SHA1 (patch-radeon_radeon__cs__gem.c) = 5cc9bd1a5f62fb380f9f92b7ce1c44769b35c751
SHA1 (patch-libkms_vmwgfx.c) = de56a4f1724bef5f237f183eca889b8cef3b81af
SHA1 (patch-libsync.h) = 1e0603e72a54a069fc9d2ab2c9559d22381a69d3
SHA1 (patch-xf86atomic.h) = 887db95db00125bdfa1ab298b2ccc555dec70366
SHA1 (patch-xf86drmMode.c) = ad3c2c9188e6582c4f311851bd366ad873455750
SHA1 (patch-xf86drm.c) = 3cd8c6a6e26728d92ec3fc03cfffa778a65c286b
SHA1 (patch-xf86drmMode.c) = d7c6617ef54f76dc3dac00098adbb2f6fb02d685
SHA1 (patch-xf86drmMode.h) = 265989e670cc7ead9bb5002e116e5ab56439ede6

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
$NetBSD: patch-ac,v 1.4 2012/02/16 20:30:56 hans Exp $
--- xf86drm.h.orig 2017-12-18 01:33:10.000000000 +0000
--- xf86drm.h.orig 2010-03-05 23:21:13.000000000 +0000
+++ xf86drm.h
@@ -35,7 +35,11 @@
#define _XF86DRM_H_
@ -14,7 +14,7 @@ $NetBSD: patch-ac,v 1.4 2012/02/16 20:30:56 hans Exp $
#include <stdint.h>
#include <drm.h>
@@ -59,6 +63,9 @@ extern "C" {
@@ -55,6 +59,9 @@
#else /* One of the *BSDs */
#include <sys/ioccom.h>
@ -24,42 +24,7 @@ $NetBSD: patch-ac,v 1.4 2012/02/16 20:30:56 hans Exp $
#define DRM_IOCTL_NR(n) ((n) & 0xff)
#define DRM_IOC_VOID IOC_VOID
#define DRM_IOC_READ IOC_OUT
@@ -78,17 +85,28 @@ extern "C" {
#ifdef __OpenBSD__
#define DRM_DIR_NAME "/dev"
-#define DRM_DEV_NAME "%s/drm%d"
-#define DRM_CONTROL_DEV_NAME "%s/drmC%d"
-#define DRM_RENDER_DEV_NAME "%s/drmR%d"
+#define DRM_PRIMARY_MINOR_NAME "drm"
+#define DRM_CONTROL_MINOR_NAME "drmC"
+#define DRM_RENDER_MINOR_NAME "drmR"
#else
#define DRM_DIR_NAME "/dev/dri"
-#define DRM_DEV_NAME "%s/card%d"
-#define DRM_CONTROL_DEV_NAME "%s/controlD%d"
-#define DRM_RENDER_DEV_NAME "%s/renderD%d"
+#define DRM_PRIMARY_MINOR_NAME "card"
+#define DRM_CONTROL_MINOR_NAME "controlD"
+#define DRM_RENDER_MINOR_NAME "renderD"
#define DRM_PROC_NAME "/proc/dri/" /* For backward Linux compatibility */
#endif
+#define DRM_DEV_NAME "%s/" DRM_PRIMARY_MINOR_NAME "%d"
+#define DRM_CONTROL_DEV_NAME "%s/" DRM_CONTROL_MINOR_NAME "%d"
+#define DRM_RENDER_DEV_NAME "%s/" DRM_RENDER_MINOR_NAME "%d"
+
+#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 + 3) /* length of the node number */
+
#define DRM_ERR_NO_DEVICE (-1001)
#define DRM_ERR_NO_ACCESS (-1002)
#define DRM_ERR_NOT_ROOT (-1003)
@@ -354,7 +372,12 @@ typedef struct _drmSetVersion {
@@ -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 */

View File

@ -8,13 +8,13 @@ From FreeBSD ports for graphics/libdrm version 2.4.84
# 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
# define ERESTART if we still don't have it after including errno.h
--- libkms/vmwgfx.c.orig 2017-11-03 16:44:27.000000000 +0000
--- libkms/vmwgfx.c.orig 2015-05-06 23:04:31.000000000 +0000
+++ libkms/vmwgfx.c
@@ -30,15 +30,31 @@
#include "config.h"
#endif
@@ -26,10 +26,22 @@
**************************************************************************/
+#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
+#define _WANT_KERNEL_ERRNO
@ -25,22 +25,13 @@ From FreeBSD ports for graphics/libdrm version 2.4.84
#include <stdlib.h>
#include <string.h>
#include "internal.h"
+#ifndef ERESTART
+#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__)
+#ifndef ERESTART
+#define ERESTART (-1)
+#endif
+#else
+#ifndef ERESTART
+#define ERESTART 85
+#endif /* __FreeBSD__ || __DragonFly__ */
+#endif
+#endif
+
#include "xf86drm.h"
#include "libdrm_macros.h"
#include "vmwgfx_drm.h"
+
struct vmwgfx_bo
{
struct kms_bo base;

View File

@ -1,18 +1,24 @@
$NetBSD$
$NetBSD: patch-libsync.h,v 1.3 2019/01/22 21:50:47 wiz Exp $
From FreeBSD ports x11/libdrm 2.4.84
Fix public header on SunOS.
If ETIME is not defined, use ETIMEDOUT.
# define ETIME as ETIMEOUT same as done in Mesa
--- libsync.h.orig 2017-11-03 16:44:27.000000000 +0000
--- libsync.h.orig 2019-01-22 16:32:41.000000000 +0000
+++ libsync.h
@@ -35,6 +35,9 @@
@@ -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

View File

@ -1,37 +0,0 @@
$NetBSD: patch-radeon_radeon__bo__gem.c,v 1.1 2014/10/26 10:20:10 wiz Exp $
FreeBSD ports / DragonFly dports does not have this patch.
--- radeon/radeon_bo_gem.c.orig 2017-11-03 16:44:27.000000000 +0000
+++ radeon/radeon_bo_gem.c
@@ -178,8 +178,13 @@ static int bo_map(struct radeon_bo_int *
boi, boi->handle, r);
return r;
}
+#if defined(__FreeBSD__) || defined(__DragonFly__)
ptr = drm_mmap(0, args.size, PROT_READ|PROT_WRITE, MAP_SHARED, boi->bom->fd, args.addr_ptr);
if (ptr == MAP_FAILED)
+#else
+ r = drmMap(boi->bom->fd, args.addr_ptr, args.size, &ptr);
+ if (r)
+#endif
return -errno;
bo_gem->priv_ptr = ptr;
wait:
@@ -252,9 +257,16 @@ 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)
{
+#if defined(__FreeBSD__) || defined(__DragonFly__)
struct drm_radeon_gem_set_tiling args = {};
+#else
+ struct drm_radeon_gem_set_tiling args;
+#endif
int r;
+#if !defined(__FreeBSD__) && !defined(__DragonFly__)
+ memset(&args, 0, sizeof args);
+#endif
args.handle = boi->handle;
r = drmCommandWriteRead(boi->bom->fd,

View File

@ -1,23 +0,0 @@
$NetBSD: patch-radeon_radeon__cs__gem.c,v 1.1 2014/10/26 10:20:10 wiz Exp $
FreeBSD ports / DragonFly dports does not have this patch.
--- radeon/radeon_cs_gem.c.orig 2017-11-03 16:44:27.000000000 +0000
+++ radeon/radeon_cs_gem.c
@@ -528,9 +528,16 @@ static const struct radeon_cs_funcs rade
static int radeon_get_device_id(int fd, uint32_t *device_id)
{
+#if !defined(__FreeBSD__) && !defined(__DragonFly__)
+ struct drm_radeon_info info;
+#else
struct drm_radeon_info info = {};
+#endif
int r;
+#if !defined(__FreeBSD__) && !defined(__DragonFly__)
+ memset(&info, 0, sizeof info);
+#endif
*device_id = 0;
info.request = RADEON_INFO_DEVICE_ID;
info.value = (uintptr_t)device_id;

View File

@ -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];

View File

@ -1,19 +1,14 @@
$NetBSD: patch-xf86drmMode.c,v 1.2 2015/04/11 10:02:11 sevan Exp $
$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
Replace 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.
Use patch from FreeBSD ports / DragonFly dports graphics/libdrm 2.4.84.
Get rid of drmModeSetPlane patch (from NetBSD?)
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 2017-11-03 16:44:27.000000000 +0000
--- xf86drmMode.c.orig 2018-10-16 14:49:03.000000000 +0000
+++ xf86drmMode.c
@@ -47,6 +47,9 @@
@@ -43,6 +43,9 @@
#include <stdlib.h>
#include <sys/ioctl.h>
#ifdef HAVE_SYS_SYSCTL_H
@ -23,7 +18,7 @@ Android deliberately uses signed crtc_x and crtc_y
#include <sys/sysctl.h>
#endif
#include <stdio.h>
@@ -796,43 +799,75 @@ int drmCheckModesettingSupported(const c
@@ -799,42 +802,60 @@ drm_public int drmCheckModesettingSuppor
closedir(sysdir);
if (found)
return 0;
@ -33,15 +28,8 @@ Android deliberately uses signed crtc_x and crtc_y
- int domain, bus, dev, func;
- int i, modesetting, ret;
- size_t len;
-
- ret = sscanf(busid, "pci:%04x:%02x:%02x.%d", &domain, &bus, &dev,
- &func);
- if (ret != 4)
- return -EINVAL;
- snprintf(kbusid, sizeof(kbusid), "pci:%04x:%02x:%02x.%d", domain, bus,
- dev, func);
+#elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__)
+ #define bus_fmt "pci:%04x:%02x:%02x.%d"
+#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)
@ -53,10 +41,25 @@ Android deliberately uses signed crtc_x and crtc_y
+ 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.%d.name", i);
+ 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);
@ -64,23 +67,14 @@ Android deliberately uses signed crtc_x and crtc_y
- ret = sysctlbyname(oid, sbusid, &len, NULL, 0);
- if (ret == -1) {
- if (errno == ENOENT)
+ 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.%d.busid", i);
+ if (sysctlbyname(name, value, &length, NULL, 0))
continue;
- return -EINVAL;
+
+ value[length] = '\0';
+ if (sscanf(value, bus_fmt, &d2, &b2, &s2, &f2) != 4)
+ continue;
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)) {
+ 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
@ -110,24 +104,21 @@ Android deliberately uses signed crtc_x and crtc_y
- return (modesetting ? 0 : -ENOSYS);
}
-#elif defined(__DragonFly__)
+#elif 0 && defined(__DragonFly__)
return 0;
-#endif
-#ifdef __OpenBSD__
+#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;
+ ret = drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res);
+ drmClose(fd);
+ if (ret == 0)
+ return 0;
+#elif defined(__OpenBSD__)
- 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)

View File

@ -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);