cg14_accel.c revision c2193d98
1c2193d98Smacallan/* $NetBSD: cg14_accel.c,v 1.15 2019/07/24 16:07:59 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 */ 31c88c16f8Smacallan 32c88c16f8Smacallan#ifdef HAVE_CONFIG_H 33c88c16f8Smacallan#include "config.h" 34c88c16f8Smacallan#endif 35c88c16f8Smacallan 364261fa58Smacallan#include <sys/types.h> 374261fa58Smacallan 384261fa58Smacallan/* all driver need this */ 394261fa58Smacallan#include "xf86.h" 404261fa58Smacallan#include "xf86_OSproc.h" 414261fa58Smacallan#include "compiler.h" 424261fa58Smacallan 434261fa58Smacallan#include "cg14.h" 444261fa58Smacallan 454261fa58Smacallan/*#define SX_DEBUG*/ 464261fa58Smacallan 474261fa58Smacallan#ifdef SX_DEBUG 484261fa58Smacallan#define ENTER xf86Msg(X_ERROR, "%s>\n", __func__); 494261fa58Smacallan#define DPRINTF xf86Msg 504261fa58Smacallan#else 514261fa58Smacallan#define ENTER 524261fa58Smacallan#define DPRINTF while (0) xf86Msg 534261fa58Smacallan#endif 544261fa58Smacallan 554261fa58Smacallan#define arraysize(ary) (sizeof(ary) / sizeof(ary[0])) 564261fa58Smacallan 574261fa58Smacallan/* 0xcc is SX's GXcopy equivalent */ 584261fa58Smacallanuint32_t sx_rop[] = { 0x00, 0x88, 0x44, 0xcc, 0x22, 0xaa, 0x66, 0xee, 594261fa58Smacallan 0x11, 0x99, 0x55, 0xdd, 0x33, 0xbb, 0x77, 0xff}; 604261fa58Smacallan 614261fa58Smacallanint src_formats[] = {PICT_a8r8g8b8, PICT_x8r8g8b8, 624261fa58Smacallan PICT_a8b8g8r8, PICT_x8b8g8r8, PICT_a8}; 634261fa58Smacallanint tex_formats[] = {PICT_a8r8g8b8, PICT_a8b8g8r8, PICT_a8}; 644261fa58Smacallan 65f71acd79Smacallanstatic void CG14Copy32(PixmapPtr, int, int, int, int, int, int); 66f71acd79Smacallanstatic void CG14Copy8(PixmapPtr, int, int, int, int, int, int); 67f71acd79Smacallan 684261fa58Smacallanstatic inline void 694261fa58SmacallanCG14Wait(Cg14Ptr p) 704261fa58Smacallan{ 71fc473876Smacallan int bail = 10000000; 72fc473876Smacallan /* we wait for the busy bit to clear */ 73fc473876Smacallan while (((read_sx_reg(p, SX_CONTROL_STATUS) & SX_BZ) != 0) && 74fc473876Smacallan (bail > 0)) { 75fc473876Smacallan bail--; 76fc473876Smacallan }; 77fc473876Smacallan if (bail == 0) { 78fc473876Smacallan xf86Msg(X_ERROR, "SX wait for idle timed out %08x %08x\n", 79fc473876Smacallan read_sx_reg(p, SX_CONTROL_STATUS), 80fc473876Smacallan read_sx_reg(p, SX_ERROR)); 81fc473876Smacallan } 824261fa58Smacallan} 834261fa58Smacallan 844261fa58Smacallanstatic void 854261fa58SmacallanCG14WaitMarker(ScreenPtr pScreen, int Marker) 864261fa58Smacallan{ 874261fa58Smacallan ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 884261fa58Smacallan Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn); 894261fa58Smacallan 904261fa58Smacallan CG14Wait(p); 914261fa58Smacallan} 924261fa58Smacallan 934261fa58Smacallanstatic Bool 944261fa58SmacallanCG14PrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, 954261fa58Smacallan int xdir, int ydir, int alu, Pixel planemask) 964261fa58Smacallan{ 974261fa58Smacallan ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum]; 984261fa58Smacallan Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn); 994261fa58Smacallan 1004261fa58Smacallan ENTER; 1014261fa58Smacallan DPRINTF(X_ERROR, "bits per pixel: %d\n", 1024261fa58Smacallan pSrcPixmap->drawable.bitsPerPixel); 1034261fa58Smacallan 1044261fa58Smacallan if (planemask != p->last_mask) { 1054261fa58Smacallan CG14Wait(p); 1064261fa58Smacallan write_sx_reg(p, SX_PLANEMASK, planemask); 1074261fa58Smacallan p->last_mask = planemask; 1084261fa58Smacallan } 1094261fa58Smacallan alu = sx_rop[alu]; 1104261fa58Smacallan if (alu != p->last_rop) { 1114261fa58Smacallan CG14Wait(p); 1124261fa58Smacallan write_sx_reg(p, SX_ROP_CONTROL, alu); 1134261fa58Smacallan p->last_rop = alu; 1144261fa58Smacallan } 115f71acd79Smacallan switch (pSrcPixmap->drawable.bitsPerPixel) { 116f71acd79Smacallan case 8: 117f71acd79Smacallan p->pExa->Copy = CG14Copy8; 118f71acd79Smacallan break; 119f71acd79Smacallan case 32: 120f71acd79Smacallan p->pExa->Copy = CG14Copy32; 121f71acd79Smacallan break; 122f71acd79Smacallan default: 123f71acd79Smacallan xf86Msg(X_ERROR, "%s depth %d\n", __func__, 124f71acd79Smacallan pSrcPixmap->drawable.bitsPerPixel); 125f71acd79Smacallan } 1264261fa58Smacallan p->srcpitch = exaGetPixmapPitch(pSrcPixmap); 1274261fa58Smacallan p->srcoff = exaGetPixmapOffset(pSrcPixmap); 1284261fa58Smacallan p->xdir = xdir; 1294261fa58Smacallan p->ydir = ydir; 1304261fa58Smacallan return TRUE; 1314261fa58Smacallan} 1324261fa58Smacallan 1334261fa58Smacallanstatic void 134f71acd79SmacallanCG14Copy32(PixmapPtr pDstPixmap, 1354261fa58Smacallan int srcX, int srcY, int dstX, int dstY, int w, int h) 1364261fa58Smacallan{ 1374261fa58Smacallan ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum]; 1384261fa58Smacallan Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn); 1394261fa58Smacallan int dstpitch, dstoff, srcpitch, srcoff; 1404261fa58Smacallan int srcstart, dststart, xinc, srcinc, dstinc; 1414261fa58Smacallan int line, count, s, d, num; 1424261fa58Smacallan 1434261fa58Smacallan ENTER; 1444261fa58Smacallan dstpitch = exaGetPixmapPitch(pDstPixmap); 1454261fa58Smacallan dstoff = exaGetPixmapOffset(pDstPixmap); 1464261fa58Smacallan srcpitch = p->srcpitch; 1474261fa58Smacallan srcoff = p->srcoff; 1484261fa58Smacallan /* 1494261fa58Smacallan * should clear the WO bit in SX_CONTROL_STATUS, then check if SX 1504261fa58Smacallan * actually wrote anything and only sync if it did 1514261fa58Smacallan */ 1524261fa58Smacallan srcstart = (srcX << 2) + (srcpitch * srcY) + srcoff; 1534261fa58Smacallan dststart = (dstX << 2) + (dstpitch * dstY) + dstoff; 1544261fa58Smacallan 1554261fa58Smacallan /* 1564261fa58Smacallan * we always copy up to 32 pixels at a time so direction doesn't 1574261fa58Smacallan * matter if w<=32 1584261fa58Smacallan */ 1594261fa58Smacallan if (w > 32) { 1604261fa58Smacallan if (p->xdir < 0) { 1614261fa58Smacallan srcstart += (w - 32) << 2; 1624261fa58Smacallan dststart += (w - 32) << 2; 1634261fa58Smacallan xinc = -128; 1644261fa58Smacallan } else 1654261fa58Smacallan xinc = 128; 1664261fa58Smacallan } else 1674261fa58Smacallan xinc = 128; 1684261fa58Smacallan if (p->ydir < 0) { 1694261fa58Smacallan srcstart += (h - 1) * srcpitch; 1704261fa58Smacallan dststart += (h - 1) * dstpitch; 1714261fa58Smacallan srcinc = -srcpitch; 1724261fa58Smacallan dstinc = -dstpitch; 1734261fa58Smacallan } else { 1744261fa58Smacallan srcinc = srcpitch; 1754261fa58Smacallan dstinc = dstpitch; 1764261fa58Smacallan } 1774261fa58Smacallan if (p->last_rop == 0xcc) { 1784261fa58Smacallan /* plain old copy */ 1794261fa58Smacallan if ( xinc > 0) { 1804261fa58Smacallan /* going left to right */ 1814261fa58Smacallan for (line = 0; line < h; line++) { 1824261fa58Smacallan count = 0; 1834261fa58Smacallan s = srcstart; 1844261fa58Smacallan d = dststart; 1854261fa58Smacallan while ( count < w) { 1864261fa58Smacallan num = min(32, w - count); 1874261fa58Smacallan write_sx_io(p, s, 1884261fa58Smacallan SX_LD(10, num - 1, s & 7)); 1894261fa58Smacallan write_sx_io(p, d, 1904261fa58Smacallan SX_STM(10, num - 1, d & 7)); 1914261fa58Smacallan s += xinc; 1924261fa58Smacallan d += xinc; 1934261fa58Smacallan count += 32; 1944261fa58Smacallan } 1954261fa58Smacallan srcstart += srcinc; 1964261fa58Smacallan dststart += dstinc; 1974261fa58Smacallan } 1984261fa58Smacallan } else { 1994261fa58Smacallan /* going right to left */ 2004261fa58Smacallan int i, chunks = (w >> 5); 2014261fa58Smacallan for (line = 0; line < h; line++) { 2024261fa58Smacallan s = srcstart; 2034261fa58Smacallan d = dststart; 2044261fa58Smacallan count = w; 2054261fa58Smacallan for (i = 0; i < chunks; i++) { 2064261fa58Smacallan write_sx_io(p, s, 2074261fa58Smacallan SX_LD(10, 31, s & 7)); 2084261fa58Smacallan write_sx_io(p, d, 2094261fa58Smacallan SX_STM(10, 31, d & 7)); 2104261fa58Smacallan s -= 128; 2114261fa58Smacallan d -= 128; 2124261fa58Smacallan count -= 32; 2134261fa58Smacallan } 2144261fa58Smacallan /* leftovers, if any */ 2154261fa58Smacallan if (count > 0) { 2164261fa58Smacallan s += (32 - count) << 2; 2174261fa58Smacallan d += (32 - count) << 2; 2184261fa58Smacallan write_sx_io(p, s, 2194261fa58Smacallan SX_LD(10, count - 1, s & 7)); 2204261fa58Smacallan write_sx_io(p, d, 2214261fa58Smacallan SX_STM(10, count - 1, d & 7)); 2224261fa58Smacallan } 2234261fa58Smacallan srcstart += srcinc; 2244261fa58Smacallan dststart += dstinc; 2254261fa58Smacallan } 2264261fa58Smacallan } 2274261fa58Smacallan } else { 2284261fa58Smacallan /* ROPs needed */ 2294261fa58Smacallan if ( xinc > 0) { 2304261fa58Smacallan /* going left to right */ 2314261fa58Smacallan for (line = 0; line < h; line++) { 2324261fa58Smacallan count = 0; 2334261fa58Smacallan s = srcstart; 2344261fa58Smacallan d = dststart; 2354261fa58Smacallan while ( count < w) { 2364261fa58Smacallan num = min(32, w - count); 2374261fa58Smacallan write_sx_io(p, s, 2384261fa58Smacallan SX_LD(10, num - 1, s & 7)); 2394261fa58Smacallan write_sx_io(p, d, 2404261fa58Smacallan SX_LD(42, num - 1, d & 7)); 2414261fa58Smacallan if (num > 16) { 2424261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 2434261fa58Smacallan SX_ROP(10, 42, 74, 15)); 2444261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 2454261fa58Smacallan SX_ROP(26, 58, 90, num - 17)); 2464261fa58Smacallan } else { 2474261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 2484261fa58Smacallan SX_ROP(10, 42, 74, num - 1)); 2494261fa58Smacallan } 2504261fa58Smacallan write_sx_io(p, d, 2514261fa58Smacallan SX_STM(74, num - 1, d & 7)); 2524261fa58Smacallan s += xinc; 2534261fa58Smacallan d += xinc; 2544261fa58Smacallan count += 32; 2554261fa58Smacallan } 2564261fa58Smacallan srcstart += srcinc; 2574261fa58Smacallan dststart += dstinc; 2584261fa58Smacallan } 2594261fa58Smacallan } else { 2604261fa58Smacallan /* going right to left */ 2614261fa58Smacallan int i, chunks = (w >> 5); 2624261fa58Smacallan for (line = 0; line < h; line++) { 2634261fa58Smacallan s = srcstart; 2644261fa58Smacallan d = dststart; 2654261fa58Smacallan count = w; 2664261fa58Smacallan for (i = 0; i < chunks; i++) { 2674261fa58Smacallan write_sx_io(p, s, SX_LD(10, 31, s & 7)); 2684261fa58Smacallan write_sx_io(p, d, SX_LD(42, 31, d & 7)); 2694261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 2704261fa58Smacallan SX_ROP(10, 42, 74, 15)); 2714261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 2724261fa58Smacallan SX_ROP(26, 58, 90, 15)); 2734261fa58Smacallan write_sx_io(p, d, 2744261fa58Smacallan SX_STM(74, 31, d & 7)); 2754261fa58Smacallan s -= 128; 2764261fa58Smacallan d -= 128; 2774261fa58Smacallan count -= 32; 2784261fa58Smacallan } 2794261fa58Smacallan /* leftovers, if any */ 2804261fa58Smacallan if (count > 0) { 2814261fa58Smacallan s += (32 - count) << 2; 2824261fa58Smacallan d += (32 - count) << 2; 2834261fa58Smacallan write_sx_io(p, s, 2844261fa58Smacallan SX_LD(10, count - 1, s & 7)); 2854261fa58Smacallan write_sx_io(p, d, 2864261fa58Smacallan SX_LD(42, count - 1, d & 7)); 2874261fa58Smacallan if (count > 16) { 2884261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 2894261fa58Smacallan SX_ROP(10, 42, 74, 15)); 2904261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 2914261fa58Smacallan SX_ROP(26, 58, 90, count - 17)); 2924261fa58Smacallan } else { 2934261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 2944261fa58Smacallan SX_ROP(10, 42, 74, count - 1)); 2954261fa58Smacallan } 2964261fa58Smacallan 2974261fa58Smacallan write_sx_io(p, d, 2984261fa58Smacallan SX_STM(74, count - 1, d & 7)); 2994261fa58Smacallan } 3004261fa58Smacallan srcstart += srcinc; 3014261fa58Smacallan dststart += dstinc; 3024261fa58Smacallan } 3034261fa58Smacallan } 3044261fa58Smacallan } 3054261fa58Smacallan exaMarkSync(pDstPixmap->drawable.pScreen); 3064261fa58Smacallan} 3074261fa58Smacallan 308f71acd79Smacallanstatic void 309f71acd79SmacallanCG14Copy8(PixmapPtr pDstPixmap, 310f71acd79Smacallan int srcX, int srcY, int dstX, int dstY, int w, int h) 311f71acd79Smacallan{ 312f71acd79Smacallan ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum]; 313f71acd79Smacallan Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn); 314f71acd79Smacallan int dstpitch, dstoff, srcpitch, srcoff; 315f71acd79Smacallan int srcstart, dststart, xinc, srcinc, dstinc; 316f71acd79Smacallan int line, count, s, d, num; 317f71acd79Smacallan 318f71acd79Smacallan ENTER; 319f71acd79Smacallan dstpitch = exaGetPixmapPitch(pDstPixmap); 320f71acd79Smacallan dstoff = exaGetPixmapOffset(pDstPixmap); 321f71acd79Smacallan srcpitch = p->srcpitch; 322f71acd79Smacallan srcoff = p->srcoff; 323f71acd79Smacallan /* 324f71acd79Smacallan * should clear the WO bit in SX_CONTROL_STATUS, then check if SX 325f71acd79Smacallan * actually wrote anything and only sync if it did 326f71acd79Smacallan */ 327f71acd79Smacallan srcstart = srcX + (srcpitch * srcY) + srcoff; 328f71acd79Smacallan dststart = dstX + (dstpitch * dstY) + dstoff; 329f71acd79Smacallan 330f71acd79Smacallan /* 331f71acd79Smacallan * we always copy up to 32 pixels at a time so direction doesn't 332f71acd79Smacallan * matter if w<=32 333f71acd79Smacallan */ 334f71acd79Smacallan if (w > 32) { 335f71acd79Smacallan if (p->xdir < 0) { 336f71acd79Smacallan srcstart += (w - 32); 337f71acd79Smacallan dststart += (w - 32); 338f71acd79Smacallan xinc = -32; 339f71acd79Smacallan } else 340f71acd79Smacallan xinc = 32; 341f71acd79Smacallan } else 342f71acd79Smacallan xinc = 32; 343f71acd79Smacallan if (p->ydir < 0) { 344f71acd79Smacallan srcstart += (h - 1) * srcpitch; 345f71acd79Smacallan dststart += (h - 1) * dstpitch; 346f71acd79Smacallan srcinc = -srcpitch; 347f71acd79Smacallan dstinc = -dstpitch; 348f71acd79Smacallan } else { 349f71acd79Smacallan srcinc = srcpitch; 350f71acd79Smacallan dstinc = dstpitch; 351f71acd79Smacallan } 352f71acd79Smacallan if (p->last_rop == 0xcc) { 353f71acd79Smacallan /* plain old copy */ 354f71acd79Smacallan if ( xinc > 0) { 355f71acd79Smacallan /* going left to right */ 356f71acd79Smacallan for (line = 0; line < h; line++) { 357f71acd79Smacallan count = 0; 358f71acd79Smacallan s = srcstart; 359f71acd79Smacallan d = dststart; 360f71acd79Smacallan while ( count < w) { 361f71acd79Smacallan num = min(32, w - count); 362f71acd79Smacallan write_sx_io(p, s, 363f71acd79Smacallan SX_LDB(10, num - 1, s & 7)); 364f71acd79Smacallan write_sx_io(p, d, 365f71acd79Smacallan SX_STBM(10, num - 1, d & 7)); 366f71acd79Smacallan s += xinc; 367f71acd79Smacallan d += xinc; 368f71acd79Smacallan count += 32; 369f71acd79Smacallan } 370f71acd79Smacallan srcstart += srcinc; 371f71acd79Smacallan dststart += dstinc; 372f71acd79Smacallan } 373f71acd79Smacallan } else { 374f71acd79Smacallan /* going right to left */ 375f71acd79Smacallan int i, chunks = (w >> 5); 376f71acd79Smacallan for (line = 0; line < h; line++) { 377f71acd79Smacallan s = srcstart; 378f71acd79Smacallan d = dststart; 379f71acd79Smacallan count = w; 380f71acd79Smacallan for (i = 0; i < chunks; i++) { 381f71acd79Smacallan write_sx_io(p, s, 382f71acd79Smacallan SX_LDB(10, 31, s & 7)); 383f71acd79Smacallan write_sx_io(p, d, 384f71acd79Smacallan SX_STBM(10, 31, d & 7)); 385f71acd79Smacallan s -= 32; 386f71acd79Smacallan d -= 32; 387f71acd79Smacallan count -= 32; 388f71acd79Smacallan } 389f71acd79Smacallan /* leftovers, if any */ 390f71acd79Smacallan if (count > 0) { 391f71acd79Smacallan s += (32 - count); 392f71acd79Smacallan d += (32 - count); 393f71acd79Smacallan write_sx_io(p, s, 394f71acd79Smacallan SX_LDB(10, count - 1, s & 7)); 395f71acd79Smacallan write_sx_io(p, d, 396f71acd79Smacallan SX_STBM(10, count - 1, d & 7)); 397f71acd79Smacallan } 398f71acd79Smacallan srcstart += srcinc; 399f71acd79Smacallan dststart += dstinc; 400f71acd79Smacallan } 401f71acd79Smacallan } 402f71acd79Smacallan } else { 403f71acd79Smacallan /* ROPs needed */ 404f71acd79Smacallan if ( xinc > 0) { 405f71acd79Smacallan /* going left to right */ 406f71acd79Smacallan for (line = 0; line < h; line++) { 407f71acd79Smacallan count = 0; 408f71acd79Smacallan s = srcstart; 409f71acd79Smacallan d = dststart; 410f71acd79Smacallan while ( count < w) { 411f71acd79Smacallan num = min(32, w - count); 412f71acd79Smacallan write_sx_io(p, s, 413f71acd79Smacallan SX_LDB(10, num - 1, s & 7)); 414f71acd79Smacallan write_sx_io(p, d, 415f71acd79Smacallan SX_LDB(42, num - 1, d & 7)); 416f71acd79Smacallan if (num > 16) { 417f71acd79Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 418f71acd79Smacallan SX_ROP(10, 42, 74, 15)); 419f71acd79Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 420f71acd79Smacallan SX_ROP(26, 58, 90, num - 17)); 421f71acd79Smacallan } else { 422f71acd79Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 423f71acd79Smacallan SX_ROP(10, 42, 74, num - 1)); 424f71acd79Smacallan } 425f71acd79Smacallan write_sx_io(p, d, 426f71acd79Smacallan SX_STBM(74, num - 1, d & 7)); 427f71acd79Smacallan s += xinc; 428f71acd79Smacallan d += xinc; 429f71acd79Smacallan count += 32; 430f71acd79Smacallan } 431f71acd79Smacallan srcstart += srcinc; 432f71acd79Smacallan dststart += dstinc; 433f71acd79Smacallan } 434f71acd79Smacallan } else { 435f71acd79Smacallan /* going right to left */ 436f71acd79Smacallan int i, chunks = (w >> 5); 437f71acd79Smacallan for (line = 0; line < h; line++) { 438f71acd79Smacallan s = srcstart; 439f71acd79Smacallan d = dststart; 440f71acd79Smacallan count = w; 441f71acd79Smacallan for (i = 0; i < chunks; i++) { 442f71acd79Smacallan write_sx_io(p, s, SX_LDB(10, 31, s & 7)); 443f71acd79Smacallan write_sx_io(p, d, SX_LDB(42, 31, d & 7)); 444f71acd79Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 445f71acd79Smacallan SX_ROP(10, 42, 74, 15)); 446f71acd79Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 447f71acd79Smacallan SX_ROP(26, 58, 90, 15)); 448f71acd79Smacallan write_sx_io(p, d, 449f71acd79Smacallan SX_STBM(74, 31, d & 7)); 450f71acd79Smacallan s -= 128; 451f71acd79Smacallan d -= 128; 452f71acd79Smacallan count -= 32; 453f71acd79Smacallan } 454f71acd79Smacallan /* leftovers, if any */ 455f71acd79Smacallan if (count > 0) { 456f71acd79Smacallan s += (32 - count); 457f71acd79Smacallan d += (32 - count); 458f71acd79Smacallan write_sx_io(p, s, 459f71acd79Smacallan SX_LDB(10, count - 1, s & 7)); 460f71acd79Smacallan write_sx_io(p, d, 461f71acd79Smacallan SX_LDB(42, count - 1, d & 7)); 462f71acd79Smacallan if (count > 16) { 463f71acd79Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 464f71acd79Smacallan SX_ROP(10, 42, 74, 15)); 465f71acd79Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 466f71acd79Smacallan SX_ROP(26, 58, 90, count - 17)); 467f71acd79Smacallan } else { 468f71acd79Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 469f71acd79Smacallan SX_ROP(10, 42, 74, count - 1)); 470f71acd79Smacallan } 471f71acd79Smacallan 472f71acd79Smacallan write_sx_io(p, d, 473f71acd79Smacallan SX_STBM(74, count - 1, d & 7)); 474f71acd79Smacallan } 475f71acd79Smacallan srcstart += srcinc; 476f71acd79Smacallan dststart += dstinc; 477f71acd79Smacallan } 478f71acd79Smacallan } 479f71acd79Smacallan } 480f71acd79Smacallan exaMarkSync(pDstPixmap->drawable.pScreen); 481f71acd79Smacallan} 482f71acd79Smacallan 4834261fa58Smacallanstatic void 4844261fa58SmacallanCG14DoneCopy(PixmapPtr pDstPixmap) 4854261fa58Smacallan{ 4864261fa58Smacallan} 4874261fa58Smacallan 4884261fa58Smacallanstatic Bool 4894261fa58SmacallanCG14PrepareSolid(PixmapPtr pPixmap, int alu, Pixel planemask, Pixel fg) 4904261fa58Smacallan{ 4914261fa58Smacallan ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; 4924261fa58Smacallan Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn); 4934261fa58Smacallan 4944261fa58Smacallan ENTER; 4956bdc2ffdSmacallan DPRINTF(X_ERROR, "bits per pixel: %d\n", 4966bdc2ffdSmacallan pPixmap->drawable.bitsPerPixel); 4974261fa58Smacallan write_sx_reg(p, SX_QUEUED(8), fg); 4984261fa58Smacallan write_sx_reg(p, SX_QUEUED(9), fg); 4994261fa58Smacallan if (planemask != p->last_mask) { 5004261fa58Smacallan CG14Wait(p); 5014261fa58Smacallan write_sx_reg(p, SX_PLANEMASK, planemask); 5024261fa58Smacallan p->last_mask = planemask; 5034261fa58Smacallan } 5044261fa58Smacallan alu = sx_rop[alu]; 5054261fa58Smacallan if (alu != p->last_rop) { 5064261fa58Smacallan CG14Wait(p); 5074261fa58Smacallan write_sx_reg(p, SX_ROP_CONTROL, alu); 5084261fa58Smacallan p->last_rop = alu; 5094261fa58Smacallan } 5104261fa58Smacallan DPRINTF(X_ERROR, "%s: %x\n", __func__, alu); 5114261fa58Smacallan return TRUE; 5124261fa58Smacallan} 5134261fa58Smacallan 5144261fa58Smacallanstatic void 5154261fa58SmacallanCG14Solid32(Cg14Ptr p, uint32_t start, uint32_t pitch, int w, int h) 5164261fa58Smacallan{ 5174261fa58Smacallan int line, x, num; 5184261fa58Smacallan uint32_t ptr; 5194261fa58Smacallan 5204261fa58Smacallan ENTER; 5214261fa58Smacallan if (p->last_rop == 0xcc) { 5224261fa58Smacallan /* simple fill */ 5234261fa58Smacallan for (line = 0; line < h; line++) { 5244261fa58Smacallan x = 0; 5254261fa58Smacallan while (x < w) { 5264261fa58Smacallan ptr = start + (x << 2); 5274261fa58Smacallan num = min(32, w - x); 5284261fa58Smacallan write_sx_io(p, ptr, 5294261fa58Smacallan SX_STS(8, num - 1, ptr & 7)); 5304261fa58Smacallan x += 32; 5314261fa58Smacallan } 5324261fa58Smacallan start += pitch; 5334261fa58Smacallan } 5344261fa58Smacallan } else if (p->last_rop == 0xaa) { 5354261fa58Smacallan /* nothing to do here */ 5364261fa58Smacallan return; 5374261fa58Smacallan } else { 5384261fa58Smacallan /* alright, let's do actual ROP stuff */ 5394261fa58Smacallan 5404261fa58Smacallan /* first repeat the fill colour into 16 registers */ 5414261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 5424261fa58Smacallan SX_SELECT_S(8, 8, 10, 15)); 5434261fa58Smacallan 5444261fa58Smacallan for (line = 0; line < h; line++) { 5454261fa58Smacallan x = 0; 5464261fa58Smacallan while (x < w) { 5474261fa58Smacallan ptr = start + (x << 2); 5484261fa58Smacallan num = min(32, w - x); 5494261fa58Smacallan /* now suck fb data into registers */ 5504261fa58Smacallan write_sx_io(p, ptr, 5514261fa58Smacallan SX_LD(42, num - 1, ptr & 7)); 5524261fa58Smacallan /* 5534261fa58Smacallan * ROP them with the fill data we left in 10 5544261fa58Smacallan * non-memory ops can only have counts up to 16 5554261fa58Smacallan */ 5564261fa58Smacallan if (num <= 16) { 5574261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 5584261fa58Smacallan SX_ROP(10, 42, 74, num - 1)); 5594261fa58Smacallan } else { 5604261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 5614261fa58Smacallan SX_ROP(10, 42, 74, 15)); 5624261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 5634261fa58Smacallan SX_ROP(10, 58, 90, num - 17)); 5644261fa58Smacallan } 5654261fa58Smacallan /* and write the result back into memory */ 5664261fa58Smacallan write_sx_io(p, ptr, 5674261fa58Smacallan SX_ST(74, num - 1, ptr & 7)); 5684261fa58Smacallan x += 32; 5694261fa58Smacallan } 5704261fa58Smacallan start += pitch; 5714261fa58Smacallan } 5724261fa58Smacallan } 5734261fa58Smacallan} 5744261fa58Smacallan 5754261fa58Smacallanstatic void 5764261fa58SmacallanCG14Solid8(Cg14Ptr p, uint32_t start, uint32_t pitch, int w, int h) 5774261fa58Smacallan{ 5784261fa58Smacallan int line, x, num, off; 5794261fa58Smacallan uint32_t ptr; 5804261fa58Smacallan 5814261fa58Smacallan ENTER; 5824261fa58Smacallan off = start & 7; 5834261fa58Smacallan start &= ~7; 5844261fa58Smacallan 5854261fa58Smacallan if (p->last_rop == 0xcc) { 5864261fa58Smacallan /* simple fill */ 5874261fa58Smacallan for (line = 0; line < h; line++) { 5884261fa58Smacallan x = 0; 5894261fa58Smacallan while (x < w) { 5904261fa58Smacallan ptr = start + x; 5914261fa58Smacallan num = min(32, w - x); 5924261fa58Smacallan write_sx_io(p, ptr, 5934261fa58Smacallan SX_STBS(8, num - 1, off)); 5944261fa58Smacallan x += 32; 5954261fa58Smacallan } 5964261fa58Smacallan start += pitch; 5974261fa58Smacallan } 5984261fa58Smacallan } else if (p->last_rop == 0xaa) { 5994261fa58Smacallan /* nothing to do here */ 6004261fa58Smacallan return; 6014261fa58Smacallan } else { 6024261fa58Smacallan /* alright, let's do actual ROP stuff */ 6034261fa58Smacallan 6044261fa58Smacallan /* first repeat the fill colour into 16 registers */ 6054261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 6064261fa58Smacallan SX_SELECT_S(8, 8, 10, 15)); 6074261fa58Smacallan 6084261fa58Smacallan for (line = 0; line < h; line++) { 6094261fa58Smacallan x = 0; 6104261fa58Smacallan while (x < w) { 6114261fa58Smacallan ptr = start + x; 6124261fa58Smacallan num = min(32, w - x); 6134261fa58Smacallan /* now suck fb data into registers */ 6144261fa58Smacallan write_sx_io(p, ptr, 6154261fa58Smacallan SX_LDB(42, num - 1, off)); 6164261fa58Smacallan /* 6174261fa58Smacallan * ROP them with the fill data we left in 10 6184261fa58Smacallan * non-memory ops can only have counts up to 16 6194261fa58Smacallan */ 6204261fa58Smacallan if (num <= 16) { 6214261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 6224261fa58Smacallan SX_ROP(10, 42, 74, num - 1)); 6234261fa58Smacallan } else { 6244261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 6254261fa58Smacallan SX_ROP(10, 42, 74, 15)); 6264261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 6274261fa58Smacallan SX_ROP(10, 58, 90, num - 17)); 6284261fa58Smacallan } 6294261fa58Smacallan /* and write the result back into memory */ 6304261fa58Smacallan write_sx_io(p, ptr, 6314261fa58Smacallan SX_STB(74, num - 1, off)); 6324261fa58Smacallan x += 32; 6334261fa58Smacallan } 6344261fa58Smacallan start += pitch; 6354261fa58Smacallan } 6364261fa58Smacallan } 6374261fa58Smacallan} 6384261fa58Smacallan 6394261fa58Smacallanstatic void 6404261fa58SmacallanCG14Solid(PixmapPtr pPixmap, int x1, int y1, int x2, int y2) 6414261fa58Smacallan{ 6424261fa58Smacallan ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; 6434261fa58Smacallan Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn); 6444261fa58Smacallan int w = x2 - x1, h = y2 - y1, dstoff, dstpitch; 6454261fa58Smacallan int start, depth; 6464261fa58Smacallan 6474261fa58Smacallan ENTER; 6484261fa58Smacallan dstpitch = exaGetPixmapPitch(pPixmap); 6494261fa58Smacallan dstoff = exaGetPixmapOffset(pPixmap); 6504261fa58Smacallan 6514261fa58Smacallan depth = pPixmap->drawable.bitsPerPixel; 6524261fa58Smacallan switch (depth) { 6534261fa58Smacallan case 32: 6544261fa58Smacallan start = dstoff + (y1 * dstpitch) + (x1 << 2); 6554261fa58Smacallan CG14Solid32(p, start, dstpitch, w, h); 6564261fa58Smacallan break; 6574261fa58Smacallan case 8: 6584261fa58Smacallan start = dstoff + (y1 * dstpitch) + x1; 6594261fa58Smacallan CG14Solid8(p, start, dstpitch, w, h); 6604261fa58Smacallan break; 6614261fa58Smacallan } 6624261fa58Smacallan 6634261fa58Smacallan DPRINTF(X_ERROR, "Solid %d %d %d %d, %d %d -> %d\n", x1, y1, x2, y2, 6644261fa58Smacallan dstpitch, dstoff, start); 6654261fa58Smacallan DPRINTF(X_ERROR, "%x %x %x\n", p->last_rop, 6664261fa58Smacallan read_sx_reg(p, SX_QUEUED(8)), read_sx_reg(p, SX_QUEUED(9))); 6674261fa58Smacallan exaMarkSync(pPixmap->drawable.pScreen); 6684261fa58Smacallan} 6694261fa58Smacallan 6704261fa58Smacallan/* 6714261fa58Smacallan * Memcpy-based UTS. 6724261fa58Smacallan */ 6734261fa58Smacallanstatic Bool 6744261fa58SmacallanCG14UploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, 6754261fa58Smacallan char *src, int src_pitch) 6764261fa58Smacallan{ 6774261fa58Smacallan ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum]; 6784261fa58Smacallan Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn); 6794261fa58Smacallan char *dst = p->fb + exaGetPixmapOffset(pDst); 6804261fa58Smacallan int dst_pitch = exaGetPixmapPitch(pDst); 6814261fa58Smacallan 6824261fa58Smacallan int bpp = pDst->drawable.bitsPerPixel; 6834261fa58Smacallan int cpp = (bpp + 7) >> 3; 6844261fa58Smacallan int wBytes = w * cpp; 6854261fa58Smacallan 6864261fa58Smacallan ENTER; 687f71acd79Smacallan DPRINTF(X_ERROR, "%s depth %d\n", __func__, bpp); 6884261fa58Smacallan dst += (x * cpp) + (y * dst_pitch); 6894261fa58Smacallan 6904261fa58Smacallan CG14Wait(p); 6914261fa58Smacallan 6924261fa58Smacallan while (h--) { 6934261fa58Smacallan memcpy(dst, src, wBytes); 6944261fa58Smacallan src += src_pitch; 6954261fa58Smacallan dst += dst_pitch; 6964261fa58Smacallan } 6974261fa58Smacallan __asm("stbar;"); 6984261fa58Smacallan return TRUE; 6994261fa58Smacallan} 7004261fa58Smacallan 7014261fa58Smacallan/* 7024261fa58Smacallan * Memcpy-based DFS. 7034261fa58Smacallan */ 7044261fa58Smacallanstatic Bool 7054261fa58SmacallanCG14DownloadFromScreen(PixmapPtr pSrc, int x, int y, int w, int h, 7064261fa58Smacallan char *dst, int dst_pitch) 7074261fa58Smacallan{ 7084261fa58Smacallan ScrnInfoPtr pScrn = xf86Screens[pSrc->drawable.pScreen->myNum]; 7094261fa58Smacallan Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn); 7104261fa58Smacallan char *src = p->fb + exaGetPixmapOffset(pSrc); 7114261fa58Smacallan int src_pitch = exaGetPixmapPitch(pSrc); 7124261fa58Smacallan 7134261fa58Smacallan ENTER; 7144261fa58Smacallan int bpp = pSrc->drawable.bitsPerPixel; 7154261fa58Smacallan int cpp = (bpp + 7) >> 3; 7164261fa58Smacallan int wBytes = w * cpp; 7174261fa58Smacallan 7184261fa58Smacallan src += (x * cpp) + (y * src_pitch); 7194261fa58Smacallan 7204261fa58Smacallan CG14Wait(p); 7214261fa58Smacallan 7224261fa58Smacallan while (h--) { 7234261fa58Smacallan memcpy(dst, src, wBytes); 7244261fa58Smacallan src += src_pitch; 7254261fa58Smacallan dst += dst_pitch; 7264261fa58Smacallan } 7274261fa58Smacallan 7284261fa58Smacallan return TRUE; 7294261fa58Smacallan} 7304261fa58Smacallan 7314261fa58SmacallanBool 7324261fa58SmacallanCG14CheckComposite(int op, PicturePtr pSrcPicture, 7334261fa58Smacallan PicturePtr pMaskPicture, 7344261fa58Smacallan PicturePtr pDstPicture) 7354261fa58Smacallan{ 7364261fa58Smacallan int i, ok = FALSE; 7374261fa58Smacallan 7384261fa58Smacallan ENTER; 7394261fa58Smacallan 7404261fa58Smacallan /* 7414261fa58Smacallan * SX is in theory capable of accelerating pretty much all Xrender ops, 7424261fa58Smacallan * even coordinate transformation and gradients. Support will be added 7434261fa58Smacallan * over time and likely have to spill over into its own source file. 7444261fa58Smacallan */ 7454261fa58Smacallan 746a3a2ba44Smacallan if ((op != PictOpOver) && (op != PictOpAdd) && (op != PictOpSrc)) { 747fe97f391Smacallan DPRINTF(X_ERROR, "%s: rejecting %d\n", __func__, op); 7484261fa58Smacallan return FALSE; 7494261fa58Smacallan } 7504261fa58Smacallan 7514bd47ccfSmacallan if (pSrcPicture != NULL) { 7524bd47ccfSmacallan i = 0; 7534bd47ccfSmacallan while ((i < arraysize(src_formats)) && (!ok)) { 7544bd47ccfSmacallan ok = (pSrcPicture->format == src_formats[i]); 7554bd47ccfSmacallan i++; 7564bd47ccfSmacallan } 7574bd47ccfSmacallan 7584bd47ccfSmacallan if (!ok) { 7594bd47ccfSmacallan DPRINTF(X_ERROR, "%s: unsupported src format %x\n", 7604bd47ccfSmacallan __func__, pSrcPicture->format); 7614bd47ccfSmacallan return FALSE; 7624bd47ccfSmacallan } 7634bd47ccfSmacallan DPRINTF(X_ERROR, "src is %x, %d\n", pSrcPicture->format, op); 7644261fa58Smacallan } 7654261fa58Smacallan 7664bd47ccfSmacallan if (pDstPicture != NULL) { 7674bd47ccfSmacallan i = 0; 7684bd47ccfSmacallan ok = FALSE; 7694bd47ccfSmacallan while ((i < arraysize(src_formats)) && (!ok)) { 7704bd47ccfSmacallan ok = (pDstPicture->format == src_formats[i]); 7714bd47ccfSmacallan i++; 7724bd47ccfSmacallan } 7734bd47ccfSmacallan 7744bd47ccfSmacallan if (!ok) { 7754bd47ccfSmacallan DPRINTF(X_ERROR, "%s: unsupported dst format %x\n", 7764bd47ccfSmacallan __func__, pDstPicture->format); 7774bd47ccfSmacallan return FALSE; 7784bd47ccfSmacallan } 7794bd47ccfSmacallan DPRINTF(X_ERROR, "dst is %x, %d\n", pDstPicture->format, op); 7804bd47ccfSmacallan } 7814261fa58Smacallan 7824261fa58Smacallan if (pMaskPicture != NULL) { 7834261fa58Smacallan DPRINTF(X_ERROR, "mask is %x %d %d\n", pMaskPicture->format, 7844261fa58Smacallan pMaskPicture->pDrawable->width, 7854261fa58Smacallan pMaskPicture->pDrawable->height); 7864261fa58Smacallan } 7874261fa58Smacallan return TRUE; 7884261fa58Smacallan} 7894261fa58Smacallan 7904261fa58SmacallanBool 7914261fa58SmacallanCG14PrepareComposite(int op, PicturePtr pSrcPicture, 7924261fa58Smacallan PicturePtr pMaskPicture, 7934261fa58Smacallan PicturePtr pDstPicture, 7944261fa58Smacallan PixmapPtr pSrc, 7954261fa58Smacallan PixmapPtr pMask, 7964261fa58Smacallan PixmapPtr pDst) 7974261fa58Smacallan{ 7984261fa58Smacallan ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum]; 7994261fa58Smacallan Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn); 8004261fa58Smacallan 8014261fa58Smacallan ENTER; 8024261fa58Smacallan 803f7cb851fSmacallan p->no_source_pixmap = FALSE; 804f7cb851fSmacallan p->source_is_solid = FALSE; 805f7cb851fSmacallan 806a3a2ba44Smacallan if (pSrcPicture->format == PICT_a1) { 8076bdc2ffdSmacallan xf86Msg(X_ERROR, "src mono, dst %x, op %d\n", 8086bdc2ffdSmacallan pDstPicture->format, op); 809a3a2ba44Smacallan if (pMaskPicture != NULL) { 810a3a2ba44Smacallan xf86Msg(X_ERROR, "msk %x\n", pMaskPicture->format); 811a3a2ba44Smacallan } 812f7cb851fSmacallan } 8134261fa58Smacallan if (pSrcPicture->pSourcePict != NULL) { 8144261fa58Smacallan if (pSrcPicture->pSourcePict->type == SourcePictTypeSolidFill) { 8154261fa58Smacallan p->fillcolour = 8164261fa58Smacallan pSrcPicture->pSourcePict->solidFill.color; 817f7cb851fSmacallan DPRINTF(X_ERROR, "%s: solid src %08x\n", 8184261fa58Smacallan __func__, p->fillcolour); 819f7cb851fSmacallan p->no_source_pixmap = TRUE; 820f7cb851fSmacallan p->source_is_solid = TRUE; 8214261fa58Smacallan } 8224261fa58Smacallan } 8234261fa58Smacallan if ((pMaskPicture != NULL) && (pMaskPicture->pSourcePict != NULL)) { 8244261fa58Smacallan if (pMaskPicture->pSourcePict->type == 8254261fa58Smacallan SourcePictTypeSolidFill) { 8264261fa58Smacallan p->fillcolour = 8274261fa58Smacallan pMaskPicture->pSourcePict->solidFill.color; 828a3a2ba44Smacallan xf86Msg(X_ERROR, "%s: solid mask %08x\n", 8294261fa58Smacallan __func__, p->fillcolour); 8304261fa58Smacallan } 8314261fa58Smacallan } 8324261fa58Smacallan if (pMaskPicture != NULL) { 833239808baSmacallan p->mskoff = exaGetPixmapOffset(pMask); 8344261fa58Smacallan p->mskpitch = exaGetPixmapPitch(pMask); 8354261fa58Smacallan p->mskformat = pMaskPicture->format; 836a3a2ba44Smacallan } else { 837239808baSmacallan p->mskoff = 0; 838a3a2ba44Smacallan p->mskpitch = 0; 839a3a2ba44Smacallan p->mskformat = 0; 8404261fa58Smacallan } 841f7cb851fSmacallan if (pSrc != NULL) { 842f7cb851fSmacallan p->source_is_solid = 843f7cb851fSmacallan ((pSrc->drawable.width == 1) && (pSrc->drawable.height == 1)); 844f7cb851fSmacallan p->srcoff = exaGetPixmapOffset(pSrc); 845f7cb851fSmacallan p->srcpitch = exaGetPixmapPitch(pSrc); 846f7cb851fSmacallan if (p->source_is_solid) { 847f7cb851fSmacallan p->fillcolour = *(uint32_t *)(p->fb + p->srcoff); 848f7cb851fSmacallan } 849f7cb851fSmacallan } 8504261fa58Smacallan p->srcformat = pSrcPicture->format; 8514261fa58Smacallan p->dstformat = pDstPicture->format; 852f7cb851fSmacallan 853f7cb851fSmacallan if (p->source_is_solid) { 854f7cb851fSmacallan uint32_t temp; 855f7cb851fSmacallan 856f7cb851fSmacallan /* stuff source colour into SX registers, swap as needed */ 857f7cb851fSmacallan temp = p->fillcolour; 858f7cb851fSmacallan switch (p->srcformat) { 859f7cb851fSmacallan case PICT_a8r8g8b8: 860f7cb851fSmacallan case PICT_x8r8g8b8: 861f7cb851fSmacallan write_sx_reg(p, SX_QUEUED(9), temp & 0xff); 862f7cb851fSmacallan temp = temp >> 8; 863f7cb851fSmacallan write_sx_reg(p, SX_QUEUED(10), temp & 0xff); 864f7cb851fSmacallan temp = temp >> 8; 865f7cb851fSmacallan write_sx_reg(p, SX_QUEUED(11), temp & 0xff); 866f7cb851fSmacallan break; 867f7cb851fSmacallan case PICT_a8b8g8r8: 868f7cb851fSmacallan case PICT_x8b8g8r8: 869f7cb851fSmacallan write_sx_reg(p, SX_QUEUED(11), temp & 0xff); 870f7cb851fSmacallan temp = temp >> 8; 871f7cb851fSmacallan write_sx_reg(p, SX_QUEUED(10), temp & 0xff); 872f7cb851fSmacallan temp = temp >> 8; 873f7cb851fSmacallan write_sx_reg(p, SX_QUEUED(9), temp & 0xff); 874f7cb851fSmacallan break; 875f7cb851fSmacallan } 876f7cb851fSmacallan write_sx_reg(p, SX_QUEUED(8), 0xff); 877f7cb851fSmacallan } 8784261fa58Smacallan p->op = op; 879a3a2ba44Smacallan if (op == PictOpSrc) { 880a3a2ba44Smacallan CG14PrepareCopy(pSrc, pDst, 1, 1, GXcopy, 0xffffffff); 881a3a2ba44Smacallan } 8824261fa58Smacallan#ifdef SX_DEBUG 8834261fa58Smacallan DPRINTF(X_ERROR, "%x %x -> %x\n", p->srcoff, p->mskoff, 8844261fa58Smacallan *(uint32_t *)(p->fb + p->srcoff)); 8854261fa58Smacallan#endif 8864261fa58Smacallan return TRUE; 8874261fa58Smacallan} 8884261fa58Smacallan 8894261fa58Smacallanvoid 8904261fa58SmacallanCG14Composite(PixmapPtr pDst, int srcX, int srcY, 8914261fa58Smacallan int maskX, int maskY, 8924261fa58Smacallan int dstX, int dstY, 8934261fa58Smacallan int width, int height) 8944261fa58Smacallan{ 8954261fa58Smacallan ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum]; 8964261fa58Smacallan Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn); 8974261fa58Smacallan uint32_t dstoff, dstpitch; 8984261fa58Smacallan uint32_t dst, msk, src; 899e311bbeeSmacallan int flip = 0; 9004261fa58Smacallan 9014261fa58Smacallan ENTER; 9024261fa58Smacallan dstoff = exaGetPixmapOffset(pDst); 9034261fa58Smacallan dstpitch = exaGetPixmapPitch(pDst); 9044261fa58Smacallan 905e311bbeeSmacallan flip = (PICT_FORMAT_TYPE(p->srcformat) != 906e311bbeeSmacallan PICT_FORMAT_TYPE(p->dstformat)); 907e311bbeeSmacallan 9084261fa58Smacallan switch (p->op) { 9094261fa58Smacallan case PictOpOver: 9104261fa58Smacallan dst = dstoff + (dstY * dstpitch) + (dstX << 2); 9114261fa58Smacallan DPRINTF(X_ERROR, "Over %08x %08x, %d %d\n", 9124261fa58Smacallan p->mskformat, p->dstformat, srcX, srcY); 913a3a2ba44Smacallan if (p->source_is_solid) { 914a3a2ba44Smacallan switch (p->mskformat) { 915a3a2ba44Smacallan case PICT_a8: 916a3a2ba44Smacallan msk = p->mskoff + 917a3a2ba44Smacallan (maskY * p->mskpitch) + 918a3a2ba44Smacallan maskX; 919a3a2ba44Smacallan CG14Comp_Over8Solid(p, 920a3a2ba44Smacallan msk, p->mskpitch, 921a3a2ba44Smacallan dst, dstpitch, 922a3a2ba44Smacallan width, height); 923a3a2ba44Smacallan break; 924a3a2ba44Smacallan case PICT_a8r8g8b8: 925a3a2ba44Smacallan case PICT_a8b8g8r8: 926a3a2ba44Smacallan msk = p->mskoff + 927a3a2ba44Smacallan (maskY * p->mskpitch) + 928a3a2ba44Smacallan (maskX << 2); 929a3a2ba44Smacallan CG14Comp_Over32Solid(p, 930a3a2ba44Smacallan msk, p->mskpitch, 931a3a2ba44Smacallan dst, dstpitch, 932a3a2ba44Smacallan width, height); 933a3a2ba44Smacallan break; 934a3a2ba44Smacallan default: 935a3a2ba44Smacallan xf86Msg(X_ERROR, 936f71acd79Smacallan "unsupported mask format %08x\n", p->mskformat); 937a3a2ba44Smacallan } 938a3a2ba44Smacallan } else { 9396bdc2ffdSmacallan DPRINTF(X_ERROR, "non-solid over with msk %x\n", 9406bdc2ffdSmacallan p->mskformat); 941a3a2ba44Smacallan switch (p->srcformat) { 942a3a2ba44Smacallan case PICT_a8r8g8b8: 943a3a2ba44Smacallan case PICT_a8b8g8r8: 944a3a2ba44Smacallan src = p->srcoff + 945a3a2ba44Smacallan (srcY * p->srcpitch) + 946a3a2ba44Smacallan (srcX << 2); 947a3a2ba44Smacallan dst = dstoff + 948a3a2ba44Smacallan (dstY * dstpitch) + 949a3a2ba44Smacallan (dstX << 2); 950a3a2ba44Smacallan if (p->mskformat == PICT_a8) { 951a3a2ba44Smacallan msk = p->mskoff + 952a3a2ba44Smacallan (maskY * p->mskpitch) + 953a3a2ba44Smacallan maskX; 954a3a2ba44Smacallan CG14Comp_Over32Mask(p, 955a3a2ba44Smacallan src, p->srcpitch, 956a3a2ba44Smacallan msk, p->mskpitch, 957a3a2ba44Smacallan dst, dstpitch, 958e311bbeeSmacallan width, height, flip); 959a3a2ba44Smacallan } else { 960a3a2ba44Smacallan CG14Comp_Over32(p, 961a3a2ba44Smacallan src, p->srcpitch, 962a3a2ba44Smacallan dst, dstpitch, 963e311bbeeSmacallan width, height, flip); 964a3a2ba44Smacallan } 965a3a2ba44Smacallan break; 966a3a2ba44Smacallan case PICT_x8r8g8b8: 967a3a2ba44Smacallan case PICT_x8b8g8r8: 9686bdc2ffdSmacallan src = p->srcoff + 9696bdc2ffdSmacallan (srcY * p->srcpitch) + 9706bdc2ffdSmacallan (srcX << 2); 9716bdc2ffdSmacallan dst = dstoff + 9726bdc2ffdSmacallan (dstY * dstpitch) + 9736bdc2ffdSmacallan (dstX << 2); 9746bdc2ffdSmacallan if (p->mskformat == PICT_a8) { 9756bdc2ffdSmacallan msk = p->mskoff + 9766bdc2ffdSmacallan (maskY * p->mskpitch) + 9776bdc2ffdSmacallan maskX; 9786bdc2ffdSmacallan CG14Comp_Over32Mask_noalpha(p, 9796bdc2ffdSmacallan src, p->srcpitch, 9806bdc2ffdSmacallan msk, p->mskpitch, 981fa158432Smacallan dst, dstpitch, 982e311bbeeSmacallan width, height, flip); 983fa158432Smacallan } else if ((p->mskformat == PICT_a8r8g8b8) || 984fa158432Smacallan (p->mskformat == PICT_a8b8g8r8)) { 985fa158432Smacallan msk = p->mskoff + 986fa158432Smacallan (maskY * p->mskpitch) + 987fa158432Smacallan (maskX << 2); 988fa158432Smacallan CG14Comp_Over32Mask32_noalpha(p, 989fa158432Smacallan src, p->srcpitch, 990fa158432Smacallan msk, p->mskpitch, 9916bdc2ffdSmacallan dst, dstpitch, 992e311bbeeSmacallan width, height, flip); 9936bdc2ffdSmacallan } else { 9946bdc2ffdSmacallan xf86Msg(X_ERROR, "no src alpha, mask is %x\n", p->mskformat); 9956bdc2ffdSmacallan } 996a3a2ba44Smacallan break; 997a3a2ba44Smacallan default: 998a3a2ba44Smacallan xf86Msg(X_ERROR, "%s: format %x in non-solid Over op\n", 999a3a2ba44Smacallan __func__, p->srcformat); 1000a3a2ba44Smacallan } 1001a3a2ba44Smacallan } 10024261fa58Smacallan break; 10034261fa58Smacallan case PictOpAdd: 10044261fa58Smacallan DPRINTF(X_ERROR, "Add %08x %08x\n", 10054261fa58Smacallan p->srcformat, p->dstformat); 10064261fa58Smacallan switch (p->srcformat) { 10074261fa58Smacallan case PICT_a8: 10084261fa58Smacallan src = p->srcoff + 10094261fa58Smacallan (srcY * p->srcpitch) + srcX; 1010d71cb32dSmacallan if (p->dstformat == PICT_a8) { 1011d71cb32dSmacallan dst = dstoff + 1012d71cb32dSmacallan (dstY * dstpitch) + dstX; 1013d71cb32dSmacallan CG14Comp_Add8(p, 1014d71cb32dSmacallan src, p->srcpitch, 1015d71cb32dSmacallan dst, dstpitch, 1016d71cb32dSmacallan width, height); 1017d71cb32dSmacallan } else { 1018d71cb32dSmacallan dst = dstoff + 1019d71cb32dSmacallan (dstY * dstpitch) + 1020d71cb32dSmacallan (dstX << 2); 1021d71cb32dSmacallan CG14Comp_Add8_32(p, 1022d71cb32dSmacallan src, p->srcpitch, 1023d71cb32dSmacallan dst, dstpitch, 1024d71cb32dSmacallan width, height); 1025d71cb32dSmacallan } 10264261fa58Smacallan break; 10274261fa58Smacallan case PICT_a8r8g8b8: 10284261fa58Smacallan case PICT_x8r8g8b8: 10294261fa58Smacallan src = p->srcoff + 10304261fa58Smacallan (srcY * p->srcpitch) + (srcX << 2); 10314261fa58Smacallan dst = dstoff + (dstY * dstpitch) + 10324261fa58Smacallan (dstX << 2); 10334261fa58Smacallan CG14Comp_Add32(p, src, p->srcpitch, 10344261fa58Smacallan dst, dstpitch, width, height); 10354261fa58Smacallan break; 10364261fa58Smacallan default: 10374261fa58Smacallan xf86Msg(X_ERROR, 10384261fa58Smacallan "unsupported src format\n"); 10394261fa58Smacallan } 10404261fa58Smacallan break; 1041a3a2ba44Smacallan case PictOpSrc: 1042a3a2ba44Smacallan DPRINTF(X_ERROR, "Src %08x %08x\n", 1043a3a2ba44Smacallan p->srcformat, p->dstformat); 1044239808baSmacallan if (p->mskformat != 0) 1045239808baSmacallan xf86Msg(X_ERROR, "Src mask %08x\n", p->mskformat); 1046f71acd79Smacallan if (p->srcformat == PICT_a8) { 1047f71acd79Smacallan CG14Copy8(pDst, srcX, srcY, dstX, dstY, width, height); 1048f71acd79Smacallan } else { 1049f71acd79Smacallan /* convert between RGB and BGR? */ 1050f71acd79Smacallan CG14Copy32(pDst, srcX, srcY, dstX, dstY, width, height); 1051f71acd79Smacallan } 1052a3a2ba44Smacallan break; 10534261fa58Smacallan default: 10544261fa58Smacallan xf86Msg(X_ERROR, "unsupported op %d\n", p->op); 10554261fa58Smacallan } 10564261fa58Smacallan exaMarkSync(pDst->drawable.pScreen); 10574261fa58Smacallan} 10584261fa58Smacallan 10594261fa58Smacallan 10604261fa58Smacallan 10614261fa58SmacallanBool 10624261fa58SmacallanCG14InitAccel(ScreenPtr pScreen) 10634261fa58Smacallan{ 10644261fa58Smacallan ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 10654261fa58Smacallan Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn); 10664261fa58Smacallan ExaDriverPtr pExa; 10674261fa58Smacallan 10684261fa58Smacallan pExa = exaDriverAlloc(); 10694261fa58Smacallan if (!pExa) 10704261fa58Smacallan return FALSE; 10714261fa58Smacallan 10724261fa58Smacallan p->pExa = pExa; 10734261fa58Smacallan 10744261fa58Smacallan pExa->exa_major = EXA_VERSION_MAJOR; 10754261fa58Smacallan pExa->exa_minor = EXA_VERSION_MINOR; 10764261fa58Smacallan 10774261fa58Smacallan pExa->memoryBase = p->fb; 10784261fa58Smacallan pExa->memorySize = p->memsize; 10794261fa58Smacallan pExa->offScreenBase = p->width * p->height * 4; 10804261fa58Smacallan 10814261fa58Smacallan /* 10824261fa58Smacallan * SX memory instructions are written to 64bit aligned addresses with 10834261fa58Smacallan * a 3 bit displacement. Make sure the displacement remains constant 10844261fa58Smacallan * within one column 10854261fa58Smacallan */ 10864261fa58Smacallan 10874261fa58Smacallan pExa->pixmapOffsetAlign = 8; 10884261fa58Smacallan pExa->pixmapPitchAlign = 8; 10894261fa58Smacallan 1090fe97f391Smacallan pExa->flags = EXA_OFFSCREEN_PIXMAPS 1091f71acd79Smacallan | EXA_SUPPORTS_OFFSCREEN_OVERLAPS 1092f71acd79Smacallan /*| EXA_MIXED_PIXMAPS*/; 10934261fa58Smacallan 10944261fa58Smacallan /* 10954261fa58Smacallan * these limits are bogus 10964261fa58Smacallan * SX doesn't deal with coordinates at all, so there is no limit but 10974261fa58Smacallan * we have to put something here 10984261fa58Smacallan */ 10994261fa58Smacallan pExa->maxX = 4096; 11004261fa58Smacallan pExa->maxY = 4096; 11014261fa58Smacallan 11024261fa58Smacallan pExa->WaitMarker = CG14WaitMarker; 11034261fa58Smacallan 11044261fa58Smacallan pExa->PrepareSolid = CG14PrepareSolid; 11054261fa58Smacallan pExa->Solid = CG14Solid; 11064261fa58Smacallan pExa->DoneSolid = CG14DoneCopy; 11074261fa58Smacallan pExa->PrepareCopy = CG14PrepareCopy; 1108f71acd79Smacallan pExa->Copy = CG14Copy32; 11094261fa58Smacallan pExa->DoneCopy = CG14DoneCopy; 11104261fa58Smacallan if (p->use_xrender) { 11114261fa58Smacallan pExa->CheckComposite = CG14CheckComposite; 11124261fa58Smacallan pExa->PrepareComposite = CG14PrepareComposite; 11134261fa58Smacallan pExa->Composite = CG14Composite; 11144261fa58Smacallan pExa->DoneComposite = CG14DoneCopy; 11154261fa58Smacallan } 11164261fa58Smacallan 11174261fa58Smacallan /* EXA hits more optimized paths when it does not have to fallback 11184261fa58Smacallan * because of missing UTS/DFS, hook memcpy-based UTS/DFS. 11194261fa58Smacallan */ 11204261fa58Smacallan pExa->UploadToScreen = CG14UploadToScreen; 11214261fa58Smacallan pExa->DownloadFromScreen = CG14DownloadFromScreen; 11224261fa58Smacallan 1123c2193d98Smacallan p->queuecount = 0; 11244261fa58Smacallan /* do some hardware init */ 11254261fa58Smacallan write_sx_reg(p, SX_PLANEMASK, 0xffffffff); 11264261fa58Smacallan p->last_mask = 0xffffffff; 11274261fa58Smacallan write_sx_reg(p, SX_ROP_CONTROL, 0xcc); 11284261fa58Smacallan p->last_rop = 0xcc; 11294261fa58Smacallan return exaDriverInit(pScreen, pExa); 11304261fa58Smacallan} 1131