Line 0
Link Here
|
|
|
1 |
--- third_party/angle/src/gpu_info_util/SystemInfo_libpci.cpp.orig 2018-08-20 10:00:10.885543000 -0700 |
2 |
+++ third_party/angle/src/gpu_info_util/SystemInfo_libpci.cpp 2018-08-20 09:50:32.387980000 -0700 |
3 |
@@ -12,6 +12,11 @@ |
4 |
#include <pci/pci.h> |
5 |
#include <unistd.h> |
6 |
|
7 |
+#if defined(__FreeBSD__) |
8 |
+#include <fcntl.h> |
9 |
+#include <sys/pciio.h> |
10 |
+#endif |
11 |
+ |
12 |
#include "common/angleutils.h" |
13 |
#include "common/debug.h" |
14 |
|
15 |
@@ -82,6 +87,75 @@ |
16 |
}; |
17 |
|
18 |
} // anonymous namespace |
19 |
+ |
20 |
+#if defined(__FreeBSD__) |
21 |
+// Adds an entry per PCI GPU found and fills the device and vendor ID. |
22 |
+bool GetPCIDevicesFreeBSD(std::vector<GPUDeviceInfo> *devices) |
23 |
+{ |
24 |
+ int fd; |
25 |
+ struct pci_conf_io conf; |
26 |
+ struct pci_conf *matches; |
27 |
+ uint32_t offset = 0; |
28 |
+ |
29 |
+ fd = open("/dev/pci", O_RDONLY); |
30 |
+ if (fd < 0) |
31 |
+ return false; |
32 |
+ |
33 |
+ matches = new struct pci_conf[32]; |
34 |
+ conf.generation = 0; |
35 |
+ do { |
36 |
+ conf.pat_buf_len = 0; |
37 |
+ conf.num_patterns = 0; |
38 |
+ conf.patterns = NULL; |
39 |
+ conf.match_buf_len = 32 * sizeof(struct pci_conf); |
40 |
+ conf.num_matches = 32; |
41 |
+ conf.matches = matches; |
42 |
+ conf.offset = offset; |
43 |
+ conf.status = PCI_GETCONF_ERROR; |
44 |
+ if (ioctl(fd, PCIOCGETCONF, &conf) < 0) { |
45 |
+ if (errno == ENODEV) |
46 |
+ break; |
47 |
+ } |
48 |
+ /* PCI_GETCONF_LIST_CHANGED would require us to start over. */ |
49 |
+ if (conf.status == PCI_GETCONF_ERROR || conf.status == PCI_GETCONF_LIST_CHANGED) { |
50 |
+ break; |
51 |
+ } |
52 |
+ |
53 |
+ for (unsigned int i = 0; i < conf.num_matches; i++) { |
54 |
+ uint16_t device_class = (matches[i].pc_class << 8) | matches[i].pc_subclass; |
55 |
+ |
56 |
+ // Skip non-GPU devices |
57 |
+ switch (device_class) |
58 |
+ { |
59 |
+ case PCI_CLASS_DISPLAY_VGA: |
60 |
+ case PCI_CLASS_DISPLAY_XGA: |
61 |
+ case PCI_CLASS_DISPLAY_3D: |
62 |
+ break; |
63 |
+ default: |
64 |
+ continue; |
65 |
+ } |
66 |
+ |
67 |
+ // Skip unknown devices |
68 |
+ if (matches[i].pc_vendor == 0 || matches[i].pc_device == 0) { |
69 |
+ continue; |
70 |
+ } |
71 |
+ |
72 |
+ GPUDeviceInfo info; |
73 |
+ info.vendorId = matches[i].pc_vendor; |
74 |
+ info.deviceId = matches[i].pc_device; |
75 |
+ |
76 |
+ devices->push_back(info); |
77 |
+ } |
78 |
+ offset += conf.num_matches; |
79 |
+ } while (conf.status == PCI_GETCONF_MORE_DEVS); |
80 |
+ |
81 |
+ delete[] matches; |
82 |
+ |
83 |
+ close(fd); |
84 |
+ |
85 |
+ return true; |
86 |
+} |
87 |
+#endif |
88 |
|
89 |
// Adds an entry per PCI GPU found and fills the device and vendor ID. |
90 |
bool GetPCIDevicesWithLibPCI(std::vector<GPUDeviceInfo> *devices) |