View | Details | Raw Unified | Return to bug 243283 | Differences between
and this patch

Collapse All | Expand All

(-)graphics/libdrm/Makefile (-2 / +2 lines)
Lines 1-74 Link Here
1
# Created by: lesi@FreeBSD.org
1
# Created by: lesi@FreeBSD.org
2
# $FreeBSD$
2
# $FreeBSD$
3
3
4
PORTNAME=	libdrm
4
PORTNAME=	libdrm
5
PORTVERSION=	2.4.99
5
PORTVERSION=	2.4.100
6
PORTEPOCH=	1
6
PORTEPOCH=	2
7
CATEGORIES=	graphics x11
7
CATEGORIES=	graphics x11
8
MASTER_SITES=	https://dri.freedesktop.org/libdrm/
8
MASTER_SITES=	https://dri.freedesktop.org/libdrm/
9
9
10
MAINTAINER=	x11@FreeBSD.org
10
MAINTAINER=	x11@FreeBSD.org
11
COMMENT=	Userspace interface to kernel Direct Rendering Module services
11
COMMENT=	Userspace interface to kernel Direct Rendering Module services
12
12
13
LICENSE=	MIT
13
LICENSE=	MIT
14
14
15
BUILD_DEPENDS=	${LOCALBASE}/libdata/pkgconfig/pthread-stubs.pc:devel/libpthread-stubs
15
BUILD_DEPENDS=	${LOCALBASE}/libdata/pkgconfig/pthread-stubs.pc:devel/libpthread-stubs
16
LIB_DEPENDS=	libpciaccess.so:devel/libpciaccess
16
LIB_DEPENDS=	libpciaccess.so:devel/libpciaccess
17
17
18
USES=		gnome meson pkgconfig tar:bzip2
18
USES=		gnome meson pkgconfig tar:bzip2
19
USE_LDCONFIG=	yes
19
USE_LDCONFIG=	yes
20
20
21
OPTIONS_DEFINE=	MANPAGES TESTS
21
OPTIONS_DEFINE=	MANPAGES TESTS
22
OPTIONS_SUB=	yes
22
OPTIONS_SUB=	yes
23
23
24
TESTS_DESC=	Install test programs (which are always built)
24
TESTS_DESC=	Install test programs (which are always built)
25
25
26
.if defined(PACKAGE_BUILDING)
26
.if defined(PACKAGE_BUILDING)
27
OPTIONS_DEFAULT+=	MANPAGES
27
OPTIONS_DEFAULT+=	MANPAGES
28
.endif
28
.endif
29
29
30
MANPAGES_BUILD_DEPENDS=	${LOCALBASE}/share/xsl/docbook/manpages/docbook.xsl:textproc/docbook-xsl
30
MANPAGES_BUILD_DEPENDS=	${LOCALBASE}/share/xsl/docbook/manpages/docbook.xsl:textproc/docbook-xsl
31
MANPAGES_USE=		GNOME=libxslt:build
31
MANPAGES_USE=		GNOME=libxslt:build
32
MANPAGES_MESON_TRUE=	man-pages
32
MANPAGES_MESON_TRUE=	man-pages
33
33
34
TESTS_MESON_TRUE=	install-test-programs
34
TESTS_MESON_TRUE=	install-test-programs
35
35
36
# avoid circular dependency in case cairo supports OpenGL (cairo->mesa-libs->libdrm->cairo)
36
# avoid circular dependency in case cairo supports OpenGL (cairo->mesa-libs->libdrm->cairo)
37
CONFIGURE_ARGS+=	-Dcairo-tests=false
37
CONFIGURE_ARGS+=	-Dcairo-tests=false
38
38
39
.include <bsd.port.options.mk>
39
.include <bsd.port.options.mk>
40
40
41
.if ${ARCH} == amd64 || ${ARCH} == i386
41
.if ${ARCH} == amd64 || ${ARCH} == i386
42
PLIST_SUB+=	ARM_DRIVERS="@comment "
42
PLIST_SUB+=	ARM_DRIVERS="@comment "
43
PLIST_SUB+=	INTEL_DRIVER=""
43
PLIST_SUB+=	INTEL_DRIVER=""
44
PLIST_SUB+=	NOUVEAU_DRIVER=""
44
PLIST_SUB+=	NOUVEAU_DRIVER=""
45
PLIST_SUB+=	RADEON_DRIVERS=""
45
PLIST_SUB+=	RADEON_DRIVERS=""
46
.elif ${ARCH:Mpowerpc*}
46
.elif ${ARCH:Mpowerpc*}
47
PLIST_SUB+=	ARM_DRIVERS="@comment "
47
PLIST_SUB+=	ARM_DRIVERS="@comment "
48
PLIST_SUB+=	INTEL_DRIVER="@comment "
48
PLIST_SUB+=	INTEL_DRIVER="@comment "
49
PLIST_SUB+=	NOUVEAU_DRIVER=""
49
PLIST_SUB+=	NOUVEAU_DRIVER=""
50
PLIST_SUB+=	RADEON_DRIVERS=""
50
PLIST_SUB+=	RADEON_DRIVERS=""
51
.elif ${ARCH} == aarch64
51
.elif ${ARCH} == aarch64
52
PLIST_SUB+=	ARM_DRIVERS=""
52
PLIST_SUB+=	ARM_DRIVERS=""
53
PLIST_SUB+=	INTEL_DRIVER="@comment "
53
PLIST_SUB+=	INTEL_DRIVER="@comment "
54
PLIST_SUB+=	NOUVEAU_DRIVER=""
54
PLIST_SUB+=	NOUVEAU_DRIVER=""
55
PLIST_SUB+=	RADEON_DRIVERS=""
55
PLIST_SUB+=	RADEON_DRIVERS=""
56
.elif ${ARCH:Marm*}
56
.elif ${ARCH:Marm*}
57
PLIST_SUB+=	ARM_DRIVERS=""
57
PLIST_SUB+=	ARM_DRIVERS=""
58
PLIST_SUB+=	INTEL_DRIVER="@comment "
58
PLIST_SUB+=	INTEL_DRIVER="@comment "
59
PLIST_SUB+=	NOUVEAU_DRIVER="@comment "
59
PLIST_SUB+=	NOUVEAU_DRIVER="@comment "
60
PLIST_SUB+=	RADEON_DRIVERS="@comment "
60
PLIST_SUB+=	RADEON_DRIVERS="@comment "
61
.else
61
.else
62
PLIST_SUB+=	ARM_DRIVERS="@comment "
62
PLIST_SUB+=	ARM_DRIVERS="@comment "
63
PLIST_SUB+=	INTEL_DRIVER="@comment "
63
PLIST_SUB+=	INTEL_DRIVER="@comment "
64
PLIST_SUB+=	NOUVEAU_DRIVER="@comment "
64
PLIST_SUB+=	NOUVEAU_DRIVER="@comment "
65
PLIST_SUB+=	RADEON_DRIVERS="@comment "
65
PLIST_SUB+=	RADEON_DRIVERS="@comment "
66
.endif
66
.endif
67
67
68
# This variable is not for users. So use a non-default name, intended for
68
# This variable is not for users. So use a non-default name, intended for
69
# people working on DRM kernel module development.
69
# people working on DRM kernel module development.
70
.if ${OPSYS} == FreeBSD && !defined(LIBDRM_SKIP_RETURN_PATCH)
70
.if ${OPSYS} == FreeBSD && !defined(LIBDRM_SKIP_RETURN_PATCH)
71
EXTRA_PATCHES+=	${FILESDIR}/extra-xf86drm.c
71
EXTRA_PATCHES+=	${FILESDIR}/extra-xf86drm.c
72
.endif
72
.endif
73
73
74
.include <bsd.port.mk>
74
.include <bsd.port.mk>
(-)graphics/libdrm/distinfo (-3 / +3 lines)
Lines 1-3 Link Here
1
TIMESTAMP = 1562265364
1
TIMESTAMP = 1578786811
2
SHA256 (libdrm-2.4.99.tar.bz2) = 4dbf539c7ed25dbb2055090b77ab87508fc46be39a9379d15fed4b5517e1da5e
2
SHA256 (libdrm-2.4.100.tar.bz2) = c77cc828186c9ceec3e56ae202b43ee99eb932b4a87255038a80e8a1060d0a5d
3
SIZE (libdrm-2.4.99.tar.bz2) = 853659
3
SIZE (libdrm-2.4.100.tar.bz2) = 855793
(-)graphics/libdrm/files/patch-meson.build (-23 lines)
Lines 1-23 Link Here
1
- sys/sysctl.h isn't self-sufficient
2
- tests don't use Bash features
3
4
--- meson.build.orig 2019-04-19 15:52:29 UTC
5
+++ meson.build
6
@@ -181,7 +181,7 @@ endif
7
 dep_m = cc.find_library('m', required : false)
