1 /**************************************************************************
3 Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
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 OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
31 * Sung-Ching Lin <sclin@sis.com.tw>
32 * Eric Anholt <anholt@FreeBSD.org>
41 #include "drm_sarea.h"
42 #include "xmlconfig.h"
43 #include "tnl/t_vertex.h"
45 #include "sis_screen.h"
46 #include "sis_common2.h"
52 #define PCI_CHIP_SIS300 0x0300
53 #define PCI_CHIP_SIS630 0x6300
54 #define PCI_CHIP_SIS540 0x5300
56 #define NEW_TEXTURING 0x1
57 #define NEW_TEXTURE_ENV 0x2
59 /* Flags for software fallback cases:
61 #define SIS_FALLBACK_TEXTURE 0x0001
62 #define SIS_FALLBACK_TEXTURE0 0x0002
63 #define SIS_FALLBACK_TEXTURE1 0x0004
64 #define SIS_FALLBACK_TEXENV0 0x0008
65 #define SIS_FALLBACK_TEXENV1 0x0010
66 #define SIS_FALLBACK_DRAW_BUFFER 0x0020
67 #define SIS_FALLBACK_STENCIL 0x0040
68 #define SIS_FALLBACK_FORCE 0x8000
70 /* Flags for hardware state that needs to be updated */
71 #define GFLAG_ENABLESETTING 0x00000001
72 #define GFLAG_ENABLESETTING2 0x00000002
73 #define GFLAG_ZSETTING 0x00000004
74 #define GFLAG_ALPHASETTING 0x00000008
75 #define GFLAG_DESTSETTING 0x00000010
76 #define GFLAG_LINESETTING 0x00000020
77 #define GFLAG_STENCILSETTING 0x00000040
78 #define GFLAG_FOGSETTING 0x00000080
79 #define GFLAG_DSTBLEND 0x00000100
80 #define GFLAG_CLIPPING 0x00000200
81 #define CFLAG_TEXTURERESET 0x00000400
82 #define GFLAG_TEXTUREMIPMAP 0x00000800
83 #define GFLAG_TEXBORDERCOLOR 0x00001000
84 #define GFLAG_TEXTUREADDRESS 0x00002000
85 #define GFLAG_TEXTUREENV 0x00004000
86 #define CFLAG_TEXTURERESET_1 0x00008000
87 #define GFLAG_TEXTUREMIPMAP_1 0x00010000
88 #define GFLAG_TEXBORDERCOLOR_1 0x00020000
89 #define GFLAG_TEXTUREADDRESS_1 0x00040000
90 #define GFLAG_TEXTUREENV_1 0x00080000
91 #define GFLAG_ALL 0x000fffff
93 #define GFLAG_TEXTURE_STATES (CFLAG_TEXTURERESET | GFLAG_TEXTUREMIPMAP | \
94 GFLAG_TEXBORDERCOLOR | GFLAG_TEXTUREADDRESS | \
95 CFLAG_TEXTURERESET_1 | GFLAG_TEXTUREMIPMAP_1 | \
96 GFLAG_TEXBORDERCOLOR_1 | \
97 GFLAG_TEXTUREADDRESS_1 | \
98 GFLAG_TEXTUREENV | GFLAG_TEXTUREENV_1)
101 #define GFLAG_RENDER_STATES (GFLAG_ENABLESETTING | GFLAG_ENABLESETTING2 | \
102 GFLAG_ZSETTING | GFLAG_ALPHASETTING | \
103 GFLAG_DESTSETTING | GFLAG_FOGSETTING | \
104 GFLAG_STENCILSETTING | GFLAG_DSTBLEND | \
107 /* Use the templated vertex format:
109 #define TAG(x) sis##x
110 #include "tnl_dd/t_dd_vertex.h"
113 /* Subpixel offsets for window coordinates (triangles):
115 #define SUBPIXEL_X (-0.5F)
116 #define SUBPIXEL_Y (-0.5F)
118 #define SIS_MAX_TEXTURE_LEVELS 11
121 GLubyte
*Data
; /* Pointer to texture in offscreen */
122 GLuint memType
; /* VIDEO_TYPE or AGP_TYPE */
123 void *handle
; /* Handle for sisFree*() */
128 typedef struct sis_tex_obj
{
129 sisTexImage image
[SIS_MAX_TEXTURE_LEVELS
]; /* Image data for each mipmap
131 GLenum format
; /* One of GL_ALPHA, GL_INTENSITY, GL_LUMINANCE,
132 * GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA */
133 GLint hwformat
; /* One of the TEXEL_ defines */
134 GLint numImages
; /* Number of images loaded into .image */
135 } sisTexObj
, *sisTexObjPtr
;
138 ** Device dependent context state
140 typedef struct __GLSiSTextureRec
144 GLint hwTextureClrHigh
;
145 GLint hwTextureClrLow
;
146 GLint hwTextureBorderColor
;
169 typedef struct __GLSiSHardwareRec
171 GLint hwCapEnable
, hwCapEnable2
; /* Enable Setting */
173 GLint hwOffsetZ
, hwZ
; /* Z Setting */
175 GLint hwZBias
, hwZMask
; /* Z Setting */
177 GLint hwAlpha
; /* Alpha Setting */
179 GLint hwDstSet
, hwDstMask
; /* Destination Setting */
181 GLint hwOffsetDest
; /* Destination Setting */
183 GLint hwLinePattern
; /* Line Setting */
185 GLint hwFog
; /* Fog Setting */
187 GLint hwFogFar
, hwFogInverse
; /* Fog Distance setting */
189 GLint hwFogDensity
; /* Fog factor & density */
191 GLint hwStSetting
, hwStSetting2
; /* Stencil Setting */
193 GLint hwStOffset
; /* Stencil Setting */
195 GLint hwDstSrcBlend
; /* Blending mode Setting */
197 GLint clipTopBottom
; /* Clip for Top & Bottom */
199 GLint clipLeftRight
; /* Clip for Left & Right */
201 struct __GLSiSTextureRec texture
[2];
203 GLint hwTexEnvColor
; /* Texture Blending Setting */
205 GLint hwTexBlendColor0
;
206 GLint hwTexBlendColor1
;
207 GLint hwTexBlendAlpha0
;
208 GLint hwTexBlendAlpha1
;
213 typedef struct sis_context sisContextRec
;
214 typedef struct sis_context
*sisContextPtr
;
216 typedef void (*sis_quad_func
)( sisContextPtr
,
222 typedef void (*sis_tri_func
)( sisContextPtr
,
227 typedef void (*sis_line_func
)( sisContextPtr
,
231 typedef void (*sis_point_func
)( sisContextPtr
,
234 /* Device dependent context state */
238 /* This must be first in this structure */
243 struct tnl_attr_map vertex_attrs
[VERT_ATTRIB_MAX
];
244 GLuint vertex_attr_count
;
245 char *verts
; /* points to tnl->clipspace.vertex_buf */
247 /* Vertex buffer (in system memory or AGP) state. */
248 unsigned char *vb
; /* Beginning of vertex buffer */
249 unsigned char *vb_cur
; /* Current write location in vertex buffer */
250 unsigned char *vb_last
; /* Last written location in vertex buffer */
251 unsigned char *vb_end
; /* End of vertex buffer */
253 GLuint vb_agp_offset
;
259 GLfloat hw_viewport
[16];
262 unsigned int virtualX
, virtualY
;
263 unsigned int bytesPerPixel
;
264 unsigned char *IOBase
;
265 unsigned char *FbBase
;
266 unsigned int displayWidth
;
267 unsigned int frontOffset
;
268 unsigned int frontPitch
;
271 unsigned int redMask
, greenMask
, blueMask
, alphaMask
;
272 unsigned int colorFormat
;
275 unsigned int zFormat
;
277 /* Clear patterns, 4 bytes */
278 unsigned int clearColorPattern
;
279 unsigned int clearZStencilPattern
;
281 /* Fallback rasterization functions
283 sis_point_func draw_point
;
284 sis_line_func draw_line
;
285 sis_tri_func draw_tri
;
286 sis_quad_func draw_quad
;
289 GLenum raster_primitive
;
290 GLenum render_primitive
;
296 unsigned int AGPSize
;
297 unsigned char *AGPBase
;
298 unsigned int AGPAddr
;
300 /* register 0x89F4 */
303 /* register 0x89F8 */
304 GLint dwPrimitiveSet
;
306 __GLSiSHardware prev
, current
;
312 /* SGRAM block write */
313 GLboolean blockWrite
;
316 GLuint last_tcl_state
;
320 GLboolean stereoEnabled
;
321 int stereo_drawIndex
;
323 GLboolean irqEnabled
;
325 GLboolean clearTexCache
;
327 GLuint TexStates
[SIS_MAX_TEXTURES
];
328 GLuint PrevTexFormat
[SIS_MAX_TEXTURES
];
330 int *CurrentQueueLenPtr
;
331 unsigned int *FrameCountPtr
;
333 /* Front/back/depth buffer info */
334 GLuint width
, height
; /* size of buffers */
335 GLint bottom
; /* used for FLIP macro */
337 unsigned int backOffset
;
338 unsigned int backPitch
;
340 unsigned int depthOffset
;
341 unsigned int depthPitch
;
342 void *zbFree
, *bbFree
; /* Cookies for freeing buffers */
343 ENGPACKET zClearPacket
, cbClearPacket
;
345 /* Drawable, cliprect and scissor information
347 GLint drawOffset
, drawPitch
;
349 /* Mirrors of some DRI state
351 __DRIcontextPrivate
*driContext
; /* DRI context */
352 __DRIscreenPrivate
*driScreen
; /* DRI screen */
353 __DRIdrawablePrivate
*driDrawable
; /* DRI drawable bound to this ctx */
355 unsigned int lastStamp
; /* mirror driDrawable->lastStamp */
357 drm_context_t hHWContext
;
358 drm_hw_lock_t
*driHwLock
;
360 sisScreenPtr sisScreen
; /* Screen private DRI data */
361 SISSAREAPrivPtr sarea
; /* Private SAREA data */
363 /* Configuration cache */
364 driOptionCache optionCache
;
367 #define SIS_CONTEXT(ctx) ((sisContextPtr)(ctx->DriverCtx))
370 #define GET_IOBase(x) ((x)->IOBase)
372 #define Y_FLIP(Y) (smesa->bottom - (Y))
374 #define SISPACKCOLOR565( r, g, b ) \
375 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
377 #define SISPACKCOLOR8888( r, g, b, a ) \
378 (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
380 #define SIS_VERBOSE 0
383 #define MMIO(reg, value) \
385 *(volatile GLint *)(smesa->IOBase + (reg)) = value; \
388 #define MMIO_READ(reg) *(volatile GLint *)(smesa->IOBase + (reg))
389 #define MMIO_READf(reg) *(volatile GLfloat *)(smesa->IOBase + (reg))
391 #define mEndPrimitive() \
393 *(volatile GLubyte *)(smesa->IOBase + REG_3D_EndPrimitiveList) = 0xff; \
394 *(volatile GLuint *)(smesa->IOBase + 0x8b60) = 0xffffffff; \
397 #define sis_fatal_error(msg) \
399 fprintf(stderr, "[%s:%d]: %s", __FILE__, __LINE__, msg); \
404 #define mWait3DCmdQueue(wLen) \
405 /* Update the mirrored queue pointer if it doesn't indicate enough space */ \
406 if (*(smesa->CurrentQueueLenPtr) < (wLen)) { \
407 *(smesa->CurrentQueueLenPtr) = \
408 (*(GLint *)(GET_IOBase(smesa) + REG_CommandQueue) & MASK_QueueLen) - 20; \
409 /* Spin and wait if the queue is actually too full */ \
410 if (*(smesa->CurrentQueueLenPtr) < (wLen)) \
411 WaitingFor3dIdle(smesa, wLen); \
412 *(smesa->CurrentQueueLenPtr) -= wLen; \
416 VERBOSE_SIS_BUFFER
= 0x1,
417 VERBOSE_SIS_MEMORY
= 0x2
420 extern GLboolean
sisCreateContext( const __GLcontextModes
*glVisual
,
421 __DRIcontextPrivate
*driContextPriv
,
422 void *sharedContextPrivate
);
423 extern void sisDestroyContext( __DRIcontextPrivate
* );
425 extern GLboolean
sisMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
426 __DRIdrawablePrivate
*driDrawPriv
,
427 __DRIdrawablePrivate
*driReadPriv
);
429 extern GLboolean
sisUnbindContext( __DRIcontextPrivate
*driContextPriv
);
431 void WaitEngIdle (sisContextPtr smesa
);
432 void Wait2DEngIdle (sisContextPtr smesa
);
433 void WaitingFor3dIdle(sisContextPtr smesa
, int wLen
);
436 extern void sis_update_texture_state( sisContextPtr smesa
);
437 extern void sis_update_render_state( sisContextPtr smesa
);