cg6_exa.c revision 777a60cd
1/* 2 * Sun GX and Turbo GX EXA support 3 * 4 * Copyright (C) 2015 Michael Lorenz 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 * copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * MICHAEL LORENZ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/suncg6/cg6_exa.c $ */ 24 25#ifdef HAVE_CONFIG_H 26#include "config.h" 27#endif 28 29#include "cg6.h" 30#include "cg6_regs.h" 31 32 33static CARD32 Cg6BlitROP[] = { 34 ROP_BLIT(GX_ROP_CLEAR, GX_ROP_CLEAR), /* GXclear */ 35 ROP_BLIT(GX_ROP_CLEAR, GX_ROP_NOOP), /* GXand */ 36 ROP_BLIT(GX_ROP_CLEAR, GX_ROP_INVERT), /* GXandReverse */ 37 ROP_BLIT(GX_ROP_CLEAR, GX_ROP_SET), /* GXcopy */ 38 ROP_BLIT(GX_ROP_NOOP, GX_ROP_CLEAR), /* GXandInverted */ 39 ROP_BLIT(GX_ROP_NOOP, GX_ROP_NOOP), /* GXnoop */ 40 ROP_BLIT(GX_ROP_NOOP, GX_ROP_INVERT), /* GXxor */ 41 ROP_BLIT(GX_ROP_NOOP, GX_ROP_SET), /* GXor */ 42 ROP_BLIT(GX_ROP_INVERT, GX_ROP_CLEAR), /* GXnor */ 43 ROP_BLIT(GX_ROP_INVERT, GX_ROP_NOOP), /* GXequiv */ 44 ROP_BLIT(GX_ROP_INVERT, GX_ROP_INVERT), /* GXinvert */ 45 ROP_BLIT(GX_ROP_INVERT, GX_ROP_SET), /* GXorReverse */ 46 ROP_BLIT(GX_ROP_SET, GX_ROP_CLEAR), /* GXcopyInverted */ 47 ROP_BLIT(GX_ROP_SET, GX_ROP_NOOP), /* GXorInverted */ 48 ROP_BLIT(GX_ROP_SET, GX_ROP_INVERT), /* GXnand */ 49 ROP_BLIT(GX_ROP_SET, GX_ROP_SET), /* GXset */ 50}; 51 52static CARD32 Cg6DrawROP[] = { 53 ROP_FILL(GX_ROP_CLEAR, GX_ROP_CLEAR), /* GXclear */ 54 ROP_FILL(GX_ROP_CLEAR, GX_ROP_NOOP), /* GXand */ 55 ROP_FILL(GX_ROP_CLEAR, GX_ROP_INVERT), /* GXandReverse */ 56 ROP_FILL(GX_ROP_CLEAR, GX_ROP_SET), /* GXcopy */ 57 ROP_FILL(GX_ROP_NOOP, GX_ROP_CLEAR), /* GXandInverted */ 58 ROP_FILL(GX_ROP_NOOP, GX_ROP_NOOP), /* GXnoop */ 59 ROP_FILL(GX_ROP_NOOP, GX_ROP_INVERT), /* GXxor */ 60 ROP_FILL(GX_ROP_NOOP, GX_ROP_SET), /* GXor */ 61 ROP_FILL(GX_ROP_INVERT, GX_ROP_CLEAR), /* GXnor */ 62 ROP_FILL(GX_ROP_INVERT, GX_ROP_NOOP), /* GXequiv */ 63 ROP_FILL(GX_ROP_INVERT, GX_ROP_INVERT), /* GXinvert */ 64 ROP_FILL(GX_ROP_INVERT, GX_ROP_SET), /* GXorReverse */ 65 ROP_FILL(GX_ROP_SET, GX_ROP_CLEAR), /* GXcopyInverted */ 66 ROP_FILL(GX_ROP_SET, GX_ROP_NOOP), /* GXorInverted */ 67 ROP_FILL(GX_ROP_SET, GX_ROP_INVERT), /* GXnand */ 68 ROP_FILL(GX_ROP_SET, GX_ROP_SET), /* GXset */ 69}; 70 71#define runDraw(pCg6) { volatile CARD32 rubbish = pCg6->fbc->draw; } 72#define runBlit(pCg6) { volatile CARD32 rubbish = pCg6->fbc->blit; } 73 74/* 75 * XXX 76 * was GX_FULL, which apparently isn't enough on some (slower) CG6 like 77 * the one found on the SPARCstation LX mainboard 78 */ 79#define waitReady(pCg6) while(pCg6->fbc->s & GX_INPROGRESS) 80 81void Cg6InitEngine(Cg6Ptr); 82 83static void 84Cg6WaitMarker(ScreenPtr pScreen, int Marker) 85{ 86 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 87 Cg6Ptr p = GET_CG6_FROM_SCRN(pScrn); 88 89 waitReady(p); 90} 91 92static Bool 93Cg6PrepareCopy 94( 95 PixmapPtr pSrcPixmap, 96 PixmapPtr pDstPixmap, 97 int xdir, 98 int ydir, 99 int alu, 100 Pixel planemask 101) 102{ 103 ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum]; 104 Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn); 105 106 waitReady(pCg6); 107 108 pCg6->fbc->mode = GX_BLIT_SRC | 109 GX_MODE_COLOR8 | 110 GX_DRAW_RENDER | 111 GX_BWRITE0_ENABLE | 112 GX_BWRITE1_DISABLE | 113 GX_BREAD_0 | 114 GX_BDISP_0; 115 116 /* we probably don't need the following three */ 117 pCg6->fbc->fg = 0xff; 118 pCg6->fbc->bg = 0x00; 119 pCg6->fbc->s = 0; 120 121 pCg6->srcoff = exaGetPixmapOffset(pSrcPixmap) / pCg6->width; 122 pCg6->fbc->alu = Cg6BlitROP[alu]; 123 pCg6->fbc->pm = planemask; 124 return TRUE; 125} 126 127static void 128Cg6Copy 129( 130 PixmapPtr pDstPixmap, 131 int xSrc, 132 int ySrc, 133 int xDst, 134 int yDst, 135 int w, 136 int h 137) 138{ 139 ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum]; 140 Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn); 141 int doff; 142 143 doff = exaGetPixmapOffset(pDstPixmap) / pCg6->width; 144 waitReady(pCg6); 145 pCg6->fbc->x0 = xSrc; 146 pCg6->fbc->y0 = ySrc + pCg6->srcoff; 147 pCg6->fbc->x1 = xSrc + w - 1; 148 pCg6->fbc->y1 = ySrc + pCg6->srcoff + h - 1; 149 pCg6->fbc->x2 = xDst; 150 pCg6->fbc->y2 = yDst + doff; 151 pCg6->fbc->x3 = xDst + w - 1; 152 pCg6->fbc->y3 = yDst + doff + h - 1; 153 runBlit(pCg6); 154 exaMarkSync(pDstPixmap->drawable.pScreen); 155} 156 157static void 158Cg6DoneCopy(PixmapPtr pDstPixmap) 159{ 160 ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum]; 161 Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn); 162 163 waitReady(pCg6); 164} 165 166static Bool 167Cg6PrepareSolid( 168 PixmapPtr pPixmap, 169 int alu, 170 Pixel planemask, 171 Pixel fg) 172{ 173 ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; 174 Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn); 175 CARD32 c2; 176 177 pCg6->srcoff = exaGetPixmapOffset(pPixmap) / pCg6->width; 178 179 waitReady(pCg6); 180 181 pCg6->fbc->mode = GX_BLIT_SRC | 182 GX_MODE_COLOR8 | 183 GX_DRAW_RENDER | 184 GX_BWRITE0_ENABLE | 185 GX_BWRITE1_DISABLE | 186 GX_BREAD_0 | 187 GX_BDISP_0; 188 pCg6->fbc->fg = fg; 189 pCg6->fbc->s = 0; 190 pCg6->fbc->alu = Cg6DrawROP[alu]; 191 pCg6->fbc->pm = planemask; 192 return TRUE; 193} 194 195static void 196Cg6Solid( 197 PixmapPtr pPixmap, 198 int x, 199 int y, 200 int x2, 201 int y2) 202{ 203 ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; 204 Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn); 205 206 waitReady(pCg6); 207 pCg6->fbc->arecty = y + pCg6->srcoff; 208 pCg6->fbc->arectx = x; 209 pCg6->fbc->rrecty = y2 - y - 1; 210 pCg6->fbc->rrectx = x2 - x - 1; 211 runDraw(pCg6); 212 exaMarkSync(pPixmap->drawable.pScreen); 213} 214 215/* 216 * UTS using host blits 217 */ 218static Bool 219Cg6UploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, 220 char *src, int src_pitch) 221{ 222 ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum]; 223 Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn); 224 uint32_t *sline; 225 int dst_pitch = exaGetPixmapPitch(pDst); 226 int dst_line = y + exaGetPixmapOffset(pDst) / pCg6->width; 227 int i, bits; 228 int words = (w + 3) >> 2; 229 230 /* clip to the destination */ 231 pCg6->fbc->clipmaxx = x + w - 1; 232 pCg6->fbc->clipminx = x; 233 234 /* see if the source is aligned, if not adjust */ 235 bits = ((long)src) & 3; 236 if (bits != 0) { 237 src -= bits; 238 w += bits; 239 words = (w + 3) >> 2; 240 x -= bits; 241 } 242 243 /* we assume that source pitch is always a multiple of 4 */ 244 if ((src_pitch & 3) != 0) 245 xf86Msg(X_ERROR, "pitch %d\n", src_pitch); 246 waitReady(pCg6); 247 248 pCg6->fbc->mode = GX_BLIT_NOSRC | 249 GX_MODE_COLOR8 | 250 GX_DRAW_RENDER | 251 GX_BWRITE0_ENABLE | 252 GX_BWRITE1_DISABLE | 253 GX_BREAD_0 | 254 GX_BDISP_0; 255 256 pCg6->fbc->alu = Cg6BlitROP[GXcopy]; 257 pCg6->fbc->pm = 0xffffffff; 258 pCg6->fbc->incx = 4; 259 pCg6->fbc->incy = 0; 260 while (h--) { 261 pCg6->fbc->x0 = x; 262 pCg6->fbc->x1 = x + 3; 263 pCg6->fbc->y0 = dst_line; 264 sline = (uint32_t *)src; 265 for (i = 0; i < words; i++) { 266 pCg6->fbc->font = *sline; 267 sline++; 268 } 269 src += src_pitch; 270 dst_line++; 271 } 272 pCg6->fbc->clipmaxx = 4096; 273 pCg6->fbc->clipminx = 0; 274 exaMarkSync(pDst->drawable.pScreen); 275 return TRUE; 276} 277 278/* 279 * Memcpy-based DFS. 280 */ 281static Bool 282Cg6DownloadFromScreen(PixmapPtr pSrc, int x, int y, int w, int h, 283 char *dst, int dst_pitch) 284{ 285 ScrnInfoPtr pScrn = xf86Screens[pSrc->drawable.pScreen->myNum]; 286 Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn); 287 uint8_t *src = pCg6->fb + exaGetPixmapOffset(pSrc); 288 int src_pitch = exaGetPixmapPitch(pSrc); 289 290 src += x + (y * src_pitch); 291 292 while (h > 0) { 293 memcpy(dst, src, w); 294 src += src_pitch; 295 dst += dst_pitch; 296 h--; 297 } 298 return TRUE; 299} 300 301int 302CG6EXAInit(ScreenPtr pScreen) 303{ 304 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 305 Cg6Ptr pCg6 = GET_CG6_FROM_SCRN(pScrn); 306 ExaDriverPtr pExa; 307 308 Cg6InitEngine(pCg6); 309 310 pExa = exaDriverAlloc(); 311 if (!pExa) 312 return FALSE; 313 314 pCg6->pExa = pExa; 315 316 pExa->exa_major = EXA_VERSION_MAJOR; 317 pExa->exa_minor = EXA_VERSION_MINOR; 318 319 pExa->memoryBase = pCg6->fb; 320 321 /* round to multiple of pixmap pitch */ 322 pExa->memorySize = (pCg6->vidmem / pCg6->width) * pCg6->width; 323 pExa->offScreenBase = pCg6->width * pCg6->height; 324 325 /* 326 * our blitter can't deal with variable pitches 327 */ 328 pExa->pixmapOffsetAlign = pCg6->width; 329 pExa->pixmapPitchAlign = pCg6->width; 330 331 pExa->flags = EXA_OFFSCREEN_PIXMAPS | 332 EXA_MIXED_PIXMAPS; 333 334 pExa->maxX = 4096; 335 pExa->maxY = 4096; 336 337 pExa->WaitMarker = Cg6WaitMarker; 338 339 pExa->PrepareSolid = Cg6PrepareSolid; 340 pExa->Solid = Cg6Solid; 341 pExa->DoneSolid = Cg6DoneCopy; 342 343 pExa->PrepareCopy = Cg6PrepareCopy; 344 pExa->Copy = Cg6Copy; 345 pExa->DoneCopy = Cg6DoneCopy; 346 347 pExa->UploadToScreen = Cg6UploadToScreen; 348 pExa->DownloadFromScreen = Cg6DownloadFromScreen; 349 350 return exaDriverInit(pScreen, pExa);; 351} 352