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