1 #ifndef DRM_HELPER_H
2 #define DRM_HELPER_H
3
4 #include <stdio.h>
5 #include "target-helpers/inline_debug_helper.h"
6 #include "target-helpers/drm_helper_public.h"
7 #include "frontend/drm_driver.h"
8 #include "util/driconf.h"
9
10 /**
11 * Instantiate a drm_driver_descriptor struct.
12 */
13 #define DEFINE_DRM_DRIVER_DESCRIPTOR(descriptor_name, driver, _driconf, _driconf_count, func) \
14 const struct drm_driver_descriptor descriptor_name = { \
15 .driver_name = #driver, \
16 .driconf = _driconf, \
17 .driconf_count = _driconf_count, \
18 .create_screen = func, \
19 };
20
21 /* The static pipe loader refers to the *_driver_descriptor structs for all
22 * drivers, regardless of whether they are configured in this Mesa build, or
23 * whether they're included in the specific gallium target. The target (dri,
24 * vdpau, etc.) will include this header with the #defines for the specific
25 * drivers it's including, and the disabled drivers will have a descriptor
26 * with a stub create function logging the failure.
27 *
28 * The dynamic pipe loader instead has target/pipeloader/pipe_*.c including
29 * this header in a pipe_*.so for each driver which will have one driver's
30 * GALLIUM_* defined. We make a single driver_descriptor entrypoint that is
31 * dlsym()ed by the dynamic pipe loader.
32 */
33
34 #ifdef PIPE_LOADER_DYNAMIC
35
36 #define DRM_DRIVER_DESCRIPTOR(driver, driconf, driconf_count) \
37 PUBLIC DEFINE_DRM_DRIVER_DESCRIPTOR(driver_descriptor, driver, driconf, driconf_count, pipe_##driver##_create_screen)
38
39 #define DRM_DRIVER_DESCRIPTOR_STUB(driver)
40
41 #define DRM_DRIVER_DESCRIPTOR_ALIAS(driver, alias, driconf, driconf_count)
42
43 #else
44
45 #define DRM_DRIVER_DESCRIPTOR(driver, driconf, driconf_count) \
46 DEFINE_DRM_DRIVER_DESCRIPTOR(driver##_driver_descriptor, driver, driconf, driconf_count, pipe_##driver##_create_screen)
47
48 #define DRM_DRIVER_DESCRIPTOR_STUB(driver) \
49 static struct pipe_screen * \
50 pipe_##driver##_create_screen(int fd, const struct pipe_screen_config *config) \
51 { \
52 fprintf(stderr, #driver ": driver missing\n"); \
53 return NULL; \
54 } \
55 DRM_DRIVER_DESCRIPTOR(driver, NULL, 0)
56
57 #define DRM_DRIVER_DESCRIPTOR_ALIAS(driver, alias, driconf, driconf_count) \
58 DEFINE_DRM_DRIVER_DESCRIPTOR(alias##_driver_descriptor, alias, driconf, \
59 driconf_count, pipe_##driver##_create_screen)
60
61 #endif
62
63 #ifdef GALLIUM_I915
64 #include "i915/drm/i915_drm_public.h"
65 #include "i915/i915_public.h"
66
67 static struct pipe_screen *
pipe_i915_create_screen(int fd,const struct pipe_screen_config * config)68 pipe_i915_create_screen(int fd, const struct pipe_screen_config *config)
69 {
70 struct i915_winsys *iws;
71 struct pipe_screen *screen;
72
73 iws = i915_drm_winsys_create(fd);
74 if (!iws)
75 return NULL;
76
77 screen = i915_screen_create(iws);
78 return screen ? debug_screen_wrap(screen) : NULL;
79 }
80 DRM_DRIVER_DESCRIPTOR(i915, NULL, 0)
81 #else
82 DRM_DRIVER_DESCRIPTOR_STUB(i915)
83 #endif
84
85 #ifdef GALLIUM_IRIS
86 #include "iris/drm/iris_drm_public.h"
87
88 static struct pipe_screen *
pipe_iris_create_screen(int fd,const struct pipe_screen_config * config)89 pipe_iris_create_screen(int fd, const struct pipe_screen_config *config)
90 {
91 struct pipe_screen *screen;
92
93 screen = iris_drm_screen_create(fd, config);
94 return screen ? debug_screen_wrap(screen) : NULL;
95 }
96
97 const driOptionDescription iris_driconf[] = {
98 #include "iris/driinfo_iris.h"
99 };
DRM_DRIVER_DESCRIPTOR(iris,iris_driconf,ARRAY_SIZE (iris_driconf))100 DRM_DRIVER_DESCRIPTOR(iris, iris_driconf, ARRAY_SIZE(iris_driconf))
101
102 #else
103 DRM_DRIVER_DESCRIPTOR_STUB(iris)
104 #endif
105
106 #ifdef GALLIUM_NOUVEAU
107 #include "nouveau/drm/nouveau_drm_public.h"
108
109 static struct pipe_screen *
110 pipe_nouveau_create_screen(int fd, const struct pipe_screen_config *config)
111 {
112 struct pipe_screen *screen;
113
114 screen = nouveau_drm_screen_create(fd);
115 return screen ? debug_screen_wrap(screen) : NULL;
116 }
117 DRM_DRIVER_DESCRIPTOR(nouveau, NULL, 0)
118
119 #else
120 DRM_DRIVER_DESCRIPTOR_STUB(nouveau)
121 #endif
122
123 #if defined(GALLIUM_VC4) || defined(GALLIUM_V3D)
124 const driOptionDescription v3d_driconf[] = {
125 #include "v3d/driinfo_v3d.h"
126 };
127 #endif
128
129 #ifdef GALLIUM_KMSRO
130 #include "kmsro/drm/kmsro_drm_public.h"
131
132 static struct pipe_screen *
pipe_kmsro_create_screen(int fd,const struct pipe_screen_config * config)133 pipe_kmsro_create_screen(int fd, const struct pipe_screen_config *config)
134 {
135 struct pipe_screen *screen;
136
137 screen = kmsro_drm_screen_create(fd, config);
138 return screen ? debug_screen_wrap(screen) : NULL;
139 }
140 #if defined(GALLIUM_VC4) || defined(GALLIUM_V3D)
DRM_DRIVER_DESCRIPTOR(kmsro,v3d_driconf,ARRAY_SIZE (v3d_driconf))141 DRM_DRIVER_DESCRIPTOR(kmsro, v3d_driconf, ARRAY_SIZE(v3d_driconf))
142 #else
143 DRM_DRIVER_DESCRIPTOR(kmsro, NULL, 0)
144 #endif
145
146 #else
147 DRM_DRIVER_DESCRIPTOR_STUB(kmsro)
148 #endif
149
150 #ifdef GALLIUM_R300
151 #include "radeon/radeon_winsys.h"
152 #include "radeon/drm/radeon_drm_public.h"
153 #include "r300/r300_public.h"
154
155 static struct pipe_screen *
156 pipe_r300_create_screen(int fd, const struct pipe_screen_config *config)
157 {
158 struct radeon_winsys *rw;
159
160 rw = radeon_drm_winsys_create(fd, config, r300_screen_create);
161 return rw ? debug_screen_wrap(rw->screen) : NULL;
162 }
163 DRM_DRIVER_DESCRIPTOR(r300, NULL, 0)
164
165 #else
166 DRM_DRIVER_DESCRIPTOR_STUB(r300)
167 #endif
168
169 #ifdef GALLIUM_R600
170 #include "radeon/radeon_winsys.h"
171 #include "radeon/drm/radeon_drm_public.h"
172 #include "r600/r600_public.h"
173
174 static struct pipe_screen *
pipe_r600_create_screen(int fd,const struct pipe_screen_config * config)175 pipe_r600_create_screen(int fd, const struct pipe_screen_config *config)
176 {
177 struct radeon_winsys *rw;
178
179 rw = radeon_drm_winsys_create(fd, config, r600_screen_create);
180 return rw ? debug_screen_wrap(rw->screen) : NULL;
181 }
182 DRM_DRIVER_DESCRIPTOR(r600, NULL, 0)
183
184 #else
185 DRM_DRIVER_DESCRIPTOR_STUB(r600)
186 #endif
187
188 #ifdef GALLIUM_RADEONSI
189 #include "radeonsi/si_public.h"
190
191 static struct pipe_screen *
pipe_radeonsi_create_screen(int fd,const struct pipe_screen_config * config)192 pipe_radeonsi_create_screen(int fd, const struct pipe_screen_config *config)
193 {
194 struct pipe_screen *screen = radeonsi_screen_create(fd, config);
195
196 return screen ? debug_screen_wrap(screen) : NULL;
197 }
198
199 const driOptionDescription radeonsi_driconf[] = {
200 #include "radeonsi/driinfo_radeonsi.h"
201 };
DRM_DRIVER_DESCRIPTOR(radeonsi,radeonsi_driconf,ARRAY_SIZE (radeonsi_driconf))202 DRM_DRIVER_DESCRIPTOR(radeonsi, radeonsi_driconf, ARRAY_SIZE(radeonsi_driconf))
203
204 #else
205 DRM_DRIVER_DESCRIPTOR_STUB(radeonsi)
206 #endif
207
208 #ifdef GALLIUM_VMWGFX
209 #include "svga/drm/svga_drm_public.h"
210 #include "svga/svga_public.h"
211
212 static struct pipe_screen *
213 pipe_vmwgfx_create_screen(int fd, const struct pipe_screen_config *config)
214 {
215 struct svga_winsys_screen *sws;
216 struct pipe_screen *screen;
217
218 sws = svga_drm_winsys_screen_create(fd);
219 if (!sws)
220 return NULL;
221
222 screen = svga_screen_create(sws);
223 return screen ? debug_screen_wrap(screen) : NULL;
224 }
225 DRM_DRIVER_DESCRIPTOR(vmwgfx, NULL, 0)
226
227 #else
228 DRM_DRIVER_DESCRIPTOR_STUB(vmwgfx)
229 #endif
230
231 #ifdef GALLIUM_FREEDRENO
232 #include "freedreno/drm/freedreno_drm_public.h"
233
234 static struct pipe_screen *
pipe_msm_create_screen(int fd,const struct pipe_screen_config * config)235 pipe_msm_create_screen(int fd, const struct pipe_screen_config *config)
236 {
237 struct pipe_screen *screen;
238
239 screen = fd_drm_screen_create(fd, NULL);
240 return screen ? debug_screen_wrap(screen) : NULL;
241 }
242 DRM_DRIVER_DESCRIPTOR(msm, NULL, 0)
243 #else
244 DRM_DRIVER_DESCRIPTOR_STUB(msm)
245 #endif
246 DRM_DRIVER_DESCRIPTOR_ALIAS(msm, kgsl, NULL, 0)
247
248 #ifdef GALLIUM_VIRGL
249 #include "virgl/drm/virgl_drm_public.h"
250 #include "virgl/virgl_public.h"
251
252 static struct pipe_screen *
pipe_virtio_gpu_create_screen(int fd,const struct pipe_screen_config * config)253 pipe_virtio_gpu_create_screen(int fd, const struct pipe_screen_config *config)
254 {
255 struct pipe_screen *screen;
256
257 screen = virgl_drm_screen_create(fd, config);
258 return screen ? debug_screen_wrap(screen) : NULL;
259 }
260
261 const driOptionDescription virgl_driconf[] = {
262 #include "virgl/virgl_driinfo.h.in"
263 };
DRM_DRIVER_DESCRIPTOR(virtio_gpu,virgl_driconf,ARRAY_SIZE (virgl_driconf))264 DRM_DRIVER_DESCRIPTOR(virtio_gpu, virgl_driconf, ARRAY_SIZE(virgl_driconf))
265
266 #else
267 DRM_DRIVER_DESCRIPTOR_STUB(virtio_gpu)
268 #endif
269
270 #ifdef GALLIUM_VC4
271 #include "vc4/drm/vc4_drm_public.h"
272
273 static struct pipe_screen *
274 pipe_vc4_create_screen(int fd, const struct pipe_screen_config *config)
275 {
276 struct pipe_screen *screen;
277
278 screen = vc4_drm_screen_create(fd, config);
279 return screen ? debug_screen_wrap(screen) : NULL;
280 }
DRM_DRIVER_DESCRIPTOR(vc4,v3d_driconf,ARRAY_SIZE (v3d_driconf))281 DRM_DRIVER_DESCRIPTOR(vc4, v3d_driconf, ARRAY_SIZE(v3d_driconf))
282 #else
283 DRM_DRIVER_DESCRIPTOR_STUB(vc4)
284 #endif
285
286 #ifdef GALLIUM_V3D
287 #include "v3d/drm/v3d_drm_public.h"
288
289 static struct pipe_screen *
290 pipe_v3d_create_screen(int fd, const struct pipe_screen_config *config)
291 {
292 struct pipe_screen *screen;
293
294 screen = v3d_drm_screen_create(fd, config);
295 return screen ? debug_screen_wrap(screen) : NULL;
296 }
297
DRM_DRIVER_DESCRIPTOR(v3d,v3d_driconf,ARRAY_SIZE (v3d_driconf))298 DRM_DRIVER_DESCRIPTOR(v3d, v3d_driconf, ARRAY_SIZE(v3d_driconf))
299
300 #else
301 DRM_DRIVER_DESCRIPTOR_STUB(v3d)
302 #endif
303
304 #ifdef GALLIUM_PANFROST
305 #include "panfrost/drm/panfrost_drm_public.h"
306
307 static struct pipe_screen *
308 pipe_panfrost_create_screen(int fd, const struct pipe_screen_config *config)
309 {
310 struct pipe_screen *screen;
311
312 screen = panfrost_drm_screen_create(fd);
313 return screen ? debug_screen_wrap(screen) : NULL;
314 }
315 DRM_DRIVER_DESCRIPTOR(panfrost, NULL, 0)
316
317 #else
318 DRM_DRIVER_DESCRIPTOR_STUB(panfrost)
319 #endif
320
321 #ifdef GALLIUM_ETNAVIV
322 #include "etnaviv/drm/etnaviv_drm_public.h"
323
324 static struct pipe_screen *
pipe_etnaviv_create_screen(int fd,const struct pipe_screen_config * config)325 pipe_etnaviv_create_screen(int fd, const struct pipe_screen_config *config)
326 {
327 struct pipe_screen *screen;
328
329 screen = etna_drm_screen_create(fd);
330 return screen ? debug_screen_wrap(screen) : NULL;
331 }
332 DRM_DRIVER_DESCRIPTOR(etnaviv, NULL, 0)
333
334 #else
335 DRM_DRIVER_DESCRIPTOR_STUB(etnaviv)
336 #endif
337
338 #ifdef GALLIUM_TEGRA
339 #include "tegra/drm/tegra_drm_public.h"
340
341 static struct pipe_screen *
pipe_tegra_create_screen(int fd,const struct pipe_screen_config * config)342 pipe_tegra_create_screen(int fd, const struct pipe_screen_config *config)
343 {
344 struct pipe_screen *screen;
345
346 screen = tegra_drm_screen_create(fd);
347
348 return screen ? debug_screen_wrap(screen) : NULL;
349 }
350 DRM_DRIVER_DESCRIPTOR(tegra, NULL, 0)
351
352 #else
353 DRM_DRIVER_DESCRIPTOR_STUB(tegra)
354 #endif
355
356 #ifdef GALLIUM_LIMA
357 #include "lima/drm/lima_drm_public.h"
358
359 static struct pipe_screen *
pipe_lima_create_screen(int fd,const struct pipe_screen_config * config)360 pipe_lima_create_screen(int fd, const struct pipe_screen_config *config)
361 {
362 struct pipe_screen *screen;
363
364 screen = lima_drm_screen_create(fd);
365 return screen ? debug_screen_wrap(screen) : NULL;
366 }
367 DRM_DRIVER_DESCRIPTOR(lima, NULL, 0)
368
369 #else
370 DRM_DRIVER_DESCRIPTOR_STUB(lima)
371 #endif
372
373 #ifdef GALLIUM_ZINK
374 #include "zink/zink_public.h"
375
376 static struct pipe_screen *
pipe_zink_create_screen(int fd,const struct pipe_screen_config * config)377 pipe_zink_create_screen(int fd, const struct pipe_screen_config *config)
378 {
379 struct pipe_screen *screen;
380 screen = zink_drm_create_screen(fd, config);
381 return screen ? debug_screen_wrap(screen) : NULL;
382 }
383
384 const driOptionDescription zink_driconf[] = {
385 #include "zink/driinfo_zink.h"
386 };
387 DRM_DRIVER_DESCRIPTOR(zink, zink_driconf, ARRAY_SIZE(zink_driconf))
388
389 #else
390 DRM_DRIVER_DESCRIPTOR_STUB(zink)
391 #endif
392
393 #endif /* DRM_HELPER_H */
394