2 /**************************************************************************
4 Copyright 2003 Eric Anholt
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 ERIC ANHOLT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 **************************************************************************/
29 * Eric Anholt <anholt@FreeBSD.org>
37 #include "framebuffer.h"
38 #include "renderbuffer.h"
40 #include "sis_context.h"
47 #include "GL/internal/dri_interface.h"
49 PUBLIC
const char __driConfigOptions
[] =
51 DRI_CONF_SECTION_DEBUG
52 DRI_CONF_OPT_BEGIN(agp_disable
,bool,false)
53 DRI_CONF_DESC(en
,"Disable AGP vertex dispatch")
55 DRI_CONF_OPT_BEGIN(fallback_force
,bool,false)
56 DRI_CONF_DESC(en
,"Force software fallback")
60 static const GLuint __driNConfigOptions
= 2;
62 extern const struct dri_extension card_extensions
[];
64 static __GLcontextModes
*
65 sisFillInModes(int bpp
)
67 __GLcontextModes
*modes
;
70 unsigned depth_buffer_factor
;
71 unsigned back_buffer_factor
;
74 static const GLenum back_buffer_modes
[] = {
75 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
77 u_int8_t depth_bits_array
[4];
78 u_int8_t stencil_bits_array
[4];
80 depth_bits_array
[0] = 0;
81 stencil_bits_array
[0] = 0;
82 depth_bits_array
[1] = 16;
83 stencil_bits_array
[1] = 0;
84 depth_bits_array
[2] = 24;
85 stencil_bits_array
[2] = 8;
86 depth_bits_array
[3] = 32;
87 stencil_bits_array
[3] = 0;
89 depth_buffer_factor
= 4;
90 back_buffer_factor
= 2;
92 /* Last 4 is for GLX_TRUE_COLOR & GLX_DIRECT_COLOR, with/without accum */
93 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
97 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
100 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
103 modes
= (*dri_interface
->createContextModes
)(num_modes
, sizeof(__GLcontextModes
));
105 if (!driFillInModes(&m
, fb_format
, fb_type
, depth_bits_array
,
106 stencil_bits_array
, depth_buffer_factor
,
107 back_buffer_modes
, back_buffer_factor
,
109 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
, __LINE__
);
113 if (!driFillInModes(&m
, fb_format
, fb_type
, depth_bits_array
,
114 stencil_bits_array
, depth_buffer_factor
,
115 back_buffer_modes
, back_buffer_factor
,
117 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
, __LINE__
);
125 /* Create the device specific screen private data struct.
128 sisCreateScreen( __DRIscreenPrivate
*sPriv
)
130 sisScreenPtr sisScreen
;
131 SISDRIPtr sisDRIPriv
= (SISDRIPtr
)sPriv
->pDevPriv
;
133 if (sPriv
->devPrivSize
!= sizeof(SISDRIRec
)) {
134 fprintf(stderr
,"\nERROR! sizeof(SISDRIRec) does not match passed size from device driver\n");
138 /* Allocate the private area */
139 sisScreen
= (sisScreenPtr
)CALLOC( sizeof(*sisScreen
) );
140 if ( sisScreen
== NULL
)
143 sisScreen
->screenX
= sisDRIPriv
->width
;
144 sisScreen
->screenY
= sisDRIPriv
->height
;
145 sisScreen
->cpp
= sisDRIPriv
->bytesPerPixel
;
146 sisScreen
->deviceID
= sisDRIPriv
->deviceID
;
147 sisScreen
->AGPCmdBufOffset
= sisDRIPriv
->AGPCmdBufOffset
;
148 sisScreen
->AGPCmdBufSize
= sisDRIPriv
->AGPCmdBufSize
;
149 sisScreen
->sarea_priv_offset
= sizeof(drm_sarea_t
);
151 sisScreen
->mmio
.handle
= sisDRIPriv
->regs
.handle
;
152 sisScreen
->mmio
.size
= sisDRIPriv
->regs
.size
;
153 if ( drmMap( sPriv
->fd
, sisScreen
->mmio
.handle
, sisScreen
->mmio
.size
,
154 &sisScreen
->mmio
.map
) )
160 if (sisDRIPriv
->agp
.size
) {
161 sisScreen
->agp
.handle
= sisDRIPriv
->agp
.handle
;
162 sisScreen
->agp
.size
= sisDRIPriv
->agp
.size
;
163 if ( drmMap( sPriv
->fd
, sisScreen
->agp
.handle
, sisScreen
->agp
.size
,
164 &sisScreen
->agp
.map
) )
166 sisScreen
->agp
.size
= 0;
170 sisScreen
->driScreen
= sPriv
;
172 /* parse information in __driConfigOptions */
173 driParseOptionInfo(&sisScreen
->optionCache
,
174 __driConfigOptions
, __driNConfigOptions
);
179 /* Destroy the device specific screen private data struct.
182 sisDestroyScreen( __DRIscreenPrivate
*sPriv
)
184 sisScreenPtr sisScreen
= (sisScreenPtr
)sPriv
->private;
186 if ( sisScreen
== NULL
)
189 if (sisScreen
->agp
.size
!= 0)
190 drmUnmap( sisScreen
->agp
.map
, sisScreen
->agp
.size
);
191 drmUnmap( sisScreen
->mmio
.map
, sisScreen
->mmio
.size
);
194 sPriv
->private = NULL
;
198 /* Create and initialize the Mesa and driver specific pixmap buffer
202 sisCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
203 __DRIdrawablePrivate
*driDrawPriv
,
204 const __GLcontextModes
*mesaVis
,
207 sisScreenPtr screen
= (sisScreenPtr
) driScrnPriv
->private;
208 struct gl_framebuffer
*fb
;
211 return GL_FALSE
; /* not implemented */
213 fb
= _mesa_create_framebuffer(mesaVis
);
215 _mesa_add_soft_renderbuffers(fb
,
216 GL_FALSE
, /* color */
217 GL_FALSE
, /* depth */
218 mesaVis
->stencilBits
> 0,
219 mesaVis
->accumRedBits
> 0,
220 GL_FALSE
, /* alpha */
222 driDrawPriv
->driverPrivate
= (void *) fb
;
224 return (driDrawPriv
->driverPrivate
!= NULL
);
229 sisDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
231 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
234 __inline__
static void
235 sis_bitblt_copy_cmd (sisContextPtr smesa
, ENGPACKET
* pkt
)
237 GLint
*lpdwDest
, *lpdwSrc
;
240 lpdwSrc
= (GLint
*) pkt
;
241 lpdwDest
= (GLint
*) (GET_IOBase (smesa
) + REG_SRC_ADDR
);
243 mWait3DCmdQueue (10);
245 for (i
= 0; i
< 7; i
++)
246 *lpdwDest
++ = *lpdwSrc
++;
248 MMIO(REG_CMD0
, *(GLint
*)&pkt
->stdwCmd
);
249 MMIO(REG_CommandQueue
, -1);
252 static void sisCopyBuffer( __DRIdrawablePrivate
*dPriv
)
254 sisContextPtr smesa
= (sisContextPtr
)dPriv
->driContextPriv
->driverPrivate
;
256 ENGPACKET stEngPacket
;
258 memset(&stEngPacket
, 0, sizeof(ENGPACKET
));
260 while ((*smesa
->FrameCountPtr
) - MMIO_READ(0x8a2c) > SIS_MAX_FRAME_LENGTH
)
265 stEngPacket
.dwSrcBaseAddr
= smesa
->back
.offset
;
266 stEngPacket
.dwSrcPitch
= smesa
->back
.pitch
|
267 ((smesa
->bytesPerPixel
== 2) ? 0x80000000 : 0xc0000000);
268 stEngPacket
.dwDestBaseAddr
= 0;
269 stEngPacket
.wDestPitch
= smesa
->front
.pitch
;
270 /* TODO: set maximum value? */
271 stEngPacket
.wDestHeight
= smesa
->virtualY
;
273 stEngPacket
.stdwCmd
.cRop
= 0xcc;
275 if (smesa
->blockWrite
)
276 stEngPacket
.stdwCmd
.cCmd0
= CMD0_PAT_FG_COLOR
;
278 stEngPacket
.stdwCmd
.cCmd0
= 0;
279 stEngPacket
.stdwCmd
.cCmd1
= CMD1_DIR_X_INC
| CMD1_DIR_Y_INC
;
281 for (i
= 0; i
< dPriv
->numClipRects
; i
++) {
282 drm_clip_rect_t
*box
= &dPriv
->pClipRects
[i
];
283 stEngPacket
.stdwSrcPos
.wY
= box
->y1
- dPriv
->y
;
284 stEngPacket
.stdwSrcPos
.wX
= box
->x1
- dPriv
->x
;
285 stEngPacket
.stdwDestPos
.wY
= box
->y1
;
286 stEngPacket
.stdwDestPos
.wX
= box
->x1
;
288 stEngPacket
.stdwDim
.wWidth
= (GLshort
) box
->x2
- box
->x1
;
289 stEngPacket
.stdwDim
.wHeight
= (GLshort
) box
->y2
- box
->y1
;
290 sis_bitblt_copy_cmd( smesa
, &stEngPacket
);
293 *(GLint
*)(smesa
->IOBase
+0x8a2c) = *smesa
->FrameCountPtr
;
294 (*smesa
->FrameCountPtr
)++;
300 /* Copy the back color buffer to the front color buffer */
302 sisSwapBuffers(__DRIdrawablePrivate
*dPriv
)
304 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
305 sisContextPtr smesa
= (sisContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
306 GLcontext
*ctx
= smesa
->glCtx
;
308 if (ctx
->Visual
.doubleBufferMode
) {
309 _mesa_notifySwapBuffers( ctx
); /* flush pending rendering comands */
310 sisCopyBuffer( dPriv
);
313 /* XXX this shouldn't be an error but we can't handle it for now */
314 _mesa_problem(NULL
, "%s: drawable has no context!", __FUNCTION__
);
319 /* Initialize the driver specific screen private data.
322 sisInitDriver( __DRIscreenPrivate
*sPriv
)
324 sPriv
->private = (void *) sisCreateScreen( sPriv
);
326 if ( !sPriv
->private ) {
327 sisDestroyScreen( sPriv
);
334 static struct __DriverAPIRec sisAPI
= {
335 .InitDriver
= sisInitDriver
,
336 .DestroyScreen
= sisDestroyScreen
,
337 .CreateContext
= sisCreateContext
,
338 .DestroyContext
= sisDestroyContext
,
339 .CreateBuffer
= sisCreateBuffer
,
340 .DestroyBuffer
= sisDestroyBuffer
,
341 .SwapBuffers
= sisSwapBuffers
,
342 .MakeCurrent
= sisMakeCurrent
,
343 .UnbindContext
= sisUnbindContext
,
348 .SwapBuffersMSC
= NULL
354 * This is the bootstrap function for the driver. libGL supplies all of the
355 * requisite information about the system, and the driver initializes itself.
356 * This routine also fills in the linked list pointed to by \c driver_modes
357 * with the \c __GLcontextModes that the driver can support for windows or
360 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
364 void * __driCreateNewScreen_20050727( __DRInativeDisplay
*dpy
, int scrn
,
366 const __GLcontextModes
*modes
,
367 const __DRIversion
*ddx_version
,
368 const __DRIversion
*dri_version
,
369 const __DRIversion
*drm_version
,
370 const __DRIframebuffer
*frame_buffer
,
371 drmAddress pSAREA
, int fd
,
372 int internal_api_version
,
373 const __DRIinterfaceMethods
* interface
,
374 __GLcontextModes
**driver_modes
)
377 __DRIscreenPrivate
*psp
;
378 static const __DRIversion ddx_expected
= {0, 8, 0};
379 static const __DRIversion dri_expected
= {4, 0, 0};
380 static const __DRIversion drm_expected
= {1, 0, 0};
382 dri_interface
= interface
;
384 if (!driCheckDriDdxDrmVersions2("SiS", dri_version
, &dri_expected
,
385 ddx_version
, &ddx_expected
,
386 drm_version
, &drm_expected
)) {
390 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
391 ddx_version
, dri_version
, drm_version
,
392 frame_buffer
, pSAREA
, fd
,
393 internal_api_version
, &sisAPI
);
395 SISDRIPtr dri_priv
= (SISDRIPtr
)psp
->pDevPriv
;
396 *driver_modes
= sisFillInModes(dri_priv
->bytesPerPixel
* 8);
398 /* Calling driInitExtensions here, with a NULL context pointer, does not actually
399 * enable the extensions. It just makes sure that all the dispatch offsets for all
400 * the extensions that *might* be enables are known. This is needed because the
401 * dispatch offsets need to be known when _mesa_context_create is called, but we can't
402 * enable the extensions until we have a context pointer.
404 * Hello chicken. Hello egg. How are you two today?
406 driInitExtensions( NULL
, card_extensions
, GL_FALSE
);