1 /**************************************************************************
3 Copyright 2003 Eric Anholt
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 on the rights to use, copy, modify, merge, publish, distribute, sub
10 license, and/or sell copies of the Software, and to permit persons to whom
11 the Software is furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice (including the next
14 paragraph) shall be included in all copies or substantial portions of the
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 ERIC ANHOLT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 **************************************************************************/
28 * Eric Anholt <anholt@FreeBSD.org>
36 #include "framebuffer.h"
37 #include "renderbuffer.h"
39 #include "sis_context.h"
46 #include "GL/internal/dri_interface.h"
48 #define SIS_AGP_DISABLE(def) \
49 DRI_CONF_OPT_BEGIN(agp_disable,bool,def) \
50 DRI_CONF_DESC(en,"Disable AGP vertex dispatch") \
53 PUBLIC
const char __driConfigOptions
[] =
55 DRI_CONF_SECTION_QUALITY
56 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
58 DRI_CONF_SECTION_DEBUG
60 DRI_CONF_NO_RAST(false)
63 static const GLuint __driNConfigOptions
= 3;
65 extern const struct dri_extension card_extensions
[];
67 static __GLcontextModes
*
68 sisFillInModes(int bpp
)
70 __GLcontextModes
*modes
;
73 unsigned depth_buffer_factor
;
74 unsigned back_buffer_factor
;
77 static const GLenum back_buffer_modes
[] = {
78 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
80 u_int8_t depth_bits_array
[4];
81 u_int8_t stencil_bits_array
[4];
83 depth_bits_array
[0] = 0;
84 stencil_bits_array
[0] = 0;
85 depth_bits_array
[1] = 16;
86 stencil_bits_array
[1] = 0;
87 depth_bits_array
[2] = 24;
88 stencil_bits_array
[2] = 8;
89 depth_bits_array
[3] = 32;
90 stencil_bits_array
[3] = 0;
92 depth_buffer_factor
= 4;
93 back_buffer_factor
= 2;
95 /* Last 4 is for GLX_TRUE_COLOR & GLX_DIRECT_COLOR, with/without accum */
96 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
100 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
103 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
106 modes
= (*dri_interface
->createContextModes
)(num_modes
, sizeof(__GLcontextModes
));
108 if (!driFillInModes(&m
, fb_format
, fb_type
, depth_bits_array
,
109 stencil_bits_array
, depth_buffer_factor
,
110 back_buffer_modes
, back_buffer_factor
,
112 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
, __LINE__
);
116 if (!driFillInModes(&m
, fb_format
, fb_type
, depth_bits_array
,
117 stencil_bits_array
, depth_buffer_factor
,
118 back_buffer_modes
, back_buffer_factor
,
120 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
, __LINE__
);
128 /* Create the device specific screen private data struct.
131 sisCreateScreen( __DRIscreenPrivate
*sPriv
)
133 sisScreenPtr sisScreen
;
134 SISDRIPtr sisDRIPriv
= (SISDRIPtr
)sPriv
->pDevPriv
;
136 if (sPriv
->devPrivSize
!= sizeof(SISDRIRec
)) {
137 fprintf(stderr
,"\nERROR! sizeof(SISDRIRec) does not match passed size from device driver\n");
141 /* Allocate the private area */
142 sisScreen
= (sisScreenPtr
)CALLOC( sizeof(*sisScreen
) );
143 if ( sisScreen
== NULL
)
146 sisScreen
->screenX
= sisDRIPriv
->width
;
147 sisScreen
->screenY
= sisDRIPriv
->height
;
148 sisScreen
->cpp
= sisDRIPriv
->bytesPerPixel
;
149 sisScreen
->deviceID
= sisDRIPriv
->deviceID
;
150 sisScreen
->AGPCmdBufOffset
= sisDRIPriv
->AGPCmdBufOffset
;
151 sisScreen
->AGPCmdBufSize
= sisDRIPriv
->AGPCmdBufSize
;
152 sisScreen
->sarea_priv_offset
= sizeof(drm_sarea_t
);
154 sisScreen
->mmio
.handle
= sisDRIPriv
->regs
.handle
;
155 sisScreen
->mmio
.size
= sisDRIPriv
->regs
.size
;
156 if ( drmMap( sPriv
->fd
, sisScreen
->mmio
.handle
, sisScreen
->mmio
.size
,
157 &sisScreen
->mmio
.map
) )
163 if (sisDRIPriv
->agp
.size
) {
164 sisScreen
->agp
.handle
= sisDRIPriv
->agp
.handle
;
165 sisScreen
->agpBaseOffset
= drmAgpBase(sPriv
->fd
);
166 sisScreen
->agp
.size
= sisDRIPriv
->agp
.size
;
167 if ( drmMap( sPriv
->fd
, sisScreen
->agp
.handle
, sisScreen
->agp
.size
,
168 &sisScreen
->agp
.map
) )
170 sisScreen
->agp
.size
= 0;
174 sisScreen
->driScreen
= sPriv
;
176 /* parse information in __driConfigOptions */
177 driParseOptionInfo(&sisScreen
->optionCache
,
178 __driConfigOptions
, __driNConfigOptions
);
183 /* Destroy the device specific screen private data struct.
186 sisDestroyScreen( __DRIscreenPrivate
*sPriv
)
188 sisScreenPtr sisScreen
= (sisScreenPtr
)sPriv
->private;
190 if ( sisScreen
== NULL
)
193 if (sisScreen
->agp
.size
!= 0)
194 drmUnmap( sisScreen
->agp
.map
, sisScreen
->agp
.size
);
195 drmUnmap( sisScreen
->mmio
.map
, sisScreen
->mmio
.size
);
198 sPriv
->private = NULL
;
202 /* Create and initialize the Mesa and driver specific pixmap buffer
206 sisCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
207 __DRIdrawablePrivate
*driDrawPriv
,
208 const __GLcontextModes
*mesaVis
,
211 /*sisScreenPtr screen = (sisScreenPtr) driScrnPriv->private;*/
212 struct gl_framebuffer
*fb
;
215 return GL_FALSE
; /* not implemented */
217 fb
= _mesa_create_framebuffer(mesaVis
);
219 _mesa_add_soft_renderbuffers(fb
,
220 GL_FALSE
, /* color */
221 GL_FALSE
, /* depth */
222 mesaVis
->stencilBits
> 0,
223 mesaVis
->accumRedBits
> 0,
224 GL_FALSE
, /* alpha */
226 driDrawPriv
->driverPrivate
= (void *) fb
;
228 return (driDrawPriv
->driverPrivate
!= NULL
);
233 sisDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
235 _mesa_unreference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)));
238 static void sisCopyBuffer( __DRIdrawablePrivate
*dPriv
)
240 sisContextPtr smesa
= (sisContextPtr
)dPriv
->driContextPriv
->driverPrivate
;
243 while ((*smesa
->FrameCountPtr
) - MMIO_READ(0x8a2c) > SIS_MAX_FRAME_LENGTH
)
248 for (i
= 0; i
< dPriv
->numClipRects
; i
++) {
249 drm_clip_rect_t
*box
= &dPriv
->pClipRects
[i
];
252 MMIO(REG_SRC_ADDR
, smesa
->back
.offset
);
253 MMIO(REG_SRC_PITCH
, smesa
->back
.pitch
| ((smesa
->bytesPerPixel
== 4) ?
254 BLIT_DEPTH_32
: BLIT_DEPTH_16
));
255 MMIO(REG_SRC_X_Y
, ((box
->x1
- dPriv
->x
) << 16) | (box
->y1
- dPriv
->y
));
256 MMIO(REG_DST_X_Y
, ((box
->x1
- dPriv
->x
) << 16) | (box
->y1
- dPriv
->y
));
257 MMIO(REG_DST_ADDR
, smesa
->front
.offset
);
258 MMIO(REG_DST_PITCH_HEIGHT
, (smesa
->virtualY
<< 16) | smesa
->front
.pitch
);
259 MMIO(REG_WIDTH_HEIGHT
, ((box
->y2
- box
->y1
) << 16) | (box
->x2
- box
->x1
));
260 MMIO(REG_BLIT_CMD
, CMD_DIR_X_INC
| CMD_DIR_Y_INC
| CMD_ROP_SRC
);
261 MMIO(REG_CommandQueue
, -1);
264 *(GLint
*)(smesa
->IOBase
+0x8a2c) = *smesa
->FrameCountPtr
;
265 (*smesa
->FrameCountPtr
)++;
271 /* Copy the back color buffer to the front color buffer */
273 sisSwapBuffers(__DRIdrawablePrivate
*dPriv
)
275 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
276 sisContextPtr smesa
= (sisContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
277 GLcontext
*ctx
= smesa
->glCtx
;
279 if (ctx
->Visual
.doubleBufferMode
) {
280 _mesa_notifySwapBuffers( ctx
); /* flush pending rendering comands */
281 sisCopyBuffer( dPriv
);
284 /* XXX this shouldn't be an error but we can't handle it for now */
285 _mesa_problem(NULL
, "%s: drawable has no context!", __FUNCTION__
);
290 /* Initialize the driver specific screen private data.
293 sisInitDriver( __DRIscreenPrivate
*sPriv
)
295 sPriv
->private = (void *) sisCreateScreen( sPriv
);
297 if ( !sPriv
->private ) {
298 sisDestroyScreen( sPriv
);
305 static struct __DriverAPIRec sisAPI
= {
306 .InitDriver
= sisInitDriver
,
307 .DestroyScreen
= sisDestroyScreen
,
308 .CreateContext
= sisCreateContext
,
309 .DestroyContext
= sisDestroyContext
,
310 .CreateBuffer
= sisCreateBuffer
,
311 .DestroyBuffer
= sisDestroyBuffer
,
312 .SwapBuffers
= sisSwapBuffers
,
313 .MakeCurrent
= sisMakeCurrent
,
314 .UnbindContext
= sisUnbindContext
,
319 .SwapBuffersMSC
= NULL
325 * This is the bootstrap function for the driver. libGL supplies all of the
326 * requisite information about the system, and the driver initializes itself.
327 * This routine also fills in the linked list pointed to by \c driver_modes
328 * with the \c __GLcontextModes that the driver can support for windows or
331 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
335 void * __driCreateNewScreen_20050727( __DRInativeDisplay
*dpy
, int scrn
,
337 const __GLcontextModes
*modes
,
338 const __DRIversion
*ddx_version
,
339 const __DRIversion
*dri_version
,
340 const __DRIversion
*drm_version
,
341 const __DRIframebuffer
*frame_buffer
,
342 drmAddress pSAREA
, int fd
,
343 int internal_api_version
,
344 const __DRIinterfaceMethods
* interface
,
345 __GLcontextModes
**driver_modes
)
348 __DRIscreenPrivate
*psp
;
349 static const __DRIversion ddx_expected
= {0, 8, 0};
350 static const __DRIversion dri_expected
= {4, 0, 0};
351 static const __DRIversion drm_expected
= {1, 0, 0};
352 static const char *driver_name
= "SiS";
353 dri_interface
= interface
;
355 if (!driCheckDriDdxDrmVersions2(driver_name
, dri_version
, &dri_expected
,
356 ddx_version
, &ddx_expected
,
357 drm_version
, &drm_expected
)) {
361 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
362 ddx_version
, dri_version
, drm_version
,
363 frame_buffer
, pSAREA
, fd
,
364 internal_api_version
, &sisAPI
);
366 SISDRIPtr dri_priv
= (SISDRIPtr
)psp
->pDevPriv
;
367 *driver_modes
= sisFillInModes(dri_priv
->bytesPerPixel
* 8);
369 /* Calling driInitExtensions here, with a NULL context pointer, does not actually
370 * enable the extensions. It just makes sure that all the dispatch offsets for all
371 * the extensions that *might* be enables are known. This is needed because the
372 * dispatch offsets need to be known when _mesa_context_create is called, but we can't
373 * enable the extensions until we have a context pointer.
375 * Hello chicken. Hello egg. How are you two today?
377 driInitExtensions( NULL
, card_extensions
, GL_FALSE
);