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