1/* 2 * XGI 300/630/730/540/315/550/650/740 frame buffer driver 3 * for Linux kernels 2.4.x and 2.5.x 4 * 5 * 2D acceleration part 6 * 7 * Based on the X driver's XGI300_accel.c which is 8 * Copyright Xavier Ducoin <x.ducoin@lectra.com> 9 * Copyright 2002 by Thomas Winischhofer, Vienna, Austria 10 * and XGI310_accel.c which is 11 * Copyright 2002 by Thomas Winischhofer, Vienna, Austria 12 * 13 * Author: Thomas Winischhofer <thomas@winischhofer.net> 14 * (see http://www.winischhofer.net/ 15 * for more information and updates) 16 */ 17 18//#include <linux/config.h> 19#include <linux/version.h> 20#include <linux/module.h> 21#include <linux/kernel.h> 22#include <linux/errno.h> 23#include <linux/string.h> 24#include <linux/mm.h> 25#include <linux/tty.h> 26#include <linux/slab.h> 27#include <linux/delay.h> 28#include <linux/fb.h> 29#include <linux/console.h> 30#include <linux/selection.h> 31#include <linux/ioport.h> 32#include <linux/init.h> 33#include <linux/pci.h> 34#include <linux/vt_kern.h> 35#include <linux/capability.h> 36#include <linux/fs.h> 37#include <linux/agp_backend.h> 38 39#include <linux/types.h> 40#include <asm/io.h> 41 42#ifdef CONFIG_MTRR 43#include <asm/mtrr.h> 44#endif 45 46#include "vgatypes.h" 47#include "vb_struct.h" 48#include "XGIfb.h" 49#include "XGI_accel.h" 50 51static const int XGIALUConv[] = 52{ 53 0x00, /* dest = 0; 0, GXclear, 0 */ 54 0x88, /* dest &= src; DSa, GXand, 0x1 */ 55 0x44, /* dest = src & ~dest; SDna, GXandReverse, 0x2 */ 56 0xCC, /* dest = src; S, GXcopy, 0x3 */ 57 0x22, /* dest &= ~src; DSna, GXandInverted, 0x4 */ 58 0xAA, /* dest = dest; D, GXnoop, 0x5 */ 59 0x66, /* dest = ^src; DSx, GXxor, 0x6 */ 60 0xEE, /* dest |= src; DSo, GXor, 0x7 */ 61 0x11, /* dest = ~src & ~dest; DSon, GXnor, 0x8 */ 62 0x99, /* dest ^= ~src ; DSxn, GXequiv, 0x9 */ 63 0x55, /* dest = ~dest; Dn, GXInvert, 0xA */ 64 0xDD, /* dest = src|~dest ; SDno, GXorReverse, 0xB */ 65 0x33, /* dest = ~src; Sn, GXcopyInverted, 0xC */ 66 0xBB, /* dest |= ~src; DSno, GXorInverted, 0xD */ 67 0x77, /* dest = ~src|~dest; DSan, GXnand, 0xE */ 68 0xFF, /* dest = 0xFF; 1, GXset, 0xF */ 69}; 70/* same ROP but with Pattern as Source */ 71static const int XGIPatALUConv[] = 72{ 73 0x00, /* dest = 0; 0, GXclear, 0 */ 74 0xA0, /* dest &= src; DPa, GXand, 0x1 */ 75 0x50, /* dest = src & ~dest; PDna, GXandReverse, 0x2 */ 76 0xF0, /* dest = src; P, GXcopy, 0x3 */ 77 0x0A, /* dest &= ~src; DPna, GXandInverted, 0x4 */ 78 0xAA, /* dest = dest; D, GXnoop, 0x5 */ 79 0x5A, /* dest = ^src; DPx, GXxor, 0x6 */ 80 0xFA, /* dest |= src; DPo, GXor, 0x7 */ 81 0x05, /* dest = ~src & ~dest; DPon, GXnor, 0x8 */ 82 0xA5, /* dest ^= ~src ; DPxn, GXequiv, 0x9 */ 83 0x55, /* dest = ~dest; Dn, GXInvert, 0xA */ 84 0xF5, /* dest = src|~dest ; PDno, GXorReverse, 0xB */ 85 0x0F, /* dest = ~src; Pn, GXcopyInverted, 0xC */ 86 0xAF, /* dest |= ~src; DPno, GXorInverted, 0xD */ 87 0x5F, /* dest = ~src|~dest; DPan, GXnand, 0xE */ 88 0xFF, /* dest = 0xFF; 1, GXset, 0xF */ 89}; 90 91static const unsigned char myrops[] = { 92 3, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 93 }; 94 95/* 300 series */ 96static void 97XGI310Sync(void) 98{ 99 XGI310Idle 100} 101 102/* 310/325 series ------------------------------------------------ */ 103 104static void 105XGI310SetupForScreenToScreenCopy(int xdir, int ydir, int rop, 106 unsigned int planemask, int trans_color) 107{ 108 XGI310SetupDSTColorDepth(xgi_video_info.DstColor); 109 XGI310SetupSRCPitch(xgi_video_info.video_linelength) 110 XGI310SetupDSTRect(xgi_video_info.video_linelength, 0xFFF) 111 if (trans_color != -1) { 112 XGI310SetupROP(0x0A) 113 XGI310SetupSRCTrans(trans_color) 114 XGI310SetupCMDFlag(TRANSPARENT_BITBLT) 115 } else { 116 XGI310SetupROP(XGIALUConv[rop]) 117 /* Set command - not needed, both 0 */ 118 /* XGISetupCMDFlag(BITBLT | SRCVIDEO) */ 119 } 120 XGI310SetupCMDFlag(xgi_video_info.XGI310_AccelDepth) 121 /* TW: The 310/325 series is smart enough to know the direction */ 122} 123 124static void 125XGI310SubsequentScreenToScreenCopy(int src_x, int src_y, int dst_x, int dst_y, 126 int width, int height) 127{ 128 long srcbase, dstbase; 129 int mymin, mymax; 130 131 srcbase = dstbase = 0; 132 mymin = min(src_y, dst_y); 133 mymax = max(src_y, dst_y); 134 135 /* Although the chip knows the direction to use 136 * if the source and destination areas overlap, 137 * that logic fails if we fiddle with the bitmap 138 * addresses. Therefore, we check if the source 139 * and destination blitting areas overlap and 140 * adapt the bitmap addresses synchronously 141 * if the coordinates exceed the valid range. 142 * The the areas do not overlap, we do our 143 * normal check. 144 */ 145 if((mymax - mymin) < height) { 146 if((src_y >= 2048) || (dst_y >= 2048)) { 147 srcbase = xgi_video_info.video_linelength * mymin; 148 dstbase = xgi_video_info.video_linelength * mymin; 149 src_y -= mymin; 150 dst_y -= mymin; 151 } 152 } else { 153 if(src_y >= 2048) { 154 srcbase = xgi_video_info.video_linelength * src_y; 155 src_y = 0; 156 } 157 if(dst_y >= 2048) { 158 dstbase = xgi_video_info.video_linelength * dst_y; 159 dst_y = 0; 160 } 161 } 162 163 XGI310SetupSRCBase(srcbase); 164 XGI310SetupDSTBase(dstbase); 165 XGI310SetupRect(width, height) 166 XGI310SetupSRCXY(src_x, src_y) 167 XGI310SetupDSTXY(dst_x, dst_y) 168 XGI310DoCMD 169} 170 171static void 172XGI310SetupForSolidFill(int color, int rop, unsigned int planemask) 173{ 174 XGI310SetupPATFG(color) 175 XGI310SetupDSTRect(xgi_video_info.video_linelength, 0xFFF) 176 XGI310SetupDSTColorDepth(xgi_video_info.DstColor); 177 XGI310SetupROP(XGIPatALUConv[rop]) 178 XGI310SetupCMDFlag(PATFG | xgi_video_info.XGI310_AccelDepth) 179} 180 181static void 182XGI310SubsequentSolidFillRect(int x, int y, int w, int h) 183{ 184 long dstbase; 185 186 dstbase = 0; 187 if(y >= 2048) { 188 dstbase = xgi_video_info.video_linelength * y; 189 y = 0; 190 } 191 XGI310SetupDSTBase(dstbase) 192 XGI310SetupDSTXY(x,y) 193 XGI310SetupRect(w,h) 194 XGI310SetupCMDFlag(BITBLT) 195 XGI310DoCMD 196} 197 198/* --------------------------------------------------------------------- */ 199 200/* The exported routines */ 201 202int XGIfb_initaccel(void) 203{ 204#ifdef XGIFB_USE_SPINLOCKS 205 spin_lock_init(&xgi_video_info.lockaccel); 206#endif 207 return(0); 208} 209 210void XGIfb_syncaccel(void) 211{ 212 213 XGI310Sync(); 214 215} 216 217int fbcon_XGI_sync(struct fb_info *info) 218{ 219 if(!XGIfb_accel) return 0; 220 CRITFLAGS 221 222 XGI310Sync(); 223 224 CRITEND 225 return 0; 226} 227 228void fbcon_XGI_fillrect(struct fb_info *info, const struct fb_fillrect *rect) 229{ 230 int col=0; 231 CRITFLAGS 232 233 234 if(!rect->width || !rect->height) 235 return; 236 237 if(!XGIfb_accel) { 238 cfb_fillrect(info, rect); 239 return; 240 } 241 242 switch(info->var.bits_per_pixel) { 243 case 8: col = rect->color; 244 break; 245 case 16: col = ((u32 *)(info->pseudo_palette))[rect->color]; 246 break; 247 case 32: col = ((u32 *)(info->pseudo_palette))[rect->color]; 248 break; 249 } 250 251 252 CRITBEGIN 253 XGI310SetupForSolidFill(col, myrops[rect->rop], 0); 254 XGI310SubsequentSolidFillRect(rect->dx, rect->dy, rect->width, rect->height); 255 CRITEND 256 XGI310Sync(); 257 258 259} 260 261void fbcon_XGI_copyarea(struct fb_info *info, const struct fb_copyarea *area) 262{ 263 int xdir, ydir; 264 CRITFLAGS 265 266 267 if(!XGIfb_accel) { 268 cfb_copyarea(info, area); 269 return; 270 } 271 272 if(!area->width || !area->height) 273 return; 274 275 if(area->sx < area->dx) xdir = 0; 276 else xdir = 1; 277 if(area->sy < area->dy) ydir = 0; 278 else ydir = 1; 279 280 CRITBEGIN 281 XGI310SetupForScreenToScreenCopy(xdir, ydir, 3, 0, -1); 282 XGI310SubsequentScreenToScreenCopy(area->sx, area->sy, area->dx, area->dy, area->width, area->height); 283 CRITEND 284 XGI310Sync(); 285 286} 287