cg14_accel.c revision b46cab2a
1b46cab2aSmacallan/* $NetBSD: cg14_accel.c,v 1.17 2021/12/03 06:10:07 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 45b8ad197aSmacallan//#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; 495b8ad197aSmacallan DPRINTF(X_ERROR, "bits per pixel: %d %08x\n", 496b8ad197aSmacallan pPixmap->drawable.bitsPerPixel, fg); 497b8ad197aSmacallan 498b8ad197aSmacallan /* repeat the colour in every sub byte if we're in 8 bit */ 499b8ad197aSmacallan if (pPixmap->drawable.bitsPerPixel == 8) { 500b8ad197aSmacallan fg |= fg << 8; 501b8ad197aSmacallan fg |= fg << 16; 502b8ad197aSmacallan } 5034261fa58Smacallan write_sx_reg(p, SX_QUEUED(8), fg); 5044261fa58Smacallan write_sx_reg(p, SX_QUEUED(9), fg); 5054261fa58Smacallan if (planemask != p->last_mask) { 5064261fa58Smacallan CG14Wait(p); 5074261fa58Smacallan write_sx_reg(p, SX_PLANEMASK, planemask); 5084261fa58Smacallan p->last_mask = planemask; 5094261fa58Smacallan } 5104261fa58Smacallan alu = sx_rop[alu]; 5114261fa58Smacallan if (alu != p->last_rop) { 5124261fa58Smacallan CG14Wait(p); 5134261fa58Smacallan write_sx_reg(p, SX_ROP_CONTROL, alu); 5144261fa58Smacallan p->last_rop = alu; 5154261fa58Smacallan } 516b8ad197aSmacallan if (0) return FALSE; 5174261fa58Smacallan DPRINTF(X_ERROR, "%s: %x\n", __func__, alu); 5184261fa58Smacallan return TRUE; 5194261fa58Smacallan} 5204261fa58Smacallan 5214261fa58Smacallanstatic void 5224261fa58SmacallanCG14Solid32(Cg14Ptr p, uint32_t start, uint32_t pitch, int w, int h) 5234261fa58Smacallan{ 5244261fa58Smacallan int line, x, num; 5254261fa58Smacallan uint32_t ptr; 5264261fa58Smacallan 5274261fa58Smacallan ENTER; 5284261fa58Smacallan if (p->last_rop == 0xcc) { 5294261fa58Smacallan /* simple fill */ 5304261fa58Smacallan for (line = 0; line < h; line++) { 5314261fa58Smacallan x = 0; 5324261fa58Smacallan while (x < w) { 5334261fa58Smacallan ptr = start + (x << 2); 5344261fa58Smacallan num = min(32, w - x); 5354261fa58Smacallan write_sx_io(p, ptr, 5364261fa58Smacallan SX_STS(8, num - 1, ptr & 7)); 5374261fa58Smacallan x += 32; 5384261fa58Smacallan } 5394261fa58Smacallan start += pitch; 5404261fa58Smacallan } 5414261fa58Smacallan } else if (p->last_rop == 0xaa) { 5424261fa58Smacallan /* nothing to do here */ 5434261fa58Smacallan return; 5444261fa58Smacallan } else { 5454261fa58Smacallan /* alright, let's do actual ROP stuff */ 5464261fa58Smacallan 5474261fa58Smacallan /* first repeat the fill colour into 16 registers */ 5484261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 5494261fa58Smacallan SX_SELECT_S(8, 8, 10, 15)); 5504261fa58Smacallan 5514261fa58Smacallan for (line = 0; line < h; line++) { 5524261fa58Smacallan x = 0; 5534261fa58Smacallan while (x < w) { 5544261fa58Smacallan ptr = start + (x << 2); 5554261fa58Smacallan num = min(32, w - x); 5564261fa58Smacallan /* now suck fb data into registers */ 5574261fa58Smacallan write_sx_io(p, ptr, 5584261fa58Smacallan SX_LD(42, num - 1, ptr & 7)); 5594261fa58Smacallan /* 5604261fa58Smacallan * ROP them with the fill data we left in 10 5614261fa58Smacallan * non-memory ops can only have counts up to 16 5624261fa58Smacallan */ 5634261fa58Smacallan if (num <= 16) { 5644261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 5654261fa58Smacallan SX_ROP(10, 42, 74, num - 1)); 5664261fa58Smacallan } else { 5674261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 5684261fa58Smacallan SX_ROP(10, 42, 74, 15)); 5694261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 5704261fa58Smacallan SX_ROP(10, 58, 90, num - 17)); 5714261fa58Smacallan } 5724261fa58Smacallan /* and write the result back into memory */ 5734261fa58Smacallan write_sx_io(p, ptr, 5744261fa58Smacallan SX_ST(74, num - 1, ptr & 7)); 5754261fa58Smacallan x += 32; 5764261fa58Smacallan } 5774261fa58Smacallan start += pitch; 5784261fa58Smacallan } 5794261fa58Smacallan } 5804261fa58Smacallan} 5814261fa58Smacallan 5824261fa58Smacallanstatic void 5834261fa58SmacallanCG14Solid8(Cg14Ptr p, uint32_t start, uint32_t pitch, int w, int h) 5844261fa58Smacallan{ 585b8ad197aSmacallan int line, x, num, off, pre, cnt; 5864261fa58Smacallan uint32_t ptr; 5874261fa58Smacallan 5884261fa58Smacallan ENTER; 589b8ad197aSmacallan pre = start & 3; 590b8ad197aSmacallan if (pre != 0) pre = 4 - pre; 5914261fa58Smacallan 5924261fa58Smacallan if (p->last_rop == 0xcc) { 5934261fa58Smacallan /* simple fill */ 5944261fa58Smacallan for (line = 0; line < h; line++) { 595b8ad197aSmacallan ptr = start; 596b8ad197aSmacallan cnt = w; 597b46cab2aSmacallan pre = min(pre, cnt); 598b8ad197aSmacallan if (pre) { 599b8ad197aSmacallan write_sx_io(p, ptr & ~7, SX_STBS(8, pre - 1, ptr & 7)); 600b8ad197aSmacallan ptr += pre; 601b8ad197aSmacallan cnt -= pre; 602b46cab2aSmacallan if (cnt == 0) goto next; 603b8ad197aSmacallan } 604b8ad197aSmacallan /* now do the aligned pixels in 32bit chunks */ 605b8ad197aSmacallan if (ptr & 3) xf86Msg(X_ERROR, "%s %x\n", __func__, ptr); 606b8ad197aSmacallan while(cnt > 3) { 607b8ad197aSmacallan num = min(32, cnt >> 2); 608b8ad197aSmacallan write_sx_io(p, ptr & ~7, SX_STS(8, num - 1, ptr & 7)); 609b8ad197aSmacallan ptr += num << 2; 610b8ad197aSmacallan cnt -= num << 2; 611b8ad197aSmacallan } 612b8ad197aSmacallan if (cnt > 3) xf86Msg(X_ERROR, "%s cnt %d\n", __func__, cnt); 613b8ad197aSmacallan if (cnt > 0) { 614b8ad197aSmacallan write_sx_io(p, ptr & ~7, SX_STBS(8, cnt - 1, ptr & 7)); 6154261fa58Smacallan } 616b8ad197aSmacallan if ((ptr + cnt) != (start + w)) xf86Msg(X_ERROR, "%s %x vs %x\n", __func__, ptr + cnt, start + w); 617b46cab2aSmacallannext: 6184261fa58Smacallan start += pitch; 6194261fa58Smacallan } 6204261fa58Smacallan } else if (p->last_rop == 0xaa) { 6214261fa58Smacallan /* nothing to do here */ 6224261fa58Smacallan return; 6234261fa58Smacallan } else { 6244261fa58Smacallan /* alright, let's do actual ROP stuff */ 625b8ad197aSmacallan off = start & 7; 626b8ad197aSmacallan start &= ~7; 6274261fa58Smacallan 6284261fa58Smacallan /* first repeat the fill colour into 16 registers */ 6294261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 6304261fa58Smacallan SX_SELECT_S(8, 8, 10, 15)); 6314261fa58Smacallan 6324261fa58Smacallan for (line = 0; line < h; line++) { 6334261fa58Smacallan x = 0; 6344261fa58Smacallan while (x < w) { 6354261fa58Smacallan ptr = start + x; 6364261fa58Smacallan num = min(32, w - x); 6374261fa58Smacallan /* now suck fb data into registers */ 6384261fa58Smacallan write_sx_io(p, ptr, 6394261fa58Smacallan SX_LDB(42, num - 1, off)); 6404261fa58Smacallan /* 6414261fa58Smacallan * ROP them with the fill data we left in 10 6424261fa58Smacallan * non-memory ops can only have counts up to 16 6434261fa58Smacallan */ 6444261fa58Smacallan if (num <= 16) { 6454261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 6464261fa58Smacallan SX_ROP(10, 42, 74, num - 1)); 6474261fa58Smacallan } else { 6484261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 6494261fa58Smacallan SX_ROP(10, 42, 74, 15)); 6504261fa58Smacallan write_sx_reg(p, SX_INSTRUCTIONS, 6514261fa58Smacallan SX_ROP(10, 58, 90, num - 17)); 6524261fa58Smacallan } 6534261fa58Smacallan /* and write the result back into memory */ 6544261fa58Smacallan write_sx_io(p, ptr, 6554261fa58Smacallan SX_STB(74, num - 1, off)); 6564261fa58Smacallan x += 32; 6574261fa58Smacallan } 6584261fa58Smacallan start += pitch; 6594261fa58Smacallan } 6604261fa58Smacallan } 6614261fa58Smacallan} 6624261fa58Smacallan 6634261fa58Smacallanstatic void 6644261fa58SmacallanCG14Solid(PixmapPtr pPixmap, int x1, int y1, int x2, int y2) 6654261fa58Smacallan{ 6664261fa58Smacallan ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; 6674261fa58Smacallan Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn); 6684261fa58Smacallan int w = x2 - x1, h = y2 - y1, dstoff, dstpitch; 6694261fa58Smacallan int start, depth; 6704261fa58Smacallan 6714261fa58Smacallan ENTER; 6724261fa58Smacallan dstpitch = exaGetPixmapPitch(pPixmap); 6734261fa58Smacallan dstoff = exaGetPixmapOffset(pPixmap); 6744261fa58Smacallan 6754261fa58Smacallan depth = pPixmap->drawable.bitsPerPixel; 6764261fa58Smacallan switch (depth) { 6774261fa58Smacallan case 32: 6784261fa58Smacallan start = dstoff + (y1 * dstpitch) + (x1 << 2); 6794261fa58Smacallan CG14Solid32(p, start, dstpitch, w, h); 6804261fa58Smacallan break; 6814261fa58Smacallan case 8: 6824261fa58Smacallan start = dstoff + (y1 * dstpitch) + x1; 6834261fa58Smacallan CG14Solid8(p, start, dstpitch, w, h); 6844261fa58Smacallan break; 6854261fa58Smacallan } 6864261fa58Smacallan 6874261fa58Smacallan DPRINTF(X_ERROR, "Solid %d %d %d %d, %d %d -> %d\n", x1, y1, x2, y2, 6884261fa58Smacallan dstpitch, dstoff, start); 6894261fa58Smacallan DPRINTF(X_ERROR, "%x %x %x\n", p->last_rop, 6904261fa58Smacallan read_sx_reg(p, SX_QUEUED(8)), read_sx_reg(p, SX_QUEUED(9))); 6914261fa58Smacallan exaMarkSync(pPixmap->drawable.pScreen); 6924261fa58Smacallan} 6934261fa58Smacallan 6944261fa58Smacallan/* 6954261fa58Smacallan * Memcpy-based UTS. 6964261fa58Smacallan */ 6974261fa58Smacallanstatic Bool 6984261fa58SmacallanCG14UploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, 6994261fa58Smacallan char *src, int src_pitch) 7004261fa58Smacallan{ 7014261fa58Smacallan ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum]; 7024261fa58Smacallan Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn); 7034261fa58Smacallan char *dst = p->fb + exaGetPixmapOffset(pDst); 7044261fa58Smacallan int dst_pitch = exaGetPixmapPitch(pDst); 7054261fa58Smacallan 7064261fa58Smacallan int bpp = pDst->drawable.bitsPerPixel; 7074261fa58Smacallan int cpp = (bpp + 7) >> 3; 7084261fa58Smacallan int wBytes = w * cpp; 7094261fa58Smacallan 7104261fa58Smacallan ENTER; 711f71acd79Smacallan DPRINTF(X_ERROR, "%s depth %d\n", __func__, bpp); 7124261fa58Smacallan dst += (x * cpp) + (y * dst_pitch); 7134261fa58Smacallan 7144261fa58Smacallan CG14Wait(p); 7154261fa58Smacallan 7164261fa58Smacallan while (h--) { 7174261fa58Smacallan memcpy(dst, src, wBytes); 7184261fa58Smacallan src += src_pitch; 7194261fa58Smacallan dst += dst_pitch; 7204261fa58Smacallan } 7214261fa58Smacallan __asm("stbar;"); 7224261fa58Smacallan return TRUE; 7234261fa58Smacallan} 7244261fa58Smacallan 7254261fa58Smacallan/* 7264261fa58Smacallan * Memcpy-based DFS. 7274261fa58Smacallan */ 7284261fa58Smacallanstatic Bool 7294261fa58SmacallanCG14DownloadFromScreen(PixmapPtr pSrc, int x, int y, int w, int h, 7304261fa58Smacallan char *dst, int dst_pitch) 7314261fa58Smacallan{ 7324261fa58Smacallan ScrnInfoPtr pScrn = xf86Screens[pSrc->drawable.pScreen->myNum]; 7334261fa58Smacallan Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn); 7344261fa58Smacallan char *src = p->fb + exaGetPixmapOffset(pSrc); 7354261fa58Smacallan int src_pitch = exaGetPixmapPitch(pSrc); 7364261fa58Smacallan 7374261fa58Smacallan ENTER; 7384261fa58Smacallan int bpp = pSrc->drawable.bitsPerPixel; 7394261fa58Smacallan int cpp = (bpp + 7) >> 3; 7404261fa58Smacallan int wBytes = w * cpp; 7414261fa58Smacallan 7424261fa58Smacallan src += (x * cpp) + (y * src_pitch); 7434261fa58Smacallan 7444261fa58Smacallan CG14Wait(p); 7454261fa58Smacallan 7464261fa58Smacallan while (h--) { 7474261fa58Smacallan memcpy(dst, src, wBytes); 7484261fa58Smacallan src += src_pitch; 7494261fa58Smacallan dst += dst_pitch; 7504261fa58Smacallan } 7514261fa58Smacallan 7524261fa58Smacallan return TRUE; 7534261fa58Smacallan} 7544261fa58Smacallan 7554261fa58SmacallanBool 7564261fa58SmacallanCG14CheckComposite(int op, PicturePtr pSrcPicture, 7574261fa58Smacallan PicturePtr pMaskPicture, 7584261fa58Smacallan PicturePtr pDstPicture) 7594261fa58Smacallan{ 7604261fa58Smacallan int i, ok = FALSE; 7614261fa58Smacallan 7624261fa58Smacallan ENTER; 7634261fa58Smacallan 7644261fa58Smacallan /* 7654261fa58Smacallan * SX is in theory capable of accelerating pretty much all Xrender ops, 7664261fa58Smacallan * even coordinate transformation and gradients. Support will be added 7674261fa58Smacallan * over time and likely have to spill over into its own source file. 7684261fa58Smacallan */ 7694261fa58Smacallan 770a3a2ba44Smacallan if ((op != PictOpOver) && (op != PictOpAdd) && (op != PictOpSrc)) { 771fe97f391Smacallan DPRINTF(X_ERROR, "%s: rejecting %d\n", __func__, op); 7724261fa58Smacallan return FALSE; 7734261fa58Smacallan } 7744261fa58Smacallan 7754bd47ccfSmacallan if (pSrcPicture != NULL) { 7764bd47ccfSmacallan i = 0; 7774bd47ccfSmacallan while ((i < arraysize(src_formats)) && (!ok)) { 7784bd47ccfSmacallan ok = (pSrcPicture->format == src_formats[i]); 7794bd47ccfSmacallan i++; 7804bd47ccfSmacallan } 7814bd47ccfSmacallan 7824bd47ccfSmacallan if (!ok) { 7834bd47ccfSmacallan DPRINTF(X_ERROR, "%s: unsupported src format %x\n", 7844bd47ccfSmacallan __func__, pSrcPicture->format); 7854bd47ccfSmacallan return FALSE; 7864bd47ccfSmacallan } 7874bd47ccfSmacallan DPRINTF(X_ERROR, "src is %x, %d\n", pSrcPicture->format, op); 7884261fa58Smacallan } 7894261fa58Smacallan 7904bd47ccfSmacallan if (pDstPicture != NULL) { 7914bd47ccfSmacallan i = 0; 7924bd47ccfSmacallan ok = FALSE; 7934bd47ccfSmacallan while ((i < arraysize(src_formats)) && (!ok)) { 7944bd47ccfSmacallan ok = (pDstPicture->format == src_formats[i]); 7954bd47ccfSmacallan i++; 7964bd47ccfSmacallan } 7974bd47ccfSmacallan 7984bd47ccfSmacallan if (!ok) { 7994bd47ccfSmacallan DPRINTF(X_ERROR, "%s: unsupported dst format %x\n", 8004bd47ccfSmacallan __func__, pDstPicture->format); 8014bd47ccfSmacallan return FALSE; 8024bd47ccfSmacallan } 8034bd47ccfSmacallan DPRINTF(X_ERROR, "dst is %x, %d\n", pDstPicture->format, op); 8044bd47ccfSmacallan } 8054261fa58Smacallan 8064261fa58Smacallan if (pMaskPicture != NULL) { 8074261fa58Smacallan DPRINTF(X_ERROR, "mask is %x %d %d\n", pMaskPicture->format, 8084261fa58Smacallan pMaskPicture->pDrawable->width, 8094261fa58Smacallan pMaskPicture->pDrawable->height); 8104261fa58Smacallan } 8114261fa58Smacallan return TRUE; 8124261fa58Smacallan} 8134261fa58Smacallan 8144261fa58SmacallanBool 8154261fa58SmacallanCG14PrepareComposite(int op, PicturePtr pSrcPicture, 8164261fa58Smacallan PicturePtr pMaskPicture, 8174261fa58Smacallan PicturePtr pDstPicture, 8184261fa58Smacallan PixmapPtr pSrc, 8194261fa58Smacallan PixmapPtr pMask, 8204261fa58Smacallan PixmapPtr pDst) 8214261fa58Smacallan{ 8224261fa58Smacallan ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum]; 8234261fa58Smacallan Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn); 8244261fa58Smacallan 8254261fa58Smacallan ENTER; 8264261fa58Smacallan 827f7cb851fSmacallan p->no_source_pixmap = FALSE; 828f7cb851fSmacallan p->source_is_solid = FALSE; 829f7cb851fSmacallan 830a3a2ba44Smacallan if (pSrcPicture->format == PICT_a1) { 8316bdc2ffdSmacallan xf86Msg(X_ERROR, "src mono, dst %x, op %d\n", 8326bdc2ffdSmacallan pDstPicture->format, op); 833a3a2ba44Smacallan if (pMaskPicture != NULL) { 834a3a2ba44Smacallan xf86Msg(X_ERROR, "msk %x\n", pMaskPicture->format); 835a3a2ba44Smacallan } 836f7cb851fSmacallan } 8374261fa58Smacallan if (pSrcPicture->pSourcePict != NULL) { 8384261fa58Smacallan if (pSrcPicture->pSourcePict->type == SourcePictTypeSolidFill) { 8394261fa58Smacallan p->fillcolour = 8404261fa58Smacallan pSrcPicture->pSourcePict->solidFill.color; 841f7cb851fSmacallan DPRINTF(X_ERROR, "%s: solid src %08x\n", 8424261fa58Smacallan __func__, p->fillcolour); 843f7cb851fSmacallan p->no_source_pixmap = TRUE; 844f7cb851fSmacallan p->source_is_solid = TRUE; 8454261fa58Smacallan } 8464261fa58Smacallan } 8474261fa58Smacallan if ((pMaskPicture != NULL) && (pMaskPicture->pSourcePict != NULL)) { 8484261fa58Smacallan if (pMaskPicture->pSourcePict->type == 8494261fa58Smacallan SourcePictTypeSolidFill) { 8504261fa58Smacallan p->fillcolour = 8514261fa58Smacallan pMaskPicture->pSourcePict->solidFill.color; 852a3a2ba44Smacallan xf86Msg(X_ERROR, "%s: solid mask %08x\n", 8534261fa58Smacallan __func__, p->fillcolour); 8544261fa58Smacallan } 8554261fa58Smacallan } 8564261fa58Smacallan if (pMaskPicture != NULL) { 857239808baSmacallan p->mskoff = exaGetPixmapOffset(pMask); 8584261fa58Smacallan p->mskpitch = exaGetPixmapPitch(pMask); 8594261fa58Smacallan p->mskformat = pMaskPicture->format; 860a3a2ba44Smacallan } else { 861239808baSmacallan p->mskoff = 0; 862a3a2ba44Smacallan p->mskpitch = 0; 863a3a2ba44Smacallan p->mskformat = 0; 8644261fa58Smacallan } 865f7cb851fSmacallan if (pSrc != NULL) { 866f7cb851fSmacallan p->source_is_solid = 867f7cb851fSmacallan ((pSrc->drawable.width == 1) && (pSrc->drawable.height == 1)); 868f7cb851fSmacallan p->srcoff = exaGetPixmapOffset(pSrc); 869f7cb851fSmacallan p->srcpitch = exaGetPixmapPitch(pSrc); 870f7cb851fSmacallan if (p->source_is_solid) { 871f7cb851fSmacallan p->fillcolour = *(uint32_t *)(p->fb + p->srcoff); 872f7cb851fSmacallan } 873f7cb851fSmacallan } 8744261fa58Smacallan p->srcformat = pSrcPicture->format; 8754261fa58Smacallan p->dstformat = pDstPicture->format; 876f7cb851fSmacallan 877f7cb851fSmacallan if (p->source_is_solid) { 878f7cb851fSmacallan uint32_t temp; 879f7cb851fSmacallan 880f7cb851fSmacallan /* stuff source colour into SX registers, swap as needed */ 881f7cb851fSmacallan temp = p->fillcolour; 882f7cb851fSmacallan switch (p->srcformat) { 883f7cb851fSmacallan case PICT_a8r8g8b8: 884f7cb851fSmacallan case PICT_x8r8g8b8: 885f7cb851fSmacallan write_sx_reg(p, SX_QUEUED(9), temp & 0xff); 886f7cb851fSmacallan temp = temp >> 8; 887f7cb851fSmacallan write_sx_reg(p, SX_QUEUED(10), temp & 0xff); 888f7cb851fSmacallan temp = temp >> 8; 889f7cb851fSmacallan write_sx_reg(p, SX_QUEUED(11), temp & 0xff); 890f7cb851fSmacallan break; 891f7cb851fSmacallan case PICT_a8b8g8r8: 892f7cb851fSmacallan case PICT_x8b8g8r8: 893f7cb851fSmacallan write_sx_reg(p, SX_QUEUED(11), temp & 0xff); 894f7cb851fSmacallan temp = temp >> 8; 895f7cb851fSmacallan write_sx_reg(p, SX_QUEUED(10), temp & 0xff); 896f7cb851fSmacallan temp = temp >> 8; 897f7cb851fSmacallan write_sx_reg(p, SX_QUEUED(9), temp & 0xff); 898f7cb851fSmacallan break; 899f7cb851fSmacallan } 900f7cb851fSmacallan write_sx_reg(p, SX_QUEUED(8), 0xff); 901f7cb851fSmacallan } 9024261fa58Smacallan p->op = op; 903a3a2ba44Smacallan if (op == PictOpSrc) { 904a3a2ba44Smacallan CG14PrepareCopy(pSrc, pDst, 1, 1, GXcopy, 0xffffffff); 905a3a2ba44Smacallan } 9064261fa58Smacallan#ifdef SX_DEBUG 9074261fa58Smacallan DPRINTF(X_ERROR, "%x %x -> %x\n", p->srcoff, p->mskoff, 9084261fa58Smacallan *(uint32_t *)(p->fb + p->srcoff)); 9094261fa58Smacallan#endif 9104261fa58Smacallan return TRUE; 9114261fa58Smacallan} 9124261fa58Smacallan 9134261fa58Smacallanvoid 9144261fa58SmacallanCG14Composite(PixmapPtr pDst, int srcX, int srcY, 9154261fa58Smacallan int maskX, int maskY, 9164261fa58Smacallan int dstX, int dstY, 9174261fa58Smacallan int width, int height) 9184261fa58Smacallan{ 9194261fa58Smacallan ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum]; 9204261fa58Smacallan Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn); 9214261fa58Smacallan uint32_t dstoff, dstpitch; 9224261fa58Smacallan uint32_t dst, msk, src; 923e311bbeeSmacallan int flip = 0; 9244261fa58Smacallan 9254261fa58Smacallan ENTER; 9264261fa58Smacallan dstoff = exaGetPixmapOffset(pDst); 9274261fa58Smacallan dstpitch = exaGetPixmapPitch(pDst); 9284261fa58Smacallan 929e311bbeeSmacallan flip = (PICT_FORMAT_TYPE(p->srcformat) != 930e311bbeeSmacallan PICT_FORMAT_TYPE(p->dstformat)); 931e311bbeeSmacallan 9324261fa58Smacallan switch (p->op) { 9334261fa58Smacallan case PictOpOver: 9344261fa58Smacallan dst = dstoff + (dstY * dstpitch) + (dstX << 2); 9354261fa58Smacallan DPRINTF(X_ERROR, "Over %08x %08x, %d %d\n", 9364261fa58Smacallan p->mskformat, p->dstformat, srcX, srcY); 937a3a2ba44Smacallan if (p->source_is_solid) { 938a3a2ba44Smacallan switch (p->mskformat) { 939a3a2ba44Smacallan case PICT_a8: 940a3a2ba44Smacallan msk = p->mskoff + 941a3a2ba44Smacallan (maskY * p->mskpitch) + 942a3a2ba44Smacallan maskX; 943a3a2ba44Smacallan CG14Comp_Over8Solid(p, 944a3a2ba44Smacallan msk, p->mskpitch, 945a3a2ba44Smacallan dst, dstpitch, 946a3a2ba44Smacallan width, height); 947a3a2ba44Smacallan break; 948a3a2ba44Smacallan case PICT_a8r8g8b8: 949a3a2ba44Smacallan case PICT_a8b8g8r8: 950a3a2ba44Smacallan msk = p->mskoff + 951a3a2ba44Smacallan (maskY * p->mskpitch) + 952a3a2ba44Smacallan (maskX << 2); 953a3a2ba44Smacallan CG14Comp_Over32Solid(p, 954a3a2ba44Smacallan msk, p->mskpitch, 955a3a2ba44Smacallan dst, dstpitch, 956a3a2ba44Smacallan width, height); 957a3a2ba44Smacallan break; 958a3a2ba44Smacallan default: 959a3a2ba44Smacallan xf86Msg(X_ERROR, 960f71acd79Smacallan "unsupported mask format %08x\n", p->mskformat); 961a3a2ba44Smacallan } 962a3a2ba44Smacallan } else { 9636bdc2ffdSmacallan DPRINTF(X_ERROR, "non-solid over with msk %x\n", 9646bdc2ffdSmacallan p->mskformat); 965a3a2ba44Smacallan switch (p->srcformat) { 966a3a2ba44Smacallan case PICT_a8r8g8b8: 967a3a2ba44Smacallan case PICT_a8b8g8r8: 968a3a2ba44Smacallan src = p->srcoff + 969a3a2ba44Smacallan (srcY * p->srcpitch) + 970a3a2ba44Smacallan (srcX << 2); 971a3a2ba44Smacallan dst = dstoff + 972a3a2ba44Smacallan (dstY * dstpitch) + 973a3a2ba44Smacallan (dstX << 2); 974a3a2ba44Smacallan if (p->mskformat == PICT_a8) { 975a3a2ba44Smacallan msk = p->mskoff + 976a3a2ba44Smacallan (maskY * p->mskpitch) + 977a3a2ba44Smacallan maskX; 978a3a2ba44Smacallan CG14Comp_Over32Mask(p, 979a3a2ba44Smacallan src, p->srcpitch, 980a3a2ba44Smacallan msk, p->mskpitch, 981a3a2ba44Smacallan dst, dstpitch, 982e311bbeeSmacallan width, height, flip); 983a3a2ba44Smacallan } else { 984a3a2ba44Smacallan CG14Comp_Over32(p, 985a3a2ba44Smacallan src, p->srcpitch, 986a3a2ba44Smacallan dst, dstpitch, 987e311bbeeSmacallan width, height, flip); 988a3a2ba44Smacallan } 989a3a2ba44Smacallan break; 990a3a2ba44Smacallan case PICT_x8r8g8b8: 991a3a2ba44Smacallan case PICT_x8b8g8r8: 9926bdc2ffdSmacallan src = p->srcoff + 9936bdc2ffdSmacallan (srcY * p->srcpitch) + 9946bdc2ffdSmacallan (srcX << 2); 9956bdc2ffdSmacallan dst = dstoff + 9966bdc2ffdSmacallan (dstY * dstpitch) + 9976bdc2ffdSmacallan (dstX << 2); 9986bdc2ffdSmacallan if (p->mskformat == PICT_a8) { 9996bdc2ffdSmacallan msk = p->mskoff + 10006bdc2ffdSmacallan (maskY * p->mskpitch) + 10016bdc2ffdSmacallan maskX; 10026bdc2ffdSmacallan CG14Comp_Over32Mask_noalpha(p, 10036bdc2ffdSmacallan src, p->srcpitch, 10046bdc2ffdSmacallan msk, p->mskpitch, 1005fa158432Smacallan dst, dstpitch, 1006e311bbeeSmacallan width, height, flip); 1007fa158432Smacallan } else if ((p->mskformat == PICT_a8r8g8b8) || 1008fa158432Smacallan (p->mskformat == PICT_a8b8g8r8)) { 1009fa158432Smacallan msk = p->mskoff + 1010fa158432Smacallan (maskY * p->mskpitch) + 1011fa158432Smacallan (maskX << 2); 1012fa158432Smacallan CG14Comp_Over32Mask32_noalpha(p, 1013fa158432Smacallan src, p->srcpitch, 1014fa158432Smacallan msk, p->mskpitch, 10156bdc2ffdSmacallan dst, dstpitch, 1016e311bbeeSmacallan width, height, flip); 10176bdc2ffdSmacallan } else { 10186bdc2ffdSmacallan xf86Msg(X_ERROR, "no src alpha, mask is %x\n", p->mskformat); 10196bdc2ffdSmacallan } 1020a3a2ba44Smacallan break; 1021a3a2ba44Smacallan default: 1022a3a2ba44Smacallan xf86Msg(X_ERROR, "%s: format %x in non-solid Over op\n", 1023a3a2ba44Smacallan __func__, p->srcformat); 1024a3a2ba44Smacallan } 1025a3a2ba44Smacallan } 10264261fa58Smacallan break; 10274261fa58Smacallan case PictOpAdd: 10284261fa58Smacallan DPRINTF(X_ERROR, "Add %08x %08x\n", 10294261fa58Smacallan p->srcformat, p->dstformat); 10304261fa58Smacallan switch (p->srcformat) { 10314261fa58Smacallan case PICT_a8: 10324261fa58Smacallan src = p->srcoff + 10334261fa58Smacallan (srcY * p->srcpitch) + srcX; 1034d71cb32dSmacallan if (p->dstformat == PICT_a8) { 1035d71cb32dSmacallan dst = dstoff + 1036d71cb32dSmacallan (dstY * dstpitch) + dstX; 1037d71cb32dSmacallan CG14Comp_Add8(p, 1038d71cb32dSmacallan src, p->srcpitch, 1039d71cb32dSmacallan dst, dstpitch, 1040d71cb32dSmacallan width, height); 1041d71cb32dSmacallan } else { 1042d71cb32dSmacallan dst = dstoff + 1043d71cb32dSmacallan (dstY * dstpitch) + 1044d71cb32dSmacallan (dstX << 2); 1045d71cb32dSmacallan CG14Comp_Add8_32(p, 1046d71cb32dSmacallan src, p->srcpitch, 1047d71cb32dSmacallan dst, dstpitch, 1048d71cb32dSmacallan width, height); 1049d71cb32dSmacallan } 10504261fa58Smacallan break; 10514261fa58Smacallan case PICT_a8r8g8b8: 10524261fa58Smacallan case PICT_x8r8g8b8: 10534261fa58Smacallan src = p->srcoff + 10544261fa58Smacallan (srcY * p->srcpitch) + (srcX << 2); 10554261fa58Smacallan dst = dstoff + (dstY * dstpitch) + 10564261fa58Smacallan (dstX << 2); 10574261fa58Smacallan CG14Comp_Add32(p, src, p->srcpitch, 10584261fa58Smacallan dst, dstpitch, width, height); 10594261fa58Smacallan break; 10604261fa58Smacallan default: 10614261fa58Smacallan xf86Msg(X_ERROR, 10624261fa58Smacallan "unsupported src format\n"); 10634261fa58Smacallan } 10644261fa58Smacallan break; 1065a3a2ba44Smacallan case PictOpSrc: 1066a3a2ba44Smacallan DPRINTF(X_ERROR, "Src %08x %08x\n", 1067a3a2ba44Smacallan p->srcformat, p->dstformat); 1068239808baSmacallan if (p->mskformat != 0) 1069239808baSmacallan xf86Msg(X_ERROR, "Src mask %08x\n", p->mskformat); 1070f71acd79Smacallan if (p->srcformat == PICT_a8) { 1071f71acd79Smacallan CG14Copy8(pDst, srcX, srcY, dstX, dstY, width, height); 1072f71acd79Smacallan } else { 1073f71acd79Smacallan /* convert between RGB and BGR? */ 1074f71acd79Smacallan CG14Copy32(pDst, srcX, srcY, dstX, dstY, width, height); 1075f71acd79Smacallan } 1076a3a2ba44Smacallan break; 10774261fa58Smacallan default: 10784261fa58Smacallan xf86Msg(X_ERROR, "unsupported op %d\n", p->op); 10794261fa58Smacallan } 10804261fa58Smacallan exaMarkSync(pDst->drawable.pScreen); 10814261fa58Smacallan} 10824261fa58Smacallan 10834261fa58Smacallan 10844261fa58Smacallan 10854261fa58SmacallanBool 10864261fa58SmacallanCG14InitAccel(ScreenPtr pScreen) 10874261fa58Smacallan{ 10884261fa58Smacallan ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 10894261fa58Smacallan Cg14Ptr p = GET_CG14_FROM_SCRN(pScrn); 10904261fa58Smacallan ExaDriverPtr pExa; 10914261fa58Smacallan 10924261fa58Smacallan pExa = exaDriverAlloc(); 10934261fa58Smacallan if (!pExa) 10944261fa58Smacallan return FALSE; 10954261fa58Smacallan 10964261fa58Smacallan p->pExa = pExa; 10974261fa58Smacallan 10984261fa58Smacallan pExa->exa_major = EXA_VERSION_MAJOR; 10994261fa58Smacallan pExa->exa_minor = EXA_VERSION_MINOR; 11004261fa58Smacallan 11014261fa58Smacallan pExa->memoryBase = p->fb; 11024261fa58Smacallan pExa->memorySize = p->memsize; 1103b8ad197aSmacallan pExa->offScreenBase = p->width * p->height * (pScrn->depth >> 3); 11044261fa58Smacallan 11054261fa58Smacallan /* 11064261fa58Smacallan * SX memory instructions are written to 64bit aligned addresses with 11074261fa58Smacallan * a 3 bit displacement. Make sure the displacement remains constant 11084261fa58Smacallan * within one column 11094261fa58Smacallan */ 11104261fa58Smacallan 11114261fa58Smacallan pExa->pixmapOffsetAlign = 8; 11124261fa58Smacallan pExa->pixmapPitchAlign = 8; 11134261fa58Smacallan 1114fe97f391Smacallan pExa->flags = EXA_OFFSCREEN_PIXMAPS 1115f71acd79Smacallan | EXA_SUPPORTS_OFFSCREEN_OVERLAPS 1116f71acd79Smacallan /*| EXA_MIXED_PIXMAPS*/; 11174261fa58Smacallan 11184261fa58Smacallan /* 11194261fa58Smacallan * these limits are bogus 11204261fa58Smacallan * SX doesn't deal with coordinates at all, so there is no limit but 11214261fa58Smacallan * we have to put something here 11224261fa58Smacallan */ 11234261fa58Smacallan pExa->maxX = 4096; 11244261fa58Smacallan pExa->maxY = 4096; 11254261fa58Smacallan 11264261fa58Smacallan pExa->WaitMarker = CG14WaitMarker; 11274261fa58Smacallan 11284261fa58Smacallan pExa->PrepareSolid = CG14PrepareSolid; 11294261fa58Smacallan pExa->Solid = CG14Solid; 11304261fa58Smacallan pExa->DoneSolid = CG14DoneCopy; 11314261fa58Smacallan pExa->PrepareCopy = CG14PrepareCopy; 1132f71acd79Smacallan pExa->Copy = CG14Copy32; 11334261fa58Smacallan pExa->DoneCopy = CG14DoneCopy; 11344261fa58Smacallan if (p->use_xrender) { 11354261fa58Smacallan pExa->CheckComposite = CG14CheckComposite; 11364261fa58Smacallan pExa->PrepareComposite = CG14PrepareComposite; 11374261fa58Smacallan pExa->Composite = CG14Composite; 11384261fa58Smacallan pExa->DoneComposite = CG14DoneCopy; 11394261fa58Smacallan } 11404261fa58Smacallan 11414261fa58Smacallan /* EXA hits more optimized paths when it does not have to fallback 11424261fa58Smacallan * because of missing UTS/DFS, hook memcpy-based UTS/DFS. 11434261fa58Smacallan */ 11444261fa58Smacallan pExa->UploadToScreen = CG14UploadToScreen; 11454261fa58Smacallan pExa->DownloadFromScreen = CG14DownloadFromScreen; 11464261fa58Smacallan 1147c2193d98Smacallan p->queuecount = 0; 11484261fa58Smacallan /* do some hardware init */ 11494261fa58Smacallan write_sx_reg(p, SX_PLANEMASK, 0xffffffff); 11504261fa58Smacallan p->last_mask = 0xffffffff; 11514261fa58Smacallan write_sx_reg(p, SX_ROP_CONTROL, 0xcc); 11524261fa58Smacallan p->last_rop = 0xcc; 11534261fa58Smacallan return exaDriverInit(pScreen, pExa); 11544261fa58Smacallan} 1155