diff -ruN ../xc/xc/config/cf/host.def xc/config/cf/host.def --- ../xc/xc/config/cf/host.def Tue Aug 12 12:03:47 2003 +++ xc/config/cf/host.def Wed Aug 20 01:48:03 2003 @@ -4,6 +4,8 @@ */ #define XFree86CustomVersion "DRI trunk" +#define DefaultGcc2i386Opt -O2 GccAliasingArgs +#define LibraryCDebugFlags -O2 GccAliasingArgs /* Don't use any special flags by default, but leave this here commented out * so people see how to if they want @@ -31,8 +33,8 @@ #else -#define XF86CardDrivers tdfx i810 mga ati glint vga -#define DriDrivers r200 tdfx mga i810 r128 radeon gamma i830 ffb /* sis */ +#define XF86CardDrivers tdfx i810 mga ati glint vga sis +#define DriDrivers r200 tdfx mga i810 r128 radeon gamma i830 ffb sis #endif diff -ruN ../xc/xc/extras/Mesa/include/GL/glxext.h xc/extras/Mesa/include/GL/glxext.h --- ../xc/xc/extras/Mesa/include/GL/glxext.h Tue Aug 12 12:03:50 2003 +++ xc/extras/Mesa/include/GL/glxext.h Tue Aug 12 12:03:13 2003 @@ -597,7 +597,7 @@ #define GLX_OML_swap_method 1 #endif -#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || defined(_STDINT_H) || defined(_SYS_INTTYPES_H_) +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || defined(_STDINT_H) || defined(_SYS_INTTYPES_H_) || 1 /* Include ISO C99 integer types for OML_sync_control; need a better test */ #include diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/Imakefile xc/lib/GL/mesa/src/drv/sis/Imakefile --- ../xc/xc/lib/GL/mesa/src/drv/sis/Imakefile Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/Imakefile Wed Aug 20 01:48:03 2003 @@ -32,7 +32,7 @@ #include "../../SPARC/Imakefile.inc" #endif -XCOMM SIS_DEFINES = -DSIS_USE_HW_CULL -DSIS_USE_FASTPATH +XCOMM SIS_DEFINES = -DSIS_USE_HW_CULL SIS_DEFINES = -DSIS_USE_HW_CULL XCOMM DEBUG_DEFINES = -DDEBUG_LOCKING @@ -42,8 +42,7 @@ $(DEBUG_DEFINES) $(STEREO_DEFINES) INCLUDES = $(X_INCLUDES) $(MESA_INCLUDES) $(DRI_INCLUDES) - DRIOBJS = $(GLXLIBSRC)/mesa/dri/dri_mesa.o \ - $(GLXLIBSRC)/dri/dri_tmm.o + DRIOBJS = $(GLXLIBSRC)/dri/dri_util.o DRMOBJS = $(GLXLIBSRC)/dri/drm/xf86drm.o \ $(GLXLIBSRC)/dri/drm/xf86drmHash.o \ @@ -59,8 +58,8 @@ #endif SRCS = $(SISSRCS) - OBJS = $(DRIOBJS) $(DRMOBJS) $(COREMESAOBJS) \ - $(MESA_ASM_OBJS) $(SISOBJS) $(HIOBJS) + OBJS = $(LOOBJS) $(DRIOBJS) $(DRMOBJS) $(COREMESAOBJS) \ + $(MESA_ASM_OBJS) $(COMMONOBJS) $(SISOBJS) $(HIOBJS) REQUIREDLIBS = MathLibrary $(LDPRELIB) $(GLXLIB) $(XONLYLIB) diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/Imakefile.inc xc/lib/GL/mesa/src/drv/sis/Imakefile.inc --- ../xc/xc/lib/GL/mesa/src/drv/sis/Imakefile.inc Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/Imakefile.inc Wed Aug 20 01:48:03 2003 @@ -17,14 +17,16 @@ #if BuildXF86DRI DRI_DEFINES = GlxDefines $(SIS_DEFINES) - DRI_INCLUDES = -I$(GLXLIBSRC)/dri -I$(GLXLIBSRC)/glx \ - -I$(INCLUDESRC) -I$(INCLUDESRC)/GL \ - -I$(GLXLIBSRC)/mesa/dri \ + DRI_INCLUDES = -I$(GLXLIBSRC)/dri \ + -I$(GLXLIBSRC)/glx \ + -I$(INCLUDESRC) \ + -I$(INCLUDESRC)/GL \ -I$(SERVERSRC)/GL/dri \ -I$(XF86OSSRC) \ -I$(XF86DRIVERSRC)/sis \ + -I$(XF86COMSRC) \ -I$(GLXLIBSRC)/dri/drm \ - -I$(GLXLIBSRC)/mesa/src/X + -I$(GLXLIBSRC)/include #endif MESA_INCLUDES = -I$(MESASRCDIR)/src -I$(MESASRCDIR)/include \ @@ -57,93 +59,99 @@ STEREO_DEFINES = -DSIS_STEREO=0 #endif - SISSRCS = $(MESADRVSISBUILDDIR)sis_render.c \ - $(MESADRVSISBUILDDIR)sis_mesa.c \ - $(MESADRVSISBUILDDIR)sis_ctx.c \ - $(MESADRVSISBUILDDIR)sis_alloc.c \ + SISSRCS = $(MESADRVSISBUILDDIR)sis_alloc.c \ + $(MESADRVSISBUILDDIR)sis_dd.c \ + $(MESADRVSISBUILDDIR)sis_lock.c \ + $(MESADRVSISBUILDDIR)sis_context.c \ $(MESADRVSISBUILDDIR)sis_fog.c \ $(MESADRVSISBUILDDIR)sis_clear.c \ + $(MESADRVSISBUILDDIR)sis_screen.c \ + $(MESADRVSISBUILDDIR)sis_state.c \ $(MESADRVSISBUILDDIR)sis_stencil.c \ - $(MESADRVSISBUILDDIR)sis_texture.c \ - $(MESADRVSISBUILDDIR)sis_xwin.c \ - $(MESADRVSISBUILDDIR)sis_xmesa.c \ $(MESADRVSISBUILDDIR)sis_span.c \ - $(MESADRVSISBUILDDIR)sis_fastpath.c \ + $(MESADRVSISBUILDDIR)sis_tex.c \ + $(MESADRVSISBUILDDIR)sis_tris.c \ + $(MESADRVSISBUILDDIR)sis_vb.c \ $(DEBUG_SRC) \ $(STEREO_SRC) - SISOBJS = $(MESADRVSISBUILDDIR)sis_render.o \ - $(MESADRVSISBUILDDIR)sis_mesa.o \ - $(MESADRVSISBUILDDIR)sis_ctx.o \ - $(MESADRVSISBUILDDIR)sis_alloc.o \ + SISOBJS = $(MESADRVSISBUILDDIR)sis_alloc.o \ + $(MESADRVSISBUILDDIR)sis_dd.o \ + $(MESADRVSISBUILDDIR)sis_lock.o \ + $(MESADRVSISBUILDDIR)sis_context.o \ $(MESADRVSISBUILDDIR)sis_fog.o \ $(MESADRVSISBUILDDIR)sis_clear.o \ + $(MESADRVSISBUILDDIR)sis_screen.o \ + $(MESADRVSISBUILDDIR)sis_state.o \ $(MESADRVSISBUILDDIR)sis_stencil.o \ - $(MESADRVSISBUILDDIR)sis_texture.o \ - $(MESADRVSISBUILDDIR)sis_xwin.o \ - $(MESADRVSISBUILDDIR)sis_xmesa.o \ $(MESADRVSISBUILDDIR)sis_span.o \ - $(MESADRVSISBUILDDIR)sis_fastpath.o \ + $(MESADRVSISBUILDDIR)sis_tex.o \ + $(MESADRVSISBUILDDIR)sis_tris.o \ + $(MESADRVSISBUILDDIR)sis_vb.o \ $(DEBUG_OBJ) \ $(STEREO_OBJ) - SISUOBJS = $(MESADRVSISBUILDDIR)unshared/sis_render.o \ - $(MESADRVSISBUILDDIR)unshared/sis_mesa.o \ - $(MESADRVSISBUILDDIR)unshared/sis_ctx.o \ - $(MESADRVSISBUILDDIR)unshared/sis_alloc.o \ + SISUOBJS = $(MESADRVSISBUILDDIR)unshared/sis_alloc.o \ + $(MESADRVSISBUILDDIR)unshared/sis_dd.o \ + $(MESADRVSISBUILDDIR)unshared/sis_lock.o \ + $(MESADRVSISBUILDDIR)unshared/sis_context.o \ $(MESADRVSISBUILDDIR)unshared/sis_fog.o \ $(MESADRVSISBUILDDIR)unshared/sis_clear.o \ + $(MESADRVSISBUILDDIR)unshared/sis_screen.o \ + $(MESADRVSISBUILDDIR)unshared/sis_state.o \ $(MESADRVSISBUILDDIR)unshared/sis_stencil.o \ - $(MESADRVSISBUILDDIR)unshared/sis_texture.o \ - $(MESADRVSISBUILDDIR)unshared/sis_xwin.o \ - $(MESADRVSISBUILDDIR)unshared/sis_xmesa.o \ $(MESADRVSISBUILDDIR)unshared/sis_span.o \ - $(MESADRVSISBUILDDIR)unshared/sis_fastpath.o \ + $(MESADRVSISBUILDDIR)unshared/sis_tex.o \ + $(MESADRVSISBUILDDIR)unshared/sis_tris.o \ + $(MESADRVSISBUILDDIR)unshared/sis_vb.o \ $(DEBUG_UOBJ) \ $(STEREO_UOBJ) - SISDOBJS = $(MESADRVSISBUILDDIR)debugger/sis_render.o \ - $(MESADRVSISBUILDDIR)debugger/sis_mesa.o \ - $(MESADRVSISBUILDDIR)debugger/sis_ctx.o \ - $(MESADRVSISBUILDDIR)debugger/sis_alloc.o \ + SISDOBJS = $(MESADRVSISBUILDDIR)debugger/sis_alloc.o \ + $(MESADRVSISBUILDDIR)debugger/sis_dd.o \ + $(MESADRVSISBUILDDIR)debugger/sis_lock.o \ + $(MESADRVSISBUILDDIR)debugger/sis_context.o \ $(MESADRVSISBUILDDIR)debugger/sis_fog.o \ $(MESADRVSISBUILDDIR)debugger/sis_clear.o \ + $(MESADRVSISBUILDDIR)debugger/sis_screen.o \ + $(MESADRVSISBUILDDIR)debugger/sis_state.o \ $(MESADRVSISBUILDDIR)debugger/sis_stencil.o \ - $(MESADRVSISBUILDDIR)debugger/sis_texture.o \ - $(MESADRVSISBUILDDIR)debugger/sis_xwin.o \ - $(MESADRVSISBUILDDIR)debugger/sis_xmesa.o \ $(MESADRVSISBUILDDIR)debugger/sis_span.o \ - $(MESADRVSISBUILDDIR)debugger/sis_fastpath.o \ + $(MESADRVSISBUILDDIR)debugger/sis_tex.o \ + $(MESADRVSISBUILDDIR)debugger/sis_tris.o \ + $(MESADRVSISBUILDDIR)debugger/sis_vb.o \ $(DEBUG_DOBJ) \ $(STEREO_DOBJ) - SISPOBJS = $(MESADRVSISBUILDDIR)profiled/sis_render.o \ - $(MESADRVSISBUILDDIR)profiled/sis_mesa.o \ - $(MESADRVSISBUILDDIR)profiled/sis_ctx.o \ - $(MESADRVSISBUILDDIR)profiled/sis_alloc.o \ + SISPOBJS = $(MESADRVSISBUILDDIR)profiled/sis_alloc.o \ + $(MESADRVSISBUILDDIR)profiled/sis_dd.o \ + $(MESADRVSISBUILDDIR)profiled/sis_lock.o \ + $(MESADRVSISBUILDDIR)profiled/sis_context.o \ $(MESADRVSISBUILDDIR)profiled/sis_fog.o \ $(MESADRVSISBUILDDIR)profiled/sis_clear.o \ + $(MESADRVSISBUILDDIR)profiled/sis_screen.o \ + $(MESADRVSISBUILDDIR)profiled/sis_state.o \ $(MESADRVSISBUILDDIR)profiled/sis_stencil.o \ - $(MESADRVSISBUILDDIR)profiled/sis_texture.o \ - $(MESADRVSISBUILDDIR)profiled/sis_xwin.o \ - $(MESADRVSISBUILDDIR)profiled/sis_xmesa.o \ $(MESADRVSISBUILDDIR)profiled/sis_span.o \ - $(MESADRVSISBUILDDIR)profiled/sis_fastpath.o \ + $(MESADRVSISBUILDDIR)profiled/sis_tex.o \ + $(MESADRVSISBUILDDIR)profiled/sis_tris.o \ + $(MESADRVSISBUILDDIR)profiled/sis_vb.o \ $(DEBUG_POBJ) \ $(STEREO_POBJ) #ifdef NeedToLinkMesaSrc -LinkSourceFile(sis_render.c, $(MESADRVSRCDIR)/sis) -LinkSourceFile(sis_mesa.c, $(MESADRVSRCDIR)/sis) -LinkSourceFile(sis_ctx.c, $(MESADRVSRCDIR)/sis) LinkSourceFile(sis_alloc.c, $(MESADRVSRCDIR)/sis) +LinkSourceFile(sis_dd.c, $(MESADRVSRCDIR)/sis) +LinkSourceFile(sis_lock.c, $(MESADRVSRCDIR)/sis) +LinkSourceFile(sis_context.c, $(MESADRVSRCDIR)/sis) LinkSourceFile(sis_fog.c, $(MESADRVSRCDIR)/sis) LinkSourceFile(sis_clear.c, $(MESADRVSRCDIR)/sis) +LinkSourceFile(sis_screen.c $(MESADRVSRCDIR)/sis) +LinkSourceFile(sis_state.c, $(MESADRVSRCDIR)/sis) LinkSourceFile(sis_stencil.c, $(MESADRVSRCDIR)/sis) -LinkSourceFile(sis_texture.c, $(MESADRVSRCDIR)/sis) -LinkSourceFile(sis_xwin.c, $(MESADRVSRCDIR)/sis) -LinkSourceFile(sis_xmesa.c, $(MESADRVSRCDIR)/sis) LinkSourceFile(sis_span.c, $(MESADRVSRCDIR)/sis) -LinkSourceFile(sis_fastpath.c, $(MESADRVSRCDIR)/sis) +LinkSourceFile(sis_tex.c, $(MESADRVSRCDIR)/sis) +LinkSourceFile(sis_tris.c, $(MESADRVSRCDIR)/sis) +LinkSourceFile(sis_vb.c, $(MESADRVSRCDIR)/sis) #endif diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_alloc.c xc/lib/GL/mesa/src/drv/sis/sis_alloc.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_alloc.c Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_alloc.c Fri Aug 22 15:33:20 2003 @@ -34,18 +34,11 @@ #include -#include "sis_ctx.h" +#include "sis_context.h" #include "sis_mesa.h" +#include "sis_alloc.h" -#if defined(XFree86Server) && !defined(XF86DRI) -# include "xf86fbman.h" -#else -# define CONFIG_DRM_SIS -# include "drm.h" -# undef CONFIG_DRM_SIS -# include "sis_drm.h" -# include -#endif +#include "sis_common.h" #define Z_BUFFER_HW_ALIGNMENT 16 #define Z_BUFFER_HW_PLUS (16 + 4) @@ -67,161 +60,92 @@ #endif #define ALIGNMENT(value, align) (ROUNDUP((value),(align))*(align)) -#if defined(XFree86Server) && !defined(XF86DRI) - -static void * -sis_alloc_fb (__GLSiScontext * hwcx, GLuint size, void **free) -{ - GLcontext *ctx = hwcx->gc; - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - - ScreenPtr pScreen = xmesa->display; - - GLuint offset; - BoxPtr pBox; - - size = ROUNDUP (size, GET_DEPTH (hwcx)); - *free = xf86AllocateLinearOffscreenArea (pScreen, size, 1, - NULL, NULL, NULL); - - if (!*free) - return NULL; - - pBox = &((FBAreaPtr) (*free))->box; - offset = pBox->y1 * GET_PITCH (hwcx) + pBox->x1 * GET_DEPTH (hwcx); - - return GET_FbBase (hwcx) + offset; -} - -static void -sis_free_fb (int hHWContext, void *free) -{ - xf86FreeOffscreenArea ((FBAreaPtr) free); -} - -#else - -int gDRMSubFD = -1; - -/* debug */ -#if 1 - static int _total_video_memory_used = 0; static int _total_video_memory_count = 0; static void * -sis_alloc_fb (__GLSiScontext * hwcx, GLuint size, void **free) +sisAllocFB( sisContextPtr smesa, GLuint size, void **free ) { - GLcontext *ctx = hwcx->gc; - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - drm_sis_mem_t fb; _total_video_memory_used += size; - fb.context = xmesa->driContextPriv->hHWContext; + fb.context = smesa->hHWContext; fb.size = size; - if(ioctl(hwcx->drmSubFD, SIS_IOCTL_FB_ALLOC, &fb) || !fb.offset) + if (drmCommandWriteRead( smesa->driFd, DRM_SIS_FB_ALLOC, &fb, + sizeof(drm_sis_mem_t) ) || fb.offset == NULL) + { return NULL; + } *free = (void *)fb.free; - /* debug */ - /* memset(fb.offset + GET_FbBase(hwcx), 0xff, size); */ - if (SIS_VERBOSE&VERBOSE_SIS_MEMORY) { - fprintf(stderr, "sis_alloc_fb: size=%u, offset=%lu, pid=%lu, count=%d\n", - size, (DWORD)fb.offset, (DWORD)getpid(), + fprintf(stderr, "sisAllocFB: size=%d, offset=%lu, pid=%d, count=%d\n", + size, fb.offset, (GLint)getpid(), ++_total_video_memory_count); } - return (void *)(fb.offset + GET_FbBase(hwcx)); + return (void *)(fb.offset + GET_FbBase(smesa)); } static void -sis_free_fb (int hHWContext, void *free) +sisFreeFB( sisContextPtr smesa, void *free ) { drm_sis_mem_t fb; if (SIS_VERBOSE&VERBOSE_SIS_MEMORY) { - fprintf(stderr, "sis_free_fb: free=%lu, pid=%lu, count=%d\n", - (DWORD)free, (DWORD)getpid(), --_total_video_memory_count); + fprintf(stderr, "sisFreeFB: free=%p, pid=%d, count=%d\n", + free, (GLint)getpid(), --_total_video_memory_count); } - fb.context = hHWContext; - fb.free = (unsigned long)free; - ioctl(gDRMSubFD, SIS_IOCTL_FB_FREE, &fb); + fb.context = smesa->hHWContext; + fb.free = free; + drmCommandWrite( smesa->driFd, DRM_SIS_FB_FREE, &fb, sizeof(drm_sis_mem_t) ); } -#else - static void * -sis_alloc_fb (__GLSiScontext * hwcx, GLuint size, void **free) -{ - static char *vidmem_base = 0x400000; - char *rval = vidmem_base; - - vidmem_base += size; - if(vidmem_base >= 31*0x100000) - return NULL; - - *free = rval + (DWORD)hwcx->FbBase; - - return rval + (DWORD)hwcx->FbBase; -} - -static void -sis_free_fb (int hHWContext, void *free) +sisAllocAGP( sisContextPtr smesa, GLuint size, void **free ) { - return; -} - -#endif - -#endif - -static void * -sis_alloc_agp (__GLSiScontext * hwcx, GLuint size, void **free) -{ - GLcontext *ctx = hwcx->gc; - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - drm_sis_mem_t agp; - if(!hwcx->AGPSize) + if(!smesa->AGPSize) return NULL; - agp.context = xmesa->driContextPriv->hHWContext; + agp.context = smesa->hHWContext; agp.size = size; - if(ioctl(hwcx->drmSubFD, SIS_IOCTL_AGP_ALLOC, &agp) || !agp.offset) + if (drmCommandWriteRead( smesa->driFd, DRM_SIS_AGP_ALLOC, &agp, + sizeof(drm_sis_mem_t) ) || !agp.offset) + { return NULL; + } *free = (void *)agp.free; if (SIS_VERBOSE&VERBOSE_SIS_MEMORY) { - fprintf(stderr, "sis_alloc_agp: size=%u, offset=%lu, pid=%lu, count=%d\n", - size, (DWORD)agp.offset, (DWORD)getpid(), + fprintf(stderr, "sisAllocAGP: size=%u, offset=%lu, pid=%d, count=%d\n", + size, agp.offset, (GLint)getpid(), ++_total_video_memory_count); } - return (void *)(agp.offset + GET_AGPBase(hwcx)); + return (void *)(agp.offset + GET_AGPBase(smesa)); } static void -sis_free_agp (int hHWContext, void *free) +sisFreeAGP( sisContextPtr smesa, void *free ) { drm_sis_mem_t agp; if (SIS_VERBOSE&VERBOSE_SIS_MEMORY) { - fprintf(stderr, "sis_free_agp: free=%lu, pid=%lu, count=%d\n", - (DWORD)free, (DWORD)getpid(), --_total_video_memory_count); + fprintf(stderr, "sisFreeAGP: free=%p, pid=%d, count=%d\n", + free, (GLint)getpid(), --_total_video_memory_count); } - agp.context = hHWContext; - agp.free = (unsigned long)free; - ioctl(gDRMSubFD, SIS_IOCTL_AGP_FREE, &agp); + agp.context = smesa->hHWContext; + agp.free = free; + drmCommandWrite( smesa->driFd, DRM_SIS_AGP_FREE, &agp, sizeof(drm_sis_mem_t) ); } /* debug */ @@ -229,32 +153,22 @@ static unsigned int Total_Textures_Used = 0; void -sis_alloc_z_stencil_buffer (GLcontext * ctx) +sisAllocZStencilBuffer( sisContextPtr smesa ) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - XMesaBuffer xm_buffer = xmesa->xm_buffer; - sisBufferInfo *priv = (sisBufferInfo *) xm_buffer->private; - GLuint z_depth; GLuint totalBytes; int width2; GLubyte *addr; - z_depth = (ctx->Visual->DepthBits + ctx->Visual->StencilBits) / 8; + z_depth = ( smesa->glCtx->Visual.depthBits + + smesa->glCtx->Visual.stencilBits ) / 8; - width2 = ALIGNMENT (xm_buffer->width * z_depth, 4); + width2 = ALIGNMENT( smesa->width * z_depth, 4 ); - totalBytes = xm_buffer->height * width2 + Z_BUFFER_HW_PLUS; + totalBytes = smesa->height * width2 + Z_BUFFER_HW_PLUS; - if (xm_buffer->depthbuffer) - { - sis_free_z_stencil_buffer (xm_buffer); - } - - addr = sis_alloc_fb (hwcx, totalBytes, &priv->zbFree); + addr = sisAllocFB( smesa, totalBytes, &smesa->zbFree ); if (!addr) { fprintf (stderr, "SIS driver : out of video memory\n"); @@ -263,82 +177,66 @@ if (SIS_VERBOSE&VERBOSE_SIS_BUFFER) { - fprintf(stderr, "sis_alloc_z_stencil_buffer: addr=%lu\n", (DWORD)addr); + fprintf(stderr, "sis_alloc_z_stencil_buffer: addr=%p\n", addr); } addr = (GLubyte *) ALIGNMENT ((unsigned long) addr, Z_BUFFER_HW_ALIGNMENT); - xm_buffer->depthbuffer = (void *) addr; + smesa->depthbuffer = (void *) addr; /* software render */ - hwcx->swZBase = addr; - hwcx->swZPitch = width2; + smesa->swZBase = addr; + smesa->swZPitch = width2; /* set pZClearPacket */ - memset (priv->pZClearPacket, 0, sizeof (ENGPACKET)); + memset (&smesa->zClearPacket, 0, sizeof (ENGPACKET)); - priv->pZClearPacket->dwSrcPitch = (z_depth == 2) ? 0x80000000 : 0xf0000000; - priv->pZClearPacket->dwDestBaseAddr = - (DWORD) addr - (DWORD) GET_FbBase (hwcx); - priv->pZClearPacket->wDestPitch = width2; - priv->pZClearPacket->stdwDestPos.wY = 0; - priv->pZClearPacket->stdwDestPos.wX = 0; - - priv->pZClearPacket->wDestHeight = hwcx->virtualY; - priv->pZClearPacket->stdwDim.wWidth = (WORD) width2 / z_depth; - priv->pZClearPacket->stdwDim.wHeight = (WORD) xm_buffer->height; - priv->pZClearPacket->stdwCmd.cRop = 0xf0; + smesa->zClearPacket.dwSrcPitch = (z_depth == 2) ? 0x80000000 : 0xf0000000; + smesa->zClearPacket.dwDestBaseAddr = (GLint)addr - (GLint)GET_FbBase (smesa); + smesa->zClearPacket.wDestPitch = width2; + smesa->zClearPacket.stdwDestPos.wY = 0; + smesa->zClearPacket.stdwDestPos.wX = 0; + + smesa->zClearPacket.wDestHeight = smesa->virtualY; + smesa->zClearPacket.stdwDim.wWidth = (GLshort) width2 / z_depth; + smesa->zClearPacket.stdwDim.wHeight = (GLshort) smesa->height; + smesa->zClearPacket.stdwCmd.cRop = 0xf0; - if (hwcx->blockWrite) + if (smesa->blockWrite) { - priv->pZClearPacket->stdwCmd.cCmd0 = (BYTE) (CMD0_PAT_FG_COLOR); - priv->pZClearPacket->stdwCmd.cCmd1 = - (BYTE) (CMD1_DIR_X_INC | CMD1_DIR_Y_INC); + smesa->zClearPacket.stdwCmd.cCmd0 = (GLbyte) (CMD0_PAT_FG_COLOR); + smesa->zClearPacket.stdwCmd.cCmd1 = + (GLbyte) (CMD1_DIR_X_INC | CMD1_DIR_Y_INC); } else { - priv->pZClearPacket->stdwCmd.cCmd0 = 0; - priv->pZClearPacket->stdwCmd.cCmd1 = - (BYTE) (CMD1_DIR_X_INC | CMD1_DIR_Y_INC); + smesa->zClearPacket.stdwCmd.cCmd0 = 0; + smesa->zClearPacket.stdwCmd.cCmd1 = + (GLbyte) (CMD1_DIR_X_INC | CMD1_DIR_Y_INC); } } void -sis_free_z_stencil_buffer (XMesaBuffer buf) +sisFreeZStencilBuffer( sisContextPtr smesa ) { - sisBufferInfo *priv = (sisBufferInfo *) buf->private; - XMesaContext xmesa = buf->xm_context; - - sis_free_fb (xmesa->driContextPriv->hHWContext, priv->zbFree); - priv->zbFree = NULL; - buf->depthbuffer = NULL; + sisFreeFB( smesa, smesa->zbFree ); + smesa->zbFree = NULL; + smesa->depthbuffer = NULL; } void -sis_alloc_back_image (GLcontext * ctx, XMesaImage *image, void **free, - ENGPACKET *packet) +sisAllocBackbuffer( sisContextPtr smesa ) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - XMesaBuffer xm_buffer = xmesa->xm_buffer; - - GLuint depth = GET_DEPTH (hwcx); + GLuint depth = GET_DEPTH (smesa); GLuint size, width2; GLbyte *addr; - if (image->data) - { - sis_free_back_image (xm_buffer, image, *free); - *free = NULL; - } - - width2 = (depth == 2) ? ALIGNMENT (xm_buffer->width, 2) : xm_buffer->width; - size = width2 * xm_buffer->height * depth + DRAW_BUFFER_HW_PLUS; + width2 = (depth == 2) ? ALIGNMENT (smesa->width, 2) : smesa->width; + size = width2 * smesa->height * depth + DRAW_BUFFER_HW_PLUS; /* Fixme: unique context alloc/free back-buffer? */ - addr = sis_alloc_fb (hwcx, size, free); + addr = sisAllocFB( smesa, size, &smesa->bbFree ); if (!addr) { fprintf (stderr, "SIS driver : out of video memory\n"); @@ -347,53 +245,42 @@ addr = (GLbyte *) ALIGNMENT ((unsigned long) addr, DRAW_BUFFER_HW_ALIGNMENT); - image->data = (char *)addr; - - image->bytes_per_line = width2 * depth; - image->bits_per_pixel = depth * 8; - - memset (packet, 0, sizeof (ENGPACKET)); - - packet->dwSrcPitch = (depth == 2) ? 0x80000000 : 0xf0000000; - packet->dwDestBaseAddr = - (DWORD) addr - (DWORD) GET_FbBase (hwcx); - packet->wDestPitch = image->bytes_per_line; - packet->stdwDestPos.wY = 0; - packet->stdwDestPos.wX = 0; - - packet->wDestHeight = hwcx->virtualY; - packet->stdwDim.wWidth = (WORD) width2; - packet->stdwDim.wHeight = (WORD) xm_buffer->height; - packet->stdwCmd.cRop = 0xf0; - - if (hwcx->blockWrite) - { - packet->stdwCmd.cCmd0 = (BYTE) (CMD0_PAT_FG_COLOR); - packet->stdwCmd.cCmd1 = - (BYTE) (CMD1_DIR_X_INC | CMD1_DIR_Y_INC); - } - else - { - packet->stdwCmd.cCmd0 = 0; - packet->stdwCmd.cCmd1 = (BYTE) (CMD1_DIR_X_INC | CMD1_DIR_Y_INC); - } + smesa->backbuffer = (char *)addr; + smesa->backOffset = (GLint)((long)addr - (long)smesa->FbBase); + smesa->backPitch = width2 * depth; + + memset (&smesa->cbClearPacket, 0, sizeof (ENGPACKET)); + + smesa->cbClearPacket.dwSrcPitch = (depth == 2) ? 0x80000000 : 0xf0000000; + smesa->cbClearPacket.dwDestBaseAddr = smesa->backOffset; + smesa->cbClearPacket.wDestPitch = smesa->backPitch; + smesa->cbClearPacket.stdwDestPos.wY = 0; + smesa->cbClearPacket.stdwDestPos.wX = 0; + + smesa->cbClearPacket.wDestHeight = smesa->virtualY; + smesa->cbClearPacket.stdwDim.wWidth = (GLshort) width2; + smesa->cbClearPacket.stdwDim.wHeight = (GLshort) smesa->height; + smesa->cbClearPacket.stdwCmd.cRop = 0xf0; + + if (smesa->blockWrite) { + smesa->cbClearPacket.stdwCmd.cCmd0 = (GLbyte) (CMD0_PAT_FG_COLOR); + } else { + smesa->cbClearPacket.stdwCmd.cCmd0 = 0; + } + smesa->cbClearPacket.stdwCmd.cCmd1 = + (GLbyte)(CMD1_DIR_X_INC | CMD1_DIR_Y_INC); } void -sis_free_back_image (XMesaBuffer buf, XMesaImage *image, void *free) +sisFreeBackbuffer( sisContextPtr smesa ) { - XMesaContext xmesa = buf->xm_context; - - sis_free_fb (xmesa->driContextPriv->hHWContext, free); - image->data = NULL; + sisFreeFB( smesa, smesa->bbFree ); + smesa->backbuffer = NULL; } void -sis_alloc_texture_image (GLcontext * ctx, GLtextureImage * image) +sisAllocTextureImage( sisContextPtr smesa, GLtextureImage * image ) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - GLuint size; SIStextureArea *area = image->DriverData; @@ -403,7 +290,7 @@ GLenum driver_format; if (area) - sis_free_texture_image (image); + sisFreeTextureImage( smesa, image ); area = calloc (1, sizeof (SIStextureArea)); if (!area){ @@ -482,13 +369,13 @@ size = image->Width * image->Height * texel_size + TEXTURE_HW_PLUS; do{ - addr = sis_alloc_fb (hwcx, size, &area->free); + addr = sisAllocFB( smesa, size, &area->free ); area->memType = VIDEO_TYPE; if(addr) break; /* TODO: swap to agp memory*/ /* video memory allocation fails */ - addr = sis_alloc_agp(hwcx, size, &area->free); + addr = sisAllocAGP( smesa, size, &area->free ); area->memType = AGP_TYPE; if(addr) break; @@ -508,7 +395,6 @@ area->Format = driver_format; area->Size = image->Width * image->Height * texel_size; area->texelSize = texel_size; - area->hHWContext = xmesa->driContextPriv->hHWContext; /* debug */ area->realSize = area->Size; @@ -519,7 +405,7 @@ } void -sis_free_texture_image (GLtextureImage * image) +sisFreeTextureImage( sisContextPtr smesa, GLtextureImage * image ) { SIStextureArea *area = (SIStextureArea *) image->DriverData; @@ -532,11 +418,11 @@ if (area->Data) switch(area->memType){ - case VIDEO_TYPE: - sis_free_fb (area->hHWContext, area->free); + case VIDEO_TYPE: + sisFreeFB( smesa, area->free ); break; - case AGP_TYPE: - sis_free_agp (area->hHWContext, area->free); + case AGP_TYPE: + sisFreeAGP( smesa, area->free ); break; default: assert(0); diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_alloc.h xc/lib/GL/mesa/src/drv/sis/sis_alloc.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_alloc.h Wed Dec 31 16:00:00 1969 +++ xc/lib/GL/mesa/src/drv/sis/sis_alloc.h Tue Aug 12 12:03:20 2003 @@ -0,0 +1,40 @@ +/************************************************************************** + +Copyright 2003 Eric Anholt +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sub license, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. +IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ +/* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_ctx.c,v 1.3 2000/09/26 15:56:48 tsi Exp $ */ + +/* + * Authors: + * Eric Anholt + * + */ + +void sisAllocZStencilBuffer( sisContextPtr smesa ); +void sisFreeZStencilBuffer( sisContextPtr smesa ); +void sisAllocBackbuffer( sisContextPtr smesa ); +void sisFreeBackbuffer ( sisContextPtr smesa ); +void sisAllocTextureImage( sisContextPtr smesa, GLtextureImage * image ); +void sisFreeTextureImage( sisContextPtr smesa, GLtextureImage * image ); diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_clear.c xc/lib/GL/mesa/src/drv/sis/sis_clear.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_clear.c Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_clear.c Fri Aug 22 15:33:20 2003 @@ -32,117 +32,179 @@ * */ -#include "sis_ctx.h" +#include "sis_context.h" #include "sis_mesa.h" +#include "sis_state.h" #include "sis_lock.h" -__inline__ static GLbitfield sis_3D_Clear (GLcontext * ctx, GLbitfield mask, - GLint x, GLint y, GLint width, - GLint height); -__inline__ static void sis_clear_color_buffer (GLcontext * ctx, GLint x, - GLint y, GLint width, - GLint height); -__inline__ static void sis_clear_z_stencil_buffer (GLcontext * ctx, - GLbitfield mask, GLint x, - GLint y, GLint width, - GLint height); - -GLbitfield -sis_Clear (GLcontext * ctx, GLbitfield mask, GLboolean all, - GLint x, GLint y, GLint width, GLint height) +#include "swrast/swrast.h" +#include "mmath.h" + +static GLbitfield sis_3D_Clear( GLcontext * ctx, GLbitfield mask, + GLint x, GLint y, GLint width, + GLint height ); +static void sis_clear_color_buffer( GLcontext *ctx, GLenum mask, GLint x, + GLint y, GLint width, GLint height ); +static void sis_clear_z_stencil_buffer( GLcontext * ctx, + GLbitfield mask, GLint x, + GLint y, GLint width, + GLint height ); + +static void +set_color_pattern( sisContextPtr smesa, GLubyte red, GLubyte green, + GLubyte blue, GLubyte alpha ) +{ + /* XXX only RGB565 and ARGB8888 */ + switch (GET_ColorFormat (smesa)) + { + case DST_FORMAT_ARGB_8888: + smesa->clearColorPattern = (alpha << 24) + + (red << 16) + (green << 8) + (blue); + break; + case DST_FORMAT_RGB_565: + smesa->clearColorPattern = ((red >> 3) << 11) + + ((green >> 2) << 5) + (blue >> 3); + smesa->clearColorPattern |= smesa->clearColorPattern << 16; + break; + default: + assert(0); + } +} + +void +sisUpdateZStencilPattern( sisContextPtr smesa, GLclampd z, int stencil ) +{ + GLuint zPattern, stencilPattern; + GLboolean dword_pattern; + + if (z <= (float) 0.0) + zPattern = 0x0; + else if (z >= (float) 1.0) + zPattern = 0xFFFFFFFF; + else + zPattern = doFPtoFixedNoRound (*(GLint *) & z, 32); + + stencilPattern = 0; + + switch (smesa->zFormat) + { + case Z_16: + zPattern = zPattern >> 16; + zPattern &= 0x0000FFFF; + dword_pattern = GL_FALSE; + break; + case S_8_Z_24: + zPattern = zPattern >> 8; + zPattern &= 0x00FFFFFF; + stencilPattern = (stencilPattern << 24); + dword_pattern = GL_TRUE; + break; + case Z_32: + dword_pattern = GL_TRUE; + break; + default: + assert(0); + } + smesa->clearZStencilPattern = zPattern | stencilPattern; + /* ?? */ + if (!dword_pattern) + smesa->clearZStencilPattern |= (zPattern | stencilPattern) << 16; +} + +void +sisDDClear( GLcontext * ctx, GLbitfield mask, GLboolean all, + GLint x, GLint y, GLint width, GLint height ) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); - XMesaBuffer xm_buffer = xmesa->xm_buffer; GLint x1, y1, width1, height1; - if (all) - { + if (all) { GLframebuffer *buffer = ctx->DrawBuffer; x1 = 0; y1 = 0; width1 = buffer->Width; height1 = buffer->Height; - } - else - { + } else { x1 = x; y1 = Y_FLIP(y+height-1); width1 = width; height1 = height; - } - - LOCK_HARDWARE (); + } - /* - * TODO: no considering multiple-buffer and clear buffer - * differs from current draw buffer - */ + LOCK_HARDWARE (); - if ((ctx->Visual->StencilBits && - ((mask | GL_DEPTH_BUFFER_BIT) ^ (mask | GL_STENCIL_BUFFER_BIT))) - || (*(DWORD *) (ctx->Color.ColorMask) != 0xffffffff) - ) - { + if (( ctx->Visual.stencilBits && + ((mask | GL_DEPTH_BUFFER_BIT) ^ (mask | GL_STENCIL_BUFFER_BIT)) ) || + (*(GLint *) (ctx->Color.ColorMask) != 0xffffffff) ) + { /* only Clear either depth or stencil buffer */ mask = sis_3D_Clear (ctx, mask, x1, y1, width1, height1); - } + } - if (mask & ctx->Color.DrawDestMask) - { - sis_clear_color_buffer (ctx, x1, y1, width1, height1); - mask &= ~ctx->Color.DrawDestMask; - } - if (mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) - { - if (xm_buffer->depthbuffer) - sis_clear_z_stencil_buffer (ctx, mask, x1, y1, width1, height1); - mask &= ~(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - } - if (mask & GL_ACCUM_BUFFER_BIT) - { - } + if ( mask & DD_FRONT_LEFT_BIT || mask & DD_BACK_LEFT_BIT) { + sis_clear_color_buffer (ctx, mask, x1, y1, width1, height1); + mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT); + } + + if (mask & (DD_DEPTH_BIT | DD_STENCIL_BIT)) { + if (smesa->depthbuffer != NULL) + sis_clear_z_stencil_buffer (ctx, mask, x1, y1, width1, height1); + mask &= ~(DD_DEPTH_BIT | DD_STENCIL_BIT); + } + + UNLOCK_HARDWARE (); + + if ( mask ) + _swrast_Clear( ctx, mask, all, x1, y1, width, height ); +} + + +void +sisDDClearColor( GLcontext * ctx, const GLfloat color[4] ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + GLubyte c[4]; - UNLOCK_HARDWARE (); + CLAMPED_FLOAT_TO_UBYTE(c[0], color[0]); + CLAMPED_FLOAT_TO_UBYTE(c[1], color[1]); + CLAMPED_FLOAT_TO_UBYTE(c[2], color[2]); + CLAMPED_FLOAT_TO_UBYTE(c[3], color[3]); - return mask; + set_color_pattern (smesa, c[0], c[1], c[2], c[3]); } void -sis_ClearDepth (GLcontext * ctx, GLclampd d) +sisDDClearDepth( GLcontext * ctx, GLclampd d ) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); - set_z_stencil_pattern (hwcx, d, ctx->Stencil.Clear); + sisUpdateZStencilPattern( smesa, d, ctx->Stencil.Clear ); } void -sis_ClearStencil (GLcontext * ctx, GLint s) +sisDDClearStencil( GLcontext * ctx, GLint s ) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); - set_z_stencil_pattern (hwcx, ctx->Depth.Clear, s); + sisUpdateZStencilPattern( smesa, ctx->Depth.Clear, s ); } #define MAKE_CLEAR_COLOR_8888(cc) \ - ( (((DWORD)(((GLubyte *)(cc))[3] * 255.0 + 0.5))<<24) | \ - (((DWORD)(((GLubyte *)(cc))[0] * 255.0 + 0.5))<<16) | \ - (((DWORD)(((GLubyte *)(cc))[1] * 255.0 + 0.5))<<8) | \ - ((DWORD)(((GLubyte *)(cc))[2] * 255.0 + 0.5)) ) + ( (((GLint)(((GLubyte *)(cc))[3] * 255.0 + 0.5))<<24) | \ + (((GLint)(((GLubyte *)(cc))[0] * 255.0 + 0.5))<<16) | \ + (((GLint)(((GLubyte *)(cc))[1] * 255.0 + 0.5))<<8) | \ + ((GLint)(((GLubyte *)(cc))[2] * 255.0 + 0.5)) ) -__inline__ static GLbitfield +static GLbitfield sis_3D_Clear (GLcontext * ctx, GLbitfield mask, GLint x, GLint y, GLint width, GLint height) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); - __GLSiSHardware *current = &hwcx->current; + __GLSiSHardware *current = &smesa->current; #define RESETSTATE (GFLAG_ENABLESETTING | GFLAG_ENABLESETTING2 | \ GFLAG_ZSETTING | GFLAG_DESTSETTING | \ @@ -151,27 +213,27 @@ SiS_SPASS_ZPASS_REPLACE) float left, top, right, bottom, zClearVal; - DWORD dwColor=0; - DWORD bClrColor, bClrDepth, bClrStencil; - DWORD dwPrimitiveSet; - DWORD dwEnable1, dwEnable2, dwDepthMask=0, dwSten1=0, dwSten2=0; + GLint dwColor=0; + GLint bClrColor, bClrDepth, bClrStencil; + GLint dwPrimitiveSet; + GLint dwEnable1, dwEnable2, dwDepthMask=0, dwSten1=0, dwSten2=0; int count; - BoxPtr pExtents; + XF86DRIClipRectPtr pExtents; bClrColor = 0; bClrDepth = (mask & GL_DEPTH_BUFFER_BIT) && - (ctx->Visual->DepthBits); + (ctx->Visual.depthBits); bClrStencil = (mask & GL_STENCIL_BUFFER_BIT) && - (ctx->Visual->StencilBits); + (ctx->Visual.stencilBits); /* update HW state */ /* TODO: if enclosing sis_Clear by sis_RenderStart and sis_RenderEnd is * uniform, but it seems needless to do so */ - if (hwcx->GlobalFlag) + if (smesa->GlobalFlag) { - sis_update_render_state (hwcx, 0); + sis_update_render_state( smesa ); } dwEnable2 = 0; @@ -186,18 +248,18 @@ if (bClrDepth && bClrStencil) { - DWORD wmask, smask; + GLint wmask, smask; GLstencil sten; zClearVal = ctx->Depth.Clear; sten = ctx->Stencil.Clear; - wmask = (DWORD) ctx->Stencil.WriteMask; + wmask = (GLint) ctx->Stencil.WriteMask; smask = 0xff; dwEnable1 = MASK_ZWriteEnable | MASK_StencilTestEnable; dwEnable2 |= MASK_ZMaskWriteEnable; dwDepthMask = ((wmask << 24) | 0x00ffffff); - dwSten1 = S_8 | (((DWORD) sten << 8) | smask) | SiS_STENCIL_ALWAYS; + dwSten1 = S_8 | (((GLint) sten << 8) | smask) | SiS_STENCIL_ALWAYS; dwSten2 = STEN_OP; } else if (bClrDepth) @@ -209,18 +271,18 @@ } else if (bClrStencil) { - DWORD wmask, smask; + GLint wmask, smask; GLstencil sten; sten = (GLstencil) ctx->Stencil.Clear; - wmask = (DWORD) ctx->Stencil.WriteMask; + wmask = (GLint) ctx->Stencil.WriteMask; smask = 0xff; zClearVal = 0; dwEnable1 = MASK_ZWriteEnable | MASK_StencilTestEnable; dwEnable2 |= MASK_ZMaskWriteEnable; dwDepthMask = (wmask << 24) & 0xff000000; - dwSten1 = S_8 | (((DWORD) sten << 8) | smask) | SiS_STENCIL_ALWAYS; + dwSten1 = S_8 | (((GLint) sten << 8) | smask) | SiS_STENCIL_ALWAYS; dwSten2 = STEN_OP; } else @@ -254,9 +316,10 @@ MMIO (REG_3D_StencilSet2, dwSten2); } - if (ctx->Color.DriverDrawBuffer == GL_FRONT_LEFT) + if (mask & DD_FRONT_LEFT_BIT) /* XXX */ { - sis_get_clip_rects (xmesa, &pExtents, &count); + pExtents = smesa->driDrawable->pClipRects; + count = smesa->driDrawable->numClipRects; } else { @@ -273,15 +336,12 @@ if (pExtents) { - GLuint origin_x, origin_y; GLuint x1, y1, x2, y2; - sis_get_drawable_origin (xmesa, &origin_x, &origin_y); - - x1 = pExtents->x1 - origin_x; - y1 = pExtents->y1 - origin_y; - x2 = pExtents->x2 - origin_x - 1; - y2 = pExtents->y2 - origin_y - 1; + x1 = pExtents->x1 - smesa->driDrawable->x; + y1 = pExtents->y1 - smesa->driDrawable->y; + x2 = pExtents->x2 - smesa->driDrawable->x - 1; + y2 = pExtents->y2 - smesa->driDrawable->y - 1; left = (left > x1) ? left : x1; right = (right > x2) ? x2 : right; @@ -292,27 +352,27 @@ pExtents++; } - MMIO (REG_3D_ClipTopBottom, ((DWORD) top << 13) | (DWORD) bottom); - MMIO (REG_3D_ClipLeftRight, ((DWORD) left << 13) | (DWORD) right); + MMIO (REG_3D_ClipTopBottom, ((GLint) top << 13) | (GLint) bottom); + MMIO (REG_3D_ClipLeftRight, ((GLint) left << 13) | (GLint) right); /* the first triangle */ dwPrimitiveSet = (OP_3D_TRIANGLE_DRAW | OP_3D_FIRE_TSARGBc | SHADE_FLAT_VertexC); MMIO (REG_3D_PrimitiveSet, dwPrimitiveSet); - MMIO (REG_3D_TSZa, *(DWORD *) & zClearVal); - MMIO (REG_3D_TSXa, *(DWORD *) & right); - MMIO (REG_3D_TSYa, *(DWORD *) & top); + MMIO (REG_3D_TSZa, *(GLint *) & zClearVal); + MMIO (REG_3D_TSXa, *(GLint *) & right); + MMIO (REG_3D_TSYa, *(GLint *) & top); MMIO (REG_3D_TSARGBa, dwColor); - MMIO (REG_3D_TSZb, *(DWORD *) & zClearVal); - MMIO (REG_3D_TSXb, *(DWORD *) & left); - MMIO (REG_3D_TSYb, *(DWORD *) & top); + MMIO (REG_3D_TSZb, *(GLint *) & zClearVal); + MMIO (REG_3D_TSXb, *(GLint *) & left); + MMIO (REG_3D_TSYb, *(GLint *) & top); MMIO (REG_3D_TSARGBb, dwColor); - MMIO (REG_3D_TSZc, *(DWORD *) & zClearVal); - MMIO (REG_3D_TSXc, *(DWORD *) & left); - MMIO (REG_3D_TSYc, *(DWORD *) & bottom); + MMIO (REG_3D_TSZc, *(GLint *) & zClearVal); + MMIO (REG_3D_TSXc, *(GLint *) & left); + MMIO (REG_3D_TSYc, *(GLint *) & bottom); MMIO (REG_3D_TSARGBc, dwColor); /* second triangle */ @@ -320,15 +380,15 @@ SHADE_FLAT_VertexB); MMIO (REG_3D_PrimitiveSet, dwPrimitiveSet); - MMIO (REG_3D_TSZb, *(DWORD *) & zClearVal); - MMIO (REG_3D_TSXb, *(DWORD *) & right); - MMIO (REG_3D_TSYb, *(DWORD *) & bottom); + MMIO (REG_3D_TSZb, *(GLint *) & zClearVal); + MMIO (REG_3D_TSXb, *(GLint *) & right); + MMIO (REG_3D_TSYb, *(GLint *) & bottom); MMIO (REG_3D_TSARGBb, dwColor); } mEndPrimitive (); - hwcx->GlobalFlag |= RESETSTATE; + smesa->GlobalFlag |= RESETSTATE; #undef RESETSTATE #undef STEN_OP @@ -339,14 +399,14 @@ return (mask & ~(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)); } -__inline__ static void -sis_bitblt_clear_cmd (__GLSiScontext * hwcx, ENGPACKET * pkt) +static void +sis_bitblt_clear_cmd (sisContextPtr smesa, ENGPACKET * pkt) { - LPDWORD lpdwDest, lpdwSrc; + GLint *lpdwDest, *lpdwSrc; int i; - lpdwSrc = (DWORD *) pkt + 1; - lpdwDest = (DWORD *) (GET_IOBase (hwcx) + REG_SRC_ADDR) + 1; + lpdwSrc = (GLint *) pkt + 1; + lpdwDest = (GLint *) (GET_IOBase (smesa) + REG_SRC_ADDR) + 1; mWait3DCmdQueue (10); @@ -358,68 +418,70 @@ *lpdwDest++ = *lpdwSrc++; } - MMIO (REG_CMD0, *(DWORD *) & pkt->stdwCmd); + MMIO (REG_CMD0, *(GLint *) & pkt->stdwCmd); MMIO (0x8240, -1); } -__inline__ static void -sis_clear_color_buffer (GLcontext * ctx, - GLint x, GLint y, GLint width, GLint height) +static void +sis_clear_color_buffer( GLcontext *ctx, GLenum mask, GLint x, GLint y, + GLint width, GLint height ) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - XMesaBuffer xm_buffer = xmesa->xm_buffer; - sisBufferInfo *priv = (sisBufferInfo *) xm_buffer->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); int count; - GLuint origin_x, origin_y; - GLuint depth = GET_DEPTH (hwcx); - BoxPtr pExtents = NULL; + GLuint depth = GET_DEPTH (smesa); + XF86DRIClipRectPtr pExtents = NULL; GLint xx, yy; GLint x0, y0, width0, height0; ENGPACKET stEngPacket; - GLuint pitch; - - switch (ctx->Color.DriverDrawBuffer) - { - case GL_BACK_LEFT: - priv->pCbClearPacket->stdwDestPos.wY = y; - priv->pCbClearPacket->stdwDestPos.wX = x; - priv->pCbClearPacket->stdwDim.wWidth = (WORD) width; - priv->pCbClearPacket->stdwDim.wHeight = (WORD) height; - priv->pCbClearPacket->dwFgRopColor = hwcx->clearColorPattern; + /* Clear back buffer */ + if (mask & DD_BACK_LEFT_BIT) { + smesa->cbClearPacket.stdwDestPos.wY = y; + smesa->cbClearPacket.stdwDestPos.wX = x; + smesa->cbClearPacket.stdwDim.wWidth = (GLshort) width; + smesa->cbClearPacket.stdwDim.wHeight = (GLshort) height; + smesa->cbClearPacket.dwFgRopColor = smesa->clearColorPattern; - sis_bitblt_clear_cmd (hwcx, priv->pCbClearPacket); - return; - case GL_FRONT_LEFT: - x0 = x; - y0 = y; - width0 = width; - height0 = height; - - pitch = GET_PITCH (hwcx); - sis_get_drawable_origin (xmesa, &origin_x, &origin_y); - sis_get_clip_rects (xmesa, &pExtents, &count); - break; - case GL_BACK_RIGHT: - case GL_FRONT_RIGHT: - default: - assert (0); + sis_bitblt_clear_cmd( smesa, &smesa->cbClearPacket ); + } + + if ((mask & DD_FRONT_LEFT_BIT) == 0) return; - } - - memset (&stEngPacket, 0, sizeof (ENGPACKET)); - while (count--) - { - GLint x2 = pExtents->x1 - origin_x; - GLint y2 = pExtents->y1 - origin_y; - GLint xx2 = pExtents->x2 - origin_x; - GLint yy2 = pExtents->y2 - origin_y; + /* Clear front buffer */ + x0 = x; + y0 = y; + width0 = width; + height0 = height; + + pExtents = smesa->driDrawable->pClipRects; + count = smesa->driDrawable->numClipRects; + + memset (&stEngPacket, 0, sizeof (ENGPACKET)); + + stEngPacket.dwSrcPitch = (depth == 2) ? 0x80000000 : 0xc0000000; + stEngPacket.dwDestBaseAddr = smesa->frontOffset; + stEngPacket.wDestPitch = smesa->frontPitch; + /* TODO: set maximum value? */ + stEngPacket.wDestHeight = smesa->virtualY; + stEngPacket.stdwCmd.cRop = 0xf0; + stEngPacket.dwFgRopColor = smesa->clearColorPattern; + + /* for SGRAM Block Write Enable */ + if (smesa->blockWrite) + stEngPacket.stdwCmd.cCmd0 = (GLbyte) (CMD0_PAT_FG_COLOR); + else + stEngPacket.stdwCmd.cCmd0 = 0; + stEngPacket.stdwCmd.cCmd1 = (GLbyte) (CMD1_DIR_X_INC | CMD1_DIR_Y_INC); + + while (count--) { + GLint x2 = pExtents->x1 - smesa->driDrawable->x; + GLint y2 = pExtents->y1 - smesa->driDrawable->y; + GLint xx2 = pExtents->x2 - smesa->driDrawable->x; + GLint yy2 = pExtents->y2 - smesa->driDrawable->y; x = (x0 > x2) ? x0 : x2; y = (y0 > y2) ? y0 : y2; @@ -432,178 +494,33 @@ if (width <= 0 || height <= 0) continue; - stEngPacket.dwSrcPitch = (depth == 2) ? 0x80000000 : 0xc0000000; - stEngPacket.stdwDestPos.wY = y + origin_y; - stEngPacket.stdwDestPos.wX = x + origin_x; - stEngPacket.dwDestBaseAddr = (DWORD) 0; - stEngPacket.wDestPitch = pitch; - /* TODO: set maximum value? */ - stEngPacket.wDestHeight = hwcx->virtualY; - stEngPacket.stdwDim.wWidth = (WORD) width; - stEngPacket.stdwDim.wHeight = (WORD) height; - stEngPacket.stdwCmd.cRop = 0xf0; - stEngPacket.dwFgRopColor = hwcx->clearColorPattern; + stEngPacket.stdwDestPos.wY = y + smesa->driDrawable->y; + stEngPacket.stdwDestPos.wX = x + smesa->driDrawable->x; + stEngPacket.stdwDim.wWidth = (GLshort)width; + stEngPacket.stdwDim.wHeight = (GLshort)height; - /* for SGRAM Block Write Enable */ - if (hwcx->blockWrite) - { - stEngPacket.stdwCmd.cCmd0 = (BYTE) (CMD0_PAT_FG_COLOR); - stEngPacket.stdwCmd.cCmd1 = - (BYTE) (CMD1_DIR_X_INC | CMD1_DIR_Y_INC); - } - else - { - stEngPacket.stdwCmd.cCmd0 = 0; - stEngPacket.stdwCmd.cCmd1 = - (BYTE) (CMD1_DIR_X_INC | CMD1_DIR_Y_INC); - } - - sis_bitblt_clear_cmd (hwcx, &stEngPacket); - } + sis_bitblt_clear_cmd( smesa, &stEngPacket ); + } } -__inline__ static void +static void sis_clear_z_stencil_buffer (GLcontext * ctx, GLbitfield mask, GLint x, GLint y, GLint width, GLint height) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - XMesaBuffer xm_buffer = xmesa->xm_buffer; - sisBufferInfo *priv = (sisBufferInfo *) xmesa->xm_buffer->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); /* TODO: check write mask */ - if (!xm_buffer->depthbuffer) + if ( smesa->depthbuffer == NULL ) return; /* TODO: consider alignment of width, height? */ - priv->pZClearPacket->stdwDestPos.wY = y; - priv->pZClearPacket->stdwDestPos.wX = x; - priv->pZClearPacket->stdwDim.wWidth = (WORD) width; - priv->pZClearPacket->stdwDim.wHeight = (WORD) height; - priv->pZClearPacket->dwFgRopColor = hwcx->clearZStencilPattern; - - sis_bitblt_clear_cmd (hwcx, priv->pZClearPacket); -} - -__inline__ static void -sis_bitblt_copy_cmd (__GLSiScontext * hwcx, ENGPACKET * pkt) -{ - LPDWORD lpdwDest, lpdwSrc; - int i; - - lpdwSrc = (DWORD *) pkt; - lpdwDest = (DWORD *) (GET_IOBase (hwcx) + REG_SRC_ADDR); - - mWait3DCmdQueue (10); - - for (i = 0; i < 7; i++) - { - *lpdwDest++ = *lpdwSrc++; - } - - MMIO (REG_CMD0, *(DWORD *) & pkt->stdwCmd); - MMIO (0x8240, -1); -} - -__inline__ static void -sis_swap_image (XMesaBuffer b, XMesaDrawable d, XMesaImage * image) -{ - XMesaContext xmesa = b->xm_context; - __GLSiScontext *hwcx = (__GLSiScontext *) b->xm_context->private; + smesa->zClearPacket.stdwDestPos.wY = y; + smesa->zClearPacket.stdwDestPos.wX = x; + smesa->zClearPacket.stdwDim.wWidth = (GLshort) width; + smesa->zClearPacket.stdwDim.wHeight = (GLshort) height; + smesa->zClearPacket.dwFgRopColor = smesa->clearZStencilPattern; - GLuint depth = GET_DEPTH (hwcx); - ENGPACKET stEngPacket; - DWORD src; - GLuint srcPitch, dstPitch; - - BoxPtr pExtents; - BoxRec box; - int count; - GLuint origin_x, origin_y; - - memset (&stEngPacket, 0, sizeof (ENGPACKET)); - - if (!sis_get_clip_rects (xmesa, &pExtents, &count)) - { - sis_get_drawable_box (xmesa, &box); - pExtents = &box; - count = 1; - } - - src = (DWORD) image->data - (DWORD) GET_FbBase (hwcx); - srcPitch = image->bytes_per_line; - dstPitch = GET_PITCH (hwcx); - sis_get_drawable_origin (xmesa, &origin_x, &origin_y); - - while(count --) - { - stEngPacket.dwSrcPitch = (depth == 2) ? 0x80000000 : 0xc0000000; - - stEngPacket.dwSrcBaseAddr = src; - stEngPacket.dwSrcPitch |= srcPitch; - - stEngPacket.stdwSrcPos.wY = pExtents->y1 - origin_y; - stEngPacket.stdwSrcPos.wX = pExtents->x1 - origin_x; - stEngPacket.stdwDestPos.wY = pExtents->y1; - stEngPacket.stdwDestPos.wX = pExtents->x1; - stEngPacket.dwDestBaseAddr = (DWORD) 0; - stEngPacket.wDestPitch = dstPitch; - - /* TODO: set maximum value? */ - stEngPacket.wDestHeight = hwcx->virtualY; - stEngPacket.stdwDim.wWidth = (WORD) pExtents->x2 - pExtents->x1; - stEngPacket.stdwDim.wHeight = (WORD) pExtents->y2 - pExtents->y1; - stEngPacket.stdwCmd.cRop = 0xcc; - - if (hwcx->blockWrite) - { - stEngPacket.stdwCmd.cCmd0 = (BYTE) (CMD0_PAT_FG_COLOR); - stEngPacket.stdwCmd.cCmd1 = - (BYTE) (CMD1_DIR_X_INC | CMD1_DIR_Y_INC); - } - else - { - stEngPacket.stdwCmd.cCmd0 = 0; - stEngPacket.stdwCmd.cCmd1 = - (BYTE) (CMD1_DIR_X_INC | CMD1_DIR_Y_INC); - } - - sis_bitblt_copy_cmd (hwcx, &stEngPacket); - - pExtents++; - } + sis_bitblt_clear_cmd (smesa, &smesa->zClearPacket); } -void -sis_swap_buffers (XMesaBuffer b) -{ - XMesaContext xmesa = b->xm_context; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - GLcontext *ctx = hwcx->gc; - - /* debug */ - /* return; */ - - /* frame control */ - /* TODO: need lock? */ - -#if 1 - { - int repeat = 0; - - while(((*hwcx->FrameCountPtr) - *(DWORD volatile *)(hwcx->IOBase+0x8a2c) - > SIS_MAX_FRAME_LENGTH) && - (repeat++ < 10)); - } -#endif - - LOCK_HARDWARE (); - - sis_swap_image (b, b->frontbuffer, b->backimage); - *(DWORD *)(hwcx->IOBase+0x8a2c) = *hwcx->FrameCountPtr; - (*hwcx->FrameCountPtr)++; - - UNLOCK_HARDWARE (); -} diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_common.h xc/lib/GL/mesa/src/drv/sis/sis_common.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_common.h Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_common.h Wed Dec 31 16:00:00 1969 @@ -1,230 +0,0 @@ -/************************************************************************** - -Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan. -All Rights Reserved. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sub license, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice (including the -next paragraph) shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. -IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -**************************************************************************/ -/* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_common.h,v 1.5 2000/09/26 15:56:48 tsi Exp $ */ - -/* - * Authors: - * Sung-Ching Lin - * - */ - -#ifndef _sis_common_h_ -#define _sis_common_h_ - -#include "types.h" -#include "sis_xmesaP.h" - -#if 0 -#define free(x) -#define calloc(x,y) sis_debug_malloc((x)*(y)) -extern void *sis_debug_malloc(int x); -#endif - -#if defined(SIS_DUMP) -#include "sis_debug.h" -#endif - -#if SIS_STEREO -# include "sis_stereo.h" -#else -# define STEREO_OFFSET(v) 0 -# define STEREO_SAMPLE(v) do{}while(0) -#endif - -#ifdef XFree86Server -# include "resource.h" -# include "windowstr.h" -# include "gcstruct.h" -# include "GL/xf86glx.h" -# include "xf86glx_util.h" -# include "xf86_ansic.h" -# include "xf86_libc.h" -#else -# ifdef GLX_DIRECT_RENDERING -# include -# include -# include -# include -# include "dri_mesaint.h" -typedef struct _Box -{ - short x1, y1, x2, y2; -} -BoxRec; -#define NullBox ((BoxPtr)0) -typedef struct _Box *BoxPtr; -# endif -#endif - -typedef unsigned short WORD; -typedef unsigned long DWORD; -typedef unsigned int UINT; -typedef int INT; -typedef long LONG; -typedef DWORD *LPDWORD; - -/* BitBlt Commands */ -#define Index_SR_Misc_Ctrl11 0x3e -#define CMD0_DD_ENABLE 0x06 -#define CMD0_SRC_VIDEO 0x00 -#define CMD0_SRC_CPU 0x10 -#define CMD0_PAT_FG_COLOR 0x00 -#define CMD1_DIR_X_DEC 0x00 -#define CMD1_DIR_X_INC 0x01 -#define CMD1_DIR_Y_DEC 0x00 -#define CMD1_DIR_Y_INC 0x02 -#define REG_SRC_ADDR 0x8200 -#define REG_CMD0 0x823c - -typedef struct -{ - WORD wSrcPitch; - WORD wDestPitch; -} -_PITCH; -typedef struct -{ - WORD wWidth; - WORD wHeight; -} -_DIM; -typedef struct -{ - WORD wY; - WORD wX; -} -_POS; - -typedef struct -{ - BYTE cCmd0; - BYTE cRop; - BYTE cCmd1; - BYTE cReserved; -} -_CMD; - -typedef struct -{ - WORD wStatus0; - BYTE cStatus0_BYTE3; - BYTE cStatus0_BYTE4; -} -_CMDQUESTATUS; - -typedef struct -{ - DWORD dwSrcBaseAddr; - DWORD dwSrcPitch; - _POS stdwSrcPos; - _POS stdwDestPos; - DWORD dwDestBaseAddr; - WORD wDestPitch; - WORD wDestHeight; - _DIM stdwDim; - DWORD dwFgRopColor; - DWORD dwBgRopColor; - DWORD dwSrcHiCKey; - DWORD dwSrcLoCKey; - DWORD dwMaskA; - DWORD dwMaskB; - DWORD dwClipA; - DWORD dwClipB; - _CMD stdwCmd; - _CMDQUESTATUS stdwCmdQueStatus; -} -ENGPACKET, *LPENGPACKET; - -/* Hardware Info */ -#include "sis_reg.h" -#include "sis_init.h" - -typedef struct gl_texture_object GLtextureObject; -typedef struct gl_texture_image GLtextureImage; - -#define VIDEO_TYPE 0 -#define AGP_TYPE 1 - -typedef struct sis_texure_area -{ - GLbyte *Data; - GLenum Format; - void *free; - GLuint memType; - GLuint Pitch; - GLuint Size; - GLuint texelSize; - unsigned int hHWContext; - - /* Debug */ - GLuint realSize; -} -SIStextureArea; - -/* dirtyFlag */ -#define SIS_TEX_ENV 0x1 -#define SIS_TEX_IMAGE 0x2 /* image in video memory is stale */ -#define SIS_TEX_PARAMETER 0x4 -#define SIS_TEX_ALL (SIS_TEX_IMAGE | SIS_TEX_PARAMETER) - -typedef struct sis_texobj_area -{ - DWORD dirtyFlag; - GLboolean valid; - struct sis_texobj_area *prev, *next; -} -sisTexobjInfo; - -typedef struct sis_buffer_private -{ - void *zbFree, *bbFree; - - ENGPACKET *pZClearPacket, *pCbClearPacket; - - ENGPACKET zClearPacket, cbClearPacket; - -#if SIS_STEREO - XMesaImage *pStereoImages[3]; - ENGPACKET *pStereoPackets[3]; - void *stereoFrees[3]; /* stereoFrees[0] is useless */ - - ENGPACKET stereoPackets[2]; -#endif -} -sisBufferInfo; - -/* HW capability */ -#define SIS_MAX_MIPMAP_LEVEL 11 -#define SIS_MAX_TEXTURE_SIZE 2048 -#define SIS_MAX_TEXTURES 2 - -#define SIS_MAX_FRAME_LENGTH 3 - -DWORD doFPtoFixedNoRound (DWORD dwInValue, int nFraction); - -#define Y_FLIP(Y) (xmesa->xm_buffer->bottom-(Y)) -#endif diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_common2.h xc/lib/GL/mesa/src/drv/sis/sis_common2.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_common2.h Wed Dec 31 16:00:00 1969 +++ xc/lib/GL/mesa/src/drv/sis/sis_common2.h Tue Aug 12 12:03:20 2003 @@ -0,0 +1,191 @@ +/************************************************************************** + +Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan. +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sub license, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. +IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ +/* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_common.h,v 1.5 2000/09/26 15:56:48 tsi Exp $ */ + +/* + * Authors: + * Sung-Ching Lin + * + */ + +#ifndef _sis_common_h_ +#define _sis_common_h_ + +#include "sis_xmesaP.h" + +#if 0 +#define free(x) +#define calloc(x,y) sis_debug_malloc((x)*(y)) +extern void *sis_debug_malloc(int x); +#endif + +#if defined(SIS_DUMP) +#include "sis_debug.h" +#endif + +#if SIS_STEREO +# include "sis_stereo.h" +#else +# define STEREO_OFFSET(v) 0 +# define STEREO_SAMPLE(v) do{}while(0) +#endif + +#ifdef GLX_DIRECT_RENDERING +# include +# include +# include +# include +typedef struct _Box +{ + short x1, y1, x2, y2; +} +BoxRec; +#define NullBox ((BoxPtr)0) +typedef struct _Box *BoxPtr; +#endif /* GLX_DIRECT_RENDERING */ + +/* BitBlt Commands */ +#define Index_SR_Misc_Ctrl11 0x3e +#define CMD0_DD_ENABLE 0x06 +#define CMD0_SRC_VIDEO 0x00 +#define CMD0_SRC_CPU 0x10 +#define CMD0_PAT_FG_COLOR 0x00 +#define CMD1_DIR_X_DEC 0x00 +#define CMD1_DIR_X_INC 0x01 +#define CMD1_DIR_Y_DEC 0x00 +#define CMD1_DIR_Y_INC 0x02 +#define REG_SRC_ADDR 0x8200 +#define REG_CMD0 0x823c + +typedef struct +{ + GLshort wSrcPitch; + GLshort wDestPitch; +} +_PITCH; +typedef struct +{ + GLshort wWidth; + GLshort wHeight; +} +_DIM; +typedef struct +{ + GLshort wY; + GLshort wX; +} +_POS; + +typedef struct +{ + GLbyte cCmd0; + GLbyte cRop; + GLbyte cCmd1; + GLbyte cReserved; +} +_CMD; + +typedef struct +{ + GLshort wStatus0; + GLbyte cStatus0_GLbyte3; + GLbyte cStatus0_GLbyte4; +} +_CMDQUESTATUS; + +typedef struct +{ + GLint dwSrcBaseAddr; + GLint dwSrcPitch; + _POS stdwSrcPos; + _POS stdwDestPos; + GLint dwDestBaseAddr; + GLshort wDestPitch; + GLshort wDestHeight; + _DIM stdwDim; + GLint dwFgRopColor; + GLint dwBgRopColor; + GLint dwSrcHiCKey; + GLint dwSrcLoCKey; + GLint dwMaskA; + GLint dwMaskB; + GLint dwClipA; + GLint dwClipB; + _CMD stdwCmd; + _CMDQUESTATUS stdwCmdQueStatus; +} +ENGPACKET, *LPENGPACKET; + +/* Hardware Info */ +#include "sis_reg.h" +#include "sis_init.h" + +typedef struct gl_texture_object GLtextureObject; +typedef struct gl_texture_image GLtextureImage; + +#define VIDEO_TYPE 0 +#define AGP_TYPE 1 + +typedef struct sis_texure_area +{ + GLbyte *Data; + GLenum Format; + void *free; + GLuint memType; + GLuint Pitch; + GLuint Size; + GLuint texelSize; + + /* Debug */ + GLuint realSize; +} +SIStextureArea; + +/* dirtyFlag */ +#define SIS_TEX_ENV 0x1 +#define SIS_TEX_IMAGE 0x2 /* image in video memory is stale */ +#define SIS_TEX_PARAMETER 0x4 +#define SIS_TEX_ALL (SIS_TEX_IMAGE | SIS_TEX_PARAMETER) + +typedef struct sis_texobj_area +{ + GLint dirtyFlag; + GLboolean valid; + struct sis_texobj_area *prev, *next; +} +sisTexobjInfo; + +/* HW capability */ +#define SIS_MAX_MIPMAP_LEVEL 11 +#define SIS_MAX_TEXTURE_SIZE 2048 +#define SIS_MAX_TEXTURES 2 + +#define SIS_MAX_FRAME_LENGTH 3 + +GLint doFPtoFixedNoRound (GLint dwInValue, int nFraction); + +#endif diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_context.c xc/lib/GL/mesa/src/drv/sis/sis_context.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_context.c Wed Dec 31 16:00:00 1969 +++ xc/lib/GL/mesa/src/drv/sis/sis_context.c Fri Aug 22 15:33:20 2003 @@ -0,0 +1,917 @@ +/************************************************************************** + +Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan. +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sub license, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. +IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ +/* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_ctx.c,v 1.3 2000/09/26 15:56:48 tsi Exp $ */ + +/* + * Authors: + * Sung-Ching Lin + * + */ + +#include "sis_dri.h" + +#include "sis_context.h" +#include "sis_state.h" +#include "sis_mesa.h" +#include "sis_dd.h" +#include "sis_span.h" +#include "sis_stencil.h" +#include "sis_tex.h" +#include "sis_tris.h" +#include "sis_vb.h" + +#include "imports.h" +#include "matrix.h" +#include "extensions.h" +#include "utils.h" + +#include "swrast/swrast.h" +#include "swrast_setup/swrast_setup.h" +#include "array_cache/acache.h" + +#include "tnl/tnl.h" +#include "tnl/t_pipeline.h" + +int GlobalCurrentHwcx = -1; +int GlobalHwcxCountBase = 1; +int GlobalCmdQueueLen = 0; + +static const char * const card_extensions[] = +{ + "GL_ARB_multitexture", + NULL +}; + +void +WaitEngIdle (sisContextPtr smesa) +{ + GLbyte *IOBase = GET_IOBase (smesa); + GLbyte cEngineState; + + cEngineState = *((GLbyte volatile *) (IOBase + 0x8243)); + while (((cEngineState & 0x80) == 0) || + ((cEngineState & 0x40) == 0) || ((cEngineState & 0x20) == 0)) + { + cEngineState = *((GLbyte volatile *) (IOBase + 0x8243)); + } +} + +void +Wait2DEngIdle (sisContextPtr smesa) +{ + GLbyte *IOBase = GET_IOBase (smesa); + GLbyte cEngineState; + + cEngineState = *((GLbyte volatile *) (IOBase + 0x8243)); + while (!(cEngineState & 0x80)) + { + cEngineState = *((GLbyte volatile *) (IOBase + 0x8243)); + } +} + +static void +sis_init_opengl_state (GLcontext * ctx) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + + __GLSiSHardware *current = &smesa->current; + __GLSiSHardware *prev = &(smesa->prev); + + /* + prev->hwCapEnable = INIT_6327_CapsEnable ; + prev->hwCapEnable = 0x000000a0; + */ + /* add Texture Perspective Enable */ + prev->hwCapEnable = 0x000002a0; + + /* + prev->hwCapEnable2 = INIT_6327_CapsEnable2; + prev->hwCapEnable2 = 0x00aa0080; + */ + /* if multi-texture enabled, disable Z pre-test */ + prev->hwCapEnable2 = 0x00000000; + + /* Z test mode is LE */ + prev->hwZ = INIT_6327_ZSet; + + /* TODO : maybe call sis_DepthFunc to update is a better way */ + ctx->Driver.DepthFunc (ctx, ctx->Depth.Func); + + /* Depth mask */ + prev->hwZMask = INIT_6327_ZMask; + + /* Alpha test mode is ALWAYS, Alpha ref value is 0 */ + prev->hwAlpha = INIT_6327_AlphaSet; + + /* ROP2 is COPYPEN */ + prev->hwDstSet = INIT_6327_DstSet; + + /* color mask */ + prev->hwDstMask = INIT_6327_DstMask; + + /* LinePattern is 0, Repeat Factor is 0 */ + prev->hwLinePattern = 0x00008000; + + /* Fog mode is Linear Fog, Fog color is (0, 0, 0) */ + prev->hwFog = INIT_6327_FogSet; + + /* Src blend is BLEND_ONE, Dst blend is D3DBLEND_ZERO */ + prev->hwDstSrcBlend = INIT_6327_BlendMode; + + /* Texture mapping mode is Tile */ +#if 0 + prev->texture[0].hwTextqureSet = INIT_6327_TextureSet; +#endif + /* Magnified & minified texture filter is NEAREST */ +#if 0 + prev->texture[0].hwTextureMip = INIT_6327_TextureMip; +#endif + + /* Texture Blending seeting */ + prev->hwTexBlendClr0 = INIT_6327_TextureColorBlend0; + + prev->hwTexBlendClr1 = INIT_6327_TextureColorBlend1; + + prev->hwTexBlendAlpha0 = INIT_6327_TextureAlphaBlend0; + + prev->hwTexBlendAlpha1 = INIT_6327_TextureAlphaBlend1; + + memcpy (current, prev, sizeof (__GLSiSHardware)); + + /* Init the texture transparency color high range value */ +#if 0 + lpdwRegIO = ((GLint *)smesa->lpEngIO + REG_3D_TransparencyColorHigh); + prev->hwTextureClrHigh = INIT_6326_TextureClrHigh; + *(lpdwRegIO) = INIT_6327_TextureClrHigh; +#endif + + smesa->clearColorPattern = 0; +} + +static void +sis_set_buffer_static (GLcontext * ctx) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + __GLSiSHardware *prev = &smesa->prev; + __GLSiSHardware *current = &smesa->current; + + switch (smesa->bytesPerPixel) + { + case 2: + current->hwDstSet |= DST_FORMAT_RGB_565; + break; + case 4: + current->hwDstSet |= DST_FORMAT_ARGB_8888; + break; + } + + switch (ctx->Visual.depthBits) + { + case 0: + current->hwCapEnable &= ~MASK_ZWriteEnable; + case 16: + smesa->zFormat = Z_16; + current->hwCapEnable |= MASK_ZWriteEnable; + smesa->depth_scale = 1.0 / (GLfloat)0xffff; + break; + case 32: + smesa->zFormat = Z_32; + current->hwCapEnable |= MASK_ZWriteEnable; + smesa->depth_scale = 1.0 / (GLfloat)0xffffffff; + break; + case 24: + assert (ctx->Visual.stencilBits); + smesa->zFormat = S_8_Z_24; + current->hwCapEnable |= MASK_StencilBufferEnable; + current->hwCapEnable |= MASK_ZWriteEnable; + smesa->depth_scale = 1.0 / (GLfloat)0xffffff; + break; + } + + current->hwZ &= ~MASK_ZBufferFormat; + current->hwZ |= smesa->zFormat; + + /* Destination Color Format */ + if (current->hwDstSet ^ prev->hwDstSet) { + prev->hwDstSet = current->hwDstSet; + smesa->GlobalFlag |= GFLAG_DESTSETTING; + } + + /* Z Buffer Data Format */ + if (current->hwZ ^ prev->hwZ) { + prev->hwZ = current->hwZ; + smesa->GlobalFlag |= GFLAG_ZSETTING; + } +} + +static void +sis_init_user_setting (GLcontext * ctx) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + +#if 0 /* XXX */ + /* disable all unsupported per-pixel extensions */ + gl_extensions_disable (ctx, "GL_EXT_blend_color"); + gl_extensions_disable (ctx, "GL_EXT_blend_minmax"); + gl_extensions_disable (ctx, "GL_EXT_blend_logic_op"); + gl_extensions_disable (ctx, "GL_EXT_blend_subtract"); + gl_extensions_disable (ctx, "GL_EXT_paletted_texture"); + gl_extensions_disable (ctx, "GL_EXT_point_parameters"); + gl_extensions_disable (ctx, "GL_EXT_texture3D"); + gl_extensions_disable (ctx, "GL_INGR_blend_func_separate"); + gl_extensions_disable (ctx, "GL_PGI_misc_hints"); + gl_extensions_disable (ctx, "GL_EXT_clip_volume_hint"); + gl_extensions_disable (ctx, "GL_EXT_texture_env_add"); + + /* TODO: driver doesn't handle this */ + if (getenv ("SIS_SINGLE_TEXTURE")) + gl_extensions_disable (ctx, "GL_ARB_multitexture"); +#endif + + /* turning off the extension has more speed */ + /* if mesa supports indirect VB rendering, remove it */ + + /* if disable it, quake3 will have broken triangle */ + /* gl_extensions_disable (ctx, "GL_EXT_compiled_vertex_array"); */ + + /* debug */ + if(getenv ("SIS_NO_AGP_CMDS")) + smesa->AGPCmdModeEnabled = GL_FALSE; + +#if SIS_STEREO + if(getenv ("SIS_STEREO") && smesa->irqEnabled) + smesa->useStereo = GL_TRUE; + else + smesa->useStereo = GL_FALSE; + + { + float val; + char *str; + + /* TODO: error check */ + if((str=getenv("SIS_STEREO_OFFSET"))){ + val= atof(str); + if(val>0 && val<1){ + StereoInitOffset = val; + } + } + + if((str=getenv("SIS_STEREO_SCALE"))){ + val= atof(str); + if(val>0){ + StereoInitScale = val; + } + } + } + + if(getenv("SIS_STEREO_DYNAMIC_Z")) + StereoDynamicZ = GL_TRUE; +#endif +} + +GLboolean +sisCreateContext( const __GLcontextModes *glVisual, + __DRIcontextPrivate *driContextPriv, + void *sharedContextPrivate ) +{ + GLcontext *ctx, *shareCtx; + __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv; + sisContextPtr smesa; + sisScreenPtr sisScreen; + int i; + + smesa = (sisContextPtr) CALLOC( sizeof(*smesa) ); + if ( smesa == NULL ) + return GL_FALSE; + + /* Allocate the Mesa context */ + if (sharedContextPrivate) + shareCtx = ((sisContextPtr) sharedContextPrivate)->glCtx; + else + shareCtx = NULL; + smesa->glCtx = _mesa_create_context(glVisual, shareCtx, (void *) smesa, GL_TRUE); + if (!smesa->glCtx) { + FREE(smesa); + return GL_FALSE; + } + driContextPriv->driverPrivate = smesa; + ctx = smesa->glCtx; + + sisScreen = smesa->sisScreen = (sisScreenPtr)(sPriv->private); + + smesa->driContext = driContextPriv; + smesa->driScreen = sPriv; + smesa->driDrawable = NULL; + smesa->hHWContext = driContextPriv->hHWContext; + smesa->driHwLock = &sPriv->pSAREA->lock; + smesa->driFd = sPriv->fd; + + smesa->virtualX = sisScreen->screenX; + smesa->virtualY = sisScreen->screenY; + smesa->bytesPerPixel = sisScreen->cpp; + smesa->IOBase = sisScreen->mmio.map; + smesa->Chipset = sisScreen->deviceID; + smesa->irqEnabled = sisScreen->irqEnabled; + + smesa->FbBase = sPriv->pFB; + smesa->displayWidth = sPriv->fbWidth; + smesa->frontPitch = sPriv->fbStride; + /* TODO: make sure psp->fd is sub-driver's fd */ + + smesa->sarea = (SISSAREAPriv *)((char *)sPriv->pSAREA + + sisScreen->sarea_priv_offset); + +#if defined(SIS_DUMP) + IOBase4Debug = GET_IOBase (smesa); +#endif + + /* support ARGB8888 and RGB565 */ + switch (smesa->bytesPerPixel) + { + case 4: + smesa->redMask = 0x00ff0000; + smesa->greenMask = 0x0000ff00; + smesa->blueMask = 0x000000ff; + smesa->alphaMask = 0xff000000; + smesa->colorFormat = DST_FORMAT_ARGB_8888; + break; + case 2: + smesa->redMask = 0xf800; + smesa->greenMask = 0x07e0; + smesa->blueMask = 0x001f; + smesa->alphaMask = 0; + smesa->colorFormat = DST_FORMAT_RGB_565; + break; + default: + assert (0); + } + + /* TODO: index mode */ + + smesa->CurrentQueueLenPtr = &(smesa->sarea->QueueLength); + smesa->FrameCountPtr = &(smesa->sarea->FrameCount); + + /* set AGP */ + smesa->AGPSize = sisScreen->agp.size; + smesa->AGPBase = sisScreen->agp.map; + smesa->AGPAddr = sisScreen->agp.handle; + + /* set AGP command buffer */ + smesa->AGPCmdModeEnabled = GL_FALSE; + if (smesa->AGPSize){ + if (sisScreen->AGPCmdBufSize){ + smesa->AGPCmdBufBase = smesa->AGPBase + sisScreen->AGPCmdBufOffset; + smesa->AGPCmdBufAddr = smesa->AGPAddr + sisScreen->AGPCmdBufOffset; + smesa->AGPCmdBufSize = sisScreen->AGPCmdBufSize; + + smesa->pAGPCmdBufNext = (GLint *)&(smesa->sarea->AGPCmdBufNext); + smesa->AGPCmdModeEnabled = GL_TRUE; + } + } + + smesa->GlobalFlag = 0L; + + smesa->swRenderFlag = 0; + smesa->swForceRender = GL_FALSE; + smesa->Primitive = 0; + smesa->Fallback = 0; + + /* Initialize the software rasterizer and helper modules. + */ + _swrast_CreateContext( ctx ); + _ac_CreateContext( ctx ); + _tnl_CreateContext( ctx ); + _swsetup_CreateContext( ctx ); + + /* Configure swrast to match hardware characteristics: + */ + _swrast_allow_pixel_fog( ctx, GL_FALSE ); + _swrast_allow_vertex_fog( ctx, GL_TRUE ); /* XXX Fixme? */ + + sisInitVB( ctx ); + sisInitTriFuncs( ctx ); + sisDDInitDriverFuncs( ctx ); + sisDDInitStateFuncs( ctx ); + sisDDInitSpanFuncs( ctx ); + sisDDInitStencilFuncs( ctx ); + sisDDInitTextureFuncs( ctx ); + + driInitExtensions( ctx, card_extensions, GL_FALSE ); + + /* TODO */ + /* smesa->blockWrite = SGRAMbw = IsBlockWrite (); */ + smesa->blockWrite = GL_FALSE; + + /* this function will over-write AGPCmdModeEnabled */ + /* TODO: pay attention to side-effect */ + sis_init_user_setting (ctx); + + sis_init_opengl_state (ctx); + sis_set_buffer_static (ctx); + sisUpdateZStencilPattern( smesa, 1.0, 0 ); + + /* TODO: need to clear cache? */ + smesa->clearTexCache = GL_TRUE; + + smesa->AGPParseSet = 0x00000040; + smesa->dwPrimitiveSet = 0x00060000; + + for (i = 0; i < SIS_MAX_TEXTURES; i++) + { + smesa->TexStates[i] = 0; + smesa->PrevTexFormat[i] = 0; + } + +#if SIS_STEREO + smesa->isFullScreen = GL_FALSE; + smesa->stereoEnabled = GL_FALSE; +#endif + + return GL_TRUE; +} + +void +sisDestroyContext ( __DRIcontextPrivate *driContextPriv ) +{ + sisContextPtr smesa = (sisContextPtr) driContextPriv->driverPrivate; + + assert( smesa != NULL ); + + if ( smesa != NULL ) { + _swsetup_DestroyContext( smesa->glCtx ); + _tnl_DestroyContext( smesa->glCtx ); + _ac_DestroyContext( smesa->glCtx ); + _swrast_DestroyContext( smesa->glCtx ); + + /* free the Mesa context */ + smesa->glCtx->DriverCtx = NULL; + _mesa_destroy_context(smesa->glCtx); + } + + FREE( smesa ); +} + +GLboolean +sisMakeCurrent( __DRIcontextPrivate *driContextPriv, + __DRIdrawablePrivate *driDrawPriv, + __DRIdrawablePrivate *driReadPriv ) +{ + if ( driContextPriv ) { + /*GET_CURRENT_CONTEXT(ctx); + sisContextPtr oldSisCtx = ctx ? SIS_CONTEXT(ctx) : NULL;*/ /* XXX see r128 */ + sisContextPtr newSisCtx = (sisContextPtr) driContextPriv->driverPrivate; + + newSisCtx->driDrawable = driDrawPriv; + + _mesa_make_current2( newSisCtx->glCtx, + (GLframebuffer *) driDrawPriv->driverPrivate, + (GLframebuffer *) driReadPriv->driverPrivate ); + + sisUpdateBufferSize( newSisCtx ); + + if ( newSisCtx->glCtx->Viewport.Width == 0 ) { + _mesa_set_viewport(newSisCtx->glCtx, 0, 0, + driDrawPriv->w, driDrawPriv->h); + } + } else { + _mesa_make_current( 0, 0 ); + } + + return GL_TRUE; +} + +GLboolean +sisUnbindContext( __DRIcontextPrivate *driContextPriv ) +{ + return GL_TRUE; +} + +void +sis_update_render_state( sisContextPtr smesa ) +{ + __GLSiSHardware *prev = &smesa->prev; + + mWait3DCmdQueue (45); + + if (smesa->GlobalFlag & GFLAG_ENABLESETTING) + { + if (!smesa->clearTexCache) + { + MMIO (REG_3D_TEnable, prev->hwCapEnable); + } + else + { + MMIO (REG_3D_TEnable, prev->hwCapEnable | MASK_TextureCacheClear); + MMIO (REG_3D_TEnable, prev->hwCapEnable); + smesa->clearTexCache = GL_FALSE; + } + } + + if (smesa->GlobalFlag & GFLAG_ENABLESETTING2) + { + MMIO (REG_3D_TEnable2, prev->hwCapEnable2); + } + + /* Z Setting */ + if (smesa->GlobalFlag & GFLAG_ZSETTING) + { + MMIO (REG_3D_ZSet, prev->hwZ); + MMIO (REG_3D_ZStWriteMask, prev->hwZMask); + MMIO (REG_3D_ZAddress, prev->hwOffsetZ); + } + + /* Alpha Setting */ + if (smesa->GlobalFlag & GFLAG_ALPHASETTING) + { + MMIO (REG_3D_AlphaSet, prev->hwAlpha); + } + + if (smesa->GlobalFlag & GFLAG_DESTSETTING) + { + MMIO (REG_3D_DstSet, prev->hwDstSet); + MMIO (REG_3D_DstAlphaWriteMask, prev->hwDstMask); + MMIO (REG_3D_DstAddress, prev->hwOffsetDest); + } + + /* Line Setting */ +#if 0 + if (smesa->GlobalFlag & GFLAG_LINESETTING) + { + MMIO(REG_3D_LinePattern, prev->hwLinePattern); + } +#endif + + /* Fog Setting */ + if (smesa->GlobalFlag & GFLAG_FOGSETTING) + { + MMIO (REG_3D_FogSet, prev->hwFog); + MMIO (REG_3D_FogInverseDistance, prev->hwFogInverse); + MMIO (REG_3D_FogFarDistance, prev->hwFogFar); + MMIO (REG_3D_FogFactorDensity, prev->hwFogDensity); + } + + /* Stencil Setting */ + if (smesa->GlobalFlag & GFLAG_STENCILSETTING) + { + MMIO (REG_3D_StencilSet, prev->hwStSetting); + MMIO (REG_3D_StencilSet2, prev->hwStSetting2); + } + + /* Miscellaneous Setting */ + if (smesa->GlobalFlag & GFLAG_DSTBLEND) + { + MMIO (REG_3D_DstBlendMode, prev->hwDstSrcBlend); + } + if (smesa->GlobalFlag & GFLAG_CLIPPING) + { + MMIO (REG_3D_ClipTopBottom, prev->clipTopBottom); + MMIO (REG_3D_ClipLeftRight, prev->clipLeftRight); + } + + smesa->GlobalFlag &= ~GFLAG_RENDER_STATES; +} + +void +sis_update_texture_state (sisContextPtr smesa) +{ + __GLSiSHardware *prev = &smesa->prev; + + mWait3DCmdQueue (55); + + if (smesa->clearTexCache) + { + MMIO (REG_3D_TEnable, prev->hwCapEnable | MASK_TextureCacheClear); + MMIO (REG_3D_TEnable, prev->hwCapEnable); + smesa->clearTexCache = GL_FALSE; + } + + /* Texture Setting */ + if (smesa->GlobalFlag & CFLAG_TEXTURERESET) + { + MMIO (REG_3D_TextureSet, prev->texture[0].hwTextureSet); + } + if (smesa->GlobalFlag & GFLAG_TEXTUREMIPMAP) + { + MMIO (REG_3D_TextureMip, prev->texture[0].hwTextureMip); + } + + /* + MMIO(REG_3D_TextureTransparencyColorHigh, prev->texture[0].hwTextureClrHigh); + MMIO(REG_3D_TextureTransparencyColorLow, prev->texture[0].hwTextureClrLow); + */ + + if (smesa->GlobalFlag & GFLAG_TEXBORDERCOLOR) + { + MMIO (REG_3D_TextureBorderColor, prev->texture[0].hwTextureBorderColor); + } + if (smesa->GlobalFlag & GFLAG_TEXTUREADDRESS) + { + MMIO (REG_3D_TEnable, prev->hwCapEnable | MASK_TextureCacheClear); + MMIO (REG_3D_TEnable, prev->hwCapEnable); + + switch ((prev->texture[0].hwTextureSet & MASK_TextureLevel) >> 8) + { + case 11: + MMIO (REG_3D_TextureAddress11, prev->texture[0].texOffset11); + case 10: + MMIO (REG_3D_TextureAddress10, prev->texture[0].texOffset10); + MMIO (REG_3D_TexturePitch10, prev->texture[0].texPitch10); + case 9: + MMIO (REG_3D_TextureAddress9, prev->texture[0].texOffset9); + case 8: + MMIO (REG_3D_TextureAddress8, prev->texture[0].texOffset8); + MMIO (REG_3D_TexturePitch8, prev->texture[0].texPitch89); + case 7: + MMIO (REG_3D_TextureAddress7, prev->texture[0].texOffset7); + case 6: + MMIO (REG_3D_TextureAddress6, prev->texture[0].texOffset6); + MMIO (REG_3D_TexturePitch6, prev->texture[0].texPitch67); + case 5: + MMIO (REG_3D_TextureAddress5, prev->texture[0].texOffset5); + case 4: + MMIO (REG_3D_TextureAddress4, prev->texture[0].texOffset4); + MMIO (REG_3D_TexturePitch4, prev->texture[0].texPitch45); + case 3: + MMIO (REG_3D_TextureAddress3, prev->texture[0].texOffset3); + case 2: + MMIO (REG_3D_TextureAddress2, prev->texture[0].texOffset2); + MMIO (REG_3D_TexturePitch2, prev->texture[0].texPitch23); + case 1: + MMIO (REG_3D_TextureAddress1, prev->texture[0].texOffset1); + case 0: + MMIO (REG_3D_TextureAddress0, prev->texture[0].texOffset0); + MMIO (REG_3D_TexturePitch0, prev->texture[0].texPitch01); + } + } + if (smesa->GlobalFlag & CFLAG_TEXTURERESET_1) + { + MMIO (REG_3D_Texture1Set, prev->texture[1].hwTextureSet); + } + if (smesa->GlobalFlag & GFLAG_TEXTUREMIPMAP_1) + { + MMIO (REG_3D_Texture1Mip, prev->texture[1].hwTextureMip); + } + + if (smesa->GlobalFlag & GFLAG_TEXBORDERCOLOR_1) + { + MMIO (REG_3D_Texture1BorderColor, + prev->texture[1].hwTextureBorderColor); + } + if (smesa->GlobalFlag & GFLAG_TEXTUREADDRESS_1) + { + switch ((prev->texture[1].hwTextureSet & MASK_TextureLevel) >> 8) + { + case 11: + MMIO (REG_3D_Texture1Address11, prev->texture[1].texOffset11); + case 10: + MMIO (REG_3D_Texture1Address10, prev->texture[1].texOffset10); + MMIO (REG_3D_Texture1Pitch10, prev->texture[1].texPitch10); + case 9: + MMIO (REG_3D_Texture1Address9, prev->texture[1].texOffset9); + case 8: + MMIO (REG_3D_Texture1Address8, prev->texture[1].texOffset8); + MMIO (REG_3D_Texture1Pitch8, prev->texture[1].texPitch89); + case 7: + MMIO (REG_3D_Texture1Address7, prev->texture[1].texOffset7); + case 6: + MMIO (REG_3D_Texture1Address6, prev->texture[1].texOffset6); + MMIO (REG_3D_Texture1Pitch6, prev->texture[1].texPitch67); + case 5: + MMIO (REG_3D_Texture1Address5, prev->texture[1].texOffset5); + case 4: + MMIO (REG_3D_Texture1Address4, prev->texture[1].texOffset4); + MMIO (REG_3D_Texture1Pitch4, prev->texture[1].texPitch45); + case 3: + MMIO (REG_3D_Texture1Address3, prev->texture[1].texOffset3); + case 2: + MMIO (REG_3D_Texture1Address2, prev->texture[1].texOffset2); + MMIO (REG_3D_Texture1Pitch2, prev->texture[1].texPitch23); + case 1: + MMIO (REG_3D_Texture1Address1, prev->texture[1].texOffset1); + case 0: + MMIO (REG_3D_Texture1Address0, prev->texture[1].texOffset0); + MMIO (REG_3D_Texture1Pitch0, prev->texture[1].texPitch01); + } + } + + /* texture environment */ + if (smesa->GlobalFlag & GFLAG_TEXTUREENV) + { + MMIO (REG_3D_TextureBlendFactor, prev->hwTexEnvColor); + MMIO (REG_3D_TextureColorBlendSet0, prev->hwTexBlendClr0); + MMIO (REG_3D_TextureAlphaBlendSet0, prev->hwTexBlendAlpha0); + } + if (smesa->GlobalFlag & GFLAG_TEXTUREENV_1) + { + MMIO (REG_3D_TextureBlendFactor, prev->hwTexEnvColor); + MMIO (REG_3D_TextureColorBlendSet1, prev->hwTexBlendClr1); + MMIO (REG_3D_TextureAlphaBlendSet1, prev->hwTexBlendAlpha1); + } + + smesa->GlobalFlag &= ~GFLAG_TEXTURE_STATES; +} + +/* Updates all state. + * Called when the lock is taken and another context had the lock previously. + */ +void +sis_validate_all_state (sisContextPtr smesa) +{ + __GLSiSHardware *prev = &smesa->prev; + + mEndPrimitive (); + mWait3DCmdQueue (40); + + /* Enable Setting */ + MMIO (REG_3D_TEnable, prev->hwCapEnable); + MMIO (REG_3D_TEnable2, prev->hwCapEnable2); + + /* Z Setting */ + /* if (prev->hwCapEnable & MASK_ZTestEnable) { */ + MMIO (REG_3D_ZSet, prev->hwZ); + MMIO (REG_3D_ZStWriteMask, prev->hwZMask); + MMIO (REG_3D_ZAddress, prev->hwOffsetZ); + /* } */ + + /* Alpha Setting */ + if (prev->hwCapEnable & MASK_AlphaTestEnable) + { + MMIO (REG_3D_AlphaSet, prev->hwAlpha); + } + + /* Destination Setting */ + MMIO (REG_3D_DstSet, prev->hwDstSet); + MMIO (REG_3D_DstAlphaWriteMask, prev->hwDstMask); + MMIO (REG_3D_DstAddress, prev->hwOffsetDest); + + /* Line Setting */ +#if 0 + if (prev->hwCapEnable2 & MASK_LinePatternEnable) { + MMIO(REG_3D_LinePattern, prev->hwLinePattern); + } +#endif + + /* Fog Setting */ + if (prev->hwCapEnable & MASK_FogEnable) + { + MMIO (REG_3D_FogSet, prev->hwFog); + MMIO (REG_3D_FogInverseDistance, prev->hwFogInverse); + MMIO (REG_3D_FogFarDistance, prev->hwFogFar); + MMIO (REG_3D_FogFactorDensity, prev->hwFogDensity); + } + + /* Stencil Setting */ + if (prev->hwCapEnable & MASK_StencilTestEnable) + { + MMIO (REG_3D_StencilSet, prev->hwStSetting); + MMIO (REG_3D_StencilSet2, prev->hwStSetting2); + } + + /* Miscellaneous Setting */ + if (prev->hwCapEnable & MASK_BlendEnable) + { + MMIO (REG_3D_DstBlendMode, prev->hwDstSrcBlend); + } + + MMIO (REG_3D_ClipTopBottom, prev->clipTopBottom); + MMIO (REG_3D_ClipLeftRight, prev->clipLeftRight); + + /* TODO */ + /* Texture Setting */ + /* if (prev->hwCapEnable & MASK_TextureEnable) */ + { + MMIO (REG_3D_TEnable, prev->hwCapEnable | MASK_TextureCacheClear); + + MMIO (REG_3D_TEnable, prev->hwCapEnable); + + MMIO (REG_3D_TextureSet, prev->texture[0].hwTextureSet); + MMIO (REG_3D_TextureMip, prev->texture[0].hwTextureMip); + /* + MMIO(REG_3D_TextureTransparencyColorHigh, prev->texture[0].hwTextureClrHigh); + MMIO(REG_3D_TextureTransparencyColorLow, prev->texture[0].hwTextureClrLow); + */ + MMIO (REG_3D_TextureBorderColor, prev->texture[0].hwTextureBorderColor); + + switch ((prev->texture[0].hwTextureSet & MASK_TextureLevel) >> 8) + { + case 11: + MMIO (REG_3D_TextureAddress11, prev->texture[0].texOffset11); + case 10: + MMIO (REG_3D_TextureAddress10, prev->texture[0].texOffset10); + MMIO (REG_3D_TexturePitch10, prev->texture[0].texPitch10); + case 9: + MMIO (REG_3D_TextureAddress9, prev->texture[0].texOffset9); + case 8: + MMIO (REG_3D_TextureAddress8, prev->texture[0].texOffset8); + MMIO (REG_3D_TexturePitch8, prev->texture[0].texPitch89); + case 7: + MMIO (REG_3D_TextureAddress7, prev->texture[0].texOffset7); + case 6: + MMIO (REG_3D_TextureAddress6, prev->texture[0].texOffset6); + MMIO (REG_3D_TexturePitch6, prev->texture[0].texPitch67); + case 5: + MMIO (REG_3D_TextureAddress5, prev->texture[0].texOffset5); + case 4: + MMIO (REG_3D_TextureAddress4, prev->texture[0].texOffset4); + MMIO (REG_3D_TexturePitch4, prev->texture[0].texPitch45); + case 3: + MMIO (REG_3D_TextureAddress3, prev->texture[0].texOffset3); + case 2: + MMIO (REG_3D_TextureAddress2, prev->texture[0].texOffset2); + MMIO (REG_3D_TexturePitch2, prev->texture[0].texPitch23); + case 1: + MMIO (REG_3D_TextureAddress1, prev->texture[0].texOffset1); + case 0: + MMIO (REG_3D_TextureAddress0, prev->texture[0].texOffset0); + MMIO (REG_3D_TexturePitch0, prev->texture[0].texPitch01); + } + + /* TODO */ + /* if (smesa->ctx->Texture.Unit[1].ReallyEnabled) */ + { + MMIO (REG_3D_Texture1Set, prev->texture[1].hwTextureSet); + MMIO (REG_3D_Texture1Mip, prev->texture[1].hwTextureMip); + /* + MMIO(REG_3D_Texture1TransparencyColorHigh, prev->texture[1].hwTextureClrHigh); + MMIO(REG_3D_Texture1TransparencyColorLow, prev->texture[1].hwTextureClrLow); + */ + MMIO (REG_3D_Texture1BorderColor, prev->texture[1].hwTextureBorderColor); + + switch ((prev->texture[1].hwTextureSet & MASK_TextureLevel) >> 8) + { + case 11: + MMIO (REG_3D_Texture1Address11, prev->texture[1].texOffset11); + case 10: + MMIO (REG_3D_Texture1Address10, prev->texture[1].texOffset10); + MMIO (REG_3D_Texture1Pitch10, prev->texture[1].texPitch10); + case 9: + MMIO (REG_3D_Texture1Address9, prev->texture[1].texOffset9); + case 8: + MMIO (REG_3D_Texture1Address8, prev->texture[1].texOffset8); + MMIO (REG_3D_Texture1Pitch8, prev->texture[1].texPitch89); + case 7: + MMIO (REG_3D_Texture1Address7, prev->texture[1].texOffset7); + case 6: + MMIO (REG_3D_Texture1Address6, prev->texture[1].texOffset6); + MMIO (REG_3D_Texture1Pitch6, prev->texture[1].texPitch67); + case 5: + MMIO (REG_3D_Texture1Address5, prev->texture[1].texOffset5); + case 4: + MMIO (REG_3D_Texture1Address4, prev->texture[1].texOffset4); + MMIO (REG_3D_Texture1Pitch4, prev->texture[1].texPitch45); + case 3: + MMIO (REG_3D_Texture1Address3, prev->texture[1].texOffset3); + case 2: + MMIO (REG_3D_Texture1Address2, prev->texture[1].texOffset2); + MMIO (REG_3D_Texture1Pitch2, prev->texture[1].texPitch23); + case 1: + MMIO (REG_3D_Texture1Address1, prev->texture[1].texOffset1); + case 0: + MMIO (REG_3D_Texture1Address0, prev->texture[1].texOffset0); + MMIO (REG_3D_Texture1Pitch0, prev->texture[1].texPitch01); + } + } + + /* texture environment */ + MMIO (REG_3D_TextureBlendFactor, prev->hwTexEnvColor); + MMIO (REG_3D_TextureColorBlendSet0, prev->hwTexBlendClr0); + MMIO (REG_3D_TextureColorBlendSet1, prev->hwTexBlendClr1); + MMIO (REG_3D_TextureAlphaBlendSet0, prev->hwTexBlendAlpha0); + MMIO (REG_3D_TextureAlphaBlendSet1, prev->hwTexBlendAlpha1); + } + + smesa->GlobalFlag = 0; +} + +void +sis_fatal_error (void) +{ + /* free video memory, or the framebuffer device will do it automatically */ + + fprintf(stderr, "Fatal errors in sis_dri.so\n"); + exit (-1); +} diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_context.h xc/lib/GL/mesa/src/drv/sis/sis_context.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_context.h Wed Dec 31 16:00:00 1969 +++ xc/lib/GL/mesa/src/drv/sis/sis_context.h Fri Aug 22 15:33:20 2003 @@ -0,0 +1,383 @@ +/************************************************************************** + +Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan. +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sub license, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. +IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ +/* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_ctx.h,v 1.5 2000/09/26 15:56:48 tsi Exp $ */ + +/* + * Authors: + * Sung-Ching Lin + * + */ + +#ifndef _sis_ctx_h_ +#define _sis_ctx_h_ + +#include "context.h" +#include "dri_util.h" + +#include "sis_screen.h" +#include "sis_common2.h" +#include "sis_sarea.h" + +/* for GLboolean */ +#include + +#define PCI_CHIP_SIS300 0x0300 +#define PCI_CHIP_SIS630 0x6300 +#define PCI_CHIP_SIS540 0x5300 + +#define SIS_STATE_TRIANGLE 1 +#define SIS_STATE_LINE 2 +#define SIS_STATE_POINT 3 + +/* for swRenderFlag */ +#define SIS_SW_TRIANGLE 0x1 +#define SIS_SW_LINE 0x2 +#define SIS_SW_POINT 0x4 +#define SIS_SW_TEXTURE_DIM 0x8 +#define SIS_SW_TEXTURE_OBJ 0x10 +#define SIS_SW_TEXTURE_OBJ1 0x20 +#define SIS_SW_TEXTURE_ENV 0x100 +#define SIS_SW_TEXTURE_ENV1 0x200 + +#define NEW_TEXTURING 0x1 +#define NEW_TEXTURE_ENV 0x2 + +#define SIS_SW_TEXTURE (SIS_SW_TEXTURE_DIM | \ + SIS_SW_TEXTURE_OBJ | SIS_SW_TEXTURE_OBJ1 | \ + SIS_SW_TEXTURE_ENV | SIS_SW_TEXTURE_ENV1) +#define SIS_SW_ALL (SIS_SW_POINT | SIS_SW_LINE | SIS_SW_TRIANGLE | \ + SIS_SW_TEXTURE) + +/* Flags for software fallback cases: + */ +#define SIS_FALLBACK_TEXTURE 0x0001 +#define SIS_FALLBACK_CULL 0x0002 +#define SIS_FALLBACK_FORCE 0x8000 + +/* Use the templated vertex format: + */ +#define TAG(x) sis##x +#include "tnl_dd/t_dd_vertex.h" +#undef TAG + +/* Subpixel offsets for window coordinates (triangles): + */ +#define SUBPIXEL_X (0.0F) /* XXX FIXME */ +#define SUBPIXEL_Y (0.0F) /* XXX FIXME */ + +/* + ** Device dependent context state + */ +typedef struct __GLSiSTextureRec +{ + GLint hwTextureSet; + GLint hwTextureMip; + GLint hwTextureClrHigh; + GLint hwTextureClrLow; + GLint hwTextureBorderColor; + + GLint texOffset0; + GLint texOffset1; + GLint texOffset2; + GLint texOffset3; + GLint texOffset4; + GLint texOffset5; + GLint texOffset6; + GLint texOffset7; + GLint texOffset8; + GLint texOffset9; + GLint texOffset10; + GLint texOffset11; + + GLint texPitch01; + GLint texPitch23; + GLint texPitch45; + GLint texPitch67; + GLint texPitch89; + GLint texPitch10; +} +__GLSiSTexture; + +typedef struct __GLSiSHardwareRec +{ + GLint hwCapEnable, hwCapEnable2; /* Enable Setting */ + + GLint hwOffsetZ, hwZ; /* Z Setting */ + + GLint hwZBias, hwZMask; /* Z Setting */ + + GLint hwAlpha; /* Alpha Setting */ + + GLint hwDstSet, hwDstMask; /* Destination Setting */ + + GLint hwOffsetDest; /* Destination Setting */ + + GLint hwLinePattern; /* Line Setting */ + + GLint hwFog; /* Fog Setting */ + + GLint hwFogFar, hwFogInverse; /* Fog Distance setting */ + + GLint hwFogDensity; /* Fog factor & density */ + + GLint hwStSetting, hwStSetting2; /* Stencil Setting */ + + GLint hwStOffset; /* Stencil Setting */ + + GLint hwDstSrcBlend; /* Blending mode Setting */ + + GLint clipTopBottom; /* Clip for Top & Bottom */ + + GLint clipLeftRight; /* Clip for Left & Right */ + + struct __GLSiSTextureRec texture[2]; + + GLint hwTexEnvColor; /* Texture Blending Setting */ + + GLint hwTexBlendClr0; + GLint hwTexBlendClr1; + GLint hwTexBlendAlpha0; + GLint hwTexBlendAlpha1; + +} +__GLSiSHardware; + +typedef struct sis_context sisContextRec; +typedef struct sis_context *sisContextPtr; + +typedef void (*sis_tri_func)( sisContextPtr, + sisVertex *, + sisVertex *, + sisVertex * ); + +typedef void (*sis_line_func)( sisContextPtr, + sisVertex *, + sisVertex * ); + +typedef void (*sis_point_func)( sisContextPtr, + sisVertex * ); + +/* Device dependent context state */ + +struct sis_context +{ + /* This must be first in this structure */ + GLcontext *glCtx; + + /* Temporaries for translating away float colors: + */ + struct gl_client_array UbyteColor; + struct gl_client_array UbyteSecondaryColor; + + GLuint NewGLState; + GLuint Fallback; + GLuint SetupIndex; + GLuint SetupNewInputs; + GLuint RenderIndex; + GLfloat hw_viewport[16]; + GLfloat depth_scale; + GLuint vertex_size; + GLuint vertex_stride_shift; + GLuint vertex_format; + GLuint num_verts; + char *verts; + + unsigned int virtualX, virtualY; + unsigned int bytesPerPixel; + unsigned char *IOBase; + unsigned char *FbBase; + unsigned int displayWidth; + unsigned int frontOffset; + unsigned int frontPitch; + + /* For Software Renderer */ + GLubyte *swZBase; + GLuint swZPitch; + GLboolean swForceRender; + + /* HW RGBA layout */ + unsigned int redMask, greenMask, blueMask, alphaMask; + unsigned int colorFormat; + + /* Z format */ + unsigned int zFormat; + + /* Clear patterns, 4 bytes */ + unsigned int clearColorPattern; + unsigned int clearZStencilPattern; + + /* Fallback rasterization functions + */ + sis_point_func draw_point; + sis_line_func draw_line; + sis_tri_func draw_tri; + + GLuint hw_primitive; + GLenum raster_primitive; + GLenum render_primitive; + + /* DRM fd */ + int driFd; + + /* AGP Memory */ + unsigned int AGPSize; + unsigned char *AGPBase; + unsigned int AGPAddr; + + /* AGP Command Buffer */ + /* TODO: use Global variables */ + + unsigned char *AGPCmdBufBase; + GLint AGPCmdBufAddr; + unsigned int AGPCmdBufSize; + GLint *pAGPCmdBufNext; + GLboolean AGPCmdModeEnabled; + GLboolean UseAGPCmdMode; + + /* register 0x89F4 */ + GLint AGPParseSet; + + /* register 0x89F8 */ + GLint dwPrimitiveSet; + + __GLSiSHardware prev, current; + + GLint chipVer; + int Chipset; + + GLint drawableID; + + /* SGRAM block write */ + GLboolean blockWrite; + + GLuint swRenderFlag; + GLenum Primitive; + + GLint GlobalFlag; + + GLint rawLockMask; + GLint lockMask; + + void (*SwapBuffers)(XMesaBuffer b); + + /* Stereo */ + GLboolean isFullScreen; + GLboolean useStereo; + GLboolean stereoEnabled; + int stereo_drawIndex; + int stereo_drawSide; + GLboolean irqEnabled; + + GLboolean clearTexCache; + + GLuint TexStates[SIS_MAX_TEXTURES]; + GLuint PrevTexFormat[SIS_MAX_TEXTURES]; + + int *CurrentQueueLenPtr; + unsigned int *FrameCountPtr; + + /* Front/back/depth buffer info */ + GLuint width, height; /* size of buffers */ + GLint bottom; /* used for FLIP macro */ + GLvoid *backbuffer; + unsigned int backOffset; + unsigned int backPitch; + GLvoid *depthbuffer; + void *zbFree, *bbFree; /* Cookies for freeing buffers */ + ENGPACKET zClearPacket, cbClearPacket; + + /* Drawable, cliprect and scissor information + */ + GLint drawOffset, drawPitch; + GLint readOffset, readPitch; + + /* Mirrors of some DRI state + */ + __DRIcontextPrivate *driContext; /* DRI context */ + __DRIscreenPrivate *driScreen; /* DRI screen */ + __DRIdrawablePrivate *driDrawable; /* DRI drawable bound to this ctx */ + + unsigned int lastStamp; /* mirror driDrawable->lastStamp */ + + drmContext hHWContext; + drmLock *driHwLock; + + sisScreenPtr sisScreen; /* Screen private DRI data */ + SISSAREAPrivPtr sarea; /* Private SAREA data */ +}; + +#define SIS_CONTEXT(ctx) ((sisContextPtr)(ctx->DriverCtx)) + +/* Macros */ +#define GET_IOBase(x) ((x)->IOBase) +#define GET_FbBase(x) ((x)->FbBase) +#define GET_AGPBase(x) ((x)->AGPBase) +#define GET_DEPTH(x) ((x)->bytesPerPixel) +#define GET_WIDTH(x) ((x)->displayWidth) +#define GET_FbPos(smesa,x,y) (GET_FbBase(smesa)+(x)*GET_DEPTH(smesa)\ + +(y)*smesa->frontPitch) + +#define GET_ColorFormat(x) ((x)->colorFormat) + +#define GET_RMASK(x) ((x)->redMask) +#define GET_GMASK(x) ((x)->greenMask) +#define GET_BMASK(x) ((x)->blueMask) +#define GET_AMASK(x) ((x)->alphaMask) +#define Y_FLIP(Y) (smesa->bottom - Y) + +#define SISPACKCOLOR565( r, g, b ) \ + ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3)) + +#define SISPACKCOLOR8888( r, g, b, a ) \ + (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)) + +extern GLboolean sisCreateContext( const __GLcontextModes *glVisual, + __DRIcontextPrivate *driContextPriv, + void *sharedContextPrivate ); +extern void sisDestroyContext( __DRIcontextPrivate * ); + +extern GLboolean sisMakeCurrent( __DRIcontextPrivate *driContextPriv, + __DRIdrawablePrivate *driDrawPriv, + __DRIdrawablePrivate *driReadPriv ); + +extern GLboolean sisUnbindContext( __DRIcontextPrivate *driContextPriv ); + +void WaitEngIdle (sisContextPtr smesa); +void Wait2DEngIdle (sisContextPtr smesa); + +/* update to hw */ +extern void sis_update_texture_state( sisContextPtr smesa ); +extern void sis_update_render_state( sisContextPtr smesa ); +extern void sis_validate_all_state( sisContextPtr smesa ); + +/* AGP */ +void sis_StartAGP (GLcontext * ctx); +void sis_FlushAGP (GLcontext * ctx); + +void sis_fatal_error (void); + +#endif diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_ctx.c xc/lib/GL/mesa/src/drv/sis/sis_ctx.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_ctx.c Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_ctx.c Wed Dec 31 16:00:00 1969 @@ -1,874 +0,0 @@ -/************************************************************************** - -Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan. -All Rights Reserved. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sub license, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice (including the -next paragraph) shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. -IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -**************************************************************************/ -/* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_ctx.c,v 1.3 2000/09/26 15:56:48 tsi Exp $ */ - -/* - * Authors: - * Sung-Ching Lin - * - */ - -#ifdef XFree86Server -# define PSZ 8 -# include "cfb.h" -# undef PSZ -# include "cfb16.h" -# include "cfb24.h" -# include "cfb32.h" -# include "cfb24_32.h" -/* for SISPtr */ -# include "xf86.h" -# include "xf86_OSproc.h" -# include "xf86Resources.h" -# include "xf86Version.h" -# include "xf86PciInfo.h" -# include "xf86Pci.h" -# include "xf86cmap.h" -# include "vgaHW.h" -# include "xf86RAC.h" -# include "sis_regs.h" -# include "sis.h" -# include "dristruct.h" -# include "dri.h" -#else -#include "sis_dri.h" -#endif - -#include "extensions.h" - -#include "sis_ctx.h" -#include "sis_mesa.h" - -int GlobalCurrentHwcx = -1; -int GlobalHwcxCountBase = 1; -int GlobalCmdQueueLen = 0; - -void -WaitEngIdle (__GLSiScontext * hwcx) -{ - BYTE *IOBase = GET_IOBase (hwcx); - BYTE cEngineState; - - cEngineState = *((BYTE volatile *) (IOBase + 0x8243)); - while (((cEngineState & 0x80) == 0) || - ((cEngineState & 0x40) == 0) || ((cEngineState & 0x20) == 0)) - { - cEngineState = *((BYTE volatile *) (IOBase + 0x8243)); - } -} - -void -Wait2DEngIdle (__GLSiScontext * hwcx) -{ - BYTE *IOBase = GET_IOBase (hwcx); - BYTE cEngineState; - - cEngineState = *((BYTE volatile *) (IOBase + 0x8243)); - while (!(cEngineState & 0x80)) - { - cEngineState = *((BYTE volatile *) (IOBase + 0x8243)); - } -} - -static void -sis_init_opengl_state (GLcontext * ctx) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - __GLSiSHardware *current = &hwcx->current; - __GLSiSHardware *prev = &(hwcx->prev); - - /* - prev->hwCapEnable = INIT_6327_CapsEnable ; - prev->hwCapEnable = 0x000000a0; - */ - /* add Texture Perspective Enable */ - prev->hwCapEnable = 0x000002a0; - - /* - prev->hwCapEnable2 = INIT_6327_CapsEnable2; - prev->hwCapEnable2 = 0x00aa0080; - */ - /* if multi-texture enabled, disable Z pre-test */ - prev->hwCapEnable2 = 0x00000000; - - /* Z test mode is LE */ - prev->hwZ = INIT_6327_ZSet; - - /* TODO : maybe call sis_DepthFunc to update is a better way */ - ctx->Driver.DepthFunc (ctx, ctx->Depth.Func); - - /* Depth mask */ - prev->hwZMask = INIT_6327_ZMask; - - /* Alpha test mode is ALWAYS, Alpha ref value is 0 */ - prev->hwAlpha = INIT_6327_AlphaSet; - - /* ROP2 is COPYPEN */ - prev->hwDstSet = INIT_6327_DstSet; - - /* color mask */ - prev->hwDstMask = INIT_6327_DstMask; - - /* LinePattern is 0, Repeat Factor is 0 */ - prev->hwLinePattern = 0x00008000; - - /* Fog mode is Linear Fog, Fog color is (0, 0, 0) */ - prev->hwFog = INIT_6327_FogSet; - - /* Src blend is BLEND_ONE, Dst blend is D3DBLEND_ZERO */ - prev->hwDstSrcBlend = INIT_6327_BlendMode; - - /* Texture mapping mode is Tile */ -#if 0 - prev->texture[0].hwTextqureSet = INIT_6327_TextureSet; -#endif - /* Magnified & minified texture filter is NEAREST */ -#if 0 - prev->texture[0].hwTextureMip = INIT_6327_TextureMip; -#endif - - /* Texture Blending seeting */ - prev->hwTexBlendClr0 = INIT_6327_TextureColorBlend0; - - prev->hwTexBlendClr1 = INIT_6327_TextureColorBlend1; - - prev->hwTexBlendAlpha0 = INIT_6327_TextureAlphaBlend0; - - prev->hwTexBlendAlpha1 = INIT_6327_TextureAlphaBlend1; - - memcpy (current, prev, sizeof (__GLSiSHardware)); - - /* Init the texture transparency color high range value */ -#if 0 - lpdwRegIO = ((LPDWORD)hwcx->lpEngIO + REG_3D_TransparencyColorHigh); - prev->hwTextureClrHigh = INIT_6326_TextureClrHigh; - *(lpdwRegIO) = INIT_6327_TextureClrHigh; -#endif -} - -static void -sis_init_user_setting (GLcontext * ctx) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - /* disable all unsupported per-pixel extensions */ - gl_extensions_disable (ctx, "GL_EXT_blend_color"); - gl_extensions_disable (ctx, "GL_EXT_blend_minmax"); - gl_extensions_disable (ctx, "GL_EXT_blend_logic_op"); - gl_extensions_disable (ctx, "GL_EXT_blend_subtract"); - gl_extensions_disable (ctx, "GL_EXT_paletted_texture"); - gl_extensions_disable (ctx, "GL_EXT_point_parameters"); - gl_extensions_disable (ctx, "GL_EXT_texture3D"); - gl_extensions_disable (ctx, "GL_INGR_blend_func_separate"); - gl_extensions_disable (ctx, "GL_PGI_misc_hints"); - gl_extensions_disable (ctx, "GL_EXT_clip_volume_hint"); - gl_extensions_disable (ctx, "GL_EXT_texture_env_add"); - - /* TODO: driver doesn't handle this */ - if (getenv ("SIS_SINGLE_TEXTURE")) - gl_extensions_disable (ctx, "GL_ARB_multitexture"); - - /* turning off the extension has more speed */ - /* if mesa supports indirect VB rendering, remove it */ - - /* if disable it, quake3 will have broken triangle */ - /* gl_extensions_disable (ctx, "GL_EXT_compiled_vertex_array"); */ - - /* debug */ - if(getenv ("SIS_NO_AGP_CMDS")) - hwcx->AGPCmdModeEnabled = GL_FALSE; - -#if SIS_STEREO - if(getenv ("SIS_STEREO") && hwcx->irqEnabled) - hwcx->useStereo = GL_TRUE; - else - hwcx->useStereo = GL_FALSE; - - { - float val; - char *str; - - /* TODO: error check */ - if((str=getenv("SIS_STEREO_OFFSET"))){ - val= atof(str); - if(val>0 && val<1){ - StereoInitOffset = val; - } - } - - if((str=getenv("SIS_STEREO_SCALE"))){ - val= atof(str); - if(val>0){ - StereoInitScale = val; - } - } - } - - if(getenv("SIS_STEREO_DYNAMIC_Z")) - StereoDynamicZ = GL_TRUE; -#endif -} - -void -SiSCreateContext (XMesaContext xmesa) -{ - GLcontext *ctx = xmesa->gl_ctx; - __GLSiScontext *hwcx; - - int i; - - hwcx = (__GLSiScontext *) calloc (1, sizeof (__GLSiScontext)); - if (!hwcx) - { - fprintf (stderr, "SIS Driver : allocating context fails\n"); - sis_fatal_error (); - return; - } - - /* set gc */ - hwcx->gc = ctx; - xmesa->private = hwcx; - - /* set static part in ctx->Driver */ - sis_init_driver (ctx); - - /* Set 2D data (from X-Server) */ - /* i assume the data will not change during X-server's lifetime */ -#ifdef XFree86Server - { - ScrnInfoPtr pScrn = xf86Screens[xmesa->display->myNum]; - SISPtr pSiS = SISPTR (pScrn); - - hwcx->virtualX = pSiS->pScrn->virtualX; - hwcx->virtualY = pSiS->pScrn->virtualY; - hwcx->bytesPerPixel = (pSiS->pScrn->bitsPerPixel + 7) / 8; - hwcx->IOBase = pSiS->IOBase; - hwcx->FbBase = pSiS->FbBase; - hwcx->displayWidth = pSiS->pScrn->displayWidth * hwcx->bytesPerPixel; - hwcx->pitch = pSiS->scrnOffset; - hwcx->Chipset = pSiS->Chipset; - hwcx->drmSubFD = pSiS->drmSubFD; -#if SIS_STEREO - hwcx->irqEnabled = pSiS->irqEnabled; -#endif - } -#else - { - __DRIscreenPrivate *psp = xmesa->driContextPriv->driScreenPriv; - SISDRIPtr priv = (SISDRIPtr) psp->pDevPriv; - - hwcx->virtualX = priv->width; - hwcx->virtualY = priv->height; - hwcx->bytesPerPixel = priv->bytesPerPixel; - hwcx->IOBase = priv->regs.map; - hwcx->FbBase = psp->pFB; - hwcx->displayWidth = psp->fbWidth; - hwcx->pitch = psp->fbStride; - hwcx->Chipset = priv->deviceID; - /* TODO: make sure psp->fd is sub-driver's fd */ - hwcx->drmSubFD = psp->fd; -#if SIS_STEREO - hwcx->irqEnabled = priv->irqEnabled; -#endif - } -#endif - -#if defined(SIS_DUMP) - IOBase4Debug = GET_IOBase (hwcx); -#endif - - /* support ARGB8888 and RGB565 */ - switch (hwcx->bytesPerPixel) - { - case 4: - hwcx->redMask = 0x00ff0000; - hwcx->greenMask = 0x0000ff00; - hwcx->blueMask = 0x000000ff; - hwcx->alphaMask = 0xff000000; - hwcx->colorFormat = DST_FORMAT_ARGB_8888; - break; - case 2: - hwcx->redMask = 0xf800; - hwcx->greenMask = 0x07e0; - hwcx->blueMask = 0x001f; - hwcx->alphaMask = 0; - hwcx->colorFormat = DST_FORMAT_RGB_565; - break; - default: - assert (0); - } - - sis_sw_init_driver (ctx); - - /* TODO: index mode */ - -#if defined(XFree86Server) - { -#if defined(XF86DRI) - ScreenPtr pScreen = xmesa->display; - ScrnInfoPtr pScrn = xf86Screens[xmesa->display->myNum]; - SISPtr pSiS = SISPTR (pScrn); - - if (pSiS->directRenderingEnabled) - { - SISSAREAPriv *saPriv = (SISSAREAPriv *) DRIGetSAREAPrivate (pScreen); - - drmContextPtr contextPtr; - - /* in DR, the action is done by DRI */ - hwcx->pDRIContextPriv = DRICreateContextPriv (pScreen, contextPtr, 0); - if (!contextPtr) - { - /* TODO */ - assert(0); - } - - hwcx->serialNumber = (int) *contextPtr; - hwcx->CurrentHwcxPtr = &(saPriv->CtxOwner); - hwcx->CurrentQueueLenPtr = pSiS->cmdQueueLenPtr; - /* hwcx->FrameCountPtr = */ - - /* what does this do? */ - /* - drmFreeReservedContextList (contextPtr); - */ - - /* TODO, set AGP command buffer */ - hwcx->AGPCmdModeEnabled = GL_FALSE; - } - else -#endif - { - hwcx->serialNumber = GlobalHwcxCountBase++; - hwcx->CurrentHwcxPtr = &GlobalCurrentHwcx; - hwcx->CurrentQueueLenPtr = pSiS->cmdQueueLenPtr; - /* hwcx->FrameCountPtr = */ - - /* TODO, set AGP command buffer */ - hwcx->AGPCmdModeEnabled = GL_FALSE; - } - } -#else - { - __DRIscreenPrivate *psp = xmesa->driContextPriv->driScreenPriv; - SISDRIPtr priv = (SISDRIPtr) psp->pDevPriv; - SISSAREAPriv *saPriv = (SISSAREAPriv *) (((char *) psp->pSAREA) + - sizeof (XF86DRISAREARec)); - - /* or use xmesa->driContextPriv->contextID - * use hHWContext is better, but limit ID to [0..2^31-1] (modify driver) - * hHWContext is CARD32 - */ - hwcx->serialNumber = xmesa->driContextPriv->hHWContext; - hwcx->CurrentHwcxPtr = &(saPriv->CtxOwner); - hwcx->CurrentQueueLenPtr = &(saPriv->QueueLength); - hwcx->FrameCountPtr = &(saPriv->FrameCount); - - /* set AGP */ - hwcx->AGPSize = priv->agp.size; - hwcx->AGPBase = priv->agp.map; - hwcx->AGPAddr = priv->agp.handle; - - /* set AGP command buffer */ - hwcx->AGPCmdModeEnabled = GL_FALSE; - if (hwcx->AGPSize){ - if(priv->AGPCmdBufSize){ - hwcx->AGPCmdBufBase = hwcx->AGPBase + priv->AGPCmdBufOffset; - hwcx->AGPCmdBufAddr = hwcx->AGPAddr + priv->AGPCmdBufOffset; - hwcx->AGPCmdBufSize = priv->AGPCmdBufSize; - - hwcx->pAGPCmdBufNext = (DWORD *)&(saPriv->AGPCmdBufNext); - hwcx->AGPCmdModeEnabled = GL_TRUE; - } - } - } -#endif - - hwcx->GlobalFlag = 0L; - - hwcx->swRenderFlag = 0; - hwcx->swForceRender = GL_FALSE; - hwcx->Primitive = 0; - hwcx->useFastPath = GL_FALSE; - - /* TODO */ - /* hwcx->blockWrite = SGRAMbw = IsBlockWrite (); */ - hwcx->blockWrite = GL_FALSE; - - /* this function will over-write AGPCmdModeEnabled */ - /* TODO: pay attention to side-effect */ - sis_init_user_setting (ctx); - - sis_init_opengl_state (ctx); - sis_set_buffer_static (ctx); - set_color_pattern (hwcx, 0, 0, 0, 0); - set_z_stencil_pattern (hwcx, 1.0, 0); - - /* TODO: need to clear cache? */ - hwcx->clearTexCache = GL_TRUE; - - hwcx->AGPParseSet = 0x00000040; - hwcx->dwPrimitiveSet = 0x00060000; - - for (i = 0; i < SIS_MAX_TEXTURES; i++) - { - hwcx->TexStates[i] = 0; - hwcx->PrevTexFormat[i] = 0; - } - -#if SIS_STEREO - hwcx->isFullScreen = GL_FALSE; - hwcx->stereoEnabled = GL_FALSE; -#endif -} - -void -SiSDestroyContext (XMesaContext xmesa) -{ - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - -#if defined(XFree86Server) && defined(XF86DRI) - DRIDestroyContextPriv ((DRIContextPrivPtr)hwcx->pDRIContextPriv); -#endif - - /* - * TODO: if the context ID given by kernel will be recycled, - * then, the current ID will set to -1 if the current ID - * is equal to my id - */ - free (hwcx); -} - -void -sis_update_render_state (__GLSiScontext * hwcx, GLuint stateType) -{ - __GLSiSHardware *prev = &hwcx->prev; - - mWait3DCmdQueue (45); - - if (hwcx->GlobalFlag & GFLAG_ENABLESETTING) - { - if (!hwcx->clearTexCache) - { - MMIO (REG_3D_TEnable, prev->hwCapEnable); - } - else - { - MMIO (REG_3D_TEnable, prev->hwCapEnable | MASK_TextureCacheClear); - MMIO (REG_3D_TEnable, prev->hwCapEnable); - hwcx->clearTexCache = GL_FALSE; - } - } - - if (hwcx->GlobalFlag & GFLAG_ENABLESETTING2) - { - MMIO (REG_3D_TEnable2, prev->hwCapEnable2); - } - - /* Z Setting */ - if (hwcx->GlobalFlag & GFLAG_ZSETTING) - { - MMIO (REG_3D_ZSet, prev->hwZ); - MMIO (REG_3D_ZStWriteMask, prev->hwZMask); - MMIO (REG_3D_ZAddress, prev->hwOffsetZ); - } - - /* Alpha Setting */ - if (hwcx->GlobalFlag & GFLAG_ALPHASETTING) - { - MMIO (REG_3D_AlphaSet, prev->hwAlpha); - } - - if (hwcx->GlobalFlag & GFLAG_DESTSETTING) - { - MMIO (REG_3D_DstSet, prev->hwDstSet); - MMIO (REG_3D_DstAlphaWriteMask, prev->hwDstMask); - MMIO (REG_3D_DstAddress, prev->hwOffsetDest); - } - - /* Line Setting */ -#if 0 - if (hwcx->GlobalFlag & GFLAG_LINESETTING) - { - MMIO(REG_3D_LinePattern, prev->hwLinePattern); - } -#endif - - /* Fog Setting */ - if (hwcx->GlobalFlag & GFLAG_FOGSETTING) - { - MMIO (REG_3D_FogSet, prev->hwFog); - MMIO (REG_3D_FogInverseDistance, prev->hwFogInverse); - MMIO (REG_3D_FogFarDistance, prev->hwFogFar); - MMIO (REG_3D_FogFactorDensity, prev->hwFogDensity); - } - - /* Stencil Setting */ - if (hwcx->GlobalFlag & GFLAG_STENCILSETTING) - { - MMIO (REG_3D_StencilSet, prev->hwStSetting); - MMIO (REG_3D_StencilSet2, prev->hwStSetting2); - } - - /* Miscellaneous Setting */ - if (hwcx->GlobalFlag & GFLAG_DSTBLEND) - { - MMIO (REG_3D_DstBlendMode, prev->hwDstSrcBlend); - } - if (hwcx->GlobalFlag & GFLAG_CLIPPING) - { - MMIO (REG_3D_ClipTopBottom, prev->clipTopBottom); - MMIO (REG_3D_ClipLeftRight, prev->clipLeftRight); - } - - hwcx->GlobalFlag &= ~GFLAG_RENDER_STATES; -} - -void -sis_update_texture_state (__GLSiScontext * hwcx) -{ - __GLSiSHardware *prev = &hwcx->prev; - - mWait3DCmdQueue (55); - - if (hwcx->clearTexCache) - { - MMIO (REG_3D_TEnable, prev->hwCapEnable | MASK_TextureCacheClear); - MMIO (REG_3D_TEnable, prev->hwCapEnable); - hwcx->clearTexCache = GL_FALSE; - } - - /* Texture Setting */ - if (hwcx->GlobalFlag & CFLAG_TEXTURERESET) - { - MMIO (REG_3D_TextureSet, prev->texture[0].hwTextureSet); - } - if (hwcx->GlobalFlag & GFLAG_TEXTUREMIPMAP) - { - MMIO (REG_3D_TextureMip, prev->texture[0].hwTextureMip); - } - - /* - MMIO(REG_3D_TextureTransparencyColorHigh, prev->texture[0].hwTextureClrHigh); - MMIO(REG_3D_TextureTransparencyColorLow, prev->texture[0].hwTextureClrLow); - */ - - if (hwcx->GlobalFlag & GFLAG_TEXBORDERCOLOR) - { - MMIO (REG_3D_TextureBorderColor, prev->texture[0].hwTextureBorderColor); - } - if (hwcx->GlobalFlag & GFLAG_TEXTUREADDRESS) - { - MMIO (REG_3D_TEnable, prev->hwCapEnable | MASK_TextureCacheClear); - MMIO (REG_3D_TEnable, prev->hwCapEnable); - - switch ((prev->texture[0].hwTextureSet & MASK_TextureLevel) >> 8) - { - case 11: - MMIO (REG_3D_TextureAddress11, prev->texture[0].texOffset11); - case 10: - MMIO (REG_3D_TextureAddress10, prev->texture[0].texOffset10); - MMIO (REG_3D_TexturePitch10, prev->texture[0].texPitch10); - case 9: - MMIO (REG_3D_TextureAddress9, prev->texture[0].texOffset9); - case 8: - MMIO (REG_3D_TextureAddress8, prev->texture[0].texOffset8); - MMIO (REG_3D_TexturePitch8, prev->texture[0].texPitch89); - case 7: - MMIO (REG_3D_TextureAddress7, prev->texture[0].texOffset7); - case 6: - MMIO (REG_3D_TextureAddress6, prev->texture[0].texOffset6); - MMIO (REG_3D_TexturePitch6, prev->texture[0].texPitch67); - case 5: - MMIO (REG_3D_TextureAddress5, prev->texture[0].texOffset5); - case 4: - MMIO (REG_3D_TextureAddress4, prev->texture[0].texOffset4); - MMIO (REG_3D_TexturePitch4, prev->texture[0].texPitch45); - case 3: - MMIO (REG_3D_TextureAddress3, prev->texture[0].texOffset3); - case 2: - MMIO (REG_3D_TextureAddress2, prev->texture[0].texOffset2); - MMIO (REG_3D_TexturePitch2, prev->texture[0].texPitch23); - case 1: - MMIO (REG_3D_TextureAddress1, prev->texture[0].texOffset1); - case 0: - MMIO (REG_3D_TextureAddress0, prev->texture[0].texOffset0); - MMIO (REG_3D_TexturePitch0, prev->texture[0].texPitch01); - } - } - if (hwcx->GlobalFlag & CFLAG_TEXTURERESET_1) - { - MMIO (REG_3D_Texture1Set, prev->texture[1].hwTextureSet); - } - if (hwcx->GlobalFlag & GFLAG_TEXTUREMIPMAP_1) - { - MMIO (REG_3D_Texture1Mip, prev->texture[1].hwTextureMip); - } - - if (hwcx->GlobalFlag & GFLAG_TEXBORDERCOLOR_1) - { - MMIO (REG_3D_Texture1BorderColor, - prev->texture[1].hwTextureBorderColor); - } - if (hwcx->GlobalFlag & GFLAG_TEXTUREADDRESS_1) - { - switch ((prev->texture[1].hwTextureSet & MASK_TextureLevel) >> 8) - { - case 11: - MMIO (REG_3D_Texture1Address11, prev->texture[1].texOffset11); - case 10: - MMIO (REG_3D_Texture1Address10, prev->texture[1].texOffset10); - MMIO (REG_3D_Texture1Pitch10, prev->texture[1].texPitch10); - case 9: - MMIO (REG_3D_Texture1Address9, prev->texture[1].texOffset9); - case 8: - MMIO (REG_3D_Texture1Address8, prev->texture[1].texOffset8); - MMIO (REG_3D_Texture1Pitch8, prev->texture[1].texPitch89); - case 7: - MMIO (REG_3D_Texture1Address7, prev->texture[1].texOffset7); - case 6: - MMIO (REG_3D_Texture1Address6, prev->texture[1].texOffset6); - MMIO (REG_3D_Texture1Pitch6, prev->texture[1].texPitch67); - case 5: - MMIO (REG_3D_Texture1Address5, prev->texture[1].texOffset5); - case 4: - MMIO (REG_3D_Texture1Address4, prev->texture[1].texOffset4); - MMIO (REG_3D_Texture1Pitch4, prev->texture[1].texPitch45); - case 3: - MMIO (REG_3D_Texture1Address3, prev->texture[1].texOffset3); - case 2: - MMIO (REG_3D_Texture1Address2, prev->texture[1].texOffset2); - MMIO (REG_3D_Texture1Pitch2, prev->texture[1].texPitch23); - case 1: - MMIO (REG_3D_Texture1Address1, prev->texture[1].texOffset1); - case 0: - MMIO (REG_3D_Texture1Address0, prev->texture[1].texOffset0); - MMIO (REG_3D_Texture1Pitch0, prev->texture[1].texPitch01); - } - } - - /* texture environment */ - if (hwcx->GlobalFlag & GFLAG_TEXTUREENV) - { - MMIO (REG_3D_TextureBlendFactor, prev->hwTexEnvColor); - MMIO (REG_3D_TextureColorBlendSet0, prev->hwTexBlendClr0); - MMIO (REG_3D_TextureAlphaBlendSet0, prev->hwTexBlendAlpha0); - } - if (hwcx->GlobalFlag & GFLAG_TEXTUREENV_1) - { - MMIO (REG_3D_TextureBlendFactor, prev->hwTexEnvColor); - MMIO (REG_3D_TextureColorBlendSet1, prev->hwTexBlendClr1); - MMIO (REG_3D_TextureAlphaBlendSet1, prev->hwTexBlendAlpha1); - } - - hwcx->GlobalFlag &= ~GFLAG_TEXTURE_STATES; -} - -void -sis_validate_all_state (__GLSiScontext * hwcx) -{ - __GLSiSHardware *prev = &hwcx->prev; - - mEndPrimitive (); - mWait3DCmdQueue (40); - - /* Enable Setting */ - MMIO (REG_3D_TEnable, prev->hwCapEnable); - MMIO (REG_3D_TEnable2, prev->hwCapEnable2); - - /* Z Setting */ - /* if (prev->hwCapEnable & MASK_ZTestEnable) { */ - MMIO (REG_3D_ZSet, prev->hwZ); - MMIO (REG_3D_ZStWriteMask, prev->hwZMask); - MMIO (REG_3D_ZAddress, prev->hwOffsetZ); - /* } */ - - /* Alpha Setting */ - if (prev->hwCapEnable & MASK_AlphaTestEnable) - { - MMIO (REG_3D_AlphaSet, prev->hwAlpha); - } - - /* Destination Setting */ - MMIO (REG_3D_DstSet, prev->hwDstSet); - MMIO (REG_3D_DstAlphaWriteMask, prev->hwDstMask); - MMIO (REG_3D_DstAddress, prev->hwOffsetDest); - - /* Line Setting */ -#if 0 - if (prev->hwCapEnable2 & MASK_LinePatternEnable) { - MMIO(REG_3D_LinePattern, prev->hwLinePattern); - } -#endif - - /* Fog Setting */ - if (prev->hwCapEnable & MASK_FogEnable) - { - MMIO (REG_3D_FogSet, prev->hwFog); - MMIO (REG_3D_FogInverseDistance, prev->hwFogInverse); - MMIO (REG_3D_FogFarDistance, prev->hwFogFar); - MMIO (REG_3D_FogFactorDensity, prev->hwFogDensity); - } - - /* Stencil Setting */ - if (prev->hwCapEnable & MASK_StencilTestEnable) - { - MMIO (REG_3D_StencilSet, prev->hwStSetting); - MMIO (REG_3D_StencilSet2, prev->hwStSetting2); - } - - /* Miscellaneous Setting */ - if (prev->hwCapEnable & MASK_BlendEnable) - { - MMIO (REG_3D_DstBlendMode, prev->hwDstSrcBlend); - } - - MMIO (REG_3D_ClipTopBottom, prev->clipTopBottom); - MMIO (REG_3D_ClipLeftRight, prev->clipLeftRight); - - /* TODO */ - /* Texture Setting */ - /* if (prev->hwCapEnable & MASK_TextureEnable) */ - { - MMIO (REG_3D_TEnable, prev->hwCapEnable | MASK_TextureCacheClear); - - MMIO (REG_3D_TEnable, prev->hwCapEnable); - - MMIO (REG_3D_TextureSet, prev->texture[0].hwTextureSet); - MMIO (REG_3D_TextureMip, prev->texture[0].hwTextureMip); - /* - MMIO(REG_3D_TextureTransparencyColorHigh, prev->texture[0].hwTextureClrHigh); - MMIO(REG_3D_TextureTransparencyColorLow, prev->texture[0].hwTextureClrLow); - */ - MMIO (REG_3D_TextureBorderColor, prev->texture[0].hwTextureBorderColor); - - switch ((prev->texture[0].hwTextureSet & MASK_TextureLevel) >> 8) - { - case 11: - MMIO (REG_3D_TextureAddress11, prev->texture[0].texOffset11); - case 10: - MMIO (REG_3D_TextureAddress10, prev->texture[0].texOffset10); - MMIO (REG_3D_TexturePitch10, prev->texture[0].texPitch10); - case 9: - MMIO (REG_3D_TextureAddress9, prev->texture[0].texOffset9); - case 8: - MMIO (REG_3D_TextureAddress8, prev->texture[0].texOffset8); - MMIO (REG_3D_TexturePitch8, prev->texture[0].texPitch89); - case 7: - MMIO (REG_3D_TextureAddress7, prev->texture[0].texOffset7); - case 6: - MMIO (REG_3D_TextureAddress6, prev->texture[0].texOffset6); - MMIO (REG_3D_TexturePitch6, prev->texture[0].texPitch67); - case 5: - MMIO (REG_3D_TextureAddress5, prev->texture[0].texOffset5); - case 4: - MMIO (REG_3D_TextureAddress4, prev->texture[0].texOffset4); - MMIO (REG_3D_TexturePitch4, prev->texture[0].texPitch45); - case 3: - MMIO (REG_3D_TextureAddress3, prev->texture[0].texOffset3); - case 2: - MMIO (REG_3D_TextureAddress2, prev->texture[0].texOffset2); - MMIO (REG_3D_TexturePitch2, prev->texture[0].texPitch23); - case 1: - MMIO (REG_3D_TextureAddress1, prev->texture[0].texOffset1); - case 0: - MMIO (REG_3D_TextureAddress0, prev->texture[0].texOffset0); - MMIO (REG_3D_TexturePitch0, prev->texture[0].texPitch01); - } - - /* TODO */ - /* if (hwcx->ctx->Texture.Unit[1].ReallyEnabled) */ - { - MMIO (REG_3D_Texture1Set, prev->texture[1].hwTextureSet); - MMIO (REG_3D_Texture1Mip, prev->texture[1].hwTextureMip); - /* - MMIO(REG_3D_Texture1TransparencyColorHigh, prev->texture[1].hwTextureClrHigh); - MMIO(REG_3D_Texture1TransparencyColorLow, prev->texture[1].hwTextureClrLow); - */ - MMIO (REG_3D_Texture1BorderColor, prev->texture[1].hwTextureBorderColor); - - switch ((prev->texture[1].hwTextureSet & MASK_TextureLevel) >> 8) - { - case 11: - MMIO (REG_3D_Texture1Address11, prev->texture[1].texOffset11); - case 10: - MMIO (REG_3D_Texture1Address10, prev->texture[1].texOffset10); - MMIO (REG_3D_Texture1Pitch10, prev->texture[1].texPitch10); - case 9: - MMIO (REG_3D_Texture1Address9, prev->texture[1].texOffset9); - case 8: - MMIO (REG_3D_Texture1Address8, prev->texture[1].texOffset8); - MMIO (REG_3D_Texture1Pitch8, prev->texture[1].texPitch89); - case 7: - MMIO (REG_3D_Texture1Address7, prev->texture[1].texOffset7); - case 6: - MMIO (REG_3D_Texture1Address6, prev->texture[1].texOffset6); - MMIO (REG_3D_Texture1Pitch6, prev->texture[1].texPitch67); - case 5: - MMIO (REG_3D_Texture1Address5, prev->texture[1].texOffset5); - case 4: - MMIO (REG_3D_Texture1Address4, prev->texture[1].texOffset4); - MMIO (REG_3D_Texture1Pitch4, prev->texture[1].texPitch45); - case 3: - MMIO (REG_3D_Texture1Address3, prev->texture[1].texOffset3); - case 2: - MMIO (REG_3D_Texture1Address2, prev->texture[1].texOffset2); - MMIO (REG_3D_Texture1Pitch2, prev->texture[1].texPitch23); - case 1: - MMIO (REG_3D_Texture1Address1, prev->texture[1].texOffset1); - case 0: - MMIO (REG_3D_Texture1Address0, prev->texture[1].texOffset0); - MMIO (REG_3D_Texture1Pitch0, prev->texture[1].texPitch01); - } - } - - /* texture environment */ - MMIO (REG_3D_TextureBlendFactor, prev->hwTexEnvColor); - MMIO (REG_3D_TextureColorBlendSet0, prev->hwTexBlendClr0); - MMIO (REG_3D_TextureColorBlendSet1, prev->hwTexBlendClr1); - MMIO (REG_3D_TextureAlphaBlendSet0, prev->hwTexBlendAlpha0); - MMIO (REG_3D_TextureAlphaBlendSet1, prev->hwTexBlendAlpha1); - } - - hwcx->GlobalFlag = 0; -} - -void -sis_fatal_error (void) -{ - /* free video memory, or the framebuffer device will do it automatically */ - -#ifdef XFree86Server - FatalError ("Fatal errors in libGLcore.a\n"); -#else - fprintf(stderr, "Fatal errors in sis_dri.so\n"); - exit (-1); -#endif -} diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_ctx.h xc/lib/GL/mesa/src/drv/sis/sis_ctx.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_ctx.h Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_ctx.h Wed Dec 31 16:00:00 1969 @@ -1,292 +0,0 @@ -/************************************************************************** - -Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan. -All Rights Reserved. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sub license, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice (including the -next paragraph) shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. -IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -**************************************************************************/ -/* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_ctx.h,v 1.5 2000/09/26 15:56:48 tsi Exp $ */ - -/* - * Authors: - * Sung-Ching Lin - * - */ - -#ifndef _sis_ctx_h_ -#define _sis_ctx_h_ - -#include "sis_common.h" - -/* for GLboolean */ -#include - -#define PCI_CHIP_SIS300 0x0300 -#define PCI_CHIP_SIS630 0x6300 -#define PCI_CHIP_SIS540 0x5300 - -#define SIS_STATE_TRIANGLE 1 -#define SIS_STATE_LINE 2 -#define SIS_STATE_POINT 3 - -/* for swRenderFlag */ -#define SIS_SW_TRIANGLE 0x1 -#define SIS_SW_LINE 0x2 -#define SIS_SW_POINT 0x4 -#define SIS_SW_TEXTURE_DIM 0x8 -#define SIS_SW_TEXTURE_OBJ 0x10 -#define SIS_SW_TEXTURE_OBJ1 0x20 -#define SIS_SW_TEXTURE_ENV 0x100 -#define SIS_SW_TEXTURE_ENV1 0x200 - -#define SIS_SW_TEXTURE (SIS_SW_TEXTURE_DIM | \ - SIS_SW_TEXTURE_OBJ | SIS_SW_TEXTURE_OBJ1 | \ - SIS_SW_TEXTURE_ENV | SIS_SW_TEXTURE_ENV1) -#define SIS_SW_ALL (SIS_SW_POINT | SIS_SW_LINE | SIS_SW_TRIANGLE | \ - SIS_SW_TEXTURE) - -/* - ** Device dependent context state - */ -typedef struct __GLSiSTextureRec -{ - DWORD hwTextureSet; - DWORD hwTextureMip; - DWORD hwTextureClrHigh; - DWORD hwTextureClrLow; - DWORD hwTextureBorderColor; - - DWORD texOffset0; - DWORD texOffset1; - DWORD texOffset2; - DWORD texOffset3; - DWORD texOffset4; - DWORD texOffset5; - DWORD texOffset6; - DWORD texOffset7; - DWORD texOffset8; - DWORD texOffset9; - DWORD texOffset10; - DWORD texOffset11; - - DWORD texPitch01; - DWORD texPitch23; - DWORD texPitch45; - DWORD texPitch67; - DWORD texPitch89; - DWORD texPitch10; -} -__GLSiSTexture; - -typedef struct __GLSiSHardwareRec -{ - DWORD hwCapEnable, hwCapEnable2; /* Enable Setting */ - - DWORD hwOffsetZ, hwZ; /* Z Setting */ - - DWORD hwZBias, hwZMask; /* Z Setting */ - - DWORD hwAlpha; /* Alpha Setting */ - - DWORD hwDstSet, hwDstMask; /* Destination Setting */ - - DWORD hwOffsetDest; /* Destination Setting */ - - DWORD hwLinePattern; /* Line Setting */ - - DWORD hwFog; /* Fog Setting */ - - DWORD hwFogFar, hwFogInverse; /* Fog Distance setting */ - - DWORD hwFogDensity; /* Fog factor & density */ - - DWORD hwStSetting, hwStSetting2; /* Stencil Setting */ - - DWORD hwStOffset; /* Stencil Setting */ - - DWORD hwDstSrcBlend; /* Blending mode Setting */ - - DWORD clipTopBottom; /* Clip for Top & Bottom */ - - DWORD clipLeftRight; /* Clip for Left & Right */ - - struct __GLSiSTextureRec texture[2]; - - DWORD hwTexEnvColor; /* Texture Blending Setting */ - - DWORD hwTexBlendClr0; - DWORD hwTexBlendClr1; - DWORD hwTexBlendAlpha0; - DWORD hwTexBlendAlpha1; - -} -__GLSiSHardware; - -/* Device dependent context state */ - -typedef struct __GLSiScontextRec -{ - /* This must be first in this structure */ - GLcontext *gc; - - unsigned int virtualX, virtualY; - unsigned int bytesPerPixel; - unsigned char *IOBase; - unsigned char *FbBase; - unsigned int displayWidth; - unsigned int pitch; - - /* For Software Renderer */ - GLubyte *swRenderBase; - GLuint swRenderPitch; - GLubyte *swZBase; - GLuint swZPitch; - GLuint pixelValue; - GLboolean swForceRender; - - /* HW RGBA layout */ - unsigned int redMask, greenMask, blueMask, alphaMask; - unsigned int colorFormat; - - /* Z format */ - unsigned int zFormat; - - /* Clear patterns, 4 bytes */ - unsigned int clearColorPattern; - unsigned int clearZStencilPattern; - - /* Render Function */ - points_func PointsFunc; - line_func LineFunc; - triangle_func TriangleFunc; - quad_func QuadFunc; - rect_func RectFunc; - - /* DRM fd */ - int drmSubFD; - - /* AGP Memory */ - unsigned int AGPSize; - unsigned char *AGPBase; - unsigned int AGPAddr; - - /* AGP Command Buffer */ - /* TODO: use Global variables */ - unsigned char *AGPCmdBufBase; - DWORD AGPCmdBufAddr; - unsigned int AGPCmdBufSize; - DWORD *pAGPCmdBufNext; - GLboolean AGPCmdModeEnabled; - GLboolean UseAGPCmdMode; - - /* register 0x89F4 */ - DWORD AGPParseSet; - - /* register 0x89F8 */ - DWORD dwPrimitiveSet; - - __GLSiSHardware prev, current; - - DWORD chipVer; - int Chipset; - - DWORD drawableID; - - /* SGRAM block write */ - GLboolean blockWrite; - - GLuint swRenderFlag; - GLenum Primitive; - - /* Fast Path */ - GLboolean useFastPath; - - DWORD GlobalFlag; - - DWORD rawLockMask; - DWORD lockMask; - - void (*SwapBuffers)(XMesaBuffer b); - - /* Stereo */ - GLboolean isFullScreen; - GLboolean useStereo; - GLboolean stereoEnabled; - int stereo_drawIndex; - int stereo_drawSide; - GLboolean irqEnabled; - - int serialNumber; - -#if defined(XFree86Server) && defined(XF86DRI) - void *pDRIContextPriv; -#endif - - GLboolean clearTexCache; - - GLuint TexStates[SIS_MAX_TEXTURES]; - GLuint PrevTexFormat[SIS_MAX_TEXTURES]; - - int *CurrentHwcxPtr; - int *CurrentQueueLenPtr; - unsigned int *FrameCountPtr; -} -__GLSiScontext; - -/* Macros */ -#define GET_IOBase(x) ((x)->IOBase) -#define GET_FbBase(x) ((x)->FbBase) -#define GET_AGPBase(x) ((x)->AGPBase) -#define GET_DEPTH(x) ((x)->bytesPerPixel) -#define GET_WIDTH(x) ((x)->displayWidth) -#define GET_PITCH(x) ((x)->pitch) -#define GET_FbPos(hwcx,x,y) (GET_FbBase(hwcx)+(x)*GET_DEPTH(hwcx)\ - +(y)*GET_PITCH(hwcx)) - -#define GET_ColorFormat(x) ((x)->colorFormat) - -#define GET_RMASK(x) ((x)->redMask) -#define GET_GMASK(x) ((x)->greenMask) -#define GET_BMASK(x) ((x)->blueMask) -#define GET_AMASK(x) ((x)->alphaMask) - -/* update to hwcx->prev */ -extern void sis_update_drawable_state (GLcontext * ctx); - -/* update to hw */ -extern void sis_update_texture_state (__GLSiScontext * hwcx); -extern void sis_update_render_state (__GLSiScontext * hwcx, GLuint stateType); -extern void sis_validate_all_state (__GLSiScontext * hwcx); - -extern void sis_set_scissor (GLcontext * gc); - -/* AGP */ -void sis_StartAGP (GLcontext * ctx); -void sis_FlushAGP (GLcontext * ctx); -extern float *AGP_CurrentPtr; - -/* DRM FD */ -extern int gDRMSubFD; - -void sis_fatal_error (void); - -#endif diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_dd.c xc/lib/GL/mesa/src/drv/sis/sis_dd.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_dd.c Wed Dec 31 16:00:00 1969 +++ xc/lib/GL/mesa/src/drv/sis/sis_dd.c Wed Aug 20 20:59:24 2003 @@ -0,0 +1,176 @@ +/************************************************************************** + +Copyright 2003 Eric Anholt +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sub license, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. +IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ +/* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_ctx.c,v 1.3 2000/09/26 15:56:48 tsi Exp $ */ + +/* + * Authors: + * Sung-Ching Lin + * Eric Anholt + * + */ + +#include "sis_context.h" +#include "sis_dd.h" +#include "sis_lock.h" +#include "sis_alloc.h" +#include "sis_state.h" + +#include "swrast/swrast.h" + +#include "utils.h" + +#define DRIVER_DATE "20030810" + +/* Return the width and height of the given buffer. + */ +static void sisDDGetBufferSize( GLframebuffer *buffer, + GLuint *width, GLuint *height ) +{ + GET_CURRENT_CONTEXT(ctx); + sisContextPtr smesa = SIS_CONTEXT(ctx); + + LOCK_HARDWARE(); + *width = smesa->driDrawable->w; + *height = smesa->driDrawable->h; + UNLOCK_HARDWARE(); +} + +/* Return various strings for glGetString(). + */ +static const GLubyte *sisDDGetString( GLcontext *ctx, GLenum name ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + static char buffer[128]; + unsigned offset; + GLuint agp_mode = (smesa->AGPSize > 0); + + switch ( name ) { + /*case GL_VENDOR: + return (GLubyte *)"Tungsten Graphics, Inc.";*/ /* XXX */ + + case GL_RENDERER: + offset = driGetRendererString( buffer, "SiS", DRIVER_DATE, agp_mode ); + + return (GLubyte *)buffer; + + default: + return NULL; + } +} + +/* Send all commands to the hardware. No-op, due to mmio. + */ +static void sisDDFlush( GLcontext *ctx ) +{ + /* Do nothing */ +} + +/* Make sure all commands have been sent to the hardware and have + * completed processing. + */ +static void sisDDFinish( GLcontext *ctx ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + + sisDDFlush( ctx ); + WaitEngIdle( smesa ); +} + +void sisUpdateBufferSize( sisContextPtr smesa ) +{ + __GLSiSHardware *current = &smesa->current; + __GLSiSHardware *prev = &smesa->prev; + GLuint z_depth; + + if ( smesa->width == smesa->driDrawable->w && + smesa->height == smesa->driDrawable->h ) + return; + + smesa->width = smesa->driDrawable->w; + smesa->height = smesa->driDrawable->h; + smesa->bottom = smesa->height - 1; + + /* XXX Should get the base offset of the frontbuffer from the X Server */ + smesa->frontOffset = smesa->driDrawable->x * smesa->bytesPerPixel + + smesa->driDrawable->y * smesa->frontPitch; + +#if SIS_STEREO + if ( (smesa->sisScreen->screenX == smesa->width) && + (smesa->sisScreen->screenY == smesa->height) ) + smesa->isFullScreen = GL_TRUE; + else + smesa->isFullScreen = GL_FALSE; +#endif + + if ( smesa->backbuffer ) + sisFreeBackbuffer( smesa ); + if ( smesa->depthbuffer ) + sisFreeZStencilBuffer( smesa ); + + if ( smesa->glCtx->Visual.depthBits > 0 ) + sisAllocZStencilBuffer( smesa ); + if ( smesa->glCtx->Visual.doubleBufferMode ) + sisAllocBackbuffer( smesa ); + + switch (smesa->zFormat) + { + case Z_16: + z_depth = 2; + break; + case Z_32: + case S_8_Z_24: + z_depth = 4; + break; + default: + assert( 0 ); + } + + current->hwZ &= ~MASK_ZBufferPitch; + current->hwZ |= smesa->width * z_depth >> 2; + current->hwOffsetZ = ( (GLint)smesa->depthbuffer - + (GLint)GET_FbBase(smesa) ) >> 2; + + if ((current->hwOffsetZ != prev->hwOffsetZ) || (current->hwZ != prev->hwZ)) { + prev->hwOffsetZ = current->hwOffsetZ; + prev->hwZ = current->hwZ; + smesa->GlobalFlag |= GFLAG_ZSETTING; + } + + sisUpdateClipping( smesa->glCtx ); +} + +/* Initialize the driver's misc functions. + */ +void sisDDInitDriverFuncs( GLcontext *ctx ) +{ + ctx->Driver.GetBufferSize = sisDDGetBufferSize; + ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; /* XXX */ + ctx->Driver.GetString = sisDDGetString; + ctx->Driver.Finish = sisDDFinish; + ctx->Driver.Flush = sisDDFlush; + ctx->Driver.Error = NULL; +} diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_dd.h xc/lib/GL/mesa/src/drv/sis/sis_dd.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_dd.h Wed Dec 31 16:00:00 1969 +++ xc/lib/GL/mesa/src/drv/sis/sis_dd.h Tue Aug 12 12:03:20 2003 @@ -0,0 +1,44 @@ +/* $XFree86$ */ +/************************************************************************** + +Copyright 2003 Eric Anholt +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +on the rights to use, copy, modify, merge, publish, distribute, sub +license, and/or sell copies of the Software, and to permit persons to whom +the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ + +/* + * Authors: + * Eric Anholt + * + */ + +#ifndef __SIS_DD_H__ +#define __SIS_DD_H__ + +#ifdef GLX_DIRECT_RENDERING + +extern void sisUpdateBufferSize( sisContextPtr smesa ); + +extern void sisDDInitDriverFuncs( GLcontext *ctx ); + +#endif +#endif diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_debug.c xc/lib/GL/mesa/src/drv/sis/sis_debug.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_debug.c Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_debug.c Tue Aug 12 12:03:20 2003 @@ -40,7 +40,7 @@ #include #include -#include "sis_ctx.h" +#include "sis_context.h" #include "sis_mesa.h" /* for SiS 300/630/540 */ @@ -53,7 +53,7 @@ char *prevLockFile = NULL; int prevLockLine = 0; -DWORD _empty[0x10000]; +GLint _empty[0x10000]; void dump_agp (void *addr, int dword_count) @@ -81,14 +81,14 @@ d2f_once (GLcontext * ctx) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); static int serialNumber = -1; - if (serialNumber == hwcx->serialNumber) + if (serialNumber == smesa->serialNumber) return; else - serialNumber = hwcx->serialNumber; + serialNumber = smesa->serialNumber; d2f(); } diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_fastpath.c xc/lib/GL/mesa/src/drv/sis/sis_fastpath.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_fastpath.c Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_fastpath.c Wed Dec 31 16:00:00 1969 @@ -1,227 +0,0 @@ -/************************************************************************** - -Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan. -All Rights Reserved. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sub license, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice (including the -next paragraph) shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. -IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -**************************************************************************/ -/* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_fastpath.c,v 1.3 2000/09/26 15:56:48 tsi Exp $ */ - -/* - * Authors: - * Sung-Ching Lin - * - */ - -/* - * FOR - * 1. triangle/strip with 2-texture with no other capability - * (depth-offset, edge-flag...) - * 2. smooth shading - * 3. render to backbuffer - * 4. use AGP command mode - */ - -#ifdef PC_HEADER -#include "all.h" -#else -#include "glheader.h" -#include "clip.h" -#include "context.h" -#include "light.h" -#include "lines.h" -#include "macros.h" -#include "matrix.h" -#include "pb.h" -#include "points.h" -#include "pipeline.h" -#include "stages.h" -#include "types.h" -#include "vb.h" -#include "vbcull.h" -#include "vbrender.h" -#include "vbindirect.h" -#include "xform.h" -#endif - -#include "sis_ctx.h" -#include "sis_mesa.h" - -#define WRITE_SMOOTH_W_T2(v) \ -do{ \ - DWORD dcSARGB; \ - \ - AGP_CurrentPtr[0] = VB->Win.data[v][0] - 0.5; \ - AGP_CurrentPtr[1] = Y_FLIP (VB->Win.data[v][1]) + 0.5; \ - AGP_CurrentPtr[2] = VB->Win.data[v][2] / 65535.0; \ - AGP_CurrentPtr[3] = VB->Win.data[v][3]; \ - RGBA8ConvertToBGRA8 (&dcSARGB, VB->ColorPtr->data[v]); \ - ((DWORD *)AGP_CurrentPtr)[4] = dcSARGB; \ - AGP_CurrentPtr[5] = VB->TexCoordPtr[0]->data[v][0]; \ - AGP_CurrentPtr[6] = VB->TexCoordPtr[0]->data[v][1]; \ - AGP_CurrentPtr[7] = VB->TexCoordPtr[1]->data[v][0]; \ - AGP_CurrentPtr[8] = VB->TexCoordPtr[1]->data[v][1]; \ - AGP_CurrentPtr+=9; \ -}while(0) - - /* TODO or use for loop and let compiler unroll it */ -#define COPY_SMOOTH_W_T2(i) \ -do{ \ - AGP_CurrentPtr[0] = (AGP_CurrentPtr+(i)*9)[0]; \ - AGP_CurrentPtr[1] = (AGP_CurrentPtr+(i)*9)[1]; \ - AGP_CurrentPtr[2] = (AGP_CurrentPtr+(i)*9)[2]; \ - AGP_CurrentPtr[3] = (AGP_CurrentPtr+(i)*9)[3]; \ - AGP_CurrentPtr[4] = (AGP_CurrentPtr+(i)*9)[4]; \ - AGP_CurrentPtr[5] = (AGP_CurrentPtr+(i)*9)[5]; \ - AGP_CurrentPtr[6] = (AGP_CurrentPtr+(i)*9)[6]; \ - AGP_CurrentPtr[7] = (AGP_CurrentPtr+(i)*9)[7]; \ - AGP_CurrentPtr[8] = (AGP_CurrentPtr+(i)*9)[8]; \ - AGP_CurrentPtr+=9; \ -}while(0) - -#if defined(SIS_USE_FASTPATH) -static void sis_render_vb( struct vertex_buffer *VB ) -{ - GLcontext *ctx = VB->ctx; - GLuint i, next, prim; - GLuint parity = VB->Parity; - render_func *tab; - GLuint count = VB->Count; - - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - if(!hwcx->useFastPath){ - gl_render_vb(VB); - return; - } - - if (VB->Indirect) { - return; -#ifndef SIS_USE_HW_CULL - } else if (VB->CullMode & CULL_MASK_ACTIVE) { - tab = ctx->Driver.RenderVBCulledTab; - - /* TODO: check */ - if (!VB->CullDone) - gl_fast_copy_vb( VB ); -#endif - } else if (VB->CullMode & CLIP_MASK_ACTIVE) { - tab = ctx->Driver.RenderVBClippedTab; - } else { - tab = ctx->Driver.RenderVBRawTab; - } - - /* TODO: know what does it do */ - gl_import_client_data( VB, ctx->RenderFlags, - (VB->ClipOrMask - ? VEC_WRITABLE|VEC_GOOD_STRIDE - : VEC_GOOD_STRIDE)); - - ctx->Driver.RenderStart( ctx ); - - if(tab != ctx->Driver.RenderVBRawTab){ - for ( i= VB->CopyStart ; i < count ; parity = 0, i = next ) - { - prim = VB->Primitive[i]; - next = VB->NextPrimitive[i]; - - tab[prim]( VB, i, next, parity ); - } - } - else{ - for ( i= VB->CopyStart ; i < count ; parity = 0, i = next ) - { - prim = VB->Primitive[i]; - next = VB->NextPrimitive[i]; - - if(prim == GL_TRIANGLE_STRIP) - { - int j; - - /* assume size >= 3 */ - /* assert(next-i+1 >= 3); */ - - if(i+2 >=next) - break; - - if(parity){ - WRITE_SMOOTH_W_T2(i+1); - WRITE_SMOOTH_W_T2(i); - WRITE_SMOOTH_W_T2(i+2); - } - else{ - WRITE_SMOOTH_W_T2(i); - WRITE_SMOOTH_W_T2(i+1); - WRITE_SMOOTH_W_T2(i+2); - } - - for(j=i+3; jDriver.RenderFinish( ctx ); -} -#endif - -GLuint sis_RegisterPipelineStages (struct gl_pipeline_stage *out, - const struct gl_pipeline_stage *in, - GLuint nr) -{ - GLuint i, o; - - for (i = o = 0 ; i < nr ; i++) { - switch (in[i].ops) { - case PIPE_OP_RENDER: - out[o] = in[i]; -#if defined(SIS_USE_FASTPATH) - if (in[i].run == gl_render_vb) { - out[o].run = sis_render_vb; - } -#endif - o++; - break; - default: - out[o++] = in[i]; - break; - } - } - - return o; -} diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_fog.c xc/lib/GL/mesa/src/drv/sis/sis_fog.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_fog.c Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_fog.c Tue Aug 12 12:03:20 2003 @@ -32,20 +32,20 @@ * */ -#include "sis_ctx.h" +#include "sis_context.h" #include "sis_mesa.h" +#include "sis_state.h" -static DWORD convertFtToFogFt (DWORD dwInValue); +static GLint convertFtToFogFt (GLint dwInValue); void -sis_Fogfv (GLcontext * ctx, GLenum pname, const GLfloat * params) +sisDDFogfv (GLcontext * ctx, GLenum pname, const GLfloat * params) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - __GLSiSHardware *current = &hwcx->current; + sisContextPtr smesa = SIS_CONTEXT(ctx); + __GLSiSHardware *current = &smesa->current; GLubyte dwFogColor[4]; - DWORD dwArg; + GLint dwArg; float fArg; switch (pname) @@ -66,18 +66,18 @@ } break; case GL_FOG_DENSITY: - dwArg = *(DWORD *) (&(ctx->Fog.Density)); + dwArg = *(GLint *) (&(ctx->Fog.Density)); current->hwFogDensity = 0; current->hwFogDensity |= convertFtToFogFt (dwArg); break; case GL_FOG_START: case GL_FOG_END: fArg = 1.0 / (ctx->Fog.End - ctx->Fog.Start); - current->hwFogInverse = doFPtoFixedNoRound (*(DWORD *) (&fArg), 10); + current->hwFogInverse = doFPtoFixedNoRound (*(GLint *) (&fArg), 10); if (pname == GL_FOG_END) { - dwArg = *(DWORD *) (&(ctx->Fog.End)); - if (hwcx->Chipset == PCI_CHIP_SIS300) + dwArg = *(GLint *) (&(ctx->Fog.End)); + if (smesa->Chipset == PCI_CHIP_SIS300) { current->hwFogFar = doFPtoFixedNoRound (dwArg, 10); } @@ -91,20 +91,20 @@ /* TODO */ break; case GL_FOG_COLOR: - *((DWORD *) dwFogColor) = 0; + *((GLint *) dwFogColor) = 0; dwFogColor[2] = (GLubyte)((ctx->Fog.Color[0]) * 255.0); dwFogColor[1] = (GLubyte)((ctx->Fog.Color[1]) * 255.0); dwFogColor[0] = (GLubyte)((ctx->Fog.Color[2]) * 255.0); current->hwFog &= 0xff000000; - current->hwFog |= *((DWORD *) dwFogColor); + current->hwFog |= *((GLint *) dwFogColor); break; } } -DWORD -doFPtoFixedNoRound (DWORD dwInValue, int nFraction) +GLint +doFPtoFixedNoRound (GLint dwInValue, int nFraction) { - DWORD dwMantissa; + GLint dwMantissa; int nTemp; if (dwInValue == 0) @@ -132,11 +132,11 @@ } /* s[8].23->s[7].10 */ -static DWORD -convertFtToFogFt (DWORD dwInValue) +static GLint +convertFtToFogFt (GLint dwInValue) { - DWORD dwMantissa, dwExp; - DWORD dwRet; + GLint dwMantissa, dwExp; + GLint dwRet; if (dwInValue == 0) return 0; @@ -153,7 +153,7 @@ dwExp = (dwInValue & 0x7F800000) >> 23; dwExp -= 63; - if ((LONG) dwExp < 0) + if (dwExp < 0) return 0; if (dwExp <= 0x7F) diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_init.h xc/lib/GL/mesa/src/drv/sis/sis_init.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_init.h Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_init.h Tue Aug 12 12:03:20 2003 @@ -35,13 +35,7 @@ #ifndef _sis_init_h_ #define _sis_init_h_ -typedef LONG fixed; - -typedef struct _FIXEDCOLOR -{ - fixed r, g, b, a; -} -FIXEDCOLOR; +typedef long fixed; /* XXX should this be a long? */ #define COMMANDMODE_MMIO 1 #define COMMANDMODE_WC 2 @@ -65,7 +59,7 @@ ((GLubyte *)fixedColor)[3] = ((GLubyte *)color)[3] ; \ } -/* Put ARGB into DWORD */ +/* Put ARGB into GLint */ #define setTSARGB(dcSARGB, fixedColor)\ {\ dcSARGB = ((fixedColor.a & 0x00ff0000) << 8 | \ @@ -81,13 +75,13 @@ #define MMIO(reg, value) \ {\ - *(LPDWORD)(GET_IOBase(hwcx) + (reg)) = value; \ + *(GLint *)(GET_IOBase(smesa) + (reg)) = value; \ } #define mEndPrimitive() \ { \ - *(GET_IOBase(hwcx) + REG_3D_EndPrimitiveList) = 0xFF; \ - *(DWORD *)(GET_IOBase(hwcx) + 0x8b60) = (DWORD)(-1); \ + *(GET_IOBase(smesa) + REG_3D_EndPrimitiveList) = 0xFF; \ + *(GLint *)(GET_IOBase(smesa) + 0x8b60) = (GLint)(-1); \ } #define INIT_6327_CapsEnable 0x00000080 @@ -202,13 +196,13 @@ /* Get lock before calling this */ #define mWait3DCmdQueue(wLen)\ do{\ - while ( *(hwcx->CurrentQueueLenPtr) < (int)(wLen))\ + while ( *(smesa->CurrentQueueLenPtr) < (int)(wLen))\ {\ - *(hwcx->CurrentQueueLenPtr) = \ - (int)(*(DWORD *)(GET_IOBase(hwcx) + REG_QUELEN) & MASK_QUELEN) \ + *(smesa->CurrentQueueLenPtr) = \ + (int)(*(GLint *)(GET_IOBase(smesa) + REG_QUELEN) & MASK_QUELEN) \ - (int)20; \ }\ - *(hwcx->CurrentQueueLenPtr) -= (int)(wLen);\ + *(smesa->CurrentQueueLenPtr) -= (int)(wLen);\ }while(0) #if 0 diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_linefunc.h xc/lib/GL/mesa/src/drv/sis/sis_linefunc.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_linefunc.h Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_linefunc.h Tue Aug 12 12:03:20 2003 @@ -35,7 +35,7 @@ #define SIS_TRI_FUNC 0 #define SIS_MMIO_WRITE_VERTEX(v, i) \ - if(SIS_STEREO && hwcx->stereoEnabled) \ + if(SIS_STEREO && smesa->stereoEnabled) \ { \ MMIOBase[(REG_3D_TSXa+(i)*0x30)/4] = VB->Win.data[v][0] - 0.5 + STEREO_OFFSET(v); \ MMIOBase[(REG_3D_TSYa+(i)*0x30)/4] = Y_FLIP (VB->Win.data[v][1]) + 0.5; \ @@ -103,29 +103,29 @@ \ if (SIS_STATES & (SIS_SMOOTH)) \ { \ - DWORD dcSARGB; \ + GLint dcSARGB; \ \ RGBA8ConvertToBGRA8 (&dcSARGB, VB->ColorPtr->data[v]); \ \ - ((DWORD *) MMIOBase)[(REG_3D_TSARGBa+(i)*0x30)/4] = dcSARGB; \ + ((GLint *) MMIOBase)[(REG_3D_TSARGBa+(i)*0x30)/4] = dcSARGB; \ } \ else if(LAST_VERTEX) \ { \ - DWORD dcSARGB; \ + GLint dcSARGB; \ \ RGBA8ConvertToBGRA8 (&dcSARGB, VB->ColorPtr->data[pv]); \ \ - ((DWORD *) MMIOBase)[(REG_3D_TSARGBa+(i)*0x30)/4] = dcSARGB; \ + ((GLint *) MMIOBase)[(REG_3D_TSARGBa+(i)*0x30)/4] = dcSARGB; \ } \ static void SIS_TAG (sis_line) (GLcontext * ctx, GLuint vert0, GLuint vert1, GLuint pv) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); struct vertex_buffer *VB = ctx->VB; - float *MMIOBase = (float *) GET_IOBase (hwcx); + float *MMIOBase = (float *) GET_IOBase (smesa); STEREO_SAMPLE(vert0); @@ -133,19 +133,19 @@ if (SIS_STATES & (SIS_SMOOTH)) { - hwcx->dwPrimitiveSet &= ~0x07001f07; - hwcx->dwPrimitiveSet |= + smesa->dwPrimitiveSet &= ~0x07001f07; + smesa->dwPrimitiveSet |= (OP_3D_FIRE_TSARGBb | SHADE_GOURAUD | OP_3D_LINE_DRAW); - ((DWORD *) MMIOBase)[REG_3D_PrimitiveSet / 4] = hwcx->dwPrimitiveSet; + ((GLint *) MMIOBase)[REG_3D_PrimitiveSet / 4] = smesa->dwPrimitiveSet; } else { - hwcx->dwPrimitiveSet &= ~0x07001f07; - hwcx->dwPrimitiveSet |= + smesa->dwPrimitiveSet &= ~0x07001f07; + smesa->dwPrimitiveSet |= (OP_3D_FIRE_TSARGBb | SHADE_FLAT_VertexB | OP_3D_LINE_DRAW); - ((DWORD *) MMIOBase)[REG_3D_PrimitiveSet / 4] = hwcx->dwPrimitiveSet; + ((GLint *) MMIOBase)[REG_3D_PrimitiveSet / 4] = smesa->dwPrimitiveSet; } #define LAST_VERTEX 0 @@ -157,14 +157,14 @@ /* debug mEndPrimitive (); - WaitEngIdle(hwcx); + WaitEngIdle(smesa); d2f_once (ctx); */ } #define SIS_AGP_WRITE_VERTEX(v) \ do{ \ -if(SIS_STEREO && hwcx->stereoEnabled) \ +if(SIS_STEREO && smesa->stereoEnabled) \ { \ AGP_CurrentPtr[0] = VB->Win.data[v][0] - 0.5 + STEREO_OFFSET(v); \ } \ @@ -201,16 +201,16 @@ if (SIS_STATES & (SIS_SMOOTH)) \ { \ RGBA8ConvertToBGRA8 (&dcSARGB, VB->ColorPtr->data[v]); \ - ((DWORD *)AGP_CurrentPtr)[0] = dcSARGB; \ + ((GLint *)AGP_CurrentPtr)[0] = dcSARGB; \ } \ else if(FIRST_VERTEX) \ { \ RGBA8ConvertToBGRA8 (&dcSARGB, VB->ColorPtr->data[pv]); \ - ((DWORD *)AGP_CurrentPtr)[0] = dcSARGB; \ + ((GLint *)AGP_CurrentPtr)[0] = dcSARGB; \ } \ else \ { \ - ((DWORD *)AGP_CurrentPtr)[0] = dcSARGB; \ + ((GLint *)AGP_CurrentPtr)[0] = dcSARGB; \ } \ AGP_CurrentPtr+=1; \ \ @@ -250,16 +250,16 @@ GLuint pv) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); struct vertex_buffer *VB = ctx->VB; - DWORD dcSARGB; + GLint dcSARGB; STEREO_SAMPLE(vert0); #if 0 - if ((DWORD) AGP_CurrentPtr - (DWORD) AGP_StartPtr >= (AGP_ALLOC_SIZE - 0x10)) + if ((GLint) AGP_CurrentPtr - (GLint) AGP_StartPtr >= (AGP_ALLOC_SIZE - 0x10)) { sis_FlushAGP (ctx); sis_StartAGP (ctx); diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_lock.c xc/lib/GL/mesa/src/drv/sis/sis_lock.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_lock.c Wed Dec 31 16:00:00 1969 +++ xc/lib/GL/mesa/src/drv/sis/sis_lock.c Wed Aug 20 20:59:24 2003 @@ -0,0 +1,77 @@ +/* $XFree86$ */ +/************************************************************************** + +Copyright 2003 Eric Anholt +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +on the rights to use, copy, modify, merge, publish, distribute, sub +license, and/or sell copies of the Software, and to permit persons to whom +the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ + +/* + * Authors: + * Eric Anholt + * + */ + +#include "context.h" +#include "sis_context.h" +#include "sis_lock.h" +#include "sis_mesa.h" +#include "sis_dd.h" + +/* Update the hardware state. This is called if another context has + * grabbed the hardware lock, which includes the X server. This + * function also updates the driver's window state after the X server + * moves, resizes or restacks a window -- the change will be reflected + * in the drawable position and clip rects. Since the X server grabs + * the hardware lock when it changes the window state, this routine will + * automatically be called after such a change. + */ +void +sisGetLock( sisContextPtr smesa, GLuint flags ) +{ + __DRIdrawablePrivate *dPriv = smesa->driDrawable; + __DRIscreenPrivate *sPriv = smesa->driScreen; + SISSAREAPrivPtr sarea = smesa->sarea; + + drmGetLock( smesa->driFd, smesa->hHWContext, flags ); + + /* The window might have moved, so we might need to get new clip + * rects. + * + * NOTE: This releases and regrabs the hw lock to allow the X server + * to respond to the DRI protocol request for new drawable info. + * Since the hardware state depends on having the latest drawable + * clip rects, all state checking must be done _after_ this call. + */ + DRI_VALIDATE_DRAWABLE_INFO( sPriv, dPriv ); + + if ( smesa->lastStamp != dPriv->lastStamp ) { + sisUpdateBufferSize( smesa ); + sisDDDrawBuffer( smesa->glCtx, smesa->glCtx->Color.DrawBuffer ); + smesa->lastStamp = dPriv->lastStamp; + } + + if ( sarea->ctxOwner != smesa->hHWContext ) { + sarea->ctxOwner = smesa->hHWContext; + sis_validate_all_state( smesa ); + } +} diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_lock.h xc/lib/GL/mesa/src/drv/sis/sis_lock.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_lock.h Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_lock.h Wed Aug 20 20:59:24 2003 @@ -32,19 +32,10 @@ * */ -#ifndef _sis_dri_h_ -#define _sis_dri_h_ +#ifndef __SIS_LOCK_H +#define __SIS_LOCK_H -/* from tdfx */ -#define SIS_VALIDATE_DRAWABLE_INFO(dpy, psp, pdp) \ -do { \ - while (*(pdp->pStamp) != pdp->lastStamp) { \ - DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \ - DRI_MESA_VALIDATE_DRAWABLE_INFO(dpy, psp->myNum, pdp); \ - DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \ - sis_SetDrawBuffer (ctx, ctx->Color.DriverDrawBuffer); \ - } \ -} while (0) +extern void sisGetLock( sisContextPtr smesa, GLuint flags ); #ifdef DEBUG_LOCKING extern char *prevLockFile; @@ -71,66 +62,26 @@ #define DEBUG_CHECK_LOCK() #endif -#ifdef XFree86Server - -/* TODO, X-server will inform us if drawable state changed? */ -#define LOCK_HARDWARE() \ - do { \ - mEndPrimitive(); \ - sis_SetDrawBuffer (ctx, ctx->Color.DriverDrawBuffer); \ - if(*(hwcx->CurrentHwcxPtr) != hwcx->serialNumber) \ - sis_validate_all_state(hwcx); \ - } while (0) - -#define UNLOCK_HARDWARE() \ - do { \ - mEndPrimitive(); \ - } while (0) - -#else - -#define DRM_LIGHT_LOCK_RETURN(fd,lock,context,__ret) \ - do { \ - DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \ - if (__ret) drmGetLock(fd,context,0); \ - } while(0) - /* Lock the hardware using the global current context */ -#define LOCK_HARDWARE() \ - do { \ - int stamp; \ - char __ret=0; \ - __DRIdrawablePrivate *dPriv = xmesa->driContextPriv->driDrawablePriv; \ - __DRIscreenPrivate *sPriv = dPriv->driScreenPriv; \ - mEndPrimitive(); \ - DEBUG_CHECK_LOCK(); \ - DEBUG_LOCK(); \ - DRM_LIGHT_LOCK_RETURN(sPriv->fd, &sPriv->pSAREA->lock, \ - dPriv->driContextPriv->hHWContext, __ret); \ - stamp=dPriv->lastStamp; \ - XMESA_VALIDATE_DRAWABLE_INFO(xmesa->display, sPriv, dPriv); \ - if (*(dPriv->pStamp)!=stamp) \ - { \ - sis_SetDrawBuffer (ctx, ctx->Color.DriverDrawBuffer); \ - } \ - if(__ret && (*(hwcx->CurrentHwcxPtr) != hwcx->serialNumber)) \ - { \ - sis_validate_all_state(hwcx); \ - } \ +#define LOCK_HARDWARE() \ + do { \ + char __ret=0; \ + mEndPrimitive(); \ + DEBUG_CHECK_LOCK(); \ + DRM_CAS( smesa->driHwLock, smesa->hHWContext, \ + (DRM_LOCK_HELD | smesa->hHWContext), __ret ); \ + if ( __ret != 0 ) \ + sisGetLock( smesa, 0 ); \ + DEBUG_LOCK(); \ } while (0) /* Unlock the hardware using the global current context */ -#define UNLOCK_HARDWARE() \ - do { \ - __DRIdrawablePrivate *dPriv = xmesa->driContextPriv->driDrawablePriv; \ - __DRIscreenPrivate *sPriv = dPriv->driScreenPriv; \ - mEndPrimitive(); \ - DEBUG_RESET(); \ - *(hwcx->CurrentHwcxPtr) = hwcx->serialNumber; \ - DRM_UNLOCK(sPriv->fd, &sPriv->pSAREA->lock, \ - dPriv->driContextPriv->hHWContext); \ +#define UNLOCK_HARDWARE() \ + do { \ + mEndPrimitive(); \ + DRM_UNLOCK(smesa->driFd, smesa->driHwLock, \ + smesa->hHWContext); \ + DEBUG_RESET(); \ } while (0) - -#endif #endif diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_mesa.c xc/lib/GL/mesa/src/drv/sis/sis_mesa.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_mesa.c Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_mesa.c Fri Aug 22 15:33:20 2003 @@ -32,7 +32,7 @@ * */ -#include "sis_ctx.h" +#include "sis_context.h" #include "sis_mesa.h" #include "sis_lock.h" @@ -42,37 +42,37 @@ sis_RenderStart (GLcontext * ctx) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); LOCK_HARDWARE (); - if (hwcx->Primitive & hwcx->swRenderFlag) + if (smesa->Primitive & smesa->swRenderFlag) { - WaitEngIdle (hwcx); + WaitEngIdle (smesa); } if (ctx->Texture.ReallyEnabled) { sis_validate_texture (ctx); - if (hwcx->swRenderFlag & SIS_SW_TEXTURE) + if (smesa->swRenderFlag & SIS_SW_TEXTURE) { - hwcx->swForceRender = GL_TRUE; + smesa->swForceRender = GL_TRUE; gl_update_state(ctx); - hwcx->swForceRender = GL_FALSE; + smesa->swForceRender = GL_FALSE; } else { - if (hwcx->GlobalFlag & GFLAG_TEXTURE_STATES) - sis_update_texture_state (hwcx); + if (smesa->GlobalFlag & GFLAG_TEXTURE_STATES) + sis_update_texture_state (smesa); } } - if (hwcx->GlobalFlag & GFLAG_RENDER_STATES) + if (smesa->GlobalFlag & GFLAG_RENDER_STATES) { - sis_update_render_state (hwcx, 0); + sis_update_render_state (smesa, 0); } - if (hwcx->UseAGPCmdMode) + if (smesa->UseAGPCmdMode) { sis_StartAGP (ctx); } @@ -86,9 +86,9 @@ sis_RenderFinish (GLcontext * ctx) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); - if (hwcx->UseAGPCmdMode) + if (smesa->UseAGPCmdMode) { sis_FlushAGP (ctx); } @@ -100,10 +100,10 @@ sis_ReducedPrimitiveChange (GLcontext * ctx, GLenum primitive) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); /* it is possible several primitive types per VB */ - if (hwcx->UseAGPCmdMode) + if (smesa->UseAGPCmdMode) { sis_FlushAGP (ctx); sis_StartAGP (ctx); @@ -120,22 +120,22 @@ /* TODO: if above rule changes, remember to modify */ } - hwcx->AGPParseSet &= ~0xf; + smesa->AGPParseSet &= ~0xf; switch (primitive) { case GL_POINT: case GL_POINTS: - hwcx->Primitive = SIS_SW_POINT; - hwcx->AGPParseSet |= 0x0; + smesa->Primitive = SIS_SW_POINT; + smesa->AGPParseSet |= 0x0; break; case GL_LINE: case GL_LINES: - hwcx->Primitive = SIS_SW_LINE; - hwcx->AGPParseSet |= 0x4; + smesa->Primitive = SIS_SW_LINE; + smesa->AGPParseSet |= 0x4; break; case GL_POLYGON: - hwcx->Primitive = SIS_SW_TRIANGLE; - hwcx->AGPParseSet |= 0x8; + smesa->Primitive = SIS_SW_TRIANGLE; + smesa->AGPParseSet |= 0x8; break; } } @@ -144,42 +144,22 @@ sis_init_driver (GLcontext * ctx) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - ctx->Driver.UpdateState = sis_UpdateState; + sisContextPtr smesa = SIS_CONTEXT(ctx); ctx->Driver.RenderStart = sis_RenderStart; ctx->Driver.RenderFinish = sis_RenderFinish; ctx->Driver.ReducedPrimitiveChange = sis_ReducedPrimitiveChange; - ctx->Driver.Finish = sis_Finish; - ctx->Driver.Flush = sis_Flush; - ctx->Driver.AlphaFunc = sis_AlphaFunc; ctx->Driver.BlendEquation = sis_BlendEquation; - ctx->Driver.BlendFunc = sis_BlendFunc; ctx->Driver.BlendFuncSeparate = sis_BlendFuncSeparate; - ctx->Driver.ClearDepth = sis_ClearDepth; - ctx->Driver.CullFace = sis_CullFace; - ctx->Driver.FrontFace = sis_FrontFace; - ctx->Driver.DepthFunc = sis_DepthFunc; - ctx->Driver.DepthMask = sis_DepthMask; ctx->Driver.DepthRange = sis_DepthRange; - ctx->Driver.Enable = sis_Enable; - ctx->Driver.Fogfv = sis_Fogfv; ctx->Driver.Hint = sis_Hint; ctx->Driver.Lightfv = sis_Lightfv; ctx->Driver.LightModelfv = sis_LightModelfv; ctx->Driver.PolygonMode = sis_PolygonMode; ctx->Driver.Scissor = sis_Scissor; - ctx->Driver.ShadeModel = sis_ShadeModel; - ctx->Driver.ClearStencil = sis_ClearStencil; - ctx->Driver.StencilFunc = sis_StencilFunc; - ctx->Driver.StencilMask = sis_StencilMask; - ctx->Driver.StencilOp = sis_StencilOp; ctx->Driver.Viewport = sis_Viewport; - ctx->Driver.Clear = sis_Clear; - ctx->Driver.TexEnv = sis_TexEnv; ctx->Driver.TexImage = sis_TexImage; ctx->Driver.TexSubImage = sis_TexSubImage; @@ -192,12 +172,7 @@ ctx->Driver.PrioritizeTexture = sis_PrioritizeTexture; ctx->Driver.ClearColor = sis_ClearColor; - ctx->Driver.SetDrawBuffer = sis_SetDrawBuffer; - ctx->Driver.SetReadBuffer = sis_SetReadBuffer; - ctx->Driver.GetBufferSize = sis_GetBufferSize; - ctx->Driver.GetString = sis_GetString; ctx->Driver.ColorMask = sis_ColorMask; - ctx->Driver.LogicOp = sis_LogicOp; ctx->Driver.Dither = sis_Dither; ctx->Driver.GetParameteri = sis_GetParameteri; ctx->Driver.DrawPixels = sis_DrawPixels; @@ -216,7 +191,7 @@ ctx->Driver.RegisterPipelineStages = sis_RegisterPipelineStages; /* driver-specific */ - hwcx->SwapBuffers = sis_swap_buffers; + smesa->SwapBuffers = sis_swap_buffers; #ifdef SIS_USE_HW_CULL /* set capability flag */ @@ -224,286 +199,6 @@ #endif } -void -sis_UpdateState (GLcontext * ctx) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - __GLSiSHardware *prev = &hwcx->prev; - __GLSiSHardware *current = &hwcx->current; - - sis_set_render_func (ctx); - - /* ?? duplicate in sis_Enable */ - if (ctx->NewState & NEW_FOG) - { - if (ctx->RasterMask & FOG_BIT) - current->hwCapEnable |= MASK_FogEnable; - else - current->hwCapEnable &= ~MASK_FogEnable; - } - - /* TODO: mesa->NewState. In sis_Enable? */ - if (ctx->RasterMask & STENCIL_BIT) - { - current->hwCapEnable |= - (MASK_StencilTestEnable | MASK_StencilWriteEnable); - } - else - { - current->hwCapEnable &= - ~(MASK_StencilTestEnable | MASK_StencilWriteEnable); - } - - /* NEW_TEXTURE_ENABLE depends on glEnable() instead of ReallyEnabled */ - /* if (ctx->NewState & NEW_TEXTURE_ENABLE) */ - if(1) - { - if (ctx->Texture.ReallyEnabled & - (TEXTURE0_1D | TEXTURE0_2D | TEXTURE1_1D | TEXTURE1_2D)) - { - current->hwCapEnable |= MASK_TextureEnable; - - current->hwCapEnable &= ~MASK_TextureNumUsed; - if (ctx->Texture.ReallyEnabled & TEXTURE1_ANY) - current->hwCapEnable |= 0x00002000; - else - current->hwCapEnable |= 0x00001000; - } - else - { - current->hwCapEnable &= ~MASK_TextureEnable; - } - -#if 1 - /* TODO : if unmark these, error in multitexture */ - if(ctx->NewState & NEW_TEXTURE_ENABLE) - { - int i; - for (i = 0; i < SIS_MAX_TEXTURES; i++) - { - hwcx->TexStates[i] |= (NEW_TEXTURING | NEW_TEXTURE_ENV); - } - } -#endif - } - - /* enable setting 1 */ - if (current->hwCapEnable ^ prev->hwCapEnable) - { - prev->hwCapEnable = current->hwCapEnable; - hwcx->GlobalFlag |= GFLAG_ENABLESETTING; - } - - /* enable setting 2 */ - if (current->hwCapEnable2 ^ prev->hwCapEnable2) - { - prev->hwCapEnable2 = current->hwCapEnable2; - hwcx->GlobalFlag |= GFLAG_ENABLESETTING2; - } - - /* TODO: if fog disable, don't check */ - if (current->hwCapEnable & MASK_FogEnable) - { - /* fog setting */ - if (current->hwFog ^ prev->hwFog) - { - prev->hwFog = current->hwFog; - hwcx->GlobalFlag |= GFLAG_FOGSETTING; - } - if (current->hwFogFar ^ prev->hwFogFar) - { - prev->hwFogFar = current->hwFogFar; - hwcx->GlobalFlag |= GFLAG_FOGSETTING; - } - if (current->hwFogInverse ^ prev->hwFogInverse) - { - prev->hwFogInverse = current->hwFogInverse; - hwcx->GlobalFlag |= GFLAG_FOGSETTING; - } - if (current->hwFogDensity ^ prev->hwFogDensity) - { - prev->hwFogDensity = current->hwFogDensity; - hwcx->GlobalFlag |= GFLAG_FOGSETTING; - } - } - -#ifdef NOT_DONE - sis_set_render_vb_tabs(ctx); -#endif - - /* TODO: assume when isFullScreen/DrawBuffer changed, UpdateState - * will be called - */ -#if SIS_STEREO - if(hwcx->isFullScreen && - (ctx->Color.DriverDrawBuffer == GL_BACK_LEFT) && - hwcx->useStereo) - { - if(!hwcx->stereoEnabled){ - sis_init_stereo(ctx); - } - } - else{ - if(hwcx->stereoEnabled){ - sis_final_stereo(ctx); - } - } -#endif - - /* TODO : 1. where to handle SIS_SW_TEXTURE? - * 2. sw<->hw - * 3. sw-render only if next primitve need to do - */ -} - -void -sis_set_buffer_static (GLcontext * ctx) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - __GLSiSHardware *prev = &hwcx->prev; - __GLSiSHardware *current = &hwcx->current; - - GLvisual *visual = ctx->Visual; - - switch (hwcx->bytesPerPixel) - { - case 2: - /* TODO: don't check - if (hwcx->redMask == 0xf800 && hwcx->greenMask == 0x07e0 && - hwcx->blueMask == 0x001f) - */ - { - current->hwDstSet |= DST_FORMAT_RGB_565; - } - break; - case 4: - /* - if (hwcx->redMask == 0xff0000 && hwcx->greenMask == 0xff00 && - hwcx->blueMask == 0xff) - */ - { - switch (visual->AlphaBits) - { - case 0: - case 1: - case 2: - case 4: - case 8: - /* TODO */ - current->hwDstSet |= DST_FORMAT_ARGB_8888; - break; - } - } - break; - default: - assert (0); - } - - switch (visual->DepthBits) - { - case 0: - current->hwCapEnable &= ~MASK_ZWriteEnable; - case 16: - hwcx->zFormat = Z_16; - current->hwCapEnable |= MASK_ZWriteEnable; - break; - case 32: - hwcx->zFormat = Z_32; - current->hwCapEnable |= MASK_ZWriteEnable; - break; - case 24: - assert (visual->StencilBits); - hwcx->zFormat = S_8_Z_24; - current->hwCapEnable |= MASK_StencilBufferEnable; - current->hwCapEnable |= MASK_ZWriteEnable; - break; - } - - current->hwZ &= ~MASK_ZBufferFormat; - current->hwZ |= hwcx->zFormat; - - /* Destination Color Format */ - if (current->hwDstSet ^ prev->hwDstSet) - { - prev->hwDstSet = current->hwDstSet; - hwcx->GlobalFlag |= GFLAG_DESTSETTING; - } - - /* Z Buffer Data Format */ - if (current->hwZ ^ prev->hwZ) - { - prev->hwZ = current->hwZ; - hwcx->GlobalFlag |= GFLAG_ZSETTING; - } - - sis_sw_set_zfuncs_static (ctx); -} - -void -sis_Finish (GLcontext * ctx) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - sis_Flush (ctx); - - WaitEngIdle (hwcx); -} - -void -sis_Flush (GLcontext * ctx) -{ - /* do nothing now */ -} - -void -sis_AlphaFunc (GLcontext * ctx, GLenum func, GLclampf ref) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - __GLSiSHardware *prev = &hwcx->prev; - __GLSiSHardware *current = &hwcx->current; - - /* TODO: ref is type GLclampf, but mesa has scaled it to 0 - 255.0 */ - current->hwAlpha = ((unsigned char) ref) << 16; - - /* Alpha Test function */ - current->hwAlpha &= ~0x07000000; - switch (func) - { - case GL_NEVER: - current->hwAlpha |= SiS_ALPHA_NEVER; - break; - case GL_LESS: - current->hwAlpha |= SiS_ALPHA_LESS; - break; - case GL_EQUAL: - current->hwAlpha |= SiS_ALPHA_EQUAL; - break; - case GL_LEQUAL: - current->hwAlpha |= SiS_ALPHA_LEQUAL; - break; - case GL_GREATER: - current->hwAlpha |= SiS_ALPHA_GREATER; - break; - case GL_NOTEQUAL: - current->hwAlpha |= SiS_ALPHA_NOTEQUAL; - break; - case GL_GEQUAL: - current->hwAlpha |= SiS_ALPHA_GEQUAL; - break; - case GL_ALWAYS: - current->hwAlpha |= SiS_ALPHA_ALWAYS; - break; - } - - prev->hwAlpha = current->hwAlpha; - hwcx->GlobalFlag |= GFLAG_ALPHASETTING; -} void sis_BlendEquation (GLcontext * ctx, GLenum mode) @@ -513,442 +208,24 @@ } void -sis_BlendFunc (GLcontext * ctx, GLenum sfactor, GLenum dfactor) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - __GLSiSHardware *prev = &hwcx->prev; - __GLSiSHardware *current = &hwcx->current; - - /* TODO: in ICD, if no blend, it will reset these value */ - /* blending enable */ - current->hwDstSrcBlend = 0x10000; /* Default destination alpha */ - - switch (dfactor) - { - case GL_ZERO: - current->hwDstSrcBlend |= SiS_D_ZERO; - break; - case GL_ONE: - current->hwDstSrcBlend |= SiS_D_ONE; - break; - case GL_SRC_COLOR: - current->hwDstSrcBlend |= SiS_D_SRC_COLOR; - break; - case GL_ONE_MINUS_SRC_COLOR: - current->hwDstSrcBlend |= SiS_D_ONE_MINUS_SRC_COLOR; - break; - case GL_SRC_ALPHA: - current->hwDstSrcBlend |= SiS_D_SRC_ALPHA; - break; - case GL_ONE_MINUS_SRC_ALPHA: - current->hwDstSrcBlend |= SiS_D_ONE_MINUS_SRC_ALPHA; - break; - case GL_DST_ALPHA: - current->hwDstSrcBlend |= SiS_D_DST_ALPHA; - break; - case GL_ONE_MINUS_DST_ALPHA: - current->hwDstSrcBlend |= SiS_D_ONE_MINUS_DST_ALPHA; - break; - } - - switch (sfactor) - { - case GL_ZERO: - current->hwDstSrcBlend |= SiS_S_ZERO; - break; - case GL_ONE: - current->hwDstSrcBlend |= SiS_S_ONE; - break; - case GL_SRC_ALPHA: - current->hwDstSrcBlend |= SiS_S_SRC_ALPHA; - break; - case GL_ONE_MINUS_SRC_ALPHA: - current->hwDstSrcBlend |= SiS_S_ONE_MINUS_SRC_ALPHA; - break; - case GL_DST_ALPHA: - current->hwDstSrcBlend |= SiS_S_DST_ALPHA; - break; - case GL_ONE_MINUS_DST_ALPHA: - current->hwDstSrcBlend |= SiS_S_ONE_MINUS_DST_ALPHA; - break; - case GL_DST_COLOR: - current->hwDstSrcBlend |= SiS_S_DST_COLOR; - break; - case GL_ONE_MINUS_DST_COLOR: - current->hwDstSrcBlend |= SiS_S_ONE_MINUS_DST_COLOR; - break; - case GL_SRC_ALPHA_SATURATE: - current->hwDstSrcBlend |= SiS_S_SRC_ALPHA_SATURATE; - break; - } - - if (current->hwDstSrcBlend ^ prev->hwDstSrcBlend) - { - prev->hwDstSrcBlend = current->hwDstSrcBlend; - hwcx->GlobalFlag |= GFLAG_DSTBLEND; - } -} - -void sis_BlendFuncSeparate (GLcontext * ctx, GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorA, GLenum dfactorA) { } void -sis_CullFace (GLcontext * ctx, GLenum mode) -{ -#ifdef SIS_USE_HW_CULL - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - hwcx->AGPParseSet &= ~0x00008000; - hwcx->dwPrimitiveSet &= ~0x08000000; - - /* TODO : GL_FRONT_AND_BACK must be handled elsewhere */ - if((mode == GL_FRONT && ctx->Polygon.FrontFace == GL_CCW) || - (mode == GL_BACK && ctx->Polygon.FrontFace == GL_CW)) - { - hwcx->AGPParseSet |= 0x00008000; - hwcx->dwPrimitiveSet |= 0x08000000; - } -#endif -} - -void -sis_FrontFace (GLcontext * ctx, GLenum mode) -{ -#ifdef SIS_USE_HW_CULL - sis_CullFace (ctx, ctx->Polygon.CullFaceMode); -#endif -} - -void -sis_DepthFunc (GLcontext * ctx, GLenum func) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - __GLSiSHardware *prev = &hwcx->prev; - __GLSiSHardware *current = &hwcx->current; - - GLuint hwZFunc = 0; - - switch (func) - { - case GL_LESS: - hwZFunc = SiS_Z_COMP_S_LT_B; - break; - case GL_GEQUAL: - hwZFunc = SiS_Z_COMP_S_GE_B; - break; - case GL_LEQUAL: - hwZFunc = SiS_Z_COMP_S_LE_B; - break; - case GL_GREATER: - hwZFunc = SiS_Z_COMP_S_GT_B; - break; - case GL_NOTEQUAL: - hwZFunc = SiS_Z_COMP_S_NE_B; - break; - case GL_EQUAL: - hwZFunc = SiS_Z_COMP_S_EQ_B; - break; - case GL_ALWAYS: - hwZFunc = SiS_Z_COMP_ALWAYS; - break; - case GL_NEVER: - hwZFunc = SiS_Z_COMP_NEVER; - break; - } - current->hwZ &= ~MASK_ZTestMode; - current->hwZ |= hwZFunc; - - if (current->hwZ ^ prev->hwZ) - { - prev->hwZ = current->hwZ; - - hwcx->GlobalFlag |= GFLAG_ZSETTING; - } -} - -void -sis_DepthMask (GLcontext * ctx, GLboolean flag) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - __GLSiSHardware *prev = &hwcx->prev; - __GLSiSHardware *current = &hwcx->current; - - if (ctx->Visual->StencilBits) - { - if (flag || ctx->Stencil.WriteMask) - { - current->hwCapEnable |= MASK_ZWriteEnable; - if (flag && ctx->Stencil.WriteMask == 0xff) - { - current->hwCapEnable2 &= ~MASK_ZMaskWriteEnable; - } - else - { - current->hwCapEnable2 |= MASK_ZMaskWriteEnable; - current->hwZMask = ((DWORD) ctx->Stencil.WriteMask << 24) | - ((flag) ? 0x00ffffff : 0); - - if (current->hwZMask ^ prev->hwZMask) - { - prev->hwZMask = current->hwZMask; - hwcx->GlobalFlag |= GFLAG_ZSETTING; - } - } - } - else - { - current->hwCapEnable &= ~MASK_ZWriteEnable; - } - } - else - { - if (flag) - { - current->hwCapEnable |= MASK_ZWriteEnable; - current->hwCapEnable2 &= ~MASK_ZMaskWriteEnable; - } - else - { - current->hwCapEnable &= ~MASK_ZWriteEnable; - } - } -} - -void sis_DepthRange (GLcontext * ctx, GLclampd nearval, GLclampd farval) { /* mesa handles it? */ } void -sis_Enable (GLcontext * ctx, GLenum cap, GLboolean state) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - __GLSiSHardware *current = &hwcx->current; - - switch (cap) - { - case GL_ALPHA_TEST: - if (state) - { - current->hwCapEnable |= MASK_AlphaTestEnable; - } - else - { - current->hwCapEnable &= ~MASK_AlphaTestEnable; - } - break; -/* - case GL_AUTO_NORMAL: - break; -*/ - case GL_BLEND: - /* TODO: */ - if(state) - /* if (state & !ctx->Color.ColorLogicOpEnabled) */ - { - current->hwCapEnable |= MASK_BlendEnable; - } - else - { - current->hwCapEnable &= ~MASK_BlendEnable; - } - break; -/* - case GL_CLIP_PLANE0: - case GL_CLIP_PLANE1: - case GL_CLIP_PLANE2: - case GL_CLIP_PLANE3: - case GL_CLIP_PLANE4: - case GL_CLIP_PLANE5: - break; - case GL_COLOR_MATERIAL: - break; -*/ - case GL_CULL_FACE: -#ifdef SIS_USE_HW_CULL - if (state) - { - current->hwCapEnable |= MASK_CullEnable; - } - else - { - current->hwCapEnable &= ~MASK_CullEnable; - } -#endif - break; - case GL_DEPTH_TEST: - if (state && xmesa->xm_buffer->depthbuffer) - { - current->hwCapEnable |= MASK_ZTestEnable; - } - else - { - current->hwCapEnable &= ~MASK_ZTestEnable; - } - break; - case GL_DITHER: - if (state) - { - current->hwCapEnable |= MASK_DitherEnable; - } - else - { - current->hwCapEnable &= ~MASK_DitherEnable; - } - break; -/* - case GL_FOG: - break; - case GL_LIGHT0: - case GL_LIGHT1: - case GL_LIGHT2: - case GL_LIGHT3: - case GL_LIGHT4: - case GL_LIGHT5: - case GL_LIGHT6: - case GL_LIGHT7: - break; - case GL_LIGHTING: - break; - case GL_LINE_SMOOTH: - break; - case GL_LINE_STIPPLE: - break; - case GL_INDEX_LOGIC_OP: - break; -*/ - case GL_COLOR_LOGIC_OP: - if (state) - { - sis_LogicOp (ctx, ctx->Color.LogicOp); - } - else - { - sis_LogicOp (ctx, GL_COPY); - } - break; -/* - case GL_MAP1_COLOR_4: - break; - case GL_MAP1_INDEX: - break; - case GL_MAP1_NORMAL: - break; - case GL_MAP1_TEXTURE_COORD_1: - break; - case GL_MAP1_TEXTURE_COORD_2: - break; - case GL_MAP1_TEXTURE_COORD_3: - break; - case GL_MAP1_TEXTURE_COORD_4: - break; - case GL_MAP1_VERTEX_3: - break; - case GL_MAP1_VERTEX_4: - break; - case GL_MAP2_COLOR_4: - break; - case GL_MAP2_INDEX: - break; - case GL_MAP2_NORMAL: - break; - case GL_MAP2_TEXTURE_COORD_1: - break; - case GL_MAP2_TEXTURE_COORD_2: - break; - case GL_MAP2_TEXTURE_COORD_3: - break; - case GL_MAP2_TEXTURE_COORD_4: - break; - case GL_MAP2_VERTEX_3: - break; - case GL_MAP2_VERTEX_4: - break; - case GL_NORMALIZE: - break; - case GL_POINT_SMOOTH: - break; - case GL_POLYGON_SMOOTH: - break; - case GL_POLYGON_STIPPLE: - break; - case GL_POLYGON_OFFSET_POINT: - break; - case GL_POLYGON_OFFSET_LINE: - break; - case GL_POLYGON_OFFSET_FILL: - case GL_POLYGON_OFFSET_EXT: - break; - case GL_RESCALE_NORMAL_EXT: - break; -*/ - case GL_SCISSOR_TEST: - sis_set_scissor (ctx); - break; -/* - case GL_SHARED_TEXTURE_PALETTE_EXT: - break; -*/ - case GL_STENCIL_TEST: - if (state) - { - current->hwCapEnable |= (MASK_StencilTestEnable | - MASK_StencilWriteEnable); - } - else - { - current->hwCapEnable &= ~(MASK_StencilTestEnable | - MASK_StencilWriteEnable); - } - break; -/* - case GL_TEXTURE_1D: - case GL_TEXTURE_2D: - case GL_TEXTURE_3D: - break; - case GL_TEXTURE_GEN_Q: - break; - case GL_TEXTURE_GEN_R: - break; - case GL_TEXTURE_GEN_S: - break; - case GL_TEXTURE_GEN_T: - break; - - case GL_VERTEX_ARRAY: - break; - case GL_NORMAL_ARRAY: - break; - case GL_COLOR_ARRAY: - break; - case GL_INDEX_ARRAY: - break; - case GL_TEXTURE_COORD_ARRAY: - break; - case GL_EDGE_FLAG_ARRAY: - break; -*/ - } -} - -void sis_Hint (GLcontext * ctx, GLenum target, GLenum mode) { #if 0 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - __GLSiSHardware *current = &hwcx->current; + sisContextPtr smesa = SIS_CONTEXT(ctx); + __GLSiSHardware *current = &smesa->current; #endif switch (target) @@ -1001,130 +278,26 @@ } void -sis_Scissor (GLcontext * ctx, GLint x, GLint y, GLsizei w, GLsizei h) -{ - if (ctx->Scissor.Enabled) - sis_set_scissor (ctx); -} - -void -sis_ShadeModel (GLcontext * ctx, GLenum mode) -{ -} - -void sis_Viewport (GLcontext * ctx, GLint x, GLint y, GLsizei w, GLsizei h) { } -void -sis_ClearColor (GLcontext * ctx, GLubyte red, GLubyte green, - GLubyte blue, GLubyte alpha) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - set_color_pattern (hwcx, red, green, blue, alpha); - -} - /* TODO */ void sis_ClearIndex (GLcontext * ctx, GLuint index) { } -void sis_set_render_pos(GLcontext * ctx, GLubyte *base, GLuint pitch) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - __GLSiSHardware *prev = &hwcx->prev; - __GLSiSHardware *current = &hwcx->current; - - assert (base != NULL); - - if (SIS_VERBOSE&VERBOSE_SIS_BUFFER){ - fprintf(stderr, "set drawing position: base=%lx, pitch=%lu\n", - (long)base, (long)pitch); - } - - /* software render */ - hwcx->swRenderBase = base; - hwcx->swRenderPitch = pitch; - - current->hwOffsetDest = ((DWORD) base - (DWORD) GET_FbBase (hwcx)) >> 1; - current->hwDstSet &= ~MASK_DstBufferPitch; - current->hwDstSet |= pitch >> 2; - - /* destination setting */ - if (current->hwDstSet ^ prev->hwDstSet) - { - prev->hwDstSet = current->hwDstSet; - hwcx->GlobalFlag |= GFLAG_DESTSETTING; - } - - if (current->hwOffsetDest ^ prev->hwOffsetDest) - { - prev->hwOffsetDest = current->hwOffsetDest; - hwcx->GlobalFlag |= GFLAG_DESTSETTING; - } -} - -GLboolean -sis_SetDrawBuffer (GLcontext * ctx, GLenum mode) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - XMesaBuffer xm_buffer = xmesa->xm_buffer; - GLubyte *base; - GLuint pitch; - GLboolean retval = GL_FALSE; - - /* if new context bind, the function will be call? */ - switch (mode) - { - case GL_BACK_LEFT: - base = (GLubyte *) xm_buffer->backimage->data; - pitch = xm_buffer->backimage->bytes_per_line; - - retval = GL_TRUE; - break; - case GL_FRONT_LEFT: - base = sis_get_drawable_pos (xmesa); - pitch = GET_PITCH (hwcx); - retval = GL_TRUE; - break; - case GL_BACK_RIGHT: - case GL_FRONT_RIGHT: - default: - assert (0); - return GL_FALSE; - } - - sis_set_render_pos(ctx, base, pitch); - - return retval; -} - -void -sis_SetReadBuffer (GLcontext *ctx, GLframebuffer *colorBuffer, - GLenum buffer) -{ - /* TODO */ -} - GLboolean sis_ColorMask (GLcontext * ctx, GLboolean rmask, GLboolean gmask, GLboolean bmask, GLboolean amask) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); - __GLSiSHardware *prev = &hwcx->prev; - __GLSiSHardware *current = &hwcx->current; + __GLSiSHardware *prev = &smesa->prev; + __GLSiSHardware *current = &smesa->current; if (rmask & gmask & bmask & @@ -1138,16 +311,16 @@ current->hwCapEnable2 |= (MASK_AlphaMaskWriteEnable | MASK_ColorMaskWriteEnable); - current->hwDstMask = (rmask) ? GET_RMASK (hwcx) : 0 | - (gmask) ? GET_GMASK (hwcx) : 0 | - (bmask) ? GET_BMASK (hwcx) : 0 | - (amask) ? GET_AMASK (hwcx) : 0; + current->hwDstMask = (rmask) ? GET_RMASK (smesa) : 0 | + (gmask) ? GET_GMASK (smesa) : 0 | + (bmask) ? GET_BMASK (smesa) : 0 | + (amask) ? GET_AMASK (smesa) : 0; } if (current->hwDstMask ^ prev->hwDstMask) { prev->hwDstMask = current->hwDstMask; - hwcx->GlobalFlag |= GFLAG_DESTSETTING; + smesa->GlobalFlag |= GFLAG_DESTSETTING; } return GL_TRUE; @@ -1157,10 +330,10 @@ sis_LogicOp (GLcontext * ctx, GLenum op) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); - __GLSiSHardware *prev = &hwcx->prev; - __GLSiSHardware *current = &hwcx->current; + __GLSiSHardware *prev = &smesa->prev; + __GLSiSHardware *current = &smesa->current; if (ctx->Color.ColorLogicOpEnabled) { @@ -1220,7 +393,7 @@ if (current->hwDstSet ^ prev->hwDstSet) { prev->hwDstSet = current->hwDstSet; - hwcx->GlobalFlag |= GFLAG_DESTSETTING; + smesa->GlobalFlag |= GFLAG_DESTSETTING; } } return GL_TRUE; @@ -1230,9 +403,9 @@ sis_Dither (GLcontext * ctx, GLboolean enable) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); - __GLSiSHardware *current = &hwcx->current; + __GLSiSHardware *current = &smesa->current; if (enable) { @@ -1273,9 +446,9 @@ const GLvoid * pixels) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); - WaitEngIdle (hwcx); + WaitEngIdle (smesa); return 0; } @@ -1285,11 +458,11 @@ const GLubyte * bitmap) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); ctx->Driver.RenderStart( ctx ); - WaitEngIdle (hwcx); + WaitEngIdle (smesa); /* TODO: use tdfx's Bitmap */ ctx->Driver.RenderFinish( ctx ); @@ -1297,282 +470,9 @@ return 0; } -void -set_color_pattern (__GLSiScontext * hwcx, GLubyte red, GLubyte green, - GLubyte blue, GLubyte alpha) -{ - /* XXX only RGB565 and ARGB8888 */ - switch (GET_ColorFormat (hwcx)) - { - case DST_FORMAT_ARGB_8888: - hwcx->clearColorPattern = (alpha << 24) + - (red << 16) + (green << 8) + (blue); - break; - case DST_FORMAT_RGB_565: - hwcx->clearColorPattern = ((red >> 3) << 11) + - ((green >> 2) << 5) + (blue >> 3); - hwcx->clearColorPattern |= hwcx->clearColorPattern << 16; - break; - default: - assert (0); - } -} - -void -set_z_stencil_pattern (__GLSiScontext * hwcx, GLclampd z, int stencil) -{ - GLuint zPattern, stencilPattern; - GLboolean dword_pattern; - - if (z <= (float) 0.0) - zPattern = 0x0; - else if (z >= (float) 1.0) - zPattern = 0xFFFFFFFF; - else - zPattern = doFPtoFixedNoRound (*(DWORD *) & z, 32); - - stencilPattern = 0; - - switch (hwcx->zFormat) - { - case Z_16: - zPattern = zPattern >> 16; - zPattern &= 0x0000FFFF; - dword_pattern = GL_FALSE; - break; - case S_8_Z_24: - zPattern = zPattern >> 8; - zPattern &= 0x00FFFFFF; - stencilPattern = (stencilPattern << 24); - dword_pattern = GL_TRUE; - break; - case Z_32: - dword_pattern = GL_TRUE; - break; - default: - assert (0); - } - hwcx->clearZStencilPattern = zPattern | stencilPattern; - /* ?? */ - if (!dword_pattern) - hwcx->clearZStencilPattern |= (zPattern | stencilPattern) << 16; -} - -void -sis_update_drawable_state (GLcontext * ctx) -{ - const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - __GLSiSHardware *current = &hwcx->current; - __GLSiSHardware *prev = &hwcx->prev; - - XMesaBuffer xm_buffer = xmesa->xm_buffer; - GLuint z_depth; - - sis_SetDrawBuffer (ctx, ctx->Color.DriverDrawBuffer); - /* TODO: call sis_SetReadBuffer? */ - - switch (hwcx->zFormat) - { - case Z_16: - z_depth = 2; - break; - case Z_32: - case S_8_Z_24: - z_depth = 4; - break; - default: - assert (0); - } - - current->hwZ &= ~MASK_ZBufferPitch; - current->hwZ |= xm_buffer->width * z_depth >> 2; - /* TODO, in xfree 3.9.18, no ctx->Buffer */ - current->hwOffsetZ = ((DWORD) (xm_buffer->depthbuffer) - - (DWORD) GET_FbBase (hwcx)) >> 2; - - if ((current->hwOffsetZ ^ prev->hwOffsetZ) - || (current->hwZ ^ prev->hwZ)) - { - prev->hwOffsetZ = current->hwOffsetZ; - prev->hwZ = current->hwZ; - - /* Z setting */ - hwcx->GlobalFlag |= GFLAG_ZSETTING; - } -} - -void -sis_GetBufferSize (GLframebuffer *buffer, GLuint * width, GLuint * height) -{ - GET_CURRENT_CONTEXT(ctx); - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - __GLSiSHardware *current = &hwcx->current; - __GLSiSHardware *prev = &hwcx->prev; - - GLuint winwidth, winheight; - XMesaBuffer xm_buffer = xmesa->xm_buffer; - -#ifndef XFree86Server - SIS_VALIDATE_DRAWABLE_INFO (xmesa->display, - xmesa->driContextPriv->driScreenPriv, - xmesa->driContextPriv->driDrawablePriv); -#endif - sis_get_drawable_size (xmesa, &winwidth, &winheight); - - *width = winwidth; - *height = winheight; - - if (winwidth != xm_buffer->width || winheight != xm_buffer->height) - { - GLuint z_depth; - - if (SIS_VERBOSE&VERBOSE_SIS_BUFFER) - { - fprintf(stderr, "GetBufferSize: before=(%d,%d), after=(%d,%d)\n", - xm_buffer->width, xm_buffer->height, winwidth, winheight); - } - - xm_buffer->width = winwidth; - xm_buffer->height = winheight; - - /* update hwcx->isFullScreen */ - /* TODO: Does X-server have exclusive-mode? */ - /* TODO: physical screen width/height will be changed dynamicly */ - -#if SIS_STEREO - if((hwcx->virtualX == winwidth) && (hwcx->virtualY == winheight)) - hwcx->isFullScreen = GL_TRUE; - else - hwcx->isFullScreen = GL_FALSE; -#endif - - if (xm_buffer->db_state) - { - sisBufferInfo *priv = (sisBufferInfo *) xm_buffer->private; - - sis_alloc_back_image (ctx, xm_buffer->backimage, &priv->bbFree, - &priv->cbClearPacket); - } - - if (ctx->Visual->DepthBits) - sis_alloc_z_stencil_buffer (ctx); - - switch (hwcx->zFormat) - { - case Z_16: - z_depth = 2; - break; - case Z_32: - case S_8_Z_24: - z_depth = 4; - break; - default: - assert (0); - } - - sis_SetDrawBuffer (ctx, ctx->Color.DriverDrawBuffer); - /* TODO: call sis_SetReadBuffer? */ - - current->hwZ &= ~MASK_ZBufferPitch; - current->hwZ |= xm_buffer->width * z_depth >> 2; - /* TODO, in xfree 3.9.18, no ctx->Buffer */ - current->hwOffsetZ = ((DWORD) (xm_buffer->depthbuffer) - - (DWORD) GET_FbBase (hwcx)) >> 2; - - if ((current->hwOffsetZ ^ prev->hwOffsetZ) - || (current->hwZ ^ prev->hwZ)) - { - prev->hwOffsetZ = current->hwOffsetZ; - prev->hwZ = current->hwZ; - - /* Z setting */ - hwcx->GlobalFlag |= GFLAG_ZSETTING; - } - } - - /* Needed by Y_FLIP macro */ - xm_buffer->bottom = (int) winheight - 1; - - sis_set_scissor (ctx); -} - -const GLubyte * -sis_GetString (GLcontext * ctx, GLenum name) -{ - (void) ctx; - - switch (name) - { - case GL_RENDERER: -#ifdef XFree86Server - return (GLubyte *)"SIS 300/630/530 IR Mode"; -#else - return (GLubyte *)"SiS 300/630/530 DR Mode"; -#endif - default: - return NULL; - } -} const char * sis_ExtensionString (GLcontext * ctx) { return NULL; -} - -void -sis_set_scissor (GLcontext * ctx) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - __GLSiSHardware *prev = &hwcx->prev; - __GLSiSHardware *current = &hwcx->current; - - GLint x1, y1, x2, y2; - - /* ?? from context.c, do it 2 times */ - - x1 = 0; - y1 = 0; - x2 = xmesa->xm_buffer->width - 1; - y2 = xmesa->xm_buffer->height - 1; - - if (ctx->Scissor.Enabled) - { - if (ctx->Scissor.X > x1) - { - x1 = ctx->Scissor.X; - } - if (ctx->Scissor.Y > y1) - { - y1 = ctx->Scissor.Y; - } - if (ctx->Scissor.X + ctx->Scissor.Width - 1 < x2) - { - x2 = ctx->Scissor.X + ctx->Scissor.Width - 1; - } - if (ctx->Scissor.Y + ctx->Scissor.Height - 1 < y2) - { - y2 = ctx->Scissor.Y + ctx->Scissor.Height - 1; - } - } - - y1 = Y_FLIP (y1); - y2 = Y_FLIP (y2); - - current->clipTopBottom = (y2 << 13) | y1; - current->clipLeftRight = (x1 << 13) | x2; - - if ((current->clipTopBottom ^ prev->clipTopBottom) || - (current->clipLeftRight ^ prev->clipLeftRight)) - { - prev->clipTopBottom = current->clipTopBottom; - prev->clipLeftRight = current->clipLeftRight; - hwcx->GlobalFlag |= GFLAG_CLIPPING; - } } diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_mesa.h xc/lib/GL/mesa/src/drv/sis/sis_mesa.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_mesa.h Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_mesa.h Fri Aug 22 15:33:20 2003 @@ -35,25 +35,18 @@ #ifndef _sis_mesa_h_ #define _sis_mesa_h_ -void sis_UpdateState (GLcontext * ctx); +#include "tnl/t_context.h" + void sis_ClearIndex (GLcontext * ctx, GLuint index); void sis_ClearColor (GLcontext * ctx, GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); -GLbitfield sis_Clear (GLcontext * ctx, GLbitfield mask, GLboolean all, - GLint x, GLint y, GLint width, GLint height); -GLboolean sis_SetDrawBuffer (GLcontext * ctx, GLenum mode); -void sis_SetReadBuffer (GLcontext *ctx, GLframebuffer *colorBuffer, - GLenum buffer); void sis_GetBufferSize (GLframebuffer * buffer, GLuint * width, GLuint * height); const char *sis_ExtensionString (GLcontext * ctx); const GLubyte *sis_GetString (GLcontext * ctx, GLenum name); -void sis_Finish (GLcontext * ctx); -void sis_Flush (GLcontext * ctx); GLboolean sis_IndexMask (GLcontext * ctx, GLuint mask); GLboolean sis_ColorMask (GLcontext * ctx, GLboolean rmask, GLboolean gmask, GLboolean bmask, GLboolean amask); -GLboolean sis_LogicOp (GLcontext * ctx, GLenum op); void sis_Dither (GLcontext * ctx, GLboolean enable); void sis_Error (GLcontext * ctx); void sis_NearFar (GLcontext * ctx, GLfloat nearVal, GLfloat farVal); @@ -136,45 +129,19 @@ /* * State-Change */ -void sis_AlphaFunc (GLcontext * ctx, GLenum func, GLclampf ref); void sis_BlendEquation (GLcontext * ctx, GLenum mode); -void sis_BlendFunc (GLcontext * ctx, GLenum sfactor, GLenum dfactor); void sis_BlendFuncSeparate (GLcontext * ctx, GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorA, GLenum dfactorA); -void sis_ClearDepth (GLcontext * ctx, GLclampd d); -void sis_CullFace (GLcontext * ctx, GLenum mode); -void sis_FrontFace (GLcontext * ctx, GLenum mode); -void sis_DepthFunc (GLcontext * ctx, GLenum func); -void sis_DepthMask (GLcontext * ctx, GLboolean flag); void sis_DepthRange (GLcontext * ctx, GLclampd nearval, GLclampd farval); -void sis_Enable (GLcontext * ctx, GLenum cap, GLboolean state); -void sis_Fogfv (GLcontext * ctx, GLenum pname, const GLfloat * params); void sis_Hint (GLcontext * ctx, GLenum target, GLenum mode); void sis_Lightfv (GLcontext * ctx, GLenum light, GLenum pname, const GLfloat * params, GLint nparams); void sis_LightModelfv (GLcontext * ctx, GLenum pname, const GLfloat * params); void sis_PolygonMode (GLcontext * ctx, GLenum face, GLenum mode); -void sis_Scissor (GLcontext * ctx, GLint x, GLint y, GLsizei w, GLsizei h); -void sis_ShadeModel (GLcontext * ctx, GLenum mode); -void sis_ClearStencil (GLcontext * ctx, GLint s); -void sis_StencilFunc (GLcontext * ctx, GLenum func, GLint ref, GLuint mask); -void sis_StencilMask (GLcontext * ctx, GLuint mask); -void sis_StencilOp (GLcontext * ctx, GLenum fail, GLenum zfail, GLenum zpass); void sis_Viewport (GLcontext * ctx, GLint x, GLint y, GLsizei w, GLsizei h); /* - * Buffer Allocation - */ -void sis_alloc_z_stencil_buffer (GLcontext * ctx); -void sis_free_z_stencil_buffer (XMesaBuffer buf); -void sis_alloc_back_image (GLcontext * ctx, XMesaImage *image, void **free, - ENGPACKET *packet); -void sis_free_back_image (XMesaBuffer buf, XMesaImage *image, void *free); -void sis_alloc_texture_image (GLcontext * ctx, GLtextureImage * image); -void sis_free_texture_image (GLtextureImage * image); - -/* * Raster-Function Picker */ void sis_set_render_func (GLcontext * ctx); @@ -188,19 +155,10 @@ /* * Local */ -void set_color_pattern (__GLSiScontext * hwcx, GLubyte red, GLubyte green, - GLubyte blue, GLubyte alpha); - -void set_z_stencil_pattern (__GLSiScontext * hwcx, GLclampd z, int stencil); - void sis_init_driver (GLcontext * ctx); void sis_sw_init_driver (GLcontext * ctx); void sis_sw_set_zfuncs_static (GLcontext * ctx); -void WaitEngIdle (__GLSiScontext * hwcx); -void Wait2DEngIdle (__GLSiScontext * hwcx); - -void sis_set_buffer_static (GLcontext * ctx); void sis_set_render_pos(GLcontext * ctx, GLubyte *base, GLuint pitch); /* diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_reg.h xc/lib/GL/mesa/src/drv/sis/sis_reg.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_reg.h Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_reg.h Fri Aug 22 15:33:20 2003 @@ -709,19 +709,19 @@ #define OP_3D_FIRE_TFIRE 0x00000000 #define OP_3D_FIRE_TSARGBa 0x00000100 -#define OP_3D_FIRE_TSWa 0x00000200 +#define OP_3D_FIRE_TSWa 0x00000200 #define OP_3D_FIRE_TSVAa 0x00000300 #define OP_3D_FIRE_TSVBa 0x00000400 #define OP_3D_FIRE_TSVCa 0x00000500 #define OP_3D_FIRE_TSARGBb 0x00000900 -#define OP_3D_FIRE_TSWb 0x00000a00 +#define OP_3D_FIRE_TSWb 0x00000a00 #define OP_3D_FIRE_TSVAb 0x00000b00 #define OP_3D_FIRE_TSVBb 0x00000c00 #define OP_3D_FIRE_TSVCb 0x00000d00 #define OP_3D_FIRE_TSARGBc 0x00001100 -#define OP_3D_FIRE_TSWc 0x00001200 +#define OP_3D_FIRE_TSWc 0x00001200 #define OP_3D_FIRE_TSVAc 0x00001300 #define OP_3D_FIRE_TSVBc 0x00001400 #define OP_3D_FIRE_TSVCc 0x00001500 @@ -735,6 +735,8 @@ #define OP_3D_TextureBumpFromA 0x00000000 #define OP_3D_TextureBumpFromB 0x00010000 #define OP_3D_TextureBumpFromC 0x00020000 + +#define OP_3D_CullDirection_CCW 0x08000000 #define SHADE_FLAT_VertexA 0x01000000 #define SHADE_FLAT_VertexB 0x02000000 diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_render.c xc/lib/GL/mesa/src/drv/sis/sis_render.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_render.c Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_render.c Tue Aug 12 12:03:20 2003 @@ -32,7 +32,7 @@ * */ -#include "sis_ctx.h" +#include "sis_context.h" #include "sis_mesa.h" #define SIS_SMOOTH 0x1 @@ -46,14 +46,13 @@ #define SIS_DEPTH_SCALE 1.0 /* - * TODO: assert(hwcx->AGPCmdBufSize % AGP_ALLOC_SIZE == 0) + * TODO: assert(smesa->AGPCmdBufSize % AGP_ALLOC_SIZE == 0) * depends on VB_SIZE is better */ #define AGP_ALLOC_SIZE 0x10000 /* #define AGP_ALLOC_SIZE (VB_SIZE/3*4 * 9) */ -static DWORD AGP_EngineOffset; -static DWORD *AGP_StartPtr; -/* export to sis_fastpath.c */ +static GLint AGP_EngineOffset; +static GLint *AGP_StartPtr; float *AGP_CurrentPtr; #define SIS_TAG(x) x##_flat @@ -179,7 +178,7 @@ sis_line_clip (GLcontext * ctx, GLuint vert0, GLuint vert1, GLuint pv) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); BoxPtr pExtents; int count; @@ -190,7 +189,7 @@ while (count--) { - DWORD clipTopBottom, clipLeftRight; + GLint clipTopBottom, clipLeftRight; clipTopBottom = ((pExtents->y1 - y) << 13) | (pExtents->y2 - y - 1); clipLeftRight = ((pExtents->x1 - x) << 13) | (pExtents->x2 - x - 1); @@ -200,12 +199,12 @@ MMIO (REG_3D_ClipTopBottom, clipTopBottom); MMIO (REG_3D_ClipLeftRight, clipLeftRight); - (hwcx->LineFunc) (ctx, vert0, vert1, pv); + (smesa->LineFunc) (ctx, vert0, vert1, pv); mEndPrimitive (); pExtents++; } - hwcx->GlobalFlag |= GFLAG_CLIPPING; + smesa->GlobalFlag |= GFLAG_CLIPPING; } static triangle_func sis_fill_triangle_func[32] = { @@ -254,7 +253,7 @@ #define USE_FLAT 0x0001000 #define USE_SMOOTH 0x0004000 -static DWORD AGPParsingValues[32] = { +static GLint AGPParsingValues[32] = { (4 << 28) | USE_XYZ | USE_RGB | USE_FLAT, (4 << 28) | USE_XYZ | USE_RGB | USE_SMOOTH, (5 << 28) | USE_XYZ | USE_W | USE_RGB | USE_FLAT, @@ -277,7 +276,7 @@ sis_tri_clip (GLcontext * ctx, GLuint v0, GLuint v1, GLuint v2, GLuint pv) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); BoxPtr pExtents; int count; @@ -288,7 +287,7 @@ while (count--) { - DWORD clipTopBottom, clipLeftRight; + GLint clipTopBottom, clipLeftRight; clipTopBottom = ((pExtents->y1 - y) << 13) | (pExtents->y2 - y - 1); clipLeftRight = ((pExtents->x1 - x) << 13) | (pExtents->x2 - x - 1); @@ -298,32 +297,32 @@ MMIO (REG_3D_ClipTopBottom, clipTopBottom); MMIO (REG_3D_ClipLeftRight, clipLeftRight); - (hwcx->TriangleFunc) (ctx, v0, v1, v2, pv); + (smesa->TriangleFunc) (ctx, v0, v1, v2, pv); mEndPrimitive (); pExtents++; } - hwcx->GlobalFlag |= GFLAG_CLIPPING; + smesa->GlobalFlag |= GFLAG_CLIPPING; } void sis_set_render_func (GLcontext * ctx) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); GLuint caps = ctx->TriangleCaps; int line_index = 0; int tri_index = 0; - if(hwcx->swForceRender){ + if(smesa->swForceRender){ ctx->Driver.LineFunc = NULL; ctx->Driver.TriangleFunc = NULL; return; } ctx->IndirectTriangles &= ~(DD_LINE_SW_RASTERIZE | DD_TRI_SW_RASTERIZE); - hwcx->swRenderFlag &= ~(SIS_SW_POINT | SIS_SW_LINE | SIS_SW_TRIANGLE); + smesa->swRenderFlag &= ~(SIS_SW_POINT | SIS_SW_LINE | SIS_SW_TRIANGLE); /* * TODO: Mesa 3.3 will set ctx->TriangleCaps to DD_SELECT @@ -339,18 +338,18 @@ #endif /* always set */ - hwcx->swRenderFlag |= SIS_SW_POINT; + smesa->swRenderFlag |= SIS_SW_POINT; if ((caps & DD_LINE_STIPPLE) || (caps & DD_LINE_WIDTH)) { line_index |= SIS_FALLBACK; - hwcx->swRenderFlag |= SIS_SW_LINE; + smesa->swRenderFlag |= SIS_SW_LINE; } if ((caps & DD_TRI_STIPPLE)) { tri_index |= SIS_FALLBACK; - hwcx->swRenderFlag |= SIS_SW_TRIANGLE; + smesa->swRenderFlag |= SIS_SW_TRIANGLE; } if (ctx->Light.ShadeModel == GL_SMOOTH) @@ -383,27 +382,27 @@ } /* TODO, use Pick */ - hwcx->UseAGPCmdMode = GL_FALSE; + smesa->UseAGPCmdMode = GL_FALSE; if (line_index & SIS_FALLBACK) { ctx->IndirectTriangles |= DD_LINE_SW_RASTERIZE; - hwcx->LineFunc = NULL; + smesa->LineFunc = NULL; } else { if ((ctx->Color.DriverDrawBuffer == GL_FRONT_LEFT) && sis_is_window (xmesa)) { - hwcx->LineFunc = sis_draw_line_func[line_index]; + smesa->LineFunc = sis_draw_line_func[line_index]; ctx->Driver.LineFunc = sis_line_clip; } else { - if (hwcx->AGPCmdModeEnabled) + if (smesa->AGPCmdModeEnabled) { ctx->Driver.LineFunc = sis_agp_draw_line_func[line_index]; - hwcx->UseAGPCmdMode = GL_TRUE; + smesa->UseAGPCmdMode = GL_TRUE; } else { @@ -415,22 +414,22 @@ if (tri_index & SIS_FALLBACK) { ctx->IndirectTriangles |= DD_TRI_SW_RASTERIZE; - hwcx->TriangleFunc = NULL; + smesa->TriangleFunc = NULL; } else { if ((ctx->Color.DriverDrawBuffer == GL_FRONT_LEFT) && sis_is_window (xmesa)) { - hwcx->TriangleFunc = sis_fill_triangle_func[tri_index]; + smesa->TriangleFunc = sis_fill_triangle_func[tri_index]; ctx->Driver.TriangleFunc = sis_tri_clip; } else { - if (hwcx->AGPCmdModeEnabled) + if (smesa->AGPCmdModeEnabled) { ctx->Driver.TriangleFunc = sis_agp_fill_triangle_func[tri_index]; - hwcx->UseAGPCmdMode = GL_TRUE; + smesa->UseAGPCmdMode = GL_TRUE; } else { @@ -438,25 +437,15 @@ } } } - - /* fast path */ - if(!(ctx->TriangleCaps & (DD_TRI_UNFILLED | DD_TRI_LIGHT_TWOSIDE)) && - (ctx->Driver.TriangleFunc == sis_agp_tri_smooth_w_t2) && - (ctx->Color.DriverDrawBuffer == GL_BACK_LEFT)){ - hwcx->useFastPath = GL_TRUE; - } - else{ - hwcx->useFastPath = GL_FALSE; - } /* TODO: AGP and MMIO use different sis_set_render_state */ - hwcx->AGPParseSet &= ~0xffff7000; - hwcx->AGPParseSet |= AGPParsingValues[line_index & ~SIS_FALLBACK]; + smesa->AGPParseSet &= ~0xffff7000; + smesa->AGPParseSet |= AGPParsingValues[line_index & ~SIS_FALLBACK]; /* Debug, test sw-render ctx->Driver.LineFunc = NULL; ctx->Driver.TriangleFunc = NULL; - hwcx->swRenderFlag = ~0x0; + smesa->swRenderFlag = ~0x0; ctx->Visual->DepthMax = (sizeof(GLdepth)==2)?0xffff:0xffffffff; ctx->Visual->DepthMaxF = (double)(sizeof(GLdepth)==2)?0xffff:0xffffffff; */ @@ -466,13 +455,13 @@ sis_StartAGP (GLcontext * ctx) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); - DWORD start, end; + GLint start, end; - start = *(hwcx->pAGPCmdBufNext); + start = *(smesa->pAGPCmdBufNext); end = start + AGP_ALLOC_SIZE; - if (end >= hwcx->AGPCmdBufSize) + if (end >= smesa->AGPCmdBufSize) { start = 0; end = AGP_ALLOC_SIZE; @@ -486,13 +475,13 @@ do { AGP_EngineOffset = - *(DWORD volatile *) (GET_IOBase (hwcx) + REG_3D_AGPCmBase) - - (DWORD) hwcx->AGPCmdBufAddr; + *(GLint volatile *) (GET_IOBase (smesa) + REG_3D_AGPCmBase) - + (GLint) smesa->AGPCmdBufAddr; } while ((AGP_EngineOffset <= end) && (AGP_EngineOffset >= start) - && ((*(GET_IOBase (hwcx) + 0x8243) & 0xe0) != 0xe0)); + && ((*(GET_IOBase (smesa) + 0x8243) & 0xe0) != 0xe0)); - AGP_StartPtr = (DWORD *) (start + hwcx->AGPCmdBufBase); + AGP_StartPtr = (GLint *) (start + smesa->AGPCmdBufBase); AGP_CurrentPtr = (float *) AGP_StartPtr; } @@ -500,27 +489,27 @@ sis_FlushAGP (GLcontext * ctx) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); /* TODO: wait queue length */ - if((DWORD *)AGP_CurrentPtr == AGP_StartPtr) + if((GLint *)AGP_CurrentPtr == AGP_StartPtr) { return; } mWait3DCmdQueue (5); mEndPrimitive (); - MMIO (REG_3D_AGPCmBase, ((DWORD) AGP_StartPtr - (DWORD) hwcx->AGPCmdBufBase) - + (DWORD) hwcx->AGPCmdBufAddr); + MMIO (REG_3D_AGPCmBase, ((GLint) AGP_StartPtr - (GLint) smesa->AGPCmdBufBase) + + (GLint) smesa->AGPCmdBufAddr); MMIO (REG_3D_AGPTtDwNum, - (((DWORD) AGP_CurrentPtr - (DWORD) AGP_StartPtr) >> 2) | 0x50000000); - MMIO (REG_3D_ParsingSet, hwcx->AGPParseSet); + (((GLint) AGP_CurrentPtr - (GLint) AGP_StartPtr) >> 2) | 0x50000000); + MMIO (REG_3D_ParsingSet, smesa->AGPParseSet); - MMIO (REG_3D_AGPCmFire, (DWORD) (-1)); + MMIO (REG_3D_AGPCmFire, (GLint) (-1)); mEndPrimitive (); - *(hwcx->pAGPCmdBufNext) = - (DWORD) AGP_CurrentPtr - (DWORD) hwcx->AGPCmdBufBase; - *(hwcx->pAGPCmdBufNext) = (*(hwcx->pAGPCmdBufNext) + 0xf) & ~0xf; + *(smesa->pAGPCmdBufNext) = + (GLint) AGP_CurrentPtr - (GLint) smesa->AGPCmdBufBase; + *(smesa->pAGPCmdBufNext) = (*(smesa->pAGPCmdBufNext) + 0xf) & ~0xf; } diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_screen.c xc/lib/GL/mesa/src/drv/sis/sis_screen.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_screen.c Wed Dec 31 16:00:00 1969 +++ xc/lib/GL/mesa/src/drv/sis/sis_screen.c Fri Aug 22 15:33:20 2003 @@ -0,0 +1,286 @@ +/* $XFree86$ */ +/************************************************************************** + +Copyright 2003 Eric Anholt +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +on the rights to use, copy, modify, merge, publish, distribute, sub +license, and/or sell copies of the Software, and to permit persons to whom +the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ + +/* + * Authors: + * Eric Anholt + * + */ + +#include "dri_util.h" + +#include "context.h" +#include "utils.h" +#include "imports.h" + +#include "sis_context.h" +#include "sis_dri.h" +#include "sis_lock.h" + +/* Create the device specific screen private data struct. + */ +static sisScreenPtr +sisCreateScreen( __DRIscreenPrivate *sPriv ) +{ + sisScreenPtr sisScreen; + SISDRIPtr sisDRIPriv = (SISDRIPtr)sPriv->pDevPriv; + + if ( ! driCheckDriDdxDrmVersions( sPriv, "SiS", 4, 0, 0, 7, 1, 0 ) ) + return NULL; + + /* Allocate the private area */ + sisScreen = (sisScreenPtr) CALLOC( sizeof(*sisScreen) ); + if ( sisScreen == NULL ) + return NULL; + + sisScreen->screenX = sisDRIPriv->width; + sisScreen->screenY = sisDRIPriv->height; + sisScreen->cpp = sisDRIPriv->bytesPerPixel; + sisScreen->irqEnabled = sisDRIPriv->bytesPerPixel; + sisScreen->deviceID = sisDRIPriv->deviceID; + sisScreen->AGPCmdBufOffset = sisDRIPriv->AGPCmdBufOffset; + sisScreen->AGPCmdBufSize = sisDRIPriv->AGPCmdBufSize; + sisScreen->sarea_priv_offset = sisDRIPriv->sarea_priv_offset; + + sisScreen->mmio.handle = sisDRIPriv->regs.handle; + sisScreen->mmio.size = sisDRIPriv->regs.size; + if ( drmMap( sPriv->fd, sisScreen->mmio.handle, sisScreen->mmio.size, + &sisScreen->mmio.map ) ) { + FREE( sisScreen ); + return NULL; + } + + if (sisDRIPriv->agp.size) { + sisScreen->agp.handle = sisDRIPriv->agp.handle; + sisScreen->agp.size = sisDRIPriv->agp.size; + if ( drmMap( sPriv->fd, sisScreen->agp.handle, sisScreen->agp.size, + &sisScreen->agp.map ) ) { + sisScreen->agp.size = 0; + } + } + + sisScreen->driScreen = sPriv; + + return sisScreen; +} + +/* Destroy the device specific screen private data struct. + */ +static void +sisDestroyScreen( __DRIscreenPrivate *sPriv ) +{ + sisScreenPtr sisScreen = (sisScreenPtr)sPriv->private; + + if ( sisScreen == NULL ) + return; + + if (sisScreen->agp.size != 0) + drmUnmap( sisScreen->agp.map, sisScreen->agp.size ); + drmUnmap( sisScreen->mmio.map, sisScreen->mmio.size ); + + FREE( sisScreen ); + sPriv->private = NULL; +} + +/* Create and initialize the Mesa and driver specific pixmap buffer + * data. + */ +static GLboolean +sisCreateBuffer( __DRIscreenPrivate *driScrnPriv, + __DRIdrawablePrivate *driDrawPriv, + const __GLcontextModes *mesaVis, + GLboolean isPixmap ) +{ + if (isPixmap) { + return GL_FALSE; /* not implemented */ + } + else { + driDrawPriv->driverPrivate = (void *) + _mesa_create_framebuffer( mesaVis, + GL_FALSE, /* software depth buffer? */ + mesaVis->stencilBits > 0, + mesaVis->accumRedBits > 0, + mesaVis->alphaBits > 0 ); /* XXX */ + return (driDrawPriv->driverPrivate != NULL); + } +} + + +static void +sisDestroyBuffer(__DRIdrawablePrivate *driDrawPriv) +{ + _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate)); +} + +__inline__ static void +sis_bitblt_copy_cmd (sisContextPtr smesa, ENGPACKET * pkt) +{ + GLint *lpdwDest, *lpdwSrc; + int i; + + lpdwSrc = (GLint *) pkt; + lpdwDest = (GLint *) (GET_IOBase (smesa) + REG_SRC_ADDR); + + mWait3DCmdQueue (10); + + for (i = 0; i < 7; i++) + *lpdwDest++ = *lpdwSrc++; + + MMIO(REG_CMD0, *(GLint *)&pkt->stdwCmd); + MMIO(0x8240, -1); +} + +static void sisCopyBuffer( __DRIdrawablePrivate *dPriv ) +{ + sisContextPtr smesa = (sisContextPtr)dPriv->driContextPriv->driverPrivate; + int i; + ENGPACKET stEngPacket; + +#if 0 + { + int repeat = 0; + + while(((*smesa->FrameCountPtr) - *(GLint volatile *)(smesa->IOBase+0x8a2c) + > SIS_MAX_FRAME_LENGTH) && + (repeat++ < 10)); + } +#endif + + LOCK_HARDWARE (); + + stEngPacket.dwSrcBaseAddr = smesa->backOffset; + stEngPacket.dwSrcPitch = smesa->backPitch | + ((smesa->bytesPerPixel == 2) ? 0x80000000 : 0xc0000000); + stEngPacket.dwDestBaseAddr = smesa->frontOffset; + stEngPacket.wDestPitch = smesa->frontPitch; + /* TODO: set maximum value? */ + stEngPacket.wDestHeight = smesa->virtualY; + + stEngPacket.stdwCmd.cRop = 0xcc; + + if (smesa->blockWrite) { + stEngPacket.stdwCmd.cCmd0 = (BYTE) (CMD0_PAT_FG_COLOR); + stEngPacket.stdwCmd.cCmd1 = (BYTE) (CMD1_DIR_X_INC | CMD1_DIR_Y_INC); + } else { + stEngPacket.stdwCmd.cCmd0 = 0; + stEngPacket.stdwCmd.cCmd1 = (BYTE) (CMD1_DIR_X_INC | CMD1_DIR_Y_INC); + } + + for (i = 0; i < dPriv->numClipRects; i++) { + XF86DRIClipRectPtr box = &dPriv->pClipRects[i]; + stEngPacket.stdwSrcPos.wY = box->y1 - dPriv->y; + stEngPacket.stdwSrcPos.wX = box->x1 - dPriv->x; + stEngPacket.stdwDestPos.wY = box->y1; + stEngPacket.stdwDestPos.wX = box->x1; + + stEngPacket.stdwDim.wWidth = (GLshort) box->x2 - box->x1; + stEngPacket.stdwDim.wHeight = (GLshort) box->y2 - box->y1; + sis_bitblt_copy_cmd(smesa, &stEngPacket); + } + + *(GLint *)(smesa->IOBase+0x8a2c) = *smesa->FrameCountPtr; + (*smesa->FrameCountPtr)++; + + UNLOCK_HARDWARE (); +} + + +/* Copy the back color buffer to the front color buffer */ +static void +sisSwapBuffers(__DRIdrawablePrivate *dPriv) +{ + if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) { + sisContextPtr smesa = (sisContextPtr) dPriv->driContextPriv->driverPrivate; + GLcontext *ctx = smesa->glCtx; + + if (ctx->Visual.doubleBufferMode) { + _mesa_notifySwapBuffers( ctx ); /* flush pending rendering comands */ + sisCopyBuffer( dPriv ); + } + } + else { + /* XXX this shouldn't be an error but we can't handle it for now */ + _mesa_problem(NULL, "%s: drawable has no context!", __FUNCTION__); + } +} + + +/* Initialize the driver specific screen private data. + */ +static GLboolean +sisInitDriver( __DRIscreenPrivate *sPriv ) +{ + sPriv->private = (void *) sisCreateScreen( sPriv ); + + if ( !sPriv->private ) { + sisDestroyScreen( sPriv ); + return GL_FALSE; + } + + return GL_TRUE; +} + +/* Fullscreen mode change stub + */ +static GLboolean +sisOpenCloseFullScreen( __DRIcontextPrivate *driContextPriv ) +{ + return GL_TRUE; +} + +static struct __DriverAPIRec sisAPI = { + .InitDriver = sisInitDriver, + .DestroyScreen = sisDestroyScreen, + .CreateContext = sisCreateContext, + .DestroyContext = sisDestroyContext, + .CreateBuffer = sisCreateBuffer, + .DestroyBuffer = sisDestroyBuffer, + .SwapBuffers = sisSwapBuffers, + .MakeCurrent = sisMakeCurrent, + .UnbindContext = sisUnbindContext, + .OpenFullScreen = sisOpenCloseFullScreen, + .CloseFullScreen = sisOpenCloseFullScreen, + .GetSwapInfo = NULL, + /*.GetMSC = driGetMSC32, + .WaitForMSC = driWaitForMSC32, + .WaitForSBC = NULL,*/ /* XXX */ + .SwapBuffersMSC = NULL + +}; + +/* + * This is the bootstrap function for the driver. + * The __driCreateScreen name is the symbol that libGL.so fetches. + * Return: pointer to a __DRIscreenPrivate. + */ +void *__driCreateScreen(Display *dpy, int scrn, __DRIscreen *psc, + int numConfigs, __GLXvisualConfig *config) +{ + __DRIscreenPrivate *psp; + psp = __driUtilCreateScreen(dpy, scrn, psc, numConfigs, config, &sisAPI); + return (void *) psp; +} diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_screen.h xc/lib/GL/mesa/src/drv/sis/sis_screen.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_screen.h Wed Dec 31 16:00:00 1969 +++ xc/lib/GL/mesa/src/drv/sis/sis_screen.h Wed Aug 20 01:48:03 2003 @@ -0,0 +1,61 @@ +/* $XFree86$ */ +/************************************************************************** + +Copyright 2003 Eric Anholt +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +on the rights to use, copy, modify, merge, publish, distribute, sub +license, and/or sell copies of the Software, and to permit persons to whom +the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ + +/* + * Authors: + * Eric Anholt + * + */ + +#ifndef __SIS_SCREEN_H +#define __SIS_SCREEN_H + +typedef struct { + drmHandle handle; /* Handle to the DRM region */ + drmSize size; /* Size of the DRM region */ + drmAddress map; /* Mapping of the DRM region */ +} sisRegionRec2, *sisRegionPtr2; + +typedef struct { + sisRegionRec2 mmio; + sisRegionRec2 agp; + + unsigned int AGPCmdBufOffset; + unsigned int AGPCmdBufSize; + + int deviceID; + int irqEnabled; + + int cpp; + unsigned int screenX, screenY; + + __DRIscreenPrivate *driScreen; + unsigned int sarea_priv_offset; + +} sisScreenRec, *sisScreenPtr; + +#endif diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_span.c xc/lib/GL/mesa/src/drv/sis/sis_span.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_span.c Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_span.c Wed Aug 20 20:59:24 2003 @@ -32,8 +32,11 @@ * */ -#include "sis_ctx.h" +#include "sis_context.h" #include "sis_mesa.h" +#include "sis_span.h" + +#include "swrast/swrast.h" #define DBG 0 @@ -42,11 +45,12 @@ * call this function without locking, or modify sis_Bitmap */ -#define LOCAL_VARS \ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; \ - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; \ - GLuint pitch = hwcx->swRenderPitch; \ - char *buf = (char *)hwcx->swRenderBase +#define LOCAL_VARS \ + sisContextPtr smesa = SIS_CONTEXT(ctx); \ + char *buf = (char *)(smesa->FbBase + smesa->drawOffset); \ + char *read_buf = (char *)(smesa->FbBase + smesa->readOffset); \ + GLuint p; \ + (void) read_buf; (void) buf; (void) p #define CLIPPIXEL(_x,_y) (_x >= minx && _x < maxx && \ _y >= miny && _y < maxy) @@ -61,43 +65,41 @@ if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx); \ } -#define HW_LOCK() do{}while(0); +#define HW_LOCK() do{} while(0); -#define HW_CLIPLOOP() \ - do { \ - BoxPtr _pExtents; \ - int _nc; \ - GLuint _x, _y; \ - sis_get_drawable_origin (xmesa, &_x, &_y); \ - sis_get_clip_rects (xmesa, &_pExtents, &_nc); \ - while (_nc--) { \ - int minx = _pExtents->x1 - _x; \ - int miny = _pExtents->y1 - _y; \ - int maxx = _pExtents->x2 - _x; \ - int maxy = _pExtents->y2 - _y; \ - _pExtents++; - -#define HW_ENDCLIPLOOP() \ - } \ - } while (0) +#define HW_CLIPLOOP() \ + do { \ + __DRIdrawablePrivate *dPriv = smesa->driDrawable; \ + int _nc = dPriv->numClipRects; \ + \ + while ( _nc-- ) { \ + int minx = dPriv->pClipRects[_nc].x1 - dPriv->x; \ + int miny = dPriv->pClipRects[_nc].y1 - dPriv->y; \ + int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x; \ + int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y; + +#define HW_ENDCLIPLOOP() \ + } \ + } while (0) #define HW_UNLOCK() do{}while(0); /* RGB565 */ -#define INIT_MONO_PIXEL(p) \ - GLushort p = hwcx->pixelValue; +#define INIT_MONO_PIXEL(p, color) \ + p = SISPACKCOLOR565( color[0], color[1], color[2] ) #define WRITE_RGBA( _x, _y, r, g, b, a ) \ - *(GLushort *)(buf + _x*2 + _y*pitch) = ( ((r & 0xf8) << 8) | \ - ((g & 0xfc) << 3) | \ - (b >> 3)) + *(GLushort *)(buf + _x*2 + _y*smesa->drawPitch) = \ + (((r & 0xf8) << 8) | \ + ((g & 0xfc) << 3) | \ + (b >> 3)) #define WRITE_PIXEL( _x, _y, p ) \ - *(GLushort *)(buf + _x*2 + _y*pitch) = p + *(GLushort *)(buf + _x*2 + _y*smesa->drawPitch) = p #define READ_RGBA( rgba, _x, _y ) \ do { \ - GLushort p = *(GLushort *)(buf + _x*2 + _y*pitch); \ + GLushort p = *(GLushort *)(read_buf + _x*2 + _y*smesa->readPitch); \ rgba[0] = (p & 0xf800) >> 8; \ rgba[1] = (p & 0x07e0) >> 3; \ rgba[2] = (p & 0x001f) << 3; \ @@ -106,35 +108,26 @@ #define TAG(x) sis_##x##_565 #include "spantmp.h" -static void sis_Color_565( GLcontext *ctx, - GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - hwcx->pixelValue = ((red & 0xf8) << 8) | - ((green & 0xfc) << 3) | - (blue >> 3); -} /* ARGB8888 */ #undef INIT_MONO_PIXEL -#define INIT_MONO_PIXEL(p) \ - GLuint p = hwcx->pixelValue; +#define INIT_MONO_PIXEL(p, color) \ + p = SISPACKCOLOR8888( color[0], color[1], color[2], color[3] ) #define WRITE_RGBA( _x, _y, r, g, b, a ) \ - *(GLuint *)(buf + _x*4 + _y*pitch) = ( ((a) << 24) | \ - ((r) << 16) | \ - ((g) << 8) | \ - ((b))) + *(GLuint *)(buf + _x*4 + _y*smesa->drawPitch) = \ + (((a) << 24) | \ + ((r) << 16) | \ + ((g) << 8) | \ + ((b))) #define WRITE_PIXEL( _x, _y, p ) \ - *(GLuint *)(buf + _x*4 + _y*pitch) = p + *(GLuint *)(buf + _x*4 + _y*smesa->drawPitch) = p #define READ_RGBA( rgba, _x, _y ) \ do { \ - GLuint p = *(GLuint *)(buf + _x*4 + _y*pitch); \ + GLuint p = *(GLuint *)(read_buf + _x*4 + _y*smesa->readPitch); \ rgba[0] = (p >> 16) & 0xff; \ rgba[1] = (p >> 8) & 0xff; \ rgba[2] = (p >> 0) & 0xff; \ @@ -143,63 +136,14 @@ #define TAG(x) sis_##x##_8888 #include "spantmp.h" -static void sis_Color_8888( GLcontext *ctx, - GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - hwcx->pixelValue = (red << 16) | - (green << 8) | - (blue) | - (alpha << 24); -} - -void sis_sw_init_driver( GLcontext *ctx ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - if (hwcx->colorFormat == DST_FORMAT_RGB_565) { - ctx->Driver.Color = sis_Color_565; - ctx->Driver.WriteRGBASpan = sis_WriteRGBASpan_565; - ctx->Driver.WriteRGBSpan = sis_WriteRGBSpan_565; - ctx->Driver.WriteMonoRGBASpan = sis_WriteMonoRGBASpan_565; - ctx->Driver.WriteRGBAPixels = sis_WriteRGBAPixels_565; - ctx->Driver.WriteMonoRGBAPixels = sis_WriteMonoRGBAPixels_565; - ctx->Driver.ReadRGBASpan = sis_ReadRGBASpan_565; - ctx->Driver.ReadRGBAPixels = sis_ReadRGBAPixels_565; - } - else if(hwcx->colorFormat == DST_FORMAT_ARGB_8888){ - ctx->Driver.Color = sis_Color_8888; - ctx->Driver.WriteRGBASpan = sis_WriteRGBASpan_8888; - ctx->Driver.WriteRGBSpan = sis_WriteRGBSpan_8888; - ctx->Driver.WriteMonoRGBASpan = sis_WriteMonoRGBASpan_8888; - ctx->Driver.WriteRGBAPixels = sis_WriteRGBAPixels_8888; - ctx->Driver.WriteMonoRGBAPixels = sis_WriteMonoRGBAPixels_8888; - ctx->Driver.ReadRGBASpan = sis_ReadRGBASpan_8888; - ctx->Driver.ReadRGBAPixels = sis_ReadRGBAPixels_8888; - } - else{ - assert(0); - } - - ctx->Driver.WriteCI8Span =NULL; - ctx->Driver.WriteCI32Span =NULL; - ctx->Driver.WriteMonoCISpan =NULL; - ctx->Driver.WriteCI32Pixels =NULL; - ctx->Driver.WriteMonoCIPixels =NULL; - ctx->Driver.ReadCI32Span =NULL; - ctx->Driver.ReadCI32Pixels =NULL; -} /* Depth/Stencil Functions * use sizeof(GLdepth) to know the Z rnage of mesa is * 0 ~ 2^16-1 or 0 ~ 2^32-1 */ #define SIS_SW_Z_BASE(x,y) \ - ((SIS_SW_DTYPE *)(hwcx->swZBase + (x)*sizeof(SIS_SW_DTYPE) + \ - (y)*hwcx->swZPitch)) + ((SIS_SW_DTYPE *)(smesa->swZBase + (x)*sizeof(SIS_SW_DTYPE) + \ + (y)*smesa->swZPitch)) /* Z16 */ #define SIS_TAG(x) x##_Z16 @@ -275,46 +219,106 @@ #undef SIS_SW_STENCIL_FUNC +/* + * This function is called to specify which buffer to read and write + * for software rasterization (swrast) fallbacks. This doesn't necessarily + * correspond to glDrawBuffer() or glReadBuffer() calls. + */ +static void sisDDSetBuffer( GLcontext *ctx, + GLframebuffer *colorBuffer, + GLuint bufferBit ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + + switch ( bufferBit ) { + case FRONT_LEFT_BIT: + smesa->drawOffset = smesa->readOffset = smesa->frontOffset; + smesa->drawPitch = smesa->readPitch = smesa->frontPitch; + break; + case BACK_LEFT_BIT: + smesa->drawOffset = smesa->readOffset = smesa->backOffset; + smesa->drawPitch = smesa->readPitch = smesa->backPitch; + break; + default: + break; + } +} + void -sis_sw_set_zfuncs_static (GLcontext * ctx) +sisDDInitSpanFuncs( GLcontext *ctx ) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); + struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx); + + swdd->SetBuffer = sisDDSetBuffer; - switch (hwcx->zFormat) - { - case Z_16: - ctx->Driver.ReadDepthSpan = sis_ReadDepthSpan_Z16; - ctx->Driver.ReadDepthPixels = sis_ReadDepthPixels_Z16; - ctx->Driver.WriteDepthSpan = sis_WriteDepthSpan_Z16; - ctx->Driver.WriteDepthPixels = sis_WriteDepthPixels_Z16; - - ctx->Driver.ReadStencilSpan = NULL; - ctx->Driver.ReadStencilPixels = NULL; - ctx->Driver.WriteStencilSpan = NULL; - ctx->Driver.WriteStencilPixels = NULL; + switch (smesa->zFormat) + { + case Z_16: + swdd->ReadDepthSpan = sis_ReadDepthSpan_Z16; + swdd->ReadDepthPixels = sis_ReadDepthPixels_Z16; + swdd->WriteDepthSpan = sis_WriteDepthSpan_Z16; + swdd->WriteDepthPixels = sis_WriteDepthPixels_Z16; + + swdd->ReadStencilSpan = NULL; + swdd->ReadStencilPixels = NULL; + swdd->WriteStencilSpan = NULL; + swdd->WriteStencilPixels = NULL; break; - case Z_32: - ctx->Driver.ReadDepthSpan = sis_ReadDepthSpan_Z32; - ctx->Driver.ReadDepthPixels = sis_ReadDepthPixels_Z32; - ctx->Driver.WriteDepthSpan = sis_WriteDepthSpan_Z32; - ctx->Driver.WriteDepthPixels = sis_WriteDepthPixels_Z32; - - ctx->Driver.ReadStencilSpan = NULL; - ctx->Driver.ReadStencilPixels = NULL; - ctx->Driver.WriteStencilSpan = NULL; - ctx->Driver.WriteStencilPixels = NULL; + case Z_32: + swdd->ReadDepthSpan = sis_ReadDepthSpan_Z32; + swdd->ReadDepthPixels = sis_ReadDepthPixels_Z32; + swdd->WriteDepthSpan = sis_WriteDepthSpan_Z32; + swdd->WriteDepthPixels = sis_WriteDepthPixels_Z32; + + swdd->ReadStencilSpan = NULL; + swdd->ReadStencilPixels = NULL; + swdd->WriteStencilSpan = NULL; + swdd->WriteStencilPixels = NULL; break; - case S_8_Z_24: - ctx->Driver.ReadDepthSpan = sis_ReadDepthSpan_S8Z24; - ctx->Driver.ReadDepthPixels = sis_ReadDepthPixels_S8Z24; - ctx->Driver.WriteDepthSpan = sis_WriteDepthSpan_S8Z24; - ctx->Driver.WriteDepthPixels = sis_WriteDepthPixels_S8Z24; - - ctx->Driver.ReadStencilSpan = sis_ReadStencilSpan_S8Z24; - ctx->Driver.ReadStencilPixels = sis_ReadStencilPixels_S8Z24; - ctx->Driver.WriteStencilSpan = sis_WriteStencilSpan_S8Z24; - ctx->Driver.WriteStencilPixels = sis_WriteStencilPixels_S8Z24; + case S_8_Z_24: + swdd->ReadDepthSpan = sis_ReadDepthSpan_S8Z24; + swdd->ReadDepthPixels = sis_ReadDepthPixels_S8Z24; + swdd->WriteDepthSpan = sis_WriteDepthSpan_S8Z24; + swdd->WriteDepthPixels = sis_WriteDepthPixels_S8Z24; + + swdd->ReadStencilSpan = sis_ReadStencilSpan_S8Z24; + swdd->ReadStencilPixels = sis_ReadStencilPixels_S8Z24; + swdd->WriteStencilSpan = sis_WriteStencilSpan_S8Z24; + swdd->WriteStencilPixels = sis_WriteStencilPixels_S8Z24; break; - } + } + + switch ( smesa->bytesPerPixel ) + { + case 2: + swdd->WriteRGBASpan = sis_WriteRGBASpan_565; + swdd->WriteRGBSpan = sis_WriteRGBSpan_565; + swdd->WriteMonoRGBASpan = sis_WriteMonoRGBASpan_565; + swdd->WriteRGBAPixels = sis_WriteRGBAPixels_565; + swdd->WriteMonoRGBAPixels = sis_WriteMonoRGBAPixels_565; + swdd->ReadRGBASpan = sis_ReadRGBASpan_565; + swdd->ReadRGBAPixels = sis_ReadRGBAPixels_565; + break; + case 4: + swdd->WriteRGBASpan = sis_WriteRGBASpan_8888; + swdd->WriteRGBSpan = sis_WriteRGBSpan_8888; + swdd->WriteMonoRGBASpan = sis_WriteMonoRGBASpan_8888; + swdd->WriteRGBAPixels = sis_WriteRGBAPixels_8888; + swdd->WriteMonoRGBAPixels = sis_WriteMonoRGBAPixels_8888; + swdd->ReadRGBASpan = sis_ReadRGBASpan_8888; + swdd->ReadRGBAPixels = sis_ReadRGBAPixels_8888; + break; + default: + assert(0); + break; + } + + swdd->WriteCI8Span = NULL; + swdd->WriteCI32Span = NULL; + swdd->WriteMonoCISpan = NULL; + swdd->WriteCI32Pixels = NULL; + swdd->WriteMonoCIPixels = NULL; + swdd->ReadCI32Span = NULL; + swdd->ReadCI32Pixels = NULL; } diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_span.h xc/lib/GL/mesa/src/drv/sis/sis_span.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_span.h Wed Dec 31 16:00:00 1969 +++ xc/lib/GL/mesa/src/drv/sis/sis_span.h Tue Aug 12 12:03:20 2003 @@ -0,0 +1,43 @@ +/************************************************************************** + +Copyright 2003 Eric Anholt +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sub license, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. +IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ +/* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_ctx.c,v 1.3 2000/09/26 15:56:48 tsi Exp $ */ + +/* + * Authors: + * Eric Anholt + * + */ + +#ifndef __SIS_SPAN_H__ +#define __SIS_SPAN_H__ + +#ifdef GLX_DIRECT_RENDERING + +extern void sisDDInitSpanFuncs( GLcontext *ctx ); + +#endif +#endif diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_state.c xc/lib/GL/mesa/src/drv/sis/sis_state.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_state.c Wed Dec 31 16:00:00 1969 +++ xc/lib/GL/mesa/src/drv/sis/sis_state.c Fri Aug 22 15:33:20 2003 @@ -0,0 +1,855 @@ +/************************************************************************** + +Copyright 2003 Eric Anholt +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sub license, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. +IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ +/* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_ctx.c,v 1.3 2000/09/26 15:56:48 tsi Exp $ */ + +/* + * Authors: + * Sung-Ching Lin + * Eric Anholt + * + */ + +#include "sis_context.h" +#include "sis_state.h" +#include "sis_tris.h" + +#include "context.h" +#include "enums.h" +#include "colormac.h" +#include "swrast/swrast.h" +#include "array_cache/acache.h" +#include "tnl/tnl.h" +#include "swrast_setup/swrast_setup.h" + +#include "tnl/t_pipeline.h" + +/* ============================================================= + * Alpha blending + */ + +static void +sisDDAlphaFunc( GLcontext * ctx, GLenum func, GLclampf ref ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + + __GLSiSHardware *prev = &smesa->prev; + __GLSiSHardware *current = &smesa->current; + + /* TODO: ref is type GLclampf, but mesa has scaled it to 0 - 255.0 */ + current->hwAlpha = ((unsigned char) ref) << 16; + + /* Alpha Test function */ + current->hwAlpha &= ~0x07000000; + switch (func) + { + case GL_NEVER: + current->hwAlpha |= SiS_ALPHA_NEVER; + break; + case GL_LESS: + current->hwAlpha |= SiS_ALPHA_LESS; + break; + case GL_EQUAL: + current->hwAlpha |= SiS_ALPHA_EQUAL; + break; + case GL_LEQUAL: + current->hwAlpha |= SiS_ALPHA_LEQUAL; + break; + case GL_GREATER: + current->hwAlpha |= SiS_ALPHA_GREATER; + break; + case GL_NOTEQUAL: + current->hwAlpha |= SiS_ALPHA_NOTEQUAL; + break; + case GL_GEQUAL: + current->hwAlpha |= SiS_ALPHA_GEQUAL; + break; + case GL_ALWAYS: + current->hwAlpha |= SiS_ALPHA_ALWAYS; + break; + } + + prev->hwAlpha = current->hwAlpha; + smesa->GlobalFlag |= GFLAG_ALPHASETTING; +} + +static void +sisDDBlendFunc( GLcontext *ctx, GLenum sfactor, GLenum dfactor ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + + __GLSiSHardware *prev = &smesa->prev; + __GLSiSHardware *current = &smesa->current; + + /* TODO: in ICD, if no blend, it will reset these value */ + /* blending enable */ + current->hwDstSrcBlend = 0x10000; /* Default destination alpha */ + + switch (dfactor) + { + case GL_ZERO: + current->hwDstSrcBlend |= SiS_D_ZERO; + break; + case GL_ONE: + current->hwDstSrcBlend |= SiS_D_ONE; + break; + case GL_SRC_COLOR: + current->hwDstSrcBlend |= SiS_D_SRC_COLOR; + break; + case GL_ONE_MINUS_SRC_COLOR: + current->hwDstSrcBlend |= SiS_D_ONE_MINUS_SRC_COLOR; + break; + case GL_SRC_ALPHA: + current->hwDstSrcBlend |= SiS_D_SRC_ALPHA; + break; + case GL_ONE_MINUS_SRC_ALPHA: + current->hwDstSrcBlend |= SiS_D_ONE_MINUS_SRC_ALPHA; + break; + case GL_DST_ALPHA: + current->hwDstSrcBlend |= SiS_D_DST_ALPHA; + break; + case GL_ONE_MINUS_DST_ALPHA: + current->hwDstSrcBlend |= SiS_D_ONE_MINUS_DST_ALPHA; + break; + } + + switch (sfactor) + { + case GL_ZERO: + current->hwDstSrcBlend |= SiS_S_ZERO; + break; + case GL_ONE: + current->hwDstSrcBlend |= SiS_S_ONE; + break; + case GL_SRC_ALPHA: + current->hwDstSrcBlend |= SiS_S_SRC_ALPHA; + break; + case GL_ONE_MINUS_SRC_ALPHA: + current->hwDstSrcBlend |= SiS_S_ONE_MINUS_SRC_ALPHA; + break; + case GL_DST_ALPHA: + current->hwDstSrcBlend |= SiS_S_DST_ALPHA; + break; + case GL_ONE_MINUS_DST_ALPHA: + current->hwDstSrcBlend |= SiS_S_ONE_MINUS_DST_ALPHA; + break; + case GL_DST_COLOR: + current->hwDstSrcBlend |= SiS_S_DST_COLOR; + break; + case GL_ONE_MINUS_DST_COLOR: + current->hwDstSrcBlend |= SiS_S_ONE_MINUS_DST_COLOR; + break; + case GL_SRC_ALPHA_SATURATE: + current->hwDstSrcBlend |= SiS_S_SRC_ALPHA_SATURATE; + break; + } + + if (current->hwDstSrcBlend ^ prev->hwDstSrcBlend) { + prev->hwDstSrcBlend = current->hwDstSrcBlend; + smesa->GlobalFlag |= GFLAG_DSTBLEND; + } +} + +/* ============================================================= + * Depth testing + */ + +static void +sisDDDepthFunc( GLcontext * ctx, GLenum func ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + __GLSiSHardware *prev = &smesa->prev; + __GLSiSHardware *current = &smesa->current; + + GLuint hwZFunc = 0; + + switch (func) + { + case GL_LESS: + hwZFunc = SiS_Z_COMP_S_LT_B; + break; + case GL_GEQUAL: + hwZFunc = SiS_Z_COMP_S_GE_B; + break; + case GL_LEQUAL: + hwZFunc = SiS_Z_COMP_S_LE_B; + break; + case GL_GREATER: + hwZFunc = SiS_Z_COMP_S_GT_B; + break; + case GL_NOTEQUAL: + hwZFunc = SiS_Z_COMP_S_NE_B; + break; + case GL_EQUAL: + hwZFunc = SiS_Z_COMP_S_EQ_B; + break; + case GL_ALWAYS: + hwZFunc = SiS_Z_COMP_ALWAYS; + break; + case GL_NEVER: + hwZFunc = SiS_Z_COMP_NEVER; + break; + } + current->hwZ &= ~MASK_ZTestMode; + current->hwZ |= hwZFunc; + + if (current->hwZ ^ prev->hwZ) { + prev->hwZ = current->hwZ; + smesa->GlobalFlag |= GFLAG_ZSETTING; + } +} + +void +sisDDDepthMask( GLcontext * ctx, GLboolean flag ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + __GLSiSHardware *prev = &smesa->prev; + __GLSiSHardware *current = &smesa->current; + + if (ctx->Visual.stencilBits) { + if (flag || ctx->Stencil.WriteMask) { + current->hwCapEnable |= MASK_ZWriteEnable; + if (flag && ctx->Stencil.WriteMask[0] == 0xff) { /* XXX WriteMask[0]? */ + current->hwCapEnable2 &= ~MASK_ZMaskWriteEnable; + } else { + current->hwCapEnable2 |= MASK_ZMaskWriteEnable; + current->hwZMask = ((GLint) ctx->Stencil.WriteMask << 24) | + ((flag) ? 0x00ffffff : 0); + + if (current->hwZMask ^ prev->hwZMask) { + prev->hwZMask = current->hwZMask; + smesa->GlobalFlag |= GFLAG_ZSETTING; + } + } + } else { + current->hwCapEnable &= ~MASK_ZWriteEnable; + } + } else { + if (flag) { + current->hwCapEnable |= MASK_ZWriteEnable; + current->hwCapEnable2 &= ~MASK_ZMaskWriteEnable; + } else { + current->hwCapEnable &= ~MASK_ZWriteEnable; + } + } +} + +/* ============================================================= + * Clipping + */ + +void +sisUpdateClipping( GLcontext *ctx ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + + __GLSiSHardware *prev = &smesa->prev; + __GLSiSHardware *current = &smesa->current; + + GLint x1, y1, x2, y2; + + /* ?? from context.c, do it 2 times */ + + x1 = 0; + y1 = 0; + x2 = smesa->width - 1; + y2 = smesa->height - 1; + + if (ctx->Scissor.Enabled) { + if (ctx->Scissor.X > x1) + x1 = ctx->Scissor.X; + if (ctx->Scissor.Y > y1) + y1 = ctx->Scissor.Y; + if (ctx->Scissor.X + ctx->Scissor.Width - 1 < x2) + x2 = ctx->Scissor.X + ctx->Scissor.Width - 1; + if (ctx->Scissor.Y + ctx->Scissor.Height - 1 < y2) + y2 = ctx->Scissor.Y + ctx->Scissor.Height - 1; + } + + y1 = Y_FLIP (y1); + y2 = Y_FLIP (y2); + + current->clipTopBottom = (y2 << 13) | y1; + current->clipLeftRight = (x1 << 13) | x2; + + if ((current->clipTopBottom ^ prev->clipTopBottom) || + (current->clipLeftRight ^ prev->clipLeftRight)) + { + prev->clipTopBottom = current->clipTopBottom; + prev->clipLeftRight = current->clipLeftRight; + smesa->GlobalFlag |= GFLAG_CLIPPING; + } +} + +static void +sisDDScissor( GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h ) +{ + if (ctx->Scissor.Enabled) + sisUpdateClipping( ctx ); +} + +/* ============================================================= + * Culling + */ + +static void +sisUpdateCull( GLcontext *ctx ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + GLint cullflag, frontface; + + cullflag = ctx->Polygon.CullFlag; + frontface = ctx->Polygon.FrontFace; + + if (cullflag == GL_FRONT_AND_BACK) { + FALLBACK(smesa, SIS_FALLBACK_CULL, 1); + return; + } else { + FALLBACK(smesa, SIS_FALLBACK_CULL, 0); + } + + smesa->AGPParseSet &= ~(MASK_PsCullDirection_CCW); + smesa->dwPrimitiveSet &= ~(MASK_CullDirection); + + if((cullflag == GL_FRONT && frontface == GL_CCW) || + (cullflag == GL_BACK && frontface == GL_CW)) + { + smesa->AGPParseSet |= 0x00008000; + smesa->dwPrimitiveSet |= OP_3D_CullDirection_CCW; + } +} + + +static void +sisDDCullFace( GLcontext *ctx, GLenum mode ) +{ + sisUpdateCull( ctx ); +} + +static void +sisDDFrontFace( GLcontext *ctx, GLenum mode ) +{ + sisUpdateCull( ctx ); +} + +/* ============================================================= + * Masks + */ + +/* ============================================================= + * Rendering attributes + */ + +/* ============================================================= + * Window position + */ + +/* ============================================================= + * Viewport + */ + +static void sisCalcViewport( GLcontext *ctx ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + const GLfloat *v = ctx->Viewport._WindowMap.m; + GLfloat *m = smesa->hw_viewport; + + /* See also sis_translate_vertex. + */ + m[MAT_SX] = v[MAT_SX]; + m[MAT_TX] = v[MAT_TX] + SUBPIXEL_X; + m[MAT_SY] = - v[MAT_SY]; + m[MAT_TY] = - v[MAT_TY] + smesa->driDrawable->h + SUBPIXEL_Y; + m[MAT_SZ] = v[MAT_SZ] * smesa->depth_scale; + m[MAT_TZ] = v[MAT_TZ] * smesa->depth_scale; +} + +static void sisDDViewport( GLcontext *ctx, + GLint x, GLint y, + GLsizei width, GLsizei height ) +{ + sisCalcViewport( ctx ); +} + +static void sisDDDepthRange( GLcontext *ctx, + GLclampd nearval, GLclampd farval ) +{ + sisCalcViewport( ctx ); +} + +/* ============================================================= + * Miscellaneous + */ + +static void +sisDDLogicOpCode( GLcontext *ctx, GLenum opcode ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + + __GLSiSHardware *prev = &smesa->prev; + __GLSiSHardware *current = &smesa->current; + + if (!ctx->Color.ColorLogicOpEnabled) + return; + + current->hwDstSet &= ~MASK_ROP2; + switch (opcode) + { + case GL_CLEAR: + current->hwDstSet |= LOP_CLEAR; + break; + case GL_SET: + current->hwDstSet |= LOP_SET; + break; + case GL_COPY: + current->hwDstSet |= LOP_COPY; + break; + case GL_COPY_INVERTED: + current->hwDstSet |= LOP_COPY_INVERTED; + break; + case GL_NOOP: + current->hwDstSet |= LOP_NOOP; + break; + case GL_INVERT: + current->hwDstSet |= LOP_INVERT; + break; + case GL_AND: + current->hwDstSet |= LOP_AND; + break; + case GL_NAND: + current->hwDstSet |= LOP_NAND; + break; + case GL_OR: + current->hwDstSet |= LOP_OR; + break; + case GL_NOR: + current->hwDstSet |= LOP_NOR; + break; + case GL_XOR: + current->hwDstSet |= LOP_XOR; + break; + case GL_EQUIV: + current->hwDstSet |= LOP_EQUIV; + break; + case GL_AND_REVERSE: + current->hwDstSet |= LOP_AND_REVERSE; + break; + case GL_AND_INVERTED: + current->hwDstSet |= LOP_AND_INVERTED; + break; + case GL_OR_REVERSE: + current->hwDstSet |= LOP_OR_REVERSE; + break; + case GL_OR_INVERTED: + current->hwDstSet |= LOP_OR_INVERTED; + break; + } + + if (current->hwDstSet ^ prev->hwDstSet) { + prev->hwDstSet = current->hwDstSet; + smesa->GlobalFlag |= GFLAG_DESTSETTING; + } +} + +void sisDDDrawBuffer( GLcontext *ctx, GLenum mode ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + + __GLSiSHardware *prev = &smesa->prev; + __GLSiSHardware *current = &smesa->current; + + /* We want to update the s/w rast state too so that sisDDSetBuffer() + * gets called. + */ + _swrast_DrawBuffer(ctx, mode); + + current->hwOffsetDest = (smesa->drawOffset) >> 1; + current->hwDstSet &= ~MASK_DstBufferPitch; + current->hwDstSet |= smesa->drawPitch >> 2; + + if (current->hwDstSet != prev->hwDstSet) { + prev->hwDstSet = current->hwDstSet; + smesa->GlobalFlag |= GFLAG_DESTSETTING; + } + + if (current->hwOffsetDest != prev->hwOffsetDest) { + prev->hwOffsetDest = current->hwOffsetDest; + smesa->GlobalFlag |= GFLAG_DESTSETTING; + } +} + +static void sisDDReadBuffer( GLcontext *ctx, GLenum mode ) +{ + /* nothing, until we implement h/w glRead/CopyPixels or CopyTexImage */ +} + +/* ============================================================= + * Polygon stipple + */ + +/* ============================================================= + * Render mode + */ + +/* ============================================================= + * State enable/disable + */ + +static void +sisDDEnable( GLcontext * ctx, GLenum cap, GLboolean state ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + + __GLSiSHardware *current = &smesa->current; + + switch (cap) + { + case GL_ALPHA_TEST: + if (state) + current->hwCapEnable |= MASK_AlphaTestEnable; + else + current->hwCapEnable &= ~MASK_AlphaTestEnable; + break; +/* + case GL_AUTO_NORMAL: + break; +*/ + case GL_BLEND: + /* TODO: */ + if (state) + /* if (state & !ctx->Color.ColorLogicOpEnabled) */ + current->hwCapEnable |= MASK_BlendEnable; + else + current->hwCapEnable &= ~MASK_BlendEnable; + break; +/* + case GL_CLIP_PLANE0: + case GL_CLIP_PLANE1: + case GL_CLIP_PLANE2: + case GL_CLIP_PLANE3: + case GL_CLIP_PLANE4: + case GL_CLIP_PLANE5: + break; + case GL_COLOR_MATERIAL: + break; +*/ + case GL_CULL_FACE: +#ifdef SIS_USE_HW_CULL + if (state) + current->hwCapEnable |= MASK_CullEnable; + else + current->hwCapEnable &= ~MASK_CullEnable; +#endif + break; + case GL_DEPTH_TEST: + if (state && smesa->depthbuffer) + current->hwCapEnable |= MASK_ZTestEnable; + else + current->hwCapEnable &= ~MASK_ZTestEnable; + break; + case GL_DITHER: + if (state) + current->hwCapEnable |= MASK_DitherEnable; + else + current->hwCapEnable &= ~MASK_DitherEnable; + break; + case GL_FOG: + if (state) + current->hwCapEnable |= MASK_FogEnable; + else + current->hwCapEnable &= ~MASK_FogEnable; + break; +/* + case GL_LIGHT0: + case GL_LIGHT1: + case GL_LIGHT2: + case GL_LIGHT3: + case GL_LIGHT4: + case GL_LIGHT5: + case GL_LIGHT6: + case GL_LIGHT7: + break; + case GL_LIGHTING: + break; + case GL_LINE_SMOOTH: + break; + case GL_LINE_STIPPLE: + break; + case GL_INDEX_LOGIC_OP: + break; +*/ + case GL_COLOR_LOGIC_OP: + if (state) + sisDDLogicOpCode( ctx, ctx->Color.LogicOp ); + else + sisDDLogicOpCode( ctx, GL_COPY ); + break; +/* + case GL_MAP1_COLOR_4: + break; + case GL_MAP1_INDEX: + break; + case GL_MAP1_NORMAL: + break; + case GL_MAP1_TEXTURE_COORD_1: + break; + case GL_MAP1_TEXTURE_COORD_2: + break; + case GL_MAP1_TEXTURE_COORD_3: + break; + case GL_MAP1_TEXTURE_COORD_4: + break; + case GL_MAP1_VERTEX_3: + break; + case GL_MAP1_VERTEX_4: + break; + case GL_MAP2_COLOR_4: + break; + case GL_MAP2_INDEX: + break; + case GL_MAP2_NORMAL: + break; + case GL_MAP2_TEXTURE_COORD_1: + break; + case GL_MAP2_TEXTURE_COORD_2: + break; + case GL_MAP2_TEXTURE_COORD_3: + break; + case GL_MAP2_TEXTURE_COORD_4: + break; + case GL_MAP2_VERTEX_3: + break; + case GL_MAP2_VERTEX_4: + break; + case GL_NORMALIZE: + break; + case GL_POINT_SMOOTH: + break; + case GL_POLYGON_SMOOTH: + break; + case GL_POLYGON_STIPPLE: + break; + case GL_POLYGON_OFFSET_POINT: + break; + case GL_POLYGON_OFFSET_LINE: + break; + case GL_POLYGON_OFFSET_FILL: + case GL_POLYGON_OFFSET_EXT: + break; + case GL_RESCALE_NORMAL_EXT: + break; +*/ + case GL_SCISSOR_TEST: + sisUpdateClipping( ctx ); + break; +/* + case GL_SHARED_TEXTURE_PALETTE_EXT: + break; +*/ + case GL_STENCIL_TEST: + if (state) + current->hwCapEnable |= (MASK_StencilTestEnable | + MASK_StencilWriteEnable); + else + current->hwCapEnable &= ~(MASK_StencilTestEnable | + MASK_StencilWriteEnable); + break; +/* + case GL_TEXTURE_1D: + case GL_TEXTURE_2D: + case GL_TEXTURE_3D: + break; + case GL_TEXTURE_GEN_Q: + break; + case GL_TEXTURE_GEN_R: + break; + case GL_TEXTURE_GEN_S: + break; + case GL_TEXTURE_GEN_T: + break; + + case GL_VERTEX_ARRAY: + break; + case GL_NORMAL_ARRAY: + break; + case GL_COLOR_ARRAY: + break; + case GL_INDEX_ARRAY: + break; + case GL_TEXTURE_COORD_ARRAY: + break; + case GL_EDGE_FLAG_ARRAY: + break; +*/ + } +} + +/* ============================================================= + * State initialization, management + */ + +static void sisDDInvalidateState( GLcontext *ctx, GLuint new_state ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + + __GLSiSHardware *prev = &smesa->prev; + __GLSiSHardware *current = &smesa->current; + + _swrast_InvalidateState( ctx, new_state ); + _swsetup_InvalidateState( ctx, new_state ); + _ac_InvalidateState( ctx, new_state ); + _tnl_InvalidateState( ctx, new_state ); + smesa->NewGLState |= new_state; + + /* NEW_TEXTURE_ENABLE depends on glEnable() instead of ReallyEnabled */ + /* if (ctx->NewState & NEW_TEXTURE_ENABLE) */ + if(1) { + if ( ctx->Texture.Unit[0]._ReallyEnabled & + (TEXTURE_1D_BIT | TEXTURE_2D_BIT) || + ctx->Texture.Unit[1]._ReallyEnabled & + (TEXTURE_1D_BIT | TEXTURE_2D_BIT) ) + { + current->hwCapEnable |= MASK_TextureEnable; + + current->hwCapEnable &= ~MASK_TextureNumUsed; + if (ctx->Texture.Unit[1]._ReallyEnabled) + current->hwCapEnable |= 0x00002000; + else + current->hwCapEnable |= 0x00001000; + } else { + current->hwCapEnable &= ~MASK_TextureEnable; + } + +#if 1 + /* TODO : if unmark these, error in multitexture */ /* XXX */ + if (new_state & _NEW_TEXTURE) { + int i; + + for (i = 0; i < SIS_MAX_TEXTURES; i++) + smesa->TexStates[i] |= (NEW_TEXTURING | NEW_TEXTURE_ENV); + } +#endif + } + + /* enable setting 1 */ + if (current->hwCapEnable ^ prev->hwCapEnable) { + prev->hwCapEnable = current->hwCapEnable; + smesa->GlobalFlag |= GFLAG_ENABLESETTING; + } + + /* enable setting 2 */ + if (current->hwCapEnable2 ^ prev->hwCapEnable2) { + prev->hwCapEnable2 = current->hwCapEnable2; + smesa->GlobalFlag |= GFLAG_ENABLESETTING2; + } + + /* TODO: if fog disable, don't check */ + if (current->hwCapEnable & MASK_FogEnable) { + /* fog setting */ + if (current->hwFog ^ prev->hwFog) { + prev->hwFog = current->hwFog; + smesa->GlobalFlag |= GFLAG_FOGSETTING; + } + if (current->hwFogFar ^ prev->hwFogFar) { + prev->hwFogFar = current->hwFogFar; + smesa->GlobalFlag |= GFLAG_FOGSETTING; + } + if (current->hwFogInverse ^ prev->hwFogInverse) { + prev->hwFogInverse = current->hwFogInverse; + smesa->GlobalFlag |= GFLAG_FOGSETTING; + } + if (current->hwFogDensity ^ prev->hwFogDensity) { + prev->hwFogDensity = current->hwFogDensity; + smesa->GlobalFlag |= GFLAG_FOGSETTING; + } + } + +#ifdef NOT_DONE + sis_set_render_vb_tabs(ctx); +#endif + + /* TODO: assume when isFullScreen/DrawBuffer changed, UpdateState + * will be called + */ +#if SIS_STEREO + if (smesa->isFullScreen && (ctx->Color.DriverDrawBuffer == GL_BACK_LEFT) && + smesa->useStereo) + { + if (!smesa->stereoEnabled) + sis_init_stereo(ctx); + } else { + if (smesa->stereoEnabled) + sis_final_stereo(ctx); + } +#endif + + /* TODO : 1. where to handle SIS_SW_TEXTURE? + * 2. sw<->hw + * 3. sw-render only if next primitve need to do + */ +} + + +/* Initialize the driver's state functions. + */ +void sisDDInitStateFuncs( GLcontext *ctx ) +{ + ctx->Driver.UpdateState = sisDDInvalidateState; + ctx->Driver.Clear = sisDDClear; + ctx->Driver.ClearColor = sisDDClearColor; + ctx->Driver.ClearDepth = sisDDClearDepth; + ctx->Driver.ClearStencil = sisDDClearStencil; + + ctx->Driver.AlphaFunc = sisDDAlphaFunc; + ctx->Driver.BlendFunc = sisDDBlendFunc; + ctx->Driver.CullFace = sisDDCullFace; + ctx->Driver.DepthMask = sisDDDepthMask; + ctx->Driver.DepthFunc = sisDDDepthFunc; + ctx->Driver.DepthRange = sisDDDepthRange; + ctx->Driver.DrawBuffer = sisDDDrawBuffer; + ctx->Driver.Enable = sisDDEnable; + ctx->Driver.FrontFace = sisDDFrontFace; + ctx->Driver.Fogfv = sisDDFogfv; + ctx->Driver.LogicOpcode = sisDDLogicOpCode; + ctx->Driver.ReadBuffer = sisDDReadBuffer; + ctx->Driver.Scissor = sisDDScissor; + ctx->Driver.Viewport = sisDDViewport; + + /* Pixel path fallbacks. + */ + ctx->Driver.Accum = _swrast_Accum; + ctx->Driver.Bitmap = _swrast_Bitmap; + ctx->Driver.CopyPixels = _swrast_CopyPixels; + ctx->Driver.DrawPixels = _swrast_DrawPixels; + ctx->Driver.ReadPixels = _swrast_ReadPixels; /* XXX Accel draw/readpix */ + + /* Swrast hooks for imaging extensions: + */ + ctx->Driver.CopyColorTable = _swrast_CopyColorTable; + ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable; + ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D; + ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D; +} diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_state.h xc/lib/GL/mesa/src/drv/sis/sis_state.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_state.h Wed Dec 31 16:00:00 1969 +++ xc/lib/GL/mesa/src/drv/sis/sis_state.h Fri Aug 22 15:33:20 2003 @@ -0,0 +1,57 @@ +/* $XFree86$ */ +/************************************************************************** + +Copyright 2003 Eric Anholt +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +on the rights to use, copy, modify, merge, publish, distribute, sub +license, and/or sell copies of the Software, and to permit persons to whom +the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ + +/* + * Authors: + * Eric Anholt + * + */ + +#ifndef __SIS_STATE_H__ +#define __SIS_STATE_H__ + +#ifdef GLX_DIRECT_RENDERING + +#include "sis_context.h" + +extern void sisDDInitStateFuncs( GLcontext *ctx ); + +extern void sisDDClear( GLcontext *ctx, GLbitfield mask, GLboolean all, + GLint x, GLint y, GLint width, GLint height ); +extern void sisDDClearColor( GLcontext * ctx, const GLfloat color[4] ); +extern void sisDDClearDepth( GLcontext * ctx, GLclampd d ); +extern void sisDDClearStencil( GLcontext * ctx, GLint s ); +extern void sisDDFogfv( GLcontext * ctx, GLenum pname, const GLfloat * params ); +extern void sisDDDepthMask( GLcontext * ctx, GLboolean flag ); + +extern void sisUpdateClipping( GLcontext * gc ); +extern void sisUpdateZStencilPattern( sisContextPtr smesa, GLclampd z, + int stencil ); +extern void sisDDDrawBuffer( GLcontext *ctx, GLenum mode ); + +#endif +#endif diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_stencil.c xc/lib/GL/mesa/src/drv/sis/sis_stencil.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_stencil.c Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_stencil.c Tue Aug 19 16:58:21 2003 @@ -32,19 +32,20 @@ * */ -#include "sis_ctx.h" +#include "sis_context.h" +#include "sis_state.h" +#include "sis_stencil.h" #include "sis_mesa.h" -void -sis_StencilFunc (GLcontext * ctx, GLenum func, GLint ref, GLuint mask) +static void +sisDDStencilFunc( GLcontext * ctx, GLenum func, GLint ref, GLuint mask ) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - __GLSiSHardware *prev = &hwcx->prev; - __GLSiSHardware *current = &hwcx->current; + sisContextPtr smesa = SIS_CONTEXT(ctx); + __GLSiSHardware *prev = &smesa->prev; + __GLSiSHardware *current = &smesa->current; /* set reference */ - current->hwStSetting = ((DWORD) ref << 8) | mask; + current->hwStSetting = ((GLint) ref << 8) | mask; current->hwStSetting &= ~0x07000000; switch (func) @@ -81,27 +82,26 @@ prev->hwStSetting = current->hwStSetting; prev->hwStSetting2 = current->hwStSetting2; - hwcx->GlobalFlag |= GFLAG_STENCILSETTING; + smesa->GlobalFlag |= GFLAG_STENCILSETTING; } } -void -sis_StencilMask (GLcontext * ctx, GLuint mask) +static void +sisDDStencilMask( GLcontext * ctx, GLuint mask ) { - if (!ctx->Visual->StencilBits) + if (!ctx->Visual.stencilBits) return; /* set Z buffer Write Enable */ - sis_DepthMask (ctx, ctx->Depth.Mask); + sisDDDepthMask (ctx, ctx->Depth.Mask); } -void -sis_StencilOp (GLcontext * ctx, GLenum fail, GLenum zfail, GLenum zpass) +static void +sisDDStencilOp( GLcontext * ctx, GLenum fail, GLenum zfail, GLenum zpass ) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - __GLSiSHardware *prev = &hwcx->prev; - __GLSiSHardware *current = &hwcx->current; + sisContextPtr smesa = SIS_CONTEXT(ctx); + __GLSiSHardware *prev = &smesa->prev; + __GLSiSHardware *current = &smesa->current; current->hwStSetting2 &= ~0x00777000; @@ -177,7 +177,15 @@ prev->hwStSetting = current->hwStSetting; prev->hwStSetting2 = current->hwStSetting2; - hwcx->GlobalFlag |= GFLAG_STENCILSETTING; + smesa->GlobalFlag |= GFLAG_STENCILSETTING; } +} + +void +sisDDInitStencilFuncs( GLcontext *ctx ) +{ + ctx->Driver.StencilFunc = sisDDStencilFunc; + ctx->Driver.StencilMask = sisDDStencilMask; + ctx->Driver.StencilOp = sisDDStencilOp; } diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_stencil.h xc/lib/GL/mesa/src/drv/sis/sis_stencil.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_stencil.h Wed Dec 31 16:00:00 1969 +++ xc/lib/GL/mesa/src/drv/sis/sis_stencil.h Tue Aug 12 12:03:20 2003 @@ -0,0 +1,42 @@ +/* $XFree86$ */ +/************************************************************************** + +Copyright 2003 Eric Anholt +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +on the rights to use, copy, modify, merge, publish, distribute, sub +license, and/or sell copies of the Software, and to permit persons to whom +the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ + +/* + * Authors: + * Eric Anholt + * + */ + +#ifndef __SIS_STENCIL_H__ +#define __SIS_STENCIL_H__ + +#ifdef GLX_DIRECT_RENDERING + +extern void sisDDInitStencilFuncs( GLcontext *ctx ); + +#endif +#endif diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_swzfunc.h xc/lib/GL/mesa/src/drv/sis/sis_swzfunc.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_swzfunc.h Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_swzfunc.h Tue Aug 12 12:03:20 2003 @@ -36,8 +36,7 @@ GLint y, const GLdepth depth[], const GLubyte mask[]) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); SIS_SW_DTYPE *base = SIS_SW_Z_BASE (x, Y_FLIP (y)); @@ -52,8 +51,7 @@ static void SIS_TAG (sis_ReadDepthSpan) (GLcontext * ctx, GLuint n, GLint x, GLint y, GLdepth depth[]) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); SIS_SW_DTYPE *base = SIS_SW_Z_BASE (x, Y_FLIP (y)); @@ -69,8 +67,7 @@ const GLdepth depth[], const GLubyte mask[]) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); SIS_SW_DTYPE *base; @@ -89,8 +86,7 @@ const GLint x[], const GLint y[], GLdepth depth[]) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); SIS_SW_DTYPE *base; @@ -109,8 +105,7 @@ const GLstencil depth[], const GLubyte mask[]) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); SIS_SW_DTYPE *base = SIS_SW_Z_BASE (x, Y_FLIP (y)); @@ -125,8 +120,7 @@ static void SIS_TAG (sis_ReadStencilSpan) (GLcontext * ctx, GLuint n, GLint x, GLint y, GLstencil depth[]) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); SIS_SW_DTYPE *base = SIS_SW_Z_BASE (x, Y_FLIP (y)); @@ -143,8 +137,7 @@ const GLstencil depth[], const GLubyte mask[]) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); SIS_SW_DTYPE *base; @@ -163,8 +156,7 @@ const GLint x[], const GLint y[], GLstencil depth[]) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); SIS_SW_DTYPE *base; diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_tex.c xc/lib/GL/mesa/src/drv/sis/sis_tex.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_tex.c Wed Dec 31 16:00:00 1969 +++ xc/lib/GL/mesa/src/drv/sis/sis_tex.c Tue Aug 19 16:58:21 2003 @@ -0,0 +1,155 @@ +/************************************************************************** + +Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan. +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sub license, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. +IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ +/* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_texture.c,v 1.5 2000/09/26 15:56:49 tsi Exp $ */ + +/* + * Authors: + * Sung-Ching Lin + * + */ + +#include "sis_context.h" +#include "sis_alloc.h" +#include "sis_mesa.h" +#include "sis_tex.h" + +#include "swrast/swrast.h" +#include "texstore.h" + + +static void +sisDDTexEnv( GLcontext *ctx, GLenum target, GLenum pname, + const GLfloat *param ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + + smesa->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURE_ENV; +} + +static void +sisDDTexParameter (GLcontext * ctx, GLenum target, + struct gl_texture_object *tObj, GLenum pname, const + GLfloat * params) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + + if (tObj->DriverData) + ((sisTexobjInfo *) tObj->DriverData)->dirtyFlag |= SIS_TEX_PARAMETER; + + smesa->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURING; +} + +static void +sisDDBindTexture( GLcontext *ctx, GLenum target, + struct gl_texture_object *tObj ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + SIStextureArea *area; + + if (!tObj->Image[0]) + return; + + if (!(area = (SIStextureArea *) tObj->Image[0]->DriverData)) + return; + + if (smesa->PrevTexFormat[ctx->Texture.CurrentUnit] != area->Format) + { + smesa->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURE_ENV; + smesa->PrevTexFormat[ctx->Texture.CurrentUnit] = area->Format; + } + smesa->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURING; +} + +static void +sisDDDeleteTexture (GLcontext * ctx, struct gl_texture_object *tObj) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + + int i; + + for (i = 0; i < MAX_TEXTURE_LEVELS; i++) + { + if (tObj->Image[i]) + sisFreeTextureImage( smesa, tObj->Image[i] ); + } + + if (tObj->DriverData) + { + free (tObj->DriverData); + tObj->DriverData = NULL; + } + else + { + /* + * this shows the texture is default object and never be a + * argument of sis_TexImage + */ + } + + smesa->clearTexCache = GL_TRUE; +} + +static GLboolean sisDDIsTextureResident (GLcontext * ctx, struct gl_texture_object *t) +{ + return GL_TRUE; +} + +static void +sisDDUpdateTexturePalette (GLcontext * ctx, struct gl_texture_object *tObj) +{ + +} + +static void +sisDDActiveTexture (GLcontext * ctx, GLuint texUnitNumber) +{ +} + +void sisDDInitTextureFuncs( GLcontext *ctx ) +{ + ctx->Driver.TexEnv = sisDDTexEnv; + /*ctx->Driver.ChooseTextureFormat = r128ChooseTextureFormat; + ctx->Driver.TexImage1D = r128TexImage1D; + ctx->Driver.TexSubImage1D = r128TexSubImage1D; + ctx->Driver.TexImage2D = r128TexImage2D; + ctx->Driver.TexSubImage2D = r128TexSubImage2D;*/ + ctx->Driver.TexImage3D = _mesa_store_teximage3d; + ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; + ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d; + ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d; + ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d; + ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d; + ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d; + ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; + ctx->Driver.TexParameter = sisDDTexParameter; + ctx->Driver.BindTexture = sisDDBindTexture; + ctx->Driver.DeleteTexture = sisDDDeleteTexture; + ctx->Driver.UpdateTexturePalette = sisDDUpdateTexturePalette; + ctx->Driver.ActiveTexture = sisDDActiveTexture; + ctx->Driver.IsTextureResident = sisDDIsTextureResident; + ctx->Driver.PrioritizeTexture = NULL; +} diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_tex.h xc/lib/GL/mesa/src/drv/sis/sis_tex.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_tex.h Wed Dec 31 16:00:00 1969 +++ xc/lib/GL/mesa/src/drv/sis/sis_tex.h Tue Aug 19 16:58:21 2003 @@ -0,0 +1,44 @@ +/* $XFree86$ */ +/************************************************************************** + +Copyright 1999, 2000 ATI Technologies Inc. and Precision Insight, Inc., + Cedar Park, Texas. +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +on the rights to use, copy, modify, merge, publish, distribute, sub +license, and/or sell copies of the Software, and to permit persons to whom +the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ + +/* + * Authors: + * Gareth Hughes + * Kevin E. Martin + * + */ + +#ifndef __SIS_TEX_H__ +#define __SIS_TEX_H__ + +#ifdef GLX_DIRECT_RENDERING + +extern void sisDDInitTextureFuncs( GLcontext *ctx ); + +#endif /* GLX_DIRECT_RENDERING */ +#endif /* __SIS_TEX_H__ */ diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_texture.c xc/lib/GL/mesa/src/drv/sis/sis_texture.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_texture.c Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_texture.c Tue Aug 19 16:58:21 2003 @@ -32,7 +32,8 @@ * */ -#include "sis_ctx.h" +#include "sis_context.h" +#include "sis_alloc.h" #include "sis_mesa.h" static void @@ -46,13 +47,12 @@ static void sis_reset_texture_env (GLcontext * ctx, int hw_unit); -static DWORD TransferTexturePitch (DWORD dwPitch); +static GLint TransferTexturePitch (GLint dwPitch); void sis_validate_texture (GLcontext * ctx) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); struct gl_texture_unit *tex_unit; struct gl_texture_object *tObj; @@ -60,12 +60,12 @@ if(ctx->Texture.ReallyEnabled & (TEXTURE0_3D | TEXTURE1_3D)) { - hwcx->swRenderFlag |= SIS_SW_TEXTURE_DIM; + smesa->swRenderFlag |= SIS_SW_TEXTURE_DIM; return; } else { - hwcx->swRenderFlag &= ~SIS_SW_TEXTURE_DIM; + smesa->swRenderFlag &= ~SIS_SW_TEXTURE_DIM; } if ((ctx->Texture.ReallyEnabled & TEXTURE0_ANY) && @@ -79,22 +79,22 @@ tObj = tex_unit->Current; texObjArea = (sisTexobjInfo *) tObj->DriverData; - if (hwcx->TexStates[unit] & NEW_TEXTURING) + if (smesa->TexStates[unit] & NEW_TEXTURING) { - hwcx->swRenderFlag &= ~(SIS_SW_TEXTURE_OBJ << unit); + smesa->swRenderFlag &= ~(SIS_SW_TEXTURE_OBJ << unit); sis_set_texobj_parm (ctx, tObj, unit); } - if (hwcx->TexStates[unit] & NEW_TEXTURE_ENV) + if (smesa->TexStates[unit] & NEW_TEXTURE_ENV) { - hwcx->swRenderFlag &= ~(SIS_SW_TEXTURE_ENV << unit); + smesa->swRenderFlag &= ~(SIS_SW_TEXTURE_ENV << unit); if (unit == 0) sis_set_texture_env0 (ctx, tObj, unit); else sis_set_texture_env1 (ctx, tObj, unit); } - hwcx->TexStates[unit] = 0; + smesa->TexStates[unit] = 0; } } else @@ -105,10 +105,10 @@ tObj = tex_unit->Current; texObjArea = (sisTexobjInfo *) tObj->DriverData; - if (hwcx->TexStates[unit] & NEW_TEXTURING) + if (smesa->TexStates[unit] & NEW_TEXTURING) sis_set_texobj_parm (ctx, tObj, unit); - if (hwcx->TexStates[unit] & NEW_TEXTURE_ENV) + if (smesa->TexStates[unit] & NEW_TEXTURE_ENV) { if(unit == 0){ sis_set_texture_env0 (ctx, tObj, unit); @@ -120,27 +120,16 @@ } } - hwcx->TexStates[unit] = 0; + smesa->TexStates[unit] = 0; } } -void -sis_TexEnv( GLcontext *ctx, GLenum target, GLenum pname, - const GLfloat *param ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - hwcx->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURE_ENV; -} - void sis_TexImage (GLcontext * ctx, GLenum target, struct gl_texture_object *tObj, GLint level, GLint internalFormat, const struct gl_texture_image *image) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); SIStextureArea *area; @@ -174,7 +163,7 @@ | SIS_TEX_ENV); } - sis_alloc_texture_image (ctx, (struct gl_texture_image *) image); + sisAllocTextureImage( smesa, (struct gl_texture_image *) image ); area = (SIStextureArea *) image->DriverData; assert (area->Data); @@ -187,7 +176,7 @@ for (i = 0; i < area->Size / 4; i++) { - *(DWORD *)dst = *(DWORD *)src & 0x00ffffff; + *(GLint *)dst = *(GLint *)src & 0x00ffffff; src += 3; dst += 4; } @@ -197,12 +186,12 @@ memcpy (area->Data, image->Data, area->Size); } - if (hwcx->PrevTexFormat[ctx->Texture.CurrentUnit] != area->Format) + if (smesa->PrevTexFormat[ctx->Texture.CurrentUnit] != area->Format) { - hwcx->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURE_ENV; - hwcx->PrevTexFormat[ctx->Texture.CurrentUnit] = area->Format; + smesa->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURE_ENV; + smesa->PrevTexFormat[ctx->Texture.CurrentUnit] = area->Format; } - hwcx->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURING; + smesa->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURING; } void @@ -211,8 +200,7 @@ GLint yoffset, GLsizei width, GLsizei height, GLint internalFormat, const struct gl_texture_image *image) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); SIStextureArea *area; int i, j; @@ -221,13 +209,13 @@ area = (SIStextureArea *) image->DriverData; - hwcx->clearTexCache = GL_TRUE; + smesa->clearTexCache = GL_TRUE; { /* * Optimize */ - WaitEngIdle (hwcx); + WaitEngIdle (smesa); } if (area->Format == GL_RGB8) @@ -240,7 +228,7 @@ { for (i = xoffset; i < xoffset + width; i++) { - *(DWORD *)dst = *(DWORD *)src & 0x00ffffff; + *(GLint *)dst = *(GLint *)src & 0x00ffffff; src += 3; dst += 4; } @@ -268,107 +256,18 @@ } void -sis_TexParameter (GLcontext * ctx, GLenum target, - struct gl_texture_object *tObj, GLenum pname, const - GLfloat * params) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - if (tObj->DriverData) - ((sisTexobjInfo *) tObj->DriverData)->dirtyFlag |= SIS_TEX_PARAMETER; - - hwcx->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURING; -} - -void -sis_BindTexture (GLcontext * ctx, GLenum target, - struct gl_texture_object *tObj) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - SIStextureArea *area; - - if (!tObj->Image[0]) - return; - - if (!(area = (SIStextureArea *) tObj->Image[0]->DriverData)) - return; - - if (hwcx->PrevTexFormat[ctx->Texture.CurrentUnit] != area->Format) - { - hwcx->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURE_ENV; - hwcx->PrevTexFormat[ctx->Texture.CurrentUnit] = area->Format; - } - hwcx->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURING; -} - -void -sis_DeleteTexture (GLcontext * ctx, struct gl_texture_object *tObj) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - - int i; - - for (i = 0; i < MAX_TEXTURE_LEVELS; i++) - { - if (tObj->Image[i]) - sis_free_texture_image (tObj->Image[i]); - } - - if (tObj->DriverData) - { - free (tObj->DriverData); - tObj->DriverData = NULL; - } - else - { - /* - * this shows the texture is default object and never be a - * argument of sis_TexImage - */ - } - - hwcx->clearTexCache = GL_TRUE; -} - -void -sis_UpdateTexturePalette (GLcontext * ctx, struct gl_texture_object *tObj) -{ - -} - -void sis_UseGlobalTexturePalette (GLcontext * ctx, GLboolean state) { } -void -sis_ActiveTexture (GLcontext * ctx, GLuint texUnitNumber) -{ -} - -GLboolean sis_IsTextureResident (GLcontext * ctx, struct gl_texture_object *t) -{ - return GL_TRUE; -} - -void -sis_PrioritizeTexture (GLcontext * ctx, - struct gl_texture_object *t, GLclampf priority) -{ -} - static void sis_set_texture_env0 (GLcontext * ctx, GLtextureObject * object, int unit) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); - __GLSiSHardware *prev = &hwcx->prev; - __GLSiSHardware *current = &hwcx->current; + __GLSiSHardware *prev = &smesa->prev; + __GLSiSHardware *current = &smesa->current; struct gl_texture_unit *texture_unit = &ctx->Texture.Unit[unit]; @@ -440,10 +339,10 @@ case GL_BLEND: current->hwTexEnvColor = - ((DWORD) (texture_unit->EnvColor[3])) << 24 | - ((DWORD) (texture_unit->EnvColor[0])) << 16 | - ((DWORD) (texture_unit->EnvColor[1])) << 8 | - ((DWORD) (texture_unit->EnvColor[2])); + ((GLint) (texture_unit->EnvColor[3])) << 24 | + ((GLint) (texture_unit->EnvColor[0])) << 16 | + ((GLint) (texture_unit->EnvColor[1])) << 8 | + ((GLint) (texture_unit->EnvColor[2])); switch (area->Format) { case GL_ALPHA8: @@ -475,18 +374,17 @@ prev->hwTexEnvColor = current->hwTexEnvColor; prev->hwTexBlendClr0 = current->hwTexBlendClr0; prev->hwTexBlendAlpha0 = current->hwTexBlendAlpha0; - hwcx->GlobalFlag |= GFLAG_TEXTUREENV; + smesa->GlobalFlag |= GFLAG_TEXTUREENV; } } void sis_set_texture_env1 (GLcontext * ctx, GLtextureObject * object, int unit) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); - __GLSiSHardware *prev = &hwcx->prev; - __GLSiSHardware *current = &hwcx->current; + __GLSiSHardware *prev = &smesa->prev; + __GLSiSHardware *current = &smesa->current; struct gl_texture_unit *texture_unit = &ctx->Texture.Unit[unit]; GLtextureImage *image = object->Image[0]; @@ -558,10 +456,10 @@ case GL_BLEND: current->hwTexEnvColor = - ((DWORD) (texture_unit->EnvColor[3])) << 24 | - ((DWORD) (texture_unit->EnvColor[0])) << 16 | - ((DWORD) (texture_unit->EnvColor[1])) << 8 | - ((DWORD) (texture_unit->EnvColor[2])); + ((GLint) (texture_unit->EnvColor[3])) << 24 | + ((GLint) (texture_unit->EnvColor[0])) << 16 | + ((GLint) (texture_unit->EnvColor[1])) << 8 | + ((GLint) (texture_unit->EnvColor[2])); switch (area->Format) { case GL_ALPHA8: @@ -593,18 +491,17 @@ prev->hwTexBlendClr1 = current->hwTexBlendClr1; prev->hwTexBlendAlpha1 = current->hwTexBlendAlpha1; prev->hwTexEnvColor = current->hwTexEnvColor; - hwcx->GlobalFlag |= GFLAG_TEXTUREENV_1; + smesa->GlobalFlag |= GFLAG_TEXTUREENV_1; } } static void sis_set_texobj_parm (GLcontext * ctx, GLtextureObject * object, int hw_unit) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); - __GLSiSHardware *prev = &hwcx->prev; - __GLSiSHardware *current = &hwcx->current; + __GLSiSHardware *prev = &smesa->prev; + __GLSiSHardware *current = &smesa->current; GLtextureImage *image = object->Image[0]; SIStextureArea *area = (SIStextureArea *) image->DriverData; @@ -636,7 +533,7 @@ current->texture[hw_unit].hwTextureSet |= TEXEL_ABGR_0888_32; break; default: - hwcx->swRenderFlag |= SIS_SW_TEXTURE_OBJ; + smesa->swRenderFlag |= SIS_SW_TEXTURE_OBJ; } if ((object->MinFilter == GL_NEAREST) || (object->MinFilter == GL_LINEAR)) @@ -655,7 +552,7 @@ else { /* can i limit capacity */ - hwcx->swRenderFlag |= SIS_SW_TEXTURE_OBJ; + smesa->swRenderFlag |= SIS_SW_TEXTURE_OBJ; } switch (object->MagFilter) @@ -753,9 +650,9 @@ prev->texture[hw_unit].hwTextureBorderColor = current->texture[hw_unit].hwTextureBorderColor; if (hw_unit == 1) - hwcx->GlobalFlag |= GFLAG_TEXBORDERCOLOR_1; + smesa->GlobalFlag |= GFLAG_TEXBORDERCOLOR_1; else - hwcx->GlobalFlag |= GFLAG_TEXBORDERCOLOR; + smesa->GlobalFlag |= GFLAG_TEXBORDERCOLOR; } current->texture[hw_unit].hwTextureSet |= (image->WidthLog2 << 4); @@ -763,9 +660,9 @@ { if (hw_unit == 0) - hwcx->GlobalFlag |= GFLAG_TEXTUREADDRESS; + smesa->GlobalFlag |= GFLAG_TEXTUREADDRESS; else - hwcx->GlobalFlag |= GFLAG_TEXTUREADDRESS_1; + smesa->GlobalFlag |= GFLAG_TEXTUREADDRESS_1; for (i = 0; i < TxLevel + 1; i++) { @@ -775,11 +672,11 @@ switch(area->memType){ case VIDEO_TYPE: - texOffset = ((char *) area->Data - (char *) GET_FbBase (hwcx)); + texOffset = ((char *) area->Data - (char *) GET_FbBase (smesa)); break; case AGP_TYPE: - texOffset = ((char *) area->Data - (char *) GET_AGPBase (hwcx)) + - (unsigned long) hwcx->AGPAddr; + texOffset = ((char *) area->Data - (char *) GET_AGPBase (smesa)) + + (unsigned long) smesa->AGPAddr; current->texture[hw_unit].hwTextureMip |= (0x40000 << i); break; default: @@ -846,9 +743,9 @@ prev->texture[hw_unit].hwTextureSet = current->texture[hw_unit].hwTextureSet; if (hw_unit == 1) - hwcx->GlobalFlag |= CFLAG_TEXTURERESET_1; + smesa->GlobalFlag |= CFLAG_TEXTURERESET_1; else - hwcx->GlobalFlag |= CFLAG_TEXTURERESET; + smesa->GlobalFlag |= CFLAG_TEXTURERESET; } if (current->texture[hw_unit].hwTextureMip ^ prev->texture[hw_unit].hwTextureMip) @@ -856,20 +753,19 @@ prev->texture[hw_unit].hwTextureMip = current->texture[hw_unit].hwTextureMip; if (hw_unit == 1) - hwcx->GlobalFlag |= GFLAG_TEXTUREMIPMAP_1; + smesa->GlobalFlag |= GFLAG_TEXTUREMIPMAP_1; else - hwcx->GlobalFlag |= GFLAG_TEXTUREMIPMAP; + smesa->GlobalFlag |= GFLAG_TEXTUREMIPMAP; } } static void sis_reset_texture_env (GLcontext * ctx, int hw_unit) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); - __GLSiSHardware *prev = &hwcx->prev; - __GLSiSHardware *current = &hwcx->current; + __GLSiSHardware *prev = &smesa->prev; + __GLSiSHardware *current = &smesa->current; if (hw_unit == 1) { @@ -883,7 +779,7 @@ prev->hwTexBlendClr1 = current->hwTexBlendClr1; prev->hwTexBlendAlpha1 = current->hwTexBlendAlpha1; prev->hwTexEnvColor = current->hwTexEnvColor; - hwcx->GlobalFlag |= GFLAG_TEXTUREENV_1; + smesa->GlobalFlag |= GFLAG_TEXTUREENV_1; } } else @@ -898,15 +794,15 @@ prev->hwTexBlendClr0 = current->hwTexBlendClr0; prev->hwTexBlendAlpha0 = current->hwTexBlendAlpha0; prev->hwTexEnvColor = current->hwTexEnvColor; - hwcx->GlobalFlag |= GFLAG_TEXTUREENV; + smesa->GlobalFlag |= GFLAG_TEXTUREENV; } } } -static DWORD -BitScanForward (WORD w) +static GLint +BitScanForward (GLshort w) { - DWORD i; + GLint i; for (i = 0; i < 16; i++) { @@ -916,12 +812,12 @@ return (i); } -static DWORD -TransferTexturePitch (DWORD dwPitch) +static GLint +TransferTexturePitch (GLint dwPitch) { - DWORD dwRet, i; + GLint dwRet, i; - i = BitScanForward ((WORD) dwPitch); + i = BitScanForward ((GLshort) dwPitch); dwRet = dwPitch >> i; dwRet |= i << 9; return (dwRet); diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_trifunc.h xc/lib/GL/mesa/src/drv/sis/sis_trifunc.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_trifunc.h Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_trifunc.h Tue Aug 12 12:03:20 2003 @@ -39,10 +39,10 @@ GLuint pv) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); struct vertex_buffer *VB = ctx->VB; - float *MMIOBase = (float *) GET_IOBase (hwcx); + float *MMIOBase = (float *) GET_IOBase (smesa); STEREO_SAMPLE(v0); @@ -55,19 +55,19 @@ * not move it to UpdateState because maybe optimization can be done * according to FAN and STRIP */ - hwcx->dwPrimitiveSet &= ~0x07001f07; - hwcx->dwPrimitiveSet |= + smesa->dwPrimitiveSet &= ~0x07001f07; + smesa->dwPrimitiveSet |= (OP_3D_FIRE_TSARGBc | SHADE_GOURAUD | OP_3D_TRIANGLE_DRAW); } else { - hwcx->dwPrimitiveSet &= ~0x07001f07; - hwcx->dwPrimitiveSet |= + smesa->dwPrimitiveSet &= ~0x07001f07; + smesa->dwPrimitiveSet |= (OP_3D_FIRE_TSARGBc | SHADE_FLAT_VertexC | OP_3D_TRIANGLE_DRAW); } { - ((DWORD *) MMIOBase)[REG_3D_PrimitiveSet / 4] = hwcx->dwPrimitiveSet; + ((GLint *) MMIOBase)[REG_3D_PrimitiveSet / 4] = smesa->dwPrimitiveSet; } #define LAST_VERTEX 0 @@ -80,7 +80,7 @@ /* debug mEndPrimitive (); - WaitEngIdle(hwcx); + WaitEngIdle(smesa); d2f_once (ctx); */ } @@ -90,17 +90,17 @@ GLuint v2, GLuint pv) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); struct vertex_buffer *VB = ctx->VB; - DWORD dcSARGB; + GLint dcSARGB; STEREO_SAMPLE(v0); /* delete if VB size <= AGP_ALLOC_SIZE */ #if 0 - if ((DWORD) AGP_CurrentPtr - (DWORD) AGP_StartPtr >= (AGP_ALLOC_SIZE - 0x10)) + if ((GLint) AGP_CurrentPtr - (GLint) AGP_StartPtr >= (AGP_ALLOC_SIZE - 0x10)) { sis_FlushAGP (ctx); sis_StartAGP (ctx); diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_tris.c xc/lib/GL/mesa/src/drv/sis/sis_tris.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_tris.c Wed Dec 31 16:00:00 1969 +++ xc/lib/GL/mesa/src/drv/sis/sis_tris.c Fri Aug 22 15:33:20 2003 @@ -0,0 +1,737 @@ +/* $XFree86: xc/lib/GL/mesa/src/drv/r128/r128_tris.c,v 1.8 2002/10/30 12:51:43 alanh Exp $ */ /* -*- c-basic-offset: 3 -*- */ +/************************************************************************** + +Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and + VA Linux Systems Inc., Fremont, California. + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +on the rights to use, copy, modify, merge, publish, distribute, sub +license, and/or sell copies of the Software, and to permit persons to whom +the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +ATI, VA LINUX SYSTEMS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ + +/* + * Authors: + * Keith Whitwell + * + */ + +#include "glheader.h" +#include "mtypes.h" +#include "colormac.h" +#include "macros.h" + +#include "swrast/swrast.h" +#include "swrast_setup/swrast_setup.h" +#include "tnl/tnl.h" +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" + +#include "sis_tris.h" +#include "sis_state.h" +#include "sis_vb.h" +#include "sis_lock.h" + +static const GLuint hw_prim[GL_POLYGON+1] = { + OP_3D_POINT_DRAW, /* GL_POINTS */ + OP_3D_LINE_DRAW, /* GL_LINES */ + OP_3D_LINE_DRAW, /* GL_LINE_LOOP */ + OP_3D_LINE_DRAW, /* GL_LINE_STRIP */ + OP_3D_TRIANGLE_DRAW, /* GL_TRIANGLES */ + OP_3D_TRIANGLE_DRAW, /* GL_TRIANGLE_STRIP */ + OP_3D_TRIANGLE_DRAW, /* GL_TRIANGLE_FAN */ + OP_3D_TRIANGLE_DRAW, /* GL_QUADS */ + OP_3D_TRIANGLE_DRAW, /* GL_QUAD_STRIP */ + OP_3D_TRIANGLE_DRAW /* GL_POLYGON */ +}; + +static const GLuint hw_prim_fire[OP_3D_TRIANGLE_DRAW+1] = { + OP_3D_FIRE_TSARGBa, + OP_3D_FIRE_TSARGBb, + OP_3D_FIRE_TSARGBc +}; + +static const GLuint hw_prim_shade_flat[OP_3D_TRIANGLE_DRAW+1] = { + SHADE_FLAT_VertexA, + SHADE_FLAT_VertexB, + SHADE_FLAT_VertexC +}; + +static void sisRasterPrimitive( GLcontext *ctx, GLenum prim, GLuint hwprim ); +static void sisRenderPrimitive( GLcontext *ctx, GLenum prim ); + + +/*********************************************************************** + * Emit primitives as inline vertices * + ***********************************************************************/ + +#define SIS_MMIO_WRITE_VERTEX(_v, i, lastvert) \ +do { \ + MMIOBase[(REG_3D_TSXa+(i)*0x30)/4] = _v->v.x; \ + MMIOBase[(REG_3D_TSYa+(i)*0x30)/4] = _v->v.y; \ + MMIOBase[(REG_3D_TSZa+(i)*0x30)/4] = _v->v.z; \ + MMIOBase[(REG_3D_TSWGa+(i)*0x30)/4] = _v->v.w; \ + /* the ARGB write of the last vertex of the primitive fired the 3d engine*/ \ + ((GLint *) MMIOBase)[(REG_3D_TSARGBa+(i)*0x30)/4] = _v->ui[4]; \ +} while (0); + +#define MMIO_VERT_REG_COUNT 5 + +static __inline void sis_draw_quad_mmio( sisContextPtr smesa, + sisVertexPtr v0, + sisVertexPtr v1, + sisVertexPtr v2, + sisVertexPtr v3 ) +{ + float *MMIOBase = (float *)GET_IOBase (smesa); + + mWait3DCmdQueue (MMIO_VERT_REG_COUNT * 6 + 1); + ((GLint *) MMIOBase)[REG_3D_PrimitiveSet / 4] = smesa->dwPrimitiveSet; + SIS_MMIO_WRITE_VERTEX(v0, 0, 0); + SIS_MMIO_WRITE_VERTEX(v1, 1, 0); + SIS_MMIO_WRITE_VERTEX(v3, 2, 1); + SIS_MMIO_WRITE_VERTEX(v1, 0, 0); + SIS_MMIO_WRITE_VERTEX(v2, 1, 0); + SIS_MMIO_WRITE_VERTEX(v3, 2, 1); +} + + +static __inline void sis_draw_triangle_mmio( sisContextPtr smesa, + sisVertexPtr v0, + sisVertexPtr v1, + sisVertexPtr v2 ) +{ + float *MMIOBase = (float *)GET_IOBase (smesa); + + mWait3DCmdQueue (MMIO_VERT_REG_COUNT * 3 + 1); + ((GLint *) MMIOBase)[REG_3D_PrimitiveSet / 4] = smesa->dwPrimitiveSet; + SIS_MMIO_WRITE_VERTEX(v0, 0, 0); + SIS_MMIO_WRITE_VERTEX(v1, 1, 0); + SIS_MMIO_WRITE_VERTEX(v2, 2, 1); +} + +static __inline void sis_draw_line_mmio( sisContextPtr smesa, + sisVertexPtr v0, + sisVertexPtr v1 ) +{ + float *MMIOBase = (float *)GET_IOBase (smesa); + + mWait3DCmdQueue (MMIO_VERT_REG_COUNT * 2 + 1); + ((GLint *) MMIOBase)[REG_3D_PrimitiveSet / 4] = smesa->dwPrimitiveSet; + SIS_MMIO_WRITE_VERTEX(v0, 0, 0); + SIS_MMIO_WRITE_VERTEX(v1, 1, 1); +} + +static __inline void sis_draw_point_mmio( sisContextPtr smesa, + sisVertexPtr v0 ) +{ + float *MMIOBase = (float *)GET_IOBase (smesa); + + mWait3DCmdQueue (MMIO_VERT_REG_COUNT * 1 + 1); + ((GLint *) MMIOBase)[REG_3D_PrimitiveSet / 4] = smesa->dwPrimitiveSet; + SIS_MMIO_WRITE_VERTEX(v0, 1, 1); +} + +/*********************************************************************** + * Macros for t_dd_tritmp.h to draw basic primitives * + ***********************************************************************/ + +#define TRI( a, b, c ) \ +do { \ + if (DO_FALLBACK) \ + smesa->draw_tri( smesa, a, b, c ); \ + else \ + sis_draw_triangle_mmio( smesa, a, b, c ); \ +} while (0) + +#define QUAD( a, b, c, d ) \ +do { \ + if (DO_FALLBACK) { \ + smesa->draw_tri( smesa, a, b, d ); \ + smesa->draw_tri( smesa, b, c, d ); \ + } else \ + sis_draw_quad_mmio( smesa, a, b, c, d ); \ +} while (0) + +#define LINE( v0, v1 ) \ +do { \ + if (DO_FALLBACK) \ + smesa->draw_line( smesa, v0, v1 ); \ + else \ + sis_draw_line_mmio( smesa, v0, v1 ); \ +} while (0) + +#define POINT( v0 ) \ +do { \ + if (DO_FALLBACK) \ + smesa->draw_point( smesa, v0 ); \ + else \ + sis_draw_point_mmio( smesa, v0 ); \ +} while (0) + + +/*********************************************************************** + * Build render functions from dd templates * + ***********************************************************************/ + +#define SIS_OFFSET_BIT 0x01 +#define SIS_TWOSIDE_BIT 0x02 +#define SIS_UNFILLED_BIT 0x04 +#define SIS_FALLBACK_BIT 0x08 +#define SIS_MAX_TRIFUNC 0x10 + + +static struct { + points_func points; + line_func line; + triangle_func triangle; + quad_func quad; +} rast_tab[SIS_MAX_TRIFUNC]; + + +#define DO_FALLBACK (IND & SIS_FALLBACK_BIT) +#define DO_OFFSET (IND & SIS_OFFSET_BIT) +#define DO_UNFILLED (IND & SIS_UNFILLED_BIT) +#define DO_TWOSIDE (IND & SIS_TWOSIDE_BIT) +#define DO_FLAT 0 +#define DO_TRI 1 +#define DO_QUAD 1 +#define DO_LINE 1 +#define DO_POINTS 1 +#define DO_FULL_QUAD 1 + +#define HAVE_RGBA 1 +#define HAVE_SPEC 1 +#define HAVE_BACK_COLORS 0 +#define HAVE_HW_FLATSHADE 1 +#define VERTEX sisVertex +#define TAB rast_tab + +#define DEPTH_SCALE 1.0 +#define UNFILLED_TRI unfilled_tri +#define UNFILLED_QUAD unfilled_quad +#define VERT_X(_v) _v->v.x +#define VERT_Y(_v) _v->v.y +#define VERT_Z(_v) _v->v.z +#define AREA_IS_CCW( a ) (a > 0) +#define GET_VERTEX(e) (smesa->verts + (e << smesa->vertex_stride_shift)) + +#define VERT_SET_RGBA( v, c ) \ + do { \ + sis_color_t *vc = (sis_color_t *)&(v)->ui[coloroffset]; \ + vc->blue = (c)[2]; \ + vc->green = (c)[1]; \ + vc->red = (c)[0]; \ + vc->alpha = (c)[3]; \ + } while (0) +#define VERT_COPY_RGBA( v0, v1 ) v0->ui[coloroffset] = v1->ui[coloroffset] +#define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[coloroffset] +#define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx] + +#define VERT_SET_SPEC( v0, c ) \ + if (havespec) { \ + (v0)->v.specular.red = (c)[0]; \ + (v0)->v.specular.green = (c)[1]; \ + (v0)->v.specular.blue = (c)[2]; \ + } +#define VERT_COPY_SPEC( v0, v1 ) \ + if (havespec) { \ + (v0)->v.specular.red = v1->v.specular.red; \ + (v0)->v.specular.green = v1->v.specular.green; \ + (v0)->v.specular.blue = v1->v.specular.blue; \ + } + +#define VERT_SAVE_SPEC( idx ) if (havespec) spec[idx] = v[idx]->ui[5] +#define VERT_RESTORE_SPEC( idx ) if (havespec) v[idx]->ui[5] = spec[idx] + +#define LOCAL_VARS(n) \ + sisContextPtr smesa = SIS_CONTEXT(ctx); \ + GLuint color[n], spec[n]; \ + GLuint coloroffset = (smesa->vertex_size == 4 ? 3 : 4); \ + GLboolean havespec = (smesa->vertex_size == 4 ? 0 : 1); \ + (void) color; (void) spec; (void) coloroffset; (void) havespec; + +/*********************************************************************** + * Helpers for rendering unfilled primitives * + ***********************************************************************/ + +#define RASTERIZE(x) if (smesa->raster_primitive != x) \ + sisRasterPrimitive( ctx, x, hw_prim[x] ) +#define RENDER_PRIMITIVE smesa->render_primitive +#define IND SIS_FALLBACK_BIT +#define TAG(x) x +#include "tnl_dd/t_dd_unfilled.h" +#undef IND + + +/*********************************************************************** + * Generate GL render functions * + ***********************************************************************/ + + +#define IND (0) +#define TAG(x) x +#include "tnl_dd/t_dd_tritmp.h" + +#define IND (SIS_OFFSET_BIT) +#define TAG(x) x##_offset +#include "tnl_dd/t_dd_tritmp.h" + +#define IND (SIS_TWOSIDE_BIT) +#define TAG(x) x##_twoside +#include "tnl_dd/t_dd_tritmp.h" + +#define IND (SIS_TWOSIDE_BIT | SIS_OFFSET_BIT) +#define TAG(x) x##_twoside_offset +#include "tnl_dd/t_dd_tritmp.h" + +#define IND (SIS_UNFILLED_BIT) +#define TAG(x) x##_unfilled +#include "tnl_dd/t_dd_tritmp.h" + +#define IND (SIS_OFFSET_BIT | SIS_UNFILLED_BIT) +#define TAG(x) x##_offset_unfilled +#include "tnl_dd/t_dd_tritmp.h" + +#define IND (SIS_TWOSIDE_BIT | SIS_UNFILLED_BIT) +#define TAG(x) x##_twoside_unfilled +#include "tnl_dd/t_dd_tritmp.h" + +#define IND (SIS_TWOSIDE_BIT | SIS_OFFSET_BIT | SIS_UNFILLED_BIT) +#define TAG(x) x##_twoside_offset_unfilled +#include "tnl_dd/t_dd_tritmp.h" + +#define IND (SIS_FALLBACK_BIT) +#define TAG(x) x##_fallback +#include "tnl_dd/t_dd_tritmp.h" + +#define IND (SIS_OFFSET_BIT | SIS_FALLBACK_BIT) +#define TAG(x) x##_offset_fallback +#include "tnl_dd/t_dd_tritmp.h" + +#define IND (SIS_TWOSIDE_BIT | SIS_FALLBACK_BIT) +#define TAG(x) x##_twoside_fallback +#include "tnl_dd/t_dd_tritmp.h" + +#define IND (SIS_TWOSIDE_BIT | SIS_OFFSET_BIT | SIS_FALLBACK_BIT) +#define TAG(x) x##_twoside_offset_fallback +#include "tnl_dd/t_dd_tritmp.h" + +#define IND (SIS_UNFILLED_BIT | SIS_FALLBACK_BIT) +#define TAG(x) x##_unfilled_fallback +#include "tnl_dd/t_dd_tritmp.h" + +#define IND (SIS_OFFSET_BIT | SIS_UNFILLED_BIT | SIS_FALLBACK_BIT) +#define TAG(x) x##_offset_unfilled_fallback +#include "tnl_dd/t_dd_tritmp.h" + +#define IND (SIS_TWOSIDE_BIT | SIS_UNFILLED_BIT | SIS_FALLBACK_BIT) +#define TAG(x) x##_twoside_unfilled_fallback +#include "tnl_dd/t_dd_tritmp.h" + +#define IND (SIS_TWOSIDE_BIT | SIS_OFFSET_BIT | SIS_UNFILLED_BIT | \ + SIS_FALLBACK_BIT) +#define TAG(x) x##_twoside_offset_unfilled_fallback +#include "tnl_dd/t_dd_tritmp.h" + + +static void init_rast_tab( void ) +{ + init(); + init_offset(); + init_twoside(); + init_twoside_offset(); + init_unfilled(); + init_offset_unfilled(); + init_twoside_unfilled(); + init_twoside_offset_unfilled(); + init_fallback(); + init_offset_fallback(); + init_twoside_fallback(); + init_twoside_offset_fallback(); + init_unfilled_fallback(); + init_offset_unfilled_fallback(); + init_twoside_unfilled_fallback(); + init_twoside_offset_unfilled_fallback(); +} + + + +/*********************************************************************** + * Rasterization fallback helpers * + ***********************************************************************/ + + +/* This code is hit only when a mix of accelerated and unaccelerated + * primitives are being drawn, and only for the unaccelerated + * primitives. + */ +static void +sis_fallback_tri( sisContextPtr smesa, + sisVertex *v0, + sisVertex *v1, + sisVertex *v2 ) +{ + GLcontext *ctx = smesa->glCtx; + SWvertex v[3]; + sis_translate_vertex( ctx, v0, &v[0] ); + sis_translate_vertex( ctx, v1, &v[1] ); + sis_translate_vertex( ctx, v2, &v[2] ); + _swrast_Triangle( ctx, &v[0], &v[1], &v[2] ); +} + + +static void +sis_fallback_line( sisContextPtr smesa, + sisVertex *v0, + sisVertex *v1 ) +{ + GLcontext *ctx = smesa->glCtx; + SWvertex v[2]; + sis_translate_vertex( ctx, v0, &v[0] ); + sis_translate_vertex( ctx, v1, &v[1] ); + _swrast_Line( ctx, &v[0], &v[1] ); +} + + +static void +sis_fallback_point( sisContextPtr smesa, + sisVertex *v0 ) +{ + GLcontext *ctx = smesa->glCtx; + SWvertex v[1]; + sis_translate_vertex( ctx, v0, &v[0] ); + _swrast_Point( ctx, &v[0] ); +} + + + +/**********************************************************************/ +/* Render unclipped begin/end objects */ +/**********************************************************************/ + +#define VERT(x) (sisVertex *)(sisverts + (x << shift)) +#define RENDER_POINTS( start, count ) \ + for ( ; start < count ; start++) \ + sis_draw_point_mmio( smesa, VERT(start) ) +#define RENDER_LINE( v0, v1 ) \ + sis_draw_line_mmio( smesa, VERT(v0), VERT(v1) ) +#define RENDER_TRI( v0, v1, v2 ) \ + sis_draw_triangle_mmio( smesa, VERT(v0), VERT(v1), VERT(v2) ) +#define RENDER_QUAD( v0, v1, v2, v3 ) \ + sis_draw_quad_mmio( smesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) ) +#define INIT(x) do { \ + if (0) \ + fprintf(stderr, "%s\n", __FUNCTION__); \ + sisRenderPrimitive( ctx, x ); \ +} while (0) +#undef LOCAL_VARS +#define LOCAL_VARS \ + sisContextPtr smesa = SIS_CONTEXT(ctx); \ + const GLuint shift = smesa->vertex_stride_shift; \ + const char *sisverts = (char *)smesa->verts; \ + const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \ + (void) elt; +#define RESET_STIPPLE +#define RESET_OCCLUSION +#define PRESERVE_VB_DEFS +#define ELT(x) (x) +#define TAG(x) sis_##x##_verts +#include "tnl/t_vb_rendertmp.h" +#undef ELT +#undef TAG +#define TAG(x) sis_##x##_elts +#define ELT(x) elt[x] +#include "tnl/t_vb_rendertmp.h" + + +/**********************************************************************/ +/* Render clipped primitives */ +/**********************************************************************/ + +static void sisRenderClippedPoly( GLcontext *ctx, const GLuint *elts, GLuint n ) +{ + TNLcontext *tnl = TNL_CONTEXT(ctx); + struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; + + /* Render the new vertices as an unclipped polygon. + */ + { + GLuint *tmp = VB->Elts; + VB->Elts = (GLuint *)elts; + tnl->Driver.Render.PrimTabElts[GL_POLYGON]( ctx, 0, n, PRIM_BEGIN|PRIM_END ); + VB->Elts = tmp; + } +} + +static void sisRenderClippedLine( GLcontext *ctx, GLuint ii, GLuint jj ) +{ + TNLcontext *tnl = TNL_CONTEXT(ctx); + tnl->Driver.Render.Line( ctx, ii, jj ); +} + +#if 0 +static void sisFastRenderClippedPoly( GLcontext *ctx, const GLuint *elts, + GLuint n ) +{ + sisContextPtr smesa = SIS_CONTEXT( ctx ); + GLuint vertsize = smesa->vertex_size; + GLuint *vb = r128AllocDmaLow( rmesa, (n-2) * 3 * 4 * vertsize ); + GLubyte *sisverts = (GLubyte *)smesa->verts; + const GLuint shift = smesa->vertex_stride_shift; + const GLuint *start = (const GLuint *)VERT(elts[0]); + int i,j; + + smesa->num_verts += (n-2) * 3; + + for (i = 2 ; i < n ; i++) { + COPY_DWORDS( j, vb, vertsize, (sisVertexPtr) VERT(elts[i-1]) ); + COPY_DWORDS( j, vb, vertsize, (sisVertexPtr) VERT(elts[i]) ); + COPY_DWORDS( j, vb, vertsize, (sisVertexPtr) start ); + } +} +#endif + + + + +/**********************************************************************/ +/* Choose render functions */ +/**********************************************************************/ + +/* XXX */ +#define _SIS_NEW_RENDER_STATE (_DD_NEW_LINE_STIPPLE | \ + _DD_NEW_LINE_SMOOTH | \ + _DD_NEW_POINT_SMOOTH | \ + _DD_NEW_TRI_SMOOTH | \ + _DD_NEW_TRI_UNFILLED | \ + _DD_NEW_TRI_LIGHT_TWOSIDE | \ + _DD_NEW_TRI_OFFSET) \ + + +#define POINT_FALLBACK (DD_POINT_SMOOTH) +#define LINE_FALLBACK (DD_LINE_STIPPLE|DD_LINE_SMOOTH) +#define TRI_FALLBACK (DD_TRI_SMOOTH) +#define ANY_FALLBACK_FLAGS (POINT_FALLBACK|LINE_FALLBACK|TRI_FALLBACK) +#define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE|DD_TRI_OFFSET|DD_TRI_UNFILLED) + + +static void sisChooseRenderState(GLcontext *ctx) +{ + sisContextPtr smesa = SIS_CONTEXT( ctx ); + GLuint flags = ctx->_TriangleCaps; + GLuint index = 0; + + if (flags & (ANY_RASTER_FLAGS|ANY_FALLBACK_FLAGS)) { + smesa->draw_point = sis_draw_point_mmio; + smesa->draw_line = sis_draw_line_mmio; + smesa->draw_tri = sis_draw_triangle_mmio; + + if (flags & ANY_RASTER_FLAGS) { + if (flags & DD_TRI_LIGHT_TWOSIDE) index |= SIS_TWOSIDE_BIT; + if (flags & DD_TRI_OFFSET) index |= SIS_OFFSET_BIT; + if (flags & DD_TRI_UNFILLED) index |= SIS_UNFILLED_BIT; + } + + /* Hook in fallbacks for specific primitives. + */ + if (flags & (POINT_FALLBACK|LINE_FALLBACK|TRI_FALLBACK)) { + if (flags & POINT_FALLBACK) smesa->draw_point = sis_fallback_point; + if (flags & LINE_FALLBACK) smesa->draw_line = sis_fallback_line; + if (flags & TRI_FALLBACK) smesa->draw_tri = sis_fallback_tri; + index |= SIS_FALLBACK_BIT; + } + } + + if (index != smesa->RenderIndex) { + TNLcontext *tnl = TNL_CONTEXT(ctx); + tnl->Driver.Render.Points = rast_tab[index].points; + tnl->Driver.Render.Line = rast_tab[index].line; + tnl->Driver.Render.Triangle = rast_tab[index].triangle; + tnl->Driver.Render.Quad = rast_tab[index].quad; + + if (index == 0) { + tnl->Driver.Render.PrimTabVerts = sis_render_tab_verts; + tnl->Driver.Render.PrimTabElts = sis_render_tab_elts; + tnl->Driver.Render.ClippedLine = rast_tab[index].line; + /*XXX: sisFastRenderClippedPoly*/ + tnl->Driver.Render.ClippedPolygon = sisRenderClippedPoly; + } else { + tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts; + tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts; + tnl->Driver.Render.ClippedLine = sisRenderClippedLine; + tnl->Driver.Render.ClippedPolygon = sisRenderClippedPoly; + } + + smesa->RenderIndex = index; + } +} + +/**********************************************************************/ +/* Validate state at pipeline start */ +/**********************************************************************/ + +static void sisRunPipeline( GLcontext *ctx ) +{ + sisContextPtr smesa = SIS_CONTEXT( ctx ); + + if (1 /*smesa->new_state || smesa->NewGLState & _NEW_TEXTURE*/) { /* XXX */ + sis_update_render_state( smesa ); /* XXX */ + sis_update_texture_state( smesa ); + } + + if (!smesa->Fallback && smesa->NewGLState) { + if (smesa->NewGLState & _SIS_NEW_VERTEX_STATE) + sisChooseVertexState( ctx ); + + if (smesa->NewGLState & _SIS_NEW_RENDER_STATE) + sisChooseRenderState( ctx ); + + smesa->NewGLState = 0; + } + + _tnl_run_pipeline( ctx ); +} + +/**********************************************************************/ +/* High level hooks for t_vb_render.c */ +/**********************************************************************/ + +/* This is called when Mesa switches between rendering triangle + * primitives (such as GL_POLYGON, GL_QUADS, GL_TRIANGLE_STRIP, etc), + * and lines, points and bitmaps. + * + * As the r128 uses triangles to render lines and points, it is + * necessary to turn off hardware culling when rendering these + * primitives. XXX + */ + +static void sisRasterPrimitive( GLcontext *ctx, GLenum prim, GLuint hwprim ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + + if (smesa->hw_primitive != hwprim) { + mEndPrimitive(); + smesa->dwPrimitiveSet &= ~(MASK_DrawPrimitiveCommand | + MASK_SetFirePosition | MASK_ShadingMode); + if (ctx->Polygon.SmoothFlag) + smesa->dwPrimitiveSet |= SHADE_GOURAUD; + else + smesa->dwPrimitiveSet |= hw_prim_shade_flat[hwprim]; + smesa->dwPrimitiveSet |= hwprim | hw_prim_fire[hwprim]; + } + smesa->raster_primitive = prim; + smesa->hw_primitive = hwprim; +} + +static void sisRenderPrimitive( GLcontext *ctx, GLenum prim ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + + smesa->render_primitive = prim; + if (prim >= GL_TRIANGLES && (ctx->_TriangleCaps & DD_TRI_UNFILLED)) + return; + sisRasterPrimitive( ctx, prim, hw_prim[prim] ); +} + + +static void sisRenderStart( GLcontext *ctx ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + + /* Check for projective texturing. Make sure all texcoord + * pointers point to something. (fix in mesa?) + */ + sisCheckTexSizes( ctx ); + LOCK_HARDWARE(); +} + +static void sisRenderFinish( GLcontext *ctx ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + + if (SIS_CONTEXT(ctx)->RenderIndex & SIS_FALLBACK_BIT) + _swrast_flush( ctx ); + mEndPrimitive(); + UNLOCK_HARDWARE(); +} + + +/**********************************************************************/ +/* Transition to/from hardware rasterization. */ +/**********************************************************************/ + +void sisFallback( GLcontext *ctx, GLuint bit, GLboolean mode ) +{ + TNLcontext *tnl = TNL_CONTEXT(ctx); + sisContextPtr smesa = SIS_CONTEXT(ctx); + GLuint oldfallback = smesa->Fallback; + + if (mode) { + smesa->Fallback |= bit; + if (oldfallback == 0) { + _swsetup_Wakeup( ctx ); + smesa->RenderIndex = ~0; + printf("software!\n"); + } + } + else { + smesa->Fallback &= ~bit; + if (oldfallback == bit) { + _swrast_flush( ctx ); + tnl->Driver.Render.Start = sisRenderStart; + tnl->Driver.Render.PrimitiveNotify = sisRenderPrimitive; + tnl->Driver.Render.Finish = sisRenderFinish; + tnl->Driver.Render.BuildVertices = sisBuildVertices; + smesa->NewGLState |= (_SIS_NEW_RENDER_STATE| + _SIS_NEW_VERTEX_STATE); + } + printf("hardware!\n"); + } +} + + +/**********************************************************************/ +/* Initialization. */ +/**********************************************************************/ + +void sisInitTriFuncs( GLcontext *ctx ) +{ + sisContextPtr smesa = SIS_CONTEXT(ctx); + TNLcontext *tnl = TNL_CONTEXT(ctx); + static int firsttime = 1; + + if (firsttime) { + init_rast_tab(); + firsttime = 0; + } + + tnl->Driver.RunPipeline = sisRunPipeline; + tnl->Driver.Render.Start = sisRenderStart; + tnl->Driver.Render.Finish = sisRenderFinish; + tnl->Driver.Render.PrimitiveNotify = sisRenderPrimitive; + tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple; + tnl->Driver.Render.BuildVertices = sisBuildVertices; + + sisFallback(ctx, SIS_FALLBACK_FORCE, 0); + smesa->RenderIndex = ~0; + smesa->NewGLState |= (_SIS_NEW_RENDER_STATE| + _SIS_NEW_VERTEX_STATE); +} diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_tris.h xc/lib/GL/mesa/src/drv/sis/sis_tris.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_tris.h Wed Dec 31 16:00:00 1969 +++ xc/lib/GL/mesa/src/drv/sis/sis_tris.h Tue Aug 12 12:03:20 2003 @@ -0,0 +1,48 @@ +/* $XFree86: xc/lib/GL/mesa/src/drv/r128/r128_tris.h,v 1.8 2002/10/30 12:51:43 alanh Exp $ */ +/************************************************************************** + +Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and + VA Linux Systems Inc., Fremont, California. + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +on the rights to use, copy, modify, merge, publish, distribute, sub +license, and/or sell copies of the Software, and to permit persons to whom +the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +ATI, VA LINUX SYSTEMS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ + +/* + * Authors: + * Keith Whitwell + * + */ + +#ifndef __SIS_TRIS_H__ +#define __SIS_TRIS_H__ + +#include "mtypes.h" + +extern void sisInitTriFuncs( GLcontext *ctx ); + + +extern void sisFallback( GLcontext *ctx, GLuint bit, GLboolean mode ); +#define FALLBACK( smesa, bit, mode ) sisFallback( smesa->glCtx, bit, mode ) + + +#endif /* __SIS_TRIS_H__ */ diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_vb.c xc/lib/GL/mesa/src/drv/sis/sis_vb.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_vb.c Wed Dec 31 16:00:00 1969 +++ xc/lib/GL/mesa/src/drv/sis/sis_vb.c Fri Aug 22 15:33:20 2003 @@ -0,0 +1,484 @@ +/* $XFree86$ */ +/************************************************************************** + +Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and + VA Linux Systems Inc., Fremont, California. + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +on the rights to use, copy, modify, merge, publish, distribute, sub +license, and/or sell copies of the Software, and to permit persons to whom +the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +ATI, VA LINUX SYSTEMS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ + +/* + * Authors: + * Keith Whitwell + * + */ + +#include "glheader.h" +#include "mtypes.h" +#include "imports.h" +#include "macros.h" +#include "colormac.h" + +#include "swrast_setup/swrast_setup.h" +#include "tnl/t_context.h" + +#include "sis_context.h" +#include "sis_vb.h" +#include "sis_tris.h" +#include "sis_state.h" + + +#define SIS_TEX1_BIT 0x1 +#define SIS_TEX0_BIT 0x2 +#define SIS_RGBA_BIT 0x4 +#define SIS_SPEC_BIT 0x8 +#define SIS_FOG_BIT 0x10 +#define SIS_XYZW_BIT 0x20 +#define SIS_PTEX_BIT 0x40 +#define SIS_MAX_SETUP 0x80 + +static struct { + void (*emit)( GLcontext *, GLuint, GLuint, void *, GLuint ); + interp_func interp; + copy_pv_func copy_pv; + GLboolean (*check_tex_sizes)( GLcontext *ctx ); + GLuint vertex_size; + GLuint vertex_stride_shift; + GLuint vertex_format; +} setup_tab[SIS_MAX_SETUP]; +/* +#define TINY_VERTEX_FORMAT (R128_CCE_VC_FRMT_DIFFUSE_ARGB) + +#define NOTEX_VERTEX_FORMAT (R128_CCE_VC_FRMT_RHW | \ + R128_CCE_VC_FRMT_DIFFUSE_ARGB |\ + R128_CCE_VC_FRMT_SPEC_FRGB) + +#define TEX0_VERTEX_FORMAT (R128_CCE_VC_FRMT_RHW | \ + R128_CCE_VC_FRMT_DIFFUSE_ARGB |\ + R128_CCE_VC_FRMT_SPEC_FRGB | \ + R128_CCE_VC_FRMT_S_T) + +#define TEX1_VERTEX_FORMAT (R128_CCE_VC_FRMT_RHW | \ + R128_CCE_VC_FRMT_DIFFUSE_ARGB |\ + R128_CCE_VC_FRMT_SPEC_FRGB | \ + R128_CCE_VC_FRMT_S_T | \ + R128_CCE_VC_FRMT_S2_T2) +*/ +#define TEX0_VERTEX_FORMAT 1 +#define TEX1_VERTEX_FORMAT 2 + +#define TINY_VERTEX_FORMAT 0 +#define NOTEX_VERTEX_FORMAT 0 +#define PROJ_TEX1_VERTEX_FORMAT 0 +#define TEX2_VERTEX_FORMAT 0 +#define TEX3_VERTEX_FORMAT 0 +#define PROJ_TEX3_VERTEX_FORMAT 0 + +#define DO_XYZW (IND & SIS_XYZW_BIT) +#define DO_RGBA (IND & SIS_RGBA_BIT) +#define DO_SPEC (IND & SIS_SPEC_BIT) +#define DO_FOG (IND & SIS_FOG_BIT) +#define DO_TEX0 (IND & SIS_TEX0_BIT) +#define DO_TEX1 (IND & SIS_TEX1_BIT) +#define DO_TEX2 0 +#define DO_TEX3 0 +#define DO_PTEX (IND & SIS_PTEX_BIT) + +#define VERTEX sisVertex +#define VERTEX_COLOR sis_color_t +#define LOCALVARS sisContextPtr smesa = SIS_CONTEXT(ctx); +#define GET_VIEWPORT_MAT() smesa->hw_viewport +#define GET_TEXSOURCE(n) n +#define GET_VERTEX_FORMAT() smesa->vertex_format +#define GET_VERTEX_STORE() smesa->verts +#define GET_VERTEX_STRIDE_SHIFT() smesa->vertex_stride_shift +#define GET_UBYTE_COLOR_STORE() &smesa->UbyteColor +#define GET_UBYTE_SPEC_COLOR_STORE() &smesa->UbyteSecondaryColor + +#define HAVE_HW_VIEWPORT 0 +#define HAVE_HW_DIVIDE 0 +#define HAVE_RGBA_COLOR 0 +#define HAVE_TINY_VERTICES 0 /* XXX */ +#define HAVE_NOTEX_VERTICES 0 /* XXX */ +#define HAVE_TEX0_VERTICES 1 +#define HAVE_TEX1_VERTICES 1 +#define HAVE_TEX2_VERTICES 0 +#define HAVE_TEX3_VERTICES 0 +#define HAVE_PTEX_VERTICES 0 /* r128 rhw2 not supported by template */ + +#define UNVIEWPORT_VARS GLfloat h = SIS_CONTEXT(ctx)->driDrawable->h +#define UNVIEWPORT_X(x) x - SUBPIXEL_X +#define UNVIEWPORT_Y(y) - y + h + SUBPIXEL_Y +#define UNVIEWPORT_Z(z) z / smesa->depth_scale + +#define PTEX_FALLBACK() FALLBACK(smesa, SIS_FALLBACK_TEXTURE, 1) + +#define IMPORT_FLOAT_COLORS sis_import_float_colors +#define IMPORT_FLOAT_SPEC_COLORS sis_import_float_spec_colors + +#define INTERP_VERTEX setup_tab[smesa->SetupIndex].interp +#define COPY_PV_VERTEX setup_tab[smesa->SetupIndex].copy_pv + +/*********************************************************************** + * Generate pv-copying and translation functions * + ***********************************************************************/ + +#define TAG(x) sis_##x +#include "tnl_dd/t_dd_vb.c" + +/*********************************************************************** + * Generate vertex emit and interp functions * + ***********************************************************************/ + + +#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT) +#define TAG(x) x##_wg +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_SPEC_BIT) +#define TAG(x) x##_wgs +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_TEX0_BIT) +#define TAG(x) x##_wgt0 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_TEX0_BIT|SIS_TEX1_BIT) +#define TAG(x) x##_wgt0t1 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_TEX0_BIT|SIS_PTEX_BIT) +#define TAG(x) x##_wgpt0 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_SPEC_BIT|SIS_TEX0_BIT) +#define TAG(x) x##_wgst0 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_SPEC_BIT|SIS_TEX0_BIT|\ + SIS_TEX1_BIT) +#define TAG(x) x##_wgst0t1 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_SPEC_BIT|SIS_TEX0_BIT|\ + SIS_PTEX_BIT) +#define TAG(x) x##_wgspt0 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_FOG_BIT) +#define TAG(x) x##_wgf +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_FOG_BIT|SIS_SPEC_BIT) +#define TAG(x) x##_wgfs +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_FOG_BIT|SIS_TEX0_BIT) +#define TAG(x) x##_wgft0 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_FOG_BIT|SIS_TEX0_BIT|\ + SIS_TEX1_BIT) +#define TAG(x) x##_wgft0t1 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_FOG_BIT|SIS_TEX0_BIT|\ + SIS_PTEX_BIT) +#define TAG(x) x##_wgfpt0 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_FOG_BIT|SIS_SPEC_BIT|\ + SIS_TEX0_BIT) +#define TAG(x) x##_wgfst0 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_FOG_BIT|SIS_SPEC_BIT|\ + SIS_TEX0_BIT|SIS_TEX1_BIT) +#define TAG(x) x##_wgfst0t1 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_FOG_BIT|SIS_SPEC_BIT|\ + SIS_TEX0_BIT|SIS_PTEX_BIT) +#define TAG(x) x##_wgfspt0 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_TEX0_BIT) +#define TAG(x) x##_t0 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_TEX0_BIT|SIS_TEX1_BIT) +#define TAG(x) x##_t0t1 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_FOG_BIT) +#define TAG(x) x##_f +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_FOG_BIT|SIS_TEX0_BIT) +#define TAG(x) x##_ft0 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_FOG_BIT|SIS_TEX0_BIT|SIS_TEX1_BIT) +#define TAG(x) x##_ft0t1 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_RGBA_BIT) +#define TAG(x) x##_g +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_RGBA_BIT|SIS_SPEC_BIT) +#define TAG(x) x##_gs +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_RGBA_BIT|SIS_TEX0_BIT) +#define TAG(x) x##_gt0 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_RGBA_BIT|SIS_TEX0_BIT|SIS_TEX1_BIT) +#define TAG(x) x##_gt0t1 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_RGBA_BIT|SIS_SPEC_BIT|SIS_TEX0_BIT) +#define TAG(x) x##_gst0 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_RGBA_BIT|SIS_SPEC_BIT|SIS_TEX0_BIT|SIS_TEX1_BIT) +#define TAG(x) x##_gst0t1 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_RGBA_BIT|SIS_FOG_BIT) +#define TAG(x) x##_gf +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_RGBA_BIT|SIS_FOG_BIT|SIS_SPEC_BIT) +#define TAG(x) x##_gfs +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_RGBA_BIT|SIS_FOG_BIT|SIS_TEX0_BIT) +#define TAG(x) x##_gft0 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_RGBA_BIT|SIS_FOG_BIT|SIS_TEX0_BIT|SIS_TEX1_BIT) +#define TAG(x) x##_gft0t1 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_RGBA_BIT|SIS_FOG_BIT|SIS_SPEC_BIT|SIS_TEX0_BIT) +#define TAG(x) x##_gfst0 +#include "tnl_dd/t_dd_vbtmp.h" + +#define IND (SIS_RGBA_BIT|SIS_FOG_BIT|SIS_SPEC_BIT|SIS_TEX0_BIT|\ + SIS_TEX1_BIT) +#define TAG(x) x##_gfst0t1 +#include "tnl_dd/t_dd_vbtmp.h" + + +static void init_setup_tab( void ) +{ + init_wg(); + init_wgs(); + init_wgt0(); + init_wgt0t1(); + init_wgpt0(); + init_wgst0(); + init_wgst0t1(); + init_wgspt0(); + init_wgf(); + init_wgfs(); + init_wgft0(); + init_wgft0t1(); + init_wgfpt0(); + init_wgfst0(); + init_wgfst0t1(); + init_wgfspt0(); + init_t0(); + init_t0t1(); + init_f(); + init_ft0(); + init_ft0t1(); + init_g(); + init_gs(); + init_gt0(); + init_gt0t1(); + init_gst0(); + init_gst0t1(); + init_gf(); + init_gfs(); + init_gft0(); + init_gft0t1(); + init_gfst0(); + init_gfst0t1(); +} + + + +void sisPrintSetupFlags(char *msg, GLuint flags ) +{ + fprintf(stderr, "%s(%x): %s%s%s%s%s%s\n", + msg, + (int)flags, + (flags & SIS_XYZW_BIT) ? " xyzw," : "", + (flags & SIS_RGBA_BIT) ? " rgba," : "", + (flags & SIS_SPEC_BIT) ? " spec," : "", + (flags & SIS_FOG_BIT) ? " fog," : "", + (flags & SIS_TEX0_BIT) ? " tex-0," : "", + (flags & SIS_TEX1_BIT) ? " tex-1," : ""); +} + + + +void sisCheckTexSizes( GLcontext *ctx ) +{ + sisContextPtr smesa = SIS_CONTEXT( ctx ); + + if (!setup_tab[smesa->SetupIndex].check_tex_sizes(ctx)) { + TNLcontext *tnl = TNL_CONTEXT(ctx); + + /* Invalidate stored verts + */ + smesa->SetupNewInputs = ~0; + smesa->SetupIndex |= SIS_PTEX_BIT; + + if (!smesa->Fallback && + !(ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) { + tnl->Driver.Render.Interp = setup_tab[smesa->SetupIndex].interp; + tnl->Driver.Render.CopyPV = setup_tab[smesa->SetupIndex].copy_pv; + } + } +} + +void sisBuildVertices( GLcontext *ctx, + GLuint start, + GLuint count, + GLuint newinputs ) +{ + sisContextPtr smesa = SIS_CONTEXT( ctx ); + GLubyte *v = ((GLubyte *)smesa->verts + (start<vertex_stride_shift)); + GLuint stride = 1 << smesa->vertex_stride_shift; + + newinputs |= smesa->SetupNewInputs; + smesa->SetupNewInputs = 0; + + if (!newinputs) + return; + + if (newinputs & VERT_BIT_CLIP) { + setup_tab[smesa->SetupIndex].emit( ctx, start, count, v, stride ); + } else { + GLuint ind = 0; + + if (newinputs & VERT_BIT_COLOR0) + ind |= SIS_RGBA_BIT; + + if (newinputs & VERT_BIT_COLOR1) + ind |= SIS_SPEC_BIT; + + if (newinputs & VERT_BIT_TEX0) + ind |= SIS_TEX0_BIT; + + if (newinputs & VERT_BIT_TEX1) + ind |= SIS_TEX1_BIT; + + if (newinputs & VERT_BIT_FOG) + ind |= SIS_FOG_BIT; + + if (smesa->SetupIndex & SIS_PTEX_BIT) + ind = ~0; + + ind &= smesa->SetupIndex; + + if (ind) { + setup_tab[ind].emit( ctx, start, count, v, stride ); + } + } +} + +void sisChooseVertexState( GLcontext *ctx ) +{ + TNLcontext *tnl = TNL_CONTEXT(ctx); + sisContextPtr smesa = SIS_CONTEXT( ctx ); + GLuint ind = SIS_XYZW_BIT | SIS_RGBA_BIT; + + if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) + ind |= SIS_SPEC_BIT; + + if (ctx->Fog.Enabled) + ind |= SIS_FOG_BIT; + + if (ctx->Texture._EnabledUnits) { + ind |= SIS_TEX0_BIT; + if (ctx->Texture.Unit[0]._ReallyEnabled && + ctx->Texture.Unit[1]._ReallyEnabled) + ind |= SIS_TEX1_BIT; + } + + smesa->SetupIndex = ind; + + if (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE | DD_TRI_UNFILLED)) { + tnl->Driver.Render.Interp = sis_interp_extras; + tnl->Driver.Render.CopyPV = sis_copy_pv_extras; + } else { + tnl->Driver.Render.Interp = setup_tab[ind].interp; + tnl->Driver.Render.CopyPV = setup_tab[ind].copy_pv; + } + + if (setup_tab[ind].vertex_format != smesa->vertex_format) { + smesa->vertex_format = setup_tab[ind].vertex_format; + smesa->vertex_size = setup_tab[ind].vertex_size; + smesa->vertex_stride_shift = setup_tab[ind].vertex_stride_shift; + } +} + + +void sisInitVB( GLcontext *ctx ) +{ + sisContextPtr smesa = SIS_CONTEXT( ctx ); + GLuint size = TNL_CONTEXT(ctx)->vb.Size; + static int firsttime = 1; + + smesa->verts = (char *)ALIGN_MALLOC(size * 4 * 16, 32); + + if (firsttime) { + init_setup_tab(); + firsttime = 0; + } +} + +void sisFreeVB( GLcontext *ctx ) +{ + sisContextPtr smesa = SIS_CONTEXT( ctx ); + if (smesa->verts) { + ALIGN_FREE(smesa->verts); + smesa->verts = NULL; + } + + + if (smesa->UbyteSecondaryColor.Ptr) { + ALIGN_FREE(smesa->UbyteSecondaryColor.Ptr); + smesa->UbyteSecondaryColor.Ptr = NULL; + } + + if (smesa->UbyteColor.Ptr) { + ALIGN_FREE(smesa->UbyteColor.Ptr); + smesa->UbyteColor.Ptr = NULL; + } +} diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_vb.h xc/lib/GL/mesa/src/drv/sis/sis_vb.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_vb.h Wed Dec 31 16:00:00 1969 +++ xc/lib/GL/mesa/src/drv/sis/sis_vb.h Wed Aug 20 20:59:24 2003 @@ -0,0 +1,66 @@ +/* $XFree86: xc/lib/GL/mesa/src/drv/r128/r128_vb.h,v 1.8 2002/10/30 12:51:46 alanh Exp $ */ +/************************************************************************** + +Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and + VA Linux Systems Inc., Fremont, California. + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +on the rights to use, copy, modify, merge, publish, distribute, sub +license, and/or sell copies of the Software, and to permit persons to whom +the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +ATI, VA LINUX SYSTEMS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ + +/* + * Authors: + * Keith Whitwell + * + */ + +#ifndef __SIS_VB_H__ +#define __SIS_VB_H__ + +#include "mtypes.h" +#include "swrast/swrast.h" +#include "sis_context.h" + +#define _SIS_NEW_VERTEX_STATE (_DD_NEW_SEPARATE_SPECULAR | \ + _DD_NEW_TRI_LIGHT_TWOSIDE | \ + _DD_NEW_TRI_UNFILLED | \ + _NEW_TEXTURE | \ + _NEW_FOG) + +extern void sisCheckTexSizes( GLcontext *ctx ); +extern void sisChooseVertexState( GLcontext *ctx ); + +extern void sisBuildVertices( GLcontext *ctx, GLuint start, GLuint count, + GLuint newinputs ); + +extern void sisPrintSetupFlags( char *msg, GLuint flags ); + +extern void sisInitVB( GLcontext *ctx ); +extern void sisFreeVB( GLcontext *ctx ); + +extern void sis_translate_vertex( GLcontext *ctx, + const sisVertex *src, + SWvertex *dst ); + +extern void sis_print_vertex( GLcontext *ctx, const sisVertex *v ); + +#endif diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_xf86glx.c xc/lib/GL/mesa/src/drv/sis/sis_xf86glx.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_xf86glx.c Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_xf86glx.c Wed Dec 31 16:00:00 1969 @@ -1,962 +0,0 @@ -/* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_xf86glx.c,v 1.1 2000/06/30 19:30:29 dawes Exp $ */ -/************************************************************************** - -Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. -All Rights Reserved. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sub license, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice (including the -next paragraph) shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. -IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -**************************************************************************/ - -/* - * Authors: - * Kevin E. Martin - * - * $PI: xc/programs/Xserver/GL/mesa/src/X/xf86glx.c,v 1.15 1999/08/04 18:14:14 faith Exp $ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "xf86glxint.h" -#include "xmesaP.h" -#include - -/* - * This define is for the glcore.h header file. - * If you add it here, then make sure you also add it in - * ../../../glx/Imakefile. - */ -#if 0 -#define DEBUG -#include -#undef DEBUG -#else -#include -#endif - - -/* - * This structure is statically allocated in the __glXScreens[] - * structure. This struct is not used anywhere other than in - * __glXScreenInit to initialize each of the active screens - * (__glXActiveScreens[]). Several of the fields must be initialized by - * the screenProbe routine before they are copied to the active screens - * struct. In particular, the contextCreate, pGlxVisual, numVisuals, - * and numUsableVisuals fields must be initialized. - */ -__GLXscreenInfo __glDDXScreenInfo = { - __MESA_screenProbe, /* Must be generic and handle all screens */ - __MESA_createContext, /* Substitute screen's createContext routine */ - __MESA_createBuffer, /* Substitute screen's createBuffer routine */ - NULL, /* Set up pGlxVisual in probe */ - NULL, /* Set up pVisualPriv in probe */ - 0, /* Set up numVisuals in probe */ - 0, /* Set up numUsableVisuals in probe */ - "Vendor String", /* GLXvendor is overwritten by __glXScreenInit */ - "Version String", /* GLXversion is overwritten by __glXScreenInit */ - "Extensions String", /* GLXextensions is overwritten by __glXScreenInit */ - NULL /* WrappedPositionWindow is overwritten */ -}; - -__GLXextensionInfo __glDDXExtensionInfo = { - GL_CORE_MESA, - __MESA_resetExtension, - __MESA_initVisuals, - __MESA_setVisualConfigs -}; - -__MESA_screen MESAScreens[MAXSCREENS]; -__GLcontext *MESA_CC = NULL; - -int numConfigs = 0; -__GLXvisualConfig *visualConfigs = NULL; -void **visualPrivates = NULL; - -static int count_bits(unsigned int n) -{ - int bits = 0; - - while (n > 0) { - if (n & 1) bits++; - n >>= 1; - } - return bits; -} - -static XMesaVisual find_mesa_visual(int screen, VisualID vid) -{ - XMesaVisual xm_vis = NULL; - __MESA_screen *pMScr = &MESAScreens[screen]; - int i; - - for (i = 0; i < pMScr->num_vis; i++) { - if (pMScr->glx_vis[i].vid == vid) { - break; - } - } - - if (i < pMScr->num_vis) { - xm_vis = pMScr->xm_vis[i]; - } - return xm_vis; -} - -#define VISUAL_CONFIG(rgba,accum,back,depth,stencil,rating) \ -{ \ - -1, /* vid */ \ - -1, /* class */ \ - rgba, /* rgba */ \ - -1, -1, -1, 0, /* rgba sizes, alpha not supported, yet */ \ - -1, -1, -1, 0, /* rgba masks, alpha not supported, yet */ \ - accum, accum, accum, accum, /* rgba accum sizes */ \ - back, /* doubleBuffer */ \ - GL_FALSE, /* stereo */ \ - -1, /* bufferSize */ \ - depth, /* depthSize */ \ - stencil, /* stencilSize */ \ - 0, /* auxBuffers */ \ - 0, /* level */ \ - rating, /* visualRating */ \ - 0, /* transparentPixel */ \ - 0, 0, 0, 0, /* transparent rgba color (floats scaled to ints) */ \ - 0 /* transparentIndex */ \ -} - -#define IS_RGBA GL_TRUE -#define IS_CI GL_FALSE -#define HAS_ACCUM ACCUM_BITS -#define NO_ACCUM 0 -#define HAS_BACK GL_TRUE -#define NO_BACK GL_FALSE -#define HAS_DEPTH DEPTH_BITS -#define NO_DEPTH 0 -#define HAS_STENCIL STENCIL_BITS -#define NO_STENCIL 0 - -static __GLXvisualConfig __MESAvisualConfigs[] = { - VISUAL_CONFIG(IS_RGBA, NO_ACCUM, NO_BACK, 0, 0, 0), - VISUAL_CONFIG(IS_RGBA, NO_ACCUM, NO_BACK, 16, 0, 0), - VISUAL_CONFIG(IS_RGBA, NO_ACCUM, NO_BACK, 32, 0, 0), - VISUAL_CONFIG(IS_RGBA, NO_ACCUM, NO_BACK, 24, 8, 0), - - VISUAL_CONFIG(IS_RGBA, NO_ACCUM, HAS_BACK, 0, 0, 0), - VISUAL_CONFIG(IS_RGBA, NO_ACCUM, HAS_BACK, 16, 0, 0), - VISUAL_CONFIG(IS_RGBA, NO_ACCUM, HAS_BACK, 32, 0, 0), - VISUAL_CONFIG(IS_RGBA, NO_ACCUM, HAS_BACK, 24, 8, 0), - - VISUAL_CONFIG(IS_RGBA, HAS_ACCUM, NO_BACK, 0, 0, 0), - VISUAL_CONFIG(IS_RGBA, HAS_ACCUM, NO_BACK, 16, 0, 0), - VISUAL_CONFIG(IS_RGBA, HAS_ACCUM, NO_BACK, 32, 0, 0), - VISUAL_CONFIG(IS_RGBA, HAS_ACCUM, NO_BACK, 24, 8, 0), - - VISUAL_CONFIG(IS_RGBA, HAS_ACCUM, HAS_BACK, 0, 0, 0), - VISUAL_CONFIG(IS_RGBA, HAS_ACCUM, HAS_BACK, 16, 0, 0), - VISUAL_CONFIG(IS_RGBA, HAS_ACCUM, HAS_BACK, 32, 0, 0), - VISUAL_CONFIG(IS_RGBA, HAS_ACCUM, HAS_BACK, 24, 8, 0), -/* - VISUAL_CONFIG( IS_CI, NO_ACCUM, NO_BACK, NO_DEPTH, NO_STENCIL, 0), - VISUAL_CONFIG( IS_CI, NO_ACCUM, NO_BACK, HAS_DEPTH, NO_STENCIL, 0), - VISUAL_CONFIG( IS_CI, NO_ACCUM, HAS_BACK, NO_DEPTH, NO_STENCIL, 0), - VISUAL_CONFIG( IS_CI, NO_ACCUM, HAS_BACK, HAS_DEPTH, NO_STENCIL, 0), - VISUAL_CONFIG( IS_CI, NO_ACCUM, NO_BACK, NO_DEPTH, NO_STENCIL, 0), - VISUAL_CONFIG( IS_CI, NO_ACCUM, HAS_BACK, HAS_DEPTH, HAS_STENCIL, 0), - VISUAL_CONFIG( IS_CI, NO_ACCUM, HAS_BACK, HAS_DEPTH, HAS_STENCIL, 0), -*/ -}; - -/* -static __GLXvisualConfig __MESAvisualConfigs[] = { - VISUAL_CONFIG(IS_RGBA, NO_ACCUM, NO_BACK, NO_DEPTH, NO_STENCIL, 0), - VISUAL_CONFIG(IS_RGBA, NO_ACCUM, NO_BACK, HAS_DEPTH, NO_STENCIL, 0), - VISUAL_CONFIG(IS_RGBA, NO_ACCUM, HAS_BACK, NO_DEPTH, NO_STENCIL, 0), - VISUAL_CONFIG(IS_RGBA, NO_ACCUM, HAS_BACK, HAS_DEPTH, NO_STENCIL, 0), - VISUAL_CONFIG(IS_RGBA, NO_ACCUM, NO_BACK, NO_DEPTH, NO_STENCIL, 0), - VISUAL_CONFIG(IS_RGBA, NO_ACCUM, HAS_BACK, HAS_DEPTH, HAS_STENCIL, 0), - VISUAL_CONFIG(IS_RGBA, HAS_ACCUM, HAS_BACK, HAS_DEPTH, HAS_STENCIL, 0), - VISUAL_CONFIG( IS_CI, NO_ACCUM, NO_BACK, NO_DEPTH, NO_STENCIL, 0), - VISUAL_CONFIG( IS_CI, NO_ACCUM, NO_BACK, HAS_DEPTH, NO_STENCIL, 0), - VISUAL_CONFIG( IS_CI, NO_ACCUM, HAS_BACK, NO_DEPTH, NO_STENCIL, 0), - VISUAL_CONFIG( IS_CI, NO_ACCUM, HAS_BACK, HAS_DEPTH, NO_STENCIL, 0), - VISUAL_CONFIG( IS_CI, NO_ACCUM, NO_BACK, NO_DEPTH, NO_STENCIL, 0), - VISUAL_CONFIG( IS_CI, NO_ACCUM, HAS_BACK, HAS_DEPTH, HAS_STENCIL, 0), - VISUAL_CONFIG( IS_CI, NO_ACCUM, HAS_BACK, HAS_DEPTH, HAS_STENCIL, 0), -}; -*/ - -static int __numMESAvisualConfigs = - sizeof(__MESAvisualConfigs)/sizeof(__GLXvisualConfig); -static int __numRGBconfigs = -1; -static int __numCIconfigs = -1; - -static Bool init_visuals(int *nvisualp, VisualPtr *visualp, - VisualID *defaultVisp, - int ndepth, DepthPtr pdepth, - int rootDepth) -{ - int numVisuals = *nvisualp; - int numMesaVisuals = 0; - int numMergedVisualConfigs = 0; - VisualPtr pVisual = *visualp; - VisualPtr pVisualNew = NULL; - VisualID *orig_vid = NULL; - __GLXvisualConfig *glXVisualPtr = NULL; - __GLXvisualConfig *pMergedVisualConfigs = NULL; - void **glXVisualPriv; - void **pMergedVisualPriv; - int *mesaConfigUsed; - int *driverConfigUsed; - int found_default = FALSE; - int i, j, k; - int is_rgb; - Bool match; - - /* Alloc space for the list of merged GLX visuals */ - pMergedVisualConfigs = - (__GLXvisualConfig *)__glXMalloc((numConfigs + - __numMESAvisualConfigs) * - sizeof(__GLXvisualConfig)); - if (!pMergedVisualConfigs) { - return FALSE; - } - - /* Alloc space for the list of merged GLX visual privates */ - pMergedVisualPriv = - (void **)__glXMalloc((numConfigs + __numMESAvisualConfigs) * - sizeof(void *)); - if (!pMergedVisualPriv) { - __glXFree(pMergedVisualConfigs); - return FALSE; - } - - /* Compute the intersection of the driver's visual configs */ - mesaConfigUsed = __glXCalloc(__numMESAvisualConfigs, sizeof(int)); - driverConfigUsed = __glXCalloc(numConfigs, sizeof(int)); - - for (i = j = 0; i < numConfigs; i++) { - k = 0; - while ((k < __numMESAvisualConfigs) && (!driverConfigUsed[i])) { - if (!mesaConfigUsed[k]) { - -#ifdef DEBUG_VISUAL_CONFIG -#define TEST_AND_COPY(fld) do { \ - if (match) { \ - if ((__MESAvisualConfigs[k].fld == visualConfigs[i].fld) || \ - (__MESAvisualConfigs[k].fld == -1)) { \ - pMergedVisualConfigs[j].fld = visualConfigs[i].fld; \ - } \ - else if (visualConfigs[i].fld == -1) { \ - pMergedVisualConfigs[j].fld = __MESAvisualConfigs[k].fld; \ - } \ - else { \ - match = FALSE; \ - xf86DrvMsg (0, 0, "[GLXVisualInit] mismatch: " \ - "(%s) DriverVisualConfig[%d] MesaVisualConfig[%d]\n", \ - #fld, i, k); \ - } \ - } \ - } while (0) -#else -#define TEST_AND_COPY(fld) do { \ - if (match) { \ - if ((__MESAvisualConfigs[k].fld == visualConfigs[i].fld) || \ - (__MESAvisualConfigs[k].fld == -1)) { \ - pMergedVisualConfigs[j].fld = visualConfigs[i].fld; \ - } \ - else if (visualConfigs[i].fld == -1) { \ - pMergedVisualConfigs[j].fld = __MESAvisualConfigs[k].fld; \ - } \ - else { \ - match = FALSE; \ - } \ - } \ - } while (0) -#endif - - match = TRUE; - TEST_AND_COPY(class); - TEST_AND_COPY(rgba); - TEST_AND_COPY(redSize); - TEST_AND_COPY(greenSize); - TEST_AND_COPY(blueSize); - TEST_AND_COPY(alphaSize); - TEST_AND_COPY(redMask); - TEST_AND_COPY(greenMask); - TEST_AND_COPY(blueMask); - TEST_AND_COPY(alphaMask); - TEST_AND_COPY(accumRedSize); - TEST_AND_COPY(accumGreenSize); - TEST_AND_COPY(accumBlueSize); - TEST_AND_COPY(accumAlphaSize); - TEST_AND_COPY(doubleBuffer); - TEST_AND_COPY(stereo); - TEST_AND_COPY(bufferSize); - TEST_AND_COPY(depthSize); - TEST_AND_COPY(stencilSize); - TEST_AND_COPY(auxBuffers); - TEST_AND_COPY(level); - TEST_AND_COPY(visualRating); - TEST_AND_COPY(transparentPixel); - TEST_AND_COPY(transparentRed); - TEST_AND_COPY(transparentGreen); - TEST_AND_COPY(transparentBlue); - TEST_AND_COPY(transparentAlpha); - TEST_AND_COPY(transparentIndex); - if (match) { - driverConfigUsed[i] = TRUE; - mesaConfigUsed[k] = TRUE; - pMergedVisualPriv[j] = visualPrivates[i]; - j++; -#ifdef DEBUG_VISUAL_CONFIG - xf86DrvMsg (0, 0, "[GLXVisualInit] MATCH: " - "DriverVisualConfig[%d] MesaVisualConfig[%d]\n", i, k); -#endif - } - } - k++; - } - } - - /* - ** If SetVisualConfigs was not called, then just make all of Mesa's - ** visual configs available. - */ - if (!numConfigs) { - memcpy(pMergedVisualConfigs, __MESAvisualConfigs, - sizeof(__GLXvisualConfig) * __numMESAvisualConfigs); - memset(pMergedVisualPriv, 0, sizeof(void *) * __numMESAvisualConfigs); - memset(mesaConfigUsed, TRUE, sizeof(int) * __numMESAvisualConfigs); - j = __numMESAvisualConfigs; - } - - /* - ** This code is not currently used. When the visual caveat - ** extension is supported by the DRI and Mesa, we can take advantage - ** of this code. - */ -#if 0 - /* Add any unclaimed MESA configs w/ slow caveat */ - for (i = 0; i < __numMESAvisualConfigs; i++) { - if (!mesaConfigUsed[i]) { - memcpy(&pMergedVisualConfigs[j], &__MESAvisualConfigs[i], - sizeof(__GLXvisualConfig)); - pMergedVisualConfigs[j].visualRating = GLX_SLOW_VISUAL_EXT; - j++; -#ifdef DEBUG_VISUAL_CONFIG - xf86DrvMsg (0, 0, "[GLXVisualInit] slow config: " - "MesaVisualConfig[%d]\n", i); -#endif - } - } - - /* Add any unclaimed driver configs w/ nonconformant caveat */ - for (i = 0; i < numConfigs; i++) { - if (!driverConfigUsed[i]) { - memcpy(&pMergedVisualConfigs[j], &visualConfigs[i], - sizeof(__GLXvisualConfig)); - pMergedVisualConfigs[j].visualRating = GLX_NON_CONFORMANT_VISUAL_EXT; - j++; -#ifdef DEBUG_VISUAL_CONFIG - xf86DrvMsg (0, 0, "[GLXVisualInit] non-conformant config: " - "DriverVisualConfig[%d]\n", i); -#endif - } - } -#endif - - numMergedVisualConfigs = j; - - /* Count the number of RGB and CI visual configs */ - __numRGBconfigs = __numCIconfigs = 0; - for (i = 0; i < numMergedVisualConfigs; i++) { - if (pMergedVisualConfigs[i].rgba) - __numRGBconfigs++; - else - __numCIconfigs++; - } - - /* Count the total number of visuals to compute */ - for (i = 0; i < numVisuals; i++) { - numMesaVisuals += - (pVisual[i].class == TrueColor || pVisual[i].class == DirectColor) - ? __numRGBconfigs : __numCIconfigs; - } - - /* Reset variables for use with the next screen/driver's visual configs */ - visualConfigs = NULL; - numConfigs = 0; - - /* Alloc temp space for the list of orig VisualIDs for each new visual */ - orig_vid = (VisualID *)__glXMalloc(numMesaVisuals * sizeof(VisualID)); - if (!orig_vid) { - __glXFree(pMergedVisualPriv); - __glXFree(pMergedVisualConfigs); - return FALSE; - } - - /* Alloc space for the list of glXVisuals */ - glXVisualPtr = (__GLXvisualConfig *)__glXMalloc(numMesaVisuals * - sizeof(__GLXvisualConfig)); - if (!glXVisualPtr) { - __glXFree(orig_vid); - __glXFree(pMergedVisualPriv); - __glXFree(pMergedVisualConfigs); - return FALSE; - } - - /* Alloc space for the list of glXVisualPrivates */ - glXVisualPriv = (void **)__glXMalloc(numMesaVisuals * sizeof(void *)); - if (!glXVisualPriv) { - __glXFree(glXVisualPtr); - __glXFree(orig_vid); - __glXFree(pMergedVisualPriv); - __glXFree(pMergedVisualConfigs); - return FALSE; - } - - /* Alloc space for the new list of the X server's visuals */ - pVisualNew = (VisualPtr)__glXMalloc(numMesaVisuals * sizeof(VisualRec)); - if (!pVisualNew) { - __glXFree(glXVisualPriv); - __glXFree(glXVisualPtr); - __glXFree(orig_vid); - __glXFree(pMergedVisualPriv); - __glXFree(pMergedVisualConfigs); - return FALSE; - } - - /* Initialize the new visuals */ - for (i = j = 0; i < numVisuals; i++) { - is_rgb = (pVisual[i].class == TrueColor || - pVisual[i].class == DirectColor); - - for (k = 0; k < numMergedVisualConfigs; k++) { - if (pMergedVisualConfigs[k].rgba != is_rgb) - continue; - - /* Initialize the new visual */ - pVisualNew[j] = pVisual[i]; - pVisualNew[j].vid = FakeClientID(0); - - /* Check for the default visual */ - if (!found_default && pVisual[i].vid == *defaultVisp) { - *defaultVisp = pVisualNew[j].vid; - found_default = TRUE; - } - - /* Save the old VisualID */ - orig_vid[j] = pVisual[i].vid; - - /* Initialize the glXVisual */ - glXVisualPtr[j] = pMergedVisualConfigs[k]; - glXVisualPtr[j].vid = pVisualNew[j].vid; - - /* - * If the class is -1, then assume the X visual information - * is identical to what GLX needs, and take them from the X - * visual. NOTE: if class != -1, then all other fields MUST - * be initialized. - */ - if (glXVisualPtr[j].class == -1) { - glXVisualPtr[j].class = pVisual[i].class; - glXVisualPtr[j].redSize = count_bits(pVisual[i].redMask); - glXVisualPtr[j].greenSize = count_bits(pVisual[i].greenMask); - glXVisualPtr[j].blueSize = count_bits(pVisual[i].blueMask); - glXVisualPtr[j].alphaSize = 0; /* Not supported in Mesa */ - glXVisualPtr[j].redMask = pVisual[i].redMask; - glXVisualPtr[j].greenMask = pVisual[i].greenMask; - glXVisualPtr[j].blueMask = pVisual[i].blueMask; - glXVisualPtr[j].alphaMask = 0; /* Not supported in Mesa */ - glXVisualPtr[j].bufferSize = rootDepth; - } - - /* Save the device-dependent private for this visual */ - glXVisualPriv[j] = pMergedVisualPriv[k]; - - j++; - } - } - - /* Save the GLX visuals in the screen structure */ - MESAScreens[screenInfo.numScreens-1].num_vis = numMesaVisuals; - MESAScreens[screenInfo.numScreens-1].glx_vis = glXVisualPtr; - MESAScreens[screenInfo.numScreens-1].private = glXVisualPriv; - - /* Set up depth's VisualIDs */ - for (i = 0; i < ndepth; i++) { - int numVids = 0; - VisualID *pVids = NULL; - int k, n = 0; - - /* Count the new number of VisualIDs at this depth */ - for (j = 0; j < pdepth[i].numVids; j++) - for (k = 0; k < numMesaVisuals; k++) - if (pdepth[i].vids[j] == orig_vid[k]) - numVids++; - - /* Allocate a new list of VisualIDs for this depth */ - pVids = (VisualID *)__glXMalloc(numVids * sizeof(VisualID)); - - /* Initialize the new list of VisualIDs for this depth */ - for (j = 0; j < pdepth[i].numVids; j++) - for (k = 0; k < numMesaVisuals; k++) - if (pdepth[i].vids[j] == orig_vid[k]) - pVids[n++] = pVisualNew[k].vid; - - /* Update this depth's list of VisualIDs */ - __glXFree(pdepth[i].vids); - pdepth[i].vids = pVids; - pdepth[i].numVids = numVids; - } - - /* Update the X server's visuals */ - *nvisualp = numMesaVisuals; - *visualp = pVisualNew; - - /* Free the old list of the X server's visuals */ - __glXFree(pVisual); - - /* Clean up temporary allocations */ - __glXFree(orig_vid); - __glXFree(pMergedVisualPriv); - __glXFree(pMergedVisualConfigs); - - /* Free the private list created by DDX HW driver */ - if (visualPrivates) xfree(visualPrivates); - visualPrivates = NULL; - - return TRUE; -} - -void __MESA_setVisualConfigs(int nconfigs, __GLXvisualConfig *configs, - void **privates) -{ - numConfigs = nconfigs; - visualConfigs = configs; - visualPrivates = privates; -} - -Bool __MESA_initVisuals(VisualPtr *visualp, DepthPtr *depthp, - int *nvisualp, int *ndepthp, int *rootDepthp, - VisualID *defaultVisp, unsigned long sizes, - int bitsPerRGB) -{ - /* - * Setup the visuals supported by this particular screen. - */ - return init_visuals(nvisualp, visualp, defaultVisp, - *ndepthp, *depthp, *rootDepthp); -} - -static void fixup_visuals(int screen) -{ - ScreenPtr pScreen = screenInfo.screens[screen]; - __MESA_screen *pMScr = &MESAScreens[screen]; - __GLXvisualConfig *pGLXVis = pMScr->glx_vis; - VisualPtr pVis; - int i, j; - - for (i = 0; i < pMScr->num_vis; i++, pGLXVis++) { - pVis = pScreen->visuals; - - /* Find a visual that matches the GLX visual's class and size */ - for (j = 0; j < pScreen->numVisuals; j++, pVis++) { - if (pVis->class == pGLXVis->class && - pVis->nplanes == pGLXVis->bufferSize) { - - /* Fixup the masks */ - pGLXVis->redMask = pVis->redMask; - pGLXVis->greenMask = pVis->greenMask; - pGLXVis->blueMask = pVis->blueMask; - - /* Recalc the sizes */ - pGLXVis->redSize = count_bits(pGLXVis->redMask); - pGLXVis->greenSize = count_bits(pGLXVis->greenMask); - pGLXVis->blueSize = count_bits(pGLXVis->blueMask); - } - } - } -} - -static void init_screen_visuals(int screen) -{ - ScreenPtr pScreen = screenInfo.screens[screen]; - __GLXvisualConfig *pGLXVis = MESAScreens[screen].glx_vis; - XMesaVisual *pXMesaVisual; - VisualPtr pVis; - int *used; - int i, j; - - /* Alloc space for the list of XMesa visuals */ - pXMesaVisual = (XMesaVisual *)__glXMalloc(MESAScreens[screen].num_vis * - sizeof(XMesaVisual)); - - used = (int *)__glXMalloc(pScreen->numVisuals * sizeof(int)); - __glXMemset(used, 0, pScreen->numVisuals * sizeof(int)); - - for (i = 0; i < MESAScreens[screen].num_vis; i++, pGLXVis++) { - - pVis = pScreen->visuals; - for (j = 0; j < pScreen->numVisuals; j++, pVis++) { - - if (pVis->class == pGLXVis->class && - pVis->nplanes == pGLXVis->bufferSize && - !used[j]) { - - if (pVis->redMask == pGLXVis->redMask && - pVis->greenMask == pGLXVis->greenMask && - pVis->blueMask == pGLXVis->blueMask) { - - /* Create the XMesa visual */ - pXMesaVisual[i] = - XMesaCreateVisual(pScreen, - pVis, - pGLXVis->rgba, - (pGLXVis->alphaSize > 0), - pGLXVis->doubleBuffer, - pGLXVis->stereo, - GL_TRUE, /* ximage_flag */ - pGLXVis->depthSize, - pGLXVis->stencilSize, - pGLXVis->accumRedSize, - pGLXVis->level); - - /* Set the VisualID */ - pGLXVis->vid = pVis->vid; - - /* Mark this visual used */ - used[j] = 1; - break; - } - } - } - } - - __glXFree(used); - - MESAScreens[screen].xm_vis = pXMesaVisual; -} - -Bool __MESA_screenProbe(int screen) -{ - /* - * Set up the current screen's visuals. - */ - __glDDXScreenInfo.pGlxVisual = MESAScreens[screen].glx_vis; - __glDDXScreenInfo.pVisualPriv = MESAScreens[screen].private; - __glDDXScreenInfo.numVisuals = - __glDDXScreenInfo.numUsableVisuals = MESAScreens[screen].num_vis; - - /* - * Set the current screen's createContext routine. This could be - * wrapped by a DDX GLX context creation routine. - */ - __glDDXScreenInfo.createContext = __MESA_createContext; - - /* - * The ordering of the rgb compenents might have been changed by the - * driver after mi initialized them. - */ - fixup_visuals(screen); - - /* - * Find the GLX visuals that are supported by this screen and create - * XMesa's visuals. - */ - init_screen_visuals(screen); - - return TRUE; -} - -extern void __MESA_resetExtension(void) -{ - int i, j; - - XMesaReset(); - - for (i = 0; i < screenInfo.numScreens; i++) { - for (j = 0; j < MESAScreens[i].num_vis; j++) { - XMesaDestroyVisual(MESAScreens[i].xm_vis[j]); - } - __glXFree(MESAScreens[i].glx_vis); - MESAScreens[i].glx_vis = NULL; - MESAScreens[i].num_vis = 0; - } - MESA_CC = NULL; -} - -void __MESA_createBuffer(__GLXdrawablePrivate *glxPriv) -{ - DrawablePtr pDraw = glxPriv->pDraw; - XMesaVisual xm_vis = find_mesa_visual(pDraw->pScreen->myNum, - glxPriv->pGlxVisual->vid); - __GLdrawablePrivate *glPriv = &glxPriv->glPriv; - __MESA_buffer buf; - - buf = (__MESA_buffer)__glXMalloc(sizeof(struct __MESA_bufferRec)); - - /* Create Mesa's buffers */ - if (glxPriv->type == DRAWABLE_WINDOW) { - buf->xm_buf = (void *)XMesaCreateWindowBuffer(xm_vis, - (WindowPtr)pDraw); - } else { - buf->xm_buf = (void *)XMesaCreatePixmapBuffer(xm_vis, - (PixmapPtr)pDraw, 0); - } - - /* Wrap the front buffer's resize routine */ - buf->fbresize = glPriv->frontBuffer.resize; - glPriv->frontBuffer.resize = __MESA_resizeBuffers; - - /* Wrap the swap buffers routine */ - buf->fbswap = glxPriv->swapBuffers; - glxPriv->swapBuffers = __MESA_swapBuffers; - - /* Save Mesa's private buffer structure */ - glPriv->private = (void *)buf; - glPriv->freePrivate = __MESA_destroyBuffer; -} - -GLboolean __MESA_resizeBuffers(__GLdrawableBuffer *buffer, - GLint x, GLint y, - GLuint width, GLuint height, - __GLdrawablePrivate *glPriv, - GLuint bufferMask) -{ - __MESA_buffer buf = (__MESA_buffer)glPriv->private; - - if (buf->xm_buf && buf->xm_buf->xm_context) { - GLcontext *ctx = buf->xm_buf->xm_context->gl_ctx; - XMesaForceCurrent(buf->xm_buf->xm_context); - (*ctx->CurrentDispatch->ResizeBuffersMESA)(); - if (MESA_CC) - XMesaForceCurrent(MESA_CC->xm_ctx); - } - - return (*buf->fbresize)(buffer, x, y, width, height, glPriv, bufferMask); -} - -GLboolean __MESA_swapBuffers(__GLXdrawablePrivate *glxPriv) -{ - __MESA_buffer buf = (__MESA_buffer)glxPriv->glPriv.private; - - /* - ** Do not call the wrapped swap buffers routine since Mesa has - ** already done the swap. - */ - XMesaSwapBuffers(buf->xm_buf); - - return GL_TRUE; -} - -void __MESA_destroyBuffer(__GLdrawablePrivate *glPriv) -{ - __MESA_buffer buf = (__MESA_buffer)glPriv->private; - __GLXdrawablePrivate *glxPriv = (__GLXdrawablePrivate *)glPriv->other; - - /* Destroy Mesa's buffers */ - if (buf->xm_buf) - XMesaDestroyBuffer(buf->xm_buf); - - /* Unwrap these routines */ - glxPriv->swapBuffers = buf->fbswap; - glPriv->frontBuffer.resize = buf->fbresize; - - __glXFree(glPriv->private); - glPriv->private = NULL; -} - -__GLinterface *__MESA_createContext(__GLimports *imports, - __GLcontextModes *modes, - __GLinterface *shareGC) -{ - __GLcontext *gl_ctx; - XMesaContext m_share = NULL; - XMesaVisual xm_vis; - __GLXcontext *glxc = (__GLXcontext *)imports->other; - - gl_ctx = (__GLcontext *)__glXMalloc(sizeof(__GLcontext)); - if (!gl_ctx) - return NULL; - - gl_ctx->iface.imports = *imports; - - gl_ctx->iface.exports.destroyContext = __MESA_destroyContext; - gl_ctx->iface.exports.loseCurrent = __MESA_loseCurrent; - gl_ctx->iface.exports.makeCurrent = __MESA_makeCurrent; - gl_ctx->iface.exports.shareContext = __MESA_shareContext; - gl_ctx->iface.exports.copyContext = __MESA_copyContext; - gl_ctx->iface.exports.forceCurrent = __MESA_forceCurrent; - gl_ctx->iface.exports.notifyResize = __MESA_notifyResize; - gl_ctx->iface.exports.notifyDestroy = __MESA_notifyDestroy; - gl_ctx->iface.exports.notifySwapBuffers = __MESA_notifySwapBuffers; - gl_ctx->iface.exports.dispatchExec = __MESA_dispatchExec; - gl_ctx->iface.exports.beginDispatchOverride = __MESA_beginDispatchOverride; - gl_ctx->iface.exports.endDispatchOverride = __MESA_endDispatchOverride; - - if (shareGC) m_share = ((__GLcontext *)shareGC)->xm_ctx; - xm_vis = find_mesa_visual(glxc->pScreen->myNum, glxc->pGlxVisual->vid); - if (xm_vis) { - gl_ctx->xm_ctx = XMesaCreateContext(xm_vis, m_share); - } else { - __glXFree(gl_ctx); - gl_ctx = NULL; - } - - return (__GLinterface *)gl_ctx; -} - -GLboolean __MESA_destroyContext(__GLcontext *gc) -{ - XMesaDestroyContext(gc->xm_ctx); - __glXFree(gc); - return GL_TRUE; -} - -GLboolean __MESA_loseCurrent(__GLcontext *gc) -{ - MESA_CC = NULL; - __glXLastContext = NULL; - return XMesaLoseCurrent(gc->xm_ctx); -} - -GLboolean __MESA_makeCurrent(__GLcontext *gc, __GLdrawablePrivate *glPriv) -{ - __MESA_buffer buf = (__MESA_buffer)glPriv->private; - - MESA_CC = gc; - return XMesaMakeCurrent(gc->xm_ctx, buf->xm_buf); -} - -GLboolean __MESA_shareContext(__GLcontext *gc, __GLcontext *gcShare) -{ - /* NOT_DONE */ - ErrorF("__MESA_shareContext\n"); - return GL_FALSE; -} - -GLboolean __MESA_copyContext(__GLcontext *dst, const __GLcontext *src, - GLuint mask) -{ - /* NOT_DONE */ - ErrorF("__MESA_copyContext\n"); - return GL_FALSE; -} - -GLboolean __MESA_forceCurrent(__GLcontext *gc) -{ - MESA_CC = gc; - return XMesaForceCurrent(gc->xm_ctx); -} - -GLboolean __MESA_notifyResize(__GLcontext *gc) -{ - /* NOT_DONE */ - ErrorF("__MESA_notifyResize\n"); - return GL_FALSE; -} - -void __MESA_notifyDestroy(__GLcontext *gc) -{ - /* NOT_DONE */ - ErrorF("__MESA_notifyDestroy\n"); - return; -} - -void __MESA_notifySwapBuffers(__GLcontext *gc) -{ - /* NOT_DONE */ - ErrorF("__MESA_notifySwapBuffers\n"); - return; -} - -struct __GLdispatchStateRec *__MESA_dispatchExec(__GLcontext *gc) -{ - /* NOT_DONE */ - ErrorF("__MESA_dispatchExec\n"); - return NULL; -} - -void __MESA_beginDispatchOverride(__GLcontext *gc) -{ - /* NOT_DONE */ - ErrorF("__MESA_beginDispatchOverride\n"); - return; -} - -void __MESA_endDispatchOverride(__GLcontext *gc) -{ - /* NOT_DONE */ - ErrorF("__MESA_endDispatchOverride\n"); - return; -} - -GLint __glEvalComputeK(GLenum target) -{ - switch (target) { - case GL_MAP1_VERTEX_4: - case GL_MAP1_COLOR_4: - case GL_MAP1_TEXTURE_COORD_4: - case GL_MAP2_VERTEX_4: - case GL_MAP2_COLOR_4: - case GL_MAP2_TEXTURE_COORD_4: - return 4; - case GL_MAP1_VERTEX_3: - case GL_MAP1_TEXTURE_COORD_3: - case GL_MAP1_NORMAL: - case GL_MAP2_VERTEX_3: - case GL_MAP2_TEXTURE_COORD_3: - case GL_MAP2_NORMAL: - return 3; - case GL_MAP1_TEXTURE_COORD_2: - case GL_MAP2_TEXTURE_COORD_2: - return 2; - case GL_MAP1_TEXTURE_COORD_1: - case GL_MAP2_TEXTURE_COORD_1: - case GL_MAP1_INDEX: - case GL_MAP2_INDEX: - return 1; - default: - return 0; - } -} - -GLuint __glFloorLog2(GLuint val) -{ - int c = 0; - - while (val > 1) { - c++; - val >>= 1; - } - return c; -} - diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_xmesa.c xc/lib/GL/mesa/src/drv/sis/sis_xmesa.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_xmesa.c Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_xmesa.c Tue Aug 19 16:58:21 2003 @@ -36,7 +36,7 @@ #include #include "sis_dri.h" -#include "sis_ctx.h" +#include "sis_context.h" #include "sis_mesa.h" #include @@ -162,26 +162,6 @@ IsDriverInit = GL_FALSE; } -/* from tdfx */ -extern void __driRegisterExtensions(void); /* silence compiler warning */ - -/* This function is called by libGL.so as soon as libGL.so is loaded. - * This is where we'd register new extension functions with the dispatcher. - */ -void __driRegisterExtensions(void) -{ -#if 0 - /* Example. Also look in fxdd.c for more details. */ - { - const int _gloffset_FooBarEXT = 555; /* just an example number! */ - if (_glapi_add_entrypoint("glFooBarEXT", _gloffset_FooBarEXT)) { - void *f = glXGetProcAddressARB("glFooBarEXT"); - assert(f); - } - } -#endif -} - GLvisual *XMesaCreateVisual(Display *dpy, __DRIscreenPrivate *driScrnPriv, const XVisualInfo *visinfo, @@ -289,136 +269,18 @@ } } -static XMesaBuffer SISCreateWindowBuffer ( Display *dpy, - __DRIscreenPrivate *driScrnPriv, - __DRIdrawablePrivate *driDrawPriv, - GLvisual *mesaVis, - XMesaContext xmesa) -{ - XMesaBuffer b = (XMesaBuffer) calloc (1, sizeof (struct xmesa_buffer)); - - if (SIS_VERBOSE&VERBOSE_SIS_BUFFER){ - fprintf(stderr, "SISCreateWindowBuffer: drawable ID=%lu\n", - (DWORD)driDrawPriv); - } - - if (!b) - return NULL; - - b->xm_context = NULL; - b->xm_visual = xmesa->xm_visual; - b->display = dpy; - b->pixmap_flag = GL_FALSE; - b->db_state = mesaVis->DBflag; - b->gl_buffer = driDrawPriv->mesaBuffer; - b->frontbuffer = driDrawPriv->draw; - - /* set 0 for buffer update */ - b->width = 0; - b->height = 0; - - if (b->backimage) - { -#if 0 - XMesaDestroyImage (b->backimage); -#else - free(b->backimage); -#endif - b->backimage = NULL; - } - -#if 0 - b->backimage = XCreateImage (b->display, - b->xm_visual->visinfo->visual, - GET_VISUAL_DEPTH (b->xm_visual), ZPixmap, 0, - NULL, b->width, b->height, 8, 0); -#else - b->backimage = (XMesaImage *) calloc (1, sizeof (XImage)); -#endif - - b->driDrawPriv = driDrawPriv; - - { - sisBufferInfo *buf_info; - - b->private = calloc (1, sizeof (sisBufferInfo)); - buf_info = (sisBufferInfo *)(b->private); - - buf_info->pZClearPacket = &buf_info->zClearPacket; - buf_info->pCbClearPacket = &buf_info->cbClearPacket; - } - - return b; -} - -GLframebuffer *XMesaCreatePixmapBuffer( Display *dpy, - __DRIscreenPrivate *driScrnPriv, - __DRIdrawablePrivate *driDrawPriv, - GLvisual *mesaVis) -{ - /* not implement yet */ - return NULL; -} - -static void SISDestroyBuffer (XMesaBuffer b) -{ - if (SIS_VERBOSE&VERBOSE_SIS_BUFFER){ - fprintf(stderr, "SISDestroyBuffer: b=%lu\n", (DWORD)b); - } - - if (b->backimage && b->backimage->data) - { - sisBufferInfo *priv = (sisBufferInfo *) b->private; - - sis_free_back_image (b, b->backimage, priv->bbFree); -#if SIS_STEREO - { - XMesaContext xmesa = (XMesaContext) b->xm_context; - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - GLcontext *ctx = xmesa->gl_ctx; - - if(hwcx->stereoEnabled){ - sis_final_stereo(ctx); - hwcx->stereoEnabled = GL_FALSE; - } - } -#endif - } - - if (b->depthbuffer) - { - sis_free_z_stencil_buffer (b); - } - - assert (b->private); - free (b->private); - b->private = NULL; - - if (b->xm_context) - b->xm_context->xm_buffer = NULL; - -#if 0 - XMesaDestroyImage (b->backimage); -#else - free(b->backimage); -#endif - - /* TODO : if b doesn't exist, do something */ - - free (b); -} void XMesaSwapBuffers(__DRIdrawablePrivate *driDrawPriv) { - __GLSiScontext *hwcx; + sisContextPtr smesa; if(!XMesa) return; FLUSH_VB( XMesa->gl_ctx, "swap buffers" ); - hwcx = (__GLSiScontext *) XMesa->private; - (hwcx->SwapBuffers)(XMesa->xm_buffer); + smesa = (sisContextPtr) XMesa->private; + (smesa->SwapBuffers)(XMesa->xm_buffer); } GLboolean XMesaUnbindContext(__DRIcontextPrivate *driContextPriv) @@ -427,88 +289,3 @@ return GL_TRUE; } -GLboolean -XMesaOpenFullScreen(__DRIcontextPrivate *driContextPriv) -{ - return GL_TRUE; -} - -GLboolean -XMesaCloseFullScreen(__DRIcontextPrivate *driContextPriv) -{ - return GL_TRUE; -} - -GLboolean XMesaMakeCurrent(__DRIcontextPrivate *driContextPriv, - __DRIdrawablePrivate *driDrawPriv, - __DRIdrawablePrivate *driReadPriv) -{ - if (driContextPriv) - { - XMesaContext c = (XMesaContext) driContextPriv->driverPrivate; - XMesaBuffer b; - - /* TODO: ??? */ - if ((c->gl_ctx == gl_get_current_context ()) && - (driContextPriv->driDrawablePriv == driDrawPriv) && - c->xm_buffer->wasCurrent) - { - return GL_TRUE; - } - - if (SIS_VERBOSE&VERBOSE_SIS_BUFFER){ - fprintf(stderr, "XMesaMakeCurrent: c=%lu, b=%lu\n", (DWORD)c, (DWORD)b); - fprintf(stderr, "XMesaMakeCurrent: drawable ID=%lu\n", (DWORD)b->frontbuffer); - fprintf(stderr, "XMesaMakeCurrent: width=%d, height=%d\n", - b->width, b->height); - { - __DRIdrawablePrivate *dPriv = c->driContextPriv->driDrawablePriv; - fprintf(stderr, "XMesaMakeCurrent: width=%d, height=%d\n", - dPriv->w, dPriv->h); - } - } - - b = SISCreateWindowBuffer(c->display, - driContextPriv->driScreenPriv, - driDrawPriv, - c->gl_ctx->Visual, - c); - - if (c->xm_buffer){ - /* TODO: ??? */ - c->xm_buffer->xm_context = NULL; - SISDestroyBuffer(c->xm_buffer); - } - - b->xm_context = c; - c->xm_buffer = b; - - gl_make_current (c->gl_ctx, b->gl_buffer); - XMesa = c; - - if(b->width == 0){ - GLuint width, height; - - sis_GetBufferSize (c->gl_ctx, &width, &height); - } - - sis_update_drawable_state(c->gl_ctx); - - if (c->gl_ctx->Viewport.Width == 0) - { - /* initialize viewport to window size */ - gl_Viewport (c->gl_ctx, 0, 0, b->width, b->height); - c->gl_ctx->Scissor.Width = b->width; - c->gl_ctx->Scissor.Height = b->height; - } - - c->xm_buffer->wasCurrent = GL_TRUE; - } - else - { - gl_make_current (NULL, NULL); - XMesa = NULL; - } - - return GL_TRUE; -} diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_xmesaP.h xc/lib/GL/mesa/src/drv/sis/sis_xmesaP.h --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_xmesaP.h Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_xmesaP.h Tue Aug 12 12:03:20 2003 @@ -26,37 +26,16 @@ #ifndef XMESAP_H #define XMESAP_H +#include +#include +#include "GL/xmesa_x.h" +#include "GL/gl.h" -#ifdef XFree86Server -# include "GL/xf86glx.h" -# include "xf86glx_util.h" -#else -# ifdef GLX_DIRECT_RENDERING -# include "dri_mesa.h" -# endif -#endif +#include "dri_util.h" -#ifdef XFree86Server -# include "GL/xmesa.h" -#else -# include -# include -# include "GL/xmesa_x.h" -# include "GL/gl.h" typedef struct xmesa_context *XMesaContext; typedef struct xmesa_visual *XMesaVisual; typedef struct xmesa_buffer *XMesaBuffer; -#endif - -#include "types.h" - -#if defined(GLX_DIRECT_RENDERING) && !defined(XFree86Server) -# include "xdriP.h" -#else -# define DRI_DRAWABLE_ARG -# define DRI_DRAWABLE_PARM -# define DRI_CTX_ARG -#endif struct xmesa_visual { GLvisual *gl_visual; /* Device independent visual parameters */ @@ -73,7 +52,7 @@ XMesaDisplay *display; /* == xm_visual->display */ -#if defined(GLX_DIRECT_RENDERING) && !defined(XFree86Server) +#if defined(GLX_DIRECT_RENDERING) __DRIcontextPrivate *driContextPriv; /* back pointer to DRI context * used for locking */ @@ -100,7 +79,7 @@ GLint bottom; /* used for FLIP macro below */ -#if defined(GLX_DIRECT_RENDERING) && !defined(XFree86Server) +#if defined(GLX_DIRECT_RENDERING) __DRIdrawablePrivate *driDrawPriv; /* back pointer to DRI drawable * used for direct access to framebuffer */ diff -ruN ../xc/xc/lib/GL/mesa/src/drv/sis/sis_xwin.c xc/lib/GL/mesa/src/drv/sis/sis_xwin.c --- ../xc/xc/lib/GL/mesa/src/drv/sis/sis_xwin.c Tue Aug 12 12:03:56 2003 +++ xc/lib/GL/mesa/src/drv/sis/sis_xwin.c Tue Aug 12 12:03:20 2003 @@ -32,87 +32,9 @@ * */ -#include "sis_ctx.h" +#include "sis_context.h" #include "sis_mesa.h" -#ifdef XFree86Server - -GLboolean -sis_get_clip_rects (XMesaContext xmesa, BoxPtr *ppExtents, int *pCount) -{ - XMesaDrawable d = xmesa->xm_buffer->frontbuffer; - - if (d->type == DRAWABLE_WINDOW) - { - RegionPtr pClipList = &((WindowPtr) d)->clipList; - RegDataPtr data = pClipList->data; - - if (data) - { - *ppExtents = - (BoxPtr) ((GLubyte *) (pClipList->data) + sizeof (RegDataRec)); - *pCount = data->numRects; - } - else - { - *ppExtents = &(pClipList->extents); - *pCount = 1; - } - } - else{ - /* Pixmap */ - /* - * TODO : sis_clear_color_buffer, sis_line_clip, sis_tri_clip don't - * consider this situation and result in page fault - */ - *ppExtents = NULL; - *pCount = 0; - return GL_FALSE; - } - - return GL_TRUE; -} - -void * -sis_get_drawable_pos (XMesaContext xmesa) -{ - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; - XMesaDrawable d = xmesa->xm_buffer->frontbuffer; - - return GET_FbBase (hwcx) + - (d->x) * GET_DEPTH (hwcx) + (d->y) * GET_PITCH (hwcx); -} - -void -sis_get_drawable_origin (XMesaContext xmesa, GLuint * x, GLuint * y) -{ - XMesaDrawable d = xmesa->xm_buffer->frontbuffer; - - *x = d->x; - *y = d->y; -} - -void -sis_get_drawable_size (XMesaContext xmesa, GLuint * w, GLuint * h) -{ - XMesaDrawable d = xmesa->xm_buffer->frontbuffer; - - *w = d->width; - *h = d->height; -} - -void -sis_get_drawable_box (XMesaContext xmesa, BoxPtr pBox) -{ - XMesaDrawable d = xmesa->xm_buffer->frontbuffer; - - pBox->x1 = d->x; - pBox->y1 = d->y; - pBox->x2 = d->x + d->width; - pBox->y2 = d->y + d->height; -} - -#else GLboolean sis_get_clip_rects (XMesaContext xmesa, BoxPtr * ppExtents, int *pCount) @@ -141,7 +63,7 @@ void * sis_get_drawable_pos (XMesaContext xmesa) { - __GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private; + sisContextPtr smesa = SIS_CONTEXT(ctx); __DRIdrawablePrivate *dPriv = xmesa->driContextPriv->driDrawablePriv; @@ -151,8 +73,8 @@ dPriv); */ - return GET_FbBase (hwcx) + (dPriv->x) * GET_DEPTH (hwcx) + - (dPriv->y) * GET_PITCH (hwcx); + return GET_FbBase (smesa) + (dPriv->x) * GET_DEPTH (smesa) + + (dPriv->y) * GET_PITCH (smesa); } void @@ -201,5 +123,3 @@ pBox->x2 = dPriv->x + dPriv->w; pBox->y2 = dPriv->y + dPriv->h; } - -#endif diff -ruN ../xc/xc/programs/Xserver/hw/xfree86/drivers/sis/init301.c xc/programs/Xserver/hw/xfree86/drivers/sis/init301.c --- ../xc/xc/programs/Xserver/hw/xfree86/drivers/sis/init301.c Wed Dec 31 16:00:00 1969 +++ xc/programs/Xserver/hw/xfree86/drivers/sis/init301.c Wed Aug 20 01:48:03 2003 @@ -0,0 +1,10798 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/sis/init301.c,v 1.9 2003/01/29 15:42:16 eich Exp $ */ +/* + * Mode switching code (CRT2 section) for SiS 300/540/630/730/315/550/650/740/330 + * (Universal module for Linux kernel framebuffer, XFree86 4.x) + * + * Assembler-To-C translation + * Copyright 2002, 2003 by Thomas Winischhofer + * Minor parts Copyright SiS, Inc. + * + * Based on BIOS + * 1.10.07, 1.10a for SiS650/LVDS+CH7019 + * 1.11.05 for 650/LVDS (w/o Chrontel) + * 1.07.1b, 1.10.6s, 1.11.6w, 1.11.7w, 1.11.8r for SiS650/301(B/LV), 650/301LVx + * 2.04.50 (I) and 2.04.5c (II) for SiS630/301(B) + * 2.02.3b, 2.03.02, 2.04.2c, 2.04.5c, 2.07a and 2.08.b3 for 630/LVDS/LVDS+CH7005 + * 2.04.5c, 2.04.6c for 730+LVDS+CH7005 + * 1.09b for 315/301(B) + * 1.16.51 for 300+301LVX (ECS A907) + * 1.01.03 for 330 (Xabre 400) + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the copyright holder not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The copyright holder makes no representations + * about the suitability of this software for any purpose. It is provided + * "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + * TW says: This code looks awful, I know. But please don't do anything about + * this otherwise debugging will be hell. + * The code is extremely fragile as regards the different chipsets, different + * video bridges and combinations thereof. If anything is changed, extreme + * care has to be taken that that change doesn't break it for other chipsets, + * bridges or combinations thereof. + * All comments in this file are by me, regardless if they are marked TW or not. + * + */ + +#include "init301.h" + +#if 0 +#define TWNEWPANEL +#endif + +#if 1 /* TW: Emulate 650/301LVx BIOS 1.10.6s (should be set) */ +#define SIS650301NEW +#endif + +#ifdef SIS300 +#include "oem300.h" +#endif + +#ifdef SIS315H +#include "oem310.h" +#endif + +#define SiS_I2CDELAY 1000 +#define SiS_I2CDELAYSHORT 333 + +BOOLEAN +SiS_SetCRT2Group301(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo, + PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT ModeIdIndex; + USHORT RefreshRateTableIndex; + + SiS_Pr->SiS_SetFlag |= ProgrammingCRT2; + + if(!SiS_Pr->UseCustomMode) { + SiS_SearchModeID(SiS_Pr,ROMAddr,&ModeNo,&ModeIdIndex); + } else { + ModeIdIndex = 0; + } + + /* TW: Used for shifting CR33 */ + SiS_Pr->SiS_SelectCRT2Rate = 4; + + SiS_UnLockCRT2(SiS_Pr, HwDeviceExtension, BaseAddr); + + RefreshRateTableIndex = SiS_GetRatePtrCRT2(SiS_Pr, ROMAddr,ModeNo,ModeIdIndex,HwDeviceExtension); + + SiS_SaveCRT2Info(SiS_Pr,ModeNo); + + if(SiS_LowModeStuff(SiS_Pr,ModeNo,HwDeviceExtension)) { + SiS_DisableBridge(SiS_Pr,HwDeviceExtension,BaseAddr); + if((SiS_Pr->SiS_IF_DEF_LVDS == 1) && (HwDeviceExtension->jChipType == SIS_730)) { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x00,0x80); + } + SiS_SetCRT2ModeRegs(SiS_Pr,BaseAddr,ModeNo,ModeIdIndex,HwDeviceExtension); + } + + if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) { + SiS_LockCRT2(SiS_Pr,HwDeviceExtension, BaseAddr); + SiS_DisplayOn(SiS_Pr); + return(TRUE); + } + + if(SiS_Pr->UseCustomMode) return(FALSE); + + SiS_GetCRT2Data(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + HwDeviceExtension); + + /* LVDS, 650/301LV(LCDA) and 630/301B BIOS set up Panel Link */ + /* 300+LV does not */ + if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || + ((HwDeviceExtension->jChipType != SIS_300) && (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV))) { + SiS_GetLVDSDesData(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + HwDeviceExtension); + } else { + SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0; + } + +#ifdef LINUX_XF86 +#ifdef TWDEBUG + xf86DrvMsg(0, X_INFO, "(init301: LCDHDES 0x%03x LCDVDES 0x%03x)\n", SiS_Pr->SiS_LCDHDES, SiS_Pr->SiS_LCDVDES); + xf86DrvMsg(0, X_INFO, "(init301: HDE 0x%03x VDE 0x%03x)\n", SiS_Pr->SiS_HDE, SiS_Pr->SiS_VDE); + xf86DrvMsg(0, X_INFO, "(init301: VGAHDE 0x%03x VGAVDE 0x%03x)\n", SiS_Pr->SiS_VGAHDE, SiS_Pr->SiS_VGAVDE); + xf86DrvMsg(0, X_INFO, "(init301: HT 0x%03x VT 0x%03x)\n", SiS_Pr->SiS_HT, SiS_Pr->SiS_VT); + xf86DrvMsg(0, X_INFO, "(init301: VGAHT 0x%03x VGAVT 0x%03x)\n", SiS_Pr->SiS_VGAHT, SiS_Pr->SiS_VGAVT); +#endif +#endif + + if(SiS_LowModeStuff(SiS_Pr,ModeNo,HwDeviceExtension)) { + SiS_SetGroup1(SiS_Pr,BaseAddr,ROMAddr,ModeNo,ModeIdIndex, + HwDeviceExtension,RefreshRateTableIndex); + } + + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + + if(SiS_LowModeStuff(SiS_Pr,ModeNo,HwDeviceExtension)) { + + SiS_SetGroup2(SiS_Pr,BaseAddr,ROMAddr,ModeNo,ModeIdIndex, + RefreshRateTableIndex,HwDeviceExtension); + SiS_SetGroup3(SiS_Pr,BaseAddr,ROMAddr,ModeNo,ModeIdIndex, + HwDeviceExtension); + SiS_SetGroup4(SiS_Pr,BaseAddr,ROMAddr,ModeNo,ModeIdIndex, + RefreshRateTableIndex,HwDeviceExtension); + SiS_SetGroup5(SiS_Pr,HwDeviceExtension, BaseAddr,ROMAddr, + ModeNo,ModeIdIndex); + + /* TW: 630/301B BIOS does all this: */ + if((HwDeviceExtension->jChipType < SIS_315H) && + (HwDeviceExtension->jChipType != SIS_300)) { + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) { + if(!((SiS_Pr->SiS_SetFlag & CRT2IsVGA) && ((ModeNo == 0x03) || (ModeNo = 0x10)))) { + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { + SiS_ModCRT1CRTC(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex, + RefreshRateTableIndex,HwDeviceExtension); + } + } + } + SiS_SetCRT2ECLK(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex, + RefreshRateTableIndex,HwDeviceExtension); + } + } + + } + + } else { + + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) { + if (SiS_Pr->SiS_IF_DEF_TRUMPION == 0) { + SiS_ModCRT1CRTC(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex, + RefreshRateTableIndex,HwDeviceExtension); + } + } + if(SiS_Pr->SiS_IF_DEF_FSTN == 0) { + SiS_SetCRT2ECLK(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex, + RefreshRateTableIndex,HwDeviceExtension); + } + if(SiS_LowModeStuff(SiS_Pr,ModeNo,HwDeviceExtension)) { + if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { + /* TW: Inserted from 650/LVDS BIOS */ + if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { + if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { + SiS_SetCH701xForLCD(SiS_Pr,HwDeviceExtension,BaseAddr); + } + } + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + /* TW: Set Chrontel registers only if CRT2 is TV */ + SiS_SetCHTVReg(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex, + RefreshRateTableIndex); + } + } + } + + } + +#ifdef SIS300 + if ( (HwDeviceExtension->jChipType == SIS_540) || + (HwDeviceExtension->jChipType == SIS_630) || + (HwDeviceExtension->jChipType == SIS_730) || + (HwDeviceExtension->jChipType == SIS_300) ) + { + if(SiS_LowModeStuff(SiS_Pr,ModeNo,HwDeviceExtension)) { + if(SiS_Pr->SiS_UseOEM) { + if((SiS_Pr->SiS_UseROM) && ROMAddr && (SiS_Pr->SiS_UseOEM == -1)) { + if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) { + SiS_OEM300Setting(SiS_Pr,HwDeviceExtension,BaseAddr,ROMAddr,ModeNo); + } + } else { + SiS_OEM300Setting(SiS_Pr,HwDeviceExtension,BaseAddr,ROMAddr,ModeNo); + } + } + } + } +#endif + +#ifdef SIS315H + if ( (HwDeviceExtension->jChipType == SIS_315H) || + (HwDeviceExtension->jChipType == SIS_315) || + (HwDeviceExtension->jChipType == SIS_315PRO)|| + (HwDeviceExtension->jChipType == SIS_550) || + (HwDeviceExtension->jChipType == SIS_740) || + (HwDeviceExtension->jChipType == SIS_650) || + (HwDeviceExtension->jChipType == SIS_330) ) + { + if(SiS_LowModeStuff(SiS_Pr,ModeNo,HwDeviceExtension)) { +#ifdef SIS650301NEW + SiS_FinalizeLCD(SiS_Pr,BaseAddr,ROMAddr,ModeNo,ModeIdIndex, HwDeviceExtension); +#else + SiS_OEMLCD(SiS_Pr,HwDeviceExtension,BaseAddr,ROMAddr,ModeNo,ModeIdIndex); +#endif + if(SiS_Pr->SiS_UseOEM) { + SiS_OEM310Setting(SiS_Pr,HwDeviceExtension,BaseAddr,ROMAddr,ModeNo,ModeIdIndex); + } + SiS_CRT2AutoThreshold(SiS_Pr,BaseAddr); + } + } +#endif + + if(HwDeviceExtension->jChipType < SIS_315H) { + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { + if(HwDeviceExtension->jChipType != SIS_730) { + SiS_DisplayOn(SiS_Pr); + } + } + } + + if(SiS_LowModeStuff(SiS_Pr,ModeNo,HwDeviceExtension)) { + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { + if(HwDeviceExtension->jChipType == SIS_730) { + SiS_DisplayOn(SiS_Pr); + } + } + SiS_EnableBridge(SiS_Pr,HwDeviceExtension,BaseAddr); + } + + SiS_DisplayOn(SiS_Pr); + + if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + /* TW: Disable LCD panel when using TV */ + SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x11,0x0C); + } else { + /* TW: Disable TV when using LCD */ + SiS_SetCH70xxANDOR(SiS_Pr,0x010E,0xF8); + } + } + + if(SiS_LowModeStuff(SiS_Pr,ModeNo,HwDeviceExtension)) { + SiS_LockCRT2(SiS_Pr,HwDeviceExtension, BaseAddr); + } + + return 1; +} + +/* TW: Checked with 330, 650/LVDS (1.10.07) and 630+301B/LVDS BIOS */ +BOOLEAN +SiS_LowModeStuff(SiS_Private *SiS_Pr, USHORT ModeNo, + PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT temp,temp1,temp2; + + if((ModeNo != 0x03) && (ModeNo != 0x10) && (ModeNo != 0x12)) + return(1); + temp = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x11); + SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x11,0x80); + temp1 = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x00); + SiS_SetReg1(SiS_Pr->SiS_P3d4,0x00,0x55); + temp2 = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x00); + SiS_SetReg1(SiS_Pr->SiS_P3d4,0x00,temp1); + SiS_SetReg1(SiS_Pr->SiS_P3d4,0x11,temp); + if((HwDeviceExtension->jChipType >= SIS_315H) || + (HwDeviceExtension->jChipType == SIS_300)) { + if(temp2 == 0x55) return(0); + else return(1); + } else { + if(temp2 != 0x55) return(1); + else { + SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01); + return(0); + } + } +} + +/* TW: Set Part1 registers */ +/* TW: Checked with 650/LVDS (1.10.07), 650/301LV (II) and 630/301B (II) BIOS */ +/* TW: Pass 2: Checked with 650/301LVx 1.10.6s, 630/301B 2.04.5a */ +void +SiS_SetGroup1(SiS_Private *SiS_Pr,USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo, + USHORT ModeIdIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension, + USHORT RefreshRateTableIndex) +{ + USHORT temp=0, tempax=0, tempbx=0, tempcx=0; + USHORT pushbx=0, CRT1Index=0; +#ifdef SIS315H + USHORT pushcx=0, tempbl=0; +#endif + USHORT modeflag, resinfo=0; + + if(ModeNo<=0x13) { + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + } else { + CRT1Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC; + resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + } + + /* TW: LCDA exists with LVDS as well */ + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { + + SiS_SetCRT2Sync(SiS_Pr,BaseAddr,ROMAddr,ModeNo, + RefreshRateTableIndex,HwDeviceExtension); + + SiS_SetGroup1_LCDA(SiS_Pr,BaseAddr,ROMAddr,ModeNo,ModeIdIndex, + HwDeviceExtension,RefreshRateTableIndex); + + } else { + + if( (HwDeviceExtension->jChipType >= SIS_315H) && + (SiS_Pr->SiS_IF_DEF_LVDS == 1) && + (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { + + SiS_SetCRT2Sync(SiS_Pr,BaseAddr,ROMAddr,ModeNo, + RefreshRateTableIndex,HwDeviceExtension); + + } else { + + SiS_SetCRT2Offset(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex, + RefreshRateTableIndex,HwDeviceExtension); + + if (HwDeviceExtension->jChipType < SIS_315H ) { +#ifdef SIS300 + SiS_SetCRT2FIFO_300(SiS_Pr,ROMAddr,ModeNo,HwDeviceExtension); +#endif + } else { +#ifdef SIS315H + SiS_SetCRT2FIFO_310(SiS_Pr,ROMAddr,ModeNo,HwDeviceExtension); +#endif + } + + SiS_SetCRT2Sync(SiS_Pr,BaseAddr,ROMAddr,ModeNo, + RefreshRateTableIndex,HwDeviceExtension); + + /* 1. Horizontal setup */ + + if (HwDeviceExtension->jChipType < SIS_315H ) { + +#ifdef SIS300 /* ------------- 300 series --------------*/ + + temp = (SiS_Pr->SiS_VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */ + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x08,temp); /* TW: CRT2 Horizontal Total */ + + temp = (((SiS_Pr->SiS_VGAHT - 1) & 0xFF00) >> 8) << 4; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0f,temp); /* TW: CRT2 Horizontal Total Overflow [7:4] */ + + temp = (SiS_Pr->SiS_VGAHDE + 12) & 0x0FF; /* BTVGA2HDEE 0x0A,0x0C */ + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x0A,temp); /* TW: CRT2 Horizontal Display Enable End */ + + pushbx = SiS_Pr->SiS_VGAHDE + 12; /* bx BTVGA@HRS 0x0B,0x0C */ + tempcx = (SiS_Pr->SiS_VGAHT - SiS_Pr->SiS_VGAHDE) >> 2; + tempbx = pushbx + tempcx; + tempcx <<= 1; + tempcx += tempbx; + + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC){ + /* CRT1Index &= 0x3F; - Not any longer */ + tempbx = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[4]; + tempbx |= ((SiS_Pr->SiS_CRT1Table[CRT1Index].CR[14] & 0xC0) << 2); + tempbx = (tempbx - 1) << 3; + tempcx = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[5]; + tempcx &= 0x1F; + temp = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[15]; + temp = (temp & 0x04) << (6-2); + tempcx = ((tempcx | temp) - 1) << 3; + } + + if((SiS_Pr->SiS_VBInfo & SetCRT2ToTV) && (resinfo == 0x08)){ + if(!(SiS_Pr->SiS_VBInfo & SetPALTV)){ + tempbx = 1040; + tempcx = 1042; + } + } + } + + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x0B,temp); /* TW: CRT2 Horizontal Retrace Start */ +#endif /* SIS300 */ + + } else { + +#ifdef SIS315H /* ----------------- 310/325 series ------------- */ + + tempcx = SiS_Pr->SiS_VGAHT; /* BTVGA2HT 0x08,0x09 */ + pushcx = tempcx; + if(modeflag & HalfDCLK) { + if((SiS_Pr->SiS_IF_DEF_LVDS == 1) && (SiS_Pr->SiS_IF_DEF_CH70xx == 0)) { + tempax = SiS_Pr->SiS_VGAHDE >> 1; + tempcx = SiS_Pr->SiS_HT - SiS_Pr->SiS_HDE + tempax; + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) { + tempcx = SiS_Pr->SiS_HT - tempax; + } + } else { + tempcx >>= 1; + } + } + tempcx--; + + temp = tempcx & 0xff; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x08,temp); /* TW: CRT2 Horizontal Total */ + + temp = ((tempcx & 0xff00) >> 8) << 4; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0F,temp); /* TW: CRT2 Horizontal Total Overflow [7:4] */ + + tempcx = pushcx; /* BTVGA2HDEE 0x0A,0x0C */ + tempbx = SiS_Pr->SiS_VGAHDE; + tempcx -= tempbx; + tempcx >>= 2; + if(modeflag & HalfDCLK) { + tempbx >>= 1; + tempcx >>= 1; + } + tempbx += 16; + + temp = tempbx & 0xff; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x0A,temp); /* TW: CRT2 Horizontal Display Enable End */ + + pushbx = tempbx; + tempcx >>= 1; + tempbx += tempcx; + tempcx += tempbx; + + if(SiS_Pr->SiS_IF_DEF_LVDS==0) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { + tempbx = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[4]; + tempbx |= ((SiS_Pr->SiS_CRT1Table[CRT1Index].CR[14] & 0xC0) << 2); + tempbx = (tempbx - 3) << 3; /*(VGAHRS-3)*8 */ + tempcx = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[5]; + tempcx &= 0x1F; + temp = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[15]; + temp = (temp & 0x04) << (5-2); /* VGAHRE D[5] */ + tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */ + tempcx &= 0x00FF; + tempcx |= (tempbx & 0xFF00); + tempbx += 16; + tempcx += 16; + tempax = SiS_Pr->SiS_VGAHT; + if (modeflag & HalfDCLK) tempax >>= 1; + tempax--; + if (tempcx > tempax) tempcx = tempax; + } + if((SiS_Pr->SiS_VBInfo & SetCRT2ToTV) && (resinfo == 0x08)){ + if(!(SiS_Pr->SiS_VBInfo & SetPALTV)){ + tempbx = 1040; + tempcx = 1042; + } + } + /* TW: Makes no sense, but is in 650/301LVx 1.10.6s */ + if((SiS_Pr->SiS_VBInfo & SetCRT2ToTV) && (resinfo == 0x08)){ + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV)) { + if(!(SiS_Pr->SiS_VBInfo & SetPALTV)) { + tempbx = 1040; + tempcx = 1042; + } + } + } + } + + temp = tempbx & 0xff; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x0B,temp); /* TW: CRT2 Horizontal Retrace Start */ +#endif /* SIS315H */ + + } /* 310 series */ + + /* TW: The following is done for all bridge/chip types/series */ + + tempax = tempbx & 0xFF00; + tempbx = pushbx; + tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4); + tempax |= (tempbx & 0xFF00); + temp = (tempax & 0xFF00) >> 8; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x0C,temp); /* TW: Overflow */ + + temp = tempcx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x0D,temp); /* TW: CRT2 Horizontal Retrace End */ + + /* 2. Vertical setup */ + + tempcx = SiS_Pr->SiS_VGAVT - 1; + temp = tempcx & 0x00FF; + + /* TW: Matches 650/301LV, 650/LVDS, 630/LVDS(CLEVO), 630/LVDS(no-Ch7005) */ + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { + if(HwDeviceExtension->jChipType < SIS_315H) { + if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { + if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO|SetCRT2ToAVIDEO)) { + temp--; + } + } + } else { + temp--; + } + } else if(HwDeviceExtension->jChipType >= SIS_315H) { + /* TW: Inserted from 650/301LVx 1.10.6s */ + temp--; + } + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x0E,temp); /* TW: CRT2 Vertical Total */ + + tempbx = SiS_Pr->SiS_VGAVDE - 1; + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x0F,temp); /* TW: CRT2 Vertical Display Enable End */ + + temp = ((tempbx & 0xFF00) << 3) >> 8; + temp |= ((tempcx & 0xFF00) >> 8); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x12,temp); /* TW: Overflow (and HWCursor Test Mode) */ + + /* TW: For 650/LVDS (1.10.07), 650/301LVx (1.10.6s) */ + if(HwDeviceExtension->jChipType >= SIS_315H) { + tempbx++; + tempax = tempbx; + tempcx++; + tempcx -= tempax; + tempcx >>= 2; + tempbx += tempcx; + if(tempcx < 4) tempcx = 4; + tempcx >>= 2; + tempcx += tempbx; + tempcx++; + } else { + /* TW: For 300/630/LVDS/301B: */ + tempbx = (SiS_Pr->SiS_VGAVT + SiS_Pr->SiS_VGAVDE) >> 1; /* BTVGA2VRS 0x10,0x11 */ + tempcx = ((SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) >> 4) + tempbx + 1; /* BTVGA2VRE 0x11 */ + } + + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC){ + tempbx = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[8]; + temp = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[7]; + if(temp & 0x04) tempbx |= 0x0100; + if(temp & 0x80) tempbx |= 0x0200; + temp = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[13]; + if(temp & 0x08) tempbx |= 0x0400; + temp = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[9]; + tempcx = (tempcx & 0xFF00) | (temp & 0x00FF); + } + } + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x10,temp); /* TW: CRT2 Vertical Retrace Start */ + + temp = ((tempbx & 0xFF00) >> 8) << 4; + temp |= (tempcx & 0x000F); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x11,temp); /* TW: CRT2 Vert. Retrace End; Overflow; "Enable CRTC Check" */ + + /* 3. Panel compensation delay */ + + if(HwDeviceExtension->jChipType < SIS_315H) { + +#ifdef SIS300 /* ---------- 300 series -------------- */ + + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + temp = 0x20; + + if(HwDeviceExtension->jChipType == SIS_300) { + temp = 0x10; + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) temp = 0x2c; + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) temp = 0x20; + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x960) temp = 0x24; + } + if(SiS_Pr->SiS_VBType & VB_SIS301) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) temp = 0x20; + } +#if 0 /* TW: Not in 630/301B BIOS */ + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x960) temp = 0x24; +#endif + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x08; +#ifdef oldHV + if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) { + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) temp = 0x2c; + else temp = 0x20; + } +#endif + if((ROMAddr) && (SiS_Pr->SiS_UseROM) && (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) { + if(ROMAddr[0x220] & 0x80) { + if(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV-SetCRT2ToHiVisionTV)) + temp = ROMAddr[0x221]; + else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) + temp = ROMAddr[0x222]; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) + temp = ROMAddr[0x223]; + else + temp = ROMAddr[0x224]; + temp &= 0x3c; + } + } + if(HwDeviceExtension->pdc) { + temp = HwDeviceExtension->pdc & 0x3c; + } + } else { + temp = 0x20; + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480) temp = 0x04; + } + if((ROMAddr) && SiS_Pr->SiS_UseROM) { + if(ROMAddr[0x220] & 0x80) { + temp = ROMAddr[0x220] & 0x3c; + } + } + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + if(HwDeviceExtension->pdc) { + temp = HwDeviceExtension->pdc & 0x3c; + } + } + } + + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x03C,temp); /* TW: Panel Link Delay Compensation; (Software Command Reset; Power Saving) */ + +#endif /* SIS300 */ + + } else { + +#ifdef SIS315H /* ----------- 310/325 series ---------------*/ + + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + temp = 0x10; + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) temp = 0x2c; + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) temp = 0x20; + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x960) temp = 0x24; + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x08; + tempbl = 0xF0; + } else { + temp = 0x00; + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x0a; + tempbl = 0xF0; + if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempbl = 0x0F; + } + } +#if 0 /* TW: Not done in 650/301LVx 1.10.6s */ + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + temp >>= 2; + } +#endif + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,tempbl,temp); /* TW: Panel Link Delay Compensation */ + + tempax = 0; + if (modeflag & DoubleScanMode) tempax |= 0x80; + if (modeflag & HalfDCLK) tempax |= 0x40; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2C,0x3f,tempax); + +#endif /* SIS315H */ + + } + + } /* Slavemode */ + + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + + /* TW: 630/301B BIOS sets up Panel Link, too! (300/301LV and 650/LV do not) */ + if( (HwDeviceExtension->jChipType < SIS_315H) && + (HwDeviceExtension->jChipType != SIS_300) && + (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && + (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) ) { + + SiS_SetGroup1_LVDS(SiS_Pr,BaseAddr,ROMAddr,ModeNo,ModeIdIndex, + HwDeviceExtension,RefreshRateTableIndex); + + } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { + + SiS_SetGroup1_301(SiS_Pr,BaseAddr,ROMAddr,ModeNo,ModeIdIndex, + HwDeviceExtension,RefreshRateTableIndex); + } + + } else { + + if(HwDeviceExtension->jChipType < SIS_315H) { + SiS_SetGroup1_LVDS(SiS_Pr,BaseAddr,ROMAddr,ModeNo,ModeIdIndex, + HwDeviceExtension,RefreshRateTableIndex); + } else { + /* TW: For 650/LVDS */ + if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { + if((!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) || (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { + SiS_SetGroup1_LVDS(SiS_Pr,BaseAddr,ROMAddr,ModeNo,ModeIdIndex, + HwDeviceExtension,RefreshRateTableIndex); + } + } else { + SiS_SetGroup1_LVDS(SiS_Pr,BaseAddr,ROMAddr,ModeNo,ModeIdIndex, + HwDeviceExtension,RefreshRateTableIndex); + } + } + + } + } /* LCDA */ +} + +/* TW: Checked against 650/301LV and 630/301B (II) BIOS */ +/* TW: Pass 2: Checked with 650/301LVx (1.10.6s) and 630/301B (2.04.5a) */ +void +SiS_SetGroup1_301(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT RefreshRateTableIndex) +{ + USHORT push1,push2; + USHORT tempax,tempbx,tempcx,temp; + USHORT resinfo,modeflag; + + if(ModeNo<=0x13) { + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo; + } else { + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; + } + + /* TW: The following is only done if bridge is in slave mode: */ + + tempax = 0xFFFF; + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempax = SiS_GetVGAHT2(SiS_Pr); + + /* TW: 630/301B, 300/301LV do not check this flag, assume it is set */ + /* 650/LV and 650/301LVx BIOS do not check this either; so we set it... */ + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + modeflag |= Charx8Dot; + } + + if(modeflag & Charx8Dot) tempcx = 0x08; + else tempcx = 0x09; + + if(tempax >= SiS_Pr->SiS_VGAHT) tempax = SiS_Pr->SiS_VGAHT; + + if(modeflag & HalfDCLK) tempax >>= 1; + + tempax = (tempax / tempcx) - 5; + tempbx = tempax & 0xFF; + + temp = 0xFF; /* set MAX HT */ + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x03,temp); + + tempax = SiS_Pr->SiS_VGAHDE; /* 0x04 Horizontal Display End */ + if(modeflag & HalfDCLK) tempax >>= 1; + tempax = (tempax / tempcx) - 1; + tempbx |= ((tempax & 0x00FF) << 8); + temp = tempax & 0xFF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x04,temp); + + temp = (tempbx & 0xFF00) >> 8; + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + if(!(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) { + temp += 2; + } +#ifdef oldHV + if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) { + if(resinfo == 7) temp -= 2; + } +#endif + } + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x05,temp); /* 0x05 Horizontal Display Start */ + + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x06,0x03); /* 0x06 Horizontal Blank end */ + +#ifdef oldHV + if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) { + temp = (tempbx & 0x00FF) - 1; + if(!(modeflag & HalfDCLK)) { + temp -= 6; + if(SiS_Pr->SiS_SetFlag & TVSimuMode) { + temp -= 2; + if(ModeNo > 0x13) temp -= 10; + } + } + } else { +#endif + tempcx = tempbx & 0x00FF; + tempbx = (tempbx & 0xFF00) >> 8; + tempcx = (tempcx + tempbx) >> 1; + temp = (tempcx & 0x00FF) + 2; + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV){ + temp--; + if(!(modeflag & HalfDCLK)){ + if((modeflag & Charx8Dot)){ + temp += 4; + if(SiS_Pr->SiS_VGAHDE >= 800) temp -= 6; + /* TW: Inserted from 650/301 BIOS, 630/301B/301 don't do this */ + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(SiS_Pr->SiS_VGAHDE == 800) temp += 2; + } + } + } + } else { + if(!(modeflag & HalfDCLK)) { + temp -= 4; + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1280x960) { + if(SiS_Pr->SiS_VGAHDE >= 800){ + temp -= 7; + if(HwDeviceExtension->jChipType < SIS_315H) { + /* 650/301LV(x) does not do this, 630/301B, 300/301LV do */ + if(SiS_Pr->SiS_ModeType == ModeEGA){ + if(SiS_Pr->SiS_VGAVDE == 1024){ + temp += 15; + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1280x1024) temp += 7; + } + } + } + if(SiS_Pr->SiS_VGAHDE >= 1280){ + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1280x960) { + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) temp += 28; + } + } + } + } + } + } +#ifdef oldHV + } +#endif + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x07,temp); /* 0x07 Horizontal Retrace Start */ + + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x08,0x00); /* 0x08 Horizontal Retrace End */ + + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + if(SiS_Pr->SiS_SetFlag & TVSimuMode) { + if(ModeNo <= 1) { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x07,0x2a); + if(!(SiS_Pr->SiS_VBInfo & SetPALTV)) { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x08,0x61); + } else { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x08,0x41); + } + } else if(SiS_Pr->SiS_ModeType == ModeText) { + if(!(SiS_Pr->SiS_VBInfo & SetPALTV)) { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x07,0x54); + } else { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x07,0x55); + } + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x08,0x00); + } else if(ModeNo <= 0x13) { + if(modeflag & HalfDCLK) { + if(!(SiS_Pr->SiS_VBInfo & SetPALTV)) { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x07,0x30); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x08,0x03); + } else { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x07,0x2f); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x08,0x02); + } + } else { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x07,0x5b); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x08,0x03); + } + } else if( ((HwDeviceExtension->jChipType >= SIS_315H) && (ModeNo == 0x50)) || + ((HwDeviceExtension->jChipType < SIS_315H) && (resinfo == 0 || resinfo == 1)) ) { + if(!(SiS_Pr->SiS_VBInfo & SetPALTV)) { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x07,0x30); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x08,0x03); + } else { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x07,0x2f); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x08,0x03); + } + } + + } + } + + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x18,0x03); /* 0x18 SR08 */ + + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x19,0xF0); + + tempbx = SiS_Pr->SiS_VGAVT; + push1 = tempbx; + + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x09,0xFF); /* 0x09 Set Max VT */ + + tempcx = 0x121; + tempbx = SiS_Pr->SiS_VGAVDE; /* 0x0E Vertical Display End */ + if(tempbx == 357) tempbx = 350; + if(tempbx == 360) tempbx = 350; + if(tempbx == 375) tempbx = 350; + if(tempbx == 405) tempbx = 400; + if(tempbx == 420) tempbx = 400; + if(tempbx == 525) tempbx = 480; + push2 = tempbx; + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) { + if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) { + if(tempbx == 350) tempbx += 5; + if(tempbx == 480) tempbx += 5; + } + } + } + tempbx--; + temp = tempbx & 0x00FF; + tempbx--; + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x10,temp); /* 0x10 vertical Blank Start */ + + tempbx = push2; + tempbx--; + temp = tempbx & 0x00FF; +#if 0 + /* TW: Missing code from 630/301B 2.04.5a and 650/301LVx 1.10.6s (calles int 2f) */ + if(xxx()) { + if(temp == 0xdf) temp = 0xda; + } +#endif + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x0E,temp); + + if(tempbx & 0x0100) { + tempcx |= 0x0002; + if(SiS_Pr->SiS_VBType & VB_SIS301) tempcx |= 0x000a; + } + + tempax = 0x000B; + if(modeflag & DoubleScanMode) tempax |= 0x8000; + + if(tempbx & 0x0200) { + tempcx |= 0x0040; + if(SiS_Pr->SiS_VBType & VB_SIS301) tempax |= 0x2000; + } + + if(SiS_Pr->SiS_VBType & VB_SIS301) { + if(SiS_Pr->SiS_VBInfo & SetPALTV) { + if(SiS_Pr->SiS_VGAVDE == 480) { + tempax = (tempax & 0x00ff) | 0x2000; + if(modeflag & DoubleScanMode) tempax |= 0x8000; + } + } + } + + temp = (tempax & 0xFF00) >> 8; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x0B,temp); + + if(tempbx & 0x0400) tempcx |= 0x0600; + + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x11,0x00); /* 0x11 Vertical Blank End */ + + tempax = push1; + tempax -= tempbx; + tempax >>= 2; + push1 = tempax; + + if(HwDeviceExtension->jChipType >= SIS_315H) { + /* TW: Inserted from 650/301LVx 1.10.6s */ + if(ModeNo > 0x13) { + if(resinfo != 0x09) { + tempax <<= 1; + tempbx += tempax; + } + } else { + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1400x1050) { + tempax <<= 1; + tempbx += tempax; + } + } + } else if((resinfo != 0x09) || (SiS_Pr->SiS_VBType & VB_SIS301)) { + tempax <<= 1; + tempbx += tempax; + } +#ifdef oldHV + if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) { + tempbx -= 10; + } else { +#endif + if(SiS_Pr->SiS_SetFlag & TVSimuMode) { + if(SiS_Pr->SiS_VBInfo & SetPALTV) { + if(!(SiS_Pr->SiS_HiVision & 0x03)) { + tempbx += 40; + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(SiS_Pr->SiS_VGAHDE == 800) tempbx += 10; + } + } + } + } +#ifdef oldHV + } +#endif + tempax = push1; + tempax >>= 2; + tempax++; + tempax += tempbx; + push1 = tempax; + if(SiS_Pr->SiS_VBInfo & SetPALTV) { + if(tempbx <= 513) { + if(tempax >= 513) tempbx = 513; + } + } + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x0C,temp); /* 0x0C Vertical Retrace Start */ + + if(!(SiS_Pr->SiS_VBType & VB_SIS301)) { + tempbx--; + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x10,temp); + + if(tempbx & 0x0100) tempcx |= 0x0008; + + if(tempbx & 0x0200) { + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x0B,0x20); + } + + tempbx++; + } + if(tempbx & 0x0100) tempcx |= 0x0004; + if(tempbx & 0x0200) tempcx |= 0x0080; + if(tempbx & 0x0400) { + if(SiS_Pr->SiS_VBType & VB_SIS301) tempcx |= 0x0800; + else tempcx |= 0x0C00; + } + + tempbx = push1; + temp = tempbx & 0x00FF; + temp &= 0x0F; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x0D,temp); /* 0x0D vertical Retrace End */ + + if(tempbx & 0x0010) tempcx |= 0x2000; + + temp = tempcx & 0x00FF; + if(SiS_Pr->SiS_VBType & VB_SIS301) { + if(SiS_Pr->SiS_VBInfo & SetPALTV) { + if(SiS_Pr->SiS_VGAVDE == 480) temp = 0xa3; + } + } + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x0A,temp); /* 0x0A CR07 */ + + temp = (tempcx & 0xFF00) >> 8; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x17,temp); /* 0x17 SR0A */ + + tempax = modeflag; + temp = (tempax & 0xFF00) >> 8; + temp = (temp >> 1) & 0x09; + /* TW: Inserted from 630/301B and 650/301(LV/LVX) BIOS; not in 630/301 BIOS */ + if(!(SiS_Pr->SiS_VBType & VB_SIS301)) { + temp |= 0x01; + } + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x16,temp); /* 0x16 SR01 */ + + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x0F,0x00); /* 0x0F CR14 */ + + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x12,0x00); /* 0x12 CR17 */ + + if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) { + if(HwDeviceExtension->jChipType >= SIS_315H) { + /* TW: Inserted from 650/301LVx 1.10.6s */ + if(SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x00) & 0x01) { + temp = 0x80; + } + } else temp = 0x80; + } else temp = 0x00; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1A,temp); /* 0x1A SR0E */ + + return; +} + +/* TW: Checked against 650/LVDS 1.10.07, 630/301B (I,II) and 630/LVDS BIOS */ +void +SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr,USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo, + USHORT ModeIdIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension, + USHORT RefreshRateTableIndex) +{ + USHORT modeflag, resinfo; + USHORT push1, push2, tempax, tempbx, tempcx, temp; +#ifdef SIS315H + USHORT pushcx; +#endif + ULONG tempeax=0, tempebx, tempecx, tempvcfact=0; + + if(ModeNo<=0x13) { + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo; + } else { + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; + } + + /* TW: Set up Panel Link */ + + /* 1. Horizontal setup */ + + tempax = SiS_Pr->SiS_LCDHDES; + + if((SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480) && (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) { + tempax -= 8; + } + + tempcx = SiS_Pr->SiS_HT; /* Horiz. Total */ + + tempbx = SiS_Pr->SiS_HDE; /* Horiz. Display End */ + + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) { + if(!SiS_Pr->SiS_IF_DEF_DSTN) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) tempbx = 800; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) tempbx = 1024; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600) tempbx = 1024; /* TW: not done in BIOS */ + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1152x768) tempbx = 1152; /* TW: not done in BIOS */ + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) tempbx = 1280; /* TW */ + else if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) tempbx = 1400; /* TW */ + } + } + tempcx = (tempcx - tempbx) >> 2; /* HT-HDE / 4 */ + + push1 = tempax; + + tempax += tempbx; + + if(tempax >= SiS_Pr->SiS_HT) tempax -= SiS_Pr->SiS_HT; + + push2 = tempax; + + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + if(!SiS_Pr->SiS_IF_DEF_DSTN){ + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) tempcx = 0x0028; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) tempcx = 0x0030; + else if( (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) || + (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1152x768) ) { + if(HwDeviceExtension->jChipType < SIS_315H) { + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { + tempcx = 0x0017; +#ifdef TWNEWPANEL + tempcx = 0x0018; +#endif + } else { + tempcx = 0x0017; /* A901; other 301B BIOS 0x0018; */ + } + } else { + tempcx = 0x0018; + } + } + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600) tempcx = 0x0018; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) tempcx = 0x0040; + else if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) tempcx = 0x0030; + } + } + + tempcx += tempax; /* lcdhrs */ + if(tempcx >= SiS_Pr->SiS_HT) tempcx -= SiS_Pr->SiS_HT; + + tempax = tempcx >> 3; /* BPLHRS */ + temp = tempax & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x14,temp); /* Part1_14h; TW: Panel Link Horizontal Retrace Start */ + + temp = (tempax & 0x00FF) + 10; + + /* TW: Inserted this entire "if"-section from 650/LVDS BIOS */ + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + if(!SiS_Pr->SiS_IF_DEF_DSTN){ + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) { + temp += 6; + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel800x600) { + temp++; + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1024x768) { + temp += 7; + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1600x1200) { + temp -= 10; + } + } + } + } + } + } + } + + temp &= 0x1F; + temp |= ((tempcx & 0x0007) << 5); + if(SiS_Pr->SiS_IF_DEF_FSTN) temp = 0x20; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x15,temp); /* Part1_15h; TW: Panel Link Horizontal Retrace End/Skew */ + + tempbx = push2; + tempcx = push1; /* lcdhdes */ + + temp = (tempcx & 0x0007); /* BPLHDESKEW */ + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1A,temp); /* Part1_1Ah; TW: Panel Link Vertical Retrace Start (2:0) */ + + tempcx >>= 3; /* BPLHDES */ + temp = (tempcx & 0x00FF); + if(ModeNo == 0x5b) temp--; /* fix fstn mode=5b */ + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x16,temp); /* Part1_16h; TW: Panel Link Horizontal Display Enable Start */ + + if(HwDeviceExtension->jChipType < SIS_315H) { /* TW: Not done in LVDS BIOS 1.10.07 */ + if(tempbx & 0x07) tempbx += 8; /* TW: Done in 630/301B and 630/LVDS BIOSes */ + } + tempbx >>= 3; /* BPLHDEE */ + temp = tempbx & 0x00FF; + if(ModeNo == 0x5b) temp--; /* fix fstn mode=5b */ + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x17,temp); /* Part1_17h; TW: Panel Link Horizontal Display Enable End */ + + /* 2. Vertical setup */ + + if(HwDeviceExtension->jChipType < SIS_315H) { + + /* TW: This entire section from 630/301B and 630/LVDS/LVDS+CH BIOS */ + tempcx = SiS_Pr->SiS_VGAVT; + tempbx = SiS_Pr->SiS_VGAVDE; + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) { + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) { + tempbx = 600; + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel800x600) { + tempbx = 768; + if( (SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1024x768) && + (SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1152x768) ) { + tempbx = 600; + } + } + } + } + tempcx -= tempbx; + + } else { + + tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE; /* VGAVT-VGAVDE */ + + } + + tempbx = SiS_Pr->SiS_LCDVDES; /* VGAVDES */ + push1 = tempbx; + + tempax = SiS_Pr->SiS_VGAVDE; + + if((SiS_Pr->SiS_IF_DEF_TRUMPION == 0) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11)) + && (SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480)) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + if(!SiS_Pr->SiS_IF_DEF_DSTN){ + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) tempax = 600; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) tempax = 768; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600) tempax = 600; /* TW */ + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1152x768) tempax = 768; /* TW */ + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) tempax = 1024; /* TW */ + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) tempax = 1050; /* TW */ + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) tempax = 1200; /* TW */ + else tempax = 600; + } + } + } + + tempbx += tempax; + if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT; + + push2 = tempbx; + + tempcx >>= 1; + + if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480)){ + if(!SiS_Pr->SiS_IF_DEF_DSTN){ + if( (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) || + (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600) ) { /* TW: @@@ TEST - not in BIOS! */ + tempcx = 0x0001; + } else if( (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) || + (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1152x768) ) { + if(HwDeviceExtension->jChipType < SIS_315H) { + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { + tempcx = 0x0002; +#ifdef TWNEWPANEL + tempcx = 0x0003; +#endif + } else { + tempcx = 0x0002; /* TW: A901; other 301B BIOS sets 0x0003; */ + } + } else tempcx = 0x0003; + } + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x768) tempcx = 0x0003; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) tempcx = 0x0001; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) tempcx = 0x0001; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) tempcx = 0x0001; + else tempcx = 0x0057; + } + } + + tempbx += tempcx; /* BPLVRS */ + + if(HwDeviceExtension->jChipType < SIS_315H) { + tempbx++; + } + + if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT; + + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x18,temp); /* Part1_18h; TW: Panel Link Vertical Retrace Start */ + + tempcx >>= 3; + + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + if( (HwDeviceExtension->jChipType < SIS_315H) && + (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480) ) tempcx = 0x0001; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) tempcx = 0x0002; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) tempcx = 0x0002; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) tempcx = 0x0003; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600) tempcx = 0x0005; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1152x768) tempcx = 0x0005; + else if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) { + if(HwDeviceExtension->jChipType < SIS_315H) { + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { + tempcx = 0x0004; +#ifdef TWNEWPANEL + tempcx = 0x0005; +#endif + } else { + tempcx = 0x0004; /* A901; Other BIOS sets 0x0005; */ + } + } else { + tempcx = 0x0005; + } + } + } + + tempcx = tempcx + tempbx + 1; /* BPLVRE */ + temp = tempcx & 0x000F; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0xf0,temp); /* Part1_19h; TW: Panel Link Vertical Retrace End (3:0); Misc. */ + + temp = ((tempbx & 0x0700) >> 8) << 3; /* BPLDESKEW =0 */ + if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40; + if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) temp |= 0x40; + if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) { + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x00) & 0x01) { /* TW: Inserted from 650/LVDS 1.10.07 */ + temp |= 0x80; + } + } else { + if( (HwDeviceExtension->jChipType == SIS_630) || + (HwDeviceExtension->jChipType == SIS_730) ) { + if(HwDeviceExtension->jChipRevision >= 0x30) { + temp |= 0x80; + } + } + } + } + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1A,0x87,temp); /* Part1_1Ah; TW: Panel Link Control Signal (7:3); Vertical Retrace Start (2:0) */ + + if (HwDeviceExtension->jChipType < SIS_315H) { + +#ifdef SIS300 /* 300 series */ + + tempeax = SiS_Pr->SiS_VGAVDE << 6; + temp = (USHORT)(tempeax % (ULONG)SiS_Pr->SiS_VDE); + tempeax = tempeax / (ULONG)SiS_Pr->SiS_VDE; + if(temp != 0) tempeax++; + tempebx = tempeax; /* BPLVCFACT */ + + if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) { + tempebx = 0x003F; + } + + temp = (USHORT)(tempebx & 0x00FF); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1E,temp); /* Part1_1Eh; TW: Panel Link Vertical Scaling Factor */ + +#endif /* SIS300 */ + + } else { + +#ifdef SIS315H /* 310/325 series */ + + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1E,0x23); + + tempeax = SiS_Pr->SiS_VGAVDE << 18; + temp = (USHORT)(tempeax % (ULONG)SiS_Pr->SiS_VDE); + tempeax = tempeax / SiS_Pr->SiS_VDE; + if(temp != 0) tempeax++; + tempebx = tempeax; /* BPLVCFACT */ + tempvcfact = tempeax; + temp = (USHORT)(tempebx & 0x00FF); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x37,temp); /* Part1_37h; TW: Panel Link Vertical Scaling Factor */ + temp = (USHORT)((tempebx & 0x00FF00) >> 8); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x36,temp); /* Part1_36h; TW: Panel Link Vertical Scaling Factor */ + temp = (USHORT)((tempebx & 0x00030000) >> 16); + if(SiS_Pr->SiS_VDE == SiS_Pr->SiS_VGAVDE) temp |= 0x04; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x35,temp); /* Part1_35h; TW: Panel Link Vertical Scaling Factor */ + +#endif /* SIS315H */ + + } + + tempbx = push2; /* p bx temppush1 BPLVDEE */ + tempcx = push1; + + push1 = temp; /* TW: For 630/301B and 630/LVDS */ + + if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { + if(!SiS_Pr->SiS_IF_DEF_DSTN){ + if(HwDeviceExtension->jChipType < SIS_315H) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600) { + if(resinfo == 15) tempcx++; + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) { + if(resinfo == 7) tempcx++; + } + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) { + if(resinfo == 7) tempcx++; + if(resinfo == 8) tempcx++; /* TW: Doesnt make sense anyway... */ + } else if(resinfo == 8) tempcx++; + } else { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) { + if(resinfo == 7) tempcx++; + } + } + } + } + + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480) { + tempcx = SiS_Pr->SiS_VGAVDE; + tempbx = SiS_Pr->SiS_VGAVDE - 1; + } + + temp = ((tempbx & 0x0700) >> 8) << 3; + temp |= ((tempcx & 0x0700) >> 8); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1D,temp); /* Part1_1Dh; TW: Vertical Display Overflow; Control Signal */ + + temp = tempbx & 0x00FF; + if(SiS_Pr->SiS_IF_DEF_FSTN) temp++; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1C,temp); /* Part1_1Ch; TW: Panel Link Vertical Display Enable End */ + + temp = tempcx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1B,temp); /* Part1_1Bh; TW: Panel Link Vertical Display Enable Start */ + + /* 3. Additional horizontal setup (scaling, etc) */ + + tempecx = SiS_Pr->SiS_VGAHDE; + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(modeflag & HalfDCLK) + tempecx >>= 1; + } + tempebx = SiS_Pr->SiS_HDE; + if(tempecx == tempebx) tempeax = 0xFFFF; + else { + tempeax = tempecx; + tempeax <<= 16; + temp = (USHORT)(tempeax % tempebx); + tempeax = tempeax / tempebx; + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(temp) tempeax++; + } + } + tempecx = tempeax; + + if (HwDeviceExtension->jChipType >= SIS_315H) { + tempeax = SiS_Pr->SiS_VGAHDE; + if(modeflag & HalfDCLK) + tempeax >>= 1; + tempeax <<= 16; + tempeax = (tempeax / tempecx) - 1; + } else { + tempeax = ((SiS_Pr->SiS_VGAHT << 16) / tempecx) - 1; + } + tempecx <<= 16; + tempecx |= (tempeax & 0xFFFF); + temp = (USHORT)(tempecx & 0x00FF); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1F,temp); /* Part1_1Fh; TW: Panel Link DDA Operational Number in each horiz. line */ + + tempbx = SiS_Pr->SiS_VDE; + if (HwDeviceExtension->jChipType >= SIS_315H) { + tempeax = (SiS_Pr->SiS_VGAVDE << 18) / tempvcfact; + tempbx = (USHORT)(tempeax & 0x0FFFF); + } else { + tempax = SiS_Pr->SiS_VGAVDE << 6; + tempbx = push1; + tempbx &= 0x3f; + if(tempbx == 0) tempbx = 64; + tempax = tempax / tempbx; + tempbx = tempax; + } + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) tempbx--; + if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) tempbx = 1; + + temp = ((tempbx & 0xFF00) >> 8) << 3; + temp |= (USHORT)((tempecx & 0x0700) >> 8); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x20,temp); /* Part1_20h; TW: Overflow register */ + + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x21,temp); /* Part1_21h; TW: Panel Link Vertical Accumulator Register */ + + tempecx >>= 16; /* BPLHCFACT */ + if(HwDeviceExtension->jChipType < SIS_315H) { + if(modeflag & HalfDCLK) tempecx >>= 1; + } + temp = (USHORT)((tempecx & 0xFF00) >> 8); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x22,temp); /* Part1_22h; TW: Panel Link Horizontal Scaling Factor High */ + + temp = (USHORT)(tempecx & 0x00FF); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x23,temp); /* Part1_22h; TW: Panel Link Horizontal Scaling Factor Low */ + + /* 630/301B and 630/LVDS do something for 640x480 panels here */ + +#ifdef SIS315H + /* TW: DSTN/FSTN initialisation - hardcoded for 320x480 panel */ + if(SiS_Pr->SiS_IF_DEF_DSTN) { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1E,0x01); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x25,0x00); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x26,0x00); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x27,0x00); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x28,0x87); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x29,0x5A); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x2A,0x4B); + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x007,0x03); + tempbx = SiS_Pr->SiS_HDE + 64; /*Blps = lcdhdee(lcdhdes+HDE) + 64*/ + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x38,temp); + temp=((tempbx & 0xFF00) >> 8) << 3; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,~0x078,temp); + tempbx += 32; /*Blpe=lBlps+32*/ + temp = tempbx & 0x00FF; + if(SiS_Pr->SiS_IF_DEF_FSTN) temp=0; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x39,temp); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x3A,0x00); /*Bflml=0*/ + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x007,0x00); + tempbx = SiS_Pr->SiS_VDE / 2; + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x3B,temp); + temp = ((tempbx & 0xFF00) >> 8) << 3; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x038,temp); + tempeax = SiS_Pr->SiS_HDE << 2; /* BDxFIFOSTOP = (HDE*4)/128 */ + tempebx = 128; + temp = (USHORT)(tempeax % tempebx); + tempeax = tempeax / tempebx; + if(temp != 0) tempeax++; + temp = (USHORT)(tempeax & 0x003F); + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x45,~0x0FF,temp); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x3F,0x00); /* BDxWadrst0 */ + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x3E,0x00); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x3D,0x10); + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x040,0x00); + tempax = SiS_Pr->SiS_HDE >> 4; /* BDxWadroff = HDE*4/8/8 */ + pushcx = tempax; + temp = tempax & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x43,temp); + temp = ((tempax & 0xFF00) >> 8) << 3; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x0F8,temp); + tempax = SiS_Pr->SiS_VDE; /*BDxWadrst1 = BDxWadrst0 + BDxWadroff * VDE */ + tempeax = (tempax * pushcx); + tempebx = 0x00100000 + tempeax; + temp = (USHORT)tempebx & 0x000000FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x42,temp); + temp = (USHORT)((tempebx & 0x0000FF00)>>8); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x41,temp); + temp = (USHORT)((tempebx & 0x00FF0000)>>16); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x40,temp); + temp = (USHORT)(((tempebx & 0x01000000)>>24) << 7); + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x080,temp); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x2F,0x03); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x03,0x50); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x04,0x00); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x2F,0x01); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x13,0x00); + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x05,0x86); /* Unlock */ + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x1e,0x62); + if(SiS_Pr->SiS_IF_DEF_FSTN){ + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x2b,0x1b); + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x2c,0xe3); + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x1e,0x62); + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x2e,0x04); + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x2f,0x42); + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x32,0x01); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x2b,0x02); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x2c,0x00); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x2d,0x00); + } + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0f,0x30); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1e,0x7d); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x2e,0xe0); + } +#endif /* SIS315H */ + + return; + +} + +#ifdef SIS315H +void +SiS_CRT2AutoThreshold(SiS_Private *SiS_Pr, USHORT BaseAddr) +{ + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x40); +} +#endif + + +/* TW: For LVDS / 302b/lv - LCDA (this must only be called on 310/325 series!) */ +/* TW: Double-checked against 650/LVDS and 650/301 BIOS */ +void +SiS_SetGroup1_LCDA(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT RefreshRateTableIndex) +{ + USHORT modeflag,resinfo; + USHORT push1,push2,tempax,tempbx,tempcx,temp; + ULONG tempeax=0,tempebx,tempecx,tempvcfact; + + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { /* TW: From 650/LVDS BIOS */ + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04); /* TW: From 650/LVDS BIOS */ + } + + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { /* TW: From 650/LVDS 1.10.07 */ + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x00); /* TW: From 650/LVDS 1.10.07 */ + } else { + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2D,0x0f); /* TW: From 650/301Lvx 1.10.6s */ + } + + if(ModeNo<=0x13) { + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo; + } else { + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; + } + + tempax = SiS_Pr->SiS_LCDHDES; + tempbx = SiS_Pr->SiS_HDE; + tempcx = SiS_Pr->SiS_HT; + + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) tempbx = 1024; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) tempbx = 1400; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) tempbx = 1600; + else tempbx = 1280; + + } + tempcx -= tempbx; /* HT-HDE */ + push1 = tempax; + tempax += tempbx; /* lcdhdee */ + tempbx = SiS_Pr->SiS_HT; + if(tempax >= tempbx) tempax -= tempbx; + + push2 = tempax; /* push ax lcdhdee */ + + tempcx >>= 2; + + /* TW: Inserted from 650/301LVx 1.10.6s */ + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) tempcx = 0x28; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) tempcx = 0x30; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) tempcx = 0x18; + else tempcx = 0x30; + } + } + + tempcx += tempax; /* lcdhrs */ + if(tempcx >= tempbx) tempcx -= tempbx; + /* v ah,cl */ + tempax = tempcx; + tempax >>= 3; /* BPLHRS */ + temp = tempax & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x14,temp); /* Part1_14h */ + + temp += 10; + temp &= 0x1F; + temp |= ((tempcx & 0x07) << 5); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x15,temp); /* Part1_15h */ + + tempbx = push2; /* lcdhdee */ + tempcx = push1; /* lcdhdes */ + temp = (tempcx & 0x00FF); + temp &= 0x07; /* BPLHDESKEW */ + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1A,temp); /* Part1_1Ah */ + + tempcx >>= 3; /* BPLHDES */ + temp = tempcx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x16,temp); /* Part1_16h */ + + if(tempbx & 0x07) tempbx += 8; + tempbx >>= 3; /* BPLHDEE */ + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x17,temp); /* Part1_17h */ + + tempcx = SiS_Pr->SiS_VGAVT; + tempbx = SiS_Pr->SiS_VGAVDE; + tempcx -= tempbx; /* GAVT-VGAVDE */ + tempbx = SiS_Pr->SiS_LCDVDES; /* VGAVDES */ + push1 = tempbx; /* push bx temppush1 */ + if(SiS_Pr->SiS_IF_DEF_TRUMPION == 0){ + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) tempax = 768; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) tempax = 1024; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) tempax = 1050; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) tempax = 1200; + else tempax = 960; +#if 0 /* TW: Removed (650/LVDS BIOS) */ + if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + tempax = SiS_Pr->SiS_VGAVDE; + } + } +#endif + } else tempax = SiS_Pr->SiS_VGAVDE; /* Trumpion */ + + tempbx += tempax; + tempax = SiS_Pr->SiS_VT; /* VT */ + if(tempbx >= tempax) tempbx -= tempax; + + push2 = tempbx; /* push bx temppush2 */ + tempcx >>= 2; /* TO CHECK - was 1 */ + + /* TW: Inserted from 650/301LVx 1.10.6s */ + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) tempcx = 1; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) tempcx = 3; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x768) tempcx = 3; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) tempcx = 1; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) tempcx = 1; + else tempcx = 0x0057; + } + } + + tempbx += tempcx; + tempbx++; /* BPLVRS */ + if(tempbx >= tempax) tempbx -= tempax; + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x18,temp); /* Part1_18h */ + + tempcx >>= 3; + tempcx += tempbx; + tempcx++; /* BPLVRE */ + temp = tempcx & 0x00FF; + temp &= 0x0F; + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { + /* TW: Inserted from 650/LVDS BIOS */ + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0xf0,temp); + } else { + /* TW: Inserted from 650/301LVx 1.10.6s */ + temp |= 0xC0; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0xF0,temp); /* Part1_19h */ + } + + temp = (tempbx & 0xFF00) >> 8; + temp &= 0x07; + temp <<= 3; /* BPLDESKEW =0 */ + tempbx = SiS_Pr->SiS_VGAVDE; + if(tempbx != SiS_Pr->SiS_VDE) temp |= 0x40; + if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) temp |= 0x40; + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { + /* TW: Inserted from 650/LVDS 1.10.07 */ + if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) temp |= 0x80; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1A,0x87,temp); /* Part1_1Ah */ + } else { + /* TW: Inserted from 650/301LVx 1.10.6s */ + if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) { + if(SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x00) & 0x01) temp |= 0x80; + } + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1A,0x87,temp); /* Part1_1Ah */ + } + + tempbx = push2; /* p bx temppush2 BPLVDEE */ + tempcx = push1; /* pop cx temppush1 NPLVDES */ + push1 = (USHORT)(tempeax & 0xFFFF); + + if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) { + if(resinfo == 7) tempcx++; + } + } + /* TW: Inserted from 650/301LVx+LVDS BIOSes */ + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480) { + tempbx = SiS_Pr->SiS_VGAVDE; + tempcx = tempbx; + tempbx--; + } + + temp = (tempbx & 0xFF00) >> 8; + temp &= 0x07; + temp <<= 3; + temp = temp | (((tempcx & 0xFF00) >> 8) & 0x07); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1D,temp); /* Part1_1Dh */ + + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1C,temp); /* Part1_1Ch */ + + temp = tempcx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1B,temp); /* Part1_1Bh */ + + tempecx = SiS_Pr->SiS_VGAVT; + tempebx = SiS_Pr->SiS_VDE; + tempeax = SiS_Pr->SiS_VGAVDE; + tempecx -= tempeax; /* VGAVT-VGAVDE */ + tempeax <<= 18; + temp = (USHORT)(tempeax % tempebx); + tempeax = tempeax / tempebx; + if(temp) tempeax++; + tempebx = tempeax; /* BPLVCFACT */ + tempvcfact = tempeax; + temp = (USHORT)(tempebx & 0x00FF); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x37,temp); + + temp = (USHORT)((tempebx & 0x00FF00) >> 8); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x36,temp); + + temp = (USHORT)((tempebx & 0x00030000) >> 16); + if(SiS_Pr->SiS_VDE == SiS_Pr->SiS_VGAVDE) temp |= 0x04; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x35,temp); + + tempecx = SiS_Pr->SiS_VGAHDE; + tempebx = SiS_Pr->SiS_HDE; + tempeax = tempecx; + tempeax <<= 16; + temp = tempeax % tempebx; + tempeax = tempeax / tempebx; + if(temp) tempeax++; + if(tempebx == tempecx) tempeax = 0xFFFF; + tempecx = tempeax; + tempeax = SiS_Pr->SiS_VGAHDE; + tempeax <<= 16; + tempeax = tempeax / tempecx; + tempecx <<= 16; + tempeax--; + tempecx = tempecx | (tempeax & 0xFFFF); + temp = (USHORT)(tempecx & 0x00FF); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1F,temp); /* Part1_1Fh */ + + tempeax = SiS_Pr->SiS_VGAVDE; + tempeax <<= 18; + tempeax = tempeax / tempvcfact; + tempbx = (USHORT)(tempeax & 0x0FFFF); + + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) tempbx--; + + if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) tempbx = 1; + + temp = ((tempbx & 0xFF00) >> 8) << 3; + temp = temp | (USHORT)(((tempecx & 0x0000FF00) >> 8) & 0x07); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x20,temp); /* Part1_20h */ + + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x21,temp); /* Part1_21h */ + + tempecx >>= 16; /* BPLHCFACT */ + if(modeflag & HalfDCLK) tempecx >>= 1; + temp = (USHORT)((tempecx & 0x0000FF00) >> 8); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x22,temp); /* Part1_22h */ + + temp=(USHORT)(tempecx & 0x000000FF); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x23,temp); + +#if 0 + /* TW: Missing code (calles int 2f) (650/301LVx 1.10.6s; 1.10.7w doesn't do this) */ + if(xxx()) { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x0e,0xda); + } +#endif + + /* TW: Only for 650/LVDS and 30xLV/30xLVX */ + if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBInfo & (VB_SIS30xLV|VB_SIS30xNEW))){ + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1e,0x20); + } + + return; +} + +/* TW: Double-checked against 650/LVDS (1.10.07) and 650/301 BIOS */ +void SiS_SetCRT2Offset(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo, + USHORT ModeIdIndex ,USHORT RefreshRateTableIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT offset; + UCHAR temp; + + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) return; + + offset = SiS_GetOffset(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + HwDeviceExtension); + temp = (UCHAR)(offset & 0xFF); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x07,temp); + temp = (UCHAR)((offset & 0xFF00) >> 8); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x09,temp); + temp = (UCHAR)(((offset >> 3) & 0xFF) + 1); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x03,temp); +} + +/* TW: Checked with 650/LVDS and 650/301 BIOS */ +USHORT +SiS_GetOffset(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT temp,colordepth; + USHORT modeinfo,index,infoflag; + + if(SiS_Pr->UseCustomMode) { + infoflag = SiS_Pr->CInfoFlag; + temp = SiS_Pr->CHDisplay / 16; + } else { + infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag; + modeinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeInfo; + + if(HwDeviceExtension->jChipType < SIS_315H ) { + index = (modeinfo >> 4) & 0xFF; + } else { + index = (modeinfo >> 8) & 0xFF; + } + + temp = SiS_Pr->SiS_ScreenOffset[index]; + } + + colordepth = SiS_GetColorDepth(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex); + + if(infoflag & InterlaceMode) temp <<= 1; + + temp *= colordepth; + + /* TW: For 1400x1050 and 856x480 */ + if( ( ((ModeNo >= 0x26) && (ModeNo <= 0x28)) || + ModeNo == 0x3f || + ModeNo == 0x42 || + ModeNo == 0x45 ) || + (SiS_Pr->UseCustomMode && (SiS_Pr->CHDisplay % 16)) ) { + colordepth >>= 1; + temp += colordepth; + } + + return(temp); +} + +/* TW: Checked with 650/LVDS BIOS */ +USHORT +SiS_GetColorDepth(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex) +{ + USHORT ColorDepth[6] = { 1, 2, 4, 4, 6, 8}; + SHORT index; + USHORT modeflag; + + if(SiS_Pr->UseCustomMode) { + modeflag = SiS_Pr->CModeFlag; + } else { + if(ModeNo <= 0x13) + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + else + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + } + + index = (modeflag & ModeInfoFlag) - ModeEGA; + if(index < 0) index = 0; + return(ColorDepth[index]); +} + +/* TW: Checked against 630/301/301B/LVDS, 650/301LVx/LVDS */ +void +SiS_SetCRT2Sync(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT tempah=0,tempbl,infoflag,flag; + + flag = 0; + tempbl = 0xC0; + + infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag; + + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { /* LVDS */ + + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + tempah = SiS_Pr->SiS_LCDInfo; + if(HwDeviceExtension->jChipType >= SIS_315H) { + tempbl = tempah & 0xc0; + } + if(SiS_Pr->SiS_LCDInfo & LCDSync) { + flag = 1; + } + } + if(flag != 1) tempah = infoflag >> 8; + tempah &= 0xC0; + tempah |= 0x20; + if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10; + + if (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480) { + /* TW: BIOS does something here @@@ */ + } + + tempah &= 0x3f; + tempah |= tempbl; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah); + + } else { + + if(HwDeviceExtension->jChipType < SIS_315H) { + +#ifdef SIS300 /* ---- 300 series --- */ + + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { /* 630 - 301B */ + + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + tempah = SiS_Pr->SiS_LCDInfo; + if(SiS_Pr->SiS_LCDInfo & LCDSync) { + flag = 1; + } + } + if(flag != 1) tempah = infoflag >> 8; + tempah &= 0xC0; + tempah |= 0x20; + + if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10; + + if (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480) { + /* TW: BIOS does something here @@@ */ + } + + tempah &= 0x3f; + tempah |= tempbl; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah); + + } else { /* 630 - 301 */ + + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + tempah = SiS_Pr->SiS_LCDInfo; + if(SiS_Pr->SiS_LCDInfo & LCDNonExpandingShift) { /* ! */ + flag = 1; + } + } + if(flag != 1) tempah = infoflag >> 8; + tempah &= 0xC0; + tempah |= 0x30; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x3F,tempah); + + } + +#endif /* SIS300 */ + + } else { + +#ifdef SIS315H /* ----- 310/325 series ---- */ + + if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { /* 310/325 - 301LV/LVX */ + + tempah = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x37); + tempah &= 0xC0; + tempah |= 0x20; + if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah); + + } else { /* 310/325 - 301, 301B */ + + tempah = infoflag >> 8; + tempah &= 0xC0; + tempah |= 0x20; + + if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10; + + if (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480) { + /* TW: BIOS does something here @@@ */ + } + + tempah &= 0x3f; + tempah |= tempbl; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah); + + } +#endif /* SIS315H */ + } + } +} + +/* TW: Set CRT2 FIFO on 300/630/730 */ +/* TW: Checked against 630/301B BIOS; BIOS does not set PCI registers */ +#ifdef SIS300 +void +SiS_SetCRT2FIFO_300(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo, + PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT temp,index; + USHORT modeidindex,refreshratetableindex; + USHORT VCLK=0,MCLK,colorth=0,data2=0; + USHORT tempal, tempah, tempbx, tempcl, tempax; + USHORT CRT1ModeNo,CRT2ModeNo; + USHORT SelectRate_backup; + ULONG data,eax; + const UCHAR LatencyFactor[] = { + 97, 88, 86, 79, 77, 00, /*; 64 bit BQ=2 */ + 00, 87, 85, 78, 76, 54, /*; 64 bit BQ=1 */ + 97, 88, 86, 79, 77, 00, /*; 128 bit BQ=2 */ + 00, 79, 77, 70, 68, 48, /*; 128 bit BQ=1 */ + 80, 72, 69, 63, 61, 00, /*; 64 bit BQ=2 */ + 00, 70, 68, 61, 59, 37, /*; 64 bit BQ=1 */ + 86, 77, 75, 68, 66, 00, /*; 128 bit BQ=2 */ + 00, 68, 66, 59, 57, 37 /*; 128 bit BQ=1 */ + }; + const UCHAR LatencyFactor730[] = { + 69, 63, 61, + 86, 79, 77, + 103, 96, 94, + 120,113,111, + 137,130,128, /* <-- last entry, data below */ + 137,130,128, /* to avoid using illegal values */ + 137,130,128, + 137,130,128, + 137,130,128, + 137,130,128, + 137,130,128, + 137,130,128, + 137,130,128, + 137,130,128, + 137,130,128, + 137,130,128, + }; + const UCHAR ThLowB[] = { + 81, 4, 72, 6, 88, 8,120,12, + 55, 4, 54, 6, 66, 8, 90,12, + 42, 4, 45, 6, 55, 8, 75,12 + }; + const UCHAR ThTiming[] = { + 1, 2, 2, 3, 0, 1, 1, 2 + }; + + SelectRate_backup = SiS_Pr->SiS_SelectCRT2Rate; + + if(!SiS_Pr->CRT1UsesCustomMode) { + + CRT1ModeNo = SiS_Pr->SiS_CRT1Mode; /* get CRT1 ModeNo */ + SiS_SearchModeID(SiS_Pr,ROMAddr,&CRT1ModeNo,&modeidindex); + SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2); + SiS_Pr->SiS_SelectCRT2Rate = 0; + refreshratetableindex = SiS_GetRatePtrCRT2(SiS_Pr,ROMAddr,CRT1ModeNo, + modeidindex,HwDeviceExtension); + + if(CRT1ModeNo >= 0x13) { + index = SiS_Pr->SiS_RefIndex[refreshratetableindex].Ext_CRTVCLK; + index &= 0x3F; + VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK; /* Get VCLK */ + data2 = SiS_Pr->SiS_ModeType - 2; + } + + } else { + + CRT1ModeNo = 0xfe; + VCLK = SiS_Pr->CSRClock; /* Get VCLK */ + data2 = (SiS_Pr->CModeFlag & ModeInfoFlag) - 2; + + } + + if(CRT1ModeNo >= 0x13) { + if(HwDeviceExtension->jChipType == SIS_300) { + index = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x3A); + } else { + index = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x1A); + } + index &= 0x07; + MCLK = SiS_Pr->SiS_MCLKData_0[index].CLOCK; /* Get MCLK */ + +#ifdef TWDEBUG + xf86DrvMsg(0, X_INFO, "FIFO2: CRT1Mode 0x%x VCLK %d MCLK %d modetype-2 = %d\n", + CRT1ModeNo, VCLK, MCLK, data2); +#endif + + switch(data2) { /* Get color depth */ + case 0 : colorth = 1; break; + case 1 : colorth = 1; break; + case 2 : colorth = 2; break; + case 3 : colorth = 2; break; + case 4 : colorth = 3; break; + case 5 : colorth = 4; break; + default: colorth = 2; break; + } + data2 = (colorth * VCLK) / MCLK; + + temp = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x14); + temp = ((temp & 0x00FF) >> 6) << 1; + if(temp == 0) temp = 1; + temp <<= 2; + temp &= 0xff; + + data2 = temp - data2; + +#ifdef TWDEBUG + xf86DrvMsg(0, X_INFO, "FIFO2: data2 (step1) = %d\n", + data2); +#endif + + if((28 * 16) % data2) { + data2 = (28 * 16) / data2; + data2++; + } else { + data2 = (28 * 16) / data2; + } + +#ifdef TWDEBUG + xf86DrvMsg(0, X_INFO, "FIFO2: data2 (step2) = %d\n", + data2); +#endif + + if(HwDeviceExtension->jChipType == SIS_300) { + + tempah = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x18); + tempah &= 0x62; + tempah >>= 1; + tempal = tempah; + tempah >>= 3; + tempal |= tempah; + tempal &= 0x07; + tempcl = ThTiming[tempal]; + tempbx = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x16); + tempbx >>= 6; + tempah = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x14); + tempah >>= 4; + tempah &= 0x0c; + tempbx |= tempah; + tempbx <<= 1; + tempal = ThLowB[tempbx + 1]; + tempal *= tempcl; + tempal += ThLowB[tempbx]; + data = tempal; + + } else if(HwDeviceExtension->jChipType == SIS_730) { + +#ifndef LINUX_XF86 + SiS_SetReg4(0xcf8,0x80000050); + eax = SiS_GetReg3(0xcfc); +#else + eax = pciReadLong(0x00000000, 0x50); +#endif + tempal = (USHORT)(eax >> 8); + tempal &= 0x06; + tempal <<= 5; + +#ifndef LINUX_XF86 + SiS_SetReg4(0xcf8,0x800000A0); + eax = SiS_GetReg3(0xcfc); +#else + eax = pciReadLong(0x00000000, 0xA0); +#endif + temp = (USHORT)(eax >> 28); + temp &= 0x0F; + tempal |= temp; + +#ifdef TWDEBUG + xf86DrvMsg(0, X_INFO, "FIFO2: Latencyfactorindex = 0x%x\n", tempal); +#endif + + tempbx = tempal; /* BIOS BUG (2.04.5d, 2.04.6a use ah here, which is unset!) */ + tempbx = 0; /* -- do it like the BIOS anyway... */ + tempax = tempbx; + tempbx &= 0xc0; + tempbx >>= 6; + tempax &= 0x0f; + tempax *= 3; + tempbx += tempax; + + data = LatencyFactor730[tempbx]; + data += 15; + temp = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x14); + if(!(temp & 0x80)) data += 5; + + } else { + + index = 0; + temp = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x14); + if(temp & 0x0080) index += 12; + +#ifndef LINUX_XF86 + SiS_SetReg4(0xcf8,0x800000A0); + eax = SiS_GetReg3(0xcfc); +#else + /* TW: We use pci functions X offers. We use tag 0, because + * we want to read/write to the host bridge (which is always + * 00:00.0 on 630, 730 and 540), not the VGA device. + */ + eax = pciReadLong(0x00000000, 0xA0); +#endif + temp = (USHORT)(eax >> 24); + if(!(temp&0x01)) index += 24; + +#ifndef LINUX_XF86 + SiS_SetReg4(0xcf8,0x80000050); + eax = SiS_GetReg3(0xcfc); +#else + eax = pciReadLong(0x00000000, 0x50); +#endif + temp=(USHORT)(eax >> 24); + if(temp & 0x01) index += 6; + + temp = (temp & 0x0F) >> 1; + index += temp; + + data = LatencyFactor[index]; + data += 15; + temp = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x14); + if(!(temp & 0x80)) data += 5; + } + +#ifdef TWDEBUG + xf86DrvMsg(0, X_INFO, "FIFO2: latencyfactor (CRT1) = %d\n", data); +#endif + + data += data2; /* CRT1 Request Period */ + +#ifdef TWDEBUG + xf86DrvMsg(0, X_INFO, "FIFO2: CRT1 request period = %d\n", data); +#endif + + CRT2ModeNo = ModeNo; + SiS_Pr->SiS_SetFlag |= ProgrammingCRT2; + SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup; + SiS_SearchModeID(SiS_Pr,ROMAddr,&CRT2ModeNo,&modeidindex); + + refreshratetableindex = SiS_GetRatePtrCRT2(SiS_Pr,ROMAddr,CRT2ModeNo, + modeidindex,HwDeviceExtension); + + index = SiS_GetVCLK2Ptr(SiS_Pr,ROMAddr,CRT2ModeNo,modeidindex, + refreshratetableindex,HwDeviceExtension); + VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK; /* Get VCLK */ + + data2 = SiS_Pr->SiS_ModeType - 2; + switch(data2) { /* Get color depth */ + case 0 : colorth = 1; break; + case 1 : colorth = 1; break; + case 2 : colorth = 2; break; + case 3 : colorth = 2; break; + case 4 : colorth = 3; break; + case 5 : colorth = 4; break; + default: colorth = 2; break; + } + +#ifdef TWDEBUG + xf86DrvMsg(0, X_INFO, "FIFO2: CRT2Mode 0x%x VCLK %d MCLK %d modetype-2 = %d, colorth %d\n", + CRT2ModeNo, VCLK, MCLK, data2, colorth); +#endif + + data = data * VCLK * colorth; + if(data % (MCLK << 4)) { + data = data / (MCLK << 4); + data++; + } else { + data = data / (MCLK << 4); + } + +#ifdef TWDEBUG + xf86DrvMsg(0, X_INFO, "FIFO2: data (unclipped) = 0x%x\n", data); +#endif + + if(data <= 6) data = 6; + if(data > 0x14) data = 0x14; + + temp = SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x01); + if(HwDeviceExtension->jChipType == SIS_300) { + if(data <= 0x0f) temp = (temp & (~0x1F)) | 0x13; + else temp = (temp & (~0x1F)) | 0x16; + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) { + temp = (temp & (~0x1F)) | 0x13; + } + } else { + if( ( (HwDeviceExtension->jChipType == SIS_630) || + (HwDeviceExtension->jChipType == SIS_730) ) && + (HwDeviceExtension->jChipRevision >= 0x30) ) /* 630s or 730(s?) */ + { + temp = (temp & (~0x1F)) | 0x1b; + } else { + temp = (temp & (~0x1F)) | 0x16; + } + } + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0xe0,temp); + + if( (HwDeviceExtension->jChipType == SIS_630) && + (HwDeviceExtension->jChipRevision >= 0x30) ) /* 630s, NOT 730 */ + { + if(data > 0x13) data = 0x13; + } + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,0xe0,data); + + } else { /* If mode <= 0x13, we just restore everything */ + + SiS_Pr->SiS_SetFlag |= ProgrammingCRT2; + SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup; + + } +} +#endif + +/* TW: Set FIFO on 310 series */ +#ifdef SIS315H +void +SiS_SetCRT2FIFO_310(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo, + PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + + UCHAR CombCode[] = { 1, 1, 1, 4, 3, 1, 3, 4, + 4, 1, 4, 4, 5, 1, 5, 4}; + UCHAR CRT2ThLow[] = { 39, 63, 55, 79, 78,102, 90,114, + 55, 87, 84,116,103,135,119,151}; + USHORT temp3,tempax,tempbx,tempcx; + USHORT tempcl, tempch; + USHORT index; + USHORT CRT1ModeNo,CRT2ModeNo; + USHORT ModeIdIndex; + USHORT RefreshRateTableIndex; + USHORT SelectRate_backup; + + SelectRate_backup = SiS_Pr->SiS_SelectCRT2Rate; + + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x01,0x3B); + + if(!SiS_Pr->CRT1UsesCustomMode) { + + CRT1ModeNo = SiS_Pr->SiS_CRT1Mode; /* get CRT1 ModeNo */ + SiS_SearchModeID(SiS_Pr,ROMAddr,&CRT1ModeNo,&ModeIdIndex); + + SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2); + SiS_Pr->SiS_SelectCRT2Rate = 0; + + /* Get REFIndex for crt1 refreshrate */ + RefreshRateTableIndex = SiS_GetRatePtrCRT2(SiS_Pr,ROMAddr,CRT1ModeNo, + ModeIdIndex,HwDeviceExtension); + + index = SiS_GetVCLK2Ptr(SiS_Pr,ROMAddr,CRT1ModeNo,ModeIdIndex, + RefreshRateTableIndex,HwDeviceExtension); + tempax = SiS_Pr->SiS_VCLKData[index].CLOCK; /* Get VCLK */ + + tempbx = SiS_GetColorDepth(SiS_Pr,ROMAddr,CRT1ModeNo,ModeIdIndex); /* Get colordepth */ + tempbx >>= 1; + if(!tempbx) tempbx++; + + } else { + + tempax = SiS_Pr->CSRClock; /* Get VCLK */ + tempbx = (SiS_Pr->CModeFlag & ModeInfoFlag) - 2; + switch(tempbx) { /* Get color depth */ + case 0 : tempbx = 1; break; + case 1 : tempbx = 1; break; + case 2 : tempbx = 2; break; + case 3 : tempbx = 2; break; + case 4 : tempbx = 3; break; + case 5 : tempbx = 4; break; + default: tempbx = 2; break; + } + + } + + tempax *= tempbx; + + tempbx = SiS_GetMCLK(SiS_Pr,ROMAddr, HwDeviceExtension); /* Get MCLK */ + + tempax /= tempbx; + + tempbx = tempax; + +#if 0 /* TW: BIOS code is skrewed */ + if(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x14) & 0x02) { + tempax = 16; + } else { + tempax = 8; + } +#endif + tempax = 16; + + tempax -= tempbx; + + tempbx = tempax; /* tempbx = 16-DRamBus - DCLK*BytePerPixel/MCLK */ + + tempax = ((52 * 16) / tempbx); + + if ((52*16 % tempbx) != 0) { + tempax++; + } + tempcx = tempax; + tempcx += 40; + + /* get DRAM latency */ + tempcl = (SiS_GetReg1(SiS_Pr->SiS_P3c4,0x17) >> 3) & 0x7; /* SR17[5:3] DRAM Queue depth */ + tempch = (SiS_GetReg1(SiS_Pr->SiS_P3c4,0x17) >> 6) & 0x3; /* SR17[7:6] DRAM Grant length */ + + for (temp3 = 0; temp3 < 16; temp3 += 2) { + if ((CombCode[temp3] == tempcl) && (CombCode[temp3+1] == tempch)) { + temp3 = CRT2ThLow[temp3 >> 1]; + } + } + + tempcx += temp3; /* CRT1 Request Period */ + + CRT2ModeNo = ModeNo; /* get CRT2 ModeNo */ + SiS_SearchModeID(SiS_Pr,ROMAddr,&CRT2ModeNo,&ModeIdIndex); /* Get ModeID Table */ + + SiS_Pr->SiS_SetFlag |= ProgrammingCRT2; + SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup; + + RefreshRateTableIndex = SiS_GetRatePtrCRT2(SiS_Pr,ROMAddr,CRT2ModeNo, + ModeIdIndex,HwDeviceExtension); + + index = SiS_GetVCLK2Ptr(SiS_Pr,ROMAddr,CRT2ModeNo,ModeIdIndex, + RefreshRateTableIndex,HwDeviceExtension); + tempax = SiS_Pr->SiS_VCLKData[index].CLOCK; /* Get VCLK */ + + tempbx = SiS_GetColorDepth(SiS_Pr,ROMAddr,CRT2ModeNo,ModeIdIndex); /* Get colordepth */ + tempbx >>= 1; + if(!tempbx) tempbx++; + + tempax *= tempbx; + + tempax *= tempcx; + + tempbx = SiS_GetMCLK(SiS_Pr,ROMAddr, HwDeviceExtension); /* Get MCLK */ + tempbx <<= 4; + + tempcx = tempax; + tempax /= tempbx; + if(tempcx % tempbx) tempax++; /* CRT1 Request period * TCLK * BytePerPixel / (MCLK*16) */ + + if (tempax > 0x37) tempax = 0x37; + + /* TW: 650/LVDS (1.10.07, 1.10.00), 650/301LV overrule calculated value; 315 does not */ + if(HwDeviceExtension->jChipType == SIS_650) { + tempax = 0x04; + } + + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,~0x3F,tempax); +} + +USHORT +SiS_GetMCLK(SiS_Private *SiS_Pr, UCHAR *ROMAddr, PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT index; + + index = SiS_Get310DRAMType(SiS_Pr,ROMAddr,HwDeviceExtension); + if(index >= 4) { + index -= 4; + return(SiS_Pr->SiS_MCLKData_1[index].CLOCK); + } else { + return(SiS_Pr->SiS_MCLKData_0[index].CLOCK); + } +} +#endif + +/* TW: Checked against 650/LVDS 1.10.07 BIOS */ +void +SiS_GetLVDSDesData(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT modeflag; + USHORT PanelIndex,ResIndex; + const SiS_LVDSDesStruct *PanelDesPtr = NULL; + + if((SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) ) { + + SiS_GetLVDSDesPtrA(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + &PanelIndex,&ResIndex); + switch (PanelIndex) + { + case 0: PanelDesPtr = SiS_Pr->LVDS1024x768Des_1; break; /* --- expanding --- */ + case 1: PanelDesPtr = SiS_Pr->LVDS1280x1024Des_1; break; + case 2: PanelDesPtr = SiS_Pr->LVDS1400x1050Des_1; break; + case 3: PanelDesPtr = SiS_Pr->LVDS1600x1200Des_1; break; + case 4: PanelDesPtr = SiS_Pr->LVDS1024x768Des_2; break; /* --- non expanding --- */ + case 5: PanelDesPtr = SiS_Pr->LVDS1280x1024Des_2; break; + case 6: PanelDesPtr = SiS_Pr->LVDS1400x1050Des_2; break; + case 7: PanelDesPtr = SiS_Pr->LVDS1600x1200Des_2; break; + default: PanelDesPtr = SiS_Pr->LVDS1024x768Des_1; break; + } + + } else { + + SiS_GetLVDSDesPtr(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + &PanelIndex,&ResIndex,HwDeviceExtension); + + switch (PanelIndex) + { + case 0: PanelDesPtr = SiS_Pr->SiS_PanelType00_1; break; /* --- expanding --- | */ + case 1: PanelDesPtr = SiS_Pr->SiS_PanelType01_1; break; + case 2: PanelDesPtr = SiS_Pr->SiS_PanelType02_1; break; + case 3: PanelDesPtr = SiS_Pr->SiS_PanelType03_1; break; + case 4: PanelDesPtr = SiS_Pr->SiS_PanelType04_1; break; + case 5: PanelDesPtr = SiS_Pr->SiS_PanelType05_1; break; + case 6: PanelDesPtr = SiS_Pr->SiS_PanelType06_1; break; + case 7: PanelDesPtr = SiS_Pr->SiS_PanelType07_1; break; + case 8: PanelDesPtr = SiS_Pr->SiS_PanelType08_1; break; + case 9: PanelDesPtr = SiS_Pr->SiS_PanelType09_1; break; + case 10: PanelDesPtr = SiS_Pr->SiS_PanelType0a_1; break; + case 11: PanelDesPtr = SiS_Pr->SiS_PanelType0b_1; break; + case 12: PanelDesPtr = SiS_Pr->SiS_PanelType0c_1; break; + case 13: PanelDesPtr = SiS_Pr->SiS_PanelType0d_1; break; + case 14: PanelDesPtr = SiS_Pr->SiS_PanelType0e_1; break; + case 15: PanelDesPtr = SiS_Pr->SiS_PanelType0f_1; break; + case 16: PanelDesPtr = SiS_Pr->SiS_PanelType00_2; break; /* --- non-expanding --- */ + case 17: PanelDesPtr = SiS_Pr->SiS_PanelType01_2; break; + case 18: PanelDesPtr = SiS_Pr->SiS_PanelType02_2; break; + case 19: PanelDesPtr = SiS_Pr->SiS_PanelType03_2; break; + case 20: PanelDesPtr = SiS_Pr->SiS_PanelType04_2; break; + case 21: PanelDesPtr = SiS_Pr->SiS_PanelType05_2; break; + case 22: PanelDesPtr = SiS_Pr->SiS_PanelType06_2; break; + case 23: PanelDesPtr = SiS_Pr->SiS_PanelType07_2; break; + case 24: PanelDesPtr = SiS_Pr->SiS_PanelType08_2; break; + case 25: PanelDesPtr = SiS_Pr->SiS_PanelType09_2; break; + case 26: PanelDesPtr = SiS_Pr->SiS_PanelType0a_2; break; + case 27: PanelDesPtr = SiS_Pr->SiS_PanelType0b_2; break; + case 28: PanelDesPtr = SiS_Pr->SiS_PanelType0c_2; break; + case 29: PanelDesPtr = SiS_Pr->SiS_PanelType0d_2; break; + case 30: PanelDesPtr = SiS_Pr->SiS_PanelType0e_2; break; + case 31: PanelDesPtr = SiS_Pr->SiS_PanelType0f_2; break; + case 32: PanelDesPtr = SiS_Pr->SiS_CHTVUNTSCDesData; break; + case 33: PanelDesPtr = SiS_Pr->SiS_CHTVONTSCDesData; break; + case 34: PanelDesPtr = SiS_Pr->SiS_CHTVUPALDesData; break; + case 35: PanelDesPtr = SiS_Pr->SiS_CHTVOPALDesData; break; + default: + if(HwDeviceExtension->jChipType < SIS_315H) + PanelDesPtr = SiS_Pr->SiS_PanelType0e_1; + else + PanelDesPtr = SiS_Pr->SiS_PanelType01_1; + break; + } + } + SiS_Pr->SiS_LCDHDES = (PanelDesPtr+ResIndex)->LCDHDES; + SiS_Pr->SiS_LCDVDES = (PanelDesPtr+ResIndex)->LCDVDES; + + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding){ + if((SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { + if(ModeNo <= 0x13) { + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + if(!(modeflag & HalfDCLK)) { + SiS_Pr->SiS_LCDHDES = 632; + } + } + } else { + if(!(SiS_Pr->SiS_SetFlag & CRT2IsVGA)) { + if((HwDeviceExtension->jChipType < SIS_315H) || (SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1280x1024)) { /* TW: New from 650/LVDS 1.10.07 */ + if(SiS_Pr->SiS_LCDResInfo >= SiS_Pr->SiS_Panel1024x768){ + if(ModeNo <= 0x13) { + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + if(HwDeviceExtension->jChipType < SIS_315H) { + if(!(modeflag & HalfDCLK)) { + SiS_Pr->SiS_LCDHDES = 320; + } + } else { + /* TW: New from 650/LVDS 1.10.07 */ + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) + SiS_Pr->SiS_LCDHDES = 480; + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) + SiS_Pr->SiS_LCDHDES = 804; + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) + SiS_Pr->SiS_LCDHDES = 704; + if(!(modeflag & HalfDCLK)) { + SiS_Pr->SiS_LCDHDES = 320; + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) + SiS_Pr->SiS_LCDHDES = 632; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) + SiS_Pr->SiS_LCDHDES = 542; + } + } + } + } + } + } + } + } + return; +} + +/* TW: Checked against 630/LVDS (2.04.5c) and 650/LVDS (1.10.07) BIOS */ +void +SiS_GetLVDSDesPtr(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,USHORT *PanelIndex, + USHORT *ResIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT tempbx,tempal,modeflag; + + if(ModeNo<=0x13) { + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; + } else { + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; + } + + tempbx = 0; + if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) { + tempbx = 32; + if((SiS_Pr->SiS_VBInfo & SetPALTV) && (!SiS_Pr->SiS_CHPALM)) tempbx += 2; + if(SiS_Pr->SiS_VBInfo & SetCHTVOverScan) tempbx += 1; + /* TW: Nothing special needed for SOverscan */ + /* PALM uses NTSC data, PALN uses PAL data */ + } + } + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + tempbx = SiS_Pr->SiS_LCDTypeInfo; + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx += 16; + /* TW: Inserted from 650/LVDS (1.10.07) BIOS */ + if(SiS_Pr->SiS_LCDInfo & LCDPass11) { + if(modeflag & HalfDCLK) tempbx += 16; + } + } + /* TW: Inserted from 630/LVDS and 650/LVDS (1.10.07) BIOS */ + if(SiS_Pr->SiS_SetFlag & CRT2IsVGA) { + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) { + tempal = 0x07; + if(HwDeviceExtension->jChipType < SIS_315H) { + if(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x13) & 0x80) tempal++; + } + } + } + + *PanelIndex = tempbx; + *ResIndex = tempal & 0x1F; +} + +void +SiS_GetLVDSDesPtrA(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,USHORT *PanelIndex, + USHORT *ResIndex) +{ + USHORT tempbx=0,tempal; + + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) { + tempbx = 3; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) { + tempbx = 4; + } else tempbx = SiS_Pr->SiS_LCDResInfo - SiS_Pr->SiS_PanelMinLVDS; + + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx += 4; + + if(ModeNo<=0x13) + tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; + else + tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; + + *PanelIndex = tempbx; + *ResIndex = tempal & 0x1F; +} + +/* TW: Checked against 650/LVDS (1.10.07), 650/301LV, 650/301LVx (!), 630/301 and 630/301B (II) BIOS */ +void +SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT BaseAddr, USHORT ModeNo, USHORT ModeIdIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT i,j,modeflag; + USHORT tempcl,tempah=0; +#ifdef SIS300 + USHORT temp; +#endif +#ifdef SIS315H + USHORT tempbl; +#endif + + if(ModeNo<=0x13) { + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + } else { + if(SiS_Pr->UseCustomMode) { + modeflag = SiS_Pr->CModeFlag; + } else { + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + } + } + + /* TW: BIOS does not do this (neither 301 nor LVDS) */ + /* (But it's harmless; see SetCRT2Offset) */ + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x03,0x00); /* fix write part1 index 0 BTDRAM bit Bug */ + + /* TW: Removed 301B302B301LV302LV check here to match 650/LVDS BIOS */ + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { + + /* TW: 1. for LVDS/302B/302LV **LCDA** */ + + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xAF,0x40); /* FUNCTION CONTROL */ + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2E,0xF7); + + } else { + + for(i=0,j=4; i<3; i++,j++) SiS_SetReg1(SiS_Pr->SiS_Part1Port,j,0); + + tempcl = SiS_Pr->SiS_ModeType; + + if(HwDeviceExtension->jChipType < SIS_315H) { + +#ifdef SIS300 /* ---- 300 series ---- */ + + /* TW: Inserted entire if-section from 630/301B BIOS */ + if((HwDeviceExtension->jChipType != SIS_300) && + (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) { + temp = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x32); + temp &= 0xef; + temp |= 0x02; + /* If 0x10 not set when using VGA2, monitor will stay black */ + if((SiS_Pr->SiS_VBInfo & SetCRT2ToTV) || (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) { + temp |= 0x10; + temp &= 0xfd; + } + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x32,temp); + } + + if(ModeNo > 0x13) { + tempcl -= ModeVGA; + if((tempcl > 0) || (tempcl == 0)) { /* TW: tempcl is USHORT -> always true! */ + tempah = ((0x10 >> tempcl) | 0x80); + } + } else tempah = 0x80; + + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0xA0; + +#endif /* SIS300 */ + + } else { + +#ifdef SIS315H /* ---- 310 series ---- */ + + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + if(SiS_Pr->SiS_VBInfo & CRT2DisplayFlag) { + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x08); + } + } + + if(ModeNo > 0x13) { + tempcl -= ModeVGA; + if((tempcl > 0) || (tempcl == 0)) { /* TW: tempcl is USHORT -> always true! */ + tempah = (0x08 >> tempcl); + if (tempah == 0) tempah = 1; + tempah |= 0x40; + } + } else tempah = 0x40; + + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0x50; + +#endif /* SIS315H */ + + } + + if(SiS_Pr->SiS_VBInfo & CRT2DisplayFlag) tempah = 0; + + if(HwDeviceExtension->jChipType < SIS_315H) { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x00,tempah); /* FUNCTION CONTROL */ + } else { + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah); /* FUNCTION CONTROL */ + } + + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + + /* TW: 2. for 301 (301B, 302B 301LV, 302LV non-LCDA) */ + + tempah = 0x01; + if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { + tempah |= 0x02; + } + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) { + tempah ^= 0x05; + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) { + tempah ^= 0x01; + } + } + + if(SiS_Pr->SiS_VBInfo & CRT2DisplayFlag) tempah = 0; + + if(HwDeviceExtension->jChipType < SIS_315H) { + + /* --- 300 series --- */ + + tempah = (tempah << 5) & 0xFF; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x01,tempah); + tempah = (tempah >> 5) & 0xFF; + + } else { + + /* --- 310 series --- */ + + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2E,0xF8,tempah); + + } + + if((SiS_Pr->SiS_ModeType == ModeVGA) && (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) { + tempah |= 0x10; + } + + /* TW: Inserted from 630/301 BIOS */ + if((HwDeviceExtension->jChipType < SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS301)) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) { + tempah |= 0x80; + } + } else { + tempah |= 0x80; + } + + if(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV - SetCRT2ToHiVisionTV)){ + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { + tempah |= 0x20; + } + } + + SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0D,0x40,tempah); + + tempah = 0; + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + SiS_Pr->SiS_SetFlag |= RPLLDIV2XO; + tempah |= 0x40; + } else { + if(!(SiS_Pr->SiS_SetFlag & TVSimuMode)) { +#ifdef oldHV + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV)) { +#endif + SiS_Pr->SiS_SetFlag |= RPLLDIV2XO; + tempah |= 0x40; +#ifdef oldHV + } +#endif + } + } + } else { + SiS_Pr->SiS_SetFlag |= RPLLDIV2XO; + tempah |= 0x40; + } + } + /* TW: Inserted from 630/301LVx BIOS 1.10.6s */ + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x39) & 0x04) + tempah |= 0x40; + } + } + + if((SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) || + (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x960)) { + tempah |= 0x80; + } + + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x0C,tempah); + + } else { + + /* TW: 3. for LVDS */ + + /* TW: Inserted if-statement - Part1Port 0x2e not assigned on 300 series */ + if(HwDeviceExtension->jChipType >= SIS_315H) { + + /* TW: Inserted this entire section (BIOS 650/LVDS); added ModeType check + * (LVDS can only be slave in 8bpp modes) + */ + tempah = 0x80; + if( (modeflag & CRT2Mode) && (SiS_Pr->SiS_ModeType > ModeVGA) ) { + if (SiS_Pr->SiS_VBInfo & DriverMode) { + tempah |= 0x02; + } + } + + if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { + tempah |= 0x02; + } + + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + tempah ^= 0x01; + } + + if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) { + tempah = 1; + } + + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2e,0xF0,tempah); + + } else { + + /* TW: (added ModeType check) */ + tempah = 0; + if( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) && (SiS_Pr->SiS_ModeType > ModeVGA) ) { + tempah |= 0x02; + } + tempah <<= 5; + + if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0; + + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x01,tempah); + + } + + } + + } + + /* TW: Inserted the entire following section */ + + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + + if(HwDeviceExtension->jChipType >= SIS_315H) { + +#ifdef SIS315H + tempah = 0x04; /* For all bridges */ + tempbl = 0xfb; + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { + tempah = 0x00; + if(SiS_IsDualEdge(SiS_Pr, HwDeviceExtension, BaseAddr)) + tempbl = 0xff; + } + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah); + + /* TW: This in order to fix "TV-blue-bug" on 315+301 */ + if(SiS_Pr->SiS_VBType & VB_SIS301) { + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2c,0xCF); /* For 301 */ + } else { + if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,0xCF,0x30); /* For 301LV */ + } else { + tempah = 0x30; /* For 301B */ + tempbl = 0xcf; + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { + tempah = 0x00; + if(SiS_IsDualEdge(SiS_Pr, HwDeviceExtension, BaseAddr)) { + tempbl = 0xff; + } + } + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,tempbl,tempah); + } + } + + if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { /* For 301LV */ + SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0x3f,0xc0); + } else { /* For 301, 301B */ + tempah = 0xc0; + tempbl = 0x3f; + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { + tempah = 0x00; + if(SiS_IsDualEdge(SiS_Pr, HwDeviceExtension, BaseAddr)) { + tempbl = 0xff; + } + } + SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,tempbl,tempah); + } + + tempah = 0x00; /* For all bridges */ + tempbl = 0x7f; + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { + tempbl = 0xff; + if(!(SiS_IsDualEdge(SiS_Pr, HwDeviceExtension, BaseAddr))) + tempah |= 0x80; + } + SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,tempbl,tempah); + +#endif /* SIS315H */ + + } else if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + + SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f); + + if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) || + ( (HwDeviceExtension->jChipType != SIS_300) && + (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) ) ) { + SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x23,0x7F); + } else { + SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x23,0x80); + } + + } + + } else { /* LVDS */ + +#ifdef SIS315H + if(HwDeviceExtension->jChipType >= SIS_315H) { + + if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { + + tempah = 0x04; + tempbl = 0xfb; + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { + tempah = 0x00; + if(SiS_IsDualEdge(SiS_Pr, HwDeviceExtension, BaseAddr)) + tempbl = 0xff; + } + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah); + + if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x00); + + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,0xcf,0x30); + + } + + } +#endif + + } + +} + +void +SiS_GetCRT2Data(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { + + SiS_GetCRT2DataLVDS(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + HwDeviceExtension); + } else { + + if((HwDeviceExtension->jChipType < SIS_315H) && + (HwDeviceExtension->jChipType != SIS_300) && + (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) { + + SiS_GetCRT2Data301(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + HwDeviceExtension); + + /* TW: Need LVDS Data for LCD on 630/301B! */ + SiS_GetCRT2DataLVDS(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + HwDeviceExtension); + + } else { + + SiS_GetCRT2Data301(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + HwDeviceExtension); + } + + } + + } else { + + SiS_GetCRT2Data301(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + HwDeviceExtension); + } + + } else { + + SiS_GetCRT2DataLVDS(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + HwDeviceExtension); + } +} + +/* Checked with 650/LVDS 1.10.07 BIOS */ +void +SiS_GetCRT2DataLVDS(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT CRT2Index, ResIndex; + const SiS_LVDSDataStruct *LVDSData = NULL; + + SiS_GetCRT2ResInfo(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,HwDeviceExtension); + + if((SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { + + SiS_Pr->SiS_NewFlickerMode = 0; + SiS_Pr->SiS_RVBHRS = 50; + SiS_Pr->SiS_RY1COE = 0; + SiS_Pr->SiS_RY2COE = 0; + SiS_Pr->SiS_RY3COE = 0; + SiS_Pr->SiS_RY4COE = 0; + + SiS_GetCRT2PtrA(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + &CRT2Index,&ResIndex); + + switch (CRT2Index) { + case 0: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1; break; + case 1: LVDSData = SiS_Pr->SiS_LVDS1280x1024Data_1; break; + case 2: LVDSData = SiS_Pr->SiS_LVDS1280x960Data_1; break; + case 3: LVDSData = SiS_Pr->SiS_LCDA1400x1050Data_1; break; + case 4: LVDSData = SiS_Pr->SiS_LCDA1600x1200Data_1; break; + case 5: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_2; break; + case 6: LVDSData = SiS_Pr->SiS_LVDS1280x1024Data_2; break; + case 7: LVDSData = SiS_Pr->SiS_LVDS1280x960Data_2; break; + case 8: LVDSData = SiS_Pr->SiS_LCDA1400x1050Data_2; break; + case 9: LVDSData = SiS_Pr->SiS_LCDA1600x1200Data_2; break; + default: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1; break; + } + + } else { + + /* TW: SiS630/301B needs LVDS Data! */ + if( (HwDeviceExtension->jChipType < SIS_315H) && + (HwDeviceExtension->jChipType != SIS_300) && + (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && + (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) ) { + SiS_Pr->SiS_IF_DEF_LVDS = 1; + } + + SiS_GetCRT2Ptr(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + &CRT2Index,&ResIndex,HwDeviceExtension); + + /* TW: SiS630/301B needs LVDS Data! */ + if( (HwDeviceExtension->jChipType < SIS_315H) && + (HwDeviceExtension->jChipType != SIS_300) && + (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && + (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) ) { + SiS_Pr->SiS_IF_DEF_LVDS = 0; + } + + switch (CRT2Index) { + case 0: LVDSData = SiS_Pr->SiS_LVDS800x600Data_1; break; + case 1: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1; break; + case 2: LVDSData = SiS_Pr->SiS_LVDS1280x1024Data_1; break; + case 3: LVDSData = SiS_Pr->SiS_LVDS800x600Data_2; break; + case 4: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_2; break; + case 5: LVDSData = SiS_Pr->SiS_LVDS1280x1024Data_2; break; + case 6: LVDSData = SiS_Pr->SiS_LVDS640x480Data_1; break; + case 7: LVDSData = SiS_Pr->SiS_LVDSXXXxXXXData_1; break; /* TW: New */ + case 8: LVDSData = SiS_Pr->SiS_LVDS1400x1050Data_1; break; /* TW: New */ + case 9: LVDSData = SiS_Pr->SiS_LVDS1400x1050Data_2; break; /* TW: New */ + case 10: LVDSData = SiS_Pr->SiS_CHTVUNTSCData; break; + case 11: LVDSData = SiS_Pr->SiS_CHTVONTSCData; break; + case 12: LVDSData = SiS_Pr->SiS_CHTVUPALData; break; + case 13: LVDSData = SiS_Pr->SiS_CHTVOPALData; break; + case 14: LVDSData = SiS_Pr->SiS_LVDS320x480Data_1; break; + case 15: LVDSData = SiS_Pr->SiS_LVDS1024x600Data_1; break; /* TW: New */ + case 16: LVDSData = SiS_Pr->SiS_LVDS1152x768Data_1; break; /* TW: New */ + case 17: LVDSData = SiS_Pr->SiS_LVDS1024x600Data_2; break; /* TW: New */ + case 18: LVDSData = SiS_Pr->SiS_LVDS1152x768Data_2; break; /* TW: New */ + case 19: LVDSData = SiS_Pr->SiS_LVDS1280x768Data_1; break; /* TW: New */ + case 20: LVDSData = SiS_Pr->SiS_LVDS1280x768Data_2; break; /* TW: New */ + case 90: LVDSData = SiS_Pr->SiS_CHTVUPALMData; break; + case 91: LVDSData = SiS_Pr->SiS_CHTVOPALMData; break; + case 92: LVDSData = SiS_Pr->SiS_CHTVUPALNData; break; + case 93: LVDSData = SiS_Pr->SiS_CHTVOPALNData; break; + case 99: LVDSData = SiS_Pr->SiS_CHTVSOPALData; break; /* TW: Super Overscan */ + default: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1; break; + } + } + + SiS_Pr->SiS_VGAHT = (LVDSData+ResIndex)->VGAHT; + SiS_Pr->SiS_VGAVT = (LVDSData+ResIndex)->VGAVT; + SiS_Pr->SiS_HT = (LVDSData+ResIndex)->LCDHT; + SiS_Pr->SiS_VT = (LVDSData+ResIndex)->LCDVT; + + if((SiS_Pr->SiS_IF_DEF_LVDS == 0) && (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) { + + if(!(SiS_Pr->SiS_LCDInfo & LCDNonExpanding)){ + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768){ + SiS_Pr->SiS_HDE = 1024; + SiS_Pr->SiS_VDE = 768; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024){ + SiS_Pr->SiS_HDE = 1280; + SiS_Pr->SiS_VDE = 1024; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050){ + SiS_Pr->SiS_HDE = 1400; + SiS_Pr->SiS_VDE = 1050; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200){ + SiS_Pr->SiS_HDE = 1600; + SiS_Pr->SiS_VDE = 1200; + } else { + SiS_Pr->SiS_HDE = 1280; + SiS_Pr->SiS_VDE = 960; + } + } + + } else { + + if(SiS_Pr->SiS_IF_DEF_TRUMPION == 0) { + if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) { + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) { + if((!(SiS_Pr->SiS_LCDInfo & LCDNonExpanding)) || (SiS_Pr->SiS_SetFlag & CRT2IsVGA)) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) { + SiS_Pr->SiS_HDE = 800; + SiS_Pr->SiS_VDE = 600; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) { + SiS_Pr->SiS_HDE = 1024; + SiS_Pr->SiS_VDE = 768; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) { + SiS_Pr->SiS_HDE = 1280; + SiS_Pr->SiS_VDE = 1024; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600) { + SiS_Pr->SiS_HDE = 1024; + SiS_Pr->SiS_VDE = 600; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) { + SiS_Pr->SiS_HDE = 1400; + SiS_Pr->SiS_VDE = 1050; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1152x768) { + SiS_Pr->SiS_HDE = 1152; + SiS_Pr->SiS_VDE = 768; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1152x864) { + SiS_Pr->SiS_HDE = 1152; + SiS_Pr->SiS_VDE = 864; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x768) { + SiS_Pr->SiS_HDE = 1280; + SiS_Pr->SiS_VDE = 768; + } else { + SiS_Pr->SiS_HDE = 1600; + SiS_Pr->SiS_VDE = 1200; + } + if(SiS_Pr->SiS_IF_DEF_FSTN) { + SiS_Pr->SiS_HDE = 320; + SiS_Pr->SiS_VDE = 480; + } + } + } + } + } + } +} + +/* TW: Checked against 630/301B BIOS; does not check VDE values for LCD */ +void +SiS_GetCRT2Data301(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT tempax,tempbx,modeflag; + USHORT resinfo; + USHORT CRT2Index,ResIndex; + const SiS_LCDDataStruct *LCDPtr = NULL; + const SiS_TVDataStruct *TVPtr = NULL; + + if(ModeNo<=0x13) { + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo; + } else { + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; + } + SiS_Pr->SiS_NewFlickerMode = 0; + SiS_Pr->SiS_RVBHRS = 50; + SiS_Pr->SiS_RY1COE = 0; + SiS_Pr->SiS_RY2COE = 0; + SiS_Pr->SiS_RY3COE = 0; + SiS_Pr->SiS_RY4COE = 0; + + SiS_GetCRT2ResInfo(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,HwDeviceExtension); + + /* TW: For VGA2 ("RAMDAC2") */ + + if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC){ + SiS_GetRAMDAC2DATA(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + HwDeviceExtension); + return; + } + + /* TW: For TV */ + + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + + SiS_GetCRT2Ptr(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + &CRT2Index,&ResIndex,HwDeviceExtension); + + switch (CRT2Index) { +#ifdef oldHV + case 2: TVPtr = SiS_Pr->SiS_ExtHiTVData; break; + case 7: TVPtr = SiS_Pr->SiS_St1HiTVData; break; + case 12: TVPtr = SiS_Pr->SiS_St2HiTVData; break; +#endif + case 3: TVPtr = SiS_Pr->SiS_ExtPALData; break; + case 4: TVPtr = SiS_Pr->SiS_ExtNTSCData; break; + case 8: TVPtr = SiS_Pr->SiS_StPALData; break; + case 9: TVPtr = SiS_Pr->SiS_StNTSCData; break; + default: TVPtr = SiS_Pr->SiS_StPALData; break; /* TW: Just to avoid a crash */ + } + + SiS_Pr->SiS_RVBHCMAX = (TVPtr+ResIndex)->RVBHCMAX; + SiS_Pr->SiS_RVBHCFACT = (TVPtr+ResIndex)->RVBHCFACT; + SiS_Pr->SiS_VGAHT = (TVPtr+ResIndex)->VGAHT; + SiS_Pr->SiS_VGAVT = (TVPtr+ResIndex)->VGAVT; + SiS_Pr->SiS_HDE = (TVPtr+ResIndex)->TVHDE; + SiS_Pr->SiS_VDE = (TVPtr+ResIndex)->TVVDE; + SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->RVBHRS; + SiS_Pr->SiS_NewFlickerMode = (TVPtr+ResIndex)->FlickerMode; + if(modeflag & HalfDCLK) { + SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->HALFRVBHRS; + } + + if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) { /* TW: NOT oldHV! */ + + if(resinfo == 0x08) SiS_Pr->SiS_NewFlickerMode = 0x40; + if(resinfo == 0x09) SiS_Pr->SiS_NewFlickerMode = 0x40; + if(resinfo == 0x12) SiS_Pr->SiS_NewFlickerMode = 0x40; + + if(SiS_Pr->SiS_VGAVDE == 350) SiS_Pr->SiS_SetFlag |= TVSimuMode; + + SiS_Pr->SiS_HT = ExtHiTVHT; + SiS_Pr->SiS_VT = ExtHiTVVT; + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { + if(SiS_Pr->SiS_SetFlag & TVSimuMode) { + SiS_Pr->SiS_HT = StHiTVHT; + SiS_Pr->SiS_VT = StHiTVVT; + if(!(modeflag & Charx8Dot)){ + SiS_Pr->SiS_HT = StHiTextTVHT; + SiS_Pr->SiS_VT = StHiTextTVVT; + } + } + } + + } else { + + SiS_Pr->SiS_RY1COE = (TVPtr+ResIndex)->RY1COE; + SiS_Pr->SiS_RY2COE = (TVPtr+ResIndex)->RY2COE; + SiS_Pr->SiS_RY3COE = (TVPtr+ResIndex)->RY3COE; + SiS_Pr->SiS_RY4COE = (TVPtr+ResIndex)->RY4COE; + + if(modeflag & HalfDCLK) { + SiS_Pr->SiS_RY1COE = 0x00; + SiS_Pr->SiS_RY2COE = 0xf4; + SiS_Pr->SiS_RY3COE = 0x10; + SiS_Pr->SiS_RY4COE = 0x38; + } + + if(!(SiS_Pr->SiS_VBInfo & SetPALTV)) { + SiS_Pr->SiS_HT = NTSCHT; +/* if(SiS_Pr->SiS_VBType & (VB_SIS30xLV|VB_SIS30xNEW)) { */ /* TW: ALL newer 650 BIOSes do this, no idea about 301B */ + if((ModeNo == 0x4a) || (ModeNo == 0x38)) SiS_Pr->SiS_HT = NTSC2HT; +/* } */ + SiS_Pr->SiS_VT = NTSCVT; + } else { + SiS_Pr->SiS_HT = PALHT; + SiS_Pr->SiS_VT = PALVT; + } + + } + + return; + } + + /* TW: For LCD */ + /* TW: Checked against 650/301LV; CRT2Index different (but does not matter) */ + + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + + SiS_GetCRT2Ptr(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + &CRT2Index,&ResIndex,HwDeviceExtension); + + switch (CRT2Index) { + case 0: LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break; /* VESA Timing */ + case 1: LCDPtr = SiS_Pr->SiS_ExtLCD1280x1024Data; break; /* VESA Timing */ + case 5: LCDPtr = SiS_Pr->SiS_StLCD1024x768Data; break; /* Obviously unused */ + case 6: LCDPtr = SiS_Pr->SiS_StLCD1280x1024Data; break; /* Obviously unused */ + case 10: LCDPtr = SiS_Pr->SiS_St2LCD1024x768Data; break; /* Non-VESA Timing */ + case 11: LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break; /* Non-VESA Timing */ + case 13: LCDPtr = SiS_Pr->SiS_NoScaleData1024x768; break; /* Non-expanding */ + case 14: LCDPtr = SiS_Pr->SiS_NoScaleData1280x1024; break; /* Non-expanding */ + case 15: LCDPtr = SiS_Pr->SiS_LCD1280x960Data; break; /* 1280x960 */ + case 20: LCDPtr = SiS_Pr->SiS_ExtLCD1400x1050Data; break; /* VESA Timing */ + case 21: LCDPtr = SiS_Pr->SiS_NoScaleData1400x1050; break; /* Non-expanding */ + case 22: LCDPtr = SiS_Pr->SiS_StLCD1400x1050Data; break; /* Non-VESA Timing */ + case 23: LCDPtr = SiS_Pr->SiS_ExtLCD1600x1200Data; break; /* VESA Timing */ + case 24: LCDPtr = SiS_Pr->SiS_NoScaleData1600x1200; break; /* Non-expanding */ + case 25: LCDPtr = SiS_Pr->SiS_StLCD1600x1200Data; break; /* Non-VESA Timing */ + default: LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break; /* Just to avoid a crash */ + } + + SiS_Pr->SiS_RVBHCMAX = (LCDPtr+ResIndex)->RVBHCMAX; + SiS_Pr->SiS_RVBHCFACT = (LCDPtr+ResIndex)->RVBHCFACT; + SiS_Pr->SiS_VGAHT = (LCDPtr+ResIndex)->VGAHT; + SiS_Pr->SiS_VGAVT = (LCDPtr+ResIndex)->VGAVT; + SiS_Pr->SiS_HT = (LCDPtr+ResIndex)->LCDHT; + SiS_Pr->SiS_VT = (LCDPtr+ResIndex)->LCDVT; + + tempax = 1024; + if(SiS_Pr->SiS_SetFlag & LCDVESATiming) { + if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 560; + else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640; + else tempbx = 768; + } else { + if (SiS_Pr->SiS_VGAVDE == 357) tempbx = 527; + else if(SiS_Pr->SiS_VGAVDE == 420) tempbx = 620; + else if(SiS_Pr->SiS_VGAVDE == 525) tempbx = 775; + else if(SiS_Pr->SiS_VGAVDE == 600) tempbx = 775; + else if(SiS_Pr->SiS_VGAVDE == 350) tempbx = 560; + else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640; + else tempbx = 768; + } + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024){ + tempax = 1280; + if (SiS_Pr->SiS_VGAVDE == 360) tempbx = 768; + else if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 800; + else if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 864; + else tempbx = 1024; + } + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x960){ + tempax = 1280; + if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 700; + else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 800; + else if(SiS_Pr->SiS_VGAVDE == 1024) tempbx = 960; + else tempbx = 960; + } + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050){ + tempax = 1400; + tempbx = 1050; + } + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) { + tempax = SiS_Pr->SiS_VGAHDE; + tempbx = SiS_Pr->SiS_VGAVDE; + } + SiS_Pr->SiS_HDE = tempax; + SiS_Pr->SiS_VDE = tempbx; + return; + } +} + +USHORT +SiS_GetResInfo(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex) +{ + USHORT resindex; + + if(ModeNo<=0x13) + resindex=SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo; + else + resindex=SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; + + return(resindex); +} + +/* TW: Checked against 650/301LV, 650/LVDS, 630/LVDS, 630/301 and 630/301B BIOS */ +void +SiS_GetCRT2ResInfo(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT xres,yres,modeflag=0,resindex; + + resindex = SiS_GetResInfo(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex); + + if(ModeNo <= 0x13) { + xres = SiS_Pr->SiS_StResInfo[resindex].HTotal; + yres = SiS_Pr->SiS_StResInfo[resindex].VTotal; + } else { + xres = SiS_Pr->SiS_ModeResInfo[resindex].HTotal; + yres = SiS_Pr->SiS_ModeResInfo[resindex].VTotal; + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + } + + /* TW: Inserted entire if-section from 650/LVDS BIOS 1.10.07: */ + if((HwDeviceExtension->jChipType >= SIS_315H) && (SiS_Pr->SiS_IF_DEF_LVDS == 1)) { + if((ModeNo != 0x03) && (SiS_Pr->SiS_SetFlag & CRT2IsVGA)) { + if(yres == 350) yres = 400; + } + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x3a) & 0x01) { + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x34) == 0x12) + yres = 400; + } + } + + if(ModeNo > 0x13) { + if(SiS_Pr->SiS_IF_DEF_FSTN == 1){ + xres *= 2; + yres *= 2; + } else { + if(modeflag & HalfDCLK) xres *= 2; + if(modeflag & DoubleScanMode) yres *= 2; + } + } + + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + /* TW: Inserted from 650/301LV BIOS */ + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { + if(xres == 720) xres = 640; + } else { + if((HwDeviceExtension->jChipType != SIS_300) || + (SiS_Pr->SiS_VBInfo & (SetCRT2ToAVIDEO | SetCRT2ToSVIDEO | + SetCRT2ToSCART | SetCRT2ToLCD | SetCRT2ToHiVisionTV))) { + if(xres == 720) xres = 640; + } + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) { + if(yres == 400) yres = 405; + if(yres == 350) yres = 360; + if(SiS_Pr->SiS_SetFlag & LCDVESATiming) { + if(yres == 360) yres = 375; + } + } + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768){ + if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) { + if(!(SiS_Pr->SiS_LCDInfo & LCDNonExpanding)) { + if(yres == 350) yres = 357; + if(yres == 400) yres = 420; + if(yres == 480) yres = 525; + } + } + } + /* TW: Inserted for 630/301B */ + if( ( (HwDeviceExtension->jChipType < SIS_315H) && + (HwDeviceExtension->jChipType != SIS_300) ) && + (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) ) { + if(xres == 720) xres = 640; + } + } + } else { + if(xres == 720) xres = 640; + /* TW: Inserted from 650/LVDS and 630/LVDS BIOS */ + if(SiS_Pr->SiS_SetFlag & CRT2IsVGA) { + yres = 400; + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x17) & 0x80) yres = 480; + } else { + if(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x13) & 0x80) yres = 480; + } + } + } + SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres; + SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = yres; +} + +/* TW: Checked against 650/301 and 650/LVDS (1.10.07) BIOS; modified for new panel resolutions */ +/* TW: Done differently in 630/301B BIOS; but same effect; checked against 630/301 */ +void +SiS_GetCRT2Ptr(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,USHORT *CRT2Index,USHORT *ResIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT tempbx=0,tempal=0; + USHORT Flag,resinfo=0; + + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { /* LCD */ + + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x960) { + tempbx = 15; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) { + tempbx = 20; + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx = 21; + if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx = 22; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) { + tempbx = 23; + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx = 24; + if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx = 25; + } else if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) { + tempbx = 13; + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) tempbx++; + } else { + tempbx = SiS_Pr->SiS_LCDResInfo - SiS_Pr->SiS_Panel1024x768; + if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) { + tempbx += 5; + /* GetRevisionID(); */ + /* TW: BIOS only adds 5 once */ + tempbx += 5; + } + } + + } else { /* TV */ +#ifdef oldHV + if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV){ + if(SiS_Pr->SiS_VGAVDE > 480) SiS_Pr->SiS_SetFlag &= (~TVSimuMode); /* TW: Was "(!TVSimuMode)" - WRONG */ + tempbx = 2; + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { + if(!(SiS_Pr->SiS_SetFlag & TVSimuMode)) tempbx = 12; /* TW: Was 10! - WRONG */ + } + } else { +#endif + if(SiS_Pr->SiS_VBInfo & SetPALTV) tempbx = 3; + else tempbx = 4; + if(SiS_Pr->SiS_SetFlag & TVSimuMode) tempbx += 5; +#ifdef oldHV + } +#endif + } + + if(ModeNo <= 0x13) { + tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; + } else { + tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; + resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; + } + + tempal &= 0x3F; + + if((SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && + (SiS_Pr->SiS_VBInfo & (SetCRT2ToTV-SetCRT2ToHiVisionTV))) { + if(tempal == 0x06) tempal = 0x07; + } + + /* TW: Inserted from 300/301LV BIOS */ + if((HwDeviceExtension->jChipType == SIS_300) && + (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) { + if(ModeNo > 0x13) { + if((resinfo == 0x0c) || (resinfo == 0x0d)) /* 720 (index diff. on 310/325!) */ + tempal = 6; + } + } + + if(HwDeviceExtension->jChipType != SIS_300) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + if((ModeNo == 0x31) || (ModeNo == 0x32)) tempal = 6; + } + } + + *CRT2Index = tempbx; + *ResIndex = tempal; + + } else { /* LVDS */ + + Flag = 1; + tempbx = 0; + if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) { + Flag = 0; + tempbx = 10; + if(SiS_Pr->SiS_VBInfo & SetCHTVOverScan) tempbx += 1; + if(SiS_Pr->SiS_VBInfo & SetPALTV) { + tempbx += 2; + if(SiS_Pr->SiS_CHSOverScan) tempbx = 99; + if(SiS_Pr->SiS_CHPALM) { + tempbx = 90; + if(SiS_Pr->SiS_VBInfo & SetCHTVOverScan) tempbx += 1; + } else if(SiS_Pr->SiS_CHPALN) { + tempbx = 92; + if(SiS_Pr->SiS_VBInfo & SetCHTVOverScan) tempbx += 1; + } + + } + } + } + + if(Flag == 1) { + tempbx = SiS_Pr->SiS_LCDResInfo - SiS_Pr->SiS_PanelMinLVDS; + if(SiS_Pr->SiS_LCDResInfo <= SiS_Pr->SiS_Panel1280x1024) { + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx += 3; + } else { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) { + tempbx = 8; + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx++; + } + if(SiS_Pr->SiS_LCDInfo & LCDPass11) { + tempbx = 7; + } + + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480) tempbx = 6; + + /* TW: Inserted from 630/LVDS 2.04.5c BIOS */ + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600) { + tempbx = 15; + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx += 2; + } + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1152x768) { + tempbx = 16; + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx += 2; + } + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x768) { + tempbx = 18; + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx++; + } + } + } + + if(ModeNo <= 0x13) + tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; + else { + tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; + resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; + } + + if(SiS_Pr->SiS_IF_DEF_FSTN){ + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel320x480){ + tempbx = 14; + tempal = 6; + } + } + + /* TW: Inserted from 650/LVDS BIOS */ + if(SiS_Pr->SiS_SetFlag & CRT2IsVGA) { + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) tempal = 7; + if(HwDeviceExtension->jChipType < SIS_315H) { + /* TW: Inserted from 630/LVDS (2.04.5c) and 630/301B (II) BIOS */ + if(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x13) & 0x80) tempal++; + } + + } + + /* TW: Inserted from 630/301B BIOS */ + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + if(ModeNo > 0x13) { + if(HwDeviceExtension->jChipType < SIS_315H) { + if((resinfo == 0x0c) || (resinfo == 0x0d)) /* 720 */ + tempal = 6; + } else { + if((resinfo == 0x0d) || (resinfo == 0x0e)) /* 720 */ + tempal = 6; + } + } + } + + *CRT2Index = tempbx; + *ResIndex = tempal & 0x1F; + } +} + +void +SiS_GetCRT2PtrA(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,USHORT *CRT2Index, + USHORT *ResIndex) +{ + USHORT tempbx,tempal; + + tempbx = SiS_Pr->SiS_LCDResInfo; + + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) { + tempbx = 4; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) { + tempbx = 3; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x960) { + tempbx = 2; + } else { + tempbx -= SiS_Pr->SiS_Panel1024x768; + } + + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx += 5; + + if(ModeNo <= 0x13) + tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; + else + tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; + + *CRT2Index = tempbx; + *ResIndex = tempal & 0x1F; +} + +/* TW: New from 650/301LVx BIOS */ +void +SiS_GetCRT2Part2Ptr(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,USHORT *CRT2Index, + USHORT *ResIndex) +{ + USHORT tempbx,tempal; + + if(ModeNo <= 0x13) + tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; + else + tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; + + tempbx = SiS_Pr->SiS_LCDResInfo; + + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx += 16; + else if(SiS_Pr->SiS_SetFlag & LCDVESATiming) tempbx += 32; + + *CRT2Index = tempbx; + *ResIndex = tempal & 0x3F; +} + +/* TW: Checked against all (incl 650/LVDS (1.10.07), 630/301B, 630/301) BIOSes */ +USHORT +SiS_GetRatePtrCRT2(SiS_Private *SiS_Pr, UCHAR *ROMAddr, USHORT ModeNo, USHORT ModeIdIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + SHORT LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, + 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01 }; + USHORT RefreshRateTableIndex,i,backup_i; + USHORT modeflag,index,temp,backupindex; + + if(SiS_Pr->UseCustomMode) return 0; + + if(ModeNo <= 0x13) + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + else + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + + if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + if(modeflag & HalfDCLK) return(0); + } + } + + if(ModeNo < 0x14) return(0xFFFF); + + /* TW: CR33 holds refresh rate index for CRT1 [3:0] and CRT2 [7:4]. + * On LVDS machines, CRT2 index is always 0 and will be + * set to 0 by the following code; this causes the function + * to take the first non-interlaced mode in SiS_Ext2Struct + */ + + index = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x33); + index >>= SiS_Pr->SiS_SelectCRT2Rate; + index &= 0x0F; + backupindex = index; + + if(index > 0) index--; + + if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) { + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { + if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) index = 0; + } else { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + if((HwDeviceExtension->jChipType < SIS_315H) && + (HwDeviceExtension->jChipType != SIS_300)) + index = 0; + else if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) + index = backupindex = 0; + } + } + } + + if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) { + if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + index = 0; + } + } + if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + /* TW: This is not done in 630/301B BIOS */ + temp = LCDRefreshIndex[SiS_Pr->SiS_LCDResInfo]; + if(index > temp) index = temp; + } else { + index = 0; + } + } + } + + RefreshRateTableIndex = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex; + ModeNo = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].ModeID; + + /* TW: Inserted from 650/LVDS 1.10.07, 650/301LVx 1.10.6s */ + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(!(SiS_Pr->SiS_VBInfo & DriverMode)) { + if( (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x105) || + (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x107) ) { + if(backupindex <= 1) + RefreshRateTableIndex++; + } + } + } + + i = 0; + do { + if(SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + i].ModeID != ModeNo) break; + temp = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag; + temp &= ModeInfoFlag; + if(temp < SiS_Pr->SiS_ModeType) break; + i++; + index--; + } while(index != 0xFFFF); + + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) { + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { + temp = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + i - 1].Ext_InfoFlag; + if(temp & InterlaceMode) { + i++; + } + } + } + + i--; + + if((SiS_Pr->SiS_SetFlag & ProgrammingCRT2) && (!(SiS_Pr->SiS_VBInfo & DisableCRT2Display))) { + backup_i = i; + if (!(SiS_AdjustCRT2Rate(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex, + RefreshRateTableIndex,&i,HwDeviceExtension))) { + /* TW: This is for avoiding random data to be used; i is + * in an undefined state if no matching CRT2 mode is + * found. + */ + i = backup_i; + } + } + + return(RefreshRateTableIndex + i); +} + +/* Checked against all (incl 650/LVDS (1.10.07), 630/301) BIOSes */ +BOOLEAN +SiS_AdjustCRT2Rate(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,USHORT *i,PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT tempax,tempbx,resinfo; + USHORT modeflag,infoflag; + + if (ModeNo <= 0x13) + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + else + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + + resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; + tempbx = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + (*i)].ModeID; + + tempax = 0; + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + /* TW: For 301, 301B, 302B, 301LV, 302LV */ + if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { + tempax |= SupportRAMDAC2; + if(HwDeviceExtension->jChipType >= SIS_315H) { + tempax |= SupportTV; + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { + if(resinfo == 0x0a) tempax |= SupportTV1024; + } + } + } + } + if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { + tempax |= SupportLCD; + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1600x1200) { + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1400x1050) { + if((resinfo == 6) && (SiS_Pr->SiS_LCDInfo & LCDNonExpanding)) { + tempax |= SupportAllCRT2; + (*i) = 0; /* TW: Restore RefreshTableIndex (BIOS 650/301LVx 1.10.6s) */ + return(1); + } else { + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1280x1024) { + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1280x960) { + if((resinfo == 6) && (SiS_Pr->SiS_LCDInfo & LCDNonExpanding)) { + return(0); + } else { + if((resinfo >= 9) && (resinfo != 0x14)) { + tempax = 0; + return(0); + } + } + } + } + } + } + } + } else { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600) { + if((resinfo != 0x0f) && ((resinfo == 4) || (resinfo >= 8))) return(0); + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1152x768) { + if((resinfo != 0x10) && (resinfo > 8)) return(0); + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x960) { + if((resinfo != 0x0e) && (resinfo > 8)) return(0); + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) { + if(resinfo > 9) return(0); + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) { + if(resinfo > 8) return(0); + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) { + if((resinfo == 4) || (resinfo > 7)) return(0); + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480) { + if((resinfo == 4) || (resinfo == 3) || (resinfo > 6)) return(0); + } + } + } +#ifdef oldHV + if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) { /* for HiTV */ + tempax |= SupportHiVisionTV; + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode){ + if(resinfo == 4) return(0); + if(resinfo == 3) { + if(SiS_Pr->SiS_SetFlag & TVSimuMode) return(0); + } + if(resinfo > 7) return(0); + } + } else { +#endif + if(SiS_Pr->SiS_VBInfo & (SetCRT2ToAVIDEO|SetCRT2ToSVIDEO|SetCRT2ToSCART)) { + tempax |= SupportTV; + tempax |= SupportTV1024; + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { + if((SiS_Pr->SiS_VBInfo & SetNotSimuMode) && (SiS_Pr->SiS_VBInfo & SetPALTV)) { + if(resinfo != 8) { + if( (!(SiS_Pr->SiS_VBInfo & SetPALTV)) || + ((SiS_Pr->SiS_VBInfo & SetPALTV) && (resinfo != 4)) ) { + tempax &= ~(SupportTV1024); + if(HwDeviceExtension->jChipType >= SIS_315H) { + if((modeflag & NoSupportSimuTV) && (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { + if( (!(SiS_Pr->SiS_VBInfo & SetPALTV)) || + ((SiS_Pr->SiS_VBInfo & SetPALTV) && (resinfo != 7)) ) { + if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) return(0); + } + } + } else { + if( (resinfo != 3) || + (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || + (SiS_Pr->SiS_VBInfo & SetNotSimuMode) ) { + if(!(SiS_Pr->SiS_VBInfo & SetPALTV)) { + if((modeflag & NoSupportSimuTV) && (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { + if(resinfo == 3) return(0); + if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) return (0); + } + } + } else return(0); + } + } + } + } else { + tempax &= ~(SupportTV1024); + if(HwDeviceExtension->jChipType >= SIS_315H) { + if((modeflag & NoSupportSimuTV) && (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { + if( (!(SiS_Pr->SiS_VBInfo & SetPALTV)) || + ((SiS_Pr->SiS_VBInfo & SetPALTV) && (resinfo != 7)) ) { + if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) return(0); + } + } + } else { + if( (resinfo != 3) || + (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || + (SiS_Pr->SiS_VBInfo & SetNotSimuMode) ) { + if(!(SiS_Pr->SiS_VBInfo & SetPALTV)) { + if((modeflag & NoSupportSimuTV) && (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { + if(resinfo == 3) return(0); + if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) return (0); + } + } + } else return(0); + } + } + } else { /* slavemode */ + if(resinfo != 8) { + if( (!(SiS_Pr->SiS_VBInfo & SetPALTV)) || + ((SiS_Pr->SiS_VBInfo & SetPALTV) && (resinfo != 4) ) ) { + tempax &= ~(SupportTV1024); + if(HwDeviceExtension->jChipType >= SIS_315H) { + if((modeflag & NoSupportSimuTV) && (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { + if( (!(SiS_Pr->SiS_VBInfo & SetPALTV)) || + ((SiS_Pr->SiS_VBInfo & SetPALTV) && (resinfo != 7)) ) { + if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) return(0); + } + } + } else { + if( (resinfo != 3) || + (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || + (SiS_Pr->SiS_VBInfo & SetNotSimuMode) ) { + if(!(SiS_Pr->SiS_VBInfo & SetPALTV)) { + if((modeflag & NoSupportSimuTV) && (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { + if(resinfo == 3) return(0); + if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) return (0); + } + } + } else return(0); + } + } + } + } + } else { /* 301 */ + tempax &= ~(SupportTV1024); + if(HwDeviceExtension->jChipType >= SIS_315H) { + if((modeflag & NoSupportSimuTV) && (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { + if( (!(SiS_Pr->SiS_VBInfo & SetPALTV)) || + ((SiS_Pr->SiS_VBInfo & SetPALTV) && (resinfo != 7)) ) { + if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) return(0); + } + } + } else { + if( (resinfo != 3) || + (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || + (SiS_Pr->SiS_VBInfo & SetNotSimuMode) ) { + if(!(SiS_Pr->SiS_VBInfo & SetPALTV)) { + if((modeflag & NoSupportSimuTV) && (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { + if(resinfo == 3) return(0); + if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) return (0); + } + } + } else return(0); + } + } + } +#ifdef oldHV + } +#endif + } else { /* TW: for LVDS */ + + if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + tempax |= SupportCHTV; + } + } + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + tempax |= SupportLCD; + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x768) { + if((resinfo != 0x14) && (resinfo > 0x09)) return(0); + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600) { + if((resinfo != 0x0f) && (resinfo > 0x08)) return(0); + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1152x768) { + if((resinfo != 0x10) && (resinfo > 0x08)) return(0); + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) { + if((resinfo != 0x15) && (resinfo > 0x09)) return(0); + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) { + if(resinfo > 0x09) return(0); + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) { + if(resinfo > 0x08) return(0); + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600){ + if(resinfo > 0x07) return(0); + if(resinfo == 0x04) return(0); + } + } + } + /* TW: Look backwards in table for matching CRT2 mode */ + for(; SiS_Pr->SiS_RefIndex[RefreshRateTableIndex+(*i)].ModeID == tempbx; (*i)--) { + infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + (*i)].Ext_InfoFlag; + if(infoflag & tempax) { + return(1); + } + if ((*i) == 0) break; + } + /* TW: Look through the whole mode-section of the table from the beginning + * for a matching CRT2 mode if no mode was found yet. + */ + for((*i) = 0; ; (*i)++) { + infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + (*i)].Ext_InfoFlag; + if(SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + (*i)].ModeID != tempbx) { + return(0); + } + if(infoflag & tempax) { + return(1); + } + } + return(1); +} + +/* Checked against 650/LVDS (1.10.07) and 650/301LV BIOS */ +void +SiS_SaveCRT2Info(SiS_Private *SiS_Pr, USHORT ModeNo) +{ + USHORT temp1,temp2; + + /* TW: We store CRT1 ModeNo in CR34 */ + SiS_SetReg1(SiS_Pr->SiS_P3d4,0x34,ModeNo); + temp1 = (SiS_Pr->SiS_VBInfo & SetInSlaveMode) >> 8; + temp2 = ~(SetInSlaveMode >> 8); + SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x31,temp2,temp1); +} + +/* TW: Checked against 650+301, 650/LVDS (1.10.07) and 650/301LVx (1.10.6s) BIOS */ +void +SiS_GetVBInfo(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo, + USHORT ModeIdIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension, + int checkcrt2mode) +{ + USHORT tempax,tempbx,temp; + USHORT modeflag, resinfo=0; + UCHAR OutputSelect = *SiS_Pr->pSiS_OutputSelect; + + if(SiS_Pr->UseCustomMode) { + modeflag = SiS_Pr->CModeFlag; + } else { + if (ModeNo <= 0x13) + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + else { + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; + } + } + + SiS_Pr->SiS_SetFlag = 0; + + SiS_Pr->SiS_ModeType = modeflag & ModeInfoFlag; + + tempbx = 0; + if(SiS_BridgeIsOn(SiS_Pr,BaseAddr,HwDeviceExtension) == 0) { /* TW: "== 0" inserted from 630/301B BIOS */ + temp = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x30); + /* SiS_HiVision is only used on 310/325+30xB/LV/LVX */ + if(SiS_Pr->SiS_HiVision & 0x03) { /* TW: New from 650/301LVx 1.10.6s */ + temp &= (SetCRT2ToHiVisionTV | SwitchToCRT2 | SetSimuScanMode); /* 0x83 */ + temp |= SetCRT2ToHiVisionTV; /* 0x80 */ + } + if(SiS_Pr->SiS_HiVision & 0x04) { /* TW: New from 650/301LVx 1.10.6s */ + temp &= (SetCRT2ToHiVisionTV | SwitchToCRT2 | SetSimuScanMode); /* 0x83 */ + temp |= SetCRT2ToSVIDEO; /* 0x08 */ + } + if(SiS_Pr->SiS_IF_DEF_FSTN) { /* fstn must set CR30=0x21 */ + temp = (SetCRT2ToLCD | SetSimuScanMode); + SiS_SetReg1(SiS_Pr->SiS_P3d4,0x30,temp); + } + tempbx |= temp; + tempax = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x31) << 8; + tempax &= (LoadDACFlag | DriverMode | SetDispDevSwitch | SetNotSimuMode | SetPALTV); + tempbx |= tempax; + tempbx &= ~(SetCHTVOverScan | SetInSlaveMode | DisableCRT2Display);; + +#ifdef SIS315H + + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(SiS_Pr->SiS_VBType & (VB_SIS302B | VB_SIS30xLV | VB_SIS30xNEW)) { +#if 0 /* Not in 1.10.8r */ + if(ModeNo == 3) { + SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x31,0xbf); + } +#endif +#if 0 /* Not in 1.10.8r */ + if(!(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8))) { + SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc); + } +#endif + if((tempbx & SetCRT2ToLCD) && (SiS_GetReg1(SiS_Pr->SiS_P3d4,0x30) & SetCRT2ToLCD)) { + if((SiS_GetReg1(SiS_Pr->SiS_P3d4, 0x36) & 0x0f) == SiS_Pr->SiS_Panel1400x1050) { + if((ModeNo <= 0x13) || (!(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8)))) { + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x5f) & 0xF0) { + SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x38,(EnableDualEdge | SetToLCDA)); /* 3 */ + } + } + } else { + if((ModeNo <= 0x13) || (!(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8)))) { + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x5f) & 0xF0) { + SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x38,(EnableDualEdge | SetToLCDA)); /* 3 */ + } + } + } + } + temp = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x38); + if((temp & (EnableDualEdge | SetToLCDA)) == (EnableDualEdge | SetToLCDA)) { + tempbx |= SetCRT2ToLCDA; + } + } + /* TW: Inserted from 650/LVDS 1.10.07 BIOS: */ + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { + temp = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x38); + if(temp & SetToLCDA) + tempbx |= SetCRT2ToLCDA; + if(temp & EnableLVDSHiVision) + tempbx |= SetCRT2ToHiVisionTV; + } + } + +#endif /* SIS315H */ + + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + temp = SetCRT2ToLCDA | SetCRT2ToSCART | SetCRT2ToLCD | + SetCRT2ToRAMDAC | SetCRT2ToSVIDEO | SetCRT2ToAVIDEO; /* = 0x807C; */ + if(SiS_Pr->SiS_IF_DEF_HiVision == 1) + temp |= SetCRT2ToHiVisionTV; /* = 0x80FC; */ + } else { + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) + temp = SetCRT2ToLCDA | SetCRT2ToSCART | + SetCRT2ToLCD | SetCRT2ToHiVisionTV | + SetCRT2ToAVIDEO | SetCRT2ToSVIDEO; /* = 0x80bc */ + else + temp = SetCRT2ToLCDA | SetCRT2ToLCD; + } else { + if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) + temp = SetCRT2ToTV | SetCRT2ToLCD; + else + temp = SetCRT2ToLCD; + } + } + + if(!(tempbx & temp)) { + tempax = DisableCRT2Display; + tempbx = 0; + } + + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + if(tempbx & SetCRT2ToLCDA) { + tempbx &= (0xFF00|SwitchToCRT2|SetSimuScanMode); + } + if(tempbx & SetCRT2ToRAMDAC) { + tempbx &= (0xFF00|SetCRT2ToRAMDAC|SwitchToCRT2|SetSimuScanMode); + } + if((tempbx & SetCRT2ToLCD) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) { + tempbx &= (0xFF00|SetCRT2ToLCD|SwitchToCRT2|SetSimuScanMode); + } + if(tempbx & SetCRT2ToSCART) { + tempbx &= (0xFF00|SetCRT2ToSCART|SwitchToCRT2|SetSimuScanMode); + tempbx |= SetPALTV; + } +#if 0 /* TW: Not done in 650/301LVx 1.10.6s BIOS */ + } else if(tempbx & SetCRT2ToHiVisionTV){ + tempbx &= (0xFF00|SetCRT2ToHiVisionTV|SwitchToCRT2|SetSimuScanMode); + tempbx |= SetPALTV; + } +#endif + } else { /* LVDS */ + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(tempbx & SetCRT2ToLCDA) + tempbx &= (0xFF00|SwitchToCRT2|SetSimuScanMode); + } + if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { + if(tempbx & SetCRT2ToTV) + tempbx &= (0xFF00|SetCRT2ToTV|SwitchToCRT2|SetSimuScanMode); + } + if(tempbx & SetCRT2ToLCD) { + tempbx &= (0xFF00|SetCRT2ToLCD|SwitchToCRT2|SetSimuScanMode); + } + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(tempbx & SetCRT2ToLCDA) + tempbx |= SetCRT2ToLCD; + } + } + + if(tempax & DisableCRT2Display) { + if(!(tempbx & (SwitchToCRT2 | SetSimuScanMode))) { + tempbx = SetSimuScanMode | DisableCRT2Display; + } + } + + if(!(tempbx & DriverMode)){ + tempbx |= SetSimuScanMode; + } + + /* TW: LVDS (LCD/TV) and 630+301B (LCD) can only be slave in 8bpp modes */ + if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) && (SiS_Pr->SiS_ModeType <= ModeVGA) ) { + modeflag &= (~CRT2Mode); + } + if( (HwDeviceExtension->jChipType < SIS_315H) && + (HwDeviceExtension->jChipType != SIS_300) && + (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) { + if(SiS_Pr->SiS_ModeType <= ModeVGA) { + if(tempbx & SetCRT2ToLCD) { + modeflag &= (~CRT2Mode); + } + } + } + /* TW end */ + + if(!(tempbx & SetSimuScanMode)){ + if(tempbx & SwitchToCRT2) { + if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) { + if( (HwDeviceExtension->jChipType >= SIS_315H) && + (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) ) { + if(resinfo != 0x0a) + tempbx |= SetSimuScanMode; + } else { + tempbx |= SetSimuScanMode; + } + } + } else { + if(!(SiS_BridgeIsEnable(SiS_Pr,BaseAddr,HwDeviceExtension))) { + if(!(tempbx & DriverMode)) { + if(SiS_BridgeInSlave(SiS_Pr)) { + tempbx |= SetSimuScanMode; + } + } + } + } + } + + if(!(tempbx & DisableCRT2Display)) { + if(tempbx & DriverMode) { + if(tempbx & SetSimuScanMode) { + if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) { + if( (HwDeviceExtension->jChipType >= SIS_315H) && + (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) ) { + if(resinfo != 0x0a) { /* TW: Inserted from 650/301 BIOS */ + tempbx |= SetInSlaveMode; + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + if(tempbx & SetCRT2ToTV) { + if(!(tempbx & SetNotSimuMode)) + SiS_Pr->SiS_SetFlag |= TVSimuMode; + } + } + } /* TW: Inserted from 650/301 BIOS */ + } else { + tempbx |= SetInSlaveMode; + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + if(tempbx & SetCRT2ToTV) { + if(!(tempbx & SetNotSimuMode)) + SiS_Pr->SiS_SetFlag |= TVSimuMode; + } + } + } + } + } + } else { + tempbx |= SetInSlaveMode; + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + if(tempbx & SetCRT2ToTV) { + if(!(tempbx & SetNotSimuMode)) + SiS_Pr->SiS_SetFlag |= TVSimuMode; + } + } + } + } + + if(SiS_Pr->SiS_CHOverScan) { + if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) { + temp = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x35); + if((temp & TVOverScan) || (SiS_Pr->SiS_CHOverScan == 1) ) + tempbx |= SetCHTVOverScan; + } + if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { + temp = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x79); + if( (temp & 0x80) || (SiS_Pr->SiS_CHOverScan == 1) ) + tempbx |= SetCHTVOverScan; + } + } + } + + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { +#ifdef SIS300 + if((HwDeviceExtension->jChipType==SIS_630) || + (HwDeviceExtension->jChipType==SIS_730)) { + if(ROMAddr && SiS_Pr->SiS_UseROM) { + OutputSelect = ROMAddr[0xfe]; + } + if(!(OutputSelect & EnablePALMN)) + SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x35,0x3F); + if(tempbx & SetCRT2ToTV) { + if(tempbx & SetPALTV) { + temp = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x35); + if(temp & EnablePALM) tempbx &= (~SetPALTV); + } + } + } +#endif +#ifdef SIS315H + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(ROMAddr && SiS_Pr->SiS_UseROM) { + OutputSelect = ROMAddr[0xf3]; + if(HwDeviceExtension->jChipType == SIS_330) { + OutputSelect = ROMAddr[0x11b]; + } + } + if(!(OutputSelect & EnablePALMN)) + SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0x3F); + if(tempbx & SetCRT2ToTV) { + if(tempbx & SetPALTV) { + temp = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x38); + if(temp & EnablePALM) tempbx &= (~SetPALTV); + } + } + } +#endif + } + + /* PALM/PALN on Chrontel 7019 */ + SiS_Pr->SiS_CHPALM = SiS_Pr->SiS_CHPALN = FALSE; + if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { + if(tempbx & SetCRT2ToTV) { + if(tempbx & SetPALTV) { + temp = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x38); + if(temp & EnablePALM) SiS_Pr->SiS_CHPALM = TRUE; + else if(temp & EnablePALN) SiS_Pr->SiS_CHPALN = TRUE; + } + } + } + + SiS_Pr->SiS_VBInfo = tempbx; + + if(HwDeviceExtension->jChipType == SIS_630) { + SiS_WhatIsThis(SiS_Pr, SiS_Pr->SiS_VBInfo); + } + +#ifdef TWDEBUG +#ifdef LINUX_KERNEL + printk(KERN_DEBUG "sisfb: (VBInfo= 0x%04x, SetFlag=0x%04x)\n", + SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag); +#endif +#ifdef LINUX_XF86 + xf86DrvMsgVerb(0, X_PROBED, 3, "(init301: VBInfo=0x%04x, SetFlag=0x%04x)\n", + SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag); +#endif +#endif + +#if 0 /* TW: Incomplete! (But does not seem to be required) */ + if(HwDeviceExtension->jChipType < SIS_315H) { + /* TW: From A901/630+301B BIOS */ + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + if(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x13) & 0x80) + } + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) { + if(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x13) & 0x80) + if( [si] == 3) ModeIdIndex = 0x3f2b; + } + } + SiS_SetRegAND(SiS_Pr->SiS_P3d4, 0x31, 0xF7); + if(ModeNo == 0x13) bp+4 = 0x03; + } else { + /* From 650/301LVx BIOS: */ + SiS_SetRegAND(SiS_Pr->SiS_P3d4, 0x31, 0xF7); + if(ModeNo == 0x13) bp+4 = 0x03; + else bp+4 = ModeNo; + } +#endif + + /* TW: 630/301B and 650/301 (not 301LV!) BIOSes do more here, but this seems for DOS mode */ + +} + +void +SiS_WhatIsThis(SiS_Private *SiS_Pr, USHORT myvbinfo) +{ + unsigned long eax, temp; + unsigned short temp1; + + if(!(SiS_Pr->SiS_ChSW)) return; + +#ifndef LINUX_XF86 + SiS_SetReg4(0xcf8,0x80000874); + eax = SiS_GetReg3(0xcfc); +#else + eax = pciReadLong(0x00000800, 0x74); +#endif + eax &= 0xFFFF; + temp = eax; + eax += 0x3c; + temp1 = SiS_GetReg4((USHORT)eax); + temp1 &= 0xFEFF; + SiS_SetReg5((USHORT)eax, temp1); + temp1 = SiS_GetReg4((USHORT)eax); + eax = temp; + eax += 0x3a; + temp1 = SiS_GetReg4((USHORT)eax); + temp1 &= 0xFEFF; + if(!(myvbinfo & SetCRT2ToTV)) { + temp1 |= 0x0100; + } + SiS_SetReg5((USHORT)eax, temp1); + temp1 = SiS_GetReg4((USHORT)eax); +} + +void +SiS_GetRAMDAC2DATA(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT tempax,tempbx,temp; + USHORT temp1,modeflag=0,tempcx; + USHORT StandTableIndex,CRT1Index; + USHORT ResInfo,DisplayType; + const SiS_LVDSCRT1DataStruct *LVDSCRT1Ptr = NULL; + + SiS_Pr->SiS_RVBHCMAX = 1; + SiS_Pr->SiS_RVBHCFACT = 1; + + if(ModeNo <= 0x13){ + + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + StandTableIndex = SiS_GetModePtr(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex); + tempax = SiS_Pr->SiS_StandTable[StandTableIndex].CRTC[0]; + tempbx = SiS_Pr->SiS_StandTable[StandTableIndex].CRTC[6]; + temp1 = SiS_Pr->SiS_StandTable[StandTableIndex].CRTC[7]; + + } else { + + if( (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) ) { + + temp = SiS_GetLVDSCRT1Ptr(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex, + RefreshRateTableIndex,&ResInfo,&DisplayType); + + if(temp == 0) return; + + switch(DisplayType) { + case 0 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_1; break; + case 1 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_1; break; + case 2 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_1; break; + case 3 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_1_H; break; + case 4 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_1_H; break; + case 5 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_1_H; break; + case 6 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_2; break; + case 7 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_2; break; + case 8 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_2; break; + case 9 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_2_H; break; + case 10: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_2_H; break; + case 11: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_2_H; break; + case 12: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1XXXxXXX_1; break; + case 13: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1XXXxXXX_1_H; break; + case 14: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_1; break; + case 15: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_1_H; break; + case 16: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_2; break; + case 17: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_2_H; break; + case 18: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UNTSC; break; + case 19: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1ONTSC; break; + case 20: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UPAL; break; + case 21: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1OPAL; break; + case 22: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x480_1; break; + case 23: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1; break; + case 24: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1_H; break; + case 25: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2; break; + case 26: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2_H; break; + case 27: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11152x768_1; break; + case 28: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11152x768_1_H; break; + case 29: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11152x768_2; break; + case 30: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11152x768_2_H; break; + case 36: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11600x1200_1; break; + case 37: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11600x1200_1_H; break; + case 38: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11600x1200_2; break; + case 39: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11600x1200_2_H; break; + case 99: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1OPAL; break; + default: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_1; break; + } + tempax = (LVDSCRT1Ptr+ResInfo)->CR[0]; + tempax |= (LVDSCRT1Ptr+ResInfo)->CR[14] << 8; + tempax &= 0x03FF; + tempbx = (LVDSCRT1Ptr+ResInfo)->CR[6]; + tempcx = (LVDSCRT1Ptr+ResInfo)->CR[13] << 8; + tempcx &= 0x0100; + tempcx <<= 2; + tempbx |= tempcx; + temp1 = (LVDSCRT1Ptr+ResInfo)->CR[7]; + + } else { + + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + CRT1Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC; +#if 0 /* Not any longer */ + if(HwDeviceExtension->jChipType < SIS_315H) CRT1Index &= 0x3F; +#endif + tempax = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[0]; + tempax |= SiS_Pr->SiS_CRT1Table[CRT1Index].CR[14] << 8; + tempax &= 0x03FF; + tempbx = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[6]; + tempcx = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[13] << 8; + tempcx &= 0x0100; + tempcx <<= 2; + tempbx |= tempcx; + temp1 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[7]; + + } + + } + + if(temp1 & 0x01) tempbx |= 0x0100; + if(temp1 & 0x20) tempbx |= 0x0200; + + tempax += 5; + + /* Charx8Dot is no more used (and assumed), so we set it */ + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + modeflag |= Charx8Dot; + } + + if(modeflag & Charx8Dot) tempax *= 8; + else tempax *= 9; + + /* TW: From 650/301LVx 1.10.6s */ + if(modeflag & HalfDCLK) tempax <<= 1; + + SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax; + tempbx++; + SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = tempbx; +} + +void +SiS_UnLockCRT2(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr) +{ + if(HwDeviceExtension->jChipType >= SIS_315H) + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2f,0x01); + else + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24,0x01); +} + +void +SiS_LockCRT2(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr) +{ + if(HwDeviceExtension->jChipType >= SIS_315H) + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2F,0xFE); + else + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x24,0xFE); +} + +void +SiS_EnableCRT2(SiS_Private *SiS_Pr) +{ + SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); +} + +/* Checked against all BIOSes */ +void +SiS_DisableBridge(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr) +{ +#ifdef SIS315H + USHORT tempah,pushax=0; +#endif + USHORT temp=0; + UCHAR *ROMAddr = HwDeviceExtension->pjVirtualRomBase; + + if (SiS_Pr->SiS_IF_DEF_LVDS == 0) { + + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { /* ===== TW: For 30xB/LV ===== */ + + if(HwDeviceExtension->jChipType < SIS_315H) { + +#ifdef SIS300 /* 300 series */ + + if(HwDeviceExtension->jChipType == SIS_300) { /* New for 300+301LV */ + + if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwDeviceExtension))) { + SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xFE,0x00); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + } + if(SiS_Is301B(SiS_Pr,BaseAddr)) { + SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0x3f); + SiS_ShortDelay(SiS_Pr,1); + } + SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF); + SiS_DisplayOff(SiS_Pr); + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); + if( (!(SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension))) || + (!(SiS_CR36BIOSWord23d(SiS_Pr,HwDeviceExtension))) ) { + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 2); + SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,0xFB,0x04); + } + + } else { + + if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwDeviceExtension))) { + SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,0xF7,0x08); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + } + if(SiS_Is301B(SiS_Pr,BaseAddr)) { + SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0x3f); + SiS_ShortDelay(SiS_Pr,1); + } + SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF); + SiS_DisplayOff(SiS_Pr); + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); + SiS_UnLockCRT2(SiS_Pr,HwDeviceExtension,BaseAddr); + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80); + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40); + if( (!(SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension))) || + (!(SiS_CR36BIOSWord23d(SiS_Pr,HwDeviceExtension))) ) { + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 2); + SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,0xFB,0x04); + } + } + +#endif /* SIS300 */ + + } else { + +#ifdef SIS315H /* 310/325 series */ + + if(IS_SIS650740) { /* 650, 740 */ + +#if 0 + if(SiS_GetReg1(SiS_Pr->SiS_Part4Port,0x00) != 1) return; /* From 1.10.7w */ +#endif + + if(SiS_Pr->SiS_VBType & (VB_SIS30xLV|VB_SIS30xNEW)) { + + if(!(SiS_IsM650or651(SiS_Pr,HwDeviceExtension, BaseAddr))) { + tempah = 0xef; + if(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr)) { + tempah = 0xf7; + } + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,tempah); + } + + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x30,0x00); + + if(!(SiS_IsDualEdge(SiS_Pr,HwDeviceExtension, BaseAddr))) { + SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xFE,0x00); + } else if(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr)) { + SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xFE,0x00); + } + + SiS_SetReg3(SiS_Pr->SiS_P3c6,0x00); + + pushax = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x06); + + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + + } + + if(SiS_Pr->SiS_VBType & (VB_SIS301B|VB_SIS302B)) { + tempah = 0x3f; + if(SiS_IsDualEdge(SiS_Pr,HwDeviceExtension, BaseAddr)) { + tempah = 0x7f; + if(!(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr))) { + tempah = 0xbf; + } + } + SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,tempah); + } + + if(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr)) { + + if(SiS_Pr->SiS_VBType & (VB_SIS301B|VB_SIS302B)) { + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1E,0xDF); + SiS_DisplayOff(SiS_Pr); + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); + } else { + SiS_DisplayOff(SiS_Pr); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 2); + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1E,0xDF); + } + + } else { + + if(SiS_Pr->SiS_VBType & (VB_SIS301B|VB_SIS302B)) { + if(!(SiS_IsDualEdge(SiS_Pr,HwDeviceExtension, BaseAddr))) { + SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xdf); + SiS_DisplayOff(SiS_Pr); + } + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80); + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); + temp = SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x00); + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10); + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x00,temp); + } else { + SiS_DisplayOff(SiS_Pr); + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 2); + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); + temp = SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x00); + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10); + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x00,temp); + } + + } + + if(SiS_Pr->SiS_VBType & (VB_SIS30xLV|VB_SIS30xNEW)) { + + tempah = 0x3f; + if(SiS_IsDualEdge(SiS_Pr,HwDeviceExtension, BaseAddr)) { + tempah = 0x7f; + if(!(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr))) { + tempah = 0xbf; + } + } + SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,tempah); + + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f); + + if(!(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr))) { + SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xdf); + } + + if(!(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr))) { + if(!(SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension))) { + if(!(SiS_IsDualEdge(SiS_Pr,HwDeviceExtension, BaseAddr))) { + SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xFD,0x00); + } + } + } + + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x06,pushax); + + } + + + } else { /* 315, 330 */ + + if(SiS_Is301B(SiS_Pr,BaseAddr)) { + tempah = 0x3f; + if(SiS_IsDualEdge(SiS_Pr,HwDeviceExtension, BaseAddr)) { + tempah = 0x7f; + if(!(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr))) { + tempah = 0xbf; + } + } + SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,tempah); + if(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr)) { + SiS_DisplayOff(SiS_Pr); + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); + } + } + if( (!(SiS_Is301B(SiS_Pr,BaseAddr))) || + (!(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr))) ) { + + if( (!(SiS_Is301B(SiS_Pr,BaseAddr))) || + (!(SiS_IsDualEdge(SiS_Pr,HwDeviceExtension, BaseAddr))) ) { + + SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF); + SiS_DisplayOff(SiS_Pr); + + } + + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80); + + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); + + temp = SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x00); + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10); + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x00,temp); + + } + + } /* 315/330 */ + +#endif /* SIS315H */ + + } + + } else { /* ============ TW: For 301 ================ */ + + if(HwDeviceExtension->jChipType < SIS_315H) { + if(SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension)) { + SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,0xF0,0x0B); + SiS_SetPanelDelay(SiS_Pr, ROMAddr, HwDeviceExtension, 1); + } + } + + SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF); /* disable VB */ + SiS_DisplayOff(SiS_Pr); + + if(HwDeviceExtension->jChipType >= SIS_315H) { + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80); + } + + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); /* disable lock mode */ + + if(HwDeviceExtension->jChipType >= SIS_315H) { + temp = SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x00); + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10); + SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x00,temp); + } else { + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); /* disable CRT2 */ + } + + } + + } else { /* ============ TW: For LVDS =============*/ + + if(HwDeviceExtension->jChipType < SIS_315H) { + +#ifdef SIS300 /* 300 series */ + + if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) { + SiS_SetCH700x(SiS_Pr,0x090E); + } + + if(HwDeviceExtension->jChipType == SIS_730) { + if(!(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x11) & 0x08)) { + SiS_WaitVBRetrace(SiS_Pr,HwDeviceExtension); + } + if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwDeviceExtension))) { + SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,0xF7,0x08); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + } + } else { + if(!(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x11) & 0x08)) { + + if(!(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x13) & 0x40)) { + + if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwDeviceExtension))) { + + SiS_WaitVBRetrace(SiS_Pr,HwDeviceExtension); + + if(!(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x06) & 0x1c)) { + SiS_DisplayOff(SiS_Pr); + } + + SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,0xF7,0x08); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + } + } + } + } + + SiS_DisplayOff(SiS_Pr); + + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); + + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); + SiS_UnLockCRT2(SiS_Pr,HwDeviceExtension,BaseAddr); + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80); + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40); + + if( (!(SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension))) || + (!(SiS_CR36BIOSWord23d(SiS_Pr,HwDeviceExtension))) ) { + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 2); + SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,0xFB,0x04); + } + +#endif /* SIS300 */ + + } else { + +#ifdef SIS315H /* 310/325 series */ + + if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { + if(!(SiS_IsDualEdge(SiS_Pr,HwDeviceExtension, BaseAddr))) { + SiS_Chrontel701xBLOff(SiS_Pr); + SiS_Chrontel701xOff(SiS_Pr); + } else if(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr)) { + SiS_Chrontel701xBLOff(SiS_Pr); + SiS_Chrontel701xOff(SiS_Pr); + } + + if(!(SiS_IsDualEdge(SiS_Pr,HwDeviceExtension, BaseAddr))) { + SiS_SetCH701x(SiS_Pr,0x0149); + } else if(SiS_IsTVOrYPbPrOrScart(SiS_Pr,HwDeviceExtension, BaseAddr)) { + SiS_SetCH701x(SiS_Pr,0x0149); + } + } + + if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { + SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,0xF7,0x08); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + } + + if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { + SiS_DisplayOff(SiS_Pr); + } else if(!(SiS_IsDualEdge(SiS_Pr,HwDeviceExtension, BaseAddr))) { + SiS_DisplayOff(SiS_Pr); + } else if(!(SiS_IsTVOrYPbPrOrScart(SiS_Pr,HwDeviceExtension, BaseAddr))) { + SiS_DisplayOff(SiS_Pr); + } + + if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80); + } else if(!(SiS_IsDualEdge(SiS_Pr,HwDeviceExtension, BaseAddr))) { + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80); + } else if(!(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr))) { + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80); + } + + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); + + if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); + } else if(!(SiS_IsDualEdge(SiS_Pr,HwDeviceExtension, BaseAddr))) { + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); + } else if(!(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr))) { + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); + } + + if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { + if(SiS_CRT2IsLCD(SiS_Pr, BaseAddr,HwDeviceExtension)) { + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf); + } + } else if(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr)) { + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf); + } + + if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { + if(SiS_IsDualEdge(SiS_Pr,HwDeviceExtension, BaseAddr)) { + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xff); + } else { + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb); + } + } + + SiS_UnLockCRT2(SiS_Pr,HwDeviceExtension, BaseAddr); + + if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7); + } else if(!(SiS_IsDualEdge(SiS_Pr,HwDeviceExtension, BaseAddr))) { + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7); + } else if(!(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr))) { + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7); + } + +#if 0 /* TW: BIOS code makes no sense */ + if(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr)) { + if(!(SiS_IsDualEdge(SiS_Pr,HwDeviceExtension, BaseAddr))) { + if(SiS_WeHaveBacklightCtrl(SiS_Pr,HwDeviceExtension, BaseAddr)) { + /* Nothing there! */ + } + } + } +#endif + if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { + if(SiS_CRT2IsLCD(SiS_Pr, BaseAddr,HwDeviceExtension)) { + if(SiS_WeHaveBacklightCtrl(SiS_Pr,HwDeviceExtension, BaseAddr)) { + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 2); + SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,0xFB,0x04); + } + } + } + +#endif /* SIS315H */ + + } /* 310 series */ + + } /* LVDS */ + +} + +/* TW: Checked against all BIOSes */ +void +SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr) +{ + USHORT temp=0,tempah; +#ifdef SIS315H + USHORT temp1,pushax=0; + BOOLEAN delaylong = FALSE; +#endif + UCHAR *ROMAddr = HwDeviceExtension->pjVirtualRomBase; + + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { /* TW: ====== For 301B et al ====== */ + + if(HwDeviceExtension->jChipType < SIS_315H) { + +#ifdef SIS300 /* 300 series */ + + if(HwDeviceExtension->jChipType == SIS_300) { + + if(SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension)) { + SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02); + if(!(SiS_CR36BIOSWord23d(SiS_Pr,HwDeviceExtension))) { + SiS_SetPanelDelay(SiS_Pr, ROMAddr, HwDeviceExtension, 0); + } + } + temp = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */ + if(SiS_BridgeInSlave(SiS_Pr)) { + tempah = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x30); + if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20; + } + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x32,temp); + SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */ + if(SiS_Is301B(SiS_Pr,BaseAddr)) { + SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,0xC0); + SiS_DisplayOn(SiS_Pr); + } else { + SiS_VBLongWait(SiS_Pr); + SiS_DisplayOn(SiS_Pr); + SiS_VBLongWait(SiS_Pr); + } + if(SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension)) { + if(!(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x13) & 0x40)) { + if(!(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x16) & 0x10)) { + if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwDeviceExtension))) { + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 1); + } + SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xfe,0x01); + } + } + } + + } else { + + if(SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension)) { + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x11,0xFB); + if(!(SiS_CR36BIOSWord23d(SiS_Pr,HwDeviceExtension))) { + SiS_SetPanelDelay(SiS_Pr, ROMAddr, HwDeviceExtension, 0); + } + SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* Enable CRT2 */ +/* DoSomeThingPCI_On(SiS_Pr) */ + SiS_DisplayOn(SiS_Pr); + SiS_UnLockCRT2(SiS_Pr,HwDeviceExtension, BaseAddr); + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF); + if(SiS_BridgeInSlave(SiS_Pr)) { + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F); + } else { + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40); + } + if(!(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x13) & 0x40)) { + if(!(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x16) & 0x10)) { + if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwDeviceExtension))) { + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 1); + } + SiS_WaitVBRetrace(SiS_Pr,HwDeviceExtension); + SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,0xF7,0x00); + } + } + } else { + temp = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */ + if(SiS_BridgeInSlave(SiS_Pr)) { + tempah = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x30); + if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20; + } + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x32,temp); + SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */ + if(SiS_Is301B(SiS_Pr,BaseAddr)) { + SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,0xC0); + SiS_DisplayOn(SiS_Pr); + } else { + SiS_VBLongWait(SiS_Pr); + SiS_DisplayOn(SiS_Pr); + SiS_VBLongWait(SiS_Pr); + } + } + + } +#endif /* SIS300 */ + + } else { + +#ifdef SIS315H /* 310/325 series */ + + if(IS_SIS650740) { /* 650, 740 */ + +#if 0 + if(SiS_GetReg1(SiS_Pr->SiS_Part4Port,0x00) != 1) return; /* From 1.10.7w */ +#endif + + if(SiS_Pr->SiS_VBType & (VB_SIS30xLV|VB_SIS30xNEW)) { + + if(!(SiS_IsM650or651(SiS_Pr,HwDeviceExtension, BaseAddr))) { + tempah = 0x10; + if(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr)) { + tempah = 0x08; + } + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x4c,tempah); + } + + SiS_SetReg3(SiS_Pr->SiS_P3c6,0x00); + + SiS_DisplayOff(SiS_Pr); + + pushax = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x06); + + if( (SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr)) || + (SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension)) ) { + if(!(SiS_GetReg1(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) { + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02); + } + } + + if(!(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x31) & 0x40)) { + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + delaylong = TRUE; + } + + } + + if(!(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr))) { + temp = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x32) & 0xDF; + if(SiS_BridgeInSlave(SiS_Pr)) { + tempah = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x30); + if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20; + } + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x32,temp); + + SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */ + if(SiS_Pr->SiS_VBType & (VB_SIS301B|VB_SIS302B)) { + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f); + temp = SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x2e); + if(!(temp & 0x80)) { + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80); + } + } else { + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 2); + } + } + + if(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr)) { + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x20); + } + + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1f,0x20); + + if(SiS_Pr->SiS_VBType & (VB_SIS301B|VB_SIS302B)) { + temp = SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x2e); + if(!(temp & 0x80)) { + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80); + } + } + + tempah = 0xc0; + if(SiS_IsDualEdge(SiS_Pr,HwDeviceExtension, BaseAddr)) { + tempah = 0x80; + if(!(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr))) { + tempah = 0x40; + } + } + SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,tempah); + + if(SiS_Pr->SiS_VBType & (VB_SIS301B|VB_SIS302B)) { + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f); + } + + if(SiS_Pr->SiS_VBType & (VB_SIS30xLV|VB_SIS30xNEW)) { + + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80); + + if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwDeviceExtension, BaseAddr))) { + if( (SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr)) || + ((SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension))) ) { + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + if(delaylong) { + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 3); + } + SiS_WaitVBRetrace(SiS_Pr,HwDeviceExtension); + SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xfe,0x01); + } + } + + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x06,pushax); + SiS_DisplayOn(SiS_Pr); + SiS_SetReg3(SiS_Pr->SiS_P3c6,0xff); + + if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwDeviceExtension, BaseAddr))) { + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f); + } + + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x30,0x00); + SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x0c); + SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x31,0x05); + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x32,0x60); + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x33,0x00); + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x34,0x10); + SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x40); + + } + + + } else { /* 315, 330 */ + + if(!(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr))) { + temp = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x32) & 0xDF; + if(SiS_BridgeInSlave(SiS_Pr)) { + tempah = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x30); + if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20; + } + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x32,temp); + + SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */ + + temp=SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x2E); + if (!(temp & 0x80)) + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80); + } + + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1f,0x20); + + if(SiS_Is301B(SiS_Pr,BaseAddr)) { + + temp=SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x2E); + if (!(temp & 0x80)) + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80); + + tempah = 0xc0; + if(SiS_IsDualEdge(SiS_Pr,HwDeviceExtension, BaseAddr)) { + tempah = 0x80; + if(!(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr))) { + tempah = 0x40; + } + } + SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,tempah); + + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f); + + } else { + + SiS_VBLongWait(SiS_Pr); + SiS_DisplayOn(SiS_Pr); + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7F); + SiS_VBLongWait(SiS_Pr); + + } + + } /* 315, 330 */ + +#endif /* SIS315H */ + + } + + } else { /* ============ TW: For 301 ================ */ + + if(HwDeviceExtension->jChipType < SIS_315H) { + if(SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension)) { + SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,0xF0,0x0B); + SiS_SetPanelDelay(SiS_Pr, ROMAddr, HwDeviceExtension, 0); + } + } + + temp = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */ + if(SiS_BridgeInSlave(SiS_Pr)) { + tempah = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x30); + if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20; + } + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x32,temp); + + SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */ + + if(HwDeviceExtension->jChipType >= SIS_315H) { + temp = SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x2E); + if(!(temp & 0x80)) + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80); /* BVBDOENABLE=1 */ + } + + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */ + + SiS_VBLongWait(SiS_Pr); + SiS_DisplayOn(SiS_Pr); + if(HwDeviceExtension->jChipType >= SIS_315H) { + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f); + } + SiS_VBLongWait(SiS_Pr); + + if(HwDeviceExtension->jChipType < SIS_315H) { + if(SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension)) { + SiS_SetPanelDelay(SiS_Pr, ROMAddr, HwDeviceExtension, 1); + SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,0xF0,0x03); + } + } + + } + + } else { /* =================== TW: For LVDS ================== */ + + if(HwDeviceExtension->jChipType < SIS_315H) { + +#ifdef SIS300 /* 300 series */ + + if(SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension)) { + if(HwDeviceExtension->jChipType == SIS_730) { + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 1); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 1); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 1); + } + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x11,0xFB); + if(!(SiS_CR36BIOSWord23d(SiS_Pr,HwDeviceExtension))) { + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 0); + } + } + + SiS_EnableCRT2(SiS_Pr); + SiS_DisplayOn(SiS_Pr); + SiS_UnLockCRT2(SiS_Pr,HwDeviceExtension, BaseAddr); + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF); + if(SiS_BridgeInSlave(SiS_Pr)) { + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F); + } else { + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40); + } + + if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) { + if(!(SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension))) { + SiS_SetCH700x(SiS_Pr,0x0B0E); + } + } + + if(SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension)) { + if(!(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x13) & 0x40)) { + if(!(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x16) & 0x10)) { + if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwDeviceExtension))) { + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 1); + SiS_SetPanelDelay(SiS_Pr,ROMAddr, HwDeviceExtension, 1); + } + SiS_WaitVBRetrace(SiS_Pr,HwDeviceExtension); + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x11,0xF7); + } + } + } + +#endif /* SIS300 */ + + } else { + +#ifdef SIS315H /* 310/325 series */ + +#if 0 /* BIOS code makes no sense */ + if(SiS_IsVAMode()) { + if(SiS_IsLCDOrLCDA()) { + } + } +#endif + + if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { + if(SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension)) { + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x11,0xFB); + SiS_SetPanelDelay(SiS_Pr, ROMAddr, HwDeviceExtension, 0); + } + } + + SiS_EnableCRT2(SiS_Pr); + SiS_UnLockCRT2(SiS_Pr,HwDeviceExtension, BaseAddr); + + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7); + + if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { + temp = SiS_GetCH701x(SiS_Pr,0x66); + temp &= 0x20; + SiS_Chrontel701xBLOff(SiS_Pr); + } + + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f); + + temp1 = SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x2E); + if (!(temp1 & 0x80)) + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80); + + if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { + if(temp) { + SiS_Chrontel701xBLOn(SiS_Pr); + } + } + + if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { + if(SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension)) { + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20); + } + } else if(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr)) { + SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20); + } + + if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwDeviceExtension, BaseAddr))) { + SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f); + } + + if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { + + if(SiS_IsTVOrYPbPrOrScart(SiS_Pr,HwDeviceExtension, BaseAddr)) { + SiS_Chrontel701xOn(SiS_Pr,HwDeviceExtension, BaseAddr); + } + + if(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr)) { + SiS_ChrontelDoSomething1(SiS_Pr,HwDeviceExtension, BaseAddr); + } else if(SiS_IsLCDOrLCDA(SiS_Pr,HwDeviceExtension, BaseAddr)) { + SiS_ChrontelDoSomething1(SiS_Pr,HwDeviceExtension, BaseAddr); + } + + } + + if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { + if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwDeviceExtension, BaseAddr))) { + if(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr)) { + SiS_Chrontel701xBLOn(SiS_Pr); + SiS_ChrontelDoSomething4(SiS_Pr,HwDeviceExtension, BaseAddr); + } else if(SiS_IsLCDOrLCDA(SiS_Pr,HwDeviceExtension, BaseAddr)) { +/* if(!SiS_WeHaveBacklightCtrl(SiS_Pr,HwDeviceExtension, BaseAddr)) { */ /* TW: makes no sense */ + SiS_Chrontel701xBLOn(SiS_Pr); + SiS_ChrontelDoSomething4(SiS_Pr,HwDeviceExtension, BaseAddr); +/* } */ + } + } + } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { + if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwDeviceExtension, BaseAddr))) { + if(SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension)) { + SiS_SetPanelDelay(SiS_Pr, ROMAddr, HwDeviceExtension, 1); + SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x11,0xF7); + } + } + } + +#endif /* SIS315H */ + + } /* 310 series */ + + } /* LVDS */ + +} + +void +SiS_SiS30xBLOn(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT BaseAddr = (USHORT)HwDeviceExtension->ulIOAddress; + + /* TW: Switch on LCD backlight on SiS30xLV */ + if( (SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr)) || + (SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension)) ) { + if(!(SiS_GetReg1(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) { + SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02); + SiS_WaitVBRetrace(SiS_Pr,HwDeviceExtension); + } + if(!(SiS_GetReg1(SiS_Pr->SiS_Part4Port,0x26) & 0x01)) { + SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01); + } + } +} + +void +SiS_SiS30xBLOff(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT BaseAddr = (USHORT)HwDeviceExtension->ulIOAddress; + + /* TW: Switch off LCD backlight on SiS30xLV */ + if( (!(SiS_IsDualEdge(SiS_Pr,HwDeviceExtension, BaseAddr))) || + (SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr)) ) { + SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xFE,0x00); + } + + if(!(SiS_IsVAMode(SiS_Pr,HwDeviceExtension, BaseAddr))) { + if(!(SiS_CRT2IsLCD(SiS_Pr,BaseAddr,HwDeviceExtension))) { + if(!(SiS_IsDualEdge(SiS_Pr,HwDeviceExtension, BaseAddr))) { + SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xFD,0x00); + } + } + } +} + +BOOLEAN +SiS_CR36BIOSWord23b(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT temp,temp1; + UCHAR *ROMAddr; + + if((ROMAddr = (UCHAR *)HwDeviceExtension->pjVirtualRomBase) && SiS_Pr->SiS_UseROM) { + temp = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x36) & 0xff; + temp >>= 4; + temp = 1 << temp; + temp1 = (ROMAddr[0x23c] << 8) | ROMAddr[0x23b]; + if(temp1 & temp) return(1); + else return(0); + } else { + return(0); + } +} + +BOOLEAN +SiS_CR36BIOSWord23d(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT temp,temp1; + UCHAR *ROMAddr; + + if((ROMAddr = (UCHAR *)HwDeviceExtension->pjVirtualRomBase) && SiS_Pr->SiS_UseROM) { + temp = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x36) & 0xff; + temp >>= 4; + temp = 1 << temp; + temp1 = (ROMAddr[0x23e] << 8) | ROMAddr[0x23d]; + if(temp1 & temp) return(1); + else return(0); + } else { + return(0); + } +} + +void +SiS_SetPanelDelay(SiS_Private *SiS_Pr, UCHAR *ROMAddr, PSIS_HW_DEVICE_INFO HwDeviceExtension, + USHORT DelayTime) +{ + USHORT PanelID, DelayIndex, Delay; +#ifdef SIS300 + USHORT temp; +#endif + + if(HwDeviceExtension->jChipType < SIS_315H) { + +#ifdef SIS300 + + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { /* 300 series, LVDS */ + + PanelID = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x36); + + DelayIndex = PanelID >> 4; + + if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) { + Delay = 3; + } else { + if(DelayTime >= 2) DelayTime -= 2; + + if(!(DelayTime & 0x01)) { + Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0]; + } else { + Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1]; + } + if((ROMAddr) && (SiS_Pr->SiS_UseROM)) { + if(ROMAddr[0x220] & 0x40) { + if(!(DelayTime & 0x01)) { + Delay = (USHORT)ROMAddr[0x225]; + } else { + Delay = (USHORT)ROMAddr[0x226]; + } + } + } + } + SiS_ShortDelay(SiS_Pr,Delay); + + } else { /* 300 series, 301(B) */ + + PanelID = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x36); + temp = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x18); + if(!(temp & 0x10)) PanelID = 0x12; + + DelayIndex = PanelID >> 4; + + if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) { + Delay = 3; + } else { + if(DelayTime >= 2) DelayTime -= 2; + + if(!(DelayTime & 0x01)) { + Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0]; + } else { + Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1]; + } + if((ROMAddr) && (SiS_Pr->SiS_UseROM)) { + if(ROMAddr[0x220] & 0x40) { + if(!(DelayTime & 0x01)) { + Delay = (USHORT)ROMAddr[0x225]; + } else { + Delay = (USHORT)ROMAddr[0x226]; + } + } + } + } + SiS_ShortDelay(SiS_Pr,Delay); + + } + +#endif /* SIS300 */ + + } else { + + if(HwDeviceExtension->jChipType == SIS_330) return; + +#ifdef SIS315H + + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { /* 310/325 series, LVDS */ + + if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { + PanelID = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x36); + DelayIndex = PanelID >> 4; + if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) { + Delay = 3; + } else { + if(DelayTime >= 2) DelayTime -= 2; + + if(!(DelayTime & 0x01)) { + Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[0]; + } else { + Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[1]; + } + if((ROMAddr) && (SiS_Pr->SiS_UseROM)) { + if(ROMAddr[0x13c] & 0x40) { + if(!(DelayTime & 0x01)) { + Delay = (USHORT)ROMAddr[0x17e]; + } else { + Delay = (USHORT)ROMAddr[0x17f]; + } + } + } + } + SiS_ShortDelay(SiS_Pr,Delay); + } + + } else { /* 310/325 series, 301(B) */ + + PanelID = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x36); + DelayIndex = PanelID >> 4; + if(!(DelayTime & 0x01)) { + Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0]; + } else { + Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1]; + } + SiS_DDC2Delay(SiS_Pr, Delay * 4); + + } + +#endif /* SIS315H */ + + } + +} + +void +SiS_LongDelay(SiS_Private *SiS_Pr, USHORT delay) +{ + while(delay--) { + SiS_GenericDelay(SiS_Pr,0x19df); + } +} + +void +SiS_ShortDelay(SiS_Private *SiS_Pr, USHORT delay) +{ + while(delay--) { + SiS_GenericDelay(SiS_Pr,0x42); + } +} + +void +SiS_GenericDelay(SiS_Private *SiS_Pr, USHORT delay) +{ + USHORT temp,flag; + + flag = SiS_GetReg3(0x61) & 0x10; + + while(delay) { + temp = SiS_GetReg3(0x61) & 0x10; + if(temp == flag) continue; + flag = temp; + delay--; + } +} + +BOOLEAN +SiS_Is301B(SiS_Private *SiS_Pr, USHORT BaseAddr) +{ + USHORT flag; + + flag = SiS_GetReg1(SiS_Pr->SiS_Part4Port,0x01); + if(flag >= 0x0B0) return(1); + else return(0); +} + +BOOLEAN +SiS_CRT2IsLCD(SiS_Private *SiS_Pr, USHORT BaseAddr, PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT flag; + + if(HwDeviceExtension->jChipType == SIS_730) { + flag = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x13); + if(flag & 0x20) return(1); + } + flag = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x30); + if(flag & 0x20) return(1); + else return(0); +} + +BOOLEAN +SiS_IsDualEdge(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr) +{ +#ifdef SIS315H + USHORT flag; + + if(HwDeviceExtension->jChipType >= SIS_315H) { + if((HwDeviceExtension->jChipType != SIS_650) || (SiS_GetReg1(SiS_Pr->SiS_P3d4,0x5f) & 0xf0)) { + flag = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x38); + if(flag & EnableDualEdge) return(1); + else return(0); + } else return(0); + } else +#endif + return(0); +} + +BOOLEAN +SiS_IsVAMode(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr) +{ +#ifdef SIS315H + USHORT flag; + + if(HwDeviceExtension->jChipType >= SIS_315H) { + flag = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x38); + if((flag & EnableDualEdge) && (flag & SetToLCDA)) return(1); +#if 0 /* Not done in 650/301LVx 1.10.6s, but in 650/301LV */ + else if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + if(flag) return(1); + else return(0); + } +#endif + else + return(0); + } else +#endif + return(0); + } + +BOOLEAN +SiS_WeHaveBacklightCtrl(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr) +{ +#ifdef SIS315H + USHORT flag; + + if(HwDeviceExtension->jChipType >= SIS_315H) { + flag = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x79); + if(flag & 0x10) return(1); + else return(0); + } else +#endif + return(0); + } + +#if 0 +BOOLEAN +SiS_Is315E(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr) +{ +#ifdef SIS315H + USHORT flag; + + if(HwDeviceExtension->jChipType >= SIS_315H) { + flag = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x5f); + if(flag & 0x10) return(1); + else return(0); + } else +#endif + return(0); +} +#endif + +BOOLEAN +SiS_IsM650or651(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr) +{ +#ifdef SIS315H + USHORT flag; + + if(HwDeviceExtension->jChipType >= SIS_315H) { + flag = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x5f); + flag &= 0xF0; + if((flag == 0xb0) || (flag == 0x90)) return 0; + else return 1; + } else +#endif + return 1; +} + +BOOLEAN +SiS_IsYPbPr(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr) +{ +#ifdef SIS315H + USHORT flag; + + if(HwDeviceExtension->jChipType >= SIS_315H) { + flag = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x38); + if(flag & EnableLVDSHiVision) return(1); /* = YPrPb = 0x08 */ + else return(0); + } else +#endif + return(0); +} + +BOOLEAN +SiS_IsChScart(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr) +{ +#ifdef SIS315H + USHORT flag; + + if(HwDeviceExtension->jChipType >= SIS_315H) { + flag = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x38); + if(flag & EnableLVDSScart) return(1); /* = Scart = 0x04 */ + else return(0); + } else +#endif + return(0); +} + +BOOLEAN +SiS_IsTVOrYPbPrOrScart(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr) +{ + USHORT flag; + +#ifdef SIS315H + if(HwDeviceExtension->jChipType >= SIS_315H) { + flag = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x30); + if(flag & SetCRT2ToTV) return(1); + flag = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x38); + if(flag & EnableLVDSHiVision) return(1); /* = YPrPb = 0x08 */ + if(flag & EnableLVDSScart) return(1); /* = Scart = 0x04- TW inserted */ + else return(0); + } else +#endif + { + flag = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x30); + if(flag & SetCRT2ToTV) return(1); + } + return(0); +} + +BOOLEAN +SiS_IsLCDOrLCDA(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr) +{ + USHORT flag; + +#ifdef SIS315H + if(HwDeviceExtension->jChipType >= SIS_315H) { + flag = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x30); + if(flag & SetCRT2ToLCD) return(1); + flag = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x38); + if(flag & SetToLCDA) return(1); + else return(0); + } else +#endif + { + flag = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x30); + if(flag & SetCRT2ToLCD) return(1); + } + return(0); + +} + +BOOLEAN +SiS_IsDisableCRT2(SiS_Private *SiS_Pr, USHORT BaseAddr) +{ + USHORT flag; + + flag = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x30); + if(flag & 0x20) return(0); + else return(1); +} + +BOOLEAN +SiS_BridgeIsOn(SiS_Private *SiS_Pr, USHORT BaseAddr,PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT flag; + + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { + return(0); + } else { + flag = SiS_GetReg1(SiS_Pr->SiS_Part4Port,0x00); + if((flag == 1) || (flag == 2)) return(0); + else return(1); + } +} + +BOOLEAN +SiS_BridgeIsEnable(SiS_Private *SiS_Pr, USHORT BaseAddr,PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT flag; + + if(!(SiS_BridgeIsOn(SiS_Pr,BaseAddr,HwDeviceExtension))) { + flag = SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x00); + if(HwDeviceExtension->jChipType < SIS_315H) { + /* 300 series (630/301B 2.04.5a) */ + flag &= 0xa0; + if((flag == 0x80) || (flag == 0x20)) return 0; + else return 1; + } else { + /* 310/325 series (650/301LVx 1.10.6s) */ + flag &= 0x50; + if((flag == 0x40) || (flag == 0x10)) return 0; + else return 1; + } + } + return 1; +} + +BOOLEAN +SiS_BridgeInSlave(SiS_Private *SiS_Pr) +{ + USHORT flag1; + + flag1 = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x31); + if(flag1 & (SetInSlaveMode >> 8)) return 1; + else return 0; +} + +/* TW: New from 650/301LV(x) 1.10.6s BIOS */ +void +SiS_SetHiVision(SiS_Private *SiS_Pr, USHORT BaseAddr,PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ +#ifdef SIS315H + USHORT temp; +#endif + + /* Note: This variable is only used on 30x/B/LV systems. + CR38 has a different meaning on LVDS/CH7019 systems. + */ + + SiS_Pr->SiS_HiVision = 0; + if(HwDeviceExtension->jChipType >= SIS_315H) { +#ifdef SIS315H + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + /* TW: New from 650/301LVx BIOS 1.10.6s */ + temp = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x38); + if(temp & 0x04) { + temp &= 0x30; + switch(temp) { + case 0x00: SiS_Pr->SiS_HiVision = 4; break; + case 0x10: SiS_Pr->SiS_HiVision = 1; break; + case 0x20: SiS_Pr->SiS_HiVision = 2; break; + default: SiS_Pr->SiS_HiVision = 3; break; + } + } + } +#endif /* SIS315H */ + } +} + +/* TW: Checked against 630/LVDS 2.08, 650/LVDS and 650/301LV BIOS */ +BOOLEAN +SiS_GetLCDResInfo(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo, + USHORT ModeIdIndex, PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT temp,modeflag,resinfo=0; + const unsigned char SiS300SeriesLCDRes[] = + { 0, 1, 2, 3, 7, 4, 5, 8, + 0, 0, 0, 0, 0, 0, 0, 0 }; + + SiS_Pr->SiS_LCDResInfo = 0; + SiS_Pr->SiS_LCDTypeInfo = 0; + SiS_Pr->SiS_LCDInfo = 0; + + if(SiS_Pr->UseCustomMode) { + modeflag = SiS_Pr->CModeFlag; + } else { + if(ModeNo <= 0x13) { + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + } else { + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; + } + } + + if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))) return 0; + + if(!(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchToCRT2))) return 0; + + temp = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x36); + + /* FSTN: Fake CR36 (TypeInfo 2, ResInfo SiS_Panel320x480) */ + if(SiS_Pr->SiS_IF_DEF_FSTN) { + temp = 0x20 | SiS_Pr->SiS_Panel320x480; + SiS_SetReg1(SiS_Pr->SiS_P3d4,0x36,temp); + } + + if(HwDeviceExtension->jChipType < SIS_315H) { + SiS_Pr->SiS_LCDTypeInfo = temp >> 4; + } else { + SiS_Pr->SiS_LCDTypeInfo = (temp & 0x0F) - 1; + } + temp &= 0x0f; + if(HwDeviceExtension->jChipType < SIS_315H) { + /* TW: Translate 300 series LCDRes to 310/325 series for unified usage */ + temp = SiS300SeriesLCDRes[temp]; + } + SiS_Pr->SiS_LCDResInfo = temp; + + if(SiS_Pr->SiS_IF_DEF_FSTN){ + SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_Panel320x480; + } + + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMin301) + SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMin301; + } else { + if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMinLVDS) + SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMinLVDS; + } + + if(SiS_Pr->SiS_LCDResInfo > SiS_Pr->SiS_PanelMax) + SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_Panel1024x768; + + temp = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x37); + if(SiS_Pr->SiS_IF_DEF_FSTN){ + /* TW: Fake LVDS bridge for FSTN */ + temp = 0x04; + SiS_SetReg1(SiS_Pr->SiS_P3d4,0x37,temp); + } + SiS_Pr->SiS_LCDInfo = temp; + + /* TW: Inserted entire 315-block from 650/LVDS/301+LVx BIOSes */ + if(HwDeviceExtension->jChipType >= SIS_315H) { +#ifdef SIS315H + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) { + if(ModeNo == 0x3a || ModeNo == 0x4d || ModeNo == 0x65) { + SiS_Pr->SiS_LCDInfo |= LCDNonExpanding; + } + } + } + } + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x39) & 0x01) { + SiS_Pr->SiS_LCDInfo &= 0xFFEF; + SiS_Pr->SiS_LCDInfo |= LCDPass11; + } +#endif + } else { +#ifdef SIS300 + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { + if((ROMAddr) && SiS_Pr->SiS_UseROM) { + if(!(ROMAddr[0x235] & 0x02)) { + SiS_Pr->SiS_LCDInfo &= 0xEF; + } + } + } else { + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + if((SiS_Pr->SiS_SetFlag & CRT2IsVGA) && ((ModeNo == 0x03) || (ModeNo == 0x10))) { + SiS_Pr->SiS_LCDInfo &= 0xEF; + } + } + } +#endif + } + +#ifdef LINUX_KERNEL + printk(KERN_DEBUG "sisfb: (LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x)\n", + SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo); +#endif +#ifdef LINUX_XF86 + xf86DrvMsgVerb(0, X_PROBED, 3, + "(init301: LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x)\n", + SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo); +#endif + + /* TW: With Trumpion, always Expanding */ + if(SiS_Pr->SiS_IF_DEF_TRUMPION != 0){ + SiS_Pr->SiS_LCDInfo &= (~LCDNonExpanding); + } + + if(!((HwDeviceExtension->jChipType < SIS_315H) && (SiS_Pr->SiS_SetFlag & CRT2IsVGA))) { + + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600) { + if(ModeNo > 0x13) { + if(!(SiS_Pr->SiS_LCDInfo & LCDNonExpanding)) { + if((resinfo == 7) || (resinfo == 3)) { + SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; + } + } + } + } + if(SiS_Pr->SiS_LCDInfo & LCDPass11) { + SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; + } + } + + if(modeflag & HalfDCLK) { + if(SiS_Pr->SiS_IF_DEF_TRUMPION == 0) { + if(!(SiS_Pr->SiS_LCDInfo & LCDNonExpanding)) { + if(!(((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (HwDeviceExtension->jChipType < SIS_315H)) && + (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480))) { + if(ModeNo > 0x13) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) { + if(resinfo == 4) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; /* 512x384 */ + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) { + if(resinfo == 3) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; /* 400x300 */ + } + } + } else SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; + } else SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; + } else SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; + } + + } + + /* TW: wdr: if (VBInfo & LCD) && (VBInfo & (SetSimuScanMode | SwitchToCRT2)) { */ + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { + if(SiS_Pr->SiS_VBInfo & SetNotSimuMode) { + SiS_Pr->SiS_SetFlag |= LCDVESATiming; + } + } else { + SiS_Pr->SiS_SetFlag |= LCDVESATiming; + } + +#ifdef SIS315H + /* TW: Inserted from 650/301LVx BIOS 1.10.6s */ + if(HwDeviceExtension->jChipType > SIS_315H) { + if(SiS_Pr->SiS_VBType & VB_SIS30xNEW) { + temp = 0x00; + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) temp = 0x04; + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) temp = 0x04; + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) temp = 0x04; + SiS_SetReg1(SiS_Pr->SiS_P3d4,0x39,temp); + } else if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + SiS_SetReg1(SiS_Pr->SiS_P3d4,0x39,0x00); + } + } +#endif + + return 1; +} + +void +SiS_PresetScratchregister(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + return; + /*SiS_SetReg1(SiS_Pr->SiS_P3d4,0x30,0x21); */ + /*SiS_SetReg1(SiS_Pr->SiS_P3d4,0x31,0x41); */ + /*SiS_SetReg1(SiS_Pr->SiS_P3d4,0x32,0x28); */ + /*SiS_SetReg1(SiS_Pr->SiS_P3d4,0x33,0x22); */ + /*SiS_SetReg1(SiS_Pr->SiS_P3d4,0x35,0x43); */ + /*SiS_SetReg1(SiS_Pr->SiS_P3d4,0x36,0x01); */ + /*SiS_SetReg1(SiS_Pr->SiS_P3d4,0x37,0x00); */ +} + +void +SiS_LongWait(SiS_Private *SiS_Pr) +{ + USHORT i; + + i = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x1F); + + if(!(i & 0xC0)) { + for(i=0; i<0xFFFF; i++) { + if(!(SiS_GetReg2(SiS_Pr->SiS_P3da) & 0x08)) + break; + } + for(i=0; i<0xFFFF; i++) { + if((SiS_GetReg2(SiS_Pr->SiS_P3da) & 0x08)) + break; + } + } +} + +void +SiS_VBLongWait(SiS_Private *SiS_Pr) +{ + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) { + SiS_VBWait(SiS_Pr); + } else { + SiS_LongWait(SiS_Pr); + } + return; +} + +void +SiS_VBWait(SiS_Private *SiS_Pr) +{ + USHORT tempal,temp,i,j; + + temp = 0; + for(i=0; i<3; i++) { + for(j=0; j<100; j++) { + tempal = SiS_GetReg2(SiS_Pr->SiS_P3da); + if(temp & 0x01) { + if((tempal & 0x08)) continue; + if(!(tempal & 0x08)) break; + } else { + if(!(tempal & 0x08)) continue; + if((tempal & 0x08)) break; + } + } + temp ^= 0x01; + } +} + +void +SiS_WaitVBRetrace(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + if(HwDeviceExtension->jChipType < SIS_315H) { +#ifdef SIS300 + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + if(!(SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x00) & 0x20)) return; + } + if(!(SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x00) & 0x80)) { + SiS_WaitRetrace1(SiS_Pr,HwDeviceExtension); + } else { + SiS_WaitRetrace2(SiS_Pr,HwDeviceExtension); + } +#endif + } else { +#ifdef SIS315H + if(!(SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x00) & 0x40)) { + SiS_WaitRetrace1(SiS_Pr,HwDeviceExtension); + } else { + SiS_WaitRetrace2(SiS_Pr,HwDeviceExtension); + } +#endif + } +} + +void +SiS_WaitRetrace1(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT watchdog; +#ifdef SIS300 + USHORT i; +#endif + + if(HwDeviceExtension->jChipType >= SIS_315H) { +#ifdef SIS315H + if(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x1f) & 0xc0) return; + watchdog = 65535; + while( (SiS_GetReg2(SiS_Pr->SiS_P3da) & 0x08) && --watchdog); + watchdog = 65535; + while( (!(SiS_GetReg2(SiS_Pr->SiS_P3da) & 0x08)) && --watchdog); +#endif + } else { +#ifdef SIS300 +#if 0 /* TW: Not done in A901 BIOS */ + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + if(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x1f) & 0xc0) return; + } +#endif + for(i=0; i<10; i++) { + watchdog = 65535; + while( (SiS_GetReg2(SiS_Pr->SiS_P3da) & 0x08) && --watchdog); + if(watchdog) break; + } + for(i=0; i<10; i++) { + watchdog = 65535; + while( (!(SiS_GetReg2(SiS_Pr->SiS_P3da) & 0x08)) && --watchdog); + if(watchdog) break; + } +#endif + } +} + +void +SiS_WaitRetraceDDC(SiS_Private *SiS_Pr) +{ + USHORT watchdog; + + if(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x1f) & 0xc0) return; + watchdog = 65535; + while( (SiS_GetReg2(SiS_Pr->SiS_P3da) & 0x08) && --watchdog); + watchdog = 65535; + while( (!(SiS_GetReg2(SiS_Pr->SiS_P3da) & 0x08)) && --watchdog); +} + +void +SiS_WaitRetrace2(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT watchdog; +#ifdef SIS300 + USHORT i; +#endif + + if(HwDeviceExtension->jChipType >= SIS_315H) { +#ifdef SIS315H + watchdog = 65535; + while( (SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x30) & 0x02) && --watchdog); + watchdog = 65535; + while( (!(SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x30) & 0x02)) && --watchdog); +#endif + } else { +#ifdef SIS300 + for(i=0; i<10; i++) { + watchdog = 65535; + while( (SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x25) & 0x02) && --watchdog); + if(watchdog) break; + } + for(i=0; i<10; i++) { + watchdog = 65535; + while( (!(SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x25) & 0x02)) && --watchdog); + if(watchdog) break; + } +#endif + } +} + +/* =========== Set and Get register routines ========== */ + +void +SiS_SetRegANDOR(USHORT Port,USHORT Index,USHORT DataAND,USHORT DataOR) +{ + USHORT temp; + + temp = SiS_GetReg1(Port,Index); + temp = (temp & (DataAND)) | DataOR; + SiS_SetReg1(Port,Index,temp); +} + +void +SiS_SetRegAND(USHORT Port,USHORT Index,USHORT DataAND) +{ + USHORT temp; + + temp = SiS_GetReg1(Port,Index); + temp &= DataAND; + SiS_SetReg1(Port,Index,temp); +} + +void SiS_SetRegOR(USHORT Port,USHORT Index,USHORT DataOR) +{ + USHORT temp; + + temp = SiS_GetReg1(Port,Index); + temp |= DataOR; + SiS_SetReg1(Port,Index,temp); +} + +/* ========================================================= */ + +/* TW: Set 301 TV Encoder (and some LCD relevant) registers */ +void +SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr, USHORT ModeNo, + USHORT ModeIdIndex,USHORT RefreshRateTableIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT i, j, tempax, tempbx, tempcx, temp, temp1; + USHORT push1, push2; + const UCHAR *PhasePoint; + const UCHAR *TimingPoint; + const SiS_Part2PortTblStruct *CRT2Part2Ptr = NULL; + USHORT modeflag, resinfo, crt2crtc, resindex, CRT2Index; + ULONG longtemp, tempeax, tempebx, temp2, tempecx; + const UCHAR atable[] = { + 0xc3,0x9e,0xc3,0x9e,0x02,0x02,0x02, + 0xab,0x87,0xab,0x9e,0xe7,0x02,0x02 + }; + + /* TW: Inserted from 650/301LV BIOS */ + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { + /* TW: Inserted from 650/301LVx 1.10.6s: (Is at end of SetGroup2!) */ + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) { + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xfc,0x03); + temp = 1; + if(ModeNo <= 0x13) temp = 3; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x0b,temp); + } + } + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + if(!(SiS_Pr->SiS_VBInfo & SetPALTV)) { + if((ModeNo == 0x4a) || (ModeNo == 0x38)) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x1c,0xa7); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x1d,0x07); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x1e,0xf2); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x1f,0x6e); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x20,0x17); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x21,0x8b); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x22,0x73); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x23,0x53); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x24,0x13); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x25,0x40); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x26,0x34); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x27,0xf4); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x28,0x63); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x29,0xbb); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2a,0xcc); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2b,0x7a); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2c,0x58); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2d,0xe4); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2e,0x73); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2f,0xda); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x30,0x13); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x43,0x72); + } + } + } + } + return; + } + + if(ModeNo<=0x13) { + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; /* si+St_ResInfo */ + resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo; + crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; + } else { + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; /* si+Ext_ResInfo */ + resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; + crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; + } + + tempcx = SiS_Pr->SiS_VBInfo; + tempax = (tempcx & 0x00FF) << 8; + tempbx = (tempcx & 0x00FF) | ((tempcx & 0x00FF) << 8); + tempbx &= 0x0410; + temp = (tempax & 0x0800) >> 8; + temp >>= 1; + temp |= (((tempbx & 0xFF00) >> 8) << 1); + temp |= ((tempbx & 0x00FF) >> 3); + temp ^= 0x0C; + + /* TW: From 1.10.7w (no vb check there) */ + if(SiS_Pr->SiS_VBType & (VB_SIS30xLV | VB_SIS30xNEW)) { + temp |= 0x0c; + } + + PhasePoint = SiS_Pr->SiS_PALPhase; + TimingPoint = SiS_Pr->SiS_PALTiming; +#ifdef oldHV + if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) { /* PALPhase */ + temp ^= 0x01; + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { + TimingPoint = SiS_Pr->SiS_HiTVSt2Timing; + if(SiS_Pr->SiS_SetFlag & TVSimuMode) { + if(modeflag & Charx8Dot) TimingPoint = SiS_Pr->SiS_HiTVSt1Timing; + else TimingPoint = SiS_Pr->SiS_HiTVTextTiming; + } + } else TimingPoint = SiS_Pr->SiS_HiTVExtTiming; + } else { +#endif + if(SiS_Pr->SiS_VBInfo & SetPALTV){ + + TimingPoint = SiS_Pr->SiS_PALTiming; + PhasePoint = SiS_Pr->SiS_PALPhase; + + if( (SiS_Pr->SiS_VBType & (VB_SIS301B | VB_SIS302B)) && + ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || + (SiS_Pr->SiS_SetFlag & TVSimuMode) ) ) { + PhasePoint = SiS_Pr->SiS_PALPhase2; + } + + } else { + + temp |= 0x10; + TimingPoint = SiS_Pr->SiS_NTSCTiming; + PhasePoint = SiS_Pr->SiS_NTSCPhase; + + if( (SiS_Pr->SiS_VBType & (VB_SIS301B | VB_SIS302B)) && + ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || + (SiS_Pr->SiS_SetFlag & TVSimuMode) ) ) { + PhasePoint = SiS_Pr->SiS_NTSCPhase2; + } + + } +#ifdef oldHV + } +#endif + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x00,temp); + + temp = 0; + if((HwDeviceExtension->jChipType == SIS_630)|| + (HwDeviceExtension->jChipType == SIS_730)) { + temp = 0x35; + } + if(HwDeviceExtension->jChipType >= SIS_315H) { + temp = 0x38; + } + if(temp) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x31) & 0x01) { + temp1 = SiS_GetReg1(SiS_Pr->SiS_P3d4,temp); + if(temp1 & EnablePALM) { /* 0x40 */ + PhasePoint = SiS_Pr->SiS_PALMPhase; + if( (SiS_Pr->SiS_VBType & (VB_SIS301B | VB_SIS302B)) && + ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || + (SiS_Pr->SiS_SetFlag & TVSimuMode) ) ) { + PhasePoint = SiS_Pr->SiS_PALMPhase2; + } + } + if(temp1 & EnablePALN) { /* 0x80 */ + PhasePoint = SiS_Pr->SiS_PALNPhase; + if( (SiS_Pr->SiS_VBType & (VB_SIS301B | VB_SIS302B)) && + ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || + (SiS_Pr->SiS_SetFlag & TVSimuMode) ) ) { + PhasePoint = SiS_Pr->SiS_PALNPhase2; + } + } + } + } + } + +#ifdef SIS315H + /* TW: Inserted from 650/301LV BIOS */ + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { /* 650/301LV : 301LV | 302LV */ + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + if(!(SiS_Pr->SiS_VBInfo & SetPALTV)) { + if((ModeNo == 0x4a) || (ModeNo == 0x38)) { + PhasePoint = SiS_Pr->SiS_SpecialPhase; + } + } + } + } + } +#endif + + for(i=0x31, j=0; i<=0x34; i++, j++){ + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,PhasePoint[j]); + } + + for(i=0x01, j=0; i<=0x2D; i++, j++){ + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]); + } + for(i=0x39; i<=0x45; i++, j++){ + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]); + } + + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(!(SiS_Pr->SiS_ModeType & 0x07)) + SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x3A,0x1F); + } else { + SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x3A,0x1F); + } + } + + SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x0A,SiS_Pr->SiS_NewFlickerMode); + + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x35,SiS_Pr->SiS_RY1COE); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x36,SiS_Pr->SiS_RY2COE); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x37,SiS_Pr->SiS_RY3COE); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x38,SiS_Pr->SiS_RY4COE); + +#ifdef oldHV + if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) tempax = 950; + else { +#endif + if(SiS_Pr->SiS_VBInfo & SetPALTV) tempax = 520; + else tempax = 440; +#ifdef oldHV + } +#endif + + if( ( ( (!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) || (SiS_Pr->SiS_HiVision == 3) ) && (SiS_Pr->SiS_VDE <= tempax) ) || + ( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) && (SiS_Pr->SiS_HiVision != 3) && + ( (SiS_Pr->SiS_VGAHDE == 1024) || ((SiS_Pr->SiS_VGAHDE != 1024) && (SiS_Pr->SiS_VDE <= tempax)) ) ) ) { + + tempax -= SiS_Pr->SiS_VDE; + tempax >>= 2; + tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8); + + temp = (tempax & 0xFF00) >> 8; + temp += (USHORT)TimingPoint[0]; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x01,temp); + + temp = (tempax & 0xFF00) >> 8; + temp += (USHORT)TimingPoint[1]; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x02,temp); + + if( (SiS_Pr->SiS_VBInfo & (SetCRT2ToTV - SetCRT2ToHiVisionTV)) && + (SiS_Pr->SiS_HiVision != 3) && + (SiS_Pr->SiS_VGAHDE >= 1024) ) { + if(SiS_Pr->SiS_VBInfo & SetPALTV) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x01,0x19); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x02,0x52); + } else { + if(HwDeviceExtension->jChipType >= SIS_315H) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x01,0x17); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x02,0x1d); + } else { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x01,0x0b); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x02,0x11); + } + } + } + + } + + tempcx = SiS_Pr->SiS_HT; + + /* TW: Inserted from 650/301LVx 1.10.6s */ + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x39) & 0x04) { + tempcx >>= 1; + } + } + + tempcx--; + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + tempcx--; + } + temp = tempcx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x1B,temp); + temp = (tempcx & 0xFF00) >> 8; + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0xF0,temp); + + tempcx++; + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + tempcx++; + } + tempcx >>= 1; + + push1 = tempcx; + + tempcx += 7; +#ifdef oldHV + if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) tempcx -= 4; +#endif + temp = (tempcx & 0x00FF) << 4; + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x22,0x0F,temp); + + tempbx = TimingPoint[j] | ((TimingPoint[j+1]) << 8); + tempbx += tempcx; + + push2 = tempbx; + + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x24,temp); + temp = ((tempbx & 0xFF00) >> 8) << 4; + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0F,temp); + + tempbx = push2; + + tempbx += 8; +#ifdef oldHV + if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) { + tempbx -= 4; + tempcx = tempbx; + } +#endif + temp = (tempbx & 0x00FF) << 4; + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x29,0x0F,temp); + + j += 2; + tempcx += ((TimingPoint[j] | ((TimingPoint[j+1]) << 8))); + temp = tempcx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x27,temp); + temp = ((tempcx & 0xFF00) >> 8) << 4; + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x28,0x0F,temp); + + tempcx += 8; +#ifdef oldHV + if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) tempcx -= 4; +#endif + temp = (tempcx & 0x00FF) << 4; + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2A,0x0F,temp); + + tempcx = push1; + + j += 2; + tempcx -= (TimingPoint[j] | ((TimingPoint[j+1]) << 8)); + temp = (tempcx & 0x00FF) << 4; + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2D,0x0F,temp); + + tempcx -= 11; + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) { + tempax = SiS_GetVGAHT2(SiS_Pr) - 1; + tempcx = tempax; + } + temp = tempcx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2E,temp); + + tempbx = SiS_Pr->SiS_VDE; + if(SiS_Pr->SiS_VGAVDE == 360) tempbx = 746; + if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 746; + if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 853; + if(HwDeviceExtension->jChipType < SIS_315H) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempbx >>= 1; + } else { + if((SiS_Pr->SiS_VBInfo & SetCRT2ToTV) && (!(SiS_Pr->SiS_HiVision & 0x03))) { + tempbx >>= 1; + if(SiS_Pr->SiS_SetFlag & TVSimuMode) { + if(ModeNo <= 0x13) { + if(crt2crtc == 1) { + tempbx++; + } + } + } else { + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { + if(crt2crtc == 4) /* TW: BIOS calls GetRatePtrCRT2 here - does not make sense */ + if(SiS_Pr->SiS_ModeType <= 3) tempbx++; + } + } + } + } + tempbx -= 2; + temp = tempbx & 0x00FF; +#ifdef oldHV + if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) { + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { + if(ModeNo == 0x2f) temp++; + } + } +#endif + /* TW: From 1.10.7w - doesn't make sense */ + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { + if(!(SiS_Pr->SiS_VBInfo & SetPALTV)) { + if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) { /* SetFlag?? */ + if(ModeNo == 0x03) temp++; + } + } + } + } + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2F,temp); + + tempax = (tempcx & 0xFF00) | (tempax & 0x00FF); + tempbx = ((tempbx & 0xFF00) << 6) | (tempbx & 0x00FF); + tempax |= (tempbx & 0xFF00); +#ifdef oldHV + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV)) { +#endif + if(HwDeviceExtension->jChipType < SIS_315H) { + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART)) { /* TW: New from 630/301B (II) BIOS */ + tempax |= 0x1000; + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToSVIDEO)) tempax |= 0x2000; + } + } else { + tempax |= 0x1000; + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToSVIDEO)) tempax |= 0x2000; + } +#ifdef oldHV + } +#endif + temp = (tempax & 0xFF00) >> 8; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x30,temp); + + /* TW: Inserted from 650/301LVx 1.10.6s */ + if(HwDeviceExtension->jChipType > SIS_315H) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + if( (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) || + (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) ) { + SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x10,0x60); + } + } + } + + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { /* tv gatingno */ + tempbx = SiS_Pr->SiS_VDE; + if((SiS_Pr->SiS_VBInfo & SetCRT2ToTV) && (!(SiS_Pr->SiS_HiVision & 0x03))) { + tempbx >>= 1; + } + tempbx -= 3; + tempbx &= 0x03ff; + temp = ((tempbx & 0xFF00) >> 8) << 5; + temp |= 0x18; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x46,temp); + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x47,temp); + if(HwDeviceExtension->jChipType >= SIS_315H) { /* TW: Inserted from 650/301LVx 1.10.6s */ + tempax = 0; + if(SiS_Pr->SiS_HiVision & 0x07) { + if(SiS_Pr->SiS_HiVision & 0x04) tempax = 0x1000; + else if(SiS_Pr->SiS_HiVision & 0x01) tempax = 0x3000; + else tempax = 0x5000; + } + temp = (tempax & 0xFF00) >> 8; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x4d,temp); + } + } + + tempbx &= 0x00FF; + if(!(modeflag & HalfDCLK)) { + tempcx = SiS_Pr->SiS_VGAHDE; + if(tempcx >= SiS_Pr->SiS_HDE) { + tempbx |= 0x2000; + tempax &= 0x00FF; + } + } + + tempcx = 0x0101; +/*if(SiS_Pr->SiS_VBInfo & (SetPALTV | SetCRT2ToTV)) { */ /*301b- TW: BIOS BUG? */ + if(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV - SetCRT2ToHiVisionTV)) { + if(!(SiS_Pr->SiS_HiVision & 0x03)) { + if(SiS_Pr->SiS_VGAHDE >= 1024) { + if((!(modeflag & HalfDCLK)) || + (HwDeviceExtension->jChipType < SIS_315H)) { /* TW: This check not in 630/301B */ + tempcx = 0x1920; + if(SiS_Pr->SiS_VGAHDE >= 1280) { + tempcx = 0x1420; + tempbx &= 0xDFFF; + } + } + } + } + } + + if(!(tempbx & 0x2000)){ + if(modeflag & HalfDCLK) { + tempcx = (tempcx & 0xFF00) | (((tempcx & 0x00FF) << 1) & 0xff); + } + push1 = tempbx; + tempeax = SiS_Pr->SiS_VGAHDE; + tempebx = (tempcx & 0xFF00) >> 8; + longtemp = tempeax * tempebx; + tempecx = tempcx & 0x00FF; + longtemp /= tempecx; + longtemp <<= 0x0d; + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + longtemp <<= 3; + } + tempecx = SiS_Pr->SiS_HDE; + temp2 = longtemp % tempecx; + tempeax = longtemp / tempecx; + if(temp2 != 0) tempeax++; + tempax = (USHORT)tempeax; + tempbx = push1; + tempcx = (tempcx & 0xff00) | (((tempax & 0xFF00) >> 8) >> 5); + tempbx |= (tempax & 0x1F00); + tempax = ((tempax & 0x00FF) << 8) | (tempax & 0x00FF); + } + + temp = (tempax & 0xFF00) >> 8; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x44,temp); + temp = (tempbx & 0xFF00) >> 8; + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x45,0xC0,temp); + + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + temp = tempcx & 0x00FF; + if(tempbx & 0x2000) temp = 0; + temp |= 0x18; + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x46,0xE0,temp); + if(SiS_Pr->SiS_VBInfo & SetPALTV) { + tempbx = 0x0382; /* TW: BIOS; Was 0x0364; */ + tempcx = 0x007e; /* TW: BIOS; Was 0x009c; */ + } else { + tempbx = 0x0369; /* TW: BIOS; Was 0x0346; */ + tempcx = 0x0061; /* TW: BIOS; Was 0x0078; */ + } + temp = (tempbx & 0x00FF) ; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x4B,temp); + temp = (tempcx & 0x00FF) ; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x4C,temp); + tempbx &= 0x03FF; + temp = (tempcx & 0xFF00) >> 8; + temp = (temp & 0x0003) << 2; + temp |= (tempbx >> 8); + if(HwDeviceExtension->jChipType < SIS_315H) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x4D,temp); + } else { + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4D,0xF0,temp); + } + + temp = SiS_GetReg1(SiS_Pr->SiS_Part2Port,0x43); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x43,(USHORT)(temp - 3)); + } + + temp = 0; + if((HwDeviceExtension->jChipType == SIS_630) || + (HwDeviceExtension->jChipType == SIS_730)) { + temp = 0x35; + } else if(HwDeviceExtension->jChipType >= SIS_315H) { + temp = 0x38; + } + if(temp) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x31) & 0x01) { + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,temp) & EnablePALM) { /* 0x40 */ + SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xEF); + temp = SiS_GetReg1(SiS_Pr->SiS_Part2Port,0x01); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x01,temp - 1); + } + } + } + } + + +#ifdef oldHV + if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) { + if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x0B,0x00); + } + } +#endif + + if(HwDeviceExtension->jChipType < SIS_315H) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + SiS_Set300Part2Regs(SiS_Pr, HwDeviceExtension, ModeIdIndex, + RefreshRateTableIndex, BaseAddr, ModeNo); + return; + } + } else { + /* TW: !!! The following is a duplicate, done for LCDA as well (see above) */ + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { /* 650/301LV: (VB_SIS301LV | VB_SIS302LV)) */ + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + if(!(SiS_Pr->SiS_VBInfo & SetPALTV)) { + if((ModeNo == 0x4a) || (ModeNo == 0x38)) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x1c,0xa7); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x1d,0x07); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x1e,0xf2); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x1f,0x6e); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x20,0x17); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x21,0x8b); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x22,0x73); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x23,0x53); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x24,0x13); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x25,0x40); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x26,0x34); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x27,0xf4); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x28,0x63); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x29,0xbb); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2a,0xcc); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2b,0x7a); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2c,0x58); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2d,0xe4); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2e,0x73); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2f,0xda); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x30,0x13); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x43,0x72); + } + } + } + } + return; + } + } + + /* TW: From here: Part2 LCD setup */ + + tempbx = SiS_Pr->SiS_HDE; + /* TW: Inserted from 650/301LVx 1.10.6s */ + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x39) & 0x04) tempbx >>= 1; + } + tempbx--; /* RHACTE=HDE-1 */ + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2C,temp); + temp = (tempbx & 0xFF00) >> 8; + temp <<= 4; + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2B,0x0F,temp); + + temp = 0x01; + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) { + if(SiS_Pr->SiS_ModeType == ModeEGA) { + if(SiS_Pr->SiS_VGAHDE >= 1024) { + temp = 0x02; + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(SiS_Pr->SiS_SetFlag & LCDVESATiming) { + temp = 0x01; + } + } + } + } + } + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x0B,temp); + + tempbx = SiS_Pr->SiS_VDE; /* RTVACTEO=(VDE-1)&0xFF */ + push1 = tempbx; + + tempbx--; + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x03,temp); + temp = ((tempbx & 0xFF00) >> 8) & 0x07; + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0C,0xF8,temp); + + tempcx = SiS_Pr->SiS_VT; + push2 = tempcx; + + tempcx--; + temp = tempcx & 0x00FF; /* RVTVT=VT-1 */ + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x19,temp); + + temp = (tempcx & 0xFF00) >> 8; + temp <<= 5; + if((HwDeviceExtension->jChipType == SIS_300) && (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) { + if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) temp |= 0x10; + } else if(HwDeviceExtension->jChipType < SIS_315H) { + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) temp |= 0x10; + else { + if(SiS_Pr->SiS_LCDInfo & LCDSync) /* TW: 630/301 BIOS checks this */ + temp |= 0x10; + } + } else { + if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { + /* TW: Inserted from 630/301LVx 1.10.6s */ + if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) { + if(SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x00) & 0x01) { + temp |= 0x10; + } + } + } else { + temp |= 0x10; + } + } + + /* 630/301 does not do all this */ + if((SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) { + if((HwDeviceExtension->jChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) { + /* TW: Inserted from 650/301LVx 1.10.6s */ + temp |= (SiS_GetReg1(SiS_Pr->SiS_P3d4,0x37) >> 6); + temp |= 0x08; /* From 1.10.7w */ + if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) temp |= 0x04; /* From 1.10.7w */ + } else { + tempbx = (tempbx & 0xFF00) | (SiS_Pr->SiS_LCDInfo & 0x0FF); + if(tempbx & LCDSync) { + tempbx &= (0xFF00 | LCDSyncBit); + tempbx = (tempbx & 0xFF00) | ((tempbx & 0x00FF) >> LCDSyncShift); + temp |= (tempbx & 0x00FF); + } + } + } + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x1A,temp); + + SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x09,0xF0); + SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x0A,0xF0); + + SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x17,0xFB); + SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x18,0xDF); + + /* 1280x960, 1280x1024 and 1600x1200 data invalid/missing in tables, use old calculation */ + if((HwDeviceExtension->jChipType >= SIS_315H) && + (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && + (SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1280x1024) && + (SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1600x1200) && + (SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1280x960)) { + /* ------------- 310 series ------------ */ + + /* TW: Inserted this entire section from 650/301LV(x) BIOS */ + + SiS_GetCRT2Part2Ptr(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + &CRT2Index,&resindex); + + switch(CRT2Index) { + case Panel_1024x768 : CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1; break; /* "Normal" */ + case Panel_1280x1024 : CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1280x1024_1; break; + case Panel_1400x1050 : CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1400x1050_1; break; + case Panel_1600x1200 : CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1600x1200_1; break; + case Panel_1024x768 + 16 : CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_2; break; /* Non-Expanding */ + case Panel_1280x1024 + 16: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1280x1024_2; break; + case Panel_1400x1050 + 16: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1400x1050_2; break; + case Panel_1600x1200 + 16: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1600x1200_2; break; + case Panel_1024x768 + 32 : CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_3; break; /* VESA Timing */ + case Panel_1280x1024 + 32: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1280x1024_3; break; + case Panel_1400x1050 + 32: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1400x1050_3; break; + case Panel_1600x1200 + 32: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1600x1200_3; break; + default: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_3; break; + } + + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]); + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]); + for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]); + } + for(j = 0x1c; j <= 0x1d; i++, j++ ) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]); + } + for(j = 0x1f; j <= 0x21; i++, j++ ) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]); + } + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]); + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]); + + if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) { + if(SiS_Pr->SiS_VGAVDE == 0x20d) { + temp = 0xc3; + if(SiS_Pr->SiS_ModeType <= ModeVGA) { + temp++; + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) temp += 2; + } + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2f,temp); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x30,0xb3); + } + if(SiS_Pr->SiS_VGAVDE == 0x1a4) { + temp = 0x4d; + if(SiS_Pr->SiS_ModeType <= ModeVGA) { + temp++; + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) temp++; + } + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2f,temp); + } + } + + /* TW: Inserted from 650/301LVx 1.10.6s: */ + /* !!! This is a duplicate, done for LCDA as well - see above */ + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) { + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xfc,0x03); /* Not done in 1.10.7w */ + temp = 1; + if(ModeNo <= 0x13) temp = 3; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x0b,temp); + } + } + + } else { /* ------------- 300 series (and other LCD resolutions) ----------- */ + + tempcx++; + tempbx = 768; + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1024x768) { + tempbx = 1024; + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1280x1024) { + tempbx = 1200; + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1600x1200) { + if(tempbx != SiS_Pr->SiS_VDE) { + tempbx = 960; + } + } + } + } + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) { + tempbx = SiS_Pr->SiS_VDE - 1; + tempcx--; + } + tempax = 1; + if(!(SiS_Pr->SiS_LCDInfo & LCDNonExpanding)) { + if(tempbx != SiS_Pr->SiS_VDE){ + tempax = tempbx; + if(tempax < SiS_Pr->SiS_VDE) { + tempax = 0; + tempcx = 0; + } else { + tempax -= SiS_Pr->SiS_VDE; + } + tempax >>= 1; + } + tempcx -= tempax; /* lcdvdes */ + tempbx -= tempax; /* lcdvdee */ + } else { + tempax >>= 1; + tempcx -= tempax; /* lcdvdes */ + tempbx -= tempax; /* lcdvdee */ + } + + temp = tempcx & 0x00FF; /* RVEQ1EQ=lcdvdes */ + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x05,temp); + temp = tempbx & 0x00FF; /* RVEQ2EQ=lcdvdee */ + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x06,temp); + + temp = ((tempbx & 0xFF00) >> 8 ) << 3; + temp |= ((tempcx & 0xFF00) >> 8); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x02,temp); + + tempbx = push2; + tempax = push1; + tempcx = tempbx; + tempcx -= tempax; + tempcx >>= 4; + tempbx += tempax; + tempbx >>= 1; + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx -= 10; + + temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */ + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x04,temp); + + temp = ((tempbx & 0xFF00) >> 8) << 4; + tempbx += (tempcx + 1); + temp |= (tempbx & 0x000F); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x01,temp); + + /* TW: Code from 630/301B (I+II) BIOS */ + + if( ( ( (HwDeviceExtension->jChipType == SIS_630) || + (HwDeviceExtension->jChipType == SIS_730) ) && + (HwDeviceExtension->jChipRevision > 2) ) && + (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) && + (!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) && + (!(SiS_Pr->SiS_LCDInfo & LCDNonExpanding)) ) { + if(ModeNo == 0x13) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x04,0xB9); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x05,0xCC); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x06,0xA6); + } else { + if((crt2crtc & 0x3F) == 4) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x01,0x2B); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x02,0x13); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x04,0xE5); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x05,0x08); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x06,0xE2); + } + } + } + + /* TW: Inserted missing code from 630/301B BIOS: (II: 3258) */ + + if(SiS_Pr->SiS_LCDTypeInfo == 0x0c) { + crt2crtc &= 0x1f; + tempcx = 0; + if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) { + if (SiS_Pr->SiS_VBInfo & SetInSlaveMode) { + tempcx += 7; + } + } + tempcx += crt2crtc; + if (crt2crtc >= 4) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x06,0xff); + } + + if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) { + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { + if(crt2crtc == 4) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x01,0x28); + } + } + } + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x02,0x18); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x04,atable[tempcx]); + } + + tempcx = (SiS_Pr->SiS_HT - SiS_Pr->SiS_HDE) >> 2; /* (HT-HDE)>>2 */ + tempbx = SiS_Pr->SiS_HDE + 7; /* lcdhdee */ + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + tempbx += 2; + } + push1 = tempbx; + temp = tempbx & 0x00FF; /* RHEQPLE=lcdhdee */ + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x23,temp); + temp = (tempbx & 0xFF00) >> 8; + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0xF0,temp); + + temp = 7; + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + temp += 2; + } + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x1F,temp); /* RHBLKE=lcdhdes */ + + SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x20,0x0F); + + tempbx += tempcx; + push2 = tempbx; + temp = tempbx & 0xFF; /* RHBURSTS=lcdhrs */ + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) { + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) { + if(SiS_Pr->SiS_HDE == 1280) temp = 0x47; + } + } + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x1C,temp); + temp = ((tempbx & 0xFF00) >> 8) << 4; + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0x0F,temp); + + tempbx = push2; + tempcx <<= 1; + tempbx += tempcx; + temp = tempbx & 0x00FF; /* RHSYEXP2S=lcdhre */ + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x21,temp); + + if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) { + if(SiS_Pr->SiS_VGAVDE == 525) { + if(SiS_Pr->SiS_ModeType <= ModeVGA) + temp=0xC6; + else + temp=0xC3; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2f,temp); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x30,0xB3); + } else if(SiS_Pr->SiS_VGAVDE == 420) { + if(SiS_Pr->SiS_ModeType <= ModeVGA) + temp=0x4F; + else + temp=0x4D; /* 650: 4e */ + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x2f,temp); + } + } + SiS_Set300Part2Regs(SiS_Pr, HwDeviceExtension, ModeIdIndex, + RefreshRateTableIndex, BaseAddr, ModeNo); + + } /* HwDeviceExtension */ +} + +USHORT +SiS_GetVGAHT2(SiS_Private *SiS_Pr) +{ + ULONG tempax,tempbx; + + tempbx = ((SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) * SiS_Pr->SiS_RVBHCMAX) & 0xFFFF; + tempax = (SiS_Pr->SiS_VT - SiS_Pr->SiS_VDE) * SiS_Pr->SiS_RVBHCFACT; + tempax = (tempax * SiS_Pr->SiS_HT) / tempbx; + return((USHORT) tempax); +} + +/* TW: New from 300/301LV BIOS 1.16.51. Seems highly preliminary. */ +void +SiS_Set300Part2Regs(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, + USHORT ModeIdIndex, USHORT RefreshRateTableIndex, + USHORT BaseAddr, USHORT ModeNo) +{ + USHORT crt2crtc, resindex; + int i,j; + const SiS_Part2PortTblStruct *CRT2Part2Ptr = NULL; + + if(HwDeviceExtension->jChipType != SIS_300) return; + if(!(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) return; + + if(ModeNo<=0x13) { + crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; + } else { + crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; + } + + resindex = crt2crtc & 0x3F; + if(SiS_Pr->SiS_SetFlag & LCDVESATiming) CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1; + else CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_2; + + /* TW: The BIOS code (1.16.51) is obviously a fragment! */ + if(ModeNo > 0x13) { + CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1; + resindex = 4; + } + + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]); + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]); + for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]); + } + for(j = 0x1c; j <= 0x1d; i++, j++ ) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]); + } + for(j = 0x1f; j <= 0x21; i++, j++ ) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]); + } + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]); + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]); +} + +/* TW: Set 301 Macrovision(tm) registers */ +/* TW: Double-Checked against 650/301LV, 650/301LVx and 630/301B BIOS */ +void +SiS_SetGroup3(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo, + USHORT ModeIdIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT temp; +#ifdef oldHV + USHORT i; + const UCHAR *tempdi; +#endif + USHORT modeflag; + + /* TW: Inserted from 650/301LVx 1.10.6s, 1.10.7w */ + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return; + + if(ModeNo<=0x13) + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + else + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + + SiS_SetReg1(SiS_Pr->SiS_Part3Port,0x00,0x00); + + if(SiS_Pr->SiS_VBInfo & SetPALTV) { + SiS_SetReg1(SiS_Pr->SiS_Part3Port,0x13,0xFA); + SiS_SetReg1(SiS_Pr->SiS_Part3Port,0x14,0xC8); + } else { + if(HwDeviceExtension->jChipType >= SIS_315H) { + SiS_SetReg1(SiS_Pr->SiS_Part3Port,0x13,0xF5); + SiS_SetReg1(SiS_Pr->SiS_Part3Port,0x14,0xB7); + } else { + SiS_SetReg1(SiS_Pr->SiS_Part3Port,0x13,0xF6); + SiS_SetReg1(SiS_Pr->SiS_Part3Port,0x14,0xBf); + } + } + + temp = 0; + if((HwDeviceExtension->jChipType == SIS_630)|| + (HwDeviceExtension->jChipType == SIS_730)) { + temp = 0x35; + } else if(HwDeviceExtension->jChipType >= SIS_315H) { + temp = 0x38; + } + if(temp) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x31) & 0x01) { + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,temp) & EnablePALM){ /* 0x40 */ + SiS_SetReg1(SiS_Pr->SiS_Part3Port,0x13,0xFA); + SiS_SetReg1(SiS_Pr->SiS_Part3Port,0x14,0xC8); + SiS_SetReg1(SiS_Pr->SiS_Part3Port,0x3D,0xA8); + } + } + } + } + +#ifdef oldHV + if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) { + tempdi = SiS_Pr->SiS_HiTVGroup3Data; + if(SiS_Pr->SiS_SetFlag & TVSimuMode) { + tempdi = SiS_Pr->SiS_HiTVGroup3Simu; + if(!(modeflag & Charx8Dot)) { + tempdi = SiS_Pr->SiS_HiTVGroup3Text; + } + } + for(i=0; i<=0x3E; i++){ + SiS_SetReg1(SiS_Pr->SiS_Part3Port,i,tempdi[i]); + } + } +#endif + + return; +} + +/* TW: Set 301 VGA2 registers */ +/* TW: Double-Checked against 650/301LV(x) and 630/301B BIOS */ +void +SiS_SetGroup4(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo, + USHORT ModeIdIndex,USHORT RefreshRateTableIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT tempax,tempcx,tempbx,modeflag,temp,temp2,resinfo; + ULONG tempebx,tempeax,templong; + + + if(ModeNo<=0x13) { + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo; + } else { + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; + } + + /* TW: From 650/301LVx 1.10.6s BIOS */ + if(SiS_Pr->SiS_VBType & (VB_SIS30xLV | VB_SIS30xNEW)) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x24,0x0e); + } + } + + if(SiS_Pr->SiS_VBType & VB_SIS30xNEW) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x10,0x9f); + } + } + + /* TW: From 650/301LV BIOS (any, incl. 1.10.6s, 1.10.7w) */ + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { + /* TW: This is a duplicate; done at the end, too */ + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x39) & 0x04) { + SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x2c); + } + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x2a,0x00); + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x30,0x00); + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x34,0x10); + return; + } + + temp = SiS_Pr->SiS_RVBHCFACT; + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x13,temp); + + tempbx = SiS_Pr->SiS_RVBHCMAX; + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x14,temp); + + temp2 = (((tempbx & 0xFF00) >> 8) << 7) & 0x00ff; + + tempcx = SiS_Pr->SiS_VGAHT - 1; + temp = tempcx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x16,temp); + + temp = (((tempcx & 0xFF00) >> 8) << 3) & 0x00ff; + temp2 |= temp; + + tempcx = SiS_Pr->SiS_VGAVT - 1; + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempcx -= 5; + + temp = tempcx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x17,temp); + + temp = temp2 | ((tempcx & 0xFF00) >> 8); + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x15,temp); + + tempcx = SiS_Pr->SiS_VBInfo; + tempbx = SiS_Pr->SiS_VGAHDE; + if(modeflag & HalfDCLK) tempbx >>= 1; + + /* TW: New for 650/301LV and 630/301B */ + temp = 0xA0; +#ifdef oldHV + if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) { + temp = 0; + if(tempbx > 800) { + temp = 0xA0; + if(tempbx != 1024) { + temp = 0xC0; + if(tempbx != 1280) temp = 0; + } + } + } else +#endif + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + if(tempbx <= 800) { + temp = 0x80; + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD){ + temp = 0; + if(tempbx > 800) temp = 0x60; + } + } + } else { + temp = 0x80; + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD){ + temp = 0; + if(tempbx > 800) temp = 0x60; + } + } + if(SiS_Pr->SiS_HiVision & 0x03) { + temp = 0; + if(SiS_Pr->SiS_VGAHDE == 1024) temp = 0x20; + } + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x39) & 0x04) temp = 0; + } + + if(SiS_Pr->SiS_VBType & VB_SIS301) { + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1280x1024) + temp |= 0x0A; + } + + SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0E,0x10,temp); + + tempebx = SiS_Pr->SiS_VDE; + +#ifdef oldHV + if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) { + if(!(temp & 0xE0)) tempebx >>=1; + } +#endif + + tempcx = SiS_Pr->SiS_RVBHRS; + temp = tempcx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x18,temp); + + tempeax = SiS_Pr->SiS_VGAVDE; + tempcx |= 0x4000; + if(tempeax <= tempebx){ + tempcx ^= 0x4000; + } else { + tempeax -= tempebx; + } + + templong = (tempeax * 256 * 1024) % tempebx; + tempeax = (tempeax * 256 * 1024) / tempebx; + tempebx = tempeax; + if(templong != 0) tempebx++; + + temp = (USHORT)(tempebx & 0x000000FF); + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x1B,temp); + temp = (USHORT)((tempebx & 0x0000FF00) >> 8); + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x1A,temp); + + tempbx = (USHORT)(tempebx >> 16); + temp = tempbx & 0x00FF; + temp <<= 4; + temp |= ((tempcx & 0xFF00) >> 8); + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x19,temp); + + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x1C,0x28); + tempbx = 0; + tempax = SiS_Pr->SiS_VGAHDE; + if(modeflag & HalfDCLK) tempax >>= 1; + if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) || (SiS_Pr->SiS_HiVision & 0x03)) { + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x39) & 0x04) tempax >>= 1; + else if(tempax > 800) tempax -= 800; + } else { + if(tempax > 800) tempax -= 800; + } + } + +/* if((SiS_Pr->SiS_VBInfo & (SetCRT2ToTV | SetPALTV)) && (!(SiS_Pr->SiS_HiVision & 0x03))) { */ + if((SiS_Pr->SiS_VBInfo & (SetCRT2ToTV - SetCRT2ToHiVisionTV)) && (!(SiS_Pr->SiS_HiVision & 0x03))) { + if(tempax > 800) { + tempbx = 8; + if(tempax == 1024) + tempax *= 25; + else + tempax *= 20; + + temp = tempax % 32; + tempax /= 32; + tempax--; + if (temp!=0) tempax++; + } + } + tempax--; + temp = (tempax & 0xFF00) >> 8; + temp &= 0x03; + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* From 1.10.7w */ + if(ModeNo > 0x13) { /* From 1.10.7w */ + if(resinfo == 8) tempax = 0x1f; /* From 1.10.7w */ + } /* From 1.10.7w */ + } /* From 1.10.7w */ + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x1D,tempax & 0x00FF); + temp <<= 4; + temp |= tempbx; + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x1E,temp); + + if(HwDeviceExtension->jChipType > SIS_315H) { + temp = 0x0026; /* From 1.10.7w; 1.10.6s: 0x0036 */ + } else { + temp = 0x0036; + } + if((SiS_Pr->SiS_VBInfo & (SetCRT2ToTV - SetCRT2ToHiVisionTV)) && + (!(SiS_Pr->SiS_HiVision & 0x03))) { + temp |= 0x01; + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { + if(!(SiS_Pr->SiS_SetFlag & TVSimuMode)) + temp &= 0xFE; + } + } + SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x1F,0xC0,temp); + + tempbx = SiS_Pr->SiS_HT; + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x39) & 0x04) tempbx >>= 1; + } + tempbx >>= 1; + tempbx -= 2; + temp = ((tempbx & 0x0700) >> 8) << 3; + SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0xC0,temp); + temp = tempbx & 0x00FF; + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x22,temp); + if( (SiS_Pr->SiS_VBType & (VB_SIS30xLV | VB_SIS30xNEW)) && + (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) ) { + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x24,0x0e); + } + + /* TW: 650 BIOS does this for all bridge types - assumingly wrong */ + if(HwDeviceExtension->jChipType >= SIS_315H) { + /* TW: This is a duplicate; done for LCDA as well (see above) */ + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x39) & 0x04) { + SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x2c); + } + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x2a,0x00); + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x30,0x00); + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x34,0x10); + } else if(HwDeviceExtension->jChipType == SIS_300) { + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x2a,0x00); + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x30,0x00); + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x34,0x10); + } + + } /* 301B */ + + SiS_SetCRT2VCLK(SiS_Pr,BaseAddr,ROMAddr,ModeNo,ModeIdIndex, + RefreshRateTableIndex,HwDeviceExtension); +} + +/* TW: Double-Checked against 650/301LV(x) and 630/301B BIOS */ +void +SiS_SetCRT2VCLK(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT vclkindex; + USHORT tempah; + + vclkindex = SiS_GetVCLK2Ptr(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + HwDeviceExtension); + + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + tempah = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_A; + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x0A,tempah); + tempah = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_B; + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x0B,tempah); + /* TW: New from 650/301LV, LVx BIOS (300/301LV does not do this) */ + if(HwDeviceExtension->jChipType >= SIS_315H) { + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { /* 650/301LV: (VB_SIS301LV | VB_SIS302LV)) */ + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + if(!(SiS_Pr->SiS_VBInfo & SetPALTV)) { + if((ModeNo == 0x4a) || (ModeNo == 0x38)) { + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x0a,0x57); + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x0b,0x46); + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x1f,0xf6); + } + } + } + } + } + } else { /* 650/301LVx does not do this anymore, jumps to SetRegs above - BUG? */ + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x0A,0x01); + tempah = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_B; + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x0B,tempah); + tempah = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_A; + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x0A,tempah); + } + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x12,0x00); + tempah = 0x08; + if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { + tempah |= 0x20; + } + SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x12,tempah); +} + +/* TW: Double-checked against 650/LVDS (1.10.07), 630/301B/LVDS/LVDS+CH, 650/301LVx (1.10.6s) BIOS */ +USHORT +SiS_GetVCLK2Ptr(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT tempbx; +#ifdef SIS300 + const USHORT LCDXlat1VCLK300[4] = {VCLK65, VCLK65, VCLK65, VCLK65}; + const USHORT LCDXlat2VCLK300[4] = {VCLK108_2,VCLK108_2,VCLK108_2,VCLK108_2}; + const USHORT LVDSXlat2VCLK300[4]= {VCLK65, VCLK65, VCLK65, VCLK65}; + const USHORT LVDSXlat3VCLK300[4]= {VCLK65, VCLK65, VCLK65, VCLK65}; +#endif +#ifdef SIS315H + const USHORT LCDXlat1VCLK310[4] = {VCLK65+2, VCLK65+2, VCLK65+2, VCLK65+2}; + const USHORT LCDXlat2VCLK310[4] = {VCLK108_2+5,VCLK108_2+5,VCLK108_2+5,VCLK108_2+5}; + const USHORT LVDSXlat2VCLK310[4]= {VCLK65+2, VCLK65+2, VCLK65+2, VCLK65+2}; + const USHORT LVDSXlat3VCLK310[4]= {VCLK108_2+5,VCLK108_2+5,VCLK108_2+5,VCLK108_2+5}; + /* {VCLK65+2, VCLK65+2, VCLK65+2, VCLK65+2}; - 650/LVDS 1.10.07 */ +#endif + const USHORT LCDXlat0VCLK[4] = {VCLK40, VCLK40, VCLK40, VCLK40}; + const USHORT LVDSXlat1VCLK[4] = {VCLK40, VCLK40, VCLK40, VCLK40}; + USHORT CRT2Index,VCLKIndex=0; + USHORT modeflag,resinfo; + const UCHAR *CHTVVCLKPtr=NULL; + const USHORT *LCDXlatVCLK1 = NULL; + const USHORT *LCDXlatVCLK2 = NULL; + const USHORT *LVDSXlatVCLK2 = NULL; + const USHORT *LVDSXlatVCLK3 = NULL; + + if(HwDeviceExtension->jChipType >= SIS_315H) { +#ifdef SIS315H + LCDXlatVCLK1 = LCDXlat1VCLK310; + LCDXlatVCLK2 = LCDXlat2VCLK310; + LVDSXlatVCLK2 = LVDSXlat2VCLK310; + LVDSXlatVCLK3 = LVDSXlat3VCLK310; +#endif + } else { +#ifdef SIS300 + LCDXlatVCLK1 = LCDXlat1VCLK300; + LCDXlatVCLK2 = LCDXlat2VCLK300; + LVDSXlatVCLK2 = LVDSXlat2VCLK300; + LVDSXlatVCLK3 = LVDSXlat3VCLK300; +#endif + } + + if(ModeNo <= 0x13) { + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo; + CRT2Index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; + } else { + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; + CRT2Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; + } + + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { /* 301 */ + + if (SiS_Pr->SiS_SetFlag & ProgrammingCRT2) { + + CRT2Index >>= 6; + if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)){ /* LCD */ + if(HwDeviceExtension->jChipType < SIS_315H) { + /* TW: Inserted from 630/301B BIOS */ + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) + VCLKIndex = LCDXlat0VCLK[CRT2Index]; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) + VCLKIndex = LCDXlatVCLK1[CRT2Index]; + else + VCLKIndex = LCDXlatVCLK2[CRT2Index]; + } else { + /* TW: 330, 650/301LV BIOS does not check expanding, 315 does */ + if( (HwDeviceExtension->jChipType > SIS_315PRO) || + (!(SiS_Pr->SiS_LCDInfo & LCDNonExpanding)) ) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x1024) { + VCLKIndex = 0x19; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) { + VCLKIndex = 0x19; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) { + VCLKIndex = 0x21; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) { + VCLKIndex = LCDXlatVCLK1[CRT2Index]; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1280x960) { + VCLKIndex = 0x45; /* TW: TODO: This is certainly wrong */ + if(resinfo == 0x09) VCLKIndex++; + } else { + VCLKIndex = LCDXlatVCLK2[CRT2Index]; + } + } else { + VCLKIndex = (UCHAR)SiS_GetReg2((USHORT)(SiS_Pr->SiS_P3ca+0x02)); /* Port 3cch */ + VCLKIndex = ((VCLKIndex >> 2) & 0x03); + if(ModeNo > 0x13) { + VCLKIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK; + } + if(ModeNo <= 0x13) { /* TW: Inserted from 315 BIOS */ + if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x42; + } + if(VCLKIndex == 0) VCLKIndex = 0x41; + if(VCLKIndex == 1) VCLKIndex = 0x43; + if(VCLKIndex == 4) VCLKIndex = 0x44; + } + } + } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* TV */ + if((SiS_Pr->SiS_IF_DEF_HiVision == 1) && (SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV)) { + if(SiS_Pr->SiS_SetFlag & RPLLDIV2XO) VCLKIndex = HiTVVCLKDIV2; + else VCLKIndex = HiTVVCLK; + if(SiS_Pr->SiS_SetFlag & TVSimuMode) { + if(modeflag & Charx8Dot) VCLKIndex = HiTVSimuVCLK; + else VCLKIndex = HiTVTextVCLK; + } + } else { + if(SiS_Pr->SiS_SetFlag & RPLLDIV2XO) VCLKIndex = TVVCLKDIV2; + else VCLKIndex = TVVCLK; + } + if(HwDeviceExtension->jChipType >= SIS_315H) { + VCLKIndex += 25; + } + } else { /* RAMDAC2 */ + VCLKIndex = (UCHAR)SiS_GetReg2((USHORT)(SiS_Pr->SiS_P3ca+0x02)); + VCLKIndex = ((VCLKIndex >> 2) & 0x03); + if(ModeNo > 0x13) { + VCLKIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK; + if(HwDeviceExtension->jChipType < SIS_315H) { + VCLKIndex &= 0x3f; + if( (HwDeviceExtension->jChipType == SIS_630) && + (HwDeviceExtension->jChipRevision >= 0x30)) { + if(VCLKIndex == 0x14) VCLKIndex = 0x2e; + } + } + } + } + + } else { /* If not programming CRT2 */ + + VCLKIndex = (UCHAR)SiS_GetReg2((USHORT)(SiS_Pr->SiS_P3ca+0x02)); + VCLKIndex = ((VCLKIndex >> 2) & 0x03); + if(ModeNo > 0x13) { + VCLKIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK; + if(HwDeviceExtension->jChipType < SIS_315H) { + VCLKIndex &= 0x3f; + if( (HwDeviceExtension->jChipType != SIS_630) && + (HwDeviceExtension->jChipType != SIS_300) ) { + if(VCLKIndex == 0x1b) VCLKIndex = 0x35; + } + } + } + } + + } else { /* LVDS */ + + VCLKIndex = CRT2Index; + + if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) { /* programming CRT2 */ + + if( (SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) ) { + + VCLKIndex &= 0x1f; + tempbx = 0; + if(SiS_Pr->SiS_VBInfo & SetCHTVOverScan) tempbx += 1; + if(SiS_Pr->SiS_VBInfo & SetPALTV) { + tempbx += 2; + if(SiS_Pr->SiS_CHSOverScan) tempbx = 8; + if(SiS_Pr->SiS_CHPALM) { + tempbx = 4; + if(SiS_Pr->SiS_VBInfo & SetCHTVOverScan) tempbx += 1; + } else if(SiS_Pr->SiS_CHPALN) { + tempbx = 6; + if(SiS_Pr->SiS_VBInfo & SetCHTVOverScan) tempbx += 1; + } + } + switch(tempbx) { + case 0: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUNTSC; break; + case 1: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKONTSC; break; + case 2: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPAL; break; + case 3: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break; + case 4: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALM; break; + case 5: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALM; break; + case 6: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALN; break; + case 7: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALN; break; + case 8: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKSOPAL; break; + default: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break; + } + VCLKIndex = CHTVVCLKPtr[VCLKIndex]; + + } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + + VCLKIndex >>= 6; + if((SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel800x600) || + (SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel320x480)) + VCLKIndex = LVDSXlat1VCLK[VCLKIndex]; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) + VCLKIndex = LVDSXlatVCLK2[VCLKIndex]; + else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600) + VCLKIndex = LVDSXlatVCLK2[VCLKIndex]; + else VCLKIndex = LVDSXlatVCLK3[VCLKIndex]; + + } else { + + VCLKIndex = (UCHAR)SiS_GetReg2((USHORT)(SiS_Pr->SiS_P3ca+0x02)); + VCLKIndex = ((VCLKIndex >> 2) & 0x03); + if(ModeNo > 0x13) { + VCLKIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK; + if(HwDeviceExtension->jChipType < SIS_315H) { + VCLKIndex &= 0x3F; + } + if( (HwDeviceExtension->jChipType == SIS_630) && + (HwDeviceExtension->jChipRevision >= 0x30) ) { + if(VCLKIndex == 0x14) VCLKIndex = 0x2e; + } + } + } + + } else { /* if not programming CRT2 */ + + VCLKIndex = (UCHAR)SiS_GetReg2((USHORT)(SiS_Pr->SiS_P3ca+0x02)); + VCLKIndex = ((VCLKIndex >> 2) & 0x03); + if(ModeNo > 0x13) { + VCLKIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK; + if(HwDeviceExtension->jChipType < SIS_315H) { + VCLKIndex &= 0x3F; + if( (HwDeviceExtension->jChipType != SIS_630) && + (HwDeviceExtension->jChipType != SIS_300) ) { + if(VCLKIndex == 0x1b) VCLKIndex = 0x35; + } +#if 0 + if(HwDeviceExtension->jChipType == SIS_730) { + if(VCLKIndex == 0x0b) VCLKIndex = 0x40; /* 1024x768-70 */ + if(VCLKIndex == 0x0d) VCLKIndex = 0x41; /* 1024x768-75 */ + } +#endif + } + } + + } + + } +#ifdef TWDEBUG + xf86DrvMsg(0, X_INFO, "VCLKIndex %d (0x%x)\n", VCLKIndex, VCLKIndex); +#endif + return (VCLKIndex); +} + +/* TW: Set 301 Palette address port registers */ +/* TW: Checked against 650/301LV BIOS */ +void +SiS_SetGroup5(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr, + UCHAR *ROMAddr, USHORT ModeNo, USHORT ModeIdIndex) +{ + + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return; + + if(SiS_Pr->SiS_ModeType == ModeVGA){ + if(!(SiS_Pr->SiS_VBInfo & (SetInSlaveMode | LoadDACFlag))){ + SiS_EnableCRT2(SiS_Pr); + SiS_LoadDAC(SiS_Pr,HwDeviceExtension,ROMAddr,ModeNo,ModeIdIndex); + } + } + return; +} + +/* TW: Checked against 650/LVDS and 630/301B BIOS */ +void +SiS_ModCRT1CRTC(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT temp,tempah,i,modeflag,j; + USHORT ResInfo,DisplayType; + const SiS_LVDSCRT1DataStruct *LVDSCRT1Ptr=NULL; + + if(ModeNo <= 0x13) { + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + } else { + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + } + + temp = SiS_GetLVDSCRT1Ptr(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + &ResInfo,&DisplayType); + + if(temp == 0) return; + + /* TW: Inserted from 630/LVDS BIOS */ + if(HwDeviceExtension->jChipType < SIS_315H) { + if(SiS_Pr->SiS_SetFlag & CRT2IsVGA) return; + } + + switch(DisplayType) { + case 0 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_1; break; + case 1 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_1; break; + case 2 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_1; break; + case 3 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_1_H; break; + case 4 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_1_H; break; + case 5 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_1_H; break; + case 6 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_2; break; + case 7 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_2; break; + case 8 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_2; break; + case 9 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_2_H; break; + case 10: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_2_H; break; + case 11: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_2_H; break; + case 12: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1XXXxXXX_1; break; + case 13: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1XXXxXXX_1_H; break; + case 14: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_1; break; + case 15: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_1_H; break; + case 16: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_2; break; + case 17: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_2_H; break; + case 18: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UNTSC; break; + case 19: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1ONTSC; break; + case 20: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UPAL; break; + case 21: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1OPAL; break; + case 22: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x480_1; break; /* FSTN */ + case 23: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1; break; + case 24: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1_H; break; + case 25: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2; break; + case 26: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2_H; break; + case 27: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11152x768_1; break; + case 28: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11152x768_1_H; break; + case 29: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11152x768_2; break; + case 30: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11152x768_2_H; break; + case 36: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11600x1200_1; break; + case 37: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11600x1200_1_H; break; + case 38: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11600x1200_2; break; + case 39: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11600x1200_2_H; break; + case 99: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1SOPAL; break; + default: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_1; break; + } + + SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f); /*unlock cr0-7 */ + + tempah = (LVDSCRT1Ptr+ResInfo)->CR[0]; + SiS_SetReg1(SiS_Pr->SiS_P3d4,0x00,tempah); + + for(i=0x02,j=1;i<=0x05;i++,j++){ + tempah = (LVDSCRT1Ptr+ResInfo)->CR[j]; + SiS_SetReg1(SiS_Pr->SiS_P3d4,i,tempah); + } + for(i=0x06,j=5;i<=0x07;i++,j++){ + tempah = (LVDSCRT1Ptr+ResInfo)->CR[j]; + SiS_SetReg1(SiS_Pr->SiS_P3d4,i,tempah); + } + for(i=0x10,j=7;i<=0x11;i++,j++){ + tempah = (LVDSCRT1Ptr+ResInfo)->CR[j]; + SiS_SetReg1(SiS_Pr->SiS_P3d4,i,tempah); + } + for(i=0x15,j=9;i<=0x16;i++,j++){ + tempah = (LVDSCRT1Ptr+ResInfo)->CR[j]; + SiS_SetReg1(SiS_Pr->SiS_P3d4,i,tempah); + } + for(i=0x0A,j=11;i<=0x0C;i++,j++){ + tempah = (LVDSCRT1Ptr+ResInfo)->CR[j]; + SiS_SetReg1(SiS_Pr->SiS_P3c4,i,tempah); + } + + tempah = (LVDSCRT1Ptr+ResInfo)->CR[14]; + tempah &= 0xE0; + SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0x1f,tempah); /* TW: Modfied (650/LVDS); Was SetReg(tempah) */ + + tempah = (LVDSCRT1Ptr+ResInfo)->CR[14]; + tempah &= 0x01; + tempah <<= 5; + if(modeflag & DoubleScanMode){ + tempah |= 0x080; + } + SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,~0x020,tempah); + + /* TW: Inserted from 650/LVDS BIOS */ + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + if(modeflag & HalfDCLK) + SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f); + } + + return; +} + +#if 0 /* TW: Unused */ +/*301b*/ +void +SiS_CHACRT1CRTC(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex) +{ + USHORT temp,tempah,i,modeflag,j; + USHORT ResInfo,DisplayType; + SiS_LVDSCRT1DataStruct *LVDSCRT1Ptr=NULL; + + if(ModeNo<=0x13) { + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; /* si+St_ResInfo */ + } else { + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; /* si+Ext_ResInfo */ + } + + temp=SiS_GetLVDSCRT1Ptr(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, + &ResInfo,&DisplayType); + if(temp==0){ + return; + } + + switch(DisplayType) { + case 0 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_1; break; + case 1 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_1; break; + case 2 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_1; break; + case 3 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_1_H; break; + case 4 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_1_H; break; + case 5 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_1_H; break; + case 6 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_2; break; + case 7 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_2; break; + case 8 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_2; break; + case 9 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_2_H; break; + case 10: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_2_H; break; + case 11: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_2_H; break; + case 12: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1XXXxXXX_1; break; + case 13: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1XXXxXXX_1_H; break; + case 14: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_1; break; + case 15: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_1_H; break; + case 16: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_2; break; + case 17: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_2_H; break; + case 18: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UNTSC; break; + case 19: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1ONTSC; break; + case 20: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UPAL; break; + case 21: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1OPAL; break; + case 22: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x480_1; break; /* FSTN */ + case 99: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1OPAL; break; + } + + tempah=(UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3d4,0x11); /*unlock cr0-7 */ + tempah=tempah&0x7F; + SiS_SetReg1(SiS_Pr->SiS_P3d4,0x11,tempah); + tempah = (LVDSCRT1Ptr+ResInfo)->CR[0]; + SiS_SetReg1(SiS_Pr->SiS_P3d4,0x0,tempah); + for(i=0x02,j=1;i<=0x05;i++,j++){ + tempah = (LVDSCRT1Ptr+ResInfo)->CR[j]; + SiS_SetReg1(SiS_Pr->SiS_P3d4,i,tempah); + } + for(i=0x06,j=5;i<=0x07;i++,j++){ + tempah = (LVDSCRT1Ptr+ResInfo)->CR[j]; + SiS_SetReg1(SiS_Pr->SiS_P3d4,i,tempah); + } + for(i=0x10,j=7;i<=0x11;i++,j++){ + tempah = (LVDSCRT1Ptr+ResInfo)->CR[j]; + SiS_SetReg1(SiS_Pr->SiS_P3d4,i,tempah); + } + for(i=0x15,j=9;i<=0x16;i++,j++){ + tempah = (LVDSCRT1Ptr+ResInfo)->CR[j]; + SiS_SetReg1(SiS_Pr->SiS_P3d4,i,tempah); + } + + for(i=0x0A,j=11;i<=0x0C;i++,j++){ + tempah = (LVDSCRT1Ptr+ResInfo)->CR[j]; + SiS_SetReg1(SiS_Pr->SiS_P3c4,i,tempah); + } + + tempah = (LVDSCRT1Ptr+ResInfo)->CR[14]; + tempah=tempah&0x0E0; + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x0E,tempah); + + tempah = (LVDSCRT1Ptr+ResInfo)->CR[14]; + tempah=tempah&0x01; + tempah=tempah<<5; + if(modeflag&DoubleScanMode){ + tempah=tempah|0x080; + } + SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,~0x020,tempah); + return; +} +#endif + +/* TW: Checked against 650/LVDS BIOS: modified for new panel resolutions */ +BOOLEAN +SiS_GetLVDSCRT1Ptr(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,USHORT *ResInfo, + USHORT *DisplayType) + { + USHORT tempbx,modeflag=0; + USHORT Flag,CRT2CRTC; + + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { + /* TW: Inserted from 650/LVDS BIOS */ + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { + if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return 0; + } + } + + if(ModeNo <= 0x13) { + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + CRT2CRTC = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; + } else { + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + CRT2CRTC = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; + } + + Flag = 1; + tempbx = 0; + if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) { + Flag = 0; + tempbx = 18; + if(SiS_Pr->SiS_VBInfo & SetCHTVOverScan) tempbx++; + if(SiS_Pr->SiS_VBInfo & SetPALTV) { + tempbx += 2; + if(SiS_Pr->SiS_CHSOverScan) tempbx = 99; + if(SiS_Pr->SiS_CHPALM) { + tempbx = 18; /* PALM uses NTSC data */ + if(SiS_Pr->SiS_VBInfo & SetCHTVOverScan) tempbx++; + } else if(SiS_Pr->SiS_CHPALN) { + tempbx = 20; /* PALN uses PAL data */ + if(SiS_Pr->SiS_VBInfo & SetCHTVOverScan) tempbx++; + } + } + } + } + if(Flag) { + tempbx = SiS_Pr->SiS_LCDResInfo; + tempbx -= SiS_Pr->SiS_PanelMinLVDS; + if(SiS_Pr->SiS_LCDResInfo <= SiS_Pr->SiS_Panel1280x1024) { + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx += 6; + if(modeflag & HalfDCLK) tempbx += 3; + } else { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) { + tempbx = 14; + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx += 2; + if(modeflag & HalfDCLK) tempbx++; + } else if(SiS_Pr->SiS_LCDInfo & LCDPass11) { + tempbx = 12; + if(modeflag & HalfDCLK) tempbx++; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x600) { + tempbx = 23; + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx += 2; + if(modeflag & HalfDCLK) tempbx++; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1152x768) { + tempbx = 27; + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx += 2; + if(modeflag & HalfDCLK) tempbx++; + } else if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1600x1200) { + tempbx = 36; + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx += 2; + if(modeflag & HalfDCLK) tempbx++; + } + } + } + if(SiS_Pr->SiS_IF_DEF_FSTN){ + if(SiS_Pr->SiS_LCDResInfo==SiS_Pr->SiS_Panel320x480){ + tempbx=22; + } + } + *ResInfo = CRT2CRTC & 0x3F; + *DisplayType = tempbx; + return 1; +} + +/* TW: Checked against 650/LVDS (1.10a, 1.10.07), 630/301B (I/II) and 630/LVDS BIOS */ +void +SiS_SetCRT2ECLK(SiS_Private *SiS_Pr, UCHAR *ROMAddr, USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT tempah,tempal,pushax; + USHORT vclkindex=0; + + if(HwDeviceExtension->jChipType < SIS_315H) { + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) return; + } + } + + if((SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel640x480) || (SiS_Pr->SiS_IF_DEF_TRUMPION == 1)) { + SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2); + tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK; + tempal &= 0x3F; + if(tempal == 2) RefreshRateTableIndex--; + vclkindex = SiS_GetVCLK2Ptr(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex, + RefreshRateTableIndex,HwDeviceExtension); + SiS_Pr->SiS_SetFlag |= ProgrammingCRT2; + } else { + vclkindex = SiS_GetVCLK2Ptr(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex, + RefreshRateTableIndex,HwDeviceExtension); + } + + tempal = 0x02B; + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { + if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { + tempal += 3; + } + } + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x05,0x86); + pushax = tempal; + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x31,0x20); + tempah = SiS_Pr->SiS_VCLKData[vclkindex].SR2B; + SiS_SetReg1(SiS_Pr->SiS_P3c4,tempal,tempah); + tempal++; + tempah = SiS_Pr->SiS_VCLKData[vclkindex].SR2C; + SiS_SetReg1(SiS_Pr->SiS_P3c4,tempal,tempah); + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x31,0x10); + tempal = pushax; + tempah = SiS_Pr->SiS_VCLKData[vclkindex].SR2B; + SiS_SetReg1(SiS_Pr->SiS_P3c4,tempal,tempah); + tempal++; + tempah = SiS_Pr->SiS_VCLKData[vclkindex].SR2C; + SiS_SetReg1(SiS_Pr->SiS_P3c4,tempal,tempah); + SiS_SetReg1(SiS_Pr->SiS_P3c4,0x31,0x00); + tempal = pushax; + tempah = SiS_Pr->SiS_VCLKData[vclkindex].SR2B; + SiS_SetReg1(SiS_Pr->SiS_P3c4,tempal,tempah); + tempal++; + tempah = SiS_Pr->SiS_VCLKData[vclkindex].SR2C; + SiS_SetReg1(SiS_Pr->SiS_P3c4,tempal,tempah); + return; +} + +#if 0 /* TW: Not used */ +void +SiS_SetDefCRT2ExtRegs(SiS_Private *SiS_Pr, USHORT BaseAddr) +{ + USHORT temp; + + if(SiS_Pr->SiS_IF_DEF_LVDS==0) { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x02,0x40); + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x10,0x80); + temp=(UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x16); + temp &= 0xC3; + SiS_SetReg1(SiS_Pr->SiS_P3d4,0x35,temp); + } else { + SiS_SetReg1(SiS_Pr->SiS_P3d4,0x32,0x02); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x02,0x00); + } +} +#endif + +/* TW: Start of Chrontel 70xx functions ---------------------- */ + +/* Set-up the Chrontel Registers */ +void +SiS_SetCHTVReg(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex) +{ + USHORT temp, tempbx, tempcl; + USHORT TVType, resindex; + const SiS_CHTVRegDataStruct *CHTVRegData = NULL; + + if(ModeNo <= 0x13) + tempcl = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; + else + tempcl = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; + + TVType = 0; + if(SiS_Pr->SiS_VBInfo & SetCHTVOverScan) TVType += 1; + if(SiS_Pr->SiS_VBInfo & SetPALTV) { + TVType += 2; + if(SiS_Pr->SiS_CHSOverScan) TVType = 8; + if(SiS_Pr->SiS_CHPALM) { + TVType = 4; + if(SiS_Pr->SiS_VBInfo & SetCHTVOverScan) TVType += 1; + } else if(SiS_Pr->SiS_CHPALN) { + TVType = 6; + if(SiS_Pr->SiS_VBInfo & SetCHTVOverScan) TVType += 1; + } + } + switch(TVType) { + case 0: CHTVRegData = SiS_Pr->SiS_CHTVReg_UNTSC; break; + case 1: CHTVRegData = SiS_Pr->SiS_CHTVReg_ONTSC; break; + case 2: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPAL; break; + case 3: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break; + case 4: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALM; break; + case 5: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALM; break; + case 6: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALN; break; + case 7: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALN; break; + case 8: CHTVRegData = SiS_Pr->SiS_CHTVReg_SOPAL; break; + default: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break; + } + resindex = tempcl & 0x3F; + + if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) { + + /* Chrontel 7005 */ + + /* TW: We don't support modes >800x600 */ + if (resindex > 5) return; + + if(SiS_Pr->SiS_VBInfo & SetPALTV) { + SiS_SetCH700x(SiS_Pr,0x4304); /* TW: 0x40=76uA (PAL); 0x03=15bit non-multi RGB*/ + SiS_SetCH700x(SiS_Pr,0x6909); /* TW: Black level for PAL (105)*/ + } else { + SiS_SetCH700x(SiS_Pr,0x0304); /* TW: upper nibble=71uA (NTSC), 0x03=15bit non-multi RGB*/ + SiS_SetCH700x(SiS_Pr,0x7109); /* TW: Black level for NTSC (113)*/ + } + + temp = CHTVRegData[resindex].Reg[0]; + tempbx=((temp&0x00FF)<<8)|0x00; /* TW: Mode register */ + SiS_SetCH700x(SiS_Pr,tempbx); + temp = CHTVRegData[resindex].Reg[1]; + tempbx=((temp&0x00FF)<<8)|0x07; /* TW: Start active video register */ + SiS_SetCH700x(SiS_Pr,tempbx); + temp = CHTVRegData[resindex].Reg[2]; + tempbx=((temp&0x00FF)<<8)|0x08; /* TW: Position overflow register */ + SiS_SetCH700x(SiS_Pr,tempbx); + temp = CHTVRegData[resindex].Reg[3]; + tempbx=((temp&0x00FF)<<8)|0x0A; /* TW: Horiz Position register */ + SiS_SetCH700x(SiS_Pr,tempbx); + temp = CHTVRegData[resindex].Reg[4]; + tempbx=((temp&0x00FF)<<8)|0x0B; /* TW: Vertical Position register */ + SiS_SetCH700x(SiS_Pr,tempbx); + + /* TW: Set minimum flicker filter for Luma channel (SR1-0=00), + minimum text enhancement (S3-2=10), + maximum flicker filter for Chroma channel (S5-4=10) + =00101000=0x28 (When reading, S1-0->S3-2, and S3-2->S1-0!) + */ + SiS_SetCH700x(SiS_Pr,0x2801); + + /* TW: Set video bandwidth + High bandwith Luma composite video filter(S0=1) + low bandwith Luma S-video filter (S2-1=00) + disable peak filter in S-video channel (S3=0) + high bandwidth Chroma Filter (S5-4=11) + =00110001=0x31 + */ + SiS_SetCH700x(SiS_Pr,0xb103); /* old: 3103 */ + + /* TW: Register 0x3D does not exist in non-macrovision register map + (Maybe this is a macrovision register?) + */ + /* SiS_SetCH70xx(SiS_Pr,0x003D); */ + + /* TW: Register 0x10 only contains 1 writable bit (S0) for sensing, + all other bits a read-only. Macrovision? + */ + SiS_SetCH70xxANDOR(SiS_Pr,0x0010,0x1F); + + /* TW: Register 0x11 only contains 3 writable bits (S0-S2) for + contrast enhancement (set to 010 -> gain 1 Yout = 17/16*(Yin-30) ) + */ + SiS_SetCH70xxANDOR(SiS_Pr,0x0211,0xF8); + + /* TW: Clear DSEN + */ + SiS_SetCH70xxANDOR(SiS_Pr,0x001C,0xEF); + + if(!(SiS_Pr->SiS_VBInfo & SetPALTV)) { /* ---- NTSC ---- */ + if(SiS_Pr->SiS_VBInfo & SetCHTVOverScan) { + if(resindex == 0x04) { /* 640x480 overscan: Mode 16 */ + SiS_SetCH70xxANDOR(SiS_Pr,0x0020,0xEF); /* loop filter off */ + SiS_SetCH70xxANDOR(SiS_Pr,0x0121,0xFE); /* ACIV on, no need to set FSCI */ + } else { + if(resindex == 0x05) { /* 800x600 overscan: Mode 23 */ + SiS_SetCH70xxANDOR(SiS_Pr,0x0118,0xF0); /* 0x18-0x1f: FSCI 469,762,048 */ + SiS_SetCH70xxANDOR(SiS_Pr,0x0C19,0xF0); + SiS_SetCH70xxANDOR(SiS_Pr,0x001A,0xF0); + SiS_SetCH70xxANDOR(SiS_Pr,0x001B,0xF0); + SiS_SetCH70xxANDOR(SiS_Pr,0x001C,0xF0); + SiS_SetCH70xxANDOR(SiS_Pr,0x001D,0xF0); + SiS_SetCH70xxANDOR(SiS_Pr,0x001E,0xF0); + SiS_SetCH70xxANDOR(SiS_Pr,0x001F,0xF0); + SiS_SetCH70xxANDOR(SiS_Pr,0x0120,0xEF); /* Loop filter on for mode 23 */ + SiS_SetCH70xxANDOR(SiS_Pr,0x0021,0xFE); /* ACIV off, need to set FSCI */ + } + } + } else { + if(resindex == 0x04) { /* ----- 640x480 underscan; Mode 17 */ + SiS_SetCH70xxANDOR(SiS_Pr,0x0020,0xEF); /* loop filter off */ + SiS_SetCH70xxANDOR(SiS_Pr,0x0121,0xFE); + } else { + if(resindex == 0x05) { /* ----- 800x600 underscan: Mode 24 */ + SiS_SetCH70xxANDOR(SiS_Pr,0x0118,0xF0); /* (FSCI was 0x1f1c71c7 - this is for mode 22) */ + SiS_SetCH70xxANDOR(SiS_Pr,0x0919,0xF0); /* FSCI for mode 24 is 428,554,851 */ + SiS_SetCH70xxANDOR(SiS_Pr,0x081A,0xF0); + SiS_SetCH70xxANDOR(SiS_Pr,0x0b1B,0xF0); + SiS_SetCH70xxANDOR(SiS_Pr,0x031C,0xF0); + SiS_SetCH70xxANDOR(SiS_Pr,0x0a1D,0xF0); + SiS_SetCH70xxANDOR(SiS_Pr,0x061E,0xF0); + SiS_SetCH70xxANDOR(SiS_Pr,0x031F,0xF0); + SiS_SetCH70xxANDOR(SiS_Pr,0x0020,0xEF); /* loop filter off for mode 24 */ + SiS_SetCH70xxANDOR(SiS_Pr,0x0021,0xFE); /* ACIV off, need to set FSCI */ + } + } + } + } else { /* ---- PAL ---- */ + /* TW: We don't play around with FSCI in PAL mode */ + if (resindex == 0x04) { + SiS_SetCH70xxANDOR(SiS_Pr,0x0020,0xEF); /* loop filter off */ + SiS_SetCH70xxANDOR(SiS_Pr,0x0121,0xFE); /* ACIV on */ + } else { + SiS_SetCH70xxANDOR(SiS_Pr,0x0020,0xEF); /* loop filter off */ + SiS_SetCH70xxANDOR(SiS_Pr,0x0121,0xFE); /* ACIV on */ + } + } + + } else { + + /* Chrontel 7019 */ + + /* TW: We don't support modes >1024x768 */ + if (resindex > 6) return; + + temp = CHTVRegData[resindex].Reg[0]; + tempbx=((temp & 0x00FF) <<8 ) | 0x00; + SiS_SetCH701x(SiS_Pr,tempbx); + + temp = CHTVRegData[resindex].Reg[1]; + tempbx=((temp & 0x00FF) <<8 ) | 0x01; + SiS_SetCH701x(SiS_Pr,tempbx); + + temp = CHTVRegData[resindex].Reg[2]; + tempbx=((temp & 0x00FF) <<8 ) | 0x02; + SiS_SetCH701x(SiS_Pr,tempbx); + + temp = CHTVRegData[resindex].Reg[3]; + tempbx=((temp & 0x00FF) <<8 ) | 0x04; + SiS_SetCH701x(SiS_Pr,tempbx); + + temp = CHTVRegData[resindex].Reg[4]; + tempbx=((temp & 0x00FF) <<8 ) | 0x03; + SiS_SetCH701x(SiS_Pr,tempbx); + + temp = CHTVRegData[resindex].Reg[5]; + tempbx=((temp & 0x00FF) <<8 ) | 0x05; + SiS_SetCH701x(SiS_Pr,tempbx); + + temp = CHTVRegData[resindex].Reg[6]; + tempbx=((temp & 0x00FF) <<8 ) | 0x06; + SiS_SetCH701x(SiS_Pr,tempbx); + + temp = CHTVRegData[resindex].Reg[7]; + tempbx=((temp & 0x00FF) <<8 ) | 0x07; + SiS_SetCH701x(SiS_Pr,tempbx); + + temp = CHTVRegData[resindex].Reg[8]; + tempbx=((temp & 0x00FF) <<8 ) | 0x08; + SiS_SetCH701x(SiS_Pr,tempbx); + + temp = CHTVRegData[resindex].Reg[9]; + tempbx=((temp & 0x00FF) <<8 ) | 0x15; + SiS_SetCH701x(SiS_Pr,tempbx); + + temp = CHTVRegData[resindex].Reg[10]; + tempbx=((temp & 0x00FF) <<8 ) | 0x1f; + SiS_SetCH701x(SiS_Pr,tempbx); + + temp = CHTVRegData[resindex].Reg[11]; + tempbx=((temp & 0x00FF) <<8 ) | 0x0c; + SiS_SetCH701x(SiS_Pr,tempbx); + + temp = CHTVRegData[resindex].Reg[12]; + tempbx=((temp & 0x00FF) <<8 ) | 0x0d; + SiS_SetCH701x(SiS_Pr,tempbx); + + temp = CHTVRegData[resindex].Reg[13]; + tempbx=((temp & 0x00FF) <<8 ) | 0x0e; + SiS_SetCH701x(SiS_Pr,tempbx); + + temp = CHTVRegData[resindex].Reg[14]; + tempbx=((temp & 0x00FF) <<8 ) | 0x0f; + SiS_SetCH701x(SiS_Pr,tempbx); + + temp = CHTVRegData[resindex].Reg[15]; + tempbx=((temp & 0x00FF) <<8 ) | 0x10; + SiS_SetCH701x(SiS_Pr,tempbx); + + } +} + +/* TW: Chrontel 701x functions ================================= */ + +void +SiS_SetCH701xForLCD(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr) +{ + UCHAR regtable[] = { 0x1c, 0x5f, 0x64, 0x6f, 0x70, 0x71, + 0x72, 0x73, 0x74, 0x76, 0x78, 0x7d }; + UCHAR table1024[] = { 0x60, 0x02, 0x00, 0x07, 0x40, 0xed, + 0xa3, 0xc8, 0xc7, 0xac, 0x60, 0x02 }; + UCHAR table1400[] = { 0x60, 0x03, 0x11, 0x00, 0x40, 0xef, + 0xad, 0xdb, 0xf6, 0xac, 0x60, 0x02 }; + UCHAR *tableptr = NULL; + USHORT tempbh; + int i; + + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) { + tableptr = table1400; + } else { + tableptr = table1024; + } + tempbh = SiS_GetCH701x(SiS_Pr,0x74); + if((tempbh == 0xf6) || (tempbh == 0xc7)) { + tempbh = SiS_GetCH701x(SiS_Pr,0x73); + if(tempbh == 0xc8) { + if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel1400x1050) return; + } else if(tempbh == 0xdb) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) return; + } + } + for(i=0; i<0x0c; i++) { + SiS_SetCH701x(SiS_Pr,(tableptr[i] << 8) | regtable[i]); + } + SiS_ChrontelPowerSequencing(SiS_Pr); + tempbh = SiS_GetCH701x(SiS_Pr,0x1e); + tempbh |= 0xc0; + SiS_SetCH701x(SiS_Pr,(tempbh << 8) | 0x1e); +} + +void +SiS_ChrontelPowerSequencing(SiS_Private *SiS_Pr) +{ + UCHAR regtable[] = { 0x67, 0x68, 0x69, 0x6a, 0x6b }; + UCHAR table1024[] = { 0x01, 0x02, 0x01, 0x01, 0x02 }; + UCHAR table1400[] = { 0x01, 0x02, 0x01, 0x01, 0x02 }; + UCHAR *tableptr = NULL; + int i; + + /* Set up Power up/down timing */ + + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) { + tableptr = table1400; + } else { + tableptr = table1024; + } + + for(i=0; i<5; i++) { + SiS_SetCH701x(SiS_Pr,(tableptr[i] << 8) | regtable[i]); + } +} + +void +SiS_Chrontel701xBLOn(SiS_Private *SiS_Pr) +{ + USHORT temp; + + /* TW: Enable Chrontel 7019 LCD panel backlight */ + if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { + temp = SiS_GetCH701x(SiS_Pr,0x66); + temp |= 0x20; + SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x66); + } +} + +void +SiS_Chrontel701xOn(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr) +{ + USHORT temp; + + if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { + if(SiS_IsYPbPr(SiS_Pr,HwDeviceExtension, BaseAddr)) { + temp = SiS_GetCH701x(SiS_Pr,0x01); + temp &= 0x3f; + temp |= 0x80; /* TW: Enable YPrPb (HDTV) */ + SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x01); + } + if(SiS_IsChScart(SiS_Pr,HwDeviceExtension, BaseAddr)) { + temp = SiS_GetCH701x(SiS_Pr,0x01); + temp &= 0x3f; + temp |= 0xc0; /* TW: Enable SCART + CVBS */ + SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x01); + } + SiS_SetCH701x(SiS_Pr,0x2049); /* TW: Enable TV path */ + temp = SiS_GetCH701x(SiS_Pr,0x49); + if(SiS_IsYPbPr(SiS_Pr,HwDeviceExtension, BaseAddr)) { + temp = SiS_GetCH701x(SiS_Pr,0x73); + temp |= 0x60; + SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x73); + } + temp = SiS_GetCH701x(SiS_Pr,0x47); + temp &= 0x7f; + SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x47); + SiS_LongDelay(SiS_Pr,2); + temp = SiS_GetCH701x(SiS_Pr,0x47); + temp |= 0x80; + SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x47); + } +} + +void +SiS_Chrontel701xBLOff(SiS_Private *SiS_Pr) +{ + USHORT temp; + + /* TW: Disable Chrontel 7019 LCD panel backlight */ + if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { + temp = SiS_GetCH701x(SiS_Pr,0x66); + temp &= 0xDF; + SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x66); + } +} + +void +SiS_Chrontel701xOff(SiS_Private *SiS_Pr) +{ + USHORT temp; + + if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { + SiS_LongDelay(SiS_Pr,2); + /* TW: Complete power down of LVDS */ + temp = SiS_GetCH701x(SiS_Pr,0x76); + temp &= 0xfc; + SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x76); + SiS_SetCH701x(SiS_Pr,0x0066); + } +} + +void +SiS_ChrontelResetDB(SiS_Private *SiS_Pr) +{ + /* TW: Reset Chrontel 7019 datapath */ + SiS_SetCH701x(SiS_Pr,0x1048); + SiS_LongDelay(SiS_Pr,1); + SiS_SetCH701x(SiS_Pr,0x1848); +} + +void +SiS_ChrontelDoSomething4(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr) +{ + USHORT temp; + + SiS_SetCH701x(SiS_Pr,0xaf76); /* Power up LVDS block */ + temp = SiS_GetCH701x(SiS_Pr,0x49); + temp &= 1; + if(temp != 1) { /* TV block powered? (0 = yes, 1 = no) */ + temp = SiS_GetCH701x(SiS_Pr,0x47); + temp &= 0x70; + SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x47); /* enable VSYNC */ + SiS_LongDelay(SiS_Pr,3); + temp = SiS_GetCH701x(SiS_Pr,0x47); + temp |= 0x80; + SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x47); /* disable VSYNC */ + } +} + +void +SiS_ChrontelDoSomething3(SiS_Private *SiS_Pr, USHORT ModeNo, PSIS_HW_DEVICE_INFO HwDeviceExtension, + USHORT BaseAddr) +{ + USHORT temp,temp1; + + temp1 = 0; + temp = SiS_GetCH701x(SiS_Pr,0x61); + if(temp < 2) { + temp++; + SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x61); + temp1 = 1; + } + SiS_SetCH701x(SiS_Pr,0xac76); + temp = SiS_GetCH701x(SiS_Pr,0x66); + temp |= 0x5f; + SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x66); + if(ModeNo > 0x13) { + if(SiS_WeHaveBacklightCtrl(SiS_Pr,HwDeviceExtension, BaseAddr)) { + SiS_GenericDelay(SiS_Pr,0x3ff); + } else { + SiS_GenericDelay(SiS_Pr,0x2ff); + } + } else { + if(!temp1) + SiS_GenericDelay(SiS_Pr,0x2ff); + } + temp = SiS_GetCH701x(SiS_Pr,0x76); + temp |= 0x03; + SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x76); + temp = SiS_GetCH701x(SiS_Pr,0x66); + temp &= 0x7f; + SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x66); + SiS_LongDelay(SiS_Pr,1); +} + +void +SiS_ChrontelDoSomething2(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr) +{ + USHORT temp,tempcl,tempch; + + SiS_LongDelay(SiS_Pr, 1); + tempcl = 3; + tempch = 0; + + do { + temp = SiS_GetCH701x(SiS_Pr,0x66); + temp &= 0x04; + if(temp == 0x04) break; + + SiS_SetCH701xForLCD(SiS_Pr,HwDeviceExtension,BaseAddr); + + if(tempcl == 0) { + if(tempch == 3) break; + SiS_ChrontelResetDB(SiS_Pr); + tempcl = 3; + tempch++; + } + tempcl--; + temp = SiS_GetCH701x(SiS_Pr,0x76); + temp &= 0xfb; + SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x76); + SiS_LongDelay(SiS_Pr,2); + temp = SiS_GetCH701x(SiS_Pr,0x76); + temp |= 0x04; + SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x76); + SiS_SetCH701x(SiS_Pr,0x6078); + SiS_LongDelay(SiS_Pr,2); + } while(0); + + SiS_SetCH701x(SiS_Pr,0x0077); +} + +void +SiS_ChrontelDoSomething1(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, + USHORT BaseAddr) +{ + USHORT temp; + + temp = SiS_GetCH701x(SiS_Pr,0x03); + temp |= 0x80; /* Set datapath 1 to TV */ + temp &= 0xbf; /* Set datapath 2 to LVDS */ + SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x03); + + SiS_ChrontelResetDB(SiS_Pr); + + SiS_ChrontelDoSomething2(SiS_Pr,HwDeviceExtension,BaseAddr); + + temp = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x34); + SiS_ChrontelDoSomething3(SiS_Pr,temp,HwDeviceExtension,BaseAddr); + + SiS_SetCH701x(SiS_Pr,0xaf76); +} + +/* TW: End of Chrontel 701x functions ==================================== */ + +/* TW: Generic Read/write routines for Chrontel ========================== */ + +/* TW: The Chrontel is connected to the 630/730 via + * the 630/730's DDC/I2C port. + * + * On 630(S)T chipset, the index changed from 0x11 to 0x0a, + * possibly for working around the DDC problems + */ + +void +SiS_SetCH70xx(SiS_Private *SiS_Pr, USHORT tempbx) +{ + if (SiS_Pr->SiS_IF_DEF_CH70xx == 1) + SiS_SetCH700x(SiS_Pr,tempbx); + else + SiS_SetCH701x(SiS_Pr,tempbx); +} + +/* TW: Write to Chrontel 700x */ +/* Parameter is [Data (S15-S8) | Register no (S7-S0)] */ +void +SiS_SetCH700x(SiS_Private *SiS_Pr, USHORT tempbx) +{ + USHORT tempah,temp,i; + + if(!(SiS_Pr->SiS_ChrontelInit)) { + SiS_Pr->SiS_DDC_Index = 0x11; /* TW: Bit 0 = SC; Bit 1 = SD */ + SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */ + SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */ + SiS_Pr->SiS_DDC_DataShift = 0x00; + SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* TW: DAB (Device Address Byte) */ + } + + for(i=0;i<10;i++) { /* TW: Do only 10 attempts to write */ + /* SiS_SetSwitchDDC2(SiS_Pr); */ + if(SiS_SetStart(SiS_Pr)) continue; /* TW: Set start condition */ + tempah = SiS_Pr->SiS_DDC_DeviceAddr; + temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* TW: Write DAB (S0=0=write) */ + if(temp) continue; /* TW: (ERROR: no ack) */ + tempah = tempbx & 0x00FF; /* TW: Write RAB */ + tempah |= 0x80; /* TW: (set bit 7, see datasheet) */ + temp = SiS_WriteDDC2Data(SiS_Pr,tempah); + if(temp) continue; /* TW: (ERROR: no ack) */ + tempah = (tempbx & 0xFF00) >> 8; + temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* TW: Write data */ + if(temp) continue; /* TW: (ERROR: no ack) */ + if(SiS_SetStop(SiS_Pr)) continue; /* TW: Set stop condition */ + SiS_Pr->SiS_ChrontelInit = 1; + return; + } + + /* TW: For 630ST */ + if(!(SiS_Pr->SiS_ChrontelInit)) { + SiS_Pr->SiS_DDC_Index = 0x0a; /* TW: Bit 7 = SC; Bit 6 = SD */ + SiS_Pr->SiS_DDC_Data = 0x80; /* Bitmask in IndexReg for Data */ + SiS_Pr->SiS_DDC_Clk = 0x40; /* Bitmask in IndexReg for Clk */ + SiS_Pr->SiS_DDC_DataShift = 0x00; + SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* TW: DAB (Device Address Byte) */ + + for(i=0;i<10;i++) { /* TW: Do only 10 attempts to write */ + /* SiS_SetSwitchDDC2(SiS_Pr); */ + if (SiS_SetStart(SiS_Pr)) continue; /* TW: Set start condition */ + tempah = SiS_Pr->SiS_DDC_DeviceAddr; + temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* TW: Write DAB (S0=0=write) */ + if(temp) continue; /* TW: (ERROR: no ack) */ + tempah = tempbx & 0x00FF; /* TW: Write RAB */ + tempah |= 0x80; /* TW: (set bit 7, see datasheet) */ + temp = SiS_WriteDDC2Data(SiS_Pr,tempah); + if(temp) continue; /* TW: (ERROR: no ack) */ + tempah = (tempbx & 0xFF00) >> 8; + temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* TW: Write data */ + if(temp) continue; /* TW: (ERROR: no ack) */ + if(SiS_SetStop(SiS_Pr)) continue; /* TW: Set stop condition */ + SiS_Pr->SiS_ChrontelInit = 1; + return; + } + } +} + +/* TW: Write to Chrontel 701x */ +/* Parameter is [Data (S15-S8) | Register no (S7-S0)] */ +void +SiS_SetCH701x(SiS_Private *SiS_Pr, USHORT tempbx) +{ + USHORT tempah,temp,i; + + SiS_Pr->SiS_DDC_Index = 0x11; /* TW: Bit 0 = SC; Bit 1 = SD */ + SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */ + SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */ + SiS_Pr->SiS_DDC_DataShift = 0x00; + SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* TW: DAB (Device Address Byte) */ + + for(i=0;i<10;i++) { /* TW: Do only 10 attempts to write */ + if (SiS_SetStart(SiS_Pr)) continue; /* TW: Set start condition */ + tempah = SiS_Pr->SiS_DDC_DeviceAddr; + temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* TW: Write DAB (S0=0=write) */ + if(temp) continue; /* TW: (ERROR: no ack) */ + tempah = tempbx & 0x00FF; + temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* TW: Write RAB */ + if(temp) continue; /* TW: (ERROR: no ack) */ + tempah = (tempbx & 0xFF00) >> 8; + temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* TW: Write data */ + if(temp) continue; /* TW: (ERROR: no ack) */ + if(SiS_SetStop(SiS_Pr)) continue; /* TW: Set stop condition */ + return; + } +} + +/* TW: Read from Chrontel 70xx */ +/* Parameter is [Register no (S7-S0)] */ +USHORT +SiS_GetCH70xx(SiS_Private *SiS_Pr, USHORT tempbx) +{ + if (SiS_Pr->SiS_IF_DEF_CH70xx == 1) + return(SiS_GetCH700x(SiS_Pr,tempbx)); + else + return(SiS_GetCH701x(SiS_Pr,tempbx)); +} + +/* TW: Read from Chrontel 700x */ +/* Parameter is [Register no (S7-S0)] */ +USHORT +SiS_GetCH700x(SiS_Private *SiS_Pr, USHORT tempbx) +{ + USHORT tempah,temp,i; + + if(!(SiS_Pr->SiS_ChrontelInit)) { + SiS_Pr->SiS_DDC_Index = 0x11; /* TW: Bit 0 = SC; Bit 1 = SD */ + SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */ + SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */ + SiS_Pr->SiS_DDC_DataShift = 0x00; + SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* TW: DAB */ + } + + SiS_Pr->SiS_DDC_ReadAddr = tempbx; + + for(i=0;i<20;i++) { /* TW: Do only 20 attempts to read */ + /* SiS_SetSwitchDDC2(SiS_Pr); */ + if(SiS_SetStart(SiS_Pr)) continue; /* TW: Set start condition */ + tempah = SiS_Pr->SiS_DDC_DeviceAddr; + temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* TW: Write DAB (S0=0=write) */ + if(temp) continue; /* TW: (ERROR: no ack) */ + tempah = SiS_Pr->SiS_DDC_ReadAddr | 0x80; /* TW: Write RAB | 0x80 */ + temp = SiS_WriteDDC2Data(SiS_Pr,tempah); + if(temp) continue; /* TW: (ERROR: no ack) */ + if (SiS_SetStart(SiS_Pr)) continue; /* TW: Re-start */ + tempah = SiS_Pr->SiS_DDC_DeviceAddr | 0x01; /* DAB | 0x01 = Read */ + temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* TW: DAB (S0=1=read) */ + if(temp) continue; /* TW: (ERROR: no ack) */ + tempah = SiS_ReadDDC2Data(SiS_Pr,tempah); /* TW: Read byte */ + if (SiS_SetStop(SiS_Pr)) continue; /* TW: Stop condition */ + SiS_Pr->SiS_ChrontelInit = 1; + return(tempah); + } + + /* TW: For 630ST */ + if(!SiS_Pr->SiS_ChrontelInit) { + SiS_Pr->SiS_DDC_Index = 0x0a; /* TW: Bit 0 = SC; Bit 1 = SD */ + SiS_Pr->SiS_DDC_Data = 0x80; /* Bitmask in IndexReg for Data */ + SiS_Pr->SiS_DDC_Clk = 0x40; /* Bitmask in IndexReg for Clk */ + SiS_Pr->SiS_DDC_DataShift = 0x00; + SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* TW: DAB (Device Address Byte) */ + + for(i=0;i<20;i++) { /* TW: Do only 20 attempts to read */ + /* SiS_SetSwitchDDC2(SiS_Pr); */ + if(SiS_SetStart(SiS_Pr)) continue; /* TW: Set start condition */ + tempah = SiS_Pr->SiS_DDC_DeviceAddr; + temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* TW: Write DAB (S0=0=write) */ + if(temp) continue; /* TW: (ERROR: no ack) */ + tempah = SiS_Pr->SiS_DDC_ReadAddr | 0x80; /* TW: Write RAB | 0x80 */ + temp = SiS_WriteDDC2Data(SiS_Pr,tempah); + if(temp) continue; /* TW: (ERROR: no ack) */ + if (SiS_SetStart(SiS_Pr)) continue; /* TW: Re-start */ + tempah = SiS_Pr->SiS_DDC_DeviceAddr | 0x01; /* DAB | 0x01 = Read */ + temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* TW: DAB (S0=1=read) */ + if(temp) continue; /* TW: (ERROR: no ack) */ + tempah = SiS_ReadDDC2Data(SiS_Pr,tempah); /* TW: Read byte */ + if (SiS_SetStop(SiS_Pr)) continue; /* TW: Stop condition */ + SiS_Pr->SiS_ChrontelInit = 1; + return(tempah); + } + } + return(0xFFFF); +} + +/* TW: Read from Chrontel 701x */ +/* Parameter is [Register no (S7-S0)] */ +USHORT +SiS_GetCH701x(SiS_Private *SiS_Pr, USHORT tempbx) +{ + USHORT tempah,temp,i; + + SiS_Pr->SiS_DDC_Index = 0x11; /* TW: Bit 0 = SC; Bit 1 = SD */ + SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */ + SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */ + SiS_Pr->SiS_DDC_DataShift = 0x00; + SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* TW: DAB */ + SiS_Pr->SiS_DDC_ReadAddr = tempbx; + + for(i=0;i<20;i++) { /* TW: Do only 20 attempts to read */ + if(SiS_SetStart(SiS_Pr)) continue; /* TW: Set start condition */ + tempah = SiS_Pr->SiS_DDC_DeviceAddr; + temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* TW: Write DAB (S0=0=write) */ + if(temp) continue; /* TW: (ERROR: no ack) */ + tempah = SiS_Pr->SiS_DDC_ReadAddr; /* TW: Write RAB */ + temp = SiS_WriteDDC2Data(SiS_Pr,tempah); + if(temp) continue; /* TW: (ERROR: no ack) */ + if (SiS_SetStart(SiS_Pr)) continue; /* TW: Re-start */ + tempah = SiS_Pr->SiS_DDC_DeviceAddr | 0x01; /* DAB | 0x01 = Read */ + temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* TW: DAB (S0=1=read) */ + if(temp) continue; /* TW: (ERROR: no ack) */ + tempah = SiS_ReadDDC2Data(SiS_Pr,tempah); /* TW: Read byte */ + SiS_SetStop(SiS_Pr); /* TW: Stop condition */ + return(tempah); + } + return 0xFFFF; +} + +#ifdef LINUX_XF86 +/* TW: Our own DDC functions */ +USHORT +SiS_InitDDCRegs(SiS_Private *SiS_Pr, SISPtr pSiS, USHORT adaptnum, USHORT DDCdatatype) +{ + unsigned char ddcdtype[] = { 0xa0, 0xa0, 0xa0, 0xa2, 0xa6}; + unsigned char flag, cr32; + USHORT temp = 0, myadaptnum = adaptnum; + + SiS_Pr->SiS_ChrontelInit = 0; /* force re-detection! */ + + SiS_Pr->SiS_DDC_SecAddr = 0; + SiS_Pr->SiS_DDC_DeviceAddr = ddcdtype[DDCdatatype]; + SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_P3c4; + SiS_Pr->SiS_DDC_Index = 0x11; + flag = 0xff; + + cr32 = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x32); + + if(pSiS->VGAEngine == SIS_300_VGA) { /* 300 series */ + + if(pSiS->VBFlags & VB_SISBRIDGE) { + if(myadaptnum == 0) { + if(!(cr32 & 0x20)) { + myadaptnum = 2; + if(!(cr32 & 0x10)) { + myadaptnum = 1; + if(!(cr32 & 0x08)) { + myadaptnum = 0; + } + } + } + } + } + + if(myadaptnum != 0) { + flag = 0; + if(pSiS->VBFlags & VB_SISBRIDGE) { + SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port; + SiS_Pr->SiS_DDC_Index = 0x0f; + } + } + + if(cr32 & 0x80) { + if(myadaptnum >= 1) { + if(!(cr32 & 0x08)) { + myadaptnum = 1; + if(!(cr32 & 0x10)) return 0xFFFF; + } + } + } + + temp = 4 - (myadaptnum * 2); + if(flag) temp = 0; + + SiS_Pr->SiS_DDC_Data = 0x02 << temp; + SiS_Pr->SiS_DDC_Clk = 0x01 << temp; + + } else { /* 310/325 series */ + + if(pSiS->VBFlags & (VB_30xLV|VB_30xLVX)) myadaptnum = 0; + + if(pSiS->VBFlags & VB_SISBRIDGE) { + if(myadaptnum == 0) { + if(!(cr32 & 0x20)) { + myadaptnum = 2; + if(!(cr32 & 0x10)) { + myadaptnum = 1; + if(!(cr32 & 0x08)) { + myadaptnum = 0; + } + } + } + } + if(myadaptnum == 2) { + myadaptnum = 1; + } + } + + if(myadaptnum == 1) { + flag = 0; + if(pSiS->VBFlags & VB_SISBRIDGE) { + SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port; + SiS_Pr->SiS_DDC_Index = 0x0f; + } + } + + if(cr32 & 0x80) { + if(myadaptnum >= 1) { + if(!(cr32 & 0x08)) { + myadaptnum = 1; + if(!(cr32 & 0x10)) return 0xFFFF; + } + } + } + + temp = myadaptnum; + if(myadaptnum == 1) { + temp = 0; + if(pSiS->VBFlags & VB_LVDS) flag = 0xff; + } + + if(flag) temp = 0; + + SiS_Pr->SiS_DDC_Data = 0x02 << temp; + SiS_Pr->SiS_DDC_Clk = 0x01 << temp; + + } + return 0; +} + +USHORT +SiS_WriteDABDDC(SiS_Private *SiS_Pr) +{ + SiS_SetStart(SiS_Pr); + if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_DeviceAddr)) return 0xFFFF; + if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_SecAddr)) return 0xFFFF; + return(0); +} + +USHORT +SiS_PrepareReadDDC(SiS_Private *SiS_Pr) +{ + SiS_SetStart(SiS_Pr); + if(SiS_WriteDDC2Data(SiS_Pr, (SiS_Pr->SiS_DDC_DeviceAddr | 0x01))) return 0xFFFF; + return(0); +} + +USHORT +SiS_PrepareDDC(SiS_Private *SiS_Pr) +{ + if(SiS_WriteDABDDC(SiS_Pr)) SiS_WriteDABDDC(SiS_Pr); + if(SiS_PrepareReadDDC(SiS_Pr)) return(SiS_PrepareReadDDC(SiS_Pr)); + return(0); +} + +void +SiS_SendACK(SiS_Private *SiS_Pr, USHORT yesno) +{ + SiS_SetSCLKLow(SiS_Pr); + if(yesno) { + SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, + ~SiS_Pr->SiS_DDC_Data, SiS_Pr->SiS_DDC_Data); + } else { + SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, + ~SiS_Pr->SiS_DDC_Data, 0); + } + SiS_SetSCLKHigh(SiS_Pr); +} + +USHORT +SiS_DoProbeDDC(SiS_Private *SiS_Pr) +{ + unsigned char mask, value; + USHORT temp, ret; + + SiS_SetSwitchDDC2(SiS_Pr); + if(SiS_PrepareDDC(SiS_Pr)) { + SiS_SetStop(SiS_Pr); + return(0xFFFF); + } + mask = 0xf0; + value = 0x20; + if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) { + temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr, 0); + SiS_SendACK(SiS_Pr, 0); + if(temp == 0) { + mask = 0xff; + value = 0xff; + } + } + temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr, 0); + SiS_SendACK(SiS_Pr, 1); + temp &= mask; + if(temp == value) ret = 0; + else { + ret = 0xFFFF; + if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) { + if(value == 0x30) ret = 0; + } + } + SiS_SetStop(SiS_Pr); + return(ret); +} + +USHORT +SiS_ProbeDDC(SiS_Private *SiS_Pr) +{ + USHORT flag; + + flag = 0x180; + SiS_Pr->SiS_DDC_DeviceAddr = 0xa0; + if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x02; + SiS_Pr->SiS_DDC_DeviceAddr = 0xa2; + if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x08; + SiS_Pr->SiS_DDC_DeviceAddr = 0xa6; + if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x10; + if(!(flag & 0x1a)) flag = 0; + return(flag); +} + +USHORT +SiS_ReadDDC(SiS_Private *SiS_Pr, SISPtr pSiS, USHORT DDCdatatype, unsigned char *buffer) +{ + USHORT flag, length, i; + unsigned char chksum,gotcha; + + if(DDCdatatype > 3) return 0xFFFF; /* incomplete! */ + + flag = 0; + SiS_SetSwitchDDC2(SiS_Pr); + if(!(SiS_PrepareDDC(SiS_Pr))) { + length = 127; + if(DDCdatatype != 1) length = 255; + chksum = 0; + gotcha = 0; + for(i=0; i 0: Returns 0 if reading OK (included a correct checksum) + if DDCdatatype = 0: Returns supported DDC modes + + */ +USHORT +SiS_HandleDDC(SiS_Private *SiS_Pr, SISPtr pSiS, USHORT adaptnum, + USHORT DDCdatatype, unsigned char *buffer) +{ + if(DDCdatatype == 2) return 0xFFFF; + if(adaptnum > 2) return 0xFFFF; + if(pSiS->VGAEngine == SIS_300_VGA) { + if((adaptnum != 0) && (DDCdatatype != 0)) return 0xFFFF; + } + if((!(pSiS->VBFlags & VB_VIDEOBRIDGE)) && (adaptnum > 0)) return 0xFFFF; + if(SiS_InitDDCRegs(SiS_Pr, pSiS, adaptnum, DDCdatatype) == 0xFFFF) return 0xFFFF; + if(DDCdatatype == 0) { + return(SiS_ProbeDDC(SiS_Pr)); + } else { + if(DDCdatatype > 4) return 0xFFFF; + return(SiS_ReadDDC(SiS_Pr, pSiS, DDCdatatype, buffer)); + } +} + +#if 0 /* for future use */ + +USHORT +SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS, unsigned char *buffer) +{ + USHORT flag, temp; + unsigned char buffer[8]; + unsigned char cr36=0, cr37=0; + unsigned chat tempal, tempah, tempbl, tempbh; + USHORT tempax, tempbx tempcx, push1, push2, push3; + unsigned char addresstable[] = { 0x00, 0x22, 0x30, 0x40 }; + + if(SiS_InitDDCRegs(SiS_Pr, pSiS, 1, 0) == 0xFFFF) return 0xFFFF; + flag = SiS_ProbeDDC(SiS_Pr); + + if(flag & 0x02) { + SiS_Pr->SiS_DDC_DeviceAddr = 0xa0; + SiS_Pr->SiS_DDC_SecAddr = 0x3a; + } else if(flag & 0x08) { + SiS_Pr->SiS_DDC_DeviceAddr = 0xa2; + SiS_Pr->SiS_DDC_SecAddr = 0x76; + } else if(flag & 0x10) { + SiS_Pr->SiS_DDC_DeviceAddr = 0xa6; + SiS_Pr->SiS_DDC_SecAddr = 0x76; + } else return 0xFFFF; + + SiS_ReadLCDDDC(SiS_Pr, 4, buffer); + tempbl = buffer[0]; + tempbh = buffer[1]; + if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) { + tempah = 0x02; + tempbl &= 0xf0; + if(tempbl != 0x40) { + tempah = 0x03; + if(tempbl == 0x50) { + if(!tempbh) { + tempbh = buffer[3] & 0xf0; + if(tempbh == 0x30) { + SiS_Pr->SiS_DDC_DeviceAddr = 0xa0; + SiS_Pr->SiS_DDC_SecAddr = 0x23; + SiS_ReadLCDDDC(SiS_Pr, 2, buffer); + tempbl = buffer[0]; + tempbh = buffer[1]; + if(tempbl) cr37 |= 0x10; + tempah = 0x0a; + } + if(tempbh == 0x40) { + SiS_Pr->SiS_DDC_DeviceAddr = 0xa0; + SiS_Pr->SiS_DDC_SecAddr = 0x23; + SiS_ReadLCDDDC(SiS_Pr, 2, buffer); + tempbl = buffer[0]; + tempbh = buffer[1]; + if(tempbl) cr37 |= 0x10; + tempah = 0x03; + } + tempbh = 0x00; + } + } + if(tempbh == 0x00) goto cr36ready; + tempah = 0x07; + if(tempbh == 0xc0) goto cr36ready; + } + SiS_Pr->SiS_DDC_DeviceAddr = 0xa0; + SiS_Pr->SiS_DDC_SecAddr = 0x18; + SiS_ReadLCDDDC(SiS_Pr, 2, buffer); + tempbl = buffer[0]; + tempbh = buffer[1]; + if(tempbl & 0x02) goto cr36ready; + SiS_Pr->SiS_DDC_DeviceAddr = 0xa0; + SiS_Pr->SiS_DDC_SecAddr = 0x23; + SiS_ReadLCDDDC(SiS_Pr, 2, buffer); + tempbl = buffer[0]; + tempbh = buffer[1]; + tempah = 0x03; + if(!tempbh & 0x01)) tempah = 0x02; + if(!tempbl) cr37 |= 0x10; + + } else { + + tempah = 0x02; + tempbx = tempbl | (tempbh << 8); + if(tempbx != 1024) tempah = 0x03; + + } + +cr36ready: + cr36 = tempah; + + if((SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) { + + SiS_Pr->SiS_DDC_SecAddr = 0x47; + SiS_ReadLCDDDC(SiS_Pr, 2, buffer); + tempah = buffer[0]; + tempah &= 0x06; + tempah ^= 0x06; + tempah <<= 5; + tempah |= 0x20; + cr37 &= 0x1f; + cr37 |= tempah; + if((cr36 & 0x07) == 0x07) cr37 &= 0x0e; + + } else { + + push1 = tempah; + SiS_Pr->SiS_DDC_SecAddr = 0x45; + SiS_ReadLCDDDC(SiS_Pr, 2, buffer); + tempah = 0x01; + if((buffer[0] != 0x20) && (buffer[0] != 0x34)) { + tempah = 0x00; + } + cr37 &= 0xfe; + cr37 |= tempah; + + SiS_Pr->SiS_DDC_SecAddr = 0x7e; + SiS_ReadLCDDDC(SiS_Pr, 2, buffer); + tempax = (USHORT)(buffer[0] | (buffer[1] << 8)); + push2 = tempax; + tempax &= 0x0003; + tempax *= 0x1b; + push3 = tempax; + tempax = (USHORT)buffer[0]; + tempax &= 0x001c; + tempax >>= 2; + tempax *= 8; + tempbx = push3; + tempbx += tempax; + if(buffer[0] & 0x20) { + SiS_Pr->SiS_DDC_SecAddr = 0x80; + SiS_ReadLCDDDC(SiS_Pr, 2, buffer); + tempax = buffer[0] | (buffer[1] << 8); + tempax &= 0x1f; + if(buffer[0] & 0x70) tempax <<= 1; + tempax++; + tempbx += tempax; + } + tempcx = push2; + tempax = push1 << 8; + tempbx = (tempbx & 0xff00) | (((tempbx & 0x00ff) + 0x80) & 0x00ff); + if(tempcx & 0xf800) { + tempal = addresstable[((tempax & 0xff00) >> 8)]; + tempcx &= 0xf8ff; + tempcx >>= 11; + for(i=0; iSiS_DDC_SecAddr = (tempbx & 0x00ff); + SiS_ReadLCDDDC(SiS_Pr, 2, buffer); + tempbx += 0x04; + if(buffer[0] == tempal) break; + } + tempah = buffer[1]; + tempah &= 0x0c; + tempah ^= 0x0c; + tempah <<= 4; + tempah |= 0x20; + cr37 &= 0x1f; + cr37 |= tempah; + if((cr36 & 0x07) == 0x07) cr37 &= 0x0e; + } + } + xf86DrvMsg(0, X_INFO, "DDC: cr36 = 0x%02x, cr37 = 0x%02x\n", cr36, cr37); + +} + +#endif + +/* TW: Generic I2C functions (compliant to i2c library) */ + +#if 0 +USHORT +SiS_I2C_GetByte(SiS_Private *SiS_Pr) +{ + return(SiS_ReadDDC2Data(SiS_Pr,0)); +} + +Bool +SiS_I2C_PutByte(SiS_Private *SiS_Pr, USHORT data) +{ + if(SiS_WriteDDC2Data(SiS_Pr,data)) return FALSE; + return TRUE; +} + +Bool +SiS_I2C_Address(SiS_Private *SiS_Pr, USHORT addr) +{ + if(SiS_SetStart(SiS_Pr)) return FALSE; + if(SiS_WriteDDC2Data(SiS_Pr,addr)) return FALSE; + return TRUE; +} + +void +SiS_I2C_Stop(SiS_Private *SiS_Pr) +{ + SiS_SetStop(SiS_Pr); +} +#endif + +#endif + +void +SiS_SetCH70xxANDOR(SiS_Private *SiS_Pr, USHORT tempax,USHORT tempbh) +{ + USHORT tempal,tempah,tempbl; + + tempal = tempax & 0x00FF; + tempah =(tempax >> 8) & 0x00FF; + tempbl = SiS_GetCH70xx(SiS_Pr,tempal); + tempbl = (((tempbl & tempbh) | tempah) << 8 | tempal); + SiS_SetCH70xx(SiS_Pr,tempbl); +} + +/* TW: Generic I2C functions for Chrontel --------- */ + +void +SiS_SetSwitchDDC2(SiS_Private *SiS_Pr) +{ + SiS_SetSCLKHigh(SiS_Pr); + /* SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAY); */ + SiS_WaitRetraceDDC(SiS_Pr); + + SiS_SetSCLKLow(SiS_Pr); + /* SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAY); */ + SiS_WaitRetraceDDC(SiS_Pr); +} + +/* TW: Set I2C start condition */ +/* TW: This is done by a SD high-to-low transition while SC is high */ +USHORT +SiS_SetStart(SiS_Private *SiS_Pr) +{ + if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* TW: (SC->low) */ + SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index, + ~SiS_Pr->SiS_DDC_Data,SiS_Pr->SiS_DDC_Data); /* TW: SD->high */ + if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* TW: SC->high */ + SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index, + ~SiS_Pr->SiS_DDC_Data,0x00); /* TW: SD->low = start condition */ + if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* TW: (SC->low) */ + return 0; +} + +/* TW: Set I2C stop condition */ +/* TW: This is done by a SD low-to-high transition while SC is high */ +USHORT +SiS_SetStop(SiS_Private *SiS_Pr) +{ + if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* TW: (SC->low) */ + SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index, + ~SiS_Pr->SiS_DDC_Data,0x00); /* TW: SD->low */ + if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* TW: SC->high */ + SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index, + ~SiS_Pr->SiS_DDC_Data,SiS_Pr->SiS_DDC_Data); /* TW: SD->high = stop condition */ + if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* TW: (SC->high) */ + return 0; +} + +/* TW: Write 8 bits of data */ +USHORT +SiS_WriteDDC2Data(SiS_Private *SiS_Pr, USHORT tempax) +{ + USHORT i,flag,temp; + + flag=0x80; + for(i=0;i<8;i++) { + SiS_SetSCLKLow(SiS_Pr); /* TW: SC->low */ + if(tempax & flag) { + SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index, + ~SiS_Pr->SiS_DDC_Data,SiS_Pr->SiS_DDC_Data); /* TW: Write bit (1) to SD */ + } else { + SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index, + ~SiS_Pr->SiS_DDC_Data,0x00); /* TW: Write bit (0) to SD */ + } + SiS_SetSCLKHigh(SiS_Pr); /* TW: SC->high */ + flag >>= 1; + } + temp = SiS_CheckACK(SiS_Pr); /* TW: Check acknowledge */ + return(temp); +} + +USHORT +SiS_ReadDDC2Data(SiS_Private *SiS_Pr, USHORT tempax) +{ + USHORT i,temp,getdata; + + getdata=0; + for(i=0; i<8; i++) { + getdata <<= 1; + SiS_SetSCLKLow(SiS_Pr); + SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index, + ~SiS_Pr->SiS_DDC_Data,SiS_Pr->SiS_DDC_Data); + SiS_SetSCLKHigh(SiS_Pr); + temp = SiS_GetReg1(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index); + if(temp & SiS_Pr->SiS_DDC_Data) getdata |= 0x01; + } + return(getdata); +} + +USHORT +SiS_SetSCLKLow(SiS_Private *SiS_Pr) +{ + USHORT temp, watchdog=50000; + + SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index, + ~SiS_Pr->SiS_DDC_Clk,0x00); /* SetSCLKLow() */ + do { + temp = SiS_GetReg1(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index); + } while((temp & SiS_Pr->SiS_DDC_Clk) && --watchdog); + if (!watchdog) return 0xFFFF; + SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT); + return 0; +} + +USHORT +SiS_SetSCLKHigh(SiS_Private *SiS_Pr) +{ + USHORT temp,watchdog=50000; + + SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index, + ~SiS_Pr->SiS_DDC_Clk,SiS_Pr->SiS_DDC_Clk); /* SetSCLKHigh() */ + do { + temp = SiS_GetReg1(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index); + } while((!(temp & SiS_Pr->SiS_DDC_Clk)) && --watchdog); + if (!watchdog) return 0xFFFF; + SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT); + return 0; +} + +void +SiS_DDC2Delay(SiS_Private *SiS_Pr, USHORT delaytime) +{ + USHORT i; + + for(i=0; iSiS_P3c4,0x05); + } +} + +/* TW: Check I2C acknowledge */ +/* Returns 0 if ack ok, non-0 if ack not ok */ +USHORT +SiS_CheckACK(SiS_Private *SiS_Pr) +{ + USHORT tempah; + + SiS_SetSCLKLow(SiS_Pr); /* TW: (SC->low) */ + SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index, + ~SiS_Pr->SiS_DDC_Data,SiS_Pr->SiS_DDC_Data); /* TW: (SD->high) */ + SiS_SetSCLKHigh(SiS_Pr); /* TW: SC->high = clock impulse for ack */ + tempah = SiS_GetReg1(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index);/* TW: Read SD */ + SiS_SetSCLKLow(SiS_Pr); /* TW: SC->low = end of clock impulse */ + if(tempah & SiS_Pr->SiS_DDC_Data) return(1); /* TW: Ack OK if bit = 0 */ + else return(0); +} + +/* TW: End of I2C functions ----------------------- */ + + +/* =============== SiS 310/325 O.E.M. ================= */ + +#ifdef SIS315H + +static USHORT +GetLCDPtrIndex(SiS_Private *SiS_Pr) +{ + USHORT index; + + index = SiS_Pr->SiS_LCDResInfo & 0x0F; + index--; + index *= 3; + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) index += 2; + else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++; + + return index; +} + +/* +--------------------------------------------------------- + GetTVPtrIndex() + return 0 : NTSC Enhanced/Standard + 1 : NTSC Standard TVSimuMode + 2 : PAL Enhanced/Standard + 3 : PAL Standard TVSimuMode + 4 : HiVision Enhanced/Standard + 5 : HiVision Standard TVSimuMode +--------------------------------------------------------- +*/ +static USHORT +GetTVPtrIndex(SiS_Private *SiS_Pr) +{ + USHORT index; + + index = 0; + if(SiS_Pr->SiS_VBInfo & SetPALTV) index++; + if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) index++; /* Hivision TV use PAL */ + + index <<= 1; + + if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) && (SiS_Pr->SiS_SetFlag & TVSimuMode)) + index++; + + return index; +} + +/* TW: Checked against 650/LVDS (1.10.07) and 650/301LVx (1.10.6s) BIOS (including data) */ +static void +SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr, + UCHAR *ROMAddr, USHORT ModeNo) +{ + USHORT delay,index,temp,romptr=0; + + if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { + if((ROMAddr) && SiS_Pr->SiS_UseROM) { + if(HwDeviceExtension->jChipType != SIS_330) { + romptr = ROMAddr[0x128] | (ROMAddr[0x129] << 8); /* 301, LVDS */ + if(SiS_Pr->SiS_VBType & (VB_SIS301B | VB_SIS302B)) + romptr = ROMAddr[0x12a] | (ROMAddr[0x12b] << 8); + } else { + romptr = ROMAddr[0x1a8] | (ROMAddr[0x1a9] << 8); /* 301, LVDS */ + if(SiS_Pr->SiS_VBType & (VB_SIS301B | VB_SIS302B)) + romptr = ROMAddr[0x1aa] | (ROMAddr[0x1ab] << 8); + } + } + if(romptr) delay = ROMAddr[romptr]; + else { + delay = SiS310_CRT2DelayCompensation1; + if(SiS_Pr->SiS_VBType & (VB_SIS301B | VB_SIS302B)) + delay = SiS310_CRT2DelayCompensation2; + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) + delay = SiS310_CRT2DelayCompensation3; + } + } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + index = GetLCDPtrIndex(SiS_Pr); + delay = SiS310_LCDDelayCompensation1[index]; + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) + delay = SiS310_LCDDelayCompensation2[index]; + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) + delay = SiS310_LCDDelayCompensation3[index]; + if((IS_SIS650740) && (SiS_Pr->SiS_IF_DEF_LVDS == 0)) { + if(SiS_IsM650or651(SiS_Pr,HwDeviceExtension, BaseAddr)) { + delay = SiS310_LCDDelayCompensation4[index]; /* 652c */ + if(SiS_Pr->SiS_VBType & VB_SIS30xNEW) + delay = SiS310_LCDDelayCompensation5[index]; /* 6541 */ + } else { + delay = SiS310_LCDDelayCompensation6[index]; /* 6550 */ + if(SiS_Pr->SiS_VBType & VB_SIS30xNEW) + delay = SiS310_LCDDelayCompensation7[index]; /* 655f */ + } + } + } else { + index = GetTVPtrIndex(SiS_Pr); + if((ROMAddr) && SiS_Pr->SiS_UseROM) { + if(HwDeviceExtension->jChipType != SIS_330) { + romptr = ROMAddr[0x114] | (ROMAddr[0x115] << 8); + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) + romptr = ROMAddr[0x11a] | (ROMAddr[0x11b] << 8); + } else { + romptr = ROMAddr[0x194] | (ROMAddr[0x195] << 8); + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) + romptr = ROMAddr[0x19a] | (ROMAddr[0x19b] << 8); + } + } + if(romptr) delay = ROMAddr[romptr + index]; + else { + delay = SiS310_TVDelayCompensation1[index]; + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) + delay = SiS310_TVDelayCompensation2[index]; + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) + delay = SiS310_TVDelayCompensation3[index]; + } + if((IS_SIS650740) && (SiS_Pr->SiS_IF_DEF_LVDS == 0)) { + romptr = 0; + if(SiS_IsM650or651(SiS_Pr,HwDeviceExtension, BaseAddr)) { + if((ROMAddr) && SiS_Pr->SiS_UseROM) { + romptr = ROMAddr[0x114] | (ROMAddr[0x115] << 8); + if(SiS_Pr->SiS_VBType & VB_SIS30xNEW) + romptr = ROMAddr[0x11a] | (ROMAddr[0x11b] << 8); + } + if(romptr) delay = ROMAddr[romptr + index]; + else { + delay = SiS310_TVDelayCompensation4[index]; /* 656e @ 0x114 */ + if(SiS_Pr->SiS_VBType & VB_SIS30xNEW) + delay = SiS310_TVDelayCompensation5[index]; /* 6574 @ 0x11a */ + } + } else { + delay = SiS310_TVDelayCompensation6[index]; /* 657a */ + if(SiS_Pr->SiS_VBType & VB_SIS30xNEW) + delay = SiS310_TVDelayCompensation7[index]; /* 6580 */ + } + } + } + + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay); + } else { + if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { + delay <<= 4; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,delay); + } else { + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay); + } + } + } else { + if((IS_SIS650740) && (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) { + temp = (SiS_GetReg1(SiS_Pr->SiS_P3d4,0x36) & 0xf0) >> 4; + if(temp == 8) { + delay &= 0x0f; + delay |= 0xb0; + } else if(temp == 6) { + delay &= 0x0f; + delay |= 0xc0; + } + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x2D,delay); /* index 2D D[3:0] */ + } else { + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay); + } + } +} + +/* TW: Checked against 650/301LVx 1.10.6s BIOS (including data) */ +static void +SetAntiFlicker(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr, + UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex) +{ + USHORT index,temp,romptr=0; + + temp = GetTVPtrIndex(SiS_Pr); + temp >>= 1; /* 0: NTSC, 1: PAL, 2: HiTV */ + + if(ModeNo<=0x13) + index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex; + else + index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex; + + if(ROMAddr && SiS_Pr->SiS_UseROM) { + romptr = ROMAddr[0x112] | (ROMAddr[0x113] << 8); + if(HwDeviceExtension->jChipType == SIS_330) { + romptr = ROMAddr[0x192] | (ROMAddr[0x193] << 8); + } + } + + if(romptr) { + temp <<= 1; + temp = ROMAddr[romptr + temp + index]; + } else { + temp = SiS310_TVAntiFlick1[temp][index]; + } + temp <<= 4; + + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8f,temp); /* index 0A D[6:4] */ +} + +/* TW: Checked against 650/301LVx 1.10.6s BIOS (including data) */ +static void +SetEdgeEnhance(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr, + UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex) +{ + USHORT index,temp,romptr=0; + + temp = GetTVPtrIndex(SiS_Pr); + temp >>= 1; /* 0: NTSC, 1: PAL, 2: HiTV */ + + if(ModeNo<=0x13) + index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex; + else + index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex; + + if(ROMAddr && SiS_Pr->SiS_UseROM) { + romptr = ROMAddr[0x124] | (ROMAddr[0x125] << 8); + if(HwDeviceExtension->jChipType == SIS_330) { + romptr = ROMAddr[0x1a4] | (ROMAddr[0x1a5] << 8); + } + } + + if(romptr) { + temp <<= 1; + temp = ROMAddr[romptr + temp + index]; + } else { + temp = SiS310_TVEdge1[temp][index]; + } + temp <<= 5; + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x3A,0x1F,temp); /* index 0A D[7:5] */ +} + +/* TW: Checked against 650/301LVx 1.10.6s BIOS (incl data) */ +static void +SetYFilter(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr, + UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex) +{ + USHORT index, temp, i, j; + UCHAR OutputSelect = *SiS_Pr->pSiS_OutputSelect; + + temp = GetTVPtrIndex(SiS_Pr); + temp >>= 1; /* 0: NTSC, 1: PAL, 2: HiTV */ + + if (ModeNo<=0x13) { + index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVYFilterIndex; + } else { + index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex; + } + + if(SiS_Pr->SiS_VBInfo&SetCRT2ToHiVisionTV) temp = 1; /* Hivision TV uses PAL */ + + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + for(i=0x35, j=0; i<=0x38; i++, j++) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]); + } + for(i=0x48; i<=0x4A; i++, j++) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]); + } + } else { + for(i=0x35, j=0; i<=0x38; i++, j++){ + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter1[temp][index][j]); + } + } + + if(ROMAddr && SiS_Pr->SiS_UseROM) { + OutputSelect = ROMAddr[0xf3]; + if(HwDeviceExtension->jChipType == SIS_330) { + OutputSelect = ROMAddr[0x11b]; + } + } + if(OutputSelect & EnablePALMN) { + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x31) & 0x01) { + temp = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x38); + temp &= (EnablePALM | EnablePALN); + if(temp == EnablePALM) { + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + for(i=0x35, j=0; i<=0x38; i++, j++) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,SiS310_PALMFilter2[index][j]); + } + for(i=0x48; i<=0x4A; i++, j++) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,SiS310_PALMFilter2[index][j]); + } + } else { + for(i=0x35, j=0; i<=0x38; i++, j++) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,SiS310_PALMFilter[index][j]); + } + } + } + if(temp == EnablePALN) { + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + for(i=0x35, j=0; i<=0x38; i++, j++) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,SiS310_PALNFilter2[index][j]); + } + for(i=0x48, j=0; i<=0x4A; i++, j++) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,SiS310_PALNFilter2[index][j]); + } + } else { + for(i=0x35, j=0; i<=0x38; i++, j++) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,SiS310_PALNFilter[index][j]); + } + } + } + } + } +} + +/* TW: Checked against 650/301LVx 1.10.6s BIOS (including data) */ +static void +SetPhaseIncr(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr, + UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex) +{ + USHORT index,temp,temp1,i,j,resinfo,romptr=0; + + if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return; + + temp1 = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x38); /* if PALM/N not set */ + temp1 &= (EnablePALM | EnablePALN); + if(temp1) return; + + if (ModeNo<=0x13) { + resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo; + } else { + resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; + } + + temp = GetTVPtrIndex(SiS_Pr); + /* 0: NTSC Graphics, 1: NTSC Text, 2: PAL Graphics, + * 3: PAL Text, 4: HiTV Graphics 5: HiTV Text + */ + if((ROMAddr) && SiS_Pr->SiS_UseROM) { + romptr = ROMAddr[0x116] | (ROMAddr[0x117] << 8); + if(HwDeviceExtension->jChipType == SIS_330) { + romptr = ROMAddr[0x196] | (ROMAddr[0x197] << 8); + } + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + romptr = ROMAddr[0x11c] | (ROMAddr[0x11d] << 8); + if(HwDeviceExtension->jChipType == SIS_330) { + romptr = ROMAddr[0x19c] | (ROMAddr[0x19d] << 8); + } + if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) && (!(SiS_Pr->SiS_SetFlag & TVSimuMode))) { + romptr = ROMAddr[0x116] | (ROMAddr[0x117] << 8); + if(HwDeviceExtension->jChipType == SIS_330) { + romptr = ROMAddr[0x196] | (ROMAddr[0x197] << 8); + } + } + } + } + if(romptr) { + romptr += (temp << 2); + for(j=0, i=0x31; i<=0x34; i++, j++) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]); + } + } else { + index = temp % 2; + temp >>= 1; /* 0:NTSC, 1:PAL, 2:HiTV */ + for(j=0, i=0x31; i<=0x34; i++, j++) { + if(!(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]); + else if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || (SiS_Pr->SiS_SetFlag & TVSimuMode)) + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr2[temp][index][j]); + else + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]); + } + } + + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { /* TW: 650/301LV: (VB_SIS301LV | VB_SIS302LV)) */ + if((!(SiS_Pr->SiS_VBInfo & SetPALTV)) && (ModeNo > 0x13)) { + if(resinfo == 6) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x31,0x21); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x32,0xf0); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x33,0xf5); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x34,0x7f); + } else if (resinfo == 7) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x31,0x21); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x32,0xf0); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x33,0xf5); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x34,0x7f); + } else if (resinfo == 8) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x31,0x1e); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x32,0x8b); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x33,0xfb); + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x34,0x7b); + } + } + } +} + +void +SiS_OEM310Setting(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr, + UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex) +{ + SetDelayComp(SiS_Pr,HwDeviceExtension,BaseAddr,ROMAddr,ModeNo); + /* TW: The TV functions are not for LVDS */ + if( (SiS_Pr->SiS_IF_DEF_LVDS == 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) ) { + SetAntiFlicker(SiS_Pr,HwDeviceExtension,BaseAddr,ROMAddr,ModeNo,ModeIdIndex); + SetPhaseIncr(SiS_Pr,HwDeviceExtension,BaseAddr,ROMAddr,ModeNo,ModeIdIndex); + SetYFilter(SiS_Pr,HwDeviceExtension,BaseAddr,ROMAddr,ModeNo,ModeIdIndex); + if(!(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) { + SetEdgeEnhance(SiS_Pr,HwDeviceExtension,BaseAddr,ROMAddr,ModeNo,ModeIdIndex); + } + } +} + +/* TW: New from 650/301LVx 1.10.6s, 1.10.7w - clashes with OEMLCD() */ +void +SiS_FinalizeLCD(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo, + USHORT ModeIdIndex, PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + USHORT tempcl,tempch,tempbl,tempbh,tempbx,tempax,temp; + USHORT resinfo,modeflag; + + if(!(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) return; + + if(ModeNo <= 0x13) { + resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo; + modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; + } else { + resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; + modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; + } + + if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) { + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x2a,0x00); + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x30,0x00); + SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x34,0x10); + } + tempch = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x36); + tempch &= 0xf0; + tempch >>= 4; + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1f,0x76); + } + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) { /* From 1.10.8w */ + if(!(SiS_Pr->SiS_LCDInfo & LCDNonExpanding)) { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x14,0x90); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x18,0x01); + if((ModeNo > 0x13) && (resinfo == 8)) { + tempbx = 806; /* 0x326 */ + tempbx--; + temp = tempbx & 0xff; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1b,temp); + temp = (tempbx >> 8) & 0x03; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1d,0xf8,temp); + } + } else { + if(ModeNo <= 0x13) { + if(ModeNo <= 1) { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x18,0x70); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x19,0xff); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1b,0x48); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1d,0x12); + } + if(!(modeflag & HalfDCLK)) { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x14,0x20); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x15,0x1a); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x16,0x28); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x17,0x00); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x18,0x4c); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x19,0xdc); + if(ModeNo == 0x12) { + switch(tempch) { + case 0: + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x18,0x95); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x19,0xdc); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1a,0x10); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1b,0x95); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1c,0x48); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1d,0x12); + break; + case 2: + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x18,0x95); + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1b,0x48); + break; + case 3: + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x1b,0x95); + break; + } + } + } + } + } + } + } else { + tempcl = tempbh = SiS_GetReg1(SiS_Pr->SiS_Part2Port,0x01); + tempcl &= 0x0f; + tempbh &= 0x70; + tempbh >>= 4; + tempbl = SiS_GetReg1(SiS_Pr->SiS_Part2Port,0x04); + tempbx = (tempbh << 8) | tempbl; + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) { + if((resinfo == 8) || (!(SiS_Pr->SiS_LCDInfo & LCDNonExpanding))) { + if(SiS_Pr->SiS_SetFlag & LCDVESATiming) { + tempbx = 770; + } else { + if(tempbx > 770) tempbx = 770; + if(SiS_Pr->SiS_VGAVDE < 600) { + tempax = 768 - SiS_Pr->SiS_VGAVDE; + tempax >>= 4; /* From 1.10.7w; 1.10.6s: 3; */ + if(SiS_Pr->SiS_VGAVDE <= 480) tempax >>= 4; /* From 1.10.7w; 1.10.6s: < 480; >>=1; */ + tempbx -= tempax; + } + } + } else return; + } +#if 0 + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) { + } +#endif + temp = tempbx & 0xff; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x04,temp); + temp = (tempbx & 0xff00) >> 8; + temp <<= 4; + temp |= tempcl; + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,temp); + } + } +} + +/* TW: New and checked from 650/301LV BIOS */ +/* This might clash with newer "FinalizeLCD()" function */ +void +SiS_OEMLCD(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr, + UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex) +{ + USHORT tempbx,tempah,tempbl,tempbh,tempcl; + + if(!(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) return; + + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { + SiS_UnLockCRT2(SiS_Pr,HwDeviceExtension,BaseAddr); + tempbh = SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x1a); + tempbh &= 0x38; + tempbh >>= 3; + tempbl = SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x18); + tempbx = (tempbh << 8) | tempbl; + if(SiS_Pr->SiS_LCDTypeInfo == 1) tempbx -= 0x12; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x18,tempbx & 0x00ff); + tempah = (tempbx & 0xff00) >> 8; + tempah &= 0x07; + tempah <<= 3; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1a,0xc7,tempah); + tempah = SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x19); + tempah &= 0x0f; + if(SiS_Pr->SiS_LCDTypeInfo == 1) tempah -= 2; + tempah &= 0x0f; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0xF0,tempah); + tempah = SiS_GetReg1(SiS_Pr->SiS_Part1Port,0x14); + if(SiS_Pr->SiS_LCDTypeInfo == 1) tempah++; + tempah -= 8; + SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x14,tempah); + } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + tempcl = tempbh = SiS_GetReg1(SiS_Pr->SiS_Part2Port,0x01); + tempbh &= 0x70; + tempbh >>= 4; + tempbl = SiS_GetReg1(SiS_Pr->SiS_Part2Port,0x04); + tempbx = (tempbh << 8) | tempbl; + if(SiS_Pr->SiS_LCDTypeInfo == 1) { + tempbx -= 0x1e; + tempcl &= 0x0f; + tempcl -= 4; + tempcl &= 0x0f; + } + tempbl = tempbx & 0x00ff; + tempbh = (tempbx >> 8) & 0x00ff; + SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x04,tempbl); + tempbh <<= 4; + tempbh |= tempcl; + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,tempbh); + } +} +#endif + + +/* ================= SiS 300 O.E.M. ================== */ + +#ifdef SIS300 + +#if 0 /* Not used */ +static USHORT +GetRevisionID(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension) +{ + ULONG temp1; +#ifndef LINUX_XF86 + ULONG base; +#endif + USHORT temp2 = 0; + + if((HwDeviceExtension->jChipType==SIS_540)|| + (HwDeviceExtension->jChipType==SIS_630)|| + (HwDeviceExtension->jChipType==SIS_730)) { +#ifndef LINUX_XF86 + base = 0x80000008; + OutPortLong(base,0xcf8); + temp1 = InPortLong(0xcfc); +#else + temp1=pciReadLong(0x00000000, 0x08); +#endif + temp1 &= 0x000000FF; + temp2 = (USHORT)(temp1); + return temp2; + } + return 0; +} +#endif + +/* TW: Checked against 630/301B BIOS (incl data) */ +static USHORT +GetOEMLCDPtr(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, UCHAR *ROMAddr, int Flag) +{ + USHORT tempbx=0,romptr=0; + UCHAR customtable300[] = { + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff + }; + UCHAR customtable630[] = { + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff + }; + + if(HwDeviceExtension->jChipType == SIS_300) { + + tempbx = SiS_Pr->SiS_LCDResInfo - 2; + if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 4; + if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1024x768) { + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx += 3; + } + if((ROMAddr) && SiS_Pr->SiS_UseROM) { + if(ROMAddr[0x235] & 0x80) { + tempbx = SiS_Pr->SiS_LCDTypeInfo; + if(Flag) { + romptr = ROMAddr[0x255] | (ROMAddr[0x256] << 8); + if(romptr) { + tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo]; + } else { + tempbx = customtable300[SiS_Pr->SiS_LCDTypeInfo]; + } + if(tempbx == 0xFF) return 0xFFFF; + } + tempbx <<= 1; + if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++; + } + } + + } else { + + if(Flag) { + if((ROMAddr) && SiS_Pr->SiS_UseROM) { + romptr = ROMAddr[0x255] | (ROMAddr[0x256] << 8); + if(romptr) { + tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo]; + } else { + tempbx = 0xff; + } + } else { + tempbx = customtable630[SiS_Pr->SiS_LCDTypeInfo]; + } + if(tempbx == 0xFF) return 0xFFFF; + tempbx <<= 2; + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempbx += 2; + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx++; + return tempbx; + } + tempbx = SiS_Pr->SiS_LCDTypeInfo << 2; + if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempbx += 2; + if(SiS_Pr->SiS_LCDInfo & LCDNonExpanding) tempbx++; + } + return tempbx; +} + +/* TW: Checked against 630/301B and 630/LVDS BIOS (incl data) */ +static void +SetOEMLCDDelay(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr, + UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex) +{ + USHORT index,temp,romptr=0; + + if((ROMAddr) && SiS_Pr->SiS_UseROM) { + if(!(ROMAddr[0x237] & 0x01)) return; + if(!(ROMAddr[0x237] & 0x02)) return; + romptr = ROMAddr[0x24b] | (ROMAddr[0x24c] << 8); + } + + /* TW: The Panel Compensation Delay should be set according to tables + * here. Unfortunately, various BIOS versions don't case about + * a uniform way using eg. ROM byte 0x220, but use different + * hard coded delays (0x04, 0x20, 0x18) in SetGroup1(). + * Thus we don't set this if the user select a custom pdc or if + * we otherwise detected a valid pdc. + */ + if(HwDeviceExtension->pdc) return; + + temp = GetOEMLCDPtr(SiS_Pr,HwDeviceExtension, ROMAddr, 0); + + index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_LCDDelayIndex; + + if(HwDeviceExtension->jChipType != SIS_300) { + if(romptr) { + romptr += (temp * 2); + romptr = ROMAddr[romptr] | (ROMAddr[romptr + 1] << 8); + romptr += index; + temp = ROMAddr[romptr]; + } else { + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + temp = SiS300_OEMLCDDelay2[temp][index]; + } else { + temp = SiS300_OEMLCDDelay3[temp][index]; + } + } + } else { + if((ROMAddr) && SiS_Pr->SiS_UseROM && (ROMAddr[0x235] & 0x80)) { + if(romptr) { + romptr += (temp * 2); + romptr = ROMAddr[romptr] | (ROMAddr[romptr + 1] << 8); + romptr += index; + temp = ROMAddr[romptr]; + } else { + temp = SiS300_OEMLCDDelay5[temp][index]; + } + } else { + if((ROMAddr) && SiS_Pr->SiS_UseROM) { + romptr = ROMAddr[0x249] | (ROMAddr[0x24a] << 8); + if(romptr) { + romptr += (temp * 2); + romptr = ROMAddr[romptr] | (ROMAddr[romptr + 1] << 8); + romptr += index; + temp = ROMAddr[romptr]; + } else { + temp = SiS300_OEMLCDDelay4[temp][index]; + } + } else { + temp = SiS300_OEMLCDDelay4[temp][index]; + } + } + } + temp &= 0x3c; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* index 0A D[6:4] */ +} + +static void +SetOEMLCDData(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr, + UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex) +{ +#if 0 /* TW: Unfinished; VData table missing */ + USHORT index,temp; + + if((ROMAddr) && SiS_Pr->SiS_UseROM) { + if(!(ROMAddr[0x237] & 0x01)) return; + if(!(ROMAddr[0x237] & 0x04)) return; + /* No rom pointer in BIOS header! */ + } + + temp = GetOEMLCDPtr(SiS_Pr,HwDeviceExtension, ROMAddr, 1); + if(temp = 0xFFFF) return; + + index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDHIndex; + for(i=0x14, j=0; i<=0x17; i++, j++) { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,i,SiS300_LCDHData[temp][index][j]); + } + SiS_SetRegANDOR(SiS_SiS_Part1Port,0x1a, 0xf8, (SiS300_LCDHData[temp][index][j] & 0x07)); + + index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDVIndex; + SiS_SetReg1(SiS_SiS_Part1Port,0x18, SiS300_LCDVData[temp][index][0]); + SiS_SetRegANDOR(SiS_SiS_Part1Port,0x19, 0xF0, SiS300_LCDVData[temp][index][1]); + SiS_SetRegANDOR(SiS_SiS_Part1Port,0x1A, 0xC7, (SiS300_LCDVData[temp][index][2] & 0x38)); + for(i=0x1b, j=3; i<=0x1d; i++, j++) { + SiS_SetReg1(SiS_Pr->SiS_Part1Port,i,SiS300_LCDVData[temp][index][j]); + } +#endif +} + +/* TW: Checked against 630/301B 2.04.50 and 630/LVDS BIOS */ +static USHORT +GetOEMTVPtr(SiS_Private *SiS_Pr) +{ + USHORT index; + + index = 0; + if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) index += 4; + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) index += 2; + else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) index += 3; + else if(SiS_Pr->SiS_VBInfo & SetPALTV) index += 1; + } else { + if(SiS_Pr->SiS_VBInfo & SetCHTVOverScan) index += 2; + if(SiS_Pr->SiS_VBInfo & SetPALTV) index += 1; + } + return index; +} + +/* TW: Checked against 630/301B 2.04.50 and 630/LVDS BIOS (incl data) */ +static void +SetOEMTVDelay(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr, + UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex) +{ + USHORT index,temp,romptr=0; + + if((ROMAddr) && SiS_Pr->SiS_UseROM) { + if(!(ROMAddr[0x238] & 0x01)) return; + if(!(ROMAddr[0x238] & 0x02)) return; + romptr = ROMAddr[0x241] | (ROMAddr[0x242] << 8); + } + + temp = GetOEMTVPtr(SiS_Pr); + + index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVDelayIndex; + + if(romptr) { + romptr += (temp * 2); + romptr = ROMAddr[romptr] | (ROMAddr[romptr + 1] << 8); + romptr += index; + temp = ROMAddr[romptr]; + } else { + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + temp = SiS300_OEMTVDelay301[temp][index]; + } else { + temp = SiS300_OEMTVDelayLVDS[temp][index]; + } + } + temp &= 0x3c; + SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* index 0A D[6:4] */ +} + +/* TW: Checked against 630/301B 2.04.50 BIOS (incl data) */ +static void +SetOEMAntiFlicker(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, + USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo, + USHORT ModeIdIndex) +{ + USHORT index,temp,romptr=0; + + if((ROMAddr) && SiS_Pr->SiS_UseROM) { + if(!(ROMAddr[0x238] & 0x01)) return; + if(!(ROMAddr[0x238] & 0x04)) return; + romptr = ROMAddr[0x243] | (ROMAddr[0x244] << 8); + } + + temp = GetOEMTVPtr(SiS_Pr); + + index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVFlickerIndex; + + if(romptr) { + romptr += (temp * 2); + romptr = ROMAddr[romptr] | (ROMAddr[romptr + 1] << 8); + romptr += index; + temp = ROMAddr[romptr]; + } else { + temp = SiS300_OEMTVFlicker[temp][index]; + } + temp &= 0x70; + SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8F,temp); /* index 0A D[6:4] */ +} + +/* TW: Checked against 630/301B 2.04.50 BIOS (incl data) */ +static void +SetOEMPhaseIncr(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr, + UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex) +{ + USHORT index,i,j,temp,romptr=0; + + if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVisionTV) return; + + if((ROMAddr) && SiS_Pr->SiS_UseROM) { + if(!(ROMAddr[0x238] & 0x01)) return; + if(!(ROMAddr[0x238] & 0x08)) return; + romptr = ROMAddr[0x245] | (ROMAddr[0x246] << 8); + } + + temp = GetOEMTVPtr(SiS_Pr); + + index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVPhaseIndex; + + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + for(i=0x31, j=0; i<=0x34; i++, j++) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,SiS300_Phase2[temp][index][j]); + } + } else { + if(romptr) { + romptr += (temp * 2); + romptr = ROMAddr[romptr] | (ROMAddr[romptr + 1] << 8); + romptr += (index * 4); + for(i=0x31, j=0; i<=0x34; i++, j++) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]); + } + } else { + for(i=0x31, j=0; i<=0x34; i++, j++) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,SiS300_Phase1[temp][index][j]); + } + } + } +} + +/* TW: Checked against 630/301B 2.04.50 BIOS (incl data) */ +static void +SetOEMYFilter(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr, + UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex) +{ + USHORT index,temp,temp1,i,j,romptr=0; + + if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSCART | SetCRT2ToHiVisionTV)) return; + + if((ROMAddr) && SiS_Pr->SiS_UseROM) { + if(!(ROMAddr[0x238] & 0x01)) return; + if(!(ROMAddr[0x238] & 0x10)) return; + romptr = ROMAddr[0x247] | (ROMAddr[0x248] << 8); + } + + temp = GetOEMTVPtr(SiS_Pr); + + index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVYFilterIndex; + + if(HwDeviceExtension->jChipType > SIS_300) { + if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x31) & 0x01) { + temp1 = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x35); + if(temp1 & (EnablePALM | EnablePALN)) { + temp = 8; + if(!(temp1 & EnablePALM)) temp = 9; + } + } + } + if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { + for(i=0x35, j=0; i<=0x38; i++, j++) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]); + } + for(i=0x48; i<=0x4A; i++, j++) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]); + } + } else { + if(romptr) { + romptr += (temp * 2); + romptr = ROMAddr[romptr] | (ROMAddr[romptr + 1] << 8); + romptr += (index * 4); + for(i=0x35, j=0; i<=0x38; i++, j++) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]); + } + } else { + for(i=0x35, j=0; i<=0x38; i++, j++) { + SiS_SetReg1(SiS_Pr->SiS_Part2Port,i,SiS300_Filter1[temp][index][j]); + } + } + } +} + +void +SiS_OEM300Setting(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, + USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo) +{ + USHORT ModeIdIndex; + + ModeIdIndex = SiS_SearchVBModeID(SiS_Pr,ROMAddr,&ModeNo); + if(!(ModeIdIndex)) return; + + if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { + SetOEMLCDDelay(SiS_Pr,HwDeviceExtension,BaseAddr,ROMAddr,ModeNo,ModeIdIndex); + if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { + SetOEMLCDData(SiS_Pr,HwDeviceExtension,BaseAddr,ROMAddr,ModeNo,ModeIdIndex); + } + } + if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { + SetOEMTVDelay(SiS_Pr,HwDeviceExtension,BaseAddr,ROMAddr,ModeNo,ModeIdIndex); + if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { + SetOEMAntiFlicker(SiS_Pr,HwDeviceExtension,BaseAddr,ROMAddr,ModeNo,ModeIdIndex); + SetOEMPhaseIncr(SiS_Pr,HwDeviceExtension,BaseAddr,ROMAddr,ModeNo,ModeIdIndex); + SetOEMYFilter(SiS_Pr,HwDeviceExtension,BaseAddr,ROMAddr,ModeNo,ModeIdIndex); + } + } +} +#endif + + diff -ruN ../xc/xc/programs/Xserver/hw/xfree86/drivers/sis/init301.h xc/programs/Xserver/hw/xfree86/drivers/sis/init301.h --- ../xc/xc/programs/Xserver/hw/xfree86/drivers/sis/init301.h Wed Dec 31 16:00:00 1969 +++ xc/programs/Xserver/hw/xfree86/drivers/sis/init301.h Wed Aug 20 01:48:03 2003 @@ -0,0 +1,285 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/sis/init301.h,v 1.8 2003/01/29 15:42:16 eich Exp $ */ +#ifndef _INIT301_ +#define _INIT301_ + +#include "osdef.h" +#include "initdef.h" +#include "vgatypes.h" +#include "vstruct.h" + +#ifdef TC +#include +#include +#include +#include +#include +#endif + +#ifdef LINUX_XF86 +#include "xf86.h" +#include "xf86Pci.h" +#include "xf86PciInfo.h" +#include "sis.h" +#include "sis_regs.h" +#endif + +#ifdef LINUX_KERNEL +#include +#include +#include +#endif + +#ifdef WIN2000 +#include +#include +#include +#include "dderror.h" +#include "devioctl.h" +#include "miniport.h" +#include "ntddvdeo.h" +#include "video.h" +#include "sisv.h" +#endif + +#if 0 +extern const USHORT SiS_MDA_DAC[]; +extern const USHORT SiS_CGA_DAC[]; +extern const USHORT SiS_EGA_DAC[]; +extern const USHORT SiS_VGA_DAC[]; +#endif + +extern BOOLEAN SiS_SearchVBModeID(SiS_Private *SiS_Pr, UCHAR *RomAddr, USHORT *); + +BOOLEAN SiS_Is301B(SiS_Private *SiS_Pr, USHORT BaseAddr); +BOOLEAN SiS_IsM650or651(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr); +BOOLEAN SiS_IsDisableCRT2(SiS_Private *SiS_Pr, USHORT BaseAddr); +BOOLEAN SiS_IsVAMode(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr); +BOOLEAN SiS_IsDualEdge(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr); +BOOLEAN SiS_CRT2IsLCD(SiS_Private *SiS_Pr, USHORT BaseAddr, PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_SetDefCRT2ExtRegs(SiS_Private *SiS_Pr, USHORT BaseAddr); +USHORT SiS_GetRatePtrCRT2(SiS_Private *SiS_Pr, UCHAR *ROMAddr, USHORT ModeNo,USHORT ModeIdIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension); +BOOLEAN SiS_AdjustCRT2Rate(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT MODEIdIndex, + USHORT RefreshRateTableIndex,USHORT *i,PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_SaveCRT2Info(SiS_Private *SiS_Pr, USHORT ModeNo); +void SiS_GetCRT2Data(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_GetCRT2DataLVDS(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_GetCRT2PtrA(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,USHORT *CRT2Index,USHORT *ResIndex); +void SiS_GetCRT2Part2Ptr(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,USHORT *CRT2Index, USHORT *ResIndex); +void SiS_GetCRT2Data301(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension); +USHORT SiS_GetResInfo(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex); +void SiS_GetCRT2ResInfo(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_GetRAMDAC2DATA(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_GetCRT2Ptr(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,USHORT *CRT2Index,USHORT *ResIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT BaseAddr,USHORT ModeNo,USHORT ModeIdIndex, + PSIS_HW_DEVICE_INFO ); +void SiS_SetHiVision(SiS_Private *SiS_Pr, USHORT BaseAddr,PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_GetLVDSDesData(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_SetCRT2Offset(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension); +USHORT SiS_GetOffset(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension); +USHORT SiS_GetColorDepth(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex); +USHORT SiS_GetMCLK(SiS_Private *SiS_Pr, UCHAR *ROMAddr, PSIS_HW_DEVICE_INFO HwDeviceExtension); +USHORT SiS_CalcDelayVB(SiS_Private *SiS_Pr); +USHORT SiS_GetVCLK2Ptr(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_SetCRT2Sync(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_SetRegANDOR(USHORT Port,USHORT Index,USHORT DataAND,USHORT DataOR); +void SiS_SetRegOR(USHORT Port,USHORT Index,USHORT DataOR); +void SiS_SetRegAND(USHORT Port,USHORT Index,USHORT DataAND); +USHORT SiS_GetVGAHT2(SiS_Private *SiS_Pr); +void SiS_Set300Part2Regs(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, + USHORT ModeIdIndex, USHORT RefreshRateTableIndex, + USHORT BaseAddr, USHORT ModeNo); +void SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_SetGroup3(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_SetGroup4(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_SetGroup5(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo, + USHORT ModeIdIndex); +void SiS_FinalizeLCD(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_SetCRT2VCLK(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_EnableCRT2(SiS_Private *SiS_Pr); +void SiS_GetVBInfo(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension, int checkcrt2mode); +BOOLEAN SiS_BridgeIsOn(SiS_Private *SiS_Pr, USHORT BaseAddr,PSIS_HW_DEVICE_INFO); +BOOLEAN SiS_BridgeIsEnable(SiS_Private *SiS_Pr, USHORT BaseAddr,PSIS_HW_DEVICE_INFO); +BOOLEAN SiS_BridgeInSlave(SiS_Private *SiS_Pr); +void SiS_PresetScratchregister(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_SetTVSystem(SiS_Private *SiS_Pr); +void SiS_LongWait(SiS_Private *SiS_Pr); +USHORT SiS_GetQueueConfig(SiS_Private *SiS_Pr); +void SiS_VBLongWait(SiS_Private *SiS_Pr); +USHORT SiS_GetVCLKLen(SiS_Private *SiS_Pr, UCHAR *ROMAddr); +void SiS_WaitVBRetrace(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_WaitRetrace1(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_WaitRetrace2(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_WaitRetraceDDC(SiS_Private *SiS_Pr); +void SiS_SetCRT2ECLK(SiS_Private *SiS_Pr, UCHAR *ROMAddr, USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_GetLVDSDesPtr(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,USHORT *PanelIndex,USHORT *ResIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_GetLVDSDesPtrA(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,USHORT *PanelIndex,USHORT *ResIndex); +void SiS_SetTPData(SiS_Private *SiS_Pr); +void SiS_WhatIsThis(SiS_Private *SiS_Pr, USHORT myvbinfo); +void SiS_ModCRT1CRTC(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_SetCHTVReg(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex); +void SiS_GetCHTVRegPtr(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex); +void SiS_SetCH700x(SiS_Private *SiS_Pr, USHORT tempax); +USHORT SiS_GetCH700x(SiS_Private *SiS_Pr, USHORT tempax); +void SiS_SetCH701x(SiS_Private *SiS_Pr, USHORT tempax); +USHORT SiS_GetCH701x(SiS_Private *SiS_Pr, USHORT tempax); +void SiS_SetCH70xx(SiS_Private *SiS_Pr, USHORT tempax); +USHORT SiS_GetCH70xx(SiS_Private *SiS_Pr, USHORT tempax); +#ifdef LINUX_XF86 +USHORT SiS_I2C_GetByte(SiS_Private *SiS_Pr); +Bool SiS_I2C_PutByte(SiS_Private *SiS_Pr, USHORT data); +Bool SiS_I2C_Address(SiS_Private *SiS_Pr, USHORT addr); +void SiS_I2C_Stop(SiS_Private *SiS_Pr); +#endif +void SiS_SetCH70xxANDOR(SiS_Private *SiS_Pr, USHORT tempax,USHORT tempbh); +void SiS_SetSwitchDDC2(SiS_Private *SiS_Pr); +USHORT SiS_SetStart(SiS_Private *SiS_Pr); +USHORT SiS_SetStop(SiS_Private *SiS_Pr); +void SiS_DDC2Delay(SiS_Private *SiS_Pr, USHORT delaytime); +USHORT SiS_SetSCLKLow(SiS_Private *SiS_Pr); +USHORT SiS_SetSCLKHigh(SiS_Private *SiS_Pr); +USHORT SiS_ReadDDC2Data(SiS_Private *SiS_Pr, USHORT tempax); +USHORT SiS_WriteDDC2Data(SiS_Private *SiS_Pr, USHORT tempax); +USHORT SiS_CheckACK(SiS_Private *SiS_Pr); +USHORT SiS_ReadLCDDDC(SiS_Private *SiS_Pr, USHORT length, unsigned char *buffer); +#ifdef SIS315H +void SiS_OEM310Setting(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr, + UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex); +void SiS_OEMLCD(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr, + UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex); +#endif +#ifdef SIS300 +void SiS_OEM300Setting(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr, + UCHAR *ROMAddr,USHORT ModeNo); +#endif +BOOLEAN SiS_LowModeStuff(SiS_Private *SiS_Pr, USHORT ModeNo,PSIS_HW_DEVICE_INFO HwDeviceExtension); + +BOOLEAN SiS_GetLCDResInfo(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo, USHORT ModeIdIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension); +/* void SiS_CHACRT1CRTC(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex); */ + +BOOLEAN SiS_SetCRT2Group301(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo, + PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT RefreshRateTableIndex); +void SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT RefreshRateTableIndex); +void SiS_SetGroup1_LCDA(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT RefreshRateTableIndex); +void SiS_SetGroup1_301(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT RefreshRateTableIndex); +#ifdef SIS300 +void SiS_SetCRT2FIFO_300(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo, + PSIS_HW_DEVICE_INFO HwDeviceExtension); +#endif +#ifdef SIS315H +void SiS_SetCRT2FIFO_310(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo, + PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_CRT2AutoThreshold(SiS_Private *SiS_Pr, USHORT BaseAddr); +#endif +BOOLEAN SiS_GetLCDDDCInfo(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_UnLockCRT2(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO,USHORT BaseAddr); +void SiS_LockCRT2(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO,USHORT BaseAddr); +void SiS_DisableBridge(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO,USHORT BaseAddr); +void SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO,USHORT BaseAddr); +void SiS_SetPanelDelay(SiS_Private *SiS_Pr, UCHAR* ROMAddr,PSIS_HW_DEVICE_INFO,USHORT DelayTime); +void SiS_ShortDelay(SiS_Private *SiS_Pr, USHORT delay); +void SiS_LongDelay(SiS_Private *SiS_Pr, USHORT delay); +void SiS_GenericDelay(SiS_Private *SiS_Pr, USHORT delay); +void SiS_VBWait(SiS_Private *SiS_Pr); + +void SiS_SiS30xBLOn(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension); +void SiS_SiS30xBLOff(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension); + +/* TW: New functions (with mostly temporary names) */ +void SiS_Chrontel701xBLOn(SiS_Private *SiS_Pr); +void SiS_Chrontel701xOn(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, + USHORT BaseAddr); +void SiS_Chrontel701xBLOff(SiS_Private *SiS_Pr); +void SiS_Chrontel701xOff(SiS_Private *SiS_Pr); +void SiS_ChrontelResetDB(SiS_Private *SiS_Pr); +void SiS_ChrontelDoSomething4(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr); +void SiS_ChrontelDoSomething3(SiS_Private *SiS_Pr, USHORT ModeNo, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr); +void SiS_ChrontelDoSomething2(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr); +void SiS_ChrontelDoSomething1(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr); +BOOLEAN SiS_WeHaveBacklightCtrl(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr); +#if 0 +BOOLEAN SiS_IsSomethingCR5F(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr); +#endif +BOOLEAN SiS_IsYPbPr(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr); +BOOLEAN SiS_IsChScart(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr); +BOOLEAN SiS_IsTVOrYPbPrOrScart(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr); +BOOLEAN SiS_IsLCDOrLCDA(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr); +void SiS_SetCH701xForLCD(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT BaseAddr); +void SiS_ChrontelPowerSequencing(SiS_Private *SiS_Pr); +BOOLEAN SiS_CR36BIOSWord23b(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension); +BOOLEAN SiS_CR36BIOSWord23d(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension); +BOOLEAN SiS_IsSR13_CR30(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension); +/* TW end */ + +extern void SiS_SetReg1(USHORT, USHORT, USHORT); +extern void SiS_SetReg3(USHORT, USHORT); +extern UCHAR SiS_GetReg1(USHORT, USHORT); +extern UCHAR SiS_GetReg2(USHORT); +extern BOOLEAN SiS_SearchModeID(SiS_Private *SiS_Pr, UCHAR *ROMAddr, USHORT *ModeNo,USHORT *ModeIdIndex); +extern BOOLEAN SiS_GetRatePtr(SiS_Private *SiS_Pr, ULONG, USHORT); +extern void SiS_SetReg4(USHORT, ULONG); +extern ULONG SiS_GetReg3(USHORT); +extern void SiS_SetReg5(USHORT, USHORT); +extern USHORT SiS_GetReg4(USHORT); +extern void SiS_DisplayOff(SiS_Private *SiS_Pr); +extern void SiS_DisplayOn(SiS_Private *SiS_Pr); +extern UCHAR SiS_GetModePtr(SiS_Private *SiS_Pr, UCHAR *ROMAddr, USHORT ModeNo,USHORT ModeIdIndex); +extern BOOLEAN SiS_GetLCDACRT1Ptr(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,USHORT *ResInfo,USHORT *DisplayType); +extern BOOLEAN SiS_GetLVDSCRT1Ptr(SiS_Private *SiS_Pr, UCHAR *ROMAddr,USHORT ModeNo,USHORT ModeIdIndex, + USHORT RefreshRateTableIndex,USHORT *ResInfo,USHORT *DisplayType); +extern void SiS_LoadDAC(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO, UCHAR *ROMAddr,USHORT ModeNo, + USHORT ModeIdIndex); +#ifdef SIS315H +extern UCHAR SiS_Get310DRAMType(SiS_Private *SiS_Pr, UCHAR *ROMAddr,PSIS_HW_DEVICE_INFO HwDeviceExtension); +#endif + +#ifdef LINUX_XF86 +/* DDC functions */ +USHORT SiS_InitDDCRegs(SiS_Private *SiS_Pr, SISPtr pSiS, USHORT adaptnum, USHORT DDCdatatype); +USHORT SiS_WriteDABDDC(SiS_Private *SiS_Pr); +USHORT SiS_PrepareReadDDC(SiS_Private *SiS_Pr); +USHORT SiS_PrepareDDC(SiS_Private *SiS_Pr); +void SiS_SendACK(SiS_Private *SiS_Pr, USHORT yesno); +USHORT SiS_DoProbeDDC(SiS_Private *SiS_Pr); +USHORT SiS_ProbeDDC(SiS_Private *SiS_Pr); +USHORT SiS_ReadDDC(SiS_Private *SiS_Pr, SISPtr pSiS, USHORT DDCdatatype, unsigned char *buffer); +USHORT SiS_HandleDDC(SiS_Private *SiS_Pr, SISPtr pSiS, USHORT adaptnum, + USHORT DDCdatatype, unsigned char *buffer); +#endif + +#endif diff -ruN ../xc/xc/programs/Xserver/hw/xfree86/drivers/sis/initdef.h xc/programs/Xserver/hw/xfree86/drivers/sis/initdef.h --- ../xc/xc/programs/Xserver/hw/xfree86/drivers/sis/initdef.h Wed Dec 31 16:00:00 1969 +++ xc/programs/Xserver/hw/xfree86/drivers/sis/initdef.h Wed Aug 20 01:48:03 2003 @@ -0,0 +1,434 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/sis/initdef.h,v 1.8 2003/01/29 15:42:16 eich Exp $ */ + + +#ifndef _INITDEF_ +#define _INITDEF_ + +#define SiS300 0x0300 +#define SiS540 0x5300 +#define SiS630 0x6300 +#define SiS730 0x6300 + +/* SiS_VBType */ +#define VB_SIS301 0x0001 +#define VB_SIS301B 0x0002 +#define VB_SIS302B 0x0004 +#define VB_SIS30xLV 0x0008 +#define VB_SIS30xNEW 0x0010 +#define VB_NoLCD 0x8000 +#define VB_SIS301BLV302BLV (VB_SIS301B|VB_SIS302B|VB_SIS30xLV|VB_SIS30xNEW) +#define VB_SIS301B302B (VB_SIS301B|VB_SIS302B) +#define VB_SIS301LV302LV (VB_SIS30xLV|VB_SIS30xNEW) + +#define IS_SIS650740 ((HwDeviceExtension->jChipType >= SIS_650) && (HwDeviceExtension->jChipType < SIS_330)) + +#define CRT1Len 17 +#define LVDSCRT1Len 15 +#define CHTVRegDataLen 5 + +/* SiS_ModeType */ +#define ModeText 0x00 +#define ModeCGA 0x01 +#define ModeEGA 0x02 +#define ModeVGA 0x03 +#define Mode15Bpp 0x04 +#define Mode16Bpp 0x05 +#define Mode24Bpp 0x06 +#define Mode32Bpp 0x07 + +#define ModeInfoFlag 0x07 +#define IsTextMode 0x07 + +#define DACInfoFlag 0x0018 +#define MemoryInfoFlag 0x01E0 +#define MemorySizeShift 5 + +/* modeflag */ +#define Charx8Dot 0x0200 +#define LineCompareOff 0x0400 +#define CRT2Mode 0x0800 +#define HalfDCLK 0x1000 +#define NoSupportSimuTV 0x2000 +#define DoubleScanMode 0x8000 + +/* Infoflag */ +#define SupportAllCRT2 0x0078 +#define SupportTV 0x0008 +#define SupportHiVisionTV 0x0010 +#define SupportLCD 0x0020 +#define SupportRAMDAC2 0x0040 +#define NoSupportTV 0x0070 +#define NoSupportHiVisionTV 0x0060 +#define NoSupportLCD 0x0058 +#define SupportCHTV 0x0800 +#define SupportTV1024 0x0800 +#define InterlaceMode 0x0080 +#define SyncPP 0x0000 +#define SyncPN 0x4000 +#define SyncNP 0x8000 +#define SyncNN 0xc000 +#define ECLKindex0 0x0000 +#define ECLKindex1 0x0100 +#define ECLKindex2 0x0200 +#define ECLKindex3 0x0300 +#define ECLKindex4 0x0400 + +/* VBInfo */ +#define SetSimuScanMode 0x0001 /* CR 30 */ +#define SwitchToCRT2 0x0002 +#define SetCRT2ToAVIDEO 0x0004 +#define SetCRT2ToSVIDEO 0x0008 +#define SetCRT2ToSCART 0x0010 +#define SetCRT2ToLCD 0x0020 +#define SetCRT2ToRAMDAC 0x0040 +#define SetCRT2ToHiVisionTV 0x0080 +#define SetCRT2ToTV 0x009C /* alias */ +#define SetNTSCTV 0x0000 /* CR 31 */ +#define SetPALTV 0x0100 +#define SetInSlaveMode 0x0200 +#define SetNotSimuMode 0x0400 +#define SetNotSimuTVMode 0x0400 +#define SetDispDevSwitch 0x0800 +#define LoadDACFlag 0x1000 +#define SetCHTVOverScan 0x1000 /* TW: Re-defined (from 0x8000) */ +#define DisableCRT2Display 0x2000 +#define CRT2DisplayFlag 0x2000 +#define DriverMode 0x4000 +#define HotKeySwitch 0x8000 /* TW: ? */ +#define SetCRT2ToLCDA 0x8000 + +#define PanelRGB18Bit 0x0100 +#define PanelRGB24Bit 0x0000 + +#define TVOverScan 0x10 /* Bit in CR35 (300 series only) */ +#define TVOverScanShift 4 +#define ClearBufferFlag 0x20 + +/* CR32 (Newer 630, and 310/325 series) + + [0] VB connected with CVBS + [1] VB connected with SVHS + [2] VB connected with SCART + [3] VB connected with LCD + [4] VB connected with CRT2 (secondary VGA) + [5] CRT1 monitor is connected + [6] VB connected with Hi-Vision TV + [7] VB connected with DVI combo connector + + + CR37 + + [0] Set 24/18 bit (0/1) RGB to LVDS/TMDS transmitter (set by BIOS) + [3:1] External chip + 300 series: + 001 SiS301 (never seen) + 010 LVDS + 011 LVDS + Tumpion Zurac + 100 LVDS + Chrontel 7005 + 110 Chrontel 7005 + 310/325 series + 001 SiS30x (never seen) + 010 LVDS + 011 LVDS + Chrontel 7019 + All other combinations reserved + [4] LVDS: Expanding(0)/Non-expanding(1) LCD display + 30x: SiS30x(0)/LCD monitor(1) scaling display + [5] LCD polarity select + 0: VESA DMT Standard + 1: EDID 2.x defined + [6] LCD horizontal polarity select + 0: High active + 1: Low active + [7] LCD vertical polarity select + 0: High active + 1: Low active +*/ + +/* CR38 (310/325 series) */ +#define EnableDualEdge 0x01 +#define SetToLCDA 0x02 /* LCD channel A (302B/LV and 650+LVDS only) */ +#define EnableSiSHiVision 0x04 /* HiVision (HDTV) on SiS bridge */ +#define EnableLVDSScart 0x04 /* Scart on Ch7019 (unofficial definition - TW) */ +#define EnableLVDSHiVision 0x08 /* YPbPr color format (480i HDTV); only on 650/Ch7019 systems */ +#define SiSHiVision1 0x10 /* See SetHiVision() */ +#define SiSHiVision2 0x20 +#define EnablePALM 0x40 /* 1 = Set PALM */ +#define EnablePALN 0x80 /* 1 = Set PALN */ + +#define SetSCARTOutput 0x01 +#define BoardTVType 0x02 + +#define EnablePALMN 0x40 /* Romflag: 1 = Allow PALM/PALN */ + +/* CR39 (650) */ +#define LCDPass1_1 0x01 /* LVDS only; set by driver to pass 1:1 data to LVDS output */ +#define SomeThingTV_LVNEW 0x04 /* 30xNEW only; set by mode switching function */ + + +/* CR79 (310/325 series only) + [3-0] Notify driver + 0001 Mode Switch event (set by BIOS) + 0010 Epansion On/Off event + 0011 TV UnderScan/OverScan event + 0100 Set Brightness event + 0101 Set Contrast event + 0110 Set Mute event + 0111 Set Volume Up/Down event + [4] Enable Backlight Control by BIOS/driver (set by driver) + [5] PAL/NTSC (set by BIOS) + [6] Expansion On/Off (set by BIOS; copied to CR32[4]) + [7] TV UnderScan/OverScan (set by BIOS) +*/ + +/* SetFlag */ +#define ProgrammingCRT2 0x01 +#define TVSimuMode 0x02 +#define RPLLDIV2XO 0x04 +#define LCDVESATiming 0x08 +#define EnableLVDSDDA 0x10 +#define SetDispDevSwitchFlag 0x20 +#define CheckWinDos 0x40 +#define SetJDOSMode 0x80 +#define CRT2IsVGA 0x80 /* TW: Not sure about this name... */ + +/* LCDResInfo */ +#define Panel300_800x600 0x01 /* CR36 */ +#define Panel300_1024x768 0x02 +#define Panel300_1280x1024 0x03 +#define Panel300_1280x960 0x04 +#define Panel300_640x480 0x05 +#define Panel300_1024x600 0x06 +#define Panel300_1152x768 0x07 +#define Panel300_320x480 0x08 /* fstn - TW: This is fake, can be any */ + +#define Panel310_800x600 0x01 +#define Panel310_1024x768 0x02 +#define Panel310_1280x1024 0x03 +#define Panel310_640x480 0x04 +#define Panel310_1024x600 0x05 +#define Panel310_1152x864 0x06 +#define Panel310_1280x960 0x07 +#define Panel310_1152x768 0x08 /* LVDS only */ +#define Panel310_1400x1050 0x09 +#define Panel310_1280x768 0x0a /* LVDS only */ +#define Panel310_1600x1200 0x0b +#define Panel310_320x480 0x0c /* fstn - TW: This is fake, can be any */ + +#define Panel_800x600 0x01 /* Unified values */ +#define Panel_1024x768 0x02 +#define Panel_1280x1024 0x03 +#define Panel_640x480 0x04 +#define Panel_1024x600 0x05 +#define Panel_1152x864 0x06 +#define Panel_1280x960 0x07 +#define Panel_1152x768 0x08 /* LVDS only */ +#define Panel_1400x1050 0x09 +#define Panel_1280x768 0x0a /* LVDS only */ +#define Panel_1600x1200 0x0b +#define Panel_320x480 0x0c /* fstn - TW: This is fake, can be any */ + +#define ExtChipType 0x0e +#define ExtChip301 0x02 +#define ExtChipLVDS 0x04 +#define ExtChipTrumpion 0x06 +#define ExtChipCH7005 0x08 +#define ExtChipMitacTV 0x0a /* TW: Incorrect, 0x0a = Chrontel 7005 only */ + +#define IsM650 0x80 /* TW: CR5F */ + +/* LCDInfo */ +#define LCDRGB18Bit 0x01 +#define LCDNonExpanding 0x10 +#define LCDNonExpandingShift 4 +#define LCDSync 0x20 +#define LCDPass11 0x100 +#define LCDSyncBit 0xe0 +#define LCDSyncShift 6 + +#define LCDDataLen 8 +#define HiTVDataLen 12 +#define TVDataLen 16 +#define SetPALTV 0x0100 +#define HalfDCLK 0x1000 /* modeflag */ +#define NTSCHT 1716 +#define NTSC2HT 1920 +#define NTSCVT 525 +#define PALHT 1728 +#define PALVT 625 +#define StHiTVHT 892 +#define StHiTVVT 1126 +#define StHiTextTVHT 1000 +#define StHiTextTVVT 1126 +#define ExtHiTVHT 2100 +#define ExtHiTVVT 1125 + +#define VCLKStartFreq 25 +#define SoftDramType 0x80 + +#define VCLK40 0x04 /* Index in VCLKData array */ +#define VCLK65 0x09 /* Index in VCLKData array */ +#define VCLK108_2 0x14 /* Index in VCLKData array */ +#define TVVCLKDIV2 0x21 /* Indices in (VB)VCLKData arrays */ +#define TVVCLK 0x22 +#define HiTVVCLKDIV2 0x23 +#define HiTVVCLK 0x24 +#define HiTVSimuVCLK 0x25 +#define HiTVTextVCLK 0x26 + +#define LoadDACFlag 0x1000 +#define AfterLockCRT2 0x4000 +#define SetCRT2ToAVIDEO 0x0004 +#define SetCRT2ToSCART 0x0010 +#define Ext2StructSize 5 + +#define SetSCARTOutput 0x01 +#define AVIDEOSense 0x01 +#define SVIDEOSense 0x02 +#define SCARTSense 0x04 +#define LCDSense 0x08 +#define Monitor1Sense 0x20 +#define Monitor2Sense 0x10 +#define HiTVSense 0x40 +#define BoardTVType 0x02 +#define HotPlugFunction 0x08 +#define StStructSize 0x06 + +#define SIS_CRT2_PORT_04 0x04 - 0x30 +#define SIS_CRT2_PORT_10 0x10 - 0x30 +#define SIS_CRT2_PORT_12 0x12 - 0x30 +#define SIS_CRT2_PORT_14 0x14 - 0x30 + +#define ADR_CRT2PtrData 0x20E +#define offset_Zurac 0x210 /* TW: Trumpion Zurac data pointer */ +#define ADR_LVDSDesPtrData 0x212 +#define ADR_LVDSCRT1DataPtr 0x214 +#define ADR_CHTVVCLKPtr 0x216 +#define ADR_CHTVRegDataPtr 0x218 + +#define LVDSDataLen 6 +#define EnableLVDSDDA 0x10 +#define LVDSDesDataLen 3 +#define ActiveNonExpanding 0x40 +#define ActiveNonExpandingShift 6 +#define ActivePAL 0x20 +#define ActivePALShift 5 +#define ModeSwitchStatus 0x0F +#define SoftTVType 0x40 +#define SoftSettingAddr 0x52 +#define ModeSettingAddr 0x53 + +#define SelectCRT1Rate 0x4 + +#define _PanelType00 0x00 +#define _PanelType01 0x08 +#define _PanelType02 0x10 +#define _PanelType03 0x18 +#define _PanelType04 0x20 +#define _PanelType05 0x28 +#define _PanelType06 0x30 +#define _PanelType07 0x38 +#define _PanelType08 0x40 +#define _PanelType09 0x48 +#define _PanelType0A 0x50 +#define _PanelType0B 0x58 +#define _PanelType0C 0x60 +#define _PanelType0D 0x68 +#define _PanelType0E 0x70 +#define _PanelType0F 0x78 + +#define PRIMARY_VGA 0 /* 1: SiS is primary vga 0:SiS is secondary vga */ +#define BIOSIDCodeAddr 0x235 /* TW: Offsets to ptrs in BIOS image */ +#define OEMUtilIDCodeAddr 0x237 +#define VBModeIDTableAddr 0x239 +#define OEMTVPtrAddr 0x241 +#define PhaseTableAddr 0x243 +#define NTSCFilterTableAddr 0x245 +#define PALFilterTableAddr 0x247 +#define OEMLCDPtr_1Addr 0x249 +#define OEMLCDPtr_2Addr 0x24B +#define LCDHPosTable_1Addr 0x24D +#define LCDHPosTable_2Addr 0x24F +#define LCDVPosTable_1Addr 0x251 +#define LCDVPosTable_2Addr 0x253 +#define OEMLCDPIDTableAddr 0x255 + +#define VBModeStructSize 5 +#define PhaseTableSize 4 +#define FilterTableSize 4 +#define LCDHPosTableSize 7 +#define LCDVPosTableSize 5 +#define OEMLVDSPIDTableSize 4 +#define LVDSHPosTableSize 4 +#define LVDSVPosTableSize 6 + +#define VB_ModeID 0 +#define VB_TVTableIndex 1 +#define VB_LCDTableIndex 2 +#define VB_LCDHIndex 3 +#define VB_LCDVIndex 4 + +#define OEMLCDEnable 0x0001 +#define OEMLCDDelayEnable 0x0002 +#define OEMLCDPOSEnable 0x0004 +#define OEMTVEnable 0x0100 +#define OEMTVDelayEnable 0x0200 +#define OEMTVFlickerEnable 0x0400 +#define OEMTVPhaseEnable 0x0800 +#define OEMTVFilterEnable 0x1000 + +#define OEMLCDPanelIDSupport 0x0080 + +/* + ============================================================= + for 310/325 series + ============================================================= +*/ +#define SoftDRAMType 0x80 +#define SoftSetting_OFFSET 0x52 +#define SR07_OFFSET 0x7C +#define SR15_OFFSET 0x7D +#define SR16_OFFSET 0x81 +#define SR17_OFFSET 0x85 +#define SR19_OFFSET 0x8D +#define SR1F_OFFSET 0x99 +#define SR21_OFFSET 0x9A +#define SR22_OFFSET 0x9B +#define SR23_OFFSET 0x9C +#define SR24_OFFSET 0x9D +#define SR25_OFFSET 0x9E +#define SR31_OFFSET 0x9F +#define SR32_OFFSET 0xA0 +#define SR33_OFFSET 0xA1 + +#define CR40_OFFSET 0xA2 +#define SR25_1_OFFSET 0xF6 +#define CR49_OFFSET 0xF7 + +#define VB310Data_1_2_Offset 0xB6 +#define VB310Data_4_D_Offset 0xB7 +#define VB310Data_4_E_Offset 0xB8 +#define VB310Data_4_10_Offset 0xBB + +#define RGBSenseDataOffset 0xBD +#define YCSenseDataOffset 0xBF +#define VideoSenseDataOffset 0xC1 +#define OutputSelectOffset 0xF3 + +#define ECLK_MCLK_DISTANCE 0x14 +#define VBIOSTablePointerStart 0x100 +#define StandTablePtrOffset VBIOSTablePointerStart+0x02 +#define EModeIDTablePtrOffset VBIOSTablePointerStart+0x04 +#define CRT1TablePtrOffset VBIOSTablePointerStart+0x06 +#define ScreenOffsetPtrOffset VBIOSTablePointerStart+0x08 +#define VCLKDataPtrOffset VBIOSTablePointerStart+0x0A +#define MCLKDataPtrOffset VBIOSTablePointerStart+0x0E +#define CRT2PtrDataPtrOffset VBIOSTablePointerStart+0x10 +#define TVAntiFlickPtrOffset VBIOSTablePointerStart+0x12 +#define TVDelayPtr1Offset VBIOSTablePointerStart+0x14 +#define TVPhaseIncrPtr1Offset VBIOSTablePointerStart+0x16 +#define TVYFilterPtr1Offset VBIOSTablePointerStart+0x18 +#define LCDDelayPtr1Offset VBIOSTablePointerStart+0x20 +#define TVEdgePtr1Offset VBIOSTablePointerStart+0x24 +#define CRT2Delay1Offset VBIOSTablePointerStart+0x28 + +#endif diff -ruN ../xc/xc/programs/Xserver/hw/xfree86/drivers/sis/sis.h xc/programs/Xserver/hw/xfree86/drivers/sis/sis.h --- ../xc/xc/programs/Xserver/hw/xfree86/drivers/sis/sis.h Tue Aug 12 12:04:07 2003 +++ xc/programs/Xserver/hw/xfree86/drivers/sis/sis.h Wed Aug 20 02:34:58 2003 @@ -129,7 +129,7 @@ #define SIS_NAME "SIS" #define SIS_DRIVER_NAME "sis" #define SIS_MAJOR_VERSION 0 -#define SIS_MINOR_VERSION 6 +#define SIS_MINOR_VERSION 7 #define SIS_PATCHLEVEL 0 #define SIS_CURRENT_VERSION ((SIS_MAJOR_VERSION << 16) | \ (SIS_MINOR_VERSION << 8) | SIS_PATCHLEVEL ) diff -ruN ../xc/xc/programs/Xserver/hw/xfree86/drivers/sis/sis_common.h xc/programs/Xserver/hw/xfree86/drivers/sis/sis_common.h --- ../xc/xc/programs/Xserver/hw/xfree86/drivers/sis/sis_common.h Wed Dec 31 16:00:00 1969 +++ xc/programs/Xserver/hw/xfree86/drivers/sis/sis_common.h Tue Aug 12 12:03:34 2003 @@ -0,0 +1,60 @@ +/* sis_common.h -- common header definitions for SiS 2D/3D/DRM suite + * Created: Sun Apr 9 18:16:28 2000 by kevin@precisioninsight.com + * + * Copyright 2003 Eric Anholt + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Author: + * Eric Anholt + * + * $XFree86$ + * + */ + +#ifndef _SIS_COMMON_H_ +#define _SIS_COMMON_H_ + +#define DRM_SIS_FB_ALLOC 0x04 +#define DRM_SIS_FB_FREE 0x05 +#define DRM_SIS_FLIP 0x08 +#define DRM_SIS_FLIP_INIT 0x09 +#define DRM_SIS_FLIP_FINAL 0x10 +#define DRM_SIS_AGP_INIT 0x13 +#define DRM_SIS_AGP_ALLOC 0x14 +#define DRM_SIS_AGP_FREE 0x15 + +typedef struct { + int context; + unsigned long offset; + unsigned long size; + void *free; +} drm_sis_mem_t; + +typedef struct { + unsigned long offset, size; +} drm_sis_agp_t; + +typedef struct { + unsigned int left, right; +} drm_sis_flip_t; + +#endif /* _SIS_COMMON_H_ */ diff -ruN ../xc/xc/programs/Xserver/hw/xfree86/drivers/sis/sis_dri.c xc/programs/Xserver/hw/xfree86/drivers/sis/sis_dri.c --- ../xc/xc/programs/Xserver/hw/xfree86/drivers/sis/sis_dri.c Tue Aug 12 12:04:07 2003 +++ xc/programs/Xserver/hw/xfree86/drivers/sis/sis_dri.c Wed Aug 20 02:34:58 2003 @@ -242,9 +242,9 @@ ((pciConfigPtr)pSIS->PciInfo->thisCard)->busnum, ((pciConfigPtr)pSIS->PciInfo->thisCard)->devnum, ((pciConfigPtr)pSIS->PciInfo->thisCard)->funcnum); - pDRIInfo->ddxDriverMajorVersion = 0; - pDRIInfo->ddxDriverMinorVersion = 1; - pDRIInfo->ddxDriverPatchVersion = 0; + pDRIInfo->ddxDriverMajorVersion = SIS_MAJOR_VERSION; + pDRIInfo->ddxDriverMinorVersion = SIS_MINOR_VERSION; + pDRIInfo->ddxDriverPatchVersion = SIS_PATCHLEVEL; pDRIInfo->frameBufferPhysicalAddress = pSIS->FbAddress; @@ -503,6 +503,7 @@ /* TODO */ pSISDRI->scrnX=pSISDRI->width; pSISDRI->scrnY=pSISDRI->height; + pSISDRI->sarea_priv_offset = sizeof(XF86DRISAREARec); /* pSISDRI->textureOffset=pSiS->texOffset; @@ -520,7 +521,7 @@ assert(saPriv); - saPriv->CtxOwner = -1; + saPriv->ctxOwner = -1; saPriv->QueueLength = 0; pSiS->cmdQueueLenPtr = &(saPriv->QueueLength); saPriv->AGPCmdBufNext = 0; diff -ruN ../xc/xc/programs/Xserver/hw/xfree86/drivers/sis/sis_dri.h xc/programs/Xserver/hw/xfree86/drivers/sis/sis_dri.h --- ../xc/xc/programs/Xserver/hw/xfree86/drivers/sis/sis_dri.h Tue Aug 12 12:04:07 2003 +++ xc/programs/Xserver/hw/xfree86/drivers/sis/sis_dri.h Tue Aug 12 12:03:34 2003 @@ -7,15 +7,10 @@ #include "xf86drm.h" +#include "sis_sarea.h" + #define SIS_MAX_DRAWABLES 256 #define SISIOMAPSIZE (64*1024) - -typedef struct { - int CtxOwner; - int QueueLength; - unsigned int AGPCmdBufNext; - unsigned int FrameCount; -} SISSAREAPriv; #define SIS_FRONT 0 #define SIS_BACK 1 diff -ruN ../xc/xc/programs/Xserver/hw/xfree86/drivers/sis/sis_driver.h xc/programs/Xserver/hw/xfree86/drivers/sis/sis_driver.h --- ../xc/xc/programs/Xserver/hw/xfree86/drivers/sis/sis_driver.h Wed Dec 31 16:00:00 1969 +++ xc/programs/Xserver/hw/xfree86/drivers/sis/sis_driver.h Wed Aug 20 01:48:03 2003 @@ -0,0 +1,512 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/sis/sis_driver.h,v 1.6 2003/01/29 15:42:17 eich Exp $ */ +/* + * sis_driver.h + * + * Copyright 2002 by Thomas Winischhofer, Vienna, Austria. + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the copyright holder not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The copyright holder makes no representations + * about the suitability of this software for any purpose. It is provided + * "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + * Author: Thomas Winischhofer : + * - 310/325 series (315/550/650/651/740/M650) support + * - new mode switching code for 300 and 310/325 series + * - many fixes for 300/540/630/730 chipsets, + * - many fixes for 5597/5598, 6326 and 530/620 chipsets, + * - VESA mode switching (deprecated), + * - extended CRT2/video bridge handling support, + * - dual head support on 300 and 310/325 series + * - 650/LVDS (up to 1400x1050), 650/Chrontel 701x support + * - 30xB/30xLV/30xLVX video bridge support (300, 310/325 series) + * - Xv support for 5597/5598, 6326, 530/620 and 310/325 series + * - video overlay enhancements for 300 series + * - etc. + */ + +/* VESA */ +/* TW: The following is included because there are BIOSes out there that + * report incomplete mode lists. These are 630 BIOS versions <2.01.2x + * + * -) VBE 3.0 on SiS300 and 310/325 series do not support 24 fpp modes + * -) Only SiS310/325 series support 1920x1440x32 + */ + /* 8 16 (24) 32 */ +static const UShort VESAModeIndex_512x384[] = {0x134, 0x137, 0x000, 0x000}; +static const UShort VESAModeIndex_640x480[] = {0x101, 0x111, 0x000, 0x13a}; +static const UShort VESAModeIndex_800x600[] = {0x103, 0x114, 0x000, 0x13b}; +static const UShort VESAModeIndex_1024x768[] = {0x105, 0x117, 0x000, 0x13c}; +static const UShort VESAModeIndex_1280x1024[] = {0x107, 0x11a, 0x000, 0x13d}; +static const UShort VESAModeIndex_1600x1200[] = {0x130, 0x131, 0x000, 0x13e}; +static const UShort VESAModeIndex_1920x1440[] = {0x13f, 0x140, 0x000, 0x141}; + +/* TW: For calculating refresh rate index (CR33) */ +static const struct _sis_vrate { + CARD16 idx; + CARD16 xres; + CARD16 yres; + CARD16 refresh; + BOOLEAN SiS730valid32bpp; +} sisx_vrate[] = { + {1, 512, 384, 60, TRUE}, + {1, 640, 400, 72, TRUE}, + {1, 640, 480, 60, TRUE}, {2, 640, 480, 72, TRUE}, {3, 640, 480, 75, TRUE}, + {4, 640, 480, 85, TRUE}, {5, 640, 480, 100, TRUE}, {6, 640, 480, 120, TRUE}, + {7, 640, 480, 160, TRUE}, {8, 640, 480, 200, TRUE}, + {1, 720, 480, 60, TRUE}, + {1, 720, 576, 58, TRUE}, + {1, 800, 480, 60, TRUE}, {2, 800, 480, 75, TRUE}, {3, 800, 480, 85, TRUE}, + {1, 800, 600, 56, TRUE}, {2, 800, 600, 60, TRUE}, {3, 800, 600, 72, TRUE}, + {4, 800, 600, 75, TRUE}, {5, 800, 600, 85, TRUE}, {6, 800, 600, 105, TRUE}, + {7, 800, 600, 120, TRUE}, {8, 800, 600, 160, TRUE}, + {1, 848, 480, 39, TRUE}, {2, 848, 480, 60, TRUE}, + {1, 856, 480, 39, TRUE}, {2, 856, 480, 60, TRUE}, + {1, 1024, 768, 43, TRUE}, {2, 1024, 768, 60, TRUE}, {3, 1024, 768, 70, FALSE}, + {4, 1024, 768, 75, FALSE}, {5, 1024, 768, 85, TRUE}, {6, 1024, 768, 100, TRUE}, + {7, 1024, 768, 120, TRUE}, + {1, 1024, 576, 60, TRUE}, {2, 1024, 576, 75, TRUE}, {3, 1024, 576, 85, TRUE}, + {1, 1024, 600, 60, TRUE}, + {1, 1152, 768, 60, TRUE}, + {1, 1152, 864, 75, TRUE}, {2, 1152, 864, 84, TRUE}, + {1, 1280, 720, 60, TRUE}, {2, 1280, 720, 75, TRUE}, {3, 1280, 720, 85, TRUE}, + {1, 1280, 768, 60, TRUE}, + {1, 1280, 1024, 43, TRUE}, {2, 1280, 1024, 60, TRUE}, {3, 1280, 1024, 75, TRUE}, + {4, 1280, 1024, 85, TRUE}, + {1, 1280, 960, 60, TRUE}, {2, 1280, 960, 85, TRUE}, + {1, 1360, 768, 60, TRUE}, + {1, 1400, 1050, 60, TRUE}, {2, 1400, 1050, 75, TRUE}, + {1, 1600, 1200, 60, TRUE}, {2, 1600, 1200, 65, TRUE}, {3, 1600, 1200, 70, TRUE}, + {4, 1600, 1200, 75, TRUE}, {5, 1600, 1200, 85, TRUE}, {6, 1600, 1200, 100, TRUE}, + {7, 1600, 1200, 120, TRUE}, + {1, 1920, 1440, 60, TRUE}, {2, 1920, 1440, 65, TRUE}, {3, 1920, 1440, 70, TRUE}, + {4, 1920, 1440, 75, TRUE}, {5, 1920, 1440, 85, TRUE}, {6, 1920, 1440, 100, TRUE}, + {1, 2048, 1536, 60, TRUE}, {2, 2048, 1536, 65, TRUE}, {3, 2048, 1536, 70, TRUE}, + {4, 2048, 1536, 75, TRUE}, {5, 2048, 1536, 85, TRUE}, + {0, 0, 0, 0, FALSE} +}; + +/* TW: Some 300-series laptops have a badly designed BIOS and make it + * impossible to detect the correct panel delay compensation. This + * table used to detect such machines by their PCI subsystem IDs; + * however, I don't know how reliable this method is. (With Asus + * machines, it is to general, ASUS uses the same ID for different + * boxes) + */ +static const pdctable mypdctable[] = { + { 0x1071, 0x7522, 32, "Mitac", "7521T" }, + { 0, 0, 0, "" , "" } +}; + +static const chswtable mychswtable[] = { + { 0x1631, 0x1002, "Mitachi", "0x1002" }, + { 0, 0, "" , "" } +}; + +/* TW: Our TV modes for the 6326. The data in these structures + * is mainly correct, but since we use our private CR and + * clock values anyway, small errors do no matter. + */ +static DisplayModeRec SiS6326PAL800x600Mode = { + NULL, NULL, /* prev, next */ + "PAL800x600", /* identifier of this mode */ + MODE_OK, /* mode status */ + M_T_BUILTIN, /* mode type */ + 36000, /* Clock frequency */ + 800, /* HDisplay */ + 848, /* HSyncStart */ + 912, /* HSyncEnd */ + 1008, /* HTotal */ + 0, /* HSkew */ + 600, /* VDisplay */ + 600, /* VSyncStart */ + 602, /* VSyncEnd */ + 625, /* VTotal */ + 0, /* VScan */ + V_PHSYNC | V_PVSYNC, /* Flags */ + -1, /* ClockIndex */ + 36000, /* SynthClock */ + 800, /* CRTC HDisplay */ + 808, /* CRTC HBlankStart */ + 848, /* CRTC HSyncStart */ + 912, /* CRTC HSyncEnd */ + 1008, /* CRTC HBlankEnd */ + 1008, /* CRTC HTotal */ + 0, /* CRTC HSkew */ + 600, /* CRTC VDisplay */ + 600, /* CRTC VBlankStart */ + 600, /* CRTC VSyncStart */ + 602, /* CRTC VSyncEnd */ + 625, /* CRTC VBlankEnd */ + 625, /* CRTC VTotal */ + FALSE, /* CrtcHAdjusted */ + FALSE, /* CrtcVAdjusted */ + 0, /* PrivSize */ + NULL, /* Private */ + 0.0, /* HSync */ + 0.0 /* VRefresh */ +}; + +/* TW: Due to the scaling method this mode uses, the vertical data here + * does not match the CR data. But this does not matter, we use our + * private CR data anyway. + */ +static DisplayModeRec SiS6326PAL800x600UMode = { + NULL, /* prev */ + &SiS6326PAL800x600Mode, /* next */ + "PAL800x600U", /* identifier of this mode */ + MODE_OK, /* mode status */ + M_T_BUILTIN, /* mode type */ + 37120, /* Clock frequency */ + 800, /* HDisplay */ + 872, /* HSyncStart */ + 984, /* HSyncEnd */ + 1088, /* HTotal */ + 0, /* HSkew */ + 600, /* VDisplay (548 due to scaling) */ + 600, /* VSyncStart (584) */ + 602, /* VSyncEnd (586) */ + 625, /* VTotal */ + 0, /* VScan */ + V_PHSYNC | V_PVSYNC, /* Flags */ + -1, /* ClockIndex */ + 37120, /* SynthClock */ + 800, /* CRTC HDisplay */ + 808, /* CRTC HBlankStart */ + 872, /* CRTC HSyncStart */ + 984, /* CRTC HSyncEnd */ + 1024, /* CRTC HBlankEnd */ + 1088, /* CRTC HTotal */ + 0, /* CRTC HSkew */ + 600, /* CRTC VDisplay (548 due to scaling) */ + 600, /* CRTC VBlankStart (600) */ + 600, /* CRTC VSyncStart (584) */ + 602, /* CRTC VSyncEnd (586) */ + 625, /* CRTC VBlankEnd */ + 625, /* CRTC VTotal */ + FALSE, /* CrtcHAdjusted */ + FALSE, /* CrtcVAdjusted */ + 0, /* PrivSize */ + NULL, /* Private */ + 0.0, /* HSync */ + 0.0 /* VRefresh */ +}; + +static DisplayModeRec SiS6326PAL720x540Mode = { + NULL, /* prev */ + &SiS6326PAL800x600UMode, /* next */ + "PAL720x540", /* identifier of this mode */ + MODE_OK, /* mode status */ + M_T_BUILTIN, /* mode type */ + 36000, /* Clock frequency */ + 720, /* HDisplay */ + 816, /* HSyncStart */ + 920, /* HSyncEnd */ + 1008, /* HTotal */ + 0, /* HSkew */ + 540, /* VDisplay */ + 578, /* VSyncStart */ + 580, /* VSyncEnd */ + 625, /* VTotal */ + 0, /* VScan */ + V_PHSYNC | V_PVSYNC, /* Flags */ + -1, /* ClockIndex */ + 36000, /* SynthClock */ + 720, /* CRTC HDisplay */ + 736, /* CRTC HBlankStart */ + 816, /* CRTC HSyncStart */ + 920, /* CRTC HSyncEnd */ + 1008, /* CRTC HBlankEnd */ + 1008, /* CRTC HTotal */ + 0, /* CRTC HSkew */ + 540, /* CRTC VDisplay */ + 577, /* CRTC VBlankStart */ + 578, /* CRTC VSyncStart */ + 580, /* CRTC VSyncEnd */ + 625, /* CRTC VBlankEnd */ + 625, /* CRTC VTotal */ + FALSE, /* CrtcHAdjusted */ + FALSE, /* CrtcVAdjusted */ + 0, /* PrivSize */ + NULL, /* Private */ + 0.0, /* HSync */ + 0.0 /* VRefresh */ +}; + +static DisplayModeRec SiS6326PAL640x480Mode = { + NULL, /* prev */ + &SiS6326PAL720x540Mode, /* next */ + "PAL640x480", /* identifier of this mode */ + MODE_OK, /* mode status */ + M_T_BUILTIN, /* mode type */ + 36000, /* Clock frequency */ + 640, /* HDisplay */ + 768, /* HSyncStart */ + 920, /* HSyncEnd */ + 1008, /* HTotal */ + 0, /* HSkew */ + 480, /* VDisplay */ + 532, /* VSyncStart */ + 534, /* VSyncEnd */ + 625, /* VTotal */ + 0, /* VScan */ + V_NHSYNC | V_NVSYNC, /* Flags */ + -1, /* ClockIndex */ + 36000, /* SynthClock */ + 640, /* CRTC HDisplay */ + 648, /* CRTC HBlankStart */ + 768, /* CRTC HSyncStart */ + 920, /* CRTC HSyncEnd */ + 944, /* CRTC HBlankEnd */ + 1008, /* CRTC HTotal */ + 0, /* CRTC HSkew */ + 480, /* CRTC VDisplay */ + 481, /* CRTC VBlankStart */ + 532, /* CRTC VSyncStart */ + 534, /* CRTC VSyncEnd */ + 561, /* CRTC VBlankEnd */ + 625, /* CRTC VTotal */ + FALSE, /* CrtcHAdjusted */ + FALSE, /* CrtcVAdjusted */ + 0, /* PrivSize */ + NULL, /* Private */ + 0.0, /* HSync */ + 0.0 /* VRefresh */ +}; + +static DisplayModeRec SiS6326NTSC640x480Mode = { + NULL, NULL, /* prev, next */ + "NTSC640x480", /* identifier of this mode */ + MODE_OK, /* mode status */ + M_T_BUILTIN, /* mode type */ + 27000, /* Clock frequency */ + 640, /* HDisplay */ + 664, /* HSyncStart */ + 760, /* HSyncEnd */ + 800, /* HTotal */ + 0, /* HSkew */ + 480, /* VDisplay */ + 489, /* VSyncStart */ + 491, /* VSyncEnd */ + 525, /* VTotal */ + 0, /* VScan */ + V_NHSYNC | V_NVSYNC, /* Flags */ + -1, /* ClockIndex */ + 27000, /* SynthClock */ + 640, /* CRTC HDisplay */ + 648, /* CRTC HBlankStart */ + 664, /* CRTC HSyncStart */ + 760, /* CRTC HSyncEnd */ + 792, /* CRTC HBlankEnd */ + 800, /* CRTC HTotal */ + 0, /* CRTC HSkew */ + 480, /* CRTC VDisplay */ + 488, /* CRTC VBlankStart */ + 489, /* CRTC VSyncStart */ + 491, /* CRTC VSyncEnd */ + 517, /* CRTC VBlankEnd */ + 525, /* CRTC VTotal */ + FALSE, /* CrtcHAdjusted */ + FALSE, /* CrtcVAdjusted */ + 0, /* PrivSize */ + NULL, /* Private */ + 0.0, /* HSync */ + 0.0 /* VRefresh */ +}; + +/* TW: Due to the scaling method this mode uses, the vertical data here + * does not match the CR data. But this does not matter, we use our + * private CR data anyway. + */ +static DisplayModeRec SiS6326NTSC640x480UMode = { + NULL, /* prev */ + &SiS6326NTSC640x480Mode, /* next */ + "NTSC640x480U", /* identifier of this mode */ + MODE_OK, /* mode status */ + M_T_BUILTIN, /* mode type */ + 32215, /* Clock frequency */ + 640, /* HDisplay */ + 696, /* HSyncStart */ + 840, /* HSyncEnd */ + 856, /* HTotal */ + 0, /* HSkew */ + 480, /* VDisplay (439 due to scaling) */ + 489, /* VSyncStart (473) */ + 491, /* VSyncEnd (475) */ + 525, /* VTotal */ + 0, /* VScan */ + V_NHSYNC | V_NVSYNC, /* Flags */ + -1, /* ClockIndex */ + 32215, /* SynthClock */ + 640, /* CRTC HDisplay */ + 656, /* CRTC HBlankStart */ + 696, /* CRTC HSyncStart */ + 840, /* CRTC HSyncEnd */ + 856, /* CRTC HBlankEnd */ + 856, /* CRTC HTotal */ + 0, /* CRTC HSkew */ + 480, /* CRTC VDisplay */ + 488, /* CRTC VBlankStart */ + 489, /* CRTC VSyncStart */ + 491, /* CRTC VSyncEnd */ + 517, /* CRTC VBlankEnd */ + 525, /* CRTC VTotal */ + FALSE, /* CrtcHAdjusted */ + FALSE, /* CrtcVAdjusted */ + 0, /* PrivSize */ + NULL, /* Private */ + 0.0, /* HSync */ + 0.0 /* VRefresh */ +}; + + +static DisplayModeRec SiS6326NTSC640x400Mode = { + NULL, /* prev */ + &SiS6326NTSC640x480UMode, /* next */ + "NTSC640x400", /* identifier of this mode */ + MODE_OK, /* mode status */ + M_T_BUILTIN, /* mode type */ + 27000, /* Clock frequency */ + 640, /* HDisplay */ + 664, /* HSyncStart */ + 760, /* HSyncEnd */ + 800, /* HTotal */ + 0, /* HSkew */ + 400, /* VDisplay */ + 459, /* VSyncStart */ + 461, /* VSyncEnd */ + 525, /* VTotal */ + 0, /* VScan */ + V_NHSYNC | V_NVSYNC, /* Flags */ + -1, /* ClockIndex */ + 27000, /* SynthClock */ + 640, /* CRTC HDisplay */ + 648, /* CRTC HBlankStart */ + 664, /* CRTC HSyncStart */ + 760, /* CRTC HSyncEnd */ + 792, /* CRTC HBlankEnd */ + 800, /* CRTC HTotal */ + 0, /* CRTC HSkew */ + 400, /* CRTC VDisplay */ + 407, /* CRTC VBlankStart */ + 459, /* CRTC VSyncStart */ + 461, /* CRTC VSyncEnd */ + 490, /* CRTC VBlankEnd */ + 525, /* CRTC VTotal */ + FALSE, /* CrtcHAdjusted */ + FALSE, /* CrtcVAdjusted */ + 0, /* PrivSize */ + NULL, /* Private */ + 0.0, /* HSync */ + 0.0 /* VRefresh */ +}; + +/* TW: Built-in hi-res modes for the 6326. + * For some reason, our default mode lines and the + * clock calculation functions in sis_dac.c do no + * good job on higher clocks. It seems, the hardware + * needs some tricks so make mode with higher clock + * rates than ca. 120MHz work. I didn't bother trying + * to find out what exactly is going wrong, so I + * implemented two special modes instead for 1280x1024 + * and 1600x1200. These two are automatically added + * to the list if they are supported with the current + * depth. + * The data in the strucures below is a proximation, + * in sis_vga.c the register contents are fetched from + * fixed tables anyway. + */ +static DisplayModeRec SiS6326SIS1280x1024_75Mode = { + NULL, /* prev */ + NULL, /* next */ + "SIS1280x1024-75", /* identifier of this mode */ + MODE_OK, /* mode status */ + M_T_BUILTIN, /* mode type */ + 135000, /* Clock frequency */ + 1280, /* HDisplay */ + 1296, /* HSyncStart */ + 1440, /* HSyncEnd */ + 1688, /* HTotal */ + 0, /* HSkew */ + 1024, /* VDisplay */ + 1025, /* VSyncStart */ + 1028, /* VSyncEnd */ + 1066, /* VTotal */ + 0, /* VScan */ + V_PHSYNC | V_PVSYNC, /* Flags */ + -1, /* ClockIndex */ + 135000, /* SynthClock */ + 1280, /* CRTC HDisplay */ + 1280, /* CRTC HBlankStart */ + 1296, /* CRTC HSyncStart */ + 1440, /* CRTC HSyncEnd */ + 1680, /* CRTC HBlankEnd */ + 1688, /* CRTC HTotal */ + 0, /* CRTC HSkew */ + 1024, /* CRTC VDisplay */ + 1024, /* CRTC VBlankStart */ + 1025, /* CRTC VSyncStart */ + 1028, /* CRTC VSyncEnd */ + 1065, /* CRTC VBlankEnd */ + 1066, /* CRTC VTotal */ + FALSE, /* CrtcHAdjusted */ + FALSE, /* CrtcVAdjusted */ + 0, /* PrivSize */ + NULL, /* Private */ + 0.0, /* HSync */ + 0.0 /* VRefresh */ +}; + +static DisplayModeRec SiS6326SIS1600x1200_60Mode = { + NULL, /* prev */ + NULL, /* next */ + "SIS1600x1200-60", /* identifier of this mode */ + MODE_OK, /* mode status */ + M_T_BUILTIN, /* mode type */ + 162000, /* Clock frequency */ + 1600, /* HDisplay */ + 1664, /* HSyncStart */ + 1856, /* HSyncEnd */ + 2160, /* HTotal */ + 0, /* HSkew */ + 1200, /* VDisplay */ + 1201, /* VSyncStart */ + 1204, /* VSyncEnd */ + 1250, /* VTotal */ + 0, /* VScan */ + V_PHSYNC | V_PVSYNC, /* Flags */ + -1, /* ClockIndex */ + 162000, /* SynthClock */ + 1600, /* CRTC HDisplay */ + 1600, /* CRTC HBlankStart */ + 1664, /* CRTC HSyncStart */ + 1856, /* CRTC HSyncEnd */ + 2152, /* CRTC HBlankEnd */ + 2160, /* CRTC HTotal */ + 0, /* CRTC HSkew */ + 1200, /* CRTC VDisplay */ + 1200, /* CRTC VBlankStart */ + 1201, /* CRTC VSyncStart */ + 1204, /* CRTC VSyncEnd */ + 1249, /* CRTC VBlankEnd */ + 1250, /* CRTC VTotal */ + FALSE, /* CrtcHAdjusted */ + FALSE, /* CrtcVAdjusted */ + 0, /* PrivSize */ + NULL, /* Private */ + 0.0, /* HSync */ + 0.0 /* VRefresh */ +}; + diff -ruN ../xc/xc/programs/Xserver/hw/xfree86/drivers/sis/sis_sarea.h xc/programs/Xserver/hw/xfree86/drivers/sis/sis_sarea.h --- ../xc/xc/programs/Xserver/hw/xfree86/drivers/sis/sis_sarea.h Wed Dec 31 16:00:00 1969 +++ xc/programs/Xserver/hw/xfree86/drivers/sis/sis_sarea.h Tue Aug 12 12:03:34 2003 @@ -0,0 +1,45 @@ +/* $XFree86$ */ +/* + * Copyright 2003 Eric Anholt + * + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation on the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL ATI, PRECISION INSIGHT, VA LINUX + * SYSTEMS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * Authors: + * Eric Anholt + * + */ + +#ifndef _SIS_SAREA_H_ +#define _SIS_SAREA_H_ + +typedef struct { + int ctxOwner; + int QueueLength; + unsigned int AGPCmdBufNext; + unsigned int FrameCount; +} SISSAREAPriv, *SISSAREAPrivPtr; + +#endif /* _SIS_SAREA_H_ */