gallium/ilo: cleanup intel_winsys.h
[mesa.git] / src / gallium / auxiliary / target-helpers / inline_drm_helper.h
1 #ifndef INLINE_DRM_HELPER_H
2 #define INLINE_DRM_HELPER_H
3
4 #include "state_tracker/drm_driver.h"
5 #include "target-helpers/inline_debug_helper.h"
6 #include "loader.h"
7 #if defined(DRI_TARGET)
8 #include "dri_screen.h"
9 #endif
10
11 #if GALLIUM_SOFTPIPE
12 #include "target-helpers/inline_sw_helper.h"
13 #include "sw/kms-dri/kms_dri_sw_winsys.h"
14 #endif
15
16 #if GALLIUM_I915
17 #include "i915/drm/i915_drm_public.h"
18 #include "i915/i915_public.h"
19 #endif
20
21 #if GALLIUM_ILO
22 #include "intel/drm/intel_drm_public.h"
23 #include "ilo/ilo_public.h"
24 #endif
25
26 #if GALLIUM_NOUVEAU
27 #include "nouveau/drm/nouveau_drm_public.h"
28 #endif
29
30 #if GALLIUM_R300
31 #include "radeon/drm/radeon_winsys.h"
32 #include "radeon/drm/radeon_drm_public.h"
33 #include "r300/r300_public.h"
34 #endif
35
36 #if GALLIUM_R600
37 #include "radeon/drm/radeon_winsys.h"
38 #include "radeon/drm/radeon_drm_public.h"
39 #include "r600/r600_public.h"
40 #endif
41
42 #if GALLIUM_RADEONSI
43 #include "radeon/drm/radeon_winsys.h"
44 #include "radeon/drm/radeon_drm_public.h"
45 #include "radeonsi/si_public.h"
46 #endif
47
48 #if GALLIUM_VMWGFX
49 #include "svga/drm/svga_drm_public.h"
50 #include "svga/svga_public.h"
51 #endif
52
53 #if GALLIUM_FREEDRENO
54 #include "freedreno/drm/freedreno_drm_public.h"
55 #endif
56
57 #if GALLIUM_VC4
58 #include "vc4/drm/vc4_drm_public.h"
59 #endif
60
61 static char* driver_name = NULL;
62
63 /* XXX: We need to teardown the winsys if *screen_create() fails. */
64
65 #if defined(GALLIUM_SOFTPIPE)
66 #if defined(DRI_TARGET)
67 #if defined(HAVE_LIBDRM)
68
69 const __DRIextension **__driDriverGetExtensions_kms_swrast(void);
70
71 PUBLIC const __DRIextension **__driDriverGetExtensions_kms_swrast(void)
72 {
73 globalDriverAPI = &dri_kms_driver_api;
74 return galliumdrm_driver_extensions;
75 }
76
77 struct pipe_screen *
78 kms_swrast_create_screen(int fd)
79 {
80 struct sw_winsys *sws;
81 struct pipe_screen *screen;
82
83 sws = kms_dri_create_winsys(fd);
84 if (!sws)
85 return NULL;
86
87 screen = sw_screen_create(sws);
88 return screen ? debug_screen_wrap(screen) : NULL;
89 }
90 #endif
91 #endif
92 #endif
93
94 #if defined(GALLIUM_I915)
95 #if defined(DRI_TARGET)
96
97 const __DRIextension **__driDriverGetExtensions_i915(void);
98
99 PUBLIC const __DRIextension **__driDriverGetExtensions_i915(void)
100 {
101 globalDriverAPI = &galliumdrm_driver_api;
102 return galliumdrm_driver_extensions;
103 }
104 #endif
105
106 static struct pipe_screen *
107 pipe_i915_create_screen(int fd)
108 {
109 struct i915_winsys *iws;
110 struct pipe_screen *screen;
111
112 iws = i915_drm_winsys_create(fd);
113 if (!iws)
114 return NULL;
115
116 screen = i915_screen_create(iws);
117 return screen ? debug_screen_wrap(screen) : NULL;
118 }
119 #endif
120
121 #if defined(GALLIUM_ILO)
122 #if defined(DRI_TARGET)
123
124 const __DRIextension **__driDriverGetExtensions_i965(void);
125
126 PUBLIC const __DRIextension **__driDriverGetExtensions_i965(void)
127 {
128 globalDriverAPI = &galliumdrm_driver_api;
129 return galliumdrm_driver_extensions;
130 }
131 #endif
132
133 static struct pipe_screen *
134 pipe_ilo_create_screen(int fd)
135 {
136 struct intel_winsys *iws;
137 struct pipe_screen *screen;
138
139 iws = intel_winsys_create_for_fd(fd);
140 if (!iws)
141 return NULL;
142
143 screen = ilo_screen_create(iws);
144 return screen ? debug_screen_wrap(screen) : NULL;
145 }
146 #endif
147
148 #if defined(GALLIUM_NOUVEAU)
149 #if defined(DRI_TARGET)
150
151 const __DRIextension **__driDriverGetExtensions_nouveau(void);
152
153 PUBLIC const __DRIextension **__driDriverGetExtensions_nouveau(void)
154 {
155 globalDriverAPI = &galliumdrm_driver_api;
156 return galliumdrm_driver_extensions;
157 }
158 #endif
159
160 static struct pipe_screen *
161 pipe_nouveau_create_screen(int fd)
162 {
163 struct pipe_screen *screen;
164
165 screen = nouveau_drm_screen_create(fd);
166 return screen ? debug_screen_wrap(screen) : NULL;
167 }
168 #endif
169
170 #if defined(GALLIUM_R300)
171 #if defined(DRI_TARGET)
172
173 const __DRIextension **__driDriverGetExtensions_r300(void);
174
175 PUBLIC const __DRIextension **__driDriverGetExtensions_r300(void)
176 {
177 globalDriverAPI = &galliumdrm_driver_api;
178 return galliumdrm_driver_extensions;
179 }
180 #endif
181
182 static struct pipe_screen *
183 pipe_r300_create_screen(int fd)
184 {
185 struct radeon_winsys *rw;
186
187 rw = radeon_drm_winsys_create(fd, r300_screen_create);
188 return rw ? debug_screen_wrap(rw->screen) : NULL;
189 }
190 #endif
191
192 #if defined(GALLIUM_R600)
193 #if defined(DRI_TARGET)
194
195 const __DRIextension **__driDriverGetExtensions_r600(void);
196
197 PUBLIC const __DRIextension **__driDriverGetExtensions_r600(void)
198 {
199 globalDriverAPI = &galliumdrm_driver_api;
200 return galliumdrm_driver_extensions;
201 }
202 #endif
203
204 static struct pipe_screen *
205 pipe_r600_create_screen(int fd)
206 {
207 struct radeon_winsys *rw;
208
209 rw = radeon_drm_winsys_create(fd, r600_screen_create);
210 return rw ? debug_screen_wrap(rw->screen) : NULL;
211 }
212 #endif
213
214 #if defined(GALLIUM_RADEONSI)
215 #if defined(DRI_TARGET)
216
217 const __DRIextension **__driDriverGetExtensions_radeonsi(void);
218
219 PUBLIC const __DRIextension **__driDriverGetExtensions_radeonsi(void)
220 {
221 globalDriverAPI = &galliumdrm_driver_api;
222 return galliumdrm_driver_extensions;
223 }
224 #endif
225
226 static struct pipe_screen *
227 pipe_radeonsi_create_screen(int fd)
228 {
229 struct radeon_winsys *rw;
230
231 rw = radeon_drm_winsys_create(fd, radeonsi_screen_create);
232 return rw ? debug_screen_wrap(rw->screen) : NULL;
233 }
234 #endif
235
236 #if defined(GALLIUM_VMWGFX)
237 #if defined(DRI_TARGET)
238
239 const __DRIextension **__driDriverGetExtensions_vmwgfx(void);
240
241 PUBLIC const __DRIextension **__driDriverGetExtensions_vmwgfx(void)
242 {
243 globalDriverAPI = &galliumdrm_driver_api;
244 return galliumdrm_driver_extensions;
245 }
246 #endif
247
248 static struct pipe_screen *
249 pipe_vmwgfx_create_screen(int fd)
250 {
251 struct svga_winsys_screen *sws;
252 struct pipe_screen *screen;
253
254 sws = svga_drm_winsys_screen_create(fd);
255 if (!sws)
256 return NULL;
257
258 screen = svga_screen_create(sws);
259 return screen ? debug_screen_wrap(screen) : NULL;
260 }
261 #endif
262
263 #if defined(GALLIUM_FREEDRENO)
264 #if defined(DRI_TARGET)
265
266 const __DRIextension **__driDriverGetExtensions_msm(void);
267
268 PUBLIC const __DRIextension **__driDriverGetExtensions_msm(void)
269 {
270 globalDriverAPI = &galliumdrm_driver_api;
271 return galliumdrm_driver_extensions;
272 }
273
274 const __DRIextension **__driDriverGetExtensions_kgsl(void);
275
276 PUBLIC const __DRIextension **__driDriverGetExtensions_kgsl(void)
277 {
278 globalDriverAPI = &galliumdrm_driver_api;
279 return galliumdrm_driver_extensions;
280 }
281 #endif
282
283 static struct pipe_screen *
284 pipe_freedreno_create_screen(int fd)
285 {
286 struct pipe_screen *screen;
287
288 screen = fd_drm_screen_create(fd);
289 return screen ? debug_screen_wrap(screen) : NULL;
290 }
291 #endif
292
293 #if defined(GALLIUM_VC4)
294 #if defined(DRI_TARGET)
295
296 const __DRIextension **__driDriverGetExtensions_vc4(void);
297
298 PUBLIC const __DRIextension **__driDriverGetExtensions_vc4(void)
299 {
300 globalDriverAPI = &galliumdrm_driver_api;
301 return galliumdrm_driver_extensions;
302 }
303
304 #if defined(USE_VC4_SIMULATOR)
305 const __DRIextension **__driDriverGetExtensions_i965(void);
306
307 /**
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.
312 *
313 * This is, of course, incompatible with building with the ilo driver, but you
314 * shouldn't be building that anyway.
315 */
316 PUBLIC const __DRIextension **__driDriverGetExtensions_i965(void)
317 {
318 globalDriverAPI = &galliumdrm_driver_api;
319 return galliumdrm_driver_extensions;
320 }
321 #endif
322
323 #endif
324
325 static struct pipe_screen *
326 pipe_vc4_create_screen(int fd)
327 {
328 struct pipe_screen *screen;
329
330 screen = vc4_drm_screen_create(fd);
331 return screen ? debug_screen_wrap(screen) : NULL;
332 }
333 #endif
334
335 inline struct pipe_screen *
336 dd_create_screen(int fd)
337 {
338 driver_name = loader_get_driver_for_fd(fd, _LOADER_GALLIUM);
339 if (!driver_name)
340 return NULL;
341
342 #if defined(GALLIUM_I915)
343 if (strcmp(driver_name, "i915") == 0)
344 return pipe_i915_create_screen(fd);
345 else
346 #endif
347 #if defined(GALLIUM_ILO)
348 if (strcmp(driver_name, "i965") == 0)
349 return pipe_ilo_create_screen(fd);
350 else
351 #endif
352 #if defined(GALLIUM_NOUVEAU)
353 if (strcmp(driver_name, "nouveau") == 0)
354 return pipe_nouveau_create_screen(fd);
355 else
356 #endif
357 #if defined(GALLIUM_R300)
358 if (strcmp(driver_name, "r300") == 0)
359 return pipe_r300_create_screen(fd);
360 else
361 #endif
362 #if defined(GALLIUM_R600)
363 if (strcmp(driver_name, "r600") == 0)
364 return pipe_r600_create_screen(fd);
365 else
366 #endif
367 #if defined(GALLIUM_RADEONSI)
368 if (strcmp(driver_name, "radeonsi") == 0)
369 return pipe_radeonsi_create_screen(fd);
370 else
371 #endif
372 #if defined(GALLIUM_VMWGFX)
373 if (strcmp(driver_name, "vmwgfx") == 0)
374 return pipe_vmwgfx_create_screen(fd);
375 else
376 #endif
377 #if defined(GALLIUM_FREEDRENO)
378 if ((strcmp(driver_name, "kgsl") == 0) || (strcmp(driver_name, "msm") == 0))
379 return pipe_freedreno_create_screen(fd);
380 else
381 #endif
382 #if defined(GALLIUM_VC4)
383 if (strcmp(driver_name, "vc4") == 0)
384 return pipe_vc4_create_screen(fd);
385 else
386 #if defined(USE_VC4_SIMULATOR)
387 if (strcmp(driver_name, "i965") == 0)
388 return pipe_vc4_create_screen(fd);
389 else
390 #endif
391 #endif
392 return NULL;
393 }
394
395 inline const char *
396 dd_driver_name(void)
397 {
398 return driver_name;
399 }
400
401 static const struct drm_conf_ret throttle_ret = {
402 DRM_CONF_INT,
403 {2},
404 };
405
406 static const struct drm_conf_ret share_fd_ret = {
407 DRM_CONF_BOOL,
408 {true},
409 };
410
411 static const struct drm_conf_ret *
412 configuration_query(enum drm_conf conf)
413 {
414 switch (conf) {
415 case DRM_CONF_THROTTLE:
416 return &throttle_ret;
417 case DRM_CONF_SHARE_FD:
418 return &share_fd_ret;
419 default:
420 break;
421 }
422 return NULL;
423 }
424
425 inline const struct drm_conf_ret *
426 dd_configuration(enum drm_conf conf)
427 {
428 if (!driver_name)
429 return NULL;
430
431 #if defined(GALLIUM_I915)
432 if (strcmp(driver_name, "i915") == 0)
433 return NULL;
434 else
435 #endif
436 #if defined(GALLIUM_ILO)
437 if (strcmp(driver_name, "i965") == 0)
438 return configuration_query(conf);
439 else
440 #endif
441 #if defined(GALLIUM_NOUVEAU)
442 if (strcmp(driver_name, "nouveau") == 0)
443 return configuration_query(conf);
444 else
445 #endif
446 #if defined(GALLIUM_R300)
447 if (strcmp(driver_name, "r300") == 0)
448 return configuration_query(conf);
449 else
450 #endif
451 #if defined(GALLIUM_R600)
452 if (strcmp(driver_name, "r600") == 0)
453 return configuration_query(conf);
454 else
455 #endif
456 #if defined(GALLIUM_RADEONSI)
457 if (strcmp(driver_name, "radeonsi") == 0)
458 return configuration_query(conf);
459 else
460 #endif
461 #if defined(GALLIUM_VMWGFX)
462 if (strcmp(driver_name, "vmwgfx") == 0)
463 return configuration_query(conf);
464 else
465 #endif
466 #if defined(GALLIUM_FREEDRENO)
467 if ((strcmp(driver_name, "kgsl") == 0) || (strcmp(driver_name, "msm") == 0))
468 return NULL;
469 else
470 #endif
471 return NULL;
472 }
473 #endif /* INLINE_DRM_HELPER_H */