• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_KMSRO_ONLY
64 #undef GALLIUM_V3D
65 #undef GALLIUM_VC4
66 #undef GALLIUM_FREEDRENO
67 #undef GALLIUM_ETNAVIV
68 #undef GALLIUM_PANFROST
69 #undef GALLIUM_LIMA
70 #undef GALLIUM_ASAHI
71 #endif
72 
73 #ifdef GALLIUM_I915
74 #include "i915/drm/i915_drm_public.h"
75 #include "i915/i915_public.h"
76 
77 static struct pipe_screen *
pipe_i915_create_screen(int fd,const struct pipe_screen_config * config)78 pipe_i915_create_screen(int fd, const struct pipe_screen_config *config)
79 {
80    struct i915_winsys *iws;
81    struct pipe_screen *screen;
82 
83    iws = i915_drm_winsys_create(fd);
84    if (!iws)
85       return NULL;
86 
87    screen = i915_screen_create(iws);
88    return screen ? debug_screen_wrap(screen) : NULL;
89 }
90 DRM_DRIVER_DESCRIPTOR(i915, NULL, 0)
91 #else
92 DRM_DRIVER_DESCRIPTOR_STUB(i915)
93 #endif
94 
95 #ifdef GALLIUM_IRIS
96 #include "iris/drm/iris_drm_public.h"
97 
98 static struct pipe_screen *
pipe_iris_create_screen(int fd,const struct pipe_screen_config * config)99 pipe_iris_create_screen(int fd, const struct pipe_screen_config *config)
100 {
101    struct pipe_screen *screen;
102 
103    screen = iris_drm_screen_create(fd, config);
104    return screen ? debug_screen_wrap(screen) : NULL;
105 }
106 
107 const driOptionDescription iris_driconf[] = {
108       #include "iris/driinfo_iris.h"
109 };
DRM_DRIVER_DESCRIPTOR(iris,iris_driconf,ARRAY_SIZE (iris_driconf))110 DRM_DRIVER_DESCRIPTOR(iris, iris_driconf, ARRAY_SIZE(iris_driconf))
111 
112 #else
113 DRM_DRIVER_DESCRIPTOR_STUB(iris)
114 #endif
115 
116 #ifdef GALLIUM_CROCUS
117 #include "crocus/drm/crocus_drm_public.h"
118 
119 static struct pipe_screen *
120 pipe_crocus_create_screen(int fd, const struct pipe_screen_config *config)
121 {
122    struct pipe_screen *screen;
123 
124    screen = crocus_drm_screen_create(fd, config);
125    return screen ? debug_screen_wrap(screen) : NULL;
126 }
127 
128 const driOptionDescription crocus_driconf[] = {
129       #include "crocus/driinfo_crocus.h"
130 };
DRM_DRIVER_DESCRIPTOR(crocus,crocus_driconf,ARRAY_SIZE (crocus_driconf))131 DRM_DRIVER_DESCRIPTOR(crocus, crocus_driconf, ARRAY_SIZE(crocus_driconf))
132 #else
133 DRM_DRIVER_DESCRIPTOR_STUB(crocus)
134 #endif
135 
136 #ifdef GALLIUM_NOUVEAU
137 #include "nouveau/drm/nouveau_drm_public.h"
138 
139 static struct pipe_screen *
140 pipe_nouveau_create_screen(int fd, const struct pipe_screen_config *config)
141 {
142    struct pipe_screen *screen;
143 
144    screen = nouveau_drm_screen_create(fd);
145    return screen ? debug_screen_wrap(screen) : NULL;
146 }
147 DRM_DRIVER_DESCRIPTOR(nouveau, NULL, 0)
148 
149 #else
150 DRM_DRIVER_DESCRIPTOR_STUB(nouveau)
151 #endif
152 
153 #if defined(GALLIUM_VC4) || defined(GALLIUM_V3D)
154 const driOptionDescription v3d_driconf[] = {
155       #include "v3d/driinfo_v3d.h"
156 };
157 #endif
158 
159 #ifdef GALLIUM_R300
160 #include "winsys/radeon_winsys.h"
161 #include "r300/r300_public.h"
162 
163 static struct pipe_screen *
pipe_r300_create_screen(int fd,const struct pipe_screen_config * config)164 pipe_r300_create_screen(int fd, const struct pipe_screen_config *config)
165 {
166    struct radeon_winsys *rw;
167 
168    rw = radeon_drm_winsys_create(fd, config, r300_screen_create);
169    return rw ? debug_screen_wrap(rw->screen) : NULL;
170 }
171 DRM_DRIVER_DESCRIPTOR(r300, NULL, 0)
172 
173 #else
174 DRM_DRIVER_DESCRIPTOR_STUB(r300)
175 #endif
176 
177 #ifdef GALLIUM_R600
178 #include "winsys/radeon_winsys.h"
179 #include "r600/r600_public.h"
180 
181 static struct pipe_screen *
pipe_r600_create_screen(int fd,const struct pipe_screen_config * config)182 pipe_r600_create_screen(int fd, const struct pipe_screen_config *config)
183 {
184    struct radeon_winsys *rw;
185 
186    rw = radeon_drm_winsys_create(fd, config, r600_screen_create);
187    return rw ? debug_screen_wrap(rw->screen) : NULL;
188 }
189 DRM_DRIVER_DESCRIPTOR(r600, NULL, 0)
190 
191 #else
192 DRM_DRIVER_DESCRIPTOR_STUB(r600)
193 #endif
194 
195 #ifdef GALLIUM_RADEONSI
196 #include "radeonsi/si_public.h"
197 
198 static struct pipe_screen *
pipe_radeonsi_create_screen(int fd,const struct pipe_screen_config * config)199 pipe_radeonsi_create_screen(int fd, const struct pipe_screen_config *config)
200 {
201    struct pipe_screen *screen = radeonsi_screen_create(fd, config);
202 
203    return screen ? debug_screen_wrap(screen) : NULL;
204 }
205 
206 const driOptionDescription radeonsi_driconf[] = {
207       #include "radeonsi/driinfo_radeonsi.h"
208 };
DRM_DRIVER_DESCRIPTOR(radeonsi,radeonsi_driconf,ARRAY_SIZE (radeonsi_driconf))209 DRM_DRIVER_DESCRIPTOR(radeonsi, radeonsi_driconf, ARRAY_SIZE(radeonsi_driconf))
210 
211 #else
212 DRM_DRIVER_DESCRIPTOR_STUB(radeonsi)
213 #endif
214 
215 #ifdef GALLIUM_VMWGFX
216 #include "svga/drm/svga_drm_public.h"
217 #include "svga/svga_public.h"
218 
219 static struct pipe_screen *
220 pipe_vmwgfx_create_screen(int fd, const struct pipe_screen_config *config)
221 {
222    struct svga_winsys_screen *sws;
223    struct pipe_screen *screen;
224 
225    sws = svga_drm_winsys_screen_create(fd);
226    if (!sws)
227       return NULL;
228 
229    screen = svga_screen_create(sws);
230    return screen ? debug_screen_wrap(screen) : NULL;
231 }
232 DRM_DRIVER_DESCRIPTOR(vmwgfx, NULL, 0)
233 
234 #else
235 DRM_DRIVER_DESCRIPTOR_STUB(vmwgfx)
236 #endif
237 
238 #ifdef GALLIUM_FREEDRENO
239 #include "freedreno/drm/freedreno_drm_public.h"
240 
241 static struct pipe_screen *
pipe_msm_create_screen(int fd,const struct pipe_screen_config * config)242 pipe_msm_create_screen(int fd, const struct pipe_screen_config *config)
243 {
244    struct pipe_screen *screen;
245 
246    screen = fd_drm_screen_create_renderonly(fd, NULL, config);
247    return screen ? debug_screen_wrap(screen) : NULL;
248 }
249 
250 const driOptionDescription msm_driconf[] = {
251 #ifdef GALLIUM_FREEDRENO
252       #include "freedreno/driinfo_freedreno.h"
253 #endif
254 };
DRM_DRIVER_DESCRIPTOR(msm,msm_driconf,ARRAY_SIZE (msm_driconf))255 DRM_DRIVER_DESCRIPTOR(msm, msm_driconf, ARRAY_SIZE(msm_driconf))
256 DRM_DRIVER_DESCRIPTOR_ALIAS(msm, kgsl, msm_driconf, ARRAY_SIZE(msm_driconf))
257 #else
258 DRM_DRIVER_DESCRIPTOR_STUB(msm)
259 DRM_DRIVER_DESCRIPTOR_STUB(kgsl)
260 #endif
261 
262 #if defined(GALLIUM_VIRGL) || (defined(GALLIUM_FREEDRENO) && !defined(PIPE_LOADER_DYNAMIC))
263 #include "virgl/drm/virgl_drm_public.h"
264 #include "virgl/virgl_public.h"
265 
266 static struct pipe_screen *
267 pipe_virtio_gpu_create_screen(int fd, const struct pipe_screen_config *config)
268 {
269    struct pipe_screen *screen = NULL;
270 
271    /* Try native guest driver(s) first, and then fallback to virgl: */
272 #ifdef GALLIUM_FREEDRENO
273    if (!screen)
274       screen = fd_drm_screen_create_renderonly(fd, NULL, config);
275 #endif
276 #ifdef GALLIUM_VIRGL
277    if (!screen)
278       screen = virgl_drm_screen_create(fd, config);
279 #endif
280    return screen ? debug_screen_wrap(screen) : NULL;
281 }
282 
283 const driOptionDescription virgl_driconf[] = {
284       #include "virgl/virgl_driinfo.h.in"
285 };
DRM_DRIVER_DESCRIPTOR(virtio_gpu,virgl_driconf,ARRAY_SIZE (virgl_driconf))286 DRM_DRIVER_DESCRIPTOR(virtio_gpu, virgl_driconf, ARRAY_SIZE(virgl_driconf))
287 
288 #else
289 DRM_DRIVER_DESCRIPTOR_STUB(virtio_gpu)
290 #endif
291 
292 #ifdef GALLIUM_VC4
293 #include "vc4/drm/vc4_drm_public.h"
294 
295 static struct pipe_screen *
296 pipe_vc4_create_screen(int fd, const struct pipe_screen_config *config)
297 {
298    struct pipe_screen *screen;
299 
300    screen = vc4_drm_screen_create(fd, config);
301    return screen ? debug_screen_wrap(screen) : NULL;
302 }
DRM_DRIVER_DESCRIPTOR(vc4,v3d_driconf,ARRAY_SIZE (v3d_driconf))303 DRM_DRIVER_DESCRIPTOR(vc4, v3d_driconf, ARRAY_SIZE(v3d_driconf))
304 #else
305 DRM_DRIVER_DESCRIPTOR_STUB(vc4)
306 #endif
307 
308 #ifdef GALLIUM_V3D
309 #include "v3d/drm/v3d_drm_public.h"
310 
311 static struct pipe_screen *
312 pipe_v3d_create_screen(int fd, const struct pipe_screen_config *config)
313 {
314    struct pipe_screen *screen;
315 
316    screen = v3d_drm_screen_create(fd, config);
317    return screen ? debug_screen_wrap(screen) : NULL;
318 }
319 
DRM_DRIVER_DESCRIPTOR(v3d,v3d_driconf,ARRAY_SIZE (v3d_driconf))320 DRM_DRIVER_DESCRIPTOR(v3d, v3d_driconf, ARRAY_SIZE(v3d_driconf))
321 
322 #else
323 DRM_DRIVER_DESCRIPTOR_STUB(v3d)
324 #endif
325 
326 #ifdef GALLIUM_PANFROST
327 #include "panfrost/drm/panfrost_drm_public.h"
328 
329 static struct pipe_screen *
330 pipe_panfrost_create_screen(int fd, const struct pipe_screen_config *config)
331 {
332    struct pipe_screen *screen;
333 
334    screen = panfrost_drm_screen_create(fd);
335    return screen ? debug_screen_wrap(screen) : NULL;
336 }
337 DRM_DRIVER_DESCRIPTOR(panfrost, NULL, 0)
338 
339 #else
340 DRM_DRIVER_DESCRIPTOR_STUB(panfrost)
341 #endif
342 
343 #ifdef GALLIUM_ASAHI
344 #include "asahi/drm/asahi_drm_public.h"
345 
346 static struct pipe_screen *
pipe_asahi_create_screen(int fd,const struct pipe_screen_config * config)347 pipe_asahi_create_screen(int fd, const struct pipe_screen_config *config)
348 {
349    struct pipe_screen *screen;
350 
351    screen = asahi_drm_screen_create(fd, config);
352    return screen ? debug_screen_wrap(screen) : NULL;
353 }
354 
355 const driOptionDescription asahi_driconf[] = {
356       #include "asahi/driinfo_asahi.h"
357 };
DRM_DRIVER_DESCRIPTOR(asahi,asahi_driconf,ARRAY_SIZE (asahi_driconf))358 DRM_DRIVER_DESCRIPTOR(asahi, asahi_driconf, ARRAY_SIZE(asahi_driconf))
359 
360 #else
361 DRM_DRIVER_DESCRIPTOR_STUB(asahi)
362 #endif
363 
364 #ifdef GALLIUM_ETNAVIV
365 #include "etnaviv/drm/etnaviv_drm_public.h"
366 
367 static struct pipe_screen *
368 pipe_etnaviv_create_screen(int fd, const struct pipe_screen_config *config)
369 {
370    struct pipe_screen *screen;
371 
372    screen = etna_drm_screen_create(fd);
373    return screen ? debug_screen_wrap(screen) : NULL;
374 }
375 DRM_DRIVER_DESCRIPTOR(etnaviv, NULL, 0)
376 
377 #else
378 DRM_DRIVER_DESCRIPTOR_STUB(etnaviv)
379 #endif
380 
381 #ifdef GALLIUM_TEGRA
382 #include "tegra/drm/tegra_drm_public.h"
383 
384 static struct pipe_screen *
pipe_tegra_create_screen(int fd,const struct pipe_screen_config * config)385 pipe_tegra_create_screen(int fd, const struct pipe_screen_config *config)
386 {
387    struct pipe_screen *screen;
388 
389    screen = tegra_drm_screen_create(fd);
390 
391    return screen ? debug_screen_wrap(screen) : NULL;
392 }
393 DRM_DRIVER_DESCRIPTOR(tegra, NULL, 0)
394 
395 #else
396 DRM_DRIVER_DESCRIPTOR_STUB(tegra)
397 #endif
398 
399 #ifdef GALLIUM_LIMA
400 #include "lima/drm/lima_drm_public.h"
401 
402 static struct pipe_screen *
pipe_lima_create_screen(int fd,const struct pipe_screen_config * config)403 pipe_lima_create_screen(int fd, const struct pipe_screen_config *config)
404 {
405    struct pipe_screen *screen;
406 
407    screen = lima_drm_screen_create(fd);
408    return screen ? debug_screen_wrap(screen) : NULL;
409 }
410 DRM_DRIVER_DESCRIPTOR(lima, NULL, 0)
411 
412 #else
413 DRM_DRIVER_DESCRIPTOR_STUB(lima)
414 #endif
415 
416 #ifdef GALLIUM_ZINK
417 #include "zink/zink_public.h"
418 
419 static struct pipe_screen *
pipe_zink_create_screen(int fd,const struct pipe_screen_config * config)420 pipe_zink_create_screen(int fd, const struct pipe_screen_config *config)
421 {
422    struct pipe_screen *screen;
423    screen = zink_drm_create_screen(fd, config);
424    return screen ? debug_screen_wrap(screen) : NULL;
425 }
426 
427 const driOptionDescription zink_driconf[] = {
428       #include "zink/driinfo_zink.h"
429 };
DRM_DRIVER_DESCRIPTOR(zink,zink_driconf,ARRAY_SIZE (zink_driconf))430 DRM_DRIVER_DESCRIPTOR(zink, zink_driconf, ARRAY_SIZE(zink_driconf))
431 
432 #else
433 DRM_DRIVER_DESCRIPTOR_STUB(zink)
434 #endif
435 
436 #ifdef GALLIUM_KMSRO
437 #include "kmsro/drm/kmsro_drm_public.h"
438 
439 static struct pipe_screen *
440 pipe_kmsro_create_screen(int fd, const struct pipe_screen_config *config)
441 {
442    struct pipe_screen *screen;
443 
444    screen = kmsro_drm_screen_create(fd, config);
445    return screen ? debug_screen_wrap(screen) : NULL;
446 }
447 const driOptionDescription kmsro_driconf[] = {
448 #if defined(GALLIUM_VC4) || defined(GALLIUM_V3D)
449       #include "v3d/driinfo_v3d.h"
450 #endif
451 #ifdef GALLIUM_ASAHI
452       #include "asahi/driinfo_asahi.h"
453 #endif
454 #ifdef GALLIUM_FREEDRENO
455       #include "freedreno/driinfo_freedreno.h"
456 #endif
457 };
458 DRM_DRIVER_DESCRIPTOR(kmsro, kmsro_driconf, ARRAY_SIZE(kmsro_driconf))
459 
460 #else
461 DRM_DRIVER_DESCRIPTOR_STUB(kmsro)
462 #endif
463 
464 /* kmsro should be the last entry in the file. */
465 
466 #endif /* DRM_HELPER_H */
467