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