1 /* $XFree86: xc/lib/GL/mesa/src/drv/radeon/radeon_screen.c,v 1.7 2003/03/26 20:43:51 tsi Exp $ */
2 /**************************************************************************
4 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
5 VA Linux Systems Inc., Fremont, California.
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial
19 portions of the Software.
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
25 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 **************************************************************************/
32 * \file radeon_screen.c
33 * Screen initialization functions for the Radeon driver.
35 * \author Kevin E. Martin <martin@valinux.com>
36 * \author Gareth Hughes <gareth@valinux.com>
42 #define STANDALONE_MMIO
43 #include "radeon_context.h"
44 #include "radeon_screen.h"
45 #include "radeon_macros.h"
51 #include "GL/internal/dri_interface.h"
53 /* Radeon configuration
57 const char __driConfigOptions
[] =
59 DRI_CONF_SECTION_PERFORMANCE
60 DRI_CONF_TCL_MODE(DRI_CONF_TCL_CODEGEN
)
61 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS
)
62 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
64 DRI_CONF_SECTION_QUALITY
65 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
66 DRI_CONF_DEF_MAX_ANISOTROPY(1.0,"1.0,2.0,4.0,8.0,16.0")
67 DRI_CONF_NO_NEG_LOD_BIAS(false)
68 DRI_CONF_FORCE_S3TC_ENABLE(false)
69 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER
)
70 DRI_CONF_ROUND_MODE(DRI_CONF_ROUND_TRUNC
)
71 DRI_CONF_DITHER_MODE(DRI_CONF_DITHER_XERRORDIFF
)
73 DRI_CONF_SECTION_DEBUG
74 DRI_CONF_NO_RAST(false)
77 static const GLuint __driNConfigOptions
= 11;
80 /* Including xf86PciInfo.h introduces a bunch of errors...
82 #define PCI_CHIP_RADEON_QD 0x5144
83 #define PCI_CHIP_RADEON_QE 0x5145
84 #define PCI_CHIP_RADEON_QF 0x5146
85 #define PCI_CHIP_RADEON_QG 0x5147
87 #define PCI_CHIP_RADEON_QY 0x5159
88 #define PCI_CHIP_RADEON_QZ 0x515A
90 #define PCI_CHIP_RADEON_LW 0x4C57 /* mobility 7 - has tcl */
92 #define PCI_CHIP_RADEON_LY 0x4C59
93 #define PCI_CHIP_RADEON_LZ 0x4C5A
95 #define PCI_CHIP_RV200_QW 0x5157 /* Radeon 7500 - not an R200 at all */
97 #define PCI_CHIP_RS100_4136 0x4136
98 #define PCI_CHIP_RS200_4137 0x4137
99 #define PCI_CHIP_RS250_4237 0x4237
100 #define PCI_CHIP_RS100_4336 0x4336
101 #define PCI_CHIP_RS200_4337 0x4337
102 #define PCI_CHIP_RS250_4437 0x4437
105 #ifdef USE_NEW_INTERFACE
106 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
107 #endif /* USE_NEW_INTERFACE */
109 static int getSwapInfo( __DRIdrawablePrivate
*dPriv
, __DRIswapInfo
* sInfo
);
111 #ifdef USE_NEW_INTERFACE
112 static __GLcontextModes
*
113 radeonFillInModes( unsigned pixel_bits
, unsigned depth_bits
,
114 unsigned stencil_bits
, GLboolean have_back_buffer
)
116 __GLcontextModes
* modes
;
117 __GLcontextModes
* m
;
119 unsigned depth_buffer_factor
;
120 unsigned back_buffer_factor
;
124 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
125 * enough to add support. Basically, if a context is created with an
126 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
127 * will never be used.
129 static const GLenum back_buffer_modes
[] = {
130 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
/*, GLX_SWAP_COPY_OML */
133 uint8_t depth_bits_array
[2];
134 uint8_t stencil_bits_array
[2];
137 depth_bits_array
[0] = depth_bits
;
138 depth_bits_array
[1] = depth_bits
;
140 /* Just like with the accumulation buffer, always provide some modes
141 * with a stencil buffer. It will be a sw fallback, but some apps won't
144 stencil_bits_array
[0] = 0;
145 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
147 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 2 : 1;
148 back_buffer_factor
= (have_back_buffer
) ? 2 : 1;
150 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
152 if ( pixel_bits
== 16 ) {
154 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
158 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
161 modes
= (*create_context_modes
)( num_modes
, sizeof( __GLcontextModes
) );
163 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
164 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
165 back_buffer_modes
, back_buffer_factor
,
167 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
168 __func__
, __LINE__
);
172 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
173 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
174 back_buffer_modes
, back_buffer_factor
,
175 GLX_DIRECT_COLOR
) ) {
176 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
177 __func__
, __LINE__
);
181 /* Mark the visual as slow if there are "fake" stencil bits.
183 for ( m
= modes
; m
!= NULL
; m
= m
->next
) {
184 if ( (m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
) ) {
185 m
->visualRating
= GLX_SLOW_CONFIG
;
191 #endif /* USE_NEW_INTERFACE */
193 /* Create the device specific screen private data struct.
195 radeonScreenPtr
radeonCreateScreen( __DRIscreenPrivate
*sPriv
)
197 radeonScreenPtr screen
;
198 RADEONDRIPtr dri_priv
= (RADEONDRIPtr
)sPriv
->pDevPriv
;
199 unsigned char *RADEONMMIO
;
202 /* Allocate the private area */
203 screen
= (radeonScreenPtr
) CALLOC( sizeof(*screen
) );
205 __driUtilMessage("%s: Could not allocate memory for screen structure",
210 /* parse information in __driConfigOptions */
211 driParseOptionInfo (&screen
->optionCache
,
212 __driConfigOptions
, __driNConfigOptions
);
214 /* This is first since which regions we map depends on whether or
215 * not we are using a PCI card.
217 screen
->IsPCI
= dri_priv
->IsPCI
;
221 drm_radeon_getparam_t gp
;
223 gp
.param
= RADEON_PARAM_GART_BUFFER_OFFSET
;
224 gp
.value
= &screen
->gart_buffer_offset
;
226 ret
= drmCommandWriteRead( sPriv
->fd
, DRM_RADEON_GETPARAM
,
230 fprintf(stderr
, "drm_radeon_getparam_t (RADEON_PARAM_GART_BUFFER_OFFSET): %d\n", ret
);
234 if (sPriv
->drmMinor
>= 6) {
235 gp
.param
= RADEON_PARAM_IRQ_NR
;
236 gp
.value
= &screen
->irq
;
238 ret
= drmCommandWriteRead( sPriv
->fd
, DRM_RADEON_GETPARAM
,
242 fprintf(stderr
, "drm_radeon_getparam_t (RADEON_PARAM_IRQ_NR): %d\n", ret
);
248 screen
->mmio
.handle
= dri_priv
->registerHandle
;
249 screen
->mmio
.size
= dri_priv
->registerSize
;
250 if ( drmMap( sPriv
->fd
,
253 &screen
->mmio
.map
) ) {
255 __driUtilMessage("%s: drmMap failed\n", __FUNCTION__
);
259 RADEONMMIO
= screen
->mmio
.map
;
261 screen
->status
.handle
= dri_priv
->statusHandle
;
262 screen
->status
.size
= dri_priv
->statusSize
;
263 if ( drmMap( sPriv
->fd
,
264 screen
->status
.handle
,
266 &screen
->status
.map
) ) {
267 drmUnmap( screen
->mmio
.map
, screen
->mmio
.size
);
269 __driUtilMessage("%s: drmMap (2) failed\n", __FUNCTION__
);
272 screen
->scratch
= (__volatile__
uint32_t *)
273 ((GLubyte
*)screen
->status
.map
+ RADEON_SCRATCH_REG_OFFSET
);
275 screen
->buffers
= drmMapBufs( sPriv
->fd
);
276 if ( !screen
->buffers
) {
277 drmUnmap( screen
->status
.map
, screen
->status
.size
);
278 drmUnmap( screen
->mmio
.map
, screen
->mmio
.size
);
280 __driUtilMessage("%s: drmMapBufs failed\n", __FUNCTION__
);
284 if ( dri_priv
->gartTexHandle
&& dri_priv
->gartTexMapSize
) {
285 screen
->gartTextures
.handle
= dri_priv
->gartTexHandle
;
286 screen
->gartTextures
.size
= dri_priv
->gartTexMapSize
;
287 if ( drmMap( sPriv
->fd
,
288 screen
->gartTextures
.handle
,
289 screen
->gartTextures
.size
,
290 (drmAddressPtr
)&screen
->gartTextures
.map
) ) {
291 drmUnmapBufs( screen
->buffers
);
292 drmUnmap( screen
->status
.map
, screen
->status
.size
);
293 drmUnmap( screen
->mmio
.map
, screen
->mmio
.size
);
295 __driUtilMessage("%s: drmMap failed for GART texture area\n", __FUNCTION__
);
299 screen
->gart_texture_offset
= dri_priv
->gartTexOffset
+ ( screen
->IsPCI
300 ? INREG( RADEON_AIC_LO_ADDR
)
301 : ( ( INREG( RADEON_MC_AGP_LOCATION
) & 0x0ffffU
) << 16 ) );
305 switch ( dri_priv
->deviceID
) {
307 fprintf(stderr
, "unknown chip id, assuming full radeon support\n");
308 case PCI_CHIP_RADEON_QD
:
309 case PCI_CHIP_RADEON_QE
:
310 case PCI_CHIP_RADEON_QF
:
311 case PCI_CHIP_RADEON_QG
:
312 case PCI_CHIP_RV200_QW
:
313 case PCI_CHIP_RADEON_LW
:
314 screen
->chipset
|= RADEON_CHIPSET_TCL
;
315 case PCI_CHIP_RADEON_QY
:
316 case PCI_CHIP_RADEON_QZ
:
317 case PCI_CHIP_RADEON_LY
:
318 case PCI_CHIP_RADEON_LZ
:
319 case PCI_CHIP_RS100_4136
: /* IGPs don't have TCL */
320 case PCI_CHIP_RS200_4137
:
321 case PCI_CHIP_RS250_4237
:
322 case PCI_CHIP_RS100_4336
:
323 case PCI_CHIP_RS200_4337
:
324 case PCI_CHIP_RS250_4437
:
328 screen
->cpp
= dri_priv
->bpp
/ 8;
329 screen
->AGPMode
= dri_priv
->AGPMode
;
331 screen
->fbLocation
= ( INREG( RADEON_MC_FB_LOCATION
) & 0xffff ) << 16;
333 if ( sPriv
->drmMinor
>= 10 ) {
334 drm_radeon_setparam_t sp
;
336 sp
.param
= RADEON_SETPARAM_FB_LOCATION
;
337 sp
.value
= screen
->fbLocation
;
339 drmCommandWrite( sPriv
->fd
, DRM_RADEON_SETPARAM
,
343 screen
->frontOffset
= dri_priv
->frontOffset
;
344 screen
->frontPitch
= dri_priv
->frontPitch
;
345 screen
->backOffset
= dri_priv
->backOffset
;
346 screen
->backPitch
= dri_priv
->backPitch
;
347 screen
->depthOffset
= dri_priv
->depthOffset
;
348 screen
->depthPitch
= dri_priv
->depthPitch
;
350 screen
->texOffset
[RADEON_LOCAL_TEX_HEAP
] = dri_priv
->textureOffset
351 + screen
->fbLocation
;
352 screen
->texSize
[RADEON_LOCAL_TEX_HEAP
] = dri_priv
->textureSize
;
353 screen
->logTexGranularity
[RADEON_LOCAL_TEX_HEAP
] =
354 dri_priv
->log2TexGran
;
356 if ( !screen
->gartTextures
.map
357 || getenv( "RADEON_GARTTEXTURING_FORCE_DISABLE" ) ) {
358 screen
->numTexHeaps
= RADEON_NR_TEX_HEAPS
- 1;
359 screen
->texOffset
[RADEON_GART_TEX_HEAP
] = 0;
360 screen
->texSize
[RADEON_GART_TEX_HEAP
] = 0;
361 screen
->logTexGranularity
[RADEON_GART_TEX_HEAP
] = 0;
363 screen
->numTexHeaps
= RADEON_NR_TEX_HEAPS
;
364 screen
->texOffset
[RADEON_GART_TEX_HEAP
] = screen
->gart_texture_offset
;
365 screen
->texSize
[RADEON_GART_TEX_HEAP
] = dri_priv
->gartTexMapSize
;
366 screen
->logTexGranularity
[RADEON_GART_TEX_HEAP
] =
367 dri_priv
->log2GARTTexGran
;
370 if ( driCompareGLXAPIVersion( 20030813 ) >= 0 ) {
371 PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension
=
372 (PFNGLXSCRENABLEEXTENSIONPROC
) glXGetProcAddress( (const GLubyte
*) "__glXScrEnableExtension" );
373 void * const psc
= sPriv
->psc
->screenConfigs
;
375 if ( glx_enable_extension
!= NULL
) {
376 if ( screen
->irq
!= 0 ) {
377 (*glx_enable_extension
)( psc
, "GLX_SGI_swap_control" );
378 (*glx_enable_extension
)( psc
, "GLX_SGI_video_sync" );
379 (*glx_enable_extension
)( psc
, "GLX_MESA_swap_control" );
382 (*glx_enable_extension
)( psc
, "GLX_MESA_swap_frame_usage" );
384 if ( driCompareGLXAPIVersion( 20030915 ) >= 0 ) {
385 (*glx_enable_extension
)( psc
, "GLX_SGIX_fbconfig" );
386 (*glx_enable_extension
)( psc
, "GLX_OML_swap_method" );
392 screen
->driScreen
= sPriv
;
393 screen
->sarea_priv_offset
= dri_priv
->sarea_priv_offset
;
397 /* Destroy the device specific screen private data struct.
399 void radeonDestroyScreen( __DRIscreenPrivate
*sPriv
)
401 radeonScreenPtr screen
= (radeonScreenPtr
)sPriv
->private;
406 if ( screen
->gartTextures
.map
) {
407 drmUnmap( screen
->gartTextures
.map
, screen
->gartTextures
.size
);
409 drmUnmapBufs( screen
->buffers
);
410 drmUnmap( screen
->status
.map
, screen
->status
.size
);
411 drmUnmap( screen
->mmio
.map
, screen
->mmio
.size
);
413 /* free all option information */
414 driDestroyOptionInfo (&screen
->optionCache
);
417 sPriv
->private = NULL
;
421 /* Initialize the driver specific screen private data.
424 radeonInitDriver( __DRIscreenPrivate
*sPriv
)
426 sPriv
->private = (void *) radeonCreateScreen( sPriv
);
427 if ( !sPriv
->private ) {
428 radeonDestroyScreen( sPriv
);
438 * Create and initialize the Mesa and driver specific pixmap buffer
441 * \todo This function (and its interface) will need to be updated to support
445 radeonCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
446 __DRIdrawablePrivate
*driDrawPriv
,
447 const __GLcontextModes
*mesaVis
,
451 return GL_FALSE
; /* not implemented */
454 const GLboolean swDepth
= GL_FALSE
;
455 const GLboolean swAlpha
= GL_FALSE
;
456 const GLboolean swAccum
= mesaVis
->accumRedBits
> 0;
457 const GLboolean swStencil
= mesaVis
->stencilBits
> 0 &&
458 mesaVis
->depthBits
!= 24;
459 driDrawPriv
->driverPrivate
= (void *)
460 _mesa_create_framebuffer( mesaVis
,
465 return (driDrawPriv
->driverPrivate
!= NULL
);
471 radeonDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
473 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
476 static struct __DriverAPIRec radeonAPI
= {
477 .InitDriver
= radeonInitDriver
,
478 .DestroyScreen
= radeonDestroyScreen
,
479 .CreateContext
= radeonCreateContext
,
480 .DestroyContext
= radeonDestroyContext
,
481 .CreateBuffer
= radeonCreateBuffer
,
482 .DestroyBuffer
= radeonDestroyBuffer
,
483 .SwapBuffers
= radeonSwapBuffers
,
484 .MakeCurrent
= radeonMakeCurrent
,
485 .UnbindContext
= radeonUnbindContext
,
486 .GetSwapInfo
= getSwapInfo
,
487 .GetMSC
= driGetMSC32
,
488 .WaitForMSC
= driWaitForMSC32
,
490 .SwapBuffersMSC
= NULL
495 * This is the bootstrap function for the driver.
496 * The __driCreateScreen name is the symbol that libGL.so fetches.
497 * Return: pointer to a __DRIscreenPrivate.
499 #if !defined(DRI_NEW_INTERFACE_ONLY)
500 void *__driCreateScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
501 int numConfigs
, __GLXvisualConfig
*config
)
503 __DRIscreenPrivate
*psp
;
504 psp
= __driUtilCreateScreen(dpy
, scrn
, psc
, numConfigs
, config
, &radeonAPI
);
507 #endif /* !defined(DRI_NEW_INTERFACE_ONLY) */
510 * This is the bootstrap function for the driver. libGL supplies all of the
511 * requisite information about the system, and the driver initializes itself.
512 * This routine also fills in the linked list pointed to by \c driver_modes
513 * with the \c __GLcontextModes that the driver can support for windows or
516 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
519 #ifdef USE_NEW_INTERFACE
520 void * __driCreateNewScreen( __DRInativeDisplay
*dpy
, int scrn
, __DRIscreen
*psc
,
521 const __GLcontextModes
* modes
,
522 const __DRIversion
* ddx_version
,
523 const __DRIversion
* dri_version
,
524 const __DRIversion
* drm_version
,
525 const __DRIframebuffer
* frame_buffer
,
526 drmAddress pSAREA
, int fd
,
527 int internal_api_version
,
528 __GLcontextModes
** driver_modes
)
531 __DRIscreenPrivate
*psp
;
532 static const __DRIversion ddx_expected
= { 4, 0, 0 };
533 static const __DRIversion dri_expected
= { 4, 0, 0 };
534 static const __DRIversion drm_expected
= { 1, 3, 0 };
536 if ( ! driCheckDriDdxDrmVersions2( "Radeon",
537 dri_version
, & dri_expected
,
538 ddx_version
, & ddx_expected
,
539 drm_version
, & drm_expected
) ) {
543 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
544 ddx_version
, dri_version
, drm_version
,
545 frame_buffer
, pSAREA
, fd
,
546 internal_api_version
, &radeonAPI
);
548 create_context_modes
= (PFNGLXCREATECONTEXTMODES
)
549 glXGetProcAddress( (const GLubyte
*) "__glXCreateContextModes" );
550 if ( create_context_modes
!= NULL
) {
551 RADEONDRIPtr dri_priv
= (RADEONDRIPtr
) psp
->pDevPriv
;
552 *driver_modes
= radeonFillInModes( dri_priv
->bpp
,
553 (dri_priv
->bpp
== 16) ? 16 : 24,
554 (dri_priv
->bpp
== 16) ? 0 : 8,
555 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
561 #endif /* USE_NEW_INTERFACE */
564 * Get information about previous buffer swaps.
567 getSwapInfo( __DRIdrawablePrivate
*dPriv
, __DRIswapInfo
* sInfo
)
569 radeonContextPtr rmesa
;
571 if ( (dPriv
== NULL
) || (dPriv
->driContextPriv
== NULL
)
572 || (dPriv
->driContextPriv
->driverPrivate
== NULL
)
573 || (sInfo
== NULL
) ) {
577 rmesa
= (radeonContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
578 sInfo
->swap_count
= rmesa
->swap_count
;
579 sInfo
->swap_ust
= rmesa
->swap_ust
;
580 sInfo
->swap_missed_count
= rmesa
->swap_missed_count
;
582 sInfo
->swap_missed_usage
= (sInfo
->swap_missed_count
!= 0)
583 ? driCalculateSwapUsage( dPriv
, 0, rmesa
->swap_missed_ust
)