8
 foreach header : ['sys/sysctl.h', 'sys/select.h', 'alloca.h']
9
   config.set('HAVE_' + header.underscorify().to_upper(),
10
-    cc.compiles('#include <@0@>'.format(header), name : '@0@ works'.format(header)))
11
+    cc.compiles('#include <sys/types.h>\n#include <@0@>'.format(header), name : '@0@ works'.format(header)))
12
 endforeach
13
 if cc.has_header_symbol('sys/sysmacros.h', 'major')
14
   config.set10('MAJOR_IN_SYSMACROS', true)
15
@@ -249,7 +249,7 @@ endif
16
 with_man_pages = with_man_pages != 'false' and prog_xslt.found() and prog_sed.found()
17
 
18
 # Used for tets
19
-prog_bash = find_program('bash')
20
+prog_bash = find_program('sh')
21
 
22
 config.set10('HAVE_VISIBILITY',
23
   cc.compiles('''int foo_hidden(void) __attribute__((visibility(("hidden"))));''',
(-)graphics/libdrm/files/patch-xf86drm.c (-183 / +38 lines)
Lines 1-749 Link Here
1
--- xf86drm.c.orig	2018-11-26 18:52:00 UTC
1
--- xf86drm.c.orig	2018-11-26 18:52:00 UTC
2
+++ xf86drm.c
2
+++ xf86drm.c
3
@@ -46,6 +46,9 @@
3
@@ -46,6 +46,9 @@
4
 #include <signal.h>
4
 #include <signal.h>
5
 #include <time.h>
5
 #include <time.h>
6
 #include <sys/types.h>
6
 #include <sys/types.h>
7
+#ifdef HAVE_SYS_SYSCTL_H
7
+#ifdef HAVE_SYS_SYSCTL_H
8
+#include <sys/sysctl.h>
8
+#include <sys/sysctl.h>
9
+#endif
9
+#endif
10
 #include <sys/stat.h>
10
 #include <sys/stat.h>
11
 #define stat_t struct stat
11
 #define stat_t struct stat
12
 #include <sys/ioctl.h>
12
 #include <sys/ioctl.h>
13
@@ -61,6 +64,10 @@
13
@@ -61,6 +64,10 @@
14
 
14
 
15
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
15
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
16
 
16
 
17
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
17
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
18
+#include <sys/pciio.h>
18
+#include <sys/pciio.h>
19
+#endif
19
+#endif
20
+
20
+
21
 /* Not all systems have MAP_FAILED defined */
21
 /* Not all systems have MAP_FAILED defined */
22
 #ifndef MAP_FAILED
22
 #ifndef MAP_FAILED
23
 #define MAP_FAILED ((void *)-1)
23
 #define MAP_FAILED ((void *)-1)
24
@@ -69,18 +76,8 @@
24
@@ -69,8 +76,8 @@
25
 
25
 
26
 #include "util_math.h"
26
 #include "util_math.h"
27
 
27
 
28
-#ifdef __OpenBSD__
29
-#define DRM_PRIMARY_MINOR_NAME  "drm"
30
-#define DRM_CONTROL_MINOR_NAME  "drmC"
31
-#define DRM_RENDER_MINOR_NAME   "drmR"
32
-#else
33
-#define DRM_PRIMARY_MINOR_NAME  "card"
34
-#define DRM_CONTROL_MINOR_NAME  "controlD"
35
-#define DRM_RENDER_MINOR_NAME   "renderD"
36
-#endif
37
-
38
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
28
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
39
-#define DRM_MAJOR 145
29
-#define DRM_MAJOR 145
40
+#define DRM_MAJOR 0	/* Major ID unused on systems with devfs */
30
+#define DRM_MAJOR 0	/* Major ID unused on systems with devfs */
41
 #endif
31
 #endif
42
 
32
 
43
 #ifdef __NetBSD__
33
 #ifdef __NetBSD__
44
@@ -222,6 +219,89 @@ drm_public drmHashEntry *drmGetEntry(int fd)
34
@@ -222,6 +229,75 @@ drm_public drmHashEntry *drmGetEntry(int fd)
45
     return entry;
35
     return entry;
46
 }
36
 }
47
 
