summaryrefslogtreecommitdiff
path: root/multimedia/onevpl/files/patch-drm-to-pciid
blob: 81d91d0279093383cd917ed1abe7c7e45fe126e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/sys/class/drm/renderD*/device/device is Linux-only, so use a BSD extension
to get vendor/device identifiers from rendor nodes. Based on libdrm code.

$ ffmpeg -hide_banner -init_hw_device qsv=auto -i foo.y4m -vf hwupload=extra_hw_frames=64,format=qsv -c:v h264_qsv -y foo.mkv
[AVHWDeviceContext @ 0x8062d0140] Error initializing an MFX session: -3.
Device creation failed: -1313558101.
Failed to set value 'qsv=auto' for option 'init_hw_device': Unknown error occurred
Error parsing global options: Unknown error occurred

--- dispatcher/linux/device_ids.h.orig	2021-12-17 04:19:18 UTC
+++ dispatcher/linux/device_ids.h
@@ -377,7 +377,62 @@ static inline eMFXHWType get_platform(unsigned int dev
     return MFX_HW_UNKNOWN;
 }
 
+#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+#if defined(__FreeBSD__) && __FreeBSD__ < 13
+#include <sys/sysctl.h>
+#else
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <unistd.h>
+#endif // defined(__FreeBSD__) && __FreeBSD__ < 13
+
+struct drm_pciinfo {
+	uint16_t	domain;
+	uint8_t		bus;
+	uint8_t		dev;
+	uint8_t		func;
+	uint16_t	vendor_id;
+	uint16_t	device_id;
+	uint16_t	subvendor_id;
+	uint16_t	subdevice_id;
+	uint8_t		revision_id;
+};
+
+#define DRM_IOCTL_BASE		'd'
+#define DRM_IOR(nr,type)	_IOR(DRM_IOCTL_BASE,nr,type)
+#define DRM_IOCTL_GET_PCIINFO	DRM_IOR(0x15, struct drm_pciinfo)
+#endif
+
 static mfxStatus get_devices(std::vector<Device> &allDevices) {
+#ifdef DRM_IOCTL_GET_PCIINFO
+    std::vector <Device> result;
+    for (int i = 0; i < 64; ++i) {
+#if defined(__FreeBSD__) && __FreeBSD__ < 13
+        std::string mib = "dev.drm." + std::to_string(128 + i) + ".PCI_ID";
+        char pci_id[20];
+        size_t len = sizeof(pci_id);
+        if (sysctlbyname(mib.c_str(), pci_id, &len, NULL, 0)) continue;
+        Device device;
+        sscanf(pci_id, "%x:%x", &device.vendor_id, &device.device_id);
+#else
+        std::string path = "/dev/dri/renderD" + std::to_string(128 + i);
+        int fd = open(path.c_str(), O_RDONLY);
+        if (fd == -1) continue;
+        struct drm_pciinfo pinfo;
+        if (ioctl(fd, DRM_IOCTL_GET_PCIINFO, &pinfo)) {
+            close(fd);
+            continue;
+        }
+        Device device = { .vendor_id = pinfo.vendor_id, .device_id = pinfo.device_id };
+        close(fd);
+#endif // defined(__FreeBSD__) && __FreeBSD__ < 13
+        if (device.vendor_id != 0x8086) {  // Filter out non-Intel devices
+            continue;
+        }
+        device.platform = get_platform(device.device_id);
+        allDevices.emplace_back(device);
+    }
+#else
     const char *dir            = "/sys/class/drm";
     const char *device_id_file = "/device/device";
     const char *vendor_id_file = "/device/vendor";
@@ -413,6 +468,7 @@ static mfxStatus get_devices(std::vector<Device> &allD
 
         allDevices.emplace_back(device);
     }
+#endif
 
     // sort by platform, unknown will appear at beginning
     std::sort(allDevices.begin(), allDevices.end(), [](const Device &a, const Device &b) {
--- dispatcher/vpl/mfx_dispatcher_vpl_msdk.cpp.orig	2022-03-04 22:06:17 UTC
+++ dispatcher/vpl/mfx_dispatcher_vpl_msdk.cpp
@@ -446,6 +446,32 @@ mfxStatus LoaderCtxMSDK::CheckD3D9Support(mfxU64 luid,
 #endif
 }
 
+#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+#if defined(__FreeBSD__) && __FreeBSD__ < 13
+#include <sys/sysctl.h>
+#else
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <unistd.h>
+#endif // defined(__FreeBSD__) && __FreeBSD__ < 13
+
+struct drm_pciinfo {
+	uint16_t	domain;
+	uint8_t		bus;
+	uint8_t		dev;
+	uint8_t		func;
+	uint16_t	vendor_id;
+	uint16_t	device_id;
+	uint16_t	subvendor_id;
+	uint16_t	subdevice_id;
+	uint8_t		revision_id;
+};
+
+#define DRM_IOCTL_BASE		'd'
+#define DRM_IOR(nr,type)	_IOR(DRM_IOCTL_BASE,nr,type)
+#define DRM_IOCTL_GET_PCIINFO	DRM_IOR(0x15, struct drm_pciinfo)
+#endif
+
 mfxStatus LoaderCtxMSDK::GetRenderNodeDescription(mfxU32 adapterID,
                                                   mfxU32 &vendorID,
                                                   mfxU16 &deviceID) {
@@ -456,6 +482,28 @@
     mfxU32 DRMRenderNodeNum = 128 + adapterID;
     std::string nodeStr     = std::to_string(DRMRenderNodeNum);
 
+#ifdef DRM_IOCTL_GET_PCIINFO
+#if defined(__FreeBSD__) && __FreeBSD__ < 13
+    std::string mib = "dev.drm." + nodeStr + ".PCI_ID";
+    char pci_id[20];
+    size_t len = sizeof(pci_id);
+    if (!sysctlbyname(mib.c_str(), pci_id, &len, NULL, 0))
+        sscanf(pci_id, "%x:%hx", &vendorID, &deviceID);
+#else
+    std::string path = "/dev/dri/renderD" + nodeStr;
+    int fd = open(path.c_str(), O_RDONLY);
+    if (fd != -1) {
+        struct drm_pciinfo pinfo;
+        if (!ioctl(fd, DRM_IOCTL_GET_PCIINFO, &pinfo)) {
+            vendorID = pinfo.vendor_id;
+            deviceID = pinfo.device_id;
+        }
+        close(fd);
+    }
+#endif // defined(__FreeBSD__) && __FreeBSD__ < 13
+    if (vendorID != 0x8086)
+        return MFX_ERR_UNSUPPORTED;
+#else
     std::string vendorPath = "/sys/class/drm/renderD" + nodeStr + "/device/vendor";
     std::string devPath    = "/sys/class/drm/renderD" + nodeStr + "/device/device";
 
@@ -481,6 +529,7 @@ mfxStatus LoaderCtxMSDK::GetRenderNodeDescription(mfxU
             deviceID = (mfxU32)u32;
         fclose(devFile);
     }
+#endif
 
     if (deviceID == 0)
         return MFX_ERR_UNSUPPORTED;