sis_accel.c 12 KB

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