i128dga.c revision 7965d9ac
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 "i128.h" 13#include "dgaproc.h" 14 15 16static Bool I128_OpenFramebuffer(ScrnInfoPtr, char **, unsigned char **, 17 int *, int *, int *); 18static Bool I128_SetMode(ScrnInfoPtr, DGAModePtr); 19static int I128_GetViewport(ScrnInfoPtr); 20static void I128_SetViewport(ScrnInfoPtr, int, int, int); 21static void I128_FillRect(ScrnInfoPtr, int, int, int, int, unsigned long); 22static void I128_BlitRect(ScrnInfoPtr, int, int, int, int, int, int); 23#if 0 24static void I128_BlitTransRect(ScrnInfoPtr, int, int, int, int, int, int, 25 unsigned long); 26#endif 27 28static 29DGAFunctionRec I128_DGAFuncs = { 30 I128_OpenFramebuffer, 31 NULL, 32 I128_SetMode, 33 I128_SetViewport, 34 I128_GetViewport, 35 I128EngineDone, 36 I128_FillRect, 37 I128_BlitRect, 38#if 0 39 I128_BlitTransRect 40#else 41 NULL 42#endif 43}; 44 45 46Bool 47I128DGAInit(ScreenPtr pScreen) 48{ 49 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 50 I128Ptr pI128 = I128PTR(pScrn); 51 DGAModePtr modes = NULL, newmodes = NULL, currentMode; 52 DisplayModePtr pMode, firstMode; 53 int Bpp = pScrn->bitsPerPixel >> 3; 54 int num = 0; 55 Bool oneMore; 56 57 pMode = firstMode = pScrn->modes; 58 59 while(pMode) { 60 61 if(0 /*pScrn->displayWidth != pMode->HDisplay*/) { 62 newmodes = xrealloc(modes, (num + 2) * sizeof(DGAModeRec)); 63 oneMore = TRUE; 64 } else { 65 newmodes = xrealloc(modes, (num + 1) * sizeof(DGAModeRec)); 66 oneMore = FALSE; 67 } 68 69 if(!newmodes) { 70 xfree(modes); 71 return FALSE; 72 } 73 modes = newmodes; 74 75SECOND_PASS: 76 77 currentMode = modes + num; 78 num++; 79 80 currentMode->mode = pMode; 81 currentMode->flags = DGA_CONCURRENT_ACCESS | DGA_PIXMAP_AVAILABLE; 82 currentMode->flags |= DGA_FILL_RECT | DGA_BLIT_RECT; 83 if(pMode->Flags & V_DBLSCAN) 84 currentMode->flags |= DGA_DOUBLESCAN; 85 if(pMode->Flags & V_INTERLACE) 86 currentMode->flags |= DGA_INTERLACED; 87 currentMode->byteOrder = pScrn->imageByteOrder; 88 currentMode->depth = pScrn->depth; 89 currentMode->bitsPerPixel = pScrn->bitsPerPixel; 90 currentMode->red_mask = pScrn->mask.red; 91 currentMode->green_mask = pScrn->mask.green; 92 currentMode->blue_mask = pScrn->mask.blue; 93 currentMode->visualClass = (Bpp == 1) ? PseudoColor : TrueColor; 94 currentMode->viewportWidth = pMode->HDisplay; 95 currentMode->viewportHeight = pMode->VDisplay; 96 currentMode->xViewportStep = 1; 97 currentMode->yViewportStep = 1; 98 currentMode->viewportFlags = DGA_FLIP_RETRACE; 99 currentMode->offset = 0; 100 currentMode->address = pI128->MemoryPtr; 101 102 if(oneMore) { /* first one is narrow width */ 103 currentMode->bytesPerScanline = ((pMode->HDisplay * Bpp) + 3) & ~3L; 104 currentMode->imageWidth = pMode->HDisplay; 105 currentMode->imageHeight = pMode->VDisplay; 106 currentMode->pixmapWidth = currentMode->imageWidth; 107 currentMode->pixmapHeight = currentMode->imageHeight; 108 currentMode->maxViewportX = currentMode->imageWidth - 109 currentMode->viewportWidth; 110 /* this might need to get clamped to some maximum */ 111 currentMode->maxViewportY = currentMode->imageHeight - 112 currentMode->viewportHeight; 113 oneMore = FALSE; 114 goto SECOND_PASS; 115 } else { 116 currentMode->bytesPerScanline = 117 ((pScrn->displayWidth * Bpp) + 3) & ~3L; 118 currentMode->imageWidth = pScrn->displayWidth; 119 currentMode->imageHeight = pMode->VDisplay; 120 currentMode->pixmapWidth = currentMode->imageWidth; 121 currentMode->pixmapHeight = currentMode->imageHeight; 122 currentMode->maxViewportX = currentMode->imageWidth - 123 currentMode->viewportWidth; 124 /* this might need to get clamped to some maximum */ 125 currentMode->maxViewportY = currentMode->imageHeight - 126 currentMode->viewportHeight; 127 } 128 129 pMode = pMode->next; 130 if(pMode == firstMode) 131 break; 132 } 133 134 pI128->numDGAModes = num; 135 pI128->DGAModes = modes; 136 137 return DGAInit(pScreen, &I128_DGAFuncs, modes, num); 138} 139 140 141static Bool 142I128_SetMode( 143 ScrnInfoPtr pScrn, 144 DGAModePtr pMode 145){ 146 static int OldDisplayWidth[MAXSCREENS]; 147 int index = pScrn->pScreen->myNum; 148 149 I128Ptr pI128 = I128PTR(pScrn); 150 151 if(!pMode) { /* restore the original mode */ 152 /* put the ScreenParameters back */ 153 154 pScrn->displayWidth = OldDisplayWidth[index]; 155 156 I128SwitchMode(index, pScrn->currentMode, 0); 157 pI128->DGAactive = FALSE; 158 } else { 159 if(!pI128->DGAactive) { /* save the old parameters */ 160 OldDisplayWidth[index] = pScrn->displayWidth; 161 162 pI128->DGAactive = TRUE; 163 } 164 165 pScrn->displayWidth = pMode->bytesPerScanline / 166 (pMode->bitsPerPixel >> 3); 167 168 I128SwitchMode(index, pMode->mode, 0); 169 } 170 171 return TRUE; 172} 173 174 175 176static int 177I128_GetViewport( 178 ScrnInfoPtr pScrn 179){ 180 I128Ptr pI128 = I128PTR(pScrn); 181 182 return pI128->DGAViewportStatus; 183} 184 185static void 186I128_SetViewport( 187 ScrnInfoPtr pScrn, 188 int x, int y, 189 int flags 190){ 191 I128Ptr pI128 = I128PTR(pScrn); 192 193 I128AdjustFrame(pScrn->pScreen->myNum, x, y, flags); 194 pI128->DGAViewportStatus = 0; /* I128AdjustFrame loops until finished */ 195} 196 197static void 198I128_FillRect ( 199 ScrnInfoPtr pScrn, 200 int x, int y, int w, int h, 201 unsigned long color 202){ 203 I128Ptr pI128 = I128PTR(pScrn); 204 205 if(pI128->XaaInfoRec) { 206 (*pI128->XaaInfoRec->SetupForSolidFill)(pScrn, color, GXcopy, ~0); 207 (*pI128->XaaInfoRec->SubsequentSolidFillRect)(pScrn, x, y, w, h); 208 SET_SYNC_FLAG(pI128->XaaInfoRec); 209 } 210} 211 212static void 213I128_BlitRect( 214 ScrnInfoPtr pScrn, 215 int srcx, int srcy, 216 int w, int h, 217 int dstx, int dsty 218){ 219 I128Ptr pI128 = I128PTR(pScrn); 220 221 if(pI128->XaaInfoRec) { 222 int xdir = ((srcx < dstx) && (srcy == dsty)) ? -1 : 1; 223 int ydir = (srcy < dsty) ? -1 : 1; 224 225 (*pI128->XaaInfoRec->SetupForScreenToScreenCopy)( 226 pScrn, xdir, ydir, GXcopy, ~0, -1); 227 (*pI128->XaaInfoRec->SubsequentScreenToScreenCopy)( 228 pScrn, srcx, srcy, dstx, dsty, w, h); 229 SET_SYNC_FLAG(pI128->XaaInfoRec); 230 } 231} 232 233#if 0 234static void 235I128_BlitTransRect( 236 ScrnInfoPtr pScrn, 237 int srcx, int srcy, 238 int w, int h, 239 int dstx, int dsty, 240 unsigned long color 241){ 242 I128Ptr pI128 = I128PTR(pScrn); 243 244 if(pI128->XaaInfoRec) { 245 int xdir = ((srcx < dstx) && (srcy == dsty)) ? -1 : 1; 246 int ydir = (srcy < dsty) ? -1 : 1; 247 248 (*pI128->XaaInfoRec->SetupForScreenToScreenCopy)( 249 pScrn, xdir, ydir, GXcopy, ~0, color); 250 (*pI128->XaaInfoRec->SubsequentScreenToScreenCopy)( 251 pScrn, srcx, srcy, dstx, dsty, w, h); 252 SET_SYNC_FLAG(pI128->XaaInfoRec); 253 } 254} 255#endif 256 257static Bool 258I128_OpenFramebuffer( 259 ScrnInfoPtr pScrn, 260 char **name, 261 unsigned char **mem, 262 int *size, 263 int *offset, 264 int *flags 265){ 266 I128Ptr pI128 = I128PTR(pScrn); 267 unsigned long FbAddress = PCI_REGION_BASE(pI128->PciInfo, 0, REGION_MEM) & 0xFFC00000; 268 269 *name = NULL; /* no special device */ 270 *mem = (unsigned char*)FbAddress; 271 *size = pI128->MemorySize*1024; 272 *offset = 0; 273 *flags = DGA_NEED_ROOT; 274 275 return TRUE; 276} 277