Line 0
Link Here
|
|
|
1 |
--- xf86drm.c.orig 2016-07-24 20:50:03.999898000 +0200 |
2 |
+++ xf86drm.c 2016-07-24 20:53:31.587058000 +0200 |
3 |
@@ -62,6 +62,10 @@ |
4 |
#endif |
5 |
#include <math.h> |
6 |
|
7 |
+#ifdef HAVE_LIBDEVQ |
8 |
+#include "libdevq.h" |
9 |
+#endif |
10 |
+ |
11 |
/* Not all systems have MAP_FAILED defined */ |
12 |
#ifndef MAP_FAILED |
13 |
#define MAP_FAILED ((void *)-1) |
14 |
@@ -82,8 +86,12 @@ |
15 |
#define DRM_RENDER_MINOR_NAME "renderD" |
16 |
#endif |
17 |
|
18 |
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) |
19 |
-#define DRM_MAJOR 145 |
20 |
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) |
21 |
+#define DRM_MAJOR 0 |
22 |
+#endif |
23 |
+ |
24 |
+#if defined(__DragonFly__) |
25 |
+#define DRM_MAJOR 65 /* was 154 XXX needs checking */ |
26 |
#endif |
27 |
|
28 |
#ifdef __NetBSD__ |
29 |
@@ -532,6 +540,7 @@ static int drmGetMinorType(int minor) |
30 |
} |
31 |
} |
32 |
|
33 |
+#if !defined(__FreeBSD__) && !defined(__DragonFly__) |
34 |
static const char *drmGetMinorName(int type) |
35 |
{ |
36 |
switch (type) { |
37 |
@@ -545,6 +554,7 @@ static const char *drmGetMinorName(int t |
38 |
return NULL; |
39 |
} |
40 |
} |
41 |
+#endif |
42 |
|
43 |
/** |
44 |
* Open the device by bus ID. |
45 |
@@ -2817,6 +2827,15 @@ static char *drmGetMinorNameForFD(int fd |
46 |
|
47 |
out_close_dir: |
48 |
closedir(sysdir); |
49 |
+#elif defined(__FreeBSD__) || defined(__DragonFly__) |
50 |
+ struct stat buf; |
51 |
+ char name[64]; |
52 |
+ |
53 |
+ fstat(fd, &buf); |
54 |
+ snprintf(name, sizeof(name), "/dev/%s", |
55 |
+ devname(buf.st_rdev, S_IFCHR)); |
56 |
+ |
57 |
+ return strdup(name); |
58 |
#else |
59 |
#warning "Missing implementation of drmGetMinorNameForFD" |
60 |
#endif |
61 |
@@ -2854,12 +2873,19 @@ static int drmParseSubsystemType(int maj |
62 |
return DRM_BUS_PCI; |
63 |
|
64 |
return -EINVAL; |
65 |
+#elif defined(__FreeBSD__) || defined(__DragonFly__) |
66 |
+ /* XXX: Don't know how to get the subsystem type, hardcode for now. |
67 |
+ * The code following the call to this function needs depends on |
68 |
+ * information provided by the /pci subsystem on linux. No replacement |
69 |
+ * found yet for FreeBSD. */ |
70 |
+ return DRM_BUS_PCI; |
71 |
#else |
72 |
#warning "Missing implementation of drmParseSubsystemType" |
73 |
return -EINVAL; |
74 |
#endif |
75 |
} |
76 |
|
77 |
+#if !defined(__FreeBSD__) && !defined(__DragonFly__) |
78 |
static int drmParsePciBusInfo(int maj, int min, drmPciBusInfoPtr info) |
79 |
{ |
80 |
#ifdef __linux__ |
81 |
@@ -2901,6 +2927,66 @@ static int drmParsePciBusInfo(int maj, i |
82 |
return -EINVAL; |
83 |
#endif |
84 |
} |
85 |
+#else |
86 |
+ |
87 |
+/* |
88 |
+ * XXX temporary workaround, because FreeBSD doesn't provide |
89 |
+ * pcibus device sysctl trees for renderD and controlD nodes (yet) |
90 |
+ */ |
91 |
+static char * |
92 |
+drmBSDDeviceNameHack(const char *path) |
93 |
+{ |
94 |
+ int start; |
95 |
+ const char *errstr; |
96 |
+ int number; |
97 |
+ char hacked_path[PATH_MAX + 1]; |
98 |
+ |
99 |
+ if (strcmp(path, DRM_DIR_NAME "/controlD") > 0) |
100 |
+ { |
101 |
+ start = 17; |
102 |
+ number = strtonum(&path[start], 0, 256, &errstr) - 64; |
103 |
+ snprintf(hacked_path, PATH_MAX, DRM_DIR_NAME "/card%i", number); |
104 |
+ }else if (strcmp(path, DRM_DIR_NAME "/renderD") > 0) |
105 |
+ { |
106 |
+ start = 16; |
107 |
+ number = strtonum(&path[start], 0, 256, &errstr) - 128; |
108 |
+ snprintf(hacked_path, PATH_MAX, DRM_DIR_NAME "/card%i", number); |
109 |
+ }else |
110 |
+ snprintf(hacked_path, PATH_MAX, "%s", path); |
111 |
+ |
112 |
+ return hacked_path; |
113 |
+} |
114 |
+ |
115 |
+static int |
116 |
+drmParsePciBusInfoBSD(const char *path, drmPciBusInfoPtr info) |
117 |
+{ |
118 |
+ int fd, ret; |
119 |
+ int domain = 0, bus = 0, slot = 0, function = 0; |
120 |
+ |
121 |
+ char hacked_path[PATH_MAX + 1]; |
122 |
+ |
123 |
+ snprintf(hacked_path, PATH_MAX, "%s", drmBSDDeviceNameHack(path)); |
124 |
+ |
125 |
+ fd = open(hacked_path, O_RDONLY); |
126 |
+ |
127 |
+ if (fd < 0) |
128 |
+ return -errno; |
129 |
+ |
130 |
+ ret = devq_device_get_pcibusaddr(fd, &domain, &bus, &slot, &function); |
131 |
+ |
132 |
+ if (ret < 0) |
133 |
+ return -1; |
134 |
+ |
135 |
+ info->domain = (uint16_t) domain; |
136 |
+ info->bus = (uint8_t) bus; |
137 |
+ info->dev = (uint8_t) slot; |
138 |
+ info->func = (uint8_t) function; |
139 |
+ |
140 |
+ close(fd); |
141 |
+ |
142 |
+ return 0; |
143 |
+} |
144 |
+#endif |
145 |
|
146 |
static int drmCompareBusInfo(drmDevicePtr a, drmDevicePtr b) |
147 |
{ |
148 |
@@ -2971,6 +3057,32 @@ static int drmParsePciDeviceInfo(const c |
149 |
device->subdevice_id = config[46] | (config[47] << 8); |
150 |
|
151 |
return 0; |
152 |
+#elif defined(__FreeBSD__) || defined(__DragonFly__) |
153 |
+ |
154 |
+ int fd, vendor_id = 0, device_id = 0, subvendor_id = 0, |
155 |
+ subdevice_id = 0, revision_id = 0; |
156 |
+ char path[PATH_MAX + 1]; |
157 |
+ char hacked_path[PATH_MAX + 1]; |
158 |
+ |
159 |
+ snprintf(path, PATH_MAX, DRM_DIR_NAME "/%s", d_name); |
160 |
+ |
161 |
+ snprintf(hacked_path, PATH_MAX, "%s", drmBSDDeviceNameHack(path)); |
162 |
+ |
163 |
+ fd = open(hacked_path, O_RDONLY); |
164 |
+ |
165 |
+ if (fd < 0) |
166 |
+ return -errno; |
167 |
+ |
168 |
+ devq_device_get_pciid_full_from_fd(fd, &vendor_id, &device_id, |
169 |
+ &subvendor_id, &subdevice_id, &revision_id); |
170 |
+ |
171 |
+ device->vendor_id = (uint16_t) vendor_id; |
172 |
+ device->device_id = (uint16_t) device_id; |
173 |
+ device->subvendor_id = (uint16_t) subvendor_id; |
174 |
+ device->subdevice_id = (uint16_t) subdevice_id; |
175 |
+ device->revision_id = (uint8_t) revision_id; |
176 |
+ |
177 |
+ return 0; |
178 |
#else |
179 |
#warning "Missing implementation of drmParsePciDeviceInfo" |
180 |
return -EINVAL; |
181 |
@@ -3029,7 +3141,12 @@ static int drmProcessPciDevice(drmDevice |
182 |
|
183 |
(*device)->businfo.pci = (drmPciBusInfoPtr)addr; |
184 |
|
185 |
+#if defined(__FreeBSD__) || defined(__DragonFly__) |
186 |
+ ret = drmParsePciBusInfoBSD(node, (*device)->businfo.pci); |
187 |
+#else |
188 |
ret = drmParsePciBusInfo(maj, min, (*device)->businfo.pci); |
189 |
+#endif |
190 |
+ |
191 |
if (ret) |
192 |
goto free_device; |
193 |
|