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