ct_dga.c revision 3699b6c4
1 2#ifdef HAVE_CONFIG_H 3#include "config.h" 4#endif 5 6#include "xf86.h" 7#include "xf86_OSproc.h" 8#include "xf86Pci.h" 9#include "xf86PciInfo.h" 10#include "xaa.h" 11#include "xaalocal.h" 12#include "ct_driver.h" 13#include "dgaproc.h" 14 15 16static Bool CHIPS_OpenFramebuffer(ScrnInfoPtr, char **, unsigned char **, 17 int *, int *, int *); 18static Bool CHIPS_SetMode(ScrnInfoPtr, DGAModePtr); 19static int CHIPS_GetViewport(ScrnInfoPtr); 20static void CHIPS_SetViewport(ScrnInfoPtr, int, int, int); 21static void CHIPS_FillRect(ScrnInfoPtr, int, int, int, int, unsigned long); 22static void CHIPS_BlitRect(ScrnInfoPtr, int, int, int, int, int, int); 23#if 0 24static void CHIPS_BlitTransRect(ScrnInfoPtr, int, int, int, int, int, int, 25 unsigned long); 26#endif 27 28static 29DGAFunctionRec CHIPS_DGAFuncs = { 30 CHIPS_OpenFramebuffer, 31 NULL, 32 CHIPS_SetMode, 33 CHIPS_SetViewport, 34 CHIPS_GetViewport, 35 CHIPSSync, 36 CHIPS_FillRect, 37 CHIPS_BlitRect, 38#if 0 39 CHIPS_BlitTransRect 40#else 41 NULL 42#endif 43}; 44 45static 46DGAFunctionRec CHIPS_MMIODGAFuncs = { 47 CHIPS_OpenFramebuffer, 48 NULL, 49 CHIPS_SetMode, 50 CHIPS_SetViewport, 51 CHIPS_GetViewport, 52 CHIPSMMIOSync, 53 CHIPS_FillRect, 54 CHIPS_BlitRect, 55#if 0 56 CHIPS_BlitTransRect 57#else 58 NULL 59#endif 60}; 61 62static 63DGAFunctionRec CHIPS_HiQVDGAFuncs = { 64 CHIPS_OpenFramebuffer, 65 NULL, 66 CHIPS_SetMode, 67 CHIPS_SetViewport, 68 CHIPS_GetViewport, 69 CHIPSHiQVSync, 70 CHIPS_FillRect, 71 CHIPS_BlitRect, 72#if 0 73 CHIPS_BlitTransRect 74#else 75 NULL 76#endif 77}; 78 79 80Bool 81CHIPSDGAInit(ScreenPtr pScreen) 82{ 83 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 84 CHIPSPtr cPtr = CHIPSPTR(pScrn); 85 DGAModePtr modes = NULL, newmodes = NULL, currentMode; 86 DisplayModePtr pMode, firstMode; 87 int Bpp = pScrn->bitsPerPixel >> 3; 88 int num = 0; 89 Bool oneMore; 90 int imlines = (pScrn->videoRam * 1024) / 91 (pScrn->displayWidth * (pScrn->bitsPerPixel >> 3)); 92 93 pMode = firstMode = pScrn->modes; 94 95 while(pMode) { 96 97 if(0 /*pScrn->displayWidth != pMode->HDisplay*/) { 98 newmodes = realloc(modes, (num + 2) * sizeof(DGAModeRec)); 99 oneMore = TRUE; 100 } else { 101 newmodes = realloc(modes, (num + 1) * sizeof(DGAModeRec)); 102 oneMore = FALSE; 103 } 104 105 if(!newmodes) { 106 free(modes); 107 return FALSE; 108 } 109 modes = newmodes; 110 111SECOND_PASS: 112 113 currentMode = modes + num; 114 num++; 115 116 currentMode->mode = pMode; 117 currentMode->flags = DGA_CONCURRENT_ACCESS | DGA_PIXMAP_AVAILABLE; 118 if(cPtr->Flags & ChipsAccelSupport) 119 currentMode->flags |= (cPtr->Flags & ChipsAccelSupport) 120 ? (DGA_FILL_RECT | DGA_BLIT_RECT) : 0; 121 if(pMode->Flags & V_DBLSCAN) 122 currentMode->flags |= DGA_DOUBLESCAN; 123 if(pMode->Flags & V_INTERLACE) 124 currentMode->flags |= DGA_INTERLACED; 125 currentMode->byteOrder = pScrn->imageByteOrder; 126 currentMode->depth = pScrn->depth; 127 currentMode->bitsPerPixel = pScrn->bitsPerPixel; 128 currentMode->red_mask = pScrn->mask.red; 129 currentMode->green_mask = pScrn->mask.green; 130 currentMode->blue_mask = pScrn->mask.blue; 131 currentMode->visualClass = (Bpp == 1) ? PseudoColor : TrueColor; 132 currentMode->viewportWidth = pMode->HDisplay; 133 currentMode->viewportHeight = pMode->VDisplay; 134 currentMode->xViewportStep = 1; 135 currentMode->yViewportStep = 1; 136 currentMode->viewportFlags = DGA_FLIP_RETRACE | DGA_FLIP_IMMEDIATE; 137 currentMode->offset = 0; 138 currentMode->address = cPtr->FbBase; 139 140 if(oneMore) { /* first one is narrow width */ 141 currentMode->bytesPerScanline = ((pMode->HDisplay * Bpp) + 3) & ~3L; 142 currentMode->imageWidth = pMode->HDisplay; 143 currentMode->imageHeight = imlines; 144 currentMode->pixmapWidth = currentMode->imageWidth; 145 currentMode->pixmapHeight = currentMode->imageHeight; 146 currentMode->maxViewportX = currentMode->imageWidth - 147 currentMode->viewportWidth; 148 /* this might need to get clamped to some maximum */ 149 currentMode->maxViewportY = currentMode->imageHeight - 150 currentMode->viewportHeight; 151 oneMore = FALSE; 152 goto SECOND_PASS; 153 } else { 154 currentMode->bytesPerScanline = 155 ((pScrn->displayWidth * Bpp) + 3) & ~3L; 156 currentMode->imageWidth = pScrn->displayWidth; 157 currentMode->imageHeight = imlines; 158 currentMode->pixmapWidth = currentMode->imageWidth; 159 currentMode->pixmapHeight = currentMode->imageHeight; 160 currentMode->maxViewportX = currentMode->imageWidth - 161 currentMode->viewportWidth; 162 /* this might need to get clamped to some maximum */ 163 currentMode->maxViewportY = currentMode->imageHeight - 164 currentMode->viewportHeight; 165 } 166 167 pMode = pMode->next; 168 if(pMode == firstMode) 169 break; 170 } 171 172 cPtr->numDGAModes = num; 173 cPtr->DGAModes = modes; 174 175 if (IS_HiQV(cPtr)) { 176 return DGAInit(pScreen, &CHIPS_HiQVDGAFuncs, modes, num); 177 } else { 178 if(!cPtr->UseMMIO) { 179 return DGAInit(pScreen, &CHIPS_DGAFuncs, modes, num); 180 } else { 181 return DGAInit(pScreen, &CHIPS_MMIODGAFuncs, modes, num); 182 } 183 } 184} 185 186 187static Bool 188CHIPS_SetMode( 189 ScrnInfoPtr pScrn, 190 DGAModePtr pMode 191){ 192 static int OldDisplayWidth[MAXSCREENS]; 193 int index = pScrn->pScreen->myNum; 194 195 CHIPSPtr cPtr = CHIPSPTR(pScrn); 196 197 if (!pMode) { /* restore the original mode */ 198 /* put the ScreenParameters back */ 199 if (cPtr->DGAactive) { 200 pScrn->displayWidth = OldDisplayWidth[index]; 201 pScrn->EnterVT(pScrn->scrnIndex,0); 202 203 cPtr->DGAactive = FALSE; 204 } 205 } else { 206 if(!cPtr->DGAactive) { /* save the old parameters */ 207 OldDisplayWidth[index] = pScrn->displayWidth; 208 pScrn->LeaveVT(pScrn->scrnIndex,0); 209 cPtr->DGAactive = TRUE; 210 } 211 212 pScrn->displayWidth = pMode->bytesPerScanline / 213 (pMode->bitsPerPixel >> 3); 214 215 CHIPSSwitchMode(index, pMode->mode, 0); 216 } 217 218 return TRUE; 219} 220 221 222 223static int 224CHIPS_GetViewport( 225 ScrnInfoPtr pScrn 226){ 227 CHIPSPtr cPtr = CHIPSPTR(pScrn); 228 229 return cPtr->DGAViewportStatus; 230} 231 232static void 233CHIPS_SetViewport( 234 ScrnInfoPtr pScrn, 235 int x, int y, 236 int flags 237 ){ 238 vgaHWPtr hwp = VGAHWPTR(pScrn); 239 CHIPSPtr cPtr = CHIPSPTR(pScrn); 240 241 if (flags & DGA_FLIP_RETRACE) { 242 while ((hwp->readST01(hwp)) & 0x08){}; 243 while (!((hwp->readST01(hwp)) & 0x08)){}; 244 } 245 246 CHIPSAdjustFrame(pScrn->pScreen->myNum, x, y, flags); 247 cPtr->DGAViewportStatus = 0; /* CHIPSAdjustFrame loops until finished */ 248} 249 250static void 251CHIPS_FillRect ( 252 ScrnInfoPtr pScrn, 253 int x, int y, int w, int h, 254 unsigned long color 255){ 256 CHIPSPtr cPtr = CHIPSPTR(pScrn); 257 258 if(cPtr->AccelInfoRec) { 259 (*cPtr->AccelInfoRec->SetupForSolidFill)(pScrn, color, GXcopy, ~0); 260 (*cPtr->AccelInfoRec->SubsequentSolidFillRect)(pScrn, x, y, w, h); 261 SET_SYNC_FLAG(cPtr->AccelInfoRec); 262 } 263} 264 265static void 266CHIPS_BlitRect( 267 ScrnInfoPtr pScrn, 268 int srcx, int srcy, 269 int w, int h, 270 int dstx, int dsty 271){ 272 CHIPSPtr cPtr = CHIPSPTR(pScrn); 273 274 if(cPtr->AccelInfoRec) { 275 int xdir = ((srcx < dstx) && (srcy == dsty)) ? -1 : 1; 276 int ydir = (srcy < dsty) ? -1 : 1; 277 278 (*cPtr->AccelInfoRec->SetupForScreenToScreenCopy)( 279 pScrn, xdir, ydir, GXcopy, ~0, -1); 280 (*cPtr->AccelInfoRec->SubsequentScreenToScreenCopy)( 281 pScrn, srcx, srcy, dstx, dsty, w, h); 282 SET_SYNC_FLAG(cPtr->AccelInfoRec); 283 } 284} 285 286#if 0 287static void 288CHIPS_BlitTransRect( 289 ScrnInfoPtr pScrn, 290 int srcx, int srcy, 291 int w, int h, 292 int dstx, int dsty, 293 unsigned long color 294){ 295 /* this one should be separate since the XAA function would 296 prohibit usage of ~0 as the key */ 297} 298#endif 299 300static Bool 301CHIPS_OpenFramebuffer( 302 ScrnInfoPtr pScrn, 303 char **name, 304 unsigned char **mem, 305 int *size, 306 int *offset, 307 int *flags 308){ 309 CHIPSPtr cPtr = CHIPSPTR(pScrn); 310 311 *name = NULL; /* no special device */ 312 *mem = (unsigned char*)cPtr->FbAddress; 313 *size = cPtr->FbMapSize; 314 *offset = 0; 315 *flags = DGA_NEED_ROOT; 316 317 return TRUE; 318} 319