1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
7 SDESC[standard]= Direct Rendering Module services kernel interface
8 HOMEPAGE= https://dri.freedesktop.org
12 SITES[main]= http://dri.freedesktop.org/libdrm/
13 DISTFILE[1]= libdrm-2.4.100.tar.bz2:main
15 SPKGS[standard]= single
17 OPTIONS_AVAILABLE= ARM X86
18 OPTIONS_STANDARD= ARM X86
23 BUILD_DEPENDS= libpthread-stubs:single:standard
24 docbook-xsl:primary:standard
25 libxslt:single:standard
26 libxml2:single:standard
28 USES= gmake libtool pkgconfig solaris-funcs
29 XORG_COMPONENTS= pciaccess
32 LICENSE_FILE= MIT:{{WRKDIR}}/LICENSE_MIT
33 LICENSE_AWK= MIT:"_XF86DRM_H_"
34 LICENSE_SOURCE= MIT:{{WRKSRC}}/xf86drm.h
37 FPC_EQUIVALENT= graphics/libdrm
38 SOL_FUNCTIONS= getline:amdgpu/amdgpu_asic_id.c
39 asprintf:tests/modetest/modetest.c
40 strndup:tests/modetest/modetest.c
43 CONFIGURE_ARGS= --disable-cairo-tests
44 --enable-install-test-programs
48 INSTALL_TARGET= install-strip
49 INSTALL_REQ_TOOLCHAIN= yes
51 [X86].DESCRIPTION= DRM Drivers for amd64 and i386 architectures
53 [ARM].DESCRIPTION= DRM Drivers for AARCH64 architecture
57 -e '/^MANPAGES_STYLESHEET=/ s|".*"|"http://cdn.docbook.org/release/xsl/current/manpages/docbook.xsl"|' \
60 [FILE:70:descriptions/desc.single]
61 Userspace interface to kernel DRM (Direct Rendering Module) services.
65 c77cc828186c9ceec3e56ae202b43ee99eb932b4a87255038a80e8a1060d0a5d 855793 libdrm-2.4.100.tar.bz2
68 [FILE:2195:manifests/plist.single]
69 %%ARM-ON%%include/freedreno/
71 freedreno_ringbuffer.h
72 %%ARM-ON%%include/libdrm/
78 libdrm_freedreno.so.1.0.0
79 %%ARM-ON%%lib/pkgconfig/
82 %%ONLY-DRAGONFLY%%bin/kmstest
83 %%ONLY-DRAGONFLY%%include/libkms/libkms.h
84 %%ONLY-DRAGONFLY%%lib/
88 %%ONLY-DRAGONFLY%%lib/pkgconfig/libkms.pc
89 %%ONLY-FREEBSD%%bin/kmstest
90 %%ONLY-FREEBSD%%include/libkms/libkms.h
95 %%ONLY-FREEBSD%%lib/pkgconfig/libkms.pc
96 %%ONLY-LINUX%%bin/kmstest
97 %%ONLY-LINUX%%include/libkms/libkms.h
102 %%ONLY-LINUX%%lib/pkgconfig/libkms.pc
103 %%X86-ON%%include/libdrm/
117 %%X86-ON%%include/libdrm/nouveau/nouveau.h
118 %%X86-ON%%include/libdrm/nouveau/nvif/
129 libdrm_amdgpu.so.1.0.0
132 libdrm_intel.so.1.0.0
135 libdrm_nouveau.so.2.0.0
138 libdrm_radeon.so.1.0.1
139 %%X86-ON%%lib/pkgconfig/
144 %%X86-ON%%share/libdrm/amdgpu.ids
181 lib/pkgconfig/libdrm.pc
185 drmModeGetResources.3.gz
195 [FILE:834:patches/patch-amdgpu_amdgpu__device.c]
196 --- amdgpu/amdgpu_device.c.orig 2019-10-16 21:36:48 UTC
197 +++ amdgpu/amdgpu_device.c
198 @@ -177,7 +177,12 @@ drm_public int amdgpu_device_initialize(
201 if ((flag_auth) && (!flag_authexist)) {
202 +#ifdef F_DUPFD_CLOEXEC
203 dev->flink_fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
205 + dev->flink_fd = fcntl(fd, F_DUPFD, 0);
206 + fcntl(dev->flink_fd, F_SETFD, FD_CLOEXEC);
209 *major_version = dev->major_version;
210 *minor_version = dev->minor_version;
211 @@ -211,7 +216,12 @@ drm_public int amdgpu_device_initialize(
215 +#ifdef F_DUPFD_CLOEXEC
216 dev->fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
218 + dev->fd = fcntl(fd, F_DUPFD, 0);
219 + fcntl(dev->fd, F_SETFD, FD_CLOEXEC);
221 dev->flink_fd = dev->fd;
222 dev->major_version = version->version_major;
223 dev->minor_version = version->version_minor;
226 [FILE:283:patches/patch-include_drm_drm.h]
227 --- include/drm/drm.h.orig 2019-10-16 21:36:48 UTC
228 +++ include/drm/drm.h
229 @@ -699,7 +699,11 @@ struct drm_set_client_cap {
232 #define DRM_RDWR O_RDWR
234 +#define DRM_CLOEXEC 0
236 #define DRM_CLOEXEC O_CLOEXEC
238 struct drm_prime_handle {
243 [FILE:691:patches/patch-intel_intel__bufmgr__gem.c]
244 --- intel/intel_bufmgr_gem.c.orig 2019-10-16 21:36:48 UTC
245 +++ intel/intel_bufmgr_gem.c
246 @@ -1005,6 +1005,27 @@ drm_intel_gem_bo_alloc_userptr(drm_intel
251 +#define posix_memalign illumos_memalign
253 +posix_memalign(void **memptr, size_t alignment, size_t size)
258 + if (alignment == 0 ||
259 + (alignment & (sizeof (void *) - 1)) != 0 ||
260 + (alignment & (alignment - 1)) != 0)
262 + else if (size != 0 &&
263 + (ptr = memalign(alignment, size)) == NULL)
272 has_userptr(drm_intel_bufmgr_gem *bufmgr_gem)
276 [FILE:379:patches/patch-intel_test__decode.c]
277 --- intel/test_decode.c.orig 2019-10-16 21:36:48 UTC
278 +++ intel/test_decode.c
281 #include <sys/types.h>
282 #include <sys/stat.h>
284 +#define errx(exitcode, format, args...) \
285 + { fprintf(stderr, format "\n", ## args); \
291 #include "libdrm_macros.h"
292 #include "intel_bufmgr.h"
295 [FILE:852:patches/patch-libkms_vmwgfx.c]
296 # the defintion of ERESTART is behind a check for _KERNEL, but
297 # defining that causes errno to not be defined. fortunately, there's
298 # an alternative switch. unfortunately, those differ by platform and
299 # _WANT_KERNEL_ERRNO is too recent to be part of any release, so just
300 # define ERESTART if we still don't have it after including errno.h
302 --- libkms/vmwgfx.c.orig 2019-10-16 21:36:48 UTC
305 **************************************************************************/
308 +#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
309 +#define _WANT_KERNEL_ERRNO
310 +#elif defined(__DragonFly__)
311 +#define _KERNEL_STRUCTURES
316 #include "internal.h"
318 +#define ERESTART (-1)
322 #include "libdrm_macros.h"
325 [FILE:521:patches/patch-libsync.h]
326 define ETIME as ETIMEOUT same as done in mesa
328 --- libsync.h.orig 2019-10-16 21:36:48 UTC
331 #include <sys/ioctl.h>
332 #include <sys/poll.h>
335 +#define ETIME ETIMEDOUT
338 #if defined(__cplusplus)
340 @@ -53,6 +56,9 @@ struct sync_merge_data {
345 +#include <sys/ioccom.h>
347 #define SYNC_IOC_MAGIC '>'
348 #define SYNC_IOC_MERGE _IOWR(SYNC_IOC_MAGIC, 3, struct sync_merge_data)
352 [FILE:267:patches/patch-tests_drmdevice.c]
353 --- tests/drmdevice.c.orig 2019-10-16 21:36:48 UTC
354 +++ tests/drmdevice.c
364 print_device_info(drmDevicePtr device, int i, bool print_revision)
367 [FILE:16850:patches/patch-xf86drm.c]
368 --- xf86drm.c.orig 2019-10-16 21:36:48 UTC
371 * DEALINGS IN THE SOFTWARE.
374 +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
384 #ifdef MAJOR_IN_SYSMACROS
385 #include <sys/sysmacros.h>
388 +#include <sys/pciio.h>
390 +#ifdef HAVE_SYS_SYSCTL_H
391 +#include <sys/sysctl.h>
395 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
398 #include "util_math.h"
400 -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
401 -#define DRM_MAJOR 145
407 +#define DRM_MAJOR 0 /* Major ID unused on systems with devfs */
411 @@ -212,6 +228,63 @@ drm_public drmHashEntry *drmGetEntry(int
416 +static int drmGetMinorBase(int type)
419 + case DRM_NODE_PRIMARY:
420 + case DRM_NODE_CONTROL:
421 + case DRM_NODE_RENDER:
428 +static int drmGetMinorType(int minor)
437 + case DRM_NODE_PRIMARY:
438 + case DRM_NODE_CONTROL:
439 + case DRM_NODE_RENDER:
446 +static int drmGetNodeNumber(const char *name)
448 + size_t name_len = strnlen(name, DRM_NODE_NAME_MAX);
449 + while (name_len && isdigit(name[name_len - 1]))
451 + return strtol(name + name_len, NULL, 10);
453 +#endif /* FREEDFLY */
455 +static int drmGetNodeType(const char *name)
457 + if (strncmp(name, DRM_PRIMARY_MINOR_NAME,
458 + sizeof(DRM_PRIMARY_MINOR_NAME) - 1) == 0)
459 + return DRM_NODE_PRIMARY;
461 + if (strncmp(name, DRM_CONTROL_MINOR_NAME,
462 + sizeof(DRM_CONTROL_MINOR_NAME ) - 1) == 0)
463 + return DRM_NODE_CONTROL;
465 + if (strncmp(name, DRM_RENDER_MINOR_NAME,
466 + sizeof(DRM_RENDER_MINOR_NAME) - 1) == 0)
467 + return DRM_NODE_RENDER;
473 * Compare two busid strings
475 @@ -343,7 +416,11 @@ static int drmOpenDevice(dev_t dev, int
480 + sprintf(buf, dev_name, DRM_DIR_NAME, minor + drmGetMinorBase(type));
482 sprintf(buf, dev_name, DRM_DIR_NAME, minor);
484 drmMsg("drmOpenDevice: node name is %s\n", buf);
486 if (drm_server_info && drm_server_info->get_perms) {
487 @@ -456,7 +533,11 @@ static int drmOpenMinor(int minor, int c
492 + sprintf(buf, dev_name, DRM_DIR_NAME, minor + drmGetMinorBase(type));
494 sprintf(buf, dev_name, DRM_DIR_NAME, minor);
496 if ((fd = open(buf, O_RDWR | O_CLOEXEC, 0)) >= 0)
499 @@ -497,6 +578,7 @@ drm_public int drmAvailable(void)
504 static int drmGetMinorBase(int type)
507 @@ -527,7 +609,9 @@ static int drmGetMinorType(int minor)
511 +#endif /* !FREEDFLY */
514 static const char *drmGetMinorName(int type)
517 @@ -541,6 +625,7 @@ static const char *drmGetMinorName(int t
524 * Open the device by bus ID.
525 @@ -2552,7 +2637,7 @@ drm_public int drmCommandNone(int fd, un
527 unsigned long request;
529 - request = DRM_IO( DRM_COMMAND_BASE + drmCommandIndex);
530 + request = DRM_IO( (DRM_COMMAND_BASE + drmCommandIndex) );
532 if (drmIoctl(fd, request, NULL)) {
534 @@ -2744,7 +2829,6 @@ drm_public int drmIsMaster(int fd)
536 drm_public char *drmGetDeviceNameFromFd(int fd)
542 @@ -2758,14 +2842,12 @@ drm_public char *drmGetDeviceNameFromFd(
545 for (i = 0; i < DRM_MAX_MINOR; i++) {
546 + char name[DRM_NODE_NAME_MAX];
547 snprintf(name, sizeof name, DRM_DEV_NAME, DRM_DIR_NAME, i);
548 if (stat(name, &sbuf) == 0 && sbuf.st_rdev == d)
550 + return strdup(name);
552 - if (i == DRM_MAX_MINOR)
555 - return strdup(name);
559 static bool drmNodeIsDRM(int maj, int min)
560 @@ -2784,6 +2866,20 @@ static bool drmNodeIsDRM(int maj, int mi
562 drm_public int drmGetNodeTypeFromFd(int fd)
565 + char *name = drmGetDeviceNameFromFd2(fd);
572 + type = drmGetNodeType(name);
581 @@ -2802,6 +2898,7 @@ drm_public int drmGetNodeTypeFromFd(int
585 +#endif /* FREEDFLY */
588 drm_public int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags,
589 @@ -2880,6 +2977,23 @@ static char *drmGetMinorNameForFD(int fd
594 + int oldnum, oldtype, newnum;
595 + const char *dev_name = drmGetDeviceName(type);
596 + char *name = drmGetDeviceNameFromFd2(fd);
597 + if (!dev_name || !name)
600 + oldnum = drmGetNodeNumber(name);
601 + oldtype = drmGetMinorType(oldnum);
607 + newnum = oldnum - drmGetMinorBase(oldtype) + drmGetMinorBase(type);
608 + snprintf(name, DRM_NODE_NAME_MAX, dev_name, DRM_DIR_NAME, newnum);
612 char buf[PATH_MAX + 1];
613 @@ -2900,7 +3014,7 @@ static char *drmGetMinorNameForFD(int fd
616 n = snprintf(buf, sizeof(buf), dev_name, DRM_DIR_NAME, min);
617 - if (n == -1 || n >= sizeof(buf))
618 + if (n == -1 || n >= (int)sizeof(buf))
622 @@ -2998,7 +3112,7 @@ static int drmParseSubsystemType(int maj
626 -#elif defined(__OpenBSD__) || defined(__DragonFly__)
627 +#elif defined(__OpenBSD__) || FREEDFLY
630 #warning "Missing implementation of drmParseSubsystemType"
631 @@ -3006,6 +3120,7 @@ static int drmParseSubsystemType(int maj
637 get_pci_path(int maj, int min, char *pci_path)
639 @@ -3021,8 +3136,10 @@ get_pci_path(int maj, int min, char *pci
640 if (term && strncmp(term, "/virtio", 7) == 0)
645 -static int drmParsePciBusInfo(int maj, int min, drmPciBusInfoPtr info)
646 +static int drmParsePciBusInfo(const char *node, int node_type,
647 + int maj, int min, drmPciBusInfoPtr info)
650 unsigned int domain, bus, dev, func;
651 @@ -3047,7 +3164,62 @@ static int drmParsePciBusInfo(int maj, i
655 -#elif defined(__OpenBSD__) || defined(__DragonFly__)
658 + * Only the primary nodes can be mapped to hw.dri.%i via major/minor
659 + * Determine the primary node by offset and use its major/minor pair
661 + if (node_type != DRM_NODE_PRIMARY) {
662 + char name[DRM_NODE_NAME_MAX];
664 + snprintf(name, sizeof(name), DRM_DEV_NAME, DRM_DIR_NAME,
665 + drmGetNodeNumber(node) - drmGetMinorBase(node_type));
667 + if (stat(name, &sbuf))
670 + maj = major(sbuf.st_rdev);
671 + min = minor(sbuf.st_rdev);
674 + * Major/minor appear after the driver name in the hw.dri.%i.name node
675 + * Find the node with matching major/minor pair and parse the bus ID,
676 + * which may be after the name or may be alone in hw.dri.%i.busid
678 + #define bus_fmt "pci:%04x:%02x:%02x.%u"
679 + #define name_fmt "%*s %x " bus_fmt
680 + for (int i = 0; i < DRM_MAX_MINOR; ++i) {
681 + char name[16], value[256];
682 + unsigned int rdev = 0, domain = 0, bus = 0, slot = 0, func = 0;
684 + size_t length = sizeof(value);
685 + snprintf(name, sizeof(name), "hw.dri.%i.name", i);
686 + if (sysctlbyname(name, value, &length, NULL, 0))
689 + value[length] = '\0';
690 + vals = sscanf(value, name_fmt, &rdev, &domain, &bus, &slot, &func);
692 + if (vals >= 1 && rdev == makedev(maj,min)) {
694 + /* busid not in the name, try busid */
695 + length = sizeof(value);
696 + snprintf(name, sizeof(name), "hw.dri.%i.busid", i);
697 + if (sysctlbyname(name, value, &length, NULL, 0))
699 + value[length] = '\0';
700 + if (sscanf(value, bus_fmt, &domain, &bus, &slot, &func) != 4)
703 + info->domain = domain;
711 +#elif defined(__OpenBSD__)
712 struct drm_pciinfo pinfo;
715 @@ -3105,32 +3277,6 @@ drm_public int drmDevicesEqual(drmDevice
719 -static int drmGetNodeType(const char *name)
721 - if (strncmp(name, DRM_CONTROL_MINOR_NAME,
722 - sizeof(DRM_CONTROL_MINOR_NAME ) - 1) == 0)
723 - return DRM_NODE_CONTROL;
725 - if (strncmp(name, DRM_RENDER_MINOR_NAME,
726 - sizeof(DRM_RENDER_MINOR_NAME) - 1) == 0)
727 - return DRM_NODE_RENDER;
729 - if (strncmp(name, DRM_PRIMARY_MINOR_NAME,
730 - sizeof(DRM_PRIMARY_MINOR_NAME) - 1) == 0)
731 - return DRM_NODE_PRIMARY;
736 -static int drmGetMaxNodeName(void)
738 - return sizeof(DRM_DIR_NAME) +
739 - MAX3(sizeof(DRM_PRIMARY_MINOR_NAME),
740 - sizeof(DRM_CONTROL_MINOR_NAME),
741 - sizeof(DRM_RENDER_MINOR_NAME)) +
742 - 3 /* length of the node number */;
746 static int parse_separate_sysfs_files(int maj, int min,
747 drmPciDeviceInfoPtr device,
748 @@ -3202,6 +3348,7 @@ static int parse_config_sysfs_file(int m
751 static int drmParsePciDeviceInfo(int maj, int min,
752 + drmPciBusInfoPtr info,
753 drmPciDeviceInfoPtr device,
756 @@ -3213,7 +3360,44 @@ static int drmParsePciDeviceInfo(int maj
757 return parse_config_sysfs_file(maj, min, device);
760 -#elif defined(__OpenBSD__) || defined(__DragonFly__)
762 + struct pci_conf_io pc;
763 + struct pci_match_conf patterns[1];
764 + struct pci_conf results[1];
766 + int fd = open("/dev/pci", O_RDONLY, 0);
770 + bzero(&patterns, sizeof(patterns));
771 + patterns[0].pc_sel.pc_domain = info->domain;
772 + patterns[0].pc_sel.pc_bus = info->bus;
773 + patterns[0].pc_sel.pc_dev = info->dev;
774 + patterns[0].pc_sel.pc_func = info->func;
775 + patterns[0].flags = PCI_GETCONF_MATCH_DOMAIN | PCI_GETCONF_MATCH_BUS
776 + | PCI_GETCONF_MATCH_DEV | PCI_GETCONF_MATCH_FUNC;
777 + bzero(&pc, sizeof(struct pci_conf_io));
778 + pc.num_patterns = 1;
779 + pc.pat_buf_len = sizeof(patterns);
780 + pc.patterns = patterns;
781 + pc.match_buf_len = sizeof(results);
782 + pc.matches = results;
784 + if (ioctl(fd, PCIOCGETCONF, &pc) || pc.status == PCI_GETCONF_ERROR) {
791 + device->vendor_id = results[0].pc_vendor;
792 + device->device_id = results[0].pc_device;
793 + device->subvendor_id = results[0].pc_subvendor;
794 + device->subdevice_id = results[0].pc_subdevice;
795 + device->revision_id = results[0].pc_revid;
798 +#elif defined(__OpenBSD__)
799 struct drm_pciinfo pinfo;
802 @@ -3318,7 +3502,7 @@ static drmDevicePtr drmDeviceAlloc(unsig
806 - max_node_length = ALIGN(drmGetMaxNodeName(), sizeof(void *));
807 + max_node_length = ALIGN(DRM_NODE_NAME_MAX, sizeof(void *));
808 extra = DRM_NODE_MAX * (sizeof(void *) + max_node_length);
810 size = sizeof(*device) + extra + bus_size + device_size;
811 @@ -3364,7 +3548,7 @@ static int drmProcessPciDevice(drmDevice
813 dev->businfo.pci = (drmPciBusInfoPtr)addr;
815 - ret = drmParsePciBusInfo(maj, min, dev->businfo.pci);
816 + ret = drmParsePciBusInfo(node, node_type, maj, min, dev->businfo.pci);
820 @@ -3373,7 +3557,7 @@ static int drmProcessPciDevice(drmDevice
821 addr += sizeof(drmPciBusInfo);
822 dev->deviceinfo.pci = (drmPciDeviceInfoPtr)addr;
824 - ret = drmParsePciDeviceInfo(maj, min, dev->deviceinfo.pci, flags);
825 + ret = drmParsePciDeviceInfo(maj, min, dev->businfo.pci, dev->deviceinfo.pci, flags);
829 @@ -3675,7 +3859,7 @@ process_device(drmDevicePtr *device, con
830 bool fetch_deviceinfo, uint32_t flags)
833 - char node[PATH_MAX + 1];
834 + char node[DRM_NODE_NAME_MAX];
835 int node_type, subsystem_type;
836 unsigned int maj, min;
838 @@ -3683,14 +3867,14 @@ process_device(drmDevicePtr *device, con
842 - snprintf(node, PATH_MAX, "%s/%s", DRM_DIR_NAME, d_name);
843 + snprintf(node, sizeof(node), "%s/%s", DRM_DIR_NAME, d_name);
844 if (stat(node, &sbuf))
847 maj = major(sbuf.st_rdev);
848 min = minor(sbuf.st_rdev);
850 - if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode))
851 + if ((DRM_MAJOR && maj != DRM_MAJOR) || !S_ISCHR(sbuf.st_mode))
854 subsystem_type = drmParseSubsystemType(maj, min);
855 @@ -3731,7 +3915,7 @@ static void drmFoldDuplicatedDevices(drm
856 local_devices[i]->available_nodes |= local_devices[j]->available_nodes;
857 node_type = log2(local_devices[j]->available_nodes);
858 memcpy(local_devices[i]->nodes[node_type],
859 - local_devices[j]->nodes[node_type], drmGetMaxNodeName());
860 + local_devices[j]->nodes[node_type], DRM_NODE_NAME_MAX);
861 drmFreeDevice(&local_devices[j]);
864 @@ -3790,7 +3974,7 @@ drm_public int drmGetDevice2(int fd, uin
868 - char node[PATH_MAX + 1];
869 + char node[DRM_NODE_NAME_MAX];
870 const char *dev_name;
871 int node_type, subsystem_type;
872 int maj, min, n, ret;
873 @@ -3804,7 +3988,7 @@ drm_public int drmGetDevice2(int fd, uin
874 maj = major(sbuf.st_rdev);
875 min = minor(sbuf.st_rdev);
877 - if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode))
878 + if (DRM_MAJOR && !drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode))
881 node_type = drmGetMinorType(min);
882 @@ -3815,8 +3999,8 @@ drm_public int drmGetDevice2(int fd, uin
886 - n = snprintf(node, PATH_MAX, dev_name, DRM_DIR_NAME, min);
887 - if (n == -1 || n >= PATH_MAX)
888 + n = snprintf(node, sizeof(node), dev_name, DRM_DIR_NAME, min);
889 + if (n == -1 || n >= (int)sizeof(node))
891 if (stat(node, &sbuf))
893 @@ -4030,9 +4214,27 @@ drm_public char *drmGetDeviceNameFromFd2
900 + if (fstat(fd, &sbuf))
903 + rdev = sbuf.st_rdev;
904 + /* minor numbers don't depend on node name suffix, search for a match */
905 + for (int i = 0; i < DRM_MAX_MINOR; ++i) {
906 + char node[DRM_NODE_NAME_MAX];
907 + for (int j = 0; j < DRM_NODE_MAX; ++j) {
908 + snprintf(node, sizeof(node), drmGetDeviceName(j),
909 + DRM_DIR_NAME, drmGetMinorBase(j) + i);
910 + if (stat(node, &sbuf) == 0 && sbuf.st_rdev == rdev)
911 + return strdup(node);
917 - char node[PATH_MAX + 1];
918 + char node[DRM_NODE_NAME_MAX];
919 const char *dev_name;
922 @@ -4054,8 +4256,8 @@ drm_public char *drmGetDeviceNameFromFd2
926 - n = snprintf(node, PATH_MAX, dev_name, DRM_DIR_NAME, min);
927 - if (n == -1 || n >= PATH_MAX)
928 + n = snprintf(node, sizeof(node), dev_name, DRM_DIR_NAME, min);
929 + if (n == -1 || n >= (int)sizeof(node))
935 [FILE:397:patches/patch-xf86drm.h]
936 --- xf86drm.h.orig 2019-10-16 21:36:48 UTC
938 @@ -59,6 +59,9 @@ extern "C" {
939 #else /* One of the *BSDs */
941 #include <sys/ioccom.h>
943 +#define _IOC(inout,group,num,len) (inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num))
945 #define DRM_IOCTL_NR(n) ((n) & 0xff)
946 #define DRM_IOC_VOID IOC_VOID
947 #define DRM_IOC_READ IOC_OUT
950 [FILE:3248:patches/patch-xf86drmMode.c]
951 --- xf86drmMode.c.orig 2019-10-16 21:36:48 UTC
955 #include <sys/ioctl.h>
956 #ifdef HAVE_SYS_SYSCTL_H
957 +#include <sys/types.h>
958 #include <sys/sysctl.h>
961 @@ -799,41 +800,59 @@ drm_public int drmCheckModesettingSuppor
965 -#elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
966 - char kbusid[1024], sbusid[1024];
968 - int domain, bus, dev, func;
969 - int i, modesetting, ret;
971 +#elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__DragonFly__)
972 + #define bus_fmt "pci:%04x:%02x:%02x.%u"
973 + #define name_fmt "%*s %*s " bus_fmt
974 + unsigned int d1 = 0, b1 = 0, s1 = 0, f1 = 0;
975 + if (sscanf(busid, bus_fmt, &d1, &b1, &s1, &f1) != 4)
978 + * hw.dri.%i.bus is not always present and hw.dri.%i.name does not
979 + * always contain the busid, so try both for best chance of success
981 + for (int i = 0; i < DRM_MAX_MINOR; ++i) {
982 + char name[22], value[256];
983 + unsigned int d2 = 0, b2 = 0, s2 = 0, f2 = 0;
984 + size_t length = sizeof(value);
985 + snprintf(name, sizeof(name), "hw.dri.%i.name", i);
986 + if (sysctlbyname(name, value, &length, NULL, 0))
989 - ret = sscanf(busid, "pci:%04x:%02x:%02x.%d", &domain, &bus, &dev,
993 - snprintf(kbusid, sizeof(kbusid), "pci:%04x:%02x:%02x.%d", domain, bus,
995 + value[length] = '\0';
996 + switch (sscanf(value, name_fmt, &d2, &b2, &s2, &f2)) {
997 + case 0: /* busid not in the name, try busid */
998 + length = sizeof(value);
999 + snprintf(name, sizeof(name), "hw.dri.%i.busid", i);
1000 + if (sysctlbyname(name, value, &length, NULL, 0))
1003 - /* How many GPUs do we expect in the machine ? */
1004 - for (i = 0; i < 16; i++) {
1005 - snprintf(oid, sizeof(oid), "hw.dri.%d.busid", i);
1006 - len = sizeof(sbusid);
1007 - ret = sysctlbyname(oid, sbusid, &len, NULL, 0);
1009 - if (errno == ENOENT)
1010 + value[length] = '\0';
1011 + if (sscanf(value, bus_fmt, &d2, &b2, &s2, &f2) != 4)
1014 + /* fall through after parsing busid */
1016 + case 4: /* if we jumped here then busid was in the name */
1017 + if (d1 == d2 && b1 == b2 && s1 == s2 && f1 == f2) {
1019 + * Confirm the drm driver for this device supports KMS,
1020 + * except on DragonFly where all the drm drivers do so
1021 + * but only hw.dri.0.modesetting is present
1023 + #ifndef __DragonFly__
1024 + int modesetting = 0;
1025 + length = sizeof(modesetting);
1026 + snprintf(name, sizeof(name), "hw.dri.%i.modesetting", i);
1027 + if (sysctlbyname(name, &modesetting, &length, NULL, 0)
1028 + || length != sizeof(modesetting) || !modesetting)
1037 - if (strcmp(sbusid, kbusid) != 0)
1039 - snprintf(oid, sizeof(oid), "hw.dri.%d.modesetting", i);
1040 - len = sizeof(modesetting);
1041 - ret = sysctlbyname(oid, &modesetting, &len, NULL, 0);
1042 - if (ret == -1 || len != sizeof(modesetting))
1044 - return (modesetting ? 0 : -ENOSYS);
1046 -#elif defined(__DragonFly__)
1048 #elif defined(__OpenBSD__)
1050 struct drm_mode_card_res res;