37
48
+static int drmGetMinorBase(int type)
38
+static int drmGetMinorBase(int type)
49
+{
39
+{
50
+    switch (type) {
40
+    switch (type) {
51
+        case DRM_NODE_PRIMARY:
41
+        case DRM_NODE_PRIMARY:
52
+        case DRM_NODE_CONTROL:
42
+        case DRM_NODE_CONTROL:
53
+        case DRM_NODE_RENDER:
43
+        case DRM_NODE_RENDER:
54
+            return type << 6;
44
+            return type << 6;
55
+        default:
45
+        default:
56
+            return -1;
46
+            return -1;
57
+    };
47
+    };
58
+}
48
+}
59
+
49
+
60
+static int drmGetMinorType(int minor)
50
+static int drmGetMinorType(int minor)
61
+{
51
+{
62
+    if (minor < 0)
52
+    if (minor < 0)
63
+        return -1;
53
+        return -1;
64
+
54
+
65
+    int type = minor >> 6;
55
+    int type = minor >> 6;
66
+    switch (type) {
56
+    switch (type) {
67
+        case DRM_NODE_PRIMARY:
57
+        case DRM_NODE_PRIMARY:
68
+        case DRM_NODE_CONTROL:
58
+        case DRM_NODE_CONTROL:
69
+        case DRM_NODE_RENDER:
59
+        case DRM_NODE_RENDER:
70
+            return type;
60
+            return type;
71
+        default:
61
+        default:
72
+            return -1;
62
+            return -1;
73
+    }
63
+    }
74
+}
64
+}
75
+
65
+
76
+#ifdef __linux__
66
+#ifdef __linux__
77
+static const char *drmGetMinorName(int type)
67
+static const char *drmGetMinorName(int type)
78
+{
68
+{
79
+    switch (type) {
69
+    switch (type) {
80
+        case DRM_NODE_PRIMARY:
70
+        case DRM_NODE_PRIMARY:
81
+            return DRM_PRIMARY_MINOR_NAME;
71
+            return DRM_PRIMARY_MINOR_NAME;
82
+        case DRM_NODE_CONTROL:
72
+        case DRM_NODE_CONTROL:
83
+            return DRM_CONTROL_MINOR_NAME;
73
+            return DRM_CONTROL_MINOR_NAME;
84
+        case DRM_NODE_RENDER:
74
+        case DRM_NODE_RENDER:
85
+            return DRM_RENDER_MINOR_NAME;
75
+            return DRM_RENDER_MINOR_NAME;
86
+        default:
76
+        default:
87
+            return NULL;
77
+            return NULL;
88
+    }
78
+    }
89
+}
79
+}
90
+#endif
80
+#endif
91
+
81
+
92
+static const char *drmGetDeviceName(int type)
93
+{
94
+    switch (type) {
95
+        case DRM_NODE_PRIMARY:
96
+            return DRM_DEV_NAME;
97
+        case DRM_NODE_CONTROL:
98
+            return DRM_CONTROL_DEV_NAME;
99
+        case DRM_NODE_RENDER:
100
+            return DRM_RENDER_DEV_NAME;
101
+        default:
102
+            return NULL;
103
+    }
104
+}
105
+
106
+static int drmGetNodeNumber(const char *name)
82
+static int drmGetNodeNumber(const char *name)
107
+{
83
+{
108
+    size_t name_len = strnlen(name, DRM_NODE_NAME_MAX);
84
+    size_t name_len = strnlen(name, DRM_NODE_NAME_MAX);
109
+    while (name_len && isdigit(name[name_len - 1]))
85
+    while (name_len && isdigit(name[name_len - 1]))
110
+        --name_len;
86
+        --name_len;
111
+    return strtol(name + name_len, NULL, 10);
87
+    return strtol(name + name_len, NULL, 10);
112
+}
88
+}
113
+
89
+
114
+static int drmGetNodeType(const char *name)
90
+static int drmGetNodeType(const char *name)
115
+{
91
+{
116
+    if (strncmp(name, DRM_PRIMARY_MINOR_NAME,
92
+    if (strncmp(name, DRM_PRIMARY_MINOR_NAME,
117
+                sizeof(DRM_PRIMARY_MINOR_NAME) - 1) == 0)
93
+                sizeof(DRM_PRIMARY_MINOR_NAME) - 1) == 0)
118
+        return DRM_NODE_PRIMARY;
94
+        return DRM_NODE_PRIMARY;
119
+
95
+
120
+    if (strncmp(name, DRM_CONTROL_MINOR_NAME,
96
+    if (strncmp(name, DRM_CONTROL_MINOR_NAME,
121
+                sizeof(DRM_CONTROL_MINOR_NAME ) - 1) == 0)
97
+                sizeof(DRM_CONTROL_MINOR_NAME ) - 1) == 0)
122
+        return DRM_NODE_CONTROL;
98
+        return DRM_NODE_CONTROL;
123
+
99
+
124
+    if (strncmp(name, DRM_RENDER_MINOR_NAME,
100
+    if (strncmp(name, DRM_RENDER_MINOR_NAME,
125
+                sizeof(DRM_RENDER_MINOR_NAME) - 1) == 0)
101
+                sizeof(DRM_RENDER_MINOR_NAME) - 1) == 0)
126
+        return DRM_NODE_RENDER;
102
+        return DRM_NODE_RENDER;
127
+
103
+
128
+    return -1;
104
+    return -1;
129
+}
105
+}
130
+
106
+
131
 /**
107
 /**
132
  * Compare two busid strings
108
  * Compare two busid strings
133
  *
109
  *
134
@@ -326,8 +406,8 @@ static int chown_check_return(const char *path, uid_t 
110
@@ -340,10 +416,14 @@
135
 static int drmOpenDevice(dev_t dev, int minor, int type)
136
 {
137
     stat_t          st;
138
-    const char      *dev_name;
139
-    char            buf[64];
140
+    const char      *dev_name = drmGetDeviceName(type);
141
+    char            buf[DRM_NODE_NAME_MAX];
142
     int             fd;
143
     mode_t          devmode = DRM_DEV_MODE, serv_mode;
144
     gid_t           serv_group;
145
@@ -335,21 +415,14 @@ static int drmOpenDevice(dev_t dev, int minor, int typ
146
     gid_t           group   = DRM_DEV_GID;
111
     gid_t           group   = DRM_DEV_GID;
147
 #endif
112
 #endif
148
 
113
 
149
-    switch (type) {
114
     if (!dev_name)
150
-    case DRM_NODE_PRIMARY:
151
-        dev_name = DRM_DEV_NAME;
152
-        break;
153
-    case DRM_NODE_CONTROL:
154
-        dev_name = DRM_CONTROL_DEV_NAME;
155
-        break;
156
-    case DRM_NODE_RENDER:
157
-        dev_name = DRM_RENDER_DEV_NAME;
158
-        break;
159
-    default:
160
+    if (!dev_name)
161
         return -EINVAL;
115
         return -EINVAL;
162
-    };
163
 
116
 
164
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
117
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
165
+    sprintf(buf, dev_name, DRM_DIR_NAME, minor + drmGetMinorBase(type));
118
+    sprintf(buf, dev_name, DRM_DIR_NAME, minor + drmGetMinorBase(type));
166
+#else
119
+#else
167
     sprintf(buf, dev_name, DRM_DIR_NAME, minor);
120
     sprintf(buf, dev_name, DRM_DIR_NAME, minor);
168
+#endif
121
+#endif
169
     drmMsg("drmOpenDevice: node name is %s\n", buf);
122
     drmMsg("drmOpenDevice: node name is %s\n", buf);
170
 
123
 
171
     if (drm_server_info && drm_server_info->get_perms) {
124
     if (drm_server_info && drm_server_info->get_perms) {
172
@@ -453,27 +526,20 @@ wait_for_udev:
125
@@ -453,16 +533,20 @@ wait_for_udev:
173
 static int drmOpenMinor(int minor, int create, int type)
126
 static int drmOpenMinor(int minor, int create, int type)
174
 {
127
 {
175
     int  fd;
128
     int  fd;
176
-    char buf[64];
129
     char buf[DRM_NODE_NAME_MAX];
177
-    const char *dev_name;
130
     const char *dev_name = drmGetDeviceName(type);
178
+    char buf[DRM_NODE_NAME_MAX];
179
+    const char *dev_name = drmGetDeviceName(type);
180
 
131
 
181
     if (create)
132
     if (create)
182
         return drmOpenDevice(makedev(DRM_MAJOR, minor), minor, type);
133
         return drmOpenDevice(makedev(DRM_MAJOR, minor), minor, type);
183
 
134
 
184
-    switch (type) {
135
     if (!dev_name)
185
-    case DRM_NODE_PRIMARY:
186
-        dev_name = DRM_DEV_NAME;
187
-        break;
188
-    case DRM_NODE_CONTROL:
189
-        dev_name = DRM_CONTROL_DEV_NAME;
190
-        break;
191
-    case DRM_NODE_RENDER:
192
-        dev_name = DRM_RENDER_DEV_NAME;
193
-        break;
194
-    default:
195
+    if (!dev_name)
196
         return -EINVAL;
136
         return -EINVAL;
197
-    };
198
 
137
 
199
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
138
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
200
+    sprintf(buf, dev_name, DRM_DIR_NAME, minor + drmGetMinorBase(type));
139
+    sprintf(buf, dev_name, DRM_DIR_NAME, minor + drmGetMinorBase(type));
201
+#else
140
+#else
202
     sprintf(buf, dev_name, DRM_DIR_NAME, minor);
141
     sprintf(buf, dev_name, DRM_DIR_NAME, minor);
203
+#endif
142
+#endif
204
     if ((fd = open(buf, O_RDWR | O_CLOEXEC, 0)) >= 0)
143
     if ((fd = open(buf, O_RDWR | O_CLOEXEC, 0)) >= 0)
205
         return fd;
144
         return fd;
206
     return -errno;
145
     return -errno;
207
@@ -514,51 +580,6 @@ drm_public int drmAvailable(void)
146
@@ -514,51 +598,6 @@ drm_public int drmAvailable(void)
208
     return retval;
147
     return retval;
209
 }
148
 }
210
 
149
 
211
-static int drmGetMinorBase(int type)
150
-static int drmGetMinorBase(int type)
212
-{
151
-{
213
-    switch (type) {
152
-    switch (type) {
214
-    case DRM_NODE_PRIMARY:
153
-    case DRM_NODE_PRIMARY:
215
-        return 0;
154
-        return 0;
216
-    case DRM_NODE_CONTROL:
155
-    case DRM_NODE_CONTROL:
217
-        return 64;
156
-        return 64;
218
-    case DRM_NODE_RENDER:
157
-    case DRM_NODE_RENDER:
219
-        return 128;
158
-        return 128;
220
-    default:
159
-    default:
221
-        return -1;
160
-        return -1;
222
-    };
161
-    };
223
-}
162
-}
224
-
163
-
225
-static int drmGetMinorType(int minor)
164
-static int drmGetMinorType(int minor)
226
-{
165
-{
227
-    int type = minor >> 6;
166
-    int type = minor >> 6;
228
-
167
-
229
-    if (minor < 0)
168
-    if (minor < 0)
230
-        return -1;
169
-        return -1;
231
-
170
-
232
-    switch (type) {
171
-    switch (type) {
233
-    case DRM_NODE_PRIMARY:
172
-    case DRM_NODE_PRIMARY:
234
-    case DRM_NODE_CONTROL:
173
-    case DRM_NODE_CONTROL:
235
-    case DRM_NODE_RENDER:
174
-    case DRM_NODE_RENDER:
236
-        return type;
175
-        return type;
237
-    default:
176
-    default:
238
-        return -1;
177
-        return -1;
239
-    }
178
-    }
240
-}
179
-}
241
-
180
-
242
-static const char *drmGetMinorName(int type)
181
-static const char *drmGetMinorName(int type)
243
-{
182
-{
244
-    switch (type) {
183
-    switch (type) {
245
-    case DRM_NODE_PRIMARY:
184
-    case DRM_NODE_PRIMARY:
246
-        return DRM_PRIMARY_MINOR_NAME;
185
-        return DRM_PRIMARY_MINOR_NAME;
247
-    case DRM_NODE_CONTROL:
186
-    case DRM_NODE_CONTROL:
248
-        return DRM_CONTROL_MINOR_NAME;
187
-        return DRM_CONTROL_MINOR_NAME;
249
-    case DRM_NODE_RENDER:
188
-    case DRM_NODE_RENDER:
250
-        return DRM_RENDER_MINOR_NAME;
189
-        return DRM_RENDER_MINOR_NAME;
251
-    default:
190
-    default:
252
-        return NULL;
191
-        return NULL;
253
-    }
192
-    }
254
-}
193
-}
255
-
194
-
256
 /**
195
 /**
257
  * Open the device by bus ID.
196
  * Open the device by bus ID.
258
  *
197
  *
259
@@ -2743,28 +2764,22 @@ drm_public int drmDropMaster(int fd)
198
@@ -2743,28 +2782,22 @@ drm_public int drmDropMaster(int fd)
260
 
199
 
261
 drm_public char *drmGetDeviceNameFromFd(int fd)
200
 drm_public char *drmGetDeviceNameFromFd(int fd)
262
 {
201
 {
263
-    char name[128];
202
-    char name[128];
264
-    struct stat sbuf;
203
-    struct stat sbuf;
265
-    dev_t d;
204
-    dev_t d;
266
-    int i;
205
-    int i;
267
-
206
-
268
     /* The whole drmOpen thing is a fiasco and we need to find a way
207
     /* The whole drmOpen thing is a fiasco and we need to find a way
269
      * back to just using open(2).  For now, however, lets just make
208
      * back to just using open(2).  For now, however, lets just make
270
      * things worse with even more ad hoc directory walking code to
209
      * things worse with even more ad hoc directory walking code to
271
      * discover the device file name. */
