55f636339b3a95de5ebaf3595609932ef37998af
[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/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/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/radeon_winsys.h"
44 #include "radeon/drm/radeon_drm_public.h"
45 #include "amdgpu/drm/amdgpu_public.h"
46 #include "radeonsi/si_public.h"
47 #endif
48
49 #if GALLIUM_VMWGFX
50 #include "svga/drm/svga_drm_public.h"
51 #include "svga/svga_public.h"
52 #endif
53
54 #if GALLIUM_FREEDRENO
55 #include "freedreno/drm/freedreno_drm_public.h"
56 #endif
57
58 #if GALLIUM_VC4
59 #include "vc4/drm/vc4_drm_public.h"
60 #endif
61
62 #if GALLIUM_VIRGL
63 #include "virgl/drm/virgl_drm_public.h"
64 #include "virgl/virgl_public.h"
65 #endif
66
67 static char* driver_name = NULL;
68
69 /* XXX: We need to teardown the winsys if *screen_create() fails. */
70
71 #if defined(GALLIUM_SOFTPIPE)
72 #if defined(DRI_TARGET)
73 #if defined(HAVE_LIBDRM)
74
75 struct pipe_screen *
76 kms_swrast_create_screen(int fd)
77 {
78 struct sw_winsys *sws;
79 struct pipe_screen *screen;
80
81 sws = kms_dri_create_winsys(fd);
82 if (!sws)
83 return NULL;
84
85 screen = sw_screen_create(sws);
86 return screen ? debug_screen_wrap(screen) : NULL;
87 }
88 #endif
89 #endif
90 #endif
91
92 #if defined(GALLIUM_I915)
93
94 static struct pipe_screen *
95 pipe_i915_create_screen(int fd)
96 {
97 struct i915_winsys *iws;
98 struct pipe_screen *screen;
99
100 iws = i915_drm_winsys_create(fd);
101 if (!iws)
102 return NULL;
103
104 screen = i915_screen_create(iws);
105 return screen ? debug_screen_wrap(screen) : NULL;
106 }
107 #endif
108
109 #if defined(GALLIUM_ILO)
110
111 static struct pipe_screen *
112 pipe_ilo_create_screen(int fd)
113 {
114 struct intel_winsys *iws;
115 struct pipe_screen *screen;
116
117 iws = intel_winsys_create_for_fd(fd);
118 if (!iws)
119 return NULL;
120
121 screen = ilo_screen_create(iws);
122 return screen ? debug_screen_wrap(screen) : NULL;
123 }
124 #endif
125
126 #if defined(GALLIUM_NOUVEAU)
127
128 static struct pipe_screen *
129 pipe_nouveau_create_screen(int fd)
130 {
131 struct pipe_screen *screen;
132
133 screen = nouveau_drm_screen_create(fd);
134 return screen ? debug_screen_wrap(screen) : NULL;
135 }
136 #endif
137
138 #if defined(GALLIUM_R300)
139
140 static struct pipe_screen *
141 pipe_r300_create_screen(int fd)
142 {
143 struct radeon_winsys *rw;
144
145 rw = radeon_drm_winsys_create(fd, r300_screen_create);
146 return rw ? debug_screen_wrap(rw->screen) : NULL;
147 }
148 #endif
149
150 #if defined(GALLIUM_R600)
151
152 static struct pipe_screen *
153 pipe_r600_create_screen(int fd)
154 {
155 struct radeon_winsys *rw;
156
157 rw = radeon_drm_winsys_create(fd, r600_screen_create);
158 return rw ? debug_screen_wrap(rw->screen) : NULL;
159 }
160 #endif
161
162 #if defined(GALLIUM_RADEONSI)
163
164 static struct pipe_screen *
165 pipe_radeonsi_create_screen(int fd)
166 {
167 struct radeon_winsys *rw;
168
169 /* First, try amdgpu. */
170 rw = amdgpu_winsys_create(fd, radeonsi_screen_create);
171
172 if (!rw)
173 rw = radeon_drm_winsys_create(fd, radeonsi_screen_create);
174
175 return rw ? debug_screen_wrap(rw->screen) : NULL;
176 }
177 #endif
178
179 #if defined(GALLIUM_VMWGFX)
180
181 static struct pipe_screen *
182 pipe_vmwgfx_create_screen(int fd)
183 {
184 struct svga_winsys_screen *sws;
185 struct pipe_screen *screen;
186
187 sws = svga_drm_winsys_screen_create(fd);
188 if (!sws)
189 return NULL;
190
191 screen = svga_screen_create(sws);
192 return screen ? debug_screen_wrap(screen) : NULL;
193 }
194 #endif
195
196 #if defined(GALLIUM_FREEDRENO)
197
198 static struct pipe_screen *
199 pipe_freedreno_create_screen(int fd)
200 {
201 struct pipe_screen *screen;
202
203 screen = fd_drm_screen_create(fd);
204 return screen ? debug_screen_wrap(screen) : NULL;
205 }
206 #endif
207
208 #if defined(GALLIUM_VIRGL)
209
210 static struct pipe_screen *
211 pipe_virgl_create_screen(int fd)
212 {
213 struct virgl_winsys *vws;
214 struct pipe_screen *screen;
215
216 vws = virgl_drm_winsys_create(fd);
217 if (!vws)
218 return NULL;
219
220 screen = virgl_create_screen(vws);
221 return screen ? debug_screen_wrap(screen) : NULL;
222 }
223 #endif
224
225 #if defined(GALLIUM_VC4)
226
227 static struct pipe_screen *
228 pipe_vc4_create_screen(int fd)
229 {
230 struct pipe_screen *screen;
231
232 screen = vc4_drm_screen_create(fd);
233 return screen ? debug_screen_wrap(screen) : NULL;
234 }
235 #endif
236
237 inline struct pipe_screen *
238 dd_create_screen(int fd)
239 {
240 driver_name = loader_get_driver_for_fd(fd, _LOADER_GALLIUM);
241 if (!driver_name)
242 return NULL;
243
244 #if defined(GALLIUM_I915)
245 if (strcmp(driver_name, "i915") == 0)
246 return pipe_i915_create_screen(fd);
247 else
248 #endif
249 #if defined(GALLIUM_ILO)
250 if (strcmp(driver_name, "i965") == 0)
251 return pipe_ilo_create_screen(fd);
252 else
253 #endif
254 #if defined(GALLIUM_NOUVEAU)
255 if (strcmp(driver_name, "nouveau") == 0)
256 return pipe_nouveau_create_screen(fd);
257 else
258 #endif
259 #if defined(GALLIUM_R300)
260 if (strcmp(driver_name, "r300") == 0)
261 return pipe_r300_create_screen(fd);
262 else
263 #endif
264 #if defined(GALLIUM_R600)
265 if (strcmp(driver_name, "r600") == 0)
266 return pipe_r600_create_screen(fd);
267 else
268 #endif
269 #if defined(GALLIUM_RADEONSI)
270 if (strcmp(driver_name, "radeonsi") == 0)
271 return pipe_radeonsi_create_screen(fd);
272 else
273 #endif
274 #if defined(GALLIUM_VMWGFX)
275 if (strcmp(driver_name, "vmwgfx") == 0)
276 return pipe_vmwgfx_create_screen(fd);
277 else
278 #endif
279 #if defined(GALLIUM_FREEDRENO)
280 if ((strcmp(driver_name, "kgsl") == 0) || (strcmp(driver_name, "msm") == 0))
281 return pipe_freedreno_create_screen(fd);
282 else
283 #endif
284 #if defined(GALLIUM_VIRGL)
285 if ((strcmp(driver_name, "virtio_gpu") == 0))
286 return pipe_virgl_create_screen(fd);
287 else
288 #endif
289 #if defined(GALLIUM_VC4)
290 if (strcmp(driver_name, "vc4") == 0)
291 return pipe_vc4_create_screen(fd);
292 else
293 #if defined(USE_VC4_SIMULATOR)
294 if (strcmp(driver_name, "i965") == 0)
295 return pipe_vc4_create_screen(fd);
296 else
297 #endif
298 #endif
299 return NULL;
300 }
301
302 inline const char *
303 dd_driver_name(void)
304 {
305 return driver_name;
306 }
307
308 static const struct drm_conf_ret throttle_ret = {
309 DRM_CONF_INT,
310 {2},
311 };
312
313 static const struct drm_conf_ret share_fd_ret = {
314 DRM_CONF_BOOL,
315 {true},
316 };
317
318 static inline const struct drm_conf_ret *
319 configuration_query(enum drm_conf conf)
320 {
321 switch (conf) {
322 case DRM_CONF_THROTTLE:
323 return &throttle_ret;
324 case DRM_CONF_SHARE_FD:
325 return &share_fd_ret;
326 default:
327 break;
328 }
329 return NULL;
330 }
331
332 inline const struct drm_conf_ret *
333 dd_configuration(enum drm_conf conf)
334 {
335 if (!driver_name)
336 return NULL;
337
338 #if defined(GALLIUM_I915)
339 if (strcmp(driver_name, "i915") == 0)
340 return configuration_query(conf);
341 else
342 #endif
343 #if defined(GALLIUM_ILO)
344 if (strcmp(driver_name, "i965") == 0)
345 return configuration_query(conf);
346 else
347 #endif
348 #if defined(GALLIUM_NOUVEAU)
349 if (strcmp(driver_name, "nouveau") == 0)
350 return configuration_query(conf);
351 else
352 #endif
353 #if defined(GALLIUM_R300)
354 if (strcmp(driver_name, "r300") == 0)
355 return configuration_query(conf);
356 else
357 #endif
358 #if defined(GALLIUM_R600)
359 if (strcmp(driver_name, "r600") == 0)
360 return configuration_query(conf);
361 else
362 #endif
363 #if defined(GALLIUM_RADEONSI)
364 if (strcmp(driver_name, "radeonsi") == 0)
365 return configuration_query(conf);
366 else
367 #endif
368 #if defined(GALLIUM_VMWGFX)
369 if (strcmp(driver_name, "vmwgfx") == 0)
370 return configuration_query(conf);
371 else
372 #endif
373 #if defined(GALLIUM_FREEDRENO)
374 if ((strcmp(driver_name, "kgsl") == 0) || (strcmp(driver_name, "msm") == 0))
375 return configuration_query(conf);
376 else
377 #endif
378 #if defined(GALLIUM_VIRGL)
379 if ((strcmp(driver_name, "virtio_gpu") == 0))
380 return configuration_query(conf);
381 else
382 #endif
383 #if defined(GALLIUM_VC4)
384 if (strcmp(driver_name, "vc4") == 0)
385 return configuration_query(conf);
386 else
387 #if defined(USE_VC4_SIMULATOR)
388 if (strcmp(driver_name, "i965") == 0)
389 return configuration_query(conf);
390 else
391 #endif
392 #endif
393 return NULL;
394 }
395 #endif /* INLINE_DRM_HELPER_H */