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