cg6_accel.c revision a1fff668
17fd8a0c2Smacallan/*
27fd8a0c2Smacallan * Sun GX and Turbo GX acceleration support
37fd8a0c2Smacallan *
47fd8a0c2Smacallan * Copyright (C) 2005 Michael Lorenz
57fd8a0c2Smacallan *
67fd8a0c2Smacallan * Permission is hereby granted, free of charge, to any person obtaining a copy
77fd8a0c2Smacallan * of this software and associated documentation files (the "Software"), to deal
87fd8a0c2Smacallan * in the Software without restriction, including without limitation the rights
97fd8a0c2Smacallan * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
107fd8a0c2Smacallan * copies of the Software, and to permit persons to whom the Software is
117fd8a0c2Smacallan * furnished to do so, subject to the following conditions:
127fd8a0c2Smacallan *
137fd8a0c2Smacallan * The above copyright notice and this permission notice shall be included in
147fd8a0c2Smacallan * all copies or substantial portions of the Software.
157fd8a0c2Smacallan *
167fd8a0c2Smacallan * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
177fd8a0c2Smacallan * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
187fd8a0c2Smacallan * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
197fd8a0c2Smacallan * MICHAEL LORENZ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
207fd8a0c2Smacallan * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
217fd8a0c2Smacallan * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
227fd8a0c2Smacallan */
237fd8a0c2Smacallan/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/suncg6/cg6_accel.c $ */
247fd8a0c2Smacallan
257fd8a0c2Smacallan#include "cg6.h"
267fd8a0c2Smacallan#include "cg6_regs.h"
277fd8a0c2Smacallan#include "dgaproc.h"
287fd8a0c2Smacallan
297fd8a0c2Smacallan
307fd8a0c2Smacallanstatic CARD32 Cg6BlitROP[] = {
317fd8a0c2Smacallan    ROP_BLIT(GX_ROP_CLEAR,  GX_ROP_CLEAR),	/* GXclear */
327fd8a0c2Smacallan    ROP_BLIT(GX_ROP_CLEAR,  GX_ROP_NOOP),	/* GXand */
337fd8a0c2Smacallan    ROP_BLIT(GX_ROP_CLEAR,  GX_ROP_INVERT),	/* GXandReverse */
347fd8a0c2Smacallan    ROP_BLIT(GX_ROP_CLEAR,  GX_ROP_SET),	/* GXcopy */
357fd8a0c2Smacallan    ROP_BLIT(GX_ROP_NOOP,   GX_ROP_CLEAR),	/* GXandInverted */
367fd8a0c2Smacallan    ROP_BLIT(GX_ROP_NOOP,   GX_ROP_NOOP),	/* GXnoop */
377fd8a0c2Smacallan    ROP_BLIT(GX_ROP_NOOP,   GX_ROP_INVERT),	/* GXxor */
387fd8a0c2Smacallan    ROP_BLIT(GX_ROP_NOOP,   GX_ROP_SET),	/* GXor */
397fd8a0c2Smacallan    ROP_BLIT(GX_ROP_INVERT, GX_ROP_CLEAR),	/* GXnor */
407fd8a0c2Smacallan    ROP_BLIT(GX_ROP_INVERT, GX_ROP_NOOP),	/* GXequiv */
417fd8a0c2Smacallan    ROP_BLIT(GX_ROP_INVERT, GX_ROP_INVERT),	/* GXinvert */
427fd8a0c2Smacallan    ROP_BLIT(GX_ROP_INVERT, GX_ROP_SET),	/* GXorReverse */
437fd8a0c2Smacallan    ROP_BLIT(GX_ROP_SET,    GX_ROP_CLEAR),	/* GXcopyInverted */
447fd8a0c2Smacallan    ROP_BLIT(GX_ROP_SET,    GX_ROP_NOOP),	/* GXorInverted */
457fd8a0c2Smacallan    ROP_BLIT(GX_ROP_SET,    GX_ROP_INVERT),	/* GXnand */
467fd8a0c2Smacallan    ROP_BLIT(GX_ROP_SET,    GX_ROP_SET),	/* GXset */
477fd8a0c2Smacallan};
487fd8a0c2Smacallan
497fd8a0c2Smacallanstatic CARD32 Cg6DrawROP[] = {
507fd8a0c2Smacallan    ROP_FILL(GX_ROP_CLEAR,  GX_ROP_CLEAR),	/* GXclear */
517fd8a0c2Smacallan    ROP_FILL(GX_ROP_CLEAR,  GX_ROP_NOOP),	/* GXand */
527fd8a0c2Smacallan    ROP_FILL(GX_ROP_CLEAR,  GX_ROP_INVERT),	/* GXandReverse */
537fd8a0c2Smacallan    ROP_FILL(GX_ROP_CLEAR,  GX_ROP_SET),	/* GXcopy */
547fd8a0c2Smacallan    ROP_FILL(GX_ROP_NOOP,   GX_ROP_CLEAR),	/* GXandInverted */
557fd8a0c2Smacallan    ROP_FILL(GX_ROP_NOOP,   GX_ROP_NOOP),	/* GXnoop */
567fd8a0c2Smacallan    ROP_FILL(GX_ROP_NOOP,   GX_ROP_INVERT),	/* GXxor */
577fd8a0c2Smacallan    ROP_FILL(GX_ROP_NOOP,   GX_ROP_SET),	/* GXor */
587fd8a0c2Smacallan    ROP_FILL(GX_ROP_INVERT, GX_ROP_CLEAR),	/* GXnor */
597fd8a0c2Smacallan    ROP_FILL(GX_ROP_INVERT, GX_ROP_NOOP),	/* GXequiv */
607fd8a0c2Smacallan    ROP_FILL(GX_ROP_INVERT, GX_ROP_INVERT),	/* GXinvert */
617fd8a0c2Smacallan    ROP_FILL(GX_ROP_INVERT, GX_ROP_SET),	/* GXorReverse */
627fd8a0c2Smacallan    ROP_FILL(GX_ROP_SET,    GX_ROP_CLEAR),	/* GXcopyInverted */
637fd8a0c2Smacallan    ROP_FILL(GX_ROP_SET,    GX_ROP_NOOP),	/* GXorInverted */
647fd8a0c2Smacallan    ROP_FILL(GX_ROP_SET,    GX_ROP_INVERT),	/* GXnand */
657fd8a0c2Smacallan    ROP_FILL(GX_ROP_SET,    GX_ROP_SET),	/* GXset */
667fd8a0c2Smacallan};
677fd8a0c2Smacallan
687fd8a0c2Smacallanstatic CARD32 Cg6StippleROP[16]={
697fd8a0c2Smacallan    ROP_STIP(GX_ROP_CLEAR,  GX_ROP_CLEAR),	/* GXclear */
707fd8a0c2Smacallan    ROP_STIP(GX_ROP_CLEAR,  GX_ROP_NOOP),	/* GXand */
717fd8a0c2Smacallan    ROP_STIP(GX_ROP_CLEAR,  GX_ROP_INVERT),	/* GXandReverse */
727fd8a0c2Smacallan    ROP_STIP(GX_ROP_CLEAR,  GX_ROP_SET),	/* GXcopy */
737fd8a0c2Smacallan    ROP_STIP(GX_ROP_NOOP,   GX_ROP_CLEAR),	/* GXandInverted */
747fd8a0c2Smacallan    ROP_STIP(GX_ROP_NOOP,   GX_ROP_NOOP),	/* GXnoop */
757fd8a0c2Smacallan    ROP_STIP(GX_ROP_NOOP,   GX_ROP_INVERT),	/* GXxor */
767fd8a0c2Smacallan    ROP_STIP(GX_ROP_NOOP,   GX_ROP_SET),	/* GXor */
777fd8a0c2Smacallan    ROP_STIP(GX_ROP_INVERT, GX_ROP_CLEAR),	/* GXnor */
787fd8a0c2Smacallan    ROP_STIP(GX_ROP_INVERT, GX_ROP_NOOP),	/* GXequiv */
797fd8a0c2Smacallan    ROP_STIP(GX_ROP_INVERT, GX_ROP_INVERT),	/* GXinvert */
807fd8a0c2Smacallan    ROP_STIP(GX_ROP_INVERT, GX_ROP_SET),	/* GXorReverse */
817fd8a0c2Smacallan    ROP_STIP(GX_ROP_SET,    GX_ROP_CLEAR),	/* GXcopyInverted */
827fd8a0c2Smacallan    ROP_STIP(GX_ROP_SET,    GX_ROP_NOOP),	/* GXorInverted */
837fd8a0c2Smacallan    ROP_STIP(GX_ROP_SET,    GX_ROP_INVERT),	/* GXnand */
847fd8a0c2Smacallan    ROP_STIP(GX_ROP_SET,    GX_ROP_SET),	/* GXset */
857fd8a0c2Smacallan};
867fd8a0c2Smacallan
877fd8a0c2Smacallanstatic CARD32 Cg6OpaqueStippleROP[16]={
887fd8a0c2Smacallan    ROP_OSTP(GX_ROP_CLEAR,  GX_ROP_CLEAR),	/* GXclear */
897fd8a0c2Smacallan    ROP_OSTP(GX_ROP_CLEAR,  GX_ROP_NOOP),	/* GXand */
907fd8a0c2Smacallan    ROP_OSTP(GX_ROP_CLEAR,  GX_ROP_INVERT),	/* GXandReverse */
917fd8a0c2Smacallan    ROP_OSTP(GX_ROP_CLEAR,  GX_ROP_SET),	/* GXcopy */
927fd8a0c2Smacallan    ROP_OSTP(GX_ROP_NOOP,   GX_ROP_CLEAR),	/* GXandInverted */
937fd8a0c2Smacallan    ROP_OSTP(GX_ROP_NOOP,   GX_ROP_NOOP),	/* GXnoop */
947fd8a0c2Smacallan    ROP_OSTP(GX_ROP_NOOP,   GX_ROP_INVERT),	/* GXxor */
957fd8a0c2Smacallan    ROP_OSTP(GX_ROP_NOOP,   GX_ROP_SET),	/* GXor */
967fd8a0c2Smacallan    ROP_OSTP(GX_ROP_INVERT, GX_ROP_CLEAR),	/* GXnor */
977fd8a0c2Smacallan    ROP_OSTP(GX_ROP_INVERT, GX_ROP_NOOP),	/* GXequiv */
987fd8a0c2Smacallan    ROP_OSTP(GX_ROP_INVERT, GX_ROP_INVERT),	/* GXinvert */
997fd8a0c2Smacallan    ROP_OSTP(GX_ROP_INVERT, GX_ROP_SET),	/* GXorReverse */
1007fd8a0c2Smacallan    ROP_OSTP(GX_ROP_SET,    GX_ROP_CLEAR),	/* GXcopyInverted */
1017fd8a0c2Smacallan    ROP_OSTP(GX_ROP_SET,    GX_ROP_NOOP),	/* GXorInverted */
1027fd8a0c2Smacallan    ROP_OSTP(GX_ROP_SET,    GX_ROP_INVERT),	/* GXnand */
1037fd8a0c2Smacallan    ROP_OSTP(GX_ROP_SET,    GX_ROP_SET),	/* GXset */
1047fd8a0c2Smacallan};
1057fd8a0c2Smacallan
1067fd8a0c2Smacallan/* DGA stuff */
1077fd8a0c2Smacallan
108a1fff668Smartinstatic Bool Cg6_OpenFramebuffer(ScrnInfoPtr pScrn, char **, unsigned char **mem,
109a1fff668Smartin    int *, int *, int *);
1107fd8a0c2Smacallanstatic Bool Cg6_SetMode(ScrnInfoPtr, DGAModePtr);
1117fd8a0c2Smacallanstatic void Cg6_SetViewport(ScrnInfoPtr, int, int, int);
1127fd8a0c2Smacallanstatic int Cg6_GetViewport(ScrnInfoPtr);
1137fd8a0c2Smacallanstatic void Cg6_FillRect(ScrnInfoPtr, int, int, int, int, unsigned long);
1147fd8a0c2Smacallanstatic void Cg6_BlitRect(ScrnInfoPtr, int, int, int, int, int, int);
1157fd8a0c2Smacallan
1167fd8a0c2Smacallanstatic void Cg6Sync(ScrnInfoPtr);
1177fd8a0c2Smacallan
1187fd8a0c2Smacallanstatic DGAFunctionRec Cg6_DGAFuncs = {
1197fd8a0c2Smacallan	Cg6_OpenFramebuffer,
1207fd8a0c2Smacallan	NULL,
1217fd8a0c2Smacallan	Cg6_SetMode,
1227fd8a0c2Smacallan	Cg6_SetViewport,
1237fd8a0c2Smacallan	Cg6_GetViewport,
1247fd8a0c2Smacallan	Cg6Sync,
1257fd8a0c2Smacallan	Cg6_FillRect,
1267fd8a0c2Smacallan	Cg6_BlitRect,
1277fd8a0c2Smacallan	NULL
1287fd8a0c2Smacallan};
1297fd8a0c2Smacallan
1307fd8a0c2Smacallan
1317fd8a0c2Smacallan/*
1327fd8a0c2Smacallan * wait until the engine is idle
1337fd8a0c2Smacallan * unclip since clipping also influences framebuffer accesses
1347fd8a0c2Smacallan */
1357fd8a0c2Smacallanstatic void
1367fd8a0c2SmacallanCg6Sync(ScrnInfoPtr pScrn)
1377fd8a0c2Smacallan{
1387fd8a0c2Smacallan    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
1397fd8a0c2Smacallan
1407fd8a0c2Smacallan    while (pCg6->fbc->s & GX_INPROGRESS);
1417fd8a0c2Smacallan    pCg6->fbc->clipminx = 0;
1427fd8a0c2Smacallan    pCg6->fbc->clipmaxx = pCg6->width;
1437fd8a0c2Smacallan    pCg6->fbc->clipminy = 0;
1447fd8a0c2Smacallan    pCg6->fbc->clipmaxy = pCg6->maxheight;
1457fd8a0c2Smacallan}
1467fd8a0c2Smacallan
1477fd8a0c2Smacallan#define runDraw(pCg6) { volatile CARD32 rubbish = pCg6->fbc->draw; }
1487fd8a0c2Smacallan#define runBlit(pCg6) { volatile CARD32 rubbish = pCg6->fbc->blit; }
1497fd8a0c2Smacallan#define waitReady(pCg6) while(pCg6->fbc->s & GX_FULL)
1507fd8a0c2Smacallan
1517fd8a0c2Smacallan/*
1527fd8a0c2Smacallan * restore clipping values set by the Xserver since we're messing with them in
1537fd8a0c2Smacallan * CPU-to-screen colour expansion
1547fd8a0c2Smacallan */
1557fd8a0c2Smacallan
1567fd8a0c2Smacallanstatic void
1577fd8a0c2SmacallanunClip(Cg6Ptr pCg6)
1587fd8a0c2Smacallan{
1597fd8a0c2Smacallan    pCg6->fbc->clipminx = pCg6->clipxa;
1607fd8a0c2Smacallan    pCg6->fbc->clipmaxx = pCg6->clipxe;
1617fd8a0c2Smacallan}
1627fd8a0c2Smacallan
1637fd8a0c2Smacallanstatic void
1647fd8a0c2SmacallanCg6InitEngine(Cg6Ptr pCg6)
1657fd8a0c2Smacallan{
1667fd8a0c2Smacallan    pCg6->clipxa = 0;
1677fd8a0c2Smacallan    pCg6->clipxe = pCg6->width;
1687fd8a0c2Smacallan    pCg6->fbc->clipminx = 0;
1697fd8a0c2Smacallan    pCg6->fbc->clipmaxx = pCg6->width;
1707fd8a0c2Smacallan    pCg6->fbc->clipminy = 0;
1717fd8a0c2Smacallan    pCg6->fbc->clipmaxy = pCg6->maxheight;
1727fd8a0c2Smacallan
1737fd8a0c2Smacallan    pCg6->fbc->mode = GX_BLIT_SRC |
1747fd8a0c2Smacallan		GX_MODE_COLOR8 |
1757fd8a0c2Smacallan		GX_DRAW_RENDER |
1767fd8a0c2Smacallan		GX_BWRITE0_ENABLE |
1777fd8a0c2Smacallan		GX_BWRITE1_DISABLE |
1787fd8a0c2Smacallan		GX_BREAD_0 |
1797fd8a0c2Smacallan		GX_BDISP_0;
1807fd8a0c2Smacallan
1817fd8a0c2Smacallan    pCg6->fbc->fg = 0xff;
1827fd8a0c2Smacallan    pCg6->fbc->bg = 0x00;
1837fd8a0c2Smacallan
1847fd8a0c2Smacallan    /* we ignore the pixel mask anyway but for completeness... */
1857fd8a0c2Smacallan    pCg6->fbc->pixelm = ~0;
1867fd8a0c2Smacallan
1877fd8a0c2Smacallan    pCg6->fbc->s = 0;
1887fd8a0c2Smacallan    pCg6->fbc->clip = 0;
1897fd8a0c2Smacallan    pCg6->fbc->offx = 0;
1907fd8a0c2Smacallan    pCg6->fbc->offy = 0;
1917fd8a0c2Smacallan    pCg6->fbc->incx = 0;
1927fd8a0c2Smacallan    pCg6->fbc->incy = 0;
1937fd8a0c2Smacallan}
1947fd8a0c2Smacallan
1957fd8a0c2Smacallanstatic void
1967fd8a0c2SmacallanCg6SetupForScreenToScreenCopy(
1977fd8a0c2Smacallan    ScrnInfoPtr  pScrn,
1987fd8a0c2Smacallan    int          xdir,
1997fd8a0c2Smacallan    int          ydir,
2007fd8a0c2Smacallan    int          rop,
2017fd8a0c2Smacallan    unsigned int planemask,
2027fd8a0c2Smacallan    int          TransparencyColour
2037fd8a0c2Smacallan)
2047fd8a0c2Smacallan{
2057fd8a0c2Smacallan    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
2067fd8a0c2Smacallan
2077fd8a0c2Smacallan    waitReady(pCg6);
2087fd8a0c2Smacallan    unClip(pCg6);
2097fd8a0c2Smacallan
2107fd8a0c2Smacallan    pCg6->fbc->mode = GX_BLIT_SRC |
2117fd8a0c2Smacallan		GX_MODE_COLOR8 |
2127fd8a0c2Smacallan		GX_DRAW_RENDER |
2137fd8a0c2Smacallan		GX_BWRITE0_ENABLE |
2147fd8a0c2Smacallan		GX_BWRITE1_DISABLE |
2157fd8a0c2Smacallan		GX_BREAD_0 |
2167fd8a0c2Smacallan		GX_BDISP_0;
2177fd8a0c2Smacallan
2187fd8a0c2Smacallan    /* we probably don't need the following three */
2197fd8a0c2Smacallan    pCg6->fbc->fg = 0xff;
2207fd8a0c2Smacallan    pCg6->fbc->bg = 0x00;
2217fd8a0c2Smacallan    pCg6->fbc->s = 0;
2227fd8a0c2Smacallan
2237fd8a0c2Smacallan    pCg6->fbc->alu = Cg6BlitROP[rop];
2247fd8a0c2Smacallan    pCg6->fbc->pm = planemask;
2257fd8a0c2Smacallan}
2267fd8a0c2Smacallan
2277fd8a0c2Smacallanstatic void
2287fd8a0c2SmacallanCg6SubsequentScreenToScreenCopy
2297fd8a0c2Smacallan(
2307fd8a0c2Smacallan    ScrnInfoPtr pScrn,
2317fd8a0c2Smacallan    int         xSrc,
2327fd8a0c2Smacallan    int         ySrc,
2337fd8a0c2Smacallan    int         xDst,
2347fd8a0c2Smacallan    int         yDst,
2357fd8a0c2Smacallan    int         w,
2367fd8a0c2Smacallan    int         h
2377fd8a0c2Smacallan)
2387fd8a0c2Smacallan{
2397fd8a0c2Smacallan    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
2407fd8a0c2Smacallan
2417fd8a0c2Smacallan    waitReady(pCg6);
2427fd8a0c2Smacallan    pCg6->fbc->x0 = xSrc;
2437fd8a0c2Smacallan    pCg6->fbc->y0 = ySrc;
2447fd8a0c2Smacallan    pCg6->fbc->x1 = xSrc + w - 1;
2457fd8a0c2Smacallan    pCg6->fbc->y1 = ySrc + h - 1;
2467fd8a0c2Smacallan    pCg6->fbc->x2 = xDst;
2477fd8a0c2Smacallan    pCg6->fbc->y2 = yDst;
2487fd8a0c2Smacallan    pCg6->fbc->x3 = xDst + w - 1;
2497fd8a0c2Smacallan    pCg6->fbc->y3 = yDst + h - 1;
2507fd8a0c2Smacallan    runBlit(pCg6);
2517fd8a0c2Smacallan}
2527fd8a0c2Smacallan
2537fd8a0c2Smacallanstatic void
2547fd8a0c2SmacallanCg6SetupForSolidFill
2557fd8a0c2Smacallan(
2567fd8a0c2Smacallan    ScrnInfoPtr  pScrn,
2577fd8a0c2Smacallan    int          colour,
2587fd8a0c2Smacallan    int          rop,
2597fd8a0c2Smacallan    unsigned int planemask
2607fd8a0c2Smacallan)
2617fd8a0c2Smacallan{
2627fd8a0c2Smacallan    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
2637fd8a0c2Smacallan    CARD32 c2;
2647fd8a0c2Smacallan
2657fd8a0c2Smacallan    waitReady(pCg6);
2667fd8a0c2Smacallan    unClip(pCg6);
2677fd8a0c2Smacallan
2687fd8a0c2Smacallan    pCg6->fbc->mode = GX_BLIT_SRC |
2697fd8a0c2Smacallan		GX_MODE_COLOR8 |
2707fd8a0c2Smacallan		GX_DRAW_RENDER |
2717fd8a0c2Smacallan		GX_BWRITE0_ENABLE |
2727fd8a0c2Smacallan		GX_BWRITE1_DISABLE |
2737fd8a0c2Smacallan		GX_BREAD_0 |
2747fd8a0c2Smacallan		GX_BDISP_0;
2757fd8a0c2Smacallan    pCg6->fbc->fg = colour;
2767fd8a0c2Smacallan    pCg6->fbc->s = 0;
2777fd8a0c2Smacallan    pCg6->fbc->alu = Cg6DrawROP[rop];
2787fd8a0c2Smacallan    pCg6->fbc->pm = planemask;
2797fd8a0c2Smacallan}
2807fd8a0c2Smacallan
2817fd8a0c2Smacallanstatic void
2827fd8a0c2SmacallanCg6SubsequentSolidFillRect
2837fd8a0c2Smacallan(
2847fd8a0c2Smacallan    ScrnInfoPtr pScrn,
2857fd8a0c2Smacallan    int         x,
2867fd8a0c2Smacallan    int         y,
2877fd8a0c2Smacallan    int         w,
2887fd8a0c2Smacallan    int         h
2897fd8a0c2Smacallan)
2907fd8a0c2Smacallan{
2917fd8a0c2Smacallan    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
2927fd8a0c2Smacallan
2937fd8a0c2Smacallan    waitReady(pCg6);
2947fd8a0c2Smacallan    pCg6->fbc->arecty = y;
2957fd8a0c2Smacallan    pCg6->fbc->arectx = x;
2967fd8a0c2Smacallan    /* use the relative coordinate registers - saves two additions */
2977fd8a0c2Smacallan    pCg6->fbc->rrecty = h - 1;
2987fd8a0c2Smacallan    pCg6->fbc->rrectx = w - 1;
2997fd8a0c2Smacallan    runDraw(pCg6);
3007fd8a0c2Smacallan}
3017fd8a0c2Smacallan
3027fd8a0c2Smacallanstatic void
3037fd8a0c2SmacallanCg6SetupForCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
3047fd8a0c2Smacallan        		int fg, int bg,
3057fd8a0c2Smacallan			int rop,
3067fd8a0c2Smacallan			unsigned int planemask)
3077fd8a0c2Smacallan{
3087fd8a0c2Smacallan    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
3097fd8a0c2Smacallan
3107fd8a0c2Smacallan    waitReady(pCg6);
3117fd8a0c2Smacallan    pCg6->fbc->mode = GX_BLIT_NOSRC | GX_MODE_COLOR1;
3127fd8a0c2Smacallan
3137fd8a0c2Smacallan    if(bg == -1) {
3147fd8a0c2Smacallan	/* transparent */
3157fd8a0c2Smacallan	pCg6->fbc->alu = Cg6StippleROP[rop] | GX_PATTERN_ONES;
3167fd8a0c2Smacallan	pCg6->fbc->bg = 0xff;
3177fd8a0c2Smacallan    } else {
3187fd8a0c2Smacallan	/* draw background */
3197fd8a0c2Smacallan	pCg6->fbc->alu = Cg6OpaqueStippleROP[rop] | GX_PATTERN_ONES;
3207fd8a0c2Smacallan	pCg6->fbc->bg = bg;
3217fd8a0c2Smacallan    }
3227fd8a0c2Smacallan    pCg6->fbc->fg = fg;
3237fd8a0c2Smacallan    pCg6->fbc->incx = 32;
3247fd8a0c2Smacallan    pCg6->fbc->incy = 0;
3257fd8a0c2Smacallan    pCg6->fbc->s = 0;
3267fd8a0c2Smacallan    pCg6->fbc->pm = planemask;
3277fd8a0c2Smacallan}
3287fd8a0c2Smacallan
3297fd8a0c2Smacallanstatic void
3307fd8a0c2SmacallanCg6SubsequentScanlineCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
3317fd8a0c2Smacallan			int x, int y, int w, int h,
3327fd8a0c2Smacallan			int skipleft )
3337fd8a0c2Smacallan{
3347fd8a0c2Smacallan    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
3357fd8a0c2Smacallan
3367fd8a0c2Smacallan    pCg6->scan_x = x;
3377fd8a0c2Smacallan    pCg6->scan_xe = x + w - 1;
3387fd8a0c2Smacallan    pCg6->scan_y = y;
3397fd8a0c2Smacallan
3407fd8a0c2Smacallan    /*
3417fd8a0c2Smacallan     * we need to clip the left and right margins of what we're going to draw or
3427fd8a0c2Smacallan     * we'll end up with garbage left or right
3437fd8a0c2Smacallan     */
3447fd8a0c2Smacallan    pCg6->fbc->clipminx = x + skipleft;
3457fd8a0c2Smacallan    pCg6->fbc->clipmaxx = x + w - 1;
3467fd8a0c2Smacallan    pCg6->words_in_scanline = ((w + 31) >> 5);
3477fd8a0c2Smacallan}
3487fd8a0c2Smacallan
3497fd8a0c2Smacallanstatic void
3507fd8a0c2SmacallanCg6SubsequentColorExpandScanline(ScrnInfoPtr pScrn, int bufno)
3517fd8a0c2Smacallan{
3527fd8a0c2Smacallan    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
3537fd8a0c2Smacallan    int i;
3547fd8a0c2Smacallan
3557fd8a0c2Smacallan    /*
3567fd8a0c2Smacallan     * the GX is WEIRD. if we tell it to draw n pixels it will fill the entire
3577fd8a0c2Smacallan     * line with whatever we feed into the font register. When we write the next
3587fd8a0c2Smacallan     * word it draws the entire line AGAIN. So we turn on clipping and pretend
3597fd8a0c2Smacallan     * to write only 32 pixels...
3607fd8a0c2Smacallan     */
3617fd8a0c2Smacallan    pCg6->fbc->x0 = pCg6->scan_x;
3627fd8a0c2Smacallan    pCg6->fbc->x1 = pCg6->scan_x + 31;
3637fd8a0c2Smacallan    pCg6->fbc->y0 = pCg6->scan_y;
3647fd8a0c2Smacallan    for (i = 0; i < pCg6->words_in_scanline; i++) {
3657fd8a0c2Smacallan	pCg6->fbc->font = pCg6->scanline[i];
3667fd8a0c2Smacallan    }
3677fd8a0c2Smacallan    pCg6->scan_y++;
3687fd8a0c2Smacallan}
3697fd8a0c2Smacallan
3707fd8a0c2Smacallanstatic void
3717fd8a0c2SmacallanCg6SetupForSolidLine(ScrnInfoPtr pScrn, int color, int rop,
3727fd8a0c2Smacallan    unsigned int planemask)
3737fd8a0c2Smacallan{
3747fd8a0c2Smacallan    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
3757fd8a0c2Smacallan
3767fd8a0c2Smacallan    waitReady(pCg6);
3777fd8a0c2Smacallan    unClip(pCg6);
3787fd8a0c2Smacallan
3797fd8a0c2Smacallan    pCg6->fbc->fg = color;
3807fd8a0c2Smacallan    pCg6->fbc->mode = GX_BLIT_NOSRC;
3817fd8a0c2Smacallan    pCg6->fbc->s = 0;
3827fd8a0c2Smacallan    pCg6->fbc->alu = Cg6DrawROP[rop];
3837fd8a0c2Smacallan    pCg6->fbc->pm = planemask;
3847fd8a0c2Smacallan}
3857fd8a0c2Smacallan
3867fd8a0c2Smacallanstatic void
3877fd8a0c2SmacallanCg6SubsequentSolidTwoPointLine(ScrnInfoPtr pScrn, int x1, int y1, int x2,
3887fd8a0c2Smacallan    int y2, int flags)
3897fd8a0c2Smacallan{
3907fd8a0c2Smacallan    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
3917fd8a0c2Smacallan
3927fd8a0c2Smacallan    /*
3937fd8a0c2Smacallan     * XXX we're blatantly ignoring the flags parameter which could tell us not
3947fd8a0c2Smacallan     * to draw the last point. Xsun simply reads it from the framebuffer and
3957fd8a0c2Smacallan     * puts it back after drawing the line but that would mean we have to wait
3967fd8a0c2Smacallan     * until the line is actually drawn. On the other hand - line drawing is
3977fd8a0c2Smacallan     * pretty fast so we won't lose too much speed
3987fd8a0c2Smacallan     */
3997fd8a0c2Smacallan    waitReady(pCg6);
4007fd8a0c2Smacallan    pCg6->fbc->aliney = y1;
4017fd8a0c2Smacallan    pCg6->fbc->alinex = x1;
4027fd8a0c2Smacallan    pCg6->fbc->aliney = y2;
4037fd8a0c2Smacallan    pCg6->fbc->alinex = x2;
4047fd8a0c2Smacallan    runDraw(pCg6);
4057fd8a0c2Smacallan}
4067fd8a0c2Smacallan
4077fd8a0c2Smacallanstatic void
4087fd8a0c2SmacallanCg6SetClippingRectangle(ScrnInfoPtr pScrn, int left, int top, int right,
4097fd8a0c2Smacallan			 int bottom)
4107fd8a0c2Smacallan{
4117fd8a0c2Smacallan    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
4127fd8a0c2Smacallan
4137fd8a0c2Smacallan    pCg6->fbc->clipminx = pCg6->clipxa = left;
4147fd8a0c2Smacallan    pCg6->fbc->clipminy = top;
4157fd8a0c2Smacallan    pCg6->fbc->clipmaxx = pCg6->clipxe = right;
4167fd8a0c2Smacallan    pCg6->fbc->clipmaxy = bottom;
4177fd8a0c2Smacallan}
4187fd8a0c2Smacallan
4197fd8a0c2Smacallanstatic void
4207fd8a0c2SmacallanCg6DisableClipping(ScrnInfoPtr pScrn)
4217fd8a0c2Smacallan{
4227fd8a0c2Smacallan    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
4237fd8a0c2Smacallan
4247fd8a0c2Smacallan    pCg6->fbc->clipminx = pCg6->clipxa = 0;
4257fd8a0c2Smacallan    pCg6->fbc->clipminy = 0;
4267fd8a0c2Smacallan    pCg6->fbc->clipmaxx = pCg6->clipxe = pCg6->width;
4277fd8a0c2Smacallan    pCg6->fbc->clipmaxy = pCg6->maxheight;
4287fd8a0c2Smacallan}
4297fd8a0c2Smacallan
4307fd8a0c2Smacallanint
4317fd8a0c2SmacallanCG6AccelInit(ScrnInfoPtr pScrn)
4327fd8a0c2Smacallan{
4337fd8a0c2Smacallan    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
4347fd8a0c2Smacallan    XAAInfoRecPtr pXAAInfo = pCg6->pXAA;
4357fd8a0c2Smacallan
4367fd8a0c2Smacallan    pXAAInfo->Flags = LINEAR_FRAMEBUFFER | PIXMAP_CACHE | OFFSCREEN_PIXMAPS;
4377fd8a0c2Smacallan    pXAAInfo->maxOffPixWidth = pCg6->width;
4387fd8a0c2Smacallan    pXAAInfo->maxOffPixHeight = pCg6->maxheight;
4397fd8a0c2Smacallan
4407fd8a0c2Smacallan    Cg6InitEngine(pCg6);
4417fd8a0c2Smacallan
4427fd8a0c2Smacallan    /* wait until the engine is idle and remove clipping */
4437fd8a0c2Smacallan    pXAAInfo->Sync = Cg6Sync;
4447fd8a0c2Smacallan
4457fd8a0c2Smacallan    /* clipping */
4467fd8a0c2Smacallan    pXAAInfo->SetClippingRectangle = Cg6SetClippingRectangle;
4477fd8a0c2Smacallan    pXAAInfo->DisableClipping = Cg6DisableClipping;
4487fd8a0c2Smacallan    pXAAInfo->ClippingFlags = HARDWARE_CLIP_SCREEN_TO_SCREEN_COPY |
4497fd8a0c2Smacallan        HARDWARE_CLIP_SOLID_FILL |
4507fd8a0c2Smacallan        /*HARDWARE_CLIP_MONO_8x8_FILL |
4517fd8a0c2Smacallan        HARDWARE_CLIP_COLOR_8x8_FILL |*/
4527fd8a0c2Smacallan        HARDWARE_CLIP_SOLID_LINE;
4537fd8a0c2Smacallan
4547fd8a0c2Smacallan    /* Screen-to-screen copy */
4557fd8a0c2Smacallan    pXAAInfo->ScreenToScreenCopyFlags = NO_TRANSPARENCY;
4567fd8a0c2Smacallan    pXAAInfo->SetupForScreenToScreenCopy = Cg6SetupForScreenToScreenCopy;
4577fd8a0c2Smacallan    pXAAInfo->SubsequentScreenToScreenCopy =
4587fd8a0c2Smacallan        Cg6SubsequentScreenToScreenCopy;
4597fd8a0c2Smacallan
4607fd8a0c2Smacallan    /* Solid fills */
4617fd8a0c2Smacallan    pXAAInfo->SetupForSolidFill = Cg6SetupForSolidFill;
4627fd8a0c2Smacallan    pXAAInfo->SubsequentSolidFillRect = Cg6SubsequentSolidFillRect;
4637fd8a0c2Smacallan
4647fd8a0c2Smacallan    /* TODO: add pattern fills */
4657fd8a0c2Smacallan
4667fd8a0c2Smacallan    /* colour expansion */
4677fd8a0c2Smacallan    pXAAInfo->ScanlineCPUToScreenColorExpandFillFlags =
4687fd8a0c2Smacallan	LEFT_EDGE_CLIPPING|SCANLINE_PAD_DWORD;
4697fd8a0c2Smacallan    pXAAInfo->NumScanlineColorExpandBuffers = 1;
4707fd8a0c2Smacallan    pCg6->buffers[0] = (unsigned char *)pCg6->scanline;
4717fd8a0c2Smacallan    pXAAInfo->ScanlineColorExpandBuffers = pCg6->buffers;
4727fd8a0c2Smacallan    pXAAInfo->SetupForScanlineCPUToScreenColorExpandFill =
4737fd8a0c2Smacallan	Cg6SetupForCPUToScreenColorExpandFill;
4747fd8a0c2Smacallan    pXAAInfo->SubsequentScanlineCPUToScreenColorExpandFill =
4757fd8a0c2Smacallan	Cg6SubsequentScanlineCPUToScreenColorExpandFill;
4767fd8a0c2Smacallan    pXAAInfo->SubsequentColorExpandScanline =
4777fd8a0c2Smacallan	Cg6SubsequentColorExpandScanline;
4787fd8a0c2Smacallan
4797fd8a0c2Smacallan    /* line drawing */
4807fd8a0c2Smacallan    pXAAInfo->SetupForSolidLine = Cg6SetupForSolidLine;
4817fd8a0c2Smacallan    pXAAInfo->SubsequentSolidTwoPointLine = Cg6SubsequentSolidTwoPointLine;
4827fd8a0c2Smacallan    pXAAInfo->SolidLineFlags = BIT_ORDER_IN_BYTE_MSBFIRST;
4837fd8a0c2Smacallan    /*
4847fd8a0c2Smacallan     * apparently the hardware can't do dashed lines, only lines with patterns
4857fd8a0c2Smacallan     * which isn't useful
4867fd8a0c2Smacallan     */
4877fd8a0c2Smacallan
4887fd8a0c2Smacallan    /* TODO: add host-to-vram colour blits */
4897fd8a0c2Smacallan
4907fd8a0c2Smacallan    return 0;
4917fd8a0c2Smacallan}
4927fd8a0c2Smacallan
4937fd8a0c2SmacallanBool
4947fd8a0c2SmacallanCg6DGAInit(ScreenPtr pScreen)
4957fd8a0c2Smacallan{
4967fd8a0c2Smacallan    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
4977fd8a0c2Smacallan    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
4987fd8a0c2Smacallan    DGAModePtr mode;
4997fd8a0c2Smacallan    int result;
5007fd8a0c2Smacallan
5017fd8a0c2Smacallan    mode = xnfcalloc(sizeof(DGAModeRec), 1);
5027fd8a0c2Smacallan    if (mode == NULL) {
5037fd8a0c2Smacallan        xf86Msg(X_WARNING, "%s: DGA setup failed, cannot allocate memory\n",
5047fd8a0c2Smacallan            pCg6->psdp->device);
5057fd8a0c2Smacallan        return FALSE;
5067fd8a0c2Smacallan    }
5077fd8a0c2Smacallan
5087fd8a0c2Smacallan    mode->mode = pScrn->modes;
5097fd8a0c2Smacallan    mode->flags = DGA_PIXMAP_AVAILABLE | DGA_CONCURRENT_ACCESS;
5107fd8a0c2Smacallan    if(!pCg6->NoAccel) {
5117fd8a0c2Smacallan        mode->flags |= DGA_FILL_RECT | DGA_BLIT_RECT;
5127fd8a0c2Smacallan    }
5137fd8a0c2Smacallan
5147fd8a0c2Smacallan    mode->imageWidth = mode->pixmapWidth = mode->viewportWidth =
5157fd8a0c2Smacallan	pScrn->virtualX;
5167fd8a0c2Smacallan    mode->imageHeight = mode->pixmapHeight = mode->viewportHeight =
5177fd8a0c2Smacallan	pScrn->virtualY;
5187fd8a0c2Smacallan
5197fd8a0c2Smacallan    mode->bytesPerScanline = mode->imageWidth;
5207fd8a0c2Smacallan
5217fd8a0c2Smacallan    mode->byteOrder = pScrn->imageByteOrder;
5227fd8a0c2Smacallan    mode->depth = 8;
5237fd8a0c2Smacallan    mode->bitsPerPixel = 8;
5247fd8a0c2Smacallan    mode->red_mask = pScrn->mask.red;
5257fd8a0c2Smacallan    mode->green_mask = pScrn->mask.green;
5267fd8a0c2Smacallan    mode->blue_mask = pScrn->mask.blue;
5277fd8a0c2Smacallan
5287fd8a0c2Smacallan    mode->visualClass = PseudoColor;
5297fd8a0c2Smacallan    mode->address = pCg6->fb;
5307fd8a0c2Smacallan
5317fd8a0c2Smacallan    result = DGAInit(pScreen, &Cg6_DGAFuncs, mode, 1);
5327fd8a0c2Smacallan
5337fd8a0c2Smacallan    if (result) {
5347fd8a0c2Smacallan    	xf86Msg(X_INFO, "%s: DGA initialized\n",
5357fd8a0c2Smacallan            pCg6->psdp->device);
5367fd8a0c2Smacallan    } else {
5377fd8a0c2Smacallan     	xf86Msg(X_WARNING, "%s: DGA setup failed\n",
5387fd8a0c2Smacallan            pCg6->psdp->device);
5397fd8a0c2Smacallan    }
5407fd8a0c2Smacallan}
5417fd8a0c2Smacallan
5427fd8a0c2Smacallanstatic Bool
5437fd8a0c2SmacallanCg6_OpenFramebuffer(ScrnInfoPtr pScrn, char **name,
544a1fff668Smartin				unsigned char **mem,
545a1fff668Smartin				int *size, int *offset,
546a1fff668Smartin				int *extra)
5477fd8a0c2Smacallan{
5487fd8a0c2Smacallan    Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn);
5497fd8a0c2Smacallan
5507fd8a0c2Smacallan    *name = pCg6->psdp->device;
5517fd8a0c2Smacallan
552a1fff668Smartin    *mem = (unsigned char*)CG6_RAM_VOFF;
5537fd8a0c2Smacallan    *size = pCg6->vidmem;
5547fd8a0c2Smacallan    *offset = 0;
5557fd8a0c2Smacallan    *extra = 0;
5567fd8a0c2Smacallan
5577fd8a0c2Smacallan    return TRUE;
5587fd8a0c2Smacallan}
5597fd8a0c2Smacallan
5607fd8a0c2Smacallanstatic Bool
5617fd8a0c2SmacallanCg6_SetMode(ScrnInfoPtr pScrn, DGAModePtr pMode)
5627fd8a0c2Smacallan{
5637fd8a0c2Smacallan    /*
5647fd8a0c2Smacallan     * Nothing to do, we currently only support one mode
5657fd8a0c2Smacallan     * and we are always in it.
5667fd8a0c2Smacallan     */
5677fd8a0c2Smacallan    return TRUE;
5687fd8a0c2Smacallan}
5697fd8a0c2Smacallan
5707fd8a0c2Smacallanstatic void
5717fd8a0c2SmacallanCg6_SetViewport(ScrnInfoPtr pScrn, int x, int y, int flags)
5727fd8a0c2Smacallan{
5737fd8a0c2Smacallan     /* We don't support viewports, so... */
5747fd8a0c2Smacallan}
5757fd8a0c2Smacallan
5767fd8a0c2Smacallanstatic int
5777fd8a0c2SmacallanCg6_GetViewport(ScrnInfoPtr pScrn)
5787fd8a0c2Smacallan{
5797fd8a0c2Smacallan    /* No viewports, none pending... */
5807fd8a0c2Smacallan    return 0;
5817fd8a0c2Smacallan}
5827fd8a0c2Smacallan
5837fd8a0c2Smacallanstatic void
5847fd8a0c2SmacallanCg6_FillRect(ScrnInfoPtr pScrn, int x, int y, int w, int h, unsigned long color)
5857fd8a0c2Smacallan{
5867fd8a0c2Smacallan
5877fd8a0c2Smacallan    Cg6SetupForSolidFill(pScrn, color, GXset, 8);
5887fd8a0c2Smacallan    Cg6SubsequentSolidFillRect(pScrn, x, y, w, h);
5897fd8a0c2Smacallan}
5907fd8a0c2Smacallan
5917fd8a0c2Smacallanstatic void
5927fd8a0c2SmacallanCg6_BlitRect(ScrnInfoPtr pScrn, int srcx, int srcy,
5937fd8a0c2Smacallan			 int w, int h, int dstx, int dsty)
5947fd8a0c2Smacallan{
5957fd8a0c2Smacallan
5967fd8a0c2Smacallan    Cg6SetupForScreenToScreenCopy(pScrn, 0, 0, GXcopy, 8, 0);
5977fd8a0c2Smacallan    Cg6SubsequentScreenToScreenCopy(pScrn, srcx, srcy, dstx, dsty, w, h);
5987fd8a0c2Smacallan}
599