1706f2543Smrg/*
2706f2543Smrg * This code was stolen from RAC and adapted to control the legacy vga
3706f2543Smrg * interface.
4706f2543Smrg *
5706f2543Smrg *
6706f2543Smrg * Copyright (c) 2007 Paulo R. Zanoni, Tiago Vignatti
7706f2543Smrg *
8706f2543Smrg * Permission is hereby granted, free of charge, to any person
9706f2543Smrg * obtaining a copy of this software and associated documentation
10706f2543Smrg * files (the "Software"), to deal in the Software without
11706f2543Smrg * restriction, including without limitation the rights to use,
12706f2543Smrg * copy, modify, merge, publish, distribute, sublicense, and/or sell
13706f2543Smrg * copies of the Software, and to permit persons to whom the
14706f2543Smrg * Software is furnished to do so, subject to the following
15706f2543Smrg * conditions:
16706f2543Smrg *
17706f2543Smrg * The above copyright notice and this permission notice shall be
18706f2543Smrg * included in all copies or substantial portions of the Software.
19706f2543Smrg *
20706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21706f2543Smrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22706f2543Smrg * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23706f2543Smrg * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24706f2543Smrg * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25706f2543Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26706f2543Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27706f2543Smrg * OTHER DEALINGS IN THE SOFTWARE.
28706f2543Smrg *
29706f2543Smrg */
30706f2543Smrg
31706f2543Smrg#include "xorg-config.h"
32706f2543Smrg
33706f2543Smrg#include "xf86VGAarbiter.h"
34706f2543Smrg
35706f2543Smrg#ifdef HAVE_PCI_DEVICE_VGAARB_INIT
36706f2543Smrg#include "xf86VGAarbiterPriv.h"
37706f2543Smrg#include "xf86Bus.h"
38706f2543Smrg#include "xf86Priv.h"
39706f2543Smrg#include "pciaccess.h"
40706f2543Smrg
41706f2543Smrg
42706f2543Smrgstatic GCFuncs VGAarbiterGCFuncs = {
43706f2543Smrg    VGAarbiterValidateGC, VGAarbiterChangeGC, VGAarbiterCopyGC,
44706f2543Smrg    VGAarbiterDestroyGC, VGAarbiterChangeClip, VGAarbiterDestroyClip,
45706f2543Smrg    VGAarbiterCopyClip
46706f2543Smrg};
47706f2543Smrg
48706f2543Smrgstatic GCOps VGAarbiterGCOps = {
49706f2543Smrg    VGAarbiterFillSpans, VGAarbiterSetSpans, VGAarbiterPutImage,
50706f2543Smrg    VGAarbiterCopyArea, VGAarbiterCopyPlane, VGAarbiterPolyPoint,
51706f2543Smrg    VGAarbiterPolylines, VGAarbiterPolySegment, VGAarbiterPolyRectangle,
52706f2543Smrg    VGAarbiterPolyArc, VGAarbiterFillPolygon, VGAarbiterPolyFillRect,
53706f2543Smrg    VGAarbiterPolyFillArc, VGAarbiterPolyText8, VGAarbiterPolyText16,
54706f2543Smrg    VGAarbiterImageText8, VGAarbiterImageText16, VGAarbiterImageGlyphBlt,
55706f2543Smrg    VGAarbiterPolyGlyphBlt, VGAarbiterPushPixels,
56706f2543Smrg};
57706f2543Smrg
58706f2543Smrgstatic miPointerSpriteFuncRec VGAarbiterSpriteFuncs = {
59706f2543Smrg    VGAarbiterSpriteRealizeCursor, VGAarbiterSpriteUnrealizeCursor,
60706f2543Smrg    VGAarbiterSpriteSetCursor, VGAarbiterSpriteMoveCursor,
61706f2543Smrg    VGAarbiterDeviceCursorInitialize, VGAarbiterDeviceCursorCleanup
62706f2543Smrg};
63706f2543Smrg
64706f2543Smrgstatic DevPrivateKeyRec VGAarbiterScreenKeyRec;
65706f2543Smrg#define VGAarbiterScreenKey (&VGAarbiterScreenKeyRec)
66706f2543Smrgstatic DevPrivateKeyRec VGAarbiterGCKeyRec;
67706f2543Smrg#define VGAarbiterGCKey (&VGAarbiterGCKeyRec)
68706f2543Smrg
69706f2543Smrgstatic int vga_no_arb = 0;
70706f2543Smrgvoid
71706f2543Smrgxf86VGAarbiterInit(void)
72706f2543Smrg{
73706f2543Smrg    if (pci_device_vgaarb_init() != 0) {
74706f2543Smrg	vga_no_arb = 1;
75706f2543Smrg        xf86Msg(X_WARNING, "VGA arbiter: cannot open kernel arbiter, no multi-card support\n");
76706f2543Smrg    }
77706f2543Smrg}
78706f2543Smrg
79706f2543Smrgvoid
80706f2543Smrgxf86VGAarbiterFini(void)
81706f2543Smrg{
82706f2543Smrg    if (vga_no_arb)
83706f2543Smrg	return;
84706f2543Smrg    pci_device_vgaarb_fini();
85706f2543Smrg}
86706f2543Smrg
87706f2543Smrgvoid
88706f2543Smrgxf86VGAarbiterLock(ScrnInfoPtr pScrn)
89706f2543Smrg{
90706f2543Smrg    if (vga_no_arb)
91706f2543Smrg	return;
92706f2543Smrg    pci_device_vgaarb_set_target(pScrn->vgaDev);
93706f2543Smrg    pci_device_vgaarb_lock();
94706f2543Smrg}
95706f2543Smrg
96706f2543Smrgvoid
97706f2543Smrgxf86VGAarbiterUnlock(ScrnInfoPtr pScrn)
98706f2543Smrg{
99706f2543Smrg    if (vga_no_arb)
100706f2543Smrg	return;
101706f2543Smrg    pci_device_vgaarb_unlock();
102706f2543Smrg}
103706f2543Smrg
104706f2543SmrgBool xf86VGAarbiterAllowDRI(ScreenPtr pScreen)
105706f2543Smrg{
106706f2543Smrg    int vga_count;
107706f2543Smrg    int rsrc_decodes;
108706f2543Smrg    ScrnInfoPtr         pScrn = xf86Screens[pScreen->myNum];
109706f2543Smrg
110706f2543Smrg    if (vga_no_arb)
111706f2543Smrg	return TRUE;
112706f2543Smrg
113706f2543Smrg    pci_device_vgaarb_get_info(pScrn->vgaDev, &vga_count, &rsrc_decodes);
114706f2543Smrg    if (vga_count > 1) {
115706f2543Smrg        if (rsrc_decodes) {
116706f2543Smrg            return FALSE;
117706f2543Smrg        }
118706f2543Smrg    }
119706f2543Smrg    return TRUE;
120706f2543Smrg}
121706f2543Smrg
122706f2543Smrgvoid
123706f2543Smrgxf86VGAarbiterScrnInit(ScrnInfoPtr pScrn)
124706f2543Smrg{
125706f2543Smrg    struct pci_device *dev;
126706f2543Smrg    EntityPtr pEnt;
127706f2543Smrg
128706f2543Smrg    if (vga_no_arb)
129706f2543Smrg	return;
130706f2543Smrg
131706f2543Smrg    pEnt = xf86Entities[pScrn->entityList[0]];
132706f2543Smrg    if (pEnt->bus.type != BUS_PCI)
133706f2543Smrg	return;
134706f2543Smrg
135706f2543Smrg    dev = pEnt->bus.id.pci;
136706f2543Smrg    pScrn->vgaDev = dev;
137706f2543Smrg}
138706f2543Smrg
139706f2543Smrgvoid
140706f2543Smrgxf86VGAarbiterDeviceDecodes(ScrnInfoPtr pScrn, int rsrc)
141706f2543Smrg{
142706f2543Smrg    if (vga_no_arb)
143706f2543Smrg	return;
144706f2543Smrg    pci_device_vgaarb_set_target(pScrn->vgaDev);
145706f2543Smrg    pci_device_vgaarb_decodes(rsrc);
146706f2543Smrg}
147706f2543Smrg
148706f2543SmrgBool
149706f2543Smrgxf86VGAarbiterWrapFunctions(void)
150706f2543Smrg{
151706f2543Smrg    ScrnInfoPtr pScrn;
152706f2543Smrg    VGAarbiterScreenPtr pScreenPriv;
153706f2543Smrg    miPointerScreenPtr PointPriv;
154706f2543Smrg    PictureScreenPtr    ps;
155706f2543Smrg    ScreenPtr pScreen;
156706f2543Smrg    int vga_count, i;
157706f2543Smrg
158706f2543Smrg    if (vga_no_arb)
159706f2543Smrg        return FALSE;
160706f2543Smrg
161706f2543Smrg    /*
162706f2543Smrg     * we need to wrap the arbiter if we have more than
163706f2543Smrg     * one VGA card - hotplug cries.
164706f2543Smrg     */
165706f2543Smrg    pci_device_vgaarb_get_info(NULL, &vga_count, NULL);
166706f2543Smrg    if (vga_count < 2 || !xf86Screens)
167706f2543Smrg        return FALSE;
168706f2543Smrg
169706f2543Smrg    xf86Msg(X_INFO,"Found %d VGA devices: arbiter wrapping enabled\n",
170706f2543Smrg            vga_count);
171706f2543Smrg
172706f2543Smrg    for (i = 0; i < xf86NumScreens; i++) {
173706f2543Smrg        pScreen = xf86Screens[i]->pScreen;
174706f2543Smrg        ps = GetPictureScreenIfSet(pScreen);
175706f2543Smrg        pScrn = xf86Screens[pScreen->myNum];
176706f2543Smrg        PointPriv = dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey);
177706f2543Smrg
178706f2543Smrg        if (!dixRegisterPrivateKey(&VGAarbiterGCKeyRec, PRIVATE_GC, sizeof(VGAarbiterGCRec)))
179706f2543Smrg            return FALSE;
180706f2543Smrg
181706f2543Smrg	if (!dixRegisterPrivateKey(&VGAarbiterScreenKeyRec, PRIVATE_SCREEN, 0))
182706f2543Smrg	    return FALSE;
183706f2543Smrg
184706f2543Smrg        if (!(pScreenPriv = malloc(sizeof(VGAarbiterScreenRec))))
185706f2543Smrg            return FALSE;
186706f2543Smrg
187706f2543Smrg        dixSetPrivate(&pScreen->devPrivates, VGAarbiterScreenKey, pScreenPriv);
188706f2543Smrg
189706f2543Smrg        WRAP_SCREEN(CloseScreen, VGAarbiterCloseScreen);
190706f2543Smrg        WRAP_SCREEN(SaveScreen, VGAarbiterSaveScreen);
191706f2543Smrg        WRAP_SCREEN(WakeupHandler, VGAarbiterWakeupHandler);
192706f2543Smrg        WRAP_SCREEN(BlockHandler, VGAarbiterBlockHandler);
193706f2543Smrg        WRAP_SCREEN(CreateGC, VGAarbiterCreateGC);
194706f2543Smrg        WRAP_SCREEN(GetImage, VGAarbiterGetImage);
195706f2543Smrg        WRAP_SCREEN(GetSpans, VGAarbiterGetSpans);
196706f2543Smrg        WRAP_SCREEN(SourceValidate, VGAarbiterSourceValidate);
197706f2543Smrg        WRAP_SCREEN(CopyWindow, VGAarbiterCopyWindow);
198706f2543Smrg        WRAP_SCREEN(ClearToBackground, VGAarbiterClearToBackground);
199706f2543Smrg        WRAP_SCREEN(CreatePixmap, VGAarbiterCreatePixmap);
200706f2543Smrg        WRAP_SCREEN(StoreColors, VGAarbiterStoreColors);
201706f2543Smrg        WRAP_SCREEN(DisplayCursor, VGAarbiterDisplayCursor);
202706f2543Smrg        WRAP_SCREEN(RealizeCursor, VGAarbiterRealizeCursor);
203706f2543Smrg        WRAP_SCREEN(UnrealizeCursor, VGAarbiterUnrealizeCursor);
204706f2543Smrg        WRAP_SCREEN(RecolorCursor, VGAarbiterRecolorCursor);
205706f2543Smrg        WRAP_SCREEN(SetCursorPosition, VGAarbiterSetCursorPosition);
206706f2543Smrg        WRAP_PICT(Composite,VGAarbiterComposite);
207706f2543Smrg        WRAP_PICT(Glyphs,VGAarbiterGlyphs);
208706f2543Smrg        WRAP_PICT(CompositeRects,VGAarbiterCompositeRects);
209706f2543Smrg        WRAP_SCREEN_INFO(AdjustFrame, VGAarbiterAdjustFrame);
210706f2543Smrg        WRAP_SCREEN_INFO(SwitchMode, VGAarbiterSwitchMode);
211706f2543Smrg        WRAP_SCREEN_INFO(EnterVT, VGAarbiterEnterVT);
212706f2543Smrg        WRAP_SCREEN_INFO(LeaveVT, VGAarbiterLeaveVT);
213706f2543Smrg        WRAP_SCREEN_INFO(FreeScreen, VGAarbiterFreeScreen);
214706f2543Smrg        WRAP_SPRITE;
215706f2543Smrg    }
216706f2543Smrg
217706f2543Smrg    return TRUE;
218706f2543Smrg}
219706f2543Smrg
220706f2543Smrg/* Screen funcs */
221706f2543Smrgstatic Bool
222706f2543SmrgVGAarbiterCloseScreen (int i, ScreenPtr pScreen)
223706f2543Smrg{
224706f2543Smrg    Bool val;
225706f2543Smrg    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
226706f2543Smrg    VGAarbiterScreenPtr pScreenPriv = (VGAarbiterScreenPtr)dixLookupPrivate(
227706f2543Smrg        &pScreen->devPrivates, VGAarbiterScreenKey);
228706f2543Smrg    miPointerScreenPtr PointPriv = (miPointerScreenPtr)dixLookupPrivate(
229706f2543Smrg        &pScreen->devPrivates, miPointerScreenKey);
230706f2543Smrg    PictureScreenPtr    ps = GetPictureScreenIfSet(pScreen);
231706f2543Smrg
232706f2543Smrg    UNWRAP_SCREEN(CreateGC);
233706f2543Smrg    UNWRAP_SCREEN(CloseScreen);
234706f2543Smrg    UNWRAP_SCREEN(GetImage);
235706f2543Smrg    UNWRAP_SCREEN(GetSpans);
236706f2543Smrg    UNWRAP_SCREEN(SourceValidate);
237706f2543Smrg    UNWRAP_SCREEN(CopyWindow);
238706f2543Smrg    UNWRAP_SCREEN(ClearToBackground);
239706f2543Smrg    UNWRAP_SCREEN(SaveScreen);
240706f2543Smrg    UNWRAP_SCREEN(StoreColors);
241706f2543Smrg    UNWRAP_SCREEN(DisplayCursor);
242706f2543Smrg    UNWRAP_SCREEN(RealizeCursor);
243706f2543Smrg    UNWRAP_SCREEN(UnrealizeCursor);
244706f2543Smrg    UNWRAP_SCREEN(RecolorCursor);
245706f2543Smrg    UNWRAP_SCREEN(SetCursorPosition);
246706f2543Smrg    UNWRAP_PICT(Composite);
247706f2543Smrg    UNWRAP_PICT(Glyphs);
248706f2543Smrg    UNWRAP_PICT(CompositeRects);
249706f2543Smrg    UNWRAP_SCREEN_INFO(AdjustFrame);
250706f2543Smrg    UNWRAP_SCREEN_INFO(SwitchMode);
251706f2543Smrg    UNWRAP_SCREEN_INFO(EnterVT);
252706f2543Smrg    UNWRAP_SCREEN_INFO(LeaveVT);
253706f2543Smrg    UNWRAP_SCREEN_INFO(FreeScreen);
254706f2543Smrg    UNWRAP_SPRITE;
255706f2543Smrg
256706f2543Smrg    free((pointer) pScreenPriv);
257706f2543Smrg    xf86VGAarbiterLock(xf86Screens[i]);
258706f2543Smrg    val = (*pScreen->CloseScreen) (i, pScreen);
259706f2543Smrg    xf86VGAarbiterUnlock(xf86Screens[i]);
260706f2543Smrg    return val;
261706f2543Smrg}
262706f2543Smrg
263706f2543Smrgstatic void
264706f2543SmrgVGAarbiterBlockHandler(int i,
265706f2543Smrg                       pointer blockData, pointer pTimeout, pointer pReadmask)
266706f2543Smrg{
267706f2543Smrg    ScreenPtr pScreen = screenInfo.screens[i];
268706f2543Smrg    SCREEN_PROLOG(BlockHandler);
269706f2543Smrg    VGAGet(pScreen);
270706f2543Smrg    pScreen->BlockHandler(i, blockData, pTimeout, pReadmask);
271706f2543Smrg    VGAPut();
272706f2543Smrg    SCREEN_EPILOG(BlockHandler, VGAarbiterBlockHandler);
273706f2543Smrg}
274706f2543Smrg
275706f2543Smrgstatic void
276706f2543SmrgVGAarbiterWakeupHandler(int i, pointer blockData, unsigned long result, pointer pReadmask)
277706f2543Smrg{
278706f2543Smrg    ScreenPtr pScreen = screenInfo.screens[i];
279706f2543Smrg    SCREEN_PROLOG(WakeupHandler);
280706f2543Smrg    VGAGet(pScreen);
281706f2543Smrg    pScreen->WakeupHandler(i, blockData, result, pReadmask);
282706f2543Smrg    VGAPut();
283706f2543Smrg    SCREEN_EPILOG(WakeupHandler, VGAarbiterWakeupHandler);
284706f2543Smrg}
285706f2543Smrg
286706f2543Smrgstatic void
287706f2543SmrgVGAarbiterGetImage (
288706f2543Smrg    DrawablePtr pDrawable,
289706f2543Smrg    int sx, int sy, int w, int h,
290706f2543Smrg    unsigned int    format,
291706f2543Smrg    unsigned long   planemask,
292706f2543Smrg    char        *pdstLine
293706f2543Smrg    )
294706f2543Smrg{
295706f2543Smrg    ScreenPtr pScreen = pDrawable->pScreen;
296706f2543Smrg    SCREEN_PROLOG(GetImage);
297706f2543Smrg//    if (xf86Screens[pScreen->myNum]->vtSema) {
298706f2543Smrg    VGAGet(pScreen);
299706f2543Smrg//    }
300706f2543Smrg    (*pScreen->GetImage) (pDrawable, sx, sy, w, h,
301706f2543Smrg              format, planemask, pdstLine);
302706f2543Smrg    VGAPut();
303706f2543Smrg    SCREEN_EPILOG (GetImage, VGAarbiterGetImage);
304706f2543Smrg}
305706f2543Smrg
306706f2543Smrgstatic void
307706f2543SmrgVGAarbiterGetSpans (
308706f2543Smrg    DrawablePtr pDrawable,
309706f2543Smrg    int     wMax,
310706f2543Smrg    DDXPointPtr ppt,
311706f2543Smrg    int     *pwidth,
312706f2543Smrg    int     nspans,
313706f2543Smrg    char    *pdstStart
314706f2543Smrg    )
315706f2543Smrg{
316706f2543Smrg    ScreenPtr       pScreen = pDrawable->pScreen;
317706f2543Smrg
318706f2543Smrg    SCREEN_PROLOG (GetSpans);
319706f2543Smrg    VGAGet(pScreen);
320706f2543Smrg    (*pScreen->GetSpans) (pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
321706f2543Smrg    VGAPut();
322706f2543Smrg    SCREEN_EPILOG (GetSpans, VGAarbiterGetSpans);
323706f2543Smrg}
324706f2543Smrg
325706f2543Smrgstatic void
326706f2543SmrgVGAarbiterSourceValidate (
327706f2543Smrg    DrawablePtr pDrawable,
328706f2543Smrg    int x, int y, int width, int height,
329706f2543Smrg    unsigned int subWindowMode )
330706f2543Smrg{
331706f2543Smrg    ScreenPtr   pScreen = pDrawable->pScreen;
332706f2543Smrg    SCREEN_PROLOG (SourceValidate);
333706f2543Smrg    VGAGet(pScreen);
334706f2543Smrg    if (pScreen->SourceValidate)
335706f2543Smrg    (*pScreen->SourceValidate) (pDrawable, x, y, width, height, subWindowMode);
336706f2543Smrg    VGAPut();
337706f2543Smrg    SCREEN_EPILOG (SourceValidate, VGAarbiterSourceValidate);
338706f2543Smrg}
339706f2543Smrg
340706f2543Smrgstatic void
341706f2543SmrgVGAarbiterCopyWindow(
342706f2543Smrg    WindowPtr pWin,
343706f2543Smrg    DDXPointRec ptOldOrg,
344706f2543Smrg    RegionPtr prgnSrc )
345706f2543Smrg{
346706f2543Smrg    ScreenPtr pScreen = pWin->drawable.pScreen;
347706f2543Smrg
348706f2543Smrg    SCREEN_PROLOG (CopyWindow);
349706f2543Smrg    VGAGet(pScreen);
350706f2543Smrg    (*pScreen->CopyWindow) (pWin, ptOldOrg, prgnSrc);
351706f2543Smrg    VGAPut();
352706f2543Smrg    SCREEN_EPILOG (CopyWindow, VGAarbiterCopyWindow);
353706f2543Smrg}
354706f2543Smrg
355706f2543Smrgstatic void
356706f2543SmrgVGAarbiterClearToBackground (
357706f2543Smrg    WindowPtr pWin,
358706f2543Smrg    int x, int y,
359706f2543Smrg    int w, int h,
360706f2543Smrg    Bool generateExposures )
361706f2543Smrg{
362706f2543Smrg    ScreenPtr pScreen = pWin->drawable.pScreen;
363706f2543Smrg
364706f2543Smrg    SCREEN_PROLOG ( ClearToBackground);
365706f2543Smrg    VGAGet(pScreen);
366706f2543Smrg    (*pScreen->ClearToBackground) (pWin, x, y, w, h, generateExposures);
367706f2543Smrg    VGAPut();
368706f2543Smrg    SCREEN_EPILOG (ClearToBackground, VGAarbiterClearToBackground);
369706f2543Smrg}
370706f2543Smrg
371706f2543Smrgstatic PixmapPtr
372706f2543SmrgVGAarbiterCreatePixmap(ScreenPtr pScreen, int w, int h, int depth, unsigned usage_hint)
373706f2543Smrg{
374706f2543Smrg    PixmapPtr pPix;
375706f2543Smrg
376706f2543Smrg    SCREEN_PROLOG ( CreatePixmap);
377706f2543Smrg    VGAGet(pScreen);
378706f2543Smrg    pPix = (*pScreen->CreatePixmap) (pScreen, w, h, depth, usage_hint);
379706f2543Smrg    VGAPut();
380706f2543Smrg    SCREEN_EPILOG (CreatePixmap, VGAarbiterCreatePixmap);
381706f2543Smrg
382706f2543Smrg    return pPix;
383706f2543Smrg}
384706f2543Smrg
385706f2543Smrgstatic Bool
386706f2543SmrgVGAarbiterSaveScreen(ScreenPtr pScreen, Bool unblank)
387706f2543Smrg{
388706f2543Smrg    Bool val;
389706f2543Smrg
390706f2543Smrg    SCREEN_PROLOG (SaveScreen);
391706f2543Smrg    VGAGet(pScreen);
392706f2543Smrg    val = (*pScreen->SaveScreen) (pScreen, unblank);
393706f2543Smrg    VGAPut();
394706f2543Smrg    SCREEN_EPILOG (SaveScreen, VGAarbiterSaveScreen);
395706f2543Smrg
396706f2543Smrg    return val;
397706f2543Smrg}
398706f2543Smrg
399706f2543Smrgstatic void
400706f2543SmrgVGAarbiterStoreColors (
401706f2543Smrg    ColormapPtr        pmap,
402706f2543Smrg    int                ndef,
403706f2543Smrg    xColorItem         *pdefs)
404706f2543Smrg{
405706f2543Smrg    ScreenPtr pScreen = pmap->pScreen;
406706f2543Smrg
407706f2543Smrg    SCREEN_PROLOG (StoreColors);
408706f2543Smrg    VGAGet(pScreen);
409706f2543Smrg    (*pScreen->StoreColors) (pmap,ndef,pdefs);
410706f2543Smrg    VGAPut();
411706f2543Smrg    SCREEN_EPILOG ( StoreColors, VGAarbiterStoreColors);
412706f2543Smrg}
413706f2543Smrg
414706f2543Smrgstatic void
415706f2543SmrgVGAarbiterRecolorCursor (
416706f2543Smrg    DeviceIntPtr pDev,
417706f2543Smrg    ScreenPtr pScreen,
418706f2543Smrg    CursorPtr pCurs,
419706f2543Smrg    Bool displayed
420706f2543Smrg    )
421706f2543Smrg{
422706f2543Smrg    SCREEN_PROLOG (RecolorCursor);
423706f2543Smrg    VGAGet(pScreen);
424706f2543Smrg    (*pScreen->RecolorCursor) (pDev, pScreen, pCurs, displayed);
425706f2543Smrg    VGAPut();
426706f2543Smrg    SCREEN_EPILOG ( RecolorCursor, VGAarbiterRecolorCursor);
427706f2543Smrg}
428706f2543Smrg
429706f2543Smrgstatic Bool
430706f2543SmrgVGAarbiterRealizeCursor (
431706f2543Smrg    DeviceIntPtr pDev,
432706f2543Smrg    ScreenPtr   pScreen,
433706f2543Smrg    CursorPtr   pCursor
434706f2543Smrg    )
435706f2543Smrg{
436706f2543Smrg    Bool val;
437706f2543Smrg
438706f2543Smrg    SCREEN_PROLOG (RealizeCursor);
439706f2543Smrg    VGAGet(pScreen);
440706f2543Smrg    val = (*pScreen->RealizeCursor) (pDev, pScreen,pCursor);
441706f2543Smrg    VGAPut();
442706f2543Smrg    SCREEN_EPILOG ( RealizeCursor, VGAarbiterRealizeCursor);
443706f2543Smrg    return val;
444706f2543Smrg}
445706f2543Smrg
446706f2543Smrgstatic Bool
447706f2543SmrgVGAarbiterUnrealizeCursor (
448706f2543Smrg    DeviceIntPtr pDev,
449706f2543Smrg    ScreenPtr   pScreen,
450706f2543Smrg    CursorPtr   pCursor
451706f2543Smrg    )
452706f2543Smrg{
453706f2543Smrg    Bool val;
454706f2543Smrg
455706f2543Smrg    SCREEN_PROLOG (UnrealizeCursor);
456706f2543Smrg    VGAGet(pScreen);
457706f2543Smrg    val = (*pScreen->UnrealizeCursor) (pDev, pScreen, pCursor);
458706f2543Smrg    VGAPut();
459706f2543Smrg    SCREEN_EPILOG ( UnrealizeCursor, VGAarbiterUnrealizeCursor);
460706f2543Smrg    return val;
461706f2543Smrg}
462706f2543Smrg
463706f2543Smrgstatic Bool
464706f2543SmrgVGAarbiterDisplayCursor (
465706f2543Smrg    DeviceIntPtr pDev,
466706f2543Smrg    ScreenPtr   pScreen,
467706f2543Smrg    CursorPtr   pCursor
468706f2543Smrg    )
469706f2543Smrg{
470706f2543Smrg    Bool val;
471706f2543Smrg
472706f2543Smrg    SCREEN_PROLOG (DisplayCursor);
473706f2543Smrg    VGAGet(pScreen);
474706f2543Smrg    val = (*pScreen->DisplayCursor) (pDev, pScreen, pCursor);
475706f2543Smrg    VGAPut();
476706f2543Smrg    SCREEN_EPILOG ( DisplayCursor, VGAarbiterDisplayCursor);
477706f2543Smrg    return val;
478706f2543Smrg}
479706f2543Smrg
480706f2543Smrgstatic Bool
481706f2543SmrgVGAarbiterSetCursorPosition (
482706f2543Smrg    DeviceIntPtr pDev,
483706f2543Smrg    ScreenPtr   pScreen,
484706f2543Smrg    int x, int y,
485706f2543Smrg    Bool generateEvent)
486706f2543Smrg{
487706f2543Smrg    Bool val;
488706f2543Smrg
489706f2543Smrg    SCREEN_PROLOG (SetCursorPosition);
490706f2543Smrg    VGAGet(pScreen);
491706f2543Smrg    val = (*pScreen->SetCursorPosition) (pDev, pScreen, x, y, generateEvent);
492706f2543Smrg    VGAPut();
493706f2543Smrg    SCREEN_EPILOG ( SetCursorPosition, VGAarbiterSetCursorPosition);
494706f2543Smrg    return val;
495706f2543Smrg}
496706f2543Smrg
497706f2543Smrgstatic void
498706f2543SmrgVGAarbiterAdjustFrame(int index, int x, int y, int flags)
499706f2543Smrg{
500706f2543Smrg    ScreenPtr pScreen = screenInfo.screens[index];
501706f2543Smrg    VGAarbiterScreenPtr pScreenPriv = (VGAarbiterScreenPtr)dixLookupPrivate(
502706f2543Smrg        &pScreen->devPrivates, VGAarbiterScreenKey);
503706f2543Smrg
504706f2543Smrg    VGAGet(pScreen);
505706f2543Smrg    (*pScreenPriv->AdjustFrame)(index, x, y, flags);
506706f2543Smrg    VGAPut();
507706f2543Smrg}
508706f2543Smrg
509706f2543Smrgstatic Bool
510706f2543SmrgVGAarbiterSwitchMode(int index, DisplayModePtr mode, int flags)
511706f2543Smrg{
512706f2543Smrg    Bool val;
513706f2543Smrg    ScreenPtr pScreen = screenInfo.screens[index];
514706f2543Smrg    VGAarbiterScreenPtr pScreenPriv = (VGAarbiterScreenPtr)dixLookupPrivate(
515706f2543Smrg        &pScreen->devPrivates, VGAarbiterScreenKey);
516706f2543Smrg
517706f2543Smrg    VGAGet(pScreen);
518706f2543Smrg    val = (*pScreenPriv->SwitchMode)(index, mode, flags);
519706f2543Smrg    VGAPut();
520706f2543Smrg    return val;
521706f2543Smrg}
522706f2543Smrg
523706f2543Smrgstatic Bool
524706f2543SmrgVGAarbiterEnterVT(int index, int flags)
525706f2543Smrg{
526706f2543Smrg    Bool val;
527706f2543Smrg    ScrnInfoPtr pScrn = xf86Screens[index];
528706f2543Smrg    ScreenPtr pScreen = screenInfo.screens[index];
529706f2543Smrg    VGAarbiterScreenPtr pScreenPriv = (VGAarbiterScreenPtr)dixLookupPrivate(
530706f2543Smrg        &pScreen->devPrivates, VGAarbiterScreenKey);
531706f2543Smrg
532706f2543Smrg    VGAGet(pScreen);
533706f2543Smrg    pScrn->EnterVT = pScreenPriv->EnterVT;
534706f2543Smrg    val = (*pScrn->EnterVT)(index, flags);
535706f2543Smrg    pScreenPriv->EnterVT = pScrn->EnterVT;
536706f2543Smrg    pScrn->EnterVT = VGAarbiterEnterVT;
537706f2543Smrg    VGAPut();
538706f2543Smrg    return val;
539706f2543Smrg}
540706f2543Smrg
541706f2543Smrgstatic void
542706f2543SmrgVGAarbiterLeaveVT(int index, int flags)
543706f2543Smrg{
544706f2543Smrg    ScrnInfoPtr pScrn = xf86Screens[index];
545706f2543Smrg    ScreenPtr pScreen = screenInfo.screens[index];
546706f2543Smrg    VGAarbiterScreenPtr pScreenPriv = (VGAarbiterScreenPtr)dixLookupPrivate(
547706f2543Smrg        &pScreen->devPrivates, VGAarbiterScreenKey);
548706f2543Smrg
549706f2543Smrg    VGAGet(pScreen);
550706f2543Smrg    pScrn->LeaveVT = pScreenPriv->LeaveVT;
551706f2543Smrg    (*pScreenPriv->LeaveVT)(index, flags);
552706f2543Smrg    pScreenPriv->LeaveVT = pScrn->LeaveVT;
553706f2543Smrg    pScrn->LeaveVT = VGAarbiterLeaveVT;
554706f2543Smrg    VGAPut();
555706f2543Smrg}
556706f2543Smrg
557706f2543Smrgstatic void
558706f2543SmrgVGAarbiterFreeScreen(int index, int flags)
559706f2543Smrg{
560706f2543Smrg    ScreenPtr pScreen = screenInfo.screens[index];
561706f2543Smrg    VGAarbiterScreenPtr pScreenPriv = (VGAarbiterScreenPtr)dixLookupPrivate(
562706f2543Smrg        &pScreen->devPrivates, VGAarbiterScreenKey);
563706f2543Smrg
564706f2543Smrg    VGAGet(pScreen);
565706f2543Smrg    (*pScreenPriv->FreeScreen)(index, flags);
566706f2543Smrg    VGAPut();
567706f2543Smrg}
568706f2543Smrg
569706f2543Smrgstatic Bool
570706f2543SmrgVGAarbiterCreateGC(GCPtr pGC)
571706f2543Smrg{
572706f2543Smrg    ScreenPtr    pScreen = pGC->pScreen;
573706f2543Smrg    VGAarbiterGCPtr pGCPriv = (VGAarbiterGCPtr)dixLookupPrivate(&pGC->devPrivates, VGAarbiterGCKey);
574706f2543Smrg    Bool         ret;
575706f2543Smrg
576706f2543Smrg    SCREEN_PROLOG(CreateGC);
577706f2543Smrg    ret = (*pScreen->CreateGC)(pGC);
578706f2543Smrg    GC_WRAP(pGC);
579706f2543Smrg    SCREEN_EPILOG(CreateGC,VGAarbiterCreateGC);
580706f2543Smrg
581706f2543Smrg    return ret;
582706f2543Smrg}
583706f2543Smrg
584706f2543Smrg/* GC funcs */
585706f2543Smrgstatic void
586706f2543SmrgVGAarbiterValidateGC(
587706f2543Smrg   GCPtr         pGC,
588706f2543Smrg   unsigned long changes,
589706f2543Smrg   DrawablePtr   pDraw )
590706f2543Smrg{
591706f2543Smrg    GC_UNWRAP(pGC);
592706f2543Smrg    (*pGC->funcs->ValidateGC)(pGC, changes, pDraw);
593706f2543Smrg    GC_WRAP(pGC);
594706f2543Smrg}
595706f2543Smrg
596706f2543Smrg
597706f2543Smrgstatic void
598706f2543SmrgVGAarbiterDestroyGC(GCPtr pGC)
599706f2543Smrg{
600706f2543Smrg    GC_UNWRAP (pGC);
601706f2543Smrg    (*pGC->funcs->DestroyGC)(pGC);
602706f2543Smrg    GC_WRAP (pGC);
603706f2543Smrg}
604706f2543Smrg
605706f2543Smrgstatic void
606706f2543SmrgVGAarbiterChangeGC (
607706f2543Smrg    GCPtr       pGC,
608706f2543Smrg    unsigned long   mask)
609706f2543Smrg{
610706f2543Smrg    GC_UNWRAP (pGC);
611706f2543Smrg    (*pGC->funcs->ChangeGC) (pGC, mask);
612706f2543Smrg    GC_WRAP (pGC);
613706f2543Smrg}
614706f2543Smrg
615706f2543Smrgstatic void
616706f2543SmrgVGAarbiterCopyGC (
617706f2543Smrg    GCPtr       pGCSrc,
618706f2543Smrg    unsigned long   mask,
619706f2543Smrg    GCPtr       pGCDst)
620706f2543Smrg{
621706f2543Smrg    GC_UNWRAP (pGCDst);
622706f2543Smrg    (*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst);
623706f2543Smrg    GC_WRAP (pGCDst);
624706f2543Smrg}
625706f2543Smrg
626706f2543Smrgstatic void
627706f2543SmrgVGAarbiterChangeClip (
628706f2543Smrg    GCPtr   pGC,
629706f2543Smrg    int     type,
630706f2543Smrg    pointer pvalue,
631706f2543Smrg    int     nrects )
632706f2543Smrg{
633706f2543Smrg    GC_UNWRAP (pGC);
634706f2543Smrg    (*pGC->funcs->ChangeClip) (pGC, type, pvalue, nrects);
635706f2543Smrg    GC_WRAP (pGC);
636706f2543Smrg}
637706f2543Smrg
638706f2543Smrgstatic void
639706f2543SmrgVGAarbiterCopyClip(GCPtr pgcDst, GCPtr pgcSrc)
640706f2543Smrg{
641706f2543Smrg    GC_UNWRAP (pgcDst);
642706f2543Smrg    (* pgcDst->funcs->CopyClip)(pgcDst, pgcSrc);
643706f2543Smrg    GC_WRAP (pgcDst);
644706f2543Smrg}
645706f2543Smrg
646706f2543Smrgstatic void
647706f2543SmrgVGAarbiterDestroyClip(GCPtr pGC)
648706f2543Smrg{
649706f2543Smrg    GC_UNWRAP (pGC);
650706f2543Smrg    (* pGC->funcs->DestroyClip)(pGC);
651706f2543Smrg    GC_WRAP (pGC);
652706f2543Smrg}
653706f2543Smrg
654706f2543Smrg/* GC Ops */
655706f2543Smrgstatic void
656706f2543SmrgVGAarbiterFillSpans(
657706f2543Smrg    DrawablePtr pDraw,
658706f2543Smrg    GC      *pGC,
659706f2543Smrg    int     nInit,
660706f2543Smrg    DDXPointPtr pptInit,
661706f2543Smrg    int *pwidthInit,
662706f2543Smrg    int fSorted )
663706f2543Smrg{
664706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
665706f2543Smrg    GC_UNWRAP(pGC);
666706f2543Smrg    VGAGet(pScreen);
667706f2543Smrg    (*pGC->ops->FillSpans)(pDraw, pGC, nInit, pptInit, pwidthInit, fSorted);
668706f2543Smrg    VGAPut();
669706f2543Smrg    GC_WRAP(pGC);
670706f2543Smrg}
671706f2543Smrg
672706f2543Smrgstatic void
673706f2543SmrgVGAarbiterSetSpans(
674706f2543Smrg    DrawablePtr     pDraw,
675706f2543Smrg    GCPtr       pGC,
676706f2543Smrg    char        *pcharsrc,
677706f2543Smrg    register DDXPointPtr ppt,
678706f2543Smrg    int         *pwidth,
679706f2543Smrg    int         nspans,
680706f2543Smrg    int         fSorted )
681706f2543Smrg{
682706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
683706f2543Smrg    GC_UNWRAP(pGC);
684706f2543Smrg    VGAGet(pScreen);
685706f2543Smrg    (*pGC->ops->SetSpans)(pDraw, pGC, pcharsrc, ppt, pwidth, nspans, fSorted);
686706f2543Smrg    VGAPut();
687706f2543Smrg    GC_WRAP(pGC);
688706f2543Smrg}
689706f2543Smrg
690706f2543Smrgstatic void
691706f2543SmrgVGAarbiterPutImage(
692706f2543Smrg    DrawablePtr pDraw,
693706f2543Smrg    GCPtr   pGC,
694706f2543Smrg    int     depth,
695706f2543Smrg    int x, int y, int w, int h,
696706f2543Smrg    int     leftPad,
697706f2543Smrg    int     format,
698706f2543Smrg    char    *pImage )
699706f2543Smrg{
700706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
701706f2543Smrg    GC_UNWRAP(pGC);
702706f2543Smrg    VGAGet(pScreen);
703706f2543Smrg    (*pGC->ops->PutImage)(pDraw, pGC, depth, x, y, w, h,
704706f2543Smrg              leftPad, format, pImage);
705706f2543Smrg    VGAPut();
706706f2543Smrg    GC_WRAP(pGC);
707706f2543Smrg}
708706f2543Smrg
709706f2543Smrgstatic RegionPtr
710706f2543SmrgVGAarbiterCopyArea(
711706f2543Smrg    DrawablePtr pSrc,
712706f2543Smrg    DrawablePtr pDst,
713706f2543Smrg    GC *pGC,
714706f2543Smrg    int srcx, int srcy,
715706f2543Smrg    int width, int height,
716706f2543Smrg    int dstx, int dsty )
717706f2543Smrg{
718706f2543Smrg    RegionPtr ret;
719706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
720706f2543Smrg    GC_UNWRAP(pGC);
721706f2543Smrg    VGAGet(pScreen);
722706f2543Smrg    ret = (*pGC->ops->CopyArea)(pSrc, pDst,
723706f2543Smrg                pGC, srcx, srcy, width, height, dstx, dsty);
724706f2543Smrg    VGAPut();
725706f2543Smrg    GC_WRAP(pGC);
726706f2543Smrg    return ret;
727706f2543Smrg}
728706f2543Smrg
729706f2543Smrgstatic RegionPtr
730706f2543SmrgVGAarbiterCopyPlane(
731706f2543Smrg    DrawablePtr pSrc,
732706f2543Smrg    DrawablePtr pDst,
733706f2543Smrg    GCPtr pGC,
734706f2543Smrg    int srcx, int srcy,
735706f2543Smrg    int width, int height,
736706f2543Smrg    int dstx, int dsty,
737706f2543Smrg    unsigned long bitPlane )
738706f2543Smrg{
739706f2543Smrg    RegionPtr ret;
740706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
741706f2543Smrg    GC_UNWRAP(pGC);
742706f2543Smrg    VGAGet(pScreen);
743706f2543Smrg    ret = (*pGC->ops->CopyPlane)(pSrc, pDst, pGC, srcx, srcy,
744706f2543Smrg                 width, height, dstx, dsty, bitPlane);
745706f2543Smrg    VGAPut();
746706f2543Smrg    GC_WRAP(pGC);
747706f2543Smrg    return ret;
748706f2543Smrg}
749706f2543Smrg
750706f2543Smrgstatic void
751706f2543SmrgVGAarbiterPolyPoint(
752706f2543Smrg    DrawablePtr pDraw,
753706f2543Smrg    GCPtr pGC,
754706f2543Smrg    int mode,
755706f2543Smrg    int npt,
756706f2543Smrg    xPoint *pptInit )
757706f2543Smrg{
758706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
759706f2543Smrg    GC_UNWRAP(pGC);
760706f2543Smrg    VGAGet(pScreen);
761706f2543Smrg    (*pGC->ops->PolyPoint)(pDraw, pGC, mode, npt, pptInit);
762706f2543Smrg    VGAPut();
763706f2543Smrg    GC_WRAP(pGC);
764706f2543Smrg}
765706f2543Smrg
766706f2543Smrg
767706f2543Smrgstatic void
768706f2543SmrgVGAarbiterPolylines(
769706f2543Smrg    DrawablePtr pDraw,
770706f2543Smrg    GCPtr   pGC,
771706f2543Smrg    int     mode,
772706f2543Smrg    int     npt,
773706f2543Smrg    DDXPointPtr pptInit )
774706f2543Smrg{
775706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
776706f2543Smrg    GC_UNWRAP(pGC);
777706f2543Smrg    VGAGet(pScreen);
778706f2543Smrg    (*pGC->ops->Polylines)(pDraw, pGC, mode, npt, pptInit);
779706f2543Smrg    VGAPut();
780706f2543Smrg    GC_WRAP(pGC);
781706f2543Smrg}
782706f2543Smrg
783706f2543Smrgstatic void
784706f2543SmrgVGAarbiterPolySegment(
785706f2543Smrg    DrawablePtr pDraw,
786706f2543Smrg    GCPtr   pGC,
787706f2543Smrg    int     nseg,
788706f2543Smrg    xSegment    *pSeg )
789706f2543Smrg{
790706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
791706f2543Smrg    GC_UNWRAP(pGC);
792706f2543Smrg    VGAGet(pScreen);
793706f2543Smrg    (*pGC->ops->PolySegment)(pDraw, pGC, nseg, pSeg);
794706f2543Smrg    VGAPut();
795706f2543Smrg    GC_WRAP(pGC);
796706f2543Smrg}
797706f2543Smrg
798706f2543Smrgstatic void
799706f2543SmrgVGAarbiterPolyRectangle(
800706f2543Smrg    DrawablePtr  pDraw,
801706f2543Smrg    GCPtr        pGC,
802706f2543Smrg    int          nRectsInit,
803706f2543Smrg    xRectangle  *pRectsInit )
804706f2543Smrg{
805706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
806706f2543Smrg    GC_UNWRAP(pGC);
807706f2543Smrg    VGAGet(pScreen);
808706f2543Smrg    (*pGC->ops->PolyRectangle)(pDraw, pGC, nRectsInit, pRectsInit);
809706f2543Smrg    VGAPut();
810706f2543Smrg    GC_WRAP(pGC);
811706f2543Smrg}
812706f2543Smrg
813706f2543Smrgstatic void
814706f2543SmrgVGAarbiterPolyArc(
815706f2543Smrg    DrawablePtr pDraw,
816706f2543Smrg    GCPtr   pGC,
817706f2543Smrg    int     narcs,
818706f2543Smrg    xArc    *parcs )
819706f2543Smrg{
820706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
821706f2543Smrg    GC_UNWRAP(pGC);
822706f2543Smrg    VGAGet(pScreen);
823706f2543Smrg    (*pGC->ops->PolyArc)(pDraw, pGC, narcs, parcs);
824706f2543Smrg    VGAPut();
825706f2543Smrg    GC_WRAP(pGC);
826706f2543Smrg}
827706f2543Smrg
828706f2543Smrgstatic void
829706f2543SmrgVGAarbiterFillPolygon(
830706f2543Smrg    DrawablePtr pDraw,
831706f2543Smrg    GCPtr   pGC,
832706f2543Smrg    int     shape,
833706f2543Smrg    int     mode,
834706f2543Smrg    int     count,
835706f2543Smrg    DDXPointPtr ptsIn )
836706f2543Smrg{
837706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
838706f2543Smrg    GC_UNWRAP(pGC);
839706f2543Smrg    VGAGet(pScreen);
840706f2543Smrg    (*pGC->ops->FillPolygon)(pDraw, pGC, shape, mode, count, ptsIn);
841706f2543Smrg    VGAPut();
842706f2543Smrg    GC_WRAP(pGC);
843706f2543Smrg}
844706f2543Smrg
845706f2543Smrgstatic void
846706f2543SmrgVGAarbiterPolyFillRect(
847706f2543Smrg    DrawablePtr pDraw,
848706f2543Smrg    GCPtr   pGC,
849706f2543Smrg    int     nrectFill,
850706f2543Smrg    xRectangle  *prectInit)
851706f2543Smrg{
852706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
853706f2543Smrg    GC_UNWRAP(pGC);
854706f2543Smrg    VGAGet(pScreen);
855706f2543Smrg    (*pGC->ops->PolyFillRect)(pDraw, pGC, nrectFill, prectInit);
856706f2543Smrg    VGAPut();
857706f2543Smrg    GC_WRAP(pGC);
858706f2543Smrg}
859706f2543Smrg
860706f2543Smrgstatic void
861706f2543SmrgVGAarbiterPolyFillArc(
862706f2543Smrg    DrawablePtr pDraw,
863706f2543Smrg    GCPtr   pGC,
864706f2543Smrg    int     narcs,
865706f2543Smrg    xArc    *parcs )
866706f2543Smrg{
867706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
868706f2543Smrg    GC_UNWRAP(pGC);
869706f2543Smrg    VGAGet(pScreen);
870706f2543Smrg    (*pGC->ops->PolyFillArc)(pDraw, pGC, narcs, parcs);
871706f2543Smrg    VGAPut();
872706f2543Smrg    GC_WRAP(pGC);
873706f2543Smrg}
874706f2543Smrg
875706f2543Smrgstatic int
876706f2543SmrgVGAarbiterPolyText8(
877706f2543Smrg    DrawablePtr pDraw,
878706f2543Smrg    GCPtr   pGC,
879706f2543Smrg    int     x,
880706f2543Smrg    int     y,
881706f2543Smrg    int     count,
882706f2543Smrg    char    *chars )
883706f2543Smrg{
884706f2543Smrg    int ret;
885706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
886706f2543Smrg    GC_UNWRAP(pGC);
887706f2543Smrg    VGAGet(pScreen);
888706f2543Smrg    ret = (*pGC->ops->PolyText8)(pDraw, pGC, x, y, count, chars);
889706f2543Smrg    VGAPut();
890706f2543Smrg    GC_WRAP(pGC);
891706f2543Smrg    return ret;
892706f2543Smrg}
893706f2543Smrg
894706f2543Smrgstatic int
895706f2543SmrgVGAarbiterPolyText16(
896706f2543Smrg    DrawablePtr pDraw,
897706f2543Smrg    GCPtr   pGC,
898706f2543Smrg    int     x,
899706f2543Smrg    int     y,
900706f2543Smrg    int     count,
901706f2543Smrg    unsigned short *chars )
902706f2543Smrg{
903706f2543Smrg    int ret;
904706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
905706f2543Smrg    GC_UNWRAP(pGC);
906706f2543Smrg    VGAGet(pScreen);
907706f2543Smrg    ret = (*pGC->ops->PolyText16)(pDraw, pGC, x, y, count, chars);
908706f2543Smrg    VGAPut();
909706f2543Smrg    GC_WRAP(pGC);
910706f2543Smrg    return ret;
911706f2543Smrg}
912706f2543Smrg
913706f2543Smrgstatic void
914706f2543SmrgVGAarbiterImageText8(
915706f2543Smrg    DrawablePtr pDraw,
916706f2543Smrg    GCPtr   pGC,
917706f2543Smrg    int     x,
918706f2543Smrg    int     y,
919706f2543Smrg    int     count,
920706f2543Smrg    char    *chars )
921706f2543Smrg{
922706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
923706f2543Smrg    GC_UNWRAP(pGC);
924706f2543Smrg    VGAGet(pScreen);
925706f2543Smrg    (*pGC->ops->ImageText8)(pDraw, pGC, x, y, count, chars);
926706f2543Smrg    VGAPut();
927706f2543Smrg    GC_WRAP(pGC);
928706f2543Smrg}
929706f2543Smrg
930706f2543Smrgstatic void
931706f2543SmrgVGAarbiterImageText16(
932706f2543Smrg    DrawablePtr pDraw,
933706f2543Smrg    GCPtr   pGC,
934706f2543Smrg    int     x,
935706f2543Smrg    int     y,
936706f2543Smrg    int     count,
937706f2543Smrg    unsigned short *chars )
938706f2543Smrg{
939706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
940706f2543Smrg    GC_UNWRAP(pGC);
941706f2543Smrg    VGAGet(pScreen);
942706f2543Smrg    (*pGC->ops->ImageText16)(pDraw, pGC, x, y, count, chars);
943706f2543Smrg    VGAPut();
944706f2543Smrg    GC_WRAP(pGC);
945706f2543Smrg}
946706f2543Smrg
947706f2543Smrg
948706f2543Smrgstatic void
949706f2543SmrgVGAarbiterImageGlyphBlt(
950706f2543Smrg    DrawablePtr pDraw,
951706f2543Smrg    GCPtr pGC,
952706f2543Smrg    int xInit, int yInit,
953706f2543Smrg    unsigned int nglyph,
954706f2543Smrg    CharInfoPtr *ppci,
955706f2543Smrg    pointer pglyphBase )
956706f2543Smrg{
957706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
958706f2543Smrg    GC_UNWRAP(pGC);
959706f2543Smrg    VGAGet(pScreen);
960706f2543Smrg    (*pGC->ops->ImageGlyphBlt)(pDraw, pGC, xInit, yInit,
961706f2543Smrg                   nglyph, ppci, pglyphBase);
962706f2543Smrg    VGAPut();
963706f2543Smrg    GC_WRAP(pGC);
964706f2543Smrg}
965706f2543Smrg
966706f2543Smrgstatic void
967706f2543SmrgVGAarbiterPolyGlyphBlt(
968706f2543Smrg    DrawablePtr pDraw,
969706f2543Smrg    GCPtr pGC,
970706f2543Smrg    int xInit, int yInit,
971706f2543Smrg    unsigned int nglyph,
972706f2543Smrg    CharInfoPtr *ppci,
973706f2543Smrg    pointer pglyphBase )
974706f2543Smrg{
975706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
976706f2543Smrg    GC_UNWRAP(pGC);
977706f2543Smrg    VGAGet(pScreen);
978706f2543Smrg    (*pGC->ops->PolyGlyphBlt)(pDraw, pGC, xInit, yInit,
979706f2543Smrg                  nglyph, ppci, pglyphBase);
980706f2543Smrg    VGAPut();
981706f2543Smrg    GC_WRAP(pGC);
982706f2543Smrg}
983706f2543Smrg
984706f2543Smrgstatic void
985706f2543SmrgVGAarbiterPushPixels(
986706f2543Smrg    GCPtr   pGC,
987706f2543Smrg    PixmapPtr   pBitMap,
988706f2543Smrg    DrawablePtr pDraw,
989706f2543Smrg    int dx, int dy, int xOrg, int yOrg )
990706f2543Smrg{
991706f2543Smrg    ScreenPtr pScreen = pGC->pScreen;
992706f2543Smrg    GC_UNWRAP(pGC);
993706f2543Smrg    VGAGet(pScreen);
994706f2543Smrg    (*pGC->ops->PushPixels)(pGC, pBitMap, pDraw, dx, dy, xOrg, yOrg);
995706f2543Smrg    VGAPut();
996706f2543Smrg    GC_WRAP(pGC);
997706f2543Smrg}
998706f2543Smrg
999706f2543Smrg
1000706f2543Smrg/* miSpriteFuncs */
1001706f2543Smrgstatic Bool
1002706f2543SmrgVGAarbiterSpriteRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCur)
1003706f2543Smrg{
1004706f2543Smrg    Bool val;
1005706f2543Smrg    SPRITE_PROLOG;
1006706f2543Smrg    VGAGet(pScreen);
1007706f2543Smrg    val = PointPriv->spriteFuncs->RealizeCursor(pDev, pScreen, pCur);
1008706f2543Smrg    VGAPut();
1009706f2543Smrg    SPRITE_EPILOG;
1010706f2543Smrg    return val;
1011706f2543Smrg}
1012706f2543Smrg
1013706f2543Smrgstatic Bool
1014706f2543SmrgVGAarbiterSpriteUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCur)
1015706f2543Smrg{
1016706f2543Smrg    Bool val;
1017706f2543Smrg    SPRITE_PROLOG;
1018706f2543Smrg    VGAGet(pScreen);
1019706f2543Smrg    val = PointPriv->spriteFuncs->UnrealizeCursor(pDev, pScreen, pCur);
1020706f2543Smrg    VGAPut();
1021706f2543Smrg    SPRITE_EPILOG;
1022706f2543Smrg    return val;
1023706f2543Smrg}
1024706f2543Smrg
1025706f2543Smrgstatic void
1026706f2543SmrgVGAarbiterSpriteSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCur, int x, int y)
1027706f2543Smrg{
1028706f2543Smrg    SPRITE_PROLOG;
1029706f2543Smrg    VGAGet(pScreen);
1030706f2543Smrg    PointPriv->spriteFuncs->SetCursor(pDev, pScreen, pCur, x, y);
1031706f2543Smrg    VGAPut();
1032706f2543Smrg    SPRITE_EPILOG;
1033706f2543Smrg}
1034706f2543Smrg
1035706f2543Smrgstatic void
1036706f2543SmrgVGAarbiterSpriteMoveCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
1037706f2543Smrg{
1038706f2543Smrg    SPRITE_PROLOG;
1039706f2543Smrg    VGAGet(pScreen);
1040706f2543Smrg    PointPriv->spriteFuncs->MoveCursor(pDev, pScreen, x, y);
1041706f2543Smrg    VGAPut();
1042706f2543Smrg    SPRITE_EPILOG;
1043706f2543Smrg}
1044706f2543Smrg
1045706f2543Smrgstatic Bool
1046706f2543SmrgVGAarbiterDeviceCursorInitialize(DeviceIntPtr pDev, ScreenPtr pScreen)
1047706f2543Smrg{
1048706f2543Smrg    Bool val;
1049706f2543Smrg    SPRITE_PROLOG;
1050706f2543Smrg    VGAGet(pScreen);
1051706f2543Smrg    val = PointPriv->spriteFuncs->DeviceCursorInitialize(pDev, pScreen);
1052706f2543Smrg    VGAPut();
1053706f2543Smrg    SPRITE_EPILOG;
1054706f2543Smrg    return val;
1055706f2543Smrg}
1056706f2543Smrg
1057706f2543Smrgstatic void
1058706f2543SmrgVGAarbiterDeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen)
1059706f2543Smrg{
1060706f2543Smrg    SPRITE_PROLOG;
1061706f2543Smrg    VGAGet(pScreen);
1062706f2543Smrg    PointPriv->spriteFuncs->DeviceCursorCleanup(pDev, pScreen);
1063706f2543Smrg    VGAPut();
1064706f2543Smrg    SPRITE_EPILOG;
1065706f2543Smrg}
1066706f2543Smrg
1067706f2543Smrgstatic void
1068706f2543SmrgVGAarbiterComposite(CARD8 op, PicturePtr pSrc, PicturePtr pMask,
1069706f2543Smrg         PicturePtr pDst, INT16 xSrc, INT16 ySrc, INT16 xMask,
1070706f2543Smrg         INT16 yMask, INT16 xDst, INT16 yDst, CARD16 width,
1071706f2543Smrg         CARD16 height)
1072706f2543Smrg{
1073706f2543Smrg    ScreenPtr       pScreen = pDst->pDrawable->pScreen;
1074706f2543Smrg    PictureScreenPtr    ps = GetPictureScreen(pScreen);
1075706f2543Smrg
1076706f2543Smrg    PICTURE_PROLOGUE(Composite);
1077706f2543Smrg
1078706f2543Smrg    VGAGet(pScreen);
1079706f2543Smrg    (*ps->Composite) (op, pSrc, pMask, pDst, xSrc, ySrc, xMask, yMask, xDst,
1080706f2543Smrg              yDst, width, height);
1081706f2543Smrg    VGAPut();
1082706f2543Smrg    PICTURE_EPILOGUE(Composite, VGAarbiterComposite);
1083706f2543Smrg}
1084706f2543Smrg
1085706f2543Smrgstatic void
1086706f2543SmrgVGAarbiterGlyphs(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
1087706f2543Smrg      PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc, int nlist,
1088706f2543Smrg      GlyphListPtr list, GlyphPtr *glyphs)
1089706f2543Smrg{
1090706f2543Smrg    ScreenPtr       pScreen = pDst->pDrawable->pScreen;
1091706f2543Smrg    PictureScreenPtr    ps = GetPictureScreen(pScreen);
1092706f2543Smrg
1093706f2543Smrg    PICTURE_PROLOGUE(Glyphs);
1094706f2543Smrg
1095706f2543Smrg    VGAGet(pScreen);
1096706f2543Smrg    (*ps->Glyphs)(op, pSrc, pDst, maskFormat, xSrc, ySrc, nlist, list, glyphs);
1097706f2543Smrg    VGAPut();
1098706f2543Smrg    PICTURE_EPILOGUE (Glyphs, VGAarbiterGlyphs);
1099706f2543Smrg}
1100706f2543Smrg
1101706f2543Smrgstatic void
1102706f2543SmrgVGAarbiterCompositeRects(CARD8 op, PicturePtr pDst, xRenderColor *color, int nRect,
1103706f2543Smrg          xRectangle *rects)
1104706f2543Smrg{
1105706f2543Smrg    ScreenPtr       pScreen = pDst->pDrawable->pScreen;
1106706f2543Smrg    PictureScreenPtr    ps = GetPictureScreen(pScreen);
1107706f2543Smrg
1108706f2543Smrg    PICTURE_PROLOGUE(CompositeRects);
1109706f2543Smrg
1110706f2543Smrg    VGAGet(pScreen);
1111706f2543Smrg    (*ps->CompositeRects)(op, pDst, color, nRect, rects);
1112706f2543Smrg    VGAPut();
1113706f2543Smrg    PICTURE_EPILOGUE (CompositeRects, VGAarbiterCompositeRects);
1114706f2543Smrg}
1115706f2543Smrg#else
1116706f2543Smrg/* dummy functions */
1117706f2543Smrgvoid xf86VGAarbiterInit(void) {}
1118706f2543Smrgvoid xf86VGAarbiterFini(void) {}
1119706f2543Smrg
1120706f2543Smrgvoid xf86VGAarbiterLock(ScrnInfoPtr pScrn) {}
1121706f2543Smrgvoid xf86VGAarbiterUnlock(ScrnInfoPtr pScrn) {}
1122706f2543SmrgBool xf86VGAarbiterAllowDRI(ScreenPtr pScreen) { return TRUE; }
1123706f2543Smrgvoid xf86VGAarbiterScrnInit(ScrnInfoPtr pScrn) {}
1124706f2543Smrgvoid xf86VGAarbiterDeviceDecodes(ScrnInfoPtr pScrn, int rsrc) {}
1125706f2543SmrgBool xf86VGAarbiterWrapFunctions(void) { return FALSE; }
1126706f2543Smrg
1127706f2543Smrg#endif
1128