1/* Header: //Mercury/Projects/archives/XFree86/4.0/smi_accel.c-arc 1.16 03 Jan 2001 13:29:06 Frido $ */ 2 3/* 4Copyright (C) 1994-1999 The XFree86 Project, Inc. All Rights Reserved. 5Copyright (C) 2000 Silicon Motion, Inc. All Rights Reserved. 6 7Permission is hereby granted, free of charge, to any person obtaining a copy of 8this software and associated documentation files (the "Software"), to deal in 9the Software without restriction, including without limitation the rights to 10use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 11of the Software, and to permit persons to whom the Software is furnished to do 12so, subject to the following conditions: 13 14The above copyright notice and this permission notice shall be included in all 15copies or substantial portions of the Software. 16 17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT- 19NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 21AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 24Except as contained in this notice, the names of the XFree86 Project and 25Silicon Motion shall not be used in advertising or otherwise to promote the 26sale, use or other dealings in this Software without prior written 27authorization from the XFree86 Project and silicon Motion. 28*/ 29 30#ifdef HAVE_CONFIG_H 31#include "config.h" 32#endif 33 34#include "smi.h" 35#include "smi_501.h" 36 37void 38SMI_GEReset(ScrnInfoPtr pScrn, int from_timeout, int line, const char *file) 39{ 40 SMIPtr pSmi = SMIPTR(pScrn); 41 int32_t tmp; 42 43 ENTER(); 44 45 if (from_timeout) { 46 if (pSmi->GEResetCnt++ < 10 || xf86GetVerbosity() > 1) 47 xf86DrvMsg(pScrn->scrnIndex,X_INFO, 48 "\tSMI_GEReset called from %s line %d\n", file, line); 49 } 50 else 51 WaitIdle(); 52 53 if (IS_MSOC(pSmi)) { 54 /* 12:13 Drawing Engine Abort 55 * 00: Normal 56 * 11: Abort 2D Engine 57 * (0x3000 == bits 12 and 13 set) 58 */ 59 tmp = READ_SCR(pSmi, 0x0000) & ~0x00003000; 60 WRITE_SCR(pSmi, 0x0000, tmp | 0x00003000); 61 /* FIXME No need to wait here? */ 62 WRITE_SCR(pSmi, 0x0000, tmp); 63 } 64 else { 65 tmp = VGAIN8_INDEX(pSmi, VGA_SEQ_INDEX, VGA_SEQ_DATA, 0x15); 66 VGAOUT8_INDEX(pSmi, VGA_SEQ_INDEX, VGA_SEQ_DATA, 0x15, tmp | 0x30); 67 } 68 69 if (!IS_MSOC(pSmi)) 70 VGAOUT8_INDEX(pSmi, VGA_SEQ_INDEX, VGA_SEQ_DATA, 0x15, tmp); 71 SMI_EngineReset(pScrn); 72 73 LEAVE(); 74} 75 76/* The sync function for the GE */ 77void 78SMI_AccelSync(ScrnInfoPtr pScrn) 79{ 80 SMIPtr pSmi = SMIPTR(pScrn); 81 82 ENTER(); 83 84 WaitIdle(); 85 86 LEAVE(); 87} 88 89void 90SMI_EngineReset(ScrnInfoPtr pScrn) 91{ 92 SMIPtr pSmi = SMIPTR(pScrn); 93 CARD32 DEDataFormat = 0; 94 int i, stride; 95 int xyAddress[] = { 320, 400, 512, 640, 800, 1024, 1280, 1600, 2048 }; 96 97 ENTER(); 98 99 DEDataFormat = SMI_DEDataFormat(pScrn->bitsPerPixel); 100 for (i = 0; i < sizeof(xyAddress) / sizeof(xyAddress[0]); i++) { 101 if (xyAddress[i] == pScrn->virtualX) { 102 DEDataFormat |= i << 16; 103 break; 104 } 105 } 106 DEDataFormat |= 0x40000000; /* Force pattern origin coordinates to (0,0) */ 107 108 WaitIdle(); 109 stride = pScrn->displayWidth; 110 if (pSmi->Bpp == 3) 111 stride *= 3; 112 WRITE_DPR(pSmi, 0x10, (stride << 16) | stride); 113 WRITE_DPR(pSmi, 0x1C, DEDataFormat); 114 WRITE_DPR(pSmi, 0x24, 0xFFFFFFFF); 115 WRITE_DPR(pSmi, 0x28, 0xFFFFFFFF); 116 WRITE_DPR(pSmi, 0x3C, (stride << 16) | stride); 117 WRITE_DPR(pSmi, 0x40, pSmi->FBOffset >> 3); 118 WRITE_DPR(pSmi, 0x44, pSmi->FBOffset >> 3); 119 120 SMI_DisableClipping(pScrn); 121 122 LEAVE(); 123} 124 125/******************************************************************************/ 126/* Clipping */ 127/******************************************************************************/ 128 129void 130SMI_SetClippingRectangle(ScrnInfoPtr pScrn, int left, int top, int right, 131 int bottom) 132{ 133 SMIPtr pSmi = SMIPTR(pScrn); 134 135 ENTER(); 136 DEBUG("left=%d top=%d right=%d bottom=%d\n", left, top, right, bottom); 137 138 if (pScrn->bitsPerPixel == 24) { 139 left *= 3; 140 right *= 3; 141 142 if (pSmi->Chipset == SMI_LYNX) { 143 top *= 3; 144 bottom *= 3; 145 } 146 } 147 148 if (IS_MSOC(pSmi)) { 149 ++right; 150 ++bottom; 151 } 152 153 pSmi->ScissorsLeft = (top << 16) | (left & 0xFFFF) | 0x2000; 154 pSmi->ScissorsRight = (bottom << 16) | (right & 0xFFFF); 155 156 pSmi->ClipTurnedOn = FALSE; 157 158 WaitQueue(); 159 WRITE_DPR(pSmi, 0x2C, pSmi->ScissorsLeft); 160 WRITE_DPR(pSmi, 0x30, pSmi->ScissorsRight); 161 162 LEAVE(); 163} 164 165void 166SMI_DisableClipping(ScrnInfoPtr pScrn) 167{ 168 SMIPtr pSmi = SMIPTR(pScrn); 169 170 ENTER(); 171 172 pSmi->ScissorsLeft = 0; 173 if (pScrn->bitsPerPixel == 24) { 174 if (pSmi->Chipset == SMI_LYNX) { 175 pSmi->ScissorsRight = ((pScrn->virtualY * 3) << 16) | (pScrn->virtualX * 3); 176 } else { 177 pSmi->ScissorsRight = (pScrn->virtualY << 16) | (pScrn->virtualX * 3); 178 } 179 } else { 180 pSmi->ScissorsRight = (pScrn->virtualY << 16) | pScrn->virtualX; 181 } 182 183 pSmi->ClipTurnedOn = FALSE; 184 185 WaitQueue(); 186 WRITE_DPR(pSmi, 0x2C, pSmi->ScissorsLeft); 187 WRITE_DPR(pSmi, 0x30, pSmi->ScissorsRight); 188 189 LEAVE(); 190} 191 192CARD32 193SMI_DEDataFormat(int bpp) { 194 CARD32 DEDataFormat = 0; 195 196 switch (bpp) { 197 case 8: 198 DEDataFormat = 0x00000000; 199 break; 200 case 16: 201 DEDataFormat = 0x00100000; 202 break; 203 case 24: 204 DEDataFormat = 0x00300000; 205 break; 206 case 32: 207 DEDataFormat = 0x00200000; 208 break; 209 } 210 return DEDataFormat; 211} 212 213