radeon: stupid mesa extension fail
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_screen.c
1 /**************************************************************************
2
3 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
4 VA Linux Systems Inc., Fremont, California.
5
6 All Rights Reserved.
7
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
15
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial
18 portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28 **************************************************************************/
29
30 /**
31 * \file radeon_screen.c
32 * Screen initialization functions for the Radeon driver.
33 *
34 * \author Kevin E. Martin <martin@valinux.com>
35 * \author Gareth Hughes <gareth@valinux.com>
36 */
37
38 #include <errno.h>
39 #include "main/glheader.h"
40 #include "main/imports.h"
41 #include "main/mtypes.h"
42 #include "main/framebuffer.h"
43 #include "main/renderbuffer.h"
44
45 #define STANDALONE_MMIO
46 #include "radeon_chipset.h"
47 #include "radeon_macros.h"
48 #include "radeon_screen.h"
49 #include "radeon_common.h"
50 #include "radeon_span.h"
51 #if !RADEON_COMMON
52 #include "radeon_context.h"
53 #include "radeon_tex.h"
54 #elif RADEON_COMMON && defined(RADEON_COMMON_FOR_R200)
55 #include "r200_context.h"
56 #include "r200_ioctl.h"
57 #include "r200_tex.h"
58 #elif RADEON_COMMON && defined(RADEON_COMMON_FOR_R300)
59 #include "r300_context.h"
60 #include "r300_fragprog.h"
61 #include "r300_tex.h"
62 #endif
63
64 #include "utils.h"
65 #include "vblank.h"
66 #include "drirenderbuffer.h"
67
68 #include "radeon_bocs_wrapper.h"
69
70 #include "GL/internal/dri_interface.h"
71
72 /* Radeon configuration
73 */
74 #include "xmlpool.h"
75
76 #define DRI_CONF_COMMAND_BUFFER_SIZE(def,min,max) \
77 DRI_CONF_OPT_BEGIN_V(command_buffer_size,int,def, # min ":" # max ) \
78 DRI_CONF_DESC(en,"Size of command buffer (in KB)") \
79 DRI_CONF_DESC(de,"Grösse des Befehlspuffers (in KB)") \
80 DRI_CONF_OPT_END
81
82 #if !RADEON_COMMON /* R100 */
83 PUBLIC const char __driConfigOptions[] =
84 DRI_CONF_BEGIN
85 DRI_CONF_SECTION_PERFORMANCE
86 DRI_CONF_TCL_MODE(DRI_CONF_TCL_CODEGEN)
87 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)
88 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0)
89 DRI_CONF_MAX_TEXTURE_UNITS(3,2,3)
90 DRI_CONF_HYPERZ(false)
91 DRI_CONF_COMMAND_BUFFER_SIZE(8, 8, 32)
92 DRI_CONF_SECTION_END
93 DRI_CONF_SECTION_QUALITY
94 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB)
95 DRI_CONF_DEF_MAX_ANISOTROPY(1.0,"1.0,2.0,4.0,8.0,16.0")
96 DRI_CONF_NO_NEG_LOD_BIAS(false)
97 DRI_CONF_FORCE_S3TC_ENABLE(false)
98 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER)
99 DRI_CONF_ROUND_MODE(DRI_CONF_ROUND_TRUNC)
100 DRI_CONF_DITHER_MODE(DRI_CONF_DITHER_XERRORDIFF)
101 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
102 DRI_CONF_SECTION_END
103 DRI_CONF_SECTION_DEBUG
104 DRI_CONF_NO_RAST(false)
105 DRI_CONF_SECTION_END
106 DRI_CONF_END;
107 static const GLuint __driNConfigOptions = 15;
108
109 #elif RADEON_COMMON && defined(RADEON_COMMON_FOR_R200)
110
111 PUBLIC const char __driConfigOptions[] =
112 DRI_CONF_BEGIN
113 DRI_CONF_SECTION_PERFORMANCE
114 DRI_CONF_TCL_MODE(DRI_CONF_TCL_CODEGEN)
115 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)
116 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0)
117 DRI_CONF_MAX_TEXTURE_UNITS(6,2,6)
118 DRI_CONF_HYPERZ(false)
119 DRI_CONF_COMMAND_BUFFER_SIZE(8, 8, 32)
120 DRI_CONF_SECTION_END
121 DRI_CONF_SECTION_QUALITY
122 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB)
123 DRI_CONF_DEF_MAX_ANISOTROPY(1.0,"1.0,2.0,4.0,8.0,16.0")
124 DRI_CONF_NO_NEG_LOD_BIAS(false)
125 DRI_CONF_FORCE_S3TC_ENABLE(false)
126 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER)
127 DRI_CONF_ROUND_MODE(DRI_CONF_ROUND_TRUNC)
128 DRI_CONF_DITHER_MODE(DRI_CONF_DITHER_XERRORDIFF)
129 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
130 DRI_CONF_TEXTURE_BLEND_QUALITY(1.0,"0.0:1.0")
131 DRI_CONF_SECTION_END
132 DRI_CONF_SECTION_DEBUG
133 DRI_CONF_NO_RAST(false)
134 DRI_CONF_SECTION_END
135 DRI_CONF_SECTION_SOFTWARE
136 DRI_CONF_NV_VERTEX_PROGRAM(false)
137 DRI_CONF_SECTION_END
138 DRI_CONF_END;
139 static const GLuint __driNConfigOptions = 17;
140
141 extern const struct dri_extension blend_extensions[];
142 extern const struct dri_extension ARB_vp_extension[];
143 extern const struct dri_extension NV_vp_extension[];
144 extern const struct dri_extension ATI_fs_extension[];
145 extern const struct dri_extension point_extensions[];
146
147 #elif RADEON_COMMON && defined(RADEON_COMMON_FOR_R300)
148
149 /* TODO: integrate these into xmlpool.h! */
150 #define DRI_CONF_MAX_TEXTURE_IMAGE_UNITS(def,min,max) \
151 DRI_CONF_OPT_BEGIN_V(texture_image_units,int,def, # min ":" # max ) \
152 DRI_CONF_DESC(en,"Number of texture image units") \
153 DRI_CONF_DESC(de,"Anzahl der Textureinheiten") \
154 DRI_CONF_OPT_END
155
156 #define DRI_CONF_MAX_TEXTURE_COORD_UNITS(def,min,max) \
157 DRI_CONF_OPT_BEGIN_V(texture_coord_units,int,def, # min ":" # max ) \
158 DRI_CONF_DESC(en,"Number of texture coordinate units") \
159 DRI_CONF_DESC(de,"Anzahl der Texturkoordinateneinheiten") \
160 DRI_CONF_OPT_END
161
162
163
164 #define DRI_CONF_DISABLE_S3TC(def) \
165 DRI_CONF_OPT_BEGIN(disable_s3tc,bool,def) \
166 DRI_CONF_DESC(en,"Disable S3TC compression") \
167 DRI_CONF_OPT_END
168
169 #define DRI_CONF_DISABLE_FALLBACK(def) \
170 DRI_CONF_OPT_BEGIN(disable_lowimpact_fallback,bool,def) \
171 DRI_CONF_DESC(en,"Disable Low-impact fallback") \
172 DRI_CONF_OPT_END
173
174 #define DRI_CONF_DISABLE_DOUBLE_SIDE_STENCIL(def) \
175 DRI_CONF_OPT_BEGIN(disable_stencil_two_side,bool,def) \
176 DRI_CONF_DESC(en,"Disable GL_EXT_stencil_two_side") \
177 DRI_CONF_OPT_END
178
179 #define DRI_CONF_FP_OPTIMIZATION(def) \
180 DRI_CONF_OPT_BEGIN_V(fp_optimization,enum,def,"0:1") \
181 DRI_CONF_DESC_BEGIN(en,"Fragment Program optimization") \
182 DRI_CONF_ENUM(0,"Optimize for Speed") \
183 DRI_CONF_ENUM(1,"Optimize for Quality") \
184 DRI_CONF_DESC_END \
185 DRI_CONF_OPT_END
186
187 PUBLIC const char __driConfigOptions[] =
188 DRI_CONF_BEGIN
189 DRI_CONF_SECTION_PERFORMANCE
190 DRI_CONF_TCL_MODE(DRI_CONF_TCL_CODEGEN)
191 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)
192 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0)
193 DRI_CONF_MAX_TEXTURE_IMAGE_UNITS(8, 2, 8)
194 DRI_CONF_MAX_TEXTURE_COORD_UNITS(8, 2, 8)
195 DRI_CONF_COMMAND_BUFFER_SIZE(8, 8, 32)
196 DRI_CONF_DISABLE_FALLBACK(true)
197 DRI_CONF_DISABLE_DOUBLE_SIDE_STENCIL(false)
198 DRI_CONF_SECTION_END
199 DRI_CONF_SECTION_QUALITY
200 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB)
201 DRI_CONF_DEF_MAX_ANISOTROPY(1.0, "1.0,2.0,4.0,8.0,16.0")
202 DRI_CONF_FORCE_S3TC_ENABLE(false)
203 DRI_CONF_DISABLE_S3TC(false)
204 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER)
205 DRI_CONF_ROUND_MODE(DRI_CONF_ROUND_TRUNC)
206 DRI_CONF_DITHER_MODE(DRI_CONF_DITHER_XERRORDIFF)
207 DRI_CONF_FP_OPTIMIZATION(DRI_CONF_FP_OPTIMIZATION_SPEED)
208 DRI_CONF_SECTION_END
209 DRI_CONF_SECTION_DEBUG
210 DRI_CONF_NO_RAST(false)
211 DRI_CONF_SECTION_END
212 DRI_CONF_END;
213 static const GLuint __driNConfigOptions = 17;
214
215 extern const struct dri_extension gl_20_extension[];
216
217 #ifndef RADEON_DEBUG
218
219 static const struct dri_debug_control debug_control[] = {
220 {"fall", DEBUG_FALLBACKS},
221 {"tex", DEBUG_TEXTURE},
222 {"ioctl", DEBUG_IOCTL},
223 {"prim", DEBUG_PRIMS},
224 {"vert", DEBUG_VERTS},
225 {"state", DEBUG_STATE},
226 {"code", DEBUG_CODEGEN},
227 {"vfmt", DEBUG_VFMT},
228 {"vtxf", DEBUG_VFMT},
229 {"verb", DEBUG_VERBOSE},
230 {"dri", DEBUG_DRI},
231 {"dma", DEBUG_DMA},
232 {"san", DEBUG_SANITY},
233 {"sync", DEBUG_SYNC},
234 {"pix", DEBUG_PIXEL},
235 {"mem", DEBUG_MEMORY},
236 {"allmsg", ~DEBUG_SYNC}, /* avoid the term "sync" because the parser uses strstr */
237 {NULL, 0}
238 };
239 #endif /* RADEON_DEBUG */
240
241 #endif /* RADEON_COMMON && defined(RADEON_COMMON_FOR_R300) */
242
243 extern const struct dri_extension card_extensions[];
244 extern const struct dri_extension mm_extensions[];
245
246 static int getSwapInfo( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo );
247
248 static int
249 radeonGetParam(int fd, int param, void *value)
250 {
251 int ret;
252 drm_radeon_getparam_t gp;
253
254 gp.param = param;
255 gp.value = value;
256
257 ret = drmCommandWriteRead( fd, DRM_RADEON_GETPARAM, &gp, sizeof(gp));
258 return ret;
259 }
260
261 static const __DRIconfig **
262 radeonFillInModes( __DRIscreenPrivate *psp,
263 unsigned pixel_bits, unsigned depth_bits,
264 unsigned stencil_bits, GLboolean have_back_buffer )
265 {
266 __DRIconfig **configs;
267 __GLcontextModes *m;
268 unsigned depth_buffer_factor;
269 unsigned back_buffer_factor;
270 GLenum fb_format;
271 GLenum fb_type;
272 int i;
273
274 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
275 * enough to add support. Basically, if a context is created with an
276 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
277 * will never be used.
278 */
279 static const GLenum back_buffer_modes[] = {
280 GLX_NONE, GLX_SWAP_UNDEFINED_OML /*, GLX_SWAP_COPY_OML */
281 };
282
283 uint8_t depth_bits_array[2];
284 uint8_t stencil_bits_array[2];
285 uint8_t msaa_samples_array[1];
286
287 depth_bits_array[0] = depth_bits;
288 depth_bits_array[1] = depth_bits;
289
290 /* Just like with the accumulation buffer, always provide some modes
291 * with a stencil buffer. It will be a sw fallback, but some apps won't
292 * care about that.
293 */
294 stencil_bits_array[0] = 0;
295 stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits;
296
297 msaa_samples_array[0] = 0;
298
299 depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 2 : 1;
300 back_buffer_factor = (have_back_buffer) ? 2 : 1;
301
302 if ( pixel_bits == 16 ) {
303 fb_format = GL_RGB;
304 fb_type = GL_UNSIGNED_SHORT_5_6_5;
305 }
306 else {
307 fb_format = GL_BGRA;
308 fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
309 }
310
311 configs = driCreateConfigs(fb_format, fb_type,
312 depth_bits_array, stencil_bits_array,
313 depth_buffer_factor,
314 back_buffer_modes, back_buffer_factor,
315 msaa_samples_array, 1);
316 if (configs == NULL) {
317 fprintf( stderr, "[%s:%u] Error creating FBConfig!\n",
318 __func__, __LINE__ );
319 return NULL;
320 }
321
322 /* Mark the visual as slow if there are "fake" stencil bits.
323 */
324 for (i = 0; configs[i]; i++) {
325 m = &configs[i]->modes;
326 if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) {
327 m->visualRating = GLX_SLOW_CONFIG;
328 }
329 }
330
331 return (const __DRIconfig **) configs;
332 }
333
334 #if !RADEON_COMMON
335 static const __DRItexOffsetExtension radeonTexOffsetExtension = {
336 { __DRI_TEX_OFFSET, __DRI_TEX_OFFSET_VERSION },
337 radeonSetTexOffset,
338 };
339
340 static const __DRItexBufferExtension radeonTexBufferExtension = {
341 { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
342 radeonSetTexBuffer,
343 radeonSetTexBuffer2,
344 };
345 #endif
346
347 #if RADEON_COMMON && defined(RADEON_COMMON_FOR_R200)
348 static const __DRIallocateExtension r200AllocateExtension = {
349 { __DRI_ALLOCATE, __DRI_ALLOCATE_VERSION },
350 r200AllocateMemoryMESA,
351 r200FreeMemoryMESA,
352 r200GetMemoryOffsetMESA
353 };
354
355 static const __DRItexOffsetExtension r200texOffsetExtension = {
356 { __DRI_TEX_OFFSET, __DRI_TEX_OFFSET_VERSION },
357 r200SetTexOffset,
358 };
359
360 static const __DRItexBufferExtension r200TexBufferExtension = {
361 { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
362 r200SetTexBuffer,
363 r200SetTexBuffer2,
364 };
365 #endif
366
367 #if RADEON_COMMON && defined(RADEON_COMMON_FOR_R300)
368 static const __DRItexOffsetExtension r300texOffsetExtension = {
369 { __DRI_TEX_OFFSET, __DRI_TEX_OFFSET_VERSION },
370 r300SetTexOffset,
371 };
372
373 static const __DRItexBufferExtension r300TexBufferExtension = {
374 { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
375 r300SetTexBuffer,
376 r300SetTexBuffer2,
377 };
378 #endif
379
380 static int radeon_set_screen_flags(radeonScreenPtr screen, int device_id)
381 {
382 screen->chip_flags = 0;
383 switch ( device_id ) {
384 case PCI_CHIP_RADEON_LY:
385 case PCI_CHIP_RADEON_LZ:
386 case PCI_CHIP_RADEON_QY:
387 case PCI_CHIP_RADEON_QZ:
388 case PCI_CHIP_RN50_515E:
389 case PCI_CHIP_RN50_5969:
390 screen->chip_family = CHIP_FAMILY_RV100;
391 break;
392
393 case PCI_CHIP_RS100_4136:
394 case PCI_CHIP_RS100_4336:
395 screen->chip_family = CHIP_FAMILY_RS100;
396 break;
397
398 case PCI_CHIP_RS200_4137:
399 case PCI_CHIP_RS200_4337:
400 case PCI_CHIP_RS250_4237:
401 case PCI_CHIP_RS250_4437:
402 screen->chip_family = CHIP_FAMILY_RS200;
403 break;
404
405 case PCI_CHIP_RADEON_QD:
406 case PCI_CHIP_RADEON_QE:
407 case PCI_CHIP_RADEON_QF:
408 case PCI_CHIP_RADEON_QG:
409 /* all original radeons (7200) presumably have a stencil op bug */
410 screen->chip_family = CHIP_FAMILY_R100;
411 screen->chip_flags = RADEON_CHIPSET_TCL | RADEON_CHIPSET_BROKEN_STENCIL;
412 break;
413
414 case PCI_CHIP_RV200_QW:
415 case PCI_CHIP_RV200_QX:
416 case PCI_CHIP_RADEON_LW:
417 case PCI_CHIP_RADEON_LX:
418 screen->chip_family = CHIP_FAMILY_RV200;
419 screen->chip_flags = RADEON_CHIPSET_TCL;
420 break;
421
422 case PCI_CHIP_R200_BB:
423 case PCI_CHIP_R200_BC:
424 case PCI_CHIP_R200_QH:
425 case PCI_CHIP_R200_QL:
426 case PCI_CHIP_R200_QM:
427 screen->chip_family = CHIP_FAMILY_R200;
428 screen->chip_flags = RADEON_CHIPSET_TCL;
429 break;
430
431 case PCI_CHIP_RV250_If:
432 case PCI_CHIP_RV250_Ig:
433 case PCI_CHIP_RV250_Ld:
434 case PCI_CHIP_RV250_Lf:
435 case PCI_CHIP_RV250_Lg:
436 screen->chip_family = CHIP_FAMILY_RV250;
437 screen->chip_flags = R200_CHIPSET_YCBCR_BROKEN | RADEON_CHIPSET_TCL;
438 break;
439
440 case PCI_CHIP_RV280_5960:
441 case PCI_CHIP_RV280_5961:
442 case PCI_CHIP_RV280_5962:
443 case PCI_CHIP_RV280_5964:
444 case PCI_CHIP_RV280_5965:
445 case PCI_CHIP_RV280_5C61:
446 case PCI_CHIP_RV280_5C63:
447 screen->chip_family = CHIP_FAMILY_RV280;
448 screen->chip_flags = RADEON_CHIPSET_TCL;
449 break;
450
451 case PCI_CHIP_RS300_5834:
452 case PCI_CHIP_RS300_5835:
453 case PCI_CHIP_RS350_7834:
454 case PCI_CHIP_RS350_7835:
455 screen->chip_family = CHIP_FAMILY_RS300;
456 break;
457
458 /* 9500 with 1 pipe verified by: Reid Linnemann <lreid@cs.okstate.edu> */
459 case PCI_CHIP_R300_AD:
460 screen->chip_family = CHIP_FAMILY_RV350;
461 screen->chip_flags = RADEON_CHIPSET_TCL;
462 break;
463 case PCI_CHIP_R300_AE:
464 case PCI_CHIP_R300_AF:
465 case PCI_CHIP_R300_AG:
466 case PCI_CHIP_R300_ND:
467 case PCI_CHIP_R300_NE:
468 case PCI_CHIP_R300_NF:
469 case PCI_CHIP_R300_NG:
470 screen->chip_family = CHIP_FAMILY_R300;
471 screen->chip_flags = RADEON_CHIPSET_TCL;
472 break;
473
474 case PCI_CHIP_RV350_AP:
475 case PCI_CHIP_RV350_AQ:
476 case PCI_CHIP_RV350_AR:
477 case PCI_CHIP_RV350_AS:
478 case PCI_CHIP_RV350_AT:
479 case PCI_CHIP_RV350_AV:
480 case PCI_CHIP_RV350_AU:
481 case PCI_CHIP_RV350_NP:
482 case PCI_CHIP_RV350_NQ:
483 case PCI_CHIP_RV350_NR:
484 case PCI_CHIP_RV350_NS:
485 case PCI_CHIP_RV350_NT:
486 case PCI_CHIP_RV350_NV:
487 screen->chip_family = CHIP_FAMILY_RV350;
488 screen->chip_flags = RADEON_CHIPSET_TCL;
489 break;
490
491 case PCI_CHIP_R350_AH:
492 case PCI_CHIP_R350_AI:
493 case PCI_CHIP_R350_AJ:
494 case PCI_CHIP_R350_AK:
495 case PCI_CHIP_R350_NH:
496 case PCI_CHIP_R350_NI:
497 case PCI_CHIP_R360_NJ:
498 case PCI_CHIP_R350_NK:
499 screen->chip_family = CHIP_FAMILY_R350;
500 screen->chip_flags = RADEON_CHIPSET_TCL;
501 break;
502
503 case PCI_CHIP_RV370_5460:
504 case PCI_CHIP_RV370_5462:
505 case PCI_CHIP_RV370_5464:
506 case PCI_CHIP_RV370_5B60:
507 case PCI_CHIP_RV370_5B62:
508 case PCI_CHIP_RV370_5B63:
509 case PCI_CHIP_RV370_5B64:
510 case PCI_CHIP_RV370_5B65:
511 case PCI_CHIP_RV380_3150:
512 case PCI_CHIP_RV380_3152:
513 case PCI_CHIP_RV380_3154:
514 case PCI_CHIP_RV380_3E50:
515 case PCI_CHIP_RV380_3E54:
516 screen->chip_family = CHIP_FAMILY_RV380;
517 screen->chip_flags = RADEON_CHIPSET_TCL;
518 break;
519
520 case PCI_CHIP_R420_JN:
521 case PCI_CHIP_R420_JH:
522 case PCI_CHIP_R420_JI:
523 case PCI_CHIP_R420_JJ:
524 case PCI_CHIP_R420_JK:
525 case PCI_CHIP_R420_JL:
526 case PCI_CHIP_R420_JM:
527 case PCI_CHIP_R420_JO:
528 case PCI_CHIP_R420_JP:
529 case PCI_CHIP_R420_JT:
530 case PCI_CHIP_R481_4B49:
531 case PCI_CHIP_R481_4B4A:
532 case PCI_CHIP_R481_4B4B:
533 case PCI_CHIP_R481_4B4C:
534 case PCI_CHIP_R423_UH:
535 case PCI_CHIP_R423_UI:
536 case PCI_CHIP_R423_UJ:
537 case PCI_CHIP_R423_UK:
538 case PCI_CHIP_R430_554C:
539 case PCI_CHIP_R430_554D:
540 case PCI_CHIP_R430_554E:
541 case PCI_CHIP_R430_554F:
542 case PCI_CHIP_R423_5550:
543 case PCI_CHIP_R423_UQ:
544 case PCI_CHIP_R423_UR:
545 case PCI_CHIP_R423_UT:
546 case PCI_CHIP_R430_5D48:
547 case PCI_CHIP_R430_5D49:
548 case PCI_CHIP_R430_5D4A:
549 case PCI_CHIP_R480_5D4C:
550 case PCI_CHIP_R480_5D4D:
551 case PCI_CHIP_R480_5D4E:
552 case PCI_CHIP_R480_5D4F:
553 case PCI_CHIP_R480_5D50:
554 case PCI_CHIP_R480_5D52:
555 case PCI_CHIP_R423_5D57:
556 screen->chip_family = CHIP_FAMILY_R420;
557 screen->chip_flags = RADEON_CHIPSET_TCL;
558 break;
559
560 case PCI_CHIP_RV410_5E4C:
561 case PCI_CHIP_RV410_5E4F:
562 case PCI_CHIP_RV410_564A:
563 case PCI_CHIP_RV410_564B:
564 case PCI_CHIP_RV410_564F:
565 case PCI_CHIP_RV410_5652:
566 case PCI_CHIP_RV410_5653:
567 case PCI_CHIP_RV410_5657:
568 case PCI_CHIP_RV410_5E48:
569 case PCI_CHIP_RV410_5E4A:
570 case PCI_CHIP_RV410_5E4B:
571 case PCI_CHIP_RV410_5E4D:
572 screen->chip_family = CHIP_FAMILY_RV410;
573 screen->chip_flags = RADEON_CHIPSET_TCL;
574 break;
575
576 case PCI_CHIP_RS480_5954:
577 case PCI_CHIP_RS480_5955:
578 case PCI_CHIP_RS482_5974:
579 case PCI_CHIP_RS482_5975:
580 case PCI_CHIP_RS400_5A41:
581 case PCI_CHIP_RS400_5A42:
582 case PCI_CHIP_RC410_5A61:
583 case PCI_CHIP_RC410_5A62:
584 screen->chip_family = CHIP_FAMILY_RS400;
585 break;
586
587 case PCI_CHIP_RS600_793F:
588 case PCI_CHIP_RS600_7941:
589 case PCI_CHIP_RS600_7942:
590 screen->chip_family = CHIP_FAMILY_RS600;
591 break;
592
593 case PCI_CHIP_RS690_791E:
594 case PCI_CHIP_RS690_791F:
595 screen->chip_family = CHIP_FAMILY_RS690;
596 break;
597 case PCI_CHIP_RS740_796C:
598 case PCI_CHIP_RS740_796D:
599 case PCI_CHIP_RS740_796E:
600 case PCI_CHIP_RS740_796F:
601 screen->chip_family = CHIP_FAMILY_RS740;
602 break;
603
604 case PCI_CHIP_R520_7100:
605 case PCI_CHIP_R520_7101:
606 case PCI_CHIP_R520_7102:
607 case PCI_CHIP_R520_7103:
608 case PCI_CHIP_R520_7104:
609 case PCI_CHIP_R520_7105:
610 case PCI_CHIP_R520_7106:
611 case PCI_CHIP_R520_7108:
612 case PCI_CHIP_R520_7109:
613 case PCI_CHIP_R520_710A:
614 case PCI_CHIP_R520_710B:
615 case PCI_CHIP_R520_710C:
616 case PCI_CHIP_R520_710E:
617 case PCI_CHIP_R520_710F:
618 screen->chip_family = CHIP_FAMILY_R520;
619 screen->chip_flags = RADEON_CHIPSET_TCL;
620 break;
621
622 case PCI_CHIP_RV515_7140:
623 case PCI_CHIP_RV515_7141:
624 case PCI_CHIP_RV515_7142:
625 case PCI_CHIP_RV515_7143:
626 case PCI_CHIP_RV515_7144:
627 case PCI_CHIP_RV515_7145:
628 case PCI_CHIP_RV515_7146:
629 case PCI_CHIP_RV515_7147:
630 case PCI_CHIP_RV515_7149:
631 case PCI_CHIP_RV515_714A:
632 case PCI_CHIP_RV515_714B:
633 case PCI_CHIP_RV515_714C:
634 case PCI_CHIP_RV515_714D:
635 case PCI_CHIP_RV515_714E:
636 case PCI_CHIP_RV515_714F:
637 case PCI_CHIP_RV515_7151:
638 case PCI_CHIP_RV515_7152:
639 case PCI_CHIP_RV515_7153:
640 case PCI_CHIP_RV515_715E:
641 case PCI_CHIP_RV515_715F:
642 case PCI_CHIP_RV515_7180:
643 case PCI_CHIP_RV515_7181:
644 case PCI_CHIP_RV515_7183:
645 case PCI_CHIP_RV515_7186:
646 case PCI_CHIP_RV515_7187:
647 case PCI_CHIP_RV515_7188:
648 case PCI_CHIP_RV515_718A:
649 case PCI_CHIP_RV515_718B:
650 case PCI_CHIP_RV515_718C:
651 case PCI_CHIP_RV515_718D:
652 case PCI_CHIP_RV515_718F:
653 case PCI_CHIP_RV515_7193:
654 case PCI_CHIP_RV515_7196:
655 case PCI_CHIP_RV515_719B:
656 case PCI_CHIP_RV515_719F:
657 case PCI_CHIP_RV515_7200:
658 case PCI_CHIP_RV515_7210:
659 case PCI_CHIP_RV515_7211:
660 screen->chip_family = CHIP_FAMILY_RV515;
661 screen->chip_flags = RADEON_CHIPSET_TCL;
662 break;
663
664 case PCI_CHIP_RV530_71C0:
665 case PCI_CHIP_RV530_71C1:
666 case PCI_CHIP_RV530_71C2:
667 case PCI_CHIP_RV530_71C3:
668 case PCI_CHIP_RV530_71C4:
669 case PCI_CHIP_RV530_71C5:
670 case PCI_CHIP_RV530_71C6:
671 case PCI_CHIP_RV530_71C7:
672 case PCI_CHIP_RV530_71CD:
673 case PCI_CHIP_RV530_71CE:
674 case PCI_CHIP_RV530_71D2:
675 case PCI_CHIP_RV530_71D4:
676 case PCI_CHIP_RV530_71D5:
677 case PCI_CHIP_RV530_71D6:
678 case PCI_CHIP_RV530_71DA:
679 case PCI_CHIP_RV530_71DE:
680 screen->chip_family = CHIP_FAMILY_RV530;
681 screen->chip_flags = RADEON_CHIPSET_TCL;
682 break;
683
684 case PCI_CHIP_R580_7240:
685 case PCI_CHIP_R580_7243:
686 case PCI_CHIP_R580_7244:
687 case PCI_CHIP_R580_7245:
688 case PCI_CHIP_R580_7246:
689 case PCI_CHIP_R580_7247:
690 case PCI_CHIP_R580_7248:
691 case PCI_CHIP_R580_7249:
692 case PCI_CHIP_R580_724A:
693 case PCI_CHIP_R580_724B:
694 case PCI_CHIP_R580_724C:
695 case PCI_CHIP_R580_724D:
696 case PCI_CHIP_R580_724E:
697 case PCI_CHIP_R580_724F:
698 case PCI_CHIP_R580_7284:
699 screen->chip_family = CHIP_FAMILY_R580;
700 screen->chip_flags = RADEON_CHIPSET_TCL;
701 break;
702
703 case PCI_CHIP_RV570_7280:
704 case PCI_CHIP_RV560_7281:
705 case PCI_CHIP_RV560_7283:
706 case PCI_CHIP_RV560_7287:
707 case PCI_CHIP_RV570_7288:
708 case PCI_CHIP_RV570_7289:
709 case PCI_CHIP_RV570_728B:
710 case PCI_CHIP_RV570_728C:
711 case PCI_CHIP_RV560_7290:
712 case PCI_CHIP_RV560_7291:
713 case PCI_CHIP_RV560_7293:
714 case PCI_CHIP_RV560_7297:
715 screen->chip_family = CHIP_FAMILY_RV560;
716 screen->chip_flags = RADEON_CHIPSET_TCL;
717 break;
718
719 default:
720 fprintf(stderr, "unknown chip id 0x%x, can't guess.\n",
721 device_id);
722 return -1;
723 }
724
725 return 0;
726 }
727
728
729 /* Create the device specific screen private data struct.
730 */
731 static radeonScreenPtr
732 radeonCreateScreen( __DRIscreenPrivate *sPriv )
733 {
734 radeonScreenPtr screen;
735 RADEONDRIPtr dri_priv = (RADEONDRIPtr)sPriv->pDevPriv;
736 unsigned char *RADEONMMIO = NULL;
737 int i;
738 int ret;
739 uint32_t temp = 0;
740
741 if (sPriv->devPrivSize != sizeof(RADEONDRIRec)) {
742 fprintf(stderr,"\nERROR! sizeof(RADEONDRIRec) does not match passed size from device driver\n");
743 return GL_FALSE;
744 }
745
746 /* Allocate the private area */
747 screen = (radeonScreenPtr) CALLOC( sizeof(*screen) );
748 if ( !screen ) {
749 __driUtilMessage("%s: Could not allocate memory for screen structure",
750 __FUNCTION__);
751 return NULL;
752 }
753
754 #if DO_DEBUG && RADEON_COMMON && defined(RADEON_COMMON_FOR_R300)
755 RADEON_DEBUG = driParseDebugString(getenv("RADEON_DEBUG"), debug_control);
756 #endif
757
758 /* parse information in __driConfigOptions */
759 driParseOptionInfo (&screen->optionCache,
760 __driConfigOptions, __driNConfigOptions);
761
762 /* This is first since which regions we map depends on whether or
763 * not we are using a PCI card.
764 */
765 screen->card_type = (dri_priv->IsPCI ? RADEON_CARD_PCI : RADEON_CARD_AGP);
766 {
767 int ret;
768
769 #ifdef RADEON_PARAM_KERNEL_MM
770 ret = radeonGetParam( sPriv->fd, RADEON_PARAM_KERNEL_MM,
771 &screen->kernel_mm);
772
773 if (ret && ret != -EINVAL) {
774 FREE( screen );
775 fprintf(stderr, "drm_radeon_getparam_t (RADEON_OFFSET): %d\n", ret);
776 return NULL;
777 }
778
779 if (ret == -EINVAL)
780 screen->kernel_mm = 0;
781 #endif
782
783 ret = radeonGetParam( sPriv->fd, RADEON_PARAM_GART_BUFFER_OFFSET,
784 &screen->gart_buffer_offset);
785
786 if (ret) {
787 FREE( screen );
788 fprintf(stderr, "drm_radeon_getparam_t (RADEON_PARAM_GART_BUFFER_OFFSET): %d\n", ret);
789 return NULL;
790 }
791
792 ret = radeonGetParam( sPriv->fd, RADEON_PARAM_GART_BASE,
793 &screen->gart_base);
794 if (ret) {
795 FREE( screen );
796 fprintf(stderr, "drm_radeon_getparam_t (RADEON_PARAM_GART_BASE): %d\n", ret);
797 return NULL;
798 }
799
800 ret = radeonGetParam( sPriv->fd, RADEON_PARAM_IRQ_NR,
801 &screen->irq);
802 if (ret) {
803 FREE( screen );
804 fprintf(stderr, "drm_radeon_getparam_t (RADEON_PARAM_IRQ_NR): %d\n", ret);
805 return NULL;
806 }
807 screen->drmSupportsCubeMapsR200 = (sPriv->drm_version.minor >= 7);
808 screen->drmSupportsBlendColor = (sPriv->drm_version.minor >= 11);
809 screen->drmSupportsTriPerf = (sPriv->drm_version.minor >= 16);
810 screen->drmSupportsFragShader = (sPriv->drm_version.minor >= 18);
811 screen->drmSupportsPointSprites = (sPriv->drm_version.minor >= 13);
812 screen->drmSupportsCubeMapsR100 = (sPriv->drm_version.minor >= 15);
813 screen->drmSupportsVertexProgram = (sPriv->drm_version.minor >= 25);
814 }
815
816 if (!screen->kernel_mm) {
817 screen->mmio.handle = dri_priv->registerHandle;
818 screen->mmio.size = dri_priv->registerSize;
819 if ( drmMap( sPriv->fd,
820 screen->mmio.handle,
821 screen->mmio.size,
822 &screen->mmio.map ) ) {
823 FREE( screen );
824 __driUtilMessage("%s: drmMap failed\n", __FUNCTION__ );
825 return NULL;
826 }
827
828 RADEONMMIO = screen->mmio.map;
829
830 screen->status.handle = dri_priv->statusHandle;
831 screen->status.size = dri_priv->statusSize;
832 if ( drmMap( sPriv->fd,
833 screen->status.handle,
834 screen->status.size,
835 &screen->status.map ) ) {
836 drmUnmap( screen->mmio.map, screen->mmio.size );
837 FREE( screen );
838 __driUtilMessage("%s: drmMap (2) failed\n", __FUNCTION__ );
839 return NULL;
840 }
841 screen->scratch = (__volatile__ uint32_t *)
842 ((GLubyte *)screen->status.map + RADEON_SCRATCH_REG_OFFSET);
843
844 screen->buffers = drmMapBufs( sPriv->fd );
845 if ( !screen->buffers ) {
846 drmUnmap( screen->status.map, screen->status.size );
847 drmUnmap( screen->mmio.map, screen->mmio.size );
848 FREE( screen );
849 __driUtilMessage("%s: drmMapBufs failed\n", __FUNCTION__ );
850 return NULL;
851 }
852
853 if ( dri_priv->gartTexHandle && dri_priv->gartTexMapSize ) {
854 screen->gartTextures.handle = dri_priv->gartTexHandle;
855 screen->gartTextures.size = dri_priv->gartTexMapSize;
856 if ( drmMap( sPriv->fd,
857 screen->gartTextures.handle,
858 screen->gartTextures.size,
859 (drmAddressPtr)&screen->gartTextures.map ) ) {
860 drmUnmapBufs( screen->buffers );
861 drmUnmap( screen->status.map, screen->status.size );
862 drmUnmap( screen->mmio.map, screen->mmio.size );
863 FREE( screen );
864 __driUtilMessage("%s: drmMap failed for GART texture area\n", __FUNCTION__);
865 return NULL;
866 }
867
868 screen->gart_texture_offset = dri_priv->gartTexOffset + screen->gart_base;
869 }
870 }
871
872
873 ret = radeon_set_screen_flags(screen, dri_priv->deviceID);
874 if (ret == -1)
875 return NULL;
876
877 if ((screen->chip_family == CHIP_FAMILY_R350 || screen->chip_family == CHIP_FAMILY_R300) &&
878 sPriv->ddx_version.minor < 2) {
879 fprintf(stderr, "xf86-video-ati-6.6.2 or newer needed for Radeon 9500/9700/9800 cards.\n");
880 return NULL;
881 }
882
883 if ((sPriv->drm_version.minor < 29) && (screen->chip_family >= CHIP_FAMILY_RV515)) {
884 fprintf(stderr, "R500 support requires a newer drm.\n");
885 return NULL;
886 }
887
888 if (getenv("R300_NO_TCL"))
889 screen->chip_flags &= ~RADEON_CHIPSET_TCL;
890
891 if (screen->chip_family <= CHIP_FAMILY_RS200)
892 screen->chip_flags |= RADEON_CLASS_R100;
893 else if (screen->chip_family <= CHIP_FAMILY_RV280)
894 screen->chip_flags |= RADEON_CLASS_R200;
895 else
896 screen->chip_flags |= RADEON_CLASS_R300;
897
898 screen->cpp = dri_priv->bpp / 8;
899 screen->AGPMode = dri_priv->AGPMode;
900
901 ret = radeonGetParam( sPriv->fd, RADEON_PARAM_FB_LOCATION,
902 &temp);
903 if (ret) {
904 if (screen->chip_family < CHIP_FAMILY_RS600 && !screen->kernel_mm)
905 screen->fbLocation = ( INREG( RADEON_MC_FB_LOCATION ) & 0xffff) << 16;
906 else {
907 FREE( screen );
908 fprintf(stderr, "Unable to get fb location need newer drm\n");
909 return NULL;
910 }
911 } else {
912 screen->fbLocation = (temp & 0xffff) << 16;
913 }
914
915 if (screen->chip_family >= CHIP_FAMILY_R300) {
916 ret = radeonGetParam( sPriv->fd, RADEON_PARAM_NUM_GB_PIPES,
917 &temp);
918 if (ret) {
919 fprintf(stderr, "Unable to get num_pipes, need newer drm\n");
920 switch (screen->chip_family) {
921 case CHIP_FAMILY_R300:
922 case CHIP_FAMILY_R350:
923 screen->num_gb_pipes = 2;
924 break;
925 case CHIP_FAMILY_R420:
926 case CHIP_FAMILY_R520:
927 case CHIP_FAMILY_R580:
928 case CHIP_FAMILY_RV560:
929 case CHIP_FAMILY_RV570:
930 screen->num_gb_pipes = 4;
931 break;
932 case CHIP_FAMILY_RV350:
933 case CHIP_FAMILY_RV515:
934 case CHIP_FAMILY_RV530:
935 case CHIP_FAMILY_RV410:
936 default:
937 screen->num_gb_pipes = 1;
938 break;
939 }
940 } else {
941 screen->num_gb_pipes = temp;
942 }
943 }
944
945 if ( sPriv->drm_version.minor >= 10 ) {
946 drm_radeon_setparam_t sp;
947
948 sp.param = RADEON_SETPARAM_FB_LOCATION;
949 sp.value = screen->fbLocation;
950
951 drmCommandWrite( sPriv->fd, DRM_RADEON_SETPARAM,
952 &sp, sizeof( sp ) );
953 }
954
955 screen->frontOffset = dri_priv->frontOffset;
956 screen->frontPitch = dri_priv->frontPitch;
957 screen->backOffset = dri_priv->backOffset;
958 screen->backPitch = dri_priv->backPitch;
959 screen->depthOffset = dri_priv->depthOffset;
960 screen->depthPitch = dri_priv->depthPitch;
961
962 /* Check if ddx has set up a surface reg to cover depth buffer */
963 screen->depthHasSurface = (sPriv->ddx_version.major > 4) ||
964 /* these chips don't use tiled z without hyperz. So always pretend
965 we have set up a surface which will cause linear reads/writes */
966 (IS_R100_CLASS(screen) &&
967 !(screen->chip_flags & RADEON_CHIPSET_TCL));
968
969 if ( dri_priv->textureSize == 0 ) {
970 screen->texOffset[RADEON_LOCAL_TEX_HEAP] = screen->gart_texture_offset;
971 screen->texSize[RADEON_LOCAL_TEX_HEAP] = dri_priv->gartTexMapSize;
972 screen->logTexGranularity[RADEON_LOCAL_TEX_HEAP] =
973 dri_priv->log2GARTTexGran;
974 } else {
975 screen->texOffset[RADEON_LOCAL_TEX_HEAP] = dri_priv->textureOffset
976 + screen->fbLocation;
977 screen->texSize[RADEON_LOCAL_TEX_HEAP] = dri_priv->textureSize;
978 screen->logTexGranularity[RADEON_LOCAL_TEX_HEAP] =
979 dri_priv->log2TexGran;
980 }
981
982 if ( !screen->gartTextures.map || dri_priv->textureSize == 0
983 || getenv( "RADEON_GARTTEXTURING_FORCE_DISABLE" ) ) {
984 screen->numTexHeaps = RADEON_NR_TEX_HEAPS - 1;
985 screen->texOffset[RADEON_GART_TEX_HEAP] = 0;
986 screen->texSize[RADEON_GART_TEX_HEAP] = 0;
987 screen->logTexGranularity[RADEON_GART_TEX_HEAP] = 0;
988 } else {
989 screen->numTexHeaps = RADEON_NR_TEX_HEAPS;
990 screen->texOffset[RADEON_GART_TEX_HEAP] = screen->gart_texture_offset;
991 screen->texSize[RADEON_GART_TEX_HEAP] = dri_priv->gartTexMapSize;
992 screen->logTexGranularity[RADEON_GART_TEX_HEAP] =
993 dri_priv->log2GARTTexGran;
994 }
995
996 i = 0;
997 screen->extensions[i++] = &driCopySubBufferExtension.base;
998 screen->extensions[i++] = &driFrameTrackingExtension.base;
999 screen->extensions[i++] = &driReadDrawableExtension;
1000
1001 if ( screen->irq != 0 ) {
1002 screen->extensions[i++] = &driSwapControlExtension.base;
1003 screen->extensions[i++] = &driMediaStreamCounterExtension.base;
1004 }
1005
1006 if (!screen->kernel_mm) {
1007 #if !RADEON_COMMON
1008 screen->extensions[i++] = &radeonTexOffsetExtension.base;
1009 #endif
1010
1011 #if RADEON_COMMON && defined(RADEON_COMMON_FOR_R200)
1012 if (IS_R200_CLASS(screen))
1013 screen->extensions[i++] = &r200AllocateExtension.base;
1014
1015 screen->extensions[i++] = &r200texOffsetExtension.base;
1016 #endif
1017
1018 #if RADEON_COMMON && defined(RADEON_COMMON_FOR_R300)
1019 screen->extensions[i++] = &r300texOffsetExtension.base;
1020 #endif
1021 }
1022
1023 screen->extensions[i++] = NULL;
1024 sPriv->extensions = screen->extensions;
1025
1026 screen->driScreen = sPriv;
1027 screen->sarea_priv_offset = dri_priv->sarea_priv_offset;
1028 screen->sarea = (drm_radeon_sarea_t *) ((GLubyte *) sPriv->pSAREA +
1029 screen->sarea_priv_offset);
1030
1031 if (screen->kernel_mm)
1032 screen->bom = radeon_bo_manager_gem_ctor(sPriv->fd);
1033 else
1034 screen->bom = radeon_bo_manager_legacy_ctor(screen);
1035 if (screen->bom == NULL) {
1036 free(screen);
1037 return NULL;
1038 }
1039
1040 return screen;
1041 }
1042
1043 static radeonScreenPtr
1044 radeonCreateScreen2(__DRIscreenPrivate *sPriv)
1045 {
1046 radeonScreenPtr screen;
1047 int i;
1048 int ret;
1049 uint32_t device_id;
1050
1051 /* Allocate the private area */
1052 screen = (radeonScreenPtr) CALLOC( sizeof(*screen) );
1053 if ( !screen ) {
1054 __driUtilMessage("%s: Could not allocate memory for screen structure",
1055 __FUNCTION__);
1056 fprintf(stderr, "leaving here\n");
1057 return NULL;
1058 }
1059
1060 #if DO_DEBUG && RADEON_COMMON && defined(RADEON_COMMON_FOR_R300)
1061 RADEON_DEBUG = driParseDebugString(getenv("RADEON_DEBUG"), debug_control);
1062 #endif
1063
1064 /* parse information in __driConfigOptions */
1065 driParseOptionInfo (&screen->optionCache,
1066 __driConfigOptions, __driNConfigOptions);
1067
1068 screen->kernel_mm = 1;
1069 screen->chip_flags = 0;
1070
1071 ret = radeonGetParam( sPriv->fd, RADEON_PARAM_IRQ_NR,
1072 &screen->irq);
1073
1074 ret = radeonGetParam( sPriv->fd, RADEON_PARAM_DEVICE_ID,
1075 &device_id);
1076 if (ret) {
1077 FREE( screen );
1078 fprintf(stderr, "drm_radeon_getparam_t (RADEON_PARAM_DEVICE_ID): %d\n", ret);
1079 return NULL;
1080 }
1081
1082 ret = radeon_set_screen_flags(screen, device_id);
1083 if (ret == -1)
1084 return NULL;
1085
1086 if (screen->chip_family <= CHIP_FAMILY_RS200)
1087 screen->chip_flags |= RADEON_CLASS_R100;
1088 else if (screen->chip_family <= CHIP_FAMILY_RV280)
1089 screen->chip_flags |= RADEON_CLASS_R200;
1090 else
1091 screen->chip_flags |= RADEON_CLASS_R300;
1092
1093 if (getenv("R300_NO_TCL"))
1094 screen->chip_flags &= ~RADEON_CHIPSET_TCL;
1095
1096 i = 0;
1097 screen->extensions[i++] = &driCopySubBufferExtension.base;
1098 screen->extensions[i++] = &driFrameTrackingExtension.base;
1099 screen->extensions[i++] = &driReadDrawableExtension;
1100
1101 if ( screen->irq != 0 ) {
1102 screen->extensions[i++] = &driSwapControlExtension.base;
1103 screen->extensions[i++] = &driMediaStreamCounterExtension.base;
1104 }
1105
1106 #if !RADEON_COMMON
1107 screen->extensions[i++] = &radeonTexBufferExtension.base;
1108 #endif
1109
1110 #if RADEON_COMMON && defined(RADEON_COMMON_FOR_R200)
1111 if (IS_R200_CLASS(screen))
1112 screen->extensions[i++] = &r200AllocateExtension.base;
1113
1114 screen->extensions[i++] = &r200TexBufferExtension.base;
1115 #endif
1116
1117 #if RADEON_COMMON && defined(RADEON_COMMON_FOR_R300)
1118 screen->extensions[i++] = &r300TexBufferExtension.base;
1119 #endif
1120
1121 screen->extensions[i++] = NULL;
1122 sPriv->extensions = screen->extensions;
1123
1124 screen->driScreen = sPriv;
1125 screen->bom = radeon_bo_manager_gem_ctor(sPriv->fd);
1126 if (screen->bom == NULL) {
1127 free(screen);
1128 return NULL;
1129 }
1130 return screen;
1131 }
1132
1133 /* Destroy the device specific screen private data struct.
1134 */
1135 static void
1136 radeonDestroyScreen( __DRIscreenPrivate *sPriv )
1137 {
1138 radeonScreenPtr screen = (radeonScreenPtr)sPriv->private;
1139
1140 if (!screen)
1141 return;
1142
1143 if (screen->kernel_mm) {
1144 #ifdef RADEON_BO_TRACK
1145 radeon_tracker_print(&screen->bom->tracker, stderr);
1146 #endif
1147 radeon_bo_manager_gem_dtor(screen->bom);
1148 } else {
1149 radeon_bo_manager_legacy_dtor(screen->bom);
1150
1151 if ( screen->gartTextures.map ) {
1152 drmUnmap( screen->gartTextures.map, screen->gartTextures.size );
1153 }
1154 drmUnmapBufs( screen->buffers );
1155 drmUnmap( screen->status.map, screen->status.size );
1156 drmUnmap( screen->mmio.map, screen->mmio.size );
1157 }
1158
1159 /* free all option information */
1160 driDestroyOptionInfo (&screen->optionCache);
1161
1162 FREE( screen );
1163 sPriv->private = NULL;
1164 }
1165
1166
1167 /* Initialize the driver specific screen private data.
1168 */
1169 static GLboolean
1170 radeonInitDriver( __DRIscreenPrivate *sPriv )
1171 {
1172 if (sPriv->dri2.enabled) {
1173 sPriv->private = (void *) radeonCreateScreen2( sPriv );
1174 } else {
1175 sPriv->private = (void *) radeonCreateScreen( sPriv );
1176 }
1177 if ( !sPriv->private ) {
1178 radeonDestroyScreen( sPriv );
1179 return GL_FALSE;
1180 }
1181
1182 return GL_TRUE;
1183 }
1184
1185
1186
1187 /**
1188 * Create the Mesa framebuffer and renderbuffers for a given window/drawable.
1189 *
1190 * \todo This function (and its interface) will need to be updated to support
1191 * pbuffers.
1192 */
1193 static GLboolean
1194 radeonCreateBuffer( __DRIscreenPrivate *driScrnPriv,
1195 __DRIdrawablePrivate *driDrawPriv,
1196 const __GLcontextModes *mesaVis,
1197 GLboolean isPixmap )
1198 {
1199 radeonScreenPtr screen = (radeonScreenPtr) driScrnPriv->private;
1200
1201 const GLboolean swDepth = GL_FALSE;
1202 const GLboolean swAlpha = GL_FALSE;
1203 const GLboolean swAccum = mesaVis->accumRedBits > 0;
1204 const GLboolean swStencil = mesaVis->stencilBits > 0 &&
1205 mesaVis->depthBits != 24;
1206 GLenum rgbFormat = (mesaVis->redBits == 5 ? GL_RGB5 : GL_RGBA8);
1207 struct radeon_framebuffer *rfb;
1208
1209 if (isPixmap)
1210 return GL_FALSE; /* not implemented */
1211
1212 rfb = CALLOC_STRUCT(radeon_framebuffer);
1213 if (!rfb)
1214 return GL_FALSE;
1215
1216 _mesa_initialize_framebuffer(&rfb->base, mesaVis);
1217
1218 /* front color renderbuffer */
1219 rfb->color_rb[0] = radeon_create_renderbuffer(rgbFormat, driDrawPriv);
1220 _mesa_add_renderbuffer(&rfb->base, BUFFER_FRONT_LEFT, &rfb->color_rb[0]->base);
1221 rfb->color_rb[0]->has_surface = 1;
1222
1223 /* back color renderbuffer */
1224 if (mesaVis->doubleBufferMode) {
1225 rfb->color_rb[1] = radeon_create_renderbuffer(rgbFormat, driDrawPriv);
1226 _mesa_add_renderbuffer(&rfb->base, BUFFER_BACK_LEFT, &rfb->color_rb[1]->base);
1227 rfb->color_rb[1]->has_surface = 1;
1228 }
1229
1230 if (mesaVis->depthBits == 24) {
1231 if (mesaVis->stencilBits == 8) {
1232 struct radeon_renderbuffer *depthStencilRb = radeon_create_renderbuffer(GL_DEPTH24_STENCIL8_EXT, driDrawPriv);
1233 _mesa_add_renderbuffer(&rfb->base, BUFFER_DEPTH, &depthStencilRb->base);
1234 _mesa_add_renderbuffer(&rfb->base, BUFFER_STENCIL, &depthStencilRb->base);
1235 depthStencilRb->has_surface = screen->depthHasSurface;
1236 } else {
1237 /* depth renderbuffer */
1238 struct radeon_renderbuffer *depth = radeon_create_renderbuffer(GL_DEPTH_COMPONENT24, driDrawPriv);
1239 _mesa_add_renderbuffer(&rfb->base, BUFFER_DEPTH, &depth->base);
1240 depth->has_surface = screen->depthHasSurface;
1241 }
1242 } else if (mesaVis->depthBits == 16) {
1243 /* just 16-bit depth buffer, no hw stencil */
1244 struct radeon_renderbuffer *depth = radeon_create_renderbuffer(GL_DEPTH_COMPONENT16, driDrawPriv);
1245 _mesa_add_renderbuffer(&rfb->base, BUFFER_DEPTH, &depth->base);
1246 depth->has_surface = screen->depthHasSurface;
1247 }
1248
1249 _mesa_add_soft_renderbuffers(&rfb->base,
1250 GL_FALSE, /* color */
1251 swDepth,
1252 swStencil,
1253 swAccum,
1254 swAlpha,
1255 GL_FALSE /* aux */);
1256 driDrawPriv->driverPrivate = (void *) rfb;
1257
1258 return (driDrawPriv->driverPrivate != NULL);
1259 }
1260
1261 static void
1262 radeonDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
1263 {
1264 struct radeon_renderbuffer *rb;
1265 struct radeon_framebuffer *rfb;
1266
1267 rfb = (void*)driDrawPriv->driverPrivate;
1268 rb = (void *)rfb->base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
1269 if (rb && rb->bo) {
1270 radeon_bo_unref(rb->bo);
1271 rb->bo = NULL;
1272 }
1273 rb = (void *)rfb->base.Attachment[BUFFER_BACK_LEFT].Renderbuffer;
1274 if (rb && rb->bo) {
1275 radeon_bo_unref(rb->bo);
1276 rb->bo = NULL;
1277 }
1278 rb = (void *)rfb->base.Attachment[BUFFER_DEPTH].Renderbuffer;
1279 if (rb && rb->bo) {
1280 radeon_bo_unref(rb->bo);
1281 rb->bo = NULL;
1282 }
1283 _mesa_reference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)), NULL);
1284 }
1285
1286 #if RADEON_COMMON && defined(RADEON_COMMON_FOR_R300)
1287 /**
1288 * Choose the appropriate CreateContext function based on the chipset.
1289 * Eventually, all drivers will go through this process.
1290 */
1291 static GLboolean radeonCreateContext(const __GLcontextModes * glVisual,
1292 __DRIcontextPrivate * driContextPriv,
1293 void *sharedContextPriv)
1294 {
1295 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
1296 radeonScreenPtr screen = (radeonScreenPtr) (sPriv->private);
1297
1298 if (IS_R300_CLASS(screen))
1299 return r300CreateContext(glVisual, driContextPriv, sharedContextPriv);
1300 return GL_FALSE;
1301 }
1302
1303 /**
1304 * Choose the appropriate DestroyContext function based on the chipset.
1305 */
1306 static void radeonDestroyContext(__DRIcontextPrivate * driContextPriv)
1307 {
1308 radeonContextPtr radeon = (radeonContextPtr) driContextPriv->driverPrivate;
1309
1310 if (IS_R300_CLASS(radeon->radeonScreen))
1311 return r300DestroyContext(driContextPriv);
1312 }
1313
1314
1315 #endif
1316
1317
1318 /**
1319 * This is the driver specific part of the createNewScreen entry point.
1320 *
1321 * \todo maybe fold this into intelInitDriver
1322 *
1323 * \return the __GLcontextModes supported by this driver
1324 */
1325 static const __DRIconfig **
1326 radeonInitScreen(__DRIscreenPrivate *psp)
1327 {
1328 #if !RADEON_COMMON
1329 static const char *driver_name = "Radeon";
1330 static const __DRIutilversion2 ddx_expected = { 4, 5, 0, 0 };
1331 static const __DRIversion dri_expected = { 4, 0, 0 };
1332 static const __DRIversion drm_expected = { 1, 6, 0 };
1333 #elif RADEON_COMMON && defined(RADEON_COMMON_FOR_R200)
1334 static const char *driver_name = "R200";
1335 static const __DRIutilversion2 ddx_expected = { 4, 5, 0, 0 };
1336 static const __DRIversion dri_expected = { 4, 0, 0 };
1337 static const __DRIversion drm_expected = { 1, 6, 0 };
1338 #elif RADEON_COMMON && defined(RADEON_COMMON_FOR_R300)
1339 static const char *driver_name = "R300";
1340 static const __DRIutilversion2 ddx_expected = { 4, 5, 0, 0 };
1341 static const __DRIversion dri_expected = { 4, 0, 0 };
1342 static const __DRIversion drm_expected = { 1, 24, 0 };
1343 #endif
1344 RADEONDRIPtr dri_priv = (RADEONDRIPtr) psp->pDevPriv;
1345
1346 if ( ! driCheckDriDdxDrmVersions3( driver_name,
1347 &psp->dri_version, & dri_expected,
1348 &psp->ddx_version, & ddx_expected,
1349 &psp->drm_version, & drm_expected ) ) {
1350 return NULL;
1351 }
1352
1353 /* Calling driInitExtensions here, with a NULL context pointer,
1354 * does not actually enable the extensions. It just makes sure
1355 * that all the dispatch offsets for all the extensions that
1356 * *might* be enables are known. This is needed because the
1357 * dispatch offsets need to be known when _mesa_context_create
1358 * is called, but we can't enable the extensions until we have a
1359 * context pointer.
1360 *
1361 * Hello chicken. Hello egg. How are you two today?
1362 */
1363 driInitExtensions( NULL, card_extensions, GL_FALSE );
1364 #if RADEON_COMMON && defined(RADEON_COMMON_FOR_R200)
1365 driInitExtensions( NULL, blend_extensions, GL_FALSE );
1366 driInitSingleExtension( NULL, ARB_vp_extension );
1367 driInitSingleExtension( NULL, NV_vp_extension );
1368 driInitSingleExtension( NULL, ATI_fs_extension );
1369 driInitExtensions( NULL, point_extensions, GL_FALSE );
1370 #elif defined(RADEON_COMMON_FOR_R300)
1371 driInitSingleExtension( NULL, gl_20_extension );
1372 #endif
1373
1374 if (!radeonInitDriver(psp))
1375 return NULL;
1376
1377 /* for now fill in all modes */
1378 return radeonFillInModes( psp,
1379 dri_priv->bpp,
1380 (dri_priv->bpp == 16) ? 16 : 24,
1381 (dri_priv->bpp == 16) ? 0 : 8, 1);
1382 }
1383 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
1384
1385 /**
1386 * This is the driver specific part of the createNewScreen entry point.
1387 * Called when using DRI2.
1388 *
1389 * \return the __GLcontextModes supported by this driver
1390 */
1391 static const
1392 __DRIconfig **radeonInitScreen2(__DRIscreenPrivate *psp)
1393 {
1394 GLenum fb_format[3];
1395 GLenum fb_type[3];
1396 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
1397 * support pageflipping at all.
1398 */
1399 static const GLenum back_buffer_modes[] = {
1400 GLX_NONE, GLX_SWAP_UNDEFINED_OML, /*, GLX_SWAP_COPY_OML*/
1401 };
1402 uint8_t depth_bits[4], stencil_bits[4], msaa_samples_array[1];
1403 int color;
1404 __DRIconfig **configs = NULL;
1405
1406 /* Calling driInitExtensions here, with a NULL context pointer,
1407 * does not actually enable the extensions. It just makes sure
1408 * that all the dispatch offsets for all the extensions that
1409 * *might* be enables are known. This is needed because the
1410 * dispatch offsets need to be known when _mesa_context_create
1411 * is called, but we can't enable the extensions until we have a
1412 * context pointer.
1413 *
1414 * Hello chicken. Hello egg. How are you two today?
1415 */
1416 driInitExtensions( NULL, card_extensions, GL_FALSE );
1417 driInitExtensions( NULL, mm_extensions, GL_FALSE );
1418 #if RADEON_COMMON && defined(RADEON_COMMON_FOR_R200)
1419 driInitExtensions( NULL, blend_extensions, GL_FALSE );
1420 driInitSingleExtension( NULL, ARB_vp_extension );
1421 driInitSingleExtension( NULL, NV_vp_extension );
1422 driInitSingleExtension( NULL, ATI_fs_extension );
1423 driInitExtensions( NULL, point_extensions, GL_FALSE );
1424 #endif
1425
1426 if (!radeonInitDriver(psp)) {
1427 return NULL;
1428 }
1429 depth_bits[0] = 0;
1430 stencil_bits[0] = 0;
1431 depth_bits[1] = 16;
1432 stencil_bits[1] = 0;
1433 depth_bits[2] = 24;
1434 stencil_bits[2] = 0;
1435 depth_bits[3] = 24;
1436 stencil_bits[3] = 8;
1437
1438 msaa_samples_array[0] = 0;
1439
1440 fb_format[0] = GL_RGB;
1441 fb_type[0] = GL_UNSIGNED_SHORT_5_6_5;
1442
1443 fb_format[1] = GL_BGR;
1444 fb_type[1] = GL_UNSIGNED_INT_8_8_8_8_REV;
1445
1446 fb_format[2] = GL_BGRA;
1447 fb_type[2] = GL_UNSIGNED_INT_8_8_8_8_REV;
1448
1449 for (color = 0; color < ARRAY_SIZE(fb_format); color++) {
1450 __DRIconfig **new_configs;
1451
1452 new_configs = driCreateConfigs(fb_format[color], fb_type[color],
1453 depth_bits,
1454 stencil_bits,
1455 ARRAY_SIZE(depth_bits),
1456 back_buffer_modes,
1457 ARRAY_SIZE(back_buffer_modes),
1458 msaa_samples_array,
1459 ARRAY_SIZE(msaa_samples_array));
1460 if (configs == NULL)
1461 configs = new_configs;
1462 else
1463 configs = driConcatConfigs(configs, new_configs);
1464 }
1465
1466 if (configs == NULL) {
1467 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
1468 __LINE__);
1469 return NULL;
1470 }
1471
1472 return (const __DRIconfig **)configs;
1473 }
1474
1475 /**
1476 * Get information about previous buffer swaps.
1477 */
1478 static int
1479 getSwapInfo( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo )
1480 {
1481 struct radeon_framebuffer *rfb;
1482
1483 if ( (dPriv == NULL) || (dPriv->driContextPriv == NULL)
1484 || (dPriv->driContextPriv->driverPrivate == NULL)
1485 || (sInfo == NULL) ) {
1486 return -1;
1487 }
1488
1489 rfb = dPriv->driverPrivate;
1490 sInfo->swap_count = rfb->swap_count;
1491 sInfo->swap_ust = rfb->swap_ust;
1492 sInfo->swap_missed_count = rfb->swap_missed_count;
1493
1494 sInfo->swap_missed_usage = (sInfo->swap_missed_count != 0)
1495 ? driCalculateSwapUsage( dPriv, 0, rfb->swap_missed_ust )
1496 : 0.0;
1497
1498 return 0;
1499 }
1500
1501 #if !RADEON_COMMON || (RADEON_COMMON && defined(RADEON_COMMON_FOR_R300))
1502 const struct __DriverAPIRec driDriverAPI = {
1503 .InitScreen = radeonInitScreen,
1504 .DestroyScreen = radeonDestroyScreen,
1505 .CreateContext = radeonCreateContext,
1506 .DestroyContext = radeonDestroyContext,
1507 .CreateBuffer = radeonCreateBuffer,
1508 .DestroyBuffer = radeonDestroyBuffer,
1509 .SwapBuffers = radeonSwapBuffers,
1510 .MakeCurrent = radeonMakeCurrent,
1511 .UnbindContext = radeonUnbindContext,
1512 .GetSwapInfo = getSwapInfo,
1513 .GetDrawableMSC = driDrawableGetMSC32,
1514 .WaitForMSC = driWaitForMSC32,
1515 .WaitForSBC = NULL,
1516 .SwapBuffersMSC = NULL,
1517 .CopySubBuffer = radeonCopySubBuffer,
1518 /* DRI2 */
1519 .InitScreen2 = radeonInitScreen2,
1520 };
1521 #else
1522 const struct __DriverAPIRec driDriverAPI = {
1523 .InitScreen = radeonInitScreen,
1524 .DestroyScreen = radeonDestroyScreen,
1525 .CreateContext = r200CreateContext,
1526 .DestroyContext = r200DestroyContext,
1527 .CreateBuffer = radeonCreateBuffer,
1528 .DestroyBuffer = radeonDestroyBuffer,
1529 .SwapBuffers = radeonSwapBuffers,
1530 .MakeCurrent = radeonMakeCurrent,
1531 .UnbindContext = radeonUnbindContext,
1532 .GetSwapInfo = getSwapInfo,
1533 .GetDrawableMSC = driDrawableGetMSC32,
1534 .WaitForMSC = driWaitForMSC32,
1535 .WaitForSBC = NULL,
1536 .SwapBuffersMSC = NULL,
1537 .CopySubBuffer = radeonCopySubBuffer,
1538 .InitScreen2 = radeonInitScreen2,
1539 };
1540 #endif
1541