1 /* $XFree86: xc/programs/Xserver/Xext/xf86dga.c,v 3.8 1997/01/18 06:53:01 dawes Exp $ */
5 Copyright (c) 1995 Jon Tombs
6 Copyright (c) 1995, 1996 XFree86 Inc
15 #include "dixstruct.h"
16 #include "extnsionst.h"
17 #include "colormapst.h"
18 #include "cursorstr.h"
19 #include "scrnintstr.h"
21 #define _XF86DGA_SERVER_
22 #include "xf86dgastr.h"
24 #include "../hw/xfree86/common/xf86.h"
26 #include <X11/Xtrans.h>
27 #include "../os/osdep.h"
28 #include <X11/Xauth.h>
31 #include <sys/socket.h>
36 #include <lan/socket.h>
39 extern int xf86ScreenIndex;
41 static int DGAErrorBase;
43 static DISPATCH_PROC(ProcDGAQueryVersion);
44 static DISPATCH_PROC(ProcXF86DGADirectVideo);
45 static DISPATCH_PROC(ProcXF86DGADispatch);
46 static DISPATCH_PROC(ProcXF86DGAGetVidPage);
47 static DISPATCH_PROC(ProcXF86DGAGetVideoLL);
48 static DISPATCH_PROC(ProcXF86DGAGetViewPortSize);
49 static DISPATCH_PROC(ProcXF86DGASetVidPage);
50 static DISPATCH_PROC(ProcXF86DGASetViewPort);
51 static DISPATCH_PROC(ProcDGAInstallColormap);
52 static DISPATCH_PROC(ProcDGAQueryDirectVideo);
53 static DISPATCH_PROC(ProcDGAViewPortChanged);
56 * SProcs should probably be deleted, a local connection can never
57 * be byte flipped!? - Jon.
59 static DISPATCH_PROC(SProcXF86DGADirectVideo);
60 static DISPATCH_PROC(SProcXF86DGADispatch);
61 static DISPATCH_PROC(SProcXF86DGAQueryVersion);
63 static void XF86DGAResetProc(
64 #if NeedFunctionPrototypes
65 ExtensionEntry* /* extEntry */
69 static unsigned char DGAReqCode = 0;
72 XFree86DGAExtensionInit()
74 ExtensionEntry* extEntry;
79 EventType = CreateNewResourceType(XF86DGAFreeEvents);
80 ScreenPrivateIndex = AllocateScreenPrivateIndex ();
81 for (i = 0; i < screenInfo.numScreens; i++)
83 pScreen = screenInfo.screens[i];
84 SetScreenPrivate (pScreen, NULL);
90 EventType && ScreenPrivateIndex != -1 &&
92 (extEntry = AddExtension(XF86DGANAME,
98 StandardMinorOpcode))) {
99 DGAReqCode = (unsigned char)extEntry->base;
100 DGAErrorBase = extEntry->errorBase;
106 XF86DGAResetProc (extEntry)
107 ExtensionEntry* extEntry;
112 ProcDGAQueryVersion(client)
113 register ClientPtr client;
115 xXF86DGAQueryVersionReply rep;
118 REQUEST_SIZE_MATCH(xXF86DGAQueryVersionReq);
121 rep.sequenceNumber = client->sequence;
122 rep.majorVersion = XF86DGA_MAJOR_VERSION;
123 rep.minorVersion = XF86DGA_MINOR_VERSION;
124 if (client->swapped) {
125 swaps(&rep.sequenceNumber, n);
126 swapl(&rep.length, n);
128 WriteToClient(client, sizeof(xXF86DGAQueryVersionReply), (char *)&rep);
129 return (client->noClientException);
133 ProcXF86DGAGetVideoLL(client)
134 register ClientPtr client;
136 REQUEST(xXF86DGAGetVideoLLReq);
137 xXF86DGAGetVideoLLReply rep;
141 if (stuff->screen > screenInfo.numScreens)
144 vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
145 REQUEST_SIZE_MATCH(xXF86DGAGetVideoLLReq);
148 rep.sequenceNumber = client->sequence;
150 xf86GetVidMemData(stuff->screen, &rep.offset, &rep.bank_size);
152 rep.offset = vptr->physBase;
153 rep.bank_size = vptr->physSize;
155 rep.width = vptr->displayWidth;
156 rep.ram_size = vptr->videoRam;
158 if (client->swapped) {
159 swaps(&rep.sequenceNumber, n);
160 swapl(&rep.length, n);
161 swapl(&rep.offset, n);
162 swapl(&rep.width, n);
163 swapl(&rep.bank_size, n);
164 swapl(&rep.ram_size, n);
166 WriteToClient(client, SIZEOF(xXF86DGAGetVideoLLReply), (char *)&rep);
167 return (client->noClientException);
171 ProcXF86DGADirectVideo(client)
172 register ClientPtr client;
174 REQUEST(xXF86DGADirectVideoReq);
177 if (stuff->screen > screenInfo.numScreens)
180 vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
182 REQUEST_SIZE_MATCH(xXF86DGADirectVideoReq);
183 if (!(vptr->directMode&XF86DGADirectPresent)) {
184 /* chipset doesn't know about directVideoMode */
185 return DGAErrorBase + XF86DGANoDirectVideoMode;
188 /* Check that the current screen is active. */
189 if (!xf86VTSema && !(vptr->directMode & XF86DGADirectGraphics)) {
190 return DGAErrorBase + XF86DGAScreenNotActive;
193 if (stuff->enable&XF86DGADirectGraphics) {
194 vptr->directMode = stuff->enable|XF86DGADirectPresent;
195 if (xf86VTSema == TRUE) {
196 vptr->EnterLeaveVT(LEAVE, stuff->screen);
200 if (xf86VTSema == FALSE) {
202 vptr->EnterLeaveVT(ENTER, stuff->screen);
204 vptr->directMode = (0x0f&stuff->enable)|XF86DGADirectPresent;
207 return (client->noClientException);
211 ProcXF86DGAGetViewPortSize(client)
212 register ClientPtr client;
214 REQUEST(xXF86DGAGetViewPortSizeReq);
215 xXF86DGAGetViewPortSizeReply rep;
219 if (stuff->screen > screenInfo.numScreens)
222 vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
224 REQUEST_SIZE_MATCH(xXF86DGAGetViewPortSizeReq);
227 rep.sequenceNumber = client->sequence;
228 rep.width = vptr->modes->HDisplay;
229 rep.height = vptr->modes->VDisplay;
231 if (client->swapped) {
232 swaps(&rep.sequenceNumber, n);
233 swapl(&rep.length, n);
234 swapl(&rep.width, n);
235 swapl(&rep.height, n);
237 WriteToClient(client, SIZEOF(xXF86DGAGetViewPortSizeReply), (char *)&rep);
238 return (client->noClientException);
242 ProcXF86DGASetViewPort(client)
243 register ClientPtr client;
245 REQUEST(xXF86DGASetViewPortReq);
248 if (stuff->screen > screenInfo.numScreens)
251 vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
253 REQUEST_SIZE_MATCH(xXF86DGASetViewPortReq);
255 if (vptr->AdjustFrame &&
256 (xf86VTSema == TRUE || vptr->directMode&XF86DGADirectGraphics))
257 vptr->AdjustFrame(stuff->x, stuff->y);
259 return DGAErrorBase + XF86DGAScreenNotActive;
261 return (client->noClientException);
265 ProcXF86DGAGetVidPage(client)
266 register ClientPtr client;
268 REQUEST(xXF86DGAGetVidPageReq);
271 if (stuff->screen > screenInfo.numScreens)
274 vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
275 ErrorF("XF86DGAGetVidPage not yet implemented\n");
277 REQUEST_SIZE_MATCH(xXF86DGAGetVidPageReq);
278 return (client->noClientException);
283 ProcXF86DGASetVidPage(client)
284 register ClientPtr client;
286 REQUEST(xXF86DGASetVidPageReq);
289 if (stuff->screen > screenInfo.numScreens)
292 vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
294 REQUEST_SIZE_MATCH(xXF86DGASetVidPageReq);
296 if (xf86VTSema == TRUE) {/* only valid when switched away! */
297 return DGAErrorBase + XF86DGADirectNotActivated;
299 if (!xf86VTSema && !(vptr->directMode & XF86DGADirectGraphics)) {
300 return DGAErrorBase + XF86DGAScreenNotActive;
304 vptr->setBank(stuff->vpage);
306 return (client->noClientException);
311 ProcDGAInstallColormap(client)
312 register ClientPtr client;
316 REQUEST(xXF86DGAInstallColormapReq);
318 REQUEST_SIZE_MATCH(xXF86DGAInstallColormapReq);
320 vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
322 if (xf86VTSema == TRUE) {/* only valid when switched away! */
323 return DGAErrorBase + XF86DGADirectNotActivated;
325 if (!xf86VTSema && !(vptr->directMode & XF86DGADirectGraphics)) {
326 return DGAErrorBase + XF86DGAScreenNotActive;
329 pcmp = (ColormapPtr )LookupIDByType(stuff->id, RT_COLORMAP);
332 vptr->directMode |= XF86DGADirectColormap;
333 vptr->directMode |= XF86DGAHasColormap;
334 (*(pcmp->pScreen->InstallColormap)) (pcmp);
335 vptr->directMode &= ~XF86DGAHasColormap;
336 return (client->noClientException);
340 client->errorValue = stuff->id;
346 ProcXF86DGAQueryDirectVideo(client)
347 register ClientPtr client;
349 REQUEST(xXF86DGAQueryDirectVideoReq);
350 xXF86DGAQueryDirectVideoReply rep;
354 if (stuff->screen > screenInfo.numScreens)
357 vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
359 REQUEST_SIZE_MATCH(xXF86DGAQueryDirectVideoReq);
362 rep.sequenceNumber = client->sequence;
363 rep.flags = vptr->directMode;
365 if (client->swapped) {
366 swaps(&rep.sequenceNumber, n);
367 swapl(&rep.length, n);
368 swapl(&rep.flags, n);
370 WriteToClient(client, SIZEOF(xXF86DGAQueryDirectVideoReply), (char *)&rep);
371 return (client->noClientException);
375 ProcXF86DGAViewPortChanged(client)
376 register ClientPtr client;
378 REQUEST(xXF86DGAViewPortChangedReq);
379 xXF86DGAViewPortChangedReply rep;
383 if (stuff->screen > screenInfo.numScreens)
386 vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
388 REQUEST_SIZE_MATCH(xXF86DGAViewPortChangedReq);
391 rep.sequenceNumber = client->sequence;
392 /* For the moment, always return TRUE. */
395 if (client->swapped) {
396 swaps(&rep.sequenceNumber, n);
397 swapl(&rep.length, n);
398 swapl(&rep.result, n);
400 WriteToClient(client, SIZEOF(xXF86DGAViewPortChangedReply), (char *)&rep);
401 return (client->noClientException);
405 ProcXF86DGADispatch (client)
406 register ClientPtr client;
410 if (!LocalClient(client))
411 return DGAErrorBase + XF86DGAClientNotLocal;
415 case X_XF86DGAQueryVersion:
416 return ProcDGAQueryVersion(client);
417 case X_XF86DGAGetVideoLL:
418 return ProcXF86DGAGetVideoLL(client);
419 case X_XF86DGADirectVideo:
420 return ProcXF86DGADirectVideo(client);
421 case X_XF86DGAGetViewPortSize:
422 return ProcXF86DGAGetViewPortSize(client);
423 case X_XF86DGASetViewPort:
424 return ProcXF86DGASetViewPort(client);
425 case X_XF86DGAGetVidPage:
426 return ProcXF86DGAGetVidPage(client);
427 case X_XF86DGASetVidPage:
428 return ProcXF86DGASetVidPage(client);
429 case X_XF86DGAInstallColormap:
430 return ProcDGAInstallColormap(client);
431 case X_XF86DGAQueryDirectVideo:
432 return ProcXF86DGAQueryDirectVideo(client);
433 case X_XF86DGAViewPortChanged:
434 return ProcXF86DGAViewPortChanged(client);
441 SProcXF86DGAQueryVersion(client)
442 register ClientPtr client;
445 REQUEST(xXF86DGAQueryVersionReq);
446 swaps(&stuff->length, n);
447 return ProcDGAQueryVersion(client);
451 SProcXF86DGADirectVideo(client)
455 REQUEST(xXF86DGADirectVideoReq);
456 swaps(&stuff->length, n);
457 REQUEST_SIZE_MATCH(xXF86DGADirectVideoReq);
458 swaps(&stuff->screen, n);
459 swaps(&stuff->enable, n);
460 return ProcXF86DGADirectVideo(client);
464 SProcXF86DGADispatch (client)
465 register ClientPtr client;
469 /* It is bound to be non-local when there is byte swapping */
470 if (!LocalClient(client))
471 return DGAErrorBase + XF86DGAClientNotLocal;
475 case X_XF86DGAQueryVersion:
476 return SProcXF86DGAQueryVersion(client);
477 case X_XF86DGADirectVideo:
478 return SProcXF86DGADirectVideo(client);