210
      * discover the device file name. */
272
 
211
 
273
+    stat_t sbuf;
212
+    stat_t sbuf;
274
     fstat(fd, &sbuf);
213
     fstat(fd, &sbuf);
275
-    d = sbuf.st_rdev;
214
-    d = sbuf.st_rdev;
276
+    dev_t d = sbuf.st_rdev;
215
+    dev_t d = sbuf.st_rdev;
277
 
216
 
278
-    for (i = 0; i < DRM_MAX_MINOR; i++) {
217
-    for (i = 0; i < DRM_MAX_MINOR; i++) {
279
+    for (int i = 0; i < DRM_MAX_MINOR; i++) {
218
+    for (int i = 0; i < DRM_MAX_MINOR; i++) {
280
+        char name[DRM_NODE_NAME_MAX];
219
+        char name[DRM_NODE_NAME_MAX];
281
         snprintf(name, sizeof name, DRM_DEV_NAME, DRM_DIR_NAME, i);
220
         snprintf(name, sizeof name, DRM_DEV_NAME, DRM_DIR_NAME, i);
282
         if (stat(name, &sbuf) == 0 && sbuf.st_rdev == d)
221
         if (stat(name, &sbuf) == 0 && sbuf.st_rdev == d)
283
-            break;
222
-            break;
284
+            return strdup(name);
223
+            return strdup(name);
285
     }
224
     }
286
-    if (i == DRM_MAX_MINOR)
225
-    if (i == DRM_MAX_MINOR)
287
-        return NULL;
226
-        return NULL;
288
-
227
-
289
-    return strdup(name);
228
-    return strdup(name);
290
+    return NULL;
229
+    return NULL;
291
 }
230
 }
292
 
231
 
293
 static bool drmNodeIsDRM(int maj, int min)
232
 static bool drmNodeIsDRM(int maj, int min)
294
@@ -2777,13 +2792,26 @@ static bool drmNodeIsDRM(int maj, int min)
233
@@ -2777,13 +2810,26 @@ static bool drmNodeIsDRM(int maj, int min)
295
              maj, min);
234
              maj, min);
296
     return stat(path, &sbuf) == 0;
235
     return stat(path, &sbuf) == 0;
297
 #else
236
 #else
298
-    return maj == DRM_MAJOR;
237
-    return maj == DRM_MAJOR;
299
+    return !DRM_MAJOR || maj == DRM_MAJOR;
238
+    return !DRM_MAJOR || maj == DRM_MAJOR;
300
 #endif
239
 #endif
301
 }
240
 }
302
 
241
 
303
 drm_public int drmGetNodeTypeFromFd(int fd)
242
 drm_public int drmGetNodeTypeFromFd(int fd)
304
 {
243
 {
305
-    struct stat sbuf;
244
-    struct stat sbuf;
306
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
245
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
307
+    char *name = drmGetDeviceNameFromFd2(fd);
246
+    char *name = drmGetDeviceNameFromFd2(fd);
308
+    if (!name) {
247
+    if (!name) {
309
+        errno = ENODEV;
248
+        errno = ENODEV;
310
+        return -1;
249
+        return -1;
311
+    }
250
+    }
312
+
251
+
313
+    int type = drmGetNodeType(strrchr(name, '/') + 1);
252
+    int type = drmGetNodeType(strrchr(name, '/') + 1);
314
+    free(name);
253
+    free(name);
315
+    if (type < 0)
254
+    if (type < 0)
316
+        errno = ENODEV;
255
+        errno = ENODEV;
317
+    return type;
256
+    return type;
318
+#else
257
+#else
319
+    stat_t sbuf;
258
+    stat_t sbuf;
320
     int maj, min, type;
259
     int maj, min, type;
321
 
260
 
322
     if (fstat(fd, &sbuf))
261
     if (fstat(fd, &sbuf))
323
@@ -2801,6 +2829,7 @@ drm_public int drmGetNodeTypeFromFd(int fd)
262
@@ -2801,6 +2847,7 @@ drm_public int drmGetNodeTypeFromFd(int fd)
324
     if (type == -1)
263
     if (type == -1)
325
         errno = ENODEV;
264
         errno = ENODEV;
326
     return type;
265
     return type;
327
+#endif
266
+#endif
328
 }
267
 }
329
 
268
 
330
 drm_public int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags,
269
 drm_public int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags,
331
@@ -2841,7 +2870,7 @@ static char *drmGetMinorNameForFD(int fd, int type)
270
@@ -2841,7 +2888,7 @@ static char *drmGetMinorNameForFD(int fd, int type)
332
 #ifdef __linux__
271
 #ifdef __linux__
333
     DIR *sysdir;
272
     DIR *sysdir;
334
     struct dirent *ent;
273
     struct dirent *ent;
335
-    struct stat sbuf;
274
-    struct stat sbuf;
336
+    stat_t sbuf;
275
+    stat_t sbuf;
337
     const char *name = drmGetMinorName(type);
276
     const char *name = drmGetMinorName(type);
338
     int len;
277
     int len;
339
     char dev_name[64], buf[64];
278
     char dev_name[64], buf[64];
340
@@ -2879,13 +2908,35 @@ static char *drmGetMinorNameForFD(int fd, int type)
279
@@ -2879,13 +2926,35 @@ static char *drmGetMinorNameForFD(int fd, int type)
341
 
280
 
342
     closedir(sysdir);
281
     closedir(sysdir);
343
     return NULL;
282
     return NULL;
344
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
283
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
345
+    const char *dev_name = drmGetDeviceName(type);
284
+    const char *dev_name = drmGetDeviceName(type);
346
+    if (!dev_name)
285
+    if (!dev_name)
347
+        return NULL;
286
+        return NULL;
348
+
287
+
349
+    char *name = drmGetDeviceNameFromFd2(fd);
288
+    char *name = drmGetDeviceNameFromFd2(fd);
350
+    if (!name)
289
+    if (!name)
351
+        return NULL;
290
+        return NULL;
352
+
291
+
353
+    int oldnum = drmGetNodeNumber(name);
292
+    int oldnum = drmGetNodeNumber(name);
354
+    int oldtype = drmGetMinorType(oldnum);
293
+    int oldtype = drmGetMinorType(oldnum);
355
+    if (oldtype < 0) {
294
+    if (oldtype < 0) {
356
+        free(name);
295
+        free(name);
357
+        return NULL;
296
+        return NULL;
358
+    }
297
+    }
359
+
298
+
360
+    int newnum = oldnum - drmGetMinorBase(oldtype) + drmGetMinorBase(type);
299
+    int newnum = oldnum - drmGetMinorBase(oldtype) + drmGetMinorBase(type);
361
+    snprintf(name, DRM_NODE_NAME_MAX, dev_name, DRM_DIR_NAME, newnum);
300
+    snprintf(name, DRM_NODE_NAME_MAX, dev_name, DRM_DIR_NAME, newnum);
362
+    return name;
301
+    return name;
363
 #else
302
 #else
