1 /* $XFree86: xc/lib/GL/mesa/src/drv/r128/r128_screen.c,v 1.9 2003/03/26 20:43:49 tsi Exp $ */
2 /**************************************************************************
4 Copyright 1999, 2000 ATI Technologies Inc. and Precision Insight, Inc.,
8 Permission is hereby granted, free of charge, to any person obtaining a
9 copy of this software and associated documentation files (the "Software"),
10 to deal in the Software without restriction, including without limitation
11 on the rights to use, copy, modify, merge, publish, distribute, sub
12 license, and/or sell copies of the Software, and to permit persons to whom
13 the Software is furnished to do so, subject to the following conditions:
15 The above copyright notice and this permission notice (including the next
16 paragraph) shall be included in all copies or substantial portions of the
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22 ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
23 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25 USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
31 * Gareth Hughes <gareth@valinux.com>
32 * Kevin E. Martin <martin@valinux.com>
38 #include "r128_context.h"
39 #include "r128_ioctl.h"
40 #include "r128_tris.h"
50 #include "glxextensions.h"
57 const char __driConfigOptions
[] =
59 DRI_CONF_SECTION_PERFORMANCE
60 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
62 DRI_CONF_SECTION_QUALITY
63 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
66 DRI_CONF_SECTION_DEBUG
67 DRI_CONF_PERFORMANCE_BOXES(false)
72 static const GLuint __driNConfigOptions
= 3;
74 static const GLuint __driNConfigOptions
= 2;
78 /* Including xf86PciInfo.h introduces a bunch of errors...
80 #define PCI_CHIP_RAGE128LE 0x4C45
81 #define PCI_CHIP_RAGE128LF 0x4C46
82 #define PCI_CHIP_RAGE128PF 0x5046
83 #define PCI_CHIP_RAGE128PR 0x5052
84 #define PCI_CHIP_RAGE128RE 0x5245
85 #define PCI_CHIP_RAGE128RF 0x5246
86 #define PCI_CHIP_RAGE128RK 0x524B
87 #define PCI_CHIP_RAGE128RL 0x524C
91 /* Create the device specific screen private data struct.
94 r128CreateScreen( __DRIscreenPrivate
*sPriv
)
96 r128ScreenPtr r128Screen
;
97 R128DRIPtr r128DRIPriv
= (R128DRIPtr
)sPriv
->pDevPriv
;
99 if ( ! driCheckDriDdxDrmVersions( sPriv
, "Rage128", 4, 0, 4, 0, 2, 2 ) )
102 /* Allocate the private area */
103 r128Screen
= (r128ScreenPtr
) CALLOC( sizeof(*r128Screen
) );
104 if ( !r128Screen
) return NULL
;
106 /* parse information in __driConfigOptions */
107 driParseOptionInfo (&r128Screen
->optionCache
,
108 __driConfigOptions
, __driNConfigOptions
);
110 /* This is first since which regions we map depends on whether or
111 * not we are using a PCI card.
113 r128Screen
->IsPCI
= r128DRIPriv
->IsPCI
;
114 r128Screen
->sarea_priv_offset
= r128DRIPriv
->sarea_priv_offset
;
116 if (sPriv
->drmMinor
>= 3) {
120 gp
.param
= R128_PARAM_IRQ_NR
;
121 gp
.value
= &r128Screen
->irq
;
123 ret
= drmCommandWriteRead( sPriv
->fd
, DRM_R128_GETPARAM
,
126 fprintf(stderr
, "drmR128GetParam (R128_PARAM_IRQ_NR): %d\n", ret
);
132 r128Screen
->mmio
.handle
= r128DRIPriv
->registerHandle
;
133 r128Screen
->mmio
.size
= r128DRIPriv
->registerSize
;
134 if ( drmMap( sPriv
->fd
,
135 r128Screen
->mmio
.handle
,
136 r128Screen
->mmio
.size
,
137 (drmAddressPtr
)&r128Screen
->mmio
.map
) ) {
142 r128Screen
->buffers
= drmMapBufs( sPriv
->fd
);
143 if ( !r128Screen
->buffers
) {
144 drmUnmap( (drmAddress
)r128Screen
->mmio
.map
, r128Screen
->mmio
.size
);
149 if ( !r128Screen
->IsPCI
) {
150 r128Screen
->agpTextures
.handle
= r128DRIPriv
->agpTexHandle
;
151 r128Screen
->agpTextures
.size
= r128DRIPriv
->agpTexMapSize
;
152 if ( drmMap( sPriv
->fd
,
153 r128Screen
->agpTextures
.handle
,
154 r128Screen
->agpTextures
.size
,
155 (drmAddressPtr
)&r128Screen
->agpTextures
.map
) ) {
156 drmUnmapBufs( r128Screen
->buffers
);
157 drmUnmap( (drmAddress
)r128Screen
->mmio
.map
, r128Screen
->mmio
.size
);
163 switch ( r128DRIPriv
->deviceID
) {
164 case PCI_CHIP_RAGE128RE
:
165 case PCI_CHIP_RAGE128RF
:
166 case PCI_CHIP_RAGE128RK
:
167 case PCI_CHIP_RAGE128RL
:
168 r128Screen
->chipset
= R128_CARD_TYPE_R128
;
170 case PCI_CHIP_RAGE128PF
:
171 r128Screen
->chipset
= R128_CARD_TYPE_R128_PRO
;
173 case PCI_CHIP_RAGE128LE
:
174 case PCI_CHIP_RAGE128LF
:
175 r128Screen
->chipset
= R128_CARD_TYPE_R128_MOBILITY
;
178 r128Screen
->chipset
= R128_CARD_TYPE_R128
;
182 r128Screen
->cpp
= r128DRIPriv
->bpp
/ 8;
183 r128Screen
->AGPMode
= r128DRIPriv
->AGPMode
;
185 r128Screen
->frontOffset
= r128DRIPriv
->frontOffset
;
186 r128Screen
->frontPitch
= r128DRIPriv
->frontPitch
;
187 r128Screen
->backOffset
= r128DRIPriv
->backOffset
;
188 r128Screen
->backPitch
= r128DRIPriv
->backPitch
;
189 r128Screen
->depthOffset
= r128DRIPriv
->depthOffset
;
190 r128Screen
->depthPitch
= r128DRIPriv
->depthPitch
;
191 r128Screen
->spanOffset
= r128DRIPriv
->spanOffset
;
193 r128Screen
->texOffset
[R128_CARD_HEAP
] = r128DRIPriv
->textureOffset
;
194 r128Screen
->texSize
[R128_CARD_HEAP
] = r128DRIPriv
->textureSize
;
195 r128Screen
->logTexGranularity
[R128_CARD_HEAP
] = r128DRIPriv
->log2TexGran
;
197 if ( r128Screen
->IsPCI
) {
198 r128Screen
->numTexHeaps
= R128_NR_TEX_HEAPS
- 1;
199 r128Screen
->texOffset
[R128_AGP_HEAP
] = 0;
200 r128Screen
->texSize
[R128_AGP_HEAP
] = 0;
201 r128Screen
->logTexGranularity
[R128_AGP_HEAP
] = 0;
203 r128Screen
->numTexHeaps
= R128_NR_TEX_HEAPS
;
204 r128Screen
->texOffset
[R128_AGP_HEAP
] =
205 r128DRIPriv
->agpTexOffset
+ R128_AGP_TEX_OFFSET
;
206 r128Screen
->texSize
[R128_AGP_HEAP
] = r128DRIPriv
->agpTexMapSize
;
207 r128Screen
->logTexGranularity
[R128_AGP_HEAP
] =
208 r128DRIPriv
->log2AGPTexGran
;
211 r128Screen
->driScreen
= sPriv
;
213 if ( driCompareGLXAPIVersion( 20030813 ) >= 0 ) {
214 PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension
=
215 (PFNGLXSCRENABLEEXTENSIONPROC
) glXGetProcAddress( (const GLubyte
*) "__glXScrEnableExtension" );
216 void * const psc
= sPriv
->psc
->screenConfigs
;
218 if ( glx_enable_extension
!= NULL
) {
219 if ( r128Screen
->irq
!= 0 ) {
220 (*glx_enable_extension
)( psc
, "GLX_SGI_swap_control" );
221 (*glx_enable_extension
)( psc
, "GLX_SGI_video_sync" );
222 (*glx_enable_extension
)( psc
, "GLX_MESA_swap_control" );
225 (*glx_enable_extension
)( psc
, "GLX_MESA_swap_frame_usage" );
232 /* Destroy the device specific screen private data struct.
235 r128DestroyScreen( __DRIscreenPrivate
*sPriv
)
237 r128ScreenPtr r128Screen
= (r128ScreenPtr
)sPriv
->private;
242 if ( !r128Screen
->IsPCI
) {
243 drmUnmap( (drmAddress
)r128Screen
->agpTextures
.map
,
244 r128Screen
->agpTextures
.size
);
246 drmUnmapBufs( r128Screen
->buffers
);
247 drmUnmap( (drmAddress
)r128Screen
->mmio
.map
, r128Screen
->mmio
.size
);
249 /* free all option information */
250 driDestroyOptionInfo (&r128Screen
->optionCache
);
253 sPriv
->private = NULL
;
257 /* Initialize the fullscreen mode.
260 r128OpenCloseFullScreen( __DRIcontextPrivate
*driContextPriv
)
266 /* Create and initialize the Mesa and driver specific pixmap buffer
270 r128CreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
271 __DRIdrawablePrivate
*driDrawPriv
,
272 const __GLcontextModes
*mesaVis
,
276 return GL_FALSE
; /* not implemented */
279 driDrawPriv
->driverPrivate
= (void *)
280 _mesa_create_framebuffer( mesaVis
,
281 GL_FALSE
, /* software depth buffer? */
282 mesaVis
->stencilBits
> 0,
283 mesaVis
->accumRedBits
> 0,
284 mesaVis
->alphaBits
> 0 );
285 return (driDrawPriv
->driverPrivate
!= NULL
);
291 r128DestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
293 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
297 /* Copy the back color buffer to the front color buffer */
299 r128SwapBuffers(__DRIdrawablePrivate
*dPriv
)
301 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
302 r128ContextPtr rmesa
;
304 rmesa
= (r128ContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
306 if (ctx
->Visual
.doubleBufferMode
) {
307 _mesa_notifySwapBuffers( ctx
); /* flush pending rendering comands */
308 if ( rmesa
->doPageFlip
) {
309 r128PageFlip( dPriv
);
312 r128CopyBuffer( dPriv
);
317 /* XXX this shouldn't be an error but we can't handle it for now */
318 _mesa_problem(NULL
, "%s: drawable has no context!", __FUNCTION__
);
323 /* Initialize the driver specific screen private data.
326 r128InitDriver( __DRIscreenPrivate
*sPriv
)
328 sPriv
->private = (void *) r128CreateScreen( sPriv
);
330 if ( !sPriv
->private ) {
331 r128DestroyScreen( sPriv
);
340 * This function is called by libGL.so as soon as libGL.so is loaded.
341 * This is where we register new extension functions with the dispatcher.
343 * \todo This interface has been deprecated, so we should probably remove
344 * this function before the next XFree86 release.
346 void __driRegisterExtensions( void )
348 PFNGLXENABLEEXTENSIONPROC glx_enable_extension
;
350 if ( driCompareGLXAPIVersion( 20030317 ) >= 0 ) {
351 glx_enable_extension
= (PFNGLXENABLEEXTENSIONPROC
)
352 glXGetProcAddress( (const GLubyte
*) "__glXEnableExtension" );
354 if ( glx_enable_extension
!= NULL
) {
355 glx_enable_extension( "GLX_SGI_swap_control", GL_FALSE
);
356 glx_enable_extension( "GLX_SGI_video_sync", GL_FALSE
);
357 glx_enable_extension( "GLX_MESA_swap_control", GL_FALSE
);
363 static struct __DriverAPIRec r128API
= {
364 .InitDriver
= r128InitDriver
,
365 .DestroyScreen
= r128DestroyScreen
,
366 .CreateContext
= r128CreateContext
,
367 .DestroyContext
= r128DestroyContext
,
368 .CreateBuffer
= r128CreateBuffer
,
369 .DestroyBuffer
= r128DestroyBuffer
,
370 .SwapBuffers
= r128SwapBuffers
,
371 .MakeCurrent
= r128MakeCurrent
,
372 .UnbindContext
= r128UnbindContext
,
373 .OpenFullScreen
= r128OpenCloseFullScreen
,
374 .CloseFullScreen
= r128OpenCloseFullScreen
,
376 .GetMSC
= driGetMSC32
,
377 .WaitForMSC
= driWaitForMSC32
,
379 .SwapBuffersMSC
= NULL
385 * This is the bootstrap function for the driver.
386 * The __driCreateScreen name is the symbol that libGL.so fetches.
387 * Return: pointer to a __DRIscreenPrivate.
390 void *__driCreateScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
391 int numConfigs
, __GLXvisualConfig
*config
)
393 __DRIscreenPrivate
*psp
;
394 psp
= __driUtilCreateScreen(dpy
, scrn
, psc
, numConfigs
, config
, &r128API
);
398 void *__driCreateScreen(struct DRIDriverRec
*driver
,
399 struct DRIDriverContextRec
*driverContext
)
401 __DRIscreenPrivate
*psp
;
402 psp
= __driUtilCreateScreen(driver
, driverContext
, &r128API
);