sis_accel.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /*
  2. * SiS 300/540/630[S]/730[S],
  3. * SiS 315[E|PRO]/550/[M]650/651/[M]661[F|M]X/740/[M]741[GX]/330/[M]760[GX],
  4. * XGI V3XT/V5/V8, Z7
  5. * frame buffer driver for Linux kernels >= 2.4.14 and >=2.6.3
  6. *
  7. * 2D acceleration part
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the named License,
  12. * or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
  22. *
  23. * Based on the XFree86/X.org driver which is
  24. * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
  25. *
  26. * Author: Thomas Winischhofer <thomas@winischhofer.net>
  27. * (see http://www.winischhofer.net/
  28. * for more information and updates)
  29. */
  30. #include <linux/version.h>
  31. #include <linux/module.h>
  32. #include <linux/kernel.h>
  33. #include <linux/fb.h>
  34. #include <linux/ioport.h>
  35. #include <linux/types.h>
  36. #include <asm/io.h>
  37. #include "sis.h"
  38. #include "sis_accel.h"
  39. static const u8 sisALUConv[] =
  40. {
  41. 0x00, /* dest = 0; 0, GXclear, 0 */
  42. 0x88, /* dest &= src; DSa, GXand, 0x1 */
  43. 0x44, /* dest = src & ~dest; SDna, GXandReverse, 0x2 */
  44. 0xCC, /* dest = src; S, GXcopy, 0x3 */
  45. 0x22, /* dest &= ~src; DSna, GXandInverted, 0x4 */
  46. 0xAA, /* dest = dest; D, GXnoop, 0x5 */
  47. 0x66, /* dest = ^src; DSx, GXxor, 0x6 */
  48. 0xEE, /* dest |= src; DSo, GXor, 0x7 */
  49. 0x11, /* dest = ~src & ~dest; DSon, GXnor, 0x8 */
  50. 0x99, /* dest ^= ~src ; DSxn, GXequiv, 0x9 */
  51. 0x55, /* dest = ~dest; Dn, GXInvert, 0xA */
  52. 0xDD, /* dest = src|~dest ; SDno, GXorReverse, 0xB */
  53. 0x33, /* dest = ~src; Sn, GXcopyInverted, 0xC */
  54. 0xBB, /* dest |= ~src; DSno, GXorInverted, 0xD */
  55. 0x77, /* dest = ~src|~dest; DSan, GXnand, 0xE */
  56. 0xFF, /* dest = 0xFF; 1, GXset, 0xF */
  57. };
  58. /* same ROP but with Pattern as Source */
  59. static const u8 sisPatALUConv[] =
  60. {
  61. 0x00, /* dest = 0; 0, GXclear, 0 */
  62. 0xA0, /* dest &= src; DPa, GXand, 0x1 */
  63. 0x50, /* dest = src & ~dest; PDna, GXandReverse, 0x2 */
  64. 0xF0, /* dest = src; P, GXcopy, 0x3 */
  65. 0x0A, /* dest &= ~src; DPna, GXandInverted, 0x4 */
  66. 0xAA, /* dest = dest; D, GXnoop, 0x5 */
  67. 0x5A, /* dest = ^src; DPx, GXxor, 0x6 */
  68. 0xFA, /* dest |= src; DPo, GXor, 0x7 */
  69. 0x05, /* dest = ~src & ~dest; DPon, GXnor, 0x8 */
  70. 0xA5, /* dest ^= ~src ; DPxn, GXequiv, 0x9 */
  71. 0x55, /* dest = ~dest; Dn, GXInvert, 0xA */
  72. 0xF5, /* dest = src|~dest ; PDno, GXorReverse, 0xB */
  73. 0x0F, /* dest = ~src; Pn, GXcopyInverted, 0xC */
  74. 0xAF, /* dest |= ~src; DPno, GXorInverted, 0xD */
  75. 0x5F, /* dest = ~src|~dest; DPan, GXnand, 0xE */
  76. 0xFF, /* dest = 0xFF; 1, GXset, 0xF */
  77. };
  78. static const int myrops[] = {
  79. 3, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
  80. };
  81. /* 300 series ----------------------------------------------------- */
  82. #ifdef CONFIG_FB_SIS_300
  83. static void
  84. SiS300Sync(struct sis_video_info *ivideo)
  85. {
  86. SiS300Idle
  87. }
  88. static void
  89. SiS300SetupForScreenToScreenCopy(struct sis_video_info *ivideo, int xdir, int ydir,
  90. int rop, int trans_color)
  91. {
  92. SiS300SetupDSTColorDepth(ivideo->DstColor);
  93. SiS300SetupSRCPitch(ivideo->video_linelength)
  94. SiS300SetupDSTRect(ivideo->video_linelength, 0xffff)
  95. if(trans_color != -1) {
  96. SiS300SetupROP(0x0A)
  97. SiS300SetupSRCTrans(trans_color)
  98. SiS300SetupCMDFlag(TRANSPARENT_BITBLT)
  99. } else {
  100. SiS300SetupROP(sisALUConv[rop])
  101. }
  102. if(xdir > 0) {
  103. SiS300SetupCMDFlag(X_INC)
  104. }
  105. if(ydir > 0) {
  106. SiS300SetupCMDFlag(Y_INC)
  107. }
  108. }
  109. static void
  110. SiS300SubsequentScreenToScreenCopy(struct sis_video_info *ivideo, int src_x,
  111. int src_y, int dst_x, int dst_y, int width, int height)
  112. {
  113. u32 srcbase = 0, dstbase = 0;
  114. if(src_y >= 2048) {
  115. srcbase = ivideo->video_linelength * src_y;
  116. src_y = 0;
  117. }
  118. if(dst_y >= 2048) {
  119. dstbase = ivideo->video_linelength * dst_y;
  120. dst_y = 0;
  121. }
  122. SiS300SetupSRCBase(srcbase);
  123. SiS300SetupDSTBase(dstbase);
  124. if(!(ivideo->CommandReg & X_INC)) {
  125. src_x += width-1;
  126. dst_x += width-1;
  127. }
  128. if(!(ivideo->CommandReg & Y_INC)) {
  129. src_y += height-1;
  130. dst_y += height-1;
  131. }
  132. SiS300SetupRect(width, height)
  133. SiS300SetupSRCXY(src_x, src_y)
  134. SiS300SetupDSTXY(dst_x, dst_y)
  135. SiS300DoCMD
  136. }
  137. static void
  138. SiS300SetupForSolidFill(struct sis_video_info *ivideo, u32 color, int rop)
  139. {
  140. SiS300SetupPATFG(color)
  141. SiS300SetupDSTRect(ivideo->video_linelength, 0xffff)
  142. SiS300SetupDSTColorDepth(ivideo->DstColor);
  143. SiS300SetupROP(sisPatALUConv[rop])
  144. SiS300SetupCMDFlag(PATFG)
  145. }
  146. static void
  147. SiS300SubsequentSolidFillRect(struct sis_video_info *ivideo, int x, int y, int w, int h)
  148. {
  149. u32 dstbase = 0;
  150. if(y >= 2048) {
  151. dstbase = ivideo->video_linelength * y;
  152. y = 0;
  153. }
  154. SiS300SetupDSTBase(dstbase)
  155. SiS300SetupDSTXY(x,y)
  156. SiS300SetupRect(w,h)
  157. SiS300SetupCMDFlag(X_INC | Y_INC | BITBLT)
  158. SiS300DoCMD
  159. }
  160. #endif
  161. /* 315/330/340 series ---------------------------------------------- */
  162. #ifdef CONFIG_FB_SIS_315
  163. static void
  164. SiS310Sync(struct sis_video_info *ivideo)
  165. {
  166. SiS310Idle
  167. }
  168. static void
  169. SiS310SetupForScreenToScreenCopy(struct sis_video_info *ivideo, int rop, int trans_color)
  170. {
  171. SiS310SetupDSTColorDepth(ivideo->DstColor);
  172. SiS310SetupSRCPitch(ivideo->video_linelength)
  173. SiS310SetupDSTRect(ivideo->video_linelength, 0x0fff)
  174. if(trans_color != -1) {
  175. SiS310SetupROP(0x0A)
  176. SiS310SetupSRCTrans(trans_color)
  177. SiS310SetupCMDFlag(TRANSPARENT_BITBLT)
  178. } else {
  179. SiS310SetupROP(sisALUConv[rop])
  180. /* Set command - not needed, both 0 */
  181. /* SiSSetupCMDFlag(BITBLT | SRCVIDEO) */
  182. }
  183. SiS310SetupCMDFlag(ivideo->SiS310_AccelDepth)
  184. /* The chip is smart enough to know the direction */
  185. }
  186. static void
  187. SiS310SubsequentScreenToScreenCopy(struct sis_video_info *ivideo, int src_x, int src_y,
  188. int dst_x, int dst_y, int width, int height)
  189. {
  190. u32 srcbase = 0, dstbase = 0;
  191. int mymin = min(src_y, dst_y);
  192. int mymax = max(src_y, dst_y);
  193. /* Although the chip knows the direction to use
  194. * if the source and destination areas overlap,
  195. * that logic fails if we fiddle with the bitmap
  196. * addresses. Therefore, we check if the source
  197. * and destination blitting areas overlap and
  198. * adapt the bitmap addresses synchronously
  199. * if the coordinates exceed the valid range.
  200. * The the areas do not overlap, we do our
  201. * normal check.
  202. */
  203. if((mymax - mymin) < height) {
  204. if((src_y >= 2048) || (dst_y >= 2048)) {
  205. srcbase = ivideo->video_linelength * mymin;
  206. dstbase = ivideo->video_linelength * mymin;
  207. src_y -= mymin;
  208. dst_y -= mymin;
  209. }
  210. } else {
  211. if(src_y >= 2048) {
  212. srcbase = ivideo->video_linelength * src_y;
  213. src_y = 0;
  214. }
  215. if(dst_y >= 2048) {
  216. dstbase = ivideo->video_linelength * dst_y;
  217. dst_y = 0;
  218. }
  219. }
  220. srcbase += ivideo->video_offset;
  221. dstbase += ivideo->video_offset;
  222. SiS310SetupSRCBase(srcbase);
  223. SiS310SetupDSTBase(dstbase);
  224. SiS310SetupRect(width, height)
  225. SiS310SetupSRCXY(src_x, src_y)
  226. SiS310SetupDSTXY(dst_x, dst_y)
  227. SiS310DoCMD
  228. }
  229. static void
  230. SiS310SetupForSolidFill(struct sis_video_info *ivideo, u32 color, int rop)
  231. {
  232. SiS310SetupPATFG(color)
  233. SiS310SetupDSTRect(ivideo->video_linelength, 0x0fff)
  234. SiS310SetupDSTColorDepth(ivideo->DstColor);
  235. SiS310SetupROP(sisPatALUConv[rop])
  236. SiS310SetupCMDFlag(PATFG | ivideo->SiS310_AccelDepth)
  237. }
  238. static void
  239. SiS310SubsequentSolidFillRect(struct sis_video_info *ivideo, int x, int y, int w, int h)
  240. {
  241. u32 dstbase = 0;
  242. if(y >= 2048) {
  243. dstbase = ivideo->video_linelength * y;
  244. y = 0;
  245. }
  246. dstbase += ivideo->video_offset;
  247. SiS310SetupDSTBase(dstbase)
  248. SiS310SetupDSTXY(x,y)
  249. SiS310SetupRect(w,h)
  250. SiS310SetupCMDFlag(BITBLT)
  251. SiS310DoCMD
  252. }
  253. #endif
  254. /* --------------------------------------------------------------------- */
  255. /* The exported routines */
  256. int sisfb_initaccel(struct sis_video_info *ivideo)
  257. {
  258. #ifdef SISFB_USE_SPINLOCKS
  259. spin_lock_init(&ivideo->lockaccel);
  260. #endif
  261. return 0;
  262. }
  263. void sisfb_syncaccel(struct sis_video_info *ivideo)
  264. {
  265. if(ivideo->sisvga_engine == SIS_300_VGA) {
  266. #ifdef CONFIG_FB_SIS_300
  267. SiS300Sync(ivideo);
  268. #endif
  269. } else {
  270. #ifdef CONFIG_FB_SIS_315
  271. SiS310Sync(ivideo);
  272. #endif
  273. }
  274. }
  275. int fbcon_sis_sync(struct fb_info *info)
  276. {
  277. struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
  278. CRITFLAGS
  279. if((!ivideo->accel) || (!ivideo->engineok))
  280. return 0;
  281. CRITBEGIN
  282. sisfb_syncaccel(ivideo);
  283. CRITEND
  284. return 0;
  285. }
  286. void fbcon_sis_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  287. {
  288. struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
  289. u32 col = 0;
  290. u32 vxres = info->var.xres_virtual;
  291. u32 vyres = info->var.yres_virtual;
  292. int width, height;
  293. CRITFLAGS
  294. if(info->state != FBINFO_STATE_RUNNING)
  295. return;
  296. if((!ivideo->accel) || (!ivideo->engineok)) {
  297. cfb_fillrect(info, rect);
  298. return;
  299. }
  300. if(!rect->width || !rect->height || rect->dx >= vxres || rect->dy >= vyres)
  301. return;
  302. /* Clipping */
  303. width = ((rect->dx + rect->width) > vxres) ? (vxres - rect->dx) : rect->width;
  304. height = ((rect->dy + rect->height) > vyres) ? (vyres - rect->dy) : rect->height;
  305. switch(info->var.bits_per_pixel) {
  306. case 8: col = rect->color;
  307. break;
  308. case 16:
  309. case 32: col = ((u32 *)(info->pseudo_palette))[rect->color];
  310. break;
  311. }
  312. if(ivideo->sisvga_engine == SIS_300_VGA) {
  313. #ifdef CONFIG_FB_SIS_300
  314. CRITBEGIN
  315. SiS300SetupForSolidFill(ivideo, col, myrops[rect->rop]);
  316. SiS300SubsequentSolidFillRect(ivideo, rect->dx, rect->dy, width, height);
  317. CRITEND
  318. #endif
  319. } else {
  320. #ifdef CONFIG_FB_SIS_315
  321. CRITBEGIN
  322. SiS310SetupForSolidFill(ivideo, col, myrops[rect->rop]);
  323. SiS310SubsequentSolidFillRect(ivideo, rect->dx, rect->dy, width, height);
  324. CRITEND
  325. #endif
  326. }
  327. sisfb_syncaccel(ivideo);
  328. }
  329. void fbcon_sis_copyarea(struct fb_info *info, const struct fb_copyarea *area)
  330. {
  331. struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
  332. u32 vxres = info->var.xres_virtual;
  333. u32 vyres = info->var.yres_virtual;
  334. int width = area->width;
  335. int height = area->height;
  336. CRITFLAGS
  337. if(info->state != FBINFO_STATE_RUNNING)
  338. return;
  339. if((!ivideo->accel) || (!ivideo->engineok)) {
  340. cfb_copyarea(info, area);
  341. return;
  342. }
  343. if(!width || !height ||
  344. area->sx >= vxres || area->sy >= vyres ||
  345. area->dx >= vxres || area->dy >= vyres)
  346. return;
  347. /* Clipping */
  348. if((area->sx + width) > vxres) width = vxres - area->sx;
  349. if((area->dx + width) > vxres) width = vxres - area->dx;
  350. if((area->sy + height) > vyres) height = vyres - area->sy;
  351. if((area->dy + height) > vyres) height = vyres - area->dy;
  352. if(ivideo->sisvga_engine == SIS_300_VGA) {
  353. #ifdef CONFIG_FB_SIS_300
  354. int xdir, ydir;
  355. if(area->sx < area->dx) xdir = 0;
  356. else xdir = 1;
  357. if(area->sy < area->dy) ydir = 0;
  358. else ydir = 1;
  359. CRITBEGIN
  360. SiS300SetupForScreenToScreenCopy(ivideo, xdir, ydir, 3, -1);
  361. SiS300SubsequentScreenToScreenCopy(ivideo, area->sx, area->sy,
  362. area->dx, area->dy, width, height);
  363. CRITEND
  364. #endif
  365. } else {
  366. #ifdef CONFIG_FB_SIS_315
  367. CRITBEGIN
  368. SiS310SetupForScreenToScreenCopy(ivideo, 3, -1);
  369. SiS310SubsequentScreenToScreenCopy(ivideo, area->sx, area->sy,
  370. area->dx, area->dy, width, height);
  371. CRITEND
  372. #endif
  373. }
  374. sisfb_syncaccel(ivideo);
  375. }