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