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>
33 #include "main/context.h"
35 #include "main/imports.h"
36 #include "main/framebuffer.h"
37 #include "main/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 const __DRIconfig
**
68 sisFillInModes(__DRIscreenPrivate
*psp
, int bpp
)
70 __DRIconfig
**configs
;
71 unsigned depth_buffer_factor
;
72 unsigned back_buffer_factor
;
75 static const GLenum back_buffer_modes
[] = {
76 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
78 uint8_t depth_bits_array
[4];
79 uint8_t stencil_bits_array
[4];
80 uint8_t msaa_samples_array
[1];
82 depth_bits_array
[0] = 0;
83 stencil_bits_array
[0] = 0;
84 depth_bits_array
[1] = 16;
85 stencil_bits_array
[1] = 0;
86 depth_bits_array
[2] = 24;
87 stencil_bits_array
[2] = 8;
88 depth_bits_array
[3] = 32;
89 stencil_bits_array
[3] = 0;
91 msaa_samples_array
[0] = 0;
93 depth_buffer_factor
= 4;
94 back_buffer_factor
= 2;
98 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
101 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
104 configs
= driCreateConfigs(fb_format
, fb_type
, depth_bits_array
,
105 stencil_bits_array
, depth_buffer_factor
,
106 back_buffer_modes
, back_buffer_factor
,
107 msaa_samples_array
, 1);
108 if (configs
== NULL
) {
109 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
, __LINE__
);
113 return (const __DRIconfig
**) configs
;
117 /* Create the device specific screen private data struct.
120 sisCreateScreen( __DRIscreenPrivate
*sPriv
)
122 sisScreenPtr sisScreen
;
123 SISDRIPtr sisDRIPriv
= (SISDRIPtr
)sPriv
->pDevPriv
;
125 if (sPriv
->devPrivSize
!= sizeof(SISDRIRec
)) {
126 fprintf(stderr
,"\nERROR! sizeof(SISDRIRec) does not match passed size from device driver\n");
130 /* Allocate the private area */
131 sisScreen
= (sisScreenPtr
)CALLOC( sizeof(*sisScreen
) );
132 if ( sisScreen
== NULL
)
135 sisScreen
->screenX
= sisDRIPriv
->width
;
136 sisScreen
->screenY
= sisDRIPriv
->height
;
137 sisScreen
->cpp
= sisDRIPriv
->bytesPerPixel
;
138 sisScreen
->deviceID
= sisDRIPriv
->deviceID
;
139 sisScreen
->AGPCmdBufOffset
= sisDRIPriv
->AGPCmdBufOffset
;
140 sisScreen
->AGPCmdBufSize
= sisDRIPriv
->AGPCmdBufSize
;
141 sisScreen
->sarea_priv_offset
= sizeof(drm_sarea_t
);
143 sisScreen
->mmio
.handle
= sisDRIPriv
->regs
.handle
;
144 sisScreen
->mmio
.size
= sisDRIPriv
->regs
.size
;
145 if ( drmMap( sPriv
->fd
, sisScreen
->mmio
.handle
, sisScreen
->mmio
.size
,
146 &sisScreen
->mmio
.map
) )
152 if (sisDRIPriv
->agp
.size
) {
153 sisScreen
->agp
.handle
= sisDRIPriv
->agp
.handle
;
154 sisScreen
->agpBaseOffset
= drmAgpBase(sPriv
->fd
);
155 sisScreen
->agp
.size
= sisDRIPriv
->agp
.size
;
156 if ( drmMap( sPriv
->fd
, sisScreen
->agp
.handle
, sisScreen
->agp
.size
,
157 &sisScreen
->agp
.map
) )
159 sisScreen
->agp
.size
= 0;
163 sisScreen
->driScreen
= sPriv
;
165 /* parse information in __driConfigOptions */
166 driParseOptionInfo(&sisScreen
->optionCache
,
167 __driConfigOptions
, __driNConfigOptions
);
172 /* Destroy the device specific screen private data struct.
175 sisDestroyScreen( __DRIscreenPrivate
*sPriv
)
177 sisScreenPtr sisScreen
= (sisScreenPtr
)sPriv
->private;
179 if ( sisScreen
== NULL
)
182 if (sisScreen
->agp
.size
!= 0)
183 drmUnmap( sisScreen
->agp
.map
, sisScreen
->agp
.size
);
184 drmUnmap( sisScreen
->mmio
.map
, sisScreen
->mmio
.size
);
187 sPriv
->private = NULL
;
191 /* Create and initialize the Mesa and driver specific pixmap buffer
195 sisCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
196 __DRIdrawablePrivate
*driDrawPriv
,
197 const __GLcontextModes
*mesaVis
,
200 /*sisScreenPtr screen = (sisScreenPtr) driScrnPriv->private;*/
201 struct gl_framebuffer
*fb
;
204 return GL_FALSE
; /* not implemented */
206 fb
= _mesa_create_framebuffer(mesaVis
);
208 _mesa_add_soft_renderbuffers(fb
,
209 GL_FALSE
, /* color */
210 GL_FALSE
, /* depth */
211 mesaVis
->stencilBits
> 0,
212 mesaVis
->accumRedBits
> 0,
213 GL_FALSE
, /* alpha */
215 driDrawPriv
->driverPrivate
= (void *) fb
;
217 return (driDrawPriv
->driverPrivate
!= NULL
);
222 sisDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
224 _mesa_reference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)), NULL
);
227 static void sisCopyBuffer( __DRIdrawablePrivate
*dPriv
)
229 sisContextPtr smesa
= (sisContextPtr
)dPriv
->driContextPriv
->driverPrivate
;
232 while ((*smesa
->FrameCountPtr
) - MMIO_READ(0x8a2c) > SIS_MAX_FRAME_LENGTH
)
237 for (i
= 0; i
< dPriv
->numClipRects
; i
++) {
238 drm_clip_rect_t
*box
= &dPriv
->pClipRects
[i
];
241 MMIO(REG_SRC_ADDR
, smesa
->back
.offset
);
242 MMIO(REG_SRC_PITCH
, smesa
->back
.pitch
| ((smesa
->bytesPerPixel
== 4) ?
243 BLIT_DEPTH_32
: BLIT_DEPTH_16
));
244 MMIO(REG_SRC_X_Y
, ((box
->x1
- dPriv
->x
) << 16) | (box
->y1
- dPriv
->y
));
245 MMIO(REG_DST_X_Y
, ((box
->x1
- dPriv
->x
) << 16) | (box
->y1
- dPriv
->y
));
246 MMIO(REG_DST_ADDR
, smesa
->front
.offset
);
247 MMIO(REG_DST_PITCH_HEIGHT
, (smesa
->virtualY
<< 16) | smesa
->front
.pitch
);
248 MMIO(REG_WIDTH_HEIGHT
, ((box
->y2
- box
->y1
) << 16) | (box
->x2
- box
->x1
));
249 MMIO(REG_BLIT_CMD
, CMD_DIR_X_INC
| CMD_DIR_Y_INC
| CMD_ROP_SRC
);
250 MMIO(REG_CommandQueue
, -1);
253 *(GLint
*)(smesa
->IOBase
+0x8a2c) = *smesa
->FrameCountPtr
;
254 (*smesa
->FrameCountPtr
)++;
260 /* Copy the back color buffer to the front color buffer */
262 sisSwapBuffers(__DRIdrawablePrivate
*dPriv
)
264 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
265 sisContextPtr smesa
= (sisContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
266 GLcontext
*ctx
= smesa
->glCtx
;
268 if (ctx
->Visual
.doubleBufferMode
) {
269 _mesa_notifySwapBuffers( ctx
); /* flush pending rendering comands */
270 sisCopyBuffer( dPriv
);
273 /* XXX this shouldn't be an error but we can't handle it for now */
274 _mesa_problem(NULL
, "%s: drawable has no context!", __FUNCTION__
);
280 * This is the driver specific part of the createNewScreen entry point.
282 * \todo maybe fold this into intelInitDriver
284 * \return the __GLcontextModes supported by this driver
286 static const __DRIconfig
**
287 sisInitScreen(__DRIscreenPrivate
*psp
)
289 static const __DRIversion ddx_expected
= {0, 8, 0};
290 static const __DRIversion dri_expected
= {4, 0, 0};
291 static const __DRIversion drm_expected
= {1, 0, 0};
292 static const char *driver_name
= "SiS";
293 SISDRIPtr dri_priv
= (SISDRIPtr
)psp
->pDevPriv
;
295 if (!driCheckDriDdxDrmVersions2(driver_name
,
296 &psp
->dri_version
, &dri_expected
,
297 &psp
->ddx_version
, &ddx_expected
,
298 &psp
->drm_version
, &drm_expected
))
301 psp
->private = sisCreateScreen(psp
);
304 sisDestroyScreen(psp
);
308 return sisFillInModes(psp
, dri_priv
->bytesPerPixel
* 8);
311 const struct __DriverAPIRec driDriverAPI
= {
312 .InitScreen
= sisInitScreen
,
313 .DestroyScreen
= sisDestroyScreen
,
314 .CreateContext
= sisCreateContext
,
315 .DestroyContext
= sisDestroyContext
,
316 .CreateBuffer
= sisCreateBuffer
,
317 .DestroyBuffer
= sisDestroyBuffer
,
318 .SwapBuffers
= sisSwapBuffers
,
319 .MakeCurrent
= sisMakeCurrent
,
320 .UnbindContext
= sisUnbindContext
,
322 .GetDrawableMSC
= NULL
,
325 .SwapBuffersMSC
= NULL