sis_accel.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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 X driver's sis300_accel.h which is
  24. * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria
  25. * and sis310_accel.h which is
  26. * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria
  27. *
  28. * Author: Thomas Winischhofer <thomas@winischhofer.net>:
  29. * (see http://www.winischhofer.net/
  30. * for more information and updates)
  31. */
  32. #ifndef _SISFB_ACCEL_H
  33. #define _SISFB_ACCEL_H
  34. /* Guard accelerator accesses with spin_lock_irqsave? Works well without. */
  35. #undef SISFB_USE_SPINLOCKS
  36. #ifdef SISFB_USE_SPINLOCKS
  37. #include <linux/spinlock.h>
  38. #define CRITBEGIN spin_lock_irqsave(&ivideo->lockaccel, critflags);
  39. #define CRITEND spin_unlock_irqrestore(&ivideo->lockaccel, critflags);
  40. #define CRITFLAGS unsigned long critflags;
  41. #else
  42. #define CRITBEGIN
  43. #define CRITEND
  44. #define CRITFLAGS
  45. #endif
  46. /* Definitions for the SIS engine communication. */
  47. #define PATREGSIZE 384 /* Pattern register size. 384 bytes @ 0x8300 */
  48. #define BR(x) (0x8200 | (x) << 2)
  49. #define PBR(x) (0x8300 | (x) << 2)
  50. /* SiS300 engine commands */
  51. #define BITBLT 0x00000000 /* Blit */
  52. #define COLOREXP 0x00000001 /* Color expand */
  53. #define ENCOLOREXP 0x00000002 /* Enhanced color expand */
  54. #define MULTIPLE_SCANLINE 0x00000003 /* ? */
  55. #define LINE 0x00000004 /* Draw line */
  56. #define TRAPAZOID_FILL 0x00000005 /* Fill trapezoid */
  57. #define TRANSPARENT_BITBLT 0x00000006 /* Transparent Blit */
  58. /* Additional engine commands for 315 */
  59. #define ALPHA_BLEND 0x00000007 /* Alpha blend ? */
  60. #define A3D_FUNCTION 0x00000008 /* 3D command ? */
  61. #define CLEAR_Z_BUFFER 0x00000009 /* ? */
  62. #define GRADIENT_FILL 0x0000000A /* Gradient fill */
  63. /* source select */
  64. #define SRCVIDEO 0x00000000 /* source is video RAM */
  65. #define SRCSYSTEM 0x00000010 /* source is system memory */
  66. #define SRCCPUBLITBUF SRCSYSTEM /* source is CPU-driven BitBuffer (for color expand) */
  67. #define SRCAGP 0x00000020 /* source is AGP memory (?) */
  68. /* Pattern flags */
  69. #define PATFG 0x00000000 /* foreground color */
  70. #define PATPATREG 0x00000040 /* pattern in pattern buffer (0x8300) */
  71. #define PATMONO 0x00000080 /* mono pattern */
  72. /* blitting direction (300 series only) */
  73. #define X_INC 0x00010000
  74. #define X_DEC 0x00000000
  75. #define Y_INC 0x00020000
  76. #define Y_DEC 0x00000000
  77. /* Clipping flags */
  78. #define NOCLIP 0x00000000
  79. #define NOMERGECLIP 0x04000000
  80. #define CLIPENABLE 0x00040000
  81. #define CLIPWITHOUTMERGE 0x04040000
  82. /* Transparency */
  83. #define OPAQUE 0x00000000
  84. #define TRANSPARENT 0x00100000
  85. /* ? */
  86. #define DSTAGP 0x02000000
  87. #define DSTVIDEO 0x02000000
  88. /* Subfunctions for Color/Enhanced Color Expansion (315 only) */
  89. #define COLOR_TO_MONO 0x00100000
  90. #define AA_TEXT 0x00200000
  91. /* Some general registers for 315 series */
  92. #define SRC_ADDR 0x8200
  93. #define SRC_PITCH 0x8204
  94. #define AGP_BASE 0x8206 /* color-depth dependent value */
  95. #define SRC_Y 0x8208
  96. #define SRC_X 0x820A
  97. #define DST_Y 0x820C
  98. #define DST_X 0x820E
  99. #define DST_ADDR 0x8210
  100. #define DST_PITCH 0x8214
  101. #define DST_HEIGHT 0x8216
  102. #define RECT_WIDTH 0x8218
  103. #define RECT_HEIGHT 0x821A
  104. #define PAT_FGCOLOR 0x821C
  105. #define PAT_BGCOLOR 0x8220
  106. #define SRC_FGCOLOR 0x8224
  107. #define SRC_BGCOLOR 0x8228
  108. #define MONO_MASK 0x822C
  109. #define LEFT_CLIP 0x8234
  110. #define TOP_CLIP 0x8236
  111. #define RIGHT_CLIP 0x8238
  112. #define BOTTOM_CLIP 0x823A
  113. #define COMMAND_READY 0x823C
  114. #define FIRE_TRIGGER 0x8240
  115. #define PATTERN_REG 0x8300 /* 384 bytes pattern buffer */
  116. /* Transparent bitblit registers */
  117. #define TRANS_DST_KEY_HIGH PAT_FGCOLOR
  118. #define TRANS_DST_KEY_LOW PAT_BGCOLOR
  119. #define TRANS_SRC_KEY_HIGH SRC_FGCOLOR
  120. #define TRANS_SRC_KEY_LOW SRC_BGCOLOR
  121. /* Store queue length in par */
  122. #define CmdQueLen ivideo->cmdqueuelength
  123. /* ------------- SiS 300 series -------------- */
  124. /* BR(16) (0x8240):
  125. bit 31 2D engine: 1 is idle,
  126. bit 30 3D engine: 1 is idle,
  127. bit 29 Command queue: 1 is empty
  128. bits 28:24: Current CPU driven BitBlt buffer stage bit[4:0]
  129. bits 15:0: Current command queue length
  130. */
  131. #define SiS300Idle \
  132. { \
  133. while((MMIO_IN16(ivideo->mmio_vbase, BR(16)+2) & 0xE000) != 0xE000){}; \
  134. while((MMIO_IN16(ivideo->mmio_vbase, BR(16)+2) & 0xE000) != 0xE000){}; \
  135. while((MMIO_IN16(ivideo->mmio_vbase, BR(16)+2) & 0xE000) != 0xE000){}; \
  136. CmdQueLen = MMIO_IN16(ivideo->mmio_vbase, 0x8240); \
  137. }
  138. /* (do three times, because 2D engine seems quite unsure about whether or not it's idle) */
  139. #define SiS300SetupSRCBase(base) \
  140. if(CmdQueLen <= 0) SiS300Idle;\
  141. MMIO_OUT32(ivideo->mmio_vbase, BR(0), base);\
  142. CmdQueLen--;
  143. #define SiS300SetupSRCPitch(pitch) \
  144. if(CmdQueLen <= 0) SiS300Idle;\
  145. MMIO_OUT16(ivideo->mmio_vbase, BR(1), pitch);\
  146. CmdQueLen--;
  147. #define SiS300SetupSRCXY(x,y) \
  148. if(CmdQueLen <= 0) SiS300Idle;\
  149. MMIO_OUT32(ivideo->mmio_vbase, BR(2), (x)<<16 | (y) );\
  150. CmdQueLen--;
  151. #define SiS300SetupDSTBase(base) \
  152. if(CmdQueLen <= 0) SiS300Idle;\
  153. MMIO_OUT32(ivideo->mmio_vbase, BR(4), base);\
  154. CmdQueLen--;
  155. #define SiS300SetupDSTXY(x,y) \
  156. if(CmdQueLen <= 0) SiS300Idle;\
  157. MMIO_OUT32(ivideo->mmio_vbase, BR(3), (x)<<16 | (y) );\
  158. CmdQueLen--;
  159. #define SiS300SetupDSTRect(x,y) \
  160. if(CmdQueLen <= 0) SiS300Idle;\
  161. MMIO_OUT32(ivideo->mmio_vbase, BR(5), (y)<<16 | (x) );\
  162. CmdQueLen--;
  163. #define SiS300SetupDSTColorDepth(bpp) \
  164. if(CmdQueLen <= 0) SiS300Idle;\
  165. MMIO_OUT16(ivideo->mmio_vbase, BR(1)+2, bpp);\
  166. CmdQueLen--;
  167. #define SiS300SetupRect(w,h) \
  168. if(CmdQueLen <= 0) SiS300Idle;\
  169. MMIO_OUT32(ivideo->mmio_vbase, BR(6), (h)<<16 | (w) );\
  170. CmdQueLen--;
  171. #define SiS300SetupPATFG(color) \
  172. if(CmdQueLen <= 0) SiS300Idle;\
  173. MMIO_OUT32(ivideo->mmio_vbase, BR(7), color);\
  174. CmdQueLen--;
  175. #define SiS300SetupPATBG(color) \
  176. if(CmdQueLen <= 0) SiS300Idle;\
  177. MMIO_OUT32(ivideo->mmio_vbase, BR(8), color);\
  178. CmdQueLen--;
  179. #define SiS300SetupSRCFG(color) \
  180. if(CmdQueLen <= 0) SiS300Idle;\
  181. MMIO_OUT32(ivideo->mmio_vbase, BR(9), color);\
  182. CmdQueLen--;
  183. #define SiS300SetupSRCBG(color) \
  184. if(CmdQueLen <= 0) SiS300Idle;\
  185. MMIO_OUT32(ivideo->mmio_vbase, BR(10), color);\
  186. CmdQueLen--;
  187. /* 0x8224 src colorkey high */
  188. /* 0x8228 src colorkey low */
  189. /* 0x821c dest colorkey high */
  190. /* 0x8220 dest colorkey low */
  191. #define SiS300SetupSRCTrans(color) \
  192. if(CmdQueLen <= 1) SiS300Idle;\
  193. MMIO_OUT32(ivideo->mmio_vbase, 0x8224, color);\
  194. MMIO_OUT32(ivideo->mmio_vbase, 0x8228, color);\
  195. CmdQueLen -= 2;
  196. #define SiS300SetupDSTTrans(color) \
  197. if(CmdQueLen <= 1) SiS300Idle;\
  198. MMIO_OUT32(ivideo->mmio_vbase, 0x821C, color); \
  199. MMIO_OUT32(ivideo->mmio_vbase, 0x8220, color); \
  200. CmdQueLen -= 2;
  201. #define SiS300SetupMONOPAT(p0,p1) \
  202. if(CmdQueLen <= 1) SiS300Idle;\
  203. MMIO_OUT32(ivideo->mmio_vbase, BR(11), p0);\
  204. MMIO_OUT32(ivideo->mmio_vbase, BR(12), p1);\
  205. CmdQueLen -= 2;
  206. #define SiS300SetupClipLT(left,top) \
  207. if(CmdQueLen <= 0) SiS300Idle;\
  208. MMIO_OUT32(ivideo->mmio_vbase, BR(13), ((left) & 0xFFFF) | (top)<<16 );\
  209. CmdQueLen--;
  210. #define SiS300SetupClipRB(right,bottom) \
  211. if(CmdQueLen <= 0) SiS300Idle;\
  212. MMIO_OUT32(ivideo->mmio_vbase, BR(14), ((right) & 0xFFFF) | (bottom)<<16 );\
  213. CmdQueLen--;
  214. /* General */
  215. #define SiS300SetupROP(rop) \
  216. ivideo->CommandReg = (rop) << 8;
  217. #define SiS300SetupCMDFlag(flags) \
  218. ivideo->CommandReg |= (flags);
  219. #define SiS300DoCMD \
  220. if(CmdQueLen <= 1) SiS300Idle;\
  221. MMIO_OUT32(ivideo->mmio_vbase, BR(15), ivideo->CommandReg); \
  222. MMIO_OUT32(ivideo->mmio_vbase, BR(16), 0);\
  223. CmdQueLen -= 2;
  224. /* -------------- SiS 315/330 series --------------- */
  225. /* Q_STATUS:
  226. bit 31 = 1: All engines idle and all queues empty
  227. bit 30 = 1: Hardware Queue (=HW CQ, 2D queue, 3D queue) empty
  228. bit 29 = 1: 2D engine is idle
  229. bit 28 = 1: 3D engine is idle
  230. bit 27 = 1: HW command queue empty
  231. bit 26 = 1: 2D queue empty
  232. bit 25 = 1: 3D queue empty
  233. bit 24 = 1: SW command queue empty
  234. bits 23:16: 2D counter 3
  235. bits 15:8: 2D counter 2
  236. bits 7:0: 2D counter 1
  237. */
  238. #define SiS310Idle \
  239. { \
  240. while( (MMIO_IN16(ivideo->mmio_vbase, Q_STATUS+2) & 0x8000) != 0x8000){}; \
  241. while( (MMIO_IN16(ivideo->mmio_vbase, Q_STATUS+2) & 0x8000) != 0x8000){}; \
  242. while( (MMIO_IN16(ivideo->mmio_vbase, Q_STATUS+2) & 0x8000) != 0x8000){}; \
  243. while( (MMIO_IN16(ivideo->mmio_vbase, Q_STATUS+2) & 0x8000) != 0x8000){}; \
  244. CmdQueLen = 0; \
  245. }
  246. #define SiS310SetupSRCBase(base) \
  247. if(CmdQueLen <= 0) SiS310Idle;\
  248. MMIO_OUT32(ivideo->mmio_vbase, SRC_ADDR, base);\
  249. CmdQueLen--;
  250. #define SiS310SetupSRCPitch(pitch) \
  251. if(CmdQueLen <= 0) SiS310Idle;\
  252. MMIO_OUT16(ivideo->mmio_vbase, SRC_PITCH, pitch);\
  253. CmdQueLen--;
  254. #define SiS310SetupSRCXY(x,y) \
  255. if(CmdQueLen <= 0) SiS310Idle;\
  256. MMIO_OUT32(ivideo->mmio_vbase, SRC_Y, (x)<<16 | (y) );\
  257. CmdQueLen--;
  258. #define SiS310SetupDSTBase(base) \
  259. if(CmdQueLen <= 0) SiS310Idle;\
  260. MMIO_OUT32(ivideo->mmio_vbase, DST_ADDR, base);\
  261. CmdQueLen--;
  262. #define SiS310SetupDSTXY(x,y) \
  263. if(CmdQueLen <= 0) SiS310Idle;\
  264. MMIO_OUT32(ivideo->mmio_vbase, DST_Y, (x)<<16 | (y) );\
  265. CmdQueLen--;
  266. #define SiS310SetupDSTRect(x,y) \
  267. if(CmdQueLen <= 0) SiS310Idle;\
  268. MMIO_OUT32(ivideo->mmio_vbase, DST_PITCH, (y)<<16 | (x) );\
  269. CmdQueLen--;
  270. #define SiS310SetupDSTColorDepth(bpp) \
  271. if(CmdQueLen <= 0) SiS310Idle;\
  272. MMIO_OUT16(ivideo->mmio_vbase, AGP_BASE, bpp);\
  273. CmdQueLen--;
  274. #define SiS310SetupRect(w,h) \
  275. if(CmdQueLen <= 0) SiS310Idle;\
  276. MMIO_OUT32(ivideo->mmio_vbase, RECT_WIDTH, (h)<<16 | (w) );\
  277. CmdQueLen--;
  278. #define SiS310SetupPATFG(color) \
  279. if(CmdQueLen <= 0) SiS310Idle;\
  280. MMIO_OUT32(ivideo->mmio_vbase, PAT_FGCOLOR, color);\
  281. CmdQueLen--;
  282. #define SiS310SetupPATBG(color) \
  283. if(CmdQueLen <= 0) SiS310Idle;\
  284. MMIO_OUT32(ivideo->mmio_vbase, PAT_BGCOLOR, color);\
  285. CmdQueLen--;
  286. #define SiS310SetupSRCFG(color) \
  287. if(CmdQueLen <= 0) SiS310Idle;\
  288. MMIO_OUT32(ivideo->mmio_vbase, SRC_FGCOLOR, color);\
  289. CmdQueLen--;
  290. #define SiS310SetupSRCBG(color) \
  291. if(CmdQueLen <= 0) SiS310Idle;\
  292. MMIO_OUT32(ivideo->mmio_vbase, SRC_BGCOLOR, color);\
  293. CmdQueLen--;
  294. #define SiS310SetupSRCTrans(color) \
  295. if(CmdQueLen <= 1) SiS310Idle;\
  296. MMIO_OUT32(ivideo->mmio_vbase, TRANS_SRC_KEY_HIGH, color);\
  297. MMIO_OUT32(ivideo->mmio_vbase, TRANS_SRC_KEY_LOW, color);\
  298. CmdQueLen -= 2;
  299. #define SiS310SetupDSTTrans(color) \
  300. if(CmdQueLen <= 1) SiS310Idle;\
  301. MMIO_OUT32(ivideo->mmio_vbase, TRANS_DST_KEY_HIGH, color); \
  302. MMIO_OUT32(ivideo->mmio_vbase, TRANS_DST_KEY_LOW, color); \
  303. CmdQueLen -= 2;
  304. #define SiS310SetupMONOPAT(p0,p1) \
  305. if(CmdQueLen <= 1) SiS310Idle;\
  306. MMIO_OUT32(ivideo->mmio_vbase, MONO_MASK, p0);\
  307. MMIO_OUT32(ivideo->mmio_vbase, MONO_MASK+4, p1);\
  308. CmdQueLen -= 2;
  309. #define SiS310SetupClipLT(left,top) \
  310. if(CmdQueLen <= 0) SiS310Idle;\
  311. MMIO_OUT32(ivideo->mmio_vbase, LEFT_CLIP, ((left) & 0xFFFF) | (top)<<16 );\
  312. CmdQueLen--;
  313. #define SiS310SetupClipRB(right,bottom) \
  314. if(CmdQueLen <= 0) SiS310Idle;\
  315. MMIO_OUT32(ivideo->mmio_vbase, RIGHT_CLIP, ((right) & 0xFFFF) | (bottom)<<16 );\
  316. CmdQueLen--;
  317. #define SiS310SetupROP(rop) \
  318. ivideo->CommandReg = (rop) << 8;
  319. #define SiS310SetupCMDFlag(flags) \
  320. ivideo->CommandReg |= (flags);
  321. #define SiS310DoCMD \
  322. if(CmdQueLen <= 1) SiS310Idle;\
  323. MMIO_OUT32(ivideo->mmio_vbase, COMMAND_READY, ivideo->CommandReg); \
  324. MMIO_OUT32(ivideo->mmio_vbase, FIRE_TRIGGER, 0); \
  325. CmdQueLen -= 2;
  326. int sisfb_initaccel(struct sis_video_info *ivideo);
  327. void sisfb_syncaccel(struct sis_video_info *ivideo);
  328. int fbcon_sis_sync(struct fb_info *info);
  329. void fbcon_sis_fillrect(struct fb_info *info, const struct fb_fillrect *rect);
  330. void fbcon_sis_copyarea(struct fb_info *info, const struct fb_copyarea *area);
  331. #endif