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