1 #ifndef INLINE_DRM_HELPER_H
2 #define INLINE_DRM_HELPER_H
4 #include "state_tracker/drm_driver.h"
5 #include "target-helpers/inline_debug_helper.h"
7 #if defined(DRI_TARGET)
8 #include "dri_screen.h"
12 #include "target-helpers/inline_sw_helper.h"
13 #include "sw/kms-dri/kms_dri_sw_winsys.h"
17 #include "i915/drm/i915_drm_public.h"
18 #include "i915/i915_public.h"
22 #include "intel/drm/intel_drm_public.h"
23 #include "ilo/ilo_public.h"
27 #include "nouveau/drm/nouveau_drm_public.h"
31 #include "radeon/drm/radeon_winsys.h"
32 #include "radeon/drm/radeon_drm_public.h"
33 #include "r300/r300_public.h"
37 #include "radeon/drm/radeon_winsys.h"
38 #include "radeon/drm/radeon_drm_public.h"
39 #include "r600/r600_public.h"
43 #include "radeon/drm/radeon_winsys.h"
44 #include "radeon/drm/radeon_drm_public.h"
45 #include "radeonsi/si_public.h"
49 #include "svga/drm/svga_drm_public.h"
50 #include "svga/svga_public.h"
54 #include "freedreno/drm/freedreno_drm_public.h"
58 #include "vc4/drm/vc4_drm_public.h"
61 static char* driver_name
= NULL
;
63 /* XXX: We need to teardown the winsys if *screen_create() fails. */
65 #if defined(GALLIUM_SOFTPIPE)
66 #if defined(DRI_TARGET)
67 #if defined(HAVE_LIBDRM)
69 const __DRIextension
**__driDriverGetExtensions_kms_swrast(void);
71 PUBLIC
const __DRIextension
**__driDriverGetExtensions_kms_swrast(void)
73 globalDriverAPI
= &dri_kms_driver_api
;
74 return galliumdrm_driver_extensions
;
78 kms_swrast_create_screen(int fd
)
80 struct sw_winsys
*sws
;
81 struct pipe_screen
*screen
;
83 sws
= kms_dri_create_winsys(fd
);
87 screen
= sw_screen_create(sws
);
88 return screen
? debug_screen_wrap(screen
) : NULL
;
94 #if defined(GALLIUM_I915)
95 #if defined(DRI_TARGET)
97 const __DRIextension
**__driDriverGetExtensions_i915(void);
99 PUBLIC
const __DRIextension
**__driDriverGetExtensions_i915(void)
101 globalDriverAPI
= &galliumdrm_driver_api
;
102 return galliumdrm_driver_extensions
;
106 static struct pipe_screen
*
107 pipe_i915_create_screen(int fd
)
109 struct i915_winsys
*iws
;
110 struct pipe_screen
*screen
;
112 iws
= i915_drm_winsys_create(fd
);
116 screen
= i915_screen_create(iws
);
117 return screen
? debug_screen_wrap(screen
) : NULL
;
121 #if defined(GALLIUM_ILO)
122 #if defined(DRI_TARGET)
124 const __DRIextension
**__driDriverGetExtensions_i965(void);
126 PUBLIC
const __DRIextension
**__driDriverGetExtensions_i965(void)
128 globalDriverAPI
= &galliumdrm_driver_api
;
129 return galliumdrm_driver_extensions
;
133 static struct pipe_screen
*
134 pipe_ilo_create_screen(int fd
)
136 struct intel_winsys
*iws
;
137 struct pipe_screen
*screen
;
139 iws
= intel_winsys_create_for_fd(fd
);
143 screen
= ilo_screen_create(iws
);
144 return screen
? debug_screen_wrap(screen
) : NULL
;
148 #if defined(GALLIUM_NOUVEAU)
149 #if defined(DRI_TARGET)
151 const __DRIextension
**__driDriverGetExtensions_nouveau(void);
153 PUBLIC
const __DRIextension
**__driDriverGetExtensions_nouveau(void)
155 globalDriverAPI
= &galliumdrm_driver_api
;
156 return galliumdrm_driver_extensions
;
160 static struct pipe_screen
*
161 pipe_nouveau_create_screen(int fd
)
163 struct pipe_screen
*screen
;
165 screen
= nouveau_drm_screen_create(fd
);
166 return screen
? debug_screen_wrap(screen
) : NULL
;
170 #if defined(GALLIUM_R300)
171 #if defined(DRI_TARGET)
173 const __DRIextension
**__driDriverGetExtensions_r300(void);
175 PUBLIC
const __DRIextension
**__driDriverGetExtensions_r300(void)
177 globalDriverAPI
= &galliumdrm_driver_api
;
178 return galliumdrm_driver_extensions
;
182 static struct pipe_screen
*
183 pipe_r300_create_screen(int fd
)
185 struct radeon_winsys
*rw
;
187 rw
= radeon_drm_winsys_create(fd
, r300_screen_create
);
188 return rw
? debug_screen_wrap(rw
->screen
) : NULL
;
192 #if defined(GALLIUM_R600)
193 #if defined(DRI_TARGET)
195 const __DRIextension
**__driDriverGetExtensions_r600(void);
197 PUBLIC
const __DRIextension
**__driDriverGetExtensions_r600(void)
199 globalDriverAPI
= &galliumdrm_driver_api
;
200 return galliumdrm_driver_extensions
;
204 static struct pipe_screen
*
205 pipe_r600_create_screen(int fd
)
207 struct radeon_winsys
*rw
;
209 rw
= radeon_drm_winsys_create(fd
, r600_screen_create
);
210 return rw
? debug_screen_wrap(rw
->screen
) : NULL
;
214 #if defined(GALLIUM_RADEONSI)
215 #if defined(DRI_TARGET)
217 const __DRIextension
**__driDriverGetExtensions_radeonsi(void);
219 PUBLIC
const __DRIextension
**__driDriverGetExtensions_radeonsi(void)
221 globalDriverAPI
= &galliumdrm_driver_api
;
222 return galliumdrm_driver_extensions
;
226 static struct pipe_screen
*
227 pipe_radeonsi_create_screen(int fd
)
229 struct radeon_winsys
*rw
;
231 rw
= radeon_drm_winsys_create(fd
, radeonsi_screen_create
);
232 return rw
? debug_screen_wrap(rw
->screen
) : NULL
;
236 #if defined(GALLIUM_VMWGFX)
237 #if defined(DRI_TARGET)
239 const __DRIextension
**__driDriverGetExtensions_vmwgfx(void);
241 PUBLIC
const __DRIextension
**__driDriverGetExtensions_vmwgfx(void)
243 globalDriverAPI
= &galliumdrm_driver_api
;
244 return galliumdrm_driver_extensions
;
248 static struct pipe_screen
*
249 pipe_vmwgfx_create_screen(int fd
)
251 struct svga_winsys_screen
*sws
;
252 struct pipe_screen
*screen
;
254 sws
= svga_drm_winsys_screen_create(fd
);
258 screen
= svga_screen_create(sws
);
259 return screen
? debug_screen_wrap(screen
) : NULL
;
263 #if defined(GALLIUM_FREEDRENO)
264 #if defined(DRI_TARGET)
266 const __DRIextension
**__driDriverGetExtensions_msm(void);
268 PUBLIC
const __DRIextension
**__driDriverGetExtensions_msm(void)
270 globalDriverAPI
= &galliumdrm_driver_api
;
271 return galliumdrm_driver_extensions
;
274 const __DRIextension
**__driDriverGetExtensions_kgsl(void);
276 PUBLIC
const __DRIextension
**__driDriverGetExtensions_kgsl(void)
278 globalDriverAPI
= &galliumdrm_driver_api
;
279 return galliumdrm_driver_extensions
;
283 static struct pipe_screen
*
284 pipe_freedreno_create_screen(int fd
)
286 struct pipe_screen
*screen
;
288 screen
= fd_drm_screen_create(fd
);
289 return screen
? debug_screen_wrap(screen
) : NULL
;
293 #if defined(GALLIUM_VC4)
294 #if defined(DRI_TARGET)
296 const __DRIextension
**__driDriverGetExtensions_vc4(void);
298 PUBLIC
const __DRIextension
**__driDriverGetExtensions_vc4(void)
300 globalDriverAPI
= &galliumdrm_driver_api
;
301 return galliumdrm_driver_extensions
;
304 #if defined(USE_VC4_SIMULATOR)
305 const __DRIextension
**__driDriverGetExtensions_i965(void);
308 * When building using the simulator (on x86), we advertise ourselves as the
309 * i965 driver so that you can just make a directory with a link from
310 * i965_dri.so to the built vc4_dri.so, and point LIBGL_DRIVERS_PATH to that
311 * on your i965-using host to run the driver under simulation.
313 * This is, of course, incompatible with building with the ilo driver, but you
314 * shouldn't be building that anyway.
316 PUBLIC
const __DRIextension
**__driDriverGetExtensions_i965(void)
318 globalDriverAPI
= &galliumdrm_driver_api
;
319 return galliumdrm_driver_extensions
;
325 static struct pipe_screen
*
326 pipe_vc4_create_screen(int fd
)
328 struct pipe_screen
*screen
;
330 screen
= vc4_drm_screen_create(fd
);
331 return screen
? debug_screen_wrap(screen
) : NULL
;
335 inline struct pipe_screen
*
336 dd_create_screen(int fd
)
338 driver_name
= loader_get_driver_for_fd(fd
, _LOADER_GALLIUM
);
342 #if defined(GALLIUM_I915)
343 if (strcmp(driver_name
, "i915") == 0)
344 return pipe_i915_create_screen(fd
);
347 #if defined(GALLIUM_ILO)
348 if (strcmp(driver_name
, "i965") == 0)
349 return pipe_ilo_create_screen(fd
);
352 #if defined(GALLIUM_NOUVEAU)
353 if (strcmp(driver_name
, "nouveau") == 0)
354 return pipe_nouveau_create_screen(fd
);
357 #if defined(GALLIUM_R300)
358 if (strcmp(driver_name
, "r300") == 0)
359 return pipe_r300_create_screen(fd
);
362 #if defined(GALLIUM_R600)
363 if (strcmp(driver_name
, "r600") == 0)
364 return pipe_r600_create_screen(fd
);
367 #if defined(GALLIUM_RADEONSI)
368 if (strcmp(driver_name
, "radeonsi") == 0)
369 return pipe_radeonsi_create_screen(fd
);
372 #if defined(GALLIUM_VMWGFX)
373 if (strcmp(driver_name
, "vmwgfx") == 0)
374 return pipe_vmwgfx_create_screen(fd
);
377 #if defined(GALLIUM_FREEDRENO)
378 if ((strcmp(driver_name
, "kgsl") == 0) || (strcmp(driver_name
, "msm") == 0))
379 return pipe_freedreno_create_screen(fd
);
382 #if defined(GALLIUM_VC4)
383 if (strcmp(driver_name
, "vc4") == 0)
384 return pipe_vc4_create_screen(fd
);
386 #if defined(USE_VC4_SIMULATOR)
387 if (strcmp(driver_name
, "i965") == 0)
388 return pipe_vc4_create_screen(fd
);
401 static const struct drm_conf_ret throttle_ret
= {
406 static const struct drm_conf_ret share_fd_ret
= {
411 static inline const struct drm_conf_ret
*
412 configuration_query(enum drm_conf conf
)
415 case DRM_CONF_THROTTLE
:
416 return &throttle_ret
;
417 case DRM_CONF_SHARE_FD
:
418 return &share_fd_ret
;
425 inline const struct drm_conf_ret
*
426 dd_configuration(enum drm_conf conf
)
431 #if defined(GALLIUM_I915)
432 if (strcmp(driver_name
, "i915") == 0)
436 #if defined(GALLIUM_ILO)
437 if (strcmp(driver_name
, "i965") == 0)
438 return configuration_query(conf
);
441 #if defined(GALLIUM_NOUVEAU)
442 if (strcmp(driver_name
, "nouveau") == 0)
443 return configuration_query(conf
);
446 #if defined(GALLIUM_R300)
447 if (strcmp(driver_name
, "r300") == 0)
448 return configuration_query(conf
);
451 #if defined(GALLIUM_R600)
452 if (strcmp(driver_name
, "r600") == 0)
453 return configuration_query(conf
);
456 #if defined(GALLIUM_RADEONSI)
457 if (strcmp(driver_name
, "radeonsi") == 0)
458 return configuration_query(conf
);
461 #if defined(GALLIUM_VMWGFX)
462 if (strcmp(driver_name
, "vmwgfx") == 0)
463 return configuration_query(conf
);
466 #if defined(GALLIUM_FREEDRENO)
467 if ((strcmp(driver_name
, "kgsl") == 0) || (strcmp(driver_name
, "msm") == 0))
468 return configuration_query(conf
);
473 #endif /* INLINE_DRM_HELPER_H */