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"
47 #include "sis6326_reg.h"
53 #define PCI_CHIP_SIS300 0x0300
54 #define PCI_CHIP_SIS630 0x6300
55 #define PCI_CHIP_SIS540 0x5300
57 #define NEW_TEXTURING 0x1
58 #define NEW_TEXTURE_ENV 0x2
60 /* Flags for software fallback cases:
62 #define SIS_FALLBACK_TEXTURE 0x0001
63 #define SIS_FALLBACK_TEXTURE0 0x0002
64 #define SIS_FALLBACK_TEXTURE1 0x0004
65 #define SIS_FALLBACK_TEXENV0 0x0008
66 #define SIS_FALLBACK_TEXENV1 0x0010
67 #define SIS_FALLBACK_DRAW_BUFFER 0x0020
68 #define SIS_FALLBACK_STENCIL 0x0040
69 #define SIS_FALLBACK_WRITEMASK 0x0080
70 #define SIS_FALLBACK_DISABLE 0x0100
72 /* Flags for hardware state that needs to be updated */
73 #define GFLAG_ENABLESETTING 0x00000001
74 #define GFLAG_ENABLESETTING2 0x00000002
75 #define GFLAG_ZSETTING 0x00000004
76 #define GFLAG_ALPHASETTING 0x00000008
77 #define GFLAG_DESTSETTING 0x00000010
78 #define GFLAG_LINESETTING 0x00000020
79 #define GFLAG_STENCILSETTING 0x00000040
80 #define GFLAG_FOGSETTING 0x00000080
81 #define GFLAG_DSTBLEND 0x00000100
82 #define GFLAG_CLIPPING 0x00000200
83 #define CFLAG_TEXTURERESET 0x00000400
84 #define GFLAG_TEXTUREMIPMAP 0x00000800
85 #define GFLAG_TEXBORDERCOLOR 0x00001000
86 #define GFLAG_TEXTUREADDRESS 0x00002000
87 #define GFLAG_TEXTUREENV 0x00004000
88 #define CFLAG_TEXTURERESET_1 0x00008000
89 #define GFLAG_TEXTUREMIPMAP_1 0x00010000
90 #define GFLAG_TEXBORDERCOLOR_1 0x00020000
91 #define GFLAG_TEXTUREADDRESS_1 0x00040000
92 #define GFLAG_TEXTUREENV_1 0x00080000
93 #define GFLAG_ALL 0x000fffff
95 #define GFLAG_TEXTURE_STATES (CFLAG_TEXTURERESET | GFLAG_TEXTUREMIPMAP | \
96 GFLAG_TEXBORDERCOLOR | GFLAG_TEXTUREADDRESS | \
97 CFLAG_TEXTURERESET_1 | GFLAG_TEXTUREMIPMAP_1 | \
98 GFLAG_TEXBORDERCOLOR_1 | \
99 GFLAG_TEXTUREADDRESS_1 | \
100 GFLAG_TEXTUREENV | GFLAG_TEXTUREENV_1)
103 #define GFLAG_RENDER_STATES (GFLAG_ENABLESETTING | GFLAG_ENABLESETTING2 | \
104 GFLAG_ZSETTING | GFLAG_ALPHASETTING | \
105 GFLAG_DESTSETTING | GFLAG_FOGSETTING | \
106 GFLAG_STENCILSETTING | GFLAG_DSTBLEND | \
109 /* Use the templated vertex format:
111 #define TAG(x) sis##x
112 #include "tnl_dd/t_dd_vertex.h"
115 /* Subpixel offsets for window coordinates (triangles):
117 #define SUBPIXEL_X (-0.5F)
118 #define SUBPIXEL_Y (-0.5F)
120 #define SIS_MAX_TEXTURE_SIZE 2048
121 #define SIS_MAX_TEXTURES 2
122 #define SIS_MAX_TEXTURE_LEVELS 11
123 #define SIS_MAX_FRAME_LENGTH 3
126 GLubyte
*Data
; /* Pointer to texture in offscreen */
127 GLuint memType
; /* VIDEO_TYPE or AGP_TYPE */
128 void *handle
; /* Handle for sisFree*() */
133 typedef struct sis_tex_obj
{
134 sisTexImage image
[SIS_MAX_TEXTURE_LEVELS
]; /* Image data for each mipmap
136 GLenum format
; /* One of GL_ALPHA, GL_INTENSITY, GL_LUMINANCE,
137 * GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA
139 GLint hwformat
; /* One of the TEXEL_ defines */
140 GLint numImages
; /* Number of images loaded into .image */
141 } sisTexObj
, *sisTexObjPtr
;
144 ** Device dependent context state
146 typedef struct __GLSiSTextureRec
150 GLint hwTextureClrHigh
;
151 GLint hwTextureClrLow
;
152 GLint hwTexWidthHeight
; /* 6326: Texture Blending Setting */
153 GLint hwTextureBorderColor
;
176 typedef struct __GLSiSHardwareRec
178 GLint hwCapEnable
, hwCapEnable2
; /* Enable Setting */
180 GLint hwOffsetZ
, hwZ
; /* Z Setting */
182 GLint hwZBias
, hwZMask
; /* Z Setting */
184 GLint hwAlpha
; /* Alpha Setting */
186 GLint hwDstSet
, hwDstMask
; /* Destination Setting */
188 GLint hwOffsetDest
; /* Destination Setting */
190 GLint hwLinePattern
; /* Line Setting */
192 GLint hwFog
; /* Fog Setting */
194 GLint hwFogFar
, hwFogInverse
; /* Fog Distance setting */
196 GLint hwFogDensity
; /* Fog factor & density */
198 GLint hwStSetting
, hwStSetting2
; /* Stencil Setting */
200 GLint hwStOffset
; /* Stencil Setting */
202 GLint hwDstSrcBlend
; /* Blending mode Setting */
204 GLint clipTopBottom
; /* Clip for Top & Bottom */
206 GLint clipLeftRight
; /* Clip for Left & Right */
208 struct __GLSiSTextureRec texture
[2];
210 GLint hwTexEnvColor
; /* Texture Blending Setting */
212 GLint hwTexBlendSet
; /* 6326 */
213 GLint hwTexBlendColor0
;
214 GLint hwTexBlendColor1
;
215 GLint hwTexBlendAlpha0
;
216 GLint hwTexBlendAlpha1
;
221 typedef struct sis_context sisContextRec
;
222 typedef struct sis_context
*sisContextPtr
;
224 typedef void (*sis_quad_func
)( sisContextPtr
,
230 typedef void (*sis_tri_func
)( sisContextPtr
,
235 typedef void (*sis_line_func
)( sisContextPtr
,
239 typedef void (*sis_point_func
)( sisContextPtr
,
243 * Derived from gl_renderbuffer.
245 struct sis_renderbuffer
{
246 struct gl_renderbuffer Base
; /* must be first! */
255 /* Device dependent context state */
259 /* This must be first in this structure */
264 struct tnl_attr_map vertex_attrs
[VERT_ATTRIB_MAX
];
265 GLuint vertex_attr_count
;
266 char *verts
; /* points to tnl->clipspace.vertex_buf */
268 /* Vertex buffer (in system memory or AGP) state. */
269 unsigned char *vb
; /* Beginning of vertex buffer */
270 unsigned char *vb_cur
; /* Current write location in vertex buffer */
271 unsigned char *vb_last
; /* Last written location in vertex buffer */
272 unsigned char *vb_end
; /* End of vertex buffer */
274 GLuint vb_agp_offset
;
276 GLint coloroffset
; /* Offset in vertex format of current color */
277 GLint specoffset
; /* Offset in vertex format of specular color */
282 GLfloat hw_viewport
[16];
285 unsigned int virtualX
, virtualY
;
286 unsigned int bytesPerPixel
;
287 unsigned char *IOBase
;
288 unsigned char *FbBase
;
289 unsigned int displayWidth
;
292 unsigned int redMask
, greenMask
, blueMask
, alphaMask
;
293 unsigned int colorFormat
;
296 unsigned int zFormat
;
298 /* Clear patterns, 4 bytes */
299 unsigned int clearColorPattern
;
300 unsigned int clearZStencilPattern
;
302 /* Fallback rasterization functions
304 sis_point_func draw_point
;
305 sis_line_func draw_line
;
306 sis_tri_func draw_tri
;
307 sis_quad_func draw_quad
;
310 GLenum raster_primitive
;
311 GLenum render_primitive
;
317 unsigned int AGPSize
;
318 unsigned char *AGPBase
;
319 unsigned int AGPAddr
;
321 /* register 0x89F4 */
324 /* register 0x89F8 */
325 GLint dwPrimitiveSet
;
327 __GLSiSHardware prev
, current
;
335 DECLARE_RENDERINPUTS(last_tcl_state_bitset
);
339 GLboolean stereoEnabled
;
340 int stereo_drawIndex
;
342 GLboolean irqEnabled
;
344 GLboolean clearTexCache
;
346 GLuint TexStates
[SIS_MAX_TEXTURES
];
347 GLuint PrevTexFormat
[SIS_MAX_TEXTURES
];
349 int *CurrentQueueLenPtr
;
350 unsigned int *FrameCountPtr
;
352 /* Front/back/depth buffer info */
353 GLuint width
, height
; /* size of buffers */
354 GLint bottom
; /* used for FLIP macro */
355 /* XXX These don't belong here. They should be per-drawable state. */
356 struct sis_renderbuffer front
;
357 struct sis_renderbuffer back
;
358 struct sis_renderbuffer depth
;
359 struct sis_renderbuffer stencil
; /* mirrors depth */
361 /* Mirrors of some DRI state
363 __DRIcontextPrivate
*driContext
; /* DRI context */
364 __DRIscreenPrivate
*driScreen
; /* DRI screen */
365 __DRIdrawablePrivate
*driDrawable
; /* DRI drawable bound to this ctx */
367 unsigned int lastStamp
; /* mirror driDrawable->lastStamp */
369 drm_context_t hHWContext
;
370 drm_hw_lock_t
*driHwLock
;
372 sisScreenPtr sisScreen
; /* Screen private DRI data */
373 SISSAREAPrivPtr sarea
; /* Private SAREA data */
375 /* Configuration cache */
376 driOptionCache optionCache
;
380 #define SIS_CONTEXT(ctx) ((sisContextPtr)(ctx->DriverCtx))
383 #define GET_IOBase(x) ((x)->IOBase)
385 #define Y_FLIP(Y) (smesa->bottom - (Y))
387 #define SISPACKCOLOR565( r, g, b ) \
388 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
390 #define SISPACKCOLOR8888( r, g, b, a ) \
391 (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
393 #define SIS_VERBOSE 0
396 #define MMIO(reg, value) \
398 *(volatile GLint *)(smesa->IOBase + (reg)) = value; \
401 #define MMIO_READ(reg) *(volatile GLint *)(smesa->IOBase + (reg))
402 #define MMIO_READf(reg) *(volatile GLfloat *)(smesa->IOBase + (reg))
404 #if defined(__i386__) || defined(__amd64__)
405 #define MMIO_WMB() __asm __volatile("" : : : "memory")
406 #elif defined(__ia64__)
407 #define MMIO_WMB() __asm __volatile("mf" : : : "memory")
409 #error platform needs WMB
412 #define mEndPrimitive() \
414 *(volatile GLubyte *)(smesa->IOBase + REG_3D_EndPrimitiveList) = 0xff; \
415 *(volatile GLuint *)(smesa->IOBase + 0x8b60) = 0xffffffff; \
418 #define sis_fatal_error(...) \
420 fprintf(stderr, "[%s:%d]:", __FILE__, __LINE__); \
421 fprintf(stderr, __VA_ARGS__); \
426 #define mWait3DCmdQueue(wLen) \
427 /* Update the mirrored queue pointer if it doesn't indicate enough space */ \
428 if (*(smesa->CurrentQueueLenPtr) < (wLen)) { \
429 *(smesa->CurrentQueueLenPtr) = \
430 (*(GLint *)(GET_IOBase(smesa) + REG_CommandQueue) & MASK_QueueLen) - 20; \
431 /* Spin and wait if the queue is actually too full */ \
432 if (*(smesa->CurrentQueueLenPtr) < (wLen)) \
433 WaitingFor3dIdle(smesa, wLen); \
434 *(smesa->CurrentQueueLenPtr) -= wLen; \
438 VERBOSE_SIS_BUFFER
= 0x1,
439 VERBOSE_SIS_MEMORY
= 0x2
442 extern GLboolean
sisCreateContext( const __GLcontextModes
*glVisual
,
443 __DRIcontextPrivate
*driContextPriv
,
444 void *sharedContextPrivate
);
445 extern void sisDestroyContext( __DRIcontextPrivate
* );
447 void sisReAllocateBuffers(GLcontext
*ctx
, GLframebuffer
*drawbuffer
,
448 GLuint width
, GLuint height
);
450 extern GLboolean
sisMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
451 __DRIdrawablePrivate
*driDrawPriv
,
452 __DRIdrawablePrivate
*driReadPriv
);
454 extern GLboolean
sisUnbindContext( __DRIcontextPrivate
*driContextPriv
);
456 void WaitEngIdle (sisContextPtr smesa
);
457 void Wait2DEngIdle (sisContextPtr smesa
);
458 void WaitingFor3dIdle(sisContextPtr smesa
, int wLen
);
461 extern void sis_update_texture_state( sisContextPtr smesa
);
462 extern void sis_update_render_state( sisContextPtr smesa
);
463 extern void sis6326_update_texture_state( sisContextPtr smesa
);
464 extern void sis6326_update_render_state( sisContextPtr smesa
);
466 /* ================================================================
472 extern int SIS_DEBUG
;
477 #define DEBUG_FALLBACKS 0x01
479 #endif /* _sis_ctx_h_ */