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];
81 depth_bits_array
[0] = 0;
82 stencil_bits_array
[0] = 0;
83 depth_bits_array
[1] = 16;
84 stencil_bits_array
[1] = 0;
85 depth_bits_array
[2] = 24;
86 stencil_bits_array
[2] = 8;
87 depth_bits_array
[3] = 32;
88 stencil_bits_array
[3] = 0;
90 depth_buffer_factor
= 4;
91 back_buffer_factor
= 2;
95 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
98 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
101 configs
= driCreateConfigs(fb_format
, fb_type
, depth_bits_array
,
102 stencil_bits_array
, depth_buffer_factor
,
103 back_buffer_modes
, back_buffer_factor
);
104 if (configs
== NULL
) {
105 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
, __LINE__
);
109 return (const __DRIconfig
**) configs
;
113 /* Create the device specific screen private data struct.
116 sisCreateScreen( __DRIscreenPrivate
*sPriv
)
118 sisScreenPtr sisScreen
;
119 SISDRIPtr sisDRIPriv
= (SISDRIPtr
)sPriv
->pDevPriv
;
121 if (sPriv
->devPrivSize
!= sizeof(SISDRIRec
)) {
122 fprintf(stderr
,"\nERROR! sizeof(SISDRIRec) does not match passed size from device driver\n");
126 /* Allocate the private area */
127 sisScreen
= (sisScreenPtr
)CALLOC( sizeof(*sisScreen
) );
128 if ( sisScreen
== NULL
)
131 sisScreen
->screenX
= sisDRIPriv
->width
;
132 sisScreen
->screenY
= sisDRIPriv
->height
;
133 sisScreen
->cpp
= sisDRIPriv
->bytesPerPixel
;
134 sisScreen
->deviceID
= sisDRIPriv
->deviceID
;
135 sisScreen
->AGPCmdBufOffset
= sisDRIPriv
->AGPCmdBufOffset
;
136 sisScreen
->AGPCmdBufSize
= sisDRIPriv
->AGPCmdBufSize
;
137 sisScreen
->sarea_priv_offset
= sizeof(drm_sarea_t
);
139 sisScreen
->mmio
.handle
= sisDRIPriv
->regs
.handle
;
140 sisScreen
->mmio
.size
= sisDRIPriv
->regs
.size
;
141 if ( drmMap( sPriv
->fd
, sisScreen
->mmio
.handle
, sisScreen
->mmio
.size
,
142 &sisScreen
->mmio
.map
) )
148 if (sisDRIPriv
->agp
.size
) {
149 sisScreen
->agp
.handle
= sisDRIPriv
->agp
.handle
;
150 sisScreen
->agpBaseOffset
= drmAgpBase(sPriv
->fd
);
151 sisScreen
->agp
.size
= sisDRIPriv
->agp
.size
;
152 if ( drmMap( sPriv
->fd
, sisScreen
->agp
.handle
, sisScreen
->agp
.size
,
153 &sisScreen
->agp
.map
) )
155 sisScreen
->agp
.size
= 0;
159 sisScreen
->driScreen
= sPriv
;
161 /* parse information in __driConfigOptions */
162 driParseOptionInfo(&sisScreen
->optionCache
,
163 __driConfigOptions
, __driNConfigOptions
);
168 /* Destroy the device specific screen private data struct.
171 sisDestroyScreen( __DRIscreenPrivate
*sPriv
)
173 sisScreenPtr sisScreen
= (sisScreenPtr
)sPriv
->private;
175 if ( sisScreen
== NULL
)
178 if (sisScreen
->agp
.size
!= 0)
179 drmUnmap( sisScreen
->agp
.map
, sisScreen
->agp
.size
);
180 drmUnmap( sisScreen
->mmio
.map
, sisScreen
->mmio
.size
);
183 sPriv
->private = NULL
;
187 /* Create and initialize the Mesa and driver specific pixmap buffer
191 sisCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
192 __DRIdrawablePrivate
*driDrawPriv
,
193 const __GLcontextModes
*mesaVis
,
196 /*sisScreenPtr screen = (sisScreenPtr) driScrnPriv->private;*/
197 struct gl_framebuffer
*fb
;
200 return GL_FALSE
; /* not implemented */
202 fb
= _mesa_create_framebuffer(mesaVis
);
204 _mesa_add_soft_renderbuffers(fb
,
205 GL_FALSE
, /* color */
206 GL_FALSE
, /* depth */
207 mesaVis
->stencilBits
> 0,
208 mesaVis
->accumRedBits
> 0,
209 GL_FALSE
, /* alpha */
211 driDrawPriv
->driverPrivate
= (void *) fb
;
213 return (driDrawPriv
->driverPrivate
!= NULL
);
218 sisDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
220 _mesa_unreference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)));
223 static void sisCopyBuffer( __DRIdrawablePrivate
*dPriv
)
225 sisContextPtr smesa
= (sisContextPtr
)dPriv
->driContextPriv
->driverPrivate
;
228 while ((*smesa
->FrameCountPtr
) - MMIO_READ(0x8a2c) > SIS_MAX_FRAME_LENGTH
)
233 for (i
= 0; i
< dPriv
->numClipRects
; i
++) {
234 drm_clip_rect_t
*box
= &dPriv
->pClipRects
[i
];
237 MMIO(REG_SRC_ADDR
, smesa
->back
.offset
);
238 MMIO(REG_SRC_PITCH
, smesa
->back
.pitch
| ((smesa
->bytesPerPixel
== 4) ?
239 BLIT_DEPTH_32
: BLIT_DEPTH_16
));
240 MMIO(REG_SRC_X_Y
, ((box
->x1
- dPriv
->x
) << 16) | (box
->y1
- dPriv
->y
));
241 MMIO(REG_DST_X_Y
, ((box
->x1
- dPriv
->x
) << 16) | (box
->y1
- dPriv
->y
));
242 MMIO(REG_DST_ADDR
, smesa
->front
.offset
);
243 MMIO(REG_DST_PITCH_HEIGHT
, (smesa
->virtualY
<< 16) | smesa
->front
.pitch
);
244 MMIO(REG_WIDTH_HEIGHT
, ((box
->y2
- box
->y1
) << 16) | (box
->x2
- box
->x1
));
245 MMIO(REG_BLIT_CMD
, CMD_DIR_X_INC
| CMD_DIR_Y_INC
| CMD_ROP_SRC
);
246 MMIO(REG_CommandQueue
, -1);
249 *(GLint
*)(smesa
->IOBase
+0x8a2c) = *smesa
->FrameCountPtr
;
250 (*smesa
->FrameCountPtr
)++;
256 /* Copy the back color buffer to the front color buffer */
258 sisSwapBuffers(__DRIdrawablePrivate
*dPriv
)
260 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
261 sisContextPtr smesa
= (sisContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
262 GLcontext
*ctx
= smesa
->glCtx
;
264 if (ctx
->Visual
.doubleBufferMode
) {
265 _mesa_notifySwapBuffers( ctx
); /* flush pending rendering comands */
266 sisCopyBuffer( dPriv
);
269 /* XXX this shouldn't be an error but we can't handle it for now */
270 _mesa_problem(NULL
, "%s: drawable has no context!", __FUNCTION__
);
276 * This is the driver specific part of the createNewScreen entry point.
278 * \todo maybe fold this into intelInitDriver
280 * \return the __GLcontextModes supported by this driver
282 static const __DRIconfig
**
283 sisInitScreen(__DRIscreenPrivate
*psp
)
285 static const __DRIversion ddx_expected
= {0, 8, 0};
286 static const __DRIversion dri_expected
= {4, 0, 0};
287 static const __DRIversion drm_expected
= {1, 0, 0};
288 static const char *driver_name
= "SiS";
289 SISDRIPtr dri_priv
= (SISDRIPtr
)psp
->pDevPriv
;
291 if (!driCheckDriDdxDrmVersions2(driver_name
,
292 &psp
->dri_version
, &dri_expected
,
293 &psp
->ddx_version
, &ddx_expected
,
294 &psp
->drm_version
, &drm_expected
))
297 /* Calling driInitExtensions here, with a NULL context pointer,
298 * does not actually enable the extensions. It just makes sure
299 * that all the dispatch offsets for all the extensions that
300 * *might* be enables are known. This is needed because the
301 * dispatch offsets need to be known when _mesa_context_create is
302 * called, but we can't enable the extensions until we have a
305 * Hello chicken. Hello egg. How are you two today?
307 driInitExtensions( NULL
, card_extensions
, GL_FALSE
);
309 psp
->private = sisCreateScreen(psp
);
312 sisDestroyScreen(psp
);
316 return sisFillInModes(psp
, dri_priv
->bytesPerPixel
* 8);
319 const struct __DriverAPIRec driDriverAPI
= {
320 .InitScreen
= sisInitScreen
,
321 .DestroyScreen
= sisDestroyScreen
,
322 .CreateContext
= sisCreateContext
,
323 .DestroyContext
= sisDestroyContext
,
324 .CreateBuffer
= sisCreateBuffer
,
325 .DestroyBuffer
= sisDestroyBuffer
,
326 .SwapBuffers
= sisSwapBuffers
,
327 .MakeCurrent
= sisMakeCurrent
,
328 .UnbindContext
= sisUnbindContext
,
330 .GetDrawableMSC
= NULL
,
333 .SwapBuffersMSC
= NULL