cg14_accel.c revision a3a2ba44
1a3a2ba44Smacallan/* $NetBSD: cg14_accel.c,v 1.2 2013/06/25 12:26:57 macallan Exp $ */
24261fa58Smacallan/*
34261fa58Smacallan * Copyright (c) 2013 Michael Lorenz
44261fa58Smacallan * All rights reserved.
54261fa58Smacallan *
64261fa58Smacallan * Redistribution and use in source and binary forms, with or without
74261fa58Smacallan * modification, are permitted provided that the following conditions
84261fa58Smacallan * are met:
94261fa58Smacallan *
104261fa58Smacallan *    - Redistributions of source code must retain the above copyright
114261fa58Smacallan *      notice, this list of conditions and the following disclaimer.
124261fa58Smacallan *    - Redistributions in binary form must reproduce the above
134261fa58Smacallan *      copyright notice, this list of conditions and the following
144261fa58Smacallan *      disclaimer in the documentation and/or other materials provided
154261fa58Smacallan *      with the distribution.
164261fa58Smacallan *
174261fa58Smacallan * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
184261fa58Smacallan * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
194261fa58Smacallan * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
204261fa58Smacallan * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
214261fa58Smacallan * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
224261fa58Smacallan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
234261fa58Smacallan * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
244261fa58Smacallan * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
254261fa58Smacallan * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
264261fa58Smacallan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
274261fa58Smacallan * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
284261fa58Smacallan * POSSIBILITY OF SUCH DAMAGE.
294261fa58Smacallan *
304261fa58Smacallan */
314261fa58Smacallan
324261fa58Smacallan#include <sys/types.h>
334261fa58Smacallan
344261fa58Smacallan/* all driver need this */
354261fa58Smacallan#include "xf86.h"
364261fa58Smacallan#include "xf86_OSproc.h"
374261fa58Smacallan#include "compiler.h"
384261fa58Smacallan
394261fa58Smacallan#include "cg14.h"
404261fa58Smacallan#include <sparc/sxreg.h>
414261fa58Smacallan
424261fa58Smacallan#define SX_SINGLE
434261fa58Smacallan/*#define SX_DEBUG*/
444261fa58Smacallan/*#define SX_ADD_SOFTWARE*/
454261fa58Smacallan
464261fa58Smacallan#ifdef SX_DEBUG
474261fa58Smacallan#define ENTER xf86Msg(X_ERROR, "%s>\n", __func__);
484261fa58Smacallan#define DPRINTF xf86Msg
494261fa58Smacallan#else
504261fa58Smacallan#define ENTER
514261fa58Smacallan#define DPRINTF while (0) xf86Msg
524261fa58Smacallan#endif
534261fa58Smacallan
544261fa58Smacallan#define arraysize(ary)        (sizeof(ary) / sizeof(ary[0]))
554261fa58Smacallan
564261fa58Smacallan/* 0xcc is SX's GXcopy equivalent */
574261fa58Smacallanuint32_t sx_rop[] = { 0x00, 0x88, 0x44, 0xcc, 0x22, 0xaa, 0x66, 0xee,
584261fa58Smacallan		      0x11, 0x99, 0x55, 0xdd, 0x33, 0xbb, 0x77, 0xff};
594261fa58Smacallan
604261fa58Smacallanint src_formats[] = {PICT_a8r8g8b8, PICT_x8r8g8b8,
614261fa58Smacallan		     PICT_a8b8g8r8, PICT_x8b8g8r8, PICT_a8};
624261fa58Smacallanint tex_formats[] = {PICT_a8r8g8b8, PICT_a8b8g8r8, PICT_a8};
634261fa58Smacallan
644261fa58Smacallanstatic inline void
654261fa58SmacallanCG14Wait(Cg14Ptr p)
664261fa58Smacallan{
674261fa58Smacallan	/* we just wait until the instruction queue is empty */
684261fa58Smacallan	while ((read_sx_reg(p, SX_CONTROL_STATUS) & SX_MT) != 0) {};
694261fa58Smacallan}
704261fa58Smacallan
714261fa58Smacallanstatic void
724261fa58SmacallanCG14WaitMarker(ScreenPtr pScreen, int Marker)
734261fa58Smacallan{
744261fa58Smacallan	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
754261fa58Smacallan	Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn);
764261fa58Smacallan
774261fa58Smacallan	CG14Wait(p);
784261fa58Smacallan}
794261fa58Smacallan
804261fa58Smacallanstatic Bool
814261fa58SmacallanCG14PrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap,
824261fa58Smacallan		int xdir, int ydir, int alu, Pixel planemask)
834261fa58Smacallan{
844261fa58Smacallan	ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
854261fa58Smacallan	Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn);
864261fa58Smacallan
874261fa58Smacallan	ENTER;
884261fa58Smacallan	DPRINTF(X_ERROR, "bits per pixel: %d\n",
894261fa58Smacallan	    pSrcPixmap->drawable.bitsPerPixel);
904261fa58Smacallan
914261fa58Smacallan	if (planemask != p->last_mask) {
924261fa58Smacallan		CG14Wait(p);
934261fa58Smacallan		write_sx_reg(p, SX_PLANEMASK, planemask);
944261fa58Smacallan		p->last_mask = planemask;
954261fa58Smacallan	}
964261fa58Smacallan	alu = sx_rop[alu];
974261fa58Smacallan	if (alu != p->last_rop) {
984261fa58Smacallan		CG14Wait(p);
994261fa58Smacallan		write_sx_reg(p, SX_ROP_CONTROL, alu);
1004261fa58Smacallan		p->last_rop = alu;
1014261fa58Smacallan	}
1024261fa58Smacallan	p->srcpitch = exaGetPixmapPitch(pSrcPixmap);
1034261fa58Smacallan	p->srcoff = exaGetPixmapOffset(pSrcPixmap);
1044261fa58Smacallan	p->xdir = xdir;
1054261fa58Smacallan	p->ydir = ydir;
1064261fa58Smacallan	return TRUE;
1074261fa58Smacallan}
1084261fa58Smacallan
1094261fa58Smacallanstatic void
1104261fa58SmacallanCG14Copy(PixmapPtr pDstPixmap,
1114261fa58Smacallan         int srcX, int srcY, int dstX, int dstY, int w, int h)
1124261fa58Smacallan{
1134261fa58Smacallan	ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
1144261fa58Smacallan	Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn);
1154261fa58Smacallan	int dstpitch, dstoff, srcpitch, srcoff;
1164261fa58Smacallan	int srcstart, dststart, xinc, srcinc, dstinc;
1174261fa58Smacallan	int line, count, s, d, num;
1184261fa58Smacallan
1194261fa58Smacallan	ENTER;
1204261fa58Smacallan	dstpitch = exaGetPixmapPitch(pDstPixmap);
1214261fa58Smacallan	dstoff = exaGetPixmapOffset(pDstPixmap);
1224261fa58Smacallan	srcpitch = p->srcpitch;
1234261fa58Smacallan	srcoff = p->srcoff;
1244261fa58Smacallan	/*
1254261fa58Smacallan	 * should clear the WO bit in SX_CONTROL_STATUS, then check if SX
1264261fa58Smacallan	 * actually wrote anything and only sync if it did
1274261fa58Smacallan	 */
1284261fa58Smacallan	srcstart = (srcX << 2) + (srcpitch * srcY) + srcoff;
1294261fa58Smacallan	dststart = (dstX << 2) + (dstpitch * dstY) + dstoff;
1304261fa58Smacallan
1314261fa58Smacallan	/*
1324261fa58Smacallan	 * we always copy up to 32 pixels at a time so direction doesn't
1334261fa58Smacallan	 * matter if w<=32
1344261fa58Smacallan	 */
1354261fa58Smacallan	if (w > 32) {
1364261fa58Smacallan		if (p->xdir < 0) {
1374261fa58Smacallan			srcstart += (w - 32) << 2;
1384261fa58Smacallan			dststart += (w - 32) << 2;
1394261fa58Smacallan			xinc = -128;
1404261fa58Smacallan		} else
1414261fa58Smacallan			xinc = 128;
1424261fa58Smacallan	} else
1434261fa58Smacallan		xinc = 128;
1444261fa58Smacallan	if (p->ydir < 0) {
1454261fa58Smacallan		srcstart += (h - 1) * srcpitch;
1464261fa58Smacallan		dststart += (h - 1) * dstpitch;
1474261fa58Smacallan		srcinc = -srcpitch;
1484261fa58Smacallan		dstinc = -dstpitch;
1494261fa58Smacallan	} else {
1504261fa58Smacallan		srcinc = srcpitch;
1514261fa58Smacallan		dstinc = dstpitch;
1524261fa58Smacallan	}
1534261fa58Smacallan	if (p->last_rop == 0xcc) {
1544261fa58Smacallan		/* plain old copy */
1554261fa58Smacallan		if ( xinc > 0) {
1564261fa58Smacallan			/* going left to right */
1574261fa58Smacallan			for (line = 0; line < h; line++) {
1584261fa58Smacallan				count = 0;
1594261fa58Smacallan				s = srcstart;
1604261fa58Smacallan				d = dststart;
1614261fa58Smacallan				while ( count < w) {
1624261fa58Smacallan					num = min(32, w - count);
1634261fa58Smacallan					write_sx_io(p, s,
1644261fa58Smacallan					    SX_LD(10, num - 1, s & 7));
1654261fa58Smacallan					write_sx_io(p, d,
1664261fa58Smacallan					    SX_STM(10, num - 1, d & 7));
1674261fa58Smacallan					s += xinc;
1684261fa58Smacallan					d += xinc;
1694261fa58Smacallan					count += 32;
1704261fa58Smacallan				}
1714261fa58Smacallan				srcstart += srcinc;
1724261fa58Smacallan				dststart += dstinc;
1734261fa58Smacallan			}
1744261fa58Smacallan		} else {
1754261fa58Smacallan			/* going right to left */
1764261fa58Smacallan			int i, chunks = (w >> 5);
1774261fa58Smacallan			for (line = 0; line < h; line++) {
1784261fa58Smacallan				s = srcstart;
1794261fa58Smacallan				d = dststart;
1804261fa58Smacallan				count = w;
1814261fa58Smacallan				for (i = 0; i < chunks; i++) {
1824261fa58Smacallan					write_sx_io(p, s,
1834261fa58Smacallan					    SX_LD(10, 31, s & 7));
1844261fa58Smacallan					write_sx_io(p, d,
1854261fa58Smacallan					    SX_STM(10, 31, d & 7));
1864261fa58Smacallan					s -= 128;
1874261fa58Smacallan					d -= 128;
1884261fa58Smacallan					count -= 32;
1894261fa58Smacallan				}
1904261fa58Smacallan				/* leftovers, if any */
1914261fa58Smacallan				if (count > 0) {
1924261fa58Smacallan					s += (32 - count) << 2;
1934261fa58Smacallan					d += (32 - count) << 2;
1944261fa58Smacallan					write_sx_io(p, s,
1954261fa58Smacallan					    SX_LD(10, count - 1, s & 7));
1964261fa58Smacallan					write_sx_io(p, d,
1974261fa58Smacallan					    SX_STM(10, count - 1, d & 7));
1984261fa58Smacallan				}
1994261fa58Smacallan				srcstart += srcinc;
2004261fa58Smacallan				dststart += dstinc;
2014261fa58Smacallan			}
2024261fa58Smacallan		}
2034261fa58Smacallan	} else {
2044261fa58Smacallan		/* ROPs needed */
2054261fa58Smacallan		if ( xinc > 0) {
2064261fa58Smacallan			/* going left to right */
2074261fa58Smacallan			for (line = 0; line < h; line++) {
2084261fa58Smacallan				count = 0;
2094261fa58Smacallan				s = srcstart;
2104261fa58Smacallan				d = dststart;
2114261fa58Smacallan				while ( count < w) {
2124261fa58Smacallan					num = min(32, w - count);
2134261fa58Smacallan					write_sx_io(p, s,
2144261fa58Smacallan					    SX_LD(10, num - 1, s & 7));
2154261fa58Smacallan					write_sx_io(p, d,
2164261fa58Smacallan					    SX_LD(42, num - 1, d & 7));
2174261fa58Smacallan					if (num > 16) {
2184261fa58Smacallan						write_sx_reg(p, SX_INSTRUCTIONS,
2194261fa58Smacallan					    	 SX_ROP(10, 42, 74, 15));
2204261fa58Smacallan						write_sx_reg(p, SX_INSTRUCTIONS,
2214261fa58Smacallan					    	 SX_ROP(26, 58, 90, num - 17));
2224261fa58Smacallan					} else {
2234261fa58Smacallan						write_sx_reg(p, SX_INSTRUCTIONS,
2244261fa58Smacallan					    	 SX_ROP(10, 42, 74, num - 1));
2254261fa58Smacallan					}
2264261fa58Smacallan					write_sx_io(p, d,
2274261fa58Smacallan					    SX_STM(74, num - 1, d & 7));
2284261fa58Smacallan					s += xinc;
2294261fa58Smacallan					d += xinc;
2304261fa58Smacallan					count += 32;
2314261fa58Smacallan				}
2324261fa58Smacallan				srcstart += srcinc;
2334261fa58Smacallan				dststart += dstinc;
2344261fa58Smacallan			}
2354261fa58Smacallan		} else {
2364261fa58Smacallan			/* going right to left */
2374261fa58Smacallan			int i, chunks = (w >> 5);
2384261fa58Smacallan			for (line = 0; line < h; line++) {
2394261fa58Smacallan				s = srcstart;
2404261fa58Smacallan				d = dststart;
2414261fa58Smacallan				count = w;
2424261fa58Smacallan				for (i = 0; i < chunks; i++) {
2434261fa58Smacallan					write_sx_io(p, s, SX_LD(10, 31, s & 7));
2444261fa58Smacallan					write_sx_io(p, d, SX_LD(42, 31, d & 7));
2454261fa58Smacallan					write_sx_reg(p, SX_INSTRUCTIONS,
2464261fa58Smacallan				    	    SX_ROP(10, 42, 74, 15));
2474261fa58Smacallan					write_sx_reg(p, SX_INSTRUCTIONS,
2484261fa58Smacallan				    	    SX_ROP(26, 58, 90, 15));
2494261fa58Smacallan					write_sx_io(p, d,
2504261fa58Smacallan					    SX_STM(74, 31, d & 7));
2514261fa58Smacallan					s -= 128;
2524261fa58Smacallan					d -= 128;
2534261fa58Smacallan					count -= 32;
2544261fa58Smacallan				}
2554261fa58Smacallan				/* leftovers, if any */
2564261fa58Smacallan				if (count > 0) {
2574261fa58Smacallan					s += (32 - count) << 2;
2584261fa58Smacallan					d += (32 - count) << 2;
2594261fa58Smacallan					write_sx_io(p, s,
2604261fa58Smacallan					    SX_LD(10, count - 1, s & 7));
2614261fa58Smacallan					write_sx_io(p, d,
2624261fa58Smacallan					    SX_LD(42, count - 1, d & 7));
2634261fa58Smacallan					if (count > 16) {
2644261fa58Smacallan						write_sx_reg(p, SX_INSTRUCTIONS,
2654261fa58Smacallan					    	    SX_ROP(10, 42, 74, 15));
2664261fa58Smacallan						write_sx_reg(p, SX_INSTRUCTIONS,
2674261fa58Smacallan					    	 SX_ROP(26, 58, 90, count - 17));
2684261fa58Smacallan					} else {
2694261fa58Smacallan						write_sx_reg(p, SX_INSTRUCTIONS,
2704261fa58Smacallan					    	 SX_ROP(10, 42, 74, count - 1));
2714261fa58Smacallan					}
2724261fa58Smacallan
2734261fa58Smacallan					write_sx_io(p, d,
2744261fa58Smacallan					    SX_STM(74, count - 1, d & 7));
2754261fa58Smacallan				}
2764261fa58Smacallan				srcstart += srcinc;
2774261fa58Smacallan				dststart += dstinc;
2784261fa58Smacallan			}
2794261fa58Smacallan		}
2804261fa58Smacallan	}
2814261fa58Smacallan	exaMarkSync(pDstPixmap->drawable.pScreen);
2824261fa58Smacallan}
2834261fa58Smacallan
2844261fa58Smacallanstatic void
2854261fa58SmacallanCG14DoneCopy(PixmapPtr pDstPixmap)
2864261fa58Smacallan{
2874261fa58Smacallan}
2884261fa58Smacallan
2894261fa58Smacallanstatic Bool
2904261fa58SmacallanCG14PrepareSolid(PixmapPtr pPixmap, int alu, Pixel planemask, Pixel fg)
2914261fa58Smacallan{
2924261fa58Smacallan	ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
2934261fa58Smacallan	Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn);
2944261fa58Smacallan
2954261fa58Smacallan	ENTER;
2964261fa58Smacallan	DPRINTF(X_ERROR, "bits per pixel: %d\n", pPixmap->drawable.bitsPerPixel);
2974261fa58Smacallan	write_sx_reg(p, SX_QUEUED(8), fg);
2984261fa58Smacallan	write_sx_reg(p, SX_QUEUED(9), fg);
2994261fa58Smacallan	if (planemask != p->last_mask) {
3004261fa58Smacallan		CG14Wait(p);
3014261fa58Smacallan		write_sx_reg(p, SX_PLANEMASK, planemask);
3024261fa58Smacallan		p->last_mask = planemask;
3034261fa58Smacallan	}
3044261fa58Smacallan	alu = sx_rop[alu];
3054261fa58Smacallan	if (alu != p->last_rop) {
3064261fa58Smacallan		CG14Wait(p);
3074261fa58Smacallan		write_sx_reg(p, SX_ROP_CONTROL, alu);
3084261fa58Smacallan		p->last_rop = alu;
3094261fa58Smacallan	}
3104261fa58Smacallan	DPRINTF(X_ERROR, "%s: %x\n", __func__, alu);
3114261fa58Smacallan	return TRUE;
3124261fa58Smacallan}
3134261fa58Smacallan
3144261fa58Smacallanstatic void
3154261fa58SmacallanCG14Solid32(Cg14Ptr p, uint32_t start, uint32_t pitch, int w, int h)
3164261fa58Smacallan{
3174261fa58Smacallan	int line, x, num;
3184261fa58Smacallan	uint32_t ptr;
3194261fa58Smacallan
3204261fa58Smacallan	ENTER;
3214261fa58Smacallan	if (p->last_rop == 0xcc) {
3224261fa58Smacallan		/* simple fill */
3234261fa58Smacallan		for (line = 0; line < h; line++) {
3244261fa58Smacallan			x = 0;
3254261fa58Smacallan			while (x < w) {
3264261fa58Smacallan				ptr = start + (x << 2);
3274261fa58Smacallan				num = min(32, w - x);
3284261fa58Smacallan				write_sx_io(p, ptr,
3294261fa58Smacallan				    SX_STS(8, num - 1, ptr & 7));
3304261fa58Smacallan				x += 32;
3314261fa58Smacallan			}
3324261fa58Smacallan			start += pitch;
3334261fa58Smacallan		}
3344261fa58Smacallan	} else if (p->last_rop == 0xaa) {
3354261fa58Smacallan		/* nothing to do here */
3364261fa58Smacallan		return;
3374261fa58Smacallan	} else {
3384261fa58Smacallan		/* alright, let's do actual ROP stuff */
3394261fa58Smacallan
3404261fa58Smacallan		/* first repeat the fill colour into 16 registers */
3414261fa58Smacallan		write_sx_reg(p, SX_INSTRUCTIONS,
3424261fa58Smacallan		    SX_SELECT_S(8, 8, 10, 15));
3434261fa58Smacallan
3444261fa58Smacallan		for (line = 0; line < h; line++) {
3454261fa58Smacallan			x = 0;
3464261fa58Smacallan			while (x < w) {
3474261fa58Smacallan				ptr = start + (x << 2);
3484261fa58Smacallan				num = min(32, w - x);
3494261fa58Smacallan				/* now suck fb data into registers */
3504261fa58Smacallan				write_sx_io(p, ptr,
3514261fa58Smacallan				    SX_LD(42, num - 1, ptr & 7));
3524261fa58Smacallan				/*
3534261fa58Smacallan				 * ROP them with the fill data we left in 10
3544261fa58Smacallan				 * non-memory ops can only have counts up to 16
3554261fa58Smacallan				 */
3564261fa58Smacallan				if (num <= 16) {
3574261fa58Smacallan					write_sx_reg(p, SX_INSTRUCTIONS,
3584261fa58Smacallan					    SX_ROP(10, 42, 74, num - 1));
3594261fa58Smacallan				} else {
3604261fa58Smacallan					write_sx_reg(p, SX_INSTRUCTIONS,
3614261fa58Smacallan					    SX_ROP(10, 42, 74, 15));
3624261fa58Smacallan					write_sx_reg(p, SX_INSTRUCTIONS,
3634261fa58Smacallan					    SX_ROP(10, 58, 90, num - 17));
3644261fa58Smacallan				}
3654261fa58Smacallan				/* and write the result back into memory */
3664261fa58Smacallan				write_sx_io(p, ptr,
3674261fa58Smacallan				    SX_ST(74, num - 1, ptr & 7));
3684261fa58Smacallan				x += 32;
3694261fa58Smacallan			}
3704261fa58Smacallan			start += pitch;
3714261fa58Smacallan		}
3724261fa58Smacallan	}
3734261fa58Smacallan}
3744261fa58Smacallan
3754261fa58Smacallanstatic void
3764261fa58SmacallanCG14Solid8(Cg14Ptr p, uint32_t start, uint32_t pitch, int w, int h)
3774261fa58Smacallan{
3784261fa58Smacallan	int line, x, num, off;
3794261fa58Smacallan	uint32_t ptr;
3804261fa58Smacallan
3814261fa58Smacallan	ENTER;
3824261fa58Smacallan	off = start & 7;
3834261fa58Smacallan	start &= ~7;
3844261fa58Smacallan
3854261fa58Smacallan	if (p->last_rop == 0xcc) {
3864261fa58Smacallan		/* simple fill */
3874261fa58Smacallan		for (line = 0; line < h; line++) {
3884261fa58Smacallan			x = 0;
3894261fa58Smacallan			while (x < w) {
3904261fa58Smacallan				ptr = start + x;
3914261fa58Smacallan				num = min(32, w - x);
3924261fa58Smacallan				write_sx_io(p, ptr,
3934261fa58Smacallan				    SX_STBS(8, num - 1, off));
3944261fa58Smacallan				x += 32;
3954261fa58Smacallan			}
3964261fa58Smacallan			start += pitch;
3974261fa58Smacallan		}
3984261fa58Smacallan	} else if (p->last_rop == 0xaa) {
3994261fa58Smacallan		/* nothing to do here */
4004261fa58Smacallan		return;
4014261fa58Smacallan	} else {
4024261fa58Smacallan		/* alright, let's do actual ROP stuff */
4034261fa58Smacallan
4044261fa58Smacallan		/* first repeat the fill colour into 16 registers */
4054261fa58Smacallan		write_sx_reg(p, SX_INSTRUCTIONS,
4064261fa58Smacallan		    SX_SELECT_S(8, 8, 10, 15));
4074261fa58Smacallan
4084261fa58Smacallan		for (line = 0; line < h; line++) {
4094261fa58Smacallan			x = 0;
4104261fa58Smacallan			while (x < w) {
4114261fa58Smacallan				ptr = start + x;
4124261fa58Smacallan				num = min(32, w - x);
4134261fa58Smacallan				/* now suck fb data into registers */
4144261fa58Smacallan				write_sx_io(p, ptr,
4154261fa58Smacallan				    SX_LDB(42, num - 1, off));
4164261fa58Smacallan				/*
4174261fa58Smacallan				 * ROP them with the fill data we left in 10
4184261fa58Smacallan				 * non-memory ops can only have counts up to 16
4194261fa58Smacallan				 */
4204261fa58Smacallan				if (num <= 16) {
4214261fa58Smacallan					write_sx_reg(p, SX_INSTRUCTIONS,
4224261fa58Smacallan					    SX_ROP(10, 42, 74, num - 1));
4234261fa58Smacallan				} else {
4244261fa58Smacallan					write_sx_reg(p, SX_INSTRUCTIONS,
4254261fa58Smacallan					    SX_ROP(10, 42, 74, 15));
4264261fa58Smacallan					write_sx_reg(p, SX_INSTRUCTIONS,
4274261fa58Smacallan					    SX_ROP(10, 58, 90, num - 17));
4284261fa58Smacallan				}
4294261fa58Smacallan				/* and write the result back into memory */
4304261fa58Smacallan				write_sx_io(p, ptr,
4314261fa58Smacallan				    SX_STB(74, num - 1, off));
4324261fa58Smacallan				x += 32;
4334261fa58Smacallan			}
4344261fa58Smacallan			start += pitch;
4354261fa58Smacallan		}
4364261fa58Smacallan	}
4374261fa58Smacallan}
4384261fa58Smacallan
4394261fa58Smacallanstatic void
4404261fa58SmacallanCG14Solid(PixmapPtr pPixmap, int x1, int y1, int x2, int y2)
4414261fa58Smacallan{
4424261fa58Smacallan	ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
4434261fa58Smacallan	Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn);
4444261fa58Smacallan	int w = x2 - x1, h = y2 - y1, dstoff, dstpitch;
4454261fa58Smacallan	int start, depth;
4464261fa58Smacallan
4474261fa58Smacallan	ENTER;
4484261fa58Smacallan	dstpitch = exaGetPixmapPitch(pPixmap);
4494261fa58Smacallan	dstoff = exaGetPixmapOffset(pPixmap);
4504261fa58Smacallan
4514261fa58Smacallan	depth = pPixmap->drawable.bitsPerPixel;
4524261fa58Smacallan	switch (depth) {
4534261fa58Smacallan		case 32:
4544261fa58Smacallan			start = dstoff + (y1 * dstpitch) + (x1 << 2);
4554261fa58Smacallan			CG14Solid32(p, start, dstpitch, w, h);
4564261fa58Smacallan			break;
4574261fa58Smacallan		case 8:
4584261fa58Smacallan			start = dstoff + (y1 * dstpitch) + x1;
4594261fa58Smacallan			CG14Solid8(p, start, dstpitch, w, h);
4604261fa58Smacallan			break;
4614261fa58Smacallan	}
4624261fa58Smacallan
4634261fa58Smacallan	DPRINTF(X_ERROR, "Solid %d %d %d %d, %d %d -> %d\n", x1, y1, x2, y2,
4644261fa58Smacallan	    dstpitch, dstoff, start);
4654261fa58Smacallan	DPRINTF(X_ERROR, "%x %x %x\n", p->last_rop,
4664261fa58Smacallan	    read_sx_reg(p, SX_QUEUED(8)), read_sx_reg(p, SX_QUEUED(9)));
4674261fa58Smacallan	exaMarkSync(pPixmap->drawable.pScreen);
4684261fa58Smacallan}
4694261fa58Smacallan
4704261fa58Smacallan/*
4714261fa58Smacallan * Memcpy-based UTS.
4724261fa58Smacallan */
4734261fa58Smacallanstatic Bool
4744261fa58SmacallanCG14UploadToScreen(PixmapPtr pDst, int x, int y, int w, int h,
4754261fa58Smacallan    char *src, int src_pitch)
4764261fa58Smacallan{
4774261fa58Smacallan	ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum];
4784261fa58Smacallan	Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn);
4794261fa58Smacallan	char  *dst        = p->fb + exaGetPixmapOffset(pDst);
4804261fa58Smacallan	int    dst_pitch  = exaGetPixmapPitch(pDst);
4814261fa58Smacallan
4824261fa58Smacallan	int bpp    = pDst->drawable.bitsPerPixel;
4834261fa58Smacallan	int cpp    = (bpp + 7) >> 3;
4844261fa58Smacallan	int wBytes = w * cpp;
4854261fa58Smacallan
4864261fa58Smacallan	ENTER;
4874261fa58Smacallan	dst += (x * cpp) + (y * dst_pitch);
4884261fa58Smacallan
4894261fa58Smacallan	CG14Wait(p);
4904261fa58Smacallan
4914261fa58Smacallan	while (h--) {
4924261fa58Smacallan		memcpy(dst, src, wBytes);
4934261fa58Smacallan		src += src_pitch;
4944261fa58Smacallan		dst += dst_pitch;
4954261fa58Smacallan	}
4964261fa58Smacallan	__asm("stbar;");
4974261fa58Smacallan	return TRUE;
4984261fa58Smacallan}
4994261fa58Smacallan
5004261fa58Smacallan/*
5014261fa58Smacallan * Memcpy-based DFS.
5024261fa58Smacallan */
5034261fa58Smacallanstatic Bool
5044261fa58SmacallanCG14DownloadFromScreen(PixmapPtr pSrc, int x, int y, int w, int h,
5054261fa58Smacallan    char *dst, int dst_pitch)
5064261fa58Smacallan{
5074261fa58Smacallan	ScrnInfoPtr pScrn = xf86Screens[pSrc->drawable.pScreen->myNum];
5084261fa58Smacallan	Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn);
5094261fa58Smacallan	char  *src        = p->fb + exaGetPixmapOffset(pSrc);
5104261fa58Smacallan	int    src_pitch  = exaGetPixmapPitch(pSrc);
5114261fa58Smacallan
5124261fa58Smacallan	ENTER;
5134261fa58Smacallan	int bpp    = pSrc->drawable.bitsPerPixel;
5144261fa58Smacallan	int cpp    = (bpp + 7) >> 3;
5154261fa58Smacallan	int wBytes = w * cpp;
5164261fa58Smacallan
5174261fa58Smacallan	src += (x * cpp) + (y * src_pitch);
5184261fa58Smacallan
5194261fa58Smacallan	CG14Wait(p);
5204261fa58Smacallan
5214261fa58Smacallan	while (h--) {
5224261fa58Smacallan		memcpy(dst, src, wBytes);
5234261fa58Smacallan		src += src_pitch;
5244261fa58Smacallan		dst += dst_pitch;
5254261fa58Smacallan	}
5264261fa58Smacallan
5274261fa58Smacallan	return TRUE;
5284261fa58Smacallan}
5294261fa58Smacallan
5304261fa58SmacallanBool
5314261fa58SmacallanCG14CheckComposite(int op, PicturePtr pSrcPicture,
5324261fa58Smacallan                           PicturePtr pMaskPicture,
5334261fa58Smacallan                           PicturePtr pDstPicture)
5344261fa58Smacallan{
5354261fa58Smacallan	int i, ok = FALSE;
5364261fa58Smacallan
5374261fa58Smacallan	ENTER;
5384261fa58Smacallan
5394261fa58Smacallan	/*
5404261fa58Smacallan	 * SX is in theory capable of accelerating pretty much all Xrender ops,
5414261fa58Smacallan	 * even coordinate transformation and gradients. Support will be added
5424261fa58Smacallan	 * over time and likely have to spill over into its own source file.
5434261fa58Smacallan	 */
5444261fa58Smacallan
545a3a2ba44Smacallan	if ((op != PictOpOver) && (op != PictOpAdd) && (op != PictOpSrc)) {
5464261fa58Smacallan		xf86Msg(X_ERROR, "%s: rejecting %d\n", __func__, op);
5474261fa58Smacallan		return FALSE;
5484261fa58Smacallan	}
5494261fa58Smacallan	i = 0;
5504261fa58Smacallan	while ((i < arraysize(src_formats)) && (!ok)) {
5514261fa58Smacallan		ok =  (pSrcPicture->format == src_formats[i]);
5524261fa58Smacallan		i++;
5534261fa58Smacallan	}
5544261fa58Smacallan
5554261fa58Smacallan	if (!ok) {
5564261fa58Smacallan		xf86Msg(X_ERROR, "%s: unsupported src format %x\n",
5574261fa58Smacallan		    __func__, pSrcPicture->format);
5584261fa58Smacallan		return FALSE;
5594261fa58Smacallan	}
5604261fa58Smacallan
561a3a2ba44Smacallan	DPRINTF(X_ERROR, "src is %x, %d: %d %d\n", pSrcPicture->format, op,
5624261fa58Smacallan	    pSrcPicture->pDrawable->width, pSrcPicture->pDrawable->height);
5634261fa58Smacallan
5644261fa58Smacallan	if (pMaskPicture != NULL) {
5654261fa58Smacallan		DPRINTF(X_ERROR, "mask is %x %d %d\n", pMaskPicture->format,
5664261fa58Smacallan		    pMaskPicture->pDrawable->width,
5674261fa58Smacallan		    pMaskPicture->pDrawable->height);
5684261fa58Smacallan	}
5694261fa58Smacallan	return TRUE;
5704261fa58Smacallan}
5714261fa58Smacallan
5724261fa58SmacallanBool
5734261fa58SmacallanCG14PrepareComposite(int op, PicturePtr pSrcPicture,
5744261fa58Smacallan                             PicturePtr pMaskPicture,
5754261fa58Smacallan                             PicturePtr pDstPicture,
5764261fa58Smacallan                             PixmapPtr  pSrc,
5774261fa58Smacallan                             PixmapPtr  pMask,
5784261fa58Smacallan                             PixmapPtr  pDst)
5794261fa58Smacallan{
5804261fa58Smacallan	ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum];
5814261fa58Smacallan	Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn);
5824261fa58Smacallan
5834261fa58Smacallan	ENTER;
5844261fa58Smacallan
585a3a2ba44Smacallan	if (pSrcPicture->format == PICT_a1) {
586a3a2ba44Smacallan		xf86Msg(X_ERROR, "src mono, dst %x, op %d\n", pDstPicture->format, op);
587a3a2ba44Smacallan		if (pMaskPicture != NULL) {
588a3a2ba44Smacallan			xf86Msg(X_ERROR, "msk %x\n", pMaskPicture->format);
589a3a2ba44Smacallan		}
590a3a2ba44Smacallan	}
5914261fa58Smacallan	if (pSrcPicture->pSourcePict != NULL) {
5924261fa58Smacallan		if (pSrcPicture->pSourcePict->type == SourcePictTypeSolidFill) {
5934261fa58Smacallan			p->fillcolour =
5944261fa58Smacallan			    pSrcPicture->pSourcePict->solidFill.color;
595a3a2ba44Smacallan			xf86Msg(X_ERROR, "%s: solid src %08x\n",
5964261fa58Smacallan			    __func__, p->fillcolour);
5974261fa58Smacallan		}
5984261fa58Smacallan	}
5994261fa58Smacallan	if ((pMaskPicture != NULL) && (pMaskPicture->pSourcePict != NULL)) {
6004261fa58Smacallan		if (pMaskPicture->pSourcePict->type ==
6014261fa58Smacallan		    SourcePictTypeSolidFill) {
6024261fa58Smacallan			p->fillcolour =
6034261fa58Smacallan			   pMaskPicture->pSourcePict->solidFill.color;
604a3a2ba44Smacallan			xf86Msg(X_ERROR, "%s: solid mask %08x\n",
6054261fa58Smacallan			    __func__, p->fillcolour);
6064261fa58Smacallan		}
6074261fa58Smacallan	}
6084261fa58Smacallan	if (pMaskPicture != NULL) {
6094261fa58Smacallan		p->mskoff = exaGetPixmapOffset(pMask);
6104261fa58Smacallan		p->mskpitch = exaGetPixmapPitch(pMask);
6114261fa58Smacallan		p->mskformat = pMaskPicture->format;
612a3a2ba44Smacallan	} else {
613a3a2ba44Smacallan		p->mskoff = 0;
614a3a2ba44Smacallan		p->mskpitch = 0;
615a3a2ba44Smacallan		p->mskformat = 0;
6164261fa58Smacallan	}
617a3a2ba44Smacallan	p->source_is_solid =
618a3a2ba44Smacallan	   ((pSrc->drawable.width == 1) && (pSrc->drawable.height == 1));
6194261fa58Smacallan	p->srcoff = exaGetPixmapOffset(pSrc);
6204261fa58Smacallan	p->srcpitch = exaGetPixmapPitch(pSrc);
6214261fa58Smacallan	p->srcformat = pSrcPicture->format;
6224261fa58Smacallan	p->dstformat = pDstPicture->format;
6234261fa58Smacallan	p->op = op;
624a3a2ba44Smacallan	if (op == PictOpSrc) {
625a3a2ba44Smacallan		CG14PrepareCopy(pSrc, pDst, 1, 1, GXcopy, 0xffffffff);
626a3a2ba44Smacallan	}
6274261fa58Smacallan#ifdef SX_DEBUG
6284261fa58Smacallan	DPRINTF(X_ERROR, "%x %x -> %x\n", p->srcoff, p->mskoff,
6294261fa58Smacallan	    *(uint32_t *)(p->fb + p->srcoff));
6304261fa58Smacallan#endif
6314261fa58Smacallan	return TRUE;
6324261fa58Smacallan}
6334261fa58Smacallan
634a3a2ba44Smacallanvoid CG14Comp_Over32Solid(Cg14Ptr p,
6354261fa58Smacallan                   uint32_t src, uint32_t srcpitch,
6364261fa58Smacallan                   uint32_t dst, uint32_t dstpitch,
6374261fa58Smacallan                   int width, int height)
6384261fa58Smacallan{
6394261fa58Smacallan	uint32_t msk = src, mskx, dstx, m;
6404261fa58Smacallan	int line, x, i;
6414261fa58Smacallan
6424261fa58Smacallan	ENTER;
6434261fa58Smacallan	/* first get the source colour */
6444261fa58Smacallan	write_sx_io(p, p->srcoff, SX_LDUQ0(8, 0, p->srcoff & 7));
6454261fa58Smacallan	write_sx_reg(p, SX_QUEUED(8), 0xff);
6464261fa58Smacallan	for (line = 0; line < height; line++) {
6474261fa58Smacallan		mskx = msk;
6484261fa58Smacallan		dstx = dst;
6494261fa58Smacallan#ifdef SX_SINGLE
6504261fa58Smacallan
6514261fa58Smacallan		for (x = 0; x < width; x++) {
6524261fa58Smacallan			m = *(volatile uint32_t *)(p->fb + mskx);
6534261fa58Smacallan			m = m >> 24;
6544261fa58Smacallan			if (m == 0) {
6554261fa58Smacallan				/* nothing to do - all transparent */
6564261fa58Smacallan			} else if (m == 0xff) {
6574261fa58Smacallan				/* all opaque */
6584261fa58Smacallan				write_sx_io(p, dstx, SX_STUQ0(8, 0, dstx & 7));
6594261fa58Smacallan			} else {
6604261fa58Smacallan				/* fetch alpha value, stick it into scam */
6614261fa58Smacallan				/* mask is in R[12:15] */
6624261fa58Smacallan				/*write_sx_io(p, mskx,
6634261fa58Smacallan				    SX_LDUQ0(12, 0, mskx & 7));*/
6644261fa58Smacallan				write_sx_reg(p, SX_QUEUED(12), m);
6654261fa58Smacallan				/* fetch dst pixel */
6664261fa58Smacallan				write_sx_io(p, dstx, SX_LDUQ0(20, 0, dstx & 7));
6674261fa58Smacallan				write_sx_reg(p, SX_INSTRUCTIONS,
6684261fa58Smacallan				    SX_ORV(12, 0, R_SCAM, 0));
6694261fa58Smacallan				/*
6704261fa58Smacallan				 * src * alpha + R0
6714261fa58Smacallan				 * R[9:11] * SCAM + R0 -> R[17:19]
6724261fa58Smacallan				 */
6734261fa58Smacallan				write_sx_reg(p, SX_INSTRUCTIONS,
6744261fa58Smacallan				    SX_SAXP16X16SR8(9, 0, 17, 2));
6754261fa58Smacallan
6764261fa58Smacallan				/* invert SCAM */
6774261fa58Smacallan				write_sx_reg(p, SX_INSTRUCTIONS,
6784261fa58Smacallan				    SX_XORV(12, 8, R_SCAM, 0));
6794261fa58Smacallan#ifdef SX_DEBUG
6804261fa58Smacallan				write_sx_reg(p, SX_INSTRUCTIONS,
6814261fa58Smacallan				    SX_XORV(12, 8, 13, 0));
6824261fa58Smacallan#endif
6834261fa58Smacallan				/* dst * (1 - alpha) + R[13:15] */
6844261fa58Smacallan				write_sx_reg(p, SX_INSTRUCTIONS,
6854261fa58Smacallan				    SX_SAXP16X16SR8(21, 17, 25, 2));
6864261fa58Smacallan				write_sx_io(p, dstx,
6874261fa58Smacallan				    SX_STUQ0C(24, 0, dstx & 7));
6884261fa58Smacallan			}
6894261fa58Smacallan			dstx += 4;
6904261fa58Smacallan			mskx += 4;
6914261fa58Smacallan		}
6924261fa58Smacallan#else
6934261fa58Smacallan		for (x = 0; x < width; x += 4) {
6944261fa58Smacallan			/* fetch 4 mask values */
6954261fa58Smacallan			write_sx_io(p, mskx, SX_LDUQ0(12, 3, mskx & 7));
6964261fa58Smacallan			/* fetch destination pixels */
6974261fa58Smacallan			write_sx_io(p, dstx, SX_LDUQ0(60, 3, dstx & 7));
6984261fa58Smacallan			/* duplicate them for all channels */
6994261fa58Smacallan			write_sx_reg(p, SX_INSTRUCTIONS, SX_ORS(0, 12, 13, 2));
7004261fa58Smacallan			write_sx_reg(p, SX_INSTRUCTIONS, SX_ORS(0, 16, 17, 2));
7014261fa58Smacallan			write_sx_reg(p, SX_INSTRUCTIONS, SX_ORS(0, 20, 21, 2));
7024261fa58Smacallan			write_sx_reg(p, SX_INSTRUCTIONS, SX_ORS(0, 24, 25, 2));
7034261fa58Smacallan			/* generate inverted alpha */
7044261fa58Smacallan			write_sx_reg(p, SX_INSTRUCTIONS,
7054261fa58Smacallan			    SX_XORS(12, 8, 28, 15));
7064261fa58Smacallan			/* multiply source */
7074261fa58Smacallan			write_sx_reg(p, SX_INSTRUCTIONS,
7084261fa58Smacallan			    SX_MUL16X16SR8(8, 12, 44, 3));
7094261fa58Smacallan			write_sx_reg(p, SX_INSTRUCTIONS,
7104261fa58Smacallan			    SX_MUL16X16SR8(8, 16, 48, 3));
7114261fa58Smacallan			write_sx_reg(p, SX_INSTRUCTIONS,
7124261fa58Smacallan			    SX_MUL16X16SR8(8, 20, 52, 3));
7134261fa58Smacallan			write_sx_reg(p, SX_INSTRUCTIONS,
7144261fa58Smacallan			    SX_MUL16X16SR8(8, 24, 56, 3));
7154261fa58Smacallan			/* multiply dest */
7164261fa58Smacallan			write_sx_reg(p, SX_INSTRUCTIONS,
7174261fa58Smacallan			    SX_MUL16X16SR8(28, 60, 76, 15));
7184261fa58Smacallan			/* add up */
7194261fa58Smacallan			write_sx_reg(p, SX_INSTRUCTIONS,
7204261fa58Smacallan			    SX_ADDV(44, 76, 92, 15));
7214261fa58Smacallan			/* write back */
7224261fa58Smacallan			write_sx_io(p, dstx, SX_STUQ0C(92, 3, dstx & 7));
7234261fa58Smacallan			dstx += 16;
7244261fa58Smacallan			mskx += 16;
7254261fa58Smacallan		}
7264261fa58Smacallan#endif
7274261fa58Smacallan		dst += dstpitch;
7284261fa58Smacallan		msk += srcpitch;
7294261fa58Smacallan	}
7304261fa58Smacallan}
7314261fa58Smacallan
7324261fa58Smacallanvoid
7334261fa58SmacallanCG14Composite(PixmapPtr pDst, int srcX, int srcY,
7344261fa58Smacallan                              int maskX, int maskY,
7354261fa58Smacallan                              int dstX, int dstY,
7364261fa58Smacallan                              int width, int height)
7374261fa58Smacallan{
7384261fa58Smacallan	ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum];
7394261fa58Smacallan	Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn);
7404261fa58Smacallan	uint32_t dstoff, dstpitch;
7414261fa58Smacallan	uint32_t dst, msk, src;
7424261fa58Smacallan
7434261fa58Smacallan	ENTER;
7444261fa58Smacallan	dstoff = exaGetPixmapOffset(pDst);
7454261fa58Smacallan	dstpitch = exaGetPixmapPitch(pDst);
7464261fa58Smacallan
7474261fa58Smacallan	switch (p->op) {
7484261fa58Smacallan		case PictOpOver:
7494261fa58Smacallan			dst = dstoff + (dstY * dstpitch) + (dstX << 2);
7504261fa58Smacallan			DPRINTF(X_ERROR, "Over %08x %08x, %d %d\n",
7514261fa58Smacallan			    p->mskformat, p->dstformat, srcX, srcY);
752a3a2ba44Smacallan			if (p->source_is_solid) {
753a3a2ba44Smacallan				switch (p->mskformat) {
754a3a2ba44Smacallan					case PICT_a8:
755a3a2ba44Smacallan						msk = p->mskoff +
756a3a2ba44Smacallan						    (maskY * p->mskpitch) +
757a3a2ba44Smacallan						    maskX;
758a3a2ba44Smacallan						CG14Comp_Over8Solid(p,
759a3a2ba44Smacallan						    msk, p->mskpitch,
760a3a2ba44Smacallan						    dst, dstpitch,
761a3a2ba44Smacallan						    width, height);
762a3a2ba44Smacallan						break;
763a3a2ba44Smacallan					case PICT_a8r8g8b8:
764a3a2ba44Smacallan					case PICT_a8b8g8r8:
765a3a2ba44Smacallan						msk = p->mskoff +
766a3a2ba44Smacallan						    (maskY * p->mskpitch) +
767a3a2ba44Smacallan						    (maskX << 2);
768a3a2ba44Smacallan						CG14Comp_Over32Solid(p,
769a3a2ba44Smacallan						    msk, p->mskpitch,
770a3a2ba44Smacallan						    dst, dstpitch,
771a3a2ba44Smacallan						    width, height);
772a3a2ba44Smacallan						break;
773a3a2ba44Smacallan					default:
774a3a2ba44Smacallan						xf86Msg(X_ERROR,
775a3a2ba44Smacallan						    "unsupported mask format\n");
776a3a2ba44Smacallan				}
777a3a2ba44Smacallan			} else {
778a3a2ba44Smacallan				DPRINTF(X_ERROR, "non-solid over with msk %x\n", p->mskformat);
779a3a2ba44Smacallan				switch (p->srcformat) {
780a3a2ba44Smacallan					case PICT_a8r8g8b8:
781a3a2ba44Smacallan					case PICT_a8b8g8r8:
782a3a2ba44Smacallan						src = p->srcoff +
783a3a2ba44Smacallan						    (srcY * p->srcpitch) +
784a3a2ba44Smacallan						    (srcX << 2);
785a3a2ba44Smacallan						dst = dstoff +
786a3a2ba44Smacallan						    (dstY * dstpitch) +
787a3a2ba44Smacallan						    (dstX << 2);
788a3a2ba44Smacallan						if (p->mskformat == PICT_a8) {
789a3a2ba44Smacallan							msk = p->mskoff +
790a3a2ba44Smacallan							    (maskY * p->mskpitch) +
791a3a2ba44Smacallan							    maskX;
792a3a2ba44Smacallan							CG14Comp_Over32Mask(p,
793a3a2ba44Smacallan							    src, p->srcpitch,
794a3a2ba44Smacallan							    msk, p->mskpitch,
795a3a2ba44Smacallan							    dst, dstpitch,
796a3a2ba44Smacallan							    width, height);
797a3a2ba44Smacallan						} else {
798a3a2ba44Smacallan							CG14Comp_Over32(p,
799a3a2ba44Smacallan							    src, p->srcpitch,
800a3a2ba44Smacallan							    dst, dstpitch,
801a3a2ba44Smacallan							    width, height);
802a3a2ba44Smacallan						}
803a3a2ba44Smacallan						break;
804a3a2ba44Smacallan					case PICT_x8r8g8b8:
805a3a2ba44Smacallan					case PICT_x8b8g8r8:
806a3a2ba44Smacallan						xf86Msg(X_ERROR, "alpha better be separate\n");
807a3a2ba44Smacallan						break;
808a3a2ba44Smacallan					default:
809a3a2ba44Smacallan						xf86Msg(X_ERROR, "%s: format %x in non-solid Over op\n",
810a3a2ba44Smacallan						    __func__, p->srcformat);
811a3a2ba44Smacallan				}
812a3a2ba44Smacallan			}
8134261fa58Smacallan			break;
8144261fa58Smacallan		case PictOpAdd:
8154261fa58Smacallan			DPRINTF(X_ERROR, "Add %08x %08x\n",
8164261fa58Smacallan			    p->srcformat, p->dstformat);
8174261fa58Smacallan			switch (p->srcformat) {
8184261fa58Smacallan				case PICT_a8:
8194261fa58Smacallan					src = p->srcoff +
8204261fa58Smacallan					    (srcY * p->srcpitch) + srcX;
8214261fa58Smacallan					dst = dstoff + (dstY * dstpitch) + dstX;
8224261fa58Smacallan					CG14Comp_Add8(p, src, p->srcpitch,
8234261fa58Smacallan					    dst, dstpitch, width, height);
8244261fa58Smacallan					break;
8254261fa58Smacallan				case PICT_a8r8g8b8:
8264261fa58Smacallan				case PICT_x8r8g8b8:
8274261fa58Smacallan					src = p->srcoff +
8284261fa58Smacallan					    (srcY * p->srcpitch) + (srcX << 2);
8294261fa58Smacallan					dst = dstoff + (dstY * dstpitch) +
8304261fa58Smacallan					    (dstX << 2);
8314261fa58Smacallan					CG14Comp_Add32(p, src, p->srcpitch,
8324261fa58Smacallan					    dst, dstpitch, width, height);
8334261fa58Smacallan					break;
8344261fa58Smacallan				default:
8354261fa58Smacallan					xf86Msg(X_ERROR,
8364261fa58Smacallan					    "unsupported src format\n");
8374261fa58Smacallan			}
8384261fa58Smacallan			break;
839a3a2ba44Smacallan		case PictOpSrc:
840a3a2ba44Smacallan			DPRINTF(X_ERROR, "Src %08x %08x\n",
841a3a2ba44Smacallan			    p->srcformat, p->dstformat);
842a3a2ba44Smacallan			CG14Copy(pDst, srcX, srcY, dstX, dstY, width, height);
843a3a2ba44Smacallan			break;
8444261fa58Smacallan		default:
8454261fa58Smacallan			xf86Msg(X_ERROR, "unsupported op %d\n", p->op);
8464261fa58Smacallan	}
8474261fa58Smacallan	exaMarkSync(pDst->drawable.pScreen);
8484261fa58Smacallan}
8494261fa58Smacallan
8504261fa58Smacallan
8514261fa58Smacallan
8524261fa58SmacallanBool
8534261fa58SmacallanCG14InitAccel(ScreenPtr pScreen)
8544261fa58Smacallan{
8554261fa58Smacallan	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
8564261fa58Smacallan	Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn);
8574261fa58Smacallan	ExaDriverPtr pExa;
8584261fa58Smacallan
8594261fa58Smacallan	pExa = exaDriverAlloc();
8604261fa58Smacallan	if (!pExa)
8614261fa58Smacallan		return FALSE;
8624261fa58Smacallan
8634261fa58Smacallan	p->pExa = pExa;
8644261fa58Smacallan
8654261fa58Smacallan	pExa->exa_major = EXA_VERSION_MAJOR;
8664261fa58Smacallan	pExa->exa_minor = EXA_VERSION_MINOR;
8674261fa58Smacallan
8684261fa58Smacallan	pExa->memoryBase = p->fb;
8694261fa58Smacallan	pExa->memorySize = p->memsize;
8704261fa58Smacallan	pExa->offScreenBase = p->width * p->height * 4;
8714261fa58Smacallan
8724261fa58Smacallan	/*
8734261fa58Smacallan	 * SX memory instructions are written to 64bit aligned addresses with
8744261fa58Smacallan	 * a 3 bit displacement. Make sure the displacement remains constant
8754261fa58Smacallan	 * within one column
8764261fa58Smacallan	 */
8774261fa58Smacallan
8784261fa58Smacallan	pExa->pixmapOffsetAlign = 8;
8794261fa58Smacallan	pExa->pixmapPitchAlign = 8;
8804261fa58Smacallan
8814261fa58Smacallan	pExa->flags = EXA_OFFSCREEN_PIXMAPS |
8824261fa58Smacallan		      /*EXA_SUPPORTS_OFFSCREEN_OVERLAPS |*/
8834261fa58Smacallan		      EXA_MIXED_PIXMAPS;
8844261fa58Smacallan
8854261fa58Smacallan	/*
8864261fa58Smacallan	 * these limits are bogus
8874261fa58Smacallan	 * SX doesn't deal with coordinates at all, so there is no limit but
8884261fa58Smacallan	 * we have to put something here
8894261fa58Smacallan	 */
8904261fa58Smacallan	pExa->maxX = 4096;
8914261fa58Smacallan	pExa->maxY = 4096;
8924261fa58Smacallan
8934261fa58Smacallan	pExa->WaitMarker = CG14WaitMarker;
8944261fa58Smacallan
8954261fa58Smacallan	pExa->PrepareSolid = CG14PrepareSolid;
8964261fa58Smacallan	pExa->Solid = CG14Solid;
8974261fa58Smacallan	pExa->DoneSolid = CG14DoneCopy;
8984261fa58Smacallan	pExa->PrepareCopy = CG14PrepareCopy;
8994261fa58Smacallan	pExa->Copy = CG14Copy;
9004261fa58Smacallan	pExa->DoneCopy = CG14DoneCopy;
9014261fa58Smacallan	if (p->use_xrender) {
9024261fa58Smacallan		pExa->CheckComposite = CG14CheckComposite;
9034261fa58Smacallan		pExa->PrepareComposite = CG14PrepareComposite;
9044261fa58Smacallan		pExa->Composite = CG14Composite;
9054261fa58Smacallan		pExa->DoneComposite = CG14DoneCopy;
9064261fa58Smacallan	}
9074261fa58Smacallan
9084261fa58Smacallan	/* EXA hits more optimized paths when it does not have to fallback
9094261fa58Smacallan	 * because of missing UTS/DFS, hook memcpy-based UTS/DFS.
9104261fa58Smacallan	 */
9114261fa58Smacallan	pExa->UploadToScreen = CG14UploadToScreen;
9124261fa58Smacallan	pExa->DownloadFromScreen = CG14DownloadFromScreen;
9134261fa58Smacallan
9144261fa58Smacallan	/* do some hardware init */
9154261fa58Smacallan	write_sx_reg(p, SX_PLANEMASK, 0xffffffff);
9164261fa58Smacallan	p->last_mask = 0xffffffff;
9174261fa58Smacallan	write_sx_reg(p, SX_ROP_CONTROL, 0xcc);
9184261fa58Smacallan	p->last_rop = 0xcc;
9194261fa58Smacallan	return exaDriverInit(pScreen, pExa);
9204261fa58Smacallan}
921