364
-    struct stat sbuf;
303
-    struct stat sbuf;
365
-    char buf[PATH_MAX + 1];
304
-    char buf[PATH_MAX + 1];
366
-    const char *dev_name;
367
+    stat_t sbuf;
305
+    stat_t sbuf;
368
+    char buf[DRM_NODE_NAME_MAX];
306
+    char buf[DRM_NODE_NAME_MAX];
369
+    const char *dev_name = drmGetDeviceName(type);
307
     const char *dev_name = drmGetDeviceName(type);
370
     unsigned int maj, min;
308
     unsigned int maj, min;
371
     int n, base;
309
     int n;
372
 
310
 
373
+    if (!dev_name)
311
+    if (!dev_name)
374
+        return NULL;
312
+        return NULL;
375
+
313
+
376
     if (fstat(fd, &sbuf))
314
     if (fstat(fd, &sbuf))
377
         return NULL;
315
         return NULL;
378
 
316
 
379
@@ -2895,20 +2946,6 @@ static char *drmGetMinorNameForFD(int fd, int type)
317
@@ -3032,7 +3101,7 @@ static int drmParseSubsystemType(int maj, int min)
380
     if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode))
381
         return NULL;
382
 
383
-    switch (type) {
384
-    case DRM_NODE_PRIMARY:
385
-        dev_name = DRM_DEV_NAME;
386
-        break;
387
-    case DRM_NODE_CONTROL:
388
-        dev_name = DRM_CONTROL_DEV_NAME;
389
-        break;
390
-    case DRM_NODE_RENDER:
391
-        dev_name = DRM_RENDER_DEV_NAME;
392
-        break;
393
-    default:
394
-        return NULL;
395
-    };
396
-
397
     base = drmGetMinorBase(type);
398
     if (base < 0)
399
         return NULL;
400
@@ -3032,7 +3069,7 @@ static int drmParseSubsystemType(int maj, int min)
401
     }
318
     }
402
 
319
 
403
     return -EINVAL;
320
     return -EINVAL;
404
-#elif defined(__OpenBSD__) || defined(__DragonFly__)
321
-#elif defined(__OpenBSD__) || defined(__DragonFly__)
405
+#elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
322
+#elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
406
     return DRM_BUS_PCI;
323
     return DRM_BUS_PCI;
407
 #else
324
 #else
408
 #warning "Missing implementation of drmParseSubsystemType"
325
 #warning "Missing implementation of drmParseSubsystemType"
409
@@ -3035,7 +3072,8 @@ get_pci_path(int maj, int min, char *pci_path)
326
@@ -3035,7 +3104,8 @@ get_pci_path(int maj, int min, char *pci_path)
410
         *term = 0;
327
         *term = 0;
411
 }
328
 }
412
 
329
 
