sis_accel.h 13 KB

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