413
-static int drmParsePciBusInfo(int maj, int min, drmPciBusInfoPtr info)
330
-static int drmParsePciBusInfo(int maj, int min, drmPciBusInfoPtr info)
414
+static int drmParsePciBusInfo(const char *node, int node_type,
331
+static int drmParsePciBusInfo(const char *node, int node_type,
415
+                              int maj, int min, drmPciBusInfoPtr info)
332
+                              int maj, int min, drmPciBusInfoPtr info)
416
 {
333
 {
417
 #ifdef __linux__
334
 #ifdef __linux__
418
     unsigned int domain, bus, dev, func;
335
     unsigned int domain, bus, dev, func;
419
@@ -3084,6 +3122,60 @@ static int drmParsePciBusInfo(int maj, int min, drmPci
336
@@ -3084,6 +3154,60 @@ static int drmParsePciBusInfo(int maj, int min, drmPci
420
     info->func = pinfo.func;
337
     info->func = pinfo.func;
421
 
338
 
422
     return 0;
339
     return 0;
423
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
340
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
424
+    /*
341
+    /*
425
+     * Only the primary nodes can be mapped to hw.dri.%i via major/minor
342
+     * Only the primary nodes can be mapped to hw.dri.%i via major/minor
426
+     * Determine the primary node by offset and use its major/minor pair
343
+     * Determine the primary node by offset and use its major/minor pair
427
+     */
344
+     */
428
+    if (node_type != DRM_NODE_PRIMARY) {
345
+    if (node_type != DRM_NODE_PRIMARY) {
429
+        char name[DRM_NODE_NAME_MAX];
346
+        char name[DRM_NODE_NAME_MAX];
430
+        snprintf(name, sizeof(name), DRM_DEV_NAME, DRM_DIR_NAME,
347
+        snprintf(name, sizeof(name), DRM_DEV_NAME, DRM_DIR_NAME,
431
+                 drmGetNodeNumber(node) - drmGetMinorBase(node_type));
348
+                 drmGetNodeNumber(node) - drmGetMinorBase(node_type));
432
+
349
+
433
+        stat_t sbuf;
350
+        stat_t sbuf;
434
+        if (stat(name, &sbuf))
351
+        if (stat(name, &sbuf))
435
+            return -errno;
352
+            return -errno;
436
+
353
+
437
+        maj = major(sbuf.st_rdev);
354
+        maj = major(sbuf.st_rdev);
438
+        min = minor(sbuf.st_rdev);
355
+        min = minor(sbuf.st_rdev);
439
+    }
356
+    }
440
+    /*
357
+    /*
441
+     * Major/minor appear after the driver name in the hw.dri.%i.name node
358
+     * Major/minor appear after the driver name in the hw.dri.%i.name node
442
+     * Find the node with matching major/minor pair and parse the bus ID,
359
+     * Find the node with matching major/minor pair and parse the bus ID,
443
+     * which may be after the name or may be alone in hw.dri.%i.busid
360
+     * which may be after the name or may be alone in hw.dri.%i.busid
444
+     */
361
+     */
445
+    #define bus_fmt "pci:%04x:%02x:%02x.%u"
362
+    #define bus_fmt "pci:%04x:%02x:%02x.%u"
446
+    #define name_fmt "%*s %x " bus_fmt
363
+    #define name_fmt "%*s %x " bus_fmt
447
+    for (int i = 0; i < DRM_MAX_MINOR; ++i) {
364
+    for (int i = 0; i < DRM_MAX_MINOR; ++i) {
448
+        char name[16], value[256];
365
+        char name[16], value[256];
449
+        size_t length = sizeof(value);
366
+        size_t length = sizeof(value);
450
+        snprintf(name, sizeof(name), "hw.dri.%i.name", i);
367
+        snprintf(name, sizeof(name), "hw.dri.%i.name", i);
451
+        if (sysctlbyname(name, value, &length, NULL, 0))
368
+        if (sysctlbyname(name, value, &length, NULL, 0))
452
+            continue;
369
+            continue;
453
+
370
+
454
+        value[length] = '\0';
371
+        value[length] = '\0';
455
+        unsigned int rdev = 0, domain = 0, bus = 0, slot = 0, func = 0;
372
+        unsigned int rdev = 0, domain = 0, bus = 0, slot = 0, func = 0;
456
+        int vals = sscanf(value, name_fmt, &rdev, &domain, &bus, &slot, &func);
373
+        int vals = sscanf(value, name_fmt, &rdev, &domain, &bus, &slot, &func);
457
+
374
+
458
+	if (vals >= 1 && rdev == makedev(maj,min)) {
375
+	if (vals >= 1 && rdev == makedev(maj,min)) {
459
+            if (vals < 5) {
376
+            if (vals < 5) {
460
+                /* busid not in the name, try busid */
377
+                /* busid not in the name, try busid */
461
+                length = sizeof(value);
378
+                length = sizeof(value);
462
+                snprintf(name, sizeof(name), "hw.dri.%i.busid", i);
379
+                snprintf(name, sizeof(name), "hw.dri.%i.busid", i);
463
+                if (sysctlbyname(name, value, &length, NULL, 0))
380
+                if (sysctlbyname(name, value, &length, NULL, 0))
464
+                    break;
381
+                    break;
465
+                value[length] = '\0';
382
+                value[length] = '\0';
466
+                if (sscanf(value, bus_fmt, &domain, &bus, &slot, &func) != 4)
383
+                if (sscanf(value, bus_fmt, &domain, &bus, &slot, &func) != 4)
467
+                    break;
384
+                    break;
468
+            }
385
+            }
469
+            info->domain = domain;
386
+            info->domain = domain;
470
+            info->bus = bus;
387
+            info->bus = bus;
471
+            info->dev = slot;
388
+            info->dev = slot;
472
+            info->func = func;
389
+            info->func = func;
473
+            return 0;
390
+            return 0;
474
+        }
391
+        }
475
+    }
392
+    }
476
+    return -ENODEV;
393
+    return -ENODEV;
477
 #else
394
 #else
478
 #warning "Missing implementation of drmParsePciBusInfo"
395
 #warning "Missing implementation of drmParsePciBusInfo"
479
     return -EINVAL;
396
     return -EINVAL;
480
@@ -3118,32 +3210,6 @@ drm_public int drmDevicesEqual(drmDevicePtr a, drmDevi
397
@@ -3118,32 +3242,6 @@ drm_public int drmDevicesEqual(drmDevicePtr a, drmDevi
481
     return 0;
398
     return 0;
482
 }
399
 }
483
 
400
 
484
-static int drmGetNodeType(const char *name)
401
-static int drmGetNodeType(const char *name)
485
-{
402
-{
486
-    if (strncmp(name, DRM_PRIMARY_MINOR_NAME,
487
-        sizeof(DRM_PRIMARY_MINOR_NAME) - 1) == 0)
488
-        return DRM_NODE_PRIMARY;
489
-
490
-    if (strncmp(name, DRM_CONTROL_MINOR_NAME,
403
-    if (strncmp(name, DRM_CONTROL_MINOR_NAME,
491
-        sizeof(DRM_CONTROL_MINOR_NAME ) - 1) == 0)
404
-        sizeof(DRM_CONTROL_MINOR_NAME ) - 1) == 0)
492
-        return DRM_NODE_CONTROL;
405
-        return DRM_NODE_CONTROL;
493
-
406
-
494
-    if (strncmp(name, DRM_RENDER_MINOR_NAME,
407
-    if (strncmp(name, DRM_RENDER_MINOR_NAME,
495
-        sizeof(DRM_RENDER_MINOR_NAME) - 1) == 0)
408
-        sizeof(DRM_RENDER_MINOR_NAME) - 1) == 0)
496
-        return DRM_NODE_RENDER;
409
-        return DRM_NODE_RENDER;
497
-
410
-
411
-    if (strncmp(name, DRM_PRIMARY_MINOR_NAME,
412
-        sizeof(DRM_PRIMARY_MINOR_NAME) - 1) == 0)
413
-        return DRM_NODE_PRIMARY;
414
-
498
-    return -EINVAL;
415
-    return -EINVAL;
499
-}
416
-}
500
-
417
-
501
-static int drmGetMaxNodeName(void)
418
-static int drmGetMaxNodeName(void)
502
-{
419
-{
503
-    return sizeof(DRM_DIR_NAME) +
420
-    return sizeof(DRM_DIR_NAME) +
504
-           MAX3(sizeof(DRM_PRIMARY_MINOR_NAME),
421
-           MAX3(sizeof(DRM_PRIMARY_MINOR_NAME),
505
-                sizeof(DRM_CONTROL_MINOR_NAME),
422
-                sizeof(DRM_CONTROL_MINOR_NAME),
506
-                sizeof(DRM_RENDER_MINOR_NAME)) +
423
-                sizeof(DRM_RENDER_MINOR_NAME)) +
507
-           3 /* length of the node number */;
424
-           3 /* length of the node number */;
508
-}
425
-}
509
-
426
-
510
 #ifdef __linux__
427
 #ifdef __linux__
511
 static int parse_separate_sysfs_files(int maj, int min,
428
 static int parse_separate_sysfs_files(int maj, int min,
512
                                       drmPciDeviceInfoPtr device,
429
                                       drmPciDeviceInfoPtr device,
513
@@ -3216,6 +3282,7 @@ static int parse_config_sysfs_file(int maj, int min,
430
@@ -3216,6 +3314,7 @@ static int parse_config_sysfs_file(int maj, int min,
514
 #endif
431
 #endif
515
 
432
 
516
 static int drmParsePciDeviceInfo(int maj, int min,
433
 static int drmParsePciDeviceInfo(int maj, int min,
517
+                                 drmPciBusInfoPtr info,
434
+                                 drmPciBusInfoPtr info,
518
                                  drmPciDeviceInfoPtr device,
435
                                  drmPciDeviceInfoPtr device,
519
                                  uint32_t flags)
436
                                  uint32_t flags)
520
 {
437
 {
521
@@ -3252,6 +3319,43 @@ static int drmParsePciDeviceInfo(int maj, int min,
438
@@ -3252,6 +3351,43 @@ static int drmParsePciDeviceInfo(int maj, int min,
522
     device->subdevice_id = pinfo.subdevice_id;
439
     device->subdevice_id = pinfo.subdevice_id;
523
 
440
 
524
     return 0;
441
     return 0;
525
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
442
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
526
+    struct pci_conf_io pc;
443
+    struct pci_conf_io pc;
527
+    struct pci_match_conf patterns[1];
444
+    struct pci_match_conf patterns[1];
528
+    struct pci_conf results[1];
445
+    struct pci_conf results[1];
529
+
446
+
530
+    int fd = open("/dev/pci", O_RDONLY, 0);
447
+    int fd = open("/dev/pci", O_RDONLY, 0);
531
+    if (fd < 0)
448
+    if (fd < 0)
532
+        return -errno;
449
+        return -errno;
533
+
450
+
534
+    bzero(&patterns, sizeof(patterns));
451
+    bzero(&patterns, sizeof(patterns));
535
+    patterns[0].pc_sel.pc_domain = info->domain;
452
+    patterns[0].pc_sel.pc_domain = info->domain;
536
+    patterns[0].pc_sel.pc_bus = info->bus;
453
+    patterns[0].pc_sel.pc_bus = info->bus;
537
+    patterns[0].pc_sel.pc_dev = info->dev;
454
+    patterns[0].pc_sel.pc_dev = info->dev;
538
+    patterns[0].pc_sel.pc_func = info->func;
455
+    patterns[0].pc_sel.pc_func = info->func;
539
+    patterns[0].flags = PCI_GETCONF_MATCH_DOMAIN | PCI_GETCONF_MATCH_BUS
456
+    patterns[0].flags = PCI_GETCONF_MATCH_DOMAIN | PCI_GETCONF_MATCH_BUS
540
+                      | PCI_GETCONF_MATCH_DEV | PCI_GETCONF_MATCH_FUNC;
457
+                      | PCI_GETCONF_MATCH_DEV | PCI_GETCONF_MATCH_FUNC;
541
+    bzero(&pc, sizeof(struct pci_conf_io));
458
+    bzero(&pc, sizeof(struct pci_conf_io));
542
+    pc.num_patterns = 1;
459
+    pc.num_patterns = 1;
543
+    pc.pat_buf_len = sizeof(patterns);
460
+    pc.pat_buf_len = sizeof(patterns);
544
+    pc.patterns = patterns;
461
+    pc.patterns = patterns;
545
+    pc.match_buf_len = sizeof(results);
462
+    pc.match_buf_len = sizeof(results);
546
+    pc.matches = results;
463
+    pc.matches = results;
547
+
464
+
548
+    if (ioctl(fd, PCIOCGETCONF, &pc) || pc.status == PCI_GETCONF_ERROR) {
465
+    if (ioctl(fd, PCIOCGETCONF, &pc) || pc.status == PCI_GETCONF_ERROR) {
549
+        int error = errno;
466
+        int error = errno;
550
+        close(fd);
467
+        close(fd);
551
+        return -error;
468
+        return -error;
552
+    }
469
+    }
553
+    close(fd);
470
+    close(fd);
554
+
471
+
555
+    device->vendor_id = results[0].pc_vendor;
472
+    device->vendor_id = results[0].pc_vendor;
556
+    device->device_id = results[0].pc_device;
473
+    device->device_id = results[0].pc_device;
557
+    device->subvendor_id = results[0].pc_subvendor;
474
+    device->subvendor_id = results[0].pc_subvendor;
558
+    device->subdevice_id = results[0].pc_subdevice;
475
+    device->subdevice_id = results[0].pc_subdevice;
559
+    device->revision_id = results[0].pc_revid;
476
+    device->revision_id = results[0].pc_revid;
560
+
477
+
561
+    return 0;
478
+    return 0;
562
 #else
479
 #else
563
 #warning "Missing implementation of drmParsePciDeviceInfo"
480
 #warning "Missing implementation of drmParsePciDeviceInfo"
564
     return -EINVAL;
481
     return -EINVAL;
565
@@ -3332,7 +3436,7 @@ static drmDevicePtr drmDeviceAlloc(unsigned int type, 
482
@@ -3332,7 +3468,7 @@ static drmDevicePtr drmDeviceAlloc(unsigned int type, 
566
     unsigned int i;
483
     unsigned int i;
567
     char *ptr;
484
     char *ptr;
568
 
485
 
569
-    max_node_length = ALIGN(drmGetMaxNodeName(), sizeof(void *));
486
-    max_node_length = ALIGN(drmGetMaxNodeName(), sizeof(void *));
570
+    max_node_length = ALIGN(DRM_NODE_NAME_MAX, sizeof(void *));
487
+    max_node_length = ALIGN(DRM_NODE_NAME_MAX, sizeof(void *));
571
     extra = DRM_NODE_MAX * (sizeof(void *) + max_node_length);
488
     extra = DRM_NODE_MAX * (sizeof(void *) + max_node_length);
572
 
489
 
573
     size = sizeof(*device) + extra + bus_size + device_size;
490
     size = sizeof(*device) + extra + bus_size + device_size;
574
@@ -3378,7 +3482,7 @@ static int drmProcessPciDevice(drmDevicePtr *device,
491
@@ -3378,7 +3514,7 @@ static int drmProcessPciDevice(drmDevicePtr *device,
575
 
492
 
576
     dev->businfo.pci = (drmPciBusInfoPtr)addr;
493
     dev->businfo.pci = (drmPciBusInfoPtr)addr;
577
 
494
 
578
-    ret = drmParsePciBusInfo(maj, min, dev->businfo.pci);
495
-    ret = drmParsePciBusInfo(maj, min, dev->businfo.pci);
579
+    ret = drmParsePciBusInfo(node, node_type, maj, min, dev->businfo.pci);
496
+    ret = drmParsePciBusInfo(node, node_type, maj, min, dev->businfo.pci);
580
     if (ret)
497
     if (ret)
581
         goto free_device;
498
         goto free_device;
582
 
499
 
583
@@ -3387,7 +3491,7 @@ static int drmProcessPciDevice(drmDevicePtr *device,
500
@@ -3387,7 +3523,7 @@ static int drmProcessPciDevice(drmDevicePtr *device,
584
         addr += sizeof(drmPciBusInfo);
501
         addr += sizeof(drmPciBusInfo);
585
         dev->deviceinfo.pci = (drmPciDeviceInfoPtr)addr;
502
         dev->deviceinfo.pci = (drmPciDeviceInfoPtr)addr;
586
 
503
 
587
-        ret = drmParsePciDeviceInfo(maj, min, dev->deviceinfo.pci, flags);
504
-        ret = drmParsePciDeviceInfo(maj, min, dev->deviceinfo.pci, flags);
588
+        ret = drmParsePciDeviceInfo(maj, min, dev->businfo.pci, dev->deviceinfo.pci, flags);
505
+        ret = drmParsePciDeviceInfo(maj, min, dev->businfo.pci, dev->deviceinfo.pci, flags);
589
         if (ret)
506
         if (ret)
590
             goto free_device;
507
             goto free_device;
591
     }
508
     }
592
@@ -3727,8 +3831,8 @@ process_device(drmDevicePtr *device, const char *d_nam
509
@@ -3727,8 +3863,8 @@ process_device(drmDevicePtr *device, const char *d_nam
593
                int req_subsystem_type,
510
                int req_subsystem_type,
594
                bool fetch_deviceinfo, uint32_t flags)
511
                bool fetch_deviceinfo, uint32_t flags)
595
 {
512
 {
596
-    struct stat sbuf;
513
-    struct stat sbuf;
597
-    char node[PATH_MAX + 1];
514
-    char node[PATH_MAX + 1];
598
+    stat_t sbuf;
515
+    stat_t sbuf;
599
+    char node[DRM_NODE_NAME_MAX];
516
+    char node[DRM_NODE_NAME_MAX];
600
     int node_type, subsystem_type;
517
     int node_type, subsystem_type;
601
     unsigned int maj, min;
518
     unsigned int maj, min;
602
 
519
 
603
@@ -3736,7 +3840,7 @@ process_device(drmDevicePtr *device, const char *d_nam
520
@@ -3736,7 +3872,7 @@ process_device(drmDevicePtr *device, const char *d_nam
604
     if (node_type < 0)
521
     if (node_type < 0)
605
         return -1;
522
         return -1;
606
 
523
 
607
-    snprintf(node, PATH_MAX, "%s/%s", DRM_DIR_NAME, d_name);
524
-    snprintf(node, PATH_MAX, "%s/%s", DRM_DIR_NAME, d_name);
608
+    snprintf(node, sizeof(node), "%s/%s", DRM_DIR_NAME, d_name);
525
+    snprintf(node, sizeof(node), "%s/%s", DRM_DIR_NAME, d_name);
609
     if (stat(node, &sbuf))
526
     if (stat(node, &sbuf))
610
         return -1;
527
         return -1;
611
 
528
 
612
@@ -3784,7 +3888,7 @@ static void drmFoldDuplicatedDevices(drmDevicePtr loca
529
@@ -3784,7 +3920,7 @@ static void drmFoldDuplicatedDevices(drmDevicePtr loca
613
                 local_devices[i]->available_nodes |= local_devices[j]->available_nodes;
530
                 local_devices[i]->available_nodes |= local_devices[j]->available_nodes;
614
                 node_type = log2(local_devices[j]->available_nodes);
531
                 node_type = log2(local_devices[j]->available_nodes);
615
                 memcpy(local_devices[i]->nodes[node_type],
532
                 memcpy(local_devices[i]->nodes[node_type],
616
-                       local_devices[j]->nodes[node_type], drmGetMaxNodeName());
533
-                       local_devices[j]->nodes[node_type], drmGetMaxNodeName());
617
+                       local_devices[j]->nodes[node_type], DRM_NODE_NAME_MAX);
534
+                       local_devices[j]->nodes[node_type], DRM_NODE_NAME_MAX);
618
                 drmFreeDevice(&local_devices[j]);
535
                 drmFreeDevice(&local_devices[j]);
619
             }
536
             }
620
         }
537
         }
621
@@ -3824,7 +3928,7 @@ drm_device_has_rdev(drmDevicePtr device, dev_t find_rd
538
@@ -3824,7 +3960,7 @@ drm_device_has_rdev(drmDevicePtr device, dev_t find_rd
622
  * Get information about the opened drm device
539
  * Get information about the opened drm device
623
  *
540
  *
624
  * \param fd file descriptor of the drm device
541
  * \param fd file descriptor of the drm device
625
- * \param flags feature/behaviour bitmask
542
- * \param flags feature/behaviour bitmask
626
+ * \param flags feature/behavior bitmask
543
+ * \param flags feature/behavior bitmask
627
  * \param device the address of a drmDevicePtr where the information
544
  * \param device the address of a drmDevicePtr where the information
628
  *               will be allocated in stored
545
  *               will be allocated in stored
629
  *
546
  *
630
@@ -3842,8 +3946,8 @@ drm_public int drmGetDevice2(int fd, uint32_t flags, d
547
@@ -3842,8 +3978,8 @@ drm_public int drmGetDevice2(int fd, uint32_t flags, d
631
      * Avoid stat'ing all of /dev needlessly by implementing this custom path.
548
      * Avoid stat'ing all of /dev needlessly by implementing this custom path.
632
      */
549
      */
633
     drmDevicePtr     d;
550
     drmDevicePtr     d;
634
-    struct stat      sbuf;
551
-    struct stat      sbuf;
635
-    char             node[PATH_MAX + 1];
552
-    char             node[PATH_MAX + 1];
636
+    stat_t           sbuf;
553
+    stat_t           sbuf;
637
+    char             node[DRM_NODE_NAME_MAX];
554
+    char             node[DRM_NODE_NAME_MAX];
638
     const char      *dev_name;
555
     const char      *dev_name;
639
     int              node_type, subsystem_type;
556
     int              node_type, subsystem_type;
640
     int              maj, min, n, ret, base;
557
     int              maj, min, n, ret, base;
641
@@ -3864,26 +3968,16 @@ drm_public int drmGetDevice2(int fd, uint32_t flags, d
558
@@ -3989,7 +4125,7 @@ drm_public int drmGetDevice(int fd, drmDevicePtr *devi
642
     if (node_type == -1)
643
         return -ENODEV;
644
 
645
-    switch (node_type) {
646
-    case DRM_NODE_PRIMARY:
647
-        dev_name = DRM_DEV_NAME;
648
-        break;
649
-    case DRM_NODE_CONTROL:
650
-        dev_name = DRM_CONTROL_DEV_NAME;
651
-        break;
652
-    case DRM_NODE_RENDER:
653
-        dev_name = DRM_RENDER_DEV_NAME;
654
-        break;
655
-    default:
656
+    dev_name = drmGetDeviceName(node_type);
657
+    if (!dev_name)
658
         return -EINVAL;
659
-    };
660
 
661
     base = drmGetMinorBase(node_type);
662
     if (base < 0)
663
         return -EINVAL;
664
 
665
-    n = snprintf(node, PATH_MAX, dev_name, DRM_DIR_NAME, min - base);
666
-    if (n == -1 || n >= PATH_MAX)
667
+    n = snprintf(node, sizeof(node), dev_name, DRM_DIR_NAME, min - base);
668
+    if (n == -1 || n >= sizeof(node))
669
       return -errno;
670
     if (stat(node, &sbuf))
671
         return -EINVAL;
672
@@ -3989,7 +4083,7 @@ drm_public int drmGetDevice(int fd, drmDevicePtr *devi
673
 /**
559
 /**
674
  * Get drm devices on the system
560
  * Get drm devices on the system
675
  *
561
  *
676
- * \param flags feature/behaviour bitmask
562
- * \param flags feature/behaviour bitmask
677
+ * \param flags feature/behavior bitmask
563
+ * \param flags feature/behavior bitmask
678
  * \param devices the array of devices with drmDevicePtr elements
564
  * \param devices the array of devices with drmDevicePtr elements
679
  *                can be NULL to get the device number first
565
  *                can be NULL to get the device number first
680
  * \param max_devices the maximum number of devices for the array
566
  * \param max_devices the maximum number of devices for the array
681
@@ -4074,7 +4168,7 @@ drm_public int drmGetDevices(drmDevicePtr devices[], i
567
@@ -4074,7 +4210,7 @@ drm_public int drmGetDevices(drmDevicePtr devices[], i
682
 drm_public char *drmGetDeviceNameFromFd2(int fd)
568
 drm_public char *drmGetDeviceNameFromFd2(int fd)
683
 {
569
 {
684
 #ifdef __linux__
570
 #ifdef __linux__
685
-    struct stat sbuf;
571
-    struct stat sbuf;
686
+    stat_t sbuf;
572
+    stat_t sbuf;
687
     char path[PATH_MAX + 1], *value;
573
     char path[PATH_MAX + 1], *value;
688
     unsigned int maj, min;
574
     unsigned int maj, min;
689
 
575
 
690
@@ -4097,9 +4191,26 @@ drm_public char *drmGetDeviceNameFromFd2(int fd)
576
@@ -4097,9 +4233,26 @@ drm_public char *drmGetDeviceNameFromFd2(int fd)
691
     free(value);
577
     free(value);
692
 
578
 
693
     return strdup(path);
579
     return strdup(path);
694
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
580
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
695
+    stat_t sbuf;
581
+    stat_t sbuf;
696
+    if (fstat(fd, &sbuf))
582
+    if (fstat(fd, &sbuf))
697
+        return NULL;
583
+        return NULL;
698
+
584
+
699
+    dev_t rdev = sbuf.st_rdev;
585
+    dev_t rdev = sbuf.st_rdev;
700
+    /* minor numbers don't depend on node name suffix, search for a match */
586
+    /* minor numbers don't depend on node name suffix, search for a match */
701
+    for (int i = 0; i < DRM_MAX_MINOR; ++i) {
587
+    for (int i = 0; i < DRM_MAX_MINOR; ++i) {
702
+        char node[DRM_NODE_NAME_MAX];
588
+        char node[DRM_NODE_NAME_MAX];
703
+        for (int j = 0; j < DRM_NODE_MAX; ++j) {
589
+        for (int j = 0; j < DRM_NODE_MAX; ++j) {
704
+            snprintf(node, sizeof(node), drmGetDeviceName(j),
590
+            snprintf(node, sizeof(node), drmGetDeviceName(j),
705
+                     DRM_DIR_NAME, drmGetMinorBase(j) + i);
591
+                     DRM_DIR_NAME, drmGetMinorBase(j) + i);
706
+            if (stat(node, &sbuf) == 0 && sbuf.st_rdev == rdev)
592
+            if (stat(node, &sbuf) == 0 && sbuf.st_rdev == rdev)
707
+                return strdup(node);
593
+                return strdup(node);
708
+        }
594
+        }
709
+    }
595
+    }
710
+    return NULL;
596
+    return NULL;
711
 #else
597
 #else
712
-    struct stat      sbuf;
598
-    struct stat      sbuf;
713
-    char             node[PATH_MAX + 1];
599
-    char             node[PATH_MAX + 1];
714
+    stat_t           sbuf;
600
+    stat_t           sbuf;
715
+    char             node[DRM_NODE_NAME_MAX];
601
+    char             node[DRM_NODE_NAME_MAX];
716
     const char      *dev_name;
602
     const char      *dev_name;
717
     int              node_type;
603
     int              node_type;
718
     int              maj, min, n, base;
604
     int              maj, min, n, base;
719
@@ -4117,26 +4228,16 @@ drm_public char *drmGetDeviceNameFromFd2(int fd)
720
     if (node_type == -1)
721
         return NULL;
722
 
723
-    switch (node_type) {
724
-    case DRM_NODE_PRIMARY:
725
-        dev_name = DRM_DEV_NAME;
726
-        break;
727
-    case DRM_NODE_CONTROL:
728
-        dev_name = DRM_CONTROL_DEV_NAME;
729
-        break;
730
-    case DRM_NODE_RENDER:
731
-        dev_name = DRM_RENDER_DEV_NAME;
732
-        break;
733
-    default:
734
+    dev_name = drmGetDeviceName(node_type);
735
+    if (!dev_name)
736
         return NULL;
737
-    };
738
 
739
     base = drmGetMinorBase(node_type);
740
     if (base < 0)
741
         return NULL;
742
 
743
-    n = snprintf(node, PATH_MAX, dev_name, DRM_DIR_NAME, min - base);
744
-    if (n == -1 || n >= PATH_MAX)
745
+    n = snprintf(node, sizeof(node), dev_name, DRM_DIR_NAME, min - base);
746
+    if (n == -1 || n >= sizeof(node))
747
       return NULL;
748
 
749
     return strdup(node);
(-)graphics/libdrm/files/patch-xf86drm.h (-36 lines)
Lines 1-36 Link Here
1
--- xf86drm.h.orig	2018-03-05 21:06:45 UTC
2
+++ xf86drm.h
3
@@ -78,16 +78,26 @@ extern "C" {
4
 
5
 #ifdef __OpenBSD__
6
 #define DRM_DIR_NAME  "/dev"
7
-#define DRM_DEV_NAME  "%s/drm%d"
8
-#define DRM_CONTROL_DEV_NAME  "%s/drmC%d"
9
-#define DRM_RENDER_DEV_NAME  "%s/drmR%d"
10
+#define DRM_PRIMARY_MINOR_NAME  "drm"
11
+#define DRM_CONTROL_MINOR_NAME  "drmC"
12
+#define DRM_RENDER_MINOR_NAME   "drmR"
13
 #else
14
 #define DRM_DIR_NAME  "/dev/dri"
15
-#define DRM_DEV_NAME  "%s/card%d"
16
-#define DRM_CONTROL_DEV_NAME  "%s/controlD%d"
17
-#define DRM_RENDER_DEV_NAME  "%s/renderD%d"
18
-#define DRM_PROC_NAME "/proc/dri/" /* For backward Linux compatibility */
19
+#define DRM_PRIMARY_MINOR_NAME  "card"
20
+#define DRM_CONTROL_MINOR_NAME  "controlD"
21
+#define DRM_RENDER_MINOR_NAME   "renderD"
22
 #endif
23
+
24
+#define DRM_DEV_NAME  "%s/" DRM_PRIMARY_MINOR_NAME "%d"
25
+#define DRM_CONTROL_DEV_NAME  "%s/" DRM_CONTROL_MINOR_NAME "%d"
26
+#define DRM_RENDER_DEV_NAME  "%s/" DRM_RENDER_MINOR_NAME "%d"
27
+
28
+#define DRM_NODE_NAME_MAX                   \
29
+    (sizeof(DRM_DIR_NAME) +                 \
30
+     MAX3(sizeof(DRM_PRIMARY_MINOR_NAME),   \
31
+         sizeof(DRM_CONTROL_MINOR_NAME),    \
32
+         sizeof(DRM_RENDER_MINOR_NAME))     \
33
+    + 3) /* length of the node number */
34
 
35
 #define DRM_ERR_NO_DEVICE  (-1001)
36
 #define DRM_ERR_NO_ACCESS  (-1002)

Return to bug 243283